]> git.ipfire.org Git - thirdparty/qemu.git/commit
qcow2: Rewrite alloc_refcount_block/grow_refcount_table
authorKevin Wolf <kwolf@redhat.com>
Tue, 23 Feb 2010 15:40:53 +0000 (16:40 +0100)
committerAurelien Jarno <aurelien@aurel32.net>
Fri, 9 Apr 2010 16:41:59 +0000 (18:41 +0200)
commitfafc2e4b33220afd52b9e4bab1091b5861c8e5c4
tree7ff2e4f0ef71eb79b3167dea7f03136863da8784
parent83ef70f24afed411d19bca42072c7a6477c6dbcc
qcow2: Rewrite alloc_refcount_block/grow_refcount_table

The current implementation of alloc_refcount_block and grow_refcount_table has
fundamental problems regarding error handling. There are some places where an
I/O error means that the image is going to be corrupted. I have found that the
only way to fix this is to completely rewrite the thing.

In detail, the problem is that the refcount blocks itself are allocated using
alloc_refcount_noref (to avoid endless recursion when updating the refcount of
the new refcount block, which migh access just the same refcount block but its
allocation is not yet completed...). Only at the end of the refcount allocation
the refcount of the refcount block is increased. If an error happens in
between, the refcount block is in use, but has a refcount of zero and will
likely be overwritten later.

The new approach is explained in comments in the code. The trick is basically
to let new refcount blocks describe their own refcount, so their refcount will
be automatically changed when they are hooked up in the refcount table.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
(cherry picked from commit 92dcb59fd4e1491afa0756ee9c2594869b487d23)
block/qcow2-refcount.c