9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * CDDL HEADER START
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The contents of this file are subject to the terms of the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Common Development and Distribution License (the "License").
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * You may not use this file except in compliance with the License.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * See the License for the specific language governing permissions
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * and limitations under the License.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * When distributing Covered Code, include this CDDL HEADER in each
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * If applicable, add the following below this CDDL HEADER, with the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * fields enclosed by brackets "[]" replaced with your own identifying
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * information: Portions Copyright [yyyy] [name of copyright owner]
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * CDDL HEADER END
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Use is subject to license terms.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * PURPOSE: Operating System Dependent layer
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Description:
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Provide OS dependent functions with a canonical DAPL
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * interface. Designed to be portable and hide OS specific quirks
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * of common functions.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * $Id: dapl_osd.c,v 1.26 2003/07/31 14:04:18 jlentini Exp $
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#include <pthread.h> /* needed for pthread_atfork() */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor#include <signal.h> /* needed for thread setup */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylorstatic void dapls_osd_fork_cleanup(void);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * dapl_osd_init
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Do Linux initialization:
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * - Set up fork handler to clean up DAPL resources in the child
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * process after a fork().
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_SUCCESS
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Set up fork control
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor status = pthread_atfork(NULL, NULL, dapls_osd_fork_cleanup);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * dapl_os_get_time
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Return 64 bit value of current time in microseconds.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * loc User location to place current time
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_SUCCESS
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor *loc = ((DAT_UINT64)(tv.tv_sec) * 1000000L) + (DAT_UINT64) tv.tv_usec;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * dapl_os_get__env_bool
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Return boolean value of passed in environment variable: 1 if present,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * TRUE or FALSE
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * dapl_os_get_env_val
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Update val to value of passed in environment variable if present
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * def_val default value if environment variable does not exist
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * TRUE or FALSE
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Wait object routines
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * dapl_os_wait_object_init
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Initialize a wait object
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_SUCCESS
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_INTERNAL_ERROR
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (0 != pthread_cond_init(&wait_obj->cv, NULL)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Always returns 0. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (void) pthread_mutex_init(&wait_obj->lock, NULL);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Wait on the supplied wait object, up to the specified time_out.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * A timeout of DAT_TIMEOUT_INFINITE will wait indefinitely.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Timeout should be specified in micro seconds.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Functional returns:
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_SUCCESS -- another thread invoked dapl_os_wait object_wakeup
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_INVALID_STATE -- someone else is already waiting in this wait
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * only one waiter is allowed at a time.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_ABORT -- another thread invoked dapl_os_wait_object_destroy
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_TIMEOUT -- the specified time limit was reached.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor microsecs = now.tv_usec + (timeout_val % 1000000);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor now.tv_sec = now.tv_sec + timeout_val / 1000000 + 1;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor now.tv_sec = now.tv_sec + timeout_val / 1000000;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Convert timeval to timespec */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor while (wait_obj->signaled == DAT_FALSE && pthread_status == 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * No need to reset &future if we go around the loop;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * It's an absolute time.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Reset the signaled status if we were woken up. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor while (wait_obj->signaled == DAT_FALSE && pthread_status == 0) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* Reset the signaled status if we were woken up. */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor } else if (0 != pthread_status) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * dapl_os_wait_object_wakeup
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Wakeup a thread waiting on a wait object
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_SUCCESS
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_INTERNAL_ERROR
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * dapl_os_wait_object_destroy
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Destroy a wait object
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_SUCCESS
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_INTERNAL_ERROR
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (0 != pthread_mutex_destroy(&wait_obj->lock)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * dapls_osd_fork_cleanup
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Update val to value of passed in environment variable if present
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * val Updated if environment variable exists
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * TRUE or FALSE
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor hca_ptr = (DAPL_HCA *) cur_node->data.extension;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Walk the list of IA ptrs & clean up. This is purposely
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * a destructive list walk, we really don't want to preserve
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * any of it.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor while (!dapl_llist_is_empty(&hca_ptr->ia_list_head)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The rest of the cleanup code is similar to
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * dapl_ia_close, the big difference is that we don't
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * release IB resources, only memory; the underlying IB
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * subsystem doesn't deal with fork at all, so leave
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * IB handles alone.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor while (!dapl_llist_is_empty(&ia_ptr->rmr_list_head)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor while (!dapl_llist_is_empty(&ia_ptr->rsp_list_head)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor while (!dapl_llist_is_empty(&ia_ptr->ep_list_head)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* ...and free the resource */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor while (!dapl_llist_is_empty(&ia_ptr->lmr_list_head)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor while (!dapl_llist_is_empty(&ia_ptr->psp_list_head)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor while (!dapl_llist_is_empty(&ia_ptr->pz_list_head)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor while (!dapl_llist_is_empty(&ia_ptr->evd_list_head)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * reset the cq_handle to avoid having it
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * asycn error evd was taken care of above, reset the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor } /* end while( ia_ptr != NULL ) */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor dapl_os_free(cur_node, sizeof (DAPL_PROVIDER_LIST_NODE));
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor } /* end while (NULL != g_dapl_provider_list.head) */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Local variables:
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * c-indent-level: 4
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * c-basic-offset: 4
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * tab-width: 8