Skip to content

Commit 0b11553

Browse files
author
Darrick J. Wong
committed
xfs: pass refcount intent directly through the log intent code
Pass the incore refcount intent through the CUI logging code instead of repeatedly boxing and unboxing parameters. Signed-off-by: Darrick J. Wong <[email protected]>
1 parent ffaa196 commit 0b11553

File tree

4 files changed

+74
-103
lines changed

4 files changed

+74
-103
lines changed

fs/xfs/libxfs/xfs_refcount.c

Lines changed: 43 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,37 +1213,33 @@ xfs_refcount_adjust_extents(
12131213
STATIC int
12141214
xfs_refcount_adjust(
12151215
struct xfs_btree_cur *cur,
1216-
xfs_agblock_t agbno,
1217-
xfs_extlen_t aglen,
1218-
xfs_agblock_t *new_agbno,
1219-
xfs_extlen_t *new_aglen,
1216+
xfs_agblock_t *agbno,
1217+
xfs_extlen_t *aglen,
12201218
enum xfs_refc_adjust_op adj)
12211219
{
12221220
bool shape_changed;
12231221
int shape_changes = 0;
12241222
int error;
12251223

1226-
*new_agbno = agbno;
1227-
*new_aglen = aglen;
12281224
if (adj == XFS_REFCOUNT_ADJUST_INCREASE)
1229-
trace_xfs_refcount_increase(cur->bc_mp, cur->bc_ag.pag->pag_agno,
1230-
agbno, aglen);
1225+
trace_xfs_refcount_increase(cur->bc_mp,
1226+
cur->bc_ag.pag->pag_agno, *agbno, *aglen);
12311227
else
1232-
trace_xfs_refcount_decrease(cur->bc_mp, cur->bc_ag.pag->pag_agno,
1233-
agbno, aglen);
1228+
trace_xfs_refcount_decrease(cur->bc_mp,
1229+
cur->bc_ag.pag->pag_agno, *agbno, *aglen);
12341230

12351231
/*
12361232
* Ensure that no rcextents cross the boundary of the adjustment range.
12371233
*/
12381234
error = xfs_refcount_split_extent(cur, XFS_REFC_DOMAIN_SHARED,
1239-
agbno, &shape_changed);
1235+
*agbno, &shape_changed);
12401236
if (error)
12411237
goto out_error;
12421238
if (shape_changed)
12431239
shape_changes++;
12441240

12451241
error = xfs_refcount_split_extent(cur, XFS_REFC_DOMAIN_SHARED,
1246-
agbno + aglen, &shape_changed);
1242+
*agbno + *aglen, &shape_changed);
12471243
if (error)
12481244
goto out_error;
12491245
if (shape_changed)
@@ -1253,7 +1249,7 @@ xfs_refcount_adjust(
12531249
* Try to merge with the left or right extents of the range.
12541250
*/
12551251
error = xfs_refcount_merge_extents(cur, XFS_REFC_DOMAIN_SHARED,
1256-
new_agbno, new_aglen, adj, &shape_changed);
1252+
agbno, aglen, adj, &shape_changed);
12571253
if (error)
12581254
goto out_error;
12591255
if (shape_changed)
@@ -1262,7 +1258,7 @@ xfs_refcount_adjust(
12621258
cur->bc_ag.refc.shape_changes++;
12631259

12641260
/* Now that we've taken care of the ends, adjust the middle extents */
1265-
error = xfs_refcount_adjust_extents(cur, new_agbno, new_aglen, adj);
1261+
error = xfs_refcount_adjust_extents(cur, agbno, aglen, adj);
12661262
if (error)
12671263
goto out_error;
12681264

@@ -1298,21 +1294,20 @@ xfs_refcount_finish_one_cleanup(
12981294
static inline int
12991295
xfs_refcount_continue_op(
13001296
struct xfs_btree_cur *cur,
1301-
xfs_fsblock_t startblock,
1302-
xfs_agblock_t new_agbno,
1303-
xfs_extlen_t new_len,
1304-
xfs_fsblock_t *new_fsbno)
1297+
struct xfs_refcount_intent *ri,
1298+
xfs_agblock_t new_agbno)
13051299
{
13061300
struct xfs_mount *mp = cur->bc_mp;
13071301
struct xfs_perag *pag = cur->bc_ag.pag;
13081302

1309-
if (XFS_IS_CORRUPT(mp, !xfs_verify_agbext(pag, new_agbno, new_len)))
1303+
if (XFS_IS_CORRUPT(mp, !xfs_verify_agbext(pag, new_agbno,
1304+
ri->ri_blockcount)))
13101305
return -EFSCORRUPTED;
13111306

1312-
*new_fsbno = XFS_AGB_TO_FSB(mp, pag->pag_agno, new_agbno);
1307+
ri->ri_startblock = XFS_AGB_TO_FSB(mp, pag->pag_agno, new_agbno);
13131308

1314-
ASSERT(xfs_verify_fsbext(mp, *new_fsbno, new_len));
1315-
ASSERT(pag->pag_agno == XFS_FSB_TO_AGNO(mp, *new_fsbno));
1309+
ASSERT(xfs_verify_fsbext(mp, ri->ri_startblock, ri->ri_blockcount));
1310+
ASSERT(pag->pag_agno == XFS_FSB_TO_AGNO(mp, ri->ri_startblock));
13161311

13171312
return 0;
13181313
}
@@ -1327,29 +1322,24 @@ xfs_refcount_continue_op(
13271322
int
13281323
xfs_refcount_finish_one(
13291324
struct xfs_trans *tp,
1330-
enum xfs_refcount_intent_type type,
1331-
xfs_fsblock_t startblock,
1332-
xfs_extlen_t blockcount,
1333-
xfs_fsblock_t *new_fsb,
1334-
xfs_extlen_t *new_len,
1325+
struct xfs_refcount_intent *ri,
13351326
struct xfs_btree_cur **pcur)
13361327
{
13371328
struct xfs_mount *mp = tp->t_mountp;
13381329
struct xfs_btree_cur *rcur;
13391330
struct xfs_buf *agbp = NULL;
13401331
int error = 0;
13411332
xfs_agblock_t bno;
1342-
xfs_agblock_t new_agbno;
13431333
unsigned long nr_ops = 0;
13441334
int shape_changes = 0;
13451335
struct xfs_perag *pag;
13461336

1347-
pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, startblock));
1348-
bno = XFS_FSB_TO_AGBNO(mp, startblock);
1337+
pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, ri->ri_startblock));
1338+
bno = XFS_FSB_TO_AGBNO(mp, ri->ri_startblock);
13491339

