Unverified Commit 030e86df authored by Mateusz Guzik's avatar Mateusz Guzik Committed by Christian Brauner
Browse files

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: default avatarMateusz Guzik <mjguzik@gmail.com>
Link: https://patch.msgid.link/20251105150630.756606-1-mjguzik@gmail.com


Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 9eda581b
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -990,8 +990,8 @@ static int complete_walk(struct nameidata *nd)
		 * We don't want to zero nd->root for scoped-lookups or
		 * externally-managed nd->root.
		 */
		if (!(nd->state & ND_ROOT_PRESET))
			if (!(nd->flags & LOOKUP_IS_SCOPED))
		if (likely(!(nd->state & ND_ROOT_PRESET)))
			if (likely(!(nd->flags & LOOKUP_IS_SCOPED)))
				nd->root.mnt = NULL;
		nd->flags &= ~LOOKUP_CACHED;
		if (!try_to_unlazy(nd))
@@ -1073,7 +1073,7 @@ static int nd_jump_root(struct nameidata *nd)
	}
	if (!nd->root.mnt) {
		int error = set_root(nd);
		if (error)
		if (unlikely(error))
			return error;
	}
	if (nd->flags & LOOKUP_RCU) {
@@ -2140,7 +2140,7 @@ static const char *handle_dots(struct nameidata *nd, int type)

		if (!nd->root.mnt) {
			error = ERR_PTR(set_root(nd));
			if (error)
			if (unlikely(error))
				return error;
		}
		if (nd->flags & LOOKUP_RCU)
@@ -2582,10 +2582,10 @@ static const char *path_init(struct nameidata *nd, unsigned flags)
	const char *s = nd->pathname;

	/* 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);

	if (!*s)
	if (unlikely(!*s))
		flags &= ~LOOKUP_RCU;
	if (flags & LOOKUP_RCU)
		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);
	smp_rmb();

	if (nd->state & ND_ROOT_PRESET) {
	if (unlikely(nd->state & ND_ROOT_PRESET)) {
		struct dentry *root = nd->root.dentry;
		struct inode *inode = root->d_inode;
		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;

	/* 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);
		if (unlikely(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. */
	if (flags & LOOKUP_IS_SCOPED) {
	if (unlikely(flags & LOOKUP_IS_SCOPED)) {
		nd->root = nd->path;
		if (flags & LOOKUP_RCU) {
			nd->root_seq = nd->seq;