2005-02-27 01:58:54 +03:00
|
|
|
/* $NetBSD: null_vnops.c,v 1.32 2005/02/26 22:59:00 perry Exp $ */
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1999-07-08 05:18:59 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1999 National Aeronautics & Space Administration
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was written by William Studenmund of the
|
2001-06-07 17:44:46 +04:00
|
|
|
* Numerical Aerospace Simulation Facility, NASA Ames Research Center.
|
1999-07-08 05:18:59 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2000-03-14 02:52:25 +03:00
|
|
|
* 3. Neither the name of the National Aeronautics & Space Administration
|
1999-07-08 05:18:59 +04:00
|
|
|
* nor the names of its contributors may be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB-
|
|
|
|
* UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|
|
|
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1994-06-08 15:33:09 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* John Heidemann of the UCLA Ficus project.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-06-08 15:33:09 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)null_vnops.c 8.6 (Berkeley) 5/27/95
|
1994-06-08 15:33:09 +04:00
|
|
|
*
|
|
|
|
* Ancestors:
|
|
|
|
* @(#)lofs_vnops.c 1.2 (Berkeley) 6/18/92
|
2005-02-27 01:58:54 +03:00
|
|
|
* Id: lofs_vnops.c,v 1.11 1992/05/30 10:05:43 jsp Exp jsp
|
1994-06-08 15:33:09 +04:00
|
|
|
* ...and...
|
|
|
|
* @(#)null_vnodeops.c 1.20 92/07/07 UCLA Ficus project
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Null Layer
|
|
|
|
*
|
|
|
|
* (See mount_null(8) for more information.)
|
|
|
|
*
|
|
|
|
* The null layer duplicates a portion of the file system
|
|
|
|
* name space under a new name. In this respect, it is
|
|
|
|
* similar to the loopback file system. It differs from
|
|
|
|
* the loopback fs in two respects: it is implemented using
|
2001-06-09 15:02:08 +04:00
|
|
|
* a stackable layers technique, and its "null-nodes" stack above
|
1994-06-08 15:33:09 +04:00
|
|
|
* all lower-layer vnodes, not just over directory vnodes.
|
|
|
|
*
|
|
|
|
* The null layer has two purposes. First, it serves as a demonstration
|
2001-06-09 15:02:08 +04:00
|
|
|
* of layering by providing a layer which does nothing (it actually
|
1994-06-08 15:33:09 +04:00
|
|
|
* does everything the loopback file system does, which is slightly
|
2001-06-09 15:02:08 +04:00
|
|
|
* more than nothing). Second, the null layer can serve as a prototype
|
1994-06-08 15:33:09 +04:00
|
|
|
* layer. Since it provides all necessary layer framework,
|
2001-06-07 17:44:46 +04:00
|
|
|
* new file system layers can be created very easily by starting
|
1994-06-08 15:33:09 +04:00
|
|
|
* with a null layer.
|
|
|
|
*
|
2001-06-07 17:44:46 +04:00
|
|
|
* The remainder of this comment examines the null layer as a basis
|
1994-06-08 15:33:09 +04:00
|
|
|
* for constructing new layers.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* INSTANTIATING NEW NULL LAYERS
|
|
|
|
*
|
|
|
|
* New null layers are created with mount_null(8).
|
2001-06-07 17:44:46 +04:00
|
|
|
* mount_null(8) takes two arguments, the pathname
|
1994-06-08 15:33:09 +04:00
|
|
|
* of the lower vfs (target-pn) and the pathname where the null
|
|
|
|
* layer will appear in the namespace (alias-pn). After
|
|
|
|
* the null layer is put into place, the contents
|
|
|
|
* of target-pn subtree will be aliased under alias-pn.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* OPERATION OF A NULL LAYER
|
|
|
|
*
|
|
|
|
* The null layer is the minimum file system layer,
|
|
|
|
* simply bypassing all possible operations to the lower layer
|
|
|
|
* for processing there. The majority of its activity centers
|
2001-06-07 17:44:46 +04:00
|
|
|
* on the bypass routine, through which nearly all vnode operations
|
1994-06-08 15:33:09 +04:00
|
|
|
* pass.
|
|
|
|
*
|
|
|
|
* The bypass routine accepts arbitrary vnode operations for
|
2001-06-07 17:44:46 +04:00
|
|
|
* handling by the lower layer. It begins by examining vnode
|
1994-06-08 15:33:09 +04:00
|
|
|
* operation arguments and replacing any null-nodes by their
|
2001-06-07 17:44:46 +04:00
|
|
|
* lower-layer equivalents. It then invokes the operation
|
1994-06-08 15:33:09 +04:00
|
|
|
* on the lower layer. Finally, it replaces the null-nodes
|
2001-06-07 17:44:46 +04:00
|
|
|
* in the arguments and, if a vnode is returned by the operation,
|
1994-06-08 15:33:09 +04:00
|
|
|
* stacks a null-node on top of the returned vnode.
|
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* Although bypass handles most operations, vop_getattr, vop_lock,
|
|
|
|
* vop_unlock, vop_inactive, vop_reclaim, and vop_print are not
|
2001-06-07 17:44:46 +04:00
|
|
|
* bypassed. vop_getattr must change the fsid being returned.
|
|
|
|
* vop_lock and vop_unlock must handle any locking for the
|
1998-03-01 05:20:01 +03:00
|
|
|
* current vnode as well as pass the lock request down.
|
2001-06-07 17:44:46 +04:00
|
|
|
* vop_inactive and vop_reclaim are not bypassed so that
|
|
|
|
* they can handle freeing null-layer specific data. vop_print
|
1998-03-01 05:20:01 +03:00
|
|
|
* is not bypassed to avoid excessive debugging information.
|
|
|
|
* Also, certain vnode operations change the locking state within
|
|
|
|
* the operation (create, mknod, remove, link, rename, mkdir, rmdir,
|
|
|
|
* and symlink). Ideally these operations should not change the
|
|
|
|
* lock state, but should be changed to let the caller of the
|
|
|
|
* function unlock them. Otherwise all intermediate vnode layers
|
|
|
|
* (such as union, umapfs, etc) must catch these functions to do
|
|
|
|
* the necessary locking at their layer.
|
1994-06-08 15:33:09 +04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* INSTANTIATING VNODE STACKS
|
|
|
|
*
|
|
|
|
* Mounting associates the null layer with a lower layer,
|
2001-06-07 17:44:46 +04:00
|
|
|
* in effect stacking two VFSes. Vnode stacks are instead
|
1994-06-08 15:33:09 +04:00
|
|
|
* created on demand as files are accessed.
|
|
|
|
*
|
|
|
|
* The initial mount creates a single vnode stack for the
|
|
|
|
* root of the new null layer. All other vnode stacks
|
|
|
|
* are created as a result of vnode operations on
|
|
|
|
* this or other null vnode stacks.
|
|
|
|
*
|
2001-06-07 17:44:46 +04:00
|
|
|
* New vnode stacks come into existence as a result of
|
2005-02-27 01:58:54 +03:00
|
|
|
* an operation which returns a vnode.
|
1994-06-08 15:33:09 +04:00
|
|
|
* The bypass routine stacks a null-node above the new
|
|
|
|
* vnode before returning it to the caller.
|
|
|
|
*
|
|
|
|
* For example, imagine mounting a null layer with
|
|
|
|
* "mount_null /usr/include /dev/layer/null".
|
|
|
|
* Changing directory to /dev/layer/null will assign
|
|
|
|
* the root null-node (which was created when the null layer was mounted).
|
|
|
|
* Now consider opening "sys". A vop_lookup would be
|
|
|
|
* done on the root null-node. This operation would bypass through
|
2005-02-27 01:58:54 +03:00
|
|
|
* to the lower layer which would return a vnode representing
|
2001-06-07 17:44:46 +04:00
|
|
|
* the UFS "sys". null_bypass then builds a null-node
|
1994-06-08 15:33:09 +04:00
|
|
|
* aliasing the UFS "sys" and returns this to the caller.
|
|
|
|
* Later operations on the null-node "sys" will repeat this
|
|
|
|
* process when constructing other vnode stacks.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* CREATING OTHER FILE SYSTEM LAYERS
|
|
|
|
*
|
|
|
|
* One of the easiest ways to construct new file system layers is to make
|
|
|
|
* a copy of the null layer, rename all files and variables, and
|
2001-06-07 17:44:46 +04:00
|
|
|
* then begin modifying the copy. sed(1) can be used to easily rename
|
1994-06-08 15:33:09 +04:00
|
|
|
* all variables.
|
|
|
|
*
|
2005-02-27 01:58:54 +03:00
|
|
|
* The umap layer is an example of a layer descended from the
|
1994-06-08 15:33:09 +04:00
|
|
|
* null layer.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* INVOKING OPERATIONS ON LOWER LAYERS
|
|
|
|
*
|
2005-02-27 01:58:54 +03:00
|
|
|
* There are two techniques to invoke operations on a lower layer
|
1994-06-08 15:33:09 +04:00
|
|
|
* when the operation cannot be completely bypassed. Each method
|
|
|
|
* is appropriate in different situations. In both cases,
|
|
|
|
* it is the responsibility of the aliasing layer to make
|
|
|
|
* the operation arguments "correct" for the lower layer
|
2001-06-07 17:44:46 +04:00
|
|
|
* by mapping any vnode arguments to the lower layer.
|
1994-06-08 15:33:09 +04:00
|
|
|
*
|
|
|
|
* The first approach is to call the aliasing layer's bypass routine.
|
|
|
|
* This method is most suitable when you wish to invoke the operation
|
2001-11-07 07:04:10 +03:00
|
|
|
* currently being handled on the lower layer. It has the advantage
|
1994-06-08 15:33:09 +04:00
|
|
|
* that the bypass routine already must do argument mapping.
|
|
|
|
* An example of this is null_getattrs in the null layer.
|
|
|
|
*
|
2001-06-07 17:44:46 +04:00
|
|
|
* A second approach is to directly invoke vnode operations on
|
1994-06-08 15:33:09 +04:00
|
|
|
* the lower layer with the VOP_OPERATIONNAME interface.
|
|
|
|
* The advantage of this method is that it is easy to invoke
|
|
|
|
* arbitrary operations on the lower layer. The disadvantage
|
2001-06-07 17:44:46 +04:00
|
|
|
* is that vnode arguments must be manually mapped.
|
1994-06-08 15:33:09 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2001-11-10 16:33:40 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-02-27 01:58:54 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: null_vnops.c,v 1.32 2005/02/26 22:59:00 perry Exp $");
|
2001-11-10 16:33:40 +03:00
|
|
|
|
1994-06-08 15:33:09 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/buf.h>
|
1998-03-01 05:20:01 +03:00
|
|
|
#include <miscfs/genfs/genfs.h>
|
1999-07-08 05:18:59 +04:00
|
|
|
#include <miscfs/nullfs/null.h>
|
|
|
|
#include <miscfs/genfs/layer_extern.h>
|
1994-06-08 15:33:09 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Global vfs data structures
|
|
|
|
*/
|
1996-02-10 01:39:56 +03:00
|
|
|
int (**null_vnodeop_p) __P((void *));
|
2001-01-22 15:17:35 +03:00
|
|
|
const struct vnodeopv_entry_desc null_vnodeop_entries[] = {
|
1999-07-08 05:18:59 +04:00
|
|
|
{ &vop_default_desc, layer_bypass },
|
|
|
|
|
|
|
|
{ &vop_lookup_desc, layer_lookup },
|
|
|
|
{ &vop_setattr_desc, layer_setattr },
|
|
|
|
{ &vop_getattr_desc, layer_getattr },
|
|
|
|
{ &vop_access_desc, layer_access },
|
|
|
|
{ &vop_lock_desc, layer_lock },
|
|
|
|
{ &vop_unlock_desc, layer_unlock },
|
|
|
|
{ &vop_islocked_desc, layer_islocked },
|
|
|
|
{ &vop_fsync_desc, layer_fsync },
|
|
|
|
{ &vop_inactive_desc, layer_inactive },
|
|
|
|
{ &vop_reclaim_desc, layer_reclaim },
|
|
|
|
{ &vop_print_desc, layer_print },
|
2004-05-28 22:55:20 +04:00
|
|
|
{ &vop_remove_desc, layer_remove },
|
2004-06-07 21:36:38 +04:00
|
|
|
{ &vop_rename_desc, layer_rename },
|
2004-06-30 21:42:55 +04:00
|
|
|
{ &vop_rmdir_desc, layer_rmdir },
|
1999-07-08 05:18:59 +04:00
|
|
|
|
|
|
|
{ &vop_open_desc, layer_open }, /* mount option handling */
|
|
|
|
|
|
|
|
{ &vop_bwrite_desc, layer_bwrite },
|
|
|
|
{ &vop_bmap_desc, layer_bmap },
|
2002-01-04 10:19:33 +03:00
|
|
|
{ &vop_getpages_desc, layer_getpages },
|
2001-12-06 07:29:23 +03:00
|
|
|
{ &vop_putpages_desc, layer_putpages },
|
1998-03-01 05:20:01 +03:00
|
|
|
|
2001-12-06 07:29:23 +03:00
|
|
|
{ NULL, NULL }
|
1994-06-08 15:33:09 +04:00
|
|
|
};
|
2001-01-22 15:17:35 +03:00
|
|
|
const struct vnodeopv_desc null_vnodeop_opv_desc =
|
1994-06-08 15:33:09 +04:00
|
|
|
{ &null_vnodeop_p, null_vnodeop_entries };
|