18 #include <asm/uaccess.h>
19 #include <linux/time.h>
22 #include <linux/kernel.h>
53 struct buffer_head *bh)
62 struct buffer_head *bh,
int flag)
68 #define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty
69 #define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty
111 "vs- 12000: level: wrong FR %z", tb->
FR[0]);
113 "PAP-12005: tb->blknum == %d, can not be > 1", tb->
blknum[0]);
115 "PAP-12010: tree can not be empty");
118 buffer_info_init_tbS0(tb, &bi);
126 "vs-12013: mode Delete, insert size %d, ih to be deleted %h",
131 if (!item_pos && tb->
CFL[0]) {
144 "PAP-12020: tb->CFL[0]==%p, tb->L[0]==%p", tb->
CFL[0],
150 if (is_direntry_le_ih(ih)) {
158 RFALSE(!item_pos && !pos_in_item && !tb->
CFL[0],
159 "PAP-12030: can not change delimiting key. CFL[0]=%p",
162 if (!item_pos && !pos_in_item && tb->
CFL[0]) {
171 "PAP-12035: cut must leave non-zero dynamic length of item");
179 "unexpected mode: %s(%d)",
189 if (tb->
lnum[0] == -1) {
190 if (tb->
rnum[0] == -1) {
228 "PAP-12045: rnum must be 0 (%d)", tb->
rnum[0]);
239 (tb->
lnum[0] + tb->
rnum[0] > n + 1),
240 "PAP-12050: rnum(%d) and lnum(%d) and item number(%d) in S[0] are not consistent",
244 "PAP-12055: bad rbytes (%d)/lbytes (%d) parameters when items are not split",
248 "PAP-12060: bad rbytes (%d)/lbytes (%d) parameters when items are split",
259 if (tb->
rnum[0] == -1) {
267 "PAP-12065: bad rnum parameter must be 0 (%d)", tb->
rnum[0]);
279 struct buffer_head **insert_ptr
286 struct buffer_head *S_new[2];
305 return balance_leaf_when_delete(tb, flag);
311 pos_in_item = tb->
tb_path->pos_in_item;
318 if (tb->
lnum[0] > 0) {
320 if (item_pos < tb->lnum[0]) {
327 if (item_pos == tb->
lnum[0] - 1
346 "PAP-12080: there is nothing to insert into L[0]: ih_item_len=%d",
350 buffer_info_init_left(tb, &
bi);
362 set_le_ih_k_offset(ih,
373 if (tb->
lbytes > zeros_num) {
381 "PAP-12085: there is nothing to insert into S[0]: ih_item_len=%d",
390 buffer_info_init_left(tb, &
bi);
402 if (item_pos == tb->
lnum[0] - 1
405 if (is_direntry_le_ih
409 "PAP-12090: invalid parameter in case of a directory");
411 if (tb->
lbytes > pos_in_item) {
446 buffer_info_init_left(tb, &
bi);
489 pos_in_item -= tb->
lbytes;
493 "PAP-12095: there is nothing to shift to L[0]. lbytes=%d",
499 "PAP-12100: incorrect position to paste: item_len=%d, pos_in_item=%d",
505 if (tb->
lbytes >= pos_in_item) {
521 "PAP-12105: there is nothing to paste into L[0]. insert_size=%d",
534 buffer_info_init_left(tb, &
bi);
559 "PAP-12106: item length must be 0");
570 "PAP-12107: items must be of the same file");
571 if (is_indirect_le_ih(
B_N_PITEM_HEAD(tb->
L[0], n + item_pos - ret_val))) {
615 if (l_n > zeros_num) {
643 "PAP-12120: item must be merge-able with left neighboring item");
651 "PAP-12125: no place for paste. pos_in_item=%d",
671 if (is_direntry_le_ih(pasted))
685 buffer_info_init_left(tb, &
bi);
698 if (is_direntry_le_ih(pasted))
715 if (is_indirect_le_ih(pasted))
723 "lnum > 0: unexpected mode: "
741 item_pos -= (tb->
lnum[0] - ((tb->
lbytes != -1) ? 1 : 0));
743 if (tb->
rnum[0] > 0) {
749 if (n - tb->
rnum[0] < item_pos) {
750 if (item_pos == n - tb->
rnum[0] + 1 && tb->
rbytes != -1) {
751 loff_t old_key_comp, old_len,
762 old_key_comp = le_ih_k_offset(ih);
770 rbytes) << (is_indirect_le_ih(ih)
774 set_le_ih_k_offset(ih, offset);
777 buffer_info_init_right(tb, &
bi);
778 if ((old_len - tb->
rbytes) > zeros_num) {
787 zeros_num - (old_len -
789 zeros_num -= r_zeros_number;
800 set_le_ih_k_offset(ih, old_key_comp);
814 buffer_info_init_right(tb, &
bi);
821 if (item_pos - n + tb->
rnum[0] - 1 == 0) {
837 if (n - tb->
rnum[0] <= item_pos) {
838 if (item_pos == n - tb->
rnum[0] && tb->
rbytes != -1) {
843 "PAP-12145: invalid parameter in case of a directory");
848 if (entry_count - tb->
rbytes <
852 int paste_entry_position;
858 "PAP-12150: no enough of entries to shift to R[0]: rbytes=%d, entry_count=%d",
870 paste_entry_position =
874 buffer_info_init_right(tb, &
bi);
877 paste_entry_position,
883 paste_entry_position,
897 if (paste_entry_position
940 "PAP-12155: invalid position to paste. ih_item_len=%d, pos_in_item=%d",
957 unsigned long temp_rem =
964 if (is_indirect_le_key
1002 (tb, tb->
CFR[0], 0);
1005 buffer_info_init_right(tb, &
bi);
1006 if (n_rem > zeros_num) {
1028 if (is_indirect_le_ih
1033 "PAP-12160: paste more than one unformatted node pointer");
1051 if (pos_in_item >= 0) {
1052 buffer_info_init_right(tb, &
bi);
1070 if (is_direntry_le_ih(pasted)
1071 && pos_in_item >= 0) {
1091 "PAP-12165: directory item must be first item of node when pasting is in 0th position");
1102 if (is_indirect_le_ih(pasted))
1113 "rnum > 0: unexpected mode: %s(%d)",
1125 "PAP-12180: blknum can not be %d. It must be <= 3",
1128 "PAP-12185: blknum can not be %d. It must be >= 0",
1134 if (tb->
blknum[0] == 0) {
1137 "PAP-12190: lnum and rnum must not be zero");
1144 "CFR not initialized");
1161 for (i = tb->
blknum[0] - 2; i >= 0; i--) {
1163 RFALSE(!snum[i],
"PAP-12200: snum[%d] == %d. Must be > 0", i,
1178 if (n - snum[i] < item_pos) {
1179 if (item_pos == n - snum[i] + 1 && sbytes[i] != -1) {
1180 int old_key_comp, old_len,
1191 old_key_comp = le_ih_k_offset(ih);
1195 set_le_ih_k_offset(ih,
1196 le_ih_k_offset(ih) +
1208 buffer_info_init_bh(tb, &
bi, S_new[i]);
1210 if ((old_len - sbytes[i]) > zeros_num) {
1219 zeros_num - (old_len -
1221 zeros_num -= r_zeros_number;
1228 set_le_ih_k_offset(ih, old_key_comp);
1230 old_len - sbytes[i]);
1236 snum[i] - 1, sbytes[i],
1240 buffer_info_init_bh(tb, &
bi, S_new[i]);
1253 snum[i], sbytes[i], S_new[i]);
1259 if (n - snum[i] <= item_pos) {
1260 if (item_pos == n - snum[i] && sbytes[i] != -1) {
1263 RFALSE(ih,
"PAP-12210: ih must be 0");
1266 if (is_direntry_le_ih(aux_ih)) {
1274 if (entry_count - sbytes[i] <
1282 "PAP-12215: insert_size is already 0");
1285 "PAP-12220: there are no so much entries (%d), only %d",
1296 buffer_info_init_bh(tb, &
bi, S_new[i]);
1346 "PAP-12225: item too short or insert_size <= 0");
1366 buffer_info_init_bh(tb, &
bi, S_new[i]);
1367 if (n_rem > zeros_num) {
1395 if (is_indirect_le_ih
1428 #ifdef CONFIG_REISERFS_CHECK
1432 if (!is_direntry_le_ih(ih_check)
1449 "PAP-12240: unexpected value returned by leaf_move_items (%d)",
1453 buffer_info_init_bh(tb, &
bi, S_new[i]);
1465 if (is_direntry_le_ih(pasted)) {
1483 if (is_indirect_le_ih(pasted))
1492 snum[i], sbytes[i], S_new[i]);
1497 "blknum > 2: unexpected mode: %s(%d)",
1506 insert_ptr[
i] = S_new[
i];
1508 RFALSE(!buffer_journaled(S_new[i])
1509 || buffer_journal_dirty(S_new[i])
1510 || buffer_dirty(S_new[i]),
"PAP-12247: S_new[%d] : (%b)",
1516 if (0 <= item_pos && item_pos < tb->s0num) {
1520 buffer_info_init_tbS0(tb, &
bi);
1525 if (item_pos == 0) {
1538 if (is_direntry_le_ih(pasted)) {
1539 if (pos_in_item >= 0 &&
1544 "PAP-12260: insert_size is 0 already");
1547 buffer_info_init_tbS0(tb, &
bi);
1570 if (!item_pos && !pos_in_item) {
1573 "PAP-12270: CFL[0]/L[0] must be specified");
1593 "PAP-12275: insert size must not be %d",
1595 buffer_info_init_tbS0(tb, &
bi);
1604 if (is_indirect_le_ih(pasted)) {
1609 "PAP-12280: insert_size for indirect item must be %d, not %d",
1619 #ifdef CONFIG_REISERFS_CHECK
1638 #ifdef CONFIG_REISERFS_CHECK
1642 "PAP-12290",
"insert_size is still not 0 (%d)",
1654 RFALSE(bi->
bi_bh ==
NULL,
"PAP-12295: pointer to the buffer is NULL");
1674 if (i == MAX_FEB_SIZE)
1677 buffer_info_init_bh(tb, &bi, tb->
FEB[i]);
1679 set_buffer_uptodate(tb->
FEB[i]);
1689 static void store_thrown(
struct tree_balance *tb,
struct buffer_head *bh)
1693 if (buffer_dirty(bh))
1695 "called with dirty buffer");
1703 "too many thrown buffers");
1712 blocknr = tb->
thrown[
i]->b_blocknr;
1713 if (buffer_dirty(tb->
thrown[i]))
1715 "called with dirty buffer %d",
1731 clear_buffer_dirty(bh);
1732 store_thrown(tb, bh);
1737 struct buffer_head *
src,
int n_src)
1741 "vs-12305: source or destination buffer is 0 (src=%p, dest=%p)",
1744 "vs-12310: invalid level (%z) for destination buffer. dest must be leaf",
1746 RFALSE(n_dest < 0 || n_src < 0,
1747 "vs-12315: src(%d) or dest(%d) key number < 0", n_src, n_dest);
1749 "vs-12320: src(%d(%d)) or dest(%d(%d)) key number is too big",
1768 "vs-12325: FL[%d](%p) or F[%d](%p) does not exist",
1771 if (Sh_position == 0)
1774 return Sh_position - 1;
1782 "vs-12330: F[%d](%p) or FR[%d](%p) does not exist",
1788 return Sh_position + 1;
1791 #ifdef CONFIG_REISERFS_CHECK
1794 static void check_internal_node(
struct super_block *
s,
struct buffer_head *bh,
1800 RFALSE(!bh,
"PAP-12336: bh == 0");
1805 RFALSE(!buffer_dirty(bh) &&
1806 !(buffer_journaled(bh) || buffer_journal_dirty(bh)),
1807 "PAP-12337: buffer (%b) must be dirty", bh);
1810 for (i = 0; i <=
B_NR_ITEMS(bh); i++, dc++) {
1814 "invalid child pointer %y in %b",
1820 static int locked_or_not_in_tree(
struct tree_balance *tb,
1821 struct buffer_head *bh,
char *which)
1823 if ((!buffer_journal_prepared(bh) && buffer_locked(bh)) ||
1831 static int check_before_balancing(
struct tree_balance *tb)
1835 if (REISERFS_SB(tb->
tb_sb)->cur_tb) {
1837 "occurred based on cur_tb not being null at "
1838 "this point in code. do_balance cannot properly "
1839 "handle concurrent tree accesses on a same "
1846 retval |= locked_or_not_in_tree(tb, tb->
L[0],
"L[0]");
1847 retval |= locked_or_not_in_tree(tb, tb->
FL[0],
"FL[0]");
1848 retval |= locked_or_not_in_tree(tb, tb->
CFL[0],
"CFL[0]");
1852 retval |= locked_or_not_in_tree(tb, tb->
R[0],
"R[0]");
1853 retval |= locked_or_not_in_tree(tb, tb->
FR[0],
"FR[0]");
1854 retval |= locked_or_not_in_tree(tb, tb->
CFR[0],
"CFR[0]");
1864 static void check_after_balance_leaf(
struct tree_balance *tb)
1873 "shift to left was incorrect");
1883 "shift to right was incorrect");
1898 "B_FREE_SPACE (PATH_H_PBUFFER(tb->tb_path,0)) = %d; "
1899 "MAX_CHILD_SIZE (%d) - dc_size( %y, %d ) [%d] = %d",
1919 static void check_internal_levels(
struct tree_balance *tb)
1926 "BAD BUFFER ON PATH");
1928 check_internal_node(tb->
tb_sb, tb->
L[h],
"BAD L");
1930 check_internal_node(tb->
tb_sb, tb->
R[h],
"BAD R");
1970 static inline void do_balance_starts(
struct tree_balance *tb)
1980 RFALSE(check_before_balancing(tb),
"PAP-12340: locked buffers in TB");
1981 #ifdef CONFIG_REISERFS_CHECK
1982 REISERFS_SB(tb->
tb_sb)->cur_tb =
tb;
1986 static inline void do_balance_completed(
struct tree_balance *tb)
1989 #ifdef CONFIG_REISERFS_CHECK
1990 check_leaf_level(tb);
1991 check_internal_levels(tb);
2000 REISERFS_SB(tb->
tb_sb)->s_do_balance++;
2036 struct buffer_head *insert_ptr[2];
2049 "insert_size == 0, mode == %c", flag);
2055 do_balance_starts(tb);
2061 balance_leaf(tb, ih, body, flag, insert_key, insert_ptr);
2063 #ifdef CONFIG_REISERFS_CHECK
2064 check_after_balance_leaf(tb);
2072 do_balance_completed(tb);