diff options
Diffstat (limited to 'fs/ext4/super.c')
-rw-r--r-- | fs/ext4/super.c | 97 |
1 files changed, 91 insertions, 6 deletions
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 13c49af7a06a..1e3fd5c9a72b 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
@@ -945,9 +945,6 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) | |||
945 | ei->i_datasync_tid = 0; | 945 | ei->i_datasync_tid = 0; |
946 | atomic_set(&ei->i_unwritten, 0); | 946 | atomic_set(&ei->i_unwritten, 0); |
947 | INIT_WORK(&ei->i_rsv_conversion_work, ext4_end_io_rsv_work); | 947 | INIT_WORK(&ei->i_rsv_conversion_work, ext4_end_io_rsv_work); |
948 | #ifdef CONFIG_EXT4_FS_ENCRYPTION | ||
949 | ei->i_crypt_info = NULL; | ||
950 | #endif | ||
951 | return &ei->vfs_inode; | 948 | return &ei->vfs_inode; |
952 | } | 949 | } |
953 | 950 | ||
@@ -1026,8 +1023,7 @@ void ext4_clear_inode(struct inode *inode) | |||
1026 | EXT4_I(inode)->jinode = NULL; | 1023 | EXT4_I(inode)->jinode = NULL; |
1027 | } | 1024 | } |
1028 | #ifdef CONFIG_EXT4_FS_ENCRYPTION | 1025 | #ifdef CONFIG_EXT4_FS_ENCRYPTION |
1029 | if (EXT4_I(inode)->i_crypt_info) | 1026 | fscrypt_put_encryption_info(inode, NULL); |
1030 | ext4_free_encryption_info(inode, EXT4_I(inode)->i_crypt_info); | ||
1031 | #endif | 1027 | #endif |
1032 | } | 1028 | } |
1033 | 1029 | ||
@@ -1094,6 +1090,90 @@ static int bdev_try_to_free_page(struct super_block *sb, struct page *page, | |||
1094 | return try_to_free_buffers(page); | 1090 | return try_to_free_buffers(page); |
1095 | } | 1091 | } |
1096 | 1092 | ||
1093 | #ifdef CONFIG_EXT4_FS_ENCRYPTION | ||
1094 | static int ext4_get_context(struct inode *inode, void *ctx, size_t len) | ||
1095 | { | ||
1096 | return ext4_xattr_get(inode, EXT4_XATTR_INDEX_ENCRYPTION, | ||
1097 | EXT4_XATTR_NAME_ENCRYPTION_CONTEXT, ctx, len); | ||
1098 | } | ||
1099 | |||
1100 | static int ext4_key_prefix(struct inode *inode, u8 **key) | ||
1101 | { | ||
1102 | *key = EXT4_SB(inode->i_sb)->key_prefix; | ||
1103 | return EXT4_SB(inode->i_sb)->key_prefix_size; | ||
1104 | } | ||
1105 | |||
1106 | static int ext4_prepare_context(struct inode *inode) | ||
1107 | { | ||
1108 | return ext4_convert_inline_data(inode); | ||
1109 | } | ||
1110 | |||
1111 | static int ext4_set_context(struct inode *inode, const void *ctx, size_t len, | ||
1112 | void *fs_data) | ||
1113 | { | ||
1114 | handle_t *handle; | ||
1115 | int res, res2; | ||
1116 | |||
1117 | /* fs_data is null when internally used. */ | ||
1118 | if (fs_data) { | ||
1119 | res = ext4_xattr_set(inode, EXT4_XATTR_INDEX_ENCRYPTION, | ||
1120 | EXT4_XATTR_NAME_ENCRYPTION_CONTEXT, ctx, | ||
1121 | len, 0); | ||
1122 | if (!res) { | ||
1123 | ext4_set_inode_flag(inode, EXT4_INODE_ENCRYPT); | ||
1124 | ext4_clear_inode_state(inode, | ||
1125 | EXT4_STATE_MAY_INLINE_DATA); | ||
1126 | } | ||
1127 | return res; | ||
1128 | } | ||
1129 | |||
1130 | handle = ext4_journal_start(inode, EXT4_HT_MISC, | ||
1131 | ext4_jbd2_credits_xattr(inode)); | ||
1132 | if (IS_ERR(handle)) | ||
1133 | return PTR_ERR(handle); | ||
1134 | |||
1135 | res = ext4_xattr_set(inode, EXT4_XATTR_INDEX_ENCRYPTION, | ||
1136 | EXT4_XATTR_NAME_ENCRYPTION_CONTEXT, ctx, | ||
1137 | len, 0); | ||
1138 | if (!res) { | ||
1139 | ext4_set_inode_flag(inode, EXT4_INODE_ENCRYPT); | ||
1140 | res = ext4_mark_inode_dirty(handle, inode); | ||
1141 | if (res) | ||
1142 | EXT4_ERROR_INODE(inode, "Failed to mark inode dirty"); | ||
1143 | } | ||
1144 | res2 = ext4_journal_stop(handle); | ||
1145 | if (!res) | ||
1146 | res = res2; | ||
1147 | return res; | ||
1148 | } | ||
1149 | |||
1150 | static int ext4_dummy_context(struct inode *inode) | ||
1151 | { | ||
1152 | return DUMMY_ENCRYPTION_ENABLED(EXT4_SB(inode->i_sb)); | ||
1153 | } | ||
1154 | |||
1155 | static unsigned ext4_max_namelen(struct inode *inode) | ||
1156 | { | ||
1157 | return S_ISLNK(inode->i_mode) ? inode->i_sb->s_blocksize : | ||
1158 | EXT4_NAME_LEN; | ||
1159 | } | ||
1160 | |||
1161 | static struct fscrypt_operations ext4_cryptops = { | ||
1162 | .get_context = ext4_get_context, | ||
1163 | .key_prefix = ext4_key_prefix, | ||
1164 | .prepare_context = ext4_prepare_context, | ||
1165 | .set_context = ext4_set_context, | ||
1166 | .dummy_context = ext4_dummy_context, | ||
1167 | .is_encrypted = ext4_encrypted_inode, | ||
1168 | .empty_dir = ext4_empty_dir, | ||
1169 | .max_namelen = ext4_max_namelen, | ||
1170 | }; | ||
1171 | #else | ||
1172 | static struct fscrypt_operations ext4_cryptops = { | ||
1173 | .is_encrypted = ext4_encrypted_inode, | ||
1174 | }; | ||
1175 | #endif | ||
1176 | |||
1097 | #ifdef CONFIG_QUOTA | 1177 | #ifdef CONFIG_QUOTA |
1098 | static char *quotatypes[] = INITQFNAMES; | 1178 | static char *quotatypes[] = INITQFNAMES; |
1099 | #define QTYPE2NAME(t) (quotatypes[t]) | 1179 | #define QTYPE2NAME(t) (quotatypes[t]) |
@@ -3693,6 +3773,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
3693 | sb->s_op = &ext4_sops; | 3773 | sb->s_op = &ext4_sops; |
3694 | sb->s_export_op = &ext4_export_ops; | 3774 | sb->s_export_op = &ext4_export_ops; |
3695 | sb->s_xattr = ext4_xattr_handlers; | 3775 | sb->s_xattr = ext4_xattr_handlers; |
3776 | sb->s_cop = &ext4_cryptops; | ||
3696 | #ifdef CONFIG_QUOTA | 3777 | #ifdef CONFIG_QUOTA |
3697 | sb->dq_op = &ext4_quota_operations; | 3778 | sb->dq_op = &ext4_quota_operations; |
3698 | if (ext4_has_feature_quota(sb)) | 3779 | if (ext4_has_feature_quota(sb)) |
@@ -4003,6 +4084,11 @@ no_journal: | |||
4003 | ratelimit_state_init(&sbi->s_msg_ratelimit_state, 5 * HZ, 10); | 4084 | ratelimit_state_init(&sbi->s_msg_ratelimit_state, 5 * HZ, 10); |
4004 | 4085 | ||
4005 | kfree(orig_data); | 4086 | kfree(orig_data); |
4087 | #ifdef CONFIG_EXT4_FS_ENCRYPTION | ||
4088 | memcpy(sbi->key_prefix, EXT4_KEY_DESC_PREFIX, | ||
4089 | EXT4_KEY_DESC_PREFIX_SIZE); | ||
4090 | sbi->key_prefix_size = EXT4_KEY_DESC_PREFIX_SIZE; | ||
4091 | #endif | ||
4006 | return 0; | 4092 | return 0; |
4007 | 4093 | ||
4008 | cantfind_ext4: | 4094 | cantfind_ext4: |
@@ -5431,7 +5517,6 @@ out5: | |||
5431 | 5517 | ||
5432 | static void __exit ext4_exit_fs(void) | 5518 | static void __exit ext4_exit_fs(void) |
5433 | { | 5519 | { |
5434 | ext4_exit_crypto(); | ||
5435 | ext4_destroy_lazyinit_thread(); | 5520 | ext4_destroy_lazyinit_thread(); |
5436 | unregister_as_ext2(); | 5521 | unregister_as_ext2(); |
5437 | unregister_as_ext3(); | 5522 | unregister_as_ext3(); |