Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MODyn-0001ck-Rw for qemu-devel@nongnu.org; Tue, 07 Jul 2009 12:57:17 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MODyi-0001be-AL for qemu-devel@nongnu.org; Tue, 07 Jul 2009 12:57:16 -0400 Received: from [199.232.76.173] (port=55714 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MODyi-0001bb-3e for qemu-devel@nongnu.org; Tue, 07 Jul 2009 12:57:12 -0400 Received: from mx20.gnu.org ([199.232.41.8]:15177) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MODyh-0004kr-DH for qemu-devel@nongnu.org; Tue, 07 Jul 2009 12:57:11 -0400 Received: from smtp.andrew.cmu.edu ([128.2.11.61]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MODyf-0007uY-EG for qemu-devel@nongnu.org; Tue, 07 Jul 2009 12:57:09 -0400 Message-ID: <4A537E61.9070602@andrew.cmu.edu> Date: Tue, 07 Jul 2009 12:57:05 -0400 From: Akkarit Sangpetch MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] qmu-img: fix qemu-img convert to generate a valid image when the source referenced a backing file List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, asangpet@andrew.cmu.edu Make 'qemu-img convert' copies unallocated parts of the source image when -B option was not specified. Signed-off-by: Akkarit Sangpetch --- qemu-img.c | 20 +++++++++++++------- 1 files changed, 13 insertions(+), 7 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index d806cfa..070fe2e 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -747,14 +747,20 @@ static int img_convert(int argc, char **argv) n = bs_offset + bs_sectors - sector_num; if (strcmp(drv->format_name, "host_device")) { - if (!bdrv_is_allocated(bs[bs_i], sector_num - bs_offset, - n, &n1)) { - sector_num += n1; - continue; + /* If the output image is being created as a copy on write image, + assume that sectors which are unallocated in the input image + are present in both the output's and input's base images (no + need to copy them). */ + if (out_baseimg) { + if (!bdrv_is_allocated(bs[bs_i], sector_num - bs_offset, + n, &n1)) { + sector_num += n1; + continue; + } + /* The next 'n1' sectors are allocated in the input image. Copy + only those as they may be followed by unallocated sectors. */ + n = n1; } - /* The next 'n1' sectors are allocated in the input image. Copy - only those as they may be followed by unallocated sectors. */ - n = n1; } else { n1 = n; } -- 1.6.2.5