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