Whamcloud - gitweb
LU-14306 sec: get rid of bad rss-counter state messages
[fs/lustre-release.git] / lustre / include / lustre_crypto.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2019, 2020, Whamcloud.
24  */
25 /*
26  * This file is part of Lustre, http://www.lustre.org/
27  */
28
29 #ifndef _LUSTRE_CRYPTO_H_
30 #define _LUSTRE_CRYPTO_H_
31
32 struct ll_sb_info;
33 int ll_set_encflags(struct inode *inode, void *encctx, __u32 encctxlen,
34                     bool preload);
35 void llcrypt_free_ctx(void *encctx, __u32 size);
36 bool ll_sbi_has_test_dummy_encryption(struct ll_sb_info *sbi);
37 bool ll_sbi_has_encrypt(struct ll_sb_info *sbi);
38 void ll_sbi_set_encrypt(struct ll_sb_info *sbi, bool set);
39
40 #ifdef CONFIG_LL_ENCRYPTION
41 #include <libcfs/crypto/llcrypt.h>
42 #else /* !CONFIG_LL_ENCRYPTION */
43 #ifdef HAVE_LUSTRE_CRYPTO
44 #define __FS_HAS_ENCRYPTION 1
45 #include <linux/fscrypt.h>
46
47 #define llcrypt_operations      fscrypt_operations
48 #define llcrypt_symlink_data    fscrypt_symlink_data
49 #define llcrypt_dummy_context_enabled(inode) \
50         fscrypt_dummy_context_enabled(inode)
51 #define llcrypt_has_encryption_key(inode) fscrypt_has_encryption_key(inode)
52 #define llcrypt_encrypt_pagecache_blocks(page, len, offs, gfp_flags)    \
53         fscrypt_encrypt_pagecache_blocks(page, len, offs, gfp_flags)
54 #define llcrypt_encrypt_block_inplace(inode, page, len, offs, lblk, gfp_flags) \
55         fscrypt_encrypt_block_inplace(inode, page, len, offs, lblk, gfp_flags)
56 #define llcrypt_decrypt_pagecache_blocks(page, len, offs)       \
57         fscrypt_decrypt_pagecache_blocks(page, len, offs)
58 #define llcrypt_decrypt_block_inplace(inode, page, len, offs, lblk_num) \
59         fscrypt_decrypt_block_inplace(inode, page, len, offs, lblk_num)
60 #define llcrypt_inherit_context(parent, child, fs_data, preload)        \
61         fscrypt_inherit_context(parent, child, fs_data, preload)
62 #define llcrypt_get_encryption_info(inode) fscrypt_get_encryption_info(inode)
63 #define llcrypt_put_encryption_info(inode) fscrypt_put_encryption_info(inode)
64 #define llcrypt_free_inode(inode)          fscrypt_free_inode(inode)
65 #define llcrypt_finalize_bounce_page(pagep)  fscrypt_finalize_bounce_page(pagep)
66 #define llcrypt_file_open(inode, filp)  fscrypt_file_open(inode, filp)
67 #define llcrypt_ioctl_set_policy(filp, arg)  fscrypt_ioctl_set_policy(filp, arg)
68 #define llcrypt_ioctl_get_policy_ex(filp, arg)  \
69         fscrypt_ioctl_get_policy_ex(filp, arg)
70 #define llcrypt_ioctl_add_key(filp, arg)        fscrypt_ioctl_add_key(filp, arg)
71 #define llcrypt_ioctl_remove_key(filp, arg)  fscrypt_ioctl_remove_key(filp, arg)
72 #define llcrypt_ioctl_remove_key_all_users(filp, arg)   \
73         fscrypt_ioctl_remove_key_all_users(filp, arg)
74 #define llcrypt_ioctl_get_key_status(filp, arg) \
75         fscrypt_ioctl_get_key_status(filp, arg)
76 #define llcrypt_drop_inode(inode)       fscrypt_drop_inode(inode)
77 #define llcrypt_prepare_rename(olddir, olddentry, newdir, newdentry, flags) \
78         fscrypt_prepare_rename(olddir, olddentry, newdir, newdentry, flags)
79 #define llcrypt_prepare_link(old_dentry, dir, dentry)   \
80         fscrypt_prepare_link(old_dentry, dir, dentry)
81 #define llcrypt_prepare_setattr(dentry, attr)           \
82         fscrypt_prepare_setattr(dentry, attr)
83 #define llcrypt_set_ops(sb, cop)        fscrypt_set_ops(sb, cop)
84 #else /* !HAVE_LUSTRE_CRYPTO */
85 #undef IS_ENCRYPTED
86 #define IS_ENCRYPTED(x) 0
87 #define llcrypt_dummy_context_enabled(inode)    NULL
88 /* copied from include/linux/fscrypt.h */
89 #define llcrypt_has_encryption_key(inode) false
90 #define llcrypt_encrypt_pagecache_blocks(page, len, offs, gfp_flags)    \
91         ERR_PTR(-EOPNOTSUPP)
92 #define llcrypt_encrypt_block_inplace(inode, page, len, offs, lblk, gfp_flags) \
93         -EOPNOTSUPP
94 #define llcrypt_decrypt_pagecache_blocks(page, len, offs)       -EOPNOTSUPP
95 #define llcrypt_decrypt_block_inplace(inode, page, len, offs, lblk_num) \
96         -EOPNOTSUPP
97 #define llcrypt_inherit_context(parent, child, fs_data, preload)     -EOPNOTSUPP
98 #define llcrypt_get_encryption_info(inode)                      -EOPNOTSUPP
99 #define llcrypt_put_encryption_info(inode)                      do {} while (0)
100 #define llcrypt_free_inode(inode)                               do {} while (0)
101 #define llcrypt_finalize_bounce_page(pagep)                     do {} while (0)
102 static inline int llcrypt_file_open(struct inode *inode, struct file *filp)
103 {
104         return IS_ENCRYPTED(inode) ? -EOPNOTSUPP : 0;
105 }
106 #define llcrypt_ioctl_set_policy(filp, arg)                     -EOPNOTSUPP
107 #define llcrypt_ioctl_get_policy_ex(filp, arg)                  -EOPNOTSUPP
108 #define llcrypt_ioctl_add_key(filp, arg)                        -EOPNOTSUPP
109 #define llcrypt_ioctl_remove_key(filp, arg)                     -EOPNOTSUPP
110 #define llcrypt_ioctl_remove_key_all_users(filp, arg)           -EOPNOTSUPP
111 #define llcrypt_ioctl_get_key_status(filp, arg)                 -EOPNOTSUPP
112 #define llcrypt_drop_inode(inode)                                0
113 #define llcrypt_prepare_rename(olddir, olddentry, newdir, newdentry, flags)    0
114 #define llcrypt_prepare_link(old_dentry, dir, dentry)            0
115 #define llcrypt_prepare_setattr(dentry, attr)                    0
116 #define llcrypt_set_ops(sb, cop)                                do {} while (0)
117 #endif /* HAVE_LUSTRE_CRYPTO */
118 #endif /* !CONFIG_LL_ENCRYPTION */
119
120 #endif /* _LUSTRE_CRYPTO_H_ */