From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VdbaG-0007en-Mo for qemu-devel@nongnu.org; Tue, 05 Nov 2013 03:02:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vdba7-0002KR-PZ for qemu-devel@nongnu.org; Tue, 05 Nov 2013 03:01:56 -0500 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:47486) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vdba7-0002Jw-39 for qemu-devel@nongnu.org; Tue, 05 Nov 2013 03:01:47 -0500 Received: from /spool/local by e28smtp05.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 5 Nov 2013 13:31:43 +0530 Received: from d28relay05.in.ibm.com (d28relay05.in.ibm.com [9.184.220.62]) by d28dlp01.in.ibm.com (Postfix) with ESMTP id 2D2AEE004A for ; Tue, 5 Nov 2013 13:33:26 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id rA581d8r49152244 for ; Tue, 5 Nov 2013 13:31:39 +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 rA581ewG009163 for ; Tue, 5 Nov 2013 13:31:41 +0530 From: Wenchao Xia Date: Tue, 5 Nov 2013 08:01:26 +0800 Message-Id: <1383609689-4417-4-git-send-email-xiawenc@linux.vnet.ibm.com> In-Reply-To: <1383609689-4417-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1383609689-4417-1-git-send-email-xiawenc@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH V5 3/6] qcow2: do not free clusters when fail in header update in qcow2_write_snapshots List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@gmail.com, mreitz@redhat.com, pbonzini@redhat.com, Wenchao Xia Signed-off-by: Wenchao Xia Reviewed-by: Max Reitz --- block/qcow2-snapshot.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 6a1d9de..70e329e 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -299,6 +299,14 @@ static int qcow2_write_snapshots(BlockDriverState *bs, Error **errp) "Failed in update of image header at %d with size %d", (int)offsetof(QCowHeader, nb_snapshots), (int)sizeof(header_data)); + + /* + * If the snapshot data part has been updated on disk, then the + * clusters at snapshot_offset may be used in next snapshot operation. + * If we free those clusters in fail path, they may be allocated and + * made dirty causing damage, so skip cluster free to be safe. + */ + snapshots_offset = 0; goto fail; } -- 1.7.1