171 lines
5.6 KiB
Diff
171 lines
5.6 KiB
Diff
From 785d2dd780b472bf857dd962d910addd9ff7b07f Mon Sep 17 00:00:00 2001
|
|
Message-Id: <785d2dd780b472bf857dd962d910addd9ff7b07f@dist-git>
|
|
From: Michal Privoznik <mprivozn@redhat.com>
|
|
Date: Fri, 6 Mar 2020 15:51:48 +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=1808388
|
|
|
|
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
|
|
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
|
|
Message-Id: <20200306145149.1610286-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 5636277888..5788354444 100644
|
|
--- a/src/qemu/qemu_conf.c
|
|
+++ b/src/qemu/qemu_conf.c
|
|
@@ -1255,7 +1255,7 @@ qemuCheckUnprivSGIO(virHashTablePtr sharedDevices,
|
|
goto cleanup;
|
|
}
|
|
|
|
- if (virGetDeviceUnprivSGIO(device_path, NULL, &val) < 0)
|
|
+ if (virGetDeviceUnprivSGIO(device_path, &val) < 0)
|
|
goto cleanup;
|
|
|
|
/* Error message on failure needs to be handled in caller
|
|
@@ -1648,7 +1648,6 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
|
|
virDomainDiskDefPtr disk = NULL;
|
|
virDomainHostdevDefPtr hostdev = NULL;
|
|
char *sysfs_path = NULL;
|
|
- const char *path = NULL;
|
|
int val = 0;
|
|
int ret = -1;
|
|
|
|
@@ -1657,13 +1656,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)))
|
|
goto cleanup;
|
|
|
|
@@ -1703,7 +1701,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)
|
|
goto cleanup;
|
|
|
|
ret = 0;
|
|
diff --git a/src/util/virutil.c b/src/util/virutil.c
|
|
index 2448eba073..ad2b8cb3a2 100644
|
|
--- a/src/util/virutil.c
|
|
+++ b/src/util/virutil.c
|
|
@@ -1736,18 +1736,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;
|
|
@@ -1756,38 +1751,32 @@ virSetDeviceUnprivSGIO(const char *path,
|
|
if (virAsprintf(&val, "%d", unpriv_sgio) < 0)
|
|
goto cleanup;
|
|
|
|
- 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')))
|
|
@@ -1795,13 +1784,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 1ba9635bd9..1a1313cfa3 100644
|
|
--- a/src/util/virutil.h
|
|
+++ b/src/util/virutil.h
|
|
@@ -160,10 +160,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
|
|
|