diff mbox series

[f2fs-dev] fsck.f2fs: update superblock if invalid

Message ID 20240712020133.140148-5-shengyong@oppo.com (mailing list archive)
State New
Headers show
Series [f2fs-dev] fsck.f2fs: update superblock if invalid | expand

Commit Message

Sheng Yong July 12, 2024, 2:01 a.m. UTC
If a superblock failed in sanity check, it should be fixed. This patch
add a new state `sb_invalid' to tell fsck needs to update superblock
at the end of all checkings.

This patch also cleans up force_stop, abnormal_stop, fs_errors and
sb_invalid by merging them into an `invalid_sb' flags, and each of
them is indicated using one bit.

Signed-off-by: Sheng Yong <shengyong@oppo.com>
---
 fsck/fsck.c       |  6 +++---
 fsck/mount.c      | 16 ++++++++++------
 include/f2fs_fs.h | 11 ++++++++---
 3 files changed, 21 insertions(+), 12 deletions(-)

Comments

Chao Yu July 12, 2024, 7:33 a.m. UTC | #1
On 2024/7/12 10:01, Sheng Yong wrote:
> If a superblock failed in sanity check, it should be fixed. This patch
> add a new state `sb_invalid' to tell fsck needs to update superblock
> at the end of all checkings.
> 
> This patch also cleans up force_stop, abnormal_stop, fs_errors and
> sb_invalid by merging them into an `invalid_sb' flags, and each of
> them is indicated using one bit.
> 
> Signed-off-by: Sheng Yong <shengyong@oppo.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,
diff mbox series

Patch

diff --git a/fsck/fsck.c b/fsck/fsck.c
index b15931eba3a0..89a5913f4a26 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -3661,13 +3661,13 @@  int fsck_verify(struct f2fs_sb_info *sbi)
 			write_checkpoints(sbi);
 		}
 
-		if (c.abnormal_stop)
+		if (c.invalid_sb & SB_ABNORMAL_STOP)
 			memset(sb->s_stop_reason, 0, MAX_STOP_REASON);
 
-		if (c.fs_errors)
+		if (c.invalid_sb & SB_FS_ERRORS)
 			memset(sb->s_errors, 0, MAX_F2FS_ERRORS);
 
-		if (c.abnormal_stop || c.fs_errors)
+		if (c.invalid_sb & SB_NEED_FIX)
 			update_superblock(sb, SB_MASK_ALL);
 
 		/* to return FSCK_ERROR_CORRECTED */
diff --git a/fsck/mount.c b/fsck/mount.c
index 93ca351ef41c..e92e64e6feab 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -701,7 +701,7 @@  void print_sb_stop_reason(struct f2fs_super_block *sb)
 	u8 *reason = sb->s_stop_reason;
 	int i;
 
-	if (!c.force_stop)
+	if (!(c.invalid_sb & SB_FORCE_STOP))
 		return;
 
 	MSG(0, "Info: checkpoint stop reason: ");
@@ -739,7 +739,7 @@  void print_sb_errors(struct f2fs_super_block *sb)
 	u8 *errors = sb->s_errors;
 	int i;
 
-	if (!c.fs_errors)
+	if (!(c.invalid_sb & SB_FS_ERRORS))
 		return;
 
 	MSG(0, "Info: fs errors: ");
@@ -1171,9 +1171,12 @@  int validate_super_block(struct f2fs_sb_info *sbi, enum SB_ADDR sb_addr)
 				VERSION_NAME_LEN);
 		get_kernel_version(c.init_version);
 
-		c.force_stop = is_checkpoint_stop(sbi->raw_super, false);
-		c.abnormal_stop = is_checkpoint_stop(sbi->raw_super, true);
-		c.fs_errors = is_inconsistent_error(sbi->raw_super);
+		if (is_checkpoint_stop(sbi->raw_super, false))
+			c.invalid_sb |= SB_FORCE_STOP;
+		if (is_checkpoint_stop(sbi->raw_super, true))
+			c.invalid_sb |= SB_ABNORMAL_STOP;
+		if (is_inconsistent_error(sbi->raw_super))
+			c.invalid_sb |= SB_FS_ERRORS;
 
 		MSG(0, "Info: MKFS version\n  \"%s\"\n", c.init_version);
 		MSG(0, "Info: FSCK version\n  from \"%s\"\n    to \"%s\"\n",
@@ -1186,6 +1189,7 @@  int validate_super_block(struct f2fs_sb_info *sbi, enum SB_ADDR sb_addr)
 
 	free(sbi->raw_super);
 	sbi->raw_super = NULL;
+	c.invalid_sb |= SB_INVALID;
 	MSG(0, "\tCan't find a valid F2FS superblock at 0x%x\n", sb_addr);
 
 	return -EINVAL;
@@ -1456,7 +1460,7 @@  static int f2fs_should_proceed(struct f2fs_super_block *sb, u32 flag)
 		if (flag & CP_FSCK_FLAG ||
 			flag & CP_DISABLED_FLAG ||
 			flag & CP_QUOTA_NEED_FSCK_FLAG ||
-			c.abnormal_stop || c.fs_errors ||
+			c.invalid_sb & SB_NEED_FIX ||
 			(exist_qf_ino(sb) && (flag & CP_ERROR_FLAG))) {
 			c.fix_on = 1;
 		} else if (!c.preen_mode) {
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 870a6e4823d2..fbd20d207e42 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -1443,6 +1443,13 @@  enum {
 	SSR
 };
 
+/* invalid sb types */
+#define SB_FORCE_STOP		0x1	/* s_stop_reason is set */
+#define SB_ABNORMAL_STOP	0x2	/* s_stop_reason is set except shutdown */
+#define SB_FS_ERRORS		0x4	/* s_erros is set */
+#define SB_INVALID		0x8	/* sb is invalid */
+#define SB_NEED_FIX (SB_ABNORMAL_STOP | SB_FS_ERRORS | SB_INVALID)
+
 #define MAX_CACHE_SUMS			8
 
 struct f2fs_configuration {
@@ -1494,9 +1501,7 @@  struct f2fs_configuration {
 	int force;
 	int defset;
 	int bug_on;
-	int force_stop;
-	int abnormal_stop;
-	int fs_errors;
+	unsigned int invalid_sb;
 	int bug_nat_bits;
 	bool quota_fixed;
 	int alloc_failed;