Commit 14dd46cf authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong

xfs: split xfs_inobt_init_cursor

Split xfs_inobt_init_cursor into separate routines for the inobt and
finobt to prepare for the removal of the xfs_btnum global enumeration
of btree types.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
parent 8541a7d9
...@@ -213,7 +213,10 @@ xfs_inobt_insert( ...@@ -213,7 +213,10 @@ xfs_inobt_insert(
int i; int i;
int error; int error;
cur = xfs_inobt_init_cursor(pag, tp, agbp, btnum); if (btnum == XFS_BTNUM_FINO)
cur = xfs_finobt_init_cursor(pag, tp, agbp);
else
cur = xfs_inobt_init_cursor(pag, tp, agbp);
for (thisino = newino; for (thisino = newino;
thisino < newino + newlen; thisino < newino + newlen;
...@@ -554,7 +557,7 @@ xfs_inobt_insert_sprec( ...@@ -554,7 +557,7 @@ xfs_inobt_insert_sprec(
int i; int i;
struct xfs_inobt_rec_incore rec; struct xfs_inobt_rec_incore rec;
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_INO); cur = xfs_inobt_init_cursor(pag, tp, agbp);
/* the new record is pre-aligned so we know where to look */ /* the new record is pre-aligned so we know where to look */
error = xfs_inobt_lookup(cur, nrec->ir_startino, XFS_LOOKUP_EQ, &i); error = xfs_inobt_lookup(cur, nrec->ir_startino, XFS_LOOKUP_EQ, &i);
...@@ -650,7 +653,7 @@ xfs_finobt_insert_sprec( ...@@ -650,7 +653,7 @@ xfs_finobt_insert_sprec(
int error; int error;
int i; int i;
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_FINO); cur = xfs_finobt_init_cursor(pag, tp, agbp);
/* the new record is pre-aligned so we know where to look */ /* the new record is pre-aligned so we know where to look */
error = xfs_inobt_lookup(cur, nrec->ir_startino, XFS_LOOKUP_EQ, &i); error = xfs_inobt_lookup(cur, nrec->ir_startino, XFS_LOOKUP_EQ, &i);
...@@ -1083,7 +1086,7 @@ xfs_dialloc_ag_inobt( ...@@ -1083,7 +1086,7 @@ xfs_dialloc_ag_inobt(
ASSERT(pag->pagi_freecount > 0); ASSERT(pag->pagi_freecount > 0);
restart_pagno: restart_pagno:
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_INO); cur = xfs_inobt_init_cursor(pag, tp, agbp);
/* /*
* If pagino is 0 (this is the root inode allocation) use newino. * If pagino is 0 (this is the root inode allocation) use newino.
* This must work because we've just allocated some. * This must work because we've just allocated some.
...@@ -1557,7 +1560,7 @@ xfs_dialloc_ag( ...@@ -1557,7 +1560,7 @@ xfs_dialloc_ag(
if (!pagino) if (!pagino)
pagino = be32_to_cpu(agi->agi_newino); pagino = be32_to_cpu(agi->agi_newino);
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_FINO); cur = xfs_finobt_init_cursor(pag, tp, agbp);
error = xfs_check_agi_freecount(cur); error = xfs_check_agi_freecount(cur);
if (error) if (error)
...@@ -1600,7 +1603,7 @@ xfs_dialloc_ag( ...@@ -1600,7 +1603,7 @@ xfs_dialloc_ag(
* the original freecount. If all is well, make the equivalent update to * the original freecount. If all is well, make the equivalent update to
* the inobt using the finobt record and offset information. * the inobt using the finobt record and offset information.
*/ */
icur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_INO); icur = xfs_inobt_init_cursor(pag, tp, agbp);
error = xfs_check_agi_freecount(icur); error = xfs_check_agi_freecount(icur);
if (error) if (error)
...@@ -2017,7 +2020,7 @@ xfs_difree_inobt( ...@@ -2017,7 +2020,7 @@ xfs_difree_inobt(
/* /*
* Initialize the cursor. * Initialize the cursor.
*/ */
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_INO); cur = xfs_inobt_init_cursor(pag, tp, agbp);
error = xfs_check_agi_freecount(cur); error = xfs_check_agi_freecount(cur);
if (error) if (error)
...@@ -2144,7 +2147,7 @@ xfs_difree_finobt( ...@@ -2144,7 +2147,7 @@ xfs_difree_finobt(
int error; int error;
int i; int i;
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_FINO); cur = xfs_finobt_init_cursor(pag, tp, agbp);
error = xfs_inobt_lookup(cur, ibtrec->ir_startino, XFS_LOOKUP_EQ, &i); error = xfs_inobt_lookup(cur, ibtrec->ir_startino, XFS_LOOKUP_EQ, &i);
if (error) if (error)
...@@ -2344,7 +2347,7 @@ xfs_imap_lookup( ...@@ -2344,7 +2347,7 @@ xfs_imap_lookup(
* we have a record, we need to ensure it contains the inode number * we have a record, we need to ensure it contains the inode number
* we are looking up. * we are looking up.
*/ */
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_INO); cur = xfs_inobt_init_cursor(pag, tp, agbp);
error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &i); error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &i);
if (!error) { if (!error) {
if (i) if (i)
...@@ -3063,7 +3066,7 @@ xfs_ialloc_check_shrink( ...@@ -3063,7 +3066,7 @@ xfs_ialloc_check_shrink(
if (!xfs_has_sparseinodes(pag->pag_mount)) if (!xfs_has_sparseinodes(pag->pag_mount))
return 0; return 0;
cur = xfs_inobt_init_cursor(pag, tp, agibp, XFS_BTNUM_INO); cur = xfs_inobt_init_cursor(pag, tp, agibp);
/* Look up the inobt record that would correspond to the new EOFS. */ /* Look up the inobt record that would correspond to the new EOFS. */
agino = XFS_AGB_TO_AGINO(pag->pag_mount, new_length); agino = XFS_AGB_TO_AGINO(pag->pag_mount, new_length);
......
...@@ -38,7 +38,15 @@ xfs_inobt_dup_cursor( ...@@ -38,7 +38,15 @@ xfs_inobt_dup_cursor(
struct xfs_btree_cur *cur) struct xfs_btree_cur *cur)
{ {
return xfs_inobt_init_cursor(cur->bc_ag.pag, cur->bc_tp, return xfs_inobt_init_cursor(cur->bc_ag.pag, cur->bc_tp,
cur->bc_ag.agbp, cur->bc_btnum); cur->bc_ag.agbp);
}
STATIC struct xfs_btree_cur *
xfs_finobt_dup_cursor(
struct xfs_btree_cur *cur)
{
return xfs_finobt_init_cursor(cur->bc_ag.pag, cur->bc_tp,
cur->bc_ag.agbp);
} }
STATIC void STATIC void
...@@ -441,7 +449,7 @@ const struct xfs_btree_ops xfs_finobt_ops = { ...@@ -441,7 +449,7 @@ const struct xfs_btree_ops xfs_finobt_ops = {
.statoff = XFS_STATS_CALC_INDEX(xs_fibt_2), .statoff = XFS_STATS_CALC_INDEX(xs_fibt_2),
.sick_mask = XFS_SICK_AG_FINOBT, .sick_mask = XFS_SICK_AG_FINOBT,
.dup_cursor = xfs_inobt_dup_cursor, .dup_cursor = xfs_finobt_dup_cursor,
.set_root = xfs_finobt_set_root, .set_root = xfs_finobt_set_root,
.alloc_block = xfs_finobt_alloc_block, .alloc_block = xfs_finobt_alloc_block,
.free_block = xfs_finobt_free_block, .free_block = xfs_finobt_free_block,
...@@ -468,28 +476,45 @@ struct xfs_btree_cur * ...@@ -468,28 +476,45 @@ struct xfs_btree_cur *
xfs_inobt_init_cursor( xfs_inobt_init_cursor(
struct xfs_perag *pag, struct xfs_perag *pag,
struct xfs_trans *tp, struct xfs_trans *tp,
struct xfs_buf *agbp, struct xfs_buf *agbp)
xfs_btnum_t btnum) /* ialloc or free ino btree */
{ {
struct xfs_mount *mp = pag->pag_mount; struct xfs_mount *mp = pag->pag_mount;
const struct xfs_btree_ops *ops = &xfs_inobt_ops;
struct xfs_btree_cur *cur; struct xfs_btree_cur *cur;
ASSERT(btnum == XFS_BTNUM_INO || btnum == XFS_BTNUM_FINO); cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_INO, &xfs_inobt_ops,
M_IGEO(mp)->inobt_maxlevels, xfs_inobt_cur_cache);
cur->bc_ag.pag = xfs_perag_hold(pag);
cur->bc_ag.agbp = agbp;
if (agbp) {
struct xfs_agi *agi = agbp->b_addr;
if (btnum == XFS_BTNUM_FINO) cur->bc_nlevels = be32_to_cpu(agi->agi_level);
ops = &xfs_finobt_ops; }
return cur;
}
/*
* Create a free inode btree cursor.
*
* For staging cursors tp and agbp are NULL.
*/
struct xfs_btree_cur *
xfs_finobt_init_cursor(
struct xfs_perag *pag,
struct xfs_trans *tp,
struct xfs_buf *agbp)
{
struct xfs_mount *mp = pag->pag_mount;
struct xfs_btree_cur *cur;
cur = xfs_btree_alloc_cursor(mp, tp, btnum, ops, cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_FINO, &xfs_finobt_ops,
M_IGEO(mp)->inobt_maxlevels, xfs_inobt_cur_cache); M_IGEO(mp)->inobt_maxlevels, xfs_inobt_cur_cache);
cur->bc_ag.pag = xfs_perag_hold(pag); cur->bc_ag.pag = xfs_perag_hold(pag);
cur->bc_ag.agbp = agbp; cur->bc_ag.agbp = agbp;
if (agbp) { if (agbp) {
struct xfs_agi *agi = agbp->b_addr; struct xfs_agi *agi = agbp->b_addr;
cur->bc_nlevels = (btnum == XFS_BTNUM_INO) ? cur->bc_nlevels = be32_to_cpu(agi->agi_free_level);
be32_to_cpu(agi->agi_level) :
be32_to_cpu(agi->agi_free_level);
} }
return cur; return cur;
} }
...@@ -724,7 +749,7 @@ xfs_finobt_count_blocks( ...@@ -724,7 +749,7 @@ xfs_finobt_count_blocks(
if (error) if (error)
return error; return error;
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_FINO); cur = xfs_inobt_init_cursor(pag, tp, agbp);
error = xfs_btree_count_blocks(cur, tree_blocks); error = xfs_btree_count_blocks(cur, tree_blocks);
xfs_btree_del_cursor(cur, error); xfs_btree_del_cursor(cur, error);
xfs_trans_brelse(tp, agbp); xfs_trans_brelse(tp, agbp);
......
...@@ -46,8 +46,10 @@ struct xfs_perag; ...@@ -46,8 +46,10 @@ struct xfs_perag;
(maxrecs) * sizeof(xfs_inobt_key_t) + \ (maxrecs) * sizeof(xfs_inobt_key_t) + \
((index) - 1) * sizeof(xfs_inobt_ptr_t))) ((index) - 1) * sizeof(xfs_inobt_ptr_t)))
extern struct xfs_btree_cur *xfs_inobt_init_cursor(struct xfs_perag *pag, struct xfs_btree_cur *xfs_inobt_init_cursor(struct xfs_perag *pag,
struct xfs_trans *tp, struct xfs_buf *agbp, xfs_btnum_t btnum); struct xfs_trans *tp, struct xfs_buf *agbp);
struct xfs_btree_cur *xfs_finobt_init_cursor(struct xfs_perag *pag,
struct xfs_trans *tp, struct xfs_buf *agbp);
extern int xfs_inobt_maxrecs(struct xfs_mount *, int, int); extern int xfs_inobt_maxrecs(struct xfs_mount *, int, int);
/* ir_holemask to inode allocation bitmap conversion */ /* ir_holemask to inode allocation bitmap conversion */
......
...@@ -894,7 +894,7 @@ xrep_agi_calc_from_btrees( ...@@ -894,7 +894,7 @@ xrep_agi_calc_from_btrees(
xfs_agino_t freecount; xfs_agino_t freecount;
int error; int error;
cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp, agi_bp, XFS_BTNUM_INO); cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp, agi_bp);
error = xfs_ialloc_count_inodes(cur, &count, &freecount); error = xfs_ialloc_count_inodes(cur, &count, &freecount);
if (error) if (error)
goto err; goto err;
...@@ -914,8 +914,7 @@ xrep_agi_calc_from_btrees( ...@@ -914,8 +914,7 @@ xrep_agi_calc_from_btrees(
if (xfs_has_finobt(mp) && xfs_has_inobtcounts(mp)) { if (xfs_has_finobt(mp) && xfs_has_inobtcounts(mp)) {
xfs_agblock_t blocks; xfs_agblock_t blocks;
cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp, agi_bp, cur = xfs_finobt_init_cursor(sc->sa.pag, sc->tp, agi_bp);
XFS_BTNUM_FINO);
error = xfs_btree_count_blocks(cur, &blocks); error = xfs_btree_count_blocks(cur, &blocks);
if (error) if (error)
goto err; goto err;
......
...@@ -620,15 +620,15 @@ xchk_ag_btcur_init( ...@@ -620,15 +620,15 @@ xchk_ag_btcur_init(
if (sa->agi_bp) { if (sa->agi_bp) {
/* Set up a inobt cursor for cross-referencing. */ /* Set up a inobt cursor for cross-referencing. */
sa->ino_cur = xfs_inobt_init_cursor(sa->pag, sc->tp, sa->agi_bp, sa->ino_cur = xfs_inobt_init_cursor(sa->pag, sc->tp,
XFS_BTNUM_INO); sa->agi_bp);
xchk_ag_btree_del_cursor_if_sick(sc, &sa->ino_cur, xchk_ag_btree_del_cursor_if_sick(sc, &sa->ino_cur,
XFS_SCRUB_TYPE_INOBT); XFS_SCRUB_TYPE_INOBT);
/* Set up a finobt cursor for cross-referencing. */ /* Set up a finobt cursor for cross-referencing. */
if (xfs_has_finobt(mp)) { if (xfs_has_finobt(mp)) {
sa->fino_cur = xfs_inobt_init_cursor(sa->pag, sc->tp, sa->fino_cur = xfs_finobt_init_cursor(sa->pag, sc->tp,
sa->agi_bp, XFS_BTNUM_FINO); sa->agi_bp);
xchk_ag_btree_del_cursor_if_sick(sc, &sa->fino_cur, xchk_ag_btree_del_cursor_if_sick(sc, &sa->fino_cur,
XFS_SCRUB_TYPE_FINOBT); XFS_SCRUB_TYPE_FINOBT);
} }
......
...@@ -663,7 +663,7 @@ xrep_ibt_build_new_trees( ...@@ -663,7 +663,7 @@ xrep_ibt_build_new_trees(
ri->new_inobt.bload.claim_block = xrep_ibt_claim_block; ri->new_inobt.bload.claim_block = xrep_ibt_claim_block;
ri->new_inobt.bload.get_records = xrep_ibt_get_records; ri->new_inobt.bload.get_records = xrep_ibt_get_records;
ino_cur = xfs_inobt_init_cursor(sc->sa.pag, NULL, NULL, XFS_BTNUM_INO); ino_cur = xfs_inobt_init_cursor(sc->sa.pag, NULL, NULL);
xfs_btree_stage_afakeroot(ino_cur, &ri->new_inobt.afake); xfs_btree_stage_afakeroot(ino_cur, &ri->new_inobt.afake);
error = xfs_btree_bload_compute_geometry(ino_cur, &ri->new_inobt.bload, error = xfs_btree_bload_compute_geometry(ino_cur, &ri->new_inobt.bload,
xfarray_length(ri->inode_records)); xfarray_length(ri->inode_records));
...@@ -684,8 +684,7 @@ xrep_ibt_build_new_trees( ...@@ -684,8 +684,7 @@ xrep_ibt_build_new_trees(
ri->new_finobt.bload.claim_block = xrep_fibt_claim_block; ri->new_finobt.bload.claim_block = xrep_fibt_claim_block;
ri->new_finobt.bload.get_records = xrep_fibt_get_records; ri->new_finobt.bload.get_records = xrep_fibt_get_records;
fino_cur = xfs_inobt_init_cursor(sc->sa.pag, NULL, NULL, fino_cur = xfs_finobt_init_cursor(sc->sa.pag, NULL, NULL);
XFS_BTNUM_FINO);
xfs_btree_stage_afakeroot(fino_cur, &ri->new_finobt.afake); xfs_btree_stage_afakeroot(fino_cur, &ri->new_finobt.afake);
error = xfs_btree_bload_compute_geometry(fino_cur, error = xfs_btree_bload_compute_geometry(fino_cur,
&ri->new_finobt.bload, ri->finobt_recs); &ri->new_finobt.bload, ri->finobt_recs);
......
...@@ -113,7 +113,7 @@ xchk_iscan_find_next( ...@@ -113,7 +113,7 @@ xchk_iscan_find_next(
* Look up the inode chunk for the current cursor position. If there * Look up the inode chunk for the current cursor position. If there
* is no chunk here, we want the next one. * is no chunk here, we want the next one.
*/ */
cur = xfs_inobt_init_cursor(pag, tp, agi_bp, XFS_BTNUM_INO); cur = xfs_inobt_init_cursor(pag, tp, agi_bp);
error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &has_rec); error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &has_rec);
if (!error && !has_rec) if (!error && !has_rec)
error = xfs_btree_increment(cur, 0, &has_rec); error = xfs_btree_increment(cur, 0, &has_rec);
......
...@@ -842,10 +842,10 @@ xrep_ag_btcur_init( ...@@ -842,10 +842,10 @@ xrep_ag_btcur_init(
if (sc->sm->sm_type != XFS_SCRUB_TYPE_INOBT && if (sc->sm->sm_type != XFS_SCRUB_TYPE_INOBT &&
sc->sm->sm_type != XFS_SCRUB_TYPE_FINOBT) { sc->sm->sm_type != XFS_SCRUB_TYPE_FINOBT) {
sa->ino_cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp, sa->ino_cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp,
sa->agi_bp, XFS_BTNUM_INO); sa->agi_bp);
if (xfs_has_finobt(mp)) if (xfs_has_finobt(mp))
sa->fino_cur = xfs_inobt_init_cursor(sc->sa.pag, sa->fino_cur = xfs_finobt_init_cursor(sc->sa.pag,
sc->tp, sa->agi_bp, XFS_BTNUM_FINO); sc->tp, sa->agi_bp);
} }
/* Set up a rmapbt cursor for cross-referencing. */ /* Set up a rmapbt cursor for cross-referencing. */
......
...@@ -447,8 +447,7 @@ xchk_rmapbt_walk_ag_metadata( ...@@ -447,8 +447,7 @@ xchk_rmapbt_walk_ag_metadata(
/* OWN_INOBT: inobt, finobt */ /* OWN_INOBT: inobt, finobt */
cur = sc->sa.ino_cur; cur = sc->sa.ino_cur;
if (!cur) if (!cur)
cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp, sc->sa.agi_bp, cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp, sc->sa.agi_bp);
XFS_BTNUM_INO);
error = xagb_bitmap_set_btblocks(&cr->inobt_owned, cur); error = xagb_bitmap_set_btblocks(&cr->inobt_owned, cur);
if (cur != sc->sa.ino_cur) if (cur != sc->sa.ino_cur)
xfs_btree_del_cursor(cur, error); xfs_btree_del_cursor(cur, error);
...@@ -458,8 +457,8 @@ xchk_rmapbt_walk_ag_metadata( ...@@ -458,8 +457,8 @@ xchk_rmapbt_walk_ag_metadata(
if (xfs_has_finobt(sc->mp)) { if (xfs_has_finobt(sc->mp)) {
cur = sc->sa.fino_cur; cur = sc->sa.fino_cur;
if (!cur) if (!cur)
cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp, cur = xfs_finobt_init_cursor(sc->sa.pag, sc->tp,
sc->sa.agi_bp, XFS_BTNUM_FINO); sc->sa.agi_bp);
error = xagb_bitmap_set_btblocks(&cr->inobt_owned, cur); error = xagb_bitmap_set_btblocks(&cr->inobt_owned, cur);
if (cur != sc->sa.fino_cur) if (cur != sc->sa.fino_cur)
xfs_btree_del_cursor(cur, error); xfs_btree_del_cursor(cur, error);
......
...@@ -269,7 +269,7 @@ xfs_iwalk_ag_start( ...@@ -269,7 +269,7 @@ xfs_iwalk_ag_start(
error = xfs_ialloc_read_agi(pag, tp, agi_bpp); error = xfs_ialloc_read_agi(pag, tp, agi_bpp);
if (error) if (error)
return error; return error;
*curpp = xfs_inobt_init_cursor(pag, tp, *agi_bpp, XFS_BTNUM_INO); *curpp = xfs_inobt_init_cursor(pag, tp, *agi_bpp);
/* Starting at the beginning of the AG? That's easy! */ /* Starting at the beginning of the AG? That's easy! */
if (agino == 0) if (agino == 0)
...@@ -387,8 +387,7 @@ xfs_iwalk_run_callbacks( ...@@ -387,8 +387,7 @@ xfs_iwalk_run_callbacks(
error = xfs_ialloc_read_agi(iwag->pag, iwag->tp, agi_bpp); error = xfs_ialloc_read_agi(iwag->pag, iwag->tp, agi_bpp);
if (error) if (error)
return error; return error;
*curpp = xfs_inobt_init_cursor(iwag->pag, iwag->tp, *agi_bpp, *curpp = xfs_inobt_init_cursor(iwag->pag, iwag->tp, *agi_bpp);
XFS_BTNUM_INO);
return xfs_inobt_lookup(*curpp, next_agino, XFS_LOOKUP_GE, has_more); return xfs_inobt_lookup(*curpp, next_agino, XFS_LOOKUP_GE, has_more);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment