Lines Matching refs:tb

51 static void create_virtual_node(struct tree_balance *tb, int h)  in create_virtual_node()  argument
54 struct virtual_node *vn = tb->tb_vn; in create_virtual_node()
58 Sh = PATH_H_PBUFFER(tb->tb_path, h); in create_virtual_node()
62 MAX_CHILD_SIZE(Sh) - B_FREE_SPACE(Sh) + tb->insert_size[h]; in create_virtual_node()
76 vn->vn_vi = (struct virtual_item *)(tb->tb_vn + 1); in create_virtual_node()
115 op_create_vi(vn, vi, is_affected, tb->insert_size[0]); in create_virtual_node()
116 if (tb->vn_buf + tb->vn_buf_size < vn->vn_free_ptr) in create_virtual_node()
117 reiserfs_panic(tb->tb_sb, "vs-8030", in create_virtual_node()
125 vn->vn_vi[new_num].vi_item_len += tb->insert_size[0]; in create_virtual_node()
137 vi->vi_item_len = tb->insert_size[0]; in create_virtual_node()
143 tb->insert_size[0]); in create_virtual_node()
150 if (tb->CFR[0]) { in create_virtual_node()
153 key = internal_key(tb->CFR[0], tb->rkey[0]); in create_virtual_node()
178 reiserfs_panic(tb->tb_sb, "vs-8045", in create_virtual_node()
194 static void check_left(struct tree_balance *tb, int h, int cur_free) in check_left() argument
197 struct virtual_node *vn = tb->tb_vn; in check_left()
205 tb->lnum[h] = cur_free / (DC_SIZE + KEY_SIZE); in check_left()
213 tb->lnum[h] = 0; in check_left()
214 tb->lbytes = -1; in check_left()
218 RFALSE(!PATH_H_PPARENT(tb->tb_path, 0), in check_left()
230 tb->lnum[0] = vn->vn_nr_item; in check_left()
231 tb->lbytes = -1; in check_left()
241 tb->lnum[0] = 0; in check_left()
248 tb->lnum[0]++; in check_left()
260 tb->lbytes = -1; in check_left()
265 tb->lbytes = op_check_left(vi, cur_free, 0, 0); in check_left()
266 if (tb->lbytes != -1) in check_left()
268 tb->lnum[0]++; in check_left()
280 static void check_right(struct tree_balance *tb, int h, int cur_free) in check_right() argument
283 struct virtual_node *vn = tb->tb_vn; in check_right()
291 tb->rnum[h] = cur_free / (DC_SIZE + KEY_SIZE); in check_right()
299 tb->rnum[h] = 0; in check_right()
300 tb->rbytes = -1; in check_right()
304 RFALSE(!PATH_H_PPARENT(tb->tb_path, 0), in check_right()
316 tb->rnum[h] = vn->vn_nr_item; in check_right()
317 tb->rbytes = -1; in check_right()
327 tb->rnum[0] = 0; in check_right()
334 tb->rnum[0]++; in check_right()
345 tb->rbytes = -1; in check_right()
355 tb->rbytes = op_check_right(vi, cur_free); in check_right()
356 if (tb->rbytes != -1) in check_right()
358 tb->rnum[0]++; in check_right()
374 static int get_num_ver(int mode, struct tree_balance *tb, int h, in get_num_ver() argument
380 struct virtual_node *vn = tb->tb_vn; in get_num_ver()
417 RFALSE(tb->insert_size[h] < 0 || (mode != M_INSERT && mode != M_PASTE), in get_num_ver()
420 max_node_size = MAX_CHILD_SIZE(PATH_H_PBUFFER(tb->tb_path, h)); in get_num_ver()
532 reiserfs_warning(tb->tb_sb, "vs-8111", in get_num_ver()
571 reiserfs_warning(tb->tb_sb, "vs-8115", in get_num_ver()
621 static void set_parameters(struct tree_balance *tb, int h, int lnum, in set_parameters() argument
625 tb->lnum[h] = lnum; in set_parameters()
626 tb->rnum[h] = rnum; in set_parameters()
627 tb->blknum[h] = blk_num; in set_parameters()
632 tb->s0num = *s012++; in set_parameters()
633 tb->snum[0] = *s012++; in set_parameters()
634 tb->snum[1] = *s012++; in set_parameters()
635 tb->sbytes[0] = *s012++; in set_parameters()
636 tb->sbytes[1] = *s012; in set_parameters()
638 tb->lbytes = lb; in set_parameters()
639 tb->rbytes = rb; in set_parameters()
641 PROC_INFO_ADD(tb->tb_sb, lnum[h], lnum); in set_parameters()
642 PROC_INFO_ADD(tb->tb_sb, rnum[h], rnum); in set_parameters()
644 PROC_INFO_ADD(tb->tb_sb, lbytes[h], lb); in set_parameters()
645 PROC_INFO_ADD(tb->tb_sb, rbytes[h], rb); in set_parameters()
652 static int is_leaf_removable(struct tree_balance *tb) in is_leaf_removable() argument
654 struct virtual_node *vn = tb->tb_vn; in is_leaf_removable()
663 to_left = tb->lnum[0] - ((tb->lbytes != -1) ? 1 : 0); in is_leaf_removable()
664 to_right = tb->rnum[0] - ((tb->rbytes != -1) ? 1 : 0); in is_leaf_removable()
672 set_parameters(tb, 0, to_left, vn->vn_nr_item - to_left, 0, in is_leaf_removable()
678 if (remain_items > 1 || tb->lbytes == -1 || tb->rbytes == -1) in is_leaf_removable()
686 if (tb->lbytes + tb->rbytes >= size) { in is_leaf_removable()
687 set_parameters(tb, 0, to_left + 1, to_right + 1, 0, NULL, in is_leaf_removable()
688 tb->lbytes, -1); in is_leaf_removable()
696 static int are_leaves_removable(struct tree_balance *tb, int lfree, int rfree) in are_leaves_removable() argument
698 struct virtual_node *vn = tb->tb_vn; in are_leaves_removable()
702 S0 = PATH_H_PBUFFER(tb->tb_path, 0); in are_leaves_removable()
721 if (tb->CFR[0] in are_leaves_removable()
723 internal_key(tb->CFR[0], in are_leaves_removable()
724 tb->rkey[0]))) in are_leaves_removable()
749 set_parameters(tb, 0, -1, -1, -1, NULL, -1, -1); in are_leaves_removable()
750 PROC_INFO_INC(tb->tb_sb, leaves_removable); in are_leaves_removable()
766 set_parameters (tb, h, to_l, 0, lnver, NULL, -1, -1);\
771 set_parameters (tb, h, lpar, 0, lnver, snum012+lset,\
772 tb->lbytes, -1);\
774 set_parameters (tb, h, lpar - (tb->lbytes!=-1), 0, lnver, snum012+lset,\
785 set_parameters (tb, h, 0, to_r, rnver, NULL, -1, -1);\
790 set_parameters (tb, h, 0, rpar, rnver, snum012+rset,\
791 -1, tb->rbytes);\
793 set_parameters (tb, h, 0, rpar - (tb->rbytes!=-1), rnver, snum012+rset,\
797 static void free_buffers_in_tb(struct tree_balance *tb) in free_buffers_in_tb() argument
801 pathrelse(tb->tb_path); in free_buffers_in_tb()
804 brelse(tb->L[i]); in free_buffers_in_tb()
805 brelse(tb->R[i]); in free_buffers_in_tb()
806 brelse(tb->FL[i]); in free_buffers_in_tb()
807 brelse(tb->FR[i]); in free_buffers_in_tb()
808 brelse(tb->CFL[i]); in free_buffers_in_tb()
809 brelse(tb->CFR[i]); in free_buffers_in_tb()
811 tb->L[i] = NULL; in free_buffers_in_tb()
812 tb->R[i] = NULL; in free_buffers_in_tb()
813 tb->FL[i] = NULL; in free_buffers_in_tb()
814 tb->FR[i] = NULL; in free_buffers_in_tb()
815 tb->CFL[i] = NULL; in free_buffers_in_tb()
816 tb->CFR[i] = NULL; in free_buffers_in_tb()
827 static int get_empty_nodes(struct tree_balance *tb, int h) in get_empty_nodes() argument
829 struct buffer_head *new_bh, *Sh = PATH_H_PBUFFER(tb->tb_path, h); in get_empty_nodes()
834 struct super_block *sb = tb->tb_sb; in get_empty_nodes()
857 for (counter = 0, number_of_freeblk = tb->cur_blknum; in get_empty_nodes()
860 (tb->blknum[counter]) ? (tb->blknum[counter] - in get_empty_nodes()
865 amount_needed = (Sh) ? (tb->blknum[h] - 1) : 1; in get_empty_nodes()
879 if (reiserfs_new_form_blocknrs(tb, blocknrs, in get_empty_nodes()
898 RFALSE(tb->FEB[tb->cur_blknum], in get_empty_nodes()
902 tb->FEB[tb->cur_blknum++] = new_bh; in get_empty_nodes()
905 if (retval == CARRY_ON && FILESYSTEM_CHANGED_TB(tb)) in get_empty_nodes()
915 static int get_lfree(struct tree_balance *tb, int h) in get_lfree() argument
920 if ((f = PATH_H_PPARENT(tb->tb_path, h)) == NULL || in get_lfree()
921 (l = tb->FL[h]) == NULL) in get_lfree()
925 order = PATH_H_B_ITEM_ORDER(tb->tb_path, h) - 1; in get_lfree()
938 static int get_rfree(struct tree_balance *tb, int h) in get_rfree() argument
943 if ((f = PATH_H_PPARENT(tb->tb_path, h)) == NULL || in get_rfree()
944 (r = tb->FR[h]) == NULL) in get_rfree()
948 order = PATH_H_B_ITEM_ORDER(tb->tb_path, h) + 1; in get_rfree()
959 static int is_left_neighbor_in_cache(struct tree_balance *tb, int h) in is_left_neighbor_in_cache() argument
962 struct super_block *sb = tb->tb_sb; in is_left_neighbor_in_cache()
967 if (!tb->FL[h]) in is_left_neighbor_in_cache()
971 father = PATH_H_PBUFFER(tb->tb_path, h + 1); in is_left_neighbor_in_cache()
975 !B_IS_IN_TREE(tb->FL[h]) || in is_left_neighbor_in_cache()
977 !buffer_uptodate(tb->FL[h]), in is_left_neighbor_in_cache()
979 father, tb->FL[h]); in is_left_neighbor_in_cache()
985 left_neighbor_position = (father == tb->FL[h]) ? in is_left_neighbor_in_cache()
986 tb->lkey[h] : B_NR_ITEMS(tb->FL[h]); in is_left_neighbor_in_cache()
989 B_N_CHILD_NUM(tb->FL[h], left_neighbor_position); in is_left_neighbor_in_cache()
1023 static int get_far_parent(struct tree_balance *tb, in get_far_parent() argument
1030 struct treepath *path = tb->tb_path; in get_far_parent()
1092 (tb->tb_path, in get_far_parent()
1094 SB_ROOT_BLOCK(tb->tb_sb)) { in get_far_parent()
1110 int depth = reiserfs_write_unlock_nested(tb->tb_sb); in get_far_parent()
1112 reiserfs_write_lock_nested(tb->tb_sb, depth); in get_far_parent()
1113 if (FILESYSTEM_CHANGED_TB(tb)) { in get_far_parent()
1129 LEFT_PARENTS) ? (tb->lkey[h - 1] = in get_far_parent()
1131 1) : (tb->rkey[h - in get_far_parent()
1139 (tb->tb_sb, &s_lr_father_key, &s_path_to_neighbor_father, in get_far_parent()
1144 if (FILESYSTEM_CHANGED_TB(tb)) { in get_far_parent()
1172 static int get_parents(struct tree_balance *tb, int h) in get_parents() argument
1174 struct treepath *path = tb->tb_path; in get_parents()
1177 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h); in get_parents()
1187 brelse(tb->FL[h]); in get_parents()
1188 brelse(tb->CFL[h]); in get_parents()
1189 brelse(tb->FR[h]); in get_parents()
1190 brelse(tb->CFR[h]); in get_parents()
1191 tb->FL[h] = NULL; in get_parents()
1192 tb->CFL[h] = NULL; in get_parents()
1193 tb->FR[h] = NULL; in get_parents()
1194 tb->CFR[h] = NULL; in get_parents()
1206 tb->lkey[h] = position - 1; in get_parents()
1216 if ((ret = get_far_parent(tb, h + 1, &curf, in get_parents()
1222 brelse(tb->FL[h]); in get_parents()
1223 tb->FL[h] = curf; /* New initialization of FL[h]. */ in get_parents()
1224 brelse(tb->CFL[h]); in get_parents()
1225 tb->CFL[h] = curcf; /* New initialization of CFL[h]. */ in get_parents()
1242 get_far_parent(tb, h + 1, &curf, &curcf, in get_parents()
1251 tb->rkey[h] = position; in get_parents()
1254 brelse(tb->FR[h]); in get_parents()
1256 tb->FR[h] = curf; in get_parents()
1258 brelse(tb->CFR[h]); in get_parents()
1260 tb->CFR[h] = curcf; in get_parents()
1274 struct tree_balance *tb, int h) in can_node_be_removed() argument
1276 struct buffer_head *Sh = PATH_H_PBUFFER(tb->tb_path, h); in can_node_be_removed()
1277 int levbytes = tb->insert_size[h]; in can_node_be_removed()
1282 if (tb->CFR[h]) in can_node_be_removed()
1283 r_key = internal_key(tb->CFR[h], tb->rkey[h]); in can_node_be_removed()
1298 tb->s0num = in can_node_be_removed()
1301 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); in can_node_be_removed()
1305 PROC_INFO_INC(tb->tb_sb, can_node_be_removed[h]); in can_node_be_removed()
1324 static int ip_check_balance(struct tree_balance *tb, int h) in ip_check_balance() argument
1326 struct virtual_node *vn = tb->tb_vn; in ip_check_balance()
1373 Sh = PATH_H_PBUFFER(tb->tb_path, h); in ip_check_balance()
1374 levbytes = tb->insert_size[h]; in ip_check_balance()
1379 reiserfs_panic(tb->tb_sb, "vs-8210", in ip_check_balance()
1381 switch (ret = get_empty_nodes(tb, h)) { in ip_check_balance()
1384 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); in ip_check_balance()
1391 reiserfs_panic(tb->tb_sb, "vs-8215", "incorrect " in ip_check_balance()
1397 ret = get_parents(tb, h); in ip_check_balance()
1404 rfree = get_rfree(tb, h); in ip_check_balance()
1405 lfree = get_lfree(tb, h); in ip_check_balance()
1408 if (can_node_be_removed(vn->vn_mode, lfree, sfree, rfree, tb, h) == in ip_check_balance()
1412 create_virtual_node(tb, h); in ip_check_balance()
1420 check_left(tb, h, lfree); in ip_check_balance()
1428 check_right(tb, h, rfree); in ip_check_balance()
1434 if (h && (tb->rnum[h] + tb->lnum[h] >= vn->vn_nr_item + 1)) { in ip_check_balance()
1446 ((MAX_NR_KEY(Sh) << 1) + 2 - tb->lnum[h] - tb->rnum[h] + in ip_check_balance()
1448 tb->rnum[h]); in ip_check_balance()
1449 set_parameters(tb, h, vn->vn_nr_item + 1 - to_r, to_r, 0, NULL, in ip_check_balance()
1459 (tb->lnum[h] >= vn->vn_nr_item + 1 || in ip_check_balance()
1460 tb->rnum[h] >= vn->vn_nr_item + 1), in ip_check_balance()
1462 RFALSE(!h && ((tb->lnum[h] >= vn->vn_nr_item && (tb->lbytes == -1)) || in ip_check_balance()
1463 (tb->rnum[h] >= vn->vn_nr_item && (tb->rbytes == -1))), in ip_check_balance()
1470 if (!h && is_leaf_removable(tb)) in ip_check_balance()
1483 tb->s0num = vn->vn_nr_item; in ip_check_balance()
1484 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); in ip_check_balance()
1512 lpar = tb->lnum[h]; in ip_check_balance()
1513 rpar = tb->rnum[h]; in ip_check_balance()
1523 nver = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1534 nver1 = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1550 lnver = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1551 lpar - ((h || tb->lbytes == -1) ? 0 : 1), in ip_check_balance()
1557 lnver1 = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1559 ((tb->lbytes != -1) ? 1 : 0), in ip_check_balance()
1560 tb->lbytes, 0, -1, in ip_check_balance()
1575 rnver = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1578 ((tb-> in ip_check_balance()
1586 rnver1 = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1589 ((tb->rbytes != -1) ? 1 : 0)), in ip_check_balance()
1590 tb->rbytes, in ip_check_balance()
1605 lrnver = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1606 lpar - ((h || tb->lbytes == -1) ? 0 : 1), in ip_check_balance()
1609 ((tb-> in ip_check_balance()
1617 lrnver1 = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1619 ((tb->lbytes != -1) ? 1 : 0), in ip_check_balance()
1620 tb->lbytes, in ip_check_balance()
1622 ((tb->rbytes != -1) ? 1 : 0)), in ip_check_balance()
1623 tb->rbytes, in ip_check_balance()
1639 (tb->lnum[h] != 1 || in ip_check_balance()
1640 tb->rnum[h] != 1 || in ip_check_balance()
1644 set_parameters(tb, h, tb->lnum[h], tb->rnum[h], in ip_check_balance()
1646 tb->lbytes, tb->rbytes); in ip_check_balance()
1648 set_parameters(tb, h, in ip_check_balance()
1649 tb->lnum[h] - in ip_check_balance()
1650 ((tb->lbytes == -1) ? 0 : 1), in ip_check_balance()
1651 tb->rnum[h] - in ip_check_balance()
1652 ((tb->rbytes == -1) ? 0 : 1), in ip_check_balance()
1663 set_parameters(tb, h, 0, 0, nver, snum012 + nset, -1, in ip_check_balance()
1695 if (is_left_neighbor_in_cache(tb, h)) { in ip_check_balance()
1726 static int dc_check_balance_internal(struct tree_balance *tb, int h) in dc_check_balance_internal() argument
1728 struct virtual_node *vn = tb->tb_vn; in dc_check_balance_internal()
1738 Sh = PATH_H_PBUFFER(tb->tb_path, h); in dc_check_balance_internal()
1739 Fh = PATH_H_PPARENT(tb->tb_path, h); in dc_check_balance_internal()
1747 create_virtual_node(tb, h); in dc_check_balance_internal()
1752 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); in dc_check_balance_internal()
1760 set_parameters(tb, h, 0, 0, 0, NULL, -1, -1); in dc_check_balance_internal()
1764 if ((ret = get_parents(tb, h)) != CARRY_ON) in dc_check_balance_internal()
1768 rfree = get_rfree(tb, h); in dc_check_balance_internal()
1769 lfree = get_lfree(tb, h); in dc_check_balance_internal()
1772 check_left(tb, h, lfree); in dc_check_balance_internal()
1773 check_right(tb, h, rfree); in dc_check_balance_internal()
1786 if (tb->lnum[h] >= vn->vn_nr_item + 1) { in dc_check_balance_internal()
1792 PATH_H_B_ITEM_ORDER(tb->tb_path, in dc_check_balance_internal()
1794 0) ? B_NR_ITEMS(tb->FL[h]) : n - 1; in dc_check_balance_internal()
1795 n = dc_size(B_N_CHILD(tb->FL[h], order_L)) / in dc_check_balance_internal()
1797 set_parameters(tb, h, -n - 1, 0, 0, NULL, -1, in dc_check_balance_internal()
1803 if (tb->rnum[h] >= vn->vn_nr_item + 1) { in dc_check_balance_internal()
1809 PATH_H_B_ITEM_ORDER(tb->tb_path, in dc_check_balance_internal()
1812 n = dc_size(B_N_CHILD(tb->FR[h], order_R)) / in dc_check_balance_internal()
1814 set_parameters(tb, h, 0, -n - 1, 0, NULL, -1, in dc_check_balance_internal()
1824 if (tb->rnum[h] + tb->lnum[h] >= vn->vn_nr_item + 1) { in dc_check_balance_internal()
1828 ((MAX_NR_KEY(Sh) << 1) + 2 - tb->lnum[h] - in dc_check_balance_internal()
1829 tb->rnum[h] + vn->vn_nr_item + 1) / 2 - in dc_check_balance_internal()
1830 (MAX_NR_KEY(Sh) + 1 - tb->rnum[h]); in dc_check_balance_internal()
1831 set_parameters(tb, h, vn->vn_nr_item + 1 - to_r, to_r, in dc_check_balance_internal()
1837 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); in dc_check_balance_internal()
1846 if (tb->lnum[h] >= vn->vn_nr_item + 1) in dc_check_balance_internal()
1847 if (is_left_neighbor_in_cache(tb, h) in dc_check_balance_internal()
1848 || tb->rnum[h] < vn->vn_nr_item + 1 || !tb->FR[h]) { in dc_check_balance_internal()
1854 PATH_H_B_ITEM_ORDER(tb->tb_path, in dc_check_balance_internal()
1856 0) ? B_NR_ITEMS(tb->FL[h]) : n - 1; in dc_check_balance_internal()
1857 n = dc_size(B_N_CHILD(tb->FL[h], order_L)) / (DC_SIZE + in dc_check_balance_internal()
1859 set_parameters(tb, h, -n - 1, 0, 0, NULL, -1, -1); in dc_check_balance_internal()
1864 if (tb->rnum[h] >= vn->vn_nr_item + 1) { in dc_check_balance_internal()
1870 PATH_H_B_ITEM_ORDER(tb->tb_path, in dc_check_balance_internal()
1872 n = dc_size(B_N_CHILD(tb->FR[h], order_R)) / (DC_SIZE + in dc_check_balance_internal()
1874 set_parameters(tb, h, 0, -n - 1, 0, NULL, -1, -1); in dc_check_balance_internal()
1879 if (tb->rnum[h] + tb->lnum[h] >= vn->vn_nr_item + 1) { in dc_check_balance_internal()
1883 ((MAX_NR_KEY(Sh) << 1) + 2 - tb->lnum[h] - tb->rnum[h] + in dc_check_balance_internal()
1885 tb->rnum[h]); in dc_check_balance_internal()
1886 set_parameters(tb, h, vn->vn_nr_item + 1 - to_r, to_r, 0, NULL, in dc_check_balance_internal()
1892 RFALSE(!tb->FL[h] && !tb->FR[h], "vs-8235: trying to borrow for root"); in dc_check_balance_internal()
1895 if (is_left_neighbor_in_cache(tb, h) || !tb->FR[h]) { in dc_check_balance_internal()
1899 (MAX_NR_KEY(Sh) + 1 - tb->lnum[h] + vn->vn_nr_item + in dc_check_balance_internal()
1901 set_parameters(tb, h, -from_l, 0, 1, NULL, -1, -1); in dc_check_balance_internal()
1905 set_parameters(tb, h, 0, in dc_check_balance_internal()
1906 -((MAX_NR_KEY(Sh) + 1 - tb->rnum[h] + vn->vn_nr_item + in dc_check_balance_internal()
1925 static int dc_check_balance_leaf(struct tree_balance *tb, int h) in dc_check_balance_leaf() argument
1927 struct virtual_node *vn = tb->tb_vn; in dc_check_balance_leaf()
1947 S0 = PATH_H_PBUFFER(tb->tb_path, 0); in dc_check_balance_leaf()
1948 F0 = PATH_H_PPARENT(tb->tb_path, 0); in dc_check_balance_leaf()
1950 levbytes = tb->insert_size[h]; in dc_check_balance_leaf()
1959 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); in dc_check_balance_leaf()
1963 if ((ret = get_parents(tb, h)) != CARRY_ON) in dc_check_balance_leaf()
1967 rfree = get_rfree(tb, h); in dc_check_balance_leaf()
1968 lfree = get_lfree(tb, h); in dc_check_balance_leaf()
1970 create_virtual_node(tb, h); in dc_check_balance_leaf()
1973 if (are_leaves_removable(tb, lfree, rfree)) in dc_check_balance_leaf()
1982 check_left(tb, h, lfree); in dc_check_balance_leaf()
1983 check_right(tb, h, rfree); in dc_check_balance_leaf()
1986 if (tb->lnum[0] >= vn->vn_nr_item && tb->lbytes == -1) in dc_check_balance_leaf()
1987 …if (is_left_neighbor_in_cache(tb, h) || ((tb->rnum[0] - ((tb->rbytes == -1) ? 0 : 1)) < vn->vn_nr_… in dc_check_balance_leaf()
1988 !tb->FR[h]) { in dc_check_balance_leaf()
1990 RFALSE(!tb->FL[h], in dc_check_balance_leaf()
1994 set_parameters(tb, h, -1, 0, 0, NULL, -1, -1); in dc_check_balance_leaf()
1999 if (tb->rnum[0] >= vn->vn_nr_item && tb->rbytes == -1) { in dc_check_balance_leaf()
2000 set_parameters(tb, h, 0, -1, 0, NULL, -1, -1); in dc_check_balance_leaf()
2008 if (is_leaf_removable(tb)) in dc_check_balance_leaf()
2012 tb->s0num = vn->vn_nr_item; in dc_check_balance_leaf()
2013 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); in dc_check_balance_leaf()
2031 static int dc_check_balance(struct tree_balance *tb, int h) in dc_check_balance() argument
2033 RFALSE(!(PATH_H_PBUFFER(tb->tb_path, h)), in dc_check_balance()
2037 return dc_check_balance_internal(tb, h); in dc_check_balance()
2039 return dc_check_balance_leaf(tb, h); in dc_check_balance()
2062 struct tree_balance *tb, in check_balance() argument
2070 vn = tb->tb_vn = (struct virtual_node *)(tb->vn_buf); in check_balance()
2071 vn->vn_free_ptr = (char *)(tb->tb_vn + 1); in check_balance()
2082 if (tb->insert_size[h] > 0) in check_balance()
2083 return ip_check_balance(tb, h); in check_balance()
2086 return dc_check_balance(tb, h); in check_balance()
2090 static int get_direct_parent(struct tree_balance *tb, int h) in get_direct_parent() argument
2093 struct treepath *path = tb->tb_path; in get_direct_parent()
2095 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h); in get_direct_parent()
2104 b_blocknr == SB_ROOT_BLOCK(tb->tb_sb)) { in get_direct_parent()
2130 int depth = reiserfs_write_unlock_nested(tb->tb_sb); in get_direct_parent()
2132 reiserfs_write_lock_nested(tb->tb_sb, depth); in get_direct_parent()
2133 if (FILESYSTEM_CHANGED_TB(tb)) in get_direct_parent()
2151 static int get_neighbors(struct tree_balance *tb, int h) in get_neighbors() argument
2154 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h + 1); in get_neighbors()
2156 struct super_block *sb = tb->tb_sb; in get_neighbors()
2162 if (tb->lnum[h]) { in get_neighbors()
2165 bh = PATH_OFFSET_PBUFFER(tb->tb_path, path_offset); in get_neighbors()
2167 RFALSE(bh == tb->FL[h] && in get_neighbors()
2168 !PATH_OFFSET_POSITION(tb->tb_path, path_offset), in get_neighbors()
2173 tb->FL[h]) ? tb->lkey[h] : B_NR_ITEMS(tb-> in get_neighbors()
2175 son_number = B_N_CHILD_NUM(tb->FL[h], child_position); in get_neighbors()
2176 depth = reiserfs_write_unlock_nested(tb->tb_sb); in get_neighbors()
2178 reiserfs_write_lock_nested(tb->tb_sb, depth); in get_neighbors()
2181 if (FILESYSTEM_CHANGED_TB(tb)) { in get_neighbors()
2187 RFALSE(!B_IS_IN_TREE(tb->FL[h]) || in get_neighbors()
2188 child_position > B_NR_ITEMS(tb->FL[h]) || in get_neighbors()
2189 B_N_CHILD_NUM(tb->FL[h], child_position) != in get_neighbors()
2195 dc_size(B_N_CHILD(tb->FL[0], child_position)), in get_neighbors()
2198 brelse(tb->L[h]); in get_neighbors()
2199 tb->L[h] = bh; in get_neighbors()
2203 if (tb->rnum[h]) { in get_neighbors()
2205 bh = PATH_OFFSET_PBUFFER(tb->tb_path, path_offset); in get_neighbors()
2207 RFALSE(bh == tb->FR[h] && in get_neighbors()
2208 PATH_OFFSET_POSITION(tb->tb_path, in get_neighbors()
2214 (bh == tb->FR[h]) ? tb->rkey[h] + 1 : 0; in get_neighbors()
2215 son_number = B_N_CHILD_NUM(tb->FR[h], child_position); in get_neighbors()
2216 depth = reiserfs_write_unlock_nested(tb->tb_sb); in get_neighbors()
2218 reiserfs_write_lock_nested(tb->tb_sb, depth); in get_neighbors()
2221 if (FILESYSTEM_CHANGED_TB(tb)) { in get_neighbors()
2226 brelse(tb->R[h]); in get_neighbors()
2227 tb->R[h] = bh; in get_neighbors()
2232 dc_size(B_N_CHILD(tb->FR[0], child_position)), in get_neighbors()
2235 dc_size(B_N_CHILD(tb->FR[0], child_position))); in get_neighbors()
2265 static int get_mem_for_virtual_node(struct tree_balance *tb) in get_mem_for_virtual_node() argument
2271 size = get_virtual_node_size(tb->tb_sb, PATH_PLAST_BUFFER(tb->tb_path)); in get_mem_for_virtual_node()
2274 if (size > tb->vn_buf_size) { in get_mem_for_virtual_node()
2275 if (tb->vn_buf) { in get_mem_for_virtual_node()
2277 kfree(tb->vn_buf); in get_mem_for_virtual_node()
2283 tb->vn_buf_size = size; in get_mem_for_virtual_node()
2294 free_buffers_in_tb(tb); in get_mem_for_virtual_node()
2297 tb->vn_buf_size = 0; in get_mem_for_virtual_node()
2299 tb->vn_buf = buf; in get_mem_for_virtual_node()
2304 tb->vn_buf = buf; in get_mem_for_virtual_node()
2307 if (check_fs && FILESYSTEM_CHANGED_TB(tb)) in get_mem_for_virtual_node()
2364 static int wait_tb_buffers_until_unlocked(struct tree_balance *tb) in wait_tb_buffers_until_unlocked() argument
2376 for (i = tb->tb_path->path_length; in wait_tb_buffers_until_unlocked()
2378 if (PATH_OFFSET_PBUFFER(tb->tb_path, i)) { in wait_tb_buffers_until_unlocked()
2385 if (PATH_PLAST_BUFFER(tb->tb_path) == in wait_tb_buffers_until_unlocked()
2386 PATH_OFFSET_PBUFFER(tb->tb_path, i)) in wait_tb_buffers_until_unlocked()
2387 tb_buffer_sanity_check(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2389 (tb->tb_path, in wait_tb_buffers_until_unlocked()
2391 tb->tb_path-> in wait_tb_buffers_until_unlocked()
2394 if (!clear_all_dirty_bits(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2396 (tb->tb_path, in wait_tb_buffers_until_unlocked()
2399 PATH_OFFSET_PBUFFER(tb->tb_path, in wait_tb_buffers_until_unlocked()
2405 for (i = 0; !locked && i < MAX_HEIGHT && tb->insert_size[i]; in wait_tb_buffers_until_unlocked()
2408 if (tb->lnum[i]) { in wait_tb_buffers_until_unlocked()
2410 if (tb->L[i]) { in wait_tb_buffers_until_unlocked()
2411 tb_buffer_sanity_check(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2412 tb->L[i], in wait_tb_buffers_until_unlocked()
2415 (tb->tb_sb, tb->L[i])) in wait_tb_buffers_until_unlocked()
2416 locked = tb->L[i]; in wait_tb_buffers_until_unlocked()
2419 if (!locked && tb->FL[i]) { in wait_tb_buffers_until_unlocked()
2420 tb_buffer_sanity_check(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2421 tb->FL[i], in wait_tb_buffers_until_unlocked()
2424 (tb->tb_sb, tb->FL[i])) in wait_tb_buffers_until_unlocked()
2425 locked = tb->FL[i]; in wait_tb_buffers_until_unlocked()
2428 if (!locked && tb->CFL[i]) { in wait_tb_buffers_until_unlocked()
2429 tb_buffer_sanity_check(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2430 tb->CFL[i], in wait_tb_buffers_until_unlocked()
2433 (tb->tb_sb, tb->CFL[i])) in wait_tb_buffers_until_unlocked()
2434 locked = tb->CFL[i]; in wait_tb_buffers_until_unlocked()
2439 if (!locked && (tb->rnum[i])) { in wait_tb_buffers_until_unlocked()
2441 if (tb->R[i]) { in wait_tb_buffers_until_unlocked()
2442 tb_buffer_sanity_check(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2443 tb->R[i], in wait_tb_buffers_until_unlocked()
2446 (tb->tb_sb, tb->R[i])) in wait_tb_buffers_until_unlocked()
2447 locked = tb->R[i]; in wait_tb_buffers_until_unlocked()
2450 if (!locked && tb->FR[i]) { in wait_tb_buffers_until_unlocked()
2451 tb_buffer_sanity_check(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2452 tb->FR[i], in wait_tb_buffers_until_unlocked()
2455 (tb->tb_sb, tb->FR[i])) in wait_tb_buffers_until_unlocked()
2456 locked = tb->FR[i]; in wait_tb_buffers_until_unlocked()
2459 if (!locked && tb->CFR[i]) { in wait_tb_buffers_until_unlocked()
2460 tb_buffer_sanity_check(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2461 tb->CFR[i], in wait_tb_buffers_until_unlocked()
2464 (tb->tb_sb, tb->CFR[i])) in wait_tb_buffers_until_unlocked()
2465 locked = tb->CFR[i]; in wait_tb_buffers_until_unlocked()
2480 if (tb->FEB[i]) { in wait_tb_buffers_until_unlocked()
2482 (tb->tb_sb, tb->FEB[i])) in wait_tb_buffers_until_unlocked()
2483 locked = tb->FEB[i]; in wait_tb_buffers_until_unlocked()
2492 reiserfs_warning(tb->tb_sb, "reiserfs-8200", in wait_tb_buffers_until_unlocked()
2499 return (FILESYSTEM_CHANGED_TB(tb)) ? in wait_tb_buffers_until_unlocked()
2503 depth = reiserfs_write_unlock_nested(tb->tb_sb); in wait_tb_buffers_until_unlocked()
2505 reiserfs_write_lock_nested(tb->tb_sb, depth); in wait_tb_buffers_until_unlocked()
2506 if (FILESYSTEM_CHANGED_TB(tb)) in wait_tb_buffers_until_unlocked()
2546 int fix_nodes(int op_mode, struct tree_balance *tb, in fix_nodes() argument
2549 int ret, h, item_num = PATH_LAST_POSITION(tb->tb_path); in fix_nodes()
2557 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); in fix_nodes()
2559 ++REISERFS_SB(tb->tb_sb)->s_fix_nodes; in fix_nodes()
2561 pos_in_item = tb->tb_path->pos_in_item; in fix_nodes()
2563 tb->fs_gen = get_generation(tb->tb_sb); in fix_nodes()
2571 reiserfs_prepare_for_journal(tb->tb_sb, in fix_nodes()
2572 SB_BUFFER_WITH_SB(tb->tb_sb), 1); in fix_nodes()
2573 journal_mark_dirty(tb->transaction_handle, in fix_nodes()
2574 SB_BUFFER_WITH_SB(tb->tb_sb)); in fix_nodes()
2575 if (FILESYSTEM_CHANGED_TB(tb)) in fix_nodes()
2580 int depth = reiserfs_write_unlock_nested(tb->tb_sb); in fix_nodes()
2582 reiserfs_write_lock_nested(tb->tb_sb, depth); in fix_nodes()
2583 if (FILESYSTEM_CHANGED_TB(tb)) in fix_nodes()
2587 if (REISERFS_SB(tb->tb_sb)->cur_tb) { in fix_nodes()
2589 reiserfs_panic(tb->tb_sb, "PAP-8305", in fix_nodes()
2594 reiserfs_panic(tb->tb_sb, "PAP-8320", "S[0] (%b %z) is " in fix_nodes()
2603 reiserfs_panic(tb->tb_sb, "PAP-8330", "Incorrect " in fix_nodes()
2613 reiserfs_panic(tb->tb_sb, "PAP-8335", "Incorrect " in fix_nodes()
2617 tb->insert_size[0]); in fix_nodes()
2621 reiserfs_panic(tb->tb_sb, "PAP-8340", "Incorrect mode " in fix_nodes()
2626 if (get_mem_for_virtual_node(tb) == REPEAT_SEARCH) in fix_nodes()
2631 for (h = 0; h < MAX_HEIGHT && tb->insert_size[h]; h++) { in fix_nodes()
2632 ret = get_direct_parent(tb, h); in fix_nodes()
2636 ret = check_balance(op_mode, tb, h, item_num, in fix_nodes()
2641 ret = get_neighbors(tb, h); in fix_nodes()
2645 tb->insert_size[h + 1] = 0; in fix_nodes()
2655 ret = get_neighbors(tb, h); in fix_nodes()
2663 ret = get_empty_nodes(tb, h); in fix_nodes()
2671 if (!PATH_H_PBUFFER(tb->tb_path, h)) { in fix_nodes()
2673 RFALSE(tb->blknum[h] != 1, in fix_nodes()
2677 tb->insert_size[h + 1] = 0; in fix_nodes()
2678 } else if (!PATH_H_PBUFFER(tb->tb_path, h + 1)) { in fix_nodes()
2685 if (tb->blknum[h] > 1) { in fix_nodes()
2690 tb->insert_size[h + 1] = in fix_nodes()
2692 KEY_SIZE) * (tb->blknum[h] - 1) + in fix_nodes()
2695 tb->insert_size[h + 1] = 0; in fix_nodes()
2697 tb->insert_size[h + 1] = in fix_nodes()
2698 (DC_SIZE + KEY_SIZE) * (tb->blknum[h] - 1); in fix_nodes()
2701 ret = wait_tb_buffers_until_unlocked(tb); in fix_nodes()
2703 if (FILESYSTEM_CHANGED_TB(tb)) { in fix_nodes()
2728 pathrelse_and_restore(tb->tb_sb, tb->tb_path); in fix_nodes()
2730 pathrelse(tb->tb_path); in fix_nodes()
2735 reiserfs_restore_prepared_buffer(tb->tb_sb, in fix_nodes()
2736 tb->L[i]); in fix_nodes()
2737 reiserfs_restore_prepared_buffer(tb->tb_sb, in fix_nodes()
2738 tb->R[i]); in fix_nodes()
2739 reiserfs_restore_prepared_buffer(tb->tb_sb, in fix_nodes()
2740 tb->FL[i]); in fix_nodes()
2741 reiserfs_restore_prepared_buffer(tb->tb_sb, in fix_nodes()
2742 tb->FR[i]); in fix_nodes()
2743 reiserfs_restore_prepared_buffer(tb->tb_sb, in fix_nodes()
2744 tb-> in fix_nodes()
2746 reiserfs_restore_prepared_buffer(tb->tb_sb, in fix_nodes()
2747 tb-> in fix_nodes()
2751 brelse(tb->L[i]); in fix_nodes()
2752 brelse(tb->R[i]); in fix_nodes()
2753 brelse(tb->FL[i]); in fix_nodes()
2754 brelse(tb->FR[i]); in fix_nodes()
2755 brelse(tb->CFL[i]); in fix_nodes()
2756 brelse(tb->CFR[i]); in fix_nodes()
2758 tb->L[i] = NULL; in fix_nodes()
2759 tb->R[i] = NULL; in fix_nodes()
2760 tb->FL[i] = NULL; in fix_nodes()
2761 tb->FR[i] = NULL; in fix_nodes()
2762 tb->CFL[i] = NULL; in fix_nodes()
2763 tb->CFR[i] = NULL; in fix_nodes()
2768 if (tb->FEB[i]) in fix_nodes()
2770 (tb->tb_sb, tb->FEB[i]); in fix_nodes()
2778 void unfix_nodes(struct tree_balance *tb) in unfix_nodes() argument
2783 pathrelse_and_restore(tb->tb_sb, tb->tb_path); in unfix_nodes()
2787 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->L[i]); in unfix_nodes()
2788 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->R[i]); in unfix_nodes()
2789 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->FL[i]); in unfix_nodes()
2790 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->FR[i]); in unfix_nodes()
2791 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->CFL[i]); in unfix_nodes()
2792 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->CFR[i]); in unfix_nodes()
2794 brelse(tb->L[i]); in unfix_nodes()
2795 brelse(tb->R[i]); in unfix_nodes()
2796 brelse(tb->FL[i]); in unfix_nodes()
2797 brelse(tb->FR[i]); in unfix_nodes()
2798 brelse(tb->CFL[i]); in unfix_nodes()
2799 brelse(tb->CFR[i]); in unfix_nodes()
2804 if (tb->FEB[i]) { in unfix_nodes()
2805 b_blocknr_t blocknr = tb->FEB[i]->b_blocknr; in unfix_nodes()
2810 brelse(tb->FEB[i]); in unfix_nodes()
2811 reiserfs_free_block(tb->transaction_handle, NULL, in unfix_nodes()
2814 if (tb->used[i]) { in unfix_nodes()
2816 brelse(tb->used[i]); in unfix_nodes()
2820 kfree(tb->vn_buf); in unfix_nodes()