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 | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame^] | 11 | struct extent_map { |
| 12 | struct rb_node rb_node; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 13 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame^] | 14 | /* all of these are in bytes */ |
| 15 | u64 start; |
| 16 | u64 len; |
| 17 | u64 block_start; |
| 18 | unsigned long flags; |
| 19 | struct block_device *bdev; |
| 20 | atomic_t refs; |
| 21 | int in_tree; |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 22 | }; |
| 23 | |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 24 | struct extent_map_tree { |
| 25 | struct rb_root map; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame^] | 26 | struct extent_map *last; |
| 27 | spinlock_t lock; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 28 | }; |
| 29 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame^] | 30 | static inline u64 extent_map_end(struct extent_map *em) |
| 31 | { |
| 32 | if (em->start + em->len < em->start) |
| 33 | return (u64)-1; |
| 34 | return em->start + em->len; |
| 35 | } |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 36 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame^] | 37 | static inline u64 extent_map_block_end(struct extent_map *em) |
| 38 | { |
| 39 | if (em->block_start + em->len < em->block_start) |
| 40 | return (u64)-1; |
| 41 | return em->block_start + em->len; |
| 42 | } |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 43 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame^] | 44 | 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] | 45 | struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree, |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame^] | 46 | u64 start, u64 len); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 47 | int add_extent_mapping(struct extent_map_tree *tree, |
| 48 | struct extent_map *em); |
| 49 | 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^] | 50 | |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 51 | struct extent_map *alloc_extent_map(gfp_t mask); |
| 52 | void free_extent_map(struct extent_map *em); |
Wyatt Banks | 2f4cbe6 | 2007-11-19 10:22:33 -0500 | [diff] [blame] | 53 | int __init extent_map_init(void); |
Christian Hesse | 17636e0 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 54 | void extent_map_exit(void); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 55 | #endif |