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