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

d759b5
From 65f4ff0e2c9a968b7ec65c8d751d4055cc212628 Mon Sep 17 00:00:00 2001
d759b5
Message-Id: <65f4ff0e2c9a968b7ec65c8d751d4055cc212628@dist-git>
d759b5
From: Michal Privoznik <mprivozn@redhat.com>
d759b5
Date: Thu, 10 Oct 2019 14:20:58 +0200
d759b5
Subject: [PATCH] RHEL: qemuSetUnprivSGIO: Actually use calculated @sysfs_path
d759b5
 to set unpriv_sgio
d759b5
d759b5
In previous commits I've attempted to make qemuSetUnprivSGIO()
d759b5
construct a generic enough path for SCSI devices to set
d759b5
unpriv_sgio. However, virSetDeviceUnprivSGIO() does not care
d759b5
about that - it constructs the path on it's own again. This is
d759b5
suboptimal in either case - we already have the path constructed.
d759b5
d759b5
https://bugzilla.redhat.com/show_bug.cgi?id=1754241
d759b5
d759b5
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
d759b5
Message-Id: <1f6fa49bd2fec4e3b144cb8c1a27a9d0456c9431.1570709916.git.mprivozn@redhat.com>
d759b5
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
d759b5
---
d759b5
 src/qemu/qemu_conf.c |  8 +++-----
d759b5
 src/util/virutil.c   | 24 ++++++------------------
d759b5
 src/util/virutil.h   |  2 --
d759b5
 3 files changed, 9 insertions(+), 25 deletions(-)
d759b5
d759b5
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
d759b5
index 5636277888..5788354444 100644
d759b5
--- a/src/qemu/qemu_conf.c
d759b5
+++ b/src/qemu/qemu_conf.c
d759b5
@@ -1255,7 +1255,7 @@ qemuCheckUnprivSGIO(virHashTablePtr sharedDevices,
d759b5
         goto cleanup;
d759b5
     }
d759b5
 
d759b5
-    if (virGetDeviceUnprivSGIO(device_path, NULL, &val) < 0)
d759b5
+    if (virGetDeviceUnprivSGIO(device_path, &val) < 0)
d759b5
         goto cleanup;
d759b5
 
d759b5
     /* Error message on failure needs to be handled in caller
d759b5
@@ -1648,7 +1648,6 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
d759b5
     virDomainDiskDefPtr disk = NULL;
d759b5
     virDomainHostdevDefPtr hostdev = NULL;
d759b5
     char *sysfs_path = NULL;
d759b5
-    const char *path = NULL;
d759b5
     int val = 0;
d759b5
     int ret = -1;
d759b5
 
d759b5
@@ -1657,13 +1656,12 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
d759b5
      */
d759b5
     if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
d759b5
         disk = dev->data.disk;
d759b5
+        const char *path = virDomainDiskGetSource(disk);
d759b5
 
d759b5
         if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN ||
d759b5
             !virStorageSourceIsBlockLocal(disk->src))
d759b5
             return 0;
d759b5
 
d759b5
-        path = virDomainDiskGetSource(disk);
d759b5
-
d759b5
         if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, NULL)))
d759b5
             goto cleanup;
d759b5
 
d759b5
@@ -1703,7 +1701,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
d759b5
      * virSetDeviceUnprivSGIO, to report an error for unsupported unpriv_sgio.
d759b5
      */
d759b5
     if ((virFileExists(sysfs_path) || val == 1) &&
d759b5
-        virSetDeviceUnprivSGIO(path, NULL, val) < 0)
d759b5
+        virSetDeviceUnprivSGIO(sysfs_path, val) < 0)
d759b5
         goto cleanup;
d759b5
 
d759b5
     ret = 0;
