blob: 6fd5e2c90615c4bdf77c854a4e02cd2f2a7d5782 [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;
51};
52
53struct extent_state {
54 u64 start;
55 u64 end; /* inclusive */
Chris Masond1310b22008-01-24 16:13:08 -050056 struct rb_node rb_node;
Chris Mason70dec802008-01-29 09:59:12 -050057 struct extent_io_tree *tree;
Chris Masond1310b22008-01-24 16:13:08 -050058 wait_queue_head_t wq;
59 atomic_t refs;
60 unsigned long state;
61
62 /* for use by the FS */
63 u64 private;
64
65 struct list_head list;
66};
67
68struct extent_buffer {
69 u64 start;
70 unsigned long len;
71 char *map_token;
72 char *kaddr;
73 unsigned long map_start;
74 unsigned long map_len;
75 struct page *first_page;
76 struct list_head lru;
77 atomic_t refs;
78 int flags;
79};
80
81struct extent_map_tree;
82
83typedef struct extent_map *(get_extent_t)(struct inode *inode,
84 struct page *page,
85 size_t page_offset,
86 u64 start, u64 len,
87 int create);
88
89void extent_io_tree_init(struct extent_io_tree *tree,
90 struct address_space *mapping, gfp_t mask);
91void extent_io_tree_empty_lru(struct extent_io_tree *tree);
92int try_release_extent_mapping(struct extent_map_tree *map,
Chris Mason70dec802008-01-29 09:59:12 -050093 struct extent_io_tree *tree, struct page *page,
94 gfp_t mask);
Chris Masond1310b22008-01-24 16:13:08 -050095int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
96int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
97int extent_read_full_page(struct extent_io_tree *tree, struct page *page,
98 get_extent_t *get_extent);
99int __init extent_io_init(void);
100void extent_io_exit(void);
101
102u64 count_range_bits(struct extent_io_tree *tree,
103 u64 *start, u64 search_end,
104 u64 max_bytes, unsigned long bits);
105
106int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
107 int bits, int filled);
108int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
109 int bits, gfp_t mask);
110int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
111 int bits, gfp_t mask);
112int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
113 gfp_t mask);
114int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
115 gfp_t mask);
116int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
117 gfp_t mask);
118int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
119 gfp_t mask);
120int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end,
121 gfp_t mask);
122int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
123 u64 *start_ret, u64 *end_ret, int bits);
124int extent_invalidatepage(struct extent_io_tree *tree,
125 struct page *page, unsigned long offset);
126int extent_write_full_page(struct extent_io_tree *tree, struct page *page,
127 get_extent_t *get_extent,
128 struct writeback_control *wbc);
129int extent_writepages(struct extent_io_tree *tree,
130 struct address_space *mapping,
131 get_extent_t *get_extent,
132 struct writeback_control *wbc);
133int extent_readpages(struct extent_io_tree *tree,
134 struct address_space *mapping,
135 struct list_head *pages, unsigned nr_pages,
136 get_extent_t get_extent);
137int extent_prepare_write(struct extent_io_tree *tree,
138 struct inode *inode, struct page *page,
139 unsigned from, unsigned to, get_extent_t *get_extent);
140int extent_commit_write(struct extent_io_tree *tree,
141 struct inode *inode, struct page *page,
142 unsigned from, unsigned to);
143sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
144 get_extent_t *get_extent);
145int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end);
146int set_state_private(struct extent_io_tree *tree, u64 start, u64 private);
147int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private);
148void set_page_extent_mapped(struct page *page);
149
150struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
151 u64 start, unsigned long len,
152 struct page *page0,
153 gfp_t mask);
154struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
155 u64 start, unsigned long len,
156 gfp_t mask);
157void free_extent_buffer(struct extent_buffer *eb);
158int read_extent_buffer_pages(struct extent_io_tree *tree,
159 struct extent_buffer *eb, u64 start, int wait);
160
161static inline void extent_buffer_get(struct extent_buffer *eb)
162{
163 atomic_inc(&eb->refs);
164}
165
166int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
167 unsigned long start,
168 unsigned long len);
169void read_extent_buffer(struct extent_buffer *eb, void *dst,
170 unsigned long start,
171 unsigned long len);
172void write_extent_buffer(struct extent_buffer *eb, const void *src,
173 unsigned long start, unsigned long len);
174void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
175 unsigned long dst_offset, unsigned long src_offset,
176 unsigned long len);
177void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
178 unsigned long src_offset, unsigned long len);
179void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
180 unsigned long src_offset, unsigned long len);
181void memset_extent_buffer(struct extent_buffer *eb, char c,
182 unsigned long start, unsigned long len);
183int wait_on_extent_buffer_writeback(struct extent_io_tree *tree,
184 struct extent_buffer *eb);
185int clear_extent_buffer_dirty(struct extent_io_tree *tree,
186 struct extent_buffer *eb);
187int set_extent_buffer_dirty(struct extent_io_tree *tree,
188 struct extent_buffer *eb);
189int set_extent_buffer_uptodate(struct extent_io_tree *tree,
190 struct extent_buffer *eb);
191int extent_buffer_uptodate(struct extent_io_tree *tree,
192 struct extent_buffer *eb);
193int map_extent_buffer(struct extent_buffer *eb, unsigned long offset,
194 unsigned long min_len, char **token, char **map,
195 unsigned long *map_start,
196 unsigned long *map_len, int km);
197int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset,
198 unsigned long min_len, char **token, char **map,
199 unsigned long *map_start,
200 unsigned long *map_len, int km);
201void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km);
202#endif