Home | History | Annotate | Line # | Download | only in coda
coda_namecache.h revision 1.7
      1  1.7  drochner /*	$NetBSD: coda_namecache.h,v 1.7 2003/08/27 17:49:49 drochner Exp $	*/
      2  1.2       rvb 
      3  1.1       rvb /*
      4  1.2       rvb  *
      5  1.2       rvb  *             Coda: an Experimental Distributed File System
      6  1.2       rvb  *                              Release 3.1
      7  1.2       rvb  *
      8  1.2       rvb  *           Copyright (c) 1987-1998 Carnegie Mellon University
      9  1.2       rvb  *                          All Rights Reserved
     10  1.2       rvb  *
     11  1.2       rvb  * Permission  to  use, copy, modify and distribute this software and its
     12  1.2       rvb  * documentation is hereby granted,  provided  that  both  the  copyright
     13  1.2       rvb  * notice  and  this  permission  notice  appear  in  all  copies  of the
     14  1.2       rvb  * software, derivative works or  modified  versions,  and  any  portions
     15  1.2       rvb  * thereof, and that both notices appear in supporting documentation, and
     16  1.2       rvb  * that credit is given to Carnegie Mellon University  in  all  documents
     17  1.2       rvb  * and publicity pertaining to direct or indirect use of this code or its
     18  1.2       rvb  * derivatives.
     19  1.2       rvb  *
     20  1.2       rvb  * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
     21  1.2       rvb  * SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
     22  1.2       rvb  * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
     23  1.2       rvb  * DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
     24  1.2       rvb  * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
     25  1.2       rvb  * ANY DERIVATIVE WORK.
     26  1.2       rvb  *
     27  1.2       rvb  * Carnegie  Mellon  encourages  users  of  this  software  to return any
     28  1.2       rvb  * improvements or extensions that  they  make,  and  to  grant  Carnegie
     29  1.2       rvb  * Mellon the rights to redistribute these changes without encumbrance.
     30  1.2       rvb  *
     31  1.4       rvb  * 	@(#) coda/coda_namecache.h,v 1.1.1.1 1998/08/29 21:26:46 rvb Exp $
     32  1.2       rvb  */
     33  1.1       rvb 
     34  1.1       rvb /*
     35  1.1       rvb  * Mach Operating System
     36  1.1       rvb  * Copyright (c) 1990 Carnegie-Mellon University
     37  1.1       rvb  * Copyright (c) 1989 Carnegie-Mellon University
     38  1.1       rvb  * All rights reserved.  The CMU software License Agreement specifies
     39  1.1       rvb  * the terms and conditions for use and redistribution.
     40  1.1       rvb  */
     41  1.1       rvb 
     42  1.1       rvb /*
     43  1.1       rvb  * This code was written for the Coda file system at Carnegie Mellon University.
     44  1.1       rvb  * Contributers include David Steere, James Kistler, and M. Satyanarayanan.
     45  1.1       rvb  */
     46  1.2       rvb 
     47  1.3       rvb #ifndef _CODA_NC_HEADER_
     48  1.3       rvb #define _CODA_NC_HEADER_
     49  1.1       rvb 
     50  1.1       rvb /*
     51  1.3       rvb  * Coda constants
     52  1.1       rvb  */
     53  1.3       rvb #define CODA_NC_NAMELEN		15		/* longest name stored in cache */
     54  1.3       rvb #define CODA_NC_CACHESIZE	 256		/* Default cache size */
     55  1.3       rvb #define CODA_NC_HASHSIZE	64		/* Must be multiple of 2 */
     56  1.1       rvb 
     57  1.1       rvb /*
     58  1.1       rvb  * Hash function for the primary hash.
     59  1.1       rvb  */
     60  1.1       rvb 
     61  1.1       rvb /*
     62  1.1       rvb  * First try -- (first + last letters + length + (int)cp) mod size
     63  1.1       rvb  * 2nd try -- same, except dir fid.vnode instead of cp
     64  1.1       rvb  */
     65  1.1       rvb 
     66  1.1       rvb #ifdef	oldhash
     67  1.3       rvb #define CODA_NC_HASH(name, namelen, cp) \
     68  1.5      ross 	((name[0] + name[namelen-1] + namelen + (int)(long)(cp)) \
     69  1.5      ross 	  & (coda_nc_hashsize-1))
     70  1.1       rvb #else
     71  1.3       rvb #define CODA_NC_HASH(name, namelen, cp) \
     72  1.5      ross 	((name[0] + (name[namelen-1]<<4) + namelen + (((int)(long)cp)>>8)) \
     73  1.5      ross 	  & (coda_nc_hashsize-1))
     74  1.1       rvb #endif
     75  1.1       rvb 
     76  1.3       rvb #define CODA_NAMEMATCH(cp, name, namelen, dcp) \
     77  1.1       rvb 	((namelen == cp->namelen) && (dcp == cp->dcp) && \
     78  1.1       rvb 		 (bcmp(cp->name,name,namelen) == 0))
     79  1.1       rvb 
     80  1.1       rvb /*
     81  1.1       rvb  * Functions to modify the hash and lru chains.
     82  1.1       rvb  * insque and remque assume that the pointers are the first thing
     83  1.1       rvb  * in the list node, thus the trickery for lru.
     84  1.1       rvb  */
     85  1.1       rvb 
     86  1.3       rvb #define CODA_NC_HSHINS(elem, pred)	insque(elem,pred)
     87  1.3       rvb #define CODA_NC_HSHREM(elem)		remque(elem)
     88  1.3       rvb #define CODA_NC_HSHNUL(elem)		(elem)->hash_next = \
     89  1.1       rvb 					(elem)->hash_prev = (elem)
     90  1.1       rvb 
     91  1.3       rvb #define CODA_NC_LRUINS(elem, pred)	insque(LRU_PART(elem), LRU_PART(pred))
     92  1.3       rvb #define CODA_NC_LRUREM(elem)		remque(LRU_PART(elem));
     93  1.3       rvb #define CODA_NC_LRUGET(lruhead)		LRU_TOP((lruhead).lru_prev)
     94  1.1       rvb 
     95  1.3       rvb #define CODA_NC_VALID(cncp)	(cncp->dcp != (struct cnode *)0)
     96  1.1       rvb 
     97  1.3       rvb #define LRU_PART(cncp)			(struct coda_cache *) \
     98  1.3       rvb 				((char *)cncp + (2*sizeof(struct coda_cache *)))
     99  1.3       rvb #define LRU_TOP(cncp)				(struct coda_cache *) \
    100  1.3       rvb 			((char *)cncp - (2*sizeof(struct coda_cache *)))
    101  1.3       rvb #define DATA_PART(cncp)				(struct coda_cache *) \
    102  1.3       rvb 			((char *)cncp + (4*sizeof(struct coda_cache *)))
    103  1.3       rvb #define DATA_SIZE	(sizeof(struct coda_cache)-(4*sizeof(struct coda_cache *)))
    104  1.1       rvb 
    105  1.1       rvb /*
    106  1.3       rvb  * Structure for an element in the CODA Name Cache.
    107  1.1       rvb  * NOTE: I use the position of arguments and their size in the
    108  1.3       rvb  * implementation of the functions CODA_NC_LRUINS, CODA_NC_LRUREM, and
    109  1.1       rvb  * DATA_PART.
    110  1.1       rvb  */
    111  1.1       rvb 
    112  1.3       rvb struct coda_cache {
    113  1.3       rvb 	struct coda_cache	*hash_next,*hash_prev;	/* Hash list */
    114  1.3       rvb 	struct coda_cache	*lru_next, *lru_prev;	/* LRU list */
    115  1.1       rvb 	struct cnode	*cp;			/* vnode of the file */
    116  1.1       rvb 	struct cnode	*dcp;			/* parent's cnode */
    117  1.1       rvb 	struct ucred	*cred;			/* user credentials */
    118  1.3       rvb 	char		name[CODA_NC_NAMELEN];	/* segment name */
    119  1.1       rvb 	int		namelen;		/* length of name */
    120  1.1       rvb };
    121  1.1       rvb 
    122  1.3       rvb struct	coda_lru {		/* Start of LRU chain */
    123  1.1       rvb 	char *dummy1, *dummy2;			/* place holders */
    124  1.3       rvb 	struct coda_cache *lru_next, *lru_prev;   /* position of pointers is important */
    125  1.1       rvb };
    126  1.1       rvb 
    127  1.1       rvb 
    128  1.3       rvb struct coda_hash {		/* Start of Hash chain */
    129  1.3       rvb 	struct coda_cache *hash_next, *hash_prev; /* NOTE: chain pointers must be first */
    130  1.1       rvb         int length;                             /* used for tuning purposes */
    131  1.1       rvb };
    132  1.1       rvb 
    133  1.1       rvb 
    134  1.1       rvb /*
    135  1.1       rvb  * Symbols to aid in debugging the namecache code. Assumes the existence
    136  1.3       rvb  * of the variable coda_nc_debug, which is defined in cfs_namecache.c
    137  1.1       rvb  */
    138  1.3       rvb #define CODA_NC_DEBUG(N, STMT)     { if (coda_nc_debug & (1 <<N)) { STMT } }
    139  1.1       rvb 
    140  1.1       rvb /* Prototypes of functions exported within cfs */
    141  1.3       rvb extern void coda_nc_init(void);
    142  1.3       rvb extern void coda_nc_enter(struct cnode *, const char *, int, struct ucred *, struct cnode *);
    143  1.3       rvb extern struct cnode *coda_nc_lookup(struct cnode *, const char *, int, struct ucred *);
    144  1.3       rvb 
    145  1.7  drochner extern void coda_nc_zapParentfid(CodaFid *, enum dc_status);
    146  1.7  drochner extern void coda_nc_zapfid(CodaFid *, enum dc_status);
    147  1.7  drochner extern void coda_nc_zapvnode(CodaFid *, struct ucred *, enum dc_status);
    148  1.3       rvb extern void coda_nc_zapfile(struct cnode *, const char *, int);
    149  1.7  drochner extern void coda_nc_purge_user(uid_t, enum dc_status);
    150  1.3       rvb extern void coda_nc_flush(enum dc_status);
    151  1.3       rvb 
    152  1.3       rvb extern void print_coda_nc(void);
    153  1.3       rvb extern void coda_nc_gather_stats(void);
    154  1.3       rvb extern int  coda_nc_resize(int, int, enum dc_status);
    155  1.3       rvb extern void coda_nc_name(struct cnode *cp);
    156  1.1       rvb 
    157  1.1       rvb /*
    158  1.1       rvb  * Structure to contain statistics on the cache usage
    159  1.1       rvb  */
    160  1.1       rvb 
    161  1.3       rvb struct coda_nc_statistics {
    162  1.1       rvb 	unsigned	hits;
    163  1.1       rvb 	unsigned	misses;
    164  1.1       rvb 	unsigned	enters;
    165  1.1       rvb 	unsigned	dbl_enters;
    166  1.1       rvb 	unsigned	long_name_enters;
    167  1.1       rvb 	unsigned	long_name_lookups;
    168  1.1       rvb 	unsigned	long_remove;
    169  1.1       rvb 	unsigned	lru_rm;
    170  1.1       rvb 	unsigned	zapPfids;
    171  1.1       rvb 	unsigned	zapFids;
    172  1.1       rvb 	unsigned	zapFile;
    173  1.1       rvb 	unsigned	zapUsers;
    174  1.1       rvb 	unsigned	Flushes;
    175  1.1       rvb 	unsigned        Sum_bucket_len;
    176  1.1       rvb 	unsigned        Sum2_bucket_len;
    177  1.1       rvb 	unsigned        Max_bucket_len;
    178  1.1       rvb 	unsigned        Num_zero_len;
    179  1.1       rvb 	unsigned        Search_len;
    180  1.1       rvb };
    181  1.1       rvb 
    182  1.3       rvb #define CODA_NC_FIND		((u_long) 1)
    183  1.3       rvb #define CODA_NC_REMOVE		((u_long) 2)
    184  1.3       rvb #define CODA_NC_INIT		((u_long) 3)
    185  1.3       rvb #define CODA_NC_ENTER		((u_long) 4)
    186  1.3       rvb #define CODA_NC_LOOKUP		((u_long) 5)
    187  1.3       rvb #define CODA_NC_ZAPPFID		((u_long) 6)
    188  1.3       rvb #define CODA_NC_ZAPFID		((u_long) 7)
    189  1.3       rvb #define CODA_NC_ZAPVNODE		((u_long) 8)
    190  1.3       rvb #define CODA_NC_ZAPFILE		((u_long) 9)
    191  1.3       rvb #define CODA_NC_PURGEUSER		((u_long) 10)
    192  1.3       rvb #define CODA_NC_FLUSH		((u_long) 11)
    193  1.3       rvb #define CODA_NC_PRINTCODA_NC	((u_long) 12)
    194  1.3       rvb #define CODA_NC_PRINTSTATS	((u_long) 13)
    195  1.1       rvb 
    196  1.1       rvb #endif /* _CFSNC_HEADER_ */
    197