Add support for CDROM devices for bhyve driver using
bhyve(8)'s 'ahci-cd' device type.

As bhyve currently does not support media insertion at runtime,
disallow to start a domain with an empty source path for cdrom
devices.
---
 src/bhyve/bhyve_command.c                          | 43 +++++++++++++++++-----
 .../bhyvexml2argv-disk-cdrom.args                  |  3 ++
 .../bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.xml | 22 +++++++++++
 tests/bhyvexml2argvtest.c                          |  1 +
 4 files changed, 59 insertions(+), 10 deletions(-)
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.args
 create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.xml

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index f1862fe..7862bc8 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -152,13 +152,31 @@ bhyveBuildDiskArgStr(const virDomainDef *def 
ATTRIBUTE_UNUSED,
                      virCommandPtr cmd)
 {
     const char *bus_type;
+    const char *disk_source;
 
     switch (disk->bus) {
     case VIR_DOMAIN_DISK_BUS_SATA:
-        bus_type = "ahci-hd";
+        switch (disk->device) {
+        case VIR_DOMAIN_DISK_DEVICE_DISK:
+            bus_type = "ahci-hd";
+            break;
+        case VIR_DOMAIN_DISK_DEVICE_CDROM:
+            bus_type = "ahci-cd";
+            break;
+        default:
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("unsupported disk device"));
+            return -1;
+        }
         break;
     case VIR_DOMAIN_DISK_BUS_VIRTIO:
-        bus_type = "virtio-blk";
+        if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
+            bus_type = "virtio-blk";
+        } else {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("unsupported disk device"));
+            return -1;
+        }
         break;
     default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -166,22 +184,26 @@ bhyveBuildDiskArgStr(const virDomainDef *def 
ATTRIBUTE_UNUSED,
         return -1;
     }
 
-    if (disk->device != VIR_DOMAIN_DISK_DEVICE_DISK) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("unsupported disk device"));
-        return -1;
-    }
-
     if (virDomainDiskGetType(disk) != VIR_STORAGE_TYPE_FILE) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("unsupported disk type"));
         return -1;
     }
 
+    disk_source = virDomainDiskGetSource(disk);
+
+    if ((disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
+        (disk_source == NULL)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("cdrom device without source path "
+                             "not supported"));
+            return -1;
+    }
+
     virCommandAddArg(cmd, "-s");
     virCommandAddArgFormat(cmd, "%d:0,%s,%s",
                            disk->info.addr.pci.slot, bus_type,
-                           virDomainDiskGetSource(disk));
+                           disk_source);
 
     return 0;
 }
@@ -282,7 +304,8 @@ virBhyveProcessBuildLoadCmd(bhyveConnPtr driver 
ATTRIBUTE_UNUSED,
 
     disk = def->disks[0];
 
-    if (disk->device != VIR_DOMAIN_DISK_DEVICE_DISK) {
+    if ((disk->device != VIR_DOMAIN_DISK_DEVICE_DISK) &&
+        (disk->device != VIR_DOMAIN_DISK_DEVICE_CDROM)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("unsupported disk device"));
         return NULL;
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.args 
b/tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.args
new file mode 100644
index 0000000..eb38969
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.args
@@ -0,0 +1,3 @@
+/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
+-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
+-s 2:0,ahci-cd,/tmp/cdrom.iso bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.xml 
b/tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.xml
new file mode 100644
index 0000000..d70219c
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.xml
@@ -0,0 +1,22 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory>219136</memory>
+  <vcpu>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </os>
+  <devices>
+    <disk type='file' device='cdrom'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/cdrom.iso'/>
+      <target dev='hdc' bus='sata'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' 
function='0x0'/>
+    </disk>
+    <interface type='bridge'>
+      <model type='virtio'/>
+      <source bridge="virbr0"/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' 
function='0x0'/>
+    </interface>
+  </devices>
+</domain>
diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c
index f6f2bc4..408c73a 100644
--- a/tests/bhyvexml2argvtest.c
+++ b/tests/bhyvexml2argvtest.c
@@ -104,6 +104,7 @@ mymain(void)
 
     DO_TEST("base");
     DO_TEST("acpiapic");
+    DO_TEST("disk-cdrom");
     DO_TEST("disk-virtio");
     DO_TEST("macaddr");
     DO_TEST("serial");
-- 
1.9.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to