]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: new function virPCIDeviceGetVFIOGroupDev
authorLaine Stump <laine@laine.org>
Thu, 25 Apr 2013 10:34:43 +0000 (06:34 -0400)
committerLaine Stump <laine@laine.org>
Fri, 26 Apr 2013 01:28:43 +0000 (21:28 -0400)
Given a virPCIDevice, this function returns the path for the device
that controls the vfio group the device belongs to,
e.g. "/dev/vfio/15".

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

index 33ec37973d75401de49b5a5d7a356b2cdecd1629..2a2c40eb3adfc9ef27df28ad65c8cb5e66849120 100644 (file)
@@ -1609,6 +1609,7 @@ virPCIDeviceGetReprobe;
 virPCIDeviceGetStubDriver;
 virPCIDeviceGetUnbindFromStub;
 virPCIDeviceGetUsedBy;
+virPCIDeviceGetVFIOGroupDev;
 virPCIDeviceIsAssignable;
 virPCIDeviceListAdd;
 virPCIDeviceListCount;
index 805406b5646222db4a1b7afb768caac62c4884d5..97bba74a384f7cd3ffd36efcbe2e66a29a67313e 100644 (file)
@@ -1727,6 +1727,41 @@ cleanup:
     return ret;
 }
 
+/* virPCIDeviceGetVFIOGroupDev - return the name of the device used to
+ * control this PCI device's group (e.g. "/dev/vfio/15")
+ */
+char *
+virPCIDeviceGetVFIOGroupDev(virPCIDevicePtr dev)
+{
+    char *devPath = NULL;
+    char *groupPath = NULL;
+    char *groupDev = NULL;
+
+    if (virPCIFile(&devPath, dev->name, "iommu_group") < 0)
+        goto cleanup;
+    if (virFileIsLink(devPath) != 1) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Invalid device %s iommu_group file %s is not a symlink"),
+                       dev->name, devPath);
+        goto cleanup;
+    }
+    if (virFileResolveLink(devPath, &groupPath) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to resolve device %s iommu_group symlink %s"),
+                       dev->name, devPath);
+        goto cleanup;
+    }
+    if (virAsprintf(&groupDev, "/dev/vfio/%s",
+                    last_component(groupPath)) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+cleanup:
+    VIR_FREE(devPath);
+    VIR_FREE(groupPath);
+    return groupDev;
+}
+
 static int
 virPCIDeviceDownstreamLacksACS(virPCIDevicePtr dev)
 {
index db0be35990655679d33dd64f611ede0495e4022a..3911b72359a5c3ffed0e70185149f5930f0463c3 100644 (file)
@@ -111,6 +111,8 @@ typedef int (*virPCIDeviceFileActor)(virPCIDevicePtr dev,
 int virPCIDeviceFileIterate(virPCIDevicePtr dev,
                             virPCIDeviceFileActor actor,
                             void *opaque);
+char *
+virPCIDeviceGetVFIOGroupDev(virPCIDevicePtr dev);
 
 int virPCIDeviceIsAssignable(virPCIDevicePtr dev,
                              int strict_acs_check);