Home | History | Annotate | Line # | Download | only in genfs
layer_vnops.c revision 1.35.10.3
      1  1.35.10.3      yamt /*	$NetBSD: layer_vnops.c,v 1.35.10.3 2010/08/11 22:54:47 yamt Exp $	*/
      2        1.1  wrstuden 
      3        1.1  wrstuden /*
      4        1.1  wrstuden  * Copyright (c) 1999 National Aeronautics & Space Administration
      5        1.1  wrstuden  * All rights reserved.
      6        1.1  wrstuden  *
      7        1.1  wrstuden  * This software was written by William Studenmund of the
      8        1.6       wiz  * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
      9        1.1  wrstuden  *
     10        1.1  wrstuden  * Redistribution and use in source and binary forms, with or without
     11        1.1  wrstuden  * modification, are permitted provided that the following conditions
     12        1.1  wrstuden  * are met:
     13        1.1  wrstuden  * 1. Redistributions of source code must retain the above copyright
     14        1.1  wrstuden  *    notice, this list of conditions and the following disclaimer.
     15        1.1  wrstuden  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1  wrstuden  *    notice, this list of conditions and the following disclaimer in the
     17        1.1  wrstuden  *    documentation and/or other materials provided with the distribution.
     18        1.2     soren  * 3. Neither the name of the National Aeronautics & Space Administration
     19        1.1  wrstuden  *    nor the names of its contributors may be used to endorse or promote
     20        1.1  wrstuden  *    products derived from this software without specific prior written
     21        1.1  wrstuden  *    permission.
     22        1.1  wrstuden  *
     23        1.1  wrstuden  * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION
     24        1.1  wrstuden  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25        1.1  wrstuden  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26        1.1  wrstuden  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB-
     27        1.1  wrstuden  * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
     28        1.1  wrstuden  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29        1.1  wrstuden  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30        1.1  wrstuden  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31        1.1  wrstuden  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32        1.1  wrstuden  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33        1.1  wrstuden  * POSSIBILITY OF SUCH DAMAGE.
     34        1.1  wrstuden  */
     35  1.35.10.3      yamt 
     36        1.1  wrstuden /*
     37        1.1  wrstuden  * Copyright (c) 1992, 1993
     38        1.1  wrstuden  *	The Regents of the University of California.  All rights reserved.
     39        1.1  wrstuden  *
     40        1.1  wrstuden  * This code is derived from software contributed to Berkeley by
     41        1.1  wrstuden  * John Heidemann of the UCLA Ficus project.
     42        1.1  wrstuden  *
     43        1.1  wrstuden  * Redistribution and use in source and binary forms, with or without
     44        1.1  wrstuden  * modification, are permitted provided that the following conditions
     45        1.1  wrstuden  * are met:
     46        1.1  wrstuden  * 1. Redistributions of source code must retain the above copyright
     47        1.1  wrstuden  *    notice, this list of conditions and the following disclaimer.
     48        1.1  wrstuden  * 2. Redistributions in binary form must reproduce the above copyright
     49        1.1  wrstuden  *    notice, this list of conditions and the following disclaimer in the
     50        1.1  wrstuden  *    documentation and/or other materials provided with the distribution.
     51       1.11       agc  * 3. Neither the name of the University nor the names of its contributors
     52        1.1  wrstuden  *    may be used to endorse or promote products derived from this software
     53        1.1  wrstuden  *    without specific prior written permission.
     54        1.1  wrstuden  *
     55        1.1  wrstuden  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     56        1.1  wrstuden  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     57        1.1  wrstuden  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     58        1.1  wrstuden  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     59        1.1  wrstuden  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     60        1.1  wrstuden  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     61        1.1  wrstuden  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     62        1.1  wrstuden  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     63        1.1  wrstuden  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     64        1.1  wrstuden  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     65        1.1  wrstuden  * SUCH DAMAGE.
     66        1.1  wrstuden  *
     67        1.1  wrstuden  *	@(#)null_vnops.c	8.6 (Berkeley) 5/27/95
     68        1.1  wrstuden  *
     69        1.1  wrstuden  * Ancestors:
     70        1.1  wrstuden  *	@(#)lofs_vnops.c	1.2 (Berkeley) 6/18/92
     71       1.31     enami  *	Id: lofs_vnops.c,v 1.11 1992/05/30 10:05:43 jsp Exp jsp
     72        1.1  wrstuden  *	...and...
     73        1.1  wrstuden  *	@(#)null_vnodeops.c 1.20 92/07/07 UCLA Ficus project
     74        1.1  wrstuden  */
     75        1.1  wrstuden 
     76        1.1  wrstuden /*
     77  1.35.10.3      yamt  * Generic layer vnode operations.
     78        1.1  wrstuden  *
     79        1.1  wrstuden  * The layer.h, layer_extern.h, layer_vfs.c, and layer_vnops.c files provide
     80  1.35.10.3      yamt  * the core implementation of stacked file-systems.
     81  1.35.10.3      yamt  *
     82  1.35.10.3      yamt  * The layerfs duplicates a portion of the file system name space under
     83  1.35.10.3      yamt  * a new name.  In this respect, it is similar to the loopback file system.
     84  1.35.10.3      yamt  * It differs from the loopback fs in two respects: it is implemented using
     85  1.35.10.3      yamt  * a stackable layers technique, and it is "layerfs-nodes" stack above all
     86  1.35.10.3      yamt  * lower-layer vnodes, not just over directory vnodes.
     87  1.35.10.3      yamt  *
     88  1.35.10.3      yamt  * OPERATION OF LAYERFS
     89  1.35.10.3      yamt  *
     90  1.35.10.3      yamt  * The layerfs is the minimum file system layer, bypassing all possible
     91  1.35.10.3      yamt  * operations to the lower layer for processing there.  The majority of its
     92  1.35.10.3      yamt  * activity centers on the bypass routine, through which nearly all vnode
     93  1.35.10.3      yamt  * operations pass.
     94  1.35.10.3      yamt  *
     95  1.35.10.3      yamt  * The bypass routine accepts arbitrary vnode operations for handling by
     96  1.35.10.3      yamt  * the lower layer.  It begins by examining vnode operation arguments and
     97  1.35.10.3      yamt  * replacing any layered nodes by their lower-layer equivalents.  It then
     98  1.35.10.3      yamt  * invokes an operation on the lower layer.  Finally, it replaces the
     99  1.35.10.3      yamt  * layered nodes in the arguments and, if a vnode is returned by the
    100  1.35.10.3      yamt  * operation, stacks a layered node on top of the returned vnode.
    101        1.1  wrstuden  *
    102        1.1  wrstuden  * The bypass routine in this file, layer_bypass(), is suitable for use
    103        1.1  wrstuden  * by many different layered filesystems. It can be used by multiple
    104        1.1  wrstuden  * filesystems simultaneously. Alternatively, a layered fs may provide
    105        1.1  wrstuden  * its own bypass routine, in which case layer_bypass() should be used as
    106        1.1  wrstuden  * a model. For instance, the main functionality provided by umapfs, the user
    107        1.1  wrstuden  * identity mapping file system, is handled by a custom bypass routine.
    108        1.1  wrstuden  *
    109        1.1  wrstuden  * Typically a layered fs registers its selected bypass routine as the
    110        1.1  wrstuden  * default vnode operation in its vnodeopv_entry_desc table. Additionally
    111        1.1  wrstuden  * the filesystem must store the bypass entry point in the layerm_bypass
    112        1.1  wrstuden  * field of struct layer_mount. All other layer routines in this file will
    113  1.35.10.3      yamt  * use the layerm_bypass() routine.
    114        1.1  wrstuden  *
    115        1.1  wrstuden  * Although the bypass routine handles most operations outright, a number
    116  1.35.10.3      yamt  * of operations are special cased and handled by the layerfs.  For instance,
    117  1.35.10.3      yamt  * layer_getattr() must change the fsid being returned.  While layer_lock()
    118  1.35.10.3      yamt  * and layer_unlock() must handle any locking for the current vnode as well
    119  1.35.10.3      yamt  * as pass the lock request down.  layer_inactive() and layer_reclaim() are
    120  1.35.10.3      yamt  * not bypassed so that they can handle freeing layerfs-specific data.  Also,
    121  1.35.10.3      yamt  * certain vnode operations (create, mknod, remove, link, rename, mkdir,
    122  1.35.10.3      yamt  * rmdir, and symlink) change the locking state within the operation.  Ideally
    123  1.35.10.3      yamt  * these operations should not change the lock state, but should be changed
    124  1.35.10.3      yamt  * to let the caller of the function unlock them.  Otherwise, all intermediate
    125  1.35.10.3      yamt  * vnode layers (such as union, umapfs, etc) must catch these functions to do
    126        1.1  wrstuden  * the necessary locking at their layer.
    127        1.1  wrstuden  *
    128        1.1  wrstuden  * INSTANTIATING VNODE STACKS
    129        1.1  wrstuden  *
    130  1.35.10.3      yamt  * Mounting associates "layerfs-nodes" stack and lower layer, in effect
    131  1.35.10.3      yamt  * stacking two VFSes.  The initial mount creates a single vnode stack for
    132  1.35.10.3      yamt  * the root of the new layerfs.  All other vnode stacks are created as a
    133  1.35.10.3      yamt  * result of vnode operations on this or other layerfs vnode stacks.
    134  1.35.10.3      yamt  *
    135  1.35.10.3      yamt  * New vnode stacks come into existence as a result of an operation which
    136  1.35.10.3      yamt  * returns a vnode.  The bypass routine stacks a layerfs-node above the new
    137        1.1  wrstuden  * vnode before returning it to the caller.
    138        1.1  wrstuden  *
    139  1.35.10.3      yamt  * For example, imagine mounting a null layer with:
    140        1.1  wrstuden  *
    141  1.35.10.3      yamt  *	"mount_null /usr/include /dev/layer/null"
    142        1.1  wrstuden  *
    143  1.35.10.3      yamt  * Changing directory to /dev/layer/null will assign the root layerfs-node,
    144  1.35.10.3      yamt  * which was created when the null layer was mounted).  Now consider opening
    145  1.35.10.3      yamt  * "sys".  A layer_lookup() would be performed on the root layerfs-node.
    146  1.35.10.3      yamt  * This operation would bypass through to the lower layer which would return
    147  1.35.10.3      yamt  * a vnode representing the UFS "sys".  Then, layer_bypass() builds a
    148  1.35.10.3      yamt  * layerfs-node aliasing the UFS "sys" and returns this to the caller.
    149  1.35.10.3      yamt  * Later operations on the layerfs-node "sys" will repeat this process when
    150  1.35.10.3      yamt  * constructing other vnode stacks.
    151        1.1  wrstuden  *
    152        1.1  wrstuden  * INVOKING OPERATIONS ON LOWER LAYERS
    153        1.1  wrstuden  *
    154  1.35.10.3      yamt  * There are two techniques to invoke operations on a lower layer when the
    155  1.35.10.3      yamt  * operation cannot be completely bypassed.  Each method is appropriate in
    156  1.35.10.3      yamt  * different situations.  In both cases, it is the responsibility of the
    157  1.35.10.3      yamt  * aliasing layer to make the operation arguments "correct" for the lower
    158  1.35.10.3      yamt  * layer by mapping any vnode arguments to the lower layer.
    159  1.35.10.3      yamt  *
    160  1.35.10.3      yamt  * The first approach is to call the aliasing layer's bypass routine.  This
    161  1.35.10.3      yamt  * method is most suitable when you wish to invoke the operation currently
    162  1.35.10.3      yamt  * being handled on the lower layer.  It has the advantage that the bypass
    163  1.35.10.3      yamt  * routine already must do argument mapping.  An example of this is
    164  1.35.10.3      yamt  * layer_getattr().
    165  1.35.10.3      yamt  *
    166  1.35.10.3      yamt  * A second approach is to directly invoke vnode operations on the lower
    167  1.35.10.3      yamt  * layer with the VOP_OPERATIONNAME interface.  The advantage of this method
    168  1.35.10.3      yamt  * is that it is easy to invoke arbitrary operations on the lower layer.
    169  1.35.10.3      yamt  * The disadvantage is that vnode's arguments must be manually mapped.
    170        1.1  wrstuden  */
    171        1.8     lukem 
    172        1.8     lukem #include <sys/cdefs.h>
    173  1.35.10.3      yamt __KERNEL_RCSID(0, "$NetBSD: layer_vnops.c,v 1.35.10.3 2010/08/11 22:54:47 yamt Exp $");
    174        1.1  wrstuden 
    175        1.1  wrstuden #include <sys/param.h>
    176        1.1  wrstuden #include <sys/systm.h>
    177        1.1  wrstuden #include <sys/proc.h>
    178        1.1  wrstuden #include <sys/time.h>
    179        1.1  wrstuden #include <sys/vnode.h>
    180        1.1  wrstuden #include <sys/mount.h>
    181        1.1  wrstuden #include <sys/namei.h>
    182       1.34        ad #include <sys/kmem.h>
    183        1.1  wrstuden #include <sys/buf.h>
    184       1.27      elad #include <sys/kauth.h>
    185       1.27      elad 
    186        1.1  wrstuden #include <miscfs/genfs/layer.h>
    187        1.1  wrstuden #include <miscfs/genfs/layer_extern.h>
    188        1.1  wrstuden #include <miscfs/genfs/genfs.h>
    189        1.1  wrstuden 
    190        1.1  wrstuden /*
    191        1.1  wrstuden  * This is the 08-June-99 bypass routine, based on the 10-Apr-92 bypass
    192        1.1  wrstuden  *		routine by John Heidemann.
    193        1.1  wrstuden  *	The new element for this version is that the whole nullfs
    194  1.35.10.3      yamt  * system gained the concept of locks on the lower node.
    195        1.1  wrstuden  *    The 10-Apr-92 version was optimized for speed, throwing away some
    196        1.1  wrstuden  * safety checks.  It should still always work, but it's not as
    197        1.1  wrstuden  * robust to programmer errors.
    198        1.1  wrstuden  *
    199        1.1  wrstuden  * In general, we map all vnodes going down and unmap them on the way back.
    200        1.1  wrstuden  *
    201        1.1  wrstuden  * Also, some BSD vnode operations have the side effect of vrele'ing
    202        1.1  wrstuden  * their arguments.  With stacking, the reference counts are held
    203        1.1  wrstuden  * by the upper node, not the lower one, so we must handle these
    204        1.1  wrstuden  * side-effects here.  This is not of concern in Sun-derived systems
    205        1.1  wrstuden  * since there are no such side-effects.
    206        1.1  wrstuden  *
    207        1.1  wrstuden  * New for the 08-June-99 version: we also handle operations which unlock
    208        1.1  wrstuden  * the passed-in node (typically they vput the node).
    209        1.1  wrstuden  *
    210        1.1  wrstuden  * This makes the following assumptions:
    211        1.1  wrstuden  * - only one returned vpp
    212        1.1  wrstuden  * - no INOUT vpp's (Sun's vop_open has one of these)
    213        1.1  wrstuden  * - the vnode operation vector of the first vnode should be used
    214        1.1  wrstuden  *   to determine what implementation of the op should be invoked
    215        1.1  wrstuden  * - all mapped vnodes are of our vnode-type (NEEDSWORK:
    216        1.1  wrstuden  *   problems on rmdir'ing mount points and renaming?)
    217       1.24     perry  */
    218        1.1  wrstuden int
    219  1.35.10.1      yamt layer_bypass(void *v)
    220        1.1  wrstuden {
    221        1.1  wrstuden 	struct vop_generic_args /* {
    222        1.1  wrstuden 		struct vnodeop_desc *a_desc;
    223        1.1  wrstuden 		<other random data follows, presumably>
    224        1.1  wrstuden 	} */ *ap = v;
    225       1.25   xtraeme 	int (**our_vnodeop_p)(void *);
    226        1.3  augustss 	struct vnode **this_vp_p;
    227  1.35.10.3      yamt 	int error;
    228        1.1  wrstuden 	struct vnode *old_vps[VDESC_MAX_VPS], *vp0;
    229        1.1  wrstuden 	struct vnode **vps_p[VDESC_MAX_VPS];
    230        1.1  wrstuden 	struct vnode ***vppp;
    231       1.33    dyoung 	struct mount *mp;
    232        1.1  wrstuden 	struct vnodeop_desc *descp = ap->a_desc;
    233        1.1  wrstuden 	int reles, i, flags;
    234        1.1  wrstuden 
    235  1.35.10.1      yamt #ifdef DIAGNOSTIC
    236        1.1  wrstuden 	/*
    237        1.1  wrstuden 	 * We require at least one vp.
    238        1.1  wrstuden 	 */
    239        1.1  wrstuden 	if (descp->vdesc_vp_offsets == NULL ||
    240        1.1  wrstuden 	    descp->vdesc_vp_offsets[0] == VDESC_NO_OFFSET)
    241       1.20      yamt 		panic("%s: no vp's in map.\n", __func__);
    242        1.1  wrstuden #endif
    243        1.1  wrstuden 
    244       1.20      yamt 	vps_p[0] =
    245       1.20      yamt 	    VOPARG_OFFSETTO(struct vnode**, descp->vdesc_vp_offsets[0], ap);
    246        1.1  wrstuden 	vp0 = *vps_p[0];
    247       1.33    dyoung 	mp = vp0->v_mount;
    248       1.33    dyoung 	flags = MOUNTTOLAYERMOUNT(mp)->layerm_flags;
    249        1.1  wrstuden 	our_vnodeop_p = vp0->v_op;
    250        1.1  wrstuden 
    251        1.1  wrstuden 	if (flags & LAYERFS_MBYPASSDEBUG)
    252       1.20      yamt 		printf("%s: %s\n", __func__, descp->vdesc_name);
    253        1.1  wrstuden 
    254        1.1  wrstuden 	/*
    255        1.1  wrstuden 	 * Map the vnodes going in.
    256        1.1  wrstuden 	 * Later, we'll invoke the operation based on
    257        1.1  wrstuden 	 * the first mapped vnode's operation vector.
    258        1.1  wrstuden 	 */
    259        1.1  wrstuden 	reles = descp->vdesc_flags;
    260        1.1  wrstuden 	for (i = 0; i < VDESC_MAX_VPS; reles >>= 1, i++) {
    261        1.1  wrstuden 		if (descp->vdesc_vp_offsets[i] == VDESC_NO_OFFSET)
    262        1.1  wrstuden 			break;   /* bail out at end of list */
    263       1.24     perry 		vps_p[i] = this_vp_p =
    264       1.20      yamt 		    VOPARG_OFFSETTO(struct vnode**, descp->vdesc_vp_offsets[i],
    265       1.20      yamt 		    ap);
    266        1.1  wrstuden 		/*
    267        1.1  wrstuden 		 * We're not guaranteed that any but the first vnode
    268        1.1  wrstuden 		 * are of our type.  Check for and don't map any
    269        1.1  wrstuden 		 * that aren't.  (We must always map first vp or vclean fails.)
    270        1.1  wrstuden 		 */
    271        1.1  wrstuden 		if (i && (*this_vp_p == NULL ||
    272        1.1  wrstuden 		    (*this_vp_p)->v_op != our_vnodeop_p)) {
    273        1.1  wrstuden 			old_vps[i] = NULL;
    274        1.1  wrstuden 		} else {
    275        1.1  wrstuden 			old_vps[i] = *this_vp_p;
    276        1.1  wrstuden 			*(vps_p[i]) = LAYERVPTOLOWERVP(*this_vp_p);
    277        1.1  wrstuden 			/*
    278        1.1  wrstuden 			 * XXX - Several operations have the side effect
    279        1.1  wrstuden 			 * of vrele'ing their vp's.  We must account for
    280        1.1  wrstuden 			 * that.  (This should go away in the future.)
    281        1.1  wrstuden 			 */
    282        1.1  wrstuden 			if (reles & VDESC_VP0_WILLRELE)
    283  1.35.10.2      yamt 				vref(*this_vp_p);
    284        1.1  wrstuden 		}
    285        1.1  wrstuden 	}
    286        1.1  wrstuden 
    287        1.1  wrstuden 	/*
    288        1.1  wrstuden 	 * Call the operation on the lower layer
    289        1.1  wrstuden 	 * with the modified argument structure.
    290        1.1  wrstuden 	 */
    291        1.1  wrstuden 	error = VCALL(*vps_p[0], descp->vdesc_offset, ap);
    292        1.1  wrstuden 
    293        1.1  wrstuden 	/*
    294        1.1  wrstuden 	 * Maintain the illusion of call-by-value
    295        1.1  wrstuden 	 * by restoring vnodes in the argument structure
    296        1.1  wrstuden 	 * to their original value.
    297        1.1  wrstuden 	 */
    298        1.1  wrstuden 	reles = descp->vdesc_flags;
    299        1.1  wrstuden 	for (i = 0; i < VDESC_MAX_VPS; reles >>= 1, i++) {
    300        1.1  wrstuden 		if (descp->vdesc_vp_offsets[i] == VDESC_NO_OFFSET)
    301        1.1  wrstuden 			break;   /* bail out at end of list */
    302        1.1  wrstuden 		if (old_vps[i]) {
    303        1.1  wrstuden 			*(vps_p[i]) = old_vps[i];
    304        1.1  wrstuden 			if (reles & VDESC_VP0_WILLRELE)
    305        1.1  wrstuden 				vrele(*(vps_p[i]));
    306        1.1  wrstuden 		}
    307        1.1  wrstuden 	}
    308        1.1  wrstuden 
    309        1.1  wrstuden 	/*
    310        1.1  wrstuden 	 * Map the possible out-going vpp
    311        1.1  wrstuden 	 * (Assumes that the lower layer always returns
    312        1.1  wrstuden 	 * a VREF'ed vpp unless it gets an error.)
    313        1.1  wrstuden 	 */
    314        1.1  wrstuden 	if (descp->vdesc_vpp_offset != VDESC_NO_OFFSET &&
    315        1.1  wrstuden 	    !(descp->vdesc_flags & VDESC_NOMAP_VPP) &&
    316        1.1  wrstuden 	    !error) {
    317        1.1  wrstuden 		/*
    318        1.1  wrstuden 		 * XXX - even though some ops have vpp returned vp's,
    319        1.1  wrstuden 		 * several ops actually vrele this before returning.
    320        1.1  wrstuden 		 * We must avoid these ops.
    321        1.1  wrstuden 		 * (This should go away when these ops are regularized.)
    322        1.1  wrstuden 		 */
    323        1.1  wrstuden 		if (descp->vdesc_flags & VDESC_VPP_WILLRELE)
    324        1.1  wrstuden 			goto out;
    325        1.1  wrstuden 		vppp = VOPARG_OFFSETTO(struct vnode***,
    326       1.20      yamt 				 descp->vdesc_vpp_offset, ap);
    327        1.1  wrstuden 		/*
    328        1.1  wrstuden 		 * Only vop_lookup, vop_create, vop_makedir, vop_bmap,
    329        1.7     assar 		 * vop_mknod, and vop_symlink return vpp's. vop_bmap
    330        1.1  wrstuden 		 * doesn't call bypass as the lower vpp is fine (we're just
    331       1.20      yamt 		 * going to do i/o on it). vop_lookup doesn't call bypass
    332        1.1  wrstuden 		 * as a lookup on "." would generate a locking error.
    333        1.1  wrstuden 		 * So all the calls which get us here have a locked vpp. :-)
    334        1.1  wrstuden 		 */
    335       1.33    dyoung 		error = layer_node_create(mp, **vppp, *vppp);
    336       1.19      yamt 		if (error) {
    337       1.19      yamt 			vput(**vppp);
    338       1.19      yamt 			**vppp = NULL;
    339       1.19      yamt 		}
    340        1.1  wrstuden 	}
    341  1.35.10.3      yamt out:
    342  1.35.10.3      yamt 	return error;
    343        1.1  wrstuden }
    344        1.1  wrstuden 
    345        1.1  wrstuden /*
    346        1.1  wrstuden  * We have to carry on the locking protocol on the layer vnodes
    347        1.1  wrstuden  * as we progress through the tree. We also have to enforce read-only
    348        1.1  wrstuden  * if this layer is mounted read-only.
    349        1.1  wrstuden  */
    350        1.1  wrstuden int
    351  1.35.10.1      yamt layer_lookup(void *v)
    352        1.1  wrstuden {
    353        1.1  wrstuden 	struct vop_lookup_args /* {
    354        1.1  wrstuden 		struct vnodeop_desc *a_desc;
    355        1.1  wrstuden 		struct vnode * a_dvp;
    356        1.1  wrstuden 		struct vnode ** a_vpp;
    357        1.1  wrstuden 		struct componentname * a_cnp;
    358        1.1  wrstuden 	} */ *ap = v;
    359        1.1  wrstuden 	struct componentname *cnp = ap->a_cnp;
    360       1.29       chs 	struct vnode *dvp, *lvp, *ldvp;
    361  1.35.10.3      yamt 	int error, flags = cnp->cn_flags;
    362        1.1  wrstuden 
    363        1.1  wrstuden 	dvp = ap->a_dvp;
    364        1.1  wrstuden 
    365        1.1  wrstuden 	if ((flags & ISLASTCN) && (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
    366        1.1  wrstuden 	    (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
    367  1.35.10.3      yamt 		return EROFS;
    368        1.1  wrstuden 
    369        1.1  wrstuden 	ldvp = LAYERVPTOLOWERVP(dvp);
    370        1.1  wrstuden 	ap->a_dvp = ldvp;
    371        1.1  wrstuden 	error = VCALL(ldvp, ap->a_desc->vdesc_offset, ap);
    372       1.29       chs 	lvp = *ap->a_vpp;
    373       1.18      yamt 	*ap->a_vpp = NULL;
    374        1.1  wrstuden 
    375        1.1  wrstuden 	if (error == EJUSTRETURN && (flags & ISLASTCN) &&
    376        1.1  wrstuden 	    (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
    377        1.1  wrstuden 	    (cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME))
    378        1.1  wrstuden 		error = EROFS;
    379       1.29       chs 
    380        1.1  wrstuden 	/*
    381       1.24     perry 	 * We must do the same locking and unlocking at this layer as
    382       1.29       chs 	 * is done in the layers below us.
    383        1.1  wrstuden 	 */
    384       1.29       chs 	if (ldvp == lvp) {
    385        1.1  wrstuden 		/*
    386  1.35.10.1      yamt 		 * Got the same object back, because we looked up ".",
    387  1.35.10.1      yamt 		 * or ".." in the root node of a mount point.
    388  1.35.10.1      yamt 		 * So we make another reference to dvp and return it.
    389        1.1  wrstuden 		 */
    390  1.35.10.2      yamt 		vref(dvp);
    391        1.1  wrstuden 		*ap->a_vpp = dvp;
    392       1.29       chs 		vrele(lvp);
    393       1.29       chs 	} else if (lvp != NULL) {
    394  1.35.10.3      yamt 		/* Note: dvp, ldvp and lvp are all locked. */
    395       1.29       chs 		error = layer_node_create(dvp->v_mount, lvp, ap->a_vpp);
    396       1.19      yamt 		if (error) {
    397       1.29       chs 			vput(lvp);
    398       1.19      yamt 		}
    399        1.1  wrstuden 	}
    400  1.35.10.3      yamt 	return error;
    401        1.1  wrstuden }
    402        1.1  wrstuden 
    403        1.1  wrstuden /*
    404        1.1  wrstuden  * Setattr call. Disallow write attempts if the layer is mounted read-only.
    405        1.1  wrstuden  */
    406        1.1  wrstuden int
    407  1.35.10.1      yamt layer_setattr(void *v)
    408        1.1  wrstuden {
    409        1.1  wrstuden 	struct vop_setattr_args /* {
    410        1.1  wrstuden 		struct vnodeop_desc *a_desc;
    411        1.1  wrstuden 		struct vnode *a_vp;
    412        1.1  wrstuden 		struct vattr *a_vap;
    413       1.27      elad 		kauth_cred_t a_cred;
    414       1.26  christos 		struct lwp *a_l;
    415        1.1  wrstuden 	} */ *ap = v;
    416        1.1  wrstuden 	struct vnode *vp = ap->a_vp;
    417        1.1  wrstuden 	struct vattr *vap = ap->a_vap;
    418        1.1  wrstuden 
    419        1.1  wrstuden   	if ((vap->va_flags != VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
    420        1.1  wrstuden 	    vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
    421        1.1  wrstuden 	    vap->va_mtime.tv_sec != VNOVAL || vap->va_mode != (mode_t)VNOVAL) &&
    422        1.1  wrstuden 	    (vp->v_mount->mnt_flag & MNT_RDONLY))
    423  1.35.10.3      yamt 		return EROFS;
    424        1.1  wrstuden 	if (vap->va_size != VNOVAL) {
    425        1.1  wrstuden  		switch (vp->v_type) {
    426        1.1  wrstuden  		case VDIR:
    427  1.35.10.3      yamt  			return EISDIR;
    428        1.1  wrstuden  		case VCHR:
    429        1.1  wrstuden  		case VBLK:
    430        1.1  wrstuden  		case VSOCK:
    431        1.1  wrstuden  		case VFIFO:
    432  1.35.10.3      yamt 			return 0;
    433        1.1  wrstuden 		case VREG:
    434        1.1  wrstuden 		case VLNK:
    435        1.1  wrstuden  		default:
    436        1.1  wrstuden 			/*
    437        1.1  wrstuden 			 * Disallow write attempts if the filesystem is
    438        1.1  wrstuden 			 * mounted read-only.
    439        1.1  wrstuden 			 */
    440        1.1  wrstuden 			if (vp->v_mount->mnt_flag & MNT_RDONLY)
    441  1.35.10.3      yamt 				return EROFS;
    442        1.1  wrstuden 		}
    443        1.1  wrstuden 	}
    444  1.35.10.3      yamt 	return LAYERFS_DO_BYPASS(vp, ap);
    445        1.1  wrstuden }
    446        1.1  wrstuden 
    447        1.1  wrstuden /*
    448        1.1  wrstuden  *  We handle getattr only to change the fsid.
    449        1.1  wrstuden  */
    450        1.1  wrstuden int
    451  1.35.10.1      yamt layer_getattr(void *v)
    452        1.1  wrstuden {
    453        1.1  wrstuden 	struct vop_getattr_args /* {
    454        1.1  wrstuden 		struct vnode *a_vp;
    455        1.1  wrstuden 		struct vattr *a_vap;
    456       1.27      elad 		kauth_cred_t a_cred;
    457       1.26  christos 		struct lwp *a_l;
    458        1.1  wrstuden 	} */ *ap = v;
    459        1.1  wrstuden 	struct vnode *vp = ap->a_vp;
    460        1.1  wrstuden 	int error;
    461        1.1  wrstuden 
    462  1.35.10.3      yamt 	error = LAYERFS_DO_BYPASS(vp, ap);
    463  1.35.10.3      yamt 	if (error) {
    464  1.35.10.3      yamt 		return error;
    465  1.35.10.3      yamt 	}
    466        1.1  wrstuden 	/* Requires that arguments be restored. */
    467       1.15  christos 	ap->a_vap->va_fsid = vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0];
    468  1.35.10.3      yamt 	return 0;
    469        1.1  wrstuden }
    470        1.1  wrstuden 
    471        1.1  wrstuden int
    472  1.35.10.1      yamt layer_access(void *v)
    473        1.1  wrstuden {
    474        1.1  wrstuden 	struct vop_access_args /* {
    475        1.1  wrstuden 		struct vnode *a_vp;
    476        1.1  wrstuden 		int  a_mode;
    477       1.27      elad 		kauth_cred_t a_cred;
    478       1.26  christos 		struct lwp *a_l;
    479        1.1  wrstuden 	} */ *ap = v;
    480        1.1  wrstuden 	struct vnode *vp = ap->a_vp;
    481        1.1  wrstuden 	mode_t mode = ap->a_mode;
    482        1.1  wrstuden 
    483        1.1  wrstuden 	/*
    484        1.1  wrstuden 	 * Disallow write attempts on read-only layers;
    485        1.1  wrstuden 	 * unless the file is a socket, fifo, or a block or
    486        1.1  wrstuden 	 * character device resident on the file system.
    487        1.1  wrstuden 	 */
    488        1.1  wrstuden 	if (mode & VWRITE) {
    489        1.1  wrstuden 		switch (vp->v_type) {
    490        1.1  wrstuden 		case VDIR:
    491        1.1  wrstuden 		case VLNK:
    492        1.1  wrstuden 		case VREG:
    493        1.1  wrstuden 			if (vp->v_mount->mnt_flag & MNT_RDONLY)
    494  1.35.10.3      yamt 				return EROFS;
    495        1.1  wrstuden 			break;
    496        1.1  wrstuden 		default:
    497        1.1  wrstuden 			break;
    498        1.1  wrstuden 		}
    499        1.1  wrstuden 	}
    500  1.35.10.3      yamt 	return LAYERFS_DO_BYPASS(vp, ap);
    501        1.1  wrstuden }
    502        1.1  wrstuden 
    503        1.1  wrstuden /*
    504        1.1  wrstuden  * We must handle open to be able to catch MNT_NODEV and friends.
    505        1.1  wrstuden  */
    506        1.1  wrstuden int
    507  1.35.10.1      yamt layer_open(void *v)
    508        1.1  wrstuden {
    509  1.35.10.3      yamt 	struct vop_open_args /* {
    510  1.35.10.3      yamt 		const struct vnodeop_desc *a_desc;
    511  1.35.10.3      yamt 		struct vnode *a_vp;
    512  1.35.10.3      yamt 		int a_mode;
    513  1.35.10.3      yamt 		kauth_cred_t a_cred;
    514  1.35.10.3      yamt 	} */ *ap = v;
    515        1.1  wrstuden 	struct vnode *vp = ap->a_vp;
    516        1.1  wrstuden 	enum vtype lower_type = LAYERVPTOLOWERVP(vp)->v_type;
    517        1.1  wrstuden 
    518        1.1  wrstuden 	if (((lower_type == VBLK) || (lower_type == VCHR)) &&
    519        1.1  wrstuden 	    (vp->v_mount->mnt_flag & MNT_NODEV))
    520        1.1  wrstuden 		return ENXIO;
    521        1.1  wrstuden 
    522        1.1  wrstuden 	return LAYERFS_DO_BYPASS(vp, ap);
    523        1.1  wrstuden }
    524        1.1  wrstuden 
    525        1.1  wrstuden /*
    526        1.1  wrstuden  * If vinvalbuf is calling us, it's a "shallow fsync" -- don't bother
    527        1.1  wrstuden  * syncing the underlying vnodes, since they'll be fsync'ed when
    528  1.35.10.3      yamt  * reclaimed; otherwise, pass it through to the underlying layer.
    529        1.1  wrstuden  *
    530        1.1  wrstuden  * XXX Do we still need to worry about shallow fsync?
    531        1.1  wrstuden  */
    532        1.1  wrstuden int
    533  1.35.10.1      yamt layer_fsync(void *v)
    534        1.1  wrstuden {
    535        1.1  wrstuden 	struct vop_fsync_args /* {
    536        1.1  wrstuden 		struct vnode *a_vp;
    537       1.27      elad 		kauth_cred_t a_cred;
    538        1.1  wrstuden 		int  a_flags;
    539        1.4      fvdl 		off_t offlo;
    540        1.4      fvdl 		off_t offhi;
    541       1.26  christos 		struct lwp *a_l;
    542        1.1  wrstuden 	} */ *ap = v;
    543        1.1  wrstuden 
    544        1.1  wrstuden 	if (ap->a_flags & FSYNC_RECLAIM) {
    545        1.1  wrstuden 		return 0;
    546        1.1  wrstuden 	}
    547  1.35.10.3      yamt 	return LAYERFS_DO_BYPASS(ap->a_vp, ap);
    548        1.1  wrstuden }
    549        1.1  wrstuden 
    550        1.1  wrstuden int
    551  1.35.10.1      yamt layer_inactive(void *v)
    552        1.1  wrstuden {
    553        1.1  wrstuden 	struct vop_inactive_args /* {
    554        1.1  wrstuden 		struct vnode *a_vp;
    555       1.34        ad 		bool *a_recycle;
    556        1.1  wrstuden 	} */ *ap = v;
    557        1.5     enami 	struct vnode *vp = ap->a_vp;
    558        1.1  wrstuden 
    559        1.1  wrstuden 	/*
    560       1.34        ad 	 * ..., but don't cache the device node. Also, if we did a
    561       1.34        ad 	 * remove, don't cache the node.
    562       1.34        ad 	 */
    563       1.34        ad 	*ap->a_recycle = (vp->v_type == VBLK || vp->v_type == VCHR
    564       1.34        ad 	    || (VTOLAYER(vp)->layer_flags & LAYERFS_REMOVED));
    565       1.34        ad 
    566       1.34        ad 	/*
    567        1.1  wrstuden 	 * Do nothing (and _don't_ bypass).
    568        1.1  wrstuden 	 * Wait to vrele lowervp until reclaim,
    569        1.1  wrstuden 	 * so that until then our layer_node is in the
    570        1.1  wrstuden 	 * cache and reusable.
    571        1.1  wrstuden 	 *
    572        1.1  wrstuden 	 * NEEDSWORK: Someday, consider inactive'ing
    573        1.1  wrstuden 	 * the lowervp and then trying to reactivate it
    574        1.1  wrstuden 	 * with capabilities (v_id)
    575        1.1  wrstuden 	 * like they do in the name lookup cache code.
    576        1.1  wrstuden 	 * That's too much work for now.
    577        1.1  wrstuden 	 */
    578  1.35.10.3      yamt 	VOP_UNLOCK(vp);
    579  1.35.10.3      yamt 	return 0;
    580        1.1  wrstuden }
    581        1.1  wrstuden 
    582        1.1  wrstuden int
    583  1.35.10.1      yamt layer_remove(void *v)
    584       1.16  wrstuden {
    585       1.16  wrstuden 	struct vop_remove_args /* {
    586       1.16  wrstuden 		struct vonde		*a_dvp;
    587       1.16  wrstuden 		struct vnode		*a_vp;
    588       1.16  wrstuden 		struct componentname	*a_cnp;
    589       1.16  wrstuden 	} */ *ap = v;
    590  1.35.10.3      yamt 	struct vnode *vp = ap->a_vp;
    591  1.35.10.3      yamt 	int error;
    592       1.16  wrstuden 
    593       1.16  wrstuden 	vref(vp);
    594  1.35.10.3      yamt 	error = LAYERFS_DO_BYPASS(vp, ap);
    595  1.35.10.3      yamt 	if (error == 0) {
    596       1.16  wrstuden 		VTOLAYER(vp)->layer_flags |= LAYERFS_REMOVED;
    597  1.35.10.3      yamt 	}
    598       1.16  wrstuden 	vrele(vp);
    599       1.16  wrstuden 
    600  1.35.10.3      yamt 	return error;
    601       1.16  wrstuden }
    602       1.16  wrstuden 
    603       1.16  wrstuden int
    604  1.35.10.1      yamt layer_rename(void *v)
    605       1.17      yamt {
    606       1.17      yamt 	struct vop_rename_args  /* {
    607       1.17      yamt 		struct vnode		*a_fdvp;
    608       1.17      yamt 		struct vnode		*a_fvp;
    609       1.17      yamt 		struct componentname	*a_fcnp;
    610       1.17      yamt 		struct vnode		*a_tdvp;
    611       1.17      yamt 		struct vnode		*a_tvp;
    612       1.17      yamt 		struct componentname	*a_tcnp;
    613       1.17      yamt 	} */ *ap = v;
    614  1.35.10.3      yamt 	struct vnode *fdvp = ap->a_fdvp, *tvp;
    615       1.17      yamt 	int error;
    616       1.17      yamt 
    617       1.17      yamt 	tvp = ap->a_tvp;
    618       1.17      yamt 	if (tvp) {
    619       1.17      yamt 		if (tvp->v_mount != fdvp->v_mount)
    620       1.17      yamt 			tvp = NULL;
    621       1.17      yamt 		else
    622       1.17      yamt 			vref(tvp);
    623       1.17      yamt 	}
    624       1.17      yamt 	error = LAYERFS_DO_BYPASS(fdvp, ap);
    625       1.17      yamt 	if (tvp) {
    626       1.17      yamt 		if (error == 0)
    627       1.17      yamt 			VTOLAYER(tvp)->layer_flags |= LAYERFS_REMOVED;
    628       1.17      yamt 		vrele(tvp);
    629       1.17      yamt 	}
    630  1.35.10.3      yamt 	return error;
    631       1.17      yamt }
    632       1.17      yamt 
    633       1.17      yamt int
    634  1.35.10.1      yamt layer_rmdir(void *v)
    635       1.23   hannken {
    636       1.23   hannken 	struct vop_rmdir_args /* {
    637       1.23   hannken 		struct vnode		*a_dvp;
    638       1.23   hannken 		struct vnode		*a_vp;
    639       1.23   hannken 		struct componentname	*a_cnp;
    640       1.23   hannken 	} */ *ap = v;
    641       1.23   hannken 	int		error;
    642       1.23   hannken 	struct vnode	*vp = ap->a_vp;
    643       1.23   hannken 
    644       1.23   hannken 	vref(vp);
    645  1.35.10.3      yamt 	error = LAYERFS_DO_BYPASS(vp, ap);
    646  1.35.10.3      yamt 	if (error == 0) {
    647       1.23   hannken 		VTOLAYER(vp)->layer_flags |= LAYERFS_REMOVED;
    648  1.35.10.3      yamt 	}
    649       1.23   hannken 	vrele(vp);
    650       1.23   hannken 
    651  1.35.10.3      yamt 	return error;
    652       1.23   hannken }
    653       1.23   hannken 
    654       1.23   hannken int
    655  1.35.10.1      yamt layer_reclaim(void *v)
    656        1.1  wrstuden {
    657        1.1  wrstuden 	struct vop_reclaim_args /* {
    658        1.1  wrstuden 		struct vnode *a_vp;
    659       1.26  christos 		struct lwp *a_l;
    660        1.1  wrstuden 	} */ *ap = v;
    661        1.1  wrstuden 	struct vnode *vp = ap->a_vp;
    662        1.1  wrstuden 	struct layer_mount *lmp = MOUNTTOLAYERMOUNT(vp->v_mount);
    663        1.1  wrstuden 	struct layer_node *xp = VTOLAYER(vp);
    664        1.1  wrstuden 	struct vnode *lowervp = xp->layer_lowervp;
    665        1.1  wrstuden 
    666        1.1  wrstuden 	/*
    667        1.1  wrstuden 	 * Note: in vop_reclaim, the node's struct lock has been
    668        1.1  wrstuden 	 * decomissioned, so we have to be careful about calling
    669       1.34        ad 	 * VOP's on ourself.  We must be careful as VXLOCK is set.
    670        1.1  wrstuden 	 */
    671  1.35.10.3      yamt 	if (vp == lmp->layerm_rootvp) {
    672        1.1  wrstuden 		/*
    673        1.1  wrstuden 		 * Oops! We no longer have a root node. Most likely reason is
    674        1.1  wrstuden 		 * that someone forcably unmunted the underlying fs.
    675        1.1  wrstuden 		 *
    676        1.1  wrstuden 		 * Now getting the root vnode will fail. We're dead. :-(
    677        1.1  wrstuden 		 */
    678        1.1  wrstuden 		lmp->layerm_rootvp = NULL;
    679        1.1  wrstuden 	}
    680  1.35.10.3      yamt 	/* After this assignment, this node will not be re-used. */
    681        1.1  wrstuden 	xp->layer_lowervp = NULL;
    682       1.32        ad 	mutex_enter(&lmp->layerm_hashlock);
    683        1.1  wrstuden 	LIST_REMOVE(xp, layer_hash);
    684       1.32        ad 	mutex_exit(&lmp->layerm_hashlock);
    685       1.34        ad 	kmem_free(vp->v_data, lmp->layerm_size);
    686        1.1  wrstuden 	vp->v_data = NULL;
    687       1.29       chs 	vrele(lowervp);
    688       1.34        ad 
    689  1.35.10.3      yamt 	return 0;
    690        1.1  wrstuden }
    691        1.1  wrstuden 
    692        1.1  wrstuden /*
    693        1.1  wrstuden  * We just feed the returned vnode up to the caller - there's no need
    694        1.1  wrstuden  * to build a layer node on top of the node on which we're going to do
    695        1.1  wrstuden  * i/o. :-)
    696        1.1  wrstuden  */
    697        1.1  wrstuden int
    698  1.35.10.1      yamt layer_bmap(void *v)
    699        1.1  wrstuden {
    700        1.1  wrstuden 	struct vop_bmap_args /* {
    701        1.1  wrstuden 		struct vnode *a_vp;
    702        1.1  wrstuden 		daddr_t  a_bn;
    703        1.1  wrstuden 		struct vnode **a_vpp;
    704        1.1  wrstuden 		daddr_t *a_bnp;
    705        1.1  wrstuden 		int *a_runp;
    706        1.1  wrstuden 	} */ *ap = v;
    707        1.1  wrstuden 	struct vnode *vp;
    708        1.1  wrstuden 
    709  1.35.10.3      yamt 	vp = LAYERVPTOLOWERVP(ap->a_vp);
    710  1.35.10.3      yamt 	ap->a_vp = vp;
    711        1.1  wrstuden 
    712  1.35.10.3      yamt 	return VCALL(vp, ap->a_desc->vdesc_offset, ap);
    713        1.1  wrstuden }
    714        1.1  wrstuden 
    715        1.1  wrstuden int
    716  1.35.10.1      yamt layer_print(void *v)
    717        1.1  wrstuden {
    718        1.1  wrstuden 	struct vop_print_args /* {
    719        1.1  wrstuden 		struct vnode *a_vp;
    720        1.1  wrstuden 	} */ *ap = v;
    721        1.3  augustss 	struct vnode *vp = ap->a_vp;
    722        1.1  wrstuden 	printf ("\ttag VT_LAYERFS, vp=%p, lowervp=%p\n", vp, LAYERVPTOLOWERVP(vp));
    723  1.35.10.3      yamt 	return 0;
    724        1.1  wrstuden }
    725        1.1  wrstuden 
    726        1.1  wrstuden /*
    727       1.14   hannken  * XXX - vop_bwrite must be hand coded because it has no
    728        1.1  wrstuden  * vnode in its arguments.
    729        1.1  wrstuden  * This goes away with a merged VM/buffer cache.
    730        1.1  wrstuden  */
    731        1.1  wrstuden int
    732  1.35.10.1      yamt layer_bwrite(void *v)
    733        1.1  wrstuden {
    734        1.1  wrstuden 	struct vop_bwrite_args /* {
    735        1.1  wrstuden 		struct buf *a_bp;
    736        1.1  wrstuden 	} */ *ap = v;
    737        1.1  wrstuden 	struct buf *bp = ap->a_bp;
    738        1.1  wrstuden 	struct vnode *savedvp;
    739  1.35.10.3      yamt 	int error;
    740        1.1  wrstuden 
    741        1.1  wrstuden 	savedvp = bp->b_vp;
    742        1.1  wrstuden 	bp->b_vp = LAYERVPTOLOWERVP(bp->b_vp);
    743        1.1  wrstuden 	error = VOP_BWRITE(bp);
    744        1.1  wrstuden 	bp->b_vp = savedvp;
    745        1.1  wrstuden 
    746  1.35.10.3      yamt 	return error;
    747       1.10       chs }
    748       1.10       chs 
    749       1.10       chs int
    750  1.35.10.1      yamt layer_getpages(void *v)
    751       1.10       chs {
    752       1.10       chs 	struct vop_getpages_args /* {
    753       1.10       chs 		struct vnode *a_vp;
    754       1.10       chs 		voff_t a_offset;
    755       1.10       chs 		struct vm_page **a_m;
    756       1.10       chs 		int *a_count;
    757       1.10       chs 		int a_centeridx;
    758       1.10       chs 		vm_prot_t a_access_type;
    759       1.10       chs 		int a_advice;
    760       1.10       chs 		int a_flags;
    761       1.10       chs 	} */ *ap = v;
    762       1.10       chs 	struct vnode *vp = ap->a_vp;
    763       1.10       chs 	int error;
    764       1.10       chs 
    765       1.10       chs 	/*
    766       1.10       chs 	 * just pass the request on to the underlying layer.
    767       1.10       chs 	 */
    768       1.10       chs 
    769       1.10       chs 	if (ap->a_flags & PGO_LOCKED) {
    770       1.10       chs 		return EBUSY;
    771       1.10       chs 	}
    772       1.10       chs 	ap->a_vp = LAYERVPTOLOWERVP(vp);
    773       1.34        ad 	mutex_exit(&vp->v_interlock);
    774       1.34        ad 	mutex_enter(&ap->a_vp->v_interlock);
    775       1.10       chs 	error = VCALL(ap->a_vp, VOFFSET(vop_getpages), ap);
    776       1.10       chs 	return error;
    777       1.10       chs }
    778       1.10       chs 
    779       1.10       chs int
    780  1.35.10.1      yamt layer_putpages(void *v)
    781       1.10       chs {
    782       1.10       chs 	struct vop_putpages_args /* {
    783       1.10       chs 		struct vnode *a_vp;
    784       1.10       chs 		voff_t a_offlo;
    785       1.10       chs 		voff_t a_offhi;
    786       1.10       chs 		int a_flags;
    787       1.10       chs 	} */ *ap = v;
    788       1.10       chs 	struct vnode *vp = ap->a_vp;
    789       1.10       chs 	int error;
    790       1.10       chs 
    791       1.10       chs 	/*
    792       1.10       chs 	 * just pass the request on to the underlying layer.
    793       1.10       chs 	 */
    794       1.10       chs 
    795       1.10       chs 	ap->a_vp = LAYERVPTOLOWERVP(vp);
    796       1.34        ad 	mutex_exit(&vp->v_interlock);
    797       1.30       chs 	if (ap->a_flags & PGO_RECLAIM) {
    798       1.30       chs 		return 0;
    799       1.30       chs 	}
    800       1.34        ad 	mutex_enter(&ap->a_vp->v_interlock);
    801       1.10       chs 	error = VCALL(ap->a_vp, VOFFSET(vop_putpages), ap);
    802       1.10       chs 	return error;
    803        1.1  wrstuden }
    804