2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A
2N/A/*
2N/A *
2N/A * MODULE: dat_init.c
2N/A *
2N/A * PURPOSE: DAT registry implementation for uDAPL
2N/A * Description: init and fini functions for DAT module.
2N/A *
2N/A * $Id: dat_init.c,v 1.12 2003/07/09 11:26:06 hobie16 Exp $
2N/A */
2N/A
2N/A#include "dat_init.h"
2N/A
2N/A#include "dat_dr.h"
2N/A#include "dat_osd.h"
2N/A
2N/A#ifndef DAT_NO_STATIC_REGISTRY
2N/A#include "dat_sr.h"
2N/A#endif
2N/A
2N/A
2N/A/*
2N/A *
2N/A * Global Variables
2N/A *
2N/A */
2N/A
2N/A/*
2N/A * Ideally, the following two rules could be enforced:
2N/A *
2N/A * - The DAT Registry's initialization function is executed before that
2N/A * of any DAT Providers and hence all calls into the registry occur
2N/A * after the registry module is initialized.
2N/A *
2N/A * - The DAT Registry's deinitialization function is executed after that
2N/A * of any DAT Providers and hence all calls into the registry occur
2N/A * before the registry module is deinitialized.
2N/A *
2N/A * However, on many platforms few guarantees are provided regarding the
2N/A * order in which modules initialization and deinitialization functions
2N/A * are invoked.
2N/A *
2N/A * To understand why these rules are difficult to enforce using only
2N/A * features common to all platforms, consider the Linux platform. The order
2N/A * in which Linux shared libraries are loaded into a process's address space
2N/A * is undefined. When a DAT consumer explicitly links to DAT provider
2N/A * libraries, the order in which library initialization and deinitialization
2N/A * functions are invoked becomes important. For example if the DAPL provider
2N/A * calls dat_registry_add_provider() before the registry has been initialized,
2N/A * an error will occur.
2N/A *
2N/A * We assume that modules are loaded with a single thread. Given
2N/A * this assumption, we can use a simple state variable to determine
2N/A * the state of the DAT registry.
2N/A */
2N/A
2N/Astatic DAT_MODULE_STATE g_module_state = DAT_MODULE_STATE_UNINITIALIZED;
2N/A
2N/A
2N/A/*
2N/A * Function: dat_module_get_state
2N/A */
2N/A
2N/ADAT_MODULE_STATE
2N/Adat_module_get_state(void)
2N/A{
2N/A return (g_module_state);
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Function: dat_init
2N/A */
2N/A
2N/Avoid
2N/Adat_init(void)
2N/A{
2N/A if (DAT_MODULE_STATE_UNINITIALIZED == g_module_state) {
2N/A /*
2N/A * update the module state flag immediately in case there
2N/A * is a recursive call to dat_init().
2N/A */
2N/A g_module_state = DAT_MODULE_STATE_INITIALIZING;
2N/A
2N/A dat_os_dbg_init();
2N/A
2N/A dat_os_dbg_print(DAT_OS_DBG_TYPE_GENERIC,
2N/A "DAT Registry: Started (dat_init)\n");
2N/A
2N/A#ifndef DAT_NO_STATIC_REGISTRY
2N/A (void) dat_sr_init();
2N/A#endif
2N/A (void) dat_dr_init();
2N/A
2N/A g_module_state = DAT_MODULE_STATE_INITIALIZED;
2N/A }
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Function: dat_fini
2N/A */
2N/A
2N/Avoid
2N/Adat_fini(void)
2N/A{
2N/A if (DAT_MODULE_STATE_INITIALIZED == g_module_state) {
2N/A g_module_state = DAT_MODULE_STATE_DEINITIALIZING;
2N/A
2N/A (void) dat_dr_fini();
2N/A#ifndef DAT_NO_STATIC_REGISTRY
2N/A (void) dat_sr_fini();
2N/A#endif
2N/A dat_os_dbg_print(DAT_OS_DBG_TYPE_GENERIC,
2N/A "DAT Registry: Stopped (dat_fini)\n");
2N/A
2N/A g_module_state = DAT_MODULE_STATE_DEINITIALIZED;
2N/A }
2N/A}
2N/A
2N/A
2N/A/*
2N/A * Local variables:
2N/A * c-indent-level: 4
2N/A * c-basic-offset: 4
2N/A * tab-width: 8
2N/A * End:
2N/A */