git: e27d36e038bf - main - unix: Simplify uipc_detach()
Mark Johnston <[email protected]>
| Newsgroups | gmane.os.freebsd.devel.cvs.src |
|---|---|
| Message-ID | <6a7a0d0c.3fad2.191c95f8__3295.08403535641$1786383653$gmane$org@gitrepo.freebsd.org> |
The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e27d36e038bf0d681d19a07d3512e0dc5adb20c7 commit e27d36e038bf0d681d19a07d3512e0dc5adb20c7 Author: Mark Johnston <[email protected]> AuthorDate: 2026-08-10 14:41:22 +0000 Commit: Mark Johnston <[email protected]> CommitDate: 2026-08-10 17:31:21 +0000 unix: Simplify uipc_detach() uipc_close() handles detaching a unix socket from the vnode to which it's bound, if any, so doing the same in uipc_detach() is redundant. Moreover, it's conceptually wrong that uipc_detach() might need to handle this: detach happens when there are no remaining references to the socket, and that should include the vnode's reference, even though it's not explicitly counted. No functional change intended. Reviewed by: John Ericson <[email protected]>, glebius MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D58675 --- sys/kern/uipc_usrreq.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 835daa09fc9a..df9568015724 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -802,15 +802,10 @@ static void uipc_detach(struct socket *so) { struct unpcb *unp, *unp2; - struct mtx *vplock; - struct vnode *vp; unp = sotounpcb(so); KASSERT(unp != NULL, ("uipc_detach: unp == NULL")); - vp = NULL; - vplock = NULL; - if (!SOLISTENING(so)) unp_dispose(so); @@ -822,23 +817,9 @@ uipc_detach(struct socket *so) --unp_count; UNP_LINK_WUNLOCK(); - UNP_PCB_UNLOCK_ASSERT(unp); - restart: - if ((vp = unp->unp_vnode) != NULL) { - vplock = mtx_pool_find(unp_vp_mtxpool, vp); - mtx_lock(vplock); - } UNP_PCB_LOCK(unp); - if (unp->unp_vnode != vp && unp->unp_vnode != NULL) { - if (vplock) - mtx_unlock(vplock); - UNP_PCB_UNLOCK(unp); - goto restart; - } - if ((vp = unp->unp_vnode) != NULL) { - VOP_UNP_DETACH(vp); - unp->unp_vnode = NULL; - } + KASSERT(unp->unp_vnode == NULL, + ("%s: unp %p has vnode", __func__, unp)); if ((unp2 = unp_pcb_lock_peer(unp)) != NULL) unp_disconnect(unp, unp2); else @@ -865,10 +846,7 @@ uipc_detach(struct socket *so) unp->unp_addr = NULL; if (!unp_pcb_rele(unp)) UNP_PCB_UNLOCK(unp); - if (vp) { - mtx_unlock(vplock); - vrele(vp); - } + maybe_schedule_gc(); switch (so->so_type) {