]> git.ipfire.org Git - thirdparty/qemu.git/commit
qcow2: Improve refcount structure rebuilding
authorHanna Reitz <hreitz@redhat.com>
Tue, 5 Apr 2022 13:46:50 +0000 (15:46 +0200)
committerHanna Reitz <hreitz@redhat.com>
Wed, 20 Apr 2022 08:14:28 +0000 (10:14 +0200)
commita8c07ec287554dcefd33733f0e5888a281ddc95e
tree7bbfee74628e45bc924d742b2a3be9d0791a6f59
parent32911369fee72de1932a1ded714319fe0ecb9d2d
qcow2: Improve refcount structure rebuilding

When rebuilding the refcount structures (when qemu-img check -r found
errors with refcount = 0, but reference count > 0), the new refcount
table defaults to being put at the image file end[1].  There is no good
reason for that except that it means we will not have to rewrite any
refblocks we already wrote to disk.

Changing the code to rewrite those refblocks is not too difficult,
though, so let us do that.  That is beneficial for images on block
devices, where we cannot really write beyond the end of the image file.

Use this opportunity to add extensive comments to the code, and refactor
it a bit, getting rid of the backwards-jumping goto.

[1] Unless there is something allocated in the area pointed to by the
    last refblock, so we have to write that refblock.  In that case, we
    try to put the reftable in there.

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1519071
Closes: https://gitlab.com/qemu-project/qemu/-/issues/941
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20220405134652.19278-2-hreitz@redhat.com>
block/qcow2-refcount.c