xref: /titanic_54/usr/src/uts/common/sys/dnlc.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
32*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
33*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
34*7c478bd9Sstevel@tonic-gate  *
35*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
36*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
37*7c478bd9Sstevel@tonic-gate  * contributors.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #ifndef _SYS_DNLC_H
41*7c478bd9Sstevel@tonic-gate #define	_SYS_DNLC_H
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
46*7c478bd9Sstevel@tonic-gate extern "C" {
47*7c478bd9Sstevel@tonic-gate #endif
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate /*
52*7c478bd9Sstevel@tonic-gate  * DNLC - Directory name lookup cache.
53*7c478bd9Sstevel@tonic-gate  * There are now two sorts of name caching:
54*7c478bd9Sstevel@tonic-gate  *
55*7c478bd9Sstevel@tonic-gate  * Standard dnlc: This original cache holds recent mappings
56*7c478bd9Sstevel@tonic-gate  *                of <directory vnode, name> to vnode mappings.
57*7c478bd9Sstevel@tonic-gate  *
58*7c478bd9Sstevel@tonic-gate  * Directory caches: Entire large directories can be cached, subject to
59*7c478bd9Sstevel@tonic-gate  *		     memory availability and tunables. A directory cache
60*7c478bd9Sstevel@tonic-gate  *		     anchor point must be provided in the xxnode for
61*7c478bd9Sstevel@tonic-gate  *		     a directory.
62*7c478bd9Sstevel@tonic-gate  */
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate /*
66*7c478bd9Sstevel@tonic-gate  * Standard dnlc
67*7c478bd9Sstevel@tonic-gate  * =============
68*7c478bd9Sstevel@tonic-gate  */
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate /*
71*7c478bd9Sstevel@tonic-gate  * This structure describes the elements in the cache of recent
72*7c478bd9Sstevel@tonic-gate  * names looked up.
73*7c478bd9Sstevel@tonic-gate  *
74*7c478bd9Sstevel@tonic-gate  * Note namlen is a uchar_t to conserve space
75*7c478bd9Sstevel@tonic-gate  * and alignment padding. The max length of any
76*7c478bd9Sstevel@tonic-gate  * pathname component is defined as MAXNAMELEN
77*7c478bd9Sstevel@tonic-gate  * which is 256 (including the terminating null).
78*7c478bd9Sstevel@tonic-gate  * So provided this doesn't change, we don't include the null,
79*7c478bd9Sstevel@tonic-gate  * we always use bcmp to compare strings, and we don't start
80*7c478bd9Sstevel@tonic-gate  * storing full names, then we are ok. The space savings are worth it.
81*7c478bd9Sstevel@tonic-gate  */
82*7c478bd9Sstevel@tonic-gate typedef struct ncache {
83*7c478bd9Sstevel@tonic-gate 	struct ncache *hash_next; 	/* hash chain, MUST BE FIRST */
84*7c478bd9Sstevel@tonic-gate 	struct ncache *hash_prev;
85*7c478bd9Sstevel@tonic-gate 	struct vnode *vp;		/* vnode the name refers to */
86*7c478bd9Sstevel@tonic-gate 	struct vnode *dp;		/* vnode of parent of name */
87*7c478bd9Sstevel@tonic-gate 	int hash;			/* hash signature */
88*7c478bd9Sstevel@tonic-gate 	uchar_t namlen;			/* length of name */
89*7c478bd9Sstevel@tonic-gate 	char name[1];			/* segment name - null terminated */
90*7c478bd9Sstevel@tonic-gate } ncache_t;
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate /*
93*7c478bd9Sstevel@tonic-gate  * Hash table bucket structure of name cache entries for fast lookup.
94*7c478bd9Sstevel@tonic-gate  */
95*7c478bd9Sstevel@tonic-gate typedef struct nc_hash	{
96*7c478bd9Sstevel@tonic-gate 	ncache_t *hash_next;
97*7c478bd9Sstevel@tonic-gate 	ncache_t *hash_prev;
98*7c478bd9Sstevel@tonic-gate 	kmutex_t hash_lock;
99*7c478bd9Sstevel@tonic-gate } nc_hash_t;
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate /*
102*7c478bd9Sstevel@tonic-gate  * Statistics on name cache
103*7c478bd9Sstevel@tonic-gate  * Not protected by locks
104*7c478bd9Sstevel@tonic-gate  */
105*7c478bd9Sstevel@tonic-gate /*
106*7c478bd9Sstevel@tonic-gate  * ncstats has been deprecated, due to the integer size of the counters
107*7c478bd9Sstevel@tonic-gate  * which can easily overflow in the dnlc.
108*7c478bd9Sstevel@tonic-gate  * It is maintained (at some expense) for compatability.
109*7c478bd9Sstevel@tonic-gate  * The preferred interface is the kstat accessible nc_stats below, ehich
110*7c478bd9Sstevel@tonic-gate  * is actually shared with directory caching.
111*7c478bd9Sstevel@tonic-gate  */
112*7c478bd9Sstevel@tonic-gate struct ncstats {
113*7c478bd9Sstevel@tonic-gate 	int	hits;		/* hits that we can really use */
114*7c478bd9Sstevel@tonic-gate 	int	misses;		/* cache misses */
115*7c478bd9Sstevel@tonic-gate 	int	enters;		/* number of enters done */
116*7c478bd9Sstevel@tonic-gate 	int	dbl_enters;	/* number of enters tried when already cached */
117*7c478bd9Sstevel@tonic-gate 	int	long_enter;	/* deprecated, no longer accounted */
118*7c478bd9Sstevel@tonic-gate 	int	long_look;	/* deprecated, no longer accounted */
119*7c478bd9Sstevel@tonic-gate 	int	move_to_front;	/* entry moved to front of hash chain */
120*7c478bd9Sstevel@tonic-gate 	int	purges;		/* number of purges of cache */
121*7c478bd9Sstevel@tonic-gate };
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate struct nc_stats {
124*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_hits;		/* cache hits */
125*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_misses;	/* cache misses */
126*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_neg_hits;	/* negative cache hits */
127*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_enters;	/* enters */
128*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dbl_enters;	/* enters when entry already cached */
129*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_purge_total;	/* total entries prurged */
130*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_purge_all;	/* dnlc_purge() calls */
131*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_purge_vp;	/* dnlc_purge_vp() calls */
132*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_purge_vfs;	/* dnlc_purge_vfs() calls */
133*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_purge_fs1;	/* dnlc_purge_fs1() calls */
134*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_pick_free;	/* found a free ncache */
135*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_pick_heur;	/* found ncache w/ NULL vpages */
136*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_pick_last;	/* found last ncache on chain */
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 	/* directory caching stats */
139*7c478bd9Sstevel@tonic-gate 
140*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_hits;	/* dir cache hits */
141*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_misses;	/* dir cache misses */
142*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_cur_dirs;	/* current # directories cached */
143*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_num_ents;	/* current # entries cached */
144*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dirs_cached;	/* total # directories cached */
145*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_start_nm;	/* dir start no memory */
146*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_add_nm;	/* add entry/space - no memory */
147*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_addabort;	/* add entry/space - abort */
148*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_add_max;	/* add entry/space - max exceeded */
149*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_reme_fai;	/* remove entry fail */
150*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_rems_fai;	/* remove space fail */
151*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_upd_fail;	/* update space fail */
152*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_finipurg;	/* fini purges */
153*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_rec_last;	/* reclaim last */
154*7c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_recl_any;	/* reclaim any */
155*7c478bd9Sstevel@tonic-gate };
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate /*
158*7c478bd9Sstevel@tonic-gate  * The dnlc hashing function.
159*7c478bd9Sstevel@tonic-gate  * Although really a kernel macro we export it to allow validation
160*7c478bd9Sstevel@tonic-gate  * of ncache_t entries by mdb. Note, mdb can handle the ASSERT.
161*7c478bd9Sstevel@tonic-gate  *
162*7c478bd9Sstevel@tonic-gate  * 'hash' and 'namlen' must be l-values. A check is made to ensure
163*7c478bd9Sstevel@tonic-gate  * the name length fits into an unsigned char (see ncache_t).
164*7c478bd9Sstevel@tonic-gate  */
165*7c478bd9Sstevel@tonic-gate #define	DNLCHASH(name, dvp, hash, namlen)			\
166*7c478bd9Sstevel@tonic-gate 	{							\
167*7c478bd9Sstevel@tonic-gate 		char Xc, *Xcp;					\
168*7c478bd9Sstevel@tonic-gate 		hash = (int)((uintptr_t)(dvp)) >> 8;		\
169*7c478bd9Sstevel@tonic-gate 		for (Xcp = (name); (Xc = *Xcp) != 0; Xcp++)	\
170*7c478bd9Sstevel@tonic-gate 			(hash) = ((hash) << 4) + (hash) + Xc;	\
171*7c478bd9Sstevel@tonic-gate 		ASSERT((Xcp - (name)) <= ((1 << NBBY) - 1));	\
172*7c478bd9Sstevel@tonic-gate 		(namlen) = Xcp - (name);			\
173*7c478bd9Sstevel@tonic-gate 	}
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
178*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate extern int ncsize;		/* set in param_init() # of dnlc entries */
181*7c478bd9Sstevel@tonic-gate extern vnode_t negative_cache_vnode;
182*7c478bd9Sstevel@tonic-gate #define	DNLC_NO_VNODE &negative_cache_vnode
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate void	dnlc_init(void);
185*7c478bd9Sstevel@tonic-gate void	dnlc_enter(vnode_t *, char *, vnode_t *);
186*7c478bd9Sstevel@tonic-gate void	dnlc_update(vnode_t *, char *, vnode_t *);
187*7c478bd9Sstevel@tonic-gate vnode_t	*dnlc_lookup(vnode_t *, char *);
188*7c478bd9Sstevel@tonic-gate void	dnlc_purge(void);
189*7c478bd9Sstevel@tonic-gate void	dnlc_purge_vp(vnode_t *);
190*7c478bd9Sstevel@tonic-gate int	dnlc_purge_vfsp(vfs_t *, int);
191*7c478bd9Sstevel@tonic-gate void	dnlc_remove(vnode_t *, char *);
192*7c478bd9Sstevel@tonic-gate int	dnlc_fs_purge1(struct vnodeops *);
193*7c478bd9Sstevel@tonic-gate vnode_t	*dnlc_reverse_lookup(vnode_t *, char *, size_t);
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate /*
199*7c478bd9Sstevel@tonic-gate  * Directory caching interfaces
200*7c478bd9Sstevel@tonic-gate  * ============================
201*7c478bd9Sstevel@tonic-gate  */
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate /*
204*7c478bd9Sstevel@tonic-gate  * Typically for large directories, the file names will be the same or
205*7c478bd9Sstevel@tonic-gate  * at least similar lengths. So there's no point in anything more elaborate
206*7c478bd9Sstevel@tonic-gate  * than a simple unordered linked list of free space entries.
207*7c478bd9Sstevel@tonic-gate  * For small directories the name length distribution doesn't really matter.
208*7c478bd9Sstevel@tonic-gate  */
209*7c478bd9Sstevel@tonic-gate typedef struct dcfree {
210*7c478bd9Sstevel@tonic-gate 	uint64_t df_handle;		/* fs supplied handle */
211*7c478bd9Sstevel@tonic-gate 	struct dcfree *df_next; 	/* link to next free entry in bucket */
212*7c478bd9Sstevel@tonic-gate 	uint_t df_len;			/* length of free entry */
213*7c478bd9Sstevel@tonic-gate } dcfree_t;
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate typedef struct dcentry {
216*7c478bd9Sstevel@tonic-gate 	uint64_t de_handle;		/* fs supplied and returned data */
217*7c478bd9Sstevel@tonic-gate 	struct dcentry *de_next;	/* link to next name entry in bucket */
218*7c478bd9Sstevel@tonic-gate 	int de_hash;			/* hash signature */
219*7c478bd9Sstevel@tonic-gate 	uchar_t de_namelen;		/* length of name excluding null */
220*7c478bd9Sstevel@tonic-gate 	char de_name[1];		/* null terminated name */
221*7c478bd9Sstevel@tonic-gate } dcentry_t;
222*7c478bd9Sstevel@tonic-gate 
223*7c478bd9Sstevel@tonic-gate typedef struct dircache {
224*7c478bd9Sstevel@tonic-gate 	struct dircache *dc_next;	/* chain - for purge purposes */
225*7c478bd9Sstevel@tonic-gate 	struct dircache *dc_prev;	/* chain - for purge purposes */
226*7c478bd9Sstevel@tonic-gate 	int64_t dc_actime;		/* dir access time, from lbolt64 */
227*7c478bd9Sstevel@tonic-gate 	dcentry_t **dc_namehash;	/* entry hash table pointer */
228*7c478bd9Sstevel@tonic-gate 	dcfree_t **dc_freehash;		/* free entry hash table pointer */
229*7c478bd9Sstevel@tonic-gate 	uint_t dc_num_entries;		/* no of named entries */
230*7c478bd9Sstevel@tonic-gate 	uint_t dc_num_free;		/* no of free space entries */
231*7c478bd9Sstevel@tonic-gate 	uint_t dc_nhash_mask;		/* name hash table size - 1 */
232*7c478bd9Sstevel@tonic-gate 	uint_t dc_fhash_mask;		/* free space hash table size - 1 */
233*7c478bd9Sstevel@tonic-gate 	struct dcanchor *dc_anchor;	/* back ptr to anchor */
234*7c478bd9Sstevel@tonic-gate 	boolean_t dc_complete;		/* cache complete boolean */
235*7c478bd9Sstevel@tonic-gate } dircache_t;
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate typedef struct dcanchor {
238*7c478bd9Sstevel@tonic-gate 	void *dca_dircache;	/* pointer to directory cache */
239*7c478bd9Sstevel@tonic-gate 	kmutex_t dca_lock;		/* protects the directory cache */
240*7c478bd9Sstevel@tonic-gate } dcanchor_t;
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate /*
243*7c478bd9Sstevel@tonic-gate  * Head struct for doubly linked chain of dircache_t
244*7c478bd9Sstevel@tonic-gate  * The next and prev fields must match those of a dircache_t
245*7c478bd9Sstevel@tonic-gate  */
246*7c478bd9Sstevel@tonic-gate typedef struct {
247*7c478bd9Sstevel@tonic-gate 	dircache_t *dch_next;		/* next in chain */
248*7c478bd9Sstevel@tonic-gate 	dircache_t *dch_prev;		/* prev in chain */
249*7c478bd9Sstevel@tonic-gate 	kmutex_t dch_lock;		/* lock for the chain */
250*7c478bd9Sstevel@tonic-gate } dchead_t;
251*7c478bd9Sstevel@tonic-gate 
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate /*
256*7c478bd9Sstevel@tonic-gate  * Status returns from the directory cache interfaces
257*7c478bd9Sstevel@tonic-gate  */
258*7c478bd9Sstevel@tonic-gate typedef enum {
259*7c478bd9Sstevel@tonic-gate 	DOK,		/* operation sucessful */
260*7c478bd9Sstevel@tonic-gate 	DNOCACHE,	/* there is no cache */
261*7c478bd9Sstevel@tonic-gate 	DFOUND,		/* entry found */
262*7c478bd9Sstevel@tonic-gate 	DNOENT,		/* no entry found */
263*7c478bd9Sstevel@tonic-gate 	DTOOBIG,	/* exceeds tunable dnlc_max_dir_cache */
264*7c478bd9Sstevel@tonic-gate 	DNOMEM		/* no memory */
265*7c478bd9Sstevel@tonic-gate } dcret_t;
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate /*
268*7c478bd9Sstevel@tonic-gate  * dnlc_dir_start() requests that a directory be cached.
269*7c478bd9Sstevel@tonic-gate  * This must be called initially to enable caching on a directory.
270*7c478bd9Sstevel@tonic-gate  * After a successful call, directory entries and free space can be
271*7c478bd9Sstevel@tonic-gate  * added (see below) until the directory is marked complete.
272*7c478bd9Sstevel@tonic-gate  * "num_entries" is an estimate of the current number of
273*7c478bd9Sstevel@tonic-gate  * directory entries. The request is rejected with DNOCACHE
274*7c478bd9Sstevel@tonic-gate  * if num_entries falls below the tunable dnlc_dir_min_size (see
275*7c478bd9Sstevel@tonic-gate  * below), and rejected with DTOOBIG if it's above dnlc_dir_max_size.
276*7c478bd9Sstevel@tonic-gate  * Returns DOK, DNOCACHE, DTOOBIG, DNOMEM.
277*7c478bd9Sstevel@tonic-gate  *
278*7c478bd9Sstevel@tonic-gate  * Due to memory shortages, directory caches can be purged at
279*7c478bd9Sstevel@tonic-gate  * any time. If the last directory cache is purged due to memory
280*7c478bd9Sstevel@tonic-gate  * shortage, then the directory cache is marked internally
281*7c478bd9Sstevel@tonic-gate  * as "no memory". Future returns will all be DNOCACHE until
282*7c478bd9Sstevel@tonic-gate  * the next dnlc_start_dir() which will return DNOMEM once.
283*7c478bd9Sstevel@tonic-gate  * This memory shortage may only be transient. It's up to the
284*7c478bd9Sstevel@tonic-gate  * file system as to what to do about this condition, but an
285*7c478bd9Sstevel@tonic-gate  * attempt to immediately re-build the cache will very likely
286*7c478bd9Sstevel@tonic-gate  * lead to the same shortage of memory and a thrashing situation.
287*7c478bd9Sstevel@tonic-gate  *
288*7c478bd9Sstevel@tonic-gate  * It's file system policy as to when and what size directories to cache.
289*7c478bd9Sstevel@tonic-gate  */
290*7c478bd9Sstevel@tonic-gate dcret_t dnlc_dir_start(dcanchor_t *dcap, uint_t num_entries);
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate /*
293*7c478bd9Sstevel@tonic-gate  * dnlc_dir_add_entry() adds an entry (name and handle) into a
294*7c478bd9Sstevel@tonic-gate  * partial or complete cache. "handle" is a file system specific
295*7c478bd9Sstevel@tonic-gate  * quantity that is returned on calls to dnlc_dir_lookup() - see below.
296*7c478bd9Sstevel@tonic-gate  * For example, "handle" for ufs holds the inumber and a directory
297*7c478bd9Sstevel@tonic-gate  * entry offset. Returns DOK, DNOCACHE, DTOOBIG.
298*7c478bd9Sstevel@tonic-gate  */
299*7c478bd9Sstevel@tonic-gate dcret_t dnlc_dir_add_entry(dcanchor_t *dcap, char *name, uint64_t handle);
300*7c478bd9Sstevel@tonic-gate 
301*7c478bd9Sstevel@tonic-gate /*
302*7c478bd9Sstevel@tonic-gate  * dnlc_dir_add_space adds free space (length and file system specific
303*7c478bd9Sstevel@tonic-gate  * handle) into a partial or complete cache. "handle" is a file
304*7c478bd9Sstevel@tonic-gate  * system specific quantity that is returned on calls to
305*7c478bd9Sstevel@tonic-gate  * dnlc_dir_rem_space_by_len(). For example, "handle" for ufs holds
306*7c478bd9Sstevel@tonic-gate  * the directory entry offset.  Returns DOK, DNOCACHE, DTOOBIG.
307*7c478bd9Sstevel@tonic-gate  */
308*7c478bd9Sstevel@tonic-gate dcret_t dnlc_dir_add_space(dcanchor_t *dcap, uint_t len, uint64_t handle);
309*7c478bd9Sstevel@tonic-gate 
310*7c478bd9Sstevel@tonic-gate /*
311*7c478bd9Sstevel@tonic-gate  * dnlc_dir_complete() indicates the previously partial cache is now complete.
312*7c478bd9Sstevel@tonic-gate  */
313*7c478bd9Sstevel@tonic-gate void dnlc_dir_complete(dcanchor_t *dcap);
314*7c478bd9Sstevel@tonic-gate 
315*7c478bd9Sstevel@tonic-gate /*
316*7c478bd9Sstevel@tonic-gate  * dnlc_dir_purge() deletes a partial or complete directory cache
317*7c478bd9Sstevel@tonic-gate  */
318*7c478bd9Sstevel@tonic-gate void dnlc_dir_purge(dcanchor_t *dcap);
319*7c478bd9Sstevel@tonic-gate 
320*7c478bd9Sstevel@tonic-gate /*
321*7c478bd9Sstevel@tonic-gate  * dnlc_dir_lookup() lookups a file name in a directory cache
322*7c478bd9Sstevel@tonic-gate  * and returns the file system handle specified on dnlc_dir_add_entry()
323*7c478bd9Sstevel@tonic-gate  * in "handlep". Returns DFOUND, DNOENT, DNOCACHE.
324*7c478bd9Sstevel@tonic-gate  */
325*7c478bd9Sstevel@tonic-gate dcret_t dnlc_dir_lookup(dcanchor_t *dcap, char *name, uint64_t *handlep);
326*7c478bd9Sstevel@tonic-gate 
327*7c478bd9Sstevel@tonic-gate /*
328*7c478bd9Sstevel@tonic-gate  * dnlc_dir_update() amends the handle for an entry in a directory cache
329*7c478bd9Sstevel@tonic-gate  * "handle" is the new file system specific handle for the file "name".
330*7c478bd9Sstevel@tonic-gate  * Returns DFOUND, DNOENT, DNOCACHE.
331*7c478bd9Sstevel@tonic-gate  */
332*7c478bd9Sstevel@tonic-gate dcret_t dnlc_dir_update(dcanchor_t *dcap, char *name, uint64_t handle);
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate /*
335*7c478bd9Sstevel@tonic-gate  * dnlc_dir_rem_entry() removes an entry form a directory cache.
336*7c478bd9Sstevel@tonic-gate  * Returns the handle if "handlep" non null.
337*7c478bd9Sstevel@tonic-gate  * Returns DFOUND, DNOENT, DNOCACHE.
338*7c478bd9Sstevel@tonic-gate  */
339*7c478bd9Sstevel@tonic-gate dcret_t dnlc_dir_rem_entry(dcanchor_t *dcap, char *name, uint64_t *handlep);
340*7c478bd9Sstevel@tonic-gate 
341*7c478bd9Sstevel@tonic-gate /*
342*7c478bd9Sstevel@tonic-gate  * dnlc_dir_rem_space_by_len() looks up and returns free space in a
343*7c478bd9Sstevel@tonic-gate  * directory cache of at least the given "len". Returns in "handlep"
344*7c478bd9Sstevel@tonic-gate  * the handle supplied when adding the free space in dnlc_dir_add_space().
345*7c478bd9Sstevel@tonic-gate  * Returns DFOUND, DNOENT, DNOCACHE.
346*7c478bd9Sstevel@tonic-gate  */
347*7c478bd9Sstevel@tonic-gate dcret_t dnlc_dir_rem_space_by_len(dcanchor_t *dcap, uint_t len,
348*7c478bd9Sstevel@tonic-gate     uint64_t *handlep);
349*7c478bd9Sstevel@tonic-gate 
350*7c478bd9Sstevel@tonic-gate /*
351*7c478bd9Sstevel@tonic-gate  * dnlc_dir_rem_space_by_handle() looks up and removes the free space in
352*7c478bd9Sstevel@tonic-gate  * a directory cache with the given handle. Returns DFOUND, DNOENT, DNOCACHE.
353*7c478bd9Sstevel@tonic-gate  */
354*7c478bd9Sstevel@tonic-gate dcret_t dnlc_dir_rem_space_by_handle(dcanchor_t *dcap, uint64_t handle);
355*7c478bd9Sstevel@tonic-gate 
356*7c478bd9Sstevel@tonic-gate /*
357*7c478bd9Sstevel@tonic-gate  * dnlc_dir_init() initialises a directory anchor
358*7c478bd9Sstevel@tonic-gate  */
359*7c478bd9Sstevel@tonic-gate #define	dnlc_dir_init(dcap) { \
360*7c478bd9Sstevel@tonic-gate 	(dcap)->dca_dircache = NULL; \
361*7c478bd9Sstevel@tonic-gate 	mutex_init(&(dcap)->dca_lock, NULL, MUTEX_DEFAULT, NULL); }
362*7c478bd9Sstevel@tonic-gate 
363*7c478bd9Sstevel@tonic-gate /*
364*7c478bd9Sstevel@tonic-gate  * dnlc_dir_fini() is called to indicate the anchor is no longer used.
365*7c478bd9Sstevel@tonic-gate  * It ensures there's no directory cache and mutex_destroys the lock
366*7c478bd9Sstevel@tonic-gate  */
367*7c478bd9Sstevel@tonic-gate void dnlc_dir_fini(dcanchor_t *dcap);
368*7c478bd9Sstevel@tonic-gate 
369*7c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
370*7c478bd9Sstevel@tonic-gate 
371*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
372*7c478bd9Sstevel@tonic-gate }
373*7c478bd9Sstevel@tonic-gate #endif
374*7c478bd9Sstevel@tonic-gate 
375*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_DNLC_H */
376