Whamcloud - gitweb
LU-14385 tests: verify lfs setstripe comp-flags and flags options 23/41423/5
authorJian Yu <yujian@whamcloud.com>
Fri, 19 Feb 2021 23:33:34 +0000 (15:33 -0800)
committerOleg Drokin <green@whamcloud.com>
Sat, 6 Mar 2021 02:35:37 +0000 (02:35 +0000)
This patch adds more test cases to verify lfs setstripe
--comp-flags|--component-flags and --flags options.

Change-Id: Ie09089ceb65372fdf4e3b50df3771c9a355210cc
Signed-off-by: Jian Yu <yujian@whamcloud.com>
Reviewed-on: https://review.whamcloud.com/41423
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: John L. Hammond <jhammond@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/create_foreign_dir.c
lustre/tests/create_foreign_file.c
lustre/tests/sanity-flr.sh
lustre/tests/sanity.sh
lustre/utils/lfs.c

index 7cd9b77..a0601bf 100644 (file)
@@ -36,8 +36,10 @@ int main(int argc, char **argv)
                        }
                        break;
                case 'f':
+                       errno = 0;
                        flags = strtoul(optarg, &end, 0);
-                       if (*end != '\0') {
+                       if (errno != 0 || *end != '\0' ||
+                           flags >= UINT32_MAX) {
                                fprintf(stderr,
                                        "%s: invalid flags '%s'\n", argv[0],
                                        optarg);
index acd5540..71caa3e 100644 (file)
@@ -37,8 +37,10 @@ int main(int argc, char **argv)
                        }
                        break;
                case 'F':
+                       errno = 0;
                        flags = strtoul(optarg, &end, 0);
-                       if (*end != '\0') {
+                       if (errno != 0 || *end != '\0' ||
+                           flags >= UINT32_MAX) {
                                fprintf(stderr,
                                        "%s: invalid flags '%s'\n", argv[0],
                                        optarg);
index 9c53120..9c7329a 100644 (file)
@@ -683,6 +683,21 @@ run_test 0f "lfs mirror extend composite layout mirrors"
 test_0g() {
        local tf=$DIR/$tfile
 
+       ! $LFS mirror create --flags prefer $tf ||
+               error "creating $tf w/ --flags but w/o -N option should fail"
+
+       ! $LFS mirror create -N --flags foo $tf ||
+               error "creating $tf with '--flags foo' should fail"
+
+       ! $LFS mirror create -N --flags stale $tf ||
+               error "creating $tf with '--flags stale' should fail"
+
+       ! $LFS mirror create -N --flags prefer,init $tf ||
+               error "creating $tf with '--flags prefer,init' should fail"
+
+       ! $LFS mirror create -N --flags ^prefer $tf ||
+               error "creating $tf with '--flags ^prefer' should fail"
+
        $LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
                           -N -o1 $tf || error "create mirrored file $tf failed"
 
@@ -730,6 +745,12 @@ test_0h() {
        verify_comp_attr lcme_flags $tf 0x10002 prefer
 
        # set flags to the first component
+       ! $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,foo $tf ||
+               error "setting '^prefer,foo' flags should fail"
+
+       ! $LFS getstripe --component-flags=prefer,foo $tf ||
+               error "getting component(s) with 'prefer,foo' flags should fail"
+
        $LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
 
        verify_comp_attr lcme_flags $tf 0x10001 stale
index af78fe5..a56b131 100755 (executable)
@@ -2721,6 +2721,17 @@ test_27J() {
        local uuid2=$(cat /proc/sys/kernel/random/uuid)
 
        # create foreign file (raw way)
+       ! $LFS setstripe --flags 0xda08 $DIR/$tdir/$tfile ||
+               error "creating $tfile w/ hex flags w/o --foreign should fail"
+
+       ! $LFS setstripe --foreign --flags foo \
+               --xattr ${uuid1}@${uuid2} $DIR/$tdir/$tfile ||
+                       error "creating $tfile with '--flags foo' should fail"
+
+       ! $LFS setstripe --foreign --flags 0xffffffff \
+               --xattr ${uuid1}@${uuid2} $DIR/$tdir/$tfile ||
+                       error "creating $tfile w/ 0xffffffff flags should fail"
+
        create_foreign_file -f $DIR/$tdir/$tfile -x "${uuid1}@${uuid2}" \
                -t 1 -F 0xda08 || error "create_foreign_file failed"
 
@@ -2816,6 +2827,17 @@ test_27K() {
        local uuid2=$(cat /proc/sys/kernel/random/uuid)
 
        # create foreign dir (raw way)
+       ! $LFS setdirstripe --flags 0xda08 $DIR/$tdir/$tdir ||
+               error "creating $tdir w/ hex flags w/o --foreign should fail"
+
+       ! $LFS setdirstripe --foreign --flags foo \
+               --xattr ${uuid1}@${uuid2} $DIR/$tdir/$tdir ||
+                       error "creating $tdir with '--flags foo' should fail"
+
+       ! $LFS setdirstripe --foreign --flags 0xffffffff \
+               --xattr ${uuid1}@${uuid2} $DIR/$tdir/$tdir ||
+                       error "creating $tdir w/ 0xffffffff flags should fail"
+
        create_foreign_dir -d $DIR/$tdir/$tdir -x "${uuid1}@${uuid2}" -t 1 ||
                error "create_foreign_dir FAILED"
 
index c1497a3..78615c9 100644 (file)
@@ -425,6 +425,12 @@ command_t cmdlist[] = {
         "\tcomp_flags:  'init' indicating all instantiated components\n"
         "\t             '^init' indicating all uninstantiated components\n"
         "\t-I and -F cannot be specified at the same time\n"
+        " or\n"
+        "To set or clear flags on a specific component\n"
+        "(note that this command can only be applied to mirrored files:\n"
+        "usage: setstripe --comp-set {-I comp_id|--comp-flags=comp_flags}\n"
+        "                            <filename>\n"
+        " or\n"
         "To create a file with a foreign (free format) layout:\n"
         "usage: setstripe --foreign[=<foreign_type>]\n"
         "                 --xattr|-x <layout_string> [--flags <hex>]\n"
@@ -493,7 +499,6 @@ command_t cmdlist[] = {
         "     [[!] --gid|-g|--group|-G <gid>|<gname>]\n"
         "     [[!] --uid|-u|--user|-U <uid>|<uname>] [[!] --pool <pool>]\n"
         "     [[!] --projid <projid>]\n"
-        "     [[!] --foreign[=<foreign_type>]]\n"
         "     [[!] --layout|-L released,raid0,mdt]\n"
         "     [[!] --foreign[=<foreign_type>]]\n"
         "     [[!] --component-count [+-]<comp_cnt>]\n"
@@ -1396,13 +1401,24 @@ out_closed:
 static int comp_str2flags(char *string, __u32 *flags, __u32 *neg_flags)
 {
        char *name;
-
-       if (!string)
-               return -EINVAL;
+       char *dup_string = NULL;
+       int rc = 0;
 
        *flags = 0;
        *neg_flags = 0;
-       for (name = strtok(string, ","); name; name = strtok(NULL, ",")) {
+
+       if (!string || !string[0])
+               return -EINVAL;
+
+       dup_string = strdup(string);
+       if (!dup_string) {
+               llapi_printf(LLAPI_MSG_ERROR,
+                            "%s: insufficient memory\n",
+                            progname);
+               return -ENOMEM;
+       }
+
+       for (name = strtok(dup_string, ","); name; name = strtok(NULL, ",")) {
                bool found = false;
                int i;
 
@@ -1423,18 +1439,21 @@ static int comp_str2flags(char *string, __u32 *flags, __u32 *neg_flags)
                        llapi_printf(LLAPI_MSG_ERROR,
                                     "%s: component flag '%s' not supported\n",
                                     progname, name);
-                       return -EINVAL;
+                       rc = -EINVAL;
+                       goto out_free;
                }
        }
 
        if (!*flags && !*neg_flags)
-               return -EINVAL;
+               rc = -EINVAL;
 
        /* don't allow to set and exclude the same flag */
        if (*flags & *neg_flags)
-               return -EINVAL;
+               rc = -EINVAL;
 
-       return 0;
+out_free:
+       free(dup_string);
+       return rc;
 }
 
 static int mirror_str2state(char *string, __u16 *state, __u16 *neg_state)
@@ -3409,13 +3428,21 @@ static int lfs_setstripe_internal(int argc, char **argv,
 
                        /* check for numeric flags (foreign and mirror cases) */
                        if (setstripe_mode && !mirror_mode && !last_mirror) {
+                               errno = 0;
                                flags = strtoul(optarg, &end, 16);
-                               if (*end != '\0') {
+                               if (errno != 0 || *end != '\0' ||
+                                   flags >= UINT32_MAX) {
                                        fprintf(stderr,
-                                               "%s %s: bad flags '%s'\n",
+                                               "%s %s: invalid hex flags '%s'\n",
                                                progname, argv[0], optarg);
                                        return CMD_HELP;
                                }
+                               if (!foreign_mode) {
+                                       fprintf(stderr,
+                                               "%s %s: hex flags must be specified with --foreign option\n",
+                                               progname, argv[0]);
+                                       return CMD_HELP;
+                               }
                                break;
                        }
 
@@ -4421,8 +4448,6 @@ static int lfs_find(int argc, char **argv)
                                                .has_arg = required_argument },
        { .val = LFS_MIRROR_STATE_OPT,
                        .name = "mirror-state", .has_arg = required_argument },
-       { .val = LFS_LAYOUT_FOREIGN_OPT,
-                       .name = "foreign",      .has_arg = optional_argument},
        { .val = LFS_NEWERXY_OPT,
                        .name = "newer",        .has_arg = required_argument},
        { .val = LFS_NEWERXY_OPT,
@@ -6208,13 +6233,21 @@ static int lfs_setdirstripe(int argc, char **argv)
                        foreign_mode = true;
                        break;
                case LFS_LAYOUT_FLAGS_OPT:
+                       errno = 0;
                        flags = strtoul(optarg, &end, 16);
-                       if (*end != '\0') {
+                       if (errno != 0 || *end != '\0' ||
+                           flags >= UINT32_MAX) {
                                fprintf(stderr,
-                                       "%s %s: bad flags '%s'\n",
+                                       "%s %s: invalid hex flags '%s'\n",
                                        progname, argv[0], optarg);
                                return CMD_HELP;
                        }
+                       if (!foreign_mode) {
+                               fprintf(stderr,
+                                       "%s %s: hex flags must be specified with --foreign option\n",
+                                       progname, argv[0]);
+                               return CMD_HELP;
+                       }
                        break;
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
                case 't':