From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MRiPp-0007fj-Ov for qemu-devel@nongnu.org; Fri, 17 Jul 2009 04:03:37 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MRiPl-0007ew-8Q for qemu-devel@nongnu.org; Fri, 17 Jul 2009 04:03:37 -0400 Received: from [199.232.76.173] (port=49450 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MRiPl-0007et-1Q for qemu-devel@nongnu.org; Fri, 17 Jul 2009 04:03:33 -0400 Received: from mx20.gnu.org ([199.232.41.8]:49098) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MRiPk-0005jC-8n for qemu-devel@nongnu.org; Fri, 17 Jul 2009 04:03:32 -0400 Received: from mx2.redhat.com ([66.187.237.31]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MRiPj-0003QH-Ci for qemu-devel@nongnu.org; Fri, 17 Jul 2009 04:03:31 -0400 From: Kevin Wolf Date: Fri, 17 Jul 2009 10:02:15 +0200 Message-Id: <1247817735-14831-1-git-send-email-kwolf@redhat.com> 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: Akkarit Sangpetch From: Akkarit Sangpetch Make 'qemu-img convert' copies unallocated parts of the source image when -B option was not specified. Signed-off-by: Akkarit Sangpetch Signed-off-by: Kevin Wolf --- Akkarit doesn't seem to repost with the patch corruption fixed, but we need this fix anyway. 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.0.6