|
|
3e5111 |
From ebb336d5b22b9707b53bcc4fd2e24845666fdc4f Mon Sep 17 00:00:00 2001
|
|
|
3e5111 |
Message-Id: <ebb336d5b22b9707b53bcc4fd2e24845666fdc4f@dist-git>
|
|
|
3e5111 |
From: Erik Skultety <eskultet@redhat.com>
|
|
|
3e5111 |
Date: Thu, 18 May 2017 14:02:50 +0200
|
|
|
3e5111 |
Subject: [PATCH] mdev: Pass a uuidstr rather than an mdev object to some util
|
|
|
3e5111 |
functions
|
|
|
3e5111 |
|
|
|
3e5111 |
Namely, this patch is about virMediatedDeviceGetIOMMUGroup{Dev,Num}
|
|
|
3e5111 |
functions. There's no compelling reason why these functions should take
|
|
|
3e5111 |
an object, on the contrary, having to create an object every time one
|
|
|
3e5111 |
needs to query the IOMMU group number, discarding the object afterwards,
|
|
|
3e5111 |
seems odd.
|
|
|
3e5111 |
|
|
|
3e5111 |
https://bugzilla.redhat.com/show_bug.cgi?id=1452072
|
|
|
3e5111 |
|
|
|
3e5111 |
Signed-off-by: Erik Skultety <eskultet@redhat.com>
|
|
|
3e5111 |
(cherry picked from commit 3a2a2a7401d06a8f06fa75359190f59737c5dc5d)
|
|
|
3e5111 |
Signed-off-by: Erik Skultety <eskultet@redhat.com>
|
|
|
3e5111 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
3e5111 |
---
|
|
|
3e5111 |
src/qemu/qemu_domain.c | 8 +-------
|
|
|
3e5111 |
src/security/security_apparmor.c | 10 +---------
|
|
|
3e5111 |
src/security/security_dac.c | 20 ++------------------
|
|
|
3e5111 |
src/security/security_selinux.c | 20 ++------------------
|
|
|
3e5111 |
src/util/virmdev.c | 21 +++++++++++++--------
|
|
|
3e5111 |
src/util/virmdev.h | 4 ++--
|
|
|
3e5111 |
6 files changed, 21 insertions(+), 62 deletions(-)
|
|
|
3e5111 |
|
|
|
3e5111 |
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
|
|
|
3e5111 |
index 117c6142b..04d1b39db 100644
|
|
|
3e5111 |
--- a/src/qemu/qemu_domain.c
|
|
|
3e5111 |
+++ b/src/qemu/qemu_domain.c
|
|
|
3e5111 |
@@ -7216,7 +7216,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
|
|
|
3e5111 |
virUSBDevicePtr usb = NULL;
|
|
|
3e5111 |
virSCSIDevicePtr scsi = NULL;
|
|
|
3e5111 |
virSCSIVHostDevicePtr host = NULL;
|
|
|
3e5111 |
- virMediatedDevicePtr mdev = NULL;
|
|
|
3e5111 |
char *tmpPath = NULL;
|
|
|
3e5111 |
bool freeTmpPath = false;
|
|
|
3e5111 |
bool includeVFIO = false;
|
|
|
3e5111 |
@@ -7317,11 +7316,7 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
|
|
|
3e5111 |
}
|
|
|
3e5111 |
|
|
|
3e5111 |
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
|
|
|
3e5111 |
- if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
|
|
|
3e5111 |
- mdevsrc->model)))
|
|
|
3e5111 |
- goto cleanup;
|
|
|
3e5111 |
-
|
|
|
3e5111 |
- if (!(tmpPath = virMediatedDeviceGetIOMMUGroupDev(mdev)))
|
|
|
3e5111 |
+ if (!(tmpPath = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
|
|
|
3e5111 |
goto cleanup;
|
|
|
3e5111 |
|
|
|
3e5111 |
freeTmpPath = true;
|
|
|
3e5111 |
@@ -7377,7 +7372,6 @@ qemuDomainGetHostdevPath(virDomainDefPtr def,
|
|
|
3e5111 |
virUSBDeviceFree(usb);
|
|
|
3e5111 |
virSCSIDeviceFree(scsi);
|
|
|
3e5111 |
virSCSIVHostDeviceFree(host);
|
|
|
3e5111 |
- virMediatedDeviceFree(mdev);
|
|
|
3e5111 |
if (freeTmpPath)
|
|
|
3e5111 |
VIR_FREE(tmpPath);
|
|
|
3e5111 |
return ret;
|
|
|
3e5111 |
diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
|
|
|
3e5111 |
index fc5581526..62672b0af 100644
|
|
|
3e5111 |
--- a/src/security/security_apparmor.c
|
|
|
3e5111 |
+++ b/src/security/security_apparmor.c
|
|
|
3e5111 |
@@ -905,21 +905,13 @@ AppArmorSetSecurityHostdevLabel(virSecurityManagerPtr mgr,
|
|
|
3e5111 |
|
|
|
3e5111 |
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
|
|
3e5111 |
char *vfiodev = NULL;
|
|
|
3e5111 |
- virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
|
|
|
3e5111 |
- mdevsrc->model);
|
|
|
3e5111 |
|
|
|
3e5111 |
- if (!mdev)
|
|
|
3e5111 |
+ if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
|
|
|
3e5111 |
goto done;
|
|
|
3e5111 |
|
|
|
3e5111 |
- if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
|
|
|
3e5111 |
- virMediatedDeviceFree(mdev);
|
|
|
3e5111 |
- goto done;
|
|
|
3e5111 |
- }
|
|
|
3e5111 |
-
|
|
|
3e5111 |
ret = AppArmorSetSecurityHostdevLabelHelper(vfiodev, ptr);
|
|
|
3e5111 |
|
|
|
3e5111 |
VIR_FREE(vfiodev);
|
|
|
3e5111 |
- virMediatedDeviceFree(mdev);
|
|
|
3e5111 |
break;
|
|
|
3e5111 |
}
|
|
|
3e5111 |
|
|
|
3e5111 |
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
|
|
|
3e5111 |
index 922e48494..7dcf4c15f 100644
|
|
|
3e5111 |
--- a/src/security/security_dac.c
|
|
|
3e5111 |
+++ b/src/security/security_dac.c
|
|
|
3e5111 |
@@ -968,21 +968,13 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
|
|
|
3e5111 |
|
|
|
3e5111 |
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
|
|
3e5111 |
char *vfiodev = NULL;
|
|
|
3e5111 |
- virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
|
|
|
3e5111 |
- mdevsrc->model);
|
|
|
3e5111 |
|
|
|
3e5111 |
- if (!mdev)
|
|
|
3e5111 |
+ if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
|
|
|
3e5111 |
goto done;
|
|
|
3e5111 |
|
|
|
3e5111 |
- if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
|
|
|
3e5111 |
- virMediatedDeviceFree(mdev);
|
|
|
3e5111 |
- goto done;
|
|
|
3e5111 |
- }
|
|
|
3e5111 |
-
|
|
|
3e5111 |
ret = virSecurityDACSetHostdevLabelHelper(vfiodev, &cbdata);
|
|
|
3e5111 |
|
|
|
3e5111 |
VIR_FREE(vfiodev);
|
|
|
3e5111 |
- virMediatedDeviceFree(mdev);
|
|
|
3e5111 |
break;
|
|
|
3e5111 |
}
|
|
|
3e5111 |
|
|
|
3e5111 |
@@ -1144,21 +1136,13 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr mgr,
|
|
|
3e5111 |
|
|
|
3e5111 |
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
|
|
3e5111 |
char *vfiodev = NULL;
|
|
|
3e5111 |
- virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
|
|
|
3e5111 |
- mdevsrc->model);
|
|
|
3e5111 |
|
|
|
3e5111 |
- if (!mdev)
|
|
|
3e5111 |
+ if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
|
|
|
3e5111 |
goto done;
|
|
|
3e5111 |
|
|
|
3e5111 |
- if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
|
|
|
3e5111 |
- virMediatedDeviceFree(mdev);
|
|
|
3e5111 |
- goto done;
|
|
|
3e5111 |
- }
|
|
|
3e5111 |
-
|
|
|
3e5111 |
ret = virSecurityDACRestoreFileLabel(virSecurityManagerGetPrivateData(mgr),
|
|
|
3e5111 |
vfiodev);
|
|
|
3e5111 |
VIR_FREE(vfiodev);
|
|
|
3e5111 |
- virMediatedDeviceFree(mdev);
|
|
|
3e5111 |
break;
|
|
|
3e5111 |
}
|
|
|
3e5111 |
|
|
|
3e5111 |
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
|
|
|
3e5111 |
index df7c96833..c7a2dfe98 100644
|
|
|
3e5111 |
--- a/src/security/security_selinux.c
|
|
|
3e5111 |
+++ b/src/security/security_selinux.c
|
|
|
3e5111 |
@@ -1843,21 +1843,13 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
|
|
|
3e5111 |
|
|
|
3e5111 |
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
|
|
3e5111 |
char *vfiodev = NULL;
|
|
|
3e5111 |
- virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
|
|
|
3e5111 |
- mdevsrc->model);
|
|
|
3e5111 |
|
|
|
3e5111 |
- if (!mdev)
|
|
|
3e5111 |
+ if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
|
|
|
3e5111 |
goto done;
|
|
|
3e5111 |
|
|
|
3e5111 |
- if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
|
|
|
3e5111 |
- virMediatedDeviceFree(mdev);
|
|
|
3e5111 |
- goto done;
|
|
|
3e5111 |
- }
|
|
|
3e5111 |
-
|
|
|
3e5111 |
ret = virSecuritySELinuxSetHostdevLabelHelper(vfiodev, &data);
|
|
|
3e5111 |
|
|
|
3e5111 |
VIR_FREE(vfiodev);
|
|
|
3e5111 |
- virMediatedDeviceFree(mdev);
|
|
|
3e5111 |
break;
|
|
|
3e5111 |
}
|
|
|
3e5111 |
|
|
|
3e5111 |
@@ -2092,21 +2084,13 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
|
|
|
3e5111 |
|
|
|
3e5111 |
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
|
|
3e5111 |
char *vfiodev = NULL;
|
|
|
3e5111 |
- virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr,
|
|
|
3e5111 |
- mdevsrc->model);
|
|
|
3e5111 |
|
|
|
3e5111 |
- if (!mdev)
|
|
|
3e5111 |
+ if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdevsrc->uuidstr)))
|
|
|
3e5111 |
goto done;
|
|
|
3e5111 |
|
|
|
3e5111 |
- if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
|
|
|
3e5111 |
- virMediatedDeviceFree(mdev);
|
|
|
3e5111 |
- goto done;
|
|
|
3e5111 |
- }
|
|
|
3e5111 |
-
|
|
|
3e5111 |
ret = virSecuritySELinuxRestoreFileLabel(mgr, vfiodev);
|
|
|
3e5111 |
|
|
|
3e5111 |
VIR_FREE(vfiodev);
|
|
|
3e5111 |
- virMediatedDeviceFree(mdev);
|
|
|
3e5111 |
break;
|
|
|
3e5111 |
}
|
|
|
3e5111 |
|
|
|
3e5111 |
diff --git a/src/util/virmdev.c b/src/util/virmdev.c
|
|
|
3e5111 |
index c861d21c9..169deedfd 100644
|
|
|
3e5111 |
--- a/src/util/virmdev.c
|
|
|
3e5111 |
+++ b/src/util/virmdev.c
|
|
|
3e5111 |
@@ -209,43 +209,48 @@ virMediatedDeviceGetPath(virMediatedDevicePtr dev)
|
|
|
3e5111 |
* for freeing the result.
|
|
|
3e5111 |
*/
|
|
|
3e5111 |
char *
|
|
|
3e5111 |
-virMediatedDeviceGetIOMMUGroupDev(virMediatedDevicePtr dev)
|
|
|
3e5111 |
+virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr)
|
|
|
3e5111 |
{
|
|
|
3e5111 |
- char *resultpath = NULL;
|
|
|
3e5111 |
+ char *result_path = NULL;
|
|
|
3e5111 |
char *iommu_path = NULL;
|
|
|
3e5111 |
char *vfio_path = NULL;
|
|
|
3e5111 |
+ char *dev_path = virMediatedDeviceGetSysfsPath(uuidstr);
|
|
|
3e5111 |
|
|
|
3e5111 |
- if (virAsprintf(&iommu_path, "%s/iommu_group", dev->path) < 0)
|
|
|
3e5111 |
+ if (!dev_path)
|
|
|
3e5111 |
return NULL;
|
|
|
3e5111 |
|
|
|
3e5111 |
+ if (virAsprintf(&iommu_path, "%s/iommu_group", dev_path) < 0)
|
|
|
3e5111 |
+ goto cleanup;
|
|
|
3e5111 |
+
|
|
|
3e5111 |
if (!virFileExists(iommu_path)) {
|
|
|
3e5111 |
virReportSystemError(errno, _("failed to access '%s'"), iommu_path);
|
|
|
3e5111 |
goto cleanup;
|
|
|
3e5111 |
}
|
|
|
3e5111 |
|
|
|
3e5111 |
- if (virFileResolveLink(iommu_path, &resultpath) < 0) {
|
|
|
3e5111 |
+ if (virFileResolveLink(iommu_path, &result_path) < 0) {
|
|
|
3e5111 |
virReportSystemError(errno, _("failed to resolve '%s'"), iommu_path);
|
|
|
3e5111 |
goto cleanup;
|
|
|
3e5111 |
}
|
|
|
3e5111 |
|
|
|
3e5111 |
- if (virAsprintf(&vfio_path, "/dev/vfio/%s", last_component(resultpath)) < 0)
|
|
|
3e5111 |
+ if (virAsprintf(&vfio_path, "/dev/vfio/%s", last_component(result_path)) < 0)
|
|
|
3e5111 |
goto cleanup;
|
|
|
3e5111 |
|
|
|
3e5111 |
cleanup:
|
|
|
3e5111 |
- VIR_FREE(resultpath);
|
|
|
3e5111 |
+ VIR_FREE(result_path);
|
|
|
3e5111 |
VIR_FREE(iommu_path);
|
|
|
3e5111 |
+ VIR_FREE(dev_path);
|
|
|
3e5111 |
return vfio_path;
|
|
|
3e5111 |
}
|
|
|
3e5111 |
|
|
|
3e5111 |
|
|
|
3e5111 |
int
|
|
|
3e5111 |
-virMediatedDeviceGetIOMMUGroupNum(virMediatedDevicePtr dev)
|
|
|
3e5111 |
+virMediatedDeviceGetIOMMUGroupNum(const char *uuidstr)
|
|
|
3e5111 |
{
|
|
|
3e5111 |
char *vfio_path = NULL;
|
|
|
3e5111 |
char *group_num_str = NULL;
|
|
|
3e5111 |
unsigned int group_num = -1;
|
|
|
3e5111 |
|
|
|
3e5111 |
- if (!(vfio_path = virMediatedDeviceGetIOMMUGroupDev(dev)))
|
|
|
3e5111 |
+ if (!(vfio_path = virMediatedDeviceGetIOMMUGroupDev(uuidstr)))
|
|
|
3e5111 |
return -1;
|
|
|
3e5111 |
|
|
|
3e5111 |
group_num_str = last_component(vfio_path);
|
|
|
3e5111 |
diff --git a/src/util/virmdev.h b/src/util/virmdev.h
|
|
|
3e5111 |
index 8bb46b9c5..0b8e830f4 100644
|
|
|
3e5111 |
--- a/src/util/virmdev.h
|
|
|
3e5111 |
+++ b/src/util/virmdev.h
|
|
|
3e5111 |
@@ -65,10 +65,10 @@ virMediatedDeviceSetUsedBy(virMediatedDevicePtr dev,
|
|
|
3e5111 |
const char *domname);
|
|
|
3e5111 |
|
|
|
3e5111 |
char *
|
|
|
3e5111 |
-virMediatedDeviceGetIOMMUGroupDev(virMediatedDevicePtr dev);
|
|
|
3e5111 |
+virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr);
|
|
|
3e5111 |
|
|
|
3e5111 |
int
|
|
|
3e5111 |
-virMediatedDeviceGetIOMMUGroupNum(virMediatedDevicePtr dev);
|
|
|
3e5111 |
+virMediatedDeviceGetIOMMUGroupNum(const char *uuidstr);
|
|
|
3e5111 |
|
|
|
3e5111 |
char *
|
|
|
3e5111 |
virMediatedDeviceGetSysfsPath(const char *uuidstr);
|
|
|
3e5111 |
--
|
|
|
3e5111 |
2.13.0
|
|
|
3e5111 |
|