[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 26/32] qcow2-refcount: fix_l2_entry_by_zero(): also zero L2 entry
From: |
Hanna Reitz |
Subject: |
[PULL 26/32] qcow2-refcount: fix_l2_entry_by_zero(): also zero L2 entry bitmap |
Date: |
Wed, 15 Sep 2021 19:53:12 +0200 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
We'll reuse the function to fix wrong L2 entry bitmap. Support it now.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20210914122454.141075-6-vsementsov@virtuozzo.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
---
block/qcow2-refcount.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 184b96ad63..f48c5e1b5d 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -1588,7 +1588,8 @@ enum {
};
/*
- * Fix L2 entry by making it QCOW2_CLUSTER_ZERO_PLAIN.
+ * Fix L2 entry by making it QCOW2_CLUSTER_ZERO_PLAIN (or making all its
present
+ * subclusters QCOW2_SUBCLUSTER_ZERO_PLAIN).
*
* This function decrements res->corruptions on success, so the caller is
* responsible to increment res->corruptions prior to the call.
@@ -1605,9 +1606,20 @@ static int fix_l2_entry_by_zero(BlockDriverState *bs,
BdrvCheckResult *res,
int idx = l2_index * (l2_entry_size(s) / sizeof(uint64_t));
uint64_t l2e_offset = l2_offset + (uint64_t)l2_index * l2_entry_size(s);
int ign = active ? QCOW2_OL_ACTIVE_L2 : QCOW2_OL_INACTIVE_L2;
- uint64_t l2_entry = has_subclusters(s) ? 0 : QCOW_OFLAG_ZERO;
- set_l2_entry(s, l2_table, l2_index, l2_entry);
+ if (has_subclusters(s)) {
+ uint64_t l2_bitmap = get_l2_bitmap(s, l2_table, l2_index);
+
+ /* Allocated subclusters become zero */
+ l2_bitmap |= l2_bitmap << 32;
+ l2_bitmap &= QCOW_L2_BITMAP_ALL_ZEROES;
+
+ set_l2_bitmap(s, l2_table, l2_index, l2_bitmap);
+ set_l2_entry(s, l2_table, l2_index, 0);
+ } else {
+ set_l2_entry(s, l2_table, l2_index, QCOW_OFLAG_ZERO);
+ }
+
ret = qcow2_pre_write_overlap_check(bs, ign, l2e_offset, l2_entry_size(s),
false);
if (metadata_overlap) {
--
2.31.1
- [PULL 14/32] iotests/297: Cover tests/, (continued)
- [PULL 14/32] iotests/297: Cover tests/, Hanna Reitz, 2021/09/15
- [PULL 08/32] iotests: Fix unspecified-encoding pylint warnings, Hanna Reitz, 2021/09/15
- [PULL 19/32] qcow2: refactor handle_dependencies() loop body, Hanna Reitz, 2021/09/15
- [PULL 18/32] simplebench: add img_bench_templater.py, Hanna Reitz, 2021/09/15
- [PULL 21/32] qemu-img: Allow target be aligned to sector size, Hanna Reitz, 2021/09/15
- [PULL 20/32] qcow2: handle_dependencies(): relax conflict detection, Hanna Reitz, 2021/09/15
- [PULL 22/32] qcow2-refcount: improve style of check_refcounts_l2(), Hanna Reitz, 2021/09/15
- [PULL 23/32] qcow2: compressed read: simplify cluster descriptor passing, Hanna Reitz, 2021/09/15
- [PULL 24/32] qcow2: introduce qcow2_parse_compressed_l2_entry() helper, Hanna Reitz, 2021/09/15
- [PULL 25/32] qcow2-refcount: introduce fix_l2_entry_by_zero(), Hanna Reitz, 2021/09/15
- [PULL 26/32] qcow2-refcount: fix_l2_entry_by_zero(): also zero L2 entry bitmap,
Hanna Reitz <=
- [PULL 27/32] qcow2-refcount: check_refcounts_l2(): check l2_bitmap, Hanna Reitz, 2021/09/15
- [PULL 28/32] qcow2-refcount: check_refcounts_l2(): check reserved bits, Hanna Reitz, 2021/09/15
- [PULL 29/32] qcow2-refcount: improve style of check_refcounts_l1(), Hanna Reitz, 2021/09/15
- [PULL 30/32] qcow2-refcount: check_refcounts_l1(): check reserved bits, Hanna Reitz, 2021/09/15
- [PULL 31/32] qcow2-refcount: check_refblocks(): add separate message for reserved, Hanna Reitz, 2021/09/15
- [PULL 32/32] qemu-img: Add -F shorthand to convert, Hanna Reitz, 2021/09/15
- Re: [PULL 00/32] Block patches, Peter Maydell, 2021/09/16