Skip to content

Commit

Permalink
xfs: add a perag to the btree cursor
Browse files Browse the repository at this point in the history
Which will eventually completely replace the agno in it.

Signed-off-by: Dave Chinner <[email protected]>
Reviewed-by: Darrick J. Wong <[email protected]>
Reviewed-by: Brian Foster <[email protected]>
  • Loading branch information
Dave Chinner authored and dchinner committed Jun 2, 2021
1 parent 58d43a7 commit be9fb17
Show file tree
Hide file tree
Showing 21 changed files with 119 additions and 70 deletions.
25 changes: 15 additions & 10 deletions fs/xfs/libxfs/xfs_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,8 @@ xfs_alloc_cur_setup(
*/
if (!acur->cnt)
acur->cnt = xfs_allocbt_init_cursor(args->mp, args->tp,
args->agbp, args->agno, XFS_BTNUM_CNT);
args->agbp, args->agno,
args->pag, XFS_BTNUM_CNT);
error = xfs_alloc_lookup_ge(acur->cnt, 0, args->maxlen, &i);
if (error)
return error;
Expand All @@ -786,10 +787,12 @@ xfs_alloc_cur_setup(
*/
if (!acur->bnolt)
acur->bnolt = xfs_allocbt_init_cursor(args->mp, args->tp,
args->agbp, args->agno, XFS_BTNUM_BNO);
args->agbp, args->agno,
args->pag, XFS_BTNUM_BNO);
if (!acur->bnogt)
acur->bnogt = xfs_allocbt_init_cursor(args->mp, args->tp,
args->agbp, args->agno, XFS_BTNUM_BNO);
args->agbp, args->agno,
args->pag, XFS_BTNUM_BNO);
return i == 1 ? 0 : -ENOSPC;
}

Expand Down Expand Up @@ -1217,7 +1220,7 @@ xfs_alloc_ag_vextent_exact(
* Allocate/initialize a cursor for the by-number freespace btree.
*/
bno_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
args->agno, XFS_BTNUM_BNO);
args->agno, args->pag, XFS_BTNUM_BNO);

/*
* Lookup bno and minlen in the btree (minlen is irrelevant, really).
Expand Down Expand Up @@ -1277,7 +1280,7 @@ xfs_alloc_ag_vextent_exact(
* Allocate/initialize a cursor for the by-size btree.
*/
cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
args->agno, XFS_BTNUM_CNT);
args->agno, args->pag, XFS_BTNUM_CNT);
ASSERT(args->agbno + args->len <= be32_to_cpu(agf->agf_length));
error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen, args->agbno,
args->len, XFSA_FIXUP_BNO_OK);
Expand Down Expand Up @@ -1674,7 +1677,7 @@ xfs_alloc_ag_vextent_size(
* Allocate and initialize a cursor for the by-size btree.
*/
cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
args->agno, XFS_BTNUM_CNT);
args->agno, args->pag, XFS_BTNUM_CNT);
bno_cur = NULL;
busy = false;

