From 5343454a347f23695b6afcb25dbd9e697307aea4 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Sun, 11 Aug 2024 08:55:30 +0200 Subject: [PATCH] xfs: create routine to allocate and initialize a realtime refcount btree inode Source kernel commit: 0066145ac851fd746ed22e523c3b60062e94c250 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 Signed-off-by: Christoph Hellwig --- libxfs/xfs_rtgroup.c | 2 ++ libxfs/xfs_rtrefcount_btree.c | 25 +++++++++++++++++++++++++ libxfs/xfs_rtrefcount_btree.h | 3 +++ 3 files changed, 30 insertions(+) diff --git a/libxfs/xfs_rtgroup.c b/libxfs/xfs_rtgroup.c index e43258a4a..274158c35 100644 --- a/libxfs/xfs_rtgroup.c +++ b/libxfs/xfs_rtgroup.c @@ -31,6 +31,7 @@ #include "xfs_metafile.h" #include "xfs_metadir.h" #include "xfs_rtrmap_btree.h" +#include "xfs_rtrefcount_btree.h" /* * Passive reference counting access wrappers to the rtgroup structures. If @@ -419,6 +420,7 @@ static const struct xfs_rtginode_ops xfs_rtginode_ops[XFS_RTG_MAX] = { .metafile_type = XFS_METAFILE_RTREFCOUNT, .format = XFS_DINODE_FMT_REFCOUNT, .enabled = xfs_has_rtreflink, + .create = xfs_rtrefcountbt_create, }, }; diff --git a/libxfs/xfs_rtrefcount_btree.c b/libxfs/xfs_rtrefcount_btree.c index ba9dc33b7..ed6ef0356 100644 --- a/libxfs/xfs_rtrefcount_btree.c +++ b/libxfs/xfs_rtrefcount_btree.c @@ -697,3 +697,28 @@ 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); + + ifp->if_format = XFS_DINODE_FMT_REFCOUNT; + 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_rtrefcount_broot_space_calc(ip->i_mount, 0, 0)); + xfs_btree_init_block(ip->i_mount, ifp->if_broot, &xfs_rtrefcountbt_ops, + 0, 0, ip->i_ino); + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE | XFS_ILOG_DBROOT); + return 0; +} diff --git a/libxfs/xfs_rtrefcount_btree.h b/libxfs/xfs_rtrefcount_btree.h index 3e587ca76..484bd2b09 100644 --- a/libxfs/xfs_rtrefcount_btree.h +++ b/libxfs/xfs_rtrefcount_btree.h @@ -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__ */ -- 2.50.1