1 Replace use of inode->i_crypt_info with inode->i_private, cast as a struct llcrypt_info.
2 This is required in order to be able to support encryption on kernels that lack
3 inode->i_crypt_info field.
5 --- a/libcfs/include/libcfs/crypto/llcrypt.h
6 +++ b/libcfs/include/libcfs/crypto/llcrypt.h
7 @@ -81,11 +81,7 @@ struct llcrypt_ctx {
11 -static inline bool llcrypt_has_encryption_key(const struct inode *inode)
13 - /* pairs with cmpxchg_release() in llcrypt_get_encryption_info() */
14 - return READ_ONCE(inode->i_crypt_info) != NULL;
16 +extern bool llcrypt_has_encryption_key(const struct inode *inode);
18 static inline bool llcrypt_dummy_context_enabled(struct inode *inode)
20 --- a/libcfs/libcfs/crypto/crypto.c
21 +++ b/libcfs/libcfs/crypto/crypto.c
22 @@ -158,7 +158,7 @@ int llcrypt_crypt_block(const struct ino
23 struct skcipher_request *req = NULL;
24 DECLARE_CRYPTO_WAIT(wait);
25 struct scatterlist dst, src;
26 - struct llcrypt_info *ci = inode->i_crypt_info;
27 + struct llcrypt_info *ci = llcrypt_info(inode);
28 struct crypto_skcipher *tfm = ci->ci_ctfm;
31 --- a/libcfs/libcfs/crypto/fname.c
32 +++ b/libcfs/libcfs/crypto/fname.c
33 @@ -39,7 +39,7 @@ int fname_encrypt(struct inode *inode, c
35 struct skcipher_request *req = NULL;
36 DECLARE_CRYPTO_WAIT(wait);
37 - struct llcrypt_info *ci = inode->i_crypt_info;
38 + struct llcrypt_info *ci = llcrypt_info(inode);
39 struct crypto_skcipher *tfm = ci->ci_ctfm;
41 struct scatterlist sg;
42 @@ -92,7 +92,7 @@ static int fname_decrypt(struct inode *i
43 struct skcipher_request *req = NULL;
44 DECLARE_CRYPTO_WAIT(wait);
45 struct scatterlist src_sg, dst_sg;
46 - struct llcrypt_info *ci = inode->i_crypt_info;
47 + struct llcrypt_info *ci = llcrypt_info(inode);
48 struct crypto_skcipher *tfm = ci->ci_ctfm;
51 @@ -181,7 +181,7 @@ static int base64_decode(const char *src
52 bool llcrypt_fname_encrypted_size(const struct inode *inode, u32 orig_len,
53 u32 max_len, u32 *encrypted_len_ret)
55 - const struct llcrypt_info *ci = inode->i_crypt_info;
56 + const struct llcrypt_info *ci = llcrypt_info(inode);
57 int padding = 4 << (llcrypt_policy_flags(&ci->ci_policy) &
58 LLCRYPT_POLICY_FLAGS_PAD_MASK);
60 --- a/libcfs/libcfs/crypto/keysetup.c
61 +++ b/libcfs/libcfs/crypto/keysetup.c
62 @@ -501,7 +501,8 @@ int llcrypt_get_encryption_info(struct i
66 - if (cmpxchg_release(&inode->i_crypt_info, NULL, crypt_info) == NULL) {
67 + if (cmpxchg_release(&(llcrypt_info_nocast(inode)), NULL,
68 + crypt_info) == NULL) {
70 struct llcrypt_master_key *mk =
71 master_key->payload.data[0];
72 @@ -538,8 +539,8 @@ EXPORT_SYMBOL(llcrypt_get_encryption_inf
74 void llcrypt_put_encryption_info(struct inode *inode)
76 - put_crypt_info(inode->i_crypt_info);
77 - inode->i_crypt_info = NULL;
78 + put_crypt_info(llcrypt_info(inode));
79 + llcrypt_info_nocast(inode) = NULL;
81 EXPORT_SYMBOL(llcrypt_put_encryption_info);
83 @@ -569,9 +570,10 @@ EXPORT_SYMBOL(llcrypt_free_inode);
85 int llcrypt_drop_inode(struct inode *inode)
87 - const struct llcrypt_info *ci = READ_ONCE(inode->i_crypt_info);
88 + const struct llcrypt_info *ci;
89 const struct llcrypt_master_key *mk;
91 + ci = (struct llcrypt_info *)READ_ONCE(llcrypt_info_nocast(inode));
93 * If ci is NULL, then the inode doesn't have an encryption key set up
94 * so it's irrelevant. If ci_master_key is NULL, then the master key
95 @@ -593,3 +595,10 @@ int llcrypt_drop_inode(struct inode *ino
96 return !is_master_key_secret_present(&mk->mk_secret);
98 EXPORT_SYMBOL_GPL(llcrypt_drop_inode);
100 +inline bool llcrypt_has_encryption_key(const struct inode *inode)
102 + /* pairs with cmpxchg_release() in llcrypt_get_encryption_info() */
103 + return READ_ONCE(llcrypt_info_nocast(inode)) != NULL;
105 +EXPORT_SYMBOL_GPL(llcrypt_has_encryption_key);
106 --- a/libcfs/libcfs/crypto/llcrypt_private.h
107 +++ b/libcfs/libcfs/crypto/llcrypt_private.h
109 #define CRYPTO_TFM_REQ_FORBID_WEAK_KEYS CRYPTO_TFM_REQ_WEAK_KEY
112 +#define llcrypt_info(inode) ((struct llcrypt_info *)(inode)->i_private)
113 +#define llcrypt_info_nocast(inode) ((inode)->i_private)
115 #define CONST_STRLEN(str) (sizeof(str) - 1)
117 #define FS_KEY_DERIVATION_NONCE_SIZE 16
118 @@ -160,8 +163,8 @@ struct llcrypt_symlink_data {
119 * llcrypt_info - the "encryption key" for an inode
121 * When an encrypted file's key is made available, an instance of this struct is
122 - * allocated and stored in ->i_crypt_info. Once created, it remains until the
123 - * inode is evicted.
124 + * allocated and stored in '(struct llcrypt_info *)inode->i_private'.
125 + * Once created, it remains until the inode is evicted.
127 struct llcrypt_info {
129 --- a/libcfs/libcfs/crypto/policy.c
130 +++ b/libcfs/libcfs/crypto/policy.c
131 @@ -212,7 +212,7 @@ static int llcrypt_get_policy(struct ino
132 struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
135 - ci = READ_ONCE(inode->i_crypt_info);
136 + ci = (struct llcrypt_info *)READ_ONCE(llcrypt_info_nocast(inode));
138 /* key available, use the cached policy */
139 *policy = ci->ci_policy;
140 @@ -472,7 +472,7 @@ EXPORT_SYMBOL(llcrypt_has_permitted_cont
141 * @parent: Parent inode from which the context is inherited.
142 * @child: Child inode that inherits the context from @parent.
143 * @fs_data: private data given by FS.
144 - * @preload: preload child i_crypt_info if true
145 + * @preload: preload child crypt info if true
147 * Return: 0 on success, -errno on failure
149 @@ -489,7 +489,7 @@ int llcrypt_inherit_context(struct inode
153 - ci = READ_ONCE(parent->i_crypt_info);
154 + ci = (struct llcrypt_info *)READ_ONCE(llcrypt_info_nocast(parent));