a9640c
From e30f529dc3ddb474ed78cf771b71d79616c3b8ce Mon Sep 17 00:00:00 2001
a9640c
Message-Id: <e30f529dc3ddb474ed78cf771b71d79616c3b8ce@dist-git>
a9640c
From: Michal Privoznik <mprivozn@redhat.com>
a9640c
Date: Tue, 26 Jan 2016 11:23:46 +0100
a9640c
Subject: [PATCH] vmx: Adapt to emptyBackingString for cdrom-image
a9640c
a9640c
RHEL-7.3: https://bugzilla.redhat.com/show_bug.cgi?id=1275039
a9640c
RHEL-7.2.z: https://bugzilla.redhat.com/show_bug.cgi?id=1301892
a9640c
vdsm ovirt-3.6.z: https://bugzilla.redhat.com/show_bug.cgi?id=1266088
a9640c
a9640c
We are missing this value for cdrom-image device. It seems like
a9640c
there's no added value to extend this to other types of disk
a9640c
devices [1].
a9640c
a9640c
1: https://www.redhat.com/archives/libvir-list/2016-January/msg01038.html
a9640c
a9640c
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
a9640c
(cherry picked from commit 35c3aab44d20daa2623fcf2191fc2e3afc12b9f0)
a9640c
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
a9640c
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a9640c
---
a9640c
 src/vmx/vmx.c                                  | 29 +++++++++++++++++++-------
a9640c
 tests/vmx2xmldata/vmx2xml-cdrom-ide-empty.vmx  |  5 +++++
a9640c
 tests/vmx2xmldata/vmx2xml-cdrom-ide-empty.xml  | 23 ++++++++++++++++++++
a9640c
 tests/vmx2xmldata/vmx2xml-cdrom-scsi-empty.vmx |  6 ++++++
a9640c
 tests/vmx2xmldata/vmx2xml-cdrom-scsi-empty.xml | 23 ++++++++++++++++++++
a9640c
 tests/vmx2xmltest.c                            |  3 +++
a9640c
 tests/xml2vmxdata/xml2vmx-cdrom-ide-empty.vmx  | 13 ++++++++++++
a9640c
 tests/xml2vmxdata/xml2vmx-cdrom-ide-empty.xml  | 13 ++++++++++++
a9640c
 tests/xml2vmxdata/xml2vmx-cdrom-scsi-empty.vmx | 14 +++++++++++++
a9640c
 tests/xml2vmxdata/xml2vmx-cdrom-scsi-empty.xml | 13 ++++++++++++
a9640c
 tests/xml2vmxtest.c                            |  2 ++
a9640c
 11 files changed, 137 insertions(+), 7 deletions(-)
a9640c
 create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-ide-empty.vmx
a9640c
 create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-ide-empty.xml
a9640c
 create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-scsi-empty.vmx
a9640c
 create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-scsi-empty.xml
a9640c
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-ide-empty.vmx
a9640c
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-ide-empty.xml
a9640c
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-scsi-empty.vmx
a9640c
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-scsi-empty.xml
a9640c
a9640c
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
a9640c
index 84f71f7..805ad60 100644
a9640c
--- a/src/vmx/vmx.c
a9640c
+++ b/src/vmx/vmx.c
a9640c
@@ -2176,6 +2176,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
a9640c
                 (*def)->transient = STRCASEEQ(mode,
a9640c
                                               "independent-nonpersistent");
