Skip to content

Commit 77a530e

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: add a generic group pointer to the btree cursor
Replace the pag pointers in the type specific union with a generic xfs_group pointer. This prepares for adding realtime group support. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent adbc76a commit 77a530e

23 files changed

+122
-137
lines changed

fs/xfs/libxfs/xfs_alloc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ xfs_alloc_complain_bad_rec(
275275

276276
xfs_warn(mp,
277277
"%sbt record corruption in AG %d detected at %pS!",
278-
cur->bc_ops->name, pag_agno(cur->bc_ag.pag), fa);
278+
cur->bc_ops->name, cur->bc_group->xg_gno, fa);
279279
xfs_warn(mp,
280280
"start block 0x%x block count 0x%x", irec->ar_startblock,
281281
irec->ar_blockcount);
@@ -303,7 +303,7 @@ xfs_alloc_get_rec(
303303
return error;
304304

305305
xfs_alloc_btrec_to_irec(rec, &irec);
306-
fa = xfs_alloc_check_irec(cur->bc_ag.pag, &irec);
306+
fa = xfs_alloc_check_irec(to_perag(cur->bc_group), &irec);
307307
if (fa)
308308
return xfs_alloc_complain_bad_rec(cur, fa, &irec);
309309

@@ -540,7 +540,7 @@ static int
540540
xfs_alloc_fixup_longest(
541541
struct xfs_btree_cur *cnt_cur)
542542
{
543-
struct xfs_perag *pag = cnt_cur->bc_ag.pag;
543+
struct xfs_perag *pag = to_perag(cnt_cur->bc_group);
544544
struct xfs_buf *bp = cnt_cur->bc_ag.agbp;
545545
struct xfs_agf *agf = bp->b_addr;
546546
xfs_extlen_t longest = 0;
@@ -4044,7 +4044,7 @@ xfs_alloc_query_range_helper(
40444044
xfs_failaddr_t fa;
40454045

40464046
xfs_alloc_btrec_to_irec(rec, &irec);
4047-
fa = xfs_alloc_check_irec(cur->bc_ag.pag, &irec);
4047+
fa = xfs_alloc_check_irec(to_perag(cur->bc_group), &irec);
40484048
if (fa)
40494049
return xfs_alloc_complain_bad_rec(cur, fa, &irec);
40504050

fs/xfs/libxfs/xfs_alloc_btree.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,37 @@ xfs_bnobt_dup_cursor(
2828
struct xfs_btree_cur *cur)
2929
{
3030
return xfs_bnobt_init_cursor(cur->bc_mp, cur->bc_tp, cur->bc_ag.agbp,
31-
cur->bc_ag.pag);
31+
to_perag(cur->bc_group));
3232
}
3333

3434
STATIC struct xfs_btree_cur *
3535
xfs_cntbt_dup_cursor(
3636
struct xfs_btree_cur *cur)
3737
{
3838
return xfs_cntbt_init_cursor(cur->bc_mp, cur->bc_tp, cur->bc_ag.agbp,
39-
cur->bc_ag.pag);
39+
to_perag(cur->bc_group));
4040
}
4141

42-
4342
STATIC void
4443
xfs_allocbt_set_root(
4544
struct xfs_btree_cur *cur,
4645
const union xfs_btree_ptr *ptr,
4746
int inc)
4847
{
49-
struct xfs_buf *agbp = cur->bc_ag.agbp;
50-
struct xfs_agf *agf = agbp->b_addr;
48+
struct xfs_perag *pag = to_perag(cur->bc_group);
49+
struct xfs_buf *agbp = cur->bc_ag.agbp;
50+
struct xfs_agf *agf = agbp->b_addr;
5151

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

5454
if (xfs_btree_is_bno(cur->bc_ops)) {
5555
agf->agf_bno_root = ptr->s;
5656
be32_add_cpu(&agf->agf_bno_level, inc);
57-
cur->bc_ag.pag->pagf_bno_level += inc;
57+
pag->pagf_bno_level += inc;
5858
} else {
5959
agf->agf_cnt_root = ptr->s;
6060
be32_add_cpu(&agf->agf_cnt_level, inc);
61-
cur->bc_ag.pag->pagf_cnt_level += inc;
61+
pag->pagf_cnt_level += inc;
6262
}
6363

6464
xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_ROOTS | XFS_AGF_LEVELS);
@@ -75,7 +75,7 @@ xfs_allocbt_alloc_block(
7575
xfs_agblock_t bno;
7676

7777
/* Allocate the new block from the freelist. If we can't, give up. */
78-
error = xfs_alloc_get_freelist(cur->bc_ag.pag, cur->bc_tp,
78+
error = xfs_alloc_get_freelist(to_perag(cur->bc_group), cur->bc_tp,
7979
cur->bc_ag.agbp, &bno, 1);
8080
if (error)
8181
return error;
@@ -86,7 +86,7 @@ xfs_allocbt_alloc_block(
8686
}
8787

8888
atomic64_inc(&cur->bc_mp->m_allocbt_blks);
89-
xfs_extent_busy_reuse(pag_group(cur->bc_ag.pag), bno, 1, false);
89+
xfs_extent_busy_reuse(cur->bc_group, bno, 1, false);
9090

9191
new->s = cpu_to_be32(bno);
9292

@@ -104,8 +104,8 @@ xfs_allocbt_free_block(
104104
int error;
105105

106106
bno = xfs_daddr_to_agbno(cur->bc_mp, xfs_buf_daddr(bp));
107-
error = xfs_alloc_put_freelist(cur->bc_ag.pag, cur->bc_tp, agbp, NULL,
108-
bno, 1);
107+
error = xfs_alloc_put_freelist(to_perag(cur->bc_group), cur->bc_tp,
108+
agbp, NULL, bno, 1);
109109
if (error)
110110
return error;
111111

@@ -178,7 +178,7 @@ xfs_allocbt_init_ptr_from_cur(
178178
{
179179
struct xfs_agf *agf = cur->bc_ag.agbp->b_addr;
180180

181-
ASSERT(pag_agno(cur->bc_ag.pag) == be32_to_cpu(agf->agf_seqno));
181+
ASSERT(cur->bc_group->xg_gno == be32_to_cpu(agf->agf_seqno));
182182

183183
if (xfs_btree_is_bno(cur->bc_ops))
184184
ptr->s = agf->agf_bno_root;
@@ -492,7 +492,7 @@ xfs_bnobt_init_cursor(
492492

493493
cur = xfs_btree_alloc_cursor(mp, tp, &xfs_bnobt_ops,
494494
mp->m_alloc_maxlevels, xfs_allocbt_cur_cache);
495-
cur->bc_ag.pag = xfs_perag_hold(pag);
495+
cur->bc_group = xfs_group_hold(pag_group(pag));
496496
cur->bc_ag.agbp = agbp;
497497
if (agbp) {
498498
struct xfs_agf *agf = agbp->b_addr;
@@ -518,7 +518,7 @@ xfs_cntbt_init_cursor(
518518

519519
cur = xfs_btree_alloc_cursor(mp, tp, &xfs_cntbt_ops,
520520
mp->m_alloc_maxlevels, xfs_allocbt_cur_cache);
521-
cur->bc_ag.pag = xfs_perag_hold(pag);
521+
cur->bc_group = xfs_group_hold(pag_group(pag));
522522
cur->bc_ag.agbp = agbp;
523523
if (agbp) {
524524
struct xfs_agf *agf = agbp->b_addr;

fs/xfs/libxfs/xfs_btree.c

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ __xfs_btree_check_agblock(
225225
struct xfs_buf *bp)
226226
{
227227
struct xfs_mount *mp = cur->bc_mp;
228-
struct xfs_perag *pag = cur->bc_ag.pag;
228+
struct xfs_perag *pag = to_perag(cur->bc_group);
229229
xfs_failaddr_t fa;
230230
xfs_agblock_t agbno;
231231

@@ -331,7 +331,7 @@ __xfs_btree_check_ptr(
331331
return -EFSCORRUPTED;
332332
break;
333333
case XFS_BTREE_TYPE_AG:
334-
if (!xfs_verify_agbno(cur->bc_ag.pag,
334+
if (!xfs_verify_agbno(to_perag(cur->bc_group),
335335
be32_to_cpu((&ptr->s)[index])))
336336
return -EFSCORRUPTED;
337337
break;
@@ -372,7 +372,7 @@ xfs_btree_check_ptr(
372372
case XFS_BTREE_TYPE_AG:
373373
xfs_err(cur->bc_mp,
374374
"AG %u: Corrupt %sbt pointer at level %d index %d.",
375-
pag_agno(cur->bc_ag.pag), cur->bc_ops->name,
375+
cur->bc_group->xg_gno, cur->bc_ops->name,
376376
level, index);
377377
break;
378378
}
@@ -523,20 +523,8 @@ xfs_btree_del_cursor(
523523
ASSERT(!xfs_btree_is_bmap(cur->bc_ops) || cur->bc_bmap.allocated == 0 ||
524524
xfs_is_shutdown(cur->bc_mp) || error != 0);
525525

526-
switch (cur->bc_ops->type) {
527-
case XFS_BTREE_TYPE_AG:
528-
if (cur->bc_ag.pag)
529-
xfs_perag_put(cur->bc_ag.pag);
530-
break;
531-
case XFS_BTREE_TYPE_INODE:
532-
/* nothing to do */
533-
break;
534-
case XFS_BTREE_TYPE_MEM:
535-
if (cur->bc_mem.pag)
536-
xfs_perag_put(cur->bc_mem.pag);
537-
break;
538-
}
539-
526+
if (cur->bc_group)
527+
xfs_group_put(cur->bc_group);
540528
kmem_cache_free(cur->bc_cache, cur);
541529
}
542530

@@ -1017,21 +1005,22 @@ xfs_btree_readahead_agblock(
10171005
struct xfs_btree_block *block)
10181006
{
10191007
struct xfs_mount *mp = cur->bc_mp;
1008+
struct xfs_perag *pag = to_perag(cur->bc_group);
10201009
xfs_agblock_t left = be32_to_cpu(block->bb_u.s.bb_leftsib);
10211010
xfs_agblock_t right = be32_to_cpu(block->bb_u.s.bb_rightsib);
10221011
int rval = 0;
10231012

10241013
if ((lr & XFS_BTCUR_LEFTRA) && left != NULLAGBLOCK) {
10251014
xfs_buf_readahead(mp->m_ddev_targp,
1026-
xfs_agbno_to_daddr(cur->bc_ag.pag, left),
1027-
mp->m_bsize, cur->bc_ops->buf_ops);
1015+
xfs_agbno_to_daddr(pag, left), mp->m_bsize,
1016+
cur->bc_ops->buf_ops);
10281017
rval++;
10291018
}
10301019

10311020
if ((lr & XFS_BTCUR_RIGHTRA) && right != NULLAGBLOCK) {
10321021
xfs_buf_readahead(mp->m_ddev_targp,
1033-
xfs_agbno_to_daddr(cur->bc_ag.pag, right),
1034-
mp->m_bsize, cur->bc_ops->buf_ops);
1022+
xfs_agbno_to_daddr(pag, right), mp->m_bsize,
1023+
cur->bc_ops->buf_ops);
10351024
rval++;
10361025
}
10371026

@@ -1090,7 +1079,7 @@ xfs_btree_ptr_to_daddr(
10901079

10911080
switch (cur->bc_ops->type) {
10921081
case XFS_BTREE_TYPE_AG:
1093-
*daddr = xfs_agbno_to_daddr(cur->bc_ag.pag,
1082+
*daddr = xfs_agbno_to_daddr(to_perag(cur->bc_group),
10941083
be32_to_cpu(ptr->s));
10951084
break;
10961085
case XFS_BTREE_TYPE_INODE:
@@ -1312,7 +1301,7 @@ xfs_btree_owner(
13121301
case XFS_BTREE_TYPE_INODE:
13131302
return cur->bc_ino.ip->i_ino;
13141303
case XFS_BTREE_TYPE_AG:
1315-
return pag_agno(cur->bc_ag.pag);
1304+
return cur->bc_group->xg_gno;
13161305
default:
13171306
ASSERT(0);
13181307
return 0;

fs/xfs/libxfs/xfs_btree.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ struct xfs_btree_cur
254254
union xfs_btree_irec bc_rec; /* current insert/search record value */
255255
uint8_t bc_nlevels; /* number of levels in the tree */
256256
uint8_t bc_maxlevels; /* maximum levels for this btree type */
257+
struct xfs_group *bc_group;
257258

258259
/* per-type information */
259260
union {
@@ -264,13 +265,11 @@ struct xfs_btree_cur
264265
struct xbtree_ifakeroot *ifake; /* for staging cursor */
265266
} bc_ino;
266267
struct {
267-
struct xfs_perag *pag;
268268
struct xfs_buf *agbp;
269269
struct xbtree_afakeroot *afake; /* for staging cursor */
270270
} bc_ag;
271271
struct {
272272
struct xfbtree *xfbtree;
273-
struct xfs_perag *pag;
274273
} bc_mem;
275274
};
276275

fs/xfs/libxfs/xfs_btree_mem.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ xfbtree_dup_cursor(
5757
ncur->bc_flags = cur->bc_flags;
5858
ncur->bc_nlevels = cur->bc_nlevels;
5959
ncur->bc_mem.xfbtree = cur->bc_mem.xfbtree;
60-
61-
if (cur->bc_mem.pag)
62-
ncur->bc_mem.pag = xfs_perag_hold(cur->bc_mem.pag);
63-
60+
if (cur->bc_group)
61+
ncur->bc_group = xfs_group_hold(cur->bc_group);
6462
return ncur;
6563
}
6664

fs/xfs/libxfs/xfs_ialloc.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ xfs_inobt_complain_bad_rec(
142142

143143
xfs_warn(mp,
144144
"%sbt record corruption in AG %d detected at %pS!",
145-
cur->bc_ops->name, pag_agno(cur->bc_ag.pag), fa);
145+
cur->bc_ops->name, cur->bc_group->xg_gno, fa);
146146
xfs_warn(mp,
147147
"start inode 0x%x, count 0x%x, free 0x%x freemask 0x%llx, holemask 0x%x",
148148
irec->ir_startino, irec->ir_count, irec->ir_freecount,
@@ -170,7 +170,7 @@ xfs_inobt_get_rec(
170170
return error;
171171

172172
xfs_inobt_btrec_to_irec(mp, rec, irec);
173-
fa = xfs_inobt_check_irec(cur->bc_ag.pag, irec);
173+
fa = xfs_inobt_check_irec(to_perag(cur->bc_group), irec);
174174
if (fa)
175175
return xfs_inobt_complain_bad_rec(cur, fa, irec);
176176

@@ -275,8 +275,10 @@ xfs_check_agi_freecount(
275275
}
276276
} while (i == 1);
277277

278-
if (!xfs_is_shutdown(cur->bc_mp))
279-
ASSERT(freecount == cur->bc_ag.pag->pagi_freecount);
278+
if (!xfs_is_shutdown(cur->bc_mp)) {
279+
ASSERT(freecount ==
280+
to_perag(cur->bc_group)->pagi_freecount);
281+
}
280282
}
281283
return 0;
282284
}
@@ -2880,7 +2882,7 @@ xfs_ialloc_count_inodes_rec(
28802882
xfs_failaddr_t fa;
28812883

28822884
xfs_inobt_btrec_to_irec(cur->bc_mp, rec, &irec);
2883-
fa = xfs_inobt_check_irec(cur->bc_ag.pag, &irec);
2885+
fa = xfs_inobt_check_irec(to_perag(cur->bc_group), &irec);
28842886
if (fa)
28852887
return xfs_inobt_complain_bad_rec(cur, fa, &irec);
28862888

fs/xfs/libxfs/xfs_ialloc_btree.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ STATIC struct xfs_btree_cur *
3737
xfs_inobt_dup_cursor(
3838
struct xfs_btree_cur *cur)
3939
{
40-
return xfs_inobt_init_cursor(cur->bc_ag.pag, cur->bc_tp,
40+
return xfs_inobt_init_cursor(to_perag(cur->bc_group), cur->bc_tp,
4141
cur->bc_ag.agbp);
4242
}
4343

4444
STATIC struct xfs_btree_cur *
4545
xfs_finobt_dup_cursor(
4646
struct xfs_btree_cur *cur)
4747
{
48-
return xfs_finobt_init_cursor(cur->bc_ag.pag, cur->bc_tp,
48+
return xfs_finobt_init_cursor(to_perag(cur->bc_group), cur->bc_tp,
4949
cur->bc_ag.agbp);
5050
}
5151

@@ -112,7 +112,7 @@ __xfs_inobt_alloc_block(
112112
memset(&args, 0, sizeof(args));
113113
args.tp = cur->bc_tp;
114114
args.mp = cur->bc_mp;
115-
args.pag = cur->bc_ag.pag;
115+
args.pag = to_perag(cur->bc_group);
116116
args.oinfo = XFS_RMAP_OINFO_INOBT;
117117
args.minlen = 1;
118118
args.maxlen = 1;
@@ -248,7 +248,7 @@ xfs_inobt_init_ptr_from_cur(
248248
{
249249
struct xfs_agi *agi = cur->bc_ag.agbp->b_addr;
250250

251-
ASSERT(pag_agno(cur->bc_ag.pag) == be32_to_cpu(agi->agi_seqno));
251+
ASSERT(cur->bc_group->xg_gno == be32_to_cpu(agi->agi_seqno));
252252

253253
ptr->s = agi->agi_root;
254254
}
@@ -260,7 +260,8 @@ xfs_finobt_init_ptr_from_cur(
260260
{
261261
struct xfs_agi *agi = cur->bc_ag.agbp->b_addr;
262262

263-
ASSERT(pag_agno(cur->bc_ag.pag) == be32_to_cpu(agi->agi_seqno));
263+
ASSERT(cur->bc_group->xg_gno == be32_to_cpu(agi->agi_seqno));
264+
264265
ptr->s = agi->agi_free_root;
265266
}
266267

@@ -483,7 +484,7 @@ xfs_inobt_init_cursor(
483484

484485
cur = xfs_btree_alloc_cursor(mp, tp, &xfs_inobt_ops,
485486
M_IGEO(mp)->inobt_maxlevels, xfs_inobt_cur_cache);
486-
cur->bc_ag.pag = xfs_perag_hold(pag);
487+
cur->bc_group = xfs_group_hold(pag_group(pag));
487488
cur->bc_ag.agbp = agbp;
488489
if (agbp) {
489490
struct xfs_agi *agi = agbp->b_addr;
@@ -509,7 +510,7 @@ xfs_finobt_init_cursor(
509510

510511
cur = xfs_btree_alloc_cursor(mp, tp, &xfs_finobt_ops,
511512
M_IGEO(mp)->inobt_maxlevels, xfs_inobt_cur_cache);
512-
cur->bc_ag.pag = xfs_perag_hold(pag);
513+
cur->bc_group = xfs_group_hold(pag_group(pag));
513514
cur->bc_ag.agbp = agbp;
514515
if (agbp) {
515516
struct xfs_agi *agi = agbp->b_addr;

0 commit comments

Comments
 (0)