Skip to content

Commit aa67ec6

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: merge the perag freeing helpers
There is no good reason to have two different routines for freeing perag structures for the unmount and error cases. Add two arguments to specify the range of AGs to free to xfs_free_perag, and use that to replace xfs_free_unused_perag_range. The addition RCU grace period for the error case is harmless, and the extra check for the AG to actually exist is not required now that the callers pass the exact known allocated range. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent 82742f8 commit aa67ec6

File tree

4 files changed

+15
-37
lines changed

4 files changed

+15
-37
lines changed

fs/xfs/libxfs/xfs_ag.c

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,20 @@ xfs_initialize_perag_data(
185185
}
186186

187187
/*
188-
* Free up the per-ag resources associated with the mount structure.
188+
* Free up the per-ag resources within the specified AG range.
189189
*/
190190
void
191-
xfs_free_perag(
192-
struct xfs_mount *mp)
191+
xfs_free_perag_range(
192+
struct xfs_mount *mp,
193+
xfs_agnumber_t first_agno,
194+
xfs_agnumber_t end_agno)
195+
193196
{
194-
struct xfs_perag *pag;
195197
xfs_agnumber_t agno;
196198

197-
for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) {
198-
pag = xa_erase(&mp->m_perags, agno);
199+
for (agno = first_agno; agno < end_agno; agno++) {
200+
struct xfs_perag *pag = xa_erase(&mp->m_perags, agno);
201+
199202
ASSERT(pag);
200203
XFS_IS_CORRUPT(pag->pag_mount, atomic_read(&pag->pag_ref) != 0);
201204
xfs_defer_drain_free(&pag->pag_intents_drain);
@@ -270,29 +273,6 @@ xfs_agino_range(
270273
return __xfs_agino_range(mp, xfs_ag_block_count(mp, agno), first, last);
271274
}
272275

273-
/*
274-
* Free perag within the specified AG range, it is only used to free unused
275-
* perags under the error handling path.
276-
*/
277-
void
278-
xfs_free_unused_perag_range(
279-
struct xfs_mount *mp,
280-
xfs_agnumber_t agstart,
281-
xfs_agnumber_t agend)
282-
{
283-
struct xfs_perag *pag;
284-
xfs_agnumber_t index;
285-
286-
for (index = agstart; index < agend; index++) {
287-
pag = xa_erase(&mp->m_perags, index);
288-
if (!pag)
289-
break;
290-
xfs_buf_cache_destroy(&pag->pag_bcache);
291-
xfs_defer_drain_free(&pag->pag_intents_drain);
292-
kfree(pag);
293-
}
294-
}
295-
296276
int
297277
xfs_initialize_perag(
298278
struct xfs_mount *mp,
@@ -366,7 +346,7 @@ xfs_initialize_perag(
366346
out_free_pag:
367347
kfree(pag);
368348
out_unwind_new_pags:
369-
xfs_free_unused_perag_range(mp, old_agcount, index);
349+
xfs_free_perag_range(mp, old_agcount, index);
370350
return error;
371351
}
372352

fs/xfs/libxfs/xfs_ag.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,12 @@ __XFS_AG_OPSTATE(prefers_metadata, PREFERS_METADATA)
144144
__XFS_AG_OPSTATE(allows_inodes, ALLOWS_INODES)
145145
__XFS_AG_OPSTATE(agfl_needs_reset, AGFL_NEEDS_RESET)
146146

147-
void xfs_free_unused_perag_range(struct xfs_mount *mp, xfs_agnumber_t agstart,
148-
xfs_agnumber_t agend);
149147
int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t old_agcount,
150148
xfs_agnumber_t agcount, xfs_rfsblock_t dcount,
151149
xfs_agnumber_t *maxagi);
150+
void xfs_free_perag_range(struct xfs_mount *mp, xfs_agnumber_t first_agno,
151+
xfs_agnumber_t end_agno);
152152
int xfs_initialize_perag_data(struct xfs_mount *mp, xfs_agnumber_t agno);
153-
void xfs_free_perag(struct xfs_mount *mp);
154153

155154
/* Passive AG references */
156155
struct xfs_perag *xfs_perag_get(struct xfs_mount *mp, xfs_agnumber_t agno);

fs/xfs/xfs_fsops.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ xfs_growfs_data_private(
229229
xfs_trans_cancel(tp);
230230
out_free_unused_perag:
231231
if (nagcount > oagcount)
232-
xfs_free_unused_perag_range(mp, oagcount, nagcount);
232+
xfs_free_perag_range(mp, oagcount, nagcount);
233233
return error;
234234
}
235235

fs/xfs/xfs_mount.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ xfs_mountfs(
10481048
xfs_buftarg_drain(mp->m_logdev_targp);
10491049
xfs_buftarg_drain(mp->m_ddev_targp);
10501050
out_free_perag:
1051-
xfs_free_perag(mp);
1051+
xfs_free_perag_range(mp, 0, mp->m_sb.sb_agcount);
10521052
out_free_dir:
10531053
xfs_da_unmount(mp);
10541054
out_remove_uuid:
@@ -1129,8 +1129,7 @@ xfs_unmountfs(
11291129
xfs_errortag_clearall(mp);
11301130
#endif
11311131
shrinker_free(mp->m_inodegc_shrinker);
1132-
xfs_free_perag(mp);
1133-
1132+
xfs_free_perag_range(mp, 0, mp->m_sb.sb_agcount);
11341133
xfs_errortag_del(mp);
11351134
xfs_error_sysfs_del(mp);
11361135
xchk_stats_unregister(mp->m_scrub_stats);

0 commit comments

Comments
 (0)