xref: /titanic_50/usr/src/cmd/isns/isnsd/isns_cache.h (revision 385cc6b4ad1792caef3f84eb61eed3f27085801f)
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 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _ISNS_CACHE_H
28 #define	_ISNS_CACHE_H
29 
30 #include <synch.h>
31 #include <isns_htab.h>
32 #include <isns_dd.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #define	CACHE_FLAG_UPDATED	0x1
39 
40 #define	SET_CACHE_UPDATED()	(cache_flag |= CACHE_FLAG_UPDATED)
41 #define	RESET_CACHE_UPDATED()	(cache_flag &= ~CACHE_FLAG_UPDATED)
42 
43 #define	IS_CACHE_UPDATED()	(cache_flag & CACHE_FLAG_UPDATED)
44 
45 #define	CACHE_NO_ACTION	(0)
46 #define	CACHE_READ	(1)
47 #define	CACHE_TRY_READ	(2)
48 #define	CACHE_WRITE	(3)
49 
50 typedef struct cache {
51 	rwlock_t l;
52 	htab_t **t;
53 	matrix_t **x;
54 	uint32_t (*get_hval)(void *, uint16_t, uint32_t *);
55 	uint32_t (*get_uid)(const void *);
56 	uint32_t (*set_uid)(void *, uint32_t);
57 	uint32_t (*timestamp)(void);
58 	int (*add_hook)(void *);
59 	int (*replace_hook)(void *, void *, uint32_t *, int);
60 	int (*cmp)(void *, void *, int);
61 	void *(*clone)(void *, int);
62 	int (*ddd)(void *, const uchar_t);
63 #ifdef DEBUG
64 	void (*dump)(void *);
65 #endif
66 } cache_t;
67 
68 int cache_init(void);
69 void cache_destroy(void);
70 int cache_lock(int);
71 int cache_unlock(int, int);
72 int cache_lock_read(void);
73 int cache_lock_write(void);
74 int cache_unlock_sync(int);
75 int cache_unlock_nosync(void);
76 htab_t *cache_get_htab(isns_type_t);
77 matrix_t *cache_get_matrix(isns_type_t);
78 int cache_lookup(lookup_ctrl_t *, uint32_t *, int (*)(void *, void *));
79 int cache_rekey(lookup_ctrl_t *, uint32_t *, int (*)(void *, void *));
80 int cache_add(isns_obj_t *, int, uint32_t *, int *);
81 isns_obj_t *cache_remove(lookup_ctrl_t *, int);
82 
83 #ifdef DEBUG
84 void cache_dump_htab(isns_type_t);
85 #endif
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 #endif /* _ISNS_CACHE_H */
92