]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: create routine to allocate and initialize a realtime rmap btree inode
authorDarrick J. Wong <djwong@kernel.org>
Fri, 9 Aug 2024 07:03:58 +0000 (00:03 -0700)
committerChristoph Hellwig <hch@lst.de>
Sat, 10 Aug 2024 08:44:25 +0000 (10:44 +0200)
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>
fs/xfs/libxfs/xfs_rtgroup.c
fs/xfs/libxfs/xfs_rtrmap_btree.c
fs/xfs/libxfs/xfs_rtrmap_btree.h

index abbe81a156476c6ffe51b158044d25d70834b40b..51221ac9483dded71a6355e0e5c2120bb56655ab 100644 (file)
@@ -33,6 +33,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
@@ -384,6 +385,7 @@ static const struct xfs_rtginode_ops xfs_rtginode_ops[XFS_RTG_MAX] = {
                .name           = "rmap",
                .format         = XFS_DINODE_FMT_RMAP,
                .enabled        = xfs_has_rtrmapbt,
+               .create         = xfs_rtrmapbt_create,
        },
 };
 
index 177fa62cce98e6335caa8155d0e1ee6d2c51961d..46e418a8e26b3e6c4f81eefe32f96d5a88505d0d 100644 (file)
@@ -805,3 +805,47 @@ 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;
+       int                     error = 0;
+
+       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);
+
+       if (init && xfs_has_rtsb(mp) && rtg->rtg_rgno == 0) {
+               struct xfs_rmap_irec    rmap = {
+                       .rm_blockcount  = mp->m_sb.sb_rextsize,
+                       .rm_owner       = XFS_RMAP_OWN_FS,
+               };
+               struct xfs_btree_cur    *cur;
+
+               /*
+                * Add an rmap the rtgroup superblock; this had better
+                * fit in the data fork.
+                */
+               cur = xfs_rtrmapbt_init_cursor(mp, tp, rtg, ip);
+               error = xfs_rmap_map_raw(cur, &rmap);
+               xfs_btree_del_cursor(cur, error);
+       }
+
+       return error;
+}
index 39471df846abc19bca9009c2d8cd3704fa0cf797..33b79daa813ded846c1afa043dbebd44f58d20bc 100644 (file)
@@ -194,4 +194,7 @@ 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);
+
 #endif /* __XFS_RTRMAP_BTREE_H__ */