version 1.81, 2007/10/10 20:42:30 |
version 1.81.2.1, 2007/11/13 16:02:45 |
Line 127 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 127 __KERNEL_RCSID(0, "$NetBSD$"); |
|
|
|
void procfs_hashins(struct pfsnode *); |
void procfs_hashins(struct pfsnode *); |
void procfs_hashrem(struct pfsnode *); |
void procfs_hashrem(struct pfsnode *); |
struct vnode *procfs_hashget(pid_t, pfstype, int, struct mount *); |
struct vnode *procfs_hashget(pid_t, pfstype, int, struct mount *, int); |
|
|
LIST_HEAD(pfs_hashhead, pfsnode) *pfs_hashtbl; |
LIST_HEAD(pfs_hashhead, pfsnode) *pfs_hashtbl; |
u_long pfs_ihash; /* size of hash table - 1 */ |
u_long pfs_ihash; /* size of hash table - 1 */ |
Line 177 procfs_allocvp(mp, vpp, pid, pfs_type, f |
|
Line 177 procfs_allocvp(mp, vpp, pid, pfs_type, f |
|
struct vnode *vp; |
struct vnode *vp; |
int error; |
int error; |
|
|
if ((*vpp = procfs_hashget(pid, pfs_type, fd, mp)) != NULL) |
retry: |
|
*vpp = procfs_hashget(pid, pfs_type, fd, mp, LK_EXCLUSIVE); |
|
if (*vpp != NULL) |
return (0); |
return (0); |
|
|
if ((error = getnewvnode(VT_PROCFS, mp, procfs_vnodeop_p, &vp)) != 0) { |
if ((error = getnewvnode(VT_PROCFS, mp, procfs_vnodeop_p, &vp)) != 0) { |
Line 187 procfs_allocvp(mp, vpp, pid, pfs_type, f |
|
Line 189 procfs_allocvp(mp, vpp, pid, pfs_type, f |
|
MALLOC(pfs, void *, sizeof(struct pfsnode), M_TEMP, M_WAITOK); |
MALLOC(pfs, void *, sizeof(struct pfsnode), M_TEMP, M_WAITOK); |
|
|
mutex_enter(&pfs_hashlock); |
mutex_enter(&pfs_hashlock); |
if ((*vpp = procfs_hashget(pid, pfs_type, fd, mp)) != NULL) { |
if ((*vpp = procfs_hashget(pid, pfs_type, fd, mp, 0)) != NULL) { |
mutex_exit(&pfs_hashlock); |
mutex_exit(&pfs_hashlock); |
ungetnewvnode(vp); |
ungetnewvnode(vp); |
FREE(pfs, M_TEMP); |
FREE(pfs, M_TEMP); |
return (0); |
goto retry; |
} |
} |
|
|
vp->v_data = pfs; |
vp->v_data = pfs; |
|
|
pfs->pfs_pid = pid; |
pfs->pfs_pid = pid; |
pfs->pfs_type = pfs_type; |
pfs->pfs_type = pfs_type; |
pfs->pfs_vnode = vp; |
pfs->pfs_vnode = vp; |
Line 205 procfs_allocvp(mp, vpp, pid, pfs_type, f |
|
Line 206 procfs_allocvp(mp, vpp, pid, pfs_type, f |
|
|
|
switch (pfs_type) { |
switch (pfs_type) { |
case PFSroot: /* /proc = dr-xr-xr-x */ |
case PFSroot: /* /proc = dr-xr-xr-x */ |
vp->v_vflag = VV_ROOT; |
vp->v_vflag |= VV_ROOT; |
/*FALLTHROUGH*/ |
/*FALLTHROUGH*/ |
case PFSproc: /* /proc/N = dr-xr-xr-x */ |
case PFSproc: /* /proc/N = dr-xr-xr-x */ |
pfs->pfs_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; |
pfs->pfs_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; |
Line 229 procfs_allocvp(mp, vpp, pid, pfs_type, f |
|
Line 230 procfs_allocvp(mp, vpp, pid, pfs_type, f |
|
struct file *fp; |
struct file *fp; |
struct vnode *vxp; |
struct vnode *vxp; |
|
|
mutex_enter(&p->p_mutex); |
|
fp = fd_getfile(p->p_fd, pfs->pfs_fd); |
fp = fd_getfile(p->p_fd, pfs->pfs_fd); |
mutex_exit(&p->p_mutex); |
|
if (fp == NULL) { |
if (fp == NULL) { |
error = EBADF; |
error = EBADF; |
goto bad; |
goto bad; |
Line 326 procfs_allocvp(mp, vpp, pid, pfs_type, f |
|
Line 325 procfs_allocvp(mp, vpp, pid, pfs_type, f |
|
bad: |
bad: |
mutex_exit(&pfs_hashlock); |
mutex_exit(&pfs_hashlock); |
FREE(pfs, M_TEMP); |
FREE(pfs, M_TEMP); |
|
vp->v_data = NULL; |
ungetnewvnode(vp); |
ungetnewvnode(vp); |
return (error); |
return (error); |
} |
} |
Line 598 procfs_hashdone() |
|
Line 598 procfs_hashdone() |
|
} |
} |
|
|
struct vnode * |
struct vnode * |
procfs_hashget(pid, type, fd, mp) |
procfs_hashget(pid, type, fd, mp, flags) |
pid_t pid; |
pid_t pid; |
pfstype type; |
pfstype type; |
int fd; |
int fd; |
struct mount *mp; |
struct mount *mp; |
|
int flags; |
{ |
{ |
struct pfs_hashhead *ppp; |
struct pfs_hashhead *ppp; |
struct pfsnode *pp; |
struct pfsnode *pp; |
|
|
vp = PFSTOV(pp); |
vp = PFSTOV(pp); |
if (pid == pp->pfs_pid && pp->pfs_type == type && |
if (pid == pp->pfs_pid && pp->pfs_type == type && |
pp->pfs_fd == fd && vp->v_mount == mp) { |
pp->pfs_fd == fd && vp->v_mount == mp) { |
simple_lock(&vp->v_interlock); |
if (flags == 0) { |
mutex_exit(&pfs_ihash_lock); |
mutex_exit(&pfs_ihash_lock); |
if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK)) |
} else { |
goto loop; |
simple_lock(&vp->v_interlock); |
|
mutex_exit(&pfs_ihash_lock); |
|
if (vget(vp, flags | LK_INTERLOCK)) |
|
goto loop; |
|
} |
return (vp); |
return (vp); |
} |
} |
} |
} |
Line 669 procfs_revoke_vnodes(p, arg) |
|
Line 674 procfs_revoke_vnodes(p, arg) |
|
if (!(p->p_flag & PK_SUGID)) |
if (!(p->p_flag & PK_SUGID)) |
return; |
return; |
|
|
|
mutex_enter(&pfs_ihash_lock); |
ppp = &pfs_hashtbl[PFSPIDHASH(p->p_pid)]; |
ppp = &pfs_hashtbl[PFSPIDHASH(p->p_pid)]; |
for (pfs = LIST_FIRST(ppp); pfs; pfs = pnext) { |
for (pfs = LIST_FIRST(ppp); pfs; pfs = pnext) { |
vp = PFSTOV(pfs); |
vp = PFSTOV(pfs); |
pnext = LIST_NEXT(pfs, pfs_hash); |
pnext = LIST_NEXT(pfs, pfs_hash); |
|
simple_lock(&vp->v_interlock); |
if (vp->v_usecount > 0 && pfs->pfs_pid == p->p_pid && |
if (vp->v_usecount > 0 && pfs->pfs_pid == p->p_pid && |
vp->v_mount == mp) |
vp->v_mount == mp) { |
|
vp->v_usecount++; |
|
simple_unlock(&vp->v_interlock); |
|
mutex_exit(&pfs_ihash_lock); |
VOP_REVOKE(vp, REVOKEALL); |
VOP_REVOKE(vp, REVOKEALL); |
|
vrele(vp); |
|
mutex_enter(&pfs_ihash_lock); |
|
} else { |
|
simple_unlock(&vp->v_interlock); |
|
} |
} |
} |
|
mutex_exit(&pfs_ihash_lock); |
} |
} |
|
|
int |
int |
Line 691 procfs_proc_lock(int pid, struct proc ** |
|
Line 707 procfs_proc_lock(int pid, struct proc ** |
|
tp = &proc0; |
tp = &proc0; |
else if ((tp = p_find(pid, PFIND_LOCKED)) == NULL) |
else if ((tp = p_find(pid, PFIND_LOCKED)) == NULL) |
error = notfound; |
error = notfound; |
|
if (tp != NULL && !rw_tryenter(&tp->p_reflock, RW_READER)) |
if (tp != NULL) { |
error = EBUSY; |
mutex_enter(&tp->p_mutex); |
|
error = proc_addref(tp); |
|
mutex_exit(&tp->p_mutex); |
|
} |
|
|
|
mutex_exit(&proclist_lock); |
mutex_exit(&proclist_lock); |
|
|
Line 707 procfs_proc_lock(int pid, struct proc ** |
|
Line 719 procfs_proc_lock(int pid, struct proc ** |
|
void |
void |
procfs_proc_unlock(struct proc *p) |
procfs_proc_unlock(struct proc *p) |
{ |
{ |
mutex_enter(&p->p_mutex); |
|
proc_delref(p); |
rw_exit(&p->p_reflock); |
mutex_exit(&p->p_mutex); |
|
} |
} |
|
|
int |
int |