diff mbox series

[v3,45/54] btrfs: handle __add_reloc_root failure in btrfs_recover_relocation

Message ID c8b8686a06271891df483dec87e3e6164cbc0f9e.1606938211.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series Cleanup error handling in relocation | expand

Commit Message

Josef Bacik Dec. 2, 2020, 7:51 p.m. UTC
We can already handle errors appropriately from this function, deal with
an error coming from __add_reloc_root appropriately.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Qu Wenruo Dec. 3, 2020, 5:32 a.m. UTC | #1
On 2020/12/3 上午3:51, Josef Bacik wrote:
> We can already handle errors appropriately from this function, deal with
> an error coming from __add_reloc_root appropriately.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

It turns out that we can do less cleanups, as if we error out here, the
fs won't be mounted any way.

Thus things like reloc tree don't need to be dropped.

Thanks,
Qu
> ---
>  fs/btrfs/relocation.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index bcced4e436af..6315e74c1da0 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -3984,7 +3984,12 @@ int btrfs_recover_relocation(struct btrfs_root *root)
>  		}
>  
>  		err = __add_reloc_root(reloc_root);
> -		BUG_ON(err < 0); /* -ENOMEM or logic error */
> +		if (err) {
> +			list_add_tail(&reloc_root->root_list, &reloc_roots);
> +			btrfs_put_root(fs_root);
> +			btrfs_end_transaction(trans);
> +			goto out_unset;
> +		}
>  		fs_root->reloc_root = btrfs_grab_root(reloc_root);
>  		btrfs_put_root(fs_root);
>  	}
>
diff mbox series

Patch

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index bcced4e436af..6315e74c1da0 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3984,7 +3984,12 @@  int btrfs_recover_relocation(struct btrfs_root *root)
 		}
 
 		err = __add_reloc_root(reloc_root);
-		BUG_ON(err < 0); /* -ENOMEM or logic error */
+		if (err) {
+			list_add_tail(&reloc_root->root_list, &reloc_roots);
+			btrfs_put_root(fs_root);
+			btrfs_end_transaction(trans);
+			goto out_unset;
+		}
 		fs_root->reloc_root = btrfs_grab_root(reloc_root);
 		btrfs_put_root(fs_root);
 	}