]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: factor out a xfs_growfs_rt_alloc_blocks helper
authorChristoph Hellwig <hch@lst.de>
Wed, 9 Oct 2024 11:54:28 +0000 (13:54 +0200)
committerChristoph Hellwig <hch@lst.de>
Wed, 9 Oct 2024 13:49:31 +0000 (15:49 +0200)
Split out a helper to allocate or grow the rtbitmap and rtsummary files
in preparation of per-RT group bitmap and summary files.

Signed-off-by: Christoph Hellwig <hch@lst.de>
fs/xfs/xfs_rtalloc.c

index 96225313686414c5891fb934e8792bb9a9109c80..9a451f88bf4647ca3852e6b58c79ee7a92bde8ee 100644 (file)
@@ -875,6 +875,43 @@ xfs_last_rt_bmblock(
        return bmbno;
 }
 
+/*
+ * Allocate space to the bitmap and summary files, as necessary.
+ */
+static int
+xfs_growfs_rt_alloc_blocks(
+       struct xfs_mount        *mp,
+       xfs_rfsblock_t          nrblocks,
+       xfs_agblock_t           rextsize,
+       xfs_extlen_t            *nrbmblocks)
+{
+       struct xfs_inode        *rbmip = mp->m_rbmip;
+       struct xfs_inode        *rsumip = mp->m_rsumip;
+       xfs_rtxnum_t            nrextents = div_u64(nrblocks, rextsize);
+       xfs_extlen_t            orbmblocks;
+       xfs_extlen_t            orsumblocks;
+       xfs_extlen_t            nrsumblocks;
+       int                     error;
+
+       /*
+        * Get the old block counts for bitmap and summary inodes.
+        * These can't change since other growfs callers are locked out.
+        */
+       orbmblocks = XFS_B_TO_FSB(mp, rbmip->i_disk_size);
+       orsumblocks = XFS_B_TO_FSB(mp, rsumip->i_disk_size);
+
+       *nrbmblocks = xfs_rtbitmap_blockcount(mp, nrextents);
+       nrsumblocks = xfs_rtsummary_blockcount(mp,
+               xfs_compute_rextslog(nrextents) + 1, *nrbmblocks);
+
+       error = xfs_rtfile_initialize_blocks(rbmip, orbmblocks,
+                       *nrbmblocks, NULL);
+       if (error)
+               return error;
+       return xfs_rtfile_initialize_blocks(rsumip, orsumblocks,
+                       nrsumblocks, NULL);
+}
+
 /*
  * Grow the realtime area of the filesystem.
  */
@@ -889,8 +926,6 @@ xfs_growfs_rt(
        xfs_extlen_t    nrbmblocks;     /* new number of rt bitmap blocks */
        xfs_rtxnum_t    nrextents;      /* new number of realtime extents */
        xfs_extlen_t    nrsumblocks;    /* new number of summary blocks */
-       xfs_extlen_t    rbmblocks;      /* current number of rt bitmap blocks */
-       xfs_extlen_t    rsumblocks;     /* current number of rt summary blks */
        uint8_t         *rsum_cache;    /* old summary cache */
        xfs_agblock_t   old_rextsize = mp->m_sb.sb_rextsize;
 
@@ -963,21 +998,8 @@ xfs_growfs_rt(
                goto out_unlock;
        }
 
-       /*
-        * Get the old block counts for bitmap and summary inodes.
-        * These can't change since other growfs callers are locked out.
-        */
-       rbmblocks = XFS_B_TO_FSB(mp, mp->m_rbmip->i_disk_size);
-       rsumblocks = XFS_B_TO_FSB(mp, mp->m_rsumip->i_disk_size);
-       /*
-        * Allocate space to the bitmap and summary files, as necessary.
-        */
-       error = xfs_rtfile_initialize_blocks(mp->m_rbmip, rbmblocks,
-                       nrbmblocks, NULL);
-       if (error)
-               goto out_unlock;
-       error = xfs_rtfile_initialize_blocks(mp->m_rsumip, rsumblocks,
-                       nrsumblocks, NULL);
+       error = xfs_growfs_rt_alloc_blocks(mp, in->newblocks, in->extsize,
+                       &nrbmblocks);
        if (error)
                goto out_unlock;