blob: 283110ec4ee0f3da9937d64b83f263b80bf6e43e [file] [log] [blame]
Chris Masond1310b22008-01-24 16:13:08 -05001#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)
Chris Masone6dcd2d2008-07-17 12:53:50 -040016#define EXTENT_ORDERED (1 << 9)
17#define EXTENT_ORDERED_METADATA (1 << 10)
Zheng Yan5b21f2e2008-09-26 10:05:38 -040018#define EXTENT_BOUNDARY (1 << 11)
Chris Masond1310b22008-01-24 16:13:08 -050019#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
20
Chris Masonc8b97812008-10-29 14:49:59 -040021/* flags for bio submission */
22#define EXTENT_BIO_COMPRESSED 1
23
Chris Masond1310b22008-01-24 16:13:08 -050024/*
25 * page->private values. Every page that is controlled by the extent
26 * map has page->private set to one.
27 */
28#define EXTENT_PAGE_PRIVATE 1
29#define EXTENT_PAGE_PRIVATE_FIRST_PAGE 3
30
Chris Mason70dec802008-01-29 09:59:12 -050031struct extent_state;
32
Chris Mason44b8bd72008-04-16 11:14:51 -040033typedef int (extent_submit_bio_hook_t)(struct inode *inode, int rw,
Chris Masonc8b97812008-10-29 14:49:59 -040034 struct bio *bio, int mirror_num,
35 unsigned long bio_flags);
Chris Masond1310b22008-01-24 16:13:08 -050036struct extent_io_ops {
Chris Masonc8b97812008-10-29 14:49:59 -040037 int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
38 u64 start, u64 end, int *page_started);
Chris Mason247e7432008-07-17 12:53:51 -040039 int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
Chris Masond1310b22008-01-24 16:13:08 -050040 int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
Chris Mason44b8bd72008-04-16 11:14:51 -040041 extent_submit_bio_hook_t *submit_bio_hook;
Chris Mason239b14b2008-03-24 15:02:07 -040042 int (*merge_bio_hook)(struct page *page, unsigned long offset,
Chris Masonc8b97812008-10-29 14:49:59 -040043 size_t size, struct bio *bio,
44 unsigned long bio_flags);
Chris Masond1310b22008-01-24 16:13:08 -050045 int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
Chris Mason7e383262008-04-09 16:28:12 -040046 int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
47 u64 start, u64 end,
48 struct extent_state *state);
Chris Mason1259ab72008-05-12 13:39:03 -040049 int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
50 u64 start, u64 end,
51 struct extent_state *state);
Chris Mason70dec802008-01-29 09:59:12 -050052 int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
53 struct extent_state *state);
Chris Mason1259ab72008-05-12 13:39:03 -040054 int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
Chris Masone6dcd2d2008-07-17 12:53:50 -040055 struct extent_state *state, int uptodate);
Chris Mason291d6732008-01-29 15:55:23 -050056 int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
Chris Masonb0c68f82008-01-31 11:05:37 -050057 unsigned long old, unsigned long bits);
Chris Mason291d6732008-01-29 15:55:23 -050058 int (*clear_bit_hook)(struct inode *inode, u64 start, u64 end,
Chris Masonb0c68f82008-01-31 11:05:37 -050059 unsigned long old, unsigned long bits);
Chris Mason4bef0842008-09-08 11:18:08 -040060 int (*write_cache_pages_lock_hook)(struct page *page);
Chris Masond1310b22008-01-24 16:13:08 -050061};
62
63struct extent_io_tree {
64 struct rb_root state;
Chris Mason6af118ce2008-07-22 11:18:07 -040065 struct rb_root buffer;
Chris Masond1310b22008-01-24 16:13:08 -050066 struct address_space *mapping;
67 u64 dirty_bytes;
Chris Mason70dec802008-01-29 09:59:12 -050068 spinlock_t lock;
Chris Mason6af118ce2008-07-22 11:18:07 -040069 spinlock_t buffer_lock;
Chris Masond1310b22008-01-24 16:13:08 -050070 struct extent_io_ops *ops;
Chris Masond1310b22008-01-24 16:13:08 -050071};
72
73struct extent_state {
74 u64 start;
75 u64 end; /* inclusive */
Chris Masond1310b22008-01-24 16:13:08 -050076 struct rb_node rb_node;
Chris Mason70dec802008-01-29 09:59:12 -050077 struct extent_io_tree *tree;
Chris Masond1310b22008-01-24 16:13:08 -050078 wait_queue_head_t wq;
79 atomic_t refs;
80 unsigned long state;
81
82 /* for use by the FS */
83 u64 private;
84
Chris Mason2d2ae542008-03-26 16:24:23 -040085 struct list_head leak_list;
Chris Masond1310b22008-01-24 16:13:08 -050086};
87
88struct extent_buffer {
89 u64 start;
90 unsigned long len;
91 char *map_token;
92 char *kaddr;
93 unsigned long map_start;
94 unsigned long map_len;
95 struct page *first_page;
Chris Masond1310b22008-01-24 16:13:08 -050096 atomic_t refs;
97 int flags;
Chris Mason2d2ae542008-03-26 16:24:23 -040098 struct list_head leak_list;
Chris Mason6af118ce2008-07-22 11:18:07 -040099 struct rb_node rb_node;
Chris Masona61e6f22008-07-22 11:18:08 -0400100 struct mutex mutex;
Chris Masond1310b22008-01-24 16:13:08 -0500101};
102
103struct extent_map_tree;
104
Chris Masond7fc6402008-02-18 12:12:38 -0500105static inline struct extent_state *extent_state_next(struct extent_state *state)
106{
107 struct rb_node *node;
108 node = rb_next(&state->rb_node);
109 if (!node)
110 return NULL;
111 return rb_entry(node, struct extent_state, rb_node);
112}
113
Chris Masond1310b22008-01-24 16:13:08 -0500114typedef struct extent_map *(get_extent_t)(struct inode *inode,
115 struct page *page,
116 size_t page_offset,
117 u64 start, u64 len,
118 int create);
119
120void extent_io_tree_init(struct extent_io_tree *tree,
121 struct address_space *mapping, gfp_t mask);
Chris Masond1310b22008-01-24 16:13:08 -0500122int try_release_extent_mapping(struct extent_map_tree *map,
Chris Mason70dec802008-01-29 09:59:12 -0500123 struct extent_io_tree *tree, struct page *page,
124 gfp_t mask);
Chris Mason6af118ce2008-07-22 11:18:07 -0400125int try_release_extent_buffer(struct extent_io_tree *tree, struct page *page);
Chris Mason7b13b7b2008-04-18 10:29:50 -0400126int try_release_extent_state(struct extent_map_tree *map,
127 struct extent_io_tree *tree, struct page *page,
128 gfp_t mask);
Chris Masond1310b22008-01-24 16:13:08 -0500129int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
130int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
Josef Bacik25179202008-10-29 14:49:05 -0400131int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end,
132 gfp_t mask);
Chris Masond1310b22008-01-24 16:13:08 -0500133int extent_read_full_page(struct extent_io_tree *tree, struct page *page,
134 get_extent_t *get_extent);
135int __init extent_io_init(void);
136void extent_io_exit(void);
137
138u64 count_range_bits(struct extent_io_tree *tree,
139 u64 *start, u64 search_end,
140 u64 max_bytes, unsigned long bits);
141
142int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
143 int bits, int filled);
144int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
145 int bits, gfp_t mask);
Chris Masone6dcd2d2008-07-17 12:53:50 -0400146int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
147 int bits, int wake, int delete, gfp_t mask);
Chris Masond1310b22008-01-24 16:13:08 -0500148int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
149 int bits, gfp_t mask);
150int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
151 gfp_t mask);
152int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
153 gfp_t mask);
154int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
155 gfp_t mask);
156int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
157 gfp_t mask);
Chris Masone6dcd2d2008-07-17 12:53:50 -0400158int clear_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end,
159 gfp_t mask);
160int clear_extent_ordered_metadata(struct extent_io_tree *tree, u64 start,
161 u64 end, gfp_t mask);
Chris Masond1310b22008-01-24 16:13:08 -0500162int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end,
163 gfp_t mask);
Chris Masone6dcd2d2008-07-17 12:53:50 -0400164int set_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end,
165 gfp_t mask);
Chris Masond1310b22008-01-24 16:13:08 -0500166int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
167 u64 *start_ret, u64 *end_ret, int bits);
Chris Masond7fc6402008-02-18 12:12:38 -0500168struct extent_state *find_first_extent_bit_state(struct extent_io_tree *tree,
169 u64 start, int bits);
Chris Masond1310b22008-01-24 16:13:08 -0500170int extent_invalidatepage(struct extent_io_tree *tree,
171 struct page *page, unsigned long offset);
172int extent_write_full_page(struct extent_io_tree *tree, struct page *page,
173 get_extent_t *get_extent,
174 struct writeback_control *wbc);
175int extent_writepages(struct extent_io_tree *tree,
176 struct address_space *mapping,
177 get_extent_t *get_extent,
178 struct writeback_control *wbc);
179int extent_readpages(struct extent_io_tree *tree,
180 struct address_space *mapping,
181 struct list_head *pages, unsigned nr_pages,
182 get_extent_t get_extent);
183int extent_prepare_write(struct extent_io_tree *tree,
184 struct inode *inode, struct page *page,
185 unsigned from, unsigned to, get_extent_t *get_extent);
186int extent_commit_write(struct extent_io_tree *tree,
187 struct inode *inode, struct page *page,
188 unsigned from, unsigned to);
189sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
190 get_extent_t *get_extent);
191int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end);
192int set_state_private(struct extent_io_tree *tree, u64 start, u64 private);
193int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private);
194void set_page_extent_mapped(struct page *page);
195
196struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
197 u64 start, unsigned long len,
198 struct page *page0,
199 gfp_t mask);
200struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
201 u64 start, unsigned long len,
202 gfp_t mask);
203void free_extent_buffer(struct extent_buffer *eb);
204int read_extent_buffer_pages(struct extent_io_tree *tree,
Chris Masona86c12c2008-02-07 10:50:54 -0500205 struct extent_buffer *eb, u64 start, int wait,
Chris Masonf1885912008-04-09 16:28:12 -0400206 get_extent_t *get_extent, int mirror_num);
Chris Masond1310b22008-01-24 16:13:08 -0500207
208static inline void extent_buffer_get(struct extent_buffer *eb)
209{
210 atomic_inc(&eb->refs);
211}
212
213int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
214 unsigned long start,
215 unsigned long len);
216void read_extent_buffer(struct extent_buffer *eb, void *dst,
217 unsigned long start,
218 unsigned long len);
219void write_extent_buffer(struct extent_buffer *eb, const void *src,
220 unsigned long start, unsigned long len);
221void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
222 unsigned long dst_offset, unsigned long src_offset,
223 unsigned long len);
224void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
225 unsigned long src_offset, unsigned long len);
226void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
227 unsigned long src_offset, unsigned long len);
228void memset_extent_buffer(struct extent_buffer *eb, char c,
229 unsigned long start, unsigned long len);
230int wait_on_extent_buffer_writeback(struct extent_io_tree *tree,
231 struct extent_buffer *eb);
Chris Masone6dcd2d2008-07-17 12:53:50 -0400232int wait_on_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end);
233int wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits);
Chris Masond1310b22008-01-24 16:13:08 -0500234int clear_extent_buffer_dirty(struct extent_io_tree *tree,
235 struct extent_buffer *eb);
236int set_extent_buffer_dirty(struct extent_io_tree *tree,
237 struct extent_buffer *eb);
238int set_extent_buffer_uptodate(struct extent_io_tree *tree,
239 struct extent_buffer *eb);
Chris Mason1259ab72008-05-12 13:39:03 -0400240int clear_extent_buffer_uptodate(struct extent_io_tree *tree,
241 struct extent_buffer *eb);
Chris Masond1310b22008-01-24 16:13:08 -0500242int extent_buffer_uptodate(struct extent_io_tree *tree,
243 struct extent_buffer *eb);
244int map_extent_buffer(struct extent_buffer *eb, unsigned long offset,
245 unsigned long min_len, char **token, char **map,
246 unsigned long *map_start,
247 unsigned long *map_len, int km);
248int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset,
249 unsigned long min_len, char **token, char **map,
250 unsigned long *map_start,
251 unsigned long *map_len, int km);
252void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km);
Chris Masonce9adaa2008-04-09 16:28:12 -0400253int release_extent_buffer_tail_pages(struct extent_buffer *eb);
254int extent_range_uptodate(struct extent_io_tree *tree,
255 u64 start, u64 end);
Chris Masonc8b97812008-10-29 14:49:59 -0400256int extent_clear_unlock_delalloc(struct inode *inode,
257 struct extent_io_tree *tree,
258 u64 start, u64 end, struct page *locked_page,
259 int clear_dirty, int set_writeback,
260 int clear_writeback);
Chris Masond1310b22008-01-24 16:13:08 -0500261#endif