From: Lai Siyao Date: Sun, 7 Nov 2021 05:15:56 +0000 (-0400) Subject: LU-15200 llite: "lfs getdirstripe -D" shows inherit layout X-Git-Tag: 2.15.0-RC1~57 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=61b1fad9e3fb21edcc0e713c89a3bfaeba9c883e;p=fs%2Flustre-release.git LU-15200 llite: "lfs getdirstripe -D" shows inherit layout 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 Change-Id: If7354cb4093c58f6d56a6a4d449fb69a9deec7cc Reviewed-on: https://review.whamcloud.com/45570 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index ae83d1b..36edab3 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -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); diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 6b93dc3..c9df3fd 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -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 diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 3b6be2c..99f8b1b 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -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);