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?
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.
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.
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()
23 Signed-off-by: Joel Becker <joel.becker@oracle.com>
24 Acked-by: Mark Fasheh <mark.fasheh@suse.com>
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 ++++++------
34 8 files changed, 240 insertions(+), 332 deletions(-)
36 --- a/fs/ocfs2/alloc.c
37 +++ b/fs/ocfs2/alloc.c
40 #include "buffer_head_io.h"
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
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
52 - * ocfs2_extent_tree_operations abstract the normal operations we do for
53 - * the root of extent b-tree.
55 -struct ocfs2_extent_tree;
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);
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;
69 - unsigned int et_max_leaf_clusters;
72 -static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et)
74 - struct ocfs2_dinode *di = et->et_object;
76 - et->et_root_el = &di->id2.i_list;
79 + * Pre-declare ocfs2_dinode_et_ops so we can use it as a sanity check
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,
85 +static void ocfs2_dinode_update_clusters(struct inode *inode,
86 + struct ocfs2_extent_tree *et,
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,
103 static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et,
106 struct ocfs2_dinode *di = et->et_object;
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);
113 @@ -112,7 +108,7 @@ static u64 ocfs2_dinode_get_last_eb_blk(
115 struct ocfs2_dinode *di = et->et_object;
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);
122 @@ -153,7 +149,7 @@ static int ocfs2_dinode_sanity_check(str
124 struct ocfs2_dinode *di;
126 - BUG_ON(et->et_type != OCFS2_DINODE_EXTENT);
127 + BUG_ON(et->et_ops != &ocfs2_dinode_et_ops);
130 if (!OCFS2_IS_VALID_DINODE(di)) {
131 @@ -166,14 +162,13 @@ static int ocfs2_dinode_sanity_check(str
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,
143 +static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et)
145 + struct ocfs2_dinode *di = et->et_object;
147 + et->et_root_el = &di->id2.i_list;
151 static void ocfs2_xattr_value_fill_root_el(struct ocfs2_extent_tree *et)
153 @@ -269,10 +264,8 @@ static void __ocfs2_get_extent_tree(stru
155 struct buffer_head *bh,
157 - enum ocfs2_extent_tree_type et_type,
158 struct ocfs2_extent_tree_operations *ops)
160 - et->et_type = et_type;
164 @@ -287,50 +280,31 @@ static void __ocfs2_get_extent_tree(stru
165 et->et_ops->eo_fill_max_leaf_clusters(inode, et);
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)
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);
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)
187 __ocfs2_get_extent_tree(et, inode, bh, NULL,
188 - OCFS2_XATTR_TREE_EXTENT,
189 &ocfs2_xattr_tree_et_ops);
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)
201 __ocfs2_get_extent_tree(et, inode, bh, xv,
202 - OCFS2_XATTR_VALUE_EXTENT,
203 &ocfs2_xattr_value_et_ops);
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,
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);
222 -static void ocfs2_put_extent_tree(struct ocfs2_extent_tree *et)
223 +void ocfs2_put_extent_tree(struct ocfs2_extent_tree *et)
225 brelse(et->et_root_bh);
227 @@ -682,22 +656,18 @@ struct ocfs2_merge_ctxt {
229 int ocfs2_num_free_extents(struct ocfs2_super *osb,
231 - struct buffer_head *root_bh,
232 - enum ocfs2_extent_tree_type type,
234 + struct ocfs2_extent_tree *et)
237 struct ocfs2_extent_list *el = NULL;
238 struct ocfs2_extent_block *eb;
239 struct buffer_head *eb_bh = NULL;
241 - struct ocfs2_extent_tree et;
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);
252 retval = ocfs2_read_block(osb, last_eb_blk,
253 @@ -717,7 +687,6 @@ bail:
257 - ocfs2_put_extent_tree(&et);
261 @@ -4415,16 +4384,15 @@ out:
263 * The caller needs to update fe->i_clusters
265 -static int ocfs2_insert_extent(struct ocfs2_super *osb,
267 - struct inode *inode,
268 - struct buffer_head *root_bh,
273 - struct ocfs2_alloc_context *meta_ac,
274 - struct ocfs2_extent_tree *et)
275 +int ocfs2_insert_extent(struct ocfs2_super *osb,
277 + struct inode *inode,
278 + struct ocfs2_extent_tree *et,
283 + struct ocfs2_alloc_context *meta_ac)
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);
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);
296 @@ -4484,77 +4452,10 @@ bail:
300 -int ocfs2_dinode_insert_extent(struct ocfs2_super *osb,
302 - struct inode *inode,
303 - struct buffer_head *root_bh,
308 - struct ocfs2_alloc_context *meta_ac)
311 - struct ocfs2_extent_tree et;
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);
322 -int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb,
324 - struct inode *inode,
325 - struct buffer_head *root_bh,
330 - struct ocfs2_alloc_context *meta_ac,
331 - struct ocfs2_xattr_value_root *xv)
334 - struct ocfs2_extent_tree et;
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);
345 -int ocfs2_xattr_tree_insert_extent(struct ocfs2_super *osb,
347 - struct inode *inode,
348 - struct buffer_head *root_bh,
353 - struct ocfs2_alloc_context *meta_ac)
356 - struct ocfs2_extent_tree et;
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);
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.
375 @@ -4563,14 +4464,11 @@ int ocfs2_add_clusters_in_btree(struct o
379 - struct buffer_head *root_bh,
380 - struct ocfs2_extent_list *root_el,
381 + struct ocfs2_extent_tree *et,
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,
388 + enum ocfs2_alloc_restarted *reason_ret)
392 @@ -4584,8 +4482,7 @@ int ocfs2_add_clusters_in_btree(struct o
394 flags = OCFS2_EXT_UNWRITTEN;
396 - free_extents = ocfs2_num_free_extents(osb, inode, root_bh, type,
398 + free_extents = ocfs2_num_free_extents(osb, inode, et);
399 if (free_extents < 0) {
400 status = free_extents;
402 @@ -4604,7 +4501,7 @@ int ocfs2_add_clusters_in_btree(struct o
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");
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);
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);
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,
432 - block, num_bits, flags,
435 - status = ocfs2_xattr_value_insert_extent(osb, handle,
438 - block, num_bits, flags,
440 + status = ocfs2_insert_extent(osb, handle, inode, et,
441 + *logical_offset, block,
442 + num_bits, flags, meta_ac);
448 - status = ocfs2_journal_dirty(handle, root_bh);
449 + status = ocfs2_journal_dirty(handle, et->et_root_bh);
453 @@ -4924,25 +4808,21 @@ out:
455 * The caller is responsible for passing down meta_ac if we'll need it.
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,
465 + struct ocfs2_cached_dealloc_ctxt *dealloc)
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;
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);
477 - ocfs2_get_extent_tree(&et, inode, root_bh, et_type, obj);
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
484 * XXX: This should be fixed up so that we just re-insert the
485 * next extent records.
487 + * XXX: This is a hack on the extent tree, maybe it should be
490 - if (et_type == OCFS2_DINODE_EXTENT)
491 + if (et->et_ops == &ocfs2_dinode_et_ops)
492 ocfs2_extent_map_trunc(inode, 0);
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);
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;
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,
508 @@ -4998,7 +4881,6 @@ int ocfs2_mark_extent_written(struct ino
511 ocfs2_free_path(left_path);
512 - ocfs2_put_extent_tree(&et);
516 @@ -5228,25 +5110,21 @@ out:
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,
528 + struct ocfs2_cached_dealloc_ctxt *dealloc)
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;
537 - ocfs2_get_extent_tree(&et, inode, root_bh, et_type, obj);
539 ocfs2_extent_map_trunc(inode, 0);
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);
546 @@ -5299,13 +5177,13 @@ int ocfs2_remove_extent(struct inode *in
548 if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) {
549 ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc,
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);
562 @@ -5354,7 +5232,7 @@ int ocfs2_remove_extent(struct inode *in
565 ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc,
571 @@ -5363,7 +5241,6 @@ int ocfs2_remove_extent(struct inode *in
574 ocfs2_free_path(path);
575 - ocfs2_put_extent_tree(&et);
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;
585 has_data = i_size_read(inode) ? 1 : 0;
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.
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);
600 --- a/fs/ocfs2/alloc.h
601 +++ b/fs/ocfs2/alloc.h
603 #ifndef OCFS2_ALLOC_H
604 #define OCFS2_ALLOC_H
606 -enum ocfs2_extent_tree_type {
607 - OCFS2_DINODE_EXTENT = 0,
608 - OCFS2_XATTR_VALUE_EXTENT,
609 - OCFS2_XATTR_TREE_EXTENT,
613 * For xattr tree leaf, we limit the leaf byte size to be 64K.
615 #define OCFS2_MAX_XATTR_TREE_LEAF_SIZE 65536
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
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.
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
631 + * ocfs2_extent_tree_operations abstract the normal operations we do for
632 + * the root of extent b-tree.
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;
640 + unsigned int et_max_leaf_clusters;
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().
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);
660 struct ocfs2_alloc_context;
661 -int ocfs2_dinode_insert_extent(struct ocfs2_super *osb,
663 - struct inode *inode,
664 - struct buffer_head *root_bh,
669 - struct ocfs2_alloc_context *meta_ac);
670 -int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb,
672 - struct inode *inode,
673 - struct buffer_head *root_bh,
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,
682 - struct inode *inode,
683 - struct buffer_head *root_bh,
688 - struct ocfs2_alloc_context *meta_ac);
689 +int ocfs2_insert_extent(struct ocfs2_super *osb,
691 + struct inode *inode,
692 + struct ocfs2_extent_tree *et,
697 + struct ocfs2_alloc_context *meta_ac);
699 enum ocfs2_alloc_restarted {
702 @@ -76,32 +96,25 @@ int ocfs2_add_clusters_in_btree(struct o
706 - struct buffer_head *root_bh,
707 - struct ocfs2_extent_list *root_el,
708 + struct ocfs2_extent_tree *et,
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,
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,
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,
734 + struct ocfs2_cached_dealloc_ctxt *dealloc);
735 int ocfs2_num_free_extents(struct ocfs2_super *osb,
737 - struct buffer_head *root_bh,
738 - enum ocfs2_extent_tree_type et_type,
740 + struct ocfs2_extent_tree *et);
743 * how many new metadata chunks would an allocation need at maximum?
744 --- a/fs/ocfs2/aops.c
745 +++ b/fs/ocfs2/aops.c
746 @@ -1243,6 +1243,7 @@ static int ocfs2_write_cluster(struct ad
748 u64 v_blkno, p_blkno;
749 struct inode *inode = mapping->host;
750 + struct ocfs2_extent_tree et;
752 new = phys == 0 ? 1 : 0;
754 @@ -1275,10 +1276,11 @@ static int ocfs2_write_cluster(struct ad
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);
769 @@ -1685,6 +1687,7 @@ int ocfs2_write_begin_nolock(struct addr
770 struct ocfs2_alloc_context *data_ac = NULL;
771 struct ocfs2_alloc_context *meta_ac = NULL;
773 + struct ocfs2_extent_tree et;
775 ret = ocfs2_alloc_write_ctxt(&wc, osb, pos, len, di_bh);
777 @@ -1738,10 +1741,11 @@ int ocfs2_write_begin_nolock(struct addr
778 (long long)i_size_read(inode), le32_to_cpu(di->i_clusters),
779 clusters_to_alloc, extents_to_split);
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);
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;
798 + struct ocfs2_extent_tree et;
800 + ocfs2_get_dinode_extent_tree(&et, dir, di_bh);
802 alloc = ocfs2_clusters_for_bytes(sb, bytes);
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.
808 - ret = ocfs2_dinode_insert_extent(osb, handle, dir, di_bh, 0, blkno,
810 + ret = ocfs2_insert_extent(osb, handle, dir, &et, 0, blkno, len,
815 @@ -1337,8 +1340,8 @@ static int ocfs2_expand_inline_dir(struc
817 blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off);
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);
826 @@ -1360,6 +1363,7 @@ out:
830 + ocfs2_put_extent_tree(&et);
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;
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,
848 - OCFS2_DINODE_EXTENT,
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;
856 --- a/fs/ocfs2/file.c
857 +++ b/fs/ocfs2/file.c
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)
862 - struct ocfs2_dinode *fe = (struct ocfs2_dinode *) fe_bh->b_data;
863 - struct ocfs2_extent_list *el = &fe->id2.i_list;
865 + struct ocfs2_extent_tree et;
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,
872 - data_ac, meta_ac, reason_ret,
873 - OCFS2_DINODE_EXTENT, NULL);
875 + data_ac, meta_ac, reason_ret);
876 + ocfs2_put_extent_tree(&et);
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;
888 mlog_entry("(clusters_to_add = %u)\n", clusters_to_add);
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),
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);
904 @@ -1236,11 +1241,13 @@ static int __ocfs2_remove_inode_range(st
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;
910 + ocfs2_get_dinode_extent_tree(&et, inode, di_bh);
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);
917 + ocfs2_put_extent_tree(&et);
921 @@ -1269,8 +1276,8 @@ static int __ocfs2_remove_inode_range(st
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,
932 @@ -1297,6 +1304,7 @@ out:
934 ocfs2_free_alloc_context(meta_ac);
936 + ocfs2_put_extent_tree(&et);
940 --- a/fs/ocfs2/suballoc.c
941 +++ b/fs/ocfs2/suballoc.c
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().
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)
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 *
960 BUG_ON(clusters_to_add != 0 && data_ac == NULL);
962 - num_free_extents = ocfs2_num_free_extents(osb, inode, root_bh,
964 + num_free_extents = ocfs2_num_free_extents(osb, inode, et);
965 if (num_free_extents < 0) {
966 ret = num_free_extents;
968 @@ -1951,7 +1949,7 @@ int ocfs2_lock_allocators(struct inode *
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);
977 --- a/fs/ocfs2/suballoc.h
978 +++ b/fs/ocfs2/suballoc.h
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_ */
992 --- a/fs/ocfs2/xattr.c
993 +++ b/fs/ocfs2/xattr.c
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;
1002 mlog(0, "(clusters_to_add for xattr= %u)\n", clusters_to_add);
1004 + ocfs2_get_xattr_value_extent_tree(&et, inode, xattr_bh, xv);
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);
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,
1021 handle = ocfs2_start_trans(osb, credits);
1022 if (IS_ERR(handle)) {
1023 status = PTR_ERR(handle);
1024 @@ -260,14 +262,11 @@ restarted_transaction:
1035 - OCFS2_XATTR_VALUE_EXTENT,
1038 if ((status < 0) && (status != -EAGAIN)) {
1039 if (status != -ENOSPC)
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,
1048 status = ocfs2_extend_trans(handle, credits);
1050 @@ -324,6 +323,7 @@ leave:
1054 + ocfs2_put_extent_tree(&et);
1058 @@ -339,11 +339,13 @@ static int __ocfs2_remove_xattr_range(st
1059 struct inode *tl_inode = osb->osb_tl_inode;
1061 struct ocfs2_alloc_context *meta_ac = NULL;
1062 + struct ocfs2_extent_tree et;
1064 + ocfs2_get_xattr_value_extent_tree(&et, inode, root_bh, xv);
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);
1071 + ocfs2_put_extent_tree(&et);
1075 @@ -372,8 +374,8 @@ static int __ocfs2_remove_xattr_range(st
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,
1086 @@ -399,6 +401,7 @@ out:
1088 ocfs2_free_alloc_context(meta_ac);
1090 + ocfs2_put_extent_tree(&et);
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;
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);
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);
1115 + ret = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0,
1116 + &data_ac, &meta_ac);
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,
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
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,
1135 + ret = ocfs2_insert_extent(osb, handle, inode, &et, v_start, block,
1136 + num_bits, 0, meta_ac);
1140 @@ -3743,6 +3743,7 @@ leave:
1142 ocfs2_free_alloc_context(meta_ac);
1144 + ocfs2_put_extent_tree(&et);
1148 @@ -4347,9 +4348,11 @@ static int ocfs2_rm_xattr_cluster(struct
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;
1157 + ocfs2_get_xattr_tree_extent_tree(&et, inode, root_bh);
1159 ocfs2_init_dealloc_ctxt(&dealloc);
1161 @@ -4358,10 +4361,9 @@ static int ocfs2_rm_xattr_cluster(struct
1163 ocfs2_remove_xattr_clusters_from_cache(inode, blkno, len);
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);
1170 + ocfs2_put_extent_tree(&et);
1174 @@ -4390,8 +4392,8 @@ static int ocfs2_rm_xattr_cluster(struct
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,
1185 @@ -4421,6 +4423,7 @@ out:
1187 ocfs2_run_deallocs(osb, &dealloc);
1189 + ocfs2_put_extent_tree(&et);