blob: 52a8b9394fc6e6f458a3483cc36eca385fcc1c7a [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 Mason5f39d392007-10-15 16:14:19 -040020#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
21
22
Chris Mason07157aa2007-08-30 08:50:51 -040023struct extent_map_ops {
24 int (*fill_delalloc)(struct inode *inode, u64 start, u64 end);
25 int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
26 int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
27 int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end);
Christoph Hellwig0e2752a2007-09-10 20:02:33 -040028 void (*writepage_end_io_hook)(struct page *page, u64 start, u64 end);
Chris Mason07157aa2007-08-30 08:50:51 -040029};
30
Chris Masona52d9a82007-08-27 16:49:44 -040031struct extent_map_tree {
32 struct rb_root map;
33 struct rb_root state;
34 struct address_space *mapping;
35 rwlock_t lock;
Chris Mason07157aa2007-08-30 08:50:51 -040036 struct extent_map_ops *ops;
Chris Mason4dc119042007-10-15 16:18:14 -040037 spinlock_t lru_lock;
38 struct list_head buffer_lru;
39 int lru_size;
Chris Masona52d9a82007-08-27 16:49:44 -040040};
41
42/* note, this must start with the same fields as fs/extent_map.c:tree_entry */
43struct extent_map {
44 u64 start;
45 u64 end; /* inclusive */
46 int in_tree;
47 struct rb_node rb_node;
48 /* block_start and block_end are in bytes */
49 u64 block_start;
50 u64 block_end; /* inclusive */
51 struct block_device *bdev;
52 atomic_t refs;
53};
54
55/* note, this must start with the same fields as fs/extent_map.c:tree_entry */
56struct extent_state {
57 u64 start;
58 u64 end; /* inclusive */
59 int in_tree;
60 struct rb_node rb_node;
61 wait_queue_head_t wq;
62 atomic_t refs;
63 unsigned long state;
Chris Mason07157aa2007-08-30 08:50:51 -040064
65 /* for use by the FS */
66 u64 private;
67
Chris Masona52d9a82007-08-27 16:49:44 -040068 struct list_head list;
69};
70
71struct extent_buffer {
72 u64 start;
Chris Mason5f39d392007-10-15 16:14:19 -040073 unsigned long len;
Chris Masondb945352007-10-15 16:15:53 -040074 char *map_token;
75 char *kaddr;
76 unsigned long map_start;
77 unsigned long map_len;
Chris Mason4dc119042007-10-15 16:18:14 -040078 struct page *last_page;
79 struct list_head lru;
80 atomic_t refs;
81 int flags;
Chris Masona52d9a82007-08-27 16:49:44 -040082};
83
84typedef struct extent_map *(get_extent_t)(struct inode *inode,
85 struct page *page,
86 size_t page_offset,
87 u64 start, u64 end,
88 int create);
89
90void extent_map_tree_init(struct extent_map_tree *tree,
91 struct address_space *mapping, gfp_t mask);
Chris Mason4dc119042007-10-15 16:18:14 -040092void extent_map_tree_cleanup(struct extent_map_tree *tree);
Chris Masona52d9a82007-08-27 16:49:44 -040093struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree,
94 u64 start, u64 end);
95int add_extent_mapping(struct extent_map_tree *tree,
96 struct extent_map *em);
97int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em);
98int try_release_extent_mapping(struct extent_map_tree *tree, struct page *page);
99int lock_extent(struct extent_map_tree *tree, u64 start, u64 end, gfp_t mask);
100int unlock_extent(struct extent_map_tree *tree, u64 start, u64 end, gfp_t mask);
101struct extent_map *alloc_extent_map(gfp_t mask);
102void free_extent_map(struct extent_map *em);
103int extent_read_full_page(struct extent_map_tree *tree, struct page *page,
104 get_extent_t *get_extent);
105void __init extent_map_init(void);
106void __exit extent_map_exit(void);
Chris Mason1a5bc162007-10-15 16:15:26 -0400107
108int test_range_bit(struct extent_map_tree *tree, u64 start, u64 end,
109 int bits, int filled);
Chris Mason96b51792007-10-15 16:15:19 -0400110int clear_extent_bits(struct extent_map_tree *tree, u64 start, u64 end,
111 int bits, gfp_t mask);
112int set_extent_bits(struct extent_map_tree *tree, u64 start, u64 end,
113 int bits, gfp_t mask);
Chris Masona52d9a82007-08-27 16:49:44 -0400114int set_extent_uptodate(struct extent_map_tree *tree, u64 start, u64 end,
115 gfp_t mask);
116int set_extent_new(struct extent_map_tree *tree, u64 start, u64 end,
117 gfp_t mask);
118int set_extent_dirty(struct extent_map_tree *tree, u64 start, u64 end,
119 gfp_t mask);
Chris Mason5f39d392007-10-15 16:14:19 -0400120int clear_extent_dirty(struct extent_map_tree *tree, u64 start, u64 end,
121 gfp_t mask);
Chris Masonb888db22007-08-27 16:49:44 -0400122int set_extent_delalloc(struct extent_map_tree *tree, u64 start, u64 end,
123 gfp_t mask);
Chris Mason5f39d392007-10-15 16:14:19 -0400124int find_first_extent_bit(struct extent_map_tree *tree, u64 start,
125 u64 *start_ret, u64 *end_ret, int bits);
Chris Masona52d9a82007-08-27 16:49:44 -0400126int extent_invalidatepage(struct extent_map_tree *tree,
127 struct page *page, unsigned long offset);
128int extent_write_full_page(struct extent_map_tree *tree, struct page *page,
129 get_extent_t *get_extent,
130 struct writeback_control *wbc);
131int extent_prepare_write(struct extent_map_tree *tree,
132 struct inode *inode, struct page *page,
133 unsigned from, unsigned to, get_extent_t *get_extent);
134int extent_commit_write(struct extent_map_tree *tree,
135 struct inode *inode, struct page *page,
136 unsigned from, unsigned to);
Christoph Hellwigd396c6f2007-09-10 20:02:30 -0400137sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
138 get_extent_t *get_extent);
Chris Masona52d9a82007-08-27 16:49:44 -0400139int set_range_dirty(struct extent_map_tree *tree, u64 start, u64 end);
Chris Mason07157aa2007-08-30 08:50:51 -0400140int set_state_private(struct extent_map_tree *tree, u64 start, u64 private);
141int get_state_private(struct extent_map_tree *tree, u64 start, u64 *private);
Christoph Hellwigb3cfa352007-09-17 11:25:58 -0400142void set_page_extent_mapped(struct page *page);
Chris Mason5f39d392007-10-15 16:14:19 -0400143
144struct extent_buffer *alloc_extent_buffer(struct extent_map_tree *tree,
145 u64 start, unsigned long len,
146 gfp_t mask);
147struct extent_buffer *find_extent_buffer(struct extent_map_tree *tree,
148 u64 start, unsigned long len,
149 gfp_t mask);
150void free_extent_buffer(struct extent_buffer *eb);
151int read_extent_buffer_pages(struct extent_map_tree *tree,
152 struct extent_buffer *eb, int wait);
153
154static inline void extent_buffer_get(struct extent_buffer *eb)
155{
156 atomic_inc(&eb->refs);
157}
158
Chris Mason5f39d392007-10-15 16:14:19 -0400159int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
160 unsigned long start,
161 unsigned long len);
162void read_extent_buffer(struct extent_buffer *eb, void *dst,
163 unsigned long start,
164 unsigned long len);
165void write_extent_buffer(struct extent_buffer *eb, const void *src,
166 unsigned long start, unsigned long len);
167void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
168 unsigned long dst_offset, unsigned long src_offset,
169 unsigned long len);
170void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
171 unsigned long src_offset, unsigned long len);
172void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
173 unsigned long src_offset, unsigned long len);
174void memset_extent_buffer(struct extent_buffer *eb, char c,
175 unsigned long start, unsigned long len);
176int wait_on_extent_buffer_writeback(struct extent_map_tree *tree,
177 struct extent_buffer *eb);
178int clear_extent_buffer_dirty(struct extent_map_tree *tree,
179 struct extent_buffer *eb);
180int set_extent_buffer_dirty(struct extent_map_tree *tree,
181 struct extent_buffer *eb);
182int set_extent_buffer_uptodate(struct extent_map_tree *tree,
183 struct extent_buffer *eb);
184int extent_buffer_uptodate(struct extent_map_tree *tree,
185 struct extent_buffer *eb);
186int map_extent_buffer(struct extent_buffer *eb, unsigned long offset,
Chris Mason479965d2007-10-15 16:14:27 -0400187 unsigned long min_len, char **token, char **map,
Chris Mason5f39d392007-10-15 16:14:19 -0400188 unsigned long *map_start,
189 unsigned long *map_len, int km);
190void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km);
Chris Masona52d9a82007-08-27 16:49:44 -0400191#endif