From patchwork Fri May 17 07:56:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 244519 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 2EBE12C00A1 for ; Fri, 17 May 2013 17:59:44 +1000 (EST) Received: from localhost ([::1]:53006 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdFZm-0004On-Go for incoming@patchwork.ozlabs.org; Fri, 17 May 2013 03:59:42 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37588) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdFYb-0002qq-Ii for qemu-devel@nongnu.org; Fri, 17 May 2013 03:58:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UdFYV-0000vv-TQ for qemu-devel@nongnu.org; Fri, 17 May 2013 03:58:29 -0400 Received: from e23smtp03.au.ibm.com ([202.81.31.145]:49257) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UdFYV-0000si-6x for qemu-devel@nongnu.org; Fri, 17 May 2013 03:58:23 -0400 Received: from /spool/local by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 17 May 2013 17:49:58 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 17 May 2013 17:49:56 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 0CB162BB0023 for ; Fri, 17 May 2013 17:58:17 +1000 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r4H7iEdE22806670 for ; Fri, 17 May 2013 17:44:14 +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 r4H7wGeV000678 for ; Fri, 17 May 2013 17:58:16 +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 r4H7umEY030909; Fri, 17 May 2013 17:58:14 +1000 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Fri, 17 May 2013 15:56:45 +0800 Message-Id: <1368777405-8750-3-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-6102-0000-0000-0000038A9112 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.145 Cc: kwolf@redhat.com, pbonzini@redhat.com, Wenchao Xia , stefanha@gmail.com Subject: [Qemu-devel] [PATCH V2 2/2] 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 | 17 ++++++++++++++--- 1 files changed, 14 insertions(+), 3 deletions(-) diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 45da32d..033f705 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -367,7 +367,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) 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); @@ -380,7 +380,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 */ @@ -397,7 +397,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) if (ret < 0) { g_free(s->snapshots); s->snapshots = old_snapshot_list; - goto fail; + goto restore_refcount; } g_free(old_snapshot_list); @@ -410,6 +410,17 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) #endif return 0; +restore_refcount: + ret = qcow2_update_snapshot_refcount(bs, s->l1_table_offset, + s->l1_size, -1); + if (ret < 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); + fail: g_free(sn->id_str); g_free(sn->name);