[Qemu-devel] Patch: Adding ability for qemu-img to create SCSI VMware di
From:
Aaron Mason
Subject:
[Qemu-devel] Patch: Adding ability for qemu-img to create SCSI VMware disk images
Date:
Fri, 22 May 2009 20:29:57 +1000
Hi,
I needed to create a heap of virtual hard drives to practice creating RAID arrays. Since qemu-img only creates IDE images, creating a large number of images for this was a very cumbersome excercise. I compared a SCSI image to an IDE image, and the only difference is the adapter type. This patch adds command line parameters to qemu-img to specify either a BusLogic or LSI Logic image for 'create' and 'convert', and extends the 'info' command to show the adapter type. I have also updated the file qemu-img.text and the help output to display the new parameters, and put in a parameter that was missing.
The patch is as follows, and can be applied to 0.10.5 stable (and latest snapshot if qemu-img hasn't changed) with patch -Np1:
+/* Added by thirdwheel to support BusLogic and LSI logic based VMDKs - 17/04/09 */ +#define BLOCK_FLAG_BUSLOGIC 8 +#define BLOCK_FLAG_LSILOGIC 16 + struct BlockDriver { const char *format_name;
int instance_size; diff -Naur qemu-0.10.5.orig/qemu-img.c qemu-0.10.5/qemu-img.c --- qemu-0.10.5.orig/qemu-img.c Thu May 21 06:47:00 2009 +++ qemu-0.10.5/qemu-img.c Fri May 22 20:09:44 2009 @@ -58,9 +58,9 @@
"QEMU disk image utility\n" "\n" "Command syntax:\n" - " create [-e] [-6] [-b base_image] [-f fmt] filename [size]\n" + " create [-e] [-6] [-S] [-L] [-b base_image] [-f fmt] filename [size]\n"
" commit [-f fmt] filename\n" - " convert [-c] [-e] [-6] [-f fmt] [-O output_fmt] [-B output_base_image] filename [filename2 [...]] output_filename\n" + " convert [-c] [-e] [-6] [-S] [-L] [-f fmt] [-O output_fmt] [-B output_base_image] filename [filename2 [...]] output_filename\n"
" info [-f fmt] filename\n" " snapshot [-l | -a snapshot | -c snapshot | -d snapshot] filename\n" "\n" @@ -81,6 +81,8 @@ " '-c' indicates that target image must be compressed (qcow format only)\n"
" '-e' indicates that the target image must be encrypted (qcow format only)\n" " '-6' indicates that the target image must use compatibility level 6 (vmdk format only)\n"
+ " '-S' indicates that the target image must be a BusLogic SCSI virtual disk (vmdk format only)\n" + " '-L' indicates that the target image must be a LSI Logic SCSI virtual disk (vmdk format only)\n"
" '-h' with or without a command shows this help and lists the supported formats\n" "\n" "Parameters to snapshot subcommand:\n" @@ -226,7 +228,7 @@
flags = 0; for(;;) { - c = getopt(argc, argv, "b:f:he6"); + c = getopt(argc, argv, "b:f:he6SL"); if (c == -1) break; switch(c) {
@@ -245,6 +247,12 @@ case '6': flags |= BLOCK_FLAG_COMPAT6; break; + case 'S': + flags |= BLOCK_FLAG_BUSLOGIC; + break; + case 'L':
+ flags |= BLOCK_FLAG_LSILOGIC; + break; } } if (optind >= argc) @@ -275,12 +283,23 @@ drv = bdrv_find_format(fmt); if (!drv) error("Unknown file format '%s'", fmt);
+ if (flags & BLOCK_FLAG_BUSLOGIC && drv != &bdrv_vmdk) + error("BusLogic images not supported for this file format"); + if (flags & BLOCK_FLAG_LSILOGIC && drv != &bdrv_vmdk)
+ error("LSI Logic images not supported for this file format"); + if (flags & BLOCK_FLAG_LSILOGIC && flags & BLOCK_FLAG_BUSLOGIC) + error("Please select either LSI Logic or BusLogic, not both");
+ printf("Formatting '%s', fmt=%s", filename, fmt); if (flags & BLOCK_FLAG_ENCRYPT) printf(", encrypted"); if (flags & BLOCK_FLAG_COMPAT6)
printf(", compatibility level=6"); + if (flags & BLOCK_FLAG_BUSLOGIC) + printf(", in BusLogic mode"); + if (flags & BLOCK_FLAG_LSILOGIC) + printf(", in LSI Logic mode");
if (base_filename) { printf(", backing_file=%s", base_filename); @@ -415,7 +434,7 @@ out_baseimg = NULL; flags = 0; for(;;) { - c = getopt(argc, argv, "f:O:B:hce6");
+ c = getopt(argc, argv, "f:O:B:hce6SL"); if (c == -1) break; switch(c) { @@ -440,6 +459,12 @@ case '6': flags |= BLOCK_FLAG_COMPAT6;
break; + case 'S': + flags |= BLOCK_FLAG_BUSLOGIC; + break; + case 'L': + flags |= BLOCK_FLAG_LSILOGIC; + break; } }
@@ -473,6 +498,15 @@ error("Encryption not supported for this file format"); if (flags & BLOCK_FLAG_COMPAT6 && drv != &bdrv_vmdk) error("Alternative compatibility level not supported for this file format");
+ if (flags & BLOCK_FLAG_BUSLOGIC && drv != &bdrv_vmdk) + error("BusLogic images not supported for this file format"); + if (flags & BLOCK_FLAG_LSILOGIC && drv != &bdrv_vmdk)
+ error("LSI Logic images not supported for this file format"); + if (flags & BLOCK_FLAG_LSILOGIC && flags & BLOCK_FLAG_BUSLOGIC) + error("Please select either LSI Logic or BusLogic, not both");
+ /* I'm not sure if buslogic and/or lsi logic images are supported at compatibility level 6 - if not, uncomment this until it can be tested */ + /*if ((flags & BLOCK_FLAG_LSILOGIC || flags & BLOCK_FLAG_BUSLOGIC) && BLOCK_FLAG_COMPAT6) */
+ /*error("SCSI VMDK images are not currently supported in compatibilty level 6");*/ if (flags & BLOCK_FLAG_ENCRYPT && flags & BLOCK_FLAG_COMPRESS) error("Compression and encryption not supported at the same time");
@@ -681,6 +715,10 @@ char backing_filename[1024]; char backing_filename2[1024]; BlockDriverInfo bdi; + + /* Added this to show what kind of adapter a vmdk image is - thirdwheel 17/04/2009 */
+ char line[1024]; + FILE *vmdk;
fmt = NULL; for(;;) { @@ -729,6 +767,22 @@ filename, fmt_name, size_buf, (total_sectors * 512), dsize_buf);
+ + if (strcmp(fmt_name, "vmdk") == 0) { + /* Now we find out what adapter type it is! - thirdwheel, 17/04/2009 */ + vmdk = fopen(filename, "r"); + fseek(vmdk, 512, SEEK_SET);
+ + while (fgets(line, 1024, vmdk) != NULL) { + + if (strcmp(strtok(line, "\""), "ddb.adapterType = ") == 0) { + + printf("Adapter type: %s\n", strtok(NULL, "\""));
+ break; + } + } + fclose(vmdk); + } if (bdrv_is_encrypted(bs)) printf("encrypted: yes\n"); if (bdrv_get_info(bs, &bdi) >= 0) { diff -Naur qemu-0.10.5.orig/qemu-img.texi qemu-0.10.5/qemu-img.texi
--- qemu-0.10.5.orig/qemu-img.texi Thu May 21 06:47:00 2009 +++ qemu-0.10.5/qemu-img.texi Fri May 22 20:16:30 2009 @@ -52,7 +52,7 @@ image format in QEMU. It is supported only for compatibility with previous versions. It does not work on win32.
address@hidden vmdk -VMware 3 and 4 compatible image format. +VMware 3 and 4 compatible image format. Supports IDE and SCSI (BusLogic and LSI Logic) adapters address@hidden cloop Linux Compressed Loop image, useful only to reuse directly compressed
CD-ROM images present for example in the Knoppix CD-ROMs. @@ -98,7 +98,7 @@ Command description:
Create the new disk image @var{filename} of size @var{size} and format address@hidden @@ -108,11 +108,15 @@
this case. @var{base_image} will never be modified unless you use the address@hidden monitor command.
+If the format is @code{vmdk}, the @code{-S} option will create a BusLogic image, +whereas the @code{-L} will create an LSI Logic image. Specifying neither option
+creates an IDE image. + address@hidden commit [-f @var{fmt}] @var{filename}
Commit the changes recorded in @var{filename} in its base image.
Convert the disk image @var{filename} to disk image @var{output_filename} using format @var{output_fmt}. It can be optionally encrypted
@@ -129,12 +133,17 @@ growable format such as @code{qcow} or @code{cow}: the empty sectors are detected and suppressed from the destination image.
+As with the create command, if the format is @code{vmdk}, the @code{-S}
+option will create a BusLogic image, whereas the @code{-L} will create +an LSI Logic image. Specifying neither option creates an IDE image. + address@hidden info [-f @var{fmt}] @var{filename}
Give information about the disk image @var{filename}. Use it in
particular to know the size reserved on disk which can be different from the displayed size. If VM snapshots are stored in the disk image, -they are displayed too. +they are displayed too. For the @code{vmdk} format, the adapter type of
+the image is displayed as well.