mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
qemu: Implement startupPolicy for USB passed through devices
This commit is contained in:
parent
059aff6b98
commit
edc9269a2a
@ -289,6 +289,8 @@ int qemuSetupCgroup(struct qemud_driver *driver,
|
|||||||
continue;
|
continue;
|
||||||
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
|
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
|
||||||
continue;
|
continue;
|
||||||
|
if (hostdev->missing)
|
||||||
|
continue;
|
||||||
|
|
||||||
if ((usb = usbGetDevice(hostdev->source.subsys.u.usb.bus,
|
if ((usb = usbGetDevice(hostdev->source.subsys.u.usb.bus,
|
||||||
hostdev->source.subsys.u.usb.device)) == NULL)
|
hostdev->source.subsys.u.usb.device)) == NULL)
|
||||||
|
@ -3507,17 +3507,21 @@ qemuBuildUSBHostdevDevStr(virDomainHostdevDefPtr dev,
|
|||||||
{
|
{
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
|
|
||||||
if (!dev->source.subsys.u.usb.bus &&
|
if (!dev->missing &&
|
||||||
|
!dev->source.subsys.u.usb.bus &&
|
||||||
!dev->source.subsys.u.usb.device) {
|
!dev->source.subsys.u.usb.device) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("USB host device is missing bus/device information"));
|
_("USB host device is missing bus/device information"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
virBufferAsprintf(&buf, "usb-host,hostbus=%d,hostaddr=%d,id=%s",
|
virBufferAddLit(&buf, "usb-host");
|
||||||
dev->source.subsys.u.usb.bus,
|
if (!dev->missing) {
|
||||||
dev->source.subsys.u.usb.device,
|
virBufferAsprintf(&buf, ",hostbus=%d,hostaddr=%d",
|
||||||
dev->info->alias);
|
dev->source.subsys.u.usb.bus,
|
||||||
|
dev->source.subsys.u.usb.device);
|
||||||
|
}
|
||||||
|
virBufferAsprintf(&buf, ",id=%s", dev->info->alias);
|
||||||
|
|
||||||
if (qemuBuildDeviceAddressStr(&buf, dev->info, caps) < 0)
|
if (qemuBuildDeviceAddressStr(&buf, dev->info, caps) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -3577,6 +3581,12 @@ qemuBuildUSBHostdevUsbDevStr(virDomainHostdevDefPtr dev)
|
|||||||
{
|
{
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
|
|
||||||
|
if (dev->missing) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
|
_("This QEMU doesn't not support missing USB devices"));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!dev->source.subsys.u.usb.bus &&
|
if (!dev->source.subsys.u.usb.bus &&
|
||||||
!dev->source.subsys.u.usb.device) {
|
!dev->source.subsys.u.usb.device) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
@ -696,7 +696,8 @@ out:
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
qemuPrepareHostUSBDevices(struct qemud_driver *driver,
|
qemuPrepareHostUSBDevices(struct qemud_driver *driver,
|
||||||
virDomainDefPtr def)
|
virDomainDefPtr def,
|
||||||
|
bool coldBoot)
|
||||||
{
|
{
|
||||||
int i, ret = -1;
|
int i, ret = -1;
|
||||||
usbDeviceList *list;
|
usbDeviceList *list;
|
||||||
@ -716,6 +717,7 @@ qemuPrepareHostUSBDevices(struct qemud_driver *driver,
|
|||||||
*/
|
*/
|
||||||
for (i = 0 ; i < nhostdevs ; i++) {
|
for (i = 0 ; i < nhostdevs ; i++) {
|
||||||
virDomainHostdevDefPtr hostdev = hostdevs[i];
|
virDomainHostdevDefPtr hostdev = hostdevs[i];
|
||||||
|
bool required = true;
|
||||||
usbDevice *usb;
|
usbDevice *usb;
|
||||||
|
|
||||||
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
|
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
|
||||||
@ -723,10 +725,15 @@ qemuPrepareHostUSBDevices(struct qemud_driver *driver,
|
|||||||
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
|
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (qemuFindHostdevUSBDevice(hostdev, true, &usb) < 0)
|
if (hostdev->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_OPTIONAL ||
|
||||||
|
(hostdev->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_REQUISITE &&
|
||||||
|
!coldBoot))
|
||||||
|
required = false;
|
||||||
|
|
||||||
|
if (qemuFindHostdevUSBDevice(hostdev, required, &usb) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (usbDeviceListAdd(list, usb) < 0) {
|
if (usb && usbDeviceListAdd(list, usb) < 0) {
|
||||||
usbFreeDevice(usb);
|
usbFreeDevice(usb);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -756,7 +763,8 @@ cleanup:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int qemuPrepareHostDevices(struct qemud_driver *driver,
|
int qemuPrepareHostDevices(struct qemud_driver *driver,
|
||||||
virDomainDefPtr def)
|
virDomainDefPtr def,
|
||||||
|
bool coldBoot)
|
||||||
{
|
{
|
||||||
if (!def->nhostdevs)
|
if (!def->nhostdevs)
|
||||||
return 0;
|
return 0;
|
||||||
@ -764,7 +772,7 @@ int qemuPrepareHostDevices(struct qemud_driver *driver,
|
|||||||
if (qemuPrepareHostPCIDevices(driver, def) < 0)
|
if (qemuPrepareHostPCIDevices(driver, def) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (qemuPrepareHostUSBDevices(driver, def) < 0)
|
if (qemuPrepareHostUSBDevices(driver, def, coldBoot) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -891,6 +899,8 @@ qemuDomainReAttachHostUsbDevices(struct qemud_driver *driver,
|
|||||||
continue;
|
continue;
|
||||||
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
|
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
|
||||||
continue;
|
continue;
|
||||||
|
if (hostdev->missing)
|
||||||
|
continue;
|
||||||
|
|
||||||
usb = usbGetDevice(hostdev->source.subsys.u.usb.bus,
|
usb = usbGetDevice(hostdev->source.subsys.u.usb.bus,
|
||||||
hostdev->source.subsys.u.usb.device);
|
hostdev->source.subsys.u.usb.device);
|
||||||
|
@ -43,7 +43,8 @@ int qemuPrepareHostdevUSBDevices(struct qemud_driver *driver,
|
|||||||
const char *name,
|
const char *name,
|
||||||
usbDeviceList *list);
|
usbDeviceList *list);
|
||||||
int qemuPrepareHostDevices(struct qemud_driver *driver,
|
int qemuPrepareHostDevices(struct qemud_driver *driver,
|
||||||
virDomainDefPtr def);
|
virDomainDefPtr def,
|
||||||
|
bool coldBoot);
|
||||||
void qemuReattachPciDevice(pciDevice *dev, struct qemud_driver *driver);
|
void qemuReattachPciDevice(pciDevice *dev, struct qemud_driver *driver);
|
||||||
void qemuDomainReAttachHostdevDevices(struct qemud_driver *driver,
|
void qemuDomainReAttachHostdevDevices(struct qemud_driver *driver,
|
||||||
const char *name,
|
const char *name,
|
||||||
|
@ -3384,7 +3384,7 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
|
|
||||||
/* Must be run before security labelling */
|
/* Must be run before security labelling */
|
||||||
VIR_DEBUG("Preparing host devices");
|
VIR_DEBUG("Preparing host devices");
|
||||||
if (qemuPrepareHostDevices(driver, vm->def) < 0)
|
if (qemuPrepareHostDevices(driver, vm->def, !migrateFrom) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_DEBUG("Preparing chr devices");
|
VIR_DEBUG("Preparing chr devices");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user