]> xenbits.xensource.com Git - libvirt.git/commitdiff
pci: Publish some internal code for virpcitest
authorJiri Denemark <jdenemar@redhat.com>
Thu, 16 Jan 2014 11:27:23 +0000 (12:27 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Mon, 20 Jan 2014 12:58:04 +0000 (13:58 +0100)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
src/libvirt_private.syms
src/util/virpci.c
src/util/virpci.h

index 3ede3d5ebca142a97914a7fb596cbfcd2d649ff6..92c7aecf72a58385902b4802738042156bd9ce72 100644 (file)
@@ -1585,6 +1585,7 @@ virPCIDeviceCopy;
 virPCIDeviceDetach;
 virPCIDeviceFileIterate;
 virPCIDeviceFree;
+virPCIDeviceGetDriverPathAndName;
 virPCIDeviceGetIOMMUGroupDev;
 virPCIDeviceGetIOMMUGroupList;
 virPCIDeviceGetManaged;
@@ -1616,6 +1617,7 @@ virPCIDeviceSetReprobe;
 virPCIDeviceSetStubDriver;
 virPCIDeviceSetUnbindFromStub;
 virPCIDeviceSetUsedBy;
+virPCIDeviceUnbind;
 virPCIDeviceWaitForCleanup;
 virPCIGetNetName;
 virPCIGetPhysicalFunction;
index f6ab794a3b44939c783a3079c3499da181b27a3a..e2d222e52b6adca2ce5f79b19f9eb787197808ed 100644 (file)
@@ -225,7 +225,7 @@ virPCIFile(char **buffer, const char *device, const char *file)
  *
  * Return 0 for success, -1 for error.
  */
-static int
+int
 virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev, char **path, char **name)
 {
     int ret = -1;
@@ -1005,6 +1005,44 @@ recheck:
     return -1;
 }
 
+int
+virPCIDeviceUnbind(virPCIDevicePtr dev, bool reprobe)
+{
+    char *path = NULL;
+    char *drvpath = NULL;
+    char *driver = NULL;
+    int ret = -1;
+
+    if (virPCIDeviceGetDriverPathAndName(dev, &drvpath, &driver) < 0)
+        goto cleanup;
+
+    if (!driver) {
+        /* The device is not bound to any driver */
+        ret = 0;
+        goto cleanup;
+    }
+
+    if (virPCIFile(&path, dev->name, "driver/unbind") < 0)
+        goto cleanup;
+
+    if (virFileExists(path)) {
+        if (virFileWriteStr(path, dev->name, 0) < 0) {
+            virReportSystemError(errno,
+                                 _("Failed to unbind PCI device '%s' from %s"),
+                                 dev->name, driver);
+            goto cleanup;
+        }
+        dev->reprobe = reprobe;
+    }
+
+    ret = 0;
+cleanup:
+    VIR_FREE(path);
+    VIR_FREE(drvpath);
+    VIR_FREE(driver);
+    return ret;
+}
+
 static const char *virPCIKnownStubs[] = {
     "pciback",  /* used by xen */
     "pci-stub", /* used by kvm legacy passthrough */
@@ -1047,18 +1085,8 @@ virPCIDeviceUnbindFromStub(virPCIDevicePtr dev)
     if (!isStub)
         goto remove_slot;
 
-    if (virFileExists(drvdir)) {
-        if (virPCIDriverFile(&path, driver, "unbind") < 0) {
-            goto cleanup;
-        }
-
-        if (virFileWriteStr(path, dev->name, 0) < 0) {
-            virReportSystemError(errno,
-                                 _("Failed to unbind PCI device '%s' from %s"),
-                                 dev->name, driver);
-            goto cleanup;
-        }
-    }
+    if (virPCIDeviceUnbind(dev, dev->reprobe) < 0)
+        goto cleanup;
     dev->unbind_from_stub = false;
 
 remove_slot:
@@ -1174,24 +1202,9 @@ virPCIDeviceBindToStub(virPCIDevicePtr dev,
         goto remove_id;
     }
 
-    /* If the device is already bound to a driver, unbind it.
-     * Note, this will have rather unpleasant side effects if this
-     * PCI device happens to be IDE controller for the disk hosting
-     * your root filesystem.
-     */
-    if (virPCIFile(&path, dev->name, "driver/unbind") < 0)
+    if (virPCIDeviceUnbind(dev, reprobe) < 0)
         goto remove_id;
 
-    if (virFileExists(path)) {
-        if (virFileWriteStr(path, dev->name, 0) < 0) {
-            virReportSystemError(errno,
-                                 _("Failed to unbind PCI device '%s'"),
-                                 dev->name);
-            goto remove_id;
-        }
-        dev->reprobe = reprobe;
-    }
-
     /* If the device isn't already bound to pci-stub, try binding it now.
      */
     if (!virFileLinkPointsTo(driverLink, stubDriverPath)) {
index 08bf4c37dd8e5c0ca253dcd5056292a49ba056b9..42c3c957e2376193ef628c1931a91a078e58baf6 100644 (file)
@@ -167,4 +167,9 @@ int virPCIDeviceAddressParse(char *address, virPCIDeviceAddressPtr bdf);
 int virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
                                  char **pfname, int *vf_index);
 
+int virPCIDeviceUnbind(virPCIDevicePtr dev, bool reprobe);
+int virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev,
+                                     char **path,
+                                     char **name);
+
 #endif /* __VIR_PCI_H__ */