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