File: dapl_init.c

package info (click to toggle)
dapl 2.0.19-1.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 4,300 kB
  • sloc: ansic: 39,217; sh: 10,475; makefile: 529
file content (306 lines) | stat: -rw-r--r-- 7,199 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*
 * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
 *
 * This Software is licensed under one of the following licenses:
 *
 * 1) under the terms of the "Common Public License 1.0" a copy of which is
 *    available from the Open Source Initiative, see
 *    http://www.opensource.org/licenses/cpl.php.
 *
 * 2) under the terms of the "The BSD License" a copy of which is
 *    available from the Open Source Initiative, see
 *    http://www.opensource.org/licenses/bsd-license.php.
 *
 * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
 *    copy of which is available from the Open Source Initiative, see
 *    http://www.opensource.org/licenses/gpl-license.php.
 *
 * Licensee has the right to choose one of the above licenses.
 *
 * Redistributions of source code must retain the above copyright
 * notice and one of the license notices.
 *
 * Redistributions in binary form must reproduce both the above copyright
 * notice, one of the license notices in the documentation
 * and/or other materials provided with the distribution.
 */

/**********************************************************************
 * 
 * MODULE: dapl_init.c
 *
 * PURPOSE: Interface Adapter management
 * Description: Interfaces in this file are completely described in
 *		the DAPL 1.1 API, Chapter 6, section 2
 *
 * $Id:$
 **********************************************************************/

#include "dapl.h"
#include <dat2/dat_registry.h>	/* Provider API function prototypes */
#include "dapl_hca_util.h"
#include "dapl_init.h"
#include "dapl_provider.h"
#include "dapl_mr_util.h"
#include "dapl_osd.h"
#include "dapl_adapter_util.h"
#include "dapl_name_service.h"
#include "dapl_timer_util.h"
#include "dapl_vendor.h"

/*
 * dapl_init
 *
 * initialize this provider
 * includes initialization of all global variables
 * as well as registering all supported IAs with the dat registry
 *
 * This function needs to be called once when the provider is loaded.
 *
 * Input:
 *	none
 *
 * Output:
 *	none
 *
 * Return Values:
 */
void dapl_init(void)
{
	DAT_RETURN dat_status;

	/* set up debug type */
	g_dapl_dbg_type = dapl_os_get_env_val("DAPL_DBG_TYPE",
					      DAPL_DBG_TYPE_ERR);
	/* set up debug destination */
	g_dapl_dbg_dest = dapl_os_get_env_val("DAPL_DBG_DEST",
					      DAPL_DBG_DEST_STDOUT);

	/* open log file on first logging call if necessary */
	if (g_dapl_dbg_dest & DAPL_DBG_DEST_SYSLOG)
		openlog("libdapl", LOG_ODELAY | LOG_PID | LOG_CONS, LOG_USER);

	dapl_log(DAPL_DBG_TYPE_UTIL, "dapl_init: dbg_type=0x%x,dbg_dest=0x%x\n",
		 g_dapl_dbg_type, g_dapl_dbg_dest);

	/* See if the user is on a loopback setup */
	g_dapl_loopback_connection = dapl_os_get_env_bool("DAPL_LOOPBACK");

	dapl_dbg_log(DAPL_DBG_TYPE_UTIL, "DAPL: %s Setting Loopback\n",
		     g_dapl_loopback_connection ? "" : "NOT");

	/* initialize verbs library */
	dapls_ib_init();

	/* initialize the timer */
	dapls_timer_init();

	/* Set up name services */
	dat_status = dapls_ns_init();
	if (DAT_SUCCESS != dat_status) {
		dapl_dbg_log(DAPL_DBG_TYPE_ERR,
			     "dapls_ns_init failed %d\n", dat_status);
		goto bail;
	}

	/* initialize the provider list */
	dat_status = dapl_provider_list_create();

	if (DAT_SUCCESS != dat_status) {
		dapl_dbg_log(DAPL_DBG_TYPE_ERR,
			     "dapl_provider_list_create failed %d\n",
			     dat_status);
		goto bail;
	}

	return;

      bail:
	dapl_dbg_log(DAPL_DBG_TYPE_ERR, "ERROR: dapl_init failed\n");
	return;
}

/*
 * dapl_fini
 *
 * finalize this provider
 * includes freeing of all global variables
 * as well as deregistering all supported IAs from the dat registry
 *
 * This function needs to be called once when the provider is loaded.
 *
 * Input:
 *	none
 *
 * Output:
 *	none
 *
 * Return Values:
 */
