orcm/tools/orcmd/orcmd.c
/* process incoming messages in order of receipt */
process incoming messages in order of receipt
process incoming messages in order of receipt
static void orcmd_recv(int status, orte_process_name_t* sender,
                       opal_buffer_t* buffer, orte_rml_tag_t tag,
                       void* cbdata)
{
    orcm_rm_cmd_flag_t command;
    int n, rc;
    orcm_alloc_t *alloc;
    opal_buffer_t *buf;
    orte_jobid_t jobid;
    int hnp = 0;
    int port_num = HNP_PORT_NUM;
    char *hnp_uri = NULL;
    char *hnp_ip = NULL;
    struct hostent *hnp_hostent = NULL;
    struct in_addr **addr_list;
    n = 1;
    if (OPAL_SUCCESS != (rc = opal_dss.unpack(buffer, &command, &n, ORCM_RM_CMD_T))) {
        ORTE_ERROR_LOG (rc);
        return;
    }
    switch(command) {
    case ORCM_LAUNCH_STEPD_COMMAND:
        n = 1; 
        stepd_pid = 0;
        if (OPAL_SUCCESS !=
            (rc = opal_dss.unpack(buffer, &alloc, &n, ORCM_ALLOC))) {
            ORTE_ERROR_LOG(rc);
            return;
        }
        if (OPAL_EQUAL ==
            orte_util_compare_name_fields(ORTE_NS_CMP_ALL, &alloc->hnp,
                          ORTE_PROC_MY_NAME)) {
            hnp = 1;
        }
        opal_output(0,
                "%s: allocate session : %d\n",
                ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), (int) alloc->id);
        jobid = alloc->id << 16;
        port_num++;
        orcm_pwrmgmt.alloc_notify(alloc);
        if (alloc->hnpname != NULL) {
            if ((hnp_hostent =
                 gethostbyname(alloc->hnpname)) == NULL
                || hnp_hostent->h_addr_list == NULL) {
                ORTE_ERROR_LOG(ORTE_ERR_NOT_FOUND);
                return;
            }
            addr_list = (struct in_addr **)hnp_hostent->h_addr_list;
            hnp_ip = strdup(inet_ntoa(*addr_list[0]));
            asprintf(&hnp_uri, "%i.0;tcp://%s:%i[$.$]", jobid, hnp_ip,
                port_num);
            alloc->hnpuri = hnp_uri;
        } 
        if (hnp_uri) {
            slm_fork_hnp_procs(jobid, port_num, hnp, hnp_uri, alloc, &stepd_pid);
        }
        command = ORCM_VM_READY_COMMAND;
        buf = OBJ_NEW(opal_buffer_t);
        if (OPAL_SUCCESS !=
            (rc = opal_dss.pack(buf, &command, 1, ORCM_RM_CMD_T))) {
            ORTE_ERROR_LOG(rc);
            OBJ_RELEASE(buf);
            if (hnp_ip) {
                free(hnp_ip);
            }
            if (hnp_uri) {
                free(hnp_uri);
            }
            return;
        }
        if (OPAL_SUCCESS !=
            (rc = opal_dss.pack(buf, &alloc, 1, ORCM_ALLOC))) {
            ORTE_ERROR_LOG(rc);
            OBJ_RELEASE(buf);
            if (hnp_ip) {
                free(hnp_ip);
            }
            if (hnp_uri) {
                free(hnp_uri);
            }
            return;
        }
        if (ORTE_SUCCESS !=
            (rc = orte_rml.send_buffer_nb(ORTE_PROC_MY_SCHEDULER, buf,
                                          ORCM_RML_TAG_RM,
                                          orte_rml_send_callback, NULL))) {
            ORTE_ERROR_LOG(rc);
            OBJ_RELEASE(buf);
            if (hnp_ip) {
                free(hnp_ip);
            }
            if (hnp_uri) {
                free(hnp_uri);
            }
            return;
        }
        break;
    case ORCM_CANCEL_STEPD_COMMAND:
        opal_output(0,
                "%s: ORCM daemon got cancel stepd command, executing hostname",
                ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
        n = 1;
        if (OPAL_SUCCESS !=
            (rc = opal_dss.unpack(buffer, &alloc, &n, ORCM_ALLOC))) {
            ORTE_ERROR_LOG(rc);
            return;
        }
         printf("Calling power management dealloc notify\n");
        orcm_pwrmgmt.dealloc_notify(alloc);
        orte_rml.recv_cancel(ORTE_NAME_WILDCARD,
                     ORTE_RML_TAG_ABORT);
        if (stepd_pid > 0) {
            kill_local(stepd_pid, SIGKILL);
            stepd_pid = 0;
        } else {
            opal_output(0, "%s orcmd:STEPD PID %d FAILED",
                         ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), stepd_pid);
        }
        command = ORCM_STEPD_COMPLETE_COMMAND;
        buf = OBJ_NEW(opal_buffer_t);
        if (OPAL_SUCCESS !=
            (rc = opal_dss.pack(buf, &command, 1, ORCM_RM_CMD_T))) {
            ORTE_ERROR_LOG(rc);
            OBJ_RELEASE(buf);
            return;
        }
        if (OPAL_SUCCESS !=
            (rc = opal_dss.pack(buf, &alloc, 1, ORCM_ALLOC))) {
            ORTE_ERROR_LOG(rc);
            OBJ_RELEASE(buf);
            return;
        }
        if (ORTE_SUCCESS !=
            (rc =
             orte_rml.send_buffer_nb(ORTE_PROC_MY_SCHEDULER, buf,
                         ORCM_RML_TAG_RM,
                         orte_rml_send_callback, NULL))) {
            ORTE_ERROR_LOG(rc);
            OBJ_RELEASE(buf);
            return;
        }
        break;
    case ORCM_CALIBRATE_COMMAND:
        opal_output(0, "%s: RUNNING CALIBRATION",
                    ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
        orcm_diag.calibrate();
        break;
    default:
        opal_output(0, "%s: COMMAND UNKNOWN",
                    ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
    }
    if (hnp_ip) {
        free(hnp_ip);
    }
    if (hnp_uri) {
        free(hnp_uri);
    }
    return;
}
static void orcmd_recv ( int status , orte_process_name_t * sender , opal_buffer_t * buffer , orte_rml_tag_t tag , void * cbdata ) { orcm_rm_cmd_flag_t command ; int n , rc ; orcm_alloc_t * alloc ; opal_buffer_t * buf ; orte_jobid_t jobid ; int hnp = 0 ; int port_num = HNP_PORT_NUM ; char * hnp_uri = NULL ; char * hnp_ip = NULL ; struct hostent * hnp_hostent = NULL ; struct in_addr * * addr_list ; n = 1 ; if ( OPAL_SUCCESS != ( rc = opal_dss . unpack ( buffer , & command , & n , ORCM_RM_CMD_T ) ) ) { ORTE_ERROR_LOG ( rc ) ; return ; } switch ( command ) { case ORCM_LAUNCH_STEPD_COMMAND : n = 1 ; stepd_pid = 0 ; if ( OPAL_SUCCESS != ( rc = opal_dss . unpack ( buffer , & alloc , & n , ORCM_ALLOC ) ) ) { ORTE_ERROR_LOG ( rc ) ; return ; } if ( OPAL_EQUAL == orte_util_compare_name_fields ( ORTE_NS_CMP_ALL , & alloc -> hnp , ORTE_PROC_MY_NAME ) ) { hnp = 1 ; } opal_output ( 0 , " \n " , ORTE_NAME_PRINT ( ORTE_PROC_MY_NAME ) , ( int ) alloc -> id ) ; jobid = alloc -> id << 16 ; port_num ++ ; orcm_pwrmgmt . alloc_notify ( alloc ) ; if ( alloc -> hnpname != NULL ) { if ( ( hnp_hostent = gethostbyname ( alloc -> hnpname ) ) == NULL || hnp_hostent -> h_addr_list == NULL ) { ORTE_ERROR_LOG ( ORTE_ERR_NOT_FOUND ) ; return ; } addr_list = ( struct in_addr * * ) hnp_hostent -> h_addr_list ; hnp_ip = strdup ( inet_ntoa ( * addr_list [ 0 ] ) ) ; asprintf ( & hnp_uri , " " , jobid , hnp_ip , port_num ) ; alloc -> hnpuri = hnp_uri ; } if ( hnp_uri ) { slm_fork_hnp_procs ( jobid , port_num , hnp , hnp_uri , alloc , & stepd_pid ) ; } command = ORCM_VM_READY_COMMAND ; buf = OBJ_NEW ( opal_buffer_t ) ; if ( OPAL_SUCCESS != ( rc = opal_dss . pack ( buf , & command , 1 , ORCM_RM_CMD_T ) ) ) { ORTE_ERROR_LOG ( rc ) ; OBJ_RELEASE ( buf ) ; if ( hnp_ip ) { free ( hnp_ip ) ; } if ( hnp_uri ) { free ( hnp_uri ) ; } return ; } if ( OPAL_SUCCESS != ( rc = opal_dss . pack ( buf , & alloc , 1 , ORCM_ALLOC ) ) ) { ORTE_ERROR_LOG ( rc ) ; OBJ_RELEASE ( buf ) ; if ( hnp_ip ) { free ( hnp_ip ) ; } if ( hnp_uri ) { free ( hnp_uri ) ; } return ; } if ( ORTE_SUCCESS != ( rc = orte_rml . send_buffer_nb ( ORTE_PROC_MY_SCHEDULER , buf , ORCM_RML_TAG_RM , orte_rml_send_callback , NULL ) ) ) { ORTE_ERROR_LOG ( rc ) ; OBJ_RELEASE ( buf ) ; if ( hnp_ip ) { free ( hnp_ip ) ; } if ( hnp_uri ) { free ( hnp_uri ) ; } return ; } break ; case ORCM_CANCEL_STEPD_COMMAND : opal_output ( 0 , " " , ORTE_NAME_PRINT ( ORTE_PROC_MY_NAME ) ) ; n = 1 ; if ( OPAL_SUCCESS != ( rc = opal_dss . unpack ( buffer , & alloc , & n , ORCM_ALLOC ) ) ) { ORTE_ERROR_LOG ( rc ) ; return ; } printf ( " \n " ) ; orcm_pwrmgmt . dealloc_notify ( alloc ) ; orte_rml . recv_cancel ( ORTE_NAME_WILDCARD , ORTE_RML_TAG_ABORT ) ; if ( stepd_pid > 0 ) { kill_local ( stepd_pid , SIGKILL ) ; stepd_pid = 0 ; } else { opal_output ( 0 , " " , ORTE_NAME_PRINT ( ORTE_PROC_MY_NAME ) , stepd_pid ) ; } command = ORCM_STEPD_COMPLETE_COMMAND ; buf = OBJ_NEW ( opal_buffer_t ) ; if ( OPAL_SUCCESS != ( rc = opal_dss . pack ( buf , & command , 1 , ORCM_RM_CMD_T ) ) ) { ORTE_ERROR_LOG ( rc ) ; OBJ_RELEASE ( buf ) ; return ; } if ( OPAL_SUCCESS != ( rc = opal_dss . pack ( buf , & alloc , 1 , ORCM_ALLOC ) ) ) { ORTE_ERROR_LOG ( rc ) ; OBJ_RELEASE ( buf ) ; return ; } if ( ORTE_SUCCESS != ( rc = orte_rml . send_buffer_nb ( ORTE_PROC_MY_SCHEDULER , buf , ORCM_RML_TAG_RM , orte_rml_send_callback , NULL ) ) ) { ORTE_ERROR_LOG ( rc ) ; OBJ_RELEASE ( buf ) ; return ; } break ; case ORCM_CALIBRATE_COMMAND : opal_output ( 0 , " " , ORTE_NAME_PRINT ( ORTE_PROC_MY_NAME ) ) ; orcm_diag . calibrate ( ) ; break ; default : opal_output ( 0 , " " , ORTE_NAME_PRINT ( ORTE_PROC_MY_NAME ) ) ; } if ( hnp_ip ) { free ( hnp_ip ) ; } if ( hnp_uri ) { free ( hnp_uri ) ; } return ; }
process incoming messages in order of receipt
process incoming messages in order of receipt
/* notify the power management framework */ /* construct the hnp uri */ /* pack the complete command flag */ /* notify the power management framework */ /* pack the complete command flag */