]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Use virPCIDevice as argument in virPCIDeviceGetVfioPath
authorPavel Hrdina <phrdina@redhat.com>
Sun, 15 Feb 2026 16:51:46 +0000 (17:51 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 16 Feb 2026 14:50:39 +0000 (15:50 +0100)
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/security/security_apparmor.c
src/security/security_dac.c
src/security/security_selinux.c
src/util/virpci.c
src/util/virpci.h

index 934acfb46198401d84d47cc6266a9403eda5a3b0..6c5da2a65067fccb588770ffa5737fc8e1ff81c7 100644 (file)
@@ -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);
index d0ed22db2d24c6739fff2e88b0953bd242b71ed1..704c8dbfecc24aac1bab80eefe8e4149c3eb9a69 100644 (file)
@@ -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,
index 834383a7de1920f79b1f15761fee522a6ea43235..4a5f61d16b21886072bfd87a3a8ce9bf5e53454d 100644 (file)
@@ -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);
index 30feec6dae6314101fac4ce9c185fda5077876fc..78c47869efb0a2073b67adbac261d212d716e938 100644 (file)
@@ -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);
index 78485672856b45b76e5e80c5792f8cfd3476b93f..933099da6cde7dce48e2894403524d41a796fd7c 100644 (file)
@@ -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);