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