aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2014-04-23 10:00:48 -0400
committerJan Kara <jack@suse.cz>2014-05-07 12:34:13 -0400
commitcf22df182bfce50670c25ce432e679e03aff3745 (patch)
tree547b537de06ab7a91be3d6ea7d38c91f11e2a0df /fs/reiserfs
parentf1f007c308eb95be5ebb3d9fec566f86662975be (diff)
reiserfs: balance_leaf refactor, pull out balance_leaf_paste_left
This patch factors out a new balance_leaf_paste_left from the code in balance_leaf responsible for pasting new content into an existing item located in the node to the left of S[0] in the tree. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Jan Kara <jack@suse.cz>
Diffstat (limited to 'fs/reiserfs')
-rw-r--r--fs/reiserfs/do_balan.c117
1 files changed, 64 insertions, 53 deletions
diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
index 44eb4f6ce0da..f8fab372e32c 100644
--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -348,62 +348,13 @@ static void balance_leaf_insert_left(struct tree_balance *tb,
348 348
349} 349}
350 350
351/** 351static void balance_leaf_paste_left(struct tree_balance *tb,
352 * balance_leaf - reiserfs tree balancing algorithm 352 struct item_head *ih, const char *body)
353 * @tb: tree balance state
354 * @ih: item header of inserted item (little endian)
355 * @body: body of inserted item or bytes to paste
356 * @flag: i - insert, d - delete, c - cut, p - paste (see do_balance)
357 * passed back:
358 * @insert_key: key to insert new nodes
359 * @insert_ptr: array of nodes to insert at the next level
360 *
361 * In our processing of one level we sometimes determine what must be
362 * inserted into the next higher level. This insertion consists of a
363 * key or two keys and their corresponding pointers.
364 */
365static int balance_leaf(struct tree_balance *tb, struct item_head *ih,
366 const char *body, int flag,
367 struct item_head *insert_key,
368 struct buffer_head **insert_ptr)
369{ 353{
370 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); 354 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
371 struct buffer_info bi;
372 int n, i;
373 int ret_val; 355 int ret_val;
374 356 struct buffer_info bi;
375 PROC_INFO_INC(tb->tb_sb, balance_at[0]); 357 int n = B_NR_ITEMS(tb->L[0]);
376
377 /* Make balance in case insert_size[0] < 0 */
378 if (tb->insert_size[0] < 0)
379 return balance_leaf_when_delete(tb, flag);
380
381 tb->item_pos = PATH_LAST_POSITION(tb->tb_path),
382 tb->pos_in_item = tb->tb_path->pos_in_item,
383 tb->zeroes_num = 0;
384 if (flag == M_INSERT && !body)
385 tb->zeroes_num = ih_item_len(ih);
386
387 /*
388 * for indirect item pos_in_item is measured in unformatted node
389 * pointers. Recalculate to bytes
390 */
391 if (flag != M_INSERT
392 && is_indirect_le_ih(item_head(tbS0, tb->item_pos)))
393 tb->pos_in_item *= UNFM_P_SIZE;
394
395 if (tb->lnum[0] > 0) {
396 /* Shift lnum[0] items from S[0] to the left neighbor L[0] */
397 if (tb->item_pos < tb->lnum[0]) {
398 /* new item or it part falls to L[0], shift it too */
399 n = B_NR_ITEMS(tb->L[0]);
400
401 switch (flag) {
402 case M_INSERT: /* insert item into L[0] */
403 balance_leaf_insert_left(tb, ih, body);
404 break;
405
406 case M_PASTE: /* append item in L[0] */
407 358
408 if (tb->item_pos == tb->lnum[0] - 1 && tb->lbytes != -1) { 359 if (tb->item_pos == tb->lnum[0] - 1 && tb->lbytes != -1) {
409 /* we must shift the part of the appended item */ 360 /* we must shift the part of the appended item */
@@ -554,6 +505,66 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih,
554 tb->insert_size[0] = 0; 505 tb->insert_size[0] = 0;
555 tb->zeroes_num = 0; 506 tb->zeroes_num = 0;
556 } 507 }
508
509}
510
511/**
512 * balance_leaf - reiserfs tree balancing algorithm
513 * @tb: tree balance state
514 * @ih: item header of inserted item (little endian)
515 * @body: body of inserted item or bytes to paste
516 * @flag: i - insert, d - delete, c - cut, p - paste (see do_balance)
517 * passed back:
518 * @insert_key: key to insert new nodes
519 * @insert_ptr: array of nodes to insert at the next level
520 *
521 * In our processing of one level we sometimes determine what must be
522 * inserted into the next higher level. This insertion consists of a
523 * key or two keys and their corresponding pointers.
524 */
525static int balance_leaf(struct tree_balance *tb, struct item_head *ih,
526 const char *body, int flag,
527 struct item_head *insert_key,
528 struct buffer_head **insert_ptr)
529{
530 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
531 struct buffer_info bi;
532 int n, i;
533 int ret_val;
534
535 PROC_INFO_INC(tb->tb_sb, balance_at[0]);
536
537 /* Make balance in case insert_size[0] < 0 */
538 if (tb->insert_size[0] < 0)
539 return balance_leaf_when_delete(tb, flag);
540
541 tb->item_pos = PATH_LAST_POSITION(tb->tb_path),
542 tb->pos_in_item = tb->tb_path->pos_in_item,
543 tb->zeroes_num = 0;
544 if (flag == M_INSERT && !body)
545 tb->zeroes_num = ih_item_len(ih);
546
547 /*
548 * for indirect item pos_in_item is measured in unformatted node
549 * pointers. Recalculate to bytes
550 */
551 if (flag != M_INSERT
552 && is_indirect_le_ih(item_head(tbS0, tb->item_pos)))
553 tb->pos_in_item *= UNFM_P_SIZE;
554
555 if (tb->lnum[0] > 0) {
556 /* Shift lnum[0] items from S[0] to the left neighbor L[0] */
557 if (tb->item_pos < tb->lnum[0]) {
558 /* new item or it part falls to L[0], shift it too */
559 n = B_NR_ITEMS(tb->L[0]);
560
561 switch (flag) {
562 case M_INSERT: /* insert item into L[0] */
563 balance_leaf_insert_left(tb, ih, body);
564 break;
565
566 case M_PASTE: /* append item in L[0] */
567 balance_leaf_paste_left(tb, ih, body);
557 break; 568 break;
558 default: /* cases d and t */ 569 default: /* cases d and t */
559 reiserfs_panic(tb->tb_sb, "PAP-12130", 570 reiserfs_panic(tb->tb_sb, "PAP-12130",