From a9f62388faa08610e855e6c5a59b853b9f17ccd3 Mon Sep 17 00:00:00 2001 From: Wang Shilong Date: Wed, 8 Jan 2020 09:45:27 +0800 Subject: [PATCH] LU-13117 libcfs: fix to match right key in cfs_get_environ() 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 Reviewed-by: Andreas Dilger Reviewed-by: Emoly Liu Reviewed-by: Ben Evans Reviewed-by: Oleg Drokin Reviewed-on: https://review.whamcloud.com/37396 Tested-by: jenkins Tested-by: Maloo --- libcfs/libcfs/linux/linux-curproc.c | 2 ++ lustre/tests/sanity.sh | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/libcfs/libcfs/linux/linux-curproc.c b/libcfs/libcfs/linux/linux-curproc.c index fee47a2..8e843a2 100644 --- a/libcfs/libcfs/linux/linux-curproc.c +++ b/libcfs/libcfs/linux/linux-curproc.c @@ -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; diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 4c8b9a2..283c74d 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -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() { -- 1.8.3.1