From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VRLDS-0003Ev-7c for qemu-devel@nongnu.org; Wed, 02 Oct 2013 08:07:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VRLDJ-0004kp-Po for qemu-devel@nongnu.org; Wed, 02 Oct 2013 08:07:42 -0400 Received: from mail-wg0-x233.google.com ([2a00:1450:400c:c00::233]:38096) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VRLDJ-0004kU-I5 for qemu-devel@nongnu.org; Wed, 02 Oct 2013 08:07:33 -0400 Received: by mail-wg0-f51.google.com with SMTP id c11so742043wgh.6 for ; Wed, 02 Oct 2013 05:07:32 -0700 (PDT) Date: Wed, 2 Oct 2013 14:07:29 +0200 From: Stefan Hajnoczi Message-ID: <20131002120729.GA12200@stefanha-thinkpad.redhat.com> References: <1378695482-29805-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1378695482-29805-3-git-send-email-xiawenc@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1378695482-29805-3-git-send-email-xiawenc@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH V3 2/7] qcow2: free allocated cluster on fail in qcow2_write_snapshots() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Wenchao Xia Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com On Mon, Sep 09, 2013 at 10:57:57AM +0800, Wenchao Xia wrote: > Signed-off-by: Wenchao Xia > --- > 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); It is safer to skip qcow2_free_clusters() when the final bdrv_pwrite_sync() fails. We don't know if the header was updated on disk. If it was updated, then freeing the clusters may allow them to be reallocated later (this will cause corruption).