Commit 4867268c authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

Btrfs: don't BUG() during drop snapshot

Really there's lots of things that can go wrong here, kill all the
BUG_ON()'s and replace the logic ones with ASSERT()'s and return EIO
instead.
Signed-off-by: default avatarJosef Bacik <jbacik@fb.com>
[ switched to btrfs_err, errors go to common label ]
Reviewed-by: default avatarLiu Bo <bo.li.liu@oracle.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 2fd57fcb
...@@ -8886,15 +8886,13 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, ...@@ -8886,15 +8886,13 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
ret = btrfs_lookup_extent_info(trans, root, bytenr, level - 1, 1, ret = btrfs_lookup_extent_info(trans, root, bytenr, level - 1, 1,
&wc->refs[level - 1], &wc->refs[level - 1],
&wc->flags[level - 1]); &wc->flags[level - 1]);
if (ret < 0) { if (ret < 0)
btrfs_tree_unlock(next); goto out_unlock;
free_extent_buffer(next);
return ret;
}
if (unlikely(wc->refs[level - 1] == 0)) { if (unlikely(wc->refs[level - 1] == 0)) {
btrfs_err(root->fs_info, "Missing references."); btrfs_err(root->fs_info, "Missing references.");
BUG(); ret = -EIO;
goto out_unlock;
} }
*lookup_info = 0; *lookup_info = 0;
...@@ -8946,7 +8944,12 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, ...@@ -8946,7 +8944,12 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
} }
level--; level--;
BUG_ON(level != btrfs_header_level(next)); ASSERT(level == btrfs_header_level(next));
if (level != btrfs_header_level(next)) {
btrfs_err(root->fs_info, "mismatched level");
ret = -EIO;
goto out_unlock;
}
path->nodes[level] = next; path->nodes[level] = next;
path->slots[level] = 0; path->slots[level] = 0;
path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING; path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING;
...@@ -8961,8 +8964,15 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, ...@@ -8961,8 +8964,15 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) { if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
parent = path->nodes[level]->start; parent = path->nodes[level]->start;
} else { } else {
BUG_ON(root->root_key.objectid != ASSERT(root->root_key.objectid ==
btrfs_header_owner(path->nodes[level])); btrfs_header_owner(path->nodes[level]));
if (root->root_key.objectid !=
btrfs_header_owner(path->nodes[level])) {
btrfs_err(root->fs_info,
"mismatched block owner");
ret = -EIO;
goto out_unlock;
}
parent = 0; parent = 0;
} }
...@@ -8977,12 +8987,18 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans, ...@@ -8977,12 +8987,18 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
} }
ret = btrfs_free_extent(trans, root, bytenr, blocksize, parent, ret = btrfs_free_extent(trans, root, bytenr, blocksize, parent,
root->root_key.objectid, level - 1, 0); root->root_key.objectid, level - 1, 0);
BUG_ON(ret); /* -ENOMEM */ if (ret)
goto out_unlock;
} }
*lookup_info = 1;
ret = 1;
out_unlock:
btrfs_tree_unlock(next); btrfs_tree_unlock(next);
free_extent_buffer(next); free_extent_buffer(next);
*lookup_info = 1;
return 1; return ret;
} }
/* /*
......
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