Since we're constructing the fantasy that new_fs has always been a 64bit fs, we need to adjust reserved_gdt_blocks when we start resizing the metadata so that the size of the gdt space in the new fs reflects the fantasy throughout the resize process. Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx> --- resize/resize2fs.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/resize/resize2fs.c b/resize/resize2fs.c index 472aa4a..5a576a7 100644 --- a/resize/resize2fs.c +++ b/resize/resize2fs.c @@ -241,6 +241,24 @@ errout: return retval; } +/* Keep the size of the group descriptor region constant */ +static void adjust_reserved_gdt_blocks(ext2_filsys old_fs, ext2_filsys fs) +{ + if ((fs->super->s_feature_compat & + EXT2_FEATURE_COMPAT_RESIZE_INODE) && + (old_fs->desc_blocks != fs->desc_blocks)) { + int new; + + new = ((int) fs->super->s_reserved_gdt_blocks) + + (old_fs->desc_blocks - fs->desc_blocks); + if (new < 0) + new = 0; + if (new > (int) fs->blocksize/4) + new = fs->blocksize/4; + fs->super->s_reserved_gdt_blocks = new; + } +} + /* Toggle 64bit mode */ static errcode_t resize_group_descriptors(ext2_resize_t rfs, blk64_t new_size) { @@ -300,6 +318,8 @@ static errcode_t resize_group_descriptors(ext2_resize_t rfs, blk64_t new_size) for (i = 0; i < rfs->old_fs->group_desc_count; i++) ext2fs_group_desc_csum_set(rfs->new_fs, i); + adjust_reserved_gdt_blocks(rfs->old_fs, rfs->new_fs); + return 0; } @@ -756,20 +776,11 @@ retry: * number of descriptor blocks, then adjust * s_reserved_gdt_blocks if possible to avoid needing to move * the inode table either now or in the future. + * + * Note: If we're converting to 64bit mode, we did this earlier. */ - if ((fs->super->s_feature_compat & - EXT2_FEATURE_COMPAT_RESIZE_INODE) && - (old_fs->desc_blocks != fs->desc_blocks)) { - int new; - - new = ((int) fs->super->s_reserved_gdt_blocks) + - (old_fs->desc_blocks - fs->desc_blocks); - if (new < 0) - new = 0; - if (new > (int) fs->blocksize/4) - new = fs->blocksize/4; - fs->super->s_reserved_gdt_blocks = new; - } + if (EXT2_DESC_SIZE(old_fs->super) == EXT2_DESC_SIZE(fs->super)) + adjust_reserved_gdt_blocks(old_fs, fs); /* * If we are shrinking the number of block groups, we're done -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html