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>
This commit is contained in:
Tao Ma 2009-08-18 11:22:34 +08:00 committed by Joel Becker
parent fe92441595
commit e2e9f6082b
2 changed files with 72 additions and 53 deletions

View File

@ -567,36 +567,6 @@ static inline int ocfs2_et_sanity_check(struct ocfs2_extent_tree *et)
static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc); static void ocfs2_free_truncate_context(struct ocfs2_truncate_context *tc);
static int ocfs2_cache_extent_block_free(struct ocfs2_cached_dealloc_ctxt *ctxt, static int ocfs2_cache_extent_block_free(struct ocfs2_cached_dealloc_ctxt *ctxt,
struct ocfs2_extent_block *eb); struct ocfs2_extent_block *eb);
/*
* Structures which describe a path through a btree, and functions to
* manipulate them.
*
* The idea here is to be as generic as possible with the tree
* manipulation code.
*/
struct ocfs2_path_item {
struct buffer_head *bh;
struct ocfs2_extent_list *el;
};
#define OCFS2_MAX_PATH_DEPTH 5
struct ocfs2_path {
int p_tree_depth;
ocfs2_journal_access_func p_root_access;
struct ocfs2_path_item p_node[OCFS2_MAX_PATH_DEPTH];
};
#define path_root_bh(_path) ((_path)->p_node[0].bh)
#define path_root_el(_path) ((_path)->p_node[0].el)
#define path_root_access(_path)((_path)->p_root_access)
#define path_leaf_bh(_path) ((_path)->p_node[(_path)->p_tree_depth].bh)
#define path_leaf_el(_path) ((_path)->p_node[(_path)->p_tree_depth].el)
#define path_num_items(_path) ((_path)->p_tree_depth + 1)
static int ocfs2_find_path(struct ocfs2_caching_info *ci,
struct ocfs2_path *path, u32 cpos);
static void ocfs2_adjust_rightmost_records(handle_t *handle, static void ocfs2_adjust_rightmost_records(handle_t *handle,
struct ocfs2_extent_tree *et, struct ocfs2_extent_tree *et,
struct ocfs2_path *path, struct ocfs2_path *path,
@ -606,7 +576,7 @@ static void ocfs2_adjust_rightmost_records(handle_t *handle,
* to build another path. Generally, this involves freeing the buffer * to build another path. Generally, this involves freeing the buffer
* heads. * heads.
*/ */
static void ocfs2_reinit_path(struct ocfs2_path *path, int keep_root) void ocfs2_reinit_path(struct ocfs2_path *path, int keep_root)
{ {
int i, start = 0, depth = 0; int i, start = 0, depth = 0;
struct ocfs2_path_item *node; struct ocfs2_path_item *node;
@ -635,7 +605,7 @@ static void ocfs2_reinit_path(struct ocfs2_path *path, int keep_root)
path->p_tree_depth = depth; path->p_tree_depth = depth;
} }
static void ocfs2_free_path(struct ocfs2_path *path) void ocfs2_free_path(struct ocfs2_path *path)
{ {
if (path) { if (path) {
ocfs2_reinit_path(path, 0); ocfs2_reinit_path(path, 0);
@ -733,13 +703,13 @@ static struct ocfs2_path *ocfs2_new_path(struct buffer_head *root_bh,
return path; return path;
} }
static struct ocfs2_path *ocfs2_new_path_from_path(struct ocfs2_path *path) struct ocfs2_path *ocfs2_new_path_from_path(struct ocfs2_path *path)
{ {
return ocfs2_new_path(path_root_bh(path), path_root_el(path), return ocfs2_new_path(path_root_bh(path), path_root_el(path),
path_root_access(path)); path_root_access(path));
} }
static struct ocfs2_path *ocfs2_new_path_from_et(struct ocfs2_extent_tree *et) struct ocfs2_path *ocfs2_new_path_from_et(struct ocfs2_extent_tree *et)
{ {
return ocfs2_new_path(et->et_root_bh, et->et_root_el, return ocfs2_new_path(et->et_root_bh, et->et_root_el,
et->et_root_journal_access); et->et_root_journal_access);
@ -752,10 +722,10 @@ static struct ocfs2_path *ocfs2_new_path_from_et(struct ocfs2_extent_tree *et)
* I don't like the way this function's name looks next to * I don't like the way this function's name looks next to
* ocfs2_journal_access_path(), but I don't have a better one. * ocfs2_journal_access_path(), but I don't have a better one.
*/ */
static int ocfs2_path_bh_journal_access(handle_t *handle, int ocfs2_path_bh_journal_access(handle_t *handle,
struct ocfs2_caching_info *ci, struct ocfs2_caching_info *ci,
struct ocfs2_path *path, struct ocfs2_path *path,
int idx) int idx)
{ {
ocfs2_journal_access_func access = path_root_access(path); ocfs2_journal_access_func access = path_root_access(path);
@ -772,9 +742,9 @@ static int ocfs2_path_bh_journal_access(handle_t *handle,
/* /*
* Convenience function to journal all components in a path. * Convenience function to journal all components in a path.
*/ */
static int ocfs2_journal_access_path(struct ocfs2_caching_info *ci, int ocfs2_journal_access_path(struct ocfs2_caching_info *ci,
handle_t *handle, handle_t *handle,
struct ocfs2_path *path) struct ocfs2_path *path)
{ {
int i, ret = 0; int i, ret = 0;
@ -1942,8 +1912,8 @@ static void find_path_ins(void *data, struct buffer_head *bh)
ocfs2_path_insert_eb(fp->path, fp->index, bh); ocfs2_path_insert_eb(fp->path, fp->index, bh);
fp->index++; fp->index++;
} }
static int ocfs2_find_path(struct ocfs2_caching_info *ci, int ocfs2_find_path(struct ocfs2_caching_info *ci,
struct ocfs2_path *path, u32 cpos) struct ocfs2_path *path, u32 cpos)
{ {
struct find_path_data data; struct find_path_data data;
@ -5104,13 +5074,13 @@ out:
* have been brought into cache (and pinned via the journal), so the * have been brought into cache (and pinned via the journal), so the
* extra overhead is not expressed in terms of disk reads. * extra overhead is not expressed in terms of disk reads.
*/ */
static int __ocfs2_split_extent(handle_t *handle, int ocfs2_split_extent(handle_t *handle,
struct ocfs2_extent_tree *et, struct ocfs2_extent_tree *et,
struct ocfs2_path *path, struct ocfs2_path *path,
int split_index, int split_index,
struct ocfs2_extent_rec *split_rec, struct ocfs2_extent_rec *split_rec,
struct ocfs2_alloc_context *meta_ac, struct ocfs2_alloc_context *meta_ac,
struct ocfs2_cached_dealloc_ctxt *dealloc) struct ocfs2_cached_dealloc_ctxt *dealloc)
{ {
int ret = 0; int ret = 0;
struct ocfs2_extent_list *el = path_leaf_el(path); struct ocfs2_extent_list *el = path_leaf_el(path);
@ -5267,9 +5237,9 @@ static int ocfs2_change_extent_flag(handle_t *handle,
if (clear_flags) if (clear_flags)
split_rec.e_flags &= ~clear_flags; split_rec.e_flags &= ~clear_flags;
ret = __ocfs2_split_extent(handle, et, left_path, ret = ocfs2_split_extent(handle, et, left_path,
index, &split_rec, meta_ac, index, &split_rec, meta_ac,
dealloc); dealloc);
if (ret) if (ret)
mlog_errno(ret); mlog_errno(ret);

View File

@ -115,6 +115,14 @@ int ocfs2_add_clusters_in_btree(handle_t *handle,
struct ocfs2_alloc_context *meta_ac, struct ocfs2_alloc_context *meta_ac,
enum ocfs2_alloc_restarted *reason_ret); enum ocfs2_alloc_restarted *reason_ret);
struct ocfs2_cached_dealloc_ctxt; struct ocfs2_cached_dealloc_ctxt;
struct ocfs2_path;
int ocfs2_split_extent(handle_t *handle,
struct ocfs2_extent_tree *et,
struct ocfs2_path *path,
int split_index,
struct ocfs2_extent_rec *split_rec,
struct ocfs2_alloc_context *meta_ac,
struct ocfs2_cached_dealloc_ctxt *dealloc);
int ocfs2_mark_extent_written(struct inode *inode, int ocfs2_mark_extent_written(struct inode *inode,
struct ocfs2_extent_tree *et, struct ocfs2_extent_tree *et,
handle_t *handle, u32 cpos, u32 len, u32 phys, 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)
return !rec->e_leaf_clusters; return !rec->e_leaf_clusters;
} }
/*
* Structures which describe a path through a btree, and functions to
* manipulate them.
*
* The idea here is to be as generic as possible with the tree
* manipulation code.
*/
struct ocfs2_path_item {
struct buffer_head *bh;
struct ocfs2_extent_list *el;
};
#define OCFS2_MAX_PATH_DEPTH 5
struct ocfs2_path {
int p_tree_depth;
ocfs2_journal_access_func p_root_access;
struct ocfs2_path_item p_node[OCFS2_MAX_PATH_DEPTH];
};
#define path_root_bh(_path) ((_path)->p_node[0].bh)
#define path_root_el(_path) ((_path)->p_node[0].el)
#define path_root_access(_path)((_path)->p_root_access)
#define path_leaf_bh(_path) ((_path)->p_node[(_path)->p_tree_depth].bh)
#define path_leaf_el(_path) ((_path)->p_node[(_path)->p_tree_depth].el)
#define path_num_items(_path) ((_path)->p_tree_depth + 1)
void ocfs2_reinit_path(struct ocfs2_path *path, int keep_root);
void ocfs2_free_path(struct ocfs2_path *path);
int ocfs2_find_path(struct ocfs2_caching_info *ci,
struct ocfs2_path *path,
u32 cpos);
struct ocfs2_path *ocfs2_new_path_from_path(struct ocfs2_path *path);
struct ocfs2_path *ocfs2_new_path_from_et(struct ocfs2_extent_tree *et);
int ocfs2_path_bh_journal_access(handle_t *handle,
struct ocfs2_caching_info *ci,
struct ocfs2_path *path,
int idx);
int ocfs2_journal_access_path(struct ocfs2_caching_info *ci,
handle_t *handle,
struct ocfs2_path *path);
#endif /* OCFS2_ALLOC_H */ #endif /* OCFS2_ALLOC_H */