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.

Signed-off-by: Qiuyang Sun <[email protected]>
---
 fsck/fsck.c  | 2 ++
 fsck/mount.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/fsck/fsck.c b/fsck/fsck.c
index 6f0f262..66eb53c 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -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))) =
diff --git a/fsck/mount.c b/fsck/mount.c
index aecd0cd..81ab660 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -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;
        }
-- 
1.8.3.1



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

Reply via email to