Home | History | Annotate | Line # | Download | only in deadfs
dead_vnops.c revision 1.32
      1  1.32       chs /*	$NetBSD: dead_vnops.c,v 1.32 2001/12/06 04:27:40 chs 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.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1       cgd  *    must display the following acknowledgement:
     17   1.1       cgd  *	This product includes software developed by the University of
     18   1.1       cgd  *	California, Berkeley and its contributors.
     19   1.1       cgd  * 4. Neither the name of the University nor the names of its contributors
     20   1.1       cgd  *    may be used to endorse or promote products derived from this software
     21   1.1       cgd  *    without specific prior written permission.
     22   1.1       cgd  *
     23   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1       cgd  * SUCH DAMAGE.
     34   1.1       cgd  *
     35  1.13   mycroft  *	@(#)dead_vnops.c	8.2 (Berkeley) 11/21/94
     36   1.1       cgd  */
     37  1.31     lukem 
     38  1.31     lukem #include <sys/cdefs.h>
     39  1.32       chs __KERNEL_RCSID(0, "$NetBSD: dead_vnops.c,v 1.32 2001/12/06 04:27:40 chs Exp $");
     40   1.1       cgd 
     41   1.6   mycroft #include <sys/param.h>
     42   1.6   mycroft #include <sys/systm.h>
     43   1.6   mycroft #include <sys/time.h>
     44   1.6   mycroft #include <sys/vnode.h>
     45   1.6   mycroft #include <sys/errno.h>
     46   1.6   mycroft #include <sys/namei.h>
     47   1.6   mycroft #include <sys/buf.h>
     48  1.14  christos #include <sys/proc.h>
     49   1.1       cgd 
     50  1.17   mycroft #include <miscfs/genfs/genfs.h>
     51  1.17   mycroft 
     52   1.1       cgd /*
     53   1.1       cgd  * Prototypes for dead operations on vnodes.
     54   1.1       cgd  */
     55  1.14  christos int	dead_lookup	__P((void *));
     56  1.17   mycroft #define dead_create	genfs_badop
     57  1.17   mycroft #define dead_mknod	genfs_badop
     58  1.14  christos int	dead_open	__P((void *));
     59  1.17   mycroft #define dead_close	genfs_nullop
     60  1.17   mycroft #define dead_access	genfs_ebadf
     61  1.17   mycroft #define dead_getattr	genfs_ebadf
     62  1.17   mycroft #define dead_setattr	genfs_ebadf
     63  1.14  christos int	dead_read	__P((void *));
     64  1.14  christos int	dead_write	__P((void *));
     65  1.26  sommerfe #define dead_lease_check genfs_nullop
     66  1.27  sommerfe #define dead_fcntl	genfs_nullop
     67  1.14  christos int	dead_ioctl	__P((void *));
     68  1.19   mycroft int	dead_poll	__P((void *));
     69  1.17   mycroft #define dead_mmap	genfs_badop
     70  1.17   mycroft #define dead_fsync	genfs_nullop
     71  1.17   mycroft #define dead_seek	genfs_nullop
     72  1.17   mycroft #define dead_remove	genfs_badop
     73  1.17   mycroft #define dead_link	genfs_badop
     74  1.17   mycroft #define dead_rename	genfs_badop
     75  1.17   mycroft #define dead_mkdir	genfs_badop
     76  1.17   mycroft #define dead_rmdir	genfs_badop
     77  1.17   mycroft #define dead_symlink	genfs_badop
     78  1.17   mycroft #define dead_readdir	genfs_ebadf
     79  1.17   mycroft #define dead_readlink	genfs_ebadf
     80  1.17   mycroft #define dead_abortop	genfs_badop
     81  1.17   mycroft #define dead_inactive	genfs_nullop
     82  1.17   mycroft #define dead_reclaim	genfs_nullop
     83  1.14  christos int	dead_lock	__P((void *));
     84  1.17   mycroft #define dead_unlock	genfs_nullop
     85  1.14  christos int	dead_bmap	__P((void *));
     86  1.14  christos int	dead_strategy	__P((void *));
     87  1.14  christos int	dead_print	__P((void *));
     88  1.17   mycroft #define dead_islocked	genfs_nullop
     89  1.17   mycroft #define dead_pathconf	genfs_ebadf
     90  1.17   mycroft #define dead_advlock	genfs_ebadf
     91  1.17   mycroft #define dead_blkatoff	genfs_badop
     92  1.17   mycroft #define dead_valloc	genfs_badop
     93  1.17   mycroft #define dead_vfree	genfs_badop
     94  1.17   mycroft #define dead_truncate	genfs_nullop
     95  1.17   mycroft #define dead_update	genfs_nullop
     96  1.17   mycroft #define dead_bwrite	genfs_nullop
     97  1.22      fvdl #define dead_revoke	genfs_nullop
     98  1.32       chs #define dead_putpages	genfs_null_putpages
     99  1.14  christos 
    100  1.14  christos int	chkvnlock __P((struct vnode *));
    101  1.14  christos 
    102  1.14  christos int (**dead_vnodeop_p) __P((void *));
    103   1.8   mycroft 
    104  1.30  jdolecek const struct vnodeopv_entry_desc dead_vnodeop_entries[] = {
    105   1.8   mycroft 	{ &vop_default_desc, vn_default_error },
    106  1.17   mycroft 	{ &vop_lookup_desc, dead_lookup },		/* lookup */
    107  1.17   mycroft 	{ &vop_create_desc, dead_create },		/* create */
    108  1.17   mycroft 	{ &vop_mknod_desc, dead_mknod },		/* mknod */
    109  1.17   mycroft 	{ &vop_open_desc, dead_open },			/* open */
    110  1.17   mycroft 	{ &vop_close_desc, dead_close },		/* close */
    111  1.17   mycroft 	{ &vop_access_desc, dead_access },		/* access */
    112  1.17   mycroft 	{ &vop_getattr_desc, dead_getattr },		/* getattr */
    113  1.17   mycroft 	{ &vop_setattr_desc, dead_setattr },		/* setattr */
    114  1.17   mycroft 	{ &vop_read_desc, dead_read },			/* read */
    115  1.17   mycroft 	{ &vop_write_desc, dead_write },		/* write */
    116  1.26  sommerfe 	{ &vop_lease_desc, dead_lease_check },		/* lease */
    117  1.25  sommerfe 	{ &vop_fcntl_desc, dead_fcntl },		/* fcntl */
    118  1.17   mycroft 	{ &vop_ioctl_desc, dead_ioctl },		/* ioctl */
    119  1.19   mycroft 	{ &vop_poll_desc, dead_poll },			/* poll */
    120  1.22      fvdl 	{ &vop_revoke_desc, dead_revoke },		/* revoke */
    121  1.17   mycroft 	{ &vop_mmap_desc, dead_mmap },			/* mmap */
    122  1.17   mycroft 	{ &vop_fsync_desc, dead_fsync },		/* fsync */
    123  1.17   mycroft 	{ &vop_seek_desc, dead_seek },			/* seek */
    124  1.17   mycroft 	{ &vop_remove_desc, dead_remove },		/* remove */
    125  1.17   mycroft 	{ &vop_link_desc, dead_link },			/* link */
    126  1.17   mycroft 	{ &vop_rename_desc, dead_rename },		/* rename */
    127  1.17   mycroft 	{ &vop_mkdir_desc, dead_mkdir },		/* mkdir */
    128  1.17   mycroft 	{ &vop_rmdir_desc, dead_rmdir },		/* rmdir */
    129  1.17   mycroft 	{ &vop_symlink_desc, dead_symlink },		/* symlink */
    130  1.17   mycroft 	{ &vop_readdir_desc, dead_readdir },		/* readdir */
    131  1.17   mycroft 	{ &vop_readlink_desc, dead_readlink },		/* readlink */
    132  1.17   mycroft 	{ &vop_abortop_desc, dead_abortop },		/* abortop */
    133  1.17   mycroft 	{ &vop_inactive_desc, dead_inactive },		/* inactive */
    134  1.17   mycroft 	{ &vop_reclaim_desc, dead_reclaim },		/* reclaim */
    135  1.17   mycroft 	{ &vop_lock_desc, dead_lock },			/* lock */
    136  1.17   mycroft 	{ &vop_unlock_desc, dead_unlock },		/* unlock */
    137  1.17   mycroft 	{ &vop_bmap_desc, dead_bmap },			/* bmap */
    138  1.17   mycroft 	{ &vop_strategy_desc, dead_strategy },		/* strategy */
    139  1.17   mycroft 	{ &vop_print_desc, dead_print },		/* print */
    140  1.17   mycroft 	{ &vop_islocked_desc, dead_islocked },		/* islocked */
    141  1.17   mycroft 	{ &vop_pathconf_desc, dead_pathconf },		/* pathconf */
    142  1.17   mycroft 	{ &vop_advlock_desc, dead_advlock },		/* advlock */
    143  1.17   mycroft 	{ &vop_blkatoff_desc, dead_blkatoff },		/* blkatoff */
    144  1.17   mycroft 	{ &vop_valloc_desc, dead_valloc },		/* valloc */
    145  1.17   mycroft 	{ &vop_vfree_desc, dead_vfree },		/* vfree */
    146  1.17   mycroft 	{ &vop_truncate_desc, dead_truncate },		/* truncate */
    147  1.17   mycroft 	{ &vop_update_desc, dead_update },		/* update */
    148  1.17   mycroft 	{ &vop_bwrite_desc, dead_bwrite },		/* bwrite */
    149  1.32       chs 	{ &vop_putpages_desc, dead_putpages },		/* putpages */
    150  1.32       chs 	{ NULL, NULL }
    151   1.1       cgd };
    152  1.30  jdolecek const struct vnodeopv_desc dead_vnodeop_opv_desc =
    153   1.8   mycroft 	{ &dead_vnodeop_p, dead_vnodeop_entries };
    154   1.1       cgd 
    155   1.1       cgd /*
    156   1.1       cgd  * Trivial lookup routine that always fails.
    157   1.1       cgd  */
    158   1.1       cgd /* ARGSUSED */
    159   1.3    andrew int
    160  1.14  christos dead_lookup(v)
    161  1.14  christos 	void *v;
    162  1.14  christos {
    163   1.8   mycroft 	struct vop_lookup_args /* {
    164   1.8   mycroft 		struct vnode * a_dvp;
    165   1.8   mycroft 		struct vnode ** a_vpp;
    166   1.8   mycroft 		struct componentname * a_cnp;
    167  1.14  christos 	} */ *ap = v;
    168   1.1       cgd 
    169   1.8   mycroft 	*ap->a_vpp = NULL;
    170   1.1       cgd 	return (ENOTDIR);
    171   1.1       cgd }
    172   1.1       cgd 
    173   1.1       cgd /*
    174   1.1       cgd  * Open always fails as if device did not exist.
    175   1.1       cgd  */
    176   1.1       cgd /* ARGSUSED */
    177  1.14  christos int
    178  1.14  christos dead_open(v)
    179  1.14  christos 	void *v;
    180   1.1       cgd {
    181   1.1       cgd 
    182   1.1       cgd 	return (ENXIO);
    183   1.1       cgd }
    184   1.1       cgd 
    185   1.1       cgd /*
    186   1.1       cgd  * Vnode op for read
    187   1.1       cgd  */
    188   1.1       cgd /* ARGSUSED */
    189  1.14  christos int
    190  1.14  christos dead_read(v)
    191  1.14  christos 	void *v;
    192  1.14  christos {
    193   1.8   mycroft 	struct vop_read_args /* {
    194   1.8   mycroft 		struct vnode *a_vp;
    195   1.8   mycroft 		struct uio *a_uio;
    196   1.8   mycroft 		int  a_ioflag;
    197   1.8   mycroft 		struct ucred *a_cred;
    198  1.14  christos 	} */ *ap = v;
    199   1.1       cgd 
    200   1.8   mycroft 	if (chkvnlock(ap->a_vp))
    201   1.1       cgd 		panic("dead_read: lock");
    202   1.1       cgd 	/*
    203  1.13   mycroft 	 * Return EOF for tty devices, EIO for others
    204   1.1       cgd 	 */
    205  1.13   mycroft 	if ((ap->a_vp->v_flag & VISTTY) == 0)
    206   1.1       cgd 		return (EIO);
    207   1.1       cgd 	return (0);
    208   1.1       cgd }
    209   1.1       cgd 
    210   1.1       cgd /*
    211   1.1       cgd  * Vnode op for write
    212   1.1       cgd  */
    213   1.1       cgd /* ARGSUSED */
    214  1.14  christos int
    215  1.14  christos dead_write(v)
    216  1.14  christos 	void *v;
    217  1.14  christos {
    218   1.8   mycroft 	struct vop_write_args /* {
    219   1.8   mycroft 		struct vnode *a_vp;
    220   1.8   mycroft 		struct uio *a_uio;
    221   1.8   mycroft 		int  a_ioflag;
    222   1.8   mycroft 		struct ucred *a_cred;
    223  1.14  christos 	} */ *ap = v;
    224   1.1       cgd 
    225   1.8   mycroft 	if (chkvnlock(ap->a_vp))
    226   1.1       cgd 		panic("dead_write: lock");
    227   1.1       cgd 	return (EIO);
    228   1.1       cgd }
    229   1.1       cgd 
    230   1.1       cgd /*
    231   1.1       cgd  * Device ioctl operation.
    232   1.1       cgd  */
    233   1.1       cgd /* ARGSUSED */
    234  1.14  christos int
    235  1.14  christos dead_ioctl(v)
    236  1.14  christos 	void *v;
    237  1.14  christos {
    238   1.8   mycroft 	struct vop_ioctl_args /* {
    239   1.8   mycroft 		struct vnode *a_vp;
    240  1.10       cgd 		u_long a_command;
    241   1.8   mycroft 		caddr_t  a_data;
    242   1.8   mycroft 		int  a_fflag;
    243   1.8   mycroft 		struct ucred *a_cred;
    244   1.8   mycroft 		struct proc *a_p;
    245  1.14  christos 	} */ *ap = v;
    246   1.1       cgd 
    247   1.8   mycroft 	if (!chkvnlock(ap->a_vp))
    248   1.1       cgd 		return (EBADF);
    249   1.8   mycroft 	return (VCALL(ap->a_vp, VOFFSET(vop_ioctl), ap));
    250   1.1       cgd }
    251   1.1       cgd 
    252   1.1       cgd /* ARGSUSED */
    253  1.14  christos int
    254  1.19   mycroft dead_poll(v)
    255  1.14  christos 	void *v;
    256   1.1       cgd {
    257  1.19   mycroft 	struct vop_poll_args /* {
    258  1.17   mycroft 		struct vnode *a_vp;
    259  1.19   mycroft 		int a_events;
    260  1.17   mycroft 		struct proc *a_p;
    261  1.17   mycroft 	} */ *ap = v;
    262  1.17   mycroft 
    263   1.1       cgd 	/*
    264   1.1       cgd 	 * Let the user find out that the descriptor is gone.
    265   1.1       cgd 	 */
    266  1.19   mycroft 	return (ap->a_events);
    267   1.1       cgd }
    268   1.1       cgd 
    269   1.1       cgd /*
    270   1.1       cgd  * Just call the device strategy routine
    271   1.1       cgd  */
    272  1.14  christos int
    273  1.14  christos dead_strategy(v)
    274  1.14  christos 	void *v;
    275  1.14  christos {
    276  1.14  christos 
    277   1.8   mycroft 	struct vop_strategy_args /* {
    278   1.8   mycroft 		struct buf *a_bp;
    279  1.14  christos 	} */ *ap = v;
    280   1.8   mycroft 	if (ap->a_bp->b_vp == NULL || !chkvnlock(ap->a_bp->b_vp)) {
    281   1.8   mycroft 		ap->a_bp->b_flags |= B_ERROR;
    282   1.8   mycroft 		biodone(ap->a_bp);
    283   1.1       cgd 		return (EIO);
    284   1.1       cgd 	}
    285   1.8   mycroft 	return (VOP_STRATEGY(ap->a_bp));
    286   1.1       cgd }
    287   1.1       cgd 
    288   1.1       cgd /*
    289   1.1       cgd  * Wait until the vnode has finished changing state.
    290   1.1       cgd  */
    291  1.14  christos int
    292  1.14  christos dead_lock(v)
    293  1.14  christos 	void *v;
    294  1.14  christos {
    295   1.8   mycroft 	struct vop_lock_args /* {
    296   1.8   mycroft 		struct vnode *a_vp;
    297  1.23        pk 		int a_flags;
    298  1.23        pk 		struct proc *a_p;
    299  1.14  christos 	} */ *ap = v;
    300   1.1       cgd 
    301  1.24      fvdl 	if (ap->a_flags & LK_INTERLOCK) {
    302  1.23        pk 		simple_unlock(&ap->a_vp->v_interlock);
    303  1.24      fvdl 		ap->a_flags &= ~LK_INTERLOCK;
    304  1.24      fvdl 	}
    305   1.8   mycroft 	if (!chkvnlock(ap->a_vp))
    306   1.1       cgd 		return (0);
    307   1.8   mycroft 	return (VCALL(ap->a_vp, VOFFSET(vop_lock), ap));
    308   1.1       cgd }
    309   1.1       cgd 
    310   1.1       cgd /*
    311   1.1       cgd  * Wait until the vnode has finished changing state.
    312   1.1       cgd  */
    313  1.14  christos int
    314  1.14  christos dead_bmap(v)
    315  1.14  christos 	void *v;
    316  1.14  christos {
    317   1.8   mycroft 	struct vop_bmap_args /* {
    318   1.8   mycroft 		struct vnode *a_vp;
    319   1.8   mycroft 		daddr_t  a_bn;
    320   1.8   mycroft 		struct vnode **a_vpp;
    321   1.8   mycroft 		daddr_t *a_bnp;
    322   1.8   mycroft 		int *a_runp;
    323  1.14  christos 	} */ *ap = v;
    324   1.1       cgd 
    325   1.8   mycroft 	if (!chkvnlock(ap->a_vp))
    326   1.1       cgd 		return (EIO);
    327   1.8   mycroft 	return (VOP_BMAP(ap->a_vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp));
    328   1.1       cgd }
    329   1.1       cgd 
    330   1.1       cgd /*
    331   1.1       cgd  * Print out the contents of a dead vnode.
    332   1.1       cgd  */
    333   1.1       cgd /* ARGSUSED */
    334  1.14  christos int
    335  1.14  christos dead_print(v)
    336  1.14  christos 	void *v;
    337   1.1       cgd {
    338  1.21  christos 	printf("tag VT_NON, dead vnode\n");
    339  1.14  christos 	return 0;
    340   1.1       cgd }
    341   1.1       cgd 
    342   1.1       cgd /*
    343   1.1       cgd  * We have to wait during times when the vnode is
    344   1.1       cgd  * in a state of change.
    345   1.1       cgd  */
    346  1.14  christos int
    347   1.1       cgd chkvnlock(vp)
    348  1.28  augustss 	struct vnode *vp;
    349   1.1       cgd {
    350   1.1       cgd 	int locked = 0;
    351   1.1       cgd 
    352   1.1       cgd 	while (vp->v_flag & VXLOCK) {
    353   1.1       cgd 		vp->v_flag |= VXWANT;
    354  1.29   thorpej 		(void) tsleep(vp, PINOD, "deadchk", 0);
    355   1.1       cgd 		locked = 1;
    356   1.1       cgd 	}
    357   1.1       cgd 	return (locked);
    358   1.1       cgd }
    359