Skip to content

Commit 00e7b3b

Browse files
author
Darrick J. Wong
committed
xfs: give xfs_refcount_intent its own perag reference
Give the xfs_refcount_intent a passive reference to the perag structure data. This reference will be used to enable scrub intent draining functionality in subsequent patches. Any space being modified by a refcount intent is already allocated, so we need to be able to operate even if the AG is being shrunk or offlined. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent c13418e commit 00e7b3b

3 files changed

Lines changed: 50 additions & 23 deletions

File tree

fs/xfs/libxfs/xfs_refcount.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,39 +1332,35 @@ xfs_refcount_finish_one(
13321332
xfs_agblock_t bno;
13331333
unsigned long nr_ops = 0;
13341334
int shape_changes = 0;
1335-
struct xfs_perag *pag;
13361335

1337-
pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, ri->ri_startblock));
13381336
bno = XFS_FSB_TO_AGBNO(mp, ri->ri_startblock);
13391337

13401338
trace_xfs_refcount_deferred(mp, XFS_FSB_TO_AGNO(mp, ri->ri_startblock),
13411339
ri->ri_type, XFS_FSB_TO_AGBNO(mp, ri->ri_startblock),
13421340
ri->ri_blockcount);
13431341

1344-
if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_REFCOUNT_FINISH_ONE)) {
1345-
error = -EIO;
1346-
goto out_drop;
1347-
}
1342+
if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_REFCOUNT_FINISH_ONE))
1343+
return -EIO;
13481344

13491345
/*
13501346
* If we haven't gotten a cursor or the cursor AG doesn't match
13511347
* the startblock, get one now.
13521348
*/
13531349
rcur = *pcur;
1354-
if (rcur != NULL && rcur->bc_ag.pag != pag) {
1350+
if (rcur != NULL && rcur->bc_ag.pag != ri->ri_pag) {
13551351
nr_ops = rcur->bc_ag.refc.nr_ops;
13561352
shape_changes = rcur->bc_ag.refc.shape_changes;
13571353
xfs_refcount_finish_one_cleanup(tp, rcur, 0);
13581354
rcur = NULL;
13591355
*pcur = NULL;
13601356
}
13611357
if (rcur == NULL) {
1362-
error = xfs_alloc_read_agf(pag, tp, XFS_ALLOC_FLAG_FREEING,
1363-
&agbp);
1358+
error = xfs_alloc_read_agf(ri->ri_pag, tp,
1359+
XFS_ALLOC_FLAG_FREEING, &agbp);
13641360
if (error)
1365-
goto out_drop;
1361+
return error;
13661362

1367-
rcur = xfs_refcountbt_init_cursor(mp, tp, agbp, pag);
1363+
rcur = xfs_refcountbt_init_cursor(mp, tp, agbp, ri->ri_pag);
13681364
rcur->bc_ag.refc.nr_ops = nr_ops;
13691365
rcur->bc_ag.refc.shape_changes = shape_changes;
13701366
}
@@ -1375,39 +1371,37 @@ xfs_refcount_finish_one(
13751371
error = xfs_refcount_adjust(rcur, &bno, &ri->ri_blockcount,
13761372
XFS_REFCOUNT_ADJUST_INCREASE);
13771373
if (error)
1378-
goto out_drop;
1374+
return error;
13791375
if (ri->ri_blockcount > 0)
13801376
error = xfs_refcount_continue_op(rcur, ri, bno);
13811377
break;
13821378
case XFS_REFCOUNT_DECREASE:
13831379
error = xfs_refcount_adjust(rcur, &bno, &ri->ri_blockcount,
13841380
XFS_REFCOUNT_ADJUST_DECREASE);
13851381
if (error)
1386-
goto out_drop;
1382+
return error;
13871383
if (ri->ri_blockcount > 0)
13881384
error = xfs_refcount_continue_op(rcur, ri, bno);
13891385
break;
13901386
case XFS_REFCOUNT_ALLOC_COW:
13911387
error = __xfs_refcount_cow_alloc(rcur, bno, ri->ri_blockcount);
13921388
if (error)
1393-
goto out_drop;
1389+
return error;
13941390
ri->ri_blockcount = 0;
13951391
break;
13961392
case XFS_REFCOUNT_FREE_COW:
13971393
error = __xfs_refcount_cow_free(rcur, bno, ri->ri_blockcount);
13981394
if (error)
1399-
goto out_drop;
1395+
return error;
14001396
ri->ri_blockcount = 0;
14011397
break;
14021398
default:
14031399
ASSERT(0);
1404-
error = -EFSCORRUPTED;
1400+
return -EFSCORRUPTED;
14051401
}
14061402
if (!error && ri->ri_blockcount > 0)
1407-
trace_xfs_refcount_finish_one_leftover(mp, pag->pag_agno,
1403+
trace_xfs_refcount_finish_one_leftover(mp, ri->ri_pag->pag_agno,
14081404
ri->ri_type, bno, ri->ri_blockcount);
1409-
out_drop:
1410-
xfs_perag_put(pag);
14111405
return error;
14121406
}
14131407

@@ -1435,6 +1429,7 @@ __xfs_refcount_add(
14351429
ri->ri_startblock = startblock;
14361430
ri->ri_blockcount = blockcount;
14371431

1432+
xfs_refcount_update_get_group(tp->t_mountp, ri);
14381433
xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_REFCOUNT, &ri->ri_list);
14391434
}
14401435

