From: Keguang Xu Date: Fri, 8 Nov 2024 01:35:00 +0000 (+0800) Subject: LU-18244 utils: add 'lfs mkdir -C -N' overstriping support X-Git-Tag: 2.16.51~55 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=refs%2Fchanges%2F25%2F56925%2F7;p=fs%2Flustre-release.git LU-18244 utils: add 'lfs mkdir -C -N' overstriping support Adding support of "-N" in "lfs mkdir -C -N" which specify the overstripe factor for each MDT. While meta-overstriping has already been introduced (refer LU-12273), this change mainly aligns the mkdir -C -N with the overstriping behavior OSTs. - Util side, add range check [-5, -1] if overstriped enabled within lfs_setdirstripe(). - Server side, in lod_object.c::lod_ah_init() where the decision of striping configuration is made, we adjust the ldo_dir_stripe_count value account for the specified overstripe factor. - Macro LMV_OVERSTRIPE_COUNT_{MIN, MAX} added indicating the overstipe count for each MDT, in -N format. Signed-off-by: Keguang Xu Change-Id: I99bdd543c1482798441d8753f4aeb2b7190060a8 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56925 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Lai Siyao Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/uapi/linux/lustre/lustre_user.h b/lustre/include/uapi/linux/lustre/lustre_user.h index 8598f37..42fc4ab 100644 --- a/lustre/include/uapi/linux/lustre/lustre_user.h +++ b/lustre/include/uapi/linux/lustre/lustre_user.h @@ -1220,6 +1220,13 @@ enum lustre_foreign_types { extern struct lustre_foreign_type lu_foreign_types[]; +/** + * When specified or returned as the value for stripe count, all + * available MDTs will be used. + */ +#define LMV_OVERSTRIPE_COUNT_MIN ((__s16)0xffff) /* -1 */ +#define LMV_OVERSTRIPE_COUNT_MAX ((__s16)0xfffb) /* -5 */ + /* Got this according to how get LOV_MAX_STRIPE_COUNT, see above, * (max buffer size - lmv+rpc header) / sizeof(struct lmv_user_mds_data) */ diff --git a/lustre/lod/lod_object.c b/lustre/lod/lod_object.c index 7741d1d..95b8b55 100644 --- a/lustre/lod/lod_object.c +++ b/lustre/lod/lod_object.c @@ -5805,7 +5805,8 @@ static void lod_ah_init(const struct lu_env *env, if (S_ISDIR(child_mode)) { const struct lmv_user_md_v1 *lum1 = ah->dah_eadata; - int max_stripe_count; + int max_stripe_count = 0; + int mdt_count = d->lod_remote_mdt_count + 1; /* other default values are 0 */ lc->ldo_dir_stripe_offset = LMV_OFFSET_DEFAULT; @@ -5907,17 +5908,25 @@ static void lod_ah_init(const struct lu_env *env, } } - /* shrink the stripe count to max_mdt_stripecount if it is -1 - * and max_mdt_stripecount is not 0 + /* + * 1. overstriped case(< 0), adjust stripe count given + * overstriped factor by mdt_countmdt_count; + * 1.1 use lod_max_mdt_stripecount as max_stripe_count; + * 2. overstriped case(> 0), multiply max_stripe_count by + * max_stripes_per_mdt; */ - if (lc->ldo_dir_stripe_count == (__u16)(-1) && - d->lod_max_mdt_stripecount) - lc->ldo_dir_stripe_count = d->lod_max_mdt_stripecount; - - max_stripe_count = d->lod_remote_mdt_count + 1; - if (lc->ldo_dir_hash_type & LMV_HASH_FLAG_OVERSTRIPED) + max_stripe_count = mdt_count; + if ((__s16)lc->ldo_dir_stripe_count >= + LMV_OVERSTRIPE_COUNT_MAX && + (__s16)lc->ldo_dir_stripe_count <= + LMV_OVERSTRIPE_COUNT_MIN) { + lc->ldo_dir_stripe_count = mdt_count * + -(__s16)lc->ldo_dir_stripe_count; + max_stripe_count = d->lod_max_mdt_stripecount ?: + mdt_count * d->lod_max_stripes_per_mdt; + } else if (lc->ldo_dir_hash_type & LMV_HASH_FLAG_OVERSTRIPED) { max_stripe_count *= d->lod_max_stripes_per_mdt; - + } /* shrink the stripe_count to max stripe count */ if (lc->ldo_dir_stripe_count > max_stripe_count && !CFS_FAIL_CHECK(OBD_FAIL_LARGE_STRIPE)) { diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 7291756..54f6aaf 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -27979,7 +27979,13 @@ test_300t() { mkdir $dir2 stripe_count=$($LFS getdirstripe -c $dir2) - (( $stripe_count == $max_count )) || error "wrong stripe count" + if (( $MDSCOUNT == 2 && + $MDS1_VERSION >= $(version_code 2.16.0) )); then + (( $stripe_count == 0 )) || error "(0) wrong stripe count" + else + (( $stripe_count == $max_count )) || + error "(1) wrong stripe count" + fi } run_test 300t "test max_mdt_stripecount" @@ -28348,6 +28354,30 @@ test_300ui() { } run_test 300ui "overstripe is not supported on one MDT system" +test_300uj() { + (( MDSCOUNT > 1 )) || skip "needs >= 2 MDTs" + (( MDS1_VERSION >= $(version_code 2.16.0) )) || + skip "need MDS >= 2.16.0 for llog timestamps" + + local setcount=-2 + local expected_count=$((MDSCOUNT * 2)) + + mkdir $DIR/$tdir + $LFS mkdir -C $setcount $DIR/$tdir/${tdir}.0 || + error "(0) failed overstriped dir creation with -C -N test" + local getstripe_count=$($LFS getdirstripe -c $DIR/$tdir/${tdir}.0) + (( getstripe_count == expected_count )) || + error "(1) incorrect stripe count for -C -N overstriped dir" + rm -f $DIR/$tdir/${tdir}.0 + + # limit testing + setcount=-6 + $LFS setdirstripe -C $setcount $DIR/$tdir/${tdir}.1 2>&1 | + grep "invalid stripe count" || + error "(0) failed overstriped dir creation limit test" +} +run_test 300uj "overstriped dir with -C -N sanity test" + (( max_stripes_per_mdt == 0 )) || do_nodes $mdts $LCTL set_param -n \ lod.$FSNAME-MDT*.max_stripes_per_mdt=$max_stripes_per_mdt diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 7c20f0b..3ff3505 100755 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -7505,9 +7505,12 @@ static int lfs_setdirstripe(int argc, char **argv) case 'T': errno = 0; lsa.lsa_stripe_count = strtoul(optarg, &end, 0); + /* only allow count -1..-5 for overstriped dirs */ if (errno != 0 || *end != '\0' || - lsa.lsa_stripe_count < LLAPI_OVERSTRIPE_COUNT_MAX || - lsa.lsa_stripe_count > LOV_MAX_STRIPE_COUNT) { + lsa.lsa_stripe_count < + (overstriped ? LMV_OVERSTRIPE_COUNT_MAX : + LLAPI_OVERSTRIPE_COUNT_MIN) || + lsa.lsa_stripe_count > LMV_MAX_STRIPE_COUNT) { fprintf(stderr, "%s: invalid stripe count '%s'\n", progname, optarg); @@ -7777,9 +7780,14 @@ static int lfs_setdirstripe(int argc, char **argv) * initialize stripe parameters, in case param is converted to specific, * i.e, 'lfs mkdir -i -1 -c N', always allocate space for lsp_tgts. */ - param = calloc(1, offsetof(typeof(*param), - lsp_tgts[lsa.lsa_stripe_count != LLAPI_LAYOUT_DEFAULT ? - lsa.lsa_stripe_count : lsa.lsa_nr_tgts])); + if (lsa.lsa_stripe_count == LLAPI_LAYOUT_DEFAULT || + lsa.lsa_stripe_count <= LLAPI_OVERSTRIPE_COUNT_MIN) { + param = calloc(1, offsetof(typeof(*param), + lsp_tgts[lsa.lsa_nr_tgts])); + } else { + param = calloc(1, offsetof(typeof(*param), + lsp_tgts[lsa.lsa_stripe_count])); + } if (!param) { fprintf(stderr, "%s %s: cannot allocate memory for parameters: %s\n", @@ -7821,7 +7829,6 @@ static int lfs_setdirstripe(int argc, char **argv) } param->lsp_max_inherit = max_inherit; if (default_stripe) { - if (max_inherit_rr == LAYOUT_INHERIT_UNSET) max_inherit_rr = LMV_INHERIT_RR_DEFAULT; param->lsp_max_inherit_rr = max_inherit_rr; diff --git a/lustre/utils/lustreapi_internal.h b/lustre/utils/lustreapi_internal.h index cf08f0b..60c848a 100644 --- a/lustre/utils/lustreapi_internal.h +++ b/lustre/utils/lustreapi_internal.h @@ -165,7 +165,8 @@ static inline bool llapi_pool_name_is_valid(const char **pool_name) static inline bool llapi_dir_stripe_count_is_valid(int64_t count) { - return count >= -1 && count <= LMV_MAX_STRIPE_COUNT; + return count >= LMV_OVERSTRIPE_COUNT_MAX && + count <= LMV_MAX_STRIPE_COUNT; } static inline bool llapi_dir_stripe_index_is_valid(int64_t index)