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

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