Commit 97fd4b97 authored by Jeff Mahoney's avatar Jeff Mahoney Committed by Jan Kara
Browse files

reiserfs: balance_leaf refactor, reformat balance_leaf comments



The comments in balance_leaf are as bad as the code. This patch shifts
them around to fit in 80 columns and be easier to read.

Signed-off-by: default avatarJeff Mahoney <jeffm@suse.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent c48138c2
Loading
Loading
Loading
Loading
+52 −32
Original line number Original line Diff line number Diff line
@@ -290,31 +290,43 @@ static int balance_leaf_when_delete(struct tree_balance *tb, int flag)
	return 0;
	return 0;
}
}


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 */
 * balance_leaf - reiserfs tree balancing algorithm
			int flag,	/* i - insert, d - delete, c - cut, p - paste
 * @tb: tree balance state
					   (see comment to do_balance) */
 * @ih: item header of inserted item (little endian)
			struct item_head *insert_key,	/* in our processing of one level we sometimes determine what
 * @body: body of inserted item or bytes to paste
							   must be inserted into the next higher level.  This insertion
 * @flag: i - insert, d - delete, c - cut, p - paste (see do_balance)
							   consists of a key or two keys and their corresponding
 * passed back:
							   pointers */
 * @insert_key: key to insert new nodes
			struct buffer_head **insert_ptr	/* inserted node-ptrs for the next level */
 * @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_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]
	/* index into the array of item headers in S[0] of the affected item */
							   of the affected item */
	int item_pos = PATH_LAST_POSITION(tb->tb_path);
	struct buffer_info bi;
	struct buffer_info bi;
	struct buffer_head *S_new[2];	/* new nodes allocated to hold what could not fit into S */
	/* new nodes allocated to hold what could not fit into S */
	int snum[2];		/* number of items that will be placed
	struct buffer_head *S_new[2];
				   into S_new (includes partially shifted
	/*
				   items) */
	 * number of items that will be placed into S_new
	int sbytes[2];		/* if an item is partially shifted into S_new then
	 * (includes partially shifted items)
				   if it is a directory item
	 */
				   it is the number of entries from the item that are shifted into S_new
	int snum[2];
				   else
	/*
				   it is the number of bytes from the item that are shifted into S_new
	 * if an item is partially shifted into S_new then if it is a
	 * directory item it is the number of entries from the item that
	 * are shifted into S_new else it is the number of bytes from
	 * the item that are shifted into S_new
	 */
	 */
	int sbytes[2];
	int n, i;
	int n, i;
	int ret_val;
	int ret_val;
	int pos_in_item;
	int pos_in_item;
@@ -331,8 +343,10 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
		zeros_num = ih_item_len(ih);
		zeros_num = ih_item_len(ih);


	pos_in_item = tb->tb_path->pos_in_item;
	pos_in_item = tb->tb_path->pos_in_item;
	/* for indirect item pos_in_item is measured in unformatted node
	/*
	   pointers. Recalculate to bytes */
	 * for indirect item pos_in_item is measured in unformatted node
	 * pointers. Recalculate to bytes
	 */
	if (flag != M_INSERT
	if (flag != M_INSERT
	    && is_indirect_le_ih(item_head(tbS0, item_pos)))
	    && is_indirect_le_ih(item_head(tbS0, item_pos)))
		pos_in_item *= UNFM_P_SIZE;
		pos_in_item *= UNFM_P_SIZE;
@@ -792,16 +806,20 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
	RFALSE(tb->blknum[0] < 0,
	RFALSE(tb->blknum[0] < 0,
	       "PAP-12185: blknum can not be %d. It must be >= 0", tb->blknum[0]);
	       "PAP-12185: blknum can not be %d. It must be >= 0", tb->blknum[0]);


	/* if while adding to a node we discover that it is possible to split
	/*
	   it in two, and merge the left part into the left neighbor and the
	 * if while adding to a node we discover that it is possible to split
	   right part into the right neighbor, eliminating the node */
	 * it in two, and merge the left part into the left neighbor and the
	 * right part into the right neighbor, eliminating the node
	 */
	if (tb->blknum[0] == 0) {	/* node S[0] is empty now */
	if (tb->blknum[0] == 0) {	/* node S[0] is empty now */


		RFALSE(!tb->lnum[0] || !tb->rnum[0],
		RFALSE(!tb->lnum[0] || !tb->rnum[0],
		       "PAP-12190: lnum and rnum must not be zero");
		       "PAP-12190: lnum and rnum must not be zero");
		/* if insertion was done before 0-th position in R[0], right
		/*
		   delimiting key of the tb->L[0]'s and left delimiting key are
		 * if insertion was done before 0-th position in R[0], right
		   not set correctly */
		 * delimiting key of the tb->L[0]'s and left delimiting key are
		 * not set correctly
		 */
		if (tb->CFL[0]) {
		if (tb->CFL[0]) {
			if (!tb->CFR[0])
			if (!tb->CFR[0])
				reiserfs_panic(tb->tb_sb, "vs-12195",
				reiserfs_panic(tb->tb_sb, "vs-12195",
@@ -1159,9 +1177,11 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
			       "PAP-12290", "insert_size is still not 0 (%d)",
			       "PAP-12290", "insert_size is still not 0 (%d)",
			       tb->insert_size[0]);
			       tb->insert_size[0]);
	}
	}
#endif				/* CONFIG_REISERFS_CHECK */
#endif

	/* Leaf level of the tree is balanced (end of balance_leaf) */
	return 0;
	return 0;
}				/* Leaf level of the tree is balanced (end of balance_leaf) */
}


/* Make empty node */
/* Make empty node */
void make_empty_node(struct buffer_info *bi)
void make_empty_node(struct buffer_info *bi)