xref: /illumos-gate/usr/src/uts/common/sys/dnlc.h (revision e7b9901e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5033f9833Sek  * Common Development and Distribution License (the "License").
6033f9833Sek  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22744947dcSTom Erickson  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
26b4203d75SMarcel Telka /*	  All Rights Reserved	*/
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
307c478bd9Sstevel@tonic-gate  * The Regents of the University of California
317c478bd9Sstevel@tonic-gate  * All Rights Reserved
327c478bd9Sstevel@tonic-gate  *
337c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
347c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
357c478bd9Sstevel@tonic-gate  * contributors.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #ifndef _SYS_DNLC_H
397c478bd9Sstevel@tonic-gate #define	_SYS_DNLC_H
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
427c478bd9Sstevel@tonic-gate extern "C" {
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * DNLC - Directory name lookup cache.
497c478bd9Sstevel@tonic-gate  * There are now two sorts of name caching:
507c478bd9Sstevel@tonic-gate  *
517c478bd9Sstevel@tonic-gate  * Standard dnlc: This original cache holds recent mappings
527c478bd9Sstevel@tonic-gate  *                of <directory vnode, name> to vnode mappings.
537c478bd9Sstevel@tonic-gate  *
547c478bd9Sstevel@tonic-gate  * Directory caches: Entire large directories can be cached, subject to
557c478bd9Sstevel@tonic-gate  *		     memory availability and tunables. A directory cache
567c478bd9Sstevel@tonic-gate  *		     anchor point must be provided in the xxnode for
577c478bd9Sstevel@tonic-gate  *		     a directory.
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate /*
627c478bd9Sstevel@tonic-gate  * Standard dnlc
637c478bd9Sstevel@tonic-gate  * =============
647c478bd9Sstevel@tonic-gate  */
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * This structure describes the elements in the cache of recent
687c478bd9Sstevel@tonic-gate  * names looked up.
697c478bd9Sstevel@tonic-gate  *
707c478bd9Sstevel@tonic-gate  * Note namlen is a uchar_t to conserve space
717c478bd9Sstevel@tonic-gate  * and alignment padding. The max length of any
727c478bd9Sstevel@tonic-gate  * pathname component is defined as MAXNAMELEN
737c478bd9Sstevel@tonic-gate  * which is 256 (including the terminating null).
747c478bd9Sstevel@tonic-gate  * So provided this doesn't change, we don't include the null,
757c478bd9Sstevel@tonic-gate  * we always use bcmp to compare strings, and we don't start
767c478bd9Sstevel@tonic-gate  * storing full names, then we are ok. The space savings are worth it.
777c478bd9Sstevel@tonic-gate  */
787c478bd9Sstevel@tonic-gate typedef struct ncache {
798329232eSGordon Ross 	struct ncache *hash_next;	/* hash chain, MUST BE FIRST */
807c478bd9Sstevel@tonic-gate 	struct ncache *hash_prev;
817c478bd9Sstevel@tonic-gate 	struct vnode *vp;		/* vnode the name refers to */
827c478bd9Sstevel@tonic-gate 	struct vnode *dp;		/* vnode of parent of name */
837c478bd9Sstevel@tonic-gate 	int hash;			/* hash signature */
847c478bd9Sstevel@tonic-gate 	uchar_t namlen;			/* length of name */
85*e7b9901eSToomas Soome 	char name[];			/* segment name */
867c478bd9Sstevel@tonic-gate } ncache_t;
877c478bd9Sstevel@tonic-gate 
88*e7b9901eSToomas Soome /*
89*e7b9901eSToomas Soome  * Produce size of struct ncache with space allocated in name string.
90*e7b9901eSToomas Soome  */
91*e7b9901eSToomas Soome #define	NCACHE_SIZE(namelen)	offsetof(ncache_t, name) + (namelen)
92*e7b9901eSToomas Soome 
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * Hash table bucket structure of name cache entries for fast lookup.
957c478bd9Sstevel@tonic-gate  */
967c478bd9Sstevel@tonic-gate typedef struct nc_hash	{
977c478bd9Sstevel@tonic-gate 	ncache_t *hash_next;
987c478bd9Sstevel@tonic-gate 	ncache_t *hash_prev;
997c478bd9Sstevel@tonic-gate 	kmutex_t hash_lock;
1007c478bd9Sstevel@tonic-gate } nc_hash_t;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate  * Statistics on name cache
1047c478bd9Sstevel@tonic-gate  * Not protected by locks
1057c478bd9Sstevel@tonic-gate  */
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * ncstats has been deprecated, due to the integer size of the counters
1087c478bd9Sstevel@tonic-gate  * which can easily overflow in the dnlc.
1097c478bd9Sstevel@tonic-gate  * It is maintained (at some expense) for compatability.
1107c478bd9Sstevel@tonic-gate  * The preferred interface is the kstat accessible nc_stats below, ehich
1117c478bd9Sstevel@tonic-gate  * is actually shared with directory caching.
1127c478bd9Sstevel@tonic-gate  */
1137c478bd9Sstevel@tonic-gate struct ncstats {
1147c478bd9Sstevel@tonic-gate 	int	hits;		/* hits that we can really use */
1157c478bd9Sstevel@tonic-gate 	int	misses;		/* cache misses */
1167c478bd9Sstevel@tonic-gate 	int	enters;		/* number of enters done */
1177c478bd9Sstevel@tonic-gate 	int	dbl_enters;	/* number of enters tried when already cached */
1187c478bd9Sstevel@tonic-gate 	int	long_enter;	/* deprecated, no longer accounted */
1197c478bd9Sstevel@tonic-gate 	int	long_look;	/* deprecated, no longer accounted */
1207c478bd9Sstevel@tonic-gate 	int	move_to_front;	/* entry moved to front of hash chain */
1217c478bd9Sstevel@tonic-gate 	int	purges;		/* number of purges of cache */
1227c478bd9Sstevel@tonic-gate };
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate struct nc_stats {
1257c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_hits;		/* cache hits */
1267c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_misses;	/* cache misses */
1277c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_neg_hits;	/* negative cache hits */
1287c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_enters;	/* enters */
1297c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dbl_enters;	/* enters when entry already cached */
1307c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_purge_total;	/* total entries prurged */
1317c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_purge_all;	/* dnlc_purge() calls */
1327c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_purge_vp;	/* dnlc_purge_vp() calls */
1337c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_purge_vfs;	/* dnlc_purge_vfs() calls */
1347c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_purge_fs1;	/* dnlc_purge_fs1() calls */
1357c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_pick_free;	/* found a free ncache */
1367c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_pick_heur;	/* found ncache w/ NULL vpages */
1377c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_pick_last;	/* found last ncache on chain */
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 	/* directory caching stats */
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_hits;	/* dir cache hits */
1427c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_misses;	/* dir cache misses */
1437c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_cur_dirs;	/* current # directories cached */
1447c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_num_ents;	/* current # entries cached */
1457c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dirs_cached;	/* total # directories cached */
1467c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_start_nm;	/* dir start no memory */
1477c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_add_nm;	/* add entry/space - no memory */
1487c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_addabort;	/* add entry/space - abort */
1497c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_add_max;	/* add entry/space - max exceeded */
1507c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_reme_fai;	/* remove entry fail */
1517c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_rems_fai;	/* remove space fail */
1527c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_upd_fail;	/* update space fail */
1537c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_finipurg;	/* fini purges */
1547c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_rec_last;	/* reclaim last */
1557c478bd9Sstevel@tonic-gate 	kstat_named_t ncs_dir_recl_any;	/* reclaim any */
1567c478bd9Sstevel@tonic-gate };
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate /*
1597c478bd9Sstevel@tonic-gate  * The dnlc hashing function.
1607c478bd9Sstevel@tonic-gate  * Although really a kernel macro we export it to allow validation
1617c478bd9Sstevel@tonic-gate  * of ncache_t entries by mdb. Note, mdb can handle the ASSERT.
1627c478bd9Sstevel@tonic-gate  *
1637c478bd9Sstevel@tonic-gate  * 'hash' and 'namlen' must be l-values. A check is made to ensure
1647c478bd9Sstevel@tonic-gate  * the name length fits into an unsigned char (see ncache_t).
1657c478bd9Sstevel@tonic-gate  */
1667c478bd9Sstevel@tonic-gate #define	DNLCHASH(name, dvp, hash, namlen)			\
1677c478bd9Sstevel@tonic-gate 	{							\
168744947dcSTom Erickson 		char Xc;					\
169744947dcSTom Erickson 		const char *Xcp;				\
1707c478bd9Sstevel@tonic-gate 		hash = (int)((uintptr_t)(dvp)) >> 8;		\
1717c478bd9Sstevel@tonic-gate 		for (Xcp = (name); (Xc = *Xcp) != 0; Xcp++)	\
1727c478bd9Sstevel@tonic-gate 			(hash) = ((hash) << 4) + (hash) + Xc;	\
1737c478bd9Sstevel@tonic-gate 		ASSERT((Xcp - (name)) <= ((1 << NBBY) - 1));	\
1747c478bd9Sstevel@tonic-gate 		(namlen) = Xcp - (name);			\
1757c478bd9Sstevel@tonic-gate 	}
1767c478bd9Sstevel@tonic-gate 
1778329232eSGordon Ross #if defined(_KERNEL) || defined(_FAKE_KERNEL)
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
1807c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate extern int ncsize;		/* set in param_init() # of dnlc entries */
1837c478bd9Sstevel@tonic-gate extern vnode_t negative_cache_vnode;
1847c478bd9Sstevel@tonic-gate #define	DNLC_NO_VNODE &negative_cache_vnode
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate void	dnlc_init(void);
187744947dcSTom Erickson void	dnlc_enter(vnode_t *, const char *, vnode_t *);
188744947dcSTom Erickson void	dnlc_update(vnode_t *, const char *, vnode_t *);
189744947dcSTom Erickson vnode_t	*dnlc_lookup(vnode_t *, const char *);
1907c478bd9Sstevel@tonic-gate void	dnlc_purge(void);
1917c478bd9Sstevel@tonic-gate void	dnlc_purge_vp(vnode_t *);
1927c478bd9Sstevel@tonic-gate int	dnlc_purge_vfsp(vfs_t *, int);
193744947dcSTom Erickson void	dnlc_remove(vnode_t *, const char *);
1947c478bd9Sstevel@tonic-gate int	dnlc_fs_purge1(struct vnodeops *);
195033f9833Sek void	dnlc_reduce_cache(void *);
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate  * Directory caching interfaces
2027c478bd9Sstevel@tonic-gate  * ============================
2037c478bd9Sstevel@tonic-gate  */
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate /*
2067c478bd9Sstevel@tonic-gate  * Typically for large directories, the file names will be the same or
2077c478bd9Sstevel@tonic-gate  * at least similar lengths. So there's no point in anything more elaborate
2087c478bd9Sstevel@tonic-gate  * than a simple unordered linked list of free space entries.
2097c478bd9Sstevel@tonic-gate  * For small directories the name length distribution doesn't really matter.
2107c478bd9Sstevel@tonic-gate  */
2117c478bd9Sstevel@tonic-gate typedef struct dcfree {
2127c478bd9Sstevel@tonic-gate 	uint64_t df_handle;		/* fs supplied handle */
2138329232eSGordon Ross 	struct dcfree *df_next;		/* link to next free entry in bucket */
2147c478bd9Sstevel@tonic-gate 	uint_t df_len;			/* length of free entry */
2157c478bd9Sstevel@tonic-gate } dcfree_t;
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate typedef struct dcentry {
2187c478bd9Sstevel@tonic-gate 	uint64_t de_handle;		/* fs supplied and returned data */
2197c478bd9Sstevel@tonic-gate 	struct dcentry *de_next;	/* link to next name entry in bucket */
2207c478bd9Sstevel@tonic-gate 	int de_hash;			/* hash signature */
2217c478bd9Sstevel@tonic-gate 	uchar_t de_namelen;		/* length of name excluding null */
222*e7b9901eSToomas Soome 	char de_name[];			/* name */
2237c478bd9Sstevel@tonic-gate } dcentry_t;
2247c478bd9Sstevel@tonic-gate 
225*e7b9901eSToomas Soome /*
226*e7b9901eSToomas Soome  * Produce size of struct dcentry with space allocated in name string.
227*e7b9901eSToomas Soome  */
228*e7b9901eSToomas Soome #define	DCENTTRY_SIZE(namelen)	offsetof(dcentry_t, de_name) + (namelen)
229*e7b9901eSToomas Soome 
2307c478bd9Sstevel@tonic-gate typedef struct dircache {
2317c478bd9Sstevel@tonic-gate 	struct dircache *dc_next;	/* chain - for purge purposes */
2327c478bd9Sstevel@tonic-gate 	struct dircache *dc_prev;	/* chain - for purge purposes */
2337c478bd9Sstevel@tonic-gate 	int64_t dc_actime;		/* dir access time, from lbolt64 */
2347c478bd9Sstevel@tonic-gate 	dcentry_t **dc_namehash;	/* entry hash table pointer */
2357c478bd9Sstevel@tonic-gate 	dcfree_t **dc_freehash;		/* free entry hash table pointer */
2367c478bd9Sstevel@tonic-gate 	uint_t dc_num_entries;		/* no of named entries */
2377c478bd9Sstevel@tonic-gate 	uint_t dc_num_free;		/* no of free space entries */
2387c478bd9Sstevel@tonic-gate 	uint_t dc_nhash_mask;		/* name hash table size - 1 */
2397c478bd9Sstevel@tonic-gate 	uint_t dc_fhash_mask;		/* free space hash table size - 1 */
2407c478bd9Sstevel@tonic-gate 	struct dcanchor *dc_anchor;	/* back ptr to anchor */
2417c478bd9Sstevel@tonic-gate 	boolean_t dc_complete;		/* cache complete boolean */
2427c478bd9Sstevel@tonic-gate } dircache_t;
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate typedef struct dcanchor {
2457c478bd9Sstevel@tonic-gate 	void *dca_dircache;	/* pointer to directory cache */
2467c478bd9Sstevel@tonic-gate 	kmutex_t dca_lock;		/* protects the directory cache */
2477c478bd9Sstevel@tonic-gate } dcanchor_t;
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate /*
2507c478bd9Sstevel@tonic-gate  * Head struct for doubly linked chain of dircache_t
2517c478bd9Sstevel@tonic-gate  * The next and prev fields must match those of a dircache_t
2527c478bd9Sstevel@tonic-gate  */
2537c478bd9Sstevel@tonic-gate typedef struct {
2547c478bd9Sstevel@tonic-gate 	dircache_t *dch_next;		/* next in chain */
2557c478bd9Sstevel@tonic-gate 	dircache_t *dch_prev;		/* prev in chain */
2567c478bd9Sstevel@tonic-gate 	kmutex_t dch_lock;		/* lock for the chain */
2577c478bd9Sstevel@tonic-gate } dchead_t;
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate /*
2637c478bd9Sstevel@tonic-gate  * Status returns from the directory cache interfaces
2647c478bd9Sstevel@tonic-gate  */
2657c478bd9Sstevel@tonic-gate typedef enum {
2667c478bd9Sstevel@tonic-gate 	DOK,		/* operation sucessful */
2677c478bd9Sstevel@tonic-gate 	DNOCACHE,	/* there is no cache */
2687c478bd9Sstevel@tonic-gate 	DFOUND,		/* entry found */
2697c478bd9Sstevel@tonic-gate 	DNOENT,		/* no entry found */
2707c478bd9Sstevel@tonic-gate 	DTOOBIG,	/* exceeds tunable dnlc_max_dir_cache */
2717c478bd9Sstevel@tonic-gate 	DNOMEM		/* no memory */
2727c478bd9Sstevel@tonic-gate } dcret_t;
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate /*
2757c478bd9Sstevel@tonic-gate  * dnlc_dir_start() requests that a directory be cached.
2767c478bd9Sstevel@tonic-gate  * This must be called initially to enable caching on a directory.
2777c478bd9Sstevel@tonic-gate  * After a successful call, directory entries and free space can be
2787c478bd9Sstevel@tonic-gate  * added (see below) until the directory is marked complete.
2797c478bd9Sstevel@tonic-gate  * "num_entries" is an estimate of the current number of
2807c478bd9Sstevel@tonic-gate  * directory entries. The request is rejected with DNOCACHE
2817c478bd9Sstevel@tonic-gate  * if num_entries falls below the tunable dnlc_dir_min_size (see
2827c478bd9Sstevel@tonic-gate  * below), and rejected with DTOOBIG if it's above dnlc_dir_max_size.
2837c478bd9Sstevel@tonic-gate  * Returns DOK, DNOCACHE, DTOOBIG, DNOMEM.
2847c478bd9Sstevel@tonic-gate  *
2857c478bd9Sstevel@tonic-gate  * Due to memory shortages, directory caches can be purged at
2867c478bd9Sstevel@tonic-gate  * any time. If the last directory cache is purged due to memory
2877c478bd9Sstevel@tonic-gate  * shortage, then the directory cache is marked internally
2887c478bd9Sstevel@tonic-gate  * as "no memory". Future returns will all be DNOCACHE until
2897c478bd9Sstevel@tonic-gate  * the next dnlc_start_dir() which will return DNOMEM once.
2907c478bd9Sstevel@tonic-gate  * This memory shortage may only be transient. It's up to the
2917c478bd9Sstevel@tonic-gate  * file system as to what to do about this condition, but an
2927c478bd9Sstevel@tonic-gate  * attempt to immediately re-build the cache will very likely
2937c478bd9Sstevel@tonic-gate  * lead to the same shortage of memory and a thrashing situation.
2947c478bd9Sstevel@tonic-gate  *
2957c478bd9Sstevel@tonic-gate  * It's file system policy as to when and what size directories to cache.
2967c478bd9Sstevel@tonic-gate  */
2977c478bd9Sstevel@tonic-gate dcret_t dnlc_dir_start(dcanchor_t *dcap, uint_t num_entries);
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate /*
3007c478bd9Sstevel@tonic-gate  * dnlc_dir_add_entry() adds an entry (name and handle) into a
3017c478bd9Sstevel@tonic-gate  * partial or complete cache. "handle" is a file system specific
3027c478bd9Sstevel@tonic-gate  * quantity that is returned on calls to dnlc_dir_lookup() - see below.
3037c478bd9Sstevel@tonic-gate  * For example, "handle" for ufs holds the inumber and a directory
3047c478bd9Sstevel@tonic-gate  * entry offset. Returns DOK, DNOCACHE, DTOOBIG.
3057c478bd9Sstevel@tonic-gate  */
306744947dcSTom Erickson dcret_t dnlc_dir_add_entry(dcanchor_t *dcap, const char *name, uint64_t handle);
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate /*
3097c478bd9Sstevel@tonic-gate  * dnlc_dir_add_space adds free space (length and file system specific
3107c478bd9Sstevel@tonic-gate  * handle) into a partial or complete cache. "handle" is a file
3117c478bd9Sstevel@tonic-gate  * system specific quantity that is returned on calls to
3127c478bd9Sstevel@tonic-gate  * dnlc_dir_rem_space_by_len(). For example, "handle" for ufs holds
3137c478bd9Sstevel@tonic-gate  * the directory entry offset.  Returns DOK, DNOCACHE, DTOOBIG.
3147c478bd9Sstevel@tonic-gate  */
3157c478bd9Sstevel@tonic-gate dcret_t dnlc_dir_add_space(dcanchor_t *dcap, uint_t len, uint64_t handle);
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate /*
3187c478bd9Sstevel@tonic-gate  * dnlc_dir_complete() indicates the previously partial cache is now complete.
3197c478bd9Sstevel@tonic-gate  */
3207c478bd9Sstevel@tonic-gate void dnlc_dir_complete(dcanchor_t *dcap);
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate /*
3237c478bd9Sstevel@tonic-gate  * dnlc_dir_purge() deletes a partial or complete directory cache
3247c478bd9Sstevel@tonic-gate  */
3257c478bd9Sstevel@tonic-gate void dnlc_dir_purge(dcanchor_t *dcap);
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate /*
3287c478bd9Sstevel@tonic-gate  * dnlc_dir_lookup() lookups a file name in a directory cache
3297c478bd9Sstevel@tonic-gate  * and returns the file system handle specified on dnlc_dir_add_entry()
3307c478bd9Sstevel@tonic-gate  * in "handlep". Returns DFOUND, DNOENT, DNOCACHE.
3317c478bd9Sstevel@tonic-gate  */
332744947dcSTom Erickson dcret_t dnlc_dir_lookup(dcanchor_t *dcap, const char *name, uint64_t *handlep);
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate /*
3357c478bd9Sstevel@tonic-gate  * dnlc_dir_update() amends the handle for an entry in a directory cache
3367c478bd9Sstevel@tonic-gate  * "handle" is the new file system specific handle for the file "name".
3377c478bd9Sstevel@tonic-gate  * Returns DFOUND, DNOENT, DNOCACHE.
3387c478bd9Sstevel@tonic-gate  */
339744947dcSTom Erickson dcret_t dnlc_dir_update(dcanchor_t *dcap, const char *name, uint64_t handle);
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate /*
3427c478bd9Sstevel@tonic-gate  * dnlc_dir_rem_entry() removes an entry form a directory cache.
3437c478bd9Sstevel@tonic-gate  * Returns the handle if "handlep" non null.
3447c478bd9Sstevel@tonic-gate  * Returns DFOUND, DNOENT, DNOCACHE.
3457c478bd9Sstevel@tonic-gate  */
346744947dcSTom Erickson dcret_t dnlc_dir_rem_entry(dcanchor_t *dcap, const char *name,
347744947dcSTom Erickson     uint64_t *handlep);
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate /*
3507c478bd9Sstevel@tonic-gate  * dnlc_dir_rem_space_by_len() looks up and returns free space in a
3517c478bd9Sstevel@tonic-gate  * directory cache of at least the given "len". Returns in "handlep"
3527c478bd9Sstevel@tonic-gate  * the handle supplied when adding the free space in dnlc_dir_add_space().
3537c478bd9Sstevel@tonic-gate  * Returns DFOUND, DNOENT, DNOCACHE.
3547c478bd9Sstevel@tonic-gate  */
3557c478bd9Sstevel@tonic-gate dcret_t dnlc_dir_rem_space_by_len(dcanchor_t *dcap, uint_t len,
3567c478bd9Sstevel@tonic-gate     uint64_t *handlep);
3577c478bd9Sstevel@tonic-gate 
3587c478bd9Sstevel@tonic-gate /*
3597c478bd9Sstevel@tonic-gate  * dnlc_dir_rem_space_by_handle() looks up and removes the free space in
3607c478bd9Sstevel@tonic-gate  * a directory cache with the given handle. Returns DFOUND, DNOENT, DNOCACHE.
3617c478bd9Sstevel@tonic-gate  */
3627c478bd9Sstevel@tonic-gate dcret_t dnlc_dir_rem_space_by_handle(dcanchor_t *dcap, uint64_t handle);
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate /*
3657c478bd9Sstevel@tonic-gate  * dnlc_dir_init() initialises a directory anchor
3667c478bd9Sstevel@tonic-gate  */
3677c478bd9Sstevel@tonic-gate #define	dnlc_dir_init(dcap) { \
3687c478bd9Sstevel@tonic-gate 	(dcap)->dca_dircache = NULL; \
3697c478bd9Sstevel@tonic-gate 	mutex_init(&(dcap)->dca_lock, NULL, MUTEX_DEFAULT, NULL); }
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate /*
3727c478bd9Sstevel@tonic-gate  * dnlc_dir_fini() is called to indicate the anchor is no longer used.
3737c478bd9Sstevel@tonic-gate  * It ensures there's no directory cache and mutex_destroys the lock
3747c478bd9Sstevel@tonic-gate  */
3757c478bd9Sstevel@tonic-gate void dnlc_dir_fini(dcanchor_t *dcap);
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate #endif	/* defined(_KERNEL) */
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
3807c478bd9Sstevel@tonic-gate }
3817c478bd9Sstevel@tonic-gate #endif
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate #endif	/* _SYS_DNLC_H */
384