From owner-svn-src-all@FreeBSD.ORG Mon Apr 2 19:01:33 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7EC021065677; Mon, 2 Apr 2012 19:01:33 +0000 (UTC) (envelope-from trociny@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5FE918FC12; Mon, 2 Apr 2012 19:01:33 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q32J1X55012254; Mon, 2 Apr 2012 19:01:33 GMT (envelope-from trociny@svn.freebsd.org) Received: (from trociny@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q32J1Xh2012250; Mon, 2 Apr 2012 19:01:33 GMT (envelope-from trociny@svn.freebsd.org) Message-Id: <201204021901.q32J1Xh2012250@svn.freebsd.org> From: Mikolaj Golub Date: Mon, 2 Apr 2012 19:01:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r233803 - in stable/9/sys: kern sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Apr 2012 19:01:33 -0000 Author: trociny Date: Mon Apr 2 19:01:32 2012 New Revision: 233803 URL: http://svn.freebsd.org/changeset/base/233803 Log: MFC r232152: When detaching a unix domain socket, uipc_detach() checks unp->unp_vnode pointer to detect if there is a vnode associated with (binded to) this socket and does necessary cleanup if there is. The issue is that after forced unmount this check may be too late as the unp_vnode is reclaimed and the reference is stale. To fix this provide a helper function that is called on a socket vnode reclamation to do necessary cleanup. Pointed by: kib Reviewed by: kib Modified: stable/9/sys/kern/uipc_usrreq.c stable/9/sys/kern/vfs_subr.c stable/9/sys/sys/vnode.h Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/kern/uipc_usrreq.c ============================================================================== --- stable/9/sys/kern/uipc_usrreq.c Mon Apr 2 18:54:10 2012 (r233802) +++ stable/9/sys/kern/uipc_usrreq.c Mon Apr 2 19:01:32 2012 (r233803) @@ -2299,6 +2299,45 @@ unp_scan(struct mbuf *m0, void (*op)(str } } +/* + * A helper function called by VFS before socket-type vnode reclamation. + * For an active vnode it clears unp_vnode pointer and decrements unp_vnode + * use count. + */ +void +vfs_unp_reclaim(struct vnode *vp) +{ + struct socket *so; + struct unpcb *unp; + int active; + + ASSERT_VOP_ELOCKED(vp, "vfs_unp_reclaim"); + KASSERT(vp->v_type == VSOCK, + ("vfs_unp_reclaim: vp->v_type != VSOCK")); + + active = 0; + UNP_LINK_WLOCK(); + so = vp->v_socket; + if (so == NULL) + goto done; + unp = sotounpcb(so); + if (unp == NULL) + goto done; + UNP_PCB_LOCK(unp); + if (unp->unp_vnode != NULL) { + KASSERT(unp->unp_vnode == vp, + ("vfs_unp_reclaim: vp != unp->unp_vnode")); + vp->v_socket = NULL; + unp->unp_vnode = NULL; + active = 1; + } + UNP_PCB_UNLOCK(unp); +done: + UNP_LINK_WUNLOCK(); + if (active) + vunref(vp); +} + #ifdef DDB static void db_print_indent(int indent) Modified: stable/9/sys/kern/vfs_subr.c ============================================================================== --- stable/9/sys/kern/vfs_subr.c Mon Apr 2 18:54:10 2012 (r233802) +++ stable/9/sys/kern/vfs_subr.c Mon Apr 2 19:01:32 2012 (r233803) @@ -2657,6 +2657,8 @@ vgonel(struct vnode *vp) vinactive(vp, td); VI_UNLOCK(vp); } + if (vp->v_type == VSOCK) + vfs_unp_reclaim(vp); /* * Reclaim the vnode. */ Modified: stable/9/sys/sys/vnode.h ============================================================================== --- stable/9/sys/sys/vnode.h Mon Apr 2 18:54:10 2012 (r233802) +++ stable/9/sys/sys/vnode.h Mon Apr 2 19:01:32 2012 (r233803) @@ -796,6 +796,8 @@ int vfs_read_dirent(struct vop_readdir_a int vfs_unixify_accmode(accmode_t *accmode); +void vfs_unp_reclaim(struct vnode *vp); + int setfmode(struct thread *td, struct ucred *cred, struct vnode *vp, int mode); int setfown(struct thread *td, struct ucred *cred, struct vnode *vp, uid_t uid, gid_t gid);