From patchwork Mon Sep 9 02:57:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 273470 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 BB0962C0127 for ; Mon, 9 Sep 2013 12:59:03 +1000 (EST) Received: from localhost ([::1]:47385 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VIrgr-0005VX-9t for incoming@patchwork.ozlabs.org; Sun, 08 Sep 2013 22:59:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47931) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VIrgL-0005Us-8B for qemu-devel@nongnu.org; Sun, 08 Sep 2013 22:58:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VIrgC-0000i1-Bn for qemu-devel@nongnu.org; Sun, 08 Sep 2013 22:58:29 -0400 Received: from e28smtp09.in.ibm.com ([122.248.162.9]:46480) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VIrgB-0000hT-PN for qemu-devel@nongnu.org; Sun, 08 Sep 2013 22:58:20 -0400 Received: from /spool/local by e28smtp09.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 9 Sep 2013 08:21:56 +0530 Received: from d28dlp01.in.ibm.com (9.184.220.126) by e28smtp09.in.ibm.com (192.168.1.139) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 9 Sep 2013 08:21:54 +0530 Received: from d28relay04.in.ibm.com (d28relay04.in.ibm.com [9.184.220.61]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id A35D7E0053 for ; Mon, 9 Sep 2013 08:29:01 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r892wAOb34734238 for ; Mon, 9 Sep 2013 08:28: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 r892wBUQ007935 for ; Mon, 9 Sep 2013 08:28:12 +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 r892w6dl007807; Mon, 9 Sep 2013 08:28:10 +0530 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Mon, 9 Sep 2013 10:57:58 +0800 Message-Id: <1378695482-29805-4-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-2674-0000-0000-00000A91BDFE X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.9 Cc: kwolf@redhat.com, pbonzini@redhat.com, mreitz@redhat.com, Wenchao Xia , stefanha@gmail.com Subject: [Qemu-devel] [PATCH V3 3/7] qcow2: cancel the modification on fail in qcow2_snapshot_create() 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 | 20 ++++++++++++++++---- 1 files changed, 16 insertions(+), 4 deletions(-) diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 9e2d695..e0b7a5a 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -378,13 +378,13 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) ret = qcow2_pre_write_overlap_check(bs, QCOW2_OL_DEFAULT, sn->l1_table_offset, s->l1_size * sizeof(uint64_t)); if (ret < 0) { - goto fail; + goto dealloc_cluster; } ret = bdrv_pwrite(bs->file, sn->l1_table_offset, l1_table, s->l1_size * sizeof(uint64_t)); if (ret < 0) { - goto fail; + goto dealloc_cluster; } g_free(l1_table); @@ -397,7 +397,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) */ ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, 1); if (ret < 0) { - goto fail; + goto dealloc_cluster; } /* Append the new snapshot to the snapshot list */ @@ -416,7 +416,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) g_free(s->snapshots); s->snapshots = old_snapshot_list; s->nb_snapshots = old_snapshot_num; - goto fail; + goto restore_refcount; } g_free(old_snapshot_list); @@ -429,6 +429,18 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) #endif return 0; +restore_refcount: + if (qcow2_update_snapshot_refcount(bs, s->l1_table_offset, s->l1_size, -1) + < 0) { + /* Nothing can be done none now, need image check later */ + error_report("qcow2: Error in restoring refcount in snapshot"); + } + +dealloc_cluster: + qcow2_free_clusters(bs, sn->l1_table_offset, + sn->l1_size * sizeof(uint64_t), + QCOW2_DISCARD_ALWAYS); + fail: g_free(sn->id_str); g_free(sn->name);