4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI"
38 * PURPOSE: DAT registry implementation for uDAPL
39 * Description: init and fini functions for DAT module.
41 * $Id: dat_init.c,v 1.12 2003/07/09 11:26:06 hobie16 Exp $
49 #ifndef DAT_NO_STATIC_REGISTRY
61 * Ideally, the following two rules could be enforced:
63 * - The DAT Registry's initialization function is executed before that
64 * of any DAT Providers and hence all calls into the registry occur
65 * after the registry module is initialized.
67 * - The DAT Registry's deinitialization function is executed after that
68 * of any DAT Providers and hence all calls into the registry occur
69 * before the registry module is deinitialized.
71 * However, on many platforms few guarantees are provided regarding the
72 * order in which modules initialization and deinitialization functions
75 * To understand why these rules are difficult to enforce using only
76 * features common to all platforms, consider the Linux platform. The order
77 * in which Linux shared libraries are loaded into a process's address space
78 * is undefined. When a DAT consumer explicitly links to DAT provider
79 * libraries, the order in which library initialization and deinitialization
80 * functions are invoked becomes important. For example if the DAPL provider
81 * calls dat_registry_add_provider() before the registry has been initialized,
82 * an error will occur.
84 * We assume that modules are loaded with a single thread. Given
85 * this assumption, we can use a simple state variable to determine
86 * the state of the DAT registry.
89 static DAT_MODULE_STATE g_module_state
= DAT_MODULE_STATE_UNINITIALIZED
;
93 * Function: dat_module_get_state
97 dat_module_get_state(void)
99 return (g_module_state
);
110 if (DAT_MODULE_STATE_UNINITIALIZED
== g_module_state
) {
112 * update the module state flag immediately in case there
113 * is a recursive call to dat_init().
115 g_module_state
= DAT_MODULE_STATE_INITIALIZING
;
119 dat_os_dbg_print(DAT_OS_DBG_TYPE_GENERIC
,
120 "DAT Registry: Started (dat_init)\n");
122 #ifndef DAT_NO_STATIC_REGISTRY
123 (void) dat_sr_init();
125 (void) dat_dr_init();
127 g_module_state
= DAT_MODULE_STATE_INITIALIZED
;
139 if (DAT_MODULE_STATE_INITIALIZED
== g_module_state
) {
140 g_module_state
= DAT_MODULE_STATE_DEINITIALIZING
;
142 (void) dat_dr_fini();
143 #ifndef DAT_NO_STATIC_REGISTRY
144 (void) dat_sr_fini();
146 dat_os_dbg_print(DAT_OS_DBG_TYPE_GENERIC
,
147 "DAT Registry: Stopped (dat_fini)\n");
149 g_module_state
= DAT_MODULE_STATE_DEINITIALIZED
;