aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/alloc.c
diff options
context:
space:
mode:
authorJoel Becker <joel.becker@oracle.com>2008-08-20 19:48:35 -0400
committerMark Fasheh <mfasheh@suse.com>2008-10-13 19:57:04 -0400
commitdc0ce61af418305afa7e0d05d86ab334e0daabf7 (patch)
tree7122bafdcb29a77cd65e34a600d3df76b9e165fe /fs/ocfs2/alloc.c
parentce1d9ea621291ed5e985d6677278c6bb20d96a40 (diff)
ocfs2: Make ocfs2_extent_tree get/put instead of alloc.
Rather than allocating a struct ocfs2_extent_tree, just put it on the stack. Fill it with ocfs2_get_extent_tree() and drop it with ocfs2_put_extent_tree(). Now the callers don't have to ENOMEM, yet still safely ref the root_bh. Signed-off-by: Joel Becker <joel.becker@oracle.com> Signed-off-by: Mark Fasheh <mfasheh@suse.com>
Diffstat (limited to 'fs/ocfs2/alloc.c')
-rw-r--r--fs/ocfs2/alloc.c117
1 files changed, 36 insertions, 81 deletions
diff --git a/fs/ocfs2/alloc.c b/fs/ocfs2/alloc.c
index 4ade2b259e6d..c200d3321689 100644
--- a/fs/ocfs2/alloc.c
+++ b/fs/ocfs2/alloc.c
@@ -223,22 +223,17 @@ static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = {
223 .eo_sanity_check = ocfs2_xattr_tree_sanity_check, 223 .eo_sanity_check = ocfs2_xattr_tree_sanity_check,
224}; 224};
225 225
226static struct ocfs2_extent_tree* 226static void ocfs2_get_extent_tree(struct ocfs2_extent_tree *et,
227 ocfs2_new_extent_tree(struct inode *inode, 227 struct inode *inode,
228 struct buffer_head *bh, 228 struct buffer_head *bh,
229 enum ocfs2_extent_tree_type et_type, 229 enum ocfs2_extent_tree_type et_type,
230 void *private) 230 void *private)
231{ 231{
232 struct ocfs2_extent_tree *et;
233
234 et = kzalloc(sizeof(*et), GFP_NOFS);
235 if (!et)
236 return NULL;
237
238 et->et_type = et_type; 232 et->et_type = et_type;
239 get_bh(bh); 233 get_bh(bh);
240 et->et_root_bh = bh; 234 et->et_root_bh = bh;
241 et->et_private = private; 235 et->et_private = private;
236 et->et_max_leaf_clusters = 0;
242 237
243 if (et_type == OCFS2_DINODE_EXTENT) { 238 if (et_type == OCFS2_DINODE_EXTENT) {
244 et->et_root_el = 239 et->et_root_el =
@@ -257,16 +252,11 @@ static struct ocfs2_extent_tree*
257 et->et_max_leaf_clusters = ocfs2_clusters_for_bytes(inode->i_sb, 252 et->et_max_leaf_clusters = ocfs2_clusters_for_bytes(inode->i_sb,
258 OCFS2_MAX_XATTR_TREE_LEAF_SIZE); 253 OCFS2_MAX_XATTR_TREE_LEAF_SIZE);
259 } 254 }
260
261 return et;
262} 255}
263 256
264static void ocfs2_free_extent_tree(struct ocfs2_extent_tree *et) 257static void ocfs2_put_extent_tree(struct ocfs2_extent_tree *et)
265{ 258{
266 if (et) { 259 brelse(et->et_root_bh);
267 brelse(et->et_root_bh);
268 kfree(et);
269 }
270} 260}
271 261
272static inline void ocfs2_et_set_last_eb_blk(struct ocfs2_extent_tree *et, 262static inline void ocfs2_et_set_last_eb_blk(struct ocfs2_extent_tree *et,
@@ -4430,22 +4420,15 @@ int ocfs2_dinode_insert_extent(struct ocfs2_super *osb,
4430 struct ocfs2_alloc_context *meta_ac) 4420 struct ocfs2_alloc_context *meta_ac)
4431{ 4421{
4432 int status; 4422 int status;
4433 struct ocfs2_extent_tree *et = NULL; 4423 struct ocfs2_extent_tree et;
4434
4435 et = ocfs2_new_extent_tree(inode, root_bh, OCFS2_DINODE_EXTENT, NULL);
4436 if (!et) {
4437 status = -ENOMEM;
4438 mlog_errno(status);
4439 goto bail;
4440 }
4441 4424
4425 ocfs2_get_extent_tree(&et, inode, root_bh, OCFS2_DINODE_EXTENT,
4426 NULL);
4442 status = ocfs2_insert_extent(osb, handle, inode, root_bh, 4427 status = ocfs2_insert_extent(osb, handle, inode, root_bh,
4443 cpos, start_blk, new_clusters, 4428 cpos, start_blk, new_clusters,
4444 flags, meta_ac, et); 4429 flags, meta_ac, &et);
4430 ocfs2_put_extent_tree(&et);
4445 4431
4446 if (et)
4447 ocfs2_free_extent_tree(et);
4448bail:
4449 return status; 4432 return status;
4450} 4433}
4451 4434
@@ -4461,23 +4444,15 @@ int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb,
4461 void *private) 4444 void *private)
4462{ 4445{
4463 int status; 4446 int status;
4464 struct ocfs2_extent_tree *et = NULL; 4447 struct ocfs2_extent_tree et;
4465
4466 et = ocfs2_new_extent_tree(inode, root_bh,
4467 OCFS2_XATTR_VALUE_EXTENT, private);
4468 if (!et) {
4469 status = -ENOMEM;
4470 mlog_errno(status);
4471 goto bail;
4472 }
4473 4448
4449 ocfs2_get_extent_tree(&et, inode, root_bh,
4450 OCFS2_XATTR_VALUE_EXTENT, private);
4474 status = ocfs2_insert_extent(osb, handle, inode, root_bh, 4451 status = ocfs2_insert_extent(osb, handle, inode, root_bh,
4475 cpos, start_blk, new_clusters, 4452 cpos, start_blk, new_clusters,
4476 flags, meta_ac, et); 4453 flags, meta_ac, &et);
4454 ocfs2_put_extent_tree(&et);
4477 4455
4478 if (et)
4479 ocfs2_free_extent_tree(et);
4480bail:
4481 return status; 4456 return status;
4482} 4457}
4483 4458
@@ -4492,23 +4467,15 @@ int ocfs2_xattr_tree_insert_extent(struct ocfs2_super *osb,
4492 struct ocfs2_alloc_context *meta_ac) 4467 struct ocfs2_alloc_context *meta_ac)
4493{ 4468{
4494 int status; 4469 int status;
4495 struct ocfs2_extent_tree *et = NULL; 4470 struct ocfs2_extent_tree et;
4496
4497 et = ocfs2_new_extent_tree(inode, root_bh, OCFS2_XATTR_TREE_EXTENT,
4498 NULL);
4499 if (!et) {
4500 status = -ENOMEM;
4501 mlog_errno(status);
4502 goto bail;
4503 }
4504 4471
4472 ocfs2_get_extent_tree(&et, inode, root_bh, OCFS2_XATTR_TREE_EXTENT,
4473 NULL);
4505 status = ocfs2_insert_extent(osb, handle, inode, root_bh, 4474 status = ocfs2_insert_extent(osb, handle, inode, root_bh,
4506 cpos, start_blk, new_clusters, 4475 cpos, start_blk, new_clusters,
4507 flags, meta_ac, et); 4476 flags, meta_ac, &et);
4477 ocfs2_put_extent_tree(&et);
4508 4478
4509 if (et)
4510 ocfs2_free_extent_tree(et);
4511bail:
4512 return status; 4479 return status;
4513} 4480}
4514 4481
@@ -4897,11 +4864,13 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
4897 struct ocfs2_extent_rec split_rec; 4864 struct ocfs2_extent_rec split_rec;
4898 struct ocfs2_path *left_path = NULL; 4865 struct ocfs2_path *left_path = NULL;
4899 struct ocfs2_extent_list *el; 4866 struct ocfs2_extent_list *el;
4900 struct ocfs2_extent_tree *et = NULL; 4867 struct ocfs2_extent_tree et;
4901 4868
4902 mlog(0, "Inode %lu cpos %u, len %u, phys %u (%llu)\n", 4869 mlog(0, "Inode %lu cpos %u, len %u, phys %u (%llu)\n",
4903 inode->i_ino, cpos, len, phys, (unsigned long long)start_blkno); 4870 inode->i_ino, cpos, len, phys, (unsigned long long)start_blkno);
4904 4871
4872 ocfs2_get_extent_tree(&et, inode, root_bh, et_type, private);
4873
4905 if (!ocfs2_writes_unwritten_extents(OCFS2_SB(inode->i_sb))) { 4874 if (!ocfs2_writes_unwritten_extents(OCFS2_SB(inode->i_sb))) {
4906 ocfs2_error(inode->i_sb, "Inode %llu has unwritten extents " 4875 ocfs2_error(inode->i_sb, "Inode %llu has unwritten extents "
4907 "that are being written to, but the feature bit " 4876 "that are being written to, but the feature bit "
@@ -4911,13 +4880,6 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
4911 goto out; 4880 goto out;
4912 } 4881 }
4913 4882
4914 et = ocfs2_new_extent_tree(inode, root_bh, et_type, private);
4915 if (!et) {
4916 ret = -ENOMEM;
4917 mlog_errno(ret);
4918 goto out;
4919 }
4920
4921 /* 4883 /*
4922 * XXX: This should be fixed up so that we just re-insert the 4884 * XXX: This should be fixed up so that we just re-insert the
4923 * next extent records. 4885 * next extent records.
@@ -4925,7 +4887,7 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
4925 if (et_type == OCFS2_DINODE_EXTENT) 4887 if (et_type == OCFS2_DINODE_EXTENT)
4926 ocfs2_extent_map_trunc(inode, 0); 4888 ocfs2_extent_map_trunc(inode, 0);
4927 4889
4928 left_path = ocfs2_new_path(et->et_root_bh, et->et_root_el); 4890 left_path = ocfs2_new_path(et.et_root_bh, et.et_root_el);
4929 if (!left_path) { 4891 if (!left_path) {
4930 ret = -ENOMEM; 4892 ret = -ENOMEM;
4931 mlog_errno(ret); 4893 mlog_errno(ret);
@@ -4956,7 +4918,7 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
4956 split_rec.e_flags = path_leaf_el(left_path)->l_recs[index].e_flags; 4918 split_rec.e_flags = path_leaf_el(left_path)->l_recs[index].e_flags;
4957 split_rec.e_flags &= ~OCFS2_EXT_UNWRITTEN; 4919 split_rec.e_flags &= ~OCFS2_EXT_UNWRITTEN;
4958 4920
4959 ret = __ocfs2_mark_extent_written(inode, et, handle, left_path, 4921 ret = __ocfs2_mark_extent_written(inode, &et, handle, left_path,
4960 index, &split_rec, meta_ac, 4922 index, &split_rec, meta_ac,
4961 dealloc); 4923 dealloc);
4962 if (ret) 4924 if (ret)
@@ -4964,8 +4926,7 @@ int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
4964 4926
4965out: 4927out:
4966 ocfs2_free_path(left_path); 4928 ocfs2_free_path(left_path);
4967 if (et) 4929 ocfs2_put_extent_tree(&et);
4968 ocfs2_free_extent_tree(et);
4969 return ret; 4930 return ret;
4970} 4931}
4971 4932
@@ -5207,18 +5168,13 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
5207 struct ocfs2_extent_rec *rec; 5168 struct ocfs2_extent_rec *rec;
5208 struct ocfs2_extent_list *el; 5169 struct ocfs2_extent_list *el;
5209 struct ocfs2_path *path = NULL; 5170 struct ocfs2_path *path = NULL;
5210 struct ocfs2_extent_tree *et = NULL; 5171 struct ocfs2_extent_tree et;
5211 5172
5212 et = ocfs2_new_extent_tree(inode, root_bh, et_type, private); 5173 ocfs2_get_extent_tree(&et, inode, root_bh, et_type, private);
5213 if (!et) {
5214 ret = -ENOMEM;
5215 mlog_errno(ret);
5216 goto out;
5217 }
5218 5174
5219 ocfs2_extent_map_trunc(inode, 0); 5175 ocfs2_extent_map_trunc(inode, 0);
5220 5176
5221 path = ocfs2_new_path(et->et_root_bh, et->et_root_el); 5177 path = ocfs2_new_path(et.et_root_bh, et.et_root_el);
5222 if (!path) { 5178 if (!path) {
5223 ret = -ENOMEM; 5179 ret = -ENOMEM;
5224 mlog_errno(ret); 5180 mlog_errno(ret);
@@ -5271,13 +5227,13 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
5271 5227
5272 if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) { 5228 if (le32_to_cpu(rec->e_cpos) == cpos || rec_range == trunc_range) {
5273 ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, 5229 ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc,
5274 cpos, len, et); 5230 cpos, len, &et);
5275 if (ret) { 5231 if (ret) {
5276 mlog_errno(ret); 5232 mlog_errno(ret);
5277 goto out; 5233 goto out;
5278 } 5234 }
5279 } else { 5235 } else {
5280 ret = ocfs2_split_tree(inode, et, handle, path, index, 5236 ret = ocfs2_split_tree(inode, &et, handle, path, index,
5281 trunc_range, meta_ac); 5237 trunc_range, meta_ac);
5282 if (ret) { 5238 if (ret) {
5283 mlog_errno(ret); 5239 mlog_errno(ret);
@@ -5326,7 +5282,7 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
5326 } 5282 }
5327 5283
5328 ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc, 5284 ret = ocfs2_truncate_rec(inode, handle, path, index, dealloc,
5329 cpos, len, et); 5285 cpos, len, &et);
5330 if (ret) { 5286 if (ret) {
5331 mlog_errno(ret); 5287 mlog_errno(ret);
5332 goto out; 5288 goto out;
@@ -5335,8 +5291,7 @@ int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
5335 5291
5336out: 5292out:
5337 ocfs2_free_path(path); 5293 ocfs2_free_path(path);
5338 if (et) 5294 ocfs2_put_extent_tree(&et);
5339 ocfs2_free_extent_tree(et);
5340 return ret; 5295 return ret;
5341} 5296}
5342 5297