]> xenbits.xensource.com Git - libvirt.git/commitdiff
bhyve: cdrom support
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Sat, 19 Jul 2014 15:15:26 +0000 (19:15 +0400)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Thu, 24 Jul 2014 14:56:37 +0000 (18:56 +0400)
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
tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.args [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.xml [new file with mode: 0644]
tests/bhyvexml2argvtest.c

index 7f22b1ce7a233b5357db16b0854a51f71af55023..e2940e8c024958ea39a3684b23c2a2982f880546 100644 (file)
@@ -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 (file)
index 0000000..eb38969
--- /dev/null
@@ -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 (file)
index 0000000..d70219c
--- /dev/null
@@ -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>
index f6f2bc4c6caf726fcefe9a616b0763ed89d9bc6b..408c73aa0bd76a1894be5c7218a9a0ef4b78b2f5 100644 (file)
@@ -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");