xref: /titanic_50/usr/src/lib/udapl/libdat/common/udat.c (revision 03494a9880d80f834bec10a1e8f0a2f8f7c97bf4)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*03494a98SBill Taylor  * Common Development and Distribution License (the "License").
6*03494a98SBill Taylor  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
227c478bd9Sstevel@tonic-gate  * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
26*03494a98SBill Taylor  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  *
337c478bd9Sstevel@tonic-gate  * MODULE: udat.c
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * PURPOSE: DAT Provider and Consumer registry functions.
367c478bd9Sstevel@tonic-gate  *
377c478bd9Sstevel@tonic-gate  * $Id: udat.c,v 1.13 2003/08/20 14:28:40 hobie16 Exp $
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #include <dat/udat.h>
417c478bd9Sstevel@tonic-gate #include <dat/dat_registry.h> /* Provider API function prototypes */
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #include "dat_dr.h"
447c478bd9Sstevel@tonic-gate #include "dat_init.h"
457c478bd9Sstevel@tonic-gate #include "dat_osd.h"
467c478bd9Sstevel@tonic-gate #ifndef	DAT_NO_STATIC_REGISTRY
477c478bd9Sstevel@tonic-gate #include "dat_sr.h"
487c478bd9Sstevel@tonic-gate #endif
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #define	UDAT_IS_BAD_POINTER(p) (NULL == (p))
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  *
557c478bd9Sstevel@tonic-gate  * Internal Function Declarations
567c478bd9Sstevel@tonic-gate  *
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate DAT_BOOLEAN
607c478bd9Sstevel@tonic-gate udat_check_state(void);
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  *
657c478bd9Sstevel@tonic-gate  * External Function Definitions
667c478bd9Sstevel@tonic-gate  *
677c478bd9Sstevel@tonic-gate  */
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  *
727c478bd9Sstevel@tonic-gate  * Provider API
737c478bd9Sstevel@tonic-gate  *
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * Function: dat_registry_add_provider
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate DAT_RETURN
dat_registry_add_provider(IN DAT_PROVIDER * provider,IN const DAT_PROVIDER_INFO * provider_info)827c478bd9Sstevel@tonic-gate dat_registry_add_provider(
837c478bd9Sstevel@tonic-gate 	IN DAT_PROVIDER			*provider,
847c478bd9Sstevel@tonic-gate 	IN const DAT_PROVIDER_INFO	*provider_info)
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate 	DAT_DR_ENTRY 		entry;
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	dat_os_dbg_print(DAT_OS_DBG_TYPE_PROVIDER_API,
897c478bd9Sstevel@tonic-gate 	    "DAT Registry: dat_registry_add_provider() called\n");
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 	if (UDAT_IS_BAD_POINTER(provider)) {
927c478bd9Sstevel@tonic-gate 		return (DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG1));
937c478bd9Sstevel@tonic-gate 	}
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	if (UDAT_IS_BAD_POINTER(provider_info)) {
967c478bd9Sstevel@tonic-gate 		return (DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG2));
977c478bd9Sstevel@tonic-gate 	}
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	if (DAT_FALSE == udat_check_state()) {
1007c478bd9Sstevel@tonic-gate 		return (DAT_ERROR(DAT_INVALID_STATE, 0));
1017c478bd9Sstevel@tonic-gate 	}
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	entry.ref_count = 0;
1047c478bd9Sstevel@tonic-gate 	entry.ia_open_func = provider->ia_open_func;
1057c478bd9Sstevel@tonic-gate 	entry.info = *provider_info;
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	return (dat_dr_insert(provider_info, &entry));
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate /*
1127c478bd9Sstevel@tonic-gate  * Function: dat_registry_remove_provider
1137c478bd9Sstevel@tonic-gate  */
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate DAT_RETURN
dat_registry_remove_provider(IN DAT_PROVIDER * provider,IN const DAT_PROVIDER_INFO * provider_info)1167c478bd9Sstevel@tonic-gate dat_registry_remove_provider(
1177c478bd9Sstevel@tonic-gate 	IN DAT_PROVIDER 		*provider,
1187c478bd9Sstevel@tonic-gate 	IN  const DAT_PROVIDER_INFO	*provider_info)
1197c478bd9Sstevel@tonic-gate {
1207c478bd9Sstevel@tonic-gate 	dat_os_dbg_print(DAT_OS_DBG_TYPE_PROVIDER_API,
1217c478bd9Sstevel@tonic-gate 	    "DAT Registry: dat_registry_remove_provider() called\n");
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	if (UDAT_IS_BAD_POINTER(provider)) {
1247c478bd9Sstevel@tonic-gate 		return (DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG1));
1257c478bd9Sstevel@tonic-gate 	}
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	if (DAT_FALSE == udat_check_state()) {
1287c478bd9Sstevel@tonic-gate 		return (DAT_ERROR(DAT_INVALID_STATE, 0));
1297c478bd9Sstevel@tonic-gate 	}
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 	return (dat_dr_remove(provider_info));
1327c478bd9Sstevel@tonic-gate }
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate /*
1367c478bd9Sstevel@tonic-gate  *
1377c478bd9Sstevel@tonic-gate  * Consumer API
1387c478bd9Sstevel@tonic-gate  *
1397c478bd9Sstevel@tonic-gate  */
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate /*
1427c478bd9Sstevel@tonic-gate  * Function: dat_ia_open
1437c478bd9Sstevel@tonic-gate  */
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate DAT_RETURN
dat_ia_openv(IN const DAT_NAME_PTR name,IN DAT_COUNT async_event_qlen,INOUT DAT_EVD_HANDLE * async_event_handle,OUT DAT_IA_HANDLE * ia_handle,IN DAT_UINT32 dapl_major,IN DAT_UINT32 dapl_minor,IN DAT_BOOLEAN thread_safety)1467c478bd9Sstevel@tonic-gate dat_ia_openv(
1477c478bd9Sstevel@tonic-gate 	IN	const DAT_NAME_PTR	name,
1487c478bd9Sstevel@tonic-gate 	IN	DAT_COUNT		async_event_qlen,
1497c478bd9Sstevel@tonic-gate 	INOUT	DAT_EVD_HANDLE		*async_event_handle,
1507c478bd9Sstevel@tonic-gate 	OUT	DAT_IA_HANDLE		*ia_handle,
1517c478bd9Sstevel@tonic-gate 	IN	DAT_UINT32		dapl_major,
1527c478bd9Sstevel@tonic-gate 	IN	DAT_UINT32		dapl_minor,
1537c478bd9Sstevel@tonic-gate 	IN	DAT_BOOLEAN		thread_safety)
1547c478bd9Sstevel@tonic-gate {
1557c478bd9Sstevel@tonic-gate 	DAT_IA_OPEN_FUNC		ia_open_func;
1567c478bd9Sstevel@tonic-gate 	DAT_PROVIDER_INFO 		info;
1577c478bd9Sstevel@tonic-gate 	DAT_RETURN 			status;
1587c478bd9Sstevel@tonic-gate 	DAT_OS_SIZE 			len;
159*03494a98SBill Taylor #define	RO_AWARE_PREFIX	"RO_AWARE_"
160*03494a98SBill Taylor 	boolean_t			ro_aware_client;
161*03494a98SBill Taylor 	const char			*_name = name;
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API,
1647c478bd9Sstevel@tonic-gate 	    "DAT Registry: dat_ia_open() called\n");
1657c478bd9Sstevel@tonic-gate 
166*03494a98SBill Taylor 	if (UDAT_IS_BAD_POINTER(_name)) {
1677c478bd9Sstevel@tonic-gate 		return (DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG1));
1687c478bd9Sstevel@tonic-gate 	}
1697c478bd9Sstevel@tonic-gate 
170*03494a98SBill Taylor 	len = dat_os_strlen(_name);
1717c478bd9Sstevel@tonic-gate 
172*03494a98SBill Taylor 	if (DAT_NAME_MAX_LENGTH <= len) {
1737c478bd9Sstevel@tonic-gate 		return (DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG1));
1747c478bd9Sstevel@tonic-gate 	}
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	if (UDAT_IS_BAD_POINTER(ia_handle)) {
1777c478bd9Sstevel@tonic-gate 		return (DAT_ERROR(DAT_INVALID_HANDLE, DAT_INVALID_HANDLE_IA));
1787c478bd9Sstevel@tonic-gate 	}
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate 	if (DAT_FALSE == udat_check_state()) {
1817c478bd9Sstevel@tonic-gate 		return (DAT_ERROR(DAT_INVALID_STATE, 0));
1827c478bd9Sstevel@tonic-gate 	}
1837c478bd9Sstevel@tonic-gate 
184*03494a98SBill Taylor 	/* Find out if this is an RO aware client and if so, strip the prefix */
185*03494a98SBill Taylor 	ro_aware_client =
186*03494a98SBill Taylor 	    (strncmp(RO_AWARE_PREFIX, _name, sizeof (RO_AWARE_PREFIX) - 1) ==
187*03494a98SBill Taylor 	    0);
188*03494a98SBill Taylor 
189*03494a98SBill Taylor 	/* strip off the prefix from the provider's name if present */
190*03494a98SBill Taylor 	if (ro_aware_client) {
191*03494a98SBill Taylor 		_name = _name + sizeof (RO_AWARE_PREFIX) - 1;
192*03494a98SBill Taylor 		len -= sizeof (RO_AWARE_PREFIX) - 1;
193*03494a98SBill Taylor 	}
194*03494a98SBill Taylor 
195*03494a98SBill Taylor 	(void) dat_os_strncpy(info.ia_name, _name, len);
1967c478bd9Sstevel@tonic-gate 	info.ia_name[len] = '\0';
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	info.dapl_version_major = dapl_major;
1997c478bd9Sstevel@tonic-gate 	info.dapl_version_minor = dapl_minor;
2007c478bd9Sstevel@tonic-gate 	info.is_thread_safe = thread_safety;
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	/*
2037c478bd9Sstevel@tonic-gate 	 * Since DAT allows providers to be loaded by either the static
2047c478bd9Sstevel@tonic-gate 	 * registry or explicitly through OS dependent methods, do not
2057c478bd9Sstevel@tonic-gate 	 * return an error if no providers are loaded via the static registry.
2067c478bd9Sstevel@tonic-gate 	 * Don't even bother calling the static registry if DAT is compiled
2077c478bd9Sstevel@tonic-gate 	 * with no static registry support.
2087c478bd9Sstevel@tonic-gate 	 */
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate #ifndef DAT_NO_STATIC_REGISTRY
2117c478bd9Sstevel@tonic-gate 	(void) dat_sr_provider_open(&info);
2127c478bd9Sstevel@tonic-gate #endif
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 	status = dat_dr_provider_open(&info, &ia_open_func);
2157c478bd9Sstevel@tonic-gate 	if (status != DAT_SUCCESS) {
2167c478bd9Sstevel@tonic-gate 		dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API,
2177c478bd9Sstevel@tonic-gate 		    "DAT Registry: dat_ia_open() provider information "
2187c478bd9Sstevel@tonic-gate 		    "for IA name %s not found in dynamic registry\n",
219*03494a98SBill Taylor 		    _name);
2207c478bd9Sstevel@tonic-gate 		return (status);
2217c478bd9Sstevel@tonic-gate 	}
2227c478bd9Sstevel@tonic-gate 
223*03494a98SBill Taylor 	return (*ia_open_func)((const DAT_NAME_PTR) _name,
2247c478bd9Sstevel@tonic-gate 	    async_event_qlen,
2257c478bd9Sstevel@tonic-gate 	    async_event_handle,
226*03494a98SBill Taylor 	    ia_handle,
227*03494a98SBill Taylor 	    ro_aware_client);
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate /*
2327c478bd9Sstevel@tonic-gate  * Function: dat_ia_close
2337c478bd9Sstevel@tonic-gate  */
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate DAT_RETURN
dat_ia_close(IN DAT_IA_HANDLE ia_handle,IN DAT_CLOSE_FLAGS ia_flags)2367c478bd9Sstevel@tonic-gate dat_ia_close(
2377c478bd9Sstevel@tonic-gate 	IN DAT_IA_HANDLE	ia_handle,
2387c478bd9Sstevel@tonic-gate 	IN DAT_CLOSE_FLAGS	ia_flags)
2397c478bd9Sstevel@tonic-gate {
2407c478bd9Sstevel@tonic-gate 	DAT_PROVIDER	*provider;
2417c478bd9Sstevel@tonic-gate 	DAT_PROVIDER_ATTR   provider_attr = {0};
2427c478bd9Sstevel@tonic-gate 	DAT_RETURN 		status;
2437c478bd9Sstevel@tonic-gate 	const char 		*ia_name;
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 	dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API,
2467c478bd9Sstevel@tonic-gate 	    "DAT Registry: dat_ia_close() called\n");
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	if (UDAT_IS_BAD_POINTER(ia_handle)) {
2497c478bd9Sstevel@tonic-gate 		return (DAT_ERROR(DAT_INVALID_HANDLE, DAT_INVALID_HANDLE_IA));
2507c478bd9Sstevel@tonic-gate 	}
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 	if (DAT_FALSE == udat_check_state()) {
2537c478bd9Sstevel@tonic-gate 		return (DAT_ERROR(DAT_INVALID_STATE, 0));
2547c478bd9Sstevel@tonic-gate 	}
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate 	provider = DAT_HANDLE_TO_PROVIDER(ia_handle);
2577c478bd9Sstevel@tonic-gate 	ia_name = provider->device_name;
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	if (DAT_SUCCESS != (status = dat_ia_query(ia_handle,
2607c478bd9Sstevel@tonic-gate 	    NULL,
2617c478bd9Sstevel@tonic-gate 	    0,
2627c478bd9Sstevel@tonic-gate 	    NULL,
2637c478bd9Sstevel@tonic-gate 	    DAT_PROVIDER_FIELD_ALL,
2647c478bd9Sstevel@tonic-gate 	    &provider_attr))) {
2657c478bd9Sstevel@tonic-gate 		dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API,
2667c478bd9Sstevel@tonic-gate 		    "DAT Registry: query function for %s provider failed\n",
2677c478bd9Sstevel@tonic-gate 		    ia_name);
2687c478bd9Sstevel@tonic-gate 	} else if (DAT_SUCCESS != (status =
2697c478bd9Sstevel@tonic-gate 	    (*provider->ia_close_func)(ia_handle, ia_flags))) {
2707c478bd9Sstevel@tonic-gate 		dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API,
2717c478bd9Sstevel@tonic-gate 		    "DAT Registry: close function for %s provider failed\n",
2727c478bd9Sstevel@tonic-gate 		    ia_name);
2737c478bd9Sstevel@tonic-gate 	} else {
2747c478bd9Sstevel@tonic-gate 		DAT_PROVIDER_INFO info;
2757c478bd9Sstevel@tonic-gate 		DAT_OS_SIZE len;
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 		len = dat_os_strlen(ia_name);
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 		dat_os_assert(len <= DAT_NAME_MAX_LENGTH);
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 		(void) dat_os_strncpy(info.ia_name, ia_name, len);
2827c478bd9Sstevel@tonic-gate 		info.ia_name[len] = '\0';
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 		info.dapl_version_major = provider_attr.dapl_version_major;
2857c478bd9Sstevel@tonic-gate 		info.dapl_version_minor = provider_attr.dapl_version_minor;
2867c478bd9Sstevel@tonic-gate 		info.is_thread_safe = provider_attr.is_thread_safe;
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 		status = dat_dr_provider_close(&info);
2897c478bd9Sstevel@tonic-gate 		if (DAT_SUCCESS != status) {
2907c478bd9Sstevel@tonic-gate 			dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API,
2917c478bd9Sstevel@tonic-gate 			    "DAT Registry: dynamic registry unable to close "
2927c478bd9Sstevel@tonic-gate 			    "provider for IA name %s\n",
2937c478bd9Sstevel@tonic-gate 			    ia_name);
2947c478bd9Sstevel@tonic-gate 		}
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate #ifndef DAT_NO_STATIC_REGISTRY
2977c478bd9Sstevel@tonic-gate 		status = dat_sr_provider_close(&info);
2987c478bd9Sstevel@tonic-gate 		if (DAT_SUCCESS != status) {
2997c478bd9Sstevel@tonic-gate 			dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API,
3007c478bd9Sstevel@tonic-gate 			    "DAT Registry: static registry unable to close "
3017c478bd9Sstevel@tonic-gate 			    "provider for IA name %s\n",
3027c478bd9Sstevel@tonic-gate 			    ia_name);
3037c478bd9Sstevel@tonic-gate 		}
3047c478bd9Sstevel@tonic-gate #endif
3057c478bd9Sstevel@tonic-gate 	}
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	return (status);
3087c478bd9Sstevel@tonic-gate }
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate /*
3127c478bd9Sstevel@tonic-gate  * Function: dat_registry_list_providers
3137c478bd9Sstevel@tonic-gate  */
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate DAT_RETURN
dat_registry_list_providers(IN DAT_COUNT max_to_return,OUT DAT_COUNT * entries_returned,OUT DAT_PROVIDER_INFO * (dat_provider_list[]))3167c478bd9Sstevel@tonic-gate dat_registry_list_providers(
3177c478bd9Sstevel@tonic-gate 	IN  DAT_COUNT   		max_to_return,
3187c478bd9Sstevel@tonic-gate 	    OUT DAT_COUNT   		*entries_returned,
3197c478bd9Sstevel@tonic-gate 	    OUT	DAT_PROVIDER_INFO 	*(dat_provider_list[]))
3207c478bd9Sstevel@tonic-gate {
3217c478bd9Sstevel@tonic-gate 	DAT_RETURN	dat_status;
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 	dat_status = DAT_SUCCESS;
3247c478bd9Sstevel@tonic-gate 	dat_os_dbg_print(DAT_OS_DBG_TYPE_CONSUMER_API,
3257c478bd9Sstevel@tonic-gate 	    "DAT Registry: dat_registry_list_providers() called\n");
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 	if (DAT_FALSE == udat_check_state()) {
3287c478bd9Sstevel@tonic-gate 			return (DAT_ERROR(DAT_INVALID_STATE, 0));
3297c478bd9Sstevel@tonic-gate 	}
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	if ((UDAT_IS_BAD_POINTER(entries_returned))) {
3327c478bd9Sstevel@tonic-gate 		return (DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG2));
3337c478bd9Sstevel@tonic-gate 	}
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 	if (0 != max_to_return && (UDAT_IS_BAD_POINTER(dat_provider_list))) {
3367c478bd9Sstevel@tonic-gate 		return (DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG3));
3377c478bd9Sstevel@tonic-gate 	}
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 	if (0 == max_to_return) {
3407c478bd9Sstevel@tonic-gate 		/*
3417c478bd9Sstevel@tonic-gate 		 * the user is allowed to call with max_to_return set to zero.
3427c478bd9Sstevel@tonic-gate 		 * in which case we simply return (in *entries_returned) the
3437c478bd9Sstevel@tonic-gate 		 * number of providers currently installed.  We must also
3447c478bd9Sstevel@tonic-gate 		 * (per spec) return an error
3457c478bd9Sstevel@tonic-gate 		 */
3467c478bd9Sstevel@tonic-gate #ifndef DAT_NO_STATIC_REGISTRY
3477c478bd9Sstevel@tonic-gate 		(void) dat_sr_size(entries_returned);
3487c478bd9Sstevel@tonic-gate #else
3497c478bd9Sstevel@tonic-gate 		(void) dat_dr_size(entries_returned);
3507c478bd9Sstevel@tonic-gate #endif
3517c478bd9Sstevel@tonic-gate 		return (DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG1));
3527c478bd9Sstevel@tonic-gate 	} else {
3537c478bd9Sstevel@tonic-gate #ifndef DAT_NO_STATIC_REGISTRY
3547c478bd9Sstevel@tonic-gate 		dat_status = dat_sr_list(max_to_return,
3557c478bd9Sstevel@tonic-gate 		    entries_returned,
3567c478bd9Sstevel@tonic-gate 		    dat_provider_list);
3577c478bd9Sstevel@tonic-gate #else
3587c478bd9Sstevel@tonic-gate 		dat_status = dat_dr_list(max_to_return,
3597c478bd9Sstevel@tonic-gate 		    entries_returned,
3607c478bd9Sstevel@tonic-gate 		    dat_provider_list);
3617c478bd9Sstevel@tonic-gate #endif
3627c478bd9Sstevel@tonic-gate 	}
3637c478bd9Sstevel@tonic-gate 	return (dat_status);
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate /*
3687c478bd9Sstevel@tonic-gate  *
3697c478bd9Sstevel@tonic-gate  * Internal Function Definitions
3707c478bd9Sstevel@tonic-gate  *
3717c478bd9Sstevel@tonic-gate  */
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate /*
3757c478bd9Sstevel@tonic-gate  * Function: udat_check_state
3767c478bd9Sstevel@tonic-gate  */
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate /*
3797c478bd9Sstevel@tonic-gate  * This function returns TRUE if the DAT registry is in a state capable
3807c478bd9Sstevel@tonic-gate  * of handling DAT API calls and false otherwise.
3817c478bd9Sstevel@tonic-gate  */
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate DAT_BOOLEAN
udat_check_state(void)3847c478bd9Sstevel@tonic-gate udat_check_state(void)
3857c478bd9Sstevel@tonic-gate {
3867c478bd9Sstevel@tonic-gate 	DAT_MODULE_STATE 		state;
3877c478bd9Sstevel@tonic-gate 	DAT_BOOLEAN 		status;
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate 	state = dat_module_get_state();
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate 	if (DAT_MODULE_STATE_UNINITIALIZED == state) {
3927c478bd9Sstevel@tonic-gate 		dat_init();
3937c478bd9Sstevel@tonic-gate 		status = DAT_TRUE;
3947c478bd9Sstevel@tonic-gate 	} else if (DAT_MODULE_STATE_DEINITIALIZED == state) {
3957c478bd9Sstevel@tonic-gate 		status = DAT_FALSE;
3967c478bd9Sstevel@tonic-gate 	} else {
3977c478bd9Sstevel@tonic-gate 		status = DAT_TRUE;
3987c478bd9Sstevel@tonic-gate 	}
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate 	return (status);
4017c478bd9Sstevel@tonic-gate }
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate /*
4057c478bd9Sstevel@tonic-gate  * Local variables:
4067c478bd9Sstevel@tonic-gate  *  c-indent-level: 4
4077c478bd9Sstevel@tonic-gate  *  c-basic-offset: 4
4087c478bd9Sstevel@tonic-gate  *  tab-width: 8
4097c478bd9Sstevel@tonic-gate  * End:
4107c478bd9Sstevel@tonic-gate  */
411