[PATCH v13 40/49] move virHostdevNodeDevice* 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 |    3 ++
 src/qemu/qemu_driver.c   |   81 ----------------------------------------------
 src/util/virhostdev.c    |   80 +++++++++++++++++++++++++++++++++++++++++++++
 src/util/virhostdev.h    |    8 ++++
 4 files changed, 91 insertions(+), 81 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d657982..c924854 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1293,6 +1293,9 @@ virHookPresent;
 
 #util/virhostdev.h
 virHostdevManagerGetDefault;
+virHostdevPciNodeDeviceDetach;
+virHostdevPciNodeDeviceReAttach;
+virHostdevPciNodeDeviceReset;
 virHostdevPreparePCIDevices;
 virHostdevPrepareSCSIDevices;
 virHostdevPrepareUSBDevices;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 44ac556..76e91d9 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11207,27 +11207,6 @@ out:
 }
 
 static int
-virHostdevPciNodeDeviceDetach(virHostdevManagerPtr hostdev_mgr,
-                              virPCIDevicePtr pci)
-{
-    int ret = -1;
-
-    virObjectLock(hostdev_mgr->activePciHostdevs);
-    virObjectLock(hostdev_mgr->inactivePciHostdevs);
-
-    if (virPCIDeviceDetach(pci, hostdev_mgr->activePciHostdevs,
-                           hostdev_mgr->inactivePciHostdevs) < 0) {
-        goto out;
-    }
-
-    ret = 0;
-out:
-    virObjectUnlock(hostdev_mgr->inactivePciHostdevs);
-    virObjectUnlock(hostdev_mgr->activePciHostdevs);
-    return ret;
-}
-
-static int
 qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
                           const char *driverName,
                           unsigned int flags)
@@ -11317,47 +11296,6 @@ qemuNodeDeviceDettach(virNodeDevicePtr dev)
 }
 
 static int
-virHostdevPciNodeDeviceReAttach(virHostdevManagerPtr hostdev_mgr,
-                                virPCIDevicePtr pci)
-{
-    virPCIDevicePtr other;
-    int ret = -1;
-
-    virObjectLock(hostdev_mgr->activePciHostdevs);
-    virObjectLock(hostdev_mgr->inactivePciHostdevs);
-    other = virPCIDeviceListFind(hostdev_mgr->activePciHostdevs, pci);
-    if (other) {
-        const char *other_drvname = NULL;
-        const char *other_domname = NULL;
-        virPCIDeviceGetUsedBy(other, &other_drvname, &other_domname);
-
-        if (other_drvname && other_domname)
-            virReportError(VIR_ERR_OPERATION_INVALID,
-                           _("PCI device %s is still in use by "
-                             "driver %s, domain %s"),
-                           virPCIDeviceGetName(pci),
-                           other_drvname, other_domname);
-        else
-            virReportError(VIR_ERR_OPERATION_INVALID,
-                           _("PCI device %s is still in use"),
-                           virPCIDeviceGetName(pci));
-        goto out;
-    }
-
-    virPCIDeviceReattachInit(pci);
-
-    if (virPCIDeviceReattach(pci, hostdev_mgr->activePciHostdevs,
-                             hostdev_mgr->inactivePciHostdevs) < 0)
-        goto out;
-
-    ret = 0;
-out:
-    virObjectUnlock(hostdev_mgr->inactivePciHostdevs);
-    virObjectUnlock(hostdev_mgr->activePciHostdevs);
-    return ret;
-}
-
-static int
 qemuNodeDeviceReAttach(virNodeDevicePtr dev)
 {
     virPCIDevicePtr pci = NULL;
@@ -11400,25 +11338,6 @@ cleanup:
 }
 
 static int
-virHostdevPciNodeDeviceReset(virHostdevManagerPtr hostdev_mgr,
-                             virPCIDevicePtr pci)
-{
-    int ret = -1;
-    virObjectLock(hostdev_mgr->activePciHostdevs);
-    virObjectLock(hostdev_mgr->inactivePciHostdevs);
-    if (virPCIDeviceReset(pci, hostdev_mgr->activePciHostdevs,
-                          hostdev_mgr->inactivePciHostdevs) < 0)
-        goto out;
-
-    ret = 0;
-out:
-    virObjectUnlock(hostdev_mgr->inactivePciHostdevs);
-    virObjectUnlock(hostdev_mgr->activePciHostdevs);
-    return ret;
-}
-
-
-static int
 qemuNodeDeviceReset(virNodeDevicePtr dev)
 {
     virPCIDevicePtr pci;
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 83d9916..e3b818e 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1357,3 +1357,83 @@ virHostdevReAttachScsiHostdevs(virHostdevManagerPtr hostdev_mgr,
     }
     virObjectUnlock(hostdev_mgr->activeScsiHostdevs);
 }
