aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/reiserfs')
-rw-r--r--fs/reiserfs/file.c6
-rw-r--r--fs/reiserfs/fix_node.c474
-rw-r--r--fs/reiserfs/stree.c370
-rw-r--r--fs/reiserfs/tail_conversion.c30
4 files changed, 438 insertions, 442 deletions
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c
index cde16429ff00..9f436668b7f8 100644
--- a/fs/reiserfs/file.c
+++ b/fs/reiserfs/file.c
@@ -138,11 +138,11 @@ static int reiserfs_sync_file(struct file *filp,
138 struct dentry *dentry, int datasync) 138 struct dentry *dentry, int datasync)
139{ 139{
140 struct inode *inode = dentry->d_inode; 140 struct inode *inode = dentry->d_inode;
141 int n_err; 141 int err;
142 int barrier_done; 142 int barrier_done;
143 143
144 BUG_ON(!S_ISREG(inode->i_mode)); 144 BUG_ON(!S_ISREG(inode->i_mode));
145 n_err = sync_mapping_buffers(inode->i_mapping); 145 err = sync_mapping_buffers(inode->i_mapping);
146 reiserfs_write_lock(inode->i_sb); 146 reiserfs_write_lock(inode->i_sb);
147 barrier_done = reiserfs_commit_for_inode(inode); 147 barrier_done = reiserfs_commit_for_inode(inode);
148 reiserfs_write_unlock(inode->i_sb); 148 reiserfs_write_unlock(inode->i_sb);
@@ -150,7 +150,7 @@ static int reiserfs_sync_file(struct file *filp,
150 blkdev_issue_flush(inode->i_sb->s_bdev, NULL); 150 blkdev_issue_flush(inode->i_sb->s_bdev, NULL);
151 if (barrier_done < 0) 151 if (barrier_done < 0)
152 return barrier_done; 152 return barrier_done;
153 return (n_err < 0) ? -EIO : 0; 153 return (err < 0) ? -EIO : 0;
154} 154}
155 155
156/* taken fs/buffer.c:__block_commit_write */ 156/* taken fs/buffer.c:__block_commit_write */
diff --git a/fs/reiserfs/fix_node.c b/fs/reiserfs/fix_node.c
index d97a55574ba9..5e5a4e6fbaf8 100644
--- a/fs/reiserfs/fix_node.c
+++ b/fs/reiserfs/fix_node.c
@@ -751,24 +751,24 @@ else \
751 751
752static void free_buffers_in_tb(struct tree_balance *tb) 752static void free_buffers_in_tb(struct tree_balance *tb)
753{ 753{
754 int n_counter; 754 int i;
755 755
756 pathrelse(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 brelse(tb->L[n_counter]); 759 brelse(tb->L[i]);
760 brelse(tb->R[n_counter]); 760 brelse(tb->R[i]);
761 brelse(tb->FL[n_counter]); 761 brelse(tb->FL[i]);
762 brelse(tb->FR[n_counter]); 762 brelse(tb->FR[i]);
763 brelse(tb->CFL[n_counter]); 763 brelse(tb->CFL[i]);
764 brelse(tb->CFR[n_counter]); 764 brelse(tb->CFR[i]);
765 765
766 tb->L[n_counter] = NULL; 766 tb->L[i] = NULL;
767 tb->R[n_counter] = NULL; 767 tb->R[i] = NULL;
768 tb->FL[n_counter] = NULL; 768 tb->FL[i] = NULL;
769 tb->FR[n_counter] = NULL; 769 tb->FR[i] = NULL;
770 tb->CFL[n_counter] = NULL; 770 tb->CFL[i] = NULL;
771 tb->CFR[n_counter] = NULL; 771 tb->CFR[i] = NULL;
772 } 772 }
773} 773}
774 774
@@ -778,13 +778,13 @@ static void free_buffers_in_tb(struct tree_balance *tb)
778 * NO_DISK_SPACE - no disk space. 778 * NO_DISK_SPACE - no disk space.
779 */ 779 */
780/* The function is NOT SCHEDULE-SAFE! */ 780/* The function is NOT SCHEDULE-SAFE! */
781static int get_empty_nodes(struct tree_balance *tb, int n_h) 781static int get_empty_nodes(struct tree_balance *tb, int h)
782{ 782{
783 struct buffer_head *new_bh, 783 struct buffer_head *new_bh,
784 *Sh = PATH_H_PBUFFER(tb->tb_path, n_h); 784 *Sh = PATH_H_PBUFFER(tb->tb_path, h);
785 b_blocknr_t *blocknr, a_n_blocknrs[MAX_AMOUNT_NEEDED] = { 0, }; 785 b_blocknr_t *blocknr, blocknrs[MAX_AMOUNT_NEEDED] = { 0, };
786 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 */
787 n_retval = CARRY_ON; 787 retval = CARRY_ON;
788 struct super_block *sb = tb->tb_sb; 788 struct super_block *sb = tb->tb_sb;
789 789
790 /* 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
@@ -793,7 +793,7 @@ static int get_empty_nodes(struct tree_balance *tb, int n_h)
793 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
794 after empty blocks are acquired, and the balancing analysis is 794 after empty blocks are acquired, and the balancing analysis is
795 then restarted, amount_needed is the number needed by this level 795 then restarted, amount_needed is the number needed by this level
796 (n_h) of the balancing analysis. 796 (h) of the balancing analysis.
797 797
798 Note that for systems with many processes writing, it would be 798 Note that for systems with many processes writing, it would be
799 more layout optimal to calculate the total number needed by all 799 more layout optimal to calculate the total number needed by all
@@ -801,31 +801,31 @@ static int get_empty_nodes(struct tree_balance *tb, int n_h)
801 801
802 /* 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
803 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
804 by all of the levels of the tree below n_h. */ 804 by all of the levels of the tree below h. */
805 /* blknum includes S[n_h], so we subtract 1 in this calculation */ 805 /* blknum includes S[h], so we subtract 1 in this calculation */
806 for (n_counter = 0, n_number_of_freeblk = tb->cur_blknum; 806 for (counter = 0, number_of_freeblk = tb->cur_blknum;
807 n_counter < n_h; n_counter++) 807 counter < h; counter++)
808 n_number_of_freeblk -= 808 number_of_freeblk -=
809 (tb->blknum[n_counter]) ? (tb->blknum[n_counter] - 809 (tb->blknum[counter]) ? (tb->blknum[counter] -
810 1) : 0; 810 1) : 0;
811 811
812 /* Allocate missing empty blocks. */ 812 /* Allocate missing empty blocks. */
813 /* if Sh == 0 then we are getting a new root */ 813 /* if Sh == 0 then we are getting a new root */
814 n_amount_needed = (Sh) ? (tb->blknum[n_h] - 1) : 1; 814 amount_needed = (Sh) ? (tb->blknum[h] - 1) : 1;
815 /* 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. */
816 if (n_amount_needed > n_number_of_freeblk) 816 if (amount_needed > number_of_freeblk)
817 n_amount_needed -= n_number_of_freeblk; 817 amount_needed -= number_of_freeblk;
818 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. */
819 return CARRY_ON; 819 return CARRY_ON;
820 820
821 /* 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 */
822 if (reiserfs_new_form_blocknrs(tb, a_n_blocknrs, 822 if (reiserfs_new_form_blocknrs(tb, blocknrs,
823 n_amount_needed) == NO_DISK_SPACE) 823 amount_needed) == NO_DISK_SPACE)
824 return NO_DISK_SPACE; 824 return NO_DISK_SPACE;
825 825
826 /* 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 */
827 for (blocknr = a_n_blocknrs, n_counter = 0; 827 for (blocknr = blocknrs, counter = 0;
828 n_counter < n_amount_needed; blocknr++, n_counter++) { 828 counter < amount_needed; blocknr++, counter++) {
829 829
830 RFALSE(!*blocknr, 830 RFALSE(!*blocknr,
831 "PAP-8135: reiserfs_new_blocknrs failed when got new blocks"); 831 "PAP-8135: reiserfs_new_blocknrs failed when got new blocks");
@@ -845,10 +845,10 @@ static int get_empty_nodes(struct tree_balance *tb, int n_h)
845 tb->FEB[tb->cur_blknum++] = new_bh; 845 tb->FEB[tb->cur_blknum++] = new_bh;
846 } 846 }
847 847
848 if (n_retval == CARRY_ON && FILESYSTEM_CHANGED_TB(tb)) 848 if (retval == CARRY_ON && FILESYSTEM_CHANGED_TB(tb))
849 n_retval = REPEAT_SEARCH; 849 retval = REPEAT_SEARCH;
850 850
851 return n_retval; 851 return retval;
852} 852}
853 853
854/* 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
@@ -896,36 +896,36 @@ static int get_rfree(struct tree_balance *tb, int h)
896} 896}
897 897
898/* Check whether left neighbor is in memory. */ 898/* Check whether left neighbor is in memory. */
899static int is_left_neighbor_in_cache(struct tree_balance *tb, int n_h) 899static int is_left_neighbor_in_cache(struct tree_balance *tb, int h)
900{ 900{
901 struct buffer_head *father, *left; 901 struct buffer_head *father, *left;
902 struct super_block *sb = tb->tb_sb; 902 struct super_block *sb = tb->tb_sb;
903 b_blocknr_t n_left_neighbor_blocknr; 903 b_blocknr_t left_neighbor_blocknr;
904 int n_left_neighbor_position; 904 int left_neighbor_position;
905 905
906 /* Father of the left neighbor does not exist. */ 906 /* Father of the left neighbor does not exist. */
907 if (!tb->FL[n_h]) 907 if (!tb->FL[h])
908 return 0; 908 return 0;
909 909
910 /* Calculate father of the node to be balanced. */ 910 /* Calculate father of the node to be balanced. */
911 father = PATH_H_PBUFFER(tb->tb_path, n_h + 1); 911 father = PATH_H_PBUFFER(tb->tb_path, h + 1);
912 912
913 RFALSE(!father || 913 RFALSE(!father ||
914 !B_IS_IN_TREE(father) || 914 !B_IS_IN_TREE(father) ||
915 !B_IS_IN_TREE(tb->FL[n_h]) || 915 !B_IS_IN_TREE(tb->FL[h]) ||
916 !buffer_uptodate(father) || 916 !buffer_uptodate(father) ||
917 !buffer_uptodate(tb->FL[n_h]), 917 !buffer_uptodate(tb->FL[h]),
918 "vs-8165: F[h] (%b) or FL[h] (%b) is invalid", 918 "vs-8165: F[h] (%b) or FL[h] (%b) is invalid",
919 father, tb->FL[n_h]); 919 father, tb->FL[h]);
920 920
921 /* 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. */
922 n_left_neighbor_position = (father == tb->FL[n_h]) ? 922 left_neighbor_position = (father == tb->FL[h]) ?
923 tb->lkey[n_h] : B_NR_ITEMS(tb->FL[n_h]); 923 tb->lkey[h] : B_NR_ITEMS(tb->FL[h]);
924 /* Get left neighbor block number. */ 924 /* Get left neighbor block number. */
925 n_left_neighbor_blocknr = 925 left_neighbor_blocknr =
926 B_N_CHILD_NUM(tb->FL[n_h], n_left_neighbor_position); 926 B_N_CHILD_NUM(tb->FL[h], left_neighbor_position);
927 /* Look for the left neighbor in the cache. */ 927 /* Look for the left neighbor in the cache. */
928 if ((left = sb_find_get_block(sb, n_left_neighbor_blocknr))) { 928 if ((left = sb_find_get_block(sb, left_neighbor_blocknr))) {
929 929
930 RFALSE(buffer_uptodate(left) && !B_IS_IN_TREE(left), 930 RFALSE(buffer_uptodate(left) && !B_IS_IN_TREE(left),
931 "vs-8170: left neighbor (%b %z) is not in the tree", 931 "vs-8170: left neighbor (%b %z) is not in the tree",
@@ -955,7 +955,7 @@ static void decrement_key(struct cpu_key *key)
955 * CARRY_ON - schedule didn't occur while the function worked; 955 * CARRY_ON - schedule didn't occur while the function worked;
956 */ 956 */
957static int get_far_parent(struct tree_balance *tb, 957static int get_far_parent(struct tree_balance *tb,
958 int n_h, 958 int h,
959 struct buffer_head **pfather, 959 struct buffer_head **pfather,
960 struct buffer_head **pcom_father, char c_lr_par) 960 struct buffer_head **pcom_father, char c_lr_par)
961{ 961{
@@ -963,38 +963,38 @@ static int get_far_parent(struct tree_balance *tb,
963 INITIALIZE_PATH(s_path_to_neighbor_father); 963 INITIALIZE_PATH(s_path_to_neighbor_father);
964 struct treepath *path = tb->tb_path; 964 struct treepath *path = tb->tb_path;
965 struct cpu_key s_lr_father_key; 965 struct cpu_key s_lr_father_key;
966 int n_counter, 966 int counter,
967 n_position = INT_MAX, 967 position = INT_MAX,
968 n_first_last_position = 0, 968 first_last_position = 0,
969 n_path_offset = PATH_H_PATH_OFFSET(path, n_h); 969 path_offset = PATH_H_PATH_OFFSET(path, h);
970 970
971 /* 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
972 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. */
973 973
974 n_counter = n_path_offset; 974 counter = path_offset;
975 975
976 RFALSE(n_counter < FIRST_PATH_ELEMENT_OFFSET, 976 RFALSE(counter < FIRST_PATH_ELEMENT_OFFSET,
977 "PAP-8180: invalid path length"); 977 "PAP-8180: invalid path length");
978 978
979 for (; n_counter > FIRST_PATH_ELEMENT_OFFSET; n_counter--) { 979 for (; counter > FIRST_PATH_ELEMENT_OFFSET; counter--) {
980 /* 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. */
981 if (!B_IS_IN_TREE 981 if (!B_IS_IN_TREE
982 (parent = PATH_OFFSET_PBUFFER(path, n_counter - 1))) 982 (parent = PATH_OFFSET_PBUFFER(path, counter - 1)))
983 return REPEAT_SEARCH; 983 return REPEAT_SEARCH;
984 /* Check whether position in the parent is correct. */ 984 /* Check whether position in the parent is correct. */
985 if ((n_position = 985 if ((position =
986 PATH_OFFSET_POSITION(path, 986 PATH_OFFSET_POSITION(path,
987 n_counter - 1)) > 987 counter - 1)) >
988 B_NR_ITEMS(parent)) 988 B_NR_ITEMS(parent))
989 return REPEAT_SEARCH; 989 return REPEAT_SEARCH;
990 /* Check whether parent at the path really points to the child. */ 990 /* Check whether parent at the path really points to the child. */
991 if (B_N_CHILD_NUM(parent, n_position) != 991 if (B_N_CHILD_NUM(parent, position) !=
992 PATH_OFFSET_PBUFFER(path, n_counter)->b_blocknr) 992 PATH_OFFSET_PBUFFER(path, counter)->b_blocknr)
993 return REPEAT_SEARCH; 993 return REPEAT_SEARCH;
994 /* 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. */
995 if (c_lr_par == RIGHT_PARENTS) 995 if (c_lr_par == RIGHT_PARENTS)
996 n_first_last_position = B_NR_ITEMS(parent); 996 first_last_position = B_NR_ITEMS(parent);
997 if (n_position != n_first_last_position) { 997 if (position != first_last_position) {
998 *pcom_father = parent; 998 *pcom_father = parent;
999 get_bh(*pcom_father); 999 get_bh(*pcom_father);
1000 /*(*pcom_father = parent)->b_count++; */ 1000 /*(*pcom_father = parent)->b_count++; */
@@ -1003,7 +1003,7 @@ static int get_far_parent(struct tree_balance *tb,
1003 } 1003 }
1004 1004
1005 /* 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 */
1006 if (n_counter == FIRST_PATH_ELEMENT_OFFSET) { 1006 if (counter == FIRST_PATH_ELEMENT_OFFSET) {
1007 /* 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. */
1008 if (PATH_OFFSET_PBUFFER 1008 if (PATH_OFFSET_PBUFFER
1009 (tb->tb_path, 1009 (tb->tb_path,
@@ -1036,18 +1036,18 @@ static int get_far_parent(struct tree_balance *tb,
1036 le_key2cpu_key(&s_lr_father_key, 1036 le_key2cpu_key(&s_lr_father_key,
1037 B_N_PDELIM_KEY(*pcom_father, 1037 B_N_PDELIM_KEY(*pcom_father,
1038 (c_lr_par == 1038 (c_lr_par ==
1039 LEFT_PARENTS) ? (tb->lkey[n_h - 1] = 1039 LEFT_PARENTS) ? (tb->lkey[h - 1] =
1040 n_position - 1040 position -
1041 1) : (tb->rkey[n_h - 1041 1) : (tb->rkey[h -
1042 1] = 1042 1] =
1043 n_position))); 1043 position)));
1044 1044
1045 if (c_lr_par == LEFT_PARENTS) 1045 if (c_lr_par == LEFT_PARENTS)
1046 decrement_key(&s_lr_father_key); 1046 decrement_key(&s_lr_father_key);
1047 1047
1048 if (search_by_key 1048 if (search_by_key
1049 (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,
1050 n_h + 1) == IO_ERROR) 1050 h + 1) == IO_ERROR)
1051 // path is released 1051 // path is released
1052 return IO_ERROR; 1052 return IO_ERROR;
1053 1053
@@ -1059,7 +1059,7 @@ static int get_far_parent(struct tree_balance *tb,
1059 1059
1060 *pfather = PATH_PLAST_BUFFER(&s_path_to_neighbor_father); 1060 *pfather = PATH_PLAST_BUFFER(&s_path_to_neighbor_father);
1061 1061
1062 RFALSE(B_LEVEL(*pfather) != n_h + 1, 1062 RFALSE(B_LEVEL(*pfather) != h + 1,
1063 "PAP-8190: (%b %z) level too small", *pfather, *pfather); 1063 "PAP-8190: (%b %z) level too small", *pfather, *pfather);
1064 RFALSE(s_path_to_neighbor_father.path_length < 1064 RFALSE(s_path_to_neighbor_father.path_length <
1065 FIRST_PATH_ELEMENT_OFFSET, "PAP-8192: path length is too small"); 1065 FIRST_PATH_ELEMENT_OFFSET, "PAP-8192: path length is too small");
@@ -1069,92 +1069,92 @@ static int get_far_parent(struct tree_balance *tb,
1069 return CARRY_ON; 1069 return CARRY_ON;
1070} 1070}
1071 1071
1072/* 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
1073 * 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],
1074 * FR[n_path_offset], CFL[n_path_offset], CFR[n_path_offset]. 1074 * FR[path_offset], CFL[path_offset], CFR[path_offset].
1075 * 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].
1076 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked; 1076 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked;
1077 * CARRY_ON - schedule didn't occur while the function worked; 1077 * CARRY_ON - schedule didn't occur while the function worked;
1078 */ 1078 */
1079static int get_parents(struct tree_balance *tb, int n_h) 1079static int get_parents(struct tree_balance *tb, int h)
1080{ 1080{
1081 struct treepath *path = tb->tb_path; 1081 struct treepath *path = tb->tb_path;
1082 int n_position, 1082 int position,
1083 n_ret_value, 1083 ret,
1084 n_path_offset = PATH_H_PATH_OFFSET(tb->tb_path, n_h); 1084 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h);
1085 struct buffer_head *curf, *curcf; 1085 struct buffer_head *curf, *curcf;
1086 1086
1087 /* 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 */
1088 if (n_path_offset <= FIRST_PATH_ELEMENT_OFFSET) { 1088 if (path_offset <= FIRST_PATH_ELEMENT_OFFSET) {
1089 /* The root can not have parents. 1089 /* The root can not have parents.
1090 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. */
1091 brelse(tb->FL[n_h]); 1091 brelse(tb->FL[h]);
1092 brelse(tb->CFL[n_h]); 1092 brelse(tb->CFL[h]);
1093 brelse(tb->FR[n_h]); 1093 brelse(tb->FR[h]);
1094 brelse(tb->CFR[n_h]); 1094 brelse(tb->CFR[h]);
1095 tb->FL[n_h] = NULL; 1095 tb->FL[h] = NULL;
1096 tb->CFL[n_h] = NULL; 1096 tb->CFL[h] = NULL;
1097 tb->FR[n_h] = NULL; 1097 tb->FR[h] = NULL;
1098 tb->CFR[n_h] = NULL; 1098 tb->CFR[h] = NULL;
1099 return CARRY_ON; 1099 return CARRY_ON;
1100 } 1100 }
1101 1101
1102 /* Get parent FL[n_path_offset] of L[n_path_offset]. */ 1102 /* Get parent FL[path_offset] of L[path_offset]. */
1103 n_position = PATH_OFFSET_POSITION(path, n_path_offset - 1); 1103 position = PATH_OFFSET_POSITION(path, path_offset - 1);
1104 if (n_position) { 1104 if (position) {
1105 /* Current node is not the first child of its parent. */ 1105 /* Current node is not the first child of its parent. */
1106 curf = PATH_OFFSET_PBUFFER(path, n_path_offset - 1); 1106 curf = PATH_OFFSET_PBUFFER(path, path_offset - 1);
1107 curcf = PATH_OFFSET_PBUFFER(path, n_path_offset - 1); 1107 curcf = PATH_OFFSET_PBUFFER(path, path_offset - 1);
1108 get_bh(curf); 1108 get_bh(curf);
1109 get_bh(curf); 1109 get_bh(curf);
1110 tb->lkey[n_h] = n_position - 1; 1110 tb->lkey[h] = position - 1;
1111 } else { 1111 } else {
1112 /* 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.
1113 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
1114 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].
1115 Calculate lkey[n_path_offset]. */ 1115 Calculate lkey[path_offset]. */
1116 if ((n_ret_value = get_far_parent(tb, n_h + 1, &curf, 1116 if ((ret = get_far_parent(tb, h + 1, &curf,
1117 &curcf, 1117 &curcf,
1118 LEFT_PARENTS)) != CARRY_ON) 1118 LEFT_PARENTS)) != CARRY_ON)
1119 return n_ret_value; 1119 return ret;
1120 } 1120 }
1121 1121
1122 brelse(tb->FL[n_h]); 1122 brelse(tb->FL[h]);
1123 tb->FL[n_h] = curf; /* New initialization of FL[n_h]. */ 1123 tb->FL[h] = curf; /* New initialization of FL[h]. */
1124 brelse(tb->CFL[n_h]); 1124 brelse(tb->CFL[h]);
1125 tb->CFL[n_h] = curcf; /* New initialization of CFL[n_h]. */ 1125 tb->CFL[h] = curcf; /* New initialization of CFL[h]. */
1126 1126
1127 RFALSE((curf && !B_IS_IN_TREE(curf)) || 1127 RFALSE((curf && !B_IS_IN_TREE(curf)) ||
1128 (curcf && !B_IS_IN_TREE(curcf)), 1128 (curcf && !B_IS_IN_TREE(curcf)),
1129 "PAP-8195: FL (%b) or CFL (%b) is invalid", curf, curcf); 1129 "PAP-8195: FL (%b) or CFL (%b) is invalid", curf, curcf);
1130 1130
1131/* Get parent FR[n_h] of R[n_h]. */ 1131/* Get parent FR[h] of R[h]. */
1132 1132
1133/* 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]. */
1134 if (n_position == B_NR_ITEMS(PATH_H_PBUFFER(path, n_h + 1))) { 1134 if (position == B_NR_ITEMS(PATH_H_PBUFFER(path, h + 1))) {
1135/* 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].
1136 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]
1137 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]. */
1138 if ((n_ret_value = 1138 if ((ret =
1139 get_far_parent(tb, n_h + 1, &curf, &curcf, 1139 get_far_parent(tb, h + 1, &curf, &curcf,
1140 RIGHT_PARENTS)) != CARRY_ON) 1140 RIGHT_PARENTS)) != CARRY_ON)
1141 return n_ret_value; 1141 return ret;
1142 } else { 1142 } else {
1143/* 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]. */
1144 curf = PATH_OFFSET_PBUFFER(path, n_path_offset - 1); 1144 curf = PATH_OFFSET_PBUFFER(path, path_offset - 1);
1145 curcf = PATH_OFFSET_PBUFFER(path, n_path_offset - 1); 1145 curcf = PATH_OFFSET_PBUFFER(path, path_offset - 1);
1146 get_bh(curf); 1146 get_bh(curf);
1147 get_bh(curf); 1147 get_bh(curf);
1148 tb->rkey[n_h] = n_position; 1148 tb->rkey[h] = position;
1149 } 1149 }
1150 1150
1151 brelse(tb->FR[n_h]); 1151 brelse(tb->FR[h]);
1152 /* New initialization of FR[n_path_offset]. */ 1152 /* New initialization of FR[path_offset]. */
1153 tb->FR[n_h] = curf; 1153 tb->FR[h] = curf;
1154 1154
1155 brelse(tb->CFR[n_h]); 1155 brelse(tb->CFR[h]);
1156 /* New initialization of CFR[n_path_offset]. */ 1156 /* New initialization of CFR[path_offset]. */
1157 tb->CFR[n_h] = curcf; 1157 tb->CFR[h] = curcf;
1158 1158
1159 RFALSE((curf && !B_IS_IN_TREE(curf)) || 1159 RFALSE((curf && !B_IS_IN_TREE(curf)) ||
1160 (curcf && !B_IS_IN_TREE(curcf)), 1160 (curcf && !B_IS_IN_TREE(curcf)),
@@ -1222,7 +1222,7 @@ static int ip_check_balance(struct tree_balance *tb, int h)
1222 contains node being balanced. The mnemonic is 1222 contains node being balanced. The mnemonic is
1223 that the attempted change in node space used level 1223 that the attempted change in node space used level
1224 is levbytes bytes. */ 1224 is levbytes bytes. */
1225 n_ret_value; 1225 ret;
1226 1226
1227 int lfree, sfree, rfree /* free space in L, S and R */ ; 1227 int lfree, sfree, rfree /* free space in L, S and R */ ;
1228 1228
@@ -1262,22 +1262,22 @@ static int ip_check_balance(struct tree_balance *tb, int h)
1262 if (!h) 1262 if (!h)
1263 reiserfs_panic(tb->tb_sb, "vs-8210", 1263 reiserfs_panic(tb->tb_sb, "vs-8210",
1264 "S[0] can not be 0"); 1264 "S[0] can not be 0");
1265 switch (n_ret_value = get_empty_nodes(tb, h)) { 1265 switch (ret = get_empty_nodes(tb, h)) {
1266 case CARRY_ON: 1266 case CARRY_ON:
1267 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); 1267 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1268 return NO_BALANCING_NEEDED; /* no balancing for higher levels needed */ 1268 return NO_BALANCING_NEEDED; /* no balancing for higher levels needed */
1269 1269
1270 case NO_DISK_SPACE: 1270 case NO_DISK_SPACE:
1271 case REPEAT_SEARCH: 1271 case REPEAT_SEARCH:
1272 return n_ret_value; 1272 return ret;
1273 default: 1273 default:
1274 reiserfs_panic(tb->tb_sb, "vs-8215", "incorrect " 1274 reiserfs_panic(tb->tb_sb, "vs-8215", "incorrect "
1275 "return value of get_empty_nodes"); 1275 "return value of get_empty_nodes");
1276 } 1276 }
1277 } 1277 }
1278 1278
1279 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. */
1280 return n_ret_value; 1280 return ret;
1281 1281
1282 sfree = B_FREE_SPACE(Sh); 1282 sfree = B_FREE_SPACE(Sh);
1283 1283
@@ -1564,7 +1564,7 @@ static int dc_check_balance_internal(struct tree_balance *tb, int h)
1564 /* Sh is the node whose balance is currently being checked, 1564 /* Sh is the node whose balance is currently being checked,
1565 and Fh is its father. */ 1565 and Fh is its father. */
1566 struct buffer_head *Sh, *Fh; 1566 struct buffer_head *Sh, *Fh;
1567 int maxsize, n_ret_value; 1567 int maxsize, ret;
1568 int lfree, rfree /* free space in L and R */ ; 1568 int lfree, rfree /* free space in L and R */ ;
1569 1569
1570 Sh = PATH_H_PBUFFER(tb->tb_path, h); 1570 Sh = PATH_H_PBUFFER(tb->tb_path, h);
@@ -1589,8 +1589,8 @@ static int dc_check_balance_internal(struct tree_balance *tb, int h)
1589 return CARRY_ON; 1589 return CARRY_ON;
1590 } 1590 }
1591 1591
1592 if ((n_ret_value = get_parents(tb, h)) != CARRY_ON) 1592 if ((ret = get_parents(tb, h)) != CARRY_ON)
1593 return n_ret_value; 1593 return ret;
1594 1594
1595 /* get free space of neighbors */ 1595 /* get free space of neighbors */
1596 rfree = get_rfree(tb, h); 1596 rfree = get_rfree(tb, h);
@@ -1747,7 +1747,7 @@ static int dc_check_balance_leaf(struct tree_balance *tb, int h)
1747 attempted change in node space used level is levbytes bytes. */ 1747 attempted change in node space used level is levbytes bytes. */
1748 int levbytes; 1748 int levbytes;
1749 /* the maximal item size */ 1749 /* the maximal item size */
1750 int maxsize, n_ret_value; 1750 int maxsize, ret;
1751 /* S0 is the node whose balance is currently being checked, 1751 /* S0 is the node whose balance is currently being checked,
1752 and F0 is its father. */ 1752 and F0 is its father. */
1753 struct buffer_head *S0, *F0; 1753 struct buffer_head *S0, *F0;
@@ -1769,8 +1769,8 @@ static int dc_check_balance_leaf(struct tree_balance *tb, int h)
1769 return NO_BALANCING_NEEDED; 1769 return NO_BALANCING_NEEDED;
1770 } 1770 }
1771 1771
1772 if ((n_ret_value = get_parents(tb, h)) != CARRY_ON) 1772 if ((ret = get_parents(tb, h)) != CARRY_ON)
1773 return n_ret_value; 1773 return ret;
1774 1774
1775 /* get free space of neighbors */ 1775 /* get free space of neighbors */
1776 rfree = get_rfree(tb, h); 1776 rfree = get_rfree(tb, h);
@@ -1889,40 +1889,40 @@ static int check_balance(int mode,
1889} 1889}
1890 1890
1891/* 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.*/
1892static int get_direct_parent(struct tree_balance *tb, int n_h) 1892static int get_direct_parent(struct tree_balance *tb, int h)
1893{ 1893{
1894 struct buffer_head *bh; 1894 struct buffer_head *bh;
1895 struct treepath *path = tb->tb_path; 1895 struct treepath *path = tb->tb_path;
1896 int n_position, 1896 int position,
1897 n_path_offset = PATH_H_PATH_OFFSET(tb->tb_path, n_h); 1897 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h);
1898 1898
1899 /* We are in the root or in the new root. */ 1899 /* We are in the root or in the new root. */
1900 if (n_path_offset <= FIRST_PATH_ELEMENT_OFFSET) { 1900 if (path_offset <= FIRST_PATH_ELEMENT_OFFSET) {
1901 1901
1902 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET - 1, 1902 RFALSE(path_offset < FIRST_PATH_ELEMENT_OFFSET - 1,
1903 "PAP-8260: invalid offset in the path"); 1903 "PAP-8260: invalid offset in the path");
1904 1904
1905 if (PATH_OFFSET_PBUFFER(path, FIRST_PATH_ELEMENT_OFFSET)-> 1905 if (PATH_OFFSET_PBUFFER(path, FIRST_PATH_ELEMENT_OFFSET)->
1906 b_blocknr == SB_ROOT_BLOCK(tb->tb_sb)) { 1906 b_blocknr == SB_ROOT_BLOCK(tb->tb_sb)) {
1907 /* Root is not changed. */ 1907 /* Root is not changed. */
1908 PATH_OFFSET_PBUFFER(path, n_path_offset - 1) = NULL; 1908 PATH_OFFSET_PBUFFER(path, path_offset - 1) = NULL;
1909 PATH_OFFSET_POSITION(path, n_path_offset - 1) = 0; 1909 PATH_OFFSET_POSITION(path, path_offset - 1) = 0;
1910 return CARRY_ON; 1910 return CARRY_ON;
1911 } 1911 }
1912 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. */
1913 } 1913 }
1914 1914
1915 if (!B_IS_IN_TREE 1915 if (!B_IS_IN_TREE
1916 (bh = PATH_OFFSET_PBUFFER(path, n_path_offset - 1))) 1916 (bh = PATH_OFFSET_PBUFFER(path, path_offset - 1)))
1917 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. */
1918 1918
1919 if ((n_position = 1919 if ((position =
1920 PATH_OFFSET_POSITION(path, 1920 PATH_OFFSET_POSITION(path,
1921 n_path_offset - 1)) > B_NR_ITEMS(bh)) 1921 path_offset - 1)) > B_NR_ITEMS(bh))
1922 return REPEAT_SEARCH; 1922 return REPEAT_SEARCH;
1923 1923
1924 if (B_N_CHILD_NUM(bh, n_position) != 1924 if (B_N_CHILD_NUM(bh, position) !=
1925 PATH_OFFSET_PBUFFER(path, n_path_offset)->b_blocknr) 1925 PATH_OFFSET_PBUFFER(path, path_offset)->b_blocknr)
1926 /* 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. */
1927 return REPEAT_SEARCH; 1927 return REPEAT_SEARCH;
1928 1928
@@ -1935,92 +1935,92 @@ static int get_direct_parent(struct tree_balance *tb, int n_h)
1935 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. */
1936} 1936}
1937 1937
1938/* 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
1939 * of S[n_h] we 1939 * of S[h] we
1940 * 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.
1941 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked; 1941 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked;
1942 * CARRY_ON - schedule didn't occur while the function worked; 1942 * CARRY_ON - schedule didn't occur while the function worked;
1943 */ 1943 */
1944static int get_neighbors(struct tree_balance *tb, int n_h) 1944static int get_neighbors(struct tree_balance *tb, int h)
1945{ 1945{
1946 int n_child_position, 1946 int child_position,
1947 n_path_offset = PATH_H_PATH_OFFSET(tb->tb_path, n_h + 1); 1947 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h + 1);
1948 unsigned long n_son_number; 1948 unsigned long son_number;
1949 struct super_block *sb = tb->tb_sb; 1949 struct super_block *sb = tb->tb_sb;
1950 struct buffer_head *bh; 1950 struct buffer_head *bh;
1951 1951
1952 PROC_INFO_INC(sb, get_neighbors[n_h]); 1952 PROC_INFO_INC(sb, get_neighbors[h]);
1953 1953
1954 if (tb->lnum[n_h]) { 1954 if (tb->lnum[h]) {
1955 /* We need left neighbor to balance S[n_h]. */ 1955 /* We need left neighbor to balance S[h]. */
1956 PROC_INFO_INC(sb, need_l_neighbor[n_h]); 1956 PROC_INFO_INC(sb, need_l_neighbor[h]);
1957 bh = PATH_OFFSET_PBUFFER(tb->tb_path, n_path_offset); 1957 bh = PATH_OFFSET_PBUFFER(tb->tb_path, path_offset);
1958 1958
1959 RFALSE(bh == tb->FL[n_h] && 1959 RFALSE(bh == tb->FL[h] &&
1960 !PATH_OFFSET_POSITION(tb->tb_path, n_path_offset), 1960 !PATH_OFFSET_POSITION(tb->tb_path, path_offset),
1961 "PAP-8270: invalid position in the parent"); 1961 "PAP-8270: invalid position in the parent");
1962 1962
1963 n_child_position = 1963 child_position =
1964 (bh == 1964 (bh ==
1965 tb->FL[n_h]) ? tb->lkey[n_h] : B_NR_ITEMS(tb-> 1965 tb->FL[h]) ? tb->lkey[h] : B_NR_ITEMS(tb->
1966 FL[n_h]); 1966 FL[h]);
1967 n_son_number = B_N_CHILD_NUM(tb->FL[n_h], n_child_position); 1967 son_number = B_N_CHILD_NUM(tb->FL[h], child_position);
1968 bh = sb_bread(sb, n_son_number); 1968 bh = sb_bread(sb, son_number);
1969 if (!bh) 1969 if (!bh)
1970 return IO_ERROR; 1970 return IO_ERROR;
1971 if (FILESYSTEM_CHANGED_TB(tb)) { 1971 if (FILESYSTEM_CHANGED_TB(tb)) {
1972 brelse(bh); 1972 brelse(bh);
1973 PROC_INFO_INC(sb, get_neighbors_restart[n_h]); 1973 PROC_INFO_INC(sb, get_neighbors_restart[h]);
1974 return REPEAT_SEARCH; 1974 return REPEAT_SEARCH;
1975 } 1975 }
1976 1976
1977 RFALSE(!B_IS_IN_TREE(tb->FL[n_h]) || 1977 RFALSE(!B_IS_IN_TREE(tb->FL[h]) ||
1978 n_child_position > B_NR_ITEMS(tb->FL[n_h]) || 1978 child_position > B_NR_ITEMS(tb->FL[h]) ||
1979 B_N_CHILD_NUM(tb->FL[n_h], n_child_position) != 1979 B_N_CHILD_NUM(tb->FL[h], child_position) !=
1980 bh->b_blocknr, "PAP-8275: invalid parent"); 1980 bh->b_blocknr, "PAP-8275: invalid parent");
1981 RFALSE(!B_IS_IN_TREE(bh), "PAP-8280: invalid child"); 1981 RFALSE(!B_IS_IN_TREE(bh), "PAP-8280: invalid child");
1982 RFALSE(!n_h && 1982 RFALSE(!h &&
1983 B_FREE_SPACE(bh) != 1983 B_FREE_SPACE(bh) !=
1984 MAX_CHILD_SIZE(bh) - 1984 MAX_CHILD_SIZE(bh) -
1985 dc_size(B_N_CHILD(tb->FL[0], n_child_position)), 1985 dc_size(B_N_CHILD(tb->FL[0], child_position)),
1986 "PAP-8290: invalid child size of left neighbor"); 1986 "PAP-8290: invalid child size of left neighbor");
1987 1987
1988 brelse(tb->L[n_h]); 1988 brelse(tb->L[h]);
1989 tb->L[n_h] = bh; 1989 tb->L[h] = bh;
1990 } 1990 }
1991 1991
1992 /* We need right neighbor to balance S[n_path_offset]. */ 1992 /* We need right neighbor to balance S[path_offset]. */
1993 if (tb->rnum[n_h]) { 1993 if (tb->rnum[h]) { /* We need right neighbor to balance S[path_offset]. */
1994 PROC_INFO_INC(sb, need_r_neighbor[n_h]); 1994 PROC_INFO_INC(sb, need_r_neighbor[h]);
1995 bh = PATH_OFFSET_PBUFFER(tb->tb_path, n_path_offset); 1995 bh = PATH_OFFSET_PBUFFER(tb->tb_path, path_offset);
1996 1996
1997 RFALSE(bh == tb->FR[n_h] && 1997 RFALSE(bh == tb->FR[h] &&
1998 PATH_OFFSET_POSITION(tb->tb_path, 1998 PATH_OFFSET_POSITION(tb->tb_path,
1999 n_path_offset) >= 1999 path_offset) >=
2000 B_NR_ITEMS(bh), 2000 B_NR_ITEMS(bh),
2001 "PAP-8295: invalid position in the parent"); 2001 "PAP-8295: invalid position in the parent");
2002 2002
2003 n_child_position = 2003 child_position =
2004 (bh == tb->FR[n_h]) ? tb->rkey[n_h] + 1 : 0; 2004 (bh == tb->FR[h]) ? tb->rkey[h] + 1 : 0;
2005 n_son_number = B_N_CHILD_NUM(tb->FR[n_h], n_child_position); 2005 son_number = B_N_CHILD_NUM(tb->FR[h], child_position);
2006 bh = sb_bread(sb, n_son_number); 2006 bh = sb_bread(sb, son_number);
2007 if (!bh) 2007 if (!bh)
2008 return IO_ERROR; 2008 return IO_ERROR;
2009 if (FILESYSTEM_CHANGED_TB(tb)) { 2009 if (FILESYSTEM_CHANGED_TB(tb)) {
2010 brelse(bh); 2010 brelse(bh);
2011 PROC_INFO_INC(sb, get_neighbors_restart[n_h]); 2011 PROC_INFO_INC(sb, get_neighbors_restart[h]);
2012 return REPEAT_SEARCH; 2012 return REPEAT_SEARCH;
2013 } 2013 }
2014 brelse(tb->R[n_h]); 2014 brelse(tb->R[h]);
2015 tb->R[n_h] = bh; 2015 tb->R[h] = bh;
2016 2016
2017 RFALSE(!n_h 2017 RFALSE(!h
2018 && B_FREE_SPACE(bh) != 2018 && B_FREE_SPACE(bh) !=
2019 MAX_CHILD_SIZE(bh) - 2019 MAX_CHILD_SIZE(bh) -
2020 dc_size(B_N_CHILD(tb->FR[0], n_child_position)), 2020 dc_size(B_N_CHILD(tb->FR[0], child_position)),
2021 "PAP-8300: invalid child size of right neighbor (%d != %d - %d)", 2021 "PAP-8300: invalid child size of right neighbor (%d != %d - %d)",
2022 B_FREE_SPACE(bh), MAX_CHILD_SIZE(bh), 2022 B_FREE_SPACE(bh), MAX_CHILD_SIZE(bh),
2023 dc_size(B_N_CHILD(tb->FR[0], n_child_position))); 2023 dc_size(B_N_CHILD(tb->FR[0], child_position)));
2024 2024
2025 } 2025 }
2026 return CARRY_ON; 2026 return CARRY_ON;
@@ -2317,11 +2317,11 @@ static int wait_tb_buffers_until_unlocked(struct tree_balance *tb)
2317 * -1 - if no_disk_space 2317 * -1 - if no_disk_space
2318 */ 2318 */
2319 2319
2320int fix_nodes(int n_op_mode, struct tree_balance *tb, 2320int fix_nodes(int op_mode, struct tree_balance *tb,
2321 struct item_head *ins_ih, const void *data) 2321 struct item_head *ins_ih, const void *data)
2322{ 2322{
2323 int n_ret_value, n_h, n_item_num = PATH_LAST_POSITION(tb->tb_path); 2323 int ret, h, item_num = PATH_LAST_POSITION(tb->tb_path);
2324 int n_pos_in_item; 2324 int pos_in_item;
2325 2325
2326 /* 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
2327 ** during wait_tb_buffers_run 2327 ** during wait_tb_buffers_run
@@ -2331,7 +2331,7 @@ int fix_nodes(int n_op_mode, struct tree_balance *tb,
2331 2331
2332 ++REISERFS_SB(tb->tb_sb)->s_fix_nodes; 2332 ++REISERFS_SB(tb->tb_sb)->s_fix_nodes;
2333 2333
2334 n_pos_in_item = tb->tb_path->pos_in_item; 2334 pos_in_item = tb->tb_path->pos_in_item;
2335 2335
2336 tb->fs_gen = get_generation(tb->tb_sb); 2336 tb->fs_gen = get_generation(tb->tb_sb);
2337 2337
@@ -2364,26 +2364,26 @@ int fix_nodes(int n_op_mode, struct tree_balance *tb,
2364 reiserfs_panic(tb->tb_sb, "PAP-8320", "S[0] (%b %z) is " 2364 reiserfs_panic(tb->tb_sb, "PAP-8320", "S[0] (%b %z) is "
2365 "not uptodate at the beginning of fix_nodes " 2365 "not uptodate at the beginning of fix_nodes "
2366 "or not in tree (mode %c)", 2366 "or not in tree (mode %c)",
2367 tbS0, tbS0, n_op_mode); 2367 tbS0, tbS0, op_mode);
2368 2368
2369 /* Check parameters. */ 2369 /* Check parameters. */
2370 switch (n_op_mode) { 2370 switch (op_mode) {
2371 case M_INSERT: 2371 case M_INSERT:
2372 if (n_item_num <= 0 || n_item_num > B_NR_ITEMS(tbS0)) 2372 if (item_num <= 0 || item_num > B_NR_ITEMS(tbS0))
2373 reiserfs_panic(tb->tb_sb, "PAP-8330", "Incorrect " 2373 reiserfs_panic(tb->tb_sb, "PAP-8330", "Incorrect "
2374 "item number %d (in S0 - %d) in case " 2374 "item number %d (in S0 - %d) in case "
2375 "of insert", n_item_num, 2375 "of insert", item_num,
2376 B_NR_ITEMS(tbS0)); 2376 B_NR_ITEMS(tbS0));
2377 break; 2377 break;
2378 case M_PASTE: 2378 case M_PASTE:
2379 case M_DELETE: 2379 case M_DELETE:
2380 case M_CUT: 2380 case M_CUT:
2381 if (n_item_num < 0 || n_item_num >= B_NR_ITEMS(tbS0)) { 2381 if (item_num < 0 || item_num >= B_NR_ITEMS(tbS0)) {
2382 print_block(tbS0, 0, -1, -1); 2382 print_block(tbS0, 0, -1, -1);
2383 reiserfs_panic(tb->tb_sb, "PAP-8335", "Incorrect " 2383 reiserfs_panic(tb->tb_sb, "PAP-8335", "Incorrect "
2384 "item number(%d); mode = %c " 2384 "item number(%d); mode = %c "
2385 "insert_size = %d", 2385 "insert_size = %d",
2386 n_item_num, n_op_mode, 2386 item_num, op_mode,
2387 tb->insert_size[0]); 2387 tb->insert_size[0]);
2388 } 2388 }
2389 break; 2389 break;
@@ -2397,73 +2397,73 @@ int fix_nodes(int n_op_mode, struct tree_balance *tb,
2397 // FIXME: maybe -ENOMEM when tb->vn_buf == 0? Now just repeat 2397 // FIXME: maybe -ENOMEM when tb->vn_buf == 0? Now just repeat
2398 return REPEAT_SEARCH; 2398 return REPEAT_SEARCH;
2399 2399
2400 /* 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. */
2401 for (n_h = 0; n_h < MAX_HEIGHT && tb->insert_size[n_h]; n_h++) { 2401 for (h = 0; h < MAX_HEIGHT && tb->insert_size[h]; h++) {
2402 n_ret_value = get_direct_parent(tb, n_h); 2402 ret = get_direct_parent(tb, h);
2403 if (n_ret_value != CARRY_ON) 2403 if (ret != CARRY_ON)
2404 goto repeat; 2404 goto repeat;
2405 2405
2406 n_ret_value = check_balance(n_op_mode, tb, n_h, n_item_num, 2406 ret = check_balance(op_mode, tb, h, item_num,
2407 n_pos_in_item, ins_ih, data); 2407 pos_in_item, ins_ih, data);
2408 if (n_ret_value != CARRY_ON) { 2408 if (ret != CARRY_ON) {
2409 if (n_ret_value == NO_BALANCING_NEEDED) { 2409 if (ret == NO_BALANCING_NEEDED) {
2410 /* No balancing for higher levels needed. */ 2410 /* No balancing for higher levels needed. */
2411 n_ret_value = get_neighbors(tb, n_h); 2411 ret = get_neighbors(tb, h);
2412 if (n_ret_value != CARRY_ON) 2412 if (ret != CARRY_ON)
2413 goto repeat; 2413 goto repeat;
2414 if (n_h != MAX_HEIGHT - 1) 2414 if (h != MAX_HEIGHT - 1)
2415 tb->insert_size[n_h + 1] = 0; 2415 tb->insert_size[h + 1] = 0;
2416 /* ok, analysis and resource gathering are complete */ 2416 /* ok, analysis and resource gathering are complete */
2417 break; 2417 break;
2418 } 2418 }
2419 goto repeat; 2419 goto repeat;
2420 } 2420 }
2421 2421
2422 n_ret_value = get_neighbors(tb, n_h); 2422 ret = get_neighbors(tb, h);
2423 if (n_ret_value != CARRY_ON) 2423 if (ret != CARRY_ON)
2424 goto repeat; 2424 goto repeat;
2425 2425
2426 /* No disk space, or schedule occurred and analysis may be 2426 /* No disk space, or schedule occurred and analysis may be
2427 * invalid and needs to be redone. */ 2427 * invalid and needs to be redone. */
2428 n_ret_value = get_empty_nodes(tb, n_h); 2428 ret = get_empty_nodes(tb, h);
2429 if (n_ret_value != CARRY_ON) 2429 if (ret != CARRY_ON)
2430 goto repeat; 2430 goto repeat;
2431 2431
2432 if (!PATH_H_PBUFFER(tb->tb_path, n_h)) { 2432 if (!PATH_H_PBUFFER(tb->tb_path, h)) {
2433 /* 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
2434 level, this means that we are creating a new root. */ 2434 level, this means that we are creating a new root. */
2435 2435
2436 RFALSE(tb->blknum[n_h] != 1, 2436 RFALSE(tb->blknum[h] != 1,
2437 "PAP-8350: creating new empty root"); 2437 "PAP-8350: creating new empty root");
2438 2438
2439 if (n_h < MAX_HEIGHT - 1) 2439 if (h < MAX_HEIGHT - 1)
2440 tb->insert_size[n_h + 1] = 0; 2440 tb->insert_size[h + 1] = 0;
2441 } else if (!PATH_H_PBUFFER(tb->tb_path, n_h + 1)) { 2441 } else if (!PATH_H_PBUFFER(tb->tb_path, h + 1)) {
2442 if (tb->blknum[n_h] > 1) { 2442 if (tb->blknum[h] > 1) {
2443 /* The tree needs to be grown, so this node S[n_h] 2443 /* The tree needs to be grown, so this node S[h]
2444 which is the root node is split into two nodes, 2444 which is the root node is split into two nodes,
2445 and a new node (S[n_h+1]) will be created to 2445 and a new node (S[h+1]) will be created to
2446 become the root node. */ 2446 become the root node. */
2447 2447
2448 RFALSE(n_h == MAX_HEIGHT - 1, 2448 RFALSE(h == MAX_HEIGHT - 1,
2449 "PAP-8355: attempt to create too high of a tree"); 2449 "PAP-8355: attempt to create too high of a tree");
2450 2450
2451 tb->insert_size[n_h + 1] = 2451 tb->insert_size[h + 1] =
2452 (DC_SIZE + 2452 (DC_SIZE +
2453 KEY_SIZE) * (tb->blknum[n_h] - 1) + 2453 KEY_SIZE) * (tb->blknum[h] - 1) +
2454 DC_SIZE; 2454 DC_SIZE;
2455 } else if (n_h < MAX_HEIGHT - 1) 2455 } else if (h < MAX_HEIGHT - 1)
2456 tb->insert_size[n_h + 1] = 0; 2456 tb->insert_size[h + 1] = 0;
2457 } else 2457 } else
2458 tb->insert_size[n_h + 1] = 2458 tb->insert_size[h + 1] =
2459 (DC_SIZE + KEY_SIZE) * (tb->blknum[n_h] - 1); 2459 (DC_SIZE + KEY_SIZE) * (tb->blknum[h] - 1);
2460 } 2460 }
2461 2461
2462 n_ret_value = wait_tb_buffers_until_unlocked(tb); 2462 ret = wait_tb_buffers_until_unlocked(tb);
2463 if (n_ret_value == CARRY_ON) { 2463 if (ret == CARRY_ON) {
2464 if (FILESYSTEM_CHANGED_TB(tb)) { 2464 if (FILESYSTEM_CHANGED_TB(tb)) {
2465 wait_tb_buffers_run = 1; 2465 wait_tb_buffers_run = 1;
2466 n_ret_value = REPEAT_SEARCH; 2466 ret = REPEAT_SEARCH;
2467 goto repeat; 2467 goto repeat;
2468 } else { 2468 } else {
2469 return CARRY_ON; 2469 return CARRY_ON;
@@ -2529,7 +2529,7 @@ int fix_nodes(int n_op_mode, struct tree_balance *tb,
2529 (tb->tb_sb, tb->FEB[i]); 2529 (tb->tb_sb, tb->FEB[i]);
2530 } 2530 }
2531 } 2531 }
2532 return n_ret_value; 2532 return ret;
2533 } 2533 }
2534 2534
2535} 2535}
diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
index fd769c8dac32..e23303daa868 100644
--- a/fs/reiserfs/stree.c
+++ b/fs/reiserfs/stree.c
@@ -136,11 +136,11 @@ inline int comp_short_le_keys(const struct reiserfs_key *key1,
136 const struct reiserfs_key *key2) 136 const struct reiserfs_key *key2)
137{ 137{
138 __u32 *k1_u32, *k2_u32; 138 __u32 *k1_u32, *k2_u32;
139 int n_key_length = REISERFS_SHORT_KEY_LEN; 139 int key_length = REISERFS_SHORT_KEY_LEN;
140 140
141 k1_u32 = (__u32 *) key1; 141 k1_u32 = (__u32 *) key1;
142 k2_u32 = (__u32 *) key2; 142 k2_u32 = (__u32 *) key2;
143 for (; n_key_length--; ++k1_u32, ++k2_u32) { 143 for (; key_length--; ++k1_u32, ++k2_u32) {
144 if (le32_to_cpu(*k1_u32) < le32_to_cpu(*k2_u32)) 144 if (le32_to_cpu(*k1_u32) < le32_to_cpu(*k2_u32))
145 return -1; 145 return -1;
146 if (le32_to_cpu(*k1_u32) > le32_to_cpu(*k2_u32)) 146 if (le32_to_cpu(*k1_u32) > le32_to_cpu(*k2_u32))
@@ -177,10 +177,10 @@ inline int comp_le_keys(const struct reiserfs_key *k1,
177 * *pos = number of the searched element if found, else the * 177 * *pos = number of the searched element if found, else the *
178 * number of the first element that is larger than key. * 178 * number of the first element that is larger than key. *
179 **************************************************************************/ 179 **************************************************************************/
180/* For those not familiar with binary search: n_lbound is the leftmost item that it 180/* For those not familiar with binary search: lbound is the leftmost item that it
181 could be, n_rbound the rightmost item that it could be. We examine the item 181 could be, rbound the rightmost item that it could be. We examine the item
182 halfway between n_lbound and n_rbound, and that tells us either that we can increase 182 halfway between lbound and rbound, and that tells us either that we can increase
183 n_lbound, or decrease n_rbound, or that we have found it, or if n_lbound <= n_rbound that 183 lbound, or decrease rbound, or that we have found it, or if lbound <= rbound that
184 there are no possible items, and we have not found it. With each examination we 184 there are no possible items, and we have not found it. With each examination we
185 cut the number of possible items it could be by one more than half rounded down, 185 cut the number of possible items it could be by one more than half rounded down,
186 or we find it. */ 186 or we find it. */
@@ -198,28 +198,27 @@ static inline int bin_search(const void *key, /* Key to search for. */
198 int *pos /* Number of the searched for element. */ 198 int *pos /* Number of the searched for element. */
199 ) 199 )
200{ 200{
201 int n_rbound, n_lbound, n_j; 201 int rbound, lbound, j;
202 202
203 for (n_j = ((n_rbound = num - 1) + (n_lbound = 0)) / 2; 203 for (j = ((rbound = num - 1) + (lbound = 0)) / 2;
204 n_lbound <= n_rbound; n_j = (n_rbound + n_lbound) / 2) 204 lbound <= rbound; j = (rbound + lbound) / 2)
205 switch (comp_keys 205 switch (comp_keys
206 ((struct reiserfs_key *)((char *)base + 206 ((struct reiserfs_key *)((char *)base + j * width),
207 n_j * width),
208 (struct cpu_key *)key)) { 207 (struct cpu_key *)key)) {
209 case -1: 208 case -1:
210 n_lbound = n_j + 1; 209 lbound = j + 1;
211 continue; 210 continue;
212 case 1: 211 case 1:
213 n_rbound = n_j - 1; 212 rbound = j - 1;
214 continue; 213 continue;
215 case 0: 214 case 0:
216 *pos = n_j; 215 *pos = j;
217 return ITEM_FOUND; /* Key found in the array. */ 216 return ITEM_FOUND; /* Key found in the array. */
218 } 217 }
219 218
220 /* bin_search did not find given key, it returns position of key, 219 /* bin_search did not find given key, it returns position of key,
221 that is minimal and greater than the given one. */ 220 that is minimal and greater than the given one. */
222 *pos = n_lbound; 221 *pos = lbound;
223 return ITEM_NOT_FOUND; 222 return ITEM_NOT_FOUND;
224} 223}
225 224
@@ -242,43 +241,41 @@ static const struct reiserfs_key MAX_KEY = {
242 of the path, and going upwards. We must check the path's validity at each step. If the key is not in 241 of the path, and going upwards. We must check the path's validity at each step. If the key is not in
243 the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this 242 the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this
244 case we return a special key, either MIN_KEY or MAX_KEY. */ 243 case we return a special key, either MIN_KEY or MAX_KEY. */
245static inline const struct reiserfs_key *get_lkey(const struct treepath 244static inline const struct reiserfs_key *get_lkey(const struct treepath *chk_path,
246 *chk_path, 245 const struct super_block *sb)
247 const struct super_block
248 *sb)
249{ 246{
250 int n_position, n_path_offset = chk_path->path_length; 247 int position, path_offset = chk_path->path_length;
251 struct buffer_head *parent; 248 struct buffer_head *parent;
252 249
253 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET, 250 RFALSE(path_offset < FIRST_PATH_ELEMENT_OFFSET,
254 "PAP-5010: invalid offset in the path"); 251 "PAP-5010: invalid offset in the path");
255 252
256 /* While not higher in path than first element. */ 253 /* While not higher in path than first element. */
257 while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) { 254 while (path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
258 255
259 RFALSE(!buffer_uptodate 256 RFALSE(!buffer_uptodate
260 (PATH_OFFSET_PBUFFER(chk_path, n_path_offset)), 257 (PATH_OFFSET_PBUFFER(chk_path, path_offset)),
261 "PAP-5020: parent is not uptodate"); 258 "PAP-5020: parent is not uptodate");
262 259
263 /* Parent at the path is not in the tree now. */ 260 /* Parent at the path is not in the tree now. */
264 if (!B_IS_IN_TREE 261 if (!B_IS_IN_TREE
265 (parent = 262 (parent =
266 PATH_OFFSET_PBUFFER(chk_path, n_path_offset))) 263 PATH_OFFSET_PBUFFER(chk_path, path_offset)))
267 return &MAX_KEY; 264 return &MAX_KEY;
268 /* Check whether position in the parent is correct. */ 265 /* Check whether position in the parent is correct. */
269 if ((n_position = 266 if ((position =
270 PATH_OFFSET_POSITION(chk_path, 267 PATH_OFFSET_POSITION(chk_path,
271 n_path_offset)) > 268 path_offset)) >
272 B_NR_ITEMS(parent)) 269 B_NR_ITEMS(parent))
273 return &MAX_KEY; 270 return &MAX_KEY;
274 /* Check whether parent at the path really points to the child. */ 271 /* Check whether parent at the path really points to the child. */
275 if (B_N_CHILD_NUM(parent, n_position) != 272 if (B_N_CHILD_NUM(parent, position) !=
276 PATH_OFFSET_PBUFFER(chk_path, 273 PATH_OFFSET_PBUFFER(chk_path,
277 n_path_offset + 1)->b_blocknr) 274 path_offset + 1)->b_blocknr)
278 return &MAX_KEY; 275 return &MAX_KEY;
279 /* Return delimiting key if position in the parent is not equal to zero. */ 276 /* Return delimiting key if position in the parent is not equal to zero. */
280 if (n_position) 277 if (position)
281 return B_N_PDELIM_KEY(parent, n_position - 1); 278 return B_N_PDELIM_KEY(parent, position - 1);
282 } 279 }
283 /* Return MIN_KEY if we are in the root of the buffer tree. */ 280 /* Return MIN_KEY if we are in the root of the buffer tree. */
284 if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)-> 281 if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)->
@@ -291,37 +288,37 @@ static inline const struct reiserfs_key *get_lkey(const struct treepath
291inline const struct reiserfs_key *get_rkey(const struct treepath *chk_path, 288inline const struct reiserfs_key *get_rkey(const struct treepath *chk_path,
292 const struct super_block *sb) 289 const struct super_block *sb)
293{ 290{
294 int n_position, n_path_offset = chk_path->path_length; 291 int position, path_offset = chk_path->path_length;
295 struct buffer_head *parent; 292 struct buffer_head *parent;
296 293
297 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET, 294 RFALSE(path_offset < FIRST_PATH_ELEMENT_OFFSET,
298 "PAP-5030: invalid offset in the path"); 295 "PAP-5030: invalid offset in the path");
299 296
300 while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) { 297 while (path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
301 298
302 RFALSE(!buffer_uptodate 299 RFALSE(!buffer_uptodate
303 (PATH_OFFSET_PBUFFER(chk_path, n_path_offset)), 300 (PATH_OFFSET_PBUFFER(chk_path, path_offset)),
304 "PAP-5040: parent is not uptodate"); 301 "PAP-5040: parent is not uptodate");
305 302
306 /* Parent at the path is not in the tree now. */ 303 /* Parent at the path is not in the tree now. */
307 if (!B_IS_IN_TREE 304 if (!B_IS_IN_TREE
308 (parent = 305 (parent =
309 PATH_OFFSET_PBUFFER(chk_path, n_path_offset))) 306 PATH_OFFSET_PBUFFER(chk_path, path_offset)))
310 return &MIN_KEY; 307 return &MIN_KEY;
311 /* Check whether position in the parent is correct. */ 308 /* Check whether position in the parent is correct. */
312 if ((n_position = 309 if ((position =
313 PATH_OFFSET_POSITION(chk_path, 310 PATH_OFFSET_POSITION(chk_path,
314 n_path_offset)) > 311 path_offset)) >
315 B_NR_ITEMS(parent)) 312 B_NR_ITEMS(parent))
316 return &MIN_KEY; 313 return &MIN_KEY;
317 /* Check whether parent at the path really points to the child. */ 314 /* Check whether parent at the path really points to the child. */
318 if (B_N_CHILD_NUM(parent, n_position) != 315 if (B_N_CHILD_NUM(parent, position) !=
319 PATH_OFFSET_PBUFFER(chk_path, 316 PATH_OFFSET_PBUFFER(chk_path,
320 n_path_offset + 1)->b_blocknr) 317 path_offset + 1)->b_blocknr)
321 return &MIN_KEY; 318 return &MIN_KEY;
322 /* Return delimiting key if position in the parent is not the last one. */ 319 /* Return delimiting key if position in the parent is not the last one. */
323 if (n_position != B_NR_ITEMS(parent)) 320 if (position != B_NR_ITEMS(parent))
324 return B_N_PDELIM_KEY(parent, n_position); 321 return B_N_PDELIM_KEY(parent, position);
325 } 322 }
326 /* Return MAX_KEY if we are in the root of the buffer tree. */ 323 /* Return MAX_KEY if we are in the root of the buffer tree. */
327 if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)-> 324 if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)->
@@ -371,14 +368,14 @@ int reiserfs_check_path(struct treepath *p)
371void pathrelse_and_restore(struct super_block *sb, 368void pathrelse_and_restore(struct super_block *sb,
372 struct treepath *search_path) 369 struct treepath *search_path)
373{ 370{
374 int n_path_offset = search_path->path_length; 371 int path_offset = search_path->path_length;
375 372
376 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET, 373 RFALSE(path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
377 "clm-4000: invalid path offset"); 374 "clm-4000: invalid path offset");
378 375
379 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) { 376 while (path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) {
380 struct buffer_head *bh; 377 struct buffer_head *bh;
381 bh = PATH_OFFSET_PBUFFER(search_path, n_path_offset--); 378 bh = PATH_OFFSET_PBUFFER(search_path, path_offset--);
382 reiserfs_restore_prepared_buffer(sb, bh); 379 reiserfs_restore_prepared_buffer(sb, bh);
383 brelse(bh); 380 brelse(bh);
384 } 381 }
@@ -388,13 +385,13 @@ void pathrelse_and_restore(struct super_block *sb,
388/* Drop the reference to each buffer in a path */ 385/* Drop the reference to each buffer in a path */
389void pathrelse(struct treepath *search_path) 386void pathrelse(struct treepath *search_path)
390{ 387{
391 int n_path_offset = search_path->path_length; 388 int path_offset = search_path->path_length;
392 389
393 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET, 390 RFALSE(path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
394 "PAP-5090: invalid path offset"); 391 "PAP-5090: invalid path offset");
395 392
396 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) 393 while (path_offset > ILLEGAL_PATH_ELEMENT_OFFSET)
397 brelse(PATH_OFFSET_PBUFFER(search_path, n_path_offset--)); 394 brelse(PATH_OFFSET_PBUFFER(search_path, path_offset--));
398 395
399 search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; 396 search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
400} 397}
@@ -572,16 +569,16 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s
572 by the calling 569 by the calling
573 function. It is filled up 570 function. It is filled up
574 by this function. */ 571 by this function. */
575 int n_stop_level /* How far down the tree to search. To 572 int stop_level /* How far down the tree to search. To
576 stop at leaf level - set to 573 stop at leaf level - set to
577 DISK_LEAF_NODE_LEVEL */ 574 DISK_LEAF_NODE_LEVEL */
578 ) 575 )
579{ 576{
580 b_blocknr_t n_block_number; 577 b_blocknr_t block_number;
581 int expected_level; 578 int expected_level;
582 struct buffer_head *bh; 579 struct buffer_head *bh;
583 struct path_element *last_element; 580 struct path_element *last_element;
584 int n_node_level, n_retval; 581 int node_level, retval;
585 int right_neighbor_of_leaf_node; 582 int right_neighbor_of_leaf_node;
586 int fs_gen; 583 int fs_gen;
587 struct buffer_head *reada_bh[SEARCH_BY_KEY_READA]; 584 struct buffer_head *reada_bh[SEARCH_BY_KEY_READA];
@@ -589,7 +586,7 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s
589 int reada_count = 0; 586 int reada_count = 0;
590 587
591#ifdef CONFIG_REISERFS_CHECK 588#ifdef CONFIG_REISERFS_CHECK
592 int n_repeat_counter = 0; 589 int repeat_counter = 0;
593#endif 590#endif
594 591
595 PROC_INFO_INC(sb, search_by_key); 592 PROC_INFO_INC(sb, search_by_key);
@@ -605,16 +602,16 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s
605 /* With each iteration of this loop we search through the items in the 602 /* With each iteration of this loop we search through the items in the
606 current node, and calculate the next current node(next path element) 603 current node, and calculate the next current node(next path element)
607 for the next iteration of this loop.. */ 604 for the next iteration of this loop.. */
608 n_block_number = SB_ROOT_BLOCK(sb); 605 block_number = SB_ROOT_BLOCK(sb);
609 expected_level = -1; 606 expected_level = -1;
610 while (1) { 607 while (1) {
611 608
612#ifdef CONFIG_REISERFS_CHECK 609#ifdef CONFIG_REISERFS_CHECK
613 if (!(++n_repeat_counter % 50000)) 610 if (!(++repeat_counter % 50000))
614 reiserfs_warning(sb, "PAP-5100", 611 reiserfs_warning(sb, "PAP-5100",
615 "%s: there were %d iterations of " 612 "%s: there were %d iterations of "
616 "while loop looking for key %K", 613 "while loop looking for key %K",
617 current->comm, n_repeat_counter, 614 current->comm, repeat_counter,
618 key); 615 key);
619#endif 616#endif
620 617
@@ -627,7 +624,7 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s
627 /* Read the next tree node, and set the last element in the path to 624 /* Read the next tree node, and set the last element in the path to
628 have a pointer to it. */ 625 have a pointer to it. */
629 if ((bh = last_element->pe_buffer = 626 if ((bh = last_element->pe_buffer =
630 sb_getblk(sb, n_block_number))) { 627 sb_getblk(sb, block_number))) {
631 if (!buffer_uptodate(bh) && reada_count > 1) 628 if (!buffer_uptodate(bh) && reada_count > 1)
632 search_by_key_reada(sb, reada_bh, 629 search_by_key_reada(sb, reada_bh,
633 reada_blocks, reada_count); 630 reada_blocks, reada_count);
@@ -661,7 +658,7 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s
661 658
662 /* Get the root block number so that we can repeat the search 659 /* Get the root block number so that we can repeat the search
663 starting from the root. */ 660 starting from the root. */
664 n_block_number = SB_ROOT_BLOCK(sb); 661 block_number = SB_ROOT_BLOCK(sb);
665 expected_level = -1; 662 expected_level = -1;
666 right_neighbor_of_leaf_node = 0; 663 right_neighbor_of_leaf_node = 0;
667 664
@@ -694,26 +691,26 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s
694 } 691 }
695 692
696 /* ok, we have acquired next formatted node in the tree */ 693 /* ok, we have acquired next formatted node in the tree */
697 n_node_level = B_LEVEL(bh); 694 node_level = B_LEVEL(bh);
698 695
699 PROC_INFO_BH_STAT(sb, bh, n_node_level - 1); 696 PROC_INFO_BH_STAT(sb, bh, node_level - 1);
700 697
701 RFALSE(n_node_level < n_stop_level, 698 RFALSE(node_level < stop_level,
702 "vs-5152: tree level (%d) is less than stop level (%d)", 699 "vs-5152: tree level (%d) is less than stop level (%d)",
703 n_node_level, n_stop_level); 700 node_level, stop_level);
704 701
705 n_retval = bin_search(key, B_N_PITEM_HEAD(bh, 0), 702 retval = bin_search(key, B_N_PITEM_HEAD(bh, 0),
706 B_NR_ITEMS(bh), 703 B_NR_ITEMS(bh),
707 (n_node_level == 704 (node_level ==
708 DISK_LEAF_NODE_LEVEL) ? IH_SIZE : 705 DISK_LEAF_NODE_LEVEL) ? IH_SIZE :
709 KEY_SIZE, 706 KEY_SIZE,
710 &(last_element->pe_position)); 707 &(last_element->pe_position));
711 if (n_node_level == n_stop_level) { 708 if (node_level == stop_level) {
712 return n_retval; 709 return retval;
713 } 710 }
714 711
715 /* we are not in the stop level */ 712 /* we are not in the stop level */
716 if (n_retval == ITEM_FOUND) 713 if (retval == ITEM_FOUND)
717 /* item has been found, so we choose the pointer which is to the right of the found one */ 714 /* item has been found, so we choose the pointer which is to the right of the found one */
718 last_element->pe_position++; 715 last_element->pe_position++;
719 716
@@ -724,12 +721,12 @@ int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to s
724 /* So we have chosen a position in the current node which is 721 /* So we have chosen a position in the current node which is
725 an internal node. Now we calculate child block number by 722 an internal node. Now we calculate child block number by
726 position in the node. */ 723 position in the node. */
727 n_block_number = 724 block_number =
728 B_N_CHILD_NUM(bh, last_element->pe_position); 725 B_N_CHILD_NUM(bh, last_element->pe_position);
729 726
730 /* if we are going to read leaf nodes, try for read ahead as well */ 727 /* if we are going to read leaf nodes, try for read ahead as well */
731 if ((search_path->reada & PATH_READA) && 728 if ((search_path->reada & PATH_READA) &&
732 n_node_level == DISK_LEAF_NODE_LEVEL + 1) { 729 node_level == DISK_LEAF_NODE_LEVEL + 1) {
733 int pos = last_element->pe_position; 730 int pos = last_element->pe_position;
734 int limit = B_NR_ITEMS(bh); 731 int limit = B_NR_ITEMS(bh);
735 struct reiserfs_key *le_key; 732 struct reiserfs_key *le_key;
@@ -781,7 +778,7 @@ int search_for_position_by_key(struct super_block *sb, /* Pointer to the super b
781 ) 778 )
782{ 779{
783 struct item_head *p_le_ih; /* pointer to on-disk structure */ 780 struct item_head *p_le_ih; /* pointer to on-disk structure */
784 int n_blk_size; 781 int blk_size;
785 loff_t item_offset, offset; 782 loff_t item_offset, offset;
786 struct reiserfs_dir_entry de; 783 struct reiserfs_dir_entry de;
787 int retval; 784 int retval;
@@ -816,7 +813,7 @@ int search_for_position_by_key(struct super_block *sb, /* Pointer to the super b
816 p_le_ih = 813 p_le_ih =
817 B_N_PITEM_HEAD(PATH_PLAST_BUFFER(search_path), 814 B_N_PITEM_HEAD(PATH_PLAST_BUFFER(search_path),
818 --PATH_LAST_POSITION(search_path)); 815 --PATH_LAST_POSITION(search_path));
819 n_blk_size = sb->s_blocksize; 816 blk_size = sb->s_blocksize;
820 817
821 if (comp_short_keys(&(p_le_ih->ih_key), p_cpu_key)) { 818 if (comp_short_keys(&(p_le_ih->ih_key), p_cpu_key)) {
822 return FILE_NOT_FOUND; 819 return FILE_NOT_FOUND;
@@ -828,10 +825,10 @@ int search_for_position_by_key(struct super_block *sb, /* Pointer to the super b
828 825
829 /* Needed byte is contained in the item pointed to by the path. */ 826 /* Needed byte is contained in the item pointed to by the path. */
830 if (item_offset <= offset && 827 if (item_offset <= offset &&
831 item_offset + op_bytes_number(p_le_ih, n_blk_size) > offset) { 828 item_offset + op_bytes_number(p_le_ih, blk_size) > offset) {
832 pos_in_item(search_path) = offset - item_offset; 829 pos_in_item(search_path) = offset - item_offset;
833 if (is_indirect_le_ih(p_le_ih)) { 830 if (is_indirect_le_ih(p_le_ih)) {
834 pos_in_item(search_path) /= n_blk_size; 831 pos_in_item(search_path) /= blk_size;
835 } 832 }
836 return POSITION_FOUND; 833 return POSITION_FOUND;
837 } 834 }
@@ -891,7 +888,7 @@ static inline int prepare_for_direct_item(struct treepath *path,
891 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_6) { 888 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_6) {
892 // 889 //
893 round_len = ROUND_UP(new_file_length); 890 round_len = ROUND_UP(new_file_length);
894 /* this was n_new_file_length < le_ih ... */ 891 /* this was new_file_length < le_ih ... */
895 if (round_len < le_ih_k_offset(le_ih)) { 892 if (round_len < le_ih_k_offset(le_ih)) {
896 *cut_size = -(IH_SIZE + ih_item_len(le_ih)); 893 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
897 return M_DELETE; /* Delete this item. */ 894 return M_DELETE; /* Delete this item. */
@@ -953,7 +950,7 @@ static inline int prepare_for_direntry_item(struct treepath *path,
953 This function returns a determination of what balance mode the calling function should employ. */ 950 This function returns a determination of what balance mode the calling function should employ. */
954static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, struct inode *inode, struct treepath *path, const struct cpu_key *item_key, int *removed, /* Number of unformatted nodes which were removed 951static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, struct inode *inode, struct treepath *path, const struct cpu_key *item_key, int *removed, /* Number of unformatted nodes which were removed
955 from end of the file. */ 952 from end of the file. */
956 int *cut_size, unsigned long long n_new_file_length /* MAX_KEY_OFFSET in case of delete. */ 953 int *cut_size, unsigned long long new_file_length /* MAX_KEY_OFFSET in case of delete. */
957 ) 954 )
958{ 955{
959 struct super_block *sb = inode->i_sb; 956 struct super_block *sb = inode->i_sb;
@@ -965,7 +962,7 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
965 /* Stat_data item. */ 962 /* Stat_data item. */
966 if (is_statdata_le_ih(p_le_ih)) { 963 if (is_statdata_le_ih(p_le_ih)) {
967 964
968 RFALSE(n_new_file_length != max_reiserfs_offset(inode), 965 RFALSE(new_file_length != max_reiserfs_offset(inode),
969 "PAP-5210: mode must be M_DELETE"); 966 "PAP-5210: mode must be M_DELETE");
970 967
971 *cut_size = -(IH_SIZE + ih_item_len(p_le_ih)); 968 *cut_size = -(IH_SIZE + ih_item_len(p_le_ih));
@@ -975,13 +972,13 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
975 /* Directory item. */ 972 /* Directory item. */
976 if (is_direntry_le_ih(p_le_ih)) 973 if (is_direntry_le_ih(p_le_ih))
977 return prepare_for_direntry_item(path, p_le_ih, inode, 974 return prepare_for_direntry_item(path, p_le_ih, inode,
978 n_new_file_length, 975 new_file_length,
979 cut_size); 976 cut_size);
980 977
981 /* Direct item. */ 978 /* Direct item. */
982 if (is_direct_le_ih(p_le_ih)) 979 if (is_direct_le_ih(p_le_ih))
983 return prepare_for_direct_item(path, p_le_ih, inode, 980 return prepare_for_direct_item(path, p_le_ih, inode,
984 n_new_file_length, cut_size); 981 new_file_length, cut_size);
985 982
986 /* Case of an indirect item. */ 983 /* Case of an indirect item. */
987 { 984 {
@@ -992,10 +989,10 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
992 int result = M_CUT; 989 int result = M_CUT;
993 int pos = 0; 990 int pos = 0;
994 991
995 if ( n_new_file_length == max_reiserfs_offset (inode) ) { 992 if ( new_file_length == max_reiserfs_offset (inode) ) {
996 /* prepare_for_delete_or_cut() is called by 993 /* prepare_for_delete_or_cut() is called by
997 * reiserfs_delete_item() */ 994 * reiserfs_delete_item() */
998 n_new_file_length = 0; 995 new_file_length = 0;
999 delete = 1; 996 delete = 1;
1000 } 997 }
1001 998
@@ -1006,7 +1003,7 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
1006 copy_item_head(&s_ih, PATH_PITEM_HEAD(path)); 1003 copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
1007 pos = I_UNFM_NUM(&s_ih); 1004 pos = I_UNFM_NUM(&s_ih);
1008 1005
1009 while (le_ih_k_offset (&s_ih) + (pos - 1) * blk_size > n_new_file_length) { 1006 while (le_ih_k_offset (&s_ih) + (pos - 1) * blk_size > new_file_length) {
1010 __le32 *unfm; 1007 __le32 *unfm;
1011 __u32 block; 1008 __u32 block;
1012 1009
@@ -1062,35 +1059,34 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
1062} 1059}
1063 1060
1064/* Calculate number of bytes which will be deleted or cut during balance */ 1061/* Calculate number of bytes which will be deleted or cut during balance */
1065static int calc_deleted_bytes_number(struct tree_balance *tb, char c_mode) 1062static int calc_deleted_bytes_number(struct tree_balance *tb, char mode)
1066{ 1063{
1067 int n_del_size; 1064 int del_size;
1068 struct item_head *p_le_ih = PATH_PITEM_HEAD(tb->tb_path); 1065 struct item_head *p_le_ih = PATH_PITEM_HEAD(tb->tb_path);
1069 1066
1070 if (is_statdata_le_ih(p_le_ih)) 1067 if (is_statdata_le_ih(p_le_ih))
1071 return 0; 1068 return 0;
1072 1069
1073 n_del_size = 1070 del_size =
1074 (c_mode == 1071 (mode ==
1075 M_DELETE) ? ih_item_len(p_le_ih) : -tb->insert_size[0]; 1072 M_DELETE) ? ih_item_len(p_le_ih) : -tb->insert_size[0];
1076 if (is_direntry_le_ih(p_le_ih)) { 1073 if (is_direntry_le_ih(p_le_ih)) {
1077 // return EMPTY_DIR_SIZE; /* We delete emty directoris only. */ 1074 /* return EMPTY_DIR_SIZE; We delete emty directoris only.
1078 // we can't use EMPTY_DIR_SIZE, as old format dirs have a different 1075 * we can't use EMPTY_DIR_SIZE, as old format dirs have a different
1079 // empty size. ick. FIXME, is this right? 1076 * empty size. ick. FIXME, is this right? */
1080 // 1077 return del_size;
1081 return n_del_size;
1082 } 1078 }
1083 1079
1084 if (is_indirect_le_ih(p_le_ih)) 1080 if (is_indirect_le_ih(p_le_ih))
1085 n_del_size = (n_del_size / UNFM_P_SIZE) * 1081 del_size = (del_size / UNFM_P_SIZE) *
1086 (PATH_PLAST_BUFFER(tb->tb_path)->b_size); 1082 (PATH_PLAST_BUFFER(tb->tb_path)->b_size);
1087 return n_del_size; 1083 return del_size;
1088} 1084}
1089 1085
1090static void init_tb_struct(struct reiserfs_transaction_handle *th, 1086static void init_tb_struct(struct reiserfs_transaction_handle *th,
1091 struct tree_balance *tb, 1087 struct tree_balance *tb,
1092 struct super_block *sb, 1088 struct super_block *sb,
1093 struct treepath *path, int n_size) 1089 struct treepath *path, int size)
1094{ 1090{
1095 1091
1096 BUG_ON(!th->t_trans_id); 1092 BUG_ON(!th->t_trans_id);
@@ -1101,7 +1097,7 @@ static void init_tb_struct(struct reiserfs_transaction_handle *th,
1101 tb->tb_path = path; 1097 tb->tb_path = path;
1102 PATH_OFFSET_PBUFFER(path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL; 1098 PATH_OFFSET_PBUFFER(path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL;
1103 PATH_OFFSET_POSITION(path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0; 1099 PATH_OFFSET_POSITION(path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0;
1104 tb->insert_size[0] = n_size; 1100 tb->insert_size[0] = size;
1105} 1101}
1106 1102
1107void padd_item(char *item, int total_length, int length) 1103void padd_item(char *item, int total_length, int length)
@@ -1156,11 +1152,11 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
1156 struct item_head s_ih; 1152 struct item_head s_ih;
1157 struct item_head *q_ih; 1153 struct item_head *q_ih;
1158 int quota_cut_bytes; 1154 int quota_cut_bytes;
1159 int n_ret_value, n_del_size, n_removed; 1155 int ret_value, del_size, removed;
1160 1156
1161#ifdef CONFIG_REISERFS_CHECK 1157#ifdef CONFIG_REISERFS_CHECK
1162 char c_mode; 1158 char mode;
1163 int n_iter = 0; 1159 int iter = 0;
1164#endif 1160#endif
1165 1161
1166 BUG_ON(!th->t_trans_id); 1162 BUG_ON(!th->t_trans_id);
@@ -1169,34 +1165,34 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
1169 0 /*size is unknown */ ); 1165 0 /*size is unknown */ );
1170 1166
1171 while (1) { 1167 while (1) {
1172 n_removed = 0; 1168 removed = 0;
1173 1169
1174#ifdef CONFIG_REISERFS_CHECK 1170#ifdef CONFIG_REISERFS_CHECK
1175 n_iter++; 1171 iter++;
1176 c_mode = 1172 mode =
1177#endif 1173#endif
1178 prepare_for_delete_or_cut(th, inode, path, 1174 prepare_for_delete_or_cut(th, inode, path,
1179 item_key, &n_removed, 1175 item_key, &removed,
1180 &n_del_size, 1176 &del_size,
1181 max_reiserfs_offset(inode)); 1177 max_reiserfs_offset(inode));
1182 1178
1183 RFALSE(c_mode != M_DELETE, "PAP-5320: mode must be M_DELETE"); 1179 RFALSE(mode != M_DELETE, "PAP-5320: mode must be M_DELETE");
1184 1180
1185 copy_item_head(&s_ih, PATH_PITEM_HEAD(path)); 1181 copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
1186 s_del_balance.insert_size[0] = n_del_size; 1182 s_del_balance.insert_size[0] = del_size;
1187 1183
1188 n_ret_value = fix_nodes(M_DELETE, &s_del_balance, NULL, NULL); 1184 ret_value = fix_nodes(M_DELETE, &s_del_balance, NULL, NULL);
1189 if (n_ret_value != REPEAT_SEARCH) 1185 if (ret_value != REPEAT_SEARCH)
1190 break; 1186 break;
1191 1187
1192 PROC_INFO_INC(sb, delete_item_restarted); 1188 PROC_INFO_INC(sb, delete_item_restarted);
1193 1189
1194 // file system changed, repeat search 1190 // file system changed, repeat search
1195 n_ret_value = 1191 ret_value =
1196 search_for_position_by_key(sb, item_key, path); 1192 search_for_position_by_key(sb, item_key, path);
1197 if (n_ret_value == IO_ERROR) 1193 if (ret_value == IO_ERROR)
1198 break; 1194 break;
1199 if (n_ret_value == FILE_NOT_FOUND) { 1195 if (ret_value == FILE_NOT_FOUND) {
1200 reiserfs_warning(sb, "vs-5340", 1196 reiserfs_warning(sb, "vs-5340",
1201 "no items of the file %K found", 1197 "no items of the file %K found",
1202 item_key); 1198 item_key);
@@ -1204,12 +1200,12 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
1204 } 1200 }
1205 } /* while (1) */ 1201 } /* while (1) */
1206 1202
1207 if (n_ret_value != CARRY_ON) { 1203 if (ret_value != CARRY_ON) {
1208 unfix_nodes(&s_del_balance); 1204 unfix_nodes(&s_del_balance);
1209 return 0; 1205 return 0;
1210 } 1206 }
1211 // reiserfs_delete_item returns item length when success 1207 // reiserfs_delete_item returns item length when success
1212 n_ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE); 1208 ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE);
1213 q_ih = get_ih(path); 1209 q_ih = get_ih(path);
1214 quota_cut_bytes = ih_item_len(q_ih); 1210 quota_cut_bytes = ih_item_len(q_ih);
1215 1211
@@ -1255,7 +1251,7 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
1255 off = ((le_ih_k_offset(&s_ih) - 1) & (PAGE_CACHE_SIZE - 1)); 1251 off = ((le_ih_k_offset(&s_ih) - 1) & (PAGE_CACHE_SIZE - 1));
1256 memcpy(data + off, 1252 memcpy(data + off,
1257 B_I_PITEM(PATH_PLAST_BUFFER(path), &s_ih), 1253 B_I_PITEM(PATH_PLAST_BUFFER(path), &s_ih),
1258 n_ret_value); 1254 ret_value);
1259 kunmap_atomic(data, KM_USER0); 1255 kunmap_atomic(data, KM_USER0);
1260 } 1256 }
1261 /* Perform balancing after all resources have been collected at once. */ 1257 /* Perform balancing after all resources have been collected at once. */
@@ -1269,7 +1265,7 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
1269 DQUOT_FREE_SPACE_NODIRTY(inode, quota_cut_bytes); 1265 DQUOT_FREE_SPACE_NODIRTY(inode, quota_cut_bytes);
1270 1266
1271 /* Return deleted body length */ 1267 /* Return deleted body length */
1272 return n_ret_value; 1268 return ret_value;
1273} 1269}
1274 1270
1275/* Summary Of Mechanisms For Handling Collisions Between Processes: 1271/* Summary Of Mechanisms For Handling Collisions Between Processes:
@@ -1432,13 +1428,13 @@ static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th,
1432 struct page *page, 1428 struct page *page,
1433 struct treepath *path, 1429 struct treepath *path,
1434 const struct cpu_key *item_key, 1430 const struct cpu_key *item_key,
1435 loff_t n_new_file_size, char *mode) 1431 loff_t new_file_size, char *mode)
1436{ 1432{
1437 struct super_block *sb = inode->i_sb; 1433 struct super_block *sb = inode->i_sb;
1438 int n_block_size = sb->s_blocksize; 1434 int block_size = sb->s_blocksize;
1439 int cut_bytes; 1435 int cut_bytes;
1440 BUG_ON(!th->t_trans_id); 1436 BUG_ON(!th->t_trans_id);
1441 BUG_ON(n_new_file_size != inode->i_size); 1437 BUG_ON(new_file_size != inode->i_size);
1442 1438
1443 /* the page being sent in could be NULL if there was an i/o error 1439 /* the page being sent in could be NULL if there was an i/o error
1444 ** reading in the last block. The user will hit problems trying to 1440 ** reading in the last block. The user will hit problems trying to
@@ -1450,15 +1446,15 @@ static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th,
1450 /* leave tail in an unformatted node */ 1446 /* leave tail in an unformatted node */
1451 *mode = M_SKIP_BALANCING; 1447 *mode = M_SKIP_BALANCING;
1452 cut_bytes = 1448 cut_bytes =
1453 n_block_size - (n_new_file_size & (n_block_size - 1)); 1449 block_size - (new_file_size & (block_size - 1));
1454 pathrelse(path); 1450 pathrelse(path);
1455 return cut_bytes; 1451 return cut_bytes;
1456 } 1452 }
1457 /* Perform the conversion to a direct_item. */ 1453 /* Perform the conversion to a direct_item. */
1458 /* return indirect_to_direct(inode, path, item_key, 1454 /* return indirect_to_direct(inode, path, item_key,
1459 n_new_file_size, mode); */ 1455 new_file_size, mode); */
1460 return indirect2direct(th, inode, page, path, item_key, 1456 return indirect2direct(th, inode, page, path, item_key,
1461 n_new_file_size, mode); 1457 new_file_size, mode);
1462} 1458}
1463 1459
1464/* we did indirect_to_direct conversion. And we have inserted direct 1460/* we did indirect_to_direct conversion. And we have inserted direct
@@ -1512,7 +1508,7 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1512 struct treepath *path, 1508 struct treepath *path,
1513 struct cpu_key *item_key, 1509 struct cpu_key *item_key,
1514 struct inode *inode, 1510 struct inode *inode,
1515 struct page *page, loff_t n_new_file_size) 1511 struct page *page, loff_t new_file_size)
1516{ 1512{
1517 struct super_block *sb = inode->i_sb; 1513 struct super_block *sb = inode->i_sb;
1518 /* Every function which is going to call do_balance must first 1514 /* Every function which is going to call do_balance must first
@@ -1521,10 +1517,10 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1521 After that we can make tree balancing. */ 1517 After that we can make tree balancing. */
1522 struct tree_balance s_cut_balance; 1518 struct tree_balance s_cut_balance;
1523 struct item_head *p_le_ih; 1519 struct item_head *p_le_ih;
1524 int n_cut_size = 0, /* Amount to be cut. */ 1520 int cut_size = 0, /* Amount to be cut. */
1525 n_ret_value = CARRY_ON, n_removed = 0, /* Number of the removed unformatted nodes. */ 1521 ret_value = CARRY_ON, removed = 0, /* Number of the removed unformatted nodes. */
1526 n_is_inode_locked = 0; 1522 is_inode_locked = 0;
1527 char c_mode; /* Mode of the balance. */ 1523 char mode; /* Mode of the balance. */
1528 int retval2 = -1; 1524 int retval2 = -1;
1529 int quota_cut_bytes; 1525 int quota_cut_bytes;
1530 loff_t tail_pos = 0; 1526 loff_t tail_pos = 0;
@@ -1532,7 +1528,7 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1532 BUG_ON(!th->t_trans_id); 1528 BUG_ON(!th->t_trans_id);
1533 1529
1534 init_tb_struct(th, &s_cut_balance, inode->i_sb, path, 1530 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
1535 n_cut_size); 1531 cut_size);
1536 1532
1537 /* Repeat this loop until we either cut the item without needing 1533 /* Repeat this loop until we either cut the item without needing
1538 to balance, or we fix_nodes without schedule occurring */ 1534 to balance, or we fix_nodes without schedule occurring */
@@ -1542,30 +1538,30 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1542 free unformatted nodes which are pointed to by the cut 1538 free unformatted nodes which are pointed to by the cut
1543 pointers. */ 1539 pointers. */
1544 1540
1545 c_mode = 1541 mode =
1546 prepare_for_delete_or_cut(th, inode, path, 1542 prepare_for_delete_or_cut(th, inode, path,
1547 item_key, &n_removed, 1543 item_key, &removed,
1548 &n_cut_size, n_new_file_size); 1544 &cut_size, new_file_size);
1549 if (c_mode == M_CONVERT) { 1545 if (mode == M_CONVERT) {
1550 /* convert last unformatted node to direct item or leave 1546 /* convert last unformatted node to direct item or leave
1551 tail in the unformatted node */ 1547 tail in the unformatted node */
1552 RFALSE(n_ret_value != CARRY_ON, 1548 RFALSE(ret_value != CARRY_ON,
1553 "PAP-5570: can not convert twice"); 1549 "PAP-5570: can not convert twice");
1554 1550
1555 n_ret_value = 1551 ret_value =
1556 maybe_indirect_to_direct(th, inode, page, 1552 maybe_indirect_to_direct(th, inode, page,
1557 path, item_key, 1553 path, item_key,
1558 n_new_file_size, &c_mode); 1554 new_file_size, &mode);
1559 if (c_mode == M_SKIP_BALANCING) 1555 if (mode == M_SKIP_BALANCING)
1560 /* tail has been left in the unformatted node */ 1556 /* tail has been left in the unformatted node */
1561 return n_ret_value; 1557 return ret_value;
1562 1558
1563 n_is_inode_locked = 1; 1559 is_inode_locked = 1;
1564 1560
1565 /* removing of last unformatted node will change value we 1561 /* removing of last unformatted node will change value we
1566 have to return to truncate. Save it */ 1562 have to return to truncate. Save it */
1567 retval2 = n_ret_value; 1563 retval2 = ret_value;
1568 /*retval2 = sb->s_blocksize - (n_new_file_size & (sb->s_blocksize - 1)); */ 1564 /*retval2 = sb->s_blocksize - (new_file_size & (sb->s_blocksize - 1)); */
1569 1565
1570 /* So, we have performed the first part of the conversion: 1566 /* So, we have performed the first part of the conversion:
1571 inserting the new direct item. Now we are removing the 1567 inserting the new direct item. Now we are removing the
@@ -1573,10 +1569,10 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1573 it. */ 1569 it. */
1574 set_cpu_key_k_type(item_key, TYPE_INDIRECT); 1570 set_cpu_key_k_type(item_key, TYPE_INDIRECT);
1575 item_key->key_length = 4; 1571 item_key->key_length = 4;
1576 n_new_file_size -= 1572 new_file_size -=
1577 (n_new_file_size & (sb->s_blocksize - 1)); 1573 (new_file_size & (sb->s_blocksize - 1));
1578 tail_pos = n_new_file_size; 1574 tail_pos = new_file_size;
1579 set_cpu_key_k_offset(item_key, n_new_file_size + 1); 1575 set_cpu_key_k_offset(item_key, new_file_size + 1);
1580 if (search_for_position_by_key 1576 if (search_for_position_by_key
1581 (sb, item_key, 1577 (sb, item_key,
1582 path) == POSITION_NOT_FOUND) { 1578 path) == POSITION_NOT_FOUND) {
@@ -1589,38 +1585,38 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1589 } 1585 }
1590 continue; 1586 continue;
1591 } 1587 }
1592 if (n_cut_size == 0) { 1588 if (cut_size == 0) {
1593 pathrelse(path); 1589 pathrelse(path);
1594 return 0; 1590 return 0;
1595 } 1591 }
1596 1592
1597 s_cut_balance.insert_size[0] = n_cut_size; 1593 s_cut_balance.insert_size[0] = cut_size;
1598 1594
1599 n_ret_value = fix_nodes(c_mode, &s_cut_balance, NULL, NULL); 1595 ret_value = fix_nodes(mode, &s_cut_balance, NULL, NULL);
1600 if (n_ret_value != REPEAT_SEARCH) 1596 if (ret_value != REPEAT_SEARCH)
1601 break; 1597 break;
1602 1598
1603 PROC_INFO_INC(sb, cut_from_item_restarted); 1599 PROC_INFO_INC(sb, cut_from_item_restarted);
1604 1600
1605 n_ret_value = 1601 ret_value =
1606 search_for_position_by_key(sb, item_key, path); 1602 search_for_position_by_key(sb, item_key, path);
1607 if (n_ret_value == POSITION_FOUND) 1603 if (ret_value == POSITION_FOUND)
1608 continue; 1604 continue;
1609 1605
1610 reiserfs_warning(sb, "PAP-5610", "item %K not found", 1606 reiserfs_warning(sb, "PAP-5610", "item %K not found",
1611 item_key); 1607 item_key);
1612 unfix_nodes(&s_cut_balance); 1608 unfix_nodes(&s_cut_balance);
1613 return (n_ret_value == IO_ERROR) ? -EIO : -ENOENT; 1609 return (ret_value == IO_ERROR) ? -EIO : -ENOENT;
1614 } /* while */ 1610 } /* while */
1615 1611
1616 // check fix_nodes results (IO_ERROR or NO_DISK_SPACE) 1612 // check fix_nodes results (IO_ERROR or NO_DISK_SPACE)
1617 if (n_ret_value != CARRY_ON) { 1613 if (ret_value != CARRY_ON) {
1618 if (n_is_inode_locked) { 1614 if (is_inode_locked) {
1619 // FIXME: this seems to be not needed: we are always able 1615 // FIXME: this seems to be not needed: we are always able
1620 // to cut item 1616 // to cut item
1621 indirect_to_direct_roll_back(th, inode, path); 1617 indirect_to_direct_roll_back(th, inode, path);
1622 } 1618 }
1623 if (n_ret_value == NO_DISK_SPACE) 1619 if (ret_value == NO_DISK_SPACE)
1624 reiserfs_warning(sb, "reiserfs-5092", 1620 reiserfs_warning(sb, "reiserfs-5092",
1625 "NO_DISK_SPACE"); 1621 "NO_DISK_SPACE");
1626 unfix_nodes(&s_cut_balance); 1622 unfix_nodes(&s_cut_balance);
@@ -1629,24 +1625,24 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1629 1625
1630 /* go ahead and perform balancing */ 1626 /* go ahead and perform balancing */
1631 1627
1632 RFALSE(c_mode == M_PASTE || c_mode == M_INSERT, "invalid mode"); 1628 RFALSE(mode == M_PASTE || mode == M_INSERT, "invalid mode");
1633 1629
1634 /* Calculate number of bytes that need to be cut from the item. */ 1630 /* Calculate number of bytes that need to be cut from the item. */
1635 quota_cut_bytes = 1631 quota_cut_bytes =
1636 (c_mode == 1632 (mode ==
1637 M_DELETE) ? ih_item_len(get_ih(path)) : -s_cut_balance. 1633 M_DELETE) ? ih_item_len(get_ih(path)) : -s_cut_balance.
1638 insert_size[0]; 1634 insert_size[0];
1639 if (retval2 == -1) 1635 if (retval2 == -1)
1640 n_ret_value = calc_deleted_bytes_number(&s_cut_balance, c_mode); 1636 ret_value = calc_deleted_bytes_number(&s_cut_balance, mode);
1641 else 1637 else
1642 n_ret_value = retval2; 1638 ret_value = retval2;
1643 1639
1644 /* For direct items, we only change the quota when deleting the last 1640 /* For direct items, we only change the quota when deleting the last
1645 ** item. 1641 ** item.
1646 */ 1642 */
1647 p_le_ih = PATH_PITEM_HEAD(s_cut_balance.tb_path); 1643 p_le_ih = PATH_PITEM_HEAD(s_cut_balance.tb_path);
1648 if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(p_le_ih)) { 1644 if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(p_le_ih)) {
1649 if (c_mode == M_DELETE && 1645 if (mode == M_DELETE &&
1650 (le_ih_k_offset(p_le_ih) & (sb->s_blocksize - 1)) == 1646 (le_ih_k_offset(p_le_ih) & (sb->s_blocksize - 1)) ==
1651 1) { 1647 1) {
1652 // FIXME: this is to keep 3.5 happy 1648 // FIXME: this is to keep 3.5 happy
@@ -1657,7 +1653,7 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1657 } 1653 }
1658 } 1654 }
1659#ifdef CONFIG_REISERFS_CHECK 1655#ifdef CONFIG_REISERFS_CHECK
1660 if (n_is_inode_locked) { 1656 if (is_inode_locked) {
1661 struct item_head *le_ih = 1657 struct item_head *le_ih =
1662 PATH_PITEM_HEAD(s_cut_balance.tb_path); 1658 PATH_PITEM_HEAD(s_cut_balance.tb_path);
1663 /* we are going to complete indirect2direct conversion. Make 1659 /* we are going to complete indirect2direct conversion. Make
@@ -1667,13 +1663,13 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1667 reiserfs_panic(sb, "vs-5652", 1663 reiserfs_panic(sb, "vs-5652",
1668 "item must be indirect %h", le_ih); 1664 "item must be indirect %h", le_ih);
1669 1665
1670 if (c_mode == M_DELETE && ih_item_len(le_ih) != UNFM_P_SIZE) 1666 if (mode == M_DELETE && ih_item_len(le_ih) != UNFM_P_SIZE)
1671 reiserfs_panic(sb, "vs-5653", "completing " 1667 reiserfs_panic(sb, "vs-5653", "completing "
1672 "indirect2direct conversion indirect " 1668 "indirect2direct conversion indirect "
1673 "item %h being deleted must be of " 1669 "item %h being deleted must be of "
1674 "4 byte long", le_ih); 1670 "4 byte long", le_ih);
1675 1671
1676 if (c_mode == M_CUT 1672 if (mode == M_CUT
1677 && s_cut_balance.insert_size[0] != -UNFM_P_SIZE) { 1673 && s_cut_balance.insert_size[0] != -UNFM_P_SIZE) {
1678 reiserfs_panic(sb, "vs-5654", "can not complete " 1674 reiserfs_panic(sb, "vs-5654", "can not complete "
1679 "indirect2direct conversion of %h " 1675 "indirect2direct conversion of %h "
@@ -1685,8 +1681,8 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1685 } 1681 }
1686#endif 1682#endif
1687 1683
1688 do_balance(&s_cut_balance, NULL, NULL, c_mode); 1684 do_balance(&s_cut_balance, NULL, NULL, mode);
1689 if (n_is_inode_locked) { 1685 if (is_inode_locked) {
1690 /* we've done an indirect->direct conversion. when the data block 1686 /* we've done an indirect->direct conversion. when the data block
1691 ** was freed, it was removed from the list of blocks that must 1687 ** was freed, it was removed from the list of blocks that must
1692 ** be flushed before the transaction commits, make sure to 1688 ** be flushed before the transaction commits, make sure to
@@ -1701,7 +1697,7 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1701 quota_cut_bytes, inode->i_uid, '?'); 1697 quota_cut_bytes, inode->i_uid, '?');
1702#endif 1698#endif
1703 DQUOT_FREE_SPACE_NODIRTY(inode, quota_cut_bytes); 1699 DQUOT_FREE_SPACE_NODIRTY(inode, quota_cut_bytes);
1704 return n_ret_value; 1700 return ret_value;
1705} 1701}
1706 1702
1707static void truncate_directory(struct reiserfs_transaction_handle *th, 1703static void truncate_directory(struct reiserfs_transaction_handle *th,
@@ -1733,9 +1729,9 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
1733 INITIALIZE_PATH(s_search_path); /* Path to the current object item. */ 1729 INITIALIZE_PATH(s_search_path); /* Path to the current object item. */
1734 struct item_head *p_le_ih; /* Pointer to an item header. */ 1730 struct item_head *p_le_ih; /* Pointer to an item header. */
1735 struct cpu_key s_item_key; /* Key to search for a previous file item. */ 1731 struct cpu_key s_item_key; /* Key to search for a previous file item. */
1736 loff_t n_file_size, /* Old file size. */ 1732 loff_t file_size, /* Old file size. */
1737 n_new_file_size; /* New file size. */ 1733 new_file_size; /* New file size. */
1738 int n_deleted; /* Number of deleted or truncated bytes. */ 1734 int deleted; /* Number of deleted or truncated bytes. */
1739 int retval; 1735 int retval;
1740 int err = 0; 1736 int err = 0;
1741 1737
@@ -1752,7 +1748,7 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
1752 } 1748 }
1753 1749
1754 /* Get new file size. */ 1750 /* Get new file size. */
1755 n_new_file_size = inode->i_size; 1751 new_file_size = inode->i_size;
1756 1752
1757 // FIXME: note, that key type is unimportant here 1753 // FIXME: note, that key type is unimportant here
1758 make_cpu_key(&s_item_key, inode, max_reiserfs_offset(inode), 1754 make_cpu_key(&s_item_key, inode, max_reiserfs_offset(inode),
@@ -1782,7 +1778,7 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
1782 /* Get real file size (total length of all file items) */ 1778 /* Get real file size (total length of all file items) */
1783 p_le_ih = PATH_PITEM_HEAD(&s_search_path); 1779 p_le_ih = PATH_PITEM_HEAD(&s_search_path);
1784 if (is_statdata_le_ih(p_le_ih)) 1780 if (is_statdata_le_ih(p_le_ih))
1785 n_file_size = 0; 1781 file_size = 0;
1786 else { 1782 else {
1787 loff_t offset = le_ih_k_offset(p_le_ih); 1783 loff_t offset = le_ih_k_offset(p_le_ih);
1788 int bytes = 1784 int bytes =
@@ -1791,42 +1787,42 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
1791 /* this may mismatch with real file size: if last direct item 1787 /* this may mismatch with real file size: if last direct item
1792 had no padding zeros and last unformatted node had no free 1788 had no padding zeros and last unformatted node had no free
1793 space, this file would have this file size */ 1789 space, this file would have this file size */
1794 n_file_size = offset + bytes - 1; 1790 file_size = offset + bytes - 1;
1795 } 1791 }
1796 /* 1792 /*
1797 * are we doing a full truncate or delete, if so 1793 * are we doing a full truncate or delete, if so
1798 * kick in the reada code 1794 * kick in the reada code
1799 */ 1795 */
1800 if (n_new_file_size == 0) 1796 if (new_file_size == 0)
1801 s_search_path.reada = PATH_READA | PATH_READA_BACK; 1797 s_search_path.reada = PATH_READA | PATH_READA_BACK;
1802 1798
1803 if (n_file_size == 0 || n_file_size < n_new_file_size) { 1799 if (file_size == 0 || file_size < new_file_size) {
1804 goto update_and_out; 1800 goto update_and_out;
1805 } 1801 }
1806 1802
1807 /* Update key to search for the last file item. */ 1803 /* Update key to search for the last file item. */
1808 set_cpu_key_k_offset(&s_item_key, n_file_size); 1804 set_cpu_key_k_offset(&s_item_key, file_size);
1809 1805
1810 do { 1806 do {
1811 /* Cut or delete file item. */ 1807 /* Cut or delete file item. */
1812 n_deleted = 1808 deleted =
1813 reiserfs_cut_from_item(th, &s_search_path, &s_item_key, 1809 reiserfs_cut_from_item(th, &s_search_path, &s_item_key,
1814 inode, page, n_new_file_size); 1810 inode, page, new_file_size);
1815 if (n_deleted < 0) { 1811 if (deleted < 0) {
1816 reiserfs_warning(inode->i_sb, "vs-5665", 1812 reiserfs_warning(inode->i_sb, "vs-5665",
1817 "reiserfs_cut_from_item failed"); 1813 "reiserfs_cut_from_item failed");
1818 reiserfs_check_path(&s_search_path); 1814 reiserfs_check_path(&s_search_path);
1819 return 0; 1815 return 0;
1820 } 1816 }
1821 1817
1822 RFALSE(n_deleted > n_file_size, 1818 RFALSE(deleted > file_size,
1823 "PAP-5670: reiserfs_cut_from_item: too many bytes deleted: deleted %d, file_size %lu, item_key %K", 1819 "PAP-5670: reiserfs_cut_from_item: too many bytes deleted: deleted %d, file_size %lu, item_key %K",
1824 n_deleted, n_file_size, &s_item_key); 1820 deleted, file_size, &s_item_key);
1825 1821
1826 /* Change key to search the last file item. */ 1822 /* Change key to search the last file item. */
1827 n_file_size -= n_deleted; 1823 file_size -= deleted;
1828 1824
1829 set_cpu_key_k_offset(&s_item_key, n_file_size); 1825 set_cpu_key_k_offset(&s_item_key, file_size);
1830 1826
1831 /* While there are bytes to truncate and previous file item is presented in the tree. */ 1827 /* While there are bytes to truncate and previous file item is presented in the tree. */
1832 1828
@@ -1857,13 +1853,13 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
1857 goto out; 1853 goto out;
1858 reiserfs_update_inode_transaction(inode); 1854 reiserfs_update_inode_transaction(inode);
1859 } 1855 }
1860 } while (n_file_size > ROUND_UP(n_new_file_size) && 1856 } while (file_size > ROUND_UP(new_file_size) &&
1861 search_for_position_by_key(inode->i_sb, &s_item_key, 1857 search_for_position_by_key(inode->i_sb, &s_item_key,
1862 &s_search_path) == POSITION_FOUND); 1858 &s_search_path) == POSITION_FOUND);
1863 1859
1864 RFALSE(n_file_size > ROUND_UP(n_new_file_size), 1860 RFALSE(file_size > ROUND_UP(new_file_size),
1865 "PAP-5680: truncate did not finish: new_file_size %Ld, current %Ld, oid %d", 1861 "PAP-5680: truncate did not finish: new_file_size %Ld, current %Ld, oid %d",
1866 n_new_file_size, n_file_size, s_item_key.on_disk_key.k_objectid); 1862 new_file_size, file_size, s_item_key.on_disk_key.k_objectid);
1867 1863
1868 update_and_out: 1864 update_and_out:
1869 if (update_timestamps) { 1865 if (update_timestamps) {
@@ -1918,7 +1914,7 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
1918 const struct cpu_key *key, /* Key to search for the needed item. */ 1914 const struct cpu_key *key, /* Key to search for the needed item. */
1919 struct inode *inode, /* Inode item belongs to */ 1915 struct inode *inode, /* Inode item belongs to */
1920 const char *body, /* Pointer to the bytes to paste. */ 1916 const char *body, /* Pointer to the bytes to paste. */
1921 int n_pasted_size) 1917 int pasted_size)
1922{ /* Size of pasted bytes. */ 1918{ /* Size of pasted bytes. */
1923 struct tree_balance s_paste_balance; 1919 struct tree_balance s_paste_balance;
1924 int retval; 1920 int retval;
@@ -1931,16 +1927,16 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
1931#ifdef REISERQUOTA_DEBUG 1927#ifdef REISERQUOTA_DEBUG
1932 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, 1928 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
1933 "reiserquota paste_into_item(): allocating %u id=%u type=%c", 1929 "reiserquota paste_into_item(): allocating %u id=%u type=%c",
1934 n_pasted_size, inode->i_uid, 1930 pasted_size, inode->i_uid,
1935 key2type(&(key->on_disk_key))); 1931 key2type(&(key->on_disk_key)));
1936#endif 1932#endif
1937 1933
1938 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, n_pasted_size)) { 1934 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, pasted_size)) {
1939 pathrelse(search_path); 1935 pathrelse(search_path);
1940 return -EDQUOT; 1936 return -EDQUOT;
1941 } 1937 }
1942 init_tb_struct(th, &s_paste_balance, th->t_super, search_path, 1938 init_tb_struct(th, &s_paste_balance, th->t_super, search_path,
1943 n_pasted_size); 1939 pasted_size);
1944#ifdef DISPLACE_NEW_PACKING_LOCALITIES 1940#ifdef DISPLACE_NEW_PACKING_LOCALITIES
1945 s_paste_balance.key = key->on_disk_key; 1941 s_paste_balance.key = key->on_disk_key;
1946#endif 1942#endif
@@ -1988,10 +1984,10 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
1988#ifdef REISERQUOTA_DEBUG 1984#ifdef REISERQUOTA_DEBUG
1989 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, 1985 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
1990 "reiserquota paste_into_item(): freeing %u id=%u type=%c", 1986 "reiserquota paste_into_item(): freeing %u id=%u type=%c",
1991 n_pasted_size, inode->i_uid, 1987 pasted_size, inode->i_uid,
1992 key2type(&(key->on_disk_key))); 1988 key2type(&(key->on_disk_key)));
1993#endif 1989#endif
1994 DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size); 1990 DQUOT_FREE_SPACE_NODIRTY(inode, pasted_size);
1995 return retval; 1991 return retval;
1996} 1992}
1997 1993
diff --git a/fs/reiserfs/tail_conversion.c b/fs/reiserfs/tail_conversion.c
index 2b90c0e5697c..d7f6e51bef2a 100644
--- a/fs/reiserfs/tail_conversion.c
+++ b/fs/reiserfs/tail_conversion.c
@@ -26,7 +26,7 @@ int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode,
26 converted item. */ 26 converted item. */
27 struct item_head ind_ih; /* new indirect item to be inserted or 27 struct item_head ind_ih; /* new indirect item to be inserted or
28 key of unfm pointer to be pasted */ 28 key of unfm pointer to be pasted */
29 int n_blk_size, n_retval; /* returned value for reiserfs_insert_item and clones */ 29 int blk_size, retval; /* returned value for reiserfs_insert_item and clones */
30 unp_t unfm_ptr; /* Handle on an unformatted node 30 unp_t unfm_ptr; /* Handle on an unformatted node
31 that will be inserted in the 31 that will be inserted in the
32 tree. */ 32 tree. */
@@ -35,7 +35,7 @@ int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode,
35 35
36 REISERFS_SB(sb)->s_direct2indirect++; 36 REISERFS_SB(sb)->s_direct2indirect++;
37 37
38 n_blk_size = sb->s_blocksize; 38 blk_size = sb->s_blocksize;
39 39
40 /* and key to search for append or insert pointer to the new 40 /* and key to search for append or insert pointer to the new
41 unformatted node. */ 41 unformatted node. */
@@ -64,17 +64,17 @@ int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode,
64 set_ih_free_space(&ind_ih, 0); /* delete at nearest future */ 64 set_ih_free_space(&ind_ih, 0); /* delete at nearest future */
65 put_ih_item_len(&ind_ih, UNFM_P_SIZE); 65 put_ih_item_len(&ind_ih, UNFM_P_SIZE);
66 PATH_LAST_POSITION(path)++; 66 PATH_LAST_POSITION(path)++;
67 n_retval = 67 retval =
68 reiserfs_insert_item(th, path, &end_key, &ind_ih, inode, 68 reiserfs_insert_item(th, path, &end_key, &ind_ih, inode,
69 (char *)&unfm_ptr); 69 (char *)&unfm_ptr);
70 } else { 70 } else {
71 /* Paste into last indirect item of an object. */ 71 /* Paste into last indirect item of an object. */
72 n_retval = reiserfs_paste_into_item(th, path, &end_key, inode, 72 retval = reiserfs_paste_into_item(th, path, &end_key, inode,
73 (char *)&unfm_ptr, 73 (char *)&unfm_ptr,
74 UNFM_P_SIZE); 74 UNFM_P_SIZE);
75 } 75 }
76 if (n_retval) { 76 if (retval) {
77 return n_retval; 77 return retval;
78 } 78 }
79 // note: from here there are two keys which have matching first 79 // note: from here there are two keys which have matching first
80 // three key components. They only differ by the fourth one. 80 // three key components. They only differ by the fourth one.
@@ -98,7 +98,7 @@ int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode,
98 RFALSE(!is_direct_le_ih(p_le_ih), 98 RFALSE(!is_direct_le_ih(p_le_ih),
99 "vs-14055: direct item expected(%K), found %h", 99 "vs-14055: direct item expected(%K), found %h",
100 &end_key, p_le_ih); 100 &end_key, p_le_ih);
101 tail_size = (le_ih_k_offset(p_le_ih) & (n_blk_size - 1)) 101 tail_size = (le_ih_k_offset(p_le_ih) & (blk_size - 1))
102 + ih_item_len(p_le_ih) - 1; 102 + ih_item_len(p_le_ih) - 1;
103 103
104 /* we only send the unbh pointer if the buffer is not up to date. 104 /* we only send the unbh pointer if the buffer is not up to date.
@@ -113,11 +113,11 @@ int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode,
113 } else { 113 } else {
114 up_to_date_bh = unbh; 114 up_to_date_bh = unbh;
115 } 115 }
116 n_retval = reiserfs_delete_item(th, path, &end_key, inode, 116 retval = reiserfs_delete_item(th, path, &end_key, inode,
117 up_to_date_bh); 117 up_to_date_bh);
118 118
119 total_tail += n_retval; 119 total_tail += retval;
120 if (tail_size == n_retval) 120 if (tail_size == retval)
121 // done: file does not have direct items anymore 121 // done: file does not have direct items anymore
122 break; 122 break;
123 123
@@ -129,7 +129,7 @@ int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode,
129 unsigned pgoff = 129 unsigned pgoff =
130 (tail_offset + total_tail - 1) & (PAGE_CACHE_SIZE - 1); 130 (tail_offset + total_tail - 1) & (PAGE_CACHE_SIZE - 1);
131 char *kaddr = kmap_atomic(up_to_date_bh->b_page, KM_USER0); 131 char *kaddr = kmap_atomic(up_to_date_bh->b_page, KM_USER0);
132 memset(kaddr + pgoff, 0, n_blk_size - total_tail); 132 memset(kaddr + pgoff, 0, blk_size - total_tail);
133 kunmap_atomic(kaddr, KM_USER0); 133 kunmap_atomic(kaddr, KM_USER0);
134 } 134 }
135 135
@@ -181,7 +181,7 @@ int indirect2direct(struct reiserfs_transaction_handle *th,
181{ 181{
182 struct super_block *sb = inode->i_sb; 182 struct super_block *sb = inode->i_sb;
183 struct item_head s_ih; 183 struct item_head s_ih;
184 unsigned long n_block_size = sb->s_blocksize; 184 unsigned long block_size = sb->s_blocksize;
185 char *tail; 185 char *tail;
186 int tail_len, round_tail_len; 186 int tail_len, round_tail_len;
187 loff_t pos, pos1; /* position of first byte of the tail */ 187 loff_t pos, pos1; /* position of first byte of the tail */
@@ -196,7 +196,7 @@ int indirect2direct(struct reiserfs_transaction_handle *th,
196 /* store item head path points to. */ 196 /* store item head path points to. */
197 copy_item_head(&s_ih, PATH_PITEM_HEAD(path)); 197 copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
198 198
199 tail_len = (n_new_file_size & (n_block_size - 1)); 199 tail_len = (n_new_file_size & (block_size - 1));
200 if (get_inode_sd_version(inode) == STAT_DATA_V2) 200 if (get_inode_sd_version(inode) == STAT_DATA_V2)
201 round_tail_len = ROUND_UP(tail_len); 201 round_tail_len = ROUND_UP(tail_len);
202 else 202 else
@@ -257,7 +257,7 @@ int indirect2direct(struct reiserfs_transaction_handle *th,
257 unformatted node. For now i_size is considered as guard for 257 unformatted node. For now i_size is considered as guard for
258 going out of file size */ 258 going out of file size */
259 kunmap(page); 259 kunmap(page);
260 return n_block_size - round_tail_len; 260 return block_size - round_tail_len;
261 } 261 }
262 kunmap(page); 262 kunmap(page);
263 263
@@ -276,5 +276,5 @@ int indirect2direct(struct reiserfs_transaction_handle *th,
276 /* mark_file_with_tail (inode, pos1 + 1); */ 276 /* mark_file_with_tail (inode, pos1 + 1); */
277 REISERFS_I(inode)->i_first_direct_byte = pos1 + 1; 277 REISERFS_I(inode)->i_first_direct_byte = pos1 + 1;
278 278
279 return n_block_size - round_tail_len; 279 return block_size - round_tail_len;
280} 280}