genfs_vnops.c revision 1.12 1 1.12 wrstuden /* $NetBSD: genfs_vnops.c,v 1.12 1999/07/08 01:18:59 wrstuden 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.1 mycroft #include <sys/malloc.h>
47 1.3 mycroft #include <sys/poll.h>
48 1.1 mycroft
49 1.1 mycroft #include <miscfs/genfs/genfs.h>
50 1.6 fvdl #include <miscfs/specfs/specdev.h>
51 1.1 mycroft
52 1.8 thorpej #ifdef NFSSERVER
53 1.8 thorpej #include <nfs/rpcv2.h>
54 1.8 thorpej #include <nfs/nfsproto.h>
55 1.8 thorpej #include <nfs/nfs.h>
56 1.8 thorpej #include <nfs/nqnfs.h>
57 1.8 thorpej #include <nfs/nfs_var.h>
58 1.8 thorpej #endif
59 1.8 thorpej
60 1.1 mycroft int
61 1.3 mycroft genfs_poll(v)
62 1.1 mycroft void *v;
63 1.1 mycroft {
64 1.3 mycroft struct vop_poll_args /* {
65 1.1 mycroft struct vnode *a_vp;
66 1.3 mycroft int a_events;
67 1.1 mycroft struct proc *a_p;
68 1.1 mycroft } */ *ap = v;
69 1.1 mycroft
70 1.3 mycroft return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
71 1.1 mycroft }
72 1.1 mycroft
73 1.1 mycroft int
74 1.1 mycroft genfs_fsync(v)
75 1.1 mycroft void *v;
76 1.1 mycroft {
77 1.1 mycroft struct vop_fsync_args /* {
78 1.1 mycroft struct vnode *a_vp;
79 1.1 mycroft struct ucred *a_cred;
80 1.7 kleink int a_flags;
81 1.1 mycroft struct proc *a_p;
82 1.1 mycroft } */ *ap = v;
83 1.1 mycroft register struct vnode *vp = ap->a_vp;
84 1.11 mycroft int wait;
85 1.1 mycroft
86 1.11 mycroft wait = (ap->a_flags & FSYNC_WAIT) != 0;
87 1.11 mycroft vflushbuf(vp, wait);
88 1.11 mycroft if ((ap->a_flags & FSYNC_DATAONLY) != 0)
89 1.7 kleink return (0);
90 1.11 mycroft else
91 1.11 mycroft return (VOP_UPDATE(ap->a_vp, NULL, NULL, wait));
92 1.1 mycroft }
93 1.1 mycroft
94 1.1 mycroft int
95 1.4 kleink genfs_seek(v)
96 1.4 kleink void *v;
97 1.4 kleink {
98 1.4 kleink struct vop_seek_args /* {
99 1.4 kleink struct vnode *a_vp;
100 1.4 kleink off_t a_oldoff;
101 1.4 kleink off_t a_newoff;
102 1.4 kleink struct ucred *a_ucred;
103 1.4 kleink } */ *ap = v;
104 1.4 kleink
105 1.4 kleink if (ap->a_newoff < 0)
106 1.4 kleink return (EINVAL);
107 1.4 kleink
108 1.4 kleink return (0);
109 1.4 kleink }
110 1.4 kleink
111 1.4 kleink int
112 1.1 mycroft genfs_abortop(v)
113 1.1 mycroft void *v;
114 1.1 mycroft {
115 1.1 mycroft struct vop_abortop_args /* {
116 1.1 mycroft struct vnode *a_dvp;
117 1.1 mycroft struct componentname *a_cnp;
118 1.1 mycroft } */ *ap = v;
119 1.1 mycroft
120 1.1 mycroft if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
121 1.1 mycroft FREE(ap->a_cnp->cn_pnbuf, M_NAMEI);
122 1.1 mycroft return (0);
123 1.1 mycroft }
124 1.1 mycroft
125 1.1 mycroft /*ARGSUSED*/
126 1.1 mycroft int
127 1.1 mycroft genfs_badop(v)
128 1.1 mycroft void *v;
129 1.1 mycroft {
130 1.1 mycroft
131 1.1 mycroft panic("genfs: bad op");
132 1.1 mycroft }
133 1.1 mycroft
134 1.1 mycroft /*ARGSUSED*/
135 1.1 mycroft int
136 1.1 mycroft genfs_nullop(v)
137 1.1 mycroft void *v;
138 1.1 mycroft {
139 1.1 mycroft
140 1.1 mycroft return (0);
141 1.10 kleink }
142 1.10 kleink
143 1.10 kleink /*ARGSUSED*/
144 1.10 kleink int
145 1.10 kleink genfs_einval(v)
146 1.10 kleink void *v;
147 1.10 kleink {
148 1.10 kleink
149 1.10 kleink return (EINVAL);
150 1.1 mycroft }
151 1.1 mycroft
152 1.1 mycroft /*ARGSUSED*/
153 1.1 mycroft int
154 1.1 mycroft genfs_eopnotsupp(v)
155 1.1 mycroft void *v;
156 1.1 mycroft {
157 1.1 mycroft
158 1.1 mycroft return (EOPNOTSUPP);
159 1.1 mycroft }
160 1.1 mycroft
161 1.12 wrstuden /*
162 1.12 wrstuden * Called when an fs doesn't support a particular vop but the vop needs to
163 1.12 wrstuden * vrele, vput, or vunlock passed in vnodes.
164 1.12 wrstuden */
165 1.12 wrstuden int
166 1.12 wrstuden genfs_eopnotsupp_rele(v)
167 1.12 wrstuden void *v;
168 1.12 wrstuden {
169 1.12 wrstuden struct vop_generic_args /*
170 1.12 wrstuden struct vnodeop_desc *a_desc;
171 1.12 wrstuden / * other random data follows, presumably * /
172 1.12 wrstuden } */ *ap = v;
173 1.12 wrstuden struct vnodeop_desc *desc = ap->a_desc;
174 1.12 wrstuden struct vnode *vp;
175 1.12 wrstuden int flags, i, j, offset;
176 1.12 wrstuden
177 1.12 wrstuden flags = desc->vdesc_flags;
178 1.12 wrstuden for (i = 0; i < VDESC_MAX_VPS; flags >>=1, i++) {
179 1.12 wrstuden if ((offset = desc->vdesc_vp_offsets[i]) == VDESC_NO_OFFSET)
180 1.12 wrstuden break; /* stop at end of list */
181 1.12 wrstuden if ((j = flags & VDESC_VP0_WILLPUT)) {
182 1.12 wrstuden vp = *VOPARG_OFFSETTO(struct vnode**,offset,ap);
183 1.12 wrstuden switch (j) {
184 1.12 wrstuden case VDESC_VP0_WILLPUT:
185 1.12 wrstuden vput(vp);
186 1.12 wrstuden break;
187 1.12 wrstuden case VDESC_VP0_WILLUNLOCK:
188 1.12 wrstuden VOP_UNLOCK(vp, 0);
189 1.12 wrstuden break;
190 1.12 wrstuden case VDESC_VP0_WILLRELE:
191 1.12 wrstuden vrele(vp);
192 1.12 wrstuden break;
193 1.12 wrstuden }
194 1.12 wrstuden }
195 1.12 wrstuden }
196 1.12 wrstuden
197 1.12 wrstuden return (EOPNOTSUPP);
198 1.12 wrstuden }
199 1.12 wrstuden
200 1.1 mycroft /*ARGSUSED*/
201 1.1 mycroft int
202 1.1 mycroft genfs_ebadf(v)
203 1.1 mycroft void *v;
204 1.1 mycroft {
205 1.1 mycroft
206 1.1 mycroft return (EBADF);
207 1.9 matthias }
208 1.9 matthias
209 1.9 matthias /* ARGSUSED */
210 1.9 matthias int
211 1.9 matthias genfs_enoioctl(v)
212 1.9 matthias void *v;
213 1.9 matthias {
214 1.9 matthias
215 1.9 matthias return (ENOTTY);
216 1.6 fvdl }
217 1.6 fvdl
218 1.6 fvdl
219 1.6 fvdl /*
220 1.6 fvdl * Eliminate all activity associated with the requested vnode
221 1.6 fvdl * and with all vnodes aliased to the requested vnode.
222 1.6 fvdl */
223 1.6 fvdl int
224 1.6 fvdl genfs_revoke(v)
225 1.6 fvdl void *v;
226 1.6 fvdl {
227 1.6 fvdl struct vop_revoke_args /* {
228 1.6 fvdl struct vnode *a_vp;
229 1.6 fvdl int a_flags;
230 1.6 fvdl } */ *ap = v;
231 1.6 fvdl struct vnode *vp, *vq;
232 1.6 fvdl struct proc *p = curproc; /* XXX */
233 1.6 fvdl
234 1.6 fvdl #ifdef DIAGNOSTIC
235 1.6 fvdl if ((ap->a_flags & REVOKEALL) == 0)
236 1.6 fvdl panic("genfs_revoke: not revokeall");
237 1.6 fvdl #endif
238 1.6 fvdl
239 1.6 fvdl vp = ap->a_vp;
240 1.6 fvdl simple_lock(&vp->v_interlock);
241 1.6 fvdl
242 1.6 fvdl if (vp->v_flag & VALIASED) {
243 1.6 fvdl /*
244 1.6 fvdl * If a vgone (or vclean) is already in progress,
245 1.6 fvdl * wait until it is done and return.
246 1.6 fvdl */
247 1.6 fvdl if (vp->v_flag & VXLOCK) {
248 1.6 fvdl vp->v_flag |= VXWANT;
249 1.6 fvdl simple_unlock(&vp->v_interlock);
250 1.6 fvdl tsleep((caddr_t)vp, PINOD, "vop_revokeall", 0);
251 1.6 fvdl return (0);
252 1.6 fvdl }
253 1.6 fvdl /*
254 1.6 fvdl * Ensure that vp will not be vgone'd while we
255 1.6 fvdl * are eliminating its aliases.
256 1.6 fvdl */
257 1.6 fvdl vp->v_flag |= VXLOCK;
258 1.6 fvdl simple_unlock(&vp->v_interlock);
259 1.6 fvdl while (vp->v_flag & VALIASED) {
260 1.6 fvdl simple_lock(&spechash_slock);
261 1.6 fvdl for (vq = *vp->v_hashchain; vq; vq = vq->v_specnext) {
262 1.6 fvdl if (vq->v_rdev != vp->v_rdev ||
263 1.6 fvdl vq->v_type != vp->v_type || vp == vq)
264 1.6 fvdl continue;
265 1.6 fvdl simple_unlock(&spechash_slock);
266 1.6 fvdl vgone(vq);
267 1.6 fvdl break;
268 1.6 fvdl }
269 1.6 fvdl if (vq == NULLVP)
270 1.6 fvdl simple_unlock(&spechash_slock);
271 1.6 fvdl }
272 1.6 fvdl /*
273 1.6 fvdl * Remove the lock so that vgone below will
274 1.6 fvdl * really eliminate the vnode after which time
275 1.6 fvdl * vgone will awaken any sleepers.
276 1.6 fvdl */
277 1.6 fvdl simple_lock(&vp->v_interlock);
278 1.6 fvdl vp->v_flag &= ~VXLOCK;
279 1.6 fvdl }
280 1.6 fvdl vgonel(vp, p);
281 1.6 fvdl return (0);
282 1.6 fvdl }
283 1.6 fvdl
284 1.6 fvdl /*
285 1.12 wrstuden * Lock the node.
286 1.6 fvdl */
287 1.6 fvdl int
288 1.12 wrstuden genfs_lock(v)
289 1.6 fvdl void *v;
290 1.6 fvdl {
291 1.6 fvdl struct vop_lock_args /* {
292 1.6 fvdl struct vnode *a_vp;
293 1.6 fvdl int a_flags;
294 1.6 fvdl struct proc *a_p;
295 1.6 fvdl } */ *ap = v;
296 1.6 fvdl struct vnode *vp = ap->a_vp;
297 1.6 fvdl
298 1.12 wrstuden return (lockmgr(&vp->v_lock, ap->a_flags, &vp->v_interlock));
299 1.6 fvdl }
300 1.6 fvdl
301 1.6 fvdl /*
302 1.12 wrstuden * Unlock the node.
303 1.6 fvdl */
304 1.6 fvdl int
305 1.12 wrstuden genfs_unlock(v)
306 1.6 fvdl void *v;
307 1.6 fvdl {
308 1.6 fvdl struct vop_unlock_args /* {
309 1.6 fvdl struct vnode *a_vp;
310 1.6 fvdl int a_flags;
311 1.6 fvdl struct proc *a_p;
312 1.6 fvdl } */ *ap = v;
313 1.6 fvdl struct vnode *vp = ap->a_vp;
314 1.6 fvdl
315 1.12 wrstuden return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE,
316 1.12 wrstuden &vp->v_interlock));
317 1.6 fvdl }
318 1.6 fvdl
319 1.6 fvdl /*
320 1.12 wrstuden * Return whether or not the node is locked.
321 1.6 fvdl */
322 1.6 fvdl int
323 1.12 wrstuden genfs_islocked(v)
324 1.6 fvdl void *v;
325 1.6 fvdl {
326 1.6 fvdl struct vop_islocked_args /* {
327 1.6 fvdl struct vnode *a_vp;
328 1.6 fvdl } */ *ap = v;
329 1.6 fvdl struct vnode *vp = ap->a_vp;
330 1.6 fvdl
331 1.12 wrstuden return (lockstatus(&vp->v_lock));
332 1.12 wrstuden }
333 1.12 wrstuden
334 1.12 wrstuden /*
335 1.12 wrstuden * Stubs to use when there is no locking to be done on the underlying object.
336 1.12 wrstuden */
337 1.12 wrstuden int
338 1.12 wrstuden genfs_nolock(v)
339 1.12 wrstuden void *v;
340 1.12 wrstuden {
341 1.12 wrstuden struct vop_lock_args /* {
342 1.12 wrstuden struct vnode *a_vp;
343 1.12 wrstuden int a_flags;
344 1.12 wrstuden struct proc *a_p;
345 1.12 wrstuden } */ *ap = v;
346 1.12 wrstuden
347 1.12 wrstuden /*
348 1.12 wrstuden * Since we are not using the lock manager, we must clear
349 1.12 wrstuden * the interlock here.
350 1.12 wrstuden */
351 1.12 wrstuden if (ap->a_flags & LK_INTERLOCK)
352 1.12 wrstuden simple_unlock(&ap->a_vp->v_interlock);
353 1.12 wrstuden return (0);
354 1.12 wrstuden }
355 1.12 wrstuden
356 1.12 wrstuden int
357 1.12 wrstuden genfs_nounlock(v)
358 1.12 wrstuden void *v;
359 1.12 wrstuden {
360 1.12 wrstuden return (0);
361 1.12 wrstuden }
362 1.12 wrstuden
363 1.12 wrstuden int
364 1.12 wrstuden genfs_noislocked(v)
365 1.12 wrstuden void *v;
366 1.12 wrstuden {
367 1.12 wrstuden return (0);
368 1.8 thorpej }
369 1.8 thorpej
370 1.8 thorpej /*
371 1.8 thorpej * Local lease check for NFS servers. Just set up args and let
372 1.8 thorpej * nqsrv_getlease() do the rest. If NFSSERVER is not in the kernel,
373 1.8 thorpej * this is a null operation.
374 1.8 thorpej */
375 1.8 thorpej int
376 1.8 thorpej genfs_lease_check(v)
377 1.8 thorpej void *v;
378 1.8 thorpej {
379 1.8 thorpej #ifdef NFSSERVER
380 1.8 thorpej struct vop_lease_args /* {
381 1.8 thorpej struct vnode *a_vp;
382 1.8 thorpej struct proc *a_p;
383 1.8 thorpej struct ucred *a_cred;
384 1.8 thorpej int a_flag;
385 1.8 thorpej } */ *ap = v;
386 1.8 thorpej u_int32_t duration = 0;
387 1.8 thorpej int cache;
388 1.8 thorpej u_quad_t frev;
389 1.8 thorpej
390 1.8 thorpej (void) nqsrv_getlease(ap->a_vp, &duration, ND_CHECK | ap->a_flag,
391 1.8 thorpej NQLOCALSLP, ap->a_p, (struct mbuf *)0, &cache, &frev, ap->a_cred);
392 1.8 thorpej return (0);
393 1.8 thorpej #else
394 1.8 thorpej return (0);
395 1.8 thorpej #endif /* NFSSERVER */
396 1.1 mycroft }
397