From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id DE96B80C1B for ; Thu, 22 Oct 2026 14:52:05 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 69MEotaM009803; Thu, 22 Oct 2026 17:50:55 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69MEotaM009803 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="uEF0QRK5" Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 69MEoerV009756 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 22 Oct 2026 17:50:40 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69MEoerV009756 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-48b02d63407so1271297f8f.0 for ; Thu, 22 Oct 2026 07:50:40 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBw5SKZA0mpccC4SXpMz1/TUZ41VXOGCzjlOGYZqipJvs+V0TNyLxPzSxaMk4qABE7bvArfljg==@openvz.org X-Gm-Message-State: AFq9FYKDDMEfVj4E0HliK9q8g4klsahhbnnzduoqOt2KEciSr0bY5G/x WtoAT4WWfY8v8tds6WaXWiQsGqRdEdDO8BZqwVnaUKbmd/wg7LrhHSI2wZTTugBBVDg935C6n/O 3skD08q0mkZKRvAtnSlnOvcCezXAQIhyeL4QLq96Jf68CofxUIhAFuQ== X-Gm-Gg: AYBFou1h2UdvZEna/MeOQWHctgV22cK4pxk7vRNtwvdvTy92SIg9uhE9i6bGLMaNKb0 tQWrNO8kTf0CYG7iEnod+ZtLu1G2wCOg+3NoQUGKwsWZRE0ccywyMGJT4b24sD0JrmeUUvk94cn Sk63F7NYwotFn9RMRqq4VxT9bdhoh44+SojuhBTnMPwX9OynbgAmfWzs/Jze63XlENHRDPYdYqY XN9cffRQmLGqW0DONP4sJ4Lld5+eSREgVN/J13wor6Td1GnODcnXd/U0gwWxCGdd/x5BgxNAoRx nP3N8mn3Kwt2jvhrn+cQp+sJw7eO99JvpcWRafB0/SIml7b/xceYFhqGNGm9VWSsk3MoftPPptn TQfO61lf/QIrkLtGw1FYozTzMfXqh X-Received: by 2002:a05:6000:4b0a:b0:48e:1080:3a92 with SMTP id ffacd0b85a97d-48e264c9785mr11847247f8f.32.1792680639995; Thu, 22 Oct 2026 07:50:39 -0700 (PDT) X-Received: by 2002:a05:6000:4b0a:b0:48e:1080:3a92 with SMTP id ffacd0b85a97d-48e264c9785mr11847186f8f.32.1792680639371; Thu, 22 Oct 2026 07:50:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1792680639; cv=none; d=google.com; s=arc-20260327; b=e/Q6NFLIvNWHmNeF7G4SWTTPaoyHEGDpntF7zJLtCtGh9RhODOQGzk27e7Zhor/eva psrGtlY1QVZUaGv/fwBjM2XaXFwgm4xP+5kaSUu6olSzOUb8mUp8nRnQDALJuMtVnvYG VhozWvEuuWTp0IAO5UbxMOOYoPrAtGXazMncP5LxNMSA0KF3d+abDcIzkjfEyA8abG/O qv5rTljoekdNUiJ9UJ6IWn2e2A8hA0tmwzk85jNm03xY5U0bjeYtaxaismeqSlZYzt9V waJYJ8DBzG1hNuLut7o66RPN28DwVHbJiSuVIteZfnV/KVHbRENcGeHHdkV/NnulskUl BTeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=oASw1LJbaOutVXiLUAxLQUdr/0HlRE8VWB3XJ+6iaoQ=; fh=1MEQxOGYABaQPNQS1Ckioh0rrUOwgCYjd8t5csgx5as=; b=qZzaMJIfcIrN5hMpF18bVHqvRNy1kWMOmUgTzLbABQKXwrvk4ogOj7ITX3jNADm5tn 7961gHIe1QeFIPqqOntZv8YUB04SUFYzWMdzJpg+XBYoDvB5pZPbiNdiML6DaDcQNHyY nh2b1C/Kmmx9ezLglC5eg1R9CmAJyFghwF873mCHjCANpRhY2m9hWRDrOtOAQbX0gzVk pvzvBw1pi3f/0uuWC9FhT02VRL+XOZh2gGGFZ95NBHPtptmfUAFCRBQa9tJM/DBkdhC6 Xm+KlzXl6mR5vtjpvlUdrn58Q0riLjukQEVhcqzL9UhO4uU9BYQFi9ubYY92vZ72Hab1 JoHg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=uEF0QRK5; spf=pass (google.com: domain of alexander.ivanov@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=alexander.ivanov@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-48e25870f13si11846569f8f.303.2026.10.22.07.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 07:50:39 -0700 (PDT) Received-SPF: pass (google.com: domain of alexander.ivanov@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=uEF0QRK5; spf=pass (google.com: domain of alexander.ivanov@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=alexander.ivanov@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=oASw1LJbaOutVXiLUAxLQUdr/0HlRE8VWB3XJ+6iaoQ=; b=uEF0QRK57irm pGSH2KC5LGBuzmsGmLVeew1ZtTfkeLkzLHDARLhjejjiQzVDJoE+ROwCtbbU6/SkrhQAfFykn/bWO C1IFxkvOpNY59oDQ6rAR+ShWSc4C+drkqNr6fZh42xQlqWL2s1bQCKOFoSDJiVA4L7zAussxIYIm1 inCBQ98oarpSlIn41lQuholXfydqC6do47UDyRaWk1ZMKwwaK2B2B0m9s6eXpVVs1BOGYeswZ3T+r qrMrZtW3v/1j/hgbx5FT/kQVqFLdId8VSa75wPule+GlIbGaRsR2H8rtj6JgkK0/kbcK68dPdsgWI oZwN6tTW+czG6SD4eYVH6w==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=sky) by relay.virtuozzo.com with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xJu4D-00GYCQ-2F; Thu, 22 Oct 2026 16:50:36 +0200 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Thu, 22 Oct 2026 16:50:31 +0200 Message-ID: <20261022145032.2128679-6-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261022145032.2128679-1-alexander.ivanov@virtuozzo.com> References: <20261022145032.2128679-1-alexander.ivanov@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v7 5/6] dm-qcow2: keep the dirty bit of an image opened dirty X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org With kernel_sets_dirty_bit, postsuspend clears the dirty bit unconditionally. An image that is dirty at open, e.g. after a crash, has unrepaired refcounts, which may be below real usage, yet it is marked clean on disk after the first suspend. A userspace check before the next open then has no reason to repair it. Clear the bit only if the image was clean before the kernel set it. The parsed header can't tell this: it is reread on every preresume and may carry the kernel's own bit, e.g. on the lower image of a backward merge cancelled by suspend in waiting_completion or of a merge with depth > 0. So track two flags per image: kernel_dirty_bit is set only while the last header write was a successful set and the reread header still has the bit, opened_dirty is set when the header has the bit and kernel_dirty_bit is not set. Clearing the bit of an image opened dirty is left to userspace check. After a failed write the bit found on disk is taken as opened dirty, which costs an extra check, rather than as the kernel's, which could clear a bit set by userspace while the device was suspended. This only preserves the on-disk marker. The driver still accepts a dirty image read-write and allocates from its refcounts, so find_unused_cluster() may hand out clusters that L2 still references until the image is checked. https://virtuozzo.atlassian.net/browse/VSTOR-148171 Feature: dm-qcow2: block device over QCOW2 files driver Signed-off-by: Alexander Ivanov --- drivers/md/dm-qcow2-target.c | 15 +++++++++++++-- drivers/md/dm-qcow2.h | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c index b667adb5472a..2d69e39a3530 100644 --- a/drivers/md/dm-qcow2-target.c +++ b/drivers/md/dm-qcow2-target.c @@ -659,6 +659,7 @@ int qcow2_set_image_file_features(struct qcow2 *qcow2, bool dirty) struct QCowHeader *raw_hdr; struct md_page *md; bool is_ro; + int ret; if (qcow2->hdr.version == 2) return 0; @@ -676,12 +677,15 @@ int qcow2_set_image_file_features(struct qcow2 *qcow2, bool dirty) if (kernel_sets_dirty_bit) { if (dirty) raw_hdr->incompatible_features |= dirty_mask; - else + else if (!qcow2->opened_dirty) raw_hdr->incompatible_features &= ~dirty_mask; } kunmap(md->page); - return qcow2_rw_page_sync(WRITE, qcow2, md->id, md->page); + ret = qcow2_rw_page_sync(WRITE, qcow2, md->id, md->page); + if (kernel_sets_dirty_bit) + qcow2->kernel_dirty_bit = dirty && !ret; + return ret; } ALLOW_ERROR_INJECTION(qcow2_set_image_file_features, ERRNO); @@ -903,6 +907,13 @@ static int qcow2_parse_header(struct dm_target *ti, struct qcow2 *qcow2, goto out; qcow2_calc_cached_parameters(qcow2, hdr); + /* The header is reread on resume and may carry our own dirty bit */ + if (!(hdr->incompatible_features & INCOMPATIBLE_FEATURES_DIRTY_BIT)) { + qcow2->opened_dirty = false; + qcow2->kernel_dirty_bit = false; + } else if (!qcow2->kernel_dirty_bit) { + qcow2->opened_dirty = true; + } ret = -EOPNOTSUPP; if (qcow2->clu_size < PAGE_SIZE || (qcow2->ext_l2 && qcow2->clu_size < PAGE_SIZE * 32)) diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h index 69d3ae6fca8a..a2d951ee5541 100644 --- a/drivers/md/dm-qcow2.h +++ b/drivers/md/dm-qcow2.h @@ -257,6 +257,8 @@ struct qcow2 { u32 refblock_bits; u32 refblock_entries; bool ext_l2; + bool opened_dirty; /* Dirty bit was set before we set it */ + bool kernel_dirty_bit; /* We set the dirty bit on disk */ bool pause_submitting_qios; /* This is used only on top qcow2 image */ bool backward_merge_in_process; -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel