Commit 592ddec7 authored by Chandan Rajendra's avatar Chandan Rajendra Committed by Theodore Ts'o

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: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarChandan Rajendra <chandan@linux.vnet.ibm.com>
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
parent 1058ef0d
...@@ -111,7 +111,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx) ...@@ -111,7 +111,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
int dir_has_error = 0; int dir_has_error = 0;
struct fscrypt_str fstr = FSTR_INIT(NULL, 0); struct fscrypt_str fstr = FSTR_INIT(NULL, 0);
if (ext4_encrypted_inode(inode)) { if (IS_ENCRYPTED(inode)) {
err = fscrypt_get_encryption_info(inode); err = fscrypt_get_encryption_info(inode);
if (err && err != -ENOKEY) if (err && err != -ENOKEY)
return err; return err;
...@@ -138,7 +138,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx) ...@@ -138,7 +138,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
return err; return err;
} }
if (ext4_encrypted_inode(inode)) { if (IS_ENCRYPTED(inode)) {
err = fscrypt_fname_alloc_buffer(inode, EXT4_NAME_LEN, &fstr); err = fscrypt_fname_alloc_buffer(inode, EXT4_NAME_LEN, &fstr);
if (err < 0) if (err < 0)
return err; return err;
...@@ -245,7 +245,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx) ...@@ -245,7 +245,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
offset += ext4_rec_len_from_disk(de->rec_len, offset += ext4_rec_len_from_disk(de->rec_len,
sb->s_blocksize); sb->s_blocksize);
if (le32_to_cpu(de->inode)) { if (le32_to_cpu(de->inode)) {
if (!ext4_encrypted_inode(inode)) { if (!IS_ENCRYPTED(inode)) {
if (!dir_emit(ctx, de->name, if (!dir_emit(ctx, de->name,
de->name_len, de->name_len,
le32_to_cpu(de->inode), le32_to_cpu(de->inode),
...@@ -613,7 +613,7 @@ static int ext4_dx_readdir(struct file *file, struct dir_context *ctx) ...@@ -613,7 +613,7 @@ static int ext4_dx_readdir(struct file *file, struct dir_context *ctx)
static int ext4_dir_open(struct inode * inode, struct file * filp) static int ext4_dir_open(struct inode * inode, struct file * filp)
{ {
if (ext4_encrypted_inode(inode)) if (IS_ENCRYPTED(inode))
return fscrypt_get_encryption_info(inode) ? -EACCES : 0; return fscrypt_get_encryption_info(inode) ? -EACCES : 0;
return 0; return 0;
} }
......
...@@ -2279,11 +2279,6 @@ extern unsigned ext4_free_clusters_after_init(struct super_block *sb, ...@@ -2279,11 +2279,6 @@ extern unsigned ext4_free_clusters_after_init(struct super_block *sb,
struct ext4_group_desc *gdp); struct ext4_group_desc *gdp);
ext4_fsblk_t ext4_inode_to_goal_block(struct inode *); ext4_fsblk_t ext4_inode_to_goal_block(struct inode *);
static inline bool ext4_encrypted_inode(struct inode *inode)
{
return ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT);
}
#ifdef CONFIG_EXT4_FS_ENCRYPTION #ifdef CONFIG_EXT4_FS_ENCRYPTION
static inline int ext4_fname_setup_filename(struct inode *dir, static inline int ext4_fname_setup_filename(struct inode *dir,
const struct qstr *iname, const struct qstr *iname,
......
...@@ -411,7 +411,7 @@ static inline int ext4_inode_journal_mode(struct inode *inode) ...@@ -411,7 +411,7 @@ static inline int ext4_inode_journal_mode(struct inode *inode)
(ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA) && (ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA) &&
!test_opt(inode->i_sb, DELALLOC))) { !test_opt(inode->i_sb, DELALLOC))) {
/* We do not support data journalling for encrypted data */ /* We do not support data journalling for encrypted data */
if (S_ISREG(inode->i_mode) && ext4_encrypted_inode(inode)) if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode))
return EXT4_INODE_ORDERED_DATA_MODE; /* ordered */ return EXT4_INODE_ORDERED_DATA_MODE; /* ordered */
return EXT4_INODE_JOURNAL_DATA_MODE; /* journal data */ return EXT4_INODE_JOURNAL_DATA_MODE; /* journal data */
} }
......
...@@ -3631,7 +3631,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, ...@@ -3631,7 +3631,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle,
max_zeroout = sbi->s_extent_max_zeroout_kb >> max_zeroout = sbi->s_extent_max_zeroout_kb >>
(inode->i_sb->s_blocksize_bits - 10); (inode->i_sb->s_blocksize_bits - 10);
if (ext4_encrypted_inode(inode)) if (IS_ENCRYPTED(inode))
max_zeroout = 0; max_zeroout = 0;
/* /*
...@@ -4818,7 +4818,7 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len) ...@@ -4818,7 +4818,7 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
* leave it disabled for encrypted inodes for now. This is a * leave it disabled for encrypted inodes for now. This is a
* bug we should fix.... * bug we should fix....
*/ */
if (ext4_encrypted_inode(inode) && if (IS_ENCRYPTED(inode) &&
(mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE | (mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE |
FALLOC_FL_ZERO_RANGE))) FALLOC_FL_ZERO_RANGE)))
return -EOPNOTSUPP; return -EOPNOTSUPP;
......
...@@ -771,7 +771,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir, ...@@ -771,7 +771,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir,
if (unlikely(ext4_forced_shutdown(sbi))) if (unlikely(ext4_forced_shutdown(sbi)))
return ERR_PTR(-EIO); return ERR_PTR(-EIO);
if ((ext4_encrypted_inode(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) && if ((IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) &&
(S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) && (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) &&
!(i_flags & EXT4_EA_INODE_FL)) { !(i_flags & EXT4_EA_INODE_FL)) {
err = fscrypt_get_encryption_info(dir); err = fscrypt_get_encryption_info(dir);
......
...@@ -415,7 +415,7 @@ int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk, ext4_fsblk_t pblk, ...@@ -415,7 +415,7 @@ int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk, ext4_fsblk_t pblk,
{ {
int ret; int ret;
if (ext4_encrypted_inode(inode)) if (IS_ENCRYPTED(inode))
return fscrypt_zeroout_range(inode, lblk, pblk, len); return fscrypt_zeroout_range(inode, lblk, pblk, len);
ret = sb_issue_zeroout(inode->i_sb, pblk, len, GFP_NOFS); 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, ...@@ -1217,8 +1217,7 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len,
(block_start < from || block_end > to)) { (block_start < from || block_end > to)) {
ll_rw_block(REQ_OP_READ, 0, 1, &bh); ll_rw_block(REQ_OP_READ, 0, 1, &bh);
*wait_bh++ = bh; *wait_bh++ = bh;
decrypt = ext4_encrypted_inode(inode) && decrypt = IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode);
S_ISREG(inode->i_mode);
} }
} }
/* /*
...@@ -3881,7 +3880,7 @@ static ssize_t ext4_direct_IO(struct kiocb *iocb, struct iov_iter *iter) ...@@ -3881,7 +3880,7 @@ static ssize_t ext4_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
ssize_t ret; ssize_t ret;
#ifdef CONFIG_EXT4_FS_ENCRYPTION #ifdef CONFIG_EXT4_FS_ENCRYPTION
if (ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode)) if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode))
return 0; return 0;
#endif #endif
...@@ -4065,8 +4064,7 @@ static int __ext4_block_zero_page_range(handle_t *handle, ...@@ -4065,8 +4064,7 @@ static int __ext4_block_zero_page_range(handle_t *handle,
/* Uhhuh. Read error. Complain and punt. */ /* Uhhuh. Read error. Complain and punt. */
if (!buffer_uptodate(bh)) if (!buffer_uptodate(bh))
goto unlock; goto unlock;
if (S_ISREG(inode->i_mode) && if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) {
ext4_encrypted_inode(inode)) {
/* We expect the key to be set. */ /* We expect the key to be set. */
BUG_ON(!fscrypt_has_encryption_key(inode)); BUG_ON(!fscrypt_has_encryption_key(inode));
BUG_ON(blocksize != PAGE_SIZE); BUG_ON(blocksize != PAGE_SIZE);
...@@ -4142,7 +4140,7 @@ static int ext4_block_truncate_page(handle_t *handle, ...@@ -4142,7 +4140,7 @@ static int ext4_block_truncate_page(handle_t *handle,
struct inode *inode = mapping->host; struct inode *inode = mapping->host;
/* If we are processing an encrypted inode during orphan list handling */ /* If we are processing an encrypted inode during orphan list handling */
if (ext4_encrypted_inode(inode) && !fscrypt_has_encryption_key(inode)) if (IS_ENCRYPTED(inode) && !fscrypt_has_encryption_key(inode))
return 0; return 0;
blocksize = inode->i_sb->s_blocksize; blocksize = inode->i_sb->s_blocksize;
...@@ -4722,7 +4720,7 @@ static bool ext4_should_use_dax(struct inode *inode) ...@@ -4722,7 +4720,7 @@ static bool ext4_should_use_dax(struct inode *inode)
return false; return false;
if (ext4_has_inline_data(inode)) if (ext4_has_inline_data(inode))
return false; return false;
if (ext4_encrypted_inode(inode)) if (ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT))
return false; return false;
return true; return true;
} }
...@@ -5072,7 +5070,7 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, ...@@ -5072,7 +5070,7 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
ret = -EFSCORRUPTED; ret = -EFSCORRUPTED;
goto bad_inode; goto bad_inode;
} }
if (ext4_encrypted_inode(inode)) { if (IS_ENCRYPTED(inode)) {
inode->i_op = &ext4_encrypted_symlink_inode_operations; inode->i_op = &ext4_encrypted_symlink_inode_operations;
ext4_set_aops(inode); ext4_set_aops(inode);
} else if (ext4_inode_is_fast_symlink(inode)) { } else if (ext4_inode_is_fast_symlink(inode)) {
......
...@@ -592,8 +592,7 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk, ...@@ -592,8 +592,7 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk,
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
if (ext4_encrypted_inode(orig_inode) || if (IS_ENCRYPTED(orig_inode) || IS_ENCRYPTED(donor_inode)) {
ext4_encrypted_inode(donor_inode)) {
ext4_msg(orig_inode->i_sb, KERN_ERR, ext4_msg(orig_inode->i_sb, KERN_ERR,
"Online defrag not supported for encrypted files"); "Online defrag not supported for encrypted files");
return -EOPNOTSUPP; return -EOPNOTSUPP;
......
...@@ -621,7 +621,7 @@ static struct stats dx_show_leaf(struct inode *dir, ...@@ -621,7 +621,7 @@ static struct stats dx_show_leaf(struct inode *dir,
name = de->name; name = de->name;
len = de->name_len; len = de->name_len;
if (ext4_encrypted_inode(dir)) if (IS_ENCRYPTED(dir))
res = fscrypt_get_encryption_info(dir); res = fscrypt_get_encryption_info(dir);
if (res) { if (res) {
printk(KERN_WARNING "Error setting up" printk(KERN_WARNING "Error setting up"
...@@ -986,7 +986,7 @@ static int htree_dirblock_to_tree(struct file *dir_file, ...@@ -986,7 +986,7 @@ static int htree_dirblock_to_tree(struct file *dir_file,
EXT4_DIR_REC_LEN(0)); EXT4_DIR_REC_LEN(0));
#ifdef CONFIG_EXT4_FS_ENCRYPTION #ifdef CONFIG_EXT4_FS_ENCRYPTION
/* Check if the directory is encrypted */ /* Check if the directory is encrypted */
if (ext4_encrypted_inode(dir)) { if (IS_ENCRYPTED(dir)) {
err = fscrypt_get_encryption_info(dir); err = fscrypt_get_encryption_info(dir);
if (err < 0) { if (err < 0) {
brelse(bh); brelse(bh);
...@@ -1015,7 +1015,7 @@ static int htree_dirblock_to_tree(struct file *dir_file, ...@@ -1015,7 +1015,7 @@ static int htree_dirblock_to_tree(struct file *dir_file,
continue; continue;
if (de->inode == 0) if (de->inode == 0)
continue; continue;
if (!ext4_encrypted_inode(dir)) { if (!IS_ENCRYPTED(dir)) {
tmp_str.name = de->name; tmp_str.name = de->name;
tmp_str.len = de->name_len; tmp_str.len = de->name_len;
err = ext4_htree_store_dirent(dir_file, err = ext4_htree_store_dirent(dir_file,
...@@ -1578,7 +1578,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi ...@@ -1578,7 +1578,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi
ino); ino);
return ERR_PTR(-EFSCORRUPTED); return ERR_PTR(-EFSCORRUPTED);
} }
if (!IS_ERR(inode) && ext4_encrypted_inode(dir) && if (!IS_ERR(inode) && IS_ENCRYPTED(dir) &&
(S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) && (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
!fscrypt_has_permitted_context(dir, inode)) { !fscrypt_has_permitted_context(dir, inode)) {
ext4_warning(inode->i_sb, ext4_warning(inode->i_sb,
......
...@@ -477,8 +477,7 @@ int ext4_bio_write_page(struct ext4_io_submit *io, ...@@ -477,8 +477,7 @@ int ext4_bio_write_page(struct ext4_io_submit *io,
bh = head = page_buffers(page); bh = head = page_buffers(page);
if (ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode) && if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode) && nr_to_submit) {
nr_to_submit) {
gfp_t gfp_flags = GFP_NOFS; gfp_t gfp_flags = GFP_NOFS;
retry_encrypt: retry_encrypt:
......
...@@ -242,8 +242,7 @@ int ext4_mpage_readpages(struct address_space *mapping, ...@@ -242,8 +242,7 @@ int ext4_mpage_readpages(struct address_space *mapping,
if (bio == NULL) { if (bio == NULL) {
struct fscrypt_ctx *ctx = NULL; struct fscrypt_ctx *ctx = NULL;
if (ext4_encrypted_inode(inode) && if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode)) {
S_ISREG(inode->i_mode)) {
ctx = fscrypt_get_ctx(inode, GFP_NOFS); ctx = fscrypt_get_ctx(inode, GFP_NOFS);
if (IS_ERR(ctx)) if (IS_ERR(ctx))
goto set_error_page; goto set_error_page;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment