Btrfs: Add zlib compression support
[linux-2.6/linux-loongson.git] / fs / btrfs / extent_io.h
blob86f859b87a6ec51bffe6975f8a95704f65bc5c53
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_BOUNDARY (1 << 11)
19 #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
21 /* flags for bio submission */
22 #define EXTENT_BIO_COMPRESSED 1
25 * page->private values. Every page that is controlled by the extent
26 * map has page->private set to one.
28 #define EXTENT_PAGE_PRIVATE 1
29 #define EXTENT_PAGE_PRIVATE_FIRST_PAGE 3
31 struct extent_state;
33 typedef int (extent_submit_bio_hook_t)(struct inode *inode, int rw,
34 struct bio *bio, int mirror_num,
35 unsigned long bio_flags);
36 struct extent_io_ops {
37 int (*fill_delalloc)(struct inode *inode, struct page *locked_page,
38 u64 start, u64 end, int *page_started);
39 int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
40 int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
41 extent_submit_bio_hook_t *submit_bio_hook;
42 int (*merge_bio_hook)(struct page *page, unsigned long offset,
43 size_t size, struct bio *bio,
44 unsigned long bio_flags);
45 int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
46 int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
47 u64 start, u64 end,
48 struct extent_state *state);
49 int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
50 u64 start, u64 end,
51 struct extent_state *state);
52 int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
53 struct extent_state *state);
54 int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
55 struct extent_state *state, int uptodate);
56 int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
57 unsigned long old, unsigned long bits);
58 int (*clear_bit_hook)(struct inode *inode, u64 start, u64 end,
59 unsigned long old, unsigned long bits);
60 int (*write_cache_pages_lock_hook)(struct page *page);
63 struct extent_io_tree {
64 struct rb_root state;
65 struct rb_root buffer;
66 struct address_space *mapping;
67 u64 dirty_bytes;
68 spinlock_t lock;
69 spinlock_t buffer_lock;
70 struct extent_io_ops *ops;
73 struct extent_state {
74 u64 start;
75 u64 end; /* inclusive */
76 struct rb_node rb_node;
77 struct extent_io_tree *tree;
78 wait_queue_head_t wq;
79 atomic_t refs;
80 unsigned long state;
82 /* for use by the FS */
83 u64 private;
85 struct list_head leak_list;
88 struct 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;
96 atomic_t refs;
97 int flags;
98 struct list_head leak_list;
99 struct rb_node rb_node;
100 struct mutex mutex;
103 struct extent_map_tree;
105 static inline struct extent_state *extent_state_next(struct extent_state *state)
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);
114 typedef 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);
120 void extent_io_tree_init(struct extent_io_tree *tree,
121 struct address_space *mapping, gfp_t mask);
122 int try_release_extent_mapping(struct extent_map_tree *map,
123 struct extent_io_tree *tree, struct page *page,
124 gfp_t mask);
125 int try_release_extent_buffer(struct extent_io_tree *tree, struct page *page);
126 int try_release_extent_state(struct extent_map_tree *map,
127 struct extent_io_tree *tree, struct page *page,
128 gfp_t mask);
129 int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
130 int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
131 int extent_read_full_page(struct extent_io_tree *tree, struct page *page,
132 get_extent_t *get_extent);
133 int __init extent_io_init(void);
134 void extent_io_exit(void);
136 u64 count_range_bits(struct extent_io_tree *tree,
137 u64 *start, u64 search_end,
138 u64 max_bytes, unsigned long bits);
140 int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
141 int bits, int filled);
142 int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
143 int bits, gfp_t mask);
144 int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
145 int bits, int wake, int delete, gfp_t mask);
146 int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
147 int bits, gfp_t mask);
148 int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
149 gfp_t mask);
150 int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
151 gfp_t mask);
152 int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
153 gfp_t mask);
154 int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
155 gfp_t mask);
156 int clear_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end,
157 gfp_t mask);
158 int clear_extent_ordered_metadata(struct extent_io_tree *tree, u64 start,
159 u64 end, gfp_t mask);
160 int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end,
161 gfp_t mask);
162 int set_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end,
163 gfp_t mask);
164 int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
165 u64 *start_ret, u64 *end_ret, int bits);
166 struct extent_state *find_first_extent_bit_state(struct extent_io_tree *tree,
167 u64 start, int bits);
168 int extent_invalidatepage(struct extent_io_tree *tree,
169 struct page *page, unsigned long offset);
170 int extent_write_full_page(struct extent_io_tree *tree, struct page *page,
171 get_extent_t *get_extent,
172 struct writeback_control *wbc);
173 int extent_writepages(struct extent_io_tree *tree,
174 struct address_space *mapping,
175 get_extent_t *get_extent,
176 struct writeback_control *wbc);
177 int extent_readpages(struct extent_io_tree *tree,
178 struct address_space *mapping,
179 struct list_head *pages, unsigned nr_pages,
180 get_extent_t get_extent);
181 int extent_prepare_write(struct extent_io_tree *tree,
182 struct inode *inode, struct page *page,
183 unsigned from, unsigned to, get_extent_t *get_extent);
184 int extent_commit_write(struct extent_io_tree *tree,
185 struct inode *inode, struct page *page,
186 unsigned from, unsigned to);
187 sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
188 get_extent_t *get_extent);
189 int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end);
190 int set_state_private(struct extent_io_tree *tree, u64 start, u64 private);
191 int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private);
192 void set_page_extent_mapped(struct page *page);
194 struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
195 u64 start, unsigned long len,
196 struct page *page0,
197 gfp_t mask);
198 struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
199 u64 start, unsigned long len,
200 gfp_t mask);
201 void free_extent_buffer(struct extent_buffer *eb);
202 int read_extent_buffer_pages(struct extent_io_tree *tree,
203 struct extent_buffer *eb, u64 start, int wait,
204 get_extent_t *get_extent, int mirror_num);
206 static inline void extent_buffer_get(struct extent_buffer *eb)
208 atomic_inc(&eb->refs);
211 int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
212 unsigned long start,
213 unsigned long len);
214 void read_extent_buffer(struct extent_buffer *eb, void *dst,
215 unsigned long start,
216 unsigned long len);
217 void write_extent_buffer(struct extent_buffer *eb, const void *src,
218 unsigned long start, unsigned long len);
219 void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
220 unsigned long dst_offset, unsigned long src_offset,
221 unsigned long len);
222 void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
223 unsigned long src_offset, unsigned long len);
224 void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
225 unsigned long src_offset, unsigned long len);
226 void memset_extent_buffer(struct extent_buffer *eb, char c,
227 unsigned long start, unsigned long len);
228 int wait_on_extent_buffer_writeback(struct extent_io_tree *tree,
229 struct extent_buffer *eb);
230 int wait_on_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end);
231 int wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits);
232 int clear_extent_buffer_dirty(struct extent_io_tree *tree,
233 struct extent_buffer *eb);
234 int set_extent_buffer_dirty(struct extent_io_tree *tree,
235 struct extent_buffer *eb);
236 int set_extent_buffer_uptodate(struct extent_io_tree *tree,
237 struct extent_buffer *eb);
238 int clear_extent_buffer_uptodate(struct extent_io_tree *tree,
239 struct extent_buffer *eb);
240 int extent_buffer_uptodate(struct extent_io_tree *tree,
241 struct extent_buffer *eb);
242 int map_extent_buffer(struct extent_buffer *eb, unsigned long offset,
243 unsigned long min_len, char **token, char **map,
244 unsigned long *map_start,
245 unsigned long *map_len, int km);
246 int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset,
247 unsigned long min_len, char **token, char **map,
248 unsigned long *map_start,
249 unsigned long *map_len, int km);
250 void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km);
251 int release_extent_buffer_tail_pages(struct extent_buffer *eb);
252 int extent_range_uptodate(struct extent_io_tree *tree,
253 u64 start, u64 end);
254 int extent_clear_unlock_delalloc(struct inode *inode,
255 struct extent_io_tree *tree,
256 u64 start, u64 end, struct page *locked_page,
257 int clear_dirty, int set_writeback,
258 int clear_writeback);
259 #endif