]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: create routine to allocate and initialize a realtime rmap btree inode
authorDarrick J. Wong <djwong@kernel.org>
Mon, 24 Feb 2025 18:21:49 +0000 (10:21 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 25 Feb 2025 17:15:58 +0000 (09:15 -0800)
Source kernel commit: 71b8acb42be60e11810eb43a6f470589fcf7b7dd

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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
libxfs/xfs_rtgroup.c
libxfs/xfs_rtrmap_btree.c
libxfs/xfs_rtrmap_btree.h

index f0c45e75e52c3e6ca606aaa2c1011d912c69cd64..c40b02be0f41b97fc8671aa15cfbe427565ebb7e 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
@@ -360,6 +361,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 39fd9a0ab986e6050dfbe5a31bb9d4cf99bf42b6..a14f2bec8aaa526cd81a49324a29b48f09c3e031 100644 (file)
@@ -830,3 +830,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_META_BTREE;
+       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 e97695066920ee3ed8eae9528f7a86443101c147..bf73460be274d194943e9e0105428728aa249750 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__ */