Staging: tm6000: silence Sparse warning "dubious: !x | !y"
[linux-2.6.git] / fs / btrfs / extent_io.h
blob7083cfafd061abf64f7b0c2252bd91324022b79a
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_BOUNDARY (1 << 9)
17 #define EXTENT_NODATASUM (1 << 10)
18 #define EXTENT_DO_ACCOUNTING (1 << 11)
19 #define EXTENT_FIRST_DELALLOC (1 << 12)
20 #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
21 #define EXTENT_CTLBITS (EXTENT_DO_ACCOUNTING | EXTENT_FIRST_DELALLOC)
24 * flags for bio submission. The high bits indicate the compression
25 * type for this bio
27 #define EXTENT_BIO_COMPRESSED 1
28 #define EXTENT_BIO_FLAG_SHIFT 16
30 /* these are bit numbers for test/set bit */
31 #define EXTENT_BUFFER_UPTODATE 0
32 #define EXTENT_BUFFER_BLOCKING 1
33 #define EXTENT_BUFFER_DIRTY 2
35 /* these are flags for extent_clear_unlock_delalloc */
36 #define EXTENT_CLEAR_UNLOCK_PAGE 0x1
37 #define EXTENT_CLEAR_UNLOCK 0x2
38 #define EXTENT_CLEAR_DELALLOC 0x4
39 #define EXTENT_CLEAR_DIRTY 0x8
40 #define EXTENT_SET_WRITEBACK 0x10
41 #define EXTENT_END_WRITEBACK 0x20
42 #define EXTENT_SET_PRIVATE2 0x40
43 #define EXTENT_CLEAR_ACCOUNTING 0x80
46 * page->private values. Every page that is controlled by the extent
47 * map has page->private set to one.
49 #define EXTENT_PAGE_PRIVATE 1
50 #define EXTENT_PAGE_PRIVATE_FIRST_PAGE 3
52 struct extent_state;
54 typedef int (extent_submit_bio_hook_t)(struct inode *inode, int rw,
55 struct bio *bio, int mirror_num,
56 unsigned long bio_flags, u64 bio_offset);
57 struct extent_io_ops {
58 int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
59 u64 start, u64 end, int *page_started,
60 unsigned long *nr_written);
61 int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
62 int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
63 extent_submit_bio_hook_t *submit_bio_hook;
64 int (*merge_bio_hook)(struct page *page, unsigned long offset,
65 size_t size, struct bio *bio,
66 unsigned long bio_flags);
67 int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
68 int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
69 u64 start, u64 end,
70 struct extent_state *state);
71 int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
72 u64 start, u64 end,
73 struct extent_state *state);
74 int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
75 struct extent_state *state);
76 int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
77 struct extent_state *state, int uptodate);
78 int (*set_bit_hook)(struct inode *inode, struct extent_state *state,
79 int *bits);
80 int (*clear_bit_hook)(struct inode *inode, struct extent_state *state,
81 int *bits);
82 int (*merge_extent_hook)(struct inode *inode,
83 struct extent_state *new,
84 struct extent_state *other);
85 int (*split_extent_hook)(struct inode *inode,
86 struct extent_state *orig, u64 split);
87 int (*write_cache_pages_lock_hook)(struct page *page);
90 struct extent_io_tree {
91 struct rb_root state;
92 struct radix_tree_root buffer;
93 struct address_space *mapping;
94 u64 dirty_bytes;
95 spinlock_t lock;
96 spinlock_t buffer_lock;
97 struct extent_io_ops *ops;
100 struct extent_state {
101 u64 start;
102 u64 end; /* inclusive */
103 struct rb_node rb_node;
105 /* ADD NEW ELEMENTS AFTER THIS */
106 struct extent_io_tree *tree;
107 wait_queue_head_t wq;
108 atomic_t refs;
109 unsigned long state;
110 u64 split_start;
111 u64 split_end;
113 /* for use by the FS */
114 u64 private;
116 struct list_head leak_list;
119 struct extent_buffer {
120 u64 start;
121 unsigned long len;
122 char *map_token;
123 char *kaddr;
124 unsigned long map_start;
125 unsigned long map_len;
126 struct page *first_page;
127 unsigned long bflags;
128 atomic_t refs;
129 struct list_head leak_list;
130 struct rcu_head rcu_head;
132 /* the spinlock is used to protect most operations */
133 spinlock_t lock;
136 * when we keep the lock held while blocking, waiters go onto
137 * the wq
139 wait_queue_head_t lock_wq;
142 static inline void extent_set_compress_type(unsigned long *bio_flags,
143 int compress_type)
145 *bio_flags |= compress_type << EXTENT_BIO_FLAG_SHIFT;
148 static inline int extent_compress_type(unsigned long bio_flags)
150 return bio_flags >> EXTENT_BIO_FLAG_SHIFT;
153 struct extent_map_tree;
155 static inline struct extent_state *extent_state_next(struct extent_state *state)
157 struct rb_node *node;
158 node = rb_next(&state->rb_node);
159 if (!node)
160 return NULL;
161 return rb_entry(node, struct extent_state, rb_node);
164 typedef struct extent_map *(get_extent_t)(struct inode *inode,
165 struct page *page,
166 size_t page_offset,
167 u64 start, u64 len,
168 int create);
170 void extent_io_tree_init(struct extent_io_tree *tree,
171 struct address_space *mapping, gfp_t mask);
172 int try_release_extent_mapping(struct extent_map_tree *map,
173 struct extent_io_tree *tree, struct page *page,
174 gfp_t mask);
175 int try_release_extent_buffer(struct extent_io_tree *tree, struct page *page);
176 int try_release_extent_state(struct extent_map_tree *map,
177 struct extent_io_tree *tree, struct page *page,
178 gfp_t mask);
179 int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
180 int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
181 int bits, struct extent_state **cached, gfp_t mask);
182 int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
183 int unlock_extent_cached(struct extent_io_tree *tree, u64 start, u64 end,
184 struct extent_state **cached, gfp_t mask);
185 int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end,
186 gfp_t mask);
187 int extent_read_full_page(struct extent_io_tree *tree, struct page *page,
188 get_extent_t *get_extent);
189 int __init extent_io_init(void);
190 void extent_io_exit(void);
192 u64 count_range_bits(struct extent_io_tree *tree,
193 u64 *start, u64 search_end,
194 u64 max_bytes, unsigned long bits);
196 void free_extent_state(struct extent_state *state);
197 int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
198 int bits, int filled, struct extent_state *cached_state);
199 int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
200 int bits, gfp_t mask);
201 int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
202 int bits, int wake, int delete, struct extent_state **cached,
203 gfp_t mask);
204 int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
205 int bits, gfp_t mask);
206 int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
207 int bits, int exclusive_bits, u64 *failed_start,
208 struct extent_state **cached_state, gfp_t mask);
209 int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
210 gfp_t mask);
211 int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
212 gfp_t mask);
213 int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
214 gfp_t mask);
215 int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
216 gfp_t mask);
217 int clear_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end,
218 gfp_t mask);
219 int clear_extent_ordered_metadata(struct extent_io_tree *tree, u64 start,
220 u64 end, gfp_t mask);
221 int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end,
222 struct extent_state **cached_state, gfp_t mask);
223 int set_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end,
224 gfp_t mask);
225 int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
226 u64 *start_ret, u64 *end_ret, int bits);
227 struct extent_state *find_first_extent_bit_state(struct extent_io_tree *tree,
228 u64 start, int bits);
229 int extent_invalidatepage(struct extent_io_tree *tree,
230 struct page *page, unsigned long offset);
231 int extent_write_full_page(struct extent_io_tree *tree, struct page *page,
232 get_extent_t *get_extent,
233 struct writeback_control *wbc);
234 int extent_write_locked_range(struct extent_io_tree *tree, struct inode *inode,
235 u64 start, u64 end, get_extent_t *get_extent,
236 int mode);
237 int extent_writepages(struct extent_io_tree *tree,
238 struct address_space *mapping,
239 get_extent_t *get_extent,
240 struct writeback_control *wbc);
241 int extent_readpages(struct extent_io_tree *tree,
242 struct address_space *mapping,
243 struct list_head *pages, unsigned nr_pages,
244 get_extent_t get_extent);
245 int extent_prepare_write(struct extent_io_tree *tree,
246 struct inode *inode, struct page *page,
247 unsigned from, unsigned to, get_extent_t *get_extent);
248 int extent_commit_write(struct extent_io_tree *tree,
249 struct inode *inode, struct page *page,
250 unsigned from, unsigned to);
251 sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
252 get_extent_t *get_extent);
253 int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
254 __u64 start, __u64 len, get_extent_t *get_extent);
255 int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end);
256 int set_state_private(struct extent_io_tree *tree, u64 start, u64 private);
257 int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private);
258 void set_page_extent_mapped(struct page *page);
260 struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
261 u64 start, unsigned long len,
262 struct page *page0,
263 gfp_t mask);
264 struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
265 u64 start, unsigned long len,
266 gfp_t mask);
267 void free_extent_buffer(struct extent_buffer *eb);
268 int read_extent_buffer_pages(struct extent_io_tree *tree,
269 struct extent_buffer *eb, u64 start, int wait,
270 get_extent_t *get_extent, int mirror_num);
272 static inline void extent_buffer_get(struct extent_buffer *eb)
274 atomic_inc(&eb->refs);
277 int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
278 unsigned long start,
279 unsigned long len);
280 void read_extent_buffer(struct extent_buffer *eb, void *dst,
281 unsigned long start,
282 unsigned long len);
283 void write_extent_buffer(struct extent_buffer *eb, const void *src,
284 unsigned long start, unsigned long len);
285 void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
286 unsigned long dst_offset, unsigned long src_offset,
287 unsigned long len);
288 void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
289 unsigned long src_offset, unsigned long len);
290 void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
291 unsigned long src_offset, unsigned long len);
292 void memset_extent_buffer(struct extent_buffer *eb, char c,
293 unsigned long start, unsigned long len);
294 int wait_on_extent_buffer_writeback(struct extent_io_tree *tree,
295 struct extent_buffer *eb);
296 int wait_on_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end);
297 int wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits);
298 int clear_extent_buffer_dirty(struct extent_io_tree *tree,
299 struct extent_buffer *eb);
300 int set_extent_buffer_dirty(struct extent_io_tree *tree,
301 struct extent_buffer *eb);
302 int test_extent_buffer_dirty(struct extent_io_tree *tree,
303 struct extent_buffer *eb);
304 int set_extent_buffer_uptodate(struct extent_io_tree *tree,
305 struct extent_buffer *eb);
306 int clear_extent_buffer_uptodate(struct extent_io_tree *tree,
307 struct extent_buffer *eb,
308 struct extent_state **cached_state);
309 int extent_buffer_uptodate(struct extent_io_tree *tree,
310 struct extent_buffer *eb,
311 struct extent_state *cached_state);
312 int map_extent_buffer(struct extent_buffer *eb, unsigned long offset,
313 unsigned long min_len, char **token, char **map,
314 unsigned long *map_start,
315 unsigned long *map_len, int km);
316 int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset,
317 unsigned long min_len, char **token, char **map,
318 unsigned long *map_start,
319 unsigned long *map_len, int km);
320 void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km);
321 int release_extent_buffer_tail_pages(struct extent_buffer *eb);
322 int extent_range_uptodate(struct extent_io_tree *tree,
323 u64 start, u64 end);
324 int extent_clear_unlock_delalloc(struct inode *inode,
325 struct extent_io_tree *tree,
326 u64 start, u64 end, struct page *locked_page,
327 unsigned long op);
328 struct bio *
329 btrfs_bio_alloc(struct block_device *bdev, u64 first_sector, int nr_vecs,
330 gfp_t gfp_flags);
331 #endif