Skip to content

Commit 0c271d9

Browse files
author
Darrick J. Wong
committed
xfs: port the perag discard code to handle generic groups
Port xfs_discard_extents and its tracepoints to handle generic groups instead of just perags. This is needed to enable busy extent tracking for rtgroups. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent e0b5b97 commit 0c271d9

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

fs/xfs/xfs_discard.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ xfs_discard_endio(
101101
bio_put(bio);
102102
}
103103

104+
static inline struct block_device *
105+
xfs_group_bdev(
106+
const struct xfs_group *xg)
107+
{
108+
struct xfs_mount *mp = xg->xg_mount;
109+
110+
switch (xg->xg_type) {
111+
case XG_TYPE_AG:
112+
return mp->m_ddev_targp->bt_bdev;
113+
case XG_TYPE_RTG:
114+
return mp->m_rtdev_targp->bt_bdev;
115+
default:
116+
ASSERT(0);
117+
break;
118+
}
119+
return NULL;
120+
}
121+
104122
/*
105123
* Walk the discard list and issue discards on all the busy extents in the
106124
* list. We plug and chain the bios so that we only need a single completion
@@ -118,12 +136,11 @@ xfs_discard_extents(
118136

119137
blk_start_plug(&plug);
120138
list_for_each_entry(busyp, &extents->extent_list, list) {
121-
struct xfs_perag *pag = to_perag(busyp->group);
122-
123-
trace_xfs_discard_extent(pag, busyp->bno, busyp->length);
139+
trace_xfs_discard_extent(busyp->group, busyp->bno,
140+
busyp->length);
124141

125-
error = __blkdev_issue_discard(mp->m_ddev_targp->bt_bdev,
126-
xfs_agbno_to_daddr(pag, busyp->bno),
142+
error = __blkdev_issue_discard(xfs_group_bdev(busyp->group),
143+
xfs_gbno_to_daddr(busyp->group, busyp->bno),
127144
XFS_FSB_TO_BB(mp, busyp->length),
128145
GFP_KERNEL, &bio);
129146
if (error && error != -EOPNOTSUPP) {
@@ -241,11 +258,11 @@ xfs_trim_gather_extents(
241258
* overlapping ranges for now.
242259
*/
243260
if (fbno + flen < tcur->start) {
244-
trace_xfs_discard_exclude(pag, fbno, flen);
261+
trace_xfs_discard_exclude(pag_group(pag), fbno, flen);
245262
goto next_extent;
246263
}
247264
if (fbno > tcur->end) {
248-
trace_xfs_discard_exclude(pag, fbno, flen);
265+
trace_xfs_discard_exclude(pag_group(pag), fbno, flen);
249266
if (tcur->by_bno) {
250267
tcur->count = 0;
251268
break;
@@ -263,7 +280,7 @@ xfs_trim_gather_extents(
263280

264281
/* Too small? Give up. */
265282
if (flen < tcur->minlen) {
266-
trace_xfs_discard_toosmall(pag, fbno, flen);
283+
trace_xfs_discard_toosmall(pag_group(pag), fbno, flen);
267284
if (tcur->by_bno)
268285
goto next_extent;
269286
tcur->count = 0;
@@ -275,7 +292,7 @@ xfs_trim_gather_extents(
275292
* discard and try again the next time.
276293
*/
277294
if (xfs_extent_busy_search(pag_group(pag), fbno, flen)) {
278-
trace_xfs_discard_busy(pag, fbno, flen);
295+
trace_xfs_discard_busy(pag_group(pag), fbno, flen);
279296
goto next_extent;
280297
}
281298

fs/xfs/xfs_trace.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,33 +2475,36 @@ DEFINE_LOG_RECOVER_ICREATE_ITEM(xfs_log_recover_icreate_cancel);
24752475
DEFINE_LOG_RECOVER_ICREATE_ITEM(xfs_log_recover_icreate_recover);
24762476

24772477
DECLARE_EVENT_CLASS(xfs_discard_class,
2478-
TP_PROTO(const struct xfs_perag *pag, xfs_agblock_t agbno,
2478+
TP_PROTO(const struct xfs_group *xg, xfs_agblock_t agbno,
24792479
xfs_extlen_t len),
2480-
TP_ARGS(pag, agbno, len),
2480+
TP_ARGS(xg, agbno, len),
24812481
TP_STRUCT__entry(
24822482
__field(dev_t, dev)
2483+
__field(enum xfs_group_type, type)
24832484
__field(xfs_agnumber_t, agno)
24842485
__field(xfs_agblock_t, agbno)
24852486
__field(xfs_extlen_t, len)
24862487
),
24872488
TP_fast_assign(
2488-
__entry->dev = pag_mount(pag)->m_super->s_dev;
2489-
__entry->agno = pag_agno(pag);
2489+
__entry->dev = xg->xg_mount->m_super->s_dev;
2490+
__entry->type = xg->xg_type;
2491+
__entry->agno = xg->xg_gno;
24902492
__entry->agbno = agbno;
24912493
__entry->len = len;
24922494
),
2493-
TP_printk("dev %d:%d agno 0x%x agbno 0x%x fsbcount 0x%x",
2495+
TP_printk("dev %d:%d %sno 0x%x gbno 0x%x fsbcount 0x%x",
24942496
MAJOR(__entry->dev), MINOR(__entry->dev),
2497+
__print_symbolic(__entry->type, XG_TYPE_STRINGS),
24952498
__entry->agno,
24962499
__entry->agbno,
24972500
__entry->len)
24982501
)
24992502

25002503
#define DEFINE_DISCARD_EVENT(name) \
25012504
DEFINE_EVENT(xfs_discard_class, name, \
2502-
TP_PROTO(const struct xfs_perag *pag, xfs_agblock_t agbno, \
2503-
xfs_extlen_t len), \
2504-
TP_ARGS(pag, agbno, len))
2505+
TP_PROTO(const struct xfs_group *xg, xfs_agblock_t agbno, \
2506+
xfs_extlen_t len), \
2507+
TP_ARGS(xg, agbno, len))
25052508
DEFINE_DISCARD_EVENT(xfs_discard_extent);
25062509
DEFINE_DISCARD_EVENT(xfs_discard_toosmall);
25072510
DEFINE_DISCARD_EVENT(xfs_discard_exclude);

0 commit comments

Comments
 (0)