Whamcloud - gitweb
LU-18244 utils: add 'lfs mkdir -C -N' overstriping support 25/56925/7
authorKeguang Xu <squalfof@gmail.com>
Fri, 8 Nov 2024 01:35:00 +0000 (09:35 +0800)
committerOleg Drokin <green@whamcloud.com>
Mon, 16 Dec 2024 08:17:50 +0000 (08:17 +0000)
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 <squalfof@gmail.com>
Change-Id: I99bdd543c1482798441d8753f4aeb2b7190060a8
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56925
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Lai Siyao <lai.siyao@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/include/uapi/linux/lustre/lustre_user.h
lustre/lod/lod_object.c
lustre/tests/sanity.sh
lustre/utils/lfs.c
lustre/utils/lustreapi_internal.h

index 8598f37..42fc4ab 100644 (file)
@@ -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)
  */
index 7741d1d..95b8b55 100644 (file)
@@ -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)) {
index 7291756..54f6aaf 100755 (executable)
@@ -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
index 7c20f0b..3ff3505 100755 (executable)
@@ -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;
index cf08f0b..60c848a 100644 (file)
@@ -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)