summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2010-05-28 12:21:27 +0200
committerKevin Wolf <kwolf@redhat.com>2010-05-28 13:29:16 +0200
commit644a872d66522bf18f626b81160770854641e956 (patch)
treecd890a555fd8217c6ac6d8b33e5221bc1aa24447 /block
parent424b2c8cec9b5783184afa34f6942addd04b007b (diff)
downloadqemu-644a872d66522bf18f626b81160770854641e956.tar.gz
qemu-644a872d66522bf18f626b81160770854641e956.tar.bz2
qemu-644a872d66522bf18f626b81160770854641e956.zip
qcow2: Fix corruption after error in update_refcount
After it is done with updating refcounts in the cache, update_refcount writes all changed entries to disk. If a refcount block allocation fails, however, there was no change yet and therefore first_index = last_index = -1. Don't treat -1 as a normal sector index (resulting in a 512 byte write!) but return without updating anything in this case. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/qcow2-refcount.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 5b7cda4774..22b0b45ff7 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -417,6 +417,10 @@ static int write_refcount_block_entries(BlockDriverState *bs,
return 0;
}
+ if (first_index < 0) {
+ return 0;
+ }
+
first_index &= ~(REFCOUNTS_PER_SECTOR - 1);
last_index = (last_index + REFCOUNTS_PER_SECTOR)
& ~(REFCOUNTS_PER_SECTOR - 1);