Whamcloud - gitweb
LU-13721 utils: fix 'lfs find --pool' for PFL files 96/39196/3
authorAndreas Dilger <adilger@whamcloud.com>
Sat, 27 Jun 2020 06:04:42 +0000 (00:04 -0600)
committerOleg Drokin <green@whamcloud.com>
Sat, 4 Jul 2020 03:01:20 +0000 (03:01 +0000)
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 <adilger@whamcloud.com>
Change-Id: I6b6f21fd2fdf58f46972704cb6fb425a943ebbe5
Reviewed-on: https://review.whamcloud.com/39196
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Bobi Jam <bobijam@hotmail.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/sanity.sh
lustre/utils/liblustreapi.c

index 414d95e..34c8753 100755 (executable)
@@ -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"
 
index 92cb3d3..dbf46bb 100644 (file)
@@ -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 = &param->fp_lmd->lmd_lmm;
-       struct lov_user_md_v3 *v3 = (void *)v1;
+       struct lov_user_md_v3 *v3 = (void *)&param->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;