mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
mdev: Pass a uuidstr rather than an mdev object to some util functions
Namely, this patch is about virMediatedDeviceGetIOMMUGroup{Dev,Num} functions. There's no compelling reason why these functions should take an object, on the contrary, having to create an object every time one needs to query the IOMMU group number, discarding the object afterwards, seems odd. Signed-off-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
1128769f9e
commit
3a2a2a7401
@ -7258,7 +7258,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
|
|||||||
virUSBDevicePtr usb = NULL;
|
virUSBDevicePtr usb = NULL;
|
||||||
virSCSIDevicePtr scsi = NULL;
|
virSCSIDevicePtr scsi = NULL;
|
||||||
virSCSIVHostDevicePtr host = NULL;
|
virSCSIVHostDevicePtr host = NULL;
|
||||||
virMediatedDevicePtr mdev = NULL;
|
|
||||||
char *tmpPath = NULL;
|
char *tmpPath = NULL;
|
||||||
bool freeTmpPath = false;
|
bool freeTmpPath = false;
|
||||||
bool includeVFIO = false;
|
bool includeVFIO = false;
|
||||||
@ -7359,11 +7358,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
|
||||||
if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
|
if (!(tmpPath = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
|
||||||
mdevsrc->model)))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!(tmpPath = virMediatedDeviceGetIOMMUGroupDev(mdev)))
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
freeTmpPath = true;
|
freeTmpPath = true;
|
||||||
@ -7419,7 +7414,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
|
|||||||
virUSBDeviceFree(usb);
|
virUSBDeviceFree(usb);
|
||||||
virSCSIDeviceFree(scsi);
|
virSCSIDeviceFree(scsi);
|
||||||
virSCSIVHostDeviceFree(host);
|
virSCSIVHostDeviceFree(host);
|
||||||
virMediatedDeviceFree(mdev);
|
|
||||||
if (freeTmpPath)
|
if (freeTmpPath)
|
||||||
VIR_FREE(tmpPath);
|
VIR_FREE(tmpPath);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -905,21 +905,13 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
|
|||||||
|
|
||||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
||||||
char *vfiodev = NULL;
|
char *vfiodev = NULL;
|
||||||
virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
|
|
||||||
mdevsrc->model);
|
|
||||||
|
|
||||||
if (!mdev)
|
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
|
|
||||||
virMediatedDeviceFree(mdev);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = AppArmorSetSecurityHostdevLabelHelper(vfiodev, ptr);
|
ret = AppArmorSetSecurityHostdevLabelHelper(vfiodev, ptr);
|
||||||
|
|
||||||
VIR_FREE(vfiodev);
|
VIR_FREE(vfiodev);
|
||||||
virMediatedDeviceFree(mdev);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -968,21 +968,13 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
|
|||||||
|
|
||||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
||||||
char *vfiodev = NULL;
|
char *vfiodev = NULL;
|
||||||
virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
|
|
||||||
mdevsrc->model);
|
|
||||||
|
|
||||||
if (!mdev)
|
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
|
|
||||||
virMediatedDeviceFree(mdev);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = virSecurityDACSetHostdevLabelHelper(vfiodev, &cbdata);
|
ret = virSecurityDACSetHostdevLabelHelper(vfiodev, &cbdata);
|
||||||
|
|
||||||
VIR_FREE(vfiodev);
|
VIR_FREE(vfiodev);
|
||||||
virMediatedDeviceFree(mdev);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1144,21 +1136,13 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr mgr,
|
|||||||
|
|
||||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
||||||
char *vfiodev = NULL;
|
char *vfiodev = NULL;
|
||||||
virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
|
|
||||||
mdevsrc->model);
|
|
||||||
|
|
||||||
if (!mdev)
|
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
|
|
||||||
virMediatedDeviceFree(mdev);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = virSecurityDACRestoreFileLabel(virSecurityManagerGetPrivateData(mgr),
|
ret = virSecurityDACRestoreFileLabel(virSecurityManagerGetPrivateData(mgr),
|
||||||
vfiodev);
|
vfiodev);
|
||||||
VIR_FREE(vfiodev);
|
VIR_FREE(vfiodev);
|
||||||
virMediatedDeviceFree(mdev);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1843,21 +1843,13 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
|
|||||||
|
|
||||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
||||||
char *vfiodev = NULL;
|
char *vfiodev = NULL;
|
||||||
virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
|
|
||||||
mdevsrc->model);
|
|
||||||
|
|
||||||
if (!mdev)
|
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
|
|
||||||
virMediatedDeviceFree(mdev);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = virSecuritySELinuxSetHostdevLabelHelper(vfiodev, &data);
|
ret = virSecuritySELinuxSetHostdevLabelHelper(vfiodev, &data);
|
||||||
|
|
||||||
VIR_FREE(vfiodev);
|
VIR_FREE(vfiodev);
|
||||||
virMediatedDeviceFree(mdev);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2092,21 +2084,13 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
|
|||||||
|
|
||||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
||||||
char *vfiodev = NULL;
|
char *vfiodev = NULL;
|
||||||
virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
|
|
||||||
mdevsrc->model);
|
|
||||||
|
|
||||||
if (!mdev)
|
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
|
|
||||||
virMediatedDeviceFree(mdev);
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = virSecuritySELinuxRestoreFileLabel(mgr, vfiodev);
|
ret = virSecuritySELinuxRestoreFileLabel(mgr, vfiodev);
|
||||||
|
|
||||||
VIR_FREE(vfiodev);
|
VIR_FREE(vfiodev);
|
||||||
virMediatedDeviceFree(mdev);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,43 +209,48 @@ virMediatedDeviceGetPath(virMediatedDevicePtr dev)
|
|||||||
* for freeing the result.
|
* for freeing the result.
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
virMediatedDeviceGetIOMMUGroupDev(virMediatedDevicePtr dev)
|
virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr)
|
||||||
{
|
{
|
||||||
char *resultpath = NULL;
|
char *result_path = NULL;
|
||||||
char *iommu_path = NULL;
|
char *iommu_path = NULL;
|
||||||
char *vfio_path = NULL;
|
char *vfio_path = NULL;
|
||||||
|
char *dev_path = virMediatedDeviceGetSysfsPath(uuidstr);
|
||||||
|
|
||||||
if (virAsprintf(&iommu_path, "%s/iommu_group", dev->path) < 0)
|
if (!dev_path)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (virAsprintf(&iommu_path, "%s/iommu_group", dev_path) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (!virFileExists(iommu_path)) {
|
if (!virFileExists(iommu_path)) {
|
||||||
virReportSystemError(errno, _("failed to access '%s'"), iommu_path);
|
virReportSystemError(errno, _("failed to access '%s'"), iommu_path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virFileResolveLink(iommu_path, &resultpath) < 0) {
|
if (virFileResolveLink(iommu_path, &result_path) < 0) {
|
||||||
virReportSystemError(errno, _("failed to resolve '%s'"), iommu_path);
|
virReportSystemError(errno, _("failed to resolve '%s'"), iommu_path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virAsprintf(&vfio_path, "/dev/vfio/%s", last_component(resultpath)) < 0)
|
if (virAsprintf(&vfio_path, "/dev/vfio/%s", last_component(result_path)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(resultpath);
|
VIR_FREE(result_path);
|
||||||
VIR_FREE(iommu_path);
|
VIR_FREE(iommu_path);
|
||||||
|
VIR_FREE(dev_path);
|
||||||
return vfio_path;
|
return vfio_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
virMediatedDeviceGetIOMMUGroupNum(virMediatedDevicePtr dev)
|
virMediatedDeviceGetIOMMUGroupNum(const char *uuidstr)
|
||||||
{
|
{
|
||||||
char *vfio_path = NULL;
|
char *vfio_path = NULL;
|
||||||
char *group_num_str = NULL;
|
char *group_num_str = NULL;
|
||||||
unsigned int group_num = -1;
|
unsigned int group_num = -1;
|
||||||
|
|
||||||
if (!(vfio_path = virMediatedDeviceGetIOMMUGroupDev(dev)))
|
if (!(vfio_path = virMediatedDeviceGetIOMMUGroupDev(uuidstr)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
group_num_str = last_component(vfio_path);
|
group_num_str = last_component(vfio_path);
|
||||||
|
@ -65,10 +65,10 @@ virMediatedDeviceSetUsedBy(virMediatedDevicePtr dev,
|
|||||||
const char *domname);
|
const char *domname);
|
||||||
|
|
||||||
char *
|
char *
|
||||||
virMediatedDeviceGetIOMMUGroupDev(virMediatedDevicePtr dev);
|
virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr);
|
||||||
|
|
||||||
int
|
int
|
||||||
virMediatedDeviceGetIOMMUGroupNum(virMediatedDevicePtr dev);
|
virMediatedDeviceGetIOMMUGroupNum(const char *uuidstr);
|
||||||
|
|
||||||
char *
|
char *
|
||||||
virMediatedDeviceGetSysfsPath(const char *uuidstr);
|
virMediatedDeviceGetSysfsPath(const char *uuidstr);
|
||||||
|
Loading…
Reference in New Issue
Block a user