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