From 09c83ef26cca5b27bfbc05538c2df93d5a396fb7 Mon Sep 17 00:00:00 2001 From: Lei Feng Date: Fri, 3 Dec 2021 19:09:13 +0800 Subject: [PATCH] LU-15307 lod: add option to set max dir stripe count Add an option to limit max dir stripe count when the default dir stripe count is set to -1. Signed-off-by: Lei Feng Change-Id: I12dd5be15012a28bda30da85f24bc726c37f1ac7 Reviewed-on: https://review.whamcloud.com/45724 Reviewed-by: Andreas Dilger Tested-by: jenkins Tested-by: Maloo Reviewed-by: Lai Siyao Reviewed-by: Oleg Drokin --- lustre/lod/lod_internal.h | 1 + lustre/lod/lod_object.c | 7 +++++++ lustre/lod/lproc_lod.c | 34 ++++++++++++++++++++++++++++++++++ lustre/tests/sanity.sh | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+) diff --git a/lustre/lod/lod_internal.h b/lustre/lod/lod_internal.h index 61d5199..49b5568 100644 --- a/lustre/lod/lod_internal.h +++ b/lustre/lod/lod_internal.h @@ -158,6 +158,7 @@ struct lod_device { /* max stripe count if stripe count is set to -1. 0 means unlimited */ unsigned int lod_max_stripecount; + unsigned int lod_max_mdt_stripecount; }; #define lod_ost_bitmap lod_ost_descs.ltd_tgt_bitmap diff --git a/lustre/lod/lod_object.c b/lustre/lod/lod_object.c index 1003ad1..22411dc 100644 --- a/lustre/lod/lod_object.c +++ b/lustre/lod/lod_object.c @@ -5606,6 +5606,13 @@ static void lod_ah_init(const struct lu_env *env, lc->ldo_dir_stripe_count = 0; } + /* shrink the stripe count to max_mdt_stripecount if it is -1 + * and max_mdt_stripecount is not 0 + */ + if (lc->ldo_dir_stripe_count == (__u16)(-1) && + d->lod_max_mdt_stripecount) + lc->ldo_dir_stripe_count = d->lod_max_mdt_stripecount; + /* shrink the stripe_count to the avaible MDT count */ if (lc->ldo_dir_stripe_count > d->lod_remote_mdt_count + 1 && !OBD_FAIL_CHECK(OBD_FAIL_LARGE_STRIPE)) { diff --git a/lustre/lod/lproc_lod.c b/lustre/lod/lproc_lod.c index 6ca8647..7949106 100644 --- a/lustre/lod/lproc_lod.c +++ b/lustre/lod/lproc_lod.c @@ -313,6 +313,39 @@ static ssize_t max_stripecount_store(struct kobject *kobj, LUSTRE_RW_ATTR(max_stripecount); +static ssize_t max_mdt_stripecount_show(struct kobject *kobj, + struct attribute *attr, char *buf) +{ + struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + + return scnprintf(buf, PAGE_SIZE, "%u\n", lod->lod_max_mdt_stripecount); +} + +static ssize_t max_mdt_stripecount_store(struct kobject *kobj, + struct attribute *attr, + const char *buffer, size_t count) +{ + struct dt_device *dt = container_of(kobj, struct dt_device, dd_kobj); + struct lod_device *lod = dt2lod_dev(dt); + long val; + int rc; + + rc = kstrtol(buffer, 0, &val); + if (rc) + return rc; + + if (val < 0 || val > LMV_MAX_STRIPE_COUNT) /* any limitation? */ + return -ERANGE; + + lod->lod_max_mdt_stripecount = val; + + return count; +} + +LUSTRE_RW_ATTR(max_mdt_stripecount); + + /** * Show default striping pattern (LOV_PATTERN_*). */ @@ -1211,6 +1244,7 @@ static struct attribute *lod_attrs[] = { &lustre_attr_stripeoffset.attr, &lustre_attr_stripecount.attr, &lustre_attr_max_stripecount.attr, + &lustre_attr_max_mdt_stripecount.attr, &lustre_attr_stripetype.attr, &lustre_attr_activeobd.attr, &lustre_attr_desc_uuid.attr, diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 0878c8c..64cbe5c 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -23733,6 +23733,38 @@ test_300s() { } run_test 300s "test lfs mkdir -c without -i" +test_300t() { + (( $MDS1_VERSION >= $(version_code 2.14.55) )) || + skip "need MDS 2.14.55 or later" + (( $MDSCOUNT >= 2 )) || skip "needs at least 2 MDTs" + + local testdir="$DIR/$tdir/striped_dir" + local dir1=$testdir/dir1 + local dir2=$testdir/dir2 + + mkdir -p $testdir + + $LFS setdirstripe -D -c -1 --max-inherit=3 $testdir || + error "failed to set default stripe count for $testdir" + + mkdir $dir1 + local stripe_count=$($LFS getdirstripe -c $dir1) + + (( $stripe_count == $MDSCOUNT )) || error "wrong stripe count" + + local max_count=$((MDSCOUNT - 1)) + local mdts=$(comma_list $(mdts_nodes)) + + do_nodes $mdts $LCTL set_param lod.*.max_mdt_stripecount=$max_count + stack_trap "do_nodes $mdts $LCTL set_param lod.*.max_mdt_stripecount=0" + + mkdir $dir2 + stripe_count=$($LFS getdirstripe -c $dir2) + + (( $stripe_count == $max_count )) || error "wrong stripe count" +} +run_test 300t "test max_mdt_stripecount" + prepare_remote_file() { mkdir $DIR/$tdir/src_dir || error "create remote source failed" -- 1.8.3.1