#include "device_conf.h"
#include "virstoragefile.h"
#include "virtpm.h"
+#include "virscsi.h"
#if defined(__linux__)
# include <linux/capability.h>
#endif
}
}
- if (virAsprintf(&hostdev->info->alias, "hostdev%d", idx) < 0) {
+ if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
+ if (virAsprintf(&hostdev->info->alias, "hostdev-%s-%d-%d-%d",
+ hostdev->source.subsys.u.scsi.adapter,
+ hostdev->source.subsys.u.scsi.bus,
+ hostdev->source.subsys.u.scsi.target,
+ hostdev->source.subsys.u.scsi.unit) < 0) {
+ virReportOOMError();
+ return -1;
+ }
+ } else if (virAsprintf(&hostdev->info->alias, "hostdev%d", idx) < 0) {
virReportOOMError();
return -1;
}
return ret;
}
+char *
+qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev,
+ virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSED)
+{
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+ char *sg = NULL;
+
+ if (!(sg = virSCSIDeviceGetSgName(dev->source.subsys.u.scsi.adapter,
+ dev->source.subsys.u.scsi.bus,
+ dev->source.subsys.u.scsi.target,
+ dev->source.subsys.u.scsi.unit))) {
+ goto error;
+ }
+
+ virBufferAsprintf(&buf, "file=/dev/%s,if=none", sg);
+ virBufferAsprintf(&buf, ",id=%s-%s",
+ virDomainDeviceAddressTypeToString(dev->info->type),
+ dev->info->alias);
+
+ if (virBufferError(&buf)) {
+ virReportOOMError();
+ goto error;
+ }
+
+ VIR_FREE(sg);
+ return virBufferContentAndReset(&buf);
+error:
+ VIR_FREE(sg);
+ virBufferFreeAndReset(&buf);
+ return NULL;
+}
+
+char *
+qemuBuildSCSIHostdevDevStr(virDomainDefPtr def,
+ virDomainHostdevDefPtr dev,
+ virQEMUCapsPtr qemuCaps)
+{
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+ int model = -1;
+
+ model = virDomainDeviceFindControllerModel(def, dev->info,
+ VIR_DOMAIN_CONTROLLER_TYPE_SCSI);
+
+ if (qemuSetScsiControllerModel(def, qemuCaps, &model) < 0)
+ goto error;
+
+ if (model == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
+ if (dev->info->addr.drive.target != 0) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("target must be 0 for scsi host device "
+ "if its controller model is 'lsilogic'"));
+ goto error;
+ }
+
+ if (dev->info->addr.drive.unit > 7) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("unit must be not more than 7 for scsi host "
+ "device if its controller model is 'lsilogic'"));
+ goto error;
+ }
+ }
+
+ virBufferAddLit(&buf, "scsi-generic");
+
+ if (model == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
+ virBufferAsprintf(&buf, ",bus=scsi%d.%d,scsi-id=%d",
+ dev->info->addr.drive.controller,
+ dev->info->addr.drive.bus,
+ dev->info->addr.drive.unit);
+ } else {
+ virBufferAsprintf(&buf, ",bus=scsi%d.0,channel=%d,scsi-id=%d,lun=%d",
+ dev->info->addr.drive.controller,
+ dev->info->addr.drive.bus,
+ dev->info->addr.drive.target,
+ dev->info->addr.drive.unit);
+ }
+ virBufferAsprintf(&buf, ",drive=%s-%s,id=%s",
+ virDomainDeviceAddressTypeToString(dev->info->type),
+ dev->info->alias, dev->info->alias);
+
+ if (virBufferError(&buf)) {
+ virReportOOMError();
+ goto error;
+ }
+
+ return virBufferContentAndReset(&buf);
+error:
+ virBufferFreeAndReset(&buf);
+ return NULL;
+}
/* This function outputs a -chardev command line option which describes only the
* host side of the character device */
if (hostdev->info->bootIndex) {
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
(hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
- hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)) {
+ hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB &&
+ hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("booting from assigned devices is only "
- "supported for PCI and USB devices"));
+ "supported for PCI, USB and SCSI devices"));
goto error;
} else {
if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) {
goto error;
}
}
+
+ /* SCSI */
+ if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+ hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
+ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE) &&
+ virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE) &&
+ virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_SCSI_GENERIC)) {
+ char *drvstr;
+
+ virCommandAddArg(cmd, "-drive");
+ if (!(drvstr = qemuBuildSCSIHostdevDrvStr(hostdev, qemuCaps)))
+ goto error;
+ virCommandAddArg(cmd, drvstr);
+ VIR_FREE(drvstr);
+
+ virCommandAddArg(cmd, "-device");
+ if (!(devstr = qemuBuildSCSIHostdevDevStr(def, hostdev, qemuCaps)))
+ goto error;
+ virCommandAddArg(cmd, devstr);
+ VIR_FREE(devstr);
+ } else {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("SCSI passthrough is not supported by this version of qemu"));
+ goto error;
+ }
+ }
}
/* Migration is very annoying due to wildly varying syntax &
--- /dev/null
+<domain type='qemu'>
+ <name>QEMUGuest2</name>
+ <uuid>c7a5fdbd-edaf-9466-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219100</memory>
+ <currentMemory unit='KiB'>219100</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu</emulator>
+ <disk type='block' device='disk'>
+ <source dev='/dev/HostVG/QEMUGuest2'/>
+ <target dev='hda' bus='ide'/>
+ <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+ </disk>
+ <controller type='scsi' index='0'/>
+ <controller type='usb' index='0'/>
+ <controller type='ide' index='0'/>
+ <controller type='pci' index='0' model='pci-root'/>
+ <hostdev mode='subsystem' type='scsi' managed='yes'>
+ <source>
+ <adapter name='scsi_host0'/>
+ <address bus='0' target='0' unit='0'/>
+ </source>
+ <address type='drive' controller='0' bus='0' target='0' unit='7'/>
+ </hostdev>
+ <memballoon model='virtio'/>
+ </devices>
+</domain>