summaryrefslogtreecommitdiff
path: root/fs/reiserfs
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2014-04-23 10:00:48 -0400
committerJan Kara <jack@suse.cz>2014-05-07 18:34:13 +0200
commitcf22df182bfce50670c25ce432e679e03aff3745 (patch)
tree547b537de06ab7a91be3d6ea7d38c91f11e2a0df /fs/reiserfs
parentf1f007c308eb95be5ebb3d9fec566f86662975be (diff)
reiserfs: balance_leaf refactor, pull out balance_leaf_paste_left
This patch factors out a new balance_leaf_paste_left from the code in balance_leaf responsible for pasting new content into an existing item located in the node to the left of S[0] in the tree. 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.c117
1 files changed, 64 insertions, 53 deletions
diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
index 44eb4f6ce0da..f8fab372e32c 100644
--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -348,62 +348,13 @@ static void balance_leaf_insert_left(struct tree_balance *tb,
}
-/**
- * balance_leaf - reiserfs tree balancing algorithm
- * @tb: tree balance state
- * @ih: item header of inserted item (little endian)
- * @body: body of inserted item or bytes to paste
- * @flag: i - insert, d - delete, c - cut, p - paste (see do_balance)
- * passed back:
- * @insert_key: key to insert new nodes
- * @insert_ptr: array of nodes to insert at the next level
- *
- * In our processing of one level we sometimes determine what must be
- * inserted into the next higher level. This insertion consists of a
- * key or two keys and their corresponding pointers.
- */
-static int balance_leaf(struct tree_balance *tb, struct item_head *ih,
- const char *body, int flag,
- struct item_head *insert_key,
- struct buffer_head **insert_ptr)
+static void balance_leaf_paste_left(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;
- int n, i;
int ret_val;
-
- PROC_INFO_INC(tb->tb_sb, balance_at[0]);
-
- /* Make balance in case insert_size[0] < 0 */
- if (tb->insert_size[0] < 0)
- return balance_leaf_when_delete(tb, flag);
-
- tb->item_pos = PATH_LAST_POSITION(tb->tb_path),
- tb->pos_in_item = tb->tb_path->pos_in_item,
- tb->zeroes_num = 0;
- if (flag == M_INSERT && !body)
- tb->zeroes_num = ih_item_len(ih);
-
- /*
- * for indirect item pos_in_item is measured in unformatted node
- * pointers. Recalculate to bytes
- */
- if (flag != M_INSERT
- && is_indirect_le_ih(item_head(tbS0, tb->item_pos)))
- tb->pos_in_item *= UNFM_P_SIZE;
-
- if (tb->lnum[0] > 0) {
- /* Shift lnum[0] items from S[0] to the left neighbor L[0] */
- if (tb->item_pos < tb->lnum[0]) {
- /* new item or it part falls to L[0], shift it too */
- n = B_NR_ITEMS(tb->L[0]);
-
- switch (flag) {
- case M_INSERT: /* insert item into L[0] */
- balance_leaf_insert_left(tb, ih, body);
- break;
-
- case M_PASTE: /* append item in L[0] */
+ struct buffer_info bi;
+ int n = B_NR_ITEMS(tb->L[0]);
if (tb->item_pos == tb->lnum[0] - 1 && tb->lbytes != -1) {
/* we must shift the part of the appended item */
@@ -554,6 +505,66 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih,
tb->insert_size[0] = 0;
tb->zeroes_num = 0;
}
+
+}
+
+/**
+ * balance_leaf - reiserfs tree balancing algorithm
+ * @tb: tree balance state
+ * @ih: item header of inserted item (little endian)
+ * @body: body of inserted item or bytes to paste
+ * @flag: i - insert, d - delete, c - cut, p - paste (see do_balance)
+ * passed back:
+ * @insert_key: key to insert new nodes
+ * @insert_ptr: array of nodes to insert at the next level
+ *
+ * In our processing of one level we sometimes determine what must be
+ * inserted into the next higher level. This insertion consists of a
+ * key or two keys and their corresponding pointers.
+ */
+static int balance_leaf(struct tree_balance *tb, struct item_head *ih,
+ const char *body, int flag,
+ struct item_head *insert_key,
+ struct buffer_head **insert_ptr)
+{
+ struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+ struct buffer_info bi;
+ int n, i;
+ int ret_val;
+
+ PROC_INFO_INC(tb->tb_sb, balance_at[0]);
+
+ /* Make balance in case insert_size[0] < 0 */
+ if (tb->insert_size[0] < 0)
+ return balance_leaf_when_delete(tb, flag);
+
+ tb->item_pos = PATH_LAST_POSITION(tb->tb_path),
+ tb->pos_in_item = tb->tb_path->pos_in_item,
+ tb->zeroes_num = 0;
+ if (flag == M_INSERT && !body)
+ tb->zeroes_num = ih_item_len(ih);
+
+ /*
+ * for indirect item pos_in_item is measured in unformatted node
+ * pointers. Recalculate to bytes
+ */
+ if (flag != M_INSERT
+ && is_indirect_le_ih(item_head(tbS0, tb->item_pos)))
+ tb->pos_in_item *= UNFM_P_SIZE;
+
+ if (tb->lnum[0] > 0) {
+ /* Shift lnum[0] items from S[0] to the left neighbor L[0] */
+ if (tb->item_pos < tb->lnum[0]) {
+ /* new item or it part falls to L[0], shift it too */
+ n = B_NR_ITEMS(tb->L[0]);
+
+ switch (flag) {
+ case M_INSERT: /* insert item into L[0] */
+ balance_leaf_insert_left(tb, ih, body);
+ break;
+
+ case M_PASTE: /* append item in L[0] */
+ balance_leaf_paste_left(tb, ih, body);
break;
default: /* cases d and t */
reiserfs_panic(tb->tb_sb, "PAP-12130",