From: Dave Chinner Date: Fri, 15 Oct 2021 20:28:25 +0000 (-0400) Subject: xfs: make for_each_perag... a first class citizen X-Git-Tag: libxfs-5.14-sync_2021-10-16~37 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=bcac47dc89d8257dd3c2cc66c9cd133b3baddbae;p=thirdparty%2Fxfsprogs-dev.git xfs: make for_each_perag... a first class citizen 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 Reviewed-by: Brian Foster Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Eric Sandeen --- diff --git a/libxfs/xfs_ag.h b/libxfs/xfs_ag.h index f26f72e47..8f26a7b13 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 */