Btrfs: Change TestSetPageLocked() to trylock_page()
[linux-2.6/verdex.git] / fs / btrfs / extent_io.h
blob315cfceae3128f72c59e4562b955763baa6dffde
1 #ifndef __EXTENTIO__
2 #define __EXTENTIO__
4 #include <linux/rbtree.h>
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_ORDERED (1 << 9)
17 #define EXTENT_ORDERED_METADATA (1 << 10)
18 #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
21 * page->private values. Every page that is controlled by the extent
22 * map has page->private set to one.
24 #define EXTENT_PAGE_PRIVATE 1
25 #define EXTENT_PAGE_PRIVATE_FIRST_PAGE 3
27 struct extent_state;
29 typedef int (extent_submit_bio_hook_t)(struct inode *inode, int rw,
30 struct bio *bio, int mirror_num);
31 struct extent_io_ops {
32 int (*fill_delalloc)(struct inode *inode, u64 start, u64 end);
33 int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
34 int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
35 extent_submit_bio_hook_t *submit_bio_hook;
36 int (*merge_bio_hook)(struct page *page, unsigned long offset,
37 size_t size, struct bio *bio);
38 int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
39 int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
40 u64 start, u64 end,
41 struct extent_state *state);
42 int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
43 u64 start, u64 end,
44 struct extent_state *state);
45 int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
46 struct extent_state *state);
47 int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
48 struct extent_state *state, int uptodate);
49 int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
50 unsigned long old, unsigned long bits);
51 int (*clear_bit_hook)(struct inode *inode, u64 start, u64 end,
52 unsigned long old, unsigned long bits);
55 struct extent_io_tree {
56 struct rb_root state;
57 struct rb_root buffer;
58 struct address_space *mapping;
59 u64 dirty_bytes;
60 spinlock_t lock;
61 spinlock_t buffer_lock;
62 struct extent_io_ops *ops;
65 struct extent_state {
66 u64 start;
67 u64 end; /* inclusive */
68 struct rb_node rb_node;
69 struct extent_io_tree *tree;
70 wait_queue_head_t wq;
71 atomic_t refs;
72 unsigned long state;
74 /* for use by the FS */
75 u64 private;
77 struct list_head leak_list;
80 struct extent_buffer {
81 u64 start;
82 unsigned long len;
83 char *map_token;
84 char *kaddr;
85 unsigned long map_start;
86 unsigned long map_len;
87 struct page *first_page;
88 atomic_t refs;
89 int flags;
90 struct list_head leak_list;
91 struct rb_node rb_node;
92 struct mutex mutex;
95 struct extent_map_tree;
97 static inline struct extent_state *extent_state_next(struct extent_state *state)
99 struct rb_node *node;
100 node = rb_next(&state->rb_node);
101 if (!node)
102 return NULL;
103 return rb_entry(node, struct extent_state, rb_node);
106 typedef struct extent_map *(get_extent_t)(struct inode *inode,
107 struct page *page,
108 size_t page_offset,
109 u64 start, u64 len,
110 int create);
112 void extent_io_tree_init(struct extent_io_tree *tree,
113 struct address_space *mapping, gfp_t mask);
114 int try_release_extent_mapping(struct extent_map_tree *map,
115 struct extent_io_tree *tree, struct page *page,
116 gfp_t mask);
117 int try_release_extent_buffer(struct extent_io_tree *tree, struct page *page);
118 int try_release_extent_state(struct extent_map_tree *map,
119 struct extent_io_tree *tree, struct page *page,
120 gfp_t mask);
121 int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
122 int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
123 int extent_read_full_page(struct extent_io_tree *tree, struct page *page,
124 get_extent_t *get_extent);
125 int __init extent_io_init(void);
126 void extent_io_exit(void);
128 u64 count_range_bits(struct extent_io_tree *tree,
129 u64 *start, u64 search_end,
130 u64 max_bytes, unsigned long bits);
132 int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
133 int bits, int filled);
134 int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
135 int bits, gfp_t mask);
136 int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
137 int bits, int wake, int delete, gfp_t mask);
138 int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
139 int bits, gfp_t mask);
140 int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
141 gfp_t mask);
142 int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
143 gfp_t mask);
144 int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
145 gfp_t mask);
146 int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
147 gfp_t mask);
148 int clear_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end,
149 gfp_t mask);
150 int clear_extent_ordered_metadata(struct extent_io_tree *tree, u64 start,
151 u64 end, gfp_t mask);
152 int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end,
153 gfp_t mask);
154 int set_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end,
155 gfp_t mask);
156 int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
157 u64 *start_ret, u64 *end_ret, int bits);
158 struct extent_state *find_first_extent_bit_state(struct extent_io_tree *tree,
159 u64 start, int bits);
160 int extent_invalidatepage(struct extent_io_tree *tree,
161 struct page *page, unsigned long offset);
162 int extent_write_full_page(struct extent_io_tree *tree, struct page *page,
163 get_extent_t *get_extent,
164 struct writeback_control *wbc);
165 int extent_writepages(struct extent_io_tree *tree,
166 struct address_space *mapping,
167 get_extent_t *get_extent,
168 struct writeback_control *wbc);
169 int extent_readpages(struct extent_io_tree *tree,
170 struct address_space *mapping,
171 struct list_head *pages, unsigned nr_pages,
172 get_extent_t get_extent);
173 int extent_prepare_write(struct extent_io_tree *tree,
174 struct inode *inode, struct page *page,
175 unsigned from, unsigned to, get_extent_t *get_extent);
176 int extent_commit_write(struct extent_io_tree *tree,
177 struct inode *inode, struct page *page,
178 unsigned from, unsigned to);
179 sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
180 get_extent_t *get_extent);
181 int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end);
182 int set_state_private(struct extent_io_tree *tree, u64 start, u64 private);
183 int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private);
184 void set_page_extent_mapped(struct page *page);
186 struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
187 u64 start, unsigned long len,
188 struct page *page0,
189 gfp_t mask);
190 struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
191 u64 start, unsigned long len,
192 gfp_t mask);
193 void free_extent_buffer(struct extent_buffer *eb);
194 int read_extent_buffer_pages(struct extent_io_tree *tree,
195 struct extent_buffer *eb, u64 start, int wait,
196 get_extent_t *get_extent, int mirror_num);
198 static inline void extent_buffer_get(struct extent_buffer *eb)
200 atomic_inc(&eb->refs);
203 int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
204 unsigned long start,
205 unsigned long len);
206 void read_extent_buffer(struct extent_buffer *eb, void *dst,
207 unsigned long start,
208 unsigned long len);
209 void write_extent_buffer(struct extent_buffer *eb, const void *src,
210 unsigned long start, unsigned long len);
211 void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
212 unsigned long dst_offset, unsigned long src_offset,
213 unsigned long len);
214 void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
215 unsigned long src_offset, unsigned long len);
216 void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
217 unsigned long src_offset, unsigned long len);
218 void memset_extent_buffer(struct extent_buffer *eb, char c,
219 unsigned long start, unsigned long len);
220 int wait_on_extent_buffer_writeback(struct extent_io_tree *tree,
221 struct extent_buffer *eb);
222 int wait_on_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end);
223 int wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits);
224 int clear_extent_buffer_dirty(struct extent_io_tree *tree,
225 struct extent_buffer *eb);
226 int set_extent_buffer_dirty(struct extent_io_tree *tree,
227 struct extent_buffer *eb);
228 int set_extent_buffer_uptodate(struct extent_io_tree *tree,
229 struct extent_buffer *eb);
230 int clear_extent_buffer_uptodate(struct extent_io_tree *tree,
231 struct extent_buffer *eb);
232 int extent_buffer_uptodate(struct extent_io_tree *tree,
233 struct extent_buffer *eb);
234 int map_extent_buffer(struct extent_buffer *eb, unsigned long offset,
235 unsigned long min_len, char **token, char **map,
236 unsigned long *map_start,
237 unsigned long *map_len, int km);
238 int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset,
239 unsigned long min_len, char **token, char **map,
240 unsigned long *map_start,
241 unsigned long *map_len, int km);
242 void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km);
243 int release_extent_buffer_tail_pages(struct extent_buffer *eb);
244 int extent_range_uptodate(struct extent_io_tree *tree,
245 u64 start, u64 end);
246 #endif