From patchwork Wed Jan 20 14:02:58 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 43285 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 18AB1B7C63 for ; Thu, 21 Jan 2010 01:14:23 +1100 (EST) Received: from localhost ([127.0.0.1]:49733 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXbJn-0006ls-FM for incoming@patchwork.ozlabs.org; Wed, 20 Jan 2010 09:13:59 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NXbAI-0006yb-A5 for qemu-devel@nongnu.org; Wed, 20 Jan 2010 09:04:10 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NXbAD-0006sW-4x for qemu-devel@nongnu.org; Wed, 20 Jan 2010 09:04:09 -0500 Received: from [199.232.76.173] (port=43293 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NXbAC-0006sI-PH for qemu-devel@nongnu.org; Wed, 20 Jan 2010 09:04:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53418) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NXbAC-0003LD-2R for qemu-devel@nongnu.org; Wed, 20 Jan 2010 09:04:04 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0KE43Ep020525 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 20 Jan 2010 09:04:03 -0500 Received: from localhost.localdomain (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0KE40Pw030534; Wed, 20 Jan 2010 09:04:02 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Wed, 20 Jan 2010 15:02:58 +0100 Message-Id: <1263996186-6623-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1263996186-6623-1-git-send-email-kwolf@redhat.com> References: <1263996186-6623-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Kevin Wolf Subject: [Qemu-devel] [PATCH v2 01/10] qcow2: Fix error handling in qcow2_grow_l1_table 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 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 | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index f88118c..cb46376 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,9 @@ 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; + qemu_free(new_l1_table); + qcow2_free_clusters(bs, new_l1_table_offset, new_l1_size2); + return ret < 0 ? ret : -EIO; } void qcow2_l2_cache_reset(BlockDriverState *bs)