Skip to content

Commit 681cb87

Browse files
author
Chandan Babu R
committed
Merge tag 'btree-geometry-in-ops-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.9-mergeC
xfs: move btree geometry to ops struct This patchset prepares the generic btree code to allow for the creation of new btree types outside of libxfs. The end goal here is for online fsck to be able to create its own in-memory btrees that will be used to improve the performance (and reduce the memory requirements of) the refcount btree. To enable this, I decided that the btree ops structure is the ideal place to encode all of the geometry information about a btree. The btree ops struture already contains the buffer ops (and hence the btree block magic numbers) as well as the key and record sizes, so it doesn't seem all that farfetched to encode the XFS_BTREE_ flags that determine the geometry (ROOT_IN_INODE, LONG_PTRS, etc). The rest of the patchset cleans up the btree functions that initialize btree blocks and btree buffers. The bulk of this work is to replace btree geometry related function call arguments with a single pointer to the ops structure, and then clean up everything else around that. As a side effect, we rename the functions. Later, Christoph Hellwig and I merged together a bunch more cleanups that he wanted to do for a while. All the btree geometry information is now in the btree ops structure, we've created an explicit btree type (ag, inode, mem) and moved the per-btree type information to a separate union. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org> * tag 'btree-geometry-in-ops-6.9_2024-02-23' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux: xfs: create predicate to determine if cursor is at inode root level xfs: split the per-btree union in struct xfs_btree_cur xfs: split out a btree type from the btree ops geometry flags xfs: store the btree pointer length in struct xfs_btree_ops xfs: factor out a btree block owner check xfs: factor out a xfs_btree_owner helper xfs: move the btree stats offset into struct btree_ops xfs: move lru refs to the btree ops structure xfs: set btree block buffer ops in _init_buf xfs: remove the unnecessary daddr paramter to _init_block xfs: btree convert xfs_btree_init_block to xfs_btree_init_buf calls xfs: rename btree block/buffer init functions xfs: initialize btree blocks using btree_ops structure xfs: extern some btree ops structures xfs: turn the allocbt cursor active field into a btree flag xfs: consolidate the xfs_alloc_lookup_* helpers xfs: remove bc_ino.flags xfs: encode the btree geometry flags in the btree ops structure xfs: fix imprecise logic in xchk_btree_check_block_owner xfs: drop XFS_BTREE_CRC_BLOCKS xfs: set the btree cursor bc_ops in xfs_btree_alloc_cursor xfs: consolidate btree block allocation tracepoints xfs: consolidate btree block freeing tracepoints
2 parents 5d1bd19 + f73def9 commit 681cb87

20 files changed

Lines changed: 563 additions & 459 deletions

fs/xfs/libxfs/xfs_ag.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ xfs_btroot_init(
492492
struct xfs_buf *bp,
493493
struct aghdr_init_data *id)
494494
{
495-
xfs_btree_init_block(mp, bp, id->type, 0, 0, id->agno);
495+
xfs_btree_init_buf(mp, bp, id->bc_ops, 0, 0, id->agno);
496496
}
497497

498498
/* Finish initializing a free space btree. */
@@ -550,25 +550,15 @@ xfs_freesp_init_recs(
550550
}
551551

552552
/*
553-
* Alloc btree root block init functions
553+
* bnobt/cntbt btree root block init functions
554554
*/
555555
static void
556556
xfs_bnoroot_init(
557557
struct xfs_mount *mp,
558558
struct xfs_buf *bp,
559559
struct aghdr_init_data *id)
560560
{
561-
xfs_btree_init_block(mp, bp, XFS_BTNUM_BNO, 0, 0, id->agno);
562-
xfs_freesp_init_recs(mp, bp, id);
563-
}
564-
565-
static void
566-
xfs_cntroot_init(
567-
struct xfs_mount *mp,
568-
struct xfs_buf *bp,
569-
struct aghdr_init_data *id)
570-
{
571-
xfs_btree_init_block(mp, bp, XFS_BTNUM_CNT, 0, 0, id->agno);
561+
xfs_btree_init_buf(mp, bp, id->bc_ops, 0, 0, id->agno);
572562
xfs_freesp_init_recs(mp, bp, id);
573563
}
574564

