Whamcloud - gitweb
LU-15200 llite: "lfs getdirstripe -D" shows inherit layout 70/45570/7
authorLai Siyao <lai.siyao@whamcloud.com>
Sun, 7 Nov 2021 05:15:56 +0000 (01:15 -0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 26 Jan 2022 05:15:52 +0000 (05:15 +0000)
Once system-wide default LMV is set, "lfs getdirstripe -D subdir"
should show inherited layout from it.

Add sanity 413e.

Signed-off-by: Lai Siyao <lai.siyao@whamcloud.com>
Change-Id: If7354cb4093c58f6d56a6a4d449fb69a9deec7cc
Reviewed-on: https://review.whamcloud.com/45570
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/llite/dir.c
lustre/tests/sanity.sh
lustre/utils/liblustreapi.c

index ae83d1b..36edab3 100644 (file)
@@ -794,7 +794,7 @@ int ll_dir_getstripe_default(struct inode *inode, void **plmm, int *plmm_size,
        rc = ll_dir_get_default_layout(inode, (void **)&lmm, &lmm_size,
                                       &req, valid, 0);
        if (rc == -ENODATA && !fid_is_root(ll_inode2fid(inode)) &&
-           !(valid & (OBD_MD_MEA|OBD_MD_DEFAULT_MEA)) && root_request != NULL){
+           !(valid & OBD_MD_MEA) && root_request != NULL) {
                int rc2 = ll_dir_get_default_layout(inode, (void **)&lmm,
                                                    &lmm_size, &root_req, valid,
                                                    GET_DEFAULT_LAYOUT_ROOT);
@@ -1627,6 +1627,41 @@ out:
                        if (lmmsize > sizeof(*ulmv))
                                GOTO(finish_req, rc = -EINVAL);
 
+                       if (root_request != NULL) {
+                               struct lmv_user_md *lum;
+                               struct ll_inode_info *lli;
+
+                               lum = (struct lmv_user_md *)lmm;
+                               lli = ll_i2info(inode);
+                               if (lum->lum_max_inherit == LMV_INHERIT_NONE ||
+                                   (lum->lum_max_inherit > 0 &&
+                                    lum->lum_max_inherit < lli->lli_dir_depth))
+                                       GOTO(finish_req, rc = -ENODATA);
+
+                               if (lum->lum_max_inherit ==
+                                   lli->lli_dir_depth) {
+                                       lum->lum_max_inherit = LMV_INHERIT_NONE;
+                                       lum->lum_max_inherit_rr =
+                                               LMV_INHERIT_RR_NONE;
+                                       goto out_copy;
+                               }
+                               if (lum->lum_max_inherit > lli->lli_dir_depth &&
+                                   lum->lum_max_inherit <= LMV_INHERIT_MAX)
+                                       lum->lum_max_inherit -=
+                                               lli->lli_dir_depth;
+
+                               if (lum->lum_max_inherit_rr >
+                                       lli->lli_dir_depth &&
+                                   lum->lum_max_inherit_rr <=
+                                       LMV_INHERIT_RR_MAX)
+                                       lum->lum_max_inherit_rr -=
+                                               lli->lli_dir_depth;
+                               else if (lum->lum_max_inherit_rr ==
+                                               lli->lli_dir_depth)
+                                       lum->lum_max_inherit_rr =
+                                               LMV_INHERIT_RR_NONE;
+                       }
+out_copy:
                        if (copy_to_user(ulmv, lmm, lmmsize))
                                GOTO(finish_req, rc = -EFAULT);
 
index 6b93dc3..c9df3fd 100755 (executable)
@@ -25752,6 +25752,46 @@ test_413e() {
 }
 run_test 413e "check default max-inherit value"
 
+test_413f() {
+       (( MDSCOUNT >= 2 )) || skip "We need at least 2 MDTs for this test"
+
+       (( MDS1_VERSION >= $(version_code 2.14.55) )) ||
+               skip "Need server version at least 2.14.55"
+
+       getfattr -d -m trusted.dmv --absolute-names $DIR > $TMP/dmv.ea ||
+               error "dump $DIR default LMV failed"
+       stack_trap "setfattr --restore=$TMP/dmv.ea"
+
+       $LFS setdirstripe -D -i -1 -c 1 -X 3 --max-inherit-rr 3 $DIR ||
+               error "set $DIR default LMV failed"
+
+       local testdir=$DIR/$tdir
+
+       local count
+       local inherit
+       local inherit_rr
+
+       for i in $(seq 3); do
+               mkdir $testdir || error "mkdir $testdir failed"
+               count=$($LFS getdirstripe -D -c $testdir)
+               (( count == 1 )) ||
+                       error "$testdir default LMV count mismatch $count != 1"
+               inherit=$($LFS getdirstripe -D -X $testdir)
+               (( inherit == 3 - i )) ||
+                       error "$testdir default LMV max-inherit $inherit != $((3 - i))"
+               inherit_rr=$($LFS getdirstripe -D --max-inherit-rr $testdir)
+               (( inherit_rr == 3 - i )) ||
+                       error "$testdir default LMV max-inherit-rr $inherit_rr != $((3 - i))"
+               testdir=$testdir/sub
+       done
+
+       mkdir $testdir || error "mkdir $testdir failed"
+       count=$($LFS getdirstripe -D -c $testdir)
+       (( count == 0 )) ||
+               error "$testdir default LMV count not zero: $count"
+}
+run_test 413f "lfs getdirstripe -D list ROOT default LMV if it's not set on dir"
+
 test_413z() {
        local pids=""
        local subdir
index 3b6be2c..99f8b1b 100644 (file)
@@ -1926,10 +1926,23 @@ static int cb_get_dirstripe(char *path, int *d, struct find_param *param)
                return -ENOTDIR;
 again:
        param->fp_lmv_md->lum_stripe_count = param->fp_lmv_stripe_count;
-       if (param->fp_get_default_lmv)
+       if (param->fp_get_default_lmv) {
+#ifdef HAVE_STATX
+               struct statx stx;
+
+               /* open() may not fetch LOOKUP lock, statx() to ensure dir depth
+                * is set.
+                */
+               statx(*d, "", AT_EMPTY_PATH, STATX_MODE, &stx);
+#else
+               struct stat st;
+
+               fstat(*d, &st);
+#endif
                param->fp_lmv_md->lum_magic = LMV_USER_MAGIC;
-       else
+       } else {
                param->fp_lmv_md->lum_magic = LMV_MAGIC_V1;
+       }
 
        ret = ioctl(*d, LL_IOC_LMV_GETSTRIPE, param->fp_lmv_md);