Whamcloud - gitweb
LU-9859 libcfs: always range-check libcfs_debug_mb setting. 28/37828/4
authorMr NeilBrown <neilb@suse.de>
Mon, 9 Mar 2020 01:35:57 +0000 (21:35 -0400)
committerOleg Drokin <green@whamcloud.com>
Tue, 24 Mar 2020 05:21:03 +0000 (05:21 +0000)
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 <neilb@suse.de>
Reviewed-on: https://review.whamcloud.com/37828
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Yang Sheng <ys@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/libcfs/debug.c
libcfs/libcfs/tracefile.c

index 99518ab..e5bff2e 100644 (file)
@@ -65,21 +65,15 @@ static int libcfs_param_debug_mb_set(const char *val,
        if (rc < 0)
                return rc;
 
        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;
 }
 
 /*
 }
 
 /*
index 7aba3ac..50d21d6 100644 (file)
@@ -880,7 +880,7 @@ int cfs_trace_set_debug_mb(int mb)
 
        up_write(&cfs_tracefile_sem);
 
 
        up_write(&cfs_tracefile_sem);
 
-       return 0;
+       return mb;
 }
 
 int cfs_trace_get_debug_mb(void)
 }
 
 int cfs_trace_get_debug_mb(void)