@@ -584,7 +574,7 @@ xfs_rmaproot_init(
584574
struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
585575
struct xfs_rmap_rec *rrec;
586576

587-
xfs_btree_init_block(mp, bp, XFS_BTNUM_RMAP, 0, 4, id->agno);
577+
xfs_btree_init_buf(mp, bp, id->bc_ops, 0, 4, id->agno);
588578

589579
/*
590580
* mark the AG header regions as static metadata The BNO
@@ -797,7 +787,7 @@ struct xfs_aghdr_grow_data {
797787
size_t numblks;
798788
const struct xfs_buf_ops *ops;
799789
aghdr_init_work_f work;
800-
xfs_btnum_t type;
790+
const struct xfs_btree_ops *bc_ops;
801791
bool need_init;
802792
};
803793

@@ -851,44 +841,47 @@ xfs_ag_init_headers(
851841
.numblks = BTOBB(mp->m_sb.sb_blocksize),
852842
.ops = &xfs_bnobt_buf_ops,
853843
.work = &xfs_bnoroot_init,
844+
.bc_ops = &xfs_bnobt_ops,
854845
.need_init = true
855846
},
856847
{ /* CNT root block */
857848
.daddr = XFS_AGB_TO_DADDR(mp, id->agno, XFS_CNT_BLOCK(mp)),
858849
.numblks = BTOBB(mp->m_sb.sb_blocksize),
859850
.ops = &xfs_cntbt_buf_ops,
860-
.work = &xfs_cntroot_init,
851+
.work = &xfs_bnoroot_init,
852+
.bc_ops = &xfs_cntbt_ops,
861853
.need_init = true
862854
},
863855
{ /* INO root block */
864856
.daddr = XFS_AGB_TO_DADDR(mp, id->agno, XFS_IBT_BLOCK(mp)),
865857
.numblks = BTOBB(mp->m_sb.sb_blocksize),
866858
.ops = &xfs_inobt_buf_ops,
867859
.work = &xfs_btroot_init,
868-
.type = XFS_BTNUM_INO,
860+
.bc_ops = &xfs_inobt_ops,
869861
.need_init = true
870862
},
871863
{ /* FINO root block */
872864
.daddr = XFS_AGB_TO_DADDR(mp, id->agno, XFS_FIBT_BLOCK(mp)),
873865
.numblks = BTOBB(mp->m_sb.sb_blocksize),
874866
.ops = &xfs_finobt_buf_ops,
875867
.work = &xfs_btroot_init,
876-
.type = XFS_BTNUM_FINO,
868+
.bc_ops = &xfs_finobt_ops,
877869
.need_init = xfs_has_finobt(mp)
878870
},
879871
{ /* RMAP root block */
880872
.daddr = XFS_AGB_TO_DADDR(mp, id->agno, XFS_RMAP_BLOCK(mp)),
881873
.numblks = BTOBB(mp->m_sb.sb_blocksize),
882874
.ops = &xfs_rmapbt_buf_ops,
883875
.work = &xfs_rmaproot_init,
876+
.bc_ops = &xfs_rmapbt_ops,
884877
.need_init = xfs_has_rmapbt(mp)
885878
},
886879
{ /* REFC root block */
887880
.daddr = XFS_AGB_TO_DADDR(mp, id->agno, xfs_refc_block(mp)),
888881
.numblks = BTOBB(mp->m_sb.sb_blocksize),
889882
.ops = &xfs_refcountbt_buf_ops,
890883
.work = &xfs_btroot_init,
891-
.type = XFS_BTNUM_REFC,
884+
.bc_ops = &xfs_refcountbt_ops,
892885
.need_init = xfs_has_reflink(mp)
893886
},
894887
{ /* NULL terminating block */
@@ -906,7 +899,7 @@ xfs_ag_init_headers(
906899

907900
id->daddr = dp->daddr;
908901
id->numblks = dp->numblks;
909-
id->type = dp->type;
902+
id->bc_ops = dp->bc_ops;
910903
error = xfs_ag_init_hdr(mp, id, dp->work, dp->ops);
911904
if (error)
912905
break;

fs/xfs/libxfs/xfs_ag.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ struct aghdr_init_data {
331331
/* per header data */
332332
xfs_daddr_t daddr; /* header location */
333333
size_t numblks; /* size of header */
334-
xfs_btnum_t type; /* type of btree root block */
334+
const struct xfs_btree_ops *bc_ops; /* btree ops */
335335
};
336336

337337
int xfs_ag_init_headers(struct xfs_mount *mp, struct aghdr_init_data *id);

fs/xfs/libxfs/xfs_alloc.c

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,38 @@ xfs_alloc_ag_max_usable(
151151
return mp->m_sb.sb_agblocks - blocks;
152152
}
153153

154+
155+
static int
156+
xfs_alloc_lookup(
157+
struct xfs_btree_cur *cur,
158+
xfs_lookup_t dir,
159+
xfs_agblock_t bno,
160+
xfs_extlen_t len,
161+
int *stat)
162+
{
163+
int error;
164+
165+
cur->bc_rec.a.ar_startblock = bno;
166+
cur->bc_rec.a.ar_blockcount = len;
167+
error = xfs_btree_lookup(cur, dir, stat);
168+
if (*stat == 1)
169+
cur->bc_flags |= XFS_BTREE_ALLOCBT_ACTIVE;
170+
else
171+
cur->bc_flags &= ~XFS_BTREE_ALLOCBT_ACTIVE;
172+
return error;
173+
}
174+
154175
/*
155176
* Lookup the record equal to [bno, len] in the btree given by cur.
156177
*/
157-
STATIC int /* error */
178+
static inline int /* error */
158179
xfs_alloc_lookup_eq(
159180
struct xfs_btree_cur *cur, /* btree cursor */
160181
xfs_agblock_t bno, /* starting block of extent */
161182
xfs_extlen_t len, /* length of extent */
162183
int *stat) /* success/failure */
163184
{
164-
int error;
165-
166-
cur->bc_rec.a.ar_startblock = bno;
167-
cur->bc_rec.a.ar_blockcount = len;
168-
error = xfs_btree_lookup(cur, XFS_LOOKUP_EQ, stat);
169-
cur->bc_ag.abt.active = (*stat == 1);
170-
return error;
185+
return xfs_alloc_lookup(cur, XFS_LOOKUP_EQ, bno, len, stat);
171186
}
172187

173188
/*
@@ -181,13 +196,7 @@ xfs_alloc_lookup_ge(
181196
xfs_extlen_t len, /* length of extent */
182197
int *stat) /* success/failure */
183198
{
184-
int error;
185-
186-
cur->bc_rec.a.ar_startblock = bno;
187-
cur->bc_rec.a.ar_blockcount = len;
188-
error = xfs_btree_lookup(cur, XFS_LOOKUP_GE, stat);
189-
cur->bc_ag.abt.active = (*stat == 1);
190-
return error;
199+
return xfs_alloc_lookup(cur, XFS_LOOKUP_GE, bno, len, stat);
191200
}
192201

193202
/*
@@ -201,19 +210,14 @@ xfs_alloc_lookup_le(
201210
xfs_extlen_t len, /* length of extent */
202211
int *stat) /* success/failure */
203212
{
204-
int error;
205-
cur->bc_rec.a.ar_startblock = bno;
206-
cur->bc_rec.a.ar_blockcount = len;
207-
error = xfs_btree_lookup(cur, XFS_LOOKUP_LE, stat);
208-
cur->bc_ag.abt.active = (*stat == 1);
209-
return error;
213+
return xfs_alloc_lookup(cur, XFS_LOOKUP_LE, bno, len, stat);
210214
}
211215

