Skip to contentSkip to conversation

gfs2: mount failure after successful recovery

PATCH New Andreas Gruenbacher 1 participant 7 messages May 19, 2025 GFS2 file system

lore
Share & tools
lore

Andreas Gruenbacher

author maintainer
#0 lore raw

cover gfs2: mount failure after successful recovery

This set of patches fixes an occasional failure to mount a filesystem after it has been successfully recovered. What's happening is that due to incorrect cache invalidation, gfs2_find_jhead() fails to find the log head written during recovery. This is fixed by only looking up the log head before recovery and then updating it instead of looking it up a second time after recovery.

Thanks,
Andreas

Andreas Gruenbacher (6):
gfs2: Minor comments fix
gfs2: Move gfs2_log_pointers_init
gfs2: Simplify gfs2_log_pointers_init
gfs2: Simplify clean_journal
gfs2: Get rid of duplicate log head lookup
gfs2: No more gfs2_find_jhead caching

 fs/gfs2/glops.c    |  5 ++---
 fs/gfs2/log.h      | 11 -----------
 fs/gfs2/lops.c     | 11 ++++-------
 fs/gfs2/lops.h     |  2 +-
 fs/gfs2/recovery.c | 25 +++++++++++++++++--------
 fs/gfs2/recovery.h |  2 ++
 fs/gfs2/super.c    | 18 ++++--------------
 fs/gfs2/util.c     |  2 +-
 8 files changed, 31 insertions(+), 45 deletions(-)
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH 1/6 gfs2: Minor comments fix

Commit 40829760096df ("gfs2: Convert gfs2_find_jhead() to use a folio") replaced grab_cache_page() by filemap_grab_folio(), but the comments were still referring to grab_cache_page().

---
 fs/gfs2/lops.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/gfs2/lops.c +2 -2
index a1022635abc9..ba97e97d3eee 100644
@@ -451,7 +451,7 @@ static bool gfs2_jhead_folio_search(struct gfs2_jdesc *jd,
  * Find the folio with 'index' in the journal's mapping. Search the folio for
  * the journal head if requested (cleanup == false). Release refs on the
  * folio so the page cache can reclaim it. We grabbed a
- * reference on this folio twice, first when we did a grab_cache_page()
+ * reference on this folio twice, first when we did a filemap_grab_folio()
  * to obtain the folio to add it to the bio and second when we do a
  * filemap_get_folio() here to get the folio to wait on while I/O on it is being
  * completed.
@@ -476,7 +476,7 @@ static void gfs2_jhead_process_page(struct gfs2_jdesc *jd, unsigned long index,
 	if (!*done)
 		*done = gfs2_jhead_folio_search(jd, head, folio);
 
-	/* filemap_get_folio() and the earlier grab_cache_page() */
+	/* filemap_get_folio() and the earlier filemap_grab_folio() */
 	folio_put_refs(folio, 2);
 }
 
Signature · 1 line
2.49.0
author maintainer
#2 lore raw

PATCH 2/6 gfs2: Move gfs2_log_pointers_init

In reply to Andreas Gruenbacher

Move gfs2_log_pointers_init to recovery.c: there is no need for inlining this function.

---
 fs/gfs2/log.h      | 11 -----------
 fs/gfs2/recovery.c |  9 +++++++++
 fs/gfs2/recovery.h |  1 +
 3 files changed, 10 insertions(+), 11 deletions(-)
fs/gfs2/log.h +0 -11
index c27b05099c1e..fc30ebdad83a 100644
@@ -44,17 +44,6 @@ __releases(&sdp->sd_log_lock)
 	spin_unlock(&sdp->sd_log_lock);
 }
 
-static inline void gfs2_log_pointers_init(struct gfs2_sbd *sdp,
-					  unsigned int value)
-{
-	if (++value == sdp->sd_jdesc->jd_blocks) {
-		value = 0;
-	}
-	sdp->sd_log_tail = value;
-	sdp->sd_log_flush_tail = value;
-	sdp->sd_log_head = value;
-}
-
 static inline void gfs2_ordered_add_inode(struct gfs2_inode *ip)
 {
 	struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
fs/gfs2/recovery.c +9 -0
index 9080f1b5f434..7776d2092b9b 100644
@@ -581,3 +581,12 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd, bool wait)
 	return wait ? jd->jd_recover_error : 0;
 }
 
