From nobody Mon Dec 19 16:50:31 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 4NbQgX1ZcQz1GB6C; Mon, 19 Dec 2022 16:50:32 +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 4NbQgX0pGhz3hqG; Mon, 19 Dec 2022 16:50:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671468632; 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=DuaVwrcVrOVPAGuez4watfuJZa8XeYOhFhnYKX0Knf0=; b=ApwU7qyw934m0apJqRlSK2HbIkDlR8a0gEizjE289m1Bd3iFhVpK03jQINtSkwk3FpCtrJ dpGDfls+l3hXzXb8aT1P7gVm99kIGgKdTUvexMTfYDqcHfOFR4NVuv2z5761iADkG9BltM aa+s1jxCO2fCM0EnNB9DqmEnpCt5w5VDQYpEdEc/cGyFMTUwz80O/X+Ss29GwXPth/xAGE 7iZSQLFxmm3qMuOtF/F0/NTDZqoLSwm/QiOcj26BqZ4zG+wasFQnB0E9ymV0tsFARqpL2B Qnjw4FyF2O71GPtO/8vs3OUWmrohpeW/xpbJT5pnsNJaOEhYARrDJVM8ZZD1rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671468632; 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=DuaVwrcVrOVPAGuez4watfuJZa8XeYOhFhnYKX0Knf0=; b=RfxXVwq8bg4V20byLM6DoJxI8Ul0/V9dNmWYjQDDow+3uGu4sd5aj14pJH1JJNCiZ1fCUV d0awHyZkVQVK7jqfVj5lhugkbn5malObV3AbMXRzURjI86YBd/0SmRvpPXKWHRcJRYKdYe riZ3R1GAKOrBhP6AFIFYdOuEEW0Gh62UBhE0ZFBq9UM0b1ecUq+F96dbV7PU/ZfnEZyVBT /J+fAKZbPEuopX0yauYTOlfvAi/EcO8FQFeY+6ChOHq0rlf82Lz+4WNGQCS9E9hPpPuqaR 7jd3Lu7BWMj6yJnreZjH5up0W9zxHDDf8Cw9ZFp5SxUnf8jvFbNkaUD2qDnCxg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1671468632; a=rsa-sha256; cv=none; b=lxJDL3e1SZbSFqno4t7L75PAhiPU67rcK0QWdvFJqoZUdP1d6sYfLR/h9gWHtzutal2Olb onA7mJ+X9RTBui83y3u3D+BlCKO6KG1O7TED51pFbo2X7UNfvkwW8uYnj1wK1xNuBuC3Jb fu3znHFiT9LnbBhY9Psaw1StDRz2FkgSkfzzN2xfNhJQchuD2MVSyDgurge09rLNDAqjdP nmEazMToKKiKsQbMnXWhC+5FUgEE8ck+3smaVNuin/bHoNB2pLVLxm2dHb5s+N3AC3/LXv IkkA3zoH2hu76uO/wvr6IIhqVYmx9aWbeKT0A/MbEAl7IBYCLOYXm/NfJmMymA== 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 4NbQgW71Mwz12mx; Mon, 19 Dec 2022 16:50:31 +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 2BJGoVmt094488; Mon, 19 Dec 2022 16:50:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BJGoVbT094487; Mon, 19 Dec 2022 16:50:31 GMT (envelope-from git) Date: Mon, 19 Dec 2022 16:50:31 GMT Message-Id: <202212191650.2BJGoVbT094487@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Doug Rabson Subject: git: 78d35459a258 - main - Add vn_path_to_global_path_hardlink 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: dfr X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 78d35459a2586da024ac18e8768b44893c7184e7 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dfr: URL: https://cgit.FreeBSD.org/src/commit/?id=78d35459a2586da024ac18e8768b44893c7184e7 commit 78d35459a2586da024ac18e8768b44893c7184e7 Author: Doug Rabson AuthorDate: 2022-12-02 14:09:31 +0000 Commit: Doug Rabson CommitDate: 2022-12-19 16:44:59 +0000 Add vn_path_to_global_path_hardlink This is similar to vn_path_to_global_path but allows for regular files which may not be present in the cache. Reviewed by: mjg, kib Tested by: pho --- sys/kern/vfs_cache.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++-- sys/sys/vnode.h | 3 +++ 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index d7b235c12f7b..f2dd8328278d 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -3812,6 +3812,71 @@ out: return (error); } +/* + * This is similar to vn_path_to_global_path but allows for regular + * files which may not be present in the cache. + * + * Requires a locked, referenced vnode. + * Vnode is re-locked on success or ENODEV, otherwise unlocked. + */ +int +vn_path_to_global_path_hardlink(struct thread *td, struct vnode *vp, + struct vnode *dvp, char *path, u_int pathlen, const char *leaf_name, + size_t leaf_length) +{ + struct nameidata nd; + struct vnode *vp1; + char *rpath, *fbuf; + size_t len; + int error; + + ASSERT_VOP_ELOCKED(vp, __func__); + + /* + * Construct global filesystem path from dvp, vp and leaf + * name. + */ + VOP_UNLOCK(vp); + error = vn_fullpath_hardlink(vp, dvp, leaf_name, leaf_length, + &rpath, &fbuf, &len); + + if (error != 0) { + vrele(vp); + goto out; + } + + if (strlen(rpath) >= pathlen) { + vrele(vp); + error = ENAMETOOLONG; + goto out; + } + + /* + * Re-lookup the vnode by path to detect a possible rename. + * As a side effect, the vnode is relocked. + * If vnode was renamed, return ENOENT. + */ + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNODE1, UIO_SYSSPACE, path); + error = namei(&nd); + if (error != 0) { + vrele(vp); + goto out; + } + NDFREE_PNBUF(&nd); + vp1 = nd.ni_vp; + vrele(vp); + if (vp1 == vp) + strcpy(path, rpath); + else { + vput(vp1); + error = ENOENT; + } + +out: + free(fbuf, M_TEMP); + return (error); +} + #ifdef DDB static void db_print_vpath(struct vnode *vp) @@ -5339,7 +5404,7 @@ cache_fplookup_climb_mount(struct cache_fpl *fpl) vp = fpl->tvp; vp_seqc = fpl->tvp_seqc; - VNPASS(vp->v_type == VDIR || vp->v_type == VBAD, vp); + VNPASS(vp->v_type == VDIR || vp->v_type == VREG || vp->v_type == VBAD, vp); mp = atomic_load_ptr(&vp->v_mountedhere); if (__predict_false(mp == NULL)) { return (0); @@ -5396,7 +5461,7 @@ cache_fplookup_cross_mount(struct cache_fpl *fpl) vp = fpl->tvp; vp_seqc = fpl->tvp_seqc; - VNPASS(vp->v_type == VDIR || vp->v_type == VBAD, vp); + VNPASS(vp->v_type == VDIR || vp->v_type == VREG || vp->v_type == VBAD, vp); mp = atomic_load_ptr(&vp->v_mountedhere); if (__predict_false(mp == NULL)) { return (0); diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index 52f735713a30..89784dd4e455 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -714,6 +714,9 @@ struct vnode * int vn_commname(struct vnode *vn, char *buf, u_int buflen); int vn_path_to_global_path(struct thread *td, struct vnode *vp, char *path, u_int pathlen); +int vn_path_to_global_path_hardlink(struct thread *td, struct vnode *vp, + struct vnode *dvp, char *path, u_int pathlen, const char *leaf_name, + size_t leaf_length); int vaccess(enum vtype type, mode_t file_mode, uid_t file_uid, gid_t file_gid, accmode_t accmode, struct ucred *cred); int vaccess_vexec_smr(mode_t file_mode, uid_t file_uid, gid_t file_gid,