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; |
| 51 | }; |
| 52 | |
| 53 | struct extent_state { |
| 54 | u64 start; |
| 55 | u64 end; /* inclusive */ |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 56 | struct rb_node rb_node; |
Chris Mason | 70dec80 | 2008-01-29 09:59:12 -0500 | [diff] [blame] | 57 | struct extent_io_tree *tree; |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 58 | wait_queue_head_t wq; |
| 59 | atomic_t refs; |
| 60 | unsigned long state; |
| 61 | |
| 62 | /* for use by the FS */ |
| 63 | u64 private; |
| 64 | |
| 65 | struct list_head list; |
| 66 | }; |
| 67 | |
| 68 | struct extent_buffer { |
| 69 | u64 start; |
| 70 | unsigned long len; |
| 71 | char *map_token; |
| 72 | char *kaddr; |
| 73 | unsigned long map_start; |
| 74 | unsigned long map_len; |
| 75 | struct page *first_page; |
| 76 | struct list_head lru; |
| 77 | atomic_t refs; |
| 78 | int flags; |
| 79 | }; |
| 80 | |
| 81 | struct extent_map_tree; |
| 82 | |
| 83 | typedef struct extent_map *(get_extent_t)(struct inode *inode, |
| 84 | struct page *page, |
| 85 | size_t page_offset, |
| 86 | u64 start, u64 len, |
| 87 | int create); |
| 88 | |
| 89 | void extent_io_tree_init(struct extent_io_tree *tree, |
| 90 | struct address_space *mapping, gfp_t mask); |
| 91 | void extent_io_tree_empty_lru(struct extent_io_tree *tree); |
| 92 | int try_release_extent_mapping(struct extent_map_tree *map, |
Chris Mason | 70dec80 | 2008-01-29 09:59:12 -0500 | [diff] [blame] | 93 | struct extent_io_tree *tree, struct page *page, |
| 94 | gfp_t mask); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 95 | int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask); |
| 96 | int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask); |
| 97 | int extent_read_full_page(struct extent_io_tree *tree, struct page *page, |
| 98 | get_extent_t *get_extent); |
| 99 | int __init extent_io_init(void); |
| 100 | void extent_io_exit(void); |
| 101 | |
| 102 | u64 count_range_bits(struct extent_io_tree *tree, |
| 103 | u64 *start, u64 search_end, |
| 104 | u64 max_bytes, unsigned long bits); |
| 105 | |
| 106 | int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, |
| 107 | int bits, int filled); |
| 108 | int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, |
| 109 | int bits, gfp_t mask); |
| 110 | int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, |
| 111 | int bits, gfp_t mask); |
| 112 | int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, |
| 113 | gfp_t mask); |
| 114 | int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end, |
| 115 | gfp_t mask); |
| 116 | int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, |
| 117 | gfp_t mask); |
| 118 | int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, |
| 119 | gfp_t mask); |
| 120 | int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end, |
| 121 | gfp_t mask); |
| 122 | int find_first_extent_bit(struct extent_io_tree *tree, u64 start, |
| 123 | u64 *start_ret, u64 *end_ret, int bits); |
| 124 | int extent_invalidatepage(struct extent_io_tree *tree, |
| 125 | struct page *page, unsigned long offset); |
| 126 | int extent_write_full_page(struct extent_io_tree *tree, struct page *page, |
| 127 | get_extent_t *get_extent, |
| 128 | struct writeback_control *wbc); |
| 129 | int extent_writepages(struct extent_io_tree *tree, |
| 130 | struct address_space *mapping, |
| 131 | get_extent_t *get_extent, |
| 132 | struct writeback_control *wbc); |
| 133 | int extent_readpages(struct extent_io_tree *tree, |
| 134 | struct address_space *mapping, |
| 135 | struct list_head *pages, unsigned nr_pages, |
| 136 | get_extent_t get_extent); |
| 137 | int extent_prepare_write(struct extent_io_tree *tree, |
| 138 | struct inode *inode, struct page *page, |
| 139 | unsigned from, unsigned to, get_extent_t *get_extent); |
| 140 | int extent_commit_write(struct extent_io_tree *tree, |
| 141 | struct inode *inode, struct page *page, |
| 142 | unsigned from, unsigned to); |
| 143 | sector_t extent_bmap(struct address_space *mapping, sector_t iblock, |
| 144 | get_extent_t *get_extent); |
| 145 | int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end); |
| 146 | int set_state_private(struct extent_io_tree *tree, u64 start, u64 private); |
| 147 | int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private); |
| 148 | void set_page_extent_mapped(struct page *page); |
| 149 | |
| 150 | struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree, |
| 151 | u64 start, unsigned long len, |
| 152 | struct page *page0, |
| 153 | gfp_t mask); |
| 154 | struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree, |
| 155 | u64 start, unsigned long len, |
| 156 | gfp_t mask); |
| 157 | void free_extent_buffer(struct extent_buffer *eb); |
| 158 | int read_extent_buffer_pages(struct extent_io_tree *tree, |
| 159 | struct extent_buffer *eb, u64 start, int wait); |
| 160 | |
| 161 | static inline void extent_buffer_get(struct extent_buffer *eb) |
| 162 | { |
| 163 | atomic_inc(&eb->refs); |
| 164 | } |
| 165 | |
| 166 | int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv, |
| 167 | unsigned long start, |
| 168 | unsigned long len); |
| 169 | void read_extent_buffer(struct extent_buffer *eb, void *dst, |
| 170 | unsigned long start, |
| 171 | unsigned long len); |
| 172 | void write_extent_buffer(struct extent_buffer *eb, const void *src, |
| 173 | unsigned long start, unsigned long len); |
| 174 | void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src, |
| 175 | unsigned long dst_offset, unsigned long src_offset, |
| 176 | unsigned long len); |
| 177 | void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, |
| 178 | unsigned long src_offset, unsigned long len); |
| 179 | void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, |
| 180 | unsigned long src_offset, unsigned long len); |
| 181 | void memset_extent_buffer(struct extent_buffer *eb, char c, |
| 182 | unsigned long start, unsigned long len); |
| 183 | int wait_on_extent_buffer_writeback(struct extent_io_tree *tree, |
| 184 | struct extent_buffer *eb); |
| 185 | int clear_extent_buffer_dirty(struct extent_io_tree *tree, |
| 186 | struct extent_buffer *eb); |
| 187 | int set_extent_buffer_dirty(struct extent_io_tree *tree, |
| 188 | struct extent_buffer *eb); |
| 189 | int set_extent_buffer_uptodate(struct extent_io_tree *tree, |
| 190 | struct extent_buffer *eb); |
| 191 | int extent_buffer_uptodate(struct extent_io_tree *tree, |
| 192 | struct extent_buffer *eb); |
| 193 | int map_extent_buffer(struct extent_buffer *eb, unsigned long offset, |
| 194 | unsigned long min_len, char **token, char **map, |
| 195 | unsigned long *map_start, |
| 196 | unsigned long *map_len, int km); |
| 197 | int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset, |
| 198 | unsigned long min_len, char **token, char **map, |
| 199 | unsigned long *map_start, |
| 200 | unsigned long *map_len, int km); |
| 201 | void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km); |
| 202 | #endif |