Skip to content

Commit 5c3216c

Browse files
Vladimir Sementsov-OgievskiyXanClic
authored andcommitted
qcow2-refcount: fix_l2_entry_by_zero(): also zero L2 entry bitmap
We'll reuse the function to fix wrong L2 entry bitmap. Support it now. Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]> Reviewed-by: Eric Blake <[email protected]> Reviewed-by: Hanna Reitz <[email protected]> Message-Id: <[email protected]> Signed-off-by: Hanna Reitz <[email protected]>
1 parent a2debf6 commit 5c3216c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

block/qcow2-refcount.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,8 @@ enum {
15881588
};
15891589

15901590
/*
1591-
* Fix L2 entry by making it QCOW2_CLUSTER_ZERO_PLAIN.
1591+
* Fix L2 entry by making it QCOW2_CLUSTER_ZERO_PLAIN (or making all its present
1592+
* subclusters QCOW2_SUBCLUSTER_ZERO_PLAIN).
15921593
*
15931594
* This function decrements res->corruptions on success, so the caller is
15941595
* responsible to increment res->corruptions prior to the call.
@@ -1605,9 +1606,20 @@ static int fix_l2_entry_by_zero(BlockDriverState *bs, BdrvCheckResult *res,
16051606
int idx = l2_index * (l2_entry_size(s) / sizeof(uint64_t));
16061607
uint64_t l2e_offset = l2_offset + (uint64_t)l2_index * l2_entry_size(s);
16071608
int ign = active ? QCOW2_OL_ACTIVE_L2 : QCOW2_OL_INACTIVE_L2;
1608-
uint64_t l2_entry = has_subclusters(s) ? 0 : QCOW_OFLAG_ZERO;
16091609

1610-
set_l2_entry(s, l2_table, l2_index, l2_entry);
1610+
if (has_subclusters(s)) {
1611+
uint64_t l2_bitmap = get_l2_bitmap(s, l2_table, l2_index);
1612+
1613+
/* Allocated subclusters become zero */
1614+
l2_bitmap |= l2_bitmap << 32;
1615+
l2_bitmap &= QCOW_L2_BITMAP_ALL_ZEROES;
1616+
1617+
set_l2_bitmap(s, l2_table, l2_index, l2_bitmap);
1618+
set_l2_entry(s, l2_table, l2_index, 0);
1619+
} else {
1620+
set_l2_entry(s, l2_table, l2_index, QCOW_OFLAG_ZERO);
1621+
}
1622+
16111623
ret = qcow2_pre_write_overlap_check(bs, ign, l2e_offset, l2_entry_size(s),
16121624
false);
16131625
if (metadata_overlap) {

0 commit comments

Comments
 (0)