提交 3561b9db 编写于 作者: L Liu Bo 提交者: David Sterba

Btrfs: return gracefully from balance if fs tree is corrupted

When relocating tree blocks, we firstly get block information from
back references in the extent tree, we then search fs tree to try to
find all parents of a block.

However, if fs tree is corrupted, eg. if there're some missing
items, we could come across these WARN_ONs and BUG_ONs.

This makes us print some error messages and return gracefully
from balance.
Signed-off-by: NLiu Bo <bo.li.liu@oracle.com>
Reviewed-by: NJosef Bacik <jbacik@fb.com>
Signed-off-by: NDavid Sterba <dsterba@suse.com>
上级 9c8e63db
...@@ -923,9 +923,16 @@ struct backref_node *build_backref_tree(struct reloc_control *rc, ...@@ -923,9 +923,16 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
path2->slots[level]--; path2->slots[level]--;
eb = path2->nodes[level]; eb = path2->nodes[level];
WARN_ON(btrfs_node_blockptr(eb, path2->slots[level]) != if (btrfs_node_blockptr(eb, path2->slots[level]) !=
cur->bytenr); cur->bytenr) {
btrfs_err(root->fs_info,
"couldn't find block (%llu) (level %d) in tree (%llu) with key (%llu %u %llu)",
cur->bytenr, level - 1, root->objectid,
node_key->objectid, node_key->type,
node_key->offset);
err = -ENOENT;
goto out;
}
lower = cur; lower = cur;
need_check = true; need_check = true;
for (; level < BTRFS_MAX_LEVEL; level++) { for (; level < BTRFS_MAX_LEVEL; level++) {
...@@ -2686,11 +2693,15 @@ static int do_relocation(struct btrfs_trans_handle *trans, ...@@ -2686,11 +2693,15 @@ static int do_relocation(struct btrfs_trans_handle *trans,
if (!upper->eb) { if (!upper->eb) {
ret = btrfs_search_slot(trans, root, key, path, 0, 1); ret = btrfs_search_slot(trans, root, key, path, 0, 1);
if (ret < 0) { if (ret) {
err = ret; if (ret < 0)
err = ret;
else
err = -ENOENT;
btrfs_release_path(path);
break; break;
} }
BUG_ON(ret > 0);
if (!upper->eb) { if (!upper->eb) {
upper->eb = path->nodes[upper->level]; upper->eb = path->nodes[upper->level];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册