[libvirt] [PATCH 1/8] util: new function virPCIDeviceGetVFIOGroupDev

2013-04-25 Thread Laine Stump
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 |  1 +
 src/util/virpci.c| 34 ++
 src/util/virpci.h|  2 ++
 3 files changed, 37 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 33ec379..2a2c40e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1609,6 +1609,7 @@ virPCIDeviceGetReprobe;
 virPCIDeviceGetStubDriver;
 virPCIDeviceGetUnbindFromStub;
 virPCIDeviceGetUsedBy;
+virPCIDeviceGetVFIOGroupDev;
 virPCIDeviceIsAssignable;
 virPCIDeviceListAdd;
 virPCIDeviceListCount;
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 73f36d0..673568f 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -1726,6 +1726,40 @@ 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, basename(groupPath))  0) {
+virReportOOMError();
+goto cleanup;
+}
+cleanup:
+VIR_FREE(devPath);
+VIR_FREE(groupPath);
+return groupDev;
+}
+
 static int
 virPCIDeviceDownstreamLacksACS(virPCIDevicePtr dev)
 {
diff --git a/src/util/virpci.h b/src/util/virpci.h
index db0be35..3911b72 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -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);
-- 
1.7.11.7

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


Re: [libvirt] [PATCH 1/8] util: new function virPCIDeviceGetVFIOGroupDev

2013-04-25 Thread Eric Blake
On 04/25/2013 11:57 AM, Laine Stump wrote:
 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.
 ---

 +if (virAsprintf(groupDev, /dev/vfio/%s, basename(groupPath))  0) {

We shouldn't be using basename() from libgen.h - it has horrible
portability problems, and is not thread-safe.  Instead, use
last_component() from gnulib's dirname.h.  [I really ought to add a
syntax-check to cfg.mk and clean up the existing offenders].

ACK with that fixed.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 1/8] util: new function virPCIDeviceGetVFIOGroupDev

2013-04-25 Thread Laine Stump
On 04/25/2013 04:06 PM, Eric Blake wrote:
 On 04/25/2013 11:57 AM, Laine Stump wrote:
 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.
 ---
 +if (virAsprintf(groupDev, /dev/vfio/%s, basename(groupPath))  0) {
 We shouldn't be using basename() from libgen.h - it has horrible
 portability problems, and is not thread-safe.  Instead, use
 last_component() from gnulib's dirname.h.  [I really ought to add a
 syntax-check to cfg.mk and clean up the existing offenders].

 ACK with that fixed.


Okay. I fixed that. I'm going to send one message for each of the three
series when I push them.

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