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

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

index e1f853dd2c5b3eb7879a985aa3f5bf82e521fe78..74701264265ce2d0d405d7d1817af3db2da5b866 100644 (file)
@@ -31,6 +31,7 @@
 #include "xfs_metafile.h"
 #include "xfs_metadir.h"
 #include "xfs_rtrmap_btree.h"
+#include "xfs_rtrefcount_btree.h"
 
 /* Find the first usable fsblock in this rtgroup. */
 static inline uint32_t
@@ -379,6 +380,7 @@ static const struct xfs_rtginode_ops xfs_rtginode_ops[XFS_RTGI_MAX] = {
                .fmt_mask       = 1U << XFS_DINODE_FMT_META_BTREE,
                /* same comment about growfs and rmap inodes applies here */
                .enabled        = xfs_has_reflink,
+               .create         = xfs_rtrefcountbt_create,
        },
 };
 
index cf9f2ee5314ddaf02185b832d351c82f2c01b98d..fa6c114d9cbc5ac1a1bcea51352845523901071f 100644 (file)
@@ -719,3 +719,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_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_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 e558a10c4744ad63adc9b1a1c956170c9721d00b..a99b7a8aec86597393204e2966f9297d092ce901 100644 (file)
@@ -183,4 +183,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__ */