Skip to content

Commit 8c7d4b5

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: clean up f2fs_may_encrypt()
Merge below two conditions into f2fs_may_encrypt() for cleanup - IS_ENCRYPTED() - DUMMY_ENCRYPTION_ENABLED() Check IS_ENCRYPTED(inode) condition in f2fs_init_inode_metadata() is enough since we have already set encrypt flag in f2fs_new_inode(). Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent b13f67f commit 8c7d4b5

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

fs/f2fs/dir.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ struct page *f2fs_init_inode_metadata(struct inode *inode, struct inode *dir,
471471
struct page *dpage)
472472
{
473473
struct page *page;
474-
int dummy_encrypt = DUMMY_ENCRYPTION_ENABLED(F2FS_I_SB(dir));
475474
int err;
476475

477476
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,
498497
if (err)
499498
goto put_error;
500499

501-
if ((IS_ENCRYPTED(dir) || dummy_encrypt) &&
502-
f2fs_may_encrypt(inode)) {
500+
if (IS_ENCRYPTED(inode)) {
503501
err = fscrypt_inherit_context(dir, inode, page, false);
504502
if (err)
505503
goto put_error;

fs/f2fs/f2fs.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3935,15 +3935,20 @@ static inline bool f2fs_lfs_mode(struct f2fs_sb_info *sbi)
39353935
return F2FS_OPTION(sbi).fs_mode == FS_MODE_LFS;
39363936
}
39373937

3938-
static inline bool f2fs_may_encrypt(struct inode *inode)
3938+
static inline bool f2fs_may_encrypt(struct inode *dir, struct inode *inode)
39393939
{
39403940
#ifdef CONFIG_FS_ENCRYPTION
3941+
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
39413942
umode_t mode = inode->i_mode;
39423943

3943-
return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
3944-
#else
3945-
return false;
3944+
/*
3945+
* If the directory encrypted or dummy encryption enabled,
3946+
* then we should encrypt the inode.
3947+
*/
3948+
if (IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi))
3949+
return (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode));
39463950
#endif
3951+
return false;
39473952
}
39483953

39493954
static inline bool f2fs_may_compress(struct inode *inode)

fs/f2fs/namei.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
7575

7676
set_inode_flag(inode, FI_NEW_INODE);
7777

78-
/* If the directory encrypted, then we should encrypt the inode. */
79-
if ((IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) &&
80-
f2fs_may_encrypt(inode))
78+
if (f2fs_may_encrypt(dir, inode))
8179
f2fs_set_encrypted_inode(inode);
8280

8381
if (f2fs_sb_has_extra_attr(sbi)) {

0 commit comments

Comments
 (0)