Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 1 | #ifndef __EXTENTMAP__ |
| 2 | #define __EXTENTMAP__ |
| 3 | |
| 4 | #include <linux/rbtree.h> |
| 5 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 6 | #define EXTENT_MAP_LAST_BYTE (u64)-4 |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 7 | #define EXTENT_MAP_HOLE (u64)-3 |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 8 | #define EXTENT_MAP_INLINE (u64)-2 |
| 9 | #define EXTENT_MAP_DELALLOC (u64)-1 |
| 10 | |
Chris Mason | 7f3c74f | 2008-07-18 12:01:11 -0400 | [diff] [blame] | 11 | /* bits for the flags field */ |
| 12 | #define EXTENT_FLAG_PINNED 0 /* this entry not yet on disk, don't free it */ |
| 13 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 14 | struct extent_map { |
| 15 | struct rb_node rb_node; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 16 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 17 | /* all of these are in bytes */ |
| 18 | u64 start; |
| 19 | u64 len; |
| 20 | u64 block_start; |
| 21 | unsigned long flags; |
| 22 | struct block_device *bdev; |
| 23 | atomic_t refs; |
| 24 | int in_tree; |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 25 | }; |
| 26 | |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 27 | struct extent_map_tree { |
| 28 | struct rb_root map; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 29 | struct extent_map *last; |
| 30 | spinlock_t lock; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 31 | }; |
| 32 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 33 | static inline u64 extent_map_end(struct extent_map *em) |
| 34 | { |
| 35 | if (em->start + em->len < em->start) |
| 36 | return (u64)-1; |
| 37 | return em->start + em->len; |
| 38 | } |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 39 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 40 | static inline u64 extent_map_block_end(struct extent_map *em) |
| 41 | { |
| 42 | if (em->block_start + em->len < em->block_start) |
| 43 | return (u64)-1; |
| 44 | return em->block_start + em->len; |
| 45 | } |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 46 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 47 | 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] | 48 | struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree, |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 49 | u64 start, u64 len); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 50 | int add_extent_mapping(struct extent_map_tree *tree, |
| 51 | struct extent_map *em); |
| 52 | int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 53 | |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 54 | struct extent_map *alloc_extent_map(gfp_t mask); |
| 55 | void free_extent_map(struct extent_map *em); |
Wyatt Banks | 2f4cbe6 | 2007-11-19 10:22:33 -0500 | [diff] [blame] | 56 | int __init extent_map_init(void); |
Christian Hesse | 17636e0 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 57 | void extent_map_exit(void); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 58 | #endif |