2011-04-23 13:37:15

by Robin Dong

[permalink] [raw]
Subject: [PATCH] fix incorrect error-message of ext2

From: Robin Dong <[email protected]>

After "mkfs.ext2 -b 8192" on a new partition, I mount it with a error dmesg:
"error: blocksize is too small"
That's not correct.

Signed-off-by: Robin Dong <[email protected]>
---
fs/ext2/super.c | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 0a78dae..f3008c1 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -758,6 +758,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
unsigned long def_mount_opts;
long ret = -EINVAL;
int blocksize = BLOCK_SIZE;
+ int hblock;
int db_count;
int i, j;
__le32 features;
@@ -893,12 +894,25 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
goto failed_mount;
}

+ hblock = bdev_logical_block_size(sb->s_bdev);
/* If the blocksize doesn't match, re-read the thing.. */
if (sb->s_blocksize != blocksize) {
+ /*
+ * Make sure the blocksize for the filesystem is larger
+ * than the hardware sectorsize for the machine.
+ */
+ if (blocksize < hblock) {
+ ext2_msg(sb, KERN_ERR,
+ "error: fsblocksize %d too small for "
+ "hardware sectorsize %d", blocksize, hblock);
+ goto failed_mount;
+ }
+
brelse(bh);

if (!sb_set_blocksize(sb, blocksize)) {
- ext2_msg(sb, KERN_ERR, "error: blocksize is too small");
+ ext2_msg(sb, KERN_ERR,
+ "error: bad blocksize %d", blocksize);
goto failed_sbi;
}

--
1.7.3.2



2011-04-23 13:53:36

by Coly Li

[permalink] [raw]
Subject: Re: [PATCH] fix incorrect error-message of ext2

On 2011年04月23日 21:36, Robin Dong Wrote:
> From: Robin Dong <[email protected]>
>
> After "mkfs.ext2 -b 8192" on a new partition, I mount it with a error dmesg:
> "error: blocksize is too small"
> That's not correct.
>

Agree, it should be too big, or invalid block size.

> Signed-off-by: Robin Dong <[email protected]>
[snip]
> + hblock = bdev_logical_block_size(sb->s_bdev);
> /* If the blocksize doesn't match, re-read the thing.. */
> if (sb->s_blocksize != blocksize) {
> + /*
> + * Make sure the blocksize for the filesystem is larger
> + * than the hardware sectorsize for the machine.
> + */
> + if (blocksize < hblock) {
> + ext2_msg(sb, KERN_ERR,
> + "error: fsblocksize %d too small for "
> + "hardware sectorsize %d", blocksize, hblock);

When a file system is mounted, the reported underlying dev logical block size may be larger than a sector size.

> + goto failed_mount;
> + }
> +
> brelse(bh);
>

How about just keeping bellowed lines ? Reporting bad block size number is the behavior how Ext3 and Ext4 do.

> if (!sb_set_blocksize(sb, blocksize)) {
> - ext2_msg(sb, KERN_ERR, "error: blocksize is too small");
> + ext2_msg(sb, KERN_ERR,
> + "error: bad blocksize %d", blocksize);
> goto failed_sbi;
> }


--
Coly Li

2011-04-23 14:10:14

by Eric Sandeen

[permalink] [raw]
Subject: Re: [PATCH] fix incorrect error-message of ext2

On 4/23/11 8:36 AM, Robin Dong wrote:
> From: Robin Dong <[email protected]>
>
> After "mkfs.ext2 -b 8192" on a new partition, I mount it with a error dmesg:
> "error: blocksize is too small"
> That's not correct.

Hi Robin -

Can you write a more descriptive changelog?

Imagine reading through git logs 2 years later, especially with --pretty=oneline.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx fix incorrect error-message of ext2

would not be a very informative summary.

And the changelog itself says nothing about why the error is incorrect.

What was the device tested? What is the pagesize of the system used?
Etc...

Maybe something like:

[PATCH] ext2: fix error msg when mounting fs with too-large blocksize

When ext2 mounts a filesystem, it attempts to set the block device
blocksize with a call to sb_set_blocksize, which can fail for
several reasons. The current failure message in ext2 prints:

EXT2-fs (loop1): error: blocksize is too small

which is not correct in all cases. This can be demonstrated
by creating a filesystem with

# mkfs.ext2 -b 8192

on a 4k page system, and attempting to mount it.

Change the error message to a more generic:

EXT2-fs (loop1): bad blocksize 8192

to match the error message in ext3.

----

If the extra tests and message about hardware sector size are needed,
they probably should be added to ext3 as well.

In the testcase above, though, we just failed due to block size
vs. page size restrictions.

-Eric


> Signed-off-by: Robin Dong <[email protected]>
> ---
> fs/ext2/super.c | 16 +++++++++++++++-
> 1 files changed, 15 insertions(+), 1 deletions(-)
>
> diff --git a/fs/ext2/super.c b/fs/ext2/super.c
> index 0a78dae..f3008c1 100644
> --- a/fs/ext2/super.c
> +++ b/fs/ext2/super.c
> @@ -758,6 +758,7 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
> unsigned long def_mount_opts;
> long ret = -EINVAL;
> int blocksize = BLOCK_SIZE;
> + int hblock;
> int db_count;
> int i, j;
> __le32 features;
> @@ -893,12 +894,25 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
> goto failed_mount;
> }
>
> + hblock = bdev_logical_block_size(sb->s_bdev);
> /* If the blocksize doesn't match, re-read the thing.. */
> if (sb->s_blocksize != blocksize) {
> + /*
> + * Make sure the blocksize for the filesystem is larger
> + * than the hardware sectorsize for the machine.
> + */
> + if (blocksize < hblock) {
> + ext2_msg(sb, KERN_ERR,
> + "error: fsblocksize %d too small for "
> + "hardware sectorsize %d", blocksize, hblock);
> + goto failed_mount;
> + }
> +
> brelse(bh);
>
> if (!sb_set_blocksize(sb, blocksize)) {
> - ext2_msg(sb, KERN_ERR, "error: blocksize is too small");
> + ext2_msg(sb, KERN_ERR,
> + "error: bad blocksize %d", blocksize);


> goto failed_sbi;
> }
>


2011-04-23 14:12:20

by Eric Sandeen

[permalink] [raw]
Subject: Re: [PATCH] fix incorrect error-message of ext2

On 4/23/11 9:23 AM, Coly Li wrote:
> On 2011年04月23日 21:36, Robin Dong Wrote:
>> From: Robin Dong <[email protected]>
>>
>> After "mkfs.ext2 -b 8192" on a new partition, I mount it with a error dmesg:
>> "error: blocksize is too small"
>> That's not correct.
>>
>
> Agree, it should be too big, or invalid block size.
>
>> Signed-off-by: Robin Dong <[email protected]>
> [snip]
>> + hblock = bdev_logical_block_size(sb->s_bdev);
>> /* If the blocksize doesn't match, re-read the thing.. */
>> if (sb->s_blocksize != blocksize) {
>> + /*
>> + * Make sure the blocksize for the filesystem is larger
>> + * than the hardware sectorsize for the machine.
>> + */
>> + if (blocksize < hblock) {
>> + ext2_msg(sb, KERN_ERR,
>> + "error: fsblocksize %d too small for "
>> + "hardware sectorsize %d", blocksize, hblock);
>
> When a file system is mounted, the reported underlying dev logical block size may be larger than a sector size.

True, but set_blocksize will fail it:

/* Size cannot be smaller than the size supported by the device */
if (size < bdev_logical_block_size(bdev))
return -EINVAL;

Above patch is really just repeating this test.

>> + goto failed_mount;
>> + }
>> +
>> brelse(bh);
>>
>
> How about just keeping bellowed lines ? Reporting bad block size number is the behavior how Ext3 and Ext4 do.
>
>> if (!sb_set_blocksize(sb, blocksize)) {
>> - ext2_msg(sb, KERN_ERR, "error: blocksize is too small");
>> + ext2_msg(sb, KERN_ERR,
>> + "error: bad blocksize %d", blocksize);
>> goto failed_sbi;
>> }

Agreed, this change makes it consistent with ext3, and I think that it is enough.

Thanks,
-Eric