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 #pragma ident "%Z%%M% %I% %E% SMI" 32 33 34 /* 35 * 36 * MODULE: dat_init.c 37 * 38 * PURPOSE: DAT registry implementation for uDAPL 39 * Description: init and fini functions for DAT module. 40 * 41 * $Id: dat_init.c,v 1.12 2003/07/09 11:26:06 hobie16 Exp $ 42 */ 43 44 #include "dat_init.h" 45 46 #include "dat_dr.h" 47 #include "dat_osd.h" 48 49 #ifndef DAT_NO_STATIC_REGISTRY 50 #include "dat_sr.h" 51 #endif 52 53 54 /* 55 * 56 * Global Variables 57 * 58 */ 59 60 /* 61 * Ideally, the following two rules could be enforced: 62 * 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. 66 * 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. 70 * 71 * However, on many platforms few guarantees are provided regarding the 72 * order in which modules initialization and deinitialization functions 73 * are invoked. 74 * 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. 83 * 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. 87 */ 88 89 static DAT_MODULE_STATE g_module_state = DAT_MODULE_STATE_UNINITIALIZED; 90 91 92 /* 93 * Function: dat_module_get_state 94 */ 95 96 DAT_MODULE_STATE 97 dat_module_get_state(void) 98 { 99 return (g_module_state); 100 } 101 102 103 /* 104 * Function: dat_init 105 */ 106 107 void 108 dat_init(void) 109 { 110 if (DAT_MODULE_STATE_UNINITIALIZED == g_module_state) { 111 /* 112 * update the module state flag immediately in case there 113 * is a recursive call to dat_init(). 114 */ 115 g_module_state = DAT_MODULE_STATE_INITIALIZING; 116 117 dat_os_dbg_init(); 118 119 dat_os_dbg_print(DAT_OS_DBG_TYPE_GENERIC, 120 "DAT Registry: Started (dat_init)\n"); 121 122 #ifndef DAT_NO_STATIC_REGISTRY 123 (void) dat_sr_init(); 124 #endif 125 (void) dat_dr_init(); 126 127 g_module_state = DAT_MODULE_STATE_INITIALIZED; 128 } 129 } 130 131 132 /* 133 * Function: dat_fini 134 */ 135 136 void 137 dat_fini(void) 138 { 139 if (DAT_MODULE_STATE_INITIALIZED == g_module_state) { 140 g_module_state = DAT_MODULE_STATE_DEINITIALIZING; 141 142 (void) dat_dr_fini(); 143 #ifndef DAT_NO_STATIC_REGISTRY 144 (void) dat_sr_fini(); 145 #endif 146 dat_os_dbg_print(DAT_OS_DBG_TYPE_GENERIC, 147 "DAT Registry: Stopped (dat_fini)\n"); 148 149 g_module_state = DAT_MODULE_STATE_DEINITIALIZED; 150 } 151 } 152 153 154 /* 155 * Local variables: 156 * c-indent-level: 4 157 * c-basic-offset: 4 158 * tab-width: 8 159 * End: 160 */ 161