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