From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40396) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UeFgS-0000om-4G for qemu-devel@nongnu.org; Sun, 19 May 2013 22:18:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UeFgN-0006YX-EH for qemu-devel@nongnu.org; Sun, 19 May 2013 22:18:44 -0400 Received: from e28smtp04.in.ibm.com ([122.248.162.4]:37232) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UeFgM-0006QE-QG for qemu-devel@nongnu.org; Sun, 19 May 2013 22:18:39 -0400 Received: from /spool/local by e28smtp04.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 20 May 2013 07:43:05 +0530 Received: from d28relay04.in.ibm.com (d28relay04.in.ibm.com [9.184.220.61]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 2C584125802D for ; Mon, 20 May 2013 07:50:07 +0530 (IST) Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r4K2I50p33161384 for ; Mon, 20 May 2013 07:48:05 +0530 Received: from d28av03.in.ibm.com (loopback [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r4K2I9xH021304 for ; Mon, 20 May 2013 12:18:10 +1000 Message-ID: <519987CE.5010907@linux.vnet.ibm.com> Date: Mon, 20 May 2013 10:17:50 +0800 From: Wenchao Xia MIME-Version: 1.0 References: <1368777405-8750-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1368777405-8750-3-git-send-email-xiawenc@linux.vnet.ibm.com> <20130517092701.GC15001@stefanha-thinkpad.redhat.com> In-Reply-To: <20130517092701.GC15001@stefanha-thinkpad.redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH V2 2/2] qcow2: cancel the modification on fail in qcow2_snapshot_create() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org 于 2013-5-17 17:27, Stefan Hajnoczi 写道: > On Fri, May 17, 2013 at 03:56:45PM +0800, Wenchao Xia wrote: >> 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); > > sn->l1_size is in uint64_t units, not in bytes. > > Do you have test cases to exercise these code paths? Use blkdebug to > inject errors at the right point so that the error code path is taken. > OK, I'll try it. -- Best Regards Wenchao Xia