]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: factor out a xfs_growfs_check_rtgeom helper
authorChristoph Hellwig <hch@lst.de>
Sun, 4 Aug 2024 20:16:46 +0000 (22:16 +0200)
committerChristoph Hellwig <hch@lst.de>
Tue, 6 Aug 2024 13:05:12 +0000 (06:05 -0700)
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>
fs/xfs/xfs_rtalloc.c

index 7085bba8c006b27291905b51435f0d8f8c409ddf..21e99caf51b09955d90c4ab9d1253b0289f7dc2e 100644 (file)
@@ -987,6 +987,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.
  */
@@ -995,9 +1020,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;
        int                     error;
 
@@ -1041,20 +1063,13 @@ xfs_growfs_rt(
        /*
         * Calculate new parameters.  These are the final values to be reached.
         */
-       nrextents = div_u64(in->newblocks, in->extsize);
-       if (nrextents == 0)
+       if (div_u64(in->newblocks, in->extsize) == 0)
                return -EINVAL;
-       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))
-               return -EINVAL;
+       /* 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)
+               return error;
 
        error = xfs_growfs_rtg(mp, in->newblocks, in->extsize);
        if (error)