From 6a5a4b49fabcb4c9715ae017009f1a8be91de235 Mon Sep 17 00:00:00 2001 From: Vitaly Fertman Date: Thu, 2 Feb 2023 23:20:04 +0300 Subject: [PATCH] LU-16527 llite: dir layout inheritance fixes fixes for some minor problems: - it may happen that the depth is not set on a dir, do not consider depth == 0 as a real depth while checking if the root default is applicable; - setdirstripe util implicitely sets max_inherit to 3 for non-striped dir when -i option is given but -c is not; at the same time 3 is the default for striped dirs only; - getdirstripe shows inherited default layouts with max_inherit==0, whereas it has no sense anymore; the same for an explicitely set default layout on a dir/root with max_inherit==0; - getdirstripe hides max_inherit_rr when stripe_offset != -1 as it has no sense and reset to 0, however it leads to user confusion; HPE-bug-id: LUS-11090 Signed-off-by: Vitaly Fertman Change-Id: I65daaac76533fad44a88e1c5a8aad4467c9f7682 Reviewed-on: https://es-gerrit.dev.cray.com/161035 Reviewed-by: Alexander Boyko Reviewed-by: Alexey Lyashkov Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49882 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Lai Siyao Reviewed-by: Oleg Drokin --- lustre/llite/dir.c | 32 ++++++++--------------- lustre/llite/namei.c | 10 +++++-- lustre/tests/sanity.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++- lustre/utils/lfs.c | 4 ++- lustre/utils/liblustreapi.c | 3 +-- 5 files changed, 86 insertions(+), 27 deletions(-) diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index 8df0b4c..0ff2e45 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -1718,36 +1718,28 @@ out: /* Get default LMV EA */ if (lum.lum_magic == LMV_USER_MAGIC) { + struct lmv_user_md *lum; + struct ll_inode_info *lli; + 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; + if (lum->lum_max_inherit == LMV_INHERIT_NONE) + GOTO(finish_req, rc = -ENODATA); - lum = (struct lmv_user_md *)lmm; + if (root_request != NULL) { lli = ll_i2info(inode); if (lum->lum_max_inherit != LMV_INHERIT_UNLIMITED) { - if (lum->lum_max_inherit == - LMV_INHERIT_NONE || - lum->lum_max_inherit < + if (lum->lum_max_inherit < LMV_INHERIT_END || lum->lum_max_inherit > LMV_INHERIT_MAX || - lum->lum_max_inherit < + 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; - } - lum->lum_max_inherit -= lli->lli_dir_depth; } @@ -1767,10 +1759,8 @@ out: goto out_copy; } - if (lum->lum_max_inherit_rr > - lli->lli_dir_depth) - lum->lum_max_inherit_rr -= - lli->lli_dir_depth; + lum->lum_max_inherit_rr -= + lli->lli_dir_depth; } } out_copy: diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c index 23feb46..2f0aebd5 100644 --- a/lustre/llite/namei.c +++ b/lustre/llite/namei.c @@ -1478,8 +1478,10 @@ static void ll_qos_mkdir_prep(struct md_op_data *op_data, struct inode *dir) struct ll_inode_info *rlli = ll_i2info(root); struct ll_inode_info *lli = ll_i2info(dir); struct lmv_stripe_md *lsm; + unsigned short depth; op_data->op_dir_depth = lli->lli_inherit_depth ?: lli->lli_dir_depth; + depth = lli->lli_dir_depth; /* parent directory is striped */ if (unlikely(lli->lli_lsm_md)) @@ -1506,13 +1508,17 @@ static void ll_qos_mkdir_prep(struct md_op_data *op_data, struct inode *dir) if (lsm->lsm_md_master_mdt_index != LMV_OFFSET_DEFAULT) goto unlock; + /** + * Check if the fs default is to be applied. + * depth == 0 means 'not inited' for not root dir. + */ if (lsm->lsm_md_max_inherit != LMV_INHERIT_NONE && (lsm->lsm_md_max_inherit == LMV_INHERIT_UNLIMITED || - lsm->lsm_md_max_inherit >= lli->lli_dir_depth)) { + (depth && lsm->lsm_md_max_inherit > depth))) { op_data->op_flags |= MF_QOS_MKDIR; if (lsm->lsm_md_max_inherit_rr != LMV_INHERIT_RR_NONE && (lsm->lsm_md_max_inherit_rr == LMV_INHERIT_RR_UNLIMITED || - lsm->lsm_md_max_inherit_rr >= lli->lli_dir_depth)) + (depth && lsm->lsm_md_max_inherit_rr > depth))) op_data->op_flags |= MF_RR_MKDIR; CDEBUG(D_INODE, DFID" requests qos mkdir %#x\n", PFID(&lli->lli_fid), op_data->op_flags); diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 7cdee60..317a78e 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -26867,7 +26867,7 @@ test_fs_dmv_inherit() local inherit local inherit_rr - for i in 1 2 3; do + for i in 1 2; do mkdir $testdir || error "mkdir $testdir failed" count=$($LFS getdirstripe -D -c $testdir) (( count == 1 )) || @@ -26980,6 +26980,68 @@ test_413h() { } run_test 413h "don't stick to parent for round-robin dirs" +test_413i() { + [ $MDSCOUNT -lt 2 ] && skip_env "needs >= 2 MDTs" + + (( 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" + + local testdir=$DIR/$tdir + local def_max_rr=1 + local def_max=3 + local count + + $LFS setdirstripe -D -i-1 -c1 --max-inherit=$def_max \ + --max-inherit-rr=$def_max_rr $DIR || + error "set $DIR default LMV failed" + + for i in $(seq 2 3); do + def_max=$((def_max - 1)) + (( def_max_rr == 0 )) || def_max_rr=$((def_max_rr - 1)) + + mkdir $testdir + # RR is decremented and keeps zeroed once exhausted + count=$($LFS getdirstripe -D --max-inherit-rr $testdir) + (( count == def_max_rr )) || + error_noexit "$testdir: max-inherit-rr $count != $def_max_rr" + + # max-inherit is decremented + count=$($LFS getdirstripe -D --max-inherit $testdir) + (( count == def_max )) || + error_noexit "$testdir: max-inherit $count != $def_max" + + testdir=$testdir/d$i + done + + # d3 is the last inherited from ROOT, no inheritance anymore + # i.e. no the default layout anymore + mkdir -p $testdir/d4/d5 + count=$($LFS getdirstripe -D --max-inherit $testdir) + (( count == -1 )) || + error_noexit "$testdir: max-inherit $count != -1" + + local p_count=$($LFS getdirstripe -i $testdir) + + for i in $(seq 4 5); do + testdir=$testdir/d$i + + # the root default layout is not applied once exhausted + count=$($LFS getdirstripe -i $testdir) + (( count == p_count )) || + error_noexit "$testdir: stripe-offset $count != parent offset $p_count" + done + + $LFS setdirstripe -i 0 $DIR/d2 + count=$($LFS getdirstripe -D --max-inherit $DIR/d2) + (( count == -1 )) || + error_noexit "$DIR/d2: max-inherit non-striped default $count != -1" +} +run_test 413i "check default layout inheritance" + test_413z() { local pids="" local subdir diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 208037b..f3ca066 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -7225,8 +7225,10 @@ static int lfs_setdirstripe(int argc, char **argv) param->lsp_stripe_pattern = LMV_HASH_TYPE_UNKNOWN; param->lsp_pool = lsa.lsa_pool_name; param->lsp_is_specific = false; + if (max_inherit == LAYOUT_INHERIT_UNSET) { - if (lsa.lsa_stripe_count == 0 || lsa.lsa_stripe_count == 1) + if (lsa.lsa_stripe_count == 0 || lsa.lsa_stripe_count == 1 || + lsa.lsa_stripe_count == LLAPI_LAYOUT_DEFAULT) max_inherit = LMV_INHERIT_DEFAULT_PLAIN; else max_inherit = LMV_INHERIT_DEFAULT_STRIPED; diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index a79fcb0..b2d4f83 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -3092,8 +3092,7 @@ void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name, } if ((verbose & VERBOSE_INHERIT_RR) && - lum->lum_magic == LMV_USER_MAGIC && - lum->lum_stripe_offset == LMV_OFFSET_DEFAULT) { + lum->lum_magic == LMV_USER_MAGIC) { llapi_printf(LLAPI_MSG_NORMAL, "%s", separator); if (verbose & ~VERBOSE_INHERIT_RR) llapi_printf(LLAPI_MSG_NORMAL, "lmv_max_inherit_rr: "); -- 1.8.3.1