From patchwork Mon Jan 18 12:11:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 43063 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 5CFB3B7C94 for ; Mon, 18 Jan 2010 23:24:11 +1100 (EST) Received: from localhost ([127.0.0.1]:39629 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NWqW7-00077G-FA for incoming@patchwork.ozlabs.org; Mon, 18 Jan 2010 07:15:35 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NWqTJ-0006hV-HW for qemu-devel@nongnu.org; Mon, 18 Jan 2010 07:12:41 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NWqTE-0006gL-0s for qemu-devel@nongnu.org; Mon, 18 Jan 2010 07:12:41 -0500 Received: from [199.232.76.173] (port=51035 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NWqTD-0006gI-Sd for qemu-devel@nongnu.org; Mon, 18 Jan 2010 07:12:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:3891) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NWqTD-0001b6-HC for qemu-devel@nongnu.org; Mon, 18 Jan 2010 07:12:35 -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 o0ICCYU1029098 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 18 Jan 2010 07:12:34 -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 o0ICCV9n011108; Mon, 18 Jan 2010 07:12:33 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Mon, 18 Jan 2010 13:11:27 +0100 Message-Id: <1263816696-24122-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1263816696-24122-1-git-send-email-kwolf@redhat.com> References: <1263816696-24122-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 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 | 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)