212216
static inline bool
213217
xfs_alloc_cur_active(
214218
struct xfs_btree_cur *cur)
215219
{
216-
return cur && cur->bc_ag.abt.active;
220+
return cur && (cur->bc_flags & XFS_BTREE_ALLOCBT_ACTIVE);
217221
}
218222

219223
/*
@@ -991,7 +995,7 @@ xfs_alloc_cur_check(
991995
deactivate = true;
992996
out:
993997
if (deactivate)
994-
cur->bc_ag.abt.active = false;
998+
cur->bc_flags &= ~XFS_BTREE_ALLOCBT_ACTIVE;
995999
trace_xfs_alloc_cur_check(args->mp, cur->bc_btnum, bno, len, diff,
9961000
*new);
9971001
return 0;
@@ -1366,7 +1370,7 @@ xfs_alloc_walk_iter(
13661370
if (error)
13671371
return error;
13681372
if (i == 0)
1369-
cur->bc_ag.abt.active = false;
1373+
cur->bc_flags &= ~XFS_BTREE_ALLOCBT_ACTIVE;
13701374

13711375
if (count > 0)
13721376
count--;
@@ -1480,7 +1484,7 @@ xfs_alloc_ag_vextent_locality(
14801484
if (error)
14811485
return error;
14821486
if (i) {
1483-
acur->cnt->bc_ag.abt.active = true;
1487+
acur->cnt->bc_flags |= XFS_BTREE_ALLOCBT_ACTIVE;
14841488
fbcur = acur->cnt;
14851489
fbinc = false;
14861490
}

fs/xfs/libxfs/xfs_alloc_btree.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,15 @@ xfs_allocbt_keys_contiguous(
454454
be32_to_cpu(key2->alloc.ar_startblock));
455455
}
456456

457-
static const struct xfs_btree_ops xfs_bnobt_ops = {
457+
const struct xfs_btree_ops xfs_bnobt_ops = {
458+
.type = XFS_BTREE_TYPE_AG,
459+
458460
.rec_len = sizeof(xfs_alloc_rec_t),
459461
.key_len = sizeof(xfs_alloc_key_t),
462+
.ptr_len = XFS_BTREE_SHORT_PTR_LEN,
463+
464+
.lru_refs = XFS_ALLOC_BTREE_REF,
465+
.statoff = XFS_STATS_CALC_INDEX(xs_abtb_2),
460466

461467
.dup_cursor = xfs_allocbt_dup_cursor,
462468
.set_root = xfs_allocbt_set_root,
@@ -477,9 +483,16 @@ static const struct xfs_btree_ops xfs_bnobt_ops = {
477483
.keys_contiguous = xfs_allocbt_keys_contiguous,
478484
};
479485

480-
static const struct xfs_btree_ops xfs_cntbt_ops = {
486+
const struct xfs_btree_ops xfs_cntbt_ops = {
487+
.type = XFS_BTREE_TYPE_AG,
488+
.geom_flags = XFS_BTGEO_LASTREC_UPDATE,
489+
481490
.rec_len = sizeof(xfs_alloc_rec_t),
482491
.key_len = sizeof(xfs_alloc_key_t),
492+
.ptr_len = XFS_BTREE_SHORT_PTR_LEN,
493+
494+
.lru_refs = XFS_ALLOC_BTREE_REF,
495+
.statoff = XFS_STATS_CALC_INDEX(xs_abtc_2),
483496

484497
.dup_cursor = xfs_allocbt_dup_cursor,
485498
.set_root = xfs_allocbt_set_root,
@@ -508,28 +521,17 @@ xfs_allocbt_init_common(
508521
struct xfs_perag *pag,
509522
xfs_btnum_t btnum)
510523
{
524+
const struct xfs_btree_ops *ops = &xfs_bnobt_ops;
511525
struct xfs_btree_cur *cur;
512526

513527
ASSERT(btnum == XFS_BTNUM_BNO || btnum == XFS_BTNUM_CNT);
514528

515-
cur = xfs_btree_alloc_cursor(mp, tp, btnum, mp->m_alloc_maxlevels,
516-
xfs_allocbt_cur_cache);
517-
cur->bc_ag.abt.active = false;
518-
519-
if (btnum == XFS_BTNUM_CNT) {
520-
cur->bc_ops = &xfs_cntbt_ops;
521-
cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_abtc_2);
522-
cur->bc_flags = XFS_BTREE_LASTREC_UPDATE;
523-
} else {
524-
cur->bc_ops = &xfs_bnobt_ops;
525-
cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_abtb_2);
526-
}
529+
if (btnum == XFS_BTNUM_CNT)
530+
ops = &xfs_cntbt_ops;
527531

532+
cur = xfs_btree_alloc_cursor(mp, tp, btnum, ops, mp->m_alloc_maxlevels,
533+
xfs_allocbt_cur_cache);
528534
cur->bc_ag.pag = xfs_perag_hold(pag);
529-
530-
if (xfs_has_crc(mp))
531-
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
532-
533535
return cur;
534536
}
535537

@@ -595,7 +597,6 @@ xfs_allocbt_commit_staged_btree(
595597
if (cur->bc_btnum == XFS_BTNUM_BNO) {
596598
xfs_btree_commit_afakeroot(cur, tp, agbp, &xfs_bnobt_ops);
597599
} else {
598-
cur->bc_flags |= XFS_BTREE_LASTREC_UPDATE;
599600
xfs_btree_commit_afakeroot(cur, tp, agbp, &xfs_cntbt_ops);
600601
}
601602
}

0 commit comments

Comments
 (0)