1 /*-
2 *
3 * Coda: an Experimental Distributed File System
4 * Release 3.1
5 *
6 * Copyright (c) 1987-1998 Carnegie Mellon University
7 * All Rights Reserved
8 *
9 * Permission to use, copy, modify and distribute this software and its
10 * documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation, and
14 * that credit is given to Carnegie Mellon University in all documents
15 * and publicity pertaining to direct or indirect use of this code or its
16 * derivatives.
17 *
18 * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
19 * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
20 * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
21 * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
22 * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
23 * ANY DERIVATIVE WORK.
24 *
25 * Carnegie Mellon encourages users of this software to return any
26 * improvements or extensions that they make, and to grant Carnegie
27 * Mellon the rights to redistribute these changes without encumbrance.
28 *
29 * @(#) src/sys/coda/coda_namecache.h,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
30 * $FreeBSD$
31 *
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 filesystem 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 #define CODA_NC_HASH(name, namelen, cp) \
67 ((name[0] + (name[namelen-1]<<4) + namelen + (((int)(intptr_t)cp)>>8)) & (coda_nc_hashsize-1))
68
69 #define CODA_NAMEMATCH(cp, name, namelen, dcp) \
70 ((namelen == cp->namelen) && (dcp == cp->dcp) && \
71 (bcmp(cp->name,name,namelen) == 0))
72
73 /*
74 * Functions to modify the hash and lru chains.
75 * insque and remque assume that the pointers are the first thing
76 * in the list node, thus the trickery for lru.
77 */
78
79 #define CODA_NC_HSHINS(elem, pred) insque(elem,pred)
80 #define CODA_NC_HSHREM(elem) remque(elem)
81 #define CODA_NC_HSHNUL(elem) (elem)->hash_next = \
82 (elem)->hash_prev = (elem)
83
84 #define CODA_NC_LRUINS(elem, pred) insque(LRU_PART(elem), LRU_PART(pred))
85 #define CODA_NC_LRUREM(elem) remque(LRU_PART(elem));
86 #define CODA_NC_LRUGET(lruhead) LRU_TOP((lruhead).lru_prev)
87
88 #define CODA_NC_VALID(cncp) (cncp->dcp != (struct cnode *)0)
89
90 #define LRU_PART(cncp) (struct coda_cache *) \
91 ((char *)cncp + (2*sizeof(struct coda_cache *)))
92 #define LRU_TOP(cncp) (struct coda_cache *) \
93 ((char *)cncp - (2*sizeof(struct coda_cache *)))
94 #define DATA_PART(cncp) (struct coda_cache *) \
95 ((char *)cncp + (4*sizeof(struct coda_cache *)))
96 #define DATA_SIZE (sizeof(struct coda_cache)-(4*sizeof(struct coda_cache *)))
97
98 /*
99 * Structure for an element in the CODA Name Cache.
100 * NOTE: I use the position of arguments and their size in the
101 * implementation of the functions CODA_NC_LRUINS, CODA_NC_LRUREM, and
102 * DATA_PART.
103 */
104
105 struct coda_cache {
106 struct coda_cache *hash_next,*hash_prev; /* Hash list */
107 struct coda_cache *lru_next, *lru_prev; /* LRU list */
108 struct cnode *cp; /* vnode of the file */
109 struct cnode *dcp; /* parent's cnode */
110 struct ucred *cred; /* user credentials */
111 char name[CODA_NC_NAMELEN]; /* segment name */
112 int namelen; /* length of name */
113 };
114
115 struct coda_lru { /* Start of LRU chain */
116 char *dummy1, *dummy2; /* place holders */
117 struct coda_cache *lru_next, *lru_prev; /* position of pointers is important */
118 };
119
120
121 struct coda_hash { /* Start of Hash chain */
122 struct coda_cache *hash_next, *hash_prev; /* NOTE: chain pointers must be first */
123 int length; /* used for tuning purposes */
124 };
125
126
127 /*
128 * Symbols to aid in debugging the namecache code. Assumes the existence
129 * of the variable coda_nc_debug, which is defined in cfs_namecache.c
130 */
131 #define CODA_NC_DEBUG(N, STMT) { if (coda_nc_debug & (1 <<N)) { STMT } }
132
133 /* Prototypes of functions exported within cfs */
134 void coda_nc_init(void);
135 void coda_nc_enter(struct cnode *, const char *, int, struct ucred *, struct cnode *);
136 struct cnode *coda_nc_lookup(struct cnode *, const char *, int, struct ucred *);
137
138 void coda_nc_zapParentfid(CodaFid *, enum dc_status);
139 void coda_nc_zapfid(CodaFid *, enum dc_status);
140 void coda_nc_zapvnode(CodaFid *, struct ucred *, enum dc_status);
141 void coda_nc_zapfile(struct cnode *, const char *, int);
142 void coda_nc_purge_user(uid_t, enum dc_status);
143 void coda_nc_flush(enum dc_status);
144
145 void print_coda_nc(void);
146 void coda_nc_gather_stats(void);
147 int coda_nc_resize(int, int, enum dc_status);
148 void coda_nc_name(struct cnode *cp);
149
150 /*
151 * Global variables tracking and controlling Coda namecache operation.
152 */
153 extern int coda_nc_debug; /* Set to enable debugging printfs */
154 extern int coda_nc_initialized; /* Set if cache has been initialized */
155 extern int coda_nc_use; /* Indicate use of CODA Name Cache */
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
Cache object: c206f1bcd7de19d66de4a995ba0d8bee
|