Home | History | Annotate | Line # | Download | only in genfs
layer_subr.c revision 1.35.2.1
      1  1.35.2.1       tls /*	$NetBSD: layer_subr.c,v 1.35.2.1 2014/08/10 06:56:05 tls 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.8       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.5     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.30     rmind 
     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 donated to Berkeley by
     41       1.1  wrstuden  * Jan-Simon Pendry.
     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.15       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  *	from: Id: lofs_subr.c,v 1.11 1992/05/30 10:05:43 jsp Exp
     68       1.1  wrstuden  *	@(#)null_subr.c	8.7 (Berkeley) 5/14/95
     69       1.1  wrstuden  */
     70       1.9     lukem 
     71       1.9     lukem #include <sys/cdefs.h>
     72  1.35.2.1       tls __KERNEL_RCSID(0, "$NetBSD: layer_subr.c,v 1.35.2.1 2014/08/10 06:56:05 tls Exp $");
     73       1.1  wrstuden 
     74       1.1  wrstuden #include <sys/param.h>
     75       1.1  wrstuden #include <sys/systm.h>
     76       1.1  wrstuden #include <sys/proc.h>
     77       1.1  wrstuden #include <sys/time.h>
     78       1.1  wrstuden #include <sys/vnode.h>
     79       1.1  wrstuden #include <sys/mount.h>
     80       1.1  wrstuden #include <sys/namei.h>
     81      1.23        ad #include <sys/kmem.h>
     82       1.1  wrstuden #include <sys/malloc.h>
     83      1.23        ad 
     84       1.1  wrstuden #include <miscfs/genfs/layer.h>
     85       1.1  wrstuden #include <miscfs/genfs/layer_extern.h>
     86       1.1  wrstuden 
     87      1.16       erh #ifdef LAYERFS_DIAGNOSTIC
     88      1.16       erh int layerfs_debug = 1;
     89      1.16       erh #endif
     90      1.16       erh 
     91       1.1  wrstuden /*
     92       1.1  wrstuden  * layer cache:
     93       1.1  wrstuden  * Each cache entry holds a reference to the lower vnode
     94       1.1  wrstuden  * along with a pointer to the alias vnode.  When an
     95       1.1  wrstuden  * entry is added the lower vnode is VREF'd.  When the
     96       1.1  wrstuden  * alias is removed the lower vnode is vrele'd.
     97       1.1  wrstuden  */
     98       1.1  wrstuden 
     99       1.1  wrstuden void
    100      1.27    cegger layerfs_init(void)
    101       1.1  wrstuden {
    102      1.30     rmind 	/* Nothing. */
    103       1.6  jdolecek }
    104       1.1  wrstuden 
    105       1.6  jdolecek void
    106      1.27    cegger layerfs_done(void)
    107       1.6  jdolecek {
    108      1.30     rmind 	/* Nothing. */
    109       1.1  wrstuden }
    110       1.1  wrstuden 
    111       1.1  wrstuden /*
    112      1.30     rmind  * layer_node_create: try to find an existing layerfs vnode refering to it,
    113      1.30     rmind  * otherwise make a new vnode which contains a reference to the lower vnode.
    114       1.1  wrstuden  */
    115       1.1  wrstuden int
    116      1.30     rmind layer_node_create(struct mount *mp, struct vnode *lowervp, struct vnode **nvpp)
    117       1.1  wrstuden {
    118  1.35.2.1       tls 	int error;
    119       1.1  wrstuden 	struct vnode *aliasvp;
    120       1.1  wrstuden 
    121  1.35.2.1       tls 	error = vcache_get(mp, &lowervp, sizeof(lowervp), &aliasvp);
    122  1.35.2.1       tls 	if (error)
    123  1.35.2.1       tls 		return error;
    124       1.1  wrstuden 
    125       1.1  wrstuden 	/*
    126      1.30     rmind 	 * Now that we acquired a reference on the upper vnode, release one
    127      1.30     rmind 	 * on the lower node.  The existence of the layer_node retains one
    128       1.1  wrstuden 	 * reference to the lower node.
    129       1.1  wrstuden 	 */
    130       1.1  wrstuden 	vrele(lowervp);
    131      1.30     rmind 	KASSERT(lowervp->v_usecount > 0);
    132       1.1  wrstuden 
    133       1.1  wrstuden #ifdef LAYERFS_DIAGNOSTIC
    134      1.16       erh 	if (layerfs_debug)
    135      1.16       erh 		vprint("layer_node_create: alias", aliasvp);
    136       1.1  wrstuden #endif
    137      1.30     rmind 	*nvpp = aliasvp;
    138      1.30     rmind 	return 0;
    139       1.1  wrstuden }
    140       1.1  wrstuden 
    141      1.16       erh #ifdef LAYERFS_DIAGNOSTIC
    142       1.1  wrstuden struct vnode *
    143      1.26       dsl layer_checkvp(struct vnode *vp, const char *fil, int lno)
    144       1.1  wrstuden {
    145       1.1  wrstuden 	struct layer_node *a = VTOLAYER(vp);
    146       1.1  wrstuden #ifdef notyet
    147       1.1  wrstuden 	/*
    148       1.1  wrstuden 	 * Can't do this check because vop_reclaim runs
    149       1.1  wrstuden 	 * with a funny vop vector.
    150       1.1  wrstuden 	 *
    151       1.1  wrstuden 	 * WRS - no it doesnt...
    152       1.1  wrstuden 	 */
    153       1.1  wrstuden 	if (vp->v_op != layer_vnodeop_p) {
    154       1.1  wrstuden 		printf ("layer_checkvp: on non-layer-node\n");
    155       1.1  wrstuden #ifdef notyet
    156       1.1  wrstuden 		while (layer_checkvp_barrier) /*WAIT*/ ;
    157       1.1  wrstuden #endif
    158       1.1  wrstuden 		panic("layer_checkvp");
    159       1.1  wrstuden 	};
    160       1.1  wrstuden #endif
    161       1.1  wrstuden 	if (a->layer_lowervp == NULL) {
    162       1.1  wrstuden 		/* Should never happen */
    163       1.1  wrstuden 		int i; u_long *p;
    164       1.1  wrstuden 		printf("vp = %p, ZERO ptr\n", vp);
    165       1.1  wrstuden 		for (p = (u_long *) a, i = 0; i < 8; i++)
    166       1.1  wrstuden 			printf(" %lx", p[i]);
    167       1.1  wrstuden 		printf("\n");
    168       1.1  wrstuden 		/* wait for debugger */
    169       1.1  wrstuden 		panic("layer_checkvp");
    170       1.1  wrstuden 	}
    171       1.1  wrstuden 	if (a->layer_lowervp->v_usecount < 1) {
    172       1.1  wrstuden 		int i; u_long *p;
    173       1.1  wrstuden 		printf("vp = %p, unref'ed lowervp\n", vp);
    174       1.1  wrstuden 		for (p = (u_long *) a, i = 0; i < 8; i++)
    175       1.1  wrstuden 			printf(" %lx", p[i]);
    176       1.1  wrstuden 		printf("\n");
    177       1.1  wrstuden 		/* wait for debugger */
    178       1.1  wrstuden 		panic ("layer with unref'ed lowervp");
    179       1.1  wrstuden 	};
    180       1.1  wrstuden #ifdef notnow
    181       1.1  wrstuden 	printf("layer %p/%d -> %p/%d [%s, %d]\n",
    182       1.1  wrstuden 	        LAYERTOV(a), LAYERTOV(a)->v_usecount,
    183       1.1  wrstuden 		a->layer_lowervp, a->layer_lowervp->v_usecount,
    184       1.1  wrstuden 		fil, lno);
    185       1.1  wrstuden #endif
    186       1.1  wrstuden 	return a->layer_lowervp;
    187       1.1  wrstuden }
    188      1.16       erh #endif
    189