blob: fcc4bb078c24fa17a27985d2ac8121a760c695bc [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)
16#define EXTENT_CSUM (1 << 9)
17#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
18
19/*
20 * page->private values. Every page that is controlled by the extent
21 * map has page->private set to one.
22 */
23#define EXTENT_PAGE_PRIVATE 1
24#define EXTENT_PAGE_PRIVATE_FIRST_PAGE 3
25
Chris Mason70dec802008-01-29 09:59:12 -050026struct extent_state;
27
Chris Masond1310b22008-01-24 16:13:08 -050028struct extent_io_ops {
29 int (*fill_delalloc)(struct inode *inode, u64 start, u64 end);
30 int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
31 int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
Chris Mason70dec802008-01-29 09:59:12 -050032 int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
33 struct extent_state *state);
34 void (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
35 struct extent_state *state);
Chris Mason291d6732008-01-29 15:55:23 -050036 int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
Chris Masonb0c68f82008-01-31 11:05:37 -050037 unsigned long old, unsigned long bits);
Chris Mason291d6732008-01-29 15:55:23 -050038 int (*clear_bit_hook)(struct inode *inode, u64 start, u64 end,
Chris Masonb0c68f82008-01-31 11:05:37 -050039 unsigned long old, unsigned long bits);
Chris Masond1310b22008-01-24 16:13:08 -050040};
41
42struct extent_io_tree {
43 struct rb_root state;
44 struct address_space *mapping;
45 u64 dirty_bytes;
Chris Mason70dec802008-01-29 09:59:12 -050046 spinlock_t lock;
Chris Masond1310b22008-01-24 16:13:08 -050047 struct extent_io_ops *ops;
48 spinlock_t lru_lock;
49 struct list_head buffer_lru;
50 int lru_size;
Chris Mason80ea96b2008-02-01 14:51:59 -050051 struct extent_state *last;
Chris Masond1310b22008-01-24 16:13:08 -050052};
53
54struct extent_state {
55 u64 start;
56 u64 end; /* inclusive */
Chris Masond1310b22008-01-24 16:13:08 -050057 struct rb_node rb_node;
Chris Mason70dec802008-01-29 09:59:12 -050058 struct extent_io_tree *tree;
Chris Masond1310b22008-01-24 16:13:08 -050059 wait_queue_head_t wq;
60 atomic_t refs;
61 unsigned long state;
62
63 /* for use by the FS */
64 u64 private;
65
66 struct list_head list;
67};
68
69struct extent_buffer {
70 u64 start;
71 unsigned long len;
72 char *map_token;
73 char *kaddr;
74 unsigned long map_start;
75 unsigned long map_len;
76 struct page *first_page;
77 struct list_head lru;
78 atomic_t refs;
79 int flags;
80};
81
82struct extent_map_tree;
83
Chris Masond7fc6402008-02-18 12:12:38 -050084static inline struct extent_state *extent_state_next(struct extent_state *state)
85{
86 struct rb_node *node;
87 node = rb_next(&state->rb_node);
88 if (!node)
89 return NULL;
90 return rb_entry(node, struct extent_state, rb_node);
91}
92
Chris Masond1310b22008-01-24 16:13:08 -050093typedef struct extent_map *(get_extent_t)(struct inode *inode,
94 struct page *page,
95 size_t page_offset,
96 u64 start, u64 len,
97 int create);
98
99void extent_io_tree_init(struct extent_io_tree *tree,
100 struct address_space *mapping, gfp_t mask);
101void extent_io_tree_empty_lru(struct extent_io_tree *tree);
102int try_release_extent_mapping(struct extent_map_tree *map,
Chris Mason70dec802008-01-29 09:59:12 -0500103 struct extent_io_tree *tree, struct page *page,
104 gfp_t mask);
Chris Masond1310b22008-01-24 16:13:08 -0500105int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
106int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
107int extent_read_full_page(struct extent_io_tree *tree, struct page *page,
108 get_extent_t *get_extent);
109int __init extent_io_init(void);
110void extent_io_exit(void);
111
112u64 count_range_bits(struct extent_io_tree *tree,
113 u64 *start, u64 search_end,
114 u64 max_bytes, unsigned long bits);
115
116int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
117 int bits, int filled);
118int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
119 int bits, gfp_t mask);
120int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
121 int bits, gfp_t mask);
122int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
123 gfp_t mask);
124int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
125 gfp_t mask);
126int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
127 gfp_t mask);
128int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
129 gfp_t mask);
130int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end,
131 gfp_t mask);
132int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
133 u64 *start_ret, u64 *end_ret, int bits);
Chris Masond7fc6402008-02-18 12:12:38 -0500134struct extent_state *find_first_extent_bit_state(struct extent_io_tree *tree,
135 u64 start, int bits);
Chris Masond1310b22008-01-24 16:13:08 -0500136int extent_invalidatepage(struct extent_io_tree *tree,
137 struct page *page, unsigned long offset);
138int extent_write_full_page(struct extent_io_tree *tree, struct page *page,
139 get_extent_t *get_extent,
140 struct writeback_control *wbc);
141int extent_writepages(struct extent_io_tree *tree,
142 struct address_space *mapping,
143 get_extent_t *get_extent,
144 struct writeback_control *wbc);
145int extent_readpages(struct extent_io_tree *tree,
146 struct address_space *mapping,
147 struct list_head *pages, unsigned nr_pages,
148 get_extent_t get_extent);
149int extent_prepare_write(struct extent_io_tree *tree,
150 struct inode *inode, struct page *page,
151 unsigned from, unsigned to, get_extent_t *get_extent);
152int extent_commit_write(struct extent_io_tree *tree,
153 struct inode *inode, struct page *page,
154 unsigned from, unsigned to);
155sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
156 get_extent_t *get_extent);
157int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end);
158int set_state_private(struct extent_io_tree *tree, u64 start, u64 private);
159int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private);
160void set_page_extent_mapped(struct page *page);
161
162struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
163 u64 start, unsigned long len,
164 struct page *page0,
165 gfp_t mask);
166struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
167 u64 start, unsigned long len,
168 gfp_t mask);
169void free_extent_buffer(struct extent_buffer *eb);
170int read_extent_buffer_pages(struct extent_io_tree *tree,
Chris Masona86c12c2008-02-07 10:50:54 -0500171 struct extent_buffer *eb, u64 start, int wait,
172 get_extent_t *get_extent);
Chris Masond1310b22008-01-24 16:13:08 -0500173
174static inline void extent_buffer_get(struct extent_buffer *eb)
175{
176 atomic_inc(&eb->refs);
177}
178
179int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
180 unsigned long start,
181 unsigned long len);
182void read_extent_buffer(struct extent_buffer *eb, void *dst,
183 unsigned long start,
184 unsigned long len);
185void write_extent_buffer(struct extent_buffer *eb, const void *src,
186 unsigned long start, unsigned long len);
187void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
188 unsigned long dst_offset, unsigned long src_offset,
189 unsigned long len);
190void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
191 unsigned long src_offset, unsigned long len);
192void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
193 unsigned long src_offset, unsigned long len);
194void memset_extent_buffer(struct extent_buffer *eb, char c,
195 unsigned long start, unsigned long len);
196int wait_on_extent_buffer_writeback(struct extent_io_tree *tree,
197 struct extent_buffer *eb);
198int clear_extent_buffer_dirty(struct extent_io_tree *tree,
199 struct extent_buffer *eb);
200int set_extent_buffer_dirty(struct extent_io_tree *tree,
201 struct extent_buffer *eb);
202int set_extent_buffer_uptodate(struct extent_io_tree *tree,
203 struct extent_buffer *eb);
204int extent_buffer_uptodate(struct extent_io_tree *tree,
205 struct extent_buffer *eb);
206int map_extent_buffer(struct extent_buffer *eb, unsigned long offset,
207 unsigned long min_len, char **token, char **map,
208 unsigned long *map_start,
209 unsigned long *map_len, int km);
210int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset,
211 unsigned long min_len, char **token, char **map,
212 unsigned long *map_start,
213 unsigned long *map_len, int km);
214void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km);
215#endif