]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
cmd_format: Check for device options after device arguments
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 7 Nov 2023 00:01:15 +0000 (19:01 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Tue, 7 Nov 2023 00:02:40 +0000 (19:02 -0500)
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>
cmd_format.c

index a44205e2497233f8615a3a8ab2b1bbcab827dad6..f0a4b6a54f51d4d21b61daada543555561dbf19f 100644 (file)
@@ -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;