]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mkfs: resolve sector size CLI conflicts
authorDave Chinner <dchinner@redhat.com>
Wed, 3 Jan 2018 20:10:10 +0000 (14:10 -0600)
committerEric Sandeen <sandeen@redhat.com>
Wed, 3 Jan 2018 20:10:10 +0000 (14:10 -0600)
Now we have a two dimensional conflict array, convert the sector
size CLI option conflict determination to use it. To get the error
specification just right, we also need to tweak how we store
and validate the sector size CLI parameter state in the options
table.

Old:

$ mkfs.xfs -N -s size=4k -d sectsize=512 /dev/pmem0
Cannot specify both -d sectsize and -d sectlog
.....

New:

$ mkfs.xfs -N -s size=4k -d sectsize=512 /dev/pmem0
Cannot specify both -s size and -d sectsize
.....

Signed-Off-By: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@sandeen.net>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
mkfs/xfs_mkfs.c

index dc1a6aacf587c7180f2110f5be174a67a39ddf2f..a3eb1be24a8f393bb1c79596b85c40802076c7e9 100644 (file)
@@ -230,6 +230,13 @@ struct opt_params {
        }               subopt_params[MAX_SUBOPTS];
 };
 
+/*
+ * The two dimensional conflict array requires some initialisations to know
+ * about tables that haven't yet been defined. Work around this ordering
+ * issue with extern definitions here.
+ */
+extern struct opt_params sopts;
+
 struct opt_params bopts = {
        .name = 'b',
        .subopts = {
@@ -348,6 +355,10 @@ struct opt_params dopts = {
                },
                { .index = D_SECTLOG,
                  .conflicts = { { &dopts, D_SECTSIZE },
+                                { &sopts, S_SIZE },
+                                { &sopts, S_SECTSIZE },
+                                { &sopts, S_LOG },
+                                { &sopts, S_SECTLOG },
                                 { NULL, LAST_CONFLICT } },
                  .minval = XFS_MIN_SECTORSIZE_LOG,
                  .maxval = XFS_MAX_SECTORSIZE_LOG,
@@ -355,6 +366,10 @@ struct opt_params dopts = {
                },
                { .index = D_SECTSIZE,
                  .conflicts = { { &dopts, D_SECTLOG },
+                                { &sopts, S_SIZE },
+                                { &sopts, S_SECTSIZE },
+                                { &sopts, S_LOG },
+                                { &sopts, S_SECTLOG },
                                 { NULL, LAST_CONFLICT } },
                  .convert = true,
                  .is_power_2 = true,
@@ -680,6 +695,9 @@ struct opt_params sopts = {
                { .index = S_LOG,
                  .conflicts = { { &sopts, S_SIZE },
                                 { &sopts, S_SECTSIZE },
+                                { &sopts, S_SECTLOG },
+                                { &dopts, D_SECTSIZE },
+                                { &dopts, D_SECTLOG },
                                 { NULL, LAST_CONFLICT } },
                  .minval = XFS_MIN_SECTORSIZE_LOG,
                  .maxval = XFS_MAX_SECTORSIZE_LOG,
@@ -688,6 +706,9 @@ struct opt_params sopts = {
                { .index = S_SECTLOG,
                  .conflicts = { { &sopts, S_SIZE },
                                 { &sopts, S_SECTSIZE },
+                                { &sopts, S_LOG },
+                                { &dopts, D_SECTSIZE },
+                                { &dopts, D_SECTLOG },
                                 { NULL, LAST_CONFLICT } },
                  .minval = XFS_MIN_SECTORSIZE_LOG,
                  .maxval = XFS_MAX_SECTORSIZE_LOG,
@@ -696,6 +717,9 @@ struct opt_params sopts = {
                { .index = S_SIZE,
                  .conflicts = { { &sopts, S_LOG },
                                 { &sopts, S_SECTLOG },
+                                { &sopts, S_SECTSIZE },
+                                { &dopts, D_SECTSIZE },
+                                { &dopts, D_SECTLOG },
                                 { NULL, LAST_CONFLICT } },
                  .convert = true,
                  .is_power_2 = true,
@@ -706,6 +730,9 @@ struct opt_params sopts = {
                { .index = S_SECTSIZE,
                  .conflicts = { { &sopts, S_LOG },
                                 { &sopts, S_SECTLOG },
+                                { &sopts, S_SIZE },
+                                { &dopts, D_SECTSIZE },
+                                { &dopts, D_SECTLOG },
                                 { NULL, LAST_CONFLICT } },
                  .convert = true,
                  .is_power_2 = true,
@@ -963,8 +990,8 @@ conflict(
        int                     conflict)
 {
        fprintf(stderr, _("Cannot specify both -%c %s and -%c %s\n"),
-                       opts->name, opts->subopts[option],
-                       con_opts->name, con_opts->subopts[conflict]);
+                       con_opts->name, con_opts->subopts[conflict],
+                       opts->name, opts->subopts[option]);
        usage();
 }
 
@@ -1522,14 +1549,10 @@ data_opts_parser(
                cli->sb_feat.nodalign = getnum(value, opts, D_NOALIGN);
                break;
        case D_SECTLOG:
-               if (cli->sectorsize)
-                       conflict(opts, D_SECTSIZE, opts, D_SECTLOG);
                sectorlog = getnum(value, opts, D_SECTLOG);
                cli->sectorsize = 1 << sectorlog;
                break;
        case D_SECTSIZE:
-               if (cli->sectorsize)
-                       conflict(opts, D_SECTSIZE, opts, D_SECTLOG);
                cli->sectorsize = getnum(value, opts, D_SECTSIZE);
                break;
        case D_RTINHERIT:
@@ -1755,17 +1778,13 @@ sector_opts_parser(
        switch (subopt) {
        case S_LOG:
        case S_SECTLOG:
-               if (cli->sectorsize)
-                       conflict(opts, S_SECTSIZE, opts, S_SECTLOG);
-               sectorlog = getnum(value, opts, S_SECTLOG);
+               sectorlog = getnum(value, opts, subopt);
                cli->sectorsize = 1 << sectorlog;
                cli->lsectorsize = cli->sectorsize;
                break;
        case S_SIZE:
        case S_SECTSIZE:
-               if (cli->sectorsize)
-                       conflict(opts, S_SECTSIZE, opts, S_SECTLOG);
-               cli->sectorsize = getnum(value, opts, S_SECTSIZE);
+               cli->sectorsize = getnum(value, opts, subopt);
                cli->lsectorsize = cli->sectorsize;
                break;
        default: