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