root/orte/mca/filem/base/filem_base_receive.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. orte_filem_base_comm_start
  2. orte_filem_base_comm_stop
  3. orte_filem_base_recv
  4. filem_base_process_get_proc_node_name_cmd
  5. filem_base_process_get_remote_path_cmd

   1 /* -*- C -*-
   2  *
   3  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2005 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2011-2012 Los Alamos National Security, LLC.  All rights
  14  *                         reserved.
  15  * Copyright (c) 2016-2019 Intel, Inc.  All rights reserved.
  16  * $COPYRIGHT$
  17  *
  18  * Additional copyrights may follow
  19  *
  20  * $HEADER$
  21  */
  22 /** @file:
  23  *
  24  */
  25 
  26 /*
  27  * includes
  28  */
  29 #include "orte_config.h"
  30 
  31 #include <string.h>
  32 #ifdef HAVE_SYS_TYPES_H
  33 #include <sys/types.h>
  34 #endif
  35 #ifdef HAVE_SYS_STAT_H
  36 #include <sys/stat.h>
  37 #endif
  38 #ifdef HAVE_UNISTD_H
  39 #include <unistd.h>
  40 #endif
  41 
  42 #include "orte/mca/mca.h"
  43 #include "opal/util/output.h"
  44 #include "opal/util/printf.h"
  45 
  46 #include "opal/dss/dss.h"
  47 #include "orte/constants.h"
  48 #include "orte/types.h"
  49 #include "orte/util/proc_info.h"
  50 #include "orte/mca/errmgr/errmgr.h"
  51 #include "orte/mca/rml/rml.h"
  52 #include "orte/mca/rml/rml_types.h"
  53 #include "orte/mca/state/state.h"
  54 #include "orte/util/name_fns.h"
  55 #include "orte/runtime/orte_globals.h"
  56 #include "orte/runtime/orte_quit.h"
  57 
  58 #include "orte/mca/filem/filem.h"
  59 #include "orte/mca/filem/base/base.h"
  60 
  61 /*
  62  * Functions to process some FileM specific commands
  63  */
  64 static void filem_base_process_get_proc_node_name_cmd(orte_process_name_t* sender,
  65                                                       opal_buffer_t* buffer);
  66 static void filem_base_process_get_remote_path_cmd(orte_process_name_t* sender,
  67                                                    opal_buffer_t* buffer);
  68 
  69 static bool recv_issued=false;
  70 
  71 int orte_filem_base_comm_start(void)
  72 {
  73     /* Only active in HNP and daemons */
  74     if( !ORTE_PROC_IS_HNP && !ORTE_PROC_IS_DAEMON ) {
  75         return ORTE_SUCCESS;
  76     }
  77     if ( recv_issued ) {
  78         return ORTE_SUCCESS;
  79     }
  80 
  81     OPAL_OUTPUT_VERBOSE((5, orte_filem_base_framework.framework_output,
  82                          "%s filem:base: Receive: Start command recv",
  83                          ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
  84 
  85     orte_rml.recv_buffer_nb(ORTE_NAME_WILDCARD,
  86                             ORTE_RML_TAG_FILEM_BASE,
  87                             ORTE_RML_PERSISTENT,
  88                             orte_filem_base_recv,
  89                             NULL);
  90 
  91     recv_issued = true;
  92 
  93     return ORTE_SUCCESS;
  94 }
  95 
  96 
  97 int orte_filem_base_comm_stop(void)
  98 {
  99     /* Only active in HNP and daemons */
 100     if( !ORTE_PROC_IS_HNP && !ORTE_PROC_IS_DAEMON ) {
 101         return ORTE_SUCCESS;
 102     }
 103     if ( recv_issued ) {
 104         return ORTE_SUCCESS;
 105     }
 106 
 107     OPAL_OUTPUT_VERBOSE((5, orte_filem_base_framework.framework_output,
 108                          "%s filem:base:receive stop comm",
 109                          ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
 110 
 111     orte_rml.recv_cancel(ORTE_NAME_WILDCARD, ORTE_RML_TAG_FILEM_BASE);
 112     recv_issued = false;
 113 
 114     return ORTE_SUCCESS;
 115 }
 116 
 117 
 118 /*
 119  * handle message from proxies
 120  * NOTE: The incoming buffer "buffer" is OBJ_RELEASED by the calling program.
 121  * DO NOT RELEASE THIS BUFFER IN THIS CODE
 122  */
 123 void orte_filem_base_recv(int status, orte_process_name_t* sender,
 124                         opal_buffer_t* buffer, orte_rml_tag_t tag,
 125                         void* cbdata)
 126 {
 127     orte_filem_cmd_flag_t command;
 128     orte_std_cntr_t count;
 129     int rc;
 130 
 131     OPAL_OUTPUT_VERBOSE((5, orte_filem_base_framework.framework_output,
 132                          "%s filem:base: Receive a command message.",
 133                          ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
 134 
 135     count = 1;
 136     if (ORTE_SUCCESS != (rc = opal_dss.unpack(buffer, &command, &count, ORTE_FILEM_CMD))) {
 137         ORTE_ERROR_LOG(rc);
 138         return;
 139     }
 140 
 141     switch (command) {
 142         case ORTE_FILEM_GET_PROC_NODE_NAME_CMD:
 143             OPAL_OUTPUT_VERBOSE((10, orte_filem_base_framework.framework_output,
 144                                  "%s filem:base: Command: Get Proc node name command",
 145                                  ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
 146 
 147             filem_base_process_get_proc_node_name_cmd(sender, buffer);
 148             break;
 149 
 150         case ORTE_FILEM_GET_REMOTE_PATH_CMD:
 151             OPAL_OUTPUT_VERBOSE((10, orte_filem_base_framework.framework_output,
 152                                  "%s filem:base: Command: Get remote path command",
 153                                  ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)));
 154 
 155             filem_base_process_get_remote_path_cmd(sender, buffer);
 156             break;
 157 
 158         default:
 159             ORTE_ERROR_LOG(ORTE_ERR_VALUE_OUT_OF_BOUNDS);
 160     }
 161 }
 162 
 163 static void filem_base_process_get_proc_node_name_cmd(orte_process_name_t* sender,
 164                                                       opal_buffer_t* buffer)
 165 {
 166     opal_buffer_t *answer;
 167     orte_std_cntr_t count;
 168     orte_job_t *jdata = NULL;
 169     orte_proc_t *proc = NULL;
 170     orte_process_name_t name;
 171     int rc;
 172 
 173     /*
 174      * Unpack the data
 175      */
 176     count = 1;
 177     if (ORTE_SUCCESS != (rc = opal_dss.unpack(buffer, &name, &count, ORTE_NAME))) {
 178         ORTE_ERROR_LOG(rc);
 179         ORTE_FORCED_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
 180         return;
 181     }
 182 
 183     /*
 184      * Process the data
 185      */
 186     /* get the job data object for this proc */
 187     if (NULL == (jdata = orte_get_job_data_object(name.jobid))) {
 188         ORTE_ERROR_LOG(ORTE_ERR_NOT_FOUND);
 189         ORTE_FORCED_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
 190         return;
 191     }
 192     /* get the proc object for it */
 193     proc = (orte_proc_t*)opal_pointer_array_get_item(jdata->procs, name.vpid);
 194     if (NULL == proc || NULL == proc->node) {
 195         ORTE_ERROR_LOG(ORTE_ERR_NOT_FOUND);
 196         ORTE_FORCED_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
 197         return;
 198     }
 199 
 200     /*
 201      * Send back the answer
 202      */
 203     answer = OBJ_NEW(opal_buffer_t);
 204     if (ORTE_SUCCESS != (rc = opal_dss.pack(answer, &(proc->node->name), 1, OPAL_STRING))) {
 205         ORTE_ERROR_LOG(rc);
 206         ORTE_FORCED_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
 207         OBJ_RELEASE(answer);
 208         return;
 209     }
 210 
 211     if (0 > (rc = orte_rml.send_buffer_nb(sender, answer,
 212                                           ORTE_RML_TAG_FILEM_BASE_RESP,
 213                                           orte_rml_send_callback, NULL))) {
 214         ORTE_ERROR_LOG(rc);
 215         ORTE_FORCED_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
 216         OBJ_RELEASE(answer);
 217         return;
 218     }
 219 }
 220 
 221 /*
 222  * This function is responsible for:
 223  * - Constructing the remote absolute path for the specified file/dir
 224  * - Verify the existence of the file/dir
 225  * - Determine if the specified file/dir is in fact a file or dir or unknown if not found.
 226  */
 227 static void filem_base_process_get_remote_path_cmd(orte_process_name_t* sender,
 228                                                    opal_buffer_t* buffer)
 229 {
 230     opal_buffer_t *answer;
 231     orte_std_cntr_t count;
 232     char *filename = NULL;
 233     char *tmp_name = NULL;
 234     char cwd[OPAL_PATH_MAX];
 235     int file_type = ORTE_FILEM_TYPE_UNKNOWN;
 236     struct stat file_status;
 237     int rc;
 238 
 239     count = 1;
 240     if (ORTE_SUCCESS != (rc = opal_dss.unpack(buffer, &filename, &count, OPAL_STRING))) {
 241         ORTE_ERROR_LOG(rc);
 242         ORTE_FORCED_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
 243         goto CLEANUP;
 244     }
 245 
 246     /*
 247      * Determine the absolute path of the file
 248      */
 249     if (filename[0] != '/') { /* if it is not an absolute path already */
 250         if (NULL == getcwd(cwd, sizeof(cwd))) {
 251             return;
 252         }
 253         opal_asprintf(&tmp_name, "%s/%s", cwd, filename);
 254     }
 255     else {
 256         tmp_name = strdup(filename);
 257     }
 258 
 259     opal_output_verbose(10, orte_filem_base_framework.framework_output,
 260                         "filem:base: process_get_remote_path_cmd: %s -> %s: Filename Requested (%s) translated to (%s)",
 261                         ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
 262                         ORTE_NAME_PRINT(sender),
 263                         filename, tmp_name);
 264 
 265     /*
 266      * Determine if the file/dir exists at that absolute path
 267      * Determine if the file/dir is a file or a directory
 268      */
 269     if (0 != (rc = stat(tmp_name, &file_status) ) ){
 270         file_type = ORTE_FILEM_TYPE_UNKNOWN;
 271     }
 272     else {
 273         /* Is it a directory? */
 274         if(S_ISDIR(file_status.st_mode)) {
 275             file_type = ORTE_FILEM_TYPE_DIR;
 276         }
 277         else if(S_ISREG(file_status.st_mode)) {
 278             file_type = ORTE_FILEM_TYPE_FILE;
 279         }
 280     }
 281 
 282     /*
 283      * Pack up the response
 284      * Send back the reference type
 285      * - ORTE_FILEM_TYPE_FILE    = File
 286      * - ORTE_FILEM_TYPE_DIR     = Directory
 287      * - ORTE_FILEM_TYPE_UNKNOWN = Could not be determined, or does not exist
 288      */
 289     answer = OBJ_NEW(opal_buffer_t);
 290     if (ORTE_SUCCESS != (rc = opal_dss.pack(answer, &tmp_name, 1, OPAL_STRING))) {
 291         ORTE_ERROR_LOG(rc);
 292         ORTE_FORCED_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
 293         OBJ_RELEASE(answer);
 294         goto CLEANUP;
 295     }
 296     if (ORTE_SUCCESS != (rc = opal_dss.pack(answer, &file_type, 1, OPAL_INT))) {
 297         ORTE_ERROR_LOG(rc);
 298         ORTE_FORCED_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
 299         OBJ_RELEASE(answer);
 300         goto CLEANUP;
 301     }
 302 
 303     if (0 > (rc = orte_rml.send_buffer_nb(sender, answer,
 304                                           ORTE_RML_TAG_FILEM_BASE_RESP,
 305                                           orte_rml_send_callback, NULL))) {
 306         ORTE_ERROR_LOG(rc);
 307         ORTE_FORCED_TERMINATE(ORTE_ERROR_DEFAULT_EXIT_CODE);
 308         OBJ_RELEASE(answer);
 309     }
 310 
 311  CLEANUP:
 312     if( NULL != filename) {
 313         free(filename);
 314         filename = NULL;
 315     }
 316     if( NULL != tmp_name) {
 317         free(tmp_name);
 318         tmp_name = NULL;
 319     }
 320 }

/* [<][>][^][v][top][bottom][index][help] */