+
+int
+virHostdevPciNodeDeviceDetach(virHostdevManagerPtr hostdev_mgr,
+                              virPCIDevicePtr pci)
+{
+    int ret = -1;
+
+    virObjectLock(hostdev_mgr->activePciHostdevs);
+    virObjectLock(hostdev_mgr->inactivePciHostdevs);
+
+    if (virPCIDeviceDetach(pci, hostdev_mgr->activePciHostdevs,
+                           hostdev_mgr->inactivePciHostdevs) < 0) {
+        goto out;
+    }
+
+    ret = 0;
+out:
+    virObjectUnlock(hostdev_mgr->inactivePciHostdevs);
+    virObjectUnlock(hostdev_mgr->activePciHostdevs);
+    return ret;
+}
+
+int
+virHostdevPciNodeDeviceReAttach(virHostdevManagerPtr hostdev_mgr,
+                                virPCIDevicePtr pci)
+{
+    virPCIDevicePtr other;
+    int ret = -1;
+
+    virObjectLock(hostdev_mgr->activePciHostdevs);
+    virObjectLock(hostdev_mgr->inactivePciHostdevs);
+    other = virPCIDeviceListFind(hostdev_mgr->activePciHostdevs, pci);
+    if (other) {
+        const char *other_drvname = NULL;
+        const char *other_domname = NULL;
+        virPCIDeviceGetUsedBy(other, &other_drvname, &other_domname);
+
+        if (other_drvname && other_domname)
+            virReportError(VIR_ERR_OPERATION_INVALID,
+                           _("PCI device %s is still in use by "
+                             "driver %s, domain %s"),
+                           virPCIDeviceGetName(pci),
+                           other_drvname, other_domname);
+        else
+            virReportError(VIR_ERR_OPERATION_INVALID,
+                           _("PCI device %s is still in use"),
+                           virPCIDeviceGetName(pci));
+        goto out;
+    }
+
+    virPCIDeviceReattachInit(pci);
+
+    if (virPCIDeviceReattach(pci, hostdev_mgr->activePciHostdevs,
+                             hostdev_mgr->inactivePciHostdevs) < 0)
+        goto out;
+
+    ret = 0;
+out:
+    virObjectUnlock(hostdev_mgr->inactivePciHostdevs);
+    virObjectUnlock(hostdev_mgr->activePciHostdevs);
+    return ret;
+}
+
+int
+virHostdevPciNodeDeviceReset(virHostdevManagerPtr hostdev_mgr,
+                             virPCIDevicePtr pci)
+{
+    int ret = -1;
+    virObjectLock(hostdev_mgr->activePciHostdevs);
+    virObjectLock(hostdev_mgr->inactivePciHostdevs);
+    if (virPCIDeviceReset(pci, hostdev_mgr->activePciHostdevs,
+                          hostdev_mgr->inactivePciHostdevs) < 0)
+        goto out;
+
+    ret = 0;
+out:
+    virObjectUnlock(hostdev_mgr->inactivePciHostdevs);
+    virObjectUnlock(hostdev_mgr->activePciHostdevs);
+    return ret;
+}
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index 0a60ec3..bb097b0 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -103,4 +103,12 @@ virHostdevUpdateActiveScsiHostdevs(virHostdevManagerPtr mgr,
                                    const char *drv_name,
                                    virDomainDefPtr def);
 
+/* functions used by NodeDevDetach/Reattach/Reset */
+int virHostdevPciNodeDeviceDetach(virHostdevManagerPtr mgr,
+                                  virPCIDevicePtr pci);
+int virHostdevPciNodeDeviceReAttach(virHostdevManagerPtr mgr,
+                                    virPCIDevicePtr pci);
+int virHostdevPciNodeDeviceReset(virHostdevManagerPtr mgr,
+                                 virPCIDevicePtr pci);
+
 #endif /* __VIR_HOSTDEV_H__ */
-- 
1.6.0.2

--
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]