linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs: clean up f2fs_may_encrypt()
@ 2020-03-20 10:18 Chao Yu
  2020-03-20 19:07 ` Eric Biggers
  0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu @ 2020-03-20 10:18 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel, linux-kernel, chao, Chao Yu

Merge below two conditions into f2fs_may_encrypt() for cleanup
- IS_ENCRYPTED()
- DUMMY_ENCRYPTION_ENABLED()

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fs/f2fs/dir.c   |  4 +---
 fs/f2fs/f2fs.h  | 13 +++++++++----
 fs/f2fs/namei.c |  4 +---
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 0971ccc4664a..2accfc5e38d0 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -471,7 +471,6 @@ struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
 			struct page *dpage)
 {
 	struct page *page;
-	int dummy_encrypt = DUMMY_ENCRYPTION_ENABLED(F2FS_I_SB(dir));
 	int err;
 
 	if (is_inode_flag_set(inode, FI_NEW_INODE)) {
@@ -498,8 +497,7 @@ struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
 		if (err)
 			goto put_error;
 
-		if ((IS_ENCRYPTED(dir) || dummy_encrypt) &&
-					f2fs_may_encrypt(inode)) {
+		if (f2fs_may_encrypt(dir, inode)) {
 			err = fscrypt_inherit_context(dir, inode, page, false);
 			if (err)
 				goto put_error;
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 09db79a20f8e..fcafa68212eb 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -3946,15 +3946,20 @@ static inline bool f2fs_lfs_mode(struct f2fs_sb_info *sbi)
 	return F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS;
 }
 
-static inline bool f2fs_may_encrypt(struct inode *inode)
+static inline bool f2fs_may_encrypt(struct inode *dir, struct inode *inode)
 {
 #ifdef CONFIG_FS_ENCRYPTION
+	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
 	umode_t mode = inode->i_mode;
 
-	return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
-#else
-	return false;
+	/*
+	 * If the directory encrypted or dummy encryption enabled,
+	 * then we should encrypt the inode.
+	 */
+	if (IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi))
+		return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
 #endif
+	return false;
 }
 
 static inline bool f2fs_may_compress(struct inode *inode)
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index b75c70813f9e..95cfbce062e8 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -75,9 +75,7 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
 
 	set_inode_flag(inode, FI_NEW_INODE);
 
-	/* If the directory encrypted, then we should encrypt the inode. */
-	if ((IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) &&
-				f2fs_may_encrypt(inode))
+	if (f2fs_may_encrypt(dir, inode))
 		f2fs_set_encrypted_inode(inode);
 
 	if (f2fs_sb_has_extra_attr(sbi)) {
-- 
2.18.0.rc1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] f2fs: clean up f2fs_may_encrypt()
  2020-03-20 10:18 [PATCH] f2fs: clean up f2fs_may_encrypt() Chao Yu
@ 2020-03-20 19:07 ` Eric Biggers
  2020-03-21 12:13   ` [f2fs-dev] " Chao Yu
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Biggers @ 2020-03-20 19:07 UTC (permalink / raw)
  To: Chao Yu; +Cc: jaegeuk, linux-kernel, linux-f2fs-devel

On Fri, Mar 20, 2020 at 06:18:31PM +0800, Chao Yu wrote:
> Merge below two conditions into f2fs_may_encrypt() for cleanup
> - IS_ENCRYPTED()
> - DUMMY_ENCRYPTION_ENABLED()
> 
> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> ---
>  fs/f2fs/dir.c   |  4 +---
>  fs/f2fs/f2fs.h  | 13 +++++++++----
>  fs/f2fs/namei.c |  4 +---
>  3 files changed, 11 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
> index 0971ccc4664a..2accfc5e38d0 100644
> --- a/fs/f2fs/dir.c
> +++ b/fs/f2fs/dir.c
> @@ -471,7 +471,6 @@ struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
>  			struct page *dpage)
>  {
>  	struct page *page;
> -	int dummy_encrypt = DUMMY_ENCRYPTION_ENABLED(F2FS_I_SB(dir));
>  	int err;
>  
>  	if (is_inode_flag_set(inode, FI_NEW_INODE)) {
> @@ -498,8 +497,7 @@ struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
>  		if (err)
>  			goto put_error;
>  
> -		if ((IS_ENCRYPTED(dir) || dummy_encrypt) &&
> -					f2fs_may_encrypt(inode)) {
> +		if (f2fs_may_encrypt(dir, inode)) {
>  			err = fscrypt_inherit_context(dir, inode, page, false);
>  			if (err)
>  				goto put_error;
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 09db79a20f8e..fcafa68212eb 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -3946,15 +3946,20 @@ static inline bool f2fs_lfs_mode(struct f2fs_sb_info *sbi)
>  	return F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS;
>  }
>  
> -static inline bool f2fs_may_encrypt(struct inode *inode)
> +static inline bool f2fs_may_encrypt(struct inode *dir, struct inode *inode)
>  {
>  #ifdef CONFIG_FS_ENCRYPTION
> +	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
>  	umode_t mode = inode->i_mode;
>  
> -	return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
> -#else
> -	return false;
> +	/*
> +	 * If the directory encrypted or dummy encryption enabled,
> +	 * then we should encrypt the inode.
> +	 */
> +	if (IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi))
> +		return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
>  #endif
> +	return false;
>  }
>  
>  static inline bool f2fs_may_compress(struct inode *inode)
> diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
> index b75c70813f9e..95cfbce062e8 100644
> --- a/fs/f2fs/namei.c
> +++ b/fs/f2fs/namei.c
> @@ -75,9 +75,7 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
>  
>  	set_inode_flag(inode, FI_NEW_INODE);
>  
> -	/* If the directory encrypted, then we should encrypt the inode. */
> -	if ((IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) &&
> -				f2fs_may_encrypt(inode))
> +	if (f2fs_may_encrypt(dir, inode))
>  		f2fs_set_encrypted_inode(inode);
>  
>  	if (f2fs_sb_has_extra_attr(sbi)) {
> -- 

Can't f2fs_init_inode_metadata() just check IS_ENCRYPTED(inode) instead?
(inode, not dir.)  The encrypt flag was already set by f2fs_new_inode(), right?

If so, then f2fs_may_encrypt() would only have one caller and it could be
inlined into f2fs_new_inode(), similar to __ext4_new_inode().

- Eric

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs: clean up f2fs_may_encrypt()
  2020-03-20 19:07 ` Eric Biggers
@ 2020-03-21 12:13   ` Chao Yu
  0 siblings, 0 replies; 3+ messages in thread
From: Chao Yu @ 2020-03-21 12:13 UTC (permalink / raw)
  To: Eric Biggers, Chao Yu; +Cc: jaegeuk, linux-kernel, linux-f2fs-devel

On 2020-3-21 3:07, Eric Biggers wrote:
> On Fri, Mar 20, 2020 at 06:18:31PM +0800, Chao Yu wrote:
>> Merge below two conditions into f2fs_may_encrypt() for cleanup
>> - IS_ENCRYPTED()
>> - DUMMY_ENCRYPTION_ENABLED()
>>
>> Signed-off-by: Chao Yu <yuchao0@huawei.com>
>> ---
>>  fs/f2fs/dir.c   |  4 +---
>>  fs/f2fs/f2fs.h  | 13 +++++++++----
>>  fs/f2fs/namei.c |  4 +---
>>  3 files changed, 11 insertions(+), 10 deletions(-)
>>
>> diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
>> index 0971ccc4664a..2accfc5e38d0 100644
>> --- a/fs/f2fs/dir.c
>> +++ b/fs/f2fs/dir.c
>> @@ -471,7 +471,6 @@ struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
>>  			struct page *dpage)
>>  {
>>  	struct page *page;
>> -	int dummy_encrypt = DUMMY_ENCRYPTION_ENABLED(F2FS_I_SB(dir));
>>  	int err;
>>
>>  	if (is_inode_flag_set(inode, FI_NEW_INODE)) {
>> @@ -498,8 +497,7 @@ struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
>>  		if (err)
>>  			goto put_error;
>>
>> -		if ((IS_ENCRYPTED(dir) || dummy_encrypt) &&
>> -					f2fs_may_encrypt(inode)) {
>> +		if (f2fs_may_encrypt(dir, inode)) {
>>  			err = fscrypt_inherit_context(dir, inode, page, false);
>>  			if (err)
>>  				goto put_error;
>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>> index 09db79a20f8e..fcafa68212eb 100644
>> --- a/fs/f2fs/f2fs.h
>> +++ b/fs/f2fs/f2fs.h
>> @@ -3946,15 +3946,20 @@ static inline bool f2fs_lfs_mode(struct f2fs_sb_info *sbi)
>>  	return F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS;
>>  }
>>
>> -static inline bool f2fs_may_encrypt(struct inode *inode)
>> +static inline bool f2fs_may_encrypt(struct inode *dir, struct inode *inode)
>>  {
>>  #ifdef CONFIG_FS_ENCRYPTION
>> +	struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
>>  	umode_t mode = inode->i_mode;
>>
>> -	return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
>> -#else
>> -	return false;
>> +	/*
>> +	 * If the directory encrypted or dummy encryption enabled,
>> +	 * then we should encrypt the inode.
>> +	 */
>> +	if (IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi))
>> +		return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
>>  #endif
>> +	return false;
>>  }
>>
>>  static inline bool f2fs_may_compress(struct inode *inode)
>> diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
>> index b75c70813f9e..95cfbce062e8 100644
>> --- a/fs/f2fs/namei.c
>> +++ b/fs/f2fs/namei.c
>> @@ -75,9 +75,7 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
>>
>>  	set_inode_flag(inode, FI_NEW_INODE);
>>
>> -	/* If the directory encrypted, then we should encrypt the inode. */
>> -	if ((IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) &&
>> -				f2fs_may_encrypt(inode))
>> +	if (f2fs_may_encrypt(dir, inode))
>>  		f2fs_set_encrypted_inode(inode);
>>
>>  	if (f2fs_sb_has_extra_attr(sbi)) {
>> --
>
> Can't f2fs_init_inode_metadata() just check IS_ENCRYPTED(inode) instead?
> (inode, not dir.)  The encrypt flag was already set by f2fs_new_inode(), right?

Correct, I've updated the patch.

Thanks,

>
> If so, then f2fs_may_encrypt() would only have one caller and it could be
> inlined into f2fs_new_inode(), similar to __ext4_new_inode().
>
> - Eric
>
>
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-21 12:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-20 10:18 [PATCH] f2fs: clean up f2fs_may_encrypt() Chao Yu
2020-03-20 19:07 ` Eric Biggers
2020-03-21 12:13   ` [f2fs-dev] " Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).