mirror of https://github.com/torvalds/linux.git
fs: touch up predicts in path lookup
Rationale: - ND_ROOT_PRESET is only set in a condition already marked unlikely - LOOKUP_IS_SCOPED already has unlikely on it, but inconsistently applied - set_root() only fails if there is a bug - most names are not empty (see !*s) - most of the time path_init() does not encounter LOOKUP_CACHED without LOOKUP_RCU - LOOKUP_IN_ROOT is a rarely seen flag Signed-off-by: Mateusz Guzik <mjguzik@gmail.com> Link: https://patch.msgid.link/20251105150630.756606-1-mjguzik@gmail.com Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
9eda581bfe
commit
030e86dfda
18
fs/namei.c
18
fs/namei.c
|
|
@ -990,8 +990,8 @@ static int complete_walk(struct nameidata *nd)
|
||||||
* We don't want to zero nd->root for scoped-lookups or
|
* We don't want to zero nd->root for scoped-lookups or
|
||||||
* externally-managed nd->root.
|
* externally-managed nd->root.
|
||||||
*/
|
*/
|
||||||
if (!(nd->state & ND_ROOT_PRESET))
|
if (likely(!(nd->state & ND_ROOT_PRESET)))
|
||||||
if (!(nd->flags & LOOKUP_IS_SCOPED))
|
if (likely(!(nd->flags & LOOKUP_IS_SCOPED)))
|
||||||
nd->root.mnt = NULL;
|
nd->root.mnt = NULL;
|
||||||
nd->flags &= ~LOOKUP_CACHED;
|
nd->flags &= ~LOOKUP_CACHED;
|
||||||
if (!try_to_unlazy(nd))
|
if (!try_to_unlazy(nd))
|
||||||
|
|
@ -1073,7 +1073,7 @@ static int nd_jump_root(struct nameidata *nd)
|
||||||
}
|
}
|
||||||
if (!nd->root.mnt) {
|
if (!nd->root.mnt) {
|
||||||
int error = set_root(nd);
|
int error = set_root(nd);
|
||||||
if (error)
|
if (unlikely(error))
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
if (nd->flags & LOOKUP_RCU) {
|
if (nd->flags & LOOKUP_RCU) {
|
||||||
|
|
@ -2140,7 +2140,7 @@ static const char *handle_dots(struct nameidata *nd, int type)
|
||||||
|
|
||||||
if (!nd->root.mnt) {
|
if (!nd->root.mnt) {
|
||||||
error = ERR_PTR(set_root(nd));
|
error = ERR_PTR(set_root(nd));
|
||||||
if (error)
|
if (unlikely(error))
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
if (nd->flags & LOOKUP_RCU)
|
if (nd->flags & LOOKUP_RCU)
|
||||||
|
|
@ -2582,10 +2582,10 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
|
||||||
const char *s = nd->pathname;
|
const char *s = nd->pathname;
|
||||||
|
|
||||||
/* LOOKUP_CACHED requires RCU, ask caller to retry */
|
/* LOOKUP_CACHED requires RCU, ask caller to retry */
|
||||||
if ((flags & (LOOKUP_RCU | LOOKUP_CACHED)) == LOOKUP_CACHED)
|
if (unlikely((flags & (LOOKUP_RCU | LOOKUP_CACHED)) == LOOKUP_CACHED))
|
||||||
return ERR_PTR(-EAGAIN);
|
return ERR_PTR(-EAGAIN);
|
||||||
|
|
||||||
if (!*s)
|
if (unlikely(!*s))
|
||||||
flags &= ~LOOKUP_RCU;
|
flags &= ~LOOKUP_RCU;
|
||||||
if (flags & LOOKUP_RCU)
|
if (flags & LOOKUP_RCU)
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
|
|
@ -2599,7 +2599,7 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
|
||||||
nd->r_seq = __read_seqcount_begin(&rename_lock.seqcount);
|
nd->r_seq = __read_seqcount_begin(&rename_lock.seqcount);
|
||||||
smp_rmb();
|
smp_rmb();
|
||||||
|
|
||||||
if (nd->state & ND_ROOT_PRESET) {
|
if (unlikely(nd->state & ND_ROOT_PRESET)) {
|
||||||
struct dentry *root = nd->root.dentry;
|
struct dentry *root = nd->root.dentry;
|
||||||
struct inode *inode = root->d_inode;
|
struct inode *inode = root->d_inode;
|
||||||
if (*s && unlikely(!d_can_lookup(root)))
|
if (*s && unlikely(!d_can_lookup(root)))
|
||||||
|
|
@ -2618,7 +2618,7 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
|
||||||
nd->root.mnt = NULL;
|
nd->root.mnt = NULL;
|
||||||
|
|
||||||
/* Absolute pathname -- fetch the root (LOOKUP_IN_ROOT uses nd->dfd). */
|
/* Absolute pathname -- fetch the root (LOOKUP_IN_ROOT uses nd->dfd). */
|
||||||
if (*s == '/' && !(flags & LOOKUP_IN_ROOT)) {
|
if (*s == '/' && likely(!(flags & LOOKUP_IN_ROOT))) {
|
||||||
error = nd_jump_root(nd);
|
error = nd_jump_root(nd);
|
||||||
if (unlikely(error))
|
if (unlikely(error))
|
||||||
return ERR_PTR(error);
|
return ERR_PTR(error);
|
||||||
|
|
@ -2671,7 +2671,7 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For scoped-lookups we need to set the root to the dirfd as well. */
|
/* For scoped-lookups we need to set the root to the dirfd as well. */
|
||||||
if (flags & LOOKUP_IS_SCOPED) {
|
if (unlikely(flags & LOOKUP_IS_SCOPED)) {
|
||||||
nd->root = nd->path;
|
nd->root = nd->path;
|
||||||
if (flags & LOOKUP_RCU) {
|
if (flags & LOOKUP_RCU) {
|
||||||
nd->root_seq = nd->seq;
|
nd->root_seq = nd->seq;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue