aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2014-04-23 10:00:51 -0400
committerJan Kara <jack@suse.cz>2014-05-07 12:50:41 -0400
commit65ab18cb735e828199ce331c6eda7fb0904048e1 (patch)
treeed2605f3c6795f9bdc3e972e065482f566cc5b52
parent3f0eb27655bba38e3dfb14db93b2720c4eccf4a8 (diff)
reiserfs: balance_leaf refactor, pull out balance_leaf_new_nodes_insert
This patch factors out a new balance_leaf_new_nodes_insert from the code in balance_leaf responsible for inserting new items into new nodes in the tree. It has not been reformatted yet. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r--fs/reiserfs/do_balan.c133
1 files changed, 73 insertions, 60 deletions
diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
index 4dbe0a34739f..c2c5ba77cfe0 100644
--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -733,6 +733,77 @@ static void balance_leaf_paste_right(struct tree_balance *tb,
733 733
734} 734}
735 735
736static void balance_leaf_new_nodes_insert(struct tree_balance *tb,
737 struct item_head *ih,
738 const char *body,
739 struct item_head *insert_key,
740 struct buffer_head **insert_ptr,
741 int i)
742{
743 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
744 int n = B_NR_ITEMS(tbS0);
745 struct buffer_info bi;
746 if (n - tb->snum[i] < tb->item_pos) { /* new item or it's part falls to first new node S_new[i] */
747 if (tb->item_pos == n - tb->snum[i] + 1 && tb->sbytes[i] != -1) { /* part of new item falls into S_new[i] */
748 int old_key_comp, old_len, r_zeroes_number;
749 const char *r_body;
750 int version;
751
752 /* Move snum[i]-1 items from S[0] to S_new[i] */
753 leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
754 tb->snum[i] - 1, -1,
755 tb->S_new[i]);
756 /* Remember key component and item length */
757 version = ih_version(ih);
758 old_key_comp = le_ih_k_offset(ih);
759 old_len = ih_item_len(ih);
760
761 /* Calculate key component and item length to insert into S_new[i] */
762 set_le_ih_k_offset(ih, le_ih_k_offset(ih) +
763 ((old_len - tb->sbytes[i]) << (is_indirect_le_ih(ih) ? tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT : 0)));
764
765 put_ih_item_len(ih, tb->sbytes[i]);
766
767 /* Insert part of the item into S_new[i] before 0-th item */
768 buffer_info_init_bh(tb, &bi, tb->S_new[i]);
769
770 if ((old_len - tb->sbytes[i]) > tb->zeroes_num) {
771 r_zeroes_number = 0;
772 r_body = body + (old_len - tb->sbytes[i]) - tb->zeroes_num;
773 } else {
774 r_body = body;
775 r_zeroes_number = tb->zeroes_num - (old_len - tb->sbytes[i]);
776 tb->zeroes_num -= r_zeroes_number;
777 }
778
779 leaf_insert_into_buf(&bi, 0, ih, r_body, r_zeroes_number);
780
781 /* Calculate key component and item length to insert into S[i] */
782 set_le_ih_k_offset(ih, old_key_comp);
783 put_ih_item_len(ih, old_len - tb->sbytes[i]);
784 tb->insert_size[0] -= tb->sbytes[i];
785 } else { /* whole new item falls into S_new[i] */
786
787 /* Shift snum[0] - 1 items to S_new[i] (sbytes[i] of split item) */
788 leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
789 tb->snum[i] - 1, tb->sbytes[i], tb->S_new[i]);
790
791 /* Insert new item into S_new[i] */
792 buffer_info_init_bh(tb, &bi, tb->S_new[i]);
793 leaf_insert_into_buf(&bi, tb->item_pos - n + tb->snum[i] - 1,
794 ih, body, tb->zeroes_num);
795
796 tb->zeroes_num = tb->insert_size[0] = 0;
797 }
798 }
799
800 else { /* new item or it part don't falls into S_new[i] */
801
802 leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
803 tb->snum[i], tb->sbytes[i], tb->S_new[i]);
804 }
805}
806
736/** 807/**
737 * balance_leaf - reiserfs tree balancing algorithm 808 * balance_leaf - reiserfs tree balancing algorithm
738 * @tb: tree balance state 809 * @tb: tree balance state
@@ -877,66 +948,8 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih,
877 948
878 switch (flag) { 949 switch (flag) {
879 case M_INSERT: /* insert item */ 950 case M_INSERT: /* insert item */
880 951 balance_leaf_new_nodes_insert(tb, ih, body, insert_key,
881 if (n - tb->snum[i] < tb->item_pos) { /* new item or it's part falls to first new node S_new[i] */ 952 insert_ptr, i);
882 if (tb->item_pos == n - tb->snum[i] + 1 && tb->sbytes[i] != -1) { /* part of new item falls into S_new[i] */
883 int old_key_comp, old_len, r_zeroes_number;
884 const char *r_body;
885 int version;
886
887 /* Move snum[i]-1 items from S[0] to S_new[i] */
888 leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
889 tb->snum[i] - 1, -1,
890 tb->S_new[i]);
891 /* Remember key component and item length */
892 version = ih_version(ih);
893 old_key_comp = le_ih_k_offset(ih);
894 old_len = ih_item_len(ih);
895
896 /* Calculate key component and item length to insert into S_new[i] */
897 set_le_ih_k_offset(ih, le_ih_k_offset(ih) +
898 ((old_len - tb->sbytes[i]) << (is_indirect_le_ih(ih) ? tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT : 0)));
899
900 put_ih_item_len(ih, tb->sbytes[i]);
901
902 /* Insert part of the item into S_new[i] before 0-th item */
903 buffer_info_init_bh(tb, &bi, tb->S_new[i]);
904
905 if ((old_len - tb->sbytes[i]) > tb->zeroes_num) {
906 r_zeroes_number = 0;
907 r_body = body + (old_len - tb->sbytes[i]) - tb->zeroes_num;
908 } else {
909 r_body = body;
910 r_zeroes_number = tb->zeroes_num - (old_len - tb->sbytes[i]);
911 tb->zeroes_num -= r_zeroes_number;
912 }
913
914 leaf_insert_into_buf(&bi, 0, ih, r_body, r_zeroes_number);
915
916 /* Calculate key component and item length to insert into S[i] */
917 set_le_ih_k_offset(ih, old_key_comp);
918 put_ih_item_len(ih, old_len - tb->sbytes[i]);
919 tb->insert_size[0] -= tb->sbytes[i];
920 } else { /* whole new item falls into S_new[i] */
921
922 /* Shift snum[0] - 1 items to S_new[i] (sbytes[i] of split item) */
923 leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
924 tb->snum[i] - 1, tb->sbytes[i], tb->S_new[i]);
925
926 /* Insert new item into S_new[i] */
927 buffer_info_init_bh(tb, &bi, tb->S_new[i]);
928 leaf_insert_into_buf(&bi, tb->item_pos - n + tb->snum[i] - 1,
929 ih, body, tb->zeroes_num);
930
931 tb->zeroes_num = tb->insert_size[0] = 0;
932 }
933 }
934
935 else { /* new item or it part don't falls into S_new[i] */
936
937 leaf_move_items(LEAF_FROM_S_TO_SNEW, tb,
938 tb->snum[i], tb->sbytes[i], tb->S_new[i]);
939 }
940 break; 953 break;
941 954
942 case M_PASTE: /* append item */ 955 case M_PASTE: /* append item */