From patchwork Sun Nov 10 23:56:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 290198 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 859B52C00AC for ; Mon, 11 Nov 2013 18:57:24 +1100 (EST) Received: from localhost ([::1]:35348 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VfmN8-0003s1-Fe for incoming@patchwork.ozlabs.org; Mon, 11 Nov 2013 02:57:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46399) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VfmMS-0003qq-Df for qemu-devel@nongnu.org; Mon, 11 Nov 2013 02:56:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VfmMJ-0000Zd-GW for qemu-devel@nongnu.org; Mon, 11 Nov 2013 02:56:40 -0500 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:57204) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VfmMI-0000Xg-RC for qemu-devel@nongnu.org; Mon, 11 Nov 2013 02:56:31 -0500 Received: from /spool/local by e28smtp05.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 11 Nov 2013 13:26:28 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp05.in.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 11 Nov 2013 13:26:27 +0530 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id EB4AE125803F for ; Mon, 11 Nov 2013 13:27:13 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay01.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id rAB7uN3733161456 for ; Mon, 11 Nov 2013 13:26:24 +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 rAB7uOcK005430 for ; Mon, 11 Nov 2013 13:26:24 +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 rAB7uIL6004926; Mon, 11 Nov 2013 13:26:23 +0530 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Mon, 11 Nov 2013 07:56:13 +0800 Message-Id: <1384127776-6428-4-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1384127776-6428-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1384127776-6428-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13111107-8256-0000-0000-00000A12BAC7 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.5 Cc: kwolf@redhat.com, jcody@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V6 3/6] qcow2: do not free clusters when fail in header update in qcow2_write_snapshots 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 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; }