summaryrefslogtreecommitdiff
path: root/fs/reiserfs/do_balan.c
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2014-04-23 18:00:54 +0400
committerJan Kara <jack@suse.cz>2014-05-07 21:03:35 +0400
commit7f447ba825a0752c0450ebd129f187484e86fe8b (patch)
tree8a00825c86e095839a82c5925952e36e25f90dec /fs/reiserfs/do_balan.c
parent8c480ea1940ffad74af3bb0db8885e413e6aee0a (diff)
downloadlinux-7f447ba825a0752c0450ebd129f187484e86fe8b.tar.xz
reiserfs: balance_leaf refactor, pull out balance_leaf_finish_node_paste
This patch factors out a new balance_leaf_finish_node_paste from the code in balance_leaf responsible for pasting new content into existing items held in S[0]. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/reiserfs/do_balan.c')
-rw-r--r--fs/reiserfs/do_balan.c150
1 files changed, 79 insertions, 71 deletions
diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
index 1c4b45993c79..18adf948aa80 100644
--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -982,6 +982,82 @@ static void balance_leaf_finish_node_insert(struct tree_balance *tb,
}
}
+static void balance_leaf_finish_node_paste(struct tree_balance *tb,
+ struct item_head *ih,
+ const char *body)
+{
+ struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+ struct buffer_info bi;
+ struct item_head *pasted;
+
+ pasted = item_head(tbS0, tb->item_pos);
+ /* when directory, may be new entry already pasted */
+ if (is_direntry_le_ih(pasted)) {
+ if (tb->pos_in_item >= 0 && tb->pos_in_item <= ih_entry_count(pasted)) {
+
+ RFALSE(!tb->insert_size[0],
+ "PAP-12260: insert_size is 0 already");
+
+ /* prepare space */
+ buffer_info_init_tbS0(tb, &bi);
+ leaf_paste_in_buffer(&bi, tb->item_pos, tb->pos_in_item,
+ tb->insert_size[0], body,
+ tb->zeroes_num);
+
+ /* paste entry */
+ leaf_paste_entries(&bi, tb->item_pos, tb->pos_in_item, 1,
+ (struct reiserfs_de_head *)body,
+ body + DEH_SIZE,
+ tb->insert_size[0]);
+ if (!tb->item_pos && !tb->pos_in_item) {
+ RFALSE(!tb->CFL[0] || !tb->L[0],
+ "PAP-12270: CFL[0]/L[0] must be specified");
+ if (tb->CFL[0])
+ replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0, 0);
+ }
+ tb->insert_size[0] = 0;
+ }
+ } else { /* regular object */
+ if (tb->pos_in_item == ih_item_len(pasted)) {
+
+ RFALSE(tb->insert_size[0] <= 0,
+ "PAP-12275: insert size must not be %d",
+ tb->insert_size[0]);
+ buffer_info_init_tbS0(tb, &bi);
+ leaf_paste_in_buffer(&bi, tb->item_pos, tb->pos_in_item,
+ tb->insert_size[0], body, tb->zeroes_num);
+
+ if (is_indirect_le_ih(pasted)) {
+#if 0
+ RFALSE(tb->
+ insert_size[0] !=
+ UNFM_P_SIZE,
+ "PAP-12280: insert_size for indirect item must be %d, not %d",
+ UNFM_P_SIZE,
+ tb->
+ insert_size[0]);
+#endif
+ set_ih_free_space(pasted, 0);
+ }
+ tb->insert_size[0] = 0;
+ }
+#ifdef CONFIG_REISERFS_CHECK
+ else {
+ if (tb->insert_size[0]) {
+ print_cur_tb("12285");
+ reiserfs_panic(tb->tb_sb,
+ "PAP-12285",
+ "insert_size "
+ "must be 0 "
+ "(%d)",
+ tb->insert_size[0]);
+ }
+ }
+#endif /* CONFIG_REISERFS_CHECK */
+
+ }
+}
+
/**
* balance_leaf - reiserfs tree balancing algorithm
* @tb: tree balance state
@@ -1002,7 +1078,6 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih,
struct buffer_head **insert_ptr)
{
struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
- struct buffer_info bi;
int n, i;
PROC_INFO_INC(tb->tb_sb, balance_at[0]);
@@ -1159,76 +1234,9 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih,
balance_leaf_finish_node_insert(tb, ih, body);
break;
- case M_PASTE:{ /* append item in S[0] */
- struct item_head *pasted;
-
- pasted = item_head(tbS0, tb->item_pos);
- /* when directory, may be new entry already pasted */
- if (is_direntry_le_ih(pasted)) {
- if (tb->pos_in_item >= 0 && tb->pos_in_item <= ih_entry_count(pasted)) {
-
- RFALSE(!tb->insert_size[0],
- "PAP-12260: insert_size is 0 already");
-
- /* prepare space */
- buffer_info_init_tbS0(tb, &bi);
- leaf_paste_in_buffer(&bi, tb->item_pos, tb->pos_in_item,
- tb->insert_size[0], body,
- tb->zeroes_num);
-
- /* paste entry */
- leaf_paste_entries(&bi, tb->item_pos, tb->pos_in_item, 1,
- (struct reiserfs_de_head *)body,
- body + DEH_SIZE,
- tb->insert_size[0]);
- if (!tb->item_pos && !tb->pos_in_item) {
- RFALSE(!tb->CFL[0] || !tb->L[0],
- "PAP-12270: CFL[0]/L[0] must be specified");
- if (tb->CFL[0])
- replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0, 0);
- }
- tb->insert_size[0] = 0;
- }
- } else { /* regular object */
- if (tb->pos_in_item == ih_item_len(pasted)) {
-
- RFALSE(tb->insert_size[0] <= 0,
- "PAP-12275: insert size must not be %d",
- tb->insert_size[0]);
- buffer_info_init_tbS0(tb, &bi);
- leaf_paste_in_buffer(&bi, tb->item_pos, tb->pos_in_item,
- tb->insert_size[0], body, tb->zeroes_num);
-
- if (is_indirect_le_ih(pasted)) {
-#if 0
- RFALSE(tb->
- insert_size[0] !=
- UNFM_P_SIZE,
- "PAP-12280: insert_size for indirect item must be %d, not %d",
- UNFM_P_SIZE,
- tb->
- insert_size[0]);
-#endif
- set_ih_free_space(pasted, 0);
- }
- tb->insert_size[0] = 0;
- }
-#ifdef CONFIG_REISERFS_CHECK
- else {
- if (tb->insert_size[0]) {
- print_cur_tb("12285");
- reiserfs_panic(tb->tb_sb,
- "PAP-12285",
- "insert_size "
- "must be 0 "
- "(%d)",
- tb->insert_size[0]);
- }
- }
-#endif /* CONFIG_REISERFS_CHECK */
-
- }
- } /* case M_PASTE: */
+ case M_PASTE: /* append item in S[0] */
+ balance_leaf_finish_node_paste(tb, ih, body);
+ break;
}
}
#ifdef CONFIG_REISERFS_CHECK