From patchwork Thu Apr 29 12:57:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 51295 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 628AEB7D2D for ; Thu, 29 Apr 2010 23:23:19 +1000 (EST) Received: from localhost ([127.0.0.1]:49113 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O7Thk-0000Xw-Cv for incoming@patchwork.ozlabs.org; Thu, 29 Apr 2010 09:23:00 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O7TJE-0002l8-2S for qemu-devel@nongnu.org; Thu, 29 Apr 2010 08:57:40 -0400 Received: from [140.186.70.92] (port=39343 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O7TJC-0002jO-11 for qemu-devel@nongnu.org; Thu, 29 Apr 2010 08:57:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O7TJ6-0004Qi-Tx for qemu-devel@nongnu.org; Thu, 29 Apr 2010 08:57:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63419) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O7TJ6-0004QX-Mg for qemu-devel@nongnu.org; Thu, 29 Apr 2010 08:57:32 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3TCvVjn006843 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 29 Apr 2010 08:57:31 -0400 Received: from localhost.localdomain (dhcp-5-217.str.redhat.com [10.32.5.217]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3TCvU91009314; Thu, 29 Apr 2010 08:57:30 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Thu, 29 Apr 2010 14:57:06 +0200 Message-Id: <1272545826-13287-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH] qemu-img rebase: Fix output image corruption X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org qemu-img rebase must always give clusters in the COW file priority over those in the backing file. As it failed to use number of non-allocated clusters but assumed the maximum, it was possible that allocated clusters were taken from the backing file instead, leading to a corrupted output image. Signed-off-by: Kevin Wolf --- qemu-img.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index c21d999..d3c30a7 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1136,7 +1136,7 @@ static int img_rebase(int argc, char **argv) if (!unsafe) { uint64_t num_sectors; uint64_t sector; - int n, n1; + int n; uint8_t * buf_old; uint8_t * buf_new; @@ -1155,8 +1155,8 @@ static int img_rebase(int argc, char **argv) } /* If the cluster is allocated, we don't need to take action */ - if (bdrv_is_allocated(bs, sector, n, &n1)) { - n = n1; + ret = bdrv_is_allocated(bs, sector, n, &n); + if (ret) { continue; }