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