From: Dave Chinner <dchinner@xxxxxxxxxx> Source kernel commit: f250eedcf7621b9a56d563912b4eeacd524422c7 for_each_perag_tag() is defined in xfs_icache.c for local use. Promote this to xfs_ag.h and define equivalent iteration functions so that we can use them to iterate AGs instead to replace open coded perag walks and perag lookups. We also convert as many of the straight forward open coded AG walks to use these iterators as possible. Anything that is not a direct conversion to an iterator is ignored and will be updated in future Signed-off-by: Dave Chinner <dchinner@xxxxxxxxxx> Reviewed-by: Brian Foster <bfoster@xxxxxxxxxx> Reviewed-by: Darrick J. Wong <djwong@xxxxxxxxxx> Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> --- libxfs/xfs_ag.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index f26f72e4..8f26a7b1 100644 --- a/libxfs/xfs_ag.h +++ b/libxfs/xfs_ag.h @@ -114,6 +114,23 @@ struct xfs_perag *xfs_perag_get_tag(struct xfs_mount *, xfs_agnumber_t, int tag); void xfs_perag_put(struct xfs_perag *pag); +/* + * Perag iteration APIs + */ +#define for_each_perag(mp, next_agno, pag) \ + for ((next_agno) = 0, (pag) = xfs_perag_get((mp), 0); \ + (pag) != NULL; \ + (next_agno) = (pag)->pag_agno + 1, \ + xfs_perag_put(pag), \ + (pag) = xfs_perag_get((mp), (next_agno))) + +#define for_each_perag_tag(mp, next_agno, pag, tag) \ + for ((next_agno) = 0, (pag) = xfs_perag_get_tag((mp), 0, (tag)); \ + (pag) != NULL; \ + (next_agno) = (pag)->pag_agno + 1, \ + xfs_perag_put(pag), \ + (pag) = xfs_perag_get_tag((mp), (next_agno), (tag))) + struct aghdr_init_data { /* per ag data */ xfs_agblock_t agno; /* ag to init */