Skip to contentSkip to conversation

fsck.f2fs: detect and recover corrupted quota file

PATCH In review Chao Yu 2 participants 3 messages Sep 19, 2018

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 fsck.f2fs: detect and recover corrupted quota file

Once quota file is corrupted, kernel will set CP_QUOTA_NEED_FSCK_FLAG into checkpoint pack, this patch makes fsck supporting to detect the flag and try to rebuild corrupted quota file.

---
 fsck/fsck.c       |  3 ++-
 fsck/main.c       |  1 +
 fsck/mount.c      | 11 +++++++++--
 include/f2fs_fs.h |  2 ++
 4 files changed, 14 insertions(+), 3 deletions(-)
fsck/fsck.c +2 -1
index 40b95f7054a2..28c913b83355 100644
@@ -2670,7 +2670,8 @@ int fsck_verify(struct f2fs_sb_info *sbi)
 				flush_curseg_sit_entries(sbi);
 			}
 			fix_checkpoint(sbi);
-		} else if (is_set_ckpt_flags(cp, CP_FSCK_FLAG)) {
+		} else if (is_set_ckpt_flags(cp, CP_FSCK_FLAG) ||
+			is_set_ckpt_flags(cp, CP_QUOTA_NEED_FSCK_FLAG)) {
 			write_checkpoint(sbi);
 		}
 	}
fsck/main.c +1 -0
index 714e28a509b9..e20f31ca09e4 100644
@@ -162,6 +162,7 @@ static void add_default_options(void)
 	case CONF_ANDROID:
 		__add_fsck_options();
 	}
+	c.quota_fix = 1;
 }
 
 void f2fs_parse_options(int argc, char *argv[])
fsck/mount.c +9 -2
index 6a3382dbd449..21a39a7222c6 100644
@@ -405,6 +405,8 @@ void print_ckpt_info(struct f2fs_sb_info *sbi)
 void print_cp_state(u32 flag)
 {
 	MSG(0, "Info: checkpoint state = %x : ", flag);
+	if (flag & CP_QUOTA_NEED_FSCK_FLAG)
+		MSG(0, "%s", " quota_need_fsck");
 	if (flag & CP_LARGE_NAT_BITMAP_FLAG)
 		MSG(0, "%s", " large_nat_bitmap");
 	if (flag & CP_NOCRC_RECOVERY_FLAG)
@@ -2541,12 +2543,17 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 
 	print_ckpt_info(sbi);
 
+	if (c.quota_fix) {
+		if (get_cp(ckpt_flags) & CP_QUOTA_NEED_FSCK_FLAG)
+			c.fix_on = 1;
+	}
+
 	if (c.auto_fix || c.preen_mode) {
 		u32 flag = get_cp(ckpt_flags);
 
 		if (flag & CP_FSCK_FLAG ||
-			(exist_qf_ino(sb) && (!(flag & CP_UMOUNT_FLAG) ||
-						flag & CP_ERROR_FLAG))) {
+			flag & CP_QUOTA_NEED_FSCK_FLAG ||
+			(exist_qf_ino(sb) && (flag & CP_ERROR_FLAG))) {
 			c.fix_on = 1;
 		} else if (!c.preen_mode) {
 			print_cp_state(flag);
include/f2fs_fs.h +2 -0
index 9396c785a254..160eaf72f0b6 100644
@@ -372,6 +372,7 @@ struct f2fs_configuration {
 	int defset;
 	int bug_on;
 	int auto_fix;
+	int quota_fix;
 	int preen_mode;
 	int ro;
 	int preserve_limits;		/* preserve quota limits */
@@ -641,6 +642,7 @@ struct f2fs_super_block {
 /*
  * For checkpoint
  */
+#define CP_QUOTA_NEED_FSCK_FLAG		0x00000800
 #define CP_LARGE_NAT_BITMAP_FLAG	0x00000400
 #define CP_NOCRC_RECOVERY_FLAG	0x00000200
 #define CP_TRIMMED_FLAG		0x00000100
Signature · 1 line
2.18.0.rc1
#1 lore raw

Hi, Chao

Quoted 52 lines · Chao Yu

Once quota file is corrupted, kernel will set CP_QUOTA_NEED_FSCK_FLAG into checkpoint pack, this patch makes fsck supporting to detect the flag and try to rebuild corrupted quota file.

---
  fsck/fsck.c       |  3 ++-
  fsck/main.c       |  1 +
  fsck/mount.c      | 11 +++++++++--
  include/f2fs_fs.h |  2 ++
  4 files changed, 14 insertions(+), 3 deletions(-)
fsck/fsck.c +2 -1
index 40b95f7054a2..28c913b83355 100644
@@ -2670,7 +2670,8 @@ int fsck_verify(struct f2fs_sb_info *sbi)
  				flush_curseg_sit_entries(sbi);
  			}
  			fix_checkpoint(sbi);
-		} else if (is_set_ckpt_flags(cp, CP_FSCK_FLAG)) {
+		} else if (is_set_ckpt_flags(cp, CP_FSCK_FLAG) ||
+			is_set_ckpt_flags(cp, CP_QUOTA_NEED_FSCK_FLAG)) {
  			write_checkpoint(sbi);
  		}
  	}
fsck/main.c +1 -0
index 714e28a509b9..e20f31ca09e4 100644
@@ -162,6 +162,7 @@ static void add_default_options(void)
  	case CONF_ANDROID:
  		__add_fsck_options();
  	}
+	c.quota_fix = 1;
  }
 
  void f2fs_parse_options(int argc, char *argv[])
