From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from OSPPR02CU001.outbound.protection.outlook.com (mail-norwayeastazon11023122.outbound.protection.outlook.com [40.107.159.122]) by lore.virtuozzo.com (Postfix) with ESMTPS id 51A458017D for ; Mon, 26 Oct 2026 19:37:23 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vZQWrfGBFd3GaDy9ezr7u1x1BrQWdddaIOoEfkh/uxPcoLT7+l3ByMBHQQL4hma2GA+7xK99tLXk2CEiYf/6fmMDgMJBcW6BWa4dETyVBycTR9gojf/0oQKet/8UH8JnzAvK/wNDDkRiEkmx/MIbFKbLh2vEGjReXRrDL2zHMVMDyfqTCMWD75IuLiHsJYWJ88uX/Q6D5o3SBz9gf19+LR1tmUU08fgSckgB470iAbqD//Cdy+eP1trDA3tA/inDqLRDGmjhuT61BdrLwqqFtP+L9da2Z1HP/AAHkhB7AGTFmCcTBJqruD0BgukII6oDqdQXxdP3GClDzo01zVK24A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=f+XENwcdpm//4QCtU6J1v6HyfBWU5oDYVwfMO5H2rJI=; b=cBTpD4y4rp6lVnqyAkGRs2pxYtgrEGDxt1J6lsRMIWgSOzsEKGZyX+4tpwIAoBVtw1h2WvxJiTYZp6fsMcUBl8PhY11aOvuI/PDPzIbjAWcOyGuBP2ModLoPB6oXeNbgj7Eop0omHWhRddqReWfxQ9IY9W7ly3XYKFwFDJscFlsziEZXNElrEZ13lowKmEyEM1nOdfV56mSDsKycGYyzrHkk1P7h7rBSeyEOFq4ZDwp2AhqZVfR9Uxi5+hBFd5mKVPp6+RNerFJtC0iMC49iF2DLM/GIrLNHm5lnlrkKlRVAjxQJSpvlRloAsgDg/dyzAJ4LwloPLLCNb620oOdaQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 2a00:1450:4864:20::433) smtp.rcpttodomain=virtuozzo.com smtp.mailfrom=openvz.org; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=openvz.org; dkim=pass (signature was verified) header.d=openvz.org; arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.onmicrosoft.com; s=selector2-virtuozzo-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f+XENwcdpm//4QCtU6J1v6HyfBWU5oDYVwfMO5H2rJI=; b=YZRRTH1pISW4VIAJfupU9WKzihvRwgDR9BDyjaU50tYvU0Jxt7pPnoOGmLQZqC0x3YsoTZSWUJe50GuSOz1O6PVyIKEmDhwGYoEXe4MVDM4Z5Fdi6s5X4Aefs6adTGbTd1WRnDO3OZKQ8tBE47Xq08wSdBAl4eJwf4KjqWO5o8Q= Received: from OS6P279CA0100.NORP279.PROD.OUTLOOK.COM (2603:10a6:e10:3d::11) by AM0PR08MB5474.eurprd08.prod.outlook.com (2603:10a6:208:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.546.22; Mon, 26 Oct 2026 19:37:20 +0000 Received: from CPH1EPF00000521.eurprd05.prod.outlook.com (2603:10a6:e10:3d:cafe::67) by OS6P279CA0100.outlook.office365.com (2603:10a6:e10:3d::11) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.546.22 via Frontend Transport; Mon, 26 Oct 2026 19:37:20 +0000 Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 2a00:1450:4864:20::433) smtp.mailfrom=openvz.org; dkim=pass (signature was verified) header.d=openvz.org;dmarc=pass action=none header.from=openvz.org; Received-SPF: Pass (protection.outlook.com: domain of openvz.org designates 2a00:1450:4864:20::433 as permitted sender) receiver=protection.outlook.com; client-ip=2a00:1450:4864:20::433; helo=mail-wr1-x433.google.com; pr=C Received: from mail-wr1-x433.google.com (2a00:1450:4864:20::433) by CPH1EPF00000521.mail.protection.outlook.com (2603:10a6:388::1e4) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.569.4 via Frontend Transport; Mon, 26 Oct 2026 19:37:19 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-48e47347279so1322410f8f.1 for ; Mon, 26 Oct 2026 12:37:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793043439; x=1793648239; darn=virtuozzo.com; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=f+XENwcdpm//4QCtU6J1v6HyfBWU5oDYVwfMO5H2rJI=; b=kSi6LZeJXg62mSgwyXTK7uJv9VWADVfHvcUO8iqv7HNCDhIhJVLuY/frBTQtEsji90 /YUlMBoZhlrUnziH9btxN3Cfo0QX0cr4fnzvDsPK3BNfXsnMp4DBeXM+b0fbdeL3Qx3Q I49vWnTpSJtm5P2f3SijGhtP9RYn46K/uBUCfSw0c99ELd8Y/MSpXBn0DHtgBxGDDCD5 RGOMTeaWpVq/43AEZZyN9xrWUlo8JZKSrSGUUP2Ggrrf6asHQFzj04JviJbrhUlOuLZQ s2ZIbKY+xbn1r/Mb3NbhdNcLrocjTiAVsrutDBiC5Ss6Wed5wmLNUD63GxaYsmcCcfTr I6lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793043439; x=1793648239; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=f+XENwcdpm//4QCtU6J1v6HyfBW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gh56j8o8qmYLynyWgDcBph4h1BEl/E1w= X-Received: by 2002:a05:6000:1610:b0:48e:548c:1356 with SMTP id ffacd0b85a97d-48e548c135fmr2346511f8f.56.1793043439319; Mon, 26 Oct 2026 12:37:19 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:1a6:7f7f:f573:ba9e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e3ecd3555sm17641792f8f.42.2026.10.26.12.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2026 12:37:18 -0700 (PDT) From: "Denis V. Lunev" To: andrey.drobyshev@virtuozzo.com Cc: svt-core@virtuozzo.com, den@openvz.org Subject: [PATCH hci-8.1 1/1] qcow2: fix subcluster discard punching data shared with a snapshot #VSTOR-144873 Date: Mon, 26 Oct 2026 20:37:15 +0100 Message-ID: <20261026193715.828224-2-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261026193715.828224-1-den@openvz.org> References: <20261026193715.828224-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-EOPTenantAttributedMessage: 0bc7f26d-0264-416e-a6fc-8352af79c58f:0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CPH1EPF00000521:EE_|AM0PR08MB5474:EE_ X-MS-Office365-Filtering-Correlation-Id: 99a1f4e7-5e64-45ac-e54a-08df33988cde X-LD-Processed: 0bc7f26d-0264-416e-a6fc-8352af79c58f,ExtAddr X-MS-Exchange-AtpMessageProperties: SA X-MS-Exchange-SenderADCheck: 0 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|48200799018|82310400026|6059299003|61400799027|9140799003|43022699015|22082099003|18002099003|261026121527099003|16102099003|55112099003|5023799004|56012099006|5063699009|261021121427099003|261022115727099003|10067099003|261021123027099003|261022075727099003|261009223027099003; X-Microsoft-Antispam-Message-Info: Udn02B3WQt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040)(376014)(48200799018)(82310400026)(6059299003)(61400799027)(9140799003)(43022699015)(22082099003)(18002099003)(261026121527099003)(16102099003)(55112099003)(5023799004)(56012099006)(5063699009)(261021121427099003)(261022115727099003)(10067099003)(261021123027099003)(261022075727099003)(261009223027099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xDzCYU+XSEKCye19X6nDB4NmL/u3CySpRhuCOfWYS7VR+9r3PM66USxeMQf5JL6sLhacq98qr894ngogma/U09wiT8cOWSV5/miI+kbu7/oTjGoUmYl81yR2YYj2PTn0td12Q7QFjLFl+2hByDU9uxU3cfnndWl0azYeVPS/0CiZsLmx+Wn+hBZ2F4OeDf/W6MVz5vYlde7KPWxVX+PP/jqSp3E6a4ACpOBuBXeryDea4vQBkgu5u0HZkxj5vmBezI4mzWMSxaqiI5uiAudgjdc9jMoojNkqePKzFm0zlUVQwx/zU6DIc3Zg6mbcytWF9r+he2KwyCqJ5zj15jp3TPXmd/z9IoSRnvwwWDPjOrGUE2uDI7WEE6BSoJcqu7e58PNa35h7bOTyia3ZlF/OXlhu4hq9LGTGEFWaG5i7KPTO12LPmnJDJPSWTaq4ImyN X-ExternalRecipientOutboundConnectors: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-Auto-Response-Suppress: DR, OOF, AutoReply X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Oct 2026 19:37:19.9838 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 99a1f4e7-5e64-45ac-e54a-08df33988cde X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-AuthSource: CPH1EPF00000521.eurprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB5474 List-Id: From: Denis V. Lunev discard_l2_subclusters() passes the discarded range down to the host file even when the cluster is still referenced by an internal snapshot. The active L2 table is copied before it is changed, so the snapshot metadata stays correct, but the host range under it is punched out and the snapshot reads zeroes there afterwards. qemu-img check finds nothing wrong. Pass the discard down only for a cluster with QCOW_OFLAG_COPIED set, i.e. one owned by the active layer alone. A shared cluster gets only its active L2 bitmap updated, as a whole-cluster discard already does by dropping the refcount instead of punching the host file. Cover it in iotest 271. Fixes: 225b4de1249 ("qcow2: make subclusters discardable") Signed-off-by: Denis V. Lunev --- block/qcow2-cluster.c | 10 +++++++--- tests/qemu-iotests/271 | 18 ++++++++++++++++++ tests/qemu-iotests/271.out | 5 +++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index e40995904b5..dfe728cd8a5 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -2196,9 +2196,13 @@ discard_l2_subclusters(BlockDriverState *bs, uint64_t offset, qcow2_cache_entry_mark_dirty(s->l2_table_cache, scri.l2_slice); } - discard_no_unref_any_file( - bs, (scri.l2_entry & L2E_OFFSET_MASK) + offset_into_cluster(s, offset), - nb_subclusters * s->subcluster_size, scri.ctype, type); + /* A cluster shared with a snapshot must keep its data */ + if (scri.l2_entry & QCOW_OFLAG_COPIED) { + discard_no_unref_any_file( + bs, + (scri.l2_entry & L2E_OFFSET_MASK) + offset_into_cluster(s, offset), + nb_subclusters * s->subcluster_size, scri.ctype, type); + } return 0; } diff --git a/tests/qemu-iotests/271 b/tests/qemu-iotests/271 index 026a40cdaed..2f60fb5fc96 100755 --- a/tests/qemu-iotests/271 +++ b/tests/qemu-iotests/271 @@ -605,6 +605,24 @@ done ############################################################ ############################################################ +echo +echo "### Discarding subclusters shared with an internal snapshot ###" +echo + +_make_test_img -o extended_l2=on 1M +$QEMU_IO -c "write -q -P 0xab 0 64k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG snapshot -c snap "$TEST_IMG" +$QEMU_IO -c "discard -q 0 4k" -c "write -q -z -u 8k 4k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -q -P 0 0 4k" -c "read -q -P 0xab 4k 4k" \ + -c "read -q -P 0 8k 4k" "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG snapshot -a snap "$TEST_IMG" +$QEMU_IO -c "read -q -P 0xab 0 64k" "$TEST_IMG" | _filter_qemu_io +_check_test_img + +############################################################ +############################################################ +############################################################ + # Test that corrupted L2 entries are detected in both read and write # operations for corruption_test_cmd in read write; do diff --git a/tests/qemu-iotests/271.out b/tests/qemu-iotests/271.out index c03e4c9bc2a..e7970d33516 100644 --- a/tests/qemu-iotests/271.out +++ b/tests/qemu-iotests/271.out @@ -504,6 +504,11 @@ Image resized. Image resized. L2 entry #1: 0x0000000000000000 0000000000000000 +### Discarding subclusters shared with an internal snapshot ### + +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576 +No errors were found on the image. + ### Corrupted L2 entries - read test (allocated) ### # 'cluster is zero' bit set on the standard cluster descriptor -- 2.53.0