diff mbox series

[-next] ext4: Fix remount with 'abort' option isn't effective

Message ID 20211221123214.2410593-1-yebin10@huawei.com
State Superseded
Headers show
Series [-next] ext4: Fix remount with 'abort' option isn't effective | expand

Commit Message

yebin (H) Dec. 21, 2021, 12:32 p.m. UTC
We test remount with 'abort' option as follows:
[root@localhost home]# mount  /dev/sda test
[root@localhost home]# mount | grep test
/dev/sda on /home/test type ext4 (rw,relatime)
[root@localhost home]# mount -o remount,abort test
[root@localhost home]# mount | grep test
/dev/sda on /home/test type ext4 (rw,relatime)

Obviously, remount 'abort' option isn't effective.
After 6e47a3cc68fc commit we process abort option with 'ctx_set_mount_flags':
static inline void ctx_set_mount_flags(struct ext4_fs_context *ctx, int flag)
{
	ctx->mask_s_mount_flags |= flag;
	ctx->vals_s_mount_flags |= flag;
}

But we test 'abort' option with 'ext4_test_mount_flag':
static inline int ext4_test_mount_flag(struct super_block *sb, int bit)
{
        return test_bit(bit, &EXT4_SB(sb)->s_mount_flags);
}

To solve this issue, pass (1 <<  EXT4_MF_FS_ABORTED) to 'ctx_set_mount_flags'.

Fixes:6e47a3cc68fc("ext4: get rid of super block and sbi from handle_mount_ops()")
Signed-off-by: Ye Bin <yebin10@huawei.com>
---
 fs/ext4/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Lukas Czerner Dec. 21, 2021, 2:43 p.m. UTC | #1
Hi,

nice catch. This is a bug indeed. However I am currently in a process of
changing the ctx_set/clear/test_ helpers because currently it generates
functions that are unused.

While I am at it I can just create a custom ctx_set_mount_flags()
helper that would behave as expected so that we won't have to specify
"1 < EXT4_MF_FS_ABORTED" which is not really obvious and hence error
prone.

My plan is to send my patch set including this one tomorrow, will that
be fine with you ?

-Lukas

