]>
Commit | Line | Data |
---|---|---|
d8d5015c GKH |
1 | From 4867268c57ff709a7b6b86ae6f6537d846d1443a Mon Sep 17 00:00:00 2001 |
2 | From: Josef Bacik <jbacik@fb.com> | |
3 | Date: Fri, 23 Sep 2016 13:23:28 +0200 | |
4 | Subject: Btrfs: don't BUG() during drop snapshot | |
5 | ||
6 | From: Josef Bacik <jbacik@fb.com> | |
7 | ||
8 | commit 4867268c57ff709a7b6b86ae6f6537d846d1443a upstream. | |
9 | ||
10 | Really there's lots of things that can go wrong here, kill all the | |
11 | BUG_ON()'s and replace the logic ones with ASSERT()'s and return EIO | |
12 | instead. | |
13 | ||
14 | Signed-off-by: Josef Bacik <jbacik@fb.com> | |
15 | [ switched to btrfs_err, errors go to common label ] | |
16 | Reviewed-by: Liu Bo <bo.li.liu@oracle.com> | |
17 | Signed-off-by: David Sterba <dsterba@suse.com> | |
18 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
19 | ||
20 | --- | |
21 | fs/btrfs/extent-tree.c | 38 +++++++++++++++++++++++++++----------- | |
22 | 1 file changed, 27 insertions(+), 11 deletions(-) | |
23 | ||
24 | --- a/fs/btrfs/extent-tree.c | |
25 | +++ b/fs/btrfs/extent-tree.c | |
26 | @@ -8884,15 +8884,13 @@ static noinline int do_walk_down(struct | |
27 | ret = btrfs_lookup_extent_info(trans, root, bytenr, level - 1, 1, | |
28 | &wc->refs[level - 1], | |
29 | &wc->flags[level - 1]); | |
30 | - if (ret < 0) { | |
31 | - btrfs_tree_unlock(next); | |
32 | - free_extent_buffer(next); | |
33 | - return ret; | |
34 | - } | |
35 | + if (ret < 0) | |
36 | + goto out_unlock; | |
37 | ||
38 | if (unlikely(wc->refs[level - 1] == 0)) { | |
39 | btrfs_err(root->fs_info, "Missing references."); | |
40 | - BUG(); | |
41 | + ret = -EIO; | |
42 | + goto out_unlock; | |
43 | } | |
44 | *lookup_info = 0; | |
45 | ||
46 | @@ -8944,7 +8942,12 @@ static noinline int do_walk_down(struct | |
47 | } | |
48 | ||
49 | level--; | |
50 | - BUG_ON(level != btrfs_header_level(next)); | |
51 | + ASSERT(level == btrfs_header_level(next)); | |
52 | + if (level != btrfs_header_level(next)) { | |
53 | + btrfs_err(root->fs_info, "mismatched level"); | |
54 | + ret = -EIO; | |
55 | + goto out_unlock; | |
56 | + } | |
57 | path->nodes[level] = next; | |
58 | path->slots[level] = 0; | |
59 | path->locks[level] = BTRFS_WRITE_LOCK_BLOCKING; | |
60 | @@ -8959,8 +8962,15 @@ skip: | |
61 | if (wc->flags[level] & BTRFS_BLOCK_FLAG_FULL_BACKREF) { | |
62 | parent = path->nodes[level]->start; | |
63 | } else { | |
64 | - BUG_ON(root->root_key.objectid != | |
65 | + ASSERT(root->root_key.objectid == | |
66 | btrfs_header_owner(path->nodes[level])); | |
67 | + if (root->root_key.objectid != | |
68 | + btrfs_header_owner(path->nodes[level])) { | |
69 | + btrfs_err(root->fs_info, | |
70 | + "mismatched block owner"); | |
71 | + ret = -EIO; | |
72 | + goto out_unlock; | |
73 | + } | |
74 | parent = 0; | |
75 | } | |
76 | ||
77 | @@ -8977,12 +8987,18 @@ skip: | |
78 | } | |
79 | ret = btrfs_free_extent(trans, root, bytenr, blocksize, parent, | |
80 | root->root_key.objectid, level - 1, 0); | |
81 | - BUG_ON(ret); /* -ENOMEM */ | |
82 | + if (ret) | |
83 | + goto out_unlock; | |
84 | } | |
85 | + | |
86 | + *lookup_info = 1; | |
87 | + ret = 1; | |
88 | + | |
89 | +out_unlock: | |
90 | btrfs_tree_unlock(next); | |
91 | free_extent_buffer(next); | |
92 | - *lookup_info = 1; | |
93 | - return 1; | |
94 | + | |
95 | + return ret; | |
96 | } | |
97 | ||
98 | /* |