genfs_vnops.c revision 1.18.2.1 1 /* $NetBSD: genfs_vnops.c,v 1.18.2.1 2000/12/14 23:36:08 he Exp $ */
2
3 /*
4 * Copyright (c) 1982, 1986, 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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 */
36
37 #include "opt_nfsserver.h"
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/proc.h>
42 #include <sys/kernel.h>
43 #include <sys/mount.h>
44 #include <sys/namei.h>
45 #include <sys/vnode.h>
46 #include <sys/fcntl.h>
47 #include <sys/malloc.h>
48 #include <sys/poll.h>
49
50 #include <miscfs/genfs/genfs.h>
51 #include <miscfs/specfs/specdev.h>
52
53 #ifdef NFSSERVER
54 #include <nfs/rpcv2.h>
55 #include <nfs/nfsproto.h>
56 #include <nfs/nfs.h>
57 #include <nfs/nqnfs.h>
58 #include <nfs/nfs_var.h>
59 #endif
60
61 int
62 genfs_poll(v)
63 void *v;
64 {
65 struct vop_poll_args /* {
66 struct vnode *a_vp;
67 int a_events;
68 struct proc *a_p;
69 } */ *ap = v;
70
71 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
72 }
73
74 int
75 genfs_fsync(v)
76 void *v;
77 {
78 struct vop_fsync_args /* {
79 struct vnode *a_vp;
80 struct ucred *a_cred;
81 int a_flags;
82 off_t offlo;
83 off_t offhi;
84 struct proc *a_p;
85 } */ *ap = v;
86 struct vnode *vp = ap->a_vp;
87 int wait;
88
89 wait = (ap->a_flags & FSYNC_WAIT) != 0;
90 vflushbuf(vp, wait);
91 if ((ap->a_flags & FSYNC_DATAONLY) != 0)
92 return (0);
93 else
94 return (VOP_UPDATE(vp, NULL, NULL, wait ? UPDATE_WAIT : 0));
95 }
96
97 int
98 genfs_seek(v)
99 void *v;
100 {
101 struct vop_seek_args /* {
102 struct vnode *a_vp;
103 off_t a_oldoff;
104 off_t a_newoff;
105 struct ucred *a_ucred;
106 } */ *ap = v;
107
108 if (ap->a_newoff < 0)
109 return (EINVAL);
110
111 return (0);
112 }
113
114 int
115 genfs_abortop(v)
116 void *v;
117 {
118 struct vop_abortop_args /* {
119 struct vnode *a_dvp;
120 struct componentname *a_cnp;
121 } */ *ap = v;
122
123 if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
124 FREE(ap->a_cnp->cn_pnbuf, M_NAMEI);
125 return (0);
126 }
127
128 int
129 genfs_fcntl(v)
130 void *v;
131 {
132 struct vop_fcntl_args /* {
133 struct vnode *a_vp;
134 u_int a_command;
135 caddr_t a_data;
136 int a_fflag;
137 struct ucred *a_cred;
138 struct proc *a_p;
139 } */ *ap = v;
140
141 if (ap->a_command == F_SETFL)
142 return (0);
143 else
144 return (EOPNOTSUPP);
145 }
146
147 /*ARGSUSED*/
148 int
149 genfs_badop(v)
150 void *v;
151 {
152
153 panic("genfs: bad op");
154 }
155
156 /*ARGSUSED*/
157 int
158 genfs_nullop(v)
159 void *v;
160 {
161
162 return (0);
163 }
164
165 /*ARGSUSED*/
166 int
167 genfs_einval(v)
168 void *v;
169 {
170
171 return (EINVAL);
172 }
173
174 /*ARGSUSED*/
175 int
176 genfs_eopnotsupp(v)
177 void *v;
178 {
179
180 return (EOPNOTSUPP);
181 }
182
183 /*
184 * Called when an fs doesn't support a particular vop but the vop needs to
185 * vrele, vput, or vunlock passed in vnodes.
186 */
187 int
188 genfs_eopnotsupp_rele(v)
189 void *v;
190 {
191 struct vop_generic_args /*
192 struct vnodeop_desc *a_desc;
193 / * other random data follows, presumably * /
194 } */ *ap = v;
195 struct vnodeop_desc *desc = ap->a_desc;
196 struct vnode *vp;
197 int flags, i, j, offset;
198
199 flags = desc->vdesc_flags;
200 for (i = 0; i < VDESC_MAX_VPS; flags >>=1, i++) {
201 if ((offset = desc->vdesc_vp_offsets[i]) == VDESC_NO_OFFSET)
202 break; /* stop at end of list */
203 if ((j = flags & VDESC_VP0_WILLPUT)) {
204 vp = *VOPARG_OFFSETTO(struct vnode**,offset,ap);
205 switch (j) {
206 case VDESC_VP0_WILLPUT:
207 vput(vp);
208 break;
209 case VDESC_VP0_WILLUNLOCK:
210 VOP_UNLOCK(vp, 0);
211 break;
212 case VDESC_VP0_WILLRELE:
213 vrele(vp);
214 break;
215 }
216 }
217 }
218
219 return (EOPNOTSUPP);
220 }
221
222 /*ARGSUSED*/
223 int
224 genfs_ebadf(v)
225 void *v;
226 {
227
228 return (EBADF);
229 }
230
231 /* ARGSUSED */
232 int
233 genfs_enoioctl(v)
234 void *v;
235 {
236
237 return (ENOTTY);
238 }
239
240
241 /*
242 * Eliminate all activity associated with the requested vnode
243 * and with all vnodes aliased to the requested vnode.
244 */
245 int
246 genfs_revoke(v)
247 void *v;
248 {
249 struct vop_revoke_args /* {
250 struct vnode *a_vp;
251 int a_flags;
252 } */ *ap = v;
253 struct vnode *vp, *vq;
254 struct proc *p = curproc; /* XXX */
255
256 #ifdef DIAGNOSTIC
257 if ((ap->a_flags & REVOKEALL) == 0)
258 panic("genfs_revoke: not revokeall");
259 #endif
260
261 vp = ap->a_vp;
262 simple_lock(&vp->v_interlock);
263
264 if (vp->v_flag & VALIASED) {
265 /*
266 * If a vgone (or vclean) is already in progress,
267 * wait until it is done and return.
268 */
269 if (vp->v_flag & VXLOCK) {
270 vp->v_flag |= VXWANT;
271 simple_unlock(&vp->v_interlock);
272 tsleep((caddr_t)vp, PINOD, "vop_revokeall", 0);
273 return (0);
274 }
275 /*
276 * Ensure that vp will not be vgone'd while we
277 * are eliminating its aliases.
278 */
279 vp->v_flag |= VXLOCK;
280 simple_unlock(&vp->v_interlock);
281 while (vp->v_flag & VALIASED) {
282 simple_lock(&spechash_slock);
283 for (vq = *vp->v_hashchain; vq; vq = vq->v_specnext) {
284 if (vq->v_rdev != vp->v_rdev ||
285 vq->v_type != vp->v_type || vp == vq)
286 continue;
287 simple_unlock(&spechash_slock);
288 vgone(vq);
289 break;
290 }
291 if (vq == NULLVP)
292 simple_unlock(&spechash_slock);
293 }
294 /*
295 * Remove the lock so that vgone below will
296 * really eliminate the vnode after which time
297 * vgone will awaken any sleepers.
298 */
299 simple_lock(&vp->v_interlock);
300 vp->v_flag &= ~VXLOCK;
301 }
302 vgonel(vp, p);
303 return (0);
304 }
305
306 /*
307 * Lock the node.
308 */
309 int
310 genfs_lock(v)
311 void *v;
312 {
313 struct vop_lock_args /* {
314 struct vnode *a_vp;
315 int a_flags;
316 } */ *ap = v;
317 struct vnode *vp = ap->a_vp;
318
319 return (lockmgr(&vp->v_lock, ap->a_flags, &vp->v_interlock));
320 }
321
322 /*
323 * Unlock the node.
324 */
325 int
326 genfs_unlock(v)
327 void *v;
328 {
329 struct vop_unlock_args /* {
330 struct vnode *a_vp;
331 int a_flags;
332 } */ *ap = v;
333 struct vnode *vp = ap->a_vp;
334
335 return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE,
336 &vp->v_interlock));
337 }
338
339 /*
340 * Return whether or not the node is locked.
341 */
342 int
343 genfs_islocked(v)
344 void *v;
345 {
346 struct vop_islocked_args /* {
347 struct vnode *a_vp;
348 } */ *ap = v;
349 struct vnode *vp = ap->a_vp;
350
351 return (lockstatus(&vp->v_lock));
352 }
353
354 /*
355 * Stubs to use when there is no locking to be done on the underlying object.
356 */
357 int
358 genfs_nolock(v)
359 void *v;
360 {
361 struct vop_lock_args /* {
362 struct vnode *a_vp;
363 int a_flags;
364 struct proc *a_p;
365 } */ *ap = v;
366
367 /*
368 * Since we are not using the lock manager, we must clear
369 * the interlock here.
370 */
371 if (ap->a_flags & LK_INTERLOCK)
372 simple_unlock(&ap->a_vp->v_interlock);
373 return (0);
374 }
375
376 int
377 genfs_nounlock(v)
378 void *v;
379 {
380 return (0);
381 }
382
383 int
384 genfs_noislocked(v)
385 void *v;
386 {
387 return (0);
388 }
389
390 /*
391 * Local lease check for NFS servers. Just set up args and let
392 * nqsrv_getlease() do the rest. If NFSSERVER is not in the kernel,
393 * this is a null operation.
394 */
395 int
396 genfs_lease_check(v)
397 void *v;
398 {
399 #ifdef NFSSERVER
400 struct vop_lease_args /* {
401 struct vnode *a_vp;
402 struct proc *a_p;
403 struct ucred *a_cred;
404 int a_flag;
405 } */ *ap = v;
406 u_int32_t duration = 0;
407 int cache;
408 u_quad_t frev;
409
410 (void) nqsrv_getlease(ap->a_vp, &duration, ND_CHECK | ap->a_flag,
411 NQLOCALSLP, ap->a_p, (struct mbuf *)0, &cache, &frev, ap->a_cred);
412 return (0);
413 #else
414 return (0);
415 #endif /* NFSSERVER */
416 }
417