[libvirt] [PATCH v1 01/31] virHostdevPreparePCIDevices: Separate out function body

Michal Privoznik mprivozn at redhat.com
Thu Jul 11 15:53:48 UTC 2019


In near future we will have a list of PCI devices we want to
detach (held in virPCIDeviceListPtr) but we don't have
virDomainHostdevDefPtr. That's okay because
virHostdevPreparePCIDevices() works with virPCIDeviceListPtr
mostly anyway. And in very few places where it needs
virDomainHostdevDefPtr are not interesting for our case.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/util/virhostdev.c | 48 ++++++++++++++++++++++++++++---------------
 1 file changed, 32 insertions(+), 16 deletions(-)

diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index a3647a6cf4..88b0828675 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -613,27 +613,22 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hostdev,
     }
 }
 
-int
-virHostdevPreparePCIDevices(virHostdevManagerPtr mgr,
-                            const char *drv_name,
-                            const char *dom_name,
-                            const unsigned char *uuid,
-                            virDomainHostdevDefPtr *hostdevs,
-                            int nhostdevs,
-                            unsigned int flags)
+
+static int
+virHostdevPreparePCIDevicesImpl(virHostdevManagerPtr mgr,
+                                const char *drv_name,
+                                const char *dom_name,
+                                const unsigned char *uuid,
+                                virPCIDeviceListPtr pcidevs,
+                                virDomainHostdevDefPtr *hostdevs,
+                                int nhostdevs,
+                                unsigned int flags)
 {
-    VIR_AUTOUNREF(virPCIDeviceListPtr) pcidevs = NULL;
     int last_processed_hostdev_vf = -1;
     size_t i;
     int ret = -1;
     virPCIDeviceAddressPtr devAddr = NULL;
 
-    if (!nhostdevs)
-        return 0;
-
-    if (!(pcidevs = virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs)))
-        return -1;
-
     virObjectLock(mgr->activePCIHostdevs);
     virObjectLock(mgr->inactivePCIHostdevs);
 
@@ -906,10 +901,31 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr,
  cleanup:
     virObjectUnlock(mgr->activePCIHostdevs);
     virObjectUnlock(mgr->inactivePCIHostdevs);
-
     return ret;
 }
 
+
+int
+virHostdevPreparePCIDevices(virHostdevManagerPtr mgr,
+                            const char *drv_name,
+                            const char *dom_name,
+                            const unsigned char *uuid,
+                            virDomainHostdevDefPtr *hostdevs,
+                            int nhostdevs,
+                            unsigned int flags)
+{
+    VIR_AUTOUNREF(virPCIDeviceListPtr) pcidevs = NULL;
+
+    if (!nhostdevs)
+        return 0;
+
+    if (!(pcidevs = virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs)))
+        return -1;
+
+    return virHostdevPreparePCIDevicesImpl(mgr, drv_name, dom_name, uuid,
+                                           pcidevs, hostdevs, nhostdevs, flags);
+}
+
 /*
  * Pre-condition: inactivePCIHostdevs & activePCIHostdevs
  * are locked
-- 
2.21.0




More information about the libvir-list mailing list