Skip to content

Commit c13418e

Browse files
author
Darrick J. Wong
committed
xfs: give xfs_rmap_intent its own perag reference
Give the xfs_rmap_intent a passive reference to the perag structure data. This reference will be used to enable scrub intent draining functionality in subsequent patches. The space we're (reverse) mapping 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 f6b3846 commit c13418e

3 files changed

Lines changed: 44 additions & 21 deletions

File tree

fs/xfs/libxfs/xfs_rmap.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,34 +2394,29 @@ xfs_rmap_finish_one(
23942394
struct xfs_btree_cur **pcur)
23952395
{
23962396
struct xfs_mount *mp = tp->t_mountp;
2397-
struct xfs_perag *pag;
23982397
struct xfs_btree_cur *rcur;
23992398
struct xfs_buf *agbp = NULL;
24002399
int error = 0;
24012400
struct xfs_owner_info oinfo;
24022401
xfs_agblock_t bno;
24032402
bool unwritten;
24042403

2405-
pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, ri->ri_bmap.br_startblock));
24062404
bno = XFS_FSB_TO_AGBNO(mp, ri->ri_bmap.br_startblock);
24072405

2408-
trace_xfs_rmap_deferred(mp, pag->pag_agno, ri->ri_type, bno,
2406+
trace_xfs_rmap_deferred(mp, ri->ri_pag->pag_agno, ri->ri_type, bno,
24092407
ri->ri_owner, ri->ri_whichfork,
24102408
ri->ri_bmap.br_startoff, ri->ri_bmap.br_blockcount,
24112409
ri->ri_bmap.br_state);
24122410

2413-
if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_RMAP_FINISH_ONE)) {
2414-
error = -EIO;
2415-
goto out_drop;
2416-
}
2417-
2411+
if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_RMAP_FINISH_ONE))
2412+
return -EIO;
24182413

24192414
/*
24202415
* If we haven't gotten a cursor or the cursor AG doesn't match
24212416
* the startblock, get one now.
24222417
*/
24232418
rcur = *pcur;
2424-
if (rcur != NULL && rcur->bc_ag.pag != pag) {
2419+
if (rcur != NULL && rcur->bc_ag.pag != ri->ri_pag) {
24252420
xfs_rmap_finish_one_cleanup(tp, rcur, 0);
24262421
rcur = NULL;
24272422
*pcur = NULL;
@@ -2432,15 +2427,13 @@ xfs_rmap_finish_one(
24322427
* rmapbt, because a shape change could cause us to
24332428
* allocate blocks.
24342429
*/
2435-
error = xfs_free_extent_fix_freelist(tp, pag, &agbp);
2430+
error = xfs_free_extent_fix_freelist(tp, ri->ri_pag, &agbp);
24362431
if (error)
2437-
goto out_drop;
2438-
if (XFS_IS_CORRUPT(tp->t_mountp, !agbp)) {
2439-
error = -EFSCORRUPTED;
2440-
goto out_drop;
2441-
}
2432+
return error;
2433+
if (XFS_IS_CORRUPT(tp->t_mountp, !agbp))
2434+
return -EFSCORRUPTED;
24422435

2443-
rcur = xfs_rmapbt_init_cursor(mp, tp, agbp, pag);
2436+
rcur = xfs_rmapbt_init_cursor(mp, tp, agbp, ri->ri_pag);
24442437
}
24452438
*pcur = rcur;
24462439

@@ -2480,8 +2473,7 @@ xfs_rmap_finish_one(
24802473
ASSERT(0);
24812474
error = -EFSCORRUPTED;
24822475
}
2483-
out_drop:
2484-
xfs_perag_put(pag);
2476+
24852477
return error;
24862478
}
24872479

@@ -2526,6 +2518,7 @@ __xfs_rmap_add(
25262518
ri->ri_whichfork = whichfork;
25272519
ri->ri_bmap = *bmap;
25282520

2521+
xfs_rmap_update_get_group(tp->t_mountp, ri);
25292522
xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_RMAP, &ri->ri_list);
25302523
}
25312524

