Skip to content

Commit 14dd46c

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
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: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
1 parent 8541a7d commit 14dd46c

10 files changed

Lines changed: 72 additions & 46 deletions

File tree

fs/xfs/libxfs/xfs_ialloc.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ xfs_inobt_insert(
213213
int i;
214214
int error;
215215

216-
cur = xfs_inobt_init_cursor(pag, tp, agbp, btnum);
216+
if (btnum == XFS_BTNUM_FINO)
217+
cur = xfs_finobt_init_cursor(pag, tp, agbp);
218+
else
219+
cur = xfs_inobt_init_cursor(pag, tp, agbp);
217220

218221
for (thisino = newino;
219222
thisino < newino + newlen;
@@ -554,7 +557,7 @@ xfs_inobt_insert_sprec(
554557
int i;
555558
struct xfs_inobt_rec_incore rec;
556559

557-
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_INO);
560+
cur = xfs_inobt_init_cursor(pag, tp, agbp);
558561

559562
/* the new record is pre-aligned so we know where to look */
560563
error = xfs_inobt_lookup(cur, nrec->ir_startino, XFS_LOOKUP_EQ, &i);
@@ -650,7 +653,7 @@ xfs_finobt_insert_sprec(
650653
int error;
651654
int i;
652655

653-
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_FINO);
656+
cur = xfs_finobt_init_cursor(pag, tp, agbp);
654657

655658
/* the new record is pre-aligned so we know where to look */
656659
error = xfs_inobt_lookup(cur, nrec->ir_startino, XFS_LOOKUP_EQ, &i);
@@ -1083,7 +1086,7 @@ xfs_dialloc_ag_inobt(
10831086
ASSERT(pag->pagi_freecount > 0);
10841087

10851088
restart_pagno:
1086-
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_INO);
1089+
cur = xfs_inobt_init_cursor(pag, tp, agbp);
10871090
/*
10881091
* If pagino is 0 (this is the root inode allocation) use newino.
10891092
* This must work because we've just allocated some.
@@ -1557,7 +1560,7 @@ xfs_dialloc_ag(
15571560
if (!pagino)
15581561
pagino = be32_to_cpu(agi->agi_newino);
15591562

1560-
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_FINO);
1563+
cur = xfs_finobt_init_cursor(pag, tp, agbp);
15611564

15621565
error = xfs_check_agi_freecount(cur);
15631566
if (error)
@@ -1600,7 +1603,7 @@ xfs_dialloc_ag(
16001603
* the original freecount. If all is well, make the equivalent update to
16011604
* the inobt using the finobt record and offset information.
16021605
*/
1603-
icur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_INO);
1606+
icur = xfs_inobt_init_cursor(pag, tp, agbp);
16041607

16051608
error = xfs_check_agi_freecount(icur);
16061609
if (error)
@@ -2017,7 +2020,7 @@ xfs_difree_inobt(
20172020
/*
20182021
* Initialize the cursor.
20192022
*/
2020-
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_INO);
2023+
cur = xfs_inobt_init_cursor(pag, tp, agbp);
20212024

20222025
error = xfs_check_agi_freecount(cur);
20232026
if (error)
@@ -2144,7 +2147,7 @@ xfs_difree_finobt(
21442147
int error;
21452148
int i;
21462149

2147-
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_FINO);
2150+
cur = xfs_finobt_init_cursor(pag, tp, agbp);
21482151

21492152
error = xfs_inobt_lookup(cur, ibtrec->ir_startino, XFS_LOOKUP_EQ, &i);
21502153
if (error)
@@ -2344,7 +2347,7 @@ xfs_imap_lookup(
23442347
* we have a record, we need to ensure it contains the inode number
23452348
* we are looking up.
23462349
*/
2347-
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_INO);
2350+
cur = xfs_inobt_init_cursor(pag, tp, agbp);
23482351
error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &i);
23492352
if (!error) {
23502353
if (i)
@@ -3063,7 +3066,7 @@ xfs_ialloc_check_shrink(
30633066
if (!xfs_has_sparseinodes(pag->pag_mount))
30643067
return 0;
30653068

3066-
cur = xfs_inobt_init_cursor(pag, tp, agibp, XFS_BTNUM_INO);
3069+
cur = xfs_inobt_init_cursor(pag, tp, agibp);
30673070

30683071
/* Look up the inobt record that would correspond to the new EOFS. */
30693072
agino = XFS_AGB_TO_AGINO(pag->pag_mount, new_length);

fs/xfs/libxfs/xfs_ialloc_btree.c

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ xfs_inobt_dup_cursor(
3838
struct xfs_btree_cur *cur)
3939
{
4040
return xfs_inobt_init_cursor(cur->bc_ag.pag, cur->bc_tp,
41-
cur->bc_ag.agbp, cur->bc_btnum);
41+
cur->bc_ag.agbp);
42+
}
43+
44+
STATIC struct xfs_btree_cur *
45+
xfs_finobt_dup_cursor(
46+
struct xfs_btree_cur *cur)
47+
{
48+
return xfs_finobt_init_cursor(cur->bc_ag.pag, cur->bc_tp,
49+
cur->bc_ag.agbp);
4250
}
4351

4452
STATIC void
@@ -441,7 +449,7 @@ const struct xfs_btree_ops xfs_finobt_ops = {
441449
.statoff = XFS_STATS_CALC_INDEX(xs_fibt_2),
442450
.sick_mask = XFS_SICK_AG_FINOBT,
443451

444-
.dup_cursor = xfs_inobt_dup_cursor,
452+
.dup_cursor = xfs_finobt_dup_cursor,
445453
.set_root = xfs_finobt_set_root,
446454
.alloc_block = xfs_finobt_alloc_block,
447455
.free_block = xfs_finobt_free_block,
@@ -468,28 +476,45 @@ struct xfs_btree_cur *
468476
xfs_inobt_init_cursor(
469477
struct xfs_perag *pag,
470478
struct xfs_trans *tp,
471-
struct xfs_buf *agbp,
472-
xfs_btnum_t btnum) /* ialloc or free ino btree */
479+
struct xfs_buf *agbp)
473480
{
474481
struct xfs_mount *mp = pag->pag_mount;
475-
const struct xfs_btree_ops *ops = &xfs_inobt_ops;
476482
struct xfs_btree_cur *cur;
477483

478-
ASSERT(btnum == XFS_BTNUM_INO || btnum == XFS_BTNUM_FINO);
484+
cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_INO, &xfs_inobt_ops,
485+
M_IGEO(mp)->inobt_maxlevels, xfs_inobt_cur_cache);
486+
cur->bc_ag.pag = xfs_perag_hold(pag);
487+
cur->bc_ag.agbp = agbp;
488+
if (agbp) {
489+
struct xfs_agi *agi = agbp->b_addr;
479490

480-
if (btnum == XFS_BTNUM_FINO)
481-
ops = &xfs_finobt_ops;
491+
cur->bc_nlevels = be32_to_cpu(agi->agi_level);
492+
}
493+
return cur;
494+
}
495+
496+
/*
497+
* Create a free inode btree cursor.
498+
*
499+
* For staging cursors tp and agbp are NULL.
500+
*/
501+
struct xfs_btree_cur *
502+
xfs_finobt_init_cursor(
503+
struct xfs_perag *pag,
504+
struct xfs_trans *tp,
505+
struct xfs_buf *agbp)
506+
{
507+
struct xfs_mount *mp = pag->pag_mount;
508+
struct xfs_btree_cur *cur;
482509

483-
cur = xfs_btree_alloc_cursor(mp, tp, btnum, ops,
510+
cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_FINO, &xfs_finobt_ops,
484511
M_IGEO(mp)->inobt_maxlevels, xfs_inobt_cur_cache);
485512
cur->bc_ag.pag = xfs_perag_hold(pag);
486513
cur->bc_ag.agbp = agbp;
487514
if (agbp) {
488515
struct xfs_agi *agi = agbp->b_addr;
489516

490-
cur->bc_nlevels = (btnum == XFS_BTNUM_INO) ?
491-
be32_to_cpu(agi->agi_level) :
492-
be32_to_cpu(agi->agi_free_level);
517+
cur->bc_nlevels = be32_to_cpu(agi->agi_free_level);
493518
}
494519
return cur;
495520
}
@@ -724,7 +749,7 @@ xfs_finobt_count_blocks(
724749
if (error)
725750
return error;
726751

727-
cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_FINO);
752+
cur = xfs_inobt_init_cursor(pag, tp, agbp);
728753
error = xfs_btree_count_blocks(cur, tree_blocks);
729754
xfs_btree_del_cursor(cur, error);
730755
xfs_trans_brelse(tp, agbp);

