]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
mkfs: clean up the rtinit() function
authorDarrick J. Wong <djwong@kernel.org>
Wed, 3 Jul 2024 21:21:44 +0000 (14:21 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:13:15 +0000 (17:13 -0700)
Clean up some of the warts in this function, like the inconsistent use
of @i for @error, missing comments, and make this more visually pleasing
by adding some whitespace between major sections.  Some things are left
untouched for the next patch.

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

index 251e3a9ee019e98d00505500f9b827f0875bd45d..65072f7b5a2801ab19a9e87a9567d66cbad421c3 100644 (file)
@@ -755,28 +755,26 @@ parse_proto(
  */
 static void
 rtinit(
-       xfs_mount_t     *mp)
+       struct xfs_mount        *mp)
 {
-       xfs_fileoff_t   bno;
-       xfs_bmbt_irec_t *ep;
-       int             error;
-       int             i;
-       xfs_bmbt_irec_t map[XFS_BMAP_MAX_NMAP];
-       xfs_extlen_t    nsumblocks;
-       uint            blocks;
-       int             nmap;
-       xfs_inode_t     *rbmip;
-       xfs_inode_t     *rsumip;
-       xfs_trans_t     *tp;
-       struct cred     creds;
-       struct fsxattr  fsxattrs;
+       struct cred             creds;
+       struct fsxattr          fsxattrs;
+       struct xfs_bmbt_irec    map[XFS_BMAP_MAX_NMAP];
+       struct xfs_inode        *rbmip;
+       struct xfs_inode        *rsumip;
+       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;
 
-       /*
-        * First, allocate the inodes.
-        */
-       i = -libxfs_trans_alloc_rollable(mp, MKFS_BLOCKRES_INODE, &tp);
-       if (i)
-               res_failed(i);
+       /* Create the realtime bitmap inode. */
+       error = -libxfs_trans_alloc_rollable(mp, MKFS_BLOCKRES_INODE, &tp);
+       if (error)
+               res_failed(error);
 
        memset(&creds, 0, sizeof(creds));
        memset(&fsxattrs, 0, sizeof(fsxattrs));
@@ -796,6 +794,8 @@ rtinit(
        libxfs_trans_log_inode(tp, rbmip, XFS_ILOG_CORE);
        libxfs_log_sb(tp);
        mp->m_rbmip = rbmip;
+
+       /* Create the realtime summary inode. */
        error = creatproto(&tp, NULL, S_IFREG, 0, &creds, &fsxattrs, &rsumip);
        if (error) {
                fail(_("Realtime summary inode allocation failed"), error);
@@ -809,14 +809,13 @@ rtinit(
                fail(_("Completion of the realtime summary inode failed"),
                                error);
        mp->m_rsumip = rsumip;
-       /*
-        * Next, give the bitmap file some zero-filled blocks.
-        */
+
+       /* Zero the realtime bitmap. */
        blocks = mp->m_sb.sb_rbmblocks +
                        XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1;
-       i = -libxfs_trans_alloc_rollable(mp, blocks, &tp);
-       if (i)
-               res_failed(i);
+       error = -libxfs_trans_alloc_rollable(mp, blocks, &tp);
+       if (error)
+               res_failed(error);
 
        libxfs_trans_ijoin(tp, rbmip, 0);
        bno = 0;
@@ -825,10 +824,10 @@ rtinit(
                error = -libxfs_bmapi_write(tp, rbmip, bno,
                                (xfs_extlen_t)(mp->m_sb.sb_rbmblocks - bno),
                                0, mp->m_sb.sb_rbmblocks, map, &nmap);
-               if (error) {
+               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),
@@ -842,25 +841,24 @@ rtinit(
                fail(_("Block allocation of the realtime bitmap inode failed"),
                                error);
 
-       /*
-        * Give the summary file some zero-filled blocks.
-        */
+       /* Zero the summary file. */
        nsumblocks = mp->m_rsumsize >> mp->m_sb.sb_blocklog;
        blocks = nsumblocks + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - 1;
-       i = -libxfs_trans_alloc_rollable(mp, blocks, &tp);
-       if (i)
-               res_failed(i);
+       error = -libxfs_trans_alloc_rollable(mp, blocks, &tp);
+       if (error)
+               res_failed(error);
        libxfs_trans_ijoin(tp, rsumip, 0);
+
        bno = 0;
        while (bno < nsumblocks) {
                nmap = XFS_BMAP_MAX_NMAP;
                error = -libxfs_bmapi_write(tp, rsumip, bno,
                                (xfs_extlen_t)(nsumblocks - bno),
                                0, nsumblocks, map, &nmap);
-               if (error) {
+               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),