ext4: Verify s_clusters_per_group even without bigalloc
Jan Kara
reviewerPATCH 1/1 ext4: Verify s_clusters_per_group even without bigalloc
Currently we ignore s_clusters_per_group field in the on-disk superblock if bigalloc feature is not enabled. However e2fsprogs don't even open the filesystem is s_clusters_per_group is invalid. This results in an odd state where kernel happily works with the filesystem while even e2fsck refuses to touch it. Verify that s_clusters_per_group is valid even if bigalloc feature is not enabled to make things consistent. Due to current e2fsprogs behavior it is unlikely there are filesystems out in the wild (except for intentionally fuzzed ones) with invalid s_clusters_per_group counts.
--- fs/ext4/super.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
fs/ext4/super.c +9 -1
@@ -4451,7 +4451,15 @@ static int ext4_handle_clustersize(struct super_block *sb) sbi->s_blocks_per_group);return -EINVAL ; } - sbi->s_clusters_per_group = sbi->s_blocks_per_group; + sbi->s_clusters_per_group = +le32_to_cpu (es->s_clusters_per_group); +if (sbi->s_blocks_per_group != sbi->s_clusters_per_group) { +ext4_msg (sb,KERN_ERR ,"blocks per group (%lu) and " +"clusters per group (%lu) inconsistent" , + sbi->s_blocks_per_group, + sbi->s_clusters_per_group); +return -EINVAL ; + } sbi->s_cluster_bits =0 ; } sbi->s_cluster_ratio = clustersize / sb->s_blocksize;
Signature · 1 line
2.35.3
Zhang Yi
reviewerHello!
Quoted 3 lines · Jan Kara
Currently we ignore
s_clusters_per_groupfield in the on-disk superblock if bigalloc feature is not enabled. However e2fsprogs don't even open the filesystem iss_clusters_per_groupis invalid. This results in an
^^
ifQuoted 20 lines
odd state where kernel happily works with the filesystem while even e2fsck refuses to touch it. Verify that
s_clusters_per_groupis valid even if bigalloc feature is not enabled to make things consistent. Due to current e2fsprogs behavior it is unlikely there are filesystems out in the wild (except for intentionally fuzzed ones) with invalids_clusters_per_groupcounts.Signed-off-by Jan Kara <[email protected]>--- fs/ext4/super.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)fs/ext4/super.c +0
-0@@ -4451,7 +4451,15 @@ static int ext4_handle_clustersize(struct super_block *sb) sbi->s_blocks_per_group);return -EINVAL ; }
fs/ext4/super.c static int ext4_handle_clustersize(struct super_block *sb) · line 4462
Quoted 10 lines
fs/ext4/super.c +9
-1- sbi->s_clusters_per_group = sbi->s_blocks_per_group; + sbi->s_clusters_per_group = +le32_to_cpu (es->s_clusters_per_group); +if (sbi->s_blocks_per_group != sbi->s_clusters_per_group) { +ext4_msg (sb,KERN_ERR ,"blocks per group (%lu) and " +"clusters per group (%lu) inconsistent" , + sbi->s_blocks_per_group, + sbi->s_clusters_per_group); +return -EINVAL ; + }
This is almost the same with the code snippet in bigalloc branch, would it be better to factor them out and reuse this hunk in both branch, just like the check e2fsprogs does?
Thanks,
Yi.
Quoted 4 lines
fs/ext4/super.c +0
-0sbi->s_cluster_bits =0 ; } sbi->s_cluster_ratio = clustersize / sb->s_blocksize;
Jan Kara
reviewerQuoted 34 lines · Zhang Yi
Hello!
Quoted 3 lines · Jan Kara
Currently we ignore
s_clusters_per_groupfield in the on-disk superblock if bigalloc feature is not enabled. However e2fsprogs don't even open the filesystem iss_clusters_per_groupis invalid. This results in an^^ ifQuoted 26 lines
odd state where kernel happily works with the filesystem while even e2fsck refuses to touch it. Verify that
s_clusters_per_groupis valid even if bigalloc feature is not enabled to make things consistent. Due to current e2fsprogs behavior it is unlikely there are filesystems out in the wild (except for intentionally fuzzed ones) with invalids_clusters_per_groupcounts.Signed-off-by Jan Kara <[email protected]>--- fs/ext4/super.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)fs/ext4/super.c +5
-1@@ -4451,7 +4451,15 @@ static int ext4_handle_clustersize(struct super_block *sb) sbi->s_blocks_per_group);return -EINVAL ; } - sbi->s_clusters_per_group = sbi->s_blocks_per_group; + sbi->s_clusters_per_group = +le32_to_cpu (es->s_clusters_per_group); +if (sbi->s_blocks_per_group != sbi->s_clusters_per_group) { + ext4_msg(sb, KERN_ERR, "blocks per group (%lu) and " + "clusters per group (%lu) inconsistent",
Quoted 8 lines
fs/ext4/super.c static int ext4_handle_clustersize(struct super_block *sb) · line 4462
Quoted 4 lines
fs/ext4/super.c +4
-0+ sbi->s_blocks_per_group, + sbi->s_clusters_per_group); +return -EINVAL ; + }This is almost the same with the code snippet in bigalloc branch, would it be better to factor them out and reuse this hunk in both branch, just like the check e2fsprogs does?
Yeah, good point. Let me send v2.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR