All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Mahoney <jeffm@suse.com>
To: ReiserFS Development List <reiserfs-devel@vger.kernel.org>
Cc: Jan Kara <jack@suse.cz>, Dave Jones <davej@redhat.com>
Subject: [patch 22/29] reiserfs: balance_leaf refactor, pull out balance_leaf{left, right, new_nodes, finish_node}
Date: Wed, 23 Apr 2014 10:00:55 -0400	[thread overview]
Message-ID: <20140423151144.448716989@suse.com> (raw)
In-Reply-To: 20140423140033.704113918@suse.com

[-- Attachment #1: reiserfs-balance_leaf-refactor-pull-out-balance_leaf-left-right-new_nodes-finish_node --]
[-- Type: text/plain, Size: 8136 bytes --]

Break out the code that splits paste/insert for each phase.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 fs/reiserfs/do_balan.c |  207 +++++++++++++++++++++++++------------------------
 1 file changed, 108 insertions(+), 99 deletions(-)

--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -508,6 +508,27 @@ static void balance_leaf_paste_left(stru
 
 }
 
+/* Shift lnum[0] items from S[0] to the left neighbor L[0] */
+static void balance_leaf_left(struct tree_balance *tb, struct item_head *ih,
+			      const char *body, int flag)
+{
+	if (tb->lnum[0] <= 0)
+		return;
+
+	/* new item or it part falls to L[0], shift it too */
+	if (tb->item_pos < tb->lnum[0]) {
+		BUG_ON(flag != M_INSERT && flag != M_PASTE);
+
+		if (flag == M_INSERT)
+			balance_leaf_insert_left(tb, ih, body);
+		else /* M_PASTE */
+			balance_leaf_paste_left(tb, ih, body);
+	} else
+		/* new item doesn't fall into L[0] */
+		leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
+}
+
+
 static void balance_leaf_insert_right(struct tree_balance *tb,
 				      struct item_head *ih, const char *body)
 {
@@ -733,6 +754,22 @@ static void balance_leaf_paste_right(str
 
 }
 
+/* shift rnum[0] items from S[0] to the right neighbor R[0] */
+static void balance_leaf_right(struct tree_balance *tb, struct item_head *ih,
+			       const char *body, int flag)
+{
+	if (tb->rnum[0] <= 0)
+		return;
+
+	BUG_ON(flag != M_INSERT && flag != M_PASTE);
+
+	if (flag == M_INSERT)
+		balance_leaf_insert_right(tb, ih, body);
+	else /* M_PASTE */
+		balance_leaf_paste_right(tb, ih, body);
+
+}
+
 static void balance_leaf_new_nodes_insert(struct tree_balance *tb,
 					  struct item_head *ih,
 					  const char *body,
@@ -962,6 +999,55 @@ static void balance_leaf_new_nodes_paste
 
 }
 
+/* Fill new nodes that appear in place of S[0] */
+static void balance_leaf_new_nodes(struct tree_balance *tb,
+				   struct item_head *ih,
+				   const char *body,
+				   struct item_head *insert_key,
+				   struct buffer_head **insert_ptr,
+				   int flag)
+{
+	int i;
+	for (i = tb->blknum[0] - 2; i >= 0; i--) {
+
+		RFALSE(!tb->snum[i],
+		       "PAP-12200: snum[%d] == %d. Must be > 0", i,
+		       tb->snum[i]);
+
+		/* here we shift from S to S_new nodes */
+
+		tb->S_new[i] = get_FEB(tb);
+
+		/* initialized block type and tree level */
+		set_blkh_level(B_BLK_HEAD(tb->S_new[i]), DISK_LEAF_NODE_LEVEL);
+
+		switch (flag) {
+		case M_INSERT:	/* insert item */
+			balance_leaf_new_nodes_insert(tb, ih, body, insert_key,
+						      insert_ptr, i);
+			break;
+
+		case M_PASTE:	/* append item */
+			balance_leaf_new_nodes_paste(tb, ih, body, insert_key,
+						     insert_ptr, i);
+			break;
+		default:	/* cases d and t */
+			reiserfs_panic(tb->tb_sb, "PAP-12245",
+				       "blknum > 2: unexpected mode: %s(%d)",
+				       (flag == M_DELETE) ? "DELETE" : ((flag == M_CUT) ? "CUT" : "UNKNOWN"), flag);
+		}
+
+		memcpy(insert_key + i, leaf_key(tb->S_new[i], 0), KEY_SIZE);
+		insert_ptr[i] = tb->S_new[i];
+
+		RFALSE(!buffer_journaled(tb->S_new[i])
+		       || buffer_journal_dirty(tb->S_new[i])
+		       || buffer_dirty(tb->S_new[i]),
+		       "PAP-12247: S_new[%d] : (%b)",
+		       i, format_bh(tb->S_new[i]));
+	}
+}
+
 static void balance_leaf_finish_node_insert(struct tree_balance *tb,
 					    struct item_head *ih,
 					    const char *body)
@@ -1058,6 +1144,24 @@ static void balance_leaf_finish_node_pas
 				}
 }
 
+/*
+ * if the affected item was not wholly shifted then we
+ * perform all necessary operations on that part or whole
+ * of the affected item which remains in S
+ */
+static void balance_leaf_finish_node(struct tree_balance *tb,
+				      struct item_head *ih,
+				      const char *body, int flag)
+{
+	/* if we must insert or append into buffer S[0] */
+	if (0 <= tb->item_pos && tb->item_pos < tb->s0num) {
+		if (flag == M_INSERT)
+			balance_leaf_finish_node_insert(tb, ih, body);
+		else /* M_PASTE */
+			balance_leaf_finish_node_paste(tb, ih, body);
+	}
+}
+
 /**
  * balance_leaf - reiserfs tree balancing algorithm
  * @tb: tree balance state
@@ -1078,7 +1182,6 @@ static int balance_leaf(struct tree_bala
 			struct buffer_head **insert_ptr)
 {
 	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
-	int n, i;
 
 	PROC_INFO_INC(tb->tb_sb, balance_at[0]);
 
@@ -1100,55 +1203,13 @@ static int balance_leaf(struct tree_bala
 	    && 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",
-					       "lnum > 0: unexpected mode: "
-					       " %s(%d)",
-					       (flag == M_DELETE) ? "DELETE" : ((flag == M_CUT) ? "CUT" : "UNKNOWN"), flag);
-			}
-		} else {
-			/* new item doesn't fall into L[0] */
-			leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
-		}
-	}
+	balance_leaf_left(tb, ih, body, flag);
 
 	/* tb->lnum[0] > 0 */
 	/* Calculate new item position */
 	tb->item_pos -= (tb->lnum[0] - ((tb->lbytes != -1) ? 1 : 0));
 
