From nobody Fri Jan 06 09:46:32 2023 X-Original-To: dev-commits-src-branches@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 4NpJQ03Hzwz2pDDG; Fri, 6 Jan 2023 09:46: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 4NpJQ02ZGqz3wFb; Fri, 6 Jan 2023 09:46:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1672998392; 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=UfblyzYgvU499OU57PRZ8a/U/kU9N/qoSlCCUgjHwkY=; b=kHnCXLPbNs/4s6nNmra8lq5pxi3Wy3sqq222JyLWUs/UUvhLN7YxJ+PWUrDghIZpnhbmC2 mIFBLy4LSShAvL1FKO7ew8cP8CMEvIQrPS3WlKmSfSZcLuNFt8w0Ub8/Mw7KIBdn4kl/M8 AjZIXQGZePAF5Mcvh7jFkjo/YqI2q+2wUy5InGfBl1J/MvrYjkBX1a9D/Xqa/wLzE11Axh kP3DsbFrFmvuZAKjiX5pQ87+9IOulh6RXVdGi6ABA68OBw2X9AdgstaACsp0gORZWiMnmw 7tKtHTOcviAUGKswRE8ylaDZpRFpQbOkYGhXozpXEfYcfo9Fq5SWWtkzzwmckA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1672998392; 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=UfblyzYgvU499OU57PRZ8a/U/kU9N/qoSlCCUgjHwkY=; b=xfzDxVIrATmFIujCRGF7s7zJDtV/g8quXkTPoIdhCFIZvHBfHOrWIrXX53k0f/j0xO9ftK 3Mf0itvUmgLfVvpA9Y1XFEJ/oP46toCTmej1TIt25Y3fR2LZvWKf4ZhoFVu+AigSuf75CY 9hJ8ZXyRstvLAyxlKcDhRA1KF2OVrVrc4fqw2yLsqXMP7A292MpVt+daDb1vujnV5n7cll 1ejDiJCcXAruZmvGNkYIoyZUmoN6hLpVi82lepD9jc49OROu0D/eviKqMAY7p64HR2xl2R xqthjyNAsCw5QBqM1PkTYL9WjnG2/6bx8ewhUnvA6FOtLyfsd6IiWXakiWmKrw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1672998392; a=rsa-sha256; cv=none; b=tmBXQVozfux/NTWI5Vl9T1TuxQGFaU428O9vJV0LOLj41zv4I/PRQ0OUgZ2WdS4JWSNTTz 8DmMWwrI35IbFzNrLrK1uiN8c469CtkNtaQmUFlL8K8qI7ycFYkdHW9rajK1jr1P9bXTZY S2ZLJVvIrFVUmrcyXhyNIciH7DrBEGeCqJIC1W0Oo/WH92GuJt0hUHBJ+RcY/MkPRo0AZy Ym8YaFu1DYRLQFa6Kx2KPjF3FRKmHpSDFk19HHBtRJ1viZHlxmgrtOP2Ru+/TriTXuVbln KylrgUCHirSJmCLJXUAMjpxwS+J/cMcbEW53539/TdLAGPTKFt0sSvoDZ0Jw9w== 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 4NpJQ01h2NzQb5; Fri, 6 Jan 2023 09:46:32 +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 3069kWe6090437; Fri, 6 Jan 2023 09:46:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 3069kWwe090436; Fri, 6 Jan 2023 09:46:32 GMT (envelope-from git) Date: Fri, 6 Jan 2023 09:46:32 GMT Message-Id: <202301060946.3069kWwe090436@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Doug Rabson Subject: git: fa7217a71232 - stable/13 - Add vn_path_to_global_path_hardlink List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: fa7217a7123209366eb82c09a198ebdd1f0b9cc4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dfr: URL: https://cgit.FreeBSD.org/src/commit/?id=fa7217a7123209366eb82c09a198ebdd1f0b9cc4 commit fa7217a7123209366eb82c09a198ebdd1f0b9cc4 Author: Doug Rabson AuthorDate: 2022-12-02 14:09:31 +0000 Commit: Doug Rabson CommitDate: 2023-01-06 07:57:57 +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 (cherry picked from commit 78d35459a2586da024ac18e8768b44893c7184e7) --- 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 c358de15f779..b422b30da3e2 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -3797,6 +3797,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, td); + 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) @@ -5349,7 +5414,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); @@ -5406,7 +5471,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 529c69ccf7c7..2011f429141c 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -704,6 +704,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,