From patchwork Mon Sep 9 02:57:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 273473 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7CC332C00C9 for ; Mon, 9 Sep 2013 13:00:56 +1000 (EST) Received: from localhost ([::1]:47401 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VIrig-0000PX-1G for incoming@patchwork.ozlabs.org; Sun, 08 Sep 2013 23:00:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VIrgP-0005Uz-JT for qemu-devel@nongnu.org; Sun, 08 Sep 2013 22:58:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VIrgC-0000iH-NR for qemu-devel@nongnu.org; Sun, 08 Sep 2013 22:58:33 -0400 Received: from e28smtp01.in.ibm.com ([122.248.162.1]:47658) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VIrgC-0000hO-1P for qemu-devel@nongnu.org; Sun, 08 Sep 2013 22:58:20 -0400 Received: from /spool/local by e28smtp01.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 9 Sep 2013 08:18:44 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp01.in.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 9 Sep 2013 08:18:42 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id E01B03940053 for ; Mon, 9 Sep 2013 08:27:59 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r893093V35782852 for ; Mon, 9 Sep 2013 08:30:10 +0530 Received: from d28av02.in.ibm.com (localhost [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r892wADi007918 for ; Mon, 9 Sep 2013 08:28:11 +0530 Received: from RH64wenchao ([9.181.129.59]) by d28av02.in.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id r892w6dk007807; Mon, 9 Sep 2013 08:28:09 +0530 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Mon, 9 Sep 2013 10:57:57 +0800 Message-Id: <1378695482-29805-3-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1378695482-29805-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1378695482-29805-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13090902-4790-0000-0000-00000A35746E X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.1 Cc: kwolf@redhat.com, pbonzini@redhat.com, mreitz@redhat.com, Wenchao Xia , stefanha@gmail.com Subject: [Qemu-devel] [PATCH V3 2/7] 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 Reviewed-by: Eric Blake --- block/qcow2-snapshot.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 40393b2..9e2d695 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -186,7 +186,7 @@ static int qcow2_write_snapshots(BlockDriverState *bs) } ret = bdrv_flush(bs); if (ret < 0) { - return ret; + goto fail; } /* The snapshot list position has not yet been updated, so these clusters @@ -194,7 +194,7 @@ static int qcow2_write_snapshots(BlockDriverState *bs) ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT, offset, s->snapshots_size); if (ret < 0) { - return ret; + goto fail; } @@ -278,6 +278,9 @@ static int qcow2_write_snapshots(BlockDriverState *bs) return 0; fail: + /* free the new snapshot table */ + qcow2_free_clusters(bs, snapshots_offset, snapshots_size, + QCOW2_DISCARD_ALWAYS); return ret; }