diff options
| author | Joel Becker <joel.becker@oracle.com> | 2008-08-20 22:36:33 -0400 |
|---|---|---|
| committer | Mark Fasheh <mfasheh@suse.com> | 2008-10-13 19:57:05 -0400 |
| commit | f99b9b7ccf6a691f653cec45f36bfdd1e94769c7 (patch) | |
| tree | 1c6ff6ea1fa1bb86b70f1fd78dd725b559c729e4 /fs/ocfs2/alloc.h | |
| parent | 1e61ee79e2a96f62c007486677319814ce621c3c (diff) | |
ocfs2: Make ocfs2_extent_tree the first-class representation of a tree.
We now have three different kinds of extent trees in ocfs2: inode data
(dinode), extended attributes (xattr_tree), and extended attribute
values (xattr_value). There is a nice abstraction for them,
ocfs2_extent_tree, but it is hidden in alloc.c. All the calling
functions have to pick amongst a varied API and pass in type bits and
often extraneous pointers.
A better way is to make ocfs2_extent_tree a first-class object.
Everyone converts their object to an ocfs2_extent_tree() via the
ocfs2_get_*_extent_tree() calls, then uses the ocfs2_extent_tree for all
tree calls to alloc.c.
This simplifies a lot of callers, making for readability. It also
provides an easy way to add additional extent tree types, as they only
need to be defined in alloc.c with a ocfs2_get_<new>_extent_tree()
function.
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mfasheh@suse.com>
Diffstat (limited to 'fs/ocfs2/alloc.h')
| -rw-r--r-- | fs/ocfs2/alloc.h | 111 |
1 files changed, 62 insertions, 49 deletions
diff --git a/fs/ocfs2/alloc.h b/fs/ocfs2/alloc.h index 5cc9a83cf1a1..35ad07f96104 100644 --- a/fs/ocfs2/alloc.h +++ b/fs/ocfs2/alloc.h | |||
| @@ -26,46 +26,66 @@ | |||
| 26 | #ifndef OCFS2_ALLOC_H | 26 | #ifndef OCFS2_ALLOC_H |
| 27 | #define OCFS2_ALLOC_H | 27 | #define OCFS2_ALLOC_H |
| 28 | 28 | ||
| 29 | enum ocfs2_extent_tree_type { | ||
| 30 | OCFS2_DINODE_EXTENT = 0, | ||
| 31 | OCFS2_XATTR_VALUE_EXTENT, | ||
| 32 | OCFS2_XATTR_TREE_EXTENT, | ||
| 33 | }; | ||
| 34 | 29 | ||
| 35 | /* | 30 | /* |
| 36 | * For xattr tree leaf, we limit the leaf byte size to be 64K. | 31 | * For xattr tree leaf, we limit the leaf byte size to be 64K. |
| 37 | */ | 32 | */ |
| 38 | #define OCFS2_MAX_XATTR_TREE_LEAF_SIZE 65536 | 33 | #define OCFS2_MAX_XATTR_TREE_LEAF_SIZE 65536 |
| 39 | 34 | ||
| 35 | /* | ||
| 36 | * ocfs2_extent_tree and ocfs2_extent_tree_operations are used to abstract | ||
| 37 | * the b-tree operations in ocfs2. Now all the b-tree operations are not | ||
| 38 | * limited to ocfs2_dinode only. Any data which need to allocate clusters | ||
| 39 | * to store can use b-tree. And it only needs to implement its ocfs2_extent_tree | ||
| 40 | * and operation. | ||
| 41 | * | ||
| 42 | * ocfs2_extent_tree becomes the first-class object for extent tree | ||
| 43 | * manipulation. Callers of the alloc.c code need to fill it via one of | ||
| 44 | * the ocfs2_get_*_extent_tree() operations below. | ||
| 45 | * | ||
| 46 | * ocfs2_extent_tree contains info for the root of the b-tree, it must have a | ||
| 47 | * root ocfs2_extent_list and a root_bh so that they can be used in the b-tree | ||
| 48 | * functions. | ||
| 49 | * ocfs2_extent_tree_operations abstract the normal operations we do for | ||
| 50 | * the root of extent b-tree. | ||
| 51 | */ | ||
| 52 | struct ocfs2_extent_tree_operations; | ||
| 53 | struct ocfs2_extent_tree { | ||
| 54 | struct ocfs2_extent_tree_operations *et_ops; | ||
| 55 | struct buffer_head *et_root_bh; | ||
| 56 | struct ocfs2_extent_list *et_root_el; | ||
| 57 | void *et_object; | ||
| 58 | unsigned int et_max_leaf_clusters; | ||
| 59 | }; | ||
| 60 | |||
| 61 | /* | ||
| 62 | * ocfs2_*_get_extent_tree() will fill an ocfs2_extent_tree from the | ||
| 63 | * specified object buffer. The bh is referenced until | ||
| 64 | * ocfs2_put_extent_tree(). | ||
| 65 | */ | ||
| 66 | void ocfs2_get_dinode_extent_tree(struct ocfs2_extent_tree *et, | ||
| 67 | struct inode *inode, | ||
| 68 | struct buffer_head *bh); | ||
| 69 | void ocfs2_get_xattr_tree_extent_tree(struct ocfs2_extent_tree *et, | ||
| 70 | struct inode *inode, | ||
| 71 | struct buffer_head *bh); | ||
| 72 | void ocfs2_get_xattr_value_extent_tree(struct ocfs2_extent_tree *et, | ||
| 73 | struct inode *inode, | ||
| 74 | struct buffer_head *bh, | ||
| 75 | struct ocfs2_xattr_value_root *xv); | ||
| 76 | void ocfs2_put_extent_tree(struct ocfs2_extent_tree *et); | ||
| 77 | |||
| 40 | struct ocfs2_alloc_context; | 78 | struct ocfs2_alloc_context; |
| 41 | int ocfs2_dinode_insert_extent(struct ocfs2_super *osb, | 79 | int ocfs2_insert_extent(struct ocfs2_super *osb, |
| 42 | handle_t *handle, | 80 | handle_t *handle, |
| 43 | struct inode *inode, | 81 | struct inode *inode, |
| 44 | struct buffer_head *root_bh, | 82 | struct ocfs2_extent_tree *et, |
| 45 | u32 cpos, | 83 | u32 cpos, |
| 46 | u64 start_blk, | 84 | u64 start_blk, |
| 47 | u32 new_clusters, | 85 | u32 new_clusters, |
| 48 | u8 flags, | 86 | u8 flags, |
| 49 | struct ocfs2_alloc_context *meta_ac); | 87 | struct ocfs2_alloc_context *meta_ac); |
| 50 | int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb, | 88 | |
| 51 | handle_t *handle, | ||
| 52 | struct inode *inode, | ||
| 53 | struct buffer_head *root_bh, | ||
| 54 | u32 cpos, | ||
| 55 | u64 start_blk, | ||
| 56 | u32 new_clusters, | ||
| 57 | u8 flags, | ||
| 58 | struct ocfs2_alloc_context *meta_ac, | ||
| 59 | struct ocfs2_xattr_value_root *xv); | ||
| 60 | int ocfs2_xattr_tree_insert_extent(struct ocfs2_super *osb, | ||
| 61 | handle_t *handle, | ||
| 62 | struct inode *inode, | ||
| 63 | struct buffer_head *root_bh, | ||
| 64 | u32 cpos, | ||
| 65 | u64 start_blk, | ||
| 66 | u32 new_clusters, | ||
| 67 | u8 flags, | ||
| 68 | struct ocfs2_alloc_context *meta_ac); | ||
| 69 | enum ocfs2_alloc_restarted { | 89 | enum ocfs2_alloc_restarted { |
| 70 | RESTART_NONE = 0, | 90 | RESTART_NONE = 0, |
| 71 | RESTART_TRANS, | 91 | RESTART_TRANS, |
| @@ -76,32 +96,25 @@ int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb, | |||
| 76 | u32 *logical_offset, | 96 | u32 *logical_offset, |
| 77 | u32 clusters_to_add, | 97 | u32 clusters_to_add, |
| 78 | int mark_unwritten, | 98 | int mark_unwritten, |
| 79 | struct buffer_head *root_bh, | 99 | struct ocfs2_extent_tree *et, |
| 80 | struct ocfs2_extent_list *root_el, | ||
| 81 | handle_t *handle, | 100 | handle_t *handle, |
| 82 | struct ocfs2_alloc_context *data_ac, | 101 | struct ocfs2_alloc_context *data_ac, |
| 83 | struct ocfs2_alloc_context *meta_ac, | 102 | struct ocfs2_alloc_context *meta_ac, |
| 84 | enum ocfs2_alloc_restarted *reason_ret, | 103 | enum ocfs2_alloc_restarted *reason_ret); |
| 85 | enum ocfs2_extent_tree_type type, | ||
| 86 | void *private); | ||
| 87 | struct ocfs2_cached_dealloc_ctxt; | 104 | struct ocfs2_cached_dealloc_ctxt; |
| 88 | int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh, | 105 | int ocfs2_mark_extent_written(struct inode *inode, |
| 106 | struct ocfs2_extent_tree *et, | ||
| 89 | handle_t *handle, u32 cpos, u32 len, u32 phys, | 107 | handle_t *handle, u32 cpos, u32 len, u32 phys, |
| 90 | struct ocfs2_alloc_context *meta_ac, | 108 | struct ocfs2_alloc_context *meta_ac, |
| 91 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 109 | struct ocfs2_cached_dealloc_ctxt *dealloc); |
| 92 | enum ocfs2_extent_tree_type et_type, | 110 | int ocfs2_remove_extent(struct inode *inode, |
| 93 | void *private); | 111 | struct ocfs2_extent_tree *et, |
| 94 | int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh, | ||
| 95 | u32 cpos, u32 len, handle_t *handle, | 112 | u32 cpos, u32 len, handle_t *handle, |
| 96 | struct ocfs2_alloc_context *meta_ac, | 113 | struct ocfs2_alloc_context *meta_ac, |
| 97 | struct ocfs2_cached_dealloc_ctxt *dealloc, | 114 | struct ocfs2_cached_dealloc_ctxt *dealloc); |
| 98 | enum ocfs2_extent_tree_type et_type, | ||
| 99 | void *private); | ||
| 100 | int ocfs2_num_free_extents(struct ocfs2_super *osb, | 115 | int ocfs2_num_free_extents(struct ocfs2_super *osb, |
| 101 | struct inode *inode, | 116 | struct inode *inode, |
| 102 | struct buffer_head *root_bh, | 117 | struct ocfs2_extent_tree *et); |
| 103 | enum ocfs2_extent_tree_type et_type, | ||
| 104 | void *private); | ||
| 105 | 118 | ||
| 106 | /* | 119 | /* |
| 107 | * how many new metadata chunks would an allocation need at maximum? | 120 | * how many new metadata chunks would an allocation need at maximum? |
