1*fcf3ce44SJohn Forte /* 2*fcf3ce44SJohn Forte * CDDL HEADER START 3*fcf3ce44SJohn Forte * 4*fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the 5*fcf3ce44SJohn Forte * Common Development and Distribution License (the "License"). 6*fcf3ce44SJohn Forte * You may not use this file except in compliance with the License. 7*fcf3ce44SJohn Forte * 8*fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing. 10*fcf3ce44SJohn Forte * See the License for the specific language governing permissions 11*fcf3ce44SJohn Forte * and limitations under the License. 12*fcf3ce44SJohn Forte * 13*fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each 14*fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the 16*fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying 17*fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner] 18*fcf3ce44SJohn Forte * 19*fcf3ce44SJohn Forte * CDDL HEADER END 20*fcf3ce44SJohn Forte */ 21*fcf3ce44SJohn Forte 22*fcf3ce44SJohn Forte /* 23*fcf3ce44SJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24*fcf3ce44SJohn Forte * Use is subject to license terms. 25*fcf3ce44SJohn Forte */ 26*fcf3ce44SJohn Forte 27*fcf3ce44SJohn Forte #ifndef _ISNS_HTAB_H 28*fcf3ce44SJohn Forte #define _ISNS_HTAB_H 29*fcf3ce44SJohn Forte 30*fcf3ce44SJohn Forte #ifdef __cplusplus 31*fcf3ce44SJohn Forte extern "C" { 32*fcf3ce44SJohn Forte #endif 33*fcf3ce44SJohn Forte 34*fcf3ce44SJohn Forte #define HASH_RATIO (3) 35*fcf3ce44SJohn Forte #define MAX_LOGSIZE (sizeof (uint32_t) * 8 - 1) 36*fcf3ce44SJohn Forte #define HVAL_MASK (((uint32_t)1 << MAX_LOGSIZE) - 1) 37*fcf3ce44SJohn Forte #define BAD_HVAL_MASK ((uint32_t)1 << MAX_LOGSIZE) 38*fcf3ce44SJohn Forte #define VALID_HVAL(H) ((H) & HVAL_MASK) 39*fcf3ce44SJohn Forte #define BAD_HVAL(H) (((H) & BAD_HVAL_MASK) == BAD_HVAL_MASK) 40*fcf3ce44SJohn Forte 41*fcf3ce44SJohn Forte #define FLAGS_CTRL_MASK (0x10000000) 42*fcf3ce44SJohn Forte #define FLAGS_CHUNK_MASK (0x00001111) 43*fcf3ce44SJohn Forte 44*fcf3ce44SJohn Forte typedef struct htab_item { 45*fcf3ce44SJohn Forte uint32_t hval; 46*fcf3ce44SJohn Forte void *p; 47*fcf3ce44SJohn Forte struct htab_item *next; 48*fcf3ce44SJohn Forte } htab_item_t; 49*fcf3ce44SJohn Forte 50*fcf3ce44SJohn Forte typedef struct htab_itemx { 51*fcf3ce44SJohn Forte uint32_t uid; 52*fcf3ce44SJohn Forte uint32_t hval; 53*fcf3ce44SJohn Forte uint32_t t; 54*fcf3ce44SJohn Forte int bf; 55*fcf3ce44SJohn Forte struct htab_itemx *l; 56*fcf3ce44SJohn Forte struct htab_itemx *r; 57*fcf3ce44SJohn Forte struct htab_itemx *n; 58*fcf3ce44SJohn Forte } htab_itemx_t; 59*fcf3ce44SJohn Forte 60*fcf3ce44SJohn Forte typedef struct htab { 61*fcf3ce44SJohn Forte int flags; 62*fcf3ce44SJohn Forte struct cache *c; 63*fcf3ce44SJohn Forte htab_item_t **items; 64*fcf3ce44SJohn Forte uint16_t logsize; 65*fcf3ce44SJohn Forte uint16_t chunks; 66*fcf3ce44SJohn Forte uint32_t mask; 67*fcf3ce44SJohn Forte uint32_t count; 68*fcf3ce44SJohn Forte /* AVL tree of the object UIDs */ 69*fcf3ce44SJohn Forte htab_itemx_t *avlt; 70*fcf3ce44SJohn Forte /* the biggest UID in the tree */ 71*fcf3ce44SJohn Forte uint32_t buid; 72*fcf3ce44SJohn Forte /* fifo list of available UIDs */ 73*fcf3ce44SJohn Forte htab_itemx_t *list; 74*fcf3ce44SJohn Forte htab_itemx_t *tail; 75*fcf3ce44SJohn Forte } htab_t; 76*fcf3ce44SJohn Forte 77*fcf3ce44SJohn Forte #define UID_FLAGS_SEQ (0x1) 78*fcf3ce44SJohn Forte 79*fcf3ce44SJohn Forte #define FOR_EACH_ITEM(HTAB, UID, STMT) \ 80*fcf3ce44SJohn Forte {\ 81*fcf3ce44SJohn Forte UID = htab_get_next(HTAB, UID);\ 82*fcf3ce44SJohn Forte while (UID != 0) {\ 83*fcf3ce44SJohn Forte STMT\ 84*fcf3ce44SJohn Forte UID = htab_get_next(HTAB, UID);\ 85*fcf3ce44SJohn Forte }\ 86*fcf3ce44SJohn Forte } 87*fcf3ce44SJohn Forte 88*fcf3ce44SJohn Forte void htab_init(void); 89*fcf3ce44SJohn Forte htab_t *htab_create(int, uint16_t, uint16_t); 90*fcf3ce44SJohn Forte void htab_destroy(htab_t *); 91*fcf3ce44SJohn Forte uint32_t htab_compute_hval(const uchar_t *); 92*fcf3ce44SJohn Forte int htab_add(htab_t *, void *, int, uint32_t *, int *); 93*fcf3ce44SJohn Forte isns_obj_t *htab_remove(htab_t *, void *, uint32_t, int); 94*fcf3ce44SJohn Forte int htab_lookup(htab_t *, void *, uint32_t, 95*fcf3ce44SJohn Forte uint32_t *, int (*)(void *, void *), int); 96*fcf3ce44SJohn Forte uint32_t htab_get_next(htab_t *, uint32_t); 97*fcf3ce44SJohn Forte #ifdef DEBUG 98*fcf3ce44SJohn Forte void htab_dump(htab_t *); 99*fcf3ce44SJohn Forte #endif 100*fcf3ce44SJohn Forte 101*fcf3ce44SJohn Forte #ifdef __cplusplus 102*fcf3ce44SJohn Forte } 103*fcf3ce44SJohn Forte #endif 104*fcf3ce44SJohn Forte 105*fcf3ce44SJohn Forte #endif /* _ISNS_HTAB_H */ 106