libvirt/SOURCES/libvirt-RHEL-qemuSetUnprivSGIO-Actually-use-calculated-sysfs_path-to-set-unpriv_sgio.patch

171 lines
5.6 KiB
Diff
Raw Normal View History

From 717423e7a452b0715e95b492b15dc08983677d12 Mon Sep 17 00:00:00 2001
Message-Id: <717423e7a452b0715e95b492b15dc08983677d12@dist-git>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Fri, 6 Mar 2020 15:52:25 +0100
Subject: [PATCH] RHEL: qemuSetUnprivSGIO: Actually use calculated @sysfs_path
to set unpriv_sgio
In previous commits I've attempted to make qemuSetUnprivSGIO()
construct a generic enough path for SCSI devices to set
unpriv_sgio. However, virSetDeviceUnprivSGIO() does not care
about that - it constructs the path on it's own again. This is
suboptimal in either case - we already have the path constructed.
https://bugzilla.redhat.com/show_bug.cgi?id=1808390
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Message-Id: <20200306145226.1610708-6-abologna@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
---
src/qemu/qemu_conf.c | 8 +++-----
src/util/virutil.c | 24 ++++++------------------
src/util/virutil.h | 2 --
3 files changed, 9 insertions(+), 25 deletions(-)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 6d6feb97cd..b61d7e59fa 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1430,7 +1430,7 @@ qemuCheckUnprivSGIO(virHashTablePtr sharedDevices,
if (!(virHashLookup(sharedDevices, key)))
return 0;
- if (virGetDeviceUnprivSGIO(device_path, NULL, &val) < 0)
+ if (virGetDeviceUnprivSGIO(device_path, &val) < 0)
return -1;
/* Error message on failure needs to be handled in caller
@@ -1789,7 +1789,6 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
virDomainDiskDefPtr disk = NULL;
virDomainHostdevDefPtr hostdev = NULL;
g_autofree char *sysfs_path = NULL;
- const char *path = NULL;
int val = 0;
/* "sgio" is only valid for block disk; cdrom
@@ -1797,13 +1796,12 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
*/
if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
disk = dev->data.disk;
+ const char *path = virDomainDiskGetSource(disk);
if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN ||
!virStorageSourceIsBlockLocal(disk->src))
return 0;
- path = virDomainDiskGetSource(disk);
-
if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, NULL)))
return -1;
@@ -1843,7 +1841,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
* virSetDeviceUnprivSGIO, to report an error for unsupported unpriv_sgio.
*/
if ((virFileExists(sysfs_path) || val == 1) &&
- virSetDeviceUnprivSGIO(path, NULL, val) < 0)
+ virSetDeviceUnprivSGIO(sysfs_path, val) < 0)
return -1;
return 0;
diff --git a/src/util/virutil.c b/src/util/virutil.c
index f142951acf..4198473fce 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -1421,18 +1421,13 @@ virGetUnprivSGIOSysfsPath(const char *path,
int
virSetDeviceUnprivSGIO(const char *path,
- const char *sysfs_dir,
int unpriv_sgio)
{
- char *sysfs_path = NULL;
char *val = NULL;
int ret = -1;
int rc;
- if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, sysfs_dir)))
- return -1;
-
- if (!virFileExists(sysfs_path)) {
+ if (!virFileExists(path)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("unpriv_sgio is not supported by this kernel"));
goto cleanup;
@@ -1440,38 +1435,32 @@ virSetDeviceUnprivSGIO(const char *path,
val = g_strdup_printf("%d", unpriv_sgio);
- if ((rc = virFileWriteStr(sysfs_path, val, 0)) < 0) {
- virReportSystemError(-rc, _("failed to set %s"), sysfs_path);
+ if ((rc = virFileWriteStr(path, val, 0)) < 0) {
+ virReportSystemError(-rc, _("failed to set %s"), path);
goto cleanup;
}
ret = 0;
cleanup:
- VIR_FREE(sysfs_path);
VIR_FREE(val);
return ret;
}
int
virGetDeviceUnprivSGIO(const char *path,
- const char *sysfs_dir,
int *unpriv_sgio)
{
- char *sysfs_path = NULL;
char *buf = NULL;
char *tmp = NULL;
int ret = -1;
- if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, sysfs_dir)))
- return -1;
-
- if (!virFileExists(sysfs_path)) {
+ if (!virFileExists(path)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("unpriv_sgio is not supported by this kernel"));
goto cleanup;
}
- if (virFileReadAll(sysfs_path, 1024, &buf) < 0)
+ if (virFileReadAll(path, 1024, &buf) < 0)
goto cleanup;
if ((tmp = strchr(buf, '\n')))
@@ -1479,13 +1468,12 @@ virGetDeviceUnprivSGIO(const char *path,
if (virStrToLong_i(buf, NULL, 10, unpriv_sgio) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to parse value of %s"), sysfs_path);
+ _("failed to parse value of %s"), path);
goto cleanup;
}
ret = 0;
cleanup:
- VIR_FREE(sysfs_path);
VIR_FREE(buf);
return ret;
}
diff --git a/src/util/virutil.h b/src/util/virutil.h
index 1a6ae1787a..a2530e21b5 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -124,10 +124,8 @@ int virGetDeviceID(const char *path,
int *maj,
int *min);
int virSetDeviceUnprivSGIO(const char *path,
- const char *sysfs_dir,
int unpriv_sgio);
int virGetDeviceUnprivSGIO(const char *path,
- const char *sysfs_dir,
int *unpriv_sgio);
char *virGetUnprivSGIOSysfsPath(const char *path,
const char *sysfs_dir);
--
2.25.1