+void gfs2_log_pointers_init(struct gfs2_sbd *sdp, unsigned int value)
+{
+	if (++value == sdp->sd_jdesc->jd_blocks) {
+		value = 0;
+	}
+	sdp->sd_log_tail = value;
+	sdp->sd_log_flush_tail = value;
+	sdp->sd_log_head = value;
+}
fs/gfs2/recovery.h +1 -0
index 6a0fd42e1120..630ac490948d 100644
@@ -29,6 +29,7 @@ void gfs2_recover_func(struct work_struct *work);
 int __get_log_header(struct gfs2_sbd *sdp,
 		     const struct gfs2_log_header *lh, unsigned int blkno,
 		     struct gfs2_log_header_host *head);
+void gfs2_log_pointers_init(struct gfs2_sbd *sdp, unsigned int value);
 
 #endif /* __RECOVERY_DOT_H__ */
 
Signature · 1 line
2.49.0
author maintainer
#3 lore raw

PATCH 3/6 gfs2: Simplify gfs2_log_pointers_init

In reply to Andreas Gruenbacher

Move the initialization of sdp->sd_log_sequence and sdp->sd_log_flush_head inside gfs2_log_pointers_init(). Use gfs2_replay_incr_blk().

Before this change, the log head lookup code in freeze_go_xmote_bh() didn't update sdp->sd_log_flush_head. This is now fixed, but the code in freeze_go_xmote_bh() appears to be pretty useless in the first place:
on a frozen filesystem, the log head will not change.

---
 fs/gfs2/glops.c    |  3 +--
 fs/gfs2/recovery.c | 19 ++++++++-----------
 fs/gfs2/recovery.h |  3 ++-
 fs/gfs2/super.c    |  3 +--
 4 files changed, 12 insertions(+), 16 deletions(-)
fs/gfs2/glops.c +1 -2
index 116efe335c32..e153db45bbd9 100644
@@ -607,8 +607,7 @@ static int freeze_go_xmote_bh(struct gfs2_glock *gl)
 		if (gfs2_assert_withdraw_delayed(sdp, head.lh_flags &
 						 GFS2_LOG_HEAD_UNMOUNT))
 			return -EIO;
-		sdp->sd_log_sequence = head.lh_sequence + 1;
-		gfs2_log_pointers_init(sdp, head.lh_blkno);
+		gfs2_log_pointers_init(sdp, &head);
 	}
 	return 0;
 }
fs/gfs2/recovery.c +8 -11
index 7776d2092b9b..db1238480e91 100644
@@ -270,10 +270,6 @@ static void clean_journal(struct gfs2_jdesc *jd,
 	gfs2_write_log_header(sdp, jd, head->lh_sequence + 1, 0, lblock,
 			      GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_RECOVERY,
 			      REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC);
-	if (jd->jd_jid == sdp->sd_lockstruct.ls_jid) {
-		sdp->sd_log_flush_head = lblock;
-		gfs2_log_incr_head(sdp);
-	}
 }
 
 
@@ -581,12 +577,13 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd, bool wait)
 	return wait ? jd->jd_recover_error : 0;
 }
 
-void gfs2_log_pointers_init(struct gfs2_sbd *sdp, unsigned int value)
+void gfs2_log_pointers_init(struct gfs2_sbd *sdp,
+			    struct gfs2_log_header_host *head)
 {
-	if (++value == sdp->sd_jdesc->jd_blocks) {
-		value = 0;
-	}
-	sdp->sd_log_tail = value;
-	sdp->sd_log_flush_tail = value;
-	sdp->sd_log_head = value;
+	sdp->sd_log_sequence = head->lh_sequence + 1;
+	gfs2_replay_incr_blk(sdp->sd_jdesc, &head->lh_blkno);
+	sdp->sd_log_tail = head->lh_blkno;
+	sdp->sd_log_flush_head = head->lh_blkno;
+	sdp->sd_log_flush_tail = head->lh_blkno;
+	sdp->sd_log_head = head->lh_blkno;
 }
fs/gfs2/recovery.h +2 -1
index 630ac490948d..5a5ba72ecd75 100644
@@ -29,7 +29,8 @@ void gfs2_recover_func(struct work_struct *work);
 int __get_log_header(struct gfs2_sbd *sdp,
 		     const struct gfs2_log_header *lh, unsigned int blkno,
 		     struct gfs2_log_header_host *head);
-void gfs2_log_pointers_init(struct gfs2_sbd *sdp, unsigned int value);
+void gfs2_log_pointers_init(struct gfs2_sbd *sdp,
+			    struct gfs2_log_header_host *head);
 
 #endif /* __RECOVERY_DOT_H__ */
 
