Skip to content

Commit ee13821

Browse files
author
Chandan Babu R
committed
Merge tag 'btree-remove-btnum-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC
xfs: remove bc_btnum from btree cursors From Christoph Hellwig, This series continues the migration of btree geometry information out of the cursor structure and into the ops structure. This time around, we replace the btree type enumeration (btnum) with an explicit name string in the btree ops structure. This enables easy creation of /any/ new btree type without having to mess with libxfs. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org> * tag 'btree-remove-btnum-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux: xfs: remove xfs_btnum_t xfs: pass a 'bool is_finobt' to xfs_inobt_insert xfs: split xfs_inobt_init_cursor xfs: split xfs_inobt_insert_sprec xfs: remove the which variable in xchk_iallocbt xfs: remove the btnum argument to xfs_inobt_count_blocks xfs: remove xfs_inobt_cur xfs: split xfs_allocbt_init_cursor xfs: refactor the btree cursor allocation logic in xchk_ag_btcur_init xfs: add a sick_mask to struct xfs_btree_ops xfs: add a name field to struct xfs_btree_ops xfs: split the agf_roots and agf_levels arrays xfs: remove xfs_bmbt_stage_cursor xfs: fold xfs_bmbt_init_common into xfs_bmbt_init_cursor xfs: make staging file forks explicit xfs: make full use of xfs_btree_stage_ifakeroot in xfs_bmbt_stage_cursor xfs: remove xfs_rmapbt_stage_cursor xfs: fold xfs_rmapbt_init_common into xfs_rmapbt_init_cursor xfs: remove xfs_refcountbt_stage_cursor xfs: fold xfs_refcountbt_init_common into xfs_refcountbt_init_cursor xfs: remove xfs_inobt_stage_cursor xfs: fold xfs_inobt_init_common into xfs_inobt_init_cursor xfs: remove xfs_allocbt_stage_cursor xfs: fold xfs_allocbt_init_common into xfs_allocbt_init_cursor xfs: don't override bc_ops for staging btrees xfs: add a xfs_btree_init_ptr_from_cur xfs: move comment about two 2 keys per pointer in the rmap btree
2 parents 681cb87 + ec793e6 commit ee13821

41 files changed

Lines changed: 739 additions & 895 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

