Home | History | Annotate | Line # | Download | only in coda
coda_namecache.h revision 1.4
      1 /*	$NetBSD: coda_namecache.h,v 1.4 1998/09/15 02:02:58 rvb Exp $	*/
      2 
      3 /*
      4  *
      5  *             Coda: an Experimental Distributed File System
      6  *                              Release 3.1
      7  *
      8  *           Copyright (c) 1987-1998 Carnegie Mellon University
      9  *                          All Rights Reserved
     10  *
     11  * Permission  to  use, copy, modify and distribute this software and its
     12  * documentation is hereby granted,  provided  that  both  the  copyright
     13  * notice  and  this  permission  notice  appear  in  all  copies  of the
     14  * software, derivative works or  modified  versions,  and  any  portions
     15  * thereof, and that both notices appear in supporting documentation, and
     16  * that credit is given to Carnegie Mellon University  in  all  documents
     17  * and publicity pertaining to direct or indirect use of this code or its
     18  * derivatives.
     19  *
     20  * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
     21  * SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
     22  * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
     23  * DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
     24  * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
     25  * ANY DERIVATIVE WORK.
     26  *
     27  * Carnegie  Mellon  encourages  users  of  this  software  to return any
     28  * improvements or extensions that  they  make,  and  to  grant  Carnegie
     29  * Mellon the rights to redistribute these changes without encumbrance.
     30  *
     31  * 	@(#) coda/coda_namecache.h,v 1.1.1.1 1998/08/29 21:26:46 rvb Exp $
     32  */
     33 
     34 /*
     35  * Mach Operating System
     36  * Copyright (c) 1990 Carnegie-Mellon University
     37  * Copyright (c) 1989 Carnegie-Mellon University
     38  * All rights reserved.  The CMU software License Agreement specifies
     39  * the terms and conditions for use and redistribution.
     40  */
     41 
     42 /*
     43  * This code was written for the Coda file system at Carnegie Mellon University.
     44  * Contributers include David Steere, James Kistler, and M. Satyanarayanan.
     45  */
     46 
     47 /*
     48  * HISTORY
     49  * $Log: coda_namecache.h,v $
     50  * Revision 1.4  1998/09/15 02:02:58  rvb
     51  * Final piece of rename cfs->coda
     52  *
     53  * Revision 1.3  1998/09/12 15:05:50  rvb
     54  * Change cfs/CFS in symbols, strings and constants to coda/CODA
     55  * to avoid fs conflicts.
     56  *
     57  * Revision 1.2  1998/09/08 17:12:48  rvb
     58  * Pass2 complete
     59  *
     60  * Revision 1.1.1.1  1998/08/29 21:26:46  rvb
     61  * Very Preliminary Coda
     62  *
     63  * Revision 1.8  1998/08/28 18:12:25  rvb
     64  * Now it also works on FreeBSD -current.  This code will be
     65  * committed to the FreeBSD -current and NetBSD -current
     66  * trees.  It will then be tailored to the particular platform
     67  * by flushing conditional code.
     68  *
     69  * Revision 1.7  1998/08/18 17:05:24  rvb
     70  * Don't use __RCSID now
     71  *
     72  * Revision 1.6  1998/08/18 16:31:49  rvb
     73  * Sync the code for NetBSD -current; test on 1.3 later
     74  *
     75  * Revision 1.5  98/01/23  11:53:51  rvb
     76  * Bring RVB_CODA1_1 to HEAD
     77  *
     78  * Revision 1.4.2.1  97/12/16  12:40:23  rvb
     79  * Sync with 1.3
     80  *
     81  * Revision 1.4  97/12/05  10:39:29  rvb
     82  * Read CHANGES
     83  *
     84  * Revision 1.3.4.3  97/11/24  15:44:51  rvb
     85  * Final cfs_venus.c w/o macros, but one locking bug
     86  *
     87  * Revision 1.3.4.2  97/11/12  12:09:44  rvb
     88  * reorg pass1
     89  *
     90  * Revision 1.3.4.1  97/11/06  21:06:05  rvb
     91  * don't include headers in headers
     92  *
     93  * Revision 1.3  97/08/05  11:08:19  lily
     94  * Removed cfsnc_replace, replaced it with a coda_find, unhash, and
     95  * rehash.  This fixes a cnode leak and a bug in which the fid is
     96  * not actually replaced.  (cfs_namecache.c, cfsnc.h, cfs_subr.c)
     97  *
     98  * Revision 1.2  96/01/02  16:57:19  bnoble
     99  * Added support for Coda MiniCache and raw inode calls (final commit)
    100  *
    101  * Revision 1.1.2.1  1995/12/20 01:57:45  bnoble
    102  * Added CODA-specific files
    103  *
    104  * Revision 3.1.1.1  1995/03/04  19:08:22  bnoble
    105  * Branch for NetBSD port revisions
    106  *
    107  * Revision 3.1  1995/03/04  19:08:21  bnoble
    108  * Bump to major revision 3 to prepare for NetBSD port
    109  *
    110  * Revision 2.2  1994/08/28  19:37:39  luqi
    111  * Add a new CODA_REPLACE call to allow venus to replace a ViceFid in the
    112  * mini-cache.
    113  *
    114  * In "cfs.h":
    115  * Add CODA_REPLACE decl.
    116  *
    117  * In "cfs_namecache.c":
    118  * Add routine cfsnc_replace.
    119  *
    120  * In "cfs_subr.c":
    121  * Add case-statement to process CODA_REPLACE.
    122  *
    123  * In "cfsnc.h":
    124  * Add decl for CODA_NC_REPLACE.
    125  *
    126  * Revision 2.1  94/07/21  16:25:27  satya
    127  * Conversion to C++ 3.0; start of Coda Release 2.0
    128  *
    129  * Revision 1.2  92/10/27  17:58:34  lily
    130  * merge kernel/latest and alpha/src/cfs
    131  *
    132  * Revision 2.2  90/07/05  11:27:04  mrt
    133  * 	Created for the Coda File System.
    134  * 	[90/05/23            dcs]
    135  *
    136  * Revision 1.4  90/05/31  17:02:12  dcs
    137  * Prepare for merge with facilities kernel.
    138  *
    139  *
    140  */
    141 
    142 #ifndef _CODA_NC_HEADER_
    143 #define _CODA_NC_HEADER_
    144 
    145 /*
    146  * Coda constants
    147  */
    148 #define CODA_NC_NAMELEN		15		/* longest name stored in cache */
    149 #define CODA_NC_CACHESIZE	 256		/* Default cache size */
    150 #define CODA_NC_HASHSIZE	64		/* Must be multiple of 2 */
    151 
    152 /*
    153  * Hash function for the primary hash.
    154  */
    155 
    156 /*
    157  * First try -- (first + last letters + length + (int)cp) mod size
    158  * 2nd try -- same, except dir fid.vnode instead of cp
    159  */
    160 
    161 #ifdef	oldhash
    162 #define CODA_NC_HASH(name, namelen, cp) \
    163 	((name[0] + name[namelen-1] + namelen + (int)(cp)) & (coda_nc_hashsize-1))
    164 #else
    165 #define CODA_NC_HASH(name, namelen, cp) \
    166 	((name[0] + (name[namelen-1]<<4) + namelen + (((int)cp)>>8)) & (coda_nc_hashsize-1))
    167 #endif
    168 
    169 #define CODA_NAMEMATCH(cp, name, namelen, dcp) \
    170 	((namelen == cp->namelen) && (dcp == cp->dcp) && \
    171 		 (bcmp(cp->name,name,namelen) == 0))
    172 
    173 /*
    174  * Functions to modify the hash and lru chains.
    175  * insque and remque assume that the pointers are the first thing
    176  * in the list node, thus the trickery for lru.
    177  */
    178 
    179 #define CODA_NC_HSHINS(elem, pred)	insque(elem,pred)
    180 #define CODA_NC_HSHREM(elem)		remque(elem)
    181 #define CODA_NC_HSHNUL(elem)		(elem)->hash_next = \
    182 					(elem)->hash_prev = (elem)
    183 
    184 #define CODA_NC_LRUINS(elem, pred)	insque(LRU_PART(elem), LRU_PART(pred))
    185 #define CODA_NC_LRUREM(elem)		remque(LRU_PART(elem));
    186 #define CODA_NC_LRUGET(lruhead)		LRU_TOP((lruhead).lru_prev)
    187 
    188 #define CODA_NC_VALID(cncp)	(cncp->dcp != (struct cnode *)0)
    189 
    190 #define LRU_PART(cncp)			(struct coda_cache *) \
    191 				((char *)cncp + (2*sizeof(struct coda_cache *)))
    192 #define LRU_TOP(cncp)				(struct coda_cache *) \
    193 			((char *)cncp - (2*sizeof(struct coda_cache *)))
    194 #define DATA_PART(cncp)				(struct coda_cache *) \
    195 			((char *)cncp + (4*sizeof(struct coda_cache *)))
    196 #define DATA_SIZE	(sizeof(struct coda_cache)-(4*sizeof(struct coda_cache *)))
    197 
    198 /*
    199  * Structure for an element in the CODA Name Cache.
    200  * NOTE: I use the position of arguments and their size in the
    201  * implementation of the functions CODA_NC_LRUINS, CODA_NC_LRUREM, and
    202  * DATA_PART.
    203  */
    204 
    205 struct coda_cache {
    206 	struct coda_cache	*hash_next,*hash_prev;	/* Hash list */
    207 	struct coda_cache	*lru_next, *lru_prev;	/* LRU list */
    208 	struct cnode	*cp;			/* vnode of the file */
    209 	struct cnode	*dcp;			/* parent's cnode */
    210 	struct ucred	*cred;			/* user credentials */
    211 	char		name[CODA_NC_NAMELEN];	/* segment name */
    212 	int		namelen;		/* length of name */
    213 };
    214 
    215 struct	coda_lru {		/* Start of LRU chain */
    216 	char *dummy1, *dummy2;			/* place holders */
    217 	struct coda_cache *lru_next, *lru_prev;   /* position of pointers is important */
    218 };
    219 
    220 
    221 struct coda_hash {		/* Start of Hash chain */
    222 	struct coda_cache *hash_next, *hash_prev; /* NOTE: chain pointers must be first */
    223         int length;                             /* used for tuning purposes */
    224 };
    225 
    226 
    227 /*
    228  * Symbols to aid in debugging the namecache code. Assumes the existence
    229  * of the variable coda_nc_debug, which is defined in cfs_namecache.c
    230  */
    231 #define CODA_NC_DEBUG(N, STMT)     { if (coda_nc_debug & (1 <<N)) { STMT } }
    232 
    233 /* Prototypes of functions exported within cfs */
    234 extern void coda_nc_init(void);
    235 extern void coda_nc_enter(struct cnode *, const char *, int, struct ucred *, struct cnode *);
    236 extern struct cnode *coda_nc_lookup(struct cnode *, const char *, int, struct ucred *);
    237 
    238 extern void coda_nc_zapParentfid(ViceFid *, enum dc_status);
    239 extern void coda_nc_zapfid(ViceFid *, enum dc_status);
    240 extern void coda_nc_zapvnode(ViceFid *, struct ucred *, enum dc_status);
    241 extern void coda_nc_zapfile(struct cnode *, const char *, int);
    242 extern void coda_nc_purge_user(vuid_t, enum dc_status);
    243 extern void coda_nc_flush(enum dc_status);
    244 
    245 extern void print_coda_nc(void);
    246 extern void coda_nc_gather_stats(void);
    247 extern int  coda_nc_resize(int, int, enum dc_status);
    248 extern void coda_nc_name(struct cnode *cp);
    249 
    250 /*
    251  * Structure to contain statistics on the cache usage
    252  */
    253 
    254 struct coda_nc_statistics {
    255 	unsigned	hits;
    256 	unsigned	misses;
    257 	unsigned	enters;
    258 	unsigned	dbl_enters;
    259 	unsigned	long_name_enters;
    260 	unsigned	long_name_lookups;
    261 	unsigned	long_remove;
    262 	unsigned	lru_rm;
    263 	unsigned	zapPfids;
    264 	unsigned	zapFids;
    265 	unsigned	zapFile;
    266 	unsigned	zapUsers;
    267 	unsigned	Flushes;
    268 	unsigned        Sum_bucket_len;
    269 	unsigned        Sum2_bucket_len;
    270 	unsigned        Max_bucket_len;
    271 	unsigned        Num_zero_len;
    272 	unsigned        Search_len;
    273 };
    274 
    275 #define CODA_NC_FIND		((u_long) 1)
    276 #define CODA_NC_REMOVE		((u_long) 2)
    277 #define CODA_NC_INIT		((u_long) 3)
    278 #define CODA_NC_ENTER		((u_long) 4)
    279 #define CODA_NC_LOOKUP		((u_long) 5)
    280 #define CODA_NC_ZAPPFID		((u_long) 6)
    281 #define CODA_NC_ZAPFID		((u_long) 7)
    282 #define CODA_NC_ZAPVNODE		((u_long) 8)
    283 #define CODA_NC_ZAPFILE		((u_long) 9)
    284 #define CODA_NC_PURGEUSER		((u_long) 10)
    285 #define CODA_NC_FLUSH		((u_long) 11)
    286 #define CODA_NC_PRINTCODA_NC	((u_long) 12)
    287 #define CODA_NC_PRINTSTATS	((u_long) 13)
    288 
    289 #endif /* _CFSNC_HEADER_ */
    290