blob: 0eae6c420acbaa6fbcb982a2b718b5bd1d4f047b [file] [log] [blame]
Chris Masona52d9a82007-08-27 16:49:44 -04001#ifndef __EXTENTMAP__
2#define __EXTENTMAP__
3
4#include <linux/rbtree.h>
5
6#define EXTENT_MAP_INLINE (u64)-2
7#define EXTENT_MAP_DELALLOC (u64)-1
8
Chris Mason07157aa2007-08-30 08:50:51 -04009struct extent_map_ops {
10 int (*fill_delalloc)(struct inode *inode, u64 start, u64 end);
11 int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
12 int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
13 int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end);
14};
15
Chris Masona52d9a82007-08-27 16:49:44 -040016struct extent_map_tree {
17 struct rb_root map;
18 struct rb_root state;
19 struct address_space *mapping;
20 rwlock_t lock;
Chris Mason07157aa2007-08-30 08:50:51 -040021 struct extent_map_ops *ops;
Chris Masona52d9a82007-08-27 16:49:44 -040022};
23
24/* note, this must start with the same fields as fs/extent_map.c:tree_entry */
25struct extent_map {
26 u64 start;
27 u64 end; /* inclusive */
28 int in_tree;
29 struct rb_node rb_node;
30 /* block_start and block_end are in bytes */
31 u64 block_start;
32 u64 block_end; /* inclusive */
33 struct block_device *bdev;
34 atomic_t refs;
35};
36
37/* note, this must start with the same fields as fs/extent_map.c:tree_entry */
38struct extent_state {
39 u64 start;
40 u64 end; /* inclusive */
41 int in_tree;
42 struct rb_node rb_node;
43 wait_queue_head_t wq;
44 atomic_t refs;
45 unsigned long state;
Chris Mason07157aa2007-08-30 08:50:51 -040046
47 /* for use by the FS */
48 u64 private;
49
Chris Masona52d9a82007-08-27 16:49:44 -040050 struct list_head list;
51};
52
53struct extent_buffer {
54 u64 start;
55 u64 end; /* inclusive */
56 char *addr;
57 struct page *pages[];
58};
59
60typedef struct extent_map *(get_extent_t)(struct inode *inode,
61 struct page *page,
62 size_t page_offset,
63 u64 start, u64 end,
64 int create);
65
66void extent_map_tree_init(struct extent_map_tree *tree,
67 struct address_space *mapping, gfp_t mask);
68struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree,
69 u64 start, u64 end);
70int add_extent_mapping(struct extent_map_tree *tree,
71 struct extent_map *em);
72int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em);
73int try_release_extent_mapping(struct extent_map_tree *tree, struct page *page);
74int lock_extent(struct extent_map_tree *tree, u64 start, u64 end, gfp_t mask);
75int unlock_extent(struct extent_map_tree *tree, u64 start, u64 end, gfp_t mask);
76struct extent_map *alloc_extent_map(gfp_t mask);
77void free_extent_map(struct extent_map *em);
78int extent_read_full_page(struct extent_map_tree *tree, struct page *page,
79 get_extent_t *get_extent);
80void __init extent_map_init(void);
81void __exit extent_map_exit(void);
82int extent_clean_all_trees(struct extent_map_tree *tree);
83int set_extent_uptodate(struct extent_map_tree *tree, u64 start, u64 end,
84 gfp_t mask);
85int set_extent_new(struct extent_map_tree *tree, u64 start, u64 end,
86 gfp_t mask);
87int set_extent_dirty(struct extent_map_tree *tree, u64 start, u64 end,
88 gfp_t mask);
Chris Masonb888db22007-08-27 16:49:44 -040089int set_extent_delalloc(struct extent_map_tree *tree, u64 start, u64 end,
90 gfp_t mask);
Chris Masona52d9a82007-08-27 16:49:44 -040091int extent_invalidatepage(struct extent_map_tree *tree,
92 struct page *page, unsigned long offset);
93int extent_write_full_page(struct extent_map_tree *tree, struct page *page,
94 get_extent_t *get_extent,
95 struct writeback_control *wbc);
96int extent_prepare_write(struct extent_map_tree *tree,
97 struct inode *inode, struct page *page,
98 unsigned from, unsigned to, get_extent_t *get_extent);
99int extent_commit_write(struct extent_map_tree *tree,
100 struct inode *inode, struct page *page,
101 unsigned from, unsigned to);
102int set_range_dirty(struct extent_map_tree *tree, u64 start, u64 end);
Chris Mason07157aa2007-08-30 08:50:51 -0400103int set_state_private(struct extent_map_tree *tree, u64 start, u64 private);
104int get_state_private(struct extent_map_tree *tree, u64 start, u64 *private);
Chris Masona52d9a82007-08-27 16:49:44 -0400105#endif