]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ | |
26 | /* | |
27 | * Copyright (c) 1992, 1993 | |
28 | * The Regents of the University of California. All rights reserved. | |
29 | * | |
30 | * This code is derived from software contributed to Berkeley by | |
31 | * John Heidemann of the UCLA Ficus project. | |
32 | * | |
33 | * Redistribution and use in source and binary forms, with or without | |
34 | * modification, are permitted provided that the following conditions | |
35 | * are met: | |
36 | * 1. Redistributions of source code must retain the above copyright | |
37 | * notice, this list of conditions and the following disclaimer. | |
38 | * 2. Redistributions in binary form must reproduce the above copyright | |
39 | * notice, this list of conditions and the following disclaimer in the | |
40 | * documentation and/or other materials provided with the distribution. | |
41 | * 3. All advertising materials mentioning features or use of this software | |
42 | * must display the following acknowledgement: | |
43 | * This product includes software developed by the University of | |
44 | * California, Berkeley and its contributors. | |
45 | * 4. Neither the name of the University nor the names of its contributors | |
46 | * may be used to endorse or promote products derived from this software | |
47 | * without specific prior written permission. | |
48 | * | |
49 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
50 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
51 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
59 | * SUCH DAMAGE. | |
60 | * | |
61 | * @(#)null_vnops.c 8.6 (Berkeley) 5/27/95 | |
62 | * | |
63 | * Ancestors: | |
64 | * @(#)lofs_vnops.c 1.2 (Berkeley) 6/18/92 | |
65 | * ...and... | |
66 | * @(#)null_vnodeops.c 1.20 92/07/07 UCLA Ficus project | |
67 | */ | |
68 | ||
69 | /* | |
70 | * Null Layer | |
71 | * | |
72 | * (See mount_null(8) for more information.) | |
73 | * | |
74 | * The null layer duplicates a portion of the file system | |
75 | * name space under a new name. In this respect, it is | |
76 | * similar to the loopback file system. It differs from | |
77 | * the loopback fs in two respects: it is implemented using | |
78 | * a stackable layers techniques, and it's "null-node"s stack above | |
79 | * all lower-layer vnodes, not just over directory vnodes. | |
80 | * | |
81 | * The null layer has two purposes. First, it serves as a demonstration | |
82 | * of layering by proving a layer which does nothing. (It actually | |
83 | * does everything the loopback file system does, which is slightly | |
84 | * more than nothing.) Second, the null layer can serve as a prototype | |
85 | * layer. Since it provides all necessary layer framework, | |
86 | * new file system layers can be created very easily be starting | |
87 | * with a null layer. | |
88 | * | |
89 | * The remainder of this man page examines the null layer as a basis | |
90 | * for constructing new layers. | |
91 | * | |
92 | * | |
93 | * INSTANTIATING NEW NULL LAYERS | |
94 | * | |
95 | * New null layers are created with mount_null(8). | |
96 | * Mount_null(8) takes two arguments, the pathname | |
97 | * of the lower vfs (target-pn) and the pathname where the null | |
98 | * layer will appear in the namespace (alias-pn). After | |
99 | * the null layer is put into place, the contents | |
100 | * of target-pn subtree will be aliased under alias-pn. | |
101 | * | |
102 | * | |
103 | * OPERATION OF A NULL LAYER | |
104 | * | |
105 | * The null layer is the minimum file system layer, | |
106 | * simply bypassing all possible operations to the lower layer | |
107 | * for processing there. The majority of its activity centers | |
108 | * on the bypass routine, though which nearly all vnode operations | |
109 | * pass. | |
110 | * | |
111 | * The bypass routine accepts arbitrary vnode operations for | |
112 | * handling by the lower layer. It begins by examing vnode | |
113 | * operation arguments and replacing any null-nodes by their | |
114 | * lower-layer equivlants. It then invokes the operation | |
115 | * on the lower layer. Finally, it replaces the null-nodes | |
116 | * in the arguments and, if a vnode is return by the operation, | |
117 | * stacks a null-node on top of the returned vnode. | |
118 | * | |
119 | * Although bypass handles most operations, vop_getattr, vop_lock, | |
120 | * vop_unlock, vop_inactive, vop_reclaim, and vop_print are not | |
121 | * bypassed. Vop_getattr must change the fsid being returned. | |
122 | * Vop_lock and vop_unlock must handle any locking for the | |
123 | * current vnode as well as pass the lock request down. | |
124 | * Vop_inactive and vop_reclaim are not bypassed so that | |
125 | * they can handle freeing null-layer specific data. Vop_print | |
126 | * is not bypassed to avoid excessive debugging information. | |
127 | * Also, certain vnode operations change the locking state within | |
128 | * the operation (create, mknod, remove, link, rename, mkdir, rmdir, | |
129 | * and symlink). Ideally these operations should not change the | |
130 | * lock state, but should be changed to let the caller of the | |
131 | * function unlock them. Otherwise all intermediate vnode layers | |
132 | * (such as union, umapfs, etc) must catch these functions to do | |
133 | * the necessary locking at their layer. | |
134 | * | |
135 | * | |
136 | * INSTANTIATING VNODE STACKS | |
137 | * | |
138 | * Mounting associates the null layer with a lower layer, | |
139 | * effect stacking two VFSes. Vnode stacks are instead | |
140 | * created on demand as files are accessed. | |
141 | * | |
142 | * The initial mount creates a single vnode stack for the | |
143 | * root of the new null layer. All other vnode stacks | |
144 | * are created as a result of vnode operations on | |
145 | * this or other null vnode stacks. | |
146 | * | |
147 | * New vnode stacks come into existance as a result of | |
148 | * an operation which returns a vnode. | |
149 | * The bypass routine stacks a null-node above the new | |
150 | * vnode before returning it to the caller. | |
151 | * | |
152 | * For example, imagine mounting a null layer with | |
153 | * "mount_null /usr/include /dev/layer/null". | |
154 | * Changing directory to /dev/layer/null will assign | |
155 | * the root null-node (which was created when the null layer was mounted). | |
156 | * Now consider opening "sys". A vop_lookup would be | |
157 | * done on the root null-node. This operation would bypass through | |
158 | * to the lower layer which would return a vnode representing | |
159 | * the UFS "sys". Null_bypass then builds a null-node | |
160 | * aliasing the UFS "sys" and returns this to the caller. | |
161 | * Later operations on the null-node "sys" will repeat this | |
162 | * process when constructing other vnode stacks. | |
163 | * | |
164 | * | |
165 | * CREATING OTHER FILE SYSTEM LAYERS | |
166 | * | |
167 | * One of the easiest ways to construct new file system layers is to make | |
168 | * a copy of the null layer, rename all files and variables, and | |
169 | * then begin modifing the copy. Sed can be used to easily rename | |
170 | * all variables. | |
171 | * | |
172 | * The umap layer is an example of a layer descended from the | |
173 | * null layer. | |
174 | * | |
175 | * | |
176 | * INVOKING OPERATIONS ON LOWER LAYERS | |
177 | * | |
178 | * There are two techniques to invoke operations on a lower layer | |
179 | * when the operation cannot be completely bypassed. Each method | |
180 | * is appropriate in different situations. In both cases, | |
181 | * it is the responsibility of the aliasing layer to make | |
182 | * the operation arguments "correct" for the lower layer | |
183 | * by mapping an vnode arguments to the lower layer. | |
184 | * | |
185 | * The first approach is to call the aliasing layer's bypass routine. | |
186 | * This method is most suitable when you wish to invoke the operation | |
187 | * currently being hanldled on the lower layer. It has the advantage | |
188 | * that the bypass routine already must do argument mapping. | |
189 | * An example of this is null_getattrs in the null layer. | |
190 | * | |
191 | * A second approach is to directly invoked vnode operations on | |
192 | * the lower layer with the VOP_OPERATIONNAME interface. | |
193 | * The advantage of this method is that it is easy to invoke | |
194 | * arbitrary operations on the lower layer. The disadvantage | |
195 | * is that vnodes arguments must be manualy mapped. | |
196 | * | |
197 | */ | |
198 | ||
199 | #include <sys/param.h> | |
200 | #include <sys/systm.h> | |
201 | #include <sys/proc.h> | |
202 | #include <sys/time.h> | |
203 | #include <sys/types.h> | |
204 | #include <sys/vnode.h> | |
205 | #include <sys/mount.h> | |
206 | #include <sys/namei.h> | |
207 | #include <sys/malloc.h> | |
208 | #include <sys/buf.h> | |
209 | #include <miscfs/nullfs/null.h> | |
210 | ||
211 | ||
212 | int null_bug_bypass = 0; /* for debugging: enables bypass printf'ing */ | |
213 | ||
214 | /* | |
215 | * This is the 10-Apr-92 bypass routine. | |
216 | * This version has been optimized for speed, throwing away some | |
217 | * safety checks. It should still always work, but it's not as | |
218 | * robust to programmer errors. | |
219 | * Define SAFETY to include some error checking code. | |
220 | * | |
221 | * In general, we map all vnodes going down and unmap them on the way back. | |
222 | * As an exception to this, vnodes can be marked "unmapped" by setting | |
223 | * the Nth bit in operation's vdesc_flags. | |
224 | * | |
225 | * Also, some BSD vnode operations have the side effect of vrele'ing | |
226 | * their arguments. With stacking, the reference counts are held | |
227 | * by the upper node, not the lower one, so we must handle these | |
228 | * side-effects here. This is not of concern in Sun-derived systems | |
229 | * since there are no such side-effects. | |
230 | * | |
231 | * This makes the following assumptions: | |
232 | * - only one returned vpp | |
233 | * - no INOUT vpp's (Sun's vop_open has one of these) | |
234 | * - the vnode operation vector of the first vnode should be used | |
235 | * to determine what implementation of the op should be invoked | |
236 | * - all mapped vnodes are of our vnode-type (NEEDSWORK: | |
237 | * problems on rmdir'ing mount points and renaming?) | |
238 | */ | |
239 | int | |
240 | null_bypass(ap) | |
241 | struct vop_generic_args /* { | |
242 | struct vnodeop_desc *a_desc; | |
243 | <other random data follows, presumably> | |
244 | } */ *ap; | |
245 | { | |
246 | extern int (**null_vnodeop_p)(void *); /* not extern, really "forward" */ | |
247 | register struct vnode **this_vp_p; | |
248 | int error; | |
249 | struct vnode *old_vps[VDESC_MAX_VPS]; | |
250 | struct vnode **vps_p[VDESC_MAX_VPS]; | |
251 | struct vnode ***vppp; | |
252 | struct vnodeop_desc *descp = ap->a_desc; | |
253 | int reles, i; | |
254 | ||
255 | if (null_bug_bypass) | |
256 | printf ("null_bypass: %s\n", descp->vdesc_name); | |
257 | ||
258 | #ifdef SAFETY | |
259 | /* | |
260 | * We require at least one vp. | |
261 | */ | |
262 | if (descp->vdesc_vp_offsets == NULL || | |
263 | descp->vdesc_vp_offsets[0] == VDESC_NO_OFFSET) | |
264 | panic ("null_bypass: no vp's in map.\n"); | |
265 | #endif | |
266 | ||
267 | /* | |
268 | * Map the vnodes going in. | |
269 | * Later, we'll invoke the operation based on | |
270 | * the first mapped vnode's operation vector. | |
271 | */ | |
272 | reles = descp->vdesc_flags; | |
273 | for (i = 0; i < VDESC_MAX_VPS; reles >>= 1, i++) { | |
274 | if (descp->vdesc_vp_offsets[i] == VDESC_NO_OFFSET) | |
275 | break; /* bail out at end of list */ | |
276 | vps_p[i] = this_vp_p = | |
277 | VOPARG_OFFSETTO(struct vnode**,descp->vdesc_vp_offsets[i],ap); | |
278 | /* | |
279 | * We're not guaranteed that any but the first vnode | |
280 | * are of our type. Check for and don't map any | |
281 | * that aren't. (We must always map first vp or vclean fails.) | |
282 | */ | |
283 | if (i && (*this_vp_p == NULL || | |
284 | (*this_vp_p)->v_op != null_vnodeop_p)) { | |
285 | old_vps[i] = NULL; | |
286 | } else { | |
287 | old_vps[i] = *this_vp_p; | |
288 | *(vps_p[i]) = NULLVPTOLOWERVP(*this_vp_p); | |
289 | /* | |
290 | * XXX - Several operations have the side effect | |
291 | * of vrele'ing their vp's. We must account for | |
292 | * that. (This should go away in the future.) | |
293 | */ | |
294 | if (reles & 1) | |
295 | VREF(*this_vp_p); | |
296 | } | |
297 | ||
298 | } | |
299 | ||
300 | /* | |
301 | * Call the operation on the lower layer | |
302 | * with the modified argument structure. | |
303 | */ | |
304 | error = VCALL(*(vps_p[0]), descp->vdesc_offset, ap); | |
305 | ||
306 | /* | |
307 | * Maintain the illusion of call-by-value | |
308 | * by restoring vnodes in the argument structure | |
309 | * to their original value. | |
310 | */ | |
311 | reles = descp->vdesc_flags; | |
312 | for (i = 0; i < VDESC_MAX_VPS; reles >>= 1, i++) { | |
313 | if (descp->vdesc_vp_offsets[i] == VDESC_NO_OFFSET) | |
314 | break; /* bail out at end of list */ | |
315 | if (old_vps[i]) { | |
316 | *(vps_p[i]) = old_vps[i]; | |
317 | if (reles & 1) | |
318 | vrele(*(vps_p[i])); | |
319 | } | |
320 | } | |
321 | ||
322 | /* | |
323 | * Map the possible out-going vpp | |
324 | * (Assumes that the lower layer always returns | |
325 | * a VREF'ed vpp unless it gets an error.) | |
326 | */ | |
327 | if (descp->vdesc_vpp_offset != VDESC_NO_OFFSET && | |
328 | !(descp->vdesc_flags & VDESC_NOMAP_VPP) && | |
329 | !error) { | |
330 | /* | |
331 | * XXX - even though some ops have vpp returned vp's, | |
332 | * several ops actually vrele this before returning. | |
333 | * We must avoid these ops. | |
334 | * (This should go away when these ops are regularized.) | |
335 | */ | |
336 | if (descp->vdesc_flags & VDESC_VPP_WILLRELE) | |
337 | goto out; | |
338 | vppp = VOPARG_OFFSETTO(struct vnode***, | |
339 | descp->vdesc_vpp_offset,ap); | |
340 | error = null_node_create(old_vps[0]->v_mount, **vppp, *vppp); | |
341 | } | |
342 | ||
343 | out: | |
344 | return (error); | |
345 | } | |
346 | ||
347 | /* | |
348 | * We have to carry on the locking protocol on the null layer vnodes | |
349 | * as we progress through the tree. We also have to enforce read-only | |
350 | * if this layer is mounted read-only. | |
351 | */ | |
352 | null_lookup(ap) | |
353 | struct vop_lookup_args /* { | |
354 | struct vnode * a_dvp; | |
355 | struct vnode ** a_vpp; | |
356 | struct componentname * a_cnp; | |
357 | } */ *ap; | |
358 | { | |
359 | struct componentname *cnp = ap->a_cnp; | |
360 | struct proc *p = cnp->cn_proc; | |
361 | int flags = cnp->cn_flags; | |
362 | struct vop_lock_args lockargs; | |
363 | struct vop_unlock_args unlockargs; | |
364 | struct vnode *dvp, *vp; | |
365 | int error; | |
366 | ||
367 | if ((flags & ISLASTCN) && (ap->a_dvp->v_mount->mnt_flag & MNT_RDONLY) && | |
368 | (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) | |
369 | return (EROFS); | |
370 | error = null_bypass(ap); | |
371 | if (error == EJUSTRETURN && (flags & ISLASTCN) && | |
372 | (ap->a_dvp->v_mount->mnt_flag & MNT_RDONLY) && | |
373 | (cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME)) | |
374 | error = EROFS; | |
375 | /* | |
376 | * We must do the same locking and unlocking at this layer as | |
377 | * is done in the layers below us. We could figure this out | |
378 | * based on the error return and the LASTCN, LOCKPARENT, and | |
379 | * LOCKLEAF flags. However, it is more expidient to just find | |
380 | * out the state of the lower level vnodes and set ours to the | |
381 | * same state. | |
382 | */ | |
383 | dvp = ap->a_dvp; | |
384 | vp = *ap->a_vpp; | |
385 | if (dvp == vp) | |
386 | return (error); | |
387 | if (!VOP_ISLOCKED(dvp)) { | |
388 | unlockargs.a_vp = dvp; | |
389 | unlockargs.a_flags = 0; | |
390 | unlockargs.a_p = p; | |
391 | vop_nounlock(&unlockargs); | |
392 | } | |
393 | if (vp != NULL && VOP_ISLOCKED(vp)) { | |
394 | lockargs.a_vp = vp; | |
395 | lockargs.a_flags = LK_SHARED; | |
396 | lockargs.a_p = p; | |
397 | vop_nolock(&lockargs); | |
398 | } | |
399 | return (error); | |
400 | } | |
401 | ||
402 | /* | |
403 | * Setattr call. Disallow write attempts if the layer is mounted read-only. | |
404 | */ | |
405 | int | |
406 | null_setattr(ap) | |
407 | struct vop_setattr_args /* { | |
408 | struct vnodeop_desc *a_desc; | |
409 | struct vnode *a_vp; | |
410 | struct vattr *a_vap; | |
411 | struct ucred *a_cred; | |
412 | struct proc *a_p; | |
413 | } */ *ap; | |
414 | { | |
415 | struct vnode *vp = ap->a_vp; | |
416 | struct vattr *vap = ap->a_vap; | |
417 | ||
418 | if ((vap->va_flags != VNOVAL || vap->va_uid != (uid_t)VNOVAL || | |
419 | vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL || | |
420 | vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL) && | |
421 | (vp->v_mount->mnt_flag & MNT_RDONLY)) | |
422 | return (EROFS); | |
423 | if (vap->va_size != VNOVAL) { | |
424 | switch (vp->v_type) { | |
425 | case VDIR: | |
426 | return (EISDIR); | |
427 | case VCHR: | |
428 | case VBLK: | |
429 | case VSOCK: | |
430 | case VFIFO: | |
431 | return (0); | |
432 | case VREG: | |
433 | case VLNK: | |
434 | default: | |
435 | /* | |
436 | * Disallow write attempts if the filesystem is | |
437 | * mounted read-only. | |
438 | */ | |
439 | if (vp->v_mount->mnt_flag & MNT_RDONLY) | |
440 | return (EROFS); | |
441 | } | |
442 | } | |
443 | return (null_bypass(ap)); | |
444 | } | |
445 | ||
446 | /* | |
447 | * We handle getattr only to change the fsid. | |
448 | */ | |
449 | int | |
450 | null_getattr(ap) | |
451 | struct vop_getattr_args /* { | |
452 | struct vnode *a_vp; | |
453 | struct vattr *a_vap; | |
454 | struct ucred *a_cred; | |
455 | struct proc *a_p; | |
456 | } */ *ap; | |
457 | { | |
458 | int error; | |
459 | ||
460 | if (error = null_bypass(ap)) | |
461 | return (error); | |
462 | /* Requires that arguments be restored. */ | |
463 | ap->a_vap->va_fsid = ap->a_vp->v_mount->mnt_stat.f_fsid.val[0]; | |
464 | return (0); | |
465 | } | |
466 | ||
467 | int | |
468 | null_access(ap) | |
469 | struct vop_access_args /* { | |
470 | struct vnode *a_vp; | |
471 | int a_mode; | |
472 | struct ucred *a_cred; | |
473 | struct proc *a_p; | |
474 | } */ *ap; | |
475 | { | |
476 | struct vnode *vp = ap->a_vp; | |
477 | mode_t mode = ap->a_mode; | |
478 | ||
479 | /* | |
480 | * Disallow write attempts on read-only layers; | |
481 | * unless the file is a socket, fifo, or a block or | |
482 | * character device resident on the file system. | |
483 | */ | |
484 | if (mode & VWRITE) { | |
485 | switch (vp->v_type) { | |
486 | case VDIR: | |
487 | case VLNK: | |
488 | case VREG: | |
489 | if (vp->v_mount->mnt_flag & MNT_RDONLY) | |
490 | return (EROFS); | |
491 | break; | |
492 | } | |
493 | } | |
494 | return (null_bypass(ap)); | |
495 | } | |
496 | ||
497 | /* | |
498 | * We need to process our own vnode lock and then clear the | |
499 | * interlock flag as it applies only to our vnode, not the | |
500 | * vnodes below us on the stack. | |
501 | */ | |
502 | int | |
503 | null_lock(ap) | |
504 | struct vop_lock_args /* { | |
505 | struct vnode *a_vp; | |
506 | int a_flags; | |
507 | struct proc *a_p; | |
508 | } */ *ap; | |
509 | { | |
510 | ||
511 | vop_nolock(ap); | |
512 | if ((ap->a_flags & LK_TYPE_MASK) == LK_DRAIN) | |
513 | return (0); | |
514 | ap->a_flags &= ~LK_INTERLOCK; | |
515 | return (null_bypass(ap)); | |
516 | } | |
517 | ||
518 | /* | |
519 | * We need to process our own vnode unlock and then clear the | |
520 | * interlock flag as it applies only to our vnode, not the | |
521 | * vnodes below us on the stack. | |
522 | */ | |
523 | int | |
524 | null_unlock(ap) | |
525 | struct vop_unlock_args /* { | |
526 | struct vnode *a_vp; | |
527 | int a_flags; | |
528 | struct proc *a_p; | |
529 | } */ *ap; | |
530 | { | |
531 | struct vnode *vp = ap->a_vp; | |
532 | ||
533 | vop_nounlock(ap); | |
534 | ap->a_flags &= ~LK_INTERLOCK; | |
535 | return (null_bypass(ap)); | |
536 | } | |
537 | ||
538 | int | |
539 | null_inactive(ap) | |
540 | struct vop_inactive_args /* { | |
541 | struct vnode *a_vp; | |
542 | struct proc *a_p; | |
543 | } */ *ap; | |
544 | { | |
545 | /* | |
546 | * Do nothing (and _don't_ bypass). | |
547 | * Wait to vrele lowervp until reclaim, | |
548 | * so that until then our null_node is in the | |
549 | * cache and reusable. | |
550 | * | |
551 | * NEEDSWORK: Someday, consider inactive'ing | |
552 | * the lowervp and then trying to reactivate it | |
553 | * with capabilities (v_id) | |
554 | * like they do in the name lookup cache code. | |
555 | * That's too much work for now. | |
556 | */ | |
557 | VOP_UNLOCK(ap->a_vp, 0, ap->a_p); | |
558 | return (0); | |
559 | } | |
560 | ||
561 | int | |
562 | null_reclaim(ap) | |
563 | struct vop_reclaim_args /* { | |
564 | struct vnode *a_vp; | |
565 | struct proc *a_p; | |
566 | } */ *ap; | |
567 | { | |
568 | struct vnode *vp = ap->a_vp; | |
569 | struct null_node *xp = VTONULL(vp); | |
570 | struct vnode *lowervp = xp->null_lowervp; | |
571 | ||
572 | /* | |
573 | * Note: in vop_reclaim, vp->v_op == dead_vnodeop_p, | |
574 | * so we can't call VOPs on ourself. | |
575 | */ | |
576 | /* After this assignment, this node will not be re-used. */ | |
577 | xp->null_lowervp = NULL; | |
578 | LIST_REMOVE(xp, null_hash); | |
579 | FREE(vp->v_data, M_TEMP); | |
580 | vp->v_data = NULL; | |
581 | vrele (lowervp); | |
582 | return (0); | |
583 | } | |
584 | ||
585 | int | |
586 | null_print(ap) | |
587 | struct vop_print_args /* { | |
588 | struct vnode *a_vp; | |
589 | } */ *ap; | |
590 | { | |
591 | register struct vnode *vp = ap->a_vp; | |
592 | printf ("\ttag VT_NULLFS, vp=%x, lowervp=%x\n", vp, NULLVPTOLOWERVP(vp)); | |
593 | return (0); | |
594 | } | |
595 | ||
596 | /* | |
597 | * XXX - vop_strategy must be hand coded because it has no | |
598 | * vnode in its arguments. | |
599 | * This goes away with a merged VM/buffer cache. | |
600 | */ | |
601 | int | |
602 | null_strategy(ap) | |
603 | struct vop_strategy_args /* { | |
604 | struct buf *a_bp; | |
605 | } */ *ap; | |
606 | { | |
607 | struct buf *bp = ap->a_bp; | |
608 | int error; | |
609 | struct vnode *savedvp; | |
610 | ||
611 | savedvp = bp->b_vp; | |
612 | bp->b_vp = NULLVPTOLOWERVP(bp->b_vp); | |
613 | ||
614 | error = VOP_STRATEGY(bp); | |
615 | ||
616 | bp->b_vp = savedvp; | |
617 | ||
618 | return (error); | |
619 | } | |
620 | ||
621 | /* | |
622 | * XXX - like vop_strategy, vop_bwrite must be hand coded because it has no | |
623 | * vnode in its arguments. | |
624 | * This goes away with a merged VM/buffer cache. | |
625 | */ | |
626 | int | |
627 | null_bwrite(ap) | |
628 | struct vop_bwrite_args /* { | |
629 | struct buf *a_bp; | |
630 | } */ *ap; | |
631 | { | |
632 | struct buf *bp = ap->a_bp; | |
633 | int error; | |
634 | struct vnode *savedvp; | |
635 | ||
636 | savedvp = bp->b_vp; | |
637 | bp->b_vp = NULLVPTOLOWERVP(bp->b_vp); | |
638 | ||
639 | error = VOP_BWRITE(bp); | |
640 | ||
641 | bp->b_vp = savedvp; | |
642 | ||
643 | return (error); | |
644 | } | |
645 | ||
646 | /* | |
647 | * Global vfs data structures | |
648 | */ | |
649 | ||
650 | #define VOPFUNC int (*)(void *) | |
651 | ||
652 | int (**null_vnodeop_p)(void *); | |
653 | struct vnodeopv_entry_desc null_vnodeop_entries[] = { | |
654 | { &vop_default_desc, (VOPFUNC)null_bypass }, | |
655 | ||
656 | { &vop_lookup_desc, (VOPFUNC)null_lookup }, | |
657 | { &vop_setattr_desc, (VOPFUNC)null_setattr }, | |
658 | { &vop_getattr_desc, (VOPFUNC)null_getattr }, | |
659 | { &vop_access_desc, (VOPFUNC)null_access }, | |
660 | { &vop_lock_desc, (VOPFUNC)null_lock }, | |
661 | { &vop_unlock_desc, (VOPFUNC)null_unlock }, | |
662 | { &vop_inactive_desc, (VOPFUNC)null_inactive }, | |
663 | { &vop_reclaim_desc, (VOPFUNC)null_reclaim }, | |
664 | { &vop_print_desc, (VOPFUNC)null_print }, | |
665 | ||
666 | { &vop_strategy_desc, (VOPFUNC)null_strategy }, | |
667 | { &vop_bwrite_desc, (VOPFUNC)null_bwrite }, | |
668 | ||
669 | { (struct vnodeop_desc*)NULL, (int(*)())NULL } | |
670 | }; | |
671 | struct vnodeopv_desc null_vnodeop_opv_desc = | |
672 | { &null_vnodeop_p, null_vnodeop_entries }; |