Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 1 | #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 Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 9 | struct 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 Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 16 | struct extent_map_tree { |
| 17 | struct rb_root map; |
| 18 | struct rb_root state; |
| 19 | struct address_space *mapping; |
| 20 | rwlock_t lock; |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 21 | struct extent_map_ops *ops; |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | /* note, this must start with the same fields as fs/extent_map.c:tree_entry */ |
| 25 | struct 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 */ |
| 38 | struct 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 Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 46 | |
| 47 | /* for use by the FS */ |
| 48 | u64 private; |
| 49 | |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 50 | struct list_head list; |
| 51 | }; |
| 52 | |
| 53 | struct extent_buffer { |
| 54 | u64 start; |
| 55 | u64 end; /* inclusive */ |
| 56 | char *addr; |
| 57 | struct page *pages[]; |
| 58 | }; |
| 59 | |
| 60 | typedef 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 | |
| 66 | void extent_map_tree_init(struct extent_map_tree *tree, |
| 67 | struct address_space *mapping, gfp_t mask); |
| 68 | struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree, |
| 69 | u64 start, u64 end); |
| 70 | int add_extent_mapping(struct extent_map_tree *tree, |
| 71 | struct extent_map *em); |
| 72 | int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em); |
| 73 | int try_release_extent_mapping(struct extent_map_tree *tree, struct page *page); |
| 74 | int lock_extent(struct extent_map_tree *tree, u64 start, u64 end, gfp_t mask); |
| 75 | int unlock_extent(struct extent_map_tree *tree, u64 start, u64 end, gfp_t mask); |
| 76 | struct extent_map *alloc_extent_map(gfp_t mask); |
| 77 | void free_extent_map(struct extent_map *em); |
| 78 | int extent_read_full_page(struct extent_map_tree *tree, struct page *page, |
| 79 | get_extent_t *get_extent); |
| 80 | void __init extent_map_init(void); |
| 81 | void __exit extent_map_exit(void); |
| 82 | int extent_clean_all_trees(struct extent_map_tree *tree); |
| 83 | int set_extent_uptodate(struct extent_map_tree *tree, u64 start, u64 end, |
| 84 | gfp_t mask); |
| 85 | int set_extent_new(struct extent_map_tree *tree, u64 start, u64 end, |
| 86 | gfp_t mask); |
| 87 | int set_extent_dirty(struct extent_map_tree *tree, u64 start, u64 end, |
| 88 | gfp_t mask); |
Chris Mason | b888db2 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 89 | int set_extent_delalloc(struct extent_map_tree *tree, u64 start, u64 end, |
| 90 | gfp_t mask); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 91 | int extent_invalidatepage(struct extent_map_tree *tree, |
| 92 | struct page *page, unsigned long offset); |
| 93 | int extent_write_full_page(struct extent_map_tree *tree, struct page *page, |
| 94 | get_extent_t *get_extent, |
| 95 | struct writeback_control *wbc); |
| 96 | int 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); |
| 99 | int extent_commit_write(struct extent_map_tree *tree, |
| 100 | struct inode *inode, struct page *page, |
| 101 | unsigned from, unsigned to); |
| 102 | int set_range_dirty(struct extent_map_tree *tree, u64 start, u64 end); |
Chris Mason | 07157aa | 2007-08-30 08:50:51 -0400 | [diff] [blame] | 103 | int set_state_private(struct extent_map_tree *tree, u64 start, u64 private); |
| 104 | int get_state_private(struct extent_map_tree *tree, u64 start, u64 *private); |
Chris Mason | a52d9a8 | 2007-08-27 16:49:44 -0400 | [diff] [blame] | 105 | #endif |