Skip to content

Commit 88ee2f4

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: split the per-btree union in struct xfs_btree_cur
Split up the union that encodes btree-specific fields in struct xfs_btree_cur. Most fields in there are specific to the btree type encoded in xfs_btree_ops.type, and we can use the obviously named union for that. But one field is specific to the bmapbt and two are shared by the refcount and rtrefcountbt. Move those to a separate union to make the usage clear and not need a separate struct for the refcount-related fields. This will also make unnecessary some very awkward btree cursor refc/rtrefc switching logic in the rtrefcount patchset. 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 4f0cd5a commit 88ee2f4

7 files changed

Lines changed: 54 additions & 63 deletions

File tree

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ xfs_bmap_extents_to_btree(
676676
goto out_root_realloc;
677677
}
678678

679-
cur->bc_ino.allocated++;
679+
cur->bc_bmap.allocated++;
680680
ip->i_nblocks++;
681681
xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, 1L);
682682
error = xfs_trans_get_buf(tp, mp->m_ddev_targp,
@@ -894,7 +894,7 @@ xfs_bmap_add_attrfork_btree(
894894
xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
895895
return -ENOSPC;
896896
}
897-
cur->bc_ino.allocated = 0;
897+
cur->bc_bmap.allocated = 0;
898898
xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
899899
}
900900
return 0;
@@ -922,7 +922,7 @@ xfs_bmap_add_attrfork_extents(
922922
error = xfs_bmap_extents_to_btree(tp, ip, &cur, 0, flags,
923923
XFS_DATA_FORK);
924924
if (cur) {
925-
cur->bc_ino.allocated = 0;
925+
cur->bc_bmap.allocated = 0;
926926
xfs_btree_del_cursor(cur, error);
927927
}
928928
return error;
@@ -1746,7 +1746,7 @@ xfs_bmap_add_extent_delay_real(
17461746
temp = PREV.br_blockcount - new->br_blockcount;
17471747
da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
17481748
startblockval(PREV.br_startblock) -
1749-
(bma->cur ? bma->cur->bc_ino.allocated : 0));
1749+
(bma->cur ? bma->cur->bc_bmap.allocated : 0));
17501750

17511751
PREV.br_startoff = new_endoff;
17521752
PREV.br_blockcount = temp;
@@ -1836,7 +1836,7 @@ xfs_bmap_add_extent_delay_real(
18361836
temp = PREV.br_blockcount - new->br_blockcount;
18371837
da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
18381838
startblockval(PREV.br_startblock) -
1839-
(bma->cur ? bma->cur->bc_ino.allocated : 0));
1839+
(bma->cur ? bma->cur->bc_bmap.allocated : 0));
18401840

