5005eec8a62b9b6d32e4faa24de9a91792d9c473
[dragonfly.git] / sys / vfs / 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  * $FreeBSD: src/sys/coda/coda_namecache.h,v 1.6 1999/08/28 00:40:53 peter Exp $
31  * $DragonFly: src/sys/vfs/coda/Attic/coda_namecache.h,v 1.2 2003/06/17 04:28:19 dillon Exp $
32  * 
33  */
34
35 /* 
36  * Mach Operating System
37  * Copyright (c) 1990 Carnegie-Mellon University
38  * Copyright (c) 1989 Carnegie-Mellon University
39  * All rights reserved.  The CMU software License Agreement specifies
40  * the terms and conditions for use and redistribution.
41  */
42
43 /*
44  * This code was written for the Coda file system at Carnegie Mellon University.
45  * Contributers include David Steere, James Kistler, and M. Satyanarayanan.
46  */
47
48 #ifndef _CODA_NC_HEADER_
49 #define _CODA_NC_HEADER_
50
51 /*
52  * Coda constants
53  */
54 #define CODA_NC_NAMELEN 15              /* longest name stored in cache */
55 #define CODA_NC_CACHESIZE 256           /* Default cache size */
56 #define CODA_NC_HASHSIZE        64              /* Must be multiple of 2 */
57
58 /*
59  * Hash function for the primary hash.
60  */
61
62 /* 
63  * First try -- (first + last letters + length + (int)cp) mod size
64  * 2nd try -- same, except dir fid.vnode instead of cp
65  */
66
67 #ifdef  oldhash
68 #define CODA_NC_HASH(name, namelen, cp) \
69         ((name[0] + name[namelen-1] + namelen + (int)(cp)) & (coda_nc_hashsize-1))
70 #else
71 #define CODA_NC_HASH(name, namelen, cp) \
72         ((name[0] + (name[namelen-1]<<4) + namelen + (((int)cp)>>8)) & (coda_nc_hashsize-1))
73 #endif
74
75 #define CODA_NAMEMATCH(cp, name, namelen, dcp) \
76         ((namelen == cp->namelen) && (dcp == cp->dcp) && \
77                  (bcmp(cp->name,name,namelen) == 0))
78
79 /*
80  * Functions to modify the hash and lru chains.
81  * insque and remque assume that the pointers are the first thing
82  * in the list node, thus the trickery for lru.
83  */
84
85 #define CODA_NC_HSHINS(elem, pred)      insque(elem,pred)
86 #define CODA_NC_HSHREM(elem)            remque(elem)
87 #define CODA_NC_HSHNUL(elem)            (elem)->hash_next = \
88                                         (elem)->hash_prev = (elem)
89
90 #define CODA_NC_LRUINS(elem, pred)      insque(LRU_PART(elem), LRU_PART(pred))
91 #define CODA_NC_LRUREM(elem)            remque(LRU_PART(elem));
92 #define CODA_NC_LRUGET(lruhead)         LRU_TOP((lruhead).lru_prev)
93
94 #define CODA_NC_VALID(cncp)     (cncp->dcp != (struct cnode *)0)
95  
96 #define LRU_PART(cncp)                  (struct coda_cache *) \
97                                 ((char *)cncp + (2*sizeof(struct coda_cache *)))
98 #define LRU_TOP(cncp)                           (struct coda_cache *) \
99                         ((char *)cncp - (2*sizeof(struct coda_cache *)))
100 #define DATA_PART(cncp)                         (struct coda_cache *) \
101                         ((char *)cncp + (4*sizeof(struct coda_cache *)))
102 #define DATA_SIZE       (sizeof(struct coda_cache)-(4*sizeof(struct coda_cache *)))
103
104 /*
105  * Structure for an element in the CODA Name Cache.
106  * NOTE: I use the position of arguments and their size in the
107  * implementation of the functions CODA_NC_LRUINS, CODA_NC_LRUREM, and
108  * DATA_PART.
109  */
110
111 struct coda_cache {     
112         struct coda_cache       *hash_next,*hash_prev;  /* Hash list */
113         struct coda_cache       *lru_next, *lru_prev;   /* LRU list */
114         struct cnode    *cp;                    /* vnode of the file */
115         struct cnode    *dcp;                   /* parent's cnode */
116         struct ucred    *cred;                  /* user credentials */
117         char            name[CODA_NC_NAMELEN];  /* segment name */
118         int             namelen;                /* length of name */
119 };
120
121 struct  coda_lru {              /* Start of LRU chain */
122         char *dummy1, *dummy2;                  /* place holders */
123         struct coda_cache *lru_next, *lru_prev;   /* position of pointers is important */
124 };
125
126
127 struct coda_hash {              /* Start of Hash chain */
128         struct coda_cache *hash_next, *hash_prev; /* NOTE: chain pointers must be first */
129         int length;                             /* used for tuning purposes */
130 };
131
132
133 /* 
134  * Symbols to aid in debugging the namecache code. Assumes the existence
135  * of the variable coda_nc_debug, which is defined in cfs_namecache.c
136  */
137 #define CODA_NC_DEBUG(N, STMT)     { if (coda_nc_debug & (1 <<N)) { STMT } }
138
139 /* Prototypes of functions exported within cfs */
140 extern void coda_nc_init(void);
141 extern void coda_nc_enter(struct cnode *, const char *, int, struct ucred *, struct cnode *);
142 extern struct cnode *coda_nc_lookup(struct cnode *, const char *, int, struct ucred *);
143
144 extern void coda_nc_zapParentfid(ViceFid *, enum dc_status);
145 extern void coda_nc_zapfid(ViceFid *, enum dc_status);
146 extern void coda_nc_zapvnode(ViceFid *, struct ucred *, enum dc_status);
147 extern void coda_nc_zapfile(struct cnode *, const char *, int);
148 extern void coda_nc_purge_user(vuid_t, enum dc_status);
149 extern void coda_nc_flush(enum dc_status);
150
151 extern void print_coda_nc(void);
152 extern void coda_nc_gather_stats(void);
153 extern int  coda_nc_resize(int, int, enum dc_status);
154 extern void coda_nc_name(struct cnode *cp);
155
156 /*
157  * Structure to contain statistics on the cache usage
158  */
159
160 struct coda_nc_statistics {
161         unsigned        hits;
162         unsigned        misses;
163         unsigned        enters;
164         unsigned        dbl_enters;
165         unsigned        long_name_enters;
166         unsigned        long_name_lookups;
167         unsigned        long_remove;
168         unsigned        lru_rm;
169         unsigned        zapPfids;
170         unsigned        zapFids;
171         unsigned        zapFile;
172         unsigned        zapUsers;
173         unsigned        Flushes;
174         unsigned        Sum_bucket_len;
175         unsigned        Sum2_bucket_len;
176         unsigned        Max_bucket_len;
177         unsigned        Num_zero_len;
178         unsigned        Search_len;
179 };
180
181 #define CODA_NC_FIND            ((u_long) 1)
182 #define CODA_NC_REMOVE          ((u_long) 2)
183 #define CODA_NC_INIT            ((u_long) 3)
184 #define CODA_NC_ENTER           ((u_long) 4)
185 #define CODA_NC_LOOKUP          ((u_long) 5)
186 #define CODA_NC_ZAPPFID         ((u_long) 6)
187 #define CODA_NC_ZAPFID          ((u_long) 7)
188 #define CODA_NC_ZAPVNODE                ((u_long) 8)
189 #define CODA_NC_ZAPFILE         ((u_long) 9)
190 #define CODA_NC_PURGEUSER               ((u_long) 10)
191 #define CODA_NC_FLUSH           ((u_long) 11)
192 #define CODA_NC_PRINTCODA_NC    ((u_long) 12)
193 #define CODA_NC_PRINTSTATS      ((u_long) 13)
194
195 #endif