Skip to content

Commit 4a201dc

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: update the pag for the last AG at recovery time
Currently log recovery never updates the in-core perag values for the last allocation group when they were grown by growfs. This leads to btree record validation failures for the alloc, ialloc or finotbt trees if a transaction references this new space. Found by Brian's new growfs recovery stress test. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Brian Foster <bfoster@redhat.com> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent 069cf5e commit 4a201dc

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

fs/xfs/libxfs/xfs_ag.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,23 @@ xfs_agino_range(
273273
return __xfs_agino_range(mp, xfs_ag_block_count(mp, agno), first, last);
274274
}
275275

276+
int
277+
xfs_update_last_ag_size(
278+
struct xfs_mount *mp,
279+
xfs_agnumber_t prev_agcount)
280+
{
281+
struct xfs_perag *pag = xfs_perag_grab(mp, prev_agcount - 1);
282+
283+
if (!pag)
284+
return -EFSCORRUPTED;
285+
pag->block_count = __xfs_ag_block_count(mp, prev_agcount - 1,
286+
mp->m_sb.sb_agcount, mp->m_sb.sb_dblocks);
287+
__xfs_agino_range(mp, pag->block_count, &pag->agino_min,
288+
&pag->agino_max);
289+
xfs_perag_rele(pag);
290+
return 0;
291+
}
292+
276293
int
277294
xfs_initialize_perag(
278295
struct xfs_mount *mp,

fs/xfs/libxfs/xfs_ag.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t old_agcount,
150150
void xfs_free_perag_range(struct xfs_mount *mp, xfs_agnumber_t first_agno,
151151
xfs_agnumber_t end_agno);
152152
int xfs_initialize_perag_data(struct xfs_mount *mp, xfs_agnumber_t agno);
153+
int xfs_update_last_ag_size(struct xfs_mount *mp, xfs_agnumber_t prev_agcount);
153154

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

fs/xfs/xfs_buf_item_recover.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,11 @@ xlog_recover_do_primary_sb_buffer(
708708

709709
xlog_recover_do_reg_buffer(mp, item, bp, buf_f, current_lsn);
710710

711+
if (orig_agcount == 0) {
712+
xfs_alert(mp, "Trying to grow file system without AGs");
713+
return -EFSCORRUPTED;
714+
}
715+
711716
/*
712717
* Update the in-core super block from the freshly recovered on-disk one.
713718
*/
@@ -718,15 +723,23 @@ xlog_recover_do_primary_sb_buffer(
718723
return -EFSCORRUPTED;
719724
}
720725

726+
/*
727+
* Growfs can also grow the last existing AG. In this case we also need
728+
* to update the length in the in-core perag structure and values
729+
* depending on it.
730+
*/
731+
error = xfs_update_last_ag_size(mp, orig_agcount);
732+
if (error)
733+
return error;
734+
721735
/*
722736
* Initialize the new perags, and also update various block and inode
723737
* allocator setting based off the number of AGs or total blocks.
724738
* Because of the latter this also needs to happen if the agcount did
725739
* not change.
726740
*/
727-
error = xfs_initialize_perag(mp, orig_agcount,
728-
mp->m_sb.sb_agcount, mp->m_sb.sb_dblocks,
729-
&mp->m_maxagi);
741+
error = xfs_initialize_perag(mp, orig_agcount, mp->m_sb.sb_agcount,
742+
mp->m_sb.sb_dblocks, &mp->m_maxagi);
730743
if (error) {
731744
xfs_warn(mp, "Failed recovery per-ag init: %d", error);
732745
return error;

0 commit comments

Comments
 (0)