render / rpms / libvirt

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