From 31170f9ceca91684ea66e0b16757881563a8cf26 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. Test-Parameters: trivial Change-Id: Ia2b4ccd1f10c89059cecc224d4e2ba8d1d75b825 Signed-off-by: Wang Shilong Reviewed-on: https://review.whamcloud.com/37156 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Emoly Liu Reviewed-by: Ben Evans Reviewed-by: Oleg Drokin --- 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 70510c9..be449ad 100644 --- a/libcfs/libcfs/linux/linux-curproc.c +++ b/libcfs/libcfs/linux/linux-curproc.c @@ -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; diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index c3aa385..22af527 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -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() { -- 1.8.3.1