From 72479a52be5f77f601d8234d957f5d6176edf6e8 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Wed, 24 Jul 2019 23:29:26 -0600 Subject: [PATCH] LU-9341 utils: fix lfs find for composite files Running "lfs getstripe -c" on a composite file returns the stripe count of the last initialized component, but "lfs find -c N" does not find this file because it was adding the total stripe_count of all components. "lfs find" should also check the stripe_count of the last initialized component, as described in the man page. Also use the last component stripe_size instead of any component. Add a test case for the correct usage. Fixes: 5a76aee24476 ("LU-8998 lfs: user space tools for PFL") Signed-off-by: Andreas Dilger Change-Id: I1f0097aa002b29febcbf183cab02519b202540e5 Reviewed-on: https://review.whamcloud.com/35611 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Jian Yu Reviewed-by: Stephan Thiell Reviewed-by: Patrick Farrell Reviewed-by: Oleg Drokin --- lustre/doc/lfs-find.1 | 2 +- lustre/tests/sanity-pfl.sh | 11 ++++++++++- lustre/utils/liblustreapi.c | 22 +++++++++++++--------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/lustre/doc/lfs-find.1 b/lustre/doc/lfs-find.1 index 92f879b..cfba95d 100644 --- a/lustre/doc/lfs-find.1 +++ b/lustre/doc/lfs-find.1 @@ -245,7 +245,7 @@ are multiple OSTs that are being replaced. Stripe size is \fIn\fR bytes, or \fBK\fRibi-, \fBM\fRebi-, \fBG\fRibi-, \fBT\fRebi-, \fBP\fRebi-, or \fBE\fRbi-abytes if a suffix is given. For composite files, this matches the stripe -size of any non-extension component. +size of the last initialized non-extension component. .TP .BR --extension-size | --ext-size | -z Extension size is \fIn\fR bytes, or \fBK\fRibi-, \fBM\fRebi-, diff --git a/lustre/tests/sanity-pfl.sh b/lustre/tests/sanity-pfl.sh index 9c71449..517bc1d 100644 --- a/lustre/tests/sanity-pfl.sh +++ b/lustre/tests/sanity-pfl.sh @@ -674,7 +674,7 @@ test_15() { $LFS setstripe -E 1M -S 1M -E 10M -E eof $parent/f1 || error "create f1" $LFS setstripe -E 4M -E 20M -E eof $parent/f2 || error "create f2" test_mkdir $parent/subdir - $LFS setstripe -E 6M -S 1M -E 30M -E eof $parent/subdir || + $LFS setstripe -E 6M -S 1M -c1 -E 30M -c4 -E eof -c -1 $parent/subdir || error "setstripe to subdir" $LFS setstripe -E 8M -E eof $parent/subdir/f3 || error "create f3" $LFS setstripe -c 1 $parent/subdir/f4 || error "create f4" @@ -724,6 +724,15 @@ test_15() { found=$($LFS find $ext_opts ! $cnt_opts $flg_opts $parent | wc -l) [ $found -eq 2 ] || error "start-1M, end+5M, !count+2, flag=init, $found != 2" + + # check last component stripe count + if [ $OSTCOUNT -gt 1 ]; then + touch $parent/subdir/f5 + $TRUNCATE $parent/subdir/f5 $((32*1024*1024)) + found=$($LFS find $parent/subdir -c $OSTCOUNT) + [[ "$found" == "$parent/subdir/f5" ]] || + error "got '$found' with stripe_count=$OSTCOUNT, not f5" + fi } run_test 15 "Verify component options for lfs find" diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index c25456d..600e732 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -4024,6 +4024,7 @@ static int find_check_stripe_size(struct find_param *param) { struct lov_comp_md_v1 *comp_v1 = NULL; struct lov_user_md_v1 *v1 = ¶m->fp_lmd->lmd_lmm; + __u32 stripe_size = 0; int ret, i, count = 1; if (v1->lmm_magic == LOV_USER_MAGIC_FOREIGN) @@ -4044,17 +4045,17 @@ static int find_check_stripe_size(struct find_param *param) ent = &comp_v1->lcm_entries[i]; if (ent->lcme_flags & LCME_FL_EXTENSION) continue; + if (!(ent->lcme_flags & LCME_FL_INIT)) + continue; } - - ret = find_value_cmp(v1->lmm_stripe_size, param->fp_stripe_size, - param->fp_stripe_size_sign, - param->fp_exclude_stripe_size, - param->fp_stripe_size_units, 0); - /* If any stripe_size matches */ - if (ret != -1) - break; + stripe_size = v1->lmm_stripe_size; } + ret = find_value_cmp(stripe_size, param->fp_stripe_size, + param->fp_stripe_size_sign, + param->fp_exclude_stripe_size, + param->fp_stripe_size_units, 0); + return ret; } @@ -4112,10 +4113,13 @@ static __u32 find_get_stripe_count(struct find_param *param) v1 = lov_comp_entry(comp_v1, i); ent = &comp_v1->lcm_entries[i]; + if (!(ent->lcme_flags & LCME_FL_INIT)) + continue; + if (ent->lcme_flags & LCME_FL_EXTENSION) continue; } - stripe_count += v1->lmm_stripe_count; + stripe_count = v1->lmm_stripe_count; } return stripe_count; -- 1.8.3.1