Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/miscfs/procfs/procfs_subr.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/miscfs/procfs/procfs_subr.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.80.6.2 retrieving revision 1.81 diff -u -p -r1.80.6.2 -r1.81 --- src/sys/miscfs/procfs/procfs_subr.c 2007/11/11 16:48:23 1.80.6.2 +++ src/sys/miscfs/procfs/procfs_subr.c 2007/10/10 20:42:30 1.81 @@ -1,4 +1,4 @@ -/* $NetBSD: procfs_subr.c,v 1.80.6.2 2007/11/11 16:48:23 joerg Exp $ */ +/* $NetBSD: procfs_subr.c,v 1.81 2007/10/10 20:42:30 ad Exp $ */ /*- * Copyright (c) 2006, 2007 The NetBSD Foundation, Inc. @@ -109,7 +109,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.80.6.2 2007/11/11 16:48:23 joerg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.81 2007/10/10 20:42:30 ad Exp $"); #include #include @@ -127,7 +127,7 @@ __KERNEL_RCSID(0, "$NetBSD: procfs_subr. void procfs_hashins(struct pfsnode *); void procfs_hashrem(struct pfsnode *); -struct vnode *procfs_hashget(pid_t, pfstype, int, struct mount *, int); +struct vnode *procfs_hashget(pid_t, pfstype, int, struct mount *); LIST_HEAD(pfs_hashhead, pfsnode) *pfs_hashtbl; u_long pfs_ihash; /* size of hash table - 1 */ @@ -177,9 +177,7 @@ procfs_allocvp(mp, vpp, pid, pfs_type, f struct vnode *vp; int error; - retry: - *vpp = procfs_hashget(pid, pfs_type, fd, mp, LK_EXCLUSIVE); - if (*vpp != NULL) + if ((*vpp = procfs_hashget(pid, pfs_type, fd, mp)) != NULL) return (0); if ((error = getnewvnode(VT_PROCFS, mp, procfs_vnodeop_p, &vp)) != 0) { @@ -189,14 +187,15 @@ procfs_allocvp(mp, vpp, pid, pfs_type, f MALLOC(pfs, void *, sizeof(struct pfsnode), M_TEMP, M_WAITOK); mutex_enter(&pfs_hashlock); - if ((*vpp = procfs_hashget(pid, pfs_type, fd, mp, 0)) != NULL) { + if ((*vpp = procfs_hashget(pid, pfs_type, fd, mp)) != NULL) { mutex_exit(&pfs_hashlock); ungetnewvnode(vp); FREE(pfs, M_TEMP); - goto retry; + return (0); } vp->v_data = pfs; + pfs->pfs_pid = pid; pfs->pfs_type = pfs_type; pfs->pfs_vnode = vp; @@ -206,7 +205,7 @@ procfs_allocvp(mp, vpp, pid, pfs_type, f switch (pfs_type) { case PFSroot: /* /proc = dr-xr-xr-x */ - vp->v_vflag |= VV_ROOT; + vp->v_vflag = VV_ROOT; /*FALLTHROUGH*/ case PFSproc: /* /proc/N = dr-xr-xr-x */ pfs->pfs_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; @@ -230,7 +229,9 @@ procfs_allocvp(mp, vpp, pid, pfs_type, f struct file *fp; struct vnode *vxp; + mutex_enter(&p->p_mutex); fp = fd_getfile(p->p_fd, pfs->pfs_fd); + mutex_exit(&p->p_mutex); if (fp == NULL) { error = EBADF; goto bad; @@ -325,7 +326,6 @@ procfs_allocvp(mp, vpp, pid, pfs_type, f bad: mutex_exit(&pfs_hashlock); FREE(pfs, M_TEMP); - vp->v_data = NULL; ungetnewvnode(vp); return (error); } @@ -598,12 +598,11 @@ procfs_hashdone() } struct vnode * -procfs_hashget(pid, type, fd, mp, flags) +procfs_hashget(pid, type, fd, mp) pid_t pid; pfstype type; int fd; struct mount *mp; - int flags; { struct pfs_hashhead *ppp; struct pfsnode *pp; @@ -616,14 +615,10 @@ loop: vp = PFSTOV(pp); if (pid == pp->pfs_pid && pp->pfs_type == type && pp->pfs_fd == fd && vp->v_mount == mp) { - if (flags == 0) { - mutex_exit(&pfs_ihash_lock); - } else { - simple_lock(&vp->v_interlock); - mutex_exit(&pfs_ihash_lock); - if (vget(vp, flags | LK_INTERLOCK)) - goto loop; - } + simple_lock(&vp->v_interlock); + mutex_exit(&pfs_ihash_lock); + if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK)) + goto loop; return (vp); } } @@ -674,25 +669,14 @@ procfs_revoke_vnodes(p, arg) if (!(p->p_flag & PK_SUGID)) return; - mutex_enter(&pfs_ihash_lock); ppp = &pfs_hashtbl[PFSPIDHASH(p->p_pid)]; for (pfs = LIST_FIRST(ppp); pfs; pfs = pnext) { vp = PFSTOV(pfs); pnext = LIST_NEXT(pfs, pfs_hash); - simple_lock(&vp->v_interlock); if (vp->v_usecount > 0 && pfs->pfs_pid == p->p_pid && - vp->v_mount == mp) { - vp->v_usecount++; - simple_unlock(&vp->v_interlock); - mutex_exit(&pfs_ihash_lock); + vp->v_mount == mp) VOP_REVOKE(vp, REVOKEALL); - vrele(vp); - mutex_enter(&pfs_ihash_lock); - } else { - simple_unlock(&vp->v_interlock); - } } - mutex_exit(&pfs_ihash_lock); } int @@ -707,8 +691,12 @@ procfs_proc_lock(int pid, struct proc ** tp = &proc0; else if ((tp = p_find(pid, PFIND_LOCKED)) == NULL) error = notfound; - if (tp != NULL && !rw_tryenter(&tp->p_reflock, RW_READER)) - error = EBUSY; + + if (tp != NULL) { + mutex_enter(&tp->p_mutex); + error = proc_addref(tp); + mutex_exit(&tp->p_mutex); + } mutex_exit(&proclist_lock); @@ -719,8 +707,9 @@ procfs_proc_lock(int pid, struct proc ** void procfs_proc_unlock(struct proc *p) { - - rw_exit(&p->p_reflock); + mutex_enter(&p->p_mutex); + proc_delref(p); + mutex_exit(&p->p_mutex); } int