diff options
-rw-r--r-- | fs/btrfs/extent_io.c | 2 | ||||
-rw-r--r-- | fs/btrfs/extent_map.c | 17 | ||||
-rw-r--r-- | fs/btrfs/extent_map.h | 6 |
3 files changed, 12 insertions, 13 deletions
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index fbe501d3bd01..2c9fbe3b6eec 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c | |||
@@ -2763,7 +2763,7 @@ __get_extent_map(struct inode *inode, struct page *page, size_t pg_offset, | |||
2763 | 2763 | ||
2764 | if (em_cached && *em_cached) { | 2764 | if (em_cached && *em_cached) { |
2765 | em = *em_cached; | 2765 | em = *em_cached; |
2766 | if (em->in_tree && start >= em->start && | 2766 | if (extent_map_in_tree(em) && start >= em->start && |
2767 | start < extent_map_end(em)) { | 2767 | start < extent_map_end(em)) { |
2768 | atomic_inc(&em->refs); | 2768 | atomic_inc(&em->refs); |
2769 | return em; | 2769 | return em; |
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 | } |
diff --git a/fs/btrfs/extent_map.h b/fs/btrfs/extent_map.h index 93fba716d7f8..f0a645a14d6e 100644 --- a/fs/btrfs/extent_map.h +++ b/fs/btrfs/extent_map.h | |||
@@ -33,7 +33,6 @@ struct extent_map { | |||
33 | unsigned long flags; | 33 | unsigned long flags; |
34 | struct block_device *bdev; | 34 | struct block_device *bdev; |
35 | atomic_t refs; | 35 | atomic_t refs; |
36 | unsigned int in_tree; | ||
37 | unsigned int compress_type; | 36 | unsigned int compress_type; |
38 | struct list_head list; | 37 | struct list_head list; |
39 | }; | 38 | }; |
@@ -44,6 +43,11 @@ struct extent_map_tree { | |||
44 | rwlock_t lock; | 43 | rwlock_t lock; |
45 | }; | 44 | }; |
46 | 45 | ||
46 | static inline int extent_map_in_tree(const struct extent_map *em) | ||
47 | { | ||
48 | return !RB_EMPTY_NODE(&em->rb_node); | ||
49 | } | ||
50 | |||
47 | static inline u64 extent_map_end(struct extent_map *em) | 51 | static inline u64 extent_map_end(struct extent_map *em) |
48 | { | 52 | { |
49 | if (em->start + em->len < em->start) | 53 | if (em->start + em->len < em->start) |