Expand Down Expand Up @@ -1837,7 +1840,7 @@ xfs_alloc_ag_vextent_size(
* Allocate and initialize a cursor for the by-block tree.
*/
bno_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
args->agno, XFS_BTNUM_BNO);
args->agno, args->pag, XFS_BTNUM_BNO);
if ((error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen,
rbno, rlen, XFSA_FIXUP_CNT_OK)))
goto error0;
Expand Down Expand Up @@ -1909,7 +1912,8 @@ xfs_free_ag_extent(
/*
* Allocate and initialize a cursor for the by-block btree.
*/
bno_cur = xfs_allocbt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_BNO);
bno_cur = xfs_allocbt_init_cursor(mp, tp, agbp, agno,
NULL, XFS_BTNUM_BNO);
/*
* Look for a neighboring block on the left (lower block numbers)
* that is contiguous with this space.
Expand Down Expand Up @@ -1979,7 +1983,8 @@ xfs_free_ag_extent(
/*
* Now allocate and initialize a cursor for the by-size tree.
*/
cnt_cur = xfs_allocbt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_CNT);
cnt_cur = xfs_allocbt_init_cursor(mp, tp, agbp, agno,
NULL, XFS_BTNUM_CNT);
/*
* Have both left and right contiguous neighbors.
* Merge all three into a single free block.
Expand Down Expand Up @@ -2490,7 +2495,7 @@ xfs_exact_minlen_extent_available(
int error = 0;

cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, agbp,
args->agno, XFS_BTNUM_CNT);
args->agno, args->pag, XFS_BTNUM_CNT);
error = xfs_alloc_lookup_ge(cnt_cur, 0, args->minlen, stat);
if (error)
goto out;
Expand Down
13 changes: 10 additions & 3 deletions fs/xfs/libxfs/xfs_alloc_btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ xfs_allocbt_dup_cursor(
{
return xfs_allocbt_init_cursor(cur->bc_mp, cur->bc_tp,
cur->bc_ag.agbp, cur->bc_ag.agno,
cur->bc_btnum);
cur->bc_ag.pag, cur->bc_btnum);
}

STATIC void
Expand Down Expand Up @@ -473,6 +473,7 @@ xfs_allocbt_init_common(
struct xfs_mount *mp,
struct xfs_trans *tp,
xfs_agnumber_t agno,
struct xfs_perag *pag,
xfs_btnum_t btnum)
{
struct xfs_btree_cur *cur;
Expand All @@ -497,6 +498,11 @@ xfs_allocbt_init_common(

cur->bc_ag.agno = agno;
cur->bc_ag.abt.active = false;
if (pag) {
/* take a reference for the cursor */
atomic_inc(&pag->pag_ref);
}
cur->bc_ag.pag = pag;

