From owner-dev-commits-src-all@freebsd.org Thu Feb 4 18:01:56 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 36D1A52A855; Thu, 4 Feb 2021 18:01:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DWmb56kwfz4hdL; Thu, 4 Feb 2021 18:01:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A399C10452; Thu, 4 Feb 2021 18:01:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 114I1r45052741; Thu, 4 Feb 2021 18:01:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 114I1rQV052740; Thu, 4 Feb 2021 18:01:53 GMT (envelope-from git) Date: Thu, 4 Feb 2021 18:01:53 GMT Message-Id: <202102041801.114I1rQV052740@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 2edd6140e9a1 - stable/13 - cache: add delayed degenerate path handling MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 2edd6140e9a157b5493cb287e30f8a15038eb95e Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Feb 2021 18:01:56 -0000 The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=2edd6140e9a157b5493cb287e30f8a15038eb95e commit 2edd6140e9a157b5493cb287e30f8a15038eb95e Author: Mateusz Guzik AuthorDate: 2021-01-31 20:54:35 +0000 Commit: Mateusz Guzik CommitDate: 2021-02-04 18:00:57 +0000 cache: add delayed degenerate path handling (cherry picked from commit 6f19dc2124a31aadf419743288d2ec1abd895563) --- sys/kern/vfs_cache.c | 57 +++++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index b13ebf66c49a..db482ea4eba3 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -3737,7 +3737,6 @@ static int cache_fplookup_cross_mount(struct cache_fpl *fpl); static int cache_fplookup_partial_setup(struct cache_fpl *fpl); static int cache_fplookup_skip_slashes(struct cache_fpl *fpl); static int cache_fplookup_trailingslash(struct cache_fpl *fpl); -static int cache_fplookup_preparse(struct cache_fpl *fpl); static void cache_fpl_pathlen_dec(struct cache_fpl *fpl); static void cache_fpl_pathlen_inc(struct cache_fpl *fpl); static void cache_fpl_pathlen_add(struct cache_fpl *fpl, size_t n); @@ -4518,6 +4517,9 @@ cache_fplookup_degenerate(struct cache_fpl *fpl) struct vnode *dvp; enum vgetstate dvs; int error, lkflags; +#ifdef INVARIANTS + char *cp; +#endif fpl->tvp = fpl->dvp; fpl->tvp_seqc = fpl->dvp_seqc; @@ -4525,6 +4527,14 @@ cache_fplookup_degenerate(struct cache_fpl *fpl) cnp = fpl->cnp; dvp = fpl->dvp; +#ifdef INVARIANTS + for (cp = cnp->cn_pnbuf; *cp != '\0'; cp++) { + KASSERT(*cp == '/', + ("%s: encountered non-slash; string [%s]\n", __func__, + cnp->cn_pnbuf)); + } +#endif + if (__predict_false(cnp->cn_nameiop != LOOKUP)) { cache_fpl_smr_exit(fpl); return (cache_fpl_handled_error(fpl, EISDIR)); @@ -4589,6 +4599,9 @@ cache_fplookup_noentry(struct cache_fpl *fpl) } if (cnp->cn_nameptr[0] == '\0') { + if (fpl->tvp == NULL) { + return (cache_fplookup_degenerate(fpl)); + } return (cache_fplookup_trailingslash(fpl)); } @@ -4897,7 +4910,7 @@ cache_symlink_resolve(struct cache_fpl *fpl, const char *string, size_t len) cache_fpl_pathlen_add(fpl, adjust); cnp->cn_nameptr = cnp->cn_pnbuf; fpl->nulchar = &cnp->cn_nameptr[ndp->ni_pathlen - 1]; - + fpl->tvp = NULL; return (0); } @@ -4957,8 +4970,7 @@ cache_fplookup_symlink(struct cache_fpl *fpl) return (cache_fpl_aborted(fpl)); } } - - return (cache_fplookup_preparse(fpl)); + return (0); } static int @@ -5238,30 +5250,6 @@ cache_fpl_pathlen_dec(struct cache_fpl *fpl) } #endif -static int __always_inline -cache_fplookup_preparse(struct cache_fpl *fpl) -{ - struct componentname *cnp; - - cnp = fpl->cnp; - - if (__predict_false(cnp->cn_nameptr[0] == '\0')) { - return (cache_fplookup_degenerate(fpl)); - } - - /* - * By this point the shortest possible pathname is one character + nul - * terminator, hence 2. - */ - KASSERT(fpl->debug.ni_pathlen >= 2, ("%s: pathlen %zu\n", __func__, - fpl->debug.ni_pathlen)); - KASSERT(&cnp->cn_nameptr[fpl->debug.ni_pathlen - 2] == fpl->nulchar - 1, - ("%s: mismatch on string (%p != %p) [%s]\n", __func__, - &cnp->cn_nameptr[fpl->debug.ni_pathlen - 2], fpl->nulchar - 1, - cnp->cn_pnbuf)); - return (0); -} - static void cache_fplookup_parse(struct cache_fpl *fpl) { @@ -5543,6 +5531,13 @@ cache_fplookup_failed_vexec(struct cache_fpl *fpl, int error) return (cache_fpl_aborted(fpl)); } + /* + * Hack: delayed degenerate path checking. + */ + if (cnp->cn_nameptr[0] == '\0' && fpl->tvp == NULL) { + return (cache_fplookup_degenerate(fpl)); + } + /* * Hack: delayed name len checking. */ @@ -5634,10 +5629,7 @@ cache_fplookup_impl(struct vnode *dvp, struct cache_fpl *fpl) return (cache_fpl_aborted(fpl)); } - error = cache_fplookup_preparse(fpl); - if (__predict_false(cache_fpl_terminated(fpl))) { - return (error); - } + MPASS(fpl->tvp == NULL); for (;;) { cache_fplookup_parse(fpl); @@ -5797,6 +5789,7 @@ cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status, fpl.nulchar = &cnp->cn_nameptr[ndp->ni_pathlen - 1]; fpl.fsearch = false; fpl.savename = (cnp->cn_flags & SAVENAME) != 0; + fpl.tvp = NULL; /* for degenerate path handling */ fpl.pwd = pwdp; pwd = pwd_get_smr(); *(fpl.pwd) = pwd;