xfs: convert allocbt cursors to use perags

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
This commit is contained in:
Dave Chinner 2021-06-02 10:48:24 +10:00 committed by Dave Chinner
parent a81a06211f
commit 289d38d22c
7 changed files with 32 additions and 43 deletions

View File

@ -776,8 +776,7 @@ xfs_alloc_cur_setup(
*/ */
if (!acur->cnt) if (!acur->cnt)
acur->cnt = xfs_allocbt_init_cursor(args->mp, args->tp, acur->cnt = xfs_allocbt_init_cursor(args->mp, args->tp,
args->agbp, args->agno, args->agbp, args->pag, XFS_BTNUM_CNT);
args->pag, XFS_BTNUM_CNT);
error = xfs_alloc_lookup_ge(acur->cnt, 0, args->maxlen, &i); error = xfs_alloc_lookup_ge(acur->cnt, 0, args->maxlen, &i);
if (error) if (error)
return error; return error;
@ -787,12 +786,10 @@ xfs_alloc_cur_setup(
*/ */
if (!acur->bnolt) if (!acur->bnolt)
acur->bnolt = xfs_allocbt_init_cursor(args->mp, args->tp, acur->bnolt = xfs_allocbt_init_cursor(args->mp, args->tp,
args->agbp, args->agno, args->agbp, args->pag, XFS_BTNUM_BNO);
args->pag, XFS_BTNUM_BNO);
if (!acur->bnogt) if (!acur->bnogt)
acur->bnogt = xfs_allocbt_init_cursor(args->mp, args->tp, acur->bnogt = xfs_allocbt_init_cursor(args->mp, args->tp,
args->agbp, args->agno, args->agbp, args->pag, XFS_BTNUM_BNO);
args->pag, XFS_BTNUM_BNO);
return i == 1 ? 0 : -ENOSPC; return i == 1 ? 0 : -ENOSPC;
} }
@ -1220,7 +1217,7 @@ xfs_alloc_ag_vextent_exact(
* Allocate/initialize a cursor for the by-number freespace btree. * Allocate/initialize a cursor for the by-number freespace btree.
*/ */
bno_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp, bno_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
args->agno, args->pag, XFS_BTNUM_BNO); args->pag, XFS_BTNUM_BNO);
/* /*
* Lookup bno and minlen in the btree (minlen is irrelevant, really). * Lookup bno and minlen in the btree (minlen is irrelevant, really).
@ -1280,7 +1277,7 @@ xfs_alloc_ag_vextent_exact(
* Allocate/initialize a cursor for the by-size btree. * Allocate/initialize a cursor for the by-size btree.
*/ */
cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp, cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
args->agno, args->pag, XFS_BTNUM_CNT); args->pag, XFS_BTNUM_CNT);
ASSERT(args->agbno + args->len <= be32_to_cpu(agf->agf_length)); ASSERT(args->agbno + args->len <= be32_to_cpu(agf->agf_length));
error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen, args->agbno, error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen, args->agbno,
args->len, XFSA_FIXUP_BNO_OK); args->len, XFSA_FIXUP_BNO_OK);
@ -1677,7 +1674,7 @@ restart:
* Allocate and initialize a cursor for the by-size btree. * Allocate and initialize a cursor for the by-size btree.
*/ */
cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp, cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
args->agno, args->pag, XFS_BTNUM_CNT); args->pag, XFS_BTNUM_CNT);
bno_cur = NULL; bno_cur = NULL;
busy = false; busy = false;
@ -1840,7 +1837,7 @@ restart:
* Allocate and initialize a cursor for the by-block tree. * Allocate and initialize a cursor for the by-block tree.
*/ */
bno_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp, bno_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
args->agno, args->pag, XFS_BTNUM_BNO); args->pag, XFS_BTNUM_BNO);
if ((error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen, if ((error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen,
rbno, rlen, XFSA_FIXUP_CNT_OK))) rbno, rlen, XFSA_FIXUP_CNT_OK)))
goto error0; goto error0;
@ -1913,8 +1910,7 @@ xfs_free_ag_extent(
/* /*
* Allocate and initialize a cursor for the by-block btree. * Allocate and initialize a cursor for the by-block btree.
*/ */
bno_cur = xfs_allocbt_init_cursor(mp, tp, agbp, agno, bno_cur = xfs_allocbt_init_cursor(mp, tp, agbp, pag, XFS_BTNUM_BNO);
NULL, XFS_BTNUM_BNO);
/* /*
* Look for a neighboring block on the left (lower block numbers) * Look for a neighboring block on the left (lower block numbers)
* that is contiguous with this space. * that is contiguous with this space.
@ -1984,8 +1980,7 @@ xfs_free_ag_extent(
/* /*
* Now allocate and initialize a cursor for the by-size tree. * Now allocate and initialize a cursor for the by-size tree.
*/ */
cnt_cur = xfs_allocbt_init_cursor(mp, tp, agbp, agno, cnt_cur = xfs_allocbt_init_cursor(mp, tp, agbp, pag, XFS_BTNUM_CNT);
NULL, XFS_BTNUM_CNT);
/* /*
* Have both left and right contiguous neighbors. * Have both left and right contiguous neighbors.
* Merge all three into a single free block. * Merge all three into a single free block.
@ -2496,7 +2491,7 @@ xfs_exact_minlen_extent_available(
int error = 0; int error = 0;
cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, agbp, cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, agbp,
args->agno, args->pag, XFS_BTNUM_CNT); args->pag, XFS_BTNUM_CNT);
error = xfs_alloc_lookup_ge(cnt_cur, 0, args->minlen, stat); error = xfs_alloc_lookup_ge(cnt_cur, 0, args->minlen, stat);
if (error) if (error)
goto out; goto out;

View File

@ -26,8 +26,7 @@ xfs_allocbt_dup_cursor(
struct xfs_btree_cur *cur) struct xfs_btree_cur *cur)
{ {
return xfs_allocbt_init_cursor(cur->bc_mp, cur->bc_tp, return xfs_allocbt_init_cursor(cur->bc_mp, cur->bc_tp,
cur->bc_ag.agbp, cur->bc_ag.agno, cur->bc_ag.agbp, cur->bc_ag.pag, cur->bc_btnum);
cur->bc_ag.pag, cur->bc_btnum);
} }
STATIC void STATIC void
@ -39,13 +38,12 @@ xfs_allocbt_set_root(
struct xfs_buf *agbp = cur->bc_ag.agbp; struct xfs_buf *agbp = cur->bc_ag.agbp;
struct xfs_agf *agf = agbp->b_addr; struct xfs_agf *agf = agbp->b_addr;
int btnum = cur->bc_btnum; int btnum = cur->bc_btnum;
struct xfs_perag *pag = agbp->b_pag;
ASSERT(ptr->s != 0); ASSERT(ptr->s != 0);
agf->agf_roots[btnum] = ptr->s; agf->agf_roots[btnum] = ptr->s;
be32_add_cpu(&agf->agf_levels[btnum], inc); be32_add_cpu(&agf->agf_levels[btnum], inc);
pag->pagf_levels[btnum] += inc; cur->bc_ag.pag->pagf_levels[btnum] += inc;
xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_ROOTS | XFS_AGF_LEVELS); xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_ROOTS | XFS_AGF_LEVELS);
} }
@ -224,7 +222,7 @@ xfs_allocbt_init_ptr_from_cur(
{ {
struct xfs_agf *agf = cur->bc_ag.agbp->b_addr; struct xfs_agf *agf = cur->bc_ag.agbp->b_addr;
ASSERT(cur->bc_ag.agno == be32_to_cpu(agf->agf_seqno)); ASSERT(cur->bc_ag.pag->pag_agno == be32_to_cpu(agf->agf_seqno));
ptr->s = agf->agf_roots[cur->bc_btnum]; ptr->s = agf->agf_roots[cur->bc_btnum];
} }
@ -472,7 +470,6 @@ STATIC struct xfs_btree_cur *
xfs_allocbt_init_common( xfs_allocbt_init_common(
struct xfs_mount *mp, struct xfs_mount *mp,
struct xfs_trans *tp, struct xfs_trans *tp,
xfs_agnumber_t agno,
struct xfs_perag *pag, struct xfs_perag *pag,
xfs_btnum_t btnum) xfs_btnum_t btnum)
{ {
@ -486,6 +483,7 @@ xfs_allocbt_init_common(
cur->bc_mp = mp; cur->bc_mp = mp;
cur->bc_btnum = btnum; cur->bc_btnum = btnum;
cur->bc_blocklog = mp->m_sb.sb_blocklog; cur->bc_blocklog = mp->m_sb.sb_blocklog;
cur->bc_ag.abt.active = false;
if (btnum == XFS_BTNUM_CNT) { if (btnum == XFS_BTNUM_CNT) {
cur->bc_ops = &xfs_cntbt_ops; cur->bc_ops = &xfs_cntbt_ops;
@ -496,13 +494,10 @@ xfs_allocbt_init_common(
cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_abtb_2); cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_abtb_2);
} }
cur->bc_ag.agno = agno; /* take a reference for the cursor */
cur->bc_ag.abt.active = false; atomic_inc(&pag->pag_ref);
if (pag) {
/* take a reference for the cursor */
atomic_inc(&pag->pag_ref);
}
cur->bc_ag.pag = pag; cur->bc_ag.pag = pag;
cur->bc_ag.agno = pag->pag_agno;
if (xfs_sb_version_hascrc(&mp->m_sb)) if (xfs_sb_version_hascrc(&mp->m_sb))
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS; cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
@ -518,14 +513,13 @@ xfs_allocbt_init_cursor(
struct xfs_mount *mp, /* file system mount point */ struct xfs_mount *mp, /* file system mount point */
struct xfs_trans *tp, /* transaction pointer */ struct xfs_trans *tp, /* transaction pointer */
struct xfs_buf *agbp, /* buffer for agf structure */ struct xfs_buf *agbp, /* buffer for agf structure */
xfs_agnumber_t agno, /* allocation group number */
struct xfs_perag *pag, struct xfs_perag *pag,
xfs_btnum_t btnum) /* btree identifier */ xfs_btnum_t btnum) /* btree identifier */
{ {
struct xfs_agf *agf = agbp->b_addr; struct xfs_agf *agf = agbp->b_addr;
struct xfs_btree_cur *cur; struct xfs_btree_cur *cur;
cur = xfs_allocbt_init_common(mp, tp, agno, pag, btnum); cur = xfs_allocbt_init_common(mp, tp, pag, btnum);
if (btnum == XFS_BTNUM_CNT) if (btnum == XFS_BTNUM_CNT)
cur->bc_nlevels = be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]); cur->bc_nlevels = be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]);
else else
@ -541,12 +535,12 @@ struct xfs_btree_cur *
xfs_allocbt_stage_cursor( xfs_allocbt_stage_cursor(
struct xfs_mount *mp, struct xfs_mount *mp,
struct xbtree_afakeroot *afake, struct xbtree_afakeroot *afake,
xfs_agnumber_t agno, struct xfs_perag *pag,
xfs_btnum_t btnum) xfs_btnum_t btnum)
{ {
struct xfs_btree_cur *cur; struct xfs_btree_cur *cur;
cur = xfs_allocbt_init_common(mp, NULL, agno, NULL, btnum); cur = xfs_allocbt_init_common(mp, NULL, pag, btnum);
xfs_btree_stage_afakeroot(cur, afake); xfs_btree_stage_afakeroot(cur, afake);
return cur; return cur;
} }

