]> xenbits.xensource.com Git - libvirt.git/commitdiff
virpci: Introduce and use virPCIDeviceAddressGetIOMMUGroupDev
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 19 Sep 2019 12:43:13 +0000 (14:43 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 17 Dec 2019 09:04:43 +0000 (10:04 +0100)
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@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
src/libvirt_private.syms
src/qemu/qemu_domain.c
src/util/virpci.c
src/util/virpci.h

index 10f8df8305a8c3053d6a39120172ae7af2ea93f7..2424e475c7ec394a68819ad1562dcb4671d07628 100644 (file)
@@ -2709,6 +2709,7 @@ virPCIDeviceAddressAsString;
 virPCIDeviceAddressEqual;
 virPCIDeviceAddressFree;
 virPCIDeviceAddressGetIOMMUGroupAddresses;
+virPCIDeviceAddressGetIOMMUGroupDev;
 virPCIDeviceAddressGetIOMMUGroupNum;
 virPCIDeviceAddressGetSysfsFile;
 virPCIDeviceAddressIOMMUGroupIterate;
index 3aead8030e32fcaaa0a31772b66c759c75ac376c..fb6dee6bde152fa71d732930de68efb2d7a88675 100644 (file)
@@ -13845,12 +13845,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) {
@@ -13858,14 +13856,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;
index 9bea5a20d01bcf8680ad6b8a7a540b5803898ee0..b0a4107551886c1f007cd1a6d324a18dfa0a0dbf 100644 (file)
@@ -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")
  */
index cfb4581edf723d83a49d2efe956d442619b67b56..1c94dc307c876889a3db196f0382e65a1413f095 100644 (file)
@@ -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,