• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/fs/reiserfs/

Lines Matching defs:tb

78 static void create_virtual_node(struct tree_balance *tb, int h)
81 struct virtual_node *vn = tb->tb_vn;
83 struct buffer_head *Sh; /* this comes from tb->S[h] */
85 Sh = PATH_H_PBUFFER(tb->tb_path, h);
89 MAX_CHILD_SIZE(Sh) - B_FREE_SPACE(Sh) + tb->insert_size[h];
103 vn->vn_vi = (struct virtual_item *)(tb->tb_vn + 1);
136 op_create_vi(vn, vi, is_affected, tb->insert_size[0]);
137 if (tb->vn_buf + tb->vn_buf_size < vn->vn_free_ptr)
138 reiserfs_panic(tb->tb_sb, "vs-8030",
146 vn->vn_vi[new_num].vi_item_len += tb->insert_size[0];
157 vi->vi_item_len = tb->insert_size[0];
163 tb->insert_size[0]);
167 if (tb->CFR[0]) {
170 key = B_N_PDELIM_KEY(tb->CFR[0], tb->rkey[0]);
188 reiserfs_panic(tb->tb_sb, "vs-8045",
202 static void check_left(struct tree_balance *tb, int h, int cur_free)
205 struct virtual_node *vn = tb->tb_vn;
213 tb->lnum[h] = cur_free / (DC_SIZE + KEY_SIZE);
221 tb->lnum[h] = 0;
222 tb->lbytes = -1;
226 RFALSE(!PATH_H_PPARENT(tb->tb_path, 0),
238 tb->lnum[0] = vn->vn_nr_item;
239 tb->lbytes = -1;
249 tb->lnum[0] = 0;
256 tb->lnum[0]++;
264 tb->lbytes = -1;
269 tb->lbytes = op_check_left(vi, cur_free, 0, 0);
270 if (tb->lbytes != -1)
272 tb->lnum[0]++;
282 static void check_right(struct tree_balance *tb, int h, int cur_free)
285 struct virtual_node *vn = tb->tb_vn;
293 tb->rnum[h] = cur_free / (DC_SIZE + KEY_SIZE);
301 tb->rnum[h] = 0;
302 tb->rbytes = -1;
306 RFALSE(!PATH_H_PPARENT(tb->tb_path, 0),
318 tb->rnum[h] = vn->vn_nr_item;
319 tb->rbytes = -1;
329 tb->rnum[0] = 0;
336 tb->rnum[0]++;
342 tb->rbytes = -1;
349 tb->rbytes = op_check_right(vi, cur_free);
350 if (tb->rbytes != -1)
352 tb->rnum[0]++;
365 static int get_num_ver(int mode, struct tree_balance *tb, int h,
373 struct virtual_node *vn = tb->tb_vn;
395 RFALSE(tb->insert_size[h] < 0 || (mode != M_INSERT && mode != M_PASTE),
398 max_node_size = MAX_CHILD_SIZE(PATH_H_PBUFFER(tb->tb_path, h));
493 // reiserfs_panic (tb->tb_sb, "vs-8115: get_num_ver: too many nodes required");
499 reiserfs_warning(tb->tb_sb, "vs-8111",
536 reiserfs_warning(tb->tb_sb, "vs-8115",
568 * Performs write of results of analysis of balancing into structure tb,
571 * tb tree_balance structure;
584 static void set_parameters(struct tree_balance *tb, int h, int lnum,
588 tb->lnum[h] = lnum;
589 tb->rnum[h] = rnum;
590 tb->blknum[h] = blk_num;
594 tb->s0num = *s012++,
595 tb->s1num = *s012++, tb->s2num = *s012++;
596 tb->s1bytes = *s012++;
597 tb->s2bytes = *s012;
599 tb->lbytes = lb;
600 tb->rbytes = rb;
602 PROC_INFO_ADD(tb->tb_sb, lnum[h], lnum);
603 PROC_INFO_ADD(tb->tb_sb, rnum[h], rnum);
605 PROC_INFO_ADD(tb->tb_sb, lbytes[h], lb);
606 PROC_INFO_ADD(tb->tb_sb, rbytes[h], rb);
609 /* check, does node disappear if we shift tb->lnum[0] items to left
610 neighbor and tb->rnum[0] to the right one. */
611 static int is_leaf_removable(struct tree_balance *tb)
613 struct virtual_node *vn = tb->tb_vn;
620 to_left = tb->lnum[0] - ((tb->lbytes != -1) ? 1 : 0);
621 to_right = tb->rnum[0] - ((tb->rbytes != -1) ? 1 : 0);
629 set_parameters(tb, 0, to_left, vn->vn_nr_item - to_left, 0,
634 if (remain_items > 1 || tb->lbytes == -1 || tb->rbytes == -1)
643 if (tb->lbytes + tb->rbytes >= size) {
644 set_parameters(tb, 0, to_left + 1, to_right + 1, 0, NULL,
645 tb->lbytes, -1);
653 static int are_leaves_removable(struct tree_balance *tb, int lfree, int rfree)
655 struct virtual_node *vn = tb->tb_vn;
659 S0 = PATH_H_PBUFFER(tb->tb_path, 0);
678 if (tb->CFR[0]
680 B_N_PDELIM_KEY(tb->CFR[0],
681 tb->rkey[0])))
701 set_parameters(tb, 0, -1, -1, -1, NULL, -1, -1);
702 PROC_INFO_INC(tb->tb_sb, leaves_removable);
718 set_parameters (tb, h, to_l, 0, lnver, NULL, -1, -1);\
723 set_parameters (tb, h, lpar, 0, lnver, snum012+lset,\
724 tb->lbytes, -1);\
726 set_parameters (tb, h, lpar - (tb->lbytes!=-1), 0, lnver, snum012+lset,\
737 set_parameters (tb, h, 0, to_r, rnver, NULL, -1, -1);\
742 set_parameters (tb, h, 0, rpar, rnver, snum012+rset,\
743 -1, tb->rbytes);\
745 set_parameters (tb, h, 0, rpar - (tb->rbytes!=-1), rnver, snum012+rset,\
749 static void free_buffers_in_tb(struct tree_balance *tb)
753 pathrelse(tb->tb_path);
756 brelse(tb->L[i]);
757 brelse(tb->R[i]);
758 brelse(tb->FL[i]);
759 brelse(tb->FR[i]);
760 brelse(tb->CFL[i]);
761 brelse(tb->CFR[i]);
763 tb->L[i] = NULL;
764 tb->R[i] = NULL;
765 tb->FL[i] = NULL;
766 tb->FR[i] = NULL;
767 tb->CFL[i] = NULL;
768 tb->CFR[i] = NULL;
778 static int get_empty_nodes(struct tree_balance *tb, int h)
781 *Sh = PATH_H_PBUFFER(tb->tb_path, h);
785 struct super_block *sb = tb->tb_sb;
790 number_of_freeblk = tb->cur_blknum can be non-zero if a schedule occurs
803 for (counter = 0, number_of_freeblk = tb->cur_blknum;
806 (tb->blknum[counter]) ? (tb->blknum[counter] -
811 amount_needed = (Sh) ? (tb->blknum[h] - 1) : 1;
819 if (reiserfs_new_form_blocknrs(tb, blocknrs,
838 RFALSE(tb->FEB[tb->cur_blknum],
842 tb->FEB[tb->cur_blknum++] = new_bh;
845 if (retval == CARRY_ON && FILESYSTEM_CHANGED_TB(tb))
853 static int get_lfree(struct tree_balance *tb, int h)
858 if ((f = PATH_H_PPARENT(tb->tb_path, h)) == NULL ||
859 (l = tb->FL[h]) == NULL)
863 order = PATH_H_B_ITEM_ORDER(tb->tb_path, h) - 1;
875 static int get_rfree(struct tree_balance *tb, int h)
880 if ((f = PATH_H_PPARENT(tb->tb_path, h)) == NULL ||
881 (r = tb->FR[h]) == NULL)
885 order = PATH_H_B_ITEM_ORDER(tb->tb_path, h) + 1;
896 static int is_left_neighbor_in_cache(struct tree_balance *tb, int h)
899 struct super_block *sb = tb->tb_sb;
904 if (!tb->FL[h])
908 father = PATH_H_PBUFFER(tb->tb_path, h + 1);
912 !B_IS_IN_TREE(tb->FL[h]) ||
914 !buffer_uptodate(tb->FL[h]),
916 father, tb->FL[h]);
919 left_neighbor_position = (father == tb->FL[h]) ?
920 tb->lkey[h] : B_NR_ITEMS(tb->FL[h]);
923 B_N_CHILD_NUM(tb->FL[h], left_neighbor_position);
954 static int get_far_parent(struct tree_balance *tb,
961 struct treepath *path = tb->tb_path;
1006 (tb->tb_path,
1008 SB_ROOT_BLOCK(tb->tb_sb)) {
1024 reiserfs_write_unlock(tb->tb_sb);
1026 reiserfs_write_lock(tb->tb_sb);
1027 if (FILESYSTEM_CHANGED_TB(tb)) {
1040 LEFT_PARENTS) ? (tb->lkey[h - 1] =
1042 1) : (tb->rkey[h -
1050 (tb->tb_sb, &s_lr_father_key, &s_path_to_neighbor_father,
1055 if (FILESYSTEM_CHANGED_TB(tb)) {
1080 static int get_parents(struct tree_balance *tb, int h)
1082 struct treepath *path = tb->tb_path;
1085 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h);
1092 brelse(tb->FL[h]);
1093 brelse(tb->CFL[h]);
1094 brelse(tb->FR[h]);
1095 brelse(tb->CFR[h]);
1096 tb->FL[h] = NULL;
1097 tb->CFL[h] = NULL;
1098 tb->FR[h] = NULL;
1099 tb->CFR[h] = NULL;
1111 tb->lkey[h] = position - 1;
1117 if ((ret = get_far_parent(tb, h + 1, &curf,
1123 brelse(tb->FL[h]);
1124 tb->FL[h] = curf; /* New initialization of FL[h]. */
1125 brelse(tb->CFL[h]);
1126 tb->CFL[h] = curcf; /* New initialization of CFL[h]. */
1140 get_far_parent(tb, h + 1, &curf, &curcf,
1149 tb->rkey[h] = position;
1152 brelse(tb->FR[h]);
1154 tb->FR[h] = curf;
1156 brelse(tb->CFR[h]);
1158 tb->CFR[h] = curcf;
1170 struct tree_balance *tb, int h)
1172 struct buffer_head *Sh = PATH_H_PBUFFER(tb->tb_path, h);
1173 int levbytes = tb->insert_size[h];
1178 if (tb->CFR[h])
1179 r_key = B_N_PDELIM_KEY(tb->CFR[h], tb->rkey[h]);
1193 tb->s0num =
1196 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1200 PROC_INFO_INC(tb->tb_sb, can_node_be_removed[h]);
1208 * tb tree_balance structure;
1218 static int ip_check_balance(struct tree_balance *tb, int h)
1220 struct virtual_node *vn = tb->tb_vn;
1258 Sh = PATH_H_PBUFFER(tb->tb_path, h);
1259 levbytes = tb->insert_size[h];
1264 reiserfs_panic(tb->tb_sb, "vs-8210",
1266 switch (ret = get_empty_nodes(tb, h)) {
1268 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1275 reiserfs_panic(tb->tb_sb, "vs-8215", "incorrect "
1280 if ((ret = get_parents(tb, h)) != CARRY_ON) /* get parents of S[h] neighbors. */
1286 rfree = get_rfree(tb, h);
1287 lfree = get_lfree(tb, h);
1289 if (can_node_be_removed(vn->vn_mode, lfree, sfree, rfree, tb, h) ==
1294 create_virtual_node(tb, h);
1297 determine maximal number of items we can shift to the left neighbor (in tb structure)
1301 check_left(tb, h, lfree);
1304 determine maximal number of items we can shift to the right neighbor (in tb structure)
1308 check_right(tb, h, rfree);
1312 if (h && (tb->rnum[h] + tb->lnum[h] >= vn->vn_nr_item + 1)) {
1322 ((MAX_NR_KEY(Sh) << 1) + 2 - tb->lnum[h] - tb->rnum[h] +
1324 tb->rnum[h]);
1325 set_parameters(tb, h, vn->vn_nr_item + 1 - to_r, to_r, 0, NULL,
1332 (tb->lnum[h] >= vn->vn_nr_item + 1 ||
1333 tb->rnum[h] >= vn->vn_nr_item + 1),
1335 RFALSE(!h && ((tb->lnum[h] >= vn->vn_nr_item && (tb->lbytes == -1)) ||
1336 (tb->rnum[h] >= vn->vn_nr_item && (tb->rbytes == -1))),
1341 if (!h && is_leaf_removable(tb))
1350 tb->s0num = vn->vn_nr_item;
1351 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1378 lpar = tb->lnum[h];
1379 rpar = tb->rnum[h];
1386 nver = get_num_ver(vn->vn_mode, tb, h,
1394 nver1 = get_num_ver(vn->vn_mode, tb, h,
1408 lnver = get_num_ver(vn->vn_mode, tb, h,
1409 lpar - ((h || tb->lbytes == -1) ? 0 : 1),
1415 lnver1 = get_num_ver(vn->vn_mode, tb, h,
1417 ((tb->lbytes != -1) ? 1 : 0),
1418 tb->lbytes, 0, -1,
1431 rnver = get_num_ver(vn->vn_mode, tb, h,
1434 ((tb->
1442 rnver1 = get_num_ver(vn->vn_mode, tb, h,
1445 ((tb->rbytes != -1) ? 1 : 0)),
1446 tb->rbytes,
1459 lrnver = get_num_ver(vn->vn_mode, tb, h,
1460 lpar - ((h || tb->lbytes == -1) ? 0 : 1),
1463 ((tb->
1471 lrnver1 = get_num_ver(vn->vn_mode, tb, h,
1473 ((tb->lbytes != -1) ? 1 : 0),
1474 tb->lbytes,
1476 ((tb->rbytes != -1) ? 1 : 0)),
1477 tb->rbytes,
1491 (tb->lnum[h] != 1 ||
1492 tb->rnum[h] != 1 ||
1496 set_parameters(tb, h, tb->lnum[h], tb->rnum[h],
1498 tb->lbytes, tb->rbytes);
1500 set_parameters(tb, h,
1501 tb->lnum[h] -
1502 ((tb->lbytes == -1) ? 0 : 1),
1503 tb->rnum[h] -
1504 ((tb->rbytes == -1) ? 0 : 1),
1512 set_parameters(tb, h, 0, 0, nver, snum012 + nset, -1,
1534 if (is_left_neighbor_in_cache(tb, h)) {
1549 * tb tree_balance structure;
1561 static int dc_check_balance_internal(struct tree_balance *tb, int h)
1563 struct virtual_node *vn = tb->tb_vn;
1571 Sh = PATH_H_PBUFFER(tb->tb_path, h);
1572 Fh = PATH_H_PPARENT(tb->tb_path, h);
1576 /* using tb->insert_size[h], which is negative in this case, create_virtual_node calculates: */
1579 create_virtual_node(tb, h);
1583 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1589 set_parameters(tb, h, 0, 0, 0, NULL, -1, -1);
1593 if ((ret = get_parents(tb, h)) != CARRY_ON)
1597 rfree = get_rfree(tb, h);
1598 lfree = get_lfree(tb, h);
1601 check_left(tb, h, lfree);
1602 check_right(tb, h, rfree);
1608 if (tb->lnum[h] >= vn->vn_nr_item + 1) {
1615 PATH_H_B_ITEM_ORDER(tb->tb_path,
1617 0) ? B_NR_ITEMS(tb->FL[h]) : n - 1;
1618 n = dc_size(B_N_CHILD(tb->FL[h], order_L)) /
1620 set_parameters(tb, h, -n - 1, 0, 0, NULL, -1,
1625 if (tb->rnum[h] >= vn->vn_nr_item + 1) {
1632 PATH_H_B_ITEM_ORDER(tb->tb_path,
1635 n = dc_size(B_N_CHILD(tb->FR[h], order_R)) /
1637 set_parameters(tb, h, 0, -n - 1, 0, NULL, -1,
1643 if (tb->rnum[h] + tb->lnum[h] >= vn->vn_nr_item + 1) {
1648 ((MAX_NR_KEY(Sh) << 1) + 2 - tb->lnum[h] -
1649 tb->rnum[h] + vn->vn_nr_item + 1) / 2 -
1650 (MAX_NR_KEY(Sh) + 1 - tb->rnum[h]);
1651 set_parameters(tb, h, vn->vn_nr_item + 1 - to_r, to_r,
1657 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1663 if (tb->lnum[h] >= vn->vn_nr_item + 1)
1664 if (is_left_neighbor_in_cache(tb, h)
1665 || tb->rnum[h] < vn->vn_nr_item + 1 || !tb->FR[h]) {
1671 PATH_H_B_ITEM_ORDER(tb->tb_path,
1673 0) ? B_NR_ITEMS(tb->FL[h]) : n - 1;
1674 n = dc_size(B_N_CHILD(tb->FL[h], order_L)) / (DC_SIZE +
1676 set_parameters(tb, h, -n - 1, 0, 0, NULL, -1, -1);
1681 if (tb->rnum[h] >= vn->vn_nr_item + 1) {
1687 PATH_H_B_ITEM_ORDER(tb->tb_path,
1689 n = dc_size(B_N_CHILD(tb->FR[h], order_R)) / (DC_SIZE +
1691 set_parameters(tb, h, 0, -n - 1, 0, NULL, -1, -1);
1696 if (tb->rnum[h] + tb->lnum[h] >= vn->vn_nr_item + 1) {
1700 ((MAX_NR_KEY(Sh) << 1) + 2 - tb->lnum[h] - tb->rnum[h] +
1702 tb->rnum[h]);
1703 set_parameters(tb, h, vn->vn_nr_item + 1 - to_r, to_r, 0, NULL,
1709 RFALSE(!tb->FL[h] && !tb->FR[h], "vs-8235: trying to borrow for root");
1712 if (is_left_neighbor_in_cache(tb, h) || !tb->FR[h]) {
1716 (MAX_NR_KEY(Sh) + 1 - tb->lnum[h] + vn->vn_nr_item +
1718 set_parameters(tb, h, -from_l, 0, 1, NULL, -1, -1);
1722 set_parameters(tb, h, 0,
1723 -((MAX_NR_KEY(Sh) + 1 - tb->rnum[h] + vn->vn_nr_item +
1732 * tb tree_balance structure;
1741 static int dc_check_balance_leaf(struct tree_balance *tb, int h)
1743 struct virtual_node *vn = tb->tb_vn;
1757 S0 = PATH_H_PBUFFER(tb->tb_path, 0);
1758 F0 = PATH_H_PPARENT(tb->tb_path, 0);
1760 levbytes = tb->insert_size[h];
1769 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1773 if ((ret = get_parents(tb, h)) != CARRY_ON)
1777 rfree = get_rfree(tb, h);
1778 lfree = get_lfree(tb, h);
1780 create_virtual_node(tb, h);
1783 if (are_leaves_removable(tb, lfree, rfree))
1790 check_left(tb, h, lfree);
1791 check_right(tb, h, rfree);
1794 if (tb->lnum[0] >= vn->vn_nr_item && tb->lbytes == -1)
1795 if (is_left_neighbor_in_cache(tb, h) || ((tb->rnum[0] - ((tb->rbytes == -1) ? 0 : 1)) < vn->vn_nr_item) || /* S can not be merged with R */
1796 !tb->FR[h]) {
1798 RFALSE(!tb->FL[h],
1802 set_parameters(tb, h, -1, 0, 0, NULL, -1, -1);
1807 if (tb->rnum[0] >= vn->vn_nr_item && tb->rbytes == -1) {
1808 set_parameters(tb, h, 0, -1, 0, NULL, -1, -1);
1813 if (is_leaf_removable(tb))
1817 tb->s0num = vn->vn_nr_item;
1818 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1826 * tb tree_balance structure;
1835 static int dc_check_balance(struct tree_balance *tb, int h)
1837 RFALSE(!(PATH_H_PBUFFER(tb->tb_path, h)),
1841 return dc_check_balance_internal(tb, h);
1843 return dc_check_balance_leaf(tb, h);
1850 * tb tree_balance structure:
1852 * tb is a large structure that must be read about in the header file
1865 struct tree_balance *tb,
1873 vn = tb->tb_vn = (struct virtual_node *)(tb->vn_buf);
1874 vn->vn_free_ptr = (char *)(tb->tb_vn + 1);
1884 if (tb->insert_size[h] > 0)
1886 return ip_check_balance(tb, h);
1889 return dc_check_balance(tb, h);
1893 static int get_direct_parent(struct tree_balance *tb, int h)
1896 struct treepath *path = tb->tb_path;
1898 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h);
1907 b_blocknr == SB_ROOT_BLOCK(tb->tb_sb)) {
1931 reiserfs_write_unlock(tb->tb_sb);
1933 reiserfs_write_lock(tb->tb_sb);
1934 if (FILESYSTEM_CHANGED_TB(tb))
1947 static int get_neighbors(struct tree_balance *tb, int h)
1950 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h + 1);
1952 struct super_block *sb = tb->tb_sb;
1957 if (tb->lnum[h]) {
1960 bh = PATH_OFFSET_PBUFFER(tb->tb_path, path_offset);
1962 RFALSE(bh == tb->FL[h] &&
1963 !PATH_OFFSET_POSITION(tb->tb_path, path_offset),
1968 tb->FL[h]) ? tb->lkey[h] : B_NR_ITEMS(tb->
1970 son_number = B_N_CHILD_NUM(tb->FL[h], child_position);
1976 if (FILESYSTEM_CHANGED_TB(tb)) {
1982 RFALSE(!B_IS_IN_TREE(tb->FL[h]) ||
1983 child_position > B_NR_ITEMS(tb->FL[h]) ||
1984 B_N_CHILD_NUM(tb->FL[h], child_position) !=
1990 dc_size(B_N_CHILD(tb->FL[0], child_position)),
1993 brelse(tb->L[h]);
1994 tb->L[h] = bh;
1998 if (tb->rnum[h]) { /* We need right neighbor to balance S[path_offset]. */
2000 bh = PATH_OFFSET_PBUFFER(tb->tb_path, path_offset);
2002 RFALSE(bh == tb->FR[h] &&
2003 PATH_OFFSET_POSITION(tb->tb_path,
2009 (bh == tb->FR[h]) ? tb->rkey[h] + 1 : 0;
2010 son_number = B_N_CHILD_NUM(tb->FR[h], child_position);
2016 if (FILESYSTEM_CHANGED_TB(tb)) {
2021 brelse(tb->R[h]);
2022 tb->R[h] = bh;
2027 dc_size(B_N_CHILD(tb->FR[0], child_position)),
2030 dc_size(B_N_CHILD(tb->FR[0], child_position)));
2057 static int get_mem_for_virtual_node(struct tree_balance *tb)
2063 size = get_virtual_node_size(tb->tb_sb, PATH_PLAST_BUFFER(tb->tb_path));
2065 if (size > tb->vn_buf_size) {
2067 if (tb->vn_buf) {
2069 kfree(tb->vn_buf);
2075 tb->vn_buf_size = size;
2084 free_buffers_in_tb(tb);
2087 tb->vn_buf_size = 0;
2089 tb->vn_buf = buf;
2094 tb->vn_buf = buf;
2097 if (check_fs && FILESYSTEM_CHANGED_TB(tb))
2154 static int wait_tb_buffers_until_unlocked(struct tree_balance *tb)
2166 for (i = tb->tb_path->path_length;
2168 if (PATH_OFFSET_PBUFFER(tb->tb_path, i)) {
2173 if (PATH_PLAST_BUFFER(tb->tb_path) ==
2174 PATH_OFFSET_PBUFFER(tb->tb_path, i))
2175 tb_buffer_sanity_check(tb->tb_sb,
2177 (tb->tb_path,
2179 tb->tb_path->
2182 if (!clear_all_dirty_bits(tb->tb_sb,
2184 (tb->tb_path,
2187 PATH_OFFSET_PBUFFER(tb->tb_path,
2193 for (i = 0; !locked && i < MAX_HEIGHT && tb->insert_size[i];
2196 if (tb->lnum[i]) {
2198 if (tb->L[i]) {
2199 tb_buffer_sanity_check(tb->tb_sb,
2200 tb->L[i],
2203 (tb->tb_sb, tb->L[i]))
2204 locked = tb->L[i];
2207 if (!locked && tb->FL[i]) {
2208 tb_buffer_sanity_check(tb->tb_sb,
2209 tb->FL[i],
2212 (tb->tb_sb, tb->FL[i]))
2213 locked = tb->FL[i];
2216 if (!locked && tb->CFL[i]) {
2217 tb_buffer_sanity_check(tb->tb_sb,
2218 tb->CFL[i],
2221 (tb->tb_sb, tb->CFL[i]))
2222 locked = tb->CFL[i];
2227 if (!locked && (tb->rnum[i])) {
2229 if (tb->R[i]) {
2230 tb_buffer_sanity_check(tb->tb_sb,
2231 tb->R[i],
2234 (tb->tb_sb, tb->R[i]))
2235 locked = tb->R[i];
2238 if (!locked && tb->FR[i]) {
2239 tb_buffer_sanity_check(tb->tb_sb,
2240 tb->FR[i],
2243 (tb->tb_sb, tb->FR[i]))
2244 locked = tb->FR[i];
2247 if (!locked && tb->CFR[i]) {
2248 tb_buffer_sanity_check(tb->tb_sb,
2249 tb->CFR[i],
2252 (tb->tb_sb, tb->CFR[i]))
2253 locked = tb->CFR[i];
2266 if (tb->FEB[i]) {
2268 (tb->tb_sb, tb->FEB[i]))
2269 locked = tb->FEB[i];
2277 reiserfs_warning(tb->tb_sb, "reiserfs-8200",
2284 return (FILESYSTEM_CHANGED_TB(tb)) ?
2288 reiserfs_write_unlock(tb->tb_sb);
2290 reiserfs_write_lock(tb->tb_sb);
2291 if (FILESYSTEM_CHANGED_TB(tb))
2319 * tb tree_balance structure;
2329 int fix_nodes(int op_mode, struct tree_balance *tb,
2332 int ret, h, item_num = PATH_LAST_POSITION(tb->tb_path);
2339 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
2341 ++REISERFS_SB(tb->tb_sb)->s_fix_nodes;
2343 pos_in_item = tb->tb_path->pos_in_item;
2345 tb->fs_gen = get_generation(tb->tb_sb);
2352 reiserfs_prepare_for_journal(tb->tb_sb,
2353 SB_BUFFER_WITH_SB(tb->tb_sb), 1);
2354 journal_mark_dirty(tb->transaction_handle, tb->tb_sb,
2355 SB_BUFFER_WITH_SB(tb->tb_sb));
2356 if (FILESYSTEM_CHANGED_TB(tb))
2361 reiserfs_write_unlock(tb->tb_sb);
2363 reiserfs_write_lock(tb->tb_sb);
2364 if (FILESYSTEM_CHANGED_TB(tb))
2368 if (REISERFS_SB(tb->tb_sb)->cur_tb) {
2370 reiserfs_panic(tb->tb_sb, "PAP-8305",
2375 reiserfs_panic(tb->tb_sb, "PAP-8320", "S[0] (%b %z) is "
2384 reiserfs_panic(tb->tb_sb, "PAP-8330", "Incorrect "
2394 reiserfs_panic(tb->tb_sb, "PAP-8335", "Incorrect "
2398 tb->insert_size[0]);
2402 reiserfs_panic(tb->tb_sb, "PAP-8340", "Incorrect mode "
2407 if (get_mem_for_virtual_node(tb) == REPEAT_SEARCH)
2411 for (h = 0; h < MAX_HEIGHT && tb->insert_size[h]; h++) {
2412 ret = get_direct_parent(tb, h);
2416 ret = check_balance(op_mode, tb, h, item_num,
2421 ret = get_neighbors(tb, h);
2425 tb->insert_size[h + 1] = 0;
2432 ret = get_neighbors(tb, h);
2438 ret = get_empty_nodes(tb, h);
2442 if (!PATH_H_PBUFFER(tb->tb_path, h)) {
2446 RFALSE(tb->blknum[h] != 1,
2450 tb->insert_size[h + 1] = 0;
2451 } else if (!PATH_H_PBUFFER(tb->tb_path, h + 1)) {
2452 if (tb->blknum[h] > 1) {
2461 tb->insert_size[h + 1] =
2463 KEY_SIZE) * (tb->blknum[h] - 1) +
2466 tb->insert_size[h + 1] = 0;
2468 tb->insert_size[h + 1] =
2469 (DC_SIZE + KEY_SIZE) * (tb->blknum[h] - 1);
2472 ret = wait_tb_buffers_until_unlocked(tb);
2474 if (FILESYSTEM_CHANGED_TB(tb)) {
2497 pathrelse_and_restore(tb->tb_sb, tb->tb_path);
2499 pathrelse(tb->tb_path);
2504 reiserfs_restore_prepared_buffer(tb->tb_sb,
2505 tb->L[i]);
2506 reiserfs_restore_prepared_buffer(tb->tb_sb,
2507 tb->R[i]);
2508 reiserfs_restore_prepared_buffer(tb->tb_sb,
2509 tb->FL[i]);
2510 reiserfs_restore_prepared_buffer(tb->tb_sb,
2511 tb->FR[i]);
2512 reiserfs_restore_prepared_buffer(tb->tb_sb,
2513 tb->
2515 reiserfs_restore_prepared_buffer(tb->tb_sb,
2516 tb->
2520 brelse(tb->L[i]);
2521 brelse(tb->R[i]);
2522 brelse(tb->FL[i]);
2523 brelse(tb->FR[i]);
2524 brelse(tb->CFL[i]);
2525 brelse(tb->CFR[i]);
2527 tb->L[i] = NULL;
2528 tb->R[i] = NULL;
2529 tb->FL[i] = NULL;
2530 tb->FR[i] = NULL;
2531 tb->CFL[i] = NULL;
2532 tb->CFR[i] = NULL;
2537 if (tb->FEB[i])
2539 (tb->tb_sb, tb->FEB[i]);
2547 /* Anatoly will probably forgive me renaming tb to tb. I just
2549 void unfix_nodes(struct tree_balance *tb)
2554 pathrelse_and_restore(tb->tb_sb, tb->tb_path);
2558 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->L[i]);
2559 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->R[i]);
2560 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->FL[i]);
2561 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->FR[i]);
2562 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->CFL[i]);
2563 reiserfs_restore_prepared_buffer(tb->tb_sb, tb->CFR[i]);
2565 brelse(tb->L[i]);
2566 brelse(tb->R[i]);
2567 brelse(tb->FL[i]);
2568 brelse(tb->FR[i]);
2569 brelse(tb->CFL[i]);
2570 brelse(tb->CFR[i]);
2575 if (tb->FEB[i]) {
2576 b_blocknr_t blocknr = tb->FEB[i]->b_blocknr;
2579 brelse(tb->FEB[i]);
2580 reiserfs_free_block(tb->transaction_handle, NULL,
2583 if (tb->used[i]) {
2585 brelse(tb->used[i]);
2589 kfree(tb->vn_buf);