blob: 39d78d31b6a224ec5f850e91cbf56815e375051b [file] [log] [blame]
Chris Masona52d9a82007-08-27 16:49:44 -04001#ifndef __EXTENTMAP__
2#define __EXTENTMAP__
3
4#include <linux/rbtree.h>
5
Chris Mason5f39d392007-10-15 16:14:19 -04006#define EXTENT_MAP_HOLE (u64)-3
Chris Masona52d9a82007-08-27 16:49:44 -04007#define EXTENT_MAP_INLINE (u64)-2
8#define EXTENT_MAP_DELALLOC (u64)-1
9
Chris Mason5f39d392007-10-15 16:14:19 -040010/* bits for the extent state */
11#define EXTENT_DIRTY 1
12#define EXTENT_WRITEBACK (1 << 1)
13#define EXTENT_UPTODATE (1 << 2)
14#define EXTENT_LOCKED (1 << 3)
15#define EXTENT_NEW (1 << 4)
16#define EXTENT_DELALLOC (1 << 5)
Chris Mason6b800532007-10-15 16:17:34 -040017#define EXTENT_DEFRAG (1 << 6)
18#define EXTENT_DEFRAG_DONE (1 << 7)
Chris Mason4dc119042007-10-15 16:18:14 -040019#define EXTENT_BUFFER_FILLED (1 << 8)
Chris Mason19c00dd2007-10-15 16:19:22 -040020#define EXTENT_CSUM (1 << 9)
Chris Mason5f39d392007-10-15 16:14:19 -040021#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
22
Chris Mason19c00dd2007-10-15 16:19:22 -040023/*
24 * page->private values. Every page that is controlled by the extent
25 * map has page->private set to one.
26 */
27
28#define EXTENT_PAGE_PRIVATE 1
29#define EXTENT_PAGE_PRIVATE_FIRST_PAGE 3
30
Chris Mason5f39d392007-10-15 16:14:19 -040031
Chris Mason07157aa2007-08-30 08:50:51 -040032struct extent_map_ops {
33 int (*fill_delalloc)(struct inode *inode, u64 start, u64 end);
34 int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
35 int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
36 int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end);
Christoph Hellwig0e2752a2007-09-10 20:02:33 -040037 void (*writepage_end_io_hook)(struct page *page, u64 start, u64 end);
Chris Mason07157aa2007-08-30 08:50:51 -040038};
39
Chris Masona52d9a82007-08-27 16:49:44 -040040struct extent_map_tree {
41 struct rb_root map;
42 struct rb_root state;
43 struct address_space *mapping;
44 rwlock_t lock;
Chris Mason07157aa2007-08-30 08:50:51 -040045 struct extent_map_ops *ops;
Chris Mason4dc119042007-10-15 16:18:14 -040046 spinlock_t lru_lock;
47 struct list_head buffer_lru;
48 int lru_size;
Chris Masona52d9a82007-08-27 16:49:44 -040049};
50
51/* note, this must start with the same fields as fs/extent_map.c:tree_entry */
52struct extent_map {
53 u64 start;
54 u64 end; /* inclusive */
55 int in_tree;
56 struct rb_node rb_node;
57 /* block_start and block_end are in bytes */
58 u64 block_start;
59 u64 block_end; /* inclusive */
60 struct block_device *bdev;
61 atomic_t refs;
62};
63
64/* note, this must start with the same fields as fs/extent_map.c:tree_entry */
65struct extent_state {
66 u64 start;
67 u64 end; /* inclusive */
68 int in_tree;
69 struct rb_node rb_node;
70 wait_queue_head_t wq;
71 atomic_t refs;
72 unsigned long state;
Chris Mason07157aa2007-08-30 08:50:51 -040073
74 /* for use by the FS */
75 u64 private;
76
Chris Masona52d9a82007-08-27 16:49:44 -040077 struct list_head list;
78};
79
80struct extent_buffer {
81 u64 start;
Chris Mason5f39d392007-10-15 16:14:19 -040082 unsigned long len;
Chris Masondb945352007-10-15 16:15:53 -040083 char *map_token;
84 char *kaddr;
85 unsigned long map_start;
86 unsigned long map_len;
Chris Mason810191f2007-10-15 16:18:55 -040087 struct page *first_page;
Chris Mason4dc119042007-10-15 16:18:14 -040088 struct list_head lru;
89 atomic_t refs;
90 int flags;
Chris Masona52d9a82007-08-27 16:49:44 -040091};
92
93typedef struct extent_map *(get_extent_t)(struct inode *inode,
94 struct page *page,
95 size_t page_offset,
96 u64 start, u64 end,
97 int create);
98
99void extent_map_tree_init(struct extent_map_tree *tree,
100 struct address_space *mapping, gfp_t mask);
Chris Mason19c00dd2007-10-15 16:19:22 -0400101void extent_map_tree_empty_lru(struct extent_map_tree *tree);
Chris Masona52d9a82007-08-27 16:49:44 -0400102struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree,
103 u64 start, u64 end);
104int add_extent_mapping(struct extent_map_tree *tree,
105 struct extent_map *em);
106int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em);
107int try_release_extent_mapping(struct extent_map_tree *tree, struct page *page);
108int lock_extent(struct extent_map_tree *tree, u64 start, u64 end, gfp_t mask);
109int unlock_extent(struct extent_map_tree *tree, u64 start, u64 end, gfp_t mask);
110struct extent_map *alloc_extent_map(gfp_t mask);
111void free_extent_map(struct extent_map *em);
112int extent_read_full_page(struct extent_map_tree *tree, struct page *page,
113 get_extent_t *get_extent);
114void __init extent_map_init(void);
115void __exit extent_map_exit(void);
Chris Mason1a5bc162007-10-15 16:15:26 -0400116
117int test_range_bit(struct extent_map_tree *tree, u64 start, u64 end,
118 int bits, int filled);
Chris Mason96b51792007-10-15 16:15:19 -0400119int clear_extent_bits(struct extent_map_tree *tree, u64 start, u64 end,
120 int bits, gfp_t mask);
121int set_extent_bits(struct extent_map_tree *tree, u64 start, u64 end,
122 int bits, gfp_t mask);
Chris Masona52d9a82007-08-27 16:49:44 -0400123int set_extent_uptodate(struct extent_map_tree *tree, u64 start, u64 end,
124 gfp_t mask);
125int set_extent_new(struct extent_map_tree *tree, u64 start, u64 end,
126 gfp_t mask);
127int set_extent_dirty(struct extent_map_tree *tree, u64 start, u64 end,
128 gfp_t mask);
Chris Mason5f39d392007-10-15 16:14:19 -0400129int clear_extent_dirty(struct extent_map_tree *tree, u64 start, u64 end,
130 gfp_t mask);
Chris Masonb888db22007-08-27 16:49:44 -0400131int set_extent_delalloc(struct extent_map_tree *tree, u64 start, u64 end,
132 gfp_t mask);
Chris Mason5f39d392007-10-15 16:14:19 -0400133int find_first_extent_bit(struct extent_map_tree *tree, u64 start,
134 u64 *start_ret, u64 *end_ret, int bits);
Chris Masona52d9a82007-08-27 16:49:44 -0400135int extent_invalidatepage(struct extent_map_tree *tree,
136 struct page *page, unsigned long offset);
137int extent_write_full_page(struct extent_map_tree *tree, struct page *page,
138 get_extent_t *get_extent,
139 struct writeback_control *wbc);
140int extent_prepare_write(struct extent_map_tree *tree,
141 struct inode *inode, struct page *page,
142 unsigned from, unsigned to, get_extent_t *get_extent);
143int extent_commit_write(struct extent_map_tree *tree,
144 struct inode *inode, struct page *page,
145 unsigned from, unsigned to);
Christoph Hellwigd396c6f2007-09-10 20:02:30 -0400146sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
147 get_extent_t *get_extent);
Chris Masona52d9a82007-08-27 16:49:44 -0400148int set_range_dirty(struct extent_map_tree *tree, u64 start, u64 end);
Chris Mason07157aa2007-08-30 08:50:51 -0400149int set_state_private(struct extent_map_tree *tree, u64 start, u64 private);
150int get_state_private(struct extent_map_tree *tree, u64 start, u64 *private);
Christoph Hellwigb3cfa352007-09-17 11:25:58 -0400151void set_page_extent_mapped(struct page *page);
Chris Mason5f39d392007-10-15 16:14:19 -0400152
153struct extent_buffer *alloc_extent_buffer(struct extent_map_tree *tree,
154 u64 start, unsigned long len,
Chris Mason19c00dd2007-10-15 16:19:22 -0400155 struct page *page0,
Chris Mason5f39d392007-10-15 16:14:19 -0400156 gfp_t mask);
157struct extent_buffer *find_extent_buffer(struct extent_map_tree *tree,
158 u64 start, unsigned long len,
159 gfp_t mask);
160void free_extent_buffer(struct extent_buffer *eb);
161int read_extent_buffer_pages(struct extent_map_tree *tree,
Chris Mason19c00dd2007-10-15 16:19:22 -0400162 struct extent_buffer *eb, u64 start, int wait);
Chris Mason5f39d392007-10-15 16:14:19 -0400163
164static inline void extent_buffer_get(struct extent_buffer *eb)
165{
166 atomic_inc(&eb->refs);
167}
168
Chris Mason5f39d392007-10-15 16:14:19 -0400169int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
170 unsigned long start,
171 unsigned long len);
172void read_extent_buffer(struct extent_buffer *eb, void *dst,
173 unsigned long start,
174 unsigned long len);
175void write_extent_buffer(struct extent_buffer *eb, const void *src,
176 unsigned long start, unsigned long len);
177void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
178 unsigned long dst_offset, unsigned long src_offset,
179 unsigned long len);
180void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
181 unsigned long src_offset, unsigned long len);
182void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
183 unsigned long src_offset, unsigned long len);
184void memset_extent_buffer(struct extent_buffer *eb, char c,
185 unsigned long start, unsigned long len);
186int wait_on_extent_buffer_writeback(struct extent_map_tree *tree,
187 struct extent_buffer *eb);
188int clear_extent_buffer_dirty(struct extent_map_tree *tree,
189 struct extent_buffer *eb);
190int set_extent_buffer_dirty(struct extent_map_tree *tree,
191 struct extent_buffer *eb);
192int set_extent_buffer_uptodate(struct extent_map_tree *tree,
193 struct extent_buffer *eb);
194int extent_buffer_uptodate(struct extent_map_tree *tree,
195 struct extent_buffer *eb);
196int map_extent_buffer(struct extent_buffer *eb, unsigned long offset,
Chris Mason479965d2007-10-15 16:14:27 -0400197 unsigned long min_len, char **token, char **map,
Chris Mason5f39d392007-10-15 16:14:19 -0400198 unsigned long *map_start,
199 unsigned long *map_len, int km);
Chris Mason19c00dd2007-10-15 16:19:22 -0400200int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset,
201 unsigned long min_len, char **token, char **map,
202 unsigned long *map_start,
203 unsigned long *map_len, int km);
Chris Mason5f39d392007-10-15 16:14:19 -0400204void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km);
Chris Masona52d9a82007-08-27 16:49:44 -0400205#endif