Home | History | Annotate | Line # | Download | only in deadfs
dead_vnops.c revision 1.14
      1  1.14  christos /*	$NetBSD: dead_vnops.c,v 1.14 1996/02/09 22:39:56 christos 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.1       cgd 
     38   1.6   mycroft #include <sys/param.h>
     39   1.6   mycroft #include <sys/systm.h>
     40   1.6   mycroft #include <sys/time.h>
     41   1.6   mycroft #include <sys/vnode.h>
     42   1.6   mycroft #include <sys/errno.h>
     43   1.6   mycroft #include <sys/namei.h>
     44   1.6   mycroft #include <sys/buf.h>
     45  1.14  christos #include <sys/proc.h>
     46   1.1       cgd 
     47   1.1       cgd /*
     48   1.1       cgd  * Prototypes for dead operations on vnodes.
     49   1.1       cgd  */
     50  1.14  christos int	dead_badop	__P((void *));
     51  1.14  christos int	dead_ebadf	__P((void *));
     52  1.14  christos int	dead_nullop	__P((void *));
     53  1.14  christos int	dead_lookup	__P((void *));
     54  1.14  christos #define dead_create	dead_badop
     55  1.14  christos #define dead_mknod	dead_badop
     56  1.14  christos int	dead_open	__P((void *));
     57  1.14  christos #define dead_close	nullop
     58  1.14  christos #define dead_access	dead_ebadf
     59  1.14  christos #define dead_getattr	dead_ebadf
     60  1.14  christos #define dead_setattr	dead_ebadf
     61  1.14  christos int	dead_read	__P((void *));
     62  1.14  christos int	dead_write	__P((void *));
     63  1.14  christos int	dead_ioctl	__P((void *));
     64  1.14  christos int	dead_select	__P((void *));
     65  1.14  christos #define dead_mmap	dead_badop
     66  1.14  christos #define dead_fsync	nullop
     67  1.14  christos #define dead_seek	nullop
     68  1.14  christos #define dead_remove	dead_badop
     69  1.14  christos #define dead_link	dead_badop
     70  1.14  christos #define dead_rename	dead_badop
     71  1.14  christos #define dead_mkdir	dead_badop
     72  1.14  christos #define dead_rmdir	dead_badop
     73  1.14  christos #define dead_symlink	dead_badop
     74  1.14  christos #define dead_readdir	dead_ebadf
     75  1.14  christos #define dead_readlink	dead_ebadf
     76  1.14  christos #define dead_abortop	dead_badop
     77  1.14  christos #define dead_inactive	nullop
     78  1.14  christos #define dead_reclaim	nullop
     79  1.14  christos int	dead_lock	__P((void *));
     80  1.14  christos #define dead_unlock	nullop
     81  1.14  christos int	dead_bmap	__P((void *));
     82  1.14  christos int	dead_strategy	__P((void *));
     83  1.14  christos int	dead_print	__P((void *));
     84  1.14  christos #define dead_islocked	nullop
     85  1.14  christos #define dead_pathconf	dead_ebadf
     86  1.14  christos #define dead_advlock	dead_ebadf
     87  1.14  christos #define dead_blkatoff	dead_badop
     88  1.14  christos #define dead_valloc	dead_badop
     89  1.14  christos #define dead_vfree	dead_badop
     90  1.14  christos #define dead_truncate	nullop
     91  1.14  christos #define dead_update	nullop
     92  1.14  christos #define dead_bwrite	nullop
     93  1.14  christos 
     94  1.14  christos int	chkvnlock __P((struct vnode *));
     95  1.14  christos 
     96  1.14  christos int (**dead_vnodeop_p) __P((void *));
     97   1.8   mycroft 
     98   1.8   mycroft struct vnodeopv_entry_desc dead_vnodeop_entries[] = {
     99   1.8   mycroft 	{ &vop_default_desc, vn_default_error },
    100   1.8   mycroft 	{ &vop_lookup_desc, dead_lookup },	/* lookup */
    101   1.8   mycroft 	{ &vop_create_desc, dead_create },	/* create */
    102   1.8   mycroft 	{ &vop_mknod_desc, dead_mknod },	/* mknod */
    103  1.14  christos 	{ &vop_open_desc, dead_open },		/* open */
    104   1.8   mycroft 	{ &vop_close_desc, dead_close },	/* close */
    105   1.8   mycroft 	{ &vop_access_desc, dead_access },	/* access */
    106   1.8   mycroft 	{ &vop_getattr_desc, dead_getattr },	/* getattr */
    107   1.8   mycroft 	{ &vop_setattr_desc, dead_setattr },	/* setattr */
    108  1.14  christos 	{ &vop_read_desc, dead_read },		/* read */
    109   1.8   mycroft 	{ &vop_write_desc, dead_write },	/* write */
    110   1.8   mycroft 	{ &vop_ioctl_desc, dead_ioctl },	/* ioctl */
    111   1.8   mycroft 	{ &vop_select_desc, dead_select },	/* select */
    112  1.14  christos 	{ &vop_mmap_desc, dead_mmap },		/* mmap */
    113   1.8   mycroft 	{ &vop_fsync_desc, dead_fsync },	/* fsync */
    114  1.14  christos 	{ &vop_seek_desc, dead_seek },		/* seek */
    115   1.8   mycroft 	{ &vop_remove_desc, dead_remove },	/* remove */
    116  1.14  christos 	{ &vop_link_desc, dead_link },		/* link */
    117   1.8   mycroft 	{ &vop_rename_desc, dead_rename },	/* rename */
    118   1.8   mycroft 	{ &vop_mkdir_desc, dead_mkdir },	/* mkdir */
    119   1.8   mycroft 	{ &vop_rmdir_desc, dead_rmdir },	/* rmdir */
    120   1.8   mycroft 	{ &vop_symlink_desc, dead_symlink },	/* symlink */
    121   1.8   mycroft 	{ &vop_readdir_desc, dead_readdir },	/* readdir */
    122   1.8   mycroft 	{ &vop_readlink_desc, dead_readlink },	/* readlink */
    123   1.8   mycroft 	{ &vop_abortop_desc, dead_abortop },	/* abortop */
    124   1.8   mycroft 	{ &vop_inactive_desc, dead_inactive },	/* inactive */
    125   1.8   mycroft 	{ &vop_reclaim_desc, dead_reclaim },	/* reclaim */
    126  1.14  christos 	{ &vop_lock_desc, dead_lock },		/* lock */
    127   1.8   mycroft 	{ &vop_unlock_desc, dead_unlock },	/* unlock */
    128  1.14  christos 	{ &vop_bmap_desc, dead_bmap },		/* bmap */
    129   1.8   mycroft 	{ &vop_strategy_desc, dead_strategy },	/* strategy */
    130   1.8   mycroft 	{ &vop_print_desc, dead_print },	/* print */
    131   1.8   mycroft 	{ &vop_islocked_desc, dead_islocked },	/* islocked */
    132   1.8   mycroft 	{ &vop_pathconf_desc, dead_pathconf },	/* pathconf */
    133   1.8   mycroft 	{ &vop_advlock_desc, dead_advlock },	/* advlock */
    134   1.8   mycroft 	{ &vop_blkatoff_desc, dead_blkatoff },	/* blkatoff */
    135   1.8   mycroft 	{ &vop_valloc_desc, dead_valloc },	/* valloc */
    136   1.8   mycroft 	{ &vop_vfree_desc, dead_vfree },	/* vfree */
    137   1.8   mycroft 	{ &vop_truncate_desc, dead_truncate },	/* truncate */
    138   1.8   mycroft 	{ &vop_update_desc, dead_update },	/* update */
    139   1.8   mycroft 	{ &vop_bwrite_desc, dead_bwrite },	/* bwrite */
    140  1.14  christos 	{ (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
    141   1.1       cgd };
    142   1.8   mycroft struct vnodeopv_desc dead_vnodeop_opv_desc =
    143   1.8   mycroft 	{ &dead_vnodeop_p, dead_vnodeop_entries };
    144   1.1       cgd 
    145   1.1       cgd /*
    146   1.1       cgd  * Trivial lookup routine that always fails.
    147   1.1       cgd  */
    148   1.1       cgd /* ARGSUSED */
    149   1.3    andrew int
    150  1.14  christos dead_lookup(v)
    151  1.14  christos 	void *v;
    152  1.14  christos {
    153   1.8   mycroft 	struct vop_lookup_args /* {
    154   1.8   mycroft 		struct vnode * a_dvp;
    155   1.8   mycroft 		struct vnode ** a_vpp;
    156   1.8   mycroft 		struct componentname * a_cnp;
    157  1.14  christos 	} */ *ap = v;
    158   1.1       cgd 
    159   1.8   mycroft 	*ap->a_vpp = NULL;
    160   1.1       cgd 	return (ENOTDIR);
    161   1.1       cgd }
    162   1.1       cgd 
    163   1.1       cgd /*
    164   1.1       cgd  * Open always fails as if device did not exist.
    165   1.1       cgd  */
    166   1.1       cgd /* ARGSUSED */
    167  1.14  christos int
    168  1.14  christos dead_open(v)
    169  1.14  christos 	void *v;
    170   1.1       cgd {
    171   1.1       cgd 
    172   1.1       cgd 	return (ENXIO);
    173   1.1       cgd }
    174   1.1       cgd 
    175   1.1       cgd /*
    176   1.1       cgd  * Vnode op for read
    177   1.1       cgd  */
    178   1.1       cgd /* ARGSUSED */
    179  1.14  christos int
    180  1.14  christos dead_read(v)
    181  1.14  christos 	void *v;
    182  1.14  christos {
    183   1.8   mycroft 	struct vop_read_args /* {
    184   1.8   mycroft 		struct vnode *a_vp;
    185   1.8   mycroft 		struct uio *a_uio;
    186   1.8   mycroft 		int  a_ioflag;
    187   1.8   mycroft 		struct ucred *a_cred;
    188  1.14  christos 	} */ *ap = v;
    189   1.1       cgd 
    190   1.8   mycroft 	if (chkvnlock(ap->a_vp))
    191   1.1       cgd 		panic("dead_read: lock");
    192   1.1       cgd 	/*
    193  1.13   mycroft 	 * Return EOF for tty devices, EIO for others
    194   1.1       cgd 	 */
    195  1.13   mycroft 	if ((ap->a_vp->v_flag & VISTTY) == 0)
    196   1.1       cgd 		return (EIO);
    197   1.1       cgd 	return (0);
    198   1.1       cgd }
    199   1.1       cgd 
    200   1.1       cgd /*
    201   1.1       cgd  * Vnode op for write
    202   1.1       cgd  */
    203   1.1       cgd /* ARGSUSED */
    204  1.14  christos int
    205  1.14  christos dead_write(v)
    206  1.14  christos 	void *v;
    207  1.14  christos {
    208   1.8   mycroft 	struct vop_write_args /* {
    209   1.8   mycroft 		struct vnode *a_vp;
    210   1.8   mycroft 		struct uio *a_uio;
    211   1.8   mycroft 		int  a_ioflag;
    212   1.8   mycroft 		struct ucred *a_cred;
    213  1.14  christos 	} */ *ap = v;
    214   1.1       cgd 
    215   1.8   mycroft 	if (chkvnlock(ap->a_vp))
    216   1.1       cgd 		panic("dead_write: lock");
    217   1.1       cgd 	return (EIO);
    218   1.1       cgd }
    219   1.1       cgd 
    220   1.1       cgd /*
    221   1.1       cgd  * Device ioctl operation.
    222   1.1       cgd  */
    223   1.1       cgd /* ARGSUSED */
    224  1.14  christos int
    225  1.14  christos dead_ioctl(v)
    226  1.14  christos 	void *v;
    227  1.14  christos {
    228   1.8   mycroft 	struct vop_ioctl_args /* {
    229   1.8   mycroft 		struct vnode *a_vp;
    230  1.10       cgd 		u_long a_command;
    231   1.8   mycroft 		caddr_t  a_data;
    232   1.8   mycroft 		int  a_fflag;
    233   1.8   mycroft 		struct ucred *a_cred;
    234   1.8   mycroft 		struct proc *a_p;
    235  1.14  christos 	} */ *ap = v;
    236   1.1       cgd 
    237   1.8   mycroft 	if (!chkvnlock(ap->a_vp))
    238   1.1       cgd 		return (EBADF);
    239   1.8   mycroft 	return (VCALL(ap->a_vp, VOFFSET(vop_ioctl), ap));
    240   1.1       cgd }
    241   1.1       cgd 
    242   1.1       cgd /* ARGSUSED */
    243  1.14  christos int
    244  1.14  christos dead_select(v)
    245  1.14  christos 	void *v;
    246   1.1       cgd {
    247   1.1       cgd 	/*
    248   1.1       cgd 	 * Let the user find out that the descriptor is gone.
    249   1.1       cgd 	 */
    250   1.1       cgd 	return (1);
    251   1.1       cgd }
    252   1.1       cgd 
    253   1.1       cgd /*
    254   1.1       cgd  * Just call the device strategy routine
    255   1.1       cgd  */
    256  1.14  christos int
    257  1.14  christos dead_strategy(v)
    258  1.14  christos 	void *v;
    259  1.14  christos {
    260  1.14  christos 
    261   1.8   mycroft 	struct vop_strategy_args /* {
    262   1.8   mycroft 		struct buf *a_bp;
    263  1.14  christos 	} */ *ap = v;
    264   1.8   mycroft 	if (ap->a_bp->b_vp == NULL || !chkvnlock(ap->a_bp->b_vp)) {
    265   1.8   mycroft 		ap->a_bp->b_flags |= B_ERROR;
    266   1.8   mycroft 		biodone(ap->a_bp);
    267   1.1       cgd 		return (EIO);
    268   1.1       cgd 	}
    269   1.8   mycroft 	return (VOP_STRATEGY(ap->a_bp));
    270   1.1       cgd }
    271   1.1       cgd 
    272   1.1       cgd /*
    273   1.1       cgd  * Wait until the vnode has finished changing state.
    274   1.1       cgd  */
    275  1.14  christos int
    276  1.14  christos dead_lock(v)
    277  1.14  christos 	void *v;
    278  1.14  christos {
    279   1.8   mycroft 	struct vop_lock_args /* {
    280   1.8   mycroft 		struct vnode *a_vp;
    281  1.14  christos 	} */ *ap = v;
    282   1.1       cgd 
    283   1.8   mycroft 	if (!chkvnlock(ap->a_vp))
    284   1.1       cgd 		return (0);
    285   1.8   mycroft 	return (VCALL(ap->a_vp, VOFFSET(vop_lock), ap));
    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_bmap(v)
    293  1.14  christos 	void *v;
    294  1.14  christos {
    295   1.8   mycroft 	struct vop_bmap_args /* {
    296   1.8   mycroft 		struct vnode *a_vp;
    297   1.8   mycroft 		daddr_t  a_bn;
    298   1.8   mycroft 		struct vnode **a_vpp;
    299   1.8   mycroft 		daddr_t *a_bnp;
    300   1.8   mycroft 		int *a_runp;
    301  1.14  christos 	} */ *ap = v;
    302   1.1       cgd 
    303   1.8   mycroft 	if (!chkvnlock(ap->a_vp))
    304   1.1       cgd 		return (EIO);
    305   1.8   mycroft 	return (VOP_BMAP(ap->a_vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp));
    306   1.1       cgd }
    307   1.1       cgd 
    308   1.1       cgd /*
    309   1.1       cgd  * Print out the contents of a dead vnode.
    310   1.1       cgd  */
    311   1.1       cgd /* ARGSUSED */
    312  1.14  christos int
    313  1.14  christos dead_print(v)
    314  1.14  christos 	void *v;
    315   1.1       cgd {
    316   1.1       cgd 	printf("tag VT_NON, dead vnode\n");
    317  1.14  christos 	return 0;
    318   1.1       cgd }
    319   1.1       cgd 
    320   1.1       cgd /*
    321   1.1       cgd  * Empty vnode failed operation
    322   1.1       cgd  */
    323  1.14  christos /*ARGSUSED*/
    324  1.14  christos int
    325  1.14  christos dead_ebadf(v)
    326  1.14  christos 	void *v;
    327   1.1       cgd {
    328   1.1       cgd 
    329   1.1       cgd 	return (EBADF);
    330   1.1       cgd }
    331   1.1       cgd 
    332   1.1       cgd /*
    333   1.1       cgd  * Empty vnode bad operation
    334   1.1       cgd  */
    335  1.14  christos /*ARGSUSED*/
    336  1.14  christos int
    337  1.14  christos dead_badop(v)
    338  1.14  christos 	void *v;
    339   1.1       cgd {
    340   1.1       cgd 
    341   1.1       cgd 	panic("dead_badop called");
    342   1.1       cgd 	/* NOTREACHED */
    343   1.1       cgd }
    344   1.1       cgd 
    345   1.1       cgd /*
    346   1.1       cgd  * Empty vnode null operation
    347   1.1       cgd  */
    348  1.14  christos /*ARGSUSED*/
    349  1.14  christos int
    350  1.14  christos dead_nullop(v)
    351  1.14  christos 	void *v;
    352   1.1       cgd {
    353   1.1       cgd 
    354   1.1       cgd 	return (0);
    355   1.1       cgd }
    356   1.1       cgd 
    357   1.1       cgd /*
    358   1.1       cgd  * We have to wait during times when the vnode is
    359   1.1       cgd  * in a state of change.
    360   1.1       cgd  */
    361  1.14  christos int
    362   1.1       cgd chkvnlock(vp)
    363   1.1       cgd 	register struct vnode *vp;
    364   1.1       cgd {
    365   1.1       cgd 	int locked = 0;
    366   1.1       cgd 
    367   1.1       cgd 	while (vp->v_flag & VXLOCK) {
    368   1.1       cgd 		vp->v_flag |= VXWANT;
    369   1.8   mycroft 		sleep((caddr_t)vp, PINOD);
    370   1.1       cgd 		locked = 1;
    371   1.1       cgd 	}
    372   1.1       cgd 	return (locked);
    373   1.1       cgd }
    374