~ubuntu-branches/ubuntu/utopic/adios/utopic

« back to all changes in this revision

Viewing changes to src/nssi/adios_nssi_config.c

  • Committer: Package Import Robot
  • Author(s): Alastair McKinstry
  • Date: 2013-12-09 15:21:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20131209152131-jtd4fpmdv3xnunnm
Tags: 1.5.0-1
* New upstream.
* Standards-Version: 3.9.5
* Include latest config.{sub,guess} 
* New watch file.
* Create libadios-bin for binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
4
 *
 
5
 * Copyright (c) 2008 - 2009.  UT-BATTELLE, LLC. All rights reserved.
 
6
 */
 
7
 
 
8
#include <string.h>
 
9
#include <stdlib.h>
 
10
#include <stdint.h>
 
11
#include <sys/stat.h> /* struct stat */
 
12
 
 
13
// xml parser
 
14
#include <mxml.h>
 
15
 
 
16
#include "public/adios_mpi.h"
 
17
#include "nssi_client.h"
 
18
#include "adios_nssi_args.h"
 
19
#include "adios_nssi_config.h"
 
20
 
 
21
// this macro makes getting the attributes easier
 
22
// fix the bgp bugs
 
23
#define GET_ATTR(n,attr,var,en)                              \
 
24
if (!strcasecmp (n, attr->name)) {                           \
 
25
    if (!var)                                                \
 
26
    {                                                        \
 
27
        var = attr->value;                                   \
 
28
        continue;                                            \
 
29
    }                                                        \
 
30
    else                                                     \
 
31
    {                                                        \
 
32
        fprintf (stderr, "xml: duplicate attribute %s on %s (ignored)",n,en); \
 
33
        continue;                                            \
 
34
    }                                                        \
 
35
}
 
36
 
 
37
 
 
38
static int parseGroup(mxml_node_t * node, struct adios_nssi_config *config)
 
39
{
 
40
    mxml_node_t * n;
 
41
    int i;
 
42
    int service_count=0;
 
43
    int service_num=0;
 
44
 
 
45
//    printf("enter parseGroup\n");
 
46
 
 
47
    for (n = mxmlWalkNext (node, node, MXML_DESCEND)
 
48
        ;n
 
49
        ;n = mxmlWalkNext (n, node, MXML_NO_DESCEND)
 
50
        )
 
51
    {
 
52
        if (n->type != MXML_ELEMENT)
 
53
        {
 
54
            continue;
 
55
        }
 
56
 
 
57
        if (!strcasecmp (n->value.element.name, "staging-service"))
 
58
        {
 
59
            service_count++;
 
60
        }
 
61
    }
 
62
 
 
63
    config->num_servers=service_count;
 
64
    config->nssi_server_ids=(nssi_remote_pid *)calloc(service_count, sizeof(nssi_remote_pid));
 
65
 
 
66
 
 
67
    service_num=0;
 
68
    for (n = mxmlWalkNext (node, node, MXML_DESCEND)
 
69
        ;n
 
70
        ;n = mxmlWalkNext (n, node, MXML_NO_DESCEND)
 
71
        )
 
72
    {
 
73
        if (n->type != MXML_ELEMENT)
 
74
        {
 
75
            continue;
 
76
        }
 
77
 
 
78
        if (!strcasecmp (n->value.element.name, "staging-service"))
 
79
        {
 
80
            mxml_node_t * n1;   // used for global_bounds
 
81
 
 
82
            const char *nid = 0;
 
83
            const char *pid= 0;
 
84
            const char *hostname = 0;
 
85
            const char *port = 0;
 
86
 
 
87
            for (i = 0; i < n->value.element.num_attrs; i++)
 
88
            {
 
89
                mxml_attr_t * attr = &n->value.element.attrs [i];
 
90
 
 
91
                GET_ATTR("nid",attr,nid,"var")
 
92
                GET_ATTR("pid",attr,pid,"var")
 
93
 
 
94
                GET_ATTR("hostname",attr,hostname,"var")
 
95
                GET_ATTR("port",attr,port,"var")
 
96
 
 
97
                fprintf (stderr, "config.xml: unknown attribute '%s' on %s "
 
98
                                 "(ignored)\n"
 
99
                        ,attr->name
 
100
                        ,"staging-service"
 
101
                        );
 
102
            }
 
103
 
 
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);
 
110
    #endif
 
111
            config->nssi_server_ids[service_num].port = (nssi_pid)atoi(port);
 
112
 
 
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);
 
115
 
 
116
//            printf("staging-service: service_num(%d) nid(%lld) pid(%llu) hostname(%s) port(%d)\n",
 
117
//                    service_num,
 
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);
 
