1 /* $NetBSD: layer_vnops.c,v 1.38 2009/03/14 21:04:25 dsl Exp $ */
4 * Copyright (c) 1999 National Aeronautics & Space Administration
7 * This software was written by William Studenmund of the
8 * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the National Aeronautics & Space Administration
19 * nor the names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior written
23 * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB-
27 * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
36 * Copyright (c) 1992, 1993
37 * The Regents of the University of California. All rights reserved.
39 * This code is derived from software contributed to Berkeley by
40 * John Heidemann of the UCLA Ficus project.
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * @(#)null_vnops.c 8.6 (Berkeley) 5/27/95
69 * @(#)lofs_vnops.c 1.2 (Berkeley) 6/18/92
70 * Id: lofs_vnops.c,v 1.11 1992/05/30 10:05:43 jsp Exp jsp
72 * @(#)null_vnodeops.c 1.20 92/07/07 UCLA Ficus project
76 * Null Layer vnode routines.
78 * (See mount_null(8) for more information.)
80 * The layer.h, layer_extern.h, layer_vfs.c, and layer_vnops.c files provide
81 * the core implementation of the null file system and most other stacked
82 * fs's. The description below refers to the null file system, but the
83 * services provided by the layer* files are useful for all layered fs's.
85 * The null layer duplicates a portion of the file system
86 * name space under a new name. In this respect, it is
87 * similar to the loopback file system. It differs from
88 * the loopback fs in two respects: it is implemented using
89 * a stackable layers techniques, and it's "null-node"s stack above
90 * all lower-layer vnodes, not just over directory vnodes.
92 * The null layer has two purposes. First, it serves as a demonstration
93 * of layering by proving a layer which does nothing. (It actually
94 * does everything the loopback file system does, which is slightly
95 * more than nothing.) Second, the null layer can serve as a prototype
96 * layer. Since it provides all necessary layer framework,
97 * new file system layers can be created very easily be starting
100 * The remainder of the man page examines the null layer as a basis
101 * for constructing new layers.
104 * INSTANTIATING NEW NULL LAYERS
106 * New null layers are created with mount_null(8).
107 * Mount_null(8) takes two arguments, the pathname
108 * of the lower vfs (target-pn) and the pathname where the null
109 * layer will appear in the namespace (alias-pn). After
110 * the null layer is put into place, the contents
111 * of target-pn subtree will be aliased under alias-pn.
113 * It is conceivable that other overlay filesystems will take different
114 * parameters. For instance, data migration or access controll layers might
115 * only take one pathname which will serve both as the target-pn and
116 * alias-pn described above.
119 * OPERATION OF A NULL LAYER
121 * The null layer is the minimum file system layer,
122 * simply bypassing all possible operations to the lower layer
123 * for processing there. The majority of its activity centers
124 * on the bypass routine, through which nearly all vnode operations
127 * The bypass routine accepts arbitrary vnode operations for
128 * handling by the lower layer. It begins by examing vnode
129 * operation arguments and replacing any layered nodes by their
130 * lower-layer equivalents. It then invokes the operation
131 * on the lower layer. Finally, it replaces the layered nodes
132 * in the arguments and, if a vnode is return by the operation,
133 * stacks a layered node on top of the returned vnode.
135 * The bypass routine in this file, layer_bypass(), is suitable for use
136 * by many different layered filesystems. It can be used by multiple
137 * filesystems simultaneously. Alternatively, a layered fs may provide
138 * its own bypass routine, in which case layer_bypass() should be used as
139 * a model. For instance, the main functionality provided by umapfs, the user
140 * identity mapping file system, is handled by a custom bypass routine.
142 * Typically a layered fs registers its selected bypass routine as the
143 * default vnode operation in its vnodeopv_entry_desc table. Additionally
144 * the filesystem must store the bypass entry point in the layerm_bypass
145 * field of struct layer_mount. All other layer routines in this file will
146 * use the layerm_bypass routine.
148 * Although the bypass routine handles most operations outright, a number
149 * of operations are special cased, and handled by the layered fs. One
150 * group, layer_setattr, layer_getattr, layer_access, layer_open, and
151 * layer_fsync, perform layer-specific manipulation in addition to calling
152 * the bypass routine. The other group
154 * Although bypass handles most operations, vop_getattr, vop_lock,
155 * vop_unlock, vop_inactive, vop_reclaim, and vop_print are not
156 * bypassed. Vop_getattr must change the fsid being returned.
157 * Vop_lock and vop_unlock must handle any locking for the
158 * current vnode as well as pass the lock request down.
159 * Vop_inactive and vop_reclaim are not bypassed so that
160 * they can handle freeing null-layer specific data. Vop_print
161 * is not bypassed to avoid excessive debugging information.
162 * Also, certain vnode operations change the locking state within
163 * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
164 * and symlink). Ideally these operations should not change the
165 * lock state, but should be changed to let the caller of the
166 * function unlock them. Otherwise all intermediate vnode layers
167 * (such as union, umapfs, etc) must catch these functions to do
168 * the necessary locking at their layer.
171 * INSTANTIATING VNODE STACKS
173 * Mounting associates the null layer with a lower layer,
174 * effect stacking two VFSes. Vnode stacks are instead
175 * created on demand as files are accessed.
177 * The initial mount creates a single vnode stack for the
178 * root of the new null layer. All other vnode stacks
179 * are created as a result of vnode operations on
180 * this or other null vnode stacks.
182 * New vnode stacks come into existence as a result of
183 * an operation which returns a vnode.
184 * The bypass routine stacks a null-node above the new
185 * vnode before returning it to the caller.
187 * For example, imagine mounting a null layer with
188 * "mount_null /usr/include /dev/layer/null".
189 * Changing directory to /dev/layer/null will assign
190 * the root null-node (which was created when the null layer was mounted).
191 * Now consider opening "sys". A vop_lookup would be
192 * done on the root null-node. This operation would bypass through
193 * to the lower layer which would return a vnode representing
194 * the UFS "sys". layer_bypass then builds a null-node
195 * aliasing the UFS "sys" and returns this to the caller.
196 * Later operations on the null-node "sys" will repeat this
197 * process when constructing other vnode stacks.
200 * CREATING OTHER FILE SYSTEM LAYERS
202 * One of the easiest ways to construct new file system layers is to make
203 * a copy of the null layer, rename all files and variables, and
204 * then begin modifing the copy. Sed can be used to easily rename
207 * The umap layer is an example of a layer descended from the
211 * INVOKING OPERATIONS ON LOWER LAYERS
213 * There are two techniques to invoke operations on a lower layer
214 * when the operation cannot be completely bypassed. Each method
215 * is appropriate in different situations. In both cases,
216 * it is the responsibility of the aliasing layer to make
217 * the operation arguments "correct" for the lower layer
218 * by mapping an vnode arguments to the lower layer.
220 * The first approach is to call the aliasing layer's bypass routine.
221 * This method is most suitable when you wish to invoke the operation
222 * currently being handled on the lower layer. It has the advantage
223 * that the bypass routine already must do argument mapping.
224 * An example of this is null_getattrs in the null layer.
226 * A second approach is to directly invoke vnode operations on
227 * the lower layer with the VOP_OPERATIONNAME interface.
228 * The advantage of this method is that it is easy to invoke
229 * arbitrary operations on the lower layer. The disadvantage
230 * is that vnodes' arguments must be manually mapped.
234 #include <sys/cdefs.h>
235 __KERNEL_RCSID(0, "$NetBSD: layer_vnops.c,v 1.38 2009/03/14 21:04:25 dsl Exp $");
237 #include <sys/param.h>
238 #include <sys/systm.h>
239 #include <sys/proc.h>
240 #include <sys/time.h>
241 #include <sys/vnode.h>
242 #include <sys/mount.h>
243 #include <sys/namei.h>
244 #include <sys/kmem.h>
246 #include <sys/kauth.h>
248 #include <miscfs/genfs/layer.h>
249 #include <miscfs/genfs/layer_extern.h>
250 #include <miscfs/genfs/genfs.h>
254 * This is the 08-June-99 bypass routine, based on the 10-Apr-92 bypass
255 * routine by John Heidemann.
256 * The new element for this version is that the whole nullfs
257 * system gained the concept of locks on the lower node, and locks on
258 * our nodes. When returning from a call to the lower layer, we may
259 * need to update lock state ONLY on our layer. The LAYERFS_UPPER*LOCK()
260 * macros provide this functionality.
261 * The 10-Apr-92 version was optimized for speed, throwing away some
262 * safety checks. It should still always work, but it's not as
263 * robust to programmer errors.
265 * In general, we map all vnodes going down and unmap them on the way back.
267 * Also, some BSD vnode operations have the side effect of vrele'ing
268 * their arguments. With stacking, the reference counts are held
269 * by the upper node, not the lower one, so we must handle these
270 * side-effects here. This is not of concern in Sun-derived systems
271 * since there are no such side-effects.
273 * New for the 08-June-99 version: we also handle operations which unlock
274 * the passed-in node (typically they vput the node).
276 * This makes the following assumptions:
277 * - only one returned vpp
278 * - no INOUT vpp's (Sun's vop_open has one of these)
279 * - the vnode operation vector of the first vnode should be used
280 * to determine what implementation of the op should be invoked
281 * - all mapped vnodes are of our vnode-type (NEEDSWORK:
282 * problems on rmdir'ing mount points and renaming?)
285 layer_bypass(void *v
)
287 struct vop_generic_args
/* {
288 struct vnodeop_desc *a_desc;
289 <other random data follows, presumably>
291 int (**our_vnodeop_p
)(void *);
292 struct vnode
**this_vp_p
;
294 struct vnode
*old_vps
[VDESC_MAX_VPS
], *vp0
;
295 struct vnode
**vps_p
[VDESC_MAX_VPS
];
296 struct vnode
***vppp
;
298 struct vnodeop_desc
*descp
= ap
->a_desc
;
303 * We require at least one vp.
305 if (descp
->vdesc_vp_offsets
== NULL
||
306 descp
->vdesc_vp_offsets
[0] == VDESC_NO_OFFSET
)
307 panic("%s: no vp's in map.\n", __func__
);
311 VOPARG_OFFSETTO(struct vnode
**, descp
->vdesc_vp_offsets
[0], ap
);
314 flags
= MOUNTTOLAYERMOUNT(mp
)->layerm_flags
;
315 our_vnodeop_p
= vp0
->v_op
;
317 if (flags
& LAYERFS_MBYPASSDEBUG
)
318 printf("%s: %s\n", __func__
, descp
->vdesc_name
);
321 * Map the vnodes going in.
322 * Later, we'll invoke the operation based on
323 * the first mapped vnode's operation vector.
325 reles
= descp
->vdesc_flags
;
326 for (i
= 0; i
< VDESC_MAX_VPS
; reles
>>= 1, i
++) {
327 if (descp
->vdesc_vp_offsets
[i
] == VDESC_NO_OFFSET
)
328 break; /* bail out at end of list */
329 vps_p
[i
] = this_vp_p
=
330 VOPARG_OFFSETTO(struct vnode
**, descp
->vdesc_vp_offsets
[i
],
333 * We're not guaranteed that any but the first vnode
334 * are of our type. Check for and don't map any
335 * that aren't. (We must always map first vp or vclean fails.)
337 if (i
&& (*this_vp_p
== NULL
||
338 (*this_vp_p
)->v_op
!= our_vnodeop_p
)) {
341 old_vps
[i
] = *this_vp_p
;
342 *(vps_p
[i
]) = LAYERVPTOLOWERVP(*this_vp_p
);
344 * XXX - Several operations have the side effect
345 * of vrele'ing their vp's. We must account for
346 * that. (This should go away in the future.)
348 if (reles
& VDESC_VP0_WILLRELE
)
355 * Call the operation on the lower layer
356 * with the modified argument structure.
358 error
= VCALL(*vps_p
[0], descp
->vdesc_offset
, ap
);
361 * Maintain the illusion of call-by-value
362 * by restoring vnodes in the argument structure
363 * to their original value.
365 reles
= descp
->vdesc_flags
;
366 for (i
= 0; i
< VDESC_MAX_VPS
; reles
>>= 1, i
++) {
367 if (descp
->vdesc_vp_offsets
[i
] == VDESC_NO_OFFSET
)
368 break; /* bail out at end of list */
370 *(vps_p
[i
]) = old_vps
[i
];
371 if (reles
& VDESC_VP0_WILLUNLOCK
)
372 LAYERFS_UPPERUNLOCK(*(vps_p
[i
]), 0, error1
);
373 if (reles
& VDESC_VP0_WILLRELE
)
379 * Map the possible out-going vpp
380 * (Assumes that the lower layer always returns
381 * a VREF'ed vpp unless it gets an error.)
383 if (descp
->vdesc_vpp_offset
!= VDESC_NO_OFFSET
&&
384 !(descp
->vdesc_flags
& VDESC_NOMAP_VPP
) &&
387 * XXX - even though some ops have vpp returned vp's,
388 * several ops actually vrele this before returning.
389 * We must avoid these ops.
390 * (This should go away when these ops are regularized.)
392 if (descp
->vdesc_flags
& VDESC_VPP_WILLRELE
)
394 vppp
= VOPARG_OFFSETTO(struct vnode
***,
395 descp
->vdesc_vpp_offset
, ap
);
397 * Only vop_lookup, vop_create, vop_makedir, vop_bmap,
398 * vop_mknod, and vop_symlink return vpp's. vop_bmap
399 * doesn't call bypass as the lower vpp is fine (we're just
400 * going to do i/o on it). vop_lookup doesn't call bypass
401 * as a lookup on "." would generate a locking error.
402 * So all the calls which get us here have a locked vpp. :-)
404 error
= layer_node_create(mp
, **vppp
, *vppp
);
416 * We have to carry on the locking protocol on the layer vnodes
417 * as we progress through the tree. We also have to enforce read-only
418 * if this layer is mounted read-only.
421 layer_lookup(void *v
)
423 struct vop_lookup_args
/* {
424 struct vnodeop_desc *a_desc;
425 struct vnode * a_dvp;
426 struct vnode ** a_vpp;
427 struct componentname * a_cnp;
429 struct componentname
*cnp
= ap
->a_cnp
;
430 int flags
= cnp
->cn_flags
;
431 struct vnode
*dvp
, *lvp
, *ldvp
;
436 if ((flags
& ISLASTCN
) && (dvp
->v_mount
->mnt_flag
& MNT_RDONLY
) &&
437 (cnp
->cn_nameiop
== DELETE
|| cnp
->cn_nameiop
== RENAME
))
440 ldvp
= LAYERVPTOLOWERVP(dvp
);
442 error
= VCALL(ldvp
, ap
->a_desc
->vdesc_offset
, ap
);
446 if (error
== EJUSTRETURN
&& (flags
& ISLASTCN
) &&
447 (dvp
->v_mount
->mnt_flag
& MNT_RDONLY
) &&
448 (cnp
->cn_nameiop
== CREATE
|| cnp
->cn_nameiop
== RENAME
))
452 * We must do the same locking and unlocking at this layer as
453 * is done in the layers below us.
458 * Got the same object back, because we looked up ".",
459 * or ".." in the root node of a mount point.
460 * So we make another reference to dvp and return it.
465 } else if (lvp
!= NULL
) {
466 /* dvp, ldvp and vp are all locked */
467 error
= layer_node_create(dvp
->v_mount
, lvp
, ap
->a_vpp
);
476 * Setattr call. Disallow write attempts if the layer is mounted read-only.
479 layer_setattr(void *v
)
481 struct vop_setattr_args
/* {
482 struct vnodeop_desc *a_desc;
488 struct vnode
*vp
= ap
->a_vp
;
489 struct vattr
*vap
= ap
->a_vap
;
491 if ((vap
->va_flags
!= VNOVAL
|| vap
->va_uid
!= (uid_t
)VNOVAL
||
492 vap
->va_gid
!= (gid_t
)VNOVAL
|| vap
->va_atime
.tv_sec
!= VNOVAL
||
493 vap
->va_mtime
.tv_sec
!= VNOVAL
|| vap
->va_mode
!= (mode_t
)VNOVAL
) &&
494 (vp
->v_mount
->mnt_flag
& MNT_RDONLY
))
496 if (vap
->va_size
!= VNOVAL
) {
497 switch (vp
->v_type
) {
509 * Disallow write attempts if the filesystem is
512 if (vp
->v_mount
->mnt_flag
& MNT_RDONLY
)
516 return (LAYERFS_DO_BYPASS(vp
, ap
));
520 * We handle getattr only to change the fsid.
523 layer_getattr(void *v
)
525 struct vop_getattr_args
/* {
531 struct vnode
*vp
= ap
->a_vp
;
534 if ((error
= LAYERFS_DO_BYPASS(vp
, ap
)) != 0)
536 /* Requires that arguments be restored. */
537 ap
->a_vap
->va_fsid
= vp
->v_mount
->mnt_stat
.f_fsidx
.__fsid_val
[0];
542 layer_access(void *v
)
544 struct vop_access_args
/* {
550 struct vnode
*vp
= ap
->a_vp
;
551 mode_t mode
= ap
->a_mode
;
554 * Disallow write attempts on read-only layers;
555 * unless the file is a socket, fifo, or a block or
556 * character device resident on the file system.
559 switch (vp
->v_type
) {
563 if (vp
->v_mount
->mnt_flag
& MNT_RDONLY
)
570 return (LAYERFS_DO_BYPASS(vp
, ap
));
574 * We must handle open to be able to catch MNT_NODEV and friends.
579 struct vop_open_args
*ap
= v
;
580 struct vnode
*vp
= ap
->a_vp
;
581 enum vtype lower_type
= LAYERVPTOLOWERVP(vp
)->v_type
;
583 if (((lower_type
== VBLK
) || (lower_type
== VCHR
)) &&
584 (vp
->v_mount
->mnt_flag
& MNT_NODEV
))
587 return LAYERFS_DO_BYPASS(vp
, ap
);
591 * We need to process our own vnode lock and then clear the
592 * interlock flag as it applies only to our vnode, not the
593 * vnodes below us on the stack.
598 struct vop_lock_args
/* {
603 struct vnode
*vp
= ap
->a_vp
, *lowervp
;
604 int flags
= ap
->a_flags
, error
;
606 if (flags
& LK_INTERLOCK
) {
607 mutex_exit(&vp
->v_interlock
);
608 flags
&= ~LK_INTERLOCK
;
611 if (vp
->v_vnlock
!= NULL
) {
613 * The lower level has exported a struct lock to us. Use
614 * it so that all vnodes in the stack lock and unlock
615 * simultaneously. Note: we don't DRAIN the lock as DRAIN
616 * decommissions the lock - just because our vnode is
617 * going away doesn't mean the struct lock below us is.
618 * LK_EXCLUSIVE is fine.
620 return (vlockmgr(vp
->v_vnlock
, flags
));
623 * Ahh well. It would be nice if the fs we're over would
624 * export a struct lock for us to use, but it doesn't.
626 * To prevent race conditions involving doing a lookup
627 * on "..", we have to lock the lower node, then lock our
628 * node. Most of the time it won't matter that we lock our
629 * node (as any locking would need the lower one locked
632 lowervp
= LAYERVPTOLOWERVP(vp
);
633 error
= VOP_LOCK(lowervp
, flags
);
636 if ((error
= vlockmgr(&vp
->v_lock
, flags
))) {
637 VOP_UNLOCK(lowervp
, 0);
646 layer_unlock(void *v
)
648 struct vop_unlock_args
/* {
653 struct vnode
*vp
= ap
->a_vp
;
654 int flags
= ap
->a_flags
;
656 if (flags
& LK_INTERLOCK
) {
657 mutex_exit(&vp
->v_interlock
);
658 flags
&= ~LK_INTERLOCK
;
661 if (vp
->v_vnlock
!= NULL
) {
662 return (vlockmgr(vp
->v_vnlock
, ap
->a_flags
| LK_RELEASE
));
664 VOP_UNLOCK(LAYERVPTOLOWERVP(vp
), flags
);
665 return (vlockmgr(&vp
->v_lock
, flags
| LK_RELEASE
));
670 layer_islocked(void *v
)
672 struct vop_islocked_args
/* {
675 struct vnode
*vp
= ap
->a_vp
;
678 if (vp
->v_vnlock
!= NULL
)
679 return vlockstatus(vp
->v_vnlock
);
681 lkstatus
= VOP_ISLOCKED(LAYERVPTOLOWERVP(vp
));
685 return vlockstatus(&vp
->v_lock
);
689 * If vinvalbuf is calling us, it's a "shallow fsync" -- don't bother
690 * syncing the underlying vnodes, since they'll be fsync'ed when
691 * reclaimed; otherwise,
692 * pass it through to the underlying layer.
694 * XXX Do we still need to worry about shallow fsync?
700 struct vop_fsync_args
/* {
709 if (ap
->a_flags
& FSYNC_RECLAIM
) {
713 return (LAYERFS_DO_BYPASS(ap
->a_vp
, ap
));
718 layer_inactive(void *v
)
720 struct vop_inactive_args
/* {
724 struct vnode
*vp
= ap
->a_vp
;
727 * ..., but don't cache the device node. Also, if we did a
728 * remove, don't cache the node.
730 *ap
->a_recycle
= (vp
->v_type
== VBLK
|| vp
->v_type
== VCHR
731 || (VTOLAYER(vp
)->layer_flags
& LAYERFS_REMOVED
));
734 * Do nothing (and _don't_ bypass).
735 * Wait to vrele lowervp until reclaim,
736 * so that until then our layer_node is in the
737 * cache and reusable.
739 * NEEDSWORK: Someday, consider inactive'ing
740 * the lowervp and then trying to reactivate it
741 * with capabilities (v_id)
742 * like they do in the name lookup cache code.
743 * That's too much work for now.
751 layer_remove(void *v
)
753 struct vop_remove_args
/* {
756 struct componentname *a_cnp;
760 struct vnode
*vp
= ap
->a_vp
;
763 if ((error
= LAYERFS_DO_BYPASS(vp
, ap
)) == 0)
764 VTOLAYER(vp
)->layer_flags
|= LAYERFS_REMOVED
;
772 layer_rename(void *v
)
774 struct vop_rename_args
/* {
775 struct vnode *a_fdvp;
777 struct componentname *a_fcnp;
778 struct vnode *a_tdvp;
780 struct componentname *a_tcnp;
784 struct vnode
*fdvp
= ap
->a_fdvp
;
789 if (tvp
->v_mount
!= fdvp
->v_mount
)
794 error
= LAYERFS_DO_BYPASS(fdvp
, ap
);
797 VTOLAYER(tvp
)->layer_flags
|= LAYERFS_REMOVED
;
807 struct vop_rmdir_args
/* {
810 struct componentname *a_cnp;
813 struct vnode
*vp
= ap
->a_vp
;
816 if ((error
= LAYERFS_DO_BYPASS(vp
, ap
)) == 0)
817 VTOLAYER(vp
)->layer_flags
|= LAYERFS_REMOVED
;
825 layer_reclaim(void *v
)
827 struct vop_reclaim_args
/* {
831 struct vnode
*vp
= ap
->a_vp
;
832 struct layer_mount
*lmp
= MOUNTTOLAYERMOUNT(vp
->v_mount
);
833 struct layer_node
*xp
= VTOLAYER(vp
);
834 struct vnode
*lowervp
= xp
->layer_lowervp
;
837 * Note: in vop_reclaim, the node's struct lock has been
838 * decomissioned, so we have to be careful about calling
839 * VOP's on ourself. We must be careful as VXLOCK is set.
841 /* After this assignment, this node will not be re-used. */
842 if ((vp
== lmp
->layerm_rootvp
)) {
844 * Oops! We no longer have a root node. Most likely reason is
845 * that someone forcably unmunted the underlying fs.
847 * Now getting the root vnode will fail. We're dead. :-(
849 lmp
->layerm_rootvp
= NULL
;
851 xp
->layer_lowervp
= NULL
;
852 mutex_enter(&lmp
->layerm_hashlock
);
853 LIST_REMOVE(xp
, layer_hash
);
854 mutex_exit(&lmp
->layerm_hashlock
);
855 kmem_free(vp
->v_data
, lmp
->layerm_size
);
863 * We just feed the returned vnode up to the caller - there's no need
864 * to build a layer node on top of the node on which we're going to do
870 struct vop_bmap_args
/* {
873 struct vnode **a_vpp;
879 ap
->a_vp
= vp
= LAYERVPTOLOWERVP(ap
->a_vp
);
881 return (VCALL(vp
, ap
->a_desc
->vdesc_offset
, ap
));
887 struct vop_print_args
/* {
890 struct vnode
*vp
= ap
->a_vp
;
891 printf ("\ttag VT_LAYERFS, vp=%p, lowervp=%p\n", vp
, LAYERVPTOLOWERVP(vp
));
896 * XXX - vop_bwrite must be hand coded because it has no
897 * vnode in its arguments.
898 * This goes away with a merged VM/buffer cache.
901 layer_bwrite(void *v
)
903 struct vop_bwrite_args
/* {
906 struct buf
*bp
= ap
->a_bp
;
908 struct vnode
*savedvp
;
911 bp
->b_vp
= LAYERVPTOLOWERVP(bp
->b_vp
);
913 error
= VOP_BWRITE(bp
);
921 layer_getpages(void *v
)
923 struct vop_getpages_args
/* {
926 struct vm_page **a_m;
929 vm_prot_t a_access_type;
933 struct vnode
*vp
= ap
->a_vp
;
937 * just pass the request on to the underlying layer.
940 if (ap
->a_flags
& PGO_LOCKED
) {
943 ap
->a_vp
= LAYERVPTOLOWERVP(vp
);
944 mutex_exit(&vp
->v_interlock
);
945 mutex_enter(&ap
->a_vp
->v_interlock
);
946 error
= VCALL(ap
->a_vp
, VOFFSET(vop_getpages
), ap
);
951 layer_putpages(void *v
)
953 struct vop_putpages_args
/* {
959 struct vnode
*vp
= ap
->a_vp
;
963 * just pass the request on to the underlying layer.
966 ap
->a_vp
= LAYERVPTOLOWERVP(vp
);
967 mutex_exit(&vp
->v_interlock
);
968 if (ap
->a_flags
& PGO_RECLAIM
) {
971 mutex_enter(&ap
->a_vp
->v_interlock
);
972 error
= VCALL(ap
->a_vp
, VOFFSET(vop_putpages
), ap
);