]> Git Repo - linux.git/commitdiff
xfs: update the pag for the last AG at recovery time
authorChristoph Hellwig <[email protected]>
Mon, 14 Oct 2024 06:04:55 +0000 (08:04 +0200)
committerCarlos Maiolino <[email protected]>
Tue, 22 Oct 2024 11:37:19 +0000 (13:37 +0200)
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 <[email protected]>
Reviewed-by: Brian Foster <[email protected]>
Signed-off-by: Carlos Maiolino <[email protected]>
fs/xfs/libxfs/xfs_ag.c
fs/xfs/libxfs/xfs_ag.h
fs/xfs/xfs_buf_item_recover.c

index 25cec9dc10c9411a2dd714c9b4a8e0bf3024307b..5ca8d01068273dbdfd8c1326701a6be7d4df0244 100644 (file)
@@ -273,6 +273,23 @@ xfs_agino_range(
        return __xfs_agino_range(mp, xfs_ag_block_count(mp, agno), first, last);
 }
 
+int
+xfs_update_last_ag_size(
+       struct xfs_mount        *mp,
+       xfs_agnumber_t          prev_agcount)
+{
+       struct xfs_perag        *pag = xfs_perag_grab(mp, prev_agcount - 1);
+
+       if (!pag)
+               return -EFSCORRUPTED;
+       pag->block_count = __xfs_ag_block_count(mp, prev_agcount - 1,
+                       mp->m_sb.sb_agcount, mp->m_sb.sb_dblocks);
+       __xfs_agino_range(mp, pag->block_count, &pag->agino_min,
+                       &pag->agino_max);
+       xfs_perag_rele(pag);
+       return 0;
+}
+
 int
 xfs_initialize_perag(
        struct xfs_mount        *mp,
index 6e68d6a3161a0f98638ce381ef487a0bd1f72d9a..9edfe0e9643964ab2d762b51b98347507cb7db46 100644 (file)
@@ -150,6 +150,7 @@ int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t old_agcount,
 void xfs_free_perag_range(struct xfs_mount *mp, xfs_agnumber_t first_agno,
                xfs_agnumber_t end_agno);
 int xfs_initialize_perag_data(struct xfs_mount *mp, xfs_agnumber_t agno);
+int xfs_update_last_ag_size(struct xfs_mount *mp, xfs_agnumber_t prev_agcount);
 
 /* Passive AG references */
 struct xfs_perag *xfs_perag_get(struct xfs_mount *mp, xfs_agnumber_t agno);
index a839ff5dcaa908b6531abb15a6717c061e54782f..5180cbf5a90b4bef8ffd448ef753c1c667e0cf2e 100644 (file)
@@ -708,6 +708,11 @@ xlog_recover_do_primary_sb_buffer(
 
        xlog_recover_do_reg_buffer(mp, item, bp, buf_f, current_lsn);
 
+       if (orig_agcount == 0) {
+               xfs_alert(mp, "Trying to grow file system without AGs");
+               return -EFSCORRUPTED;
+       }
+
        /*
         * Update the in-core super block from the freshly recovered on-disk one.
         */
@@ -718,15 +723,23 @@ xlog_recover_do_primary_sb_buffer(
                return -EFSCORRUPTED;
        }
 
+       /*
+        * Growfs can also grow the last existing AG.  In this case we also need
+        * to update the length in the in-core perag structure and values
+        * depending on it.
+        */
+       error = xfs_update_last_ag_size(mp, orig_agcount);
+       if (error)
+               return error;
+
        /*
         * Initialize the new perags, and also update various block and inode
         * allocator setting based off the number of AGs or total blocks.
         * Because of the latter this also needs to happen if the agcount did
         * not change.
         */
-       error = xfs_initialize_perag(mp, orig_agcount,
-                       mp->m_sb.sb_agcount, mp->m_sb.sb_dblocks,
-                       &mp->m_maxagi);
+       error = xfs_initialize_perag(mp, orig_agcount, mp->m_sb.sb_agcount,
+                       mp->m_sb.sb_dblocks, &mp->m_maxagi);
        if (error) {
                xfs_warn(mp, "Failed recovery per-ag init: %d", error);
                return error;
This page took 0.049517 seconds and 4 git commands to generate.