a9640c
         } else if (virFileHasSuffix(fileName, ".iso") ||
a9640c
+                   STREQ(fileName, "emptyBackingString") ||
a9640c
                    (deviceType &&
a9640c
                     (STRCASEEQ(deviceType, "atapi-cdrom") ||
a9640c
                      STRCASEEQ(deviceType, "cdrom-raw") ||
a9640c
@@ -2261,6 +2262,16 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
a9640c
                  */
a9640c
                 goto ignore;
a9640c
             }
a9640c
+        } else if (STREQ(fileName, "emptyBackingString")) {
a9640c
+            if (deviceType && STRCASENEQ(deviceType, "cdrom-image")) {
a9640c
+                virReportError(VIR_ERR_INTERNAL_ERROR,
a9640c
+                               _("Expecting VMX entry '%s' to be 'cdrom-image' "
a9640c
+                                 "but found '%s'"), deviceType_name, deviceType);
a9640c
+                goto cleanup;
a9640c
+            }
a9640c
+
a9640c
+            virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE);
a9640c
+            ignore_value(virDomainDiskSetSource(*def, NULL));
a9640c
         } else {
a9640c
             virReportError(VIR_ERR_INTERNAL_ERROR,
a9640c
                            _("Invalid or not yet handled value '%s' "
a9640c
@@ -3465,15 +3476,19 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def,
a9640c
     if (type == VIR_STORAGE_TYPE_FILE) {
a9640c
         const char *src = virDomainDiskGetSource(def);
a9640c
 
a9640c
-        if (src && ! virFileHasSuffix(src, fileExt)) {
a9640c
-            virReportError(VIR_ERR_INTERNAL_ERROR,
a9640c
-                           _("Image file for %s %s '%s' has "
a9640c
-                             "unsupported suffix, expecting '%s'"),
a9640c
-                           busType, deviceType, def->dst, fileExt);
a9640c
+        if (src) {
a9640c
+            if (!virFileHasSuffix(src, fileExt)) {
a9640c
+                virReportError(VIR_ERR_INTERNAL_ERROR,
a9640c
+                               _("Image file for %s %s '%s' has "
a9640c
+                                 "unsupported suffix, expecting '%s'"),
a9640c
+                               busType, deviceType, def->dst, fileExt);
a9640c
                 return -1;
a9640c
-        }
a9640c
+            }
a9640c
 
a9640c
-        fileName = ctx->formatFileName(src, ctx->opaque);
a9640c
+            fileName = ctx->formatFileName(src, ctx->opaque);
a9640c
+        } else if (def->device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
a9640c
+            ignore_value(VIR_STRDUP(fileName, "emptyBackingString"));
a9640c
+        }
a9640c
 
a9640c
         if (fileName == NULL)
a9640c
             return -1;
a9640c
diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-ide-empty.vmx b/tests/vmx2xmldata/vmx2xml-cdrom-ide-empty.vmx
a9640c
new file mode 100644
a9640c
index 0000000..62fdb3d
a9640c
--- /dev/null
a9640c
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-ide-empty.vmx
a9640c
@@ -0,0 +1,5 @@
a9640c
+config.version = "8"
a9640c
+virtualHW.version = "4"
a9640c
+ide0:0.present = "true"
a9640c
+ide0:0.deviceType = "cdrom-image"
a9640c
+ide0:0.fileName = "emptyBackingString"
a9640c
diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-ide-empty.xml b/tests/vmx2xmldata/vmx2xml-cdrom-ide-empty.xml
a9640c
new file mode 100644
a9640c
index 0000000..e086379
a9640c
--- /dev/null
a9640c
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-ide-empty.xml
a9640c
@@ -0,0 +1,23 @@
a9640c
+<domain type='vmware'>
a9640c
+  <uuid>00000000-0000-0000-0000-000000000000</uuid>
a9640c
+  <memory unit='KiB'>32768</memory>
a9640c
+  <currentMemory unit='KiB'>32768</currentMemory>
a9640c
+  <vcpu placement='static'>1</vcpu>
a9640c
+  <os>
a9640c
+    <type arch='i686'>hvm</type>
a9640c
+  </os>
a9640c
+  <clock offset='utc'/>
a9640c
+  <on_poweroff>destroy</on_poweroff>
a9640c
+  <on_reboot>restart</on_reboot>
a9640c
+  <on_crash>destroy</on_crash>
a9640c
+  <devices>
a9640c
+    <disk type='file' device='cdrom'>
a9640c
+      <target dev='hda' bus='ide'/>
a9640c
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
a9640c
+    </disk>
a9640c
+    <controller type='ide' index='0'/>
a9640c
+    <video>
a9640c
+      <model type='vmvga' vram='4096'/>
a9640c
+    </video>
a9640c
+  </devices>
a9640c
+</domain>
a9640c
diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-scsi-empty.vmx b/tests/vmx2xmldata/vmx2xml-cdrom-scsi-empty.vmx
a9640c
new file mode 100644
a9640c
index 0000000..3c6036a
a9640c
--- /dev/null
a9640c
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-scsi-empty.vmx
a9640c
@@ -0,0 +1,6 @@
a9640c
+config.version = "8"
a9640c
+virtualHW.version = "4"
a9640c
+scsi0.present = "true"
a9640c
+scsi0:0.present = "true"
a9640c
+scsi0:0.deviceType = "cdrom-image"
a9640c
+scsi0:0.fileName = "emptyBackingString"
a9640c
diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-scsi-empty.xml b/tests/vmx2xmldata/vmx2xml-cdrom-scsi-empty.xml
a9640c
new file mode 100644
a9640c
index 0000000..56ad678
a9640c
--- /dev/null
a9640c
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-scsi-empty.xml
a9640c
@@ -0,0 +1,23 @@
a9640c
+<domain type='vmware'>
a9640c
+  <uuid>00000000-0000-0000-0000-000000000000</uuid>
a9640c
+  <memory unit='KiB'>32768</memory>
a9640c
+  <currentMemory unit='KiB'>32768</currentMemory>
a9640c
+  <vcpu placement='static'>1</vcpu>
a9640c
+  <os>
a9640c
+    <type arch='i686'>hvm</type>
a9640c
+  </os>
a9640c
+  <clock offset='utc'/>
a9640c
+  <on_poweroff>destroy</on_poweroff>
a9640c
+  <on_reboot>restart</on_reboot>
a9640c
+  <on_crash>destroy</on_crash>
a9640c
+  <devices>
a9640c
+    <disk type='file' device='cdrom'>
a9640c
+      <target dev='sda' bus='scsi'/>
a9640c
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
a9640c
+    </disk>
a9640c
+    <controller type='scsi' index='0'/>
a9640c
+    <video>
a9640c
+      <model type='vmvga' vram='4096'/>
a9640c
+    </video>
a9640c
+  </devices>
a9640c
+</domain>
a9640c
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c
a9640c
index 1d1fe83..b8dbd31 100644
a9640c
--- a/tests/vmx2xmltest.c
a9640c
+++ b/tests/vmx2xmltest.c
a9640c
@@ -218,14 +218,17 @@ mymain(void)
a9640c
     DO_TEST("harddisk-transient", "harddisk-transient");
a9640c
 
a9640c
     DO_TEST("cdrom-scsi-file", "cdrom-scsi-file");
a9640c
+    DO_TEST("cdrom-scsi-empty", "cdrom-scsi-empty");
a9640c
     DO_TEST("cdrom-scsi-device", "cdrom-scsi-device");
a9640c
     DO_TEST("cdrom-scsi-raw-device", "cdrom-scsi-raw-device");
a9640c
     DO_TEST("cdrom-scsi-raw-auto-detect", "cdrom-scsi-raw-auto-detect");
a9640c
     DO_TEST("cdrom-scsi-passthru", "cdrom-scsi-passthru");
a9640c
     DO_TEST("cdrom-ide-file", "cdrom-ide-file");
a9640c
+    DO_TEST("cdrom-ide-empty", "cdrom-ide-empty");
a9640c
     DO_TEST("cdrom-ide-device", "cdrom-ide-device");
a9640c
     DO_TEST("cdrom-ide-raw-device", "cdrom-ide-raw-device");
a9640c
     DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect");
a9640c
+    DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect");
a9640c
 
a9640c
     DO_TEST("floppy-file", "floppy-file");
a9640c
     DO_TEST("floppy-device", "floppy-device");
a9640c
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-ide-empty.vmx b/tests/xml2vmxdata/xml2vmx-cdrom-ide-empty.vmx
a9640c
new file mode 100644
a9640c
index 0000000..45c7950
a9640c
--- /dev/null
a9640c
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-ide-empty.vmx
a9640c
@@ -0,0 +1,13 @@
a9640c
+.encoding = "UTF-8"
a9640c
+config.version = "8"
a9640c
+virtualHW.version = "4"
a9640c
+guestOS = "other"
a9640c
+uuid.bios = "56 4d 9b ef ac d9 b4 e0-c8 f0 ae a8 b9 10 35 15"
a9640c
+displayName = "cdrom-ide-file"
a9640c
+memsize = "4"
a9640c
+numvcpus = "1"
a9640c
+ide0:0.present = "true"
a9640c
+ide0:0.deviceType = "cdrom-image"
a9640c
+ide0:0.fileName = "emptyBackingString"
a9640c
+floppy0.present = "false"
a9640c
+floppy1.present = "false"
a9640c
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-ide-empty.xml b/tests/xml2vmxdata/xml2vmx-cdrom-ide-empty.xml
a9640c
new file mode 100644
a9640c
index 0000000..219603e
a9640c
--- /dev/null
a9640c
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-ide-empty.xml
a9640c
@@ -0,0 +1,13 @@
a9640c
+<domain type='vmware'>
a9640c
+  <name>cdrom-ide-file</name>
a9640c
+  <uuid>564d9bef-acd9-b4e0-c8f0-aea8b9103515</uuid>
a9640c
+  <memory unit='KiB'>4096</memory>
a9640c
+  <os>
a9640c
+    <type>hvm</type>
a9640c
+  </os>
a9640c
+  <devices>
a9640c
+    <disk type='file' device='cdrom'>
a9640c
+      <target dev='hda' bus='ide'/>
a9640c
+    </disk>
a9640c
+  </devices>
a9640c
+</domain>
a9640c
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-scsi-empty.vmx b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-empty.vmx
a9640c
new file mode 100644
a9640c
index 0000000..1097cb1
a9640c
--- /dev/null
a9640c
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-empty.vmx
a9640c
@@ -0,0 +1,14 @@
a9640c
+.encoding = "UTF-8"
a9640c
+config.version = "8"
a9640c
+virtualHW.version = "4"
a9640c
+guestOS = "other"
a9640c
+uuid.bios = "56 4d 9b ef ac d9 b4 e0-c8 f0 ae a8 b9 10 35 15"
a9640c
+displayName = "cdrom-scsi-empty"
a9640c
+memsize = "4"
a9640c
+numvcpus = "1"
a9640c
+scsi0.present = "true"
a9640c
+scsi0:0.present = "true"
a9640c
+scsi0:0.deviceType = "cdrom-image"
a9640c
+scsi0:0.fileName = "emptyBackingString"
a9640c
+floppy0.present = "false"
a9640c
+floppy1.present = "false"
a9640c
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-scsi-empty.xml b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-empty.xml
a9640c
new file mode 100644
a9640c
index 0000000..a5a6d80
a9640c
--- /dev/null
a9640c
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-empty.xml
a9640c
@@ -0,0 +1,13 @@
a9640c
+<domain type='vmware'>
a9640c
+  <name>cdrom-scsi-empty</name>
a9640c
+  <uuid>564d9bef-acd9-b4e0-c8f0-aea8b9103515</uuid>
a9640c
+  <memory unit='KiB'>4096</memory>
a9640c
+  <os>
a9640c
+    <type>hvm</type>
a9640c
+  </os>
a9640c
+  <devices>
a9640c
+    <disk type='file' device='cdrom'>
a9640c
+      <target dev='sda' bus='scsi'/>
a9640c
+    </disk>
a9640c
+  </devices>
a9640c
+</domain>
a9640c
diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c
a9640c
index 53efe31..0efd278 100644
a9640c
--- a/tests/xml2vmxtest.c
a9640c
+++ b/tests/xml2vmxtest.c
a9640c
@@ -234,11 +234,13 @@ mymain(void)
a9640c
     DO_TEST("harddisk-ide-file", "harddisk-ide-file", 4);
a9640c
 
a9640c
     DO_TEST("cdrom-scsi-file", "cdrom-scsi-file", 4);
a9640c
+    DO_TEST("cdrom-scsi-empty", "cdrom-scsi-empty", 4);
a9640c
     DO_TEST("cdrom-scsi-device", "cdrom-scsi-device", 4);
a9640c
     DO_TEST("cdrom-scsi-raw-device", "cdrom-scsi-raw-device", 4);
a9640c
     DO_TEST("cdrom-scsi-raw-auto-detect", "cdrom-scsi-raw-auto-detect", 4);
a9640c
     DO_TEST("cdrom-scsi-passthru", "cdrom-scsi-passthru", 4);
a9640c
     DO_TEST("cdrom-ide-file", "cdrom-ide-file", 4);
a9640c
+    DO_TEST("cdrom-ide-empty", "cdrom-ide-empty", 4);
a9640c
     DO_TEST("cdrom-ide-device", "cdrom-ide-device", 4);
a9640c
     DO_TEST("cdrom-ide-raw-device", "cdrom-ide-raw-device", 4);
a9640c
     DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect", 4);
a9640c
-- 
a9640c
2.7.0
a9640c