1 Linux 5.3 (commit 22d94f493bfb) introduces s_master_keys to struct super_block.
2 As we need encryption support for older kernels, replace this with
3 new lsi_master_keys field in struct lustre_sb_info.
5 --- a/libcfs/libcfs/crypto/keyring.c
6 +++ b/libcfs/libcfs/crypto/keyring.c
7 @@ -82,7 +82,7 @@ static void llcrypt_key_describe(const s
11 - * Type of key in ->s_master_keys. Each key of this type represents a master
12 + * Type of key in ->lsi_master_keys. Each key of this type represents a master
13 * key which has been added to the filesystem. Its payload is a
14 * 'struct llcrypt_master_key'. The "." prefix in the key type name prevents
15 * users from adding keys of this type via the keyrings syscalls rather than via
16 @@ -127,7 +127,7 @@ static struct key_type key_type_llcrypt_
17 .describe = llcrypt_user_key_describe,
20 -/* Search ->s_master_keys or ->mk_users */
21 +/* Search ->lsi_master_keys or ->mk_users */
22 static struct key *search_llcrypt_keyring(struct key *keyring,
23 struct key_type *type,
24 const char *description)
25 @@ -196,13 +196,17 @@ static void format_mk_user_description(
26 mk_identifier, __kuid_val(current_fsuid()));
29 -/* Create ->s_master_keys if needed. Synchronized by llcrypt_add_key_mutex. */
30 +/* Create ->lsi_master_keys if needed. Synchronized by llcrypt_add_key_mutex. */
31 static int allocate_filesystem_keyring(struct super_block *sb)
33 char description[LLCRYPT_FS_KEYRING_DESCRIPTION_SIZE];
35 + struct lustre_sb_info *lsi = s2lsi(sb);
37 - if (sb->s_master_keys)
41 + if (lsi->lsi_master_keys)
44 format_fs_keyring_description(description, sb);
45 @@ -214,18 +218,22 @@ static int allocate_filesystem_keyring(s
46 return PTR_ERR(keyring);
48 /* Pairs with READ_ONCE() in llcrypt_find_master_key() */
49 - smp_store_release(&sb->s_master_keys, keyring);
50 + smp_store_release(&lsi->lsi_master_keys, keyring);
54 void llcrypt_sb_free(struct super_block *sb)
56 - key_put(sb->s_master_keys);
57 - sb->s_master_keys = NULL;
58 + struct lustre_sb_info *lsi = s2lsi(sb);
61 + key_put(lsi->lsi_master_keys);
62 + lsi->lsi_master_keys = NULL;
67 - * Find the specified master key in ->s_master_keys.
68 + * Find the specified master key in ->lsi_master_keys.
69 * Returns ERR_PTR(-ENOKEY) if not found.
71 struct key *llcrypt_find_master_key(struct super_block *sb,
72 @@ -233,9 +241,13 @@ struct key *llcrypt_find_master_key(stru
75 char description[LLCRYPT_MK_DESCRIPTION_SIZE];
76 + struct lustre_sb_info *lsi = s2lsi(sb);
79 + return ERR_PTR(-EINVAL);
81 /* pairs with smp_store_release() in allocate_filesystem_keyring() */
82 - keyring = READ_ONCE(sb->s_master_keys);
83 + keyring = READ_ONCE(lsi->lsi_master_keys);
85 return ERR_PTR(-ENOKEY); /* No keyring yet, so no keys yet. */
87 @@ -432,8 +444,12 @@ static int add_master_key(struct super_b
89 static DEFINE_MUTEX(llcrypt_add_key_mutex);
91 + struct lustre_sb_info *lsi = s2lsi(sb);
97 mutex_lock(&llcrypt_add_key_mutex); /* serialize find + link */
99 key = llcrypt_find_master_key(sb, mk_spec);
100 @@ -441,14 +457,15 @@ retry:
104 - /* Didn't find the key in ->s_master_keys. Add it. */
105 + /* Didn't find the key in ->lsi_master_keys. Add it. */
106 err = allocate_filesystem_keyring(sb);
109 - err = add_new_master_key(secret, mk_spec, sb->s_master_keys);
110 + err = add_new_master_key(secret, mk_spec,
111 + lsi->lsi_master_keys);
114 - * Found the key in ->s_master_keys. Re-add the secret if
115 + * Found the key in ->lsi_master_keys. Re-add the secret if
116 * needed, and add the user to ->mk_users if needed.
118 down_write(&key->sem);
119 --- a/libcfs/libcfs/crypto/keysetup.c
120 +++ b/libcfs/libcfs/crypto/keysetup.c
121 @@ -326,7 +326,7 @@ static int setup_file_encryption_key(str
123 * As a legacy fallback for v1 policies, search for the key in
124 * the current task's subscribed keyrings too. Don't move this
125 - * to before the search of ->s_master_keys, since users
126 + * to before the search of ->lsi_master_keys, since users
127 * shouldn't be able to override filesystem-level keys.
129 return llcrypt_setup_v1_file_key_via_subscribed_keyrings(ci);
130 @@ -406,7 +406,7 @@ static void put_crypt_info(struct llcryp
132 * In addition, if we're removing the last inode from a key that
133 * already had its secret removed, invalidate the key so that it
134 - * gets removed from ->s_master_keys.
135 + * gets removed from ->lsi_master_keys.
137 spin_lock(&mk->mk_decrypted_inodes_lock);
138 list_del(&ci->ci_master_key_link);
139 --- a/libcfs/libcfs/crypto/llcrypt_private.h
140 +++ b/libcfs/libcfs/crypto/llcrypt_private.h
143 #include <libcfs/crypto/llcrypt.h>
144 #include <crypto/hash.h>
145 +#include <lustre_disk.h>
147 #define CONST_STRLEN(str) (sizeof(str) - 1)
149 @@ -372,7 +373,7 @@ struct llcrypt_master_key {
152 * Length of ->mk_decrypted_inodes, plus one if mk_secret is present.
153 - * Once this goes to 0, the master key is removed from ->s_master_keys.
154 + * Once this goes to 0, the master key is removed from ->lsi_master_keys.
155 * The 'struct llcrypt_master_key' will continue to live as long as the
156 * 'struct key' whose payload it is, but we won't let this reference