All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: sandeen@redhat.com, darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 4/5] mkfs: emit config file from builtin defaults
Date: Wed, 13 Jun 2018 12:32:11 -0700	[thread overview]
Message-ID: <152891833127.3968.5527165230597489132.stgit@magnolia> (raw)
In-Reply-To: <152891829964.3968.4760134019673731615.stgit@magnolia>

From: Darrick J. Wong <darrick.wong@oracle.com>

Create a build-time helper program to generate a config file from the
built-in defaults.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 mkfs/Makefile   |   14 ++++-
 mkfs/mkconfig.c |  163 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 176 insertions(+), 1 deletion(-)
 create mode 100644 mkfs/mkconfig.c


diff --git a/mkfs/Makefile b/mkfs/Makefile
index 102f5214..44ddbd30 100644
--- a/mkfs/Makefile
+++ b/mkfs/Makefile
@@ -12,13 +12,24 @@ CFILES = proto.c xfs_mkfs.c config.c defaults.c
 
 CFGFILE_CFLAGS = -DMKFS_XFS_CONF_DIR=\"$(PKG_MKFS_CFG_DIR)\" \
 		 -DMKFS_XFS_DEFAULT_CONFIG=\"$(PKG_MKFS_DEFAULT_CFGFILE)\"
+CFGFILE_TEMPLATE = $(PKG_MKFS_DEFAULT_CFGFILE).template
+
 LCFLAGS += $(CFGFILE_CFLAGS)
 LLDLIBS += $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBRT) $(LIBPTHREAD) $(LIBBLKID) \
 	$(LIBUUID)
 LTDEPENDENCIES += $(LIBXFS) $(LIBXCMD) $(LIBFROG)
 LLDFLAGS = -static-libtool-libs
+LDIRT = $(CFGFILE_TEMPLATE)
+
+default: depend $(CFGFILE_TEMPLATE) $(LTCOMMAND)
+
+mkconfig: mkconfig.c defaults.c
+	@echo "    [CC]     mkconfig"
+	$(Q) $(BUILD_CC) $(BUILD_CFLAGS) $(CFGFILE_CFLAGS) -o $@ $^
 
-default: depend $(LTCOMMAND)
+$(CFGFILE_TEMPLATE): mkconfig
+	@echo "    [GENERATE] $@"
+	$(Q) ./mkconfig > $@
 
 include $(BUILDRULES)
 
@@ -27,6 +38,7 @@ install: default
 	$(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_ROOT_SBIN_DIR)
 	$(INSTALL) -m 755 -d $(PKG_CFG_DIR)
 	$(INSTALL) -m 755 -d $(PKG_MKFS_CFG_DIR)
+	$(INSTALL) -m 644 $(CFGFILE_TEMPLATE) $(PKG_MKFS_CFG_DIR)
 install-dev:
 
 -include .dep
