1/* $NetBSD: coda_namecache.h,v 1.11 2007/11/22 22:26:19 plunky Exp $ */ 2 3/* 4 * 5 * Coda: an Experimental Distributed File System 6 * Release 3.1 7 * 8 * Copyright (c) 1987-1998 Carnegie Mellon University 9 * All Rights Reserved 10 * 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 18 * derivatives. 19 * 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. 26 * 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. 30 * 31 * @(#) coda/coda_namecache.h,v 1.1.1.1 1998/08/29 21:26:46 rvb Exp $ 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#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#ifdef oldhash 67#define CODA_NC_HASH(name, namelen, cp) \ 68 ((name[0] + name[namelen-1] + namelen + (int)(long)(cp)) \ 69 & (coda_nc_hashsize-1)) 70#else 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)) 74#endif 75 76#define CODA_NAMEMATCH(cp, name, namelen, dcp) \ 77 ((namelen == cp->namelen) && (dcp == cp->dcp) && \ 78 (memcmp(cp->name,name,namelen) == 0)) 79 80#define CODA_NC_VALID(cncp) (cncp->dcp != (struct cnode *)0) 81 82#define DATA_PART(cncp) (&((cncp)->cp)) 83#define DATA_SIZE (sizeof(struct coda_cache) - offsetof(struct coda_cache, cp)) 84 85/* 86 * Structure for an element in the CODA Name Cache. 87 */ 88 89struct coda_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 */ 97}; 98 99struct coda_lru { /* Start of LRU chain */ 100 TAILQ_HEAD(,coda_cache) head; 101}; 102 103 104struct coda_hash { /* Start of Hash chain */ 105 LIST_HEAD(,coda_cache) head; 106 int length; /* used for tuning purposes */ 107}; 108 109 110/* 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 113 */ 114#define CODA_NC_DEBUG(N, STMT) { if (coda_nc_debug & (1 <<N)) { STMT } } 115 116/* Prototypes of functions exported within cfs */ 117extern void coda_nc_init(void); 118extern void coda_nc_enter(struct cnode *, const char *, int, 119 kauth_cred_t, struct cnode *); 120extern struct cnode *coda_nc_lookup(struct cnode *, const char *, int, 121 kauth_cred_t); 122 123extern void coda_nc_zapParentfid(CodaFid *, enum dc_status); 124extern void coda_nc_zapfid(CodaFid *, enum dc_status); 125extern void coda_nc_zapvnode(CodaFid *, kauth_cred_t, enum dc_status); 126extern void coda_nc_zapfile(struct cnode *, const char *, int); 127extern void coda_nc_purge_user(uid_t, enum dc_status); 128extern void coda_nc_flush(enum dc_status); 129 130extern void print_coda_nc(void); 131extern void coda_nc_gather_stats(void); 132extern int coda_nc_resize(int, int, enum dc_status); 133extern void coda_nc_name(struct cnode *cp); 134 135/* 136 * Structure to contain statistics on the cache usage 137 */ 138 139struct coda_nc_statistics { 140 unsigned hits; 141 unsigned misses; 142 unsigned enters; 143 unsigned dbl_enters; 144 unsigned long_name_enters; 145 unsigned long_name_lookups; 146 unsigned long_remove; 147 unsigned lru_rm; 148 unsigned zapPfids; 149 unsigned zapFids; 150 unsigned zapFile; 151 unsigned zapUsers; 152 unsigned Flushes; 153 unsigned Sum_bucket_len; 154 unsigned Sum2_bucket_len; 155 unsigned Max_bucket_len; 156 unsigned Num_zero_len; 157 unsigned Search_len; 158}; 159 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) 173 174#endif /* _CFSNC_HEADER_ */ 175