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