2005-03-14 20:57:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of the University of Tennessee.
|
|
|
|
* All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 12:43:37 +00:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2005-03-14 20:57:21 +00:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
#include "orte_config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "include/orte_constants.h"
|
|
|
|
#include "mca/base/mca_base_param.h"
|
2005-05-16 21:01:09 +00:00
|
|
|
#include "mca/errmgr/errmgr.h"
|
|
|
|
#include "mca/ns/ns.h"
|
2005-03-14 20:57:21 +00:00
|
|
|
|
2005-06-21 22:48:57 +00:00
|
|
|
#include "mca/rds/resfile/rds_resfile.h"
|
2005-03-14 20:57:21 +00:00
|
|
|
|
2005-05-16 21:01:09 +00:00
|
|
|
#define ORTE_RDS_RESFILE_MAX_LINE_LENGTH 512
|
|
|
|
|
2005-07-03 16:22:16 +00:00
|
|
|
static opal_list_t orte_rds_resfile_resource_list;
|
2005-05-16 21:01:09 +00:00
|
|
|
|
|
|
|
static int orte_rds_resfile_parse_site(char *site, FILE *fp);
|
|
|
|
|
|
|
|
static int orte_rds_resfile_parse_resource(orte_rds_cell_desc_t *cell, FILE *fp);
|
|
|
|
|
|
|
|
static int orte_rds_resfile_parse_resource(orte_rds_cell_desc_t *cell, FILE *fp)
|
2005-03-14 20:57:21 +00:00
|
|
|
{
|
2005-05-16 21:01:09 +00:00
|
|
|
char *line;
|
|
|
|
bool name_given = false;
|
|
|
|
int rc;
|
|
|
|
orte_rds_cell_attr_t *na;
|
|
|
|
|
|
|
|
while (NULL != (line = orte_rds_resfile_getline(fp))) {
|
|
|
|
/* check for end of resource description */
|
|
|
|
if (0 == strncmp(line, "</resource", strlen("</resource"))) {
|
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
/* check for attribute and redirect to proper parser */
|
|
|
|
if (0 == strncmp(line, "<name", strlen("<name"))) {
|
|
|
|
/* check to ensure only ONE name is given */
|
|
|
|
if (name_given) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_BAD_PARAM);
|
|
|
|
return ORTE_ERR_BAD_PARAM;
|
|
|
|
}
|
|
|
|
name_given = true;
|
|
|
|
if (NULL == (cell->name = orte_rds_resfile_parse_field(line))) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_READ_FAILURE);
|
|
|
|
return ORTE_ERR_FILE_READ_FAILURE;
|
|
|
|
}
|
|
|
|
/* get new cellid for this site/resource */
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_ns.create_cellid(&(cell->cellid), cell->site, cell->name))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
na = OBJ_NEW(orte_rds_cell_attr_t);
|
|
|
|
if (NULL == na) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
|
|
|
|
return ORTE_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
na->keyval.key = strdup(ORTE_RDS_NAME);
|
|
|
|
na->keyval.type = ORTE_STRING;
|
|
|
|
na->keyval.value.strptr = strdup(cell->name);
|
2005-07-03 16:22:16 +00:00
|
|
|
opal_list_append(&(cell->attributes), &na->super);
|
2005-05-16 21:01:09 +00:00
|
|
|
na = OBJ_NEW(orte_rds_cell_attr_t);
|
|
|
|
if (NULL == na) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
|
|
|
|
return ORTE_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
na->keyval.key = strdup(ORTE_CELLID_KEY);
|
|
|
|
na->keyval.type = ORTE_CELLID;
|
|
|
|
na->keyval.value.cellid = cell->cellid;
|
2005-07-03 16:22:16 +00:00
|
|
|
opal_list_append(&(cell->attributes), &na->super);
|
2005-05-16 21:01:09 +00:00
|
|
|
} else if (0 == strncmp(line, "<type", strlen("<type"))) {
|
|
|
|
if (NULL == (cell->type = orte_rds_resfile_parse_field(line))) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_READ_FAILURE);
|
|
|
|
return ORTE_ERR_FILE_READ_FAILURE;
|
|
|
|
}
|
|
|
|
na = OBJ_NEW(orte_rds_cell_attr_t);
|
|
|
|
if (NULL == na) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
|
|
|
|
return ORTE_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
na->keyval.key = strdup(ORTE_RDS_TYPE);
|
|
|
|
na->keyval.type = ORTE_STRING;
|
|
|
|
na->keyval.value.strptr = strdup(cell->type);
|
2005-07-03 16:22:16 +00:00
|
|
|
opal_list_append(&(cell->attributes), &na->super);
|
2005-05-16 21:01:09 +00:00
|
|
|
} else if (0 == strncmp(line, "<front-end", strlen("<front-end"))) {
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_rds_resfile_parse_fe(cell, fp))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
} else if (0 == strncmp(line, "<compute-domains", strlen("<compute-domains"))) {
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_rds_resfile_parse_cd(cell, fp))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
} else if (0 == strncmp(line, "<os", strlen("<os"))) {
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_rds_resfile_parse_os(cell, fp))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
} else if (0 == strncmp(line, "<filesystem", strlen("<filesystem"))) {
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_rds_resfile_parse_fs(cell, fp))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
} else if (0 == strncmp(line, "<allocator", strlen("<allocator"))) {
|
|
|
|
na = OBJ_NEW(orte_rds_cell_attr_t);
|
|
|
|
if (NULL == na) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
|
|
|
|
return ORTE_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
na->keyval.key = strdup(ORTE_RDS_ALLOCATOR);
|
|
|
|
na->keyval.type = ORTE_STRING;
|
|
|
|
if (NULL == (na->keyval.value.strptr = orte_rds_resfile_parse_field(line))) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_READ_FAILURE);
|
|
|
|
return ORTE_ERR_FILE_READ_FAILURE;
|
|
|
|
}
|
2005-07-03 16:22:16 +00:00
|
|
|
opal_list_append(&(cell->attributes), &na->super);
|
2005-05-16 21:01:09 +00:00
|
|
|
} else if (0 == strncmp(line, "<launcher", strlen("<launcher"))) {
|
|
|
|
na = OBJ_NEW(orte_rds_cell_attr_t);
|
|
|
|
if (NULL == na) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
|
|
|
|
return ORTE_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
na->keyval.key = strdup(ORTE_RDS_LAUNCHER);
|
|
|
|
na->keyval.type = ORTE_STRING;
|
|
|
|
if (NULL == (na->keyval.value.strptr = orte_rds_resfile_parse_field(line))) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_READ_FAILURE);
|
|
|
|
return ORTE_ERR_FILE_READ_FAILURE;
|
|
|
|
}
|
2005-07-03 16:22:16 +00:00
|
|
|
opal_list_append(&(cell->attributes), &na->super);
|
2005-05-16 21:01:09 +00:00
|
|
|
} else if (0 == strncmp(line, "<sequence", strlen("<sequence"))) {
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_rds_resfile_parse_se(cell, fp))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
} else if (0 == strncmp(line, "<arch", strlen("<arch"))) {
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_rds_resfile_parse_na(cell, fp))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
2005-03-14 20:57:21 +00:00
|
|
|
}
|
|
|
|
}
|
2005-05-16 21:01:09 +00:00
|
|
|
return ORTE_SUCCESS;
|
2005-03-14 20:57:21 +00:00
|
|
|
}
|
|
|
|
|
2005-05-16 21:01:09 +00:00
|
|
|
|
|
|
|
static int orte_rds_resfile_parse_site(char *site, FILE *fp)
|
2005-03-14 20:57:21 +00:00
|
|
|
{
|
2005-05-16 21:01:09 +00:00
|
|
|
char *line;
|
|
|
|
orte_rds_cell_desc_t *cell;
|
|
|
|
int rc;
|
2005-03-14 20:57:21 +00:00
|
|
|
|
2005-05-16 21:01:09 +00:00
|
|
|
while (NULL != (line = orte_rds_resfile_getline(fp))) {
|
|
|
|
if (0 == strncmp(line, "<resource", strlen("<resource"))) {
|
|
|
|
cell = OBJ_NEW(orte_rds_cell_desc_t);
|
|
|
|
if (NULL == cell) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
|
|
|
|
return ORTE_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
cell->site = strdup(site);
|
|
|
|
/* parse the resource description */
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_rds_resfile_parse_resource(cell, fp))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-07-03 16:22:16 +00:00
|
|
|
opal_list_append(&orte_rds_resfile_resource_list, &cell->super);
|
2005-03-14 20:57:21 +00:00
|
|
|
}
|
|
|
|
}
|
2005-05-16 21:01:09 +00:00
|
|
|
return ORTE_SUCCESS;
|
2005-03-14 20:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int orte_rds_resfile_query(void)
|
|
|
|
{
|
2005-05-16 21:01:09 +00:00
|
|
|
int fileid, rc;
|
|
|
|
FILE *fp;
|
2005-08-10 21:05:13 +00:00
|
|
|
char *input_line, *site;
|
2005-03-14 20:57:21 +00:00
|
|
|
|
2005-07-03 22:45:48 +00:00
|
|
|
OPAL_LOCK(&mca_rds_resfile_component.lock);
|
2005-03-14 20:57:21 +00:00
|
|
|
|
2005-05-23 14:22:35 +00:00
|
|
|
if (orte_rds_resfile_queried) {
|
2005-07-03 22:45:48 +00:00
|
|
|
OPAL_UNLOCK(&mca_rds_resfile_component.lock);
|
2005-05-23 14:22:35 +00:00
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
orte_rds_resfile_queried = true;
|
|
|
|
|
2005-03-14 20:57:21 +00:00
|
|
|
/* get the resource filename */
|
2005-08-10 21:05:13 +00:00
|
|
|
fileid = mca_base_param_find("rds", "resfile", "name");
|
|
|
|
mca_base_param_lookup_string(fileid, &mca_rds_resfile_component.filename);
|
|
|
|
|
|
|
|
if (NULL == mca_rds_resfile_component.filename) { /* no resource file provided */
|
2005-05-16 21:01:09 +00:00
|
|
|
/* DO NOT ORTE_ERROR_LOG OR RETURN AN ERROR - THIS IS NOT AN ERROR CONDITION */
|
2005-07-03 22:45:48 +00:00
|
|
|
OPAL_UNLOCK(&mca_rds_resfile_component.lock);
|
2005-05-16 21:01:09 +00:00
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
2005-03-14 20:57:21 +00:00
|
|
|
|
2005-05-16 21:01:09 +00:00
|
|
|
/* open the resource file */
|
2005-08-10 21:05:13 +00:00
|
|
|
fp = fopen(mca_rds_resfile_component.filename, "r");
|
2005-05-16 21:01:09 +00:00
|
|
|
if (NULL == fp) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_NOT_FOUND);
|
2005-07-03 22:45:48 +00:00
|
|
|
OPAL_UNLOCK(&mca_rds_resfile_component.lock);
|
2005-05-16 21:01:09 +00:00
|
|
|
return ORTE_ERR_NOT_FOUND;
|
2005-03-14 20:57:21 +00:00
|
|
|
}
|
2005-05-16 21:01:09 +00:00
|
|
|
|
|
|
|
/* setup the resource list */
|
2005-07-03 16:22:16 +00:00
|
|
|
OBJ_CONSTRUCT(&orte_rds_resfile_resource_list, opal_list_t);
|
2005-05-16 21:01:09 +00:00
|
|
|
|
|
|
|
/* dump the initial line containing the DOM */
|
|
|
|
input_line = orte_rds_resfile_getline(fp);
|
|
|
|
if (NULL == input_line || 0 != strncmp(input_line, "<?xml", 5)) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_READ_FAILURE);
|
|
|
|
rc = ORTE_ERR_FILE_READ_FAILURE;
|
|
|
|
goto CLEANUP;
|
2005-03-14 20:57:21 +00:00
|
|
|
}
|
2005-05-16 21:01:09 +00:00
|
|
|
free(input_line);
|
2005-03-14 20:57:21 +00:00
|
|
|
|
2005-05-16 21:01:09 +00:00
|
|
|
/* parse file */
|
|
|
|
while (NULL != (input_line = orte_rds_resfile_getline(fp))) {
|
|
|
|
if (0 == strncmp(input_line, "<site-name>", strlen("<site-name>"))) {
|
|
|
|
/* extract the site name from input_line */
|
|
|
|
if (NULL == (site = orte_rds_resfile_parse_field(input_line))) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_READ_FAILURE);
|
|
|
|
free(input_line);
|
|
|
|
rc = ORTE_ERR_FILE_READ_FAILURE;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_rds_resfile_parse_site(site, fp))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
free(input_line);
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(input_line);
|
|
|
|
}
|
2005-03-14 20:57:21 +00:00
|
|
|
|
2005-05-16 21:01:09 +00:00
|
|
|
/* place resource list on registry */
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_rds_base_store_resource(&orte_rds_resfile_resource_list))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
CLEANUP:
|
|
|
|
fclose(fp);
|
|
|
|
OBJ_DESTRUCT(&orte_rds_resfile_resource_list);
|
|
|
|
|
2005-07-03 22:45:48 +00:00
|
|
|
OPAL_UNLOCK(&mca_rds_resfile_component.lock);
|
2005-03-14 20:57:21 +00:00
|
|
|
|
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int orte_rds_resfile_finalize(void)
|
|
|
|
{
|
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
2005-05-16 21:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
char *orte_rds_resfile_getline(FILE *fp)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *ret, *buff, *start;
|
|
|
|
char input[ORTE_RDS_RESFILE_MAX_LINE_LENGTH];
|
|
|
|
|
|
|
|
/* find the next non-blank line, stop at end-of-file */
|
|
|
|
ret = fgets(input, ORTE_RDS_RESFILE_MAX_LINE_LENGTH, fp);
|
|
|
|
while (NULL != ret) {
|
|
|
|
input[strlen(input)-1] = '\0'; /* remove newline */
|
|
|
|
/* strip leading whitespace */
|
|
|
|
for (i=0; i < (int)strlen(input) && (input[i] == ' ' || input[i] == '\t'); i++);
|
|
|
|
if (i < (int)strlen(input)) {
|
|
|
|
start = &input[i];
|
|
|
|
buff = strdup(start);
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
ret = fgets(input, ORTE_RDS_RESFILE_MAX_LINE_LENGTH, fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *orte_rds_resfile_parse_field(char *input)
|
|
|
|
{
|
|
|
|
char *start, *stop, *ans;
|
|
|
|
|
|
|
|
start = strchr(input, '>');
|
|
|
|
if (NULL == start) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_READ_FAILURE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
start++;
|
|
|
|
stop = strchr(start, '<');
|
|
|
|
if (NULL == stop) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_FILE_READ_FAILURE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*stop = '\0'; /* terminate the string */
|
|
|
|
|
|
|
|
if (start == stop) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ans = strdup(start);
|
|
|
|
return ans;
|
|
|
|
}
|