Skip to contentSkip to conversation

fsck.f2fs: allow to fix inconsistency from online resize

PATCH In review sunqiuyang 2 participants 3 messages Jul 2, 2019 – Jul 4, 2019

lore
Share & tools
lore

sunqiuyang

author
#0 lore raw

PATCH 1/1 fsck.f2fs: allow to fix inconsistency from online resize

From: Qiuyang Sun <[email protected]>

During F2FS online resize, if panic or poweroff happens when the new SB has been committed but not the new CP, the FS may end up with an inconsistent state, where user_block_count and free_segment_count in CP can be larger than allowed by the new SB.

This patch allows fsck.f2fs to fix such inconsistency.

---
 fsck/fsck.c  | 2 ++
 fsck/mount.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
fsck/fsck.c +2 -0
index 6f0f262..66eb53c 100644
@@ -2083,6 +2083,8 @@ static void fix_checkpoint(struct f2fs_sb_info *sbi)
 	set_cp(valid_block_count, fsck->chk.valid_blk_cnt);
 	set_cp(valid_node_count, fsck->chk.valid_node_cnt);
 	set_cp(valid_inode_count, fsck->chk.valid_inode_cnt);
+	set_cp(user_block_count, (uint64_t)(get_sb(segment_count_main) -
+			get_cp(overprov_segment_count)) * c.blks_per_seg);
 
 	crc = f2fs_checkpoint_chksum(cp);
 	*((__le32 *)((unsigned char *)cp + get_cp(checksum_offset))) =
fsck/mount.c +1 -1
index aecd0cd..81ab660 100644
@@ -953,7 +953,7 @@ int sanity_check_ckpt(struct f2fs_sb_info *sbi)
 	segment_count_main = get_sb(segment_count_main);
 	log_blocks_per_seg = get_sb(log_blocks_per_seg);
 	if (!user_block_count || user_block_count >=
-			segment_count_main << log_blocks_per_seg) {
+			c.total_sectors / c.sectors_per_blk) {
 		MSG(0, "\tWrong user_block_count(%u)\n", user_block_count);
 		return 1;
 	}
Signature · 8 lines
1.8.3.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw
Quoted 33 lines · sunqiuyang

From: Qiuyang Sun <[email protected]>

During F2FS online resize, if panic or poweroff happens when the new SB has been committed but not the new CP, the FS may end up with an inconsistent state, where user_block_count and free_segment_count in CP can be larger than allowed by the new SB.

This patch allows fsck.f2fs to fix such inconsistency.

---
 fsck/fsck.c  | 2 ++
 fsck/mount.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
fsck/fsck.c +2 -0
index 6f0f262..66eb53c 100644
@@ -2083,6 +2083,8 @@ static void fix_checkpoint(struct f2fs_sb_info *sbi)
 	set_cp(valid_block_count, fsck->chk.valid_blk_cnt);
 	set_cp(valid_node_count, fsck->chk.valid_node_cnt);
 	set_cp(valid_inode_count, fsck->chk.valid_inode_cnt);
+	set_cp(user_block_count, (uint64_t)(get_sb(segment_count_main) -
+			get_cp(overprov_segment_count)) * c.blks_per_seg);
 
 	crc = f2fs_checkpoint_chksum(cp);
 	*((__le32 *)((unsigned char *)cp + get_cp(checksum_offset))) =
fsck/mount.c +0 -0
index aecd0cd..81ab660 100644

fsck/mount.c int sanity_check_ckpt(struct f2fs_sb_info *sbi) · line 956

Quoted 5 lines
fsck/mount.c +1 -1
@@ -953,7 +953,7 @@ int sanity_check_ckpt(struct f2fs_sb_info *sbi)
 	segment_count_main = get_sb(segment_count_main);
 	log_blocks_per_seg = get_sb(log_blocks_per_seg);
 	if (!user_block_count || user_block_count >=
-			segment_count_main << log_blocks_per_seg) {
+			c.total_sectors / c.sectors_per_blk) {

This breaks the previous consistency check, then cp.user_block_count could still be corrupted due to we won't call fix_checkpoint later.

Other concern is if user upgrade kernel only, with low version of fsck, user can't repair image suffering power-cut during online resizing, so I wonder that is there a way to find such inconsistency and give a hint to user that which version of fsck can repair such corruption.

Thanks,

fsck/mount.c int sanity_check_ckpt(struct f2fs_sb_info *sbi) · line 959

Quoted 4 lines
fsck/mount.c +0 -0
 		MSG(0, "\tWrong user_block_count(%u)\n", user_block_count);
 		return 1;
 	}

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

author
#2 lore raw

A quick comment: if cp.user_block_count is corrupted due to resize failure, then cp.free_segment_count will also be corrupted. Then in fsck_verify(), we will find the check "free segment_count matched with CP" fails, and still call fix_checkpoint() later.

Thanks,
________________________________________
From: Yuchao (T)
Sent: Wednesday, July 03, 2019 14:29
To: sunqiuyang; [email protected]; [email protected]
Cc: fangwei (I)
Subject: Re: [PATCH 1/1] fsck.f2fs: allow to fix inconsistency from online resize

Quoted 33 lines · sunqiuyang

From: Qiuyang Sun <[email protected]>

During F2FS online resize, if panic or poweroff happens when the new SB has been committed but not the new CP, the FS may end up with an inconsistent state, where user_block_count and free_segment_count in CP can be larger than allowed by the new SB.

This patch allows fsck.f2fs to fix such inconsistency.

---
 fsck/fsck.c  | 2 ++
 fsck/mount.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
fsck/fsck.c +2 -0
index 6f0f262..66eb53c 100644
@@ -2083,6 +2083,8 @@ static void fix_checkpoint(struct f2fs_sb_info *sbi)
      set_cp(valid_block_count, fsck->chk.valid_blk_cnt);
      set_cp(valid_node_count, fsck->chk.valid_node_cnt);
      set_cp(valid_inode_count, fsck->chk.valid_inode_cnt);
+     set_cp(user_block_count, (uint64_t)(get_sb(segment_count_main) -
+                     get_cp(overprov_segment_count)) * c.blks_per_seg);
 
      crc = f2fs_checkpoint_chksum(cp);
      *((__le32 *)((unsigned char *)cp + get_cp(checksum_offset))) =
fsck/mount.c +0 -0
index aecd0cd..81ab660 100644

fsck/mount.c int sanity_check_ckpt(struct f2fs_sb_info *sbi) · line 956

Quoted 5 lines
fsck/mount.c +1 -1
@@ -953,7 +953,7 @@ int sanity_check_ckpt(struct f2fs_sb_info *sbi)
      segment_count_main = get_sb(segment_count_main);
      log_blocks_per_seg = get_sb(log_blocks_per_seg);
      if (!user_block_count || user_block_count >=
-                     segment_count_main << log_blocks_per_seg) {
+                     c.total_sectors / c.sectors_per_blk) {

This breaks the previous consistency check, then cp.user_block_count could still be corrupted due to we won't call fix_checkpoint later.

Other concern is if user upgrade kernel only, with low version of fsck, user can't repair image suffering power-cut during online resizing, so I wonder that is there a way to find such inconsistency and give a hint to user that which version of fsck can repair such corruption.

Thanks,

fsck/mount.c int sanity_check_ckpt(struct f2fs_sb_info *sbi) · line 959

Quoted 4 lines
fsck/mount.c +0 -0
              MSG(0, "\tWrong user_block_count(%u)\n", user_block_count);
              return 1;
      }

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