Home | History | Annotate | Line # | Download | only in deadfs
dead_vnops.c revision 1.47.24.1
      1  1.47.24.1       jym /*	$NetBSD: dead_vnops.c,v 1.47.24.1 2009/05/13 17:22:16 jym Exp $	*/
      2        1.9       cgd 
      3        1.1       cgd /*
      4        1.8   mycroft  * Copyright (c) 1989, 1993
      5        1.8   mycroft  *	The Regents of the University of California.  All rights reserved.
      6        1.1       cgd  *
      7        1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8        1.1       cgd  * modification, are permitted provided that the following conditions
      9        1.1       cgd  * are met:
     10        1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11        1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12        1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14        1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15       1.33       agc  * 3. Neither the name of the University nor the names of its contributors
     16        1.1       cgd  *    may be used to endorse or promote products derived from this software
     17        1.1       cgd  *    without specific prior written permission.
     18        1.1       cgd  *
     19        1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20        1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21        1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22        1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23        1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24        1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25        1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26        1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27        1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28        1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29        1.1       cgd  * SUCH DAMAGE.
     30        1.1       cgd  *
     31       1.13   mycroft  *	@(#)dead_vnops.c	8.2 (Berkeley) 11/21/94
     32        1.1       cgd  */
     33       1.31     lukem 
     34       1.31     lukem #include <sys/cdefs.h>
     35  1.47.24.1       jym __KERNEL_RCSID(0, "$NetBSD: dead_vnops.c,v 1.47.24.1 2009/05/13 17:22:16 jym Exp $");
     36        1.1       cgd 
     37        1.6   mycroft #include <sys/param.h>
     38        1.6   mycroft #include <sys/systm.h>
     39        1.6   mycroft #include <sys/time.h>
     40        1.6   mycroft #include <sys/vnode.h>
     41        1.6   mycroft #include <sys/errno.h>
     42        1.6   mycroft #include <sys/namei.h>
     43        1.6   mycroft #include <sys/buf.h>
     44       1.14  christos #include <sys/proc.h>
     45        1.1       cgd 
     46       1.17   mycroft #include <miscfs/genfs/genfs.h>
     47       1.17   mycroft 
     48        1.1       cgd /*
     49        1.1       cgd  * Prototypes for dead operations on vnodes.
     50        1.1       cgd  */
     51       1.36   xtraeme int	dead_open(void *);
     52       1.17   mycroft #define dead_close	genfs_nullop
     53       1.36   xtraeme int	dead_read(void *);
     54       1.36   xtraeme int	dead_write(void *);
     55       1.27  sommerfe #define dead_fcntl	genfs_nullop
     56       1.36   xtraeme int	dead_ioctl(void *);
     57       1.36   xtraeme int	dead_poll(void *);
     58       1.17   mycroft #define dead_fsync	genfs_nullop
     59       1.17   mycroft #define dead_seek	genfs_nullop
     60       1.17   mycroft #define dead_inactive	genfs_nullop
     61       1.17   mycroft #define dead_reclaim	genfs_nullop
     62       1.36   xtraeme int	dead_lock(void *);
     63       1.17   mycroft #define dead_unlock	genfs_nullop
     64       1.36   xtraeme int	dead_bmap(void *);
     65       1.36   xtraeme int	dead_strategy(void *);
     66       1.36   xtraeme int	dead_print(void *);
     67       1.17   mycroft #define dead_islocked	genfs_nullop
     68       1.17   mycroft #define dead_bwrite	genfs_nullop
     69       1.22      fvdl #define dead_revoke	genfs_nullop
     70       1.43     pooka int	dead_getpages(void *);
     71       1.32       chs #define dead_putpages	genfs_null_putpages
     72       1.14  christos 
     73       1.45        ad int	chkvnlock(struct vnode *, bool);
     74       1.42       chs int	dead_default_error(void *);
     75       1.14  christos 
     76       1.36   xtraeme int (**dead_vnodeop_p)(void *);
     77        1.8   mycroft 
     78       1.30  jdolecek const struct vnodeopv_entry_desc dead_vnodeop_entries[] = {
     79       1.42       chs 	{ &vop_default_desc, dead_default_error },
     80       1.17   mycroft 	{ &vop_open_desc, dead_open },			/* open */
     81       1.17   mycroft 	{ &vop_close_desc, dead_close },		/* close */
     82       1.17   mycroft 	{ &vop_read_desc, dead_read },			/* read */
     83       1.17   mycroft 	{ &vop_write_desc, dead_write },		/* write */
     84       1.25  sommerfe 	{ &vop_fcntl_desc, dead_fcntl },		/* fcntl */
     85       1.17   mycroft 	{ &vop_ioctl_desc, dead_ioctl },		/* ioctl */
     86       1.19   mycroft 	{ &vop_poll_desc, dead_poll },			/* poll */
     87       1.22      fvdl 	{ &vop_revoke_desc, dead_revoke },		/* revoke */
     88       1.17   mycroft 	{ &vop_fsync_desc, dead_fsync },		/* fsync */
     89       1.17   mycroft 	{ &vop_seek_desc, dead_seek },			/* seek */
     90       1.17   mycroft 	{ &vop_inactive_desc, dead_inactive },		/* inactive */
     91       1.17   mycroft 	{ &vop_reclaim_desc, dead_reclaim },		/* reclaim */
     92       1.17   mycroft 	{ &vop_lock_desc, dead_lock },			/* lock */
     93       1.17   mycroft 	{ &vop_unlock_desc, dead_unlock },		/* unlock */
     94       1.17   mycroft 	{ &vop_bmap_desc, dead_bmap },			/* bmap */
     95       1.17   mycroft 	{ &vop_strategy_desc, dead_strategy },		/* strategy */
     96       1.17   mycroft 	{ &vop_print_desc, dead_print },		/* print */
     97       1.17   mycroft 	{ &vop_islocked_desc, dead_islocked },		/* islocked */
     98       1.17   mycroft 	{ &vop_bwrite_desc, dead_bwrite },		/* bwrite */
     99       1.43     pooka 	{ &vop_getpages_desc, dead_getpages },		/* getpages */
    100       1.32       chs 	{ &vop_putpages_desc, dead_putpages },		/* putpages */
    101       1.32       chs 	{ NULL, NULL }
    102        1.1       cgd };
    103       1.30  jdolecek const struct vnodeopv_desc dead_vnodeop_opv_desc =
    104        1.8   mycroft 	{ &dead_vnodeop_p, dead_vnodeop_entries };
    105        1.1       cgd 
    106        1.3    andrew int
    107       1.42       chs dead_default_error(void *v)
    108       1.14  christos {
    109        1.1       cgd 
    110       1.42       chs 	return EBADF;
    111        1.1       cgd }
    112        1.1       cgd 
    113        1.1       cgd /*
    114        1.1       cgd  * Open always fails as if device did not exist.
    115        1.1       cgd  */
    116        1.1       cgd /* ARGSUSED */
    117       1.14  christos int
    118       1.41  christos dead_open(void *v)
    119        1.1       cgd {
    120        1.1       cgd 
    121        1.1       cgd 	return (ENXIO);
    122        1.1       cgd }
    123        1.1       cgd 
    124        1.1       cgd /*
    125        1.1       cgd  * Vnode op for read
    126        1.1       cgd  */
    127        1.1       cgd /* ARGSUSED */
    128       1.14  christos int
    129  1.47.24.1       jym dead_read(void *v)
    130       1.14  christos {
    131        1.8   mycroft 	struct vop_read_args /* {
    132        1.8   mycroft 		struct vnode *a_vp;
    133        1.8   mycroft 		struct uio *a_uio;
    134        1.8   mycroft 		int  a_ioflag;
    135       1.39      elad 		kauth_cred_t a_cred;
    136       1.14  christos 	} */ *ap = v;
    137        1.1       cgd 
    138       1.45        ad 	if (chkvnlock(ap->a_vp, false))
    139        1.1       cgd 		panic("dead_read: lock");
    140        1.1       cgd 	/*
    141       1.13   mycroft 	 * Return EOF for tty devices, EIO for others
    142        1.1       cgd 	 */
    143       1.45        ad 	if ((ap->a_vp->v_vflag & VV_ISTTY) == 0)
    144        1.1       cgd 		return (EIO);
    145        1.1       cgd 	return (0);
    146        1.1       cgd }
    147        1.1       cgd 
    148        1.1       cgd /*
    149        1.1       cgd  * Vnode op for write
    150        1.1       cgd  */
    151        1.1       cgd /* ARGSUSED */
    152       1.14  christos int
    153  1.47.24.1       jym dead_write(void *v)
    154       1.14  christos {
    155        1.8   mycroft 	struct vop_write_args /* {
    156        1.8   mycroft 		struct vnode *a_vp;
    157        1.8   mycroft 		struct uio *a_uio;
    158        1.8   mycroft 		int  a_ioflag;
    159       1.39      elad 		kauth_cred_t a_cred;
    160       1.14  christos 	} */ *ap = v;
    161        1.1       cgd 
    162       1.45        ad 	if (chkvnlock(ap->a_vp, false))
    163        1.1       cgd 		panic("dead_write: lock");
    164        1.1       cgd 	return (EIO);
    165        1.1       cgd }
    166        1.1       cgd 
    167        1.1       cgd /*
    168        1.1       cgd  * Device ioctl operation.
    169        1.1       cgd  */
    170        1.1       cgd /* ARGSUSED */
    171       1.14  christos int
    172  1.47.24.1       jym dead_ioctl(void *v)
    173       1.14  christos {
    174        1.8   mycroft 	struct vop_ioctl_args /* {
    175        1.8   mycroft 		struct vnode *a_vp;
    176       1.10       cgd 		u_long a_command;
    177       1.35       jrf 		void *a_data;
    178        1.8   mycroft 		int  a_fflag;
    179       1.39      elad 		kauth_cred_t a_cred;
    180       1.38  christos 		struct lwp *a_l;
    181       1.14  christos 	} */ *ap = v;
    182        1.1       cgd 
    183       1.45        ad 	if (!chkvnlock(ap->a_vp, false))
    184        1.1       cgd 		return (EBADF);
    185        1.8   mycroft 	return (VCALL(ap->a_vp, VOFFSET(vop_ioctl), ap));
    186        1.1       cgd }
    187        1.1       cgd 
    188        1.1       cgd /* ARGSUSED */
    189       1.14  christos int
    190  1.47.24.1       jym dead_poll(void *v)
    191        1.1       cgd {
    192       1.19   mycroft 	struct vop_poll_args /* {
    193       1.17   mycroft 		struct vnode *a_vp;
    194       1.19   mycroft 		int a_events;
    195       1.38  christos 		struct lwp *a_l;
    196       1.17   mycroft 	} */ *ap = v;
    197       1.17   mycroft 
    198        1.1       cgd 	/*
    199        1.1       cgd 	 * Let the user find out that the descriptor is gone.
    200        1.1       cgd 	 */
    201       1.19   mycroft 	return (ap->a_events);
    202        1.1       cgd }
    203        1.1       cgd 
    204        1.1       cgd /*
    205        1.1       cgd  * Just call the device strategy routine
    206        1.1       cgd  */
    207       1.14  christos int
    208  1.47.24.1       jym dead_strategy(void *v)
    209       1.14  christos {
    210       1.14  christos 
    211        1.8   mycroft 	struct vop_strategy_args /* {
    212       1.34   hannken 		struct vnode *a_vp;
    213        1.8   mycroft 		struct buf *a_bp;
    214       1.14  christos 	} */ *ap = v;
    215       1.45        ad 	struct buf *bp;
    216       1.45        ad 	if (ap->a_vp == NULL || !chkvnlock(ap->a_vp, false)) {
    217       1.45        ad 		bp = ap->a_bp;
    218       1.45        ad 		bp->b_error = EIO;
    219       1.45        ad 		bp->b_resid = bp->b_bcount;
    220        1.8   mycroft 		biodone(ap->a_bp);
    221        1.1       cgd 		return (EIO);
    222        1.1       cgd 	}
    223       1.34   hannken 	return (VOP_STRATEGY(ap->a_vp, ap->a_bp));
    224        1.1       cgd }
    225        1.1       cgd 
    226        1.1       cgd /*
    227        1.1       cgd  * Wait until the vnode has finished changing state.
    228        1.1       cgd  */
    229       1.14  christos int
    230  1.47.24.1       jym dead_lock(void *v)
    231       1.14  christos {
    232        1.8   mycroft 	struct vop_lock_args /* {
    233        1.8   mycroft 		struct vnode *a_vp;
    234       1.23        pk 		int a_flags;
    235       1.23        pk 		struct proc *a_p;
    236       1.14  christos 	} */ *ap = v;
    237       1.45        ad 	bool interlock;
    238        1.1       cgd 
    239       1.24      fvdl 	if (ap->a_flags & LK_INTERLOCK) {
    240       1.45        ad 		interlock = true;
    241       1.24      fvdl 		ap->a_flags &= ~LK_INTERLOCK;
    242       1.45        ad 	} else
    243       1.45        ad 		interlock = false;
    244       1.45        ad 	if (!chkvnlock(ap->a_vp, interlock))
    245        1.1       cgd 		return (0);
    246        1.8   mycroft 	return (VCALL(ap->a_vp, VOFFSET(vop_lock), ap));
    247        1.1       cgd }
    248        1.1       cgd 
    249        1.1       cgd /*
    250        1.1       cgd  * Wait until the vnode has finished changing state.
    251        1.1       cgd  */
    252       1.14  christos int
    253  1.47.24.1       jym dead_bmap(void *v)
    254       1.14  christos {
    255        1.8   mycroft 	struct vop_bmap_args /* {
    256        1.8   mycroft 		struct vnode *a_vp;
    257        1.8   mycroft 		daddr_t  a_bn;
    258        1.8   mycroft 		struct vnode **a_vpp;
    259        1.8   mycroft 		daddr_t *a_bnp;
    260        1.8   mycroft 		int *a_runp;
    261       1.14  christos 	} */ *ap = v;
    262        1.1       cgd 
    263       1.45        ad 	if (!chkvnlock(ap->a_vp, false))
    264        1.1       cgd 		return (EIO);
    265        1.8   mycroft 	return (VOP_BMAP(ap->a_vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp));
    266        1.1       cgd }
    267        1.1       cgd 
    268        1.1       cgd /*
    269        1.1       cgd  * Print out the contents of a dead vnode.
    270        1.1       cgd  */
    271        1.1       cgd /* ARGSUSED */
    272       1.14  christos int
    273       1.41  christos dead_print(void *v)
    274        1.1       cgd {
    275       1.21  christos 	printf("tag VT_NON, dead vnode\n");
    276       1.14  christos 	return 0;
    277        1.1       cgd }
    278        1.1       cgd 
    279       1.43     pooka int
    280       1.43     pooka dead_getpages(void *v)
    281       1.43     pooka {
    282       1.43     pooka 	struct vop_getpages_args /* {
    283       1.43     pooka 		struct vnode *a_vp;
    284       1.43     pooka 		voff_t a_offset;
    285       1.43     pooka 		struct vm_page **a_m;
    286       1.43     pooka 		int *a_count;
    287       1.43     pooka 		int a_centeridx;
    288       1.43     pooka 		vm_prot_t a_access_type;
    289       1.43     pooka 		int a_advice;
    290       1.43     pooka 		int a_flags;
    291       1.43     pooka 	} */ *ap = v;
    292       1.43     pooka 
    293       1.43     pooka 	if ((ap->a_flags & PGO_LOCKED) == 0)
    294       1.46        ad 		mutex_exit(&ap->a_vp->v_interlock);
    295       1.43     pooka 
    296       1.43     pooka 	return (EFAULT);
    297       1.43     pooka }
    298       1.43     pooka 
    299        1.1       cgd /*
    300        1.1       cgd  * We have to wait during times when the vnode is
    301        1.1       cgd  * in a state of change.
    302        1.1       cgd  */
    303       1.14  christos int
    304  1.47.24.1       jym chkvnlock(struct vnode *vp, bool interlock)
    305        1.1       cgd {
    306        1.1       cgd 	int locked = 0;
    307        1.1       cgd 
    308       1.45        ad 	if (!interlock)
    309       1.46        ad 		mutex_enter(&vp->v_interlock);
    310       1.45        ad 	while (vp->v_iflag & VI_XLOCK) {
    311       1.46        ad 		vwait(vp, VI_XLOCK);
    312        1.1       cgd 		locked = 1;
    313        1.1       cgd 	}
    314       1.46        ad 	mutex_exit(&vp->v_interlock);
    315       1.45        ad 
    316        1.1       cgd 	return (locked);
    317        1.1       cgd }
    318