From nobody Sun Apr 07 00:31:35 2024 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 4VBtSl4xVxz5Fhpm; Sun, 7 Apr 2024 00:31:35 +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 4VBtSl4N3Yz3wb0; Sun, 7 Apr 2024 00:31:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712449895; 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=ikBrpbGaWqzshh950gcKgGRgS6Us3+vaNGgNjxj+Qu0=; b=ZhoLK2X28pnrM90klKFyj82s1AIDuMk0He328AZJkdm2n6QbDbCEXRcIjWKAOFMXGco31G TgkQFv5n3QycqtycdE1YndiHGB6l3or/aYodshlNZJg4uROTGSkkE2YsqwA9hUZaAmlwfl XdokzX3sbm/j+wUy74HCptd7ed8qSANum4YDY7b36m4iLLykcWPCLgNIXFDlWPditjyIgC c/6Ee4bsiLB5X/AxApceTlEHmXyZegobpxC35XXusdF2Pl5f6t76N9qChxTWn7JzHZe6za eKBWhXzuGqWY2sXeRn5+nTsX2dZ+uGFyEkesPgFlwYcVWEcmR+8ocuhPfNp1tw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712449895; a=rsa-sha256; cv=none; b=bc0d26mY34EwapcsIX/6/fF/aYzQIGkbJ2R/002d71l+Zc4HiTVNL22q3MHAjS8BRdj6fC Lvs5Ua4E7f1sC72X4/BYGms9rMti0UOqWsJoTqfMq5NzyYvH4HsnKOFzmb0bOK/0P0ZVqM Wn7uwUT0dalkQtLqJmxdn57JZJHAG+s1DTWXSs81CcYOMJBBxlDDBmzaa2UNdg+Ge/bbIU ni5GfbhcQZ0OQTAdhwYjlZPcumjRXnhNth47L4jdkl2IgjwK4vdRMJm1rHMTxHFZBee5k2 aVjJY5elCx0ppFXyaHO0qM5msPzNrVzpnGbx7p2oBvRaEjk4m56bed99qdfdWA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712449895; 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=ikBrpbGaWqzshh950gcKgGRgS6Us3+vaNGgNjxj+Qu0=; b=Ft/pK51MsLrtmQN8dOrfXjaej6dikuUTESe56XPd7hERihd5lLHDR+UyhC5tWxZJL1iWad QlWMXEQzOa9mtwfRvQ+Gjm6NG1BcPSP7hnSM7yAKu1V44EURpYATp3s+pAeWBUDO0VqzgD B2MEqqe8C8Ev1yI5AwxmNcN7jCc5B48nAxNJuAaCTwOh0ofwlC/VAQ5TRqFUEvJK9+TYy7 Mo6MziVyvnLjDsLDyxGQjv/H5rgH0sXdb7ZFurRBMF6hup9afqNZ/k+lHRuZ9ofGAIyIWw titinHInoNxvJR1gGvMIUUVLsyKme6MZXV7aNNNdtmqrFMmzHzEQRIy1eNTxSA== 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 4VBtSl3yyNz156Q; Sun, 7 Apr 2024 00:31:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 4370VZdu067882; Sun, 7 Apr 2024 00:31:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4370VZPV067879; Sun, 7 Apr 2024 00:31:35 GMT (envelope-from git) Date: Sun, 7 Apr 2024 00:31:35 GMT Message-Id: <202404070031.4370VZPV067879@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Jason A. Harmening" Subject: git: 7b86d14bfccb - stable/14 - unionfs: implement VOP_UNP_* and remove special VSOCK vnode handling 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: jah X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 7b86d14bfccb589612cbc6b2e54b405da9839232 Auto-Submitted: auto-generated The branch stable/14 has been updated by jah: URL: https://cgit.FreeBSD.org/src/commit/?id=7b86d14bfccb589612cbc6b2e54b405da9839232 commit 7b86d14bfccb589612cbc6b2e54b405da9839232 Author: Jason A. Harmening AuthorDate: 2024-02-03 17:17:58 +0000 Commit: Jason A. Harmening CommitDate: 2024-04-07 00:27:00 +0000 unionfs: implement VOP_UNP_* and remove special VSOCK vnode handling unionfs has a bunch of clunky special-case code to avoid creating unionfs wrapper vnodes for AF_UNIX sockets. This was added in 2008 to address PR 118346, but in the intervening years the VOP_UNP_* operations have been added to provide a clean interface to allow sockets to work in the presence of stacked filesystems. PR: 275871 Reviewed by: kib (prior version), olce Tested by: Karlo Miličević Differential Revision: https://reviews.freebsd.org/D44288 (cherry picked from commit eee6217b40df5877674df1d9aec7d5bd04202876) --- sys/fs/unionfs/union_vnops.c | 173 +++++++++++++++++++++---------------------- 1 file changed, 84 insertions(+), 89 deletions(-) diff --git a/sys/fs/unionfs/union_vnops.c b/sys/fs/unionfs/union_vnops.c index d74d6736e580..5a2d4751ed4f 100644 --- a/sys/fs/unionfs/union_vnops.c +++ b/sys/fs/unionfs/union_vnops.c @@ -300,27 +300,8 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) error = lerror; if (error != 0) goto unionfs_lookup_cleanup; - /* - * get socket vnode. - */ - if (uvp != NULLVP && uvp->v_type == VSOCK) { - vp = uvp; - vref(vp); - if (cnp->cn_lkflags & LK_TYPE_MASK) - vn_lock(vp, cnp->cn_lkflags | LK_RETRY); - } - else if (lvp != NULLVP && lvp->v_type == VSOCK) { - vp = lvp; - vref(vp); - if (cnp->cn_lkflags & LK_TYPE_MASK) - vn_lock(vp, cnp->cn_lkflags | LK_RETRY); - } - /* - * get unionfs vnode. - */ - else - error = unionfs_nodeget(dvp->v_mount, uvp, lvp, - dvp, &vp, cnp); + error = unionfs_nodeget(dvp->v_mount, uvp, lvp, + dvp, &vp, cnp); if (error != 0) { UNIONFSDEBUG( "unionfs_lookup: Unable to create unionfs vnode."); @@ -333,7 +314,7 @@ unionfs_lookup(struct vop_cachedlookup_args *ap) *(ap->a_vpp) = vp; - if ((cnflags & MAKEENTRY) && vp->v_type != VSOCK) + if (cnflags & MAKEENTRY) cache_enter(dvp, vp, cnp); unionfs_lookup_cleanup: @@ -381,9 +362,7 @@ unionfs_create(struct vop_create_args *ap) lkflags)) && error == 0) { error = ENOENT; } - if (error == 0 && vp->v_type == VSOCK) - *(ap->a_vpp) = vp; - else if (error == 0) { + if (error == 0) { VOP_UNLOCK(vp); error = unionfs_nodeget(ap->a_dvp->v_mount, vp, NULLVP, ap->a_dvp, ap->a_vpp, cnp); @@ -464,9 +443,7 @@ unionfs_mknod(struct vop_mknod_args *ap) lkflags)) && error == 0) { error = ENOENT; } - if (error == 0 && vp->v_type == VSOCK) - *(ap->a_vpp) = vp; - else if (error == 0) { + if (error == 0) { VOP_UNLOCK(vp); error = unionfs_nodeget(ap->a_dvp->v_mount, vp, NULLVP, ap->a_dvp, ap->a_vpp, cnp); @@ -1059,9 +1036,7 @@ unionfs_remove(struct vop_remove_args *ap) struct vnode *udvp; struct vnode *uvp; struct vnode *lvp; - struct vnode *vp; struct componentname *cnp; - struct componentname cn; struct thread *td; int error; int pathlen; @@ -1069,71 +1044,34 @@ unionfs_remove(struct vop_remove_args *ap) UNIONFS_INTERNAL_DEBUG("unionfs_remove: enter\n"); KASSERT_UNIONFS_VNODE(ap->a_dvp); + KASSERT_UNIONFS_VNODE(ap->a_vp); error = 0; dunp = VTOUNIONFS(ap->a_dvp); udvp = dunp->un_uppervp; cnp = ap->a_cnp; td = curthread; - unp = NULL; - - if (ap->a_vp->v_op != &unionfs_vnodeops) { - if (ap->a_vp->v_type != VSOCK) - return (EINVAL); - ump = NULL; - vp = uvp = lvp = NULLVP; - /* search vnode */ - VOP_UNLOCK(ap->a_vp); - error = unionfs_relookup(udvp, &vp, cnp, &cn, td, - cnp->cn_nameptr, cnp->cn_namelen, DELETE); - if (error != 0 && error != ENOENT) { - vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY); - return (error); - } - if (error == 0 && vp == ap->a_vp) { - /* target vnode in upper */ - uvp = vp; - vrele(vp); - } else { - /* target vnode in lower */ - if (vp != NULLVP) { - if (udvp == vp) - vrele(vp); - else - vput(vp); - } - vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY); - lvp = ap->a_vp; - } - path = cnp->cn_nameptr; - pathlen = cnp->cn_namelen; - } else { - ump = MOUNTTOUNIONFSMOUNT(ap->a_vp->v_mount); - unp = VTOUNIONFS(ap->a_vp); - uvp = unp->un_uppervp; - lvp = unp->un_lowervp; - path = unp->un_path; - pathlen = unp->un_pathlen; - } + ump = MOUNTTOUNIONFSMOUNT(ap->a_vp->v_mount); + unp = VTOUNIONFS(ap->a_vp); + uvp = unp->un_uppervp; + lvp = unp->un_lowervp; + path = unp->un_path; + pathlen = unp->un_pathlen; if (udvp == NULLVP) return (EROFS); if (uvp != NULLVP) { - /* - * XXX: if the vnode type is VSOCK, it will create whiteout - * after remove. - */ int udvp_lkflags, uvp_lkflags; if (ump == NULL || ump->um_whitemode == UNIONFS_WHITE_ALWAYS || lvp != NULLVP) cnp->cn_flags |= DOWHITEOUT; unionfs_forward_vop_start_pair(udvp, &udvp_lkflags, - ((unp == NULL) ? NULL : uvp), &uvp_lkflags); + uvp, &uvp_lkflags); error = VOP_REMOVE(udvp, uvp, cnp); unionfs_forward_vop_finish_pair(ap->a_dvp, udvp, udvp_lkflags, - ((unp == NULL) ? NULL : ap->a_vp), uvp, uvp_lkflags); + ap->a_vp, uvp, uvp_lkflags); } else if (lvp != NULLVP) error = unionfs_mkwhiteout(ap->a_dvp, udvp, cnp, td, path, pathlen); @@ -1171,22 +1109,18 @@ unionfs_link(struct vop_link_args *ap) if (udvp == NULLVP) return (EROFS); - if (ap->a_vp->v_op != &unionfs_vnodeops) - uvp = ap->a_vp; - else { - unp = VTOUNIONFS(ap->a_vp); + unp = VTOUNIONFS(ap->a_vp); - if (unp->un_uppervp == NULLVP) { - if (ap->a_vp->v_type != VREG) - return (EOPNOTSUPP); + if (unp->un_uppervp == NULLVP) { + if (ap->a_vp->v_type != VREG) + return (EOPNOTSUPP); - error = unionfs_copyfile(unp, 1, cnp->cn_cred, td); - if (error != 0) - return (error); - needrelookup = 1; - } - uvp = unp->un_uppervp; + error = unionfs_copyfile(unp, 1, cnp->cn_cred, td); + if (error != 0) + return (error); + needrelookup = 1; } + uvp = unp->un_uppervp; if (needrelookup != 0) error = unionfs_relookup_for_create(ap->a_tdvp, cnp, td); @@ -2835,6 +2769,64 @@ unionfs_unset_text(struct vop_unset_text_args *ap) return (0); } +static int +unionfs_unp_bind(struct vop_unp_bind_args *ap) +{ + struct vnode *tvp; + struct unionfs_node *unp; + + ASSERT_VOP_LOCKED(ap->a_vp, __func__); + unp = VTOUNIONFS(ap->a_vp); + tvp = unp->un_uppervp != NULL ? unp->un_uppervp : unp->un_lowervp; + VOP_UNP_BIND(tvp, ap->a_unpcb); + return (0); +} + +static int +unionfs_unp_connect(struct vop_unp_connect_args *ap) +{ + struct vnode *tvp; + struct unionfs_node *unp; + + ASSERT_VOP_LOCKED(ap->a_vp, __func__); + unp = VTOUNIONFS(ap->a_vp); + tvp = unp->un_uppervp != NULL ? unp->un_uppervp : unp->un_lowervp; + VOP_UNP_CONNECT(tvp, ap->a_unpcb); + return (0); +} + +static int +unionfs_unp_detach(struct vop_unp_detach_args *ap) +{ + struct vnode *tvp; + struct unionfs_node *unp; + + tvp = NULL; + /* + * VOP_UNP_DETACH() is not guaranteed to be called with the unionfs + * vnode locked, so we take the interlock to prevent a concurrent + * unmount from freeing the unionfs private data. + */ + VI_LOCK(ap->a_vp); + unp = VTOUNIONFS(ap->a_vp); + if (unp != NULL) { + tvp = unp->un_uppervp != NULL ? + unp->un_uppervp : unp->un_lowervp; + /* + * Hold the target vnode to prevent a concurrent unionfs + * unmount from causing it to be recycled once the interlock + * is dropped. + */ + vholdnz(tvp); + } + VI_UNLOCK(ap->a_vp); + if (tvp != NULL) { + VOP_UNP_DETACH(tvp); + vdrop(tvp); + } + return (0); +} + struct vop_vector unionfs_vnodeops = { .vop_default = &default_vnodeops, @@ -2888,5 +2880,8 @@ struct vop_vector unionfs_vnodeops = { .vop_vput_pair = unionfs_vput_pair, .vop_set_text = unionfs_set_text, .vop_unset_text = unionfs_unset_text, + .vop_unp_bind = unionfs_unp_bind, + .vop_unp_connect = unionfs_unp_connect, + .vop_unp_detach = unionfs_unp_detach, }; VFS_VOP_VECTOR_REGISTER(unionfs_vnodeops);