]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
xfs: add a xfs_group_type_buftarg helper
authorChristoph Hellwig <hch@lst.de>
Mon, 7 Jul 2025 12:53:14 +0000 (14:53 +0200)
committerCarlos Maiolino <cem@kernel.org>
Tue, 8 Jul 2025 11:30:26 +0000 (13:30 +0200)
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 <hch@lst.de>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
fs/xfs/xfs_discard.c
fs/xfs/xfs_mount.h
fs/xfs/xfs_notify_failure.c

index 94d0873bcd6289524f7b7fe5f9aff94adb7c17e2..603d513656450889f7bc8dbb2d57642c6ad9e457 100644 (file)
@@ -103,24 +103,6 @@ xfs_discard_endio(
        bio_put(bio);
 }
 
-static inline struct block_device *
-xfs_group_bdev(
-       const struct xfs_group  *xg)
-{
-       struct xfs_mount        *mp = xg->xg_mount;
-
-       switch (xg->xg_type) {
-       case XG_TYPE_AG:
-               return mp->m_ddev_targp->bt_bdev;
-       case XG_TYPE_RTG:
-               return mp->m_rtdev_targp->bt_bdev;
-       default:
-               ASSERT(0);
-               break;
-       }
-       return NULL;
-}
-
 /*
  * Walk the discard list and issue discards on all the busy extents in the
  * list. We plug and chain the bios so that we only need a single completion
@@ -138,11 +120,14 @@ xfs_discard_extents(
 
        blk_start_plug(&plug);
        list_for_each_entry(busyp, &extents->extent_list, list) {
-               trace_xfs_discard_extent(busyp->group, busyp->bno,
-                               busyp->length);
+               struct xfs_group        *xg = busyp->group;
+               struct xfs_buftarg      *btp =
+                       xfs_group_type_buftarg(xg->xg_mount, xg->xg_type);
+
+               trace_xfs_discard_extent(xg, busyp->bno, busyp->length);
 
-               error = __blkdev_issue_discard(xfs_group_bdev(busyp->group),
-                               xfs_gbno_to_daddr(busyp->group, busyp->bno),
+               error = __blkdev_issue_discard(btp->bt_bdev,
+                               xfs_gbno_to_daddr(xg, busyp->bno),
                                XFS_FSB_TO_BB(mp, busyp->length),
                                GFP_KERNEL, &bio);
                if (error && error != -EOPNOTSUPP) {
index d85084f9f317e31fa28c02f2fc803e09c9a4f6b0..97de44c32272f256ba25bd2d4652b559b80d4c24 100644 (file)
@@ -802,4 +802,21 @@ static inline void xfs_mod_sb_delalloc(struct xfs_mount *mp, int64_t delta)
 int xfs_set_max_atomic_write_opt(struct xfs_mount *mp,
                unsigned long long new_max_bytes);
 
+static inline struct xfs_buftarg *
+xfs_group_type_buftarg(
+       struct xfs_mount        *mp,
+       enum xfs_group_type     type)
+{
+       switch (type) {
+       case XG_TYPE_AG:
+               return mp->m_ddev_targp;
+       case XG_TYPE_RTG:
+               return mp->m_rtdev_targp;
+       default:
+               ASSERT(0);
+               break;
+       }
+       return NULL;
+}
+
 #endif /* __XFS_MOUNT_H__ */
index 3545dc1d953c40d1f7cb9fb30d56a261c76484e0..42e9c72b85c00f006ac3112da46ec5c62a414180 100644 (file)
@@ -253,8 +253,7 @@ xfs_dax_notify_dev_failure(
                return -EOPNOTSUPP;
        }
 
-       error = xfs_dax_translate_range(type == XG_TYPE_RTG ?
-                       mp->m_rtdev_targp : mp->m_ddev_targp,
+       error = xfs_dax_translate_range(xfs_group_type_buftarg(mp, type),
                        offset, len, &daddr, &bblen);
        if (error)
                return error;