View File

@ -47,11 +47,11 @@ struct xbtree_afakeroot;
(maxrecs) * sizeof(xfs_alloc_key_t) + \ (maxrecs) * sizeof(xfs_alloc_key_t) + \
((index) - 1) * sizeof(xfs_alloc_ptr_t))) ((index) - 1) * sizeof(xfs_alloc_ptr_t)))
extern struct xfs_btree_cur *xfs_allocbt_init_cursor(struct xfs_mount *, extern struct xfs_btree_cur *xfs_allocbt_init_cursor(struct xfs_mount *mp,
struct xfs_trans *, struct xfs_buf *, struct xfs_trans *tp, struct xfs_buf *bp,
xfs_agnumber_t, struct xfs_perag *pag, xfs_btnum_t); struct xfs_perag *pag, xfs_btnum_t btnum);
struct xfs_btree_cur *xfs_allocbt_stage_cursor(struct xfs_mount *mp, struct xfs_btree_cur *xfs_allocbt_stage_cursor(struct xfs_mount *mp,
struct xbtree_afakeroot *afake, xfs_agnumber_t agno, struct xbtree_afakeroot *afake, struct xfs_perag *pag,
xfs_btnum_t btnum); xfs_btnum_t btnum);
extern int xfs_allocbt_maxrecs(struct xfs_mount *, int, int); extern int xfs_allocbt_maxrecs(struct xfs_mount *, int, int);
extern xfs_extlen_t xfs_allocbt_calc_size(struct xfs_mount *mp, extern xfs_extlen_t xfs_allocbt_calc_size(struct xfs_mount *mp,

View File

@ -246,7 +246,7 @@ xrep_agf_calc_from_btrees(
int error; int error;
/* Update the AGF counters from the bnobt. */ /* Update the AGF counters from the bnobt. */
cur = xfs_allocbt_init_cursor(mp, sc->tp, agf_bp, sc->sa.agno, cur = xfs_allocbt_init_cursor(mp, sc->tp, agf_bp,
sc->sa.pag, XFS_BTNUM_BNO); sc->sa.pag, XFS_BTNUM_BNO);
error = xfs_alloc_query_all(cur, xrep_agf_walk_allocbt, &raa); error = xfs_alloc_query_all(cur, xrep_agf_walk_allocbt, &raa);
if (error) if (error)
@ -260,7 +260,7 @@ xrep_agf_calc_from_btrees(
agf->agf_longest = cpu_to_be32(raa.longest); agf->agf_longest = cpu_to_be32(raa.longest);
/* Update the AGF counters from the cntbt. */ /* Update the AGF counters from the cntbt. */
cur = xfs_allocbt_init_cursor(mp, sc->tp, agf_bp, sc->sa.agno, cur = xfs_allocbt_init_cursor(mp, sc->tp, agf_bp,
sc->sa.pag, XFS_BTNUM_CNT); sc->sa.pag, XFS_BTNUM_CNT);
error = xfs_btree_count_blocks(cur, &blocks); error = xfs_btree_count_blocks(cur, &blocks);
if (error) if (error)
@ -497,7 +497,7 @@ xrep_agfl_collect_blocks(
xfs_btree_del_cursor(cur, error); xfs_btree_del_cursor(cur, error);
/* Find all blocks currently being used by the bnobt. */ /* Find all blocks currently being used by the bnobt. */
cur = xfs_allocbt_init_cursor(mp, sc->tp, agf_bp, sc->sa.agno, cur = xfs_allocbt_init_cursor(mp, sc->tp, agf_bp,
sc->sa.pag, XFS_BTNUM_BNO); sc->sa.pag, XFS_BTNUM_BNO);
error = xbitmap_set_btblocks(&ra.agmetablocks, cur); error = xbitmap_set_btblocks(&ra.agmetablocks, cur);
if (error) if (error)
@ -505,7 +505,7 @@ xrep_agfl_collect_blocks(
xfs_btree_del_cursor(cur, error); xfs_btree_del_cursor(cur, error);
/* Find all blocks currently being used by the cntbt. */ /* Find all blocks currently being used by the cntbt. */
cur = xfs_allocbt_init_cursor(mp, sc->tp, agf_bp, sc->sa.agno, cur = xfs_allocbt_init_cursor(mp, sc->tp, agf_bp,
sc->sa.pag, XFS_BTNUM_CNT); sc->sa.pag, XFS_BTNUM_CNT);
error = xbitmap_set_btblocks(&ra.agmetablocks, cur); error = xbitmap_set_btblocks(&ra.agmetablocks, cur);
if (error) if (error)

View File

@ -465,14 +465,14 @@ xchk_ag_btcur_init(
xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_BNO)) { xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_BNO)) {
/* Set up a bnobt cursor for cross-referencing. */ /* Set up a bnobt cursor for cross-referencing. */
sa->bno_cur = xfs_allocbt_init_cursor(mp, sc->tp, sa->agf_bp, sa->bno_cur = xfs_allocbt_init_cursor(mp, sc->tp, sa->agf_bp,
agno, sa->pag, XFS_BTNUM_BNO); sa->pag, XFS_BTNUM_BNO);
} }
if (sa->agf_bp && if (sa->agf_bp &&
xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_CNT)) { xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_CNT)) {
/* Set up a cntbt cursor for cross-referencing. */ /* Set up a cntbt cursor for cross-referencing. */
sa->cnt_cur = xfs_allocbt_init_cursor(mp, sc->tp, sa->agf_bp, sa->cnt_cur = xfs_allocbt_init_cursor(mp, sc->tp, sa->agf_bp,
agno, sa->pag, XFS_BTNUM_CNT); sa->pag, XFS_BTNUM_CNT);
} }
/* Set up a inobt cursor for cross-referencing. */ /* Set up a inobt cursor for cross-referencing. */

View File

@ -50,7 +50,7 @@ xfs_trim_extents(
goto out_put_perag; goto out_put_perag;
agf = agbp->b_addr; agf = agbp->b_addr;
cur = xfs_allocbt_init_cursor(mp, NULL, agbp, agno, pag, XFS_BTNUM_CNT); cur = xfs_allocbt_init_cursor(mp, NULL, agbp, pag, XFS_BTNUM_CNT);
/* /*
* Look up the longest btree in the AGF and start with it. * Look up the longest btree in the AGF and start with it.

View File

@ -740,7 +740,7 @@ xfs_getfsmap_datadev_bnobt_query(
/* Allocate cursor for this AG and query_range it. */ /* Allocate cursor for this AG and query_range it. */
*curpp = xfs_allocbt_init_cursor(tp->t_mountp, tp, info->agf_bp, *curpp = xfs_allocbt_init_cursor(tp->t_mountp, tp, info->agf_bp,
info->pag->pag_agno, info->pag, XFS_BTNUM_BNO); info->pag, XFS_BTNUM_BNO);
key->ar_startblock = info->low.rm_startblock; key->ar_startblock = info->low.rm_startblock;
key[1].ar_startblock = info->high.rm_startblock; key[1].ar_startblock = info->high.rm_startblock;
return xfs_alloc_query_range(*curpp, key, &key[1], return xfs_alloc_query_range(*curpp, key, &key[1],