From 94441071dbadbde56442e5e2560c642cc2793274 Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Sat, 27 Jun 2020 00:04:42 -0600 Subject: [PATCH] LU-13721 utils: fix 'lfs find --pool' for PFL files Fix "lfs find --pool" to check the lov_user_md_v3 for the specified pool name in find_check_pool() for composite files (PFL or FLR). The v3 pointer was initialized from the main layout xattr, but was not being refreshed for each of the components in the file. Add a test case for "lfs find --pool" usage. Fixes: 5a76aee24476 ("LU-8998 lfs: user space tools for PFL") Signed-off-by: Andreas Dilger Change-Id: I6b6f21fd2fdf58f46972704cb6fb425a943ebbe5 Reviewed-on: https://review.whamcloud.com/39196 Tested-by: jenkins Reviewed-by: Jian Yu Reviewed-by: Bobi Jam Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/tests/sanity.sh | 13 +++++++++---- lustre/utils/liblustreapi.c | 29 ++++++++++++++++++----------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 414d95e8..34c8753 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -2612,6 +2612,7 @@ test_27G() { #LU-10629 local ostrange="0 0 1" test_mkdir $DIR/$tdir + touch $DIR/$tdir/$tfile.nopool pool_add $POOL || error "pool_add failed" pool_add_targets $POOL $ostrange || error "pool_add_targets failed" $LFS setstripe -p $POOL $DIR/$tdir @@ -2619,14 +2620,18 @@ test_27G() { #LU-10629 local pool=$($LFS getstripe -p $DIR/$tdir) [ "$pool" = "$POOL" ] || error "Striping failed got '$pool' not '$POOL'" + touch $DIR/$tdir/$tfile.default + $LFS setstripe -E 1M --pool $POOL -c 1 -E eof -c 1 $DIR/$tdir/$tfile.pfl + $LFS find $DIR/$tdir -type f --pool $POOL + local found=$($LFS find $DIR/$tdir -type f --pool $POOL | wc -l) + [[ "$found" == "2" ]] || + error "found $found != 2 files in '$DIR/$tdir' in '$POOL'" $LFS setstripe -d $DIR/$tdir - pool=$($LFS getstripe -p $DIR/$tdir) + pool=$($LFS getstripe -p -d $DIR/$tdir) - rmdir $DIR/$tdir - - [ -z "$pool" ] || error "'$pool' is not empty" + [[ "$pool" != "$POOL" ]] || error "$DIR/$tdir is still '$pool'" } run_test 27G "Clear OST pool from stripe" diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 92cb3d3..dbf46bb 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -4422,38 +4422,45 @@ static int find_check_foreign(struct find_param *param) static int find_check_pool(struct find_param *param) { struct lov_comp_md_v1 *comp_v1 = NULL; - struct lov_user_md_v1 *v1 = ¶m->fp_lmd->lmd_lmm; - struct lov_user_md_v3 *v3 = (void *)v1; + struct lov_user_md_v3 *v3 = (void *)¶m->fp_lmd->lmd_lmm; int i, count = 1; bool found = false; - if (v1->lmm_magic == LOV_USER_MAGIC_COMP_V1) { - comp_v1 = (struct lov_comp_md_v1 *)v1; + if (v3->lmm_magic == LOV_USER_MAGIC_COMP_V1) { + comp_v1 = (struct lov_comp_md_v1 *)v3; count = comp_v1->lcm_entry_count; /* empty requested pool is taken as no pool search */ - if (count == 0 && param->fp_poolname[0] == '\0') + if (count == 0 && param->fp_poolname[0] == '\0') { found = true; + goto found; + } } for (i = 0; i < count; i++) { - if (comp_v1 != NULL) - v1 = lov_comp_entry(comp_v1, i); + if (comp_v1 != NULL) { + if (!(comp_v1->lcm_entries[i].lcme_flags & + LCME_FL_INIT)) + continue; - if (v1->lmm_magic == LOV_USER_MAGIC_FOREIGN) + v3 = (void *)lov_comp_entry(comp_v1, i); + } + + if (v3->lmm_magic == LOV_USER_MAGIC_FOREIGN) continue; - if (((v1->lmm_magic == LOV_USER_MAGIC_V1) && + if (((v3->lmm_magic == LOV_USER_MAGIC_V1) && (param->fp_poolname[0] == '\0')) || - ((v1->lmm_magic == LOV_USER_MAGIC_V3) && + ((v3->lmm_magic == LOV_USER_MAGIC_V3) && (strncmp(v3->lmm_pool_name, param->fp_poolname, LOV_MAXPOOLNAME) == 0)) || - ((v1->lmm_magic == LOV_USER_MAGIC_V3) && + ((v3->lmm_magic == LOV_USER_MAGIC_V3) && (strcmp(param->fp_poolname, "*") == 0))) { found = true; break; } } +found: if ((found && !param->fp_exclude_pool) || (!found && param->fp_exclude_pool)) return 1; -- 1.8.3.1