Skip to content

Commit 8b6bb99

Browse files
committed
fscrypt: Factor out a helper to configure the lookup dentry
Both fscrypt_prepare_lookup_partial and fscrypt_prepare_lookup will set DCACHE_NOKEY_NAME for dentries when the key is not available. Extract out a helper to set this flag in a single place, in preparation to also add the optimization that will disable ->d_revalidate if possible. Reviewed-by: Eric Biggers <ebiggers@google.com> Link: https://lore.kernel.org/r/20240221171412.10710-3-krisman@suse.de Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de>
1 parent 2824083 commit 8b6bb99

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

fs/crypto/hooks.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,8 @@ int __fscrypt_prepare_lookup(struct inode *dir, struct dentry *dentry,
102102
if (err && err != -ENOENT)
103103
return err;
104104

105-
if (fname->is_nokey_name) {
106-
spin_lock(&dentry->d_lock);
107-
dentry->d_flags |= DCACHE_NOKEY_NAME;
108-
spin_unlock(&dentry->d_lock);
109-
}
105+
fscrypt_prepare_dentry(dentry, fname->is_nokey_name);
106+
110107
return err;
111108
}
112109
EXPORT_SYMBOL_GPL(__fscrypt_prepare_lookup);
@@ -131,12 +128,10 @@ EXPORT_SYMBOL_GPL(__fscrypt_prepare_lookup);
131128
int fscrypt_prepare_lookup_partial(struct inode *dir, struct dentry *dentry)
132129
{
133130
int err = fscrypt_get_encryption_info(dir, true);
131+
bool is_nokey_name = (!err && !fscrypt_has_encryption_key(dir));
132+
133+
fscrypt_prepare_dentry(dentry, is_nokey_name);
134134

135-
if (!err && !fscrypt_has_encryption_key(dir)) {
136-
spin_lock(&dentry->d_lock);
137-
dentry->d_flags |= DCACHE_NOKEY_NAME;
138-
spin_unlock(&dentry->d_lock);
139-
}
140135
return err;
141136
}
142137
EXPORT_SYMBOL_GPL(fscrypt_prepare_lookup_partial);

include/linux/fscrypt.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ static inline bool fscrypt_is_nokey_name(const struct dentry *dentry)
261261
return dentry->d_flags & DCACHE_NOKEY_NAME;
262262
}
263263

264+
static inline void fscrypt_prepare_dentry(struct dentry *dentry,
265+
bool is_nokey_name)
266+
{
267+
if (is_nokey_name) {
268+
spin_lock(&dentry->d_lock);
269+
dentry->d_flags |= DCACHE_NOKEY_NAME;
270+
spin_unlock(&dentry->d_lock);
271+
}
272+
}
273+
264274
/* crypto.c */
265275
void fscrypt_enqueue_decrypt_work(struct work_struct *);
266276

@@ -425,6 +435,11 @@ static inline bool fscrypt_is_nokey_name(const struct dentry *dentry)
425435
return false;
426436
}
427437

438+
static inline void fscrypt_prepare_dentry(struct dentry *dentry,
439+
bool is_nokey_name)
440+
{
441+
}
442+
428443
/* crypto.c */
429444
static inline void fscrypt_enqueue_decrypt_work(struct work_struct *work)
430445
{

0 commit comments

Comments
 (0)