122
 
 
123
            service_num++;
 
124
 
 
125
        } else {
 
126
            if (!strncmp (n->value.element.name, "!--", 3)) // a comment
 
127
            {
 
128
                continue;
 
129
            }
 
130
            else
 
131
            {
 
132
                fprintf (stderr, "config.xml: invalid xml element: '%s'\n"
 
133
                        ,n->value.element.name
 
134
                        );
 
135
 
 
136
                return 0;
 
137
            }
 
138
        }
 
139
    }
 
140
 
 
141
    return 1;
 
142
}
 
143
 
 
144
 
 
145
int parse_nssi_config(const char *config_file, struct adios_nssi_config *config)
 
146
{
 
147
    FILE * fp = 0;
 
148
    mxml_node_t * doc = NULL;
 
149
    mxml_node_t * node = NULL;
 
150
    mxml_node_t * root = NULL;
 
151
    int saw_staging_group = 0;
 
152
 
 
153
    int i;
 
154
 
 
155
    char * buffer = NULL;
 
156
//#if HAVE_MPI
 
157
    int buffer_size = 0;
 
158
    int rank;
 
159
    MPI_Comm_rank (MPI_COMM_WORLD, &rank);
 
160
    if (rank == 0)
 
161
    {
 
162
//#endif
 
163
        fp = fopen (config_file, "r");
 
164
        if (!fp)
 
165
        {
 
166
            fprintf (stderr, "missing config file %s\n", config_file);
 
167
 
 
168
            return 0;
 
169
        }
 
170
        struct stat s;
 
171
        if (stat (config_file, &s) == 0)
 
172
        {
 
173
            buffer = malloc (s.st_size + 1);
 
174
            buffer [s.st_size] = 0;
 
175
        }
 
176
        if (buffer)
 
177
        {
 
178
            size_t bytes_read = fread (buffer, 1, s.st_size, fp);
 
179
            if (bytes_read != s.st_size)
 
180
            {
 
181
                fprintf (stderr, "error reading config file: %s. Expected %d Got %d\n"
 
182
                        ,config_file, s.st_size, bytes_read );
 
183
 
 
184
                return 0;
 
185
            }
 
186
        }
 
187
        else
 
188
        {
 
189
            fprintf (stderr, "error allocating %d for reading config.\n"
 
190
                    ,s.st_size + 1
 
191
                    );
 
192
 
 
193
            return 0;
 
194
        }
 
195
        fclose (fp);
 
196
//#if HAVE_MPI
 
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);
 
200
    }
 
201
    else
 
202
    {
 
203
        MPI_Bcast (&buffer_size, 1, MPI_INT, 0, MPI_COMM_WORLD);
 
204
        buffer = malloc (buffer_size + 1);
 
205
        if (!buffer)
 
206
        {
 
207
            fprintf (stderr, "cannot allocate %d bytes to receive config file\n"
 
208
                    ,buffer_size + 1
 
209
                    );
 
210
 
 
211
            return 0;
 
212
        }
 
213
        MPI_Bcast (buffer, buffer_size, MPI_BYTE, 0, MPI_COMM_WORLD);
 
214
        buffer [buffer_size] = 0;
 
215
    }
 
216
//#endif
 
217
 
 
218
    doc = mxmlLoadString (NULL, buffer, MXML_TEXT_CALLBACK);
 
219
    free (buffer);
 
220
    buffer = NULL;
 
221
 
 
222
    if (!doc)
 
223
    {
 
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");
 
228
 
 
229
        return 0;
 
230
    }
 
