diff options
author | Jeff Mahoney <jeffm@suse.com> | 2009-03-30 14:02:42 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-03-30 15:16:39 -0400 |
commit | fba4ebb5f0f84a6f9989e9591741ddff946de320 (patch) | |
tree | 7d140b781292f00a70a98f0f938fc2ac6f0896c0 | |
parent | 57fe60df62410f949da094d06ced1dda9575b69c (diff) |
reiserfs: factor out buffer_info initialization
This is the first in a series of patches to make balance_leaf() not
quite so insane.
This patch factors out the open coded initializations of buffer_info
structures and defines a few initializers for the 4 cases they're used.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | fs/reiserfs/do_balan.c | 175 |
1 files changed, 60 insertions, 115 deletions
diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c index e788fbc3ff6b..723a7f4011d0 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 | ||
32 | static 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 | |||
41 | static 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 | |||
50 | static 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 | |||
59 | static 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 | |||
32 | inline void do_balance_mark_leaf_dirty(struct tree_balance *tb, | 69 | inline 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 | { |
@@ -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. */ |
@@ -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 - |
@@ -523,13 +539,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h | |||
523 | (tbS0, | 539 | (tbS0, |
524 | item_pos))); | 540 | item_pos))); |
525 | /* Append to body of item in L[0] */ | 541 | /* Append to body of item in L[0] */ |
526 | bi.tb = tb; | 542 | buffer_info_init_left(tb, &bi); |
527 | bi.bi_bh = tb->L[0]; | ||
528 | bi.bi_parent = | ||
529 | tb->FL[0]; | ||
530 | bi.bi_position = | ||
531 | get_left_neighbor_position | ||
532 | (tb, 0); | ||
533 | leaf_paste_in_buffer | 543 | leaf_paste_in_buffer |
534 | (&bi, | 544 | (&bi, |
535 | n + item_pos - | 545 | n + item_pos - |
@@ -680,11 +690,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h | |||
680 | leaf_shift_left(tb, tb->lnum[0], | 690 | leaf_shift_left(tb, tb->lnum[0], |
681 | tb->lbytes); | 691 | tb->lbytes); |
682 | /* Append to body of item in L[0] */ | 692 | /* Append to body of item in L[0] */ |
683 | bi.tb = tb; | 693 | buffer_info_init_left(tb, &bi); |
684 | bi.bi_bh = tb->L[0]; | ||
685 | bi.bi_parent = tb->FL[0]; | ||
686 | bi.bi_position = | ||
687 | get_left_neighbor_position(tb, 0); | ||
688 | leaf_paste_in_buffer(&bi, | 694 | leaf_paste_in_buffer(&bi, |
689 | n + item_pos - | 695 | n + item_pos - |
690 | ret_val, | 696 | ret_val, |
@@ -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,13 +879,7 @@ 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, |
@@ -1018,12 +1010,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h | |||
1018 | (tb, tb->CFR[0], 0); | 1010 | (tb, tb->CFR[0], 0); |
1019 | 1011 | ||
1020 | /* Append part of body into R[0] */ | 1012 | /* Append part of body into R[0] */ |
1021 | bi.tb = tb; | 1013 | buffer_info_init_right(tb, &bi); |
1022 | bi.bi_bh = tb->R[0]; | ||
1023 | bi.bi_parent = tb->FR[0]; | ||
1024 | bi.bi_position = | ||
1025 | get_right_neighbor_position | ||
1026 | (tb, 0); | ||
1027 | if (n_rem > zeros_num) { | 1014 | if (n_rem > zeros_num) { |
1028 | r_zeros_number = 0; | 1015 | r_zeros_number = 0; |
1029 | r_body = | 1016 | r_body = |
@@ -1070,12 +1057,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h | |||
1070 | tb->rbytes); | 1057 | tb->rbytes); |
1071 | /* append item in R[0] */ | 1058 | /* append item in R[0] */ |
1072 | if (pos_in_item >= 0) { | 1059 | if (pos_in_item >= 0) { |
1073 | bi.tb = tb; | 1060 | buffer_info_init_right(tb, &bi); |
1074 | bi.bi_bh = tb->R[0]; | ||
1075 | bi.bi_parent = tb->FR[0]; | ||
1076 | bi.bi_position = | ||
1077 | get_right_neighbor_position | ||
1078 | (tb, 0); | ||
1079 | leaf_paste_in_buffer(&bi, | 1061 | leaf_paste_in_buffer(&bi, |
1080 | item_pos - | 1062 | item_pos - |
1081 | n + | 1063 | n + |
@@ -1231,10 +1213,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h | |||
1231 | put_ih_item_len(ih, sbytes[i]); | 1213 | put_ih_item_len(ih, sbytes[i]); |
1232 | 1214 | ||
1233 | /* 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 */ |
1234 | bi.tb = tb; | 1216 | buffer_info_init_bh(tb, &bi, S_new[i]); |
1235 | bi.bi_bh = S_new[i]; | ||
1236 | bi.bi_parent = NULL; | ||
1237 | bi.bi_position = 0; | ||
1238 | 1217 | ||
1239 | if ((old_len - sbytes[i]) > zeros_num) { | 1218 | if ((old_len - sbytes[i]) > zeros_num) { |
1240 | r_zeros_number = 0; | 1219 | r_zeros_number = 0; |
@@ -1266,10 +1245,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h | |||
1266 | S_new[i]); | 1245 | S_new[i]); |
1267 | 1246 | ||
1268 | /* Insert new item into S_new[i] */ | 1247 | /* Insert new item into S_new[i] */ |
1269 | bi.tb = tb; | 1248 | buffer_info_init_bh(tb, &bi, S_new[i]); |
1270 | bi.bi_bh = S_new[i]; | ||
1271 | bi.bi_parent = NULL; | ||
1272 | bi.bi_position = 0; | ||
1273 | leaf_insert_into_buf(&bi, | 1249 | leaf_insert_into_buf(&bi, |
1274 | item_pos - n + | 1250 | item_pos - n + |
1275 | snum[i] - 1, ih, | 1251 | snum[i] - 1, ih, |
@@ -1326,10 +1302,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h | |||
1326 | sbytes[i] - 1, | 1302 | sbytes[i] - 1, |
1327 | S_new[i]); | 1303 | S_new[i]); |
1328 | /* Paste given directory entry to directory item */ | 1304 | /* Paste given directory entry to directory item */ |
1329 | bi.tb = tb; | 1305 | buffer_info_init_bh(tb, &bi, S_new[i]); |
1330 | bi.bi_bh = S_new[i]; | ||
1331 | bi.bi_parent = NULL; | ||
1332 | bi.bi_position = 0; | ||
1333 | leaf_paste_in_buffer | 1306 | leaf_paste_in_buffer |
1334 | (&bi, 0, | 1307 | (&bi, 0, |
1335 | pos_in_item - | 1308 | pos_in_item - |
@@ -1399,11 +1372,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h | |||
1399 | if (n_rem < 0) | 1372 | if (n_rem < 0) |
1400 | n_rem = 0; | 1373 | n_rem = 0; |
1401 | /* Append part of body into S_new[0] */ | 1374 | /* Append part of body into S_new[0] */ |
1402 | bi.tb = tb; | 1375 | buffer_info_init_bh(tb, &bi, S_new[i]); |
1403 | bi.bi_bh = S_new[i]; | ||
1404 | bi.bi_parent = NULL; | ||
1405 | bi.bi_position = 0; | ||
1406 | |||
1407 | if (n_rem > zeros_num) { | 1376 | if (n_rem > zeros_num) { |
1408 | r_zeros_number = 0; | 1377 | r_zeros_number = 0; |
1409 | r_body = | 1378 | r_body = |
@@ -1490,10 +1459,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h | |||
1490 | leaf_mi); | 1459 | leaf_mi); |
1491 | 1460 | ||
1492 | /* paste into item */ | 1461 | /* paste into item */ |
1493 | bi.tb = tb; | 1462 | buffer_info_init_bh(tb, &bi, S_new[i]); |
1494 | bi.bi_bh = S_new[i]; | ||
1495 | bi.bi_parent = NULL; | ||
1496 | bi.bi_position = 0; | ||
1497 | leaf_paste_in_buffer(&bi, | 1463 | leaf_paste_in_buffer(&bi, |
1498 | item_pos - n + | 1464 | item_pos - n + |
1499 | snum[i], | 1465 | snum[i], |
@@ -1560,10 +1526,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h | |||
1560 | 1526 | ||
1561 | switch (flag) { | 1527 | switch (flag) { |
1562 | case M_INSERT: /* insert item into S[0] */ | 1528 | case M_INSERT: /* insert item into S[0] */ |
1563 | bi.tb = tb; | 1529 | buffer_info_init_tbS0(tb, &bi); |
1564 | bi.bi_bh = tbS0; | ||
1565 | bi.bi_parent = PATH_H_PPARENT(tb->tb_path, 0); | ||
1566 | bi.bi_position = PATH_H_POSITION(tb->tb_path, 1); | ||
1567 | leaf_insert_into_buf(&bi, item_pos, ih, body, | 1530 | leaf_insert_into_buf(&bi, item_pos, ih, body, |
1568 | zeros_num); | 1531 | zeros_num); |
1569 | 1532 | ||
@@ -1590,14 +1553,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h | |||
1590 | "PAP-12260: insert_size is 0 already"); | 1553 | "PAP-12260: insert_size is 0 already"); |
1591 | 1554 | ||
1592 | /* prepare space */ | 1555 | /* prepare space */ |
1593 | bi.tb = tb; | 1556 | buffer_info_init_tbS0(tb, &bi); |
1594 | bi.bi_bh = tbS0; | ||
1595 | bi.bi_parent = | ||
1596 | PATH_H_PPARENT(tb->tb_path, | ||
1597 | 0); | ||
1598 | bi.bi_position = | ||
1599 | PATH_H_POSITION(tb->tb_path, | ||
1600 | 1); | ||
1601 | leaf_paste_in_buffer(&bi, | 1557 | leaf_paste_in_buffer(&bi, |
1602 | item_pos, | 1558 | item_pos, |
1603 | pos_in_item, | 1559 | pos_in_item, |
@@ -1645,14 +1601,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h | |||
1645 | RFALSE(tb->insert_size[0] <= 0, | 1601 | RFALSE(tb->insert_size[0] <= 0, |
1646 | "PAP-12275: insert size must not be %d", | 1602 | "PAP-12275: insert size must not be %d", |
1647 | tb->insert_size[0]); | 1603 | tb->insert_size[0]); |
1648 | bi.tb = tb; | 1604 | buffer_info_init_tbS0(tb, &bi); |
1649 | bi.bi_bh = tbS0; | ||
1650 | bi.bi_parent = | ||
1651 | PATH_H_PPARENT(tb->tb_path, | ||
1652 | 0); | ||
1653 | bi.bi_position = | ||
1654 | PATH_H_POSITION(tb->tb_path, | ||
1655 | 1); | ||
1656 | leaf_paste_in_buffer(&bi, | 1605 | leaf_paste_in_buffer(&bi, |
1657 | item_pos, | 1606 | item_pos, |
1658 | pos_in_item, | 1607 | pos_in_item, |
@@ -1725,7 +1674,6 @@ void make_empty_node(struct buffer_info *bi) | |||
1725 | struct buffer_head *get_FEB(struct tree_balance *tb) | 1674 | struct buffer_head *get_FEB(struct tree_balance *tb) |
1726 | { | 1675 | { |
1727 | int i; | 1676 | int i; |
1728 | struct buffer_head *first_b; | ||
1729 | struct buffer_info bi; | 1677 | struct buffer_info bi; |
1730 | 1678 | ||
1731 | for (i = 0; i < MAX_FEB_SIZE; i++) | 1679 | for (i = 0; i < MAX_FEB_SIZE; i++) |
@@ -1735,16 +1683,13 @@ struct buffer_head *get_FEB(struct tree_balance *tb) | |||
1735 | if (i == MAX_FEB_SIZE) | 1683 | if (i == MAX_FEB_SIZE) |
1736 | reiserfs_panic(tb->tb_sb, "vs-12300", "FEB list is empty"); | 1684 | reiserfs_panic(tb->tb_sb, "vs-12300", "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 |