[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv2 1/4] VMX: Add cdrom-raw dev type from VMWare Fusion



According to VMWare's documentation 'cdrom-raw' is an acceptable value
for deviceType for a CD-ROM drive. The documentation states that the VMX
configuration for a CD-ROM deviceType is as follows:

ide|scsi(n):(n).deviceType = "cdrom-raw|atapi-cdrom|cdrom-image"

>From the documentation it appears the following is true:
- cdrom-image = Provides the ISO to the VM
- atapi-cdrom = Provides a NEC emulated ATAPI CD-ROM on top of the host
  CD-ROM
- cdrom-raw = Passthru for a host CD-ROM drive. Allows CD-R burning from
  within the guest.

A CD-ROM prior to this patch would always provide an 'atapi-cdrom' is
modeled as:
  <disk type='block' device='cdrom'>
    <source dev='/dev/scd0'/>
    <target dev='hda' bus='ide'/>
    <address type='drive' controller='0' bus='0' target='0' unit='0'/>
  </disk>

This patch allows an optional element as:
    <driver name='atapi'/>
that would maintain existing behavior. While:
    <driver name='raw'/>
would provide a 'cdrom-raw' to the VM.
---
 docs/formatdomain.html.in                          |  3 +-
 src/vmx/vmx.c                                      | 39 ++++++++++++++++++----
 tests/vmx2xmldata/vmx2xml-cdrom-ide-device.xml     |  1 +
 tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-device.vmx |  5 +++
 tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-device.xml | 25 ++++++++++++++
 tests/vmx2xmldata/vmx2xml-cdrom-scsi-device.xml    |  1 +
 .../vmx2xmldata/vmx2xml-cdrom-scsi-raw-device.vmx  |  6 ++++
 .../vmx2xmldata/vmx2xml-cdrom-scsi-raw-device.xml  | 25 ++++++++++++++
 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-2.xml    |  1 +
 tests/vmx2xmltest.c                                |  2 ++
 .../xml2vmxdata/xml2vmx-cdrom-ide-atapi-device.vmx | 13 ++++++++
 .../xml2vmxdata/xml2vmx-cdrom-ide-atapi-device.xml | 15 +++++++++
 tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-device.vmx | 13 ++++++++
 tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-device.xml | 15 +++++++++
 .../xml2vmx-cdrom-scsi-atapi-device.vmx            | 14 ++++++++
 .../xml2vmx-cdrom-scsi-atapi-device.xml            | 15 +++++++++
 .../xml2vmxdata/xml2vmx-cdrom-scsi-raw-device.vmx  | 14 ++++++++
 .../xml2vmxdata/xml2vmx-cdrom-scsi-raw-device.xml  | 15 +++++++++
 tests/xml2vmxtest.c                                |  4 +++
 19 files changed, 218 insertions(+), 8 deletions(-)
 create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-device.vmx
 create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-device.xml
 create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-device.vmx
 create mode 100644 tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-device.xml
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-ide-atapi-device.vmx
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-ide-atapi-device.xml
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-device.vmx
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-device.xml
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-scsi-atapi-device.vmx
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-scsi-atapi-device.xml
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-device.vmx
 create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-device.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 9d12293..c52b2fa 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1829,7 +1829,8 @@
             supports a name of "tap", "tap2", "phy", or "file", with a
             type of "aio", while qemu only supports a name of "qemu",
             but multiple types including "raw", "bochs", "qcow2", and
-            "qed".
+            "qed". VMWare supports a name of "raw" or "atapi" for CD-ROMs,
+            <span class="since">since 1.1.2.</span>
           </li>
           <li>
             The optional <code>cache</code> attribute controls the
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 35afe26..ba549ab 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1064,6 +1064,14 @@ virVMXHandleLegacySCSIDiskDriverName(virDomainDefPtr def,
         return 0;
     }
 
