coda_namecache.h revision 1.11 1 1.11 plunky /* $NetBSD: coda_namecache.h,v 1.11 2007/11/22 22:26:19 plunky Exp $ */
2 1.2 rvb
3 1.1 rvb /*
4 1.8 perry *
5 1.2 rvb * Coda: an Experimental Distributed File System
6 1.2 rvb * Release 3.1
7 1.8 perry *
8 1.2 rvb * Copyright (c) 1987-1998 Carnegie Mellon University
9 1.2 rvb * All Rights Reserved
10 1.8 perry *
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.8 perry *
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.8 perry *
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.8 perry *
31 1.8 perry * @(#) 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.8 perry /*
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.2 rvb
47 1.3 rvb #ifndef _CODA_NC_HEADER_
48 1.3 rvb #define _CODA_NC_HEADER_
49 1.1 rvb
50 1.1 rvb /*
51 1.3 rvb * Coda constants
52 1.1 rvb */
53 1.3 rvb #define CODA_NC_NAMELEN 15 /* longest name stored in cache */
54 1.3 rvb #define CODA_NC_CACHESIZE 256 /* Default cache size */
55 1.3 rvb #define CODA_NC_HASHSIZE 64 /* Must be multiple of 2 */
56 1.1 rvb
57 1.1 rvb /*
58 1.1 rvb * Hash function for the primary hash.
59 1.1 rvb */
60 1.1 rvb
61 1.8 perry /*
62 1.1 rvb * First try -- (first + last letters + length + (int)cp) mod size
63 1.1 rvb * 2nd try -- same, except dir fid.vnode instead of cp
64 1.1 rvb */
65 1.1 rvb
66 1.1 rvb #ifdef oldhash
67 1.3 rvb #define CODA_NC_HASH(name, namelen, cp) \
68 1.5 ross ((name[0] + name[namelen-1] + namelen + (int)(long)(cp)) \
69 1.5 ross & (coda_nc_hashsize-1))
70 1.1 rvb #else
71 1.3 rvb #define CODA_NC_HASH(name, namelen, cp) \
72 1.5 ross ((name[0] + (name[namelen-1]<<4) + namelen + (((int)(long)cp)>>8)) \
73 1.5 ross & (coda_nc_hashsize-1))
74 1.1 rvb #endif
75 1.1 rvb
76 1.3 rvb #define CODA_NAMEMATCH(cp, name, namelen, dcp) \
77 1.1 rvb ((namelen == cp->namelen) && (dcp == cp->dcp) && \
78 1.1 rvb (bcmp(cp->name,name,namelen) == 0))
79 1.1 rvb
80 1.3 rvb #define CODA_NC_VALID(cncp) (cncp->dcp != (struct cnode *)0)
81 1.8 perry
82 1.11 plunky #define DATA_PART(cncp) (&((cncp)->cp))
83 1.11 plunky #define DATA_SIZE (sizeof(struct coda_cache) - offsetof(struct coda_cache, cp))
84 1.1 rvb
85 1.1 rvb /*
86 1.3 rvb * Structure for an element in the CODA Name Cache.
87 1.1 rvb */
88 1.1 rvb
89 1.8 perry struct coda_cache {
90 1.11 plunky LIST_ENTRY(coda_cache) hash; /* Hash list */
91 1.11 plunky TAILQ_ENTRY(coda_cache) lru; /* LRU list */
92 1.1 rvb struct cnode *cp; /* vnode of the file */
93 1.1 rvb struct cnode *dcp; /* parent's cnode */
94 1.10 elad kauth_cred_t cred; /* user credentials */
95 1.3 rvb char name[CODA_NC_NAMELEN]; /* segment name */
96 1.1 rvb int namelen; /* length of name */
97 1.1 rvb };
98 1.1 rvb
99 1.3 rvb struct coda_lru { /* Start of LRU chain */
100 1.11 plunky TAILQ_HEAD(,coda_cache) head;
101 1.1 rvb };
102 1.1 rvb
103 1.1 rvb
104 1.3 rvb struct coda_hash { /* Start of Hash chain */
105 1.11 plunky LIST_HEAD(,coda_cache) head;
106 1.11 plunky int length; /* used for tuning purposes */
107 1.1 rvb };
108 1.1 rvb
109 1.1 rvb
110 1.8 perry /*
111 1.1 rvb * Symbols to aid in debugging the namecache code. Assumes the existence
112 1.3 rvb * of the variable coda_nc_debug, which is defined in cfs_namecache.c
113 1.1 rvb */
114 1.3 rvb #define CODA_NC_DEBUG(N, STMT) { if (coda_nc_debug & (1 <<N)) { STMT } }
115 1.1 rvb
116 1.1 rvb /* Prototypes of functions exported within cfs */
117 1.3 rvb extern void coda_nc_init(void);
118 1.10 elad extern void coda_nc_enter(struct cnode *, const char *, int,
119 1.10 elad kauth_cred_t, struct cnode *);
120 1.10 elad extern struct cnode *coda_nc_lookup(struct cnode *, const char *, int,
121 1.10 elad kauth_cred_t);
122 1.3 rvb
123 1.7 drochner extern void coda_nc_zapParentfid(CodaFid *, enum dc_status);
124 1.7 drochner extern void coda_nc_zapfid(CodaFid *, enum dc_status);
125 1.10 elad extern void coda_nc_zapvnode(CodaFid *, kauth_cred_t, enum dc_status);
126 1.3 rvb extern void coda_nc_zapfile(struct cnode *, const char *, int);
127 1.7 drochner extern void coda_nc_purge_user(uid_t, enum dc_status);
128 1.3 rvb extern void coda_nc_flush(enum dc_status);
129 1.3 rvb
130 1.3 rvb extern void print_coda_nc(void);
131 1.3 rvb extern void coda_nc_gather_stats(void);
132 1.3 rvb extern int coda_nc_resize(int, int, enum dc_status);
133 1.3 rvb extern void coda_nc_name(struct cnode *cp);
134 1.1 rvb
135 1.1 rvb /*
136 1.1 rvb * Structure to contain statistics on the cache usage
137 1.1 rvb */
138 1.1 rvb
139 1.3 rvb struct coda_nc_statistics {
140 1.1 rvb unsigned hits;
141 1.1 rvb unsigned misses;
142 1.1 rvb unsigned enters;
143 1.1 rvb unsigned dbl_enters;
144 1.1 rvb unsigned long_name_enters;
145 1.1 rvb unsigned long_name_lookups;
146 1.1 rvb unsigned long_remove;
147 1.1 rvb unsigned lru_rm;
148 1.1 rvb unsigned zapPfids;
149 1.1 rvb unsigned zapFids;
150 1.1 rvb unsigned zapFile;
151 1.1 rvb unsigned zapUsers;
152 1.1 rvb unsigned Flushes;
153 1.1 rvb unsigned Sum_bucket_len;
154 1.1 rvb unsigned Sum2_bucket_len;
155 1.1 rvb unsigned Max_bucket_len;
156 1.1 rvb unsigned Num_zero_len;
157 1.1 rvb unsigned Search_len;
158 1.1 rvb };
159 1.1 rvb
160 1.3 rvb #define CODA_NC_FIND ((u_long) 1)
161 1.3 rvb #define CODA_NC_REMOVE ((u_long) 2)
162 1.3 rvb #define CODA_NC_INIT ((u_long) 3)
163 1.3 rvb #define CODA_NC_ENTER ((u_long) 4)
164 1.3 rvb #define CODA_NC_LOOKUP ((u_long) 5)
165 1.3 rvb #define CODA_NC_ZAPPFID ((u_long) 6)
166 1.3 rvb #define CODA_NC_ZAPFID ((u_long) 7)
167 1.3 rvb #define CODA_NC_ZAPVNODE ((u_long) 8)
168 1.3 rvb #define CODA_NC_ZAPFILE ((u_long) 9)
169 1.3 rvb #define CODA_NC_PURGEUSER ((u_long) 10)
170 1.3 rvb #define CODA_NC_FLUSH ((u_long) 11)
171 1.3 rvb #define CODA_NC_PRINTCODA_NC ((u_long) 12)
172 1.3 rvb #define CODA_NC_PRINTSTATS ((u_long) 13)
173 1.1 rvb
174 1.1 rvb #endif /* _CFSNC_HEADER_ */
175