diff mbox series

[v8,28/39] btrfs: handle btrfs_search_slot failure in replace_path

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

Commit Message

Josef Bacik March 12, 2021, 8:25 p.m. UTC
This can fail for any number of reasons, why bring the whole box down
with it?

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

David Sterba April 6, 2021, 7:06 p.m. UTC | #1
On Fri, Mar 12, 2021 at 03:25:23PM -0500, Josef Bacik wrote:
> This can fail for any number of reasons, why bring the whole box down
> with it?

I've written something more relevant for the code change.

> Reviewed-by: Qu Wenruo <wqu@suse.com>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/btrfs/relocation.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index 592b2d156626..6e8d89e4733a 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -1322,7 +1322,8 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
>  		path->lowest_level = level;
>  		ret = btrfs_search_slot(trans, src, &key, path, 0, 1);
>  		path->lowest_level = 0;
> -		BUG_ON(ret);
> +		if (ret)
> +			break;

As replace_path returns positive values, ie. the level, search failing
to find the key could return 1 which would be wrongly interpreted if
returned as-is. The usual pattern is to switch that to -ENOENT, like

--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1323,8 +1323,11 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
                path->lowest_level = level;
                ret = btrfs_search_slot(trans, src, &key, path, 0, 1);
                path->lowest_level = 0;
-               if (ret < 0)
+               if (ret) {
+                       if (ret > 0)
+                               ret = -ENOENT;
                        break;
+               }
 
                /*
                 * Info qgroup to trace both subtrees.
---
diff mbox series

Patch

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 592b2d156626..6e8d89e4733a 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1322,7 +1322,8 @@  int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
 		path->lowest_level = level;
 		ret = btrfs_search_slot(trans, src, &key, path, 0, 1);
 		path->lowest_level = 0;
-		BUG_ON(ret);
+		if (ret)
+			break;
 
 		/*
 		 * Info qgroup to trace both subtrees.