[libvirt] [PATCHv2 2/4] VMX: Add support for 'auto detect' fileNames

Doug Goldstein cardoe at cardoe.com
Fri Aug 23 01:53:07 UTC 2013


VMWare Fusion 5 can set the CD-ROM's device name to be 'auto detect' when
using the physical drive via 'cdrom-raw' device type. VMWare will then
connect to first available host CD-ROM to the virtual machine upon start
up according to VMWare documentation.

To better model this a CD-ROM that is marked as "auto detect" when in
the off state would be modeled as the following with this patch:
  <disk type='block' device='cdrom'>
    <target dev='hda' bus='ide' tray='open'/>
    <address type='drive' controller='0' bus='0' target='0' unit='0'/>
  </disk>

Note the tray state being marked as 'open', while the <source> element is
omitted.
---
 src/vmx/vmx.c                                      | 20 ++++++++++++++++--
 .../vmx2xml-cdrom-ide-raw-auto-detect.vmx          |  5 +++++
 .../vmx2xml-cdrom-ide-raw-auto-detect.xml          | 24 ++++++++++++++++++++++
 .../vmx2xml-cdrom-scsi-raw-auto-detect.vmx         |  6 ++++++
 .../vmx2xml-cdrom-scsi-raw-auto-detect.xml         | 24 ++++++++++++++++++++++
 tests/vmx2xmltest.c                                |  2 ++
 .../xml2vmx-cdrom-ide-raw-auto-detect.vmx          | 14 +++++++++++++
 .../xml2vmx-cdrom-ide-raw-auto-detect.xml          | 14 +++++++++++++
 .../xml2vmx-cdrom-scsi-raw-auto-detect.vmx         | 15 ++++++++++++++
 .../xml2vmx-cdrom-scsi-raw-auto-detect.xml         | 14 +++++++++++++
 tests/xml2vmxtest.c                                |  2 ++
 11 files changed, 138 insertions(+), 2 deletions(-)
 create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-auto-detect.vmx
 create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-auto-detect.xml
 create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-auto-detect.vmx
 create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-auto-detect.xml
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-auto-detect.vmx
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-auto-detect.xml
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-auto-detect.vmx
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-auto-detect.xml

diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index ba549ab..e7732e4 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -2227,9 +2227,14 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
         } else if (STRCASEEQ(deviceType, "atapi-cdrom") ||
                    STRCASEEQ(deviceType, "cdrom-raw")) {
             (*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
-            (*def)->src = fileName;
 
-            fileName = NULL;
+            if (STRCASENEQ(fileName, "auto detect")) {
+                (*def)->src = fileName;
+                fileName = NULL;
+            } else {
+                (*def)->tray_status = VIR_DOMAIN_DISK_TRAY_OPEN;
+                (*def)->src = NULL;
+            }
 
             if (STRCASEEQ(deviceType, "cdrom-raw")) {
                 if (VIR_STRDUP((*def)->driverName, "raw") < 0) {
@@ -3546,6 +3551,11 @@ virVMXFormatCDROM(virVMXContext *ctx, virDomainDiskDefPtr def,
             VIR_FREE(fileName);
         }
     } else if (def->type == VIR_DOMAIN_DISK_TYPE_BLOCK) {
+        if (!def->src && def->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN) {
+            virBufferAsprintf(buffer, "%s%d:%d.autodetect = \"true\"\n",
+                              entryPrefix, controllerOrBus, unit);
+        }
+
         if (def->driverName && STRCASEEQ(def->driverName, "raw")) {
             virBufferAsprintf(buffer, "%s%d:%d.deviceType = \"cdrom-raw\"\n",
                               entryPrefix, controllerOrBus, unit);
@@ -3557,6 +3567,12 @@ virVMXFormatCDROM(virVMXContext *ctx, virDomainDiskDefPtr def,
         if (def->src != NULL) {
             virBufferAsprintf(buffer, "%s%d:%d.fileName = \"%s\"\n",
                               entryPrefix, controllerOrBus, unit, def->src);
+        } else {
+            if (def->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN) {
+                virBufferAsprintf(buffer, "%s%d:%d.fileName = "
+                                  "\"auto detect\"\n", entryPrefix,
+                                  controllerOrBus, unit);
+            }
         }
     } else {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-auto-detect.vmx b/tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-auto-detect.vmx
new file mode 100644
index 0000000..b2c4caf
--- /dev/null
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-auto-detect.vmx
@@ -0,0 +1,5 @@
+config.version = "8"
+virtualHW.version = "4"
+ide0:0.present = "true"
+ide0:0.deviceType = "cdrom-raw"
+ide0:0.fileName = "auto detect"
diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-auto-detect.xml b/tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-auto-detect.xml
new file mode 100644
index 0000000..1e32be5
--- /dev/null
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-auto-detect.xml
@@ -0,0 +1,24 @@
+<domain type='vmware'>
+  <uuid>00000000-0000-0000-0000-000000000000</uuid>
+  <memory unit='KiB'>32768</memory>
+  <currentMemory unit='KiB'>32768</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686'>hvm</type>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='block' device='cdrom'>
+      <driver name='raw'/>
+      <target dev='hda' bus='ide' tray='open'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='ide' index='0'/>
+    <video>
+      <model type='vmvga' vram='4096'/>
+    </video>
+  </devices>
+</domain>
diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-auto-detect.vmx b/tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-auto-detect.vmx
new file mode 100644
index 0000000..0209b29
--- /dev/null
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-auto-detect.vmx
@@ -0,0 +1,6 @@
+config.version = "8"
+virtualHW.version = "4"
+scsi0.present = "true"
+scsi0:0.present = "true"
+scsi0:0.deviceType = "cdrom-raw"
+scsi0:0.fileName = "auto detect"
diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-auto-detect.xml b/tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-auto-detect.xml
new file mode 100644
index 0000000..e469746
--- /dev/null
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-auto-detect.xml
@@ -0,0 +1,24 @@
+<domain type='vmware'>
+  <uuid>00000000-0000-0000-0000-000000000000</uuid>
+  <memory unit='KiB'>32768</memory>
+  <currentMemory unit='KiB'>32768</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686'>hvm</type>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='block' device='cdrom'>
+      <driver name='raw'/>
+      <target dev='sda' bus='scsi' tray='open'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='scsi' index='0'/>
+    <video>
+      <model type='vmvga' vram='4096'/>
+    </video>
+  </devices>
+</domain>
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c
index 479c84c..5eb04e9 100644
--- a/tests/vmx2xmltest.c
+++ b/tests/vmx2xmltest.c
@@ -238,9 +238,11 @@ mymain(void)
     DO_TEST("cdrom-scsi-file", "cdrom-scsi-file");
     DO_TEST("cdrom-scsi-device", "cdrom-scsi-device");
     DO_TEST("cdrom-scsi-raw-device", "cdrom-scsi-raw-device");
+    DO_TEST("cdrom-scsi-raw-auto-detect", "cdrom-scsi-raw-auto-detect");
     DO_TEST("cdrom-ide-file", "cdrom-ide-file");
     DO_TEST("cdrom-ide-device", "cdrom-ide-device");
     DO_TEST("cdrom-ide-raw-device", "cdrom-ide-raw-device");
+    DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect");
 
     DO_TEST("floppy-file", "floppy-file");
     DO_TEST("floppy-device", "floppy-device");
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-auto-detect.vmx b/tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-auto-detect.vmx
new file mode 100644
index 0000000..da41b90
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-auto-detect.vmx
@@ -0,0 +1,14 @@
+.encoding = "UTF-8"
+config.version = "8"
+virtualHW.version = "4"
+guestOS = "other"
+uuid.bios = "56 4d 9b ef ac d9 b4 e0-c8 f0 ae a8 b9 10 35 15"
+displayName = "cdrom-ide-device"
+memsize = "4"
+numvcpus = "1"
+ide0:0.present = "true"
+ide0:0.autodetect = "true"
+ide0:0.deviceType = "cdrom-raw"
+ide0:0.fileName = "auto detect"
+floppy0.present = "false"
+floppy1.present = "false"
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-auto-detect.xml b/tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-auto-detect.xml
new file mode 100644
index 0000000..ba3e60b
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-auto-detect.xml
@@ -0,0 +1,14 @@
+<domain type='vmware'>
+  <name>cdrom-ide-device</name>
+  <uuid>564d9bef-acd9-b4e0-c8f0-aea8b9103515</uuid>
+  <memory unit='KiB'>4096</memory>
+  <os>
+    <type>hvm</type>
+  </os>
+  <devices>
+    <disk type='block' device='cdrom'>
+      <driver name='raw'/>
+      <target dev='hda' bus='ide' tray='open'/>
+    </disk>
+  </devices>
+</domain>
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-auto-detect.vmx b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-auto-detect.vmx
new file mode 100644
index 0000000..e3ddc6a
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-auto-detect.vmx
@@ -0,0 +1,15 @@
+.encoding = "UTF-8"
+config.version = "8"
+virtualHW.version = "4"
+guestOS = "other"
+uuid.bios = "56 4d 9b ef ac d9 b4 e0-c8 f0 ae a8 b9 10 35 15"
+displayName = "cdrom-scsi-device"
+memsize = "4"
+numvcpus = "1"
+scsi0.present = "true"
+scsi0:0.present = "true"
+scsi0:0.autodetect = "true"
+scsi0:0.deviceType = "cdrom-raw"
+scsi0:0.fileName = "auto detect"
+floppy0.present = "false"
+floppy1.present = "false"
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-auto-detect.xml b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-auto-detect.xml
new file mode 100644
index 0000000..913545f
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-auto-detect.xml
@@ -0,0 +1,14 @@
+<domain type='vmware'>
+  <name>cdrom-scsi-device</name>
+  <uuid>564d9bef-acd9-b4e0-c8f0-aea8b9103515</uuid>
+  <memory unit='KiB'>4096</memory>
+  <os>
+    <type>hvm</type>
+  </os>
+  <devices>
+    <disk type='block' device='cdrom'>
+      <driver name='raw'/>
+      <target dev='sda' bus='scsi' tray='open'/>
+    </disk>
+  </devices>
+</domain>
diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c
index 20176de..2f325de 100644
--- a/tests/xml2vmxtest.c
+++ b/tests/xml2vmxtest.c
@@ -255,10 +255,12 @@ mymain(void)
     DO_TEST("cdrom-scsi-device", "cdrom-scsi-device", 4);
     DO_TEST("cdrom-scsi-atapi-device", "cdrom-scsi-atapi-device", 4);
     DO_TEST("cdrom-scsi-raw-device", "cdrom-scsi-raw-device", 4);
+    DO_TEST("cdrom-scsi-raw-auto-detect", "cdrom-scsi-raw-auto-detect", 4);
     DO_TEST("cdrom-ide-file", "cdrom-ide-file", 4);
     DO_TEST("cdrom-ide-device", "cdrom-ide-device", 4);
     DO_TEST("cdrom-ide-atapi-device", "cdrom-ide-atapi-device", 4);
     DO_TEST("cdrom-ide-raw-device", "cdrom-ide-raw-device", 4);
+    DO_TEST("cdrom-ide-raw-auto-detect", "cdrom-ide-raw-auto-detect", 4);
 
     DO_TEST("floppy-file", "floppy-file", 4);
     DO_TEST("floppy-device", "floppy-device", 4);
-- 
1.8.1.5




More information about the libvir-list mailing list