fs/xfs/libxfs/xfs_rmap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,12 @@ struct xfs_rmap_intent {
162162
int ri_whichfork;
163163
uint64_t ri_owner;
164164
struct xfs_bmbt_irec ri_bmap;
165+
struct xfs_perag *ri_pag;
165166
};
166167

168+
void xfs_rmap_update_get_group(struct xfs_mount *mp,
169+
struct xfs_rmap_intent *ri);
170+
167171
/* functions for updating the rmapbt based on bmbt map/unmap operations */
168172
void xfs_rmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip,
169173
int whichfork, struct xfs_bmbt_irec *imap);

fs/xfs/xfs_rmap_item.c

Lines changed: 29 additions & 3 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_rui_cache;
2526
struct kmem_cache *xfs_rud_cache;
@@ -320,14 +321,13 @@ xfs_rmap_update_diff_items(
320321
const struct list_head *a,
321322
const struct list_head *b)
322323
{
323-
struct xfs_mount *mp = priv;
324324
struct xfs_rmap_intent *ra;
325325
struct xfs_rmap_intent *rb;
326326

327327
ra = container_of(a, struct xfs_rmap_intent, ri_list);
328328
rb = container_of(b, struct xfs_rmap_intent, ri_list);
329-
return XFS_FSB_TO_AGNO(mp, ra->ri_bmap.br_startblock) -
330-
XFS_FSB_TO_AGNO(mp, rb->ri_bmap.br_startblock);
329+
330+
return ra->ri_pag->pag_agno - rb->ri_pag->pag_agno;
331331
}
332332

333333
/* Log rmap updates in the intent item. */
@@ -390,6 +390,26 @@ xfs_rmap_update_create_done(
390390
return &xfs_trans_get_rud(tp, RUI_ITEM(intent))->rud_item;
391391
}
392392

393+
/* Take a passive ref to the AG containing the space we're rmapping. */
394+
void
395+
xfs_rmap_update_get_group(
396+
struct xfs_mount *mp,
397+
struct xfs_rmap_intent *ri)
398+
{
399+
xfs_agnumber_t agno;
400+
401+
agno = XFS_FSB_TO_AGNO(mp, ri->ri_bmap.br_startblock);
402+
ri->ri_pag = xfs_perag_get(mp, agno);
403+
}
404+
405+
/* Release a passive AG ref after finishing rmapping work. */
406+
static inline void
407+
xfs_rmap_update_put_group(
408+
struct xfs_rmap_intent *ri)
409+
{
410+
xfs_perag_put(ri->ri_pag);
411+
}
412+
393413
/* Process a deferred rmap update. */
394414
STATIC int
395415
xfs_rmap_update_finish_item(
@@ -405,6 +425,8 @@ xfs_rmap_update_finish_item(
405425

406426
error = xfs_trans_log_finish_rmap_update(tp, RUD_ITEM(done), ri,
407427
state);
428+
429+
xfs_rmap_update_put_group(ri);
408430
kmem_cache_free(xfs_rmap_intent_cache, ri);
409431
return error;
410432
}
@@ -425,6 +447,8 @@ xfs_rmap_update_cancel_item(
425447
struct xfs_rmap_intent *ri;
426448

427449
ri = container_of(item, struct xfs_rmap_intent, ri_list);
450+
451+
xfs_rmap_update_put_group(ri);
428452
kmem_cache_free(xfs_rmap_intent_cache, ri);
429453
}
430454

@@ -559,11 +583,13 @@ xfs_rui_item_recover(
559583
fake.ri_bmap.br_state = (map->me_flags & XFS_RMAP_EXTENT_UNWRITTEN) ?
560584
XFS_EXT_UNWRITTEN : XFS_EXT_NORM;
561585

586+
xfs_rmap_update_get_group(mp, &fake);
562587
error = xfs_trans_log_finish_rmap_update(tp, rudp, &fake,
563588
&rcur);
564589
if (error == -EFSCORRUPTED)
565590
XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
566591
map, sizeof(*map));
592+
xfs_rmap_update_put_group(&fake);
567593
if (error)
568594
goto abort_error;
569595

0 commit comments

Comments
 (0)