]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: fold xfs_allocbt_init_common into xfs_allocbt_init_cursor
authorChristoph Hellwig <hch@lst.de>
Thu, 22 Feb 2024 20:39:36 +0000 (12:39 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 22 Feb 2024 20:39:36 +0000 (12:39 -0800)
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>
fs/xfs/libxfs/xfs_alloc_btree.c

index 75c66dca61eb19c83a265a9893110047eef19bdc..847674658d675445420e1be8fb8d0c96a4906c57 100644 (file)
@@ -513,11 +513,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)
 {
@@ -532,31 +537,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;
 }
 
@@ -570,7 +558,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;
 }