move virHostdevReAttachUsbHostdevs to virhostdev.c

This commit is contained in:
Chunyan Liu 2014-03-06 14:37:30 +08:00 committed by Daniel P. Berrange
parent 1ba06c3adf
commit 2d961cf3ba
4 changed files with 73 additions and 66 deletions

View File

@ -1303,6 +1303,7 @@ virHostdevPreparePCIDevices;
virHostdevPrepareSCSIDevices;
virHostdevPrepareUSBDevices;
virHostdevReAttachPCIDevices;
virHostdevReAttachUsbHostdevs;
virHostdevUpdateActivePciHostdevs;
virHostdevUpdateActiveScsiHostdevs;
virHostdevUpdateActiveUsbHostdevs;

View File

@ -316,72 +316,6 @@ qemuDomainReAttachHostdevDevices(virQEMUDriverPtr driver,
virObjectUnref(cfg);
}
static void
virHostdevReAttachUsbHostdevs(virHostdevManagerPtr hostdev_mgr,
const char *drv_name,
const char *name,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs)
{
size_t i;
virObjectLock(hostdev_mgr->activeUsbHostdevs);
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
virUSBDevicePtr usb, tmp;
const char *usedby_drvname;
const char *usedby_domname;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue;
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
continue;
if (hostdev->missing)
continue;
usb = virUSBDeviceNew(hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
NULL);
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 = virUSBDeviceListFind(hostdev_mgr->activeUsbHostdevs, usb);
virUSBDeviceFree(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;
}
virUSBDeviceGetUsedBy(tmp, &usedby_drvname, &usedby_domname);
if (STREQ_NULLABLE(drv_name, usedby_drvname) &&
STREQ_NULLABLE(name, usedby_domname)) {
VIR_DEBUG("Removing %03d.%03d dom=%s from activeUsbHostdevs",
hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
name);
virUSBDeviceListDel(hostdev_mgr->activeUsbHostdevs, tmp);
}
}
virObjectUnlock(hostdev_mgr->activeUsbHostdevs);
}
void
qemuDomainReAttachHostUsbDevices(virQEMUDriverPtr driver,
const char *name,

View File

@ -1251,3 +1251,69 @@ cleanup:
virObjectUnref(list);
return -1;
}
void
virHostdevReAttachUsbHostdevs(virHostdevManagerPtr hostdev_mgr,
const char *drv_name,
const char *name,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs)
{
size_t i;
virObjectLock(hostdev_mgr->activeUsbHostdevs);
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDefPtr hostdev = hostdevs[i];
virUSBDevicePtr usb, tmp;
const char *usedby_drvname;
const char *usedby_domname;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue;
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
continue;
if (hostdev->missing)
continue;
usb = virUSBDeviceNew(hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
NULL);
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 = virUSBDeviceListFind(hostdev_mgr->activeUsbHostdevs, usb);
virUSBDeviceFree(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;
}
virUSBDeviceGetUsedBy(tmp, &usedby_drvname, &usedby_domname);
if (STREQ_NULLABLE(drv_name, usedby_drvname) &&
STREQ_NULLABLE(name, usedby_domname)) {
VIR_DEBUG("Removing %03d.%03d dom=%s from activeUsbHostdevs",
hostdev->source.subsys.u.usb.bus,
hostdev->source.subsys.u.usb.device,
name);
virUSBDeviceListDel(hostdev_mgr->activeUsbHostdevs, tmp);
}
}
virObjectUnlock(hostdev_mgr->activeUsbHostdevs);
}

View File

@ -78,6 +78,12 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr hostdev_mgr,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs,
char *oldStateDir);
void
virHostdevReAttachUsbHostdevs(virHostdevManagerPtr hostdev_mgr,
const char *drv_name,
const char *name,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs);
int
virHostdevUpdateActivePciHostdevs(virHostdevManagerPtr mgr,
const char *drv_name,