Whamcloud - gitweb
LU-13117 libcfs: fix to match right key in cfs_get_environ() 56/37156/4
authorWang Shilong <wshilong@ddn.com>
Wed, 8 Jan 2020 01:45:27 +0000 (09:45 +0800)
committerOleg Drokin <green@whamcloud.com>
Thu, 23 Jan 2020 05:31:55 +0000 (05:31 +0000)
It does the memcmp() to match the environment variable
with the desired key, then accounts for the "=" when
calculating length. But it fails to check that the next
character is actually an equals sign. In the case of
any key which is also the prefix to some other variable

Also add debug information for debugging similar issue
in the future.

Test-Parameters: trivial
Change-Id: Ia2b4ccd1f10c89059cecc224d4e2ba8d1d75b825
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Reviewed-on: https://review.whamcloud.com/37156
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Emoly Liu <emoly@whamcloud.com>
Reviewed-by: Ben Evans <bevans@cray.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/libcfs/linux/linux-curproc.c
lustre/tests/sanity.sh

index 70510c9..be449ad 100644 (file)
@@ -233,9 +233,11 @@ int cfs_get_environ(const char *key, char *value, int *val_len)
 
                        entry = env_start;
                        entry_len = env_end - env_start;
+                       CDEBUG(D_INFO, "key: %s, entry: %s\n", key, entry);
 
                        /* Key length + length of '=' */
                        if (entry_len > key_len + 1 &&
+                           entry[key_len] == '='  &&
                            !memcmp(entry, key, key_len)) {
                                entry += key_len + 1;
                                entry_len -= key_len + 1;
index c3aa385..22af527 100644 (file)
@@ -15539,7 +15539,7 @@ jobstats_set() {
                "$FSNAME.sys.jobid_var" $new_jobenv
 }
 
-test_205() { # Job stats
+test_205a() { # Job stats
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
        [[ $MDS1_VERSION -ge $(version_code 2.7.1) ]] ||
                skip "Need MDS version with at least 2.7.1"
@@ -15641,7 +15641,18 @@ test_205() { # Job stats
 
        verify_jobstats "touch $DIR/$tfile" $SINGLEMDS
 }
-run_test 205 "Verify job stats"
+run_test 205a "Verify job stats"
+
+# LU-13117
+test_205b() {
+       $LCTL set_param jobid_var=USER jobid_name="%e.%u"
+       env -i USERTESTJOBSTATS=foolish touch $DIR/$tfile.1
+       do_facet $SINGLEMDS $LCTL get_param mdt.*.job_stats |
+               grep job_id: | grep foolish &&
+                       error "Unexpected jobid found"
+       true
+}
+run_test 205b "Verify job stats jobid parsing"
 
 # LU-1480, LU-1773 and LU-1657
 test_206() {