aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/suballoc.c
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 /fs/ocfs2/suballoc.c
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>
Diffstat (limited to 'fs/ocfs2/suballoc.c')
-rw-r--r--fs/ocfs2/suballoc.c134
1 files changed, 54 insertions, 80 deletions
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,