[libvirt PATCH 1/7] util: remove virGetUnprivSGIOSysfsPath

Ján Tomko jtomko at redhat.com
Thu Jan 13 17:47:36 UTC 2022


unpriv_sgio was a downstream-only feature in certain RHEL versions.
The libvirt support was merged upstream by mistake.

Remove the function that constructs the sysfs path and assume it
does not exist in all the callers.

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/libvirt_private.syms |  1 -
 src/qemu/qemu_conf.c     | 43 ++----------------
 src/util/virutil.c       | 96 +++++-----------------------------------
 src/util/virutil.h       |  2 -
 4 files changed, 16 insertions(+), 126 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5b76e66e61..932dbf4f72 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3521,7 +3521,6 @@ virGetPassword;
 virGetSelfLastChanged;
 virGetSystemPageSize;
 virGetSystemPageSizeKB;
-virGetUnprivSGIOSysfsPath;
 virGetUserCacheDirectory;
 virGetUserConfigDirectory;
 virGetUserDirectory;
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 6077457ff4..73497ad848 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1484,42 +1484,11 @@ qemuGetSharedDeviceKey(const char *device_path)
  *      being used and in the future the hostdev information.
  */
 static int
-qemuCheckUnprivSGIO(GHashTable *sharedDevices,
-                    const char *device_path,
-                    int sgio)
+qemuCheckUnprivSGIO(GHashTable *sharedDevices G_GNUC_UNUSED,
+                    const char *device_path G_GNUC_UNUSED,
+                    int sgio G_GNUC_UNUSED)
 {
-    g_autofree char *sysfs_path = NULL;
-    g_autofree char *key = NULL;
-    int val;
-
-    if (!(sysfs_path = virGetUnprivSGIOSysfsPath(device_path, NULL)))
-        return -1;
-
     /* It can't be conflict if unpriv_sgio is not supported by kernel. */
-    if (!virFileExists(sysfs_path))
-        return 0;
-
-    if (!(key = qemuGetSharedDeviceKey(device_path)))
-        return -1;
-
-    /* It can't be conflict if no other domain is sharing it. */
-    if (!(virHashLookup(sharedDevices, key)))
-        return 0;
-
-    if (virGetDeviceUnprivSGIO(device_path, NULL, &val) < 0)
-        return -1;
-
-    /* Error message on failure needs to be handled in caller
-     * since there is more specific knowledge of device
-     */
-    if (!((val == 0 &&
-           (sgio == VIR_DOMAIN_DEVICE_SGIO_FILTERED ||
-            sgio == VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) ||
-          (val == 1 &&
-           sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))) {
-        return -2;
-    }
-
     return 0;
 }
 
@@ -1840,7 +1809,6 @@ qemuSetUnprivSGIO(virDomainDeviceDef *dev)
 {
     virDomainDiskDef *disk = NULL;
     virDomainHostdevDef *hostdev = NULL;
-    g_autofree char *sysfs_path = NULL;
     const char *path = NULL;
     int val = -1;
 
@@ -1873,9 +1841,6 @@ qemuSetUnprivSGIO(virDomainDeviceDef *dev)
         return 0;
     }
 
-    if (!(sysfs_path = virGetUnprivSGIOSysfsPath(path, NULL)))
-        return -1;
-
     /* By default, filter the SG_IO commands, i.e. set unpriv_sgio to 0.  */
     val = (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED);
 
@@ -1883,7 +1848,7 @@ qemuSetUnprivSGIO(virDomainDeviceDef *dev)
      * whitelist is enabled.  But if requesting unfiltered access, always call
      * virSetDeviceUnprivSGIO, to report an error for unsupported unpriv_sgio.
      */
-    if (virFileExists(sysfs_path) || val == 1) {
+    if (val == 1) {
         int curr_val;
 
         if (virGetDeviceUnprivSGIO(path, NULL, &curr_val) < 0)
diff --git a/src/util/virutil.c b/src/util/virutil.c
index e04f1343d8..0acdc052c3 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -1354,96 +1354,24 @@ virGetDeviceID(const char *path G_GNUC_UNUSED,
 }
 #endif
 
-#define SYSFS_DEV_BLOCK_PATH "/sys/dev/block"
-
-char *
-virGetUnprivSGIOSysfsPath(const char *path,
-                          const char *sysfs_dir)
-{
-    int maj, min;
-    int rc;
-
-    if ((rc = virGetDeviceID(path, &maj, &min)) < 0) {
-        virReportSystemError(-rc,
-                             _("Unable to get device ID '%s'"),
-                             path);
-        return NULL;
-    }
-
-    return g_strdup_printf("%s/%d:%d/queue/unpriv_sgio",
-                           sysfs_dir ? sysfs_dir : SYSFS_DEV_BLOCK_PATH, maj,
-                           min);
-}
-
 int
-virSetDeviceUnprivSGIO(const char *path,
-                       const char *sysfs_dir,
-                       int unpriv_sgio)
+virSetDeviceUnprivSGIO(const char *path G_GNUC_UNUSED,
+                       const char *sysfs_dir G_GNUC_UNUSED,
+                       int unpriv_sgio G_GNUC_UNUSED)
 {
-    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)) {
-        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                       _("unpriv_sgio is not supported by this kernel"));
-        goto cleanup;
-    }
-
-    val = g_strdup_printf("%d", unpriv_sgio);
-
-    if ((rc = virFileWriteStr(sysfs_path, val, 0)) < 0) {
-        virReportSystemError(-rc, _("failed to set %s"), sysfs_path);
-        goto cleanup;
-    }
-
-    ret = 0;
- cleanup:
-    VIR_FREE(sysfs_path);
-    VIR_FREE(val);
-    return ret;
+    virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                   _("unpriv_sgio is not supported by this kernel"));
+    return -1;
 }
 
 int
-virGetDeviceUnprivSGIO(const char *path,
-                       const char *sysfs_dir,
-                       int *unpriv_sgio)
+virGetDeviceUnprivSGIO(const char *path G_GNUC_UNUSED,
+                       const char *sysfs_dir G_GNUC_UNUSED,
+                       int *unpriv_sgio G_GNUC_UNUSED)
 {
-    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)) {
-        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                       _("unpriv_sgio is not supported by this kernel"));
-        goto cleanup;
-    }
-
-    if (virFileReadAll(sysfs_path, 1024, &buf) < 0)
-        goto cleanup;
-
-    if ((tmp = strchr(buf, '\n')))
-        *tmp = '\0';
-
-    if (virStrToLong_i(buf, NULL, 10, unpriv_sgio) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("failed to parse value of %s"), sysfs_path);
-        goto cleanup;
-    }
-
-    ret = 0;
- cleanup:
-    VIR_FREE(sysfs_path);
-    VIR_FREE(buf);
-    return ret;
+    virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                   _("unpriv_sgio is not supported by this kernel"));
+    return -1;
 }
 
 
diff --git a/src/util/virutil.h b/src/util/virutil.h
index 854b494890..bd2c69bfaa 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -125,8 +125,6 @@ int virSetDeviceUnprivSGIO(const char *path,
 int virGetDeviceUnprivSGIO(const char *path,
                            const char *sysfs_dir,
                            int *unpriv_sgio);
-char *virGetUnprivSGIOSysfsPath(const char *path,
-                                const char *sysfs_dir);
 
 int virParseOwnershipIds(const char *label, uid_t *uidPtr, gid_t *gidPtr);
 
-- 
2.31.1




More information about the libvir-list mailing list