diff --git a/mkfs/mkconfig.c b/mkfs/mkconfig.c
new file mode 100644
index 00000000..3826b0bf
--- /dev/null
+++ b/mkfs/mkconfig.c
@@ -0,0 +1,163 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Oracle.  All Rights Reserved.
+ * Author: Darrick J. Wong <darrick.wong@oracle.com>
+ */
+#include "libxfs.h"
+#include "config.h"
+
+enum cfgfile_var_type {
+	FV_BOOL = 0
+};
+
+struct subopt_map {
+	const char		*suboptname;
+	const void		*ptr;
+	enum cfgfile_var_type	type;
+};
+
+/* Map all the config file options to their default_features equivalents. */
+struct confopts {
+	const char		*name;
+	struct subopt_map	subopts[CFG_MAX_SUBOPTS];
+} confopts_tab[] = {
+	{
+		.name = "data",
+		.subopts = {
+			[CFG_D_NOALIGN] = {
+				.suboptname	= "noalign",
+				.ptr		= &default_features.nodalign,
+				.type		= FV_BOOL,
+			},
+			{NULL}
+		},
+	},
+	{
+		.name = "inode",
+		.subopts = {
+			[CFG_I_ALIGN] = {
+				.suboptname	= "align",
+				.ptr		= &default_features.inode_align,
+				.type		= FV_BOOL,
+			},
+			[CFG_I_PROJID32BIT] = {
+				.suboptname	= "projid32bit",
+				.ptr		= &default_features.projid32bit,
+				.type		= FV_BOOL,
+			},
+			[CFG_I_SPINODES] = {
+				.suboptname	= "sparse",
+				.ptr		= &default_features.spinodes,
+				.type		= FV_BOOL,
+			},
+			{NULL}
+		},
+	},
+	{
+		.name = "log",
+		.subopts = {
+			[CFG_L_LAZYSBCNTR] = {
+				.suboptname	= "lazy-count",
+				.ptr		= &default_features.lazy_sb_counters,
+				.type		= FV_BOOL,
+			},
+			{NULL}
+		},
+	},
+	{
+		.name = "metadata",
+		.subopts = {
+			[CFG_M_CRC] = {
+				.suboptname	= "crc",
+				.ptr		= &default_features.crcs_enabled,
+				.type		= FV_BOOL,
+			},
+			[CFG_M_FINOBT] = {
+				.suboptname	= "finobt",
+				.ptr		= &default_features.finobt,
+				.type		= FV_BOOL,
+			},
+			[CFG_M_RMAPBT] = {
+				.suboptname	= "rmapbt",
+				.ptr		= &default_features.rmapbt,
+				.type		= FV_BOOL,
+			},
+			[CFG_M_REFLINK] = {
+				.suboptname	= "reflink",
+				.ptr		= &default_features.reflink,
+				.type		= FV_BOOL,
+			},
+			{NULL}
+		},
+	},
+	{
+		.name = "naming",
+		.subopts = {
+			[CFG_N_FTYPE] = {
+				.suboptname	= "ftype",
+				.ptr		= &default_features.dirftype,
+				.type		= FV_BOOL,
+			},
+			{NULL}
+		},
+	},
+	{
+		.name = "rtdev",
+		.subopts = {
+			[CFG_R_NOALIGN] = {
+				.suboptname	= "noalign",
+				.ptr		= &default_features.nortalign,
+				.type		= FV_BOOL,
+			},
+			{NULL}
+		},
+	},
+};
+
+/* Spit out a config file template. */
+int
+main(
+	int			argc,
+	char			*argv[])
+{
+	struct confopts		*opts = confopts_tab;
+	struct subopt_map	*submap;
+	int			c;
+	unsigned int		i, j;
+
+	while ((c = getopt(argc, argv, "")) != EOF) {
+		switch (c) {
+		case '?':
+			fprintf(stderr, "Unknown option %c.\n", optopt);
+			return 1;
+		}
+	}
+	if (argc - optind != 0) {
+		fprintf(stderr, "extra arguments\n");
+		return 1;
+	}
+
+	printf("# mkfs.xfs configuration file to collect settings.\n");
+	printf("# See the mkfs.xfs(8) manpage for details.\n");
+	printf("# Copy this file to %s/%s to override the built-in defaults.\n",
+			MKFS_XFS_CONF_DIR, MKFS_XFS_DEFAULT_CONFIG);
+
+	for (i = 0; i < ARRAY_SIZE(confopts_tab); i++, opts++) {
+		if (i > 0)
+			printf("\n");
+		printf("[%s]\n", opts->name);
+		submap = opts->subopts;
+		for (j = 0;
+		     j < ARRAY_SIZE(opts->subopts) && submap->suboptname;
+		     j++, submap++) {
+			printf("%s = ", submap->suboptname);
+			switch (submap->type) {
+			case FV_BOOL:
+				printf("%d\n", *((bool *)submap->ptr));
+				break;
+			}
+		}
+	}
+
+	return 0;
+}


  parent reply	other threads:[~2018-06-13 19:32 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-13 19:31 [PATCH 0/5] xfsprogs-4.17: mkfs config file enhancements Darrick J. Wong
2018-06-13 19:31 ` [PATCH 1/5] mkfs: move build-time defaults to a separate file Darrick J. Wong
2018-06-14  2:34   ` Eric Sandeen
2018-06-13 19:31 ` [PATCH 2/5] mkfs: move config file enums to config.h Darrick J. Wong
2018-06-14  2:51   ` Eric Sandeen
2018-06-14 16:24     ` Luis R. Rodriguez
2018-06-13 19:32 ` [PATCH 3/5] mkfs: hoist mkfs configfile dir string generation to build system Darrick J. Wong
2018-06-14  2:54   ` Eric Sandeen
2018-06-13 19:32 ` Darrick J. Wong [this message]
2018-06-14  3:05   ` [PATCH 4/5] mkfs: emit config file from builtin defaults Eric Sandeen
2018-06-13 19:32 ` [PATCH 5/5] mkfs: generate mkfs config file in man page Darrick J. Wong
2018-06-14  3:17   ` Eric Sandeen
2018-06-14  4:06 ` [PATCH 0/5] xfsprogs-4.17: mkfs config file enhancements Dave Chinner
2018-06-14  4:23   ` Eric Sandeen
2018-06-14  5:08     ` Dave Chinner
2018-06-14  6:29       ` Darrick J. Wong
2018-06-14 17:46         ` Luis R. Rodriguez
2018-06-14 17:59           ` Darrick J. Wong
2018-06-14 18:16             ` Luis R. Rodriguez
2018-06-14 18:35               ` Darrick J. Wong
2018-06-16  0:04                 ` Luis R. Rodriguez
2018-06-14 19:05             ` Eric Sandeen
2018-06-14 22:22               ` Dave Chinner
2018-06-14 23:33         ` Dave Chinner
2018-06-14 23:38           ` Eric Sandeen
2018-06-14 14:31       ` Eric Sandeen

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=152891833127.3968.5527165230597489132.stgit@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@redhat.com \
    /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.