From nobody Sat Mar 05 19:56:49 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 6460319FF221; Sat, 5 Mar 2022 19:56:50 +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 4K9wTt1zWrz3sl3; Sat, 5 Mar 2022 19:56:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646510210; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1Q9Uk+CMvIRdvUOFu40NR6rlLe0h32c22K9niXjWYj0=; b=b6zvtmu1WExWU0Ig1oIzkO20f1BPDs1j9jtJ4BnXQ5yNa3bGIqTojmRKqYYbZXOW5lcp/5 zjGo0yTgCJbm8Zh/elsQzflrXdxVcWuxIFS/lbRDGp8r3/slU3jf1KZAwP4wBaVRWTflEV Sjhh0bPlm8omH8w0Z5Ex/H0Syry0TNipu2le+bF8+zjugkF9kZt9FTWbAn/NSzLWeRNhaI Q9jOZJwhuC6d3tkTNjl7GDu0QDE7Cfu3Ufz//A50dxzrp6TSX5PT2q+TL4LHSFKK3Mox/u TgV9BWoRFB7aj2wBek/0BlYYVSwETg0DCX43hQHmTJDsuCHCApq1wUHhTpN4/A== 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 19537267EB; Sat, 5 Mar 2022 19:56:50 +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 225Jun6c018108; Sat, 5 Mar 2022 19:56:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 225Junr3018107; Sat, 5 Mar 2022 19:56:49 GMT (envelope-from git) Date: Sat, 5 Mar 2022 19:56:49 GMT Message-Id: <202203051956.225Junr3018107@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: 3343c0afbf8f - stable/13 - cache: add empty path support List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org 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: 3343c0afbf8f8db2a643722e7d4748b8dea1fb27 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646510210; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1Q9Uk+CMvIRdvUOFu40NR6rlLe0h32c22K9niXjWYj0=; b=hcZR7kCoevnpaviy2Qt23R91aUa0Zs547tNIcwotyflaaBtjNrs6s3h7rWQmXOdor+5e7o aoIKokq0y6fM+r5uJycTZlnM7GCZR3QjHSFsqE1x//Bqq0zBC8GPLpX+XRKhXiY3DKQcb/ 0hRo6fFhlDyVy1xsxmqFWKkiBRiojdwOIk9T296oVXVnfYeL4DpSrY+9gqee/sVYDS+bsZ ZwNawahveJhNej+x4jJDGvVuR1rMHSv03rFsW0AQP2QeIhjopButtzI1GHDCxNi18+0a8M /V5C+yEQkbeTnhCvNpmwvhzWwoFbB+nhfuFoVEQH+fF6B0YfwHdPK7sJlrENrg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646510210; a=rsa-sha256; cv=none; b=QAPdP30teQFWUt2VKYRz7xNxldPU2yvxunGJGb0daQbgHnfBEfG8SqBM6AghX+zUPO5Ln7 wgXrnTQrz84Y/z+GxTDkJUS50hi9I3OVGXSj5zotrbycGIAOcf42pHXYIpfPaKtEDELBcU lnEFn2TtU8TKX4INDi3Bpx3pvC6m2p6e0sDkAvlr0OT19CiWNIVUUQAHdTc8GRjW2rAgDx RdSTisE5mPCKHHTewJQHI6N1qMy7kHFuktI1knOlbVJ8mkzkgnu1RWysxXnEqKzJXioE28 PEgDEJ/uNIuck/AvQohh7SL3PpskwxZquN4JT3Le+kmZdWs3ap5UzqkCsQ/Xxw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=3343c0afbf8f8db2a643722e7d4748b8dea1fb27 commit 3343c0afbf8f8db2a643722e7d4748b8dea1fb27 Author: Mateusz Guzik AuthorDate: 2021-09-26 13:00:24 +0000 Commit: Mateusz Guzik CommitDate: 2022-03-05 19:52:29 +0000 cache: add empty path support This avoids spurious drop offs as EMPTY is passed regardless of the actual path name. Pushign the work inside the lookup instead of just ignorign the flag allows avoid checking for empty pathname for all other lookups. (cherry picked from commit 7dd419cabc6bb9e019c56d15f8e6a88ee2f46859) --- sys/kern/kern_descrip.c | 2 +- sys/kern/vfs_cache.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++-- sys/kern/vfs_lookup.c | 18 +++++++------- 3 files changed, 73 insertions(+), 12 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 025259dd20f3..1cf88be09a27 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -3034,7 +3034,7 @@ fgetvp_lookup_smr(int fd, struct nameidata *ndp, struct vnode **vpp, bool *fsear return (EAGAIN); *fsearch = ((fp->f_flag & FSEARCH) != 0); vp = fp->f_vnode; - if (__predict_false(vp == NULL || vp->v_type != VDIR)) { + if (__predict_false(vp == NULL)) { return (EAGAIN); } if (!filecaps_copy(&fde->fde_caps, &ndp->ni_filecaps, false)) { diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index 7273126a008c..313879cf6d1f 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -4174,8 +4174,8 @@ cache_fpl_terminated(struct cache_fpl *fpl) #define CACHE_FPL_SUPPORTED_CN_FLAGS \ (NC_NOMAKEENTRY | NC_KEEPPOSENTRY | LOCKLEAF | LOCKPARENT | WANTPARENT | \ - FAILIFEXISTS | FOLLOW | LOCKSHARED | SAVENAME | SAVESTART | WILLBEDIR | \ - ISOPEN | NOMACCHECK | AUDITVNODE1 | AUDITVNODE2 | NOCAPCHECK) + FAILIFEXISTS | FOLLOW | EMPTYPATH | LOCKSHARED | SAVENAME | SAVESTART | \ + WILLBEDIR | ISOPEN | NOMACCHECK | AUDITVNODE1 | AUDITVNODE2 | NOCAPCHECK) #define CACHE_FPL_INTERNAL_CN_FLAGS \ (ISDOTDOT | MAKEENTRY | ISLASTCN) @@ -4194,6 +4194,7 @@ static bool cache_fpl_istrailingslash(struct cache_fpl *fpl) { + MPASS(fpl->nulchar > fpl->cnp->cn_pnbuf); return (*(fpl->nulchar - 1) == '/'); } @@ -4764,6 +4765,54 @@ cache_fplookup_degenerate(struct cache_fpl *fpl) return (cache_fpl_handled(fpl)); } +static int __noinline +cache_fplookup_emptypath(struct cache_fpl *fpl) +{ + struct nameidata *ndp; + struct componentname *cnp; + enum vgetstate tvs; + struct vnode *tvp; + seqc_t tvp_seqc; + int error, lkflags; + + fpl->tvp = fpl->dvp; + fpl->tvp_seqc = fpl->dvp_seqc; + + ndp = fpl->ndp; + cnp = fpl->cnp; + tvp = fpl->tvp; + tvp_seqc = fpl->tvp_seqc; + + MPASS(*cnp->cn_pnbuf == '\0'); + MPASS((cnp->cn_flags & (LOCKPARENT | WANTPARENT)) == 0); + + if (__predict_false((cnp->cn_flags & EMPTYPATH) == 0)) { + cache_fpl_smr_exit(fpl); + return (cache_fpl_handled_error(fpl, ENOENT)); + } + + tvs = vget_prep_smr(tvp); + cache_fpl_smr_exit(fpl); + if (__predict_false(tvs == VGET_NONE)) { + return (cache_fpl_aborted(fpl)); + } + + if ((cnp->cn_flags & LOCKLEAF) != 0) { + lkflags = LK_SHARED; + if ((cnp->cn_flags & LOCKSHARED) == 0) + lkflags = LK_EXCLUSIVE; + error = vget_finish(tvp, lkflags, tvs); + if (__predict_false(error != 0)) { + return (cache_fpl_aborted(fpl)); + } + } else { + vget_finish_ref(tvp, tvs); + } + + ndp->ni_resflags |= NIRES_EMPTYPATH; + return (cache_fpl_handled(fpl)); +} + static int __noinline cache_fplookup_noentry(struct cache_fpl *fpl) { @@ -4796,6 +4845,10 @@ cache_fplookup_noentry(struct cache_fpl *fpl) return (cache_fplookup_skip_slashes(fpl)); } + if (cnp->cn_pnbuf[0] == '\0') { + return (cache_fplookup_emptypath(fpl)); + } + if (cnp->cn_nameptr[0] == '\0') { if (fpl->tvp == NULL) { return (cache_fplookup_degenerate(fpl)); @@ -5483,6 +5536,7 @@ cache_fplookup_parse(struct cache_fpl *fpl) * * TODO: fix this to be word-sized. */ + MPASS(&cnp->cn_nameptr[fpl->debug.ni_pathlen - 1] >= cnp->cn_pnbuf); KASSERT(&cnp->cn_nameptr[fpl->debug.ni_pathlen - 1] == fpl->nulchar, ("%s: mismatch between pathlen (%zu) and nulchar (%p != %p), string [%s]\n", __func__, fpl->debug.ni_pathlen, &cnp->cn_nameptr[fpl->debug.ni_pathlen - 1], @@ -5736,6 +5790,13 @@ cache_fplookup_failed_vexec(struct cache_fpl *fpl, int error) dvp = fpl->dvp; dvp_seqc = fpl->dvp_seqc; + /* + * Hack: delayed empty path checking. + */ + if (cnp->cn_pnbuf[0] == '\0') { + return (cache_fplookup_emptypath(fpl)); + } + /* * TODO: Due to ignoring trailing slashes lookup will perform a * permission check on the last dir when it should not be doing it. It diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index f4faf0c77210..95c5599ab232 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -465,13 +465,6 @@ namei_getpath(struct nameidata *ndp) if (__predict_false(error != 0)) return (error); - /* - * Don't allow empty pathnames unless EMPTYPATH is specified. - * Caller checks for ENOENT as an indication for the empty path. - */ - if (__predict_false(*cnp->cn_pnbuf == '\0')) - return (ENOENT); - cnp->cn_nameptr = cnp->cn_pnbuf; return (0); } @@ -602,8 +595,6 @@ namei(struct nameidata *ndp) error = namei_getpath(ndp); if (__predict_false(error != 0)) { - if (error == ENOENT && (cnp->cn_flags & EMPTYPATH) != 0) - return (namei_emptypath(ndp)); namei_cleanup_cnp(cnp); SDT_PROBE4(vfs, namei, lookup, return, error, NULL, false, ndp); @@ -646,6 +637,15 @@ namei(struct nameidata *ndp) case CACHE_FPL_STATUS_ABORTED: TAILQ_INIT(&ndp->ni_cap_tracker); MPASS(ndp->ni_lcf == 0); + if (*cnp->cn_pnbuf == '\0') { + if ((cnp->cn_flags & EMPTYPATH) != 0) { + return (namei_emptypath(ndp)); + } + namei_cleanup_cnp(cnp); + SDT_PROBE4(vfs, namei, lookup, return, ENOENT, NULL, + false, ndp); + return (ENOENT); + } error = namei_setup(ndp, &dp, &pwd); if (error != 0) { namei_cleanup_cnp(cnp);