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 5*0209230bSgjelinek * Common Development and Distribution License (the "License"). 6*0209230bSgjelinek * 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 /* 22*0209230bSgjelinek * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_MODHASH_IMPL_H 277c478bd9Sstevel@tonic-gate #define _SYS_MODHASH_IMPL_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Internal details for the kernel's generic hash implementation. 317c478bd9Sstevel@tonic-gate */ 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #ifdef __cplusplus 347c478bd9Sstevel@tonic-gate extern "C" { 357c478bd9Sstevel@tonic-gate #endif 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #ifdef _KERNEL 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <sys/ksynch.h> 407c478bd9Sstevel@tonic-gate #include <sys/modhash.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate struct mod_hash_entry { 437c478bd9Sstevel@tonic-gate mod_hash_key_t mhe_key; /* stored hash key */ 447c478bd9Sstevel@tonic-gate mod_hash_val_t mhe_val; /* stored hash value */ 457c478bd9Sstevel@tonic-gate struct mod_hash_entry *mhe_next; /* next item in chain */ 467c478bd9Sstevel@tonic-gate }; 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate struct mod_hash_stat { 497c478bd9Sstevel@tonic-gate ulong_t mhs_hit; /* tried a 'find' and it succeeded */ 507c478bd9Sstevel@tonic-gate ulong_t mhs_miss; /* tried a 'find' but it failed */ 517c478bd9Sstevel@tonic-gate ulong_t mhs_coll; /* occur when insert fails because of dup's */ 527c478bd9Sstevel@tonic-gate ulong_t mhs_nelems; /* total number of stored key/value pairs */ 537c478bd9Sstevel@tonic-gate ulong_t mhs_nomem; /* number of times kmem_alloc failed */ 547c478bd9Sstevel@tonic-gate }; 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate struct mod_hash { 577c478bd9Sstevel@tonic-gate krwlock_t mh_contents; /* lock protecting contents */ 587c478bd9Sstevel@tonic-gate char *mh_name; /* hash name */ 597c478bd9Sstevel@tonic-gate int mh_sleep; /* kmem_alloc flag */ 607c478bd9Sstevel@tonic-gate size_t mh_nchains; /* # of elements in mh_entries */ 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /* key and val destructor */ 637c478bd9Sstevel@tonic-gate void (*mh_kdtor)(mod_hash_key_t); 647c478bd9Sstevel@tonic-gate void (*mh_vdtor)(mod_hash_val_t); 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* key comparator */ 677c478bd9Sstevel@tonic-gate int (*mh_keycmp)(mod_hash_key_t, mod_hash_key_t); 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate /* hash algorithm, and algorithm-private data */ 707c478bd9Sstevel@tonic-gate uint_t (*mh_hashalg)(void *, mod_hash_key_t); 717c478bd9Sstevel@tonic-gate void *mh_hashalg_data; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate struct mod_hash *mh_next; /* next hash in list */ 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate struct mod_hash_stat mh_stat; 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate struct mod_hash_entry *mh_entries[1]; 787c478bd9Sstevel@tonic-gate }; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * MH_SIZE() 827c478bd9Sstevel@tonic-gate * Compute the size of a mod_hash_t, in bytes, given the number of 837c478bd9Sstevel@tonic-gate * elements it contains. 847c478bd9Sstevel@tonic-gate */ 857c478bd9Sstevel@tonic-gate #define MH_SIZE(n) \ 867c478bd9Sstevel@tonic-gate (sizeof (mod_hash_t) + ((n) - 1) * (sizeof (struct mod_hash_entry *))) 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate /* 897c478bd9Sstevel@tonic-gate * Module initialization; called once. 907c478bd9Sstevel@tonic-gate */ 917c478bd9Sstevel@tonic-gate void mod_hash_init(void); 927c478bd9Sstevel@tonic-gate 93*0209230bSgjelinek /* 94*0209230bSgjelinek * Internal routines. Use directly with care. 95*0209230bSgjelinek */ 96*0209230bSgjelinek uint_t i_mod_hash(mod_hash_t *, mod_hash_key_t); 97*0209230bSgjelinek int i_mod_hash_insert_nosync(mod_hash_t *, mod_hash_key_t, mod_hash_val_t, 98*0209230bSgjelinek mod_hash_hndl_t); 99*0209230bSgjelinek int i_mod_hash_remove_nosync(mod_hash_t *, mod_hash_key_t, mod_hash_val_t *); 100*0209230bSgjelinek int i_mod_hash_find_nosync(mod_hash_t *, mod_hash_key_t, mod_hash_val_t *); 101*0209230bSgjelinek void i_mod_hash_walk_nosync(mod_hash_t *, uint_t (*)(mod_hash_key_t, 102*0209230bSgjelinek mod_hash_val_t *, void *), void *); 103*0209230bSgjelinek void i_mod_hash_clear_nosync(mod_hash_t *hash); 104*0209230bSgjelinek 1057c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1087c478bd9Sstevel@tonic-gate } 1097c478bd9Sstevel@tonic-gate #endif 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate #endif /* _SYS_MODHASH_IMPL_H */ 112