Skip to contentSkip to conversation

Allow users to specify the vmdk virtual hardware version.

PATCH In review Janne Karhunen 2 participants 5 messages Apr 21, 2016 – May 3, 2016 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allow users to specify the vmdk virtual hardware version.

From: Janne Karhunen <[email protected]>

Vmdk images have metadata to indicate the vmware virtual hardware version image was created/tested to run with. Allow users to specify that version via new 'hwversion' option.

---
 block/vmdk.c              | 23 +++++++++++++++++++----
 include/block/block_int.h |  2 +-
 qemu-doc.texi             |  3 +++
 3 files changed, 23 insertions(+), 5 deletions(-)
block/vmdk.c +19 -4
index 45f9d3c..4b5cac8 100644
@@ -1829,8 +1829,8 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
     int64_t total_size = 0, filesize;
     char *adapter_type = NULL;
     char *backing_file = NULL;
+    char *hw_version = NULL;
     char *fmt = NULL;
-    int flags = 0;
     int ret = 0;
     bool flat, split, compress;
     GString *ext_desc_lines;
@@ -1861,7 +1861,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
         "# The Disk Data Base\n"
         "#DDB\n"
         "\n"
-        "ddb.virtualHWVersion = \"%d\"\n"
+        "ddb.virtualHWVersion = \"%s\"\n"
         "ddb.geometry.cylinders = \"%" PRId64 "\"\n"
         "ddb.geometry.heads = \"%" PRIu32 "\"\n"
         "ddb.geometry.sectors = \"63\"\n"
@@ -1878,8 +1878,16 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
                           BDRV_SECTOR_SIZE);
     adapter_type = qemu_opt_get_del(opts, BLOCK_OPT_ADAPTER_TYPE);
     backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+    hw_version = qemu_opt_get_del(opts, BLOCK_OPT_HWVERSION);
     if (qemu_opt_get_bool_del(opts, BLOCK_OPT_COMPAT6, false)) {
-        flags |= BLOCK_FLAG_COMPAT6;
+        if (strcmp(hw_version, "4")) {
+            error_setg(errp,
+                       "compat6 and hwversion are mutually exclusive");
+            ret = -EINVAL;
+            goto exit;
+        }
+        g_free(hw_version);
+        hw_version = g_strdup("6");
     }
     fmt = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
     if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ZEROED_GRAIN, false)) {
@@ -2001,7 +2009,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
                            fmt,
                            parent_desc_line,
                            ext_desc_lines->str,
-                           (flags & BLOCK_FLAG_COMPAT6 ? 6 : 4),
+                           hw_version,
                            total_size /
                                (int64_t)(63 * number_heads * BDRV_SECTOR_SIZE),
                            number_heads,
@@ -2047,6 +2055,7 @@ exit:
     }
     g_free(adapter_type);
     g_free(backing_file);
+    g_free(hw_version);
     g_free(fmt);
     g_free(desc);
     g_free(path);
@@ -2298,6 +2307,12 @@ static QemuOptsList vmdk_create_opts = {
             .def_value_str = "off"
         },
         {
+            .name = BLOCK_OPT_HWVERSION,
+            .type = QEMU_OPT_STRING,
+            .help = "VMDK hardware version",
+            .def_value_str = "4"
+        },
+        {
             .name = BLOCK_OPT_SUBFMT,
             .type = QEMU_OPT_STRING,
             .help =
include/block/block_int.h +1 -1
index 10d8759..931a412 100644
@@ -38,12 +38,12 @@
 #include "qemu/throttle.h"
 
 #define BLOCK_FLAG_ENCRYPT          1
-#define BLOCK_FLAG_COMPAT6          4
 #define BLOCK_FLAG_LAZY_REFCOUNTS   8
 
 #define BLOCK_OPT_SIZE              "size"
 #define BLOCK_OPT_ENCRYPT           "encryption"
 #define BLOCK_OPT_COMPAT6           "compat6"
+#define BLOCK_OPT_HWVERSION         "hwversion"
 #define BLOCK_OPT_BACKING_FILE      "backing_file"
 #define BLOCK_OPT_BACKING_FMT       "backing_fmt"
 #define BLOCK_OPT_CLUSTER_SIZE      "cluster_size"
qemu-doc.texi +3 -0
index 79141d3..d3a5f94 100644
@@ -693,6 +693,9 @@ Supported options:
 File name of a base image (see @option{create} subcommand).
 @item compat6
 Create a VMDK version 6 image (instead of version 4)
+@item hwversion
+Specify vmdk virtual hardware version. Option is mutually exclusive
+with the compat6 flag.
 @item subformat
 Specifies which VMDK subformat to use. Valid options are
 @code{monolithicSparse} (default),
Signature · 1 line
1.9.1
#1 lore raw
Quoted 8 lines · Janne Karhunen

From: Janne Karhunen <[email protected]>

Vmdk images have metadata to indicate the vmware virtual hardware version image was created/tested to run with. Allow users to specify that version via new 'hwversion' option.

Sorry for the late reply, I was distracted..

Quoted 30 lines
---
 block/vmdk.c              | 23 +++++++++++++++++++----
 include/block/block_int.h |  2 +-
 qemu-doc.texi             |  3 +++
 3 files changed, 23 insertions(+), 5 deletions(-)
block/vmdk.c +2 -2
index 45f9d3c..4b5cac8 100644
@@ -1829,8 +1829,8 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
     int64_t total_size = 0, filesize;
     char *adapter_type = NULL;
     char *backing_file = NULL;
+    char *hw_version = NULL;
     char *fmt = NULL;
-    int flags = 0;
     int ret = 0;
     bool flat, split, compress;
     GString *ext_desc_lines;
@@ -1861,7 +1861,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
         "# The Disk Data Base\n"
         "#DDB\n"
         "\n"
-        "ddb.virtualHWVersion = \"%d\"\n"
+        "ddb.virtualHWVersion = \"%s\"\n"
         "ddb.geometry.cylinders = \"%" PRId64 "\"\n"
         "ddb.geometry.heads = \"%" PRIu32 "\"\n"
         "ddb.geometry.sectors = \"63\"\n"

block/vmdk.c static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) · line 1882