fsck/mount.c +2 -0
index 6a3382dbd449..21a39a7222c6 100644
@@ -405,6 +405,8 @@ void print_ckpt_info(struct f2fs_sb_info *sbi)
  void print_cp_state(u32 flag)
  {
  	MSG(0, "Info: checkpoint state = %x : ", flag);
+	if (flag & CP_QUOTA_NEED_FSCK_FLAG)
+		MSG(0, "%s", " quota_need_fsck");
  	if (flag & CP_LARGE_NAT_BITMAP_FLAG)
  		MSG(0, "%s", " large_nat_bitmap");
  	if (flag & CP_NOCRC_RECOVERY_FLAG)

fsck/mount.c int f2fs_do_mount(struct f2fs_sb_info *sbi) · line 2550

Quoted 8 lines
fsck/mount.c +5 -0
@@ -2541,12 +2543,17 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 
  	print_ckpt_info(sbi);
 
+	if (c.quota_fix) {
+		if (get_cp(ckpt_flags) & CP_QUOTA_NEED_FSCK_FLAG)
+			c.fix_on = 1;
+	}
+

I think we don't need the quota_fix, if -f is set, fsck will always check quota files. If anything wrong, fix_on will be set.

thanks,

Quoted 32 lines
fsck/mount.c +2 -2
  	if (c.auto_fix || c.preen_mode) {
  		u32 flag = get_cp(ckpt_flags);
 
  		if (flag & CP_FSCK_FLAG ||
-			(exist_qf_ino(sb) && (!(flag & CP_UMOUNT_FLAG) ||
-						flag & CP_ERROR_FLAG))) {
+			flag & CP_QUOTA_NEED_FSCK_FLAG ||
+			(exist_qf_ino(sb) && (flag & CP_ERROR_FLAG))) {
  			c.fix_on = 1;
  		} else if (!c.preen_mode) {
  			print_cp_state(flag);
include/f2fs_fs.h +2 -0
index 9396c785a254..160eaf72f0b6 100644
@@ -372,6 +372,7 @@ struct f2fs_configuration {
  	int defset;
  	int bug_on;
  	int auto_fix;
+	int quota_fix;
  	int preen_mode;
  	int ro;
  	int preserve_limits;		/* preserve quota limits */
@@ -641,6 +642,7 @@ struct f2fs_super_block {
  /*
   * For checkpoint
   */
+#define CP_QUOTA_NEED_FSCK_FLAG		0x00000800
  #define CP_LARGE_NAT_BITMAP_FLAG	0x00000400
  #define CP_NOCRC_RECOVERY_FLAG	0x00000200
  #define CP_TRIMMED_FLAG		0x00000100
author
#2 lore raw

Hi Sheng,

Quoted 58 lines · Sheng Yong

Hi, Chao

Quoted 55 lines · Chao Yu

Once quota file is corrupted, kernel will set CP_QUOTA_NEED_FSCK_FLAG into checkpoint pack, this patch makes fsck supporting to detect the flag and try to rebuild corrupted quota file.

---
  fsck/fsck.c       |  3 ++-
  fsck/main.c       |  1 +
  fsck/mount.c      | 11 +++++++++--
  include/f2fs_fs.h |  2 ++
  4 files changed, 14 insertions(+), 3 deletions(-)
fsck/fsck.c +2 -1
index 40b95f7054a2..28c913b83355 100644
@@ -2670,7 +2670,8 @@ int fsck_verify(struct f2fs_sb_info *sbi)
  				flush_curseg_sit_entries(sbi);
  			}
  			fix_checkpoint(sbi);
-		} else if (is_set_ckpt_flags(cp, CP_FSCK_FLAG)) {
+		} else if (is_set_ckpt_flags(cp, CP_FSCK_FLAG) ||
+			is_set_ckpt_flags(cp, CP_QUOTA_NEED_FSCK_FLAG)) {
  			write_checkpoint(sbi);
  		}
  	}
fsck/main.c +1 -0
index 714e28a509b9..e20f31ca09e4 100644
@@ -162,6 +162,7 @@ static void add_default_options(void)
  	case CONF_ANDROID:
  		__add_fsck_options();
  	}
+	c.quota_fix = 1;
  }
 
  void f2fs_parse_options(int argc, char *argv[])
