Skip to content

Commit e74d1fa

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: add a xfs_group_type_buftarg helper
Generalize the xfs_group_type helper in the discard code to return a buftarg and move it to xfs_mount.h, and use the result in xfs_dax_notify_dev_failure. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: John Garry <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Carlos Maiolino <[email protected]>
1 parent d9b1e34 commit e74d1fa

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

fs/xfs/xfs_discard.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,6 @@ xfs_discard_endio(
103103
bio_put(bio);
104104
}
105105

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

139121
blk_start_plug(&plug);
140122
list_for_each_entry(busyp, &extents->extent_list, list) {
141-
trace_xfs_discard_extent(busyp->group, busyp->bno,
142-
busyp->length);
123+
struct xfs_group *xg = busyp->group;
124+
struct xfs_buftarg *btp =
125+
xfs_group_type_buftarg(xg->xg_mount, xg->xg_type);
126+
127+
trace_xfs_discard_extent(xg, busyp->bno, busyp->length);
143128

144-
error = __blkdev_issue_discard(xfs_group_bdev(busyp->group),
145-
xfs_gbno_to_daddr(busyp->group, busyp->bno),
129+
error = __blkdev_issue_discard(btp->bt_bdev,
130+
xfs_gbno_to_daddr(xg, busyp->bno),
146131
XFS_FSB_TO_BB(mp, busyp->length),
147132
GFP_KERNEL, &bio);
148133
if (error && error != -EOPNOTSUPP) {

fs/xfs/xfs_mount.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,4 +802,21 @@ static inline void xfs_mod_sb_delalloc(struct xfs_mount *mp, int64_t delta)
802802
int xfs_set_max_atomic_write_opt(struct xfs_mount *mp,
803803
unsigned long long new_max_bytes);
804804

805+
static inline struct xfs_buftarg *
806+
xfs_group_type_buftarg(
807+
struct xfs_mount *mp,
808+
enum xfs_group_type type)
809+
{
810+
switch (type) {
811+
case XG_TYPE_AG:
812+
return mp->m_ddev_targp;
813+
case XG_TYPE_RTG:
814+
return mp->m_rtdev_targp;
815+
default:
816+
ASSERT(0);
817+
break;
818+
}
819+
return NULL;
820+
}
821+
805822
#endif /* __XFS_MOUNT_H__ */

fs/xfs/xfs_notify_failure.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ xfs_dax_notify_dev_failure(
253253
return -EOPNOTSUPP;
254254
}
255255

256-
error = xfs_dax_translate_range(type == XG_TYPE_RTG ?
257-
mp->m_rtdev_targp : mp->m_ddev_targp,
256+
error = xfs_dax_translate_range(xfs_group_type_buftarg(mp, type),
258257
offset, len, &daddr, &bblen);
259258
if (error)
260259
return error;

0 commit comments

Comments
 (0)