Commit 8dbf0d8c authored by Jeff Mahoney's avatar Jeff Mahoney Committed by Jan Kara
Browse files

reiserfs: balance_leaf refactor, format balance_leaf_insert_right



Reformat balance_leaf_insert_right to adhere to CodingStyle.

Signed-off-by: default avatarJeff Mahoney <jeffm@suse.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent 3fade937
Loading
Loading
Loading
Loading
+65 −52
Original line number Original line Diff line number Diff line
@@ -626,25 +626,42 @@ static void balance_leaf_insert_right(struct tree_balance *tb,
	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
	struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
	int n = B_NR_ITEMS(tbS0);
	int n = B_NR_ITEMS(tbS0);
	struct buffer_info bi;
	struct buffer_info bi;
	int ret_val;
	int ret;
			if (n - tb->rnum[0] < tb->item_pos) {	/* new item or its part falls to R[0] */

				if (tb->item_pos == n - tb->rnum[0] + 1 && tb->rbytes != -1) {	/* part of new item falls into R[0] */
	/* new item or part of it doesn't fall into R[0] */
	if (n - tb->rnum[0] >= tb->item_pos) {
		leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
		return;
	}

	/* new item or its part falls to R[0] */

	/* part of new item falls into R[0] */
	if (tb->item_pos == n - tb->rnum[0] + 1 && tb->rbytes != -1) {
		loff_t old_key_comp, old_len, r_zeroes_number;
		loff_t old_key_comp, old_len, r_zeroes_number;
		const char *r_body;
		const char *r_body;
					int version;
		int version, shift;
		loff_t offset;
		loff_t offset;


		leaf_shift_right(tb, tb->rnum[0] - 1, -1);
		leaf_shift_right(tb, tb->rnum[0] - 1, -1);


		version = ih_version(ih);
		version = ih_version(ih);

		/* Remember key component and item length */
		/* Remember key component and item length */
		old_key_comp = le_ih_k_offset(ih);
		old_key_comp = le_ih_k_offset(ih);
		old_len = ih_item_len(ih);
		old_len = ih_item_len(ih);


					/* Calculate key component and item length to insert into R[0] */
		/*
					offset = le_ih_k_offset(ih) + ((old_len - tb->rbytes) << (is_indirect_le_ih(ih) ? tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT : 0));
		 * Calculate key component and item length to insert
		 * into R[0]
		 */
		shift = 0;
		if (is_indirect_le_ih(ih))
			shift = tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT;
		offset = le_ih_k_offset(ih) + ((old_len - tb->rbytes) << shift);
		set_le_ih_k_offset(ih, offset);
		set_le_ih_k_offset(ih, offset);
		put_ih_item_len(ih, tb->rbytes);
		put_ih_item_len(ih, tb->rbytes);

		/* Insert part of the item into R[0] */
		/* Insert part of the item into R[0] */
		buffer_info_init_right(tb, &bi);
		buffer_info_init_right(tb, &bi);
		if ((old_len - tb->rbytes) > tb->zeroes_num) {
		if ((old_len - tb->rbytes) > tb->zeroes_num) {
@@ -652,45 +669,41 @@ static void balance_leaf_insert_right(struct tree_balance *tb,
			r_body = body + (old_len - tb->rbytes) - tb->zeroes_num;
			r_body = body + (old_len - tb->rbytes) - tb->zeroes_num;
		} else {
		} else {
			r_body = body;
			r_body = body;
						r_zeroes_number = tb->zeroes_num - (old_len - tb->rbytes);
			r_zeroes_number = tb->zeroes_num -
					  (old_len - tb->rbytes);
			tb->zeroes_num -= r_zeroes_number;
			tb->zeroes_num -= r_zeroes_number;
		}
		}


					leaf_insert_into_buf(&bi, 0, ih, r_body,
		leaf_insert_into_buf(&bi, 0, ih, r_body, r_zeroes_number);
							     r_zeroes_number);


		/* Replace right delimiting key by first key in R[0] */
		/* Replace right delimiting key by first key in R[0] */
					replace_key(tb, tb->CFR[0], tb->rkey[0],
		replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0);
						    tb->R[0], 0);


					/* Calculate key component and item length to insert into S[0] */
		/*
		 * Calculate key component and item length to
		 * insert into S[0]
		 */
		set_le_ih_k_offset(ih, old_key_comp);
		set_le_ih_k_offset(ih, old_key_comp);
		put_ih_item_len(ih, old_len - tb->rbytes);
		put_ih_item_len(ih, old_len - tb->rbytes);


		tb->insert_size[0] -= tb->rbytes;
		tb->insert_size[0] -= tb->rbytes;


				} else {	/* whole new item falls into R[0] */
	} else {
		/* whole new item falls into R[0] */


		/* Shift rnum[0]-1 items to R[0] */
		/* Shift rnum[0]-1 items to R[0] */
					ret_val = leaf_shift_right(tb, tb->rnum[0] - 1, tb->rbytes);
		ret = leaf_shift_right(tb, tb->rnum[0] - 1, tb->rbytes);

		/* Insert new item into R[0] */
		/* Insert new item into R[0] */
		buffer_info_init_right(tb, &bi);
		buffer_info_init_right(tb, &bi);
		leaf_insert_into_buf(&bi, tb->item_pos - n + tb->rnum[0] - 1,
		leaf_insert_into_buf(&bi, tb->item_pos - n + tb->rnum[0] - 1,
				     ih, body, tb->zeroes_num);
				     ih, body, tb->zeroes_num);


					if (tb->item_pos - n + tb->rnum[0] - 1 == 0) {
		if (tb->item_pos - n + tb->rnum[0] - 1 == 0)
						replace_key(tb, tb->CFR[0],
			replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0);
							    tb->rkey[0],
							    tb->R[0], 0);


					}
		tb->zeroes_num = tb->insert_size[0] = 0;
		tb->zeroes_num = tb->insert_size[0] = 0;
	}
	}
			} else {	/* new item or part of it doesn't fall into R[0] */

				leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
			}

}
}


static void balance_leaf_paste_right(struct tree_balance *tb,
static void balance_leaf_paste_right(struct tree_balance *tb,