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>
flags = strtoul(optarg, &end, 0);
flags = strtoul(optarg, &end, 0);
+ if (errno != 0 || *end != '\0' ||
+ flags >= UINT32_MAX) {
fprintf(stderr,
"%s: invalid flags '%s'\n", argv[0],
optarg);
fprintf(stderr,
"%s: invalid flags '%s'\n", argv[0],
optarg);
flags = strtoul(optarg, &end, 0);
flags = strtoul(optarg, &end, 0);
+ if (errno != 0 || *end != '\0' ||
+ flags >= UINT32_MAX) {
fprintf(stderr,
"%s: invalid flags '%s'\n", argv[0],
optarg);
fprintf(stderr,
"%s: invalid flags '%s'\n", argv[0],
optarg);
test_0g() {
local tf=$DIR/$tfile
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"
$LFS mirror create -N -E 1M -S 1M -o0 --flags=prefer -E eof -o1 \
-N -o1 $tf || error "create mirrored file $tf failed"
verify_comp_attr lcme_flags $tf 0x10002 prefer
# set flags to the first component
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
$LFS setstripe --comp-set -I 0x10001 --comp-flags=^prefer,stale $tf
verify_comp_attr lcme_flags $tf 0x10001 stale
local uuid2=$(cat /proc/sys/kernel/random/uuid)
# create foreign file (raw way)
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"
create_foreign_file -f $DIR/$tdir/$tfile -x "${uuid1}@${uuid2}" \
-t 1 -F 0xda08 || error "create_foreign_file failed"
local uuid2=$(cat /proc/sys/kernel/random/uuid)
# create foreign dir (raw way)
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"
create_foreign_dir -d $DIR/$tdir/$tdir -x "${uuid1}@${uuid2}" -t 1 ||
error "create_foreign_dir FAILED"
"\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"
"\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"
"To create a file with a foreign (free format) layout:\n"
"usage: setstripe --foreign[=<foreign_type>]\n"
" --xattr|-x <layout_string> [--flags <hex>]\n"
" [[!] --gid|-g|--group|-G <gid>|<gname>]\n"
" [[!] --uid|-u|--user|-U <uid>|<uname>] [[!] --pool <pool>]\n"
" [[!] --projid <projid>]\n"
" [[!] --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"
" [[!] --layout|-L released,raid0,mdt]\n"
" [[!] --foreign[=<foreign_type>]]\n"
" [[!] --component-count [+-]<comp_cnt>]\n"
static int comp_str2flags(char *string, __u32 *flags, __u32 *neg_flags)
{
char *name;
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;
*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;
bool found = false;
int i;
llapi_printf(LLAPI_MSG_ERROR,
"%s: component flag '%s' not supported\n",
progname, name);
llapi_printf(LLAPI_MSG_ERROR,
"%s: component flag '%s' not supported\n",
progname, name);
+ rc = -EINVAL;
+ goto out_free;
}
}
if (!*flags && !*neg_flags)
}
}
if (!*flags && !*neg_flags)
/* don't allow to set and exclude the same flag */
if (*flags & *neg_flags)
/* don't allow to set and exclude the same flag */
if (*flags & *neg_flags)
+out_free:
+ free(dup_string);
+ return rc;
}
static int mirror_str2state(char *string, __u16 *state, __u16 *neg_state)
}
static int mirror_str2state(char *string, __u16 *state, __u16 *neg_state)
/* check for numeric flags (foreign and mirror cases) */
if (setstripe_mode && !mirror_mode && !last_mirror) {
/* check for numeric flags (foreign and mirror cases) */
if (setstripe_mode && !mirror_mode && !last_mirror) {
flags = strtoul(optarg, &end, 16);
flags = strtoul(optarg, &end, 16);
+ if (errno != 0 || *end != '\0' ||
+ flags >= UINT32_MAX) {
- "%s %s: bad flags '%s'\n",
+ "%s %s: invalid hex flags '%s'\n",
progname, argv[0], optarg);
return CMD_HELP;
}
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;
+ }
.has_arg = required_argument },
{ .val = LFS_MIRROR_STATE_OPT,
.name = "mirror-state", .has_arg = required_argument },
.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,
{ .val = LFS_NEWERXY_OPT,
.name = "newer", .has_arg = required_argument},
{ .val = LFS_NEWERXY_OPT,
foreign_mode = true;
break;
case LFS_LAYOUT_FLAGS_OPT:
foreign_mode = true;
break;
case LFS_LAYOUT_FLAGS_OPT:
flags = strtoul(optarg, &end, 16);
flags = strtoul(optarg, &end, 16);
+ if (errno != 0 || *end != '\0' ||
+ flags >= UINT32_MAX) {
- "%s %s: bad flags '%s'\n",
+ "%s %s: invalid hex flags '%s'\n",
progname, argv[0], optarg);
return CMD_HELP;
}
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':
break;
#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
case 't':