]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/patches/suse-2.6.27.25/patches.suse/ocfs2-Make-ocfs2_extent_tree-the-first-class-repres.patch
Updated xen patches taken from suse.
[people/pmueller/ipfire-2.x.git] / src / patches / suse-2.6.27.25 / patches.suse / ocfs2-Make-ocfs2_extent_tree-the-first-class-repres.patch
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 ---
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(-)
35
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
40 @@ -49,20 +49,6 @@
41
42 #include "buffer_head_io.h"
43
44 -/*
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
49 - * and operation.
50 - *
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
53 - * functions.
54 - * ocfs2_extent_tree_operations abstract the normal operations we do for
55 - * the root of extent b-tree.
56 - */
57 -struct ocfs2_extent_tree;
58
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);
63 };
64
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;
70 - void *et_object;
71 - unsigned int et_max_leaf_clusters;
72 -};
73
74 -static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et)
75 -{
76 - struct ocfs2_dinode *di = et->et_object;
77 -
78 - et->et_root_el = &di->id2.i_list;
79 -}
80 +/*
81 + * Pre-declare ocfs2_dinode_et_ops so we can use it as a sanity check
82 + * in the methods.
83 + */
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,
86 + u64 blkno);
87 +static void ocfs2_dinode_update_clusters(struct inode *inode,
88 + struct ocfs2_extent_tree *et,
89 + u32 clusters);
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,
103 +};
104
105 static void ocfs2_dinode_set_last_eb_blk(struct ocfs2_extent_tree *et,
106 u64 blkno)
107 {
108 struct ocfs2_dinode *di = et->et_object;
109
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);
113 }
114
115 @@ -112,7 +108,7 @@ static u64 ocfs2_dinode_get_last_eb_blk(
116 {
117 struct ocfs2_dinode *di = et->et_object;
118
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);
122 }
123
124 @@ -153,7 +149,7 @@ static int ocfs2_dinode_sanity_check(str
125 int ret = 0;
126 struct ocfs2_dinode *di;
127
128 - BUG_ON(et->et_type != OCFS2_DINODE_EXTENT);
129 + BUG_ON(et->et_ops != &ocfs2_dinode_et_ops);
130
131 di = et->et_object;
132 if (!OCFS2_IS_VALID_DINODE(di)) {
133 @@ -166,14 +162,13 @@ static int ocfs2_dinode_sanity_check(str
134 return ret;
135 }
136
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,
144 -};
145 +static void ocfs2_dinode_fill_root_el(struct ocfs2_extent_tree *et)
146 +{
147 + struct ocfs2_dinode *di = et->et_object;
148 +
149 + et->et_root_el = &di->id2.i_list;
150 +}
151 +
152
153 static void ocfs2_xattr_value_fill_root_el(struct ocfs2_extent_tree *et)
154 {
155 @@ -269,10 +264,8 @@ static void __ocfs2_get_extent_tree(stru
156 struct inode *inode,
157 struct buffer_head *bh,
158 void *obj,
159 - enum ocfs2_extent_tree_type et_type,
160 struct ocfs2_extent_tree_operations *ops)
161 {
162 - et->et_type = et_type;
163 et->et_ops = ops;
164 get_bh(bh);
165 et->et_root_bh = bh;
166 @@ -287,50 +280,31 @@ static void __ocfs2_get_extent_tree(stru
167 et->et_ops->eo_fill_max_leaf_clusters(inode, et);
168 }
169
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)
176 {
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);
180 }
181
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)
188 {
189 __ocfs2_get_extent_tree(et, inode, bh, NULL,
190 - OCFS2_XATTR_TREE_EXTENT,
191 &ocfs2_xattr_tree_et_ops);
192 }
193
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)
202 {
203 __ocfs2_get_extent_tree(et, inode, bh, xv,
204 - OCFS2_XATTR_VALUE_EXTENT,
205 &ocfs2_xattr_value_et_ops);
206 }
207
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,
212 - void *obj)
213 -{
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);
220 - else
221 - BUG();
222 -}
223 -
224 -static void ocfs2_put_extent_tree(struct ocfs2_extent_tree *et)
225 +void ocfs2_put_extent_tree(struct ocfs2_extent_tree *et)
226 {
227 brelse(et->et_root_bh);
228 }
229 @@ -682,22 +656,18 @@ struct ocfs2_merge_ctxt {
230 */
231 int ocfs2_num_free_extents(struct ocfs2_super *osb,
232 struct inode *inode,
233 - struct buffer_head *root_bh,
234 - enum ocfs2_extent_tree_type type,
235 - void *obj)
236 + struct ocfs2_extent_tree *et)
237 {
238 int retval;
239 struct ocfs2_extent_list *el = NULL;
240 struct ocfs2_extent_block *eb;
241 struct buffer_head *eb_bh = NULL;
242 u64 last_eb_blk = 0;
243 - struct ocfs2_extent_tree et;
244
245 mlog_entry_void();
246
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);
252
253 if (last_eb_blk) {
254 retval = ocfs2_read_block(osb, last_eb_blk,
255 @@ -717,7 +687,6 @@ bail:
256 if (eb_bh)
257 brelse(eb_bh);
258
259 - ocfs2_put_extent_tree(&et);
260 mlog_exit(retval);
261 return retval;
262 }
263 @@ -4415,16 +4384,15 @@ out:
264 *
265 * The caller needs to update fe->i_clusters
266 */
267 -static int ocfs2_insert_extent(struct ocfs2_super *osb,
268 - handle_t *handle,
269 - struct inode *inode,
270 - struct buffer_head *root_bh,
271 - u32 cpos,
272 - u64 start_blk,
273 - u32 new_clusters,
274 - u8 flags,
275 - struct ocfs2_alloc_context *meta_ac,
276 - struct ocfs2_extent_tree *et)
277 +int ocfs2_insert_extent(struct ocfs2_super *osb,
278 + handle_t *handle,
279 + struct inode *inode,
280 + struct ocfs2_extent_tree *et,
281 + u32 cpos,
282 + u64 start_blk,
283 + u32 new_clusters,
284 + u8 flags,
285 + struct ocfs2_alloc_context *meta_ac)
286 {
287 int status;
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);
291 if (status < 0)
292 mlog_errno(status);
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);
296
297 bail:
298 @@ -4484,77 +4452,10 @@ bail:
299 return status;
300 }
301
302 -int ocfs2_dinode_insert_extent(struct ocfs2_super *osb,
303 - handle_t *handle,
304 - struct inode *inode,
305 - struct buffer_head *root_bh,
306 - u32 cpos,
307 - u64 start_blk,
308 - u32 new_clusters,
309 - u8 flags,
310 - struct ocfs2_alloc_context *meta_ac)
311 -{
312 - int status;
313 - struct ocfs2_extent_tree et;
314 -
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);
320 -
321 - return status;
322 -}
323 -
324 -int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb,
325 - handle_t *handle,
326 - struct inode *inode,
327 - struct buffer_head *root_bh,
328 - u32 cpos,
329 - u64 start_blk,
330 - u32 new_clusters,
331 - u8 flags,
332 - struct ocfs2_alloc_context *meta_ac,
333 - struct ocfs2_xattr_value_root *xv)
334 -{
335 - int status;
336 - struct ocfs2_extent_tree et;
337 -
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);
343 -
344 - return status;
345 -}
346 -
347 -int ocfs2_xattr_tree_insert_extent(struct ocfs2_super *osb,
348 - handle_t *handle,
349 - struct inode *inode,
350 - struct buffer_head *root_bh,
351 - u32 cpos,
352 - u64 start_blk,
353 - u32 new_clusters,
354 - u8 flags,
355 - struct ocfs2_alloc_context *meta_ac)
356 -{
357 - int status;
358 - struct ocfs2_extent_tree et;
359 -
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);
365 -
366 - return status;
367 -}
368 -
369 /*
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.
376 */
377 @@ -4563,14 +4464,11 @@ int ocfs2_add_clusters_in_btree(struct o
378 u32 *logical_offset,
379 u32 clusters_to_add,
380 int mark_unwritten,
381 - struct buffer_head *root_bh,
382 - struct ocfs2_extent_list *root_el,
383 + struct ocfs2_extent_tree *et,
384 handle_t *handle,
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,
389 - void *obj)
390 + enum ocfs2_alloc_restarted *reason_ret)
391 {
392 int status = 0;
393 int free_extents;
394 @@ -4584,8 +4482,7 @@ int ocfs2_add_clusters_in_btree(struct o
395 if (mark_unwritten)
396 flags = OCFS2_EXT_UNWRITTEN;
397
398 - free_extents = ocfs2_num_free_extents(osb, inode, root_bh, type,
399 - obj);
400 + free_extents = ocfs2_num_free_extents(osb, inode, et);
401 if (free_extents < 0) {
402 status = free_extents;
403 mlog_errno(status);
404 @@ -4604,7 +4501,7 @@ int ocfs2_add_clusters_in_btree(struct o
405 goto leave;
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");
411 status = -EAGAIN;
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);
415
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);
420 if (status < 0) {
421 mlog_errno(status);
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,
432 - inode, root_bh,
433 - *logical_offset,
434 - block, num_bits, flags,
435 - meta_ac);
436 - else
437 - status = ocfs2_xattr_value_insert_extent(osb, handle,
438 - inode, root_bh,
439 - *logical_offset,
440 - block, num_bits, flags,
441 - meta_ac, obj);
442 + status = ocfs2_insert_extent(osb, handle, inode, et,
443 + *logical_offset, block,
444 + num_bits, flags, meta_ac);
445 if (status < 0) {
446 mlog_errno(status);
447 goto leave;
448 }
449
450 - status = ocfs2_journal_dirty(handle, root_bh);
451 + status = ocfs2_journal_dirty(handle, et->et_root_bh);
452 if (status < 0) {
453 mlog_errno(status);
454 goto leave;
455 @@ -4924,25 +4808,21 @@ out:
456 *
457 * The caller is responsible for passing down meta_ac if we'll need it.
458 */
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,
466 - void *obj)
467 + struct ocfs2_cached_dealloc_ctxt *dealloc)
468 {
469 int ret, index;
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;
475
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);
478
479 - ocfs2_get_extent_tree(&et, inode, root_bh, et_type, obj);
480 -
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
485 /*
486 * XXX: This should be fixed up so that we just re-insert the
487 * next extent records.
488 + *
489 + * XXX: This is a hack on the extent tree, maybe it should be
490 + * an op?
491 */
492 - if (et_type == OCFS2_DINODE_EXTENT)
493 + if (et->et_ops == &ocfs2_dinode_et_ops)
494 ocfs2_extent_map_trunc(inode, 0);
495
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);
498 if (!left_path) {
499 ret = -ENOMEM;
500 mlog_errno(ret);
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;
504
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,
508 dealloc);
509 if (ret)
510 @@ -4998,7 +4881,6 @@ int ocfs2_mark_extent_written(struct ino
511
512 out:
513 ocfs2_free_path(left_path);
514 - ocfs2_put_extent_tree(&et);
515 return ret;
516 }
517
518 @@ -5228,25 +5110,21 @@ out:
519 return ret;
520 }
521
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,
529 - void *obj)
530 + struct ocfs2_cached_dealloc_ctxt *dealloc)
531 {
532 int ret, index;
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;
538 -
539 - ocfs2_get_extent_tree(&et, inode, root_bh, et_type, obj);
540
541 ocfs2_extent_map_trunc(inode, 0);
542
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);
545 if (!path) {
546 ret = -ENOMEM;
547 mlog_errno(ret);
548 @@ -5299,13 +5177,13 @@ int ocfs2_remove_extent(struct inode *in
549
550 if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) {
551 ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc,
552 - cpos, len, &et);
553 + cpos, len, et);
554 if (ret) {
555 mlog_errno(ret);
556 goto out;
557 }
558 } else {
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);
562 if (ret) {
563 mlog_errno(ret);
564 @@ -5354,7 +5232,7 @@ int ocfs2_remove_extent(struct inode *in
565 }
566
567 ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc,
568 - cpos, len, &et);
569 + cpos, len, et);
570 if (ret) {
571 mlog_errno(ret);
572 goto out;
573 @@ -5363,7 +5241,6 @@ int ocfs2_remove_extent(struct inode *in
574
575 out:
576 ocfs2_free_path(path);
577 - ocfs2_put_extent_tree(&et);
578 return ret;
579 }
580
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;
586
587 has_data = i_size_read(inode) ? 1 : 0;
588
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.
592 */
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);
599 if (ret) {
600 mlog_errno(ret);
601 goto out_commit;
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
606 @@ -26,46 +26,66 @@
607 #ifndef OCFS2_ALLOC_H
608 #define OCFS2_ALLOC_H
609
610 -enum ocfs2_extent_tree_type {
611 - OCFS2_DINODE_EXTENT = 0,
612 - OCFS2_XATTR_VALUE_EXTENT,
613 - OCFS2_XATTR_TREE_EXTENT,
614 -};
615
616 /*
617 * For xattr tree leaf, we limit the leaf byte size to be 64K.
618 */
619 #define OCFS2_MAX_XATTR_TREE_LEAF_SIZE 65536
620
621 +/*
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
626 + * and operation.
627 + *
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.
631 + *
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
634 + * functions.
635 + * ocfs2_extent_tree_operations abstract the normal operations we do for
636 + * the root of extent b-tree.
637 + */
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;
643 + void *et_object;
644 + unsigned int et_max_leaf_clusters;
645 +};
646 +
647 +/*
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().
651 + */
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);
663 +
664 struct ocfs2_alloc_context;
665 -int ocfs2_dinode_insert_extent(struct ocfs2_super *osb,
666 - handle_t *handle,
667 - struct inode *inode,
668 - struct buffer_head *root_bh,
669 - u32 cpos,
670 - u64 start_blk,
671 - u32 new_clusters,
672 - u8 flags,
673 - struct ocfs2_alloc_context *meta_ac);
674 -int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb,
675 - handle_t *handle,
676 - struct inode *inode,
677 - struct buffer_head *root_bh,
678 - u32 cpos,
679 - u64 start_blk,
680 - u32 new_clusters,
681 - u8 flags,
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,
685 - handle_t *handle,
686 - struct inode *inode,
687 - struct buffer_head *root_bh,
688 - u32 cpos,
689 - u64 start_blk,
690 - u32 new_clusters,
691 - u8 flags,
692 - struct ocfs2_alloc_context *meta_ac);
693 +int ocfs2_insert_extent(struct ocfs2_super *osb,
694 + handle_t *handle,
695 + struct inode *inode,
696 + struct ocfs2_extent_tree *et,
697 + u32 cpos,
698 + u64 start_blk,
699 + u32 new_clusters,
700 + u8 flags,
701 + struct ocfs2_alloc_context *meta_ac);
702 +
703 enum ocfs2_alloc_restarted {
704 RESTART_NONE = 0,
705 RESTART_TRANS,
706 @@ -76,32 +96,25 @@ int ocfs2_add_clusters_in_btree(struct o
707 u32 *logical_offset,
708 u32 clusters_to_add,
709 int mark_unwritten,
710 - struct buffer_head *root_bh,
711 - struct ocfs2_extent_list *root_el,
712 + struct ocfs2_extent_tree *et,
713 handle_t *handle,
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,
718 - void *private);
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,
728 - void *private);
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,
737 - void *private);
738 + struct ocfs2_cached_dealloc_ctxt *dealloc);
739 int ocfs2_num_free_extents(struct ocfs2_super *osb,
740 struct inode *inode,
741 - struct buffer_head *root_bh,
742 - enum ocfs2_extent_tree_type et_type,
743 - void *private);
744 + struct ocfs2_extent_tree *et);
745
746 /*
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;
757
758 new = phys == 0 ? 1 : 0;
759 if (new || unwritten)
760 @@ -1276,10 +1277,11 @@ static int ocfs2_write_cluster(struct ad
761 goto out;
762 }
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);
772 if (ret < 0) {
773 mlog_errno(ret);
774 goto out;
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;
778 handle_t *handle;
779 + struct ocfs2_extent_tree et;
780
781 ret = ocfs2_alloc_write_ctxt(&wc, osb, pos, len, di_bh);
782 if (ret) {
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);
786
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);
795 if (ret) {
796 mlog_errno(ret);
797 goto out;
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;
805 handle_t *handle;
806 + struct ocfs2_extent_tree et;
807 +
808 + ocfs2_get_dinode_extent_tree(&et, dir, di_bh);
809
810 alloc = ocfs2_clusters_for_bytes(sb, bytes);
811
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.
815 */
816 - ret = ocfs2_dinode_insert_extent(osb, handle, dir, di_bh, 0, blkno,
817 - len, 0, NULL);
818 + ret = ocfs2_insert_extent(osb, handle, dir, &et, 0, blkno, len,
819 + 0, NULL);
820 if (ret) {
821 mlog_errno(ret);
822 goto out_commit;
823 @@ -1337,8 +1340,8 @@ static int ocfs2_expand_inline_dir(struc
824 }
825 blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off);
826
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);
831 if (ret) {
832 mlog_errno(ret);
833 goto out_commit;
834 @@ -1360,6 +1363,7 @@ out:
835
836 brelse(dirdata_bh);
837
838 + ocfs2_put_extent_tree(&et);
839 return ret;
840 }
841
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;
847
848 mlog_entry_void();
849
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,
855 - parent_fe_bh,
856 - OCFS2_DINODE_EXTENT,
857 - NULL);
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;
863 mlog_errno(status);
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)
871 {
872 - struct ocfs2_dinode *fe = (struct ocfs2_dinode *) fe_bh->b_data;
873 - struct ocfs2_extent_list *el = &fe->id2.i_list;
874 + int ret;
875 + struct ocfs2_extent_tree et;
876
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,
881 - fe_bh, el, handle,
882 - data_ac, meta_ac, reason_ret,
883 - OCFS2_DINODE_EXTENT, NULL);
884 + &et, handle,
885 + data_ac, meta_ac, reason_ret);
886 + ocfs2_put_extent_tree(&et);
887 +
888 + return ret;
889 }
890
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;
897
898 mlog_entry("(clusters_to_add = %u)\n", clusters_to_add);
899
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),
903 clusters_to_add);
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);
911 if (status) {
912 mlog_errno(status);
913 goto leave;
914 @@ -1236,11 +1241,13 @@ static int __ocfs2_remove_inode_range(st
915 handle_t *handle;
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;
919 +
920 + ocfs2_get_dinode_extent_tree(&et, inode, di_bh);
921
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);
926 if (ret) {
927 + ocfs2_put_extent_tree(&et);
928 mlog_errno(ret);
929 return ret;
930 }
931 @@ -1269,8 +1276,8 @@ static int __ocfs2_remove_inode_range(st
932 goto out;
933 }
934
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,
938 + dealloc);
939 if (ret) {
940 mlog_errno(ret);
941 goto out_commit;
942 @@ -1297,6 +1304,7 @@ out:
943 if (meta_ac)
944 ocfs2_free_alloc_context(meta_ac);
945
946 + ocfs2_put_extent_tree(&et);
947 return ret;
948 }
949
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().
957 */
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)
967 {
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 *
971
972 BUG_ON(clusters_to_add != 0 && data_ac == NULL);
973
974 - num_free_extents = ocfs2_num_free_extents(osb, inode, root_bh,
975 - type, private);
976 + num_free_extents = ocfs2_num_free_extents(osb, inode, et);
977 if (num_free_extents < 0) {
978 ret = num_free_extents;
979 mlog_errno(ret);
980 @@ -1951,7 +1949,7 @@ int ocfs2_lock_allocators(struct inode *
981 */
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);
986 if (ret < 0) {
987 if (ret != -ENOSPC)
988 mlog_errno(ret);
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;
1017
1018 mlog(0, "(clusters_to_add for xattr= %u)\n", clusters_to_add);
1019
1020 + ocfs2_get_xattr_value_extent_tree(&et, inode, xattr_bh, xv);
1021 +
1022 restart_all:
1023
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);
1029 if (status) {
1030 mlog_errno(status);
1031 goto leave;
1032 }
1033
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,
1036 + clusters_to_add);
1037 handle = ocfs2_start_trans(osb, credits);
1038 if (IS_ERR(handle)) {
1039 status = PTR_ERR(handle);
1040 @@ -260,14 +262,11 @@ restarted_transaction:
1041 &logical_start,
1042 clusters_to_add,
1043 0,
1044 - xattr_bh,
1045 - root_el,
1046 + &et,
1047 handle,
1048 data_ac,
1049 meta_ac,
1050 - &why,
1051 - OCFS2_XATTR_VALUE_EXTENT,
1052 - xv);
1053 + &why);
1054 if ((status < 0) && (status != -EAGAIN)) {
1055 if (status != -ENOSPC)
1056 mlog_errno(status);
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,
1061 - root_el,
1062 + et.et_root_el,
1063 clusters_to_add);
1064 status = ocfs2_extend_trans(handle, credits);
1065 if (status < 0) {
1066 @@ -324,6 +323,7 @@ leave:
1067 goto restart_all;
1068 }
1069
1070 + ocfs2_put_extent_tree(&et);
1071 return status;
1072 }
1073
1074 @@ -339,11 +339,13 @@ static int __ocfs2_remove_xattr_range(st
1075 struct inode *tl_inode = osb->osb_tl_inode;
1076 handle_t *handle;
1077 struct ocfs2_alloc_context *meta_ac = NULL;
1078 + struct ocfs2_extent_tree et;
1079 +
1080 + ocfs2_get_xattr_value_extent_tree(&et, inode, root_bh, xv);
1081
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);
1086 if (ret) {
1087 + ocfs2_put_extent_tree(&et);
1088 mlog_errno(ret);
1089 return ret;
1090 }
1091 @@ -372,8 +374,8 @@ static int __ocfs2_remove_xattr_range(st
1092 goto out_commit;
1093 }
1094
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,
1098 + dealloc);
1099 if (ret) {
1100 mlog_errno(ret);
1101 goto out_commit;
1102 @@ -399,6 +401,7 @@ out:
1103 if (meta_ac)
1104 ocfs2_free_alloc_context(meta_ac);
1105
1106 + ocfs2_put_extent_tree(&et);
1107 return ret;
1108 }
1109
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;
1120
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);
1125
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);
1130 +
1131 + ret = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0,
1132 + &data_ac, &meta_ac);
1133 if (ret) {
1134 mlog_errno(ret);
1135 goto leave;
1136 }
1137
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,
1140 + clusters_to_add);
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
1145
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,
1150 - 0, meta_ac);
1151 + ret = ocfs2_insert_extent(osb, handle, inode, &et, v_start, block,
1152 + num_bits, 0, meta_ac);
1153 if (ret < 0) {
1154 mlog_errno(ret);
1155 goto leave;
1156 @@ -3743,6 +3743,7 @@ leave:
1157 if (meta_ac)
1158 ocfs2_free_alloc_context(meta_ac);
1159
1160 + ocfs2_put_extent_tree(&et);
1161 return ret;
1162 }
1163
1164 @@ -4347,9 +4348,11 @@ static int ocfs2_rm_xattr_cluster(struct
1165 handle_t *handle;
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;
1172 +
1173 + ocfs2_get_xattr_tree_extent_tree(&et, inode, root_bh);
1174
1175 ocfs2_init_dealloc_ctxt(&dealloc);
1176
1177 @@ -4358,10 +4361,9 @@ static int ocfs2_rm_xattr_cluster(struct
1178
1179 ocfs2_remove_xattr_clusters_from_cache(inode, blkno, len);
1180
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);
1185 if (ret) {
1186 + ocfs2_put_extent_tree(&et);
1187 mlog_errno(ret);
1188 return ret;
1189 }
1190 @@ -4390,8 +4392,8 @@ static int ocfs2_rm_xattr_cluster(struct
1191 goto out_commit;
1192 }
1193
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,
1197 + &dealloc);
1198 if (ret) {
1199 mlog_errno(ret);
1200 goto out_commit;
1201 @@ -4421,6 +4423,7 @@ out:
1202
1203 ocfs2_run_deallocs(osb, &dealloc);
1204
1205 + ocfs2_put_extent_tree(&et);
1206 return ret;
1207 }
1208