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 <w...@suse.com> > Signed-off-by: Josef Bacik <jo...@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. ---