4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2019, 2020, Whamcloud.
26 * This file is part of Lustre, http://www.lustre.org/
29 #ifndef _LUSTRE_CRYPTO_H_
30 #define _LUSTRE_CRYPTO_H_
33 bool ll_sbi_has_test_dummy_encryption(struct ll_sb_info *sbi);
34 bool ll_sbi_has_encrypt(struct ll_sb_info *sbi);
35 void ll_sbi_set_encrypt(struct ll_sb_info *sbi, bool set);
37 #ifdef CONFIG_LL_ENCRYPTION
38 #include <libcfs/crypto/llcrypt.h>
39 #else /* !CONFIG_LL_ENCRYPTION */
40 #ifdef HAVE_LUSTRE_CRYPTO
41 #define __FS_HAS_ENCRYPTION 1
42 #include <linux/fscrypt.h>
44 #define llcrypt_operations fscrypt_operations
45 #define llcrypt_symlink_data fscrypt_symlink_data
46 #define llcrypt_dummy_context_enabled(inode) \
47 fscrypt_dummy_context_enabled(inode)
48 #define llcrypt_has_encryption_key(inode) fscrypt_has_encryption_key(inode)
49 #define llcrypt_encrypt_pagecache_blocks(page, len, offs, gfp_flags) \
50 fscrypt_encrypt_pagecache_blocks(page, len, offs, gfp_flags)
51 #define llcrypt_decrypt_pagecache_blocks(page, len, offs) \
52 fscrypt_decrypt_pagecache_blocks(page, len, offs)
53 #define llcrypt_inherit_context(parent, child, fs_data, preload) \
54 fscrypt_inherit_context(parent, child, fs_data, preload)
55 #define llcrypt_get_encryption_info(inode) fscrypt_get_encryption_info(inode)
56 #define llcrypt_put_encryption_info(inode) fscrypt_put_encryption_info(inode)
57 #define llcrypt_free_inode(inode) fscrypt_free_inode(inode)
58 #define llcrypt_finalize_bounce_page(pagep) fscrypt_finalize_bounce_page(pagep)
59 #define llcrypt_file_open(inode, filp) fscrypt_file_open(inode, filp)
60 #define llcrypt_ioctl_set_policy(filp, arg) fscrypt_ioctl_set_policy(filp, arg)
61 #define llcrypt_ioctl_get_policy_ex(filp, arg) \
62 fscrypt_ioctl_get_policy_ex(filp, arg)
63 #define llcrypt_ioctl_add_key(filp, arg) fscrypt_ioctl_add_key(filp, arg)
64 #define llcrypt_ioctl_remove_key(filp, arg) fscrypt_ioctl_remove_key(filp, arg)
65 #define llcrypt_ioctl_remove_key_all_users(filp, arg) \
66 fscrypt_ioctl_remove_key_all_users(filp, arg)
67 #define llcrypt_ioctl_get_key_status(filp, arg) \
68 fscrypt_ioctl_get_key_status(filp, arg)
69 #define llcrypt_drop_inode(inode) fscrypt_drop_inode(inode)
70 #define llcrypt_prepare_rename(olddir, olddentry, newdir, newdentry, flags) \
71 fscrypt_prepare_rename(olddir, olddentry, newdir, newdentry, flags)
72 #define llcrypt_prepare_link(old_dentry, dir, dentry) \
73 fscrypt_prepare_link(old_dentry, dir, dentry)
74 #define llcrypt_prepare_setattr(dentry, attr) \
75 fscrypt_prepare_setattr(dentry, attr)
76 #define llcrypt_set_ops(sb, cop) fscrypt_set_ops(sb, cop)
77 #else /* !HAVE_LUSTRE_CRYPTO */
79 #define IS_ENCRYPTED(x) 0
80 #define llcrypt_dummy_context_enabled(inode) NULL
81 /* copied from include/linux/fscrypt.h */
82 #define llcrypt_has_encryption_key(inode) false
83 #define llcrypt_encrypt_pagecache_blocks(page, len, offs, gfp_flags) \
85 #define llcrypt_decrypt_pagecache_blocks(page, len, offs) -EOPNOTSUPP
86 #define llcrypt_inherit_context(parent, child, fs_data, preload) -EOPNOTSUPP
87 #define llcrypt_get_encryption_info(inode) -EOPNOTSUPP
88 #define llcrypt_put_encryption_info(inode) do {} while (0)
89 #define llcrypt_free_inode(inode) do {} while (0)
90 #define llcrypt_finalize_bounce_page(pagep) do {} while (0)
91 static inline int llcrypt_file_open(struct inode *inode, struct file *filp)
93 return IS_ENCRYPTED(inode) ? -EOPNOTSUPP : 0;
95 #define llcrypt_ioctl_set_policy(filp, arg) -EOPNOTSUPP
96 #define llcrypt_ioctl_get_policy_ex(filp, arg) -EOPNOTSUPP
97 #define llcrypt_ioctl_add_key(filp, arg) -EOPNOTSUPP
98 #define llcrypt_ioctl_remove_key(filp, arg) -EOPNOTSUPP
99 #define llcrypt_ioctl_remove_key_all_users(filp, arg) -EOPNOTSUPP
100 #define llcrypt_ioctl_get_key_status(filp, arg) -EOPNOTSUPP
101 #define llcrypt_drop_inode(inode) 0
102 #define llcrypt_prepare_rename(olddir, olddentry, newdir, newdentry, flags) 0
103 #define llcrypt_prepare_link(old_dentry, dir, dentry) 0
104 #define llcrypt_prepare_setattr(dentry, attr) 0
105 #define llcrypt_set_ops(sb, cop) do {} while (0)
106 #endif /* HAVE_LUSTRE_CRYPTO */
107 #endif /* !CONFIG_LL_ENCRYPTION */
109 #endif /* _LUSTRE_CRYPTO_H_ */