All of lore.kernel.org
 help / color / mirror / Atom feed
From: jeffm@suse.com
To: ReiserFS Mailing List <reiserfs-devel@vger.kernel.org>
Subject: [patch 36/40] reiserfs: split out current node handling from balance_leaf
Date: Mon, 11 Jun 2007 15:03:45 -0400	[thread overview]
Message-ID: <20070611190633.390001807@suse.com> (raw)
In-Reply-To: 20070611190309.532091171@suse.com

[-- Attachment #1: reiserfs-split-balance_leaf-remainder.diff --]
[-- Type: text/plain, Size: 9950 bytes --]

 This is the last in a set of 4 patches that split balance_leaf up into
 a group of functions rather than the 2500 beast it once was.

 This patch splits off the current node balancing behavior.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>

---
 fs/reiserfs/do_balan.c |  273 +++++++++++++++++++++++++------------------------
 1 file changed, 142 insertions(+), 131 deletions(-)

--- a/fs/reiserfs/do_balan.c	2007-06-11 14:49:42.000000000 -0400
+++ b/fs/reiserfs/do_balan.c	2007-06-11 14:50:00.000000000 -0400
@@ -1210,6 +1210,146 @@ bl_new_nodes(struct tree_balance *tb, st
 	}
 }
 
+/* insert item into S[0] */
+static void
+bl_current_node_insert(struct tree_balance *tb, struct item_head *ih,
+                           const char *body, int flag, int zeros_num,
+                           int item_pos)
+{
+	struct buffer_info bi;
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	buffer_info_init_tbS0(tb, &bi);
+	leaf_insert_into_buf(&bi, item_pos, ih, body, zeros_num);
+
+	/* If we insert the first key change the delimiting key */
+	/* CFL[0] can be 0 in reiserfsck */
+	if (item_pos == 0 && tb->CFL[0])
+		replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0, 0);
+}
+
+static void
+bl_current_node_paste_de_partial(struct tree_balance *tb,
+                                     struct item_head *ih, const char *body,
+                                     int flag, int zeros_num, int item_pos,
+                                     int pos_in_item)
+{
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	struct item_head *pasted = B_N_PITEM_HEAD(tbS0, item_pos);
+	struct buffer_info bi;
+
+	if (pos_in_item < 0 || pos_in_item > ih_entry_count(pasted))
+		return;
+
+	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, item_pos, pos_in_item, tb->insert_size[0],
+	                     body, zeros_num);
+
+	/* paste entry */
+	leaf_paste_entries(bi.bi_bh, item_pos, pos_in_item, 1,
+			   (struct reiserfs_de_head *)body, body + DEH_SIZE,
+			   tb->insert_size[0]);
+
+	if (!item_pos && !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;
+}
+
+static void
+bl_current_node_paste_non_de_partial(struct tree_balance *tb,
+                                         struct item_head *ih,
+                                         const char *body, int flag,
+                                         int zeros_num, int item_pos,
+                                         int pos_in_item)
+{
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	struct item_head *pasted = B_N_PITEM_HEAD(tbS0, item_pos);
+	struct buffer_info bi;
+
+#ifdef CONFIG_REISERFS_CHECK
+	if (pos_in_item != ih_item_len(pasted)) {
+		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]);
+		}
+		return;
+	}
+#endif
+	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, item_pos, pos_in_item, tb->insert_size[0],
+	                     body, zeros_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;
+}
+
+static void
+bl_current_node_paste(struct tree_balance *tb, struct item_head *ih,
+                          const char *body, int flag, int zeros_num,
+                          int item_pos, int pos_in_item)
+{
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	struct item_head *pasted = B_N_PITEM_HEAD(tbS0, item_pos);
+	/* when directory, may be new entry already pasted */
+	if (is_direntry_le_ih(pasted))
+		bl_current_node_paste_de_partial(tb, ih, body, flag,
+		                                     zeros_num, item_pos,
+		                                     pos_in_item);
+	else
+		bl_current_node_paste_non_de_partial(tb, ih, body, flag,
+		                                         zeros_num, item_pos,
+		                                         pos_in_item);
+#ifdef CONFIG_REISERFS_CHECK
+	if (tb->insert_size[0]) {
+		print_cur_tb("12290");
+		reiserfs_panic(tb->tb_sb,
+		               "PAP-12290", "insert_size is still not 0 (%d)",
+		               tb->insert_size[0]);
+	}
+#endif				/* CONFIG_REISERFS_CHECK */
+}
+
+/* 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
+bl_current_node(struct tree_balance *tb, struct item_head *ih,
+		   const char *body, int flag, int zeros_num, int item_pos,
+		   int pos_in_item)
+{
+	BUG_ON(flag != M_INSERT && flag != M_PASTE);
+
+	/* if we must insert or append into buffer S[0] */
+	if (item_pos < 0 || item_pos >= tb->s0num)
+		return;
+
+	if (flag == M_INSERT)
+		bl_current_node_insert(tb, ih, body, flag, zeros_num,
+		                           item_pos);
+	else
+		bl_current_node_paste(tb, ih, body, flag, zeros_num,
+		                          item_pos, pos_in_item);
+}
+
+
 static int balance_leaf(struct tree_balance *tb, struct item_head *ih,	/* item header of inserted item (this is on little endian) */
 			const char *body,	/* body  of inserted item or bytes to paste */
 			int flag,	/* i - insert, d - delete, c - cut, p - paste
@@ -1224,7 +1364,6 @@ static int balance_leaf(struct tree_bala
 	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
 	int item_pos = PATH_LAST_POSITION(tb->tb_path);	/*  index into the array of item headers in S[0]
 							   of the affected item */
-	struct buffer_info bi;
 	int pos_in_item;
 	int zeros_num;
 
@@ -1290,137 +1429,9 @@ static int balance_leaf(struct tree_bala
 	bl_new_nodes(tb, ih, body, flag, insert_key, insert_ptr,
 	                       &zeros_num, item_pos, &pos_in_item);
 
-	/* 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 <= item_pos && item_pos < tb->s0num) {	/* if we must insert or append into buffer S[0] */
-
-		switch (flag) {
-		case M_INSERT:	/* insert item into S[0] */
-			buffer_info_init_tbS0(tb, &bi);
-			leaf_insert_into_buf(&bi, item_pos, ih, body,
-					     zeros_num);
-
-			/* If we insert the first key change the delimiting key */
-			if (item_pos == 0) {
-				if (tb->CFL[0])	/* can be 0 in reiserfsck */
-					replace_key(tb, tb->CFL[0], tb->lkey[0],
-						    tbS0, 0);
-
-			}
-			break;
+	bl_current_node(tb, ih, body, flag, zeros_num, item_pos,
+		          pos_in_item);
 
-		case M_PASTE:{	/* append item in S[0] */
-				struct item_head *pasted;
-
-				pasted = B_N_PITEM_HEAD(tbS0, item_pos);
-				/* when directory, may be new entry already pasted */
-				if (is_direntry_le_ih(pasted)) {
-					if (pos_in_item >= 0 &&
-					    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,
-								     item_pos,
-								     pos_in_item,
-								     tb->
-								     insert_size
-								     [0], body,
-								     zeros_num);
-
-						/* paste entry */
-						leaf_paste_entries(bi.bi_bh,
-								   item_pos,
-								   pos_in_item,
-								   1,
-								   (struct
-								    reiserfs_de_head
-								    *)body,
-								   body +
-								   DEH_SIZE,
-								   tb->
-								   insert_size
-								   [0]
-						    );
-						if (!item_pos && !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 (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,
-								     item_pos,
-								     pos_in_item,
-								     tb->
-								     insert_size
-								     [0], body,
-								     zeros_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: */
-		}
-	}
-#ifdef CONFIG_REISERFS_CHECK
-	if (flag == M_PASTE && tb->insert_size[0]) {
-		print_cur_tb("12290");
-		reiserfs_panic(tb->tb_sb,
-		               "PAP-12290", "insert_size is still not 0 (%d)",
-		               tb->insert_size[0]);
-	}
-#endif				/* CONFIG_REISERFS_CHECK */
 	return 0;
 }				/* Leaf level of the tree is balanced (end of balance_leaf) */
 

-- 
Jeff Mahoney
SUSE Labs


  parent reply	other threads:[~2007-06-11 19:03 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-11 19:03 [patch 00/40] reiserfs: patch queue (v2) jeffm
2007-06-11 19:03 ` [patch 01/40] reiserfs: fix up lockdep warnings jeffm
2007-06-11 19:03 ` [patch 02/40] reiserfs: dont use BUG when panicking jeffm
2007-06-11 19:03 ` [patch 03/40] reiserfs: use is_reusable to catch corruption jeffm
2007-06-13 15:54   ` Jeff Mahoney
2007-06-11 19:03 ` [patch 04/40] reiserfs: make bitmap use cached first zero bit jeffm
2007-06-11 19:03 ` [patch 05/40] reiserfs: use more consistent printk formatting jeffm
2007-06-11 19:03 ` [patch 06/40] reiserfs: make some warnings informational jeffm
2007-06-11 19:03 ` [patch 07/40] reiserfs: rework reiserfs_warning jeffm
2007-06-11 19:03 ` [patch 08/40] reiserfs: rework reiserfs_panic jeffm
2007-06-11 19:03 ` [patch 09/40] reiserfs: rearrange journal abort jeffm
2007-06-11 19:03 ` [patch 10/40] reiserfs: introduce reiserfs_error() jeffm
2007-06-11 19:03 ` [patch 11/40] reiserfs: use reiserfs_error() jeffm
2007-06-11 19:03 ` [patch 12/40] reiserfs: simplify xattr internal file lookups/opens jeffm
2007-06-11 19:03 ` [patch 13/40] reiserfs: eliminate per-super xattr lock jeffm
2007-06-11 19:03 ` [patch 14/40] reiserfs: make per-inode xattr locking more fine grained jeffm
2007-06-11 19:03 ` [patch 15/40] reiserfs: remove i_has_xattr_dir jeffm
2007-06-11 19:03 ` [patch 16/40] reiserfs: remove link detection code jeffm
2007-06-11 19:03 ` [patch 17/40] reiserfs: use generic xattr handlers jeffm
2007-06-11 19:03 ` [patch 18/40] reiserfs: use better open options for internal files jeffm
2007-06-11 19:03 ` [patch 19/40] reiserfs: add per-file data=ordered mode and use it for xattrs jeffm
2007-06-11 19:03 ` [patch 20/40] reiserfs: journaled xattrs jeffm
2007-06-11 19:03 ` [patch 21/40] reiserfs: use generic readdir for operations across all xattrs jeffm
2007-06-11 19:03 ` [patch 22/40] reiserfs: add atomic addition of selinux attributes during inode creation jeffm
2007-06-11 19:03 ` [patch 23/40] reiserfs: cleanup path functions jeffm
2007-06-11 19:03 ` [patch 24/40] reiserfs: strip trailing whitespace jeffm
2007-06-11 19:03 ` [patch 26/40] reiserfs: rename p_s_bh to bh jeffm
2007-06-11 19:03 ` [patch 27/40] reiserfs: rename p_s_inode to inode jeffm
2007-06-11 19:03 ` [patch 28/40] reiserfs: rename p_s_tb to tb jeffm
2007-06-11 19:03 ` [patch 29/40] reiserfs: rename p_._ variables jeffm
2007-06-11 19:03 ` [patch 30/40] reiserfs: rename _* variables jeffm
2007-06-11 19:03 ` [patch 31/40] reiserfs: factor out buffer_info initialization jeffm
2007-06-11 19:03 ` [patch 32/40] reiserfs: Turn tb->snum and tb->sbytes into an array jeffm
2007-06-11 19:03 ` [patch 33/40] reiserfs: split left balancing part of balance_leaf() off jeffm
2007-06-11 19:03 ` [patch 34/40] reiserfs: split right " jeffm
2007-06-11 19:03 ` [patch 35/40] reiserfs: split balance_leaf new node handling out jeffm
2007-06-11 19:03 ` jeffm [this message]
2007-06-11 19:03 ` [patch 37/40] reiserfs: clean up bl_when_delete jeffm
2007-06-11 19:03 ` [patch 38/40] reiserfs: clean up balancing modes jeffm
2007-06-11 19:03 ` [patch 39/40] reiserfs: split bl_when_delete jeffm
2007-06-11 19:03 ` [patch 40/40] reiserfs: reorganize do_balan.c comments jeffm
2007-06-11 19:20 ` [patch 00/40] reiserfs: patch queue (v2) Jeff Mahoney
2007-06-14 19:41 ` Jeff Mahoney

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=20070611190633.390001807@suse.com \
    --to=jeffm@suse.com \
    --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.