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