Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 1 | #ifndef __EXTENTIO__ |
| 2 | #define __EXTENTIO__ |
| 3 | |
| 4 | #include <linux/rbtree.h> |
| 5 | |
| 6 | /* bits for the extent state */ |
| 7 | #define EXTENT_DIRTY 1 |
| 8 | #define EXTENT_WRITEBACK (1 << 1) |
| 9 | #define EXTENT_UPTODATE (1 << 2) |
| 10 | #define EXTENT_LOCKED (1 << 3) |
| 11 | #define EXTENT_NEW (1 << 4) |
| 12 | #define EXTENT_DELALLOC (1 << 5) |
| 13 | #define EXTENT_DEFRAG (1 << 6) |
| 14 | #define EXTENT_DEFRAG_DONE (1 << 7) |
| 15 | #define EXTENT_BUFFER_FILLED (1 << 8) |
Chris Mason | e6dcd2d | 2008-07-17 12:53:50 -0400 | [diff] [blame^] | 16 | #define EXTENT_ORDERED (1 << 9) |
| 17 | #define EXTENT_ORDERED_METADATA (1 << 10) |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 18 | #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK) |
| 19 | |
| 20 | /* |
| 21 | * page->private values. Every page that is controlled by the extent |
| 22 | * map has page->private set to one. |
| 23 | */ |
| 24 | #define EXTENT_PAGE_PRIVATE 1 |
| 25 | #define EXTENT_PAGE_PRIVATE_FIRST_PAGE 3 |
| 26 | |
Chris Mason | 70dec80 | 2008-01-29 09:59:12 -0500 | [diff] [blame] | 27 | struct extent_state; |
| 28 | |
Chris Mason | 44b8bd7 | 2008-04-16 11:14:51 -0400 | [diff] [blame] | 29 | typedef int (extent_submit_bio_hook_t)(struct inode *inode, int rw, |
| 30 | struct bio *bio, int mirror_num); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 31 | struct extent_io_ops { |
| 32 | int (*fill_delalloc)(struct inode *inode, u64 start, u64 end); |
| 33 | int (*writepage_io_hook)(struct page *page, u64 start, u64 end); |
Chris Mason | 44b8bd7 | 2008-04-16 11:14:51 -0400 | [diff] [blame] | 34 | extent_submit_bio_hook_t *submit_bio_hook; |
Chris Mason | 239b14b | 2008-03-24 15:02:07 -0400 | [diff] [blame] | 35 | int (*merge_bio_hook)(struct page *page, unsigned long offset, |
| 36 | size_t size, struct bio *bio); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 37 | int (*readpage_io_hook)(struct page *page, u64 start, u64 end); |
Chris Mason | 7e38326 | 2008-04-09 16:28:12 -0400 | [diff] [blame] | 38 | int (*readpage_io_failed_hook)(struct bio *bio, struct page *page, |
| 39 | u64 start, u64 end, |
| 40 | struct extent_state *state); |
Chris Mason | 1259ab7 | 2008-05-12 13:39:03 -0400 | [diff] [blame] | 41 | int (*writepage_io_failed_hook)(struct bio *bio, struct page *page, |
| 42 | u64 start, u64 end, |
| 43 | struct extent_state *state); |
Chris Mason | 70dec80 | 2008-01-29 09:59:12 -0500 | [diff] [blame] | 44 | int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end, |
| 45 | struct extent_state *state); |
Chris Mason | 1259ab7 | 2008-05-12 13:39:03 -0400 | [diff] [blame] | 46 | int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end, |
Chris Mason | e6dcd2d | 2008-07-17 12:53:50 -0400 | [diff] [blame^] | 47 | struct extent_state *state, int uptodate); |
Chris Mason | 291d673 | 2008-01-29 15:55:23 -0500 | [diff] [blame] | 48 | int (*set_bit_hook)(struct inode *inode, u64 start, u64 end, |
Chris Mason | b0c68f8 | 2008-01-31 11:05:37 -0500 | [diff] [blame] | 49 | unsigned long old, unsigned long bits); |
Chris Mason | 291d673 | 2008-01-29 15:55:23 -0500 | [diff] [blame] | 50 | int (*clear_bit_hook)(struct inode *inode, u64 start, u64 end, |
Chris Mason | b0c68f8 | 2008-01-31 11:05:37 -0500 | [diff] [blame] | 51 | unsigned long old, unsigned long bits); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | struct extent_io_tree { |
| 55 | struct rb_root state; |
| 56 | struct address_space *mapping; |
| 57 | u64 dirty_bytes; |
Chris Mason | 70dec80 | 2008-01-29 09:59:12 -0500 | [diff] [blame] | 58 | spinlock_t lock; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 59 | struct extent_io_ops *ops; |
| 60 | spinlock_t lru_lock; |
| 61 | struct list_head buffer_lru; |
| 62 | int lru_size; |
Chris Mason | 80ea96b | 2008-02-01 14:51:59 -0500 | [diff] [blame] | 63 | struct extent_state *last; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | struct extent_state { |
| 67 | u64 start; |
| 68 | u64 end; /* inclusive */ |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 69 | struct rb_node rb_node; |
Chris Mason | 70dec80 | 2008-01-29 09:59:12 -0500 | [diff] [blame] | 70 | struct extent_io_tree *tree; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 71 | wait_queue_head_t wq; |
| 72 | atomic_t refs; |
| 73 | unsigned long state; |
| 74 | |
| 75 | /* for use by the FS */ |
| 76 | u64 private; |
| 77 | |
Chris Mason | 2d2ae54 | 2008-03-26 16:24:23 -0400 | [diff] [blame] | 78 | struct list_head leak_list; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | struct extent_buffer { |
| 82 | u64 start; |
| 83 | unsigned long len; |
| 84 | char *map_token; |
| 85 | char *kaddr; |
| 86 | unsigned long map_start; |
| 87 | unsigned long map_len; |
| 88 | struct page *first_page; |
| 89 | struct list_head lru; |
| 90 | atomic_t refs; |
| 91 | int flags; |
Chris Mason | 2d2ae54 | 2008-03-26 16:24:23 -0400 | [diff] [blame] | 92 | struct list_head leak_list; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | struct extent_map_tree; |
| 96 | |
Chris Mason | d7fc640 | 2008-02-18 12:12:38 -0500 | [diff] [blame] | 97 | static inline struct extent_state *extent_state_next(struct extent_state *state) |
| 98 | { |
| 99 | struct rb_node *node; |
| 100 | node = rb_next(&state->rb_node); |
| 101 | if (!node) |
| 102 | return NULL; |
| 103 | return rb_entry(node, struct extent_state, rb_node); |
| 104 | } |
| 105 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 106 | typedef struct extent_map *(get_extent_t)(struct inode *inode, |
| 107 | struct page *page, |
| 108 | size_t page_offset, |
| 109 | u64 start, u64 len, |
| 110 | int create); |
| 111 | |
| 112 | void extent_io_tree_init(struct extent_io_tree *tree, |
| 113 | struct address_space *mapping, gfp_t mask); |
| 114 | void extent_io_tree_empty_lru(struct extent_io_tree *tree); |
| 115 | int try_release_extent_mapping(struct extent_map_tree *map, |
Chris Mason | 70dec80 | 2008-01-29 09:59:12 -0500 | [diff] [blame] | 116 | struct extent_io_tree *tree, struct page *page, |
| 117 | gfp_t mask); |
Chris Mason | 7b13b7b | 2008-04-18 10:29:50 -0400 | [diff] [blame] | 118 | int try_release_extent_state(struct extent_map_tree *map, |
| 119 | struct extent_io_tree *tree, struct page *page, |
| 120 | gfp_t mask); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 121 | int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask); |
| 122 | int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask); |
| 123 | int extent_read_full_page(struct extent_io_tree *tree, struct page *page, |
| 124 | get_extent_t *get_extent); |
| 125 | int __init extent_io_init(void); |
| 126 | void extent_io_exit(void); |
| 127 | |
| 128 | u64 count_range_bits(struct extent_io_tree *tree, |
| 129 | u64 *start, u64 search_end, |
| 130 | u64 max_bytes, unsigned long bits); |
| 131 | |
| 132 | int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, |
| 133 | int bits, int filled); |
| 134 | int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, |
| 135 | int bits, gfp_t mask); |
Chris Mason | e6dcd2d | 2008-07-17 12:53:50 -0400 | [diff] [blame^] | 136 | int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, |
| 137 | int bits, int wake, int delete, gfp_t mask); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 138 | int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, |
| 139 | int bits, gfp_t mask); |
| 140 | int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, |
| 141 | gfp_t mask); |
| 142 | int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end, |
| 143 | gfp_t mask); |
| 144 | int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, |
| 145 | gfp_t mask); |
| 146 | int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, |
| 147 | gfp_t mask); |
Chris Mason | e6dcd2d | 2008-07-17 12:53:50 -0400 | [diff] [blame^] | 148 | int clear_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end, |
| 149 | gfp_t mask); |
| 150 | int clear_extent_ordered_metadata(struct extent_io_tree *tree, u64 start, |
| 151 | u64 end, gfp_t mask); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 152 | int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end, |
| 153 | gfp_t mask); |
Chris Mason | e6dcd2d | 2008-07-17 12:53:50 -0400 | [diff] [blame^] | 154 | int set_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end, |
| 155 | gfp_t mask); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 156 | int find_first_extent_bit(struct extent_io_tree *tree, u64 start, |
| 157 | u64 *start_ret, u64 *end_ret, int bits); |
Chris Mason | d7fc640 | 2008-02-18 12:12:38 -0500 | [diff] [blame] | 158 | struct extent_state *find_first_extent_bit_state(struct extent_io_tree *tree, |
| 159 | u64 start, int bits); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 160 | int extent_invalidatepage(struct extent_io_tree *tree, |
| 161 | struct page *page, unsigned long offset); |
| 162 | int extent_write_full_page(struct extent_io_tree *tree, struct page *page, |
| 163 | get_extent_t *get_extent, |
| 164 | struct writeback_control *wbc); |
| 165 | int extent_writepages(struct extent_io_tree *tree, |
| 166 | struct address_space *mapping, |
| 167 | get_extent_t *get_extent, |
| 168 | struct writeback_control *wbc); |
| 169 | int extent_readpages(struct extent_io_tree *tree, |
| 170 | struct address_space *mapping, |
| 171 | struct list_head *pages, unsigned nr_pages, |
| 172 | get_extent_t get_extent); |
| 173 | int extent_prepare_write(struct extent_io_tree *tree, |
| 174 | struct inode *inode, struct page *page, |
| 175 | unsigned from, unsigned to, get_extent_t *get_extent); |
| 176 | int extent_commit_write(struct extent_io_tree *tree, |
| 177 | struct inode *inode, struct page *page, |
| 178 | unsigned from, unsigned to); |
| 179 | sector_t extent_bmap(struct address_space *mapping, sector_t iblock, |
| 180 | get_extent_t *get_extent); |
| 181 | int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end); |
| 182 | int set_state_private(struct extent_io_tree *tree, u64 start, u64 private); |
| 183 | int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private); |
| 184 | void set_page_extent_mapped(struct page *page); |
| 185 | |
| 186 | struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree, |
| 187 | u64 start, unsigned long len, |
| 188 | struct page *page0, |
| 189 | gfp_t mask); |
| 190 | struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree, |
| 191 | u64 start, unsigned long len, |
| 192 | gfp_t mask); |
| 193 | void free_extent_buffer(struct extent_buffer *eb); |
| 194 | int read_extent_buffer_pages(struct extent_io_tree *tree, |
Chris Mason | a86c12c | 2008-02-07 10:50:54 -0500 | [diff] [blame] | 195 | struct extent_buffer *eb, u64 start, int wait, |
Chris Mason | f188591 | 2008-04-09 16:28:12 -0400 | [diff] [blame] | 196 | get_extent_t *get_extent, int mirror_num); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 197 | |
| 198 | static inline void extent_buffer_get(struct extent_buffer *eb) |
| 199 | { |
| 200 | atomic_inc(&eb->refs); |
| 201 | } |
| 202 | |
| 203 | int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv, |
| 204 | unsigned long start, |
| 205 | unsigned long len); |
| 206 | void read_extent_buffer(struct extent_buffer *eb, void *dst, |
| 207 | unsigned long start, |
| 208 | unsigned long len); |
| 209 | void write_extent_buffer(struct extent_buffer *eb, const void *src, |
| 210 | unsigned long start, unsigned long len); |
| 211 | void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src, |
| 212 | unsigned long dst_offset, unsigned long src_offset, |
| 213 | unsigned long len); |
| 214 | void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, |
| 215 | unsigned long src_offset, unsigned long len); |
| 216 | void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, |
| 217 | unsigned long src_offset, unsigned long len); |
| 218 | void memset_extent_buffer(struct extent_buffer *eb, char c, |
| 219 | unsigned long start, unsigned long len); |
| 220 | int wait_on_extent_buffer_writeback(struct extent_io_tree *tree, |
| 221 | struct extent_buffer *eb); |
Chris Mason | e6dcd2d | 2008-07-17 12:53:50 -0400 | [diff] [blame^] | 222 | int wait_on_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end); |
| 223 | int wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 224 | int clear_extent_buffer_dirty(struct extent_io_tree *tree, |
| 225 | struct extent_buffer *eb); |
| 226 | int set_extent_buffer_dirty(struct extent_io_tree *tree, |
| 227 | struct extent_buffer *eb); |
| 228 | int set_extent_buffer_uptodate(struct extent_io_tree *tree, |
| 229 | struct extent_buffer *eb); |
Chris Mason | 1259ab7 | 2008-05-12 13:39:03 -0400 | [diff] [blame] | 230 | int clear_extent_buffer_uptodate(struct extent_io_tree *tree, |
| 231 | struct extent_buffer *eb); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 232 | int extent_buffer_uptodate(struct extent_io_tree *tree, |
| 233 | struct extent_buffer *eb); |
| 234 | int map_extent_buffer(struct extent_buffer *eb, unsigned long offset, |
| 235 | unsigned long min_len, char **token, char **map, |
| 236 | unsigned long *map_start, |
| 237 | unsigned long *map_len, int km); |
| 238 | int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset, |
| 239 | unsigned long min_len, char **token, char **map, |
| 240 | unsigned long *map_start, |
| 241 | unsigned long *map_len, int km); |
| 242 | void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km); |
Chris Mason | 728131d | 2008-04-09 16:28:12 -0400 | [diff] [blame] | 243 | int invalidate_extent_lru(struct extent_io_tree *tree, u64 start, |
| 244 | unsigned long len); |
Chris Mason | ce9adaa | 2008-04-09 16:28:12 -0400 | [diff] [blame] | 245 | int release_extent_buffer_tail_pages(struct extent_buffer *eb); |
| 246 | int extent_range_uptodate(struct extent_io_tree *tree, |
| 247 | u64 start, u64 end); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 248 | #endif |