From 50075df7f81e0f9986db81918b32ec469619eb13 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Mon, 3 May 2021 19:25:23 -0600 Subject: [PATCH] LU-13440 utils: fix handling of lsa_stripe_off -1 Use LMV_OFFSET_DEFAULT instead of "-1" for parsing lfs_setdirstripe() since parse_targets() will return "(__u32)-1" to the caller for the stripe index, but lsa_stripe_off is a signed long long so it is interpreted as 4294967295. This causes the parsing to fail when "lfs setdirstripe -i -1 --max-inherit-rr 1" is used. Update sanity test_413a/413c to also specify "-i -1" to verify this. Lustre-change: https://review.whamcloud.com/43530 Lustre-commit: TBD (from 792fa045a1975a1a18af0d72470134e5bf997d6a) Fixes: 01d34a6b3b2e ("LU-13440 lmv: add default LMV inherit depth") Test-Parameters: trivial Signed-off-by: Andreas Dilger Change-Id: Ic934f859173155b1b2df56fcd315c8da633ebbe5 Reviewed-on: https://review.whamcloud.com/43524 Tested-by: jenkins Tested-by: Maloo --- lustre/tests/sanity.sh | 25 ++++++++++++------------- lustre/utils/lfs.c | 12 ++++++------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 88ecd09..fc56e10 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -23107,7 +23107,7 @@ test_qos_mkdir() { local test_mkdir_rr=true echo "dirstripe: '$($LFS getdirstripe $testdir)'" - getfattr -d -m dmv $testdir | grep dmv + getfattr -d -m dmv -e hex $testdir | grep dmv if (( $? == 0 && $MDS1_VERSION >= $(version_code 2.14.0) )); then echo "defstripe: '$($LFS getdirstripe -D $testdir)'" (( $($LFS getdirstripe -D --max-inherit-rr $testdir) == 0 )) && @@ -23125,8 +23125,7 @@ test_qos_mkdir() { done for (( i = 0; i < $MDSCOUNT; i++ )); do - count=$($LFS getdirstripe -i $testdir/* | - grep "^$i$" | wc -l) + count=$($LFS getdirstripe -i $testdir/* | grep -c "^$i$") echo "$count directories created on MDT$i" if $test_mkdir_rr; then (( $count == 100 )) || @@ -23141,7 +23140,7 @@ test_qos_mkdir() { if $test_mkdir_rr && [ $stripe_count -gt 1 ]; then count=$($LFS getdirstripe $testdir/* | - grep -P "^\s+$i\t" | wc -l) + grep -c -P "^\s+$i\t") echo "$count stripes created on MDT$i" # deviation should < 5% of average (( $count >= 95 * $stripe_count && @@ -23253,19 +23252,19 @@ test_qos_mkdir() { fi done - max=$($LFS getdirstripe -i $testdir/* | grep ^$max_index$ | wc -l) - min=$($LFS getdirstripe -i $testdir/* | grep ^$min_index$ | wc -l) + max=$($LFS getdirstripe -i $testdir/* | grep -c "^$max_index$") + min=$($LFS getdirstripe -i $testdir/* | grep -c "^$min_index$") # D-value should > 10% of averge - (( $max - $min < 10 )) && - error "subdirs shouldn't be evenly distributed" + (( $max - $min >= 10 )) || + error "subdirs shouldn't be evenly distributed: $((max - min))" # ditto if [ $stripe_count -gt 1 ]; then max=$($LFS getdirstripe $testdir/* | - grep -P "^\s+$max_index\t" | wc -l) + grep -c -P "^\s+$max_index\t") min=$($LFS getdirstripe $testdir/* | - grep -P "^\s+$min_index\t" | wc -l) + grep -c -P "^\s+$min_index\t") (( $max - $min >= 10 * $stripe_count )) || error "stripes shouldn't be evenly distributed" fi @@ -23284,7 +23283,7 @@ test_413a() { mkdir $DIR/$tdir-s$stripe_count || error "mkdir failed" mkdir $DIR/$tdir-s$stripe_count/rr || error "mkdir failed" mkdir $DIR/$tdir-s$stripe_count/qos || error "mkdir failed" - test_qos_mkdir "$LFS mkdir -c $stripe_count" $stripe_count + test_qos_mkdir "$LFS mkdir -i -1 -c $stripe_count" $stripe_count done } run_test 413a "QoS mkdir with 'lfs mkdir -i -1'" @@ -23331,7 +23330,7 @@ test_413c() { # default max_inherit is -1, default max_inherit_rr is 0 $LFS setdirstripe -D -c 1 $testdir/rr || error "setdirstripe rr failed" - $LFS setdirstripe -D -c 1 -X 2 --max-inherit-rr 1 $testdir/qos || + $LFS setdirstripe -D -c 1 -i -1 -X 2 --max-inherit-rr 1 $testdir/qos || error "setdirstripe qos failed" test_qos_mkdir "mkdir" 1 @@ -23349,7 +23348,7 @@ test_413c() { (( $inherit_rr == 0 )) || error "qos/level1 inherit-rr $inherit_rr !=0" mkdir -v $testdir/qos/level1/level2 || error "mkdir level2 failed" - getfattr -d -m dmv $testdir/qos/level1/level2 | grep dmv && + getfattr -d -m dmv -e hex $testdir/qos/level1/level2 | grep dmv && error "level2 shouldn't have default LMV" || true } run_test 413c "mkdir with default LMV max inherit rr" diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 28c6aa1..695c282 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -6342,7 +6342,7 @@ static int lfs_setdirstripe(int argc, char **argv) if (!delete && lsa.lsa_stripe_off == LLAPI_LAYOUT_DEFAULT && lsa.lsa_stripe_count == LLAPI_LAYOUT_DEFAULT && !foreign_mode) { /* if no parameters set, create directory on least-used MDTs */ - lsa.lsa_stripe_off = -1; + lsa.lsa_stripe_off = LMV_OFFSET_DEFAULT; lsa.lsa_stripe_count = 1; } @@ -6368,10 +6368,10 @@ static int lfs_setdirstripe(int argc, char **argv) if (max_inherit_rr != LAYOUT_INHERIT_UNSET && lsa.lsa_stripe_off != LLAPI_LAYOUT_DEFAULT && - lsa.lsa_stripe_off != -1) { + lsa.lsa_stripe_off != LMV_OFFSET_DEFAULT) { fprintf(stderr, - "%s %s: max-inherit-rr is meaningless if stripe offset != -1\n", - progname, argv[0]); + "%s %s: max-inherit-rr is meaningless if stripe offset %lld != -1\n", + progname, argv[0], lsa.lsa_stripe_off); return CMD_HELP; } @@ -6409,14 +6409,14 @@ static int lfs_setdirstripe(int argc, char **argv) } /* if "lfs setdirstripe -D -i -1" is used, assume 1-stripe directory */ - if (default_stripe && lsa.lsa_stripe_off == -1 && + if (default_stripe && lsa.lsa_stripe_off == LMV_OFFSET_DEFAULT && (lsa.lsa_stripe_count == LLAPI_LAYOUT_DEFAULT || lsa.lsa_stripe_count == 0)) lsa.lsa_stripe_count = 1; if (lsa.lsa_stripe_count != LLAPI_LAYOUT_DEFAULT) param->lsp_stripe_count = lsa.lsa_stripe_count; if (lsa.lsa_stripe_off == LLAPI_LAYOUT_DEFAULT) - param->lsp_stripe_offset = -1; + param->lsp_stripe_offset = LMV_OFFSET_DEFAULT; else param->lsp_stripe_offset = lsa.lsa_stripe_off; if (lsa.lsa_pattern != LLAPI_LAYOUT_RAID0) -- 1.8.3.1