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 | |
Dulshani Gunawardhana | e248e04 | 2013-10-31 10:31:13 +0530 | [diff] [blame] | 6 | #define EXTENT_MAP_LAST_BYTE ((u64)-4) |
| 7 | #define EXTENT_MAP_HOLE ((u64)-3) |
| 8 | #define EXTENT_MAP_INLINE ((u64)-2) |
| 9 | #define EXTENT_MAP_DELALLOC ((u64)-1) |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 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 */ |
Josef Bacik | ff44c6e | 2012-09-14 12:59:20 -0400 | [diff] [blame] | 16 | #define EXTENT_FLAG_LOGGING 4 /* Logging this extent */ |
Josef Bacik | b11e234 | 2012-12-03 10:58:15 -0500 | [diff] [blame] | 17 | #define EXTENT_FLAG_FILLING 5 /* Filling in a preallocated extent */ |
Chris Mason | 7f3c74f | 2008-07-18 12:01:11 -0400 | [diff] [blame] | 18 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 19 | struct extent_map { |
| 20 | struct rb_node rb_node; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 21 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 22 | /* all of these are in bytes */ |
| 23 | u64 start; |
| 24 | u64 len; |
Liu Bo | 4e2f84e | 2012-08-27 10:52:20 -0600 | [diff] [blame] | 25 | u64 mod_start; |
| 26 | u64 mod_len; |
Yan Zheng | ff5b7ee | 2008-11-10 07:34:43 -0500 | [diff] [blame] | 27 | u64 orig_start; |
Josef Bacik | b493968 | 2012-12-03 10:31:19 -0500 | [diff] [blame] | 28 | u64 orig_block_len; |
Josef Bacik | cc95bef | 2013-04-04 14:31:27 -0400 | [diff] [blame] | 29 | u64 ram_bytes; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 30 | u64 block_start; |
Chris Mason | c8b9781 | 2008-10-29 14:49:59 -0400 | [diff] [blame] | 31 | u64 block_len; |
Josef Bacik | 5dc562c | 2012-08-17 13:14:17 -0400 | [diff] [blame] | 32 | u64 generation; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 33 | unsigned long flags; |
| 34 | struct block_device *bdev; |
| 35 | atomic_t refs; |
David Sterba | c08782d | 2012-01-26 15:01:12 -0500 | [diff] [blame] | 36 | unsigned int in_tree; |
| 37 | unsigned int compress_type; |
Josef Bacik | 5dc562c | 2012-08-17 13:14:17 -0400 | [diff] [blame] | 38 | struct list_head list; |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 39 | }; |
| 40 | |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 41 | struct extent_map_tree { |
| 42 | struct rb_root map; |
Josef Bacik | 5dc562c | 2012-08-17 13:14:17 -0400 | [diff] [blame] | 43 | struct list_head modified_extents; |
Chris Mason | 890871b | 2009-09-02 16:24:52 -0400 | [diff] [blame] | 44 | rwlock_t lock; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 45 | }; |
| 46 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 47 | static inline u64 extent_map_end(struct extent_map *em) |
| 48 | { |
| 49 | if (em->start + em->len < em->start) |
| 50 | return (u64)-1; |
| 51 | return em->start + em->len; |
| 52 | } |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 53 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 54 | static inline u64 extent_map_block_end(struct extent_map *em) |
| 55 | { |
Chris Mason | c8b9781 | 2008-10-29 14:49:59 -0400 | [diff] [blame] | 56 | if (em->block_start + em->block_len < em->block_start) |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 57 | return (u64)-1; |
Chris Mason | c8b9781 | 2008-10-29 14:49:59 -0400 | [diff] [blame] | 58 | return em->block_start + em->block_len; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 59 | } |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 60 | |
David Sterba | a8067e0 | 2011-04-21 00:34:43 +0200 | [diff] [blame] | 61 | void extent_map_tree_init(struct extent_map_tree *tree); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 62 | struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree, |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 63 | u64 start, u64 len); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 64 | int add_extent_mapping(struct extent_map_tree *tree, |
Josef Bacik | 09a2a8f9 | 2013-04-05 16:51:15 -0400 | [diff] [blame] | 65 | struct extent_map *em, int modified); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 66 | 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] | 67 | |
David Sterba | 172ddd6 | 2011-04-21 00:48:27 +0200 | [diff] [blame] | 68 | struct extent_map *alloc_extent_map(void); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 69 | void free_extent_map(struct extent_map *em); |
Wyatt Banks | 2f4cbe6 | 2007-11-19 10:22:33 -0500 | [diff] [blame] | 70 | int __init extent_map_init(void); |
Christian Hesse | 17636e0 | 2007-12-11 09:25:06 -0500 | [diff] [blame] | 71 | void extent_map_exit(void); |
Josef Bacik | 5dc562c | 2012-08-17 13:14:17 -0400 | [diff] [blame] | 72 | int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len, u64 gen); |
Josef Bacik | 201a903 | 2013-01-24 12:02:07 -0500 | [diff] [blame] | 73 | void clear_em_logging(struct extent_map_tree *tree, struct extent_map *em); |
Chris Mason | b917b7c | 2009-09-18 16:07:03 -0400 | [diff] [blame] | 74 | struct extent_map *search_extent_mapping(struct extent_map_tree *tree, |
| 75 | u64 start, u64 len); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 76 | #endif |