d76c62
From f600a3df720e1d68c621e739acbed0554f5f5fb0 Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <f600a3df720e1d68c621e739acbed0554f5f5fb0@dist-git>
d76c62
From: Pino Toscano <ptoscano@redhat.com>
d76c62
Date: Fri, 20 Mar 2020 13:25:39 +0100
d76c62
Subject: [PATCH] vmx: make 'fileName' optional for CD-ROMs
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
It seems like CD-ROMs may have no 'fileName' property specified in case
d76c62
there is nothing configured as attachment for the drive. Hence, make
d76c62
sure that virVMXParseDisk() do not consider it mandatory anymore,
d76c62
considering it an empty block cdrom device. Sadly virVMXParseDisk() is
d76c62
used also to parse disk and floppies, so make sure that a NULL fileName
d76c62
is handled in cdrom- and floppy-related paths.
d76c62
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1808610
d76c62
d76c62
Signed-off-by: Pino Toscano <ptoscano@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
Tested-by: Richard W.M. Jones <rjones@redhat.com>
d76c62
(cherry picked from commit c5ee737bc5c0fc61451e45ff41526270bdf0113c)
d76c62
Signed-off-by: Pino Toscano <ptoscano@redhat.com>
d76c62
Message-Id: <20200320122539.141785-3-ptoscano@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
---
d76c62
 src/vmx/vmx.c                                 | 25 ++++++++++---------
d76c62
 .../vmx2xmldata/vmx2xml-cdrom-ide-empty-2.vmx |  4 +++
d76c62
 .../vmx2xmldata/vmx2xml-cdrom-ide-empty-2.xml | 23 +++++++++++++++++
d76c62
 tests/vmx2xmltest.c                           |  1 +
d76c62
 4 files changed, 41 insertions(+), 12 deletions(-)
d76c62
 create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-ide-empty-2.vmx
d76c62
 create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-ide-empty-2.xml
d76c62
d76c62
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
d76c62
index fc4fa1c22b..d0bcb9c2de 100644
d76c62
--- a/src/vmx/vmx.c
d76c62
+++ b/src/vmx/vmx.c
d76c62
@@ -2206,7 +2206,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
d76c62
         goto cleanup;
d76c62
 
d76c62
     /* vmx:fileName -> def:src, def:type */
d76c62
-    if (virVMXGetConfigString(conf, fileName_name, &fileName, false) < 0)
d76c62
+    if (virVMXGetConfigString(conf, fileName_name, &fileName, true) < 0)
d76c62
         goto cleanup;
d76c62
 
d76c62
     /* vmx:writeThrough -> def:cachemode */
d76c62
@@ -2217,7 +2217,8 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
d76c62
 
d76c62
     /* Setup virDomainDiskDef */
