simple_lookup(): just set DCACHE_DONTCACHE

No need to mess with ->d_op at all.  Note that ->d_delete that always
returns 1 is equivalent to having DCACHE_DONTCACHE in ->d_flags.
Later the same thing will be placed into ->s_d_flags of the filesystems
where we want that behaviour for all dentries; then the check in
simple_lookup() will at least get unlikely() slapped on it.

NOTE: there are only two filesystems where
	* simple_lookup() might be called
	* default ->d_op is non-NULL
	* its ->d_delete() doesn't always return 1
If not for those, we could have simple_lookup() just set DCACHE_DONTCACHE
without even looking at ->d_op.  Filesystems in question are btrfs
and tracefs; both have ->d_delete() returning 1 on anything fed to
simple_lookup(), so both would be fine with simple_lookup() setting
DCACHE_DONTCACHE regardless of ->d_op.

IOW, we might want to drop the check for ->d_op in simple_lookup();
it's definitely a separate story, though.

Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro 2025-02-23 20:04:30 -05:00
parent d9b13cdad8
commit a97dc087da
1 changed files with 5 additions and 3 deletions

View File

@ -75,9 +75,11 @@ struct dentry *simple_lookup(struct inode *dir, struct dentry *dentry, unsigned
{ {
if (dentry->d_name.len > NAME_MAX) if (dentry->d_name.len > NAME_MAX)
return ERR_PTR(-ENAMETOOLONG); return ERR_PTR(-ENAMETOOLONG);
if (!dentry->d_op) if (!dentry->d_op && !(dentry->d_flags & DCACHE_DONTCACHE)) {
d_set_d_op(dentry, &simple_dentry_operations); spin_lock(&dentry->d_lock);
dentry->d_flags |= DCACHE_DONTCACHE;
spin_unlock(&dentry->d_lock);
}
if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir))
return NULL; return NULL;