1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002 Cray Inc.
5 * Copyright (c) 2003 Cluster File Systems, Inc.
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * This file provides the 'library' side for the process-based nals.
25 * it is responsible for communication with the 'api' side and
26 * providing service to the generic portals 'library'
27 * implementation. 'library' might be better termed 'communication'
35 #include <procbridge.h>
36 #include <sys/types.h>
37 #include <sys/socket.h>
43 /* the following functions are stubs to satisfy the nal definition
44 without doing anything particularily useful*/
46 static int nal_dist(lib_nal_t *nal,
53 static void check_stopping(void *z)
56 procbridge p = b->local;
58 if ((p->nal_flags & NAL_FLAG_STOPPING) == 0)
61 pthread_mutex_lock(&p->mutex);
62 p->nal_flags |= NAL_FLAG_STOPPED;
63 pthread_cond_broadcast(&p->cond);
64 pthread_mutex_unlock(&p->mutex);
70 /* Function: nal_thread
71 * Arguments: z: an opaque reference to a nal control structure
72 * allocated and partially populated by the api level code
73 * Returns: nothing, and only on error or explicit shutdown
75 * This function is the entry point of the pthread initiated on
76 * the api side of the interface. This thread is used to handle
77 * asynchronous delivery to the application.
79 * We define a limit macro to place a ceiling on limits
80 * for syntactic convenience
82 extern int tcpnal_init(bridge);
84 nal_initialize nal_table[PTL_IFACE_MAX]={0,tcpnal_init,0};
86 void *nal_thread(void *z)
88 nal_init_args_t *args = (nal_init_args_t *) z;
89 bridge b = args->nia_bridge;
90 procbridge p=b->local;
92 ptl_process_id_t process_id;
95 b->lib_nal=(lib_nal_t *)malloc(sizeof(lib_nal_t));
96 b->lib_nal->libnal_data=b;
97 b->lib_nal->libnal_map=NULL;
98 b->lib_nal->libnal_unmap=NULL;
99 b->lib_nal->libnal_dist=nal_dist;
101 nal_type = args->nia_nal_type;
103 /* Wierd, but this sets b->lib_nal->libnal_ni.ni_pid.{nid,pid}, which
104 * lib_init() is about to do from the process_id passed to it...*/
105 set_address(b,args->nia_requested_pid);
107 process_id = b->lib_nal->libnal_ni.ni_pid;
109 if (nal_table[nal_type]) rc=(*nal_table[nal_type])(b);
110 /* initialize the generic 'library' level code */
112 rc = lib_init(b->lib_nal, args->nia_apinal,
114 args->nia_requested_limits,
115 args->nia_actual_limits);
118 * Whatever the initialization returned is passed back to the
119 * user level code for further interpretation. We just exit if
120 * it is non-zero since something went wrong.
122 /* this should perform error checking */
123 pthread_mutex_lock(&p->mutex);
124 p->nal_flags |= (rc != PTL_OK) ? NAL_FLAG_STOPPED : NAL_FLAG_RUNNING;
125 pthread_cond_broadcast(&p->cond);
126 pthread_mutex_unlock(&p->mutex);
129 /* the thunk function is called each time the timer loop
130 performs an operation and returns to blocking mode. we
131 overload this function to inform the api side that
132 it may be interested in looking at the event queue */
133 register_thunk(check_stopping,b);