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 39/40] reiserfs: split bl_when_delete
Date: Mon, 11 Jun 2007 15:03:48 -0400	[thread overview]
Message-ID: <20070611190633.737727733@suse.com> (raw)
In-Reply-To: 20070611190309.532091171@suse.com

[-- Attachment #1: reiserfs-balance_leaf_when_cut_or_delete.diff --]
[-- Type: text/plain, Size: 8601 bytes --]

 This patch splits bl_when_delete into two functions so that
 it is more easily readable.

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

---
 fs/reiserfs/do_balan.c |  147 +++++++++++++++++++++++++------------------------
 1 file changed, 77 insertions(+), 70 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:49:59.000000000 -0400
@@ -9,7 +9,7 @@
 /* and using buffers obtained after all above.				*/
 
 /**
- ** balance_leaf_when_delete
+ ** bl_when_delete
  ** balance_leaf
  ** do_balance
  **
@@ -78,7 +78,7 @@ inline void do_balance_mark_leaf_dirty(s
 
 /* summary:
  if deleting something ( tb->insert_size[0] < 0 )
-   return(balance_leaf_when_delete()); (flag d handled here)
+   return(bl_when_delete()); (flag d handled here)
  else
    if lnum is larger than 0 we put items into the left node
    if rnum is larger than 0 we put items into the right node
@@ -88,7 +88,7 @@ Note that all *num* count new items bein
 
 It would be easier to read balance_leaf() if each of these summary
 lines was a separate procedure rather than being inlined.  I think
-that there are many passages here and in balance_leaf_when_delete() in
+that there are many passages here and in bl_when_delete() in
 which two calls to one procedure can replace two passages, and it
 might save cache space and improve software maintenance costs to do so.
 
@@ -99,6 +99,54 @@ be performed by do_balance.
 
 -Hans */
 
+/* L[0] must be joined with S[0] */
+static int bl_delete_merge_left(struct tree_balance *tb)
+{
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	int n = B_NR_ITEMS(tbS0);
+
+	/* R[0] must be also joined with S[0] */
+	if (tb->rnum[0] == -1) {
+		if (tb->FR[0] == PATH_H_PPARENT(tb->tb_path, 0)) {
+			/* all contents of all the 3 buffers will be in L[0] */
+			if (PATH_H_POSITION(tb->tb_path, 1) == 0 &&
+		            B_NR_ITEMS(tb->FR[0]) > 1)
+				replace_key(tb, tb->CFL[0], tb->lkey[0],
+					    tb->FR[0], 1);
+
+			leaf_move_items(LEAF_FROM_S_TO_L, tb, n, -1, NULL);
+			leaf_move_items(LEAF_FROM_R_TO_L, tb,
+					B_NR_ITEMS(tb->R[0]), -1, NULL);
+
+			reiserfs_invalidate_buffer(tb, tbS0);
+			reiserfs_invalidate_buffer(tb, tb->R[0]);
+
+			return 0;
+		}
+		/* all contents of all the 3 buffers will be in R[0] */
+		leaf_move_items(LEAF_FROM_S_TO_R, tb, n, -1, NULL);
+		leaf_move_items(LEAF_FROM_L_TO_R, tb, B_NR_ITEMS(tb->L[0]),
+		                -1, NULL);
+
+		/* right_delimiting_key is correct in R[0] */
+		replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0);
+
+		reiserfs_invalidate_buffer(tb, tbS0);
+		reiserfs_invalidate_buffer(tb, tb->L[0]);
+
+		return -1;
+	}
+
+	RFALSE(tb->rnum[0] != 0,
+	       "PAP-12045: rnum must be 0 (%d)", tb->rnum[0]);
+
+	/* all contents of L[0] and S[0] will be in L[0] */
+	leaf_shift_left(tb, n, -1);
+	reiserfs_invalidate_buffer(tb, tbS0);
+	return 0;
+
+}
+
 /* Balance leaf node in case of delete or cut: insert_size[0] < 0
  *
  * lnum, rnum can have values >= -1
@@ -106,14 +154,13 @@ be performed by do_balance.
  *	 0 means that nothing should be done with the neighbor
  *	>0 means to shift entirely or partly the specified number of items to the neighbor
  */
