diff options
Diffstat (limited to 'fs/btrfs/extent_map.c')
-rw-r--r-- | fs/btrfs/extent_map.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index 996ad56b57db..64d08f94485d 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c | |||
@@ -51,7 +51,7 @@ struct extent_map *alloc_extent_map(void) | |||
51 | em = kmem_cache_zalloc(extent_map_cache, GFP_NOFS); | 51 | em = kmem_cache_zalloc(extent_map_cache, GFP_NOFS); |
52 | if (!em) | 52 | if (!em) |
53 | return NULL; | 53 | return NULL; |
54 | em->in_tree = 0; | 54 | RB_CLEAR_NODE(&em->rb_node); |
55 | em->flags = 0; | 55 | em->flags = 0; |
56 | em->compress_type = BTRFS_COMPRESS_NONE; | 56 | em->compress_type = BTRFS_COMPRESS_NONE; |
57 | em->generation = 0; | 57 | em->generation = 0; |
@@ -73,7 +73,7 @@ void free_extent_map(struct extent_map *em) | |||
73 | return; | 73 | return; |
74 | WARN_ON(atomic_read(&em->refs) == 0); | 74 | WARN_ON(atomic_read(&em->refs) == 0); |
75 | if (atomic_dec_and_test(&em->refs)) { | 75 | if (atomic_dec_and_test(&em->refs)) { |
76 | WARN_ON(em->in_tree); | 76 | WARN_ON(extent_map_in_tree(em)); |
77 | WARN_ON(!list_empty(&em->list)); | 77 | WARN_ON(!list_empty(&em->list)); |
78 | kmem_cache_free(extent_map_cache, em); | 78 | kmem_cache_free(extent_map_cache, em); |
79 | } | 79 | } |
@@ -99,8 +99,6 @@ static int tree_insert(struct rb_root *root, struct extent_map *em) | |||
99 | parent = *p; | 99 | parent = *p; |
100 | entry = rb_entry(parent, struct extent_map, rb_node); | 100 | entry = rb_entry(parent, struct extent_map, rb_node); |
101 | 101 | ||
102 | WARN_ON(!entry->in_tree); | ||
103 | |||
104 | if (em->start < entry->start) | 102 | if (em->start < entry->start) |
105 | p = &(*p)->rb_left; | 103 | p = &(*p)->rb_left; |
106 | else if (em->start >= extent_map_end(entry)) | 104 | else if (em->start >= extent_map_end(entry)) |
@@ -128,7 +126,6 @@ static int tree_insert(struct rb_root *root, struct extent_map *em) | |||
128 | if (end > entry->start && em->start < extent_map_end(entry)) | 126 | if (end > entry->start && em->start < extent_map_end(entry)) |
129 | return -EEXIST; | 127 | return -EEXIST; |
130 | 128 | ||
131 | em->in_tree = 1; | ||
132 | rb_link_node(&em->rb_node, orig_parent, p); | 129 | rb_link_node(&em->rb_node, orig_parent, p); |
133 | rb_insert_color(&em->rb_node, root); | 130 | rb_insert_color(&em->rb_node, root); |
134 | return 0; | 131 | return 0; |
@@ -153,8 +150,6 @@ static struct rb_node *__tree_search(struct rb_root *root, u64 offset, | |||
153 | prev = n; | 150 | prev = n; |
154 | prev_entry = entry; | 151 | prev_entry = entry; |
155 | 152 | ||
156 | WARN_ON(!entry->in_tree); | ||
157 | |||
158 | if (offset < entry->start) | 153 | if (offset < entry->start) |
159 | n = n->rb_left; | 154 | n = n->rb_left; |
160 | else if (offset >= extent_map_end(entry)) | 155 | else if (offset >= extent_map_end(entry)) |
@@ -240,12 +235,12 @@ static void try_merge_map(struct extent_map_tree *tree, struct extent_map *em) | |||
240 | em->len += merge->len; | 235 | em->len += merge->len; |
241 | em->block_len += merge->block_len; | 236 | em->block_len += merge->block_len; |
242 | em->block_start = merge->block_start; | 237 | em->block_start = merge->block_start; |
243 | merge->in_tree = 0; | ||
244 | em->mod_len = (em->mod_len + em->mod_start) - merge->mod_start; | 238 | em->mod_len = (em->mod_len + em->mod_start) - merge->mod_start; |
245 | em->mod_start = merge->mod_start; | 239 | em->mod_start = merge->mod_start; |
246 | em->generation = max(em->generation, merge->generation); | 240 | em->generation = max(em->generation, merge->generation); |
247 | 241 | ||
248 | rb_erase(&merge->rb_node, &tree->map); | 242 | rb_erase(&merge->rb_node, &tree->map); |
243 | RB_CLEAR_NODE(&merge->rb_node); | ||
249 | free_extent_map(merge); | 244 | free_extent_map(merge); |
250 | } | 245 | } |
251 | } | 246 | } |
@@ -257,7 +252,7 @@ static void try_merge_map(struct extent_map_tree *tree, struct extent_map *em) | |||
257 | em->len += merge->len; | 252 | em->len += merge->len; |
258 | em->block_len += merge->block_len; | 253 | em->block_len += merge->block_len; |
259 | rb_erase(&merge->rb_node, &tree->map); | 254 | rb_erase(&merge->rb_node, &tree->map); |
260 | merge->in_tree = 0; | 255 | RB_CLEAR_NODE(&merge->rb_node); |
261 | em->mod_len = (merge->mod_start + merge->mod_len) - em->mod_start; | 256 | em->mod_len = (merge->mod_start + merge->mod_len) - em->mod_start; |
262 | em->generation = max(em->generation, merge->generation); | 257 | em->generation = max(em->generation, merge->generation); |
263 | free_extent_map(merge); | 258 | free_extent_map(merge); |
@@ -319,7 +314,7 @@ out: | |||
319 | void clear_em_logging(struct extent_map_tree *tree, struct extent_map *em) | 314 | void clear_em_logging(struct extent_map_tree *tree, struct extent_map *em) |
320 | { | 315 | { |
321 | clear_bit(EXTENT_FLAG_LOGGING, &em->flags); | 316 | clear_bit(EXTENT_FLAG_LOGGING, &em->flags); |
322 | if (em->in_tree) | 317 | if (extent_map_in_tree(em)) |
323 | try_merge_map(tree, em); | 318 | try_merge_map(tree, em); |
324 | } | 319 | } |
325 | 320 | ||
@@ -434,6 +429,6 @@ int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em) | |||
434 | rb_erase(&em->rb_node, &tree->map); | 429 | rb_erase(&em->rb_node, &tree->map); |
435 | if (!test_bit(EXTENT_FLAG_LOGGING, &em->flags)) | 430 | if (!test_bit(EXTENT_FLAG_LOGGING, &em->flags)) |
436 | list_del_init(&em->list); | 431 | list_del_init(&em->list); |
437 | em->in_tree = 0; | 432 | RB_CLEAR_NODE(&em->rb_node); |
438 | return ret; | 433 | return ret; |
439 | } | 434 | } |