]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
VMX: Add support for 'auto detect' fileNames
authorDoug Goldstein <cardoe@cardoe.com>
Tue, 13 Aug 2013 15:56:01 +0000 (10:56 -0500)
committerDoug Goldstein <cardoe@cardoe.com>
Tue, 17 Sep 2013 19:10:40 +0000 (14:10 -0500)
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. If no device is available, it
appears that the device will remain disconnected.

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='lun'>
    <source startupPolicy='optional'/>
    <target dev='hda' bus='ide'/>
    <address type='drive' controller='0' bus='0' target='0' unit='0'/>
  </disk>

Once the domain transitions to the powered on state, libvirt can
populate the remaining source data with what is connected, if anything.
However future power cycles, the domain may not always start with that
device attached.

src/vmx/vmx.c
tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-auto-detect.vmx [new file with mode: 0644]
tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-auto-detect.xml [new file with mode: 0644]
tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-auto-detect.vmx [new file with mode: 0644]
tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-auto-detect.xml [new file with mode: 0644]
tests/vmx2xmltest.c
tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-auto-detect.vmx [new file with mode: 0644]
tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-auto-detect.xml [new file with mode: 0644]
tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-auto-detect.vmx [new file with mode: 0644]
tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-auto-detect.xml [new file with mode: 0644]
tests/xml2vmxtest.c

index 40416a0f88552d024e7df6bdcf1316503706fe7d..5c2c79430f158d738b84807d2da9311d76ac770b 100644 (file)
@@ -2221,14 +2221,26 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
             goto ignore;
         } else if (STRCASEEQ(deviceType, "atapi-cdrom")) {
             (*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
-            (*def)->src = fileName;
-            fileName = NULL;
+
+            if (STRCASEEQ(fileName, "auto detect")) {
+                (*def)->src = NULL;
+                (*def)->startupPolicy = VIR_DOMAIN_STARTUP_POLICY_OPTIONAL;
+            } else {
+                (*def)->src = fileName;
+                fileName = NULL;
+            }
         } else if (STRCASEEQ(deviceType, "cdrom-raw")) {
             /* Raw access CD-ROMs actually are device='lun' */
             (*def)->device = VIR_DOMAIN_DISK_DEVICE_LUN;
             (*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
-            (*def)->src = fileName;
-            fileName = NULL;
+
+            if (STRCASEEQ(fileName, "auto detect")) {
+                (*def)->src = NULL;
+                (*def)->startupPolicy = VIR_DOMAIN_STARTUP_POLICY_OPTIONAL;
+            } else {
+                (*def)->src = fileName;
+                fileName = NULL;
+            }
         } else {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Invalid or not yet handled value '%s' "
@@ -3473,7 +3485,13 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def,
 
         VIR_FREE(fileName);
     } else if (def->type == VIR_DOMAIN_DISK_TYPE_BLOCK) {
-        if (def->src != NULL) {
+        if (!def->src &&
+            def->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_OPTIONAL) {
+            virBufferAsprintf(buffer, "%s%d:%d.autodetect = \"true\"\n",
+                              busType, controllerOrBus, unit);
+            virBufferAsprintf(buffer, "%s%d:%d.fileName = \"auto detect\"\n",
+                              busType, controllerOrBus, unit);
+        } else {
             virBufferAsprintf(buffer, "%s%d:%d.fileName = \"%s\"\n",
                               busType, controllerOrBus, unit, def->src);
         }
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 (file)
index 0000000..b2c4caf
--- /dev/null
@@ -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 (file)
index 0000000..bce708d
--- /dev/null
@@ -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='lun'>
+      <source startupPolicy='optional'/>
+      <target dev='hda' bus='ide'/>
+      <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 (file)
index 0000000..0209b29
--- /dev/null
@@ -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 (file)
index 0000000..a81646a
--- /dev/null
@@ -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='lun'>
+      <source startupPolicy='optional'/>
+      <target dev='sda' bus='scsi'/>
+      <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>
index 479c84c14cfbd653bffdab9f007e439aa10fabd0..5eb04e9ea46ff7d2a36a2f5337b76f0ccb8036ee 100644 (file)
@@ -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 (file)
index 0000000..34e1467
--- /dev/null
@@ -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.deviceType = "cdrom-raw"
+ide0:0.autodetect = "true"
+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 (file)
index 0000000..166410c
--- /dev/null
@@ -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='lun'>
+      <source startupPolicy='optional'/>
+      <target dev='hda' bus='ide'/>
+    </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 (file)
index 0000000..84ec646
--- /dev/null
@@ -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.deviceType = "cdrom-raw"
+scsi0:0.autodetect = "true"
+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 (file)
index 0000000..6531ec8
--- /dev/null
@@ -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='lun'>
+      <source startupPolicy='optional'/>
+      <target dev='sda' bus='scsi'/>
+    </disk>
+  </devices>
+</domain>
index cb1c29c46dea3d5a8a94cb7dec87f9c339165a26..cafcc368ff963c9ed9123962f57f4b8e82609912 100644 (file)
@@ -254,9 +254,11 @@ mymain(void)
     DO_TEST("cdrom-scsi-file", "cdrom-scsi-file", 4);
     DO_TEST("cdrom-scsi-device", "cdrom-scsi-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-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);