From f322018c2324f8014f58ae76aa6d31bf51c29ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Thu, 13 Jan 2022 13:09:31 +0100 Subject: [PATCH] util: remove virGetUnprivSGIOSysfsPath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit unpriv_sgio was a downstream-only feature in RHEL 6-8. 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 Reviewed-by: Andrea Bolognani --- src/libvirt_private.syms | 1 - src/qemu/qemu_conf.c | 43 ++---------------- src/util/virutil.c | 98 ++++++---------------------------------- src/util/virutil.h | 2 - 4 files changed, 17 insertions(+), 127 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 48235c3461..e2394318b3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3519,7 +3519,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 +virSetDeviceUnprivSGIO(const char *path G_GNUC_UNUSED, + const char *sysfs_dir G_GNUC_UNUSED, + int unpriv_sgio G_GNUC_UNUSED) { - 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); + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("unpriv_sgio is not supported by this kernel")); + return -1; } int -virSetDeviceUnprivSGIO(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 *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; -} - -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)) { - 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);