1 Replace (struct super_block *)->s_cop with (struct lustre_sb_info *)->lsi_cop.
2 This is needed so that we can use llcrypt on kernels that do not have
3 (struct super_block *)->s_cop.
5 --- a/libcfs/include/libcfs/crypto/llcrypt.h
6 +++ b/libcfs/include/libcfs/crypto/llcrypt.h
10 #include <linux/slab.h>
11 +#include <lustre_disk.h>
12 #include <uapi/linux/llcrypt.h>
14 #define LL_CRYPTO_BLOCK_SIZE 16
15 @@ -88,8 +89,13 @@ static inline bool llcrypt_has_encryptio
17 static inline bool llcrypt_dummy_context_enabled(struct inode *inode)
19 - return inode->i_sb->s_cop->dummy_context &&
20 - inode->i_sb->s_cop->dummy_context(inode);
21 + struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
26 + return lsi->lsi_cop->dummy_context &&
27 + lsi->lsi_cop->dummy_context(inode);
31 @@ -275,9 +281,12 @@ extern const char *llcrypt_get_symlink(s
32 unsigned int max_size,
33 struct delayed_call *done);
34 static inline void llcrypt_set_ops(struct super_block *sb,
35 - const struct llcrypt_operations *s_cop)
36 + const struct llcrypt_operations *lsi_cop)
39 + struct lustre_sb_info *lsi = s2lsi(sb);
42 + lsi->lsi_cop = lsi_cop;
44 #else /* !CONFIG_LL_ENCRYPTION */
46 @@ -557,7 +566,7 @@ static inline const char *llcrypt_get_sy
49 static inline void llcrypt_set_ops(struct super_block *sb,
50 - const struct llcrypt_operations *s_cop)
51 + const struct llcrypt_operations *lsi_cop)
55 --- a/libcfs/libcfs/crypto/fname.c
56 +++ b/libcfs/libcfs/crypto/fname.c
57 @@ -333,8 +333,12 @@ int llcrypt_setup_filename(struct inode
60 if (llcrypt_has_encryption_key(dir)) {
61 + struct lustre_sb_info *lsi = s2lsi(dir->i_sb);
63 if (!llcrypt_fname_encrypted_size(dir, iname->len,
64 - dir->i_sb->s_cop->max_namelen,
66 + lsi->lsi_cop->max_namelen :
68 &fname->crypto_buf.len))
70 fname->crypto_buf.name = kmalloc(fname->crypto_buf.len,
71 --- a/libcfs/libcfs/crypto/keysetup.c
72 +++ b/libcfs/libcfs/crypto/keysetup.c
73 @@ -424,16 +424,20 @@ int llcrypt_get_encryption_info(struct i
74 union llcrypt_context ctx;
75 struct llcrypt_mode *mode;
76 struct key *master_key = NULL;
77 + struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
80 if (llcrypt_has_encryption_key(inode))
83 - res = llcrypt_initialize(inode->i_sb->s_cop->flags);
87 + res = llcrypt_initialize(lsi->lsi_cop->flags);
91 - res = inode->i_sb->s_cop->get_context(inode, &ctx, sizeof(ctx));
92 + res = lsi->lsi_cop->get_context(inode, &ctx, sizeof(ctx));
94 if (!llcrypt_dummy_context_enabled(inode) ||
95 IS_ENCRYPTED(inode)) {
96 --- a/libcfs/libcfs/crypto/keysetup_v1.c
97 +++ b/libcfs/libcfs/crypto/keysetup_v1.c
98 @@ -325,10 +325,16 @@ int llcrypt_setup_v1_file_key_via_subscr
99 key = find_and_lock_process_key(LLCRYPT_KEY_DESC_PREFIX,
100 ci->ci_policy.v1.master_key_descriptor,
101 ci->ci_mode->keysize, &payload);
102 - if (key == ERR_PTR(-ENOKEY) && ci->ci_inode->i_sb->s_cop->key_prefix) {
103 - key = find_and_lock_process_key(ci->ci_inode->i_sb->s_cop->key_prefix,
104 - ci->ci_policy.v1.master_key_descriptor,
105 - ci->ci_mode->keysize, &payload);
106 + if (key == ERR_PTR(-ENOKEY)) {
107 + struct lustre_sb_info *lsi = s2lsi(ci->ci_inode->i_sb);
109 + if (lsi && lsi->lsi_cop->key_prefix) {
111 + find_and_lock_process_key(lsi->lsi_cop->key_prefix,
112 + ci->ci_policy.v1.master_key_descriptor,
113 + ci->ci_mode->keysize,
119 --- a/libcfs/libcfs/crypto/policy.c
120 +++ b/libcfs/libcfs/crypto/policy.c
121 @@ -209,6 +209,7 @@ static int llcrypt_get_policy(struct ino
123 const struct llcrypt_info *ci;
124 union llcrypt_context ctx;
125 + struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
128 ci = READ_ONCE(inode->i_crypt_info);
129 @@ -221,7 +222,10 @@ static int llcrypt_get_policy(struct ino
130 if (!IS_ENCRYPTED(inode))
133 - ret = inode->i_sb->s_cop->get_context(inode, &ctx, sizeof(ctx));
137 + ret = lsi->lsi_cop->get_context(inode, &ctx, sizeof(ctx));
139 return (ret == -ERANGE) ? -EINVAL : ret;
141 @@ -233,6 +237,7 @@ static int set_encryption_policy(struct
143 union llcrypt_context ctx;
145 + struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
148 if (!llcrypt_supported_policy(policy, inode))
149 @@ -267,7 +272,10 @@ static int set_encryption_policy(struct
151 ctxsize = llcrypt_new_context_from_policy(&ctx, policy);
153 - return inode->i_sb->s_cop->set_context(inode, &ctx, ctxsize, NULL);
157 + return lsi->lsi_cop->set_context(inode, &ctx, ctxsize, NULL);
160 int llcrypt_ioctl_set_policy(struct file *filp, const void __user *arg)
161 @@ -313,11 +321,13 @@ int llcrypt_ioctl_set_policy(struct file
163 ret = llcrypt_get_policy(inode, &existing_policy);
164 if (ret == -ENODATA) {
165 + struct lustre_sb_info *lsi = s2lsi(inode->i_sb);
167 if (!S_ISDIR(inode->i_mode))
169 else if (IS_DEADDIR(inode))
171 - else if (!inode->i_sb->s_cop->empty_dir(inode))
172 + else if (lsi && !lsi->lsi_cop->empty_dir(inode))
175 ret = set_encryption_policy(inode, &policy);
176 @@ -472,6 +482,7 @@ int llcrypt_inherit_context(struct inode
177 union llcrypt_context ctx;
179 struct llcrypt_info *ci;
180 + struct lustre_sb_info *lsi = s2lsi(parent->i_sb);
183 res = llcrypt_get_encryption_info(parent);
184 @@ -482,10 +493,13 @@ int llcrypt_inherit_context(struct inode
191 ctxsize = llcrypt_new_context_from_policy(&ctx, &ci->ci_policy);
193 BUILD_BUG_ON(sizeof(ctx) != LLCRYPT_SET_CONTEXT_MAX_SIZE);
194 - res = parent->i_sb->s_cop->set_context(child, &ctx, ctxsize, fs_data);
195 + res = lsi->lsi_cop->set_context(child, &ctx, ctxsize, fs_data);
198 return preload ? llcrypt_get_encryption_info(child): 0;