Whamcloud - gitweb
LU-13117 libcfs: fix to match right key in cfs_get_environ() 96/37396/2
authorWang Shilong <wshilong@ddn.com>
Wed, 8 Jan 2020 01:45:27 +0000 (09:45 +0800)
committerOleg Drokin <green@whamcloud.com>
Tue, 25 Feb 2020 06:15:04 +0000 (06:15 +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.

Lustre-change: https://review.whamcloud.com/37156
Lustre-commit: 31170f9ceca91684ea66e0b16757881563a8cf26

Test-Parameters: trivial
Change-Id: Ia2b4ccd1f10c89059cecc224d4e2ba8d1d75b825
Signed-off-by: Wang Shilong <wshilong@ddn.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>
Reviewed-on: https://review.whamcloud.com/37396
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
libcfs/libcfs/linux/linux-curproc.c
lustre/tests/sanity.sh

index fee47a2..8e843a2 100644 (file)
@@ -256,9 +256,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 4c8b9a2..283c74d 100755 (executable)
@@ -14781,7 +14781,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"
@@ -14883,7 +14883,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() {