if (xfs_sb_version_hascrc(&mp->m_sb))
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
Expand All @@ -513,12 +519,13 @@ xfs_allocbt_init_cursor(
struct xfs_trans *tp, /* transaction pointer */
struct xfs_buf *agbp, /* buffer for agf structure */
xfs_agnumber_t agno, /* allocation group number */
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, agno, btnum);
cur = xfs_allocbt_init_common(mp, tp, agno, pag, btnum);
if (btnum == XFS_BTNUM_CNT)
cur->bc_nlevels = be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]);
else
Expand All @@ -539,7 +546,7 @@ xfs_allocbt_stage_cursor(
{
struct xfs_btree_cur *cur;

cur = xfs_allocbt_init_common(mp, NULL, agno, btnum);
cur = xfs_allocbt_init_common(mp, NULL, agno, NULL, btnum);
xfs_btree_stage_afakeroot(cur, afake);
return cur;
}
Expand Down
3 changes: 2 additions & 1 deletion fs/xfs/libxfs/xfs_alloc_btree.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
struct xfs_buf;
struct xfs_btree_cur;
struct xfs_mount;
struct xfs_perag;
struct xbtree_afakeroot;

/*
Expand Down Expand Up @@ -48,7 +49,7 @@ struct xbtree_afakeroot;

extern struct xfs_btree_cur *xfs_allocbt_init_cursor(struct xfs_mount *,
struct xfs_trans *, struct xfs_buf *,
xfs_agnumber_t, xfs_btnum_t);
xfs_agnumber_t, struct xfs_perag *pag, xfs_btnum_t);
struct xfs_btree_cur *xfs_allocbt_stage_cursor(struct xfs_mount *mp,
struct xbtree_afakeroot *afake, xfs_agnumber_t agno,
xfs_btnum_t btnum);
Expand Down
2 changes: 2 additions & 0 deletions fs/xfs/libxfs/xfs_btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ xfs_btree_del_cursor(
XFS_FORCED_SHUTDOWN(cur->bc_mp));
if (unlikely(cur->bc_flags & XFS_BTREE_STAGING))
kmem_free(cur->bc_ops);
if (!(cur->bc_flags & XFS_BTREE_LONG_PTRS) && cur->bc_ag.pag)
xfs_perag_put(cur->bc_ag.pag);
kmem_cache_free(xfs_btree_cur_zone, cur);
}

Expand Down
11 changes: 10 additions & 1 deletion fs/xfs/libxfs/xfs_btree.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct xfs_inode;
struct xfs_mount;
struct xfs_trans;
struct xfs_ifork;
struct xfs_perag;

extern kmem_zone_t *xfs_btree_cur_zone;

Expand Down Expand Up @@ -180,11 +181,12 @@ union xfs_btree_irec {

/* Per-AG btree information. */
struct xfs_btree_cur_ag {
xfs_agnumber_t agno;
struct xfs_perag *pag;
union {
struct xfs_buf *agbp;
struct xbtree_afakeroot *afake; /* for staging cursor */
};
xfs_agnumber_t agno;
union {
struct {
unsigned long nr_ops; /* # record updates */
Expand Down Expand Up @@ -231,6 +233,13 @@ typedef struct xfs_btree_cur
uint8_t bc_blocklog; /* log2(blocksize) of btree blocks */
xfs_btnum_t bc_btnum; /* identifies which btree type */
int bc_statoff; /* offset of btre stats array */

/*
* Short btree pointers need an agno to be able to turn the pointers
* into physical addresses for IO, so the btree cursor switches between
* bc_ino and bc_ag based on whether XFS_BTREE_LONG_PTRS is set for the
* cursor.
*/
union {
struct xfs_btree_cur_ag bc_ag;
struct xfs_btree_cur_ino bc_ino;
Expand Down
16 changes: 8 additions & 8 deletions fs/xfs/libxfs/xfs_ialloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ xfs_inobt_insert(
int i;
int error;

cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, btnum);
cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, btnum);

for (thisino = newino;
thisino < newino + newlen;
Expand Down Expand Up @@ -531,7 +531,7 @@ xfs_inobt_insert_sprec(
int i;
struct xfs_inobt_rec_incore rec;

cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, btnum);
cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, btnum);

/* the new record is pre-aligned so we know where to look */
error = xfs_inobt_lookup(cur, nrec->ir_startino, XFS_LOOKUP_EQ, &i);
Expand Down Expand Up @@ -1145,7 +1145,7 @@ xfs_dialloc_ag_inobt(
ASSERT(pag->pagi_freecount > 0);

restart_pagno:
cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_INO);
cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, XFS_BTNUM_INO);
/*
* If pagino is 0 (this is the root inode allocation) use newino.
* This must work because we've just allocated some.
Expand Down Expand Up @@ -1598,7 +1598,7 @@ xfs_dialloc_ag(
if (!pagino)
pagino = be32_to_cpu(agi->agi_newino);

cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_FINO);
cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, XFS_BTNUM_FINO);

error = xfs_check_agi_freecount(cur, agi);
if (error)
Expand Down Expand Up @@ -1641,7 +1641,7 @@ xfs_dialloc_ag(
* the original freecount. If all is well, make the equivalent update to
* the inobt using the finobt record and offset information.
*/
icur = xfs_inobt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_INO);
icur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, XFS_BTNUM_INO);

error = xfs_check_agi_freecount(icur, agi);
if (error)
Expand Down Expand Up @@ -1954,7 +1954,7 @@ xfs_difree_inobt(
/*
* Initialize the cursor.
*/
cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_INO);
cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, XFS_BTNUM_INO);

error = xfs_check_agi_freecount(cur, agi);
if (error)
Expand Down Expand Up @@ -2080,7 +2080,7 @@ xfs_difree_finobt(
int error;
int i;

cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_FINO);
cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, XFS_BTNUM_FINO);

