Home | History | Annotate | Line # | Download | only in overlay
overlay_vnops.c revision 1.16.98.1
      1  1.16.98.1     rmind /*	$NetBSD: overlay_vnops.c,v 1.16.98.1 2010/07/03 01:19:58 rmind Exp $	*/
      2        1.1  wrstuden 
      3        1.1  wrstuden /*
      4        1.1  wrstuden  * Copyright (c) 1999, 2000 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.4       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.1  wrstuden /*
     36        1.1  wrstuden  * Copyright (c) 1992, 1993
     37        1.1  wrstuden  *	The Regents of the University of California.  All rights reserved.
     38        1.1  wrstuden  *
     39        1.1  wrstuden  * This code is derived from software contributed to Berkeley by
     40        1.1  wrstuden  * John Heidemann of the UCLA Ficus project.
     41        1.1  wrstuden  *
     42        1.1  wrstuden  * Redistribution and use in source and binary forms, with or without
     43        1.1  wrstuden  * modification, are permitted provided that the following conditions
     44        1.1  wrstuden  * are met:
     45        1.1  wrstuden  * 1. Redistributions of source code must retain the above copyright
     46        1.1  wrstuden  *    notice, this list of conditions and the following disclaimer.
     47        1.1  wrstuden  * 2. Redistributions in binary form must reproduce the above copyright
     48        1.1  wrstuden  *    notice, this list of conditions and the following disclaimer in the
     49        1.1  wrstuden  *    documentation and/or other materials provided with the distribution.
     50       1.10       agc  * 3. Neither the name of the University nor the names of its contributors
     51        1.1  wrstuden  *    may be used to endorse or promote products derived from this software
     52        1.1  wrstuden  *    without specific prior written permission.
     53        1.1  wrstuden  *
     54        1.1  wrstuden  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     55        1.1  wrstuden  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     56        1.1  wrstuden  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     57        1.1  wrstuden  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     58        1.1  wrstuden  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     59        1.1  wrstuden  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     60        1.1  wrstuden  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     61        1.1  wrstuden  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     62        1.1  wrstuden  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     63        1.1  wrstuden  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     64        1.1  wrstuden  * SUCH DAMAGE.
     65        1.1  wrstuden  *
     66        1.1  wrstuden  *	@(#)null_vnops.c	8.6 (Berkeley) 5/27/95
     67        1.1  wrstuden  *
     68        1.1  wrstuden  * Ancestors:
     69        1.1  wrstuden  *	@(#)lofs_vnops.c	1.2 (Berkeley) 6/18/92
     70  1.16.98.1     rmind  *	$Id: overlay_vnops.c,v 1.16.98.1 2010/07/03 01:19:58 rmind Exp $
     71        1.1  wrstuden  *	...and...
     72        1.1  wrstuden  *	@(#)null_vnodeops.c 1.20 92/07/07 UCLA Ficus project
     73        1.1  wrstuden  */
     74        1.1  wrstuden 
     75        1.1  wrstuden /*
     76        1.1  wrstuden  * Overlay Layer
     77        1.1  wrstuden  *
     78        1.1  wrstuden  * (See mount_overlay(8) for more information.)
     79        1.1  wrstuden  *
     80        1.1  wrstuden  * The overlay layer has two purposes.  First, it serves as a demonstration
     81        1.5       wiz  * of layering by providing a layer which really does nothing (the null
     82        1.5       wiz  * layer makes the underlying files appear elsewhere in the file hierarchy).
     83        1.1  wrstuden  * Second, the overlay layer can serve as a prototype layer. Since it
     84        1.1  wrstuden  * provides all necessary layer framework, new file system layers can be
     85        1.4       wiz  * created very easily by starting with an overlay layer.
     86        1.1  wrstuden  *
     87        1.1  wrstuden  * The remainder of this comment examines the overlay layer as a basis
     88        1.1  wrstuden  * for constructing new layers.
     89        1.1  wrstuden  *
     90        1.1  wrstuden  *
     91        1.1  wrstuden  * INSTANTIATING NEW OVERLAY LAYERS
     92        1.1  wrstuden  *
     93        1.4       wiz  * New overlay layers are created with mount_overlay(8).
     94        1.4       wiz  * mount_overlay(8) takes two arguments, an ignored string
     95        1.1  wrstuden  * and the pathname which the overlay will mount over. After
     96        1.1  wrstuden  * the overlay layer is put into place, all access to the mount
     97        1.4       wiz  * point path will proceed through the overlay layer.
     98        1.1  wrstuden  *
     99        1.1  wrstuden  *
    100        1.1  wrstuden  * OPERATION OF AN OVERLAY LAYER
    101        1.1  wrstuden  *
    102        1.1  wrstuden  * The operation of an overlay layer is identical to that of a null
    103        1.1  wrstuden  * layer. See the null layer (and layerfs) documentation for more info.
    104        1.1  wrstuden  *
    105        1.1  wrstuden  *
    106        1.1  wrstuden  * CREATING OTHER FILE SYSTEM LAYERS
    107        1.1  wrstuden  *
    108        1.1  wrstuden  * One of the easiest ways to construct new file system layers is to make
    109        1.1  wrstuden  * a copy of either the null layer or the overlay layer, rename all files
    110        1.4       wiz  * and variables, and then begin modifying the copy.  sed(1) can be used to
    111        1.1  wrstuden  * easily rename all variables.
    112        1.1  wrstuden  *
    113        1.1  wrstuden  * The choice between using a null and an overlay layer depends on
    114        1.1  wrstuden  * the desirability of retaining access to the underlying filestore.
    115        1.1  wrstuden  * For instance, the umap filesystem presents both a uid-translated and an
    116        1.4       wiz  * untranslated view of the underlying files, and so it is based off of
    117        1.4       wiz  * the null layer. However a layer implementing Access Control Lists
    118        1.1  wrstuden  * might prefer to block access to the underlying filestore, for which
    119        1.1  wrstuden  * the overlay layer is a better basis.
    120        1.1  wrstuden  *
    121        1.1  wrstuden  *
    122        1.1  wrstuden  * INVOKING OPERATIONS ON LOWER LAYERS
    123        1.1  wrstuden  *
    124        1.1  wrstuden  * See the null layer documentation.
    125        1.1  wrstuden  *
    126        1.1  wrstuden  */
    127        1.6     lukem 
    128        1.6     lukem #include <sys/cdefs.h>
    129  1.16.98.1     rmind __KERNEL_RCSID(0, "$NetBSD: overlay_vnops.c,v 1.16.98.1 2010/07/03 01:19:58 rmind Exp $");
    130        1.1  wrstuden 
    131        1.1  wrstuden #include <sys/param.h>
    132        1.1  wrstuden #include <sys/systm.h>
    133        1.1  wrstuden #include <sys/proc.h>
    134        1.1  wrstuden #include <sys/time.h>
    135        1.1  wrstuden #include <sys/vnode.h>
    136        1.1  wrstuden #include <sys/mount.h>
    137        1.1  wrstuden #include <sys/namei.h>
    138        1.1  wrstuden #include <sys/malloc.h>
    139        1.1  wrstuden #include <sys/buf.h>
    140        1.1  wrstuden #include <miscfs/genfs/genfs.h>
    141        1.1  wrstuden #include <miscfs/overlay/overlay.h>
    142        1.1  wrstuden #include <miscfs/genfs/layer_extern.h>
    143        1.1  wrstuden 
    144        1.1  wrstuden /*
    145        1.1  wrstuden  * Global vfs data structures
    146        1.1  wrstuden  */
    147       1.15   xtraeme int (**overlay_vnodeop_p)(void *);
    148        1.3  jdolecek const struct vnodeopv_entry_desc overlay_vnodeop_entries[] = {
    149        1.1  wrstuden 	{ &vop_default_desc,  layer_bypass },
    150        1.1  wrstuden 
    151        1.1  wrstuden 	{ &vop_lookup_desc,   layer_lookup },
    152        1.1  wrstuden 	{ &vop_setattr_desc,  layer_setattr },
    153        1.1  wrstuden 	{ &vop_getattr_desc,  layer_getattr },
    154        1.1  wrstuden 	{ &vop_access_desc,   layer_access },
    155        1.1  wrstuden 	{ &vop_fsync_desc,    layer_fsync },
    156        1.1  wrstuden 	{ &vop_inactive_desc, layer_inactive },
    157        1.1  wrstuden 	{ &vop_reclaim_desc,  layer_reclaim },
    158        1.1  wrstuden 	{ &vop_print_desc,    layer_print },
    159       1.12  wrstuden 	{ &vop_remove_desc,   layer_remove },
    160       1.13      yamt 	{ &vop_rename_desc,   layer_rename },
    161       1.14   hannken 	{ &vop_rmdir_desc,    layer_rmdir },
    162        1.1  wrstuden 
    163        1.1  wrstuden 	{ &vop_open_desc,     layer_open },	/* mount option handling */
    164        1.1  wrstuden 
    165        1.1  wrstuden 	{ &vop_bwrite_desc,   layer_bwrite },
    166        1.1  wrstuden 	{ &vop_bmap_desc,     layer_bmap },
    167        1.9       chs 	{ &vop_getpages_desc, layer_getpages },
    168        1.8       chs 	{ &vop_putpages_desc, layer_putpages },
    169        1.1  wrstuden 
    170        1.8       chs 	{ NULL, NULL }
    171        1.1  wrstuden };
    172        1.3  jdolecek const struct vnodeopv_desc overlay_vnodeop_opv_desc =
    173        1.1  wrstuden 	{ &overlay_vnodeop_p, overlay_vnodeop_entries };
    174