4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SYS_MODHASH_IMPL_H
27 #define _SYS_MODHASH_IMPL_H
30 * Internal details for the kernel's generic hash implementation.
37 #include <sys/zfs_context.h>
38 #include <sys/modhash.h>
40 struct mod_hash_entry {
41 mod_hash_key_t mhe_key; /* stored hash key */
42 mod_hash_val_t mhe_val; /* stored hash value */
43 struct mod_hash_entry *mhe_next; /* next item in chain */
46 struct mod_hash_stat {
47 ulong_t mhs_hit; /* tried a 'find' and it succeeded */
48 ulong_t mhs_miss; /* tried a 'find' but it failed */
49 ulong_t mhs_coll; /* occur when insert fails because of dup's */
50 ulong_t mhs_nelems; /* total number of stored key/value pairs */
51 ulong_t mhs_nomem; /* number of times kmem_alloc failed */
55 krwlock_t mh_contents; /* lock protecting contents */
56 char *mh_name; /* hash name */
57 int mh_sleep; /* kmem_alloc flag */
58 size_t mh_nchains; /* # of elements in mh_entries */
60 /* key and val destructor */
61 void (*mh_kdtor)(mod_hash_key_t);
62 void (*mh_vdtor)(mod_hash_val_t);
65 int (*mh_keycmp)(mod_hash_key_t, mod_hash_key_t);
67 /* hash algorithm, and algorithm-private data */
68 uint_t (*mh_hashalg)(void *, mod_hash_key_t);
69 void *mh_hashalg_data;
71 struct mod_hash *mh_next; /* next hash in list */
73 struct mod_hash_stat mh_stat;
75 struct mod_hash_entry *mh_entries[1];
80 * Compute the size of a mod_hash_t, in bytes, given the number of
81 * elements it contains.
84 (sizeof (mod_hash_t) + ((n) - 1) * (sizeof (struct mod_hash_entry *)))
87 * Module initialization; called once.
89 void mod_hash_fini(void);
90 void mod_hash_init(void);
93 * Internal routines. Use directly with care.
95 uint_t i_mod_hash(mod_hash_t *, mod_hash_key_t);
96 int i_mod_hash_insert_nosync(mod_hash_t *, mod_hash_key_t, mod_hash_val_t,
98 int i_mod_hash_remove_nosync(mod_hash_t *, mod_hash_key_t, mod_hash_val_t *);
99 int i_mod_hash_find_nosync(mod_hash_t *, mod_hash_key_t, mod_hash_val_t *);
100 void i_mod_hash_walk_nosync(mod_hash_t *, uint_t (*)(mod_hash_key_t,
101 mod_hash_val_t *, void *), void *);
102 void i_mod_hash_clear_nosync(mod_hash_t *hash);
108 #endif /* _SYS_MODHASH_IMPL_H */