1 From: Joel Becker <joel.becker@oracle.com>
2 Subject: ocfs2: Make ocfs2_extent_tree get/put instead of alloc.
3 Patch-mainline: 2.6.28?
6 Rather than allocating a struct ocfs2_extent_tree, just put it on the
7 stack. Fill it with ocfs2_get_extent_tree() and drop it with
8 ocfs2_put_extent_tree(). Now the callers don't have to ENOMEM, yet
9 still safely ref the root_bh.
11 Signed-off-by: Joel Becker <joel.becker@oracle.com>
12 Acked-by: Mark Fasheh <mark.fasheh@suse.com>
14 fs/ocfs2/alloc.c | 117 ++++++++++++++++-------------------------------------
15 1 files changed, 36 insertions(+), 81 deletions(-)
17 diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
18 index ab16b89..0abf11e 100644
19 --- a/fs/ocfs2/alloc.c
20 +++ b/fs/ocfs2/alloc.c
21 @@ -223,22 +223,17 @@ static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = {
22 .eo_sanity_check = ocfs2_xattr_tree_sanity_check,
25 -static struct ocfs2_extent_tree*
26 - ocfs2_new_extent_tree(struct inode *inode,
27 - struct buffer_head *bh,
28 - enum ocfs2_extent_tree_type et_type,
30 +static void ocfs2_get_extent_tree(struct ocfs2_extent_tree *et,
31 + struct inode *inode,
32 + struct buffer_head *bh,
33 + enum ocfs2_extent_tree_type et_type,
36 - struct ocfs2_extent_tree *et;
38 - et = kzalloc(sizeof(*et), GFP_NOFS);
42 et->et_type = et_type;
45 et->et_private = private;
46 + et->et_max_leaf_clusters = 0;
48 if (et_type == OCFS2_DINODE_EXTENT) {
50 @@ -257,16 +252,11 @@ static struct ocfs2_extent_tree*
51 et->et_max_leaf_clusters = ocfs2_clusters_for_bytes(inode->i_sb,
52 OCFS2_MAX_XATTR_TREE_LEAF_SIZE);
58 -static void ocfs2_free_extent_tree(struct ocfs2_extent_tree *et)
59 +static void ocfs2_put_extent_tree(struct ocfs2_extent_tree *et)
62 - brelse(et->et_root_bh);
65 + brelse(et->et_root_bh);
68 static inline void ocfs2_et_set_last_eb_blk(struct ocfs2_extent_tree *et,
69 @@ -4439,22 +4429,15 @@ int ocfs2_dinode_insert_extent(struct ocfs2_super *osb,
70 struct ocfs2_alloc_context *meta_ac)
73 - struct ocfs2_extent_tree *et = NULL;
75 - et = ocfs2_new_extent_tree(inode, root_bh, OCFS2_DINODE_EXTENT, NULL);
81 + struct ocfs2_extent_tree et;
83 + ocfs2_get_extent_tree(&et, inode, root_bh, OCFS2_DINODE_EXTENT,
85 status = ocfs2_insert_extent(osb, handle, inode, root_bh,
86 cpos, start_blk, new_clusters,
87 - flags, meta_ac, et);
88 + flags, meta_ac, &et);
89 + ocfs2_put_extent_tree(&et);
92 - ocfs2_free_extent_tree(et);
97 @@ -4470,23 +4453,15 @@ int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb,
101 - struct ocfs2_extent_tree *et = NULL;
103 - et = ocfs2_new_extent_tree(inode, root_bh,
104 - OCFS2_XATTR_VALUE_EXTENT, private);
107 - mlog_errno(status);
110 + struct ocfs2_extent_tree et;
112 + ocfs2_get_extent_tree(&et, inode, root_bh,
113 + OCFS2_XATTR_VALUE_EXTENT, private);
114 status = ocfs2_insert_extent(osb, handle, inode, root_bh,
115 cpos, start_blk, new_clusters,
116 - flags, meta_ac, et);
117 + flags, meta_ac, &et);
118 + ocfs2_put_extent_tree(&et);
121 - ocfs2_free_extent_tree(et);
126 @@ -4501,23 +4476,15 @@ int ocfs2_xattr_tree_insert_extent(struct ocfs2_super *osb,
127 struct ocfs2_alloc_context *meta_ac)
130 - struct ocfs2_extent_tree *et = NULL;
132 - et = ocfs2_new_extent_tree(inode, root_bh, OCFS2_XATTR_TREE_EXTENT,
136 - mlog_errno(status);
139 + struct ocfs2_extent_tree et;
141 + ocfs2_get_extent_tree(&et, inode, root_bh, OCFS2_XATTR_TREE_EXTENT,
143 status = ocfs2_insert_extent(osb, handle, inode, root_bh,
144 cpos, start_blk, new_clusters,
145 - flags, meta_ac, et);
146 + flags, meta_ac, &et);
147 + ocfs2_put_extent_tree(&et);
150 - ocfs2_free_extent_tree(et);
155 @@ -4906,11 +4873,13 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
156 struct ocfs2_extent_rec split_rec;
157 struct ocfs2_path *left_path = NULL;
158 struct ocfs2_extent_list *el;
159 - struct ocfs2_extent_tree *et = NULL;
160 + struct ocfs2_extent_tree et;
162 mlog(0, "Inode %lu cpos %u, len %u, phys %u (%llu)\n",
163 inode->i_ino, cpos, len, phys, (unsigned long long)start_blkno);
165 + ocfs2_get_extent_tree(&et, inode, root_bh, et_type, private);
167 if (!ocfs2_writes_unwritten_extents(OCFS2_SB(inode->i_sb))) {
168 ocfs2_error(inode->i_sb, "Inode %llu has unwritten extents "
169 "that are being written to, but the feature bit "
170 @@ -4920,13 +4889,6 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
174 - et = ocfs2_new_extent_tree(inode, root_bh, et_type, private);
182 * XXX: This should be fixed up so that we just re-insert the
183 * next extent records.
184 @@ -4934,7 +4896,7 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
185 if (et_type == OCFS2_DINODE_EXTENT)
186 ocfs2_extent_map_trunc(inode, 0);
188 - left_path = ocfs2_new_path(et->et_root_bh, et->et_root_el);
189 + left_path = ocfs2_new_path(et.et_root_bh, et.et_root_el);
193 @@ -4965,7 +4927,7 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
194 split_rec.e_flags = path_leaf_el(left_path)->l_recs[index].e_flags;
195 split_rec.e_flags &= ~OCFS2_EXT_UNWRITTEN;
197 - ret = __ocfs2_mark_extent_written(inode, et, handle, left_path,
198 + ret = __ocfs2_mark_extent_written(inode, &et, handle, left_path,
199 index, &split_rec, meta_ac,
202 @@ -4973,8 +4935,7 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
205 ocfs2_free_path(left_path);
207 - ocfs2_free_extent_tree(et);
208 + ocfs2_put_extent_tree(&et);
212 @@ -5216,18 +5177,13 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
213 struct ocfs2_extent_rec *rec;
214 struct ocfs2_extent_list *el;
215 struct ocfs2_path *path = NULL;
216 - struct ocfs2_extent_tree *et = NULL;
217 + struct ocfs2_extent_tree et;
219 - et = ocfs2_new_extent_tree(inode, root_bh, et_type, private);
225 + ocfs2_get_extent_tree(&et, inode, root_bh, et_type, private);
227 ocfs2_extent_map_trunc(inode, 0);
229 - path = ocfs2_new_path(et->et_root_bh, et->et_root_el);
230 + path = ocfs2_new_path(et.et_root_bh, et.et_root_el);
234 @@ -5280,13 +5236,13 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
236 if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) {
237 ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc,
245 - ret = ocfs2_split_tree(inode, et, handle, path, index,
246 + ret = ocfs2_split_tree(inode, &et, handle, path, index,
247 trunc_range, meta_ac);
250 @@ -5335,7 +5291,7 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
253 ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc,
259 @@ -5344,8 +5300,7 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
262 ocfs2_free_path(path);
264 - ocfs2_free_extent_tree(et);
265 + ocfs2_put_extent_tree(&et);