]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: new function virPCIDeviceRebind()
authorLaine Stump <laine@laine.org>
Tue, 7 Mar 2017 17:58:15 +0000 (12:58 -0500)
committerLaine Stump <laine@laine.org>
Fri, 24 Mar 2017 04:38:21 +0000 (00:38 -0400)
This function unbinds a device from its driver, then immediately
rebinds it to its driver again. The code for this new function is just
the 2nd half of virPCIDeviceBindWithDriverOverride(), so that
function's 2nd half is replaced with a call to virPCIDeviceRebind().

src/libvirt_private.syms
src/util/virpci.c
src/util/virpci.h

index d0f4e98dd7f410af6b5fac03063f03b9d2f8b532..77f03d966775745c87a7f2b556ae885df2e48a8f 100644 (file)
@@ -2233,6 +2233,7 @@ virPCIDeviceListSteal;
 virPCIDeviceListStealIndex;
 virPCIDeviceNew;
 virPCIDeviceReattach;
+virPCIDeviceRebind;
 virPCIDeviceReset;
 virPCIDeviceSetManaged;
 virPCIDeviceSetRemoveSlot;
index 9878398100fcb61b013da307e474003e5b3ffc0f..546aeb550e420ab1c8b93b4ea6ac9948465aba5c 100644 (file)
@@ -1101,6 +1101,31 @@ virPCIDeviceUnbind(virPCIDevicePtr dev)
     return ret;
 }
 
+
+/**
+ * virPCIDeviceRebind:
+ *  @dev: virPCIDevice object describing the device to rebind
+ *
+ * unbind a device from its driver, then immediately rebind it.
+ *
+ * Returns 0 on success, -1 on failure
+ */
+int virPCIDeviceRebind(virPCIDevicePtr dev)
+{
+    if (virPCIDeviceUnbind(dev) < 0)
+        return -1;
+
+    if (virFileWriteStr(PCI_SYSFS "drivers_probe", dev->name, 0) < 0) {
+        virReportSystemError(errno,
+                             _("Failed to trigger a probe for PCI device '%s'"),
+                             dev->name);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 /*
  * Bind a PCI device to a driver using driver_override sysfs interface.
  * E.g.
@@ -1130,15 +1155,8 @@ virPCIDeviceBindWithDriverOverride(virPCIDevicePtr dev,
         goto cleanup;
     }
 
-    if (virPCIDeviceUnbind(dev) < 0)
-        goto cleanup;
-
-    if (virFileWriteStr(PCI_SYSFS "drivers_probe", dev->name, 0) < 0) {
-        virReportSystemError(errno,
-                             _("Failed to trigger a probe for PCI device '%s'"),
-                             dev->name);
+    if (virPCIDeviceRebind(dev) < 0)
         goto cleanup;
-    }
 
     ret = 0;
 
index 4be9cc0fb125a2f870e53e307fcda4108f77c949..8637c2c68513e4a06f367da0667d95e2495ddbed 100644 (file)
@@ -225,6 +225,7 @@ int virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
                                  char **pfname, int *vf_index);
 
 int virPCIDeviceUnbind(virPCIDevicePtr dev);
+int virPCIDeviceRebind(virPCIDevicePtr dev);
 int virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev,
                                      char **path,
                                      char **name);