From 1af5bc826a7863c06b32c02ede5e4098a637a1b6 Mon Sep 17 00:00:00 2001 From: Lai Siyao Date: Sun, 7 Nov 2021 01:15:56 -0400 Subject: [PATCH] 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 413f. Lustre-change: https://review.whamcloud.com/45570 Lustre-commit: 61b1fad9e3fb21edcc0e713c89a3bfaeba9c883e Signed-off-by: Lai Siyao Change-Id: If7354cb4093c58f6d56a6a4d449fb69a9deec7cc Reviewed-on: https://review.whamcloud.com/47642 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Jian Yu --- lustre/llite/dir.c | 37 ++++++++++++++++++++++++++++++++++++- lustre/tests/sanity.sh | 40 ++++++++++++++++++++++++++++++++++++++++ lustre/utils/liblustreapi.c | 17 +++++++++++++++-- 3 files changed, 91 insertions(+), 3 deletions(-) diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index 34ada9e..59a27d5 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -809,7 +809,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); @@ -1646,6 +1646,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 52e2059..7ca1b58 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -25186,6 +25186,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.0.45) )) || + skip "Need server version at least 2.14.0.45" + + 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 744c7ac..f6f2609 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -1893,10 +1893,23 @@ static int cb_get_dirstripe(char *path, DIR *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(dirfd(d), "", AT_EMPTY_PATH, STATX_MODE, &stx); +#else + struct stat st; + + fstat(dirfd(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(dirfd(d), LL_IOC_LMV_GETSTRIPE, param->fp_lmv_md); if (errno == E2BIG && ret != 0) { -- 1.8.3.1