Use same code for block moving with and without flex_bg
parent
b8f52b6c8b
commit
15e3f31df8
|
@ -6,7 +6,6 @@
|
||||||
* TODO support undo, but not by undo_io_manager because it is VERY slow
|
* TODO support undo, but not by undo_io_manager because it is VERY slow
|
||||||
* TODO check the bad block inode before block moving
|
* TODO check the bad block inode before block moving
|
||||||
* TODO check if the block mover does block_alloc_stats
|
* TODO check if the block mover does block_alloc_stats
|
||||||
* TODO try to remove duplicate code constructs
|
|
||||||
* TODO write some tests: for inode moving (image with many files),
|
* TODO write some tests: for inode moving (image with many files),
|
||||||
* for block moving, including extent blocks (one sparse file with many extents),
|
* for block moving, including extent blocks (one sparse file with many extents),
|
||||||
* for calculating block group statistics (block moving between different groups)
|
* for calculating block group statistics (block moving between different groups)
|
||||||
|
@ -296,7 +295,7 @@ int extend_move_blocks(realloc_data *rd)
|
||||||
{
|
{
|
||||||
ext2fs_block_bitmap reserve_map;
|
ext2fs_block_bitmap reserve_map;
|
||||||
blk64_t it_start, blk_diff, b_per_g;
|
blk64_t it_start, blk_diff, b_per_g;
|
||||||
dgrp_t grp, n_flex, n_grp, flex_count;
|
dgrp_t n_flex, n_grp, flex_count;
|
||||||
int retval, flexbg_size;
|
int retval, flexbg_size;
|
||||||
if (rd->new_inode_blocks_per_group == rd->fs->inode_blocks_per_group)
|
if (rd->new_inode_blocks_per_group == rd->fs->inode_blocks_per_group)
|
||||||
{
|
{
|
||||||
|
@ -317,44 +316,30 @@ int extend_move_blocks(realloc_data *rd)
|
||||||
if (EXT2_HAS_INCOMPAT_FEATURE(rd->fs->super, EXT4_FEATURE_INCOMPAT_FLEX_BG)
|
if (EXT2_HAS_INCOMPAT_FEATURE(rd->fs->super, EXT4_FEATURE_INCOMPAT_FLEX_BG)
|
||||||
&& rd->fs->super->s_log_groups_per_flex)
|
&& rd->fs->super->s_log_groups_per_flex)
|
||||||
{
|
{
|
||||||
// flex_bg
|
|
||||||
flexbg_size = 1 << rd->fs->super->s_log_groups_per_flex;
|
flexbg_size = 1 << rd->fs->super->s_log_groups_per_flex;
|
||||||
flex_count = (rd->fs->group_desc_count + flexbg_size - 1) / flexbg_size;
|
|
||||||
for (n_flex = 0; n_flex < flex_count; n_flex++)
|
|
||||||
{
|
|
||||||
n_grp = flexbg_size;
|
|
||||||
if (n_flex*flexbg_size+n_grp > rd->fs->group_desc_count)
|
|
||||||
{
|
|
||||||
n_grp = rd->fs->group_desc_count-n_flex*flexbg_size;
|
|
||||||
}
|
|
||||||
it_start = ext2fs_inode_table_loc(rd->fs, n_flex*flexbg_size);
|
|
||||||
// Check group boundaries
|
|
||||||
if ((it_start + rd->new_inode_blocks_per_group*n_grp - 1) / b_per_g
|
|
||||||
!= (it_start + rd->fs->inode_blocks_per_group*n_grp - 1) / b_per_g)
|
|
||||||
{
|
|
||||||
retval = ENOSPC;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
it_start += rd->fs->inode_blocks_per_group*n_grp;
|
|
||||||
ext2fs_mark_block_bitmap_range2(reserve_map, it_start, blk_diff*n_grp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// No flex_bg
|
flexbg_size = 1;
|
||||||
for (grp = 0; grp < rd->fs->group_desc_count; grp++)
|
}
|
||||||
|
flex_count = (rd->fs->group_desc_count + flexbg_size - 1) / flexbg_size;
|
||||||
|
for (n_flex = 0; n_flex < flex_count; n_flex++)
|
||||||
|
{
|
||||||
|
n_grp = flexbg_size;
|
||||||
|
if (n_flex*flexbg_size+n_grp > rd->fs->group_desc_count)
|
||||||
{
|
{
|
||||||
it_start = ext2fs_inode_table_loc(rd->fs, grp);
|
n_grp = rd->fs->group_desc_count-n_flex*flexbg_size;
|
||||||
// Check group boundaries
|
|
||||||
if ((it_start + rd->new_inode_blocks_per_group - 1) / b_per_g
|
|
||||||
!= (it_start + rd->fs->inode_blocks_per_group - 1) / b_per_g)
|
|
||||||
{
|
|
||||||
retval = ENOSPC;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
it_start += rd->fs->inode_blocks_per_group;
|
|
||||||
ext2fs_mark_block_bitmap_range2(reserve_map, it_start, rd->new_inode_blocks_per_group-rd->fs->inode_blocks_per_group);
|
|
||||||
}
|
}
|
||||||
|
it_start = ext2fs_inode_table_loc(rd->fs, n_flex*flexbg_size);
|
||||||
|
// Check group boundaries
|
||||||
|
if ((it_start + rd->new_inode_blocks_per_group*n_grp - 1) / b_per_g
|
||||||
|
!= (it_start + rd->fs->inode_blocks_per_group*n_grp - 1) / b_per_g)
|
||||||
|
{
|
||||||
|
retval = ENOSPC;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
it_start += rd->fs->inode_blocks_per_group*n_grp;
|
||||||
|
ext2fs_mark_block_bitmap_range2(reserve_map, it_start, blk_diff*n_grp);
|
||||||
}
|
}
|
||||||
retval = ext2fs_move_blocks(rd->fs, reserve_map, rd->fs->block_map, 0);
|
retval = ext2fs_move_blocks(rd->fs, reserve_map, rd->fs->block_map, 0);
|
||||||
ext2fs_mark_bb_dirty(rd->fs);
|
ext2fs_mark_bb_dirty(rd->fs);
|
||||||
|
|
Loading…
Reference in New Issue