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