On Tue, Dec 21, 2021 at 08:32:14PM +0800, Ye Bin wrote:
> We test remount with 'abort' option as follows:
> [root@localhost home]# mount  /dev/sda test
> [root@localhost home]# mount | grep test
> /dev/sda on /home/test type ext4 (rw,relatime)
> [root@localhost home]# mount -o remount,abort test
> [root@localhost home]# mount | grep test
> /dev/sda on /home/test type ext4 (rw,relatime)
> 
> Obviously, remount 'abort' option isn't effective.
> After 6e47a3cc68fc commit we process abort option with 'ctx_set_mount_flags':
> static inline void ctx_set_mount_flags(struct ext4_fs_context *ctx, int flag)
> {
> 	ctx->mask_s_mount_flags |= flag;
> 	ctx->vals_s_mount_flags |= flag;
> }
> 
> But we test 'abort' option with 'ext4_test_mount_flag':
> static inline int ext4_test_mount_flag(struct super_block *sb, int bit)
> {
>         return test_bit(bit, &EXT4_SB(sb)->s_mount_flags);
> }
> 
> To solve this issue, pass (1 <<  EXT4_MF_FS_ABORTED) to 'ctx_set_mount_flags'.
> 
> Fixes:6e47a3cc68fc("ext4: get rid of super block and sbi from handle_mount_ops()")
> Signed-off-by: Ye Bin <yebin10@huawei.com>
> ---
>  fs/ext4/super.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index b72d989b77fb..071b7b3c5678 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -2236,7 +2236,7 @@ static int ext4_parse_param(struct fs_context *fc, struct fs_parameter *param)
>  			 param->key);
>  		return 0;
>  	case Opt_abort:
> -		ctx_set_mount_flags(ctx, EXT4_MF_FS_ABORTED);
> +		ctx_set_mount_flags(ctx, 1 << EXT4_MF_FS_ABORTED);
>  		return 0;
>  	case Opt_i_version:
>  		ctx_set_flags(ctx, SB_I_VERSION);
> -- 
> 2.31.1
>
yebin (H) Dec. 22, 2021, 1:06 a.m. UTC | #2
On 2021/12/21 22:43, Lukas Czerner wrote:
> Hi,
>
> nice catch. This is a bug indeed. However I am currently in a process of
> changing the ctx_set/clear/test_ helpers because currently it generates
> functions that are unused.
>
> While I am at it I can just create a custom ctx_set_mount_flags()
> helper that would behave as expected so that we won't have to specify
> "1 < EXT4_MF_FS_ABORTED" which is not really obvious and hence error
> prone.
Actually, I fixed the first version as follows:

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index b72d989b77fb..199920ffc7d3 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2049,8 +2049,8 @@ struct ext4_fs_context {
  	unsigned int	mask_s_mount_opt;
  	unsigned int	vals_s_mount_opt2;
  	unsigned int	mask_s_mount_opt2;
-	unsigned int	vals_s_mount_flags;
-	unsigned int	mask_s_mount_flags;
+	unsigned long	vals_s_mount_flags;
+	unsigned long	mask_s_mount_flags;
  	unsigned int	opt_flags;	/* MOPT flags */
  	unsigned int	spec;
  	u32		s_max_batch_time;
@@ -2166,7 +2166,12 @@ static inline bool ctx_test_##name(struct ext4_fs_context *ctx, int flag)\
  EXT4_SET_CTX(flags);
  EXT4_SET_CTX(mount_opt);
  EXT4_SET_CTX(mount_opt2);
-EXT4_SET_CTX(mount_flags);
+
+static inline void ctx_set_mount_flags(struct ext4_fs_context *ctx, int bit)
+{
+	set_bit(bit, &ctx->mask_s_mount_flags);
+	set_bit(bit, &ctx->vals_s_mount_flags);
+}


I think 'mask_s_mount_flags' is useless now.
>
> My plan is to send my patch set including this one tomorrow, will that
> be fine with you ?
>
> -Lukas
>
> On Tue, Dec 21, 2021 at 08:32:14PM +0800, Ye Bin wrote:
>> We test remount with 'abort' option as follows:
>> [root@localhost home]# mount  /dev/sda test
>> [root@localhost home]# mount | grep test
>> /dev/sda on /home/test type ext4 (rw,relatime)
>> [root@localhost home]# mount -o remount,abort test
>> [root@localhost home]# mount | grep test
>> /dev/sda on /home/test type ext4 (rw,relatime)
>>
>> Obviously, remount 'abort' option isn't effective.
>> After 6e47a3cc68fc commit we process abort option with 'ctx_set_mount_flags':
>> static inline void ctx_set_mount_flags(struct ext4_fs_context *ctx, int flag)
>> {
>> 	ctx->mask_s_mount_flags |= flag;
>> 	ctx->vals_s_mount_flags |= flag;
>> }
>>
>> But we test 'abort' option with 'ext4_test_mount_flag':
>> static inline int ext4_test_mount_flag(struct super_block *sb, int bit)
>> {
>>          return test_bit(bit, &EXT4_SB(sb)->s_mount_flags);
>> }
>>
>> To solve this issue, pass (1 <<  EXT4_MF_FS_ABORTED) to 'ctx_set_mount_flags'.
>>
>> Fixes:6e47a3cc68fc("ext4: get rid of super block and sbi from handle_mount_ops()")
>> Signed-off-by: Ye Bin <yebin10@huawei.com>
>> ---
>>   fs/ext4/super.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
>> index b72d989b77fb..071b7b3c5678 100644
>> --- a/fs/ext4/super.c
>> +++ b/fs/ext4/super.c
>> @@ -2236,7 +2236,7 @@ static int ext4_parse_param(struct fs_context *fc, struct fs_parameter *param)
>>   			 param->key);
>>   		return 0;
>>   	case Opt_abort:
>> -		ctx_set_mount_flags(ctx, EXT4_MF_FS_ABORTED);
>> +		ctx_set_mount_flags(ctx, 1 << EXT4_MF_FS_ABORTED);
>>   		return 0;
>>   	case Opt_i_version:
>>   		ctx_set_flags(ctx, SB_I_VERSION);
>> -- 
>> 2.31.1
>>
> .
>
Lukas Czerner Dec. 22, 2021, 9:19 a.m. UTC | #3
On Wed, Dec 22, 2021 at 09:06:22AM +0800, yebin wrote:
> 
> 
> On 2021/12/21 22:43, Lukas Czerner wrote:
> > Hi,
> > 
> > nice catch. This is a bug indeed. However I am currently in a process of
> > changing the ctx_set/clear/test_ helpers because currently it generates
> > functions that are unused.
> > 
> > While I am at it I can just create a custom ctx_set_mount_flags()
> > helper that would behave as expected so that we won't have to specify
> > "1 < EXT4_MF_FS_ABORTED" which is not really obvious and hence error
> > prone.
> Actually, I fixed the first version as follows:

