[PATCH v14 33/49] move virHostdevReAttachUsbHostdevs to virhostdev.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_hostdev.c  | 66 ------------------------------------------------
 src/util/virhostdev.c    | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/util/virhostdev.h    |  6 +++++
 4 files changed, 73 insertions(+), 66 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f3cd7a0..ed23337 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1298,6 +1298,7 @@ virHostdevPreparePCIDevices;
 virHostdevPrepareSCSIDevices;
 virHostdevPrepareUSBDevices;
 virHostdevReAttachPCIDevices;
+virHostdevReAttachUsbHostdevs;
 virHostdevUpdateActivePciHostdevs;
 virHostdevUpdateActiveScsiHostdevs;
 virHostdevUpdateActiveUsbHostdevs;
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index af1fe87..41cda48 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -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,
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 87b7368..e679e20 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1254,3 +1254,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);
+}
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index c149603..7bd5da1 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.9.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]