231
 
 
232
    root = doc;
 
233
 
 
234
    while (root && root->type != MXML_ELEMENT)
 
235
    {
 
236
        root = mxmlWalkNext (root, doc, MXML_DESCEND);
 
237
    }
 
238
 
 
239
    while (!strncmp (root->value.element.name, "!--", 3))
 
240
    {
 
241
        root = mxmlWalkNext (root, doc, MXML_NO_DESCEND);
 
242
        root = mxmlWalkNext (root, doc, MXML_NO_DESCEND);
 
243
    }
 
244
 
 
245
    if (strcasecmp (root->value.element.name, "nssi-config"))
 
246
    {
 
247
        if (strncmp (root->value.element.name, "?xml", 4))
 
248
        {
 
249
            fprintf (stderr, "config.xml: invalid root xml element: %s\n"
 
250
                    ,root->value.element.name
 
251
                    );
 
252
 
 
253
            mxmlRelease (doc);
 
254
 
 
255
            return 0;
 
256
        }
 
257
        else
 
258
        {
 
259
            while (!strncmp (root->value.element.name, "!--", 3))
 
260
            {
 
261
                root = mxmlWalkNext (root, doc, MXML_NO_DESCEND);
 
262
            }
 
263
 
 
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))
 
267
            {
 
268
                root = mxmlWalkNext (root, doc, MXML_NO_DESCEND);
 
269
                root = mxmlWalkNext (root, doc, MXML_NO_DESCEND);
 
270
            }
 
271
        }
 
272
    }
 
273
    else
 
274
    {
 
275
        printf("it is nssi-config\n");
 
276
    }
 
277
 
 
278
 
 
279
    for (node = mxmlWalkNext (root, doc, MXML_DESCEND_FIRST)
 
280
        ;node
 
281
        ;node = mxmlWalkNext (node, root, MXML_NO_DESCEND)
 
282
        )
 
283
    {
 
284
        if (node->type != MXML_ELEMENT)
 
285
        {
 
286
            continue;
 
287
        }
 
288
 
 
289
        if (!strcasecmp (node->value.element.name, "staging-group"))
 
290
        {
 
291
            const char *write_type = 0;
 
292
 
 
293
            for (i = 0; i < node->value.element.num_attrs; i++)
 
294
            {
 
295
                mxml_attr_t *attr = &node->value.element.attrs[i];
 
296
 
 
297
                GET_ATTR("write-type",attr,write_type,"var")
 
298
 
 
299
                fprintf (stderr, "config.xml: unknown attribute '%s' on %s "
 
300
                                 "(ignored)\n"
 
301
                        ,attr->name
 
302
                        ,"staging-service"
 
303
                        );
 
304
            }
 
305
 
 
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);
 
321
            }
 
322
 
 
323
            if (!parseGroup(node, config))
 
324
                break;
 
325
            saw_staging_group = 1;
 
326
        }
 
327
        else
 
328
        {
 
329
            if (!strncmp (node->value.element.name, "!--", 3))
 
330
            {
 
331
                continue;
 
332
            }
 
333
            else
 
334
            {
 
335
                fprintf (stderr, "config.xml: invalid element: %s\n"
 
336
                        ,node->value.element.name
 
337
                );
 
338
 
 
339
                break;
 
340
            }
 
341
        }
 
342
    }
 
343
 
 
344
    mxmlRelease (doc);
 
345
 
 
346
    if (!saw_staging_group)
 
347
    {
 
348
        fprintf (stderr, "config.xml: must define at least 1 staging-group in "
 
349
                         "config.xml\n"
 
350
                );
 
351
 
 
352
        return 0;
 
353
    }
 
354
 
 
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",
 
357
//                i,
 
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);
 
362
//    }
 
363
 
 
364
    return 1;
 
365
}
 
366
 
 
367
void free_nssi_config(struct adios_nssi_config *config)
 
368
{
 
369
    if (config->nssi_server_ids) {
 
370
        free(config->nssi_server_ids);
 
371
        config->nssi_server_ids=NULL;
 
372
    }
 
373
}