]> 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>
Mon, 23 Sep 2024 20:42:04 +0000 (13:42 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 9 Oct 2024 23:29:17 +0000 (16:29 -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 1f2bece74afe9ec13afc79207b4e8b327f56fa97..919fe3136fc5e28024fd71f55df5d19dd8ab8cc8 100644 (file)
@@ -30,6 +30,7 @@
 #include "xfs_rtbitmap.h"
 #include "xfs_metafile.h"
 #include "xfs_metadir.h"
+#include "xfs_rtrmap_btree.h"
 
 /* Find the first usable fsblock in this rtgroup. */
 static inline uint32_t
@@ -349,6 +350,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 8572f2d6478797aaab98b6fdbad78253d62a7733..4402a56ce5cbe4cfbee873b039ef6459d9a58197 100644 (file)
@@ -826,3 +826,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;
+       struct xfs_btree_block  *broot;
+
+       ifp->if_format = XFS_DINODE_FMT_RMAP;
+       ASSERT(ifp->if_broot_bytes == 0);
+       ASSERT(ifp->if_bytes == 0);
+
+       /* Initialize the empty incore btree root. */
+       broot = xfs_broot_realloc(ifp, xfs_rtrmap_broot_space_calc(mp, 0, 0));
+       if (broot)
+               xfs_btree_init_block(mp, 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_rgno(rtg) == 0);
+
+       cur = xfs_rtrmapbt_init_cursor(tp, rtg);
+       error = xfs_rmap_map_raw(cur, &rmap);
+       xfs_btree_del_cursor(cur, error);
+       return error;
+}
index ddae34cac10f1c3324e029dd04a0fd91fff93f0d..db313492b17eedd77222ece8dfd23ec70483bb7a 100644 (file)
@@ -193,4 +193,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__ */