render / rpms / libvirt

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