diff mbox series

resize2fs: Check number of group descriptors only if meta_bg is disabled

Message ID 20240925171926.11354-1-jack@suse.cz
State New
Headers show
Series resize2fs: Check number of group descriptors only if meta_bg is disabled | expand

Commit Message

Jan Kara Sept. 25, 2024, 5:19 p.m. UTC
When meta_bg feature is enabled, the total number of group descriptors
is not really limiting the filesystem size. So there's no reason to
check it in that case. This allows resize2fs to resize filesystems past
256TB boundary similarly as the kernel can do it.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 resize/main.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

Comments

Ojaswin Mujoo Oct. 1, 2024, 9:11 a.m. UTC | #1
On Wed, Sep 25, 2024 at 07:19:26PM +0200, Jan Kara wrote:
> When meta_bg feature is enabled, the total number of group descriptors
> is not really limiting the filesystem size. So there's no reason to
> check it in that case. This allows resize2fs to resize filesystems past
> 256TB boundary similarly as the kernel can do it.
> 
> Signed-off-by: Jan Kara <jack@suse.cz>

Hi Jan,

Right this makes sense, I tested this using a sparse device:

# create a 1PB sparse device
sudo dmsetup create $SPARSE_DEVICE --table "0 $SIZE_1PB zero"
sudo dmsetup create $SNAPSHOT_NAME --table "0 $SIZE_1PB snapshot /dev/mapper/$SPARSE_DEVICE $BASE_DEVICE P 8"

sudo mkfs.ext4 /dev/mapper/$SNAPSHOT_NAME 512T
sudo resize2fs /dev/mapper/$SNAPSHOT_NAME 513T

This fails originally and works correctly with this patch applied. Infact without
this patch we end up failing 512T -> 512T resize as well which should just be 
a no-op.

Feel free to add:

Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>

> ---
>  resize/main.c | 29 ++++++++++++++++-------------
>  1 file changed, 16 insertions(+), 13 deletions(-)
> 
> diff --git a/resize/main.c b/resize/main.c
> index f914c0507e97..08a4bbaf7c65 100644
> --- a/resize/main.c
> +++ b/resize/main.c
> @@ -270,8 +270,6 @@ int main (int argc, char ** argv)
>  	long		sysval;
>  	int		len, mount_flags;
>  	char		*mtpt, *undo_file = NULL;
> -	dgrp_t		new_group_desc_count;
> -	unsigned long	new_desc_blocks;
>  
>  #ifdef ENABLE_NLS
>  	setlocale(LC_MESSAGES, "");
> @@ -551,17 +549,22 @@ int main (int argc, char ** argv)
>  		new_size &= ~((blk64_t)(1ULL << fs->cluster_ratio_bits) - 1);
>  	}
>  
> -	new_group_desc_count = ext2fs_div64_ceil(new_size -
> -				fs->super->s_first_data_block,
> -						 EXT2_BLOCKS_PER_GROUP(fs->super));
> -	new_desc_blocks = ext2fs_div_ceil(new_group_desc_count,
> -					  EXT2_DESC_PER_BLOCK(fs->super));
> -	if ((new_desc_blocks + fs->super->s_first_data_block) >
> -	    EXT2_BLOCKS_PER_GROUP(fs->super)) {
> -		com_err(program_name, 0,
> -			_("New size results in too many block group "
> -			  "descriptors.\n"));
> -		goto errout;
> +	if (!ext2fs_has_feature_meta_bg(fs->super)) {
> +		dgrp_t		new_group_desc_count;
> +		unsigned long	new_desc_blocks;
> +
> +		new_group_desc_count = ext2fs_div64_ceil(new_size -
> +					fs->super->s_first_data_block,
> +					EXT2_BLOCKS_PER_GROUP(fs->super));
> +		new_desc_blocks = ext2fs_div_ceil(new_group_desc_count,
> +					EXT2_DESC_PER_BLOCK(fs->super));
> +		if ((new_desc_blocks + fs->super->s_first_data_block) >
> +		    EXT2_BLOCKS_PER_GROUP(fs->super)) {
> +			com_err(program_name, 0,
> +				_("New size results in too many block group "
> +				  "descriptors.\n"));
> +			goto errout;
> +		}
>  	}
>  
>  	if (!force && new_size < min_size) {
> -- 
> 2.35.3
>
diff mbox series

Patch

diff --git a/resize/main.c b/resize/main.c
index f914c0507e97..08a4bbaf7c65 100644
--- a/resize/main.c
+++ b/resize/main.c
@@ -270,8 +270,6 @@  int main (int argc, char ** argv)
 	long		sysval;
 	int		len, mount_flags;
 	char		*mtpt, *undo_file = NULL;
-	dgrp_t		new_group_desc_count;
-	unsigned long	new_desc_blocks;
 
 #ifdef ENABLE_NLS
 	setlocale(LC_MESSAGES, "");
@@ -551,17 +549,22 @@  int main (int argc, char ** argv)
 		new_size &= ~((blk64_t)(1ULL << fs->cluster_ratio_bits) - 1);
 	}
 
-	new_group_desc_count = ext2fs_div64_ceil(new_size -
-				fs->super->s_first_data_block,
-						 EXT2_BLOCKS_PER_GROUP(fs->super));
-	new_desc_blocks = ext2fs_div_ceil(new_group_desc_count,
-					  EXT2_DESC_PER_BLOCK(fs->super));
-	if ((new_desc_blocks + fs->super->s_first_data_block) >
-	    EXT2_BLOCKS_PER_GROUP(fs->super)) {
-		com_err(program_name, 0,
-			_("New size results in too many block group "
-			  "descriptors.\n"));
-		goto errout;
+	if (!ext2fs_has_feature_meta_bg(fs->super)) {
+		dgrp_t		new_group_desc_count;
+		unsigned long	new_desc_blocks;
+
+		new_group_desc_count = ext2fs_div64_ceil(new_size -
+					fs->super->s_first_data_block,
+					EXT2_BLOCKS_PER_GROUP(fs->super));
+		new_desc_blocks = ext2fs_div_ceil(new_group_desc_count,
+					EXT2_DESC_PER_BLOCK(fs->super));
+		if ((new_desc_blocks + fs->super->s_first_data_block) >
+		    EXT2_BLOCKS_PER_GROUP(fs->super)) {
+			com_err(program_name, 0,
+				_("New size results in too many block group "
+				  "descriptors.\n"));
+			goto errout;
+		}
 	}
 
 	if (!force && new_size < min_size) {