[PATCH 3/4] xfs: create perag structures as soon as possible during log recovery

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



An unclean log can contain both the transaction that created a new
allocation group and the first transaction that is freeing space from
it, in which case the extent free item recovery requires the perag
structure to be present.

Currently the perag structures are only created after log recovery
has completed, leading a warning and file system shutdown for the
above case.  Fix this by creating new perag structures and updating
the in-memory superblock fields as soon a buffer log item that covers
the primary super block is recovered.

Signed-off-by: Christoph Hellwig <hch@xxxxxx>
---
 fs/xfs/libxfs/xfs_log_recover.h |  2 ++
 fs/xfs/xfs_buf_item_recover.c   | 16 +++++++++
 fs/xfs/xfs_log_recover.c        | 59 ++++++++++++++-------------------
 3 files changed, 43 insertions(+), 34 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_log_recover.h b/fs/xfs/libxfs/xfs_log_recover.h
index 521d327e4c89ed..d0e13c84422d0a 100644
--- a/fs/xfs/libxfs/xfs_log_recover.h
+++ b/fs/xfs/libxfs/xfs_log_recover.h
@@ -165,4 +165,6 @@ void xlog_recover_intent_item(struct xlog *log, struct xfs_log_item *lip,
 int xlog_recover_finish_intent(struct xfs_trans *tp,
 		struct xfs_defer_pending *dfp);
 
+int xlog_recover_update_agcount(struct xfs_mount *mp, struct xfs_dsb *dsb);
+
 #endif	/* __XFS_LOG_RECOVER_H__ */
diff --git a/fs/xfs/xfs_buf_item_recover.c b/fs/xfs/xfs_buf_item_recover.c
index 09e893cf563cb9..033821a56b6ac6 100644
--- a/fs/xfs/xfs_buf_item_recover.c
+++ b/fs/xfs/xfs_buf_item_recover.c
@@ -969,6 +969,22 @@ xlog_recover_buf_commit_pass2(
 			goto out_release;
 	} else {
 		xlog_recover_do_reg_buffer(mp, item, bp, buf_f, current_lsn);
+
+		/*
+		 * Update the in-memory superblock and perag structures from the
+		 * primary SB buffer.
+		 *
+		 * This is required because transactions running after growf
+		 * s may require in-memory structures like the perag right after
+		 * committing the growfs transaction that created the underlying
+		 * objects.
+		 */
+		if ((xfs_blft_from_flags(buf_f) & XFS_BLFT_SB_BUF) &&
+		    xfs_buf_daddr(bp) == 0) {
+			error = xlog_recover_update_agcount(mp, bp->b_addr);
+			if (error)
+				goto out_release;
+		}
 	}
 
 	/*
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index 2af02b32f419c2..7d7ab146cae758 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -3334,6 +3334,30 @@ xlog_do_log_recovery(
 	return error;
 }
 
+int
+xlog_recover_update_agcount(
+	struct xfs_mount		*mp,
+	struct xfs_dsb			*dsb)
+{
+	xfs_agnumber_t			old_agcount = mp->m_sb.sb_agcount;
+	int				error;
+
+	xfs_sb_from_disk(&mp->m_sb, dsb);
+	if (mp->m_sb.sb_agcount < old_agcount) {
+		xfs_alert(mp, "Shrinking AG count in log recovery");
+		return -EFSCORRUPTED;
+	}
+	mp->m_features |= xfs_sb_version_to_features(&mp->m_sb);
+	error = xfs_initialize_perag(mp, old_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;
+	}
+	mp->m_alloc_set_aside = xfs_alloc_set_aside(mp);
+	return 0;
+}
+
 /*
  * Do the actual recovery
  */
@@ -3343,10 +3367,6 @@ xlog_do_recover(
 	xfs_daddr_t		head_blk,
 	xfs_daddr_t		tail_blk)
 {
-	struct xfs_mount	*mp = log->l_mp;
-	struct xfs_buf		*bp = mp->m_sb_bp;
-	struct xfs_sb		*sbp = &mp->m_sb;
-	xfs_agnumber_t		old_agcount = sbp->sb_agcount;
 	int			error;
 
 	trace_xfs_log_recover(log, head_blk, tail_blk);
@@ -3371,36 +3391,7 @@ xlog_do_recover(
 	 */
 	xfs_ail_assign_tail_lsn(log->l_ailp);
 
-	/*
-	 * Now that we've finished replaying all buffer and inode updates,
-	 * re-read the superblock and reverify it.
-	 */
-	xfs_buf_lock(bp);
-	xfs_buf_hold(bp);
-	error = _xfs_buf_read(bp, XBF_READ);
-	if (error) {
-		if (!xlog_is_shutdown(log)) {
-			xfs_buf_ioerror_alert(bp, __this_address);
-			ASSERT(0);
-		}
-		xfs_buf_relse(bp);
-		return error;
-	}
-
-	/* Convert superblock from on-disk format */
-	xfs_sb_from_disk(sbp, bp->b_addr);
-	xfs_buf_relse(bp);
-
-	/* re-initialise in-core superblock and geometry structures */
-	mp->m_features |= xfs_sb_version_to_features(sbp);
-	xfs_reinit_percpu_counters(mp);
-	error = xfs_initialize_perag(mp, old_agcount, sbp->sb_agcount,
-			sbp->sb_dblocks, &mp->m_maxagi);
-	if (error) {
-		xfs_warn(mp, "Failed post-recovery per-ag init: %d", error);
-		return error;
-	}
-	mp->m_alloc_set_aside = xfs_alloc_set_aside(mp);
+	xfs_reinit_percpu_counters(log->l_mp);
 
 	/* Normal transactions can now occur */
 	clear_bit(XLOG_ACTIVE_RECOVERY, &log->l_opstate);
-- 
2.45.2





[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux