1 /* $NetBSD: coda_namecache.h,v 1.6 1999/10/17 23:39:15 cgd 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 #ifndef _CODA_NC_HEADER_ 48 #define _CODA_NC_HEADER_ 49 50 /* 51 * Coda constants 52 */ 53 #define CODA_NC_NAMELEN 15 /* longest name stored in cache */ 54 #define CODA_NC_CACHESIZE 256 /* Default cache size */ 55 #define CODA_NC_HASHSIZE 64 /* Must be multiple of 2 */ 56 57 /* 58 * Hash function for the primary hash. 59 */ 60 61 /* 62 * First try -- (first + last letters + length + (int)cp) mod size 63 * 2nd try -- same, except dir fid.vnode instead of cp 64 */ 65 66 #ifdef oldhash 67 #define CODA_NC_HASH(name, namelen, cp) \ 68 ((name[0] + name[namelen-1] + namelen + (int)(long)(cp)) \ 69 & (coda_nc_hashsize-1)) 70 #else 71 #define CODA_NC_HASH(name, namelen, cp) \ 72 ((name[0] + (name[namelen-1]<<4) + namelen + (((int)(long)cp)>>8)) \ 73 & (coda_nc_hashsize-1)) 74 #endif 75 76 #define CODA_NAMEMATCH(cp, name, namelen, dcp) \ 77 ((namelen == cp->namelen) && (dcp == cp->dcp) && \ 78 (bcmp(cp->name,name,namelen) == 0)) 79 80 /* 81 * Functions to modify the hash and lru chains. 82 * insque and remque assume that the pointers are the first thing 83 * in the list node, thus the trickery for lru. 84 */ 85 86 #define CODA_NC_HSHINS(elem, pred) insque(elem,pred) 87 #define CODA_NC_HSHREM(elem) remque(elem) 88 #define CODA_NC_HSHNUL(elem) (elem)->hash_next = \ 89 (elem)->hash_prev = (elem) 90 91 #define CODA_NC_LRUINS(elem, pred) insque(LRU_PART(elem), LRU_PART(pred)) 92 #define CODA_NC_LRUREM(elem) remque(LRU_PART(elem)); 93 #define CODA_NC_LRUGET(lruhead) LRU_TOP((lruhead).lru_prev) 94 95 #define CODA_NC_VALID(cncp) (cncp->dcp != (struct cnode *)0) 96 97 #define LRU_PART(cncp) (struct coda_cache *) \ 98 ((char *)cncp + (2*sizeof(struct coda_cache *))) 99 #define LRU_TOP(cncp) (struct coda_cache *) \ 100 ((char *)cncp - (2*sizeof(struct coda_cache *))) 101 #define DATA_PART(cncp) (struct coda_cache *) \ 102 ((char *)cncp + (4*sizeof(struct coda_cache *))) 103 #define DATA_SIZE (sizeof(struct coda_cache)-(4*sizeof(struct coda_cache *))) 104 105 /* 106 * Structure for an element in the CODA Name Cache. 107 * NOTE: I use the position of arguments and their size in the 108 * implementation of the functions CODA_NC_LRUINS, CODA_NC_LRUREM, and 109 * DATA_PART. 110 */ 111 112 struct coda_cache { 113 struct coda_cache *hash_next,*hash_prev; /* Hash list */ 114 struct coda_cache *lru_next, *lru_prev; /* LRU list */ 115 struct cnode *cp; /* vnode of the file */ 116 struct cnode *dcp; /* parent's cnode */ 117 struct ucred *cred; /* user credentials */ 118 char name[CODA_NC_NAMELEN]; /* segment name */ 119 int namelen; /* length of name */ 120 }; 121 122 struct coda_lru { /* Start of LRU chain */ 123 char *dummy1, *dummy2; /* place holders */ 124 struct coda_cache *lru_next, *lru_prev; /* position of pointers is important */ 125 }; 126 127 128 struct coda_hash { /* Start of Hash chain */ 129 struct coda_cache *hash_next, *hash_prev; /* NOTE: chain pointers must be first */ 130 int length; /* used for tuning purposes */ 131 }; 132 133 134 /* 135 * Symbols to aid in debugging the namecache code. Assumes the existence 136 * of the variable coda_nc_debug, which is defined in cfs_namecache.c 137 */ 138 #define CODA_NC_DEBUG(N, STMT) { if (coda_nc_debug & (1 <<N)) { STMT } } 139 140 /* Prototypes of functions exported within cfs */ 141 extern void coda_nc_init(void); 142 extern void coda_nc_enter(struct cnode *, const char *, int, struct ucred *, struct cnode *); 143 extern struct cnode *coda_nc_lookup(struct cnode *, const char *, int, struct ucred *); 144 145 extern void coda_nc_zapParentfid(ViceFid *, enum dc_status); 146 extern void coda_nc_zapfid(ViceFid *, enum dc_status); 147 extern void coda_nc_zapvnode(ViceFid *, struct ucred *, enum dc_status); 148 extern void coda_nc_zapfile(struct cnode *, const char *, int); 149 extern void coda_nc_purge_user(vuid_t, enum dc_status); 150 extern void coda_nc_flush(enum dc_status); 151 152 extern void print_coda_nc(void); 153 extern void coda_nc_gather_stats(void); 154 extern int coda_nc_resize(int, int, enum dc_status); 155 extern void coda_nc_name(struct cnode *cp); 156 157 /* 158 * Structure to contain statistics on the cache usage 159 */ 160 161 struct coda_nc_statistics { 162 unsigned hits; 163 unsigned misses; 164 unsigned enters; 165 unsigned dbl_enters; 166 unsigned long_name_enters; 167 unsigned long_name_lookups; 168 unsigned long_remove; 169 unsigned lru_rm; 170 unsigned zapPfids; 171 unsigned zapFids; 172 unsigned zapFile; 173 unsigned zapUsers; 174 unsigned Flushes; 175 unsigned Sum_bucket_len; 176 unsigned Sum2_bucket_len; 177 unsigned Max_bucket_len; 178 unsigned Num_zero_len; 179 unsigned Search_len; 180 }; 181 182 #define CODA_NC_FIND ((u_long) 1) 183 #define CODA_NC_REMOVE ((u_long) 2) 184 #define CODA_NC_INIT ((u_long) 3) 185 #define CODA_NC_ENTER ((u_long) 4) 186 #define CODA_NC_LOOKUP ((u_long) 5) 187 #define CODA_NC_ZAPPFID ((u_long) 6) 188 #define CODA_NC_ZAPFID ((u_long) 7) 189 #define CODA_NC_ZAPVNODE ((u_long) 8) 190 #define CODA_NC_ZAPFILE ((u_long) 9) 191 #define CODA_NC_PURGEUSER ((u_long) 10) 192 #define CODA_NC_FLUSH ((u_long) 11) 193 #define CODA_NC_PRINTCODA_NC ((u_long) 12) 194 #define CODA_NC_PRINTSTATS ((u_long) 13) 195 196 #endif /* _CFSNC_HEADER_ */ 197