[PATCH 053/110] xfs: fold xfs_allocbt_init_common into xfs_allocbt_init_cursor

Darrick J. Wong
2024-03-26T03:42:15Z

From: Christoph Hellwig <hch@lst.de>

Source kernel commit: fb518f8eeb90197624b21a3429e57b6a65bff7bb

Make the levels initialization in xfs_allocbt_init_cursor conditional
and merge the two helpers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
libxfs/xfs_alloc_btree.c | 42 +++++++++++++++---------------------------
1 file changed, 15 insertions(+), 27 deletions(-)

diff --git a/libxfs/xfs_alloc_btree.c b/libxfs/xfs_alloc_btree.c
index 6b17037f807d..13d2310cfa36 100644
--- a/libxfs/xfs_alloc_btree.c
+++ b/libxfs/xfs_alloc_btree.c
@@ -511,11 +511,16 @@ const struct xfs_btree_ops xfs_cntbt_ops = {
.keys_contiguous = NULL, /* not needed right now */
};

-/* Allocate most of a new allocation btree cursor. */
-STATIC struct xfs_btree_cur *
-xfs_allocbt_init_common(
+/*
+ * Allocate a new allocation btree cursor.
+ *
+ * For staging cursors tp and agbp are NULL.
+ */
+struct xfs_btree_cur *
+xfs_allocbt_init_cursor(
struct xfs_mount *mp,
struct xfs_trans *tp,
+ struct xfs_buf *agbp,
struct xfs_perag *pag,
xfs_btnum_t btnum)
{
@@ -530,31 +535,14 @@ xfs_allocbt_init_common(
cur = xfs_btree_alloc_cursor(mp, tp, btnum, ops, mp->m_alloc_maxlevels,
xfs_allocbt_cur_cache);
cur->bc_ag.pag = xfs_perag_hold(pag);
- return cur;
-}
-
-/*
- * Allocate a new allocation btree cursor.
- */
-struct xfs_btree_cur * /* new alloc btree cursor */
-xfs_allocbt_init_cursor(
- struct xfs_mount *mp, /* file system mount point */
- struct xfs_trans *tp, /* transaction pointer */
- struct xfs_buf *agbp, /* buffer for agf structure */
- struct xfs_perag *pag,
- xfs_btnum_t btnum) /* btree identifier */
-{
- struct xfs_agf *agf = agbp->b_addr;
- struct xfs_btree_cur *cur;
-
- cur = xfs_allocbt_init_common(mp, tp, pag, btnum);
- if (btnum == XFS_BTNUM_CNT)
- cur->bc_nlevels = be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]);
- else
- cur->bc_nlevels = be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]);
-
cur->bc_ag.agbp = agbp;
+ if (agbp) {
+ struct xfs_agf *agf = agbp->b_addr;

+ cur->bc_nlevels = (btnum == XFS_BTNUM_BNO) ?
+ be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]) :
+ be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]);
+ }
return cur;
}

@@ -568,7 +556,7 @@ xfs_allocbt_stage_cursor(
{
struct xfs_btree_cur *cur;

- cur = xfs_allocbt_init_common(mp, NULL, pag, btnum);
+ cur = xfs_allocbt_init_cursor(mp, NULL, NULL, pag, btnum);
xfs_btree_stage_afakeroot(cur, afake);
return cur;
}