diff options
author | Jeff Mahoney <jeffm@suse.com> | 2014-04-23 10:00:50 -0400 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2014-05-07 12:47:53 -0400 |
commit | 3f0eb27655bba38e3dfb14db93b2720c4eccf4a8 (patch) | |
tree | 8247ab2c0c8b6142c2607aadae70c4742bf05d60 /fs/reiserfs | |
parent | e80ef3d1488e3bfb8eb39b0643cfaffb25ed9814 (diff) |
reiserfs: balance_leaf refactor, pull out balance_leaf_paste_right
This patch factors out a new balance_leaf_paste_right from the code in
balance_leaf responsible for pasting new contents into an existing item
located in the node to the right of S[0] in the tree.
It has not been reformatted yet.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/reiserfs')
-rw-r--r-- | fs/reiserfs/do_balan.c | 170 |
1 files changed, 90 insertions, 80 deletions
diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c index fc15e676a651..4dbe0a34739f 100644 --- a/fs/reiserfs/do_balan.c +++ b/fs/reiserfs/do_balan.c | |||
@@ -582,91 +582,14 @@ static void balance_leaf_insert_right(struct tree_balance *tb, | |||
582 | 582 | ||
583 | } | 583 | } |
584 | 584 | ||
585 | /** | 585 | static void balance_leaf_paste_right(struct tree_balance *tb, |
586 | * balance_leaf - reiserfs tree balancing algorithm | 586 | struct item_head *ih, const char *body) |
587 | * @tb: tree balance state | ||
588 | * @ih: item header of inserted item (little endian) | ||
589 | * @body: body of inserted item or bytes to paste | ||
590 | * @flag: i - insert, d - delete, c - cut, p - paste (see do_balance) | ||
591 | * passed back: | ||
592 | * @insert_key: key to insert new nodes | ||
593 | * @insert_ptr: array of nodes to insert at the next level | ||
594 | * | ||
595 | * In our processing of one level we sometimes determine what must be | ||
596 | * inserted into the next higher level. This insertion consists of a | ||
597 | * key or two keys and their corresponding pointers. | ||
598 | */ | ||
599 | static int balance_leaf(struct tree_balance *tb, struct item_head *ih, | ||
600 | const char *body, int flag, | ||
601 | struct item_head *insert_key, | ||
602 | struct buffer_head **insert_ptr) | ||
603 | { | 587 | { |
604 | struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); | 588 | struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); |
589 | int n = B_NR_ITEMS(tbS0); | ||
605 | struct buffer_info bi; | 590 | struct buffer_info bi; |
606 | int n, i; | ||
607 | int ret_val; | 591 | int ret_val; |
608 | 592 | ||
609 | PROC_INFO_INC(tb->tb_sb, balance_at[0]); | ||
610 | |||
611 | /* Make balance in case insert_size[0] < 0 */ | ||
612 | if (tb->insert_size[0] < 0) | ||
613 | return balance_leaf_when_delete(tb, flag); | ||
614 | |||
615 | tb->item_pos = PATH_LAST_POSITION(tb->tb_path), | ||
616 | tb->pos_in_item = tb->tb_path->pos_in_item, | ||
617 | tb->zeroes_num = 0; | ||
618 | if (flag == M_INSERT && !body) | ||
619 | tb->zeroes_num = ih_item_len(ih); | ||
620 | |||
621 | /* | ||
622 | * for indirect item pos_in_item is measured in unformatted node | ||
623 | * pointers. Recalculate to bytes | ||
624 | */ | ||
625 | if (flag != M_INSERT | ||
626 | && is_indirect_le_ih(item_head(tbS0, tb->item_pos))) | ||
627 | tb->pos_in_item *= UNFM_P_SIZE; | ||
628 | |||
629 | if (tb->lnum[0] > 0) { | ||
630 | /* Shift lnum[0] items from S[0] to the left neighbor L[0] */ | ||
631 | if (tb->item_pos < tb->lnum[0]) { | ||
632 | /* new item or it part falls to L[0], shift it too */ | ||
633 | n = B_NR_ITEMS(tb->L[0]); | ||
634 | |||
635 | switch (flag) { | ||
636 | case M_INSERT: /* insert item into L[0] */ | ||
637 | balance_leaf_insert_left(tb, ih, body); | ||
638 | break; | ||
639 | |||
640 | case M_PASTE: /* append item in L[0] */ | ||
641 | balance_leaf_paste_left(tb, ih, body); | ||
642 | break; | ||
643 | default: /* cases d and t */ | ||
644 | reiserfs_panic(tb->tb_sb, "PAP-12130", | ||
645 | "lnum > 0: unexpected mode: " | ||
646 | " %s(%d)", | ||
647 | (flag == M_DELETE) ? "DELETE" : ((flag == M_CUT) ? "CUT" : "UNKNOWN"), flag); | ||
648 | } | ||
649 | } else { | ||
650 | /* new item doesn't fall into L[0] */ | ||
651 | leaf_shift_left(tb, tb->lnum[0], tb->lbytes); | ||
652 | } | ||
653 | } | ||
654 | |||
655 | /* tb->lnum[0] > 0 */ | ||
656 | /* Calculate new item position */ | ||
657 | tb->item_pos -= (tb->lnum[0] - ((tb->lbytes != -1) ? 1 : 0)); | ||
658 | |||
659 | if (tb->rnum[0] > 0) { | ||
660 | /* shift rnum[0] items from S[0] to the right neighbor R[0] */ | ||
661 | n = B_NR_ITEMS(tbS0); | ||
662 | switch (flag) { | ||
663 | |||
664 | case M_INSERT: /* insert item */ | ||
665 | balance_leaf_insert_right(tb, ih, body); | ||
666 | break; | ||
667 | |||
668 | case M_PASTE: /* append item */ | ||
669 | |||
670 | if (n - tb->rnum[0] <= tb->item_pos) { /* pasted item or part of it falls to R[0] */ | 593 | if (n - tb->rnum[0] <= tb->item_pos) { /* pasted item or part of it falls to R[0] */ |
671 | if (tb->item_pos == n - tb->rnum[0] && tb->rbytes != -1) { /* we must shift the part of the appended item */ | 594 | if (tb->item_pos == n - tb->rnum[0] && tb->rbytes != -1) { /* we must shift the part of the appended item */ |
672 | if (is_direntry_le_ih(item_head(tbS0, tb->item_pos))) { /* we append to directory item */ | 595 | if (is_direntry_le_ih(item_head(tbS0, tb->item_pos))) { /* we append to directory item */ |
@@ -807,6 +730,93 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, | |||
807 | 730 | ||
808 | leaf_shift_right(tb, tb->rnum[0], tb->rbytes); | 731 | leaf_shift_right(tb, tb->rnum[0], tb->rbytes); |
809 | } | 732 | } |
733 | |||
734 | } | ||
735 | |||
736 | /** | ||
737 | * balance_leaf - reiserfs tree balancing algorithm | ||
738 | * @tb: tree balance state | ||
739 | * @ih: item header of inserted item (little endian) | ||
740 | * @body: body of inserted item or bytes to paste | ||
741 | * @flag: i - insert, d - delete, c - cut, p - paste (see do_balance) | ||
742 | * passed back: | ||
743 | * @insert_key: key to insert new nodes | ||
744 | * @insert_ptr: array of nodes to insert at the next level | ||
745 | * | ||
746 | * In our processing of one level we sometimes determine what must be | ||
747 | * inserted into the next higher level. This insertion consists of a | ||
748 | * key or two keys and their corresponding pointers. | ||
749 | */ | ||
750 | static int balance_leaf(struct tree_balance *tb, struct item_head *ih, | ||
751 | const char *body, int flag, | ||
752 | struct item_head *insert_key, | ||
753 | struct buffer_head **insert_ptr) | ||
754 | { | ||
755 | struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); | ||
756 | struct buffer_info bi; | ||
757 | int n, i; | ||
758 | |||
759 | PROC_INFO_INC(tb->tb_sb, balance_at[0]); | ||
760 | |||
761 | /* Make balance in case insert_size[0] < 0 */ | ||
762 | if (tb->insert_size[0] < 0) | ||
763 | return balance_leaf_when_delete(tb, flag); | ||
764 | |||
765 | tb->item_pos = PATH_LAST_POSITION(tb->tb_path), | ||
766 | tb->pos_in_item = tb->tb_path->pos_in_item, | ||
767 | tb->zeroes_num = 0; | ||
768 | if (flag == M_INSERT && !body) | ||
769 | tb->zeroes_num = ih_item_len(ih); | ||
770 | |||
771 | /* | ||
772 | * for indirect item pos_in_item is measured in unformatted node | ||
773 | * pointers. Recalculate to bytes | ||
774 | */ | ||
775 | if (flag != M_INSERT | ||
776 | && is_indirect_le_ih(item_head(tbS0, tb->item_pos))) | ||
777 | tb->pos_in_item *= UNFM_P_SIZE; | ||
778 | |||
779 | if (tb->lnum[0] > 0) { | ||
780 | /* Shift lnum[0] items from S[0] to the left neighbor L[0] */ | ||
781 | if (tb->item_pos < tb->lnum[0]) { | ||
782 | /* new item or it part falls to L[0], shift it too */ | ||
783 | n = B_NR_ITEMS(tb->L[0]); | ||
784 | |||
785 | switch (flag) { | ||
786 | case M_INSERT: /* insert item into L[0] */ | ||
787 | balance_leaf_insert_left(tb, ih, body); | ||
788 | break; | ||
789 | |||
790 | case M_PASTE: /* append item in L[0] */ | ||
791 | balance_leaf_paste_left(tb, ih, body); | ||
792 | break; | ||
793 | default: /* cases d and t */ | ||
794 | reiserfs_panic(tb->tb_sb, "PAP-12130", | ||
795 | "lnum > 0: unexpected mode: " | ||
796 | " %s(%d)", | ||
797 | (flag == M_DELETE) ? "DELETE" : ((flag == M_CUT) ? "CUT" : "UNKNOWN"), flag); | ||
798 | } | ||
799 | } else { | ||
800 | /* new item doesn't fall into L[0] */ | ||
801 | leaf_shift_left(tb, tb->lnum[0], tb->lbytes); | ||
802 | } | ||
803 | } | ||
804 | |||
805 | /* tb->lnum[0] > 0 */ | ||
806 | /* Calculate new item position */ | ||
807 | tb->item_pos -= (tb->lnum[0] - ((tb->lbytes != -1) ? 1 : 0)); | ||
808 | |||
809 | if (tb->rnum[0] > 0) { | ||
810 | /* shift rnum[0] items from S[0] to the right neighbor R[0] */ | ||
811 | n = B_NR_ITEMS(tbS0); | ||
812 | switch (flag) { | ||
813 | |||
814 | case M_INSERT: /* insert item */ | ||
815 | balance_leaf_insert_right(tb, ih, body); | ||
816 | break; | ||
817 | |||
818 | case M_PASTE: /* append item */ | ||
819 | balance_leaf_paste_right(tb, ih, body); | ||
810 | break; | 820 | break; |
811 | default: /* cases d and t */ | 821 | default: /* cases d and t */ |
812 | reiserfs_panic(tb->tb_sb, "PAP-12175", | 822 | reiserfs_panic(tb->tb_sb, "PAP-12175", |