]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_repair,mkfs: port to libxfs_rt{bitmap,summary}_create
authorDarrick J. Wong <djwong@kernel.org>
Thu, 21 Nov 2024 00:24:26 +0000 (16:24 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 24 Dec 2024 02:01:32 +0000 (18:01 -0800)
Replace the open-coded rtbitmap and summary creation routines with the
ones in libxfs so that we share code.

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

index 55182bf50fd399b9ad8810e23e83c9fa68313dc1..846b1c9a9e8a2144303894cea2554ff882140820 100644 (file)
@@ -948,7 +948,10 @@ static void
 create_sb_metadata_file(
        struct xfs_rtgroup      *rtg,
        enum xfs_rtg_inodes     type,
-       void                    (*create)(struct xfs_inode *ip))
+       int                     (*create)(struct xfs_rtgroup *rtg,
+                                         struct xfs_inode *ip,
+                                         struct xfs_trans *tp,
+                                         bool init))
 {
        struct xfs_mount        *mp = rtg_mount(rtg);
        struct xfs_icreate_args args = {
@@ -972,9 +975,23 @@ create_sb_metadata_file(
        if (error)
                goto fail;
 
-       create(ip);
+       error = create(rtg, ip, tp, true);
+       if (error < 0)
+               error = -error;
+       if (error)
+               goto fail;
 
-       libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+       switch (type) {
+       case XFS_RTGI_BITMAP:
+               mp->m_sb.sb_rbmino = ip->i_ino;
+               break;
+       case XFS_RTGI_SUMMARY:
+               mp->m_sb.sb_rsumino = ip->i_ino;
+               break;
+       default:
+               error = EFSCORRUPTED;
+               goto fail;
+       }
        libxfs_log_sb(tp);
 
        error = -libxfs_trans_commit(tp);
@@ -990,30 +1007,6 @@ fail:
                fail(_("Realtime inode allocation failed"), error);
 }
 
-static void
-rtbitmap_create(
-       struct xfs_inode        *ip)
-{
-       struct xfs_mount        *mp = ip->i_mount;
-
-       ip->i_disk_size = mp->m_sb.sb_rbmblocks * mp->m_sb.sb_blocksize;
-       ip->i_diflags |= XFS_DIFLAG_NEWRTBM;
-       inode_set_atime(VFS_I(ip), 0, 0);
-
-       mp->m_sb.sb_rbmino = ip->i_ino;
-}
-
-static void
-rtsummary_create(
-       struct xfs_inode        *ip)
-{
-       struct xfs_mount        *mp = ip->i_mount;
-
-       ip->i_disk_size = mp->m_rsumblocks * mp->m_sb.sb_blocksize;
-
-       mp->m_sb.sb_rsumino = ip->i_ino;
-}
-
 /*
  * Free the whole realtime area using transactions.
  * Do one transaction per bitmap block.
@@ -1078,9 +1071,9 @@ rtinit(
 
        while ((rtg = xfs_rtgroup_next(mp, rtg))) {
                create_sb_metadata_file(rtg, XFS_RTGI_BITMAP,
-                               rtbitmap_create);
+                               libxfs_rtbitmap_create);
                create_sb_metadata_file(rtg, XFS_RTGI_SUMMARY,
-                               rtsummary_create);
+                               libxfs_rtsummary_create);
 
                rtfreesp_init(rtg);
        }
index 41342d884ce37a20d52dea79e787c1e87455d825..e9feaa5739efa18970aeee20339c36297ad8d20b 100644 (file)
@@ -550,14 +550,10 @@ _("couldn't iget realtime %s inode -- error - %d\n"),
 
        switch (type) {
        case XFS_RTGI_BITMAP:
-               ip->i_disk_size = mp->m_sb.sb_rbmblocks * mp->m_sb.sb_blocksize;
-               libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
-               error = 0;
+               error = -libxfs_rtbitmap_create(rtg, ip, tp, false);
                break;
        case XFS_RTGI_SUMMARY:
-               ip->i_disk_size = mp->m_rsumblocks * mp->m_sb.sb_blocksize;
-               libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
-               error = 0;
+               error = -libxfs_rtsummary_create(rtg, ip, tp, false);
                break;
        default:
                error = EINVAL;