diff options
Diffstat (limited to 'fs/reiserfs/fix_node.c')
-rw-r--r-- | fs/reiserfs/fix_node.c | 1021 |
1 files changed, 510 insertions, 511 deletions
diff --git a/fs/reiserfs/fix_node.c b/fs/reiserfs/fix_node.c index 07d05e0842b7..5e5a4e6fbaf8 100644 --- a/fs/reiserfs/fix_node.c +++ b/fs/reiserfs/fix_node.c | |||
@@ -30,8 +30,8 @@ | |||
30 | ** get_direct_parent | 30 | ** get_direct_parent |
31 | ** get_neighbors | 31 | ** get_neighbors |
32 | ** fix_nodes | 32 | ** fix_nodes |
33 | ** | 33 | ** |
34 | ** | 34 | ** |
35 | **/ | 35 | **/ |
36 | 36 | ||
37 | #include <linux/time.h> | 37 | #include <linux/time.h> |
@@ -135,8 +135,7 @@ static void create_virtual_node(struct tree_balance *tb, int h) | |||
135 | vn->vn_free_ptr += | 135 | vn->vn_free_ptr += |
136 | op_create_vi(vn, vi, is_affected, tb->insert_size[0]); | 136 | op_create_vi(vn, vi, is_affected, tb->insert_size[0]); |
137 | if (tb->vn_buf + tb->vn_buf_size < vn->vn_free_ptr) | 137 | if (tb->vn_buf + tb->vn_buf_size < vn->vn_free_ptr) |
138 | reiserfs_panic(tb->tb_sb, | 138 | reiserfs_panic(tb->tb_sb, "vs-8030", |
139 | "vs-8030: create_virtual_node: " | ||
140 | "virtual node space consumed"); | 139 | "virtual node space consumed"); |
141 | 140 | ||
142 | if (!is_affected) | 141 | if (!is_affected) |
@@ -186,8 +185,9 @@ static void create_virtual_node(struct tree_balance *tb, int h) | |||
186 | && I_ENTRY_COUNT(B_N_PITEM_HEAD(Sh, 0)) == 1)) { | 185 | && I_ENTRY_COUNT(B_N_PITEM_HEAD(Sh, 0)) == 1)) { |
187 | /* node contains more than 1 item, or item is not directory item, or this item contains more than 1 entry */ | 186 | /* node contains more than 1 item, or item is not directory item, or this item contains more than 1 entry */ |
188 | print_block(Sh, 0, -1, -1); | 187 | print_block(Sh, 0, -1, -1); |
189 | reiserfs_panic(tb->tb_sb, | 188 | reiserfs_panic(tb->tb_sb, "vs-8045", |
190 | "vs-8045: create_virtual_node: rdkey %k, affected item==%d (mode==%c) Must be %c", | 189 | "rdkey %k, affected item==%d " |
190 | "(mode==%c) Must be %c", | ||
191 | key, vn->vn_affected_item_num, | 191 | key, vn->vn_affected_item_num, |
192 | vn->vn_mode, M_DELETE); | 192 | vn->vn_mode, M_DELETE); |
193 | } | 193 | } |
@@ -377,9 +377,9 @@ static int get_num_ver(int mode, struct tree_balance *tb, int h, | |||
377 | int needed_nodes; | 377 | int needed_nodes; |
378 | int start_item, /* position of item we start filling node from */ | 378 | int start_item, /* position of item we start filling node from */ |
379 | end_item, /* position of item we finish filling node by */ | 379 | end_item, /* position of item we finish filling node by */ |
380 | start_bytes, /* number of first bytes (entries for directory) of start_item-th item | 380 | start_bytes, /* number of first bytes (entries for directory) of start_item-th item |
381 | we do not include into node that is being filled */ | 381 | we do not include into node that is being filled */ |
382 | end_bytes; /* number of last bytes (entries for directory) of end_item-th item | 382 | end_bytes; /* number of last bytes (entries for directory) of end_item-th item |
383 | we do node include into node that is being filled */ | 383 | we do node include into node that is being filled */ |
384 | int split_item_positions[2]; /* these are positions in virtual item of | 384 | int split_item_positions[2]; /* these are positions in virtual item of |
385 | items, that are split between S[0] and | 385 | items, that are split between S[0] and |
@@ -496,8 +496,8 @@ static int get_num_ver(int mode, struct tree_balance *tb, int h, | |||
496 | snum012[needed_nodes - 1 + 3] = units; | 496 | snum012[needed_nodes - 1 + 3] = units; |
497 | 497 | ||
498 | if (needed_nodes > 2) | 498 | if (needed_nodes > 2) |
499 | reiserfs_warning(tb->tb_sb, "vs-8111: get_num_ver: " | 499 | reiserfs_warning(tb->tb_sb, "vs-8111", |
500 | "split_item_position is out of boundary"); | 500 | "split_item_position is out of range"); |
501 | snum012[needed_nodes - 1]++; | 501 | snum012[needed_nodes - 1]++; |
502 | split_item_positions[needed_nodes - 1] = i; | 502 | split_item_positions[needed_nodes - 1] = i; |
503 | needed_nodes++; | 503 | needed_nodes++; |
@@ -533,8 +533,8 @@ static int get_num_ver(int mode, struct tree_balance *tb, int h, | |||
533 | 533 | ||
534 | if (vn->vn_vi[split_item_num].vi_index != TYPE_DIRENTRY && | 534 | if (vn->vn_vi[split_item_num].vi_index != TYPE_DIRENTRY && |
535 | vn->vn_vi[split_item_num].vi_index != TYPE_INDIRECT) | 535 | vn->vn_vi[split_item_num].vi_index != TYPE_INDIRECT) |
536 | reiserfs_warning(tb->tb_sb, "vs-8115: get_num_ver: not " | 536 | reiserfs_warning(tb->tb_sb, "vs-8115", |
537 | "directory or indirect item"); | 537 | "not directory or indirect item"); |
538 | } | 538 | } |
539 | 539 | ||
540 | /* now we know S2bytes, calculate S1bytes */ | 540 | /* now we know S2bytes, calculate S1bytes */ |
@@ -569,7 +569,7 @@ extern struct tree_balance *cur_tb; | |||
569 | 569 | ||
570 | /* Set parameters for balancing. | 570 | /* Set parameters for balancing. |
571 | * Performs write of results of analysis of balancing into structure tb, | 571 | * Performs write of results of analysis of balancing into structure tb, |
572 | * where it will later be used by the functions that actually do the balancing. | 572 | * where it will later be used by the functions that actually do the balancing. |
573 | * Parameters: | 573 | * Parameters: |
574 | * tb tree_balance structure; | 574 | * tb tree_balance structure; |
575 | * h current level of the node; | 575 | * h current level of the node; |
@@ -749,25 +749,26 @@ else \ | |||
749 | -1, -1);\ | 749 | -1, -1);\ |
750 | } | 750 | } |
751 | 751 | ||
752 | static void free_buffers_in_tb(struct tree_balance *p_s_tb) | 752 | static void free_buffers_in_tb(struct tree_balance *tb) |
753 | { | 753 | { |
754 | int n_counter; | 754 | int i; |
755 | 755 | ||
756 | decrement_counters_in_path(p_s_tb->tb_path); | 756 | pathrelse(tb->tb_path); |
757 | 757 | ||
758 | for (n_counter = 0; n_counter < MAX_HEIGHT; n_counter++) { | 758 | for (i = 0; i < MAX_HEIGHT; i++) { |
759 | decrement_bcount(p_s_tb->L[n_counter]); | 759 | brelse(tb->L[i]); |
760 | p_s_tb->L[n_counter] = NULL; | 760 | brelse(tb->R[i]); |
761 | decrement_bcount(p_s_tb->R[n_counter]); | 761 | brelse(tb->FL[i]); |
762 | p_s_tb->R[n_counter] = NULL; | 762 | brelse(tb->FR[i]); |
763 | decrement_bcount(p_s_tb->FL[n_counter]); | 763 | brelse(tb->CFL[i]); |
764 | p_s_tb->FL[n_counter] = NULL; | 764 | brelse(tb->CFR[i]); |
765 | decrement_bcount(p_s_tb->FR[n_counter]); | 765 | |
766 | p_s_tb->FR[n_counter] = NULL; | 766 | tb->L[i] = NULL; |
767 | decrement_bcount(p_s_tb->CFL[n_counter]); | 767 | tb->R[i] = NULL; |
768 | p_s_tb->CFL[n_counter] = NULL; | 768 | tb->FL[i] = NULL; |
769 | decrement_bcount(p_s_tb->CFR[n_counter]); | 769 | tb->FR[i] = NULL; |
770 | p_s_tb->CFR[n_counter] = NULL; | 770 | tb->CFL[i] = NULL; |
771 | tb->CFR[i] = NULL; | ||
771 | } | 772 | } |
772 | } | 773 | } |
773 | 774 | ||
@@ -777,14 +778,14 @@ static void free_buffers_in_tb(struct tree_balance *p_s_tb) | |||
777 | * NO_DISK_SPACE - no disk space. | 778 | * NO_DISK_SPACE - no disk space. |
778 | */ | 779 | */ |
779 | /* The function is NOT SCHEDULE-SAFE! */ | 780 | /* The function is NOT SCHEDULE-SAFE! */ |
780 | static int get_empty_nodes(struct tree_balance *p_s_tb, int n_h) | 781 | static int get_empty_nodes(struct tree_balance *tb, int h) |
781 | { | 782 | { |
782 | struct buffer_head *p_s_new_bh, | 783 | struct buffer_head *new_bh, |
783 | *p_s_Sh = PATH_H_PBUFFER(p_s_tb->tb_path, n_h); | 784 | *Sh = PATH_H_PBUFFER(tb->tb_path, h); |
784 | b_blocknr_t *p_n_blocknr, a_n_blocknrs[MAX_AMOUNT_NEEDED] = { 0, }; | 785 | b_blocknr_t *blocknr, blocknrs[MAX_AMOUNT_NEEDED] = { 0, }; |
785 | int n_counter, n_number_of_freeblk, n_amount_needed, /* number of needed empty blocks */ | 786 | int counter, number_of_freeblk, amount_needed, /* number of needed empty blocks */ |
786 | n_retval = CARRY_ON; | 787 | retval = CARRY_ON; |
787 | struct super_block *p_s_sb = p_s_tb->tb_sb; | 788 | struct super_block *sb = tb->tb_sb; |
788 | 789 | ||
789 | /* number_of_freeblk is the number of empty blocks which have been | 790 | /* number_of_freeblk is the number of empty blocks which have been |
790 | acquired for use by the balancing algorithm minus the number of | 791 | acquired for use by the balancing algorithm minus the number of |
@@ -792,7 +793,7 @@ static int get_empty_nodes(struct tree_balance *p_s_tb, int n_h) | |||
792 | number_of_freeblk = tb->cur_blknum can be non-zero if a schedule occurs | 793 | number_of_freeblk = tb->cur_blknum can be non-zero if a schedule occurs |
793 | after empty blocks are acquired, and the balancing analysis is | 794 | after empty blocks are acquired, and the balancing analysis is |
794 | then restarted, amount_needed is the number needed by this level | 795 | then restarted, amount_needed is the number needed by this level |
795 | (n_h) of the balancing analysis. | 796 | (h) of the balancing analysis. |
796 | 797 | ||
797 | Note that for systems with many processes writing, it would be | 798 | Note that for systems with many processes writing, it would be |
798 | more layout optimal to calculate the total number needed by all | 799 | more layout optimal to calculate the total number needed by all |
@@ -800,54 +801,54 @@ static int get_empty_nodes(struct tree_balance *p_s_tb, int n_h) | |||
800 | 801 | ||
801 | /* Initiate number_of_freeblk to the amount acquired prior to the restart of | 802 | /* Initiate number_of_freeblk to the amount acquired prior to the restart of |
802 | the analysis or 0 if not restarted, then subtract the amount needed | 803 | the analysis or 0 if not restarted, then subtract the amount needed |
803 | by all of the levels of the tree below n_h. */ | 804 | by all of the levels of the tree below h. */ |
804 | /* blknum includes S[n_h], so we subtract 1 in this calculation */ | 805 | /* blknum includes S[h], so we subtract 1 in this calculation */ |
805 | for (n_counter = 0, n_number_of_freeblk = p_s_tb->cur_blknum; | 806 | for (counter = 0, number_of_freeblk = tb->cur_blknum; |
806 | n_counter < n_h; n_counter++) | 807 | counter < h; counter++) |
807 | n_number_of_freeblk -= | 808 | number_of_freeblk -= |
808 | (p_s_tb->blknum[n_counter]) ? (p_s_tb->blknum[n_counter] - | 809 | (tb->blknum[counter]) ? (tb->blknum[counter] - |
809 | 1) : 0; | 810 | 1) : 0; |
810 | 811 | ||
811 | /* Allocate missing empty blocks. */ | 812 | /* Allocate missing empty blocks. */ |
812 | /* if p_s_Sh == 0 then we are getting a new root */ | 813 | /* if Sh == 0 then we are getting a new root */ |
813 | n_amount_needed = (p_s_Sh) ? (p_s_tb->blknum[n_h] - 1) : 1; | 814 | amount_needed = (Sh) ? (tb->blknum[h] - 1) : 1; |
814 | /* Amount_needed = the amount that we need more than the amount that we have. */ | 815 | /* Amount_needed = the amount that we need more than the amount that we have. */ |
815 | if (n_amount_needed > n_number_of_freeblk) | 816 | if (amount_needed > number_of_freeblk) |
816 | n_amount_needed -= n_number_of_freeblk; | 817 | amount_needed -= number_of_freeblk; |
817 | else /* If we have enough already then there is nothing to do. */ | 818 | else /* If we have enough already then there is nothing to do. */ |
818 | return CARRY_ON; | 819 | return CARRY_ON; |
819 | 820 | ||
820 | /* No need to check quota - is not allocated for blocks used for formatted nodes */ | 821 | /* No need to check quota - is not allocated for blocks used for formatted nodes */ |
821 | if (reiserfs_new_form_blocknrs(p_s_tb, a_n_blocknrs, | 822 | if (reiserfs_new_form_blocknrs(tb, blocknrs, |
822 | n_amount_needed) == NO_DISK_SPACE) | 823 | amount_needed) == NO_DISK_SPACE) |
823 | return NO_DISK_SPACE; | 824 | return NO_DISK_SPACE; |
824 | 825 | ||
825 | /* for each blocknumber we just got, get a buffer and stick it on FEB */ | 826 | /* for each blocknumber we just got, get a buffer and stick it on FEB */ |
826 | for (p_n_blocknr = a_n_blocknrs, n_counter = 0; | 827 | for (blocknr = blocknrs, counter = 0; |
827 | n_counter < n_amount_needed; p_n_blocknr++, n_counter++) { | 828 | counter < amount_needed; blocknr++, counter++) { |
828 | 829 | ||
829 | RFALSE(!*p_n_blocknr, | 830 | RFALSE(!*blocknr, |
830 | "PAP-8135: reiserfs_new_blocknrs failed when got new blocks"); | 831 | "PAP-8135: reiserfs_new_blocknrs failed when got new blocks"); |
831 | 832 | ||
832 | p_s_new_bh = sb_getblk(p_s_sb, *p_n_blocknr); | 833 | new_bh = sb_getblk(sb, *blocknr); |
833 | RFALSE(buffer_dirty(p_s_new_bh) || | 834 | RFALSE(buffer_dirty(new_bh) || |
834 | buffer_journaled(p_s_new_bh) || | 835 | buffer_journaled(new_bh) || |
835 | buffer_journal_dirty(p_s_new_bh), | 836 | buffer_journal_dirty(new_bh), |
836 | "PAP-8140: journlaled or dirty buffer %b for the new block", | 837 | "PAP-8140: journlaled or dirty buffer %b for the new block", |
837 | p_s_new_bh); | 838 | new_bh); |
838 | 839 | ||
839 | /* Put empty buffers into the array. */ | 840 | /* Put empty buffers into the array. */ |
840 | RFALSE(p_s_tb->FEB[p_s_tb->cur_blknum], | 841 | RFALSE(tb->FEB[tb->cur_blknum], |
841 | "PAP-8141: busy slot for new buffer"); | 842 | "PAP-8141: busy slot for new buffer"); |
842 | 843 | ||
843 | set_buffer_journal_new(p_s_new_bh); | 844 | set_buffer_journal_new(new_bh); |
844 | p_s_tb->FEB[p_s_tb->cur_blknum++] = p_s_new_bh; | 845 | tb->FEB[tb->cur_blknum++] = new_bh; |
845 | } | 846 | } |
846 | 847 | ||
847 | if (n_retval == CARRY_ON && FILESYSTEM_CHANGED_TB(p_s_tb)) | 848 | if (retval == CARRY_ON && FILESYSTEM_CHANGED_TB(tb)) |
848 | n_retval = REPEAT_SEARCH; | 849 | retval = REPEAT_SEARCH; |
849 | 850 | ||
850 | return n_retval; | 851 | return retval; |
851 | } | 852 | } |
852 | 853 | ||
853 | /* Get free space of the left neighbor, which is stored in the parent | 854 | /* Get free space of the left neighbor, which is stored in the parent |
@@ -895,35 +896,36 @@ static int get_rfree(struct tree_balance *tb, int h) | |||
895 | } | 896 | } |
896 | 897 | ||
897 | /* Check whether left neighbor is in memory. */ | 898 | /* Check whether left neighbor is in memory. */ |
898 | static int is_left_neighbor_in_cache(struct tree_balance *p_s_tb, int n_h) | 899 | static int is_left_neighbor_in_cache(struct tree_balance *tb, int h) |
899 | { | 900 | { |
900 | struct buffer_head *p_s_father, *left; | 901 | struct buffer_head *father, *left; |
901 | struct super_block *p_s_sb = p_s_tb->tb_sb; | 902 | struct super_block *sb = tb->tb_sb; |
902 | b_blocknr_t n_left_neighbor_blocknr; | 903 | b_blocknr_t left_neighbor_blocknr; |
903 | int n_left_neighbor_position; | 904 | int left_neighbor_position; |
904 | 905 | ||
905 | if (!p_s_tb->FL[n_h]) /* Father of the left neighbor does not exist. */ | 906 | /* Father of the left neighbor does not exist. */ |
907 | if (!tb->FL[h]) | ||
906 | return 0; | 908 | return 0; |
907 | 909 | ||
908 | /* Calculate father of the node to be balanced. */ | 910 | /* Calculate father of the node to be balanced. */ |
909 | p_s_father = PATH_H_PBUFFER(p_s_tb->tb_path, n_h + 1); | 911 | father = PATH_H_PBUFFER(tb->tb_path, h + 1); |
910 | 912 | ||
911 | RFALSE(!p_s_father || | 913 | RFALSE(!father || |
912 | !B_IS_IN_TREE(p_s_father) || | 914 | !B_IS_IN_TREE(father) || |
913 | !B_IS_IN_TREE(p_s_tb->FL[n_h]) || | 915 | !B_IS_IN_TREE(tb->FL[h]) || |
914 | !buffer_uptodate(p_s_father) || | 916 | !buffer_uptodate(father) || |
915 | !buffer_uptodate(p_s_tb->FL[n_h]), | 917 | !buffer_uptodate(tb->FL[h]), |
916 | "vs-8165: F[h] (%b) or FL[h] (%b) is invalid", | 918 | "vs-8165: F[h] (%b) or FL[h] (%b) is invalid", |
917 | p_s_father, p_s_tb->FL[n_h]); | 919 | father, tb->FL[h]); |
918 | 920 | ||
919 | /* Get position of the pointer to the left neighbor into the left father. */ | 921 | /* Get position of the pointer to the left neighbor into the left father. */ |
920 | n_left_neighbor_position = (p_s_father == p_s_tb->FL[n_h]) ? | 922 | left_neighbor_position = (father == tb->FL[h]) ? |
921 | p_s_tb->lkey[n_h] : B_NR_ITEMS(p_s_tb->FL[n_h]); | 923 | tb->lkey[h] : B_NR_ITEMS(tb->FL[h]); |
922 | /* Get left neighbor block number. */ | 924 | /* Get left neighbor block number. */ |
923 | n_left_neighbor_blocknr = | 925 | left_neighbor_blocknr = |
924 | B_N_CHILD_NUM(p_s_tb->FL[n_h], n_left_neighbor_position); | 926 | B_N_CHILD_NUM(tb->FL[h], left_neighbor_position); |
925 | /* Look for the left neighbor in the cache. */ | 927 | /* Look for the left neighbor in the cache. */ |
926 | if ((left = sb_find_get_block(p_s_sb, n_left_neighbor_blocknr))) { | 928 | if ((left = sb_find_get_block(sb, left_neighbor_blocknr))) { |
927 | 929 | ||
928 | RFALSE(buffer_uptodate(left) && !B_IS_IN_TREE(left), | 930 | RFALSE(buffer_uptodate(left) && !B_IS_IN_TREE(left), |
929 | "vs-8170: left neighbor (%b %z) is not in the tree", | 931 | "vs-8170: left neighbor (%b %z) is not in the tree", |
@@ -938,10 +940,10 @@ static int is_left_neighbor_in_cache(struct tree_balance *p_s_tb, int n_h) | |||
938 | #define LEFT_PARENTS 'l' | 940 | #define LEFT_PARENTS 'l' |
939 | #define RIGHT_PARENTS 'r' | 941 | #define RIGHT_PARENTS 'r' |
940 | 942 | ||
941 | static void decrement_key(struct cpu_key *p_s_key) | 943 | static void decrement_key(struct cpu_key *key) |
942 | { | 944 | { |
943 | // call item specific function for this key | 945 | // call item specific function for this key |
944 | item_ops[cpu_key_k_type(p_s_key)]->decrement_key(p_s_key); | 946 | item_ops[cpu_key_k_type(key)]->decrement_key(key); |
945 | } | 947 | } |
946 | 948 | ||
947 | /* Calculate far left/right parent of the left/right neighbor of the current node, that | 949 | /* Calculate far left/right parent of the left/right neighbor of the current node, that |
@@ -952,77 +954,77 @@ static void decrement_key(struct cpu_key *p_s_key) | |||
952 | SCHEDULE_OCCURRED - schedule occurred while the function worked; | 954 | SCHEDULE_OCCURRED - schedule occurred while the function worked; |
953 | * CARRY_ON - schedule didn't occur while the function worked; | 955 | * CARRY_ON - schedule didn't occur while the function worked; |
954 | */ | 956 | */ |
955 | static int get_far_parent(struct tree_balance *p_s_tb, | 957 | static int get_far_parent(struct tree_balance *tb, |
956 | int n_h, | 958 | int h, |
957 | struct buffer_head **pp_s_father, | 959 | struct buffer_head **pfather, |
958 | struct buffer_head **pp_s_com_father, char c_lr_par) | 960 | struct buffer_head **pcom_father, char c_lr_par) |
959 | { | 961 | { |
960 | struct buffer_head *p_s_parent; | 962 | struct buffer_head *parent; |
961 | INITIALIZE_PATH(s_path_to_neighbor_father); | 963 | INITIALIZE_PATH(s_path_to_neighbor_father); |
962 | struct treepath *p_s_path = p_s_tb->tb_path; | 964 | struct treepath *path = tb->tb_path; |
963 | struct cpu_key s_lr_father_key; | 965 | struct cpu_key s_lr_father_key; |
964 | int n_counter, | 966 | int counter, |
965 | n_position = INT_MAX, | 967 | position = INT_MAX, |
966 | n_first_last_position = 0, | 968 | first_last_position = 0, |
967 | n_path_offset = PATH_H_PATH_OFFSET(p_s_path, n_h); | 969 | path_offset = PATH_H_PATH_OFFSET(path, h); |
968 | 970 | ||
969 | /* Starting from F[n_h] go upwards in the tree, and look for the common | 971 | /* Starting from F[h] go upwards in the tree, and look for the common |
970 | ancestor of F[n_h], and its neighbor l/r, that should be obtained. */ | 972 | ancestor of F[h], and its neighbor l/r, that should be obtained. */ |
971 | 973 | ||
972 | n_counter = n_path_offset; | 974 | counter = path_offset; |
973 | 975 | ||
974 | RFALSE(n_counter < FIRST_PATH_ELEMENT_OFFSET, | 976 | RFALSE(counter < FIRST_PATH_ELEMENT_OFFSET, |
975 | "PAP-8180: invalid path length"); | 977 | "PAP-8180: invalid path length"); |
976 | 978 | ||
977 | for (; n_counter > FIRST_PATH_ELEMENT_OFFSET; n_counter--) { | 979 | for (; counter > FIRST_PATH_ELEMENT_OFFSET; counter--) { |
978 | /* Check whether parent of the current buffer in the path is really parent in the tree. */ | 980 | /* Check whether parent of the current buffer in the path is really parent in the tree. */ |
979 | if (!B_IS_IN_TREE | 981 | if (!B_IS_IN_TREE |
980 | (p_s_parent = PATH_OFFSET_PBUFFER(p_s_path, n_counter - 1))) | 982 | (parent = PATH_OFFSET_PBUFFER(path, counter - 1))) |
981 | return REPEAT_SEARCH; | 983 | return REPEAT_SEARCH; |
982 | /* Check whether position in the parent is correct. */ | 984 | /* Check whether position in the parent is correct. */ |
983 | if ((n_position = | 985 | if ((position = |
984 | PATH_OFFSET_POSITION(p_s_path, | 986 | PATH_OFFSET_POSITION(path, |
985 | n_counter - 1)) > | 987 | counter - 1)) > |
986 | B_NR_ITEMS(p_s_parent)) | 988 | B_NR_ITEMS(parent)) |
987 | return REPEAT_SEARCH; | 989 | return REPEAT_SEARCH; |
988 | /* Check whether parent at the path really points to the child. */ | 990 | /* Check whether parent at the path really points to the child. */ |
989 | if (B_N_CHILD_NUM(p_s_parent, n_position) != | 991 | if (B_N_CHILD_NUM(parent, position) != |
990 | PATH_OFFSET_PBUFFER(p_s_path, n_counter)->b_blocknr) | 992 | PATH_OFFSET_PBUFFER(path, counter)->b_blocknr) |
991 | return REPEAT_SEARCH; | 993 | return REPEAT_SEARCH; |
992 | /* Return delimiting key if position in the parent is not equal to first/last one. */ | 994 | /* Return delimiting key if position in the parent is not equal to first/last one. */ |
993 | if (c_lr_par == RIGHT_PARENTS) | 995 | if (c_lr_par == RIGHT_PARENTS) |
994 | n_first_last_position = B_NR_ITEMS(p_s_parent); | 996 | first_last_position = B_NR_ITEMS(parent); |
995 | if (n_position != n_first_last_position) { | 997 | if (position != first_last_position) { |
996 | *pp_s_com_father = p_s_parent; | 998 | *pcom_father = parent; |
997 | get_bh(*pp_s_com_father); | 999 | get_bh(*pcom_father); |
998 | /*(*pp_s_com_father = p_s_parent)->b_count++; */ | 1000 | /*(*pcom_father = parent)->b_count++; */ |
999 | break; | 1001 | break; |
1000 | } | 1002 | } |
1001 | } | 1003 | } |
1002 | 1004 | ||
1003 | /* if we are in the root of the tree, then there is no common father */ | 1005 | /* if we are in the root of the tree, then there is no common father */ |
1004 | if (n_counter == FIRST_PATH_ELEMENT_OFFSET) { | 1006 | if (counter == FIRST_PATH_ELEMENT_OFFSET) { |
1005 | /* Check whether first buffer in the path is the root of the tree. */ | 1007 | /* Check whether first buffer in the path is the root of the tree. */ |
1006 | if (PATH_OFFSET_PBUFFER | 1008 | if (PATH_OFFSET_PBUFFER |
1007 | (p_s_tb->tb_path, | 1009 | (tb->tb_path, |
1008 | FIRST_PATH_ELEMENT_OFFSET)->b_blocknr == | 1010 | FIRST_PATH_ELEMENT_OFFSET)->b_blocknr == |
1009 | SB_ROOT_BLOCK(p_s_tb->tb_sb)) { | 1011 | SB_ROOT_BLOCK(tb->tb_sb)) { |
1010 | *pp_s_father = *pp_s_com_father = NULL; | 1012 | *pfather = *pcom_father = NULL; |
1011 | return CARRY_ON; | 1013 | return CARRY_ON; |
1012 | } | 1014 | } |
1013 | return REPEAT_SEARCH; | 1015 | return REPEAT_SEARCH; |
1014 | } | 1016 | } |
1015 | 1017 | ||
1016 | RFALSE(B_LEVEL(*pp_s_com_father) <= DISK_LEAF_NODE_LEVEL, | 1018 | RFALSE(B_LEVEL(*pcom_father) <= DISK_LEAF_NODE_LEVEL, |
1017 | "PAP-8185: (%b %z) level too small", | 1019 | "PAP-8185: (%b %z) level too small", |
1018 | *pp_s_com_father, *pp_s_com_father); | 1020 | *pcom_father, *pcom_father); |
1019 | 1021 | ||
1020 | /* Check whether the common parent is locked. */ | 1022 | /* Check whether the common parent is locked. */ |
1021 | 1023 | ||
1022 | if (buffer_locked(*pp_s_com_father)) { | 1024 | if (buffer_locked(*pcom_father)) { |
1023 | __wait_on_buffer(*pp_s_com_father); | 1025 | __wait_on_buffer(*pcom_father); |
1024 | if (FILESYSTEM_CHANGED_TB(p_s_tb)) { | 1026 | if (FILESYSTEM_CHANGED_TB(tb)) { |
1025 | decrement_bcount(*pp_s_com_father); | 1027 | brelse(*pcom_father); |
1026 | return REPEAT_SEARCH; | 1028 | return REPEAT_SEARCH; |
1027 | } | 1029 | } |
1028 | } | 1030 | } |
@@ -1032,128 +1034,131 @@ static int get_far_parent(struct tree_balance *p_s_tb, | |||
1032 | 1034 | ||
1033 | /* Form key to get parent of the left/right neighbor. */ | 1035 | /* Form key to get parent of the left/right neighbor. */ |
1034 | le_key2cpu_key(&s_lr_father_key, | 1036 | le_key2cpu_key(&s_lr_father_key, |
1035 | B_N_PDELIM_KEY(*pp_s_com_father, | 1037 | B_N_PDELIM_KEY(*pcom_father, |
1036 | (c_lr_par == | 1038 | (c_lr_par == |
1037 | LEFT_PARENTS) ? (p_s_tb->lkey[n_h - 1] = | 1039 | LEFT_PARENTS) ? (tb->lkey[h - 1] = |
1038 | n_position - | 1040 | position - |
1039 | 1) : (p_s_tb->rkey[n_h - | 1041 | 1) : (tb->rkey[h - |
1040 | 1] = | 1042 | 1] = |
1041 | n_position))); | 1043 | position))); |
1042 | 1044 | ||
1043 | if (c_lr_par == LEFT_PARENTS) | 1045 | if (c_lr_par == LEFT_PARENTS) |
1044 | decrement_key(&s_lr_father_key); | 1046 | decrement_key(&s_lr_father_key); |
1045 | 1047 | ||
1046 | if (search_by_key | 1048 | if (search_by_key |
1047 | (p_s_tb->tb_sb, &s_lr_father_key, &s_path_to_neighbor_father, | 1049 | (tb->tb_sb, &s_lr_father_key, &s_path_to_neighbor_father, |
1048 | n_h + 1) == IO_ERROR) | 1050 | h + 1) == IO_ERROR) |
1049 | // path is released | 1051 | // path is released |
1050 | return IO_ERROR; | 1052 | return IO_ERROR; |
1051 | 1053 | ||
1052 | if (FILESYSTEM_CHANGED_TB(p_s_tb)) { | 1054 | if (FILESYSTEM_CHANGED_TB(tb)) { |
1053 | decrement_counters_in_path(&s_path_to_neighbor_father); | 1055 | pathrelse(&s_path_to_neighbor_father); |
1054 | decrement_bcount(*pp_s_com_father); | 1056 | brelse(*pcom_father); |
1055 | return REPEAT_SEARCH; | 1057 | return REPEAT_SEARCH; |
1056 | } | 1058 | } |
1057 | 1059 | ||
1058 | *pp_s_father = PATH_PLAST_BUFFER(&s_path_to_neighbor_father); | 1060 | *pfather = PATH_PLAST_BUFFER(&s_path_to_neighbor_father); |
1059 | 1061 | ||
1060 | RFALSE(B_LEVEL(*pp_s_father) != n_h + 1, | 1062 | RFALSE(B_LEVEL(*pfather) != h + 1, |
1061 | "PAP-8190: (%b %z) level too small", *pp_s_father, *pp_s_father); | 1063 | "PAP-8190: (%b %z) level too small", *pfather, *pfather); |
1062 | RFALSE(s_path_to_neighbor_father.path_length < | 1064 | RFALSE(s_path_to_neighbor_father.path_length < |
1063 | FIRST_PATH_ELEMENT_OFFSET, "PAP-8192: path length is too small"); | 1065 | FIRST_PATH_ELEMENT_OFFSET, "PAP-8192: path length is too small"); |
1064 | 1066 | ||
1065 | s_path_to_neighbor_father.path_length--; | 1067 | s_path_to_neighbor_father.path_length--; |
1066 | decrement_counters_in_path(&s_path_to_neighbor_father); | 1068 | pathrelse(&s_path_to_neighbor_father); |
1067 | return CARRY_ON; | 1069 | return CARRY_ON; |
1068 | } | 1070 | } |
1069 | 1071 | ||
1070 | /* Get parents of neighbors of node in the path(S[n_path_offset]) and common parents of | 1072 | /* Get parents of neighbors of node in the path(S[path_offset]) and common parents of |
1071 | * S[n_path_offset] and L[n_path_offset]/R[n_path_offset]: F[n_path_offset], FL[n_path_offset], | 1073 | * S[path_offset] and L[path_offset]/R[path_offset]: F[path_offset], FL[path_offset], |
1072 | * FR[n_path_offset], CFL[n_path_offset], CFR[n_path_offset]. | 1074 | * FR[path_offset], CFL[path_offset], CFR[path_offset]. |
1073 | * Calculate numbers of left and right delimiting keys position: lkey[n_path_offset], rkey[n_path_offset]. | 1075 | * Calculate numbers of left and right delimiting keys position: lkey[path_offset], rkey[path_offset]. |
1074 | * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked; | 1076 | * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked; |
1075 | * CARRY_ON - schedule didn't occur while the function worked; | 1077 | * CARRY_ON - schedule didn't occur while the function worked; |
1076 | */ | 1078 | */ |
1077 | static int get_parents(struct tree_balance *p_s_tb, int n_h) | 1079 | static int get_parents(struct tree_balance *tb, int h) |
1078 | { | 1080 | { |
1079 | struct treepath *p_s_path = p_s_tb->tb_path; | 1081 | struct treepath *path = tb->tb_path; |
1080 | int n_position, | 1082 | int position, |
1081 | n_ret_value, | 1083 | ret, |
1082 | n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h); | 1084 | path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h); |
1083 | struct buffer_head *p_s_curf, *p_s_curcf; | 1085 | struct buffer_head *curf, *curcf; |
1084 | 1086 | ||
1085 | /* Current node is the root of the tree or will be root of the tree */ | 1087 | /* Current node is the root of the tree or will be root of the tree */ |
1086 | if (n_path_offset <= FIRST_PATH_ELEMENT_OFFSET) { | 1088 | if (path_offset <= FIRST_PATH_ELEMENT_OFFSET) { |
1087 | /* The root can not have parents. | 1089 | /* The root can not have parents. |
1088 | Release nodes which previously were obtained as parents of the current node neighbors. */ | 1090 | Release nodes which previously were obtained as parents of the current node neighbors. */ |
1089 | decrement_bcount(p_s_tb->FL[n_h]); | 1091 | brelse(tb->FL[h]); |
1090 | decrement_bcount(p_s_tb->CFL[n_h]); | 1092 | brelse(tb->CFL[h]); |
1091 | decrement_bcount(p_s_tb->FR[n_h]); | 1093 | brelse(tb->FR[h]); |
1092 | decrement_bcount(p_s_tb->CFR[n_h]); | 1094 | brelse(tb->CFR[h]); |
1093 | p_s_tb->FL[n_h] = p_s_tb->CFL[n_h] = p_s_tb->FR[n_h] = | 1095 | tb->FL[h] = NULL; |
1094 | p_s_tb->CFR[n_h] = NULL; | 1096 | tb->CFL[h] = NULL; |
1097 | tb->FR[h] = NULL; | ||
1098 | tb->CFR[h] = NULL; | ||
1095 | return CARRY_ON; | 1099 | return CARRY_ON; |
1096 | } | 1100 | } |
1097 | 1101 | ||
1098 | /* Get parent FL[n_path_offset] of L[n_path_offset]. */ | 1102 | /* Get parent FL[path_offset] of L[path_offset]. */ |
1099 | if ((n_position = PATH_OFFSET_POSITION(p_s_path, n_path_offset - 1))) { | 1103 | position = PATH_OFFSET_POSITION(path, path_offset - 1); |
1104 | if (position) { | ||
1100 | /* Current node is not the first child of its parent. */ | 1105 | /* Current node is not the first child of its parent. */ |
1101 | /*(p_s_curf = p_s_curcf = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1))->b_count += 2; */ | 1106 | curf = PATH_OFFSET_PBUFFER(path, path_offset - 1); |
1102 | p_s_curf = p_s_curcf = | 1107 | curcf = PATH_OFFSET_PBUFFER(path, path_offset - 1); |
1103 | PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1); | 1108 | get_bh(curf); |
1104 | get_bh(p_s_curf); | 1109 | get_bh(curf); |
1105 | get_bh(p_s_curf); | 1110 | tb->lkey[h] = position - 1; |
1106 | p_s_tb->lkey[n_h] = n_position - 1; | ||
1107 | } else { | 1111 | } else { |
1108 | /* Calculate current parent of L[n_path_offset], which is the left neighbor of the current node. | 1112 | /* Calculate current parent of L[path_offset], which is the left neighbor of the current node. |
1109 | Calculate current common parent of L[n_path_offset] and the current node. Note that | 1113 | Calculate current common parent of L[path_offset] and the current node. Note that |
1110 | CFL[n_path_offset] not equal FL[n_path_offset] and CFL[n_path_offset] not equal F[n_path_offset]. | 1114 | CFL[path_offset] not equal FL[path_offset] and CFL[path_offset] not equal F[path_offset]. |
1111 | Calculate lkey[n_path_offset]. */ | 1115 | Calculate lkey[path_offset]. */ |
1112 | if ((n_ret_value = get_far_parent(p_s_tb, n_h + 1, &p_s_curf, | 1116 | if ((ret = get_far_parent(tb, h + 1, &curf, |
1113 | &p_s_curcf, | 1117 | &curcf, |
1114 | LEFT_PARENTS)) != CARRY_ON) | 1118 | LEFT_PARENTS)) != CARRY_ON) |
1115 | return n_ret_value; | 1119 | return ret; |
1116 | } | 1120 | } |
1117 | 1121 | ||
1118 | decrement_bcount(p_s_tb->FL[n_h]); | 1122 | brelse(tb->FL[h]); |
1119 | p_s_tb->FL[n_h] = p_s_curf; /* New initialization of FL[n_h]. */ | 1123 | tb->FL[h] = curf; /* New initialization of FL[h]. */ |
1120 | decrement_bcount(p_s_tb->CFL[n_h]); | 1124 | brelse(tb->CFL[h]); |
1121 | p_s_tb->CFL[n_h] = p_s_curcf; /* New initialization of CFL[n_h]. */ | 1125 | tb->CFL[h] = curcf; /* New initialization of CFL[h]. */ |
1122 | 1126 | ||
1123 | RFALSE((p_s_curf && !B_IS_IN_TREE(p_s_curf)) || | 1127 | RFALSE((curf && !B_IS_IN_TREE(curf)) || |
1124 | (p_s_curcf && !B_IS_IN_TREE(p_s_curcf)), | 1128 | (curcf && !B_IS_IN_TREE(curcf)), |
1125 | "PAP-8195: FL (%b) or CFL (%b) is invalid", p_s_curf, p_s_curcf); | 1129 | "PAP-8195: FL (%b) or CFL (%b) is invalid", curf, curcf); |
1126 | 1130 | ||
1127 | /* Get parent FR[n_h] of R[n_h]. */ | 1131 | /* Get parent FR[h] of R[h]. */ |
1128 | 1132 | ||
1129 | /* Current node is the last child of F[n_h]. FR[n_h] != F[n_h]. */ | 1133 | /* Current node is the last child of F[h]. FR[h] != F[h]. */ |
1130 | if (n_position == B_NR_ITEMS(PATH_H_PBUFFER(p_s_path, n_h + 1))) { | 1134 | if (position == B_NR_ITEMS(PATH_H_PBUFFER(path, h + 1))) { |
1131 | /* Calculate current parent of R[n_h], which is the right neighbor of F[n_h]. | 1135 | /* Calculate current parent of R[h], which is the right neighbor of F[h]. |
1132 | Calculate current common parent of R[n_h] and current node. Note that CFR[n_h] | 1136 | Calculate current common parent of R[h] and current node. Note that CFR[h] |
1133 | not equal FR[n_path_offset] and CFR[n_h] not equal F[n_h]. */ | 1137 | not equal FR[path_offset] and CFR[h] not equal F[h]. */ |
1134 | if ((n_ret_value = | 1138 | if ((ret = |
1135 | get_far_parent(p_s_tb, n_h + 1, &p_s_curf, &p_s_curcf, | 1139 | get_far_parent(tb, h + 1, &curf, &curcf, |
1136 | RIGHT_PARENTS)) != CARRY_ON) | 1140 | RIGHT_PARENTS)) != CARRY_ON) |
1137 | return n_ret_value; | 1141 | return ret; |
1138 | } else { | 1142 | } else { |
1139 | /* Current node is not the last child of its parent F[n_h]. */ | 1143 | /* Current node is not the last child of its parent F[h]. */ |
1140 | /*(p_s_curf = p_s_curcf = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1))->b_count += 2; */ | 1144 | curf = PATH_OFFSET_PBUFFER(path, path_offset - 1); |
1141 | p_s_curf = p_s_curcf = | 1145 | curcf = PATH_OFFSET_PBUFFER(path, path_offset - 1); |
1142 | PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1); | 1146 | get_bh(curf); |
1143 | get_bh(p_s_curf); | 1147 | get_bh(curf); |
1144 | get_bh(p_s_curf); | 1148 | tb->rkey[h] = position; |
1145 | p_s_tb->rkey[n_h] = n_position; | ||
1146 | } | 1149 | } |
1147 | 1150 | ||
1148 | decrement_bcount(p_s_tb->FR[n_h]); | 1151 | brelse(tb->FR[h]); |
1149 | p_s_tb->FR[n_h] = p_s_curf; /* New initialization of FR[n_path_offset]. */ | 1152 | /* New initialization of FR[path_offset]. */ |
1153 | tb->FR[h] = curf; | ||
1150 | 1154 | ||
1151 | decrement_bcount(p_s_tb->CFR[n_h]); | 1155 | brelse(tb->CFR[h]); |
1152 | p_s_tb->CFR[n_h] = p_s_curcf; /* New initialization of CFR[n_path_offset]. */ | 1156 | /* New initialization of CFR[path_offset]. */ |
1157 | tb->CFR[h] = curcf; | ||
1153 | 1158 | ||
1154 | RFALSE((p_s_curf && !B_IS_IN_TREE(p_s_curf)) || | 1159 | RFALSE((curf && !B_IS_IN_TREE(curf)) || |
1155 | (p_s_curcf && !B_IS_IN_TREE(p_s_curcf)), | 1160 | (curcf && !B_IS_IN_TREE(curcf)), |
1156 | "PAP-8205: FR (%b) or CFR (%b) is invalid", p_s_curf, p_s_curcf); | 1161 | "PAP-8205: FR (%b) or CFR (%b) is invalid", curf, curcf); |
1157 | 1162 | ||
1158 | return CARRY_ON; | 1163 | return CARRY_ON; |
1159 | } | 1164 | } |
@@ -1203,7 +1208,7 @@ static inline int can_node_be_removed(int mode, int lfree, int sfree, int rfree, | |||
1203 | * h current level of the node; | 1208 | * h current level of the node; |
1204 | * inum item number in S[h]; | 1209 | * inum item number in S[h]; |
1205 | * mode i - insert, p - paste; | 1210 | * mode i - insert, p - paste; |
1206 | * Returns: 1 - schedule occurred; | 1211 | * Returns: 1 - schedule occurred; |
1207 | * 0 - balancing for higher levels needed; | 1212 | * 0 - balancing for higher levels needed; |
1208 | * -1 - no balancing for higher levels needed; | 1213 | * -1 - no balancing for higher levels needed; |
1209 | * -2 - no disk space. | 1214 | * -2 - no disk space. |
@@ -1217,7 +1222,7 @@ static int ip_check_balance(struct tree_balance *tb, int h) | |||
1217 | contains node being balanced. The mnemonic is | 1222 | contains node being balanced. The mnemonic is |
1218 | that the attempted change in node space used level | 1223 | that the attempted change in node space used level |
1219 | is levbytes bytes. */ | 1224 | is levbytes bytes. */ |
1220 | n_ret_value; | 1225 | ret; |
1221 | 1226 | ||
1222 | int lfree, sfree, rfree /* free space in L, S and R */ ; | 1227 | int lfree, sfree, rfree /* free space in L, S and R */ ; |
1223 | 1228 | ||
@@ -1238,7 +1243,7 @@ static int ip_check_balance(struct tree_balance *tb, int h) | |||
1238 | /* we perform 8 calls to get_num_ver(). For each call we calculate five parameters. | 1243 | /* we perform 8 calls to get_num_ver(). For each call we calculate five parameters. |
1239 | where 4th parameter is s1bytes and 5th - s2bytes | 1244 | where 4th parameter is s1bytes and 5th - s2bytes |
1240 | */ | 1245 | */ |
1241 | short snum012[40] = { 0, }; /* s0num, s1num, s2num for 8 cases | 1246 | short snum012[40] = { 0, }; /* s0num, s1num, s2num for 8 cases |
1242 | 0,1 - do not shift and do not shift but bottle | 1247 | 0,1 - do not shift and do not shift but bottle |
1243 | 2 - shift only whole item to left | 1248 | 2 - shift only whole item to left |
1244 | 3 - shift to left and bottle as much as possible | 1249 | 3 - shift to left and bottle as much as possible |
@@ -1255,24 +1260,24 @@ static int ip_check_balance(struct tree_balance *tb, int h) | |||
1255 | /* Calculate balance parameters for creating new root. */ | 1260 | /* Calculate balance parameters for creating new root. */ |
1256 | if (!Sh) { | 1261 | if (!Sh) { |
1257 | if (!h) | 1262 | if (!h) |
1258 | reiserfs_panic(tb->tb_sb, | 1263 | reiserfs_panic(tb->tb_sb, "vs-8210", |
1259 | "vs-8210: ip_check_balance: S[0] can not be 0"); | 1264 | "S[0] can not be 0"); |
1260 | switch (n_ret_value = get_empty_nodes(tb, h)) { | 1265 | switch (ret = get_empty_nodes(tb, h)) { |
1261 | case CARRY_ON: | 1266 | case CARRY_ON: |
1262 | set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); | 1267 | set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); |
1263 | return NO_BALANCING_NEEDED; /* no balancing for higher levels needed */ | 1268 | return NO_BALANCING_NEEDED; /* no balancing for higher levels needed */ |
1264 | 1269 | ||
1265 | case NO_DISK_SPACE: | 1270 | case NO_DISK_SPACE: |
1266 | case REPEAT_SEARCH: | 1271 | case REPEAT_SEARCH: |
1267 | return n_ret_value; | 1272 | return ret; |
1268 | default: | 1273 | default: |
1269 | reiserfs_panic(tb->tb_sb, | 1274 | reiserfs_panic(tb->tb_sb, "vs-8215", "incorrect " |
1270 | "vs-8215: ip_check_balance: incorrect return value of get_empty_nodes"); | 1275 | "return value of get_empty_nodes"); |
1271 | } | 1276 | } |
1272 | } | 1277 | } |
1273 | 1278 | ||
1274 | if ((n_ret_value = get_parents(tb, h)) != CARRY_ON) /* get parents of S[h] neighbors. */ | 1279 | if ((ret = get_parents(tb, h)) != CARRY_ON) /* get parents of S[h] neighbors. */ |
1275 | return n_ret_value; | 1280 | return ret; |
1276 | 1281 | ||
1277 | sfree = B_FREE_SPACE(Sh); | 1282 | sfree = B_FREE_SPACE(Sh); |
1278 | 1283 | ||
@@ -1287,7 +1292,7 @@ static int ip_check_balance(struct tree_balance *tb, int h) | |||
1287 | 1292 | ||
1288 | create_virtual_node(tb, h); | 1293 | create_virtual_node(tb, h); |
1289 | 1294 | ||
1290 | /* | 1295 | /* |
1291 | determine maximal number of items we can shift to the left neighbor (in tb structure) | 1296 | determine maximal number of items we can shift to the left neighbor (in tb structure) |
1292 | and the maximal number of bytes that can flow to the left neighbor | 1297 | and the maximal number of bytes that can flow to the left neighbor |
1293 | from the left most liquid item that cannot be shifted from S[0] entirely (returned value) | 1298 | from the left most liquid item that cannot be shifted from S[0] entirely (returned value) |
@@ -1348,13 +1353,13 @@ static int ip_check_balance(struct tree_balance *tb, int h) | |||
1348 | 1353 | ||
1349 | { | 1354 | { |
1350 | int lpar, rpar, nset, lset, rset, lrset; | 1355 | int lpar, rpar, nset, lset, rset, lrset; |
1351 | /* | 1356 | /* |
1352 | * regular overflowing of the node | 1357 | * regular overflowing of the node |
1353 | */ | 1358 | */ |
1354 | 1359 | ||
1355 | /* get_num_ver works in 2 modes (FLOW & NO_FLOW) | 1360 | /* get_num_ver works in 2 modes (FLOW & NO_FLOW) |
1356 | lpar, rpar - number of items we can shift to left/right neighbor (including splitting item) | 1361 | lpar, rpar - number of items we can shift to left/right neighbor (including splitting item) |
1357 | nset, lset, rset, lrset - shows, whether flowing items give better packing | 1362 | nset, lset, rset, lrset - shows, whether flowing items give better packing |
1358 | */ | 1363 | */ |
1359 | #define FLOW 1 | 1364 | #define FLOW 1 |
1360 | #define NO_FLOW 0 /* do not any splitting */ | 1365 | #define NO_FLOW 0 /* do not any splitting */ |
@@ -1544,7 +1549,7 @@ static int ip_check_balance(struct tree_balance *tb, int h) | |||
1544 | * h current level of the node; | 1549 | * h current level of the node; |
1545 | * inum item number in S[h]; | 1550 | * inum item number in S[h]; |
1546 | * mode i - insert, p - paste; | 1551 | * mode i - insert, p - paste; |
1547 | * Returns: 1 - schedule occurred; | 1552 | * Returns: 1 - schedule occurred; |
1548 | * 0 - balancing for higher levels needed; | 1553 | * 0 - balancing for higher levels needed; |
1549 | * -1 - no balancing for higher levels needed; | 1554 | * -1 - no balancing for higher levels needed; |
1550 | * -2 - no disk space. | 1555 | * -2 - no disk space. |
@@ -1559,7 +1564,7 @@ static int dc_check_balance_internal(struct tree_balance *tb, int h) | |||
1559 | /* Sh is the node whose balance is currently being checked, | 1564 | /* Sh is the node whose balance is currently being checked, |
1560 | and Fh is its father. */ | 1565 | and Fh is its father. */ |
1561 | struct buffer_head *Sh, *Fh; | 1566 | struct buffer_head *Sh, *Fh; |
1562 | int maxsize, n_ret_value; | 1567 | int maxsize, ret; |
1563 | int lfree, rfree /* free space in L and R */ ; | 1568 | int lfree, rfree /* free space in L and R */ ; |
1564 | 1569 | ||
1565 | Sh = PATH_H_PBUFFER(tb->tb_path, h); | 1570 | Sh = PATH_H_PBUFFER(tb->tb_path, h); |
@@ -1584,8 +1589,8 @@ static int dc_check_balance_internal(struct tree_balance *tb, int h) | |||
1584 | return CARRY_ON; | 1589 | return CARRY_ON; |
1585 | } | 1590 | } |
1586 | 1591 | ||
1587 | if ((n_ret_value = get_parents(tb, h)) != CARRY_ON) | 1592 | if ((ret = get_parents(tb, h)) != CARRY_ON) |
1588 | return n_ret_value; | 1593 | return ret; |
1589 | 1594 | ||
1590 | /* get free space of neighbors */ | 1595 | /* get free space of neighbors */ |
1591 | rfree = get_rfree(tb, h); | 1596 | rfree = get_rfree(tb, h); |
@@ -1727,7 +1732,7 @@ static int dc_check_balance_internal(struct tree_balance *tb, int h) | |||
1727 | * h current level of the node; | 1732 | * h current level of the node; |
1728 | * inum item number in S[h]; | 1733 | * inum item number in S[h]; |
1729 | * mode i - insert, p - paste; | 1734 | * mode i - insert, p - paste; |
1730 | * Returns: 1 - schedule occurred; | 1735 | * Returns: 1 - schedule occurred; |
1731 | * 0 - balancing for higher levels needed; | 1736 | * 0 - balancing for higher levels needed; |
1732 | * -1 - no balancing for higher levels needed; | 1737 | * -1 - no balancing for higher levels needed; |
1733 | * -2 - no disk space. | 1738 | * -2 - no disk space. |
@@ -1742,7 +1747,7 @@ static int dc_check_balance_leaf(struct tree_balance *tb, int h) | |||
1742 | attempted change in node space used level is levbytes bytes. */ | 1747 | attempted change in node space used level is levbytes bytes. */ |
1743 | int levbytes; | 1748 | int levbytes; |
1744 | /* the maximal item size */ | 1749 | /* the maximal item size */ |
1745 | int maxsize, n_ret_value; | 1750 | int maxsize, ret; |
1746 | /* S0 is the node whose balance is currently being checked, | 1751 | /* S0 is the node whose balance is currently being checked, |
1747 | and F0 is its father. */ | 1752 | and F0 is its father. */ |
1748 | struct buffer_head *S0, *F0; | 1753 | struct buffer_head *S0, *F0; |
@@ -1764,8 +1769,8 @@ static int dc_check_balance_leaf(struct tree_balance *tb, int h) | |||
1764 | return NO_BALANCING_NEEDED; | 1769 | return NO_BALANCING_NEEDED; |
1765 | } | 1770 | } |
1766 | 1771 | ||
1767 | if ((n_ret_value = get_parents(tb, h)) != CARRY_ON) | 1772 | if ((ret = get_parents(tb, h)) != CARRY_ON) |
1768 | return n_ret_value; | 1773 | return ret; |
1769 | 1774 | ||
1770 | /* get free space of neighbors */ | 1775 | /* get free space of neighbors */ |
1771 | rfree = get_rfree(tb, h); | 1776 | rfree = get_rfree(tb, h); |
@@ -1821,7 +1826,7 @@ static int dc_check_balance_leaf(struct tree_balance *tb, int h) | |||
1821 | * h current level of the node; | 1826 | * h current level of the node; |
1822 | * inum item number in S[h]; | 1827 | * inum item number in S[h]; |
1823 | * mode d - delete, c - cut. | 1828 | * mode d - delete, c - cut. |
1824 | * Returns: 1 - schedule occurred; | 1829 | * Returns: 1 - schedule occurred; |
1825 | * 0 - balancing for higher levels needed; | 1830 | * 0 - balancing for higher levels needed; |
1826 | * -1 - no balancing for higher levels needed; | 1831 | * -1 - no balancing for higher levels needed; |
1827 | * -2 - no disk space. | 1832 | * -2 - no disk space. |
@@ -1850,7 +1855,7 @@ static int dc_check_balance(struct tree_balance *tb, int h) | |||
1850 | * h current level of the node; | 1855 | * h current level of the node; |
1851 | * inum item number in S[h]; | 1856 | * inum item number in S[h]; |
1852 | * mode i - insert, p - paste, d - delete, c - cut. | 1857 | * mode i - insert, p - paste, d - delete, c - cut. |
1853 | * Returns: 1 - schedule occurred; | 1858 | * Returns: 1 - schedule occurred; |
1854 | * 0 - balancing for higher levels needed; | 1859 | * 0 - balancing for higher levels needed; |
1855 | * -1 - no balancing for higher levels needed; | 1860 | * -1 - no balancing for higher levels needed; |
1856 | * -2 - no disk space. | 1861 | * -2 - no disk space. |
@@ -1884,137 +1889,138 @@ static int check_balance(int mode, | |||
1884 | } | 1889 | } |
1885 | 1890 | ||
1886 | /* Check whether parent at the path is the really parent of the current node.*/ | 1891 | /* Check whether parent at the path is the really parent of the current node.*/ |
1887 | static int get_direct_parent(struct tree_balance *p_s_tb, int n_h) | 1892 | static int get_direct_parent(struct tree_balance *tb, int h) |
1888 | { | 1893 | { |
1889 | struct buffer_head *p_s_bh; | 1894 | struct buffer_head *bh; |
1890 | struct treepath *p_s_path = p_s_tb->tb_path; | 1895 | struct treepath *path = tb->tb_path; |
1891 | int n_position, | 1896 | int position, |
1892 | n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h); | 1897 | path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h); |
1893 | 1898 | ||
1894 | /* We are in the root or in the new root. */ | 1899 | /* We are in the root or in the new root. */ |
1895 | if (n_path_offset <= FIRST_PATH_ELEMENT_OFFSET) { | 1900 | if (path_offset <= FIRST_PATH_ELEMENT_OFFSET) { |
1896 | 1901 | ||
1897 | RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET - 1, | 1902 | RFALSE(path_offset < FIRST_PATH_ELEMENT_OFFSET - 1, |
1898 | "PAP-8260: invalid offset in the path"); | 1903 | "PAP-8260: invalid offset in the path"); |
1899 | 1904 | ||
1900 | if (PATH_OFFSET_PBUFFER(p_s_path, FIRST_PATH_ELEMENT_OFFSET)-> | 1905 | if (PATH_OFFSET_PBUFFER(path, FIRST_PATH_ELEMENT_OFFSET)-> |
1901 | b_blocknr == SB_ROOT_BLOCK(p_s_tb->tb_sb)) { | 1906 | b_blocknr == SB_ROOT_BLOCK(tb->tb_sb)) { |
1902 | /* Root is not changed. */ | 1907 | /* Root is not changed. */ |
1903 | PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1) = NULL; | 1908 | PATH_OFFSET_PBUFFER(path, path_offset - 1) = NULL; |
1904 | PATH_OFFSET_POSITION(p_s_path, n_path_offset - 1) = 0; | 1909 | PATH_OFFSET_POSITION(path, path_offset - 1) = 0; |
1905 | return CARRY_ON; | 1910 | return CARRY_ON; |
1906 | } | 1911 | } |
1907 | return REPEAT_SEARCH; /* Root is changed and we must recalculate the path. */ | 1912 | return REPEAT_SEARCH; /* Root is changed and we must recalculate the path. */ |
1908 | } | 1913 | } |
1909 | 1914 | ||
1910 | if (!B_IS_IN_TREE | 1915 | if (!B_IS_IN_TREE |
1911 | (p_s_bh = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1))) | 1916 | (bh = PATH_OFFSET_PBUFFER(path, path_offset - 1))) |
1912 | return REPEAT_SEARCH; /* Parent in the path is not in the tree. */ | 1917 | return REPEAT_SEARCH; /* Parent in the path is not in the tree. */ |
1913 | 1918 | ||
1914 | if ((n_position = | 1919 | if ((position = |
1915 | PATH_OFFSET_POSITION(p_s_path, | 1920 | PATH_OFFSET_POSITION(path, |
1916 | n_path_offset - 1)) > B_NR_ITEMS(p_s_bh)) | 1921 | path_offset - 1)) > B_NR_ITEMS(bh)) |
1917 | return REPEAT_SEARCH; | 1922 | return REPEAT_SEARCH; |
1918 | 1923 | ||
1919 | if (B_N_CHILD_NUM(p_s_bh, n_position) != | 1924 | if (B_N_CHILD_NUM(bh, position) != |
1920 | PATH_OFFSET_PBUFFER(p_s_path, n_path_offset)->b_blocknr) | 1925 | PATH_OFFSET_PBUFFER(path, path_offset)->b_blocknr) |
1921 | /* Parent in the path is not parent of the current node in the tree. */ | 1926 | /* Parent in the path is not parent of the current node in the tree. */ |
1922 | return REPEAT_SEARCH; | 1927 | return REPEAT_SEARCH; |
1923 | 1928 | ||
1924 | if (buffer_locked(p_s_bh)) { | 1929 | if (buffer_locked(bh)) { |
1925 | __wait_on_buffer(p_s_bh); | 1930 | __wait_on_buffer(bh); |
1926 | if (FILESYSTEM_CHANGED_TB(p_s_tb)) | 1931 | if (FILESYSTEM_CHANGED_TB(tb)) |
1927 | return REPEAT_SEARCH; | 1932 | return REPEAT_SEARCH; |
1928 | } | 1933 | } |
1929 | 1934 | ||
1930 | return CARRY_ON; /* Parent in the path is unlocked and really parent of the current node. */ | 1935 | return CARRY_ON; /* Parent in the path is unlocked and really parent of the current node. */ |
1931 | } | 1936 | } |
1932 | 1937 | ||
1933 | /* Using lnum[n_h] and rnum[n_h] we should determine what neighbors | 1938 | /* Using lnum[h] and rnum[h] we should determine what neighbors |
1934 | * of S[n_h] we | 1939 | * of S[h] we |
1935 | * need in order to balance S[n_h], and get them if necessary. | 1940 | * need in order to balance S[h], and get them if necessary. |
1936 | * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked; | 1941 | * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked; |
1937 | * CARRY_ON - schedule didn't occur while the function worked; | 1942 | * CARRY_ON - schedule didn't occur while the function worked; |
1938 | */ | 1943 | */ |
1939 | static int get_neighbors(struct tree_balance *p_s_tb, int n_h) | 1944 | static int get_neighbors(struct tree_balance *tb, int h) |
1940 | { | 1945 | { |
1941 | int n_child_position, | 1946 | int child_position, |
1942 | n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h + 1); | 1947 | path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h + 1); |
1943 | unsigned long n_son_number; | 1948 | unsigned long son_number; |
1944 | struct super_block *p_s_sb = p_s_tb->tb_sb; | 1949 | struct super_block *sb = tb->tb_sb; |
1945 | struct buffer_head *p_s_bh; | 1950 | struct buffer_head *bh; |
1946 | 1951 | ||
1947 | PROC_INFO_INC(p_s_sb, get_neighbors[n_h]); | 1952 | PROC_INFO_INC(sb, get_neighbors[h]); |
1948 | 1953 | ||
1949 | if (p_s_tb->lnum[n_h]) { | 1954 | if (tb->lnum[h]) { |
1950 | /* We need left neighbor to balance S[n_h]. */ | 1955 | /* We need left neighbor to balance S[h]. */ |
1951 | PROC_INFO_INC(p_s_sb, need_l_neighbor[n_h]); | 1956 | PROC_INFO_INC(sb, need_l_neighbor[h]); |
1952 | p_s_bh = PATH_OFFSET_PBUFFER(p_s_tb->tb_path, n_path_offset); | 1957 | bh = PATH_OFFSET_PBUFFER(tb->tb_path, path_offset); |
1953 | 1958 | ||
1954 | RFALSE(p_s_bh == p_s_tb->FL[n_h] && | 1959 | RFALSE(bh == tb->FL[h] && |
1955 | !PATH_OFFSET_POSITION(p_s_tb->tb_path, n_path_offset), | 1960 | !PATH_OFFSET_POSITION(tb->tb_path, path_offset), |
1956 | "PAP-8270: invalid position in the parent"); | 1961 | "PAP-8270: invalid position in the parent"); |
1957 | 1962 | ||
1958 | n_child_position = | 1963 | child_position = |
1959 | (p_s_bh == | 1964 | (bh == |
1960 | p_s_tb->FL[n_h]) ? p_s_tb->lkey[n_h] : B_NR_ITEMS(p_s_tb-> | 1965 | tb->FL[h]) ? tb->lkey[h] : B_NR_ITEMS(tb-> |
1961 | FL[n_h]); | 1966 | FL[h]); |
1962 | n_son_number = B_N_CHILD_NUM(p_s_tb->FL[n_h], n_child_position); | 1967 | son_number = B_N_CHILD_NUM(tb->FL[h], child_position); |
1963 | p_s_bh = sb_bread(p_s_sb, n_son_number); | 1968 | bh = sb_bread(sb, son_number); |
1964 | if (!p_s_bh) | 1969 | if (!bh) |
1965 | return IO_ERROR; | 1970 | return IO_ERROR; |
1966 | if (FILESYSTEM_CHANGED_TB(p_s_tb)) { | 1971 | if (FILESYSTEM_CHANGED_TB(tb)) { |
1967 | decrement_bcount(p_s_bh); | 1972 | brelse(bh); |
1968 | PROC_INFO_INC(p_s_sb, get_neighbors_restart[n_h]); | 1973 | PROC_INFO_INC(sb, get_neighbors_restart[h]); |
1969 | return REPEAT_SEARCH; | 1974 | return REPEAT_SEARCH; |
1970 | } | 1975 | } |
1971 | 1976 | ||
1972 | RFALSE(!B_IS_IN_TREE(p_s_tb->FL[n_h]) || | 1977 | RFALSE(!B_IS_IN_TREE(tb->FL[h]) || |
1973 | n_child_position > B_NR_ITEMS(p_s_tb->FL[n_h]) || | 1978 | child_position > B_NR_ITEMS(tb->FL[h]) || |
1974 | B_N_CHILD_NUM(p_s_tb->FL[n_h], n_child_position) != | 1979 | B_N_CHILD_NUM(tb->FL[h], child_position) != |
1975 | p_s_bh->b_blocknr, "PAP-8275: invalid parent"); | 1980 | bh->b_blocknr, "PAP-8275: invalid parent"); |
1976 | RFALSE(!B_IS_IN_TREE(p_s_bh), "PAP-8280: invalid child"); | 1981 | RFALSE(!B_IS_IN_TREE(bh), "PAP-8280: invalid child"); |
1977 | RFALSE(!n_h && | 1982 | RFALSE(!h && |
1978 | B_FREE_SPACE(p_s_bh) != | 1983 | B_FREE_SPACE(bh) != |
1979 | MAX_CHILD_SIZE(p_s_bh) - | 1984 | MAX_CHILD_SIZE(bh) - |
1980 | dc_size(B_N_CHILD(p_s_tb->FL[0], n_child_position)), | 1985 | dc_size(B_N_CHILD(tb->FL[0], child_position)), |
1981 | "PAP-8290: invalid child size of left neighbor"); | 1986 | "PAP-8290: invalid child size of left neighbor"); |
1982 | 1987 | ||
1983 | decrement_bcount(p_s_tb->L[n_h]); | 1988 | brelse(tb->L[h]); |
1984 | p_s_tb->L[n_h] = p_s_bh; | 1989 | tb->L[h] = bh; |
1985 | } | 1990 | } |
1986 | 1991 | ||
1987 | if (p_s_tb->rnum[n_h]) { /* We need right neighbor to balance S[n_path_offset]. */ | 1992 | /* We need right neighbor to balance S[path_offset]. */ |
1988 | PROC_INFO_INC(p_s_sb, need_r_neighbor[n_h]); | 1993 | if (tb->rnum[h]) { /* We need right neighbor to balance S[path_offset]. */ |
1989 | p_s_bh = PATH_OFFSET_PBUFFER(p_s_tb->tb_path, n_path_offset); | 1994 | PROC_INFO_INC(sb, need_r_neighbor[h]); |
1995 | bh = PATH_OFFSET_PBUFFER(tb->tb_path, path_offset); | ||
1990 | 1996 | ||
1991 | RFALSE(p_s_bh == p_s_tb->FR[n_h] && | 1997 | RFALSE(bh == tb->FR[h] && |
1992 | PATH_OFFSET_POSITION(p_s_tb->tb_path, | 1998 | PATH_OFFSET_POSITION(tb->tb_path, |
1993 | n_path_offset) >= | 1999 | path_offset) >= |
1994 | B_NR_ITEMS(p_s_bh), | 2000 | B_NR_ITEMS(bh), |
1995 | "PAP-8295: invalid position in the parent"); | 2001 | "PAP-8295: invalid position in the parent"); |
1996 | 2002 | ||
1997 | n_child_position = | 2003 | child_position = |
1998 | (p_s_bh == p_s_tb->FR[n_h]) ? p_s_tb->rkey[n_h] + 1 : 0; | 2004 | (bh == tb->FR[h]) ? tb->rkey[h] + 1 : 0; |
1999 | n_son_number = B_N_CHILD_NUM(p_s_tb->FR[n_h], n_child_position); | 2005 | son_number = B_N_CHILD_NUM(tb->FR[h], child_position); |
2000 | p_s_bh = sb_bread(p_s_sb, n_son_number); | 2006 | bh = sb_bread(sb, son_number); |
2001 | if (!p_s_bh) | 2007 | if (!bh) |
2002 | return IO_ERROR; | 2008 | return IO_ERROR; |
2003 | if (FILESYSTEM_CHANGED_TB(p_s_tb)) { | 2009 | if (FILESYSTEM_CHANGED_TB(tb)) { |
2004 | decrement_bcount(p_s_bh); | 2010 | brelse(bh); |
2005 | PROC_INFO_INC(p_s_sb, get_neighbors_restart[n_h]); | 2011 | PROC_INFO_INC(sb, get_neighbors_restart[h]); |
2006 | return REPEAT_SEARCH; | 2012 | return REPEAT_SEARCH; |
2007 | } | 2013 | } |
2008 | decrement_bcount(p_s_tb->R[n_h]); | 2014 | brelse(tb->R[h]); |
2009 | p_s_tb->R[n_h] = p_s_bh; | 2015 | tb->R[h] = bh; |
2010 | 2016 | ||
2011 | RFALSE(!n_h | 2017 | RFALSE(!h |
2012 | && B_FREE_SPACE(p_s_bh) != | 2018 | && B_FREE_SPACE(bh) != |
2013 | MAX_CHILD_SIZE(p_s_bh) - | 2019 | MAX_CHILD_SIZE(bh) - |
2014 | dc_size(B_N_CHILD(p_s_tb->FR[0], n_child_position)), | 2020 | dc_size(B_N_CHILD(tb->FR[0], child_position)), |
2015 | "PAP-8300: invalid child size of right neighbor (%d != %d - %d)", | 2021 | "PAP-8300: invalid child size of right neighbor (%d != %d - %d)", |
2016 | B_FREE_SPACE(p_s_bh), MAX_CHILD_SIZE(p_s_bh), | 2022 | B_FREE_SPACE(bh), MAX_CHILD_SIZE(bh), |
2017 | dc_size(B_N_CHILD(p_s_tb->FR[0], n_child_position))); | 2023 | dc_size(B_N_CHILD(tb->FR[0], child_position))); |
2018 | 2024 | ||
2019 | } | 2025 | } |
2020 | return CARRY_ON; | 2026 | return CARRY_ON; |
@@ -2088,52 +2094,46 @@ static int get_mem_for_virtual_node(struct tree_balance *tb) | |||
2088 | } | 2094 | } |
2089 | 2095 | ||
2090 | #ifdef CONFIG_REISERFS_CHECK | 2096 | #ifdef CONFIG_REISERFS_CHECK |
2091 | static void tb_buffer_sanity_check(struct super_block *p_s_sb, | 2097 | static void tb_buffer_sanity_check(struct super_block *sb, |
2092 | struct buffer_head *p_s_bh, | 2098 | struct buffer_head *bh, |
2093 | const char *descr, int level) | 2099 | const char *descr, int level) |
2094 | { | 2100 | { |
2095 | if (p_s_bh) { | 2101 | if (bh) { |
2096 | if (atomic_read(&(p_s_bh->b_count)) <= 0) { | 2102 | if (atomic_read(&(bh->b_count)) <= 0) |
2097 | 2103 | ||
2098 | reiserfs_panic(p_s_sb, | 2104 | reiserfs_panic(sb, "jmacd-1", "negative or zero " |
2099 | "jmacd-1: tb_buffer_sanity_check(): negative or zero reference counter for buffer %s[%d] (%b)\n", | 2105 | "reference counter for buffer %s[%d] " |
2100 | descr, level, p_s_bh); | 2106 | "(%b)", descr, level, bh); |
2101 | } | 2107 | |
2102 | 2108 | if (!buffer_uptodate(bh)) | |
2103 | if (!buffer_uptodate(p_s_bh)) { | 2109 | reiserfs_panic(sb, "jmacd-2", "buffer is not up " |
2104 | reiserfs_panic(p_s_sb, | 2110 | "to date %s[%d] (%b)", |
2105 | "jmacd-2: tb_buffer_sanity_check(): buffer is not up to date %s[%d] (%b)\n", | 2111 | descr, level, bh); |
2106 | descr, level, p_s_bh); | 2112 | |
2107 | } | 2113 | if (!B_IS_IN_TREE(bh)) |
2108 | 2114 | reiserfs_panic(sb, "jmacd-3", "buffer is not " | |
2109 | if (!B_IS_IN_TREE(p_s_bh)) { | 2115 | "in tree %s[%d] (%b)", |
2110 | reiserfs_panic(p_s_sb, | 2116 | descr, level, bh); |
2111 | "jmacd-3: tb_buffer_sanity_check(): buffer is not in tree %s[%d] (%b)\n", | 2117 | |
2112 | descr, level, p_s_bh); | 2118 | if (bh->b_bdev != sb->s_bdev) |
2113 | } | 2119 | reiserfs_panic(sb, "jmacd-4", "buffer has wrong " |
2114 | 2120 | "device %s[%d] (%b)", | |
2115 | if (p_s_bh->b_bdev != p_s_sb->s_bdev) { | 2121 | descr, level, bh); |
2116 | reiserfs_panic(p_s_sb, | 2122 | |
2117 | "jmacd-4: tb_buffer_sanity_check(): buffer has wrong device %s[%d] (%b)\n", | 2123 | if (bh->b_size != sb->s_blocksize) |
2118 | descr, level, p_s_bh); | 2124 | reiserfs_panic(sb, "jmacd-5", "buffer has wrong " |
2119 | } | 2125 | "blocksize %s[%d] (%b)", |
2120 | 2126 | descr, level, bh); | |
2121 | if (p_s_bh->b_size != p_s_sb->s_blocksize) { | 2127 | |
2122 | reiserfs_panic(p_s_sb, | 2128 | if (bh->b_blocknr > SB_BLOCK_COUNT(sb)) |
2123 | "jmacd-5: tb_buffer_sanity_check(): buffer has wrong blocksize %s[%d] (%b)\n", | 2129 | reiserfs_panic(sb, "jmacd-6", "buffer block " |
2124 | descr, level, p_s_bh); | 2130 | "number too high %s[%d] (%b)", |
2125 | } | 2131 | descr, level, bh); |
2126 | |||
2127 | if (p_s_bh->b_blocknr > SB_BLOCK_COUNT(p_s_sb)) { | ||
2128 | reiserfs_panic(p_s_sb, | ||
2129 | "jmacd-6: tb_buffer_sanity_check(): buffer block number too high %s[%d] (%b)\n", | ||
2130 | descr, level, p_s_bh); | ||
2131 | } | ||
2132 | } | 2132 | } |
2133 | } | 2133 | } |
2134 | #else | 2134 | #else |
2135 | static void tb_buffer_sanity_check(struct super_block *p_s_sb, | 2135 | static void tb_buffer_sanity_check(struct super_block *sb, |
2136 | struct buffer_head *p_s_bh, | 2136 | struct buffer_head *bh, |
2137 | const char *descr, int level) | 2137 | const char *descr, int level) |
2138 | {; | 2138 | {; |
2139 | } | 2139 | } |
@@ -2144,7 +2144,7 @@ static int clear_all_dirty_bits(struct super_block *s, struct buffer_head *bh) | |||
2144 | return reiserfs_prepare_for_journal(s, bh, 0); | 2144 | return reiserfs_prepare_for_journal(s, bh, 0); |
2145 | } | 2145 | } |
2146 | 2146 | ||
2147 | static int wait_tb_buffers_until_unlocked(struct tree_balance *p_s_tb) | 2147 | static int wait_tb_buffers_until_unlocked(struct tree_balance *tb) |
2148 | { | 2148 | { |
2149 | struct buffer_head *locked; | 2149 | struct buffer_head *locked; |
2150 | #ifdef CONFIG_REISERFS_CHECK | 2150 | #ifdef CONFIG_REISERFS_CHECK |
@@ -2156,95 +2156,94 @@ static int wait_tb_buffers_until_unlocked(struct tree_balance *p_s_tb) | |||
2156 | 2156 | ||
2157 | locked = NULL; | 2157 | locked = NULL; |
2158 | 2158 | ||
2159 | for (i = p_s_tb->tb_path->path_length; | 2159 | for (i = tb->tb_path->path_length; |
2160 | !locked && i > ILLEGAL_PATH_ELEMENT_OFFSET; i--) { | 2160 | !locked && i > ILLEGAL_PATH_ELEMENT_OFFSET; i--) { |
2161 | if (PATH_OFFSET_PBUFFER(p_s_tb->tb_path, i)) { | 2161 | if (PATH_OFFSET_PBUFFER(tb->tb_path, i)) { |
2162 | /* if I understand correctly, we can only be sure the last buffer | 2162 | /* if I understand correctly, we can only be sure the last buffer |
2163 | ** in the path is in the tree --clm | 2163 | ** in the path is in the tree --clm |
2164 | */ | 2164 | */ |
2165 | #ifdef CONFIG_REISERFS_CHECK | 2165 | #ifdef CONFIG_REISERFS_CHECK |
2166 | if (PATH_PLAST_BUFFER(p_s_tb->tb_path) == | 2166 | if (PATH_PLAST_BUFFER(tb->tb_path) == |
2167 | PATH_OFFSET_PBUFFER(p_s_tb->tb_path, i)) { | 2167 | PATH_OFFSET_PBUFFER(tb->tb_path, i)) |
2168 | tb_buffer_sanity_check(p_s_tb->tb_sb, | 2168 | tb_buffer_sanity_check(tb->tb_sb, |
2169 | PATH_OFFSET_PBUFFER | 2169 | PATH_OFFSET_PBUFFER |
2170 | (p_s_tb->tb_path, | 2170 | (tb->tb_path, |
2171 | i), "S", | 2171 | i), "S", |
2172 | p_s_tb->tb_path-> | 2172 | tb->tb_path-> |
2173 | path_length - i); | 2173 | path_length - i); |
2174 | } | ||
2175 | #endif | 2174 | #endif |
2176 | if (!clear_all_dirty_bits(p_s_tb->tb_sb, | 2175 | if (!clear_all_dirty_bits(tb->tb_sb, |
2177 | PATH_OFFSET_PBUFFER | 2176 | PATH_OFFSET_PBUFFER |
2178 | (p_s_tb->tb_path, | 2177 | (tb->tb_path, |
2179 | i))) { | 2178 | i))) { |
2180 | locked = | 2179 | locked = |
2181 | PATH_OFFSET_PBUFFER(p_s_tb->tb_path, | 2180 | PATH_OFFSET_PBUFFER(tb->tb_path, |
2182 | i); | 2181 | i); |
2183 | } | 2182 | } |
2184 | } | 2183 | } |
2185 | } | 2184 | } |
2186 | 2185 | ||
2187 | for (i = 0; !locked && i < MAX_HEIGHT && p_s_tb->insert_size[i]; | 2186 | for (i = 0; !locked && i < MAX_HEIGHT && tb->insert_size[i]; |
2188 | i++) { | 2187 | i++) { |
2189 | 2188 | ||
2190 | if (p_s_tb->lnum[i]) { | 2189 | if (tb->lnum[i]) { |
2191 | 2190 | ||
2192 | if (p_s_tb->L[i]) { | 2191 | if (tb->L[i]) { |
2193 | tb_buffer_sanity_check(p_s_tb->tb_sb, | 2192 | tb_buffer_sanity_check(tb->tb_sb, |
2194 | p_s_tb->L[i], | 2193 | tb->L[i], |
2195 | "L", i); | 2194 | "L", i); |
2196 | if (!clear_all_dirty_bits | 2195 | if (!clear_all_dirty_bits |
2197 | (p_s_tb->tb_sb, p_s_tb->L[i])) | 2196 | (tb->tb_sb, tb->L[i])) |
2198 | locked = p_s_tb->L[i]; | 2197 | locked = tb->L[i]; |
2199 | } | 2198 | } |
2200 | 2199 | ||
2201 | if (!locked && p_s_tb->FL[i]) { | 2200 | if (!locked && tb->FL[i]) { |
2202 | tb_buffer_sanity_check(p_s_tb->tb_sb, | 2201 | tb_buffer_sanity_check(tb->tb_sb, |
2203 | p_s_tb->FL[i], | 2202 | tb->FL[i], |
2204 | "FL", i); | 2203 | "FL", i); |
2205 | if (!clear_all_dirty_bits | 2204 | if (!clear_all_dirty_bits |
2206 | (p_s_tb->tb_sb, p_s_tb->FL[i])) | 2205 | (tb->tb_sb, tb->FL[i])) |
2207 | locked = p_s_tb->FL[i]; | 2206 | locked = tb->FL[i]; |
2208 | } | 2207 | } |
2209 | 2208 | ||
2210 | if (!locked && p_s_tb->CFL[i]) { | 2209 | if (!locked && tb->CFL[i]) { |
2211 | tb_buffer_sanity_check(p_s_tb->tb_sb, | 2210 | tb_buffer_sanity_check(tb->tb_sb, |
2212 | p_s_tb->CFL[i], | 2211 | tb->CFL[i], |
2213 | "CFL", i); | 2212 | "CFL", i); |
2214 | if (!clear_all_dirty_bits | 2213 | if (!clear_all_dirty_bits |
2215 | (p_s_tb->tb_sb, p_s_tb->CFL[i])) | 2214 | (tb->tb_sb, tb->CFL[i])) |
2216 | locked = p_s_tb->CFL[i]; | 2215 | locked = tb->CFL[i]; |
2217 | } | 2216 | } |
2218 | 2217 | ||
2219 | } | 2218 | } |
2220 | 2219 | ||
2221 | if (!locked && (p_s_tb->rnum[i])) { | 2220 | if (!locked && (tb->rnum[i])) { |
2222 | 2221 | ||
2223 | if (p_s_tb->R[i]) { | 2222 | if (tb->R[i]) { |
2224 | tb_buffer_sanity_check(p_s_tb->tb_sb, | 2223 | tb_buffer_sanity_check(tb->tb_sb, |
2225 | p_s_tb->R[i], | 2224 | tb->R[i], |
2226 | "R", i); | 2225 | "R", i); |
2227 | if (!clear_all_dirty_bits | 2226 | if (!clear_all_dirty_bits |
2228 | (p_s_tb->tb_sb, p_s_tb->R[i])) | 2227 | (tb->tb_sb, tb->R[i])) |
2229 | locked = p_s_tb->R[i]; | 2228 | locked = tb->R[i]; |
2230 | } | 2229 | } |
2231 | 2230 | ||
2232 | if (!locked && p_s_tb->FR[i]) { | 2231 | if (!locked && tb->FR[i]) { |
2233 | tb_buffer_sanity_check(p_s_tb->tb_sb, | 2232 | tb_buffer_sanity_check(tb->tb_sb, |
2234 | p_s_tb->FR[i], | 2233 | tb->FR[i], |
2235 | "FR", i); | 2234 | "FR", i); |
2236 | if (!clear_all_dirty_bits | 2235 | if (!clear_all_dirty_bits |
2237 | (p_s_tb->tb_sb, p_s_tb->FR[i])) | 2236 | (tb->tb_sb, tb->FR[i])) |
2238 | locked = p_s_tb->FR[i]; | 2237 | locked = tb->FR[i]; |
2239 | } | 2238 | } |
2240 | 2239 | ||
2241 | if (!locked && p_s_tb->CFR[i]) { | 2240 | if (!locked && tb->CFR[i]) { |
2242 | tb_buffer_sanity_check(p_s_tb->tb_sb, | 2241 | tb_buffer_sanity_check(tb->tb_sb, |
2243 | p_s_tb->CFR[i], | 2242 | tb->CFR[i], |
2244 | "CFR", i); | 2243 | "CFR", i); |
2245 | if (!clear_all_dirty_bits | 2244 | if (!clear_all_dirty_bits |
2246 | (p_s_tb->tb_sb, p_s_tb->CFR[i])) | 2245 | (tb->tb_sb, tb->CFR[i])) |
2247 | locked = p_s_tb->CFR[i]; | 2246 | locked = tb->CFR[i]; |
2248 | } | 2247 | } |
2249 | } | 2248 | } |
2250 | } | 2249 | } |
@@ -2257,10 +2256,10 @@ static int wait_tb_buffers_until_unlocked(struct tree_balance *p_s_tb) | |||
2257 | ** --clm | 2256 | ** --clm |
2258 | */ | 2257 | */ |
2259 | for (i = 0; !locked && i < MAX_FEB_SIZE; i++) { | 2258 | for (i = 0; !locked && i < MAX_FEB_SIZE; i++) { |
2260 | if (p_s_tb->FEB[i]) { | 2259 | if (tb->FEB[i]) { |
2261 | if (!clear_all_dirty_bits | 2260 | if (!clear_all_dirty_bits |
2262 | (p_s_tb->tb_sb, p_s_tb->FEB[i])) | 2261 | (tb->tb_sb, tb->FEB[i])) |
2263 | locked = p_s_tb->FEB[i]; | 2262 | locked = tb->FEB[i]; |
2264 | } | 2263 | } |
2265 | } | 2264 | } |
2266 | 2265 | ||
@@ -2268,21 +2267,20 @@ static int wait_tb_buffers_until_unlocked(struct tree_balance *p_s_tb) | |||
2268 | #ifdef CONFIG_REISERFS_CHECK | 2267 | #ifdef CONFIG_REISERFS_CHECK |
2269 | repeat_counter++; | 2268 | repeat_counter++; |
2270 | if ((repeat_counter % 10000) == 0) { | 2269 | if ((repeat_counter % 10000) == 0) { |
2271 | reiserfs_warning(p_s_tb->tb_sb, | 2270 | reiserfs_warning(tb->tb_sb, "reiserfs-8200", |
2272 | "wait_tb_buffers_until_released(): too many " | 2271 | "too many iterations waiting " |
2273 | "iterations waiting for buffer to unlock " | 2272 | "for buffer to unlock " |
2274 | "(%b)", locked); | 2273 | "(%b)", locked); |
2275 | 2274 | ||
2276 | /* Don't loop forever. Try to recover from possible error. */ | 2275 | /* Don't loop forever. Try to recover from possible error. */ |
2277 | 2276 | ||
2278 | return (FILESYSTEM_CHANGED_TB(p_s_tb)) ? | 2277 | return (FILESYSTEM_CHANGED_TB(tb)) ? |
2279 | REPEAT_SEARCH : CARRY_ON; | 2278 | REPEAT_SEARCH : CARRY_ON; |
2280 | } | 2279 | } |
2281 | #endif | 2280 | #endif |
2282 | __wait_on_buffer(locked); | 2281 | __wait_on_buffer(locked); |
2283 | if (FILESYSTEM_CHANGED_TB(p_s_tb)) { | 2282 | if (FILESYSTEM_CHANGED_TB(tb)) |
2284 | return REPEAT_SEARCH; | 2283 | return REPEAT_SEARCH; |
2285 | } | ||
2286 | } | 2284 | } |
2287 | 2285 | ||
2288 | } while (locked); | 2286 | } while (locked); |
@@ -2295,15 +2293,15 @@ static int wait_tb_buffers_until_unlocked(struct tree_balance *p_s_tb) | |||
2295 | * analyze what and where should be moved; | 2293 | * analyze what and where should be moved; |
2296 | * get sufficient number of new nodes; | 2294 | * get sufficient number of new nodes; |
2297 | * Balancing will start only after all resources will be collected at a time. | 2295 | * Balancing will start only after all resources will be collected at a time. |
2298 | * | 2296 | * |
2299 | * When ported to SMP kernels, only at the last moment after all needed nodes | 2297 | * When ported to SMP kernels, only at the last moment after all needed nodes |
2300 | * are collected in cache, will the resources be locked using the usual | 2298 | * are collected in cache, will the resources be locked using the usual |
2301 | * textbook ordered lock acquisition algorithms. Note that ensuring that | 2299 | * textbook ordered lock acquisition algorithms. Note that ensuring that |
2302 | * this code neither write locks what it does not need to write lock nor locks out of order | 2300 | * this code neither write locks what it does not need to write lock nor locks out of order |
2303 | * will be a pain in the butt that could have been avoided. Grumble grumble. -Hans | 2301 | * will be a pain in the butt that could have been avoided. Grumble grumble. -Hans |
2304 | * | 2302 | * |
2305 | * fix is meant in the sense of render unchanging | 2303 | * fix is meant in the sense of render unchanging |
2306 | * | 2304 | * |
2307 | * Latency might be improved by first gathering a list of what buffers are needed | 2305 | * Latency might be improved by first gathering a list of what buffers are needed |
2308 | * and then getting as many of them in parallel as possible? -Hans | 2306 | * and then getting as many of them in parallel as possible? -Hans |
2309 | * | 2307 | * |
@@ -2312,159 +2310,160 @@ static int wait_tb_buffers_until_unlocked(struct tree_balance *p_s_tb) | |||
2312 | * tb tree_balance structure; | 2310 | * tb tree_balance structure; |
2313 | * inum item number in S[h]; | 2311 | * inum item number in S[h]; |
2314 | * pos_in_item - comment this if you can | 2312 | * pos_in_item - comment this if you can |
2315 | * ins_ih & ins_sd are used when inserting | 2313 | * ins_ih item head of item being inserted |
2314 | * data inserted item or data to be pasted | ||
2316 | * Returns: 1 - schedule occurred while the function worked; | 2315 | * Returns: 1 - schedule occurred while the function worked; |
2317 | * 0 - schedule didn't occur while the function worked; | 2316 | * 0 - schedule didn't occur while the function worked; |
2318 | * -1 - if no_disk_space | 2317 | * -1 - if no_disk_space |
2319 | */ | 2318 | */ |
2320 | 2319 | ||
2321 | int fix_nodes(int n_op_mode, struct tree_balance *p_s_tb, struct item_head *p_s_ins_ih, // item head of item being inserted | 2320 | int fix_nodes(int op_mode, struct tree_balance *tb, |
2322 | const void *data // inserted item or data to be pasted | 2321 | struct item_head *ins_ih, const void *data) |
2323 | ) | ||
2324 | { | 2322 | { |
2325 | int n_ret_value, n_h, n_item_num = PATH_LAST_POSITION(p_s_tb->tb_path); | 2323 | int ret, h, item_num = PATH_LAST_POSITION(tb->tb_path); |
2326 | int n_pos_in_item; | 2324 | int pos_in_item; |
2327 | 2325 | ||
2328 | /* we set wait_tb_buffers_run when we have to restore any dirty bits cleared | 2326 | /* we set wait_tb_buffers_run when we have to restore any dirty bits cleared |
2329 | ** during wait_tb_buffers_run | 2327 | ** during wait_tb_buffers_run |
2330 | */ | 2328 | */ |
2331 | int wait_tb_buffers_run = 0; | 2329 | int wait_tb_buffers_run = 0; |
2332 | struct buffer_head *p_s_tbS0 = PATH_PLAST_BUFFER(p_s_tb->tb_path); | 2330 | struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); |
2333 | 2331 | ||
2334 | ++REISERFS_SB(p_s_tb->tb_sb)->s_fix_nodes; | 2332 | ++REISERFS_SB(tb->tb_sb)->s_fix_nodes; |
2335 | 2333 | ||
2336 | n_pos_in_item = p_s_tb->tb_path->pos_in_item; | 2334 | pos_in_item = tb->tb_path->pos_in_item; |
2337 | 2335 | ||
2338 | p_s_tb->fs_gen = get_generation(p_s_tb->tb_sb); | 2336 | tb->fs_gen = get_generation(tb->tb_sb); |
2339 | 2337 | ||
2340 | /* we prepare and log the super here so it will already be in the | 2338 | /* we prepare and log the super here so it will already be in the |
2341 | ** transaction when do_balance needs to change it. | 2339 | ** transaction when do_balance needs to change it. |
2342 | ** This way do_balance won't have to schedule when trying to prepare | 2340 | ** This way do_balance won't have to schedule when trying to prepare |
2343 | ** the super for logging | 2341 | ** the super for logging |
2344 | */ | 2342 | */ |
2345 | reiserfs_prepare_for_journal(p_s_tb->tb_sb, | 2343 | reiserfs_prepare_for_journal(tb->tb_sb, |
2346 | SB_BUFFER_WITH_SB(p_s_tb->tb_sb), 1); | 2344 | SB_BUFFER_WITH_SB(tb->tb_sb), 1); |
2347 | journal_mark_dirty(p_s_tb->transaction_handle, p_s_tb->tb_sb, | 2345 | journal_mark_dirty(tb->transaction_handle, tb->tb_sb, |
2348 | SB_BUFFER_WITH_SB(p_s_tb->tb_sb)); | 2346 | SB_BUFFER_WITH_SB(tb->tb_sb)); |
2349 | if (FILESYSTEM_CHANGED_TB(p_s_tb)) | 2347 | if (FILESYSTEM_CHANGED_TB(tb)) |
2350 | return REPEAT_SEARCH; | 2348 | return REPEAT_SEARCH; |
2351 | 2349 | ||
2352 | /* if it possible in indirect_to_direct conversion */ | 2350 | /* if it possible in indirect_to_direct conversion */ |
2353 | if (buffer_locked(p_s_tbS0)) { | 2351 | if (buffer_locked(tbS0)) { |
2354 | __wait_on_buffer(p_s_tbS0); | 2352 | __wait_on_buffer(tbS0); |
2355 | if (FILESYSTEM_CHANGED_TB(p_s_tb)) | 2353 | if (FILESYSTEM_CHANGED_TB(tb)) |
2356 | return REPEAT_SEARCH; | 2354 | return REPEAT_SEARCH; |
2357 | } | 2355 | } |
2358 | #ifdef CONFIG_REISERFS_CHECK | 2356 | #ifdef CONFIG_REISERFS_CHECK |
2359 | if (cur_tb) { | 2357 | if (cur_tb) { |
2360 | print_cur_tb("fix_nodes"); | 2358 | print_cur_tb("fix_nodes"); |
2361 | reiserfs_panic(p_s_tb->tb_sb, | 2359 | reiserfs_panic(tb->tb_sb, "PAP-8305", |
2362 | "PAP-8305: fix_nodes: there is pending do_balance"); | 2360 | "there is pending do_balance"); |
2363 | } | 2361 | } |
2364 | 2362 | ||
2365 | if (!buffer_uptodate(p_s_tbS0) || !B_IS_IN_TREE(p_s_tbS0)) { | 2363 | if (!buffer_uptodate(tbS0) || !B_IS_IN_TREE(tbS0)) |
2366 | reiserfs_panic(p_s_tb->tb_sb, | 2364 | reiserfs_panic(tb->tb_sb, "PAP-8320", "S[0] (%b %z) is " |
2367 | "PAP-8320: fix_nodes: S[0] (%b %z) is not uptodate " | 2365 | "not uptodate at the beginning of fix_nodes " |
2368 | "at the beginning of fix_nodes or not in tree (mode %c)", | 2366 | "or not in tree (mode %c)", |
2369 | p_s_tbS0, p_s_tbS0, n_op_mode); | 2367 | tbS0, tbS0, op_mode); |
2370 | } | ||
2371 | 2368 | ||
2372 | /* Check parameters. */ | 2369 | /* Check parameters. */ |
2373 | switch (n_op_mode) { | 2370 | switch (op_mode) { |
2374 | case M_INSERT: | 2371 | case M_INSERT: |
2375 | if (n_item_num <= 0 || n_item_num > B_NR_ITEMS(p_s_tbS0)) | 2372 | if (item_num <= 0 || item_num > B_NR_ITEMS(tbS0)) |
2376 | reiserfs_panic(p_s_tb->tb_sb, | 2373 | reiserfs_panic(tb->tb_sb, "PAP-8330", "Incorrect " |
2377 | "PAP-8330: fix_nodes: Incorrect item number %d (in S0 - %d) in case of insert", | 2374 | "item number %d (in S0 - %d) in case " |
2378 | n_item_num, B_NR_ITEMS(p_s_tbS0)); | 2375 | "of insert", item_num, |
2376 | B_NR_ITEMS(tbS0)); | ||
2379 | break; | 2377 | break; |
2380 | case M_PASTE: | 2378 | case M_PASTE: |
2381 | case M_DELETE: | 2379 | case M_DELETE: |
2382 | case M_CUT: | 2380 | case M_CUT: |
2383 | if (n_item_num < 0 || n_item_num >= B_NR_ITEMS(p_s_tbS0)) { | 2381 | if (item_num < 0 || item_num >= B_NR_ITEMS(tbS0)) { |
2384 | print_block(p_s_tbS0, 0, -1, -1); | 2382 | print_block(tbS0, 0, -1, -1); |
2385 | reiserfs_panic(p_s_tb->tb_sb, | 2383 | reiserfs_panic(tb->tb_sb, "PAP-8335", "Incorrect " |
2386 | "PAP-8335: fix_nodes: Incorrect item number(%d); mode = %c insert_size = %d\n", | 2384 | "item number(%d); mode = %c " |
2387 | n_item_num, n_op_mode, | 2385 | "insert_size = %d", |
2388 | p_s_tb->insert_size[0]); | 2386 | item_num, op_mode, |
2387 | tb->insert_size[0]); | ||
2389 | } | 2388 | } |
2390 | break; | 2389 | break; |
2391 | default: | 2390 | default: |
2392 | reiserfs_panic(p_s_tb->tb_sb, | 2391 | reiserfs_panic(tb->tb_sb, "PAP-8340", "Incorrect mode " |
2393 | "PAP-8340: fix_nodes: Incorrect mode of operation"); | 2392 | "of operation"); |
2394 | } | 2393 | } |
2395 | #endif | 2394 | #endif |
2396 | 2395 | ||
2397 | if (get_mem_for_virtual_node(p_s_tb) == REPEAT_SEARCH) | 2396 | if (get_mem_for_virtual_node(tb) == REPEAT_SEARCH) |
2398 | // FIXME: maybe -ENOMEM when tb->vn_buf == 0? Now just repeat | 2397 | // FIXME: maybe -ENOMEM when tb->vn_buf == 0? Now just repeat |
2399 | return REPEAT_SEARCH; | 2398 | return REPEAT_SEARCH; |
2400 | 2399 | ||
2401 | /* Starting from the leaf level; for all levels n_h of the tree. */ | 2400 | /* Starting from the leaf level; for all levels h of the tree. */ |
2402 | for (n_h = 0; n_h < MAX_HEIGHT && p_s_tb->insert_size[n_h]; n_h++) { | 2401 | for (h = 0; h < MAX_HEIGHT && tb->insert_size[h]; h++) { |
2403 | if ((n_ret_value = get_direct_parent(p_s_tb, n_h)) != CARRY_ON) { | 2402 | ret = get_direct_parent(tb, h); |
2403 | if (ret != CARRY_ON) | ||
2404 | goto repeat; | 2404 | goto repeat; |
2405 | } | ||
2406 | 2405 | ||
2407 | if ((n_ret_value = | 2406 | ret = check_balance(op_mode, tb, h, item_num, |
2408 | check_balance(n_op_mode, p_s_tb, n_h, n_item_num, | 2407 | pos_in_item, ins_ih, data); |
2409 | n_pos_in_item, p_s_ins_ih, | 2408 | if (ret != CARRY_ON) { |
2410 | data)) != CARRY_ON) { | 2409 | if (ret == NO_BALANCING_NEEDED) { |
2411 | if (n_ret_value == NO_BALANCING_NEEDED) { | ||
2412 | /* No balancing for higher levels needed. */ | 2410 | /* No balancing for higher levels needed. */ |
2413 | if ((n_ret_value = | 2411 | ret = get_neighbors(tb, h); |
2414 | get_neighbors(p_s_tb, n_h)) != CARRY_ON) { | 2412 | if (ret != CARRY_ON) |
2415 | goto repeat; | 2413 | goto repeat; |
2416 | } | 2414 | if (h != MAX_HEIGHT - 1) |
2417 | if (n_h != MAX_HEIGHT - 1) | 2415 | tb->insert_size[h + 1] = 0; |
2418 | p_s_tb->insert_size[n_h + 1] = 0; | ||
2419 | /* ok, analysis and resource gathering are complete */ | 2416 | /* ok, analysis and resource gathering are complete */ |
2420 | break; | 2417 | break; |
2421 | } | 2418 | } |
2422 | goto repeat; | 2419 | goto repeat; |
2423 | } | 2420 | } |
2424 | 2421 | ||
2425 | if ((n_ret_value = get_neighbors(p_s_tb, n_h)) != CARRY_ON) { | 2422 | ret = get_neighbors(tb, h); |
2423 | if (ret != CARRY_ON) | ||
2426 | goto repeat; | 2424 | goto repeat; |
2427 | } | ||
2428 | 2425 | ||
2429 | if ((n_ret_value = get_empty_nodes(p_s_tb, n_h)) != CARRY_ON) { | 2426 | /* No disk space, or schedule occurred and analysis may be |
2430 | goto repeat; /* No disk space, or schedule occurred and | 2427 | * invalid and needs to be redone. */ |
2431 | analysis may be invalid and needs to be redone. */ | 2428 | ret = get_empty_nodes(tb, h); |
2432 | } | 2429 | if (ret != CARRY_ON) |
2430 | goto repeat; | ||
2433 | 2431 | ||
2434 | if (!PATH_H_PBUFFER(p_s_tb->tb_path, n_h)) { | 2432 | if (!PATH_H_PBUFFER(tb->tb_path, h)) { |
2435 | /* We have a positive insert size but no nodes exist on this | 2433 | /* We have a positive insert size but no nodes exist on this |
2436 | level, this means that we are creating a new root. */ | 2434 | level, this means that we are creating a new root. */ |
2437 | 2435 | ||
2438 | RFALSE(p_s_tb->blknum[n_h] != 1, | 2436 | RFALSE(tb->blknum[h] != 1, |
2439 | "PAP-8350: creating new empty root"); | 2437 | "PAP-8350: creating new empty root"); |
2440 | 2438 | ||
2441 | if (n_h < MAX_HEIGHT - 1) | 2439 | if (h < MAX_HEIGHT - 1) |
2442 | p_s_tb->insert_size[n_h + 1] = 0; | 2440 | tb->insert_size[h + 1] = 0; |
2443 | } else if (!PATH_H_PBUFFER(p_s_tb->tb_path, n_h + 1)) { | 2441 | } else if (!PATH_H_PBUFFER(tb->tb_path, h + 1)) { |
2444 | if (p_s_tb->blknum[n_h] > 1) { | 2442 | if (tb->blknum[h] > 1) { |
2445 | /* The tree needs to be grown, so this node S[n_h] | 2443 | /* The tree needs to be grown, so this node S[h] |
2446 | which is the root node is split into two nodes, | 2444 | which is the root node is split into two nodes, |
2447 | and a new node (S[n_h+1]) will be created to | 2445 | and a new node (S[h+1]) will be created to |
2448 | become the root node. */ | 2446 | become the root node. */ |
2449 | 2447 | ||
2450 | RFALSE(n_h == MAX_HEIGHT - 1, | 2448 | RFALSE(h == MAX_HEIGHT - 1, |
2451 | "PAP-8355: attempt to create too high of a tree"); | 2449 | "PAP-8355: attempt to create too high of a tree"); |
2452 | 2450 | ||
2453 | p_s_tb->insert_size[n_h + 1] = | 2451 | tb->insert_size[h + 1] = |
2454 | (DC_SIZE + | 2452 | (DC_SIZE + |
2455 | KEY_SIZE) * (p_s_tb->blknum[n_h] - 1) + | 2453 | KEY_SIZE) * (tb->blknum[h] - 1) + |
2456 | DC_SIZE; | 2454 | DC_SIZE; |
2457 | } else if (n_h < MAX_HEIGHT - 1) | 2455 | } else if (h < MAX_HEIGHT - 1) |
2458 | p_s_tb->insert_size[n_h + 1] = 0; | 2456 | tb->insert_size[h + 1] = 0; |
2459 | } else | 2457 | } else |
2460 | p_s_tb->insert_size[n_h + 1] = | 2458 | tb->insert_size[h + 1] = |
2461 | (DC_SIZE + KEY_SIZE) * (p_s_tb->blknum[n_h] - 1); | 2459 | (DC_SIZE + KEY_SIZE) * (tb->blknum[h] - 1); |
2462 | } | 2460 | } |
2463 | 2461 | ||
2464 | if ((n_ret_value = wait_tb_buffers_until_unlocked(p_s_tb)) == CARRY_ON) { | 2462 | ret = wait_tb_buffers_until_unlocked(tb); |
2465 | if (FILESYSTEM_CHANGED_TB(p_s_tb)) { | 2463 | if (ret == CARRY_ON) { |
2464 | if (FILESYSTEM_CHANGED_TB(tb)) { | ||
2466 | wait_tb_buffers_run = 1; | 2465 | wait_tb_buffers_run = 1; |
2467 | n_ret_value = REPEAT_SEARCH; | 2466 | ret = REPEAT_SEARCH; |
2468 | goto repeat; | 2467 | goto repeat; |
2469 | } else { | 2468 | } else { |
2470 | return CARRY_ON; | 2469 | return CARRY_ON; |
@@ -2485,57 +2484,57 @@ int fix_nodes(int n_op_mode, struct tree_balance *p_s_tb, struct item_head *p_s_ | |||
2485 | 2484 | ||
2486 | /* Release path buffers. */ | 2485 | /* Release path buffers. */ |
2487 | if (wait_tb_buffers_run) { | 2486 | if (wait_tb_buffers_run) { |
2488 | pathrelse_and_restore(p_s_tb->tb_sb, p_s_tb->tb_path); | 2487 | pathrelse_and_restore(tb->tb_sb, tb->tb_path); |
2489 | } else { | 2488 | } else { |
2490 | pathrelse(p_s_tb->tb_path); | 2489 | pathrelse(tb->tb_path); |
2491 | } | 2490 | } |
2492 | /* brelse all resources collected for balancing */ | 2491 | /* brelse all resources collected for balancing */ |
2493 | for (i = 0; i < MAX_HEIGHT; i++) { | 2492 | for (i = 0; i < MAX_HEIGHT; i++) { |
2494 | if (wait_tb_buffers_run) { | 2493 | if (wait_tb_buffers_run) { |
2495 | reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, | 2494 | reiserfs_restore_prepared_buffer(tb->tb_sb, |
2496 | p_s_tb->L[i]); | 2495 | tb->L[i]); |
2497 | reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, | 2496 | reiserfs_restore_prepared_buffer(tb->tb_sb, |
2498 | p_s_tb->R[i]); | 2497 | tb->R[i]); |
2499 | reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, | 2498 | reiserfs_restore_prepared_buffer(tb->tb_sb, |
2500 | p_s_tb->FL[i]); | 2499 | tb->FL[i]); |
2501 | reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, | 2500 | reiserfs_restore_prepared_buffer(tb->tb_sb, |
2502 | p_s_tb->FR[i]); | 2501 | tb->FR[i]); |
2503 | reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, | 2502 | reiserfs_restore_prepared_buffer(tb->tb_sb, |
2504 | p_s_tb-> | 2503 | tb-> |
2505 | CFL[i]); | 2504 | CFL[i]); |
2506 | reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, | 2505 | reiserfs_restore_prepared_buffer(tb->tb_sb, |
2507 | p_s_tb-> | 2506 | tb-> |
2508 | CFR[i]); | 2507 | CFR[i]); |
2509 | } | 2508 | } |
2510 | 2509 | ||
2511 | brelse(p_s_tb->L[i]); | 2510 | brelse(tb->L[i]); |
2512 | p_s_tb->L[i] = NULL; | 2511 | brelse(tb->R[i]); |
2513 | brelse(p_s_tb->R[i]); | 2512 | brelse(tb->FL[i]); |
2514 | p_s_tb->R[i] = NULL; | 2513 | brelse(tb->FR[i]); |
2515 | brelse(p_s_tb->FL[i]); | 2514 | brelse(tb->CFL[i]); |
2516 | p_s_tb->FL[i] = NULL; | 2515 | brelse(tb->CFR[i]); |
2517 | brelse(p_s_tb->FR[i]); | 2516 | |
2518 | p_s_tb->FR[i] = NULL; | 2517 | tb->L[i] = NULL; |
2519 | brelse(p_s_tb->CFL[i]); | 2518 | tb->R[i] = NULL; |
2520 | p_s_tb->CFL[i] = NULL; | 2519 | tb->FL[i] = NULL; |
2521 | brelse(p_s_tb->CFR[i]); | 2520 | tb->FR[i] = NULL; |
2522 | p_s_tb->CFR[i] = NULL; | 2521 | tb->CFL[i] = NULL; |
2522 | tb->CFR[i] = NULL; | ||
2523 | } | 2523 | } |
2524 | 2524 | ||
2525 | if (wait_tb_buffers_run) { | 2525 | if (wait_tb_buffers_run) { |
2526 | for (i = 0; i < MAX_FEB_SIZE; i++) { | 2526 | for (i = 0; i < MAX_FEB_SIZE; i++) { |
2527 | if (p_s_tb->FEB[i]) { | 2527 | if (tb->FEB[i]) |
2528 | reiserfs_restore_prepared_buffer | 2528 | reiserfs_restore_prepared_buffer |
2529 | (p_s_tb->tb_sb, p_s_tb->FEB[i]); | 2529 | (tb->tb_sb, tb->FEB[i]); |
2530 | } | ||
2531 | } | 2530 | } |
2532 | } | 2531 | } |
2533 | return n_ret_value; | 2532 | return ret; |
2534 | } | 2533 | } |
2535 | 2534 | ||
2536 | } | 2535 | } |
2537 | 2536 | ||
2538 | /* Anatoly will probably forgive me renaming p_s_tb to tb. I just | 2537 | /* Anatoly will probably forgive me renaming tb to tb. I just |
2539 | wanted to make lines shorter */ | 2538 | wanted to make lines shorter */ |
2540 | void unfix_nodes(struct tree_balance *tb) | 2539 | void unfix_nodes(struct tree_balance *tb) |
2541 | { | 2540 | { |