]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: make for_each_perag... a first class citizen
authorDave Chinner <dchinner@redhat.com>
Fri, 15 Oct 2021 20:28:25 +0000 (16:28 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Fri, 15 Oct 2021 20:28:25 +0000 (16:28 -0400)
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@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_ag.h

index f26f72e4735aecd0ace6956af5d5a1ad49237338..8f26a7b13dbc076e1306c476fd16897a354b0247 100644 (file)
@@ -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 */