fs/xfs/libxfs/xfs_ialloc_btree.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ struct xfs_perag;
4646
(maxrecs) * sizeof(xfs_inobt_key_t) + \
4747
((index) - 1) * sizeof(xfs_inobt_ptr_t)))
4848

49-
extern struct xfs_btree_cur *xfs_inobt_init_cursor(struct xfs_perag *pag,
50-
struct xfs_trans *tp, struct xfs_buf *agbp, xfs_btnum_t btnum);
49+
struct xfs_btree_cur *xfs_inobt_init_cursor(struct xfs_perag *pag,
50+
struct xfs_trans *tp, struct xfs_buf *agbp);
51+
struct xfs_btree_cur *xfs_finobt_init_cursor(struct xfs_perag *pag,
52+
struct xfs_trans *tp, struct xfs_buf *agbp);
5153
extern int xfs_inobt_maxrecs(struct xfs_mount *, int, int);
5254

5355
/* ir_holemask to inode allocation bitmap conversion */

fs/xfs/scrub/agheader_repair.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ xrep_agi_calc_from_btrees(
894894
xfs_agino_t freecount;
895895
int error;
896896

897-
cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp, agi_bp, XFS_BTNUM_INO);
897+
cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp, agi_bp);
898898
error = xfs_ialloc_count_inodes(cur, &count, &freecount);
899899
if (error)
900900
goto err;
@@ -914,8 +914,7 @@ xrep_agi_calc_from_btrees(
914914
if (xfs_has_finobt(mp) && xfs_has_inobtcounts(mp)) {
915915
xfs_agblock_t blocks;
916916

917-
cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp, agi_bp,
918-
XFS_BTNUM_FINO);
917+
cur = xfs_finobt_init_cursor(sc->sa.pag, sc->tp, agi_bp);
919918
error = xfs_btree_count_blocks(cur, &blocks);
920919
if (error)
921920
goto err;

fs/xfs/scrub/common.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,15 +620,15 @@ xchk_ag_btcur_init(
620620

621621
if (sa->agi_bp) {
622622
/* Set up a inobt cursor for cross-referencing. */
623-
sa->ino_cur = xfs_inobt_init_cursor(sa->pag, sc->tp, sa->agi_bp,
624-
XFS_BTNUM_INO);
623+
sa->ino_cur = xfs_inobt_init_cursor(sa->pag, sc->tp,
624+
sa->agi_bp);
625625
xchk_ag_btree_del_cursor_if_sick(sc, &sa->ino_cur,
626626
XFS_SCRUB_TYPE_INOBT);
627627

628628
/* Set up a finobt cursor for cross-referencing. */
629629
if (xfs_has_finobt(mp)) {
630-
sa->fino_cur = xfs_inobt_init_cursor(sa->pag, sc->tp,
631-
sa->agi_bp, XFS_BTNUM_FINO);
630+
sa->fino_cur = xfs_finobt_init_cursor(sa->pag, sc->tp,
631+
sa->agi_bp);
632632
xchk_ag_btree_del_cursor_if_sick(sc, &sa->fino_cur,
633633
XFS_SCRUB_TYPE_FINOBT);
634634
}

fs/xfs/scrub/ialloc_repair.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ xrep_ibt_build_new_trees(
663663
ri->new_inobt.bload.claim_block = xrep_ibt_claim_block;
664664
ri->new_inobt.bload.get_records = xrep_ibt_get_records;
665665

666-
ino_cur = xfs_inobt_init_cursor(sc->sa.pag, NULL, NULL, XFS_BTNUM_INO);
666+
ino_cur = xfs_inobt_init_cursor(sc->sa.pag, NULL, NULL);
667667
xfs_btree_stage_afakeroot(ino_cur, &ri->new_inobt.afake);
668668
error = xfs_btree_bload_compute_geometry(ino_cur, &ri->new_inobt.bload,
669669
xfarray_length(ri->inode_records));
@@ -684,8 +684,7 @@ xrep_ibt_build_new_trees(
684684
ri->new_finobt.bload.claim_block = xrep_fibt_claim_block;
685685
ri->new_finobt.bload.get_records = xrep_fibt_get_records;
686686

687-
fino_cur = xfs_inobt_init_cursor(sc->sa.pag, NULL, NULL,
688-
XFS_BTNUM_FINO);
687+
fino_cur = xfs_finobt_init_cursor(sc->sa.pag, NULL, NULL);
689688
xfs_btree_stage_afakeroot(fino_cur, &ri->new_finobt.afake);
690689
error = xfs_btree_bload_compute_geometry(fino_cur,
691690
&ri->new_finobt.bload, ri->finobt_recs);

fs/xfs/scrub/iscan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ xchk_iscan_find_next(
113113
* Look up the inode chunk for the current cursor position. If there
114114
* is no chunk here, we want the next one.
115115
*/
116-
cur = xfs_inobt_init_cursor(pag, tp, agi_bp, XFS_BTNUM_INO);
116+
cur = xfs_inobt_init_cursor(pag, tp, agi_bp);
117117
error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &has_rec);
118118
if (!error && !has_rec)
119119
error = xfs_btree_increment(cur, 0, &has_rec);

fs/xfs/scrub/repair.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -842,10 +842,10 @@ xrep_ag_btcur_init(
842842
if (sc->sm->sm_type != XFS_SCRUB_TYPE_INOBT &&
843843
sc->sm->sm_type != XFS_SCRUB_TYPE_FINOBT) {
844844
sa->ino_cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp,
845-
sa->agi_bp, XFS_BTNUM_INO);
845+
sa->agi_bp);
846846
if (xfs_has_finobt(mp))
847-
sa->fino_cur = xfs_inobt_init_cursor(sc->sa.pag,
848-
sc->tp, sa->agi_bp, XFS_BTNUM_FINO);
847+
sa->fino_cur = xfs_finobt_init_cursor(sc->sa.pag,
848+
sc->tp, sa->agi_bp);
849849
}
850850

851851
/* Set up a rmapbt cursor for cross-referencing. */

fs/xfs/scrub/rmap.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,7 @@ xchk_rmapbt_walk_ag_metadata(
447447
/* OWN_INOBT: inobt, finobt */
448448
cur = sc->sa.ino_cur;
449449
if (!cur)
450-
cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp, sc->sa.agi_bp,
451-
XFS_BTNUM_INO);
450+
cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp, sc->sa.agi_bp);
452451
error = xagb_bitmap_set_btblocks(&cr->inobt_owned, cur);
453452
if (cur != sc->sa.ino_cur)
454453
xfs_btree_del_cursor(cur, error);
@@ -458,8 +457,8 @@ xchk_rmapbt_walk_ag_metadata(
458457
if (xfs_has_finobt(sc->mp)) {
459458
cur = sc->sa.fino_cur;
460459
if (!cur)
461-
cur = xfs_inobt_init_cursor(sc->sa.pag, sc->tp,
462-
sc->sa.agi_bp, XFS_BTNUM_FINO);
460+
cur = xfs_finobt_init_cursor(sc->sa.pag, sc->tp,
461+
sc->sa.agi_bp);
463462
error = xagb_bitmap_set_btblocks(&cr->inobt_owned, cur);
464463
if (cur != sc->sa.fino_cur)
465464
xfs_btree_del_cursor(cur, error);

fs/xfs/xfs_iwalk.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ xfs_iwalk_ag_start(
269269
error = xfs_ialloc_read_agi(pag, tp, agi_bpp);
270270
if (error)
271271
return error;
272-
*curpp = xfs_inobt_init_cursor(pag, tp, *agi_bpp, XFS_BTNUM_INO);
272+
*curpp = xfs_inobt_init_cursor(pag, tp, *agi_bpp);
273273

274274
/* Starting at the beginning of the AG? That's easy! */
275275
if (agino == 0)
@@ -387,8 +387,7 @@ xfs_iwalk_run_callbacks(
387387
error = xfs_ialloc_read_agi(iwag->pag, iwag->tp, agi_bpp);
388388
if (error)
389389
return error;
390-
*curpp = xfs_inobt_init_cursor(iwag->pag, iwag->tp, *agi_bpp,
391-
XFS_BTNUM_INO);
390+
*curpp = xfs_inobt_init_cursor(iwag->pag, iwag->tp, *agi_bpp);
392391
return xfs_inobt_lookup(*curpp, next_agino, XFS_LOOKUP_GE, has_more);
393392
}
394393

0 commit comments

Comments
 (0)