Commit 8717cf44 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: handle extent corruption with select_one_root properly

In corruption cases we could have paths from a block up to no root at
all, and thus we'll BUG_ON(!root) in select_one_root.  Handle this by
adding an ASSERT() for developers, and returning an error for normal
users.
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent e0b085b0
...@@ -2218,7 +2218,13 @@ struct btrfs_root *select_one_root(struct btrfs_backref_node *node) ...@@ -2218,7 +2218,13 @@ struct btrfs_root *select_one_root(struct btrfs_backref_node *node)
cond_resched(); cond_resched();
next = walk_up_backref(next, edges, &index); next = walk_up_backref(next, edges, &index);
root = next->root; root = next->root;
BUG_ON(!root);
/*
* This can occur if we have incomplete extent refs leading all
* the way up a particular path, in this case return -EUCLEAN.
*/
if (!root)
return ERR_PTR(-EUCLEAN);
/* No other choice for non-shareable tree */ /* No other choice for non-shareable tree */
if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state))
...@@ -2608,8 +2614,15 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, ...@@ -2608,8 +2614,15 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans,
BUG_ON(node->processed); BUG_ON(node->processed);
root = select_one_root(node); root = select_one_root(node);
if (root == ERR_PTR(-ENOENT)) { if (IS_ERR(root)) {
ret = PTR_ERR(root);
/* See explanation in select_one_root for the -EUCLEAN case. */
ASSERT(ret == -ENOENT);
if (ret == -ENOENT) {
ret = 0;
update_processed_blocks(rc, node); update_processed_blocks(rc, node);
}
goto out; goto out;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment