xfs: factor out a xfs_growfs_check_rtgeom helper
authorChristoph Hellwig <hch@lst.de>
Mon, 4 Nov 2024 04:19:13 +0000 (20:19 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 5 Nov 2024 21:38:38 +0000 (13:38 -0800)
Split the check that the rtsummary fits into the log into a separate
helper, and use xfs_growfs_rt_alloc_fake_mount to calculate the new RT
geometry.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
[djwong: avoid division for the 0-rtx growfs check]
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
fs/xfs/xfs_rtalloc.c

index e69728c..d4e5589 100644 (file)
@@ -1023,6 +1023,31 @@ out_rele:
        return error;
 }
 
+static int
+xfs_growfs_check_rtgeom(
+       const struct xfs_mount  *mp,
+       xfs_rfsblock_t          rblocks,
+       xfs_extlen_t            rextsize)
+{
+       struct xfs_mount        *nmp;
+       int                     error = 0;
+
+       nmp = xfs_growfs_rt_alloc_fake_mount(mp, rblocks, rextsize);
+       if (!nmp)
+               return -ENOMEM;
+
+       /*
+        * New summary size can't be more than half the size of the log.  This
+        * prevents us from getting a log overflow, since we'll log basically
+        * the whole summary file at once.
+        */
+       if (nmp->m_rsumblocks > (mp->m_sb.sb_logblocks >> 1))
+               error = -EINVAL;
+
+       kfree(nmp);
+       return error;
+}
+
 /*
  * Grow the realtime area of the filesystem.
  */
@@ -1031,9 +1056,6 @@ xfs_growfs_rt(
        xfs_mount_t     *mp,            /* mount point for filesystem */
        xfs_growfs_rt_t *in)            /* growfs rt input struct */
 {
-       xfs_rtxnum_t            nrextents;
-       xfs_extlen_t            nrbmblocks;
-       xfs_extlen_t            nrsumblocks;
        struct xfs_buf          *bp;
        xfs_agblock_t           old_rextsize = mp->m_sb.sb_rextsize;
        int                     error;
@@ -1082,20 +1104,13 @@ xfs_growfs_rt(
        /*
         * Calculate new parameters.  These are the final values to be reached.
         */
-       nrextents = div_u64(in->newblocks, in->extsize);
        error = -EINVAL;
-       if (nrextents == 0)
+       if (in->newblocks < in->extsize)
                goto out_unlock;
-       nrbmblocks = xfs_rtbitmap_blockcount(mp, nrextents);
-       nrsumblocks = xfs_rtsummary_blockcount(mp,
-                       xfs_compute_rextslog(nrextents) + 1, nrbmblocks);
 
-       /*
-        * New summary size can't be more than half the size of
-        * the log.  This prevents us from getting a log overflow,
-        * since we'll log basically the whole summary file at once.
-        */
-       if (nrsumblocks > (mp->m_sb.sb_logblocks >> 1))
+       /* Make sure the new fs size won't cause problems with the log. */
+       error = xfs_growfs_check_rtgeom(mp, in->newblocks, in->extsize);
+       if (error)
                goto out_unlock;
 
        error = xfs_growfs_rtg(mp, in->newblocks, in->extsize);