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 26/29] reiserfs: balance_leaf refactor, format balance_leaf_paste_right
Date: Wed, 23 Apr 2014 10:00:59 -0400 [thread overview]
Message-ID: <20140423151150.962658899@suse.com> (raw)
In-Reply-To: 20140423140033.704113918@suse.com
[-- Attachment #1: reiserfs/reiserfs-balance_leaf-refactor-format-balance_leaf_paste_right --]
[-- Type: text/plain, Size: 12570 bytes --]
Break up balance_leaf_paste_right into:
balance_leaf_paste_right_shift
balance_leaf_paste_right_shift_dirent
balance_leaf_paste_right_whole
and keep balance_leaf_paste_right as a handler to select which is appropriate.
Also reformat to adhere to CodingStyle.
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
fs/reiserfs/do_balan.c | 300 +++++++++++++++++++++++++++----------------------
1 file changed, 170 insertions(+), 130 deletions(-)
--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -706,155 +706,197 @@ static void balance_leaf_insert_right(st
}
}
-static void balance_leaf_paste_right(struct tree_balance *tb,
+
+static void balance_leaf_paste_right_shift_dirent(struct tree_balance *tb,
struct item_head *ih, const char *body)
{
struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
- int n = B_NR_ITEMS(tbS0);
struct buffer_info bi;
- int ret_val;
-
- if (n - tb->rnum[0] <= tb->item_pos) { /* pasted item or part of it falls to R[0] */
- if (tb->item_pos == n - tb->rnum[0] && tb->rbytes != -1) { /* we must shift the part of the appended item */
- if (is_direntry_le_ih(item_head(tbS0, tb->item_pos))) { /* we append to directory item */
- int entry_count;
-
- RFALSE(tb->zeroes_num,
- "PAP-12145: invalid parameter in case of a directory");
- entry_count = ih_entry_count(item_head
- (tbS0, tb->item_pos));
- if (entry_count - tb->rbytes <
- tb->pos_in_item)
- /* new directory entry falls into R[0] */
- {
- int paste_entry_position;
-
- RFALSE(tb->rbytes - 1 >= entry_count || !tb-> insert_size[0],
- "PAP-12150: no enough of entries to shift to R[0]: rbytes=%d, entry_count=%d",
- tb->rbytes, entry_count);
- /* Shift rnum[0]-1 items in whole. Shift rbytes-1 directory entries from directory item number rnum[0] */
- leaf_shift_right(tb, tb->rnum[0], tb->rbytes - 1);
- /* Paste given directory entry to directory item */
- paste_entry_position = tb->pos_in_item - entry_count + tb->rbytes - 1;
- buffer_info_init_right(tb, &bi);
- leaf_paste_in_buffer(&bi, 0, paste_entry_position, tb->insert_size[0], body, tb->zeroes_num);
- /* paste entry */
- leaf_paste_entries(&bi, 0, paste_entry_position, 1,
- (struct reiserfs_de_head *) body,
- body + DEH_SIZE, tb->insert_size[0]);
+ int entry_count;
- if (paste_entry_position == 0) {
- /* change delimiting keys */
- replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0],0);
- }
-
- tb->insert_size[0] = 0;
- tb->pos_in_item++;
- } else { /* new directory entry doesn't fall into R[0] */
+ RFALSE(zeroes_num,
+ "PAP-12145: invalid parameter in case of a directory");
+ entry_count = ih_entry_count(item_head(tbS0, tb->item_pos));
+
+ /* new directory entry falls into R[0] */
+ if (entry_count - tb->rbytes < tb->pos_in_item) {
+ int paste_entry_position;
+
+ RFALSE(tb->rbytes - 1 >= entry_count || !tb->insert_size[0],
+ "PAP-12150: no enough of entries to shift to R[0]: "
+ "rbytes=%d, entry_count=%d", tb->rbytes, entry_count);
+
+ /*
+ * Shift rnum[0]-1 items in whole.
+ * Shift rbytes-1 directory entries from directory
+ * item number rnum[0]
+ */
+ leaf_shift_right(tb, tb->rnum[0], tb->rbytes - 1);
+
+ /* Paste given directory entry to directory item */
+ paste_entry_position = tb->pos_in_item - entry_count +
+ tb->rbytes - 1;
+ buffer_info_init_right(tb, &bi);
+ leaf_paste_in_buffer(&bi, 0, paste_entry_position,
+ tb->insert_size[0], body, tb->zeroes_num);
+
+ /* paste entry */
+ leaf_paste_entries(&bi, 0, paste_entry_position, 1,
+ (struct reiserfs_de_head *) body,
+ body + DEH_SIZE, tb->insert_size[0]);
+
+ /* change delimiting keys */
+ if (paste_entry_position == 0)
+ replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0);
+
+ tb->insert_size[0] = 0;
+ tb->pos_in_item++;
+ } else {
+ /* new directory entry doesn't fall into R[0] */
+ leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
+ }
+}
- leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
- }
- } else { /* regular object */
+static void balance_leaf_paste_right_shift(struct tree_balance *tb,
+ struct item_head *ih, const char *body)
+{
+ struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+ int n_shift, n_rem, r_zeroes_number, version;
+ unsigned long temp_rem;
+ const char *r_body;
+ struct buffer_info bi;
- int n_shift, n_rem, r_zeroes_number;
- const char *r_body;
+ /* we append to directory item */
+ if (is_direntry_le_ih(item_head(tbS0, tb->item_pos))) {
+ balance_leaf_paste_right_shift_dirent(tb, ih, body);
+ return;
+ }
- /* Calculate number of bytes which must be shifted from appended item */
- if ((n_shift = tb->rbytes - tb->insert_size[0]) < 0)
- n_shift = 0;
+ /* regular object */
- RFALSE(tb->pos_in_item != ih_item_len
- (item_head(tbS0, tb->item_pos)),
- "PAP-12155: invalid position to paste. ih_item_len=%d, pos_in_item=%d",
- tb->pos_in_item, ih_item_len
- (item_head(tbS0, tb->item_pos)));
-
- leaf_shift_right(tb, tb->rnum[0], n_shift);
- /* Calculate number of bytes which must remain in body after appending to R[0] */
- if ((n_rem = tb->insert_size[0] - tb->rbytes) < 0)
- n_rem = 0;
+ /*
+ * Calculate number of bytes which must be shifted
+ * from appended item
+ */
+ n_shift = tb->rbytes - tb->insert_size[0];
+ if (n_shift < 0)
+ n_shift = 0;
+
+ RFALSE(pos_in_item != ih_item_len(item_head(tbS0, item_pos)),
+ "PAP-12155: invalid position to paste. ih_item_len=%d, "
+ "pos_in_item=%d", pos_in_item,
+ ih_item_len(item_head(tbS0, item_pos)));
+
+ leaf_shift_right(tb, tb->rnum[0], n_shift);
+
+ /*
+ * Calculate number of bytes which must remain in body
+ * after appending to R[0]
+ */
+ n_rem = tb->insert_size[0] - tb->rbytes;
+ if (n_rem < 0)
+ n_rem = 0;
+
+ temp_rem = n_rem;
+
+ version = ih_version(item_head(tb->R[0], 0));
+
+ if (is_indirect_le_key(version, leaf_key(tb->R[0], 0))) {
+ int shift = tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT;
+ temp_rem = n_rem << shift;
+ }
- {
- int version;
- unsigned long temp_rem = n_rem;
+ add_le_key_k_offset(version, leaf_key(tb->R[0], 0), temp_rem);
+ add_le_key_k_offset(version, internal_key(tb->CFR[0], tb->rkey[0]),
+ temp_rem);
+
+ do_balance_mark_internal_dirty(tb, tb->CFR[0], 0);
+
+ /* Append part of body into R[0] */
+ buffer_info_init_right(tb, &bi);
+ if (n_rem > tb->zeroes_num) {
+ r_zeroes_number = 0;
+ r_body = body + n_rem - tb->zeroes_num;
+ } else {
+ r_body = body;
+ r_zeroes_number = tb->zeroes_num - n_rem;
+ tb->zeroes_num -= r_zeroes_number;
+ }
- version = ih_version(item_head(tb->R[0], 0));
- if (is_indirect_le_key(version, leaf_key(tb->R[0], 0))) {
- temp_rem = n_rem << (tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT);
- }
- set_le_key_k_offset(version, leaf_key(tb->R[0], 0),
- le_key_k_offset(version, leaf_key(tb->R[0], 0)) + temp_rem);
- set_le_key_k_offset(version, internal_key(tb->CFR[0], tb->rkey[0]),
- le_key_k_offset(version, internal_key(tb->CFR[0], tb->rkey[0])) + temp_rem);
- }
-/* k_offset (leaf_key(tb->R[0],0)) += n_rem;
- k_offset (internal_key(tb->CFR[0],tb->rkey[0])) += n_rem;*/
- do_balance_mark_internal_dirty(tb, tb->CFR[0], 0);
+ leaf_paste_in_buffer(&bi, 0, n_shift, tb->insert_size[0] - n_rem,
+ r_body, r_zeroes_number);
- /* Append part of body into R[0] */
- buffer_info_init_right(tb, &bi);
- if (n_rem > tb->zeroes_num) {
- r_zeroes_number = 0;
- r_body = body + n_rem - tb->zeroes_num;
- } else {
- r_body = body;
- r_zeroes_number = tb->zeroes_num - n_rem;
- tb->zeroes_num -= r_zeroes_number;
- }
+ if (is_indirect_le_ih(item_head(tb->R[0], 0)))
+ set_ih_free_space(item_head(tb->R[0], 0), 0);
- leaf_paste_in_buffer(&bi, 0, n_shift,
- tb->insert_size[0] - n_rem,
- r_body, r_zeroes_number);
+ tb->insert_size[0] = n_rem;
+ if (!n_rem)
+ tb->pos_in_item++;
+}
- if (is_indirect_le_ih(item_head(tb->R[0], 0))) {
-#if 0
- RFALSE(n_rem,
- "PAP-12160: paste more than one unformatted node pointer");
-#endif
- set_ih_free_space(item_head(tb->R[0], 0), 0);
- }
- tb->insert_size[0] = n_rem;
- if (!n_rem)
- tb->pos_in_item++;
- }
- } else { /* pasted item in whole falls into R[0] */
+static void balance_leaf_paste_right_whole(struct tree_balance *tb,
+ struct item_head *ih, const char *body)
+{
+ struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+ int n = B_NR_ITEMS(tbS0);
+ struct item_head *pasted;
+ struct buffer_info bi;
- struct item_head *pasted;
+ buffer_info_init_right(tb, &bi);
+ leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
- ret_val = leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
- /* append item in R[0] */
- if (tb->pos_in_item >= 0) {
- buffer_info_init_right(tb, &bi);
- leaf_paste_in_buffer(&bi, tb->item_pos - n + tb->rnum[0], tb->pos_in_item,
- tb->insert_size[0], body, tb->zeroes_num);
- }
+ /* append item in R[0] */
+ if (tb->pos_in_item >= 0) {
+ buffer_info_init_right(tb, &bi);
+ leaf_paste_in_buffer(&bi, tb->item_pos - n + tb->rnum[0],
+ tb->pos_in_item, tb->insert_size[0], body,
+ tb->zeroes_num);
+ }
- /* paste new entry, if item is directory item */
- pasted = item_head(tb->R[0], tb->item_pos - n + tb->rnum[0]);
- if (is_direntry_le_ih(pasted) && tb->pos_in_item >= 0) {
- leaf_paste_entries(&bi, tb->item_pos - n + tb->rnum[0],
- tb->pos_in_item, 1,
- (struct reiserfs_de_head *) body,
- body + DEH_SIZE, tb->insert_size[0]);
- if (!tb->pos_in_item) {
+ /* paste new entry, if item is directory item */
+ pasted = item_head(tb->R[0], tb->item_pos - n + tb->rnum[0]);
+ if (is_direntry_le_ih(pasted) && tb->pos_in_item >= 0) {
+ leaf_paste_entries(&bi, tb->item_pos - n + tb->rnum[0],
+ tb->pos_in_item, 1,
+ (struct reiserfs_de_head *)body,
+ body + DEH_SIZE, tb->insert_size[0]);
+
+ if (!tb->pos_in_item) {
+
+ RFALSE(tb->item_pos - n + tb->rnum[0],
+ "PAP-12165: directory item must be first "
+ "item of node when pasting is in 0th position");
+
+ /* update delimiting keys */
+ replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0);
+ }
+ }
- RFALSE(tb->item_pos - n + tb->rnum[0],
- "PAP-12165: directory item must be first item of node when pasting is in 0th position");
+ if (is_indirect_le_ih(pasted))
+ set_ih_free_space(pasted, 0);
+ tb->zeroes_num = tb->insert_size[0] = 0;
+}
- /* update delimiting keys */
- replace_key(tb, tb->CFR[0], tb->rkey[0], tb->R[0], 0);
- }
- }
+static void balance_leaf_paste_right(struct tree_balance *tb,
+ struct item_head *ih, const char *body)
+{
+ struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
+ int n = B_NR_ITEMS(tbS0);
- if (is_indirect_le_ih(pasted))
- set_ih_free_space(pasted, 0);
- tb->zeroes_num = tb->insert_size[0] = 0;
- }
- } else { /* new item doesn't fall into R[0] */
+ /* new item doesn't fall into R[0] */
+ if (n - tb->rnum[0] > tb->item_pos) {
+ leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
+ return;
+ }
- leaf_shift_right(tb, tb->rnum[0], tb->rbytes);
- }
+ /* pasted item or part of it falls to R[0] */
+ if (tb->item_pos == n - tb->rnum[0] && tb->rbytes != -1)
+ /* we must shift the part of the appended item */
+ balance_leaf_paste_right_shift(tb, ih, body);
+ else
+ /* pasted item in whole falls into R[0] */
+ balance_leaf_paste_right_whole(tb, ih, body);
}
/* shift rnum[0] items from S[0] to the right neighbor R[0] */
@@ -870,7 +912,6 @@ static void balance_leaf_right(struct tr
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,
@@ -1083,8 +1124,7 @@ static void balance_leaf_new_nodes_paste
tb->pos_in_item, 1,
(struct reiserfs_de_head *)body,
body + DEH_SIZE,
- tb->insert_size[0]
- );
+ tb->insert_size[0]);
}
/* if we paste to indirect item update ih_free_space */
next prev 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 ` [patch 22/29] reiserfs: balance_leaf refactor, pull out balance_leaf{left, right, new_nodes, finish_node} Jeff Mahoney
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 ` Jeff Mahoney [this message]
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=20140423151150.962658899@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.