From: Dave Chinner <david@fromorbit.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH 15/42] mkfs: factor in memory superblock setup
Date: Wed, 30 Aug 2017 09:50:25 +1000 [thread overview]
Message-ID: <20170829235052.21050-16-david@fromorbit.com> (raw)
In-Reply-To: <20170829235052.21050-1-david@fromorbit.com>
From: Dave Chinner <dchinner@redhat.com>
Signed-Off-By: Dave Chinner <dchinner@redhat.com>
---
mkfs/xfs_mkfs.c | 141 ++++++++++++++++++++++++++++++++------------------------
1 file changed, 82 insertions(+), 59 deletions(-)
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 4c67062047d9..0e115bf3cf4d 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -1915,6 +1915,84 @@ print_mkfs_cfg(
(long long)cfg->rtblocks, (long long)cfg->rtextents);
}
+/*
+ * Format everything from the generated config into the superblock that
+ * will be used to initialise the on-disk superblock. This is the in-memory
+ * copy, so no need to care about endian swapping here.
+ */
+static void
+setup_superblock(
+ struct mkfs_params *cfg,
+ struct xfs_mount *mp,
+ struct xfs_sb *sbp)
+{
+ if (cfg->label)
+ strncpy(sbp->sb_fname, cfg->label, sizeof(sbp->sb_fname));
+
+ sbp->sb_magicnum = XFS_SB_MAGIC;
+ sbp->sb_blocksize = cfg->blocksize;
+ sbp->sb_dblocks = cfg->dblocks;
+ sbp->sb_rblocks = cfg->rtblocks;
+ sbp->sb_rextents = cfg->rtextents;
+ platform_uuid_copy(&sbp->sb_uuid, &cfg->uuid);
+ /* Only in memory; libxfs expects this as if read from disk */
+ platform_uuid_copy(&sbp->sb_meta_uuid, &cfg->uuid);
+ sbp->sb_logstart = cfg->logstart;
+ sbp->sb_rootino = sbp->sb_rbmino = sbp->sb_rsumino = NULLFSINO;
+ sbp->sb_rextsize = cfg->rtextblocks;
+ sbp->sb_agcount = (xfs_agnumber_t)cfg->agcount;
+ sbp->sb_rbmblocks = cfg->rtbmblocks;
+ sbp->sb_logblocks = (xfs_extlen_t)cfg->logblocks;
+ sbp->sb_sectsize = (uint16_t)cfg->sectorsize;
+ sbp->sb_inodesize = (uint16_t)cfg->inodesize;
+ sbp->sb_inopblock = (uint16_t)(cfg->blocksize / cfg->inodesize);
+ sbp->sb_sectlog = (uint8_t)cfg->sectorlog;
+ sbp->sb_inodelog = (uint8_t)cfg->inodelog;
+ sbp->sb_inopblog = (uint8_t)(cfg->blocklog - cfg->inodelog);
+ sbp->sb_rextslog = (uint8_t)(cfg->rtextents ?
+ libxfs_highbit32((unsigned int)cfg->rtextents) : 0);
+ sbp->sb_inprogress = 1; /* mkfs is in progress */
+ sbp->sb_imax_pct = cfg->imaxpct;
+ sbp->sb_icount = 0;
+ sbp->sb_ifree = 0;
+ sbp->sb_fdblocks = cfg->dblocks -
+ cfg->agcount * libxfs_prealloc_blocks(mp) -
+ (cfg->loginternal ? cfg->logblocks : 0);
+ sbp->sb_frextents = 0; /* will do a free later */
+ sbp->sb_uquotino = sbp->sb_gquotino = sbp->sb_pquotino = 0;
+ sbp->sb_qflags = 0;
+ sbp->sb_unit = cfg->dsunit;
+ sbp->sb_width = cfg->dswidth;
+ sbp->sb_dirblklog = cfg->dirblocklog - cfg->blocklog;
+
+ /*
+ * log stripe unit is stored in bytes on disk and cannot be zero
+ * for v2 logs.
+ */
+ if (cfg->sb_feat.log_version == 2) {
+ int lsunit = (cfg->lsunit == 0) ? 1 : cfg->lsunit;
+
+ sbp->sb_logsunit = XFS_FSB_TO_B(mp, lsunit);;
+ } else
+ sbp->sb_logsunit = 0;
+
+ if (cfg->sb_feat.inode_align) {
+ int cluster_size = XFS_INODE_BIG_CLUSTER_SIZE;
+ if (cfg->sb_feat.crcs_enabled)
+ cluster_size *= cfg->inodesize / XFS_DINODE_MIN_SIZE;
+ sbp->sb_inoalignmt = cluster_size >> cfg->blocklog;
+ } else
+ sbp->sb_inoalignmt = 0;
+
+ if (cfg->lsectorsize != BBSIZE || cfg->sectorsize != BBSIZE) {
+ sbp->sb_logsectlog = (uint8_t)cfg->lsectorlog;
+ sbp->sb_logsectsize = (uint16_t)cfg->lsectorsize;
+ } else {
+ sbp->sb_logsectlog = 0;
+ sbp->sb_logsectsize = 0;
+ }
+}
+
int
main(
int argc,
@@ -3091,65 +3169,10 @@ _("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;
- sbp->sb_blocksize = blocksize;
- sbp->sb_dblocks = dblocks;
- sbp->sb_rblocks = rtblocks;
- sbp->sb_rextents = rtextents;
- platform_uuid_copy(&sbp->sb_uuid, &uuid);
- /* Only in memory; libxfs expects this as if read from disk */
- platform_uuid_copy(&sbp->sb_meta_uuid, &uuid);
- sbp->sb_logstart = logstart;
- sbp->sb_rootino = sbp->sb_rbmino = sbp->sb_rsumino = NULLFSINO;
- sbp->sb_rextsize = rtextblocks;
- sbp->sb_agcount = (xfs_agnumber_t)agcount;
- sbp->sb_rbmblocks = nbmblocks;
- sbp->sb_logblocks = (xfs_extlen_t)logblocks;
- sbp->sb_sectsize = (uint16_t)sectorsize;
- sbp->sb_inodesize = (uint16_t)isize;
- sbp->sb_inopblock = (uint16_t)(blocksize / isize);
- sbp->sb_sectlog = (uint8_t)sectorlog;
- sbp->sb_inodelog = (uint8_t)inodelog;
- sbp->sb_inopblog = (uint8_t)(blocklog - inodelog);
- sbp->sb_rextslog =
- (uint8_t)(rtextents ?
- libxfs_highbit32((unsigned int)rtextents) : 0);
- sbp->sb_inprogress = 1; /* mkfs is in progress */
- sbp->sb_imax_pct = imaxpct;
- sbp->sb_icount = 0;
- sbp->sb_ifree = 0;
- sbp->sb_fdblocks = dblocks - agcount * libxfs_prealloc_blocks(mp) -
- (loginternal ? logblocks : 0);
- sbp->sb_frextents = 0; /* will do a free later */
- sbp->sb_uquotino = sbp->sb_gquotino = sbp->sb_pquotino = 0;
- sbp->sb_qflags = 0;
- sbp->sb_unit = dsunit;
- sbp->sb_width = dswidth;
- sbp->sb_dirblklog = dirblocklog - blocklog;
- if (sb_feat.log_version == 2) { /* This is stored in bytes */
- lsunit = (lsunit == 0) ? 1 : XFS_FSB_TO_B(mp, lsunit);
- sbp->sb_logsunit = lsunit;
- } else
- sbp->sb_logsunit = 0;
- if (sb_feat.inode_align) {
- int cluster_size = XFS_INODE_BIG_CLUSTER_SIZE;
- if (sb_feat.crcs_enabled)
- cluster_size *= isize / XFS_DINODE_MIN_SIZE;
- sbp->sb_inoalignmt = cluster_size >> blocklog;
- sb_feat.inode_align = sbp->sb_inoalignmt != 0;
- } else
- sbp->sb_inoalignmt = 0;
- if (lsectorsize != BBSIZE || sectorsize != BBSIZE) {
- sbp->sb_logsectlog = (uint8_t)lsectorlog;
- sbp->sb_logsectsize = (uint16_t)lsectorsize;
- } else {
- sbp->sb_logsectlog = 0;
- sbp->sb_logsectsize = 0;
- }
-
- sb_set_features(&mp->m_sb, &sb_feat, sectorsize, lsectorsize, dsunit);
+ /*
+ * Finish setting up the superblock state ready for formatting.
+ */
+ setup_superblock(&cfg, mp, sbp);
if (force_overwrite)
zero_old_xfs_structures(&xi, sbp);
--
2.13.3
next prev parent reply other threads:[~2017-08-29 23:51 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-29 23:50 [PATCH 00/42] mkfs: factor the crap out of the code Dave Chinner
2017-08-29 23:50 ` [PATCH 01/42] mkfs: can't specify sector size of internal log Dave Chinner
2017-08-29 23:50 ` [PATCH 02/42] mkfs: make subopt table const Dave Chinner
2017-08-29 23:50 ` [PATCH 03/42] mkfs: introduce a structure to hold CLI options Dave Chinner
2017-08-29 23:50 ` [PATCH 04/42] mkfs: add generic subopt parsing table Dave Chinner
2017-08-29 23:50 ` [PATCH 05/42] mkfs: factor block subopts parser Dave Chinner
2017-08-29 23:50 ` [PATCH 06/42] mkfs: factor data " Dave Chinner
2017-08-29 23:50 ` [PATCH 07/42] mkfs: factor inode " Dave Chinner
2017-08-29 23:50 ` [PATCH 08/42] mkfs: factor log " Dave Chinner
2017-08-29 23:50 ` [PATCH 09/42] mkfs: factor meta " Dave Chinner
2017-08-29 23:50 ` [PATCH 10/42] mkfs: factor naming " Dave Chinner
2017-08-29 23:50 ` [PATCH 11/42] mkfs: factor rt " Dave Chinner
2017-08-29 23:50 ` [PATCH 12/42] mkfs: factor sector " Dave Chinner
2017-08-29 23:50 ` [PATCH 13/42] mkfs: Introduce mkfs configuration structure Dave Chinner
2017-08-29 23:50 ` [PATCH 14/42] mkfs: factor printing of mkfs config Dave Chinner
2017-08-29 23:50 ` Dave Chinner [this message]
2017-08-29 23:50 ` [PATCH 16/42] mkfs: factor out device preparation Dave Chinner
2017-08-29 23:50 ` [PATCH 17/42] mkfs: factor writing AG headers Dave Chinner
2017-08-29 23:50 ` [PATCH 18/42] mkfs: factor secondary superblock updates Dave Chinner
2017-08-29 23:50 ` [PATCH 19/42] mkfs: introduce default configuration structure Dave Chinner
2017-08-29 23:50 ` [PATCH 20/42] mkfs: rename top level CLI parameters Dave Chinner
2017-08-29 23:50 ` [PATCH 21/42] mkfs: factor sectorsize validation Dave Chinner
2017-08-29 23:50 ` [PATCH 22/42] mkfs: factor blocksize validation Dave Chinner
2017-08-29 23:50 ` [PATCH 23/42] mkfs: factor log sector size validation Dave Chinner
2017-08-29 23:50 ` [PATCH 24/42] mkfs: factor superblock feature validation Dave Chinner
2017-08-29 23:50 ` [PATCH 25/42] mkfs: factor directory blocksize validation Dave Chinner
2017-08-29 23:50 ` [PATCH 26/42] mkfs: factor inode size validation Dave Chinner
2017-08-29 23:50 ` [PATCH 27/42] mkfs: factor out device size calculations Dave Chinner
2017-08-29 23:50 ` [PATCH 28/42] mkfs: fix hidden parameter in DTOBT() Dave Chinner
2017-08-29 23:50 ` [PATCH 29/42] mkfs: factor rtdev extent size validation Dave Chinner
2017-08-29 23:50 ` [PATCH 30/42] mkfs: rework stripe calculations Dave Chinner
2017-08-29 23:50 ` [PATCH 31/42] mkfs: factor device opening Dave Chinner
2017-08-29 23:50 ` [PATCH 32/42] mkfs: factor data device validation Dave Chinner
2017-08-29 23:50 ` [PATCH 33/42] mkfs: factor log " Dave Chinner
2017-08-29 23:50 ` [PATCH 34/42] mkfs: factor rt " Dave Chinner
2017-08-29 23:50 ` [PATCH 35/42] mkfs: factor AG geometry calculations Dave Chinner
2017-08-29 23:50 ` [PATCH 36/42] mkfs: factor AG alignment Dave Chinner
2017-08-30 23:44 ` Dave Chinner
2017-08-29 23:50 ` [PATCH 37/42] mkfs: rework imaxpct calculation Dave Chinner
2017-08-29 23:50 ` [PATCH 38/42] mkfs: factor initial mount setup Dave Chinner
2017-08-29 23:50 ` [PATCH 39/42] mkfs: factor log size calculations Dave Chinner
2017-09-05 5:23 ` Dave Chinner
2017-08-29 23:50 ` [PATCH 40/42] mkfs: cleanup redundant temporary code Dave Chinner
2017-08-29 23:50 ` [PATCH 41/42] mkfs: move error functions Dave Chinner
2017-08-29 23:50 ` [PATCH 42/42] mkfs: tidy up definitions Dave Chinner
2017-08-30 1:23 ` [PATCH 00/42] mkfs: factor the crap out of the code Darrick J. Wong
2017-08-30 1:57 ` Dave Chinner
2017-08-30 4:16 ` Luis R. Rodriguez
2017-08-30 5:44 ` Dave Chinner
2017-08-30 22:10 ` Luis R. Rodriguez
2017-08-30 23:22 ` Dave Chinner
2017-08-31 0:05 ` Luis R. Rodriguez
2017-08-31 16:23 ` Jan Tulak
2017-08-30 7:44 ` Martin Steigerwald
2017-09-04 12:31 ` Chandan Rajendra
2017-09-04 15:34 ` Eric Sandeen
2017-09-04 22:40 ` Dave Chinner
2017-09-07 10:31 ` Chandan Rajendra
2017-09-07 23:38 ` Dave Chinner
2017-09-09 10:24 ` Chandan Rajendra
2017-09-15 9:42 ` Jan Tulak
2017-09-16 11:29 ` Dave Chinner
2017-10-24 3:00 ` Eric Sandeen
2017-10-25 0:59 ` Dave Chinner
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=20170829235052.21050-16-david@fromorbit.com \
--to=david@fromorbit.com \
--cc=linux-xfs@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).