Home | History | Annotate | Line # | Download | only in genfs
genfs_vnops.c revision 1.168
      1  1.168     pooka /*	$NetBSD: genfs_vnops.c,v 1.168 2009/04/18 15:40:33 pooka Exp $	*/
      2  1.164        ad 
      3  1.164        ad /*-
      4  1.164        ad  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      5  1.164        ad  * All rights reserved.
      6  1.164        ad  *
      7  1.164        ad  * Redistribution and use in source and binary forms, with or without
      8  1.164        ad  * modification, are permitted provided that the following conditions
      9  1.164        ad  * are met:
     10  1.164        ad  * 1. Redistributions of source code must retain the above copyright
     11  1.164        ad  *    notice, this list of conditions and the following disclaimer.
     12  1.164        ad  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.164        ad  *    notice, this list of conditions and the following disclaimer in the
     14  1.164        ad  *    documentation and/or other materials provided with the distribution.
     15  1.164        ad  *
     16  1.164        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.164        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.164        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.164        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.164        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.164        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.164        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.164        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.164        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.164        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.164        ad  * POSSIBILITY OF SUCH DAMAGE.
     27  1.164        ad  */
     28    1.6      fvdl 
     29    1.6      fvdl /*
     30    1.6      fvdl  * Copyright (c) 1982, 1986, 1989, 1993
     31    1.6      fvdl  *	The Regents of the University of California.  All rights reserved.
     32    1.6      fvdl  *
     33    1.6      fvdl  * Redistribution and use in source and binary forms, with or without
     34    1.6      fvdl  * modification, are permitted provided that the following conditions
     35    1.6      fvdl  * are met:
     36    1.6      fvdl  * 1. Redistributions of source code must retain the above copyright
     37    1.6      fvdl  *    notice, this list of conditions and the following disclaimer.
     38    1.6      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     39    1.6      fvdl  *    notice, this list of conditions and the following disclaimer in the
     40    1.6      fvdl  *    documentation and/or other materials provided with the distribution.
     41   1.81       agc  * 3. Neither the name of the University nor the names of its contributors
     42    1.6      fvdl  *    may be used to endorse or promote products derived from this software
     43    1.6      fvdl  *    without specific prior written permission.
     44    1.6      fvdl  *
     45    1.6      fvdl  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     46    1.6      fvdl  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     47    1.6      fvdl  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     48    1.6      fvdl  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     49    1.6      fvdl  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     50    1.6      fvdl  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     51    1.6      fvdl  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     52    1.6      fvdl  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     53    1.6      fvdl  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     54    1.6      fvdl  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     55    1.6      fvdl  * SUCH DAMAGE.
     56    1.6      fvdl  *
     57    1.6      fvdl  */
     58   1.40     lukem 
     59   1.40     lukem #include <sys/cdefs.h>
     60  1.168     pooka __KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.168 2009/04/18 15:40:33 pooka Exp $");
     61    1.8   thorpej 
     62    1.1   mycroft #include <sys/param.h>
     63    1.1   mycroft #include <sys/systm.h>
     64    1.6      fvdl #include <sys/proc.h>
     65    1.1   mycroft #include <sys/kernel.h>
     66    1.1   mycroft #include <sys/mount.h>
     67    1.1   mycroft #include <sys/namei.h>
     68    1.1   mycroft #include <sys/vnode.h>
     69   1.13  wrstuden #include <sys/fcntl.h>
     70  1.135      yamt #include <sys/kmem.h>
     71    1.3   mycroft #include <sys/poll.h>
     72   1.37       chs #include <sys/mman.h>
     73   1.66  jdolecek #include <sys/file.h>
     74  1.125      elad #include <sys/kauth.h>
     75    1.1   mycroft 
     76    1.1   mycroft #include <miscfs/genfs/genfs.h>
     77   1.37       chs #include <miscfs/genfs/genfs_node.h>
     78    1.6      fvdl #include <miscfs/specfs/specdev.h>
     79    1.1   mycroft 
     80   1.21       chs #include <uvm/uvm.h>
     81   1.21       chs #include <uvm/uvm_pager.h>
     82   1.21       chs 
     83   1.70  christos static void filt_genfsdetach(struct knote *);
     84   1.70  christos static int filt_genfsread(struct knote *, long);
     85   1.70  christos static int filt_genfsvnode(struct knote *, long);
     86   1.70  christos 
     87    1.1   mycroft int
     88   1.53     enami genfs_poll(void *v)
     89    1.1   mycroft {
     90    1.3   mycroft 	struct vop_poll_args /* {
     91    1.1   mycroft 		struct vnode *a_vp;
     92    1.3   mycroft 		int a_events;
     93  1.116  christos 		struct lwp *a_l;
     94    1.1   mycroft 	} */ *ap = v;
     95    1.1   mycroft 
     96    1.3   mycroft 	return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
     97    1.1   mycroft }
     98    1.1   mycroft 
     99    1.1   mycroft int
    100   1.53     enami genfs_seek(void *v)
    101    1.4    kleink {
    102    1.4    kleink 	struct vop_seek_args /* {
    103    1.4    kleink 		struct vnode *a_vp;
    104    1.4    kleink 		off_t a_oldoff;
    105    1.4    kleink 		off_t a_newoff;
    106  1.125      elad 		kauth_cred_t cred;
    107    1.4    kleink 	} */ *ap = v;
    108    1.4    kleink 
    109    1.4    kleink 	if (ap->a_newoff < 0)
    110    1.4    kleink 		return (EINVAL);
    111    1.4    kleink 
    112    1.4    kleink 	return (0);
    113    1.4    kleink }
    114    1.4    kleink 
    115    1.4    kleink int
    116   1.53     enami genfs_abortop(void *v)
    117    1.1   mycroft {
    118    1.1   mycroft 	struct vop_abortop_args /* {
    119    1.1   mycroft 		struct vnode *a_dvp;
    120    1.1   mycroft 		struct componentname *a_cnp;
    121    1.1   mycroft 	} */ *ap = v;
    122   1.53     enami 
    123    1.1   mycroft 	if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
    124   1.19   thorpej 		PNBUF_PUT(ap->a_cnp->cn_pnbuf);
    125    1.1   mycroft 	return (0);
    126   1.13  wrstuden }
    127   1.13  wrstuden 
    128   1.13  wrstuden int
    129   1.53     enami genfs_fcntl(void *v)
    130   1.13  wrstuden {
    131   1.13  wrstuden 	struct vop_fcntl_args /* {
    132   1.13  wrstuden 		struct vnode *a_vp;
    133   1.13  wrstuden 		u_int a_command;
    134  1.150  christos 		void *a_data;
    135   1.13  wrstuden 		int a_fflag;
    136  1.125      elad 		kauth_cred_t a_cred;
    137  1.116  christos 		struct lwp *a_l;
    138   1.13  wrstuden 	} */ *ap = v;
    139   1.13  wrstuden 
    140   1.13  wrstuden 	if (ap->a_command == F_SETFL)
    141   1.13  wrstuden 		return (0);
    142   1.13  wrstuden 	else
    143   1.13  wrstuden 		return (EOPNOTSUPP);
    144    1.1   mycroft }
    145    1.1   mycroft 
    146    1.1   mycroft /*ARGSUSED*/
    147    1.1   mycroft int
    148  1.138  christos genfs_badop(void *v)
    149    1.1   mycroft {
    150    1.1   mycroft 
    151    1.1   mycroft 	panic("genfs: bad op");
    152    1.1   mycroft }
    153    1.1   mycroft 
    154    1.1   mycroft /*ARGSUSED*/
    155    1.1   mycroft int
    156  1.138  christos genfs_nullop(void *v)
    157    1.1   mycroft {
    158    1.1   mycroft 
    159    1.1   mycroft 	return (0);
    160   1.10    kleink }
    161   1.10    kleink 
    162   1.10    kleink /*ARGSUSED*/
    163   1.10    kleink int
    164  1.138  christos genfs_einval(void *v)
    165   1.10    kleink {
    166   1.10    kleink 
    167   1.10    kleink 	return (EINVAL);
    168    1.1   mycroft }
    169    1.1   mycroft 
    170   1.12  wrstuden /*
    171   1.74  jdolecek  * Called when an fs doesn't support a particular vop.
    172   1.74  jdolecek  * This takes care to vrele, vput, or vunlock passed in vnodes.
    173   1.12  wrstuden  */
    174   1.12  wrstuden int
    175   1.75  jdolecek genfs_eopnotsupp(void *v)
    176   1.12  wrstuden {
    177   1.12  wrstuden 	struct vop_generic_args /*
    178   1.12  wrstuden 		struct vnodeop_desc *a_desc;
    179   1.53     enami 		/ * other random data follows, presumably * /
    180   1.12  wrstuden 	} */ *ap = v;
    181   1.12  wrstuden 	struct vnodeop_desc *desc = ap->a_desc;
    182   1.74  jdolecek 	struct vnode *vp, *vp_last = NULL;
    183   1.12  wrstuden 	int flags, i, j, offset;
    184   1.12  wrstuden 
    185   1.12  wrstuden 	flags = desc->vdesc_flags;
    186   1.12  wrstuden 	for (i = 0; i < VDESC_MAX_VPS; flags >>=1, i++) {
    187   1.12  wrstuden 		if ((offset = desc->vdesc_vp_offsets[i]) == VDESC_NO_OFFSET)
    188   1.12  wrstuden 			break;	/* stop at end of list */
    189   1.12  wrstuden 		if ((j = flags & VDESC_VP0_WILLPUT)) {
    190   1.53     enami 			vp = *VOPARG_OFFSETTO(struct vnode **, offset, ap);
    191   1.74  jdolecek 
    192   1.74  jdolecek 			/* Skip if NULL */
    193   1.74  jdolecek 			if (!vp)
    194   1.74  jdolecek 				continue;
    195   1.74  jdolecek 
    196   1.12  wrstuden 			switch (j) {
    197   1.12  wrstuden 			case VDESC_VP0_WILLPUT:
    198   1.74  jdolecek 				/* Check for dvp == vp cases */
    199   1.74  jdolecek 				if (vp == vp_last)
    200   1.74  jdolecek 					vrele(vp);
    201   1.74  jdolecek 				else {
    202   1.74  jdolecek 					vput(vp);
    203   1.74  jdolecek 					vp_last = vp;
    204   1.74  jdolecek 				}
    205   1.12  wrstuden 				break;
    206   1.12  wrstuden 			case VDESC_VP0_WILLUNLOCK:
    207   1.12  wrstuden 				VOP_UNLOCK(vp, 0);
    208   1.12  wrstuden 				break;
    209   1.12  wrstuden 			case VDESC_VP0_WILLRELE:
    210   1.12  wrstuden 				vrele(vp);
    211   1.12  wrstuden 				break;
    212   1.12  wrstuden 			}
    213   1.12  wrstuden 		}
    214   1.12  wrstuden 	}
    215   1.12  wrstuden 
    216   1.12  wrstuden 	return (EOPNOTSUPP);
    217   1.12  wrstuden }
    218   1.12  wrstuden 
    219    1.1   mycroft /*ARGSUSED*/
    220    1.1   mycroft int
    221  1.138  christos genfs_ebadf(void *v)
    222    1.1   mycroft {
    223    1.1   mycroft 
    224    1.1   mycroft 	return (EBADF);
    225    1.9  matthias }
    226    1.9  matthias 
    227    1.9  matthias /* ARGSUSED */
    228    1.9  matthias int
    229  1.138  christos genfs_enoioctl(void *v)
    230    1.9  matthias {
    231    1.9  matthias 
    232   1.51    atatat 	return (EPASSTHROUGH);
    233    1.6      fvdl }
    234    1.6      fvdl 
    235    1.6      fvdl 
    236    1.6      fvdl /*
    237   1.15      fvdl  * Eliminate all activity associated with the requested vnode
    238    1.6      fvdl  * and with all vnodes aliased to the requested vnode.
    239    1.6      fvdl  */
    240    1.6      fvdl int
    241   1.53     enami genfs_revoke(void *v)
    242    1.6      fvdl {
    243    1.6      fvdl 	struct vop_revoke_args /* {
    244    1.6      fvdl 		struct vnode *a_vp;
    245    1.6      fvdl 		int a_flags;
    246    1.6      fvdl 	} */ *ap = v;
    247    1.6      fvdl 
    248    1.6      fvdl #ifdef DIAGNOSTIC
    249    1.6      fvdl 	if ((ap->a_flags & REVOKEALL) == 0)
    250    1.6      fvdl 		panic("genfs_revoke: not revokeall");
    251    1.6      fvdl #endif
    252  1.161        ad 	vrevoke(ap->a_vp);
    253    1.6      fvdl 	return (0);
    254    1.6      fvdl }
    255    1.6      fvdl 
    256    1.6      fvdl /*
    257   1.12  wrstuden  * Lock the node.
    258    1.6      fvdl  */
    259    1.6      fvdl int
    260   1.53     enami genfs_lock(void *v)
    261    1.6      fvdl {
    262    1.6      fvdl 	struct vop_lock_args /* {
    263    1.6      fvdl 		struct vnode *a_vp;
    264    1.6      fvdl 		int a_flags;
    265    1.6      fvdl 	} */ *ap = v;
    266    1.6      fvdl 	struct vnode *vp = ap->a_vp;
    267  1.163        ad 	int flags = ap->a_flags;
    268    1.6      fvdl 
    269  1.163        ad 	if ((flags & LK_INTERLOCK) != 0) {
    270  1.163        ad 		flags &= ~LK_INTERLOCK;
    271  1.163        ad 		mutex_exit(&vp->v_interlock);
    272  1.163        ad 	}
    273  1.163        ad 
    274  1.163        ad 	return (vlockmgr(vp->v_vnlock, flags));
    275    1.6      fvdl }
    276    1.6      fvdl 
    277    1.6      fvdl /*
    278   1.12  wrstuden  * Unlock the node.
    279    1.6      fvdl  */
    280    1.6      fvdl int
    281   1.53     enami genfs_unlock(void *v)
    282    1.6      fvdl {
    283    1.6      fvdl 	struct vop_unlock_args /* {
    284    1.6      fvdl 		struct vnode *a_vp;
    285    1.6      fvdl 		int a_flags;
    286    1.6      fvdl 	} */ *ap = v;
    287    1.6      fvdl 	struct vnode *vp = ap->a_vp;
    288    1.6      fvdl 
    289  1.163        ad 	KASSERT(ap->a_flags == 0);
    290  1.163        ad 
    291  1.163        ad 	return (vlockmgr(vp->v_vnlock, LK_RELEASE));
    292    1.6      fvdl }
    293    1.6      fvdl 
    294    1.6      fvdl /*
    295   1.12  wrstuden  * Return whether or not the node is locked.
    296    1.6      fvdl  */
    297    1.6      fvdl int
    298   1.53     enami genfs_islocked(void *v)
    299    1.6      fvdl {
    300    1.6      fvdl 	struct vop_islocked_args /* {
    301    1.6      fvdl 		struct vnode *a_vp;
    302    1.6      fvdl 	} */ *ap = v;
    303    1.6      fvdl 	struct vnode *vp = ap->a_vp;
    304    1.6      fvdl 
    305  1.163        ad 	return (vlockstatus(vp->v_vnlock));
    306   1.12  wrstuden }
    307   1.12  wrstuden 
    308   1.12  wrstuden /*
    309   1.12  wrstuden  * Stubs to use when there is no locking to be done on the underlying object.
    310   1.12  wrstuden  */
    311   1.12  wrstuden int
    312   1.53     enami genfs_nolock(void *v)
    313   1.12  wrstuden {
    314   1.12  wrstuden 	struct vop_lock_args /* {
    315   1.12  wrstuden 		struct vnode *a_vp;
    316   1.12  wrstuden 		int a_flags;
    317  1.116  christos 		struct lwp *a_l;
    318   1.12  wrstuden 	} */ *ap = v;
    319   1.12  wrstuden 
    320   1.12  wrstuden 	/*
    321   1.12  wrstuden 	 * Since we are not using the lock manager, we must clear
    322   1.12  wrstuden 	 * the interlock here.
    323   1.12  wrstuden 	 */
    324   1.12  wrstuden 	if (ap->a_flags & LK_INTERLOCK)
    325  1.160        ad 		mutex_exit(&ap->a_vp->v_interlock);
    326   1.12  wrstuden 	return (0);
    327   1.12  wrstuden }
    328   1.12  wrstuden 
    329   1.12  wrstuden int
    330  1.138  christos genfs_nounlock(void *v)
    331   1.12  wrstuden {
    332   1.53     enami 
    333   1.12  wrstuden 	return (0);
    334   1.12  wrstuden }
    335   1.12  wrstuden 
    336   1.12  wrstuden int
    337  1.138  christos genfs_noislocked(void *v)
    338   1.12  wrstuden {
    339   1.53     enami 
    340   1.12  wrstuden 	return (0);
    341    1.8   thorpej }
    342    1.8   thorpej 
    343   1.34       chs int
    344  1.138  christos genfs_mmap(void *v)
    345   1.34       chs {
    346   1.53     enami 
    347   1.53     enami 	return (0);
    348   1.21       chs }
    349   1.21       chs 
    350  1.168     pooka /*
    351  1.168     pooka  * VOP_PUTPAGES() for vnodes which never have pages.
    352  1.168     pooka  */
    353  1.168     pooka 
    354  1.168     pooka int
    355  1.168     pooka genfs_null_putpages(void *v)
    356  1.168     pooka {
    357  1.168     pooka 	struct vop_putpages_args /* {
    358  1.168     pooka 		struct vnode *a_vp;
    359  1.168     pooka 		voff_t a_offlo;
    360  1.168     pooka 		voff_t a_offhi;
    361  1.168     pooka 		int a_flags;
    362  1.168     pooka 	} */ *ap = v;
    363  1.168     pooka 	struct vnode *vp = ap->a_vp;
    364  1.168     pooka 
    365  1.168     pooka 	KASSERT(vp->v_uobj.uo_npages == 0);
    366  1.168     pooka 	mutex_exit(&vp->v_interlock);
    367  1.168     pooka 	return (0);
    368  1.168     pooka }
    369  1.168     pooka 
    370   1.37       chs void
    371   1.98      yamt genfs_node_init(struct vnode *vp, const struct genfs_ops *ops)
    372   1.37       chs {
    373   1.37       chs 	struct genfs_node *gp = VTOG(vp);
    374   1.37       chs 
    375  1.146        ad 	rw_init(&gp->g_glock);
    376   1.37       chs 	gp->g_op = ops;
    377   1.37       chs }
    378   1.37       chs 
    379   1.37       chs void
    380  1.147        ad genfs_node_destroy(struct vnode *vp)
    381  1.147        ad {
    382  1.147        ad 	struct genfs_node *gp = VTOG(vp);
    383  1.147        ad 
    384  1.147        ad 	rw_destroy(&gp->g_glock);
    385  1.147        ad }
    386  1.147        ad 
    387  1.147        ad void
    388  1.138  christos genfs_size(struct vnode *vp, off_t size, off_t *eobp, int flags)
    389   1.21       chs {
    390   1.21       chs 	int bsize;
    391   1.21       chs 
    392   1.37       chs 	bsize = 1 << vp->v_mount->mnt_fs_bshift;
    393   1.37       chs 	*eobp = (size + bsize - 1) & ~(bsize - 1);
    394   1.43       chs }
    395   1.43       chs 
    396   1.66  jdolecek static void
    397   1.66  jdolecek filt_genfsdetach(struct knote *kn)
    398   1.66  jdolecek {
    399   1.66  jdolecek 	struct vnode *vp = (struct vnode *)kn->kn_hook;
    400   1.66  jdolecek 
    401  1.164        ad 	mutex_enter(&vp->v_interlock);
    402   1.66  jdolecek 	SLIST_REMOVE(&vp->v_klist, kn, knote, kn_selnext);
    403  1.164        ad 	mutex_exit(&vp->v_interlock);
    404   1.66  jdolecek }
    405   1.66  jdolecek 
    406   1.66  jdolecek static int
    407   1.66  jdolecek filt_genfsread(struct knote *kn, long hint)
    408   1.66  jdolecek {
    409   1.66  jdolecek 	struct vnode *vp = (struct vnode *)kn->kn_hook;
    410  1.164        ad 	int rv;
    411   1.66  jdolecek 
    412   1.66  jdolecek 	/*
    413   1.66  jdolecek 	 * filesystem is gone, so set the EOF flag and schedule
    414   1.66  jdolecek 	 * the knote for deletion.
    415   1.66  jdolecek 	 */
    416  1.164        ad 	switch (hint) {
    417  1.164        ad 	case NOTE_REVOKE:
    418  1.164        ad 		KASSERT(mutex_owned(&vp->v_interlock));
    419   1.66  jdolecek 		kn->kn_flags |= (EV_EOF | EV_ONESHOT);
    420   1.66  jdolecek 		return (1);
    421  1.164        ad 	case 0:
    422  1.164        ad 		mutex_enter(&vp->v_interlock);
    423  1.165        ad 		kn->kn_data = vp->v_size - ((file_t *)kn->kn_obj)->f_offset;
    424  1.164        ad 		rv = (kn->kn_data != 0);
    425  1.164        ad 		mutex_exit(&vp->v_interlock);
    426  1.164        ad 		return rv;
    427  1.164        ad 	default:
    428  1.164        ad 		KASSERT(mutex_owned(&vp->v_interlock));
    429  1.165        ad 		kn->kn_data = vp->v_size - ((file_t *)kn->kn_obj)->f_offset;
    430  1.164        ad 		return (kn->kn_data != 0);
    431   1.66  jdolecek 	}
    432   1.66  jdolecek }
    433   1.66  jdolecek 
    434   1.66  jdolecek static int
    435   1.66  jdolecek filt_genfsvnode(struct knote *kn, long hint)
    436   1.66  jdolecek {
    437  1.164        ad 	struct vnode *vp = (struct vnode *)kn->kn_hook;
    438  1.164        ad 	int fflags;
    439   1.66  jdolecek 
    440  1.164        ad 	switch (hint) {
    441  1.164        ad 	case NOTE_REVOKE:
    442  1.164        ad 		KASSERT(mutex_owned(&vp->v_interlock));
    443   1.66  jdolecek 		kn->kn_flags |= EV_EOF;
    444  1.164        ad 		if ((kn->kn_sfflags & hint) != 0)
    445  1.164        ad 			kn->kn_fflags |= hint;
    446   1.66  jdolecek 		return (1);
    447  1.164        ad 	case 0:
    448  1.164        ad 		mutex_enter(&vp->v_interlock);
    449  1.164        ad 		fflags = kn->kn_fflags;
    450  1.164        ad 		mutex_exit(&vp->v_interlock);
    451  1.164        ad 		break;
    452  1.164        ad 	default:
    453  1.164        ad 		KASSERT(mutex_owned(&vp->v_interlock));
    454  1.164        ad 		if ((kn->kn_sfflags & hint) != 0)
    455  1.164        ad 			kn->kn_fflags |= hint;
    456  1.164        ad 		fflags = kn->kn_fflags;
    457  1.164        ad 		break;
    458   1.66  jdolecek 	}
    459  1.164        ad 
    460  1.165        ad 	return (fflags != 0);
    461   1.66  jdolecek }
    462   1.66  jdolecek 
    463   1.96     perry static const struct filterops genfsread_filtops =
    464   1.66  jdolecek 	{ 1, NULL, filt_genfsdetach, filt_genfsread };
    465   1.96     perry static const struct filterops genfsvnode_filtops =
    466   1.66  jdolecek 	{ 1, NULL, filt_genfsdetach, filt_genfsvnode };
    467   1.66  jdolecek 
    468   1.66  jdolecek int
    469   1.66  jdolecek genfs_kqfilter(void *v)
    470   1.66  jdolecek {
    471   1.66  jdolecek 	struct vop_kqfilter_args /* {
    472   1.66  jdolecek 		struct vnode	*a_vp;
    473   1.66  jdolecek 		struct knote	*a_kn;
    474   1.66  jdolecek 	} */ *ap = v;
    475   1.66  jdolecek 	struct vnode *vp;
    476   1.66  jdolecek 	struct knote *kn;
    477   1.66  jdolecek 
    478   1.66  jdolecek 	vp = ap->a_vp;
    479   1.66  jdolecek 	kn = ap->a_kn;
    480   1.66  jdolecek 	switch (kn->kn_filter) {
    481   1.66  jdolecek 	case EVFILT_READ:
    482   1.66  jdolecek 		kn->kn_fop = &genfsread_filtops;
    483   1.66  jdolecek 		break;
    484   1.66  jdolecek 	case EVFILT_VNODE:
    485   1.66  jdolecek 		kn->kn_fop = &genfsvnode_filtops;
    486   1.66  jdolecek 		break;
    487   1.66  jdolecek 	default:
    488  1.159     pooka 		return (EINVAL);
    489   1.66  jdolecek 	}
    490   1.66  jdolecek 
    491   1.66  jdolecek 	kn->kn_hook = vp;
    492   1.66  jdolecek 
    493  1.164        ad 	mutex_enter(&vp->v_interlock);
    494   1.66  jdolecek 	SLIST_INSERT_HEAD(&vp->v_klist, kn, kn_selnext);
    495  1.164        ad 	mutex_exit(&vp->v_interlock);
    496   1.66  jdolecek 
    497   1.66  jdolecek 	return (0);
    498    1.1   mycroft }
    499  1.136      yamt 
    500  1.136      yamt void
    501  1.136      yamt genfs_node_wrlock(struct vnode *vp)
    502  1.136      yamt {
    503  1.136      yamt 	struct genfs_node *gp = VTOG(vp);
    504  1.136      yamt 
    505  1.146        ad 	rw_enter(&gp->g_glock, RW_WRITER);
    506  1.136      yamt }
    507  1.136      yamt 
    508  1.136      yamt void
    509  1.136      yamt genfs_node_rdlock(struct vnode *vp)
    510  1.136      yamt {
    511  1.136      yamt 	struct genfs_node *gp = VTOG(vp);
    512  1.136      yamt 
    513  1.146        ad 	rw_enter(&gp->g_glock, RW_READER);
    514  1.136      yamt }
    515  1.136      yamt 
    516  1.136      yamt void
    517  1.136      yamt genfs_node_unlock(struct vnode *vp)
    518  1.136      yamt {
    519  1.136      yamt 	struct genfs_node *gp = VTOG(vp);
    520  1.136      yamt 
    521  1.146        ad 	rw_exit(&gp->g_glock);
    522  1.136      yamt }
    523