mirror of
https://github.com/libvirt/libvirt.git
synced 2026-10-02 12:20:06 -05:00
util: Use virPCIDevice as argument in virPCIDeviceGetVfioPath
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
1 parent
76b720168b
commit
3365bff598
5 files changed
+14
-12
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
+8
-6
@@ -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);
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user