Lines Matching refs:resize

385 struct resize {  struct
433 static int drop_blocks(struct resize *resize, unsigned begin_index, in drop_blocks() argument
440 r = dm_btree_remove(&resize->info->btree_info, resize->root, in drop_blocks()
441 &key, &resize->root); in drop_blocks()
461 static int shrink(struct resize *resize) in shrink() argument
471 if (resize->new_nr_full_blocks < resize->old_nr_full_blocks) { in shrink()
472 begin = total_nr_blocks_needed(resize->new_nr_full_blocks, in shrink()
473 resize->new_nr_entries_in_last_block); in shrink()
474 end = total_nr_blocks_needed(resize->old_nr_full_blocks, in shrink()
475 resize->old_nr_entries_in_last_block); in shrink()
477 r = drop_blocks(resize, begin, end); in shrink()
485 if (resize->new_nr_entries_in_last_block) { in shrink()
486 r = shadow_ablock(resize->info, &resize->root, in shrink()
487 resize->new_nr_full_blocks, &block, &ab); in shrink()
491 trim_ablock(resize->info, ab, resize->new_nr_entries_in_last_block); in shrink()
492 unlock_ablock(resize->info, block); in shrink()
501 static int grow_extend_tail_block(struct resize *resize, uint32_t new_nr_entries) in grow_extend_tail_block() argument
507 r = shadow_ablock(resize->info, &resize->root, in grow_extend_tail_block()
508 resize->old_nr_full_blocks, &block, &ab); in grow_extend_tail_block()
512 fill_ablock(resize->info, ab, resize->value, new_nr_entries); in grow_extend_tail_block()
513 unlock_ablock(resize->info, block); in grow_extend_tail_block()
518 static int grow_add_tail_block(struct resize *resize) in grow_add_tail_block() argument
520 return insert_new_ablock(resize->info, resize->size_of_block, in grow_add_tail_block()
521 resize->max_entries, in grow_add_tail_block()
522 resize->new_nr_full_blocks, in grow_add_tail_block()
523 resize->new_nr_entries_in_last_block, in grow_add_tail_block()
524 resize->value, &resize->root); in grow_add_tail_block()
527 static int grow_needs_more_blocks(struct resize *resize) in grow_needs_more_blocks() argument
530 unsigned old_nr_blocks = resize->old_nr_full_blocks; in grow_needs_more_blocks()
532 if (resize->old_nr_entries_in_last_block > 0) { in grow_needs_more_blocks()
535 r = grow_extend_tail_block(resize, resize->max_entries); in grow_needs_more_blocks()
540 r = insert_full_ablocks(resize->info, resize->size_of_block, in grow_needs_more_blocks()
542 resize->new_nr_full_blocks, in grow_needs_more_blocks()
543 resize->max_entries, resize->value, in grow_needs_more_blocks()
544 &resize->root); in grow_needs_more_blocks()
548 if (resize->new_nr_entries_in_last_block) in grow_needs_more_blocks()
549 r = grow_add_tail_block(resize); in grow_needs_more_blocks()
554 static int grow(struct resize *resize) in grow() argument
556 if (resize->new_nr_full_blocks > resize->old_nr_full_blocks) in grow()
557 return grow_needs_more_blocks(resize); in grow()
559 else if (resize->old_nr_entries_in_last_block) in grow()
560 return grow_extend_tail_block(resize, resize->new_nr_entries_in_last_block); in grow()
563 return grow_add_tail_block(resize); in grow()
664 struct resize resize; in array_resize() local
671 resize.info = info; in array_resize()
672 resize.root = root; in array_resize()
673 resize.size_of_block = dm_bm_block_size(dm_tm_get_bm(info->btree_info.tm)); in array_resize()
674 resize.max_entries = calc_max_entries(info->value_type.size, in array_resize()
675 resize.size_of_block); in array_resize()
677 resize.old_nr_full_blocks = old_size / resize.max_entries; in array_resize()
678 resize.old_nr_entries_in_last_block = old_size % resize.max_entries; in array_resize()
679 resize.new_nr_full_blocks = new_size / resize.max_entries; in array_resize()
680 resize.new_nr_entries_in_last_block = new_size % resize.max_entries; in array_resize()
681 resize.value = value; in array_resize()
683 r = ((new_size > old_size) ? grow : shrink)(&resize); in array_resize()
687 *new_root = resize.root; in array_resize()