From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=40715 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OUjGJ-00045i-Hq for qemu-devel@nongnu.org; Fri, 02 Jul 2010 12:38:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OUjGH-0001Tg-P8 for qemu-devel@nongnu.org; Fri, 02 Jul 2010 12:38:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35226) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OUjGH-0001T8-I5 for qemu-devel@nongnu.org; Fri, 02 Jul 2010 12:38:45 -0400 From: Kevin Wolf Date: Fri, 2 Jul 2010 18:38:10 +0200 Message-Id: <1278088712-12302-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1278088712-12302-1-git-send-email-kwolf@redhat.com> References: <1278088712-12302-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 01/23] qcow2: Fix error handling during metadata preallocation List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org People were wondering why qemu-img check failed after they tried to preallocate a large qcow2 file and ran out of disk space. Signed-off-by: Kevin Wolf --- block/qcow2.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index d29e6b6..9ee34b6 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -805,14 +805,14 @@ static int preallocate(BlockDriverState *bs) while (nb_sectors) { num = MIN(nb_sectors, INT_MAX >> 9); ret = qcow2_alloc_cluster_offset(bs, offset, 0, num, &num, &meta); - if (ret < 0) { - return -1; + return ret; } - if (qcow2_alloc_cluster_link_l2(bs, &meta) < 0) { + ret = qcow2_alloc_cluster_link_l2(bs, &meta); + if (ret < 0) { qcow2_free_any_clusters(bs, meta.cluster_offset, meta.nb_clusters); - return -1; + return ret; } /* There are no dependent requests, but we need to remove our request @@ -833,7 +833,10 @@ static int preallocate(BlockDriverState *bs) if (meta.cluster_offset != 0) { uint8_t buf[512]; memset(buf, 0, 512); - bdrv_write(bs->file, (meta.cluster_offset >> 9) + num - 1, buf, 1); + ret = bdrv_write(bs->file, (meta.cluster_offset >> 9) + num - 1, buf, 1); + if (ret < 0) { + return ret; + } } return 0; @@ -1030,7 +1033,7 @@ exit: BlockDriver *drv = bdrv_find_format("qcow2"); bs = bdrv_new(""); bdrv_open(bs, filename, BDRV_O_CACHE_WB | BDRV_O_RDWR, drv); - preallocate(bs); + ret = preallocate(bs); bdrv_close(bs); } -- 1.6.6.1