fs/gfs2/super.c +1 -2
index 54f1efd47a3e..b55aa38a485a 100644
@@ -153,8 +153,7 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
 	}
 
 	/*  Initialize some head of the log stuff  */
-	sdp->sd_log_sequence = head.lh_sequence + 1;
-	gfs2_log_pointers_init(sdp, head.lh_blkno);
+	gfs2_log_pointers_init(sdp, &head);
 
 	error = gfs2_quota_init(sdp);
 	if (!error && gfs2_withdrawing_or_withdrawn(sdp))
Signature · 1 line
2.49.0
author maintainer
#4 lore raw

PATCH 4/6 gfs2: Simplify clean_journal

In reply to Andreas Gruenbacher

In function clean_journal(), update @head to point at the log header that indicates successful recovery: this is where logging needs to resume.

---
 fs/gfs2/recovery.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/gfs2/recovery.c +3 -3
index db1238480e91..5e37574820b7 100644
@@ -264,10 +264,10 @@ static void clean_journal(struct gfs2_jdesc *jd,
 			  struct gfs2_log_header_host *head)
 {
 	struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
-	u32 lblock = head->lh_blkno;
 
-	gfs2_replay_incr_blk(jd, &lblock);
-	gfs2_write_log_header(sdp, jd, head->lh_sequence + 1, 0, lblock,
+	gfs2_replay_incr_blk(jd, &head->lh_blkno);
+	head->lh_sequence++;
+	gfs2_write_log_header(sdp, jd, head->lh_sequence, 0, head->lh_blkno,
 			      GFS2_LOG_HEAD_UNMOUNT | GFS2_LOG_HEAD_RECOVERY,
 			      REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC);
 }
Signature · 1 line
2.49.0
author maintainer
#5 lore raw

PATCH 5/6 gfs2: Get rid of duplicate log head lookup

In reply to Andreas Gruenbacher

Currently at mount time, the recovery code looks up the current log head and, if necessary, replays the log and writes a recovery header to indicate that the log is clean. It does that for each log that may need recovery. We also know that our own log will always be checked as part of that process. Then, the mount code looks up the log head of our own log again.

The double log head lookup can be costly, but more importantly, it is unnecessary because we can trivially compute the position of the log head after recovery; all we need to do for that is bump the position and lh_sequence by one when writing a recovery header.

With that in mind, move the call to gfs2_log_pointers_init() into gfs2_recover_func() and get rid of the double lookup in gfs2_make_fs_rw().

---
 fs/gfs2/recovery.c |  3 +++
 fs/gfs2/super.c    | 15 +++------------
 2 files changed, 6 insertions(+), 12 deletions(-)
fs/gfs2/recovery.c +3 -0
index 5e37574820b7..b3a11105df7c 100644
@@ -530,6 +530,9 @@ void gfs2_recover_func(struct work_struct *work)
 			ktime_ms_delta(t_rep, t_tlck));
 	}
 
