From: Christian Brauner brauner@kernel.org
mainline inclusion from mainline-v6.12-rc1 commit 4770d96a6d89c7dd5675056629c0008f7f8106bf category: performance bugzilla: https://gitee.com/src-openeuler/kernel/issues/IB1S01
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?i...
--------------------------------
Perform the check for trailing slashes right in the fastpath check and don't bother with any additional work.
Signed-off-by: Christian Brauner brauner@kernel.org Signed-off-by: Jinjie Ruan ruanjinjie@huawei.com --- fs/namei.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/fs/namei.c b/fs/namei.c index fbbcec1cbb46..0108d86b83ee 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3516,6 +3516,9 @@ static struct dentry *lookup_fast_for_open(struct nameidata *nd, int open_flag) struct dentry *dentry;
if (open_flag & O_CREAT) { + if (trailing_slashes(nd)) + return ERR_PTR(-EISDIR); + /* Don't bother on an O_EXCL create */ if (open_flag & O_EXCL) return NULL; @@ -3581,20 +3584,13 @@ static const char *open_last_lookups(struct nameidata *nd, bool unlazied;
/* can stay in rcuwalk if not auditing */ - if (dentry && audit_dummy_context()) { - if (trailing_slashes(nd)) - return ERR_PTR(-EISDIR); + if (dentry && audit_dummy_context()) goto finish_lookup; - } unlazied = dentry ? try_to_unlazy_next(nd, dentry) : try_to_unlazy(nd); if (!unlazied) return ERR_PTR(-ECHILD); } - if (trailing_slashes(nd)) { - dput(dentry); - return ERR_PTR(-EISDIR); - } if (dentry) goto finish_lookup; }