Skip to content

Commit 592ddec

Browse files
Chandan Rajendratytso
authored andcommitted
ext4: use IS_ENCRYPTED() to check encryption status
This commit removes the ext4 specific ext4_encrypted_inode() and makes use of the generic IS_ENCRYPTED() macro to check for the encryption status of an inode. Reviewed-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com> Signed-off-by: Eric Biggers <ebiggers@google.com>
1 parent 1058ef0 commit 592ddec

10 files changed

Lines changed: 22 additions & 32 deletions

File tree

‎fs/ext4/dir.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
111111
int dir_has_error = 0;
112112
struct fscrypt_str fstr = FSTR_INIT(NULL, 0);
113113

114-
if (ext4_encrypted_inode(inode)) {
114+
if (IS_ENCRYPTED(inode)) {
115115
err = fscrypt_get_encryption_info(inode);
116116
if (err && err != -ENOKEY)
117117
return err;
@@ -138,7 +138,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
138138
return err;
139139
}
140140

141-
if (ext4_encrypted_inode(inode)) {
141+
if (IS_ENCRYPTED(inode)) {
142142
err = fscrypt_fname_alloc_buffer(inode, EXT4_NAME_LEN, &fstr);
143143
if (err < 0)
144144
return err;
@@ -245,7 +245,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
245245
offset += ext4_rec_len_from_disk(de->rec_len,
246246
sb->s_blocksize);
247247
if (le32_to_cpu(de->inode)) {
248-
if (!ext4_encrypted_inode(inode)) {
248+
if (!IS_ENCRYPTED(inode)) {
249249
if (!dir_emit(ctx, de->name,
250250
de->name_len,
251251
le32_to_cpu(de->inode),
@@ -613,7 +613,7 @@ static int ext4_dx_readdir(struct file *file, struct dir_context *ctx)
613613

614614
static int ext4_dir_open(struct inode * inode, struct file * filp)
615615
{
616-
if (ext4_encrypted_inode(inode))
616+
if (IS_ENCRYPTED(inode))
617617
return fscrypt_get_encryption_info(inode) ? -EACCES : 0;
618618
return 0;
619619
}

‎fs/ext4/ext4.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2279,11 +2279,6 @@ extern unsigned ext4_free_clusters_after_init(struct super_block *sb,
22792279
struct ext4_group_desc *gdp);
22802280
ext4_fsblk_t ext4_inode_to_goal_block(struct inode *);
22812281

2282-
static inline bool ext4_encrypted_inode(struct inode *inode)
2283-
{
2284-
return ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT);
2285-
}
2286-
22872282
#ifdef CONFIG_EXT4_FS_ENCRYPTION
22882283
static inline int ext4_fname_setup_filename(struct inode *dir,
22892284
const struct qstr *iname,

‎fs/ext4/ext4_jbd2.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ static inline int ext4_inode_journal_mode(struct inode *inode)
411411
(ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA) &&
412412
!test_opt(inode->i_sb, DELALLOC))) {
413413
/* We do not support data journalling for encrypted data */
414-
if (S_ISREG(inode->i_mode) && ext4_encrypted_inode(inode))
414+
if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode))
415415
return EXT4_INODE_ORDERED_DATA_MODE; /* ordered */
416416
return EXT4_INODE_JOURNAL_DATA_MODE; /* journal data */
417417
}

‎fs/ext4/extents.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3631,7 +3631,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
36313631
max_zeroout = sbi->s_extent_max_zeroout_kb >>
36323632
(inode->i_sb->s_blocksize_bits - 10);
36333633

3634-
if (ext4_encrypted_inode(inode))
3634+
if (IS_ENCRYPTED(inode))
36353635
max_zeroout = 0;
36363636

36373637
/*
@@ -4818,7 +4818,7 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
48184818
* leave it disabled for encrypted inodes for now. This is a
48194819
* bug we should fix....
48204820
*/
4821-
if (ext4_encrypted_inode(inode) &&
4821+
if (IS_ENCRYPTED(inode) &&
48224822
(mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE |
48234823
FALLOC_FL_ZERO_RANGE)))
48244824
return -EOPNOTSUPP;

‎fs/ext4/ialloc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
771771
if (unlikely(ext4_forced_shutdown(sbi)))
772772
return ERR_PTR(-EIO);
773773

774-
if ((ext4_encrypted_inode(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) &&
774+
if ((IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) &&
775775
(S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) &&
776776
!(i_flags & EXT4_EA_INODE_FL)) {
777777
err = fscrypt_get_encryption_info(dir);

‎fs/ext4/inode.c‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk, ext4_fsblk_t pblk,
415415
{
416416
int ret;
417417

418-
if (ext4_encrypted_inode(inode))
418+
if (IS_ENCRYPTED(inode))
419419
return fscrypt_zeroout_range(inode, lblk, pblk, len);
420420

421421
ret = sb_issue_zeroout(inode->i_sb, pblk, len, GFP_NOFS);
@@ -1217,8 +1217,7 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len,
12171217
(block_start < from || block_end > to)) {
12181218
ll_rw_block(REQ_OP_READ, 0, 1, &bh);
12191219
*wait_bh++ = bh;
1220-
decrypt = ext4_encrypted_inode(inode) &&
1221-
S_ISREG(inode->i_mode);
1220+
decrypt = IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode);
12221221
}
12231222
}
12241223
/*
@@ -3881,7 +3880,7 @@ static ssize_t ext4_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
38813880
ssize_t ret;
38823881

38833882
#ifdef CONFIG_EXT4_FS_ENCRYPTION
3884-
if (ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode))
3883+
if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode))
38853884
return 0;
38863885
#endif
38873886

@@ -4065,8 +4064,7 @@ static int __ext4_block_zero_page_range(handle_t *handle,
40654064
/* Uhhuh. Read error. Complain and punt. */
40664065
if (!buffer_uptodate(bh))
40674066
goto unlock;
4068-
if (S_ISREG(inode->i_mode) &&
4069-
ext4_encrypted_inode(inode)) {
4067+
if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
40704068
/* We expect the key to be set. */
40714069
BUG_ON(!fscrypt_has_encryption_key(inode));
40724070
BUG_ON(blocksize != PAGE_SIZE);
@@ -4142,7 +4140,7 @@ static int ext4_block_truncate_page(handle_t *handle,
41424140
struct inode *inode = mapping->host;
41434141

41444142
/* If we are processing an encrypted inode during orphan list handling */
4145-
if (ext4_encrypted_inode(inode) && !fscrypt_has_encryption_key(inode))
4143+
if (IS_ENCRYPTED(inode) && !fscrypt_has_encryption_key(inode))
41464144
return 0;
41474145

41484146
blocksize = inode->i_sb->s_blocksize;
@@ -4722,7 +4720,7 @@ static bool ext4_should_use_dax(struct inode *inode)
47224720
return false;
47234721
if (ext4_has_inline_data(inode))
47244722
return false;
4725-
if (ext4_encrypted_inode(inode))
4723+
if (ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT))
47264724
return false;
47274725
return true;
47284726
}
@@ -5072,7 +5070,7 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
50725070
ret = -EFSCORRUPTED;
50735071
goto bad_inode;
50745072
}
5075-
if (ext4_encrypted_inode(inode)) {
5073+
if (IS_ENCRYPTED(inode)) {
50765074
inode->i_op = &ext4_encrypted_symlink_inode_operations;
50775075
ext4_set_aops(inode);
50785076
} else if (ext4_inode_is_fast_symlink(inode)) {

‎fs/ext4/move_extent.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,7 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,
592592
return -EOPNOTSUPP;
593593
}
594594

595-
if (ext4_encrypted_inode(orig_inode) ||
596-
ext4_encrypted_inode(donor_inode)) {
595+
if (IS_ENCRYPTED(orig_inode) || IS_ENCRYPTED(donor_inode)) {
597596
ext4_msg(orig_inode->i_sb, KERN_ERR,
598597
"Online defrag not supported for encrypted files");
599598
return -EOPNOTSUPP;

‎fs/ext4/namei.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ static struct stats dx_show_leaf(struct inode *dir,
621621

622622
name = de->name;
623623
len = de->name_len;
624-
if (ext4_encrypted_inode(dir))
624+
if (IS_ENCRYPTED(dir))
625625
res = fscrypt_get_encryption_info(dir);
626626
if (res) {
627627
printk(KERN_WARNING "Error setting up"
@@ -986,7 +986,7 @@ static int htree_dirblock_to_tree(struct file *dir_file,
986986
EXT4_DIR_REC_LEN(0));
987987
#ifdef CONFIG_EXT4_FS_ENCRYPTION
988988
/* Check if the directory is encrypted */
989-
if (ext4_encrypted_inode(dir)) {
989+
if (IS_ENCRYPTED(dir)) {
990990
err = fscrypt_get_encryption_info(dir);
991991
if (err < 0) {
992992
brelse(bh);
@@ -1015,7 +1015,7 @@ static int htree_dirblock_to_tree(struct file *dir_file,
10151015
continue;
10161016
if (de->inode == 0)
10171017
continue;
1018-
if (!ext4_encrypted_inode(dir)) {
1018+
if (!IS_ENCRYPTED(dir)) {
10191019
tmp_str.name = de->name;
10201020
tmp_str.len = de->name_len;
10211021
err = ext4_htree_store_dirent(dir_file,
@@ -1578,7 +1578,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi
15781578
ino);
15791579
return ERR_PTR(-EFSCORRUPTED);
15801580
}
1581-
if (!IS_ERR(inode) && ext4_encrypted_inode(dir) &&
1581+
if (!IS_ERR(inode) && IS_ENCRYPTED(dir) &&
15821582
(S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
15831583
!fscrypt_has_permitted_context(dir, inode)) {
15841584
ext4_warning(inode->i_sb,

‎fs/ext4/page-io.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,7 @@ int ext4_bio_write_page(struct ext4_io_submit *io,
477477

478478
bh = head = page_buffers(page);
479479

480-
if (ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode) &&
481-
nr_to_submit) {
480+
if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode) && nr_to_submit) {
482481
gfp_t gfp_flags = GFP_NOFS;
483482

484483
retry_encrypt:

‎fs/ext4/readpage.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ int ext4_mpage_readpages(struct address_space *mapping,
242242
if (bio == NULL) {
243243
struct fscrypt_ctx *ctx = NULL;
244244

245-
if (ext4_encrypted_inode(inode) &&
246-
S_ISREG(inode->i_mode)) {
245+
if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode)) {
247246
ctx = fscrypt_get_ctx(inode, GFP_NOFS);
248247
if (IS_ERR(ctx))
249248
goto set_error_page;

0 commit comments

Comments
 (0)