+	if (jd->jd_jid == sdp->sd_lockstruct.ls_jid)
+		gfs2_log_pointers_init(sdp, &head);
+
 	gfs2_recovery_done(sdp, jd->jd_jid, LM_RD_SUCCESS);
 
 	if (jlocked) {
fs/gfs2/super.c +3 -12
index b55aa38a485a..a9af02ef580d 100644
@@ -134,27 +134,18 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
 {
 	struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode);
 	struct gfs2_glock *j_gl = ip->i_gl;
-	struct gfs2_log_header_host head;
 	int error;
 
 	j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
 	if (gfs2_withdrawing_or_withdrawn(sdp))
 		return -EIO;
 
-	error = gfs2_find_jhead(sdp->sd_jdesc, &head, false);
-	if (error) {
-		gfs2_consist(sdp);
-		return error;
-	}
-
-	if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
-		gfs2_consist(sdp);
+	if (sdp->sd_log_sequence == 0) {
+		fs_err(sdp, "unknown status of our own journal jid %d",
+		       sdp->sd_lockstruct.ls_jid);
 		return -EIO;
 	}
 
-	/*  Initialize some head of the log stuff  */
-	gfs2_log_pointers_init(sdp, &head);
-
 	error = gfs2_quota_init(sdp);
 	if (!error && gfs2_withdrawing_or_withdrawn(sdp))
 		error = -EIO;
Signature · 1 line
2.49.0
author maintainer
#6 lore raw

PATCH 6/6 gfs2: No more gfs2_find_jhead caching

In reply to Andreas Gruenbacher

We are no longer calling gfs2_find_jhead() on the same log twice, so there is no more reason for keeping the log contents cached across those calls. In addition, log head lookup and log header writing didn't go through the same address space and so the caching wasn't even fully working, anyway.

---
 fs/gfs2/glops.c    | 2 +-
 fs/gfs2/lops.c     | 7 ++-----
 fs/gfs2/lops.h     | 2 +-
 fs/gfs2/recovery.c | 2 +-
 fs/gfs2/super.c    | 2 +-
 fs/gfs2/util.c     | 2 +-
 6 files changed, 7 insertions(+), 10 deletions(-)
fs/gfs2/glops.c +1 -1
index e153db45bbd9..cebd66b22694 100644
@@ -601,7 +601,7 @@ static int freeze_go_xmote_bh(struct gfs2_glock *gl)
 	if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
 		j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
 
-		error = gfs2_find_jhead(sdp->sd_jdesc, &head, false);
+		error = gfs2_find_jhead(sdp->sd_jdesc, &head);
 		if (gfs2_assert_withdraw_delayed(sdp, !error))
 			return error;
 		if (gfs2_assert_withdraw_delayed(sdp, head.lh_flags &
fs/gfs2/lops.c +2 -5
index ba97e97d3eee..9c8c305a75c4 100644
@@ -496,15 +496,13 @@ static struct bio *gfs2_chain_bio(struct bio *prev, unsigned int nr_iovecs)
  * gfs2_find_jhead - find the head of a log
  * @jd: The journal descriptor
  * @head: The log descriptor for the head of the log is returned here
- * @keep_cache: If set inode pages will not be truncated
  *
  * Do a search of a journal by reading it in large chunks using bios and find
  * the valid log entry with the highest sequence number.  (i.e. the log head)
  *
  * Returns: 0 on success, errno otherwise
  */
-int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head,
-		    bool keep_cache)
+int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head)
 {
 	struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
 	struct address_space *mapping = jd->jd_inode->i_mapping;
@@ -593,8 +591,7 @@ int gfs2_find_jhead(struct gfs2_jdesc *jd, struct gfs2_log_header_host *head,
 	if (!ret)
 		ret = filemap_check_wb_err(mapping, since);
 
-	if (!keep_cache)
-		truncate_inode_pages(mapping, 0);
+	truncate_inode_pages(mapping, 0);
 
 	return ret;
 }
fs/gfs2/lops.h +1 -1
index 07890c7b145d..be740bf33666 100644
@@ -20,7 +20,7 @@ void gfs2_log_write(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
 void gfs2_log_submit_bio(struct bio **biop, blk_opf_t opf);
 void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh);
 int gfs2_find_jhead(struct gfs2_jdesc *jd,
-		    struct gfs2_log_header_host *head, bool keep_cache);
+		    struct gfs2_log_header_host *head);
 void gfs2_drain_revokes(struct gfs2_sbd *sdp);
 
 static inline unsigned int buf_limit(struct gfs2_sbd *sdp)
fs/gfs2/recovery.c +1 -1
index b3a11105df7c..24250478b085 100644
@@ -454,7 +454,7 @@ void gfs2_recover_func(struct work_struct *work)
 	if (error)
 		goto fail_gunlock_ji;
 
-	error = gfs2_find_jhead(jd, &head, true);
+	error = gfs2_find_jhead(jd, &head);
 	if (error)
 		goto fail_gunlock_ji;
 	t_jhd = ktime_get();
fs/gfs2/super.c +1 -1
index a9af02ef580d..dbc119f8c762 100644
@@ -360,7 +360,7 @@ static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp)
 		error = gfs2_jdesc_check(jd);
 		if (error)
 			break;
-		error = gfs2_find_jhead(jd, &lh, false);
+		error = gfs2_find_jhead(jd, &lh);
 		if (error)
 			break;
 		if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
fs/gfs2/util.c +1 -1
index 13be8d1d228b..d5a1e63fa257 100644
@@ -73,7 +73,7 @@ int check_journal_clean(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
 			       "mount.\n");
 		goto out_unlock;
 	}
-	error = gfs2_find_jhead(jd, &head, false);
+	error = gfs2_find_jhead(jd, &head);
 	if (error) {
 		if (verbose)
 			fs_err(sdp, "Error parsing journal for spectator "
Signature · 1 line
2.49.0