aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs/do_balan.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/reiserfs/do_balan.c')
-rw-r--r--fs/reiserfs/do_balan.c313
1 files changed, 129 insertions, 184 deletions
diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
index 2f87f5b14630..4beb964a2a3e 100644
--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -29,6 +29,43 @@ struct tree_balance *cur_tb = NULL; /* detects whether more than one
29 is interrupting do_balance */ 29 is interrupting do_balance */
30#endif 30#endif
31 31
32static inline void buffer_info_init_left(struct tree_balance *tb,
33 struct buffer_info *bi)
34{
35 bi->tb = tb;
36 bi->bi_bh = tb->L[0];
37 bi->bi_parent = tb->FL[0];
38 bi->bi_position = get_left_neighbor_position(tb, 0);
39}
40
41static inline void buffer_info_init_right(struct tree_balance *tb,
42 struct buffer_info *bi)
43{
44 bi->tb = tb;
45 bi->bi_bh = tb->R[0];
46 bi->bi_parent = tb->FR[0];
47 bi->bi_position = get_right_neighbor_position(tb, 0);
48}
49
50static inline void buffer_info_init_tbS0(struct tree_balance *tb,
51 struct buffer_info *bi)
52{
53 bi->tb = tb;
54 bi->bi_bh = PATH_PLAST_BUFFER(tb->tb_path);
55 bi->bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
56 bi->bi_position = PATH_H_POSITION(tb->tb_path, 1);
57}
58
59static inline void buffer_info_init_bh(struct tree_balance *tb,
60 struct buffer_info *bi,
61 struct buffer_head *bh)
62{
63 bi->tb = tb;
64 bi->bi_bh = bh;
65 bi->bi_parent = NULL;
66 bi->bi_position = 0;
67}
68
32inline void do_balance_mark_leaf_dirty(struct tree_balance *tb, 69inline void do_balance_mark_leaf_dirty(struct tree_balance *tb,
33 struct buffer_head *bh, int flag) 70 struct buffer_head *bh, int flag)
34{ 71{
@@ -39,21 +76,21 @@ inline void do_balance_mark_leaf_dirty(struct tree_balance *tb,
39#define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty 76#define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty
40#define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty 77#define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty
41 78
42/* summary: 79/* summary:
43 if deleting something ( tb->insert_size[0] < 0 ) 80 if deleting something ( tb->insert_size[0] < 0 )
44 return(balance_leaf_when_delete()); (flag d handled here) 81 return(balance_leaf_when_delete()); (flag d handled here)
45 else 82 else
46 if lnum is larger than 0 we put items into the left node 83 if lnum is larger than 0 we put items into the left node
47 if rnum is larger than 0 we put items into the right node 84 if rnum is larger than 0 we put items into the right node
48 if snum1 is larger than 0 we put items into the new node s1 85 if snum1 is larger than 0 we put items into the new node s1
49 if snum2 is larger than 0 we put items into the new node s2 86 if snum2 is larger than 0 we put items into the new node s2
50Note that all *num* count new items being created. 87Note that all *num* count new items being created.
51 88
52It would be easier to read balance_leaf() if each of these summary 89It would be easier to read balance_leaf() if each of these summary
53lines was a separate procedure rather than being inlined. I think 90lines was a separate procedure rather than being inlined. I think
54that there are many passages here and in balance_leaf_when_delete() in 91that there are many passages here and in balance_leaf_when_delete() in
55which two calls to one procedure can replace two passages, and it 92which two calls to one procedure can replace two passages, and it
56might save cache space and improve software maintenance costs to do so. 93might save cache space and improve software maintenance costs to do so.
57 94
58Vladimir made the perceptive comment that we should offload most of 95Vladimir made the perceptive comment that we should offload most of
59the decision making in this function into fix_nodes/check_balance, and 96the decision making in this function into fix_nodes/check_balance, and
@@ -86,6 +123,7 @@ static int balance_leaf_when_delete(struct tree_balance *tb, int flag)
86 "PAP-12010: tree can not be empty"); 123 "PAP-12010: tree can not be empty");
87 124
88 ih = B_N_PITEM_HEAD(tbS0, item_pos); 125 ih = B_N_PITEM_HEAD(tbS0, item_pos);
126 buffer_info_init_tbS0(tb, &bi);
89 127
90 /* Delete or truncate the item */ 128 /* Delete or truncate the item */
91 129
@@ -96,10 +134,6 @@ static int balance_leaf_when_delete(struct tree_balance *tb, int flag)
96 "vs-12013: mode Delete, insert size %d, ih to be deleted %h", 134 "vs-12013: mode Delete, insert size %d, ih to be deleted %h",
97 -tb->insert_size[0], ih); 135 -tb->insert_size[0], ih);
98 136
99 bi.tb = tb;
100 bi.bi_bh = tbS0;
101 bi.bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
102 bi.bi_position = PATH_H_POSITION(tb->tb_path, 1);
103 leaf_delete_items(&bi, 0, item_pos, 1, -1); 137 leaf_delete_items(&bi, 0, item_pos, 1, -1);
104 138
105 if (!item_pos && tb->CFL[0]) { 139 if (!item_pos && tb->CFL[0]) {
@@ -121,10 +155,6 @@ static int balance_leaf_when_delete(struct tree_balance *tb, int flag)
121 break; 155 break;
122 156
123 case M_CUT:{ /* cut item in S[0] */ 157 case M_CUT:{ /* cut item in S[0] */
124 bi.tb = tb;
125 bi.bi_bh = tbS0;
126 bi.bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
127 bi.bi_position = PATH_H_POSITION(tb->tb_path, 1);
128 if (is_direntry_le_ih(ih)) { 158 if (is_direntry_le_ih(ih)) {
129 159
130 /* UFS unlink semantics are such that you can only delete one directory entry at a time. */ 160 /* UFS unlink semantics are such that you can only delete one directory entry at a time. */
@@ -153,8 +183,8 @@ static int balance_leaf_when_delete(struct tree_balance *tb, int flag)
153 183
154 default: 184 default:
155 print_cur_tb("12040"); 185 print_cur_tb("12040");
156 reiserfs_panic(tb->tb_sb, 186 reiserfs_panic(tb->tb_sb, "PAP-12040",
157 "PAP-12040: balance_leaf_when_delete: unexpectable mode: %s(%d)", 187 "unexpected mode: %s(%d)",
158 (flag == 188 (flag ==
159 M_PASTE) ? "PASTE" : ((flag == 189 M_PASTE) ? "PASTE" : ((flag ==
160 M_INSERT) ? "INSERT" : 190 M_INSERT) ? "INSERT" :
@@ -258,15 +288,15 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
258 ) 288 )
259{ 289{
260 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); 290 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
261 int item_pos = PATH_LAST_POSITION(tb->tb_path); /* index into the array of item headers in S[0] 291 int item_pos = PATH_LAST_POSITION(tb->tb_path); /* index into the array of item headers in S[0]
262 of the affected item */ 292 of the affected item */
263 struct buffer_info bi; 293 struct buffer_info bi;
264 struct buffer_head *S_new[2]; /* new nodes allocated to hold what could not fit into S */ 294 struct buffer_head *S_new[2]; /* new nodes allocated to hold what could not fit into S */
265 int snum[2]; /* number of items that will be placed 295 int snum[2]; /* number of items that will be placed
266 into S_new (includes partially shifted 296 into S_new (includes partially shifted
267 items) */ 297 items) */
268 int sbytes[2]; /* if an item is partially shifted into S_new then 298 int sbytes[2]; /* if an item is partially shifted into S_new then
269 if it is a directory item 299 if it is a directory item
270 it is the number of entries from the item that are shifted into S_new 300 it is the number of entries from the item that are shifted into S_new
271 else 301 else
272 it is the number of bytes from the item that are shifted into S_new 302 it is the number of bytes from the item that are shifted into S_new
@@ -325,11 +355,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
325 ih_item_len(ih)); 355 ih_item_len(ih));
326 356
327 /* Insert new item into L[0] */ 357 /* Insert new item into L[0] */
328 bi.tb = tb; 358 buffer_info_init_left(tb, &bi);
329 bi.bi_bh = tb->L[0];
330 bi.bi_parent = tb->FL[0];
331 bi.bi_position =
332 get_left_neighbor_position(tb, 0);
333 leaf_insert_into_buf(&bi, 359 leaf_insert_into_buf(&bi,
334 n + item_pos - 360 n + item_pos -
335 ret_val, ih, body, 361 ret_val, ih, body,
@@ -369,11 +395,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
369 leaf_shift_left(tb, tb->lnum[0] - 1, 395 leaf_shift_left(tb, tb->lnum[0] - 1,
370 tb->lbytes); 396 tb->lbytes);
371 /* Insert new item into L[0] */ 397 /* Insert new item into L[0] */
372 bi.tb = tb; 398 buffer_info_init_left(tb, &bi);
373 bi.bi_bh = tb->L[0];
374 bi.bi_parent = tb->FL[0];
375 bi.bi_position =
376 get_left_neighbor_position(tb, 0);
377 leaf_insert_into_buf(&bi, 399 leaf_insert_into_buf(&bi,
378 n + item_pos - 400 n + item_pos -
379 ret_val, ih, body, 401 ret_val, ih, body,
@@ -429,13 +451,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
429 } 451 }
430 452
431 /* Append given directory entry to directory item */ 453 /* Append given directory entry to directory item */
432 bi.tb = tb; 454 buffer_info_init_left(tb, &bi);
433 bi.bi_bh = tb->L[0];
434 bi.bi_parent =
435 tb->FL[0];
436 bi.bi_position =
437 get_left_neighbor_position
438 (tb, 0);
439 leaf_paste_in_buffer 455 leaf_paste_in_buffer
440 (&bi, 456 (&bi,
441 n + item_pos - 457 n + item_pos -
@@ -449,8 +465,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
449 /* when we have merge directory item, pos_in_item has been changed too */ 465 /* when we have merge directory item, pos_in_item has been changed too */
450 466
451 /* paste new directory entry. 1 is entry number */ 467 /* paste new directory entry. 1 is entry number */
452 leaf_paste_entries(bi. 468 leaf_paste_entries(&bi,
453 bi_bh,
454 n + 469 n +
455 item_pos 470 item_pos
456 - 471 -
@@ -524,13 +539,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
524 (tbS0, 539 (tbS0,
525 item_pos))); 540 item_pos)));
526 /* Append to body of item in L[0] */ 541 /* Append to body of item in L[0] */
527 bi.tb = tb; 542 buffer_info_init_left(tb, &bi);
528 bi.bi_bh = tb->L[0];
529 bi.bi_parent =
530 tb->FL[0];
531 bi.bi_position =
532 get_left_neighbor_position
533 (tb, 0);
534 leaf_paste_in_buffer 543 leaf_paste_in_buffer
535 (&bi, 544 (&bi,
536 n + item_pos - 545 n + item_pos -
@@ -681,11 +690,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
681 leaf_shift_left(tb, tb->lnum[0], 690 leaf_shift_left(tb, tb->lnum[0],
682 tb->lbytes); 691 tb->lbytes);
683 /* Append to body of item in L[0] */ 692 /* Append to body of item in L[0] */
684 bi.tb = tb; 693 buffer_info_init_left(tb, &bi);
685 bi.bi_bh = tb->L[0];
686 bi.bi_parent = tb->FL[0];
687 bi.bi_position =
688 get_left_neighbor_position(tb, 0);
689 leaf_paste_in_buffer(&bi, 694 leaf_paste_in_buffer(&bi,
690 n + item_pos - 695 n + item_pos -
691 ret_val, 696 ret_val,
@@ -699,7 +704,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
699 n + item_pos - 704 n + item_pos -
700 ret_val); 705 ret_val);
701 if (is_direntry_le_ih(pasted)) 706 if (is_direntry_le_ih(pasted))
702 leaf_paste_entries(bi.bi_bh, 707 leaf_paste_entries(&bi,
703 n + 708 n +
704 item_pos - 709 item_pos -
705 ret_val, 710 ret_val,
@@ -722,8 +727,9 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
722 } 727 }
723 break; 728 break;
724 default: /* cases d and t */ 729 default: /* cases d and t */
725 reiserfs_panic(tb->tb_sb, 730 reiserfs_panic(tb->tb_sb, "PAP-12130",
726 "PAP-12130: balance_leaf: lnum > 0: unexpectable mode: %s(%d)", 731 "lnum > 0: unexpected mode: "
732 " %s(%d)",
727 (flag == 733 (flag ==
728 M_DELETE) ? "DELETE" : ((flag == 734 M_DELETE) ? "DELETE" : ((flag ==
729 M_CUT) 735 M_CUT)
@@ -776,11 +782,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
776 set_le_ih_k_offset(ih, offset); 782 set_le_ih_k_offset(ih, offset);
777 put_ih_item_len(ih, tb->rbytes); 783 put_ih_item_len(ih, tb->rbytes);
778 /* Insert part of the item into R[0] */ 784 /* Insert part of the item into R[0] */
779 bi.tb = tb; 785 buffer_info_init_right(tb, &bi);
780 bi.bi_bh = tb->R[0];
781 bi.bi_parent = tb->FR[0];
782 bi.bi_position =
783 get_right_neighbor_position(tb, 0);
784 if ((old_len - tb->rbytes) > zeros_num) { 786 if ((old_len - tb->rbytes) > zeros_num) {
785 r_zeros_number = 0; 787 r_zeros_number = 0;
786 r_body = 788 r_body =
@@ -817,11 +819,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
817 tb->rnum[0] - 1, 819 tb->rnum[0] - 1,
818 tb->rbytes); 820 tb->rbytes);
819 /* Insert new item into R[0] */ 821 /* Insert new item into R[0] */
820 bi.tb = tb; 822 buffer_info_init_right(tb, &bi);
821 bi.bi_bh = tb->R[0];
822 bi.bi_parent = tb->FR[0];
823 bi.bi_position =
824 get_right_neighbor_position(tb, 0);
825 leaf_insert_into_buf(&bi, 823 leaf_insert_into_buf(&bi,
826 item_pos - n + 824 item_pos - n +
827 tb->rnum[0] - 1, 825 tb->rnum[0] - 1,
@@ -881,21 +879,14 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
881 pos_in_item - 879 pos_in_item -
882 entry_count + 880 entry_count +
883 tb->rbytes - 1; 881 tb->rbytes - 1;
884 bi.tb = tb; 882 buffer_info_init_right(tb, &bi);
885 bi.bi_bh = tb->R[0];
886 bi.bi_parent =
887 tb->FR[0];
888 bi.bi_position =
889 get_right_neighbor_position
890 (tb, 0);
891 leaf_paste_in_buffer 883 leaf_paste_in_buffer
892 (&bi, 0, 884 (&bi, 0,
893 paste_entry_position, 885 paste_entry_position,
894 tb->insert_size[0], 886 tb->insert_size[0],
895 body, zeros_num); 887 body, zeros_num);
896 /* paste entry */ 888 /* paste entry */
897 leaf_paste_entries(bi. 889 leaf_paste_entries(&bi,
898 bi_bh,
899 0, 890 0,
900 paste_entry_position, 891 paste_entry_position,
901 1, 892 1,
@@ -1019,12 +1010,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1019 (tb, tb->CFR[0], 0); 1010 (tb, tb->CFR[0], 0);
1020 1011
1021 /* Append part of body into R[0] */ 1012 /* Append part of body into R[0] */
1022 bi.tb = tb; 1013 buffer_info_init_right(tb, &bi);
1023 bi.bi_bh = tb->R[0];
1024 bi.bi_parent = tb->FR[0];
1025 bi.bi_position =
1026 get_right_neighbor_position
1027 (tb, 0);
1028 if (n_rem > zeros_num) { 1014 if (n_rem > zeros_num) {
1029 r_zeros_number = 0; 1015 r_zeros_number = 0;
1030 r_body = 1016 r_body =
@@ -1071,12 +1057,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1071 tb->rbytes); 1057 tb->rbytes);
1072 /* append item in R[0] */ 1058 /* append item in R[0] */
1073 if (pos_in_item >= 0) { 1059 if (pos_in_item >= 0) {
1074 bi.tb = tb; 1060 buffer_info_init_right(tb, &bi);
1075 bi.bi_bh = tb->R[0];
1076 bi.bi_parent = tb->FR[0];
1077 bi.bi_position =
1078 get_right_neighbor_position
1079 (tb, 0);
1080 leaf_paste_in_buffer(&bi, 1061 leaf_paste_in_buffer(&bi,
1081 item_pos - 1062 item_pos -
1082 n + 1063 n +
@@ -1096,7 +1077,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1096 tb->rnum[0]); 1077 tb->rnum[0]);
1097 if (is_direntry_le_ih(pasted) 1078 if (is_direntry_le_ih(pasted)
1098 && pos_in_item >= 0) { 1079 && pos_in_item >= 0) {
1099 leaf_paste_entries(bi.bi_bh, 1080 leaf_paste_entries(&bi,
1100 item_pos - 1081 item_pos -
1101 n + 1082 n +
1102 tb->rnum[0], 1083 tb->rnum[0],
@@ -1136,8 +1117,8 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1136 } 1117 }
1137 break; 1118 break;
1138 default: /* cases d and t */ 1119 default: /* cases d and t */
1139 reiserfs_panic(tb->tb_sb, 1120 reiserfs_panic(tb->tb_sb, "PAP-12175",
1140 "PAP-12175: balance_leaf: rnum > 0: unexpectable mode: %s(%d)", 1121 "rnum > 0: unexpected mode: %s(%d)",
1141 (flag == 1122 (flag ==
1142 M_DELETE) ? "DELETE" : ((flag == 1123 M_DELETE) ? "DELETE" : ((flag ==
1143 M_CUT) ? "CUT" 1124 M_CUT) ? "CUT"
@@ -1167,8 +1148,8 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1167 not set correctly */ 1148 not set correctly */
1168 if (tb->CFL[0]) { 1149 if (tb->CFL[0]) {
1169 if (!tb->CFR[0]) 1150 if (!tb->CFR[0])
1170 reiserfs_panic(tb->tb_sb, 1151 reiserfs_panic(tb->tb_sb, "vs-12195",
1171 "vs-12195: balance_leaf: CFR not initialized"); 1152 "CFR not initialized");
1172 copy_key(B_N_PDELIM_KEY(tb->CFL[0], tb->lkey[0]), 1153 copy_key(B_N_PDELIM_KEY(tb->CFL[0], tb->lkey[0]),
1173 B_N_PDELIM_KEY(tb->CFR[0], tb->rkey[0])); 1154 B_N_PDELIM_KEY(tb->CFR[0], tb->rkey[0]));
1174 do_balance_mark_internal_dirty(tb, tb->CFL[0], 0); 1155 do_balance_mark_internal_dirty(tb, tb->CFL[0], 0);
@@ -1232,10 +1213,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1232 put_ih_item_len(ih, sbytes[i]); 1213 put_ih_item_len(ih, sbytes[i]);
1233 1214
1234 /* Insert part of the item into S_new[i] before 0-th item */ 1215 /* Insert part of the item into S_new[i] before 0-th item */
1235 bi.tb = tb; 1216 buffer_info_init_bh(tb, &bi, S_new[i]);
1236 bi.bi_bh = S_new[i];
1237 bi.bi_parent = NULL;
1238 bi.bi_position = 0;
1239 1217
1240 if ((old_len - sbytes[i]) > zeros_num) { 1218 if ((old_len - sbytes[i]) > zeros_num) {
1241 r_zeros_number = 0; 1219 r_zeros_number = 0;
@@ -1267,10 +1245,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1267 S_new[i]); 1245 S_new[i]);
1268 1246
1269 /* Insert new item into S_new[i] */ 1247 /* Insert new item into S_new[i] */
1270 bi.tb = tb; 1248 buffer_info_init_bh(tb, &bi, S_new[i]);
1271 bi.bi_bh = S_new[i];
1272 bi.bi_parent = NULL;
1273 bi.bi_position = 0;
1274 leaf_insert_into_buf(&bi, 1249 leaf_insert_into_buf(&bi,
1275 item_pos - n + 1250 item_pos - n +
1276 snum[i] - 1, ih, 1251 snum[i] - 1, ih,
@@ -1327,10 +1302,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1327 sbytes[i] - 1, 1302 sbytes[i] - 1,
1328 S_new[i]); 1303 S_new[i]);
1329 /* Paste given directory entry to directory item */ 1304 /* Paste given directory entry to directory item */
1330 bi.tb = tb; 1305 buffer_info_init_bh(tb, &bi, S_new[i]);
1331 bi.bi_bh = S_new[i];
1332 bi.bi_parent = NULL;
1333 bi.bi_position = 0;
1334 leaf_paste_in_buffer 1306 leaf_paste_in_buffer
1335 (&bi, 0, 1307 (&bi, 0,
1336 pos_in_item - 1308 pos_in_item -
@@ -1339,8 +1311,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1339 tb->insert_size[0], 1311 tb->insert_size[0],
1340 body, zeros_num); 1312 body, zeros_num);
1341 /* paste new directory entry */ 1313 /* paste new directory entry */
1342 leaf_paste_entries(bi. 1314 leaf_paste_entries(&bi,
1343 bi_bh,
1344 0, 1315 0,
1345 pos_in_item 1316 pos_in_item
1346 - 1317 -
@@ -1401,11 +1372,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1401 if (n_rem < 0) 1372 if (n_rem < 0)
1402 n_rem = 0; 1373 n_rem = 0;
1403 /* Append part of body into S_new[0] */ 1374 /* Append part of body into S_new[0] */
1404 bi.tb = tb; 1375 buffer_info_init_bh(tb, &bi, S_new[i]);
1405 bi.bi_bh = S_new[i];
1406 bi.bi_parent = NULL;
1407 bi.bi_position = 0;
1408
1409 if (n_rem > zeros_num) { 1376 if (n_rem > zeros_num) {
1410 r_zeros_number = 0; 1377 r_zeros_number = 0;
1411 r_body = 1378 r_body =
@@ -1475,7 +1442,10 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1475 && (pos_in_item != ih_item_len(ih_check) 1442 && (pos_in_item != ih_item_len(ih_check)
1476 || tb->insert_size[0] <= 0)) 1443 || tb->insert_size[0] <= 0))
1477 reiserfs_panic(tb->tb_sb, 1444 reiserfs_panic(tb->tb_sb,
1478 "PAP-12235: balance_leaf: pos_in_item must be equal to ih_item_len"); 1445 "PAP-12235",
1446 "pos_in_item "
1447 "must be equal "
1448 "to ih_item_len");
1479#endif /* CONFIG_REISERFS_CHECK */ 1449#endif /* CONFIG_REISERFS_CHECK */
1480 1450
1481 leaf_mi = 1451 leaf_mi =
@@ -1489,10 +1459,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1489 leaf_mi); 1459 leaf_mi);
1490 1460
1491 /* paste into item */ 1461 /* paste into item */
1492 bi.tb = tb; 1462 buffer_info_init_bh(tb, &bi, S_new[i]);
1493 bi.bi_bh = S_new[i];
1494 bi.bi_parent = NULL;
1495 bi.bi_position = 0;
1496 leaf_paste_in_buffer(&bi, 1463 leaf_paste_in_buffer(&bi,
1497 item_pos - n + 1464 item_pos - n +
1498 snum[i], 1465 snum[i],
@@ -1505,7 +1472,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1505 item_pos - n + 1472 item_pos - n +
1506 snum[i]); 1473 snum[i]);
1507 if (is_direntry_le_ih(pasted)) { 1474 if (is_direntry_le_ih(pasted)) {
1508 leaf_paste_entries(bi.bi_bh, 1475 leaf_paste_entries(&bi,
1509 item_pos - 1476 item_pos -
1510 n + snum[i], 1477 n + snum[i],
1511 pos_in_item, 1478 pos_in_item,
@@ -1535,8 +1502,8 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1535 } 1502 }
1536 break; 1503 break;
1537 default: /* cases d and t */ 1504 default: /* cases d and t */
1538 reiserfs_panic(tb->tb_sb, 1505 reiserfs_panic(tb->tb_sb, "PAP-12245",
1539 "PAP-12245: balance_leaf: blknum > 2: unexpectable mode: %s(%d)", 1506 "blknum > 2: unexpected mode: %s(%d)",
1540 (flag == 1507 (flag ==
1541 M_DELETE) ? "DELETE" : ((flag == 1508 M_DELETE) ? "DELETE" : ((flag ==
1542 M_CUT) ? "CUT" 1509 M_CUT) ? "CUT"
@@ -1559,10 +1526,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1559 1526
1560 switch (flag) { 1527 switch (flag) {
1561 case M_INSERT: /* insert item into S[0] */ 1528 case M_INSERT: /* insert item into S[0] */
1562 bi.tb = tb; 1529 buffer_info_init_tbS0(tb, &bi);
1563 bi.bi_bh = tbS0;
1564 bi.bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
1565 bi.bi_position = PATH_H_POSITION(tb->tb_path, 1);
1566 leaf_insert_into_buf(&bi, item_pos, ih, body, 1530 leaf_insert_into_buf(&bi, item_pos, ih, body,
1567 zeros_num); 1531 zeros_num);
1568 1532
@@ -1589,14 +1553,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1589 "PAP-12260: insert_size is 0 already"); 1553 "PAP-12260: insert_size is 0 already");
1590 1554
1591 /* prepare space */ 1555 /* prepare space */
1592 bi.tb = tb; 1556 buffer_info_init_tbS0(tb, &bi);
1593 bi.bi_bh = tbS0;
1594 bi.bi_parent =
1595 PATH_H_PPARENT(tb->tb_path,
1596 0);
1597 bi.bi_position =
1598 PATH_H_POSITION(tb->tb_path,
1599 1);
1600 leaf_paste_in_buffer(&bi, 1557 leaf_paste_in_buffer(&bi,
1601 item_pos, 1558 item_pos,
1602 pos_in_item, 1559 pos_in_item,
@@ -1606,7 +1563,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1606 zeros_num); 1563 zeros_num);
1607 1564
1608 /* paste entry */ 1565 /* paste entry */
1609 leaf_paste_entries(bi.bi_bh, 1566 leaf_paste_entries(&bi,
1610 item_pos, 1567 item_pos,
1611 pos_in_item, 1568 pos_in_item,
1612 1, 1569 1,
@@ -1644,14 +1601,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1644 RFALSE(tb->insert_size[0] <= 0, 1601 RFALSE(tb->insert_size[0] <= 0,
1645 "PAP-12275: insert size must not be %d", 1602 "PAP-12275: insert size must not be %d",
1646 tb->insert_size[0]); 1603 tb->insert_size[0]);
1647 bi.tb = tb; 1604 buffer_info_init_tbS0(tb, &bi);
1648 bi.bi_bh = tbS0;
1649 bi.bi_parent =
1650 PATH_H_PPARENT(tb->tb_path,
1651 0);
1652 bi.bi_position =
1653 PATH_H_POSITION(tb->tb_path,
1654 1);
1655 leaf_paste_in_buffer(&bi, 1605 leaf_paste_in_buffer(&bi,
1656 item_pos, 1606 item_pos,
1657 pos_in_item, 1607 pos_in_item,
@@ -1681,10 +1631,11 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1681 print_cur_tb("12285"); 1631 print_cur_tb("12285");
1682 reiserfs_panic(tb-> 1632 reiserfs_panic(tb->
1683 tb_sb, 1633 tb_sb,
1684 "PAP-12285: balance_leaf: insert_size must be 0 (%d)", 1634 "PAP-12285",
1685 tb-> 1635 "insert_size "
1686 insert_size 1636 "must be 0 "
1687 [0]); 1637 "(%d)",
1638 tb->insert_size[0]);
1688 } 1639 }
1689 } 1640 }
1690#endif /* CONFIG_REISERFS_CHECK */ 1641#endif /* CONFIG_REISERFS_CHECK */
@@ -1697,11 +1648,10 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1697 if (flag == M_PASTE && tb->insert_size[0]) { 1648 if (flag == M_PASTE && tb->insert_size[0]) {
1698 print_cur_tb("12290"); 1649 print_cur_tb("12290");
1699 reiserfs_panic(tb->tb_sb, 1650 reiserfs_panic(tb->tb_sb,
1700 "PAP-12290: balance_leaf: insert_size is still not 0 (%d)", 1651 "PAP-12290", "insert_size is still not 0 (%d)",
1701 tb->insert_size[0]); 1652 tb->insert_size[0]);
1702 } 1653 }
1703#endif /* CONFIG_REISERFS_CHECK */ 1654#endif /* CONFIG_REISERFS_CHECK */
1704
1705 return 0; 1655 return 0;
1706} /* Leaf level of the tree is balanced (end of balance_leaf) */ 1656} /* Leaf level of the tree is balanced (end of balance_leaf) */
1707 1657
@@ -1724,7 +1674,6 @@ void make_empty_node(struct buffer_info *bi)
1724struct buffer_head *get_FEB(struct tree_balance *tb) 1674struct buffer_head *get_FEB(struct tree_balance *tb)
1725{ 1675{
1726 int i; 1676 int i;
1727 struct buffer_head *first_b;
1728 struct buffer_info bi; 1677 struct buffer_info bi;
1729 1678
1730 for (i = 0; i < MAX_FEB_SIZE; i++) 1679 for (i = 0; i < MAX_FEB_SIZE; i++)
@@ -1732,19 +1681,15 @@ struct buffer_head *get_FEB(struct tree_balance *tb)
1732 break; 1681 break;
1733 1682
1734 if (i == MAX_FEB_SIZE) 1683 if (i == MAX_FEB_SIZE)
1735 reiserfs_panic(tb->tb_sb, 1684 reiserfs_panic(tb->tb_sb, "vs-12300", "FEB list is empty");
1736 "vs-12300: get_FEB: FEB list is empty");
1737 1685
1738 bi.tb = tb; 1686 buffer_info_init_bh(tb, &bi, tb->FEB[i]);
1739 bi.bi_bh = first_b = tb->FEB[i];
1740 bi.bi_parent = NULL;
1741 bi.bi_position = 0;
1742 make_empty_node(&bi); 1687 make_empty_node(&bi);
1743 set_buffer_uptodate(first_b); 1688 set_buffer_uptodate(tb->FEB[i]);
1689 tb->used[i] = tb->FEB[i];
1744 tb->FEB[i] = NULL; 1690 tb->FEB[i] = NULL;
1745 tb->used[i] = first_b;
1746 1691
1747 return (first_b); 1692 return tb->used[i];
1748} 1693}
1749 1694
1750/* This is now used because reiserfs_free_block has to be able to 1695/* This is now used because reiserfs_free_block has to be able to
@@ -1755,15 +1700,16 @@ static void store_thrown(struct tree_balance *tb, struct buffer_head *bh)
1755 int i; 1700 int i;
1756 1701
1757 if (buffer_dirty(bh)) 1702 if (buffer_dirty(bh))
1758 reiserfs_warning(tb->tb_sb, 1703 reiserfs_warning(tb->tb_sb, "reiserfs-12320",
1759 "store_thrown deals with dirty buffer"); 1704 "called with dirty buffer");
1760 for (i = 0; i < ARRAY_SIZE(tb->thrown); i++) 1705 for (i = 0; i < ARRAY_SIZE(tb->thrown); i++)
1761 if (!tb->thrown[i]) { 1706 if (!tb->thrown[i]) {
1762 tb->thrown[i] = bh; 1707 tb->thrown[i] = bh;
1763 get_bh(bh); /* free_thrown puts this */ 1708 get_bh(bh); /* free_thrown puts this */
1764 return; 1709 return;
1765 } 1710 }
1766 reiserfs_warning(tb->tb_sb, "store_thrown: too many thrown buffers"); 1711 reiserfs_warning(tb->tb_sb, "reiserfs-12321",
1712 "too many thrown buffers");
1767} 1713}
1768 1714
1769static void free_thrown(struct tree_balance *tb) 1715static void free_thrown(struct tree_balance *tb)
@@ -1774,8 +1720,8 @@ static void free_thrown(struct tree_balance *tb)
1774 if (tb->thrown[i]) { 1720 if (tb->thrown[i]) {
1775 blocknr = tb->thrown[i]->b_blocknr; 1721 blocknr = tb->thrown[i]->b_blocknr;
1776 if (buffer_dirty(tb->thrown[i])) 1722 if (buffer_dirty(tb->thrown[i]))
1777 reiserfs_warning(tb->tb_sb, 1723 reiserfs_warning(tb->tb_sb, "reiserfs-12322",
1778 "free_thrown deals with dirty buffer %d", 1724 "called with dirty buffer %d",
1779 blocknr); 1725 blocknr);
1780 brelse(tb->thrown[i]); /* incremented in store_thrown */ 1726 brelse(tb->thrown[i]); /* incremented in store_thrown */
1781 reiserfs_free_block(tb->transaction_handle, NULL, 1727 reiserfs_free_block(tb->transaction_handle, NULL,
@@ -1873,20 +1819,19 @@ static void check_internal_node(struct super_block *s, struct buffer_head *bh,
1873 for (i = 0; i <= B_NR_ITEMS(bh); i++, dc++) { 1819 for (i = 0; i <= B_NR_ITEMS(bh); i++, dc++) {
1874 if (!is_reusable(s, dc_block_number(dc), 1)) { 1820 if (!is_reusable(s, dc_block_number(dc), 1)) {
1875 print_cur_tb(mes); 1821 print_cur_tb(mes);
1876 reiserfs_panic(s, 1822 reiserfs_panic(s, "PAP-12338",
1877 "PAP-12338: check_internal_node: invalid child pointer %y in %b", 1823 "invalid child pointer %y in %b",
1878 dc, bh); 1824 dc, bh);
1879 } 1825 }
1880 } 1826 }
1881} 1827}
1882 1828
1883static int locked_or_not_in_tree(struct buffer_head *bh, char *which) 1829static int locked_or_not_in_tree(struct tree_balance *tb,
1830 struct buffer_head *bh, char *which)
1884{ 1831{
1885 if ((!buffer_journal_prepared(bh) && buffer_locked(bh)) || 1832 if ((!buffer_journal_prepared(bh) && buffer_locked(bh)) ||
1886 !B_IS_IN_TREE(bh)) { 1833 !B_IS_IN_TREE(bh)) {
1887 reiserfs_warning(NULL, 1834 reiserfs_warning(tb->tb_sb, "vs-12339", "%s (%b)", which, bh);
1888 "vs-12339: locked_or_not_in_tree: %s (%b)",
1889 which, bh);
1890 return 1; 1835 return 1;
1891 } 1836 }
1892 return 0; 1837 return 0;
@@ -1897,26 +1842,28 @@ static int check_before_balancing(struct tree_balance *tb)
1897 int retval = 0; 1842 int retval = 0;
1898 1843
1899 if (cur_tb) { 1844 if (cur_tb) {
1900 reiserfs_panic(tb->tb_sb, "vs-12335: check_before_balancing: " 1845 reiserfs_panic(tb->tb_sb, "vs-12335", "suspect that schedule "
1901 "suspect that schedule occurred based on cur_tb not being null at this point in code. " 1846 "occurred based on cur_tb not being null at "
1902 "do_balance cannot properly handle schedule occurring while it runs."); 1847 "this point in code. do_balance cannot properly "
1848 "handle schedule occurring while it runs.");
1903 } 1849 }
1904 1850
1905 /* double check that buffers that we will modify are unlocked. (fix_nodes should already have 1851 /* double check that buffers that we will modify are unlocked. (fix_nodes should already have
1906 prepped all of these for us). */ 1852 prepped all of these for us). */
1907 if (tb->lnum[0]) { 1853 if (tb->lnum[0]) {
1908 retval |= locked_or_not_in_tree(tb->L[0], "L[0]"); 1854 retval |= locked_or_not_in_tree(tb, tb->L[0], "L[0]");
1909 retval |= locked_or_not_in_tree(tb->FL[0], "FL[0]"); 1855 retval |= locked_or_not_in_tree(tb, tb->FL[0], "FL[0]");
1910 retval |= locked_or_not_in_tree(tb->CFL[0], "CFL[0]"); 1856 retval |= locked_or_not_in_tree(tb, tb->CFL[0], "CFL[0]");
1911 check_leaf(tb->L[0]); 1857 check_leaf(tb->L[0]);
1912 } 1858 }
1913 if (tb->rnum[0]) { 1859 if (tb->rnum[0]) {
1914 retval |= locked_or_not_in_tree(tb->R[0], "R[0]"); 1860 retval |= locked_or_not_in_tree(tb, tb->R[0], "R[0]");
1915 retval |= locked_or_not_in_tree(tb->FR[0], "FR[0]"); 1861 retval |= locked_or_not_in_tree(tb, tb->FR[0], "FR[0]");
1916 retval |= locked_or_not_in_tree(tb->CFR[0], "CFR[0]"); 1862 retval |= locked_or_not_in_tree(tb, tb->CFR[0], "CFR[0]");
1917 check_leaf(tb->R[0]); 1863 check_leaf(tb->R[0]);
1918 } 1864 }
1919 retval |= locked_or_not_in_tree(PATH_PLAST_BUFFER(tb->tb_path), "S[0]"); 1865 retval |= locked_or_not_in_tree(tb, PATH_PLAST_BUFFER(tb->tb_path),
1866 "S[0]");
1920 check_leaf(PATH_PLAST_BUFFER(tb->tb_path)); 1867 check_leaf(PATH_PLAST_BUFFER(tb->tb_path));
1921 1868
1922 return retval; 1869 return retval;
@@ -1930,8 +1877,8 @@ static void check_after_balance_leaf(struct tree_balance *tb)
1930 dc_size(B_N_CHILD 1877 dc_size(B_N_CHILD
1931 (tb->FL[0], get_left_neighbor_position(tb, 0)))) { 1878 (tb->FL[0], get_left_neighbor_position(tb, 0)))) {
1932 print_cur_tb("12221"); 1879 print_cur_tb("12221");
1933 reiserfs_panic(tb->tb_sb, 1880 reiserfs_panic(tb->tb_sb, "PAP-12355",
1934 "PAP-12355: check_after_balance_leaf: shift to left was incorrect"); 1881 "shift to left was incorrect");
1935 } 1882 }
1936 } 1883 }
1937 if (tb->rnum[0]) { 1884 if (tb->rnum[0]) {
@@ -1940,8 +1887,8 @@ static void check_after_balance_leaf(struct tree_balance *tb)
1940 dc_size(B_N_CHILD 1887 dc_size(B_N_CHILD
1941 (tb->FR[0], get_right_neighbor_position(tb, 0)))) { 1888 (tb->FR[0], get_right_neighbor_position(tb, 0)))) {
1942 print_cur_tb("12222"); 1889 print_cur_tb("12222");
1943 reiserfs_panic(tb->tb_sb, 1890 reiserfs_panic(tb->tb_sb, "PAP-12360",
1944 "PAP-12360: check_after_balance_leaf: shift to right was incorrect"); 1891 "shift to right was incorrect");
1945 } 1892 }
1946 } 1893 }
1947 if (PATH_H_PBUFFER(tb->tb_path, 1) && 1894 if (PATH_H_PBUFFER(tb->tb_path, 1) &&
@@ -1955,7 +1902,7 @@ static void check_after_balance_leaf(struct tree_balance *tb)
1955 PATH_H_POSITION(tb->tb_path, 1902 PATH_H_POSITION(tb->tb_path,
1956 1)))); 1903 1))));
1957 print_cur_tb("12223"); 1904 print_cur_tb("12223");
1958 reiserfs_warning(tb->tb_sb, 1905 reiserfs_warning(tb->tb_sb, "reiserfs-12363",
1959 "B_FREE_SPACE (PATH_H_PBUFFER(tb->tb_path,0)) = %d; " 1906 "B_FREE_SPACE (PATH_H_PBUFFER(tb->tb_path,0)) = %d; "
1960 "MAX_CHILD_SIZE (%d) - dc_size( %y, %d ) [%d] = %d", 1907 "MAX_CHILD_SIZE (%d) - dc_size( %y, %d ) [%d] = %d",
1961 left, 1908 left,
@@ -1966,8 +1913,7 @@ static void check_after_balance_leaf(struct tree_balance *tb)
1966 (PATH_H_PBUFFER(tb->tb_path, 1), 1913 (PATH_H_PBUFFER(tb->tb_path, 1),
1967 PATH_H_POSITION(tb->tb_path, 1))), 1914 PATH_H_POSITION(tb->tb_path, 1))),
1968 right); 1915 right);
1969 reiserfs_panic(tb->tb_sb, 1916 reiserfs_panic(tb->tb_sb, "PAP-12365", "S is incorrect");
1970 "PAP-12365: check_after_balance_leaf: S is incorrect");
1971 } 1917 }
1972} 1918}
1973 1919
@@ -2037,7 +1983,7 @@ static inline void do_balance_starts(struct tree_balance *tb)
2037 /* store_print_tb (tb); */ 1983 /* store_print_tb (tb); */
2038 1984
2039 /* do not delete, just comment it out */ 1985 /* do not delete, just comment it out */
2040/* print_tb(flag, PATH_LAST_POSITION(tb->tb_path), tb->tb_path->pos_in_item, tb, 1986/* print_tb(flag, PATH_LAST_POSITION(tb->tb_path), tb->tb_path->pos_in_item, tb,
2041 "check");*/ 1987 "check");*/
2042 RFALSE(check_before_balancing(tb), "PAP-12340: locked buffers in TB"); 1988 RFALSE(check_before_balancing(tb), "PAP-12340: locked buffers in TB");
2043#ifdef CONFIG_REISERFS_CHECK 1989#ifdef CONFIG_REISERFS_CHECK
@@ -2102,14 +2048,13 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
2102 tb->need_balance_dirty = 0; 2048 tb->need_balance_dirty = 0;
2103 2049
2104 if (FILESYSTEM_CHANGED_TB(tb)) { 2050 if (FILESYSTEM_CHANGED_TB(tb)) {
2105 reiserfs_panic(tb->tb_sb, 2051 reiserfs_panic(tb->tb_sb, "clm-6000", "fs generation has "
2106 "clm-6000: do_balance, fs generation has changed\n"); 2052 "changed");
2107 } 2053 }
2108 /* if we have no real work to do */ 2054 /* if we have no real work to do */
2109 if (!tb->insert_size[0]) { 2055 if (!tb->insert_size[0]) {
2110 reiserfs_warning(tb->tb_sb, 2056 reiserfs_warning(tb->tb_sb, "PAP-12350",
2111 "PAP-12350: do_balance: insert_size == 0, mode == %c", 2057 "insert_size == 0, mode == %c", flag);
2112 flag);
2113 unfix_nodes(tb); 2058 unfix_nodes(tb);
2114 return; 2059 return;
2115 } 2060 }