+    /* Legitmate drivers are 'atapi' and 'raw' for CD-ROMs, so don't
+     * attempt to do legacy parsing on them.
+     */
+    if (STRCASEEQ(disk->driverName, "atapi") ||
+            STRCASEEQ(disk->driverName, "raw")) {
+            return 0;
+    }
+
     tmp = disk->driverName;
 
     for (; *tmp != '\0'; ++tmp) {
@@ -2174,12 +2182,13 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
                 goto cleanup;
             }
         } else if (virFileHasSuffix(fileName, ".iso") ||
-                   STRCASEEQ(deviceType, "atapi-cdrom")) {
+                   STRCASEEQ(deviceType, "atapi-cdrom") ||
+                   STRCASEEQ(deviceType, "cdrom-raw")) {
             /*
              * This function was called in order to parse a harddisk device,
-             * but .iso files and 'atapi-cdrom' devices are for CDROM devices
-             * only. Just ignore it, another call to this function to parse a
-             * CDROM device may handle it.
+             * but .iso files, 'atapi-cdrom', and 'cdrom-raw' devices are for
+             * CDROM devices only. Just ignore it, another call to this
+             * function to parse a CDROM device may handle it.
              */
             goto ignore;
         } else {
@@ -2215,11 +2224,22 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con
              * handle it.
              */
             goto ignore;
-        } else if (STRCASEEQ(deviceType, "atapi-cdrom")) {
+        } else if (STRCASEEQ(deviceType, "atapi-cdrom") ||
+                   STRCASEEQ(deviceType, "cdrom-raw")) {
             (*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK;
             (*def)->src = fileName;
 
             fileName = NULL;
+
+            if (STRCASEEQ(deviceType, "cdrom-raw")) {
+                if (VIR_STRDUP((*def)->driverName, "raw") < 0) {
+                    goto cleanup;
+                }
+            } else {
+                if (VIR_STRDUP((*def)->driverName, "atapi") < 0) {
+                    goto cleanup;
+                }
+            }
         } else {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Invalid or not yet handled value '%s' "
@@ -3526,8 +3546,13 @@ virVMXFormatCDROM(virVMXContext *ctx, virDomainDiskDefPtr def,
             VIR_FREE(fileName);
         }
     } else if (def->type == VIR_DOMAIN_DISK_TYPE_BLOCK) {
-        virBufferAsprintf(buffer, "%s%d:%d.deviceType = \"atapi-cdrom\"\n",
-                          entryPrefix, controllerOrBus, unit);
+        if (def->driverName && STRCASEEQ(def->driverName, "raw")) {
+            virBufferAsprintf(buffer, "%s%d:%d.deviceType = \"cdrom-raw\"\n",
+                              entryPrefix, controllerOrBus, unit);
+        } else {
+            virBufferAsprintf(buffer, "%s%d:%d.deviceType = \"atapi-cdrom\"\n",
+                              entryPrefix, controllerOrBus, unit);
+        }
 
         if (def->src != NULL) {
             virBufferAsprintf(buffer, "%s%d:%d.fileName = \"%s\"\n",
diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-ide-device.xml b/tests/vmx2xmldata/vmx2xml-cdrom-ide-device.xml
index a4bf33c..3639708 100644
--- a/tests/vmx2xmldata/vmx2xml-cdrom-ide-device.xml
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-ide-device.xml
@@ -12,6 +12,7 @@
   <on_crash>destroy</on_crash>
   <devices>
     <disk type='block' device='cdrom'>
+      <driver name='atapi'/>
       <source dev='/dev/scd0'/>
       <target dev='hda' bus='ide'/>
       <address type='drive' controller='0' bus='0' target='0' unit='0'/>
diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-device.vmx b/tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-device.vmx
new file mode 100644
index 0000000..1648111
--- /dev/null
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-device.vmx
@@ -0,0 +1,5 @@
+config.version = "8"
+virtualHW.version = "4"
+ide0:0.present = "true"
+ide0:0.deviceType = "cdrom-raw"
+ide0:0.fileName = "/dev/scd0"
diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-device.xml b/tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-device.xml
new file mode 100644
index 0000000..95967b9
--- /dev/null
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-device.xml
@@ -0,0 +1,25 @@
+<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'/>
+      <source dev='/dev/scd0'/>
+      <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-device.xml b/tests/vmx2xmldata/vmx2xml-cdrom-scsi-device.xml
index 0cdfb91..9b5e583 100644
--- a/tests/vmx2xmldata/vmx2xml-cdrom-scsi-device.xml
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-scsi-device.xml
@@ -12,6 +12,7 @@
   <on_crash>destroy</on_crash>
   <devices>
     <disk type='block' device='cdrom'>
+      <driver name='atapi'/>
       <source dev='/dev/scd0'/>
       <target dev='sda' bus='scsi'/>
       <address type='drive' controller='0' bus='0' target='0' unit='0'/>
diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-device.vmx b/tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-device.vmx
new file mode 100644
index 0000000..773b743
--- /dev/null
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-device.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 = "/dev/scd0"
diff --git a/tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-device.xml b/tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-device.xml
new file mode 100644
index 0000000..52c251e
--- /dev/null
+++ b/tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-device.xml
@@ -0,0 +1,25 @@
+<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'/>
+      <source dev='/dev/scd0'/>
+      <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>
diff --git a/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-2.xml b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-2.xml
index fd3b92c..9401f5d 100644
--- a/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-2.xml
+++ b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-2.xml
@@ -29,6 +29,7 @@
       <address type='drive' controller='0' bus='0' target='0' unit='0'/>
     </disk>
     <disk type='block' device='cdrom'>
+      <driver name='atapi'/>
       <source dev='/dev/scd0'/>
       <target dev='hdb' bus='ide'/>
       <address type='drive' controller='0' bus='0' target='0' unit='1'/>
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c
index c9616de..479c84c 100644
--- a/tests/vmx2xmltest.c
+++ b/tests/vmx2xmltest.c
@@ -237,8 +237,10 @@ 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-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("floppy-file", "floppy-file");
     DO_TEST("floppy-device", "floppy-device");
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-ide-atapi-device.vmx b/tests/xml2vmxdata/xml2vmx-cdrom-ide-atapi-device.vmx
new file mode 100644
index 0000000..13b91b4
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-ide-atapi-device.vmx
@@ -0,0 +1,13 @@
+.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 = "atapi-cdrom"
+ide0:0.fileName = "/dev/scd0"
+floppy0.present = "false"
+floppy1.present = "false"
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-ide-atapi-device.xml b/tests/xml2vmxdata/xml2vmx-cdrom-ide-atapi-device.xml
new file mode 100644
index 0000000..4ec3a7c
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-ide-atapi-device.xml
@@ -0,0 +1,15 @@
+<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='atapi'/>
+      <source dev='/dev/scd0'/>
+      <target dev='hda' bus='ide'/>
+    </disk>
+  </devices>
+</domain>
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-device.vmx b/tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-device.vmx
new file mode 100644
index 0000000..cd391e0
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-device.vmx
@@ -0,0 +1,13 @@
+.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.fileName = "/dev/scd0"
+floppy0.present = "false"
+floppy1.present = "false"
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-device.xml b/tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-device.xml
new file mode 100644
index 0000000..2e71825
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-device.xml
@@ -0,0 +1,15 @@
+<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'/>
+      <source dev='/dev/scd0'/>
+      <target dev='hda' bus='ide'/>
+    </disk>
+  </devices>
+</domain>
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-scsi-atapi-device.vmx b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-atapi-device.vmx
new file mode 100644
index 0000000..705b31b
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-atapi-device.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-scsi-device"
+memsize = "4"
+numvcpus = "1"
+scsi0.present = "true"
+scsi0:0.present = "true"
+scsi0:0.deviceType = "atapi-cdrom"
+scsi0:0.fileName = "/dev/scd0"
+floppy0.present = "false"
+floppy1.present = "false"
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-scsi-atapi-device.xml b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-atapi-device.xml
new file mode 100644
index 0000000..e6da5b5
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-atapi-device.xml
@@ -0,0 +1,15 @@
+<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='atapi'/>
+      <source dev='/dev/scd0'/>
+      <target dev='sda' bus='scsi'/>
+    </disk>
+  </devices>
+</domain>
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-device.vmx b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-device.vmx
new file mode 100644
index 0000000..e044004
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-device.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-scsi-device"
+memsize = "4"
+numvcpus = "1"
+scsi0.present = "true"
+scsi0:0.present = "true"
+scsi0:0.deviceType = "cdrom-raw"
+scsi0:0.fileName = "/dev/scd0"
+floppy0.present = "false"
+floppy1.present = "false"
diff --git a/tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-device.xml b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-device.xml
new file mode 100644
index 0000000..466249d
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-device.xml
@@ -0,0 +1,15 @@
+<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'/>
+      <source dev='/dev/scd0'/>
+      <target dev='sda' bus='scsi'/>
+    </disk>
+  </devices>
+</domain>
diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c
index 0dffebd..20176de 100644
--- a/tests/xml2vmxtest.c
+++ b/tests/xml2vmxtest.c
@@ -253,8 +253,12 @@ mymain(void)
 
     DO_TEST("cdrom-scsi-file", "cdrom-scsi-file", 4);
     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-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("floppy-file", "floppy-file", 4);
     DO_TEST("floppy-device", "floppy-device", 4);
-- 
1.8.1.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]