aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Chinner <dchinner@redhat.com>2017-12-06 17:14:27 -0600
committerEric Sandeen <sandeen@redhat.com>2017-12-06 17:14:27 -0600
commit68344ba0f8cea778919e17958969b6c2459f890a (patch)
tree520c7e29095b93985238c7dbb343af6daa024067
parente2847e5c0a0037f5bad1fb4edcb3f639fff44cae (diff)
downloadxfsprogs-dev-68344ba0f8cea778919e17958969b6c2459f890a.tar.gz
mkfs: introduce default configuration structure
mkfs has lots of options that require default values. Some of these are centralised, but others aren't. Introduce a new structure designed to hold default values for all the parameters that need defaults in one place. This structure also provides a mechanism for providing mkfs defaults from a config file. This is not implemented in this series, but a comment is left where it is expected this functionality will hook in. Signed-Off-By: Dave Chinner <dchinner@redhat.com> Reviewed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
-rw-r--r--mkfs/xfs_mkfs.c77
1 files changed, 61 insertions, 16 deletions
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 1b23ada2b5..a7d087b37b 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -862,6 +862,27 @@ struct mkfs_params {
struct sb_feat_args sb_feat;
};
+/*
+ * Default filesystem features and configuration values
+ *
+ * This structure contains the default mkfs values that are to be used when
+ * a user does not specify the option on the command line. We do not use these
+ * values directly - they are inputs to the mkfs geometry validation and
+ * calculations.
+ */
+struct mkfs_default_params {
+ char *source; /* where the defaults came from */
+
+ int sectorsize;
+ int blocksize;
+
+ /* feature flags that are set */
+ struct sb_feat_args sb_feat;
+
+ /* root inode characteristics */
+ struct fsxattr fsx;
+};
+
#define TERABYTES(count, blog) ((uint64_t)(count) << (40 - (blog)))
#define GIGABYTES(count, blog) ((uint64_t)(count) << (30 - (blog)))
#define MEGABYTES(count, blog) ((uint64_t)(count) << (20 - (blog)))
@@ -2608,25 +2629,33 @@ main(
int worst_freelist;
libxfs_init_t xi;
struct fs_topology ft;
- struct sb_feat_args sb_feat = {
- .finobt = 1,
- .spinodes = 0,
- .log_version = 2,
- .attr_version = 2,
- .dir_version = XFS_DFL_DIR_VERSION,
- .inode_align = XFS_IFLAG_ALIGN,
- .nci = false,
- .lazy_sb_counters = true,
- .projid16bit = false,
- .crcs_enabled = true,
- .dirftype = true,
- .parent_pointers = false,
- .rmapbt = false,
- .reflink = false,
+ struct sb_feat_args sb_feat;
+ /* build time defaults */
+ struct mkfs_default_params dft = {
+ .source = "package build definitions",
+ .sectorsize = XFS_MIN_SECTORSIZE,
+ .blocksize = 1 << XFS_DFL_BLOCKSIZE_LOG,
+ .sb_feat = {
+ .log_version = 2,
+ .attr_version = 2,
+ .dir_version = XFS_DFL_DIR_VERSION,
+ .inode_align = XFS_IFLAG_ALIGN,
+ .nci = false,
+ .lazy_sb_counters = true,
+ .projid16bit = false,
+ .crcs_enabled = true,
+ .dirftype = true,
+ .finobt = true,
+ .spinodes = false,
+ .rmapbt = false,
+ .reflink = false,
+ .parent_pointers = false,
+ .nodalign = false,
+ .nortalign = false,
+ },
};
struct cli_params cli = {
.xi = &xi,
- .sb_feat = sb_feat,
};
struct mkfs_params cfg = {};
@@ -2636,6 +2665,22 @@ main(
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
+ /*
+ * TODO: Sourcing defaults from a config file
+ *
+ * Before anything else, see if there's a config file with different
+ * defaults. If a file exists in <package location>, read in the new
+ * default values and overwrite them in the &dft structure. This way the
+ * new defaults will apply before we parse the CLI, and the CLI will
+ * still be able to override them. Emit a message to indicate where the
+ * defaults being used came from.
+ */
+ printf(_("Default configuration sourced from %s\n"), dft.source);
+
+ /* 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));
+
blflag = bsflag = slflag = ssflag = lslflag = lssflag = 0;
blocklog = blocksize = 0;
sectorlog = lsectorlog = 0;