From f8456e5a18671544cea341ec8a3e82a7a21035d8 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Mon, 12 Aug 2013 20:55:57 -0500 Subject: [PATCH] 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:
This patch allows the 'device' attribute to be set to 'lun' for a raw acccess CD-ROM such as:
--- docs/formatdomain.html.in | 3 +- src/vmx/vmx.c | 30 ++++++++++++++----- .../vmx2xml-cdrom-ide-raw-device.vmx | 5 ++++ .../vmx2xml-cdrom-ide-raw-device.xml | 24 +++++++++++++++ .../vmx2xml-cdrom-scsi-raw-device.vmx | 6 ++++ .../vmx2xml-cdrom-scsi-raw-device.xml | 24 +++++++++++++++ tests/vmx2xmltest.c | 2 ++ .../xml2vmx-cdrom-ide-raw-device.vmx | 13 ++++++++ .../xml2vmx-cdrom-ide-raw-device.xml | 14 +++++++++ .../xml2vmx-cdrom-scsi-raw-device.vmx | 14 +++++++++ .../xml2vmx-cdrom-scsi-raw-device.xml | 14 +++++++++ tests/xml2vmxtest.c | 2 ++ 12 files changed, 141 insertions(+), 10 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-raw-device.vmx create mode 100644 tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-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 e7fbe5f051..f8bfe0b961 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -1597,8 +1597,7 @@ defaulting to "disk".

Using "lun" (since 0.9.10) is only - valid when type is "block" and the target element's "bus" - attribute is "virtio", and behaves identically to "disk", + valid when type is "block", and behaves identically to "disk", except that generic SCSI commands from the guest are accepted and passed through to the physical device. Also note that device='lun' will only be recognized for actual raw devices, diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 06a22a72f5..40416a0f88 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1936,12 +1936,16 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con virDomainDiskDefPtr *def) { /* - * device = {VIR_DOMAIN_DISK_DEVICE_DISK, VIR_DOMAIN_DISK_DEVICE_CDROM} + * device = {VIR_DOMAIN_DISK_DEVICE_DISK, + * VIR_DOMAIN_DISK_DEVICE_CDROM, + * VIR_DOMAIN_DISK_DEVICE_LUN} * busType = VIR_DOMAIN_DISK_BUS_SCSI * controllerOrBus = [0..3] -> controller * unit = [0..6,8..15] * - * device = {VIR_DOMAIN_DISK_DEVICE_DISK, VIR_DOMAIN_DISK_DEVICE_CDROM} + * device = {VIR_DOMAIN_DISK_DEVICE_DISK, + * VIR_DOMAIN_DISK_DEVICE_CDROM, + * VIR_DOMAIN_DISK_DEVICE_LUN} * busType = VIR_DOMAIN_DISK_BUS_IDE * controllerOrBus = [0..1] -> bus * unit = [0..1] @@ -2173,12 +2177,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 { @@ -2217,7 +2222,12 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con } else if (STRCASEEQ(deviceType, "atapi-cdrom")) { (*def)->type = VIR_DOMAIN_DISK_TYPE_BLOCK; (*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; } else { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -3213,6 +3223,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe switch (def->disks[i]->device) { case VIR_DOMAIN_DISK_DEVICE_DISK: case VIR_DOMAIN_DISK_DEVICE_CDROM: + case VIR_DOMAIN_DISK_DEVICE_LUN: if (virVMXFormatDisk(ctx, def->disks[i], &buffer) < 0) { goto cleanup; } @@ -3383,7 +3394,8 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def, /* Check that we got a valid device type */ if (def->device != VIR_DOMAIN_DISK_DEVICE_DISK && - def->device != VIR_DOMAIN_DISK_DEVICE_CDROM) { + def->device != VIR_DOMAIN_DISK_DEVICE_CDROM && + def->device != VIR_DOMAIN_DISK_DEVICE_LUN) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid device type supplied: %s"), deviceType); return -1; @@ -3427,6 +3439,8 @@ virVMXFormatDisk(virVMXContext *ctx, virDomainDiskDefPtr def, vmxDeviceType = "cdrom-image"; else vmxDeviceType = "atapi-cdrom"; + } else if (def->device == VIR_DOMAIN_DISK_DEVICE_LUN) { + vmxDeviceType = "cdrom-raw"; } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("%s %s '%s' has an unsupported type '%s'"), 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 0000000000..164811140f --- /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 0000000000..530a29a7f2 --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-cdrom-ide-raw-device.xml @@ -0,0 +1,24 @@ + + 00000000-0000-0000-0000-000000000000 + 32768 + 32768 + 1 + + hvm + + + destroy + restart + destroy + + + + +

+ + + + + 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 0000000000..773b7432ea --- /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 0000000000..bca8510ab4 --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-cdrom-scsi-raw-device.xml @@ -0,0 +1,24 @@ + + 00000000-0000-0000-0000-000000000000 + 32768 + 32768 + 1 + + hvm + + + destroy + restart + destroy + + + + +
+ + + + + diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index c9616de2e7..479c84c14c 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-raw-device.vmx b/tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-device.vmx new file mode 100644 index 0000000000..cd391e06ec --- /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 0000000000..ef4c7b103e --- /dev/null +++ b/tests/xml2vmxdata/xml2vmx-cdrom-ide-raw-device.xml @@ -0,0 +1,14 @@ + + cdrom-ide-device + 564d9bef-acd9-b4e0-c8f0-aea8b9103515 + 4096 + + hvm + + + + + + + + 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 0000000000..e044004691 --- /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 0000000000..253763f3f5 --- /dev/null +++ b/tests/xml2vmxdata/xml2vmx-cdrom-scsi-raw-device.xml @@ -0,0 +1,14 @@ + + cdrom-scsi-device + 564d9bef-acd9-b4e0-c8f0-aea8b9103515 + 4096 + + hvm + + + + + + + + diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index 0dffebd38b..cb1c29c46d 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -253,8 +253,10 @@ 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-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("floppy-file", "floppy-file", 4); DO_TEST("floppy-device", "floppy-device", 4);