Quoted 6 lines
block/vmdk.c +1 -1
@@ -1878,8 +1878,16 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
                           BDRV_SECTOR_SIZE);
     adapter_type = qemu_opt_get_del(opts, BLOCK_OPT_ADAPTER_TYPE);
     backing_file = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE);
+    hw_version = qemu_opt_get_del(opts, BLOCK_OPT_HWVERSION);
     if (qemu_opt_get_bool_del(opts, BLOCK_OPT_COMPAT6, false)) {
-        flags |= BLOCK_FLAG_COMPAT6;

Please remove BLOCK_FLAG_COMPAT6 from include/block/block_int.h| as well.

block/vmdk.c static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp) · line 1883

Quoted 1 line
block/vmdk.c +1 -0
+        if (strcmp(hw_version, "4")) {

Doesn't compat6 mean hw_version is 6? I think you want s/4/6/ here.

Quoted 63 lines
block/vmdk.c +15 -1
+            error_setg(errp,
+                       "compat6 and hwversion are mutually exclusive");
+            ret = -EINVAL;
+            goto exit;
+        }
+        g_free(hw_version);
+        hw_version = g_strdup("6");
     }
     fmt = qemu_opt_get_del(opts, BLOCK_OPT_SUBFMT);
     if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ZEROED_GRAIN, false)) {
@@ -2001,7 +2009,7 @@ static int vmdk_create(const char *filename, QemuOpts *opts, Error **errp)
                            fmt,
                            parent_desc_line,
                            ext_desc_lines->str,
-                           (flags & BLOCK_FLAG_COMPAT6 ? 6 : 4),
+                           hw_version,
                            total_size /
                                (int64_t)(63 * number_heads * BDRV_SECTOR_SIZE),
                            number_heads,
@@ -2047,6 +2055,7 @@ exit:
     }
     g_free(adapter_type);
     g_free(backing_file);
+    g_free(hw_version);
     g_free(fmt);
     g_free(desc);
     g_free(path);
