Skip to contentSkip to conversation

fsck.f2fs: detect and recover corrupted quota file

PATCH In review Chao Yu 3 participants 3 messages Aug 29, 2018 Library code

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/mount.c      | 6 ++++--
 include/f2fs_fs.h | 2 ++
 lib/libf2fs.c     | 2 ++
 4 files changed, 10 insertions(+), 3 deletions(-)
fsck/fsck.c +2 -1
index f080d3c8741c..10b69ef403ef 100644
@@ -2668,7 +2668,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/mount.c +4 -2
index a2448e370c0b..168cf387991f 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)
@@ -2532,8 +2534,8 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 		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
lib/libf2fs.c +2 -0
index a1f8beb1f78d..192b8125de36 100644
@@ -619,6 +619,8 @@ void f2fs_init_configuration(void)
 	/* default root owner */
 	c.root_uid = getuid();
 	c.root_gid = getgid();
+
+	c.quota_fix = 1;
 }
 
 #ifdef HAVE_SETMNTENT
Signature · 6 lines
2.18.0.rc1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
#1 lore raw

Hi, Chao

Quoted 4 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.

Do we need to drop recovery data? Recovery data is never checked by fsck, if fsck tries to rebuild quota, it needs to allocate blocks from cursegs, this may overwrite data blocks which may be recovered latter.

thanks

Quoted 72 lines
---
  fsck/fsck.c       | 3 ++-
  fsck/mount.c      | 6 ++++--
  include/f2fs_fs.h | 2 ++
  lib/libf2fs.c     | 2 ++
  4 files changed, 10 insertions(+), 3 deletions(-)
fsck/fsck.c +2 -1
index f080d3c8741c..10b69ef403ef 100644
@@ -2668,7 +2668,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/mount.c +4 -2
index a2448e370c0b..168cf387991f 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)
@@ -2532,8 +2534,8 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
  		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
lib/libf2fs.c +0 -0
index a1f8beb1f78d..192b8125de36 100644

lib/libf2fs.c void f2fs_init_configuration(void) · line 626

Quoted 8 lines
lib/libf2fs.c +2 -0
@@ -619,6 +619,8 @@ void f2fs_init_configuration(void)
  	/* default root owner */
  	c.root_uid = getuid();
  	c.root_gid = getgid();
+
+	c.quota_fix = 1;
  }
 
  #ifdef HAVE_SETMNTENT

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

#2 lore raw

Hi Sheng,

Quoted 10 lines · Sheng Yong

Hi, Chao

Quoted 4 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.

Do we need to drop recovery data? Recovery data is never checked by fsck, if fsck tries to rebuild quota, it needs to allocate blocks from cursegs, this may overwrite data blocks which may be recovered latter.

IMO, we'd better not to drop those data, so I prefer to support recovering fsynced data in fsck, and do recovery in the condition of:
- needs to allocate block from log header.
- through defined option.

How do you think?

Thanks,

Quoted 82 lines

thanks

Quoted 70 lines

---
  fsck/fsck.c       | 3 ++-
  fsck/mount.c      | 6 ++++--
  include/f2fs_fs.h | 2 ++
  lib/libf2fs.c     | 2 ++

  4 files changed, 10 insertions(+), 3 deletions(-)
fsck/fsck.c +2 -1
index f080d3c8741c..10b69ef403ef 100644
@@ -2668,7 +2668,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/mount.c +2 -0
index a2448e370c0b..168cf387991f 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)
@@ -2532,8 +2534,8 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
           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 +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
lib/libf2fs.c +0 -0
index a1f8beb1f78d..192b8125de36 100644

lib/libf2fs.c void f2fs_init_configuration(void) · line 626

Quoted 8 lines
lib/libf2fs.c +2 -0
@@ -619,6 +619,8 @@ void f2fs_init_configuration(void)
       /* default root owner */
       c.root_uid = getuid();
       c.root_gid = getgid();
+
+    c.quota_fix = 1;
   }
     #ifdef HAVE_SETMNTENT
 
Quoted 7 lines

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linux-f2fs-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel