]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
mkfs: use xfs_rtfile_initialize_blocks
authorChristoph Hellwig <hch@lst.de>
Tue, 30 Jul 2024 20:25:34 +0000 (13:25 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 1 Aug 2024 00:07:33 +0000 (17:07 -0700)
Use the new libxfs helper for initializing the rtbitmap/summary files
for rtgroup-enabled file systems.  Also skip the zeroing of the blocks
for rtgroup file systems as we'll overwrite every block instantly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
libxfs/libxfs_api_defs.h
mkfs/proto.c

index e2070849e1670e6769029aca6a42ccf232d80e8b..8f74d8ce7eb510f7485fd81e43389d8de67ef58e 100644 (file)
 #define xfs_suminfo_add                        libxfs_suminfo_add
 #define xfs_suminfo_get                        libxfs_suminfo_get
 #define xfs_rtsummary_wordcount                libxfs_rtsummary_wordcount
+#define xfs_rtfile_initialize_blocks   libxfs_rtfile_initialize_blocks
 
 #define xfs_rtfree_extent              libxfs_rtfree_extent
 #define xfs_rtfree_blocks              libxfs_rtfree_blocks
index c145bf4fdc1fa3dfe1fe0ffbf7bbc7b6141a3432..f51cef8bd636e8b68d18a036aa9fc9ec3172ccfe 100644 (file)
@@ -888,96 +888,6 @@ rtsummary_create(
        ihold(VFS_I(ip));
 }
 
-/* Zero the realtime bitmap. */
-static void
-rtbitmap_init(
-       struct xfs_mount        *mp)
-{
-       struct xfs_bmbt_irec    map[XFS_BMAP_MAX_NMAP];
-       struct xfs_trans        *tp;
-       struct xfs_bmbt_irec    *ep;
-       xfs_fileoff_t           bno;
-       uint                    blocks;
-       int                     i;
-       int                     nmap;
-       int                     error;
-
-       blocks = mp->m_sb.sb_rbmblocks +
-                       XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1;
-       error = -libxfs_trans_alloc_rollable(mp, blocks, &tp);
-       if (error)
-               res_failed(error);
-
-       libxfs_trans_ijoin(tp, mp->m_rbmip, 0);
-       bno = 0;
-       while (bno < mp->m_sb.sb_rbmblocks) {
-               nmap = XFS_BMAP_MAX_NMAP;
-               error = -libxfs_bmapi_write(tp, mp->m_rbmip, bno,
-                               (xfs_extlen_t)(mp->m_sb.sb_rbmblocks - bno),
-                               0, mp->m_sb.sb_rbmblocks, map, &nmap);
-               if (error)
-                       fail(_("Allocation of the realtime bitmap failed"),
-                               error);
-
-               for (i = 0, ep = map; i < nmap; i++, ep++) {
-                       libxfs_device_zero(mp->m_ddev_targp,
-                               XFS_FSB_TO_DADDR(mp, ep->br_startblock),
-                               XFS_FSB_TO_BB(mp, ep->br_blockcount));
-                       bno += ep->br_blockcount;
-               }
-       }
-
-       error = -libxfs_trans_commit(tp);
-       if (error)
-               fail(_("Block allocation of the realtime bitmap inode failed"),
-                               error);
-}
-
-/* Zero the realtime summary file. */
-static void
-rtsummary_init(
-       struct xfs_mount        *mp)
-{
-       struct xfs_bmbt_irec    map[XFS_BMAP_MAX_NMAP];
-       struct xfs_trans        *tp;
-       struct xfs_bmbt_irec    *ep;
-       xfs_fileoff_t           bno;
-       xfs_extlen_t            nsumblocks;
-       uint                    blocks;
-       int                     i;
-       int                     nmap;
-       int                     error;
-
-       nsumblocks = mp->m_rsumsize >> mp->m_sb.sb_blocklog;
-       blocks = nsumblocks + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1;
-       error = -libxfs_trans_alloc_rollable(mp, blocks, &tp);
-       if (error)
-               res_failed(error);
-       libxfs_trans_ijoin(tp, mp->m_rsumip, 0);
-
-       bno = 0;
-       while (bno < nsumblocks) {
-               nmap = XFS_BMAP_MAX_NMAP;
-               error = -libxfs_bmapi_write(tp, mp->m_rsumip, bno,
-                               (xfs_extlen_t)(nsumblocks - bno),
-                               0, nsumblocks, map, &nmap);
-               if (error)
-                       fail(_("Allocation of the realtime summary failed"),
-                               error);
-
-               for (i = 0, ep = map; i < nmap; i++, ep++) {
-                       libxfs_device_zero(mp->m_ddev_targp,
-                               XFS_FSB_TO_DADDR(mp, ep->br_startblock),
-                               XFS_FSB_TO_BB(mp, ep->br_blockcount));
-                       bno += ep->br_blockcount;
-               }
-       }
-       error = -libxfs_trans_commit(tp);
-       if (error)
-               fail(_("Block allocation of the realtime summary inode failed"),
-                               error);
-}
-
 /*
  * Free the whole realtime area using transactions.
  * Do one transaction per bitmap block.
@@ -991,6 +901,22 @@ rtfreesp_init(
        xfs_rtxnum_t            ertx;
        int                     error;
 
+       /*
+        * First zero the realtime bitmap and summary files.
+        */
+       error = -libxfs_rtfile_initialize_blocks(mp->m_rbmip, 0,
+                       mp->m_sb.sb_rbmblocks, NULL);
+       if (error)
+               fail(_("Initialization of rtbitmap inode failed"), error);
+
+       error = -libxfs_rtfile_initialize_blocks(mp->m_rsumip, 0,
+                       XFS_B_TO_FSB(mp, mp->m_rsumsize), NULL);
+       if (error)
+               fail(_("Initialization of rtsummary inode failed"), error);
+
+       /*
+        * Then free the blocks into the allocator, one bitmap block at a time.
+        */
        for (rtx = 0; rtx < mp->m_sb.sb_rextents; rtx = ertx) {
                error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
                                0, 0, 0, &tp);
@@ -1024,8 +950,6 @@ rtinit(
        create_sb_metadata_file(mp, rtbitmap_create);
        create_sb_metadata_file(mp, rtsummary_create);
 
-       rtbitmap_init(mp);
-       rtsummary_init(mp);
        rtfreesp_init(mp);
 }