[libvirt] [PATCH v3 05/30] virpci: Introduce and use virPCIDeviceAddressGetIOMMUGroupDev

Michal Privoznik mprivozn at redhat.com
Mon Dec 2 14:26:28 UTC 2019


Sometimes, we have a PCI address and not fully allocated
virPCIDevice and yet we still want to know its /dev/vfio/N path.
Introduce virPCIDeviceAddressGetIOMMUGroupDev() function exactly
for that.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_domain.c   | 11 +----------
 src/util/virpci.c        | 15 +++++++++++++++
 src/util/virpci.h        |  1 +
 4 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8fe0bf9365..0988f36c20 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2692,6 +2692,7 @@ virPCIDeviceAddressAsString;
 virPCIDeviceAddressEqual;
 virPCIDeviceAddressFree;
 virPCIDeviceAddressGetIOMMUGroupAddresses;
+virPCIDeviceAddressGetIOMMUGroupDev;
 virPCIDeviceAddressGetIOMMUGroupNum;
 virPCIDeviceAddressGetSysfsFile;
 virPCIDeviceAddressIOMMUGroupIterate;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 21a4dad37d..59e98de2d2 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -12884,12 +12884,10 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev,
     virDomainHostdevSubsysSCSIPtr scsisrc = &dev->source.subsys.u.scsi;
     virDomainHostdevSubsysSCSIVHostPtr hostsrc = &dev->source.subsys.u.scsi_host;
     virDomainHostdevSubsysMediatedDevPtr mdevsrc = &dev->source.subsys.u.mdev;
-    g_autoptr(virPCIDevice) pci = NULL;
     g_autoptr(virUSBDevice) usb = NULL;
     g_autoptr(virSCSIDevice) scsi = NULL;
     g_autoptr(virSCSIVHostDevice) host = NULL;
     g_autofree char *tmpPath = NULL;
-    g_autofree int *tmpPerms = NULL;
     int perm = 0;
 
     switch ((virDomainHostdevMode) dev->mode) {
@@ -12897,14 +12895,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev,
         switch ((virDomainHostdevSubsysType)dev->source.subsys.type) {
         case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
             if (pcisrc->backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) {
-                pci = virPCIDeviceNew(pcisrc->addr.domain,
-                                      pcisrc->addr.bus,
-                                      pcisrc->addr.slot,
-                                      pcisrc->addr.function);
-                if (!pci)
-                    return -1;
-
-                if (!(tmpPath = virPCIDeviceGetIOMMUGroupDev(pci)))
+                if (!(tmpPath = virPCIDeviceAddressGetIOMMUGroupDev(&pcisrc->addr)))
                     return -1;
 
                 perm = VIR_CGROUP_DEVICE_RW;
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 9bea5a20d0..b0a4107551 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -1942,6 +1942,21 @@ virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr)
 }
 
 
+char *
+virPCIDeviceAddressGetIOMMUGroupDev(const virPCIDeviceAddress *devAddr)
+{
+    g_autoptr(virPCIDevice) pci = NULL;
+
+    if (!(pci = virPCIDeviceNew(devAddr->domain,
+                                devAddr->bus,
+                                devAddr->slot,
+                                devAddr->function)))
+        return NULL;
+
+    return virPCIDeviceGetIOMMUGroupDev(pci);
+}
+
+
 /* virPCIDeviceGetIOMMUGroupDev - return the name of the device used
  * to control this PCI device's group (e.g. "/dev/vfio/15")
  */
diff --git a/src/util/virpci.h b/src/util/virpci.h
index cfb4581edf..1c94dc307c 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -195,6 +195,7 @@ int virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDeviceAddressPtr devAddr,
                                               virPCIDeviceAddressPtr **iommuGroupDevices,
                                               size_t *nIommuGroupDevices);
 int virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr);
+char *virPCIDeviceAddressGetIOMMUGroupDev(const virPCIDeviceAddress *devAddr);
 char *virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev);
 
 int virPCIDeviceIsAssignable(virPCIDevicePtr dev,
-- 
2.23.0




More information about the libvir-list mailing list