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.
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.
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]
22 * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
26 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
35 * PURPOSE: DAT Provider and Consumer registry functions.
37 * $Id: udat.c,v 1.13 2003/08/20 14:28:40 hobie16 Exp $
41 #include <dat/dat_registry.h> /* Provider API function prototypes */
46 #ifndef DAT_NO_STATIC_REGISTRY
51 #define UDAT_IS_BAD_POINTER(p) (NULL == (p))
55 * Internal Function Declarations
60 udat_check_state(void);
65 * External Function Definitions
78 * Function: dat_registry_add_provider
82 dat_registry_add_provider(
83 IN DAT_PROVIDER
*provider
,
84 IN
const DAT_PROVIDER_INFO
*provider_info
)
88 dat_os_dbg_print(DAT_OS_DBG_TYPE_PROVIDER_API
,
89 "DAT Registry: dat_registry_add_provider() called\n");
91 if (UDAT_IS_BAD_POINTER(provider
)) {
92 return (DAT_ERROR(DAT_INVALID_PARAMETER
, DAT_INVALID_ARG1
));
95 if (UDAT_IS_BAD_POINTER(provider_info
)) {
96 return (DAT_ERROR(DAT_INVALID_PARAMETER
, DAT_INVALID_ARG2
));
99 if (DAT_FALSE
== udat_check_state()) {
100 return (DAT_ERROR(DAT_INVALID_STATE
, 0));
104 entry
.ia_open_func
= provider
->ia_open_func
;
105 entry
.info
= *provider_info
;
107 return (dat_dr_insert(provider_info
, &entry
));
112 * Function: dat_registry_remove_provider
116 dat_registry_remove_provider(
117 IN DAT_PROVIDER
*provider
,
118 IN
const DAT_PROVIDER_INFO
*provider_info
)
120 dat_os_dbg_print(DAT_OS_DBG_TYPE_PROVIDER_API
,
121 "DAT Registry: dat_registry_remove_provider() called\n");
123 if (UDAT_IS_BAD_POINTER(provider
)) {
124 return (DAT_ERROR(DAT_INVALID_PARAMETER
, DAT_INVALID_ARG1
));
127 if (DAT_FALSE
== udat_check_state()) {
128 return (DAT_ERROR(DAT_INVALID_STATE
, 0));
131 return (dat_dr_remove(provider_info
));
142 * Function: dat_ia_open
147 IN
const DAT_NAME_PTR name
,
148 IN DAT_COUNT async_event_qlen
,
149 INOUT DAT_EVD_HANDLE
*async_event_handle
,
150 OUT DAT_IA_HANDLE
*ia_handle
,
151 IN DAT_UINT32 dapl_major
,
152 IN DAT_UINT32 dapl_minor
,
153 IN DAT_BOOLEAN thread_safety
)
155 DAT_IA_OPEN_FUNC ia_open_func
;
156 DAT_PROVIDER_INFO info
;
159 #define RO_AWARE_PREFIX "RO_AWARE_"
160 boolean_t ro_aware_client
;
161 const char *_name
= name
;
163 dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API
,
164 "DAT Registry: dat_ia_open() called\n");
166 if (UDAT_IS_BAD_POINTER(_name
)) {
167 return (DAT_ERROR(DAT_INVALID_PARAMETER
, DAT_INVALID_ARG1
));
170 len
= dat_os_strlen(_name
);
172 if (DAT_NAME_MAX_LENGTH
<= len
) {
173 return (DAT_ERROR(DAT_INVALID_PARAMETER
, DAT_INVALID_ARG1
));
176 if (UDAT_IS_BAD_POINTER(ia_handle
)) {
177 return (DAT_ERROR(DAT_INVALID_HANDLE
, DAT_INVALID_HANDLE_IA
));
180 if (DAT_FALSE
== udat_check_state()) {
181 return (DAT_ERROR(DAT_INVALID_STATE
, 0));
184 /* Find out if this is an RO aware client and if so, strip the prefix */
186 (strncmp(RO_AWARE_PREFIX
, _name
, sizeof (RO_AWARE_PREFIX
) - 1) ==
189 /* strip off the prefix from the provider's name if present */
190 if (ro_aware_client
) {
191 _name
= _name
+ sizeof (RO_AWARE_PREFIX
) - 1;
192 len
-= sizeof (RO_AWARE_PREFIX
) - 1;
195 (void) dat_os_strncpy(info
.ia_name
, _name
, len
);
196 info
.ia_name
[len
] = '\0';
198 info
.dapl_version_major
= dapl_major
;
199 info
.dapl_version_minor
= dapl_minor
;
200 info
.is_thread_safe
= thread_safety
;
203 * Since DAT allows providers to be loaded by either the static
204 * registry or explicitly through OS dependent methods, do not
205 * return an error if no providers are loaded via the static registry.
206 * Don't even bother calling the static registry if DAT is compiled
207 * with no static registry support.
210 #ifndef DAT_NO_STATIC_REGISTRY
211 (void) dat_sr_provider_open(&info
);
214 status
= dat_dr_provider_open(&info
, &ia_open_func
);
215 if (status
!= DAT_SUCCESS
) {
216 dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API
,
217 "DAT Registry: dat_ia_open() provider information "
218 "for IA name %s not found in dynamic registry\n",
223 return (*ia_open_func
)((const DAT_NAME_PTR
) _name
,
232 * Function: dat_ia_close
237 IN DAT_IA_HANDLE ia_handle
,
238 IN DAT_CLOSE_FLAGS ia_flags
)
240 DAT_PROVIDER
*provider
;
241 DAT_PROVIDER_ATTR provider_attr
= {0};
245 dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API
,
246 "DAT Registry: dat_ia_close() called\n");
248 if (UDAT_IS_BAD_POINTER(ia_handle
)) {
249 return (DAT_ERROR(DAT_INVALID_HANDLE
, DAT_INVALID_HANDLE_IA
));
252 if (DAT_FALSE
== udat_check_state()) {
253 return (DAT_ERROR(DAT_INVALID_STATE
, 0));
256 provider
= DAT_HANDLE_TO_PROVIDER(ia_handle
);
257 ia_name
= provider
->device_name
;
259 if (DAT_SUCCESS
!= (status
= dat_ia_query(ia_handle
,
263 DAT_PROVIDER_FIELD_ALL
,
265 dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API
,
266 "DAT Registry: query function for %s provider failed\n",
268 } else if (DAT_SUCCESS
!= (status
=
269 (*provider
->ia_close_func
)(ia_handle
, ia_flags
))) {
270 dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API
,
271 "DAT Registry: close function for %s provider failed\n",
274 DAT_PROVIDER_INFO info
;
277 len
= dat_os_strlen(ia_name
);
279 dat_os_assert(len
<= DAT_NAME_MAX_LENGTH
);
281 (void) dat_os_strncpy(info
.ia_name
, ia_name
, len
);
282 info
.ia_name
[len
] = '\0';
284 info
.dapl_version_major
= provider_attr
.dapl_version_major
;
285 info
.dapl_version_minor
= provider_attr
.dapl_version_minor
;
286 info
.is_thread_safe
= provider_attr
.is_thread_safe
;
288 status
= dat_dr_provider_close(&info
);
289 if (DAT_SUCCESS
!= status
) {
290 dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API
,
291 "DAT Registry: dynamic registry unable to close "
292 "provider for IA name %s\n",
296 #ifndef DAT_NO_STATIC_REGISTRY
297 status
= dat_sr_provider_close(&info
);
298 if (DAT_SUCCESS
!= status
) {
299 dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API
,
300 "DAT Registry: static registry unable to close "
301 "provider for IA name %s\n",
312 * Function: dat_registry_list_providers
316 dat_registry_list_providers(
317 IN DAT_COUNT max_to_return
,
318 OUT DAT_COUNT
*entries_returned
,
319 OUT DAT_PROVIDER_INFO
*(dat_provider_list
[]))
321 DAT_RETURN dat_status
;
323 dat_status
= DAT_SUCCESS
;
324 dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API
,
325 "DAT Registry: dat_registry_list_providers() called\n");
327 if (DAT_FALSE
== udat_check_state()) {
328 return (DAT_ERROR(DAT_INVALID_STATE
, 0));
331 if ((UDAT_IS_BAD_POINTER(entries_returned
))) {
332 return (DAT_ERROR(DAT_INVALID_PARAMETER
, DAT_INVALID_ARG2
));
335 if (0 != max_to_return
&& (UDAT_IS_BAD_POINTER(dat_provider_list
))) {
336 return (DAT_ERROR(DAT_INVALID_PARAMETER
, DAT_INVALID_ARG3
));
339 if (0 == max_to_return
) {
341 * the user is allowed to call with max_to_return set to zero.
342 * in which case we simply return (in *entries_returned) the
343 * number of providers currently installed. We must also
344 * (per spec) return an error
346 #ifndef DAT_NO_STATIC_REGISTRY
347 (void) dat_sr_size(entries_returned
);
349 (void) dat_dr_size(entries_returned
);
351 return (DAT_ERROR(DAT_INVALID_PARAMETER
, DAT_INVALID_ARG1
));
353 #ifndef DAT_NO_STATIC_REGISTRY
354 dat_status
= dat_sr_list(max_to_return
,
358 dat_status
= dat_dr_list(max_to_return
,
369 * Internal Function Definitions
375 * Function: udat_check_state
379 * This function returns TRUE if the DAT registry is in a state capable
380 * of handling DAT API calls and false otherwise.
384 udat_check_state(void)
386 DAT_MODULE_STATE state
;
389 state
= dat_module_get_state();
391 if (DAT_MODULE_STATE_UNINITIALIZED
== state
) {
394 } else if (DAT_MODULE_STATE_DEINITIALIZED
== state
) {