Lines Matching +full:render +full:- +full:max

66 		       "vs-8005: for INSERT mode and item number of inserted item");  in old_item_num()
68 return new_num - 1; in old_item_num()
72 "vs-8010: old_item_num: mode must be M_DELETE (mode = \'%c\'", in old_item_num()
81 struct virtual_node *vn = tb->tb_vn; in create_virtual_node()
83 struct buffer_head *Sh; /* this comes from tb->S[h] */ in create_virtual_node()
85 Sh = PATH_H_PBUFFER(tb->tb_path, h); in create_virtual_node()
88 vn->vn_size = in create_virtual_node()
89 MAX_CHILD_SIZE(Sh) - B_FREE_SPACE(Sh) + tb->insert_size[h]; in create_virtual_node()
93 vn->vn_nr_item = (vn->vn_size - DC_SIZE) / (DC_SIZE + KEY_SIZE); in create_virtual_node()
98 vn->vn_nr_item = in create_virtual_node()
99 B_NR_ITEMS(Sh) + ((vn->vn_mode == M_INSERT) ? 1 : 0) - in create_virtual_node()
100 ((vn->vn_mode == M_DELETE) ? 1 : 0); in create_virtual_node()
103 vn->vn_vi = (struct virtual_item *)(tb->tb_vn + 1); in create_virtual_node()
104 memset(vn->vn_vi, 0, vn->vn_nr_item * sizeof(struct virtual_item)); in create_virtual_node()
105 vn->vn_free_ptr += vn->vn_nr_item * sizeof(struct virtual_item); in create_virtual_node()
110 /* define the mergeability for 0-th item (if it is not being deleted) */ in create_virtual_node()
111 if (op_is_left_mergeable(&(ih->ih_key), Sh->b_size) in create_virtual_node()
112 && (vn->vn_mode != M_DELETE || vn->vn_affected_item_num)) in create_virtual_node()
113 vn->vn_vi[0].vi_type |= VI_TYPE_LEFT_MERGEABLE; in create_virtual_node()
116 for (new_num = 0; new_num < vn->vn_nr_item; new_num++) { in create_virtual_node()
118 struct virtual_item *vi = vn->vn_vi + new_num; in create_virtual_node()
120 ((new_num != vn->vn_affected_item_num) ? 0 : 1); in create_virtual_node()
122 if (is_affected && vn->vn_mode == M_INSERT) in create_virtual_node()
126 j = old_item_num(new_num, vn->vn_affected_item_num, in create_virtual_node()
127 vn->vn_mode); in create_virtual_node()
129 vi->vi_item_len += ih_item_len(ih + j) + IH_SIZE; in create_virtual_node()
130 vi->vi_ih = ih + j; in create_virtual_node()
131 vi->vi_item = B_I_PITEM(Sh, ih + j); in create_virtual_node()
132 vi->vi_uarea = vn->vn_free_ptr; in create_virtual_node()
136 vn->vn_free_ptr += 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()
146 if (vn->vn_mode == M_PASTE || vn->vn_mode == M_CUT) { in create_virtual_node()
147 vn->vn_vi[new_num].vi_item_len += tb->insert_size[0]; in create_virtual_node()
148 vi->vi_new_data = vn->vn_data; // pointer to data which is going to be pasted in create_virtual_node()
153 if (vn->vn_mode == M_INSERT) { in create_virtual_node()
154 struct virtual_item *vi = vn->vn_vi + vn->vn_affected_item_num; in create_virtual_node()
156 RFALSE(vn->vn_ins_ih == NULL, in create_virtual_node()
157 "vs-8040: item header of inserted item is not specified"); in create_virtual_node()
158 vi->vi_item_len = tb->insert_size[0]; in create_virtual_node()
159 vi->vi_ih = vn->vn_ins_ih; in create_virtual_node()
160 vi->vi_item = vn->vn_data; in create_virtual_node()
161 vi->vi_uarea = vn->vn_free_ptr; 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()
172 if (op_is_left_mergeable(key, Sh->b_size) in create_virtual_node()
173 && (vn->vn_mode != M_DELETE in create_virtual_node()
174 || vn->vn_affected_item_num != B_NR_ITEMS(Sh) - 1)) in create_virtual_node()
175 vn->vn_vi[vn->vn_nr_item - 1].vi_type |= in create_virtual_node()
179 if (op_is_left_mergeable(key, Sh->b_size) && in create_virtual_node()
180 !(vn->vn_mode != M_DELETE in create_virtual_node()
181 || vn->vn_affected_item_num != B_NR_ITEMS(Sh) - 1)) { in create_virtual_node()
188 print_block(Sh, 0, -1, -1); in create_virtual_node()
189 reiserfs_panic(tb->tb_sb, "vs-8045", in create_virtual_node()
192 key, vn->vn_affected_item_num, in create_virtual_node()
193 vn->vn_mode, M_DELETE); in create_virtual_node()
206 struct virtual_node *vn = tb->tb_vn; in check_left()
210 RFALSE(cur_free < 0, "vs-8050: cur_free (%d) < 0", cur_free); in check_left()
214 tb->lnum[h] = cur_free / (DC_SIZE + KEY_SIZE); in check_left()
220 if (!cur_free || !vn->vn_nr_item) { 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()
228 "vs-8055: parent does not exist or invalid"); in check_left()
230 vi = vn->vn_vi; in check_left()
232 (vn->vn_size - in check_left()
233 ((vi->vi_type & VI_TYPE_LEFT_MERGEABLE) ? IH_SIZE : 0))) { in check_left()
236 RFALSE(vn->vn_mode == M_INSERT || vn->vn_mode == M_PASTE, in check_left()
237 "vs-8055: invalid mode or balance condition failed"); in check_left()
239 tb->lnum[0] = vn->vn_nr_item; in check_left()
240 tb->lbytes = -1; in check_left()
247 if (vi->vi_type & VI_TYPE_LEFT_MERGEABLE) in check_left()
248 d_size = -((int)IH_SIZE), ih_size = 0; in check_left()
250 tb->lnum[0] = 0; in check_left()
251 for (i = 0; i < vn->vn_nr_item; in check_left()
253 d_size += vi->vi_item_len; in check_left()
256 cur_free -= d_size; in check_left()
257 tb->lnum[0]++; in check_left()
265 tb->lbytes = -1; in check_left()
268 cur_free -= ih_size; 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()
286 struct virtual_node *vn = tb->tb_vn; in check_right()
290 RFALSE(cur_free < 0, "vs-8070: cur_free < 0"); in check_right()
294 tb->rnum[h] = cur_free / (DC_SIZE + KEY_SIZE); in check_right()
300 if (!cur_free || !vn->vn_nr_item) { 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()
308 "vs-8075: parent does not exist or invalid"); in check_right()
310 vi = vn->vn_vi + vn->vn_nr_item - 1; in check_right()
312 (vn->vn_size - in check_right()
313 ((vi->vi_type & VI_TYPE_RIGHT_MERGEABLE) ? IH_SIZE : 0))) { in check_right()
316 RFALSE(vn->vn_mode == M_INSERT || vn->vn_mode == M_PASTE, in check_right()
317 "vs-8080: invalid mode or balance condition failed"); in check_right()
319 tb->rnum[h] = vn->vn_nr_item; in check_right()
320 tb->rbytes = -1; in check_right()
327 if (vi->vi_type & VI_TYPE_RIGHT_MERGEABLE) in check_right()
328 d_size = -(int)IH_SIZE, ih_size = 0; in check_right()
330 tb->rnum[0] = 0; in check_right()
331 for (i = vn->vn_nr_item - 1; i >= 0; in check_right()
332 i--, d_size = 0, ih_size = IH_SIZE, vi--) { in check_right()
333 d_size += vi->vi_item_len; in check_right()
336 cur_free -= d_size; in check_right()
337 tb->rnum[0]++; in check_right()
343 tb->rbytes = -1; in check_right()
348 cur_free -= ih_size; /* cur_free is still > 0 */ 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()
362 * from - number of items, which are shifted to left neighbor entirely
363 * to - number of item, which are shifted to right neighbor entirely
364 …* from_bytes - number of bytes of boundary item (or directory entries) which are shifted to left n…
365 …* to_bytes - number of bytes of boundary item (or directory entries) which are shifted to right ne…
374 struct virtual_node *vn = tb->tb_vn; in get_num_ver()
381 start_bytes, /* number of first bytes (entries for directory) of start_item-th item in get_num_ver()
383 end_bytes; /* number of last bytes (entries for directory) of end_item-th item in get_num_ver()
389 split_item_positions[0] = -1; in get_num_ver()
390 split_item_positions[1] = -1; in get_num_ver()
396 RFALSE(tb->insert_size[h] < 0 || (mode != M_INSERT && mode != M_PASTE), in get_num_ver()
397 "vs-8100: insert_size < 0 in overflow"); in get_num_ver()
399 max_node_size = MAX_CHILD_SIZE(PATH_H_PBUFFER(tb->tb_path, h)); in get_num_ver()
401 /* snum012 [0-2] - number of items, that lay in get_num_ver()
403 snum012[3] = -1; /* s1bytes */ in get_num_ver()
404 snum012[4] = -1; /* s2bytes */ in get_num_ver()
408 i = ((to - from) * (KEY_SIZE + DC_SIZE) + DC_SIZE); in get_num_ver()
419 // start from 'from'-th item in get_num_ver()
422 start_bytes = ((from_bytes != -1) ? from_bytes : 0); in get_num_ver()
424 // last included item is the 'end_item'-th one in get_num_ver()
425 end_item = vn->vn_nr_item - to - 1; in get_num_ver()
426 // do not count last 'end_bytes' units of 'end_item'-th item in get_num_ver()
427 end_bytes = (to_bytes != -1) ? to_bytes : 0; in get_num_ver()
429 /* go through all item beginning from the start_item-th item and ending by in get_num_ver()
430 the end_item-th item. Do not count first 'start_bytes' units of in get_num_ver()
431 'start_item'-th item and last 'end_bytes' of 'end_item'-th item */ in get_num_ver()
434 struct virtual_item *vi = vn->vn_vi + i; in get_num_ver()
437 RFALSE(needed_nodes > 3, "vs-8105: too many nodes are needed"); in get_num_ver()
440 current_item_size = vi->vi_item_len; in get_num_ver()
442 /* do not take in calculation head part (from_bytes) of from-th item */ in get_num_ver()
443 current_item_size -= in get_num_ver()
447 current_item_size -= in get_num_ver()
452 snum012[needed_nodes - 1]++; in get_num_ver()
459 /* virtual item length is longer, than max size of item in in get_num_ver()
461 RFALSE(is_direct_le_ih(vi->vi_ih), in get_num_ver()
462 "vs-8110: " in get_num_ver()
472 i--; in get_num_ver()
481 free_space = max_node_size - total_node_size - IH_SIZE; in get_num_ver()
485 if (units == -1) { in get_num_ver()
487 needed_nodes++, i--, total_node_size = 0; in get_num_ver()
493 //if (snum012[3] != -1 || needed_nodes != 1) in get_num_ver()
494 // reiserfs_panic (tb->tb_sb, "vs-8115: get_num_ver: too many nodes required"); in get_num_ver()
495 //snum012[needed_nodes - 1 + 3] = op_unit_num (vi) - start_bytes - units; in get_num_ver()
497 snum012[needed_nodes - 1 + 3] = units; in get_num_ver()
500 reiserfs_warning(tb->tb_sb, "vs-8111", in get_num_ver()
502 snum012[needed_nodes - 1]++; in get_num_ver()
503 split_item_positions[needed_nodes - 1] = i; in get_num_ver()
505 /* continue from the same item with start_bytes != -1 */ in get_num_ver()
507 i--; in get_num_ver()
511 // sum012[4] (if it is not -1) contains number of units of which in get_num_ver()
512 // are to be in S1new, snum012[3] - to be in S0. They are supposed in get_num_ver()
522 && from_bytes != -1) ? from_bytes : 0); in get_num_ver()
525 && end_bytes != -1) ? end_bytes : 0); in get_num_ver()
532 op_unit_num(&vn->vn_vi[split_item_num]) - snum012[4] - in get_num_ver()
533 bytes_to_r - bytes_to_l - bytes_to_S1new; in get_num_ver()
535 if (vn->vn_vi[split_item_num].vi_index != TYPE_DIRENTRY && in get_num_ver()
536 vn->vn_vi[split_item_num].vi_index != TYPE_INDIRECT) in get_num_ver()
537 reiserfs_warning(tb->tb_sb, "vs-8115", in get_num_ver()
550 && from_bytes != -1) ? from_bytes : 0); in get_num_ver()
553 && end_bytes != -1) ? end_bytes : 0); in get_num_ver()
556 && snum012[4] != -1) ? snum012[4] : 0); in get_num_ver()
560 op_unit_num(&vn->vn_vi[split_item_num]) - snum012[3] - in get_num_ver()
561 bytes_to_r - bytes_to_l - bytes_to_S2new; in get_num_ver()
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()
610 /* check, does node disappear if we shift tb->lnum[0] items to left
611 neighbor and tb->rnum[0] to the right one. */
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()
623 remain_items = vn->vn_nr_item; in is_leaf_removable()
626 remain_items -= (to_left + to_right); in is_leaf_removable()
630 set_parameters(tb, 0, to_left, vn->vn_nr_item - to_left, 0, in is_leaf_removable()
631 NULL, -1, -1); in is_leaf_removable()
635 if (remain_items > 1 || tb->lbytes == -1 || tb->rbytes == -1) in is_leaf_removable()
642 size = op_unit_num(&(vn->vn_vi[to_left])); in is_leaf_removable()
644 if (tb->lbytes + tb->rbytes >= size) { in is_leaf_removable()
646 tb->lbytes, -1); in is_leaf_removable()
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()
663 if (vn->vn_nr_item) { in are_leaves_removable()
664 if (vn->vn_vi[0].vi_type & VI_TYPE_LEFT_MERGEABLE) in are_leaves_removable()
667 if (vn->vn_vi[vn->vn_nr_item - 1]. in are_leaves_removable()
675 "vs-8125: item number must be 1: it is %d", in are_leaves_removable()
679 if (tb->CFR[0] in are_leaves_removable()
680 && !comp_short_le_keys(&(ih->ih_key), in are_leaves_removable()
681 B_N_PDELIM_KEY(tb->CFR[0], in are_leaves_removable()
682 tb->rkey[0]))) in are_leaves_removable()
696 "vs-8130: first directory item can not be removed until directory is not empty"); in are_leaves_removable()
701 if (MAX_CHILD_SIZE(S0) + vn->vn_size <= rfree + lfree + ih_size) { 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()
716 to_l = (MAX_NR_KEY(Sh)+1 - lpar + vn->vn_nr_item + 1) / 2 -\
717 (MAX_NR_KEY(Sh) + 1 - lpar);\
719 set_parameters (tb, h, to_l, 0, lnver, NULL, -1, -1);\
725 tb->lbytes, -1);\
727 set_parameters (tb, h, lpar - (tb->lbytes!=-1), 0, lnver, snum012+lset,\
728 -1, -1);\
736 to_r = (MAX_NR_KEY(Sh)+1 - rpar + vn->vn_nr_item + 1) / 2 - (MAX_NR_KEY(Sh) + 1 - rpar);\
738 set_parameters (tb, h, 0, to_r, rnver, NULL, -1, -1);\
744 -1, tb->rbytes);\
746 set_parameters (tb, h, 0, rpar - (tb->rbytes!=-1), rnver, snum012+rset,\
747 -1, -1);\
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()
774 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked;
775 * CARRY_ON - schedule didn't occur while the function worked;
776 * NO_DISK_SPACE - no disk space.
778 /* The function is NOT SCHEDULE-SAFE! */
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()
791 number_of_freeblk = tb->cur_blknum can be non-zero if a schedule occurs in get_empty_nodes()
804 for (counter = 0, number_of_freeblk = tb->cur_blknum; in get_empty_nodes()
806 number_of_freeblk -= 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()
815 amount_needed -= number_of_freeblk; in get_empty_nodes()
819 /* No need to check quota - is not allocated for blocks used for formatted nodes */ in get_empty_nodes()
829 "PAP-8135: reiserfs_new_blocknrs failed when got new blocks"); in get_empty_nodes()
835 "PAP-8140: journaled or dirty buffer %b for the new block", in get_empty_nodes()
839 RFALSE(tb->FEB[tb->cur_blknum], in get_empty_nodes()
840 "PAP-8141: busy slot for new buffer"); in get_empty_nodes()
843 tb->FEB[tb->cur_blknum++] = new_bh; in get_empty_nodes()
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()
870 return (MAX_CHILD_SIZE(f) - dc_size(B_N_CHILD(f, order))); in get_lfree()
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()
892 return (MAX_CHILD_SIZE(f) - dc_size(B_N_CHILD(f, order))); in get_rfree()
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()
916 "vs-8165: F[h] (%b) or FL[h] (%b) is invalid", 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()
929 "vs-8170: left neighbor (%b %z) is not in the tree", in is_left_neighbor_in_cache()
944 item_ops[cpu_key_k_type(key)]->decrement_key(key); in decrement_key()
951 * Returns: PATH_INCORRECT - path in the tree is not correct;
952 SCHEDULE_OCCURRED - schedule occurred while the function worked;
953 * CARRY_ON - schedule didn't occur while the function worked;
962 struct treepath *path = tb->tb_path; in get_far_parent()
975 "PAP-8180: invalid path length"); in get_far_parent()
977 for (; counter > FIRST_PATH_ELEMENT_OFFSET; counter--) { in get_far_parent()
980 (parent = PATH_OFFSET_PBUFFER(path, counter - 1))) in get_far_parent()
985 counter - 1)) > in get_far_parent()
990 PATH_OFFSET_PBUFFER(path, counter)->b_blocknr) in get_far_parent()
998 /*(*pcom_father = parent)->b_count++; */ in get_far_parent()
1007 (tb->tb_path, in get_far_parent()
1008 FIRST_PATH_ELEMENT_OFFSET)->b_blocknr == in get_far_parent()
1009 SB_ROOT_BLOCK(tb->tb_sb)) { in get_far_parent()
1017 "PAP-8185: (%b %z) level too small", 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()
1041 LEFT_PARENTS) ? (tb->lkey[h - 1] = in get_far_parent()
1042 position - 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()
1065 "PAP-8190: (%b %z) level too small", *pfather, *pfather); in get_far_parent()
1067 FIRST_PATH_ELEMENT_OFFSET, "PAP-8192: path length is too small"); in get_far_parent()
1069 s_path_to_neighbor_father.path_length--; in get_far_parent()
1078 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked;
1079 * CARRY_ON - schedule didn't occur while the function worked;
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()
1105 position = PATH_OFFSET_POSITION(path, path_offset - 1); in get_parents()
1108 curf = PATH_OFFSET_PBUFFER(path, path_offset - 1); in get_parents()
1109 curcf = PATH_OFFSET_PBUFFER(path, path_offset - 1); in get_parents()
1112 tb->lkey[h] = position - 1; 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()
1131 "PAP-8195: FL (%b) or CFL (%b) is invalid", curf, curcf); in get_parents()
1146 curf = PATH_OFFSET_PBUFFER(path, path_offset - 1); in get_parents()
1147 curcf = PATH_OFFSET_PBUFFER(path, path_offset - 1); 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()
1163 "PAP-8205: FR (%b) or CFR (%b) is invalid", curf, curcf); in get_parents()
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()
1184 - in can_node_be_removed()
1186 && op_is_left_mergeable(&(ih->ih_key), Sh->b_size)) ? IH_SIZE : 0) in can_node_be_removed()
1187 - in can_node_be_removed()
1189 && op_is_left_mergeable(r_key, Sh->b_size)) ? IH_SIZE : 0) 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()
1212 * mode i - insert, p - paste;
1213 * Returns: 1 - schedule occurred;
1214 * 0 - balancing for higher levels needed;
1215 * -1 - no balancing for higher levels needed;
1216 * -2 - no disk space.
1221 struct virtual_node *vn = tb->tb_vn; in ip_check_balance()
1246 where 4th parameter is s1bytes and 5th - s2bytes in ip_check_balance()
1249 0,1 - do not shift and do not shift but bottle in ip_check_balance()
1250 2 - shift only whole item to left in ip_check_balance()
1251 3 - shift to left and bottle as much as possible in ip_check_balance()
1252 4,5 - shift to right (whole items and as much as possible in ip_check_balance()
1253 6,7 - shift to both directions (whole items and as much as possible) 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()
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()
1290 if (can_node_be_removed(vn->vn_mode, lfree, sfree, rfree, tb, h) == 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()
1324 vn->vn_nr_item + 1) / 2 - (MAX_NR_KEY(Sh) + 1 - 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()
1327 -1, -1); 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()
1335 "vs-8220: tree is not balanced on internal level"); 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()
1338 "vs-8225: tree is not balanced on leaf level"); 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()
1363 lpar, rpar - number of items we can shift to left/right neighbor (including splitting item) in ip_check_balance()
1364 nset, lset, rset, lrset - shows, whether flowing items give better packing 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()
1388 0, -1, h ? vn->vn_nr_item : 0, -1, in ip_check_balance()
1394 /* note, that in this case we try to bottle between S[0] and S1 (S1 - the first new node) */ in ip_check_balance()
1395 nver1 = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1396 0, -1, 0, -1, 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()
1411 -1, h ? vn->vn_nr_item : 0, -1, in ip_check_balance()
1416 lnver1 = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1417 lpar - 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()
1433 0, -1, in ip_check_balance()
1434 h ? (vn->vn_nr_item - rpar) : (rpar - in ip_check_balance()
1435 ((tb-> in ip_check_balance()
1437 -1) ? 1 : in ip_check_balance()
1438 0)), -1, in ip_check_balance()
1443 rnver1 = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1444 0, -1, in ip_check_balance()
1445 (rpar - 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()
1462 -1, in ip_check_balance()
1463 h ? (vn->vn_nr_item - rpar) : (rpar - in ip_check_balance()
1464 ((tb-> in ip_check_balance()
1466 -1) ? 1 : in ip_check_balance()
1467 0)), -1, in ip_check_balance()
1472 lrnver1 = get_num_ver(vn->vn_mode, tb, h, in ip_check_balance()
1473 lpar - in ip_check_balance()
1474 ((tb->lbytes != -1) ? 1 : 0), in ip_check_balance()
1475 tb->lbytes, in ip_check_balance()
1476 (rpar - 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()
1495 || h != 1), "vs-8230: bad h"); 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()
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()
1506 lrnver, snum012 + lrset, -1, -1); in ip_check_balance()
1513 set_parameters(tb, h, 0, 0, nver, snum012 + nset, -1, in ip_check_balance()
1514 -1); in ip_check_balance()
1553 * mode i - insert, p - paste;
1554 * Returns: 1 - schedule occurred;
1555 * 0 - balancing for higher levels needed;
1556 * -1 - no balancing for higher levels needed;
1557 * -2 - no disk space.
1560 * the internal part of S+tree is as for the B-trees.
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()
1577 /* using tb->insert_size[h], which is negative in this case, create_virtual_node calculates: */ in dc_check_balance_internal()
1583 if (vn->vn_nr_item > 0) { 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()
1605 if (vn->vn_nr_item >= MIN_NR_KEY(Sh)) { /* Balance condition for the internal node is valid. in dc_check_balance_internal()
1607 if (vn->vn_nr_item == MIN_NR_KEY(Sh)) { /* Here we join S[h] with one of its neighbors, 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()
1622 -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()
1639 -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()
1653 0, NULL, -1, -1); 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()
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()
1702 vn->vn_nr_item + 1) / 2 - (MAX_NR_KEY(Sh) + 1 - 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()
1705 -1, -1); 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()
1718 1) / 2 - (vn->vn_nr_item + 1); in dc_check_balance_internal()
1719 set_parameters(tb, h, -from_l, 0, 1, NULL, -1, -1); in dc_check_balance_internal()
1724 -((MAX_NR_KEY(Sh) + 1 - tb->rnum[h] + vn->vn_nr_item + in dc_check_balance_internal()
1725 1) / 2 - (vn->vn_nr_item + 1)), 1, NULL, -1, -1); in dc_check_balance_internal()
1736 * mode i - insert, p - paste;
1737 * Returns: 1 - schedule occurred;
1738 * 0 - balancing for higher levels needed;
1739 * -1 - no balancing for higher levels needed;
1740 * -2 - no disk space.
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()
1767 RFALSE(-levbytes >= maxsize - B_FREE_SPACE(S0), in dc_check_balance_leaf()
1768 "vs-8240: attempt to create empty buffer tree"); in dc_check_balance_leaf()
1770 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); 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()
1800 "vs-8245: dc_check_balance_leaf: FL[h] must exist"); 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()
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()
1830 * mode d - delete, c - cut.
1831 * Returns: 1 - schedule occurred;
1832 * 0 - balancing for higher levels needed;
1833 * -1 - no balancing for higher levels needed;
1834 * -2 - no disk space.
1838 RFALSE(!(PATH_H_PBUFFER(tb->tb_path, h)), in dc_check_balance()
1839 "vs-8250: S is not initialized"); in dc_check_balance()
1859 * mode i - insert, p - paste, d - delete, c - cut.
1860 * Returns: 1 - schedule occurred;
1861 * 0 - balancing for higher levels needed;
1862 * -1 - no balancing for higher levels needed;
1863 * -2 - no disk space.
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()
1876 vn->vn_mode = mode; in check_balance()
1877 vn->vn_affected_item_num = inum; in check_balance()
1878 vn->vn_pos_in_item = pos_in_item; in check_balance()
1879 vn->vn_ins_ih = ins_ih; in check_balance()
1880 vn->vn_data = data; in check_balance()
1882 RFALSE(mode == M_INSERT && !vn->vn_ins_ih, in check_balance()
1883 "vs-8255: ins_ih can not be 0 in insert mode"); in check_balance()
1885 if (tb->insert_size[h] > 0) in check_balance()
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()
1904 RFALSE(path_offset < FIRST_PATH_ELEMENT_OFFSET - 1, in get_direct_parent()
1905 "PAP-8260: invalid offset in the path"); in get_direct_parent()
1907 if (PATH_OFFSET_PBUFFER(path, FIRST_PATH_ELEMENT_OFFSET)-> in get_direct_parent()
1908 b_blocknr == SB_ROOT_BLOCK(tb->tb_sb)) { in get_direct_parent()
1910 PATH_OFFSET_PBUFFER(path, path_offset - 1) = NULL; in get_direct_parent()
1911 PATH_OFFSET_POSITION(path, path_offset - 1) = 0; in get_direct_parent()
1918 (bh = PATH_OFFSET_PBUFFER(path, path_offset - 1))) in get_direct_parent()
1923 path_offset - 1)) > B_NR_ITEMS(bh)) in get_direct_parent()
1927 PATH_OFFSET_PBUFFER(path, path_offset)->b_blocknr) 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()
1945 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked;
1946 * CARRY_ON - schedule didn't occur while the function worked;
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()
1965 "PAP-8270: invalid position in the parent"); 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()
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()
1986 bh->b_blocknr, "PAP-8275: invalid parent"); in get_neighbors()
1987 RFALSE(!B_IS_IN_TREE(bh), "PAP-8280: invalid child"); in get_neighbors()
1990 MAX_CHILD_SIZE(bh) - in get_neighbors()
1991 dc_size(B_N_CHILD(tb->FL[0], child_position)), in get_neighbors()
1992 "PAP-8290: invalid child size of left neighbor"); 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()
2007 "PAP-8295: invalid position in the parent"); 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()
2022 brelse(tb->R[h]); in get_neighbors()
2023 tb->R[h] = bh; in get_neighbors()
2027 MAX_CHILD_SIZE(bh) - in get_neighbors()
2028 dc_size(B_N_CHILD(tb->FR[0], child_position)), in get_neighbors()
2029 "PAP-8300: invalid child size of right neighbor (%d != %d - %d)", in get_neighbors()
2031 dc_size(B_N_CHILD(tb->FR[0], child_position))); in get_neighbors()
2041 unsigned long blocksize = sb->s_blocksize; in get_virtual_node_size()
2045 max_num_of_items = (blocksize - BLKH_SIZE) / (IH_SIZE + MIN_ITEM_LEN); in get_virtual_node_size()
2046 max_num_of_entries = (blocksize - BLKH_SIZE - IH_SIZE) / in get_virtual_node_size()
2050 max(max_num_of_items * sizeof(struct virtual_item), in get_virtual_node_size()
2052 (max_num_of_entries - 1) * sizeof(__u16)); in get_virtual_node_size()
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()
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()
2110 if (atomic_read(&(bh->b_count)) <= 0) in tb_buffer_sanity_check()
2112 reiserfs_panic(sb, "jmacd-1", "negative or zero " in tb_buffer_sanity_check()
2117 reiserfs_panic(sb, "jmacd-2", "buffer is not up " in tb_buffer_sanity_check()
2122 reiserfs_panic(sb, "jmacd-3", "buffer is not " in tb_buffer_sanity_check()
2126 if (bh->b_bdev != sb->s_bdev) in tb_buffer_sanity_check()
2127 reiserfs_panic(sb, "jmacd-4", "buffer has wrong " in tb_buffer_sanity_check()
2131 if (bh->b_size != sb->s_blocksize) in tb_buffer_sanity_check()
2132 reiserfs_panic(sb, "jmacd-5", "buffer has wrong " in tb_buffer_sanity_check()
2136 if (bh->b_blocknr > SB_BLOCK_COUNT(sb)) in tb_buffer_sanity_check()
2137 reiserfs_panic(sb, "jmacd-6", "buffer block " in tb_buffer_sanity_check()
2167 for (i = tb->tb_path->path_length; in wait_tb_buffers_until_unlocked()
2168 !locked && i > ILLEGAL_PATH_ELEMENT_OFFSET; i--) { in wait_tb_buffers_until_unlocked()
2169 if (PATH_OFFSET_PBUFFER(tb->tb_path, i)) { in wait_tb_buffers_until_unlocked()
2171 ** in the path is in the tree --clm 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()
2181 path_length - i); 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()
2264 ** --clm 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()
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()
2311 * will be a pain in the butt that could have been avoided. Grumble grumble. -Hans
2313 * fix is meant in the sense of render unchanging
2316 * and then getting as many of them in parallel as possible? -Hans
2319 * op_mode i - insert, d - delete, c - cut (truncate), p - paste (append)
2322 * pos_in_item - comment this if you can
2325 * Returns: 1 - schedule occurred while the function worked;
2326 * 0 - schedule didn't occur while the function worked;
2327 * -1 - if no_disk_space
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()
2362 reiserfs_write_unlock(tb->tb_sb); in fix_nodes()
2364 reiserfs_write_lock(tb->tb_sb); 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()
2386 "item number %d (in S0 - %d) in case " in fix_nodes()
2394 print_block(tbS0, 0, -1, -1); 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()
2409 // FIXME: maybe -ENOMEM when tb->vn_buf == 0? Now just repeat in fix_nodes()
2413 for (h = 0; h < MAX_HEIGHT && tb->insert_size[h]; h++) { in fix_nodes()
2426 if (h != MAX_HEIGHT - 1) in fix_nodes()
2427 tb->insert_size[h + 1] = 0; in fix_nodes()
2444 if (!PATH_H_PBUFFER(tb->tb_path, h)) { in fix_nodes()
2448 RFALSE(tb->blknum[h] != 1, in fix_nodes()
2449 "PAP-8350: creating new empty root"); in fix_nodes()
2451 if (h < MAX_HEIGHT - 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()
2460 RFALSE(h == MAX_HEIGHT - 1, in fix_nodes()
2461 "PAP-8355: attempt to create too high of a tree"); in fix_nodes()
2463 tb->insert_size[h + 1] = in fix_nodes()
2465 KEY_SIZE) * (tb->blknum[h] - 1) + in fix_nodes()
2467 } else if (h < MAX_HEIGHT - 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()
2491 // failure. If the first is the case - the search will be in fix_nodes()
2492 // repeated. For now - free all resources acquired so far except 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()
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()
2579 /* de-allocated block which was not used by balancing and 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()