-static int balance_leaf_when_delete(struct tree_balance *tb, int flag)
+static int bl_when_delete(struct tree_balance *tb, int flag)
 {
-	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
 	int item_pos = PATH_LAST_POSITION(tb->tb_path);
-	int pos_in_item = tb->tb_path->pos_in_item;
+	int n, pos_in_item = tb->tb_path->pos_in_item;
+	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+	struct item_head *ih = B_N_PITEM_HEAD(tbS0, item_pos);
 	struct buffer_info bi;
-	int n;
-	struct item_head *ih;
 
 	if (flag != M_DELETE && flag != M_CUT) {
 		print_cur_tb("12040");
@@ -129,22 +176,20 @@ static int balance_leaf_when_delete(stru
 	RFALSE(!tb->blknum[0] && !PATH_H_PPARENT(tb->tb_path, 0),
 	       "PAP-12010: tree can not be empty");
 
-	ih = B_N_PITEM_HEAD(tbS0, item_pos);
 	buffer_info_init_tbS0(tb, &bi);
 
 	/* Delete or truncate the item */
-
 	if (flag == M_DELETE) {
 		RFALSE(ih_item_len(ih) + IH_SIZE != -tb->insert_size[0],
-		       "vs-12013: mode Delete, insert size %d, ih to be deleted %h",
-		       -tb->insert_size[0], ih);
+		       "vs-12013: mode Delete, insert size %d, "
+		       "ih to be deleted %h", -tb->insert_size[0], ih);
 
 		leaf_delete_items(&bi, 0, item_pos, 1, -1);
 
 		if (!item_pos && tb->CFL[0]) {
 			if (B_NR_ITEMS(tbS0)) {
-				replace_key(tb, tb->CFL[0], tb->lkey[0], tbS0,
-					    0);
+				replace_key(tb, tb->CFL[0], tb->lkey[0],
+				            tbS0, 0);
 			} else {
 				if (!PATH_H_POSITION(tb->tb_path, 1))
 					replace_key(tb, tb->CFL[0], tb->lkey[0],
@@ -170,8 +215,8 @@ static int balance_leaf_when_delete(stru
 					     -tb->insert_size[0]);
 
 			RFALSE(!item_pos && !pos_in_item && !tb->CFL[0],
-			       "PAP-12030: can not change delimiting key. CFL[0]=%p",
-			       tb->CFL[0]);
+			       "PAP-12030: can not change delimiting key. "
+			       "CFL[0]=%p", tb->CFL[0]);
 
 			if (!item_pos && !pos_in_item && tb->CFL[0]) {
 				replace_key(tb, tb->CFL[0], tb->lkey[0],
@@ -186,69 +231,31 @@ static int balance_leaf_when_delete(stru
 		}
 	}
 
-	/* the rule is that no shifting occurs unless by shifting a node can be freed */
+	/* the rule is that no shifting occurs unless by
+	 * shifting a node can be freed */
 	n = B_NR_ITEMS(tbS0);
-	if (tb->lnum[0]) {	/* L[0] takes part in balancing */
-		if (tb->lnum[0] == -1) {	/* L[0] must be joined with S[0] */
-			if (tb->rnum[0] == -1) {	/* R[0] must be also joined with S[0] */
-				if (tb->FR[0] == PATH_H_PPARENT(tb->tb_path, 0)) {
-					/* all contents of all the 3 buffers will be in L[0] */
-					if (PATH_H_POSITION(tb->tb_path, 1) == 0
-					    && 1 < B_NR_ITEMS(tb->FR[0]))
-						replace_key(tb, tb->CFL[0],
-							    tb->lkey[0],
-							    tb->FR[0], 1);
-
-					leaf_move_items(LEAF_FROM_S_TO_L, tb, n,
-							-1, NULL);
-					leaf_move_items(LEAF_FROM_R_TO_L, tb,
-							B_NR_ITEMS(tb->R[0]),
-							-1, NULL);
-
-					reiserfs_invalidate_buffer(tb, tbS0);
-					reiserfs_invalidate_buffer(tb,
-								   tb->R[0]);
-
-					return 0;
-				}
-				/* all contents of all the 3 buffers will be in R[0] */
-				leaf_move_items(LEAF_FROM_S_TO_R, tb, n, -1,
-						NULL);
-				leaf_move_items(LEAF_FROM_L_TO_R, tb,
-						B_NR_ITEMS(tb->L[0]), -1, NULL);
-
-				/* right_delimiting_key is correct in R[0] */
-				replace_key(tb, tb->CFR[0], tb->rkey[0],
-					    tb->R[0], 0);
-
-				reiserfs_invalidate_buffer(tb, tbS0);
-				reiserfs_invalidate_buffer(tb, tb->L[0]);
-
-				return -1;
-			}
-
-			RFALSE(tb->rnum[0] != 0,
-			       "PAP-12045: rnum must be 0 (%d)", tb->rnum[0]);
-			/* all contents of L[0] and S[0] will be in L[0] */
-			leaf_shift_left(tb, n, -1);
-
-			reiserfs_invalidate_buffer(tb, tbS0);
-
-			return 0;
-		}
-		/* a part of contents of S[0] will be in L[0] and the rest part of S[0] will be in R[0] */
+	/* L[0] takes part in balancing */
+	if (tb->lnum[0]) {
+		/* L[0] must be joined with S[0] */
+		if (tb->lnum[0] == -1)
+			return bl_delete_merge_left(tb);
 
+		/* a part of contents of S[0] will be in L[0] and
+		 * the rest part of S[0] will be in R[0] */
 		RFALSE((tb->lnum[0] + tb->rnum[0] < n) ||
 		       (tb->lnum[0] + tb->rnum[0] > n + 1),
-		       "PAP-12050: rnum(%d) and lnum(%d) and item number(%d) in S[0] are not consistent",
+		       "PAP-12050: rnum(%d) and lnum(%d) and "
+		       "item number(%d) in S[0] are not consistent",
 		       tb->rnum[0], tb->lnum[0], n);
 		RFALSE((tb->lnum[0] + tb->rnum[0] == n) &&
 		       (tb->lbytes != -1 || tb->rbytes != -1),
-		       "PAP-12055: bad rbytes (%d)/lbytes (%d) parameters when items are not split",
+		       "PAP-12055: bad rbytes (%d)/lbytes (%d) "
+		       "parameters when items are not split",
 		       tb->rbytes, tb->lbytes);
 		RFALSE((tb->lnum[0] + tb->rnum[0] == n + 1) &&
 		       (tb->lbytes < 1 || tb->rbytes != -1),
-		       "PAP-12060: bad rbytes (%d)/lbytes (%d) parameters when items are split",
+		       "PAP-12060: bad rbytes (%d)/lbytes (%d) "
+		       "parameters when items are split",
 		       tb->rbytes, tb->lbytes);
 
 		leaf_shift_left(tb, tb->lnum[0], tb->lbytes);
@@ -1366,7 +1373,7 @@ static int balance_leaf(struct tree_bala
 
 	/* Make balance in case insert_size[0] < 0 */
 	if (tb->insert_size[0] < 0)
-		return balance_leaf_when_delete(tb, flag);
+		return bl_when_delete(tb, flag);
 
 	zeros_num = 0;
 	if (flag == M_INSERT && body == 0)

-- 
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 ` [patch 36/40] reiserfs: split out current node handling from balance_leaf jeffm
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 ` jeffm [this message]
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.737727733@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.