aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-11-06 19:01:15 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-11-06 19:02:40 -0500
commitcc902bb4bf7d990dfd3f9b815fcfc6311fbe0088 (patch)
treeb96b7361249b74e89b962b41c3967049c5da5b42
parent26efa5cf2eb7b20777eaa512dbd9496ac76eda79 (diff)
downloadbcachefs-tools-cc902bb4bf7d990dfd3f9b815fcfc6311fbe0088.tar.gz
cmd_format: Check for device options after device arguments
It's a common user error to specify device specific options at the end of a format command, and then not have them apply to any devices - add a check for this. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--cmd_format.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/cmd_format.c b/cmd_format.c
index a44205e2..f0a4b6a5 100644
--- a/cmd_format.c
+++ b/cmd_format.c
@@ -119,6 +119,7 @@ int cmd_format(int argc, char *argv[])
struct format_opts opts = format_opts_default();
struct dev_opts dev_opts = dev_opts_default(), *dev;
bool force = false, no_passphrase = false, quiet = false, initialize = true, verbose = false;
+ bool unconsumed_dev_option = false;
unsigned v;
int opt;
@@ -162,6 +163,7 @@ int cmd_format(int argc, char *argv[])
case O_fs_size:
if (bch2_strtoull_h(optarg, &dev_opts.size))
die("invalid filesystem size");
+ unconsumed_dev_option = true;
break;
case O_superblock_size:
if (bch2_strtouint_h(optarg, &opts.superblock_size))
@@ -172,23 +174,28 @@ int cmd_format(int argc, char *argv[])
case O_bucket_size:
if (bch2_strtoull_h(optarg, &dev_opts.bucket_size))
die("bad bucket_size %s", optarg);
+ unconsumed_dev_option = true;
break;
case O_label:
case 'l':
dev_opts.label = optarg;
+ unconsumed_dev_option = true;
break;
case O_discard:
dev_opts.discard = true;
+ unconsumed_dev_option = true;
break;
case O_data_allowed:
dev_opts.data_allowed =
read_flag_list_or_die(optarg,
bch2_data_types, "data type");
+ unconsumed_dev_option = true;
break;
case O_durability:
if (kstrtouint(optarg, 10, &dev_opts.durability) ||
dev_opts.durability > BCH_REPLICAS_MAX)
die("invalid durability");
+ unconsumed_dev_option = true;
break;
case O_version:
if (kstrtouint(optarg, 10, &opts.version))
@@ -202,6 +209,7 @@ int cmd_format(int argc, char *argv[])
dev_opts.path = optarg;
darray_push(&devices, dev_opts);
dev_opts.size = 0;
+ unconsumed_dev_option = false;
break;
case O_quiet:
case 'q':
@@ -219,6 +227,9 @@ int cmd_format(int argc, char *argv[])
break;
}
+ if (unconsumed_dev_option)
+ die("Options for devices apply to subsequent devices; got a device option with no device");
+
if (opts.version != bcachefs_metadata_version_current)
initialize = false;