@@ -2298,6 +2307,12 @@ static QemuOptsList vmdk_create_opts = {
             .def_value_str = "off"
         },
         {
+            .name = BLOCK_OPT_HWVERSION,
+            .type = QEMU_OPT_STRING,
+            .help = "VMDK hardware version",
+            .def_value_str = "4"
+        },
+        {
             .name = BLOCK_OPT_SUBFMT,
             .type = QEMU_OPT_STRING,
             .help =
include/block/block_int.h +1 -1
index 10d8759..931a412 100644
@@ -38,12 +38,12 @@
 #include "qemu/throttle.h"
 
 #define BLOCK_FLAG_ENCRYPT          1
-#define BLOCK_FLAG_COMPAT6          4
 #define BLOCK_FLAG_LAZY_REFCOUNTS   8
 
 #define BLOCK_OPT_SIZE              "size"
 #define BLOCK_OPT_ENCRYPT           "encryption"
 #define BLOCK_OPT_COMPAT6           "compat6"
+#define BLOCK_OPT_HWVERSION         "hwversion"
 #define BLOCK_OPT_BACKING_FILE      "backing_file"
 #define BLOCK_OPT_BACKING_FMT       "backing_fmt"
 #define BLOCK_OPT_CLUSTER_SIZE      "cluster_size"
qemu-doc.texi +0 -0
index 79141d3..d3a5f94 100644

qemu-doc.texi Supported options: · line 698

Quoted 6 lines
qemu-doc.texi +3 -0
@@ -693,6 +693,9 @@ Supported options:
 File name of a base image (see @option{create} subcommand).
 @item compat6
 Create a VMDK version 6 image (instead of version 4)
+@item hwversion
+Specify vmdk virtual hardware version. Option is mutually exclusive
+with the compat6 flag.

The code is not really treating them exclusively, it only checks for contradiction of values. So I suggest either fix the document or the code.

Fam

Quoted 7 lines
qemu-doc.texi +0 -0
 @item subformat
 Specifies which VMDK subformat to use. Valid options are
 @code{monolithicSparse} (default),
Signature · 1 line
1.9.1
#2 lore raw
Quoted 3 lines · Fam Zheng
Quoted 1 line

Sorry for the late reply, I was distracted..

Like wise, was traveling..

Quoted 4 lines
Quoted 2 lines
     if (qemu_opt_get_bool_del(opts, BLOCK_OPT_COMPAT6, false)) {

- flags |= BLOCK_FLAG_COMPAT6;

Please remove BLOCK_FLAG_COMPAT6 from include/block/block_int.h| as well.

Wasn't it removed?

-#define BLOCK_FLAG_COMPAT6 4

Quoted 3 lines
Quoted 1 line

+ if (strcmp(hw_version, "4")) {

Doesn't compat6 mean hw_version is 6? I think you want s/4/6/ here.

Yes and that's the functionality here. So the logic is that if BLOCK_OPT_COMPAT6 was defined and hw_version had something other than "4" we fail saying can't do both.

Test case:
qemu-img convert -f vmdk -O vmdk img.vmdk img.vmdk-output ddb.virtualHWVersion = "4" (default)

qemu-img convert -f vmdk -O vmdk -o compat6=on img.vmdk img.vmdk-output ddb.virtualHWVersion = "6" (compat6 default)

qemu-img convert -f vmdk -O vmdk -o hwversion=9 img.vmdk img.vmdk-output ddb.virtualHWVersion = "9" (the new feature)

Quoted 6 lines

qemu-doc.texi Supported options: · line 698

Quoted 3 lines

+@item hwversion

qemu-doc.texi +2 -0
+Specify vmdk virtual hardware version. Option is mutually exclusive
+with the compat6 flag.

The code is not really treating them exclusively, it only checks for contradiction of values. So I suggest either fix the document or the code.

It fails instantly if you try to pass both so what do you suggest it should do (returns -EINVAL)?

qemu-img convert -f vmdk -O vmdk -o compat6=on -o hwversion=9 img.vmdk img.vmdk.out
qemu-img: img.vmdk-output: error while converting vmdk: compat6 and hwversion are mutually exclusive

--
Janne

#3 lore raw
Quoted 8 lines · Janne Karhunen
Quoted 4 lines
Quoted 2 lines
     if (qemu_opt_get_bool_del(opts, BLOCK_OPT_COMPAT6, false)) {

- flags |= BLOCK_FLAG_COMPAT6;

Please remove BLOCK_FLAG_COMPAT6 from include/block/block_int.h| as well.

Wasn't it removed?

-#define BLOCK_FLAG_COMPAT6 4

Yes you are right, it's my oversight. :)

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

+ if (strcmp(hw_version, "4")) {

Doesn't compat6 mean hw_version is 6? I think you want s/4/6/ here.

Quoted 7 lines

Yes and that's the functionality here. So the logic is that if BLOCK_OPT_COMPAT6 was defined and hw_version had something other than "4" we fail saying can't do both.

Test case:
qemu-img convert -f vmdk -O vmdk img.vmdk img.vmdk-output ddb.virtualHWVersion = "4" (default)

Yes.

Quoted 3 lines

qemu-img convert -f vmdk -O vmdk -o compat6=on img.vmdk img.vmdk-output ddb.virtualHWVersion = "6" (compat6 default)

Yes.

Quoted 3 lines

qemu-img convert -f vmdk -O vmdk -o hwversion=9 img.vmdk img.vmdk-output ddb.virtualHWVersion = "9" (the new feature)

Yes.

But you get:

1)

    $ qemu-img create -f vmdk -o compat6=on,hwversion=4 /tmp/a.vmdk 1G; grep -a
    virtualHWVersion /tmp/a.vmdk Formatting '/tmp/a.vmdk', fmt=vmdk size=1073741824 compat6=on hwversion=4
    ddb.virtualHWVersion = "6"

which is wrong.

2) IMO if the documentation says "the options are mutually exclusive" instead of "specific value combinations are invalid", this:

    $ qemu-img create -f vmdk -o compat6=off,hwversion=9 /tmp/a.vmdk 1G; grep -a virtualHWVersion /tmp/a.vmdk
    Formatting '/tmp/a.vmdk', fmt=vmdk size=1073741824 compat6=off hwversion=9
    ddb.virtualHWVersion = "9"

should better be rejected:

    $ qemu-img create -f vmdk -o compat6=off,hwversion=9 /tmp/a.vmdk 1G; grep -a virtualHWVersion /tmp/a.vmdk
    Formatting '/tmp/a.vmdk', fmt=vmdk size=1073741824 compat6=off hwversion=9
    qemu-img: /tmp/a.vmdk: compat6 and hwversion are mutually exclusive

1) is a bug in your code, and 2) is a documenting problem.

Fam

#4 lore raw
Quoted 3 lines · Fam Zheng

Yes.

But you get:

Fair enough, sent another one.

Thanks,

Signature · 1 line
Janne