int pmix_rte_init(pmix_proc_type_t type, pmix_info_t info[], size_t ninfo, pmix_ptl_cbfunc_t cbfunc) { int ret, debug_level; char *error = NULL, *evar; size_t n; char hostname[PMIX_MAXHOSTNAMELEN]; if( ++pmix_initialized != 1 ) { if( pmix_initialized < 1 ) { return PMIX_ERROR; } return PMIX_SUCCESS; } #if PMIX_NO_LIB_DESTRUCTOR if (pmix_init_called) { /* can't use show_help here */ fprintf (stderr, "pmix_init: attempted to initialize after finalize without compiler " "support for either __attribute__(destructor) or linker support for -fini -- process " "will likely abort\n"); return PMIX_ERR_NOT_SUPPORTED; } #endif pmix_init_called = true; /* initialize the output system */ if (!pmix_output_init()) { return PMIX_ERROR; } /* initialize install dirs code */ if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_pinstalldirs_base_framework, 0))) { fprintf(stderr, "pmix_pinstalldirs_base_open() failed -- process will likely abort (%s:%d, returned %d instead of PMIX_SUCCESS)\n", __FILE__, __LINE__, ret); return ret; } /* initialize the help system */ pmix_show_help_init(); /* keyval lex-based parser */ if (PMIX_SUCCESS != (ret = pmix_util_keyval_parse_init())) { error = "pmix_util_keyval_parse_init"; goto return_error; } /* Setup the parameter system */ if (PMIX_SUCCESS != (ret = pmix_mca_base_var_init())) { error = "mca_base_var_init"; goto return_error; } /* register params for pmix */ if (PMIX_SUCCESS != (ret = pmix_register_params())) { error = "pmix_register_params"; goto return_error; } /* initialize the mca */ if (PMIX_SUCCESS != (ret = pmix_mca_base_open())) { error = "mca_base_open"; goto return_error; } /* setup the globals structure */ gethostname(hostname, PMIX_MAXHOSTNAMELEN); pmix_globals.hostname = strdup(hostname); memset(&pmix_globals.myid.nspace, 0, PMIX_MAX_NSLEN+1); pmix_globals.myid.rank = PMIX_RANK_INVALID; PMIX_CONSTRUCT(&pmix_globals.events, pmix_events_t); pmix_globals.event_window.tv_sec = pmix_event_caching_window; pmix_globals.event_window.tv_usec = 0; PMIX_CONSTRUCT(&pmix_globals.cached_events, pmix_list_t); /* construct the global notification ring buffer */ PMIX_CONSTRUCT(&pmix_globals.notifications, pmix_hotel_t); ret = pmix_hotel_init(&pmix_globals.notifications, pmix_globals.max_events, pmix_globals.evbase, pmix_globals.event_eviction_time, _notification_eviction_cbfunc); if (PMIX_SUCCESS != ret) { error = "notification hotel init"; goto return_error; } /* and setup the iof request tracking list */ PMIX_CONSTRUCT(&pmix_globals.iof_requests, pmix_list_t); /* Setup client verbosities as all procs are allowed to * access client APIs */ if (0 < pmix_client_globals.get_verbose) { /* set default output */ pmix_client_globals.get_output = pmix_output_open(NULL); pmix_output_set_verbosity(pmix_client_globals.get_output, pmix_client_globals.get_verbose); } if (0 < pmix_client_globals.connect_verbose) { /* set default output */ pmix_client_globals.connect_output = pmix_output_open(NULL); pmix_output_set_verbosity(pmix_client_globals.connect_output, pmix_client_globals.connect_verbose); } if (0 < pmix_client_globals.fence_verbose) { /* set default output */ pmix_client_globals.fence_output = pmix_output_open(NULL); pmix_output_set_verbosity(pmix_client_globals.fence_output, pmix_client_globals.fence_verbose); } if (0 < pmix_client_globals.pub_verbose) { /* set default output */ pmix_client_globals.pub_output = pmix_output_open(NULL); pmix_output_set_verbosity(pmix_client_globals.pub_output, pmix_client_globals.pub_verbose); } if (0 < pmix_client_globals.spawn_verbose) { /* set default output */ pmix_client_globals.spawn_output = pmix_output_open(NULL); pmix_output_set_verbosity(pmix_client_globals.spawn_output, pmix_client_globals.spawn_verbose); } if (0 < pmix_client_globals.event_verbose) { /* set default output */ pmix_client_globals.event_output = pmix_output_open(NULL); pmix_output_set_verbosity(pmix_client_globals.event_output, pmix_client_globals.event_verbose); } if (0 < pmix_client_globals.iof_verbose) { /* set default output */ pmix_client_globals.iof_output = pmix_output_open(NULL); pmix_output_set_verbosity(pmix_client_globals.iof_output, pmix_client_globals.iof_verbose); } /* get our effective id's */ pmix_globals.uid = geteuid(); pmix_globals.gid = getegid(); /* see if debug is requested */ if (NULL != (evar = getenv("PMIX_DEBUG"))) { debug_level = strtol(evar, NULL, 10); pmix_globals.debug_output = pmix_output_open(NULL); pmix_output_set_verbosity(pmix_globals.debug_output, debug_level); } /* create our peer object */ pmix_globals.mypeer = PMIX_NEW(pmix_peer_t); if (NULL == pmix_globals.mypeer) { ret = PMIX_ERR_NOMEM; goto return_error; } /* whatever our declared proc type, we are definitely v3.0 */ pmix_globals.mypeer->proc_type = type | PMIX_PROC_V3; /* create an nspace object for ourselves - we will * fill in the nspace name later */ pmix_globals.mypeer->nptr = PMIX_NEW(pmix_namespace_t); if (NULL == pmix_globals.mypeer->nptr) { PMIX_RELEASE(pmix_globals.mypeer); ret = PMIX_ERR_NOMEM; goto return_error; } /* scan incoming info for directives */ if (NULL != info) { for (n=0; n < ninfo; n++) { if (PMIX_CHECK_KEY(&info[n], PMIX_EVENT_BASE)) { pmix_globals.evbase = (pmix_event_base_t*)info[n].value.data.ptr; pmix_globals.external_evbase = true; } else if (PMIX_CHECK_KEY(&info[n], PMIX_HOSTNAME)) { if (NULL != pmix_globals.hostname) { free(pmix_globals.hostname); } pmix_globals.hostname = strdup(info[n].value.data.string); } else if (PMIX_CHECK_KEY(&info[n], PMIX_NODEID)) { PMIX_VALUE_GET_NUMBER(ret, &info[n].value, pmix_globals.nodeid, uint32_t); if (PMIX_SUCCESS != ret) { goto return_error; } } } } /* the choice of modules to use when communicating with a peer * will be done by the individual init functions and at the * time of connection to that peer */ /* open the bfrops and select the active plugins */ if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_bfrops_base_framework, 0)) ) { error = "pmix_bfrops_base_open"; goto return_error; } if (PMIX_SUCCESS != (ret = pmix_bfrop_base_select()) ) { error = "pmix_bfrops_base_select"; goto return_error; } /* open the ptl and select the active plugins */ if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_ptl_base_framework, 0)) ) { error = "pmix_ptl_base_open"; goto return_error; } if (PMIX_SUCCESS != (ret = pmix_ptl_base_select()) ) { error = "pmix_ptl_base_select"; goto return_error; } /* set the notification callback function */ if (PMIX_SUCCESS != (ret = pmix_ptl_base_set_notification_cbfunc(cbfunc))) { error = "pmix_ptl_set_notification_cbfunc"; goto return_error; } /* open the psec and select the active plugins */ if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_psec_base_framework, 0))) { error = "pmix_psec_base_open"; goto return_error; } if (PMIX_SUCCESS != (ret = pmix_psec_base_select())) { error = "pmix_psec_base_select"; goto return_error; } /* open the gds and select the active plugins */ if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_gds_base_framework, 0)) ) { error = "pmix_gds_base_open"; goto return_error; } if (PMIX_SUCCESS != (ret = pmix_gds_base_select(info, ninfo)) ) { error = "pmix_gds_base_select"; goto return_error; } /* initialize pif framework */ if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_pif_base_framework, 0))) { error = "pmix_pif_base_open"; return ret; } /* open the preg and select the active plugins */ if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_preg_base_framework, 0)) ) { error = "pmix_preg_base_open"; goto return_error; } if (PMIX_SUCCESS != (ret = pmix_preg_base_select()) ) { error = "pmix_preg_base_select"; goto return_error; } /* open the plog and select the active plugins */ if (PMIX_SUCCESS != (ret = pmix_mca_base_framework_open(&pmix_plog_base_framework, 0)) ) { error = "pmix_plog_base_open"; goto return_error; } if (PMIX_SUCCESS != (ret = pmix_plog_base_select()) ) { error = "pmix_plog_base_select"; goto return_error; } /* if an external event base wasn't provide, create one */ if (!pmix_globals.external_evbase) { /* tell libevent that we need thread support */ pmix_event_use_threads(); /* create an event base and progress thread for us */ if (NULL == (pmix_globals.evbase = pmix_progress_thread_init(NULL))) { error = "progress thread"; ret = PMIX_ERROR; goto return_error; } } return PMIX_SUCCESS; return_error: if (PMIX_ERR_SILENT != ret) { pmix_show_help( "help-pmix-runtime.txt", "pmix_init:startup:internal-failure", true, error, ret ); } return ret; }
static pmix_status_t allocate(pmix_namespace_t *nptr, pmix_info_t *info, pmix_list_t *ilist) { uint64_t unique_key[2]; size_t n, nreqs=0; int ports_per_node=0; pmix_kval_t *kv; pmix_status_t rc; pmix_info_t *requests = NULL; char **reqs, *cptr; bool allocated = false, seckey = false; tcp_port_tracker_t *trk; tcp_available_ports_t *avail, *aptr; pmix_list_t mylist; pmix_buffer_t buf; char *type = NULL, *plane = NULL, *idkey = NULL; pmix_output_verbose(2, pmix_pnet_base_framework.framework_output, "pnet:tcp:allocate for nspace %s", nptr->nspace); /* if I am not the gateway, then ignore this call - should never * happen, but check to be safe */ if (!PMIX_PROC_IS_GATEWAY(pmix_globals.mypeer)) { return PMIX_SUCCESS; } if (NULL == info) { return PMIX_ERR_TAKE_NEXT_OPTION; } /* check directives to see if a crypto key and/or * network resource allocations requested */ PMIX_CONSTRUCT(&mylist, pmix_list_t); if (PMIX_CHECK_KEY(info, PMIX_SETUP_APP_ENVARS) || PMIX_CHECK_KEY(info, PMIX_SETUP_APP_ALL)) { if (NULL != mca_pnet_tcp_component.include) { pmix_output_verbose(2, pmix_pnet_base_framework.framework_output, "pnet: tcp harvesting envars %s excluding %s", (NULL == mca_pnet_tcp_component.incparms) ? "NONE" : mca_pnet_tcp_component.incparms, (NULL == mca_pnet_tcp_component.excparms) ? "NONE" : mca_pnet_tcp_component.excparms); rc = pmix_pnet_base_harvest_envars(mca_pnet_tcp_component.include, mca_pnet_tcp_component.exclude, ilist); return rc; } return PMIX_SUCCESS; } else if (!PMIX_CHECK_KEY(info, PMIX_ALLOC_NETWORK)) { /* not a network allocation request */ return PMIX_SUCCESS; } pmix_output_verbose(2, pmix_pnet_base_framework.framework_output, "pnet:tcp:allocate alloc_network for nspace %s", nptr->nspace); /* this info key includes an array of pmix_info_t, each providing * a key (that is to be used as the key for the allocated ports) and * a number of ports to allocate for that key */ if (PMIX_DATA_ARRAY != info->value.type || NULL == info->value.data.darray || PMIX_INFO != info->value.data.darray->type || NULL == info->value.data.darray->array) { /* they made an error */ PMIX_ERROR_LOG(PMIX_ERR_BAD_PARAM); return PMIX_ERR_BAD_PARAM; } requests = (pmix_info_t*)info->value.data.darray->array; nreqs = info->value.data.darray->size; /* cycle thru the provided array and see if this refers to * tcp/udp-based resources - there is no required ordering * of the keys, so just have to do a search */ for (n=0; n < nreqs; n++) { if (0 == strncasecmp(requests[n].key, PMIX_ALLOC_NETWORK_TYPE, PMIX_MAX_KEYLEN)) { /* check for bozo error */ if (PMIX_STRING != requests[n].value.type || NULL == requests[n].value.data.string) { PMIX_ERROR_LOG(PMIX_ERR_BAD_PARAM); return PMIX_ERR_BAD_PARAM; } type = requests[n].value.data.string; } else if (0 == strncasecmp(requests[n].key, PMIX_ALLOC_NETWORK_PLANE, PMIX_MAX_KEYLEN)) { /* check for bozo error */ if (PMIX_STRING != requests[n].value.type || NULL == requests[n].value.data.string) { PMIX_ERROR_LOG(PMIX_ERR_BAD_PARAM); return PMIX_ERR_BAD_PARAM; } plane = requests[n].value.data.string; } else if (0 == strncasecmp(requests[n].key, PMIX_ALLOC_NETWORK_ENDPTS, PMIX_MAX_KEYLEN)) { PMIX_VALUE_GET_NUMBER(rc, &requests[n].value, ports_per_node, int); if (PMIX_SUCCESS != rc) { return rc; } } else if (0 == strncmp(requests[n].key, PMIX_ALLOC_NETWORK_ID, PMIX_MAX_KEYLEN)) {