All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Luis R. Rodriguez" <mcgrof@kernel.org>
To: sandeen@sandeen.net, linux-xfs@vger.kernel.org
Cc: darrick.wong@oracle.com, jack@suse.com, jeffm@suse.com,
	okurz@suse.com, lpechacek@suse.com, jtulak@redhat.com,
	"Luis R. Rodriguez" <mcgrof@kernel.org>
Subject: [PATCH v2 4/5] mkfs: add helpers to process defaults
Date: Thu, 17 May 2018 12:26:59 -0700	[thread overview]
Message-ID: <20180517192700.23457-5-mcgrof@kernel.org> (raw)
In-Reply-To: <20180517192700.23457-1-mcgrof@kernel.org>

Move the built-in defaults globally and add helpers to reset and
process the defaults. This will be expanded on later. The commented
out print of the defaults source is moved below CLI processing to
acknowledge that one will later want to be able to specify a
different configuration file to be used through the CLI.

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 mkfs/xfs_mkfs.c | 93 ++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 63 insertions(+), 30 deletions(-)

diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index de0eab3f68e0..cb549be89835 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3662,6 +3662,61 @@ rewrite_secondary_superblocks(
 	libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
 }
 
+/* build time defaults */
+struct mkfs_default_params	built_in_dft = {
+	.type = DEFAULTS_BUILTIN,
+	.sectorsize = XFS_MIN_SECTORSIZE,
+	.blocksize = 1 << XFS_DFL_BLOCKSIZE_LOG,
+	.sb_feat = {
+		.log_version = 2,
+		.attr_version = 2,
+		.dir_version = 2,
+		.inode_align = true,
+		.nci = false,
+		.lazy_sb_counters = true,
+		.projid32bit = true,
+		.crcs_enabled = true,
+		.dirftype = true,
+		.finobt = true,
+		.spinodes = true,
+		.rmapbt = false,
+		.reflink = false,
+		.parent_pointers = false,
+		.nodalign = false,
+		.nortalign = false,
+	},
+};
+
+/* installs new defaults into the CLI parsing structure */
+static void install_defaults(
+	struct mkfs_default_params	*dft,
+	struct cli_params		*cli)
+{
+	memcpy(&cli->sb_feat, &dft->sb_feat, sizeof(cli->sb_feat));
+	memcpy(&cli->fsx, &dft->fsx, sizeof(cli->fsx));
+}
+
+/*
+ * Reset defaults first to built-in defaults. Then resets cli opts to start
+ * with these built-in defaults. All previously set CLI options will be ignored.
+ */
+static void reset_defaults_and_cli(
+	struct mkfs_default_params	*dft,
+	struct cli_params		*cli)
+{
+	*dft = built_in_dft;
+
+	install_defaults(dft, cli);
+}
+
+/* Does the required work to process a new set of defaults */
+static void process_defaults(
+	struct mkfs_default_params	*dft,
+	struct cli_params		*cli)
+{
+	install_defaults(dft, cli);
+}
+
 int
 main(
 	int			argc,
@@ -3694,31 +3749,9 @@ main(
 		.loginternal = 1,
 	};
 	struct mkfs_params	cfg = {};
+	struct mkfs_default_params	dft;
 
-	/* build time defaults */
-	struct mkfs_default_params	dft = {
-		.type = DEFAULTS_BUILTIN,
-		.sectorsize = XFS_MIN_SECTORSIZE,
-		.blocksize = 1 << XFS_DFL_BLOCKSIZE_LOG,
-		.sb_feat = {
-			.log_version = 2,
-			.attr_version = 2,
-			.dir_version = 2,
-			.inode_align = true,
-			.nci = false,
-			.lazy_sb_counters = true,
-			.projid32bit = true,
-			.crcs_enabled = true,
-			.dirftype = true,
-			.finobt = true,
-			.spinodes = true,
-			.rmapbt = false,
-			.reflink = false,
-			.parent_pointers = false,
-			.nodalign = false,
-			.nortalign = false,
-		},
-	};
+	reset_defaults_and_cli(&dft, &cli);
 
 	platform_uuid_generate(&cli.uuid);
 	progname = basename(argv[0]);
@@ -3736,14 +3769,9 @@ main(
 	 * still be able to override them. When more than one source is
 	 * implemented, emit a message to indicate where the defaults being
 	 * used came from.
-	 *
-	 * printf(_("Default configuration sourced from %s\n"),
-	 *	  default_type_str(dft.type));
 	 */
 
-	/* copy new defaults into CLI parsing structure */
-	memcpy(&cli.sb_feat, &dft.sb_feat, sizeof(cli.sb_feat));
-	memcpy(&cli.fsx, &dft.fsx, sizeof(cli.fsx));
+	process_defaults(&dft, &cli);
 
 	while ((c = getopt(argc, argv, "b:d:i:l:L:m:n:KNp:qr:s:CfV")) != EOF) {
 		switch (c) {
@@ -3795,6 +3823,11 @@ main(
 	} else
 		dfile = xi.dname;
 
+	/*
+	 * printf(_("Default configuration sourced from %s\n"),
+	 *	  default_type_str(dft.type));
+	 */
+
 	protostring = setup_proto(protofile);
 
 	/*
-- 
2.16.3


  parent reply	other threads:[~2018-05-17 19:27 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-17 19:26 [PATCH v2 0/5] xfsprogs: add mkfs.xfs configuration file parsing support Luis R. Rodriguez
2018-05-17 19:26 ` [PATCH v2 1/5] mkfs: distinguish between struct sb_feat_args and struct cli_params Luis R. Rodriguez
2018-05-17 22:02   ` Dave Chinner
2018-05-17 19:26 ` [PATCH v2 2/5] mkfs: move shared structs and cli params into their own headers Luis R. Rodriguez
2018-05-17 22:40   ` Dave Chinner
2018-05-17 23:54     ` Luis R. Rodriguez
2018-05-18  0:49       ` Dave Chinner
2018-05-19  1:33         ` Luis R. Rodriguez
2018-05-17 19:26 ` [PATCH v2 3/5] mkfs: replace defaults source with an enum Luis R. Rodriguez
2018-05-17 22:48   ` Dave Chinner
2018-05-17 23:09     ` Luis R. Rodriguez
2018-05-18  0:53       ` Dave Chinner
2018-05-17 19:26 ` Luis R. Rodriguez [this message]
2018-05-17 22:53   ` [PATCH v2 4/5] mkfs: add helpers to process defaults Dave Chinner
2018-05-18  0:06     ` Luis R. Rodriguez
2018-05-17 19:27 ` [PATCH v2 5/5] mkfs.xfs: add configuration file parsing support using our own parser Luis R. Rodriguez
2018-05-17 21:31   ` Darrick J. Wong
2018-05-18  0:29     ` Luis R. Rodriguez
2018-05-21 18:32     ` Luis R. Rodriguez
2018-05-18  0:44   ` Dave Chinner
2018-05-19  1:32     ` Luis R. Rodriguez
2018-05-21  0:14       ` Dave Chinner
2018-05-21 15:30         ` Darrick J. Wong
2018-05-21 16:58         ` Luis R. Rodriguez
2018-05-22 19:37     ` Luis R. Rodriguez
2018-05-18  3:24   ` Eric Sandeen
2018-05-18  3:46     ` Darrick J. Wong
2018-05-18 15:38       ` Luis R. Rodriguez
2018-05-18 17:09         ` Eric Sandeen
2018-05-18 23:56           ` Luis R. Rodriguez
2018-05-21  9:40             ` Jan Tulak
2018-05-25  0:50               ` Luis R. Rodriguez
2018-05-20  0:16       ` Dave Chinner
2018-05-21 15:33         ` Darrick J. Wong
2018-05-21 17:05           ` Luis R. Rodriguez
2018-05-21 22:10             ` Dave Chinner
2018-05-21 22:24               ` Eric Sandeen
2018-05-22  0:38                 ` Dave Chinner
2018-05-25  0:51                   ` Luis R. Rodriguez
2018-05-25  0:54           ` Luis R. Rodriguez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180517192700.23457-5-mcgrof@kernel.org \
    --to=mcgrof@kernel.org \
    --cc=darrick.wong@oracle.com \
    --cc=jack@suse.com \
    --cc=jeffm@suse.com \
    --cc=jtulak@redhat.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=lpechacek@suse.com \
    --cc=okurz@suse.com \
    --cc=sandeen@sandeen.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.