aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2014-04-23 10:00:47 -0400
committerJan Kara <jack@suse.cz>2014-05-07 12:33:17 -0400
commitf1f007c308eb95be5ebb3d9fec566f86662975be (patch)
tree5b52279845d8726a2cd9a6cceeff4d24cd4ef4ac /fs/reiserfs
parentb49fb112d4ae62ca1c549130a111fb39e85e2c93 (diff)
reiserfs: balance_leaf refactor, pull out balance_leaf_insert_left
This patch factors out a new balance_leaf_insert_left from the code in balance_leaf responsible for inserting new items into the node to the left of S[0] in the tree. It is not yet formatted correctly. 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.c108
1 files changed, 59 insertions, 49 deletions
diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
index 6dbe55ff408e..44eb4f6ce0da 100644
--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -290,6 +290,64 @@ static int balance_leaf_when_delete(struct tree_balance *tb, int flag)
290 return 0; 290 return 0;
291} 291}
292 292
293static void balance_leaf_insert_left(struct tree_balance *tb,
294 struct item_head *ih, const char *body)
295{
296 int ret_val;
297 struct buffer_info bi;
298 int n = B_NR_ITEMS(tb->L[0]);
299
300 if (tb->item_pos == tb->lnum[0] - 1 && tb->lbytes != -1) {
301 /* part of new item falls into L[0] */
302 int new_item_len;
303 int version;
304
305 ret_val = leaf_shift_left(tb, tb->lnum[0] - 1, -1);
306
307 /* Calculate item length to insert to S[0] */
308 new_item_len = ih_item_len(ih) - tb->lbytes;
309 /* Calculate and check item length to insert to L[0] */
310 put_ih_item_len(ih, ih_item_len(ih) - new_item_len);
311
312 RFALSE(ih_item_len(ih) <= 0,
313 "PAP-12080: there is nothing to insert into L[0]: ih_item_len=%d",
314 ih_item_len(ih));
315
316 /* Insert new item into L[0] */
317 buffer_info_init_left(tb, &bi);
318 leaf_insert_into_buf(&bi,
319 n + tb->item_pos - ret_val, ih, body,
320 tb->zeroes_num > ih_item_len(ih) ? ih_item_len(ih) : tb->zeroes_num);
321
322 version = ih_version(ih);
323
324 /* Calculate key component, item length and body to insert into S[0] */
325 set_le_ih_k_offset(ih, le_ih_k_offset(ih) +
326 (tb->lbytes << (is_indirect_le_ih(ih) ? tb->tb_sb->s_blocksize_bits - UNFM_P_SHIFT : 0)));
327
328 put_ih_item_len(ih, new_item_len);
329 if (tb->lbytes > tb->zeroes_num) {
330 body += (tb->lbytes - tb->zeroes_num);
331 tb->zeroes_num = 0;
332 } else
333 tb->zeroes_num -= tb->lbytes;
334
335 RFALSE(ih_item_len(ih) <= 0,
336 "PAP-12085: there is nothing to insert into S[0]: ih_item_len=%d",
337 ih_item_len(ih));
338 } else {
339 /* new item in whole falls into L[0] */
340 /* Shift lnum[0]-1 items to L[0] */
341 ret_val = leaf_shift_left(tb, tb->lnum[0] - 1, tb->lbytes);
342 /* Insert new item into L[0] */
343 buffer_info_init_left(tb, &bi);
344 leaf_insert_into_buf(&bi, n + tb->item_pos - ret_val, ih, body, tb->zeroes_num);
345 tb->insert_size[0] = 0;
346 tb->zeroes_num = 0;
347 }
348
349}
350
293/** 351/**
294 * balance_leaf - reiserfs tree balancing algorithm 352 * balance_leaf - reiserfs tree balancing algorithm
295 * @tb: tree balance state 353 * @tb: tree balance state
@@ -342,55 +400,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih,
342 400
343 switch (flag) { 401 switch (flag) {
344 case M_INSERT: /* insert item into L[0] */ 402 case M_INSERT: /* insert item into L[0] */
345 403 balance_leaf_insert_left(tb, ih, body);
346 if (tb->item_pos == tb->lnum[0] - 1 && tb->lbytes != -1) {
347 /* part of new item falls into L[0] */
348 int new_item_len;
349 int version;
350
351 ret_val = leaf_shift_left(tb, tb->lnum[0] - 1, -1);
352
353 /* Calculate item length to insert to S[0] */
354 new_item_len = ih_item_len(ih) - tb->lbytes;
355 /* Calculate and check item length to insert to L[0] */
356 put_ih_item_len(ih, ih_item_len(ih) - new_item_len);
357
358 RFALSE(ih_item_len(ih) <= 0,
359 "PAP-12080: there is nothing to insert into L[0]: ih_item_len=%d",
360 ih_item_len(ih));
361
362 /* Insert new item into L[0] */
363 buffer_info_init_left(tb, &bi);
364 leaf_insert_into_buf(&bi,
365 n + tb->item_pos - ret_val, ih, body,
366 tb->zeroes_num > ih_item_len(ih) ? ih_item_len(ih) : tb->zeroes_num);
367
368 version = ih_version(ih);
369
370 /* Calculate key component, item length and body to insert into S[0] */
371 set_le_ih_k_offset(ih, le_ih_k_offset(ih) +
372 (tb-> lbytes << (is_indirect_le_ih(ih) ? tb->tb_sb-> s_blocksize_bits - UNFM_P_SHIFT : 0)));
373
374 put_ih_item_len(ih, new_item_len);
375 if (tb->lbytes > tb->zeroes_num) {
376 body += (tb->lbytes - tb->zeroes_num);
377 tb->zeroes_num = 0;
378 } else
379 tb->zeroes_num -= tb->lbytes;
380
381 RFALSE(ih_item_len(ih) <= 0,
382 "PAP-12085: there is nothing to insert into S[0]: ih_item_len=%d",
383 ih_item_len(ih));
384 } else {
385 /* new item in whole falls into L[0] */
386 /* Shift lnum[0]-1 items to L[0] */
387 ret_val = leaf_shift_left(tb, tb->lnum[0] - 1, tb->lbytes);
388 /* Insert new item into L[0] */
389 buffer_info_init_left(tb, &bi);
390 leaf_insert_into_buf(&bi, n + tb->item_pos - ret_val, ih, body, tb->zeroes_num);
391 tb->insert_size[0] = 0;
392 tb->zeroes_num = 0;
393 }
394 break; 404 break;
395 405
396 case M_PASTE: /* append item in L[0] */ 406 case M_PASTE: /* append item in L[0] */