From nobody Fri Nov 7 00:20:08 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551275212173611.1545238769527; Wed, 27 Feb 2019 05:46:52 -0800 (PST) Received: from localhost ([127.0.0.1]:44028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzXs-0000JT-4V for importer@patchew.org; Wed, 27 Feb 2019 08:46:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51423) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzUr-0005eA-DE for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:43:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyzIw-0003ws-QN for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:31:23 -0500 Received: from relay.sw.ru ([185.231.240.75]:33468) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyzIw-0003mR-Iq; Wed, 27 Feb 2019 08:31:22 -0500 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gyz2f-0004Qy-D5; Wed, 27 Feb 2019 16:14:33 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 27 Feb 2019 16:14:29 +0300 Message-Id: <20190227131433.197063-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190227131433.197063-1-vsementsov@virtuozzo.com> References: <20190227131433.197063-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v5 1/5] qcow2-refcount: fix check_oflag_copied X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, den@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Increase corruptions_fixed only after successful fix. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/qcow2-refcount.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 6f13d470d3..16e8942343 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1825,7 +1825,7 @@ static int check_oflag_copied(BlockDriverState *bs, B= drvCheckResult *res, for (i =3D 0; i < s->l1_size; i++) { uint64_t l1_entry =3D s->l1_table[i]; uint64_t l2_offset =3D l1_entry & L1E_OFFSET_MASK; - bool l2_dirty =3D false; + int l2_dirty =3D 0; =20 if (!l2_offset) { continue; @@ -1887,8 +1887,7 @@ static int check_oflag_copied(BlockDriverState *bs, B= drvCheckResult *res, l2_table[j] =3D cpu_to_be64(refcount =3D=3D 1 ? l2_entry | QCOW_OFLAG_COPIED : l2_entry & ~QCOW_OFLAG_COPIED); - l2_dirty =3D true; - res->corruptions_fixed++; + l2_dirty++; } else { res->corruptions++; } @@ -1896,7 +1895,7 @@ static int check_oflag_copied(BlockDriverState *bs, B= drvCheckResult *res, } } =20 - if (l2_dirty) { + if (l2_dirty > 0) { ret =3D qcow2_pre_write_overlap_check(bs, QCOW2_OL_ACTIVE_L2, l2_offset, s->cluster_size= ); if (ret < 0) { @@ -1914,6 +1913,7 @@ static int check_oflag_copied(BlockDriverState *bs, B= drvCheckResult *res, res->check_errors++; goto fail; } + res->corruptions_fixed +=3D l2_dirty; } } =20 --=20 2.18.0 From nobody Fri Nov 7 00:20:08 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551275817044187.4777570789056; Wed, 27 Feb 2019 05:56:57 -0800 (PST) Received: from localhost ([127.0.0.1]:44198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzhc-0007kq-Vh for importer@patchew.org; Wed, 27 Feb 2019 08:56:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzUt-0005jH-Dk for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:43:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyzIq-0003u5-Bk for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:31:17 -0500 Received: from relay.sw.ru ([185.231.240.75]:33468) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyzIq-0003mR-4F; Wed, 27 Feb 2019 08:31:16 -0500 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gyz2f-0004Qy-FH; Wed, 27 Feb 2019 16:14:33 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 27 Feb 2019 16:14:30 +0300 Message-Id: <20190227131433.197063-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190227131433.197063-1-vsementsov@virtuozzo.com> References: <20190227131433.197063-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v5 2/5] qcow2-refcount: avoid eating RAM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, den@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qcow2_inc_refcounts_imrt() (through realloc_refcount_array()) can eat an unpredictable amount of memory on corrupted table entries, which are referencing regions far beyond the end of file. Prevent this, by skipping such regions from further processing. Interesting that iotest 138 checks exactly the behavior which we fix here. So, change the test appropriately. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/qcow2-refcount.c | 19 +++++++++++++++++++ tests/qemu-iotests/138 | 12 +++++------- tests/qemu-iotests/138.out | 5 ++++- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 16e8942343..add1bbf54f 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1508,12 +1508,31 @@ int qcow2_inc_refcounts_imrt(BlockDriverState *bs, = BdrvCheckResult *res, { BDRVQcow2State *s =3D bs->opaque; uint64_t start, last, cluster_offset, k, refcount; + int64_t file_len; int ret; =20 if (size <=3D 0) { return 0; } =20 + file_len =3D bdrv_getlength(bs->file->bs); + if (file_len < 0) { + return file_len; + } + + /* + * Last cluster of qcow2 image may be semi-allocated, so it may be OK = to + * reference some space after file end but it should be less than one + * cluster. + */ + if (offset + size - file_len >=3D s->cluster_size) { + fprintf(stderr, "ERROR: counting reference for region exceeding th= e " + "end of the file by one cluster or more: offset 0x%" PRIx64 + " size 0x%" PRIx64 "\n", offset, size); + res->corruptions++; + return 0; + } + start =3D start_of_cluster(s, offset); last =3D start_of_cluster(s, offset + size - 1); for(cluster_offset =3D start; cluster_offset <=3D last; diff --git a/tests/qemu-iotests/138 b/tests/qemu-iotests/138 index eccbcae3a6..12e20762e5 100755 --- a/tests/qemu-iotests/138 +++ b/tests/qemu-iotests/138 @@ -54,15 +54,13 @@ $QEMU_IO -c 'write 0 512' "$TEST_IMG" | _filter_qemu_io # Put the data cluster at a multiple of 2 TB, resulting in the image appar= ently # having a multiple of 2^32 clusters # (To be more specific: It is at 32 PB) -poke_file "$TEST_IMG" 2048 "\x80\x80\x00\x00\x00\x00\x00\x00" +poke_file "$TEST_IMG" $((2048 + 8)) "\x00\x80\x00\x00\x00\x00\x00\x00" =20 # An offset of 32 PB results in qemu-img check having to allocate an in-me= mory -# refcount table of 128 TB (16 bit refcounts, 512 byte clusters). -# This should be generally too much for any system and thus fail. -# What this test is checking is that the qcow2 driver actually tries to al= locate -# such a large amount of memory (and is consequently aborting) instead of = having -# truncated the cluster count somewhere (which would result in much less m= emory -# being allocated and then a segfault occurring). +# refcount table of 128 TB (16 bit refcounts, 512 byte clusters), if qemu-= img +# don't check that referenced data cluster is far beyond the end of file. +# But starting from 4.0, qemu-img does this check, and instead of "Cannot +# allocate memory", we have an error showing that l2 entry is invalid. _check_test_img =20 # success, all done diff --git a/tests/qemu-iotests/138.out b/tests/qemu-iotests/138.out index 3fe911f85a..aca7d47a80 100644 --- a/tests/qemu-iotests/138.out +++ b/tests/qemu-iotests/138.out @@ -5,5 +5,8 @@ QA output created by 138 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D512 wrote 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -qemu-img: Check failed: Cannot allocate memory +ERROR: counting reference for region exceeding the end of the file by one = cluster or more: offset 0x80000000000000 size 0x200 + +1 errors were found on the image. +Data may be corrupted, or further writes to the image may corrupt it. *** done --=20 2.18.0 From nobody Fri Nov 7 00:20:08 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551275741489102.95171356857793; Wed, 27 Feb 2019 05:55:41 -0800 (PST) Received: from localhost ([127.0.0.1]:44161 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzgO-0006hT-Rs for importer@patchew.org; Wed, 27 Feb 2019 08:55:36 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51935) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzUt-00064R-Qt for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:43:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyzIg-0003nw-L2 for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:31:07 -0500 Received: from relay.sw.ru ([185.231.240.75]:33468) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyzIg-0003mR-BU; Wed, 27 Feb 2019 08:31:06 -0500 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gyz2f-0004Qy-IS; Wed, 27 Feb 2019 16:14:33 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 27 Feb 2019 16:14:31 +0300 Message-Id: <20190227131433.197063-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190227131433.197063-1-vsementsov@virtuozzo.com> References: <20190227131433.197063-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v5 3/5] qcow2-refcount: check_refcounts_l2: reduce ignored overlaps X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, den@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Reduce number of structures ignored in overlap check: when checking active table ignore active tables, when checking inactive table ignore inactive ones. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/qcow2-refcount.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index add1bbf54f..00a922edfa 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1579,7 +1579,7 @@ enum { static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res, void **refcount_table, int64_t *refcount_table_size, int64_t l2_off= set, - int flags, BdrvCheckMode fix) + int flags, BdrvCheckMode fix, bool active) { BDRVQcow2State *s =3D bs->opaque; uint64_t *l2_table, l2_entry; @@ -1663,11 +1663,12 @@ static int check_refcounts_l2(BlockDriverState *bs,= BdrvCheckResult *res, if (fix & BDRV_FIX_ERRORS) { uint64_t l2e_offset =3D l2_offset + (uint64_t)i * sizeof(uint64_t); + int ign =3D active ? QCOW2_OL_ACTIVE_L2 : + QCOW2_OL_INACTIVE_L2; =20 l2_entry =3D QCOW_OFLAG_ZERO; l2_table[i] =3D cpu_to_be64(l2_entry); - ret =3D qcow2_pre_write_overlap_check(bs, - QCOW2_OL_ACTIVE_L2 | QCOW2_OL_INACTIVE_L2, + ret =3D qcow2_pre_write_overlap_check(bs, ign, l2e_offset, sizeof(uint64_t)); if (ret < 0) { fprintf(stderr, "ERROR: Overlap check failed\n= "); @@ -1741,7 +1742,7 @@ static int check_refcounts_l1(BlockDriverState *bs, void **refcount_table, int64_t *refcount_table_size, int64_t l1_table_offset, int l1_size, - int flags, BdrvCheckMode fix) + int flags, BdrvCheckMode fix, bool active) { BDRVQcow2State *s =3D bs->opaque; uint64_t *l1_table =3D NULL, l2_offset, l1_size2; @@ -1797,7 +1798,7 @@ static int check_refcounts_l1(BlockDriverState *bs, /* Process and check L2 entries */ ret =3D check_refcounts_l2(bs, res, refcount_table, refcount_table_size, l2_offset, flags, - fix); + fix, active); if (ret < 0) { goto fail; } @@ -2083,7 +2084,7 @@ static int calculate_refcounts(BlockDriverState *bs, = BdrvCheckResult *res, /* current L1 table */ ret =3D check_refcounts_l1(bs, res, refcount_table, nb_clusters, s->l1_table_offset, s->l1_size, CHECK_FRAG_IN= FO, - fix); + fix, true); if (ret < 0) { return ret; } @@ -2106,7 +2107,8 @@ static int calculate_refcounts(BlockDriverState *bs, = BdrvCheckResult *res, continue; } ret =3D check_refcounts_l1(bs, res, refcount_table, nb_clusters, - sn->l1_table_offset, sn->l1_size, 0, fix); + sn->l1_table_offset, sn->l1_size, 0, fix, + false); if (ret < 0) { return ret; } --=20 2.18.0 From nobody Fri Nov 7 00:20:08 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551275615084775.229207297376; Wed, 27 Feb 2019 05:53:35 -0800 (PST) Received: from localhost ([127.0.0.1]:44128 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzeJ-000575-My for importer@patchew.org; Wed, 27 Feb 2019 08:53:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzUt-00057D-KM for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:43:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyzIn-0003sq-6J for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:31:13 -0500 Received: from relay.sw.ru ([185.231.240.75]:33468) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyzIm-0003mR-Uy; Wed, 27 Feb 2019 08:31:13 -0500 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gyz2f-0004Qy-Li; Wed, 27 Feb 2019 16:14:33 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 27 Feb 2019 16:14:32 +0300 Message-Id: <20190227131433.197063-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190227131433.197063-1-vsementsov@virtuozzo.com> References: <20190227131433.197063-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v5 4/5] qcow2-refcount: check_refcounts_l2: don't count fixed cluster as allocated X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, den@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Do not count a cluster which is fixed to be ZERO as allocated. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/qcow2-refcount.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 00a922edfa..35a9d943f2 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1641,15 +1641,6 @@ static int check_refcounts_l2(BlockDriverState *bs, = BdrvCheckResult *res, { uint64_t offset =3D l2_entry & L2E_OFFSET_MASK; =20 - if (flags & CHECK_FRAG_INFO) { - res->bfi.allocated_clusters++; - if (next_contiguous_offset && - offset !=3D next_contiguous_offset) { - res->bfi.fragmented_clusters++; - } - next_contiguous_offset =3D offset + s->cluster_size; - } - /* Correct offsets are cluster aligned */ if (offset_into_cluster(s, offset)) { if (qcow2_get_cluster_type(l2_entry) =3D=3D @@ -1702,6 +1693,15 @@ static int check_refcounts_l2(BlockDriverState *bs, = BdrvCheckResult *res, } } =20 + if (flags & CHECK_FRAG_INFO) { + res->bfi.allocated_clusters++; + if (next_contiguous_offset && + offset !=3D next_contiguous_offset) { + res->bfi.fragmented_clusters++; + } + next_contiguous_offset =3D offset + s->cluster_size; + } + /* Mark cluster as used */ ret =3D qcow2_inc_refcounts_imrt(bs, res, refcount_table, refcount_table_= size, --=20 2.18.0 From nobody Fri Nov 7 00:20:08 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 155127577384975.25220365635596; Wed, 27 Feb 2019 05:56:13 -0800 (PST) Received: from localhost ([127.0.0.1]:44194 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzgu-0007BX-MH for importer@patchew.org; Wed, 27 Feb 2019 08:56:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51122) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzUt-00057B-Nm for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:43:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyzIk-0003r5-1P for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:31:10 -0500 Received: from relay.sw.ru ([185.231.240.75]:33468) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyzIj-0003mR-N9; Wed, 27 Feb 2019 08:31:09 -0500 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gyz2f-0004Qy-Na; Wed, 27 Feb 2019 16:14:33 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 27 Feb 2019 16:14:33 +0300 Message-Id: <20190227131433.197063-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190227131433.197063-1-vsementsov@virtuozzo.com> References: <20190227131433.197063-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v5 5/5] qcow2-refcount: don't mask corruptions under internal errors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, den@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No reasons for not reporting found corruptions as corruptions in case of some internal errors, especially in case of just failed to fix l2 entry (and in this case, missed corruptions may influence comparing logic, when we calculate difference between corruptions fields of two results) Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block/qcow2-refcount.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 35a9d943f2..55dad70a2a 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1643,6 +1643,8 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, =20 /* Correct offsets are cluster aligned */ if (offset_into_cluster(s, offset)) { + res->corruptions++; + if (qcow2_get_cluster_type(l2_entry) =3D=3D QCOW2_CLUSTER_ZERO_ALLOC) { @@ -1678,18 +1680,16 @@ static int check_refcounts_l2(BlockDriverState *bs,= BdrvCheckResult *res, /* Do not abort, continue checking the rest of= this * L2 table's entries */ } else { + res->corruptions--; res->corruptions_fixed++; /* Skip marking the cluster as used * (it is unused now) */ continue; } - } else { - res->corruptions++; } } else { fprintf(stderr, "ERROR offset=3D%" PRIx64 ": Data clus= ter is " "not properly aligned; L2 entry corrupted.\n", off= set); - res->corruptions++; } } =20 @@ -1858,6 +1858,7 @@ static int check_oflag_copied(BlockDriverState *bs, B= drvCheckResult *res, continue; } if ((refcount =3D=3D 1) !=3D ((l1_entry & QCOW_OFLAG_COPIED) !=3D = 0)) { + res->corruptions++; fprintf(stderr, "%s OFLAG_COPIED L2 cluster: l1_index=3D%d " "l1_entry=3D%" PRIx64 " refcount=3D%" PRIu64 "\n", repair ? "Repairing" : "ERROR", i, l1_entry, refcount); @@ -1870,9 +1871,8 @@ static int check_oflag_copied(BlockDriverState *bs, B= drvCheckResult *res, res->check_errors++; goto fail; } + res->corruptions--; res->corruptions_fixed++; - } else { - res->corruptions++; } } =20 @@ -1900,6 +1900,7 @@ static int check_oflag_copied(BlockDriverState *bs, B= drvCheckResult *res, continue; } if ((refcount =3D=3D 1) !=3D ((l2_entry & QCOW_OFLAG_COPIE= D) !=3D 0)) { + res->corruptions++; fprintf(stderr, "%s OFLAG_COPIED data cluster: " "l2_entry=3D%" PRIx64 " refcount=3D%" PRIu64 "= \n", repair ? "Repairing" : "ERROR", l2_entry, refc= ount); @@ -1908,8 +1909,6 @@ static int check_oflag_copied(BlockDriverState *bs, B= drvCheckResult *res, ? l2_entry | QCOW_OFLAG_COPIED : l2_entry & ~QCOW_OFLAG_COPIED); l2_dirty++; - } else { - res->corruptions++; } } } @@ -1933,6 +1932,7 @@ static int check_oflag_copied(BlockDriverState *bs, B= drvCheckResult *res, res->check_errors++; goto fail; } + res->corruptions -=3D l2_dirty; res->corruptions_fixed +=3D l2_dirty; } } @@ -1971,6 +1971,7 @@ static int check_refblocks(BlockDriverState *bs, Bdrv= CheckResult *res, } =20 if (cluster >=3D *nb_clusters) { + res->corruptions++; fprintf(stderr, "%s refcount block %" PRId64 " is outside imag= e\n", fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i); =20 @@ -2010,6 +2011,7 @@ static int check_refblocks(BlockDriverState *bs, Bdrv= CheckResult *res, goto resize_fail; } =20 + res->corruptions--; res->corruptions_fixed++; ret =3D qcow2_inc_refcounts_imrt(bs, res, refcount_table, nb_clusters, @@ -2023,12 +2025,9 @@ static int check_refblocks(BlockDriverState *bs, Bdr= vCheckResult *res, continue; =20 resize_fail: - res->corruptions++; *rebuild =3D true; fprintf(stderr, "ERROR could not resize image: %s\n", strerror(-ret)); - } else { - res->corruptions++; } continue; } --=20 2.18.0