Skip to contentSkip to conversation

Patch: Adding ability for qemu-img to create SCSI VMware disk images

Qemu-devel Aaron Mason 6 participants 11 messages May 22, 2009 – May 27, 2009 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

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:

block-vmdk.c Fri May 22 20:09:44 2009 renamed from block-vmdk.c Thu May 21 06:46:58 2009 +4 -1
diff -Naur qemu-0.10.5.orig/block-vmdk.c qemu-0.10.5/block-vmdk.c
@@ -692,6 +692,7 @@
     int fd, i;
     VMDK4Header header;
     uint32_t tmp, magic, grains, gd_size, gt_size, gt_count;
+
     static const char desc_template[] =
         "# Disk DescriptorFile\n"
         "version=1\n"
@@ -709,10 +710,19 @@
         "ddb.geometry.cylinders = \"%" PRId64 "\"\n"
         "ddb.geometry.heads = \"16\"\n"
         "ddb.geometry.sectors = \"63\"\n"
-        "ddb.adapterType = \"ide\"\n";
+        "ddb.adapterType = \"%s\"\n";
     char desc[1024];
+    char adaptType[10];
     const char *real_filename, *temp_str;
 
+    /* If neither BusLogic or LSI logic is requested, default to IDE -

thirdwheel, 17/04/2009 */

+    if (flags & BLOCK_FLAG_BUSLOGIC)
+    strcpy(adaptType, "buslogic");
+    else if (flags & BLOCK_FLAG_LSILOGIC)
+    strcpy(adaptType, "lsilogic");
+    else
+    strcpy(adaptType, "ide");
+
     /* XXX: add support for backing file */
     if (backing_file) {
         return vmdk_snapshot_create(filename, backing_file);

@@ -784,7 +794,8 @@
snprintf(desc, sizeof(desc), desc_template, (unsigned int)time(NULL),
total_size, real_filename,
(flags & BLOCK_FLAG_COMPAT6 ? 6 : 4),
- total_size / (int64_t)(63 * 16));
+ total_size / (int64_t)(63 * 16),
+ adaptType);

     /* write the descriptor */
     lseek(fd, le64_to_cpu(header.desc_offset) << 9, SEEK_SET);
block_int.h Fri May 22 20:09:44 2009 renamed from block_int.h Thu May 21 06:46:58 2009 +1 -0
diff -Naur qemu-0.10.5.orig/block_int.h qemu-0.10.5/block_int.h
@@ -36,6 +36,10 @@
     BlockDriverAIOCB *free_aiocb;
 } AIOPool;
 
