dead_vnops.c revision 59368
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 * $FreeBSD: head/sys/fs/deadfs/dead_vnops.c 59368 2000-04-18 15:15:39Z phk $
35 */
36
37#include <sys/param.h>
38#include <sys/systm.h>
39#include <sys/kernel.h>
40#include <sys/lock.h>
41#include <sys/vnode.h>
42#include <sys/poll.h>
43
44static int	chkvnlock __P((struct vnode *));
45/*
46 * Prototypes for dead operations on vnodes.
47 */
48static int	dead_badop __P((void));
49static int	dead_bmap __P((struct vop_bmap_args *));
50static int	dead_ioctl __P((struct vop_ioctl_args *));
51static int	dead_lock __P((struct vop_lock_args *));
52static int	dead_lookup __P((struct vop_lookup_args *));
53static int	dead_open __P((struct vop_open_args *));
54static int	dead_poll __P((struct vop_poll_args *));
55static int	dead_print __P((struct vop_print_args *));
56static int	dead_read __P((struct vop_read_args *));
57static int	dead_write __P((struct vop_write_args *));
58
59vop_t **dead_vnodeop_p;
60static struct vnodeopv_entry_desc dead_vnodeop_entries[] = {
61	{ &vop_default_desc,		(vop_t *) vop_defaultop },
62	{ &vop_access_desc,		(vop_t *) vop_ebadf },
63	{ &vop_advlock_desc,		(vop_t *) vop_ebadf },
64	{ &vop_bmap_desc,		(vop_t *) dead_bmap },
65	{ &vop_create_desc,		(vop_t *) dead_badop },
66	{ &vop_getattr_desc,		(vop_t *) vop_ebadf },
67	{ &vop_inactive_desc,		(vop_t *) vop_null },
68	{ &vop_ioctl_desc,		(vop_t *) dead_ioctl },
69	{ &vop_link_desc,		(vop_t *) dead_badop },
70	{ &vop_lock_desc,		(vop_t *) dead_lock },
71	{ &vop_lookup_desc,		(vop_t *) dead_lookup },
72	{ &vop_mkdir_desc,		(vop_t *) dead_badop },
73	{ &vop_mknod_desc,		(vop_t *) dead_badop },
74	{ &vop_mmap_desc,		(vop_t *) dead_badop },
75	{ &vop_open_desc,		(vop_t *) dead_open },
76	{ &vop_pathconf_desc,		(vop_t *) vop_ebadf },	/* per pathconf(2) */
77	{ &vop_poll_desc,		(vop_t *) dead_poll },
78	{ &vop_print_desc,		(vop_t *) dead_print },
79	{ &vop_read_desc,		(vop_t *) dead_read },
80	{ &vop_readdir_desc,		(vop_t *) vop_ebadf },
81	{ &vop_readlink_desc,		(vop_t *) vop_ebadf },
82	{ &vop_reclaim_desc,		(vop_t *) vop_null },
83	{ &vop_remove_desc,		(vop_t *) dead_badop },
84	{ &vop_rename_desc,		(vop_t *) dead_badop },
85	{ &vop_rmdir_desc,		(vop_t *) dead_badop },
86	{ &vop_setattr_desc,		(vop_t *) vop_ebadf },
87	{ &vop_symlink_desc,		(vop_t *) dead_badop },
88	{ &vop_write_desc,		(vop_t *) dead_write },
89	{ NULL, NULL }
90};
91static struct vnodeopv_desc dead_vnodeop_opv_desc =
92	{ &dead_vnodeop_p, dead_vnodeop_entries };
93
94VNODEOP_SET(dead_vnodeop_opv_desc);
95
96/*
97 * Trivial lookup routine that always fails.
98 */
99/* ARGSUSED */
100static int
101dead_lookup(ap)
102	struct vop_lookup_args /* {
103		struct vnode * a_dvp;
104		struct vnode ** a_vpp;
105		struct componentname * a_cnp;
106	} */ *ap;
107{
108
109	*ap->a_vpp = NULL;
110	return (ENOTDIR);
111}
112
113/*
114 * Open always fails as if device did not exist.
115 */
116/* ARGSUSED */
117static int
118dead_open(ap)
119	struct vop_open_args /* {
120		struct vnode *a_vp;
121		int  a_mode;
122		struct ucred *a_cred;
123		struct proc *a_p;
124	} */ *ap;
125{
126
127	return (ENXIO);
128}
129
130/*
131 * Vnode op for read
132 */
133/* ARGSUSED */
134static int
135dead_read(ap)
136	struct vop_read_args /* {
137		struct vnode *a_vp;
138		struct uio *a_uio;
139		int  a_ioflag;
140		struct ucred *a_cred;
141	} */ *ap;
142{
143
144	if (chkvnlock(ap->a_vp))
145		panic("dead_read: lock");
146	/*
147	 * Return EOF for tty devices, EIO for others
148	 */
149	if ((ap->a_vp->v_flag & VISTTY) == 0)
150		return (EIO);
151	return (0);
152}
153
154/*
155 * Vnode op for write
156 */
157/* ARGSUSED */
158static int
159dead_write(ap)
160	struct vop_write_args /* {
161		struct vnode *a_vp;
162		struct uio *a_uio;
163		int  a_ioflag;
164		struct ucred *a_cred;
165	} */ *ap;
166{
167
168	if (chkvnlock(ap->a_vp))
169		panic("dead_write: lock");
170	return (EIO);
171}
172
173/*
174 * Device ioctl operation.
175 */
176/* ARGSUSED */
177static int
178dead_ioctl(ap)
179	struct vop_ioctl_args /* {
180		struct vnode *a_vp;
181		int  a_command;
182		caddr_t  a_data;
183		int  a_fflag;
184		struct ucred *a_cred;
185		struct proc *a_p;
186	} */ *ap;
187{
188
189	if (!chkvnlock(ap->a_vp))
190		return (ENOTTY);
191	return (VCALL(ap->a_vp, VOFFSET(vop_ioctl), ap));
192}
193
194
195/*
196 * Wait until the vnode has finished changing state.
197 */
198static int
199dead_lock(ap)
200	struct vop_lock_args /* {
201		struct vnode *a_vp;
202		int a_flags;
203		struct proc *a_p;
204	} */ *ap;
205{
206	struct vnode *vp = ap->a_vp;
207
208	/*
209	 * Since we are not using the lock manager, we must clear
210	 * the interlock here.
211	 */
212	if (ap->a_flags & LK_INTERLOCK) {
213		simple_unlock(&vp->v_interlock);
214		ap->a_flags &= ~LK_INTERLOCK;
215	}
216	if (!chkvnlock(vp))
217		return (0);
218	return (VCALL(vp, VOFFSET(vop_lock), ap));
219}
220
221/*
222 * Wait until the vnode has finished changing state.
223 */
224static int
225dead_bmap(ap)
226	struct vop_bmap_args /* {
227		struct vnode *a_vp;
228		daddr_t  a_bn;
229		struct vnode **a_vpp;
230		daddr_t *a_bnp;
231		int *a_runp;
232		int *a_runb;
233	} */ *ap;
234{
235
236	if (!chkvnlock(ap->a_vp))
237		return (EIO);
238	return (VOP_BMAP(ap->a_vp, ap->a_bn, ap->a_vpp, ap->a_bnp, ap->a_runp, ap->a_runb));
239}
240
241/*
242 * Print out the contents of a dead vnode.
243 */
244/* ARGSUSED */
245static int
246dead_print(ap)
247	struct vop_print_args /* {
248		struct vnode *a_vp;
249	} */ *ap;
250{
251
252	printf("tag VT_NON, dead vnode\n");
253	return (0);
254}
255
256/*
257 * Empty vnode bad operation
258 */
259static int
260dead_badop()
261{
262
263	panic("dead_badop called");
264	/* NOTREACHED */
265}
266
267/*
268 * We have to wait during times when the vnode is
269 * in a state of change.
270 */
271int
272chkvnlock(vp)
273	register struct vnode *vp;
274{
275	int locked = 0;
276
277	while (vp->v_flag & VXLOCK) {
278		vp->v_flag |= VXWANT;
279		(void) tsleep((caddr_t)vp, PINOD, "ckvnlk", 0);
280		locked = 1;
281	}
282	return (locked);
283}
284
285/*
286 * Trivial poll routine that always returns POLLHUP.
287 * This is necessary so that a process which is polling a file
288 * gets notified when that file is revoke()d.
289 */
290static int
291dead_poll(ap)
292	struct vop_poll_args *ap;
293{
294	return (POLLHUP);
295}
296