]> git.proxmox.com Git - 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)
committerAnthony Liguori <aliguori@us.ibm.com>
Tue, 23 Feb 2010 19:23:29 +0000 (13:23 -0600)
commit92dcb59fd4e1491afa0756ee9c2594869b487d23
tree53b14f5af9bcdbcef9c0ec8ec180b3a9586ed7fc
parent05121aedc41f87e44e41e9cef55f2e49ce7ba94e
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>
block/qcow2-refcount.c