diff mbox series

[v2,07/13] ext4: factor out ext4_encoding_init()

Message ID 20220903030156.770313-8-yanaijie@huawei.com
State Superseded
Headers show
Series some refactor of __ext4_fill_super() | expand

Commit Message

Jason Yan Sept. 3, 2022, 3:01 a.m. UTC
Factor out ext4_encoding_init(). No functional change.

Signed-off-by: Jason Yan <yanaijie@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/super.c | 80 +++++++++++++++++++++++++++----------------------
 1 file changed, 44 insertions(+), 36 deletions(-)

Comments

Ritesh Harjani (IBM) Sept. 8, 2022, 8:56 a.m. UTC | #1
On 22/09/03 11:01AM, Jason Yan wrote:
> Factor out ext4_encoding_init(). No functional change.
> 
> Signed-off-by: Jason Yan <yanaijie@huawei.com>
> Reviewed-by: Jan Kara <jack@suse.cz>
> ---
>  fs/ext4/super.c | 80 +++++++++++++++++++++++++++----------------------
>  1 file changed, 44 insertions(+), 36 deletions(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index f8806226b796..67972b0218c0 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -4521,6 +4521,48 @@ static int ext4_inode_info_init(struct super_block *sb,
>  	return 0;
>  }
>  
> +static int ext4_encoding_init(struct super_block *sb, struct ext4_super_block *es)
> +{
> +#if IS_ENABLED(CONFIG_UNICODE)

How about simplying it like below.
		if (!IS_ENABLED(CONFIG_UNICODE))
			return 0;
	
		<...>	

Then we don't need #ifdef CONFIG_UNICODE

-ritesh

> +	const struct ext4_sb_encodings *encoding_info;
> +	struct unicode_map *encoding;
> +	__u16 encoding_flags = le16_to_cpu(es->s_encoding_flags);
> +
> +	if (!ext4_has_feature_casefold(sb) || sb->s_encoding)
> +		return 0;
> +
> +	encoding_info = ext4_sb_read_encoding(es);
> +	if (!encoding_info) {
> +		ext4_msg(sb, KERN_ERR,
> +			"Encoding requested by superblock is unknown");
> +		return -EINVAL;
> +	}
> +
> +	encoding = utf8_load(encoding_info->version);
> +	if (IS_ERR(encoding)) {
> +		ext4_msg(sb, KERN_ERR,
> +			"can't mount with superblock charset: %s-%u.%u.%u "
> +			"not supported by the kernel. flags: 0x%x.",
> +			encoding_info->name,
> +			unicode_major(encoding_info->version),
> +			unicode_minor(encoding_info->version),
> +			unicode_rev(encoding_info->version),
> +			encoding_flags);
> +		return -EINVAL;
> +	}
> +	ext4_msg(sb, KERN_INFO,"Using encoding defined by superblock: "
> +		"%s-%u.%u.%u with flags 0x%hx", encoding_info->name,
> +		unicode_major(encoding_info->version),
> +		unicode_minor(encoding_info->version),
> +		unicode_rev(encoding_info->version),
> +		encoding_flags);
> +
> +	sb->s_encoding = encoding;
> +	sb->s_encoding_flags = encoding_flags;
> +#endif
> +	return 0;
> +}
> +
>  static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
>  {
>  	struct buffer_head *bh, **group_desc;
> @@ -4678,42 +4720,8 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
>  
>  	ext4_apply_options(fc, sb);
>  
> -#if IS_ENABLED(CONFIG_UNICODE)
> -	if (ext4_has_feature_casefold(sb) && !sb->s_encoding) {
> -		const struct ext4_sb_encodings *encoding_info;
> -		struct unicode_map *encoding;
> -		__u16 encoding_flags = le16_to_cpu(es->s_encoding_flags);
> -
> -		encoding_info = ext4_sb_read_encoding(es);
> -		if (!encoding_info) {
> -			ext4_msg(sb, KERN_ERR,
> -				 "Encoding requested by superblock is unknown");
> -			goto failed_mount;
> -		}
> -
> -		encoding = utf8_load(encoding_info->version);
> -		if (IS_ERR(encoding)) {
> -			ext4_msg(sb, KERN_ERR,
> -				 "can't mount with superblock charset: %s-%u.%u.%u "
> -				 "not supported by the kernel. flags: 0x%x.",
> -				 encoding_info->name,
> -				 unicode_major(encoding_info->version),
> -				 unicode_minor(encoding_info->version),
> -				 unicode_rev(encoding_info->version),
> -				 encoding_flags);
> -			goto failed_mount;
> -		}
> -		ext4_msg(sb, KERN_INFO,"Using encoding defined by superblock: "
> -			 "%s-%u.%u.%u with flags 0x%hx", encoding_info->name,
> -			 unicode_major(encoding_info->version),
> -			 unicode_minor(encoding_info->version),
> -			 unicode_rev(encoding_info->version),
> -			 encoding_flags);
> -
> -		sb->s_encoding = encoding;
> -		sb->s_encoding_flags = encoding_flags;
> -	}
> -#endif
> +	if (ext4_encoding_init(sb, es))
> +		goto failed_mount;
>  
>  	if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
>  		printk_once(KERN_WARNING "EXT4-fs: Warning: mounting with data=journal disables delayed allocation, dioread_nolock, O_DIRECT and fast_commit support!\n");
> -- 
> 2.31.1
>
Jason Yan Sept. 12, 2022, 2:30 a.m. UTC | #2
On 2022/9/8 16:56, Ritesh Harjani (IBM) wrote:
> On 22/09/03 11:01AM, Jason Yan wrote:
>> Factor out ext4_encoding_init(). No functional change.
>>
>> Signed-off-by: Jason Yan <yanaijie@huawei.com>
>> Reviewed-by: Jan Kara <jack@suse.cz>
>> ---
>>   fs/ext4/super.c | 80 +++++++++++++++++++++++++++----------------------
>>   1 file changed, 44 insertions(+), 36 deletions(-)
>>
>> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
>> index f8806226b796..67972b0218c0 100644
>> --- a/fs/ext4/super.c
>> +++ b/fs/ext4/super.c
>> @@ -4521,6 +4521,48 @@ static int ext4_inode_info_init(struct super_block *sb,
>>   	return 0;
>>   }
>>   
>> +static int ext4_encoding_init(struct super_block *sb, struct ext4_super_block *es)
>> +{
>> +#if IS_ENABLED(CONFIG_UNICODE)
> 
> How about simplying it like below.
> 		if (!IS_ENABLED(CONFIG_UNICODE))
> 			return 0;
> 	
> 		<...>	
> 
> Then we don't need #ifdef CONFIG_UNICODE
> 

Nice idea. Will update.

Thanks
Jason
Jason Yan Sept. 12, 2022, 3:12 a.m. UTC | #3
On 2022/9/12 10:30, Jason Yan wrote:
> 
> On 2022/9/8 16:56, Ritesh Harjani (IBM) wrote:
>> On 22/09/03 11:01AM, Jason Yan wrote:
>>> Factor out ext4_encoding_init(). No functional change.
>>>
>>> Signed-off-by: Jason Yan <yanaijie@huawei.com>
>>> Reviewed-by: Jan Kara <jack@suse.cz>
>>> ---
>>>   fs/ext4/super.c | 80 +++++++++++++++++++++++++++----------------------
>>>   1 file changed, 44 insertions(+), 36 deletions(-)
>>>
>>> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
>>> index f8806226b796..67972b0218c0 100644
>>> --- a/fs/ext4/super.c
>>> +++ b/fs/ext4/super.c
>>> @@ -4521,6 +4521,48 @@ static int ext4_inode_info_init(struct 
>>> super_block *sb,
>>>       return 0;
>>>   }
>>> +static int ext4_encoding_init(struct super_block *sb, struct 
>>> ext4_super_block *es)
>>> +{
>>> +#if IS_ENABLED(CONFIG_UNICODE)
>>
>> How about simplying it like below.
>>         if (!IS_ENABLED(CONFIG_UNICODE))
>>             return 0;
>>
>>         <...>
>>
>> Then we don't need #ifdef CONFIG_UNICODE
>>
> 
> Nice idea. Will update.
> 

Sorry I tried to compile with this change but the compiler is not clever 
enough to ignore the code down if CONFIG_UNICODE is not enabled.


fs/ext4/super.c: In function ‘ext4_encoding_init’:
fs/ext4/super.c:4529:2: warning: ISO C90 forbids mixed declarations and 
code [-Wdeclaration-after-statement]
  4529 |  const struct ext4_sb_encodings *encoding_info;
       |  ^~~~~
fs/ext4/super.c:4533:42: error: ‘struct super_block’ has no member named 
‘s_encoding’
  4533 |  if (!ext4_has_feature_casefold(sb) || sb->s_encoding)
       |                                          ^~
fs/ext4/super.c:4536:18: error: implicit declaration of function 
‘ext4_sb_read_encoding’; did you mean ‘ext4_sb_bread_unmovable’? 
[-Werror=implicit-function-declaration]
  4536 |  encoding_info = ext4_sb_read_encoding(es);
       |                  ^~~~~~~~~~~~~~~~~~~~~
       |                  ext4_sb_bread_unmovable
fs/ext4/super.c:4536:16: warning: assignment to ‘const struct 
ext4_sb_encodings *’ from ‘int’ makes pointer from integer without a 
cast [-Wint-conversion]
  4536 |  encoding_info = ext4_sb_read_encoding(es);
       |                ^
fs/ext4/super.c:4543:36: error: dereferencing pointer to incomplete type 
‘const struct ext4_sb_encodings’
  4543 |  encoding = utf8_load(encoding_info->version);
       |                                    ^~
fs/ext4/super.c:4562:4: error: ‘struct super_block’ has no member named 
‘s_encoding’
  4562 |  sb->s_encoding = encoding;
       |    ^~
fs/ext4/super.c:4563:4: error: ‘struct super_block’ has no member named 
‘s_encoding_flags’
  4563 |  sb->s_encoding_flags = encoding_flags;
       |    ^~
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:249: fs/ext4/super.o] Error 1
make[1]: *** [scripts/Makefile.build:465: fs/ext4] Error 2
make: *** [Makefile:1852: fs] Error 2




> Thanks
> Jason
> .
diff mbox series

Patch

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index f8806226b796..67972b0218c0 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -4521,6 +4521,48 @@  static int ext4_inode_info_init(struct super_block *sb,
 	return 0;
 }
 
+static int ext4_encoding_init(struct super_block *sb, struct ext4_super_block *es)
+{
+#if IS_ENABLED(CONFIG_UNICODE)
+	const struct ext4_sb_encodings *encoding_info;
+	struct unicode_map *encoding;
+	__u16 encoding_flags = le16_to_cpu(es->s_encoding_flags);
+
+	if (!ext4_has_feature_casefold(sb) || sb->s_encoding)
+		return 0;
+
+	encoding_info = ext4_sb_read_encoding(es);
+	if (!encoding_info) {
+		ext4_msg(sb, KERN_ERR,
+			"Encoding requested by superblock is unknown");
+		return -EINVAL;
+	}
+
+	encoding = utf8_load(encoding_info->version);
+	if (IS_ERR(encoding)) {
+		ext4_msg(sb, KERN_ERR,
+			"can't mount with superblock charset: %s-%u.%u.%u "
+			"not supported by the kernel. flags: 0x%x.",
+			encoding_info->name,
+			unicode_major(encoding_info->version),
+			unicode_minor(encoding_info->version),
+			unicode_rev(encoding_info->version),
+			encoding_flags);
+		return -EINVAL;
+	}
+	ext4_msg(sb, KERN_INFO,"Using encoding defined by superblock: "
+		"%s-%u.%u.%u with flags 0x%hx", encoding_info->name,
+		unicode_major(encoding_info->version),
+		unicode_minor(encoding_info->version),
+		unicode_rev(encoding_info->version),
+		encoding_flags);
+
+	sb->s_encoding = encoding;
+	sb->s_encoding_flags = encoding_flags;
+#endif
+	return 0;
+}
+
 static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
 {
 	struct buffer_head *bh, **group_desc;
@@ -4678,42 +4720,8 @@  static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
 
 	ext4_apply_options(fc, sb);
 
-#if IS_ENABLED(CONFIG_UNICODE)
-	if (ext4_has_feature_casefold(sb) && !sb->s_encoding) {
-		const struct ext4_sb_encodings *encoding_info;
-		struct unicode_map *encoding;
-		__u16 encoding_flags = le16_to_cpu(es->s_encoding_flags);
-
-		encoding_info = ext4_sb_read_encoding(es);
-		if (!encoding_info) {
-			ext4_msg(sb, KERN_ERR,
-				 "Encoding requested by superblock is unknown");
-			goto failed_mount;
-		}
-
-		encoding = utf8_load(encoding_info->version);
-		if (IS_ERR(encoding)) {
-			ext4_msg(sb, KERN_ERR,
-				 "can't mount with superblock charset: %s-%u.%u.%u "
-				 "not supported by the kernel. flags: 0x%x.",
-				 encoding_info->name,
-				 unicode_major(encoding_info->version),
-				 unicode_minor(encoding_info->version),
-				 unicode_rev(encoding_info->version),
-				 encoding_flags);
-			goto failed_mount;
-		}
-		ext4_msg(sb, KERN_INFO,"Using encoding defined by superblock: "
-			 "%s-%u.%u.%u with flags 0x%hx", encoding_info->name,
-			 unicode_major(encoding_info->version),
-			 unicode_minor(encoding_info->version),
-			 unicode_rev(encoding_info->version),
-			 encoding_flags);
-
-		sb->s_encoding = encoding;
-		sb->s_encoding_flags = encoding_flags;
-	}
-#endif
+	if (ext4_encoding_init(sb, es))
+		goto failed_mount;
 
 	if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
 		printk_once(KERN_WARNING "EXT4-fs: Warning: mounting with data=journal disables delayed allocation, dioread_nolock, O_DIRECT and fast_commit support!\n");