From patchwork Tue Jun 22 15:34:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 56523 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AB870B6F18 for ; Wed, 23 Jun 2010 01:35:33 +1000 (EST) Received: from localhost ([127.0.0.1]:45086 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OR5Va-0002TY-8j for incoming@patchwork.ozlabs.org; Tue, 22 Jun 2010 11:35:30 -0400 Received: from [140.186.70.92] (port=40885 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OR5UV-0002SS-IZ for qemu-devel@nongnu.org; Tue, 22 Jun 2010 11:34:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OR5UU-0004wS-LE for qemu-devel@nongnu.org; Tue, 22 Jun 2010 11:34:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51263) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OR5UU-0004wG-Ek for qemu-devel@nongnu.org; Tue, 22 Jun 2010 11:34:22 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5MFYK8F028507 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 22 Jun 2010 11:34:21 -0400 Received: from localhost.localdomain (dhcp-5-217.str.redhat.com [10.32.5.217]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5MFYJm5023554; Tue, 22 Jun 2010 11:34:20 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Tue, 22 Jun 2010 17:34:11 +0200 Message-Id: <1277220851-635-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH] qcow2: Fix error handling during metadata preallocation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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); }