mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-06 13:05:20 +00:00
qemu: Delete USB devices used by domain on stop
To prevent assigning one USB device to two domains,
we keep a list of assigned USB devices. On domain
startup - qemuProcessStart() - we insert devices
used by domain into the list but remove them only
on detach-device. Devices are, however, released
on qemuProcessStop() as well.
(cherry picked from commit e2f5dd6134
)
This commit is contained in:
parent
779ac7ab69
commit
8fca254f5d
@ -755,6 +755,63 @@ void qemuDomainReAttachHostdevDevices(struct qemud_driver *driver,
|
||||
pciDeviceListFree(pcidevs);
|
||||
}
|
||||
|
||||
static void
|
||||
qemuDomainReAttachHostUsbDevices(struct qemud_driver *driver,
|
||||
const char *name,
|
||||
virDomainHostdevDefPtr *hostdevs,
|
||||
int nhostdevs)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nhostdevs; i++) {
|
||||
virDomainHostdevDefPtr hostdev = hostdevs[i];
|
||||
usbDevice *usb, *tmp;
|
||||
const char *used_by = NULL;
|
||||
|
||||
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
|
||||
continue;
|
||||
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
|
||||
continue;
|
||||
|
||||
usb = usbGetDevice(hostdev->source.subsys.u.usb.bus,
|
||||
hostdev->source.subsys.u.usb.device);
|
||||
|
||||
if (!usb) {
|
||||
VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s",
|
||||
hostdev->source.subsys.u.usb.bus,
|
||||
hostdev->source.subsys.u.usb.device,
|
||||
name);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Delete only those USB devices which belongs
|
||||
* to domain @name because qemuProcessStart() might
|
||||
* have failed because USB device is already taken.
|
||||
* Therefore we want to steal only those devices from
|
||||
* the list which were taken by @name */
|
||||
|
||||
tmp = usbDeviceListFind(driver->activeUsbHostdevs, usb);
|
||||
usbFreeDevice(usb);
|
||||
|
||||
if (!tmp) {
|
||||
VIR_WARN("Unable to find device %03d.%03d "
|
||||
"in list of active USB devices",
|
||||
hostdev->source.subsys.u.usb.bus,
|
||||
hostdev->source.subsys.u.usb.device);
|
||||
continue;
|
||||
}
|
||||
|
||||
used_by = usbDeviceGetUsedBy(tmp);
|
||||
if (STREQ_NULLABLE(used_by, name)) {
|
||||
VIR_DEBUG("Removing %03d.%03d dom=%s from activeUsbHostdevs",
|
||||
hostdev->source.subsys.u.usb.bus,
|
||||
hostdev->source.subsys.u.usb.device,
|
||||
name);
|
||||
|
||||
usbDeviceListDel(driver->activeUsbHostdevs, tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void qemuDomainReAttachHostDevices(struct qemud_driver *driver,
|
||||
virDomainDefPtr def)
|
||||
@ -764,4 +821,7 @@ void qemuDomainReAttachHostDevices(struct qemud_driver *driver,
|
||||
|
||||
qemuDomainReAttachHostdevDevices(driver, def->name, def->hostdevs,
|
||||
def->nhostdevs);
|
||||
|
||||
qemuDomainReAttachHostUsbDevices(driver, def->name, def->hostdevs,
|
||||
def->nhostdevs);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user