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