fs/xfs/libxfs/xfs_refcount.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ enum xfs_refcount_intent_type {
5050

5151
struct xfs_refcount_intent {
5252
struct list_head ri_list;
53+
struct xfs_perag *ri_pag;
5354
enum xfs_refcount_intent_type ri_type;
5455
xfs_extlen_t ri_blockcount;
5556
xfs_fsblock_t ri_startblock;
@@ -67,6 +68,9 @@ xfs_refcount_check_domain(
6768
return true;
6869
}
6970

71+
void xfs_refcount_update_get_group(struct xfs_mount *mp,
72+
struct xfs_refcount_intent *ri);
73+
7074
void xfs_refcount_increase_extent(struct xfs_trans *tp,
7175
struct xfs_bmbt_irec *irec);
7276
void xfs_refcount_decrease_extent(struct xfs_trans *tp,

fs/xfs/xfs_refcount_item.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "xfs_error.h"
2121
#include "xfs_log_priv.h"
2222
#include "xfs_log_recover.h"
23+
#include "xfs_ag.h"
2324

2425
struct kmem_cache *xfs_cui_cache;
2526
struct kmem_cache *xfs_cud_cache;
@@ -279,14 +280,13 @@ xfs_refcount_update_diff_items(
279280
const struct list_head *a,
280281
const struct list_head *b)
281282
{
282-
struct xfs_mount *mp = priv;
283283
struct xfs_refcount_intent *ra;
284284
struct xfs_refcount_intent *rb;
285285

286286
ra = container_of(a, struct xfs_refcount_intent, ri_list);
287287
rb = container_of(b, struct xfs_refcount_intent, ri_list);
288-
return XFS_FSB_TO_AGNO(mp, ra->ri_startblock) -
289-
XFS_FSB_TO_AGNO(mp, rb->ri_startblock);
288+
289+
return ra->ri_pag->pag_agno - rb->ri_pag->pag_agno;
290290
}
291291

292292
/* Set the phys extent flags for this reverse mapping. */
@@ -365,6 +365,26 @@ xfs_refcount_update_create_done(
365365
return &xfs_trans_get_cud(tp, CUI_ITEM(intent))->cud_item;
366366
}
367367

368+
/* Take a passive ref to the AG containing the space we're refcounting. */
369+
void
370+
xfs_refcount_update_get_group(
371+
struct xfs_mount *mp,
372+
struct xfs_refcount_intent *ri)
373+
{
374+
xfs_agnumber_t agno;
375+
376+
agno = XFS_FSB_TO_AGNO(mp, ri->ri_startblock);
377+
ri->ri_pag = xfs_perag_get(mp, agno);
378+
}
379+
380+
/* Release a passive AG ref after finishing refcounting work. */
381+
static inline void
382+
xfs_refcount_update_put_group(
383+
struct xfs_refcount_intent *ri)
384+
{
385+
xfs_perag_put(ri->ri_pag);
386+
}
387+
368388
/* Process a deferred refcount update. */
369389
STATIC int
370390
xfs_refcount_update_finish_item(
@@ -386,6 +406,8 @@ xfs_refcount_update_finish_item(
386406
ri->ri_type == XFS_REFCOUNT_DECREASE);
387407
return -EAGAIN;
388408
}
409+
410+
xfs_refcount_update_put_group(ri);
389411
kmem_cache_free(xfs_refcount_intent_cache, ri);
390412
return error;
391413
}
@@ -406,6 +428,8 @@ xfs_refcount_update_cancel_item(
406428
struct xfs_refcount_intent *ri;
407429

408430
ri = container_of(item, struct xfs_refcount_intent, ri_list);
431+
432+
xfs_refcount_update_put_group(ri);
409433
kmem_cache_free(xfs_refcount_intent_cache, ri);
410434
}
411435

@@ -520,9 +544,13 @@ xfs_cui_item_recover(
520544

521545
fake.ri_startblock = pmap->pe_startblock;
522546
fake.ri_blockcount = pmap->pe_len;
523-
if (!requeue_only)
547+
548+
if (!requeue_only) {
549+
xfs_refcount_update_get_group(mp, &fake);
524550
error = xfs_trans_log_finish_refcount_update(tp, cudp,
525551
&fake, &rcur);
552+
xfs_refcount_update_put_group(&fake);
553+
}
526554
if (error == -EFSCORRUPTED)
527555
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
528556
&cuip->cui_format,

0 commit comments

Comments
 (0)