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 */ |
Chris Mason | c8b9781 | 2008-10-29 14:49:59 -0400 | [diff] [blame] | 13 | #define EXTENT_FLAG_COMPRESSED 1 |
Yan Zheng | 9036c10 | 2008-10-30 14:19:41 -0400 | [diff] [blame] | 14 | #define EXTENT_FLAG_VACANCY 2 /* no file extent item found */ |
Yan Zheng | d899e05 | 2008-10-30 14:25:28 -0400 | [diff] [blame] | 15 | #define EXTENT_FLAG_PREALLOC 3 /* pre-allocated extent */ |
Chris Mason | 7f3c74f | 2008-07-18 12:01:11 -0400 | [diff] [blame] | 16 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 17 | struct extent_map { |
| 18 | struct rb_node rb_node; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 19 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 20 | /* all of these are in bytes */ |
| 21 | u64 start; |
| 22 | u64 len; |
Yan Zheng | ff5b7ee | 2008-11-10 07:34:43 -0500 | [diff] [blame] | 23 | u64 orig_start; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 24 | u64 block_start; |
Chris Mason | c8b9781 | 2008-10-29 14:49:59 -0400 | [diff] [blame] | 25 | u64 block_len; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 26 | unsigned long flags; |
| 27 | struct block_device *bdev; |
| 28 | atomic_t refs; |
| 29 | int in_tree; |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 30 | }; |
| 31 | |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 32 | struct extent_map_tree { |
| 33 | struct rb_root map; |
Chris Mason | 890871b | 2009-09-02 16:24:52 -0400 | [diff] [blame] | 34 | rwlock_t lock; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 35 | }; |
| 36 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 37 | static inline u64 extent_map_end(struct extent_map *em) |
| 38 | { |
| 39 | if (em->start + em->len < em->start) |
| 40 | return (u64)-1; |
| 41 | return em->start + em->len; |
| 42 | } |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 43 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 44 | static inline u64 extent_map_block_end(struct extent_map *em) |
| 45 | { |
Chris Mason | c8b9781 | 2008-10-29 14:49:59 -0400 | [diff] [blame] | 46 | if (em->block_start + em->block_len < em->block_start) |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 47 | return (u64)-1; |
Chris Mason | c8b9781 | 2008-10-29 14:49:59 -0400 | [diff] [blame] | 48 | return em->block_start + em->block_len; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 49 | } |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 50 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 51 | 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] | 52 | struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree, |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 53 | u64 start, u64 len); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 54 | int add_extent_mapping(struct extent_map_tree *tree, |
| 55 | struct extent_map *em); |
| 56 | 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] | 57 | |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 58 | struct extent_map *alloc_extent_map(gfp_t mask); |
| 59 | void free_extent_map(struct extent_map *em); |
Wyatt Banks | 2f4cbe6 | 2007-11-19 10:22:33 -0500 | [diff] [blame] | 60 | int __init extent_map_init(void); |
Christian Hesse | 17636e0 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 61 | void extent_map_exit(void); |
Chris Mason | a1ed835 | 2009-09-11 12:27:37 -0400 | [diff] [blame] | 62 | int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len); |
Chris Mason | b917b7c | 2009-09-18 16:07:03 -0400 | [diff] [blame] | 63 | struct extent_map *search_extent_mapping(struct extent_map_tree *tree, |
| 64 | u64 start, u64 len); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 65 | #endif |