diff options
Diffstat (limited to 'fs/ocfs2/suballoc.c')
-rw-r--r-- | fs/ocfs2/suballoc.c | 171 |
1 files changed, 131 insertions, 40 deletions
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c index c30b644d9572..c3c60bc3e072 100644 --- a/fs/ocfs2/suballoc.c +++ b/fs/ocfs2/suballoc.c | |||
@@ -51,7 +51,7 @@ | |||
51 | #define ALLOC_NEW_GROUP 0x1 | 51 | #define ALLOC_NEW_GROUP 0x1 |
52 | #define ALLOC_GROUPS_FROM_GLOBAL 0x2 | 52 | #define ALLOC_GROUPS_FROM_GLOBAL 0x2 |
53 | 53 | ||
54 | #define OCFS2_MAX_INODES_TO_STEAL 1024 | 54 | #define OCFS2_MAX_TO_STEAL 1024 |
55 | 55 | ||
56 | static inline void ocfs2_debug_bg(struct ocfs2_group_desc *bg); | 56 | static inline void ocfs2_debug_bg(struct ocfs2_group_desc *bg); |
57 | static inline void ocfs2_debug_suballoc_inode(struct ocfs2_dinode *fe); | 57 | static inline void ocfs2_debug_suballoc_inode(struct ocfs2_dinode *fe); |
@@ -637,12 +637,113 @@ bail: | |||
637 | return status; | 637 | return status; |
638 | } | 638 | } |
639 | 639 | ||
640 | static void ocfs2_init_inode_steal_slot(struct ocfs2_super *osb) | ||
641 | { | ||
642 | spin_lock(&osb->osb_lock); | ||
643 | osb->s_inode_steal_slot = OCFS2_INVALID_SLOT; | ||
644 | spin_unlock(&osb->osb_lock); | ||
645 | atomic_set(&osb->s_num_inodes_stolen, 0); | ||
646 | } | ||
647 | |||
648 | static void ocfs2_init_meta_steal_slot(struct ocfs2_super *osb) | ||
649 | { | ||
650 | spin_lock(&osb->osb_lock); | ||
651 | osb->s_meta_steal_slot = OCFS2_INVALID_SLOT; | ||
652 | spin_unlock(&osb->osb_lock); | ||
653 | atomic_set(&osb->s_num_meta_stolen, 0); | ||
654 | } | ||
655 | |||
656 | void ocfs2_init_steal_slots(struct ocfs2_super *osb) | ||
657 | { | ||
658 | ocfs2_init_inode_steal_slot(osb); | ||
659 | ocfs2_init_meta_steal_slot(osb); | ||
660 | } | ||
661 | |||
662 | static void __ocfs2_set_steal_slot(struct ocfs2_super *osb, int slot, int type) | ||
663 | { | ||
664 | spin_lock(&osb->osb_lock); | ||
665 | if (type == INODE_ALLOC_SYSTEM_INODE) | ||
666 | osb->s_inode_steal_slot = slot; | ||
667 | else if (type == EXTENT_ALLOC_SYSTEM_INODE) | ||
668 | osb->s_meta_steal_slot = slot; | ||
669 | spin_unlock(&osb->osb_lock); | ||
670 | } | ||
671 | |||
672 | static int __ocfs2_get_steal_slot(struct ocfs2_super *osb, int type) | ||
673 | { | ||
674 | int slot = OCFS2_INVALID_SLOT; | ||
675 | |||
676 | spin_lock(&osb->osb_lock); | ||
677 | if (type == INODE_ALLOC_SYSTEM_INODE) | ||
678 | slot = osb->s_inode_steal_slot; | ||
679 | else if (type == EXTENT_ALLOC_SYSTEM_INODE) | ||
680 | slot = osb->s_meta_steal_slot; | ||
681 | spin_unlock(&osb->osb_lock); | ||
682 | |||
683 | return slot; | ||
684 | } | ||
685 | |||
686 | static int ocfs2_get_inode_steal_slot(struct ocfs2_super *osb) | ||
687 | { | ||
688 | return __ocfs2_get_steal_slot(osb, INODE_ALLOC_SYSTEM_INODE); | ||
689 | } | ||
690 | |||
691 | static int ocfs2_get_meta_steal_slot(struct ocfs2_super *osb) | ||
692 | { | ||
693 | return __ocfs2_get_steal_slot(osb, EXTENT_ALLOC_SYSTEM_INODE); | ||
694 | } | ||
695 | |||
696 | static int ocfs2_steal_resource(struct ocfs2_super *osb, | ||
697 | struct ocfs2_alloc_context *ac, | ||
698 | int type) | ||
699 | { | ||
700 | int i, status = -ENOSPC; | ||
701 | int slot = __ocfs2_get_steal_slot(osb, type); | ||
702 | |||
703 | /* Start to steal resource from the first slot after ours. */ | ||
704 | if (slot == OCFS2_INVALID_SLOT) | ||
705 | slot = osb->slot_num + 1; | ||
706 | |||
707 | for (i = 0; i < osb->max_slots; i++, slot++) { | ||
708 | if (slot == osb->max_slots) | ||
709 | slot = 0; | ||
710 | |||
711 | if (slot == osb->slot_num) | ||
712 | continue; | ||
713 | |||
714 | status = ocfs2_reserve_suballoc_bits(osb, ac, | ||
715 | type, | ||
716 | (u32)slot, NULL, | ||
717 | NOT_ALLOC_NEW_GROUP); | ||
718 | if (status >= 0) { | ||
719 | __ocfs2_set_steal_slot(osb, slot, type); | ||
720 | break; | ||
721 | } | ||
722 | |||
723 | ocfs2_free_ac_resource(ac); | ||
724 | } | ||
725 | |||
726 | return status; | ||
727 | } | ||
728 | |||
729 | static int ocfs2_steal_inode(struct ocfs2_super *osb, | ||
730 | struct ocfs2_alloc_context *ac) | ||
731 | { | ||
732 | return ocfs2_steal_resource(osb, ac, INODE_ALLOC_SYSTEM_INODE); | ||
733 | } | ||
734 | |||
735 | static int ocfs2_steal_meta(struct ocfs2_super *osb, | ||
736 | struct ocfs2_alloc_context *ac) | ||
737 | { | ||
738 | return ocfs2_steal_resource(osb, ac, EXTENT_ALLOC_SYSTEM_INODE); | ||
739 | } | ||
740 | |||
640 | int ocfs2_reserve_new_metadata_blocks(struct ocfs2_super *osb, | 741 | int ocfs2_reserve_new_metadata_blocks(struct ocfs2_super *osb, |
641 | int blocks, | 742 | int blocks, |
642 | struct ocfs2_alloc_context **ac) | 743 | struct ocfs2_alloc_context **ac) |
643 | { | 744 | { |
644 | int status; | 745 | int status; |
645 | u32 slot; | 746 | int slot = ocfs2_get_meta_steal_slot(osb); |
646 | 747 | ||
647 | *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL); | 748 | *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL); |
648 | if (!(*ac)) { | 749 | if (!(*ac)) { |
@@ -653,12 +754,34 @@ int ocfs2_reserve_new_metadata_blocks(struct ocfs2_super *osb, | |||
653 | 754 | ||
654 | (*ac)->ac_bits_wanted = blocks; | 755 | (*ac)->ac_bits_wanted = blocks; |
655 | (*ac)->ac_which = OCFS2_AC_USE_META; | 756 | (*ac)->ac_which = OCFS2_AC_USE_META; |
656 | slot = osb->slot_num; | ||
657 | (*ac)->ac_group_search = ocfs2_block_group_search; | 757 | (*ac)->ac_group_search = ocfs2_block_group_search; |
658 | 758 | ||
759 | if (slot != OCFS2_INVALID_SLOT && | ||
760 | atomic_read(&osb->s_num_meta_stolen) < OCFS2_MAX_TO_STEAL) | ||
761 | goto extent_steal; | ||
762 | |||
763 | atomic_set(&osb->s_num_meta_stolen, 0); | ||
659 | status = ocfs2_reserve_suballoc_bits(osb, (*ac), | 764 | status = ocfs2_reserve_suballoc_bits(osb, (*ac), |
660 | EXTENT_ALLOC_SYSTEM_INODE, | 765 | EXTENT_ALLOC_SYSTEM_INODE, |
661 | slot, NULL, ALLOC_NEW_GROUP); | 766 | (u32)osb->slot_num, NULL, |
767 | ALLOC_NEW_GROUP); | ||
768 | |||
769 | |||
770 | if (status >= 0) { | ||
771 | status = 0; | ||
772 | if (slot != OCFS2_INVALID_SLOT) | ||
773 | ocfs2_init_meta_steal_slot(osb); | ||
774 | goto bail; | ||
775 | } else if (status < 0 && status != -ENOSPC) { | ||
776 | mlog_errno(status); | ||
777 | goto bail; | ||
778 | } | ||
779 | |||
780 | ocfs2_free_ac_resource(*ac); | ||
781 | |||
782 | extent_steal: | ||
783 | status = ocfs2_steal_meta(osb, *ac); | ||
784 | atomic_inc(&osb->s_num_meta_stolen); | ||
662 | if (status < 0) { | 785 | if (status < 0) { |
663 | if (status != -ENOSPC) | 786 | if (status != -ENOSPC) |
664 | mlog_errno(status); | 787 | mlog_errno(status); |
@@ -685,43 +808,11 @@ int ocfs2_reserve_new_metadata(struct ocfs2_super *osb, | |||
685 | ac); | 808 | ac); |
686 | } | 809 | } |
687 | 810 | ||
688 | static int ocfs2_steal_inode_from_other_nodes(struct ocfs2_super *osb, | ||
689 | struct ocfs2_alloc_context *ac) | ||
690 | { | ||
691 | int i, status = -ENOSPC; | ||
692 | s16 slot = ocfs2_get_inode_steal_slot(osb); | ||
693 | |||
694 | /* Start to steal inodes from the first slot after ours. */ | ||
695 | if (slot == OCFS2_INVALID_SLOT) | ||
696 | slot = osb->slot_num + 1; | ||
697 | |||
698 | for (i = 0; i < osb->max_slots; i++, slot++) { | ||
699 | if (slot == osb->max_slots) | ||
700 | slot = 0; | ||
701 | |||
702 | if (slot == osb->slot_num) | ||
703 | continue; | ||
704 | |||
705 | status = ocfs2_reserve_suballoc_bits(osb, ac, | ||
706 | INODE_ALLOC_SYSTEM_INODE, | ||
707 | slot, NULL, | ||
708 | NOT_ALLOC_NEW_GROUP); | ||
709 | if (status >= 0) { | ||
710 | ocfs2_set_inode_steal_slot(osb, slot); | ||
711 | break; | ||
712 | } | ||
713 | |||
714 | ocfs2_free_ac_resource(ac); | ||
715 | } | ||
716 | |||
717 | return status; | ||
718 | } | ||
719 | |||
720 | int ocfs2_reserve_new_inode(struct ocfs2_super *osb, | 811 | int ocfs2_reserve_new_inode(struct ocfs2_super *osb, |
721 | struct ocfs2_alloc_context **ac) | 812 | struct ocfs2_alloc_context **ac) |
722 | { | 813 | { |
723 | int status; | 814 | int status; |
724 | s16 slot = ocfs2_get_inode_steal_slot(osb); | 815 | int slot = ocfs2_get_inode_steal_slot(osb); |
725 | u64 alloc_group; | 816 | u64 alloc_group; |
726 | 817 | ||
727 | *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL); | 818 | *ac = kzalloc(sizeof(struct ocfs2_alloc_context), GFP_KERNEL); |
@@ -754,14 +845,14 @@ int ocfs2_reserve_new_inode(struct ocfs2_super *osb, | |||
754 | * need to check our slots to see whether there is some space for us. | 845 | * need to check our slots to see whether there is some space for us. |
755 | */ | 846 | */ |
756 | if (slot != OCFS2_INVALID_SLOT && | 847 | if (slot != OCFS2_INVALID_SLOT && |
757 | atomic_read(&osb->s_num_inodes_stolen) < OCFS2_MAX_INODES_TO_STEAL) | 848 | atomic_read(&osb->s_num_inodes_stolen) < OCFS2_MAX_TO_STEAL) |
758 | goto inode_steal; | 849 | goto inode_steal; |
759 | 850 | ||
760 | atomic_set(&osb->s_num_inodes_stolen, 0); | 851 | atomic_set(&osb->s_num_inodes_stolen, 0); |
761 | alloc_group = osb->osb_inode_alloc_group; | 852 | alloc_group = osb->osb_inode_alloc_group; |
762 | status = ocfs2_reserve_suballoc_bits(osb, *ac, | 853 | status = ocfs2_reserve_suballoc_bits(osb, *ac, |
763 | INODE_ALLOC_SYSTEM_INODE, | 854 | INODE_ALLOC_SYSTEM_INODE, |
764 | osb->slot_num, | 855 | (u32)osb->slot_num, |
765 | &alloc_group, | 856 | &alloc_group, |
766 | ALLOC_NEW_GROUP | | 857 | ALLOC_NEW_GROUP | |
767 | ALLOC_GROUPS_FROM_GLOBAL); | 858 | ALLOC_GROUPS_FROM_GLOBAL); |
@@ -789,7 +880,7 @@ int ocfs2_reserve_new_inode(struct ocfs2_super *osb, | |||
789 | ocfs2_free_ac_resource(*ac); | 880 | ocfs2_free_ac_resource(*ac); |
790 | 881 | ||
791 | inode_steal: | 882 | inode_steal: |
792 | status = ocfs2_steal_inode_from_other_nodes(osb, *ac); | 883 | status = ocfs2_steal_inode(osb, *ac); |
793 | atomic_inc(&osb->s_num_inodes_stolen); | 884 | atomic_inc(&osb->s_num_inodes_stolen); |
794 | if (status < 0) { | 885 | if (status < 0) { |
795 | if (status != -ENOSPC) | 886 | if (status != -ENOSPC) |