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 | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 6 | #define EXTENT_MAP_HOLE (u64)-3 |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 7 | #define EXTENT_MAP_INLINE (u64)-2 |
| 8 | #define EXTENT_MAP_DELALLOC (u64)-1 |
| 9 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 10 | /* bits for the extent state */ |
| 11 | #define EXTENT_DIRTY 1 |
| 12 | #define EXTENT_WRITEBACK (1 << 1) |
| 13 | #define EXTENT_UPTODATE (1 << 2) |
| 14 | #define EXTENT_LOCKED (1 << 3) |
| 15 | #define EXTENT_NEW (1 << 4) |
| 16 | #define EXTENT_DELALLOC (1 << 5) |
Chris Mason | 6b80053 | 2007-10-15 16:17:34 -0400 | [diff] [blame] | 17 | #define EXTENT_DEFRAG (1 << 6) |
| 18 | #define EXTENT_DEFRAG_DONE (1 << 7) |
Chris Mason | 4dc11904 | 2007-10-15 16:18:14 -0400 | [diff] [blame^] | 19 | #define EXTENT_BUFFER_FILLED (1 << 8) |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 20 | #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK) |
| 21 | |
| 22 | |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 23 | struct extent_map_ops { |
| 24 | int (*fill_delalloc)(struct inode *inode, u64 start, u64 end); |
| 25 | int (*writepage_io_hook)(struct page *page, u64 start, u64 end); |
| 26 | int (*readpage_io_hook)(struct page *page, u64 start, u64 end); |
| 27 | int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end); |
Christoph Hellwig | 0e2752a | 2007-09-10 20:02:33 -0400 | [diff] [blame] | 28 | void (*writepage_end_io_hook)(struct page *page, u64 start, u64 end); |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 29 | }; |
| 30 | |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 31 | struct extent_map_tree { |
| 32 | struct rb_root map; |
| 33 | struct rb_root state; |
| 34 | struct address_space *mapping; |
| 35 | rwlock_t lock; |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 36 | struct extent_map_ops *ops; |
Chris Mason | 4dc11904 | 2007-10-15 16:18:14 -0400 | [diff] [blame^] | 37 | spinlock_t lru_lock; |
| 38 | struct list_head buffer_lru; |
| 39 | int lru_size; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | /* note, this must start with the same fields as fs/extent_map.c:tree_entry */ |
| 43 | struct extent_map { |
| 44 | u64 start; |
| 45 | u64 end; /* inclusive */ |
| 46 | int in_tree; |
| 47 | struct rb_node rb_node; |
| 48 | /* block_start and block_end are in bytes */ |
| 49 | u64 block_start; |
| 50 | u64 block_end; /* inclusive */ |
| 51 | struct block_device *bdev; |
| 52 | atomic_t refs; |
| 53 | }; |
| 54 | |
| 55 | /* note, this must start with the same fields as fs/extent_map.c:tree_entry */ |
| 56 | struct extent_state { |
| 57 | u64 start; |
| 58 | u64 end; /* inclusive */ |
| 59 | int in_tree; |
| 60 | struct rb_node rb_node; |
| 61 | wait_queue_head_t wq; |
| 62 | atomic_t refs; |
| 63 | unsigned long state; |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 64 | |
| 65 | /* for use by the FS */ |
| 66 | u64 private; |
| 67 | |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 68 | struct list_head list; |
| 69 | }; |
| 70 | |
| 71 | struct extent_buffer { |
| 72 | u64 start; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 73 | unsigned long len; |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 74 | char *map_token; |
| 75 | char *kaddr; |
| 76 | unsigned long map_start; |
| 77 | unsigned long map_len; |
Chris Mason | 4dc11904 | 2007-10-15 16:18:14 -0400 | [diff] [blame^] | 78 | struct page *last_page; |
| 79 | struct list_head lru; |
| 80 | atomic_t refs; |
| 81 | int flags; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | typedef struct extent_map *(get_extent_t)(struct inode *inode, |
| 85 | struct page *page, |
| 86 | size_t page_offset, |
| 87 | u64 start, u64 end, |
| 88 | int create); |
| 89 | |
| 90 | void extent_map_tree_init(struct extent_map_tree *tree, |
| 91 | struct address_space *mapping, gfp_t mask); |
Chris Mason | 4dc11904 | 2007-10-15 16:18:14 -0400 | [diff] [blame^] | 92 | void extent_map_tree_cleanup(struct extent_map_tree *tree); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 93 | struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree, |
| 94 | u64 start, u64 end); |
| 95 | int add_extent_mapping(struct extent_map_tree *tree, |
| 96 | struct extent_map *em); |
| 97 | int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em); |
| 98 | int try_release_extent_mapping(struct extent_map_tree *tree, struct page *page); |
| 99 | int lock_extent(struct extent_map_tree *tree, u64 start, u64 end, gfp_t mask); |
| 100 | int unlock_extent(struct extent_map_tree *tree, u64 start, u64 end, gfp_t mask); |
| 101 | struct extent_map *alloc_extent_map(gfp_t mask); |
| 102 | void free_extent_map(struct extent_map *em); |
| 103 | int extent_read_full_page(struct extent_map_tree *tree, struct page *page, |
| 104 | get_extent_t *get_extent); |
| 105 | void __init extent_map_init(void); |
| 106 | void __exit extent_map_exit(void); |
Chris Mason | 1a5bc16 | 2007-10-15 16:15:26 -0400 | [diff] [blame] | 107 | |
| 108 | int test_range_bit(struct extent_map_tree *tree, u64 start, u64 end, |
| 109 | int bits, int filled); |
Chris Mason | 96b5179 | 2007-10-15 16:15:19 -0400 | [diff] [blame] | 110 | int clear_extent_bits(struct extent_map_tree *tree, u64 start, u64 end, |
| 111 | int bits, gfp_t mask); |
| 112 | int set_extent_bits(struct extent_map_tree *tree, u64 start, u64 end, |
| 113 | int bits, gfp_t mask); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 114 | int set_extent_uptodate(struct extent_map_tree *tree, u64 start, u64 end, |
| 115 | gfp_t mask); |
| 116 | int set_extent_new(struct extent_map_tree *tree, u64 start, u64 end, |
| 117 | gfp_t mask); |
| 118 | int set_extent_dirty(struct extent_map_tree *tree, u64 start, u64 end, |
| 119 | gfp_t mask); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 120 | int clear_extent_dirty(struct extent_map_tree *tree, u64 start, u64 end, |
| 121 | gfp_t mask); |
Chris Mason | b888db2 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 122 | int set_extent_delalloc(struct extent_map_tree *tree, u64 start, u64 end, |
| 123 | gfp_t mask); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 124 | int find_first_extent_bit(struct extent_map_tree *tree, u64 start, |
| 125 | u64 *start_ret, u64 *end_ret, int bits); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 126 | int extent_invalidatepage(struct extent_map_tree *tree, |
| 127 | struct page *page, unsigned long offset); |
| 128 | int extent_write_full_page(struct extent_map_tree *tree, struct page *page, |
| 129 | get_extent_t *get_extent, |
| 130 | struct writeback_control *wbc); |
| 131 | int extent_prepare_write(struct extent_map_tree *tree, |
| 132 | struct inode *inode, struct page *page, |
| 133 | unsigned from, unsigned to, get_extent_t *get_extent); |
| 134 | int extent_commit_write(struct extent_map_tree *tree, |
| 135 | struct inode *inode, struct page *page, |
| 136 | unsigned from, unsigned to); |
Christoph Hellwig | d396c6f | 2007-09-10 20:02:30 -0400 | [diff] [blame] | 137 | sector_t extent_bmap(struct address_space *mapping, sector_t iblock, |
| 138 | get_extent_t *get_extent); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 139 | int set_range_dirty(struct extent_map_tree *tree, u64 start, u64 end); |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 140 | int set_state_private(struct extent_map_tree *tree, u64 start, u64 private); |
| 141 | int get_state_private(struct extent_map_tree *tree, u64 start, u64 *private); |
Christoph Hellwig | b3cfa35 | 2007-09-17 11:25:58 -0400 | [diff] [blame] | 142 | void set_page_extent_mapped(struct page *page); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 143 | |
| 144 | struct extent_buffer *alloc_extent_buffer(struct extent_map_tree *tree, |
| 145 | u64 start, unsigned long len, |
| 146 | gfp_t mask); |
| 147 | struct extent_buffer *find_extent_buffer(struct extent_map_tree *tree, |
| 148 | u64 start, unsigned long len, |
| 149 | gfp_t mask); |
| 150 | void free_extent_buffer(struct extent_buffer *eb); |
| 151 | int read_extent_buffer_pages(struct extent_map_tree *tree, |
| 152 | struct extent_buffer *eb, int wait); |
| 153 | |
| 154 | static inline void extent_buffer_get(struct extent_buffer *eb) |
| 155 | { |
| 156 | atomic_inc(&eb->refs); |
| 157 | } |
| 158 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 159 | int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv, |
| 160 | unsigned long start, |
| 161 | unsigned long len); |
| 162 | void read_extent_buffer(struct extent_buffer *eb, void *dst, |
| 163 | unsigned long start, |
| 164 | unsigned long len); |
| 165 | void write_extent_buffer(struct extent_buffer *eb, const void *src, |
| 166 | unsigned long start, unsigned long len); |
| 167 | void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src, |
| 168 | unsigned long dst_offset, unsigned long src_offset, |
| 169 | unsigned long len); |
| 170 | void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, |
| 171 | unsigned long src_offset, unsigned long len); |
| 172 | void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, |
| 173 | unsigned long src_offset, unsigned long len); |
| 174 | void memset_extent_buffer(struct extent_buffer *eb, char c, |
| 175 | unsigned long start, unsigned long len); |
| 176 | int wait_on_extent_buffer_writeback(struct extent_map_tree *tree, |
| 177 | struct extent_buffer *eb); |
| 178 | int clear_extent_buffer_dirty(struct extent_map_tree *tree, |
| 179 | struct extent_buffer *eb); |
| 180 | int set_extent_buffer_dirty(struct extent_map_tree *tree, |
| 181 | struct extent_buffer *eb); |
| 182 | int set_extent_buffer_uptodate(struct extent_map_tree *tree, |
| 183 | struct extent_buffer *eb); |
| 184 | int extent_buffer_uptodate(struct extent_map_tree *tree, |
| 185 | struct extent_buffer *eb); |
| 186 | int map_extent_buffer(struct extent_buffer *eb, unsigned long offset, |
Chris Mason | 479965d | 2007-10-15 16:14:27 -0400 | [diff] [blame] | 187 | unsigned long min_len, char **token, char **map, |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 188 | unsigned long *map_start, |
| 189 | unsigned long *map_len, int km); |
| 190 | void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 191 | #endif |