From 58ca6f55a5463db44ea07dde8605f3442cb776ec Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Wed, 3 Jul 2024 14:22:29 -0700 Subject: [PATCH] xfs: create routine to allocate and initialize a realtime refcount btree inode 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 --- libxfs/xfs_rtrefcount_btree.c | 33 +++++++++++++++++++++++++++++++++ libxfs/xfs_rtrefcount_btree.h | 4 ++++ 2 files changed, 37 insertions(+) diff --git a/libxfs/xfs_rtrefcount_btree.c b/libxfs/xfs_rtrefcount_btree.c index d4ed2efd8..4dcfd20c4 100644 --- a/libxfs/xfs_rtrefcount_btree.c +++ b/libxfs/xfs_rtrefcount_btree.c @@ -697,3 +697,36 @@ xfs_iflush_rtrefcount( ifp->if_broot_bytes, dfp, XFS_DFORK_SIZE(dip, ip->i_mount, XFS_DATA_FORK)); } + +/* + * Create a realtime refcount btree inode. + * + * Regardless of the return value, the caller must clean up @upd. If a new + * inode is returned through @upd->ip, the caller must finish setting up that + * incore inode and release it. + */ +int +xfs_rtrefcountbt_create( + struct xfs_imeta_update *upd) +{ + struct xfs_mount *mp = upd->mp; + struct xfs_ifork *ifp; + int error; + + error = xfs_imeta_create(upd, S_IFREG); + if (error) + return error; + + ifp = xfs_ifork_ptr(upd->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(upd->ip, XFS_DATA_FORK, + xfs_rtrefcount_broot_space_calc(mp, 0, 0)); + xfs_btree_init_block(mp, ifp->if_broot, &xfs_rtrefcountbt_ops, + 0, 0, upd->ip->i_ino); + xfs_trans_log_inode(upd->tp, upd->ip, XFS_ILOG_CORE | XFS_ILOG_DBROOT); + return 0; +} diff --git a/libxfs/xfs_rtrefcount_btree.h b/libxfs/xfs_rtrefcount_btree.h index ee309f625..df72debf8 100644 --- a/libxfs/xfs_rtrefcount_btree.h +++ b/libxfs/xfs_rtrefcount_btree.h @@ -188,4 +188,8 @@ 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); +struct xfs_imeta_update; + +int xfs_rtrefcountbt_create(struct xfs_imeta_update *upd); + #endif /* __XFS_RTREFCOUNT_BTREE_H__ */ -- 2.50.1