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