Signed-off-by: Chunyan Liu <cyliu(a)suse.com>
---
src/libvirt_private.syms | 1 +
src/qemu/qemu_hostdev.c | 65 ----------------------------------------------
src/util/virhostdev.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++
src/util/virhostdev.h | 6 ++++
4 files changed, 72 insertions(+), 65 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index fd92467..7da32a0 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1297,6 +1297,7 @@ virHostdevPreparePCIDevices;
virHostdevPrepareSCSIDevices;
virHostdevPrepareUSBDevices;
virHostdevReAttachPCIDevices;
+virHostdevReAttachUsbHostdevs;
virHostdevUpdateActivePciHostdevs;
virHostdevUpdateActiveScsiHostdevs;
virHostdevUpdateActiveUsbHostdevs;
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 2c92c2b..6e65a02 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -342,71 +342,6 @@ out:
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 ATTRIBUTE_UNUSED,
const char *name,
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 5d1bb64..03962d3 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1230,3 +1230,68 @@ cleanup:
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);
+}
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index fc36ead..a07ba27 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -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,
--
1.6.0.2