Disallow moving resize inode; use ext2fs_block_alloc_stats2 in block mover
parent
ee1b499ca9
commit
8bf3f6d012
8
bmove.c
8
bmove.c
|
@ -53,7 +53,9 @@ static int process_block(ext2_filsys fs, blk64_t *block_nr,
|
||||||
* Let's see if this is one which we need to relocate
|
* Let's see if this is one which we need to relocate
|
||||||
*/
|
*/
|
||||||
if (ext2fs_test_block_bitmap2(pb->reserve, block)) {
|
if (ext2fs_test_block_bitmap2(pb->reserve, block)) {
|
||||||
if (pb->ino == EXT2_BAD_INO) {
|
if (blockcnt >= 0 && (pb->ino == EXT2_BAD_INO || pb->ino == EXT2_RESIZE_INO)) {
|
||||||
|
// We obviously can't move bad blocks; and also the resize inode, because it must be in a predefined location
|
||||||
|
// But we allow to move extent blocks (blockcnt == -1) and directory index blocks (blockcnt == -2)
|
||||||
pb->error = EXT2_ET_BAD_BLOCK_IN_INODE_TABLE;
|
pb->error = EXT2_ET_BAD_BLOCK_IN_INODE_TABLE;
|
||||||
return BLOCK_ABORT;
|
return BLOCK_ABORT;
|
||||||
}
|
}
|
||||||
|
@ -78,8 +80,8 @@ static int process_block(ext2_filsys fs, blk64_t *block_nr,
|
||||||
return BLOCK_ABORT;
|
return BLOCK_ABORT;
|
||||||
}
|
}
|
||||||
*block_nr = block;
|
*block_nr = block;
|
||||||
ext2fs_mark_block_bitmap2(pb->alloc_map, block);
|
ext2fs_block_alloc_stats2(fs, orig, -1);
|
||||||
ext2fs_unmark_block_bitmap2(pb->alloc_map, orig);
|
ext2fs_block_alloc_stats2(fs, block, +1);
|
||||||
ret = BLOCK_CHANGED;
|
ret = BLOCK_CHANGED;
|
||||||
if (pb->flags & EXT2_BMOVE_DEBUG)
|
if (pb->flags & EXT2_BMOVE_DEBUG)
|
||||||
printf("ino=%u, blockcnt=%lld, %llu->%llu\n",
|
printf("ino=%u, blockcnt=%lld, %llu->%llu\n",
|
||||||
|
|
|
@ -13,7 +13,7 @@ mkdir -p dir
|
||||||
mount -o loop $FILE dir
|
mount -o loop $FILE dir
|
||||||
# For block moving test: create a sparse file with many extents
|
# For block moving test: create a sparse file with many extents
|
||||||
dd if=/dev/urandom of=dir/f_random bs=1k count=1
|
dd if=/dev/urandom of=dir/f_random bs=1k count=1
|
||||||
for i in {1..1200}; do
|
for i in {1..2500}; do
|
||||||
dd if=dir/f_random of=dir/f_sparse bs=1k count=1 seek=$((2400-i*2)) conv=notrunc 2>/dev/null
|
dd if=dir/f_random of=dir/f_sparse bs=1k count=1 seek=$((2400-i*2)) conv=notrunc 2>/dev/null
|
||||||
done
|
done
|
||||||
# For inode moving test: create 1201 1kb sized files
|
# For inode moving test: create 1201 1kb sized files
|
||||||
|
|
|
@ -4,10 +4,9 @@
|
||||||
*
|
*
|
||||||
* TODO bigalloc compatibility
|
* TODO bigalloc compatibility
|
||||||
* 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 if the block mover does block_alloc_stats
|
|
||||||
* 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 block moving between different groups
|
||||||
*
|
*
|
||||||
* The theory isn't that hard:
|
* The theory isn't that hard:
|
||||||
* 1) If shrinking - move inodes away from the end of each block group inode table
|
* 1) If shrinking - move inodes away from the end of each block group inode table
|
||||||
|
@ -333,7 +332,7 @@ int extend_move_blocks(realloc_data *rd)
|
||||||
n_grp = rd->fs->group_desc_count-flex_grp*flexbg_size;
|
n_grp = rd->fs->group_desc_count-flex_grp*flexbg_size;
|
||||||
}
|
}
|
||||||
it_start = ext2fs_inode_table_loc(rd->fs, flex_grp*flexbg_size);
|
it_start = ext2fs_inode_table_loc(rd->fs, flex_grp*flexbg_size);
|
||||||
// Check group boundaries (just in case)
|
// Check group boundaries (the first group in flex_bg must contain all inode tables)
|
||||||
if ((it_start + rd->ibg_new*n_grp - 1) / b_per_g
|
if ((it_start + rd->ibg_new*n_grp - 1) / b_per_g
|
||||||
!= (it_start + rd->ibg_old*n_grp - 1) / b_per_g)
|
!= (it_start + rd->ibg_old*n_grp - 1) / b_per_g)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue