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