diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-07-30 16:37:53 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-07-30 16:37:53 -0400 |
commit | 37cd9600a9e20359b0283983c9e3a55d84347168 (patch) | |
tree | fea12ce0ecbaf417b0d835b3cbee14e973103fad /fs/xfs/xfs_ialloc.c | |
parent | 95b18e69950ca7fd9acfa55964e929f58bec9379 (diff) | |
parent | 9a57fa8ee7c29e11c2a29ce058573ba99157eda7 (diff) |
Merge tag 'for-linus-v3.6-rc1' of git://oss.sgi.com/xfs/xfs
Pull xfs update from Ben Myers:
"Numerous cleanups and several bug fixes. Here are some highlights:
- Discontiguous directory buffer support
- Inode allocator refactoring
- Removal of the IO lock in inode reclaim
- Implementation of .update_time
- Fix for handling of EOF in xfs_vm_writepage
- Fix for races in xfsaild, and idle mode is re-enabled
- Fix for a crash in xfs_buf completion handlers on unmount."
Fix up trivial conflicts in fs/xfs/{xfs_buf.c,xfs_log.c,xfs_log_priv.h}
due to duplicate patches that had already been merged for 3.5.
* tag 'for-linus-v3.6-rc1' of git://oss.sgi.com/xfs/xfs: (44 commits)
xfs: wait for the write the superblock on unmount
xfs: re-enable xfsaild idle mode and fix associated races
xfs: remove iolock lock classes
xfs: avoid the iolock in xfs_free_eofblocks for evicted inodes
xfs: do not take the iolock in xfs_inactive
xfs: remove xfs_inactive_attrs
xfs: clean up xfs_inactive
xfs: do not read the AGI buffer in xfs_dialloc until nessecary
xfs: refactor xfs_ialloc_ag_select
xfs: add a short cut to xfs_dialloc for the non-NULL agbp case
xfs: remove the alloc_done argument to xfs_dialloc
xfs: split xfs_dialloc
xfs: remove xfs_ialloc_find_free
Prefix IO_XX flags with XFS_IO_XX to avoid namespace colision.
xfs: remove xfs_inotobp
xfs: merge xfs_itobp into xfs_imap_to_bp
xfs: handle EOF correctly in xfs_vm_writepage
xfs: implement ->update_time
xfs: fix comment typo of struct xfs_da_blkinfo.
xfs: do not call xfs_bdstrat_cb in xfs_buf_iodone_callbacks
...
Diffstat (limited to 'fs/xfs/xfs_ialloc.c')
-rw-r--r-- | fs/xfs/xfs_ialloc.c | 446 |
1 files changed, 222 insertions, 224 deletions
diff --git a/fs/xfs/xfs_ialloc.c b/fs/xfs/xfs_ialloc.c index 177a21a7ac49..21e37b55f7e5 100644 --- a/fs/xfs/xfs_ialloc.c +++ b/fs/xfs/xfs_ialloc.c | |||
@@ -442,14 +442,13 @@ xfs_ialloc_next_ag( | |||
442 | * Select an allocation group to look for a free inode in, based on the parent | 442 | * Select an allocation group to look for a free inode in, based on the parent |
443 | * inode and then mode. Return the allocation group buffer. | 443 | * inode and then mode. Return the allocation group buffer. |
444 | */ | 444 | */ |
445 | STATIC xfs_buf_t * /* allocation group buffer */ | 445 | STATIC xfs_agnumber_t |
446 | xfs_ialloc_ag_select( | 446 | xfs_ialloc_ag_select( |
447 | xfs_trans_t *tp, /* transaction pointer */ | 447 | xfs_trans_t *tp, /* transaction pointer */ |
448 | xfs_ino_t parent, /* parent directory inode number */ | 448 | xfs_ino_t parent, /* parent directory inode number */ |
449 | umode_t mode, /* bits set to indicate file type */ | 449 | umode_t mode, /* bits set to indicate file type */ |
450 | int okalloc) /* ok to allocate more space */ | 450 | int okalloc) /* ok to allocate more space */ |
451 | { | 451 | { |
452 | xfs_buf_t *agbp; /* allocation group header buffer */ | ||
453 | xfs_agnumber_t agcount; /* number of ag's in the filesystem */ | 452 | xfs_agnumber_t agcount; /* number of ag's in the filesystem */ |
454 | xfs_agnumber_t agno; /* current ag number */ | 453 | xfs_agnumber_t agno; /* current ag number */ |
455 | int flags; /* alloc buffer locking flags */ | 454 | int flags; /* alloc buffer locking flags */ |
@@ -459,6 +458,7 @@ xfs_ialloc_ag_select( | |||
459 | int needspace; /* file mode implies space allocated */ | 458 | int needspace; /* file mode implies space allocated */ |
460 | xfs_perag_t *pag; /* per allocation group data */ | 459 | xfs_perag_t *pag; /* per allocation group data */ |
461 | xfs_agnumber_t pagno; /* parent (starting) ag number */ | 460 | xfs_agnumber_t pagno; /* parent (starting) ag number */ |
461 | int error; | ||
462 | 462 | ||
463 | /* | 463 | /* |
464 | * Files of these types need at least one block if length > 0 | 464 | * Files of these types need at least one block if length > 0 |
@@ -474,7 +474,9 @@ xfs_ialloc_ag_select( | |||
474 | if (pagno >= agcount) | 474 | if (pagno >= agcount) |
475 | pagno = 0; | 475 | pagno = 0; |
476 | } | 476 | } |
477 | |||
477 | ASSERT(pagno < agcount); | 478 | ASSERT(pagno < agcount); |
479 | |||
478 | /* | 480 | /* |
479 | * Loop through allocation groups, looking for one with a little | 481 | * Loop through allocation groups, looking for one with a little |
480 | * free space in it. Note we don't look for free inodes, exactly. | 482 | * free space in it. Note we don't look for free inodes, exactly. |
@@ -486,51 +488,45 @@ xfs_ialloc_ag_select( | |||
486 | flags = XFS_ALLOC_FLAG_TRYLOCK; | 488 | flags = XFS_ALLOC_FLAG_TRYLOCK; |
487 | for (;;) { | 489 | for (;;) { |
488 | pag = xfs_perag_get(mp, agno); | 490 | pag = xfs_perag_get(mp, agno); |
491 | if (!pag->pagi_inodeok) { | ||
492 | xfs_ialloc_next_ag(mp); | ||
493 | goto nextag; | ||
494 | } | ||
495 | |||
489 | if (!pag->pagi_init) { | 496 | if (!pag->pagi_init) { |
490 | if (xfs_ialloc_read_agi(mp, tp, agno, &agbp)) { | 497 | error = xfs_ialloc_pagi_init(mp, tp, agno); |
491 | agbp = NULL; | 498 | if (error) |
492 | goto nextag; | 499 | goto nextag; |
493 | } | 500 | } |
494 | } else | ||
495 | agbp = NULL; | ||
496 | 501 | ||
497 | if (!pag->pagi_inodeok) { | 502 | if (pag->pagi_freecount) { |
498 | xfs_ialloc_next_ag(mp); | 503 | xfs_perag_put(pag); |
499 | goto unlock_nextag; | 504 | return agno; |
500 | } | 505 | } |
501 | 506 | ||
502 | /* | 507 | if (!okalloc) |
503 | * Is there enough free space for the file plus a block | 508 | goto nextag; |
504 | * of inodes (if we need to allocate some)? | 509 | |
505 | */ | 510 | if (!pag->pagf_init) { |
506 | ineed = pag->pagi_freecount ? 0 : XFS_IALLOC_BLOCKS(mp); | 511 | error = xfs_alloc_pagf_init(mp, tp, agno, flags); |
507 | if (ineed && !pag->pagf_init) { | 512 | if (error) |
508 | if (agbp == NULL && | ||
509 | xfs_ialloc_read_agi(mp, tp, agno, &agbp)) { | ||
510 | agbp = NULL; | ||
511 | goto nextag; | 513 | goto nextag; |
512 | } | ||
513 | (void)xfs_alloc_pagf_init(mp, tp, agno, flags); | ||
514 | } | 514 | } |
515 | if (!ineed || pag->pagf_init) { | 515 | |
516 | if (ineed && !(longest = pag->pagf_longest)) | 516 | /* |
517 | longest = pag->pagf_flcount > 0; | 517 | * Is there enough free space for the file plus a block of |
518 | if (!ineed || | 518 | * inodes? (if we need to allocate some)? |
519 | (pag->pagf_freeblks >= needspace + ineed && | 519 | */ |
520 | longest >= ineed && | 520 | ineed = XFS_IALLOC_BLOCKS(mp); |
521 | okalloc)) { | 521 | longest = pag->pagf_longest; |
522 | if (agbp == NULL && | 522 | if (!longest) |
523 | xfs_ialloc_read_agi(mp, tp, agno, &agbp)) { | 523 | longest = pag->pagf_flcount > 0; |
524 | agbp = NULL; | 524 | |
525 | goto nextag; | 525 | if (pag->pagf_freeblks >= needspace + ineed && |
526 | } | 526 | longest >= ineed) { |
527 | xfs_perag_put(pag); | 527 | xfs_perag_put(pag); |
528 | return agbp; | 528 | return agno; |
529 | } | ||
530 | } | 529 | } |
531 | unlock_nextag: | ||
532 | if (agbp) | ||
533 | xfs_trans_brelse(tp, agbp); | ||
534 | nextag: | 530 | nextag: |
535 | xfs_perag_put(pag); | 531 | xfs_perag_put(pag); |
536 | /* | 532 | /* |
@@ -538,13 +534,13 @@ nextag: | |||
538 | * down. | 534 | * down. |
539 | */ | 535 | */ |
540 | if (XFS_FORCED_SHUTDOWN(mp)) | 536 | if (XFS_FORCED_SHUTDOWN(mp)) |
541 | return NULL; | 537 | return NULLAGNUMBER; |
542 | agno++; | 538 | agno++; |
543 | if (agno >= agcount) | 539 | if (agno >= agcount) |
544 | agno = 0; | 540 | agno = 0; |
545 | if (agno == pagno) { | 541 | if (agno == pagno) { |
546 | if (flags == 0) | 542 | if (flags == 0) |
547 | return NULL; | 543 | return NULLAGNUMBER; |
548 | flags = 0; | 544 | flags = 0; |
549 | } | 545 | } |
550 | } | 546 | } |
@@ -607,195 +603,39 @@ xfs_ialloc_get_rec( | |||
607 | } | 603 | } |
608 | 604 | ||
609 | /* | 605 | /* |
610 | * Visible inode allocation functions. | 606 | * Allocate an inode. |
611 | */ | ||
612 | /* | ||
613 | * Find a free (set) bit in the inode bitmask. | ||
614 | */ | ||
615 | static inline int xfs_ialloc_find_free(xfs_inofree_t *fp) | ||
616 | { | ||
617 | return xfs_lowbit64(*fp); | ||
618 | } | ||
619 | |||
620 | /* | ||
621 | * Allocate an inode on disk. | ||
622 | * Mode is used to tell whether the new inode will need space, and whether | ||
623 | * it is a directory. | ||
624 | * | ||
625 | * The arguments IO_agbp and alloc_done are defined to work within | ||
626 | * the constraint of one allocation per transaction. | ||
627 | * xfs_dialloc() is designed to be called twice if it has to do an | ||
628 | * allocation to make more free inodes. On the first call, | ||
629 | * IO_agbp should be set to NULL. If an inode is available, | ||
630 | * i.e., xfs_dialloc() did not need to do an allocation, an inode | ||
631 | * number is returned. In this case, IO_agbp would be set to the | ||
632 | * current ag_buf and alloc_done set to false. | ||
633 | * If an allocation needed to be done, xfs_dialloc would return | ||
634 | * the current ag_buf in IO_agbp and set alloc_done to true. | ||
635 | * The caller should then commit the current transaction, allocate a new | ||
636 | * transaction, and call xfs_dialloc() again, passing in the previous | ||
637 | * value of IO_agbp. IO_agbp should be held across the transactions. | ||
638 | * Since the agbp is locked across the two calls, the second call is | ||
639 | * guaranteed to have a free inode available. | ||
640 | * | 607 | * |
641 | * Once we successfully pick an inode its number is returned and the | 608 | * The caller selected an AG for us, and made sure that free inodes are |
642 | * on-disk data structures are updated. The inode itself is not read | 609 | * available. |
643 | * in, since doing so would break ordering constraints with xfs_reclaim. | ||
644 | */ | 610 | */ |
645 | int | 611 | STATIC int |
646 | xfs_dialloc( | 612 | xfs_dialloc_ag( |
647 | xfs_trans_t *tp, /* transaction pointer */ | 613 | struct xfs_trans *tp, |
648 | xfs_ino_t parent, /* parent inode (directory) */ | 614 | struct xfs_buf *agbp, |
649 | umode_t mode, /* mode bits for new inode */ | 615 | xfs_ino_t parent, |
650 | int okalloc, /* ok to allocate more space */ | 616 | xfs_ino_t *inop) |
651 | xfs_buf_t **IO_agbp, /* in/out ag header's buffer */ | ||
652 | boolean_t *alloc_done, /* true if we needed to replenish | ||
653 | inode freelist */ | ||
654 | xfs_ino_t *inop) /* inode number allocated */ | ||
655 | { | 617 | { |
656 | xfs_agnumber_t agcount; /* number of allocation groups */ | 618 | struct xfs_mount *mp = tp->t_mountp; |
657 | xfs_buf_t *agbp; /* allocation group header's buffer */ | 619 | struct xfs_agi *agi = XFS_BUF_TO_AGI(agbp); |
658 | xfs_agnumber_t agno; /* allocation group number */ | 620 | xfs_agnumber_t agno = be32_to_cpu(agi->agi_seqno); |
659 | xfs_agi_t *agi; /* allocation group header structure */ | 621 | xfs_agnumber_t pagno = XFS_INO_TO_AGNO(mp, parent); |
660 | xfs_btree_cur_t *cur; /* inode allocation btree cursor */ | 622 | xfs_agino_t pagino = XFS_INO_TO_AGINO(mp, parent); |
661 | int error; /* error return value */ | 623 | struct xfs_perag *pag; |
662 | int i; /* result code */ | 624 | struct xfs_btree_cur *cur, *tcur; |
663 | int ialloced; /* inode allocation status */ | 625 | struct xfs_inobt_rec_incore rec, trec; |
664 | int noroom = 0; /* no space for inode blk allocation */ | 626 | xfs_ino_t ino; |
665 | xfs_ino_t ino; /* fs-relative inode to be returned */ | 627 | int error; |
666 | /* REFERENCED */ | 628 | int offset; |
667 | int j; /* result code */ | 629 | int i, j; |
668 | xfs_mount_t *mp; /* file system mount structure */ | ||
669 | int offset; /* index of inode in chunk */ | ||
670 | xfs_agino_t pagino; /* parent's AG relative inode # */ | ||
671 | xfs_agnumber_t pagno; /* parent's AG number */ | ||
672 | xfs_inobt_rec_incore_t rec; /* inode allocation record */ | ||
673 | xfs_agnumber_t tagno; /* testing allocation group number */ | ||
674 | xfs_btree_cur_t *tcur; /* temp cursor */ | ||
675 | xfs_inobt_rec_incore_t trec; /* temp inode allocation record */ | ||
676 | struct xfs_perag *pag; | ||
677 | |||
678 | |||
679 | if (*IO_agbp == NULL) { | ||
680 | /* | ||
681 | * We do not have an agbp, so select an initial allocation | ||
682 | * group for inode allocation. | ||
683 | */ | ||
684 | agbp = xfs_ialloc_ag_select(tp, parent, mode, okalloc); | ||
685 | /* | ||
686 | * Couldn't find an allocation group satisfying the | ||
687 | * criteria, give up. | ||
688 | */ | ||
689 | if (!agbp) { | ||
690 | *inop = NULLFSINO; | ||
691 | return 0; | ||
692 | } | ||
693 | agi = XFS_BUF_TO_AGI(agbp); | ||
694 | ASSERT(agi->agi_magicnum == cpu_to_be32(XFS_AGI_MAGIC)); | ||
695 | } else { | ||
696 | /* | ||
697 | * Continue where we left off before. In this case, we | ||
698 | * know that the allocation group has free inodes. | ||
699 | */ | ||
700 | agbp = *IO_agbp; | ||
701 | agi = XFS_BUF_TO_AGI(agbp); | ||
702 | ASSERT(agi->agi_magicnum == cpu_to_be32(XFS_AGI_MAGIC)); | ||
703 | ASSERT(be32_to_cpu(agi->agi_freecount) > 0); | ||
704 | } | ||
705 | mp = tp->t_mountp; | ||
706 | agcount = mp->m_sb.sb_agcount; | ||
707 | agno = be32_to_cpu(agi->agi_seqno); | ||
708 | tagno = agno; | ||
709 | pagno = XFS_INO_TO_AGNO(mp, parent); | ||
710 | pagino = XFS_INO_TO_AGINO(mp, parent); | ||
711 | |||
712 | /* | ||
713 | * If we have already hit the ceiling of inode blocks then clear | ||
714 | * okalloc so we scan all available agi structures for a free | ||
715 | * inode. | ||
716 | */ | ||
717 | |||
718 | if (mp->m_maxicount && | ||
719 | mp->m_sb.sb_icount + XFS_IALLOC_INODES(mp) > mp->m_maxicount) { | ||
720 | noroom = 1; | ||
721 | okalloc = 0; | ||
722 | } | ||
723 | 630 | ||
724 | /* | ||
725 | * Loop until we find an allocation group that either has free inodes | ||
726 | * or in which we can allocate some inodes. Iterate through the | ||
727 | * allocation groups upward, wrapping at the end. | ||
728 | */ | ||
729 | *alloc_done = B_FALSE; | ||
730 | while (!agi->agi_freecount) { | ||
731 | /* | ||
732 | * Don't do anything if we're not supposed to allocate | ||
733 | * any blocks, just go on to the next ag. | ||
734 | */ | ||
735 | if (okalloc) { | ||
736 | /* | ||
737 | * Try to allocate some new inodes in the allocation | ||
738 | * group. | ||
739 | */ | ||
740 | if ((error = xfs_ialloc_ag_alloc(tp, agbp, &ialloced))) { | ||
741 | xfs_trans_brelse(tp, agbp); | ||
742 | if (error == ENOSPC) { | ||
743 | *inop = NULLFSINO; | ||
744 | return 0; | ||
745 | } else | ||
746 | return error; | ||
747 | } | ||
748 | if (ialloced) { | ||
749 | /* | ||
750 | * We successfully allocated some inodes, return | ||
751 | * the current context to the caller so that it | ||
752 | * can commit the current transaction and call | ||
753 | * us again where we left off. | ||
754 | */ | ||
755 | ASSERT(be32_to_cpu(agi->agi_freecount) > 0); | ||
756 | *alloc_done = B_TRUE; | ||
757 | *IO_agbp = agbp; | ||
758 | *inop = NULLFSINO; | ||
759 | return 0; | ||
760 | } | ||
761 | } | ||
762 | /* | ||
763 | * If it failed, give up on this ag. | ||
764 | */ | ||
765 | xfs_trans_brelse(tp, agbp); | ||
766 | /* | ||
767 | * Go on to the next ag: get its ag header. | ||
768 | */ | ||
769 | nextag: | ||
770 | if (++tagno == agcount) | ||
771 | tagno = 0; | ||
772 | if (tagno == agno) { | ||
773 | *inop = NULLFSINO; | ||
774 | return noroom ? ENOSPC : 0; | ||
775 | } | ||
776 | pag = xfs_perag_get(mp, tagno); | ||
777 | if (pag->pagi_inodeok == 0) { | ||
778 | xfs_perag_put(pag); | ||
779 | goto nextag; | ||
780 | } | ||
781 | error = xfs_ialloc_read_agi(mp, tp, tagno, &agbp); | ||
782 | xfs_perag_put(pag); | ||
783 | if (error) | ||
784 | goto nextag; | ||
785 | agi = XFS_BUF_TO_AGI(agbp); | ||
786 | ASSERT(agi->agi_magicnum == cpu_to_be32(XFS_AGI_MAGIC)); | ||
787 | } | ||
788 | /* | ||
789 | * Here with an allocation group that has a free inode. | ||
790 | * Reset agno since we may have chosen a new ag in the | ||
791 | * loop above. | ||
792 | */ | ||
793 | agno = tagno; | ||
794 | *IO_agbp = NULL; | ||
795 | pag = xfs_perag_get(mp, agno); | 631 | pag = xfs_perag_get(mp, agno); |
796 | 632 | ||
633 | ASSERT(pag->pagi_init); | ||
634 | ASSERT(pag->pagi_inodeok); | ||
635 | ASSERT(pag->pagi_freecount > 0); | ||
636 | |||
797 | restart_pagno: | 637 | restart_pagno: |
798 | cur = xfs_inobt_init_cursor(mp, tp, agbp, be32_to_cpu(agi->agi_seqno)); | 638 | cur = xfs_inobt_init_cursor(mp, tp, agbp, agno); |
799 | /* | 639 | /* |
800 | * If pagino is 0 (this is the root inode allocation) use newino. | 640 | * If pagino is 0 (this is the root inode allocation) use newino. |
801 | * This must work because we've just allocated some. | 641 | * This must work because we've just allocated some. |
@@ -995,7 +835,7 @@ newino: | |||
995 | } | 835 | } |
996 | 836 | ||
997 | alloc_inode: | 837 | alloc_inode: |
998 | offset = xfs_ialloc_find_free(&rec.ir_free); | 838 | offset = xfs_lowbit64(rec.ir_free); |
999 | ASSERT(offset >= 0); | 839 | ASSERT(offset >= 0); |
1000 | ASSERT(offset < XFS_INODES_PER_CHUNK); | 840 | ASSERT(offset < XFS_INODES_PER_CHUNK); |
1001 | ASSERT((XFS_AGINO_TO_OFFSET(mp, rec.ir_startino) % | 841 | ASSERT((XFS_AGINO_TO_OFFSET(mp, rec.ir_startino) % |
@@ -1028,6 +868,164 @@ error0: | |||
1028 | } | 868 | } |
1029 | 869 | ||
1030 | /* | 870 | /* |
871 | * Allocate an inode on disk. | ||
872 | * | ||
873 | * Mode is used to tell whether the new inode will need space, and whether it | ||
874 | * is a directory. | ||
875 | * | ||
876 | * This function is designed to be called twice if it has to do an allocation | ||
877 | * to make more free inodes. On the first call, *IO_agbp should be set to NULL. | ||
878 | * If an inode is available without having to performn an allocation, an inode | ||
879 | * number is returned. In this case, *IO_agbp would be NULL. If an allocation | ||
880 | * needes to be done, xfs_dialloc would return the current AGI buffer in | ||
881 | * *IO_agbp. The caller should then commit the current transaction, allocate a | ||
882 | * new transaction, and call xfs_dialloc() again, passing in the previous value | ||
883 | * of *IO_agbp. IO_agbp should be held across the transactions. Since the AGI | ||
884 | * buffer is locked across the two calls, the second call is guaranteed to have | ||
885 | * a free inode available. | ||
886 | * | ||
887 | * Once we successfully pick an inode its number is returned and the on-disk | ||
888 | * data structures are updated. The inode itself is not read in, since doing so | ||
889 | * would break ordering constraints with xfs_reclaim. | ||
890 | */ | ||
891 | int | ||
892 | xfs_dialloc( | ||
893 | struct xfs_trans *tp, | ||
894 | xfs_ino_t parent, | ||
895 | umode_t mode, | ||
896 | int okalloc, | ||
897 | struct xfs_buf **IO_agbp, | ||
898 | xfs_ino_t *inop) | ||
899 | { | ||
900 | struct xfs_mount *mp = tp->t_mountp; | ||
901 | struct xfs_buf *agbp; | ||
902 | xfs_agnumber_t agno; | ||
903 | int error; | ||
904 | int ialloced; | ||
905 | int noroom = 0; | ||
906 | xfs_agnumber_t start_agno; | ||
907 | struct xfs_perag *pag; | ||
908 | |||
909 | if (*IO_agbp) { | ||
910 | /* | ||
911 | * If the caller passes in a pointer to the AGI buffer, | ||
912 | * continue where we left off before. In this case, we | ||
913 | * know that the allocation group has free inodes. | ||
914 | */ | ||
915 | agbp = *IO_agbp; | ||
916 | goto out_alloc; | ||
917 | } | ||
918 | |||
919 | /* | ||
920 | * We do not have an agbp, so select an initial allocation | ||
921 | * group for inode allocation. | ||
922 | */ | ||
923 | start_agno = xfs_ialloc_ag_select(tp, parent, mode, okalloc); | ||
924 | if (start_agno == NULLAGNUMBER) { | ||
925 | *inop = NULLFSINO; | ||
926 | return 0; | ||
927 | } | ||
928 | |||
929 | /* | ||
930 | * If we have already hit the ceiling of inode blocks then clear | ||
931 | * okalloc so we scan all available agi structures for a free | ||
932 | * inode. | ||
933 | */ | ||
934 | if (mp->m_maxicount && | ||
935 | mp->m_sb.sb_icount + XFS_IALLOC_INODES(mp) > mp->m_maxicount) { | ||
936 | noroom = 1; | ||
937 | okalloc = 0; | ||
938 | } | ||
939 | |||
940 | /* | ||
941 | * Loop until we find an allocation group that either has free inodes | ||
942 | * or in which we can allocate some inodes. Iterate through the | ||
943 | * allocation groups upward, wrapping at the end. | ||
944 | */ | ||
945 | agno = start_agno; | ||
946 | for (;;) { | ||
947 | pag = xfs_perag_get(mp, agno); | ||
948 | if (!pag->pagi_inodeok) { | ||
949 | xfs_ialloc_next_ag(mp); | ||
950 | goto nextag; | ||
951 | } | ||
952 | |||
953 | if (!pag->pagi_init) { | ||
954 | error = xfs_ialloc_pagi_init(mp, tp, agno); | ||
955 | if (error) | ||
956 | goto out_error; | ||
957 | } | ||
958 | |||
959 | /* | ||
960 | * Do a first racy fast path check if this AG is usable. | ||
961 | */ | ||
962 | if (!pag->pagi_freecount && !okalloc) | ||
963 | goto nextag; | ||
964 | |||
965 | error = xfs_ialloc_read_agi(mp, tp, agno, &agbp); | ||
966 | if (error) | ||
967 | goto out_error; | ||
968 | |||
969 | /* | ||
970 | * Once the AGI has been read in we have to recheck | ||
971 | * pagi_freecount with the AGI buffer lock held. | ||
972 | */ | ||
973 | if (pag->pagi_freecount) { | ||
974 | xfs_perag_put(pag); | ||
975 | goto out_alloc; | ||
976 | } | ||
977 | |||
978 | if (!okalloc) { | ||
979 | xfs_trans_brelse(tp, agbp); | ||
980 | goto nextag; | ||
981 | } | ||
982 | |||
983 | error = xfs_ialloc_ag_alloc(tp, agbp, &ialloced); | ||
984 | if (error) { | ||
985 | xfs_trans_brelse(tp, agbp); | ||
986 | |||
987 | if (error != ENOSPC) | ||
988 | goto out_error; | ||
989 | |||
990 | xfs_perag_put(pag); | ||
991 | *inop = NULLFSINO; | ||
992 | return 0; | ||
993 | } | ||
994 | |||
995 | if (ialloced) { | ||
996 | /* | ||
997 | * We successfully allocated some inodes, return | ||
998 | * the current context to the caller so that it | ||
999 | * can commit the current transaction and call | ||
1000 | * us again where we left off. | ||
1001 | */ | ||
1002 | ASSERT(pag->pagi_freecount > 0); | ||
1003 | xfs_perag_put(pag); | ||
1004 | |||
1005 | *IO_agbp = agbp; | ||
1006 | *inop = NULLFSINO; | ||
1007 | return 0; | ||
1008 | } | ||
1009 | |||
1010 | nextag: | ||
1011 | xfs_perag_put(pag); | ||
1012 | if (++agno == mp->m_sb.sb_agcount) | ||
1013 | agno = 0; | ||
1014 | if (agno == start_agno) { | ||
1015 | *inop = NULLFSINO; | ||
1016 | return noroom ? ENOSPC : 0; | ||
1017 | } | ||
1018 | } | ||
1019 | |||
1020 | out_alloc: | ||
1021 | *IO_agbp = NULL; | ||
1022 | return xfs_dialloc_ag(tp, agbp, parent, inop); | ||
1023 | out_error: | ||
1024 | xfs_perag_put(pag); | ||
1025 | return XFS_ERROR(error); | ||
1026 | } | ||
1027 | |||
1028 | /* | ||
1031 | * Free disk inode. Carefully avoids touching the incore inode, all | 1029 | * Free disk inode. Carefully avoids touching the incore inode, all |
1032 | * manipulations incore are the caller's responsibility. | 1030 | * manipulations incore are the caller's responsibility. |
1033 | * The on-disk inode is not changed by this operation, only the | 1031 | * The on-disk inode is not changed by this operation, only the |