From patchwork Fri May 28 11:22:53 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [5/5] qcow2: Fix corruption after error in update_refcount Date: Fri, 28 May 2010 01:22:53 -0000 From: Kevin Wolf X-Patchwork-Id: 53887 Message-Id: <1275045773-26963-6-git-send-email-kwolf@redhat.com> To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@linux.vnet.ibm.com 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 Reviewed-by: Stefan Hajnoczi --- block/qcow2-refcount.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 5b7cda4..22b0b45 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);