Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 1 | #include <linux/err.h> |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 2 | #include <linux/gfp.h> |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 3 | #include <linux/slab.h> |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 4 | #include <linux/module.h> |
| 5 | #include <linux/spinlock.h> |
Jens Axboe | 0a2118d | 2007-10-19 09:23:05 -0400 | [diff] [blame] | 6 | #include <linux/version.h> |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 7 | #include <linux/hardirq.h> |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 8 | #include "extent_map.h" |
| 9 | |
Chris Mason | 86479a0 | 2007-09-10 19:58:16 -0400 | [diff] [blame] | 10 | /* temporary define until extent_map moves out of btrfs */ |
| 11 | struct kmem_cache *btrfs_cache_create(const char *name, size_t size, |
| 12 | unsigned long extra_flags, |
| 13 | void (*ctor)(void *, struct kmem_cache *, |
| 14 | unsigned long)); |
| 15 | |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 16 | static struct kmem_cache *extent_map_cache; |
Chris Mason | ca66462 | 2007-11-27 11:16:35 -0500 | [diff] [blame] | 17 | |
Wyatt Banks | 2f4cbe6 | 2007-11-19 10:22:33 -0500 | [diff] [blame] | 18 | int __init extent_map_init(void) |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 19 | { |
Chris Mason | 86479a0 | 2007-09-10 19:58:16 -0400 | [diff] [blame] | 20 | extent_map_cache = btrfs_cache_create("extent_map", |
Chris Mason | 6d36dcd | 2007-10-15 16:14:37 -0400 | [diff] [blame] | 21 | sizeof(struct extent_map), 0, |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 22 | NULL); |
Wyatt Banks | 2f4cbe6 | 2007-11-19 10:22:33 -0500 | [diff] [blame] | 23 | if (!extent_map_cache) |
| 24 | return -ENOMEM; |
Wyatt Banks | 2f4cbe6 | 2007-11-19 10:22:33 -0500 | [diff] [blame] | 25 | return 0; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 26 | } |
| 27 | |
Christian Hesse | 17636e0 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 28 | void extent_map_exit(void) |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 29 | { |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 30 | if (extent_map_cache) |
| 31 | kmem_cache_destroy(extent_map_cache); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 32 | } |
| 33 | |
Christoph Hellwig | 9d2423c | 2008-06-11 21:52:17 -0400 | [diff] [blame] | 34 | /** |
| 35 | * extent_map_tree_init - initialize extent map tree |
| 36 | * @tree: tree to initialize |
| 37 | * @mask: flags for memory allocations during tree operations |
| 38 | * |
| 39 | * Initialize the extent tree @tree. Should be called for each new inode |
| 40 | * or other user of the extent_map interface. |
| 41 | */ |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 42 | void extent_map_tree_init(struct extent_map_tree *tree, gfp_t mask) |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 43 | { |
| 44 | tree->map.rb_node = NULL; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 45 | tree->last = NULL; |
| 46 | spin_lock_init(&tree->lock); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 47 | } |
| 48 | EXPORT_SYMBOL(extent_map_tree_init); |
| 49 | |
Christoph Hellwig | 9d2423c | 2008-06-11 21:52:17 -0400 | [diff] [blame] | 50 | /** |
| 51 | * alloc_extent_map - allocate new extent map structure |
| 52 | * @mask: memory allocation flags |
| 53 | * |
| 54 | * Allocate a new extent_map structure. The new structure is |
| 55 | * returned with a reference count of one and needs to be |
| 56 | * freed using free_extent_map() |
| 57 | */ |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 58 | struct extent_map *alloc_extent_map(gfp_t mask) |
| 59 | { |
| 60 | struct extent_map *em; |
| 61 | em = kmem_cache_alloc(extent_map_cache, mask); |
| 62 | if (!em || IS_ERR(em)) |
| 63 | return em; |
| 64 | em->in_tree = 0; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 65 | em->flags = 0; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 66 | atomic_set(&em->refs, 1); |
| 67 | return em; |
| 68 | } |
| 69 | EXPORT_SYMBOL(alloc_extent_map); |
| 70 | |
Christoph Hellwig | 9d2423c | 2008-06-11 21:52:17 -0400 | [diff] [blame] | 71 | /** |
| 72 | * free_extent_map - drop reference count of an extent_map |
| 73 | * @em: extent map beeing releasead |
| 74 | * |
| 75 | * Drops the reference out on @em by one and free the structure |
| 76 | * if the reference count hits zero. |
| 77 | */ |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 78 | void free_extent_map(struct extent_map *em) |
| 79 | { |
Chris Mason | 2bf5a72 | 2007-08-30 11:54:02 -0400 | [diff] [blame] | 80 | if (!em) |
| 81 | return; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 82 | WARN_ON(atomic_read(&em->refs) == 0); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 83 | if (atomic_dec_and_test(&em->refs)) { |
| 84 | WARN_ON(em->in_tree); |
| 85 | kmem_cache_free(extent_map_cache, em); |
| 86 | } |
| 87 | } |
| 88 | EXPORT_SYMBOL(free_extent_map); |
| 89 | |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 90 | static struct rb_node *tree_insert(struct rb_root *root, u64 offset, |
| 91 | struct rb_node *node) |
| 92 | { |
| 93 | struct rb_node ** p = &root->rb_node; |
| 94 | struct rb_node * parent = NULL; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 95 | struct extent_map *entry; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 96 | |
| 97 | while(*p) { |
| 98 | parent = *p; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 99 | entry = rb_entry(parent, struct extent_map, rb_node); |
| 100 | |
| 101 | WARN_ON(!entry->in_tree); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 102 | |
| 103 | if (offset < entry->start) |
| 104 | p = &(*p)->rb_left; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 105 | else if (offset >= extent_map_end(entry)) |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 106 | p = &(*p)->rb_right; |
| 107 | else |
| 108 | return parent; |
| 109 | } |
| 110 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 111 | entry = rb_entry(node, struct extent_map, rb_node); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 112 | entry->in_tree = 1; |
| 113 | rb_link_node(node, parent, p); |
| 114 | rb_insert_color(node, root); |
| 115 | return NULL; |
| 116 | } |
| 117 | |
| 118 | static struct rb_node *__tree_search(struct rb_root *root, u64 offset, |
Chris Mason | 5f56406 | 2008-01-22 16:47:59 -0500 | [diff] [blame] | 119 | struct rb_node **prev_ret, |
| 120 | struct rb_node **next_ret) |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 121 | { |
| 122 | struct rb_node * n = root->rb_node; |
| 123 | struct rb_node *prev = NULL; |
Chris Mason | 5f56406 | 2008-01-22 16:47:59 -0500 | [diff] [blame] | 124 | struct rb_node *orig_prev = NULL; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 125 | struct extent_map *entry; |
| 126 | struct extent_map *prev_entry = NULL; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 127 | |
| 128 | while(n) { |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 129 | entry = rb_entry(n, struct extent_map, rb_node); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 130 | prev = n; |
| 131 | prev_entry = entry; |
| 132 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 133 | WARN_ON(!entry->in_tree); |
| 134 | |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 135 | if (offset < entry->start) |
| 136 | n = n->rb_left; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 137 | else if (offset >= extent_map_end(entry)) |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 138 | n = n->rb_right; |
| 139 | else |
| 140 | return n; |
| 141 | } |
Chris Mason | 5f56406 | 2008-01-22 16:47:59 -0500 | [diff] [blame] | 142 | |
| 143 | if (prev_ret) { |
| 144 | orig_prev = prev; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 145 | while(prev && offset >= extent_map_end(prev_entry)) { |
Chris Mason | 5f56406 | 2008-01-22 16:47:59 -0500 | [diff] [blame] | 146 | prev = rb_next(prev); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 147 | prev_entry = rb_entry(prev, struct extent_map, rb_node); |
Chris Mason | 5f56406 | 2008-01-22 16:47:59 -0500 | [diff] [blame] | 148 | } |
| 149 | *prev_ret = prev; |
| 150 | prev = orig_prev; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 151 | } |
Chris Mason | 5f56406 | 2008-01-22 16:47:59 -0500 | [diff] [blame] | 152 | |
| 153 | if (next_ret) { |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 154 | prev_entry = rb_entry(prev, struct extent_map, rb_node); |
Chris Mason | 5f56406 | 2008-01-22 16:47:59 -0500 | [diff] [blame] | 155 | while(prev && offset < prev_entry->start) { |
| 156 | prev = rb_prev(prev); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 157 | prev_entry = rb_entry(prev, struct extent_map, rb_node); |
Chris Mason | 5f56406 | 2008-01-22 16:47:59 -0500 | [diff] [blame] | 158 | } |
| 159 | *next_ret = prev; |
| 160 | } |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 161 | return NULL; |
| 162 | } |
| 163 | |
| 164 | static inline struct rb_node *tree_search(struct rb_root *root, u64 offset) |
| 165 | { |
| 166 | struct rb_node *prev; |
| 167 | struct rb_node *ret; |
Chris Mason | 5f56406 | 2008-01-22 16:47:59 -0500 | [diff] [blame] | 168 | ret = __tree_search(root, offset, &prev, NULL); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 169 | if (!ret) |
| 170 | return prev; |
| 171 | return ret; |
| 172 | } |
| 173 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 174 | static int mergable_maps(struct extent_map *prev, struct extent_map *next) |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 175 | { |
Chris Mason | 7f3c74f | 2008-07-18 12:01:11 -0400 | [diff] [blame^] | 176 | if (test_bit(EXTENT_FLAG_PINNED, &prev->flags)) |
| 177 | return 0; |
| 178 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 179 | if (extent_map_end(prev) == next->start && |
| 180 | prev->flags == next->flags && |
| 181 | prev->bdev == next->bdev && |
| 182 | ((next->block_start == EXTENT_MAP_HOLE && |
| 183 | prev->block_start == EXTENT_MAP_HOLE) || |
| 184 | (next->block_start == EXTENT_MAP_INLINE && |
| 185 | prev->block_start == EXTENT_MAP_INLINE) || |
| 186 | (next->block_start == EXTENT_MAP_DELALLOC && |
| 187 | prev->block_start == EXTENT_MAP_DELALLOC) || |
| 188 | (next->block_start < EXTENT_MAP_LAST_BYTE - 1 && |
| 189 | next->block_start == extent_map_block_end(prev)))) { |
| 190 | return 1; |
| 191 | } |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 192 | return 0; |
| 193 | } |
| 194 | |
Christoph Hellwig | 9d2423c | 2008-06-11 21:52:17 -0400 | [diff] [blame] | 195 | /** |
| 196 | * add_extent_mapping - add new extent map to the extent tree |
| 197 | * @tree: tree to insert new map in |
| 198 | * @em: map to insert |
| 199 | * |
| 200 | * Insert @em into @tree or perform a simple forward/backward merge with |
| 201 | * existing mappings. The extent_map struct passed in will be inserted |
| 202 | * into the tree directly, with an additional reference taken, or a |
| 203 | * reference dropped if the merge attempt was sucessfull. |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 204 | */ |
| 205 | int add_extent_mapping(struct extent_map_tree *tree, |
| 206 | struct extent_map *em) |
| 207 | { |
| 208 | int ret = 0; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 209 | struct extent_map *merge = NULL; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 210 | struct rb_node *rb; |
| 211 | |
Chris Mason | e6dcd2d | 2008-07-17 12:53:50 -0400 | [diff] [blame] | 212 | BUG_ON(spin_trylock(&tree->lock)); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 213 | rb = tree_insert(&tree->map, em->start, &em->rb_node); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 214 | if (rb) { |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 215 | ret = -EEXIST; |
Chris Mason | e6dcd2d | 2008-07-17 12:53:50 -0400 | [diff] [blame] | 216 | free_extent_map(merge); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 217 | goto out; |
| 218 | } |
| 219 | atomic_inc(&em->refs); |
| 220 | if (em->start != 0) { |
| 221 | rb = rb_prev(&em->rb_node); |
| 222 | if (rb) |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 223 | merge = rb_entry(rb, struct extent_map, rb_node); |
| 224 | if (rb && mergable_maps(merge, em)) { |
| 225 | em->start = merge->start; |
| 226 | em->len += merge->len; |
| 227 | em->block_start = merge->block_start; |
| 228 | merge->in_tree = 0; |
| 229 | rb_erase(&merge->rb_node, &tree->map); |
| 230 | free_extent_map(merge); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 231 | } |
| 232 | } |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 233 | rb = rb_next(&em->rb_node); |
| 234 | if (rb) |
| 235 | merge = rb_entry(rb, struct extent_map, rb_node); |
| 236 | if (rb && mergable_maps(em, merge)) { |
| 237 | em->len += merge->len; |
| 238 | rb_erase(&merge->rb_node, &tree->map); |
| 239 | merge->in_tree = 0; |
| 240 | free_extent_map(merge); |
| 241 | } |
| 242 | tree->last = em; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 243 | out: |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 244 | return ret; |
| 245 | } |
| 246 | EXPORT_SYMBOL(add_extent_mapping); |
| 247 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 248 | static u64 range_end(u64 start, u64 len) |
| 249 | { |
| 250 | if (start + len < start) |
| 251 | return (u64)-1; |
| 252 | return start + len; |
| 253 | } |
| 254 | |
Christoph Hellwig | 9d2423c | 2008-06-11 21:52:17 -0400 | [diff] [blame] | 255 | /** |
| 256 | * lookup_extent_mapping - lookup extent_map |
| 257 | * @tree: tree to lookup in |
| 258 | * @start: byte offset to start the search |
| 259 | * @len: length of the lookup range |
| 260 | * |
| 261 | * Find and return the first extent_map struct in @tree that intersects the |
| 262 | * [start, len] range. There may be additional objects in the tree that |
| 263 | * intersect, so check the object returned carefully to make sure that no |
| 264 | * additional lookups are needed. |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 265 | */ |
| 266 | struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree, |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 267 | u64 start, u64 len) |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 268 | { |
| 269 | struct extent_map *em; |
| 270 | struct rb_node *rb_node; |
Christoph Hellwig | 306929f | 2008-06-10 10:21:04 -0400 | [diff] [blame] | 271 | struct rb_node *prev = NULL; |
| 272 | struct rb_node *next = NULL; |
| 273 | u64 end = range_end(start, len); |
| 274 | |
Chris Mason | e6dcd2d | 2008-07-17 12:53:50 -0400 | [diff] [blame] | 275 | BUG_ON(spin_trylock(&tree->lock)); |
Christoph Hellwig | 306929f | 2008-06-10 10:21:04 -0400 | [diff] [blame] | 276 | em = tree->last; |
| 277 | if (em && end > em->start && start < extent_map_end(em)) |
| 278 | goto found; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 279 | |
Chris Mason | 5f56406 | 2008-01-22 16:47:59 -0500 | [diff] [blame] | 280 | rb_node = __tree_search(&tree->map, start, &prev, &next); |
| 281 | if (!rb_node && prev) { |
| 282 | em = rb_entry(prev, struct extent_map, rb_node); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 283 | if (end > em->start && start < extent_map_end(em)) |
Chris Mason | 5f56406 | 2008-01-22 16:47:59 -0500 | [diff] [blame] | 284 | goto found; |
| 285 | } |
| 286 | if (!rb_node && next) { |
| 287 | em = rb_entry(next, struct extent_map, rb_node); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 288 | if (end > em->start && start < extent_map_end(em)) |
Chris Mason | 5f56406 | 2008-01-22 16:47:59 -0500 | [diff] [blame] | 289 | goto found; |
| 290 | } |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 291 | if (!rb_node) { |
| 292 | em = NULL; |
| 293 | goto out; |
| 294 | } |
| 295 | if (IS_ERR(rb_node)) { |
| 296 | em = ERR_PTR(PTR_ERR(rb_node)); |
| 297 | goto out; |
| 298 | } |
| 299 | em = rb_entry(rb_node, struct extent_map, rb_node); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 300 | if (end > em->start && start < extent_map_end(em)) |
| 301 | goto found; |
| 302 | |
| 303 | em = NULL; |
| 304 | goto out; |
| 305 | |
Chris Mason | 5f56406 | 2008-01-22 16:47:59 -0500 | [diff] [blame] | 306 | found: |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 307 | atomic_inc(&em->refs); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 308 | tree->last = em; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 309 | out: |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 310 | return em; |
| 311 | } |
| 312 | EXPORT_SYMBOL(lookup_extent_mapping); |
| 313 | |
Christoph Hellwig | 9d2423c | 2008-06-11 21:52:17 -0400 | [diff] [blame] | 314 | /** |
| 315 | * remove_extent_mapping - removes an extent_map from the extent tree |
| 316 | * @tree: extent tree to remove from |
| 317 | * @em: extent map beeing removed |
| 318 | * |
| 319 | * Removes @em from @tree. No reference counts are dropped, and no checks |
| 320 | * are done to see if the range is in use |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 321 | */ |
| 322 | int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em) |
| 323 | { |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 324 | int ret = 0; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 325 | |
Chris Mason | 7f3c74f | 2008-07-18 12:01:11 -0400 | [diff] [blame^] | 326 | WARN_ON(test_bit(EXTENT_FLAG_PINNED, &em->flags)); |
Chris Mason | e6dcd2d | 2008-07-17 12:53:50 -0400 | [diff] [blame] | 327 | BUG_ON(spin_trylock(&tree->lock)); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 328 | rb_erase(&em->rb_node, &tree->map); |
| 329 | em->in_tree = 0; |
| 330 | if (tree->last == em) |
| 331 | tree->last = NULL; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 332 | return ret; |
| 333 | } |
| 334 | EXPORT_SYMBOL(remove_extent_mapping); |