mkfs: use libxfs_alloc_file_space for rtinit
authorDarrick J. Wong <djwong@kernel.org>
Tue, 9 Jan 2024 17:40:22 +0000 (09:40 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 10 Apr 2024 00:21:45 +0000 (17:21 -0700)
Since xfs_bmapi_write can now zero newly allocated blocks, use it to
initialize the realtime inodes instead of open coding this.

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

index 742ad5be4853bb2408c5a317267d578e77e3624f..ec74281d8ccfd9d7f984e1396603ee909043823f 100644 (file)
@@ -952,43 +952,14 @@ 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);
+       error = -libxfs_alloc_file_space(mp->m_rbmip, 0,
+                       mp->m_sb.sb_rbmblocks << mp->m_sb.sb_blocklog,
+                       XFS_BMAPI_ZERO);
        if (error)
-               fail(_("Block allocation of the realtime bitmap inode failed"),
+               fail(
+       _("Block allocation of the realtime bitmap inode failed"),
                                error);
 
        if (xfs_has_rtgroups(mp)) {
@@ -1004,43 +975,13 @@ 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);
+       error = -libxfs_alloc_file_space(mp->m_rsumip, 0, mp->m_rsumsize,
+                       XFS_BMAPI_ZERO);
        if (error)
-               fail(_("Block allocation of the realtime summary inode failed"),
+               fail(
+       _("Block allocation of the realtime summary inode failed"),
                                error);
 
        if (xfs_has_rtgroups(mp)) {
@@ -1146,6 +1087,9 @@ rtinit(
                        rtrmapbt_create(rtg);
        }
 
+       if (mp->m_sb.sb_rbmblocks == 0)
+               return;
+
        rtbitmap_init(mp);
        rtsummary_init(mp);
        if (xfs_has_rtgroups(mp))