} 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);
} 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);
} 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,
} 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);
} 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);
* 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) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot find VFIO device for PCI device %1$s"),
- addrStr);
+ pci->name);
return -1;
}
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);
void virPCIDeviceAddressFree(virPCIDeviceAddress *address);
-int virPCIDeviceGetVfioPath(virPCIDeviceAddress *addr, char **vfioPath);
+int virPCIDeviceGetVfioPath(virPCIDevice *pci, char **vfioPath);
int virPCIDeviceOpenVfioFd(virPCIDeviceAddress *addr);