Skip to content

Commit 3561b9d

Browse files
Liu Bokdave
authored andcommitted
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: Liu Bo <[email protected]> Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 9c8e63d commit 3561b9d

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

fs/btrfs/relocation.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -923,9 +923,16 @@ struct backref_node *build_backref_tree(struct reloc_control *rc,
923923
path2->slots[level]--;
924924

925925
eb = path2->nodes[level];
926-
WARN_ON(btrfs_node_blockptr(eb, path2->slots[level]) !=
927-
cur->bytenr);
928-
926+
if (btrfs_node_blockptr(eb, path2->slots[level]) !=
927+
cur->bytenr) {
928+
btrfs_err(root->fs_info,
929+
"couldn't find block (%llu) (level %d) in tree (%llu) with key (%llu %u %llu)",
930+
cur->bytenr, level - 1, root->objectid,
931+
node_key->objectid, node_key->type,
932+
node_key->offset);
933+
err = -ENOENT;
934+
goto out;
935+
}
929936
lower = cur;
930937
need_check = true;
931938
for (; level < BTRFS_MAX_LEVEL; level++) {
@@ -2686,11 +2693,15 @@ static int do_relocation(struct btrfs_trans_handle *trans,
26862693

26872694
if (!upper->eb) {
26882695
ret = btrfs_search_slot(trans, root, key, path, 0, 1);
2689-
if (ret < 0) {
2690-
err = ret;
2696+
if (ret) {
2697+
if (ret < 0)
2698+
err = ret;
2699+
else
2700+
err = -ENOENT;
2701+
2702+
btrfs_release_path(path);
26912703
break;
26922704
}
2693-
BUG_ON(ret > 0);
26942705

26952706
if (!upper->eb) {
26962707
upper->eb = path->nodes[upper->level];

0 commit comments

Comments
 (0)