bhyve: cdrom support

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.
This commit is contained in:
Roman Bogorodskiy 2014-07-19 19:15:26 +04:00
parent dd4791c00d
commit d704e69858
4 changed files with 59 additions and 10 deletions

View File

@ -152,13 +152,31 @@ bhyveBuildDiskArgStr(const virDomainDef *def ATTRIBUTE_UNUSED,
virCommandPtr cmd) virCommandPtr cmd)
{ {
const char *bus_type; const char *bus_type;
const char *disk_source;
switch (disk->bus) { switch (disk->bus) {
case VIR_DOMAIN_DISK_BUS_SATA: case VIR_DOMAIN_DISK_BUS_SATA:
switch (disk->device) {
case VIR_DOMAIN_DISK_DEVICE_DISK:
bus_type = "ahci-hd"; bus_type = "ahci-hd";
break; 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: case VIR_DOMAIN_DISK_BUS_VIRTIO:
if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
bus_type = "virtio-blk"; bus_type = "virtio-blk";
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("unsupported disk device"));
return -1;
}
break; break;
default: default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@ -166,22 +184,26 @@ bhyveBuildDiskArgStr(const virDomainDef *def ATTRIBUTE_UNUSED,
return -1; 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) { if (virDomainDiskGetType(disk) != VIR_STORAGE_TYPE_FILE) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("unsupported disk type")); _("unsupported disk type"));
return -1; 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"); virCommandAddArg(cmd, "-s");
virCommandAddArgFormat(cmd, "%d:0,%s,%s", virCommandAddArgFormat(cmd, "%d:0,%s,%s",
disk->info.addr.pci.slot, bus_type, disk->info.addr.pci.slot, bus_type,
virDomainDiskGetSource(disk)); disk_source);
return 0; return 0;
} }
@ -282,7 +304,8 @@ virBhyveProcessBuildLoadCmd(bhyveConnPtr driver ATTRIBUTE_UNUSED,
disk = def->disks[0]; 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", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("unsupported disk device")); _("unsupported disk device"));
return NULL; return NULL;

View File

@ -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

View File

@ -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>

View File

@ -104,6 +104,7 @@ mymain(void)
DO_TEST("base"); DO_TEST("base");
DO_TEST("acpiapic"); DO_TEST("acpiapic");
DO_TEST("disk-cdrom");
DO_TEST("disk-virtio"); DO_TEST("disk-virtio");
DO_TEST("macaddr"); DO_TEST("macaddr");
DO_TEST("serial"); DO_TEST("serial");