diff options
author | Chandan Rajendra <chandan@linux.vnet.ibm.com> | 2018-12-12 04:50:10 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2019-01-23 23:56:43 -0500 |
commit | 592ddec7578a33fb6b3e2ba78aed91614bbb30e2 (patch) | |
tree | 21b6aea465ac22643d6cec4796536fecd5d92e89 | |
parent | 1058ef0dcb7116fc49270131fda3037fddcc6595 (diff) |
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>
-rw-r--r-- | fs/ext4/dir.c | 8 | ||||
-rw-r--r-- | fs/ext4/ext4.h | 5 | ||||
-rw-r--r-- | fs/ext4/ext4_jbd2.h | 2 | ||||
-rw-r--r-- | fs/ext4/extents.c | 4 | ||||
-rw-r--r-- | fs/ext4/ialloc.c | 2 | ||||
-rw-r--r-- | fs/ext4/inode.c | 16 | ||||
-rw-r--r-- | fs/ext4/move_extent.c | 3 | ||||
-rw-r--r-- | fs/ext4/namei.c | 8 | ||||
-rw-r--r-- | fs/ext4/page-io.c | 3 | ||||
-rw-r--r-- | fs/ext4/readpage.c | 3 |
10 files changed, 22 insertions, 32 deletions
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index f93f9881ec18..fb7a64ea5679 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c | |||
@@ -111,7 +111,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx) | |||
111 | int dir_has_error = 0; | 111 | int dir_has_error = 0; |
112 | struct fscrypt_str fstr = FSTR_INIT(NULL, 0); | 112 | struct fscrypt_str fstr = FSTR_INIT(NULL, 0); |
113 | 113 | ||
114 | if (ext4_encrypted_inode(inode)) { | 114 | if (IS_ENCRYPTED(inode)) { |
115 | err = fscrypt_get_encryption_info(inode); | 115 | err = fscrypt_get_encryption_info(inode); |
116 | if (err && err != -ENOKEY) | 116 | if (err && err != -ENOKEY) |
117 | return err; | 117 | return err; |
@@ -138,7 +138,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx) | |||
138 | return err; | 138 | return err; |
139 | } | 139 | } |
140 | 140 | ||
141 | if (ext4_encrypted_inode(inode)) { | 141 | if (IS_ENCRYPTED(inode)) { |
142 | err = fscrypt_fname_alloc_buffer(inode, EXT4_NAME_LEN, &fstr); | 142 | err = fscrypt_fname_alloc_buffer(inode, EXT4_NAME_LEN, &fstr); |
143 | if (err < 0) | 143 | if (err < 0) |
144 | return err; | 144 | return err; |
@@ -245,7 +245,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx) | |||
245 | offset += ext4_rec_len_from_disk(de->rec_len, | 245 | offset += ext4_rec_len_from_disk(de->rec_len, |
246 | sb->s_blocksize); | 246 | sb->s_blocksize); |
247 | if (le32_to_cpu(de->inode)) { | 247 | if (le32_to_cpu(de->inode)) { |
248 | if (!ext4_encrypted_inode(inode)) { | 248 | if (!IS_ENCRYPTED(inode)) { |
249 | if (!dir_emit(ctx, de->name, | 249 | if (!dir_emit(ctx, de->name, |
250 | de->name_len, | 250 | de->name_len, |
251 | le32_to_cpu(de->inode), | 251 | le32_to_cpu(de->inode), |
@@ -613,7 +613,7 @@ finished: | |||
613 | 613 | ||
614 | static int ext4_dir_open(struct inode * inode, struct file * filp) | 614 | static int ext4_dir_open(struct inode * inode, struct file * filp) |
615 | { | 615 | { |
616 | if (ext4_encrypted_inode(inode)) | 616 | if (IS_ENCRYPTED(inode)) |
617 | return fscrypt_get_encryption_info(inode) ? -EACCES : 0; | 617 | return fscrypt_get_encryption_info(inode) ? -EACCES : 0; |
618 | return 0; | 618 | return 0; |
619 | } | 619 | } |
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 185a05d3257e..afdb9ad8be0e 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h | |||
@@ -2279,11 +2279,6 @@ extern unsigned ext4_free_clusters_after_init(struct super_block *sb, | |||
2279 | struct ext4_group_desc *gdp); | 2279 | struct ext4_group_desc *gdp); |
2280 | ext4_fsblk_t ext4_inode_to_goal_block(struct inode *); | 2280 | ext4_fsblk_t ext4_inode_to_goal_block(struct inode *); |
2281 | 2281 | ||
2282 | static inline bool ext4_encrypted_inode(struct inode *inode) | ||
2283 | { | ||
2284 | return ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT); | ||
2285 | } | ||
2286 | |||
2287 | #ifdef CONFIG_EXT4_FS_ENCRYPTION | 2282 | #ifdef CONFIG_EXT4_FS_ENCRYPTION |
2288 | static inline int ext4_fname_setup_filename(struct inode *dir, | 2283 | static inline int ext4_fname_setup_filename(struct inode *dir, |
2289 | const struct qstr *iname, | 2284 | const struct qstr *iname, |
diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h index 15b6dd733780..a1ac7e9245ec 100644 --- a/fs/ext4/ext4_jbd2.h +++ b/fs/ext4/ext4_jbd2.h | |||
@@ -411,7 +411,7 @@ static inline int ext4_inode_journal_mode(struct inode *inode) | |||
411 | (ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA) && | 411 | (ext4_test_inode_flag(inode, EXT4_INODE_JOURNAL_DATA) && |
412 | !test_opt(inode->i_sb, DELALLOC))) { | 412 | !test_opt(inode->i_sb, DELALLOC))) { |
413 | /* We do not support data journalling for encrypted data */ | 413 | /* 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)) |
415 | return EXT4_INODE_ORDERED_DATA_MODE; /* ordered */ | 415 | return EXT4_INODE_ORDERED_DATA_MODE; /* ordered */ |
416 | return EXT4_INODE_JOURNAL_DATA_MODE; /* journal data */ | 416 | return EXT4_INODE_JOURNAL_DATA_MODE; /* journal data */ |
417 | } | 417 | } |
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 240b6dea5441..79d986dbf5af 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c | |||
@@ -3631,7 +3631,7 @@ static int ext4_ext_convert_to_initialized(handle_t *handle, | |||
3631 | max_zeroout = sbi->s_extent_max_zeroout_kb >> | 3631 | max_zeroout = sbi->s_extent_max_zeroout_kb >> |
3632 | (inode->i_sb->s_blocksize_bits - 10); | 3632 | (inode->i_sb->s_blocksize_bits - 10); |
3633 | 3633 | ||
3634 | if (ext4_encrypted_inode(inode)) | 3634 | if (IS_ENCRYPTED(inode)) |
3635 | max_zeroout = 0; | 3635 | max_zeroout = 0; |
3636 | 3636 | ||
3637 | /* | 3637 | /* |
@@ -4818,7 +4818,7 @@ long ext4_fallocate(struct file *file, int mode, loff_t offset, loff_t len) | |||
4818 | * leave it disabled for encrypted inodes for now. This is a | 4818 | * leave it disabled for encrypted inodes for now. This is a |
4819 | * bug we should fix.... | 4819 | * bug we should fix.... |
4820 | */ | 4820 | */ |
4821 | if (ext4_encrypted_inode(inode) && | 4821 | if (IS_ENCRYPTED(inode) && |
4822 | (mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE | | 4822 | (mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE | |
4823 | FALLOC_FL_ZERO_RANGE))) | 4823 | FALLOC_FL_ZERO_RANGE))) |
4824 | return -EOPNOTSUPP; | 4824 | return -EOPNOTSUPP; |
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index 7ff14a1adba3..f3e17a8c84b4 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c | |||
@@ -771,7 +771,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir, | |||
771 | if (unlikely(ext4_forced_shutdown(sbi))) | 771 | if (unlikely(ext4_forced_shutdown(sbi))) |
772 | return ERR_PTR(-EIO); | 772 | return ERR_PTR(-EIO); |
773 | 773 | ||
774 | if ((ext4_encrypted_inode(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) && | 774 | if ((IS_ENCRYPTED(dir) || DUMMY_ENCRYPTION_ENABLED(sbi)) && |
775 | (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) && | 775 | (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) && |
776 | !(i_flags & EXT4_EA_INODE_FL)) { | 776 | !(i_flags & EXT4_EA_INODE_FL)) { |
777 | err = fscrypt_get_encryption_info(dir); | 777 | err = fscrypt_get_encryption_info(dir); |
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 34d7e0703cc6..71bd2d28f58d 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -415,7 +415,7 @@ int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk, ext4_fsblk_t pblk, | |||
415 | { | 415 | { |
416 | int ret; | 416 | int ret; |
417 | 417 | ||
418 | if (ext4_encrypted_inode(inode)) | 418 | if (IS_ENCRYPTED(inode)) |
419 | return fscrypt_zeroout_range(inode, lblk, pblk, len); | 419 | return fscrypt_zeroout_range(inode, lblk, pblk, len); |
420 | 420 | ||
421 | ret = sb_issue_zeroout(inode->i_sb, pblk, len, GFP_NOFS); | 421 | 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 | (block_start < from || block_end > to)) { | 1217 | (block_start < from || block_end > to)) { |
1218 | ll_rw_block(REQ_OP_READ, 0, 1, &bh); | 1218 | ll_rw_block(REQ_OP_READ, 0, 1, &bh); |
1219 | *wait_bh++ = bh; | 1219 | *wait_bh++ = bh; |
1220 | decrypt = ext4_encrypted_inode(inode) && | 1220 | decrypt = IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode); |
1221 | S_ISREG(inode->i_mode); | ||
1222 | } | 1221 | } |
1223 | } | 1222 | } |
1224 | /* | 1223 | /* |
@@ -3881,7 +3880,7 @@ static ssize_t ext4_direct_IO(struct kiocb *iocb, struct iov_iter *iter) | |||
3881 | ssize_t ret; | 3880 | ssize_t ret; |
3882 | 3881 | ||
3883 | #ifdef CONFIG_EXT4_FS_ENCRYPTION | 3882 | #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)) |
3885 | return 0; | 3884 | return 0; |
3886 | #endif | 3885 | #endif |
3887 | 3886 | ||
@@ -4065,8 +4064,7 @@ static int __ext4_block_zero_page_range(handle_t *handle, | |||
4065 | /* Uhhuh. Read error. Complain and punt. */ | 4064 | /* Uhhuh. Read error. Complain and punt. */ |
4066 | if (!buffer_uptodate(bh)) | 4065 | if (!buffer_uptodate(bh)) |
4067 | goto unlock; | 4066 | goto unlock; |
4068 | if (S_ISREG(inode->i_mode) && | 4067 | if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode)) { |
4069 | ext4_encrypted_inode(inode)) { | ||
4070 | /* We expect the key to be set. */ | 4068 | /* We expect the key to be set. */ |
4071 | BUG_ON(!fscrypt_has_encryption_key(inode)); | 4069 | BUG_ON(!fscrypt_has_encryption_key(inode)); |
4072 | BUG_ON(blocksize != PAGE_SIZE); | 4070 | BUG_ON(blocksize != PAGE_SIZE); |
@@ -4142,7 +4140,7 @@ static int ext4_block_truncate_page(handle_t *handle, | |||
4142 | struct inode *inode = mapping->host; | 4140 | struct inode *inode = mapping->host; |
4143 | 4141 | ||
4144 | /* If we are processing an encrypted inode during orphan list handling */ | 4142 | /* 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)) |
4146 | return 0; | 4144 | return 0; |
4147 | 4145 | ||
4148 | blocksize = inode->i_sb->s_blocksize; | 4146 | blocksize = inode->i_sb->s_blocksize; |
@@ -4722,7 +4720,7 @@ static bool ext4_should_use_dax(struct inode *inode) | |||
4722 | return false; | 4720 | return false; |
4723 | if (ext4_has_inline_data(inode)) | 4721 | if (ext4_has_inline_data(inode)) |
4724 | return false; | 4722 | return false; |
4725 | if (ext4_encrypted_inode(inode)) | 4723 | if (ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT)) |
4726 | return false; | 4724 | return false; |
4727 | return true; | 4725 | return true; |
4728 | } | 4726 | } |
@@ -5072,7 +5070,7 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, | |||
5072 | ret = -EFSCORRUPTED; | 5070 | ret = -EFSCORRUPTED; |
5073 | goto bad_inode; | 5071 | goto bad_inode; |
5074 | } | 5072 | } |
5075 | if (ext4_encrypted_inode(inode)) { | 5073 | if (IS_ENCRYPTED(inode)) { |
5076 | inode->i_op = &ext4_encrypted_symlink_inode_operations; | 5074 | inode->i_op = &ext4_encrypted_symlink_inode_operations; |
5077 | ext4_set_aops(inode); | 5075 | ext4_set_aops(inode); |
5078 | } else if (ext4_inode_is_fast_symlink(inode)) { | 5076 | } else if (ext4_inode_is_fast_symlink(inode)) { |
diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index 2f5be02fc6f6..1083a9f3f16a 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c | |||
@@ -592,8 +592,7 @@ ext4_move_extents(struct file *o_filp, struct file *d_filp, __u64 orig_blk, | |||
592 | return -EOPNOTSUPP; | 592 | return -EOPNOTSUPP; |
593 | } | 593 | } |
594 | 594 | ||
595 | if (ext4_encrypted_inode(orig_inode) || | 595 | if (IS_ENCRYPTED(orig_inode) || IS_ENCRYPTED(donor_inode)) { |
596 | ext4_encrypted_inode(donor_inode)) { | ||
597 | ext4_msg(orig_inode->i_sb, KERN_ERR, | 596 | ext4_msg(orig_inode->i_sb, KERN_ERR, |
598 | "Online defrag not supported for encrypted files"); | 597 | "Online defrag not supported for encrypted files"); |
599 | return -EOPNOTSUPP; | 598 | return -EOPNOTSUPP; |
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 2b928eb07fa2..be6cb69beb12 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c | |||
@@ -621,7 +621,7 @@ static struct stats dx_show_leaf(struct inode *dir, | |||
621 | 621 | ||
622 | name = de->name; | 622 | name = de->name; |
623 | len = de->name_len; | 623 | len = de->name_len; |
624 | if (ext4_encrypted_inode(dir)) | 624 | if (IS_ENCRYPTED(dir)) |
625 | res = fscrypt_get_encryption_info(dir); | 625 | res = fscrypt_get_encryption_info(dir); |
626 | if (res) { | 626 | if (res) { |
627 | printk(KERN_WARNING "Error setting up" | 627 | printk(KERN_WARNING "Error setting up" |
@@ -986,7 +986,7 @@ static int htree_dirblock_to_tree(struct file *dir_file, | |||
986 | EXT4_DIR_REC_LEN(0)); | 986 | EXT4_DIR_REC_LEN(0)); |
987 | #ifdef CONFIG_EXT4_FS_ENCRYPTION | 987 | #ifdef CONFIG_EXT4_FS_ENCRYPTION |
988 | /* Check if the directory is encrypted */ | 988 | /* Check if the directory is encrypted */ |
989 | if (ext4_encrypted_inode(dir)) { | 989 | if (IS_ENCRYPTED(dir)) { |
990 | err = fscrypt_get_encryption_info(dir); | 990 | err = fscrypt_get_encryption_info(dir); |
991 | if (err < 0) { | 991 | if (err < 0) { |
992 | brelse(bh); | 992 | brelse(bh); |
@@ -1015,7 +1015,7 @@ static int htree_dirblock_to_tree(struct file *dir_file, | |||
1015 | continue; | 1015 | continue; |
1016 | if (de->inode == 0) | 1016 | if (de->inode == 0) |
1017 | continue; | 1017 | continue; |
1018 | if (!ext4_encrypted_inode(dir)) { | 1018 | if (!IS_ENCRYPTED(dir)) { |
1019 | tmp_str.name = de->name; | 1019 | tmp_str.name = de->name; |
1020 | tmp_str.len = de->name_len; | 1020 | tmp_str.len = de->name_len; |
1021 | err = ext4_htree_store_dirent(dir_file, | 1021 | err = ext4_htree_store_dirent(dir_file, |
@@ -1578,7 +1578,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi | |||
1578 | ino); | 1578 | ino); |
1579 | return ERR_PTR(-EFSCORRUPTED); | 1579 | return ERR_PTR(-EFSCORRUPTED); |
1580 | } | 1580 | } |
1581 | if (!IS_ERR(inode) && ext4_encrypted_inode(dir) && | 1581 | if (!IS_ERR(inode) && IS_ENCRYPTED(dir) && |
1582 | (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) && | 1582 | (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) && |
1583 | !fscrypt_has_permitted_context(dir, inode)) { | 1583 | !fscrypt_has_permitted_context(dir, inode)) { |
1584 | ext4_warning(inode->i_sb, | 1584 | ext4_warning(inode->i_sb, |
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c index 2aa62d58d8dd..c398b55da854 100644 --- a/fs/ext4/page-io.c +++ b/fs/ext4/page-io.c | |||
@@ -477,8 +477,7 @@ int ext4_bio_write_page(struct ext4_io_submit *io, | |||
477 | 477 | ||
478 | bh = head = page_buffers(page); | 478 | bh = head = page_buffers(page); |
479 | 479 | ||
480 | if (ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode) && | 480 | if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode) && nr_to_submit) { |
481 | nr_to_submit) { | ||
482 | gfp_t gfp_flags = GFP_NOFS; | 481 | gfp_t gfp_flags = GFP_NOFS; |
483 | 482 | ||
484 | retry_encrypt: | 483 | retry_encrypt: |
diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c index 6aa282ee455a..52d3ff5a9db1 100644 --- a/fs/ext4/readpage.c +++ b/fs/ext4/readpage.c | |||
@@ -242,8 +242,7 @@ int ext4_mpage_readpages(struct address_space *mapping, | |||
242 | if (bio == NULL) { | 242 | if (bio == NULL) { |
243 | struct fscrypt_ctx *ctx = NULL; | 243 | struct fscrypt_ctx *ctx = NULL; |
244 | 244 | ||
245 | if (ext4_encrypted_inode(inode) && | 245 | if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode)) { |
246 | S_ISREG(inode->i_mode)) { | ||
247 | ctx = fscrypt_get_ctx(inode, GFP_NOFS); | 246 | ctx = fscrypt_get_ctx(inode, GFP_NOFS); |
248 | if (IS_ERR(ctx)) | 247 | if (IS_ERR(ctx)) |
249 | goto set_error_page; | 248 | goto set_error_page; |