Whamcloud - gitweb
LU-17925 utils: fix 'lfs setstripe -c -1' interop 48/55548/11
authorRajeev Mishra <rajeevm@hpe.com>
Thu, 27 Jun 2024 03:37:18 +0000 (03:37 +0000)
committerOleg Drokin <green@whamcloud.com>
Wed, 31 Jul 2024 16:07:18 +0000 (16:07 +0000)
This issue was caused by the -C option was storing -1 as 0xffdf
and -33 was stored as 0xffff, which changed the on-disk file layout
compared to all older versions storing -1 as 0xffff. This resulted
in interop failure of 'lfs setstripe -c/-C' usage.

Instead, store stripe_count as -1 = 0xffff, and -32 = 0xffe0, like
normal unsigned short.  There is no need to distinguish "-c -1"
from "-C -1" in the layout since they both mean the same thing, to
allocate one object per OST.  However, don't allow "-c -2..-32"
since this has no meaning today.  Keep these in reserve in case we
assign some meaning to them in the future.

Restore LLAPI_LAYOUT_WIDE and LOV_ALL_STRIPES definitions, since
these are part of the API and may be used by userspace applications.

Rename LOV_ALL_STRIPES_MIN to LOV_ALL_STRIPES_WIDE since it was
confusing that the "MIN" value created files with the most stripes.

Rename LOV_V1_INSANE_STRIPE_COUNT to LOV_V1_INSANE_STRIPE_INDEX
since it is really the maximum OST index and not a stripe count.

Test-Parameters: testlist=sanity-flr serverversion=2.15 env=SANITY_FLR_EXCEPT="0k 44e 205"
Fixes: 1a6ef725c285 ("LU-16938 utils: setstripe overstripe multiple OST count")
Signed-off-by: Rajeev Mishra <rajeevm@hpe.com>
Change-Id: I3908bd5a70aa35305ef8f278fb0346319055e5b3
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/55548
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Alexander Boyko <alexander.boyko@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
15 files changed:
lustre/include/lu_object.h
lustre/include/lustre/lustreapi.h
lustre/include/uapi/linux/lustre/lustre_idl.h
lustre/include/uapi/linux/lustre/lustre_user.h
lustre/lmv/lmv_obd.c
lustre/lod/lod_object.c
lustre/lod/lod_qos.c
lustre/lov/lov_ea.c
lustre/lov/lov_pack.c
lustre/tests/llapi_layout_test.c
lustre/tests/sanity-flr.sh
lustre/tests/sanity.sh
lustre/utils/lfs.c
lustre/utils/liblustreapi_layout.c
lustre/utils/lustreapi_internal.h

index e5c976f..363b0f9 100644 (file)
@@ -1641,7 +1641,7 @@ static inline __u64 tgt_statfs_iavail(struct lu_tgt_desc *tgt)
 /* number of pointers at 2nd level */
 #define TGT_PTRS_PER_BLOCK     (PAGE_SIZE / sizeof(void *))
 /* number of pointers at 1st level - only need as many as max OST/MDT count */
-#define TGT_PTRS               ((LOV_ALL_STRIPES_MAX + 1) / TGT_PTRS_PER_BLOCK)
+#define TGT_PTRS               ((LOV_ALL_STRIPES + 1) / TGT_PTRS_PER_BLOCK)
 
 struct lu_tgt_desc_idx {
        struct lu_tgt_desc *ldi_tgt[TGT_PTRS_PER_BLOCK];
index 5b7bb4a..13c4061 100644 (file)
@@ -875,10 +875,13 @@ int llapi_layout_merge(struct llapi_layout **dst_layout,
  * When specified or returned as the value for stripe count, all
  * available OSTs will be used.
  */
-#define LLAPI_MIN_STRIPE_COUNT    (-1)
-#define LLAPI_MAX_STRIPE_COUNT    (-32)
-#define LLAPI_LAYOUT_WIDE_MIN  (LLAPI_LAYOUT_INVALID + 2)
-#define LLAPI_LAYOUT_WIDE_MAX  (LLAPI_LAYOUT_WIDE_MIN + 32)
+#define LLAPI_OVERSTRIPE_COUNT_MIN    ((__s16)LOV_ALL_STRIPES)      /*  -1 */
+#define LLAPI_OVERSTRIPE_COUNT_MAX    ((__s16)LOV_ALL_STRIPES_WIDE) /* -32 */
+#define LLAPI_LAYOUT_WIDE_MIN (LLAPI_LAYOUT_DEFAULT - \
+                               LLAPI_OVERSTRIPE_COUNT_MIN)
+#define LLAPI_LAYOUT_WIDE_MAX (LLAPI_LAYOUT_DEFAULT - \
+                               LLAPI_OVERSTRIPE_COUNT_MAX)
+#define LLAPI_LAYOUT_WIDE     LLAPI_LAYOUT_WIDE_MIN /* backward compatibility */
 
 /**
  * When specified as the value for layout pattern, file objects will be
index 0ad5db3..d963e4e 100644 (file)
@@ -1308,7 +1308,7 @@ struct lov_mds_md_v3 {            /* LOV EA mds/wire data (little-endian) */
 
 static inline __u32 lov_mds_md_size(__u16 stripes, __u32 lmm_magic)
 {
-       if (stripes >= LOV_ALL_STRIPES_MIN && stripes <= LOV_ALL_STRIPES_MAX)
+       if (stripes <= LOV_ALL_STRIPES && stripes >= LOV_ALL_STRIPES_WIDE)
                stripes = 0;
 
        if (lmm_magic == LOV_MAGIC_V1)
index 46cede1..15be589 100644 (file)
@@ -813,12 +813,11 @@ static inline bool lov_pool_is_reserved(const char *pool)
  */
 #define LOV_MAX_STRIPE_COUNT 2000  /* ~((12 * 4096 - 256) / 24) */
 
-/* Below given max and min values are used to check range of stripe count */
-/* LOV_ALL_STRIPES_MAX  LLAPI_MIN_STRIPE_COUNT */
-/* LOV_ALL_STRIPES_MIN  LLAPI_MIN_STRIPE_COUNT+ LLAPI_MAX_STRIPE_COUNT */
-#define LOV_ALL_STRIPES_MAX 0xffff
-#define LOV_ALL_STRIPES_MIN 0xffdf
-#define LOV_V1_INSANE_STRIPE_COUNT 65532 /* maximum stripe count bz13933 */
+/* max and min values are used to check range of overstripe count */
+#define LOV_ALL_STRIPES       0xffff /* only valid for directories */
+#define LOV_ALL_STRIPES_WIDE  0xffe0 /* LLAPI_OVERSTRIPE_COUNT_MAX */
+#define LOV_V1_INSANE_STRIPE_INDEX (LOV_ALL_STRIPES_WIDE - 1) /* max index */
+#define LOV_V1_INSANE_STRIPE_COUNT LOV_V1_INSANE_STRIPE_INDEX /* deprecated */
 
 #define XATTR_LUSTRE_PREFIX    "lustre."
 #define XATTR_LUSTRE_LOV       XATTR_LUSTRE_PREFIX"lov"
@@ -1059,7 +1058,7 @@ struct lov_comp_md_v1 {
 
 static inline __u32 lov_user_md_size(__u16 stripes, __u32 lmm_magic)
 {
-       if (stripes >= LOV_ALL_STRIPES_MIN && stripes <= LOV_ALL_STRIPES_MAX)
+       if (stripes <= LOV_ALL_STRIPES && stripes >= LOV_ALL_STRIPES_WIDE)
                stripes = 0;
 
        if (lmm_magic == LOV_USER_MAGIC_V1)
index bb08666..008ddbd 100644 (file)
@@ -160,7 +160,7 @@ retry:
                     "%s: MDT index %u more than MDT count %u\n",
                     obd->obd_name, index, lmv->lmv_mdt_count);
 
-       if (index >= LOV_V1_INSANE_STRIPE_COUNT)
+       if (index >= LOV_V1_INSANE_STRIPE_INDEX)
                return NULL;
 
        if (now > next_print) {
index 5f9a360..7d331a2 100644 (file)
@@ -2731,8 +2731,8 @@ __u16 lod_comp_entry_stripe_count(struct lod_object *lo, int comp_idx,
        entry = &lo->ldo_comp_entries[comp_idx];
        if (lod_comp_inited(entry))
                return entry->llc_stripe_count;
-       if (entry->llc_stripe_count >= LOV_ALL_STRIPES_MIN &&
-            entry->llc_stripe_count <= LOV_ALL_STRIPES_MAX)
+       if (entry->llc_stripe_count <= LOV_ALL_STRIPES &&
+           entry->llc_stripe_count >= LOV_ALL_STRIPES_WIDE)
                return lod_get_stripe_count_plain(lod, lo,
                                                  entry->llc_stripe_count,
                                                  entry->llc_pattern &
@@ -2886,8 +2886,8 @@ static int lod_declare_layout_add(const struct lu_env *env,
                    (lod_comp_inited(lod_comp) ||
                     lod_comp->llc_extent.e_start <
                     lod_comp->llc_extent.e_end) &&
-                    !(lod_comp->llc_stripe_count >= LOV_ALL_STRIPES_MIN &&
-                      lod_comp->llc_stripe_count <= LOV_ALL_STRIPES_MAX) &&
+                   !(lod_comp->llc_stripe_count <= LOV_ALL_STRIPES &&
+                     lod_comp->llc_stripe_count >= LOV_ALL_STRIPES_WIDE) &&
                    ext->e_end != OBD_OBJECT_EOF &&
                    (__u64)(lod_comp->llc_stripe_count *
                            lod_comp->llc_stripe_size) >
@@ -5509,15 +5509,11 @@ static int lod_get_default_lov_striping(const struct lu_env *env,
                        }
                }
 
-               CDEBUG(D_LAYOUT, DFID" magic = %#08x, pattern = %#x, stripe_count = %hu, stripe_size = %u, stripe_offset = %hu, append_pool = '%s', append_stripe_count = %d\n",
-                      PFID(lu_object_fid(&lo->ldo_obj.do_lu)),
-                      v1->lmm_magic,
-                      v1->lmm_pattern,
-                      v1->lmm_stripe_count,
-                      v1->lmm_stripe_size,
-                      v1->lmm_stripe_offset,
-                      append_pool ?: "",
-                      append_stripe_count);
+               CDEBUG(D_LAYOUT, DFID" magic = %#08x, pattern = %#x, stripe_count = %hd, stripe_size = %u, stripe_offset = %hd, append_pool = '%s', append_stripe_count = %d\n",
+                      PFID(lu_object_fid(&lo->ldo_obj.do_lu)), v1->lmm_magic,
+                      v1->lmm_pattern, (__s16)v1->lmm_stripe_count,
+                      v1->lmm_stripe_size, (__s16)v1->lmm_stripe_offset,
+                      append_pool ?: "", append_stripe_count);
 
                if (!lov_pattern_supported(v1->lmm_pattern) &&
                    !(v1->lmm_pattern & LOV_PATTERN_F_RELEASED)) {
index e8cd761..d71caca 100644 (file)
@@ -2069,30 +2069,28 @@ __u16 lod_get_stripe_count_plain(struct lod_device *lod, struct lod_object *lo,
 {
        struct lov_desc *lov_desc = &lod->lod_ost_descs.ltd_lov_desc;
 
+       if (!stripe_count)
+               stripe_count = lov_desc->ld_default_stripe_count;
+
        /* Overstriping allows more stripes than targets */
        if (stripe_count > lov_desc->ld_active_tgt_count) {
-               if (overstriping) {
-                       if (stripe_count >= LOV_ALL_STRIPES_MIN &&
-                               stripe_count <= LOV_ALL_STRIPES_MAX) {
-                               stripe_count =
-                               ((stripe_count - LOV_ALL_STRIPES_MIN) + 1) *
-                               lov_desc->ld_active_tgt_count;
-                       }
-               } else {
+               if (!overstriping) {
                        *flags |= LOD_USES_DEFAULT_STRIPE;
-                       if ((stripe_count >= LOV_ALL_STRIPES_MIN &&
-                            stripe_count <= LOV_ALL_STRIPES_MAX) &&
-                            lod->lod_max_stripecount)
+                       if (stripe_count == LOV_ALL_STRIPES &&
+                           lod->lod_max_stripecount)
                                stripe_count = lod->lod_max_stripecount;
                        else
                                stripe_count = lov_desc->ld_active_tgt_count;
+               } else if (stripe_count <= LOV_ALL_STRIPES &&
+                          stripe_count >= LOV_ALL_STRIPES_WIDE) {
+                       stripe_count = lov_desc->ld_active_tgt_count *
+                               (LOV_ALL_STRIPES - stripe_count + 1);
                }
        }
-
        if (!stripe_count)
-               stripe_count = lov_desc->ld_default_stripe_count;
+               stripe_count = 1;
 
-       if (overstriping && stripe_count > LOV_MAX_STRIPE_COUNT)
+       if (stripe_count > LOV_MAX_STRIPE_COUNT)
                stripe_count = LOV_MAX_STRIPE_COUNT;
 
        return stripe_count;
@@ -2308,9 +2306,9 @@ int lod_use_defined_striping(const struct lu_env *env,
                    !(lod_comp->llc_flags & LCME_FL_EXTENSION) &&
                    (lod_comp_inited(lod_comp) ||
                     lod_comp->llc_extent.e_start <
-                    lod_comp->llc_extent.e_end) &&
-                   !(lod_comp->llc_stripe_count >= LOV_ALL_STRIPES_MIN &&
-                     lod_comp->llc_stripe_count <= LOV_ALL_STRIPES_MAX) &&
+                                               lod_comp->llc_extent.e_end) &&
+                   !(lod_comp->llc_stripe_count <= LOV_ALL_STRIPES &&
+                     lod_comp->llc_stripe_count >= LOV_ALL_STRIPES_WIDE) &&
                    lod_comp->llc_extent.e_end != OBD_OBJECT_EOF &&
                    (__u64)lod_comp->llc_stripe_count *
                           lod_comp->llc_stripe_size >
@@ -2605,11 +2603,11 @@ int lod_qos_parse_config(const struct lu_env *env, struct lod_object *lo,
                 */
                if (lo->ldo_is_composite &&
                    !(lod_comp->llc_flags & LCME_FL_EXTENSION) &&
-                   !(lod_comp->llc_stripe_count >= LOV_ALL_STRIPES_MIN &&
-                     lod_comp->llc_stripe_count <= LOV_ALL_STRIPES_MAX) &&
+                   !(lod_comp->llc_stripe_count <= LOV_ALL_STRIPES &&
+                     lod_comp->llc_stripe_count >= LOV_ALL_STRIPES_WIDE) &&
                    (lod_comp_inited(lod_comp) ||
                     lod_comp->llc_extent.e_start <
-                    lod_comp->llc_extent.e_end) &&
+                                               lod_comp->llc_extent.e_end) &&
                    lod_comp->llc_extent.e_end != OBD_OBJECT_EOF &&
                    lod_comp->llc_stripe_count * lod_comp->llc_stripe_size >
                    (lod_comp->llc_extent.e_end - lod_comp->llc_extent.e_start))
index 19fe451..eee64d5 100644 (file)
@@ -298,7 +298,7 @@ retry_new_ost:
                                lov->desc.ld_uuid.uuid, POSTID(&loi->loi_oi),
                                loi->loi_ost_idx, lov->desc.ld_tgt_count);
 
-                       if ((u32)loi->loi_ost_idx >= LOV_V1_INSANE_STRIPE_COUNT)
+                       if ((u32)loi->loi_ost_idx >= LOV_V1_INSANE_STRIPE_INDEX)
                                GOTO(out_lsme, rc = -EINVAL);
 
                        if (now > next_print) {
index a33b13d..1dc298e 100644 (file)
@@ -69,7 +69,7 @@ static void lov_dump_lmm_objects(int level, struct lov_ost_data *lod,
        if (stripe_count > LOV_V1_INSANE_STRIPE_COUNT) {
                CDEBUG_LIMIT(level,
                             "bad stripe_count %u > max_stripe_count %u\n",
-                            stripe_count, LOV_V1_INSANE_STRIPE_COUNT);
+                            stripe_count, LOV_V1_INSANE_STRIPE_INDEX);
                return;
        }
 
index 051e048..0e16f1b 100644 (file)
@@ -773,7 +773,7 @@ static void test17(void)
        ASSERTF(rc == 0 || errno == ENOENT, "errno = %d", errno);
        layout = llapi_layout_alloc();
        ASSERTF(layout != NULL, "errno = %d", errno);
-       rc = llapi_layout_stripe_count_set(layout, LLAPI_LAYOUT_WIDE_MIN);
+       rc = llapi_layout_stripe_count_set(layout, LLAPI_LAYOUT_WIDE);
        ASSERTF(rc == 0, "errno = %d", errno);
        fd = llapi_layout_file_create(path, 0, 0640, layout);
        ASSERTF(fd >= 0, "errno = %d", errno);
@@ -907,7 +907,7 @@ static void test20(void)
        rc = llapi_layout_stripe_count_get(deflayout, &dcount);
        ASSERTF(rc == 0, "errno = %d", errno);
        ASSERTF(fcount == dcount || dcount == LLAPI_LAYOUT_DEFAULT ||
-               IN_RANGE(dcount, LLAPI_LAYOUT_WIDE_MIN, LLAPI_LAYOUT_WIDE_MAX),
+               dcount == LLAPI_LAYOUT_WIDE,
                "%"PRIu64" != %"PRIu64, fcount, dcount);
 
        rc = llapi_layout_stripe_size_get(filelayout, &fsize);
@@ -1216,9 +1216,7 @@ static void test28(void)
 
        rc = llapi_layout_stripe_count_get(layout, &count);
        ASSERTF(rc == 0, "errno = %d\n", errno);
-       ASSERTF((count >= LLAPI_LAYOUT_WIDE_MIN &&
-                count <= LLAPI_LAYOUT_WIDE_MAX),
-                "count = %"PRIu64"\n", count);
+       ASSERTF(count == LLAPI_LAYOUT_WIDE, "count = %"PRIu64"\n", count);
 
        llapi_layout_free(layout);
 }
index 71ec955..16dda47 100644 (file)
@@ -491,13 +491,7 @@ test_0c() {
        # verify components ${ids[6]}, ${ids[8]} and ${ids[10]}
        for i in 6 8 10; do
                verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
-               # ffdf which is -33 and matches LOV_ALL_STRIPES_MIN
-               local decimal_lov_lower_limit=-33
-               #C_opt is -c option which can be -1 to -32
-               local C_opt=-1
-               local count_exp=$(($decimal_lov_lower_limit + $C_opt + 1))
-
-               verify_comp_attr stripe-count $tf ${ids[$i]} $count_exp
+               verify_comp_attr stripe-count $tf ${ids[$i]} -1
                verify_comp_attr pool $tf ${ids[$i]} archive
                verify_comp_extent $tf ${ids[$i]} 536870912 EOF
        done
@@ -708,13 +702,7 @@ test_0f() {
        # verify components ${ids[9]}, ${ids[11]} and ${ids[13]}
        for i in 9 11 13; do
                verify_comp_attr stripe-size $tf ${ids[$i]} 16777216
-               # ffdf which is -33 and matches LOV_ALL_STRIPES_MIN
-               local decimal_lov_lower_limit=-33
-               #C_opt is -c option which can be -1 to -32
-               local C_opt=-1
-               local count_exp=$(($decimal_lov_lower_limit + $C_opt + 1))
-
-               verify_comp_attr stripe-count $tf ${ids[$i]} $count_exp
+               verify_comp_attr stripe-count $tf ${ids[$i]} -1
                verify_comp_attr pool $tf ${ids[$i]} archive
                verify_comp_extent $tf ${ids[$i]} 536870912 EOF
        done
index 78ab98c..043fc8b 100755 (executable)
@@ -1667,6 +1667,8 @@ test_27ce() {
                        osts=$osts","
                fi
        done
+
+       echo "$LFS setstripe -o $osts $DIR/$tdir/$tfile"
        $LFS setstripe -o $osts $DIR/$tdir/$tfile || error "setstripe failed"
        local getstripe=$($LFS getstripe $DIR/$tdir/$tfile)
        echo "$getstripe"
@@ -1675,7 +1677,7 @@ test_27ce() {
        local getstripe_osts=$(echo "$getstripe" | sed -e '1,/obdidx/d' |\
                awk '{print $1}' | tr '\n' ' ' | sed -e 's/[[:space:]]*$//')
        [ "$getstripe_osts" = "${osts//,/ }" ] ||
-               error "stripes not on specified OSTs"
+               error "stripes '$getstripe_osts' not on given OSTs ${osts//,/ }"
 
        dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=4 || error "dd failed"
 }
@@ -1840,8 +1842,13 @@ test_27m() {
        stack_trap simple_cleanup_common
        test_mkdir $DIR/$tdir
        $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.1
-       dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=1024 count=$MAXFREE &&
-               error "dd should fill OST0"
+       if check_fallocate_supported $ost1; then
+               fallocate -l ${MAXFREE}k $DIR/$tdir/$tfile.1 &&
+                       error "fallocate should fill OST0"
+       else
+               dd if=/dev/zero of=$DIR/$tdir/$tfile.1 bs=1024 count=$MAXFREE &&
+                       error "dd should fill OST0"
+       fi
        i=2
        while $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile.$i; do
                i=$((i + 1))
@@ -2627,15 +2634,18 @@ test_27Cj() {
                skip "need MDS >= 2.15.61.76"
 
        stack_trap "rm -f $DIR/$tfile"
+
+       #check that beyond -32 it fails
+       echo "setstripe -C -33 should fail"
+       $LFS setstripe -C -33 $DIR/$tfile && error "setstripe should fail"
+
        # start_full_debug_logging
        # number of stripes created will be 32*ost count
        $LFS setstripe  -C -32 $DIR/$tfile || error "create $tfile failed"
        local count=$($LFS getstripe -c $DIR/$tfile)
        local stripe_cnt=$(($OSTCOUNT * 32))
        (( $count == $stripe_cnt )) ||
-               error "$DIR/$tfile stripe count $count != $OSTCOUNT"
-       #check that beyond -32 it fails
-       !($LFS setstripe  -C -34 $DIR/$tfile) || error "setstripe should fail"
+               error "$DIR/$tfile stripe count $count != $stripe_cnt"
 }
 run_test 27Cj "overstriping with -C for max values in multiple of targets"
 
index 8c742f9..b1c6299 100755 (executable)
@@ -2789,7 +2789,7 @@ static int lsa_args_stripe_count_check(struct lfs_setstripe_args *lsa)
                if (lsa->lsa_stripe_count > 0 &&
                    lsa->lsa_stripe_count != LLAPI_LAYOUT_DEFAULT &&
                    !(lsa->lsa_stripe_count >= LLAPI_LAYOUT_WIDE_MIN &&
-                    lsa->lsa_stripe_count <= LLAPI_LAYOUT_WIDE_MAX) &&
+                     lsa->lsa_stripe_count <= LLAPI_LAYOUT_WIDE_MAX) &&
                    lsa->lsa_nr_tgts != lsa->lsa_stripe_count) {
                        fprintf(stderr, "stripe_count(%lld) != nr_tgts(%d)\n",
                                lsa->lsa_stripe_count,
@@ -3877,16 +3877,18 @@ static int lfs_setstripe_internal(int argc, char **argv,
                                        progname, argv[0]);
                                goto usage_error;
                        }
-                       if (migrate_mode)
-                               overstriped = true;
-                       else
+                       overstriped = true;
+                       if (!migrate_mode)
                                lsa.lsa_pattern = LLAPI_LAYOUT_OVERSTRIPING;
                        fallthrough;
                case 'c':
                        errno = 0;
                        lsa.lsa_stripe_count = strtoul(optarg, &end, 0);
+                       /* only allow count -2..-32 for overstriped files */
                        if (errno != 0 || *end != '\0'|| optarg == end ||
-                           lsa.lsa_stripe_count < LLAPI_MAX_STRIPE_COUNT ||
+                           lsa.lsa_stripe_count <
+                               (overstriped ? LLAPI_OVERSTRIPE_COUNT_MAX :
+                                              LLAPI_OVERSTRIPE_COUNT_MIN) ||
                            lsa.lsa_stripe_count > LOV_MAX_STRIPE_COUNT) {
                                fprintf(stderr,
                                        "%s %s: invalid stripe count '%s'\n",
@@ -3894,10 +3896,12 @@ static int lfs_setstripe_internal(int argc, char **argv,
                                goto usage_error;
                        }
 
-                       if (lsa.lsa_stripe_count <= LLAPI_MIN_STRIPE_COUNT &&
-                           lsa.lsa_stripe_count >= LLAPI_MAX_STRIPE_COUNT) {
-                               lsa.lsa_stripe_count = LLAPI_LAYOUT_WIDE_MIN +
-                                   abs(lsa.lsa_stripe_count + 1);
+                       if (lsa.lsa_stripe_count <=
+                                               LLAPI_OVERSTRIPE_COUNT_MIN &&
+                           lsa.lsa_stripe_count >=
+                                               LLAPI_OVERSTRIPE_COUNT_MAX) {
+                               lsa.lsa_stripe_count = LLAPI_LAYOUT_WIDE_MIN -
+                                       (lsa.lsa_stripe_count + 1);
                        }
                        break;
                case 'd':
@@ -3975,8 +3979,8 @@ static int lfs_setstripe_internal(int argc, char **argv,
                        errno = 0;
                        lsa.lsa_stripe_off = strtol(optarg, &end, 0);
                        if (errno != 0 || *end != '\0' || optarg == end ||
-                           lsa.lsa_stripe_off < -1 ||
-                           lsa.lsa_stripe_off > LOV_V1_INSANE_STRIPE_COUNT) {
+                           lsa.lsa_stripe_off < (__s16)LOV_ALL_STRIPES ||
+                           lsa.lsa_stripe_off > LOV_V1_INSANE_STRIPE_INDEX) {
                                fprintf(stderr,
                                        "%s %s: invalid stripe offset '%s'\n",
                                        progname, argv[0], optarg);
@@ -4484,9 +4488,10 @@ static int lfs_setstripe_internal(int argc, char **argv,
                        param->lsp_stripe_size = lsa.lsa_stripe_size;
                if (lsa.lsa_stripe_count != LLAPI_LAYOUT_DEFAULT) {
                        if (lsa.lsa_stripe_count >= LLAPI_LAYOUT_WIDE_MIN &&
-                               lsa.lsa_stripe_count < LLAPI_LAYOUT_WIDE_MAX)
-                               param->lsp_stripe_count = LOV_ALL_STRIPES_MIN +
-                               (lsa.lsa_stripe_count - LLAPI_LAYOUT_WIDE_MIN);
+                           lsa.lsa_stripe_count <= LLAPI_LAYOUT_WIDE_MAX)
+                               param->lsp_stripe_count =
+                                       LLAPI_LAYOUT_WIDE_MIN -
+                                       (lsa.lsa_stripe_count + 1);
                        else
                                param->lsp_stripe_count = lsa.lsa_stripe_count;
                }
@@ -7166,7 +7171,7 @@ static int mntdf(char *mntdir, char *fsname, char *pool, enum mntdf_flags flags,
                if (!(tp->st_op & ops))
                        continue;
 
-               for (index = 0; index < LOV_ALL_STRIPES_MAX &&
+               for (index = 0; index < LOV_ALL_STRIPES &&
                     (!lsb || lsb->sb_count < LL_STATFS_MAX); index++) {
                        memset(&stat_buf, 0, sizeof(struct obd_statfs));
                        memset(&uuid_buf, 0, sizeof(struct obd_uuid));
@@ -7345,7 +7350,7 @@ static int lfs_setdirstripe(int argc, char **argv)
                        errno = 0;
                        lsa.lsa_stripe_count = strtoul(optarg, &end, 0);
                        if (errno != 0 || *end != '\0' ||
-                           lsa.lsa_stripe_count < LLAPI_MAX_STRIPE_COUNT ||
+                           lsa.lsa_stripe_count < LLAPI_OVERSTRIPE_COUNT_MAX ||
                            lsa.lsa_stripe_count > LOV_MAX_STRIPE_COUNT) {
                                fprintf(stderr,
                                        "%s: invalid stripe count '%s'\n",
@@ -9106,7 +9111,7 @@ static int tgt_name2index(const char *tgtname, unsigned int *idx)
        dash += 4;
 
        *idx = strtoul(dash, &endp, 16);
-       if (*idx > LOV_V1_INSANE_STRIPE_COUNT) {
+       if (*idx > LOV_V1_INSANE_STRIPE_INDEX) {
                fprintf(stderr, "wrong index %s\n", tgtname);
                return -ERANGE;
        }
@@ -9637,7 +9642,7 @@ static int lfs_quota(int argc, char **argv)
                case 'm':
                        errno = 0;
                        idx = strtol(optarg, &endp, 0);
-                       if (errno != 0 || idx > LOV_V1_INSANE_STRIPE_COUNT ||
+                       if (errno != 0 || idx > LOV_V1_INSANE_STRIPE_INDEX ||
                            idx < 0 || *endp != '\0') {
                                fprintf(stderr,
                                        "%s quota: invalid MDT index '%s'\n",
@@ -9658,7 +9663,7 @@ static int lfs_quota(int argc, char **argv)
                        idx = strtol(optarg, &endp, 0);
                        /* simple digit, treat it as a numerical OST index */
                        if (*endp == '\0') {
-                               if (idx > LOV_V1_INSANE_STRIPE_COUNT ||
+                               if (idx > LOV_V1_INSANE_STRIPE_INDEX ||
                                    idx < 0) {
                                        fprintf(stderr,
                                                "%s quota: invalid OST index '%s'\n",
index 066d6e9..498ed04 100644 (file)
@@ -683,12 +683,11 @@ struct llapi_layout *llapi_layout_get_by_xattr(void *lov_xattr,
                else
                        comp->llc_stripe_size = v1->lmm_stripe_size;
 
-               if (v1->lmm_stripe_count >= (typeof(v1->lmm_stripe_count))
-                    LOV_ALL_STRIPES_MIN && v1->lmm_stripe_count <=
-                    (typeof(v1->lmm_stripe_count)) LOV_ALL_STRIPES_MAX)
-                       comp->llc_stripe_count =
-                       LLAPI_LAYOUT_WIDE_MIN +
-                       (v1->lmm_stripe_count -  LOV_ALL_STRIPES_MIN);
+               if (v1->lmm_stripe_count >= LOV_ALL_STRIPES_WIDE &&
+                   v1->lmm_stripe_count <= LOV_ALL_STRIPES)
+                       comp->llc_stripe_count = LLAPI_LAYOUT_WIDE_MIN +
+                                               (LOV_ALL_STRIPES -
+                                                v1->lmm_stripe_count);
                else if (v1->lmm_stripe_count == 0)
                        comp->llc_stripe_count = LLAPI_LAYOUT_DEFAULT;
                else
@@ -876,8 +875,9 @@ llapi_layout_to_lum(const struct llapi_layout *layout)
                        blob->lmm_stripe_count = 0;
                else if (comp->llc_stripe_count >= LLAPI_LAYOUT_WIDE_MIN &&
                         comp->llc_stripe_count <= LLAPI_LAYOUT_WIDE_MAX) {
-                       blob->lmm_stripe_count = LOV_ALL_STRIPES_MIN +
-                       (comp->llc_stripe_count - LLAPI_LAYOUT_WIDE_MIN);
+                       blob->lmm_stripe_count = LOV_ALL_STRIPES -
+                               (comp->llc_stripe_count -
+                                LLAPI_LAYOUT_WIDE_MIN);
                }
                else
                        blob->lmm_stripe_count = comp->llc_stripe_count;
@@ -1309,9 +1309,7 @@ bool llapi_layout_stripe_count_is_valid(int64_t stripe_count)
        return stripe_count == LLAPI_LAYOUT_DEFAULT ||
                (stripe_count >= LLAPI_LAYOUT_WIDE_MIN &&
                 stripe_count <= LLAPI_LAYOUT_WIDE_MAX) ||
-               (stripe_count != 0 && !(stripe_count <=
-                LLAPI_MIN_STRIPE_COUNT &&
-                stripe_count >= LLAPI_MAX_STRIPE_COUNT) &&
+               (stripe_count > 0 &&
                 llapi_stripe_count_is_valid(stripe_count));
 }
 
index 7e1dd40..a67e745 100644 (file)
@@ -44,6 +44,8 @@
 #include <linux/lustre/lustre_ioctl.h>
 #include <linux/lustre/lustre_kernelcomm.h>
 
+#include <lustre/lustreapi.h>
+
 #define MAX_IOC_BUFLEN 8192
 #define MAX_LINE_LEN    256
 #define MAX_INSTANCE_LEN  32
@@ -130,13 +132,13 @@ static inline bool llapi_stripe_size_is_too_big(uint64_t size)
 
 static inline bool llapi_stripe_count_is_valid(int64_t count)
 {
-       return (count >= LOV_ALL_STRIPES_MIN && count <= LOV_ALL_STRIPES_MAX) ||
-                  count <= LOV_MAX_STRIPE_COUNT;
+       return count >= LLAPI_OVERSTRIPE_COUNT_MAX &&
+              count <= LOV_MAX_STRIPE_COUNT;
 }
 
 static inline bool llapi_stripe_index_is_valid(int64_t index)
 {
-       return index >= -1 && index <= LOV_V1_INSANE_STRIPE_COUNT;
+       return index >= -1 && index <= LOV_V1_INSANE_STRIPE_INDEX;
 }
 
 static inline bool llapi_pool_name_is_valid(const char **pool_name)