xref: /onnv-gate/usr/src/uts/common/sys/modhash_impl.h (revision 3247:e05001c14ea2)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*3247Sgjelinek  * Common Development and Distribution License (the "License").
6*3247Sgjelinek  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*3247Sgjelinek  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef _SYS_MODHASH_IMPL_H
270Sstevel@tonic-gate #define	_SYS_MODHASH_IMPL_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate /*
320Sstevel@tonic-gate  * Internal details for the kernel's generic hash implementation.
330Sstevel@tonic-gate  */
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #ifdef __cplusplus
360Sstevel@tonic-gate extern "C" {
370Sstevel@tonic-gate #endif
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #ifdef _KERNEL
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #include <sys/ksynch.h>
420Sstevel@tonic-gate #include <sys/modhash.h>
430Sstevel@tonic-gate 
440Sstevel@tonic-gate struct mod_hash_entry {
450Sstevel@tonic-gate 	mod_hash_key_t mhe_key;			/* stored hash key	*/
460Sstevel@tonic-gate 	mod_hash_val_t mhe_val;			/* stored hash value	*/
470Sstevel@tonic-gate 	struct mod_hash_entry *mhe_next;	/* next item in chain	*/
480Sstevel@tonic-gate };
490Sstevel@tonic-gate 
500Sstevel@tonic-gate struct mod_hash_stat {
510Sstevel@tonic-gate 	ulong_t mhs_hit;	/* tried a 'find' and it succeeded */
520Sstevel@tonic-gate 	ulong_t mhs_miss;	/* tried a 'find' but it failed */
530Sstevel@tonic-gate 	ulong_t mhs_coll;	/* occur when insert fails because of dup's */
540Sstevel@tonic-gate 	ulong_t mhs_nelems;	/* total number of stored key/value pairs */
550Sstevel@tonic-gate 	ulong_t mhs_nomem;	/* number of times kmem_alloc failed */
560Sstevel@tonic-gate };
570Sstevel@tonic-gate 
580Sstevel@tonic-gate struct mod_hash {
590Sstevel@tonic-gate 	krwlock_t	mh_contents;	/* lock protecting contents */
600Sstevel@tonic-gate 	char		*mh_name;	/* hash name */
610Sstevel@tonic-gate 	int		mh_sleep;	/* kmem_alloc flag */
620Sstevel@tonic-gate 	size_t		mh_nchains;	/* # of elements in mh_entries */
630Sstevel@tonic-gate 
640Sstevel@tonic-gate 	/* key and val destructor */
650Sstevel@tonic-gate 	void    (*mh_kdtor)(mod_hash_key_t);
660Sstevel@tonic-gate 	void    (*mh_vdtor)(mod_hash_val_t);
670Sstevel@tonic-gate 
680Sstevel@tonic-gate 	/* key comparator */
690Sstevel@tonic-gate 	int	(*mh_keycmp)(mod_hash_key_t, mod_hash_key_t);
700Sstevel@tonic-gate 
710Sstevel@tonic-gate 	/* hash algorithm, and algorithm-private data */
720Sstevel@tonic-gate 	uint_t  (*mh_hashalg)(void *, mod_hash_key_t);
730Sstevel@tonic-gate 	void    *mh_hashalg_data;
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 	struct mod_hash	*mh_next;	/* next hash in list */
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 	struct mod_hash_stat mh_stat;
780Sstevel@tonic-gate 
790Sstevel@tonic-gate 	struct mod_hash_entry *mh_entries[1];
800Sstevel@tonic-gate };
810Sstevel@tonic-gate 
820Sstevel@tonic-gate /*
830Sstevel@tonic-gate  * MH_SIZE()
840Sstevel@tonic-gate  * 	Compute the size of a mod_hash_t, in bytes, given the number of
850Sstevel@tonic-gate  * 	elements it contains.
860Sstevel@tonic-gate  */
870Sstevel@tonic-gate #define	MH_SIZE(n) \
880Sstevel@tonic-gate 	(sizeof (mod_hash_t) + ((n) - 1) * (sizeof (struct mod_hash_entry *)))
890Sstevel@tonic-gate 
900Sstevel@tonic-gate /*
910Sstevel@tonic-gate  * Module initialization; called once.
920Sstevel@tonic-gate  */
930Sstevel@tonic-gate void mod_hash_init(void);
940Sstevel@tonic-gate 
95*3247Sgjelinek /*
96*3247Sgjelinek  * Internal routines.  Use directly with care.
97*3247Sgjelinek  */
98*3247Sgjelinek uint_t i_mod_hash(mod_hash_t *, mod_hash_key_t);
99*3247Sgjelinek int i_mod_hash_insert_nosync(mod_hash_t *, mod_hash_key_t, mod_hash_val_t,
100*3247Sgjelinek     mod_hash_hndl_t);
101*3247Sgjelinek int i_mod_hash_remove_nosync(mod_hash_t *, mod_hash_key_t, mod_hash_val_t *);
102*3247Sgjelinek int i_mod_hash_find_nosync(mod_hash_t *, mod_hash_key_t, mod_hash_val_t *);
103*3247Sgjelinek void i_mod_hash_walk_nosync(mod_hash_t *, uint_t (*)(mod_hash_key_t,
104*3247Sgjelinek     mod_hash_val_t *, void *), void *);
105*3247Sgjelinek void i_mod_hash_clear_nosync(mod_hash_t *hash);
106*3247Sgjelinek 
1070Sstevel@tonic-gate #endif /* _KERNEL */
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate #ifdef __cplusplus
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate #endif
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate #endif /* _SYS_MODHASH_IMPL_H */
114