From patchwork Fri May 17 07:56:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 244518 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E3B402C009D for ; Fri, 17 May 2013 17:58:51 +1000 (EST) Received: from localhost ([::1]:50250 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdFYw-0002v7-8v for incoming@patchwork.ozlabs.org; Fri, 17 May 2013 03:58:50 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdFYa-0002q9-Tc for qemu-devel@nongnu.org; Fri, 17 May 2013 03:58:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UdFYV-0000ue-3j for qemu-devel@nongnu.org; Fri, 17 May 2013 03:58:28 -0400 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:49146) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdFYU-0000qu-G7 for qemu-devel@nongnu.org; Fri, 17 May 2013 03:58:23 -0400 Received: from /spool/local by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 17 May 2013 17:45:26 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 17 May 2013 17:45:25 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id D00402BB0051 for ; Fri, 17 May 2013 17:58:13 +1000 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r4H7w6Hq22020224 for ; Fri, 17 May 2013 17:58:06 +1000 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r4H7wDIG000619 for ; Fri, 17 May 2013 17:58:13 +1000 Received: from RH63Wenchao (wenchaox.cn.ibm.com [9.115.122.173]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r4H7umEX030909; Fri, 17 May 2013 17:58:11 +1000 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Fri, 17 May 2013 15:56:44 +0800 Message-Id: <1368777405-8750-2-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1368777405-8750-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1368777405-8750-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13051707-9264-0000-0000-000003C3C4A4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.146 Cc: kwolf@redhat.com, pbonzini@redhat.com, Wenchao Xia , stefanha@gmail.com Subject: [Qemu-devel] [PATCH V2 1/2] qcow2: free allocated cluster on fail in qcow2_write_snapshots() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Wenchao Xia --- block/qcow2-snapshot.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 992a5c8..45da32d 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -180,13 +180,13 @@ static int qcow2_write_snapshots(BlockDriverState *bs) /* Allocate space for the new snapshot list */ snapshots_offset = qcow2_alloc_clusters(bs, snapshots_size); - offset = snapshots_offset; - if (offset < 0) { - return offset; + ret = offset = snapshots_offset; + if (ret < 0) { + goto fail; } ret = bdrv_flush(bs); if (ret < 0) { - return ret; + goto fail; } /* Write all snapshots to the new list */ @@ -268,6 +268,8 @@ static int qcow2_write_snapshots(BlockDriverState *bs) return 0; fail: + /* free the new snapshot table */ + qcow2_free_clusters(bs, snapshots_offset, snapshots_size); return ret; }