From patchwork Thu Dec 5 12:02:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 297101 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 D44172C0077 for ; Thu, 5 Dec 2013 23:04:49 +1100 (EST) Received: from localhost ([::1]:53066 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoXfj-0006sL-Gq for incoming@patchwork.ozlabs.org; Thu, 05 Dec 2013 07:04:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40868) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoXcc-0002L5-9i for qemu-devel@nongnu.org; Thu, 05 Dec 2013 07:01:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VoXcT-0005Cu-D4 for qemu-devel@nongnu.org; Thu, 05 Dec 2013 07:01:34 -0500 Received: from e28smtp04.in.ibm.com ([122.248.162.4]:43111) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoXcS-0005CO-Nt for qemu-devel@nongnu.org; Thu, 05 Dec 2013 07:01:25 -0500 Received: from /spool/local by e28smtp04.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 5 Dec 2013 17:31:22 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp04.in.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 5 Dec 2013 17:31:20 +0530 Received: from d28relay01.in.ibm.com (d28relay01.in.ibm.com [9.184.220.58]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id B838B394005B for ; Thu, 5 Dec 2013 17:31:19 +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 rB5C19VM10879124 for ; Thu, 5 Dec 2013 17:31:09 +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 rB5C1Emf003190 for ; Thu, 5 Dec 2013 17:31:14 +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 rB5C19ia002561; Thu, 5 Dec 2013 17:31:13 +0530 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Thu, 5 Dec 2013 20:02:49 +0800 Message-Id: <1386244972-528-4-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1386244972-528-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1386244972-528-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13120512-5564-0000-0000-00000AF985EF X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.4 Cc: kwolf@redhat.com, jcody@redhat.com, Wenchao Xia , stefanha@redhat.com, mreitz@redhat.com Subject: [Qemu-devel] [PATCH V7 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 d7ab4ae..55746c4 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; }