Skip to content

Commit ec793e6

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: remove xfs_btnum_t
The last checks for bc_btnum can be replaced with helpers that check the btree ops. This allows adding new btrees to XFS without having to update a global enum. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> [djwong: complete the ops predicates] Signed-off-by: Darrick J. Wong <djwong@kernel.org>
1 parent fbeef4e commit ec793e6

16 files changed

Lines changed: 65 additions & 70 deletions

fs/xfs/libxfs/xfs_alloc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ xfs_alloc_cur_check(
918918
bool busy;
919919
unsigned busy_gen = 0;
920920
bool deactivate = false;
921-
bool isbnobt = cur->bc_btnum == XFS_BTNUM_BNO;
921+
bool isbnobt = xfs_btree_is_bno(cur->bc_ops);
922922

923923
*new = 0;
924924

@@ -4026,7 +4026,7 @@ xfs_alloc_query_range(
40264026
union xfs_btree_irec high_brec = { .a = *high_rec };
40274027
struct xfs_alloc_query_range_info query = { .priv = priv, .fn = fn };
40284028

4029-
ASSERT(cur->bc_btnum == XFS_BTNUM_BNO);
4029+
ASSERT(xfs_btree_is_bno(cur->bc_ops));
40304030
return xfs_btree_query_range(cur, &low_brec, &high_brec,
40314031
xfs_alloc_query_range_helper, &query);
40324032
}
@@ -4040,7 +4040,7 @@ xfs_alloc_query_all(
40404040
{
40414041
struct xfs_alloc_query_range_info query;
40424042

4043-
ASSERT(cur->bc_btnum == XFS_BTNUM_BNO);
4043+
ASSERT(xfs_btree_is_bno(cur->bc_ops));
40444044
query.priv = priv;
40454045
query.fn = fn;
40464046
return xfs_btree_query_all(cur, xfs_alloc_query_range_helper, &query);

fs/xfs/libxfs/xfs_alloc_btree.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ xfs_allocbt_set_root(
5151

5252
ASSERT(ptr->s != 0);
5353

54-
if (cur->bc_btnum == XFS_BTNUM_BNO) {
54+
if (xfs_btree_is_bno(cur->bc_ops)) {
5555
agf->agf_bno_root = ptr->s;
5656
be32_add_cpu(&agf->agf_bno_level, inc);
5757
cur->bc_ag.pag->pagf_bno_level += inc;
@@ -131,7 +131,7 @@ xfs_allocbt_update_lastrec(
131131
__be32 len;
132132
int numrecs;
133133

134-
ASSERT(cur->bc_btnum == XFS_BTNUM_CNT);
134+
ASSERT(!xfs_btree_is_bno(cur->bc_ops));
135135

136136
switch (reason) {
137137
case LASTREC_UPDATE:
@@ -241,7 +241,7 @@ xfs_allocbt_init_ptr_from_cur(
241241

242242
ASSERT(cur->bc_ag.pag->pag_agno == be32_to_cpu(agf->agf_seqno));
243243

244-
if (cur->bc_btnum == XFS_BTNUM_BNO)
244+
if (xfs_btree_is_bno(cur->bc_ops))
245245
ptr->s = agf->agf_bno_root;
246246
else
247247
ptr->s = agf->agf_cnt_root;
@@ -554,7 +554,7 @@ xfs_bnobt_init_cursor(
554554
{
555555
struct xfs_btree_cur *cur;
556556

557-
cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_BNO, &xfs_bnobt_ops,
557+
cur = xfs_btree_alloc_cursor(mp, tp, &xfs_bnobt_ops,
558558
mp->m_alloc_maxlevels, xfs_allocbt_cur_cache);
559559
cur->bc_ag.pag = xfs_perag_hold(pag);
560560
cur->bc_ag.agbp = agbp;
@@ -580,7 +580,7 @@ xfs_cntbt_init_cursor(
580580
{
581581
struct xfs_btree_cur *cur;
582582

583-
cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_CNT, &xfs_cntbt_ops,
583+
cur = xfs_btree_alloc_cursor(mp, tp, &xfs_cntbt_ops,
584584
mp->m_alloc_maxlevels, xfs_allocbt_cur_cache);
585585
cur->bc_ag.pag = xfs_perag_hold(pag);
586586
cur->bc_ag.agbp = agbp;
@@ -607,7 +607,7 @@ xfs_allocbt_commit_staged_btree(
607607

608608
ASSERT(cur->bc_flags & XFS_BTREE_STAGING);
609609

610-
if (cur->bc_btnum == XFS_BTNUM_BNO) {
610+
if (xfs_btree_is_bno(cur->bc_ops)) {
611611
agf->agf_bno_root = cpu_to_be32(afake->af_root);
612612
agf->agf_bno_level = cpu_to_be32(afake->af_levels);
613613
} else {

fs/xfs/libxfs/xfs_bmap_btree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,8 @@ xfs_bmbt_init_cursor(
574574
maxlevels = mp->m_bm_maxlevels[whichfork];
575575
break;
576576
}
577-
cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_BMAP, &xfs_bmbt_ops,
578-
maxlevels, xfs_bmbt_cur_cache);
577+
cur = xfs_btree_alloc_cursor(mp, tp, &xfs_bmbt_ops, maxlevels,
578+
xfs_bmbt_cur_cache);
579579
cur->bc_ino.ip = ip;
580580
cur->bc_ino.whichfork = whichfork;
581581
cur->bc_bmap.allocated = 0;

fs/xfs/libxfs/xfs_btree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ xfs_btree_del_cursor(
454454
* zero, then we should be shut down or on our way to shutdown due to
455455
* cancelling a dirty transaction on error.
456456
*/
457-
ASSERT(cur->bc_btnum != XFS_BTNUM_BMAP || cur->bc_bmap.allocated == 0 ||
457+
ASSERT(!xfs_btree_is_bmap(cur->bc_ops) || cur->bc_bmap.allocated == 0 ||
458458
xfs_is_shutdown(cur->bc_mp) || error != 0);
459459

460460
switch (cur->bc_ops->type) {
@@ -3016,7 +3016,7 @@ xfs_btree_split(
30163016
struct xfs_btree_split_args args;
30173017
DECLARE_COMPLETION_ONSTACK(done);
30183018

3019-
if (cur->bc_btnum != XFS_BTNUM_BMAP ||
3019+
if (!xfs_btree_is_bmap(cur->bc_ops) ||
30203020
cur->bc_tp->t_highest_agno == NULLAGNUMBER)
30213021
return __xfs_btree_split(cur, level, ptrp, key, curp, stat);
30223022

fs/xfs/libxfs/xfs_btree.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ union xfs_btree_rec {
5555
#define XFS_LOOKUP_LE ((xfs_lookup_t)XFS_LOOKUP_LEi)
5656
#define XFS_LOOKUP_GE ((xfs_lookup_t)XFS_LOOKUP_GEi)
5757

58-
#define XFS_BTNUM_BNO ((xfs_btnum_t)XFS_BTNUM_BNOi)
59-
#define XFS_BTNUM_CNT ((xfs_btnum_t)XFS_BTNUM_CNTi)
60-
#define XFS_BTNUM_BMAP ((xfs_btnum_t)XFS_BTNUM_BMAPi)
61-
#define XFS_BTNUM_INO ((xfs_btnum_t)XFS_BTNUM_INOi)
62-
#define XFS_BTNUM_FINO ((xfs_btnum_t)XFS_BTNUM_FINOi)
63-
#define XFS_BTNUM_RMAP ((xfs_btnum_t)XFS_BTNUM_RMAPi)
64-
#define XFS_BTNUM_REFC ((xfs_btnum_t)XFS_BTNUM_REFCi)
65-
6658
struct xfs_btree_ops;
6759
uint32_t xfs_btree_magic(struct xfs_mount *mp, const struct xfs_btree_ops *ops);
6860

@@ -272,7 +264,6 @@ struct xfs_btree_cur
272264
const struct xfs_btree_ops *bc_ops;
273265
struct kmem_cache *bc_cache; /* cursor cache */
274266
unsigned int bc_flags; /* btree features - below */
275-
xfs_btnum_t bc_btnum; /* identifies which btree type */
276267
union xfs_btree_irec bc_rec; /* current insert/search record value */
277268
uint8_t bc_nlevels; /* number of levels in the tree */
278269
uint8_t bc_maxlevels; /* maximum levels for this btree type */
@@ -726,7 +717,6 @@ static inline struct xfs_btree_cur *
726717
xfs_btree_alloc_cursor(
727718
struct xfs_mount *mp,
728719
struct xfs_trans *tp,
729-
xfs_btnum_t btnum,
730720
const struct xfs_btree_ops *ops,
731721
uint8_t maxlevels,
732722
struct kmem_cache *cache)
@@ -742,7 +732,6 @@ xfs_btree_alloc_cursor(
742732
cur->bc_ops = ops;
743733
cur->bc_tp = tp;
744734
cur->bc_mp = mp;
745-
cur->bc_btnum = btnum;
746735
cur->bc_maxlevels = maxlevels;
747736
cur->bc_cache = cache;
748737

fs/xfs/libxfs/xfs_ialloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2848,7 +2848,7 @@ xfs_ialloc_count_inodes(
28482848
struct xfs_ialloc_count_inodes ci = {0};
28492849
int error;
28502850

2851-
ASSERT(cur->bc_btnum == XFS_BTNUM_INO);
2851+
ASSERT(xfs_btree_is_ino(cur->bc_ops));
28522852
error = xfs_btree_query_all(cur, xfs_ialloc_count_inodes_rec, &ci);
28532853
if (error)
28542854
return error;

fs/xfs/libxfs/xfs_ialloc_btree.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ xfs_inobt_mod_blockcount(
9090
if (!xfs_has_inobtcounts(cur->bc_mp))
9191
return;
9292

93-
if (cur->bc_btnum == XFS_BTNUM_FINO)
93+
if (xfs_btree_is_fino(cur->bc_ops))
9494
be32_add_cpu(&agi->agi_fblocks, howmuch);
95-
else if (cur->bc_btnum == XFS_BTNUM_INO)
95+
else
9696
be32_add_cpu(&agi->agi_iblocks, howmuch);
9797
xfs_ialloc_log_agi(cur->bc_tp, agbp, XFS_AGI_IBLOCKS);
9898
}
@@ -481,7 +481,7 @@ xfs_inobt_init_cursor(
481481
struct xfs_mount *mp = pag->pag_mount;
482482
struct xfs_btree_cur *cur;
483483

484-
cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_INO, &xfs_inobt_ops,
484+
cur = xfs_btree_alloc_cursor(mp, tp, &xfs_inobt_ops,
485485
M_IGEO(mp)->inobt_maxlevels, xfs_inobt_cur_cache);
486486
cur->bc_ag.pag = xfs_perag_hold(pag);
487487
cur->bc_ag.agbp = agbp;
@@ -507,7 +507,7 @@ xfs_finobt_init_cursor(
507507
struct xfs_mount *mp = pag->pag_mount;
508508
struct xfs_btree_cur *cur;
509509

510-
cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_FINO, &xfs_finobt_ops,
510+
cur = xfs_btree_alloc_cursor(mp, tp, &xfs_finobt_ops,
511511
M_IGEO(mp)->inobt_maxlevels, xfs_inobt_cur_cache);
512512
cur->bc_ag.pag = xfs_perag_hold(pag);
513513
cur->bc_ag.agbp = agbp;
@@ -535,7 +535,7 @@ xfs_inobt_commit_staged_btree(
535535

536536
ASSERT(cur->bc_flags & XFS_BTREE_STAGING);
537537

538-
if (cur->bc_btnum == XFS_BTNUM_INO) {
538+
if (xfs_btree_is_ino(cur->bc_ops)) {
539539
fields = XFS_AGI_ROOT | XFS_AGI_LEVEL;
540540
agi->agi_root = cpu_to_be32(afake->af_root);
541541
agi->agi_level = cpu_to_be32(afake->af_levels);

fs/xfs/libxfs/xfs_refcount_btree.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,8 @@ xfs_refcountbt_init_cursor(
364364

365365
ASSERT(pag->pag_agno < mp->m_sb.sb_agcount);
366366

367-
cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_REFC,
368-
&xfs_refcountbt_ops, mp->m_refc_maxlevels,
369-
xfs_refcountbt_cur_cache);
367+
cur = xfs_btree_alloc_cursor(mp, tp, &xfs_refcountbt_ops,
368+
mp->m_refc_maxlevels, xfs_refcountbt_cur_cache);
370369
cur->bc_ag.pag = xfs_perag_hold(pag);
371370
cur->bc_refc.nr_ops = 0;
372371
cur->bc_refc.shape_changes = 0;

fs/xfs/libxfs/xfs_rmap_btree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ xfs_rmapbt_init_cursor(
518518
{
519519
struct xfs_btree_cur *cur;
520520

521-
cur = xfs_btree_alloc_cursor(mp, tp, XFS_BTNUM_RMAP, &xfs_rmapbt_ops,
521+
cur = xfs_btree_alloc_cursor(mp, tp, &xfs_rmapbt_ops,
522522
mp->m_rmap_maxlevels, xfs_rmapbt_cur_cache);
523523
cur->bc_ag.pag = xfs_perag_hold(pag);
524524
cur->bc_ag.agbp = agbp;

fs/xfs/libxfs/xfs_shared.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,41 @@ extern const struct xfs_btree_ops xfs_bmbt_ops;
5252
extern const struct xfs_btree_ops xfs_refcountbt_ops;
5353
extern const struct xfs_btree_ops xfs_rmapbt_ops;
5454

55+
static inline bool xfs_btree_is_bno(const struct xfs_btree_ops *ops)
56+
{
57+
return ops == &xfs_bnobt_ops;
58+
}
59+
60+
static inline bool xfs_btree_is_cnt(const struct xfs_btree_ops *ops)
61+
{
62+
return ops == &xfs_cntbt_ops;
63+
}
64+
65+
static inline bool xfs_btree_is_bmap(const struct xfs_btree_ops *ops)
66+
{
67+
return ops == &xfs_bmbt_ops;
68+
}
69+
70+
static inline bool xfs_btree_is_ino(const struct xfs_btree_ops *ops)
71+
{
72+
return ops == &xfs_inobt_ops;
73+
}
74+
75+
static inline bool xfs_btree_is_fino(const struct xfs_btree_ops *ops)
76+
{
77+
return ops == &xfs_finobt_ops;
78+
}
79+
80+
static inline bool xfs_btree_is_refcount(const struct xfs_btree_ops *ops)
81+
{
82+
return ops == &xfs_refcountbt_ops;
83+
}
84+
85+
static inline bool xfs_btree_is_rmap(const struct xfs_btree_ops *ops)
86+
{
87+
return ops == &xfs_rmapbt_ops;
88+
}
89+
5590
/* log size calculation functions */
5691
int xfs_log_calc_unit_res(struct xfs_mount *mp, int unit_bytes);
5792
int xfs_log_calc_minimum_size(struct xfs_mount *);

0 commit comments

Comments
 (0)