Home | History | Annotate | Line # | Download | only in procfs
procfs_subr.c revision 1.41
      1  1.41   thorpej /*	$NetBSD: procfs_subr.c,v 1.41 2002/11/07 08:21:36 thorpej Exp $	*/
      2  1.13       cgd 
      3   1.1        pk /*
      4  1.20   thorpej  * Copyright (c) 1994 Christopher G. Demetriou.  All rights reserved.
      5   1.5       cgd  * Copyright (c) 1993 Jan-Simon Pendry
      6  1.11   mycroft  * Copyright (c) 1993
      7  1.11   mycroft  *	The Regents of the University of California.  All rights reserved.
      8   1.2        pk  *
      9   1.5       cgd  * This code is derived from software contributed to Berkeley by
     10   1.5       cgd  * Jan-Simon Pendry.
     11   1.5       cgd  *
     12   1.2        pk  * Redistribution and use in source and binary forms, with or without
     13   1.2        pk  * modification, are permitted provided that the following conditions
     14   1.2        pk  * are met:
     15   1.2        pk  * 1. Redistributions of source code must retain the above copyright
     16   1.2        pk  *    notice, this list of conditions and the following disclaimer.
     17   1.2        pk  * 2. Redistributions in binary form must reproduce the above copyright
     18   1.2        pk  *    notice, this list of conditions and the following disclaimer in the
     19   1.2        pk  *    documentation and/or other materials provided with the distribution.
     20   1.2        pk  * 3. All advertising materials mentioning features or use of this software
     21   1.2        pk  *    must display the following acknowledgement:
     22   1.5       cgd  *	This product includes software developed by the University of
     23   1.5       cgd  *	California, Berkeley and its contributors.
     24   1.5       cgd  * 4. Neither the name of the University nor the names of its contributors
     25   1.5       cgd  *    may be used to endorse or promote products derived from this software
     26   1.5       cgd  *    without specific prior written permission.
     27   1.5       cgd  *
     28   1.5       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29   1.5       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30   1.5       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31   1.5       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32   1.5       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33   1.5       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34   1.5       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35   1.5       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36   1.5       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37   1.5       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38   1.5       cgd  * SUCH DAMAGE.
     39   1.2        pk  *
     40  1.23      fvdl  *	@(#)procfs_subr.c	8.6 (Berkeley) 5/14/95
     41   1.1        pk  */
     42  1.39     lukem 
     43  1.39     lukem #include <sys/cdefs.h>
     44  1.41   thorpej __KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.41 2002/11/07 08:21:36 thorpej Exp $");
     45   1.5       cgd 
     46   1.4   mycroft #include <sys/param.h>
     47   1.4   mycroft #include <sys/systm.h>
     48   1.4   mycroft #include <sys/time.h>
     49   1.4   mycroft #include <sys/kernel.h>
     50   1.4   mycroft #include <sys/proc.h>
     51   1.4   mycroft #include <sys/vnode.h>
     52  1.11   mycroft #include <sys/malloc.h>
     53  1.18   mycroft #include <sys/stat.h>
     54  1.18   mycroft 
     55   1.5       cgd #include <miscfs/procfs/procfs.h>
     56   1.1        pk 
     57  1.29      fvdl void procfs_hashins __P((struct pfsnode *));
     58  1.29      fvdl void procfs_hashrem __P((struct pfsnode *));
     59  1.29      fvdl struct vnode *procfs_hashget __P((pid_t, pfstype, struct mount *));
     60  1.29      fvdl 
     61  1.29      fvdl LIST_HEAD(pfs_hashhead, pfsnode) *pfs_hashtbl;
     62  1.30      fvdl u_long	pfs_ihash;	/* size of hash table - 1 */
     63  1.38       chs #define PFSPIDHASH(pid)	((pid) & pfs_ihash)
     64  1.29      fvdl 
     65  1.29      fvdl struct lock pfs_hashlock;
     66  1.29      fvdl struct simplelock pfs_hash_slock;
     67   1.1        pk 
     68  1.20   thorpej #define	ISSET(t, f)	((t) & (f))
     69  1.20   thorpej 
     70   1.1        pk /*
     71   1.5       cgd  * allocate a pfsnode/vnode pair.  the vnode is
     72  1.27  wrstuden  * referenced, and locked.
     73   1.5       cgd  *
     74   1.5       cgd  * the pid, pfs_type, and mount point uniquely
     75   1.5       cgd  * identify a pfsnode.  the mount point is needed
     76   1.5       cgd  * because someone might mount this filesystem
     77   1.5       cgd  * twice.
     78   1.5       cgd  *
     79   1.5       cgd  * all pfsnodes are maintained on a singly-linked
     80   1.5       cgd  * list.  new nodes are only allocated when they cannot
     81   1.5       cgd  * be found on this list.  entries on the list are
     82   1.5       cgd  * removed when the vfs reclaim entry is called.
     83   1.5       cgd  *
     84   1.5       cgd  * a single lock is kept for the entire list.  this is
     85   1.5       cgd  * needed because the getnewvnode() function can block
     86   1.5       cgd  * waiting for a vnode to become free, in which case there
     87   1.5       cgd  * may be more than one process trying to get the same
     88   1.5       cgd  * vnode.  this lock is only taken if we are going to
     89   1.5       cgd  * call getnewvnode, since the kernel itself is single-threaded.
     90   1.5       cgd  *
     91   1.5       cgd  * if an entry is found on the list, then call vget() to
     92   1.5       cgd  * take a reference.  this is done because there may be
     93   1.5       cgd  * zero references to it and so it needs to removed from
     94   1.5       cgd  * the vnode free list.
     95   1.1        pk  */
     96  1.11   mycroft int
     97   1.5       cgd procfs_allocvp(mp, vpp, pid, pfs_type)
     98   1.5       cgd 	struct mount *mp;
     99   1.5       cgd 	struct vnode **vpp;
    100   1.5       cgd 	long pid;
    101   1.5       cgd 	pfstype pfs_type;
    102   1.1        pk {
    103  1.12   mycroft 	struct pfsnode *pfs;
    104  1.12   mycroft 	struct vnode *vp;
    105   1.5       cgd 	int error;
    106   1.5       cgd 
    107  1.29      fvdl 	do {
    108  1.29      fvdl 		if ((*vpp = procfs_hashget(pid, pfs_type, mp)) != NULL)
    109   1.5       cgd 			return (0);
    110  1.29      fvdl 	} while (lockmgr(&pfs_hashlock, LK_EXCLUSIVE|LK_SLEEPFAIL, 0));
    111   1.1        pk 
    112  1.29      fvdl 	if ((error = getnewvnode(VT_PROCFS, mp, procfs_vnodeop_p, vpp)) != 0) {
    113  1.29      fvdl 		*vpp = NULL;
    114  1.33       chs 		lockmgr(&pfs_hashlock, LK_RELEASE, NULL);
    115  1.29      fvdl 		return (error);
    116   1.5       cgd 	}
    117  1.11   mycroft 	vp = *vpp;
    118   1.5       cgd 
    119  1.11   mycroft 	MALLOC(pfs, void *, sizeof(struct pfsnode), M_TEMP, M_WAITOK);
    120  1.11   mycroft 	vp->v_data = pfs;
    121   1.5       cgd 
    122   1.5       cgd 	pfs->pfs_pid = (pid_t) pid;
    123   1.5       cgd 	pfs->pfs_type = pfs_type;
    124  1.11   mycroft 	pfs->pfs_vnode = vp;
    125   1.5       cgd 	pfs->pfs_flags = 0;
    126   1.5       cgd 	pfs->pfs_fileno = PROCFS_FILENO(pid, pfs_type);
    127   1.5       cgd 
    128   1.5       cgd 	switch (pfs_type) {
    129  1.11   mycroft 	case Proot:	/* /proc = dr-xr-xr-x */
    130  1.17   mycroft 		pfs->pfs_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
    131  1.11   mycroft 		vp->v_type = VDIR;
    132  1.11   mycroft 		vp->v_flag = VROOT;
    133  1.11   mycroft 		break;
    134  1.11   mycroft 
    135  1.22   mycroft 	case Pcurproc:	/* /proc/curproc = lr-xr-xr-x */
    136  1.28   thorpej 	case Pself:	/* /proc/self    = lr-xr-xr-x */
    137  1.22   mycroft 		pfs->pfs_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
    138  1.11   mycroft 		vp->v_type = VLNK;
    139   1.5       cgd 		break;
    140   1.5       cgd 
    141  1.17   mycroft 	case Pproc:	/* /proc/N = dr-xr-xr-x */
    142  1.17   mycroft 		pfs->pfs_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
    143   1.6        ws 		vp->v_type = VDIR;
    144   1.5       cgd 		break;
    145   1.5       cgd 
    146  1.17   mycroft 	case Pfile:	/* /proc/N/file = -rw------- */
    147  1.17   mycroft 	case Pmem:	/* /proc/N/mem = -rw------- */
    148  1.17   mycroft 	case Pregs:	/* /proc/N/regs = -rw------- */
    149  1.17   mycroft 	case Pfpregs:	/* /proc/N/fpregs = -rw------- */
    150  1.17   mycroft 		pfs->pfs_mode = S_IRUSR|S_IWUSR;
    151   1.9       cgd 		vp->v_type = VREG;
    152   1.9       cgd 		break;
    153   1.9       cgd 
    154  1.17   mycroft 	case Pctl:	/* /proc/N/ctl = --w------ */
    155  1.17   mycroft 	case Pnote:	/* /proc/N/note = --w------ */
    156  1.17   mycroft 	case Pnotepg:	/* /proc/N/notepg = --w------ */
    157  1.17   mycroft 		pfs->pfs_mode = S_IWUSR;
    158   1.6        ws 		vp->v_type = VREG;
    159   1.5       cgd 		break;
    160   1.5       cgd 
    161  1.25   msaitoh 	case Pmap:	/* /proc/N/map = -r--r--r-- */
    162  1.37      fvdl 	case Pmaps:	/* /proc/N/maps = -r--r--r-- */
    163  1.17   mycroft 	case Pstatus:	/* /proc/N/status = -r--r--r-- */
    164  1.26  christos 	case Pcmdline:	/* /proc/N/cmdline = -r--r--r-- */
    165  1.35      fvdl 	case Pmeminfo:	/* /proc/meminfo = -r--r--r-- */
    166  1.35      fvdl 	case Pcpuinfo:	/* /proc/cpuinfo = -r--r--r-- */
    167  1.17   mycroft 		pfs->pfs_mode = S_IRUSR|S_IRGRP|S_IROTH;
    168   1.6        ws 		vp->v_type = VREG;
    169   1.5       cgd 		break;
    170   1.5       cgd 
    171  1.40   thorpej #ifdef __HAVE_PROCFS_MACHDEP
    172  1.40   thorpej 	PROCFS_MACHDEP_NODETYPE_CASES
    173  1.40   thorpej 		procfs_machdep_allocvp(vp);
    174  1.40   thorpej 		break;
    175  1.40   thorpej #endif
    176  1.40   thorpej 
    177   1.5       cgd 	default:
    178  1.11   mycroft 		panic("procfs_allocvp");
    179   1.5       cgd 	}
    180  1.27  wrstuden 
    181  1.29      fvdl 	procfs_hashins(pfs);
    182  1.34       chs 	uvm_vnp_setsize(vp, 0);
    183  1.33       chs 	lockmgr(&pfs_hashlock, LK_RELEASE, NULL);
    184   1.1        pk 
    185   1.5       cgd 	return (error);
    186   1.1        pk }
    187   1.1        pk 
    188  1.11   mycroft int
    189   1.5       cgd procfs_freevp(vp)
    190   1.5       cgd 	struct vnode *vp;
    191   1.1        pk {
    192   1.5       cgd 	struct pfsnode *pfs = VTOPFS(vp);
    193   1.5       cgd 
    194  1.29      fvdl 	procfs_hashrem(pfs);
    195   1.1        pk 
    196  1.11   mycroft 	FREE(vp->v_data, M_TEMP);
    197  1.11   mycroft 	vp->v_data = 0;
    198   1.5       cgd 	return (0);
    199   1.1        pk }
    200   1.1        pk 
    201  1.11   mycroft int
    202  1.15  christos procfs_rw(v)
    203  1.15  christos 	void *v;
    204   1.1        pk {
    205  1.15  christos 	struct vop_read_args *ap = v;
    206  1.11   mycroft 	struct vnode *vp = ap->a_vp;
    207  1.11   mycroft 	struct uio *uio = ap->a_uio;
    208   1.5       cgd 	struct proc *curp = uio->uio_procp;
    209   1.5       cgd 	struct pfsnode *pfs = VTOPFS(vp);
    210   1.5       cgd 	struct proc *p;
    211   1.5       cgd 
    212   1.5       cgd 	p = PFIND(pfs->pfs_pid);
    213   1.5       cgd 	if (p == 0)
    214   1.1        pk 		return (EINVAL);
    215  1.19   mycroft 
    216  1.19   mycroft 	switch (pfs->pfs_type) {
    217  1.19   mycroft 	case Pregs:
    218  1.19   mycroft 	case Pfpregs:
    219  1.19   mycroft 	case Pmem:
    220  1.40   thorpej #if defined(__HAVE_PROCFS_MACHDEP) && defined(PROCFS_MACHDEP_PROTECT_CASES)
    221  1.40   thorpej 	PROCFS_MACHDEP_PROTECT_CASES
    222  1.40   thorpej #endif
    223  1.19   mycroft 		/*
    224  1.19   mycroft 		 * Do not allow init to be modified while in secure mode; it
    225  1.19   mycroft 		 * could be duped into changing the security level.
    226  1.19   mycroft 		 */
    227  1.19   mycroft 		if (uio->uio_rw == UIO_WRITE &&
    228  1.19   mycroft 		    p == initproc && securelevel > -1)
    229  1.19   mycroft 			return (EPERM);
    230  1.19   mycroft 		break;
    231  1.19   mycroft 
    232  1.19   mycroft 	default:
    233  1.19   mycroft 		break;
    234  1.19   mycroft 	}
    235   1.1        pk 
    236   1.5       cgd 	switch (pfs->pfs_type) {
    237   1.5       cgd 	case Pnote:
    238   1.5       cgd 	case Pnotepg:
    239  1.11   mycroft 		return (procfs_donote(curp, p, pfs, uio));
    240   1.5       cgd 
    241   1.5       cgd 	case Pregs:
    242  1.11   mycroft 		return (procfs_doregs(curp, p, pfs, uio));
    243   1.9       cgd 
    244   1.9       cgd 	case Pfpregs:
    245  1.11   mycroft 		return (procfs_dofpregs(curp, p, pfs, uio));
    246   1.5       cgd 
    247   1.5       cgd 	case Pctl:
    248  1.11   mycroft 		return (procfs_doctl(curp, p, pfs, uio));
    249   1.5       cgd 
    250   1.5       cgd 	case Pstatus:
    251  1.11   mycroft 		return (procfs_dostatus(curp, p, pfs, uio));
    252  1.25   msaitoh 
    253  1.25   msaitoh 	case Pmap:
    254  1.37      fvdl 		return (procfs_domap(curp, p, pfs, uio, 0));
    255  1.37      fvdl 
    256  1.37      fvdl 	case Pmaps:
    257  1.37      fvdl 		return (procfs_domap(curp, p, pfs, uio, 1));
    258   1.1        pk 
    259   1.5       cgd 	case Pmem:
    260  1.11   mycroft 		return (procfs_domem(curp, p, pfs, uio));
    261  1.26  christos 
    262  1.26  christos 	case Pcmdline:
    263  1.26  christos 		return (procfs_docmdline(curp, p, pfs, uio));
    264  1.35      fvdl 
    265  1.35      fvdl 	case Pmeminfo:
    266  1.35      fvdl 		return (procfs_domeminfo(curp, p, pfs, uio));
    267  1.40   thorpej 
    268  1.35      fvdl 	case Pcpuinfo:
    269  1.35      fvdl 		return (procfs_docpuinfo(curp, p, pfs, uio));
    270  1.40   thorpej 
    271  1.40   thorpej #ifdef __HAVE_PROCFS_MACHDEP
    272  1.40   thorpej 	PROCFS_MACHDEP_NODETYPE_CASES
    273  1.40   thorpej 		return (procfs_machdep_rw(curp, p, pfs, uio));
    274  1.40   thorpej #endif
    275   1.1        pk 
    276   1.5       cgd 	default:
    277   1.5       cgd 		return (EOPNOTSUPP);
    278   1.5       cgd 	}
    279   1.1        pk }
    280   1.1        pk 
    281   1.5       cgd /*
    282   1.5       cgd  * Get a string from userland into (buf).  Strip a trailing
    283   1.5       cgd  * nl character (to allow easy access from the shell).
    284  1.11   mycroft  * The buffer should be *buflenp + 1 chars long.  vfs_getuserstr
    285   1.5       cgd  * will automatically add a nul char at the end.
    286   1.5       cgd  *
    287   1.5       cgd  * Returns 0 on success or the following errors
    288   1.5       cgd  *
    289   1.5       cgd  * EINVAL:    file offset is non-zero.
    290   1.5       cgd  * EMSGSIZE:  message is longer than kernel buffer
    291   1.5       cgd  * EFAULT:    user i/o buffer is not addressable
    292   1.5       cgd  */
    293  1.11   mycroft int
    294  1.11   mycroft vfs_getuserstr(uio, buf, buflenp)
    295   1.5       cgd 	struct uio *uio;
    296   1.5       cgd 	char *buf;
    297   1.5       cgd 	int *buflenp;
    298   1.1        pk {
    299   1.5       cgd 	int xlen;
    300   1.5       cgd 	int error;
    301   1.5       cgd 
    302  1.11   mycroft 	if (uio->uio_offset != 0)
    303  1.11   mycroft 		return (EINVAL);
    304  1.11   mycroft 
    305   1.5       cgd 	xlen = *buflenp;
    306   1.1        pk 
    307   1.5       cgd 	/* must be able to read the whole string in one go */
    308   1.5       cgd 	if (xlen < uio->uio_resid)
    309   1.5       cgd 		return (EMSGSIZE);
    310   1.5       cgd 	xlen = uio->uio_resid;
    311   1.5       cgd 
    312  1.14  christos 	if ((error = uiomove(buf, xlen, uio)) != 0)
    313   1.5       cgd 		return (error);
    314   1.5       cgd 
    315  1.11   mycroft 	/* allow multiple writes without seeks */
    316  1.11   mycroft 	uio->uio_offset = 0;
    317  1.11   mycroft 
    318   1.5       cgd 	/* cleanup string and remove trailing newline */
    319   1.5       cgd 	buf[xlen] = '\0';
    320   1.5       cgd 	xlen = strlen(buf);
    321   1.5       cgd 	if (xlen > 0 && buf[xlen-1] == '\n')
    322   1.5       cgd 		buf[--xlen] = '\0';
    323   1.5       cgd 	*buflenp = xlen;
    324   1.1        pk 
    325   1.5       cgd 	return (0);
    326   1.1        pk }
    327   1.1        pk 
    328  1.36  jdolecek const vfs_namemap_t *
    329  1.11   mycroft vfs_findname(nm, buf, buflen)
    330  1.36  jdolecek 	const vfs_namemap_t *nm;
    331  1.36  jdolecek 	const char *buf;
    332   1.5       cgd 	int buflen;
    333   1.1        pk {
    334  1.11   mycroft 
    335   1.5       cgd 	for (; nm->nm_name; nm++)
    336  1.24     perry 		if (memcmp(buf, nm->nm_name, buflen+1) == 0)
    337   1.5       cgd 			return (nm);
    338   1.5       cgd 
    339   1.5       cgd 	return (0);
    340  1.29      fvdl }
    341  1.29      fvdl 
    342  1.29      fvdl /*
    343  1.29      fvdl  * Initialize pfsnode hash table.
    344  1.29      fvdl  */
    345  1.29      fvdl void
    346  1.29      fvdl procfs_hashinit()
    347  1.29      fvdl {
    348  1.29      fvdl 	lockinit(&pfs_hashlock, PINOD, "pfs_hashlock", 0, 0);
    349  1.32        ad 	pfs_hashtbl = hashinit(desiredvnodes / 4, HASH_LIST, M_UFSMNT,
    350  1.32        ad 	    M_WAITOK, &pfs_ihash);
    351  1.29      fvdl 	simple_lock_init(&pfs_hash_slock);
    352  1.31  jdolecek }
    353  1.31  jdolecek 
    354  1.38       chs void
    355  1.38       chs procfs_hashreinit()
    356  1.38       chs {
    357  1.38       chs 	struct pfsnode *pp;
    358  1.38       chs 	struct pfs_hashhead *oldhash, *hash;
    359  1.41   thorpej 	u_long i, oldmask, mask, val;
    360  1.38       chs 
    361  1.38       chs 	hash = hashinit(desiredvnodes / 4, HASH_LIST, M_UFSMNT, M_WAITOK,
    362  1.38       chs 	    &mask);
    363  1.38       chs 
    364  1.38       chs 	simple_lock(&pfs_hash_slock);
    365  1.38       chs 	oldhash = pfs_hashtbl;
    366  1.38       chs 	oldmask = pfs_ihash;
    367  1.38       chs 	pfs_hashtbl = hash;
    368  1.38       chs 	pfs_ihash = mask;
    369  1.38       chs 	for (i = 0; i <= oldmask; i++) {
    370  1.38       chs 		while ((pp = LIST_FIRST(&oldhash[i])) != NULL) {
    371  1.38       chs 			LIST_REMOVE(pp, pfs_hash);
    372  1.38       chs 			val = PFSPIDHASH(pp->pfs_pid);
    373  1.38       chs 			LIST_INSERT_HEAD(&hash[val], pp, pfs_hash);
    374  1.38       chs 		}
    375  1.38       chs 	}
    376  1.38       chs 	simple_unlock(&pfs_hash_slock);
    377  1.38       chs 	hashdone(oldhash, M_UFSMNT);
    378  1.38       chs }
    379  1.38       chs 
    380  1.31  jdolecek /*
    381  1.31  jdolecek  * Free pfsnode hash table.
    382  1.31  jdolecek  */
    383  1.31  jdolecek void
    384  1.31  jdolecek procfs_hashdone()
    385  1.31  jdolecek {
    386  1.31  jdolecek 	hashdone(pfs_hashtbl, M_UFSMNT);
    387  1.29      fvdl }
    388  1.29      fvdl 
    389  1.29      fvdl struct vnode *
    390  1.29      fvdl procfs_hashget(pid, type, mp)
    391  1.29      fvdl 	pid_t pid;
    392  1.29      fvdl 	pfstype type;
    393  1.29      fvdl 	struct mount *mp;
    394  1.29      fvdl {
    395  1.38       chs 	struct pfs_hashhead *ppp;
    396  1.29      fvdl 	struct pfsnode *pp;
    397  1.29      fvdl 	struct vnode *vp;
    398  1.29      fvdl 
    399  1.29      fvdl loop:
    400  1.29      fvdl 	simple_lock(&pfs_hash_slock);
    401  1.38       chs 	ppp = &pfs_hashtbl[PFSPIDHASH(pid)];
    402  1.38       chs 	LIST_FOREACH(pp, ppp, pfs_hash) {
    403  1.29      fvdl 		vp = PFSTOV(pp);
    404  1.29      fvdl 		if (pid == pp->pfs_pid && pp->pfs_type == type &&
    405  1.29      fvdl 		    vp->v_mount == mp) {
    406  1.29      fvdl 			simple_lock(&vp->v_interlock);
    407  1.29      fvdl 			simple_unlock(&pfs_hash_slock);
    408  1.29      fvdl 			if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK))
    409  1.29      fvdl 				goto loop;
    410  1.29      fvdl 			return (vp);
    411  1.29      fvdl 		}
    412  1.29      fvdl 	}
    413  1.29      fvdl 	simple_unlock(&pfs_hash_slock);
    414  1.29      fvdl 	return (NULL);
    415  1.29      fvdl }
    416  1.29      fvdl 
    417  1.29      fvdl /*
    418  1.29      fvdl  * Insert the pfsnode into the hash table and lock it.
    419  1.29      fvdl  */
    420  1.29      fvdl void
    421  1.29      fvdl procfs_hashins(pp)
    422  1.29      fvdl 	struct pfsnode *pp;
    423  1.29      fvdl {
    424  1.29      fvdl 	struct pfs_hashhead *ppp;
    425  1.29      fvdl 
    426  1.29      fvdl 	/* lock the pfsnode, then put it on the appropriate hash list */
    427  1.29      fvdl 	lockmgr(&pp->pfs_vnode->v_lock, LK_EXCLUSIVE, (struct simplelock *)0);
    428  1.29      fvdl 
    429  1.29      fvdl 	simple_lock(&pfs_hash_slock);
    430  1.38       chs 	ppp = &pfs_hashtbl[PFSPIDHASH(pp->pfs_pid)];
    431  1.29      fvdl 	LIST_INSERT_HEAD(ppp, pp, pfs_hash);
    432  1.29      fvdl 	simple_unlock(&pfs_hash_slock);
    433  1.29      fvdl }
    434  1.29      fvdl 
    435  1.29      fvdl /*
    436  1.29      fvdl  * Remove the pfsnode from the hash table.
    437  1.29      fvdl  */
    438  1.29      fvdl void
    439  1.29      fvdl procfs_hashrem(pp)
    440  1.29      fvdl 	struct pfsnode *pp;
    441  1.29      fvdl {
    442  1.29      fvdl 	simple_lock(&pfs_hash_slock);
    443  1.29      fvdl 	LIST_REMOVE(pp, pfs_hash);
    444  1.29      fvdl 	simple_unlock(&pfs_hash_slock);
    445  1.29      fvdl }
    446  1.29      fvdl 
    447  1.29      fvdl void
    448  1.29      fvdl procfs_revoke_vnodes(p, arg)
    449  1.29      fvdl 	struct proc *p;
    450  1.29      fvdl 	void *arg;
    451  1.29      fvdl {
    452  1.29      fvdl 	struct pfsnode *pfs, *pnext;
    453  1.29      fvdl 	struct vnode *vp;
    454  1.29      fvdl 	struct mount *mp = (struct mount *)arg;
    455  1.38       chs 	struct pfs_hashhead *ppp;
    456  1.29      fvdl 
    457  1.29      fvdl 	if (!(p->p_flag & P_SUGID))
    458  1.29      fvdl 		return;
    459  1.29      fvdl 
    460  1.38       chs 	ppp = &pfs_hashtbl[PFSPIDHASH(p->p_pid)];
    461  1.38       chs 	for (pfs = LIST_FIRST(ppp); pfs; pfs = pnext) {
    462  1.29      fvdl 		vp = PFSTOV(pfs);
    463  1.38       chs 		pnext = LIST_NEXT(pfs, pfs_hash);
    464  1.29      fvdl 		if (vp->v_usecount > 0 && pfs->pfs_pid == p->p_pid &&
    465  1.29      fvdl 		    vp->v_mount == mp)
    466  1.29      fvdl 			VOP_REVOKE(vp, REVOKEALL);
    467  1.29      fvdl 	}
    468   1.1        pk }
    469