2
* ADIOS is freely available under the terms of the BSD license described
3
* in the COPYING file in the top level directory of this source distribution.
5
* Copyright (c) 2008 - 2009. UT-BATTELLE, LLC. All rights reserved.
11
#include <sys/stat.h> /* struct stat */
16
#include "public/adios_mpi.h"
17
#include "nssi_client.h"
18
#include "adios_nssi_args.h"
19
#include "adios_nssi_config.h"
21
// this macro makes getting the attributes easier
23
#define GET_ATTR(n,attr,var,en) \
24
if (!strcasecmp (n, attr->name)) { \
32
fprintf (stderr, "xml: duplicate attribute %s on %s (ignored)",n,en); \
38
static int parseGroup(mxml_node_t * node, struct adios_nssi_config *config)
45
// printf("enter parseGroup\n");
47
for (n = mxmlWalkNext (node, node, MXML_DESCEND)
49
;n = mxmlWalkNext (n, node, MXML_NO_DESCEND)
52
if (n->type != MXML_ELEMENT)
57
if (!strcasecmp (n->value.element.name, "staging-service"))
63
config->num_servers=service_count;
64
config->nssi_server_ids=(nssi_remote_pid *)calloc(service_count, sizeof(nssi_remote_pid));
68
for (n = mxmlWalkNext (node, node, MXML_DESCEND)
70
;n = mxmlWalkNext (n, node, MXML_NO_DESCEND)
73
if (n->type != MXML_ELEMENT)
78
if (!strcasecmp (n->value.element.name, "staging-service"))
80
mxml_node_t * n1; // used for global_bounds
84
const char *hostname = 0;
87
for (i = 0; i < n->value.element.num_attrs; i++)
89
mxml_attr_t * attr = &n->value.element.attrs [i];
91
GET_ATTR("nid",attr,nid,"var")
92
GET_ATTR("pid",attr,pid,"var")
94
GET_ATTR("hostname",attr,hostname,"var")
95
GET_ATTR("port",attr,port,"var")
97
fprintf (stderr, "config.xml: unknown attribute '%s' on %s "
104
config->nssi_server_ids[service_num].nid = (nssi_pid)atoll(nid);
105
config->nssi_server_ids[service_num].pid = (nssi_pid)atoll(pid);
106
config->nssi_server_ids[service_num].hostname[0]='\0';
107
strncpy(config->nssi_server_ids[service_num].hostname, hostname, NSSI_HOSTNAME_LEN);
108
#ifdef HAVE_INFINIBAND
109
config->nssi_server_ids[service_num].addr = inet_addr(config->nssi_server_ids[service_num]->hostname);
111
config->nssi_server_ids[service_num].port = (nssi_pid)atoi(port);
113
// log_debug(netcdf_config_debug_level, "service (nid=%lld, pid=%llu, hostname=%s, addr=%d, port=%d)",
114
// (long long)id->nid, (long long)id->pid, id->hostname, id->addr, id->port);
116
// printf("staging-service: service_num(%d) nid(%lld) pid(%llu) hostname(%s) port(%d)\n",
118
// config->nssi_server_ids[service_num].nid,
119
// config->nssi_server_ids[service_num].pid,
120
// config->nssi_server_ids[service_num].hostname,
121
// config->nssi_server_ids[service_num].port);
126
if (!strncmp (n->value.element.name, "!--", 3)) // a comment
132
fprintf (stderr, "config.xml: invalid xml element: '%s'\n"
133
,n->value.element.name
145
int parse_nssi_config(const char *config_file, struct adios_nssi_config *config)
148
mxml_node_t * doc = NULL;
149
mxml_node_t * node = NULL;
150
mxml_node_t * root = NULL;
151
int saw_staging_group = 0;
155
char * buffer = NULL;
159
MPI_Comm_rank (MPI_COMM_WORLD, &rank);
163
fp = fopen (config_file, "r");
166
fprintf (stderr, "missing config file %s\n", config_file);
171
if (stat (config_file, &s) == 0)
173
buffer = malloc (s.st_size + 1);
174
buffer [s.st_size] = 0;
178
size_t bytes_read = fread (buffer, 1, s.st_size, fp);
179
if (bytes_read != s.st_size)
181
fprintf (stderr, "error reading config file: %s. Expected %d Got %d\n"
182
,config_file, s.st_size, bytes_read );
189
fprintf (stderr, "error allocating %d for reading config.\n"
197
buffer_size = s.st_size;
198
MPI_Bcast (&buffer_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
199
MPI_Bcast (buffer, buffer_size, MPI_BYTE, 0, MPI_COMM_WORLD);
203
MPI_Bcast (&buffer_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
204
buffer = malloc (buffer_size + 1);
207
fprintf (stderr, "cannot allocate %d bytes to receive config file\n"
213
MPI_Bcast (buffer, buffer_size, MPI_BYTE, 0, MPI_COMM_WORLD);
214
buffer [buffer_size] = 0;
218
doc = mxmlLoadString (NULL, buffer, MXML_TEXT_CALLBACK);
224
fprintf (stderr, "config.xml: unknown error parsing XML "
225
"(probably structural)\n"
226
"Did you remember to start the file with\n"
227
"<?xml version=\"1.0\"?>\n");
234
while (root && root->type != MXML_ELEMENT)
236
root = mxmlWalkNext (root, doc, MXML_DESCEND);
239
while (!strncmp (root->value.element.name, "!--", 3))
241
root = mxmlWalkNext (root, doc, MXML_NO_DESCEND);
242
root = mxmlWalkNext (root, doc, MXML_NO_DESCEND);
245
if (strcasecmp (root->value.element.name, "nssi-config"))
247
if (strncmp (root->value.element.name, "?xml", 4))
249
fprintf (stderr, "config.xml: invalid root xml element: %s\n"
250
,root->value.element.name
259
while (!strncmp (root->value.element.name, "!--", 3))
261
root = mxmlWalkNext (root, doc, MXML_NO_DESCEND);
264
root = mxmlWalkNext (root, doc, MXML_DESCEND); // skip ver num
265
root = mxmlWalkNext (root, doc, MXML_NO_DESCEND); // get next
266
while (!strncmp (root->value.element.name, "!--", 3))
268
root = mxmlWalkNext (root, doc, MXML_NO_DESCEND);
269
root = mxmlWalkNext (root, doc, MXML_NO_DESCEND);
275
printf("it is nssi-config\n");
279
for (node = mxmlWalkNext (root, doc, MXML_DESCEND_FIRST)
281
;node = mxmlWalkNext (node, root, MXML_NO_DESCEND)
284
if (node->type != MXML_ELEMENT)
289
if (!strcasecmp (node->value.element.name, "staging-group"))
291
const char *write_type = 0;
293
for (i = 0; i < node->value.element.num_attrs; i++)
295
mxml_attr_t *attr = &node->value.element.attrs[i];
297
GET_ATTR("write-type",attr,write_type,"var")
299
fprintf (stderr, "config.xml: unknown attribute '%s' on %s "
306
if (!strcmp(write_type, "WRITE_DIRECT")) {
307
config->write_type = WRITE_DIRECT;
308
// log_debug(LOG_ALL, "using %s", write_type);
309
} else if (!strcmp(write_type, "WRITE_AGGREGATE_INDEPENDENT")) {
310
config->write_type = WRITE_AGGREGATE_INDEPENDENT;
311
// log_debug(LOG_ALL, "using %s", write_type);
312
} else if (!strcmp(write_type, "WRITE_AGGREGATE_COLLECTIVE")) {
313
config->write_type = WRITE_AGGREGATE_COLLECTIVE;
314
// log_debug(LOG_ALL, "using %s", write_type);
315
} else if (!strcmp(write_type, "WRITE_CACHING_INDEPENDENT")) {
316
config->write_type = WRITE_CACHING_INDEPENDENT;
317
// log_debug(LOG_ALL, "using %s", write_type);
318
} else if (!strcmp(write_type, "WRITE_CACHING_COLLECTIVE")) {
319
config->write_type = WRITE_CACHING_COLLECTIVE;
320
// log_debug(LOG_ALL, "using %s", write_type);
323
if (!parseGroup(node, config))
325
saw_staging_group = 1;
329
if (!strncmp (node->value.element.name, "!--", 3))
335
fprintf (stderr, "config.xml: invalid element: %s\n"
336
,node->value.element.name
346
if (!saw_staging_group)
348
fprintf (stderr, "config.xml: must define at least 1 staging-group in "
355
// for (i=0;i<config->num_servers;i++) {
356
// printf("staging-service: service_num(%d) nid(%lld) pid(%llu) hostname(%s) port(%d)\n",
358
// config->nssi_server_ids[i].nid,
359
// config->nssi_server_ids[i].pid,
360
// config->nssi_server_ids[i].hostname,
361
// config->nssi_server_ids[i].port);
367
void free_nssi_config(struct adios_nssi_config *config)
369
if (config->nssi_server_ids) {
370
free(config->nssi_server_ids);
371
config->nssi_server_ids=NULL;