]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs: create routine to allocate and initialize a realtime rmap btree inode
authorDarrick J. Wong <djwong@kernel.org>
Thu, 15 Aug 2024 18:48:55 +0000 (11:48 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 16 Aug 2024 21:57:39 +0000 (14:57 -0700)
Create a library routine to allocate and initialize an empty realtime
rmapbt inode.  We'll use this for mkfs and repair.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
libxfs/xfs_rtgroup.c
libxfs/xfs_rtrmap_btree.c
libxfs/xfs_rtrmap_btree.h

index 65e834b6998303fd28b1849f9702331f30bae6f8..b532c668a1de380ea51880d1e22770072eb478d7 100644 (file)
@@ -30,6 +30,7 @@
 #include "xfs_rtbitmap.h"
 #include "xfs_metafile.h"
 #include "xfs_metadir.h"
+#include "xfs_rtrmap_btree.h"
 
 /*
  * Passive reference counting access wrappers to the rtgroup structures.  If
@@ -399,6 +400,7 @@ static const struct xfs_rtginode_ops xfs_rtginode_ops[XFS_RTGI_MAX] = {
                 * rtrmapbt predicate here.
                 */
                .enabled        = xfs_has_rmapbt,
+               .create         = xfs_rtrmapbt_create,
        },
 };
 
index 2ef2fae68dbead2836cf8f8a796ec9320233b55d..4ba64c8f44be35a276c29d3f48796c9810d768eb 100644 (file)
@@ -803,3 +803,57 @@ xfs_iflush_rtrmap(
        xfs_rtrmapbt_to_disk(ip->i_mount, ifp->if_broot, ifp->if_broot_bytes,
                        dfp, XFS_DFORK_SIZE(dip, ip->i_mount, XFS_DATA_FORK));
 }
+
+/*
+ * Create a realtime rmap btree inode.
+ */
+int
+xfs_rtrmapbt_create(
+       struct xfs_rtgroup      *rtg,
+       struct xfs_inode        *ip,
+       struct xfs_trans        *tp,
+       bool                    init)
+{
+       struct xfs_ifork        *ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK);
+       struct xfs_mount        *mp = ip->i_mount;
+
+       ifp->if_format = XFS_DINODE_FMT_RMAP;
+       ASSERT(ifp->if_broot_bytes == 0);
+       ASSERT(ifp->if_bytes == 0);
+
+       /* Initialize the empty incore btree root. */
+       xfs_iroot_alloc(ip, XFS_DATA_FORK,
+                       xfs_rtrmap_broot_space_calc(mp, 0, 0));
+       xfs_btree_init_block(mp, ifp->if_broot, &xfs_rtrmapbt_ops, 0, 0,
+                       ip->i_ino);
+       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE | XFS_ILOG_DBROOT);
+
+       return 0;
+}
+
+/*
+ * Initialize an rmap for a realtime superblock using the potentially updated
+ * rt geometry in the provided @mp.
+ */
+int
+xfs_rtrmapbt_init_rtsb(
+       struct xfs_mount        *mp,
+       struct xfs_rtgroup      *rtg,
+       struct xfs_trans        *tp)
+{
+       struct xfs_rmap_irec    rmap = {
+               .rm_blockcount  = mp->m_sb.sb_rextsize,
+               .rm_owner       = XFS_RMAP_OWN_FS,
+       };
+       struct xfs_btree_cur    *cur;
+       int                     error;
+
+       ASSERT(xfs_has_rtsb(mp));
+       ASSERT(rtg->rtg_rgno == 0);
+
+       cur = xfs_rtrmapbt_init_cursor(mp, tp, rtg,
+                       rtg->rtg_inodes[XFS_RTGI_RMAP]);
+       error = xfs_rmap_map_raw(cur, &rmap);
+       xfs_btree_del_cursor(cur, error);
+       return error;
+}
index 39471df846abc19bca9009c2d8cd3704fa0cf797..0c8e20380fc846220aa1beb50b4ee7e8f86c7c50 100644 (file)
@@ -194,4 +194,9 @@ void xfs_rtrmapbt_to_disk(struct xfs_mount *mp, struct xfs_btree_block *rblock,
                unsigned int dblocklen);
 void xfs_iflush_rtrmap(struct xfs_inode *ip, struct xfs_dinode *dip);
 
+int xfs_rtrmapbt_create(struct xfs_rtgroup *rtg, struct xfs_inode *ip,
+               struct xfs_trans *tp, bool init);
+int xfs_rtrmapbt_init_rtsb(struct xfs_mount *mp, struct xfs_rtgroup *rtg,
+               struct xfs_trans *tp);
+
 #endif /* __XFS_RTRMAP_BTREE_H__ */