[PATCH v4 06/10] Pass activeDevs and inactiveDevs to virPCIDeviceUnbindFromStub and virPCIDeviceBindToStub

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

 



The inactiveDevs need to be selectively altered for more than one
device in case of vfio devices. So, pass the whole list.

Signed-off-by: Shivaprasad G Bhat <sbhat@xxxxxxxxxxxxxxxxxx>
---
 src/util/virpci.c |   36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/src/util/virpci.c b/src/util/virpci.c
index febf100..a8a22d1 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -1129,7 +1129,9 @@ virPCIDeviceReprobeHostDriver(virPCIDevicePtr dev,
 }
 
 static int
-virPCIDeviceUnbindFromStub(virPCIDevicePtr dev)
+virPCIDeviceUnbindFromStub(virPCIDevicePtr dev,
+                           virPCIDeviceListPtr activeDevs ATTRIBUTE_UNUSED,
+                           virPCIDeviceListPtr inactiveDevs)
 {
     int result = -1;
     char *drvdir = NULL;
@@ -1186,6 +1188,9 @@ virPCIDeviceUnbindFromStub(virPCIDevicePtr dev)
     result = 0;
 
  cleanup:
+    if ((result == 0) && inactiveDevs)
+        virPCIDeviceListDel(inactiveDevs, dev);
+
     /* do not do it again */
     dev->unbind_from_stub = false;
     dev->remove_slot = false;
@@ -1201,7 +1206,9 @@ virPCIDeviceUnbindFromStub(virPCIDevicePtr dev)
 
 static int
 virPCIDeviceBindToStub(virPCIDevicePtr dev,
-                       const char *stubDriverName)
+                       const char *stubDriverName,
+                       virPCIDeviceListPtr activeDevs,
+                       virPCIDeviceListPtr inactiveDevs)
 {
     int result = -1;
     bool reprobe = false;
@@ -1328,9 +1335,15 @@ virPCIDeviceBindToStub(virPCIDevicePtr dev,
     VIR_FREE(driverLink);
     VIR_FREE(path);
 
+    /* Add *a copy of* the dev into list inactiveDevs, if
+     * it's not already there. */
+    if ((result == 0) && inactiveDevs && !virPCIDeviceListFind(inactiveDevs, dev) &&
+        virPCIDeviceListAddCopy(inactiveDevs, dev) < 0) {
+        result = -1;
+    }
     if (result < 0) {
         VIR_FREE(newDriverName);
-        virPCIDeviceUnbindFromStub(dev);
+        virPCIDeviceUnbindFromStub(dev, activeDevs, inactiveDevs);
     } else {
         VIR_FREE(dev->stubDriver);
         dev->stubDriver = newDriverName;
@@ -1377,16 +1390,9 @@ virPCIDeviceDetach(virPCIDevicePtr dev,
         return -1;
     }
 
-    if (virPCIDeviceBindToStub(dev, dev->stubDriver) < 0)
-        return -1;
-
-    /* Add *a copy of* the dev into list inactiveDevs, if
-     * it's not already there.
-     */
-    if (inactiveDevs && !virPCIDeviceListFind(inactiveDevs, dev) &&
-        virPCIDeviceListAddCopy(inactiveDevs, dev) < 0) {
+    if (virPCIDeviceBindToStub(dev, dev->stubDriver,
+                               activeDevs, inactiveDevs) < 0)
         return -1;
-    }
 
     return 0;
 }
@@ -1402,13 +1408,9 @@ virPCIDeviceReattach(virPCIDevicePtr dev,
         return -1;
     }
 
-    if (virPCIDeviceUnbindFromStub(dev) < 0)
+    if (virPCIDeviceUnbindFromStub(dev, activeDevs, inactiveDevs) < 0)
         return -1;
 
-    /* Steal the dev from list inactiveDevs */
-    if (inactiveDevs)
-        virPCIDeviceListDel(inactiveDevs, dev);
-
     return 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]