error = xfs_inobt_lookup(cur, ibtrec->ir_startino, XFS_LOOKUP_EQ, &i);
if (error)
Expand Down Expand Up @@ -2281,7 +2281,7 @@ xfs_imap_lookup(
* we have a record, we need to ensure it contains the inode number
* we are looking up.
*/
cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_INO);
cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, XFS_BTNUM_INO);
error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &i);
if (!error) {
if (i)
Expand Down
15 changes: 11 additions & 4 deletions fs/xfs/libxfs/xfs_ialloc_btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ xfs_inobt_dup_cursor(
{
return xfs_inobt_init_cursor(cur->bc_mp, cur->bc_tp,
cur->bc_ag.agbp, cur->bc_ag.agno,
cur->bc_btnum);
cur->bc_ag.pag, cur->bc_btnum);
}

STATIC void
Expand Down Expand Up @@ -429,6 +429,7 @@ xfs_inobt_init_common(
struct xfs_mount *mp, /* file system mount point */
struct xfs_trans *tp, /* transaction pointer */
xfs_agnumber_t agno, /* allocation group number */
struct xfs_perag *pag,
xfs_btnum_t btnum) /* ialloc or free ino btree */
{
struct xfs_btree_cur *cur;
Expand All @@ -451,6 +452,11 @@ xfs_inobt_init_common(
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;

cur->bc_ag.agno = agno;
if (pag) {
/* take a reference for the cursor */
atomic_inc(&pag->pag_ref);
}
cur->bc_ag.pag = pag;
return cur;
}

Expand All @@ -461,12 +467,13 @@ xfs_inobt_init_cursor(
struct xfs_trans *tp,
struct xfs_buf *agbp,
xfs_agnumber_t agno,
struct xfs_perag *pag,
xfs_btnum_t btnum)
{
struct xfs_btree_cur *cur;
struct xfs_agi *agi = agbp->b_addr;

cur = xfs_inobt_init_common(mp, tp, agno, btnum);
cur = xfs_inobt_init_common(mp, tp, agno, pag, btnum);
if (btnum == XFS_BTNUM_INO)
cur->bc_nlevels = be32_to_cpu(agi->agi_level);
else
Expand All @@ -485,7 +492,7 @@ xfs_inobt_stage_cursor(
{
struct xfs_btree_cur *cur;

cur = xfs_inobt_init_common(mp, NULL, agno, btnum);
cur = xfs_inobt_init_common(mp, NULL, agno, NULL, btnum);
xfs_btree_stage_afakeroot(cur, afake);
return cur;
}
Expand Down Expand Up @@ -672,7 +679,7 @@ xfs_inobt_cur(
if (error)
return error;

cur = xfs_inobt_init_cursor(mp, tp, *agi_bpp, agno, which);
cur = xfs_inobt_init_cursor(mp, tp, *agi_bpp, agno, NULL, which);
*curpp = cur;
return 0;
}
Expand Down
7 changes: 4 additions & 3 deletions fs/xfs/libxfs/xfs_ialloc_btree.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
struct xfs_buf;
struct xfs_btree_cur;
struct xfs_mount;
struct xfs_perag;

/*
* Btree block header size depends on a superblock flag.
Expand Down Expand Up @@ -45,9 +46,9 @@ struct xfs_mount;
(maxrecs) * sizeof(xfs_inobt_key_t) + \
((index) - 1) * sizeof(xfs_inobt_ptr_t)))

extern struct xfs_btree_cur *xfs_inobt_init_cursor(struct xfs_mount *,
struct xfs_trans *, struct xfs_buf *, xfs_agnumber_t,
xfs_btnum_t);
extern struct xfs_btree_cur *xfs_inobt_init_cursor(struct xfs_mount *mp,
struct xfs_trans *tp, struct xfs_buf *agbp, xfs_agnumber_t agno,
struct xfs_perag *pag, xfs_btnum_t btnum);
struct xfs_btree_cur *xfs_inobt_stage_cursor(struct xfs_mount *mp,
struct xbtree_afakeroot *afake, xfs_agnumber_t agno,
xfs_btnum_t btnum);
Expand Down
4 changes: 2 additions & 2 deletions fs/xfs/libxfs/xfs_refcount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ xfs_refcount_finish_one(
if (error)
return error;

rcur = xfs_refcountbt_init_cursor(mp, tp, agbp, agno);
rcur = xfs_refcountbt_init_cursor(mp, tp, agbp, agno, NULL);
rcur->bc_ag.refc.nr_ops = nr_ops;
rcur->bc_ag.refc.shape_changes = shape_changes;
}
Expand Down Expand Up @@ -1707,7 +1707,7 @@ xfs_refcount_recover_cow_leftovers(
error = xfs_alloc_read_agf(mp, tp, agno, 0, &agbp);
if (error)
goto out_trans;
cur = xfs_refcountbt_init_cursor(mp, tp, agbp, agno);
cur = xfs_refcountbt_init_cursor(mp, tp, agbp, agno, NULL);

/* Find all the leftover CoW staging extents. */
memset(&low, 0, sizeof(low));
Expand Down
Loading

0 comments on commit be9fb17

Please sign in to comment.