blob: 75dc600dc0f9e33ace0ea160f57bbcb97baf8225 [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)
17#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
18
19
Chris Mason07157aa2007-08-30 08:50:51 -040020struct extent_map_ops {
21 int (*fill_delalloc)(struct inode *inode, u64 start, u64 end);
22 int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
23 int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
24 int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end);
Christoph Hellwig0e2752a2007-09-10 20:02:33 -040025 void (*writepage_end_io_hook)(struct page *page, u64 start, u64 end);
Chris Mason07157aa2007-08-30 08:50:51 -040026};
27
Chris Masona52d9a82007-08-27 16:49:44 -040028struct extent_map_tree {
29 struct rb_root map;
30 struct rb_root state;
31 struct address_space *mapping;
32 rwlock_t lock;
Chris Mason07157aa2007-08-30 08:50:51 -040033 struct extent_map_ops *ops;
Chris Masona52d9a82007-08-27 16:49:44 -040034};
35
36/* note, this must start with the same fields as fs/extent_map.c:tree_entry */
37struct extent_map {
38 u64 start;
39 u64 end; /* inclusive */
40 int in_tree;
41 struct rb_node rb_node;
42 /* block_start and block_end are in bytes */
43 u64 block_start;
44 u64 block_end; /* inclusive */
45 struct block_device *bdev;
46 atomic_t refs;
47};
48
49/* note, this must start with the same fields as fs/extent_map.c:tree_entry */
50struct extent_state {
51 u64 start;
52 u64 end; /* inclusive */
53 int in_tree;
54 struct rb_node rb_node;
55 wait_queue_head_t wq;
56 atomic_t refs;
57 unsigned long state;
Chris Mason07157aa2007-08-30 08:50:51 -040058
59 /* for use by the FS */
60 u64 private;
61
Chris Masona52d9a82007-08-27 16:49:44 -040062 struct list_head list;
63};
64
65struct extent_buffer {
66 u64 start;
Chris Mason5f39d392007-10-15 16:14:19 -040067 unsigned long len;
68 atomic_t refs;
69 int flags;
Chris Mason6d36dcd2007-10-15 16:14:37 -040070 struct list_head list;
Chris Masonf510cfe2007-10-15 16:14:48 -040071 struct list_head leak_list;
Chris Mason6d36dcd2007-10-15 16:14:37 -040072 struct page *first_page;
Chris Masonf510cfe2007-10-15 16:14:48 -040073 unsigned long alloc_addr;
Chris Masona52d9a82007-08-27 16:49:44 -040074};
75
76typedef struct extent_map *(get_extent_t)(struct inode *inode,
77 struct page *page,
78 size_t page_offset,
79 u64 start, u64 end,
80 int create);
81
82void extent_map_tree_init(struct extent_map_tree *tree,
83 struct address_space *mapping, gfp_t mask);
84struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree,
85 u64 start, u64 end);
86int add_extent_mapping(struct extent_map_tree *tree,
87 struct extent_map *em);
88int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em);
89int try_release_extent_mapping(struct extent_map_tree *tree, struct page *page);
90int lock_extent(struct extent_map_tree *tree, u64 start, u64 end, gfp_t mask);
91int unlock_extent(struct extent_map_tree *tree, u64 start, u64 end, gfp_t mask);
92struct extent_map *alloc_extent_map(gfp_t mask);
93void free_extent_map(struct extent_map *em);
94int extent_read_full_page(struct extent_map_tree *tree, struct page *page,
95 get_extent_t *get_extent);
96void __init extent_map_init(void);
97void __exit extent_map_exit(void);
Chris Mason1a5bc162007-10-15 16:15:26 -040098
99int test_range_bit(struct extent_map_tree *tree, u64 start, u64 end,
100 int bits, int filled);
Chris Mason96b51792007-10-15 16:15:19 -0400101int clear_extent_bits(struct extent_map_tree *tree, u64 start, u64 end,
102 int bits, gfp_t mask);
103int set_extent_bits(struct extent_map_tree *tree, u64 start, u64 end,
104 int bits, gfp_t mask);
Chris Masona52d9a82007-08-27 16:49:44 -0400105int set_extent_uptodate(struct extent_map_tree *tree, u64 start, u64 end,
106 gfp_t mask);
107int set_extent_new(struct extent_map_tree *tree, u64 start, u64 end,
108 gfp_t mask);
109int set_extent_dirty(struct extent_map_tree *tree, u64 start, u64 end,
110 gfp_t mask);
Chris Mason5f39d392007-10-15 16:14:19 -0400111int clear_extent_dirty(struct extent_map_tree *tree, u64 start, u64 end,
112 gfp_t mask);
Chris Masonb888db22007-08-27 16:49:44 -0400113int set_extent_delalloc(struct extent_map_tree *tree, u64 start, u64 end,
114 gfp_t mask);
Chris Mason5f39d392007-10-15 16:14:19 -0400115int find_first_extent_bit(struct extent_map_tree *tree, u64 start,
116 u64 *start_ret, u64 *end_ret, int bits);
Chris Masona52d9a82007-08-27 16:49:44 -0400117int extent_invalidatepage(struct extent_map_tree *tree,
118 struct page *page, unsigned long offset);
119int extent_write_full_page(struct extent_map_tree *tree, struct page *page,
120 get_extent_t *get_extent,
121 struct writeback_control *wbc);
122int extent_prepare_write(struct extent_map_tree *tree,
123 struct inode *inode, struct page *page,
124 unsigned from, unsigned to, get_extent_t *get_extent);
125int extent_commit_write(struct extent_map_tree *tree,
126 struct inode *inode, struct page *page,
127 unsigned from, unsigned to);
Christoph Hellwigd396c6f2007-09-10 20:02:30 -0400128sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
129 get_extent_t *get_extent);
Chris Masona52d9a82007-08-27 16:49:44 -0400130int set_range_dirty(struct extent_map_tree *tree, u64 start, u64 end);
Chris Mason07157aa2007-08-30 08:50:51 -0400131int set_state_private(struct extent_map_tree *tree, u64 start, u64 private);
132int get_state_private(struct extent_map_tree *tree, u64 start, u64 *private);
Christoph Hellwigb3cfa352007-09-17 11:25:58 -0400133void set_page_extent_mapped(struct page *page);
Chris Mason5f39d392007-10-15 16:14:19 -0400134
135struct extent_buffer *alloc_extent_buffer(struct extent_map_tree *tree,
136 u64 start, unsigned long len,
137 gfp_t mask);
138struct extent_buffer *find_extent_buffer(struct extent_map_tree *tree,
139 u64 start, unsigned long len,
140 gfp_t mask);
141void free_extent_buffer(struct extent_buffer *eb);
142int read_extent_buffer_pages(struct extent_map_tree *tree,
143 struct extent_buffer *eb, int wait);
144
145static inline void extent_buffer_get(struct extent_buffer *eb)
146{
147 atomic_inc(&eb->refs);
148}
149
150static inline u64 extent_buffer_blocknr(struct extent_buffer *eb)
151{
152 return eb->start / 4096;
153}
154
155int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
156 unsigned long start,
157 unsigned long len);
158void read_extent_buffer(struct extent_buffer *eb, void *dst,
159 unsigned long start,
160 unsigned long len);
161void write_extent_buffer(struct extent_buffer *eb, const void *src,
162 unsigned long start, unsigned long len);
163void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
164 unsigned long dst_offset, unsigned long src_offset,
165 unsigned long len);
166void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
167 unsigned long src_offset, unsigned long len);
168void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
169 unsigned long src_offset, unsigned long len);
170void memset_extent_buffer(struct extent_buffer *eb, char c,
171 unsigned long start, unsigned long len);
172int wait_on_extent_buffer_writeback(struct extent_map_tree *tree,
173 struct extent_buffer *eb);
174int clear_extent_buffer_dirty(struct extent_map_tree *tree,
175 struct extent_buffer *eb);
176int set_extent_buffer_dirty(struct extent_map_tree *tree,
177 struct extent_buffer *eb);
178int set_extent_buffer_uptodate(struct extent_map_tree *tree,
179 struct extent_buffer *eb);
180int extent_buffer_uptodate(struct extent_map_tree *tree,
181 struct extent_buffer *eb);
182int map_extent_buffer(struct extent_buffer *eb, unsigned long offset,
Chris Mason479965d2007-10-15 16:14:27 -0400183 unsigned long min_len, char **token, char **map,
Chris Mason5f39d392007-10-15 16:14:19 -0400184 unsigned long *map_start,
185 unsigned long *map_len, int km);
186void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km);
Chris Masona52d9a82007-08-27 16:49:44 -0400187#endif