xref: /illumos-gate/usr/src/lib/udapl/libdat/common/dat_sr.c (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate  */
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate /*
32*7c478bd9Sstevel@tonic-gate  *
33*7c478bd9Sstevel@tonic-gate  * MODULE: dat_sr.c
34*7c478bd9Sstevel@tonic-gate  *
35*7c478bd9Sstevel@tonic-gate  * PURPOSE: static registry implementation
36*7c478bd9Sstevel@tonic-gate  *
37*7c478bd9Sstevel@tonic-gate  * $Id: dat_sr.c,v 1.12 2003/08/20 14:28:40 hobie16 Exp $
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate 
41*7c478bd9Sstevel@tonic-gate #include "dat_sr.h"
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #include "dat_dictionary.h"
44*7c478bd9Sstevel@tonic-gate #include "udat_sr_parser.h"
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate /*
48*7c478bd9Sstevel@tonic-gate  *
49*7c478bd9Sstevel@tonic-gate  * Global Variables
50*7c478bd9Sstevel@tonic-gate  *
51*7c478bd9Sstevel@tonic-gate  */
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate static DAT_OS_LOCK 		g_sr_lock;
54*7c478bd9Sstevel@tonic-gate static DAT_DICTIONARY 		*g_sr_dictionary = NULL;
55*7c478bd9Sstevel@tonic-gate 
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate /*
58*7c478bd9Sstevel@tonic-gate  *
59*7c478bd9Sstevel@tonic-gate  * External Functions
60*7c478bd9Sstevel@tonic-gate  *
61*7c478bd9Sstevel@tonic-gate  */
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate /*
65*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_init
66*7c478bd9Sstevel@tonic-gate  */
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate DAT_RETURN
dat_sr_init(void)69*7c478bd9Sstevel@tonic-gate dat_sr_init(void)
70*7c478bd9Sstevel@tonic-gate {
71*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 			status;
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate 	status = dat_os_lock_init(&g_sr_lock);
74*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
75*7c478bd9Sstevel@tonic-gate 		return (status);
76*7c478bd9Sstevel@tonic-gate 	}
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate 	status = dat_dictionary_create(&g_sr_dictionary);
79*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
80*7c478bd9Sstevel@tonic-gate 		return (status);
81*7c478bd9Sstevel@tonic-gate 	}
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 	/*
84*7c478bd9Sstevel@tonic-gate 	 * Since DAT allows providers to be loaded by either the static
85*7c478bd9Sstevel@tonic-gate 	 * registry or explicitly through OS dependent methods, do not
86*7c478bd9Sstevel@tonic-gate 	 * return an error if no providers are loaded via the static registry.
87*7c478bd9Sstevel@tonic-gate 	 */
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 	(void) dat_sr_load();
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate 	return (DAT_SUCCESS);
92*7c478bd9Sstevel@tonic-gate }
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate /*
96*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_fini
97*7c478bd9Sstevel@tonic-gate  */
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate extern DAT_RETURN
dat_sr_fini(void)100*7c478bd9Sstevel@tonic-gate dat_sr_fini(void)
101*7c478bd9Sstevel@tonic-gate {
102*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 			status;
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate 	status = dat_os_lock_destroy(&g_sr_lock);
105*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
106*7c478bd9Sstevel@tonic-gate 		return (status);
107*7c478bd9Sstevel@tonic-gate 	}
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate 	status = dat_dictionary_destroy(g_sr_dictionary);
110*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
111*7c478bd9Sstevel@tonic-gate 		return (status);
112*7c478bd9Sstevel@tonic-gate 	}
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 	return (DAT_SUCCESS);
115*7c478bd9Sstevel@tonic-gate }
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate /*
119*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_insert
120*7c478bd9Sstevel@tonic-gate  */
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate extern DAT_RETURN
dat_sr_insert(IN const DAT_PROVIDER_INFO * info,IN DAT_SR_ENTRY * entry)123*7c478bd9Sstevel@tonic-gate dat_sr_insert(
124*7c478bd9Sstevel@tonic-gate     IN  const DAT_PROVIDER_INFO *info,
125*7c478bd9Sstevel@tonic-gate     IN  DAT_SR_ENTRY 		*entry)
126*7c478bd9Sstevel@tonic-gate {
127*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 		status;
128*7c478bd9Sstevel@tonic-gate 	DAT_SR_ENTRY 		*data;
129*7c478bd9Sstevel@tonic-gate 	DAT_OS_SIZE 		lib_path_size;
130*7c478bd9Sstevel@tonic-gate 	DAT_OS_SIZE 		lib_path_len;
131*7c478bd9Sstevel@tonic-gate 	DAT_OS_SIZE 		ia_params_size;
132*7c478bd9Sstevel@tonic-gate 	DAT_OS_SIZE 		ia_params_len;
133*7c478bd9Sstevel@tonic-gate 	DAT_DICTIONARY_ENTRY 	dict_entry;
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate 	if (NULL == (data = dat_os_alloc(sizeof (DAT_SR_ENTRY)))) {
136*7c478bd9Sstevel@tonic-gate 		status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
137*7c478bd9Sstevel@tonic-gate 		    DAT_RESOURCE_MEMORY);
138*7c478bd9Sstevel@tonic-gate 		goto bail;
139*7c478bd9Sstevel@tonic-gate 	}
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 	lib_path_len = strlen(entry->lib_path);
142*7c478bd9Sstevel@tonic-gate 	lib_path_size = (lib_path_len + 1) * sizeof (char);
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate 	if (NULL == (data->lib_path = dat_os_alloc(lib_path_size))) {
145*7c478bd9Sstevel@tonic-gate 		status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
146*7c478bd9Sstevel@tonic-gate 		    DAT_RESOURCE_MEMORY);
147*7c478bd9Sstevel@tonic-gate 		goto bail;
148*7c478bd9Sstevel@tonic-gate 	}
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate 	(void) dat_os_strncpy(data->lib_path, entry->lib_path, lib_path_len);
151*7c478bd9Sstevel@tonic-gate 	data->lib_path[lib_path_len] = '\0';
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate 	ia_params_len = strlen(entry->ia_params);
154*7c478bd9Sstevel@tonic-gate 	ia_params_size = (ia_params_len + 1) * sizeof (char);
155*7c478bd9Sstevel@tonic-gate 
156*7c478bd9Sstevel@tonic-gate 	if (NULL == (data->ia_params = dat_os_alloc(ia_params_size))) {
157*7c478bd9Sstevel@tonic-gate 		status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
158*7c478bd9Sstevel@tonic-gate 		    DAT_RESOURCE_MEMORY);
159*7c478bd9Sstevel@tonic-gate 		goto bail;
160*7c478bd9Sstevel@tonic-gate 	}
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate 	(void) dat_os_strncpy(data->ia_params, entry->ia_params, ia_params_len);
163*7c478bd9Sstevel@tonic-gate 	data->ia_params[ia_params_len] = '\0';
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate 	data->info = entry->info;
166*7c478bd9Sstevel@tonic-gate 	data->lib_handle = entry->lib_handle;
167*7c478bd9Sstevel@tonic-gate 	data->ref_count = entry->ref_count;
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate 	dict_entry = NULL;
170*7c478bd9Sstevel@tonic-gate 	status = dat_dictionary_entry_create(&dict_entry);
171*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
172*7c478bd9Sstevel@tonic-gate 		goto bail;
173*7c478bd9Sstevel@tonic-gate 	}
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate 	dat_os_lock(&g_sr_lock);
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate 	status = dat_dictionary_insert(g_sr_dictionary,
178*7c478bd9Sstevel@tonic-gate 				dict_entry,
179*7c478bd9Sstevel@tonic-gate 				info,
180*7c478bd9Sstevel@tonic-gate 				(DAT_DICTIONARY_DATA *)data);
181*7c478bd9Sstevel@tonic-gate 	dat_os_unlock(&g_sr_lock);
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate bail:
184*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != status) {
185*7c478bd9Sstevel@tonic-gate 		if (NULL != data) {
186*7c478bd9Sstevel@tonic-gate 			if (NULL != data->lib_path) {
187*7c478bd9Sstevel@tonic-gate 				dat_os_free(data->lib_path, lib_path_size);
188*7c478bd9Sstevel@tonic-gate 			}
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate 			if (NULL != data->ia_params) {
191*7c478bd9Sstevel@tonic-gate 				dat_os_free(data->ia_params, ia_params_size);
192*7c478bd9Sstevel@tonic-gate 			}
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate 			dat_os_free(data, sizeof (DAT_SR_ENTRY));
195*7c478bd9Sstevel@tonic-gate 		}
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate 		if (NULL != dict_entry) {
198*7c478bd9Sstevel@tonic-gate 			(void) dat_dictionary_entry_destroy(dict_entry);
199*7c478bd9Sstevel@tonic-gate 		}
200*7c478bd9Sstevel@tonic-gate 	}
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate 	return (status);
203*7c478bd9Sstevel@tonic-gate }
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate /*
207*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_size
208*7c478bd9Sstevel@tonic-gate  */
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate extern DAT_RETURN
dat_sr_size(OUT DAT_COUNT * size)211*7c478bd9Sstevel@tonic-gate dat_sr_size(
212*7c478bd9Sstevel@tonic-gate     OUT DAT_COUNT		*size)
213*7c478bd9Sstevel@tonic-gate {
214*7c478bd9Sstevel@tonic-gate 	return (dat_dictionary_size(g_sr_dictionary, size));
215*7c478bd9Sstevel@tonic-gate }
216*7c478bd9Sstevel@tonic-gate 
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate /*
219*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_list
220*7c478bd9Sstevel@tonic-gate  */
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate extern DAT_RETURN
dat_sr_list(IN DAT_COUNT max_to_return,OUT DAT_COUNT * entries_returned,OUT DAT_PROVIDER_INFO * (dat_provider_list[]))223*7c478bd9Sstevel@tonic-gate dat_sr_list(
224*7c478bd9Sstevel@tonic-gate     IN  DAT_COUNT		max_to_return,
225*7c478bd9Sstevel@tonic-gate     OUT DAT_COUNT		*entries_returned,
226*7c478bd9Sstevel@tonic-gate     OUT DAT_PROVIDER_INFO	* (dat_provider_list[]))
227*7c478bd9Sstevel@tonic-gate {
228*7c478bd9Sstevel@tonic-gate 	DAT_SR_ENTRY		**array;
229*7c478bd9Sstevel@tonic-gate 	DAT_COUNT 		array_size;
230*7c478bd9Sstevel@tonic-gate 	DAT_COUNT 		i;
231*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 		status;
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate 	array = NULL;
234*7c478bd9Sstevel@tonic-gate 	status = DAT_SUCCESS;
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate 	/*
237*7c478bd9Sstevel@tonic-gate 	 * The dictionary size may increase between the call to
238*7c478bd9Sstevel@tonic-gate 	 * dat_dictionary_size() and dat_dictionary_enumerate().
239*7c478bd9Sstevel@tonic-gate 	 * Therefore we loop until a successful enumeration is made.
240*7c478bd9Sstevel@tonic-gate 	 */
241*7c478bd9Sstevel@tonic-gate 	*entries_returned = 0;
242*7c478bd9Sstevel@tonic-gate 	for (;;) {
243*7c478bd9Sstevel@tonic-gate 		status = dat_dictionary_size(g_sr_dictionary, &array_size);
244*7c478bd9Sstevel@tonic-gate 		if (DAT_SUCCESS != status) {
245*7c478bd9Sstevel@tonic-gate 			goto bail;
246*7c478bd9Sstevel@tonic-gate 		}
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate 		if (array_size == 0) {
249*7c478bd9Sstevel@tonic-gate 			status = DAT_SUCCESS;
250*7c478bd9Sstevel@tonic-gate 			goto bail;
251*7c478bd9Sstevel@tonic-gate 		}
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate 		array = dat_os_alloc(array_size * sizeof (DAT_SR_ENTRY *));
254*7c478bd9Sstevel@tonic-gate 		if (array == NULL) {
255*7c478bd9Sstevel@tonic-gate 			status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
256*7c478bd9Sstevel@tonic-gate 			    DAT_RESOURCE_MEMORY);
257*7c478bd9Sstevel@tonic-gate 			goto bail;
258*7c478bd9Sstevel@tonic-gate 		}
259*7c478bd9Sstevel@tonic-gate 
260*7c478bd9Sstevel@tonic-gate 		dat_os_lock(&g_sr_lock);
261*7c478bd9Sstevel@tonic-gate 
262*7c478bd9Sstevel@tonic-gate 		status = dat_dictionary_enumerate(g_sr_dictionary,
263*7c478bd9Sstevel@tonic-gate 				(DAT_DICTIONARY_DATA *) array,
264*7c478bd9Sstevel@tonic-gate 				array_size);
265*7c478bd9Sstevel@tonic-gate 
266*7c478bd9Sstevel@tonic-gate 		dat_os_unlock(&g_sr_lock);
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate 		if (DAT_SUCCESS == status) {
269*7c478bd9Sstevel@tonic-gate 			break;
270*7c478bd9Sstevel@tonic-gate 		} else {
271*7c478bd9Sstevel@tonic-gate 			dat_os_free(array,
272*7c478bd9Sstevel@tonic-gate 			    array_size * sizeof (DAT_SR_ENTRY *));
273*7c478bd9Sstevel@tonic-gate 			array = NULL;
274*7c478bd9Sstevel@tonic-gate 			continue;
275*7c478bd9Sstevel@tonic-gate 		}
276*7c478bd9Sstevel@tonic-gate 	}
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate 	for (i = 0; (i < max_to_return) && (i < array_size); i++) {
279*7c478bd9Sstevel@tonic-gate 		if (NULL == dat_provider_list[i]) {
280*7c478bd9Sstevel@tonic-gate 			status = DAT_ERROR(DAT_INVALID_PARAMETER,
281*7c478bd9Sstevel@tonic-gate 			    DAT_INVALID_ARG3);
282*7c478bd9Sstevel@tonic-gate 			goto bail;
283*7c478bd9Sstevel@tonic-gate 		}
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate 		*dat_provider_list[i] = array[i]->info;
286*7c478bd9Sstevel@tonic-gate 	}
287*7c478bd9Sstevel@tonic-gate 
288*7c478bd9Sstevel@tonic-gate 	*entries_returned = i;
289*7c478bd9Sstevel@tonic-gate 
290*7c478bd9Sstevel@tonic-gate bail:
291*7c478bd9Sstevel@tonic-gate 	if (NULL != array) {
292*7c478bd9Sstevel@tonic-gate 		dat_os_free(array, array_size * sizeof (DAT_SR_ENTRY *));
293*7c478bd9Sstevel@tonic-gate 	}
294*7c478bd9Sstevel@tonic-gate 
295*7c478bd9Sstevel@tonic-gate 	return (status);
296*7c478bd9Sstevel@tonic-gate }
297*7c478bd9Sstevel@tonic-gate 
298*7c478bd9Sstevel@tonic-gate 
299*7c478bd9Sstevel@tonic-gate 
300*7c478bd9Sstevel@tonic-gate /*
301*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_provider_open
302*7c478bd9Sstevel@tonic-gate  */
303*7c478bd9Sstevel@tonic-gate 
304*7c478bd9Sstevel@tonic-gate extern DAT_RETURN
dat_sr_provider_open(IN const DAT_PROVIDER_INFO * info)305*7c478bd9Sstevel@tonic-gate dat_sr_provider_open(
306*7c478bd9Sstevel@tonic-gate     IN  const DAT_PROVIDER_INFO *info)
307*7c478bd9Sstevel@tonic-gate {
308*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 		status;
309*7c478bd9Sstevel@tonic-gate 	DAT_SR_ENTRY 		*data;
310*7c478bd9Sstevel@tonic-gate 
311*7c478bd9Sstevel@tonic-gate 	dat_os_lock(&g_sr_lock);
312*7c478bd9Sstevel@tonic-gate 
313*7c478bd9Sstevel@tonic-gate 	status = dat_dictionary_search(g_sr_dictionary,
314*7c478bd9Sstevel@tonic-gate 			info,
315*7c478bd9Sstevel@tonic-gate 			(DAT_DICTIONARY_DATA *) &data);
316*7c478bd9Sstevel@tonic-gate 
317*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS == status) {
318*7c478bd9Sstevel@tonic-gate 		if (0 == data->ref_count) {
319*7c478bd9Sstevel@tonic-gate 			status = dat_os_library_load(data->lib_path,
320*7c478bd9Sstevel@tonic-gate 			    &data->lib_handle);
321*7c478bd9Sstevel@tonic-gate 			if (status == DAT_SUCCESS) {
322*7c478bd9Sstevel@tonic-gate 				data->ref_count++;
323*7c478bd9Sstevel@tonic-gate 			} else {
324*7c478bd9Sstevel@tonic-gate 				dat_os_dbg_print(DAT_OS_DBG_TYPE_SR,
325*7c478bd9Sstevel@tonic-gate 				    "DAT Registry: static registry unable to "
326*7c478bd9Sstevel@tonic-gate 				    "load library %s\n", data->lib_path);
327*7c478bd9Sstevel@tonic-gate 				goto bail;
328*7c478bd9Sstevel@tonic-gate 			}
329*7c478bd9Sstevel@tonic-gate 			data->init_func = (DAT_PROVIDER_INIT_FUNC)
330*7c478bd9Sstevel@tonic-gate 			    dat_os_library_sym(data->lib_handle,
331*7c478bd9Sstevel@tonic-gate 				DAT_PROVIDER_INIT_FUNC_STR);
332*7c478bd9Sstevel@tonic-gate 			data->fini_func = (DAT_PROVIDER_FINI_FUNC)
333*7c478bd9Sstevel@tonic-gate 			    dat_os_library_sym(data->lib_handle,
334*7c478bd9Sstevel@tonic-gate 				DAT_PROVIDER_FINI_FUNC_STR);
335*7c478bd9Sstevel@tonic-gate 
336*7c478bd9Sstevel@tonic-gate 			if (NULL != data->init_func) {
337*7c478bd9Sstevel@tonic-gate 				(*data->init_func)(&data->info,
338*7c478bd9Sstevel@tonic-gate 				    data->ia_params);
339*7c478bd9Sstevel@tonic-gate 			}
340*7c478bd9Sstevel@tonic-gate 		} else {
341*7c478bd9Sstevel@tonic-gate 			data->ref_count++;
342*7c478bd9Sstevel@tonic-gate 		}
343*7c478bd9Sstevel@tonic-gate 	}
344*7c478bd9Sstevel@tonic-gate 
345*7c478bd9Sstevel@tonic-gate bail:
346*7c478bd9Sstevel@tonic-gate 	dat_os_unlock(&g_sr_lock);
347*7c478bd9Sstevel@tonic-gate 
348*7c478bd9Sstevel@tonic-gate 	return (status);
349*7c478bd9Sstevel@tonic-gate }
350*7c478bd9Sstevel@tonic-gate 
351*7c478bd9Sstevel@tonic-gate 
352*7c478bd9Sstevel@tonic-gate /*
353*7c478bd9Sstevel@tonic-gate  * Function: dat_sr_provider_close
354*7c478bd9Sstevel@tonic-gate  */
355*7c478bd9Sstevel@tonic-gate 
356*7c478bd9Sstevel@tonic-gate extern DAT_RETURN
dat_sr_provider_close(IN const DAT_PROVIDER_INFO * info)357*7c478bd9Sstevel@tonic-gate dat_sr_provider_close(
358*7c478bd9Sstevel@tonic-gate     IN  const DAT_PROVIDER_INFO *info)
359*7c478bd9Sstevel@tonic-gate {
360*7c478bd9Sstevel@tonic-gate 	DAT_RETURN 		status;
361*7c478bd9Sstevel@tonic-gate 	DAT_SR_ENTRY 		*data;
362*7c478bd9Sstevel@tonic-gate 
363*7c478bd9Sstevel@tonic-gate 	dat_os_lock(&g_sr_lock);
364*7c478bd9Sstevel@tonic-gate 
365*7c478bd9Sstevel@tonic-gate 	status = dat_dictionary_search(g_sr_dictionary,
366*7c478bd9Sstevel@tonic-gate 			info,
367*7c478bd9Sstevel@tonic-gate 			(DAT_DICTIONARY_DATA *)&data);
368*7c478bd9Sstevel@tonic-gate 
369*7c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS == status) {
370*7c478bd9Sstevel@tonic-gate 		if (1 == data->ref_count) {
371*7c478bd9Sstevel@tonic-gate 			if (NULL != data->fini_func) {
372*7c478bd9Sstevel@tonic-gate 				(*data->fini_func)(&data->info);
373*7c478bd9Sstevel@tonic-gate 			}
374*7c478bd9Sstevel@tonic-gate 
375*7c478bd9Sstevel@tonic-gate 			status = dat_os_library_unload(data->lib_handle);
376*7c478bd9Sstevel@tonic-gate 			if (status == DAT_SUCCESS) {
377*7c478bd9Sstevel@tonic-gate 				data->ref_count--;
378*7c478bd9Sstevel@tonic-gate 			}
379*7c478bd9Sstevel@tonic-gate 		} else {
380*7c478bd9Sstevel@tonic-gate 			data->ref_count--;
381*7c478bd9Sstevel@tonic-gate 		}
382*7c478bd9Sstevel@tonic-gate 	}
383*7c478bd9Sstevel@tonic-gate 
384*7c478bd9Sstevel@tonic-gate 	dat_os_unlock(&g_sr_lock);
385*7c478bd9Sstevel@tonic-gate 
386*7c478bd9Sstevel@tonic-gate 	return (status);
387*7c478bd9Sstevel@tonic-gate }
388