Re: [f2fs-dev] [PATCH v7] f2fs: unify the error handling of f2fs_is_valid_blkaddr

From: Chao Yu
Date: Tue Feb 20 2024 - 02:58:11 EST


On 2024/2/20 15:45, Zhiguo Niu wrote:


On Tue, Feb 20, 2024 at 2:32 PM Chao Yu <chao@xxxxxxxxxx <mailto:chao@xxxxxxxxxx>> wrote:
>
> On 2024/2/20 13:34, Zhiguo Niu wrote:
> > I think do f2fs_handle_error in __is_bitmap_valid is a good way.
>
> Like this?
>
> ---
>   fs/f2fs/checkpoint.c | 28 ++++++++++++++--------------
>   1 file changed, 14 insertions(+), 14 deletions(-)
>
> diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
> index 87b7c988c8ca..b8a7e83eb4e0 100644
> --- a/fs/f2fs/checkpoint.c
> +++ b/fs/f2fs/checkpoint.c
> @@ -155,21 +155,24 @@ static bool __is_bitmap_valid(struct f2fs_sb_info *sbi, block_t blkaddr,
>                 return exist;
>
>         if ((exist && type == DATA_GENERIC_ENHANCE_UPDATE) ||
> -               (!exist && type == DATA_GENERIC_ENHANCE)) {
> -               f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d",
> -                        blkaddr, exist);
> -               set_sbi_flag(sbi, SBI_NEED_FSCK);
> -               dump_stack();
> -       }
> -
> +               (!exist && type == DATA_GENERIC_ENHANCE))
> +               goto out_err;
> +       if (!exist && type != DATA_GENERIC_ENHANCE_UPDATE)
> +               goto out_handle;
> +       return exist;
> +out_err:
> +       f2fs_err(sbi, "Inconsistent error blkaddr:%u, sit bitmap:%d",
> +                blkaddr, exist);
> +       set_sbi_flag(sbi, SBI_NEED_FSCK);
> +       dump_stack();
> +out_handle:
> +       f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
>         return exist;
>   }
>
>   static bool __f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
>                                         block_t blkaddr, int type)
>   {
> -       bool valid = false;
> -
>         switch (type) {
>         case META_NAT:
>                 break;
> @@ -209,10 +212,7 @@ static bool __f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
>                         dump_stack();
>                         goto err;
>                 } else {
> -                       valid = __is_bitmap_valid(sbi, blkaddr, type);
> -                       if ((!valid && type != DATA_GENERIC_ENHANCE_UPDATE) ||
> -                               (valid && type == DATA_GENERIC_ENHANCE_UPDATE))
> -                               goto err;
> +                       return __is_bitmap_valid(sbi, blkaddr, type);
>                 }
>                 break;
>         case META_GENERIC:
> @@ -227,7 +227,7 @@ static bool __f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
>         return true;
>   err:
>         f2fs_handle_error(sbi, ERROR_INVALID_BLKADDR);
> -       return valid;
> +       return false;
I think it's OK.
Do we need to wait for Jaegeuk Kim’s suggestion or should I update the new patch  version first😀?
thanks!

I guess we'd better to wait for Jaegeuk's comments.

Thanks,

>   }
>
>   bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
> --
> 2.40.1
>
>