Lines Matching refs:tb
78 static void create_virtual_node(struct tree_balance *tb, int h) in create_virtual_node() argument
81 struct virtual_node *vn = tb->tb_vn; in create_virtual_node()
85 Sh = PATH_H_PBUFFER(tb->tb_path, h); in create_virtual_node()
89 MAX_CHILD_SIZE(Sh) - B_FREE_SPACE(Sh) + tb->insert_size[h]; in create_virtual_node()
103 vn->vn_vi = (struct virtual_item *)(tb->tb_vn + 1); in create_virtual_node()
137 op_create_vi(vn, vi, is_affected, tb->insert_size[0]); in create_virtual_node()
138 if (tb->vn_buf + tb->vn_buf_size < vn->vn_free_ptr) in create_virtual_node()
139 reiserfs_panic(tb->tb_sb, "vs-8030", in create_virtual_node()
147 vn->vn_vi[new_num].vi_item_len += tb->insert_size[0]; in create_virtual_node()
158 vi->vi_item_len = tb->insert_size[0]; in create_virtual_node()
164 tb->insert_size[0]); in create_virtual_node()
168 if (tb->CFR[0]) { in create_virtual_node()
171 key = B_N_PDELIM_KEY(tb->CFR[0], tb->rkey[0]); in create_virtual_node()
189 reiserfs_panic(tb->tb_sb, "vs-8045", in create_virtual_node()
203 static void check_left(struct tree_balance *tb, int h, int cur_free) in check_left() argument
206 struct virtual_node *vn = tb->tb_vn; in check_left()
214 tb->lnum[h] = cur_free / (DC_SIZE + KEY_SIZE); in check_left()
222 tb->lnum[h] = 0; in check_left()
223 tb->lbytes = -1; in check_left()
227 RFALSE(!PATH_H_PPARENT(tb->tb_path, 0), in check_left()
239 tb->lnum[0] = vn->vn_nr_item; in check_left()
240 tb->lbytes = -1; in check_left()
250 tb->lnum[0] = 0; in check_left()
257 tb->lnum[0]++; in check_left()
265 tb->lbytes = -1; in check_left()
270 tb->lbytes = op_check_left(vi, cur_free, 0, 0); in check_left()
271 if (tb->lbytes != -1) in check_left()
273 tb->lnum[0]++; in check_left()
283 static void check_right(struct tree_balance *tb, int h, int cur_free) in check_right() argument
286 struct virtual_node *vn = tb->tb_vn; in check_right()
294 tb->rnum[h] = cur_free / (DC_SIZE + KEY_SIZE); in check_right()
302 tb->rnum[h] = 0; in check_right()
303 tb->rbytes = -1; in check_right()
307 RFALSE(!PATH_H_PPARENT(tb->tb_path, 0), in check_right()
319 tb->rnum[h] = vn->vn_nr_item; in check_right()
320 tb->rbytes = -1; in check_right()
330 tb->rnum[0] = 0; in check_right()
337 tb->rnum[0]++; in check_right()
343 tb->rbytes = -1; in check_right()
350 tb->rbytes = op_check_right(vi, cur_free); in check_right()
351 if (tb->rbytes != -1) in check_right()
353 tb->rnum[0]++; in check_right()
366 static int get_num_ver(int mode, struct tree_balance *tb, int h, in get_num_ver() argument
374 struct virtual_node *vn = tb->tb_vn; in get_num_ver()
396 RFALSE(tb->insert_size[h] < 0 || (mode != M_INSERT && mode != M_PASTE), in get_num_ver()
399 max_node_size = MAX_CHILD_SIZE(PATH_H_PBUFFER(tb->tb_path, h)); in get_num_ver()
500 reiserfs_warning(tb->tb_sb, "vs-8111", in get_num_ver()
537 reiserfs_warning(tb->tb_sb, "vs-8115", in get_num_ver()
585 static void set_parameters(struct tree_balance *tb, int h, int lnum, in set_parameters() argument
589 tb->lnum[h] = lnum; in set_parameters()
590 tb->rnum[h] = rnum; in set_parameters()
591 tb->blknum[h] = blk_num; in set_parameters()
595 tb->s0num = *s012++, in set_parameters()
596 tb->s1num = *s012++, tb->s2num = *s012++; in set_parameters()
597 tb->s1bytes = *s012++; in set_parameters()
598 tb->s2bytes = *s012; in set_parameters()
600 tb->lbytes = lb; in set_parameters()
601 tb->rbytes = rb; in set_parameters()
603 PROC_INFO_ADD(tb->tb_sb, lnum[h], lnum); in set_parameters()
604 PROC_INFO_ADD(tb->tb_sb, rnum[h], rnum); in set_parameters()
606 PROC_INFO_ADD(tb->tb_sb, lbytes[h], lb); in set_parameters()
607 PROC_INFO_ADD(tb->tb_sb, rbytes[h], rb); in set_parameters()
612 static int is_leaf_removable(struct tree_balance *tb) in is_leaf_removable() argument
614 struct virtual_node *vn = tb->tb_vn; in is_leaf_removable()
621 to_left = tb->lnum[0] - ((tb->lbytes != -1) ? 1 : 0); in is_leaf_removable()
622 to_right = tb->rnum[0] - ((tb->rbytes != -1) ? 1 : 0); in is_leaf_removable()
630 set_parameters(tb, 0, to_left, vn->vn_nr_item - to_left, 0, in is_leaf_removable()
635 if (remain_items > 1 || tb->lbytes == -1 || tb->rbytes == -1) in is_leaf_removable()
644 if (tb->lbytes + tb->rbytes >= size) { in is_leaf_removable()
645 set_parameters(tb, 0, to_left + 1, to_right + 1, 0, NULL, in is_leaf_removable()
646 tb->lbytes, -1); in is_leaf_removable()
654 static int are_leaves_removable(struct tree_balance *tb, int lfree, int rfree) in are_leaves_removable() argument
656 struct virtual_node *vn = tb->tb_vn; in are_leaves_removable()
660 S0 = PATH_H_PBUFFER(tb->tb_path, 0); in are_leaves_removable()
679 if (tb->CFR[0] in are_leaves_removable()
681 B_N_PDELIM_KEY(tb->CFR[0], in are_leaves_removable()
682 tb->rkey[0]))) in are_leaves_removable()
702 set_parameters(tb, 0, -1, -1, -1, NULL, -1, -1); in are_leaves_removable()
703 PROC_INFO_INC(tb->tb_sb, leaves_removable); in are_leaves_removable()
719 set_parameters (tb, h, to_l, 0, lnver, NULL, -1, -1);\
724 set_parameters (tb, h, lpar, 0, lnver, snum012+lset,\
725 tb->lbytes, -1);\
727 set_parameters (tb, h, lpar - (tb->lbytes!=-1), 0, lnver, snum012+lset,\
738 set_parameters (tb, h, 0, to_r, rnver, NULL, -1, -1);\
743 set_parameters (tb, h, 0, rpar, rnver, snum012+rset,\
744 -1, tb->rbytes);\
746 set_parameters (tb, h, 0, rpar - (tb->rbytes!=-1), rnver, snum012+rset,\
750 static void free_buffers_in_tb(struct tree_balance *tb) in free_buffers_in_tb() argument
754 pathrelse(tb->tb_path); in free_buffers_in_tb()
757 brelse(tb->L[i]); in free_buffers_in_tb()
758 brelse(tb->R[i]); in free_buffers_in_tb()
759 brelse(tb->FL[i]); in free_buffers_in_tb()
760 brelse(tb->FR[i]); in free_buffers_in_tb()
761 brelse(tb->CFL[i]); in free_buffers_in_tb()
762 brelse(tb->CFR[i]); in free_buffers_in_tb()
764 tb->L[i] = NULL; in free_buffers_in_tb()
765 tb->R[i] = NULL; in free_buffers_in_tb()
766 tb->FL[i] = NULL; in free_buffers_in_tb()
767 tb->FR[i] = NULL; in free_buffers_in_tb()
768 tb->CFL[i] = NULL; in free_buffers_in_tb()
769 tb->CFR[i] = NULL; in free_buffers_in_tb()
779 static int get_empty_nodes(struct tree_balance *tb, int h) in get_empty_nodes() argument
782 *Sh = PATH_H_PBUFFER(tb->tb_path, h); in get_empty_nodes()
786 struct super_block *sb = tb->tb_sb; in get_empty_nodes()
804 for (counter = 0, number_of_freeblk = tb->cur_blknum; in get_empty_nodes()
807 (tb->blknum[counter]) ? (tb->blknum[counter] - in get_empty_nodes()
812 amount_needed = (Sh) ? (tb->blknum[h] - 1) : 1; in get_empty_nodes()
820 if (reiserfs_new_form_blocknrs(tb, blocknrs, in get_empty_nodes()
839 RFALSE(tb->FEB[tb->cur_blknum], in get_empty_nodes()
843 tb->FEB[tb->cur_blknum++] = new_bh; in get_empty_nodes()
846 if (retval == CARRY_ON && FILESYSTEM_CHANGED_TB(tb)) in get_empty_nodes()
854 static int get_lfree(struct tree_balance *tb, int h) in get_lfree() argument
859 if ((f = PATH_H_PPARENT(tb->tb_path, h)) == NULL || in get_lfree()
860 (l = tb->FL[h]) == NULL) in get_lfree()
864 order = PATH_H_B_ITEM_ORDER(tb->tb_path, h) - 1; in get_lfree()
876 static int get_rfree(struct tree_balance *tb, int h) in get_rfree() argument
881 if ((f = PATH_H_PPARENT(tb->tb_path, h)) == NULL || in get_rfree()
882 (r = tb->FR[h]) == NULL) in get_rfree()
886 order = PATH_H_B_ITEM_ORDER(tb->tb_path, h) + 1; in get_rfree()
897 static int is_left_neighbor_in_cache(struct tree_balance *tb, int h) in is_left_neighbor_in_cache() argument
900 struct super_block *sb = tb->tb_sb; in is_left_neighbor_in_cache()
905 if (!tb->FL[h]) in is_left_neighbor_in_cache()
909 father = PATH_H_PBUFFER(tb->tb_path, h + 1); in is_left_neighbor_in_cache()
913 !B_IS_IN_TREE(tb->FL[h]) || in is_left_neighbor_in_cache()
915 !buffer_uptodate(tb->FL[h]), in is_left_neighbor_in_cache()
917 father, tb->FL[h]); in is_left_neighbor_in_cache()
920 left_neighbor_position = (father == tb->FL[h]) ? in is_left_neighbor_in_cache()
921 tb->lkey[h] : B_NR_ITEMS(tb->FL[h]); in is_left_neighbor_in_cache()
924 B_N_CHILD_NUM(tb->FL[h], left_neighbor_position); in is_left_neighbor_in_cache()
955 static int get_far_parent(struct tree_balance *tb, in get_far_parent() argument
962 struct treepath *path = tb->tb_path; in get_far_parent()
1007 (tb->tb_path, in get_far_parent()
1009 SB_ROOT_BLOCK(tb->tb_sb)) { in get_far_parent()
1025 reiserfs_write_unlock(tb->tb_sb); in get_far_parent()
1027 reiserfs_write_lock(tb->tb_sb); in get_far_parent()
1028 if (FILESYSTEM_CHANGED_TB(tb)) { in get_far_parent()
1041 LEFT_PARENTS) ? (tb->lkey[h - 1] = in get_far_parent()
1043 1) : (tb->rkey[h - in get_far_parent()
1051 (tb->tb_sb, &s_lr_father_key, &s_path_to_neighbor_father, in get_far_parent()
1056 if (FILESYSTEM_CHANGED_TB(tb)) { in get_far_parent()
1081 static int get_parents(struct tree_balance *tb, int h) in get_parents() argument
1083 struct treepath *path = tb->tb_path; in get_parents()
1086 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h); in get_parents()
1093 brelse(tb->FL[h]); in get_parents()
1094 brelse(tb->CFL[h]); in get_parents()
1095 brelse(tb->FR[h]); in get_parents()
1096 brelse(tb->CFR[h]); in get_parents()
1097 tb->FL[h] = NULL; in get_parents()
1098 tb->CFL[h] = NULL; in get_parents()
1099 tb->FR[h] = NULL; in get_parents()
1100 tb->CFR[h] = NULL; in get_parents()
1112 tb->lkey[h] = position - 1; in get_parents()
1118 if ((ret = get_far_parent(tb, h + 1, &curf, in get_parents()
1124 brelse(tb->FL[h]); in get_parents()
1125 tb->FL[h] = curf; /* New initialization of FL[h]. */ in get_parents()
1126 brelse(tb->CFL[h]); in get_parents()
1127 tb->CFL[h] = curcf; /* New initialization of CFL[h]. */ in get_parents()
1141 get_far_parent(tb, h + 1, &curf, &curcf, in get_parents()
1150 tb->rkey[h] = position; in get_parents()
1153 brelse(tb->FR[h]); in get_parents()
1155 tb->FR[h] = curf; in get_parents()
1157 brelse(tb->CFR[h]); in get_parents()
1159 tb->CFR[h] = curcf; in get_parents()
1171 struct tree_balance *tb, int h) in can_node_be_removed() argument
1173 struct buffer_head *Sh = PATH_H_PBUFFER(tb->tb_path, h); in can_node_be_removed()
1174 int levbytes = tb->insert_size[h]; in can_node_be_removed()
1179 if (tb->CFR[h]) in can_node_be_removed()
1180 r_key = B_N_PDELIM_KEY(tb->CFR[h], tb->rkey[h]); in can_node_be_removed()
1194 tb->s0num = in can_node_be_removed()
1197 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); in can_node_be_removed()
1201 PROC_INFO_INC(tb->tb_sb, can_node_be_removed[h]); in can_node_be_removed()
1219 static int ip_check_balance(struct tree_balance *tb, int h) in ip_check_balance() argument
1221 struct virtual_node *vn = tb->tb_vn; in ip_check_balance()
1259 Sh = PATH_H_PBUFFER(tb->tb_path, h); in ip_check_balance()
1260 levbytes = tb->insert_size[h]; in ip_check_balance()
1265 reiserfs_panic(tb->tb_sb, "vs-8210", in ip_check_balance()
1267 switch (ret = get_empty_nodes(tb, h)) { in ip_check_balance()
1269 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); in ip_check_balance()
1276 reiserfs_panic(tb->tb_sb, "vs-8215", "incorrect " in ip_check_balance()
1281 if ((ret = get_parents(tb, h)) != CARRY_ON) /* get parents of S[h] neighbors. */ in ip_check_balance()
1287 rfree = get_rfree(tb, h); in ip_check_balance()
1288 lfree = get_lfree(tb, h); in ip_check_balance()
1290 if (can_node_be_removed(vn->vn_mode, lfree, sfree, rfree, tb, h) == in ip_check_balance()
1295 create_virtual_node(tb, h); in ip_check_balance()
1302 check_left(tb, h, lfree); in ip_check_balance()
1309 check_right(tb, h, rfree); in ip_check_balance()
1313 if (h && (tb->rnum[h] + tb->lnum[h] >= vn->vn_nr_item + 1)) { in ip_check_balance()
1323 ((MAX_NR_KEY(Sh) << 1) + 2 - tb->lnum[h] - tb->rnum[h] + in ip_check_balance()
1325 tb->rnum[h]); in ip_check_balance()
1326 set_parameters(tb, h, vn->vn_nr_item + 1 - to_r, to_r, 0, NULL, in ip_check_balance()
1333 (tb->lnum[h] >= vn->vn_nr_item + 1 || in ip_check_balance()
1334 tb->rnum[h] >= vn->vn_nr_item + 1), in ip_check_balance()
1336 RFALSE(!h && ((tb->lnum[h] >= vn->vn_nr_item && (tb->lbytes == -1)) || in ip_check_balance()
1337 (tb->rnum[h] >= vn->vn_nr_item && (tb->rbytes == -1))), in ip_check_balance()
1342 if (!h && is_leaf_removable(tb)) in ip_check_balance()
1351 tb->s0num = vn->vn_nr_item; in ip_check_balance()
1352 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); in ip_check_balance()
1379 lpar = tb->lnum[h]; in ip_check_balance()
1380 rpar = tb->rnum[h]; in ip_check_balance()
1387 nver = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1395 nver1 = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1409 lnver = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1410 lpar - ((h || tb->lbytes == -1) ? 0 : 1), in ip_check_balance()
1416 lnver1 = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1418 ((tb->lbytes != -1) ? 1 : 0), in ip_check_balance()
1419 tb->lbytes, 0, -1, in ip_check_balance()
1432 rnver = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1435 ((tb-> in ip_check_balance()
1443 rnver1 = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1446 ((tb->rbytes != -1) ? 1 : 0)), in ip_check_balance()
1447 tb->rbytes, in ip_check_balance()
1460 lrnver = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1461 lpar - ((h || tb->lbytes == -1) ? 0 : 1), in ip_check_balance()
1464 ((tb-> in ip_check_balance()
1472 lrnver1 = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1474 ((tb->lbytes != -1) ? 1 : 0), in ip_check_balance()
1475 tb->lbytes, in ip_check_balance()
1477 ((tb->rbytes != -1) ? 1 : 0)), in ip_check_balance()
1478 tb->rbytes, in ip_check_balance()
1492 (tb->lnum[h] != 1 || in ip_check_balance()
1493 tb->rnum[h] != 1 || in ip_check_balance()
1497 set_parameters(tb, h, tb->lnum[h], tb->rnum[h], in ip_check_balance()
1499 tb->lbytes, tb->rbytes); in ip_check_balance()
1501 set_parameters(tb, h, in ip_check_balance()
1502 tb->lnum[h] - in ip_check_balance()
1503 ((tb->lbytes == -1) ? 0 : 1), in ip_check_balance()
1504 tb->rnum[h] - in ip_check_balance()
1505 ((tb->rbytes == -1) ? 0 : 1), in ip_check_balance()
1513 set_parameters(tb, h, 0, 0, nver, snum012 + nset, -1, in ip_check_balance()
1535 if (is_left_neighbor_in_cache(tb, h)) { in ip_check_balance()
1562 static int dc_check_balance_internal(struct tree_balance *tb, int h) in dc_check_balance_internal() argument
1564 struct virtual_node *vn = tb->tb_vn; in dc_check_balance_internal()
1572 Sh = PATH_H_PBUFFER(tb->tb_path, h); in dc_check_balance_internal()
1573 Fh = PATH_H_PPARENT(tb->tb_path, h); in dc_check_balance_internal()
1580 create_virtual_node(tb, h); in dc_check_balance_internal()
1584 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); in dc_check_balance_internal()
1590 set_parameters(tb, h, 0, 0, 0, NULL, -1, -1); in dc_check_balance_internal()
1594 if ((ret = get_parents(tb, h)) != CARRY_ON) in dc_check_balance_internal()
1598 rfree = get_rfree(tb, h); in dc_check_balance_internal()
1599 lfree = get_lfree(tb, h); in dc_check_balance_internal()
1602 check_left(tb, h, lfree); in dc_check_balance_internal()
1603 check_right(tb, h, rfree); in dc_check_balance_internal()
1609 if (tb->lnum[h] >= vn->vn_nr_item + 1) { in dc_check_balance_internal()
1616 PATH_H_B_ITEM_ORDER(tb->tb_path, in dc_check_balance_internal()
1618 0) ? B_NR_ITEMS(tb->FL[h]) : n - 1; in dc_check_balance_internal()
1619 n = dc_size(B_N_CHILD(tb->FL[h], order_L)) / in dc_check_balance_internal()
1621 set_parameters(tb, h, -n - 1, 0, 0, NULL, -1, in dc_check_balance_internal()
1626 if (tb->rnum[h] >= vn->vn_nr_item + 1) { in dc_check_balance_internal()
1633 PATH_H_B_ITEM_ORDER(tb->tb_path, in dc_check_balance_internal()
1636 n = dc_size(B_N_CHILD(tb->FR[h], order_R)) / in dc_check_balance_internal()
1638 set_parameters(tb, h, 0, -n - 1, 0, NULL, -1, in dc_check_balance_internal()
1644 if (tb->rnum[h] + tb->lnum[h] >= vn->vn_nr_item + 1) { in dc_check_balance_internal()
1649 ((MAX_NR_KEY(Sh) << 1) + 2 - tb->lnum[h] - in dc_check_balance_internal()
1650 tb->rnum[h] + vn->vn_nr_item + 1) / 2 - in dc_check_balance_internal()
1651 (MAX_NR_KEY(Sh) + 1 - tb->rnum[h]); in dc_check_balance_internal()
1652 set_parameters(tb, h, vn->vn_nr_item + 1 - to_r, to_r, in dc_check_balance_internal()
1658 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); in dc_check_balance_internal()
1664 if (tb->lnum[h] >= vn->vn_nr_item + 1) in dc_check_balance_internal()
1665 if (is_left_neighbor_in_cache(tb, h) in dc_check_balance_internal()
1666 || tb->rnum[h] < vn->vn_nr_item + 1 || !tb->FR[h]) { in dc_check_balance_internal()
1672 PATH_H_B_ITEM_ORDER(tb->tb_path, in dc_check_balance_internal()
1674 0) ? B_NR_ITEMS(tb->FL[h]) : n - 1; in dc_check_balance_internal()
1675 n = dc_size(B_N_CHILD(tb->FL[h], order_L)) / (DC_SIZE + in dc_check_balance_internal()
1677 set_parameters(tb, h, -n - 1, 0, 0, NULL, -1, -1); in dc_check_balance_internal()
1682 if (tb->rnum[h] >= vn->vn_nr_item + 1) { in dc_check_balance_internal()
1688 PATH_H_B_ITEM_ORDER(tb->tb_path, in dc_check_balance_internal()
1690 n = dc_size(B_N_CHILD(tb->FR[h], order_R)) / (DC_SIZE + in dc_check_balance_internal()
1692 set_parameters(tb, h, 0, -n - 1, 0, NULL, -1, -1); in dc_check_balance_internal()
1697 if (tb->rnum[h] + tb->lnum[h] >= vn->vn_nr_item + 1) { in dc_check_balance_internal()
1701 ((MAX_NR_KEY(Sh) << 1) + 2 - tb->lnum[h] - tb->rnum[h] + in dc_check_balance_internal()
1703 tb->rnum[h]); in dc_check_balance_internal()
1704 set_parameters(tb, h, vn->vn_nr_item + 1 - to_r, to_r, 0, NULL, in dc_check_balance_internal()
1710 RFALSE(!tb->FL[h] && !tb->FR[h], "vs-8235: trying to borrow for root"); in dc_check_balance_internal()
1713 if (is_left_neighbor_in_cache(tb, h) || !tb->FR[h]) { in dc_check_balance_internal()
1717 (MAX_NR_KEY(Sh) + 1 - tb->lnum[h] + vn->vn_nr_item + in dc_check_balance_internal()
1719 set_parameters(tb, h, -from_l, 0, 1, NULL, -1, -1); in dc_check_balance_internal()
1723 set_parameters(tb, h, 0, in dc_check_balance_internal()
1724 -((MAX_NR_KEY(Sh) + 1 - tb->rnum[h] + vn->vn_nr_item + in dc_check_balance_internal()
1742 static int dc_check_balance_leaf(struct tree_balance *tb, int h) in dc_check_balance_leaf() argument
1744 struct virtual_node *vn = tb->tb_vn; in dc_check_balance_leaf()
1758 S0 = PATH_H_PBUFFER(tb->tb_path, 0); in dc_check_balance_leaf()
1759 F0 = PATH_H_PPARENT(tb->tb_path, 0); in dc_check_balance_leaf()
1761 levbytes = tb->insert_size[h]; in dc_check_balance_leaf()
1770 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); in dc_check_balance_leaf()
1774 if ((ret = get_parents(tb, h)) != CARRY_ON) in dc_check_balance_leaf()
1778 rfree = get_rfree(tb, h); in dc_check_balance_leaf()
1779 lfree = get_lfree(tb, h); in dc_check_balance_leaf()
1781 create_virtual_node(tb, h); in dc_check_balance_leaf()
1784 if (are_leaves_removable(tb, lfree, rfree)) in dc_check_balance_leaf()
1791 check_left(tb, h, lfree); in dc_check_balance_leaf()
1792 check_right(tb, h, rfree); in dc_check_balance_leaf()
1795 if (tb->lnum[0] >= vn->vn_nr_item && tb->lbytes == -1) in dc_check_balance_leaf()
1796 …if (is_left_neighbor_in_cache(tb, h) || ((tb->rnum[0] - ((tb->rbytes == -1) ? 0 : 1)) < vn->vn_nr_… in dc_check_balance_leaf()
1797 !tb->FR[h]) { in dc_check_balance_leaf()
1799 RFALSE(!tb->FL[h], in dc_check_balance_leaf()
1803 set_parameters(tb, h, -1, 0, 0, NULL, -1, -1); in dc_check_balance_leaf()
1808 if (tb->rnum[0] >= vn->vn_nr_item && tb->rbytes == -1) { in dc_check_balance_leaf()
1809 set_parameters(tb, h, 0, -1, 0, NULL, -1, -1); in dc_check_balance_leaf()
1814 if (is_leaf_removable(tb)) in dc_check_balance_leaf()
1818 tb->s0num = vn->vn_nr_item; in dc_check_balance_leaf()
1819 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); in dc_check_balance_leaf()
1836 static int dc_check_balance(struct tree_balance *tb, int h) in dc_check_balance() argument
1838 RFALSE(!(PATH_H_PBUFFER(tb->tb_path, h)), in dc_check_balance()
1842 return dc_check_balance_internal(tb, h); in dc_check_balance()
1844 return dc_check_balance_leaf(tb, h); in dc_check_balance()
1866 struct tree_balance *tb, in check_balance() argument
1874 vn = tb->tb_vn = (struct virtual_node *)(tb->vn_buf); in check_balance()
1875 vn->vn_free_ptr = (char *)(tb->tb_vn + 1); in check_balance()
1885 if (tb->insert_size[h] > 0) in check_balance()
1887 return ip_check_balance(tb, h); in check_balance()
1890 return dc_check_balance(tb, h); in check_balance()
1894 static int get_direct_parent(struct tree_balance *tb, int h) in get_direct_parent() argument
1897 struct treepath *path = tb->tb_path; in get_direct_parent()
1899 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h); in get_direct_parent()
1908 b_blocknr == SB_ROOT_BLOCK(tb->tb_sb)) { in get_direct_parent()
1932 reiserfs_write_unlock(tb->tb_sb); in get_direct_parent()
1934 reiserfs_write_lock(tb->tb_sb); in get_direct_parent()
1935 if (FILESYSTEM_CHANGED_TB(tb)) in get_direct_parent()
1948 static int get_neighbors(struct tree_balance *tb, int h) in get_neighbors() argument
1951 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h + 1); in get_neighbors()
1953 struct super_block *sb = tb->tb_sb; in get_neighbors()
1958 if (tb->lnum[h]) { in get_neighbors()
1961 bh = PATH_OFFSET_PBUFFER(tb->tb_path, path_offset); in get_neighbors()
1963 RFALSE(bh == tb->FL[h] && in get_neighbors()
1964 !PATH_OFFSET_POSITION(tb->tb_path, path_offset), in get_neighbors()
1969 tb->FL[h]) ? tb->lkey[h] : B_NR_ITEMS(tb-> in get_neighbors()
1971 son_number = B_N_CHILD_NUM(tb->FL[h], child_position); in get_neighbors()
1977 if (FILESYSTEM_CHANGED_TB(tb)) { in get_neighbors()
1983 RFALSE(!B_IS_IN_TREE(tb->FL[h]) || in get_neighbors()
1984 child_position > B_NR_ITEMS(tb->FL[h]) || in get_neighbors()
1985 B_N_CHILD_NUM(tb->FL[h], child_position) != in get_neighbors()
1991 dc_size(B_N_CHILD(tb->FL[0], child_position)), in get_neighbors()
1994 brelse(tb->L[h]); in get_neighbors()
1995 tb->L[h] = bh; in get_neighbors()
1999 if (tb->rnum[h]) { /* We need right neighbor to balance S[path_offset]. */ in get_neighbors()
2001 bh = PATH_OFFSET_PBUFFER(tb->tb_path, path_offset); in get_neighbors()
2003 RFALSE(bh == tb->FR[h] && in get_neighbors()
2004 PATH_OFFSET_POSITION(tb->tb_path, in get_neighbors()
2010 (bh == tb->FR[h]) ? tb->rkey[h] + 1 : 0; in get_neighbors()
2011 son_number = B_N_CHILD_NUM(tb->FR[h], child_position); in get_neighbors()
2017 if (FILESYSTEM_CHANGED_TB(tb)) { in get_neighbors()
2022 brelse(tb->R[h]); in get_neighbors()
2023 tb->R[h] = bh; in get_neighbors()
2028 dc_size(B_N_CHILD(tb->FR[0], child_position)), in get_neighbors()
2031 dc_size(B_N_CHILD(tb->FR[0], child_position))); in get_neighbors()
2058 static int get_mem_for_virtual_node(struct tree_balance *tb) in get_mem_for_virtual_node() argument
2064 size = get_virtual_node_size(tb->tb_sb, PATH_PLAST_BUFFER(tb->tb_path)); in get_mem_for_virtual_node()
2066 if (size > tb->vn_buf_size) { in get_mem_for_virtual_node()
2068 if (tb->vn_buf) { in get_mem_for_virtual_node()
2070 kfree(tb->vn_buf); in get_mem_for_virtual_node()
2076 tb->vn_buf_size = size; in get_mem_for_virtual_node()
2085 free_buffers_in_tb(tb); in get_mem_for_virtual_node()
2088 tb->vn_buf_size = 0; in get_mem_for_virtual_node()
2090 tb->vn_buf = buf; in get_mem_for_virtual_node()
2095 tb->vn_buf = buf; in get_mem_for_virtual_node()
2098 if (check_fs && FILESYSTEM_CHANGED_TB(tb)) in get_mem_for_virtual_node()
2155 static int wait_tb_buffers_until_unlocked(struct tree_balance *tb) in wait_tb_buffers_until_unlocked() argument
2167 for (i = tb->tb_path->path_length; in wait_tb_buffers_until_unlocked()
2169 if (PATH_OFFSET_PBUFFER(tb->tb_path, i)) { in wait_tb_buffers_until_unlocked()
2174 if (PATH_PLAST_BUFFER(tb->tb_path) == in wait_tb_buffers_until_unlocked()
2175 PATH_OFFSET_PBUFFER(tb->tb_path, i)) in wait_tb_buffers_until_unlocked()
2176 tb_buffer_sanity_check(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2178 (tb->tb_path, in wait_tb_buffers_until_unlocked()
2180 tb->tb_path-> in wait_tb_buffers_until_unlocked()
2183 if (!clear_all_dirty_bits(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2185 (tb->tb_path, in wait_tb_buffers_until_unlocked()
2188 PATH_OFFSET_PBUFFER(tb->tb_path, in wait_tb_buffers_until_unlocked()
2194 for (i = 0; !locked && i < MAX_HEIGHT && tb->insert_size[i]; in wait_tb_buffers_until_unlocked()
2197 if (tb->lnum[i]) { in wait_tb_buffers_until_unlocked()
2199 if (tb->L[i]) { in wait_tb_buffers_until_unlocked()
2200 tb_buffer_sanity_check(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2201 tb->L[i], in wait_tb_buffers_until_unlocked()
2204 (tb->tb_sb, tb->L[i])) in wait_tb_buffers_until_unlocked()
2205 locked = tb->L[i]; in wait_tb_buffers_until_unlocked()
2208 if (!locked && tb->FL[i]) { in wait_tb_buffers_until_unlocked()
2209 tb_buffer_sanity_check(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2210 tb->FL[i], in wait_tb_buffers_until_unlocked()
2213 (tb->tb_sb, tb->FL[i])) in wait_tb_buffers_until_unlocked()
2214 locked = tb->FL[i]; in wait_tb_buffers_until_unlocked()
2217 if (!locked && tb->CFL[i]) { in wait_tb_buffers_until_unlocked()
2218 tb_buffer_sanity_check(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2219 tb->CFL[i], in wait_tb_buffers_until_unlocked()
2222 (tb->tb_sb, tb->CFL[i])) in wait_tb_buffers_until_unlocked()
2223 locked = tb->CFL[i]; in wait_tb_buffers_until_unlocked()
2228 if (!locked && (tb->rnum[i])) { in wait_tb_buffers_until_unlocked()
2230 if (tb->R[i]) { in wait_tb_buffers_until_unlocked()
2231 tb_buffer_sanity_check(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2232 tb->R[i], in wait_tb_buffers_until_unlocked()
2235 (tb->tb_sb, tb->R[i])) in wait_tb_buffers_until_unlocked()
2236 locked = tb->R[i]; in wait_tb_buffers_until_unlocked()
2239 if (!locked && tb->FR[i]) { in wait_tb_buffers_until_unlocked()
2240 tb_buffer_sanity_check(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2241 tb->FR[i], in wait_tb_buffers_until_unlocked()
2244 (tb->tb_sb, tb->FR[i])) in wait_tb_buffers_until_unlocked()
2245 locked = tb->FR[i]; in wait_tb_buffers_until_unlocked()
2248 if (!locked && tb->CFR[i]) { in wait_tb_buffers_until_unlocked()
2249 tb_buffer_sanity_check(tb->tb_sb, in wait_tb_buffers_until_unlocked()
2250 tb->CFR[i], in wait_tb_buffers_until_unlocked()
2253 (tb->tb_sb, tb->CFR[i])) in wait_tb_buffers_until_unlocked()
2254 locked = tb->CFR[i]; in wait_tb_buffers_until_unlocked()
2267 if (tb->FEB[i]) { in wait_tb_buffers_until_unlocked()
2269 (tb->tb_sb, tb->FEB[i])) in wait_tb_buffers_until_unlocked()
2270 locked = tb->FEB[i]; in wait_tb_buffers_until_unlocked()
2278 reiserfs_warning(tb->tb_sb, "reiserfs-8200", in wait_tb_buffers_until_unlocked()
2285 return (FILESYSTEM_CHANGED_TB(tb)) ? in wait_tb_buffers_until_unlocked()
2289 reiserfs_write_unlock(tb->tb_sb); in wait_tb_buffers_until_unlocked()
2291 reiserfs_write_lock(tb->tb_sb); in wait_tb_buffers_until_unlocked()
2292 if (FILESYSTEM_CHANGED_TB(tb)) in wait_tb_buffers_until_unlocked()
2330 int fix_nodes(int op_mode, struct tree_balance *tb, in fix_nodes() argument
2333 int ret, h, item_num = PATH_LAST_POSITION(tb->tb_path); in fix_nodes()
2340 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); in fix_nodes()
2342 ++REISERFS_SB(tb->tb_sb)->s_fix_nodes; in fix_nodes()
2344 pos_in_item = tb->tb_path->pos_in_item; in fix_nodes()
2346 tb->fs_gen = get_generation(tb->tb_sb); in fix_nodes()
2353 reiserfs_prepare_for_journal(tb->tb_sb, in fix_nodes()
2354 SB_BUFFER_WITH_SB(tb->tb_sb), 1); in fix_nodes()
2355 journal_mark_dirty(tb->transaction_handle, tb->tb_sb, in fix_nodes()
2356 SB_BUFFER_WITH_SB(tb->tb_sb)); in fix_nodes()
2357 if (FILESYSTEM_CHANGED_TB(tb)) in fix_nodes()
2362 reiserfs_write_unlock(tb->tb_sb); in fix_nodes()
2364 reiserfs_write_lock(tb->tb_sb); in fix_nodes()
2365 if (FILESYSTEM_CHANGED_TB(tb)) in fix_nodes()
2369 if (REISERFS_SB(tb->tb_sb)->cur_tb) { in fix_nodes()
2371 reiserfs_panic(tb->tb_sb, "PAP-8305", in fix_nodes()
2376 reiserfs_panic(tb->tb_sb, "PAP-8320", "S[0] (%b %z) is " in fix_nodes()
2385 reiserfs_panic(tb->tb_sb, "PAP-8330", "Incorrect " in fix_nodes()
2395 reiserfs_panic(tb->tb_sb, "PAP-8335", "Incorrect " in fix_nodes()
2399 tb->insert_size[0]); in fix_nodes()
2403 reiserfs_panic(tb->tb_sb, "PAP-8340", "Incorrect mode " in fix_nodes()
2408 if (get_mem_for_virtual_node(tb) == REPEAT_SEARCH) in fix_nodes()
2413 for (h = 0; h < MAX_HEIGHT && tb->insert_size[h]; h++) { in fix_nodes()
2414 ret = get_direct_parent(tb, h); in fix_nodes()
2418 ret = check_balance(op_mode, tb, h, item_num, in fix_nodes()
2423 ret = get_neighbors(tb, h); in fix_nodes()
2427 tb->insert_size[h + 1] = 0; in fix_nodes()
2434 ret = get_neighbors(tb, h); in fix_nodes()
2440 ret = get_empty_nodes(tb, h); in fix_nodes()
2444 if (!PATH_H_PBUFFER(tb->tb_path, h)) { in fix_nodes()
2448 RFALSE(tb->blknum[h] != 1, in fix_nodes()
2452 tb->insert_size[h + 1] = 0; in fix_nodes()
2453 } else if (!PATH_H_PBUFFER(tb->tb_path, h + 1)) { in fix_nodes()
2454 if (tb->blknum[h] > 1) { in fix_nodes()
2463 tb->insert_size[h + 1] = in fix_nodes()
2465 KEY_SIZE) * (tb->blknum[h] - 1) + in fix_nodes()
2468 tb->insert_size[h + 1] = 0; in fix_nodes()
2470 tb->insert_size[h + 1] = in fix_nodes()
2471 (DC_SIZE + KEY_SIZE) * (tb->blknum[h] - 1); in fix_nodes()
2474 ret = wait_tb_buffers_until_unlocked(tb); in fix_nodes()
2476 if (FILESYSTEM_CHANGED_TB(tb)) { in fix_nodes()
2499 pathrelse_and_restore(tb->tb_sb, tb->tb_path); in fix_nodes()
2501 pathrelse(tb->tb_path); in fix_nodes()
2506 reiserfs_restore_prepared_buffer(tb->tb_sb, in fix_nodes()
2507 tb->L[i]); in fix_nodes()
2508 reiserfs_restore_prepared_buffer(tb->tb_sb, in fix_nodes()
2509 tb->R[i]); in fix_nodes()
2510 reiserfs_restore_prepared_buffer(tb->tb_sb, in fix_nodes()
2511 tb->FL[i]); in fix_nodes()
2512 reiserfs_restore_prepared_buffer(tb->tb_sb, in fix_nodes()
2513 tb->FR[i]); in fix_nodes()
2514 reiserfs_restore_prepared_buffer(tb->tb_sb, in fix_nodes()
2515 tb-> in fix_nodes()
2517 reiserfs_restore_prepared_buffer(tb->tb_sb, in fix_nodes()
2518 tb-> in fix_nodes()
2522 brelse(tb->L[i]); in fix_nodes()
2523 brelse(tb->R[i]); in fix_nodes()
2524 brelse(tb->FL[i]); in fix_nodes()
2525 brelse(tb->FR[i]); in fix_nodes()
2526 brelse(tb->CFL[i]); in fix_nodes()
2527 brelse(tb->CFR[i]); in fix_nodes()
2529 tb->L[i] = NULL; in fix_nodes()
2530 tb->R[i] = NULL; in fix_nodes()
2531 tb->FL[i] = NULL; in fix_nodes()
2532 tb->FR[i] = NULL; in fix_nodes()
2533 tb->CFL[i] = NULL; in fix_nodes()
2534 tb->CFR[i] = NULL; in fix_nodes()
2539 if (tb->FEB[i]) in fix_nodes()
2541 (tb->tb_sb, tb->FEB[i]); in fix_nodes()
2551 void unfix_nodes(struct tree_balance *tb) in unfix_nodes() argument
2556 pathrelse_and_restore(tb->tb_sb, tb->tb_path); in unfix_nodes()
2560 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->L[i]); in unfix_nodes()
2561 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->R[i]); in unfix_nodes()
2562 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->FL[i]); in unfix_nodes()
2563 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->FR[i]); in unfix_nodes()
2564 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->CFL[i]); in unfix_nodes()
2565 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->CFR[i]); in unfix_nodes()
2567 brelse(tb->L[i]); in unfix_nodes()
2568 brelse(tb->R[i]); in unfix_nodes()
2569 brelse(tb->FL[i]); in unfix_nodes()
2570 brelse(tb->FR[i]); in unfix_nodes()
2571 brelse(tb->CFL[i]); in unfix_nodes()
2572 brelse(tb->CFR[i]); in unfix_nodes()
2577 if (tb->FEB[i]) { in unfix_nodes()
2578 b_blocknr_t blocknr = tb->FEB[i]->b_blocknr; in unfix_nodes()
2581 brelse(tb->FEB[i]); in unfix_nodes()
2582 reiserfs_free_block(tb->transaction_handle, NULL, in unfix_nodes()
2585 if (tb->used[i]) { in unfix_nodes()
2587 brelse(tb->used[i]); in unfix_nodes()
2591 kfree(tb->vn_buf); in unfix_nodes()