coda_namecache.c revision 1.8 1 1.8 rvb /* $NetBSD: coda_namecache.c,v 1.8 1998/10/28 19:54:50 rvb 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.c,v 1.1.1.1 1998/08/29 21:26:45 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.c,v $
50 1.8 rvb * Revision 1.8 1998/10/28 19:54:50 rvb
51 1.8 rvb * Venus must be passed O_CREAT flag on VOP_OPEN iff this is
52 1.8 rvb * a creat so that we can will allow a mode 444 file to be
53 1.8 rvb * written into. Sync with the latest coda.h and deal with
54 1.8 rvb * collateral damage.
55 1.7 rvb *
56 1.7 rvb * Revision 1.7 1998/09/28 17:55:21 rvb
57 1.7 rvb * I want to distinguish from DEBUG printouts and CODA_VERBOSE printouts.
58 1.7 rvb * The latter are normal informational messages that are sometimes
59 1.7 rvb * interesting to view.
60 1.6 tv *
61 1.6 tv * Revision 1.6 1998/09/26 15:24:46 tv
62 1.6 tv * DIAGNOSTIC -> DEBUG for all non-panic messages. DIAGNOSTIC is only for
63 1.6 tv * sanity checks and should not turn on any messages not already printed
64 1.6 tv * without it.
65 1.5 rvb *
66 1.5 rvb * Revision 1.5 1998/09/25 15:01:12 rvb
67 1.5 rvb * Conditionalize "stray" printouts under DIAGNOSTIC and DEBUG.
68 1.4 rvb * Make files compile if DEBUG is on (from Alan Barrett). Finally,
69 1.4 rvb * make coda an lkm.
70 1.4 rvb *
71 1.4 rvb * Revision 1.4 1998/09/15 02:02:58 rvb
72 1.3 rvb * Final piece of rename cfs->coda
73 1.3 rvb *
74 1.3 rvb * Revision 1.3 1998/09/12 15:05:48 rvb
75 1.2 rvb * Change cfs/CFS in symbols, strings and constants to coda/CODA
76 1.2 rvb * to avoid fs conflicts.
77 1.2 rvb *
78 1.1 rvb * Revision 1.2 1998/09/08 17:12:46 rvb
79 1.1 rvb * Pass2 complete
80 1.1 rvb *
81 1.1 rvb * Revision 1.1.1.1 1998/08/29 21:26:45 rvb
82 1.1 rvb * Very Preliminary Coda
83 1.1 rvb *
84 1.1 rvb * Revision 1.11 1998/08/28 18:12:16 rvb
85 1.1 rvb * Now it also works on FreeBSD -current. This code will be
86 1.1 rvb * committed to the FreeBSD -current and NetBSD -current
87 1.1 rvb * trees. It will then be tailored to the particular platform
88 1.1 rvb * by flushing conditional code.
89 1.1 rvb *
90 1.1 rvb * Revision 1.10 1998/08/18 17:05:14 rvb
91 1.1 rvb * Don't use __RCSID now
92 1.1 rvb *
93 1.1 rvb * Revision 1.9 1998/08/18 16:31:39 rvb
94 1.3 rvb * Sync the code for NetBSD -current; test on 1.3 later
95 1.1 rvb *
96 1.1 rvb * Revision 1.8 98/01/31 20:53:10 rvb
97 1.1 rvb * First version that works on FreeBSD 2.2.5
98 1.1 rvb *
99 1.1 rvb * Revision 1.7 98/01/23 11:53:39 rvb
100 1.1 rvb * Bring RVB_CODA1_1 to HEAD
101 1.1 rvb *
102 1.1 rvb * Revision 1.6.2.4 98/01/23 11:21:02 rvb
103 1.1 rvb * Sync with 2.2.5
104 1.1 rvb *
105 1.1 rvb * Revision 1.6.2.3 97/12/16 12:40:03 rvb
106 1.1 rvb * Sync with 1.3
107 1.1 rvb *
108 1.1 rvb * Revision 1.6.2.2 97/12/09 16:07:10 rvb
109 1.1 rvb * Sync with vfs/include/coda.h
110 1.1 rvb *
111 1.1 rvb * Revision 1.6.2.1 97/12/06 17:41:18 rvb
112 1.1 rvb * Sync with peters coda.h
113 1.1 rvb *
114 1.1 rvb * Revision 1.6 97/12/05 10:39:13 rvb
115 1.1 rvb * Read CHANGES
116 1.1 rvb *
117 1.1 rvb * Revision 1.5.4.7 97/11/25 08:08:43 rvb
118 1.1 rvb * cfs_venus ... done; until cred/vattr change
119 1.1 rvb *
120 1.1 rvb * Revision 1.5.4.6 97/11/24 15:44:43 rvb
121 1.1 rvb * Final cfs_venus.c w/o macros, but one locking bug
122 1.1 rvb *
123 1.1 rvb * Revision 1.5.4.5 97/11/20 11:46:38 rvb
124 1.1 rvb * Capture current cfs_venus
125 1.1 rvb *
126 1.1 rvb * Revision 1.5.4.4 97/11/18 10:27:13 rvb
127 1.1 rvb * cfs_nbsd.c is DEAD!!!; integrated into cfs_vf/vnops.c
128 1.1 rvb * cfs_nb_foo and cfs_foo are joined
129 1.1 rvb *
130 1.1 rvb * Revision 1.5.4.3 97/11/13 22:02:57 rvb
131 1.1 rvb * pass2 cfs_NetBSD.h mt
132 1.1 rvb *
133 1.1 rvb * Revision 1.5.4.2 97/11/12 12:09:35 rvb
134 1.3 rvb * reorg pass1
135 1.1 rvb *
136 1.1 rvb * Revision 1.5.4.1 97/10/28 23:10:12 rvb
137 1.1 rvb * >64Meg; venus can be killed!
138 1.1 rvb *
139 1.1 rvb * Revision 1.5 97/08/05 11:08:01 lily
140 1.1 rvb * Removed cfsnc_replace, replaced it with a coda_find, unhash, and
141 1.1 rvb * rehash. This fixes a cnode leak and a bug in which the fid is
142 1.1 rvb * not actually replaced. (cfs_namecache.c, cfsnc.h, cfs_subr.c)
143 1.1 rvb *
144 1.1 rvb * Revision 1.4 96/12/12 22:10:57 bnoble
145 1.1 rvb * Fixed the "downcall invokes venus operation" deadlock in all known cases.
146 1.1 rvb * There may be more
147 1.1 rvb *
148 1.1 rvb * Revision 1.3 1996/11/08 18:06:09 bnoble
149 1.1 rvb * Minor changes in vnode operation signature, VOP_UPDATE signature, and
150 1.3 rvb * some newly defined bits in the include files.
151 1.1 rvb *
152 1.1 rvb * Revision 1.2 1996/01/02 16:56:50 bnoble
153 1.1 rvb * Added support for Coda MiniCache and raw inode calls (final commit)
154 1.1 rvb *
155 1.1 rvb * Revision 1.1.2.1 1995/12/20 01:57:15 bnoble
156 1.1 rvb * Added CODA-specific files
157 1.1 rvb *
158 1.1 rvb * Revision 3.1.1.1 1995/03/04 19:07:57 bnoble
159 1.1 rvb * Branch for NetBSD port revisions
160 1.1 rvb *
161 1.1 rvb * Revision 3.1 1995/03/04 19:07:56 bnoble
162 1.3 rvb * Bump to major revision 3 to prepare for NetBSD port
163 1.1 rvb *
164 1.1 rvb * Revision 2.3 1994/10/14 09:57:54 dcs
165 1.1 rvb * Made changes 'cause sun4s have braindead compilers
166 1.3 rvb *
167 1.1 rvb * Revision 2.2 94/08/28 19:37:35 luqi
168 1.1 rvb * Add a new CODA_REPLACE call to allow venus to replace a ViceFid in the
169 1.1 rvb * mini-cache.
170 1.1 rvb *
171 1.1 rvb * In "cfs.h":
172 1.3 rvb * Add CODA_REPLACE decl.
173 1.1 rvb *
174 1.1 rvb * In "cfs_namecache.c":
175 1.3 rvb * Add routine cfsnc_replace.
176 1.1 rvb *
177 1.1 rvb * In "cfs_subr.c":
178 1.1 rvb * Add case-statement to process CODA_REPLACE.
179 1.1 rvb *
180 1.1 rvb * In "cfsnc.h":
181 1.1 rvb * Add decl for CODA_NC_REPLACE.
182 1.1 rvb *
183 1.1 rvb *
184 1.1 rvb * Revision 2.1 94/07/21 16:25:15 satya
185 1.3 rvb * Conversion to C++ 3.0; start of Coda Release 2.0
186 1.1 rvb *
187 1.1 rvb * Revision 1.2 92/10/27 17:58:21 lily
188 1.1 rvb * merge kernel/latest and alpha/src/cfs
189 1.1 rvb *
190 1.1 rvb * Revision 2.3 92/09/30 14:16:20 mja
191 1.1 rvb * call coda_flush instead of calling inode_uncache_try directly
192 1.1 rvb * (from dcs). Also...
193 1.1 rvb *
194 1.1 rvb * Substituted rvb's history blurb so that we agree with Mach 2.5 sources.
195 1.1 rvb * [91/02/09 jjk]
196 1.1 rvb *
197 1.1 rvb * Added contributors blurb.
198 1.1 rvb * [90/12/13 jjk]
199 1.1 rvb *
200 1.1 rvb * Revision 2.2 90/07/05 11:26:30 mrt
201 1.1 rvb * Created for the Coda File System.
202 1.1 rvb * [90/05/23 dcs]
203 1.1 rvb *
204 1.1 rvb * Revision 1.3 90/05/31 17:01:24 dcs
205 1.3 rvb * Prepare for merge with facilities kernel.
206 1.1 rvb *
207 1.1 rvb *
208 1.1 rvb */
209 1.1 rvb
210 1.1 rvb /*
211 1.1 rvb * This module contains the routines to implement the CODA name cache. The
212 1.1 rvb * purpose of this cache is to reduce the cost of translating pathnames
213 1.1 rvb * into Vice FIDs. Each entry in the cache contains the name of the file,
214 1.1 rvb * the vnode (FID) of the parent directory, and the cred structure of the
215 1.1 rvb * user accessing the file.
216 1.1 rvb *
217 1.1 rvb * The first time a file is accessed, it is looked up by the local Venus
218 1.1 rvb * which first insures that the user has access to the file. In addition
219 1.1 rvb * we are guaranteed that Venus will invalidate any name cache entries in
220 1.1 rvb * case the user no longer should be able to access the file. For these
221 1.1 rvb * reasons we do not need to keep access list information as well as a
222 1.1 rvb * cred structure for each entry.
223 1.1 rvb *
224 1.1 rvb * The table can be accessed through the routines cnc_init(), cnc_enter(),
225 1.1 rvb * cnc_lookup(), cnc_rmfidcred(), cnc_rmfid(), cnc_rmcred(), and cnc_purge().
226 1.1 rvb * There are several other routines which aid in the implementation of the
227 1.1 rvb * hash table.
228 1.3 rvb */
229 1.3 rvb
230 1.1 rvb /*
231 1.1 rvb * NOTES: rvb@cs
232 1.1 rvb * 1. The name cache holds a reference to every vnode in it. Hence files can not be
233 1.1 rvb * closed or made inactive until they are released.
234 1.1 rvb * 2. coda_nc_name(cp) was added to get a name for a cnode pointer for debugging.
235 1.1 rvb * 3. coda_nc_find() has debug code to detect when entries are stored with different
236 1.1 rvb * credentials. We don't understand yet, if/how entries are NOT EQ but still
237 1.1 rvb * EQUAL
238 1.1 rvb * 4. I wonder if this name cache could be replace by the vnode name cache.
239 1.1 rvb * The latter has no zapping functions, so probably not.
240 1.1 rvb */
241 1.4 rvb
242 1.4 rvb #include <sys/param.h>
243 1.4 rvb #include <sys/errno.h>
244 1.1 rvb #include <sys/malloc.h>
245 1.5 rvb #include <sys/select.h>
246 1.5 rvb
247 1.5 rvb #include <coda/coda.h>
248 1.5 rvb #include <coda/cnode.h>
249 1.1 rvb #include <coda/coda_namecache.h>
250 1.1 rvb
251 1.1 rvb #ifdef DEBUG
252 1.1 rvb #include <coda/coda_vnops.h>
253 1.1 rvb #endif
254 1.1 rvb
255 1.1 rvb #ifndef insque
256 1.1 rvb #include <sys/systm.h>
257 1.3 rvb #endif /* insque */
258 1.1 rvb
259 1.3 rvb /*
260 1.3 rvb * Declaration of the name cache data structure.
261 1.1 rvb */
262 1.3 rvb
263 1.3 rvb int coda_nc_use = 1; /* Indicate use of CODA Name Cache */
264 1.3 rvb
265 1.1 rvb int coda_nc_size = CODA_NC_CACHESIZE; /* size of the cache */
266 1.3 rvb int coda_nc_hashsize = CODA_NC_HASHSIZE; /* size of the primary hash */
267 1.1 rvb
268 1.1 rvb struct coda_cache *coda_nc_heap; /* pointer to the cache entries */
269 1.1 rvb struct coda_hash *coda_nc_hash; /* hash table of cfscache pointers */
270 1.1 rvb struct coda_lru coda_nc_lru; /* head of lru chain */
271 1.3 rvb
272 1.1 rvb struct coda_nc_statistics coda_nc_stat; /* Keep various stats */
273 1.1 rvb
274 1.3 rvb /*
275 1.1 rvb * for testing purposes
276 1.3 rvb */
277 1.3 rvb int coda_nc_debug = 0;
278 1.1 rvb
279 1.1 rvb /*
280 1.3 rvb * Entry points for the CODA Name Cache
281 1.1 rvb */
282 1.1 rvb static struct coda_cache *
283 1.1 rvb coda_nc_find(struct cnode *dcp, const char *name, int namelen,
284 1.1 rvb struct ucred *cred, int hash);
285 1.1 rvb static void
286 1.3 rvb coda_nc_remove(struct coda_cache *cncp, enum dc_status dcstat);
287 1.3 rvb
288 1.1 rvb /*
289 1.3 rvb * Initialize the cache, the LRU structure and the Hash structure(s)
290 1.1 rvb */
291 1.1 rvb
292 1.3 rvb #define TOTAL_CACHE_SIZE (sizeof(struct coda_cache) * coda_nc_size)
293 1.1 rvb #define TOTAL_HASH_SIZE (sizeof(struct coda_hash) * coda_nc_hashsize)
294 1.1 rvb
295 1.1 rvb int coda_nc_initialized = 0; /* Initially the cache has not been initialized */
296 1.1 rvb
297 1.1 rvb void
298 1.3 rvb coda_nc_init(void)
299 1.1 rvb {
300 1.7 rvb int i;
301 1.3 rvb
302 1.5 rvb /* zero the statistics structure */
303 1.3 rvb
304 1.3 rvb bzero(&coda_nc_stat, (sizeof(struct coda_nc_statistics)));
305 1.1 rvb
306 1.3 rvb #ifdef CODA_VERBOSE
307 1.3 rvb printf("CODA NAME CACHE: CACHE %d, HASH TBL %d\n", CODA_NC_CACHESIZE, CODA_NC_HASHSIZE);
308 1.1 rvb #endif
309 1.1 rvb CODA_ALLOC(coda_nc_heap, struct coda_cache *, TOTAL_CACHE_SIZE);
310 1.3 rvb CODA_ALLOC(coda_nc_hash, struct coda_hash *, TOTAL_HASH_SIZE);
311 1.3 rvb
312 1.3 rvb coda_nc_lru.lru_next =
313 1.3 rvb coda_nc_lru.lru_prev = (struct coda_cache *)LRU_PART(&coda_nc_lru);
314 1.1 rvb
315 1.1 rvb
316 1.3 rvb for (i=0; i < coda_nc_size; i++) { /* initialize the heap */
317 1.3 rvb CODA_NC_LRUINS(&coda_nc_heap[i], &coda_nc_lru);
318 1.1 rvb CODA_NC_HSHNUL(&coda_nc_heap[i]);
319 1.1 rvb coda_nc_heap[i].cp = coda_nc_heap[i].dcp = (struct cnode *)0;
320 1.3 rvb }
321 1.1 rvb
322 1.1 rvb for (i=0; i < coda_nc_hashsize; i++) { /* initialize the hashtable */
323 1.1 rvb CODA_NC_HSHNUL((struct coda_cache *)&coda_nc_hash[i]);
324 1.1 rvb }
325 1.1 rvb
326 1.1 rvb coda_nc_initialized++;
327 1.3 rvb }
328 1.3 rvb
329 1.1 rvb /*
330 1.1 rvb * Auxillary routines -- shouldn't be entry points
331 1.1 rvb */
332 1.1 rvb
333 1.1 rvb static struct coda_cache *
334 1.1 rvb coda_nc_find(dcp, name, namelen, cred, hash)
335 1.1 rvb struct cnode *dcp;
336 1.1 rvb const char *name;
337 1.1 rvb int namelen;
338 1.1 rvb struct ucred *cred;
339 1.3 rvb int hash;
340 1.1 rvb {
341 1.1 rvb /*
342 1.3 rvb * hash to find the appropriate bucket, look through the chain
343 1.3 rvb * for the right entry (especially right cred, unless cred == 0)
344 1.1 rvb */
345 1.1 rvb struct coda_cache *cncp;
346 1.3 rvb int count = 1;
347 1.3 rvb
348 1.1 rvb CODA_NC_DEBUG(CODA_NC_FIND,
349 1.1 rvb myprintf(("coda_nc_find(dcp %p, name %s, len %d, cred %p, hash %d\n",
350 1.1 rvb dcp, name, namelen, cred, hash));)
351 1.3 rvb
352 1.1 rvb for (cncp = coda_nc_hash[hash].hash_next;
353 1.1 rvb cncp != (struct coda_cache *)&coda_nc_hash[hash];
354 1.1 rvb cncp = cncp->hash_next, count++)
355 1.3 rvb {
356 1.1 rvb
357 1.1 rvb if ((CODA_NAMEMATCH(cncp, name, namelen, dcp)) &&
358 1.1 rvb ((cred == 0) || (cncp->cred == cred)))
359 1.3 rvb {
360 1.3 rvb /* compare cr_uid instead */
361 1.1 rvb coda_nc_stat.Search_len += count;
362 1.1 rvb return(cncp);
363 1.1 rvb }
364 1.1 rvb #ifdef DEBUG
365 1.1 rvb else if (CODA_NAMEMATCH(cncp, name, namelen, dcp)) {
366 1.1 rvb printf("coda_nc_find: name %s, new cred = %p, cred = %p\n",
367 1.1 rvb name, cred, cncp->cred);
368 1.1 rvb printf("nref %d, nuid %d, ngid %d // oref %d, ocred %d, ogid %d\n",
369 1.1 rvb cred->cr_ref, cred->cr_uid, cred->cr_gid,
370 1.1 rvb cncp->cred->cr_ref, cncp->cred->cr_uid, cncp->cred->cr_gid);
371 1.3 rvb print_cred(cred);
372 1.1 rvb print_cred(cncp->cred);
373 1.1 rvb }
374 1.1 rvb #endif
375 1.1 rvb }
376 1.1 rvb
377 1.1 rvb return((struct coda_cache *)0);
378 1.1 rvb }
379 1.3 rvb
380 1.1 rvb /*
381 1.1 rvb * Enter a new (dir cnode, name) pair into the cache, updating the
382 1.1 rvb * LRU and Hash as needed.
383 1.1 rvb */
384 1.1 rvb void
385 1.1 rvb coda_nc_enter(dcp, name, namelen, cred, cp)
386 1.3 rvb struct cnode *dcp;
387 1.1 rvb const char *name;
388 1.1 rvb int namelen;
389 1.3 rvb struct ucred *cred;
390 1.1 rvb struct cnode *cp;
391 1.1 rvb {
392 1.3 rvb struct coda_cache *cncp;
393 1.1 rvb int hash;
394 1.1 rvb
395 1.1 rvb if (coda_nc_use == 0) /* Cache is off */
396 1.3 rvb return;
397 1.3 rvb
398 1.1 rvb CODA_NC_DEBUG(CODA_NC_ENTER,
399 1.3 rvb myprintf(("Enter: dcp %p cp %p name %s cred %p \n",
400 1.1 rvb dcp, cp, name, cred)); )
401 1.1 rvb
402 1.1 rvb if (namelen > CODA_NC_NAMELEN) {
403 1.3 rvb CODA_NC_DEBUG(CODA_NC_ENTER,
404 1.3 rvb myprintf(("long name enter %s\n",name));)
405 1.3 rvb coda_nc_stat.long_name_enters++; /* record stats */
406 1.3 rvb return;
407 1.1 rvb }
408 1.1 rvb
409 1.1 rvb hash = CODA_NC_HASH(name, namelen, dcp);
410 1.3 rvb cncp = coda_nc_find(dcp, name, namelen, cred, hash);
411 1.1 rvb if (cncp != (struct coda_cache *) 0) {
412 1.1 rvb coda_nc_stat.dbl_enters++; /* duplicate entry */
413 1.3 rvb return;
414 1.1 rvb }
415 1.3 rvb
416 1.1 rvb coda_nc_stat.enters++; /* record the enters statistic */
417 1.3 rvb
418 1.1 rvb /* Grab the next element in the lru chain */
419 1.1 rvb cncp = CODA_NC_LRUGET(coda_nc_lru);
420 1.1 rvb
421 1.3 rvb CODA_NC_LRUREM(cncp); /* remove it from the lists */
422 1.1 rvb
423 1.3 rvb if (CODA_NC_VALID(cncp)) {
424 1.3 rvb /* Seems really ugly, but we have to decrement the appropriate
425 1.1 rvb hash bucket length here, so we have to find the hash bucket
426 1.1 rvb */
427 1.1 rvb coda_nc_hash[CODA_NC_HASH(cncp->name, cncp->namelen, cncp->dcp)].length--;
428 1.1 rvb
429 1.1 rvb coda_nc_stat.lru_rm++; /* zapped a valid entry */
430 1.1 rvb CODA_NC_HSHREM(cncp);
431 1.1 rvb vrele(CTOV(cncp->dcp));
432 1.1 rvb vrele(CTOV(cncp->cp));
433 1.1 rvb crfree(cncp->cred);
434 1.1 rvb }
435 1.1 rvb
436 1.1 rvb /*
437 1.1 rvb * Put a hold on the current vnodes and fill in the cache entry.
438 1.1 rvb */
439 1.1 rvb vref(CTOV(cp));
440 1.1 rvb vref(CTOV(dcp));
441 1.1 rvb crhold(cred);
442 1.1 rvb cncp->dcp = dcp;
443 1.1 rvb cncp->cp = cp;
444 1.1 rvb cncp->namelen = namelen;
445 1.3 rvb cncp->cred = cred;
446 1.3 rvb
447 1.3 rvb bcopy(name, cncp->name, (unsigned)namelen);
448 1.1 rvb
449 1.3 rvb /* Insert into the lru and hash chains. */
450 1.1 rvb
451 1.1 rvb CODA_NC_LRUINS(cncp, &coda_nc_lru);
452 1.1 rvb CODA_NC_HSHINS(cncp, &coda_nc_hash[hash]);
453 1.1 rvb coda_nc_hash[hash].length++; /* Used for tuning */
454 1.1 rvb
455 1.1 rvb CODA_NC_DEBUG(CODA_NC_PRINTCODA_NC, print_coda_nc(); )
456 1.1 rvb }
457 1.3 rvb
458 1.1 rvb /*
459 1.1 rvb * Find the (dir cnode, name) pair in the cache, if it's cred
460 1.1 rvb * matches the input, return it, otherwise return 0
461 1.1 rvb */
462 1.1 rvb struct cnode *
463 1.1 rvb coda_nc_lookup(dcp, name, namelen, cred)
464 1.3 rvb struct cnode *dcp;
465 1.1 rvb const char *name;
466 1.3 rvb int namelen;
467 1.1 rvb struct ucred *cred;
468 1.1 rvb {
469 1.3 rvb int hash;
470 1.3 rvb struct coda_cache *cncp;
471 1.1 rvb
472 1.3 rvb if (coda_nc_use == 0) /* Cache is off */
473 1.1 rvb return((struct cnode *) 0);
474 1.1 rvb
475 1.1 rvb if (namelen > CODA_NC_NAMELEN) {
476 1.1 rvb CODA_NC_DEBUG(CODA_NC_LOOKUP,
477 1.1 rvb myprintf(("long name lookup %s\n",name));)
478 1.1 rvb coda_nc_stat.long_name_lookups++; /* record stats */
479 1.1 rvb return((struct cnode *) 0);
480 1.1 rvb }
481 1.3 rvb
482 1.3 rvb /* Use the hash function to locate the starting point,
483 1.3 rvb then the search routine to go down the list looking for
484 1.3 rvb the correct cred.
485 1.1 rvb */
486 1.1 rvb
487 1.1 rvb hash = CODA_NC_HASH(name, namelen, dcp);
488 1.3 rvb cncp = coda_nc_find(dcp, name, namelen, cred, hash);
489 1.1 rvb if (cncp == (struct coda_cache *) 0) {
490 1.1 rvb coda_nc_stat.misses++; /* record miss */
491 1.3 rvb return((struct cnode *) 0);
492 1.3 rvb }
493 1.1 rvb
494 1.1 rvb coda_nc_stat.hits++;
495 1.1 rvb
496 1.3 rvb /* put this entry at the end of the LRU */
497 1.3 rvb CODA_NC_LRUREM(cncp);
498 1.1 rvb CODA_NC_LRUINS(cncp, &coda_nc_lru);
499 1.3 rvb
500 1.1 rvb /* move it to the front of the hash chain */
501 1.1 rvb /* don't need to change the hash bucket length */
502 1.1 rvb CODA_NC_HSHREM(cncp);
503 1.1 rvb CODA_NC_HSHINS(cncp, &coda_nc_hash[hash]);
504 1.1 rvb
505 1.1 rvb CODA_NC_DEBUG(CODA_NC_LOOKUP,
506 1.1 rvb printf("lookup: dcp %p, name %s, cred %p = cp %p\n",
507 1.3 rvb dcp, name, cred, cncp->cp); )
508 1.3 rvb
509 1.1 rvb return(cncp->cp);
510 1.1 rvb }
511 1.1 rvb
512 1.1 rvb static void
513 1.1 rvb coda_nc_remove(cncp, dcstat)
514 1.1 rvb struct coda_cache *cncp;
515 1.1 rvb enum dc_status dcstat;
516 1.3 rvb {
517 1.3 rvb /*
518 1.1 rvb * remove an entry -- vrele(cncp->dcp, cp), crfree(cred),
519 1.1 rvb * remove it from it's hash chain, and
520 1.1 rvb * place it at the head of the lru list.
521 1.3 rvb */
522 1.1 rvb CODA_NC_DEBUG(CODA_NC_REMOVE,
523 1.3 rvb myprintf(("coda_nc_remove %s from parent %lx.%lx.%lx\n",
524 1.1 rvb cncp->name, (cncp->dcp)->c_fid.Volume,
525 1.1 rvb (cncp->dcp)->c_fid.Vnode, (cncp->dcp)->c_fid.Unique));)
526 1.1 rvb
527 1.1 rvb CODA_NC_HSHREM(cncp);
528 1.1 rvb
529 1.1 rvb CODA_NC_HSHNUL(cncp); /* have it be a null chain */
530 1.1 rvb if ((dcstat == IS_DOWNCALL) && (CTOV(cncp->dcp)->v_usecount == 1)) {
531 1.1 rvb cncp->dcp->c_flags |= C_PURGING;
532 1.1 rvb }
533 1.1 rvb vrele(CTOV(cncp->dcp));
534 1.1 rvb
535 1.1 rvb if ((dcstat == IS_DOWNCALL) && (CTOV(cncp->cp)->v_usecount == 1)) {
536 1.1 rvb cncp->cp->c_flags |= C_PURGING;
537 1.1 rvb }
538 1.1 rvb vrele(CTOV(cncp->cp));
539 1.3 rvb
540 1.3 rvb crfree(cncp->cred);
541 1.1 rvb bzero(DATA_PART(cncp),DATA_SIZE);
542 1.1 rvb
543 1.1 rvb /* Put the null entry just after the least-recently-used entry */
544 1.1 rvb /* LRU_TOP adjusts the pointer to point to the top of the structure. */
545 1.1 rvb CODA_NC_LRUREM(cncp);
546 1.1 rvb CODA_NC_LRUINS(cncp, LRU_TOP(coda_nc_lru.lru_prev));
547 1.3 rvb }
548 1.1 rvb
549 1.1 rvb /*
550 1.1 rvb * Remove all entries with a parent which has the input fid.
551 1.1 rvb */
552 1.1 rvb void
553 1.1 rvb coda_nc_zapParentfid(fid, dcstat)
554 1.1 rvb ViceFid *fid;
555 1.1 rvb enum dc_status dcstat;
556 1.3 rvb {
557 1.1 rvb /* To get to a specific fid, we might either have another hashing
558 1.1 rvb function or do a sequential search through the cache for the
559 1.3 rvb appropriate entries. The later may be acceptable since I don't
560 1.1 rvb think callbacks or whatever Case 1 covers are frequent occurences.
561 1.1 rvb */
562 1.3 rvb struct coda_cache *cncp, *ncncp;
563 1.1 rvb int i;
564 1.1 rvb
565 1.1 rvb if (coda_nc_use == 0) /* Cache is off */
566 1.3 rvb return;
567 1.1 rvb
568 1.3 rvb CODA_NC_DEBUG(CODA_NC_ZAPPFID,
569 1.1 rvb myprintf(("ZapParent: fid 0x%lx, 0x%lx, 0x%lx \n",
570 1.1 rvb fid->Volume, fid->Vnode, fid->Unique)); )
571 1.1 rvb
572 1.1 rvb coda_nc_stat.zapPfids++;
573 1.1 rvb
574 1.1 rvb for (i = 0; i < coda_nc_hashsize; i++) {
575 1.3 rvb
576 1.3 rvb /*
577 1.1 rvb * Need to save the hash_next pointer in case we remove the
578 1.1 rvb * entry. remove causes hash_next to point to itself.
579 1.1 rvb */
580 1.1 rvb
581 1.1 rvb for (cncp = coda_nc_hash[i].hash_next;
582 1.3 rvb cncp != (struct coda_cache *)&coda_nc_hash[i];
583 1.3 rvb cncp = ncncp) {
584 1.1 rvb ncncp = cncp->hash_next;
585 1.1 rvb if ((cncp->dcp->c_fid.Volume == fid->Volume) &&
586 1.1 rvb (cncp->dcp->c_fid.Vnode == fid->Vnode) &&
587 1.1 rvb (cncp->dcp->c_fid.Unique == fid->Unique)) {
588 1.1 rvb coda_nc_hash[i].length--; /* Used for tuning */
589 1.1 rvb coda_nc_remove(cncp, dcstat);
590 1.1 rvb }
591 1.1 rvb }
592 1.1 rvb }
593 1.3 rvb }
594 1.1 rvb
595 1.1 rvb /*
596 1.1 rvb * Remove all entries which have the same fid as the input
597 1.1 rvb */
598 1.1 rvb void
599 1.1 rvb coda_nc_zapfid(fid, dcstat)
600 1.3 rvb ViceFid *fid;
601 1.1 rvb enum dc_status dcstat;
602 1.1 rvb {
603 1.3 rvb /* See comment for zapParentfid. This routine will be used
604 1.1 rvb if attributes are being cached.
605 1.1 rvb */
606 1.3 rvb struct coda_cache *cncp, *ncncp;
607 1.1 rvb int i;
608 1.1 rvb
609 1.1 rvb if (coda_nc_use == 0) /* Cache is off */
610 1.3 rvb return;
611 1.1 rvb
612 1.3 rvb CODA_NC_DEBUG(CODA_NC_ZAPFID,
613 1.3 rvb myprintf(("Zapfid: fid 0x%lx, 0x%lx, 0x%lx \n",
614 1.3 rvb fid->Volume, fid->Vnode, fid->Unique)); )
615 1.1 rvb
616 1.1 rvb coda_nc_stat.zapFids++;
617 1.1 rvb
618 1.1 rvb for (i = 0; i < coda_nc_hashsize; i++) {
619 1.1 rvb for (cncp = coda_nc_hash[i].hash_next;
620 1.3 rvb cncp != (struct coda_cache *)&coda_nc_hash[i];
621 1.3 rvb cncp = ncncp) {
622 1.1 rvb ncncp = cncp->hash_next;
623 1.1 rvb if ((cncp->cp->c_fid.Volume == fid->Volume) &&
624 1.1 rvb (cncp->cp->c_fid.Vnode == fid->Vnode) &&
625 1.1 rvb (cncp->cp->c_fid.Unique == fid->Unique)) {
626 1.1 rvb coda_nc_hash[i].length--; /* Used for tuning */
627 1.1 rvb coda_nc_remove(cncp, dcstat);
628 1.1 rvb }
629 1.1 rvb }
630 1.1 rvb }
631 1.3 rvb }
632 1.1 rvb
633 1.1 rvb /*
634 1.1 rvb * Remove all entries which match the fid and the cred
635 1.1 rvb */
636 1.1 rvb void
637 1.1 rvb coda_nc_zapvnode(fid, cred, dcstat)
638 1.1 rvb ViceFid *fid;
639 1.1 rvb struct ucred *cred;
640 1.3 rvb enum dc_status dcstat;
641 1.1 rvb {
642 1.1 rvb /* See comment for zapfid. I don't think that one would ever
643 1.3 rvb want to zap a file with a specific cred from the kernel.
644 1.1 rvb We'll leave this one unimplemented.
645 1.1 rvb */
646 1.1 rvb if (coda_nc_use == 0) /* Cache is off */
647 1.1 rvb return;
648 1.1 rvb
649 1.1 rvb CODA_NC_DEBUG(CODA_NC_ZAPVNODE,
650 1.1 rvb myprintf(("Zapvnode: fid 0x%lx, 0x%lx, 0x%lx cred %p\n",
651 1.1 rvb fid->Volume, fid->Vnode, fid->Unique, cred)); )
652 1.1 rvb
653 1.3 rvb }
654 1.1 rvb
655 1.1 rvb /*
656 1.1 rvb * Remove all entries which have the (dir vnode, name) pair
657 1.1 rvb */
658 1.1 rvb void
659 1.1 rvb coda_nc_zapfile(dcp, name, namelen)
660 1.1 rvb struct cnode *dcp;
661 1.3 rvb const char *name;
662 1.1 rvb int namelen;
663 1.1 rvb {
664 1.3 rvb /* use the hash function to locate the file, then zap all
665 1.1 rvb entries of it regardless of the cred.
666 1.1 rvb */
667 1.3 rvb struct coda_cache *cncp;
668 1.1 rvb int hash;
669 1.1 rvb
670 1.1 rvb if (coda_nc_use == 0) /* Cache is off */
671 1.3 rvb return;
672 1.3 rvb
673 1.1 rvb CODA_NC_DEBUG(CODA_NC_ZAPFILE,
674 1.1 rvb myprintf(("Zapfile: dcp %p name %s \n",
675 1.1 rvb dcp, name)); )
676 1.3 rvb
677 1.1 rvb if (namelen > CODA_NC_NAMELEN) {
678 1.3 rvb coda_nc_stat.long_remove++; /* record stats */
679 1.3 rvb return;
680 1.1 rvb }
681 1.1 rvb
682 1.3 rvb coda_nc_stat.zapFile++;
683 1.1 rvb
684 1.3 rvb hash = CODA_NC_HASH(name, namelen, dcp);
685 1.3 rvb cncp = coda_nc_find(dcp, name, namelen, 0, hash);
686 1.1 rvb
687 1.1 rvb while (cncp) {
688 1.1 rvb coda_nc_hash[hash].length--; /* Used for tuning */
689 1.1 rvb /* 1.3 */
690 1.1 rvb coda_nc_remove(cncp, NOT_DOWNCALL);
691 1.1 rvb cncp = coda_nc_find(dcp, name, namelen, 0, hash);
692 1.1 rvb }
693 1.1 rvb }
694 1.3 rvb
695 1.1 rvb /*
696 1.1 rvb * Remove all the entries for a particular user. Used when tokens expire.
697 1.1 rvb * A user is determined by his/her effective user id (id_uid).
698 1.1 rvb */
699 1.1 rvb void
700 1.1 rvb coda_nc_purge_user(uid, dcstat)
701 1.1 rvb vuid_t uid;
702 1.1 rvb enum dc_status dcstat;
703 1.1 rvb {
704 1.1 rvb /*
705 1.1 rvb * I think the best approach is to go through the entire cache
706 1.3 rvb * via HASH or whatever and zap all entries which match the
707 1.1 rvb * input cred. Or just flush the whole cache. It might be
708 1.1 rvb * best to go through on basis of LRU since cache will almost
709 1.3 rvb * always be full and LRU is more straightforward.
710 1.1 rvb */
711 1.1 rvb
712 1.3 rvb struct coda_cache *cncp, *ncncp;
713 1.8 rvb int hash;
714 1.3 rvb
715 1.1 rvb if (coda_nc_use == 0) /* Cache is off */
716 1.3 rvb return;
717 1.3 rvb
718 1.1 rvb CODA_NC_DEBUG(CODA_NC_PURGEUSER,
719 1.3 rvb myprintf(("ZapDude: uid %x\n", uid)); )
720 1.1 rvb coda_nc_stat.zapUsers++;
721 1.3 rvb
722 1.1 rvb for (cncp = CODA_NC_LRUGET(coda_nc_lru);
723 1.1 rvb cncp != (struct coda_cache *)(&coda_nc_lru);
724 1.1 rvb cncp = ncncp) {
725 1.1 rvb ncncp = CODA_NC_LRUGET(*cncp);
726 1.3 rvb
727 1.3 rvb if ((CODA_NC_VALID(cncp)) &&
728 1.1 rvb ((cncp->cred)->cr_uid == uid)) {
729 1.3 rvb /* Seems really ugly, but we have to decrement the appropriate
730 1.1 rvb hash bucket length here, so we have to find the hash bucket
731 1.1 rvb */
732 1.1 rvb hash = CODA_NC_HASH(cncp->name, cncp->namelen, cncp->dcp);
733 1.1 rvb coda_nc_hash[hash].length--; /* For performance tuning */
734 1.1 rvb
735 1.1 rvb coda_nc_remove(cncp, dcstat);
736 1.1 rvb }
737 1.1 rvb }
738 1.3 rvb }
739 1.1 rvb
740 1.1 rvb /*
741 1.1 rvb * Flush the entire name cache. In response to a flush of the Venus cache.
742 1.1 rvb */
743 1.1 rvb void
744 1.1 rvb coda_nc_flush(dcstat)
745 1.1 rvb enum dc_status dcstat;
746 1.1 rvb {
747 1.1 rvb /* One option is to deallocate the current name cache and
748 1.1 rvb call init to start again. Or just deallocate, then rebuild.
749 1.1 rvb Or again, we could just go through the array and zero the
750 1.1 rvb appropriate fields.
751 1.1 rvb */
752 1.3 rvb
753 1.1 rvb /*
754 1.1 rvb * Go through the whole lru chain and kill everything as we go.
755 1.3 rvb * I don't use remove since that would rebuild the lru chain
756 1.1 rvb * as it went and that seemed unneccesary.
757 1.1 rvb */
758 1.3 rvb struct coda_cache *cncp;
759 1.1 rvb int i;
760 1.3 rvb
761 1.3 rvb if (coda_nc_use == 0) /* Cache is off */
762 1.3 rvb return;
763 1.3 rvb
764 1.1 rvb coda_nc_stat.Flushes++;
765 1.3 rvb
766 1.3 rvb for (cncp = CODA_NC_LRUGET(coda_nc_lru);
767 1.1 rvb cncp != (struct coda_cache *)&coda_nc_lru;
768 1.1 rvb cncp = CODA_NC_LRUGET(*cncp)) {
769 1.1 rvb if (CODA_NC_VALID(cncp)) {
770 1.1 rvb
771 1.1 rvb CODA_NC_HSHREM(cncp); /* only zero valid nodes */
772 1.1 rvb CODA_NC_HSHNUL(cncp);
773 1.1 rvb if ((dcstat == IS_DOWNCALL)
774 1.1 rvb && (CTOV(cncp->dcp)->v_usecount == 1))
775 1.3 rvb {
776 1.3 rvb cncp->dcp->c_flags |= C_PURGING;
777 1.3 rvb }
778 1.1 rvb vrele(CTOV(cncp->dcp));
779 1.1 rvb
780 1.1 rvb if (CTOV(cncp->cp)->v_flag & VTEXT) {
781 1.1 rvb if (coda_vmflush(cncp->cp))
782 1.1 rvb CODADEBUG(CODA_FLUSH,
783 1.1 rvb myprintf(("coda_nc_flush: (%lx.%lx.%lx) busy\n", cncp->cp->c_fid.Volume, cncp->cp->c_fid.Vnode, cncp->cp->c_fid.Unique)); )
784 1.1 rvb }
785 1.1 rvb
786 1.1 rvb if ((dcstat == IS_DOWNCALL)
787 1.1 rvb && (CTOV(cncp->cp)->v_usecount == 1))
788 1.1 rvb {
789 1.1 rvb cncp->cp->c_flags |= C_PURGING;
790 1.1 rvb }
791 1.1 rvb vrele(CTOV(cncp->cp));
792 1.3 rvb
793 1.3 rvb crfree(cncp->cred);
794 1.1 rvb bzero(DATA_PART(cncp),DATA_SIZE);
795 1.1 rvb }
796 1.1 rvb }
797 1.1 rvb
798 1.1 rvb for (i = 0; i < coda_nc_hashsize; i++)
799 1.1 rvb coda_nc_hash[i].length = 0;
800 1.1 rvb }
801 1.1 rvb
802 1.1 rvb /*
803 1.1 rvb * Debugging routines
804 1.3 rvb */
805 1.1 rvb
806 1.1 rvb /*
807 1.3 rvb * This routine should print out all the hash chains to the console.
808 1.1 rvb */
809 1.3 rvb void
810 1.1 rvb print_coda_nc(void)
811 1.1 rvb {
812 1.3 rvb int hash;
813 1.3 rvb struct coda_cache *cncp;
814 1.1 rvb
815 1.1 rvb for (hash = 0; hash < coda_nc_hashsize; hash++) {
816 1.1 rvb myprintf(("\nhash %d\n",hash));
817 1.1 rvb
818 1.1 rvb for (cncp = coda_nc_hash[hash].hash_next;
819 1.1 rvb cncp != (struct coda_cache *)&coda_nc_hash[hash];
820 1.1 rvb cncp = cncp->hash_next) {
821 1.1 rvb myprintf(("cp %p dcp %p cred %p name %s\n",
822 1.1 rvb cncp->cp, cncp->dcp,
823 1.3 rvb cncp->cred, cncp->name));
824 1.1 rvb }
825 1.1 rvb }
826 1.1 rvb }
827 1.3 rvb
828 1.3 rvb void
829 1.3 rvb coda_nc_gather_stats(void)
830 1.1 rvb {
831 1.1 rvb int i, max = 0, sum = 0, temp, zeros = 0, ave, n;
832 1.1 rvb
833 1.1 rvb for (i = 0; i < coda_nc_hashsize; i++) {
834 1.3 rvb if (coda_nc_hash[i].length) {
835 1.3 rvb sum += coda_nc_hash[i].length;
836 1.1 rvb } else {
837 1.1 rvb zeros++;
838 1.1 rvb }
839 1.1 rvb
840 1.1 rvb if (coda_nc_hash[i].length > max)
841 1.1 rvb max = coda_nc_hash[i].length;
842 1.3 rvb }
843 1.3 rvb
844 1.3 rvb /*
845 1.1 rvb * When computing the Arithmetic mean, only count slots which
846 1.3 rvb * are not empty in the distribution.
847 1.1 rvb */
848 1.1 rvb coda_nc_stat.Sum_bucket_len = sum;
849 1.1 rvb coda_nc_stat.Num_zero_len = zeros;
850 1.1 rvb coda_nc_stat.Max_bucket_len = max;
851 1.1 rvb
852 1.3 rvb if ((n = coda_nc_hashsize - zeros) > 0)
853 1.3 rvb ave = sum / n;
854 1.3 rvb else
855 1.1 rvb ave = 0;
856 1.1 rvb
857 1.1 rvb sum = 0;
858 1.3 rvb for (i = 0; i < coda_nc_hashsize; i++) {
859 1.1 rvb if (coda_nc_hash[i].length) {
860 1.1 rvb temp = coda_nc_hash[i].length - ave;
861 1.1 rvb sum += temp * temp;
862 1.1 rvb }
863 1.1 rvb }
864 1.1 rvb coda_nc_stat.Sum2_bucket_len = sum;
865 1.1 rvb }
866 1.1 rvb
867 1.1 rvb /*
868 1.3 rvb * The purpose of this routine is to allow the hash and cache sizes to be
869 1.1 rvb * changed dynamically. This should only be used in controlled environments,
870 1.1 rvb * it makes no effort to lock other users from accessing the cache while it
871 1.1 rvb * is in an improper state (except by turning the cache off).
872 1.1 rvb */
873 1.1 rvb int
874 1.1 rvb coda_nc_resize(hashsize, heapsize, dcstat)
875 1.1 rvb int hashsize, heapsize;
876 1.3 rvb enum dc_status dcstat;
877 1.1 rvb {
878 1.3 rvb if ((hashsize % 2) || (heapsize % 2)) { /* Illegal hash or cache sizes */
879 1.1 rvb return(EINVAL);
880 1.1 rvb }
881 1.3 rvb
882 1.3 rvb coda_nc_use = 0; /* Turn the cache off */
883 1.1 rvb
884 1.3 rvb coda_nc_flush(dcstat); /* free any cnodes in the cache */
885 1.3 rvb
886 1.1 rvb /* WARNING: free must happen *before* size is reset */
887 1.3 rvb CODA_FREE(coda_nc_heap,TOTAL_CACHE_SIZE);
888 1.1 rvb CODA_FREE(coda_nc_hash,TOTAL_HASH_SIZE);
889 1.3 rvb
890 1.1 rvb coda_nc_hashsize = hashsize;
891 1.1 rvb coda_nc_size = heapsize;
892 1.1 rvb
893 1.3 rvb coda_nc_init(); /* Set up a cache with the new size */
894 1.1 rvb
895 1.1 rvb coda_nc_use = 1; /* Turn the cache back on */
896 1.3 rvb return(0);
897 1.1 rvb }
898 1.3 rvb
899 1.1 rvb char coda_nc_name_buf[CODA_MAXNAMLEN+1];
900 1.1 rvb
901 1.3 rvb void
902 1.1 rvb coda_nc_name(struct cnode *cp)
903 1.1 rvb {
904 1.3 rvb struct coda_cache *cncp, *ncncp;
905 1.3 rvb int i;
906 1.3 rvb
907 1.1 rvb if (coda_nc_use == 0) /* Cache is off */
908 1.1 rvb return;
909 1.1 rvb
910 1.3 rvb for (i = 0; i < coda_nc_hashsize; i++) {
911 1.3 rvb for (cncp = coda_nc_hash[i].hash_next;
912 1.1 rvb cncp != (struct coda_cache *)&coda_nc_hash[i];
913 1.3 rvb cncp = ncncp) {
914 1.1 rvb ncncp = cncp->hash_next;
915 1.1 rvb if (cncp->cp == cp) {
916 1.1 rvb bcopy(cncp->name, coda_nc_name_buf, cncp->namelen);
917 1.1 rvb coda_nc_name_buf[cncp->namelen] = 0;
918 1.1 rvb printf(" is %s (%p,%p)@%p",
919 coda_nc_name_buf, cncp->cp, cncp->dcp, cncp);
920 }
921
922 }
923 }
924 }
925