diff options
author | Chris Mason <chris.mason@oracle.com> | 2008-01-24 16:13:08 -0500 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-09-25 11:03:59 -0400 |
commit | d1310b2e0cd98eb1348553e69b73827b436dca7b (patch) | |
tree | f55e9c380df0f3a7e9fb792b2308b52b632b90aa /fs/btrfs/extent_io.h | |
parent | 5f56406aabdf5444d040c5955effc665b1d0dbaf (diff) |
Btrfs: Split the extent_map code into two parts
There is now extent_map for mapping offsets in the file to disk and
extent_io for state tracking, IO submission and extent_bufers.
The new extent_map code shifts from [start,end] pairs to [start,len], and
pushes the locking out into the caller. This allows a few performance
optimizations and is easier to use.
A number of extent_map usage bugs were fixed, mostly with failing
to remove extent_map entries when changing the file.
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/extent_io.h')
-rw-r--r-- | fs/btrfs/extent_io.h | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h new file mode 100644 index 000000000000..06be1fe84b29 --- /dev/null +++ b/fs/btrfs/extent_io.h | |||
@@ -0,0 +1,193 @@ | |||
1 | #ifndef __EXTENTIO__ | ||
2 | #define __EXTENTIO__ | ||
3 | |||
4 | #include <linux/rbtree.h> | ||
5 | |||
6 | /* bits for the extent state */ | ||
7 | #define EXTENT_DIRTY 1 | ||
8 | #define EXTENT_WRITEBACK (1 << 1) | ||
9 | #define EXTENT_UPTODATE (1 << 2) | ||
10 | #define EXTENT_LOCKED (1 << 3) | ||
11 | #define EXTENT_NEW (1 << 4) | ||
12 | #define EXTENT_DELALLOC (1 << 5) | ||
13 | #define EXTENT_DEFRAG (1 << 6) | ||
14 | #define EXTENT_DEFRAG_DONE (1 << 7) | ||
15 | #define EXTENT_BUFFER_FILLED (1 << 8) | ||
16 | #define EXTENT_CSUM (1 << 9) | ||
17 | #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK) | ||
18 | |||
19 | /* | ||
20 | * page->private values. Every page that is controlled by the extent | ||
21 | * map has page->private set to one. | ||
22 | */ | ||
23 | #define EXTENT_PAGE_PRIVATE 1 | ||
24 | #define EXTENT_PAGE_PRIVATE_FIRST_PAGE 3 | ||
25 | |||
26 | struct extent_io_ops { | ||
27 | int (*fill_delalloc)(struct inode *inode, u64 start, u64 end); | ||
28 | int (*writepage_io_hook)(struct page *page, u64 start, u64 end); | ||
29 | int (*readpage_io_hook)(struct page *page, u64 start, u64 end); | ||
30 | int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end); | ||
31 | void (*writepage_end_io_hook)(struct page *page, u64 start, u64 end); | ||
32 | }; | ||
33 | |||
34 | struct extent_io_tree { | ||
35 | struct rb_root state; | ||
36 | struct address_space *mapping; | ||
37 | u64 dirty_bytes; | ||
38 | rwlock_t lock; | ||
39 | struct extent_io_ops *ops; | ||
40 | spinlock_t lru_lock; | ||
41 | struct list_head buffer_lru; | ||
42 | int lru_size; | ||
43 | }; | ||
44 | |||
45 | struct extent_state { | ||
46 | u64 start; | ||
47 | u64 end; /* inclusive */ | ||
48 | int in_tree; | ||
49 | struct rb_node rb_node; | ||
50 | wait_queue_head_t wq; | ||
51 | atomic_t refs; | ||
52 | unsigned long state; | ||
53 | |||
54 | /* for use by the FS */ | ||
55 | u64 private; | ||
56 | |||
57 | struct list_head list; | ||
58 | }; | ||
59 | |||
60 | struct extent_buffer { | ||
61 | u64 start; | ||
62 | unsigned long len; | ||
63 | char *map_token; | ||
64 | char *kaddr; | ||
65 | unsigned long map_start; | ||
66 | unsigned long map_len; | ||
67 | struct page *first_page; | ||
68 | struct list_head lru; | ||
69 | atomic_t refs; | ||
70 | int flags; | ||
71 | }; | ||
72 | |||
73 | struct extent_map_tree; | ||
74 | |||
75 | typedef struct extent_map *(get_extent_t)(struct inode *inode, | ||
76 | struct page *page, | ||
77 | size_t page_offset, | ||
78 | u64 start, u64 len, | ||
79 | int create); | ||
80 | |||
81 | void extent_io_tree_init(struct extent_io_tree *tree, | ||
82 | struct address_space *mapping, gfp_t mask); | ||
83 | void extent_io_tree_empty_lru(struct extent_io_tree *tree); | ||
84 | int try_release_extent_mapping(struct extent_map_tree *map, | ||
85 | struct extent_io_tree *tree, struct page *page); | ||
86 | int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask); | ||
87 | int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask); | ||
88 | int extent_read_full_page(struct extent_io_tree *tree, struct page *page, | ||
89 | get_extent_t *get_extent); | ||
90 | int __init extent_io_init(void); | ||
91 | void extent_io_exit(void); | ||
92 | |||
93 | u64 count_range_bits(struct extent_io_tree *tree, | ||
94 | u64 *start, u64 search_end, | ||
95 | u64 max_bytes, unsigned long bits); | ||
96 | |||
97 | int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end, | ||
98 | int bits, int filled); | ||
99 | int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, | ||
100 | int bits, gfp_t mask); | ||
101 | int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, | ||
102 | int bits, gfp_t mask); | ||
103 | int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, | ||
104 | gfp_t mask); | ||
105 | int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end, | ||
106 | gfp_t mask); | ||
107 | int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, | ||
108 | gfp_t mask); | ||
109 | int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, | ||
110 | gfp_t mask); | ||
111 | int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end, | ||
112 | gfp_t mask); | ||
113 | int find_first_extent_bit(struct extent_io_tree *tree, u64 start, | ||
114 | u64 *start_ret, u64 *end_ret, int bits); | ||
115 | int extent_invalidatepage(struct extent_io_tree *tree, | ||
116 | struct page *page, unsigned long offset); | ||
117 | int extent_write_full_page(struct extent_io_tree *tree, struct page *page, | ||
118 | get_extent_t *get_extent, | ||
119 | struct writeback_control *wbc); | ||
120 | int extent_writepages(struct extent_io_tree *tree, | ||
121 | struct address_space *mapping, | ||
122 | get_extent_t *get_extent, | ||
123 | struct writeback_control *wbc); | ||
124 | int extent_readpages(struct extent_io_tree *tree, | ||
125 | struct address_space *mapping, | ||
126 | struct list_head *pages, unsigned nr_pages, | ||
127 | get_extent_t get_extent); | ||
128 | int extent_prepare_write(struct extent_io_tree *tree, | ||
129 | struct inode *inode, struct page *page, | ||
130 | unsigned from, unsigned to, get_extent_t *get_extent); | ||
131 | int extent_commit_write(struct extent_io_tree *tree, | ||
132 | struct inode *inode, struct page *page, | ||
133 | unsigned from, unsigned to); | ||
134 | sector_t extent_bmap(struct address_space *mapping, sector_t iblock, | ||
135 | get_extent_t *get_extent); | ||
136 | int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end); | ||
137 | int set_state_private(struct extent_io_tree *tree, u64 start, u64 private); | ||
138 | int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private); | ||
139 | void set_page_extent_mapped(struct page *page); | ||
140 | |||
141 | struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree, | ||
142 | u64 start, unsigned long len, | ||
143 | struct page *page0, | ||
144 | gfp_t mask); | ||
145 | struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree, | ||
146 | u64 start, unsigned long len, | ||
147 | gfp_t mask); | ||
148 | void free_extent_buffer(struct extent_buffer *eb); | ||
149 | int read_extent_buffer_pages(struct extent_io_tree *tree, | ||
150 | struct extent_buffer *eb, u64 start, int wait); | ||
151 | |||
152 | static inline void extent_buffer_get(struct extent_buffer *eb) | ||
153 | { | ||
154 | atomic_inc(&eb->refs); | ||
155 | } | ||
156 | |||
157 | int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv, | ||
158 | unsigned long start, | ||
159 | unsigned long len); | ||
160 | void read_extent_buffer(struct extent_buffer *eb, void *dst, | ||
161 | unsigned long start, | ||
162 | unsigned long len); | ||
163 | void write_extent_buffer(struct extent_buffer *eb, const void *src, | ||
164 | unsigned long start, unsigned long len); | ||
165 | void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src, | ||
166 | unsigned long dst_offset, unsigned long src_offset, | ||
167 | unsigned long len); | ||
168 | void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, | ||
169 | unsigned long src_offset, unsigned long len); | ||
170 | void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, | ||
171 | unsigned long src_offset, unsigned long len); | ||
172 | void memset_extent_buffer(struct extent_buffer *eb, char c, | ||
173 | unsigned long start, unsigned long len); | ||
174 | int wait_on_extent_buffer_writeback(struct extent_io_tree *tree, | ||
175 | struct extent_buffer *eb); | ||
176 | int clear_extent_buffer_dirty(struct extent_io_tree *tree, | ||
177 | struct extent_buffer *eb); | ||
178 | int set_extent_buffer_dirty(struct extent_io_tree *tree, | ||
179 | struct extent_buffer *eb); | ||
180 | int set_extent_buffer_uptodate(struct extent_io_tree *tree, | ||
181 | struct extent_buffer *eb); | ||
182 | int extent_buffer_uptodate(struct extent_io_tree *tree, | ||
183 | struct extent_buffer *eb); | ||
184 | int map_extent_buffer(struct extent_buffer *eb, unsigned long offset, | ||
185 | unsigned long min_len, char **token, char **map, | ||
186 | unsigned long *map_start, | ||
187 | unsigned long *map_len, int km); | ||
188 | int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset, | ||
189 | unsigned long min_len, char **token, char **map, | ||
190 | unsigned long *map_start, | ||
191 | unsigned long *map_len, int km); | ||
192 | void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km); | ||
193 | #endif | ||