From patchwork Mon Jan 18 12:11:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [01/10] qcow2: Fix error handling in qcow2_grow_l1_table Date: Mon, 18 Jan 2010 02:11:27 -0000 From: Kevin Wolf X-Patchwork-Id: 43063 Message-Id: <1263816696-24122-2-git-send-email-kwolf@redhat.com> To: qemu-devel@nongnu.org Cc: Kevin Wolf Return the appropriate error value instead of always using EIO. Don't free the L1 table on errors, we still need it. Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index f88118c..adddf56 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -67,9 +67,10 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size) /* set new table */ cpu_to_be32w((uint32_t*)data, new_l1_size); cpu_to_be64w((uint64_t*)(data + 4), new_l1_table_offset); - if (bdrv_pwrite(s->hd, offsetof(QCowHeader, l1_size), data, - sizeof(data)) != sizeof(data)) + ret = bdrv_pwrite(s->hd, offsetof(QCowHeader, l1_size), data,sizeof(data)); + if (ret != sizeof(data)) { goto fail; + } qemu_free(s->l1_table); qcow2_free_clusters(bs, s->l1_table_offset, s->l1_size * sizeof(uint64_t)); s->l1_table_offset = new_l1_table_offset; @@ -77,8 +78,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size) s->l1_size = new_l1_size; return 0; fail: - qemu_free(s->l1_table); - return -EIO; + return ret < 0 ? ret : -EIO; } void qcow2_l2_cache_reset(BlockDriverState *bs)