]> 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>
Thu, 15 Aug 2024 18:48:55 +0000 (11:48 -0700)
committerChristoph Hellwig <hch@lst.de>
Sun, 22 Sep 2024 08:48:13 +0000 (10:48 +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
fs/xfs/xfs_rtalloc.c

index b8b2370b3057a2d985f1e6119b5fb6f662cddf26..3c06854c25f49eb412c714798e11cc5e4bc602f2 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(
@@ -288,6 +289,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 6a0161e7e4e9b3546579ff0c3c1d6882bbbe9fd1..9551931d7406ed01a990af79f9f6cf0ae0731e60 100644 (file)
@@ -831,3 +831,58 @@ 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(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__ */
index e5f6e1014f2b179ae4f4e996cba6074464417bac..92b227bdda075e1be336ba1f295851be7861a5ae 100644 (file)
@@ -846,6 +846,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;
 }
 
@@ -893,8 +900,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