xref: /onnv-gate/usr/src/cmd/isns/isnsd/cache.c (revision 7836:4e95154b5b7a)
1*7836SJohn.Forte@Sun.COM /*
2*7836SJohn.Forte@Sun.COM  * CDDL HEADER START
3*7836SJohn.Forte@Sun.COM  *
4*7836SJohn.Forte@Sun.COM  * The contents of this file are subject to the terms of the
5*7836SJohn.Forte@Sun.COM  * Common Development and Distribution License (the "License").
6*7836SJohn.Forte@Sun.COM  * You may not use this file except in compliance with the License.
7*7836SJohn.Forte@Sun.COM  *
8*7836SJohn.Forte@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7836SJohn.Forte@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*7836SJohn.Forte@Sun.COM  * See the License for the specific language governing permissions
11*7836SJohn.Forte@Sun.COM  * and limitations under the License.
12*7836SJohn.Forte@Sun.COM  *
13*7836SJohn.Forte@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*7836SJohn.Forte@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7836SJohn.Forte@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*7836SJohn.Forte@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*7836SJohn.Forte@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*7836SJohn.Forte@Sun.COM  *
19*7836SJohn.Forte@Sun.COM  * CDDL HEADER END
20*7836SJohn.Forte@Sun.COM  */
21*7836SJohn.Forte@Sun.COM 
22*7836SJohn.Forte@Sun.COM /*
23*7836SJohn.Forte@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24*7836SJohn.Forte@Sun.COM  * Use is subject to license terms.
25*7836SJohn.Forte@Sun.COM  */
26*7836SJohn.Forte@Sun.COM 
27*7836SJohn.Forte@Sun.COM #include <stdio.h>
28*7836SJohn.Forte@Sun.COM #include <stdlib.h>
29*7836SJohn.Forte@Sun.COM #include <string.h>
30*7836SJohn.Forte@Sun.COM 
31*7836SJohn.Forte@Sun.COM #include "isns_server.h"
32*7836SJohn.Forte@Sun.COM #include "isns_cache.h"
33*7836SJohn.Forte@Sun.COM #include "isns_msgq.h"
34*7836SJohn.Forte@Sun.COM #include "isns_obj.h"
35*7836SJohn.Forte@Sun.COM #include "isns_htab.h"
36*7836SJohn.Forte@Sun.COM 
37*7836SJohn.Forte@Sun.COM /*
38*7836SJohn.Forte@Sun.COM  * external variables
39*7836SJohn.Forte@Sun.COM  */
40*7836SJohn.Forte@Sun.COM extern msg_queue_t *sys_q;
41*7836SJohn.Forte@Sun.COM 
42*7836SJohn.Forte@Sun.COM #ifdef DEBUG
43*7836SJohn.Forte@Sun.COM extern int verbose_lock;
44*7836SJohn.Forte@Sun.COM #endif
45*7836SJohn.Forte@Sun.COM 
46*7836SJohn.Forte@Sun.COM /*
47*7836SJohn.Forte@Sun.COM  * global data
48*7836SJohn.Forte@Sun.COM  */
49*7836SJohn.Forte@Sun.COM int cache_flag = 0;
50*7836SJohn.Forte@Sun.COM 
51*7836SJohn.Forte@Sun.COM /*
52*7836SJohn.Forte@Sun.COM  * local variables
53*7836SJohn.Forte@Sun.COM  */
54*7836SJohn.Forte@Sun.COM static cache_t *imc;
55*7836SJohn.Forte@Sun.COM 
56*7836SJohn.Forte@Sun.COM /*
57*7836SJohn.Forte@Sun.COM  * local functions.
58*7836SJohn.Forte@Sun.COM  */
59*7836SJohn.Forte@Sun.COM 
60*7836SJohn.Forte@Sun.COM /*
61*7836SJohn.Forte@Sun.COM  * ****************************************************************************
62*7836SJohn.Forte@Sun.COM  * cache_init:
63*7836SJohn.Forte@Sun.COM  *	create the cache data initially, including to invoke individual
64*7836SJohn.Forte@Sun.COM  *	functions for creating the hash tables for object storage and
65*7836SJohn.Forte@Sun.COM  *	discovery domain membership matrix.
66*7836SJohn.Forte@Sun.COM  *
67*7836SJohn.Forte@Sun.COM  * return - 0: no error; 1: otherwise.
68*7836SJohn.Forte@Sun.COM  *
69*7836SJohn.Forte@Sun.COM  * ****************************************************************************
70*7836SJohn.Forte@Sun.COM  */
71*7836SJohn.Forte@Sun.COM int
cache_init()72*7836SJohn.Forte@Sun.COM cache_init(
73*7836SJohn.Forte@Sun.COM )
74*7836SJohn.Forte@Sun.COM {
75*7836SJohn.Forte@Sun.COM 	/*
76*7836SJohn.Forte@Sun.COM 	 * allocate global cache memory.
77*7836SJohn.Forte@Sun.COM 	 */
78*7836SJohn.Forte@Sun.COM 	imc = (cache_t *)calloc(sizeof (cache_t), 1);
79*7836SJohn.Forte@Sun.COM 	if (imc == NULL ||
80*7836SJohn.Forte@Sun.COM 	    obj_tab_init(imc) != 0 ||
81*7836SJohn.Forte@Sun.COM 	    dd_matrix_init(imc) != 0) {
82*7836SJohn.Forte@Sun.COM 		cache_destroy();
83*7836SJohn.Forte@Sun.COM 		return (1); /* no memory */
84*7836SJohn.Forte@Sun.COM 	}
85*7836SJohn.Forte@Sun.COM 
86*7836SJohn.Forte@Sun.COM 	/*
87*7836SJohn.Forte@Sun.COM 	 * initialize global cache rwlock.
88*7836SJohn.Forte@Sun.COM 	 */
89*7836SJohn.Forte@Sun.COM 	(void) rwlock_init(&imc->l, NULL, NULL);
90*7836SJohn.Forte@Sun.COM 
91*7836SJohn.Forte@Sun.COM 	/*
92*7836SJohn.Forte@Sun.COM 	 * inintialize global cache functions.
93*7836SJohn.Forte@Sun.COM 	 */
94*7836SJohn.Forte@Sun.COM 	imc->get_hval = obj_hval;
95*7836SJohn.Forte@Sun.COM 	imc->get_uid = get_obj_uid;
96*7836SJohn.Forte@Sun.COM 	imc->set_uid = set_obj_uid;
97*7836SJohn.Forte@Sun.COM 	imc->timestamp = get_timestamp;
98*7836SJohn.Forte@Sun.COM 	imc->add_hook = add_object;
99*7836SJohn.Forte@Sun.COM 	imc->replace_hook = replace_object;
100*7836SJohn.Forte@Sun.COM 	imc->cmp = obj_cmp;
101*7836SJohn.Forte@Sun.COM 	imc->clone = assoc_clone;
102*7836SJohn.Forte@Sun.COM 	imc->ddd = update_ddd;
103*7836SJohn.Forte@Sun.COM #ifdef DEBUG
104*7836SJohn.Forte@Sun.COM 	imc->dump = obj_dump;
105*7836SJohn.Forte@Sun.COM #endif
106*7836SJohn.Forte@Sun.COM 
107*7836SJohn.Forte@Sun.COM 	return (0);
108*7836SJohn.Forte@Sun.COM }
109*7836SJohn.Forte@Sun.COM 
110*7836SJohn.Forte@Sun.COM /*
111*7836SJohn.Forte@Sun.COM  * ****************************************************************************
112*7836SJohn.Forte@Sun.COM  * cache_destroy:
113*7836SJohn.Forte@Sun.COM  *	destroy the cache data.
114*7836SJohn.Forte@Sun.COM  *
115*7836SJohn.Forte@Sun.COM  * ****************************************************************************
116*7836SJohn.Forte@Sun.COM  */
117*7836SJohn.Forte@Sun.COM void
cache_destroy()118*7836SJohn.Forte@Sun.COM cache_destroy(
119*7836SJohn.Forte@Sun.COM )
120*7836SJohn.Forte@Sun.COM {
121*7836SJohn.Forte@Sun.COM 	/* do nothing */
122*7836SJohn.Forte@Sun.COM }
123*7836SJohn.Forte@Sun.COM 
124*7836SJohn.Forte@Sun.COM /*
125*7836SJohn.Forte@Sun.COM  * ****************************************************************************
126*7836SJohn.Forte@Sun.COM  * cache_lock:
127*7836SJohn.Forte@Sun.COM  *	grab the lock on the cache data.
128*7836SJohn.Forte@Sun.COM  *
129*7836SJohn.Forte@Sun.COM  * mode - the read/write mode of the lock.
130*7836SJohn.Forte@Sun.COM  * return - error code.
131*7836SJohn.Forte@Sun.COM  *
132*7836SJohn.Forte@Sun.COM  * ****************************************************************************
133*7836SJohn.Forte@Sun.COM  */
134*7836SJohn.Forte@Sun.COM int
cache_lock(int mode)135*7836SJohn.Forte@Sun.COM cache_lock(
136*7836SJohn.Forte@Sun.COM 	int mode
137*7836SJohn.Forte@Sun.COM )
138*7836SJohn.Forte@Sun.COM {
139*7836SJohn.Forte@Sun.COM 	int ret = 0;
140*7836SJohn.Forte@Sun.COM 
141*7836SJohn.Forte@Sun.COM 	switch (mode) {
142*7836SJohn.Forte@Sun.COM 	case CACHE_WRITE:
143*7836SJohn.Forte@Sun.COM 		ret = rw_wrlock(&imc->l);
144*7836SJohn.Forte@Sun.COM #ifdef DEBUG
145*7836SJohn.Forte@Sun.COM 		if (verbose_lock) {
146*7836SJohn.Forte@Sun.COM 			printf("cache locked for writing.\n");
147*7836SJohn.Forte@Sun.COM 		}
148*7836SJohn.Forte@Sun.COM #endif
149*7836SJohn.Forte@Sun.COM 		break;
150*7836SJohn.Forte@Sun.COM 	case CACHE_READ:
151*7836SJohn.Forte@Sun.COM 		ret = rw_rdlock(&imc->l);
152*7836SJohn.Forte@Sun.COM #ifdef DEBUG
153*7836SJohn.Forte@Sun.COM 		if (verbose_lock) {
154*7836SJohn.Forte@Sun.COM 			printf("cache locked for reading.\n");
155*7836SJohn.Forte@Sun.COM 		}
156*7836SJohn.Forte@Sun.COM #endif
157*7836SJohn.Forte@Sun.COM 		break;
158*7836SJohn.Forte@Sun.COM 	case CACHE_TRY_READ:
159*7836SJohn.Forte@Sun.COM 		ret = rw_tryrdlock(&imc->l);
160*7836SJohn.Forte@Sun.COM #ifdef DEBUG
161*7836SJohn.Forte@Sun.COM 		if (verbose_lock) {
162*7836SJohn.Forte@Sun.COM 			if (ret == 0) {
163*7836SJohn.Forte@Sun.COM 				printf("cache locked for reading.\n");
164*7836SJohn.Forte@Sun.COM 			} else {
165*7836SJohn.Forte@Sun.COM 				printf("cache locked for reading failed.\n");
166*7836SJohn.Forte@Sun.COM 			}
167*7836SJohn.Forte@Sun.COM 		}
168*7836SJohn.Forte@Sun.COM #endif
169*7836SJohn.Forte@Sun.COM 		break;
170*7836SJohn.Forte@Sun.COM 	default:
171*7836SJohn.Forte@Sun.COM 		break;
172*7836SJohn.Forte@Sun.COM 	}
173*7836SJohn.Forte@Sun.COM 
174*7836SJohn.Forte@Sun.COM 	return (ret);
175*7836SJohn.Forte@Sun.COM }
176*7836SJohn.Forte@Sun.COM 
177*7836SJohn.Forte@Sun.COM /*
178*7836SJohn.Forte@Sun.COM  * ****************************************************************************
179*7836SJohn.Forte@Sun.COM  * cache_unlock:
180*7836SJohn.Forte@Sun.COM  *	release the lock on the cache data.
181*7836SJohn.Forte@Sun.COM  *	if the cache was locked for writing, a synchronization between
182*7836SJohn.Forte@Sun.COM  *	the cache and persistent data store needs to be performed.
183*7836SJohn.Forte@Sun.COM  *
184*7836SJohn.Forte@Sun.COM  * mode - the read/write mode which the cache data was locked for.
185*7836SJohn.Forte@Sun.COM  * ec - 0: commit the cache update; otherwise retreat it.
186*7836SJohn.Forte@Sun.COM  * return - error code.
187*7836SJohn.Forte@Sun.COM  *
188*7836SJohn.Forte@Sun.COM  * ****************************************************************************
189*7836SJohn.Forte@Sun.COM  */
190*7836SJohn.Forte@Sun.COM int
cache_unlock(int mode,int ec)191*7836SJohn.Forte@Sun.COM cache_unlock(
192*7836SJohn.Forte@Sun.COM 	int mode,
193*7836SJohn.Forte@Sun.COM 	int ec
194*7836SJohn.Forte@Sun.COM )
195*7836SJohn.Forte@Sun.COM {
196*7836SJohn.Forte@Sun.COM 	if (mode != CACHE_NO_ACTION) {
197*7836SJohn.Forte@Sun.COM 		/* sync between cache and data store */
198*7836SJohn.Forte@Sun.COM 		if (mode == CACHE_WRITE) {
199*7836SJohn.Forte@Sun.COM 			if (sys_q) {
200*7836SJohn.Forte@Sun.COM 				ec = data_sync(ec);
201*7836SJohn.Forte@Sun.COM 			}
202*7836SJohn.Forte@Sun.COM 
203*7836SJohn.Forte@Sun.COM 			/* rest the cache update flag */
204*7836SJohn.Forte@Sun.COM 			RESET_CACHE_UPDATED();
205*7836SJohn.Forte@Sun.COM 		}
206*7836SJohn.Forte@Sun.COM 
207*7836SJohn.Forte@Sun.COM 		ASSERT(!IS_CACHE_UPDATED());
208*7836SJohn.Forte@Sun.COM 
209*7836SJohn.Forte@Sun.COM 		/* unlock it */
210*7836SJohn.Forte@Sun.COM 		(void) rw_unlock(&imc->l);
211*7836SJohn.Forte@Sun.COM #ifdef DEBUG
212*7836SJohn.Forte@Sun.COM 		if (verbose_lock) {
213*7836SJohn.Forte@Sun.COM 			printf("cache unlocked.\n");
214*7836SJohn.Forte@Sun.COM 		}
215*7836SJohn.Forte@Sun.COM #endif
216*7836SJohn.Forte@Sun.COM 	}
217*7836SJohn.Forte@Sun.COM 
218*7836SJohn.Forte@Sun.COM 	return (ec);
219*7836SJohn.Forte@Sun.COM }
220*7836SJohn.Forte@Sun.COM 
221*7836SJohn.Forte@Sun.COM /*
222*7836SJohn.Forte@Sun.COM  * ****************************************************************************
223*7836SJohn.Forte@Sun.COM  * cache_lock_read:
224*7836SJohn.Forte@Sun.COM  *	grab the read lock on the cache.
225*7836SJohn.Forte@Sun.COM  *
226*7836SJohn.Forte@Sun.COM  * return - error code.
227*7836SJohn.Forte@Sun.COM  *
228*7836SJohn.Forte@Sun.COM  * ****************************************************************************
229*7836SJohn.Forte@Sun.COM  */
230*7836SJohn.Forte@Sun.COM int
cache_lock_read()231*7836SJohn.Forte@Sun.COM cache_lock_read(
232*7836SJohn.Forte@Sun.COM )
233*7836SJohn.Forte@Sun.COM {
234*7836SJohn.Forte@Sun.COM 	return (cache_lock(CACHE_READ));
235*7836SJohn.Forte@Sun.COM }
236*7836SJohn.Forte@Sun.COM 
237*7836SJohn.Forte@Sun.COM /*
238*7836SJohn.Forte@Sun.COM  * ****************************************************************************
239*7836SJohn.Forte@Sun.COM  * cache_lock_write:
240*7836SJohn.Forte@Sun.COM  *	grab the write lock on the cache.
241*7836SJohn.Forte@Sun.COM  *
242*7836SJohn.Forte@Sun.COM  * return - error code.
243*7836SJohn.Forte@Sun.COM  *
244*7836SJohn.Forte@Sun.COM  * ****************************************************************************
245*7836SJohn.Forte@Sun.COM  */
246*7836SJohn.Forte@Sun.COM int
cache_lock_write()247*7836SJohn.Forte@Sun.COM cache_lock_write(
248*7836SJohn.Forte@Sun.COM )
249*7836SJohn.Forte@Sun.COM {
250*7836SJohn.Forte@Sun.COM 	return (cache_lock(CACHE_WRITE));
251*7836SJohn.Forte@Sun.COM }
252*7836SJohn.Forte@Sun.COM 
253*7836SJohn.Forte@Sun.COM /*
254*7836SJohn.Forte@Sun.COM  * ****************************************************************************
255*7836SJohn.Forte@Sun.COM  * cache_unlock_sync:
256*7836SJohn.Forte@Sun.COM  *	synchronize the cache with persistent data store and
257*7836SJohn.Forte@Sun.COM  *	release the lock.
258*7836SJohn.Forte@Sun.COM  *
259*7836SJohn.Forte@Sun.COM  * ec - 0: commit the cache update; otherwise retreat it.
260*7836SJohn.Forte@Sun.COM  * return - error code.
261*7836SJohn.Forte@Sun.COM  *
262*7836SJohn.Forte@Sun.COM  * ****************************************************************************
263*7836SJohn.Forte@Sun.COM  */
264*7836SJohn.Forte@Sun.COM int
cache_unlock_sync(int ec)265*7836SJohn.Forte@Sun.COM cache_unlock_sync(
266*7836SJohn.Forte@Sun.COM 	int ec
267*7836SJohn.Forte@Sun.COM )
268*7836SJohn.Forte@Sun.COM {
269*7836SJohn.Forte@Sun.COM 	return (cache_unlock(CACHE_WRITE, ec));
270*7836SJohn.Forte@Sun.COM }
271*7836SJohn.Forte@Sun.COM 
272*7836SJohn.Forte@Sun.COM /*
273*7836SJohn.Forte@Sun.COM  * ****************************************************************************
274*7836SJohn.Forte@Sun.COM  * cache_unlock_nosync:
275*7836SJohn.Forte@Sun.COM  *	release the lock, no need to sync the data between cache and
276*7836SJohn.Forte@Sun.COM  *	data store.
277*7836SJohn.Forte@Sun.COM  *	if the cache has been updated, do not call this function, call
278*7836SJohn.Forte@Sun.COM  *	cache_unlock_sync() with non-zero error code to indicate the
279*7836SJohn.Forte@Sun.COM  *	sync action.
280*7836SJohn.Forte@Sun.COM  *
281*7836SJohn.Forte@Sun.COM  * return - error code.
282*7836SJohn.Forte@Sun.COM  *
283*7836SJohn.Forte@Sun.COM  * ****************************************************************************
284*7836SJohn.Forte@Sun.COM  */
285*7836SJohn.Forte@Sun.COM int
cache_unlock_nosync()286*7836SJohn.Forte@Sun.COM cache_unlock_nosync(
287*7836SJohn.Forte@Sun.COM )
288*7836SJohn.Forte@Sun.COM {
289*7836SJohn.Forte@Sun.COM 	return (cache_unlock(CACHE_READ, 0));
290*7836SJohn.Forte@Sun.COM }
291*7836SJohn.Forte@Sun.COM 
292*7836SJohn.Forte@Sun.COM /*
293*7836SJohn.Forte@Sun.COM  * ****************************************************************************
294*7836SJohn.Forte@Sun.COM  * cache_get_htab:
295*7836SJohn.Forte@Sun.COM  *	get the hash table for individual type of object.
296*7836SJohn.Forte@Sun.COM  *
297*7836SJohn.Forte@Sun.COM  * type - the object type.
298*7836SJohn.Forte@Sun.COM  * return - the hash table.
299*7836SJohn.Forte@Sun.COM  *
300*7836SJohn.Forte@Sun.COM  * ****************************************************************************
301*7836SJohn.Forte@Sun.COM  */
302*7836SJohn.Forte@Sun.COM htab_t *
cache_get_htab(isns_type_t type)303*7836SJohn.Forte@Sun.COM cache_get_htab(
304*7836SJohn.Forte@Sun.COM 	isns_type_t type
305*7836SJohn.Forte@Sun.COM )
306*7836SJohn.Forte@Sun.COM {
307*7836SJohn.Forte@Sun.COM 	if (type > 0 && type < MAX_OBJ_TYPE) {
308*7836SJohn.Forte@Sun.COM 		return (imc->t[type]);
309*7836SJohn.Forte@Sun.COM 	}
310*7836SJohn.Forte@Sun.COM 
311*7836SJohn.Forte@Sun.COM 	return (NULL);
312*7836SJohn.Forte@Sun.COM }
313*7836SJohn.Forte@Sun.COM 
314*7836SJohn.Forte@Sun.COM /*
315*7836SJohn.Forte@Sun.COM  * ****************************************************************************
316*7836SJohn.Forte@Sun.COM  * cache_get_matrix:
317*7836SJohn.Forte@Sun.COM  *	get the membership matrix for a discovery domain or a
318*7836SJohn.Forte@Sun.COM  *	discovery domain set.
319*7836SJohn.Forte@Sun.COM  *
320*7836SJohn.Forte@Sun.COM  * type - the discovery domain or discovery domain set object type.
321*7836SJohn.Forte@Sun.COM  * return - the matrix.
322*7836SJohn.Forte@Sun.COM  *
323*7836SJohn.Forte@Sun.COM  * ****************************************************************************
324*7836SJohn.Forte@Sun.COM  */
325*7836SJohn.Forte@Sun.COM matrix_t *
cache_get_matrix(isns_type_t type)326*7836SJohn.Forte@Sun.COM cache_get_matrix(
327*7836SJohn.Forte@Sun.COM 	isns_type_t type
328*7836SJohn.Forte@Sun.COM )
329*7836SJohn.Forte@Sun.COM {
330*7836SJohn.Forte@Sun.COM 	matrix_t *x = NULL;
331*7836SJohn.Forte@Sun.COM 
332*7836SJohn.Forte@Sun.COM 	switch (type) {
333*7836SJohn.Forte@Sun.COM 	case OBJ_DD:
334*7836SJohn.Forte@Sun.COM 		x = imc->x[0];
335*7836SJohn.Forte@Sun.COM 		break;
336*7836SJohn.Forte@Sun.COM 	case OBJ_DDS:
337*7836SJohn.Forte@Sun.COM 		x = imc->x[1];
338*7836SJohn.Forte@Sun.COM 		break;
339*7836SJohn.Forte@Sun.COM 	default:
340*7836SJohn.Forte@Sun.COM 		break;
341*7836SJohn.Forte@Sun.COM 	}
342*7836SJohn.Forte@Sun.COM 
343*7836SJohn.Forte@Sun.COM 	return (x);
344*7836SJohn.Forte@Sun.COM }
345*7836SJohn.Forte@Sun.COM 
346*7836SJohn.Forte@Sun.COM /*
347*7836SJohn.Forte@Sun.COM  * ****************************************************************************
348*7836SJohn.Forte@Sun.COM  * cache_lookup:
349*7836SJohn.Forte@Sun.COM  *	invoke the hash table lookup for looking up a specific object and
350*7836SJohn.Forte@Sun.COM  *	perform the callback function on the object.
351*7836SJohn.Forte@Sun.COM  *
352*7836SJohn.Forte@Sun.COM  * lcp - the object lookup control data.
353*7836SJohn.Forte@Sun.COM  * uid_p - the pointer of object UID for returning.
354*7836SJohn.Forte@Sun.COM  * callback - the callback function for the object.
355*7836SJohn.Forte@Sun.COM  * return - error code.
356*7836SJohn.Forte@Sun.COM  *
357*7836SJohn.Forte@Sun.COM  * ****************************************************************************
358*7836SJohn.Forte@Sun.COM  */
359*7836SJohn.Forte@Sun.COM int
cache_lookup(lookup_ctrl_t * lcp,uint32_t * uid_p,int (* callback)(void *,void *))360*7836SJohn.Forte@Sun.COM cache_lookup(
361*7836SJohn.Forte@Sun.COM 	lookup_ctrl_t *lcp,
362*7836SJohn.Forte@Sun.COM 	uint32_t *uid_p,
363*7836SJohn.Forte@Sun.COM 	int (*callback)(void *, void *)
364*7836SJohn.Forte@Sun.COM )
365*7836SJohn.Forte@Sun.COM {
366*7836SJohn.Forte@Sun.COM 	return (htab_lookup(imc->t[lcp->type],
367*7836SJohn.Forte@Sun.COM 	    lcp,
368*7836SJohn.Forte@Sun.COM 	    (lcp->op[0] == OP_INTEGER) ? lcp->data[0].ui : 0,
369*7836SJohn.Forte@Sun.COM 	    uid_p,
370*7836SJohn.Forte@Sun.COM 	    callback,
371*7836SJohn.Forte@Sun.COM 	    0));
372*7836SJohn.Forte@Sun.COM }
373*7836SJohn.Forte@Sun.COM 
374*7836SJohn.Forte@Sun.COM /*
375*7836SJohn.Forte@Sun.COM  * ****************************************************************************
376*7836SJohn.Forte@Sun.COM  * cache_lookup:
377*7836SJohn.Forte@Sun.COM  *	invoke the hash table lookup for looking up a specific object,
378*7836SJohn.Forte@Sun.COM  *	the callback function is going to change the key of the object.
379*7836SJohn.Forte@Sun.COM  *
380*7836SJohn.Forte@Sun.COM  * lcp - the object lookup control data.
381*7836SJohn.Forte@Sun.COM  * uid_p - the pointer of object UID for returning.
382*7836SJohn.Forte@Sun.COM  * callback - the callback function for the object.
383*7836SJohn.Forte@Sun.COM  * return - error code.
384*7836SJohn.Forte@Sun.COM  *
385*7836SJohn.Forte@Sun.COM  * ****************************************************************************
386*7836SJohn.Forte@Sun.COM  */
387*7836SJohn.Forte@Sun.COM int
cache_rekey(lookup_ctrl_t * lcp,uint32_t * uid_p,int (* callback)(void *,void *))388*7836SJohn.Forte@Sun.COM cache_rekey(
389*7836SJohn.Forte@Sun.COM 	lookup_ctrl_t *lcp,
390*7836SJohn.Forte@Sun.COM 	uint32_t *uid_p,
391*7836SJohn.Forte@Sun.COM 	int (*callback)(void *, void *)
392*7836SJohn.Forte@Sun.COM )
393*7836SJohn.Forte@Sun.COM {
394*7836SJohn.Forte@Sun.COM 	return (htab_lookup(imc->t[lcp->type],
395*7836SJohn.Forte@Sun.COM 	    lcp,
396*7836SJohn.Forte@Sun.COM 	    (lcp->op[0] == OP_INTEGER) ? lcp->data[0].ui : 0,
397*7836SJohn.Forte@Sun.COM 	    uid_p,
398*7836SJohn.Forte@Sun.COM 	    callback,
399*7836SJohn.Forte@Sun.COM 	    1));
400*7836SJohn.Forte@Sun.COM }
401*7836SJohn.Forte@Sun.COM 
402*7836SJohn.Forte@Sun.COM /*
403*7836SJohn.Forte@Sun.COM  * ****************************************************************************
404*7836SJohn.Forte@Sun.COM  * cache_add:
405*7836SJohn.Forte@Sun.COM  *	invoke hash table add to add an object.
406*7836SJohn.Forte@Sun.COM  *
407*7836SJohn.Forte@Sun.COM  * obj - the object being added.
408*7836SJohn.Forte@Sun.COM  * flag - 0: a real object;
409*7836SJohn.Forte@Sun.COM  *	  otherwise an association object for discovery domain membership.
410*7836SJohn.Forte@Sun.COM  * uid_p - the pointer of object UID for returning.
411*7836SJohn.Forte@Sun.COM  * update_p - the pointer of flag (update object or newly register)
412*7836SJohn.Forte@Sun.COM  *		for returning.
413*7836SJohn.Forte@Sun.COM  * return - error code.
414*7836SJohn.Forte@Sun.COM  *
415*7836SJohn.Forte@Sun.COM  * ****************************************************************************
416*7836SJohn.Forte@Sun.COM  */
417*7836SJohn.Forte@Sun.COM int
cache_add(isns_obj_t * obj,int flag,uint32_t * uid_p,int * update_p)418*7836SJohn.Forte@Sun.COM cache_add(
419*7836SJohn.Forte@Sun.COM 	isns_obj_t *obj,
420*7836SJohn.Forte@Sun.COM 	int flag,
421*7836SJohn.Forte@Sun.COM 	uint32_t *uid_p,
422*7836SJohn.Forte@Sun.COM 	int *update_p
423*7836SJohn.Forte@Sun.COM )
424*7836SJohn.Forte@Sun.COM {
425*7836SJohn.Forte@Sun.COM 	return (htab_add(imc->t[obj->type], obj, flag, uid_p, update_p));
426*7836SJohn.Forte@Sun.COM }
427*7836SJohn.Forte@Sun.COM 
428*7836SJohn.Forte@Sun.COM /*
429*7836SJohn.Forte@Sun.COM  * ****************************************************************************
430*7836SJohn.Forte@Sun.COM  * cache_remove:
431*7836SJohn.Forte@Sun.COM  *	invoke hash table remove to remove an object.
432*7836SJohn.Forte@Sun.COM  *
433*7836SJohn.Forte@Sun.COM  * lcp - the lookup control data for the object being removed.
434*7836SJohn.Forte@Sun.COM  * flag - 0: a real object;
435*7836SJohn.Forte@Sun.COM  *	  otherwise an association object for discovery domain membership.
436*7836SJohn.Forte@Sun.COM  * return - the removed object.
437*7836SJohn.Forte@Sun.COM  *
438*7836SJohn.Forte@Sun.COM  * ****************************************************************************
439*7836SJohn.Forte@Sun.COM  */
440*7836SJohn.Forte@Sun.COM isns_obj_t *
cache_remove(lookup_ctrl_t * lcp,int flag)441*7836SJohn.Forte@Sun.COM cache_remove(
442*7836SJohn.Forte@Sun.COM 	lookup_ctrl_t *lcp,
443*7836SJohn.Forte@Sun.COM 	int flag
444*7836SJohn.Forte@Sun.COM )
445*7836SJohn.Forte@Sun.COM {
446*7836SJohn.Forte@Sun.COM 	return (htab_remove(imc->t[lcp->type],
447*7836SJohn.Forte@Sun.COM 	    lcp,
448*7836SJohn.Forte@Sun.COM 	    (lcp->op[0] == OP_INTEGER) ? lcp->data[0].ui : 0,
449*7836SJohn.Forte@Sun.COM 	    flag));
450*7836SJohn.Forte@Sun.COM }
451*7836SJohn.Forte@Sun.COM 
452*7836SJohn.Forte@Sun.COM /*
453*7836SJohn.Forte@Sun.COM  * ****************************************************************************
454*7836SJohn.Forte@Sun.COM  * cache_dump_htab:
455*7836SJohn.Forte@Sun.COM  *	dump the hash table for debugging purpose.
456*7836SJohn.Forte@Sun.COM  *
457*7836SJohn.Forte@Sun.COM  * type - the object type.
458*7836SJohn.Forte@Sun.COM  *
459*7836SJohn.Forte@Sun.COM  * ****************************************************************************
460*7836SJohn.Forte@Sun.COM  */
461*7836SJohn.Forte@Sun.COM #ifdef DEBUG
462*7836SJohn.Forte@Sun.COM void
cache_dump_htab(isns_type_t type)463*7836SJohn.Forte@Sun.COM cache_dump_htab(
464*7836SJohn.Forte@Sun.COM 	isns_type_t type
465*7836SJohn.Forte@Sun.COM )
466*7836SJohn.Forte@Sun.COM {
467*7836SJohn.Forte@Sun.COM 	(void) htab_dump(imc->t[type]);
468*7836SJohn.Forte@Sun.COM }
469*7836SJohn.Forte@Sun.COM #endif
470