Allright, this looks better.

> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index b72d989b77fb..199920ffc7d3 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -2049,8 +2049,8 @@ struct ext4_fs_context {
>  	unsigned int	mask_s_mount_opt;
>  	unsigned int	vals_s_mount_opt2;
>  	unsigned int	mask_s_mount_opt2;
> -	unsigned int	vals_s_mount_flags;
> -	unsigned int	mask_s_mount_flags;
> +	unsigned long	vals_s_mount_flags;
> +	unsigned long	mask_s_mount_flags;
>  	unsigned int	opt_flags;	/* MOPT flags */
>  	unsigned int	spec;
>  	u32		s_max_batch_time;
> @@ -2166,7 +2166,12 @@ static inline bool ctx_test_##name(struct ext4_fs_context *ctx, int flag)\
>  EXT4_SET_CTX(flags);
>  EXT4_SET_CTX(mount_opt);
>  EXT4_SET_CTX(mount_opt2);
> -EXT4_SET_CTX(mount_flags);
> +
> +static inline void ctx_set_mount_flags(struct ext4_fs_context *ctx, int bit)

Maybe ctx_set_mount_flag since you can't really set more than one this
way?

> +{
> +	set_bit(bit, &ctx->mask_s_mount_flags);
> +	set_bit(bit, &ctx->vals_s_mount_flags);
> +}
> 
> 
> I think 'mask_s_mount_flags' is useless now.

So how would we know what flags have changed ? Sure, there is currently
no need to clear the flag but that can come in future and once it does
we'll only need to create a clear helper, the rest will be ready.
I'd rather keep it.

-Lukas

> > 
> > My plan is to send my patch set including this one tomorrow, will that
> > be fine with you ?
> > 
> > -Lukas
> > 
> > On Tue, Dec 21, 2021 at 08:32:14PM +0800, Ye Bin wrote:
> > > We test remount with 'abort' option as follows:
> > > [root@localhost home]# mount  /dev/sda test
> > > [root@localhost home]# mount | grep test
> > > /dev/sda on /home/test type ext4 (rw,relatime)
> > > [root@localhost home]# mount -o remount,abort test
> > > [root@localhost home]# mount | grep test
> > > /dev/sda on /home/test type ext4 (rw,relatime)
> > > 
> > > Obviously, remount 'abort' option isn't effective.
> > > After 6e47a3cc68fc commit we process abort option with 'ctx_set_mount_flags':
> > > static inline void ctx_set_mount_flags(struct ext4_fs_context *ctx, int flag)
> > > {
> > > 	ctx->mask_s_mount_flags |= flag;
> > > 	ctx->vals_s_mount_flags |= flag;
> > > }
> > > 
> > > But we test 'abort' option with 'ext4_test_mount_flag':
> > > static inline int ext4_test_mount_flag(struct super_block *sb, int bit)
> > > {
> > >          return test_bit(bit, &EXT4_SB(sb)->s_mount_flags);
> > > }
> > > 
> > > To solve this issue, pass (1 <<  EXT4_MF_FS_ABORTED) to 'ctx_set_mount_flags'.
> > > 
> > > Fixes:6e47a3cc68fc("ext4: get rid of super block and sbi from handle_mount_ops()")
> > > Signed-off-by: Ye Bin <yebin10@huawei.com>
> > > ---
> > >   fs/ext4/super.c | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> > > index b72d989b77fb..071b7b3c5678 100644
> > > --- a/fs/ext4/super.c
> > > +++ b/fs/ext4/super.c
> > > @@ -2236,7 +2236,7 @@ static int ext4_parse_param(struct fs_context *fc, struct fs_parameter *param)
> > >   			 param->key);
> > >   		return 0;
> > >   	case Opt_abort:
> > > -		ctx_set_mount_flags(ctx, EXT4_MF_FS_ABORTED);
> > > +		ctx_set_mount_flags(ctx, 1 << EXT4_MF_FS_ABORTED);
> > >   		return 0;
> > >   	case Opt_i_version:
> > >   		ctx_set_flags(ctx, SB_I_VERSION);
> > > -- 
> > > 2.31.1
> > > 
> > .
> > 
>
yebin (H) Dec. 23, 2021, 1:41 a.m. UTC | #4
On 2021/12/22 17:19, Lukas Czerner wrote:
> On Wed, Dec 22, 2021 at 09:06:22AM +0800, yebin wrote:
>>
>> On 2021/12/21 22:43, Lukas Czerner wrote:
>>> Hi,
>>>
>>> nice catch. This is a bug indeed. However I am currently in a process of
>>> changing the ctx_set/clear/test_ helpers because currently it generates
>>> functions that are unused.
>>>
>>> While I am at it I can just create a custom ctx_set_mount_flags()
>>> helper that would behave as expected so that we won't have to specify
>>> "1 < EXT4_MF_FS_ABORTED" which is not really obvious and hence error
>>> prone.
>> Actually, I fixed the first version as follows:
> Allright, this looks better.
>
>> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
>> index b72d989b77fb..199920ffc7d3 100644
>> --- a/fs/ext4/super.c
>> +++ b/fs/ext4/super.c
>> @@ -2049,8 +2049,8 @@ struct ext4_fs_context {
>>   	unsigned int	mask_s_mount_opt;
>>   	unsigned int	vals_s_mount_opt2;
>>   	unsigned int	mask_s_mount_opt2;
>> -	unsigned int	vals_s_mount_flags;
>> -	unsigned int	mask_s_mount_flags;
>> +	unsigned long	vals_s_mount_flags;
>> +	unsigned long	mask_s_mount_flags;
>>   	unsigned int	opt_flags;	/* MOPT flags */
>>   	unsigned int	spec;
>>   	u32		s_max_batch_time;
>> @@ -2166,7 +2166,12 @@ static inline bool ctx_test_##name(struct ext4_fs_context *ctx, int flag)\
>>   EXT4_SET_CTX(flags);
>>   EXT4_SET_CTX(mount_opt);
>>   EXT4_SET_CTX(mount_opt2);
>> -EXT4_SET_CTX(mount_flags);
>> +
>> +static inline void ctx_set_mount_flags(struct ext4_fs_context *ctx, int bit)
> Maybe ctx_set_mount_flag since you can't really set more than one this
> way?
So I think it's a little inappropriate to use the current repair scheme.
>> +{
>> +	set_bit(bit, &ctx->mask_s_mount_flags);
>> +	set_bit(bit, &ctx->vals_s_mount_flags);
>> +}
>>
>>
>> I think 'mask_s_mount_flags' is useless now.
> So how would we know what flags have changed ? Sure, there is currently
> no need to clear the flag but that can come in future and once it does
> we'll only need to create a clear helper, the rest will be ready.
> I'd rather keep it.
>
> -Lukas
 From this point of view, I agree with you.
>>> My plan is to send my patch set including this one tomorrow, will that
>>> be fine with you ?
>>>
>>> -Lukas
>>>
>>> On Tue, Dec 21, 2021 at 08:32:14PM +0800, Ye Bin wrote:
>>>> We test remount with 'abort' option as follows:
>>>> [root@localhost home]# mount  /dev/sda test
>>>> [root@localhost home]# mount | grep test
>>>> /dev/sda on /home/test type ext4 (rw,relatime)
>>>> [root@localhost home]# mount -o remount,abort test
>>>> [root@localhost home]# mount | grep test
>>>> /dev/sda on /home/test type ext4 (rw,relatime)
>>>>
>>>> Obviously, remount 'abort' option isn't effective.
>>>> After 6e47a3cc68fc commit we process abort option with 'ctx_set_mount_flags':
>>>> static inline void ctx_set_mount_flags(struct ext4_fs_context *ctx, int flag)
>>>> {
>>>> 	ctx->mask_s_mount_flags |= flag;
>>>> 	ctx->vals_s_mount_flags |= flag;
>>>> }
>>>>
>>>> But we test 'abort' option with 'ext4_test_mount_flag':
>>>> static inline int ext4_test_mount_flag(struct super_block *sb, int bit)
>>>> {
>>>>           return test_bit(bit, &EXT4_SB(sb)->s_mount_flags);
>>>> }
>>>>
>>>> To solve this issue, pass (1 <<  EXT4_MF_FS_ABORTED) to 'ctx_set_mount_flags'.
>>>>
>>>> Fixes:6e47a3cc68fc("ext4: get rid of super block and sbi from handle_mount_ops()")
>>>> Signed-off-by: Ye Bin <yebin10@huawei.com>
>>>> ---
>>>>    fs/ext4/super.c | 2 +-
>>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
>>>> index b72d989b77fb..071b7b3c5678 100644
>>>> --- a/fs/ext4/super.c
>>>> +++ b/fs/ext4/super.c
>>>> @@ -2236,7 +2236,7 @@ static int ext4_parse_param(struct fs_context *fc, struct fs_parameter *param)
>>>>    			 param->key);
>>>>    		return 0;
>>>>    	case Opt_abort:
>>>> -		ctx_set_mount_flags(ctx, EXT4_MF_FS_ABORTED);
>>>> +		ctx_set_mount_flags(ctx, 1 << EXT4_MF_FS_ABORTED);
>>>>    		return 0;
>>>>    	case Opt_i_version:
>>>>    		ctx_set_flags(ctx, SB_I_VERSION);
>>>> -- 
>>>> 2.31.1
>>>>
>>> .
>>>
> .
>
Theodore Ts'o Dec. 23, 2021, 3:41 p.m. UTC | #5
On Thu, Dec 23, 2021 at 09:41:31AM +0800, yebin wrote:
> 
> On 2021/12/22 17:19, Lukas Czerner wrote:
> > On Wed, Dec 22, 2021 at 09:06:22AM +0800, yebin wrote:
> > > 
> > > On 2021/12/21 22:43, Lukas Czerner wrote:
> > > > Hi,
> > > > 
> > > > nice catch. This is a bug indeed. However I am currently in a process of
> > > > changing the ctx_set/clear/test_ helpers because currently it generates
> > > > functions that are unused.
> > > > 
> > > > While I am at it I can just create a custom ctx_set_mount_flags()
> > > > helper that would behave as expected so that we won't have to specify
> > > > "1 < EXT4_MF_FS_ABORTED" which is not really obvious and hence error
> > > > prone.
> > > Actually, I fixed the first version as follows:
> > Allright, this looks better.

Was there an update to this patch?  I can't seem to find it in my
inbox or in patchwork....

Thanks,

					- Ted
diff mbox series

Patch

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index b72d989b77fb..071b7b3c5678 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2236,7 +2236,7 @@  static int ext4_parse_param(struct fs_context *fc, struct fs_parameter *param)
 			 param->key);
 		return 0;
 	case Opt_abort:
-		ctx_set_mount_flags(ctx, EXT4_MF_FS_ABORTED);
+		ctx_set_mount_flags(ctx, 1 << EXT4_MF_FS_ABORTED);
 		return 0;
 	case Opt_i_version:
 		ctx_set_flags(ctx, SB_I_VERSION);