Home | History | Annotate | Line # | Download | only in genfs
layer.h revision 1.10
      1  1.10      jmmv /*	$NetBSD: layer.h,v 1.10 2005/09/25 21:17:05 jmmv 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.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 /*
     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.5       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.h,v 1.8 1992/05/30 10:05:43 jsp Exp
     68   1.1  wrstuden  *	@(#)null.h	8.2 (Berkeley) 1/21/94
     69   1.1  wrstuden  */
     70   1.1  wrstuden 
     71   1.1  wrstuden #ifndef _MISCFS_GENFS_LAYER_H_
     72   1.1  wrstuden #define _MISCFS_GENFS_LAYER_H_
     73   1.1  wrstuden 
     74   1.1  wrstuden struct layer_args {
     75   1.1  wrstuden 	char	*target;		/* Target of loopback  */
     76  1.10      jmmv 	struct export_args30 _pad1; /* compat with old userland tools */
     77   1.1  wrstuden };
     78   1.1  wrstuden 
     79   1.1  wrstuden #ifdef _KERNEL
     80   1.1  wrstuden 
     81   1.1  wrstuden struct layer_node;
     82   1.1  wrstuden 
     83   1.1  wrstuden LIST_HEAD(layer_node_hashhead, layer_node);
     84   1.1  wrstuden 
     85   1.1  wrstuden struct layer_mount {
     86   1.1  wrstuden 	struct mount		*layerm_vfs;
     87   1.1  wrstuden 	struct vnode		*layerm_rootvp;	/* Ref to root layer_node */
     88   1.1  wrstuden 	u_int			layerm_flags;	/* mount point layer flags */
     89   1.1  wrstuden 	u_int			layerm_size;	/* size of fs's struct node */
     90   1.1  wrstuden 	enum vtype		layerm_tag;	/* vtag of our vnodes */
     91   1.1  wrstuden 	int				/* bypass routine for this mount */
     92   1.8   xtraeme 				(*layerm_bypass)(void *);
     93   1.1  wrstuden 	int			(*layerm_alloc)	/* alloc a new layer node */
     94   1.8   xtraeme 				(struct mount *, struct vnode *,
     95   1.8   xtraeme 						struct vnode **);
     96   1.1  wrstuden 	int			(**layerm_vnodeop_p)	/* ops for our nodes */
     97   1.8   xtraeme 				(void *);
     98   1.1  wrstuden 	struct layer_node_hashhead	/* head of hash list for layer_nodes */
     99   1.1  wrstuden 				*layerm_node_hashtbl;
    100   1.1  wrstuden 	u_long			layerm_node_hash; /* hash mask for hash chain */
    101   1.1  wrstuden 	struct simplelock	layerm_hashlock; /* interlock for hash chain. */
    102   1.1  wrstuden };
    103   1.1  wrstuden 
    104   1.1  wrstuden #define	LAYERFS_MFLAGS		0x00000fff	/* reserved layer mount flags */
    105   1.1  wrstuden #define	LAYERFS_MBYPASSDEBUG	0x00000001
    106   1.1  wrstuden 
    107   1.1  wrstuden /*
    108   1.1  wrstuden  * A cache of vnode references
    109   1.1  wrstuden  */
    110   1.1  wrstuden struct layer_node {
    111   1.1  wrstuden 	LIST_ENTRY(layer_node)	layer_hash;	/* Hash list */
    112   1.1  wrstuden 	struct vnode	        *layer_lowervp;	/* VREFed once */
    113   1.1  wrstuden 	struct vnode		*layer_vnode;	/* Back pointer */
    114   1.1  wrstuden 	unsigned int		layer_flags;	/* locking, etc. */
    115   1.1  wrstuden };
    116   1.1  wrstuden 
    117   1.1  wrstuden #define	LAYERFS_RESFLAGS	0x00000fff	/* flags reserved for layerfs */
    118   1.6  wrstuden #define	LAYERFS_REMOVED 	0x00000001	/* Did a remove on this node */
    119   1.1  wrstuden 
    120   1.1  wrstuden /*
    121   1.1  wrstuden  * The following macros handle upperfs-specific locking. They are needed
    122   1.1  wrstuden  * when the lowerfs does not export a struct lock for locking use by the
    123   1.1  wrstuden  * upper layers. These macros are inteded for adjusting the upperfs
    124   1.1  wrstuden  * struct lock to reflect changes in the underlying vnode's lock state.
    125   1.1  wrstuden  */
    126   1.1  wrstuden #define	LAYERFS_UPPERLOCK(v, f, r)	do { \
    127   1.1  wrstuden 	if ((v)->v_vnlock == NULL) \
    128   1.1  wrstuden 		r = lockmgr(&(v)->v_lock, (f), &(v)->v_interlock); \
    129   1.1  wrstuden 	else \
    130   1.1  wrstuden 		r = 0; \
    131   1.1  wrstuden 	} while (0)
    132   1.1  wrstuden 
    133   1.1  wrstuden #define	LAYERFS_UPPERUNLOCK(v, f, r)	do { \
    134   1.1  wrstuden 	if ((v)->v_vnlock == NULL) \
    135   1.1  wrstuden 	    r = lockmgr(&(v)->v_lock, (f) | LK_RELEASE, &(v)->v_interlock); \
    136   1.1  wrstuden 	else \
    137   1.1  wrstuden 		r = 0; \
    138   1.1  wrstuden 	} while (0)
    139   1.1  wrstuden 
    140   1.1  wrstuden #define	LAYERFS_UPPERISLOCKED(v, r)	do { \
    141   1.1  wrstuden 	if ((v)->v_vnlock == NULL) \
    142   1.1  wrstuden 		r = lockstatus(&(v)->v_lock); \
    143   1.1  wrstuden 	else \
    144   1.1  wrstuden 		r = -1; \
    145   1.1  wrstuden 	} while (0)
    146   1.1  wrstuden 
    147   1.1  wrstuden #define	LAYERFS_DO_BYPASS(vp, ap)	\
    148   1.1  wrstuden 	(*MOUNTTOLAYERMOUNT((vp)->v_mount)->layerm_bypass)((ap))
    149   1.1  wrstuden 
    150   1.8   xtraeme struct vnode *layer_checkvp(struct vnode *vp, const char *fil, int lno);
    151   1.1  wrstuden 
    152   1.1  wrstuden #define	MOUNTTOLAYERMOUNT(mp) ((struct layer_mount *)((mp)->mnt_data))
    153   1.1  wrstuden #define	VTOLAYER(vp) ((struct layer_node *)(vp)->v_data)
    154   1.1  wrstuden #define	LAYERTOV(xp) ((xp)->layer_vnode)
    155   1.1  wrstuden #ifdef LAYERFS_DIAGNOSTIC
    156   1.1  wrstuden #define	LAYERVPTOLOWERVP(vp) layer_checkvp((vp), __FILE__, __LINE__)
    157   1.7       erh extern int layerfs_debug;
    158   1.1  wrstuden #else
    159   1.1  wrstuden #define	LAYERVPTOLOWERVP(vp) (VTOLAYER(vp)->layer_lowervp)
    160   1.1  wrstuden #endif
    161   1.1  wrstuden 
    162   1.1  wrstuden #endif /* _KERNEL */
    163   1.1  wrstuden #endif /* _MISCFS_GENFS_LAYER_H_ */
    164