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@xxxxxxxxxx> --- src/libvirt_private.syms | 1 + src/qemu/qemu_domain.c | 10 +--------- src/util/virpci.c | 15 +++++++++++++++ src/util/virpci.h | 1 + 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index de124eb37b..4b726b3139 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2658,6 +2658,7 @@ virPCIDeviceAddressAsString; virPCIDeviceAddressEqual; virPCIDeviceAddressFree; virPCIDeviceAddressGetIOMMUGroupAddresses; +virPCIDeviceAddressGetIOMMUGroupDev; virPCIDeviceAddressGetIOMMUGroupNum; virPCIDeviceAddressGetSysfsFile; virPCIDeviceAddressIOMMUGroupIterate; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e92c2053c1..f8fe430a7f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12859,7 +12859,6 @@ 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; - VIR_AUTOPTR(virPCIDevice) pci = NULL; VIR_AUTOPTR(virUSBDevice) usb = NULL; VIR_AUTOPTR(virSCSIDevice) scsi = NULL; VIR_AUTOPTR(virSCSIVHostDevice) host = NULL; @@ -12871,14 +12870,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 ee78151e74..fc620d49ce 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1974,6 +1974,21 @@ virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr) } +char * +virPCIDeviceAddressGetIOMMUGroupDev(const virPCIDeviceAddress *devAddr) +{ + VIR_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 dc20f91710..293d10b3ab 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -193,6 +193,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.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list