]>
Commit | Line | Data |
---|---|---|
2cb7cef9 BS |
1 | From: Joel Becker <joel.becker@oracle.com> |
2 | Subject: ocfs2: Make ocfs2_extent_tree the first-class representation of a tree. | |
3 | Patch-mainline: 2.6.28? | |
4 | References: FATE302067 | |
5 | ||
6 | We now have three different kinds of extent trees in ocfs2: inode data | |
7 | (dinode), extended attributes (xattr_tree), and extended attribute | |
8 | values (xattr_value). There is a nice abstraction for them, | |
9 | ocfs2_extent_tree, but it is hidden in alloc.c. All the calling | |
10 | functions have to pick amongst a varied API and pass in type bits and | |
11 | often extraneous pointers. | |
12 | ||
13 | A better way is to make ocfs2_extent_tree a first-class object. | |
14 | Everyone converts their object to an ocfs2_extent_tree() via the | |
15 | ocfs2_get_*_extent_tree() calls, then uses the ocfs2_extent_tree for all | |
16 | tree calls to alloc.c. | |
17 | ||
18 | This simplifies a lot of callers, making for readability. It also | |
19 | provides an easy way to add additional extent tree types, as they only | |
20 | need to be defined in alloc.c with a ocfs2_get_<new>_extent_tree() | |
21 | function. | |
22 | ||
23 | Signed-off-by: Joel Becker <joel.becker@oracle.com> | |
24 | Acked-by: Mark Fasheh <mark.fasheh@suse.com> | |
25 | --- | |
82094b55 AF |
26 | fs/ocfs2/alloc.c | 300 +++++++++++++++------------------------------------- |
27 | fs/ocfs2/alloc.h | 111 ++++++++++--------- | |
28 | fs/ocfs2/aops.c | 16 +- | |
29 | fs/ocfs2/dir.c | 20 ++- | |
30 | fs/ocfs2/file.c | 36 +++--- | |
31 | fs/ocfs2/suballoc.c | 12 -- | |
32 | fs/ocfs2/suballoc.h | 6 - | |
33 | fs/ocfs2/xattr.c | 71 ++++++------ | |
2cb7cef9 BS |
34 | 8 files changed, 240 insertions(+), 332 deletions(-) |
35 | ||
82094b55 AF |
36 | --- a/fs/ocfs2/alloc.c |
37 | +++ b/fs/ocfs2/alloc.c | |
2cb7cef9 BS |
38 | @@ -49,20 +49,6 @@ |
39 | ||
40 | #include "buffer_head_io.h" | |
41 | ||
42 | -/* | |
43 | - * ocfs2_extent_tree and ocfs2_extent_tree_operations are used to abstract | |
44 | - * the b-tree operations in ocfs2. Now all the b-tree operations are not | |
45 | - * limited to ocfs2_dinode only. Any data which need to allocate clusters | |
46 | - * to store can use b-tree. And it only needs to implement its ocfs2_extent_tree | |
47 | - * and operation. | |
48 | - * | |
49 | - * ocfs2_extent_tree contains info for the root of the b-tree, it must have a | |
50 | - * root ocfs2_extent_list and a root_bh so that they can be used in the b-tree | |
51 | - * functions. | |
52 | - * ocfs2_extent_tree_operations abstract the normal operations we do for | |
53 | - * the root of extent b-tree. | |
54 | - */ | |
55 | -struct ocfs2_extent_tree; | |
56 | ||
57 | struct ocfs2_extent_tree_operations { | |
58 | void (*eo_set_last_eb_blk)(struct ocfs2_extent_tree *et, | |
59 | @@ -83,28 +69,38 @@ struct ocfs2_extent_tree_operations { | |
60 | struct ocfs2_extent_tree *et); | |
61 | }; | |
62 | ||
63 | -struct ocfs2_extent_tree { | |
64 | - enum ocfs2_extent_tree_type et_type; | |
65 | - struct ocfs2_extent_tree_operations *et_ops; | |
66 | - struct buffer_head *et_root_bh; | |
67 | - struct ocfs2_extent_list *et_root_el; | |
68 | - void *et_object; | |
69 | - unsigned int et_max_leaf_clusters; | |
70 | -}; | |
71 | ||
72 | -static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et) | |
73 | -{ | |
74 | - struct ocfs2_dinode *di = et->et_object; | |
75 | - | |
76 | - et->et_root_el = &di->id2.i_list; | |
77 | -} | |
78 | +/* | |
79 | + * Pre-declare ocfs2_dinode_et_ops so we can use it as a sanity check | |
80 | + * in the methods. | |
81 | + */ | |
82 | +static u64 ocfs2_dinode_get_last_eb_blk(struct ocfs2_extent_tree *et); | |
83 | +static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et, | |
84 | + u64 blkno); | |
85 | +static void ocfs2_dinode_update_clusters(struct inode *inode, | |
86 | + struct ocfs2_extent_tree *et, | |
87 | + u32 clusters); | |
88 | +static int ocfs2_dinode_insert_check(struct inode *inode, | |
89 | + struct ocfs2_extent_tree *et, | |
90 | + struct ocfs2_extent_rec *rec); | |
91 | +static int ocfs2_dinode_sanity_check(struct inode *inode, | |
92 | + struct ocfs2_extent_tree *et); | |
93 | +static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et); | |
94 | +static struct ocfs2_extent_tree_operations ocfs2_dinode_et_ops = { | |
95 | + .eo_set_last_eb_blk = ocfs2_dinode_set_last_eb_blk, | |
96 | + .eo_get_last_eb_blk = ocfs2_dinode_get_last_eb_blk, | |
97 | + .eo_update_clusters = ocfs2_dinode_update_clusters, | |
98 | + .eo_insert_check = ocfs2_dinode_insert_check, | |
99 | + .eo_sanity_check = ocfs2_dinode_sanity_check, | |
100 | + .eo_fill_root_el = ocfs2_dinode_fill_root_el, | |
101 | +}; | |
102 | ||
103 | static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et, | |
104 | u64 blkno) | |
105 | { | |
106 | struct ocfs2_dinode *di = et->et_object; | |
107 | ||
108 | - BUG_ON(et->et_type != OCFS2_DINODE_EXTENT); | |
109 | + BUG_ON(et->et_ops != &ocfs2_dinode_et_ops); | |
110 | di->i_last_eb_blk = cpu_to_le64(blkno); | |
111 | } | |
112 | ||
113 | @@ -112,7 +108,7 @@ static u64 ocfs2_dinode_get_last_eb_blk( | |
114 | { | |
115 | struct ocfs2_dinode *di = et->et_object; | |
116 | ||
117 | - BUG_ON(et->et_type != OCFS2_DINODE_EXTENT); | |
118 | + BUG_ON(et->et_ops != &ocfs2_dinode_et_ops); | |
119 | return le64_to_cpu(di->i_last_eb_blk); | |
120 | } | |
121 | ||
122 | @@ -153,7 +149,7 @@ static int ocfs2_dinode_sanity_check(str | |
123 | int ret = 0; | |
124 | struct ocfs2_dinode *di; | |
125 | ||
126 | - BUG_ON(et->et_type != OCFS2_DINODE_EXTENT); | |
127 | + BUG_ON(et->et_ops != &ocfs2_dinode_et_ops); | |
128 | ||
129 | di = et->et_object; | |
130 | if (!OCFS2_IS_VALID_DINODE(di)) { | |
131 | @@ -166,14 +162,13 @@ static int ocfs2_dinode_sanity_check(str | |
132 | return ret; | |
133 | } | |
134 | ||
135 | -static struct ocfs2_extent_tree_operations ocfs2_dinode_et_ops = { | |
136 | - .eo_set_last_eb_blk = ocfs2_dinode_set_last_eb_blk, | |
137 | - .eo_get_last_eb_blk = ocfs2_dinode_get_last_eb_blk, | |
138 | - .eo_update_clusters = ocfs2_dinode_update_clusters, | |
139 | - .eo_insert_check = ocfs2_dinode_insert_check, | |
140 | - .eo_sanity_check = ocfs2_dinode_sanity_check, | |
141 | - .eo_fill_root_el = ocfs2_dinode_fill_root_el, | |
142 | -}; | |
143 | +static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et) | |
144 | +{ | |
145 | + struct ocfs2_dinode *di = et->et_object; | |
146 | + | |
147 | + et->et_root_el = &di->id2.i_list; | |
148 | +} | |
149 | + | |
150 | ||
151 | static void ocfs2_xattr_value_fill_root_el(struct ocfs2_extent_tree *et) | |
152 | { | |
153 | @@ -269,10 +264,8 @@ static void __ocfs2_get_extent_tree(stru | |
154 | struct inode *inode, | |
155 | struct buffer_head *bh, | |
156 | void *obj, | |
157 | - enum ocfs2_extent_tree_type et_type, | |
158 | struct ocfs2_extent_tree_operations *ops) | |
159 | { | |
160 | - et->et_type = et_type; | |
161 | et->et_ops = ops; | |
162 | get_bh(bh); | |
163 | et->et_root_bh = bh; | |
164 | @@ -287,50 +280,31 @@ static void __ocfs2_get_extent_tree(stru | |
165 | et->et_ops->eo_fill_max_leaf_clusters(inode, et); | |
166 | } | |
167 | ||
168 | -static void ocfs2_get_dinode_extent_tree(struct ocfs2_extent_tree *et, | |
169 | - struct inode *inode, | |
170 | - struct buffer_head *bh) | |
171 | +void ocfs2_get_dinode_extent_tree(struct ocfs2_extent_tree *et, | |
172 | + struct inode *inode, | |
173 | + struct buffer_head *bh) | |
174 | { | |
175 | - __ocfs2_get_extent_tree(et, inode, bh, NULL, OCFS2_DINODE_EXTENT, | |
176 | - &ocfs2_dinode_et_ops); | |
177 | + __ocfs2_get_extent_tree(et, inode, bh, NULL, &ocfs2_dinode_et_ops); | |
178 | } | |
179 | ||
180 | -static void ocfs2_get_xattr_tree_extent_tree(struct ocfs2_extent_tree *et, | |
181 | - struct inode *inode, | |
182 | - struct buffer_head *bh) | |
183 | +void ocfs2_get_xattr_tree_extent_tree(struct ocfs2_extent_tree *et, | |
184 | + struct inode *inode, | |
185 | + struct buffer_head *bh) | |
186 | { | |
187 | __ocfs2_get_extent_tree(et, inode, bh, NULL, | |
188 | - OCFS2_XATTR_TREE_EXTENT, | |
189 | &ocfs2_xattr_tree_et_ops); | |
190 | } | |
191 | ||
192 | -static void ocfs2_get_xattr_value_extent_tree(struct ocfs2_extent_tree *et, | |
193 | - struct inode *inode, | |
194 | - struct buffer_head *bh, | |
195 | - struct ocfs2_xattr_value_root *xv) | |
196 | +void ocfs2_get_xattr_value_extent_tree(struct ocfs2_extent_tree *et, | |
197 | + struct inode *inode, | |
198 | + struct buffer_head *bh, | |
199 | + struct ocfs2_xattr_value_root *xv) | |
200 | { | |
201 | __ocfs2_get_extent_tree(et, inode, bh, xv, | |
202 | - OCFS2_XATTR_VALUE_EXTENT, | |
203 | &ocfs2_xattr_value_et_ops); | |
204 | } | |
205 | ||
206 | -static void ocfs2_get_extent_tree(struct ocfs2_extent_tree *et, | |
207 | - struct inode *inode, | |
208 | - struct buffer_head *bh, | |
209 | - enum ocfs2_extent_tree_type et_type, | |
210 | - void *obj) | |
211 | -{ | |
212 | - if (et_type == OCFS2_DINODE_EXTENT) | |
213 | - ocfs2_get_dinode_extent_tree(et, inode, bh); | |
214 | - else if (et_type == OCFS2_XATTR_VALUE_EXTENT) | |
215 | - ocfs2_get_xattr_tree_extent_tree(et, inode, bh); | |
216 | - else if (et_type == OCFS2_XATTR_TREE_EXTENT) | |
217 | - ocfs2_get_xattr_value_extent_tree(et, inode, bh, obj); | |
218 | - else | |
219 | - BUG(); | |
220 | -} | |
221 | - | |
222 | -static void ocfs2_put_extent_tree(struct ocfs2_extent_tree *et) | |
223 | +void ocfs2_put_extent_tree(struct ocfs2_extent_tree *et) | |
224 | { | |
225 | brelse(et->et_root_bh); | |
226 | } | |
227 | @@ -682,22 +656,18 @@ struct ocfs2_merge_ctxt { | |
228 | */ | |
229 | int ocfs2_num_free_extents(struct ocfs2_super *osb, | |
230 | struct inode *inode, | |
231 | - struct buffer_head *root_bh, | |
232 | - enum ocfs2_extent_tree_type type, | |
233 | - void *obj) | |
234 | + struct ocfs2_extent_tree *et) | |
235 | { | |
236 | int retval; | |
237 | struct ocfs2_extent_list *el = NULL; | |
238 | struct ocfs2_extent_block *eb; | |
239 | struct buffer_head *eb_bh = NULL; | |
240 | u64 last_eb_blk = 0; | |
241 | - struct ocfs2_extent_tree et; | |
242 | ||
243 | mlog_entry_void(); | |
244 | ||
245 | - ocfs2_get_extent_tree(&et, inode, root_bh, type, obj); | |
246 | - el = et.et_root_el; | |
247 | - last_eb_blk = ocfs2_et_get_last_eb_blk(&et); | |
248 | + el = et->et_root_el; | |
249 | + last_eb_blk = ocfs2_et_get_last_eb_blk(et); | |
250 | ||
251 | if (last_eb_blk) { | |
252 | retval = ocfs2_read_block(osb, last_eb_blk, | |
253 | @@ -717,7 +687,6 @@ bail: | |
254 | if (eb_bh) | |
255 | brelse(eb_bh); | |
256 | ||
257 | - ocfs2_put_extent_tree(&et); | |
258 | mlog_exit(retval); | |
259 | return retval; | |
260 | } | |
261 | @@ -4415,16 +4384,15 @@ out: | |
262 | * | |
263 | * The caller needs to update fe->i_clusters | |
264 | */ | |
265 | -static int ocfs2_insert_extent(struct ocfs2_super *osb, | |
266 | - handle_t *handle, | |
267 | - struct inode *inode, | |
268 | - struct buffer_head *root_bh, | |
269 | - u32 cpos, | |
270 | - u64 start_blk, | |
271 | - u32 new_clusters, | |
272 | - u8 flags, | |
273 | - struct ocfs2_alloc_context *meta_ac, | |
274 | - struct ocfs2_extent_tree *et) | |
275 | +int ocfs2_insert_extent(struct ocfs2_super *osb, | |
276 | + handle_t *handle, | |
277 | + struct inode *inode, | |
278 | + struct ocfs2_extent_tree *et, | |
279 | + u32 cpos, | |
280 | + u64 start_blk, | |
281 | + u32 new_clusters, | |
282 | + u8 flags, | |
283 | + struct ocfs2_alloc_context *meta_ac) | |
284 | { | |
285 | int status; | |
286 | int uninitialized_var(free_records); | |
287 | @@ -4473,7 +4441,7 @@ static int ocfs2_insert_extent(struct oc | |
288 | status = ocfs2_do_insert_extent(inode, handle, et, &rec, &insert); | |
289 | if (status < 0) | |
290 | mlog_errno(status); | |
291 | - else if (et->et_type == OCFS2_DINODE_EXTENT) | |
292 | + else if (et->et_ops == &ocfs2_dinode_et_ops) | |
293 | ocfs2_extent_map_insert_rec(inode, &rec); | |
294 | ||
295 | bail: | |
296 | @@ -4484,77 +4452,10 @@ bail: | |
297 | return status; | |
298 | } | |
299 | ||
300 | -int ocfs2_dinode_insert_extent(struct ocfs2_super *osb, | |
301 | - handle_t *handle, | |
302 | - struct inode *inode, | |
303 | - struct buffer_head *root_bh, | |
304 | - u32 cpos, | |
305 | - u64 start_blk, | |
306 | - u32 new_clusters, | |
307 | - u8 flags, | |
308 | - struct ocfs2_alloc_context *meta_ac) | |
309 | -{ | |
310 | - int status; | |
311 | - struct ocfs2_extent_tree et; | |
312 | - | |
313 | - ocfs2_get_dinode_extent_tree(&et, inode, root_bh); | |
314 | - status = ocfs2_insert_extent(osb, handle, inode, root_bh, | |
315 | - cpos, start_blk, new_clusters, | |
316 | - flags, meta_ac, &et); | |
317 | - ocfs2_put_extent_tree(&et); | |
318 | - | |
319 | - return status; | |
320 | -} | |
321 | - | |
322 | -int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb, | |
323 | - handle_t *handle, | |
324 | - struct inode *inode, | |
325 | - struct buffer_head *root_bh, | |
326 | - u32 cpos, | |
327 | - u64 start_blk, | |
328 | - u32 new_clusters, | |
329 | - u8 flags, | |
330 | - struct ocfs2_alloc_context *meta_ac, | |
331 | - struct ocfs2_xattr_value_root *xv) | |
332 | -{ | |
333 | - int status; | |
334 | - struct ocfs2_extent_tree et; | |
335 | - | |
336 | - ocfs2_get_xattr_value_extent_tree(&et, inode, root_bh, xv); | |
337 | - status = ocfs2_insert_extent(osb, handle, inode, root_bh, | |
338 | - cpos, start_blk, new_clusters, | |
339 | - flags, meta_ac, &et); | |
340 | - ocfs2_put_extent_tree(&et); | |
341 | - | |
342 | - return status; | |
343 | -} | |
344 | - | |
345 | -int ocfs2_xattr_tree_insert_extent(struct ocfs2_super *osb, | |
346 | - handle_t *handle, | |
347 | - struct inode *inode, | |
348 | - struct buffer_head *root_bh, | |
349 | - u32 cpos, | |
350 | - u64 start_blk, | |
351 | - u32 new_clusters, | |
352 | - u8 flags, | |
353 | - struct ocfs2_alloc_context *meta_ac) | |
354 | -{ | |
355 | - int status; | |
356 | - struct ocfs2_extent_tree et; | |
357 | - | |
358 | - ocfs2_get_xattr_tree_extent_tree(&et, inode, root_bh); | |
359 | - status = ocfs2_insert_extent(osb, handle, inode, root_bh, | |
360 | - cpos, start_blk, new_clusters, | |
361 | - flags, meta_ac, &et); | |
362 | - ocfs2_put_extent_tree(&et); | |
363 | - | |
364 | - return status; | |
365 | -} | |
366 | - | |
367 | /* | |
368 | * Allcate and add clusters into the extent b-tree. | |
369 | * The new clusters(clusters_to_add) will be inserted at logical_offset. | |
370 | - * The extent b-tree's root is root_el and it should be in root_bh, and | |
371 | + * The extent b-tree's root is specified by et, and | |
372 | * it is not limited to the file storage. Any extent tree can use this | |
373 | * function if it implements the proper ocfs2_extent_tree. | |
374 | */ | |
375 | @@ -4563,14 +4464,11 @@ int ocfs2_add_clusters_in_btree(struct o | |
376 | u32 *logical_offset, | |
377 | u32 clusters_to_add, | |
378 | int mark_unwritten, | |
379 | - struct buffer_head *root_bh, | |
380 | - struct ocfs2_extent_list *root_el, | |
381 | + struct ocfs2_extent_tree *et, | |
382 | handle_t *handle, | |
383 | struct ocfs2_alloc_context *data_ac, | |
384 | struct ocfs2_alloc_context *meta_ac, | |
385 | - enum ocfs2_alloc_restarted *reason_ret, | |
386 | - enum ocfs2_extent_tree_type type, | |
387 | - void *obj) | |
388 | + enum ocfs2_alloc_restarted *reason_ret) | |
389 | { | |
390 | int status = 0; | |
391 | int free_extents; | |
392 | @@ -4584,8 +4482,7 @@ int ocfs2_add_clusters_in_btree(struct o | |
393 | if (mark_unwritten) | |
394 | flags = OCFS2_EXT_UNWRITTEN; | |
395 | ||
396 | - free_extents = ocfs2_num_free_extents(osb, inode, root_bh, type, | |
397 | - obj); | |
398 | + free_extents = ocfs2_num_free_extents(osb, inode, et); | |
399 | if (free_extents < 0) { | |
400 | status = free_extents; | |
401 | mlog_errno(status); | |
402 | @@ -4604,7 +4501,7 @@ int ocfs2_add_clusters_in_btree(struct o | |
403 | goto leave; | |
404 | } else if ((!free_extents) | |
405 | && (ocfs2_alloc_context_bits_left(meta_ac) | |
406 | - < ocfs2_extend_meta_needed(root_el))) { | |
407 | + < ocfs2_extend_meta_needed(et->et_root_el))) { | |
408 | mlog(0, "filesystem is really fragmented...\n"); | |
409 | status = -EAGAIN; | |
410 | reason = RESTART_META; | |
411 | @@ -4622,7 +4519,7 @@ int ocfs2_add_clusters_in_btree(struct o | |
412 | BUG_ON(num_bits > clusters_to_add); | |
413 | ||
414 | /* reserve our write early -- insert_extent may update the inode */ | |
415 | - status = ocfs2_journal_access(handle, inode, root_bh, | |
416 | + status = ocfs2_journal_access(handle, inode, et->et_root_bh, | |
417 | OCFS2_JOURNAL_ACCESS_WRITE); | |
418 | if (status < 0) { | |
419 | mlog_errno(status); | |
420 | @@ -4632,28 +4529,15 @@ int ocfs2_add_clusters_in_btree(struct o | |
421 | block = ocfs2_clusters_to_blocks(osb->sb, bit_off); | |
422 | mlog(0, "Allocating %u clusters at block %u for inode %llu\n", | |
423 | num_bits, bit_off, (unsigned long long)OCFS2_I(inode)->ip_blkno); | |
424 | - if (type == OCFS2_DINODE_EXTENT) | |
425 | - status = ocfs2_dinode_insert_extent(osb, handle, inode, root_bh, | |
426 | - *logical_offset, block, | |
427 | - num_bits, flags, meta_ac); | |
428 | - else if (type == OCFS2_XATTR_TREE_EXTENT) | |
429 | - status = ocfs2_xattr_tree_insert_extent(osb, handle, | |
430 | - inode, root_bh, | |
431 | - *logical_offset, | |
432 | - block, num_bits, flags, | |
433 | - meta_ac); | |
434 | - else | |
435 | - status = ocfs2_xattr_value_insert_extent(osb, handle, | |
436 | - inode, root_bh, | |
437 | - *logical_offset, | |
438 | - block, num_bits, flags, | |
439 | - meta_ac, obj); | |
440 | + status = ocfs2_insert_extent(osb, handle, inode, et, | |
441 | + *logical_offset, block, | |
442 | + num_bits, flags, meta_ac); | |
443 | if (status < 0) { | |
444 | mlog_errno(status); | |
445 | goto leave; | |
446 | } | |
447 | ||
448 | - status = ocfs2_journal_dirty(handle, root_bh); | |
449 | + status = ocfs2_journal_dirty(handle, et->et_root_bh); | |
450 | if (status < 0) { | |
451 | mlog_errno(status); | |
452 | goto leave; | |
453 | @@ -4924,25 +4808,21 @@ out: | |
454 | * | |
455 | * The caller is responsible for passing down meta_ac if we'll need it. | |
456 | */ | |
457 | -int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh, | |
458 | +int ocfs2_mark_extent_written(struct inode *inode, | |
459 | + struct ocfs2_extent_tree *et, | |
460 | handle_t *handle, u32 cpos, u32 len, u32 phys, | |
461 | struct ocfs2_alloc_context *meta_ac, | |
462 | - struct ocfs2_cached_dealloc_ctxt *dealloc, | |
463 | - enum ocfs2_extent_tree_type et_type, | |
464 | - void *obj) | |
465 | + struct ocfs2_cached_dealloc_ctxt *dealloc) | |
466 | { | |
467 | int ret, index; | |
468 | u64 start_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys); | |
469 | struct ocfs2_extent_rec split_rec; | |
470 | struct ocfs2_path *left_path = NULL; | |
471 | struct ocfs2_extent_list *el; | |
472 | - struct ocfs2_extent_tree et; | |
473 | ||
474 | mlog(0, "Inode %lu cpos %u, len %u, phys %u (%llu)\n", | |
475 | inode->i_ino, cpos, len, phys, (unsigned long long)start_blkno); | |
476 | ||
477 | - ocfs2_get_extent_tree(&et, inode, root_bh, et_type, obj); | |
478 | - | |
479 | if (!ocfs2_writes_unwritten_extents(OCFS2_SB(inode->i_sb))) { | |
480 | ocfs2_error(inode->i_sb, "Inode %llu has unwritten extents " | |
481 | "that are being written to, but the feature bit " | |
482 | @@ -4955,11 +4835,14 @@ int ocfs2_mark_extent_written(struct ino | |
483 | /* | |
484 | * XXX: This should be fixed up so that we just re-insert the | |
485 | * next extent records. | |
486 | + * | |
487 | + * XXX: This is a hack on the extent tree, maybe it should be | |
488 | + * an op? | |
489 | */ | |
490 | - if (et_type == OCFS2_DINODE_EXTENT) | |
491 | + if (et->et_ops == &ocfs2_dinode_et_ops) | |
492 | ocfs2_extent_map_trunc(inode, 0); | |
493 | ||
494 | - left_path = ocfs2_new_path(et.et_root_bh, et.et_root_el); | |
495 | + left_path = ocfs2_new_path(et->et_root_bh, et->et_root_el); | |
496 | if (!left_path) { | |
497 | ret = -ENOMEM; | |
498 | mlog_errno(ret); | |
499 | @@ -4990,7 +4873,7 @@ int ocfs2_mark_extent_written(struct ino | |
500 | split_rec.e_flags = path_leaf_el(left_path)->l_recs[index].e_flags; | |
501 | split_rec.e_flags &= ~OCFS2_EXT_UNWRITTEN; | |
502 | ||
503 | - ret = __ocfs2_mark_extent_written(inode, &et, handle, left_path, | |
504 | + ret = __ocfs2_mark_extent_written(inode, et, handle, left_path, | |
505 | index, &split_rec, meta_ac, | |
506 | dealloc); | |
507 | if (ret) | |
508 | @@ -4998,7 +4881,6 @@ int ocfs2_mark_extent_written(struct ino | |
509 | ||
510 | out: | |
511 | ocfs2_free_path(left_path); | |
512 | - ocfs2_put_extent_tree(&et); | |
513 | return ret; | |
514 | } | |
515 | ||
516 | @@ -5228,25 +5110,21 @@ out: | |
517 | return ret; | |
518 | } | |
519 | ||
520 | -int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh, | |
521 | +int ocfs2_remove_extent(struct inode *inode, | |
522 | + struct ocfs2_extent_tree *et, | |
523 | u32 cpos, u32 len, handle_t *handle, | |
524 | struct ocfs2_alloc_context *meta_ac, | |
525 | - struct ocfs2_cached_dealloc_ctxt *dealloc, | |
526 | - enum ocfs2_extent_tree_type et_type, | |
527 | - void *obj) | |
528 | + struct ocfs2_cached_dealloc_ctxt *dealloc) | |
529 | { | |
530 | int ret, index; | |
531 | u32 rec_range, trunc_range; | |
532 | struct ocfs2_extent_rec *rec; | |
533 | struct ocfs2_extent_list *el; | |
534 | struct ocfs2_path *path = NULL; | |
535 | - struct ocfs2_extent_tree et; | |
536 | - | |
537 | - ocfs2_get_extent_tree(&et, inode, root_bh, et_type, obj); | |
538 | ||
539 | ocfs2_extent_map_trunc(inode, 0); | |
540 | ||
541 | - path = ocfs2_new_path(et.et_root_bh, et.et_root_el); | |
542 | + path = ocfs2_new_path(et->et_root_bh, et->et_root_el); | |
543 | if (!path) { | |
544 | ret = -ENOMEM; | |
545 | mlog_errno(ret); | |
546 | @@ -5299,13 +5177,13 @@ int ocfs2_remove_extent(struct inode *in | |
547 | ||
548 | if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) { | |
549 | ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, | |
550 | - cpos, len, &et); | |
551 | + cpos, len, et); | |
552 | if (ret) { | |
553 | mlog_errno(ret); | |
554 | goto out; | |
555 | } | |
556 | } else { | |
557 | - ret = ocfs2_split_tree(inode, &et, handle, path, index, | |
558 | + ret = ocfs2_split_tree(inode, et, handle, path, index, | |
559 | trunc_range, meta_ac); | |
560 | if (ret) { | |
561 | mlog_errno(ret); | |
562 | @@ -5354,7 +5232,7 @@ int ocfs2_remove_extent(struct inode *in | |
563 | } | |
564 | ||
565 | ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, | |
566 | - cpos, len, &et); | |
567 | + cpos, len, et); | |
568 | if (ret) { | |
569 | mlog_errno(ret); | |
570 | goto out; | |
571 | @@ -5363,7 +5241,6 @@ int ocfs2_remove_extent(struct inode *in | |
572 | ||
573 | out: | |
574 | ocfs2_free_path(path); | |
575 | - ocfs2_put_extent_tree(&et); | |
576 | return ret; | |
577 | } | |
578 | ||
579 | @@ -6782,6 +6659,7 @@ int ocfs2_convert_inline_data_to_extents | |
580 | struct ocfs2_alloc_context *data_ac = NULL; | |
581 | struct page **pages = NULL; | |
582 | loff_t end = osb->s_clustersize; | |
583 | + struct ocfs2_extent_tree et; | |
584 | ||
585 | has_data = i_size_read(inode) ? 1 : 0; | |
586 | ||
587 | @@ -6881,8 +6759,10 @@ int ocfs2_convert_inline_data_to_extents | |
588 | * this proves to be false, we could always re-build | |
589 | * the in-inode data from our pages. | |
590 | */ | |
591 | - ret = ocfs2_dinode_insert_extent(osb, handle, inode, di_bh, | |
592 | - 0, block, 1, 0, NULL); | |
593 | + ocfs2_get_dinode_extent_tree(&et, inode, di_bh); | |
594 | + ret = ocfs2_insert_extent(osb, handle, inode, &et, | |
595 | + 0, block, 1, 0, NULL); | |
596 | + ocfs2_put_extent_tree(&et); | |
597 | if (ret) { | |
598 | mlog_errno(ret); | |
599 | goto out_commit; | |
82094b55 AF |
600 | --- a/fs/ocfs2/alloc.h |
601 | +++ b/fs/ocfs2/alloc.h | |
2cb7cef9 BS |
602 | @@ -26,46 +26,66 @@ |
603 | #ifndef OCFS2_ALLOC_H | |
604 | #define OCFS2_ALLOC_H | |
605 | ||
606 | -enum ocfs2_extent_tree_type { | |
607 | - OCFS2_DINODE_EXTENT = 0, | |
608 | - OCFS2_XATTR_VALUE_EXTENT, | |
609 | - OCFS2_XATTR_TREE_EXTENT, | |
610 | -}; | |
611 | ||
612 | /* | |
613 | * For xattr tree leaf, we limit the leaf byte size to be 64K. | |
614 | */ | |
615 | #define OCFS2_MAX_XATTR_TREE_LEAF_SIZE 65536 | |
616 | ||
617 | +/* | |
618 | + * ocfs2_extent_tree and ocfs2_extent_tree_operations are used to abstract | |
619 | + * the b-tree operations in ocfs2. Now all the b-tree operations are not | |
620 | + * limited to ocfs2_dinode only. Any data which need to allocate clusters | |
621 | + * to store can use b-tree. And it only needs to implement its ocfs2_extent_tree | |
622 | + * and operation. | |
623 | + * | |
624 | + * ocfs2_extent_tree becomes the first-class object for extent tree | |
625 | + * manipulation. Callers of the alloc.c code need to fill it via one of | |
626 | + * the ocfs2_get_*_extent_tree() operations below. | |
627 | + * | |
628 | + * ocfs2_extent_tree contains info for the root of the b-tree, it must have a | |
629 | + * root ocfs2_extent_list and a root_bh so that they can be used in the b-tree | |
630 | + * functions. | |
631 | + * ocfs2_extent_tree_operations abstract the normal operations we do for | |
632 | + * the root of extent b-tree. | |
633 | + */ | |
634 | +struct ocfs2_extent_tree_operations; | |
635 | +struct ocfs2_extent_tree { | |
636 | + struct ocfs2_extent_tree_operations *et_ops; | |
637 | + struct buffer_head *et_root_bh; | |
638 | + struct ocfs2_extent_list *et_root_el; | |
639 | + void *et_object; | |
640 | + unsigned int et_max_leaf_clusters; | |
641 | +}; | |
642 | + | |
643 | +/* | |
644 | + * ocfs2_*_get_extent_tree() will fill an ocfs2_extent_tree from the | |
645 | + * specified object buffer. The bh is referenced until | |
646 | + * ocfs2_put_extent_tree(). | |
647 | + */ | |
648 | +void ocfs2_get_dinode_extent_tree(struct ocfs2_extent_tree *et, | |
649 | + struct inode *inode, | |
650 | + struct buffer_head *bh); | |
651 | +void ocfs2_get_xattr_tree_extent_tree(struct ocfs2_extent_tree *et, | |
652 | + struct inode *inode, | |
653 | + struct buffer_head *bh); | |
654 | +void ocfs2_get_xattr_value_extent_tree(struct ocfs2_extent_tree *et, | |
655 | + struct inode *inode, | |
656 | + struct buffer_head *bh, | |
657 | + struct ocfs2_xattr_value_root *xv); | |
658 | +void ocfs2_put_extent_tree(struct ocfs2_extent_tree *et); | |
659 | + | |
660 | struct ocfs2_alloc_context; | |
661 | -int ocfs2_dinode_insert_extent(struct ocfs2_super *osb, | |
662 | - handle_t *handle, | |
663 | - struct inode *inode, | |
664 | - struct buffer_head *root_bh, | |
665 | - u32 cpos, | |
666 | - u64 start_blk, | |
667 | - u32 new_clusters, | |
668 | - u8 flags, | |
669 | - struct ocfs2_alloc_context *meta_ac); | |
670 | -int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb, | |
671 | - handle_t *handle, | |
672 | - struct inode *inode, | |
673 | - struct buffer_head *root_bh, | |
674 | - u32 cpos, | |
675 | - u64 start_blk, | |
676 | - u32 new_clusters, | |
677 | - u8 flags, | |
678 | - struct ocfs2_alloc_context *meta_ac, | |
679 | - struct ocfs2_xattr_value_root *xv); | |
680 | -int ocfs2_xattr_tree_insert_extent(struct ocfs2_super *osb, | |
681 | - handle_t *handle, | |
682 | - struct inode *inode, | |
683 | - struct buffer_head *root_bh, | |
684 | - u32 cpos, | |
685 | - u64 start_blk, | |
686 | - u32 new_clusters, | |
687 | - u8 flags, | |
688 | - struct ocfs2_alloc_context *meta_ac); | |
689 | +int ocfs2_insert_extent(struct ocfs2_super *osb, | |
690 | + handle_t *handle, | |
691 | + struct inode *inode, | |
692 | + struct ocfs2_extent_tree *et, | |
693 | + u32 cpos, | |
694 | + u64 start_blk, | |
695 | + u32 new_clusters, | |
696 | + u8 flags, | |
697 | + struct ocfs2_alloc_context *meta_ac); | |
698 | + | |
699 | enum ocfs2_alloc_restarted { | |
700 | RESTART_NONE = 0, | |
701 | RESTART_TRANS, | |
702 | @@ -76,32 +96,25 @@ int ocfs2_add_clusters_in_btree(struct o | |
703 | u32 *logical_offset, | |
704 | u32 clusters_to_add, | |
705 | int mark_unwritten, | |
706 | - struct buffer_head *root_bh, | |
707 | - struct ocfs2_extent_list *root_el, | |
708 | + struct ocfs2_extent_tree *et, | |
709 | handle_t *handle, | |
710 | struct ocfs2_alloc_context *data_ac, | |
711 | struct ocfs2_alloc_context *meta_ac, | |
712 | - enum ocfs2_alloc_restarted *reason_ret, | |
713 | - enum ocfs2_extent_tree_type type, | |
714 | - void *private); | |
715 | + enum ocfs2_alloc_restarted *reason_ret); | |
716 | struct ocfs2_cached_dealloc_ctxt; | |
717 | -int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh, | |
718 | +int ocfs2_mark_extent_written(struct inode *inode, | |
719 | + struct ocfs2_extent_tree *et, | |
720 | handle_t *handle, u32 cpos, u32 len, u32 phys, | |
721 | struct ocfs2_alloc_context *meta_ac, | |
722 | - struct ocfs2_cached_dealloc_ctxt *dealloc, | |
723 | - enum ocfs2_extent_tree_type et_type, | |
724 | - void *private); | |
725 | -int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh, | |
726 | + struct ocfs2_cached_dealloc_ctxt *dealloc); | |
727 | +int ocfs2_remove_extent(struct inode *inode, | |
728 | + struct ocfs2_extent_tree *et, | |
729 | u32 cpos, u32 len, handle_t *handle, | |
730 | struct ocfs2_alloc_context *meta_ac, | |
731 | - struct ocfs2_cached_dealloc_ctxt *dealloc, | |
732 | - enum ocfs2_extent_tree_type et_type, | |
733 | - void *private); | |
734 | + struct ocfs2_cached_dealloc_ctxt *dealloc); | |
735 | int ocfs2_num_free_extents(struct ocfs2_super *osb, | |
736 | struct inode *inode, | |
737 | - struct buffer_head *root_bh, | |
738 | - enum ocfs2_extent_tree_type et_type, | |
739 | - void *private); | |
740 | + struct ocfs2_extent_tree *et); | |
741 | ||
742 | /* | |
743 | * how many new metadata chunks would an allocation need at maximum? | |
82094b55 AF |
744 | --- a/fs/ocfs2/aops.c |
745 | +++ b/fs/ocfs2/aops.c | |
746 | @@ -1243,6 +1243,7 @@ static int ocfs2_write_cluster(struct ad | |
747 | int ret, i, new; | |
2cb7cef9 BS |
748 | u64 v_blkno, p_blkno; |
749 | struct inode *inode = mapping->host; | |
750 | + struct ocfs2_extent_tree et; | |
751 | ||
752 | new = phys == 0 ? 1 : 0; | |
82094b55 AF |
753 | |
754 | @@ -1275,10 +1276,11 @@ static int ocfs2_write_cluster(struct ad | |
2cb7cef9 BS |
755 | goto out; |
756 | } | |
757 | } else if (unwritten) { | |
758 | - ret = ocfs2_mark_extent_written(inode, wc->w_di_bh, | |
759 | + ocfs2_get_dinode_extent_tree(&et, inode, wc->w_di_bh); | |
760 | + ret = ocfs2_mark_extent_written(inode, &et, | |
761 | wc->w_handle, cpos, 1, phys, | |
762 | - meta_ac, &wc->w_dealloc, | |
763 | - OCFS2_DINODE_EXTENT, NULL); | |
764 | + meta_ac, &wc->w_dealloc); | |
765 | + ocfs2_put_extent_tree(&et); | |
766 | if (ret < 0) { | |
767 | mlog_errno(ret); | |
768 | goto out; | |
82094b55 | 769 | @@ -1685,6 +1687,7 @@ int ocfs2_write_begin_nolock(struct addr |
2cb7cef9 BS |
770 | struct ocfs2_alloc_context *data_ac = NULL; |
771 | struct ocfs2_alloc_context *meta_ac = NULL; | |
772 | handle_t *handle; | |
773 | + struct ocfs2_extent_tree et; | |
774 | ||
775 | ret = ocfs2_alloc_write_ctxt(&wc, osb, pos, len, di_bh); | |
776 | if (ret) { | |
82094b55 | 777 | @@ -1738,10 +1741,11 @@ int ocfs2_write_begin_nolock(struct addr |
2cb7cef9 BS |
778 | (long long)i_size_read(inode), le32_to_cpu(di->i_clusters), |
779 | clusters_to_alloc, extents_to_split); | |
780 | ||
781 | - ret = ocfs2_lock_allocators(inode, wc->w_di_bh, &di->id2.i_list, | |
782 | + ocfs2_get_dinode_extent_tree(&et, inode, wc->w_di_bh); | |
783 | + ret = ocfs2_lock_allocators(inode, &et, | |
784 | clusters_to_alloc, extents_to_split, | |
785 | - &data_ac, &meta_ac, | |
786 | - OCFS2_DINODE_EXTENT, NULL); | |
787 | + &data_ac, &meta_ac); | |
788 | + ocfs2_put_extent_tree(&et); | |
789 | if (ret) { | |
790 | mlog_errno(ret); | |
791 | goto out; | |
82094b55 AF |
792 | --- a/fs/ocfs2/dir.c |
793 | +++ b/fs/ocfs2/dir.c | |
2cb7cef9 BS |
794 | @@ -1192,6 +1192,9 @@ static int ocfs2_expand_inline_dir(struc |
795 | struct buffer_head *dirdata_bh = NULL; | |
796 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | |
797 | handle_t *handle; | |
798 | + struct ocfs2_extent_tree et; | |
799 | + | |
800 | + ocfs2_get_dinode_extent_tree(&et, dir, di_bh); | |
801 | ||
802 | alloc = ocfs2_clusters_for_bytes(sb, bytes); | |
803 | ||
804 | @@ -1305,8 +1308,8 @@ static int ocfs2_expand_inline_dir(struc | |
805 | * This should never fail as our extent list is empty and all | |
806 | * related blocks have been journaled already. | |
807 | */ | |
808 | - ret = ocfs2_dinode_insert_extent(osb, handle, dir, di_bh, 0, blkno, | |
809 | - len, 0, NULL); | |
810 | + ret = ocfs2_insert_extent(osb, handle, dir, &et, 0, blkno, len, | |
811 | + 0, NULL); | |
812 | if (ret) { | |
813 | mlog_errno(ret); | |
814 | goto out_commit; | |
815 | @@ -1337,8 +1340,8 @@ static int ocfs2_expand_inline_dir(struc | |
816 | } | |
817 | blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off); | |
818 | ||
819 | - ret = ocfs2_dinode_insert_extent(osb, handle, dir, di_bh, 1, | |
820 | - blkno, len, 0, NULL); | |
821 | + ret = ocfs2_insert_extent(osb, handle, dir, &et, 1, | |
822 | + blkno, len, 0, NULL); | |
823 | if (ret) { | |
824 | mlog_errno(ret); | |
825 | goto out_commit; | |
826 | @@ -1360,6 +1363,7 @@ out: | |
827 | ||
828 | brelse(dirdata_bh); | |
829 | ||
830 | + ocfs2_put_extent_tree(&et); | |
831 | return ret; | |
832 | } | |
833 | ||
834 | @@ -1437,6 +1441,7 @@ static int ocfs2_extend_dir(struct ocfs2 | |
835 | struct buffer_head *new_bh = NULL; | |
836 | struct ocfs2_dir_entry * de; | |
837 | struct super_block *sb = osb->sb; | |
838 | + struct ocfs2_extent_tree et; | |
839 | ||
840 | mlog_entry_void(); | |
841 | ||
842 | @@ -1480,10 +1485,9 @@ static int ocfs2_extend_dir(struct ocfs2 | |
843 | spin_lock(&OCFS2_I(dir)->ip_lock); | |
844 | if (dir_i_size == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)) { | |
845 | spin_unlock(&OCFS2_I(dir)->ip_lock); | |
846 | - num_free_extents = ocfs2_num_free_extents(osb, dir, | |
847 | - parent_fe_bh, | |
848 | - OCFS2_DINODE_EXTENT, | |
849 | - NULL); | |
850 | + ocfs2_get_dinode_extent_tree(&et, dir, parent_fe_bh); | |
851 | + num_free_extents = ocfs2_num_free_extents(osb, dir, &et); | |
852 | + ocfs2_put_extent_tree(&et); | |
853 | if (num_free_extents < 0) { | |
854 | status = num_free_extents; | |
855 | mlog_errno(status); | |
82094b55 AF |
856 | --- a/fs/ocfs2/file.c |
857 | +++ b/fs/ocfs2/file.c | |
2cb7cef9 BS |
858 | @@ -509,14 +509,17 @@ int ocfs2_add_inode_data(struct ocfs2_su |
859 | struct ocfs2_alloc_context *meta_ac, | |
860 | enum ocfs2_alloc_restarted *reason_ret) | |
861 | { | |
862 | - struct ocfs2_dinode *fe = (struct ocfs2_dinode *) fe_bh->b_data; | |
863 | - struct ocfs2_extent_list *el = &fe->id2.i_list; | |
864 | + int ret; | |
865 | + struct ocfs2_extent_tree et; | |
866 | ||
867 | - return ocfs2_add_clusters_in_btree(osb, inode, logical_offset, | |
868 | + ocfs2_get_dinode_extent_tree(&et, inode, fe_bh); | |
869 | + ret = ocfs2_add_clusters_in_btree(osb, inode, logical_offset, | |
870 | clusters_to_add, mark_unwritten, | |
871 | - fe_bh, el, handle, | |
872 | - data_ac, meta_ac, reason_ret, | |
873 | - OCFS2_DINODE_EXTENT, NULL); | |
874 | + &et, handle, | |
875 | + data_ac, meta_ac, reason_ret); | |
876 | + ocfs2_put_extent_tree(&et); | |
877 | + | |
878 | + return ret; | |
879 | } | |
880 | ||
881 | static int __ocfs2_extend_allocation(struct inode *inode, u32 logical_start, | |
882 | @@ -533,6 +536,7 @@ static int __ocfs2_extend_allocation(str | |
883 | struct ocfs2_alloc_context *meta_ac = NULL; | |
884 | enum ocfs2_alloc_restarted why; | |
885 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | |
886 | + struct ocfs2_extent_tree et; | |
887 | ||
888 | mlog_entry("(clusters_to_add = %u)\n", clusters_to_add); | |
889 | ||
890 | @@ -564,9 +568,10 @@ restart_all: | |
891 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | |
892 | (long long)i_size_read(inode), le32_to_cpu(fe->i_clusters), | |
893 | clusters_to_add); | |
894 | - status = ocfs2_lock_allocators(inode, bh, &fe->id2.i_list, | |
895 | - clusters_to_add, 0, &data_ac, | |
896 | - &meta_ac, OCFS2_DINODE_EXTENT, NULL); | |
897 | + ocfs2_get_dinode_extent_tree(&et, inode, bh); | |
898 | + status = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0, | |
899 | + &data_ac, &meta_ac); | |
900 | + ocfs2_put_extent_tree(&et); | |
901 | if (status) { | |
902 | mlog_errno(status); | |
903 | goto leave; | |
904 | @@ -1236,11 +1241,13 @@ static int __ocfs2_remove_inode_range(st | |
905 | handle_t *handle; | |
906 | struct ocfs2_alloc_context *meta_ac = NULL; | |
907 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; | |
908 | + struct ocfs2_extent_tree et; | |
909 | + | |
910 | + ocfs2_get_dinode_extent_tree(&et, inode, di_bh); | |
911 | ||
912 | - ret = ocfs2_lock_allocators(inode, di_bh, &di->id2.i_list, | |
913 | - 0, 1, NULL, &meta_ac, | |
914 | - OCFS2_DINODE_EXTENT, NULL); | |
915 | + ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac); | |
916 | if (ret) { | |
917 | + ocfs2_put_extent_tree(&et); | |
918 | mlog_errno(ret); | |
919 | return ret; | |
920 | } | |
921 | @@ -1269,8 +1276,8 @@ static int __ocfs2_remove_inode_range(st | |
922 | goto out; | |
923 | } | |
924 | ||
925 | - ret = ocfs2_remove_extent(inode, di_bh, cpos, len, handle, meta_ac, | |
926 | - dealloc, OCFS2_DINODE_EXTENT, NULL); | |
927 | + ret = ocfs2_remove_extent(inode, &et, cpos, len, handle, meta_ac, | |
928 | + dealloc); | |
929 | if (ret) { | |
930 | mlog_errno(ret); | |
931 | goto out_commit; | |
932 | @@ -1297,6 +1304,7 @@ out: | |
933 | if (meta_ac) | |
934 | ocfs2_free_alloc_context(meta_ac); | |
935 | ||
936 | + ocfs2_put_extent_tree(&et); | |
937 | return ret; | |
938 | } | |
939 | ||
82094b55 AF |
940 | --- a/fs/ocfs2/suballoc.c |
941 | +++ b/fs/ocfs2/suballoc.c | |
2cb7cef9 BS |
942 | @@ -1911,12 +1911,11 @@ static inline void ocfs2_debug_suballoc_ |
943 | * File systems which don't support holes call this from | |
944 | * ocfs2_extend_allocation(). | |
945 | */ | |
946 | -int ocfs2_lock_allocators(struct inode *inode, struct buffer_head *root_bh, | |
947 | - struct ocfs2_extent_list *root_el, | |
948 | +int ocfs2_lock_allocators(struct inode *inode, | |
949 | + struct ocfs2_extent_tree *et, | |
950 | u32 clusters_to_add, u32 extents_to_split, | |
951 | struct ocfs2_alloc_context **data_ac, | |
952 | - struct ocfs2_alloc_context **meta_ac, | |
953 | - enum ocfs2_extent_tree_type type, void *private) | |
954 | + struct ocfs2_alloc_context **meta_ac) | |
955 | { | |
956 | int ret = 0, num_free_extents; | |
957 | unsigned int max_recs_needed = clusters_to_add + 2 * extents_to_split; | |
958 | @@ -1928,8 +1927,7 @@ int ocfs2_lock_allocators(struct inode * | |
959 | ||
960 | BUG_ON(clusters_to_add != 0 && data_ac == NULL); | |
961 | ||
962 | - num_free_extents = ocfs2_num_free_extents(osb, inode, root_bh, | |
963 | - type, private); | |
964 | + num_free_extents = ocfs2_num_free_extents(osb, inode, et); | |
965 | if (num_free_extents < 0) { | |
966 | ret = num_free_extents; | |
967 | mlog_errno(ret); | |
968 | @@ -1951,7 +1949,7 @@ int ocfs2_lock_allocators(struct inode * | |
969 | */ | |
970 | if (!num_free_extents || | |
971 | (ocfs2_sparse_alloc(osb) && num_free_extents < max_recs_needed)) { | |
972 | - ret = ocfs2_reserve_new_metadata(osb, root_el, meta_ac); | |
973 | + ret = ocfs2_reserve_new_metadata(osb, et->et_root_el, meta_ac); | |
974 | if (ret < 0) { | |
975 | if (ret != -ENOSPC) | |
976 | mlog_errno(ret); | |
82094b55 AF |
977 | --- a/fs/ocfs2/suballoc.h |
978 | +++ b/fs/ocfs2/suballoc.h | |
2cb7cef9 BS |
979 | @@ -164,10 +164,8 @@ u64 ocfs2_which_cluster_group(struct ino |
980 | int ocfs2_check_group_descriptor(struct super_block *sb, | |
981 | struct ocfs2_dinode *di, | |
982 | struct ocfs2_group_desc *gd); | |
983 | -int ocfs2_lock_allocators(struct inode *inode, struct buffer_head *root_bh, | |
984 | - struct ocfs2_extent_list *root_el, | |
985 | +int ocfs2_lock_allocators(struct inode *inode, struct ocfs2_extent_tree *et, | |
986 | u32 clusters_to_add, u32 extents_to_split, | |
987 | struct ocfs2_alloc_context **data_ac, | |
988 | - struct ocfs2_alloc_context **meta_ac, | |
989 | - enum ocfs2_extent_tree_type type, void *private); | |
990 | + struct ocfs2_alloc_context **meta_ac); | |
991 | #endif /* _CHAINALLOC_H_ */ | |
82094b55 AF |
992 | --- a/fs/ocfs2/xattr.c |
993 | +++ b/fs/ocfs2/xattr.c | |
2cb7cef9 BS |
994 | @@ -222,22 +222,24 @@ static int ocfs2_xattr_extend_allocation |
995 | struct ocfs2_alloc_context *meta_ac = NULL; | |
996 | enum ocfs2_alloc_restarted why; | |
997 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | |
998 | - struct ocfs2_extent_list *root_el = &xv->xr_list; | |
999 | u32 prev_clusters, logical_start = le32_to_cpu(xv->xr_clusters); | |
1000 | + struct ocfs2_extent_tree et; | |
1001 | ||
1002 | mlog(0, "(clusters_to_add for xattr= %u)\n", clusters_to_add); | |
1003 | ||
1004 | + ocfs2_get_xattr_value_extent_tree(&et, inode, xattr_bh, xv); | |
1005 | + | |
1006 | restart_all: | |
1007 | ||
1008 | - status = ocfs2_lock_allocators(inode, xattr_bh, root_el, | |
1009 | - clusters_to_add, 0, &data_ac, | |
1010 | - &meta_ac, OCFS2_XATTR_VALUE_EXTENT, xv); | |
1011 | + status = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0, | |
1012 | + &data_ac, &meta_ac); | |
1013 | if (status) { | |
1014 | mlog_errno(status); | |
1015 | goto leave; | |
1016 | } | |
1017 | ||
1018 | - credits = ocfs2_calc_extend_credits(osb->sb, root_el, clusters_to_add); | |
1019 | + credits = ocfs2_calc_extend_credits(osb->sb, et.et_root_el, | |
1020 | + clusters_to_add); | |
1021 | handle = ocfs2_start_trans(osb, credits); | |
1022 | if (IS_ERR(handle)) { | |
1023 | status = PTR_ERR(handle); | |
1024 | @@ -260,14 +262,11 @@ restarted_transaction: | |
1025 | &logical_start, | |
1026 | clusters_to_add, | |
1027 | 0, | |
1028 | - xattr_bh, | |
1029 | - root_el, | |
1030 | + &et, | |
1031 | handle, | |
1032 | data_ac, | |
1033 | meta_ac, | |
1034 | - &why, | |
1035 | - OCFS2_XATTR_VALUE_EXTENT, | |
1036 | - xv); | |
1037 | + &why); | |
1038 | if ((status < 0) && (status != -EAGAIN)) { | |
1039 | if (status != -ENOSPC) | |
1040 | mlog_errno(status); | |
1041 | @@ -292,7 +291,7 @@ restarted_transaction: | |
1042 | mlog(0, "restarting transaction.\n"); | |
1043 | /* TODO: This can be more intelligent. */ | |
1044 | credits = ocfs2_calc_extend_credits(osb->sb, | |
1045 | - root_el, | |
1046 | + et.et_root_el, | |
1047 | clusters_to_add); | |
1048 | status = ocfs2_extend_trans(handle, credits); | |
1049 | if (status < 0) { | |
1050 | @@ -324,6 +323,7 @@ leave: | |
1051 | goto restart_all; | |
1052 | } | |
1053 | ||
1054 | + ocfs2_put_extent_tree(&et); | |
1055 | return status; | |
1056 | } | |
1057 | ||
1058 | @@ -339,11 +339,13 @@ static int __ocfs2_remove_xattr_range(st | |
1059 | struct inode *tl_inode = osb->osb_tl_inode; | |
1060 | handle_t *handle; | |
1061 | struct ocfs2_alloc_context *meta_ac = NULL; | |
1062 | + struct ocfs2_extent_tree et; | |
1063 | + | |
1064 | + ocfs2_get_xattr_value_extent_tree(&et, inode, root_bh, xv); | |
1065 | ||
1066 | - ret = ocfs2_lock_allocators(inode, root_bh, &xv->xr_list, | |
1067 | - 0, 1, NULL, &meta_ac, | |
1068 | - OCFS2_XATTR_VALUE_EXTENT, xv); | |
1069 | + ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac); | |
1070 | if (ret) { | |
1071 | + ocfs2_put_extent_tree(&et); | |
1072 | mlog_errno(ret); | |
1073 | return ret; | |
1074 | } | |
1075 | @@ -372,8 +374,8 @@ static int __ocfs2_remove_xattr_range(st | |
1076 | goto out_commit; | |
1077 | } | |
1078 | ||
1079 | - ret = ocfs2_remove_extent(inode, root_bh, cpos, len, handle, meta_ac, | |
1080 | - dealloc, OCFS2_XATTR_VALUE_EXTENT, xv); | |
1081 | + ret = ocfs2_remove_extent(inode, &et, cpos, len, handle, meta_ac, | |
1082 | + dealloc); | |
1083 | if (ret) { | |
1084 | mlog_errno(ret); | |
1085 | goto out_commit; | |
1086 | @@ -399,6 +401,7 @@ out: | |
1087 | if (meta_ac) | |
1088 | ocfs2_free_alloc_context(meta_ac); | |
1089 | ||
1090 | + ocfs2_put_extent_tree(&et); | |
1091 | return ret; | |
1092 | } | |
1093 | ||
1094 | @@ -3638,26 +3641,24 @@ static int ocfs2_add_new_xattr_cluster(s | |
1095 | struct ocfs2_alloc_context *data_ac = NULL; | |
1096 | struct ocfs2_alloc_context *meta_ac = NULL; | |
1097 | struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); | |
1098 | - struct ocfs2_xattr_block *xb = | |
1099 | - (struct ocfs2_xattr_block *)root_bh->b_data; | |
1100 | - struct ocfs2_xattr_tree_root *xb_root = &xb->xb_attrs.xb_root; | |
1101 | - struct ocfs2_extent_list *root_el = &xb_root->xt_list; | |
1102 | - enum ocfs2_extent_tree_type type = OCFS2_XATTR_TREE_EXTENT; | |
1103 | + struct ocfs2_extent_tree et; | |
1104 | ||
1105 | mlog(0, "Add new xattr cluster for %llu, previous xattr hash = %u, " | |
1106 | "previous xattr blkno = %llu\n", | |
1107 | (unsigned long long)OCFS2_I(inode)->ip_blkno, | |
1108 | prev_cpos, prev_blkno); | |
1109 | ||
1110 | - ret = ocfs2_lock_allocators(inode, root_bh, root_el, | |
1111 | - clusters_to_add, 0, &data_ac, | |
1112 | - &meta_ac, type, NULL); | |
1113 | + ocfs2_get_xattr_tree_extent_tree(&et, inode, root_bh); | |
1114 | + | |
1115 | + ret = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0, | |
1116 | + &data_ac, &meta_ac); | |
1117 | if (ret) { | |
1118 | mlog_errno(ret); | |
1119 | goto leave; | |
1120 | } | |
1121 | ||
1122 | - credits = ocfs2_calc_extend_credits(osb->sb, root_el, clusters_to_add); | |
1123 | + credits = ocfs2_calc_extend_credits(osb->sb, et.et_root_el, | |
1124 | + clusters_to_add); | |
1125 | handle = ocfs2_start_trans(osb, credits); | |
1126 | if (IS_ERR(handle)) { | |
1127 | ret = PTR_ERR(handle); | |
1128 | @@ -3721,9 +3722,8 @@ static int ocfs2_add_new_xattr_cluster(s | |
1129 | ||
1130 | mlog(0, "Insert %u clusters at block %llu for xattr at %u\n", | |
1131 | num_bits, block, v_start); | |
1132 | - ret = ocfs2_xattr_tree_insert_extent(osb, handle, inode, root_bh, | |
1133 | - v_start, block, num_bits, | |
1134 | - 0, meta_ac); | |
1135 | + ret = ocfs2_insert_extent(osb, handle, inode, &et, v_start, block, | |
1136 | + num_bits, 0, meta_ac); | |
1137 | if (ret < 0) { | |
1138 | mlog_errno(ret); | |
1139 | goto leave; | |
1140 | @@ -3743,6 +3743,7 @@ leave: | |
1141 | if (meta_ac) | |
1142 | ocfs2_free_alloc_context(meta_ac); | |
1143 | ||
1144 | + ocfs2_put_extent_tree(&et); | |
1145 | return ret; | |
1146 | } | |
1147 | ||
1148 | @@ -4347,9 +4348,11 @@ static int ocfs2_rm_xattr_cluster(struct | |
1149 | handle_t *handle; | |
1150 | struct ocfs2_xattr_block *xb = | |
1151 | (struct ocfs2_xattr_block *)root_bh->b_data; | |
1152 | - struct ocfs2_extent_list *root_el = &xb->xb_attrs.xb_root.xt_list; | |
1153 | struct ocfs2_alloc_context *meta_ac = NULL; | |
1154 | struct ocfs2_cached_dealloc_ctxt dealloc; | |
1155 | + struct ocfs2_extent_tree et; | |
1156 | + | |
1157 | + ocfs2_get_xattr_tree_extent_tree(&et, inode, root_bh); | |
1158 | ||
1159 | ocfs2_init_dealloc_ctxt(&dealloc); | |
1160 | ||
1161 | @@ -4358,10 +4361,9 @@ static int ocfs2_rm_xattr_cluster(struct | |
1162 | ||
1163 | ocfs2_remove_xattr_clusters_from_cache(inode, blkno, len); | |
1164 | ||
1165 | - ret = ocfs2_lock_allocators(inode, root_bh, root_el, | |
1166 | - 0, 1, NULL, &meta_ac, | |
1167 | - OCFS2_XATTR_TREE_EXTENT, NULL); | |
1168 | + ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac); | |
1169 | if (ret) { | |
1170 | + ocfs2_put_extent_tree(&et); | |
1171 | mlog_errno(ret); | |
1172 | return ret; | |
1173 | } | |
1174 | @@ -4390,8 +4392,8 @@ static int ocfs2_rm_xattr_cluster(struct | |
1175 | goto out_commit; | |
1176 | } | |
1177 | ||
1178 | - ret = ocfs2_remove_extent(inode, root_bh, cpos, len, handle, meta_ac, | |
1179 | - &dealloc, OCFS2_XATTR_TREE_EXTENT, NULL); | |
1180 | + ret = ocfs2_remove_extent(inode, &et, cpos, len, handle, meta_ac, | |
1181 | + &dealloc); | |
1182 | if (ret) { | |
1183 | mlog_errno(ret); | |
1184 | goto out_commit; | |
1185 | @@ -4421,6 +4423,7 @@ out: | |
1186 | ||
1187 | ocfs2_run_deallocs(osb, &dealloc); | |
1188 | ||
1189 | + ocfs2_put_extent_tree(&et); | |
1190 | return ret; | |
1191 | } | |
1192 |