d76c62
     if (device == VIR_DOMAIN_DISK_DEVICE_DISK) {
d76c62
-        if (virStringHasCaseSuffix(fileName, ".iso") ||
d76c62
+        if (fileName == NULL ||
d76c62
+            virStringHasCaseSuffix(fileName, ".iso") ||
d76c62
             STREQ(fileName, "emptyBackingString") ||
d76c62
             (deviceType &&
d76c62
              (STRCASEEQ(deviceType, "atapi-cdrom") ||
d76c62
@@ -2276,7 +2277,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
d76c62
             goto cleanup;
d76c62
         }
d76c62
     } else if (device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
d76c62
-        if (virStringHasCaseSuffix(fileName, ".vmdk")) {
d76c62
+        if (fileName && virStringHasCaseSuffix(fileName, ".vmdk")) {
d76c62
             /*
d76c62
              * This function was called in order to parse a CDROM device, but
d76c62
              * .vmdk files are for harddisk devices only. Just ignore it,
d76c62
@@ -2284,7 +2285,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
d76c62
              * handle it.
d76c62
              */
d76c62
             goto ignore;
d76c62
-        } else if (virStringHasCaseSuffix(fileName, ".iso")) {
d76c62
+        } else if (fileName && virStringHasCaseSuffix(fileName, ".iso")) {
d76c62
             char *tmp;
d76c62
 
d76c62
             if (deviceType && STRCASENEQ(deviceType, "cdrom-image")) {
d76c62
@@ -2305,7 +2306,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
d76c62
         } else if (deviceType && STRCASEEQ(deviceType, "atapi-cdrom")) {
d76c62
             virDomainDiskSetType(*def, VIR_STORAGE_TYPE_BLOCK);
d76c62
 
d76c62
-            if (STRCASEEQ(fileName, "auto detect")) {
d76c62
+            if (fileName && STRCASEEQ(fileName, "auto detect")) {
d76c62
                 ignore_value(virDomainDiskSetSource(*def, NULL));
d76c62
                 (*def)->startupPolicy = VIR_DOMAIN_STARTUP_POLICY_OPTIONAL;
d76c62
             } else if (virDomainDiskSetSource(*def, fileName) < 0) {
d76c62
@@ -2316,7 +2317,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
d76c62
             (*def)->device = VIR_DOMAIN_DISK_DEVICE_LUN;
d76c62
             virDomainDiskSetType(*def, VIR_STORAGE_TYPE_BLOCK);
d76c62
 
d76c62
-            if (STRCASEEQ(fileName, "auto detect")) {
d76c62
+            if (fileName && STRCASEEQ(fileName, "auto detect")) {
d76c62
                 ignore_value(virDomainDiskSetSource(*def, NULL));
d76c62
                 (*def)->startupPolicy = VIR_DOMAIN_STARTUP_POLICY_OPTIONAL;
d76c62
             } else if (virDomainDiskSetSource(*def, fileName) < 0) {
d76c62
@@ -2324,7 +2325,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
d76c62
             }
d76c62
         } else if (busType == VIR_DOMAIN_DISK_BUS_SCSI &&
d76c62
                    deviceType && STRCASEEQ(deviceType, "scsi-passthru")) {
d76c62
-            if (STRPREFIX(fileName, "/vmfs/devices/cdrom/")) {
d76c62
+            if (fileName && STRPREFIX(fileName, "/vmfs/devices/cdrom/")) {
d76c62
                 /* SCSI-passthru CD-ROMs actually are device='lun' */
d76c62
                 (*def)->device = VIR_DOMAIN_DISK_DEVICE_LUN;
d76c62
                 virDomainDiskSetType(*def, VIR_STORAGE_TYPE_BLOCK);
d76c62
@@ -2340,7 +2341,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
d76c62
                  */
d76c62
                 goto ignore;
d76c62
             }
d76c62
-        } else if (STREQ(fileName, "emptyBackingString")) {
d76c62
+        } else if (fileName && STREQ(fileName, "emptyBackingString")) {
d76c62
             if (deviceType && STRCASENEQ(deviceType, "cdrom-image")) {
d76c62
                 virReportError(VIR_ERR_INTERNAL_ERROR,
d76c62
                                _("Expecting VMX entry '%s' to be 'cdrom-image' "
d76c62
@@ -2354,7 +2355,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
d76c62
             virReportError(VIR_ERR_INTERNAL_ERROR,
d76c62
                            _("Invalid or not yet handled value '%s' "
d76c62
                              "for VMX entry '%s' for device type '%s'"),
d76c62
-                           fileName, fileName_name,
d76c62
+                           NULLSTR(fileName), fileName_name,
d76c62
                            deviceType ? deviceType : "unknown");
d76c62
             goto cleanup;
d76c62
         }
d76c62
@@ -2364,10 +2365,10 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
d76c62
             if (virDomainDiskSetSource(*def, fileName) < 0)
d76c62
                 goto cleanup;
d76c62
         } else if (fileType != NULL && STRCASEEQ(fileType, "file")) {
d76c62
-            char *tmp;
d76c62
+            char *tmp = NULL;
d76c62
 
d76c62
             virDomainDiskSetType(*def, VIR_STORAGE_TYPE_FILE);
d76c62
-            if (!(tmp = ctx->parseFileName(fileName, ctx->opaque)))
d76c62
+            if (fileName && !(tmp = ctx->parseFileName(fileName, ctx->opaque)))
d76c62
                 goto cleanup;
d76c62
             if (virDomainDiskSetSource(*def, tmp) < 0) {
d76c62
                 VIR_FREE(tmp);
d76c62
@@ -2378,7 +2379,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
d76c62
             virReportError(VIR_ERR_INTERNAL_ERROR,
d76c62
                            _("Invalid or not yet handled value '%s' "
d76c62
                              "for VMX entry '%s' for device type '%s'"),
d76c62
-                           fileName, fileName_name,
d76c62
+                           NULLSTR(fileName), fileName_name,
d76c62
                            deviceType ? deviceType : "unknown");
d76c62
             goto cleanup;
d76c62
         }
d76c62
diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-ide-empty-2.vmx b/tests/vmx2xmldata/vmx2xml-cdrom-ide-empty-2.vmx
d76c62
new file mode 100644
d76c62
index 0000000000..36286cb20f
d76c62
--- /dev/null
d76c62
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-ide-empty-2.vmx
d76c62
@@ -0,0 +1,4 @@
d76c62
+config.version = "8"
d76c62
+virtualHW.version = "4"
d76c62
+ide0:0.present = "true"
d76c62
+ide0:0.deviceType = "atapi-cdrom"
d76c62
diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-ide-empty-2.xml b/tests/vmx2xmldata/vmx2xml-cdrom-ide-empty-2.xml
d76c62
new file mode 100644
d76c62
index 0000000000..af4a5ff9f6
d76c62
--- /dev/null
d76c62
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-ide-empty-2.xml
d76c62
@@ -0,0 +1,23 @@
d76c62
+<domain type='vmware'>
d76c62
+  <uuid>00000000-0000-0000-0000-000000000000</uuid>
d76c62
+  <memory unit='KiB'>32768</memory>
d76c62
+  <currentMemory unit='KiB'>32768</currentMemory>
d76c62
+  <vcpu placement='static'>1</vcpu>
d76c62
+  <os>
d76c62
+    <type arch='i686'>hvm</type>
d76c62
+  </os>
d76c62
+  <clock offset='utc'/>
d76c62
+  <on_poweroff>destroy</on_poweroff>
d76c62
+  <on_reboot>restart</on_reboot>
d76c62
+  <on_crash>destroy</on_crash>
d76c62
+  <devices>
d76c62
+    <disk type='block' device='cdrom'>
d76c62
+      <target dev='hda' bus='ide'/>
d76c62
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
d76c62
+    </disk>
d76c62
+    <controller type='ide' index='0'/>
d76c62
+    <video>
d76c62
+      <model type='vmvga' vram='4096' primary='yes'/>
d76c62
+    </video>
d76c62
+  </devices>
d76c62
+</domain>
d76c62
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c
d76c62
index 8d7b8ba2a4..1966aed6fe 100644
d76c62
--- a/tests/vmx2xmltest.c
d76c62
+++ b/tests/vmx2xmltest.c
d76c62
@@ -218,6 +218,7 @@ mymain(void)
d76c62
     DO_TEST("cdrom-scsi-passthru", "cdrom-scsi-passthru");
d76c62
     DO_TEST("cdrom-ide-file", "cdrom-ide-file");
d76c62
     DO_TEST("cdrom-ide-empty", "cdrom-ide-empty");
d76c62
+    DO_TEST("cdrom-ide-empty-2", "cdrom-ide-empty-2");
d76c62
     DO_TEST("cdrom-ide-device", "cdrom-ide-device");
d76c62
     DO_TEST("cdrom-ide-raw-device", "cdrom-ide-raw-device");
d76c62
     DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect");
d76c62
-- 
d76c62
2.25.1
d76c62