From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MNrAm-0008OQ-Uo for qemu-devel@nongnu.org; Mon, 06 Jul 2009 12:36:08 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MNrAh-0008LE-V6 for qemu-devel@nongnu.org; Mon, 06 Jul 2009 12:36:08 -0400 Received: from [199.232.76.173] (port=53385 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MNrAh-0008L9-RK for qemu-devel@nongnu.org; Mon, 06 Jul 2009 12:36:03 -0400 Received: from smtp.andrew.cmu.edu ([128.2.11.96]:35646) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MNrAg-0001Hj-UX for qemu-devel@nongnu.org; Mon, 06 Jul 2009 12:36:03 -0400 Received: from [128.2.141.50] (ARCANINE.CYLAB.CMU.EDU [128.2.141.50]) (user=asangpet mech=PLAIN (0 bits)) by smtp.andrew.cmu.edu (8.14.3/8.14.3) with ESMTP id n66GZw62010870 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Mon, 6 Jul 2009 12:35:59 -0400 Message-ID: <4A5227EE.40505@andrew.cmu.edu> Date: Mon, 06 Jul 2009 12:35:58 -0400 From: Akkarit Sangpetch MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040600000105080409080705" Subject: [Qemu-devel] qemu-img convert : failed to convert an image which contains a backing file List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------040600000105080409080705 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, I have a problem with qemu-img convert tool in the master branch. The command 'qemu-img convert' failed to produce a valid image if the source image referenced a backing file. To reproduce, suppose we have an image base.qcow2 1. qemu-img create -b base.qcow2 -f qcow2 temp.qcow2 2. do something with temp.qcow2 (run a vm, write a file, etc.) 3. qemu-img convert -O qcow2 temp.qcow2 rebase.qcow2 The content of rebase.qcow2 is exactly the same as temp.qcow2, but without any backing file reference. This makes the file unusable. In earlier version, qemu-img convert produced a rebased version (it also removed reference to the backing files but the final image contains merged contents from both base.qcow2 and temp.qcow2) It seems that qemu-img convert assume '-B' option so it skips the unallocated part of the source file. The attached patch seems to fix the problem. (it modifies the patch found here http://git.savannah.gnu.org/cgit/qemu.git/commit/?id=93c65b47a6fb9ba0e2b89269a751ba3433a33427) --Akkarit --------------040600000105080409080705 Content-Type: text/plain; name="qemu-fix-img-rebase.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="qemu-fix-img-rebase.patch" diff -uNrp qemu-kvm-devel-87.orig/qemu-img.c qemu-kvm-devel-87/qemu-img.c --- qemu-kvm-devel-87.orig/qemu-img.c 2009-07-05 13:44:04.095124070 -0400 +++ qemu-kvm-devel-87/qemu-img.c 2009-07-05 20:40:07.282452250 -0400 @@ -747,14 +747,20 @@ static int img_convert(int argc, char ** 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; - } - /* The next 'n1' sectors are allocated in the input image. Copy - only those as they may be followed by unallocated sectors. */ - n = n1; + /* 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; + } } else { n1 = n; } --------------040600000105080409080705--