mbox series

[v2,0/2] qcow2: Improve refcount structure rebuilding

Message ID 20220329091917.24512-1-hreitz@redhat.com (mailing list archive)
Headers show
Series qcow2: Improve refcount structure rebuilding | expand

Message

Hanna Czenczek March 29, 2022, 9:19 a.m. UTC
Hi,

v1 cover letter:
https://lists.nongnu.org/archive/html/qemu-block/2021-03/msg00651.html

Since it’s been a while since v1, let me reproduce parts from that cover
letter here:


When the qcow2 refcount structure is broken to a point where we cannot
rely on any information from it (because it shows clusters as free that
are in use), “qemu-img check -r all” completely rewrites it.

The new reftable is preferably written into the area covered by the last
refblock for the image, but if that refblock is empty (e.g. because the
image is on a block device and there is just nothing near the end of the
block device), then the reftable will be put after the image’s end.
Which is a problem on block devices, because they can’t easily be
resized (also, resizing wouldn’t really help in this case, because the
reftable would still be written past the new end).


Effectively, this means you can’t run `qemu-img check -r all` on qcow2
images that are on block devices when there are clusters that are in
use, but not marked as allocated.


I recommend reviewing patch 1 not based on the diff, but by applying it
and reviewing the rebuild_refcount_structure() function (and its new
rebuild_refcounts_write_refblocks() helper).


v2:
- Dropped patches 2 and 3 (not really necessary with QSD --daemonize),
  which used to bring support for the QSD to _launch_qemu
- Patch 1: Functionally the same (I hope), but I have added extensive
  comments and put the `for ()` loop into its own dedicated function so
  that we can get rid of the backwards-jumping goto
- Patch 2: Changed to make do without _launch_qemu having QSD support


git backport-diff against v1:

Key:
[----] : patches are identical
[####] : number of functional differences between upstream/downstream patch
[down] : patch is downstream-only
The flags [FC] indicate (F)unctional and (C)ontextual differences, respectively

001/2:[0370] [FC] 'qcow2: Improve refcount structure rebuilding'
002/2:[0047] [FC] 'iotests/108: Test new refcount rebuild algorithm'


Hanna Reitz (2):
  qcow2: Improve refcount structure rebuilding
  iotests/108: Test new refcount rebuild algorithm

 block/qcow2-refcount.c     | 332 ++++++++++++++++++++++++++-----------
 tests/qemu-iotests/108     | 259 ++++++++++++++++++++++++++++-
 tests/qemu-iotests/108.out |  81 +++++++++
 3 files changed, 574 insertions(+), 98 deletions(-)