1350-
trace_xfs_refcount_deferred(mp, XFS_FSB_TO_AGNO(mp, startblock),
1351-
type, XFS_FSB_TO_AGBNO(mp, startblock),
1352-
blockcount);
1340+
trace_xfs_refcount_deferred(mp, XFS_FSB_TO_AGNO(mp, ri->ri_startblock),
1341+
ri->ri_type, XFS_FSB_TO_AGBNO(mp, ri->ri_startblock),
1342+
ri->ri_blockcount);
13531343

13541344
if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_REFCOUNT_FINISH_ONE)) {
13551345
error = -EIO;
@@ -1380,42 +1370,42 @@ xfs_refcount_finish_one(
13801370
}
13811371
*pcur = rcur;
13821372

1383-
switch (type) {
1373+
switch (ri->ri_type) {
13841374
case XFS_REFCOUNT_INCREASE:
1385-
error = xfs_refcount_adjust(rcur, bno, blockcount, &new_agbno,
1386-
new_len, XFS_REFCOUNT_ADJUST_INCREASE);
1375+
error = xfs_refcount_adjust(rcur, &bno, &ri->ri_blockcount,
1376+
XFS_REFCOUNT_ADJUST_INCREASE);
13871377
if (error)
13881378
goto out_drop;
1389-
if (*new_len > 0)
1390-
error = xfs_refcount_continue_op(rcur, startblock,
1391-
new_agbno, *new_len, new_fsb);
1379+
if (ri->ri_blockcount > 0)
1380+
error = xfs_refcount_continue_op(rcur, ri, bno);
13921381
break;
13931382
case XFS_REFCOUNT_DECREASE:
1394-
error = xfs_refcount_adjust(rcur, bno, blockcount, &new_agbno,
1395-
new_len, XFS_REFCOUNT_ADJUST_DECREASE);
1383+
error = xfs_refcount_adjust(rcur, &bno, &ri->ri_blockcount,
1384+
XFS_REFCOUNT_ADJUST_DECREASE);
13961385
if (error)
13971386
goto out_drop;
1398-
if (*new_len > 0)
1399-
error = xfs_refcount_continue_op(rcur, startblock,
1400-
new_agbno, *new_len, new_fsb);
1387+
if (ri->ri_blockcount > 0)
1388+
error = xfs_refcount_continue_op(rcur, ri, bno);
14011389
break;
14021390
case XFS_REFCOUNT_ALLOC_COW:
1403-
*new_fsb = startblock + blockcount;
1404-
*new_len = 0;
1405-
error = __xfs_refcount_cow_alloc(rcur, bno, blockcount);
1391+
error = __xfs_refcount_cow_alloc(rcur, bno, ri->ri_blockcount);
1392+
if (error)
1393+
goto out_drop;
1394+
ri->ri_blockcount = 0;
14061395
break;
14071396
case XFS_REFCOUNT_FREE_COW:
1408-
*new_fsb = startblock + blockcount;
1409-
*new_len = 0;
1410-
error = __xfs_refcount_cow_free(rcur, bno, blockcount);
1397+
error = __xfs_refcount_cow_free(rcur, bno, ri->ri_blockcount);
1398+
if (error)
1399+
goto out_drop;
1400+
ri->ri_blockcount = 0;
14111401
break;
14121402
default:
14131403
ASSERT(0);
14141404
error = -EFSCORRUPTED;
14151405
}
1416-
if (!error && *new_len > 0)
1417-
trace_xfs_refcount_finish_one_leftover(mp, pag->pag_agno, type,
1418-
bno, blockcount, new_agbno, *new_len);
1406+
if (!error && ri->ri_blockcount > 0)
1407+
trace_xfs_refcount_finish_one_leftover(mp, pag->pag_agno,
1408+
ri->ri_type, bno, ri->ri_blockcount);
14191409
out_drop:
14201410
xfs_perag_put(pag);
14211411
return error;

fs/xfs/libxfs/xfs_refcount.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ void xfs_refcount_decrease_extent(struct xfs_trans *tp,
7575
extern void xfs_refcount_finish_one_cleanup(struct xfs_trans *tp,
7676
struct xfs_btree_cur *rcur, int error);
7777
extern int xfs_refcount_finish_one(struct xfs_trans *tp,
78-
enum xfs_refcount_intent_type type, xfs_fsblock_t startblock,
79-
xfs_extlen_t blockcount, xfs_fsblock_t *new_fsb,
80-
xfs_extlen_t *new_len, struct xfs_btree_cur **pcur);
78+
struct xfs_refcount_intent *ri, struct xfs_btree_cur **pcur);
8179

8280
extern int xfs_refcount_find_shared(struct xfs_btree_cur *cur,
8381
xfs_agblock_t agbno, xfs_extlen_t aglen, xfs_agblock_t *fbno,

fs/xfs/xfs_refcount_item.c

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,12 @@ static int
252252
xfs_trans_log_finish_refcount_update(
253253
struct xfs_trans *tp,
254254
struct xfs_cud_log_item *cudp,
255-
enum xfs_refcount_intent_type type,
256-
xfs_fsblock_t startblock,
257-
xfs_extlen_t blockcount,
258-
xfs_fsblock_t *new_fsb,
259-
xfs_extlen_t *new_len,
255+
struct xfs_refcount_intent *ri,
260256
struct xfs_btree_cur **pcur)
261257
{
262258
int error;
263259

264-
error = xfs_refcount_finish_one(tp, type, startblock,
265-
blockcount, new_fsb, new_len, pcur);
260+
error = xfs_refcount_finish_one(tp, ri, pcur);
266261

267262
/*
268263
* Mark the transaction dirty, even on error. This ensures the
@@ -378,25 +373,20 @@ xfs_refcount_update_finish_item(
378373
struct list_head *item,
379374
struct xfs_btree_cur **state)
380375
{
381-
struct xfs_refcount_intent *refc;
382-
xfs_fsblock_t new_fsb;
383-
xfs_extlen_t new_aglen;
376+
struct xfs_refcount_intent *ri;
384377
int error;
385378

386-
refc = container_of(item, struct xfs_refcount_intent, ri_list);
387-
error = xfs_trans_log_finish_refcount_update(tp, CUD_ITEM(done),
388-
refc->ri_type, refc->ri_startblock, refc->ri_blockcount,
389-
&new_fsb, &new_aglen, state);
379+
ri = container_of(item, struct xfs_refcount_intent, ri_list);
380+
error = xfs_trans_log_finish_refcount_update(tp, CUD_ITEM(done), ri,
381+
state);
390382

391383
/* Did we run out of reservation? Requeue what we didn't finish. */
392-
if (!error && new_aglen > 0) {
393-
ASSERT(refc->ri_type == XFS_REFCOUNT_INCREASE ||
394-
refc->ri_type == XFS_REFCOUNT_DECREASE);
395-
refc->ri_startblock = new_fsb;
396-
refc->ri_blockcount = new_aglen;
384+
if (!error && ri->ri_blockcount > 0) {
385+
ASSERT(ri->ri_type == XFS_REFCOUNT_INCREASE ||
386+
ri->ri_type == XFS_REFCOUNT_DECREASE);
397387
return -EAGAIN;
398388
}
399-
kmem_cache_free(xfs_refcount_intent_cache, refc);
389+
kmem_cache_free(xfs_refcount_intent_cache, ri);
400390
return error;
401391
}
402392

@@ -463,18 +453,13 @@ xfs_cui_item_recover(
463453
struct xfs_log_item *lip,
464454
struct list_head *capture_list)
465455
{
466-
struct xfs_bmbt_irec irec;
467456
struct xfs_cui_log_item *cuip = CUI_ITEM(lip);
468-
struct xfs_phys_extent *refc;
469457
struct xfs_cud_log_item *cudp;
470458
struct xfs_trans *tp;
471459
struct xfs_btree_cur *rcur = NULL;
472460
struct xfs_mount *mp = lip->li_log->l_mp;
473-
xfs_fsblock_t new_fsb;
474-
xfs_extlen_t new_len;
475461
unsigned int refc_type;
476462
bool requeue_only = false;
477-
enum xfs_refcount_intent_type type;
478463
int i;
479464
int error = 0;
480465

@@ -513,14 +498,17 @@ xfs_cui_item_recover(
513498
cudp = xfs_trans_get_cud(tp, cuip);
514499

515500
for (i = 0; i < cuip->cui_format.cui_nextents; i++) {
501+
struct xfs_refcount_intent fake = { };
502+
struct xfs_phys_extent *refc;
503+
516504
refc = &cuip->cui_format.cui_extents[i];
517505
refc_type = refc->pe_flags & XFS_REFCOUNT_EXTENT_TYPE_MASK;
518506
switch (refc_type) {
519507
case XFS_REFCOUNT_INCREASE:
520508
case XFS_REFCOUNT_DECREASE:
521509
case XFS_REFCOUNT_ALLOC_COW:
522510
case XFS_REFCOUNT_FREE_COW:
523-
type = refc_type;
511+
fake.ri_type = refc_type;
524512
break;
525513
default:
526514
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
@@ -529,13 +517,12 @@ xfs_cui_item_recover(
529517
error = -EFSCORRUPTED;
530518
goto abort_error;
531519
}
532-
if (requeue_only) {
533-
new_fsb = refc->pe_startblock;
534-
new_len = refc->pe_len;
535-
} else
520+
521+
fake.ri_startblock = refc->pe_startblock;
522+
fake.ri_blockcount = refc->pe_len;
523+
if (!requeue_only)
536524
error = xfs_trans_log_finish_refcount_update(tp, cudp,
537-
type, refc->pe_startblock, refc->pe_len,
538-
&new_fsb, &new_len, &rcur);
525+
&fake, &rcur);
539526
if (error == -EFSCORRUPTED)
540527
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
541528
&cuip->cui_format,
@@ -544,10 +531,13 @@ xfs_cui_item_recover(
544531
goto abort_error;
545532

546533
/* Requeue what we didn't finish. */
547-
if (new_len > 0) {
548-
irec.br_startblock = new_fsb;
549-
irec.br_blockcount = new_len;
550-
switch (type) {
534+
if (fake.ri_blockcount > 0) {
535+
struct xfs_bmbt_irec irec = {
536+
.br_startblock = fake.ri_startblock,
537+
.br_blockcount = fake.ri_blockcount,
538+
};
539+
540+
switch (fake.ri_type) {
551541
case XFS_REFCOUNT_INCREASE:
552542
xfs_refcount_increase_extent(tp, &irec);
553543
break;

fs/xfs/xfs_trace.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3207,35 +3207,28 @@ DEFINE_REFCOUNT_DEFERRED_EVENT(xfs_refcount_deferred);
32073207

32083208
TRACE_EVENT(xfs_refcount_finish_one_leftover,
32093209
TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno,
3210-
int type, xfs_agblock_t agbno, xfs_extlen_t len,
3211-
xfs_agblock_t new_agbno, xfs_extlen_t new_len),
3212-
TP_ARGS(mp, agno, type, agbno, len, new_agbno, new_len),
3210+
int type, xfs_agblock_t agbno, xfs_extlen_t len),
3211+
TP_ARGS(mp, agno, type, agbno, len),
32133212
TP_STRUCT__entry(
32143213
__field(dev_t, dev)
32153214
__field(xfs_agnumber_t, agno)
32163215
__field(int, type)
32173216
__field(xfs_agblock_t, agbno)
32183217
__field(xfs_extlen_t, len)
3219-
__field(xfs_agblock_t, new_agbno)
3220-
__field(xfs_extlen_t, new_len)
32213218
),
32223219
TP_fast_assign(
32233220
__entry->dev = mp->m_super->s_dev;
32243221
__entry->agno = agno;
32253222
__entry->type = type;
32263223
__entry->agbno = agbno;
32273224
__entry->len = len;
3228-
__entry->new_agbno = new_agbno;
3229-
__entry->new_len = new_len;
32303225
),
3231-
TP_printk("dev %d:%d type %d agno 0x%x agbno 0x%x fsbcount 0x%x new_agbno 0x%x new_fsbcount 0x%x",
3226+
TP_printk("dev %d:%d type %d agno 0x%x agbno 0x%x fsbcount 0x%x",
32323227
MAJOR(__entry->dev), MINOR(__entry->dev),
32333228
__entry->type,
32343229
__entry->agno,
32353230
__entry->agbno,
3236-
__entry->len,
3237-
__entry->new_agbno,
3238-
__entry->new_len)
3231+
__entry->len)
32393232
);
32403233

32413234
/* simple inode-based error/%ip tracepoint class */

0 commit comments

Comments
 (0)