[PATCH v3 05/31] ocfs2: abstract the dinode fs_generation mismatch check
From: Joseph Qi
Date: Mon Nov 09 2026 - 07:24:42 EST
The comparison against OCFS2_SB(sb)->fs_generation is open-coded in the
normal validator, the filecheck validator and the repair path. Fold it
into a shared predicate.
Each call site keeps its own log message and return code: the normal
validator escalates through ocfs2_error(), filecheck reports
OCFS2_FILECHECK_ERR_GENERATION, and repair rewrites the field.
No functional change intended.
Signed-off-by: Joseph Qi <joseph.qi@xxxxxxxxxxxxxxxxx>
---
fs/ocfs2/inode.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c
index 8b4652002ae2..6b78b3f3c5fa 100644
--- a/fs/ocfs2/inode.c
+++ b/fs/ocfs2/inode.c
@@ -92,6 +92,12 @@ static bool ocfs2_dinode_has_no_valid_flag(struct ocfs2_dinode *di)
return !(le32_to_cpu(di->i_flags) & OCFS2_VALID_FL);
}
+static bool ocfs2_dinode_has_wrong_fs_generation(struct super_block *sb,
+ struct ocfs2_dinode *di)
+{
+ return le32_to_cpu(di->i_fs_generation) != OCFS2_SB(sb)->fs_generation;
+}
+
static bool ocfs2_valid_inode_mode(umode_t mode)
{
return fs_umode_to_ftype(mode) != FT_UNKNOWN;
@@ -1542,8 +1548,7 @@ int ocfs2_validate_inode_block(struct super_block *sb,
goto bail;
}
- if (le32_to_cpu(di->i_fs_generation) !=
- OCFS2_SB(sb)->fs_generation) {
+ if (ocfs2_dinode_has_wrong_fs_generation(sb, di)) {
rc = ocfs2_error(sb,
"Invalid dinode #%llu: fs_generation is %u\n",
(unsigned long long)bh->b_blocknr,
@@ -1868,8 +1873,7 @@ static int ocfs2_filecheck_validate_inode_block(struct super_block *sb,
goto bail;
}
- if (le32_to_cpu(di->i_fs_generation) !=
- OCFS2_SB(sb)->fs_generation) {
+ if (ocfs2_dinode_has_wrong_fs_generation(sb, di)) {
mlog(ML_ERROR,
"Filecheck: invalid dinode #%llu: fs_generation is %u\n",
(unsigned long long)bh->b_blocknr,
@@ -1964,8 +1968,7 @@ static int ocfs2_filecheck_repair_inode_block(struct super_block *sb,
(unsigned long long)le64_to_cpu(di->i_blkno));
}
- if (le32_to_cpu(di->i_fs_generation) !=
- OCFS2_SB(sb)->fs_generation) {
+ if (ocfs2_dinode_has_wrong_fs_generation(sb, di)) {
di->i_fs_generation = cpu_to_le32(OCFS2_SB(sb)->fs_generation);
changed = 1;
mlog(ML_ERROR,
--
2.39.3