]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: store a generic xfs_group pointer in xfs_getfsmap_info xfs-generic-group
authorChristoph Hellwig <hch@lst.de>
Thu, 19 Sep 2024 06:45:52 +0000 (08:45 +0200)
committerChristoph Hellwig <hch@lst.de>
Thu, 19 Sep 2024 13:19:57 +0000 (15:19 +0200)
Replace the pag and rtg pointers with a generic group pointer.

Signed-off-by: Christoph Hellwig <hch@lst.de>
fs/xfs/xfs_fsmap.c

index c2aa9e1f1223f24dbe6eed1fa7b92d3ba3d233b2..94c88afdd9c78f4f1a42044232529e11f4db12e1 100644 (file)
@@ -161,8 +161,7 @@ struct xfs_getfsmap_info {
        struct xfs_fsmap_head   *head;
        struct fsmap            *fsmap_recs;    /* mapping records */
        struct xfs_buf          *agf_bp;        /* AGF, for refcount queries */
-       struct xfs_perag        *pag;           /* AG info, if applicable */
-       struct xfs_rtgroup      *rtg;           /* rtgroup, if applicable */
+       struct xfs_group        *group;         /* group info, if applicable */
        xfs_daddr_t             next_daddr;     /* next daddr we expect */
        /* daddr of low fsmap key when we're using the rtbitmap */
        xfs_daddr_t             low_daddr;
@@ -219,14 +218,13 @@ xfs_getfsmap_is_shared(
        *stat = false;
        if (!xfs_has_reflink(mp))
                return 0;
-
-       if (info->rtg)
-               cur = xfs_rtrefcountbt_init_cursor(tp, info->rtg);
-       else if (info->pag)
-               cur = xfs_refcountbt_init_cursor(mp, tp, info->agf_bp,
-                               info->pag);
-       else
+       if (!info->group)
                return 0;
+       if (info->group->xg_type == XG_TYPE_RTG)
+               cur = xfs_rtrefcountbt_init_cursor(tp, to_rtg(info->group));
+       else
+               cur = xfs_refcountbt_init_cursor(mp, tp, info->agf_bp,
+                               to_perag(info->group));
 
        /* Are there any shared blocks here? */
        flen = 0;
@@ -342,14 +340,8 @@ xfs_getfsmap_helper(
        if (info->head->fmh_entries >= info->head->fmh_count)
                return -ECANCELED;
 
-       if (info->pag)
-               trace_xfs_fsmap_mapping(mp, info->dev, pag_agno(info->pag),
-                               frec);
-       else if (info->rtg)
-               trace_xfs_fsmap_mapping(mp, info->dev, rtg_rgno(info->rtg),
-                               frec);
-       else
-               trace_xfs_fsmap_mapping(mp, info->dev, NULLAGNUMBER, frec);
+       trace_xfs_fsmap_mapping(mp, info->dev,
+               info->group ? info->group->xg_index : NULLAGNUMBER, frec);
 
        fmr.fmr_device = info->dev;
        fmr.fmr_physical = frec->start_daddr;
@@ -547,7 +539,7 @@ __xfs_getfsmap_datadev(
                 * Set the AG high key from the fsmap high key if this
                 * is the last AG that we're querying.
                 */
-               info->pag = pag;
+               info->group = &pag->pag_group;
                if (pag_agno(pag) == end_ag) {
                        info->high.rm_startblock = XFS_FSB_TO_AGBNO(mp,
                                        end_fsb);
@@ -597,7 +589,7 @@ __xfs_getfsmap_datadev(
                        if (error)
                                break;
                }
-               info->pag = NULL;
+               info->group = NULL;
        }
 
        if (bt_cur)
@@ -607,9 +599,9 @@ __xfs_getfsmap_datadev(
                xfs_trans_brelse(tp, info->agf_bp);
                info->agf_bp = NULL;
        }
-       if (info->pag) {
-               xfs_perag_rele(info->pag);
-               info->pag = NULL;
+       if (info->group) {
+               xfs_perag_rele(pag);
+               info->group = NULL;
        } else if (pag) {
                /* loop termination case */
                xfs_perag_rele(pag);
@@ -632,7 +624,7 @@ xfs_getfsmap_datadev_rmapbt_query(
 
        /* Allocate cursor for this AG and query_range it. */
        *curpp = xfs_rmapbt_init_cursor(tp->t_mountp, tp, info->agf_bp,
-                       info->pag);
+                       to_perag(info->group));
        return xfs_rmap_query_range(*curpp, &info->low, &info->high,
                        xfs_getfsmap_rmapbt_helper, info);
 }
@@ -665,7 +657,7 @@ xfs_getfsmap_datadev_bnobt_query(
 
        /* Allocate cursor for this AG and query_range it. */
        *curpp = xfs_bnobt_init_cursor(tp->t_mountp, tp, info->agf_bp,
-                       info->pag);
+                       to_perag(info->group));
        key->ar_startblock = info->low.rm_startblock;
        key[1].ar_startblock = info->high.rm_startblock;
        return xfs_alloc_query_range(*curpp, key, &key[1],
@@ -808,7 +800,7 @@ xfs_getfsmap_rtdev_rtbitmap(
                        end_rtx = xfs_rtb_to_rtx(mp,
                                        end_rtbno + mp->m_sb.sb_rextsize - 1);
 
-               info->rtg = rtg;
+               info->group = &rtg->rtg_group;
                xfs_rtgroup_lock(rtg, XFS_RTGLOCK_BITMAP_SHARED);
                error = xfs_rtalloc_query_range(rtg, tp, start_rtx, end_rtx,
                                xfs_getfsmap_rtdev_rtbitmap_helper, info);
@@ -834,14 +826,14 @@ xfs_getfsmap_rtdev_rtbitmap(
                }
 
                xfs_rtgroup_unlock(rtg, XFS_RTGLOCK_BITMAP_SHARED);
-               info->rtg = NULL;
+               info->group = NULL;
                start_rtx = 0;
        }
 
-       if (info->rtg) {
-               xfs_rtgroup_unlock(info->rtg, XFS_RTGLOCK_BITMAP_SHARED);
-               xfs_rtgroup_rele(info->rtg);
-               info->rtg = NULL;
+       if (info->group) {
+               xfs_rtgroup_unlock(rtg, XFS_RTGLOCK_BITMAP_SHARED);
+               xfs_rtgroup_rele(rtg);
+               info->group = NULL;
        } else if (rtg) {
                /* loop termination case */
                xfs_rtgroup_rele(rtg);
@@ -857,13 +849,15 @@ xfs_getfsmap_rtdev_rmapbt_query(
        struct xfs_getfsmap_info        *info,
        struct xfs_btree_cur            **curpp)
 {
+       struct xfs_rtgroup              *rtg = to_rtg(info->group);
+
        /* Report any gap at the end of the last rtgroup. */
        if (info->last)
                return xfs_getfsmap_rmapbt_helper(*curpp, &info->high, info);
 
        /* Query the rtrmapbt */
-       xfs_rtgroup_lock(info->rtg, XFS_RTGLOCK_RMAP | XFS_RTGLOCK_REFCOUNT);
-       *curpp = xfs_rtrmapbt_init_cursor(tp, info->rtg);
+       xfs_rtgroup_lock(rtg, XFS_RTGLOCK_RMAP | XFS_RTGLOCK_REFCOUNT);
+       *curpp = xfs_rtrmapbt_init_cursor(tp, rtg);
        return xfs_rmap_query_range(*curpp, &info->low, &info->high,
                        xfs_getfsmap_rmapbt_helper, info);
 }
@@ -935,7 +929,7 @@ xfs_getfsmap_rtdev_rmapbt(
                 * Set the rtgroup high key from the fsmap high key if this
                 * is the last rtgroup that we're querying.
                 */
-               info->rtg = rtg;
+               info->group = &rtg->rtg_group;
                if (rtg_rgno(rtg) == end_rg) {
                        info->high.rm_startblock =
                                xfs_rtb_to_rgbno(mp, end_rtb);
@@ -983,7 +977,7 @@ xfs_getfsmap_rtdev_rmapbt(
                        if (error)
                                break;
                }
-               info->rtg = NULL;
+               info->group = NULL;
        }
 
        if (bt_cur) {
@@ -992,9 +986,9 @@ xfs_getfsmap_rtdev_rmapbt(
                xfs_btree_del_cursor(bt_cur, error < 0 ? XFS_BTREE_ERROR :
                                                         XFS_BTREE_NOERROR);
        }
-       if (info->rtg) {
-               xfs_rtgroup_rele(info->rtg);
-               info->rtg = NULL;
+       if (info->group) {
+               xfs_rtgroup_rele(rtg);
+               info->group = NULL;
        } else if (rtg) {
                /* loop termination case */
                xfs_rtgroup_rele(rtg);
@@ -1211,8 +1205,7 @@ xfs_getfsmap(
 
                info.dev = handlers[i].dev;
                info.last = false;
-               info.pag = NULL;
-               info.rtg = NULL;
+               info.group = NULL;
                info.low_daddr = XFS_BUF_DADDR_NULL;
                info.low.rm_blockcount = 0;
                error = handlers[i].fn(tp, dkeys, &info);