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

On 2019/7/2 15:42, sunqiuyang wrote:
> 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) {

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,

>               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

Reply via email to