Blob Blame History Raw
From 65f4ff0e2c9a968b7ec65c8d751d4055cc212628 Mon Sep 17 00:00:00 2001
Message-Id: <65f4ff0e2c9a968b7ec65c8d751d4055cc212628@dist-git>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Thu, 10 Oct 2019 14:20:58 +0200
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=1754241

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Message-Id: <1f6fa49bd2fec4e3b144cb8c1a27a9d0456c9431.1570709916.git.mprivozn@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 fb2a95041a..fd70df120b 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -1715,18 +1715,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;
@@ -1735,38 +1730,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')))
@@ -1774,13 +1763,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 abbbb7101e..b0ee8329e2 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.23.0