From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=33188 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q3bUt-0002jL-JN for qemu-devel@nongnu.org; Sat, 26 Mar 2011 17:58:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q3bUr-0005Ti-TQ for qemu-devel@nongnu.org; Sat, 26 Mar 2011 17:58:15 -0400 Received: from smtp1.iitd.ernet.in ([202.141.68.45]:47442) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q3bUq-0005MI-RD for qemu-devel@nongnu.org; Sat, 26 Mar 2011 17:58:13 -0400 Message-ID: <4D8E612B.4030107@cse.iitd.ac.in> Date: Sun, 27 Mar 2011 03:26:59 +0530 From: Dushyant Bansal MIME-Version: 1.0 Subject: Re: [Qemu-devel] Re: KVM call agenda for Jan 25 References: <20110124132559.GA25236@x200.localdomain> <4D3DF7EA.4010807@codemonkey.ws> <20110125115727.5f2b495e@doriath> <20110125120244.5b18863d@doriath> <4D43F0F5.10206@cse.iitd.ac.in> <4D67E9EB.7090606@cse.iitd.ac.in> <4D6975B0.4060309@cse.iitd.ac.in> <4D6C087B.90603@cse.iitd.ac.in> <4D7E309B.6080800@cse.iitd.ac.in> <4D7F3EFC.3050106@redhat.com> <4D81DD6C.4000203@redhat.com> In-Reply-To: <4D81DD6C.4000203@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: Stefan Hajnoczi , qemu-devel@nongnu.org >> On the other hand, I think the starting point for a generic in-place >> converter would be a loop that does something like bdrv_is_allocated() >> but translates the guest position in the block device into an offset >> into the image file. That, together with some sort of free map or >> space allocation bitmap would allow a generic approach to figuring out >> the data mapping and which parts of the file can be safely used. >> > We can discuss the detailed API later, but I agree that the critical > thing to convert is the mapping. > > You would probably open the file with the source format driver read-only > and with the destination driver read-write. For qcow2 you would start > with writing a refcount table that marks the whole file as used, other > formats use the file size anyway. Then you can start creating L1 and L2 > tables and copy the mapping over. Once this is done, you do an fsck to > free the metadata of the old format. > > One thing that may become tricky is the image header which both drivers > may want to use and which is fixed at offset 0. And of course, you must > make sure that the image is safe at any point if the converter crashes. > For image header issue, this is the approach that comes to mind. Lets say, destination format is qcow2. BDRVQcowState is responsible for header fields inside BlockDriverState. We need qcow2 image header to initiliaze all the fields of BDRVQcowState, which is done by bdrv_open(qcow2_open()). So initially, for the qcow2 driver, we do not copy the qcow2 image header (we keep the source header). We can then manually set fields of BDRVQcowState with the desired header fields. And after all other metadata has been copied for the qcow2 format, we can replace the source image header with the qcow2 header. Thanks, Dushyant