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