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
commit4ab08e3b3f29f1e44040e35f388c0ed9d572be69 (patch)
tree6b1777ec19a8b8cd351f8e4f23b6878436d65796
parentf948f00a8ed70aaf3d64c15fd46b2562ca48918c (diff)
downloadxfsprogs-dev-4ab08e3b3f29f1e44040e35f388c0ed9d572be69.tar.gz
mkfs: Introduce mkfs configuration structure
Formatting the on disk XFS structures requires a certain set of validated and calculated parameters. By the time we start writing information to disk this has all been done. Abstract this information out into a separate structures and initialise it with all the calculated parameters so we can factor the mkfs formatting code to use it. 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.c89
1 files changed, 88 insertions, 1 deletions
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 641707cc3e..6fb7dcf437 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -735,7 +735,7 @@ cli_opt_set(
* geometry validation and override any default configuration value we have.
*
* We don't keep flags to indicate what parameters are set - if we need to check
- * if an option was set on teh command line, we check the relevant entry in the
+ * if an option was set on the command line, we check the relevant entry in the
* option table which records whether it was specified in the .seen and
* .str_seen variables in the table.
*
@@ -810,6 +810,58 @@ struct cli_params {
struct libxfs_xinit *xi;
};
+/*
+ * Calculated filesystem feature and geometry information.
+ *
+ * This structure contains the information we will use to create the on-disk
+ * filesystem from. The validation and calculation code uses it to store all the
+ * temporary and final config state for the filesystem.
+ *
+ * The information in this structure will contain a mix of validated CLI input
+ * variables, default feature state and calculated values that are needed to
+ * construct the superblock and other on disk features. These are all in one
+ * place so that we don't have to pass handfuls of seemingly arbitrary variables
+ * around to different functions to do the work we need to do.
+ */
+struct mkfs_params {
+ int blocksize;
+ int blocklog;
+ int sectorsize;
+ int sectorlog;
+ int lsectorsize;
+ int lsectorlog;
+ int dirblocksize;
+ int dirblocklog;
+ int inodesize;
+ int inodelog;
+ int inopblock;
+
+ uint64_t dblocks;
+ uint64_t logblocks;
+ uint64_t rtblocks;
+ uint64_t rtextblocks;
+ uint64_t rtextents;
+ uint64_t rtbmblocks; /* rt bitmap blocks */
+
+ int dsunit; /* in FSBs */
+ int dswidth; /* in FSBs */
+ int lsunit; /* in FSBs */
+
+ uint64_t agsize;
+ uint64_t agcount;
+
+ int imaxpct;
+
+ bool loginternal;
+ uint64_t logstart;
+ uint64_t logagno;
+
+ uuid_t uuid;
+ char *label;
+
+ struct sb_feat_args sb_feat;
+};
+
#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)))
@@ -1956,6 +2008,7 @@ main(
.xi = &xi,
.sb_feat = sb_feat,
};
+ struct mkfs_params cfg = {};
platform_uuid_generate(&uuid);
progname = basename(argv[0]);
@@ -2987,6 +3040,39 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
}
validate_log_size(logblocks, blocklog, min_logblocks);
+ /* Temp support code to set up mkfs cfg parameters */
+ cfg.blocksize = blocksize;
+ cfg.blocklog = blocklog;
+ cfg.sectorsize = sectorsize;
+ cfg.sectorlog = sectorlog;
+ cfg.lsectorsize = lsectorsize;
+ cfg.lsectorlog = lsectorlog;
+ cfg.dirblocksize = dirblocksize;
+ cfg.dirblocklog = dirblocklog;
+ cfg.inodesize = isize;
+ cfg.inodelog = inodelog;
+ cfg.inopblock = inopblock;
+
+ cfg.dblocks = dblocks;
+ cfg.logblocks = logblocks;
+ cfg.rtblocks = rtblocks;
+ cfg.rtextblocks = rtextblocks;
+ cfg.rtextents = rtextents;
+ cfg.rtbmblocks = nbmblocks;
+ cfg.dsunit = dsunit;
+ cfg.dswidth = dswidth;
+ cfg.lsunit = lsunit;
+ cfg.agsize = agsize;
+ cfg.agcount = agcount;
+ cfg.imaxpct = imaxpct;
+ cfg.loginternal = loginternal;
+ cfg.logstart = logstart;
+ cfg.logagno = logagno;
+ cfg.label = label;
+ platform_uuid_copy(&cfg.uuid, &uuid);
+ memcpy(&cfg.sb_feat, &sb_feat, sizeof(sb_feat));
+ /* end temp support code */
+
if (!qflag || Nflag) {
printf(_(
"meta-data=%-22s isize=%-6d agcount=%lld, agsize=%lld blks\n"
@@ -3016,6 +3102,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
exit(0);
}
+
if (label)
strncpy(sbp->sb_fname, label, sizeof(sbp->sb_fname));
sbp->sb_magicnum = XFS_SB_MAGIC;