fsck/mount.c +2 -0
index 6a3382dbd449..21a39a7222c6 100644
@@ -405,6 +405,8 @@ void print_ckpt_info(struct f2fs_sb_info *sbi)
  void print_cp_state(u32 flag)
  {
  	MSG(0, "Info: checkpoint state = %x : ", flag);
+	if (flag & CP_QUOTA_NEED_FSCK_FLAG)
+		MSG(0, "%s", " quota_need_fsck");
  	if (flag & CP_LARGE_NAT_BITMAP_FLAG)
  		MSG(0, "%s", " large_nat_bitmap");
  	if (flag & CP_NOCRC_RECOVERY_FLAG)
@@ -2541,12 +2543,17 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 
  	print_ckpt_info(sbi);
 
Quoted 8 lines

fsck/mount.c int f2fs_do_mount(struct f2fs_sb_info *sbi) · line 2550

Quoted 5 lines
fsck/mount.c +5 -0
+	if (c.quota_fix) {
+		if (get_cp(ckpt_flags) & CP_QUOTA_NEED_FSCK_FLAG)
+			c.fix_on = 1;
+	}
+

I think we don't need the quota_fix, if -f is set, fsck will always check quota files. If anything wrong, fix_on will be set.

Yeah, since kernel will be aware of quota file corruption under journalled mode, so I prefer to let fsck to check the CP_QUOTA_NEED_FSCK_FLAG by default and once that flag is set, then do repairing automatically, like we did for CP_FSCK_FLAG. By this way we can avoid traversing all data to check quota info.

So how about just turning o c.fix_on under -a or -p 0 mode? Since in android environment, auto_fix is enabled by default, we can expect above design can work.

Thanks,

Quoted 44 lines

thanks,

Quoted 25 lines
fsck/mount.c +2 -2
  	if (c.auto_fix || c.preen_mode) {
  		u32 flag = get_cp(ckpt_flags);
 
  		if (flag & CP_FSCK_FLAG ||
-			(exist_qf_ino(sb) && (!(flag & CP_UMOUNT_FLAG) ||
-						flag & CP_ERROR_FLAG))) {
+			flag & CP_QUOTA_NEED_FSCK_FLAG ||
+			(exist_qf_ino(sb) && (flag & CP_ERROR_FLAG))) {
  			c.fix_on = 1;
  		} else if (!c.preen_mode) {
  			print_cp_state(flag);
include/f2fs_fs.h +1 -0
index 9396c785a254..160eaf72f0b6 100644
@@ -372,6 +372,7 @@ struct f2fs_configuration {
  	int defset;
  	int bug_on;
  	int auto_fix;
+	int quota_fix;
  	int preen_mode;
  	int ro;
  	int preserve_limits;		/* preserve quota limits */

include/f2fs_fs.h struct f2fs_super_block { · line 648

Quoted 7 lines
include/f2fs_fs.h +1 -0
@@ -641,6 +642,7 @@ struct f2fs_super_block {
  /*
   * For checkpoint
   */
+#define CP_QUOTA_NEED_FSCK_FLAG		0x00000800
  #define CP_LARGE_NAT_BITMAP_FLAG	0x00000400
  #define CP_NOCRC_RECOVERY_FLAG	0x00000200
  #define CP_TRIMMED_FLAG		0x00000100

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel