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