Skip to content

Commit

Permalink
btrfs: do proper error handling in merge_reloc_roots
Browse files Browse the repository at this point in the history
We have a BUG_ON() if we get an error back from btrfs_get_fs_root().
This honestly should never fail, as at this point we have a solid
coordination of fs root to reloc root, and these roots will all be in
memory.  But in the name of killing BUG_ON()'s remove these and handle
the error condition properly, ASSERT()'ing for developers.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
Josef Bacik authored and David Sterba committed Apr 19, 2021
1 parent 8717cf4 commit 24213fa
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions fs/btrfs/relocation.c
Original file line number Diff line number Diff line change
Expand Up @@ -1969,8 +1969,29 @@ void merge_reloc_roots(struct reloc_control *rc)
root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset,
false);
if (btrfs_root_refs(&reloc_root->root_item) > 0) {
BUG_ON(IS_ERR(root));
BUG_ON(root->reloc_root != reloc_root);
if (IS_ERR(root)) {
/*
* For recovery we read the fs roots on mount,
* and if we didn't find the root then we marked
* the reloc root as a garbage root. For normal
* relocation obviously the root should exist in
* memory. However there's no reason we can't
* handle the error properly here just in case.
*/
ASSERT(0);
ret = PTR_ERR(root);
goto out;
}
if (root->reloc_root != reloc_root) {
/*
* This is actually impossible without something
* going really wrong (like weird race condition
* or cosmic rays).
*/
ASSERT(0);
ret = -EINVAL;
goto out;
}
ret = merge_reloc_root(rc, root);
btrfs_put_root(root);
if (ret) {
Expand Down

0 comments on commit 24213fa

Please sign in to comment.