Lines Matching refs:h

51 static void create_virtual_node(struct tree_balance *tb, int h)  in create_virtual_node()  argument
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()
65 if (h) { in create_virtual_node()
194 static void check_left(struct tree_balance *tb, int h, int cur_free) in check_left() argument
204 if (h > 0) { in check_left()
205 tb->lnum[h] = cur_free / (DC_SIZE + KEY_SIZE); in check_left()
213 tb->lnum[h] = 0; in check_left()
280 static void check_right(struct tree_balance *tb, int h, int cur_free) in check_right() argument
290 if (h > 0) { in check_right()
291 tb->rnum[h] = cur_free / (DC_SIZE + KEY_SIZE); in check_right()
299 tb->rnum[h] = 0; in check_right()
316 tb->rnum[h] = vn->vn_nr_item; in check_right()
374 static int get_num_ver(int mode, struct tree_balance *tb, int h, in get_num_ver() argument
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()
430 if (h > 0) { 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()
630 if (h == 0) { 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()
759 if (h)\
766 set_parameters (tb, h, to_l, 0, lnver, NULL, -1, -1);\
771 set_parameters (tb, h, lpar, 0, lnver, snum012+lset,\
774 set_parameters (tb, h, lpar - (tb->lbytes!=-1), 0, lnver, snum012+lset,\
779 if (h)\
785 set_parameters (tb, h, 0, to_r, rnver, NULL, -1, -1);\
790 set_parameters (tb, h, 0, rpar, rnver, snum012+rset,\
793 set_parameters (tb, h, 0, rpar - (tb->rbytes!=-1), rnver, snum012+rset,\
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()
858 counter < h; counter++) in get_empty_nodes()
865 amount_needed = (Sh) ? (tb->blknum[h] - 1) : 1; 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
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()
1024 int h, in get_far_parent() argument
1035 path_offset = PATH_H_PATH_OFFSET(path, h); in get_far_parent()
1129 LEFT_PARENTS) ? (tb->lkey[h - 1] = in get_far_parent()
1131 1) : (tb->rkey[h - in get_far_parent()
1140 h + 1) == IO_ERROR) in get_far_parent()
1152 RFALSE(B_LEVEL(*pfather) != h + 1, in get_far_parent()
1172 static int get_parents(struct tree_balance *tb, int h) in get_parents() argument
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()
1234 if (position == B_NR_ITEMS(PATH_H_PBUFFER(path, h + 1))) { 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()
1288 ((!h in can_node_be_removed()
1291 ((!h && r_key in can_node_be_removed()
1293 + ((h) ? KEY_SIZE : 0)) { in can_node_be_removed()
1297 if (!h) 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
1373 Sh = PATH_H_PBUFFER(tb->tb_path, h); in ip_check_balance()
1374 levbytes = tb->insert_size[h]; in ip_check_balance()
1378 if (!h) 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()
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()
1458 RFALSE(h && 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()
1482 if (!h) 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()
1524 0, -1, h ? vn->vn_nr_item : 0, -1, in ip_check_balance()
1527 if (!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()
1552 -1, h ? vn->vn_nr_item : 0, -1, in ip_check_balance()
1554 if (!h) { in ip_check_balance()
1557 lnver1 = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1575 rnver = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1577 h ? (vn->vn_nr_item - rpar) : (rpar - in ip_check_balance()
1583 if (!h) { in ip_check_balance()
1586 rnver1 = get_num_ver(vn->vn_mode, tb, h, 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()
1608 h ? (vn->vn_nr_item - rpar) : (rpar - in ip_check_balance()
1614 if (!h) { in ip_check_balance()
1617 lrnver1 = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1638 RFALSE(h && in ip_check_balance()
1639 (tb->lnum[h] != 1 || in ip_check_balance()
1640 tb->rnum[h] != 1 || in ip_check_balance()
1642 || h != 1), "vs-8230: bad h"); in ip_check_balance()
1644 set_parameters(tb, h, tb->lnum[h], tb->rnum[h], in ip_check_balance()
1648 set_parameters(tb, h, in ip_check_balance()
1649 tb->lnum[h] - in ip_check_balance()
1651 tb->rnum[h] - 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
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()
1793 h)) == 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()
1810 h)) == 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()
1855 h)) == 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()
1871 h)) == B_NR_ITEMS(Fh)) ? 0 : (n + 1); 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
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()
1982 check_left(tb, h, lfree); in dc_check_balance_leaf()
1983 check_right(tb, h, rfree); 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()
2000 set_parameters(tb, h, 0, -1, 0, NULL, -1, -1); 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()
2036 if (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()
2063 int h, in check_balance() argument
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
2095 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h); 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()
2160 PROC_INFO_INC(sb, get_neighbors[h]); in get_neighbors()
2162 if (tb->lnum[h]) { in get_neighbors()
2164 PROC_INFO_INC(sb, need_l_neighbor[h]); in get_neighbors()
2167 RFALSE(bh == tb->FL[h] && in get_neighbors()
2173 tb->FL[h]) ? tb->lkey[h] : B_NR_ITEMS(tb-> in get_neighbors()
2174 FL[h]); in get_neighbors()
2175 son_number = B_N_CHILD_NUM(tb->FL[h], child_position); in get_neighbors()
2183 PROC_INFO_INC(sb, get_neighbors_restart[h]); 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()
2192 RFALSE(!h && 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()
2204 PROC_INFO_INC(sb, need_r_neighbor[h]); in get_neighbors()
2207 RFALSE(bh == tb->FR[h] && 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()
2223 PROC_INFO_INC(sb, get_neighbors_restart[h]); in get_neighbors()
2226 brelse(tb->R[h]); in get_neighbors()
2227 tb->R[h] = bh; in get_neighbors()
2229 RFALSE(!h in get_neighbors()
2549 int ret, h, item_num = PATH_LAST_POSITION(tb->tb_path); in fix_nodes() local
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()
2644 if (h != MAX_HEIGHT - 1) 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()
2676 if (h < MAX_HEIGHT - 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()
2687 RFALSE(h == MAX_HEIGHT - 1, in fix_nodes()
2690 tb->insert_size[h + 1] = in fix_nodes()
2692 KEY_SIZE) * (tb->blknum[h] - 1) + in fix_nodes()
2694 } else if (h < MAX_HEIGHT - 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()