d759b5
diff --git a/src/util/virutil.c b/src/util/virutil.c
d759b5
index fb2a95041a..fd70df120b 100644
d759b5
--- a/src/util/virutil.c
d759b5
+++ b/src/util/virutil.c
d759b5
@@ -1715,18 +1715,13 @@ virGetUnprivSGIOSysfsPath(const char *path,
d759b5
 
d759b5
 int
d759b5
 virSetDeviceUnprivSGIO(const char *path,
d759b5
-                       const char *sysfs_dir,
d759b5
                        int unpriv_sgio)
d759b5
 {
d759b5
-    char *sysfs_path = NULL;
d759b5
     char *val = NULL;
d759b5
     int ret = -1;
d759b5
     int rc;
d759b5
 
d759b5
-    if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, sysfs_dir)))
d759b5
-        return -1;
d759b5
-
d759b5
-    if (!virFileExists(sysfs_path)) {
d759b5
+    if (!virFileExists(path)) {
d759b5
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
d759b5
                        _("unpriv_sgio is not supported by this kernel"));
d759b5
         goto cleanup;
d759b5
@@ -1735,38 +1730,32 @@ virSetDeviceUnprivSGIO(const char *path,
d759b5
     if (virAsprintf(&val, "%d", unpriv_sgio) < 0)
d759b5
         goto cleanup;
d759b5
 
d759b5
-    if ((rc = virFileWriteStr(sysfs_path, val, 0)) < 0) {
d759b5
-        virReportSystemError(-rc, _("failed to set %s"), sysfs_path);
d759b5
+    if ((rc = virFileWriteStr(path, val, 0)) < 0) {
d759b5
+        virReportSystemError(-rc, _("failed to set %s"), path);
d759b5
         goto cleanup;
d759b5
     }
d759b5
 
d759b5
     ret = 0;
d759b5
  cleanup:
d759b5
-    VIR_FREE(sysfs_path);
d759b5
     VIR_FREE(val);
d759b5
     return ret;
d759b5
 }
d759b5
 
d759b5
 int
d759b5
 virGetDeviceUnprivSGIO(const char *path,
d759b5
-                       const char *sysfs_dir,
d759b5
                        int *unpriv_sgio)
d759b5
 {
d759b5
-    char *sysfs_path = NULL;
d759b5
     char *buf = NULL;
d759b5
     char *tmp = NULL;
d759b5
     int ret = -1;
d759b5
 
d759b5
-    if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, sysfs_dir)))
d759b5
-        return -1;
d759b5
-
d759b5
-    if (!virFileExists(sysfs_path)) {
d759b5
+    if (!virFileExists(path)) {
d759b5
         virReportError(VIR_ERR_OPERATION_INVALID, "%s",
d759b5
                        _("unpriv_sgio is not supported by this kernel"));
d759b5
         goto cleanup;
d759b5
     }
d759b5
 
d759b5
-    if (virFileReadAll(sysfs_path, 1024, &buf) < 0)
d759b5
+    if (virFileReadAll(path, 1024, &buf) < 0)
d759b5
         goto cleanup;
d759b5
 
d759b5
     if ((tmp = strchr(buf, '\n')))
d759b5
@@ -1774,13 +1763,12 @@ virGetDeviceUnprivSGIO(const char *path,
d759b5
 
d759b5
     if (virStrToLong_i(buf, NULL, 10, unpriv_sgio) < 0) {
d759b5
         virReportError(VIR_ERR_INTERNAL_ERROR,
d759b5
-                       _("failed to parse value of %s"), sysfs_path);
d759b5
+                       _("failed to parse value of %s"), path);
d759b5
         goto cleanup;
d759b5
     }
d759b5
 
d759b5
     ret = 0;
d759b5
  cleanup:
d759b5
-    VIR_FREE(sysfs_path);
d759b5
     VIR_FREE(buf);
d759b5
     return ret;
d759b5
 }
d759b5
diff --git a/src/util/virutil.h b/src/util/virutil.h
d759b5
index abbbb7101e..b0ee8329e2 100644
d759b5
--- a/src/util/virutil.h
d759b5
+++ b/src/util/virutil.h
d759b5
@@ -160,10 +160,8 @@ int virGetDeviceID(const char *path,
d759b5
                    int *maj,
d759b5
                    int *min);
d759b5
 int virSetDeviceUnprivSGIO(const char *path,
d759b5
-                           const char *sysfs_dir,
d759b5
                            int unpriv_sgio);
d759b5
 int virGetDeviceUnprivSGIO(const char *path,
d759b5
-                           const char *sysfs_dir,
d759b5
                            int *unpriv_sgio);
d759b5
 char *virGetUnprivSGIOSysfsPath(const char *path,
d759b5
                                 const char *sysfs_dir);
d759b5
-- 
d759b5
2.23.0
d759b5