void dapl_fini(void)
{
	DAT_RETURN dat_status;

	dapl_dbg_log(DAPL_DBG_TYPE_UTIL, "DAPL: ENTER (dapl_fini)\n");

	dat_status = dapl_provider_list_destroy();
	if (DAT_SUCCESS != dat_status) {
		dapl_dbg_log(DAPL_DBG_TYPE_ERR,
			     "dapl_provider_list_destroy failed %d\n",
			     dat_status);
	}

	dapls_ib_release();

	dapl_dbg_log(DAPL_DBG_TYPE_UTIL, "DAPL: Exit (dapl_fini)\n");

	if (g_dapl_dbg_dest & DAPL_DBG_DEST_SYSLOG)
		closelog();

	return;
}

/*
 *
 * This function is called by the registry to initialize a provider
 *
 * The instance data string is expected to have the following form:
 *
 * <hca name> <port number>
 *
 */
void DAT_API
DAT_PROVIDER_INIT_FUNC_NAME(IN const DAT_PROVIDER_INFO * provider_info,
			    IN const char *instance_data)
{
	DAT_PROVIDER *provider;
	DAPL_HCA *hca_ptr;
	DAT_RETURN dat_status;
	char *data;
	char *name;
	char *port;
	unsigned int len;
	unsigned int i;

	data = NULL;
	provider = NULL;
	hca_ptr = NULL;

#if defined(_WIN32) || defined(_WIN64)
	/* initialize DAPL library here as when called from DLL context in DLLmain()
	 * the IB (ibal) call hangs.
	 */
	dapl_init();
#endif

	dat_status =
	    dapl_provider_list_insert(provider_info->ia_name, &provider);
	if (DAT_SUCCESS != dat_status) {
		dapl_dbg_log(DAPL_DBG_TYPE_ERR,
			     "dat_provider_list_insert failed: %x\n",
			     dat_status);
		goto bail;
	}

	data = dapl_os_strdup(instance_data);
	if (NULL == data) {
		goto bail;
	}

	len = dapl_os_strlen(data);

	for (i = 0; i < len; i++) {
		if (' ' == data[i]) {
			data[i] = '\0';
			break;
		}
	}

	/* if the instance data did not have a valid format */
	if (i == len) {
		goto bail;
	}

	name = data;
	port = data + (i + 1);

	hca_ptr = dapl_hca_alloc(name, port);
	if (NULL == hca_ptr) {
		dapl_dbg_log(DAPL_DBG_TYPE_ERR,
			     "%s() dapl_hca_alloc failed?\n");
		goto bail;
	}

	provider->extension = hca_ptr;
	dat_status = dat_registry_add_provider(provider, provider_info);
	if (DAT_SUCCESS != dat_status) {
		dapl_dbg_log(DAPL_DBG_TYPE_ERR,
			     "dat_registry_add_provider failed: %x\n",
			     dat_status);
	}

      bail:
	if (NULL != data) {
		dapl_os_free(data, len + 1);
	}

	if (DAT_SUCCESS != dat_status) {
		if (NULL != provider) {
			(void)dapl_provider_list_remove(provider_info->ia_name);
		}

		if (NULL != hca_ptr) {
			dapl_hca_free(hca_ptr);
		}
	}
}

/*
 *
 * This function is called by the registry to de-initialize a provider
 *
 */
void DAT_API
DAT_PROVIDER_FINI_FUNC_NAME(IN const DAT_PROVIDER_INFO * provider_info)
{
	DAT_PROVIDER *provider;
	DAT_RETURN dat_status;

	dat_status =
	    dapl_provider_list_search(provider_info->ia_name, &provider);
	if (DAT_SUCCESS != dat_status) {
		dapl_dbg_log(DAPL_DBG_TYPE_ERR,
			     "dat_registry_add_provider failed: %x\n",
			     dat_status);
		return;
	}

	dat_status = dat_registry_remove_provider(provider, provider_info);
	if (DAT_SUCCESS != dat_status) {
		dapl_dbg_log(DAPL_DBG_TYPE_ERR,
			     "dat_registry_add_provider failed: %x\n",
			     dat_status);
	}

	/*
	 * free HCA memory
	 */
	dapl_hca_free(provider->extension);

	(void)dapl_provider_list_remove(provider_info->ia_name);

#if defined(_WIN32) || defined(_WIN64)
	/* cleanup DAPL library - relocated here from OSD DLL context as the IBAL
	 * calls hung in the DLL context?
	 */
	dapl_fini();
#endif
}

/*
 * Local variables:
 *  c-indent-level: 4
 *  c-basic-offset: 4
 *  tab-width: 8
 * End:
 */