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