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 08F9B813D0 for ; Mon, 9 Nov 2026 14:03:49 +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 6A9E2ZQO032615; Mon, 9 Nov 2026 17:02:36 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A9E2ZQO032615 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="v2xcxfDz" 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 6A9E1nDp032531 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 9 Nov 2026 17:01:49 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A9E1nDp032531 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4a20fd059ddso7085755e9.0 for ; Mon, 09 Nov 2026 06:01:49 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFS5DQil2hdKQZDSU/I4M4tAbkbcRdTQyjl66zqDVU1YrEDxU/QMCWqrF2ChRW+uE+jlg5XAQ==@openvz.org X-Gm-Message-State: APuU4Z/HrzpWfkPGuptM2MsgY+cvkX4MCO+OMy5LZvS0nKordxUpWRtw 4MslYMTCbNL61A8tqr5uM4qF448nlKbo3L8R4bhKmxcUX9owvXA8j5eVzNZncGZUrPI0UNGkMIc UMnY8fLcjkhPWji4QshKVGeO136QVzb4AwEBfiyRixZj+0i9kfCTqRA== X-Gm-Gg: AYBFou0UVGr/bPMcsSVmJLcqNbDujnDD/d1fH404z8S3+pcedWJGvE2DAGT5/D4G5kZ mD5vMTp9eMaAdoHbJXqcQ69n6kIPn4fjCHPshdmxLCaOw7qAqa2F/iNpAf32L+x0AxYRfFRov+P 3lbUOpQ33LunCnMC+nGdMtN5OxR6Qd+MRUeJHWcOhPxOZpXkBvnAYfhSZXq4MKE0Vpt5yiOGhVr 5DJIk36cxm89Peg1cxA43FzTv2FuG+pVidgvN4J0fW9JoooTJDq9RZR+7noaNfgd5rv7PXZpiQ1 mrc+Y332/Hagk0YSy754WEsV+1hsUgkfxWp80Fl0UHMlNCsTPnAxkQAa5cwM1GQDEtTkuC7sW/l sk+lqnG/qZ3WzrcxgExAVeNO/ONM= X-Received: by 2002:a05:600c:3b04:b0:4a2:e0c:2b0a with SMTP id 5b1f17b1804b1-4b960e9a794mr78733245e9.16.1794232908203; Mon, 09 Nov 2026 06:01:48 -0800 (PST) X-Received: by 2002:a05:600c:3b04:b0:4a2:e0c:2b0a with SMTP id 5b1f17b1804b1-4b960e9a794mr78731935e9.16.1794232906984; Mon, 09 Nov 2026 06:01:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794232906; cv=none; d=google.com; s=arc-20260327; b=gbnCx62EtOhaOnzwAvj3Cvid9OZcIG8uROqhIWlUVtY8G1W+tKLiPgLbRpucywDX2E ZsfZ0Z+CbQzl6wvn4LuIb5y4mAvqBG3h5Hf2RSSGDC3fXILIUNM784C3XlB2A+RqI0DS L+34kcdNnxWERL81FBfmgWYdzaj6tE/jLIL48O9BV/xdCh2Dd3X1TxrhKA9UoEiLTCGj FA/4iybJRPOWyRGlAiYbHFV3dO6weqLeS9m/1rSDc35pm7xfb1SDEBkCWRvySsoznOjM pctk2Ll2qZ8K0HUoDbVBUpv9nLhZfsxHFi1yrp76YeTBNy8kIrApZUV5mrhQ5yAR9olq Mrew== 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=IfirJ8sjauDKbUpKiQTRfzTow3oSJPxUUnJ46nu7doI=; fh=CMILZ+goaghq6B4UpCDhf0EQp6kYD0LAlmOkUiVCOvs=; b=m5/l14uJKC2khhfwPL5H3qc8OB+oR2GevRjreOwFmEVviwPyapFHIs8L9M0oED4GNe NP6bNPQ+W0ieOwPLmi0fpiq0eSQDVDbhx/kHDIpRYsWPo/BKDw+Fx5A/P9fV4aJMBPCY R/5De3uVTbCyiUyM4hWgZzAf5CitjDOQ3Ho8cVvMh3CIOOPYhrMkmt8Knn4HpXPVT0jW 6oTEoz2XHYVrigTREhFF02GA9Lotdi0Fl8mTWCzyh1IdYq3JQuKfvMNKLxUYdt1RHA4r Z4h5e9re4esbc+yq9xObdprb0MsbrWUQGxzVxApnQ6XTz9X1Zl7AE1Df7zuXQcalNUPE tdzQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=v2xcxfDz; 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 5b1f17b1804b1-4b90ee128a1si89563415e9.11.2026.11.09.06.01.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2026 06:01:46 -0800 (PST) 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=v2xcxfDz; 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=IfirJ8sjauDKbUpKiQTRfzTow3oSJPxUUnJ46nu7doI=; b=v2xcxfDzVcyQ m6O3N5BmaNEBcnJ125d1PAfQn4kLO2DTJdiSZSyAb28D2Sv8kj7iomGtUVPwd8LUdSyy92duCtGDO ZZlWJUXVSYeu4k8oStU1vUdWoF/qmAEvU7ZRCsFDPiJeF+nz36Qp9NkEVch7rVrpo3bzYYvckeoMl IqjOpHsfai6fToFShZ6pF5JOuzXSgp08X5DEbidFQ5YtVIXLa72QZenbgwuGYQ7HMvXxN9grRIm8Q MafKWIfWZ/SfC3UoQVKSmALRvrAThHHN+73TAW6OBgrhDsMFkzDQtz3yLhzk14bNlEKC1zxxchIf0 OK+LIId4ScpEIKOeP9RrcA==; 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 1xQPsM-005vFF-0j; Mon, 09 Nov 2026 15:01:38 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Mon, 9 Nov 2026 15:01:39 +0100 Message-ID: <20261109140143.1408038-7-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261109140143.1408038-1-alexander.ivanov@virtuozzo.com> References: <20261109140143.1408038-1-alexander.ivanov@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v11 06/10] dm-qcow2: keep the dirty bit of an image that needs check 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 The dm-qcow2 module parameter kernel_sets_dirty_bit makes the kernel set the dirty bit on resume and clear it on postsuspend. It is off by default and Virtuozzo does not set it: ploop manages the dirty bit from userspace itself. So this is a hardening patch for the non-default mode. 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. The same happens after an error that sets wants_check, e.g. md_writeback_error: it is kept only in the target, so resume is refused, but after a table reload or a host restart the image is reopened with a clean header. Clear the bit only if the image was clean before the kernel set it and wants_check is not set. The parsed header can't tell the former: 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_set 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_set 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. 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 | 14 ++++++++++++-- drivers/md/dm-qcow2.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c index bb322254cea9..6824d95193ae 100644 --- a/drivers/md/dm-qcow2-target.c +++ b/drivers/md/dm-qcow2-target.c @@ -666,6 +666,7 @@ int qcow2_set_image_file_features(struct qcow2 *qcow2, bool dirty) u64 dirty_mask = cpu_to_be64(INCOMPATIBLE_FEATURES_DIRTY_BIT); struct QCowHeader *raw_hdr; struct md_page *md; + int ret; if (qcow2->hdr.version == 2) return 0; @@ -682,12 +683,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 && !qcow2_wants_check(qcow2->tgt)) 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_set = dirty && !ret; + return ret; } ALLOW_ERROR_INJECTION(qcow2_set_image_file_features, ERRNO); @@ -911,6 +915,12 @@ static int qcow2_parse_header(struct dm_target *ti, struct qcow2 *qcow2, goto out; qcow2_calc_cached_parameters(qcow2, hdr); + if (!(hdr->incompatible_features & INCOMPATIBLE_FEATURES_DIRTY_BIT)) { + qcow2->opened_dirty = false; + qcow2->kernel_dirty_bit_set = false; + } else if (!qcow2->kernel_dirty_bit_set) { + 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 5abc7f5ad239..2a6203c86e3a 100644 --- a/drivers/md/dm-qcow2.h +++ b/drivers/md/dm-qcow2.h @@ -259,6 +259,8 @@ struct qcow2 { u32 refblock_bits; u32 refblock_entries; bool ext_l2; + bool opened_dirty; + bool kernel_dirty_bit_set; 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