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