From: Pavel Hrdina Date: Sun, 15 Feb 2026 16:51:46 +0000 (+0100) Subject: util: Use virPCIDevice as argument in virPCIDeviceGetVfioPath X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3365bff598a0d0a5b21afc7060e10a0a2f7d21a7;p=thirdparty%2Flibvirt.git util: Use virPCIDevice as argument in virPCIDeviceGetVfioPath Signed-off-by: Pavel Hrdina Reviewed-by: Michal Privoznik --- diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c index 934acfb461..6c5da2a650 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -860,7 +860,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManager *mgr, } else { g_autofree char *vfiofdDev = NULL; - if (virPCIDeviceGetVfioPath(&dev->source.subsys.u.pci.addr, &vfiofdDev) < 0) + if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0) goto done; ret = AppArmorSetSecurityPCILabel(pci, vfiofdDev, ptr); diff --git a/src/security/security_dac.c b/src/security/security_dac.c index d0ed22db2d..704c8dbfec 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -1295,7 +1295,7 @@ virSecurityDACSetHostdevLabel(virSecurityManager *mgr, } else { g_autofree char *vfiofdDev = NULL; - if (virPCIDeviceGetVfioPath(&dev->source.subsys.u.pci.addr, &vfiofdDev) < 0) + if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0) return -1; ret = virSecurityDACSetHostdevLabelHelper(vfiofdDev, false, &cbdata); @@ -1468,7 +1468,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManager *mgr, } else { g_autofree char *vfiofdDev = NULL; - if (virPCIDeviceGetVfioPath(&dev->source.subsys.u.pci.addr, &vfiofdDev) < 0) + if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0) return -1; ret = virSecurityDACRestoreFileLabelInternal(mgr, NULL, diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 834383a7de..4a5f61d16b 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -2269,7 +2269,7 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManager *mgr, } else { g_autofree char *vfiofdDev = NULL; - if (virPCIDeviceGetVfioPath(&dev->source.subsys.u.pci.addr, &vfiofdDev) < 0) + if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0) return -1; ret = virSecuritySELinuxSetHostdevLabelHelper(vfiofdDev, false, &data); @@ -2515,7 +2515,7 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManager *mgr, } else { g_autofree char *vfiofdDev = NULL; - if (virPCIDeviceGetVfioPath(&dev->source.subsys.u.pci.addr, &vfiofdDev) < 0) + if (virPCIDeviceGetVfioPath(pci, &vfiofdDev) < 0) return -1; ret = virSecuritySELinuxRestoreFileLabel(mgr, vfiofdDev, false, false); diff --git a/src/util/virpci.c b/src/util/virpci.c index 30feec6dae..78c47869ef 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -3331,19 +3331,17 @@ virPCIDeviceAddressFree(virPCIDeviceAddress *address) * Returns: 0 on success, -1 on failure */ int -virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr, +virPCIDeviceGetVfioPath(virPCIDevice *pci, char **vfioPath) { - g_autofree char *addrStr = NULL; g_autofree char *sysfsPath = NULL; g_autoptr(DIR) dir = NULL; struct dirent *entry = NULL; *vfioPath = NULL; - addrStr = virPCIDeviceAddressAsString(addr); /* Look in device's vfio-dev subdirectory */ - sysfsPath = g_strdup_printf("/sys/bus/pci/devices/%s/vfio-dev/", addrStr); + sysfsPath = virPCIFile(pci->name, "vfio-dev"); if (virDirOpen(&dir, sysfsPath) == 1) { while (virDirRead(dir, &entry, sysfsPath) > 0) { @@ -3356,7 +3354,7 @@ virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr, virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find VFIO device for PCI device %1$s"), - addrStr); + pci->name); return -1; } @@ -3371,10 +3369,14 @@ virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr, int virPCIDeviceOpenVfioFd(virPCIDeviceAddress *addr) { + g_autoptr(virPCIDevice) pci = NULL; g_autofree char *vfioPath = NULL; int fd = -1; - if (virPCIDeviceGetVfioPath(addr, &vfioPath) < 0) + if (!(pci = virPCIDeviceNew(addr))) + return -1; + + if (virPCIDeviceGetVfioPath(pci, &vfioPath) < 0) return -1; VIR_DEBUG("Opening VFIO device %s", vfioPath); diff --git a/src/util/virpci.h b/src/util/virpci.h index 7848567285..933099da6c 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -296,7 +296,7 @@ void virPCIEDeviceInfoFree(virPCIEDeviceInfo *dev); void virPCIDeviceAddressFree(virPCIDeviceAddress *address); -int virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr, char **vfioPath); +int virPCIDeviceGetVfioPath(virPCIDevice *pci, char **vfioPath); int virPCIDeviceOpenVfioFd(virPCIDeviceAddress *addr);