1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
24  */
25 
26 /*
27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 /*
32  *
33  * MODULE: dat_init.c
34  *
35  * PURPOSE: DAT registry implementation for uDAPL
36  * Description: init and fini functions for DAT module.
37  *
38  * $Id: dat_init.c,v 1.12 2003/07/09 11:26:06 hobie16 Exp $
39  */
40 
41 #include "dat_init.h"
42 
43 #include "dat_dr.h"
44 #include "dat_osd.h"
45 
46 #ifndef DAT_NO_STATIC_REGISTRY
47 #include "dat_sr.h"
48 #endif
49 
50 
51 /*
52  *
53  * Global Variables
54  *
55  */
56 
57 /*
58  * Ideally, the following two rules could be enforced:
59  *
60  * - The DAT Registry's initialization function is executed before that
61  *   of any DAT Providers and hence all calls into the registry occur
62  *   after the registry module is initialized.
63  *
64  * - The DAT Registry's deinitialization function is executed after that
65  *   of any DAT Providers and hence all calls into the registry occur
66  *   before the registry module is deinitialized.
67  *
68  * However, on many platforms few guarantees are provided regarding the
69  * order in which modules initialization and deinitialization functions
70  * are invoked.
71  *
72  * To understand why these rules are difficult to enforce using only
73  * features common to all platforms, consider the Linux platform. The order
74  * in which Linux shared libraries are loaded into a process's address space
75  * is undefined. When a DAT consumer explicitly links to DAT provider
76  * libraries, the order in which library initialization and deinitialization
77  * functions are invoked becomes important. For example if the DAPL provider
78  * calls dat_registry_add_provider() before the registry has been initialized,
79  * an error will occur.
80  *
81  * We assume that modules are loaded with a single thread. Given
82  * this assumption, we can use a simple state variable to determine
83  * the state of the DAT registry.
84  */
85 
86 static DAT_MODULE_STATE 	g_module_state = DAT_MODULE_STATE_UNINITIALIZED;
87 
88 
89 /*
90  * Function: dat_module_get_state
91  */
92 
93 DAT_MODULE_STATE
dat_module_get_state(void)94 dat_module_get_state(void)
95 {
96 	return (g_module_state);
97 }
98 
99 
100 /*
101  *  Function: dat_init
102  */
103 
104 void
dat_init(void)105 dat_init(void)
106 {
107 	if (DAT_MODULE_STATE_UNINITIALIZED == g_module_state) {
108 	/*
109 	 * update the module state flag immediately in case there
110 	 * is a recursive call to dat_init().
111 	 */
112 		g_module_state = DAT_MODULE_STATE_INITIALIZING;
113 
114 		dat_os_dbg_init();
115 
116 		dat_os_dbg_print(DAT_OS_DBG_TYPE_GENERIC,
117 		    "DAT Registry: Started (dat_init)\n");
118 
119 #ifndef DAT_NO_STATIC_REGISTRY
120 		(void) dat_sr_init();
121 #endif
122 		(void) dat_dr_init();
123 
124 		g_module_state = DAT_MODULE_STATE_INITIALIZED;
125 	}
126 }
127 
128 
129 /*
130  * Function: dat_fini
131  */
132 
133 void
dat_fini(void)134 dat_fini(void)
135 {
136 	if (DAT_MODULE_STATE_INITIALIZED == g_module_state) {
137 		g_module_state = DAT_MODULE_STATE_DEINITIALIZING;
138 
139 		(void) dat_dr_fini();
140 #ifndef DAT_NO_STATIC_REGISTRY
141 		(void) dat_sr_fini();
142 #endif
143 		dat_os_dbg_print(DAT_OS_DBG_TYPE_GENERIC,
144 		    "DAT Registry: Stopped (dat_fini)\n");
145 
146 		g_module_state = DAT_MODULE_STATE_DEINITIALIZED;
147 	}
148 }
149 
150 
151 /*
152  * Local variables:
153  *  c-indent-level: 4
154  *  c-basic-offset: 4
155  *  tab-width: 8
156  * End:
157  */
158