Skip to content

Commit 8199287

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: add a xfs_group_next_range helper
Add a helper to iterate over iterate over all groups, which can be used as a simple while loop: struct xfs_group *xg = NULL; while ((xg = xfs_group_next_range(mp, xg, 0, MAX_GROUP))) { ... } This will be wrapped by the realtime group code first, and eventually replace the for_each_rtgroup_from and for_each_rtgroup_range helpers. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent e9c4d8b commit 8199287

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

fs/xfs/libxfs/xfs_group.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,32 @@ xfs_group_grab(
8787
return xg;
8888
}
8989

90+
/*
91+
* Iterate to the next group. To start the iteration at @start_index, a %NULL
92+
* @xg is passed, else the previous group returned from this function. The
93+
* caller should break out of the loop when this returns %NULL. If the caller
94+
* wants to break out of a loop that did not finish it needs to release the
95+
* active reference to @xg using xfs_group_rele() itself.
96+
*/
97+
struct xfs_group *
98+
xfs_group_next_range(
99+
struct xfs_mount *mp,
100+
struct xfs_group *xg,
101+
uint32_t start_index,
102+
uint32_t end_index,
103+
enum xfs_group_type type)
104+
{
105+
uint32_t index = start_index;
106+
107+
if (xg) {
108+
index = xg->xg_gno + 1;
109+
xfs_group_rele(xg);
110+
}
111+
if (index > end_index)
112+
return NULL;
113+
return xfs_group_grab(mp, index, type);
114+
}
115+
90116
/*
91117
* Find the next group after @xg, or the first group if @xg is NULL.
92118
*/

fs/xfs/libxfs/xfs_group.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ void xfs_group_put(struct xfs_group *xg);
2020

2121
struct xfs_group *xfs_group_grab(struct xfs_mount *mp, uint32_t index,
2222
enum xfs_group_type type);
23+
struct xfs_group *xfs_group_next_range(struct xfs_mount *mp,
24+
struct xfs_group *xg, uint32_t start_index, uint32_t end_index,
25+
enum xfs_group_type type);
2326
struct xfs_group *xfs_group_grab_next_mark(struct xfs_mount *mp,
2427
struct xfs_group *xg, xa_mark_t mark, enum xfs_group_type type);
2528
void xfs_group_rele(struct xfs_group *xg);

0 commit comments

Comments
 (0)