Re: [PATCH] fs: btrfs: fix error return code of btrfs_recover_relocation()

From: Filipe Manana
Date: Fri Mar 05 2021 - 06:29:04 EST


On Fri, Mar 5, 2021 at 9:46 AM Jia-Ju Bai <baijiaju1990@xxxxxxxxx> wrote:
>
> When the list of reloc_roots is empty, no error return code of
> btrfs_recover_relocation() is assigned.
> To fix this bug, err is assigned with -ENOENT as error return code.

No, there isn't any such bug.

If there are no reloc roots, it means there's no relocation to resume,
in which case err is already 0 and we therefore return 0.
By setting err to -ENOENT, that will cause a mount failure on any fs
that does not have relocation to resume.

You could have tested this simply by doing:

$ mkfs.btrfs -f /dev/sdc
$ mount /dev/sdc /mnt/sdc
mount: /mnt/sdc: mount(2) system call failed: No such file or directory.

It's always a good idea to test patches, even if we are very
comfortable with the code they are touching...

Thanks.


>
> Reported-by: TOTE Robot <oslab@xxxxxxxxxxxxxxx>
> Signed-off-by: Jia-Ju Bai <baijiaju1990@xxxxxxxxx>
> ---
> fs/btrfs/relocation.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index 232d5da7b7be..631b672a852f 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -3817,8 +3817,10 @@ int btrfs_recover_relocation(struct btrfs_root *root)
> }
> btrfs_release_path(path);
>
> - if (list_empty(&reloc_roots))
> + if (list_empty(&reloc_roots)) {
> + err = -ENOENT;
> goto out;
> + }
>
> rc = alloc_reloc_control(fs_info);
> if (!rc) {
> --
> 2.17.1
>


--
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”