From: Jian Yu Date: Fri, 19 Feb 2021 23:33:34 +0000 (-0800) Subject: LU-14385 tests: verify lfs setstripe comp-flags and flags options X-Git-Tag: 2.14.51~80 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=4b40d2bd165308457c033d468961a2e9347baf23 LU-14385 tests: verify lfs setstripe comp-flags and flags options 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 Reviewed-on: https://review.whamcloud.com/41423 Tested-by: jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: Oleg Drokin --- diff --git a/lustre/tests/create_foreign_dir.c b/lustre/tests/create_foreign_dir.c index 7cd9b77..a0601bf 100644 --- a/lustre/tests/create_foreign_dir.c +++ b/lustre/tests/create_foreign_dir.c @@ -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); diff --git a/lustre/tests/create_foreign_file.c b/lustre/tests/create_foreign_file.c index acd5540..71caa3e 100644 --- a/lustre/tests/create_foreign_file.c +++ b/lustre/tests/create_foreign_file.c @@ -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); diff --git a/lustre/tests/sanity-flr.sh b/lustre/tests/sanity-flr.sh index 9c53120..9c7329a 100644 --- a/lustre/tests/sanity-flr.sh +++ b/lustre/tests/sanity-flr.sh @@ -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 diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index af78fe5..a56b131 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -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" diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index c1497a3..78615c9 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -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" + " \n" + " or\n" "To create a file with a foreign (free format) layout:\n" "usage: setstripe --foreign[=]\n" " --xattr|-x [--flags ]\n" @@ -493,7 +499,6 @@ command_t cmdlist[] = { " [[!] --gid|-g|--group|-G |]\n" " [[!] --uid|-u|--user|-U |] [[!] --pool ]\n" " [[!] --projid ]\n" - " [[!] --foreign[=]]\n" " [[!] --layout|-L released,raid0,mdt]\n" " [[!] --foreign[=]]\n" " [[!] --component-count [+-]]\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':