]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mkfs: hoist the internal log size clamp code
authorDarrick J. Wong <djwong@kernel.org>
Sat, 12 Mar 2022 01:23:41 +0000 (17:23 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 17 Mar 2022 21:40:26 +0000 (14:40 -0700)
Move the code that clamps the computation of the internal log size so
that we can begin to enhnace mkfs without turning calculate_log_size
into more spaghetti.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
mkfs/xfs_mkfs.c

index 96682f9a3958754b73200b09477392a35264295a..b97bd360d5c826d1f3fbb24b657507dfe303bf44 100644 (file)
@@ -3259,6 +3259,34 @@ validate_log_size(uint64_t logblocks, int blocklog, int min_logblocks)
        }
 }
 
+static void
+clamp_internal_log_size(
+       struct mkfs_params      *cfg,
+       struct xfs_mount        *mp,
+       int                     min_logblocks)
+{
+       /* Ensure the chosen size meets minimum log size requirements */
+       cfg->logblocks = max(min_logblocks, cfg->logblocks);
+
+       /*
+        * Make sure the log fits wholly within an AG
+        *
+        * XXX: If agf->freeblks ends up as 0 because the log uses all
+        * the free space, it causes the kernel all sorts of problems
+        * with per-ag reservations. Right now just back it off one
+        * block, but there's a whole can of worms here that needs to be
+        * opened to decide what is the valid maximum size of a log in
+        * an AG.
+        */
+       cfg->logblocks = min(cfg->logblocks,
+                            libxfs_alloc_ag_max_usable(mp) - 1);
+
+       /* and now clamp the size to the maximum supported size */
+       cfg->logblocks = min(cfg->logblocks, XFS_MAX_LOG_BLOCKS);
+       if ((cfg->logblocks << cfg->blocklog) > XFS_MAX_LOG_BYTES)
+               cfg->logblocks = XFS_MAX_LOG_BYTES >> cfg->blocklog;
+}
+
 static void
 calculate_log_size(
        struct mkfs_params      *cfg,
@@ -3331,26 +3359,7 @@ _("external log device size %lld blocks too small, must be at least %lld blocks\
                        cfg->logblocks = cfg->logblocks >> cfg->blocklog;
                }
 
-               /* Ensure the chosen size meets minimum log size requirements */
-               cfg->logblocks = max(min_logblocks, cfg->logblocks);
-
-               /*
-                * Make sure the log fits wholly within an AG
-                *
-                * XXX: If agf->freeblks ends up as 0 because the log uses all
-                * the free space, it causes the kernel all sorts of problems
-                * with per-ag reservations. Right now just back it off one
-                * block, but there's a whole can of worms here that needs to be
-                * opened to decide what is the valid maximum size of a log in
-                * an AG.
-                */
-               cfg->logblocks = min(cfg->logblocks,
-                                    libxfs_alloc_ag_max_usable(mp) - 1);
-
-               /* and now clamp the size to the maximum supported size */
-               cfg->logblocks = min(cfg->logblocks, XFS_MAX_LOG_BLOCKS);
-               if ((cfg->logblocks << cfg->blocklog) > XFS_MAX_LOG_BYTES)
-                       cfg->logblocks = XFS_MAX_LOG_BYTES >> cfg->blocklog;
+               clamp_internal_log_size(cfg, mp, min_logblocks);
 
                validate_log_size(cfg->logblocks, cfg->blocklog, min_logblocks);
        }