2008-02-28 04:57:57 +03:00
|
|
|
/* -*- C -*-
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2012-04-06 18:23:13 +04:00
|
|
|
* Copyright (c) 2011 Los Alamos National Security, LLC. All rights
|
|
|
|
* reserved.
|
2008-02-28 04:57:57 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
/** @file:
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* includes
|
|
|
|
*/
|
|
|
|
#include "orte_config.h"
|
|
|
|
|
2009-07-16 22:27:33 +04:00
|
|
|
#ifdef HAVE_STRING_H
|
2009-03-13 05:10:32 +03:00
|
|
|
#include <string.h>
|
|
|
|
#endif
|
2009-07-16 22:27:33 +04:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
2008-02-28 04:57:57 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
2009-07-16 22:27:33 +04:00
|
|
|
#ifdef HAVE_SYS_STAT_H
|
2008-02-28 04:57:57 +03:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
2009-07-16 22:27:33 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2008-02-28 04:57:57 +03:00
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "opal/mca/mca.h"
|
2009-02-14 05:26:12 +03:00
|
|
|
#include "opal/util/output.h"
|
2008-02-28 04:57:57 +03:00
|
|
|
#include "opal/mca/base/mca_base_param.h"
|
|
|
|
|
|
|
|
#include "opal/dss/dss.h"
|
2009-03-13 05:10:32 +03:00
|
|
|
#include "orte/constants.h"
|
|
|
|
#include "orte/types.h"
|
2008-02-28 04:57:57 +03:00
|
|
|
#include "orte/util/proc_info.h"
|
|
|
|
#include "orte/mca/errmgr/errmgr.h"
|
|
|
|
#include "orte/mca/rml/rml.h"
|
2009-02-14 05:26:12 +03:00
|
|
|
#include "orte/mca/rml/rml_types.h"
|
2012-04-06 18:23:13 +04:00
|
|
|
#include "orte/mca/state/state.h"
|
2008-02-28 04:57:57 +03:00
|
|
|
#include "orte/util/name_fns.h"
|
|
|
|
#include "orte/runtime/orte_globals.h"
|
2010-07-18 01:03:27 +04:00
|
|
|
#include "orte/runtime/orte_quit.h"
|
2008-02-28 04:57:57 +03:00
|
|
|
|
|
|
|
#include "orte/mca/filem/filem.h"
|
|
|
|
#include "orte/mca/filem/base/base.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Functions to process some FileM specific commands
|
|
|
|
*/
|
|
|
|
static void filem_base_process_get_proc_node_name_cmd(orte_process_name_t* sender,
|
|
|
|
opal_buffer_t* buffer);
|
|
|
|
static void filem_base_process_get_remote_path_cmd(orte_process_name_t* sender,
|
|
|
|
opal_buffer_t* buffer);
|
|
|
|
|
|
|
|
static bool recv_issued=false;
|
|
|
|
|
|
|
|
int orte_filem_base_comm_start(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2008-03-05 07:57:23 +03:00
|
|
|
/* Only active in HNP and daemons */
|
2009-05-04 15:07:40 +04:00
|
|
|
if( !ORTE_PROC_IS_HNP && !ORTE_PROC_IS_DAEMON ) {
|
2008-03-05 07:57:23 +03:00
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
if ( recv_issued ) {
|
2008-02-28 04:57:57 +03:00
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-06-09 18:53:58 +04:00
|
|
|
OPAL_OUTPUT_VERBOSE((5, orte_filem_base_output,
|
2008-02-28 04:57:57 +03:00
|
|
|
"%s filem:base: Receive: Start command recv",
|
2009-03-06 00:50:47 +03:00
|
|
|
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
|
2008-02-28 04:57:57 +03:00
|
|
|
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_rml.recv_buffer_nb(ORTE_NAME_WILDCARD,
|
|
|
|
ORTE_RML_TAG_FILEM_BASE,
|
|
|
|
ORTE_RML_PERSISTENT,
|
|
|
|
orte_filem_base_recv,
|
|
|
|
NULL))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
recv_issued = true;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int orte_filem_base_comm_stop(void)
|
|
|
|
{
|
|
|
|
int rc;
|
2008-03-05 07:57:23 +03:00
|
|
|
|
|
|
|
/* Only active in HNP and daemons */
|
2009-05-04 15:07:40 +04:00
|
|
|
if( !ORTE_PROC_IS_HNP && !ORTE_PROC_IS_DAEMON ) {
|
2008-03-05 07:57:23 +03:00
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
if ( recv_issued ) {
|
2008-02-28 04:57:57 +03:00
|
|
|
return ORTE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-06-09 18:53:58 +04:00
|
|
|
OPAL_OUTPUT_VERBOSE((5, orte_filem_base_output,
|
2008-02-28 04:57:57 +03:00
|
|
|
"%s filem:base:receive stop comm",
|
2009-03-06 00:50:47 +03:00
|
|
|
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
|
2008-02-28 04:57:57 +03:00
|
|
|
|
|
|
|
if (ORTE_SUCCESS != (rc = orte_rml.recv_cancel(ORTE_NAME_WILDCARD, ORTE_RML_TAG_FILEM_BASE))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
}
|
|
|
|
recv_issued = false;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handle message from proxies
|
|
|
|
* NOTE: The incoming buffer "buffer" is OBJ_RELEASED by the calling program.
|
|
|
|
* DO NOT RELEASE THIS BUFFER IN THIS CODE
|
|
|
|
*/
|
|
|
|
void orte_filem_base_recv(int status, orte_process_name_t* sender,
|
|
|
|
opal_buffer_t* buffer, orte_rml_tag_t tag,
|
|
|
|
void* cbdata)
|
|
|
|
{
|
|
|
|
orte_filem_cmd_flag_t command;
|
|
|
|
orte_std_cntr_t count;
|
|
|
|
int rc;
|
|
|
|
|
2008-06-09 18:53:58 +04:00
|
|
|
OPAL_OUTPUT_VERBOSE((5, orte_filem_base_output,
|
2008-02-28 04:57:57 +03:00
|
|
|
"%s filem:base: Receive a command message.",
|
2009-03-06 00:50:47 +03:00
|
|
|
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
|
2008-02-28 04:57:57 +03:00
|
|
|
|
|
|
|
count = 1;
|
|
|
|
if (ORTE_SUCCESS != (rc = opal_dss.unpack(buffer, &command, &count, ORTE_FILEM_CMD))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (command) {
|
|
|
|
case ORTE_FILEM_GET_PROC_NODE_NAME_CMD:
|
2008-06-09 18:53:58 +04:00
|
|
|
OPAL_OUTPUT_VERBOSE((10, orte_filem_base_output,
|
2008-02-28 04:57:57 +03:00
|
|
|
"%s filem:base: Command: Get Proc node name command",
|
2009-03-06 00:50:47 +03:00
|
|
|
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
|
2008-02-28 04:57:57 +03:00
|
|
|
|
|
|
|
filem_base_process_get_proc_node_name_cmd(sender, buffer);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ORTE_FILEM_GET_REMOTE_PATH_CMD:
|
2008-06-09 18:53:58 +04:00
|
|
|
OPAL_OUTPUT_VERBOSE((10, orte_filem_base_output,
|
2008-02-28 04:57:57 +03:00
|
|
|
"%s filem:base: Command: Get remote path command",
|
2009-03-06 00:50:47 +03:00
|
|
|
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
|
2008-02-28 04:57:57 +03:00
|
|
|
|
|
|
|
filem_base_process_get_remote_path_cmd(sender, buffer);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_VALUE_OUT_OF_BOUNDS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void filem_base_process_get_proc_node_name_cmd(orte_process_name_t* sender,
|
|
|
|
opal_buffer_t* buffer)
|
|
|
|
{
|
|
|
|
opal_buffer_t answer;
|
|
|
|
orte_std_cntr_t count;
|
|
|
|
orte_job_t *jdata = NULL;
|
|
|
|
orte_proc_t **procs = NULL;
|
|
|
|
orte_process_name_t name;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
OBJ_CONSTRUCT(&answer, opal_buffer_t);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unpack the data
|
|
|
|
*/
|
|
|
|
count = 1;
|
|
|
|
if (ORTE_SUCCESS != (rc = opal_dss.unpack(buffer, &name, &count, ORTE_NAME))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
2012-04-06 18:23:13 +04:00
|
|
|
ORTE_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
|
2008-02-28 04:57:57 +03:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the data
|
|
|
|
*/
|
|
|
|
/* get the job data object for this proc */
|
|
|
|
if (NULL == (jdata = orte_get_job_data_object(name.jobid))) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_NOT_FOUND);
|
2012-04-06 18:23:13 +04:00
|
|
|
ORTE_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
|
2008-02-28 04:57:57 +03:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
/* get the proc object for it */
|
|
|
|
procs = (orte_proc_t**)jdata->procs->addr;
|
|
|
|
if (NULL == procs[name.vpid] || NULL == procs[name.vpid]->node) {
|
|
|
|
ORTE_ERROR_LOG(ORTE_ERR_NOT_FOUND);
|
2012-04-06 18:23:13 +04:00
|
|
|
ORTE_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
|
2008-02-28 04:57:57 +03:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send back the answer
|
|
|
|
*/
|
|
|
|
if (ORTE_SUCCESS != (rc = opal_dss.pack(&answer, &(procs[name.vpid]->node->name), 1, OPAL_STRING))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
2012-04-06 18:23:13 +04:00
|
|
|
ORTE_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
|
2008-02-28 04:57:57 +03:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 > (rc = orte_rml.send_buffer(sender, &answer, ORTE_RML_TAG_FILEM_BASE_RESP, 0))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
2012-04-06 18:23:13 +04:00
|
|
|
ORTE_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
|
2008-02-28 04:57:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CLEANUP:
|
|
|
|
OBJ_DESTRUCT(&answer);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is responsible for:
|
|
|
|
* - Constructing the remote absolute path for the specified file/dir
|
|
|
|
* - Verify the existence of the file/dir
|
|
|
|
* - Determine if the specified file/dir is in fact a file or dir or unknown if not found.
|
|
|
|
*/
|
|
|
|
static void filem_base_process_get_remote_path_cmd(orte_process_name_t* sender,
|
|
|
|
opal_buffer_t* buffer)
|
|
|
|
{
|
|
|
|
opal_buffer_t answer;
|
|
|
|
orte_std_cntr_t count;
|
|
|
|
char *filename = NULL;
|
|
|
|
char *tmp_name = NULL;
|
2009-05-07 00:11:28 +04:00
|
|
|
char cwd[OPAL_PATH_MAX];
|
2008-02-28 04:57:57 +03:00
|
|
|
int file_type = ORTE_FILEM_TYPE_UNKNOWN;
|
|
|
|
struct stat file_status;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unpack the data
|
|
|
|
*/
|
|
|
|
OBJ_CONSTRUCT(&answer, opal_buffer_t);
|
|
|
|
|
|
|
|
count = 1;
|
|
|
|
if (ORTE_SUCCESS != (rc = opal_dss.unpack(buffer, &filename, &count, OPAL_STRING))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
2012-04-06 18:23:13 +04:00
|
|
|
ORTE_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
|
2008-02-28 04:57:57 +03:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine the absolute path of the file
|
|
|
|
*/
|
|
|
|
if(filename[0] != '/') { /* if it is not an absolute path already */
|
|
|
|
getcwd(cwd, sizeof(cwd));
|
|
|
|
asprintf(&tmp_name, "%s/%s", cwd, filename);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tmp_name = strdup(filename);
|
|
|
|
}
|
|
|
|
|
2008-06-09 18:53:58 +04:00
|
|
|
opal_output_verbose(10, orte_filem_base_output,
|
2008-02-28 04:57:57 +03:00
|
|
|
"filem:base: process_get_remote_path_cmd: %s -> %s: Filename Requested (%s) translated to (%s)",
|
2009-03-06 00:50:47 +03:00
|
|
|
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
|
|
|
|
ORTE_NAME_PRINT(sender),
|
2008-02-28 04:57:57 +03:00
|
|
|
filename, tmp_name);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine if the file/dir exists at that absolute path
|
|
|
|
* Determine if the file/dir is a file or a directory
|
|
|
|
*/
|
|
|
|
if(0 != (rc = stat(tmp_name, &file_status) ) ){
|
|
|
|
file_type = ORTE_FILEM_TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Is it a directory? */
|
|
|
|
if(S_ISDIR(file_status.st_mode)) {
|
|
|
|
file_type = ORTE_FILEM_TYPE_DIR;
|
|
|
|
}
|
|
|
|
else if(S_ISREG(file_status.st_mode)) {
|
|
|
|
file_type = ORTE_FILEM_TYPE_FILE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pack up the response
|
|
|
|
* Send back the reference type
|
|
|
|
* - ORTE_FILEM_TYPE_FILE = File
|
|
|
|
* - ORTE_FILEM_TYPE_DIR = Directory
|
|
|
|
* - ORTE_FILEM_TYPE_UNKNOWN = Could not be determined, or does not exist
|
|
|
|
*/
|
|
|
|
if (ORTE_SUCCESS != (rc = opal_dss.pack(&answer, &tmp_name, 1, OPAL_STRING))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
2012-04-06 18:23:13 +04:00
|
|
|
ORTE_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
|
2008-02-28 04:57:57 +03:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
if (ORTE_SUCCESS != (rc = opal_dss.pack(&answer, &file_type, 1, OPAL_INT))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
2012-04-06 18:23:13 +04:00
|
|
|
ORTE_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
|
2008-02-28 04:57:57 +03:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 > (rc = orte_rml.send_buffer(sender, &answer, ORTE_RML_TAG_FILEM_BASE_RESP, 0))) {
|
|
|
|
ORTE_ERROR_LOG(rc);
|
2012-04-06 18:23:13 +04:00
|
|
|
ORTE_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
|
2008-02-28 04:57:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CLEANUP:
|
|
|
|
if( NULL != filename) {
|
|
|
|
free(filename);
|
|
|
|
filename = NULL;
|
|
|
|
}
|
|
|
|
if( NULL != tmp_name) {
|
|
|
|
free(tmp_name);
|
|
|
|
tmp_name = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
OBJ_DESTRUCT(&answer);
|
|
|
|
}
|