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