1 /* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)dead_vnops.c 8.1 (Berkeley) 6/10/93 34 * $Id: dead_vnops.c,v 1.14 1997/09/02 20:06:08 bde Exp $ 35 */ 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/kernel.h> 40 #include <sys/vnode.h> 41 #include <sys/buf.h> 42 43 static int chkvnlock __P((struct vnode *)); 44 /* 45 * Prototypes for dead operations on vnodes. 46 */ 47 static int dead_badop __P((void)); 48 static int dead_ebadf __P((void)); 49 static int dead_lookup __P((struct vop_lookup_args *)); 50 #define dead_create ((int (*) __P((struct vop_create_args *)))dead_badop) 51 #define dead_mknod ((int (*) __P((struct vop_mknod_args *)))dead_badop) 52 static int dead_open __P((struct vop_open_args *)); 53 #define dead_close ((int (*) __P((struct vop_close_args *)))nullop) 54 #define dead_access ((int (*) __P((struct vop_access_args *)))dead_ebadf) 55 #define dead_getattr ((int (*) __P((struct vop_getattr_args *)))dead_ebadf) 56 #define dead_setattr ((int (*) __P((struct vop_setattr_args *)))dead_ebadf) 57 static int dead_read __P((struct vop_read_args *)); 58 static int dead_write __P((struct vop_write_args *)); 59 static int dead_ioctl __P((struct vop_ioctl_args *)); 60 #define dead_poll vop_nopoll 61 #define dead_mmap ((int (*) __P((struct vop_mmap_args *)))dead_badop) 62 #define dead_fsync ((int (*) __P((struct vop_fsync_args *)))nullop) 63 #define dead_seek ((int (*) __P((struct vop_seek_args *)))nullop) 64 #define dead_remove ((int (*) __P((struct vop_remove_args *)))dead_badop) 65 #define dead_link ((int (*) __P((struct vop_link_args *)))dead_badop) 66 #define dead_rename ((int (*) __P((struct vop_rename_args *)))dead_badop) 67 #define dead_mkdir ((int (*) __P((struct vop_mkdir_args *)))dead_badop) 68 #define dead_rmdir ((int (*) __P((struct vop_rmdir_args *)))dead_badop) 69 #define dead_symlink ((int (*) __P((struct vop_symlink_args *)))dead_badop) 70 #define dead_readdir ((int (*) __P((struct vop_readdir_args *)))dead_ebadf) 71 #define dead_readlink ((int (*) __P((struct vop_readlink_args *)))dead_ebadf) 72 #define dead_abortop ((int (*) __P((struct vop_abortop_args *)))dead_badop) 73 #define dead_inactive ((int (*) __P((struct vop_inactive_args *)))nullop) 74 #define dead_reclaim ((int (*) __P((struct vop_reclaim_args *)))nullop) 75 static int dead_lock __P((struct vop_lock_args *)); 76 #define dead_unlock ((int (*) __P((struct vop_unlock_args *)))vop_nounlock) 77 static int dead_bmap __P((struct vop_bmap_args *)); 78 static int dead_strategy __P((struct vop_strategy_args *)); 79 static int dead_print __P((struct vop_print_args *)); 80 #define dead_islocked ((int(*) __P((struct vop_islocked_args *)))vop_noislocked) 81 #define dead_pathconf ((int (*) __P((struct vop_pathconf_args *)))dead_ebadf) 82 #define dead_advlock ((int (*) __P((struct vop_advlock_args *)))dead_ebadf) 83 #define dead_blkatoff ((int (*) __P((struct vop_blkatoff_args *)))dead_badop) 84 #define dead_valloc ((int (*) __P((struct vop_valloc_args *)))dead_badop) 85 #define dead_vfree ((int (*) __P((struct vop_vfree_args *)))dead_badop) 86 #define dead_truncate ((int (*) __P((struct vop_truncate_args *)))nullop) 87 #define dead_update ((int (*) __P((struct vop_update_args *)))nullop) 88 #define dead_bwrite ((int (*) __P((struct vop_bwrite_args *)))nullop) 89 90 vop_t **dead_vnodeop_p; 91 static struct vnodeopv_entry_desc dead_vnodeop_entries[] = { 92 { &vop_default_desc, (vop_t *)vn_default_error }, 93 { &vop_lookup_desc, (vop_t *)dead_lookup }, /* lookup */ 94 /* XXX: vop_cachedlookup */ 95 { &vop_create_desc, (vop_t *)dead_create }, /* create */ 96 /* XXX: vop_whiteout */ 97 { &vop_mknod_desc, (vop_t *)dead_mknod }, /* mknod */ 98 { &vop_open_desc, (vop_t *)dead_open }, /* open */ 99 { &vop_close_desc, (vop_t *)dead_close }, /* close */ 100 { &vop_access_desc, (vop_t *)dead_access }, /* access */ 101 { &vop_getattr_desc, (vop_t *)dead_getattr }, /* getattr */ 102 { &vop_setattr_desc, (vop_t *)dead_setattr }, /* setattr */ 103 { &vop_read_desc, (vop_t *)dead_read }, /* read */ 104 { &vop_write_desc, (vop_t *)dead_write }, /* write */ 105 /* XXX: vop_lease */ 106 { &vop_ioctl_desc, (vop_t *)dead_ioctl }, /* ioctl */ 107 { &vop_poll_desc, (vop_t *)dead_poll }, /* poll */ 108 /* XXX: vop_revoke */ 109 { &vop_mmap_desc, (vop_t *)dead_mmap }, /* mmap */ 110 { &vop_fsync_desc, (vop_t *)dead_fsync }, /* fsync */ 111 { &vop_seek_desc, (vop_t *)dead_seek }, /* seek */ 112 { &vop_remove_desc, (vop_t *)dead_remove }, /* remove */ 113 { &vop_link_desc, (vop_t *)dead_link }, /* link */ 114 { &vop_rename_desc, (vop_t *)dead_rename }, /* rename */ 115 { &vop_mkdir_desc, (vop_t *)dead_mkdir }, /* mkdir */ 116 { &vop_rmdir_desc, (vop_t *)dead_rmdir }, /* rmdir */ 117 { &vop_symlink_desc, (vop_t *)dead_symlink }, /* symlink */ 118 { &vop_readdir_desc, (vop_t *)dead_readdir }, /* readdir */ 119 { &vop_readlink_desc, (vop_t *)dead_readlink }, /* readlink */ 120 { &vop_abortop_desc, (vop_t *)dead_abortop }, /* abortop */ 121 { &vop_inactive_desc, (vop_t *)dead_inactive }, /* inactive */ 122 { &vop_reclaim_desc, (vop_t *)dead_reclaim }, /* reclaim */ 123 { &vop_lock_desc, (vop_t *)dead_lock }, /* lock */ 124 { &vop_unlock_desc, (vop_t *)dead_unlock }, /* unlock */ 125 { &vop_bmap_desc, (vop_t *)dead_bmap }, /* bmap */ 126 { &vop_strategy_desc, (vop_t *)dead_strategy }, /* strategy */ 127 { &vop_print_desc, (vop_t *)dead_print }, /* print */ 128 { &vop_islocked_desc, (vop_t *)dead_islocked }, /* islocked */ 129 { &vop_pathconf_desc, (vop_t *)dead_pathconf }, /* pathconf */ 130 { &vop_advlock_desc, (vop_t *)dead_advlock }, /* advlock */ 131 { &vop_blkatoff_desc, (vop_t *)dead_blkatoff }, /* blkatoff */ 132 { &vop_valloc_desc, (vop_t *)dead_valloc }, /* valloc */ 133 /* XXX: vop_reallocblks */ 134 { &vop_vfree_desc, (vop_t *)dead_vfree }, /* vfree */ 135 { &vop_truncate_desc, (vop_t *)dead_truncate }, /* truncate */ 136 { &vop_update_desc, (vop_t *)dead_update }, /* update */ 137 /* XXX: vop_getpages */ 138 /* XXX: vop_putpages */ 139 { &vop_bwrite_desc, (vop_t *)dead_bwrite }, /* bwrite */ 140 { NULL, NULL } 141 }; 142 static struct vnodeopv_desc dead_vnodeop_opv_desc = 143 { &dead_vnodeop_p, dead_vnodeop_entries }; 144 145 VNODEOP_SET(dead_vnodeop_opv_desc); 146 147 /* 148 * Trivial lookup routine that always fails. 149 */ 150 /* ARGSUSED */ 151 static int 152 dead_lookup(ap) 153 struct vop_lookup_args /* { 154 struct vnode * a_dvp; 155 struct vnode ** a_vpp; 156 struct componentname * a_cnp; 157 } */ *ap; 158 { 159 160 *ap->a_vpp = NULL; 161 return (ENOTDIR); 162 } 163 164 /* 165 * Open always fails as if device did not exist. 166 */ 167 /* ARGSUSED */ 168 static int 169 dead_open(ap) 170 struct vop_open_args /* { 171 struct vnode *a_vp; 172 int a_mode; 173 struct ucred *a_cred; 174 struct proc *a_p; 175 } */ *ap; 176 { 177 178 return (ENXIO); 179 } 180 181 /* 182 * Vnode op for read 183 */ 184 /* ARGSUSED */ 185 static int 186 dead_read(ap) 187 struct vop_read_args /* { 188 struct vnode *a_vp; 189 struct uio *a_uio; 190 int a_ioflag; 191 struct ucred *a_cred; 192 } */ *ap; 193 { 194 195 if (chkvnlock(ap->a_vp)) 196 panic("dead_read: lock"); 197 #if 0 198 /* Lite2 behaviour */ 199 /* 200 * Return EOF for tty devices, EIO for others 201 */ 202 if ((ap->a_vp->v_flag & VISTTY) == 0) 203 return (EIO); 204 #else 205 /* 206 * Return EOF for character devices, EIO for others 207 */ 208 if (ap->a_vp->v_type != VCHR) 209 return (EIO); 210 #endif 211 return (0); 212 } 213 214 /* 215 * Vnode op for write 216 */ 217 /* ARGSUSED */ 218 static int 219 dead_write(ap) 220 struct vop_write_args /* { 221 struct vnode *a_vp; 222 struct uio *a_uio; 223 int a_ioflag; 224 struct ucred *a_cred; 225 } */ *ap; 226 { 227 228 if (chkvnlock(ap->a_vp)) 229 panic("dead_write: lock"); 230 return (EIO); 231 } 232 233 /* 234 * Device ioctl operation. 235 */ 236 /* ARGSUSED */ 237 static int 238 dead_ioctl(ap) 239 struct vop_ioctl_args /* { 240 struct vnode *a_vp; 241 int a_command; 242 caddr_t a_data; 243 int a_fflag; 244 struct ucred *a_cred; 245 struct proc *a_p; 246 } */ *ap; 247 { 248 249 if (!chkvnlock(ap->a_vp)) 250 return (EBADF); 251 return (VCALL(ap->a_vp, VOFFSET(vop_ioctl), ap)); 252 } 253 254 /* 255 * Just call the device strategy routine 256 */ 257 static int 258 dead_strategy(ap) 259 struct vop_strategy_args /* { 260 struct buf *a_bp; 261 } */ *ap; 262 { 263 264 if (ap->a_bp->b_vp == NULL || !chkvnlock(ap->a_bp->b_vp)) { 265 ap->a_bp->b_flags |= B_ERROR; 266 biodone(ap->a_bp); 267 return (EIO); 268 } 269 return (VOP_STRATEGY(ap->a_bp)); 270 } 271 272 /* 273 * Wait until the vnode has finished changing state. 274 */ 275 static int 276 dead_lock(ap) 277 struct vop_lock_args /* { 278 struct vnode *a_vp; 279 int a_flags; 280 struct proc *a_p; 281 } */ *ap; 282 { 283 struct vnode *vp = ap->a_vp; 284 285 /* 286 * Since we are not using the lock manager, we must clear 287 * the interlock here. 288 */ 289 if (ap->a_flags & LK_INTERLOCK) { 290 simple_unlock(&vp->v_interlock); 291 ap->a_flags &= ~LK_INTERLOCK; 292 } 293 if (!chkvnlock(vp)) 294 return (0); 295 return (VCALL(vp, VOFFSET(vop_lock), ap)); 296 } 297 298 /* 299 * Wait until the vnode has finished changing state. 300 */ 301 static int 302 dead_bmap(ap) 303 struct vop_bmap_args /* { 304 struct vnode *a_vp; 305 daddr_t a_bn; 306 struct vnode **a_vpp; 307 daddr_t *a_bnp; 308 int *a_runp; 309 int *a_runb; 310 } */ *ap; 311 { 312 313 if (!chkvnlock(ap->a_vp)) 314 return (EIO); 315 return (VOP_BMAP(ap->a_vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp, ap->a_runb)); 316 } 317 318 /* 319 * Print out the contents of a dead vnode. 320 */ 321 /* ARGSUSED */ 322 static int 323 dead_print(ap) 324 struct vop_print_args /* { 325 struct vnode *a_vp; 326 } */ *ap; 327 { 328 329 printf("tag VT_NON, dead vnode\n"); 330 return (0); 331 } 332 333 /* 334 * Empty vnode failed operation 335 */ 336 static int 337 dead_ebadf() 338 { 339 340 return (EBADF); 341 } 342 343 /* 344 * Empty vnode bad operation 345 */ 346 static int 347 dead_badop() 348 { 349 350 panic("dead_badop called"); 351 /* NOTREACHED */ 352 } 353 354 /* 355 * We have to wait during times when the vnode is 356 * in a state of change. 357 */ 358 int 359 chkvnlock(vp) 360 register struct vnode *vp; 361 { 362 int locked = 0; 363 364 while (vp->v_flag & VXLOCK) { 365 vp->v_flag |= VXWANT; 366 (void) tsleep((caddr_t)vp, PINOD, "ckvnlk", 0); 367 locked = 1; 368 } 369 return (locked); 370 } 371