+/* 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;
qemu-img.c Fri May 22 20:09:44 2009 renamed from qemu-img.c Thu May 21 06:47:00 2009 +1 -1
diff -Naur qemu-0.10.5.orig/qemu-img.c qemu-0.10.5/qemu-img.c
@@ -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) {
qemu-img.texi Fri May 22 20:16:30 2009 renamed from qemu-img.texi Thu May 21 06:47:00 2009 +1 -1
diff -Naur qemu-0.10.5.orig/qemu-img.texi qemu-0.10.5/qemu-img.texi
@@ -52,7 +52,7 @@
 image format in QEMU. It is supported only for compatibility with
 previous versions. It does not work on win32.
 @item vmdk
-VMware 3 and 4 compatible image format.
+VMware 3 and 4 compatible image format.  Supports IDE and SCSI (BusLogic

and LSI Logic) adapters
@item 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:

@table @option
-@item create [-6] [-e] [-b @var{base_image}] [-f @var{fmt}] @var{filename} [@var{size}]
+@item create [-S] [-L] [-6] [-e] [-b @var{base_image}] [-f @var{fmt}] @var{filename} [@var{size}]

Create the new disk image @var{filename} of size @var{size} and format @var{fmt}.
@@ -108,11 +108,15 @@
this case. @var{base_image} will never be modified unless you use the @code{commit} 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.
+
@item commit [-f @var{fmt}] @var{filename}

Commit the changes recorded in @var{filename} in its base image.

-@item convert [-c] [-e] [-f @var{fmt}] @var{filename} [-O @var{output_fmt}] @var{output_filename}
+@item convert [-c] [-e] [-6] [-S] [-L] [-f @var{fmt}] @var{filename} [-O @var{output_fmt}] @var{output_filename}

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. +
@item 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.

@item snapshot [-l | -a @var{snapshot} | -c @var{snapshot} | -d
@var{snapshot} ] @var{filename}

#1 lore raw
Quoted 6 lines · Aaron Mason

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:

I don't think this functionality is very useful for QEMU because we don't emulate the same SCSI controller that VMware does.

Regards,

Anthony Liguori

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 2 lines · Aaron Mason

Who said the images had to be used for QEMU? As I said, I use the utility primarily for creating VMware images.

If it's not useful for QEMU, then I don't see that it's worth maintaining within QEMU.

Regards,

Anthony Liguori

#4 lore raw
Quoted 6 lines · Anthony Liguori
Quoted 2 lines · Aaron Mason

Who said the images had to be used for QEMU? As I said, I use the utility primarily for creating VMware images.

If it's not useful for QEMU, then I don't see that it's worth maintaining within QEMU.

Then I wonder why we have the compat6 option for VMDK. I would be rather surprised if it was useful for qemu itself.

FWIW, I know that SUSE had a use for these SCSI VMDKs and they carry a local patch for it. I would prefer to have such things upstream, even if it's just for exporting. After all, qemu-img is the Swiss army knife for images.

Kevin

#5 lore raw
Quoted 4 lines · Kevin Wolf
Quoted 2 lines · Anthony Liguori

Aaron Mason wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Who said the images had to be used for QEMU? As I said, I use the utility primarily for creating VMware images.

If it's not useful for QEMU, then I don't see that it's worth maintaining within QEMU.

Then I wonder why we have the compat6 option for VMDK. I would be rather surprised if it was useful for qemu itself.

Yup. I don't like the compat6 patch either as it's pretty invasive.

Quoted 5 lines

FWIW, I know that SUSE had a use for these SCSI VMDKs and they carry a local patch for it. I would prefer to have such things upstream, even if it's just for exporting. After all, qemu-img is the Swiss army knife for images.

If there's support for it, we can take it. I worry about adding features that aren't widely useful as they add complexity and make it hard to refactor things.

Introducing BLOCK_FLAG_BUSLOGIC and BLOCK_FLAG_LSILOGIC seems very wrong to me. You're happy with it?

Regards,

Anthony Liguori

Quoted 2 lines

Kevin

#6 lore raw
Quoted 8 lines · Anthony Liguori
Quoted 5 lines · Kevin Wolf

FWIW, I know that SUSE had a use for these SCSI VMDKs and they carry a local patch for it. I would prefer to have such things upstream, even if it's just for exporting. After all, qemu-img is the Swiss army knife for images.

Quoted 6 lines

If there's support for it, we can take it. I worry about adding features that aren't widely useful as they add complexity and make it hard to refactor things.

Introducing BLOCK_FLAG_BUSLOGIC and BLOCK_FLAG_LSILOGIC seems very wrong to me. You're happy with it?

I think the addition of new VMDK specific flags to qemu-img is pretty wrong too

-           "  create [-e] [-6] [-b base_image] [-f fmt] filename [size]\n"
+           "  create [-e] [-6] [-S] [-L] [-b base_image] [-f fmt] filename

....
+ " '-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"

If we want to expose this capability, then I think we should have some kind of generic 'feature' string that can be passed through to the specific block driver, without needing an unbounded number of qemu-img args to be added. eg.

qemu-img create -o target=buslogic foo.vmdk
qemu-img create -o target=lsilogic foo.vmdk

And just pass the whole value from '-o' through to the block layer's create method.

Daniel

Signature · 4 lines
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
#7 lore raw
Quoted 32 lines · Daniel P. Berrange
Quoted 9 lines · Anthony Liguori
Quoted 6 lines · Kevin Wolf

FWIW, I know that SUSE had a use for these SCSI VMDKs and they carry a local patch for it. I would prefer to have such things upstream, even if it's just for exporting. After all, qemu-img is the Swiss army knife for images.

Quoted 4 lines

If there's support for it, we can take it. I worry about adding features that aren't widely useful as they add complexity and make it hard to refactor things.

Introducing BLOCK_FLAG_BUSLOGIC and BLOCK_FLAG_LSILOGIC seems very wrong to me. You're happy with it?

I think the addition of new VMDK specific flags to qemu-img is pretty wrong too

(quoted diff) +2 -1
-           "  create [-e] [-6] [-b base_image] [-f fmt] filename [size]\n"
+           "  create [-e] [-6] [-S] [-L] [-b base_image] [-f fmt] filename
....
+       "  '-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"

If we want to expose this capability, then I think we should have some kind of generic 'feature' string that can be passed through to the specific block driver, without needing an unbounded number of qemu-img args to be added. eg.

Quoted 6 lines

qemu-img create -o target=buslogic foo.vmdk
qemu-img create -o target=lsilogic foo.vmdk

And just pass the whole value from '-o' through to the block layer's create method.

You can have the configs be external to vmdk's too, right?

Could we just make configs external to the sparse images so that people could edit them however they wanted?

Regards,

Anthony Liguori

Quoted 2 lines

Daniel

#8 lore raw
In reply to Anthony Liguori
Quoted 8 lines · Anthony Liguori
Quoted 7 lines · Kevin Wolf
Quoted 5 lines · Anthony Liguori
Quoted 3 lines · Aaron Mason

Who said the images had to be used for QEMU? As I said, I use the utility primarily for creating VMware images.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

If it's not useful for QEMU, then I don't see that it's worth maintaining within QEMU.

Then I wonder why we have the compat6 option for VMDK. I would be rather surprised if it was useful for qemu itself.

Yup. I don't like the compat6 patch either as it's pretty invasive.

Hm, we're both talking about ec36ba1? Because I can't see how it is invasing, with the exception of the changes to qemu-img. But we don't need these any more, we have -o now.

Quoted 6 lines
Quoted 5 lines

FWIW, I know that SUSE had a use for these SCSI VMDKs and they carry a local patch for it. I would prefer to have such things upstream, even if it's just for exporting. After all, qemu-img is the Swiss army knife for images.

Quoted 6 lines

If there's support for it, we can take it. I worry about adding features that aren't widely useful as they add complexity and make it hard to refactor things.

Introducing BLOCK_FLAG_BUSLOGIC and BLOCK_FLAG_LSILOGIC seems very wrong to me. You're happy with it?

No, I'm not happy with this particular patch, especially given that it doesn't apply to master any more. ;-)

You said this was "not useful", so I'm just talking of the functionality, independent of the code. And code-wise, it really should be only a few lines to vmdk - which makes the create function longer by maybe five lines, but hardly more complex.

Kevin

#9 lore raw
Quoted 7 lines · Kevin Wolf

No, I'm not happy with this particular patch, especially given that it doesn't apply to master any more. ;-)

You said this was "not useful", so I'm just talking of the functionality, independent of the code. And code-wise, it really should be only a few lines to vmdk - which makes the create function longer by maybe five lines, but hardly more complex.

Exactly my though. Rebased ontop of Kevin's option rework this is pretty trivial and useful enough to put it in.

Aaron, can you rebase this to the lastest git tree?

#10 lore raw
In reply to Kevin Wolf
Quoted 20 lines · Kevin Wolf
Quoted 18 lines · Anthony Liguori
Quoted 16 lines · Kevin Wolf
Quoted 9 lines · Anthony Liguori
Quoted 3 lines · Aaron Mason

Who said the images had to be used for QEMU? As I said, I use the utility primarily for creating VMware images.

If it's not useful for QEMU, then I don't see that it's worth maintaining within QEMU.

Then I wonder why we have the compat6 option for VMDK. I would be rather surprised if it was useful for qemu itself.

Quoted 7 lines
Quoted 2 lines

Yup. I don't like the compat6 patch either as it's pretty invasive.

Hm, we're both talking about ec36ba1? Because I can't see how it is invasing, with the exception of the changes to qemu-img. But we don't need these any more, we have -o now.

I find it invasive because it extends the block subsytem API with a non-generic interface.

Quoted 11 lines
Quoted 2 lines

Introducing BLOCK_FLAG_BUSLOGIC and BLOCK_FLAG_LSILOGIC seems very wrong to me. You're happy with it?

No, I'm not happy with this particular patch, especially given that it doesn't apply to master any more. ;-)

You said this was "not useful", so I'm just talking of the functionality, independent of the code. And code-wise, it really should be only a few lines to vmdk - which makes the create function longer by maybe five lines, but hardly more complex.

I wouldn't mind a few line patch to vmdk's create function.

Regards,

Anthony Liguori

Quoted 2 lines

Kevin

#11 lore raw
In reply to Anthony Liguori
Quoted 5 lines · Anthony Liguori
Quoted 2 lines

Who said the images had to be used for QEMU? As I said, I use the utility primarily for creating VMware images.

If it's not useful for QEMU, then I don't see that it's worth maintaining within QEMU.

I vote for including this small patch. Besides using QEMU I have to convert images among different emulators / virtualizers very often.

Robert Riebisch

Signature · 2 lines
BTTR Software
http://www.bttr-software.de/