reiserfs: balance_leaf refactor, pull out balance_leaf_finish_node_paste
authorJeff Mahoney <jeffm@suse.com>
Wed, 23 Apr 2014 14:00:54 +0000 (10:00 -0400)
committerJan Kara <jack@suse.cz>
Wed, 7 May 2014 17:03:35 +0000 (19:03 +0200)
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>
fs/reiserfs/do_balan.c

index 1c4b45993c793e7aa4303f5802df02b8bb69b6ce..18adf948aa80e7ddcb21523b5f5bc7aa51972372 100644 (file)
@@ -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
This page took 0.028811 seconds and 5 git commands to generate.