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 Index: linux-2.6.26/fs/ocfs2/alloc.c
37 ===================================================================
38 --- linux-2.6.26.orig/fs/ocfs2/alloc.c
39 +++ linux-2.6.26/fs/ocfs2/alloc.c
42 #include "buffer_head_io.h"
45 - * ocfs2_extent_tree and ocfs2_extent_tree_operations are used to abstract
46 - * the b-tree operations in ocfs2. Now all the b-tree operations are not
47 - * limited to ocfs2_dinode only. Any data which need to allocate clusters
48 - * to store can use b-tree. And it only needs to implement its ocfs2_extent_tree
51 - * ocfs2_extent_tree contains info for the root of the b-tree, it must have a
52 - * root ocfs2_extent_list and a root_bh so that they can be used in the b-tree
54 - * ocfs2_extent_tree_operations abstract the normal operations we do for
55 - * the root of extent b-tree.
57 -struct ocfs2_extent_tree;
59 struct ocfs2_extent_tree_operations {
60 void (*eo_set_last_eb_blk)(struct ocfs2_extent_tree *et,
61 @@ -83,28 +69,38 @@ struct ocfs2_extent_tree_operations {
62 struct ocfs2_extent_tree *et);
65 -struct ocfs2_extent_tree {
66 - enum ocfs2_extent_tree_type et_type;
67 - struct ocfs2_extent_tree_operations *et_ops;
68 - struct buffer_head *et_root_bh;
69 - struct ocfs2_extent_list *et_root_el;
71 - unsigned int et_max_leaf_clusters;
74 -static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et)
76 - struct ocfs2_dinode *di = et->et_object;
78 - et->et_root_el = &di->id2.i_list;
81 + * Pre-declare ocfs2_dinode_et_ops so we can use it as a sanity check
84 +static u64 ocfs2_dinode_get_last_eb_blk(struct ocfs2_extent_tree *et);
85 +static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et,
87 +static void ocfs2_dinode_update_clusters(struct inode *inode,
88 + struct ocfs2_extent_tree *et,
90 +static int ocfs2_dinode_insert_check(struct inode *inode,
91 + struct ocfs2_extent_tree *et,
92 + struct ocfs2_extent_rec *rec);
93 +static int ocfs2_dinode_sanity_check(struct inode *inode,
94 + struct ocfs2_extent_tree *et);
95 +static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et);
96 +static struct ocfs2_extent_tree_operations ocfs2_dinode_et_ops = {
97 + .eo_set_last_eb_blk = ocfs2_dinode_set_last_eb_blk,
98 + .eo_get_last_eb_blk = ocfs2_dinode_get_last_eb_blk,
99 + .eo_update_clusters = ocfs2_dinode_update_clusters,
100 + .eo_insert_check = ocfs2_dinode_insert_check,
101 + .eo_sanity_check = ocfs2_dinode_sanity_check,
102 + .eo_fill_root_el = ocfs2_dinode_fill_root_el,
105 static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et,
108 struct ocfs2_dinode *di = et->et_object;
110 - BUG_ON(et->et_type != OCFS2_DINODE_EXTENT);
111 + BUG_ON(et->et_ops != &ocfs2_dinode_et_ops);
112 di->i_last_eb_blk = cpu_to_le64(blkno);
115 @@ -112,7 +108,7 @@ static u64 ocfs2_dinode_get_last_eb_blk(
117 struct ocfs2_dinode *di = et->et_object;
119 - BUG_ON(et->et_type != OCFS2_DINODE_EXTENT);
120 + BUG_ON(et->et_ops != &ocfs2_dinode_et_ops);
121 return le64_to_cpu(di->i_last_eb_blk);
124 @@ -153,7 +149,7 @@ static int ocfs2_dinode_sanity_check(str
126 struct ocfs2_dinode *di;
128 - BUG_ON(et->et_type != OCFS2_DINODE_EXTENT);
129 + BUG_ON(et->et_ops != &ocfs2_dinode_et_ops);
132 if (!OCFS2_IS_VALID_DINODE(di)) {
133 @@ -166,14 +162,13 @@ static int ocfs2_dinode_sanity_check(str
137 -static struct ocfs2_extent_tree_operations ocfs2_dinode_et_ops = {
138 - .eo_set_last_eb_blk = ocfs2_dinode_set_last_eb_blk,
139 - .eo_get_last_eb_blk = ocfs2_dinode_get_last_eb_blk,
140 - .eo_update_clusters = ocfs2_dinode_update_clusters,
141 - .eo_insert_check = ocfs2_dinode_insert_check,
142 - .eo_sanity_check = ocfs2_dinode_sanity_check,
143 - .eo_fill_root_el = ocfs2_dinode_fill_root_el,
145 +static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et)
147 + struct ocfs2_dinode *di = et->et_object;
149 + et->et_root_el = &di->id2.i_list;
153 static void ocfs2_xattr_value_fill_root_el(struct ocfs2_extent_tree *et)
155 @@ -269,10 +264,8 @@ static void __ocfs2_get_extent_tree(stru
157 struct buffer_head *bh,
159 - enum ocfs2_extent_tree_type et_type,
160 struct ocfs2_extent_tree_operations *ops)
162 - et->et_type = et_type;
166 @@ -287,50 +280,31 @@ static void __ocfs2_get_extent_tree(stru
167 et->et_ops->eo_fill_max_leaf_clusters(inode, et);
170 -static void ocfs2_get_dinode_extent_tree(struct ocfs2_extent_tree *et,
171 - struct inode *inode,
172 - struct buffer_head *bh)
173 +void ocfs2_get_dinode_extent_tree(struct ocfs2_extent_tree *et,
174 + struct inode *inode,
175 + struct buffer_head *bh)
177 - __ocfs2_get_extent_tree(et, inode, bh, NULL, OCFS2_DINODE_EXTENT,
178 - &ocfs2_dinode_et_ops);
179 + __ocfs2_get_extent_tree(et, inode, bh, NULL, &ocfs2_dinode_et_ops);
182 -static void ocfs2_get_xattr_tree_extent_tree(struct ocfs2_extent_tree *et,
183 - struct inode *inode,
184 - struct buffer_head *bh)
185 +void ocfs2_get_xattr_tree_extent_tree(struct ocfs2_extent_tree *et,
186 + struct inode *inode,
187 + struct buffer_head *bh)
189 __ocfs2_get_extent_tree(et, inode, bh, NULL,
190 - OCFS2_XATTR_TREE_EXTENT,
191 &ocfs2_xattr_tree_et_ops);
194 -static void ocfs2_get_xattr_value_extent_tree(struct ocfs2_extent_tree *et,
195 - struct inode *inode,
196 - struct buffer_head *bh,
197 - struct ocfs2_xattr_value_root *xv)
198 +void ocfs2_get_xattr_value_extent_tree(struct ocfs2_extent_tree *et,
199 + struct inode *inode,
200 + struct buffer_head *bh,
201 + struct ocfs2_xattr_value_root *xv)
203 __ocfs2_get_extent_tree(et, inode, bh, xv,
204 - OCFS2_XATTR_VALUE_EXTENT,
205 &ocfs2_xattr_value_et_ops);
208 -static void ocfs2_get_extent_tree(struct ocfs2_extent_tree *et,
209 - struct inode *inode,
210 - struct buffer_head *bh,
211 - enum ocfs2_extent_tree_type et_type,
214 - if (et_type == OCFS2_DINODE_EXTENT)
215 - ocfs2_get_dinode_extent_tree(et, inode, bh);
216 - else if (et_type == OCFS2_XATTR_VALUE_EXTENT)
217 - ocfs2_get_xattr_tree_extent_tree(et, inode, bh);
218 - else if (et_type == OCFS2_XATTR_TREE_EXTENT)
219 - ocfs2_get_xattr_value_extent_tree(et, inode, bh, obj);
224 -static void ocfs2_put_extent_tree(struct ocfs2_extent_tree *et)
225 +void ocfs2_put_extent_tree(struct ocfs2_extent_tree *et)
227 brelse(et->et_root_bh);
229 @@ -682,22 +656,18 @@ struct ocfs2_merge_ctxt {
231 int ocfs2_num_free_extents(struct ocfs2_super *osb,
233 - struct buffer_head *root_bh,
234 - enum ocfs2_extent_tree_type type,
236 + struct ocfs2_extent_tree *et)
239 struct ocfs2_extent_list *el = NULL;
240 struct ocfs2_extent_block *eb;
241 struct buffer_head *eb_bh = NULL;
243 - struct ocfs2_extent_tree et;
247 - ocfs2_get_extent_tree(&et, inode, root_bh, type, obj);
248 - el = et.et_root_el;
249 - last_eb_blk = ocfs2_et_get_last_eb_blk(&et);
250 + el = et->et_root_el;
251 + last_eb_blk = ocfs2_et_get_last_eb_blk(et);
254 retval = ocfs2_read_block(osb, last_eb_blk,
255 @@ -717,7 +687,6 @@ bail:
259 - ocfs2_put_extent_tree(&et);
263 @@ -4415,16 +4384,15 @@ out:
265 * The caller needs to update fe->i_clusters
267 -static int ocfs2_insert_extent(struct ocfs2_super *osb,
269 - struct inode *inode,
270 - struct buffer_head *root_bh,
275 - struct ocfs2_alloc_context *meta_ac,
276 - struct ocfs2_extent_tree *et)
277 +int ocfs2_insert_extent(struct ocfs2_super *osb,
279 + struct inode *inode,
280 + struct ocfs2_extent_tree *et,
285 + struct ocfs2_alloc_context *meta_ac)
288 int uninitialized_var(free_records);
289 @@ -4473,7 +4441,7 @@ static int ocfs2_insert_extent(struct oc
290 status = ocfs2_do_insert_extent(inode, handle, et, &rec, &insert);
293 - else if (et->et_type == OCFS2_DINODE_EXTENT)
294 + else if (et->et_ops == &ocfs2_dinode_et_ops)
295 ocfs2_extent_map_insert_rec(inode, &rec);
298 @@ -4484,77 +4452,10 @@ bail:
302 -int ocfs2_dinode_insert_extent(struct ocfs2_super *osb,
304 - struct inode *inode,
305 - struct buffer_head *root_bh,
310 - struct ocfs2_alloc_context *meta_ac)
313 - struct ocfs2_extent_tree et;
315 - ocfs2_get_dinode_extent_tree(&et, inode, root_bh);
316 - status = ocfs2_insert_extent(osb, handle, inode, root_bh,
317 - cpos, start_blk, new_clusters,
318 - flags, meta_ac, &et);
319 - ocfs2_put_extent_tree(&et);
324 -int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb,
326 - struct inode *inode,
327 - struct buffer_head *root_bh,
332 - struct ocfs2_alloc_context *meta_ac,
333 - struct ocfs2_xattr_value_root *xv)
336 - struct ocfs2_extent_tree et;
338 - ocfs2_get_xattr_value_extent_tree(&et, inode, root_bh, xv);
339 - status = ocfs2_insert_extent(osb, handle, inode, root_bh,
340 - cpos, start_blk, new_clusters,
341 - flags, meta_ac, &et);
342 - ocfs2_put_extent_tree(&et);
347 -int ocfs2_xattr_tree_insert_extent(struct ocfs2_super *osb,
349 - struct inode *inode,
350 - struct buffer_head *root_bh,
355 - struct ocfs2_alloc_context *meta_ac)
358 - struct ocfs2_extent_tree et;
360 - ocfs2_get_xattr_tree_extent_tree(&et, inode, root_bh);
361 - status = ocfs2_insert_extent(osb, handle, inode, root_bh,
362 - cpos, start_blk, new_clusters,
363 - flags, meta_ac, &et);
364 - ocfs2_put_extent_tree(&et);
370 * Allcate and add clusters into the extent b-tree.
371 * The new clusters(clusters_to_add) will be inserted at logical_offset.
372 - * The extent b-tree's root is root_el and it should be in root_bh, and
373 + * The extent b-tree's root is specified by et, and
374 * it is not limited to the file storage. Any extent tree can use this
375 * function if it implements the proper ocfs2_extent_tree.
377 @@ -4563,14 +4464,11 @@ int ocfs2_add_clusters_in_btree(struct o
381 - struct buffer_head *root_bh,
382 - struct ocfs2_extent_list *root_el,
383 + struct ocfs2_extent_tree *et,
385 struct ocfs2_alloc_context *data_ac,
386 struct ocfs2_alloc_context *meta_ac,
387 - enum ocfs2_alloc_restarted *reason_ret,
388 - enum ocfs2_extent_tree_type type,
390 + enum ocfs2_alloc_restarted *reason_ret)
394 @@ -4584,8 +4482,7 @@ int ocfs2_add_clusters_in_btree(struct o
396 flags = OCFS2_EXT_UNWRITTEN;
398 - free_extents = ocfs2_num_free_extents(osb, inode, root_bh, type,
400 + free_extents = ocfs2_num_free_extents(osb, inode, et);
401 if (free_extents < 0) {
402 status = free_extents;
404 @@ -4604,7 +4501,7 @@ int ocfs2_add_clusters_in_btree(struct o
406 } else if ((!free_extents)
407 && (ocfs2_alloc_context_bits_left(meta_ac)
408 - < ocfs2_extend_meta_needed(root_el))) {
409 + < ocfs2_extend_meta_needed(et->et_root_el))) {
410 mlog(0, "filesystem is really fragmented...\n");
412 reason = RESTART_META;
413 @@ -4622,7 +4519,7 @@ int ocfs2_add_clusters_in_btree(struct o
414 BUG_ON(num_bits > clusters_to_add);
416 /* reserve our write early -- insert_extent may update the inode */
417 - status = ocfs2_journal_access(handle, inode, root_bh,
418 + status = ocfs2_journal_access(handle, inode, et->et_root_bh,
419 OCFS2_JOURNAL_ACCESS_WRITE);
422 @@ -4632,28 +4529,15 @@ int ocfs2_add_clusters_in_btree(struct o
423 block = ocfs2_clusters_to_blocks(osb->sb, bit_off);
424 mlog(0, "Allocating %u clusters at block %u for inode %llu\n",
425 num_bits, bit_off, (unsigned long long)OCFS2_I(inode)->ip_blkno);
426 - if (type == OCFS2_DINODE_EXTENT)
427 - status = ocfs2_dinode_insert_extent(osb, handle, inode, root_bh,
428 - *logical_offset, block,
429 - num_bits, flags, meta_ac);
430 - else if (type == OCFS2_XATTR_TREE_EXTENT)
431 - status = ocfs2_xattr_tree_insert_extent(osb, handle,
434 - block, num_bits, flags,
437 - status = ocfs2_xattr_value_insert_extent(osb, handle,
440 - block, num_bits, flags,
442 + status = ocfs2_insert_extent(osb, handle, inode, et,
443 + *logical_offset, block,
444 + num_bits, flags, meta_ac);
450 - status = ocfs2_journal_dirty(handle, root_bh);
451 + status = ocfs2_journal_dirty(handle, et->et_root_bh);
455 @@ -4924,25 +4808,21 @@ out:
457 * The caller is responsible for passing down meta_ac if we'll need it.
459 -int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
460 +int ocfs2_mark_extent_written(struct inode *inode,
461 + struct ocfs2_extent_tree *et,
462 handle_t *handle, u32 cpos, u32 len, u32 phys,
463 struct ocfs2_alloc_context *meta_ac,
464 - struct ocfs2_cached_dealloc_ctxt *dealloc,
465 - enum ocfs2_extent_tree_type et_type,
467 + struct ocfs2_cached_dealloc_ctxt *dealloc)
470 u64 start_blkno = ocfs2_clusters_to_blocks(inode->i_sb, phys);
471 struct ocfs2_extent_rec split_rec;
472 struct ocfs2_path *left_path = NULL;
473 struct ocfs2_extent_list *el;
474 - struct ocfs2_extent_tree et;
476 mlog(0, "Inode %lu cpos %u, len %u, phys %u (%llu)\n",
477 inode->i_ino, cpos, len, phys, (unsigned long long)start_blkno);
479 - ocfs2_get_extent_tree(&et, inode, root_bh, et_type, obj);
481 if (!ocfs2_writes_unwritten_extents(OCFS2_SB(inode->i_sb))) {
482 ocfs2_error(inode->i_sb, "Inode %llu has unwritten extents "
483 "that are being written to, but the feature bit "
484 @@ -4955,11 +4835,14 @@ int ocfs2_mark_extent_written(struct ino
486 * XXX: This should be fixed up so that we just re-insert the
487 * next extent records.
489 + * XXX: This is a hack on the extent tree, maybe it should be
492 - if (et_type == OCFS2_DINODE_EXTENT)
493 + if (et->et_ops == &ocfs2_dinode_et_ops)
494 ocfs2_extent_map_trunc(inode, 0);
496 - left_path = ocfs2_new_path(et.et_root_bh, et.et_root_el);
497 + left_path = ocfs2_new_path(et->et_root_bh, et->et_root_el);
501 @@ -4990,7 +4873,7 @@ int ocfs2_mark_extent_written(struct ino
502 split_rec.e_flags = path_leaf_el(left_path)->l_recs[index].e_flags;
503 split_rec.e_flags &= ~OCFS2_EXT_UNWRITTEN;
505 - ret = __ocfs2_mark_extent_written(inode, &et, handle, left_path,
506 + ret = __ocfs2_mark_extent_written(inode, et, handle, left_path,
507 index, &split_rec, meta_ac,
510 @@ -4998,7 +4881,6 @@ int ocfs2_mark_extent_written(struct ino
513 ocfs2_free_path(left_path);
514 - ocfs2_put_extent_tree(&et);
518 @@ -5228,25 +5110,21 @@ out:
522 -int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
523 +int ocfs2_remove_extent(struct inode *inode,
524 + struct ocfs2_extent_tree *et,
525 u32 cpos, u32 len, handle_t *handle,
526 struct ocfs2_alloc_context *meta_ac,
527 - struct ocfs2_cached_dealloc_ctxt *dealloc,
528 - enum ocfs2_extent_tree_type et_type,
530 + struct ocfs2_cached_dealloc_ctxt *dealloc)
533 u32 rec_range, trunc_range;
534 struct ocfs2_extent_rec *rec;
535 struct ocfs2_extent_list *el;
536 struct ocfs2_path *path = NULL;
537 - struct ocfs2_extent_tree et;
539 - ocfs2_get_extent_tree(&et, inode, root_bh, et_type, obj);
541 ocfs2_extent_map_trunc(inode, 0);
543 - path = ocfs2_new_path(et.et_root_bh, et.et_root_el);
544 + path = ocfs2_new_path(et->et_root_bh, et->et_root_el);
548 @@ -5299,13 +5177,13 @@ int ocfs2_remove_extent(struct inode *in
550 if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) {
551 ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc,
559 - ret = ocfs2_split_tree(inode, &et, handle, path, index,
560 + ret = ocfs2_split_tree(inode, et, handle, path, index,
561 trunc_range, meta_ac);
564 @@ -5354,7 +5232,7 @@ int ocfs2_remove_extent(struct inode *in
567 ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc,
573 @@ -5363,7 +5241,6 @@ int ocfs2_remove_extent(struct inode *in
576 ocfs2_free_path(path);
577 - ocfs2_put_extent_tree(&et);
581 @@ -6782,6 +6659,7 @@ int ocfs2_convert_inline_data_to_extents
582 struct ocfs2_alloc_context *data_ac = NULL;
583 struct page **pages = NULL;
584 loff_t end = osb->s_clustersize;
585 + struct ocfs2_extent_tree et;
587 has_data = i_size_read(inode) ? 1 : 0;
589 @@ -6881,8 +6759,10 @@ int ocfs2_convert_inline_data_to_extents
590 * this proves to be false, we could always re-build
591 * the in-inode data from our pages.
593 - ret = ocfs2_dinode_insert_extent(osb, handle, inode, di_bh,
594 - 0, block, 1, 0, NULL);
595 + ocfs2_get_dinode_extent_tree(&et, inode, di_bh);
596 + ret = ocfs2_insert_extent(osb, handle, inode, &et,
597 + 0, block, 1, 0, NULL);
598 + ocfs2_put_extent_tree(&et);
602 Index: linux-2.6.26/fs/ocfs2/alloc.h
603 ===================================================================
604 --- linux-2.6.26.orig/fs/ocfs2/alloc.h
605 +++ linux-2.6.26/fs/ocfs2/alloc.h
607 #ifndef OCFS2_ALLOC_H
608 #define OCFS2_ALLOC_H
610 -enum ocfs2_extent_tree_type {
611 - OCFS2_DINODE_EXTENT = 0,
612 - OCFS2_XATTR_VALUE_EXTENT,
613 - OCFS2_XATTR_TREE_EXTENT,
617 * For xattr tree leaf, we limit the leaf byte size to be 64K.
619 #define OCFS2_MAX_XATTR_TREE_LEAF_SIZE 65536
622 + * ocfs2_extent_tree and ocfs2_extent_tree_operations are used to abstract
623 + * the b-tree operations in ocfs2. Now all the b-tree operations are not
624 + * limited to ocfs2_dinode only. Any data which need to allocate clusters
625 + * to store can use b-tree. And it only needs to implement its ocfs2_extent_tree
628 + * ocfs2_extent_tree becomes the first-class object for extent tree
629 + * manipulation. Callers of the alloc.c code need to fill it via one of
630 + * the ocfs2_get_*_extent_tree() operations below.
632 + * ocfs2_extent_tree contains info for the root of the b-tree, it must have a
633 + * root ocfs2_extent_list and a root_bh so that they can be used in the b-tree
635 + * ocfs2_extent_tree_operations abstract the normal operations we do for
636 + * the root of extent b-tree.
638 +struct ocfs2_extent_tree_operations;
639 +struct ocfs2_extent_tree {
640 + struct ocfs2_extent_tree_operations *et_ops;
641 + struct buffer_head *et_root_bh;
642 + struct ocfs2_extent_list *et_root_el;
644 + unsigned int et_max_leaf_clusters;
648 + * ocfs2_*_get_extent_tree() will fill an ocfs2_extent_tree from the
649 + * specified object buffer. The bh is referenced until
650 + * ocfs2_put_extent_tree().
652 +void ocfs2_get_dinode_extent_tree(struct ocfs2_extent_tree *et,
653 + struct inode *inode,
654 + struct buffer_head *bh);
655 +void ocfs2_get_xattr_tree_extent_tree(struct ocfs2_extent_tree *et,
656 + struct inode *inode,
657 + struct buffer_head *bh);
658 +void ocfs2_get_xattr_value_extent_tree(struct ocfs2_extent_tree *et,
659 + struct inode *inode,
660 + struct buffer_head *bh,
661 + struct ocfs2_xattr_value_root *xv);
662 +void ocfs2_put_extent_tree(struct ocfs2_extent_tree *et);
664 struct ocfs2_alloc_context;
665 -int ocfs2_dinode_insert_extent(struct ocfs2_super *osb,
667 - struct inode *inode,
668 - struct buffer_head *root_bh,
673 - struct ocfs2_alloc_context *meta_ac);
674 -int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb,
676 - struct inode *inode,
677 - struct buffer_head *root_bh,
682 - struct ocfs2_alloc_context *meta_ac,
683 - struct ocfs2_xattr_value_root *xv);
684 -int ocfs2_xattr_tree_insert_extent(struct ocfs2_super *osb,
686 - struct inode *inode,
687 - struct buffer_head *root_bh,
692 - struct ocfs2_alloc_context *meta_ac);
693 +int ocfs2_insert_extent(struct ocfs2_super *osb,
695 + struct inode *inode,
696 + struct ocfs2_extent_tree *et,
701 + struct ocfs2_alloc_context *meta_ac);
703 enum ocfs2_alloc_restarted {
706 @@ -76,32 +96,25 @@ int ocfs2_add_clusters_in_btree(struct o
710 - struct buffer_head *root_bh,
711 - struct ocfs2_extent_list *root_el,
712 + struct ocfs2_extent_tree *et,
714 struct ocfs2_alloc_context *data_ac,
715 struct ocfs2_alloc_context *meta_ac,
716 - enum ocfs2_alloc_restarted *reason_ret,
717 - enum ocfs2_extent_tree_type type,
719 + enum ocfs2_alloc_restarted *reason_ret);
720 struct ocfs2_cached_dealloc_ctxt;
721 -int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
722 +int ocfs2_mark_extent_written(struct inode *inode,
723 + struct ocfs2_extent_tree *et,
724 handle_t *handle, u32 cpos, u32 len, u32 phys,
725 struct ocfs2_alloc_context *meta_ac,
726 - struct ocfs2_cached_dealloc_ctxt *dealloc,
727 - enum ocfs2_extent_tree_type et_type,
729 -int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
730 + struct ocfs2_cached_dealloc_ctxt *dealloc);
731 +int ocfs2_remove_extent(struct inode *inode,
732 + struct ocfs2_extent_tree *et,
733 u32 cpos, u32 len, handle_t *handle,
734 struct ocfs2_alloc_context *meta_ac,
735 - struct ocfs2_cached_dealloc_ctxt *dealloc,
736 - enum ocfs2_extent_tree_type et_type,
738 + struct ocfs2_cached_dealloc_ctxt *dealloc);
739 int ocfs2_num_free_extents(struct ocfs2_super *osb,
741 - struct buffer_head *root_bh,
742 - enum ocfs2_extent_tree_type et_type,
744 + struct ocfs2_extent_tree *et);
747 * how many new metadata chunks would an allocation need at maximum?
748 Index: linux-2.6.26/fs/ocfs2/aops.c
749 ===================================================================
750 --- linux-2.6.26.orig/fs/ocfs2/aops.c
751 +++ linux-2.6.26/fs/ocfs2/aops.c
752 @@ -1242,6 +1242,7 @@ static int ocfs2_write_cluster(struct ad
753 int ret, i, new, should_zero = 0;
754 u64 v_blkno, p_blkno;
755 struct inode *inode = mapping->host;
756 + struct ocfs2_extent_tree et;
758 new = phys == 0 ? 1 : 0;
759 if (new || unwritten)
760 @@ -1276,10 +1277,11 @@ static int ocfs2_write_cluster(struct ad
763 } else if (unwritten) {
764 - ret = ocfs2_mark_extent_written(inode, wc->w_di_bh,
765 + ocfs2_get_dinode_extent_tree(&et, inode, wc->w_di_bh);
766 + ret = ocfs2_mark_extent_written(inode, &et,
767 wc->w_handle, cpos, 1, phys,
768 - meta_ac, &wc->w_dealloc,
769 - OCFS2_DINODE_EXTENT, NULL);
770 + meta_ac, &wc->w_dealloc);
771 + ocfs2_put_extent_tree(&et);
775 @@ -1666,6 +1668,7 @@ int ocfs2_write_begin_nolock(struct addr
776 struct ocfs2_alloc_context *data_ac = NULL;
777 struct ocfs2_alloc_context *meta_ac = NULL;
779 + struct ocfs2_extent_tree et;
781 ret = ocfs2_alloc_write_ctxt(&wc, osb, pos, len, di_bh);
783 @@ -1719,10 +1722,11 @@ int ocfs2_write_begin_nolock(struct addr
784 (long long)i_size_read(inode), le32_to_cpu(di->i_clusters),
785 clusters_to_alloc, extents_to_split);
787 - ret = ocfs2_lock_allocators(inode, wc->w_di_bh, &di->id2.i_list,
788 + ocfs2_get_dinode_extent_tree(&et, inode, wc->w_di_bh);
789 + ret = ocfs2_lock_allocators(inode, &et,
790 clusters_to_alloc, extents_to_split,
791 - &data_ac, &meta_ac,
792 - OCFS2_DINODE_EXTENT, NULL);
793 + &data_ac, &meta_ac);
794 + ocfs2_put_extent_tree(&et);
798 Index: linux-2.6.26/fs/ocfs2/dir.c
799 ===================================================================
800 --- linux-2.6.26.orig/fs/ocfs2/dir.c
801 +++ linux-2.6.26/fs/ocfs2/dir.c
802 @@ -1192,6 +1192,9 @@ static int ocfs2_expand_inline_dir(struc
803 struct buffer_head *dirdata_bh = NULL;
804 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
806 + struct ocfs2_extent_tree et;
808 + ocfs2_get_dinode_extent_tree(&et, dir, di_bh);
810 alloc = ocfs2_clusters_for_bytes(sb, bytes);
812 @@ -1305,8 +1308,8 @@ static int ocfs2_expand_inline_dir(struc
813 * This should never fail as our extent list is empty and all
814 * related blocks have been journaled already.
816 - ret = ocfs2_dinode_insert_extent(osb, handle, dir, di_bh, 0, blkno,
818 + ret = ocfs2_insert_extent(osb, handle, dir, &et, 0, blkno, len,
823 @@ -1337,8 +1340,8 @@ static int ocfs2_expand_inline_dir(struc
825 blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off);
827 - ret = ocfs2_dinode_insert_extent(osb, handle, dir, di_bh, 1,
828 - blkno, len, 0, NULL);
829 + ret = ocfs2_insert_extent(osb, handle, dir, &et, 1,
830 + blkno, len, 0, NULL);
834 @@ -1360,6 +1363,7 @@ out:
838 + ocfs2_put_extent_tree(&et);
842 @@ -1437,6 +1441,7 @@ static int ocfs2_extend_dir(struct ocfs2
843 struct buffer_head *new_bh = NULL;
844 struct ocfs2_dir_entry * de;
845 struct super_block *sb = osb->sb;
846 + struct ocfs2_extent_tree et;
850 @@ -1480,10 +1485,9 @@ static int ocfs2_extend_dir(struct ocfs2
851 spin_lock(&OCFS2_I(dir)->ip_lock);
852 if (dir_i_size == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)) {
853 spin_unlock(&OCFS2_I(dir)->ip_lock);
854 - num_free_extents = ocfs2_num_free_extents(osb, dir,
856 - OCFS2_DINODE_EXTENT,
858 + ocfs2_get_dinode_extent_tree(&et, dir, parent_fe_bh);
859 + num_free_extents = ocfs2_num_free_extents(osb, dir, &et);
860 + ocfs2_put_extent_tree(&et);
861 if (num_free_extents < 0) {
862 status = num_free_extents;
864 Index: linux-2.6.26/fs/ocfs2/file.c
865 ===================================================================
866 --- linux-2.6.26.orig/fs/ocfs2/file.c
867 +++ linux-2.6.26/fs/ocfs2/file.c
868 @@ -509,14 +509,17 @@ int ocfs2_add_inode_data(struct ocfs2_su
869 struct ocfs2_alloc_context *meta_ac,
870 enum ocfs2_alloc_restarted *reason_ret)
872 - struct ocfs2_dinode *fe = (struct ocfs2_dinode *) fe_bh->b_data;
873 - struct ocfs2_extent_list *el = &fe->id2.i_list;
875 + struct ocfs2_extent_tree et;
877 - return ocfs2_add_clusters_in_btree(osb, inode, logical_offset,
878 + ocfs2_get_dinode_extent_tree(&et, inode, fe_bh);
879 + ret = ocfs2_add_clusters_in_btree(osb, inode, logical_offset,
880 clusters_to_add, mark_unwritten,
882 - data_ac, meta_ac, reason_ret,
883 - OCFS2_DINODE_EXTENT, NULL);
885 + data_ac, meta_ac, reason_ret);
886 + ocfs2_put_extent_tree(&et);
891 static int __ocfs2_extend_allocation(struct inode *inode, u32 logical_start,
892 @@ -533,6 +536,7 @@ static int __ocfs2_extend_allocation(str
893 struct ocfs2_alloc_context *meta_ac = NULL;
894 enum ocfs2_alloc_restarted why;
895 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
896 + struct ocfs2_extent_tree et;
898 mlog_entry("(clusters_to_add = %u)\n", clusters_to_add);
900 @@ -564,9 +568,10 @@ restart_all:
901 (unsigned long long)OCFS2_I(inode)->ip_blkno,
902 (long long)i_size_read(inode), le32_to_cpu(fe->i_clusters),
904 - status = ocfs2_lock_allocators(inode, bh, &fe->id2.i_list,
905 - clusters_to_add, 0, &data_ac,
906 - &meta_ac, OCFS2_DINODE_EXTENT, NULL);
907 + ocfs2_get_dinode_extent_tree(&et, inode, bh);
908 + status = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0,
909 + &data_ac, &meta_ac);
910 + ocfs2_put_extent_tree(&et);
914 @@ -1236,11 +1241,13 @@ static int __ocfs2_remove_inode_range(st
916 struct ocfs2_alloc_context *meta_ac = NULL;
917 struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
918 + struct ocfs2_extent_tree et;
920 + ocfs2_get_dinode_extent_tree(&et, inode, di_bh);
922 - ret = ocfs2_lock_allocators(inode, di_bh, &di->id2.i_list,
923 - 0, 1, NULL, &meta_ac,
924 - OCFS2_DINODE_EXTENT, NULL);
925 + ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac);
927 + ocfs2_put_extent_tree(&et);
931 @@ -1269,8 +1276,8 @@ static int __ocfs2_remove_inode_range(st
935 - ret = ocfs2_remove_extent(inode, di_bh, cpos, len, handle, meta_ac,
936 - dealloc, OCFS2_DINODE_EXTENT, NULL);
937 + ret = ocfs2_remove_extent(inode, &et, cpos, len, handle, meta_ac,
942 @@ -1297,6 +1304,7 @@ out:
944 ocfs2_free_alloc_context(meta_ac);
946 + ocfs2_put_extent_tree(&et);
950 Index: linux-2.6.26/fs/ocfs2/suballoc.c
951 ===================================================================
952 --- linux-2.6.26.orig/fs/ocfs2/suballoc.c
953 +++ linux-2.6.26/fs/ocfs2/suballoc.c
954 @@ -1911,12 +1911,11 @@ static inline void ocfs2_debug_suballoc_
955 * File systems which don't support holes call this from
956 * ocfs2_extend_allocation().
958 -int ocfs2_lock_allocators(struct inode *inode, struct buffer_head *root_bh,
959 - struct ocfs2_extent_list *root_el,
960 +int ocfs2_lock_allocators(struct inode *inode,
961 + struct ocfs2_extent_tree *et,
962 u32 clusters_to_add, u32 extents_to_split,
963 struct ocfs2_alloc_context **data_ac,
964 - struct ocfs2_alloc_context **meta_ac,
965 - enum ocfs2_extent_tree_type type, void *private)
966 + struct ocfs2_alloc_context **meta_ac)
968 int ret = 0, num_free_extents;
969 unsigned int max_recs_needed = clusters_to_add + 2 * extents_to_split;
970 @@ -1928,8 +1927,7 @@ int ocfs2_lock_allocators(struct inode *
972 BUG_ON(clusters_to_add != 0 && data_ac == NULL);
974 - num_free_extents = ocfs2_num_free_extents(osb, inode, root_bh,
976 + num_free_extents = ocfs2_num_free_extents(osb, inode, et);
977 if (num_free_extents < 0) {
978 ret = num_free_extents;
980 @@ -1951,7 +1949,7 @@ int ocfs2_lock_allocators(struct inode *
982 if (!num_free_extents ||
983 (ocfs2_sparse_alloc(osb) && num_free_extents < max_recs_needed)) {
984 - ret = ocfs2_reserve_new_metadata(osb, root_el, meta_ac);
985 + ret = ocfs2_reserve_new_metadata(osb, et->et_root_el, meta_ac);
989 Index: linux-2.6.26/fs/ocfs2/suballoc.h
990 ===================================================================
991 --- linux-2.6.26.orig/fs/ocfs2/suballoc.h
992 +++ linux-2.6.26/fs/ocfs2/suballoc.h
993 @@ -164,10 +164,8 @@ u64 ocfs2_which_cluster_group(struct ino
994 int ocfs2_check_group_descriptor(struct super_block *sb,
995 struct ocfs2_dinode *di,
996 struct ocfs2_group_desc *gd);
997 -int ocfs2_lock_allocators(struct inode *inode, struct buffer_head *root_bh,
998 - struct ocfs2_extent_list *root_el,
999 +int ocfs2_lock_allocators(struct inode *inode, struct ocfs2_extent_tree *et,
1000 u32 clusters_to_add, u32 extents_to_split,
1001 struct ocfs2_alloc_context **data_ac,
1002 - struct ocfs2_alloc_context **meta_ac,
1003 - enum ocfs2_extent_tree_type type, void *private);
1004 + struct ocfs2_alloc_context **meta_ac);
1005 #endif /* _CHAINALLOC_H_ */
1006 Index: linux-2.6.26/fs/ocfs2/xattr.c
1007 ===================================================================
1008 --- linux-2.6.26.orig/fs/ocfs2/xattr.c
1009 +++ linux-2.6.26/fs/ocfs2/xattr.c
1010 @@ -222,22 +222,24 @@ static int ocfs2_xattr_extend_allocation
1011 struct ocfs2_alloc_context *meta_ac = NULL;
1012 enum ocfs2_alloc_restarted why;
1013 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1014 - struct ocfs2_extent_list *root_el = &xv->xr_list;
1015 u32 prev_clusters, logical_start = le32_to_cpu(xv->xr_clusters);
1016 + struct ocfs2_extent_tree et;
1018 mlog(0, "(clusters_to_add for xattr= %u)\n", clusters_to_add);
1020 + ocfs2_get_xattr_value_extent_tree(&et, inode, xattr_bh, xv);
1024 - status = ocfs2_lock_allocators(inode, xattr_bh, root_el,
1025 - clusters_to_add, 0, &data_ac,
1026 - &meta_ac, OCFS2_XATTR_VALUE_EXTENT, xv);
1027 + status = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0,
1028 + &data_ac, &meta_ac);
1034 - credits = ocfs2_calc_extend_credits(osb->sb, root_el, clusters_to_add);
1035 + credits = ocfs2_calc_extend_credits(osb->sb, et.et_root_el,
1037 handle = ocfs2_start_trans(osb, credits);
1038 if (IS_ERR(handle)) {
1039 status = PTR_ERR(handle);
1040 @@ -260,14 +262,11 @@ restarted_transaction:
1051 - OCFS2_XATTR_VALUE_EXTENT,
1054 if ((status < 0) && (status != -EAGAIN)) {
1055 if (status != -ENOSPC)
1057 @@ -292,7 +291,7 @@ restarted_transaction:
1058 mlog(0, "restarting transaction.\n");
1059 /* TODO: This can be more intelligent. */
1060 credits = ocfs2_calc_extend_credits(osb->sb,
1064 status = ocfs2_extend_trans(handle, credits);
1066 @@ -324,6 +323,7 @@ leave:
1070 + ocfs2_put_extent_tree(&et);
1074 @@ -339,11 +339,13 @@ static int __ocfs2_remove_xattr_range(st
1075 struct inode *tl_inode = osb->osb_tl_inode;
1077 struct ocfs2_alloc_context *meta_ac = NULL;
1078 + struct ocfs2_extent_tree et;
1080 + ocfs2_get_xattr_value_extent_tree(&et, inode, root_bh, xv);
1082 - ret = ocfs2_lock_allocators(inode, root_bh, &xv->xr_list,
1083 - 0, 1, NULL, &meta_ac,
1084 - OCFS2_XATTR_VALUE_EXTENT, xv);
1085 + ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac);
1087 + ocfs2_put_extent_tree(&et);
1091 @@ -372,8 +374,8 @@ static int __ocfs2_remove_xattr_range(st
1095 - ret = ocfs2_remove_extent(inode, root_bh, cpos, len, handle, meta_ac,
1096 - dealloc, OCFS2_XATTR_VALUE_EXTENT, xv);
1097 + ret = ocfs2_remove_extent(inode, &et, cpos, len, handle, meta_ac,
1102 @@ -399,6 +401,7 @@ out:
1104 ocfs2_free_alloc_context(meta_ac);
1106 + ocfs2_put_extent_tree(&et);
1110 @@ -3638,26 +3641,24 @@ static int ocfs2_add_new_xattr_cluster(s
1111 struct ocfs2_alloc_context *data_ac = NULL;
1112 struct ocfs2_alloc_context *meta_ac = NULL;
1113 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1114 - struct ocfs2_xattr_block *xb =
1115 - (struct ocfs2_xattr_block *)root_bh->b_data;
1116 - struct ocfs2_xattr_tree_root *xb_root = &xb->xb_attrs.xb_root;
1117 - struct ocfs2_extent_list *root_el = &xb_root->xt_list;
1118 - enum ocfs2_extent_tree_type type = OCFS2_XATTR_TREE_EXTENT;
1119 + struct ocfs2_extent_tree et;
1121 mlog(0, "Add new xattr cluster for %llu, previous xattr hash = %u, "
1122 "previous xattr blkno = %llu\n",
1123 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1124 prev_cpos, prev_blkno);
1126 - ret = ocfs2_lock_allocators(inode, root_bh, root_el,
1127 - clusters_to_add, 0, &data_ac,
1128 - &meta_ac, type, NULL);
1129 + ocfs2_get_xattr_tree_extent_tree(&et, inode, root_bh);
1131 + ret = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0,
1132 + &data_ac, &meta_ac);
1138 - credits = ocfs2_calc_extend_credits(osb->sb, root_el, clusters_to_add);
1139 + credits = ocfs2_calc_extend_credits(osb->sb, et.et_root_el,
1141 handle = ocfs2_start_trans(osb, credits);
1142 if (IS_ERR(handle)) {
1143 ret = PTR_ERR(handle);
1144 @@ -3721,9 +3722,8 @@ static int ocfs2_add_new_xattr_cluster(s
1146 mlog(0, "Insert %u clusters at block %llu for xattr at %u\n",
1147 num_bits, block, v_start);
1148 - ret = ocfs2_xattr_tree_insert_extent(osb, handle, inode, root_bh,
1149 - v_start, block, num_bits,
1151 + ret = ocfs2_insert_extent(osb, handle, inode, &et, v_start, block,
1152 + num_bits, 0, meta_ac);
1156 @@ -3743,6 +3743,7 @@ leave:
1158 ocfs2_free_alloc_context(meta_ac);
1160 + ocfs2_put_extent_tree(&et);
1164 @@ -4347,9 +4348,11 @@ static int ocfs2_rm_xattr_cluster(struct
1166 struct ocfs2_xattr_block *xb =
1167 (struct ocfs2_xattr_block *)root_bh->b_data;
1168 - struct ocfs2_extent_list *root_el = &xb->xb_attrs.xb_root.xt_list;
1169 struct ocfs2_alloc_context *meta_ac = NULL;
1170 struct ocfs2_cached_dealloc_ctxt dealloc;
1171 + struct ocfs2_extent_tree et;
1173 + ocfs2_get_xattr_tree_extent_tree(&et, inode, root_bh);
1175 ocfs2_init_dealloc_ctxt(&dealloc);
1177 @@ -4358,10 +4361,9 @@ static int ocfs2_rm_xattr_cluster(struct
1179 ocfs2_remove_xattr_clusters_from_cache(inode, blkno, len);
1181 - ret = ocfs2_lock_allocators(inode, root_bh, root_el,
1182 - 0, 1, NULL, &meta_ac,
1183 - OCFS2_XATTR_TREE_EXTENT, NULL);
1184 + ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac);
1186 + ocfs2_put_extent_tree(&et);
1190 @@ -4390,8 +4392,8 @@ static int ocfs2_rm_xattr_cluster(struct
1194 - ret = ocfs2_remove_extent(inode, root_bh, cpos, len, handle, meta_ac,
1195 - &dealloc, OCFS2_XATTR_TREE_EXTENT, NULL);
1196 + ret = ocfs2_remove_extent(inode, &et, cpos, len, handle, meta_ac,
1201 @@ -4421,6 +4423,7 @@ out:
1203 ocfs2_run_deallocs(osb, &dealloc);
1205 + ocfs2_put_extent_tree(&et);