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