Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 1 | #ifndef __EXTENTMAP__ |
| 2 | #define __EXTENTMAP__ |
| 3 | |
| 4 | #include <linux/rbtree.h> |
| 5 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 6 | #define EXTENT_MAP_HOLE (u64)-3 |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 7 | #define EXTENT_MAP_INLINE (u64)-2 |
| 8 | #define EXTENT_MAP_DELALLOC (u64)-1 |
| 9 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 10 | /* bits for the extent state */ |
| 11 | #define EXTENT_DIRTY 1 |
| 12 | #define EXTENT_WRITEBACK (1 << 1) |
| 13 | #define EXTENT_UPTODATE (1 << 2) |
| 14 | #define EXTENT_LOCKED (1 << 3) |
| 15 | #define EXTENT_NEW (1 << 4) |
| 16 | #define EXTENT_DELALLOC (1 << 5) |
Chris Mason | 6b80053 | 2007-10-15 16:17:34 -0400 | [diff] [blame] | 17 | #define EXTENT_DEFRAG (1 << 6) |
| 18 | #define EXTENT_DEFRAG_DONE (1 << 7) |
Chris Mason | 4dc1190 | 2007-10-15 16:18:14 -0400 | [diff] [blame] | 19 | #define EXTENT_BUFFER_FILLED (1 << 8) |
Chris Mason | 19c00dd | 2007-10-15 16:19:22 -0400 | [diff] [blame] | 20 | #define EXTENT_CSUM (1 << 9) |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 21 | #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK) |
| 22 | |
Chris Mason | 19c00dd | 2007-10-15 16:19:22 -0400 | [diff] [blame] | 23 | /* |
| 24 | * page->private values. Every page that is controlled by the extent |
| 25 | * map has page->private set to one. |
| 26 | */ |
Chris Mason | 19c00dd | 2007-10-15 16:19:22 -0400 | [diff] [blame] | 27 | #define EXTENT_PAGE_PRIVATE 1 |
| 28 | #define EXTENT_PAGE_PRIVATE_FIRST_PAGE 3 |
| 29 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 30 | |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 31 | struct extent_map_ops { |
| 32 | int (*fill_delalloc)(struct inode *inode, u64 start, u64 end); |
| 33 | int (*writepage_io_hook)(struct page *page, u64 start, u64 end); |
| 34 | int (*readpage_io_hook)(struct page *page, u64 start, u64 end); |
| 35 | int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end); |
Christoph Hellwig | 0e2752a | 2007-09-10 20:02:33 -0400 | [diff] [blame] | 36 | void (*writepage_end_io_hook)(struct page *page, u64 start, u64 end); |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 37 | }; |
| 38 | |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 39 | struct extent_map_tree { |
| 40 | struct rb_root map; |
| 41 | struct rb_root state; |
| 42 | struct address_space *mapping; |
| 43 | rwlock_t lock; |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 44 | struct extent_map_ops *ops; |
Chris Mason | 4dc1190 | 2007-10-15 16:18:14 -0400 | [diff] [blame] | 45 | spinlock_t lru_lock; |
| 46 | struct list_head buffer_lru; |
| 47 | int lru_size; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | /* note, this must start with the same fields as fs/extent_map.c:tree_entry */ |
| 51 | struct extent_map { |
| 52 | u64 start; |
| 53 | u64 end; /* inclusive */ |
| 54 | int in_tree; |
| 55 | struct rb_node rb_node; |
| 56 | /* block_start and block_end are in bytes */ |
| 57 | u64 block_start; |
| 58 | u64 block_end; /* inclusive */ |
| 59 | struct block_device *bdev; |
| 60 | atomic_t refs; |
| 61 | }; |
| 62 | |
| 63 | /* note, this must start with the same fields as fs/extent_map.c:tree_entry */ |
| 64 | struct extent_state { |
| 65 | u64 start; |
| 66 | u64 end; /* inclusive */ |
| 67 | int in_tree; |
| 68 | struct rb_node rb_node; |
| 69 | wait_queue_head_t wq; |
| 70 | atomic_t refs; |
| 71 | unsigned long state; |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 72 | |
| 73 | /* for use by the FS */ |
| 74 | u64 private; |
| 75 | |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 76 | struct list_head list; |
| 77 | }; |
| 78 | |
| 79 | struct extent_buffer { |
| 80 | u64 start; |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 81 | unsigned long len; |
Chris Mason | db94535 | 2007-10-15 16:15:53 -0400 | [diff] [blame] | 82 | char *map_token; |
| 83 | char *kaddr; |
| 84 | unsigned long map_start; |
| 85 | unsigned long map_len; |
Chris Mason | 810191f | 2007-10-15 16:18:55 -0400 | [diff] [blame] | 86 | struct page *first_page; |
Chris Mason | 4dc1190 | 2007-10-15 16:18:14 -0400 | [diff] [blame] | 87 | struct list_head lru; |
| 88 | atomic_t refs; |
| 89 | int flags; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | typedef struct extent_map *(get_extent_t)(struct inode *inode, |
| 93 | struct page *page, |
| 94 | size_t page_offset, |
| 95 | u64 start, u64 end, |
| 96 | int create); |
| 97 | |
| 98 | void extent_map_tree_init(struct extent_map_tree *tree, |
| 99 | struct address_space *mapping, gfp_t mask); |
Chris Mason | 19c00dd | 2007-10-15 16:19:22 -0400 | [diff] [blame] | 100 | void extent_map_tree_empty_lru(struct extent_map_tree *tree); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 101 | struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree, |
| 102 | u64 start, u64 end); |
| 103 | int add_extent_mapping(struct extent_map_tree *tree, |
| 104 | struct extent_map *em); |
| 105 | int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em); |
| 106 | int try_release_extent_mapping(struct extent_map_tree *tree, struct page *page); |
| 107 | int lock_extent(struct extent_map_tree *tree, u64 start, u64 end, gfp_t mask); |
| 108 | int unlock_extent(struct extent_map_tree *tree, u64 start, u64 end, gfp_t mask); |
| 109 | struct extent_map *alloc_extent_map(gfp_t mask); |
| 110 | void free_extent_map(struct extent_map *em); |
| 111 | int extent_read_full_page(struct extent_map_tree *tree, struct page *page, |
| 112 | get_extent_t *get_extent); |
Wyatt Banks | 2f4cbe6 | 2007-11-19 10:22:33 -0500 | [diff] [blame^] | 113 | int __init extent_map_init(void); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 114 | void __exit extent_map_exit(void); |
Chris Mason | 1a5bc16 | 2007-10-15 16:15:26 -0400 | [diff] [blame] | 115 | |
| 116 | int test_range_bit(struct extent_map_tree *tree, u64 start, u64 end, |
| 117 | int bits, int filled); |
Chris Mason | 96b5179 | 2007-10-15 16:15:19 -0400 | [diff] [blame] | 118 | int clear_extent_bits(struct extent_map_tree *tree, u64 start, u64 end, |
| 119 | int bits, gfp_t mask); |
| 120 | int set_extent_bits(struct extent_map_tree *tree, u64 start, u64 end, |
| 121 | int bits, gfp_t mask); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 122 | int set_extent_uptodate(struct extent_map_tree *tree, u64 start, u64 end, |
| 123 | gfp_t mask); |
| 124 | int set_extent_new(struct extent_map_tree *tree, u64 start, u64 end, |
| 125 | gfp_t mask); |
| 126 | int set_extent_dirty(struct extent_map_tree *tree, u64 start, u64 end, |
| 127 | gfp_t mask); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 128 | int clear_extent_dirty(struct extent_map_tree *tree, u64 start, u64 end, |
| 129 | gfp_t mask); |
Chris Mason | b888db2 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 130 | int set_extent_delalloc(struct extent_map_tree *tree, u64 start, u64 end, |
| 131 | gfp_t mask); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 132 | int find_first_extent_bit(struct extent_map_tree *tree, u64 start, |
| 133 | u64 *start_ret, u64 *end_ret, int bits); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 134 | int extent_invalidatepage(struct extent_map_tree *tree, |
| 135 | struct page *page, unsigned long offset); |
| 136 | int extent_write_full_page(struct extent_map_tree *tree, struct page *page, |
| 137 | get_extent_t *get_extent, |
| 138 | struct writeback_control *wbc); |
Chris Mason | b293f02 | 2007-11-01 19:45:34 -0400 | [diff] [blame] | 139 | int extent_writepages(struct extent_map_tree *tree, |
| 140 | struct address_space *mapping, |
| 141 | get_extent_t *get_extent, |
| 142 | struct writeback_control *wbc); |
Chris Mason | 3ab2fb5 | 2007-11-08 10:59:22 -0500 | [diff] [blame] | 143 | int extent_readpages(struct extent_map_tree *tree, |
| 144 | struct address_space *mapping, |
| 145 | struct list_head *pages, unsigned nr_pages, |
| 146 | get_extent_t get_extent); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 147 | int extent_prepare_write(struct extent_map_tree *tree, |
| 148 | struct inode *inode, struct page *page, |
| 149 | unsigned from, unsigned to, get_extent_t *get_extent); |
| 150 | int extent_commit_write(struct extent_map_tree *tree, |
| 151 | struct inode *inode, struct page *page, |
| 152 | unsigned from, unsigned to); |
Christoph Hellwig | d396c6f | 2007-09-10 20:02:30 -0400 | [diff] [blame] | 153 | sector_t extent_bmap(struct address_space *mapping, sector_t iblock, |
| 154 | get_extent_t *get_extent); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 155 | int set_range_dirty(struct extent_map_tree *tree, u64 start, u64 end); |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 156 | int set_state_private(struct extent_map_tree *tree, u64 start, u64 private); |
| 157 | int get_state_private(struct extent_map_tree *tree, u64 start, u64 *private); |
Christoph Hellwig | b3cfa35 | 2007-09-17 11:25:58 -0400 | [diff] [blame] | 158 | void set_page_extent_mapped(struct page *page); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 159 | |
| 160 | struct extent_buffer *alloc_extent_buffer(struct extent_map_tree *tree, |
| 161 | u64 start, unsigned long len, |
Chris Mason | 19c00dd | 2007-10-15 16:19:22 -0400 | [diff] [blame] | 162 | struct page *page0, |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 163 | gfp_t mask); |
| 164 | struct extent_buffer *find_extent_buffer(struct extent_map_tree *tree, |
| 165 | u64 start, unsigned long len, |
| 166 | gfp_t mask); |
| 167 | void free_extent_buffer(struct extent_buffer *eb); |
| 168 | int read_extent_buffer_pages(struct extent_map_tree *tree, |
Chris Mason | 19c00dd | 2007-10-15 16:19:22 -0400 | [diff] [blame] | 169 | struct extent_buffer *eb, u64 start, int wait); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 170 | |
| 171 | static inline void extent_buffer_get(struct extent_buffer *eb) |
| 172 | { |
| 173 | atomic_inc(&eb->refs); |
| 174 | } |
| 175 | |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 176 | int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv, |
| 177 | unsigned long start, |
| 178 | unsigned long len); |
| 179 | void read_extent_buffer(struct extent_buffer *eb, void *dst, |
| 180 | unsigned long start, |
| 181 | unsigned long len); |
| 182 | void write_extent_buffer(struct extent_buffer *eb, const void *src, |
| 183 | unsigned long start, unsigned long len); |
| 184 | void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src, |
| 185 | unsigned long dst_offset, unsigned long src_offset, |
| 186 | unsigned long len); |
| 187 | void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, |
| 188 | unsigned long src_offset, unsigned long len); |
| 189 | void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, |
| 190 | unsigned long src_offset, unsigned long len); |
| 191 | void memset_extent_buffer(struct extent_buffer *eb, char c, |
| 192 | unsigned long start, unsigned long len); |
| 193 | int wait_on_extent_buffer_writeback(struct extent_map_tree *tree, |
| 194 | struct extent_buffer *eb); |
| 195 | int clear_extent_buffer_dirty(struct extent_map_tree *tree, |
| 196 | struct extent_buffer *eb); |
| 197 | int set_extent_buffer_dirty(struct extent_map_tree *tree, |
| 198 | struct extent_buffer *eb); |
| 199 | int set_extent_buffer_uptodate(struct extent_map_tree *tree, |
| 200 | struct extent_buffer *eb); |
| 201 | int extent_buffer_uptodate(struct extent_map_tree *tree, |
| 202 | struct extent_buffer *eb); |
| 203 | int map_extent_buffer(struct extent_buffer *eb, unsigned long offset, |
Chris Mason | 479965d | 2007-10-15 16:14:27 -0400 | [diff] [blame] | 204 | unsigned long min_len, char **token, char **map, |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 205 | unsigned long *map_start, |
| 206 | unsigned long *map_len, int km); |
Chris Mason | 19c00dd | 2007-10-15 16:19:22 -0400 | [diff] [blame] | 207 | int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset, |
| 208 | unsigned long min_len, char **token, char **map, |
| 209 | unsigned long *map_start, |
| 210 | unsigned long *map_len, int km); |
Chris Mason | 5f39d39 | 2007-10-15 16:14:19 -0400 | [diff] [blame] | 211 | void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 212 | #endif |