blktap: qcow2 image format support
PATCH 1/1 blktap: qcow2 image format support
This patch adds support for the qcow2 image format to blktap. It consists mostly of qemu code, adapted to the blktap interfaces. Snapshots and compressed images are supported.
The qcow2 driver may be used by either specifying tap:qcow2 or by using tap:qcow which will detect that you have a version 2 image and will call the qcow2 driver.
tools/blktap/drivers/Makefile +1 -0
@@ -27,6 +27,7 @@ BLK-OBJS-y += block-vmdk.o BLK-OBJS-y += block-vmdk.o BLK-OBJS-y += block-ram.o BLK-OBJS-y += block-qcow.o +BLK-OBJS-y += block-qcow2.o BLK-OBJS-y += aes.o BLK-OBJS-y += tapaio.o BLK-OBJS-$(CONFIG_Linux) += blk_linux.c
tools/blktap/drivers/aes.h +2 -0
@@ -1,5 +1,7 @@#ifndef QEMU_AES_H #define QEMU_AES_H + +#include <stdint.h> #define AES_MAXNR 14#define AES_BLOCK_SIZE 16
tools/blktap/drivers/blktapctrl.c +11 -8
@@ -181,27 +181,29 @@ static int test_path(char *path, char ** {char *ptr, handle[10 ];int i, size, found =0 ; +size_t handle_len; size =sizeof (dtypes)/sizeof (disk_info_t *); *type =MAX_DISK_TYPES +1 ; *blkif =NULL ;if ( (ptr =strstr (path,":" ))!=NULL ) { -memcpy (handle, path, (ptr - path)); + handle_len = (ptr - path); +memcpy (handle, path, handle_len); *dev = ptr +1 ; - ptr = handle + (ptr - path); + ptr = handle + handle_len; *ptr ='\0' ;DPRINTF ("Detected handle: [%s]\n" ,handle); -for (i =0 ; i < size; i++) -if (strncmp (handle, dtypes[i]->handle, - (ptr - path)) ==0 ) { +for (i =0 ; i < size; i++) { +if ((strlen (dtypes[i]->handle) == handle_len) && +strncmp (handle, dtypes[i]->handle, + handle_len) ==0 ) { found =1 ; -break ; } -if (found) { - *type = dtypes[i]->idnum; +if (found) { + *type = dtypes[i]->idnum;if (dtypes[i]->single_handler ==1 ) {/* Check whether tapdisk process
@@ -214,6 +216,7 @@ static int test_path(char *path, char ** }return 0 ; } + } }/* Fall-through case, we didn't find a disk driver. */
tools/blktap/drivers/block-qcow.c +13 -1
@@ -890,8 +890,20 @@ int tdqcow_open (struct disk_driver *dd,be32_to_cpus (&header->crypt_method);be64_to_cpus (&header->l1_table_offset); -if (header->magic !=QCOW_MAGIC || header->version >QCOW_VERSION ) +if (header->magic !=QCOW_MAGIC ) goto fail; + +switch (header->version) { +case QCOW_VERSION : +break ; +case 2 : +close (fd); + dd->drv = &tapdisk_qcow2; +return dd->drv->td_open (dd, name, flags); +default : + goto fail; + } +if (header->size <=1 || header->cluster_bits <9 ) goto fail;if (header->crypt_method >QCOW_CRYPT_AES )
tools/blktap/drivers/tapdisk.h +15 -1
@@ -58,11 +58,12 @@#include <stdint.h> #include <syslog.h> +#include <stdio.h> #include "blktaplib.h" /*If enabled, log all debug messages to syslog*/ #if 1 -#define DPRINTF(_f, _a...) syslog( LOG_DEBUG, _f , ## _a ) +#define DPRINTF(_f, _a...) syslog( LOG_DEBUG, __FILE__ ":%d: " _f , __LINE__, ## _a )#else #define DPRINTF(_f, _a...) ((void)0)#endif
@@ -156,6 +157,7 @@ extern struct tap_disk tapdisk_vmdk;extern struct tap_disk tapdisk_vmdk;extern struct tap_disk tapdisk_ram;extern struct tap_disk tapdisk_qcow; +extern struct tap_disk tapdisk_qcow2;#define MAX_DISK_TYPES 20
@@ -164,6 +166,7 @@ extern struct tap_disk tapdisk_qcow;#define DISK_TYPE_VMDK 2#define DISK_TYPE_RAM 3#define DISK_TYPE_QCOW 4 +#define DISK_TYPE_QCOW2 5/*Define Individual Disk Parameters here */
@@ -214,6 +217,16 @@ static disk_info_t qcow_disk = {0 , #ifdef TAPDISK &tapdisk_qcow, +#endif +}; + +static disk_info_t qcow2_disk = { +DISK_TYPE_QCOW2 , +"qcow2 disk (qcow2)" , +"qcow2" , +0 , +#ifdef TAPDISK + &tapdisk_qcow2, #endif };
@@ -224,6 +237,7 @@ static disk_info_t *dtypes[] = { &vmdk_disk, &ram_disk, &qcow_disk, + &qcow2_disk, }; typedef struct driver_list_entry {
tools/python/xen/xend/server/BlktapController.py +2 -1
@@ -12,7 +12,8 @@ blktap_disk_types = [ 'sync', 'vmdk', 'ram', - 'qcow' + 'qcow', + 'qcow2' ] class BlktapController(BlkifController):
tools/blktap/drivers/block-qcow2.c new file +2327 -0
2,327 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 7 lines · Kevin Wolf
This patch adds support for the qcow2 image format to blktap. It consists mostly of qemu code, adapted to the blktap interfaces. Snapshots and compressed images are supported.
The qcow2 driver may be used by either specifying tap:qcow2 or by using tap:qcow which will detect that you have a version 2 image and will call the qcow2 driver.
Is qcow2 so different from qcow1 that it really needs its own backend driver?
-- Keir
Quoted 11 lines · On Thursday 21 February 2008 09:57:48 Keir Fraser wrote:
Quoted 7 lines · Kevin Wolf
This patch adds support for the qcow2 image format to blktap. It consists mostly of qemu code, adapted to the blktap interfaces. Snapshots and compressed images are supported.
The qcow2 driver may be used by either specifying tap:qcow2 or by using tap:qcow which will detect that you have a version 2 image and will call the qcow2 driver.
Is qcow2 so different from qcow1 that it really needs its own backend driver?
IMO, _all_ blktap drivers need some code refactoring. There is a lot of duplicated code across all drivers
that can be moved into a blktap/drivers/blk-common.c.
Christoph
Signature · 12 lines
AMD Saxony, Dresden, Germany Operating System Research Center Legal Information: AMD Saxony Limited Liability Company & Co. KG Sitz (Geschäftsanschrift): Wilschdorfer Landstr. 101, 01109 Dresden, Deutschland Registergericht Dresden: HRA 4896 vertretungsberechtigter Komplementär: AMD Saxony LLC (Sitz Wilmington, Delaware, USA) Geschäftsführer der AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
Quoted 8 lines · Kevin Wolf
That's a good question. I am not really familiar with the qcow code but I think I saw quite some differences. If you put enough effort on it, you could probably get a single driver for both, but I can't really estimate if it was a sensible thing to do.
The main reason why I did it this way is that it is the way qemu has done it, so I just had to take and adapt their code. I'm not sure if it is a good idea to diverge too much from the qemu code base.
Okay that seems reasonable.
-- Keir
Quoted 2 lines · Keir Fraser
Is qcow2 so different from qcow1 that it really needs its own backend driver?
That's a good question. I am not really familiar with the qcow code but I think I saw quite some differences. If you put enough effort on it, you could probably get a single driver for both, but I can't really estimate if it was a sensible thing to do.
The main reason why I did it this way is that it is the way qemu has done it, so I just had to take and adapt their code. I'm not sure if it is a good idea to diverge too much from the qemu code base.
Kevin
Quoted 4 lines · Christoph Egger
On Thursday 21 February 2008 09:57:48 Keir Fraser wrote:
IMO, _all_ blktap drivers need some code refactoring. There is a lot of duplicated code across all drivers
that can be moved into ablktap/drivers/blk-common.c.
Yes, I think you're right on that. I noticed this especially with the aio function which are duplicated in each single driver. I decided not to fix this with the qcow2 patch as it is a different problem, but it could be a good next step.
Kevin
Keir Fraser
AppliedQuoted 7 lines · Kevin Wolf
This patch adds support for the qcow2 image format to blktap. It consists mostly of qemu code, adapted to the blktap interfaces. Snapshots and compressed images are supported.
The qcow2 driver may be used by either specifying tap:qcow2 or by using tap:qcow which will detect that you have a version 2 image and will call the qcow2 driver.
Applied. I had to convert lx to PRIx64 in a number of places.
-- Ekir
Quoted 10 lines · Christoph Egger
Quoted 9 lines · On Thursday 21 February 2008 09:57:48 Keir Fraser wrote:
Quoted 7 lines · Kevin Wolf
This patch adds support for the qcow2 image format to blktap. It consists mostly of qemu code, adapted to the blktap interfaces. Snapshots and compressed images are supported.
The qcow2 driver may be used by either specifying tap:qcow2 or by using tap:qcow which will detect that you have a version 2 image and will call the qcow2 driver.
Quoted 6 lines
Quoted 2 lines
Is qcow2 so different from qcow1 that it really needs its own backend driver?
IMO, _all_ blktap drivers need some code refactoring. There is a lot of duplicated code across all drivers
that can be moved into ablktap/drivers/blk-common.c.
Well if you're concerned about code duplication - we've 2 entirely separate impls of every disk format - one in blktap and one in QEMU itself. The original motivation for the duplication was that QEMU's block driver API did not support Async-IO operations, but that was addressed in 0.9.0 - if you look at the internal QEMU block driver API for disk formats vs blktaps internal driver API they're near identical. I think it'd be an interesting project to actually make QEMU userspace talk directly to blktap kernel driver, thus eliminating the entire blktap users & all code duplication. Then we'd have parity of disk support across PV & HVM guests too. Certainly not an easy or quick project, but if someone's looking for something interesting to hack on....
Dan.
Signature · 4 lines
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
Daniel P. Berrange writes ("Re: [Xen-devel] [PATCH] blktap: qcow2 image format support"):
Quoted 7 lines
Well if you're concerned about code duplication - we've 2 entirely separate impls of every disk format - one in blktap and one in QEMU itself. The original motivation for the duplication was that QEMU's block driver API did not support Async-IO operations, but that was addressed in 0.9.0 - if you look at the internal QEMU block driver API for disk formats vs blktaps internal driver API they're near identical.
Yes. This is pretty poor and although I don't want to stand in the way of useful stuff I'm disappointed to see more of this duplication going on.
Quoted 6 lines
I think it'd be an interesting project to actually make
QEMU userspace talk directly to blktap kernel driver, thus eliminating the entire blktap users & all code duplication. Then we'd have parity of disk support across PV & HVM guests too. Certainly not an easy or quick project, but if someone's looking for something interesting to hack on....
I'm currently trying to merge our qemu with upstream's, at least somewhat, and this is definitely something I'm keeping an eye on.
Ian.
Hi,
Quoted 6 lines · Keir Fraser
Quoted 4 lines · Kevin Wolf
This patch adds support for the qcow2 image format to blktap. It consists mostly of qemu code, adapted to the blktap interfaces. Snapshots and compressed images are supported.
Quoted 7 lines
Quoted 3 lines
The qcow2 driver may be used by either specifying tap:qcow2 or by using tap:qcow which will detect that you have a version 2 image and will call the qcow2 driver.
Applied. I had to convert lx to PRIx64 in a number of places.
-- Ekir
Don't know if this build breakage has been reported yet:
gcc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -m32 -march=i686 -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -m32 -march=i686 -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -m32 -march=i686 -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -D__XEN_TOOLS__ -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -mno-tls-direct-seg-refs -m32 -march=i686 -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -D__XEN_TOOLS__ -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -mno-tls-direct-seg-refs -m32 -march=i686 -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -D__XEN_TOOLS__ -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -mno-tls-direct-seg-refs -m32 -march=i686 -fno-strict-aliasing -std=gnu99 -Wall -Wstrict-prototypes -Wno-unused-value -Wdeclaration-after-statement -D__XEN_TOOLS__ -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -mno-tls-direct-seg-refs -Werror -Wno-unused -I../../../tools/libxc -I../../../tools/include -I ../../libaio/src -I.. -I../lib -I../../../tools/include -I. -I../../xenstore -D_GNU_SOURCE -Wp,-MD,.block-qcow2.o.d -c -o block-qcow2.o block-qcow2.c
cc1: warnings being treated as errorsblock-qcow2.c: In function 'qcow2_create':
block-qcow2.c:1512: warning: ignoring return value of 'write', declared with attribute warn_unused_result
block-qcow2.c:1514: warning: ignoring return value of 'write', declared with attribute warn_unused_result
block-qcow2.c:1519: warning: ignoring return value of 'write', declared with attribute warn_unused_result
block-qcow2.c:1522: warning: ignoring return value of 'write', declared with attribute warn_unused_result
block-qcow2.c:1525: warning: ignoring return value of 'write', declared with attribute warn_unused_resultblock-qcow2.c: In function 'qcow_write_compressed':
block-qcow2.c:1554: warning: ignoring return value of 'ftruncate',
declared with attribute warn_unused_result
make[4]: *** [block-qcow2.o] Error 1
make[4]: Leaving directory `/builddir/build/BUILD/xen-unstable/tools/blktap/drivers'
Need to deal with return value of writes in qcow2_create() and ftruncate in qcow_write_compressed(). Probably need to deal with errno too.
Thanks
kurt