[v2,3/6] jbd2: do extra handle when do journal recovery

Message ID 20230210032044.146115-4-yebin@huaweicloud.com
State New
Headers
Series fix error flag covered by journal recovery |

Commit Message

Ye Bin Feb. 10, 2023, 3:20 a.m. UTC
  From: Ye Bin <yebin10@huawei.com>

Ext4 file system's super block in journal maybe not uptodate, when
file system has error, we need set error information when do recover
uper block.

Signed-off-by: Ye Bin <yebin10@huawei.com>
---
 fs/jbd2/recovery.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
  

Patch

diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c
index 8286a9ec122f..83b1a9689984 100644
--- a/fs/jbd2/recovery.c
+++ b/fs/jbd2/recovery.c
@@ -309,6 +309,15 @@  int jbd2_journal_recover(journal_t *journal)
 		return 0;
 	}
 
+	if (journal->j_replay_prepare_callback) {
+		err = journal->j_replay_prepare_callback(journal);
+		if (err) {
+			jbd2_debug(1, "JBD2: failed to prepare replay %d",
+				   err);
+			return err;
+		}
+	}
+
 	err = do_one_pass(journal, &info, PASS_SCAN);
 	if (!err)
 		err = do_one_pass(journal, &info, PASS_REVOKE);
@@ -335,6 +344,10 @@  int jbd2_journal_recover(journal_t *journal)
 		if (!err)
 			err = err2;
 	}
+
+	if (journal->j_replay_end_callback)
+		journal->j_replay_end_callback(journal);
+
 	return err;
 }
 
@@ -687,6 +700,20 @@  static int do_one_pass(journal_t *journal,
 						*((__be32 *)nbh->b_data) =
 						cpu_to_be32(JBD2_MAGIC_NUMBER);
 					}
+					if (unlikely(journal->j_replay_callback)) {
+						err = journal->j_replay_callback(
+							journal, nbh);
+						if (err) {
+							printk(KERN_ERR
+							       "JBD2: replay "
+							       "call back "
+							       "failed.\n");
+							unlock_buffer(nbh);
+							brelse(obh);
+							brelse(nbh);
+							goto failed;
+						}
+					}
 
 					BUFFER_TRACE(nbh, "marking dirty");
 					set_buffer_uptodate(nbh);