-	if (tb->rnum[0] > 0) {
-		/* shift rnum[0] items from S[0] to the right neighbor R[0] */
-		n = B_NR_ITEMS(tbS0);
-		switch (flag) {
-
-		case M_INSERT:	/* insert item */
-			balance_leaf_insert_right(tb, ih, body);
-			break;
-
-		case M_PASTE:	/* append item */
-			balance_leaf_paste_right(tb, ih, body);
-			break;
-		default:	/* cases d and t */
-			reiserfs_panic(tb->tb_sb, "PAP-12175",
-				       "rnum > 0: unexpected mode: %s(%d)",
-				       (flag == M_DELETE) ? "DELETE" : ((flag == M_CUT) ? "CUT" : "UNKNOWN"), flag);
-		}
-
-	}
+	balance_leaf_right(tb, ih, body, flag);
 
 	/* tb->rnum[0] > 0 */
 	RFALSE(tb->blknum[0] > 3,
@@ -1183,62 +1244,10 @@ static int balance_leaf(struct tree_bala
 		return 0;
 	}
 
-	/* Fill new nodes that appear in place of S[0] */
-	for (i = tb->blknum[0] - 2; i >= 0; i--) {
-
-		RFALSE(!tb->snum[i],
-		       "PAP-12200: snum[%d] == %d. Must be > 0", i,
-		       tb->snum[i]);
-
-		/* here we shift from S to S_new nodes */
+	balance_leaf_new_nodes(tb, ih, body, insert_key, insert_ptr, flag);
 
-		tb->S_new[i] = get_FEB(tb);
+	balance_leaf_finish_node(tb, ih, body, flag);
 
-		/* initialized block type and tree level */
-		set_blkh_level(B_BLK_HEAD(tb->S_new[i]), DISK_LEAF_NODE_LEVEL);
-
-		n = B_NR_ITEMS(tbS0);
-
-		switch (flag) {
-		case M_INSERT:	/* insert item */
-			balance_leaf_new_nodes_insert(tb, ih, body, insert_key,
-						      insert_ptr, i);
-			break;
-
-		case M_PASTE:	/* append item */
-			balance_leaf_new_nodes_paste(tb, ih, body, insert_key,
-						     insert_ptr, i);
-			break;
-		default:	/* cases d and t */
-			reiserfs_panic(tb->tb_sb, "PAP-12245",
-				       "blknum > 2: unexpected mode: %s(%d)",
-				       (flag == M_DELETE) ? "DELETE" : ((flag == M_CUT) ? "CUT" : "UNKNOWN"), flag);
-		}
-
-		memcpy(insert_key + i, leaf_key(tb->S_new[i], 0), KEY_SIZE);
-		insert_ptr[i] = tb->S_new[i];
-
-		RFALSE(!buffer_journaled(tb->S_new[i])
-		       || buffer_journal_dirty(tb->S_new[i])
-		       || buffer_dirty(tb->S_new[i]),
-		       "PAP-12247: S_new[%d] : (%b)",
-		       i, tb->S_new[i]);
-	}
-
-	/* if the affected item was not wholly shifted then we perform all necessary operations on that part or whole of the
-	   affected item which remains in S */
-	if (0 <= tb->item_pos && tb->item_pos < tb->s0num) {	/* if we must insert or append into buffer S[0] */
-
-		switch (flag) {
-		case M_INSERT:	/* insert item into S[0] */
-			balance_leaf_finish_node_insert(tb, ih, body);
-			break;
-
-		case M_PASTE:	/* append item in S[0] */
-			balance_leaf_finish_node_paste(tb, ih, body);
-			break;
-		}
-	}
 #ifdef CONFIG_REISERFS_CHECK
 	if (flag == M_PASTE && tb->insert_size[0]) {
 		print_cur_tb("12290");



  parent reply	other threads:[~2014-04-23 14:00 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-23 14:00 [patch 00/29] reiserfs cleanup patchset Jeff Mahoney
2014-04-23 14:00 ` [patch 01/29] reiserfs: use per-fs commit workqueues Jeff Mahoney
2014-04-23 14:00 ` [patch 02/29] reiserfs: cleanup, rename key and item accessors to more friendly names Jeff Mahoney
2014-04-23 14:00 ` [patch 04/29] reiserfs: cleanup, remove nblocks argument from journal_end Jeff Mahoney
2014-04-23 14:00 ` [patch 05/29] reiserfs: cleanup, remove sb " Jeff Mahoney
2014-04-23 14:00 ` [patch 06/29] reiserfs: cleanup, remove sb argument from journal_mark_dirty Jeff Mahoney
2014-04-23 14:00 ` [patch 07/29] reiserfs: cleanup, remove blocks arg from journal_join Jeff Mahoney
2014-04-23 14:00 ` [patch 08/29] reiserfs: cleanup, remove leading whitespace from labels Jeff Mahoney
2014-04-23 14:00 ` [patch 09/29] reiserfs: cleanup, remove unnecessary parens Jeff Mahoney
2014-04-23 14:00 ` [patch 10/29] reiserfs: cleanup, remove unnecessary parens in dirent creation Jeff Mahoney
2014-04-23 14:00 ` [patch 11/29] reiserfs: cleanup, make hash detection saner Jeff Mahoney
2014-05-06 21:27   ` Jan Kara
2014-05-07 12:16     ` Jeff Mahoney
2014-05-07 15:50       ` Jan Kara
2014-04-23 14:00 ` [patch 12/29] reiserfs: balance_leaf refactor, reformat balance_leaf comments Jeff Mahoney
2014-04-23 14:00 ` [patch 13/29] reiserfs: balance_leaf refactor, move state variables into tree_balance Jeff Mahoney
2014-04-23 14:00 ` [patch 14/29] reiserfs: balance_leaf refactor, pull out balance_leaf_insert_left Jeff Mahoney
2014-04-23 14:00 ` [patch 15/29] reiserfs: balance_leaf refactor, pull out balance_leaf_paste_left Jeff Mahoney
2014-04-23 14:00 ` [patch 16/29] reiserfs: balance_leaf refactor, pull out balance_leaf_insert_right Jeff Mahoney
2014-04-23 14:00 ` [patch 17/29] reiserfs: balance_leaf refactor, pull out balance_leaf_paste_right Jeff Mahoney
2014-04-23 14:00 ` [patch 18/29] reiserfs: balance_leaf refactor, pull out balance_leaf_new_nodes_insert Jeff Mahoney
2014-04-23 14:00 ` [patch 19/29] reiserfs: balance_leaf refactor, pull out balance_leaf_new_nodes_paste Jeff Mahoney
2014-04-23 14:00 ` [patch 20/29] reiserfs: balance_leaf refactor pull out balance_leaf_finish_node_insert Jeff Mahoney
2014-04-23 14:00 ` [patch 21/29] reiserfs: balance_leaf refactor, pull out balance_leaf_finish_node_paste Jeff Mahoney
2014-04-23 14:00 ` Jeff Mahoney [this message]
2014-04-23 14:00 ` [patch 23/29] reiserfs: balance_leaf refactor, format balance_leaf_insert_left Jeff Mahoney
2014-04-23 14:00 ` [patch 24/29] reiserfs: balance_leaf refactor, format balance_leaf_paste_left Jeff Mahoney
2014-04-23 14:00 ` [patch 25/29] reiserfs: balance_leaf refactor, format balance_leaf_insert_right Jeff Mahoney
2014-04-23 14:00 ` [patch 26/29] reiserfs: balance_leaf refactor, format balance_leaf_paste_right Jeff Mahoney
2014-04-23 14:01 ` [patch 27/29] reiserfs: balance_leaf refactor, format balance_leaf_new_nodes_paste Jeff Mahoney
2014-04-23 14:01 ` [patch 28/29] reiserfs: balance_leaf refactor, format balance_leaf_finish_node Jeff Mahoney
2014-04-23 14:01 ` [patch 29/29] reiserfs: balance_leaf refactor, split up balance_leaf_when_delete Jeff Mahoney
2014-04-26  3:46 ` [patch 00/29] reiserfs cleanup patchset doiggl
2014-04-26 15:14   ` Jeff Mahoney
2014-05-16 10:47     ` doiggl
2014-05-22  8:24       ` doiggl
2014-05-22 13:51         ` Jeff Mahoney
2014-05-26  4:12           ` doiggl
2014-05-26 18:24             ` Jeff Mahoney
2014-06-12 14:31           ` doiggl
2014-06-12 14:38             ` Jeff Mahoney
2014-06-13  4:20               ` doiggl
2014-06-13  4:25                 ` Jeff Mahoney
2014-06-13 15:09                   ` Jeff Mahoney
2014-05-13 14:13 ` Jan Kara
2014-05-13 14:15   ` Jeff Mahoney
2014-05-27  9:23 ` doiggl
2014-05-27 12:36   ` Jeff Mahoney
2014-06-05  3:21     ` Jose R R
     [not found]       ` <47aabceb9575031270f0940059da157c@mail.velocitynet.com.au>
2014-06-26 14:27         ` [patch 00/29] reiserfs cleanup patchset - 03/29 attached [reiserfs: cleanup, reformat comments to normal kernel style] Jose R R

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140423151144.448716989@suse.com \
    --to=jeffm@suse.com \
    --cc=davej@redhat.com \
    --cc=jack@suse.cz \
    --cc=reiserfs-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.