aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Fasheh <mark.fasheh@oracle.com>2006-10-06 21:34:35 -0400
committerMark Fasheh <mark.fasheh@oracle.com>2006-12-01 21:27:49 -0500
commitda5cbf2f9df922cfdafa39351691fa83517f1e25 (patch)
tree845dc288b72f0408870f50605bb3c96eec978dd8
parent8d5596c687c49c1d8812c3456946dec15d069139 (diff)
ocfs2: don't use handle for locking in allocation functions
Instead we record our state on the allocation context structure which all callers already know about and lifetime correctly. This means the reservation functions don't need a handle passed in any more, and we can also take it off the alloc context. Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
-rw-r--r--fs/ocfs2/dir.c14
-rw-r--r--fs/ocfs2/file.c19
-rw-r--r--fs/ocfs2/localalloc.c26
-rw-r--r--fs/ocfs2/localalloc.h1
-rw-r--r--fs/ocfs2/namei.c26
-rw-r--r--fs/ocfs2/suballoc.c134
-rw-r--r--fs/ocfs2/suballoc.h4
7 files changed, 72 insertions, 152 deletions
diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c
index 04e01915b86e..d10ccea82fab 100644
--- a/fs/ocfs2/dir.c
+++ b/fs/ocfs2/dir.c
@@ -409,13 +409,6 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
409 mlog(0, "extending dir %llu (i_size = %lld)\n", 409 mlog(0, "extending dir %llu (i_size = %lld)\n",
410 (unsigned long long)OCFS2_I(dir)->ip_blkno, dir_i_size); 410 (unsigned long long)OCFS2_I(dir)->ip_blkno, dir_i_size);
411 411
412 handle = ocfs2_alloc_handle(osb);
413 if (handle == NULL) {
414 status = -ENOMEM;
415 mlog_errno(status);
416 goto bail;
417 }
418
419 /* dir->i_size is always block aligned. */ 412 /* dir->i_size is always block aligned. */
420 spin_lock(&OCFS2_I(dir)->ip_lock); 413 spin_lock(&OCFS2_I(dir)->ip_lock);
421 if (dir_i_size == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)) { 414 if (dir_i_size == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)) {
@@ -428,8 +421,7 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
428 } 421 }
429 422
430 if (!num_free_extents) { 423 if (!num_free_extents) {
431 status = ocfs2_reserve_new_metadata(osb, handle, 424 status = ocfs2_reserve_new_metadata(osb, fe, &meta_ac);
432 fe, &meta_ac);
433 if (status < 0) { 425 if (status < 0) {
434 if (status != -ENOSPC) 426 if (status != -ENOSPC)
435 mlog_errno(status); 427 mlog_errno(status);
@@ -437,7 +429,7 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
437 } 429 }
438 } 430 }
439 431
440 status = ocfs2_reserve_clusters(osb, handle, 1, &data_ac); 432 status = ocfs2_reserve_clusters(osb, 1, &data_ac);
441 if (status < 0) { 433 if (status < 0) {
442 if (status != -ENOSPC) 434 if (status != -ENOSPC)
443 mlog_errno(status); 435 mlog_errno(status);
@@ -450,7 +442,7 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
450 credits = OCFS2_SIMPLE_DIR_EXTEND_CREDITS; 442 credits = OCFS2_SIMPLE_DIR_EXTEND_CREDITS;
451 } 443 }
452 444
453 handle = ocfs2_start_trans(osb, handle, credits); 445 handle = ocfs2_start_trans(osb, NULL, credits);
454 if (IS_ERR(handle)) { 446 if (IS_ERR(handle)) {
455 status = PTR_ERR(handle); 447 status = PTR_ERR(handle);
456 handle = NULL; 448 handle = NULL;
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index d8bd2c32f08a..bd944e893bbe 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -463,13 +463,6 @@ restart_all:
463 (unsigned long long)OCFS2_I(inode)->ip_blkno, i_size_read(inode), 463 (unsigned long long)OCFS2_I(inode)->ip_blkno, i_size_read(inode),
464 fe->i_clusters, clusters_to_add); 464 fe->i_clusters, clusters_to_add);
465 465
466 handle = ocfs2_alloc_handle(osb);
467 if (handle == NULL) {
468 status = -ENOMEM;
469 mlog_errno(status);
470 goto leave;
471 }
472
473 num_free_extents = ocfs2_num_free_extents(osb, 466 num_free_extents = ocfs2_num_free_extents(osb,
474 inode, 467 inode,
475 fe); 468 fe);
@@ -480,10 +473,7 @@ restart_all:
480 } 473 }
481 474
482 if (!num_free_extents) { 475 if (!num_free_extents) {
483 status = ocfs2_reserve_new_metadata(osb, 476 status = ocfs2_reserve_new_metadata(osb, fe, &meta_ac);
484 handle,
485 fe,
486 &meta_ac);
487 if (status < 0) { 477 if (status < 0) {
488 if (status != -ENOSPC) 478 if (status != -ENOSPC)
489 mlog_errno(status); 479 mlog_errno(status);
@@ -491,10 +481,7 @@ restart_all:
491 } 481 }
492 } 482 }
493 483
494 status = ocfs2_reserve_clusters(osb, 484 status = ocfs2_reserve_clusters(osb, clusters_to_add, &data_ac);
495 handle,
496 clusters_to_add,
497 &data_ac);
498 if (status < 0) { 485 if (status < 0) {
499 if (status != -ENOSPC) 486 if (status != -ENOSPC)
500 mlog_errno(status); 487 mlog_errno(status);
@@ -509,7 +496,7 @@ restart_all:
509 drop_alloc_sem = 1; 496 drop_alloc_sem = 1;
510 497
511 credits = ocfs2_calc_extend_credits(osb->sb, fe, clusters_to_add); 498 credits = ocfs2_calc_extend_credits(osb->sb, fe, clusters_to_add);
512 handle = ocfs2_start_trans(osb, handle, credits); 499 handle = ocfs2_start_trans(osb, NULL, credits);
513 if (IS_ERR(handle)) { 500 if (IS_ERR(handle)) {
514 status = PTR_ERR(handle); 501 status = PTR_ERR(handle);
515 handle = NULL; 502 handle = NULL;
diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
index 75f09f1b4ced..869383e7c562 100644
--- a/fs/ocfs2/localalloc.c
+++ b/fs/ocfs2/localalloc.c
@@ -64,7 +64,6 @@ static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
64 struct buffer_head *main_bm_bh); 64 struct buffer_head *main_bm_bh);
65 65
66static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb, 66static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb,
67 struct ocfs2_journal_handle *handle,
68 struct ocfs2_alloc_context **ac, 67 struct ocfs2_alloc_context **ac,
69 struct inode **bitmap_inode, 68 struct inode **bitmap_inode,
70 struct buffer_head **bitmap_bh); 69 struct buffer_head **bitmap_bh);
@@ -448,7 +447,6 @@ out:
448 * our own in order to shift windows. 447 * our own in order to shift windows.
449 */ 448 */
450int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb, 449int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
451 struct ocfs2_journal_handle *passed_handle,
452 u32 bits_wanted, 450 u32 bits_wanted,
453 struct ocfs2_alloc_context *ac) 451 struct ocfs2_alloc_context *ac)
454{ 452{
@@ -459,9 +457,7 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
459 457
460 mlog_entry_void(); 458 mlog_entry_void();
461 459
462 BUG_ON(!passed_handle);
463 BUG_ON(!ac); 460 BUG_ON(!ac);
464 BUG_ON(passed_handle->k_handle);
465 461
466 local_alloc_inode = 462 local_alloc_inode =
467 ocfs2_get_system_file_inode(osb, 463 ocfs2_get_system_file_inode(osb,
@@ -472,7 +468,11 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
472 mlog_errno(status); 468 mlog_errno(status);
473 goto bail; 469 goto bail;
474 } 470 }
475 ocfs2_handle_add_inode(passed_handle, local_alloc_inode); 471
472 mutex_lock(&local_alloc_inode->i_mutex);
473
474 ac->ac_inode = local_alloc_inode;
475 ac->ac_which = OCFS2_AC_USE_LOCAL;
476 476
477 if (osb->local_alloc_state != OCFS2_LA_ENABLED) { 477 if (osb->local_alloc_state != OCFS2_LA_ENABLED) {
478 status = -ENOSPC; 478 status = -ENOSPC;
@@ -511,14 +511,10 @@ int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
511 } 511 }
512 } 512 }
513 513
514 ac->ac_inode = igrab(local_alloc_inode);
515 get_bh(osb->local_alloc_bh); 514 get_bh(osb->local_alloc_bh);
516 ac->ac_bh = osb->local_alloc_bh; 515 ac->ac_bh = osb->local_alloc_bh;
517 ac->ac_which = OCFS2_AC_USE_LOCAL;
518 status = 0; 516 status = 0;
519bail: 517bail:
520 if (local_alloc_inode)
521 iput(local_alloc_inode);
522 518
523 mlog_exit(status); 519 mlog_exit(status);
524 return status; 520 return status;
@@ -774,7 +770,6 @@ bail:
774} 770}
775 771
776static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb, 772static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb,
777 struct ocfs2_journal_handle *handle,
778 struct ocfs2_alloc_context **ac, 773 struct ocfs2_alloc_context **ac,
779 struct inode **bitmap_inode, 774 struct inode **bitmap_inode,
780 struct buffer_head **bitmap_bh) 775 struct buffer_head **bitmap_bh)
@@ -788,7 +783,6 @@ static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb,
788 goto bail; 783 goto bail;
789 } 784 }
790 785
791 (*ac)->ac_handle = handle;
792 (*ac)->ac_bits_wanted = ocfs2_local_alloc_window_bits(osb); 786 (*ac)->ac_bits_wanted = ocfs2_local_alloc_window_bits(osb);
793 787
794 status = ocfs2_reserve_cluster_bitmap_bits(osb, *ac); 788 status = ocfs2_reserve_cluster_bitmap_bits(osb, *ac);
@@ -891,16 +885,8 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
891 885
892 mlog_entry_void(); 886 mlog_entry_void();
893 887
894 handle = ocfs2_alloc_handle(osb);
895 if (!handle) {
896 status = -ENOMEM;
897 mlog_errno(status);
898 goto bail;
899 }
900
901 /* This will lock the main bitmap for us. */ 888 /* This will lock the main bitmap for us. */
902 status = ocfs2_local_alloc_reserve_for_window(osb, 889 status = ocfs2_local_alloc_reserve_for_window(osb,
903 handle,
904 &ac, 890 &ac,
905 &main_bm_inode, 891 &main_bm_inode,
906 &main_bm_bh); 892 &main_bm_bh);
@@ -910,7 +896,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
910 goto bail; 896 goto bail;
911 } 897 }
912 898
913 handle = ocfs2_start_trans(osb, handle, OCFS2_WINDOW_MOVE_CREDITS); 899 handle = ocfs2_start_trans(osb, NULL, OCFS2_WINDOW_MOVE_CREDITS);
914 if (IS_ERR(handle)) { 900 if (IS_ERR(handle)) {
915 status = PTR_ERR(handle); 901 status = PTR_ERR(handle);
916 handle = NULL; 902 handle = NULL;
diff --git a/fs/ocfs2/localalloc.h b/fs/ocfs2/localalloc.h
index 30f88ce14e46..4bd624ce380a 100644
--- a/fs/ocfs2/localalloc.h
+++ b/fs/ocfs2/localalloc.h
@@ -42,7 +42,6 @@ int ocfs2_alloc_should_use_local(struct ocfs2_super *osb,
42 42
43struct ocfs2_alloc_context; 43struct ocfs2_alloc_context;
44int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb, 44int ocfs2_reserve_local_alloc_bits(struct ocfs2_super *osb,
45 struct ocfs2_journal_handle *passed_handle,
46 u32 bits_wanted, 45 u32 bits_wanted,
47 struct ocfs2_alloc_context *ac); 46 struct ocfs2_alloc_context *ac);
48 47
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index 5bd5f9948a2f..ca012446d8e7 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -334,13 +334,6 @@ static int ocfs2_mknod(struct inode *dir,
334 return status; 334 return status;
335 } 335 }
336 336
337 handle = ocfs2_alloc_handle(osb);
338 if (handle == NULL) {
339 status = -ENOMEM;
340 mlog_errno(status);
341 goto leave;
342 }
343
344 if (S_ISDIR(mode) && (dir->i_nlink >= OCFS2_LINK_MAX)) { 337 if (S_ISDIR(mode) && (dir->i_nlink >= OCFS2_LINK_MAX)) {
345 status = -EMLINK; 338 status = -EMLINK;
346 goto leave; 339 goto leave;
@@ -368,7 +361,7 @@ static int ocfs2_mknod(struct inode *dir,
368 } 361 }
369 362
370 /* reserve an inode spot */ 363 /* reserve an inode spot */
371 status = ocfs2_reserve_new_inode(osb, handle, &inode_ac); 364 status = ocfs2_reserve_new_inode(osb, &inode_ac);
372 if (status < 0) { 365 if (status < 0) {
373 if (status != -ENOSPC) 366 if (status != -ENOSPC)
374 mlog_errno(status); 367 mlog_errno(status);
@@ -378,7 +371,7 @@ static int ocfs2_mknod(struct inode *dir,
378 /* are we making a directory? If so, reserve a cluster for his 371 /* are we making a directory? If so, reserve a cluster for his
379 * 1st extent. */ 372 * 1st extent. */
380 if (S_ISDIR(mode)) { 373 if (S_ISDIR(mode)) {
381 status = ocfs2_reserve_clusters(osb, handle, 1, &data_ac); 374 status = ocfs2_reserve_clusters(osb, 1, &data_ac);
382 if (status < 0) { 375 if (status < 0) {
383 if (status != -ENOSPC) 376 if (status != -ENOSPC)
384 mlog_errno(status); 377 mlog_errno(status);
@@ -386,7 +379,7 @@ static int ocfs2_mknod(struct inode *dir,
386 } 379 }
387 } 380 }
388 381
389 handle = ocfs2_start_trans(osb, handle, OCFS2_MKNOD_CREDITS); 382 handle = ocfs2_start_trans(osb, NULL, OCFS2_MKNOD_CREDITS);
390 if (IS_ERR(handle)) { 383 if (IS_ERR(handle)) {
391 status = PTR_ERR(handle); 384 status = PTR_ERR(handle);
392 handle = NULL; 385 handle = NULL;
@@ -1649,14 +1642,7 @@ static int ocfs2_symlink(struct inode *dir,
1649 goto bail; 1642 goto bail;
1650 } 1643 }
1651 1644
1652 handle = ocfs2_alloc_handle(osb); 1645 status = ocfs2_reserve_new_inode(osb, &inode_ac);
1653 if (handle == NULL) {
1654 status = -ENOMEM;
1655 mlog_errno(status);
1656 goto bail;
1657 }
1658
1659 status = ocfs2_reserve_new_inode(osb, handle, &inode_ac);
1660 if (status < 0) { 1646 if (status < 0) {
1661 if (status != -ENOSPC) 1647 if (status != -ENOSPC)
1662 mlog_errno(status); 1648 mlog_errno(status);
@@ -1665,7 +1651,7 @@ static int ocfs2_symlink(struct inode *dir,
1665 1651
1666 /* don't reserve bitmap space for fast symlinks. */ 1652 /* don't reserve bitmap space for fast symlinks. */
1667 if (l > ocfs2_fast_symlink_chars(sb)) { 1653 if (l > ocfs2_fast_symlink_chars(sb)) {
1668 status = ocfs2_reserve_clusters(osb, handle, 1, &data_ac); 1654 status = ocfs2_reserve_clusters(osb, 1, &data_ac);
1669 if (status < 0) { 1655 if (status < 0) {
1670 if (status != -ENOSPC) 1656 if (status != -ENOSPC)
1671 mlog_errno(status); 1657 mlog_errno(status);
@@ -1673,7 +1659,7 @@ static int ocfs2_symlink(struct inode *dir,
1673 } 1659 }
1674 } 1660 }
1675 1661
1676 handle = ocfs2_start_trans(osb, handle, credits); 1662 handle = ocfs2_start_trans(osb, NULL, credits);
1677 if (IS_ERR(handle)) { 1663 if (IS_ERR(handle)) {
1678 status = PTR_ERR(handle); 1664 status = PTR_ERR(handle);
1679 handle = NULL; 1665 handle = NULL;
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
index 32093409e256..31bda54fefe3 100644
--- a/fs/ocfs2/suballoc.c
+++ b/fs/ocfs2/suballoc.c
@@ -59,9 +59,6 @@ static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
59 struct inode *alloc_inode, 59 struct inode *alloc_inode,
60 struct buffer_head *bh); 60 struct buffer_head *bh);
61 61
62static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
63 struct ocfs2_alloc_context *ac);
64
65static int ocfs2_cluster_group_search(struct inode *inode, 62static int ocfs2_cluster_group_search(struct inode *inode,
66 struct buffer_head *group_bh, 63 struct buffer_head *group_bh,
67 u32 bits_wanted, u32 min_bits, 64 u32 bits_wanted, u32 min_bits,
@@ -72,6 +69,7 @@ static int ocfs2_block_group_search(struct inode *inode,
72 u16 *bit_off, u16 *bits_found); 69 u16 *bit_off, u16 *bits_found);
73static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb, 70static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb,
74 struct ocfs2_alloc_context *ac, 71 struct ocfs2_alloc_context *ac,
72 struct ocfs2_journal_handle *handle,
75 u32 bits_wanted, 73 u32 bits_wanted,
76 u32 min_bits, 74 u32 min_bits,
77 u16 *bit_off, 75 u16 *bit_off,
@@ -120,8 +118,16 @@ static inline void ocfs2_block_to_cluster_group(struct inode *inode,
120 118
121void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac) 119void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac)
122{ 120{
123 if (ac->ac_inode) 121 struct inode *inode = ac->ac_inode;
124 iput(ac->ac_inode); 122
123 if (inode) {
124 if (ac->ac_which != OCFS2_AC_USE_LOCAL)
125 ocfs2_meta_unlock(inode, 1);
126
127 mutex_unlock(&inode->i_mutex);
128
129 iput(inode);
130 }
125 if (ac->ac_bh) 131 if (ac->ac_bh)
126 brelse(ac->ac_bh); 132 brelse(ac->ac_bh);
127 kfree(ac); 133 kfree(ac);
@@ -284,16 +290,8 @@ static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
284 290
285 mlog_entry_void(); 291 mlog_entry_void();
286 292
287 handle = ocfs2_alloc_handle(osb);
288 if (!handle) {
289 status = -ENOMEM;
290 mlog_errno(status);
291 goto bail;
292 }
293
294 cl = &fe->id2.i_chain; 293 cl = &fe->id2.i_chain;
295 status = ocfs2_reserve_clusters(osb, 294 status = ocfs2_reserve_clusters(osb,
296 handle,
297 le16_to_cpu(cl->cl_cpg), 295 le16_to_cpu(cl->cl_cpg),
298 &ac); 296 &ac);
299 if (status < 0) { 297 if (status < 0) {
@@ -402,27 +400,38 @@ bail:
402} 400}
403 401
404static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb, 402static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
405 struct ocfs2_alloc_context *ac) 403 struct ocfs2_alloc_context *ac,
404 int type,
405 u32 slot)
406{ 406{
407 int status; 407 int status;
408 u32 bits_wanted = ac->ac_bits_wanted; 408 u32 bits_wanted = ac->ac_bits_wanted;
409 struct inode *alloc_inode = ac->ac_inode; 409 struct inode *alloc_inode;
410 struct buffer_head *bh = NULL; 410 struct buffer_head *bh = NULL;
411 struct ocfs2_journal_handle *handle = ac->ac_handle;
412 struct ocfs2_dinode *fe; 411 struct ocfs2_dinode *fe;
413 u32 free_bits; 412 u32 free_bits;
414 413
415 mlog_entry_void(); 414 mlog_entry_void();
416 415
417 BUG_ON(handle->k_handle); 416 alloc_inode = ocfs2_get_system_file_inode(osb, type, slot);
417 if (!alloc_inode) {
418 mlog_errno(-EINVAL);
419 return -EINVAL;
420 }
418 421
419 ocfs2_handle_add_inode(handle, alloc_inode); 422 mutex_lock(&alloc_inode->i_mutex);
420 status = ocfs2_meta_lock(alloc_inode, handle, &bh, 1); 423
424 status = ocfs2_meta_lock(alloc_inode, NULL, &bh, 1);
421 if (status < 0) { 425 if (status < 0) {
426 mutex_unlock(&alloc_inode->i_mutex);
427 iput(alloc_inode);
428
422 mlog_errno(status); 429 mlog_errno(status);
423 goto bail; 430 return status;
424 } 431 }
425 432
433 ac->ac_inode = alloc_inode;
434
426 fe = (struct ocfs2_dinode *) bh->b_data; 435 fe = (struct ocfs2_dinode *) bh->b_data;
427 if (!OCFS2_IS_VALID_DINODE(fe)) { 436 if (!OCFS2_IS_VALID_DINODE(fe)) {
428 OCFS2_RO_ON_INVALID_DINODE(alloc_inode->i_sb, fe); 437 OCFS2_RO_ON_INVALID_DINODE(alloc_inode->i_sb, fe);
@@ -473,12 +482,11 @@ bail:
473} 482}
474 483
475int ocfs2_reserve_new_metadata(struct ocfs2_super *osb, 484int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
476 struct ocfs2_journal_handle *handle,
477 struct ocfs2_dinode *fe, 485 struct ocfs2_dinode *fe,
478 struct ocfs2_alloc_context **ac) 486 struct ocfs2_alloc_context **ac)
479{ 487{
480 int status; 488 int status;
481 struct inode *alloc_inode = NULL; 489 u32 slot;
482 490
483 *ac = kcalloc(1, sizeof(struct ocfs2_alloc_context), GFP_KERNEL); 491 *ac = kcalloc(1, sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
484 if (!(*ac)) { 492 if (!(*ac)) {
@@ -488,28 +496,18 @@ int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
488 } 496 }
489 497
490 (*ac)->ac_bits_wanted = ocfs2_extend_meta_needed(fe); 498 (*ac)->ac_bits_wanted = ocfs2_extend_meta_needed(fe);
491 (*ac)->ac_handle = handle;
492 (*ac)->ac_which = OCFS2_AC_USE_META; 499 (*ac)->ac_which = OCFS2_AC_USE_META;
493 500
494#ifndef OCFS2_USE_ALL_METADATA_SUBALLOCATORS 501#ifndef OCFS2_USE_ALL_METADATA_SUBALLOCATORS
495 alloc_inode = ocfs2_get_system_file_inode(osb, 502 slot = 0;
496 EXTENT_ALLOC_SYSTEM_INODE,
497 0);
498#else 503#else
499 alloc_inode = ocfs2_get_system_file_inode(osb, 504 slot = osb->slot_num;
500 EXTENT_ALLOC_SYSTEM_INODE,
501 osb->slot_num);
502#endif 505#endif
503 if (!alloc_inode) {
504 status = -ENOMEM;
505 mlog_errno(status);
506 goto bail;
507 }
508 506
509 (*ac)->ac_inode = igrab(alloc_inode);
510 (*ac)->ac_group_search = ocfs2_block_group_search; 507 (*ac)->ac_group_search = ocfs2_block_group_search;
511 508
512 status = ocfs2_reserve_suballoc_bits(osb, (*ac)); 509 status = ocfs2_reserve_suballoc_bits(osb, (*ac),
510 EXTENT_ALLOC_SYSTEM_INODE, slot);
513 if (status < 0) { 511 if (status < 0) {
514 if (status != -ENOSPC) 512 if (status != -ENOSPC)
515 mlog_errno(status); 513 mlog_errno(status);
@@ -523,19 +521,14 @@ bail:
523 *ac = NULL; 521 *ac = NULL;
524 } 522 }
525 523
526 if (alloc_inode)
527 iput(alloc_inode);
528
529 mlog_exit(status); 524 mlog_exit(status);
530 return status; 525 return status;
531} 526}
532 527
533int ocfs2_reserve_new_inode(struct ocfs2_super *osb, 528int ocfs2_reserve_new_inode(struct ocfs2_super *osb,
534 struct ocfs2_journal_handle *handle,
535 struct ocfs2_alloc_context **ac) 529 struct ocfs2_alloc_context **ac)
536{ 530{
537 int status; 531 int status;
538 struct inode *alloc_inode = NULL;
539 532
540 *ac = kcalloc(1, sizeof(struct ocfs2_alloc_context), GFP_KERNEL); 533 *ac = kcalloc(1, sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
541 if (!(*ac)) { 534 if (!(*ac)) {
@@ -545,22 +538,13 @@ int ocfs2_reserve_new_inode(struct ocfs2_super *osb,
545 } 538 }
546 539
547 (*ac)->ac_bits_wanted = 1; 540 (*ac)->ac_bits_wanted = 1;
548 (*ac)->ac_handle = handle;
549 (*ac)->ac_which = OCFS2_AC_USE_INODE; 541 (*ac)->ac_which = OCFS2_AC_USE_INODE;
550 542
551 alloc_inode = ocfs2_get_system_file_inode(osb,
552 INODE_ALLOC_SYSTEM_INODE,
553 osb->slot_num);
554 if (!alloc_inode) {
555 status = -ENOMEM;
556 mlog_errno(status);
557 goto bail;
558 }
559
560 (*ac)->ac_inode = igrab(alloc_inode);
561 (*ac)->ac_group_search = ocfs2_block_group_search; 543 (*ac)->ac_group_search = ocfs2_block_group_search;
562 544
563 status = ocfs2_reserve_suballoc_bits(osb, *ac); 545 status = ocfs2_reserve_suballoc_bits(osb, *ac,
546 INODE_ALLOC_SYSTEM_INODE,
547 osb->slot_num);
564 if (status < 0) { 548 if (status < 0) {
565 if (status != -ENOSPC) 549 if (status != -ENOSPC)
566 mlog_errno(status); 550 mlog_errno(status);
@@ -574,9 +558,6 @@ bail:
574 *ac = NULL; 558 *ac = NULL;
575 } 559 }
576 560
577 if (alloc_inode)
578 iput(alloc_inode);
579
580 mlog_exit(status); 561 mlog_exit(status);
581 return status; 562 return status;
582} 563}
@@ -588,20 +569,17 @@ int ocfs2_reserve_cluster_bitmap_bits(struct ocfs2_super *osb,
588{ 569{
589 int status; 570 int status;
590 571
591 ac->ac_inode = ocfs2_get_system_file_inode(osb,
592 GLOBAL_BITMAP_SYSTEM_INODE,
593 OCFS2_INVALID_SLOT);
594 if (!ac->ac_inode) {
595 status = -EINVAL;
596 mlog(ML_ERROR, "Could not get bitmap inode!\n");
597 goto bail;
598 }
599 ac->ac_which = OCFS2_AC_USE_MAIN; 572 ac->ac_which = OCFS2_AC_USE_MAIN;
600 ac->ac_group_search = ocfs2_cluster_group_search; 573 ac->ac_group_search = ocfs2_cluster_group_search;
601 574
602 status = ocfs2_reserve_suballoc_bits(osb, ac); 575 status = ocfs2_reserve_suballoc_bits(osb, ac,
603 if (status < 0 && status != -ENOSPC) 576 GLOBAL_BITMAP_SYSTEM_INODE,
577 OCFS2_INVALID_SLOT);
578 if (status < 0 && status != -ENOSPC) {
604 mlog_errno(status); 579 mlog_errno(status);
580 goto bail;
581 }
582
605bail: 583bail:
606 return status; 584 return status;
607} 585}
@@ -610,7 +588,6 @@ bail:
610 * use so we figure it out for them, but unfortunately this clutters 588 * use so we figure it out for them, but unfortunately this clutters
611 * things a bit. */ 589 * things a bit. */
612int ocfs2_reserve_clusters(struct ocfs2_super *osb, 590int ocfs2_reserve_clusters(struct ocfs2_super *osb,
613 struct ocfs2_journal_handle *handle,
614 u32 bits_wanted, 591 u32 bits_wanted,
615 struct ocfs2_alloc_context **ac) 592 struct ocfs2_alloc_context **ac)
616{ 593{
@@ -618,8 +595,6 @@ int ocfs2_reserve_clusters(struct ocfs2_super *osb,
618 595
619 mlog_entry_void(); 596 mlog_entry_void();
620 597
621 BUG_ON(!handle);
622
623 *ac = kcalloc(1, sizeof(struct ocfs2_alloc_context), GFP_KERNEL); 598 *ac = kcalloc(1, sizeof(struct ocfs2_alloc_context), GFP_KERNEL);
624 if (!(*ac)) { 599 if (!(*ac)) {
625 status = -ENOMEM; 600 status = -ENOMEM;
@@ -628,12 +603,10 @@ int ocfs2_reserve_clusters(struct ocfs2_super *osb,
628 } 603 }
629 604
630 (*ac)->ac_bits_wanted = bits_wanted; 605 (*ac)->ac_bits_wanted = bits_wanted;
631 (*ac)->ac_handle = handle;
632 606
633 status = -ENOSPC; 607 status = -ENOSPC;
634 if (ocfs2_alloc_should_use_local(osb, bits_wanted)) { 608 if (ocfs2_alloc_should_use_local(osb, bits_wanted)) {
635 status = ocfs2_reserve_local_alloc_bits(osb, 609 status = ocfs2_reserve_local_alloc_bits(osb,
636 handle,
637 bits_wanted, 610 bits_wanted,
638 *ac); 611 *ac);
639 if ((status < 0) && (status != -ENOSPC)) { 612 if ((status < 0) && (status != -ENOSPC)) {
@@ -1055,6 +1028,7 @@ out:
1055} 1028}
1056 1029
1057static int ocfs2_search_one_group(struct ocfs2_alloc_context *ac, 1030static int ocfs2_search_one_group(struct ocfs2_alloc_context *ac,
1031 struct ocfs2_journal_handle *handle,
1058 u32 bits_wanted, 1032 u32 bits_wanted,
1059 u32 min_bits, 1033 u32 min_bits,
1060 u16 *bit_off, 1034 u16 *bit_off,
@@ -1067,7 +1041,6 @@ static int ocfs2_search_one_group(struct ocfs2_alloc_context *ac,
1067 struct buffer_head *group_bh = NULL; 1041 struct buffer_head *group_bh = NULL;
1068 struct ocfs2_group_desc *gd; 1042 struct ocfs2_group_desc *gd;
1069 struct inode *alloc_inode = ac->ac_inode; 1043 struct inode *alloc_inode = ac->ac_inode;
1070 struct ocfs2_journal_handle *handle = ac->ac_handle;
1071 1044
1072 ret = ocfs2_read_block(OCFS2_SB(alloc_inode->i_sb), gd_blkno, 1045 ret = ocfs2_read_block(OCFS2_SB(alloc_inode->i_sb), gd_blkno,
1073 &group_bh, OCFS2_BH_CACHED, alloc_inode); 1046 &group_bh, OCFS2_BH_CACHED, alloc_inode);
@@ -1115,6 +1088,7 @@ out:
1115} 1088}
1116 1089
1117static int ocfs2_search_chain(struct ocfs2_alloc_context *ac, 1090static int ocfs2_search_chain(struct ocfs2_alloc_context *ac,
1091 struct ocfs2_journal_handle *handle,
1118 u32 bits_wanted, 1092 u32 bits_wanted,
1119 u32 min_bits, 1093 u32 min_bits,
1120 u16 *bit_off, 1094 u16 *bit_off,
@@ -1126,7 +1100,6 @@ static int ocfs2_search_chain(struct ocfs2_alloc_context *ac,
1126 u16 chain, tmp_bits; 1100 u16 chain, tmp_bits;
1127 u32 tmp_used; 1101 u32 tmp_used;
1128 u64 next_group; 1102 u64 next_group;
1129 struct ocfs2_journal_handle *handle = ac->ac_handle;
1130 struct inode *alloc_inode = ac->ac_inode; 1103 struct inode *alloc_inode = ac->ac_inode;
1131 struct buffer_head *group_bh = NULL; 1104 struct buffer_head *group_bh = NULL;
1132 struct buffer_head *prev_group_bh = NULL; 1105 struct buffer_head *prev_group_bh = NULL;
@@ -1272,6 +1245,7 @@ bail:
1272/* will give out up to bits_wanted contiguous bits. */ 1245/* will give out up to bits_wanted contiguous bits. */
1273static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb, 1246static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb,
1274 struct ocfs2_alloc_context *ac, 1247 struct ocfs2_alloc_context *ac,
1248 struct ocfs2_journal_handle *handle,
1275 u32 bits_wanted, 1249 u32 bits_wanted,
1276 u32 min_bits, 1250 u32 min_bits,
1277 u16 *bit_off, 1251 u16 *bit_off,
@@ -1313,8 +1287,8 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb,
1313 * by jumping straight to the most recently used 1287 * by jumping straight to the most recently used
1314 * allocation group. This helps us mantain some 1288 * allocation group. This helps us mantain some
1315 * contiguousness across allocations. */ 1289 * contiguousness across allocations. */
1316 status = ocfs2_search_one_group(ac, bits_wanted, min_bits, 1290 status = ocfs2_search_one_group(ac, handle, bits_wanted,
1317 bit_off, num_bits, 1291 min_bits, bit_off, num_bits,
1318 hint_blkno, &bits_left); 1292 hint_blkno, &bits_left);
1319 if (!status) { 1293 if (!status) {
1320 /* Be careful to update *bg_blkno here as the 1294 /* Be careful to update *bg_blkno here as the
@@ -1336,7 +1310,7 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb,
1336 ac->ac_chain = victim; 1310 ac->ac_chain = victim;
1337 ac->ac_allow_chain_relink = 1; 1311 ac->ac_allow_chain_relink = 1;
1338 1312
1339 status = ocfs2_search_chain(ac, bits_wanted, min_bits, bit_off, 1313 status = ocfs2_search_chain(ac, handle, bits_wanted, min_bits, bit_off,
1340 num_bits, bg_blkno, &bits_left); 1314 num_bits, bg_blkno, &bits_left);
1341 if (!status) 1315 if (!status)
1342 goto set_hint; 1316 goto set_hint;
@@ -1360,7 +1334,7 @@ static int ocfs2_claim_suballoc_bits(struct ocfs2_super *osb,
1360 continue; 1334 continue;
1361 1335
1362 ac->ac_chain = i; 1336 ac->ac_chain = i;
1363 status = ocfs2_search_chain(ac, bits_wanted, min_bits, 1337 status = ocfs2_search_chain(ac, handle, bits_wanted, min_bits,
1364 bit_off, num_bits, bg_blkno, 1338 bit_off, num_bits, bg_blkno,
1365 &bits_left); 1339 &bits_left);
1366 if (!status) 1340 if (!status)
@@ -1401,10 +1375,10 @@ int ocfs2_claim_metadata(struct ocfs2_super *osb,
1401 BUG_ON(!ac); 1375 BUG_ON(!ac);
1402 BUG_ON(ac->ac_bits_wanted < (ac->ac_bits_given + bits_wanted)); 1376 BUG_ON(ac->ac_bits_wanted < (ac->ac_bits_given + bits_wanted));
1403 BUG_ON(ac->ac_which != OCFS2_AC_USE_META); 1377 BUG_ON(ac->ac_which != OCFS2_AC_USE_META);
1404 BUG_ON(ac->ac_handle != handle);
1405 1378
1406 status = ocfs2_claim_suballoc_bits(osb, 1379 status = ocfs2_claim_suballoc_bits(osb,
1407 ac, 1380 ac,
1381 handle,
1408 bits_wanted, 1382 bits_wanted,
1409 1, 1383 1,
1410 suballoc_bit_start, 1384 suballoc_bit_start,
@@ -1440,10 +1414,10 @@ int ocfs2_claim_new_inode(struct ocfs2_super *osb,
1440 BUG_ON(ac->ac_bits_given != 0); 1414 BUG_ON(ac->ac_bits_given != 0);
1441 BUG_ON(ac->ac_bits_wanted != 1); 1415 BUG_ON(ac->ac_bits_wanted != 1);
1442 BUG_ON(ac->ac_which != OCFS2_AC_USE_INODE); 1416 BUG_ON(ac->ac_which != OCFS2_AC_USE_INODE);
1443 BUG_ON(ac->ac_handle != handle);
1444 1417
1445 status = ocfs2_claim_suballoc_bits(osb, 1418 status = ocfs2_claim_suballoc_bits(osb,
1446 ac, 1419 ac,
1420 handle,
1447 1, 1421 1,
1448 1, 1422 1,
1449 suballoc_bit, 1423 suballoc_bit,
@@ -1546,7 +1520,6 @@ int ocfs2_claim_clusters(struct ocfs2_super *osb,
1546 1520
1547 BUG_ON(ac->ac_which != OCFS2_AC_USE_LOCAL 1521 BUG_ON(ac->ac_which != OCFS2_AC_USE_LOCAL
1548 && ac->ac_which != OCFS2_AC_USE_MAIN); 1522 && ac->ac_which != OCFS2_AC_USE_MAIN);
1549 BUG_ON(ac->ac_handle != handle);
1550 1523
1551 if (ac->ac_which == OCFS2_AC_USE_LOCAL) { 1524 if (ac->ac_which == OCFS2_AC_USE_LOCAL) {
1552 status = ocfs2_claim_local_alloc_bits(osb, 1525 status = ocfs2_claim_local_alloc_bits(osb,
@@ -1572,6 +1545,7 @@ int ocfs2_claim_clusters(struct ocfs2_super *osb,
1572 1545
1573 status = ocfs2_claim_suballoc_bits(osb, 1546 status = ocfs2_claim_suballoc_bits(osb,
1574 ac, 1547 ac,
1548 handle,
1575 bits_wanted, 1549 bits_wanted,
1576 min_clusters, 1550 min_clusters,
1577 &bg_bit_off, 1551 &bg_bit_off,
diff --git a/fs/ocfs2/suballoc.h b/fs/ocfs2/suballoc.h
index c787838d1052..e7c4b277c8d6 100644
--- a/fs/ocfs2/suballoc.h
+++ b/fs/ocfs2/suballoc.h
@@ -43,7 +43,6 @@ struct ocfs2_alloc_context {
43#define OCFS2_AC_USE_INODE 3 43#define OCFS2_AC_USE_INODE 3
44#define OCFS2_AC_USE_META 4 44#define OCFS2_AC_USE_META 4
45 u32 ac_which; 45 u32 ac_which;
46 struct ocfs2_journal_handle *ac_handle;
47 46
48 /* these are used by the chain search */ 47 /* these are used by the chain search */
49 u16 ac_chain; 48 u16 ac_chain;
@@ -60,14 +59,11 @@ static inline int ocfs2_alloc_context_bits_left(struct ocfs2_alloc_context *ac)
60} 59}
61 60
62int ocfs2_reserve_new_metadata(struct ocfs2_super *osb, 61int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
63 struct ocfs2_journal_handle *handle,
64 struct ocfs2_dinode *fe, 62 struct ocfs2_dinode *fe,
65 struct ocfs2_alloc_context **ac); 63 struct ocfs2_alloc_context **ac);
66int ocfs2_reserve_new_inode(struct ocfs2_super *osb, 64int ocfs2_reserve_new_inode(struct ocfs2_super *osb,
67 struct ocfs2_journal_handle *handle,
68 struct ocfs2_alloc_context **ac); 65 struct ocfs2_alloc_context **ac);
69int ocfs2_reserve_clusters(struct ocfs2_super *osb, 66int ocfs2_reserve_clusters(struct ocfs2_super *osb,
70 struct ocfs2_journal_handle *handle,
71 u32 bits_wanted, 67 u32 bits_wanted,
72 struct ocfs2_alloc_context **ac); 68 struct ocfs2_alloc_context **ac);
73 69