fs/xfs/libxfs/xfs_ag.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -669,14 +669,13 @@ xfs_agfblock_init(
669669
agf->agf_versionnum = cpu_to_be32(XFS_AGF_VERSION);
670670
agf->agf_seqno = cpu_to_be32(id->agno);
671671
agf->agf_length = cpu_to_be32(id->agsize);
672-
agf->agf_roots[XFS_BTNUM_BNOi] = cpu_to_be32(XFS_BNO_BLOCK(mp));
673-
agf->agf_roots[XFS_BTNUM_CNTi] = cpu_to_be32(XFS_CNT_BLOCK(mp));
674-
agf->agf_levels[XFS_BTNUM_BNOi] = cpu_to_be32(1);
675-
agf->agf_levels[XFS_BTNUM_CNTi] = cpu_to_be32(1);
672+
agf->agf_bno_root = cpu_to_be32(XFS_BNO_BLOCK(mp));
673+
agf->agf_cnt_root = cpu_to_be32(XFS_CNT_BLOCK(mp));
674+
agf->agf_bno_level = cpu_to_be32(1);
675+
agf->agf_cnt_level = cpu_to_be32(1);
676676
if (xfs_has_rmapbt(mp)) {
677-
agf->agf_roots[XFS_BTNUM_RMAPi] =
678-
cpu_to_be32(XFS_RMAP_BLOCK(mp));
679-
agf->agf_levels[XFS_BTNUM_RMAPi] = cpu_to_be32(1);
677+
agf->agf_rmap_root = cpu_to_be32(XFS_RMAP_BLOCK(mp));
678+
agf->agf_rmap_level = cpu_to_be32(1);
680679
agf->agf_rmap_blocks = cpu_to_be32(1);
681680
}
682681

fs/xfs/libxfs/xfs_ag.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ struct xfs_perag {
3636
atomic_t pag_active_ref; /* active reference count */
3737
wait_queue_head_t pag_active_wq;/* woken active_ref falls to zero */
3838
unsigned long pag_opstate;
39-
uint8_t pagf_levels[XFS_BTNUM_AGF];
40-
/* # of levels in bno & cnt btree */
39+
uint8_t pagf_bno_level; /* # of levels in bno btree */
40+
uint8_t pagf_cnt_level; /* # of levels in cnt btree */
41+
uint8_t pagf_rmap_level;/* # of levels in rmap btree */
4142
uint32_t pagf_flcount; /* count of blocks in freelist */
4243
xfs_extlen_t pagf_freeblks; /* total free blocks */
4344
xfs_extlen_t pagf_longest; /* longest free space */
@@ -86,7 +87,8 @@ struct xfs_perag {
8687
* Alternate btree heights so that online repair won't trip the write
8788
* verifiers while rebuilding the AG btrees.
8889
*/
89-
uint8_t pagf_repair_levels[XFS_BTNUM_AGF];
90+
uint8_t pagf_repair_bno_level;
91+
uint8_t pagf_repair_cnt_level;
9092
uint8_t pagf_repair_refcount_level;
9193
#endif
9294

fs/xfs/libxfs/xfs_alloc.c

Lines changed: 43 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,8 @@ xfs_alloc_complain_bad_rec(
273273
struct xfs_mount *mp = cur->bc_mp;
274274

275275
xfs_warn(mp,
276-
"%s Freespace BTree record corruption in AG %d detected at %pS!",
277-
cur->bc_btnum == XFS_BTNUM_BNO ? "Block" : "Size",
278-
cur->bc_ag.pag->pag_agno, fa);
276+
"%sbt record corruption in AG %d detected at %pS!",
277+
cur->bc_ops->name, cur->bc_ag.pag->pag_agno, fa);
279278
xfs_warn(mp,
280279
"start block 0x%x block count 0x%x", irec->ar_startblock,
281280
irec->ar_blockcount);
@@ -863,8 +862,8 @@ xfs_alloc_cur_setup(
863862
* attempt a small allocation.
864863
*/
865864
if (!acur->cnt)
866-
acur->cnt = xfs_allocbt_init_cursor(args->mp, args->tp,
867-
args->agbp, args->pag, XFS_BTNUM_CNT);
865+
acur->cnt = xfs_cntbt_init_cursor(args->mp, args->tp,
866+
args->agbp, args->pag);
868867
error = xfs_alloc_lookup_ge(acur->cnt, 0, args->maxlen, &i);
869868
if (error)
870869
return error;
@@ -873,11 +872,11 @@ xfs_alloc_cur_setup(
873872
* Allocate the bnobt left and right search cursors.
874873
*/
875874
if (!acur->bnolt)
876-
acur->bnolt = xfs_allocbt_init_cursor(args->mp, args->tp,
877-
args->agbp, args->pag, XFS_BTNUM_BNO);
875+
acur->bnolt = xfs_bnobt_init_cursor(args->mp, args->tp,
876+
args->agbp, args->pag);
878877
if (!acur->bnogt)
879-
acur->bnogt = xfs_allocbt_init_cursor(args->mp, args->tp,
880-
args->agbp, args->pag, XFS_BTNUM_BNO);
878+
acur->bnogt = xfs_bnobt_init_cursor(args->mp, args->tp,
879+
args->agbp, args->pag);
881880
return i == 1 ? 0 : -ENOSPC;
882881
}
883882

@@ -919,7 +918,7 @@ xfs_alloc_cur_check(
919918
bool busy;
920919
unsigned busy_gen = 0;
921920
bool deactivate = false;
922-
bool isbnobt = cur->bc_btnum == XFS_BTNUM_BNO;
921+
bool isbnobt = xfs_btree_is_bno(cur->bc_ops);
923922

924923
*new = 0;
925924

@@ -996,8 +995,7 @@ xfs_alloc_cur_check(
996995
out:
997996
if (deactivate)
998997
cur->bc_flags &= ~XFS_BTREE_ALLOCBT_ACTIVE;
999-
trace_xfs_alloc_cur_check(args->mp, cur->bc_btnum, bno, len, diff,
1000-
*new);
998+
trace_xfs_alloc_cur_check(cur, bno, len, diff, *new);
1001999
return 0;
10021000
}
10031001

@@ -1236,8 +1234,8 @@ xfs_alloc_ag_vextent_exact(
12361234
/*
12371235
* Allocate/initialize a cursor for the by-number freespace btree.
12381236
*/
1239-
bno_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
1240-
args->pag, XFS_BTNUM_BNO);
1237+
bno_cur = xfs_bnobt_init_cursor(args->mp, args->tp, args->agbp,
1238+
args->pag);
12411239

12421240
/*
12431241
* Lookup bno and minlen in the btree (minlen is irrelevant, really).
@@ -1297,8 +1295,8 @@ xfs_alloc_ag_vextent_exact(
12971295
* We are allocating agbno for args->len
12981296
* Allocate/initialize a cursor for the by-size btree.
12991297
*/
1300-
cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
1301-
args->pag, XFS_BTNUM_CNT);
1298+
cnt_cur = xfs_cntbt_init_cursor(args->mp, args->tp, args->agbp,
1299+
args->pag);
13021300
ASSERT(args->agbno + args->len <= be32_to_cpu(agf->agf_length));
13031301
error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen, args->agbno,
13041302
args->len, XFSA_FIXUP_BNO_OK);
@@ -1712,8 +1710,8 @@ xfs_alloc_ag_vextent_size(
17121710
/*
17131711
* Allocate and initialize a cursor for the by-size btree.
17141712
*/
1715-
cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
1716-
args->pag, XFS_BTNUM_CNT);
1713+
cnt_cur = xfs_cntbt_init_cursor(args->mp, args->tp, args->agbp,
1714+
args->pag);
17171715
bno_cur = NULL;
17181716

17191717
/*
@@ -1898,8 +1896,8 @@ xfs_alloc_ag_vextent_size(
18981896
/*
18991897
* Allocate and initialize a cursor for the by-block tree.
19001898
*/
1901-
bno_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
1902-
args->pag, XFS_BTNUM_BNO);
1899+
bno_cur = xfs_bnobt_init_cursor(args->mp, args->tp, args->agbp,
1900+
args->pag);
19031901
if ((error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen,
19041902
rbno, rlen, XFSA_FIXUP_CNT_OK)))
19051903
goto error0;
@@ -1973,7 +1971,7 @@ xfs_free_ag_extent(
19731971
/*
19741972
* Allocate and initialize a cursor for the by-block btree.
19751973
*/
1976-
bno_cur = xfs_allocbt_init_cursor(mp, tp, agbp, pag, XFS_BTNUM_BNO);
1974+
bno_cur = xfs_bnobt_init_cursor(mp, tp, agbp, pag);
19771975
/*
19781976
* Look for a neighboring block on the left (lower block numbers)
19791977
* that is contiguous with this space.
@@ -2047,7 +2045,7 @@ xfs_free_ag_extent(
20472045
/*
20482046
* Now allocate and initialize a cursor for the by-size tree.
20492047
*/
2050-
cnt_cur = xfs_allocbt_init_cursor(mp, tp, agbp, pag, XFS_BTNUM_CNT);
2048+
cnt_cur = xfs_cntbt_init_cursor(mp, tp, agbp, pag);
20512049
/*
20522050
* Have both left and right contiguous neighbors.
20532051
* Merge all three into a single free block.
@@ -2335,8 +2333,9 @@ xfs_alloc_min_freelist(
23352333
struct xfs_perag *pag)
23362334
{
23372335
/* AG btrees have at least 1 level. */
2338-
static const uint8_t fake_levels[XFS_BTNUM_AGF] = {1, 1, 1};
2339-
const uint8_t *levels = pag ? pag->pagf_levels : fake_levels;
2336+
const unsigned int bno_level = pag ? pag->pagf_bno_level : 1;
2337+
const unsigned int cnt_level = pag ? pag->pagf_cnt_level : 1;
2338+
const unsigned int rmap_level = pag ? pag->pagf_rmap_level : 1;
23402339
unsigned int min_free;
23412340

23422341
ASSERT(mp->m_alloc_maxlevels > 0);
@@ -2363,16 +2362,12 @@ xfs_alloc_min_freelist(
23632362
*/
23642363

23652364
/* space needed by-bno freespace btree */
2366-
min_free = min_t(unsigned int, levels[XFS_BTNUM_BNOi] + 1,
2367-
mp->m_alloc_maxlevels) * 2 - 2;
2365+
min_free = min(bno_level + 1, mp->m_alloc_maxlevels) * 2 - 2;
23682366
/* space needed by-size freespace btree */
2369-
min_free += min_t(unsigned int, levels[XFS_BTNUM_CNTi] + 1,
2370-
mp->m_alloc_maxlevels) * 2 - 2;
2367+
min_free += min(cnt_level + 1, mp->m_alloc_maxlevels) * 2 - 2;
23712368
/* space needed reverse mapping used space btree */
23722369
if (xfs_has_rmapbt(mp))
2373-
min_free += min_t(unsigned int, levels[XFS_BTNUM_RMAPi] + 1,
2374-
mp->m_rmap_maxlevels) * 2 - 2;
2375-
2370+
min_free += min(rmap_level + 1, mp->m_rmap_maxlevels) * 2 - 2;
23762371
return min_free;
23772372
}
23782373

@@ -2759,8 +2754,8 @@ xfs_exact_minlen_extent_available(
27592754
xfs_extlen_t flen;
27602755
int error = 0;
27612756

2762-
cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, agbp,
2763-
args->pag, XFS_BTNUM_CNT);
2757+
cnt_cur = xfs_cntbt_init_cursor(args->mp, args->tp, agbp,
2758+
args->pag);
27642759
error = xfs_alloc_lookup_ge(cnt_cur, 0, args->minlen, stat);
27652760
if (error)
27662761
goto out;
@@ -3056,8 +3051,8 @@ xfs_alloc_log_agf(
30563051
offsetof(xfs_agf_t, agf_versionnum),
30573052
offsetof(xfs_agf_t, agf_seqno),
30583053
offsetof(xfs_agf_t, agf_length),
3059-
offsetof(xfs_agf_t, agf_roots[0]),
3060-
offsetof(xfs_agf_t, agf_levels[0]),
3054+
offsetof(xfs_agf_t, agf_bno_root), /* also cnt/rmap root */
3055+
offsetof(xfs_agf_t, agf_bno_level), /* also cnt/rmap levels */
30613056
offsetof(xfs_agf_t, agf_flfirst),
30623057
offsetof(xfs_agf_t, agf_fllast),
30633058
offsetof(xfs_agf_t, agf_flcount),
@@ -3236,12 +3231,10 @@ xfs_agf_verify(
32363231
be32_to_cpu(agf->agf_freeblks) > agf_length)
32373232
return __this_address;
32383233

3239-
if (be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]) < 1 ||
3240-
be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]) < 1 ||
3241-
be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]) >
3242-
mp->m_alloc_maxlevels ||
3243-
be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]) >
3244-
mp->m_alloc_maxlevels)
3234+
if (be32_to_cpu(agf->agf_bno_level) < 1 ||
3235+
be32_to_cpu(agf->agf_cnt_level) < 1 ||
3236+
be32_to_cpu(agf->agf_bno_level) > mp->m_alloc_maxlevels ||
3237+
be32_to_cpu(agf->agf_cnt_level) > mp->m_alloc_maxlevels)
32453238
return __this_address;
32463239

