]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: create routine to allocate and initialize a realtime refcount btree inode
authorDarrick J. Wong <djwong@kernel.org>
Thu, 15 Aug 2024 18:49:26 +0000 (11:49 -0700)
committerChristoph Hellwig <hch@lst.de>
Sun, 22 Sep 2024 08:48:25 +0000 (10:48 +0200)
Create a library routine to allocate and initialize an empty realtime
refcountbt inode.  We'll use this for growfs, mkfs, and repair.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
fs/xfs/libxfs/xfs_rtgroup.c
fs/xfs/libxfs/xfs_rtrefcount_btree.c
fs/xfs/libxfs/xfs_rtrefcount_btree.h

index 168a7017f5b1c2dc6358c7d208c0aa667854c5f7..89504174c7f3afec2d8cec6f7b0e139a0a8cf2b9 100644 (file)
@@ -34,6 +34,7 @@
 #include "xfs_metafile.h"
 #include "xfs_metadir.h"
 #include "xfs_rtrmap_btree.h"
+#include "xfs_rtrefcount_btree.h"
 
 int
 xfs_rtgroup_alloc(
@@ -314,6 +315,7 @@ static const struct xfs_rtginode_ops xfs_rtginode_ops[XFS_RTGI_MAX] = {
                .fmt_mask       = 1U << XFS_DINODE_FMT_REFCOUNT,
                /* same comment about growfs and rmap inodes applies here */
                .enabled        = xfs_has_reflink,
+               .create         = xfs_rtrefcountbt_create,
        },
 };
 
index 6a4f6002fc8722162c07da9d2eafcbc38c479566..3e43d2a7e5c4befac1614bdaa2b1ec14a663fce6 100644 (file)
@@ -721,3 +721,31 @@ xfs_iflush_rtrefcount(
                        ifp->if_broot_bytes, dfp,
                        XFS_DFORK_SIZE(dip, ip->i_mount, XFS_DATA_FORK));
 }
+
+/*
+ * Create a realtime refcount btree inode.
+ */
+int
+xfs_rtrefcountbt_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_REFCOUNT;
+       ASSERT(ifp->if_broot_bytes == 0);
+       ASSERT(ifp->if_bytes == 0);
+
+       /* Initialize the empty incore btree root. */
+       broot = xfs_broot_realloc(ifp,
+                       xfs_rtrefcount_broot_space_calc(mp, 0, 0));
+       if (broot)
+               xfs_btree_init_block(mp, broot, &xfs_rtrefcountbt_ops, 0, 0,
+                               ip->i_ino);
+       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE | XFS_ILOG_DBROOT);
+       return 0;
+}
index 3e587ca765e17988689d357fd44ba57039f90457..484bd2b091a3084f3b5a343220140e04784710c6 100644 (file)
@@ -184,4 +184,7 @@ void xfs_rtrefcountbt_to_disk(struct xfs_mount *mp,
                struct xfs_rtrefcount_root *dblock, int dblocklen);
 void xfs_iflush_rtrefcount(struct xfs_inode *ip, struct xfs_dinode *dip);
 
+int xfs_rtrefcountbt_create(struct xfs_rtgroup *rtg, struct xfs_inode *ip,
+               struct xfs_trans *tp, bool init);
+
 #endif /* __XFS_RTREFCOUNT_BTREE_H__ */