Whamcloud - gitweb
LU-12275 sec: atomicity of encryption context getting/setting
[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_decrypt_pagecache_blocks(page, len, offs)       \
55         fscrypt_decrypt_pagecache_blocks(page, len, offs)
56 #define llcrypt_inherit_context(parent, child, fs_data, preload)        \
57         fscrypt_inherit_context(parent, child, fs_data, preload)
58 #define llcrypt_get_encryption_info(inode) fscrypt_get_encryption_info(inode)
59 #define llcrypt_put_encryption_info(inode) fscrypt_put_encryption_info(inode)
60 #define llcrypt_free_inode(inode)          fscrypt_free_inode(inode)
61 #define llcrypt_finalize_bounce_page(pagep)  fscrypt_finalize_bounce_page(pagep)
62 #define llcrypt_file_open(inode, filp)  fscrypt_file_open(inode, filp)
63 #define llcrypt_ioctl_set_policy(filp, arg)  fscrypt_ioctl_set_policy(filp, arg)
64 #define llcrypt_ioctl_get_policy_ex(filp, arg)  \
65         fscrypt_ioctl_get_policy_ex(filp, arg)
66 #define llcrypt_ioctl_add_key(filp, arg)        fscrypt_ioctl_add_key(filp, arg)
67 #define llcrypt_ioctl_remove_key(filp, arg)  fscrypt_ioctl_remove_key(filp, arg)
68 #define llcrypt_ioctl_remove_key_all_users(filp, arg)   \
69         fscrypt_ioctl_remove_key_all_users(filp, arg)
70 #define llcrypt_ioctl_get_key_status(filp, arg) \
71         fscrypt_ioctl_get_key_status(filp, arg)
72 #define llcrypt_drop_inode(inode)       fscrypt_drop_inode(inode)
73 #define llcrypt_prepare_rename(olddir, olddentry, newdir, newdentry, flags) \
74         fscrypt_prepare_rename(olddir, olddentry, newdir, newdentry, flags)
75 #define llcrypt_prepare_link(old_dentry, dir, dentry)   \
76         fscrypt_prepare_link(old_dentry, dir, dentry)
77 #define llcrypt_prepare_setattr(dentry, attr)           \
78         fscrypt_prepare_setattr(dentry, attr)
79 #define llcrypt_set_ops(sb, cop)        fscrypt_set_ops(sb, cop)
80 #else /* !HAVE_LUSTRE_CRYPTO */
81 #undef IS_ENCRYPTED
82 #define IS_ENCRYPTED(x) 0
83 #define llcrypt_dummy_context_enabled(inode)    NULL
84 /* copied from include/linux/fscrypt.h */
85 #define llcrypt_has_encryption_key(inode) false
86 #define llcrypt_encrypt_pagecache_blocks(page, len, offs, gfp_flags)    \
87         ERR_PTR(-EOPNOTSUPP)
88 #define llcrypt_decrypt_pagecache_blocks(page, len, offs)       -EOPNOTSUPP
89 #define llcrypt_inherit_context(parent, child, fs_data, preload)     -EOPNOTSUPP
90 #define llcrypt_get_encryption_info(inode)                      -EOPNOTSUPP
91 #define llcrypt_put_encryption_info(inode)                      do {} while (0)
92 #define llcrypt_free_inode(inode)                               do {} while (0)
93 #define llcrypt_finalize_bounce_page(pagep)                     do {} while (0)
94 static inline int llcrypt_file_open(struct inode *inode, struct file *filp)
95 {
96         return IS_ENCRYPTED(inode) ? -EOPNOTSUPP : 0;
97 }
98 #define llcrypt_ioctl_set_policy(filp, arg)                     -EOPNOTSUPP
99 #define llcrypt_ioctl_get_policy_ex(filp, arg)                  -EOPNOTSUPP
100 #define llcrypt_ioctl_add_key(filp, arg)                        -EOPNOTSUPP
101 #define llcrypt_ioctl_remove_key(filp, arg)                     -EOPNOTSUPP
102 #define llcrypt_ioctl_remove_key_all_users(filp, arg)           -EOPNOTSUPP
103 #define llcrypt_ioctl_get_key_status(filp, arg)                 -EOPNOTSUPP
104 #define llcrypt_drop_inode(inode)                                0
105 #define llcrypt_prepare_rename(olddir, olddentry, newdir, newdentry, flags)    0
106 #define llcrypt_prepare_link(old_dentry, dir, dentry)            0
107 #define llcrypt_prepare_setattr(dentry, attr)                    0
108 #define llcrypt_set_ops(sb, cop)                                do {} while (0)
109 #endif /* HAVE_LUSTRE_CRYPTO */
110 #endif /* !CONFIG_LL_ENCRYPTION */
111
112 #endif /* _LUSTRE_CRYPTO_H_ */