32473240
if (xfs_has_lazysbcount(mp) &&
@@ -3252,9 +3245,8 @@ xfs_agf_verify(
32523245
if (be32_to_cpu(agf->agf_rmap_blocks) > agf_length)
32533246
return __this_address;
32543247

3255-
if (be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]) < 1 ||
3256-
be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]) >
3257-
mp->m_rmap_maxlevels)
3248+
if (be32_to_cpu(agf->agf_rmap_level) < 1 ||
3249+
be32_to_cpu(agf->agf_rmap_level) > mp->m_rmap_maxlevels)
32583250
return __this_address;
32593251
}
32603252

@@ -3380,12 +3372,9 @@ xfs_alloc_read_agf(
33803372
pag->pagf_btreeblks = be32_to_cpu(agf->agf_btreeblks);
33813373
pag->pagf_flcount = be32_to_cpu(agf->agf_flcount);
33823374
pag->pagf_longest = be32_to_cpu(agf->agf_longest);
3383-
pag->pagf_levels[XFS_BTNUM_BNOi] =
3384-
be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNOi]);
3385-
pag->pagf_levels[XFS_BTNUM_CNTi] =
3386-
be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNTi]);
3387-
pag->pagf_levels[XFS_BTNUM_RMAPi] =
3388-
be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAPi]);
3375+
pag->pagf_bno_level = be32_to_cpu(agf->agf_bno_level);
3376+
pag->pagf_cnt_level = be32_to_cpu(agf->agf_cnt_level);
3377+
pag->pagf_rmap_level = be32_to_cpu(agf->agf_rmap_level);
33893378
pag->pagf_refcount_level = be32_to_cpu(agf->agf_refcount_level);
33903379
if (xfs_agfl_needs_reset(pag->pag_mount, agf))
33913380
set_bit(XFS_AGSTATE_AGFL_NEEDS_RESET, &pag->pag_opstate);
@@ -3414,10 +3403,8 @@ xfs_alloc_read_agf(
34143403
ASSERT(pag->pagf_btreeblks == be32_to_cpu(agf->agf_btreeblks));
34153404
ASSERT(pag->pagf_flcount == be32_to_cpu(agf->agf_flcount));
34163405
ASSERT(pag->pagf_longest == be32_to_cpu(agf->agf_longest));
3417-
ASSERT(pag->pagf_levels[XFS_BTNUM_BNOi] ==
3418-
be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNOi]));
3419-
ASSERT(pag->pagf_levels[XFS_BTNUM_CNTi] ==
3420-
be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNTi]));
3406+
ASSERT(pag->pagf_bno_level == be32_to_cpu(agf->agf_bno_level));
3407+
ASSERT(pag->pagf_cnt_level == be32_to_cpu(agf->agf_cnt_level));
34213408
}
34223409
#endif
34233410
if (agfbpp)
@@ -4039,7 +4026,7 @@ xfs_alloc_query_range(
40394026
union xfs_btree_irec high_brec = { .a = *high_rec };
40404027
struct xfs_alloc_query_range_info query = { .priv = priv, .fn = fn };
40414028

4042-
ASSERT(cur->bc_btnum == XFS_BTNUM_BNO);
4029+
ASSERT(xfs_btree_is_bno(cur->bc_ops));
40434030
return xfs_btree_query_range(cur, &low_brec, &high_brec,
40444031
xfs_alloc_query_range_helper, &query);
40454032
}
@@ -4053,7 +4040,7 @@ xfs_alloc_query_all(
40534040
{
40544041
struct xfs_alloc_query_range_info query;
40554042

4056-
ASSERT(cur->bc_btnum == XFS_BTNUM_BNO);
4043+
ASSERT(xfs_btree_is_bno(cur->bc_ops));
40574044
query.priv = priv;
40584045
query.fn = fn;
40594046
return xfs_btree_query_all(cur, xfs_alloc_query_range_helper, &query);

0 commit comments

Comments
 (0)