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