]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
mkfs: move more code into create_sb_metadata_file
authorChristoph Hellwig <hch@lst.de>
Wed, 31 Jul 2024 14:14:06 +0000 (07:14 -0700)
committerChristoph Hellwig <hch@lst.de>
Wed, 31 Jul 2024 14:15:17 +0000 (07:15 -0700)
Move more boilerplate for creating the two possible files into
create_sb_metadata_file, and turn the actual bitmap/summary specific code
into callbacks.

Signed-off-by: Christoph Hellwig <hch@lst.de>
mkfs/proto.c

index 805c32b3645d4549ff133a75aedd1223167b638b..c63eac4acd178ad4620d9b7bbff4f54a46b50ea2 100644 (file)
@@ -799,99 +799,76 @@ out_rele:
        return error;
 }
 
-static int
+static void
 create_sb_metadata_file(
-       struct xfs_trans        **tpp,
-       mode_t                  mode,
-       struct xfs_inode        **ipp)
+       struct xfs_mount        *mp,
+       void                    (*create)(struct xfs_inode *ip))
 {
        struct xfs_icreate_args args = {
-               .mode           = mode,
+               .mode           = S_IFREG,
                .flags          = XFS_ICREATE_UNLINKABLE,
        };
-       struct xfs_mount        *mp = (*tpp)->t_mountp;
        xfs_ino_t               ino;
        int                     error;
+       struct xfs_trans        *tp;
+       struct xfs_inode        *ip;
 
-       /*
-        * Call the space management code to pick the on-disk inode to be
-        * allocated.
-        */
-       error = -libxfs_dialloc(tpp, &args, &ino);
+       error = -libxfs_trans_alloc_rollable(mp, MKFS_BLOCKRES_INODE, &tp);
        if (error)
-               return error;
+               res_failed(error);
 
-       error = -libxfs_icreate(*tpp, ino, &args, ipp);
+       error = -libxfs_dialloc(&tp, &args, &ino);
        if (error)
-               return error;
+               goto fail;
+
+       error = -libxfs_icreate(tp, ino, &args, &ip);
+       if (error)
+               goto fail;
 
        if (xfs_has_metadir(mp))
-               libxfs_metafile_set_iflag(*tpp, *ipp);
+               libxfs_metafile_set_iflag(tp, ip);
 
-       return 0;
+       create(ip);
+
+       libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+       libxfs_log_sb(tp);
+
+       error = -libxfs_trans_commit(tp);
+       if (error)
+               goto fail;
+       return;
+fail:
+       if (error)
+               fail(_("Realtime inode allocation failed"), error);
 }
 
 /* Create the realtime bitmap inode. */
 static void
 rtbitmap_create(
-       struct xfs_mount        *mp)
+       struct xfs_inode        *ip)
 {
-       struct xfs_trans        *tp;
-       struct xfs_inode        *rbmip;
-       int                     error;
-
-       /* Create the realtime bitmap inode. */
-       error = -libxfs_trans_alloc_rollable(mp, MKFS_BLOCKRES_INODE, &tp);
-       if (error)
-               res_failed(error);
+       struct xfs_mount        *mp = ip->i_mount;
 
-       error = create_sb_metadata_file(&tp, S_IFREG, &rbmip);
-       if (error)
-               fail(_("Realtime bitmap inode allocation failed"), error);
-
-       mp->m_sb.sb_rbmino = rbmip->i_ino;
-       rbmip->i_disk_size = mp->m_sb.sb_rbmblocks * mp->m_sb.sb_blocksize;
-       rbmip->i_diflags |= XFS_DIFLAG_NEWRTBM;
+       ip->i_disk_size = mp->m_sb.sb_rbmblocks * mp->m_sb.sb_blocksize;
+       ip->i_diflags |= XFS_DIFLAG_NEWRTBM;
        if (!xfs_has_rtgroups(mp))
-               inode_set_atime(VFS_I(rbmip), 0, 0);
-       libxfs_trans_log_inode(tp, rbmip, XFS_ILOG_CORE);
-       libxfs_log_sb(tp);
+               inode_set_atime(VFS_I(ip), 0, 0);
 
-       error = -libxfs_trans_commit(tp);
-       if (error)
-               fail(_("Completion of the realtime bitmap inode failed"),
-                               error);
-       mp->m_rbmip = rbmip;
+       mp->m_sb.sb_rbmino = ip->i_ino;
+       mp->m_rbmip = ip;
 }
 
 /* Create the realtime summary inode. */
 static void
 rtsummary_create(
-       struct xfs_mount        *mp)
+       struct xfs_inode        *ip)
 {
-       struct xfs_trans        *tp;
-       struct xfs_inode        *rsumip;
-       int                     error;
+       struct xfs_mount        *mp = ip->i_mount;
 
-       error = -libxfs_trans_alloc_rollable(mp, MKFS_BLOCKRES_INODE, &tp);
-       if (error)
-               res_failed(error);
+       ip->i_disk_size = mp->m_rsumsize;
 
-       /* Create the realtime summary inode. */
-       error = create_sb_metadata_file(&tp, S_IFREG, &rsumip);
-       if (error)
-               fail(_("Realtime summary inode allocation failed"), error);
-
-       mp->m_sb.sb_rsumino = rsumip->i_ino;
-       rsumip->i_disk_size = mp->m_rsumsize;
-       libxfs_trans_log_inode(tp, rsumip, XFS_ILOG_CORE);
-       libxfs_log_sb(tp);
-
-       error = -libxfs_trans_commit(tp);
-       if (error)
-               fail(_("Completion of the realtime summary inode failed"),
-                               error);
-       mp->m_rsumip = rsumip;
+       mp->m_sb.sb_rsumino = ip->i_ino;
+       mp->m_rsumip = ip;
 }
 
 /*
@@ -995,8 +972,8 @@ static void
 rtinit(
        struct xfs_mount        *mp)
 {
-       rtbitmap_create(mp);
-       rtsummary_create(mp);
+       create_sb_metadata_file(mp, rtbitmap_create);
+       create_sb_metadata_file(mp, rtsummary_create);
 
        if (xfs_has_rtgroups(mp))
                rtgroups_create(mp);