1 /* $NetBSD: coda_namecache.h,v 1.11 2007/11/22 22:26:19 plunky Exp $ */
5 * Coda: an Experimental Distributed File System
8 * Copyright (c) 1987-1998 Carnegie Mellon University
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
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.
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.
31 * @(#) coda/coda_namecache.h,v 1.1.1.1 1998/08/29 21:26:46 rvb Exp $
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.
43 * This code was written for the Coda file system at Carnegie Mellon University.
44 * Contributers include David Steere, James Kistler, and M. Satyanarayanan.
47 #ifndef _CODA_NC_HEADER_
48 #define _CODA_NC_HEADER_
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 */
58 * Hash function for the primary hash.
62 * First try -- (first + last letters + length + (int)cp) mod size
63 * 2nd try -- same, except dir fid.vnode instead of cp
67 #define CODA_NC_HASH(name, namelen, cp) \
68 ((name[0] + name[namelen-1] + namelen + (int)(long)(cp)) \
69 & (coda_nc_hashsize-1))
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))
76 #define CODA_NAMEMATCH(cp, name, namelen, dcp) \
77 ((namelen == cp->namelen) && (dcp == cp->dcp) && \
78 (memcmp(cp->name,name,namelen) == 0))
80 #define CODA_NC_VALID(cncp) (cncp->dcp != (struct cnode *)0)
82 #define DATA_PART(cncp) (&((cncp)->cp))
83 #define DATA_SIZE (sizeof(struct coda_cache) - offsetof(struct coda_cache, cp))
86 * Structure for an element in the CODA Name Cache.
90 LIST_ENTRY(coda_cache
) hash
; /* Hash list */
91 TAILQ_ENTRY(coda_cache
) lru
; /* LRU list */
92 struct cnode
*cp
; /* vnode of the file */
93 struct cnode
*dcp
; /* parent's cnode */
94 kauth_cred_t cred
; /* user credentials */
95 char name
[CODA_NC_NAMELEN
]; /* segment name */
96 int namelen
; /* length of name */
99 struct coda_lru
{ /* Start of LRU chain */
100 TAILQ_HEAD(,coda_cache
) head
;
104 struct coda_hash
{ /* Start of Hash chain */
105 LIST_HEAD(,coda_cache
) head
;
106 int length
; /* used for tuning purposes */
111 * Symbols to aid in debugging the namecache code. Assumes the existence
112 * of the variable coda_nc_debug, which is defined in cfs_namecache.c
114 #define CODA_NC_DEBUG(N, STMT) { if (coda_nc_debug & (1 <<N)) { STMT } }
116 /* Prototypes of functions exported within cfs */
117 extern void coda_nc_init(void);
118 extern void coda_nc_enter(struct cnode
*, const char *, int,
119 kauth_cred_t
, struct cnode
*);
120 extern struct cnode
*coda_nc_lookup(struct cnode
*, const char *, int,
123 extern void coda_nc_zapParentfid(CodaFid
*, enum dc_status
);
124 extern void coda_nc_zapfid(CodaFid
*, enum dc_status
);
125 extern void coda_nc_zapvnode(CodaFid
*, kauth_cred_t
, enum dc_status
);
126 extern void coda_nc_zapfile(struct cnode
*, const char *, int);
127 extern void coda_nc_purge_user(uid_t
, enum dc_status
);
128 extern void coda_nc_flush(enum dc_status
);
130 extern void print_coda_nc(void);
131 extern void coda_nc_gather_stats(void);
132 extern int coda_nc_resize(int, int, enum dc_status
);
133 extern void coda_nc_name(struct cnode
*cp
);
136 * Structure to contain statistics on the cache usage
139 struct coda_nc_statistics
{
144 unsigned long_name_enters
;
145 unsigned long_name_lookups
;
146 unsigned long_remove
;
153 unsigned Sum_bucket_len
;
154 unsigned Sum2_bucket_len
;
155 unsigned Max_bucket_len
;
156 unsigned Num_zero_len
;
160 #define CODA_NC_FIND ((u_long) 1)
161 #define CODA_NC_REMOVE ((u_long) 2)
162 #define CODA_NC_INIT ((u_long) 3)
163 #define CODA_NC_ENTER ((u_long) 4)
164 #define CODA_NC_LOOKUP ((u_long) 5)
165 #define CODA_NC_ZAPPFID ((u_long) 6)
166 #define CODA_NC_ZAPFID ((u_long) 7)
167 #define CODA_NC_ZAPVNODE ((u_long) 8)
168 #define CODA_NC_ZAPFILE ((u_long) 9)
169 #define CODA_NC_PURGEUSER ((u_long) 10)
170 #define CODA_NC_FLUSH ((u_long) 11)
171 #define CODA_NC_PRINTCODA_NC ((u_long) 12)
172 #define CODA_NC_PRINTSTATS ((u_long) 13)
174 #endif /* _CFSNC_HEADER_ */