blob: b47859ccd78a5b558061f3bc0901cf61857b78e7 [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 Masond1310b22008-01-24 16:13:08 -050016#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
17
18/*
19 * page->private values. Every page that is controlled by the extent
20 * map has page->private set to one.
21 */
22#define EXTENT_PAGE_PRIVATE 1
23#define EXTENT_PAGE_PRIVATE_FIRST_PAGE 3
24
Chris Mason70dec802008-01-29 09:59:12 -050025struct extent_state;
26
Chris Masond1310b22008-01-24 16:13:08 -050027struct extent_io_ops {
28 int (*fill_delalloc)(struct inode *inode, u64 start, u64 end);
29 int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
Chris Masonf1885912008-04-09 16:28:12 -040030 int (*submit_bio_hook)(struct inode *inode, int rw, struct bio *bio,
31 int mirror_num);
Chris Mason239b14b2008-03-24 15:02:07 -040032 int (*merge_bio_hook)(struct page *page, unsigned long offset,
33 size_t size, struct bio *bio);
Chris Masond1310b22008-01-24 16:13:08 -050034 int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
Chris Mason7e383262008-04-09 16:28:12 -040035 int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
36 u64 start, u64 end,
37 struct extent_state *state);
Chris Mason70dec802008-01-29 09:59:12 -050038 int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
39 struct extent_state *state);
40 void (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
41 struct extent_state *state);
Chris Mason291d6732008-01-29 15:55:23 -050042 int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
Chris Masonb0c68f82008-01-31 11:05:37 -050043 unsigned long old, unsigned long bits);
Chris Mason291d6732008-01-29 15:55:23 -050044 int (*clear_bit_hook)(struct inode *inode, u64 start, u64 end,
Chris Masonb0c68f82008-01-31 11:05:37 -050045 unsigned long old, unsigned long bits);
Chris Masond1310b22008-01-24 16:13:08 -050046};
47
48struct extent_io_tree {
49 struct rb_root state;
50 struct address_space *mapping;
51 u64 dirty_bytes;
Chris Mason70dec802008-01-29 09:59:12 -050052 spinlock_t lock;
Chris Masond1310b22008-01-24 16:13:08 -050053 struct extent_io_ops *ops;
54 spinlock_t lru_lock;
55 struct list_head buffer_lru;
56 int lru_size;
Chris Mason80ea96b2008-02-01 14:51:59 -050057 struct extent_state *last;
Chris Masond1310b22008-01-24 16:13:08 -050058};
59
60struct extent_state {
61 u64 start;
62 u64 end; /* inclusive */
Chris Masond1310b22008-01-24 16:13:08 -050063 struct rb_node rb_node;
Chris Mason70dec802008-01-29 09:59:12 -050064 struct extent_io_tree *tree;
Chris Masond1310b22008-01-24 16:13:08 -050065 wait_queue_head_t wq;
66 atomic_t refs;
67 unsigned long state;
68
69 /* for use by the FS */
70 u64 private;
71
Chris Mason2d2ae542008-03-26 16:24:23 -040072 struct list_head leak_list;
Chris Masond1310b22008-01-24 16:13:08 -050073};
74
75struct extent_buffer {
76 u64 start;
77 unsigned long len;
78 char *map_token;
79 char *kaddr;
80 unsigned long map_start;
81 unsigned long map_len;
82 struct page *first_page;
83 struct list_head lru;
84 atomic_t refs;
85 int flags;
Chris Mason2d2ae542008-03-26 16:24:23 -040086 struct list_head leak_list;
Chris Masond1310b22008-01-24 16:13:08 -050087};
88
89struct extent_map_tree;
90
Chris Masond7fc6402008-02-18 12:12:38 -050091static inline struct extent_state *extent_state_next(struct extent_state *state)
92{
93 struct rb_node *node;
94 node = rb_next(&state->rb_node);
95 if (!node)
96 return NULL;
97 return rb_entry(node, struct extent_state, rb_node);
98}
99
Chris Masond1310b22008-01-24 16:13:08 -0500100typedef struct extent_map *(get_extent_t)(struct inode *inode,
101 struct page *page,
102 size_t page_offset,
103 u64 start, u64 len,
104 int create);
105
106void extent_io_tree_init(struct extent_io_tree *tree,
107 struct address_space *mapping, gfp_t mask);
108void extent_io_tree_empty_lru(struct extent_io_tree *tree);
109int try_release_extent_mapping(struct extent_map_tree *map,
Chris Mason70dec802008-01-29 09:59:12 -0500110 struct extent_io_tree *tree, struct page *page,
111 gfp_t mask);
Chris Masond1310b22008-01-24 16:13:08 -0500112int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
113int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
114int extent_read_full_page(struct extent_io_tree *tree, struct page *page,
115 get_extent_t *get_extent);
116int __init extent_io_init(void);
117void extent_io_exit(void);
118
119u64 count_range_bits(struct extent_io_tree *tree,
120 u64 *start, u64 search_end,
121 u64 max_bytes, unsigned long bits);
122
123int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
124 int bits, int filled);
125int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
126 int bits, gfp_t mask);
127int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
128 int bits, gfp_t mask);
129int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
130 gfp_t mask);
131int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
132 gfp_t mask);
133int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
134 gfp_t mask);
135int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
136 gfp_t mask);
137int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end,
138 gfp_t mask);
139int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
140 u64 *start_ret, u64 *end_ret, int bits);
Chris Masond7fc6402008-02-18 12:12:38 -0500141struct extent_state *find_first_extent_bit_state(struct extent_io_tree *tree,
142 u64 start, int bits);
Chris Masond1310b22008-01-24 16:13:08 -0500143int extent_invalidatepage(struct extent_io_tree *tree,
144 struct page *page, unsigned long offset);
145int extent_write_full_page(struct extent_io_tree *tree, struct page *page,
146 get_extent_t *get_extent,
147 struct writeback_control *wbc);
148int extent_writepages(struct extent_io_tree *tree,
149 struct address_space *mapping,
150 get_extent_t *get_extent,
151 struct writeback_control *wbc);
152int extent_readpages(struct extent_io_tree *tree,
153 struct address_space *mapping,
154 struct list_head *pages, unsigned nr_pages,
155 get_extent_t get_extent);
156int extent_prepare_write(struct extent_io_tree *tree,
157 struct inode *inode, struct page *page,
158 unsigned from, unsigned to, get_extent_t *get_extent);
159int extent_commit_write(struct extent_io_tree *tree,
160 struct inode *inode, struct page *page,
161 unsigned from, unsigned to);
162sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
163 get_extent_t *get_extent);
164int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end);
165int set_state_private(struct extent_io_tree *tree, u64 start, u64 private);
166int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private);
167void set_page_extent_mapped(struct page *page);
168
169struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
170 u64 start, unsigned long len,
171 struct page *page0,
172 gfp_t mask);
173struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
174 u64 start, unsigned long len,
175 gfp_t mask);
176void free_extent_buffer(struct extent_buffer *eb);
177int read_extent_buffer_pages(struct extent_io_tree *tree,
Chris Masona86c12c2008-02-07 10:50:54 -0500178 struct extent_buffer *eb, u64 start, int wait,
Chris Masonf1885912008-04-09 16:28:12 -0400179 get_extent_t *get_extent, int mirror_num);
Chris Masond1310b22008-01-24 16:13:08 -0500180
181static inline void extent_buffer_get(struct extent_buffer *eb)
182{
183 atomic_inc(&eb->refs);
184}
185
186int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
187 unsigned long start,
188 unsigned long len);
189void read_extent_buffer(struct extent_buffer *eb, void *dst,
190 unsigned long start,
191 unsigned long len);
192void write_extent_buffer(struct extent_buffer *eb, const void *src,
193 unsigned long start, unsigned long len);
194void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
195 unsigned long dst_offset, unsigned long src_offset,
196 unsigned long len);
197void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
198 unsigned long src_offset, unsigned long len);
199void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
200 unsigned long src_offset, unsigned long len);
201void memset_extent_buffer(struct extent_buffer *eb, char c,
202 unsigned long start, unsigned long len);
203int wait_on_extent_buffer_writeback(struct extent_io_tree *tree,
204 struct extent_buffer *eb);
205int clear_extent_buffer_dirty(struct extent_io_tree *tree,
206 struct extent_buffer *eb);
207int set_extent_buffer_dirty(struct extent_io_tree *tree,
208 struct extent_buffer *eb);
209int set_extent_buffer_uptodate(struct extent_io_tree *tree,
210 struct extent_buffer *eb);
211int extent_buffer_uptodate(struct extent_io_tree *tree,
212 struct extent_buffer *eb);
213int map_extent_buffer(struct extent_buffer *eb, unsigned long offset,
214 unsigned long min_len, char **token, char **map,
215 unsigned long *map_start,
216 unsigned long *map_len, int km);
217int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset,
218 unsigned long min_len, char **token, char **map,
219 unsigned long *map_start,
220 unsigned long *map_len, int km);
221void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km);
Chris Mason728131d2008-04-09 16:28:12 -0400222int invalidate_extent_lru(struct extent_io_tree *tree, u64 start,
223 unsigned long len);
Chris Masonce9adaa2008-04-09 16:28:12 -0400224int release_extent_buffer_tail_pages(struct extent_buffer *eb);
225int extent_range_uptodate(struct extent_io_tree *tree,
226 u64 start, u64 end);
Chris Masond1310b22008-01-24 16:13:08 -0500227#endif