From 8b78a3ffb5220330f41b4fa8576a05c4e017cfb1 Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Sun, 8 Mar 2020 21:35:57 -0400 Subject: [PATCH 1/1] LU-9859 libcfs: always range-check libcfs_debug_mb setting. When the libcfs_debug_mb module parameter is set at module-load time it isn't range-checked. When it is set via sysfs it is. This inconsistency makes the code harder to follow. It is quite safe to call cfs_trace_set_debug_mb() and cfs_trace_get_debug_mb() before the module is initialized as cfs_tcd_for_each() does nothing before initializtion. So change cfs_trace_set_debug_mb() - which does range checking - to returned the ranged checked number (it currently always returns zero) and use that as the new value, unless cfs_trace_get_debug_mb() now returns a non-zero value. Linux-commit: 205b154f3bd6fa3e95ceca8bba8d00122bb8fb04 Change-Id: I495097bbae138625e54a012bf06c96e62d206228 Signed-off-by: Mr NeilBrown Reviewed-on: https://review.whamcloud.com/37828 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Yang Sheng Reviewed-by: Oleg Drokin --- libcfs/libcfs/debug.c | 20 +++++++------------- libcfs/libcfs/tracefile.c | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/libcfs/libcfs/debug.c b/libcfs/libcfs/debug.c index 99518ab..e5bff2e 100644 --- a/libcfs/libcfs/debug.c +++ b/libcfs/libcfs/debug.c @@ -65,21 +65,15 @@ static int libcfs_param_debug_mb_set(const char *val, if (rc < 0) return rc; -/* - * RHEL6 does not support any kind of locking so we have to provide - * our own - */ - if (!*((unsigned int *)kp->arg)) { - *((unsigned int *)kp->arg) = num; - return 0; - } + num = cfs_trace_set_debug_mb(num); - rc = cfs_trace_set_debug_mb(num); - - if (!rc) - *((unsigned int *)kp->arg) = cfs_trace_get_debug_mb(); + *((unsigned int *)kp->arg) = num; + num = cfs_trace_get_debug_mb(); + if (num) + /* This value is more precise */ + *((unsigned int *)kp->arg) = num; - return rc; + return 0; } /* diff --git a/libcfs/libcfs/tracefile.c b/libcfs/libcfs/tracefile.c index 7aba3ac..50d21d6 100644 --- a/libcfs/libcfs/tracefile.c +++ b/libcfs/libcfs/tracefile.c @@ -880,7 +880,7 @@ int cfs_trace_set_debug_mb(int mb) up_write(&cfs_tracefile_sem); - return 0; + return mb; } int cfs_trace_get_debug_mb(void) -- 1.8.3.1