18411841
PREV.br_startblock = nullstartblock(da_new);
18421842
PREV.br_blockcount = temp;
@@ -1959,8 +1959,8 @@ xfs_bmap_add_extent_delay_real(
19591959
xfs_mod_delalloc(mp, (int64_t)da_new - da_old);
19601960

19611961
if (bma->cur) {
1962-
da_new += bma->cur->bc_ino.allocated;
1963-
bma->cur->bc_ino.allocated = 0;
1962+
da_new += bma->cur->bc_bmap.allocated;
1963+
bma->cur->bc_bmap.allocated = 0;
19641964
}
19651965

19661966
/* adjust for changes in reserved delayed indirect blocks */
@@ -2525,7 +2525,7 @@ xfs_bmap_add_extent_unwritten_real(
25252525

25262526
/* clear out the allocated field, done with it now in any case. */
25272527
if (cur) {
2528-
cur->bc_ino.allocated = 0;
2528+
cur->bc_bmap.allocated = 0;
25292529
*curp = cur;
25302530
}
25312531

@@ -2913,7 +2913,7 @@ xfs_bmap_add_extent_hole_real(
29132913

29142914
/* clear out the allocated field, done with it now in any case. */
29152915
if (cur)
2916-
cur->bc_ino.allocated = 0;
2916+
cur->bc_bmap.allocated = 0;
29172917

29182918
xfs_bmap_check_leaf_extents(cur, ip, whichfork);
29192919
done:
@@ -5629,7 +5629,7 @@ __xfs_bunmapi(
56295629
xfs_trans_log_inode(tp, ip, logflags);
56305630
if (cur) {
56315631
if (!error)
5632-
cur->bc_ino.allocated = 0;
5632+
cur->bc_bmap.allocated = 0;
56335633
xfs_btree_del_cursor(cur, error);
56345634
}
56355635
return error;
@@ -6145,7 +6145,7 @@ xfs_bmap_split_extent(
61456145

61466146
del_cursor:
61476147
if (cur) {
6148-
cur->bc_ino.allocated = 0;
6148+
cur->bc_bmap.allocated = 0;
61496149
xfs_btree_del_cursor(cur, error);
61506150
}
61516151

fs/xfs/libxfs/xfs_bmap_btree.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ xfs_bmbt_update_cursor(
198198
ASSERT((dst->bc_tp->t_highest_agno != NULLAGNUMBER) ||
199199
(dst->bc_ino.ip->i_diflags & XFS_DIFLAG_REALTIME));
200200

201-
dst->bc_ino.allocated += src->bc_ino.allocated;
201+
dst->bc_bmap.allocated += src->bc_bmap.allocated;
202202
dst->bc_tp->t_highest_agno = src->bc_tp->t_highest_agno;
203203

204-
src->bc_ino.allocated = 0;
204+
src->bc_bmap.allocated = 0;
205205
}
206206

207207
STATIC int
@@ -256,7 +256,7 @@ xfs_bmbt_alloc_block(
256256
}
257257

258258
ASSERT(args.len == 1);
259-
cur->bc_ino.allocated++;
259+
cur->bc_bmap.allocated++;
260260
cur->bc_ino.ip->i_nblocks++;
261261
xfs_trans_log_inode(args.tp, cur->bc_ino.ip, XFS_ILOG_CORE);
262262
xfs_trans_mod_dquot_byino(args.tp, cur->bc_ino.ip,
@@ -568,8 +568,7 @@ xfs_bmbt_init_common(
568568
mp->m_bm_maxlevels[whichfork], xfs_bmbt_cur_cache);
569569

570570
cur->bc_ino.ip = ip;
571-
cur->bc_ino.allocated = 0;
572-
571+
cur->bc_bmap.allocated = 0;
573572
return cur;
574573
}
575574

fs/xfs/libxfs/xfs_btree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ xfs_btree_del_cursor(
445445
* zero, then we should be shut down or on our way to shutdown due to
446446
* cancelling a dirty transaction on error.
447447
*/
448-
ASSERT(cur->bc_btnum != XFS_BTNUM_BMAP || cur->bc_ino.allocated == 0 ||
448+
ASSERT(cur->bc_btnum != XFS_BTNUM_BMAP || cur->bc_bmap.allocated == 0 ||
449449
xfs_is_shutdown(cur->bc_mp) || error != 0);
450450

451451
switch (cur->bc_ops->type) {

fs/xfs/libxfs/xfs_btree.h

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -243,30 +243,6 @@ union xfs_btree_irec {
243243
struct xfs_refcount_irec rc;
244244
};
245245

246-
/* Per-AG btree information. */
247-
struct xfs_btree_cur_ag {
248-
struct xfs_perag *pag;
249-
union {
250-
struct xfs_buf *agbp;
251-
struct xbtree_afakeroot *afake; /* for staging cursor */
252-
};
253-
union {
254-
struct {
255-
unsigned int nr_ops; /* # record updates */
256-
unsigned int shape_changes; /* # of extent splits */
257-
} refc;
258-
};
259-
};
260-
261-
/* Btree-in-inode cursor information */
262-
struct xfs_btree_cur_ino {
263-
struct xfs_inode *ip;
264-
struct xbtree_ifakeroot *ifake; /* for staging cursor */
265-
int allocated;
266-
short forksize;
267-
char whichfork;
268-
};
269-
270246
struct xfs_btree_level {
271247
/* buffer pointer */
272248
struct xfs_buf *bp;
@@ -296,15 +272,30 @@ struct xfs_btree_cur
296272
uint8_t bc_nlevels; /* number of levels in the tree */
297273
uint8_t bc_maxlevels; /* maximum levels for this btree type */
298274

299-
/*
300-
* Short btree pointers need an agno to be able to turn the pointers
301-
* into physical addresses for IO, so the btree cursor switches between
302-
* bc_ino and bc_ag based on bc_ops->type.
303-
* the cursor.
304-
*/
275+
/* per-type information */
276+
union {
277+
struct {
278+
struct xfs_inode *ip;
279+
short forksize;
280+
char whichfork;
281+
struct xbtree_ifakeroot *ifake; /* for staging cursor */
282+
} bc_ino;
283+
struct {
284+
struct xfs_perag *pag;
285+
struct xfs_buf *agbp;
286+
struct xbtree_afakeroot *afake; /* for staging cursor */
287+
} bc_ag;
288+
};
289+
290+
/* per-format private data */
305291
union {
306-
struct xfs_btree_cur_ag bc_ag;
307-
struct xfs_btree_cur_ino bc_ino;
292+
struct {
293+
int allocated;
294+
} bc_bmap; /* bmapbt */
295+
struct {
296+
unsigned int nr_ops; /* # record updates */
297+
unsigned int shape_changes; /* # of extent splits */
298+
} bc_refc; /* refcountbt */
308299
};
309300

310301
/* Must be at the end of the struct! */

fs/xfs/libxfs/xfs_btree_staging.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ xfs_btree_commit_afakeroot(
172172
trace_xfs_btree_commit_afakeroot(cur);
173173

174174
kfree((void *)cur->bc_ops);
175+
cur->bc_ag.afake = NULL;
175176
cur->bc_ag.agbp = agbp;
176177
cur->bc_ops = ops;
177178
cur->bc_flags &= ~XFS_BTREE_STAGING;

fs/xfs/libxfs/xfs_refcount.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,25 +1077,25 @@ xfs_refcount_still_have_space(
10771077
* to handle each of the shape changes to the refcount btree.
10781078
*/
10791079
overhead = xfs_allocfree_block_count(cur->bc_mp,
1080-
cur->bc_ag.refc.shape_changes);
1080+
cur->bc_refc.shape_changes);
10811081
overhead += cur->bc_mp->m_refc_maxlevels;
10821082
overhead *= cur->bc_mp->m_sb.sb_blocksize;
10831083

10841084
/*
10851085
* Only allow 2 refcount extent updates per transaction if the
10861086
* refcount continue update "error" has been injected.
10871087
*/
1088-
if (cur->bc_ag.refc.nr_ops > 2 &&
1088+
if (cur->bc_refc.nr_ops > 2 &&
10891089
XFS_TEST_ERROR(false, cur->bc_mp,
10901090
XFS_ERRTAG_REFCOUNT_CONTINUE_UPDATE))
10911091
return false;
10921092

1093-
if (cur->bc_ag.refc.nr_ops == 0)
1093+
if (cur->bc_refc.nr_ops == 0)
10941094
return true;
10951095
else if (overhead > cur->bc_tp->t_log_res)
10961096
return false;
1097-
return cur->bc_tp->t_log_res - overhead >
1098-
cur->bc_ag.refc.nr_ops * XFS_REFCOUNT_ITEM_OVERHEAD;
1097+
return cur->bc_tp->t_log_res - overhead >
1098+
cur->bc_refc.nr_ops * XFS_REFCOUNT_ITEM_OVERHEAD;
10991099
}
11001100

11011101
/*
@@ -1155,7 +1155,7 @@ xfs_refcount_adjust_extents(
11551155
* Either cover the hole (increment) or
11561156
* delete the range (decrement).
11571157
*/
1158-
cur->bc_ag.refc.nr_ops++;
1158+
cur->bc_refc.nr_ops++;
11591159
if (tmp.rc_refcount) {
11601160
error = xfs_refcount_insert(cur, &tmp,
11611161
&found_tmp);
@@ -1216,7 +1216,7 @@ xfs_refcount_adjust_extents(
12161216
ext.rc_refcount += adj;
12171217
trace_xfs_refcount_modify_extent(cur->bc_mp,
12181218
cur->bc_ag.pag->pag_agno, &ext);
1219-
cur->bc_ag.refc.nr_ops++;
1219+
cur->bc_refc.nr_ops++;
12201220
if (ext.rc_refcount > 1) {
12211221
error = xfs_refcount_update(cur, &ext);
12221222
if (error)
@@ -1305,7 +1305,7 @@ xfs_refcount_adjust(
13051305
if (shape_changed)
13061306
shape_changes++;
13071307
if (shape_changes)
1308-
cur->bc_ag.refc.shape_changes++;
1308+
cur->bc_refc.shape_changes++;
13091309

13101310
/* Now that we've taken care of the ends, adjust the middle extents */
13111311
error = xfs_refcount_adjust_extents(cur, agbno, aglen, adj);
@@ -1400,8 +1400,8 @@ xfs_refcount_finish_one(
14001400
*/
14011401
rcur = *pcur;
14021402
if (rcur != NULL && rcur->bc_ag.pag != ri->ri_pag) {
1403-
nr_ops = rcur->bc_ag.refc.nr_ops;
1404-
shape_changes = rcur->bc_ag.refc.shape_changes;
1403+
nr_ops = rcur->bc_refc.nr_ops;
1404+
shape_changes = rcur->bc_refc.shape_changes;
14051405
xfs_refcount_finish_one_cleanup(tp, rcur, 0);
14061406
rcur = NULL;
14071407
*pcur = NULL;
@@ -1413,8 +1413,8 @@ xfs_refcount_finish_one(
14131413
return error;
14141414

14151415
rcur = xfs_refcountbt_init_cursor(mp, tp, agbp, ri->ri_pag);
1416-
rcur->bc_ag.refc.nr_ops = nr_ops;
1417-
rcur->bc_ag.refc.shape_changes = shape_changes;
1416+
rcur->bc_refc.nr_ops = nr_ops;
1417+
rcur->bc_refc.shape_changes = shape_changes;
14181418
}
14191419
*pcur = rcur;
14201420

fs/xfs/libxfs/xfs_refcount_btree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ xfs_refcountbt_init_common(
362362
&xfs_refcountbt_ops, mp->m_refc_maxlevels,
363363
xfs_refcountbt_cur_cache);
364364
cur->bc_ag.pag = xfs_perag_hold(pag);
365-
cur->bc_ag.refc.nr_ops = 0;
366-
cur->bc_ag.refc.shape_changes = 0;
365+
cur->bc_refc.nr_ops = 0;
366+
cur->bc_refc.shape_changes = 0;
367367
return cur;
368368
}
369369

0 commit comments

Comments
 (0)