From 3c9580931d1a7753e6c03900df01fd05ab3ca73d Mon Sep 17 00:00:00 2001 From: Lei Feng Date: Thu, 11 Nov 2021 14:06:39 +0800 Subject: [PATCH] LU-9162 lod: option to set max stripe count per filesystem Add an option to set max default stripe count when the stripe count is set to -1. Change-Id: I02634a02a6f6579750fe964662b7e644af1689d6 Signed-off-by: Lei Feng Test-Parameters: trivial Reviewed-on: https://review.whamcloud.com/45532 Tested-by: jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Li Xi Reviewed-by: Oleg Drokin --- lustre/lod/lod_dev.c | 1 + lustre/lod/lod_internal.h | 3 +++ lustre/lod/lod_qos.c | 6 +++++- lustre/lod/lproc_lod.c | 33 +++++++++++++++++++++++++++++++++ lustre/tests/sanity.sh | 30 ++++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-) diff --git a/lustre/lod/lod_dev.c b/lustre/lod/lod_dev.c index d41e3ce..e535d2e 100644 --- a/lustre/lod/lod_dev.c +++ b/lustre/lod/lod_dev.c @@ -1791,6 +1791,7 @@ static int lod_init0(const struct lu_env *env, struct lod_device *lod, dt_conf_get(env, &lod->lod_dt_dev, &ddp); lod->lod_osd_max_easize = ddp.ddp_max_ea_size; lod->lod_dom_stripesize_max_kb = (1ULL << 10); /* 1Mb is default */ + lod->lod_max_stripecount = 0; /* initialize local statfs cached values */ rc = lod_lsfs_init(env, lod); diff --git a/lustre/lod/lod_internal.h b/lustre/lod/lod_internal.h index dc5c243..89da19f 100644 --- a/lustre/lod/lod_internal.h +++ b/lustre/lod/lod_internal.h @@ -155,6 +155,9 @@ struct lod_device { /* ROOT object, used to fetch FS default striping */ struct lod_object *lod_md_root; + + /* max stripe count if stripe count is set to -1. 0 means unlimited */ + unsigned int lod_max_stripecount; }; #define lod_ost_bitmap lod_ost_descs.ltd_tgt_bitmap diff --git a/lustre/lod/lod_qos.c b/lustre/lod/lod_qos.c index cafdc25..f6571f3 100644 --- a/lustre/lod/lod_qos.c +++ b/lustre/lod/lod_qos.c @@ -1878,7 +1878,10 @@ __u16 lod_get_stripe_count(struct lod_device *lod, struct lod_object *lo, /* max stripe count is based on OSD ea size */ unsigned int easize = lod->lod_osd_max_easize; int i; + ENTRY; + if (stripe_count == (__u16)(-1) && lod->lod_max_stripecount) + stripe_count = lod->lod_max_stripecount; if (!stripe_count) stripe_count = lod->lod_ost_descs.ltd_lov_desc.ld_default_stripe_count; @@ -1932,7 +1935,8 @@ __u16 lod_get_stripe_count(struct lod_device *lod, struct lod_object *lo, max_stripes = lov_mds_md_max_stripe_count(easize, LOV_MAGIC_V3); max_stripes = (max_stripes == 0) ? 0 : max_stripes - 1; - return (stripe_count < max_stripes) ? stripe_count : max_stripes; + stripe_count = min_t(__u16, stripe_count, max_stripes); + RETURN(stripe_count); } /** diff --git a/lustre/lod/lproc_lod.c b/lustre/lod/lproc_lod.c index f984bbd..6ca8647 100644 --- a/lustre/lod/lproc_lod.c +++ b/lustre/lod/lproc_lod.c @@ -281,6 +281,38 @@ static ssize_t stripeoffset_store(struct kobject *kobj, LUSTRE_RW_ATTR(stripeoffset); +static ssize_t max_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_stripecount); +} + +static ssize_t max_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 > LOV_MAX_STRIPE_COUNT) + return -ERANGE; + + lod->lod_max_stripecount = val; + + return count; +} + +LUSTRE_RW_ATTR(max_stripecount); + /** * Show default striping pattern (LOV_PATTERN_*). */ @@ -1178,6 +1210,7 @@ static struct attribute *lod_attrs[] = { &lustre_attr_stripesize.attr, &lustre_attr_stripeoffset.attr, &lustre_attr_stripecount.attr, + &lustre_attr_max_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 ce1e1ae..e6396f3 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -3349,6 +3349,36 @@ test_27Q() { } run_test 27Q "llapi_file_get_stripe() works on symlinks" +test_27R() { + (( $MDS1_VERSION >= $(version_code 2.14.55) )) || + skip "need MDS 2.14.55 or later" + (( $OSTCOUNT >= 2 )) || skip_env "needs at least 2 OSTs" + + local testdir="$DIR/$tdir" + test_mkdir -p $testdir + stack_trap "rm -rf $testdir" + $LFS setstripe -c -1 $testdir || error "setstripe failed" + + local f1="$testdir/f1" + touch $f1 || error "failed to touch $f1" + local count=$($LFS getstripe -c $f1) + (( $count == $OSTCOUNT )) || error "wrong stripe count" + + do_facet $SINGLEMDS $LCTL set_param lod.*.max_stripecount=-1 + (( $? == 34 )) || error "setting max_stripecount to -1 should fail and return ERANGE" + + local maxcount=$(($OSTCOUNT - 1)) + local mdts=$(comma_list $(mdts_nodes)) + do_nodes $mdts $LCTL set_param lod.*.max_stripecount=$maxcount + stack_trap "do_nodes $mdts $LCTL set_param lod.*.max_stripecount=0" + + local f2="$testdir/f2" + touch $f2 || error "failed to touch $f2" + local count=$($LFS getstripe -c $f2) + (( $count == $maxcount )) || error "wrong stripe count" +} +run_test 27R "test max_stripecount limitation when stripe count is set to -1" + # createtest also checks that device nodes are created and # then visible correctly (#2091) test_28() { # bug 2091 -- 1.8.3.1