]> git.proxmox.com Git - mirror_zfs-debian.git/blob - module/icp/include/sys/modhash_impl.h
New upstream version 0.7.2
[mirror_zfs-debian.git] / module / icp / include / sys / modhash_impl.h
1 /*
2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #ifndef _SYS_MODHASH_IMPL_H
27 #define _SYS_MODHASH_IMPL_H
28
29 /*
30 * Internal details for the kernel's generic hash implementation.
31 */
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #include <sys/zfs_context.h>
38 #include <sys/modhash.h>
39
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 */
44 };
45
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 */
52 };
53
54 struct mod_hash {
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 */
59
60 /* key and val destructor */
61 void (*mh_kdtor)(mod_hash_key_t);
62 void (*mh_vdtor)(mod_hash_val_t);
63
64 /* key comparator */
65 int (*mh_keycmp)(mod_hash_key_t, mod_hash_key_t);
66
67 /* hash algorithm, and algorithm-private data */
68 uint_t (*mh_hashalg)(void *, mod_hash_key_t);
69 void *mh_hashalg_data;
70
71 struct mod_hash *mh_next; /* next hash in list */
72
73 struct mod_hash_stat mh_stat;
74
75 struct mod_hash_entry *mh_entries[1];
76 };
77
78 /*
79 * MH_SIZE()
80 * Compute the size of a mod_hash_t, in bytes, given the number of
81 * elements it contains.
82 */
83 #define MH_SIZE(n) \
84 (sizeof (mod_hash_t) + ((n) - 1) * (sizeof (struct mod_hash_entry *)))
85
86 /*
87 * Module initialization; called once.
88 */
89 void mod_hash_fini(void);
90 void mod_hash_init(void);
91
92 /*
93 * Internal routines. Use directly with care.
94 */
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,
97 mod_hash_hndl_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);
103
104 #ifdef __cplusplus
105 }
106 #endif
107
108 #endif /* _SYS_MODHASH_IMPL_H */