diff options
author | Tao Ma <tao.ma@oracle.com> | 2009-08-17 23:22:34 -0400 |
---|---|---|
committer | Joel Becker <joel.becker@oracle.com> | 2009-09-22 23:09:32 -0400 |
commit | e2e9f6082b5ff099978774d5c0148e062344c2f9 (patch) | |
tree | 1da7dc993c77ca08cb83aba8f21e0da9fd055044 /fs/ocfs2 | |
parent | fe924415957e60471536762172d127e85519ef78 (diff) |
ocfs2: move tree path functions to alloc.h.
Now fs/ocfs2/alloc.c has more than 7000 lines. It contains our
basic b-tree operation. Although we have already make our b-tree
operation generic, the basic structrue ocfs2_path which is used
to iterate one b-tree branch is still static and limited to only
used in alloc.c. As refcount tree need them and I don't want to
add any more b-tree unrelated code to alloc.c, export them out.
Signed-off-by: Tao Ma <tao.ma@oracle.com>
Diffstat (limited to 'fs/ocfs2')
-rw-r--r-- | fs/ocfs2/alloc.c | 76 | ||||
-rw-r--r-- | fs/ocfs2/alloc.h | 49 |
2 files changed, 72 insertions, 53 deletions
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c index a6296560a5cb..2c8ce32adf01 100644 --- a/fs/ocfs2/alloc.c +++ b/fs/ocfs2/alloc.c | |||
@@ -567,36 +567,6 @@ static inline int ocfs2_et_sanity_check(struct ocfs2_extent_tree *et) | |||
567 | static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc); | 567 | static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc); |
568 | static int ocfs2_cache_extent_block_free(struct ocfs2_cached_dealloc_ctxt *ctxt, | 568 | static int ocfs2_cache_extent_block_free(struct ocfs2_cached_dealloc_ctxt *ctxt, |
569 | struct ocfs2_extent_block *eb); | 569 | struct ocfs2_extent_block *eb); |
570 | |||
571 | /* | ||
572 | * Structures which describe a path through a btree, and functions to | ||
573 | * manipulate them. | ||
574 | * | ||
575 | * The idea here is to be as generic as possible with the tree | ||
576 | * manipulation code. | ||
577 | */ | ||
578 | struct ocfs2_path_item { | ||
579 | struct buffer_head *bh; | ||
580 | struct ocfs2_extent_list *el; | ||
581 | }; | ||
582 | |||
583 | #define OCFS2_MAX_PATH_DEPTH 5 | ||
584 | |||
585 | struct ocfs2_path { | ||
586 | int p_tree_depth; | ||
587 | ocfs2_journal_access_func p_root_access; | ||
588 | struct ocfs2_path_item p_node[OCFS2_MAX_PATH_DEPTH]; | ||
589 | }; | ||
590 | |||
591 | #define path_root_bh(_path) ((_path)->p_node[0].bh) | ||
592 | #define path_root_el(_path) ((_path)->p_node[0].el) | ||
593 | #define path_root_access(_path)((_path)->p_root_access) | ||
594 | #define path_leaf_bh(_path) ((_path)->p_node[(_path)->p_tree_depth].bh) | ||
595 | #define path_leaf_el(_path) ((_path)->p_node[(_path)->p_tree_depth].el) | ||
596 | #define path_num_items(_path) ((_path)->p_tree_depth + 1) | ||
597 | |||
598 | static int ocfs2_find_path(struct ocfs2_caching_info *ci, | ||
599 | struct ocfs2_path *path, u32 cpos); | ||
600 | static void ocfs2_adjust_rightmost_records(handle_t *handle, | 570 | static void ocfs2_adjust_rightmost_records(handle_t *handle, |
601 | struct ocfs2_extent_tree *et, | 571 | struct ocfs2_extent_tree *et, |
602 | struct ocfs2_path *path, | 572 | struct ocfs2_path *path, |
@@ -606,7 +576,7 @@ static void ocfs2_adjust_rightmost_records(handle_t *handle, | |||
606 | * to build another path. Generally, this involves freeing the buffer | 576 | * to build another path. Generally, this involves freeing the buffer |
607 | * heads. | 577 | * heads. |
608 | */ | 578 | */ |
609 | static void ocfs2_reinit_path(struct ocfs2_path *path, int keep_root) | 579 | void ocfs2_reinit_path(struct ocfs2_path *path, int keep_root) |
610 | { | 580 | { |
611 | int i, start = 0, depth = 0; | 581 | int i, start = 0, depth = 0; |
612 | struct ocfs2_path_item *node; | 582 | struct ocfs2_path_item *node; |
@@ -635,7 +605,7 @@ static void ocfs2_reinit_path(struct ocfs2_path *path, int keep_root) | |||
635 | path->p_tree_depth = depth; | 605 | path->p_tree_depth = depth; |
636 | } | 606 | } |
637 | 607 | ||
638 | static void ocfs2_free_path(struct ocfs2_path *path) | 608 | void ocfs2_free_path(struct ocfs2_path *path) |
639 | { | 609 | { |
640 | if (path) { | 610 | if (path) { |
641 | ocfs2_reinit_path(path, 0); | 611 | ocfs2_reinit_path(path, 0); |
@@ -733,13 +703,13 @@ static struct ocfs2_path *ocfs2_new_path(struct buffer_head *root_bh, | |||
733 | return path; | 703 | return path; |
734 | } | 704 | } |
735 | 705 | ||
736 | static struct ocfs2_path *ocfs2_new_path_from_path(struct ocfs2_path *path) | 706 | struct ocfs2_path *ocfs2_new_path_from_path(struct ocfs2_path *path) |
737 | { | 707 | { |
738 | return ocfs2_new_path(path_root_bh(path), path_root_el(path), | 708 | return ocfs2_new_path(path_root_bh(path), path_root_el(path), |
739 | path_root_access(path)); | 709 | path_root_access(path)); |
740 | } | 710 | } |
741 | 711 | ||
742 | static struct ocfs2_path *ocfs2_new_path_from_et(struct ocfs2_extent_tree *et) | 712 | struct ocfs2_path *ocfs2_new_path_from_et(struct ocfs2_extent_tree *et) |
743 | { | 713 | { |
744 | return ocfs2_new_path(et->et_root_bh, et->et_root_el, | 714 | return ocfs2_new_path(et->et_root_bh, et->et_root_el, |
745 | et->et_root_journal_access); | 715 | et->et_root_journal_access); |
@@ -752,10 +722,10 @@ static struct ocfs2_path *ocfs2_new_path_from_et(struct ocfs2_extent_tree *et) | |||
752 | * I don't like the way this function's name looks next to | 722 | * I don't like the way this function's name looks next to |
753 | * ocfs2_journal_access_path(), but I don't have a better one. | 723 | * ocfs2_journal_access_path(), but I don't have a better one. |
754 | */ | 724 | */ |
755 | static int ocfs2_path_bh_journal_access(handle_t *handle, | 725 | int ocfs2_path_bh_journal_access(handle_t *handle, |
756 | struct ocfs2_caching_info *ci, | 726 | struct ocfs2_caching_info *ci, |
757 | struct ocfs2_path *path, | 727 | struct ocfs2_path *path, |
758 | int idx) | 728 | int idx) |
759 | { | 729 | { |
760 | ocfs2_journal_access_func access = path_root_access(path); | 730 | ocfs2_journal_access_func access = path_root_access(path); |
761 | 731 | ||
@@ -772,9 +742,9 @@ static int ocfs2_path_bh_journal_access(handle_t *handle, | |||
772 | /* | 742 | /* |
773 | * Convenience function to journal all components in a path. | 743 | * Convenience function to journal all components in a path. |
774 | */ | 744 | */ |
775 | static int ocfs2_journal_access_path(struct ocfs2_caching_info *ci, | 745 | int ocfs2_journal_access_path(struct ocfs2_caching_info *ci, |
776 | handle_t *handle, | 746 | handle_t *handle, |
777 | struct ocfs2_path *path) | 747 | struct ocfs2_path *path) |
778 | { | 748 | { |
779 | int i, ret = 0; | 749 | int i, ret = 0; |
780 | 750 | ||
@@ -1942,8 +1912,8 @@ static void find_path_ins(void *data, struct buffer_head *bh) | |||
1942 | ocfs2_path_insert_eb(fp->path, fp->index, bh); | 1912 | ocfs2_path_insert_eb(fp->path, fp->index, bh); |
1943 | fp->index++; | 1913 | fp->index++; |
1944 | } | 1914 | } |
1945 | static int ocfs2_find_path(struct ocfs2_caching_info *ci, | 1915 | int ocfs2_find_path(struct ocfs2_caching_info *ci, |
1946 | struct ocfs2_path *path, u32 cpos) | 1916 | struct ocfs2_path *path, u32 cpos) |
1947 | { | 1917 | { |
1948 | struct find_path_data data; | 1918 | struct find_path_data data; |
1949 | 1919 | ||
@@ -5104,13 +5074,13 @@ out: | |||
5104 | * have been brought into cache (and pinned via the journal), so the | 5074 | * have been brought into cache (and pinned via the journal), so the |
5105 | * extra overhead is not expressed in terms of disk reads. | 5075 | * extra overhead is not expressed in terms of disk reads. |
5106 | */ | 5076 | */ |
5107 | static int __ocfs2_split_extent(handle_t *handle, | 5077 | int ocfs2_split_extent(handle_t *handle, |
5108 | struct ocfs2_extent_tree *et, | 5078 | struct ocfs2_extent_tree *et, |
5109 | struct ocfs2_path *path, | 5079 | struct ocfs2_path *path, |
5110 | int split_index, | 5080 | int split_index, |
5111 | struct ocfs2_extent_rec *split_rec, | 5081 | struct ocfs2_extent_rec *split_rec, |
5112 | struct ocfs2_alloc_context *meta_ac, | 5082 | struct ocfs2_alloc_context *meta_ac, |
5113 | struct ocfs2_cached_dealloc_ctxt *dealloc) | 5083 | struct ocfs2_cached_dealloc_ctxt *dealloc) |
5114 | { | 5084 | { |
5115 | int ret = 0; | 5085 | int ret = 0; |
5116 | struct ocfs2_extent_list *el = path_leaf_el(path); | 5086 | struct ocfs2_extent_list *el = path_leaf_el(path); |
@@ -5267,9 +5237,9 @@ static int ocfs2_change_extent_flag(handle_t *handle, | |||
5267 | if (clear_flags) | 5237 | if (clear_flags) |
5268 | split_rec.e_flags &= ~clear_flags; | 5238 | split_rec.e_flags &= ~clear_flags; |
5269 | 5239 | ||
5270 | ret = __ocfs2_split_extent(handle, et, left_path, | 5240 | ret = ocfs2_split_extent(handle, et, left_path, |
5271 | index, &split_rec, meta_ac, | 5241 | index, &split_rec, meta_ac, |
5272 | dealloc); | 5242 | dealloc); |
5273 | if (ret) | 5243 | if (ret) |
5274 | mlog_errno(ret); | 5244 | mlog_errno(ret); |
5275 | 5245 | ||
diff --git a/fs/ocfs2/alloc.h b/fs/ocfs2/alloc.h index df0e778a2b68..3f4348923b73 100644 --- a/fs/ocfs2/alloc.h +++ b/fs/ocfs2/alloc.h | |||
@@ -115,6 +115,14 @@ int ocfs2_add_clusters_in_btree(handle_t *handle, | |||
115 | struct ocfs2_alloc_context *meta_ac, | 115 | struct ocfs2_alloc_context *meta_ac, |
116 | enum ocfs2_alloc_restarted *reason_ret); | 116 | enum ocfs2_alloc_restarted *reason_ret); |
117 | struct ocfs2_cached_dealloc_ctxt; | 117 | struct ocfs2_cached_dealloc_ctxt; |
118 | struct ocfs2_path; | ||
119 | int ocfs2_split_extent(handle_t *handle, | ||
120 | struct ocfs2_extent_tree *et, | ||
121 | struct ocfs2_path *path, | ||
122 | int split_index, | ||
123 | struct ocfs2_extent_rec *split_rec, | ||
124 | struct ocfs2_alloc_context *meta_ac, | ||
125 | struct ocfs2_cached_dealloc_ctxt *dealloc); | ||
118 | int ocfs2_mark_extent_written(struct inode *inode, | 126 | int ocfs2_mark_extent_written(struct inode *inode, |
119 | struct ocfs2_extent_tree *et, | 127 | struct ocfs2_extent_tree *et, |
120 | handle_t *handle, u32 cpos, u32 len, u32 phys, | 128 | handle_t *handle, u32 cpos, u32 len, u32 phys, |
@@ -254,4 +262,45 @@ static inline int ocfs2_is_empty_extent(struct ocfs2_extent_rec *rec) | |||
254 | return !rec->e_leaf_clusters; | 262 | return !rec->e_leaf_clusters; |
255 | } | 263 | } |
256 | 264 | ||
265 | /* | ||
266 | * Structures which describe a path through a btree, and functions to | ||
267 | * manipulate them. | ||
268 | * | ||
269 | * The idea here is to be as generic as possible with the tree | ||
270 | * manipulation code. | ||
271 | */ | ||
272 | struct ocfs2_path_item { | ||
273 | struct buffer_head *bh; | ||
274 | struct ocfs2_extent_list *el; | ||
275 | }; | ||
276 | |||
277 | #define OCFS2_MAX_PATH_DEPTH 5 | ||
278 | |||
279 | struct ocfs2_path { | ||
280 | int p_tree_depth; | ||
281 | ocfs2_journal_access_func p_root_access; | ||
282 | struct ocfs2_path_item p_node[OCFS2_MAX_PATH_DEPTH]; | ||
283 | }; | ||
284 | |||
285 | #define path_root_bh(_path) ((_path)->p_node[0].bh) | ||
286 | #define path_root_el(_path) ((_path)->p_node[0].el) | ||
287 | #define path_root_access(_path)((_path)->p_root_access) | ||
288 | #define path_leaf_bh(_path) ((_path)->p_node[(_path)->p_tree_depth].bh) | ||
289 | #define path_leaf_el(_path) ((_path)->p_node[(_path)->p_tree_depth].el) | ||
290 | #define path_num_items(_path) ((_path)->p_tree_depth + 1) | ||
291 | |||
292 | void ocfs2_reinit_path(struct ocfs2_path *path, int keep_root); | ||
293 | void ocfs2_free_path(struct ocfs2_path *path); | ||
294 | int ocfs2_find_path(struct ocfs2_caching_info *ci, | ||
295 | struct ocfs2_path *path, | ||
296 | u32 cpos); | ||
297 | struct ocfs2_path *ocfs2_new_path_from_path(struct ocfs2_path *path); | ||
298 | struct ocfs2_path *ocfs2_new_path_from_et(struct ocfs2_extent_tree *et); | ||
299 | int ocfs2_path_bh_journal_access(handle_t *handle, | ||
300 | struct ocfs2_caching_info *ci, | ||
301 | struct ocfs2_path *path, | ||
302 | int idx); | ||
303 | int ocfs2_journal_access_path(struct ocfs2_caching_info *ci, | ||
304 | handle_t *handle, | ||
305 | struct ocfs2_path *path); | ||
257 | #endif /* OCFS2_ALLOC_H */ | 306 | #endif /* OCFS2_ALLOC_H */ |