Skip to content

Commit 4867268

Browse files
Josef Bacikkdave
authored andcommitted
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: Josef Bacik <[email protected]> [ switched to btrfs_err, errors go to common label ] Reviewed-by: Liu Bo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 2fd57fc commit 4867268

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

fs/btrfs/extent-tree.c

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8886,15 +8886,13 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
88868886
ret = btrfs_lookup_extent_info(trans, root, bytenr, level - 1, 1,
88878887
&wc->refs[level - 1],
88888888
&wc->flags[level - 1]);
8889-
if (ret < 0) {
8890-
btrfs_tree_unlock(next);
8891-
free_extent_buffer(next);
8892-
return ret;
8893-
}
8889+
if (ret < 0)
8890+
goto out_unlock;
88948891

88958892
if (unlikely(wc->refs[level - 1] == 0)) {
88968893
btrfs_err(root->fs_info, "Missing references.");
8897-
BUG();
8894+
ret = -EIO;
8895+
goto out_unlock;
88988896
}
88998897
*lookup_info = 0;
89008898

@@ -8946,7 +8944,12 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
89468944
}
89478945

89488946
level--;
8949-
BUG_ON(level != btrfs_header_level(next));
8947+
ASSERT(level == btrfs_header_level(next));
8948+
if (level != btrfs_header_level(next)) {
8949+
btrfs_err(root->fs_info, "mismatched level");
8950+
ret = -EIO;
8951+
goto out_unlock;
8952+
}
89508953
path->nodes[level] = next;
89518954
path->slots[level] = 0;
89528955
path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING;
@@ -8961,8 +8964,15 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
89618964
if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
89628965
parent = path->nodes[level]->start;
89638966
} else {
8964-
BUG_ON(root->root_key.objectid !=
8967+
ASSERT(root->root_key.objectid ==
89658968
btrfs_header_owner(path->nodes[level]));
8969+
if (root->root_key.objectid !=
8970+
btrfs_header_owner(path->nodes[level])) {
8971+
btrfs_err(root->fs_info,
8972+
"mismatched block owner");
8973+
ret = -EIO;
8974+
goto out_unlock;
8975+
}
89668976
parent = 0;
89678977
}
89688978

@@ -8977,12 +8987,18 @@ static noinline int do_walk_down(struct btrfs_trans_handle *trans,
89778987
}
89788988
ret = btrfs_free_extent(trans, root, bytenr, blocksize, parent,
89798989
root->root_key.objectid, level - 1, 0);
8980-
BUG_ON(ret); /* -ENOMEM */
8990+
if (ret)
8991+
goto out_unlock;
89818992
}
8993+
8994+
*lookup_info = 1;
8995+
ret = 1;
8996+
8997+
out_unlock:
89828998
btrfs_tree_unlock(next);
89838999
free_extent_buffer(next);
8984-
*lookup_info = 1;
8985-
return 1;
9000+
9001+
return ret;
89869002
}
89879003

89889004
/*

0 commit comments

Comments
 (0)