Skip to content

Commit 82742f8

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: pass the exact range to initialize to xfs_initialize_perag
Currently only the new agcount is passed to xfs_initialize_perag, which requires lookups of existing AGs to skip them and complicates error handling. Also pass the previous agcount so that the range that xfs_initialize_perag operates on is exactly defined. That way the extra lookups can be avoided, and error handling can clean up the exact range from the old count to the last added perag structure. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Brian Foster <bfoster@redhat.com> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent af8512c commit 82742f8

File tree

5 files changed

+22
-38
lines changed

5 files changed

+22
-38
lines changed

fs/xfs/libxfs/xfs_ag.c

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -296,27 +296,16 @@ xfs_free_unused_perag_range(
296296
int
297297
xfs_initialize_perag(
298298
struct xfs_mount *mp,
299-
xfs_agnumber_t agcount,
299+
xfs_agnumber_t old_agcount,
300+
xfs_agnumber_t new_agcount,
300301
xfs_rfsblock_t dblocks,
301302
xfs_agnumber_t *maxagi)
302303
{
303304
struct xfs_perag *pag;
304305
xfs_agnumber_t index;
305-
xfs_agnumber_t first_initialised = NULLAGNUMBER;
306306
int error;
307307

308-
/*
309-
* Walk the current per-ag tree so we don't try to initialise AGs
310-
* that already exist (growfs case). Allocate and insert all the
311-
* AGs we don't find ready for initialisation.
312-
*/
313-
for (index = 0; index < agcount; index++) {
314-
pag = xfs_perag_get(mp, index);
315-
if (pag) {
316-
xfs_perag_put(pag);
317-
continue;
318-
}
319-
308+
for (index = old_agcount; index < new_agcount; index++) {
320309
pag = kzalloc(sizeof(*pag), GFP_KERNEL | __GFP_RETRY_MAYFAIL);
321310
if (!pag) {
322311
error = -ENOMEM;
@@ -353,21 +342,17 @@ xfs_initialize_perag(
353342
/* Active ref owned by mount indicates AG is online. */
354343
atomic_set(&pag->pag_active_ref, 1);
355344

356-
/* first new pag is fully initialized */
357-
if (first_initialised == NULLAGNUMBER)
358-
first_initialised = index;
359-
360345
/*
361346
* Pre-calculated geometry
362347
*/
363-
pag->block_count = __xfs_ag_block_count(mp, index, agcount,
348+
pag->block_count = __xfs_ag_block_count(mp, index, new_agcount,
364349
dblocks);
365350
pag->min_block = XFS_AGFL_BLOCK(mp);
366351
__xfs_agino_range(mp, pag->block_count, &pag->agino_min,
367352
&pag->agino_max);
368353
}
369354

370-
index = xfs_set_inode_alloc(mp, agcount);
355+
index = xfs_set_inode_alloc(mp, new_agcount);
371356

372357
if (maxagi)
373358
*maxagi = index;
@@ -381,8 +366,7 @@ xfs_initialize_perag(
381366
out_free_pag:
382367
kfree(pag);
383368
out_unwind_new_pags:
384-
/* unwind any prior newly initialized pags */
385-
xfs_free_unused_perag_range(mp, first_initialised, agcount);
369+
xfs_free_unused_perag_range(mp, old_agcount, index);
386370
return error;
387371
}
388372

fs/xfs/libxfs/xfs_ag.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ __XFS_AG_OPSTATE(agfl_needs_reset, AGFL_NEEDS_RESET)
146146

147147
void xfs_free_unused_perag_range(struct xfs_mount *mp, xfs_agnumber_t agstart,
148148
xfs_agnumber_t agend);
149-
int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t agcount,
150-
xfs_rfsblock_t dcount, xfs_agnumber_t *maxagi);
149+
int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t old_agcount,
150+
xfs_agnumber_t agcount, xfs_rfsblock_t dcount,
151+
xfs_agnumber_t *maxagi);
151152
int xfs_initialize_perag_data(struct xfs_mount *mp, xfs_agnumber_t agno);
152153
void xfs_free_perag(struct xfs_mount *mp);
153154

fs/xfs/xfs_fsops.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ xfs_growfs_data_private(
8787
struct xfs_mount *mp, /* mount point for filesystem */
8888
struct xfs_growfs_data *in) /* growfs data input struct */
8989
{
90+
xfs_agnumber_t oagcount = mp->m_sb.sb_agcount;
9091
struct xfs_buf *bp;
9192
int error;
9293
xfs_agnumber_t nagcount;
9394
xfs_agnumber_t nagimax = 0;
9495
xfs_rfsblock_t nb, nb_div, nb_mod;
9596
int64_t delta;
9697
bool lastag_extended = false;
97-
xfs_agnumber_t oagcount;
9898
struct xfs_trans *tp;
9999
struct aghdr_init_data id = {};
100100
struct xfs_perag *last_pag;
@@ -138,16 +138,14 @@ xfs_growfs_data_private(
138138
if (delta == 0)
139139
return 0;
140140

141-
oagcount = mp->m_sb.sb_agcount;
142-
/* allocate the new per-ag structures */
143-
if (nagcount > oagcount) {
144-
error = xfs_initialize_perag(mp, nagcount, nb, &nagimax);
145-
if (error)
146-
return error;
147-
} else if (nagcount < oagcount) {
148-
/* TODO: shrinking the entire AGs hasn't yet completed */
141+
/* TODO: shrinking the entire AGs hasn't yet completed */
142+
if (nagcount < oagcount)
149143
return -EINVAL;
150-
}
144+
145+
/* allocate the new per-ag structures */
146+
error = xfs_initialize_perag(mp, oagcount, nagcount, nb, &nagimax);
147+
if (error)
148+
return error;
151149

152150
if (delta > 0)
153151
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growdata,

fs/xfs/xfs_log_recover.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3346,6 +3346,7 @@ xlog_do_recover(
33463346
struct xfs_mount *mp = log->l_mp;
33473347
struct xfs_buf *bp = mp->m_sb_bp;
33483348
struct xfs_sb *sbp = &mp->m_sb;
3349+
xfs_agnumber_t orig_agcount = sbp->sb_agcount;
33493350
int error;
33503351

33513352
trace_xfs_log_recover(log, head_blk, tail_blk);
@@ -3393,8 +3394,8 @@ xlog_do_recover(
33933394
/* re-initialise in-core superblock and geometry structures */
33943395
mp->m_features |= xfs_sb_version_to_features(sbp);
33953396
xfs_reinit_percpu_counters(mp);
3396-
error = xfs_initialize_perag(mp, sbp->sb_agcount, sbp->sb_dblocks,
3397-
&mp->m_maxagi);
3397+
error = xfs_initialize_perag(mp, orig_agcount, sbp->sb_agcount,
3398+
sbp->sb_dblocks, &mp->m_maxagi);
33983399
if (error) {
33993400
xfs_warn(mp, "Failed post-recovery per-ag init: %d", error);
34003401
return error;

fs/xfs/xfs_mount.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,8 @@ xfs_mountfs(
810810
/*
811811
* Allocate and initialize the per-ag data.
812812
*/
813-
error = xfs_initialize_perag(mp, sbp->sb_agcount, mp->m_sb.sb_dblocks,
814-
&mp->m_maxagi);
813+
error = xfs_initialize_perag(mp, 0, sbp->sb_agcount,
814+
mp->m_sb.sb_dblocks, &mp->m_maxagi);
815815
if (error) {
816816
xfs_warn(mp, "Failed per-ag init: %d", error);
817817
goto out_free_dir;

0 commit comments

Comments
 (0)