[libvirt] [PATCH v3 07/30] virHostdevReAttachPCIDevices: Separate out function body

Michal Privoznik posted 30 patches 42 weeks ago

[libvirt] [PATCH v3 07/30] virHostdevReAttachPCIDevices: Separate out function body

Posted by Michal Privoznik 42 weeks ago
In near future we will have a list of PCI devices we want to
re-attach to the host (held in virPCIDeviceListPtr) but we don't
have virDomainHostdevDefPtr. That's okay because
virHostdevReAttachPCIDevices() 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@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
---
 src/util/virhostdev.c | 58 +++++++++++++++++++++++++++----------------
 1 file changed, 37 insertions(+), 21 deletions(-)

diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index b8e6e2bc36..94a0185597 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1002,30 +1002,17 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr,
 }
 
 
-/* @oldStateDir:
- * For upgrade purpose: see virHostdevRestoreNetConfig
- */
-void
-virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr,
-                             const char *drv_name,
-                             const char *dom_name,
-                             virDomainHostdevDefPtr *hostdevs,
-                             int nhostdevs,
-                             const char *oldStateDir)
+static void
+virHostdevReAttachPCIDevicesImpl(virHostdevManagerPtr mgr,
+                                 const char *drv_name,
+                                 const char *dom_name,
+                                 virPCIDeviceListPtr pcidevs,
+                                 virDomainHostdevDefPtr *hostdevs,
+                                 int nhostdevs,
+                                 const char *oldStateDir)
 {
-    g_autoptr(virPCIDeviceList) pcidevs = NULL;
     size_t i;
 
-    if (!nhostdevs)
-        return;
-
-    if (!(pcidevs = virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))) {
-        VIR_ERROR(_("Failed to allocate PCI device list: %s"),
-                  virGetLastErrorMessage());
-        virResetLastError();
-        return;
-    }
-
     virObjectLock(mgr->activePCIHostdevs);
     virObjectLock(mgr->inactivePCIHostdevs);
 
@@ -1121,6 +1108,35 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr,
     virObjectUnlock(mgr->inactivePCIHostdevs);
 }
 
+
+/* @oldStateDir:
+ * For upgrade purpose: see virHostdevRestoreNetConfig
+ */
+void
+virHostdevReAttachPCIDevices(virHostdevManagerPtr mgr,
+                             const char *drv_name,
+                             const char *dom_name,
+                             virDomainHostdevDefPtr *hostdevs,
+                             int nhostdevs,
+                             const char *oldStateDir)
+{
+    g_autoptr(virPCIDeviceList) pcidevs = NULL;
+
+    if (!nhostdevs)
+        return;
+
+    if (!(pcidevs = virHostdevGetPCIHostDeviceList(hostdevs, nhostdevs))) {
+        VIR_ERROR(_("Failed to allocate PCI device list: %s"),
+                  virGetLastErrorMessage());
+        virResetLastError();
+        return;
+    }
+
+    virHostdevReAttachPCIDevicesImpl(mgr, drv_name, dom_name, pcidevs,
+                                     hostdevs, nhostdevs, oldStateDir);
+}
+
+
 int
 virHostdevUpdateActivePCIDevices(virHostdevManagerPtr mgr,
                                  virDomainHostdevDefPtr *hostdevs,
-- 
2.23.0

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

Re: [libvirt] [PATCH v3 07/30] virHostdevReAttachPCIDevices: Separate out function body

Posted by Cole Robinson 41 weeks ago
On 12/2/19 9:26 AM, Michal Privoznik wrote:
> In near future we will have a list of PCI devices we want to
> re-attach to the host (held in virPCIDeviceListPtr) but we don't
> have virDomainHostdevDefPtr. That's okay because
> virHostdevReAttachPCIDevices() 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@redhat.com>
> ACKed-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  src/util/virhostdev.c | 58 +++++++++++++++++++++++++++----------------
>  1 file changed, 37 insertions(+), 21 deletions(-)

Reviewed-by: Cole Robinson <crobinso@redhat.com>

- Cole

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