Skip to content

Commit 64c247c

Browse files
author
rhc54
authored
Merge pull request open-mpi#2148 from rhc54/topic/showhelp
2 parents 3ff08e8 + 8dda91c commit 64c247c

File tree

5 files changed

+163
-31
lines changed

5 files changed

+163
-31
lines changed

opal/mca/pmix/pmix.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,14 @@ typedef const char* (*opal_pmix_base_module_get_nspace_fn_t)(opal_jobid_t jobid)
786786
/* register a jobid-to-nspace pair */
787787
typedef void (*opal_pmix_base_module_register_jobid_fn_t)(opal_jobid_t jobid, const char *nspace);
788788

789+
/* query information from the system */
790+
typedef void (*opal_pmix_base_module_query_fn_t)(opal_list_t *queries,
791+
opal_pmix_info_cbfunc_t cbfunc, void *cbdata);
792+
793+
/* log data to the system */
794+
typedef void (*opal_pmix_base_log_fn_t)(opal_list_t *info,
795+
opal_pmix_op_cbfunc_t cbfunc, void *cbdata);
796+
789797
/*
790798
* the standard public API data structure
791799
*/
@@ -815,6 +823,8 @@ typedef struct {
815823
opal_pmix_base_module_disconnect_nb_fn_t disconnect_nb;
816824
opal_pmix_base_module_resolve_peers_fn_t resolve_peers;
817825
opal_pmix_base_module_resolve_nodes_fn_t resolve_nodes;
826+
opal_pmix_base_module_query_fn_t query;
827+
opal_pmix_base_log_fn_t log;
818828
/* server APIs */
819829
opal_pmix_base_module_server_init_fn_t server_init;
820830
opal_pmix_base_module_server_finalize_fn_t server_finalize;

opal/mca/pmix/pmix3x/pmix3x.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "opal/mca/pmix/pmix_types.h"
4141

4242
#include <pmix_common.h>
43+
#include <pmix.h>
4344

4445
/**** C.O.M.M.O.N I.N.T.E.R.F.A.C.E.S ****/
4546

@@ -61,6 +62,10 @@ static int notify_event(int status,
6162
opal_pmix_data_range_t range,
6263
opal_list_t *info,
6364
opal_pmix_op_cbfunc_t cbfunc, void *cbdata);
65+
static void pmix3x_query(opal_list_t *queries,
66+
opal_pmix_info_cbfunc_t cbfunc, void *cbdata);
67+
static void pmix3x_log(opal_list_t *info,
68+
opal_pmix_op_cbfunc_t cbfunc, void *cbdata);
6469

6570
const opal_pmix_base_module_t opal_pmix_pmix3x_module = {
6671
/* client APIs */
@@ -88,6 +93,8 @@ const opal_pmix_base_module_t opal_pmix_pmix3x_module = {
8893
.disconnect_nb = pmix3x_disconnectnb,
8994
.resolve_peers = pmix3x_resolve_peers,
9095
.resolve_nodes = pmix3x_resolve_nodes,
96+
.query = pmix3x_query,
97+
.log = pmix3x_log,
9198
/* server APIs */
9299
.server_init = pmix3x_server_init,
93100
.server_finalize = pmix3x_server_finalize,
@@ -1293,6 +1300,65 @@ static int notify_event(int status,
12931300
return OPAL_SUCCESS;
12941301
}
12951302

1303+
static void pmix3x_query(opal_list_t *queries,
1304+
opal_pmix_info_cbfunc_t cbfunc, void *cbdata)
1305+
{
1306+
if (NULL != cbfunc) {
1307+
cbfunc(OPAL_ERR_NOT_SUPPORTED, NULL, cbdata, NULL, NULL);
1308+
}
1309+
return;
1310+
}
1311+
1312+
static void opcbfunc(pmix_status_t status, void *cbdata)
1313+
{
1314+
pmix3x_opcaddy_t *op = (pmix3x_opcaddy_t*)cbdata;
1315+
1316+
if (NULL != op->opcbfunc) {
1317+
op->opcbfunc(pmix3x_convert_rc(status), op->cbdata);
1318+
}
1319+
OBJ_RELEASE(op);
1320+
}
1321+
1322+
static void pmix3x_log(opal_list_t *info,
1323+
opal_pmix_op_cbfunc_t cbfunc, void *cbdata)
1324+
{
1325+
int rc;
1326+
opal_value_t *ival;
1327+
size_t n, ninfo;
1328+
pmix3x_opcaddy_t *cd;
1329+
1330+
/* bozo check */
1331+
if (NULL == info || 0 == (ninfo = opal_list_get_size(info))) {
1332+
rc = OPAL_ERR_BAD_PARAM;
1333+
goto CLEANUP;
1334+
}
1335+
1336+
/* setup the operation */
1337+
cd = OBJ_NEW(pmix3x_opcaddy_t);
1338+
cd->opcbfunc = cbfunc;
1339+
cd->cbdata = cbdata;
1340+
cd->ninfo = ninfo;
1341+
1342+
/* convert the list to an array of info objects */
1343+
PMIX_INFO_CREATE(cd->info, cd->ninfo);
1344+
n=0;
1345+
OPAL_LIST_FOREACH(ival, info, opal_value_t) {
1346+
(void)strncpy(cd->info[n].key, ival->key, PMIX_MAX_KEYLEN);
1347+
pmix3x_value_load(&cd->info[n].value, ival);
1348+
++n;
1349+
}
1350+
1351+
/* pass it down */
1352+
PMIx_Log_nb(cd->info, cd->ninfo, NULL, 0,
1353+
opcbfunc, cd);
1354+
return;
1355+
1356+
CLEANUP:
1357+
if (NULL != cbfunc) {
1358+
cbfunc(rc, cbdata);
1359+
}
1360+
}
1361+
12961362
/**** INSTANTIATE INTERNAL CLASSES ****/
12971363
OBJ_CLASS_INSTANCE(opal_pmix3x_jobid_trkr_t,
12981364
opal_list_item_t,

opal/mca/pmix/pmix_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ BEGIN_C_DECLS
201201
// procs in job on same node
202202
#define OPAL_PMIX_QUERY_AUTHORIZATIONS "pmix.qry.auths" // return operations tool is authorized to perform"
203203

204+
/* log attributes */
205+
#define OPAL_PMIX_LOG_STDERR "pmix.log.stderr" // (bool) log data to stderr
206+
#define OPAL_PMIX_LOG_STDOUT "pmix.log.stdout" // (bool) log data to stdout
207+
#define OPAL_PMIX_LOG_SYSLOG "pmix.log.syslog" // (bool) log data to syslog - defaults to ERROR priority unless
204208

205209
/* define a scope for data "put" by PMI per the following:
206210
*

orte/orted/pmix/pmix_server_gen.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,18 +481,27 @@ void pmix_server_log_fn(opal_process_name_t *requestor,
481481
void *cbdata)
482482
{
483483
opal_value_t *val;
484+
opal_buffer_t *buf;
485+
int rc;
484486

485487
/* for now, we only support logging show_help messages */
486488
OPAL_LIST_FOREACH(val, info, opal_value_t) {
487489
/* we ignore the key as irrelevant - we only want to
488-
* pull out the string value */
489-
if (OPAL_STRING != val->type) {
490+
* pull out the blob */
491+
if (OPAL_BYTE_OBJECT != val->type) {
490492
continue;
491493
}
492-
opal_output(0, "SHOWHELP: %s", val->data.string);
494+
buf = OBJ_NEW(opal_buffer_t);
495+
opal_dss.load(buf, val->data.bo.bytes, val->data.bo.size);
496+
val->data.bo.bytes = NULL;
497+
if (ORTE_SUCCESS != (rc = orte_rml.send_buffer_nb(ORTE_PROC_MY_HNP, buf,
498+
ORTE_RML_TAG_SHOW_HELP,
499+
orte_rml_send_callback, NULL))) {
500+
ORTE_ERROR_LOG(rc);
501+
OBJ_RELEASE(buf);
502+
}
493503
}
494504
if (NULL != cbfunc) {
495505
cbfunc(OPAL_SUCCESS, cbdata);
496506
}
497507
}
498-

orte/util/show_help.c

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "opal/util/output.h"
3131
#include "opal/dss/dss.h"
3232
#include "opal/mca/event/event.h"
33+
#include "opal/mca/pmix/pmix.h"
3334

3435
#include "orte/mca/errmgr/errmgr.h"
3536
#include "orte/mca/rml/rml.h"
@@ -602,11 +603,23 @@ int orte_show_help(const char *filename, const char *topic,
602603
return rc;
603604
}
604605

606+
static void cbfunc(int status, void *cbdata)
607+
{
608+
volatile bool *active = (volatile bool*)cbdata;
609+
*active = false;
610+
}
611+
605612
int orte_show_help_norender(const char *filename, const char *topic,
606613
bool want_error_header, const char *output)
607614
{
608615
int rc = ORTE_SUCCESS;
609616
int8_t have_output = 1;
617+
opal_buffer_t *buf;
618+
bool am_inside = false;
619+
opal_list_t info;
620+
opal_value_t *kv;
621+
volatile bool active;
622+
struct timespec tp;
610623

611624
if (!ready) {
612625
/* if we are finalizing, then we have no way to process
@@ -628,39 +641,44 @@ int orte_show_help_norender(const char *filename, const char *topic,
628641
* mode, then all we can do is process this locally
629642
*/
630643
if (ORTE_PROC_IS_HNP || ORTE_PROC_IS_TOOL ||
631-
orte_standalone_operation ||
632-
NULL == orte_rml.send_buffer_nb ||
633-
NULL == orte_routed.get_route ||
634-
NULL == orte_process_info.my_hnp_uri) {
644+
orte_standalone_operation) {
635645
rc = show_help(filename, topic, output, ORTE_PROC_MY_NAME);
646+
goto CLEANUP;
647+
} else if (ORTE_PROC_IS_DAEMON) {
648+
if (NULL == orte_rml.send_buffer_nb ||
649+
NULL == orte_routed.get_route ||
650+
NULL == orte_process_info.my_hnp_uri) {
651+
rc = show_help(filename, topic, output, ORTE_PROC_MY_NAME);
652+
goto CLEANUP;
653+
}
636654
}
637655

638656
/* otherwise, we relay the output message to
639657
* the HNP for processing
640658
*/
641-
else {
642-
opal_buffer_t *buf;
643-
static bool am_inside = false;
644659

645-
/* JMS Note that we *may* have a recursion situation here where
646-
the RML could call show_help. Need to think about this
647-
properly, but put a safeguard in here for sure for the time
648-
being. */
649-
if (am_inside) {
650-
rc = show_help(filename, topic, output, ORTE_PROC_MY_NAME);
651-
} else {
652-
am_inside = true;
653-
654-
/* build the message to the HNP */
655-
buf = OBJ_NEW(opal_buffer_t);
656-
/* pack the filename of the show_help text file */
657-
opal_dss.pack(buf, &filename, 1, OPAL_STRING);
658-
/* pack the topic tag */
659-
opal_dss.pack(buf, &topic, 1, OPAL_STRING);
660-
/* pack the flag that we have a string */
661-
opal_dss.pack(buf, &have_output, 1, OPAL_INT8);
662-
/* pack the resulting string */
663-
opal_dss.pack(buf, &output, 1, OPAL_STRING);
660+
/* JMS Note that we *may* have a recursion situation here where
661+
the RML could call show_help. Need to think about this
662+
properly, but put a safeguard in here for sure for the time
663+
being. */
664+
if (am_inside) {
665+
rc = show_help(filename, topic, output, ORTE_PROC_MY_NAME);
666+
} else {
667+
am_inside = true;
668+
669+
/* build the message to the HNP */
670+
buf = OBJ_NEW(opal_buffer_t);
671+
/* pack the filename of the show_help text file */
672+
opal_dss.pack(buf, &filename, 1, OPAL_STRING);
673+
/* pack the topic tag */
674+
opal_dss.pack(buf, &topic, 1, OPAL_STRING);
675+
/* pack the flag that we have a string */
676+
opal_dss.pack(buf, &have_output, 1, OPAL_INT8);
677+
/* pack the resulting string */
678+
opal_dss.pack(buf, &output, 1, OPAL_STRING);
679+
680+
/* if we are a daemon, then send it via RML to the HNP */
681+
if (ORTE_PROC_IS_DAEMON) {
664682
/* send it to the HNP */
665683
if (ORTE_SUCCESS != (rc = orte_rml.send_buffer_nb(ORTE_PROC_MY_HNP, buf,
666684
ORTE_RML_TAG_SHOW_HELP,
@@ -672,8 +690,33 @@ int orte_show_help_norender(const char *filename, const char *topic,
672690
} else {
673691
rc = ORTE_SUCCESS;
674692
}
675-
am_inside = false;
693+
} else {
694+
/* if we are not a daemon (i.e., we are an app) and if PMIx
695+
* support for "log" is available, then use that channel */
696+
if (NULL != opal_pmix.log) {
697+
OBJ_CONSTRUCT(&info, opal_list_t);
698+
kv = OBJ_NEW(opal_value_t),
699+
kv->key = strdup(OPAL_PMIX_LOG_STDERR);
700+
kv->type = OPAL_BYTE_OBJECT;
701+
opal_dss.unload(buf, (void**)&kv->data.bo.bytes, &kv->data.bo.size);
702+
opal_list_append(&info, &kv->super);
703+
active = true;
704+
tp.tv_sec = 0;
705+
tp.tv_nsec = 1000000;
706+
opal_pmix.log(&info, cbfunc, (void*)&active);
707+
while (active) {
708+
nanosleep(&tp, NULL);
709+
}
710+
OBJ_RELEASE(buf);
711+
kv->data.bo.bytes = NULL;
712+
OPAL_LIST_DESTRUCT(&info);
713+
rc = ORTE_SUCCESS;
714+
goto CLEANUP;
715+
} else {
716+
rc = show_help(filename, topic, output, ORTE_PROC_MY_NAME);
717+
}
676718
}
719+
am_inside = false;
677720
}
678721

679722
CLEANUP:

0 commit comments

Comments
 (0)