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 D40858017D for ; Mon, 26 Oct 2026 14:44:06 +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 69QEgpLE011707; Mon, 26 Oct 2026 17:42:52 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69QEgpLE011707 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="MzE+PJZp" Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 69QEgTu2011656 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 26 Oct 2026 17:42:29 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69QEgTu2011656 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4a77c1cbd15so2422055e9.0 for ; Mon, 26 Oct 2026 07:42:29 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBw/H9NO6dxI5BvE++mHHPhRJNTwQtDWO/MHJiAMAS3Lee420wxt5mzGvfJ7D+JsMbG3d32PDw==@openvz.org X-Gm-Message-State: AFq9FYLoij12NmIWMsfqb+j9HkEzW1LO3NB/IcJYqHLOTEap/X3ehyY4 UCiNfWmu4BCY4WAtcFzejQXWOo3uOrD1//m5siG93aV0Ze9v/IUU8+L+jaQG4aMaS8VZStgy4Cp 4/LZAk+61rdp7EZbjVdn/GfoKjIibiCNOpgPLMXzNwLX1eQlc9cCS9A== X-Gm-Gg: AYBFou2lp1H+cGnQku0A9IsxBFkVAb+ny1jJ1tv/VE8xoCaMlh99XmT5TbmHwXPwrhM avJvyAzWMwk0o6dFBegM1TVAQE5HHWrdA6sd+uvJ+7yyMpKGZ50i9eIgxAOoHLa6GWm/yD9hPu2 byG2fn7e7hTLRELRLpmfPNwoCZWrg4fYbV8zr5kDRo6KkyWmFBf/imianRCGczqhjTd6A8lV3rD ioy0GCY02Pklh3WjDBgQAaUEhsyK+8IwgCZ9MRrvdwqceVWxVoEGcBYV94vX1d27KeaX9U17GVF rYVjNhcf7dTLuQ2sx7wkZo0i9nd7nPbv4mDiBOOOYiQrvsbJ+mKftak7w6dfvtaun0X2DPm4xyZ cwKAka+oMmvLRq+Gogk55FPCWtHs= X-Received: by 2002:a05:600c:3b93:b0:4a2:fe3:121b with SMTP id 5b1f17b1804b1-4a35acb0791mr143652865e9.28.1793025748916; Mon, 26 Oct 2026 07:42:28 -0700 (PDT) X-Received: by 2002:a05:600c:3b93:b0:4a2:fe3:121b with SMTP id 5b1f17b1804b1-4a35acb0791mr143652365e9.28.1793025748346; Mon, 26 Oct 2026 07:42:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1793025748; cv=none; d=google.com; s=arc-20260327; b=etyx6Ln0dIQjUehQJbB8EzNHdFesc7vCYH6NrJhMoxr5AGbr2xfzEP2lSrfN1Y3qNe QtsBwZT9xZg0S2EIpEgsBnYcBsd9pC4E6VDPMh5JPaEhGBQh6aXp+EC/dqYsXbibSvKw tayVJ/TyeEKG5Bjikm47WtGEXSOsFyEFb6m3QQ72KRvKm9IXvTkdH5BCZqrkL5HMCzBl X62sOxzM5IvEzvmIUmaeL8SBAjmPIPdzHuNUXOBJFSVEfk1xSYORD9L0Gr5X8A+4oJB2 3VAqm1Sn9D4ebkU2Gu8lk6jyfgMAqKVTcnUxJqykNP3w5YsqP4vq2HWx4PYQ4msCYsll kBRg== 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=OIIQ3EbfrjolcrWMHFFXM4icXSL2Ry7/Y+ee5SpW7c6rnfEuWgZmkcUJY9790EK1MB ile+w/NNGi8m+y3vizjBB7490F0V9YSm17a2k3ZaUoP01zBrUB53CCEAWq3csfTg7Raj cpRg7/s66Iu6kK3GeMKgzNztxGYqlHb/Kc1p0jIG6zH/gf1Rv1LdrZgmmhm713wuqwjJ yRd3R+NDxZKcgcqtED5uLrGrqR+McfWYN/CWbOgetYnKEQhMj6oXwM6TvVkKUWqqV+7x XAySP999h6S57u9g4+QvdiCSKcBnrNhE1WxDnXPJQaKawrKcplxAJIe90sPn7IaL9iOy U+uQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=MzE+PJZp; 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-48e5244761bsi5180229f8f.343.2026.10.26.07.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2026 07:42:28 -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=MzE+PJZp; 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=MzE+PJZpExRr oyE0QHDQgMn8Z2/3gi6rLgDrDyszCwfUarkmMH3f5jTO02JTMBUWkGeq1Eez2xHCHGAeZ6ZgxxVdo Fioht9QXy9oKwxjP+SlfgST90CpvjPCGfEYhWDiYwfeuZSVFvZM2oePWtvpwwUVNZaB08mAH3nZk8 nPL0jwQeUdhwD9+OXRNsfSkQYVUtHWWWo5VnkT/O33myFKJ1DakVkh+q1HcX65okLoEcY8nyCU93c PJIW6+zh+mYE1kO8EcfkraDg9TbCB1R7heIR/ObXcfvXUxajI5rc8hioOIYCCaHoRgUkAXE4d89se VItzVESHSdhLTVA8Ce7RkA==; 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 1xLLqO-004nT9-1D; Mon, 26 Oct 2026 15:42:19 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Mon, 26 Oct 2026 15:42:22 +0100 Message-ID: <20261026144223.2787145-6-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261026144223.2787145-1-alexander.ivanov@virtuozzo.com> References: <20261026144223.2787145-1-alexander.ivanov@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v8 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