]> 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>
Mon, 23 Sep 2024 20:42:04 +0000 (13:42 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 2 Oct 2024 01:10:57 +0000 (18:10 -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>
fs/xfs/libxfs/xfs_rtgroup.c
fs/xfs/libxfs/xfs_rtrmap_btree.c
fs/xfs/libxfs/xfs_rtrmap_btree.h
fs/xfs/xfs_rtalloc.c

index 664846e8f7b83d681cf472b02cb96dd57ccc7b64..dda5dde2e3075637230626e794238945d899cfc2 100644 (file)
@@ -33,6 +33,7 @@
 #include "xfs_rtbitmap.h"
 #include "xfs_metafile.h"
 #include "xfs_metadir.h"
+#include "xfs_rtrmap_btree.h"
 
 int
 xfs_rtgroup_alloc(
@@ -313,6 +314,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 b79264f32e71cdf934b843948e7e0c0eb91615a1..efabd7b3b47b4bd6a20039bd5fc4c9e2a7609e40 100644 (file)
@@ -825,3 +825,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__ */
index af631e64a8280e5c9ef43df02aa89e0bdf016579..a2b86c7617b4662f3226deefab679b90a464a43b 100644 (file)
@@ -845,6 +845,13 @@ xfs_growfs_rt_init_rtsb(
        mp->m_rtsb_bp = rtsb_bp;
        error = xfs_bwrite(rtsb_bp);
        xfs_buf_unlock(rtsb_bp);
+       if (error)
+               return error;
+
+       /* Initialize the rtrmap to reflect the rtsb. */
+       if (args->rtg->rtg_inodes[XFS_RTGI_RMAP] != NULL)
+               error = xfs_rtrmapbt_init_rtsb(nargs->mp, args->rtg, args->tp);
+
        return error;
 }
 
@@ -892,8 +899,9 @@ xfs_growfs_rt_bmblock(
                goto out_free;
        nargs.tp = args.tp;
 
-       xfs_rtgroup_lock(args.rtg, XFS_RTGLOCK_BITMAP);
-       xfs_rtgroup_trans_join(args.tp, args.rtg, XFS_RTGLOCK_BITMAP);
+       xfs_rtgroup_lock(args.rtg, XFS_RTGLOCK_BITMAP | XFS_RTGLOCK_RMAP);
+       xfs_rtgroup_trans_join(args.tp, args.rtg,
+                       XFS_RTGLOCK_BITMAP | XFS_RTGLOCK_RMAP);
 
        /*
         * Update the bitmap inode's size ondisk and incore.  We need to update