1
1
http://www.open-mpi.org/community/lists/devel/2014/04/14496.php

Revamp the opal database framework, including renaming it to "dstore" to reflect that it isn't a "database". Move the "db" framework to ORTE for now, soon to move to ORCM

This commit was SVN r31557.
Этот коммит содержится в:
Ralph Castain 2014-04-29 21:49:23 +00:00
родитель fc0a75da91
Коммит c4c9bc1573
101 изменённых файлов: 5214 добавлений и 4178 удалений

Просмотреть файл

@ -1638,7 +1638,6 @@ ompi_proc_t **ompi_comm_get_rprocs ( ompi_communicator_t *local_comm,
} }
/* And now add the information into the database */ /* And now add the information into the database */
/* Store the remote processes into the opal_db */
if (OMPI_SUCCESS != (rc = MCA_PML_CALL(add_procs(rprocs, rsize)))) { if (OMPI_SUCCESS != (rc = MCA_PML_CALL(add_procs(rprocs, rsize)))) {
OMPI_ERROR_LOG(rc); OMPI_ERROR_LOG(rc);
goto err_exit; goto err_exit;

Просмотреть файл

@ -3,6 +3,7 @@
* Copyright (c) 2011-2013 Los Alamos National Security, LLC. All rights * Copyright (c) 2011-2013 Los Alamos National Security, LLC. All rights
* reserved. * reserved.
* Copyright (c) 2011 UT-Battelle, LLC. All rights reserved. * Copyright (c) 2011 UT-Battelle, LLC. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -14,7 +15,9 @@
#include "common_ugni.h" #include "common_ugni.h"
#include "ompi/proc/proc.h" #include "ompi/proc/proc.h"
#include "opal/mca/db/db.h" #include "opal/mca/dstore/dstore.h"
#include "opal/class/opal_list.h"
#include "opal/dss/dss.h"
/* NTH: we need some options from the btl */ /* NTH: we need some options from the btl */
#include "ompi/mca/btl/ugni/btl_ugni.h" #include "ompi/mca/btl/ugni/btl_ugni.h"
@ -240,11 +243,25 @@ int ompi_common_ugni_init (void)
/* get a unique id from the runtime */ /* get a unique id from the runtime */
#if defined(OMPI_DB_GLOBAL_RANK) #if defined(OMPI_DB_GLOBAL_RANK)
ptr = &my_rank; {
rc = opal_db.fetch ((opal_identifier_t *) &my_proc->proc_name, OMPI_DB_GLOBAL_RANK, opal_list_t myvals;
(void **) &ptr, OPAL_UINT32); opal_value_t *kv;
if (OPAL_SUCCESS != rc) {
my_rank = my_proc->proc_name.vpid; ptr = &my_rank;
OBJ_CONSTRUCT(&myvals, opal_list_t);
rc = opal_dstore.fetch (opal_dstore_internal,
ORTE_NAME_PRINT(&my_proc->proc_name),
OMPI_DB_GLOBAL_RANK,
&myvals);
if (OPAL_SUCCESS == rc) {
kv = (opal_value_t*)opal_list_get_first(&myvals):
if (OPAL_SUCCESS != opal_value_unload(&kv, (void**)&ptr, OPAL_UINT32)) {
my_rank = my_proc->proc_name.vpid;
}
} else {
my_rank = my_proc->proc_name.vpid;
}
OPAL_LIST_DESTRUCT(&myvals);
} }
#else #else
my_rank = my_proc->proc_name.vpid; my_rank = my_proc->proc_name.vpid;

Просмотреть файл

@ -15,7 +15,7 @@
* Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved. * Copyright (c) 2009 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) 2011-2013 Los Alamos National Security, LLC. All rights * Copyright (c) 2011-2013 Los Alamos National Security, LLC. All rights
* reserved. * reserved.
* Copyright (c) 2013 Intel, Inc. All rights reserved * Copyright (c) 2013-2014 Intel, Inc. All rights reserved
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -39,7 +39,6 @@
#include "opal/util/argv.h" #include "opal/util/argv.h"
#include "opal/util/opal_getcwd.h" #include "opal/util/opal_getcwd.h"
#include "opal/dss/dss.h" #include "opal/dss/dss.h"
#include "opal/mca/db/db.h"
#include "opal/mca/hwloc/base/base.h" #include "opal/mca/hwloc/base/base.h"
#include "orte/mca/errmgr/errmgr.h" #include "orte/mca/errmgr/errmgr.h"

Просмотреть файл

@ -2,8 +2,7 @@
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. * Copyright (c) 2012-2013 Los Alamos National Security, LLC.
* All rights reserved. * All rights reserved.
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved * Copyright (c) 2013-2014 Intel, Inc. All rights reserved
* * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2014 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -99,14 +98,6 @@ OMPI_DECLSPEC int ompi_rte_db_store(const ompi_process_name_t *nm, const char* k
OMPI_DECLSPEC int ompi_rte_db_fetch(const struct ompi_proc_t *proc, OMPI_DECLSPEC int ompi_rte_db_fetch(const struct ompi_proc_t *proc,
const char *key, const char *key,
void **data, opal_data_type_t type); void **data, opal_data_type_t type);
OMPI_DECLSPEC int ompi_rte_db_fetch_pointer(const struct ompi_proc_t *proc,
const char *key,
void **data, opal_data_type_t type);
OMPI_DECLSPEC int ompi_rte_db_fetch_multiple(const struct ompi_proc_t *proc,
const char *key,
opal_list_t *kvs);
OMPI_DECLSPEC int ompi_rte_db_remove(const ompi_process_name_t *nm,
const char *key);
#define OMPI_DB_HOSTNAME ORTE_DB_HOSTNAME #define OMPI_DB_HOSTNAME ORTE_DB_HOSTNAME
#define OMPI_DB_LOCALITY ORTE_DB_LOCALITY #define OMPI_DB_LOCALITY ORTE_DB_LOCALITY
#define OMPI_DB_GLOBAL_RANK ORTE_DB_GLOBAL_RANK #define OMPI_DB_GLOBAL_RANK ORTE_DB_GLOBAL_RANK

Просмотреть файл

@ -2,7 +2,7 @@
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. * Copyright (c) 2012-2013 Los Alamos National Security, LLC.
* All rights reserved. * All rights reserved.
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved * Copyright (c) 2013-2014 Intel, Inc. All rights reserved
* Copyright (c) 2014 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2014 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
*/ */
#include "ompi_config.h" #include "ompi_config.h"
@ -15,8 +15,10 @@
#include "opal/dss/dss.h" #include "opal/dss/dss.h"
#include "opal/util/argv.h" #include "opal/util/argv.h"
#include "opal/util/opal_getcwd.h" #include "opal/util/opal_getcwd.h"
#include "opal/mca/db/db.h" #include "opal/mca/dstore/dstore.h"
#include "opal/threads/threads.h" #include "opal/threads/threads.h"
#include "opal/class/opal_list.h"
#include "opal/dss/dss.h"
#include "orte/mca/errmgr/errmgr.h" #include "orte/mca/errmgr/errmgr.h"
#include "orte/mca/ess/ess.h" #include "orte/mca/ess/ess.h"
@ -157,6 +159,11 @@ int ompi_rte_modex(ompi_rte_collective_t *coll)
/* mark that this process reached modex */ /* mark that this process reached modex */
orte_grpcomm_base.modex_ready = true; orte_grpcomm_base.modex_ready = true;
/* let the datastore commit any data we provided that needs
* to be shared with our peers, if required
*/
opal_dstore.commit(opal_dstore_peer, (opal_identifier_t*)ORTE_PROC_MY_NAME);
if ((orte_process_info.num_procs < ompi_hostname_cutoff) || if ((orte_process_info.num_procs < ompi_hostname_cutoff) ||
!mca_rte_orte_component.direct_modex || !mca_rte_orte_component.direct_modex ||
orte_standalone_operation) { orte_standalone_operation) {
@ -209,11 +216,23 @@ int ompi_rte_modex(ompi_rte_collective_t *coll)
int ompi_rte_db_store(const orte_process_name_t *nm, const char* key, int ompi_rte_db_store(const orte_process_name_t *nm, const char* key,
const void *data, opal_data_type_t type) const void *data, opal_data_type_t type)
{ {
opal_value_t kv;
int rc;
OBJ_CONSTRUCT(&kv, opal_value_t);
kv.key = strdup(key);
if (OPAL_SUCCESS != (rc = opal_value_load(&kv, (void*)data, type))) {
OBJ_DESTRUCT(&kv);
return rc;
}
/* MPI connection data is to be shared with ALL other processes */ /* MPI connection data is to be shared with ALL other processes */
return opal_db.store((opal_identifier_t*)nm, OPAL_SCOPE_GLOBAL, key, data, type); rc = opal_dstore.store(opal_dstore_peer, (opal_identifier_t*)nm, &kv);
OBJ_DESTRUCT(&kv);
return rc;
} }
static int direct_modex(orte_process_name_t *peer, opal_scope_t scope) static int direct_modex(orte_process_name_t *peer)
{ {
int rc; int rc;
ompi_orte_tracker_t *req; ompi_orte_tracker_t *req;
@ -225,12 +244,6 @@ static int direct_modex(orte_process_name_t *peer, opal_scope_t scope)
ORTE_NAME_PRINT(peer))); ORTE_NAME_PRINT(peer)));
buf = OBJ_NEW(opal_buffer_t); buf = OBJ_NEW(opal_buffer_t);
/* pack the scope of the request */
if (OPAL_SUCCESS != (rc = opal_dss.pack(buf, &scope, 1, OPAL_DATA_SCOPE_T))) {
ORTE_ERROR_LOG(rc);
OBJ_RELEASE(buf);
return rc;
}
/* create a tracker for this request */ /* create a tracker for this request */
req = OBJ_NEW(ompi_orte_tracker_t); req = OBJ_NEW(ompi_orte_tracker_t);
@ -272,13 +285,22 @@ int ompi_rte_db_fetch(const struct ompi_proc_t *proc,
void **data, opal_data_type_t type) void **data, opal_data_type_t type)
{ {
int rc; int rc;
opal_list_t myvals;
opal_value_t *kv;
OPAL_OUTPUT_VERBOSE((2, orte_grpcomm_base_framework.framework_output, OPAL_OUTPUT_VERBOSE((2, orte_grpcomm_base_framework.framework_output,
"%s fetch data from %s for %s", "%s fetch data from %s for %s",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
ORTE_NAME_PRINT(&proc->proc_name), key)); ORTE_NAME_PRINT(&proc->proc_name), key));
if (OPAL_SUCCESS != (rc = opal_db.fetch((opal_identifier_t*)(&proc->proc_name), key, data, type))) { OBJ_CONSTRUCT(&myvals, opal_list_t);
/* the peer dstore contains our own data that will be shared
* with our peers - the nonpeer dstore contains data we received
* that would only be shared with nonpeer procs
*/
if (OPAL_SUCCESS != (rc = opal_dstore.fetch(opal_dstore_nonpeer,
(opal_identifier_t*)(&proc->proc_name),
key, &myvals))) {
if (direct_modex_enabled) { if (direct_modex_enabled) {
OPAL_OUTPUT_VERBOSE((2, orte_grpcomm_base_framework.framework_output, OPAL_OUTPUT_VERBOSE((2, orte_grpcomm_base_framework.framework_output,
"%s requesting direct modex from %s for %s", "%s requesting direct modex from %s for %s",
@ -287,115 +309,63 @@ int ompi_rte_db_fetch(const struct ompi_proc_t *proc,
/* if we couldn't fetch the data via the db, then we will attempt /* if we couldn't fetch the data via the db, then we will attempt
* to retrieve it from the target proc * to retrieve it from the target proc
*/ */
if (ORTE_SUCCESS != (rc = direct_modex((orte_process_name_t*)&proc->proc_name, OPAL_SCOPE_PEER))) { if (ORTE_SUCCESS != (rc = direct_modex((orte_process_name_t*)(&proc->proc_name)))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
OPAL_LIST_DESTRUCT(&myvals);
return rc; return rc;
} }
/* now retrieve the requested piece */ /* now retrieve the requested piece */
if (OPAL_SUCCESS != (rc = opal_db.fetch((opal_identifier_t*)(&proc->proc_name), key, data, type))) { if (OPAL_SUCCESS != (rc = opal_dstore.fetch(opal_dstore_nonpeer,
(opal_identifier_t*)(&proc->proc_name),
key, &myvals))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
OPAL_LIST_DESTRUCT(&myvals);
return rc; return rc;
} }
} else { } else {
return rc; /* see if we can find it in the internal dstore */
}
}
/* update the hostname upon first call to modex-recv for this proc */
if (NULL == proc->proc_hostname) {
opal_db.fetch_pointer((opal_identifier_t*)(&proc->proc_name), ORTE_DB_HOSTNAME, (void**)&proc->proc_hostname, OPAL_STRING);
}
return OMPI_SUCCESS;
}
int ompi_rte_db_fetch_pointer(const struct ompi_proc_t *proc,
const char *key,
void **data, opal_data_type_t type)
{
int rc;
OPAL_OUTPUT_VERBOSE((2, orte_grpcomm_base_framework.framework_output,
"%s fetch data pointer from %s for %s",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
ORTE_NAME_PRINT(&proc->proc_name), key));
if (OPAL_SUCCESS != (rc = opal_db.fetch_pointer((opal_identifier_t*)(&proc->proc_name), key, data, type))) {
if (direct_modex_enabled) {
/* if we couldn't fetch the data via the db, then we will attempt
* to retrieve it from the target proc
*/
OPAL_OUTPUT_VERBOSE((2, orte_grpcomm_base_framework.framework_output, OPAL_OUTPUT_VERBOSE((2, orte_grpcomm_base_framework.framework_output,
"%s requesting direct modex from %s for %s", "%s searching nonpeer dstore for %s",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), key));
ORTE_NAME_PRINT(&proc->proc_name), key)); if (OPAL_SUCCESS != (rc = opal_dstore.fetch(opal_dstore_internal,
if (ORTE_SUCCESS != (rc = direct_modex((orte_process_name_t*)&proc->proc_name, OPAL_SCOPE_PEER))) { (opal_identifier_t*)(&proc->proc_name),
ORTE_ERROR_LOG(rc); key, &myvals))) {
return rc; /* try one last place - the peer dstore in case it got stuck there for some reason */
OPAL_OUTPUT_VERBOSE((2, orte_grpcomm_base_framework.framework_output,
"%s searching internal dstore for %s",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), key));
if (OPAL_SUCCESS != (rc = opal_dstore.fetch(opal_dstore_peer,
(opal_identifier_t*)(&proc->proc_name),
key, &myvals))) {
ORTE_ERROR_LOG(rc);
OPAL_LIST_DESTRUCT(&myvals);
return rc;
}
} }
/* now retrieve the requested piece */
if (OPAL_SUCCESS != (rc = opal_db.fetch_pointer((opal_identifier_t*)(&proc->proc_name), key, data, type))) {
ORTE_ERROR_LOG(rc);
return rc;
}
} else {
return rc;
} }
} }
/* only one value should have been returned */
kv = (opal_value_t*)opal_list_get_first(&myvals);
if (NULL == kv) {
return OMPI_ERROR;
}
opal_value_unload(kv, data, type);
OPAL_LIST_DESTRUCT(&myvals);
/* update the hostname upon first call to modex-recv for this proc */ /* update the hostname upon first call to modex-recv for this proc */
if (NULL == proc->proc_hostname) { if (NULL == proc->proc_hostname) {
opal_db.fetch_pointer((opal_identifier_t*)(&proc->proc_name), ORTE_DB_HOSTNAME, (void**)&proc->proc_hostname, OPAL_STRING); OBJ_CONSTRUCT(&myvals, opal_list_t);
} if (OPAL_SUCCESS == opal_dstore.fetch(opal_dstore_internal, (opal_identifier_t*)(&proc->proc_name), ORTE_DB_HOSTNAME, &myvals)) {
return OMPI_SUCCESS; kv = (opal_value_t*)opal_list_get_first(&myvals);
} if (NULL != kv) {
opal_value_unload(kv, (void**)&proc->proc_hostname, OPAL_STRING);
int ompi_rte_db_fetch_multiple(const struct ompi_proc_t *proc,
const char *key,
opal_list_t *kvs)
{
int rc;
OPAL_OUTPUT_VERBOSE((2, orte_grpcomm_base_framework.framework_output,
"%s fetch multiple from %s for %s",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
ORTE_NAME_PRINT(&proc->proc_name), key));
/* MPI processes are only concerned with shared info */
if (OPAL_SUCCESS != (rc = opal_db.fetch_multiple((opal_identifier_t*)(&proc->proc_name),
OPAL_SCOPE_GLOBAL, key, kvs))) {
if (direct_modex_enabled) {
/* if we couldn't fetch the data via the db, then we will attempt
* to retrieve it from the target proc
*/
OPAL_OUTPUT_VERBOSE((2, orte_grpcomm_base_framework.framework_output,
"%s requesting direct modex from %s for %s",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
ORTE_NAME_PRINT(&proc->proc_name), key));
if (ORTE_SUCCESS != (rc = direct_modex((orte_process_name_t*)&proc->proc_name, OPAL_SCOPE_GLOBAL))) {
ORTE_ERROR_LOG(rc);
return rc;
} }
/* now retrieve the requested pieces */
if (OPAL_SUCCESS != (rc = opal_db.fetch_multiple((opal_identifier_t*)(&proc->proc_name),
OPAL_SCOPE_GLOBAL, key, kvs))) {
ORTE_ERROR_LOG(rc);
return rc;
}
} else {
return rc;
} }
} OPAL_LIST_DESTRUCT(&myvals);
/* update the hostname upon first call to modex-recv for this proc */
if (NULL == proc->proc_hostname) {
opal_db.fetch_pointer((opal_identifier_t*)(&proc->proc_name), ORTE_DB_HOSTNAME, (void**)&proc->proc_hostname, OPAL_STRING);
} }
return OMPI_SUCCESS; return OMPI_SUCCESS;
} }
int ompi_rte_db_remove(const orte_process_name_t *nm,
const char *key)
{
return opal_db.remove((opal_identifier_t*)nm, key);
}
/* this function executes in the RML event base, and so /* this function executes in the RML event base, and so
* we must take care to protect against threading conflicts * we must take care to protect against threading conflicts

Просмотреть файл

@ -31,7 +31,7 @@
#include "opal/dss/dss.h" #include "opal/dss/dss.h"
#include "opal/util/arch.h" #include "opal/util/arch.h"
#include "opal/util/show_help.h" #include "opal/util/show_help.h"
#include "opal/mca/db/db.h" #include "opal/mca/dstore/dstore.h"
#include "opal/mca/hwloc/base/base.h" #include "opal/mca/hwloc/base/base.h"
#include "ompi/proc/proc.h" #include "ompi/proc/proc.h"
@ -83,9 +83,9 @@ void ompi_proc_destruct(ompi_proc_t* proc)
* destroyed here. It will be destroyed later when the ompi_datatype_finalize is called. * destroyed here. It will be destroyed later when the ompi_datatype_finalize is called.
*/ */
OBJ_RELEASE( proc->proc_convertor ); OBJ_RELEASE( proc->proc_convertor );
/* DO NOT FREE THE HOSTNAME FIELD AS THIS POINTS if (NULL != proc->proc_hostname) {
* TO AN AREA ALLOCATED/FREE'D ELSEWHERE free(proc->proc_hostname);
*/ }
OPAL_THREAD_LOCK(&ompi_proc_lock); OPAL_THREAD_LOCK(&ompi_proc_lock);
opal_list_remove_item(&ompi_proc_list, (opal_list_item_t*)proc); opal_list_remove_item(&ompi_proc_list, (opal_list_item_t*)proc);
OPAL_THREAD_UNLOCK(&ompi_proc_lock); OPAL_THREAD_UNLOCK(&ompi_proc_lock);
@ -113,7 +113,7 @@ int ompi_proc_init(void)
if (i == OMPI_PROC_MY_NAME->vpid) { if (i == OMPI_PROC_MY_NAME->vpid) {
ompi_proc_local_proc = proc; ompi_proc_local_proc = proc;
proc->proc_flags = OPAL_PROC_ALL_LOCAL; proc->proc_flags = OPAL_PROC_ALL_LOCAL;
proc->proc_hostname = ompi_process_info.nodename; proc->proc_hostname = strdup(ompi_process_info.nodename);
proc->proc_arch = opal_local_arch; proc->proc_arch = opal_local_arch;
#if OPAL_ENABLE_HETEROGENEOUS_SUPPORT #if OPAL_ENABLE_HETEROGENEOUS_SUPPORT
/* add our arch to the modex */ /* add our arch to the modex */
@ -129,26 +129,39 @@ int ompi_proc_init(void)
int ompi_proc_set_locality(ompi_proc_t *proc) int ompi_proc_set_locality(ompi_proc_t *proc)
{ {
opal_hwloc_locality_t *hwlocale, locality; opal_hwloc_locality_t locality;
ompi_vpid_t vpid, *vptr; ompi_vpid_t vpid;
int ret; int ret;
opal_list_t myvals;
opal_value_t *kv, kvn;
/* get the locality information - do not use modex recv for /* get the locality information - do not use modex recv for
* this request as that will automatically cause the hostname * this request as that will automatically cause the hostname
* to be loaded as well * to be loaded as well
*/ */
hwlocale = &(proc->proc_flags); OBJ_CONSTRUCT(&myvals, opal_list_t);
if (OMPI_SUCCESS == opal_db.fetch((opal_identifier_t*)&proc->proc_name, OPAL_DB_LOCALITY, if (OMPI_SUCCESS == opal_dstore.fetch(opal_dstore_internal,
(void**)&hwlocale, OPAL_HWLOC_LOCALITY_T)) { (opal_identifier_t*)&proc->proc_name,
OPAL_DSTORE_LOCALITY, &myvals)) {
kv = (opal_value_t*)opal_list_get_first(&myvals);
proc->proc_flags = kv->data.uint16;
OPAL_LIST_DESTRUCT(&myvals);
return OMPI_SUCCESS; return OMPI_SUCCESS;
} }
OPAL_LIST_DESTRUCT(&myvals);
/* if we don't already have it, compute and save it for future use */ /* if we don't already have it, compute and save it for future use */
vptr = &vpid; OBJ_CONSTRUCT(&myvals, opal_list_t);
if (OMPI_SUCCESS != (ret = opal_db.fetch((opal_identifier_t*)&proc->proc_name, OMPI_RTE_NODE_ID, if (OMPI_SUCCESS != (ret = opal_dstore.fetch(opal_dstore_nonpeer,
(void**)&vptr, OPAL_UINT32))) { (opal_identifier_t*)&proc->proc_name,
OMPI_RTE_NODE_ID, &myvals))) {
OPAL_LIST_DESTRUCT(&myvals);
return ret; return ret;
} }
kv = (opal_value_t*)opal_list_get_first(&myvals);
vpid = kv->data.uint32;
OPAL_LIST_DESTRUCT(&myvals);
/* if we are on different nodes, then we are probably non-local */ /* if we are on different nodes, then we are probably non-local */
if (vpid != OMPI_RTE_MY_NODEID) { if (vpid != OMPI_RTE_MY_NODEID) {
locality = OPAL_PROC_NON_LOCAL; locality = OPAL_PROC_NON_LOCAL;
@ -157,9 +170,12 @@ int ompi_proc_set_locality(ompi_proc_t *proc)
* present, then no coprocessors were detected and we can * present, then no coprocessors were detected and we can
* ignore this test * ignore this test
*/ */
vptr = &vpid; OBJ_CONSTRUCT(&myvals, opal_list_t);
if (OMPI_SUCCESS == opal_db.fetch((opal_identifier_t*)&proc->proc_name, OMPI_RTE_HOST_ID, if (OMPI_SUCCESS == opal_dstore.fetch(opal_dstore_internal,
(void**)&vptr, OPAL_UINT32)) { (opal_identifier_t*)&proc->proc_name,
OMPI_RTE_HOST_ID, &myvals)) {
kv = (opal_value_t*)opal_list_get_first(&myvals);
vpid = kv->data.uint32;
/* if this matches my host id, then we are on the same host, /* if this matches my host id, then we are on the same host,
* but not on the same board * but not on the same board
*/ */
@ -169,6 +185,7 @@ int ompi_proc_set_locality(ompi_proc_t *proc)
locality = OPAL_PROC_NON_LOCAL; locality = OPAL_PROC_NON_LOCAL;
} }
} }
OPAL_LIST_DESTRUCT(&myvals);
#endif #endif
} else { } else {
#if OPAL_HAVE_HWLOC #if OPAL_HAVE_HWLOC
@ -176,29 +193,40 @@ int ompi_proc_set_locality(ompi_proc_t *proc)
char *cpu_bitmap; char *cpu_bitmap;
/* retrieve the binding for the other proc */ /* retrieve the binding for the other proc */
if (OMPI_SUCCESS != opal_db.fetch((opal_identifier_t*)&proc->proc_name, OPAL_DB_CPUSET, OBJ_CONSTRUCT(&myvals, opal_list_t);
(void**)&cpu_bitmap, OPAL_STRING)) { if (OMPI_SUCCESS != opal_dstore.fetch(opal_dstore_internal,
(opal_identifier_t*)&proc->proc_name,
OPAL_DSTORE_CPUSET, &myvals)) {
/* we don't know their cpuset, so nothing more we can say */ /* we don't know their cpuset, so nothing more we can say */
locality = OPAL_PROC_ON_NODE; locality = OPAL_PROC_ON_NODE;
} else if (NULL == cpu_bitmap || NULL == ompi_process_info.cpuset) {
/* one or both of us is not bound, so all we can say is we are on the
* same node
*/
locality = OPAL_PROC_ON_NODE;
} else { } else {
/* we share a node - see what else we share */ kv = (opal_value_t*)opal_list_get_first(&myvals);
locality = opal_hwloc_base_get_relative_locality(opal_hwloc_topology, cpu_bitmap = kv->data.string;
ompi_process_info.cpuset, if (NULL == cpu_bitmap || NULL == ompi_process_info.cpuset) {
cpu_bitmap); /* one or both of us is not bound, so all we can say is we are on the
* same node
*/
locality = OPAL_PROC_ON_NODE;
} else {
/* we share a node - see what else we share */
locality = opal_hwloc_base_get_relative_locality(opal_hwloc_topology,
ompi_process_info.cpuset,
cpu_bitmap);
}
} }
OPAL_LIST_DESTRUCT(&myvals);
} }
#else #else
/* all we know is that we share this node */ /* all we know is that we share this node */
locality = OPAL_PROC_ON_NODE; locality = OPAL_PROC_ON_NODE;
#endif #endif
} }
ret = opal_db.store((opal_identifier_t*)&proc, OPAL_SCOPE_INTERNAL, OBJ_CONSTRUCT(&kvn, opal_value_t);
OPAL_DB_LOCALITY, &locality, OPAL_HWLOC_LOCALITY_T); kvn.key = strdup(OPAL_DSTORE_LOCALITY);
kvn.type = OPAL_HWLOC_LOCALITY_T;
kvn.data.uint16 = locality;
ret = opal_dstore.store(opal_dstore_internal, (opal_identifier_t*)&proc, &kvn);
OBJ_DESTRUCT(&kvn);
/* set the proc's local value as well */ /* set the proc's local value as well */
proc->proc_flags = locality; proc->proc_flags = locality;
return ret; return ret;
@ -241,8 +269,9 @@ int ompi_proc_complete_init(void)
* ALL modex info for this proc) will have no appreciable * ALL modex info for this proc) will have no appreciable
* impact on launch scaling * impact on launch scaling
*/ */
ret = ompi_modex_recv_string_pointer(OMPI_DB_HOSTNAME, proc, (void**)&(proc->proc_hostname), OPAL_STRING); ret = ompi_modex_recv_key_value(OMPI_DB_HOSTNAME, proc, (void**)&(proc->proc_hostname), OPAL_STRING);
if (OMPI_SUCCESS != ret) { if (OMPI_SUCCESS != ret) {
errcode = ret;
break; break;
} }
} else { } else {
@ -486,7 +515,7 @@ int ompi_proc_refresh(void) {
* ALL modex info for this proc) will have no appreciable * ALL modex info for this proc) will have no appreciable
* impact on launch scaling * impact on launch scaling
*/ */
ret = ompi_modex_recv_string_pointer(OMPI_DB_HOSTNAME, proc, (void**)&(proc->proc_hostname), OPAL_STRING); ret = ompi_modex_recv_key_value(OMPI_DB_HOSTNAME, proc, (void**)&(proc->proc_hostname), OPAL_STRING);
if (OMPI_SUCCESS != ret) { if (OMPI_SUCCESS != ret) {
break; break;
} }
@ -505,6 +534,9 @@ int ompi_proc_refresh(void) {
/* get the remote architecture */ /* get the remote architecture */
uint32_t* uiptr = &(proc->proc_arch); uint32_t* uiptr = &(proc->proc_arch);
ret = ompi_modex_recv_key_value("OMPI_ARCH", proc, (void**)&uiptr, OPAL_UINT32); ret = ompi_modex_recv_key_value("OMPI_ARCH", proc, (void**)&uiptr, OPAL_UINT32);
if (OMPI_SUCCESS != ret) {
break;
}
/* if arch is different than mine, create a new convertor for this proc */ /* if arch is different than mine, create a new convertor for this proc */
if (proc->proc_arch != opal_local_arch) { if (proc->proc_arch != opal_local_arch) {
OBJ_RELEASE(proc->proc_convertor); OBJ_RELEASE(proc->proc_convertor);
@ -563,14 +595,23 @@ ompi_proc_pack(ompi_proc_t **proclist, int proclistsize,
* data that each process computes about its peers * data that each process computes about its peers
*/ */
OBJ_CONSTRUCT(&data, opal_list_t); OBJ_CONSTRUCT(&data, opal_list_t);
rc = opal_db.fetch_multiple((opal_identifier_t*)&proclist[i]->proc_name, rc = opal_dstore.fetch(opal_dstore_peer,
OPAL_SCOPE_GLOBAL, NULL, &data); (opal_identifier_t*)&proclist[i]->proc_name,
NULL, &data);
if (OPAL_SUCCESS != rc) { if (OPAL_SUCCESS != rc) {
OMPI_ERROR_LOG(rc); OMPI_ERROR_LOG(rc);
num_entries = 0; num_entries = 0;
} else { } else {
/* count the number of entries we will send */ rc = opal_dstore.fetch(opal_dstore_nonpeer,
num_entries = opal_list_get_size(&data); (opal_identifier_t*)&proclist[i]->proc_name,
NULL, &data);
if (OPAL_SUCCESS != rc) {
OMPI_ERROR_LOG(rc);
num_entries = 0;
} else {
/* count the number of entries we will send */
num_entries = opal_list_get_size(&data);
}
} }
/* put the number of entries into the buffer */ /* put the number of entries into the buffer */
@ -657,6 +698,8 @@ ompi_proc_unpack(opal_buffer_t* buf,
int i; int i;
size_t newprocs_len = 0; size_t newprocs_len = 0;
ompi_proc_t **plist=NULL, **newprocs = NULL; ompi_proc_t **plist=NULL, **newprocs = NULL;
opal_list_t myvals;
opal_value_t *kv;
/* do not free plist *ever*, since it is used in the remote group /* do not free plist *ever*, since it is used in the remote group
structure of a communicator */ structure of a communicator */
@ -730,41 +773,51 @@ ompi_proc_unpack(opal_buffer_t* buf,
* Extract the attribute names and values * Extract the attribute names and values
*/ */
for (j = 0; j < num_recvd_entries; j++) { for (j = 0; j < num_recvd_entries; j++) {
opal_value_t *kv;
cnt = 1; cnt = 1;
if (OPAL_SUCCESS != (rc = opal_dss.unpack(buf, &kv, &cnt, OPAL_VALUE))) { if (OPAL_SUCCESS != (rc = opal_dss.unpack(buf, &kv, &cnt, OPAL_VALUE))) {
OMPI_ERROR_LOG(rc); OMPI_ERROR_LOG(rc);
break; break;
} }
/* if this is me, dump the data - we already have it in the db */ /* if this is me, ignore the data - we already have it in the db */
if (OPAL_EQUAL == ompi_rte_compare_name_fields(OMPI_RTE_CMP_ALL, if (OPAL_EQUAL != ompi_rte_compare_name_fields(OMPI_RTE_CMP_ALL,
OMPI_PROC_MY_NAME, &new_name)) { OMPI_PROC_MY_NAME, &new_name)) {
OBJ_RELEASE(kv);
} else {
/* store it in the database */ /* store it in the database */
if (OPAL_SUCCESS != (rc = opal_db.store_pointer((opal_identifier_t*)&new_name, kv))) { if (OPAL_SUCCESS != (rc = opal_dstore.store(opal_dstore_peer,
(opal_identifier_t*)&new_name, kv))) {
OMPI_ERROR_LOG(rc); OMPI_ERROR_LOG(rc);
OBJ_RELEASE(kv);
} }
/* do not release the kv - the db holds that pointer */
} }
OBJ_RELEASE(kv);
} }
#if OPAL_ENABLE_HETEROGENEOUS_SUPPORT #if OPAL_ENABLE_HETEROGENEOUS_SUPPORT
rc = opal_db.fetch((opal_identifier_t*)&new_name, "OMPI_ARCH", OBJ_CONSTRUCT(&myvals, opal_list_t);
rc = opal_dstore.fetch(opal_dstore_peer,
(opal_identifier_t*)&new_name,
"OMPI_ARCH", &myvals);
(void**)&new_arch, OPAL_UINT32); (void**)&new_arch, OPAL_UINT32);
if( OPAL_SUCCESS == rc ) { if( OPAL_SUCCESS == rc ) {
kv = (opal_value_t*)opal_list_get_first(&myvals);
new_arch = kv->data.uint32;
} else {
new_arch = opal_local_arch; new_arch = opal_local_arch;
} }
OPAL_LIST_DESTRUCT(&myvals);
#else #else
new_arch = opal_local_arch; new_arch = opal_local_arch;
#endif #endif
if (ompi_process_info.num_procs < ompi_hostname_cutoff) { if (ompi_process_info.num_procs < ompi_hostname_cutoff) {
/* retrieve the hostname */ /* retrieve the hostname */
rc = opal_db.fetch_pointer((opal_identifier_t*)&new_name, OMPI_DB_HOSTNAME, OBJ_CONSTRUCT(&myvals, opal_list_t);
(void**)&new_hostname, OPAL_STRING); rc = opal_dstore.fetch(opal_dstore_peer,
if( OPAL_SUCCESS != rc ) { (opal_identifier_t*)&new_name,
OMPI_DB_HOSTNAME, &myvals);
if( OPAL_SUCCESS == rc ) {
kv = (opal_value_t*)opal_list_get_first(&myvals);
new_hostname = strdup(kv->data.string);
} else {
new_hostname = NULL; new_hostname = NULL;
} }
OPAL_LIST_DESTRUCT(&myvals);
} else { } else {
/* just set the hostname to NULL for now - we'll fill it in /* just set the hostname to NULL for now - we'll fill it in
* as modex_recv's are called for procs we will talk to * as modex_recv's are called for procs we will talk to

Просмотреть файл

@ -11,6 +11,7 @@
* All rights reserved. * All rights reserved.
* Copyright (c) 2006-2012 Los Alamos National Security, LLC. All rights * Copyright (c) 2006-2012 Los Alamos National Security, LLC. All rights
* reserved. * reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -86,27 +87,6 @@ ompi_modex_recv(const mca_base_component_t *component,
return rc; return rc;
} }
/* return a pointer to the data, but don't create a new copy of it */
int ompi_modex_recv_pointer(const mca_base_component_t *component,
const ompi_proc_t *proc,
void **buffer, opal_data_type_t type)
{
int rc;
char *name = mca_base_component_to_string(component);
/* set defaults */
*buffer = NULL;
if (NULL == name) {
return OMPI_ERR_OUT_OF_RESOURCE;
}
/* the fetch_poointer API returns a pointer to the data */
rc = ompi_rte_db_fetch_pointer(proc, name, buffer, type);
free(name);
return rc;
}
int int
ompi_modex_send_string(const char* key, ompi_modex_send_string(const char* key,
@ -152,22 +132,6 @@ ompi_modex_recv_string(const char* key,
return rc; return rc;
} }
/* return a pointer to the data, but don't create a new copy of it */
int ompi_modex_recv_string_pointer(const char* key,
const ompi_proc_t *source_proc,
void **buffer, opal_data_type_t type)
{
int rc;
/* set defaults */
*buffer = NULL;
/* the fetch_pointer API returns a pointer to the data */
rc = ompi_rte_db_fetch_pointer(source_proc, key, (void**)buffer, type);
return rc;
}
int int
ompi_modex_send_key_value(const char* key, ompi_modex_send_key_value(const char* key,
const void *value, const void *value,

Просмотреть файл

@ -12,6 +12,7 @@
* Copyright (c) 2006-2012 Los Alamos National Security, LLC. All rights * Copyright (c) 2006-2012 Los Alamos National Security, LLC. All rights
* reserved. * reserved.
* Copyright (c) 2008 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -191,10 +192,6 @@ OMPI_DECLSPEC int ompi_modex_recv(const mca_base_component_t *dest_component,
const ompi_proc_t *source_proc, const ompi_proc_t *source_proc,
void **buffer, size_t *size); void **buffer, size_t *size);
OMPI_DECLSPEC int ompi_modex_recv_pointer(const mca_base_component_t *component,
const ompi_proc_t *proc,
void **buffer, opal_data_type_t type);
/** /**
* Receive a buffer from a given peer * Receive a buffer from a given peer
* *
@ -227,10 +224,6 @@ OMPI_DECLSPEC int ompi_modex_recv_string(const char* key,
const ompi_proc_t *source_proc, const ompi_proc_t *source_proc,
void **buffer, size_t *size); void **buffer, size_t *size);
OMPI_DECLSPEC int ompi_modex_recv_string_pointer(const char* key,
const ompi_proc_t *source_proc,
void **buffer, opal_data_type_t type);
/** /**
* Recv a value from a given peer * Recv a value from a given peer
* *

Просмотреть файл

@ -11,6 +11,7 @@
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved. * Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -33,8 +34,17 @@
BEGIN_C_DECLS BEGIN_C_DECLS
/* A non-API function for something that happens in a number
* of places throughout the code base - loading a value into
* an opal_value_t structure
*/
OPAL_DECLSPEC int opal_value_load(opal_value_t *kv,
void *data, opal_data_type_t type);
OPAL_DECLSPEC int opal_value_unload(opal_value_t *kv,
void **data, opal_data_type_t type);
/** /**
* Top-level itnerface function to pack one or more values into a * Top-level interface function to pack one or more values into a
* buffer. * buffer.
* *
* The pack function packs one or more values of a specified type into * The pack function packs one or more values of a specified type into

Просмотреть файл

@ -261,7 +261,6 @@ int opal_dss_copy_value(opal_value_t **dest, opal_value_t *src,
if (NULL != src->key) { if (NULL != src->key) {
p->key = strdup(src->key); p->key = strdup(src->key);
} }
p->scope = src->scope;
p->type = src->type; p->type = src->type;
/* copy the right field */ /* copy the right field */

Просмотреть файл

@ -9,6 +9,7 @@
* University of Stuttgart. All rights reserved. * University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -21,6 +22,8 @@
*/ */
#include "opal_config.h" #include "opal_config.h"
#include "opal/util/error.h"
#include "opal/dss/dss_internal.h" #include "opal/dss/dss_internal.h"
@ -145,3 +148,157 @@ int opal_dss_copy_payload(opal_buffer_t *dest, opal_buffer_t *src)
return OPAL_SUCCESS; return OPAL_SUCCESS;
} }
int opal_value_load(opal_value_t *kv,
void *data, opal_data_type_t type)
{
opal_byte_object_t *boptr;
switch (type) {
case OPAL_STRING:
kv->type = OPAL_STRING;
if (NULL != data) {
kv->data.string = strdup( (const char *) data);
} else {
kv->data.string = NULL;
}
break;
case OPAL_UINT64:
if (NULL == data) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
return OPAL_ERR_BAD_PARAM;
}
kv->type = OPAL_UINT64;
kv->data.uint64 = *(uint64_t*)(data);
break;
case OPAL_UINT32:
if (NULL == data) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
return OPAL_ERR_BAD_PARAM;
}
kv->type = OPAL_UINT32;
kv->data.uint32 = *(uint32_t*)data;
break;
case OPAL_UINT16:
if (NULL == data) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
return OPAL_ERR_BAD_PARAM;
}
kv->type = OPAL_UINT16;
kv->data.uint16 = *(uint16_t*)(data);
break;
case OPAL_INT:
if (NULL == data) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
return OPAL_ERR_BAD_PARAM;
}
kv->type = OPAL_INT;
kv->data.integer = *(int*)(data);
break;
case OPAL_UINT:
if (NULL == data) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
return OPAL_ERR_BAD_PARAM;
}
kv->type = OPAL_UINT;
kv->data.uint = *(unsigned int*)(data);
break;
case OPAL_FLOAT:
if (NULL == data) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
return OPAL_ERR_BAD_PARAM;
}
kv->type = OPAL_FLOAT;
kv->data.fval = *(float*)(data);
break;
case OPAL_BYTE_OBJECT:
kv->type = OPAL_BYTE_OBJECT;
boptr = (opal_byte_object_t*)data;
if (NULL != boptr && NULL != boptr->bytes && 0 < boptr->size) {
kv->data.bo.bytes = (uint8_t *) malloc(boptr->size);
memcpy(kv->data.bo.bytes, boptr->bytes, boptr->size);
kv->data.bo.size = boptr->size;
} else {
kv->data.bo.bytes = NULL;
kv->data.bo.size = 0;
}
break;
default:
OPAL_ERROR_LOG(OPAL_ERR_NOT_SUPPORTED);
return OPAL_ERR_NOT_SUPPORTED;
}
return OPAL_SUCCESS;
}
int opal_value_unload(opal_value_t *kv,
void **data, opal_data_type_t type)
{
opal_byte_object_t *boptr;
switch (type) {
case OPAL_STRING:
if (OPAL_STRING != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
if (NULL != kv->data.string) {
*data = strdup(kv->data.string);
} else {
*data = NULL;
}
break;
case OPAL_UINT64:
if (OPAL_UINT64 != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
memcpy(*data, &kv->data.uint64, 8);
break;
case OPAL_UINT32:
if (OPAL_UINT32 != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
memcpy(*data, &kv->data.uint32, 4);
break;
case OPAL_UINT16:
if (OPAL_UINT16 != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
memcpy(*data, &kv->data.uint16, 2);
break;
case OPAL_INT:
if (OPAL_INT != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
memcpy(*data, &kv->data.integer, sizeof(int));
break;
case OPAL_UINT:
if (OPAL_UINT != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
memcpy(*data, &kv->data.uint, sizeof(unsigned int));
break;
case OPAL_FLOAT:
if (OPAL_FLOAT != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
memcpy(*data, &kv->data.fval, sizeof(float));
break;
case OPAL_BYTE_OBJECT:
if (OPAL_BYTE_OBJECT != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
boptr = (opal_byte_object_t*)malloc(sizeof(opal_byte_object_t));
if (NULL != kv->data.bo.bytes && 0 < kv->data.bo.size) {
boptr->bytes = (uint8_t *) malloc(kv->data.bo.size);
memcpy(boptr->bytes, kv->data.bo.bytes, kv->data.bo.size);
boptr->size = kv->data.bo.size;
} else {
boptr->bytes = NULL;
boptr->size = 0;
}
*data = boptr;
break;
default:
OPAL_ERROR_LOG(OPAL_ERR_NOT_SUPPORTED);
return OPAL_ERR_NOT_SUPPORTED;
}
return OPAL_SUCCESS;
}

Просмотреть файл

@ -72,7 +72,6 @@ static void opal_value_construct(opal_value_t* ptr)
{ {
ptr->key = NULL; ptr->key = NULL;
ptr->type = OPAL_UNDEF; ptr->type = OPAL_UNDEF;
ptr->scope = OPAL_SCOPE_UNDEF;
} }
static void opal_value_destruct(opal_value_t* ptr) static void opal_value_destruct(opal_value_t* ptr)
{ {

Просмотреть файл

@ -688,9 +688,6 @@ int opal_dss_pack_value(opal_buffer_t *buffer, const void *src,
if (OPAL_SUCCESS != (ret = opal_dss_pack_string(buffer, &ptr[i]->key, 1, OPAL_STRING))) { if (OPAL_SUCCESS != (ret = opal_dss_pack_string(buffer, &ptr[i]->key, 1, OPAL_STRING))) {
return ret; return ret;
} }
if (OPAL_SUCCESS != (ret = opal_dss_pack_data_type(buffer, &ptr[i]->scope, 1, OPAL_DATA_SCOPE_T))) {
return ret;
}
if (OPAL_SUCCESS != (ret = opal_dss_pack_data_type(buffer, &ptr[i]->type, 1, OPAL_DATA_TYPE))) { if (OPAL_SUCCESS != (ret = opal_dss_pack_data_type(buffer, &ptr[i]->type, 1, OPAL_DATA_TYPE))) {
return ret; return ret;
} }

Просмотреть файл

@ -538,7 +538,6 @@ int opal_dss_print_node_stat(char **output, char *prefix, opal_node_stats_t *src
int opal_dss_print_value(char **output, char *prefix, opal_value_t *src, opal_data_type_t type) int opal_dss_print_value(char **output, char *prefix, opal_value_t *src, opal_data_type_t type)
{ {
char *prefx; char *prefx;
char *scope;
/* deal with NULL prefix */ /* deal with NULL prefix */
if (NULL == prefix) asprintf(&prefx, " "); if (NULL == prefix) asprintf(&prefx, " ");
@ -551,50 +550,34 @@ int opal_dss_print_value(char **output, char *prefix, opal_value_t *src, opal_da
return OPAL_SUCCESS; return OPAL_SUCCESS;
} }
if (OPAL_SCOPE_UNDEF == src->scope) {
scope = "UNDEF";
} else if (OPAL_SCOPE_PEER == src->scope) {
scope = "PEER";
} else if (OPAL_SCOPE_NON_PEER == src->scope) {
scope = "NON_PEER";
} else if (OPAL_SCOPE_GLOBAL == src->scope) {
scope = "GLOBAL";
} else if (OPAL_SCOPE_INTERNAL == src->scope) {
scope = "INTERNAL";
} else if (OPAL_SCOPE_ALL == src->scope) {
scope = "ALL";
} else {
scope = "INTERNAL";
}
switch (src->type) { switch (src->type) {
case OPAL_STRING: case OPAL_STRING:
asprintf(output, "%sOPAL_VALUE: Data type: OPAL_STRING\tKey: %s\tScope:%s\tValue: %s", asprintf(output, "%sOPAL_VALUE: Data type: OPAL_STRING\tKey: %s\tValue: %s",
prefx, src->key, scope, src->data.string); prefx, src->key, src->data.string);
break; break;
case OPAL_INT16: case OPAL_INT16:
asprintf(output, "%sOPAL_VALUE: Data type: OPAL_STRING\tKey: %s\tScope:%s\tValue: %d", asprintf(output, "%sOPAL_VALUE: Data type: OPAL_STRING\tKey: %s\tValue: %d",
prefx, src->key, scope, (int)src->data.int16); prefx, src->key, (int)src->data.int16);
break; break;
case OPAL_INT32: case OPAL_INT32:
asprintf(output, "%sOPAL_VALUE: Data type: OPAL_INT32\tKey: %s\tScope:%s\tValue: %d", asprintf(output, "%sOPAL_VALUE: Data type: OPAL_INT32\tKey: %s\tValue: %d",
prefx, src->key, scope, src->data.int32); prefx, src->key, src->data.int32);
break; break;
case OPAL_PID: case OPAL_PID:
asprintf(output, "%sOPAL_VALUE: Data type: OPAL_STRING\tKey: %s\tScope:%s\tValue: %lu", asprintf(output, "%sOPAL_VALUE: Data type: OPAL_STRING\tKey: %s\tValue: %lu",
prefx, src->key, scope, (unsigned long)src->data.pid); prefx, src->key, (unsigned long)src->data.pid);
break; break;
case OPAL_FLOAT: case OPAL_FLOAT:
asprintf(output, "%sOPAL_VALUE: Data type: OPAL_FLOAT\tKey: %s\tScope:%s\tValue: %f", asprintf(output, "%sOPAL_VALUE: Data type: OPAL_FLOAT\tKey: %s\tValue: %f",
prefx, src->key, scope, src->data.fval); prefx, src->key, src->data.fval);
break; break;
case OPAL_TIMEVAL: case OPAL_TIMEVAL:
asprintf(output, "%sOPAL_VALUE: Data type: OPAL_TIMEVAL\tKey: %s\tScope:%s\tValue: %ld.%06ld", prefx, asprintf(output, "%sOPAL_VALUE: Data type: OPAL_TIMEVAL\tKey: %s\tValue: %ld.%06ld", prefx,
src->key, scope, (long)src->data.tv.tv_sec, (long)src->data.tv.tv_usec); src->key, (long)src->data.tv.tv_sec, (long)src->data.tv.tv_usec);
break; break;
default: default:
asprintf(output, "%sOPAL_VALUE: Data type: UNKNOWN\tKey: %s\tScope:%s\tValue: UNPRINTABLE", asprintf(output, "%sOPAL_VALUE: Data type: UNKNOWN\tKey: %s\tValue: UNPRINTABLE",
prefx, src->key, scope); prefx, src->key);
break; break;
} }
free(prefx); free(prefx);

Просмотреть файл

@ -96,33 +96,10 @@ typedef uint64_t opal_identifier_t;
#define OPAL_VALUE2_GREATER -1 #define OPAL_VALUE2_GREATER -1
#define OPAL_EQUAL 0 #define OPAL_EQUAL 0
/* define a flag to indicate the scope of data being
* stored in the database. The following options are supported:
*
* PEER: data to be shared with our peers
* NON_PEER: data to be shared only with non-peer
* processes (i.e., processes from other jobs)
* GLOBAL: data to be shared with all processes
* INTERNAL: data is to be internally stored in this app
* ALL: any of the above
*
* REFER: indicates the value is stored by reference
*/
typedef uint8_t opal_scope_t;
#define OPAL_SCOPE_UNDEF 0x00
#define OPAL_SCOPE_PEER 0x01
#define OPAL_SCOPE_NON_PEER 0x02
#define OPAL_SCOPE_GLOBAL 0x03
#define OPAL_SCOPE_INTERNAL 0x08
#define OPAL_SCOPE_ALL 0x0f
#define OPAL_SCOPE_REFER 0x10
#define OPAL_DATA_SCOPE_T OPAL_UINT8
/* Data value object */ /* Data value object */
typedef struct { typedef struct {
opal_list_item_t super; /* required for this to be on lists */ opal_list_item_t super; /* required for this to be on lists */
char *key; /* key string */ char *key; /* key string */
opal_scope_t scope;
opal_data_type_t type; /* the type of value stored */ opal_data_type_t type; /* the type of value stored */
union { union {
uint8_t byte; uint8_t byte;

Просмотреть файл

@ -920,10 +920,6 @@ int opal_dss_unpack_value(opal_buffer_t *buffer, void *dest,
return ret; return ret;
} }
m=1; m=1;
if (OPAL_SUCCESS != (ret = opal_dss_unpack_data_type(buffer, &ptr[i]->scope, &m, OPAL_DATA_SCOPE_T))) {
return ret;
}
m=1;
if (OPAL_SUCCESS != (ret = opal_dss_unpack_data_type(buffer, &ptr[i]->type, &m, OPAL_DATA_TYPE))) { if (OPAL_SUCCESS != (ret = opal_dss_unpack_data_type(buffer, &ptr[i]->type, &m, OPAL_DATA_TYPE))) {
return ret; return ret;
} }

Просмотреть файл

@ -5,7 +5,7 @@
* Copyright (c) 2011 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2011 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2011-2013 Los Alamos National Security, LLC. All * Copyright (c) 2011-2013 Los Alamos National Security, LLC. All
* rights reserved. * rights reserved.
* Copyright (c) 2013 Intel, Inc. All rights reserved. * Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -17,6 +17,8 @@
#include "opal/constants.h" #include "opal/constants.h"
#include "opal/types.h" #include "opal/types.h"
#include "opal/util/output.h"
#include <string.h> #include <string.h>
#include <pmi.h> #include <pmi.h>
#if WANT_PMI2_SUPPORT #if WANT_PMI2_SUPPORT
@ -38,6 +40,8 @@ bool mca_common_pmi_init (void) {
{ {
int spawned, size, rank, appnum; int spawned, size, rank, appnum;
opal_output(0, "INIT PMI");
/* if we can't startup PMI, we can't be used */ /* if we can't startup PMI, we can't be used */
if (PMI2_Initialized ()) { if (PMI2_Initialized ()) {
return true; return true;

Просмотреть файл

@ -1,78 +0,0 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/** @file:
*/
#ifndef MCA_DB_BASE_H
#define MCA_DB_BASE_H
#include "opal_config.h"
#include "opal/types.h"
#include "opal/mca/mca.h"
#include "opal/mca/base/mca_base_framework.h"
#include "opal/class/opal_list.h"
#include "opal/dss/dss.h"
#include "opal/mca/db/db.h"
BEGIN_C_DECLS
OPAL_DECLSPEC extern mca_base_framework_t opal_db_base_framework;
/**
* Select a db module
*/
OPAL_DECLSPEC int opal_db_base_select(bool restrict_local);
typedef struct {
opal_list_item_t super;
int pri;
opal_db_base_module_t *module;
opal_db_base_component_t *component;
} opal_db_active_module_t;
OBJ_CLASS_DECLARATION(opal_db_active_module_t);
typedef struct {
opal_identifier_t my_id;
bool id_set;
opal_list_t store_order;
opal_list_t fetch_order;
} opal_db_base_t;
OPAL_DECLSPEC extern opal_db_base_t opal_db_base;
OPAL_DECLSPEC void opal_db_base_set_id(const opal_identifier_t *proc);
OPAL_DECLSPEC int opal_db_base_store(const opal_identifier_t *proc,
opal_scope_t scope,
const char *key, const void *object,
opal_data_type_t type);
OPAL_DECLSPEC int opal_db_base_store_pointer(const opal_identifier_t *proc,
opal_value_t *kv);
OPAL_DECLSPEC int opal_db_base_fetch(const opal_identifier_t *proc,
const char *key, void **data,
opal_data_type_t type);
OPAL_DECLSPEC int opal_db_base_fetch_pointer(const opal_identifier_t *proc,
const char *key,
void **data, opal_data_type_t type);
OPAL_DECLSPEC int opal_db_base_fetch_multiple(const opal_identifier_t *proc,
opal_scope_t scope,
const char *key,
opal_list_t *kvs);
OPAL_DECLSPEC int opal_db_base_remove_data(const opal_identifier_t *proc,
const char *key);
OPAL_DECLSPEC int opal_db_base_add_log(const char *table,
const opal_value_t *kvs, int nkvs);
OPAL_DECLSPEC void opal_db_base_commit(const opal_identifier_t *proc);
END_C_DECLS
#endif

Просмотреть файл

@ -1,272 +0,0 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013 Intel Inc. All rights reserved
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal_stdint.h"
#include "opal/mca/mca.h"
#include "opal/util/error.h"
#include "opal/util/output.h"
#include "opal/mca/base/base.h"
#include "opal/dss/dss_types.h"
#include "opal/mca/db/base/base.h"
void opal_db_base_set_id(const opal_identifier_t *proc)
{
/* to protect alignment, copy the data across */
memcpy(&opal_db_base.my_id, proc, sizeof(opal_identifier_t));
opal_db_base.id_set = true;
}
int opal_db_base_store(const opal_identifier_t *proc,
opal_scope_t scope,
const char *key, const void *object,
opal_data_type_t type)
{
opal_db_active_module_t *mod;
int rc;
if (!opal_db_base.id_set) {
return OPAL_ERR_FATAL;
}
/* cycle thru the active modules until one agrees to perform the op */
OPAL_LIST_FOREACH(mod, &opal_db_base.store_order, opal_db_active_module_t) {
if (NULL == mod->module->store) {
continue;
}
if (OPAL_SUCCESS == (rc = mod->module->store(proc, scope, key, object, type))) {
return OPAL_SUCCESS;
}
/* modules return "next option" if they didn't perform
* the operation - anything else is a true error.
*/
if (OPAL_ERR_TAKE_NEXT_OPTION != rc) {
OPAL_ERROR_LOG(rc);
return rc;
}
}
/* we did not perform any operation, that's an error */
OPAL_ERROR_LOG(OPAL_ERROR);
return OPAL_ERROR;
}
int opal_db_base_store_pointer(const opal_identifier_t *proc,
opal_value_t *kv)
{
opal_db_active_module_t *mod;
int rc;
if (!opal_db_base.id_set) {
return OPAL_ERR_FATAL;
}
/* cycle thru the active modules until one agrees to perform the op */
OPAL_LIST_FOREACH(mod, &opal_db_base.store_order, opal_db_active_module_t) {
if (NULL == mod->module->store_pointer) {
continue;
}
if (OPAL_SUCCESS == (rc = mod->module->store_pointer(proc, kv))) {
return OPAL_SUCCESS;
}
/* modules return "next option" if they didn't perform
* the operation - anything else is a true error.
*/
if (OPAL_ERR_TAKE_NEXT_OPTION != rc) {
OPAL_ERROR_LOG(rc);
return rc;
}
}
/* we did not perform any operation, that's an error */
OPAL_ERROR_LOG(OPAL_ERROR);
return OPAL_ERROR;
}
void opal_db_base_commit(const opal_identifier_t *proc)
{
opal_db_active_module_t *mod;
/* cycle thru the active modules giving each a chance to perform the op */
OPAL_LIST_FOREACH(mod, &opal_db_base.store_order, opal_db_active_module_t) {
if (NULL == mod->module->commit) {
continue;
}
mod->module->commit(proc);
}
}
int opal_db_base_fetch(const opal_identifier_t *proc,
const char *key, void **data,
opal_data_type_t type)
{
opal_db_active_module_t *mod;
int rc, i;
if (!opal_db_base.id_set) {
return OPAL_ERR_FATAL;
}
/* cycle thru the active modules until one agrees to perform the op.
* we cycle thru the list of modules twice - this allows us to check
* a local store first, then attempt to obtain the data from an
* external store that puts it in the local store
*/
for(i = 0; i < 2; i++) {
OPAL_LIST_FOREACH(mod, &opal_db_base.fetch_order, opal_db_active_module_t) {
if (NULL == mod->module->fetch) {
continue;
}
if (OPAL_SUCCESS == (rc = mod->module->fetch(proc, key, data, type))) {
return OPAL_SUCCESS;
}
/* modules return "next option" if they didn't perform
* the operation - anything else is a true error.
*/
if (OPAL_ERR_TAKE_NEXT_OPTION != rc) {
return rc;
}
}
}
/* if we get here without performing the operation, that's an error */
return OPAL_ERR_DATA_VALUE_NOT_FOUND;
}
int opal_db_base_fetch_pointer(const opal_identifier_t *proc,
const char *key,
void **data, opal_data_type_t type)
{
opal_db_active_module_t *mod;
int rc, i;
if (!opal_db_base.id_set) {
return OPAL_ERR_FATAL;
}
/* cycle thru the active modules until one agrees to perform the op.
* we cycle thru the list of modules twice - this allows us to check
* a local store first, then attempt to obtain the data from an
* external store that puts it in the local store
*/
for(i = 0; i < 2; i++) {
OPAL_LIST_FOREACH(mod, &opal_db_base.fetch_order, opal_db_active_module_t) {
if (NULL == mod->module->fetch_pointer) {
continue;
}
if (OPAL_SUCCESS == (rc = mod->module->fetch_pointer(proc, key, data, type))) {
return OPAL_SUCCESS;
}
/* modules return "next option" if they didn't perform
* the operation - anything else is a true error.
*/
if (OPAL_ERR_TAKE_NEXT_OPTION != rc) {
return rc;
}
}
}
/* if we get here without performing the operation, that's an error */
return OPAL_ERR_DATA_VALUE_NOT_FOUND;
}
int opal_db_base_fetch_multiple(const opal_identifier_t *proc,
opal_scope_t scope,
const char *key,
opal_list_t *kvs)
{
opal_db_active_module_t *mod;
int rc;
if (!opal_db_base.id_set) {
return OPAL_ERR_FATAL;
}
/* cycle thru the active modules until one agrees to perform the op */
OPAL_LIST_FOREACH(mod, &opal_db_base.fetch_order, opal_db_active_module_t) {
if (NULL == mod->module->fetch_multiple) {
continue;
}
if (OPAL_SUCCESS == (rc = mod->module->fetch_multiple(proc, scope, key, kvs))) {
return OPAL_SUCCESS;
}
/* modules return "next option" if they didn't perform
* the operation - anything else is a true error.
*/
if (OPAL_ERR_TAKE_NEXT_OPTION != rc) {
return rc;
}
}
/* if we get here without performing the operation, that's an error */
return OPAL_ERR_DATA_VALUE_NOT_FOUND;
}
int opal_db_base_remove_data(const opal_identifier_t *proc,
const char *key)
{
opal_db_active_module_t *mod;
int rc;
/* cycle thru the actiove modules until one agrees to perform the op */
OPAL_LIST_FOREACH(mod, &opal_db_base.store_order, opal_db_active_module_t) {
if (NULL == mod->module->remove) {
continue;
}
if (OPAL_SUCCESS == (rc = mod->module->remove(proc, key))) {
return OPAL_SUCCESS;
}
/* modules return "next option" if they didn't perform
* the operation - anything else is a true error.
*/
if (OPAL_ERR_TAKE_NEXT_OPTION != rc) {
OPAL_ERROR_LOG(rc);
return rc;
}
}
/* if we get here without performing the operation, that's an error */
OPAL_ERROR_LOG(OPAL_ERROR);
return OPAL_ERROR;
}
int opal_db_base_add_log(const char *table,
const opal_value_t *kvs, int nkvs)
{
opal_db_active_module_t *mod;
int rc;
/* cycle thru the active modules until one agrees to perform the op */
OPAL_LIST_FOREACH(mod, &opal_db_base.store_order, opal_db_active_module_t) {
if (NULL == mod->module->add_log) {
continue;
}
if (OPAL_SUCCESS == (rc = mod->module->add_log(table, kvs, nkvs))) {
return OPAL_SUCCESS;
}
/* modules return "next option" if they didn't perform
* the operation - anything else is a true error.
*/
if (OPAL_ERR_TAKE_NEXT_OPTION != rc) {
/* don't error log it here */
return rc;
}
}
/* if we get here without performing the operation, let the caller know */
return OPAL_ERROR;
}

Просмотреть файл

@ -1,78 +0,0 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal/mca/mca.h"
#include "opal/util/output.h"
#include "opal/mca/base/base.h"
#include "opal/dss/dss_types.h"
#include "opal/mca/db/base/base.h"
/*
* The following file was created by configure. It contains extern
* dbments and the definition of an array of pointers to each
* module's public mca_base_module_t struct.
*/
#include "opal/mca/db/base/static-components.h"
opal_db_base_module_t opal_db = {
NULL,
NULL,
opal_db_base_set_id,
opal_db_base_store,
opal_db_base_store_pointer,
opal_db_base_commit,
opal_db_base_fetch,
opal_db_base_fetch_pointer,
opal_db_base_fetch_multiple,
opal_db_base_remove_data,
opal_db_base_add_log
};
opal_db_base_t opal_db_base;
static int opal_db_base_close(void)
{
opal_db_active_module_t *mod;
/* cycle across all the active db modules and let them cleanup - order
* doesn't matter in this case
*/
OPAL_LIST_FOREACH(mod, &opal_db_base.store_order, opal_db_active_module_t) {
if (NULL != mod->module->finalize) {
mod->module->finalize();
}
}
return mca_base_framework_components_close(&opal_db_base_framework, NULL);
}
static int opal_db_base_open(mca_base_open_flag_t flags)
{
opal_db_base.my_id = 0;
opal_db_base.id_set = false;
OBJ_CONSTRUCT(&opal_db_base.fetch_order, opal_list_t);
OBJ_CONSTRUCT(&opal_db_base.store_order, opal_list_t);
/* Open up all available components */
return mca_base_framework_components_open(&opal_db_base_framework, flags);
}
MCA_BASE_FRAMEWORK_DECLARE(opal, db, NULL, NULL, opal_db_base_open, opal_db_base_close,
mca_db_base_static_components, 0);
OBJ_CLASS_INSTANCE(opal_db_active_module_t,
opal_list_item_t,
NULL, NULL);

Просмотреть файл

@ -1,136 +0,0 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal/class/opal_list.h"
#include "opal/mca/mca.h"
#include "opal/mca/base/base.h"
#include "opal/mca/base/mca_base_component_repository.h"
#include "opal/util/output.h"
#include "opal/mca/db/base/base.h"
static bool selected = false;
int
opal_db_base_select(bool restrict_local)
{
mca_base_component_list_item_t *cli = NULL;
opal_db_base_component_t *component = NULL;
opal_db_base_module_t *module = NULL;
opal_db_active_module_t *nmodule, *mod;
int rc, fetch, store;
bool inserted;
if (selected) {
/* ensure we don't do this twice */
return OPAL_SUCCESS;
}
selected = true;
/* Query all available components and ask if they have a module */
OPAL_LIST_FOREACH(cli, &opal_db_base_framework.framework_components, mca_base_component_list_item_t) {
component = (opal_db_base_component_t *) cli->cli_component;
opal_output_verbose(5, opal_db_base_framework.framework_output,
"mca:db:select: checking available component %s",
component->base_version.mca_component_name);
/* If there's no query function, skip it */
if (NULL == component->query) {
opal_output_verbose(5, opal_db_base_framework.framework_output,
"mca:db:select: Skipping component [%s]. It does not implement a query function",
component->base_version.mca_component_name );
continue;
}
/* Query the component */
opal_output_verbose(5, opal_db_base_framework.framework_output,
"mca:db:select: Querying component [%s]",
component->base_version.mca_component_name);
rc = component->query(&module, &store, &fetch, restrict_local);
/* If no module was returned, then skip component */
if (OPAL_SUCCESS != rc || NULL == module) {
opal_output_verbose(5, opal_db_base_framework.framework_output,
"mca:db:select: Skipping component [%s]. Query failed to return a module",
component->base_version.mca_component_name );
continue;
}
/* attempt to initialize the module */
if (NULL != module->init) {
if (OPAL_SUCCESS != (rc = module->init())) {
/* skip the module */
continue;
}
}
/* If we got a module, add to the store list */
nmodule = OBJ_NEW(opal_db_active_module_t);
nmodule->pri = store;
nmodule->module = module;
nmodule->component = component;
/* maintain priority order */
inserted = false;
OPAL_LIST_FOREACH(mod, &opal_db_base.store_order, opal_db_active_module_t) {
if (store > mod->pri) {
opal_list_insert_pos(&opal_db_base.store_order,
&mod->super, &nmodule->super);
inserted = true;
break;
}
}
if (!inserted) {
/* must be lowest priority - add to end */
opal_list_append(&opal_db_base.store_order, &nmodule->super);
}
/* do the same for fetch list */
nmodule = OBJ_NEW(opal_db_active_module_t);
nmodule->pri = fetch;
nmodule->module = module;
nmodule->component = component;
/* maintain priority order */
inserted = false;
OPAL_LIST_FOREACH(mod, &opal_db_base.fetch_order, opal_db_active_module_t) {
if (fetch > mod->pri) {
opal_list_insert_pos(&opal_db_base.fetch_order,
&mod->super, &nmodule->super);
inserted = true;
break;
}
}
if (!inserted) {
/* must be lowest priority - add to end */
opal_list_append(&opal_db_base.fetch_order, &nmodule->super);
}
}
if (4 < opal_output_get_verbosity(opal_db_base_framework.framework_output)) {
opal_output(0, "Final db priorities");
/* show the prioritized list */
OPAL_LIST_FOREACH(mod, &opal_db_base.store_order, opal_db_active_module_t) {
opal_output(0, "\tComponent: %s Store Priority: %d",
mod->component->base_version.mca_component_name, mod->pri);
}
OPAL_LIST_FOREACH(mod, &opal_db_base.fetch_order, opal_db_active_module_t) {
opal_output(0, "\tComponent: %s Fetch Priority: %d",
mod->component->base_version.mca_component_name, mod->pri);
}
}
return OPAL_SUCCESS;;
}

Просмотреть файл

@ -1,205 +0,0 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/** @file:
*
* The Database Framework
*
*/
#ifndef OPAL_DB_H
#define OPAL_DB_H
#include "opal_config.h"
#include "opal/types.h"
#include "opal/mca/mca.h"
#include "opal/dss/dss_types.h"
#include "opal/mca/db/db_types.h"
/**
* DATABASE DESIGN
*
* Data is always associated with a given opal identifier. Individual
* modules may store the data local to the calling process, or on one
* or more remote sites. Time lags between when data is written and
* when it is available at a remote proc will therefore exist.
*/
BEGIN_C_DECLS
/*
* Initialize the module
*/
typedef int (*opal_db_base_module_init_fn_t)(void);
/*
* Finalize the module
*/
typedef void (*opal_db_base_module_finalize_fn_t)(void);
/*
* Set local identifier - pass in an opal_identifier_t value
* that identifies this process. Used to determine whether or
* not to publish values outside the process. Values stored
* for other processes are never published as it is assumed
* that each process is responsible for determining its own
* need to publish a given piece of data
*/
typedef void (*opal_db_base_module_set_id_fn_t)(const opal_identifier_t *proc);
/*
* Store a copy of data in the database - overwrites if already present. The
* data is copied into the database and therefore does not need to be preserved
* by the caller. The scope of the data determines where it is stored:
*
* - if the proc id is NOT my own, or the scope is INTERNAL, then the
* data is stored in my own internal storage system. Data for procs
* other than myself is NEVER published to the outside world
*
* - if the proc id is my own, and the scope is LOCAL, then the data
* is both stored internally AND pushed to the outside world. If the
* external API supports node-local operations, then the data will
* only be pushed to procs that are on the same node as ourselves.
* Otherwise, the data will be published GLOBAL.
*
* - if the proc id is my own, and the scope is GLOBAL, then the data
* is both stored internally AND pushed to the outside world.
&
*/
typedef int (*opal_db_base_module_store_fn_t)(const opal_identifier_t *proc,
opal_scope_t scope,
const char *key, const void *data,
opal_data_type_t type);
/*
* Store a pointer to data in the database - data must be retained by the user.
* This allows users to share data across the code base without consuming
* additional memory, but while retaining local access. Scope rules are
* as outlined above
*/
typedef int (*opal_db_base_module_store_pointer_fn_t)(const opal_identifier_t *proc,
opal_value_t *kv);
/*
* Commit data to the database - used to generate a commit of data
* to an external key-value store such as PMI
*/
typedef void (*opal_db_base_module_commit_fn_t)(const opal_identifier_t *proc);
/*
* Retrieve data
*
* Retrieve data for the given proc associated with the specified key. Wildcards
* are supported here as well. Caller is responsible for releasing any returned
* object.
*/
typedef int (*opal_db_base_module_fetch_fn_t)(const opal_identifier_t *proc,
const char *key,
void **data, opal_data_type_t type);
/*
* Retrieve a pointer to data
*
* Retrieve a pointer to the data for the given proc associated with the specified key. Wildcards
* are supported here as well. Callers are cautioned against modifying the data as this
* will directly alter information in the database! A local copy of the data should be made
* wherever modification is possible.
*/
typedef int (*opal_db_base_module_fetch_pointer_fn_t)(const opal_identifier_t *proc,
const char *key,
void **data, opal_data_type_t type);
/*
* Retrieve multiple data elements
*
* Retrieve data for the given proc associated with the specified key. Wildcards
* are supported here as well (key==NULL implies return all key-value pairs). Caller
* is responsible for releasing the objects on the list. Scope rules are as described above.
* A NULL identifer parameter indicates that data for all procs is to be returned.
* The scope of the data is matched against the scope of the data when
* stored. Note that a call to fetch data with a GLOBAL scope will return data
* that was stored as PEER or NON_PEER, but not data stored as INTERNAL. A scope
* of ALL will return data stored under any scope.
*/
typedef int (*opal_db_base_module_fetch_multiple_fn_t)(const opal_identifier_t *proc,
opal_scope_t scope,
const char *key,
opal_list_t *kvs);
/*
* Delete data
*
* Delete the data associated with the specified key. If a NULL key is provided,
* all data for the given proc will be deleted.
*
* This function also supports wildcard values in the proc field. A NULL proc indicates
* that ALL data in the database is to be purged. A WILDCARD vpid will delete all matching
* keys from that jobid. Etc.
*/
typedef int (*opal_db_base_module_remove_fn_t)(const opal_identifier_t *proc, const char *key);
/*
* Log data
*
* Insert statistical, non-process oriented data into a logging system.
*/
typedef int (*opal_db_base_module_add_log_fn_t)(const char *table, const opal_value_t *kvs, int nkvs);
/*
* the standard module data structure
*/
struct opal_db_base_module_1_0_0_t {
opal_db_base_module_init_fn_t init;
opal_db_base_module_finalize_fn_t finalize;
opal_db_base_module_set_id_fn_t set_id;
opal_db_base_module_store_fn_t store;
opal_db_base_module_store_pointer_fn_t store_pointer;
opal_db_base_module_commit_fn_t commit;
opal_db_base_module_fetch_fn_t fetch;
opal_db_base_module_fetch_pointer_fn_t fetch_pointer;
opal_db_base_module_fetch_multiple_fn_t fetch_multiple;
opal_db_base_module_remove_fn_t remove;
opal_db_base_module_add_log_fn_t add_log;
};
typedef struct opal_db_base_module_1_0_0_t opal_db_base_module_1_0_0_t;
typedef struct opal_db_base_module_1_0_0_t opal_db_base_module_t;
/* we need to get two priorities back from our components, so
* define a customized query function for our use
*/
typedef int (*opal_db_component_query_fn_t)(opal_db_base_module_t **module,
int *store_priority,
int *fetch_priority,
bool restrict_local);
/*
* the standard component data structure
*/
struct opal_db_base_component_1_0_0_t {
mca_base_component_t base_version;
mca_base_component_data_t base_data;
opal_db_component_query_fn_t query;
};
typedef struct opal_db_base_component_1_0_0_t opal_db_base_component_1_0_0_t;
typedef struct opal_db_base_component_1_0_0_t opal_db_base_component_t;
/*
* Macro for use in components that are of type db
*/
#define OPAL_DB_BASE_VERSION_1_0_0 \
MCA_BASE_VERSION_2_0_0, \
"db", 1, 0, 0
/* Global structure for accessing DB functions */
OPAL_DECLSPEC extern opal_db_base_module_t opal_db; /* holds base function pointers */
END_C_DECLS
#endif

Просмотреть файл

@ -1,673 +0,0 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2004-2011 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2011-2013 Los Alamos National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#include "opal_config.h"
#include "opal/constants.h"
#include <time.h>
#include <string.h>
#include "opal_stdint.h"
#include "opal/class/opal_hash_table.h"
#include "opal/class/opal_pointer_array.h"
#include "opal/dss/dss_types.h"
#include "opal/util/error.h"
#include "opal/util/output.h"
#include "opal/util/show_help.h"
#include "opal/mca/db/base/base.h"
#include "db_hash.h"
static int init(void);
static void finalize(void);
static int store(const opal_identifier_t *proc,
opal_scope_t scope,
const char *key, const void *object,
opal_data_type_t type);
static int store_pointer(const opal_identifier_t *proc,
opal_value_t *kv);
static int fetch(const opal_identifier_t *proc,
const char *key, void **data,
opal_data_type_t type);
static int fetch_pointer(const opal_identifier_t *proc,
const char *key,
void **data, opal_data_type_t type);
static int fetch_multiple(const opal_identifier_t *proc,
opal_scope_t scope,
const char *key,
opal_list_t *kvs);
static int remove_data(const opal_identifier_t *proc, const char *key);
opal_db_base_module_t opal_db_hash_module = {
init,
finalize,
opal_db_base_set_id,
store,
store_pointer,
NULL,
fetch,
fetch_pointer,
fetch_multiple,
remove_data,
NULL
};
/* Local "globals" */
static opal_hash_table_t hash_data;
/**
* Data for a particular opal process
* The name association is maintained in the
* proc_data hash table.
*/
typedef struct {
/** Structure can be put on lists (including in hash tables) */
opal_list_item_t super;
/* List of opal_value_t structures containing all data
received from this process, sorted by key. */
opal_list_t data;
} proc_data_t;
static void proc_data_construct(proc_data_t *ptr)
{
OBJ_CONSTRUCT(&ptr->data, opal_list_t);
}
static void proc_data_destruct(proc_data_t *ptr)
{
opal_list_item_t *item;
while (NULL != (item = opal_list_remove_first(&ptr->data))) {
OBJ_RELEASE(item);
}
OBJ_DESTRUCT(&ptr->data);
}
OBJ_CLASS_INSTANCE(proc_data_t, opal_list_item_t,
proc_data_construct, proc_data_destruct);
static int init(void)
{
OBJ_CONSTRUCT(&hash_data, opal_hash_table_t);
opal_hash_table_init(&hash_data, 256);
return OPAL_SUCCESS;
}
static void finalize(void)
{
proc_data_t *proc_data;
uint64_t key;
char *node;
/* to assist in getting a clean valgrind, cycle thru the hash table
* and release all data stored in it
*/
if (OPAL_SUCCESS == opal_hash_table_get_first_key_uint64(&hash_data, &key,
(void**)&proc_data,
(void**)&node)) {
if (NULL != proc_data) {
OBJ_RELEASE(proc_data);
}
while (OPAL_SUCCESS == opal_hash_table_get_next_key_uint64(&hash_data, &key,
(void**)&proc_data,
node, (void**)&node)) {
if (NULL != proc_data) {
OBJ_RELEASE(proc_data);
}
}
}
OBJ_DESTRUCT(&hash_data);
}
/**
* Find data for a given key in a given proc_data_t
* container.
*/
static opal_value_t* lookup_keyval(proc_data_t *proc_data,
const char *key)
{
opal_value_t *kv = NULL;
for (kv = (opal_value_t *) opal_list_get_first(&proc_data->data);
kv != (opal_value_t *) opal_list_get_end(&proc_data->data);
kv = (opal_value_t *) opal_list_get_next(kv)) {
if (0 == strcmp(key, kv->key)) {
return kv;
}
}
return NULL;
}
/**
* Find proc_data_t container associated with given
* opal_identifier_t.
*/
static proc_data_t* lookup_opal_proc(opal_hash_table_t *jtable, opal_identifier_t id)
{
proc_data_t *proc_data = NULL;
opal_hash_table_get_value_uint64(jtable, id, (void**)&proc_data);
if (NULL == proc_data) {
/* The proc clearly exists, so create a data structure for it */
proc_data = OBJ_NEW(proc_data_t);
if (NULL == proc_data) {
opal_output(0, "db:hash:lookup_opal_proc: unable to allocate proc_data_t\n");
return NULL;
}
opal_hash_table_set_value_uint64(jtable, id, proc_data);
}
return proc_data;
}
static int store(const opal_identifier_t *uid,
opal_scope_t scope,
const char *key, const void *data,
opal_data_type_t type)
{
proc_data_t *proc_data;
opal_value_t *kv;
opal_byte_object_t *boptr;
opal_identifier_t id;
/* data must have an assigned scope */
if (OPAL_SCOPE_UNDEF == scope) {
return OPAL_ERR_BAD_PARAM;
}
/* to protect alignment, copy the data across */
memcpy(&id, uid, sizeof(opal_identifier_t));
/* we are at the bottom of the store priorities, so
* if this fell to us, we store it
*/
opal_output_verbose(1, opal_db_base_framework.framework_output,
"db:hash:store storing data for proc %" PRIu64 " for scope %d",
id, (int)scope);
/* lookup the proc data object for this proc */
if (NULL == (proc_data = lookup_opal_proc(&hash_data, id))) {
/* unrecoverable error */
OPAL_OUTPUT_VERBOSE((5, opal_db_base_framework.framework_output,
"db:hash:store: storing key %s[%s] for proc %" PRIu64 " unrecoverably failed",
key, opal_dss.lookup_data_type(type), id));
return OPAL_ERR_OUT_OF_RESOURCE;
}
/* see if we already have this key in the data - means we are updating
* a pre-existing value
*/
kv = lookup_keyval(proc_data, key);
OPAL_OUTPUT_VERBOSE((5, opal_db_base_framework.framework_output,
"db:hash:store: %s key %s[%s] for proc %" PRIu64 "",
(NULL == kv ? "storing" : "updating"),
key, opal_dss.lookup_data_type(type), id));
if (NULL != kv) {
opal_list_remove_item(&proc_data->data, &kv->super);
OBJ_RELEASE(kv);
}
kv = OBJ_NEW(opal_value_t);
kv->key = strdup(key);
kv->scope = scope;
opal_list_append(&proc_data->data, &kv->super);
/* the type could come in as an OPAL one (e.g., OPAL_VPID). Since
* the value is an OPAL definition, it cannot cover OPAL data
* types, so convert to the underlying OPAL type
*/
switch (type) {
case OPAL_STRING:
kv->type = OPAL_STRING;
if (NULL != data) {
kv->data.string = strdup( (const char *) data);
} else {
kv->data.string = NULL;
}
break;
case OPAL_UINT64:
if (NULL == data) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
return OPAL_ERR_BAD_PARAM;
}
kv->type = OPAL_UINT64;
kv->data.uint64 = *(uint64_t*)(data);
break;
case OPAL_UINT32:
if (NULL == data) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
return OPAL_ERR_BAD_PARAM;
}
kv->type = OPAL_UINT32;
kv->data.uint32 = *(uint32_t*)data;
break;
case OPAL_UINT16:
if (NULL == data) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
return OPAL_ERR_BAD_PARAM;
}
kv->type = OPAL_UINT16;
kv->data.uint16 = *(uint16_t*)(data);
break;
case OPAL_INT:
if (NULL == data) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
return OPAL_ERR_BAD_PARAM;
}
kv->type = OPAL_INT;
kv->data.integer = *(int*)(data);
break;
case OPAL_UINT:
if (NULL == data) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
return OPAL_ERR_BAD_PARAM;
}
kv->type = OPAL_UINT;
kv->data.uint = *(unsigned int*)(data);
break;
case OPAL_FLOAT:
if (NULL == data) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
return OPAL_ERR_BAD_PARAM;
}
kv->type = OPAL_FLOAT;
kv->data.fval = *(float*)(data);
break;
case OPAL_BYTE_OBJECT:
kv->type = OPAL_BYTE_OBJECT;
boptr = (opal_byte_object_t*)data;
if (NULL != boptr && NULL != boptr->bytes && 0 < boptr->size) {
kv->data.bo.bytes = (uint8_t *) malloc(boptr->size);
memcpy(kv->data.bo.bytes, boptr->bytes, boptr->size);
kv->data.bo.size = boptr->size;
} else {
kv->data.bo.bytes = NULL;
kv->data.bo.size = 0;
}
break;
default:
OPAL_ERROR_LOG(OPAL_ERR_NOT_SUPPORTED);
return OPAL_ERR_NOT_SUPPORTED;
}
return OPAL_SUCCESS;
}
static int store_pointer(const opal_identifier_t *uid,
opal_value_t *kv)
{
proc_data_t *proc_data;
opal_value_t *k2;
opal_identifier_t id;
/* data must have an assigned scope */
if (OPAL_SCOPE_UNDEF == kv->scope) {
return OPAL_ERR_BAD_PARAM;
}
/* to protect alignment, copy the data across */
memcpy(&id, uid, sizeof(opal_identifier_t));
/* we are at the bottom of the store priorities, so
* if this fell to us, we store it
*/
opal_output_verbose(1, opal_db_base_framework.framework_output,
"db:hash:store storing data for proc %" PRIu64 " for scope %d",
id, (int)kv->scope);
/* lookup the proc data object for this proc */
if (NULL == (proc_data = lookup_opal_proc(&hash_data, id))) {
/* unrecoverable error */
OPAL_OUTPUT_VERBOSE((5, opal_db_base_framework.framework_output,
"db:hash:store: storing key %s[%s] for proc %" PRIu64 " unrecoverably failed",
kv->key, opal_dss.lookup_data_type(kv->type), id));
return OPAL_ERR_OUT_OF_RESOURCE;
}
/* see if we already have this key in the data - means we are updating
* a pre-existing value
*/
k2 = lookup_keyval(proc_data, kv->key);
OPAL_OUTPUT_VERBOSE((5, opal_db_base_framework.framework_output,
"db:hash:store: %s pointer of key %s[%s] for proc %" PRIu64 "",
(NULL == k2 ? "storing" : "updating"),
kv->key, opal_dss.lookup_data_type(kv->type), id));
if (NULL != k2) {
opal_list_remove_item(&proc_data->data, &k2->super);
OBJ_RELEASE(k2);
}
kv->scope |= OPAL_SCOPE_REFER; // mark that this value was stored by reference and doesn't belong to us
opal_list_append(&proc_data->data, &kv->super);
return OPAL_SUCCESS;
}
static int fetch(const opal_identifier_t *uid,
const char *key, void **data,
opal_data_type_t type)
{
proc_data_t *proc_data;
opal_value_t *kv;
opal_byte_object_t *boptr;
opal_identifier_t id;
/* to protect alignment, copy the data across */
memcpy(&id, uid, sizeof(opal_identifier_t));
OPAL_OUTPUT_VERBOSE((5, opal_db_base_framework.framework_output,
"db:hash:fetch: searching for key %s[%s] on proc %" PRIu64 "",
(NULL == key) ? "NULL" : key,
opal_dss.lookup_data_type(type), id));
/* if the key is NULL, that is an error */
if (NULL == key) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
return OPAL_ERR_BAD_PARAM;
}
/* lookup the proc data object for this proc */
if (NULL == (proc_data = lookup_opal_proc(&hash_data, id))) {
/* maybe they can find it elsewhere */
OPAL_OUTPUT_VERBOSE((5, opal_db_base_framework.framework_output,
"db_hash:fetch data for proc %" PRIu64 " not found", id));
return OPAL_ERR_TAKE_NEXT_OPTION;
}
/* find the value */
if (NULL == (kv = lookup_keyval(proc_data, key))) {
/* let them look globally for it */
OPAL_OUTPUT_VERBOSE((5, opal_db_base_framework.framework_output,
"db_hash:fetch key %s for proc %" PRIu64 " not found",
(NULL == key) ? "NULL" : key, id));
return OPAL_ERR_TAKE_NEXT_OPTION;
}
/* do the copy and check the type */
switch (type) {
case OPAL_STRING:
if (OPAL_STRING != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
if (NULL != kv->data.string) {
*data = strdup(kv->data.string);
} else {
*data = NULL;
}
break;
case OPAL_UINT64:
if (OPAL_UINT64 != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
memcpy(*data, &kv->data.uint64, 8);
break;
case OPAL_UINT32:
if (OPAL_UINT32 != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
memcpy(*data, &kv->data.uint32, 4);
break;
case OPAL_UINT16:
if (OPAL_UINT16 != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
memcpy(*data, &kv->data.uint16, 2);
break;
case OPAL_INT:
if (OPAL_INT != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
memcpy(*data, &kv->data.integer, sizeof(int));
break;
case OPAL_UINT:
if (OPAL_UINT != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
memcpy(*data, &kv->data.uint, sizeof(unsigned int));
break;
case OPAL_FLOAT:
if (OPAL_FLOAT != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
memcpy(*data, &kv->data.fval, sizeof(float));
break;
case OPAL_BYTE_OBJECT:
if (OPAL_BYTE_OBJECT != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
boptr = (opal_byte_object_t*)malloc(sizeof(opal_byte_object_t));
if (NULL != kv->data.bo.bytes && 0 < kv->data.bo.size) {
boptr->bytes = (uint8_t *) malloc(kv->data.bo.size);
memcpy(boptr->bytes, kv->data.bo.bytes, kv->data.bo.size);
boptr->size = kv->data.bo.size;
} else {
boptr->bytes = NULL;
boptr->size = 0;
}
*data = boptr;
break;
default:
OPAL_ERROR_LOG(OPAL_ERR_NOT_SUPPORTED);
return OPAL_ERR_NOT_SUPPORTED;
}
return OPAL_SUCCESS;
}
static int fetch_pointer(const opal_identifier_t *uid,
const char *key,
void **data, opal_data_type_t type)
{
proc_data_t *proc_data;
opal_value_t *kv;
opal_identifier_t id;
/* to protect alignment, copy the data across */
memcpy(&id, uid, sizeof(opal_identifier_t));
OPAL_OUTPUT_VERBOSE((5, opal_db_base_framework.framework_output,
"db:hash:fetch_pointer: searching for key %s on proc %" PRIu64 "",
(NULL == key) ? "NULL" : key, id));
/* if the key is NULL, that is an error */
if (NULL == key) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
return OPAL_ERR_BAD_PARAM;
}
/* lookup the proc data object for this proc */
if (NULL == (proc_data = lookup_opal_proc(&hash_data, id))) {
/* look elsewhere */
return OPAL_ERR_TAKE_NEXT_OPTION;
}
/* find the value */
if (NULL == (kv = lookup_keyval(proc_data, key))) {
/* let them look globally for it */
return OPAL_ERR_TAKE_NEXT_OPTION;
}
switch (type) {
case OPAL_STRING:
if (OPAL_STRING != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
*data = kv->data.string;
break;
case OPAL_UINT64:
if (OPAL_UINT64 != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
*data = &kv->data.uint64;
break;
case OPAL_UINT32:
if (OPAL_UINT32 != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
*data = &kv->data.uint32;
break;
case OPAL_UINT16:
if (OPAL_UINT16 != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
*data = &kv->data.uint16;
break;
case OPAL_INT:
if (OPAL_INT != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
*data = &kv->data.integer;
break;
case OPAL_UINT:
if (OPAL_UINT != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
*data = &kv->data.uint;
break;
case OPAL_BYTE_OBJECT:
if (OPAL_BYTE_OBJECT != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
*data = &kv->data.bo;
break;
case OPAL_FLOAT:
if (OPAL_FLOAT != kv->type) {
return OPAL_ERR_TYPE_MISMATCH;
}
*data = &kv->data.fval;
break;
default:
OPAL_ERROR_LOG(OPAL_ERR_NOT_SUPPORTED);
return OPAL_ERR_NOT_SUPPORTED;
}
return OPAL_SUCCESS;
}
static int fetch_multiple(const opal_identifier_t *uid,
opal_scope_t scope,
const char *key,
opal_list_t *kvs)
{
proc_data_t *proc_data;
opal_value_t *kv, *kvnew;
int rc;
char *srchkey, *ptr;
size_t len = 0;
opal_identifier_t id;
/* to protect alignment, copy the data across */
memcpy(&id, uid, sizeof(opal_identifier_t));
OPAL_OUTPUT_VERBOSE((5, opal_db_base_framework.framework_output,
"db:hash:fetch_multiple: searching for key %s on proc %" PRIu64 "",
(NULL == key) ? "NULL" : key, id));
/* lookup the proc data object for this proc */
if (NULL == (proc_data = lookup_opal_proc(&hash_data, id))) {
/* look elsewhere */
return OPAL_ERR_TAKE_NEXT_OPTION;
}
/* if the key is NULL, then return all the values */
if (NULL == key) {
for (kv = (opal_value_t*) opal_list_get_first(&proc_data->data);
kv != (opal_value_t*) opal_list_get_end(&proc_data->data);
kv = (opal_value_t*) opal_list_get_next(kv)) {
/* check for a matching scope */
if (!(scope & kv->scope)) {
continue;
}
if (OPAL_SUCCESS != (rc = opal_dss.copy((void**)&kvnew, kv, OPAL_VALUE))) {
OPAL_ERROR_LOG(rc);
return rc;
}
opal_list_append(kvs, &kvnew->super);
}
return OPAL_SUCCESS;
}
/* see if the key includes a wildcard */
srchkey = strdup(key);
if (NULL != (ptr = strchr(srchkey, '*'))) {
*ptr = '\0';
len = strlen(srchkey);
}
/* otherwise, find all matching keys and return them */
for (kv = (opal_value_t*) opal_list_get_first(&proc_data->data);
kv != (opal_value_t*) opal_list_get_end(&proc_data->data);
kv = (opal_value_t*) opal_list_get_next(kv)) {
/* check for a matching scope */
if (!(scope & kv->scope)) {
continue;
}
if ((0 < len && 0 == strncmp(srchkey, kv->key, len)) ||
(0 == len && 0 == strcmp(key, kv->key))) {
if (OPAL_SUCCESS != (rc = opal_dss.copy((void**)&kvnew, kv, OPAL_VALUE))) {
OPAL_ERROR_LOG(rc);
return rc;
}
opal_list_append(kvs, &kvnew->super);
}
}
free(srchkey);
return OPAL_SUCCESS;
}
static int remove_data(const opal_identifier_t *uid, const char *key)
{
proc_data_t *proc_data;
opal_value_t *kv;
opal_identifier_t id;
/* to protect alignment, copy the data across */
memcpy(&id, uid, sizeof(opal_identifier_t));
/* lookup the specified proc */
if (NULL == (proc_data = lookup_opal_proc(&hash_data, id))) {
/* no data for this proc */
return OPAL_SUCCESS;
}
/* if key is NULL, remove all data for this proc */
if (NULL == key) {
while (NULL != (kv = (opal_value_t *) opal_list_remove_first(&proc_data->data))) {
OBJ_RELEASE(kv);
}
/* remove the proc_data object itself from the jtable */
opal_hash_table_remove_value_uint64(&hash_data, id);
/* cleanup */
OBJ_RELEASE(proc_data);
return OPAL_SUCCESS;
}
/* remove this item */
for (kv = (opal_value_t*) opal_list_get_first(&proc_data->data);
kv != (opal_value_t*) opal_list_get_end(&proc_data->data);
kv = (opal_value_t*) opal_list_get_next(kv)) {
if (0 == strcmp(key, kv->key)) {
opal_list_remove_item(&proc_data->data, &kv->super);
if (!(kv->scope & OPAL_SCOPE_REFER)) {
OBJ_RELEASE(kv);
}
break;
}
}
return OPAL_SUCCESS;
}

Просмотреть файл

@ -1,24 +0,0 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_DB_HASH_H
#define OPAL_DB_HASH_H
#include "opal/mca/db/db.h"
BEGIN_C_DECLS
OPAL_MODULE_DECLSPEC extern opal_db_base_component_t mca_db_hash_component;
OPAL_DECLSPEC extern opal_db_base_module_t opal_db_hash_module;
END_C_DECLS
#endif /* OPAL_DB_HASH_H */

Просмотреть файл

@ -1,119 +0,0 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
* These symbols are in a file by themselves to provide nice linker
* semantics. Since linkers generally pull in symbols by object
* files, keeping these symbols as the only symbols in this file
* prevents utility programs such as "ompi_info" from having to import
* entire components just to query their version and parameters.
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal/mca/base/base.h"
#include "opal/mca/db/db.h"
#include "opal/mca/db/base/base.h"
#include "db_hash.h"
static int db_hash_component_open(void);
static int db_hash_component_query(opal_db_base_module_t **module,
int *store_priority,
int *fetch_priority,
bool restrict_local);
static int db_hash_component_close(void);
static int db_hash_component_register(void);
/*
* Instantiate the public struct with all of our public information
* and pointers to our public functions in it
*/
opal_db_base_component_t mca_db_hash_component = {
{
OPAL_DB_BASE_VERSION_1_0_0,
/* Component name and version */
"hash",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component open and close functions */
db_hash_component_open,
db_hash_component_close,
NULL,
db_hash_component_register
},
{
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
db_hash_component_query
};
/* we should be the last place to store data as
* it usually is stored globally, then can fall
* down to us if it is internal
*/
static int my_store_priority = 1;
/* we should be the first place to look for data
* in case we already have it - then try to fetch
* it globally if we don't
*/
static int my_fetch_priority = 100;
static int db_hash_component_open(void)
{
return OPAL_SUCCESS;
}
static int db_hash_component_query(opal_db_base_module_t **module,
int *store_priority,
int *fetch_priority,
bool restrict_local)
{
/* we are the default - the ESS modules will set the db selection
* envar if they need someone else
*/
*store_priority = my_store_priority;
*fetch_priority = my_fetch_priority;
*module = &opal_db_hash_module;
return OPAL_SUCCESS;
}
static int db_hash_component_close(void)
{
return OPAL_SUCCESS;
}
static int db_hash_component_register(void)
{
mca_base_component_t *c = &mca_db_hash_component.base_version;
my_store_priority = 1;
(void) mca_base_component_var_register(c, "store_priority",
"Priority dictating order in which store commands will given to database components",
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&my_store_priority);
my_fetch_priority = 100;
(void) mca_base_component_var_register(c, "fetch_priority",
"Priority dictating order in which fetch commands will given to database components",
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&my_fetch_priority);
return OPAL_SUCCESS;
}

Просмотреть файл

@ -1,39 +0,0 @@
#
# Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
sources = \
db_pmi.h \
db_pmi_component.c \
db_pmi.c
# Make the output library in this directory, and name it either
# mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la
# (for static builds).
if MCA_BUILD_opal_db_pmi_DSO
component_noinst =
component_install = mca_db_pmi.la
else
component_noinst = libmca_db_pmi.la
component_install =
endif
mcacomponentdir = $(ompilibdir)
mcacomponent_LTLIBRARIES = $(component_install)
mca_db_pmi_la_SOURCES = $(sources)
mca_db_pmi_la_CPPFLAGS = $(db_pmi_CPPFLAGS)
mca_db_pmi_la_LDFLAGS = -module -avoid-version $(db_pmi_LDFLAGS)
mca_db_pmi_la_LIBADD = $(db_pmi_LIBS) \
$(top_ompi_builddir)/opal/mca/common/pmi/libmca_common_pmi.la
noinst_LTLIBRARIES = $(component_noinst)
libmca_db_pmi_la_SOURCES =$(sources)
libmca_db_pmi_la_CPPFLAGS = $(db_pmi_CPPFLAGS)
libmca_db_pmi_la_LDFLAGS = -module -avoid-version $(db_pmi_LDFLAGS)
libmca_db_pmi_la_LIBADD = $(db_pmi_LIBS)

Просмотреть файл

@ -1,707 +0,0 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#include "opal_config.h"
#include "opal/constants.h"
#include <time.h>
#include <string.h>
#include <pmi.h>
#if WANT_PMI2_SUPPORT
#include <pmi2.h>
#endif
#include <regex.h>
#include "opal_stdint.h"
#include "opal/class/opal_pointer_array.h"
#include "opal/dss/dss_types.h"
#include "opal/util/argv.h"
#include "opal/util/error.h"
#include "opal/util/output.h"
#include "opal/util/show_help.h"
#include "opal/mca/common/pmi/common_pmi.h"
#include "opal/mca/db/base/base.h"
#include "db_pmi.h"
#define OPAL_PMI_PAD 10
static int init(void);
static void finalize(void);
static int store(const opal_identifier_t *id,
opal_scope_t scope,
const char *key, const void *object,
opal_data_type_t type);
static int store_pointer(const opal_identifier_t *proc,
opal_value_t *kv);
static void commit(const opal_identifier_t *proc);
static int fetch(const opal_identifier_t *proc,
const char *key, void **data, opal_data_type_t type);
static int fetch_pointer(const opal_identifier_t *proc,
const char *key,
void **data, opal_data_type_t type);
static int fetch_multiple(const opal_identifier_t *proc,
opal_scope_t scope,
const char *key,
opal_list_t *kvs);
static int remove_data(const opal_identifier_t *proc, const char *key);
opal_db_base_module_t opal_db_pmi_module = {
init,
finalize,
opal_db_base_set_id,
store,
store_pointer,
commit,
fetch,
fetch_pointer,
fetch_multiple,
remove_data,
NULL
};
static char *pmi_encode(const void *val, size_t vallen);
static uint8_t* pmi_decode(const char *data, size_t *retlen);
static int setup_pmi(void);
static char* setup_key(opal_identifier_t name, const char *key);
/* Local variables */
static char *pmi_kvs_name = NULL;
static int pmi_vallen_max = -1;
static int pmi_keylen_max = -1;
static char *pmi_packed_data = NULL;
static int pmi_pack_key = 0;
static int pmi_packed_data_off = 0;
/* Because Cray uses PMI2 extensions for some, but not all,
* PMI functions, we define a set of wrappers for those
* common functions we will use
*/
static int kvs_put(const char *key, const char *value)
{
#if WANT_PMI2_SUPPORT
return PMI2_KVS_Put(key, value);
#else
return PMI_KVS_Put(pmi_kvs_name, key, value);
#endif
}
static int kvs_get(const char *key, char *value, int valuelen)
{
#if WANT_PMI2_SUPPORT
int len;
return PMI2_KVS_Get(pmi_kvs_name, PMI2_ID_NULL, key, value, valuelen, &len);
#else
return PMI_KVS_Get(pmi_kvs_name, key, value, valuelen);
#endif
}
static int init(void)
{
int rc;
rc = setup_pmi();
/* don't error log this return status as it
* could just mean we don't have PMI setup
* for this job
*/
return rc;
}
static void finalize(void)
{
if (NULL != pmi_kvs_name) {
free(pmi_kvs_name);
pmi_kvs_name = NULL;
}
}
static int pmi_commit_packed (const opal_identifier_t *uid) {
char *pmikey = NULL, *tmp;
opal_identifier_t proc;
char tmp_key[32], save;
char *encoded_data;
int rc, left;
if (pmi_packed_data_off == 0) {
/* nothing to write */
return OPAL_SUCCESS;
}
/* to protect alignment, copy the data across */
memcpy(&proc, uid, sizeof(opal_identifier_t));
if (NULL == (encoded_data = pmi_encode(pmi_packed_data, pmi_packed_data_off))) {
OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE);
return OPAL_ERR_OUT_OF_RESOURCE;
}
for (left = strlen (encoded_data), tmp = encoded_data ; left ; ) {
size_t value_size = pmi_vallen_max > left ? left : pmi_vallen_max - 1;
sprintf (tmp_key, "key%d", pmi_pack_key);
if (NULL == (pmikey = setup_key(proc, tmp_key))) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
rc = OPAL_ERR_BAD_PARAM;
break;
}
/* only write value_size bytes */
save = tmp[value_size];
tmp[value_size] = '\0';
rc = kvs_put(pmikey, tmp);
free (pmikey);
if (PMI_SUCCESS != rc) {
OPAL_PMI_ERROR(rc, "PMI_KVS_Put");
rc = OPAL_ERROR;
break;
}
tmp[value_size] = save;
tmp += value_size;
left -= value_size;
pmi_pack_key ++;
rc = OPAL_SUCCESS;
}
if (encoded_data) {
free (encoded_data);
}
pmi_packed_data_off = 0;
free (pmi_packed_data);
pmi_packed_data = NULL;
return rc;
}
static int pmi_store_encoded(const opal_identifier_t *uid, const char *key, const void *data, opal_data_type_t type)
{
opal_byte_object_t *bo;
size_t data_len = 0;
size_t needed;
switch (type) {
case OPAL_STRING:
data_len = data ? strlen (data) + 1 : 0;
break;
case OPAL_INT:
case OPAL_UINT:
data_len = sizeof (int);
break;
case OPAL_INT16:
case OPAL_UINT16:
data_len = sizeof (int16_t);
break;
case OPAL_INT32:
case OPAL_UINT32:
data_len = sizeof (int32_t);
break;
case OPAL_INT64:
case OPAL_UINT64:
data_len = sizeof (int64_t);
break;
case OPAL_BYTE_OBJECT:
bo = (opal_byte_object_t *) data;
data = bo->bytes;
data_len = bo->size;
}
needed = 10 + data_len + strlen (key);
if (NULL == pmi_packed_data) {
pmi_packed_data = calloc (needed, 1);
} else {
/* grow the region */
pmi_packed_data = realloc (pmi_packed_data, pmi_packed_data_off + needed);
}
/* special length meaning NULL */
if (NULL == data) {
data_len = 0xffff;
}
/* serialize the opal datatype */
pmi_packed_data_off += sprintf (pmi_packed_data + pmi_packed_data_off,
"%s%c%02x%c%04x%c", key, '\0', type, '\0',
(int) data_len, '\0');
if (NULL != data) {
memmove (pmi_packed_data + pmi_packed_data_off, data, data_len);
pmi_packed_data_off += data_len;
}
return OPAL_SUCCESS;
}
static int pmi_get_packed (const opal_identifier_t *uid, char **packed_data, size_t *len)
{
char *tmp_encoded = NULL, *pmikey, *pmi_tmp;
int remote_key, size;
size_t bytes_read;
opal_identifier_t proc;
int rc;
/* set default */
*packed_data = NULL;
*len = 0;
/* to protect alignment, copy the data across */
memcpy(&proc, uid, sizeof(opal_identifier_t));
pmi_tmp = calloc (pmi_vallen_max, 1);
if (NULL == pmi_tmp) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
/* read all of the packed data from this proc */
for (remote_key = 0, bytes_read = 0 ; ; ++remote_key) {
char tmp_key[32];
sprintf (tmp_key, "key%d", remote_key);
if (NULL == (pmikey = setup_key(proc, tmp_key))) {
rc = OPAL_ERR_OUT_OF_RESOURCE;
OPAL_ERROR_LOG(rc);
return rc;
}
OPAL_OUTPUT_VERBOSE((10, opal_db_base_framework.framework_output,
"GETTING KEY %s", pmikey));
rc = kvs_get(pmikey, pmi_tmp, pmi_vallen_max);
free (pmikey);
if (PMI_SUCCESS != rc) {
break;
}
size = strlen (pmi_tmp);
if (NULL == tmp_encoded) {
tmp_encoded = malloc (size + 1);
} else {
tmp_encoded = realloc (tmp_encoded, bytes_read + size + 1);
}
strcpy (tmp_encoded + bytes_read, pmi_tmp);
bytes_read += size;
/* is the string terminator present? */
if ('-' == tmp_encoded[bytes_read-1]) {
break;
}
}
free (pmi_tmp);
OPAL_OUTPUT_VERBOSE((10, opal_db_base_framework.framework_output,
"Read data %s\n",
(NULL == tmp_encoded) ? "NULL" : tmp_encoded));
if (NULL != tmp_encoded) {
*packed_data = (char *) pmi_decode (tmp_encoded, len);
free (tmp_encoded);
if (NULL == *packed_data) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
}
return OPAL_SUCCESS;
}
static void cache_keys_locally(const opal_identifier_t *uid)
{
char *tmp, *tmp2, *tmp3, *tmp_val;
opal_data_type_t stored_type;
size_t len, offset;
int rc, size;
OPAL_OUTPUT_VERBOSE((1, opal_db_base_framework.framework_output,
"db:pmi:fetch get all keys for proc %" PRIu64 " in KVS %s",
*uid, pmi_kvs_name));
rc = pmi_get_packed (uid, &tmp_val, &len);
if (OPAL_SUCCESS != rc) {
return;
}
/* search for this key in the decoded data */
for (offset = 0 ; offset < len && '\0' != tmp_val[offset] ; ) {
/* type */
tmp = tmp_val + offset + strlen (tmp_val + offset) + 1;
/* size */
tmp2 = tmp + strlen (tmp) + 1;
/* data */
tmp3 = tmp2 + strlen (tmp2) + 1;
stored_type = (opal_data_type_t) strtol (tmp, NULL, 16);
size = strtol (tmp2, NULL, 16);
/* cache value locally so we don't have to look it up via pmi again */
if (OPAL_BYTE_OBJECT == stored_type) {
opal_byte_object_t bo;
if (size == 0xffff) {
bo.bytes = NULL;
bo.size = 0;
} else {
bo.bytes = (uint8_t*)tmp3;
bo.size = size;
}
opal_db.store (uid, OPAL_SCOPE_GLOBAL, tmp_val + offset, &bo, stored_type);
} else if (size < 0xffff) {
opal_db.store (uid, OPAL_SCOPE_GLOBAL, tmp_val + offset, tmp3, stored_type);
} else {
opal_db.store (uid, OPAL_SCOPE_GLOBAL, tmp_val + offset, NULL, stored_type);
}
/* keep going and cache everything locally */
offset = (size_t) (tmp3 - tmp_val) + size;
}
free (tmp_val);
}
static int store(const opal_identifier_t *uid,
opal_scope_t scope,
const char *key, const void *data, opal_data_type_t type)
{
opal_identifier_t proc;
int rc;
/* to protect alignment, copy the data across */
memcpy(&proc, uid, sizeof(opal_identifier_t));
/* we never push other proc's data, or INTERNAL data */
if (OPAL_SCOPE_INTERNAL & scope ||
proc != opal_db_base.my_id) {
return OPAL_ERR_TAKE_NEXT_OPTION;
}
OPAL_OUTPUT_VERBOSE((5, opal_db_base_framework.framework_output,
"db:pmi:store: storing key %s[%s] for proc %" PRIu64 "",
key, opal_dss.lookup_data_type(type), proc));
if (OPAL_SUCCESS != (rc = pmi_store_encoded (uid, key, data, type))) {
OPAL_ERROR_LOG(rc);
return rc;
}
/* we want our internal data to be stored internally
* as well since some of the upper layer components
* want to retrieve it
*/
return OPAL_ERR_TAKE_NEXT_OPTION;
}
static int store_pointer(const opal_identifier_t *uid,
opal_value_t *kv)
{
int rc;
opal_identifier_t proc;
/* to protect alignment, copy the data across */
memcpy(&proc, uid, sizeof(opal_identifier_t));
/* we never push other proc's data, or INTERNAL data */
if (OPAL_SCOPE_INTERNAL & kv->scope ||
proc != opal_db_base.my_id) {
return OPAL_ERR_TAKE_NEXT_OPTION;
}
/* just push this to PMI */
if (OPAL_SUCCESS != (rc = store(uid, kv->scope, kv->key, (void*)&kv->data, kv->type))) {
OPAL_ERROR_LOG(rc);
return rc;
}
/* we want our internal data to be stored internally
* as well since some of the upper layer components
* want to retrieve it
*/
return OPAL_ERR_TAKE_NEXT_OPTION;
}
static void commit(const opal_identifier_t *proc)
{
/* commit the packed data to PMI */
pmi_commit_packed (proc);
#if WANT_PMI2_SUPPORT
PMI2_KVS_Fence();
#else
{
int rc;
if (PMI_SUCCESS != (rc = PMI_KVS_Commit(pmi_kvs_name))) {
OPAL_PMI_ERROR(rc, "PMI_KVS_Commit");
return;
}
/* Barrier here to ensure all other procs have committed */
PMI_Barrier();
}
#endif
}
static int fetch(const opal_identifier_t *uid,
const char *key, void **data,
opal_data_type_t type)
{
opal_identifier_t proc;
/* to protect alignment, copy the data across */
memcpy(&proc, uid, sizeof(opal_identifier_t));
/* if it is my own id, the data isn't here */
if (proc == opal_db_base.my_id) {
return OPAL_ERR_TAKE_NEXT_OPTION;
}
cache_keys_locally(&proc);
/* all keys will be available internally now */
return OPAL_ERR_TAKE_NEXT_OPTION;
}
static int fetch_pointer(const opal_identifier_t *uid,
const char *key,
void **data, opal_data_type_t type)
{
opal_identifier_t proc;
/* to protect alignment, copy the data across */
memcpy(&proc, uid, sizeof(opal_identifier_t));
/* if it is my own id, the data isn't here */
if (proc == opal_db_base.my_id) {
return OPAL_ERR_TAKE_NEXT_OPTION;
}
cache_keys_locally(&proc);
/* all keys will be available internally now */
return OPAL_ERR_TAKE_NEXT_OPTION;
}
static int fetch_multiple(const opal_identifier_t *uid,
opal_scope_t scope,
const char *key,
opal_list_t *kvs)
{
opal_identifier_t proc;
/* to protect alignment, copy the data across */
memcpy(&proc, uid, sizeof(opal_identifier_t));
/* if it is my own id, the data isn't here */
if (proc == opal_db_base.my_id) {
return OPAL_ERR_TAKE_NEXT_OPTION;
}
OPAL_OUTPUT_VERBOSE((1, opal_db_base_framework.framework_output,
"db:pmi:fetch_multiple get key %s for proc %" PRIu64 " in KVS %s",
(NULL == key) ? "NULL" : key, proc, pmi_kvs_name));
cache_keys_locally(&proc);
/* all keys will be available internally now */
return OPAL_ERR_TAKE_NEXT_OPTION;
}
static int remove_data(const opal_identifier_t *proc, const char *key)
{
/* nothing to do here */
return OPAL_SUCCESS;
}
static int setup_pmi(void)
{
int max_length, rc;
#if WANT_PMI2_SUPPORT
pmi_vallen_max = PMI2_MAX_VALLEN;
max_length = PMI2_MAX_VALLEN;
#else
rc = PMI_KVS_Get_value_length_max(&pmi_vallen_max);
if (PMI_SUCCESS != rc) {
OPAL_OUTPUT_VERBOSE((1, opal_db_base_framework.framework_output,
"db:pmi:pmi_setup failed %s with error %s",
"PMI_Get_value_length_max",
opal_errmgr_base_pmi_error(rc)));
return OPAL_ERROR;
}
if (PMI_SUCCESS != (rc = PMI_KVS_Get_name_length_max(&max_length))) {
OPAL_OUTPUT_VERBOSE((1, opal_db_base_framework.framework_output,
"db:pmi:pmi_setup failed %s with error %s",
"PMI_KVS_Get_name_length_max",
opal_errmgr_base_pmi_error(rc)));
return OPAL_ERROR;
}
#endif
pmi_kvs_name = (char*)malloc(max_length);
if (NULL == pmi_kvs_name) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
#if WANT_PMI2_SUPPORT
rc = PMI2_Job_GetId(pmi_kvs_name, max_length);
#else
rc = PMI_KVS_Get_my_name(pmi_kvs_name,max_length);
#endif
if (PMI_SUCCESS != rc) {
OPAL_OUTPUT_VERBOSE((1, opal_db_base_framework.framework_output,
"db:pmi:pmi_setup failed %s with error %s on maxlength %d",
"PMI_KVS_Get_my_name",
opal_errmgr_base_pmi_error(rc), max_length));
return OPAL_ERROR;
}
#if WANT_PMI2_SUPPORT
pmi_keylen_max = PMI2_MAX_KEYLEN;
#else
if (PMI_SUCCESS != (rc = PMI_KVS_Get_key_length_max(&pmi_keylen_max))) {
OPAL_OUTPUT_VERBOSE((1, opal_db_base_framework.framework_output,
"db:pmi:pmi_setup failed %s with error %s",
"PMI_KVS_Get_key_length_max",
opal_errmgr_base_pmi_error(rc)));
return OPAL_ERROR;
}
#endif
return OPAL_SUCCESS;
}
static char* setup_key(opal_identifier_t name, const char *key)
{
char *pmi_kvs_key;
if (pmi_keylen_max <= asprintf(&pmi_kvs_key, "%" PRIu64 "-%s",
name, key)) {
free(pmi_kvs_key);
return NULL;
}
return pmi_kvs_key;
}
/* base64 encoding with illegal (to Cray PMI) characters removed ('=' is replaced by ' ') */
static inline unsigned char pmi_base64_encsym (unsigned char value) {
assert (value < 64);
if (value < 26) {
return 'A' + value;
} else if (value < 52) {
return 'a' + (value - 26);
} else if (value < 62) {
return '0' + (value - 52);
}
return (62 == value) ? '+' : '/';
}
static inline unsigned char pmi_base64_decsym (unsigned char value) {
if ('+' == value) {
return 62;
} else if ('/' == value) {
return 63;
} else if (' ' == value) {
return 64;
} else if (value <= '9') {
return (value - '0') + 52;
} else if (value <= 'Z') {
return (value - 'A');
} else if (value <= 'z') {
return (value - 'a') + 26;
}
return 64;
}
static inline void pmi_base64_encode_block (const unsigned char in[3], char out[4], int len) {
out[0] = pmi_base64_encsym (in[0] >> 2);
out[1] = pmi_base64_encsym (((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4));
/* Cray PMI doesn't allow = in PMI attributes so pad with spaces */
out[2] = 1 < len ? pmi_base64_encsym(((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6)) : ' ';
out[3] = 2 < len ? pmi_base64_encsym(in[2] & 0x3f) : ' ';
}
static inline int pmi_base64_decode_block (const char in[4], unsigned char out[3]) {
char in_dec[4];
in_dec[0] = pmi_base64_decsym (in[0]);
in_dec[1] = pmi_base64_decsym (in[1]);
in_dec[2] = pmi_base64_decsym (in[2]);
in_dec[3] = pmi_base64_decsym (in[3]);
out[0] = in_dec[0] << 2 | in_dec[1] >> 4;
if (64 == in_dec[2]) {
return 1;
}
out[1] = in_dec[1] << 4 | in_dec[2] >> 2;
if (64 == in_dec[3]) {
return 2;
}
out[2] = ((in_dec[2] << 6) & 0xc0) | in_dec[3];
return 3;
}
/* PMI only supports strings. For now, do a simple base64. */
static char *pmi_encode(const void *val, size_t vallen) {
char *outdata, *tmp;
size_t i;
outdata = calloc (((2 + vallen) * 4) / 3 + 2, 1);
if (NULL == outdata) {
return NULL;
}
for (i = 0, tmp = outdata ; i < vallen ; i += 3, tmp += 4) {
pmi_base64_encode_block((unsigned char *) val + i, tmp, vallen - i);
}
/* mark the end of the pmi string */
tmp[0] = (unsigned char)'-';
tmp[1] = (unsigned char)'\0';
return outdata;
}
static uint8_t *pmi_decode (const char *data, size_t *retlen) {
size_t input_len = (strlen (data) - 1) / 4;
unsigned char *ret;
int out_len;
size_t i;
/* default */
*retlen = 0;
ret = calloc (1, 3 * input_len + 1);
if (NULL == ret) {
return ret;
}
for (i = 0, out_len = 0 ; i < input_len ; i++, data += 4) {
out_len += pmi_base64_decode_block(data, ret + 3 * i);
}
ret[out_len] = '\0';
*retlen = out_len;
return ret;
}

Просмотреть файл

@ -1,23 +0,0 @@
/*
* Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_DB_PMI_H
#define OPAL_DB_PMI_H
#include "opal/mca/db/db.h"
BEGIN_C_DECLS
OPAL_MODULE_DECLSPEC extern opal_db_base_component_t mca_db_pmi_component;
OPAL_DECLSPEC extern opal_db_base_module_t opal_db_pmi_module;
END_C_DECLS
#endif /* OPAL_DB_PMI_H */

Просмотреть файл

@ -1,123 +0,0 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal/mca/base/base.h"
#include "opal/mca/common/pmi/common_pmi.h"
#include "opal/mca/db/db.h"
#include "opal/mca/db/base/base.h"
#include "db_pmi.h"
static int db_pmi_component_open(void);
static int db_pmi_component_query(opal_db_base_module_t **module,
int *store_priority,
int *fetch_priority,
bool restrict_local);
static int db_pmi_component_close(void);
static int db_pmi_component_register(void);
/*
* Instantiate the public struct with all of our public information
* and pointers to our public functions in it
*/
opal_db_base_component_t mca_db_pmi_component = {
{
OPAL_DB_BASE_VERSION_1_0_0,
/* Component name and version */
"pmi",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component open and close functions */
db_pmi_component_open,
db_pmi_component_close,
NULL,
db_pmi_component_register
},
{
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
db_pmi_component_query
};
/* if we are to be used, someone external will set
* our store priority to a high level
*/
static int my_store_priority = 0;
/* fetch from us if not found elsewhere */
static int my_fetch_priority = 1;
static int db_pmi_component_open(void)
{
return OPAL_SUCCESS;
}
static int db_pmi_component_query(opal_db_base_module_t **module,
int *store_priority,
int *fetch_priority,
bool restrict_local)
{
if (!restrict_local) {
/* only use PMI if available - the ESS pmi module
* will force our selection if we are direct-launched,
* and the orted will turn us "off" if indirectly launched
*/
if (mca_common_pmi_init()) {
*store_priority = my_store_priority;
*fetch_priority = my_fetch_priority;
*module = &opal_db_pmi_module;
return OPAL_SUCCESS;
}
}
*store_priority = 0;
*fetch_priority = 0;
*module = NULL;
return OPAL_ERROR;
}
static int db_pmi_component_close(void)
{
mca_common_pmi_finalize();
return OPAL_SUCCESS;
}
static int db_pmi_component_register(void)
{
mca_base_component_t *c = &mca_db_pmi_component.base_version;
my_store_priority = 0;
(void) mca_base_component_var_register(c, "store_priority",
"Priority dictating order in which store commands will given to database components",
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&my_store_priority);
my_fetch_priority = 1;
(void) mca_base_component_var_register(c, "fetch_priority",
"Priority dictating order in which fetch commands will given to database components",
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&my_fetch_priority);
return OPAL_SUCCESS;
}

Просмотреть файл

@ -1,218 +0,0 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#include "opal_config.h"
#include "opal/constants.h"
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#include <stdio.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "libpq-fe.h"
#include "opal_stdint.h"
#include "opal/util/argv.h"
#include "opal/util/error.h"
#include "opal/mca/db/base/base.h"
#include "db_postgres.h"
#define OPAL_PG_MAX_LINE_LENGTH 4096
static int init(void);
static void finalize(void);
static int add_log(const char *table,
const opal_value_t *kvs, int nkvs);
opal_db_base_module_t opal_db_postgres_module = {
init,
finalize,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
add_log
};
static PGconn *conn = NULL;
/* local variables */
static int init(void)
{
char **login=NULL;
char **connection=NULL;
/* break the user info into its login parts */
login = opal_argv_split(mca_db_postgres_component.user, ':');
if (2 != opal_argv_count(login)) {
opal_output(0, "db:postgres: User info is invalid: %s",
mca_db_postgres_component.user);
opal_argv_free(login);
return OPAL_ERR_BAD_PARAM;
}
/* break the uri */
connection = opal_argv_split(mca_db_postgres_component.pguri, ':');
if (2 != opal_argv_count(connection)) {
opal_argv_free(login);
opal_argv_free(connection);
opal_output(0, "db:postgres: Connection info is invalid: %s",
mca_db_postgres_component.pguri);
return OPAL_ERR_BAD_PARAM;
}
conn = PQsetdbLogin(connection[0], connection[1],
mca_db_postgres_component.pgoptions,
mca_db_postgres_component.pgtty,
mca_db_postgres_component.dbname,
login[0], login[1]);
opal_argv_free(login);
opal_argv_free(connection);
if (PQstatus(conn) != CONNECTION_OK) {
conn = NULL;
opal_output(0, "***********************************************\n");
opal_output(0, "db:postgres: Connection failed:\n\tURI: %s\n\tOPTIONS: %s\n\tTTY: %s\n\tDBNAME: %s\n\tUSER: %s",
mca_db_postgres_component.pguri,
(NULL == mca_db_postgres_component.pgoptions) ? "NULL" : mca_db_postgres_component.pgoptions,
(NULL == mca_db_postgres_component.pgtty) ? "NULL" : mca_db_postgres_component.pgtty,
mca_db_postgres_component.dbname,
mca_db_postgres_component.user);
opal_output(0, "\n***********************************************");
exit(OPAL_ERR_CONNECTION_FAILED);
return OPAL_ERR_CONNECTION_FAILED;
}
opal_output_verbose(5, opal_db_base_framework.framework_output,
"db:postgres: Connection established to %s",
mca_db_postgres_component.dbname);
return OPAL_SUCCESS;
}
static void finalize(void)
{
if (NULL != conn) {
PQfinish(conn);
}
}
/* NOTE: at this time, we only support data from the
* "sigar" source. We'll have to add a mapping from
* source to table later
*/
static int add_log(const char *source,
const opal_value_t *kvs, int nkvs)
{
char *query, *vstr;
PGresult *res;
char **cmdargs=NULL;
time_t nowtime;
struct tm *nowtm;
char tbuf[1024], buf[64];
int i;
opal_output_verbose(2, opal_db_base_framework.framework_output,
"Logging data for source %s", source);
if (0 != strcmp(source, "sigar")) {
OPAL_ERROR_LOG(OPAL_ERR_NOT_SUPPORTED);
return OPAL_ERR_NOT_SUPPORTED;
}
/* cycle through the provided values and construct
* an insert command for them - note that the values
* MUST be in column-order for the database!
*/
for (i=0; i < nkvs; i++) {
switch (kvs[i].type) {
case OPAL_STRING:
snprintf(tbuf, sizeof(tbuf), "\'%s\'", kvs[i].data.string);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT32:
snprintf(tbuf, sizeof(tbuf), "%d", kvs[i].data.int32);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT16:
snprintf(tbuf, sizeof(tbuf), "%d", (int)kvs[i].data.int16);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_PID:
snprintf(tbuf, sizeof(tbuf), "%lu", (unsigned long)kvs[i].data.pid);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT64:
snprintf(tbuf, sizeof(tbuf), "%" PRIi64 "", kvs[i].data.int64);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT64:
snprintf(tbuf, sizeof(tbuf), "%" PRIu64 "", kvs[i].data.uint64);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_FLOAT:
snprintf(tbuf, sizeof(tbuf), "%f", kvs[i].data.fval);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_TIMEVAL:
/* we only care about seconds */
nowtime = kvs[i].data.tv.tv_sec;
nowtm = localtime(&nowtime);
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", nowtm);
snprintf(tbuf, sizeof(tbuf), "\'%s\'", buf);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
default:
OPAL_ERROR_LOG(OPAL_ERR_NOT_SUPPORTED);
break;
}
}
/* assemble the value string */
vstr = opal_argv_join(cmdargs, ',');
/* create the query */
asprintf(&query, "INSERT INTO %s values (%s)", mca_db_postgres_component.table, vstr);
free(vstr);
opal_output_verbose(2, opal_db_base_framework.framework_output,
"Executing query %s", query);
/* execute it */
res = PQexec(conn, query);
free(query);
if ((!res) || (PQresultStatus(res) != PGRES_COMMAND_OK)) {
opal_output(0, "***********************************************\n");
opal_output(0, "POSTGRES INSERT COMMAND FAILED - UNABLE TO LOG");
opal_output(0, "SENSOR DATA. ABORTING");
opal_output(0, "\n***********************************************");
PQclear(res);
return OPAL_ERROR;
}
opal_output_verbose(2, opal_db_base_framework.framework_output,
"Query succeeded");
PQclear(res);
return OPAL_SUCCESS;
}

Просмотреть файл

@ -1,34 +0,0 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_DB_POSTGRES_H
#define OPAL_DB_POSTGRES_H
#include "opal/mca/db/db.h"
BEGIN_C_DECLS
typedef struct {
opal_db_base_component_t super;
int num_worker_threads;
char *dbname;
char *table;
char *user;
char *pguri;
char *pgoptions;
char *pgtty;
} opal_db_postgres_component_t;
OPAL_MODULE_DECLSPEC extern opal_db_postgres_component_t mca_db_postgres_component;
OPAL_DECLSPEC extern opal_db_base_module_t opal_db_postgres_module;
END_C_DECLS
#endif /* OPAL_DB_POSTGRES_H */

Просмотреть файл

@ -1,180 +0,0 @@
/*
* Copyright (c) 2013 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
* These symbols are in a file by themselves to provide nice linker
* semantics. Since linkers generally pull in symbols by object
* files, keeping these symbols as the only symbols in this file
* prevents utility programs such as "ompi_info" from having to import
* entire components just to query their version and parameters.
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal/mca/base/base.h"
#include "opal/mca/base/mca_base_var.h"
#include "opal/mca/db/db.h"
#include "opal/mca/db/base/base.h"
#include "db_postgres.h"
extern opal_db_base_module_t opal_db_postgres_module;
char *opal_db_postgres_file;
static int postgres_component_open(void);
static int postgres_component_close(void);
static int postgres_component_query(opal_db_base_module_t **module,
int *store_priority,
int *fetch_priority,
bool restrict_local);
static int postgres_component_register(void);
/*
* Instantiate the public struct with all of our public information
* and pointers to our public functions in it
*/
opal_db_postgres_component_t mca_db_postgres_component = {
{
{
OPAL_DB_BASE_VERSION_1_0_0,
/* Component name and version */
"postgres",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component open and close functions */
postgres_component_open,
postgres_component_close,
NULL,
postgres_component_register
},
{
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
postgres_component_query
}
};
static int postgres_component_open(void)
{
return OPAL_SUCCESS;
}
static int postgres_component_query(opal_db_base_module_t **module,
int *store_priority,
int *fetch_priority,
bool restrict_local)
{
if (NULL != mca_db_postgres_component.dbname &&
NULL != mca_db_postgres_component.table &&
NULL != mca_db_postgres_component.user &&
NULL != mca_db_postgres_component.pguri) {
*store_priority = 3; /* ahead of sqlite3 */
*fetch_priority = 3;
*module = &opal_db_postgres_module;
return OPAL_SUCCESS;
}
*store_priority = 0;
*fetch_priority = 0;
*module = NULL;
return OPAL_ERROR;
}
static int postgres_component_close(void)
{
if (NULL != mca_db_postgres_component.dbname) {
free(mca_db_postgres_component.dbname);
}
if (NULL != mca_db_postgres_component.table) {
free(mca_db_postgres_component.table);
}
if (NULL != mca_db_postgres_component.user) {
free(mca_db_postgres_component.user);
}
if (NULL != mca_db_postgres_component.pguri) {
free(mca_db_postgres_component.pguri);
}
if (NULL != mca_db_postgres_component.pgoptions) {
free(mca_db_postgres_component.pgoptions);
}
if (NULL != mca_db_postgres_component.pgtty) {
free(mca_db_postgres_component.pgtty);
}
return OPAL_SUCCESS;
}
static int postgres_component_register(void) {
mca_base_component_t *c = &mca_db_postgres_component.super.base_version;
/* retrieve the name of the database to be used */
mca_db_postgres_component.dbname = NULL;
(void) mca_base_component_var_register (c, "database", "Name of database",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&mca_db_postgres_component.dbname);
/* retrieve the name of the table to be used */
mca_db_postgres_component.table = NULL;
(void) mca_base_component_var_register (c, "table", "Name of table",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&mca_db_postgres_component.table);
/* retrieve the name of the user to be used */
mca_db_postgres_component.user = NULL;
(void) mca_base_component_var_register (c, "user", "Name of database user:password",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&mca_db_postgres_component.table);
/* retrieve the server:port */
mca_db_postgres_component.pguri = NULL;
(void) mca_base_component_var_register (c, "uri", "Contact info for Postgres server as ip:port",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&mca_db_postgres_component.pguri);
/* retrieve any options to be used */
mca_db_postgres_component.pgoptions = NULL;
(void) mca_base_component_var_register (c, "options", "Options to pass to the database",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&mca_db_postgres_component.pgoptions);
/* retrieve the tty argument */
mca_db_postgres_component.pgtty = NULL;
(void) mca_base_component_var_register (c, "tty", "TTY option for database",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&mca_db_postgres_component.pgtty);
/* retrieve the number of worker threads to be used */
mca_db_postgres_component.num_worker_threads = 0;
(void) mca_base_component_var_register (c, "num_worker_threads",
"Number of worker threads to be used",
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&mca_db_postgres_component.num_worker_threads);
return OPAL_SUCCESS;
}

Просмотреть файл

@ -1,221 +0,0 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#include "opal_config.h"
#include "opal/constants.h"
#include <time.h>
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#include <stdio.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "opal/class/opal_pointer_array.h"
#include "opal/util/argv.h"
#include "opal/util/output.h"
#include "opal_stdint.h"
#include "opal/mca/db/base/base.h"
#include "db_print.h"
static int init(void);
static void finalize(void);
static int add_log(const char *table,
const opal_value_t *kvs, int nkvs);
opal_db_base_module_t opal_db_print_module = {
init,
finalize,
opal_db_base_set_id,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
add_log
};
static opal_pointer_array_t tables;
static FILE *fpout=NULL;
static int init(void)
{
OBJ_CONSTRUCT(&tables, opal_pointer_array_t);
opal_pointer_array_init(&tables, 1, INT_MAX, 1);
if (0 == strcmp(mca_db_print_component.filename, "-")) {
fpout = stdout;
} else if (0 == strcmp(mca_db_print_component.filename, "+")) {
fpout = stderr;
} else if (NULL == (fpout = fopen(mca_db_print_component.filename, "w"))) {
opal_output(0, "ERROR: cannot open log file %s", mca_db_print_component.filename);
return OPAL_ERROR;
}
return OPAL_SUCCESS;
}
static void finalize(void)
{
int i;
char *ptr;
for (i=0; i < tables.size; i++) {
if (NULL != (ptr = (char*)opal_pointer_array_get_item(&tables, i))) {
free(ptr);
}
}
OBJ_DESTRUCT(&tables);
if (NULL != fpout &&
stdout != fpout &&
stderr != fpout) {
fclose(fpout);
fpout = NULL;
}
}
static int add_log(const char *table,
const opal_value_t *kvs, int nkvs)
{
char **cmdargs=NULL, *vstr;
time_t nowtime;
struct tm nowtm;
char tbuf[1024];
int i;
bool found;
opal_output_verbose(2, opal_db_base_framework.framework_output,
"Logging data for table %s", table);
found = false;
for (i=0; i < tables.size; i++) {
if (NULL == (vstr = (char*)opal_pointer_array_get_item(&tables, i))) {
continue;
}
if (0 == strcmp(vstr, table)) {
/* already handled this one */
found = true;
break;
}
}
if (!found) {
/* record that we have it */
vstr = strdup(table);
opal_pointer_array_add(&tables, vstr);
/* start with the table name */
opal_argv_append_nosize(&cmdargs, table);
/* create and print the column headers */
for (i=0; i < nkvs; i++) {
opal_argv_append_nosize(&cmdargs, kvs[i].key);
}
vstr = opal_argv_join(cmdargs, '|');
fprintf(fpout, "%s\n", vstr);
free(vstr);
opal_argv_free(cmdargs);
cmdargs = NULL;
}
/* put the table at the start */
opal_argv_append_nosize(&cmdargs, table);
/* cycle through the provided values and print them */
for (i=0; i < nkvs; i++) {
switch (kvs[i].type) {
case OPAL_STRING:
snprintf(tbuf, sizeof(tbuf), "%s", kvs[i].data.string);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_SIZE:
snprintf(tbuf, sizeof(tbuf), "%" PRIsize_t "", kvs[i].data.size);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT:
snprintf(tbuf, sizeof(tbuf), "%d", kvs[i].data.integer);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT8:
snprintf(tbuf, sizeof(tbuf), "%" PRIi8 "", kvs[i].data.int8);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT16:
snprintf(tbuf, sizeof(tbuf), "%" PRIi16 "", kvs[i].data.int16);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT32:
snprintf(tbuf, sizeof(tbuf), "%" PRIi32 "", kvs[i].data.int32);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT64:
snprintf(tbuf, sizeof(tbuf), "%" PRIi64 "", kvs[i].data.int64);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT:
snprintf(tbuf, sizeof(tbuf), "%u", kvs[i].data.uint);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT8:
snprintf(tbuf, sizeof(tbuf), "%" PRIu8 "", kvs[i].data.uint8);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT16:
snprintf(tbuf, sizeof(tbuf), "%" PRIu16 "", kvs[i].data.uint16);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT32:
snprintf(tbuf, sizeof(tbuf), "%" PRIu32 "", kvs[i].data.uint32);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT64:
snprintf(tbuf, sizeof(tbuf), "%" PRIu64 "", kvs[i].data.uint64);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_PID:
snprintf(tbuf, sizeof(tbuf), "%lu", (unsigned long)kvs[i].data.pid);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_FLOAT:
snprintf(tbuf, sizeof(tbuf), "%f", kvs[i].data.fval);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_TIMEVAL:
/* we only care about seconds */
nowtime = kvs[i].data.tv.tv_sec;
(void)localtime_r(&nowtime, &nowtm);
strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", &nowtm);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
default:
snprintf(tbuf, sizeof(tbuf), "Unsupported type: %s",
opal_dss.lookup_data_type(kvs[i].type));
opal_argv_append_nosize(&cmdargs, tbuf);
break;
}
}
/* assemble the value string */
vstr = opal_argv_join(cmdargs, ',');
/* print it */
fprintf(fpout, "%s\n", vstr);
free(vstr);
return OPAL_SUCCESS;
}

Просмотреть файл

@ -1,27 +0,0 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_DB_PRINT_H
#define OPAL_DB_PRINT_H
#include "opal/mca/db/db.h"
BEGIN_C_DECLS
typedef struct {
opal_db_base_component_t super;
char *filename;
} opal_db_print_component_t;
OPAL_MODULE_DECLSPEC extern opal_db_print_component_t mca_db_print_component;
OPAL_DECLSPEC extern opal_db_base_module_t opal_db_print_module;
END_C_DECLS
#endif /* OPAL_DB_PRINT_H */

Просмотреть файл

@ -1,107 +0,0 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
* These symbols are in a file by themselves to provide nice linker
* semantics. Since linkers generally pull in symbols by object
* files, keeping these symbols as the only symbols in this file
* prevents utility programs such as "ompi_info" from having to import
* entire components just to query their version and parameters.
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal/mca/base/base.h"
#include "opal/mca/db/db.h"
#include "opal/mca/db/base/base.h"
#include "db_print.h"
extern opal_db_base_module_t opal_db_print_module;
static int print_component_register(void);
static int print_component_open(void);
static int print_component_close(void);
static int print_component_query(opal_db_base_module_t **module,
int *store_priority,
int *fetch_priority,
bool restrict_local);
static int print_component_register(void);
/*
* Instantiate the public struct with all of our public information
* and pointers to our public functions in it
*/
opal_db_print_component_t mca_db_print_component = {
{
{
OPAL_DB_BASE_VERSION_1_0_0,
/* Component name and version */
"print",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component open and close functions */
print_component_open,
print_component_close,
NULL,
print_component_register
},
{
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
print_component_query
}
};
static int print_component_open(void)
{
return OPAL_SUCCESS;
}
/* this component is NEVER used for store or fetch */
static int print_component_query(opal_db_base_module_t **module,
int *store_priority,
int *fetch_priority,
bool restrict_local)
{
if (NULL == mca_db_print_component.filename) {
*store_priority = 0;
*fetch_priority = 0;
*module = NULL;
return OPAL_ERROR;
}
*store_priority = 0;
*fetch_priority = 0;
*module = &opal_db_print_module;
return OPAL_SUCCESS;
}
static int print_component_close(void)
{
return OPAL_SUCCESS;
}
static int print_component_register(void)
{
mca_db_print_component.filename = NULL;
(void) mca_base_component_var_register (&mca_db_print_component.super.base_version,
"file", "Print to the indicated file (- => stdout, + => stderr)",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&mca_db_print_component.filename);
return OPAL_SUCCESS;
}

Просмотреть файл

@ -1,191 +0,0 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#include "opal_config.h"
#include "opal/constants.h"
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#include <stdio.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sqlite3.h>
#include "opal/dss/dss_types.h"
#include "opal/util/argv.h"
#include "opal/util/basename.h"
#include "opal/util/os_dirpath.h"
#include "opal/util/os_path.h"
#include "opal/util/output.h"
#include "opal/util/malloc.h"
#include "opal/util/basename.h"
#include "opal/mca/pstat/base/base.h"
#include "opal/util/show_help.h"
#include "opal/mca/db/base/base.h"
#include "db_sqlite.h"
static int init(void);
static void finalize(void);
static int add_log(const char *table,
const opal_value_t *kvs, int nkvs);
opal_db_base_module_t opal_db_sqlite_module = {
init,
finalize,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
add_log
};
/* local variables */
static sqlite3 **dbhandles=NULL;
static int nthreads = 1;
static int active = 0;
static int init(void)
{
int i;
/* initialize sqlite3 */
if (SQLITE_OK != sqlite3_initialize()) {
return OPAL_ERR_UNREACH;
}
/* check if sqlite was built thread-safe - if not, we won't
* use worker threads for thruput
*/
if (0 == mca_db_sqlite_component.num_worker_threads || 0 != sqlite3_threadsafe()) {
nthreads = 1;
} else {
nthreads = mca_db_sqlite_component.num_worker_threads;
}
/* get the required number of database handles */
dbhandles = (sqlite3**)malloc(nthreads * sizeof(sqlite3*));
/* open the database - this will create the database file if
* it doesn't already exist
*/
for (i=0; i < nthreads; i++) {
if (SQLITE_OK != sqlite3_open(mca_db_sqlite_component.db_file, &dbhandles[i])) {
opal_show_help("help-db-sqlite.txt", "cannot-create-sqlite", true, mca_db_sqlite_component.db_file);
return OPAL_ERR_FILE_OPEN_FAILURE;
}
}
return OPAL_SUCCESS;
}
static void finalize(void)
{
int i;
/* if we are normally terminating, remove the recovery file */
if (NULL != dbhandles) {
for (i=0; i < nthreads; i++) {
if (SQLITE_OK != sqlite3_close(dbhandles[i])) {
opal_output(0, "sqlite failed to close");
}
}
}
}
static int add_log(const char *table,
const opal_value_t *kvs, int nkvs)
{
int i, rc;
char *sql, **cmd = NULL, *tmp;
sqlite3_stmt *stmt;
opal_output_verbose(2, opal_db_base_framework.framework_output,
"Logging data for table %s", table);
/* setup the insert statement */
for (i=0; i < nkvs; i++) {
opal_argv_append_nosize(&cmd, "?");
}
tmp = opal_argv_join(cmd, ',');
asprintf(&sql, "INSERT INTO %s VALUES (%s)", table, tmp);
free(tmp);
opal_argv_free(cmd);
/* use the next worker thread */
OPAL_SQLITE_CMD(prepare_v2(dbhandles[active], sql, strlen(sql)+1, &stmt, NULL), dbhandles[active], &rc);
if (SQLITE_OK != rc) {
return OPAL_ERROR;
}
/* cycle through the provided values and construct
* an insert command for them - note that the values
* MUST be in column-order for the database!
*/
for (i=0; i < nkvs; i++) {
switch (kvs[i].type) {
case OPAL_STRING:
OPAL_SQLITE_CMD(bind_text(stmt, i, kvs[i].data.string, strlen(kvs[i].data.string), NULL),
dbhandles[active], &rc);
break;
case OPAL_INT32:
OPAL_SQLITE_CMD(bind_int(stmt, i, kvs[i].data.int32), dbhandles[active], &rc);
break;
case OPAL_INT16:
OPAL_SQLITE_CMD(bind_int(stmt, i, kvs[i].data.int16), dbhandles[active], &rc);
break;
case OPAL_PID:
OPAL_SQLITE_CMD(bind_int64(stmt, i, kvs[i].data.pid), dbhandles[active], &rc);
break;
case OPAL_INT64:
OPAL_SQLITE_CMD(bind_int64(stmt, i, kvs[i].data.int64), dbhandles[active], &rc);
break;
case OPAL_FLOAT:
OPAL_SQLITE_CMD(bind_double(stmt, i, kvs[i].data.fval), dbhandles[active], &rc);
break;
case OPAL_TIMEVAL:
asprintf(&tmp, "%d.%06d", (int)kvs[i].data.tv.tv_sec, (int)kvs[i].data.tv.tv_usec);
OPAL_SQLITE_CMD(bind_text(stmt, i, tmp, strlen(tmp), NULL),
dbhandles[active], &rc);
free(tmp);
break;
}
if (SQLITE_OK != rc) {
return OPAL_ERROR;
}
}
OPAL_SQLITE_OP(step(stmt), DONE, dbhandles[active], &rc);
if (SQLITE_OK != rc) {
return OPAL_ERROR;
}
opal_output_verbose(2, opal_db_base_framework.framework_output,
"INSERTED ROW %d", (int)sqlite3_last_insert_rowid(dbhandles[active]));
/* cycle to the next worker thread */
active++;
if (nthreads < active) {
active = 0;
}
return OPAL_SUCCESS;
}

Просмотреть файл

@ -1,132 +0,0 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
* These symbols are in a file by themselves to provide nice linker
* semantics. Since linkers generally pull in symbols by object
* files, keeping these symbols as the only symbols in this file
* prevents utility programs such as "ompi_info" from having to import
* entire components just to query their version and parameters.
*/
#include "opal_config.h"
#include "opal/constants.h"
#include <sys/stat.h>
#include "opal/mca/base/base.h"
#include "opal/util/show_help.h"
#include "opal/mca/db/db.h"
#include "opal/mca/db/base/base.h"
#include "db_sqlite.h"
extern opal_db_base_module_t opal_db_sqlite_module;
char *opal_db_sqlite_file;
static int sqlite_component_register(void);
static int sqlite_component_open(void);
static int sqlite_component_close(void);
static int sqlite_component_query(opal_db_base_module_t **module,
int *store_priority,
int *fetch_priority,
bool restrict_local);
static int sqlite_component_register(void);
/*
* Instantiate the public struct with all of our public information
* and pointers to our public functions in it
*/
opal_db_sqlite_component_t mca_db_sqlite_component = {
{
{
OPAL_DB_BASE_VERSION_1_0_0,
/* Component name and version */
"sqlite",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component open and close functions */
sqlite_component_open,
sqlite_component_close,
NULL,
sqlite_component_register
},
{
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
sqlite_component_query
}
};
static int sqlite_component_open(void)
{
return OPAL_SUCCESS;
}
/* this component is NEVER used for store or fetch */
static int sqlite_component_query(opal_db_base_module_t **module,
int *store_priority,
int *fetch_priority,
bool restrict_local)
{
struct stat buf;
*store_priority = 0;
*fetch_priority = 0;
if (NULL != mca_db_sqlite_component.db_file) {
/* if the database file doesn't exist, then we can't operate */
if (0 != stat(mca_db_sqlite_component.db_file, &buf)) {
/* not found */
opal_show_help("help-db-sqlite.txt", "file-not-found",
true, mca_db_sqlite_component.db_file);
*module = NULL;
return OPAL_ERROR;
}
*module = &opal_db_sqlite_module;
return OPAL_SUCCESS;
}
*module = NULL;
return OPAL_ERROR;
}
static int sqlite_component_close(void)
{
return OPAL_SUCCESS;
}
static int sqlite_component_register(void)
{
mca_base_component_t *c = &mca_db_sqlite_component.super.base_version;
/* retrieve the name of the file to be used */
mca_db_sqlite_component.db_file = NULL;
(void) mca_base_component_var_register (c, "database", "Name of file to be used for database",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&mca_db_sqlite_component.db_file);
/* retrieve the number of worker threads to be used, if sqlite3 is thread-safe */
mca_db_sqlite_component.num_worker_threads = 0;
(void) mca_base_component_var_register (c, "num_worker_threads", "Number of worker threads to be used",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&mca_db_sqlite_component.num_worker_threads);
return OPAL_SUCCESS;
}

Просмотреть файл

@ -10,15 +10,15 @@
AM_CPPFLAGS = $(LTDLINCL) AM_CPPFLAGS = $(LTDLINCL)
# main library setup # main library setup
noinst_LTLIBRARIES = libmca_db.la noinst_LTLIBRARIES = libmca_dstore.la
libmca_db_la_SOURCES = libmca_dstore_la_SOURCES =
# pkgdata setup # pkgdata setup
dist_ompidata_DATA = dist_ompidata_DATA =
# local files # local files
headers = db.h db_types.h headers = dstore.h dstore_types.h
libmca_db_la_SOURCES += $(headers) libmca_dstore_la_SOURCES += $(headers)
# Conditionally install the header files # Conditionally install the header files
if WANT_INSTALL_HEADERS if WANT_INSTALL_HEADERS

20
opal/mca/dstore/base/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,20 @@
#
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
# Copyright (c) 2014 Intel, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
dist_ompidata_DATA += base/help-dstore-base.txt
headers += \
base/base.h
libmca_dstore_la_SOURCES += \
base/dstore_base_frame.c \
base/dstore_base_select.c \
base/dstore_base_stubs.c

94
opal/mca/dstore/base/base.h Обычный файл
Просмотреть файл

@ -0,0 +1,94 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/** @file:
*/
#ifndef MCA_DB_BASE_H
#define MCA_DB_BASE_H
#include "opal_config.h"
#include "opal/types.h"
#include "opal/mca/mca.h"
#include "opal/mca/base/mca_base_framework.h"
#include "opal/mca/event/event.h"
#include "opal/class/opal_hash_table.h"
#include "opal/class/opal_list.h"
#include "opal/class/opal_pointer_array.h"
#include "opal/dss/dss.h"
#include "opal/mca/dstore/dstore.h"
BEGIN_C_DECLS
OPAL_DECLSPEC extern mca_base_framework_t opal_dstore_base_framework;
/**
* Select a dstore module
*/
OPAL_DECLSPEC int opal_dstore_base_select(void);
typedef struct {
opal_dstore_base_component_t *active; // active component
opal_pointer_array_t handles; // array of open datastore handles
} opal_dstore_base_t;
OPAL_DECLSPEC extern opal_dstore_base_t opal_dstore_base;
typedef struct {
opal_object_t super;
char *name;
opal_dstore_base_module_t *module;
} opal_dstore_handle_t;
OBJ_CLASS_DECLARATION(opal_dstore_handle_t);
/**
* Data for a particular opal process
* The name association is maintained in the
* proc_data hash table.
*/
typedef struct {
/** Structure can be put on lists (including in hash tables) */
opal_list_item_t super;
bool loaded;
/* List of opal_value_t structures containing all data
received from this process, sorted by key. */
opal_list_t data;
} opal_dstore_proc_data_t;
OBJ_CLASS_DECLARATION(opal_dstore_proc_data_t);
OPAL_DECLSPEC int opal_dstore_base_open(const char *name);
OPAL_DECLSPEC int opal_dstore_base_close(int dstorehandle);
OPAL_DECLSPEC int opal_dstore_base_store(int dstorehandle,
const opal_identifier_t *id,
opal_value_t *kv);
OPAL_DECLSPEC void opal_dstore_base_commit(int dstorehandle,
const opal_identifier_t *id);
OPAL_DECLSPEC int opal_dstore_base_fetch(int dstorehandle,
const opal_identifier_t *id,
const char *key,
opal_list_t *kvs);
OPAL_DECLSPEC int opal_dstore_base_remove_data(int dstorehandle,
const opal_identifier_t *id,
const char *key);
/* support */
OPAL_DECLSPEC opal_dstore_proc_data_t* opal_dstore_base_lookup_proc(opal_hash_table_t *jtable,
opal_identifier_t id);
OPAL_DECLSPEC opal_value_t* opal_dstore_base_lookup_keyval(opal_dstore_proc_data_t *proc_data,
const char *key);
END_C_DECLS
#endif

122
opal/mca/dstore/base/dstore_base_frame.c Обычный файл
Просмотреть файл

@ -0,0 +1,122 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal/mca/mca.h"
#include "opal/util/output.h"
#include "opal/mca/base/base.h"
#include "opal/dss/dss_types.h"
#include "opal/mca/dstore/base/base.h"
/*
* The following file was created by configure. It contains extern
* dstorements and the definition of an array of pointers to each
* module's public mca_base_module_t struct.
*/
#include "opal/mca/dstore/base/static-components.h"
opal_dstore_base_API_t opal_dstore = {
opal_dstore_base_open,
opal_dstore_base_close,
opal_dstore_base_store,
opal_dstore_base_commit,
opal_dstore_base_fetch,
opal_dstore_base_remove_data
};
opal_dstore_base_t opal_dstore_base;
int opal_dstore_peer = -1;
int opal_dstore_internal = -1;
int opal_dstore_nonpeer = -1;
static int opal_dstore_base_frame_close(void)
{
opal_dstore_handle_t *hdl;
int i;
/* cycle across all the active dstore handles and let them cleanup - order
* doesn't matter in this case
*/
for (i=0; i < opal_dstore_base.handles.size; i++) {
if (NULL != (hdl = (opal_dstore_handle_t*)opal_pointer_array_get_item(&opal_dstore_base.handles, i))) {
OBJ_RELEASE(hdl);
}
}
OBJ_DESTRUCT(&opal_dstore_base.handles);
/* let the active component to finalize, should it wish to do so */
if (NULL != opal_dstore_base.active && NULL != opal_dstore_base.active->finalize) {
opal_dstore_base.active->finalize();
}
return mca_base_framework_components_close(&opal_dstore_base_framework, NULL);
}
static int opal_dstore_base_frame_open(mca_base_open_flag_t flags)
{
OBJ_CONSTRUCT(&opal_dstore_base.handles, opal_pointer_array_t);
opal_pointer_array_init(&opal_dstore_base.handles, 3, INT_MAX, 1);
/* Open up all available components */
return mca_base_framework_components_open(&opal_dstore_base_framework, flags);
}
MCA_BASE_FRAMEWORK_DECLARE(opal, dstore, NULL, NULL,
opal_dstore_base_frame_open,
opal_dstore_base_frame_close,
mca_dstore_base_static_components, 0);
static void hdl_con(opal_dstore_handle_t *p)
{
p->name = NULL;
p->module = NULL;
}
static void hdl_des(opal_dstore_handle_t *p)
{
opal_dstore_base_module_t *mod;
if (NULL != p->name) {
free(p->name);
}
if (NULL != p->module) {
mod = (opal_dstore_base_module_t*)p->module;
if (NULL != mod->finalize) {
mod->finalize((struct opal_dstore_base_module_t*)mod);
}
free(mod);
}
}
OBJ_CLASS_INSTANCE(opal_dstore_handle_t,
opal_object_t,
hdl_con, hdl_des);
static void proc_data_construct(opal_dstore_proc_data_t *ptr)
{
ptr->loaded = false;
OBJ_CONSTRUCT(&ptr->data, opal_list_t);
}
static void proc_data_destruct(opal_dstore_proc_data_t *ptr)
{
OPAL_LIST_DESTRUCT(&ptr->data);
}
OBJ_CLASS_INSTANCE(opal_dstore_proc_data_t,
opal_list_item_t,
proc_data_construct,
proc_data_destruct);

83
opal/mca/dstore/base/dstore_base_select.c Обычный файл
Просмотреть файл

@ -0,0 +1,83 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal/class/opal_list.h"
#include "opal/mca/mca.h"
#include "opal/mca/base/base.h"
#include "opal/mca/base/mca_base_component_repository.h"
#include "opal/util/output.h"
#include "opal/mca/dstore/base/base.h"
static bool selected = false;
int
opal_dstore_base_select(void)
{
mca_base_component_list_item_t *cli;
opal_dstore_base_component_t *component, *best=NULL;
int pri = -1000;
if (selected) {
/* ensure we don't do this twice */
return OPAL_SUCCESS;
}
selected = true;
/* Query all available components and ask if they have a module */
OPAL_LIST_FOREACH(cli, &opal_dstore_base_framework.framework_components, mca_base_component_list_item_t) {
component = (opal_dstore_base_component_t*)cli->cli_component;
opal_output_verbose(5, opal_dstore_base_framework.framework_output,
"mca:dstore:select: checking available component %s",
component->base_version.mca_component_name);
/* If there's no query function, skip it */
if (NULL == component->available) {
opal_output_verbose(5, opal_dstore_base_framework.framework_output,
"mca:dstore:select: Skipping component [%s]. It does not implement a query function",
component->base_version.mca_component_name );
continue;
}
/* Query the component */
opal_output_verbose(5, opal_dstore_base_framework.framework_output,
"mca:dstore:select: Querying component [%s]",
component->base_version.mca_component_name);
/* If the component is not available, then skip it as
* it has no available interfaces
*/
if (!component->available()) {
opal_output_verbose(5, opal_dstore_base_framework.framework_output,
"mca:dstore:select: Skipping component [%s] - not available",
component->base_version.mca_component_name );
continue;
}
/* keep only the highest priority component */
if (pri < component->priority) {
best = component;
pri = component->priority;
}
}
/* if no components are available, that is an error */
if (NULL == best) {
return OPAL_ERR_NOT_FOUND;
}
opal_dstore_base.active = best;
return OPAL_SUCCESS;;
}

179
opal/mca/dstore/base/dstore_base_stubs.c Обычный файл
Просмотреть файл

@ -0,0 +1,179 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013-2014 Intel Inc. All rights reserved
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal_stdint.h"
#include "opal/mca/mca.h"
#include "opal/util/error.h"
#include "opal/util/output.h"
#include "opal/mca/base/base.h"
#include "opal/dss/dss_types.h"
#include "opal/mca/dstore/base/base.h"
int opal_dstore_base_open(const char *name)
{
opal_dstore_handle_t *hdl;
int index;
opal_dstore_base_module_t *mod;
/* create the module */
if (NULL != (mod = opal_dstore_base.active->create_handle())) {
/* have our module, so create a new dstore_handle */
hdl = OBJ_NEW(opal_dstore_handle_t);
if (NULL != name) {
hdl->name = strdup(name);
}
hdl->module = mod;
if (0 > (index = opal_pointer_array_add(&opal_dstore_base.handles, hdl))) {
OPAL_ERROR_LOG(index);
OBJ_RELEASE(hdl);
}
return index;
}
/* if we get here, then we were unable to create a module
* for this scope
*/
return OPAL_ERROR;
}
int opal_dstore_base_close(int dstorehandle)
{
opal_dstore_handle_t *hdl;
int i;
/* if the handle is -1, then close all handles */
if (dstorehandle < 0) {
for (i=0; i < opal_dstore_base.handles.size; i++) {
if (NULL != (hdl = (opal_dstore_handle_t*)opal_pointer_array_get_item(&opal_dstore_base.handles, i))) {
OBJ_RELEASE(hdl);
opal_pointer_array_set_item(&opal_dstore_base.handles, i, NULL);
}
}
return OPAL_SUCCESS;
}
/* get the datastore handle */
if (NULL == (hdl = (opal_dstore_handle_t*)opal_pointer_array_get_item(&opal_dstore_base.handles, dstorehandle))) {
return OPAL_ERR_NOT_FOUND;
}
opal_pointer_array_set_item(&opal_dstore_base.handles, dstorehandle, NULL);
/* release the handle - this will also finalize and free the module */
OBJ_RELEASE(hdl);
return OPAL_SUCCESS;
}
int opal_dstore_base_store(int dstorehandle,
const opal_identifier_t *id,
opal_value_t *kv)
{
opal_dstore_handle_t *hdl;
if (NULL == (hdl = (opal_dstore_handle_t*)opal_pointer_array_get_item(&opal_dstore_base.handles, dstorehandle))) {
OPAL_ERROR_LOG(OPAL_ERR_NOT_FOUND);
return OPAL_ERR_NOT_FOUND;
}
return hdl->module->store((struct opal_dstore_base_module_t*)hdl->module, id, kv);
}
void opal_dstore_base_commit(int dstorehandle,
const opal_identifier_t *id)
{
opal_dstore_handle_t *hdl;
if (NULL == (hdl = (opal_dstore_handle_t*)opal_pointer_array_get_item(&opal_dstore_base.handles, dstorehandle))) {
OPAL_ERROR_LOG(OPAL_ERR_NOT_FOUND);
return;
}
if (NULL != hdl->module->commit) {
hdl->module->commit((struct opal_dstore_base_module_t*)hdl->module, id);
}
}
int opal_dstore_base_fetch(int dstorehandle,
const opal_identifier_t *id,
const char *key,
opal_list_t *kvs)
{
opal_dstore_handle_t *hdl;
if (NULL == (hdl = (opal_dstore_handle_t*)opal_pointer_array_get_item(&opal_dstore_base.handles, dstorehandle))) {
OPAL_ERROR_LOG(OPAL_ERR_NOT_FOUND);
return OPAL_ERR_NOT_FOUND;
}
return hdl->module->fetch((struct opal_dstore_base_module_t*)hdl->module, id, key, kvs);
}
int opal_dstore_base_remove_data(int dstorehandle,
const opal_identifier_t *id,
const char *key)
{
opal_dstore_handle_t *hdl;
if (NULL == (hdl = (opal_dstore_handle_t*)opal_pointer_array_get_item(&opal_dstore_base.handles, dstorehandle))) {
OPAL_ERROR_LOG(OPAL_ERR_NOT_FOUND);
return OPAL_ERR_NOT_FOUND;
}
return hdl->module->remove((struct opal_dstore_base_module_t*)hdl->module, id, key);
}
/**
* Find data for a given key in a given proc_data_t
* container.
*/
opal_value_t* opal_dstore_base_lookup_keyval(opal_dstore_proc_data_t *proc_data,
const char *key)
{
opal_value_t *kv;
OPAL_LIST_FOREACH(kv, &proc_data->data, opal_value_t) {
if (0 == strcmp(key, kv->key)) {
return kv;
}
}
return NULL;
}
/**
* Find proc_data_t container associated with given
* opal_identifier_t.
*/
opal_dstore_proc_data_t* opal_dstore_base_lookup_proc(opal_hash_table_t *jtable, opal_identifier_t id)
{
opal_dstore_proc_data_t *proc_data = NULL;
opal_hash_table_get_value_uint64(jtable, id, (void**)&proc_data);
if (NULL == proc_data) {
/* The proc clearly exists, so create a data structure for it */
proc_data = OBJ_NEW(opal_dstore_proc_data_t);
if (NULL == proc_data) {
opal_output(0, "dstore:hash:lookup_opal_proc: unable to allocate proc_data_t\n");
return NULL;
}
opal_hash_table_set_value_uint64(jtable, id, proc_data);
}
return proc_data;
}

19
opal/mca/dstore/base/help-dstore-base.txt Обычный файл
Просмотреть файл

@ -0,0 +1,19 @@
-*- text -*-
#
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
#
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# This is the US/English general help file for OPAL Errmgr HNP module.
#
[errmgr-hnp:unknown-job-error]
An error has occurred in an unknown job. This generally should not happen
except due to an internal OPAL error.
Job state: %s
This information should probably be repopald to the OMPI developers.

212
opal/mca/dstore/dstore.h Обычный файл
Просмотреть файл

@ -0,0 +1,212 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/** @file:
*
* The Database Framework - used for internal storage of
* information relating to modex and other OMPI operations
*
*/
#ifndef OPAL_DB_H
#define OPAL_DB_H
#include "opal_config.h"
#include "opal/types.h"
#include "opal/mca/mca.h"
#include "opal/mca/event/event.h"
#include "opal/dss/dss_types.h"
#include "opal/mca/dstore/dstore_types.h"
/**
* DATABASE DESIGN
*
* Each API function is treated as blocking.
*
*/
BEGIN_C_DECLS
/* declare a pair of global handles until such time
* as someone figures out how to separate the various
* datastore channels
*/
OPAL_DECLSPEC extern int opal_dstore_peer;
OPAL_DECLSPEC extern int opal_dstore_internal;
OPAL_DECLSPEC extern int opal_dstore_nonpeer;
/**** DEFINE THE PUBLIC API'S ****/
/*
* Open a database
*
* Open a database for access. The name field is purely for
* debug purposes and has no implementation relevance.
* Just like the standard POSIX file open, the call will return
* a unique "handle" that must be provided with any subsequent
* call to store or fetch data from this database.
*
* NOTE: calls to these APIs must be thread-protected as there
* is NO internal thread safety.
*/
typedef int (*opal_dstore_base_API_open_fn_t)(const char *name);
/*
* Close a database handle
*
* Close the specified database handle. A -1 handle indicates
* that ALL open database handles are to be closed.
*/
typedef int (*opal_dstore_base_API_close_fn_t)(int dstorehandle);
/*
* Store a data value against the primary key - overwrites any data
* of matching key that is already present. The data is copied into the database
* and therefore does not need to be preserved by the caller.
*/
typedef int (*opal_dstore_base_API_store_fn_t)(int dstorehandle,
const opal_identifier_t *id,
opal_value_t *kv);
/*
* Commit data to the database - action depends on implementation within
* each active component
*/
typedef void (*opal_dstore_base_API_commit_fn_t)(int dstorehandle,
const opal_identifier_t *id);
/*
* Retrieve data
*
* Retrieve data for the given primary key associated with the specified key. Wildcards
* are supported here as well. Caller is responsible for releasing the returned list
* of opal_value_t objects.
*/
typedef int (*opal_dstore_base_API_fetch_fn_t)(int dstorehandle,
const opal_identifier_t *id,
const char *key,
opal_list_t *kvs);
/*
* Delete data
*
* Delete the data for the given primary key that is associated with the specified key.
* If a NULL key is provided, all data for the given primary key will be deleted.
*/
typedef int (*opal_dstore_base_API_remove_fn_t)(int dstorehandle,
const opal_identifier_t *id,
const char *key);
/*
* the standard public API data structure
*/
typedef struct {
opal_dstore_base_API_open_fn_t open;
opal_dstore_base_API_close_fn_t close;
opal_dstore_base_API_store_fn_t store;
opal_dstore_base_API_commit_fn_t commit;
opal_dstore_base_API_fetch_fn_t fetch;
opal_dstore_base_API_remove_fn_t remove;
} opal_dstore_base_API_t;
/**** DEFINE THE MODULE API'S ****/
/* Note that each datastore handle will be associated with
* a single active module. Thus, storing and fetching data
* from that module does not require that we pass in the
* handle itself.
*
* NOTE: the call to actually store/fetch data in a given
* datastore handle must be protected against threaded operations
* as there is NO thread protection inside the various modules.
*/
struct opal_dstore_base_module_t;
/*
* Initialize the module
*/
typedef int (*opal_dstore_base_module_init_fn_t)(struct opal_dstore_base_module_t *mod);
/*
* Finalize the module
*/
typedef void (*opal_dstore_base_module_finalize_fn_t)(struct opal_dstore_base_module_t *mod);
/* store the data in this module */
typedef int (*opal_dstore_base_module_store_fn_t)(struct opal_dstore_base_module_t *mod,
const opal_identifier_t *id,
opal_value_t *kv);
/* commit data */
typedef void (*opal_dstore_base_module_commit_fn_t)(struct opal_dstore_base_module_t *mod,
const opal_identifier_t *id);
/* fetch data from the module */
typedef int (*opal_dstore_base_module_fetch_fn_t)(struct opal_dstore_base_module_t *mod,
const opal_identifier_t *id,
const char *key,
opal_list_t *kvs);
/* remove data */
typedef int (*opal_dstore_base_module_remove_fn_t)(struct opal_dstore_base_module_t *mod,
const opal_identifier_t *id,
const char *key);
/*
* the standard module data structure
*/
typedef struct {
opal_dstore_base_module_init_fn_t init;
opal_dstore_base_module_finalize_fn_t finalize;
opal_dstore_base_module_store_fn_t store;
opal_dstore_base_module_commit_fn_t commit;
opal_dstore_base_module_fetch_fn_t fetch;
opal_dstore_base_module_remove_fn_t remove;
} opal_dstore_base_module_t;
/*
* the component data structure
*/
/* function to determine if this component is available for use.
* Note that we do not use the standard component open
* function as we do not want/need return of a module.
*/
typedef bool (*mca_dstore_base_component_avail_fn_t)(void);
/* create and return a datastore module */
typedef opal_dstore_base_module_t* (*mca_dstore_base_component_create_hdl_fn_t)(void);
/* provide a chance for the component to finalize */
typedef void (*mca_dstore_base_component_finalize_fn_t)(void);
typedef struct {
mca_base_component_t base_version;
mca_base_component_data_t base_data;
int priority;
mca_dstore_base_component_avail_fn_t available;
mca_dstore_base_component_create_hdl_fn_t create_handle;
mca_dstore_base_component_finalize_fn_t finalize;
} opal_dstore_base_component_t;
/*
* Macro for use in components that are of type dstore
*/
#define OPAL_DSTORE_BASE_VERSION_2_0_0 \
MCA_BASE_VERSION_2_0_0, \
"dstore", 2, 0, 0
/* Global structure for accessing store functions */
OPAL_DECLSPEC extern opal_dstore_base_API_t opal_dstore; /* holds base function pointers */
END_C_DECLS
#endif

Просмотреть файл

@ -13,8 +13,8 @@
* *
*/ */
#ifndef OPAL_DB_TYPES_H #ifndef OPAL_DSTORE_TYPES_H
#define OPAL_DB_TYPES_H #define OPAL_DSTORE_TYPES_H
#include "opal_config.h" #include "opal_config.h"
#include "opal/types.h" #include "opal/types.h"
@ -24,13 +24,13 @@
BEGIN_C_DECLS BEGIN_C_DECLS
/* some OPAL-appropriate key definitions */ /* some OPAL-appropriate key definitions */
#define OPAL_DB_LOCALITY "opal.locality" #define OPAL_DSTORE_LOCALITY "opal.locality"
#define OPAL_DB_CPUSET "opal.cpuset" #define OPAL_DSTORE_CPUSET "opal.cpuset"
#define OPAL_DB_CREDENTIAL "opal.cred" #define OPAL_DSTORE_CREDENTIAL "opal.cred"
#define OPAL_DB_JOB_SDIR "opal.job.session.dir" #define OPAL_DSTORE_JOB_SDIR "opal.job.session.dir"
#define OPAL_DB_MY_SDIR "opal.my.session.dir" #define OPAL_DSTORE_MY_SDIR "opal.my.session.dir"
#define OPAL_DB_LOCALRANK "opal.local.rank" #define OPAL_DSTORE_LOCALRANK "opal.local.rank"
#define OPAL_DB_LOCALLDR "opal.local.ldr" #define OPAL_DSTORE_LOCALLDR "opal.local.ldr"
END_C_DECLS END_C_DECLS

Просмотреть файл

@ -9,28 +9,28 @@
# #
sources = \ sources = \
db_hash.h \ dstore_hash.h \
db_hash_component.c \ dstore_hash_component.c \
db_hash.c dstore_hash.c
# Make the output library in this directory, and name it either # Make the output library in this directory, and name it either
# mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la # mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la
# (for static builds). # (for static builds).
if MCA_BUILD_opal_db_hash_DSO if MCA_BUILD_opal_dstore_hash_DSO
component_noinst = component_noinst =
component_install = mca_db_hash.la component_install = mca_dstore_hash.la
else else
component_noinst = libmca_db_hash.la component_noinst = libmca_dstore_hash.la
component_install = component_install =
endif endif
mcacomponentdir = $(ompilibdir) mcacomponentdir = $(ompilibdir)
mcacomponent_LTLIBRARIES = $(component_install) mcacomponent_LTLIBRARIES = $(component_install)
mca_db_hash_la_SOURCES = $(sources) mca_dstore_hash_la_SOURCES = $(sources)
mca_db_hash_la_LDFLAGS = -module -avoid-version mca_dstore_hash_la_LDFLAGS = -module -avoid-version
mca_db_hash_la_LIBADD = $(db_hash_LIBS) mca_dstore_hash_la_LIBADD = $(dstore_hash_LIBS)
noinst_LTLIBRARIES = $(component_noinst) noinst_LTLIBRARIES = $(component_noinst)
libmca_db_hash_la_SOURCES =$(sources) libmca_dstore_hash_la_SOURCES =$(sources)
libmca_db_hash_la_LDFLAGS = -module -avoid-version libmca_dstore_hash_la_LDFLAGS = -module -avoid-version

249
opal/mca/dstore/hash/dstore_hash.c Обычный файл
Просмотреть файл

@ -0,0 +1,249 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2004-2011 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2011-2013 Los Alamos National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#include "opal_config.h"
#include "opal/constants.h"
#include <time.h>
#include <string.h>
#include "opal_stdint.h"
#include "opal/class/opal_hash_table.h"
#include "opal/class/opal_pointer_array.h"
#include "opal/dss/dss_types.h"
#include "opal/util/error.h"
#include "opal/util/output.h"
#include "opal/util/show_help.h"
#include "opal/mca/dstore/base/base.h"
#include "dstore_hash.h"
static int init(struct opal_dstore_base_module_t *imod);
static void finalize(struct opal_dstore_base_module_t *imod);
static int store(struct opal_dstore_base_module_t *imod,
const opal_identifier_t *proc,
opal_value_t *val);
static int fetch(struct opal_dstore_base_module_t *imod,
const opal_identifier_t *proc,
const char *key,
opal_list_t *kvs);
static int remove_data(struct opal_dstore_base_module_t *imod,
const opal_identifier_t *proc, const char *key);
mca_dstore_hash_module_t opal_dstore_hash_module = {
{
init,
finalize,
store,
NULL,
fetch,
remove_data
}
};
/* Initialize our hash table */
static int init(struct opal_dstore_base_module_t *imod)
{
mca_dstore_hash_module_t *mod;
mod = (mca_dstore_hash_module_t*)imod;
OBJ_CONSTRUCT(&mod->hash_data, opal_hash_table_t);
opal_hash_table_init(&mod->hash_data, 256);
return OPAL_SUCCESS;
}
static void finalize(struct opal_dstore_base_module_t *imod)
{
opal_dstore_proc_data_t *proc_data;
uint64_t key;
char *node;
mca_dstore_hash_module_t *mod;
mod = (mca_dstore_hash_module_t*)imod;
/* to assist in getting a clean valgrind, cycle thru the hash table
* and release all data stored in it
*/
if (OPAL_SUCCESS == opal_hash_table_get_first_key_uint64(&mod->hash_data, &key,
(void**)&proc_data,
(void**)&node)) {
if (NULL != proc_data) {
OBJ_RELEASE(proc_data);
}
while (OPAL_SUCCESS == opal_hash_table_get_next_key_uint64(&mod->hash_data, &key,
(void**)&proc_data,
node, (void**)&node)) {
if (NULL != proc_data) {
OBJ_RELEASE(proc_data);
}
}
}
OBJ_DESTRUCT(&mod->hash_data);
}
static int store(struct opal_dstore_base_module_t *imod,
const opal_identifier_t *uid,
opal_value_t *val)
{
opal_dstore_proc_data_t *proc_data;
opal_value_t *kv;
opal_identifier_t id;
mca_dstore_hash_module_t *mod;
int rc;
mod = (mca_dstore_hash_module_t*)imod;
/* to protect alignment, copy the identifier across */
memcpy(&id, uid, sizeof(opal_identifier_t));
opal_output_verbose(1, opal_dstore_base_framework.framework_output,
"dstore:hash:store storing data for proc %" PRIu64 "", id);
/* lookup the proc data object for this proc */
if (NULL == (proc_data = opal_dstore_base_lookup_proc(&mod->hash_data, id))) {
/* unrecoverable error */
OPAL_OUTPUT_VERBOSE((5, opal_dstore_base_framework.framework_output,
"dstore:hash:store: storing data for proc %" PRIu64 " unrecoverably failed",
id));
return OPAL_ERR_OUT_OF_RESOURCE;
}
/* see if we already have this key in the data - means we are updating
* a pre-existing value
*/
kv = opal_dstore_base_lookup_keyval(proc_data, val->key);
OPAL_OUTPUT_VERBOSE((5, opal_dstore_base_framework.framework_output,
"dstore:hash:store: %s key %s[%s] for proc %" PRIu64 "",
(NULL == kv ? "storing" : "updating"),
val->key, opal_dss.lookup_data_type(val->type), id));
if (NULL != kv) {
opal_list_remove_item(&proc_data->data, &kv->super);
OBJ_RELEASE(kv);
}
/* create the copy */
if (OPAL_SUCCESS != (rc = opal_dss.copy((void**)&kv, val, OPAL_VALUE))) {
OPAL_ERROR_LOG(rc);
return rc;
}
opal_list_append(&proc_data->data, &kv->super);
return OPAL_SUCCESS;
}
static int fetch(struct opal_dstore_base_module_t *imod,
const opal_identifier_t *uid,
const char *key, opal_list_t *kvs)
{
opal_dstore_proc_data_t *proc_data;
opal_value_t *kv, *knew;
opal_identifier_t id;
mca_dstore_hash_module_t *mod;
int rc;
mod = (mca_dstore_hash_module_t*)imod;
/* to protect alignment, copy the identifier across */
memcpy(&id, uid, sizeof(opal_identifier_t));
OPAL_OUTPUT_VERBOSE((5, opal_dstore_base_framework.framework_output,
"dstore:hash:fetch: searching for key %s on proc %" PRIu64 "",
(NULL == key) ? "NULL" : key, id));
/* lookup the proc data object for this proc */
if (NULL == (proc_data = opal_dstore_base_lookup_proc(&mod->hash_data, id))) {
OPAL_OUTPUT_VERBOSE((5, opal_dstore_base_framework.framework_output,
"dstore_hash:fetch data for proc %" PRIu64 " not found", id));
return OPAL_ERR_NOT_FOUND;
}
/* if the key is NULL, that we want everything */
if (NULL == key) {
OPAL_LIST_FOREACH(kv, &proc_data->data, opal_value_t) {
/* copy the value */
if (OPAL_SUCCESS != (rc = opal_dss.copy((void**)&knew, kv, OPAL_VALUE))) {
OPAL_ERROR_LOG(rc);
return rc;
}
/* add it to the output list */
opal_list_append(kvs, &knew->super);
}
return OPAL_SUCCESS;
}
/* find the value */
if (NULL == (kv = opal_dstore_base_lookup_keyval(proc_data, key))) {
OPAL_OUTPUT_VERBOSE((5, opal_dstore_base_framework.framework_output,
"dstore_hash:fetch key %s for proc %" PRIu64 " not found",
(NULL == key) ? "NULL" : key, id));
return OPAL_ERR_NOT_FOUND;
}
/* create the copy */
if (OPAL_SUCCESS != (rc = opal_dss.copy((void**)&knew, kv, OPAL_VALUE))) {
OPAL_ERROR_LOG(rc);
return rc;
}
/* add it to the output list */
opal_list_append(kvs, &knew->super);
return OPAL_SUCCESS;
}
static int remove_data(struct opal_dstore_base_module_t *imod,
const opal_identifier_t *uid, const char *key)
{
opal_dstore_proc_data_t *proc_data;
opal_value_t *kv;
opal_identifier_t id;
mca_dstore_hash_module_t *mod;
mod = (mca_dstore_hash_module_t*)imod;
/* to protect alignment, copy the identifier across */
memcpy(&id, uid, sizeof(opal_identifier_t));
/* lookup the specified proc */
if (NULL == (proc_data = opal_dstore_base_lookup_proc(&mod->hash_data, id))) {
/* no data for this proc */
return OPAL_SUCCESS;
}
/* if key is NULL, remove all data for this proc */
if (NULL == key) {
while (NULL != (kv = (opal_value_t *) opal_list_remove_first(&proc_data->data))) {
OBJ_RELEASE(kv);
}
/* remove the proc_data object itself from the jtable */
opal_hash_table_remove_value_uint64(&mod->hash_data, id);
/* cleanup */
OBJ_RELEASE(proc_data);
return OPAL_SUCCESS;
}
/* remove this item */
OPAL_LIST_FOREACH(kv, &proc_data->data, opal_value_t) {
if (0 == strcmp(key, kv->key)) {
opal_list_remove_item(&proc_data->data, &kv->super);
OBJ_RELEASE(kv);
break;
}
}
return OPAL_SUCCESS;
}

31
opal/mca/dstore/hash/dstore_hash.h Обычный файл
Просмотреть файл

@ -0,0 +1,31 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_DSTORE_HASH_H
#define OPAL_DSTORE_HASH_H
#include "opal/class/opal_hash_table.h"
#include "opal/mca/dstore/dstore.h"
BEGIN_C_DECLS
OPAL_MODULE_DECLSPEC extern opal_dstore_base_component_t mca_dstore_hash_component;
typedef struct {
opal_dstore_base_module_t api;
opal_hash_table_t hash_data;
} mca_dstore_hash_module_t;
OPAL_MODULE_DECLSPEC extern mca_dstore_hash_module_t opal_dstore_hash_module;
END_C_DECLS
#endif /* OPAL_DSTORE_HASH_H */

100
opal/mca/dstore/hash/dstore_hash_component.c Обычный файл
Просмотреть файл

@ -0,0 +1,100 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
* These symbols are in a file by themselves to provide nice linker
* semantics. Since linkers generally pull in symbols by object
* files, keeping these symbols as the only symbols in this file
* prevents utility programs such as "ompi_info" from having to import
* entire components just to query their version and parameters.
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal/mca/base/base.h"
#include "opal/util/error.h"
#include "opal/mca/dstore/dstore.h"
#include "opal/mca/dstore/base/base.h"
#include "dstore_hash.h"
static int dstore_hash_component_register(void);
static bool component_avail(void);
static opal_dstore_base_module_t *component_create(void);
/*
* Instantiate the public struct with all of our public information
* and pointers to our public functions in it
*/
opal_dstore_base_component_t mca_dstore_hash_component = {
{
OPAL_DSTORE_BASE_VERSION_2_0_0,
/* Component name and version */
"hash",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component open and close functions */
NULL,
NULL,
NULL,
dstore_hash_component_register
},
{
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
1,
component_avail,
component_create,
NULL
};
static int dstore_hash_component_register(void)
{
mca_base_component_t *c = &mca_dstore_hash_component.base_version;
mca_dstore_hash_component.priority = 1;
(void) mca_base_component_var_register(c, "priority",
"Priority dictating order in which components will be considered",
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&mca_dstore_hash_component.priority);
return OPAL_SUCCESS;
}
static bool component_avail(void)
{
/* we are always available */
return true;
}
static opal_dstore_base_module_t *component_create(void)
{
mca_dstore_hash_module_t *mod;
mod = (mca_dstore_hash_module_t*)malloc(sizeof(mca_dstore_hash_module_t));
if (NULL == mod) {
OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE);
return NULL;
}
/* copy the APIs across */
memcpy(mod, &opal_dstore_hash_module.api, sizeof(opal_dstore_base_module_t));
/* let the module init itself */
if (OPAL_SUCCESS != mod->api.init((struct opal_dstore_base_module_t*)mod)) {
/* release the module and return the error */
free(mod);
return NULL;
}
return (opal_dstore_base_module_t*)mod;
}

39
opal/mca/dstore/pmi/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,39 @@
#
# Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
sources = \
dstore_pmi.h \
dstore_pmi_component.c \
dstore_pmi.c
# Make the output library in this directory, and name it either
# mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la
# (for static builds).
if MCA_BUILD_opal_dstore_pmi_DSO
component_noinst =
component_install = mca_dstore_pmi.la
else
component_noinst = libmca_dstore_pmi.la
component_install =
endif
mcacomponentdir = $(ompilibdir)
mcacomponent_LTLIBRARIES = $(component_install)
mca_dstore_pmi_la_SOURCES = $(sources)
mca_dstore_pmi_la_CPPFLAGS = $(dstore_pmi_CPPFLAGS)
mca_dstore_pmi_la_LDFLAGS = -module -avoid-version $(dstore_pmi_LDFLAGS)
mca_dstore_pmi_la_LIBADD = $(dstore_pmi_LIBS) \
$(top_ompi_builddir)/opal/mca/common/pmi/libmca_common_pmi.la
noinst_LTLIBRARIES = $(component_noinst)
libmca_dstore_pmi_la_SOURCES =$(sources)
libmca_dstore_pmi_la_CPPFLAGS = $(dstore_pmi_CPPFLAGS)
libmca_dstore_pmi_la_LDFLAGS = -module -avoid-version $(dstore_pmi_LDFLAGS)
libmca_dstore_pmi_la_LIBADD = $(dstore_pmi_LIBS)

Просмотреть файл

@ -8,21 +8,21 @@
# #
# $HEADER$ # $HEADER$
# #
# MCA_db_pmi_CONFIG([action-if-found], [action-if-not-found]) # MCA_dstore_pmi_CONFIG([action-if-found], [action-if-not-found])
# ----------------------------------------------------------- # -----------------------------------------------------------
AC_DEFUN([MCA_opal_db_pmi_CONFIG], [ AC_DEFUN([MCA_opal_dstore_pmi_CONFIG], [
AC_CONFIG_FILES([opal/mca/db/pmi/Makefile]) AC_CONFIG_FILES([opal/mca/dstore/pmi/Makefile])
OPAL_CHECK_PMI([db_pmi], [db_pmi_good=1], [db_pmi_good=0]) OPAL_CHECK_PMI([dstore_pmi], [dstore_pmi_good=1], [dstore_pmi_good=0])
# Evaluate succeed / fail # Evaluate succeed / fail
AS_IF([test "$db_pmi_good" = 1], AS_IF([test "$dstore_pmi_good" = 1],
[$1], [$1],
[$2]) [$2])
# set build flags to use in makefile # set build flags to use in makefile
AC_SUBST([db_pmi_CPPFLAGS]) AC_SUBST([dstore_pmi_CPPFLAGS])
AC_SUBST([db_pmi_LDFLAGS]) AC_SUBST([dstore_pmi_LDFLAGS])
AC_SUBST([db_pmi_LIBS]) AC_SUBST([dstore_pmi_LIBS])
]) ])

741
opal/mca/dstore/pmi/dstore_pmi.c Обычный файл
Просмотреть файл

@ -0,0 +1,741 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#include "opal_config.h"
#include "opal/constants.h"
#include <time.h>
#include <string.h>
#include <pmi.h>
#if WANT_PMI2_SUPPORT
#include <pmi2.h>
#endif
#include <regex.h>
#include "opal_stdint.h"
#include "opal/class/opal_pointer_array.h"
#include "opal/dss/dss_types.h"
#include "opal/util/argv.h"
#include "opal/util/error.h"
#include "opal/util/output.h"
#include "opal/util/show_help.h"
#include "opal/mca/common/pmi/common_pmi.h"
#include "opal/mca/dstore/base/base.h"
#include "dstore_pmi.h"
#define OPAL_PMI_PAD 10
static void finalize(struct opal_dstore_base_module_t *imod);
static int store(struct opal_dstore_base_module_t *imod,
const opal_identifier_t *proc,
opal_value_t *kv);
static void commit(struct opal_dstore_base_module_t *mod,
const opal_identifier_t *id);
static int fetch(struct opal_dstore_base_module_t *imod,
const opal_identifier_t *proc,
const char *key,
opal_list_t *kvs);
static int remove_data(struct opal_dstore_base_module_t *imod,
const opal_identifier_t *proc, const char *key);
mca_dstore_pmi_module_t opal_dstore_pmi_module = {
{
NULL,
finalize,
store,
commit,
fetch,
remove_data
}
};
static char *pmi_encode(const void *val, size_t vallen);
static uint8_t* pmi_decode(const char *data, size_t *retlen);
static char* setup_key(mca_dstore_pmi_module_t *mod,
opal_identifier_t name, const char *key);
/* Local variables */
/* Because Cray uses PMI2 extensions for some, but not all,
* PMI functions, we define a set of wrappers for those
* common functions we will use
*/
static int kvs_put(mca_dstore_pmi_module_t *mod,
const char *key, const char *value)
{
#if WANT_PMI2_SUPPORT
return PMI2_KVS_Put(key, value);
#else
return PMI_KVS_Put(mod->pmi_kvs_name, key, value);
#endif
}
static int kvs_get(mca_dstore_pmi_module_t *mod,
const char *key, char *value, int valuelen)
{
#if WANT_PMI2_SUPPORT
int len;
return PMI2_KVS_Get(mod->pmi_kvs_name, PMI2_ID_NULL, key, value, valuelen, &len);
#else
return PMI_KVS_Get(mod->pmi_kvs_name, key, value, valuelen);
#endif
}
static void finalize(struct opal_dstore_base_module_t *imod)
{
mca_dstore_pmi_module_t *mod;
opal_dstore_proc_data_t *proc_data;
uint64_t key;
char *node;
mod = (mca_dstore_pmi_module_t*)imod;
if (NULL != mod->pmi_kvs_name) {
free(mod->pmi_kvs_name);
mod->pmi_kvs_name = NULL;
}
/* to assist in getting a clean valgrind, cycle thru the hash table
* and release all data stored in it
*/
if (OPAL_SUCCESS == opal_hash_table_get_first_key_uint64(&mod->hash_data, &key,
(void**)&proc_data,
(void**)&node)) {
if (NULL != proc_data) {
OBJ_RELEASE(proc_data);
}
while (OPAL_SUCCESS == opal_hash_table_get_next_key_uint64(&mod->hash_data, &key,
(void**)&proc_data,
node, (void**)&node)) {
if (NULL != proc_data) {
OBJ_RELEASE(proc_data);
}
}
}
OBJ_DESTRUCT(&mod->hash_data);
}
static int pmi_commit_packed(mca_dstore_pmi_module_t *mod,
opal_identifier_t proc) {
char *pmikey = NULL, *tmp;
char tmp_key[32], save;
char *encoded_data;
int rc, left;
if (mod->pmi_packed_data_off == 0) {
/* nothing to write */
return OPAL_SUCCESS;
}
if (NULL == (encoded_data = pmi_encode(mod->pmi_packed_data, mod->pmi_packed_data_off))) {
OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE);
return OPAL_ERR_OUT_OF_RESOURCE;
}
for (left = strlen (encoded_data), tmp = encoded_data ; left ; ) {
size_t value_size = mod->pmi_vallen_max > left ? left : mod->pmi_vallen_max - 1;
sprintf (tmp_key, "key%d", mod->pmi_pack_key);
if (NULL == (pmikey = setup_key(mod, proc, tmp_key))) {
OPAL_ERROR_LOG(OPAL_ERR_BAD_PARAM);
rc = OPAL_ERR_BAD_PARAM;
break;
}
/* only write value_size bytes */
save = tmp[value_size];
tmp[value_size] = '\0';
rc = kvs_put(mod, pmikey, tmp);
free(pmikey);
if (PMI_SUCCESS != rc) {
OPAL_PMI_ERROR(rc, "PMI_KVS_Put");
rc = OPAL_ERROR;
break;
}
tmp[value_size] = save;
tmp += value_size;
left -= value_size;
mod->pmi_pack_key ++;
rc = OPAL_SUCCESS;
}
if (encoded_data) {
free(encoded_data);
}
mod->pmi_packed_data_off = 0;
free(mod->pmi_packed_data);
mod->pmi_packed_data = NULL;
return rc;
}
static int pmi_store_encoded(mca_dstore_pmi_module_t *mod,
const char *key, const void *data,
opal_data_type_t type)
{
opal_byte_object_t *bo;
size_t data_len = 0;
size_t needed;
switch (type) {
case OPAL_STRING:
data_len = data ? strlen (data) + 1 : 0;
break;
case OPAL_INT:
case OPAL_UINT:
data_len = sizeof (int);
break;
case OPAL_INT16:
case OPAL_UINT16:
data_len = sizeof (int16_t);
break;
case OPAL_INT32:
case OPAL_UINT32:
data_len = sizeof (int32_t);
break;
case OPAL_INT64:
case OPAL_UINT64:
data_len = sizeof (int64_t);
break;
case OPAL_BYTE_OBJECT:
bo = (opal_byte_object_t *) data;
data = bo->bytes;
data_len = bo->size;
}
needed = 10 + data_len + strlen (key);
if (NULL == mod->pmi_packed_data) {
mod->pmi_packed_data = calloc (needed, 1);
} else {
/* grow the region */
mod->pmi_packed_data = realloc (mod->pmi_packed_data, mod->pmi_packed_data_off + needed);
}
/* special length meaning NULL */
if (NULL == data) {
data_len = 0xffff;
}
/* serialize the opal datatype */
mod->pmi_packed_data_off += sprintf (mod->pmi_packed_data + mod->pmi_packed_data_off,
"%s%c%02x%c%04x%c", key, '\0', type, '\0',
(int) data_len, '\0');
if (NULL != data) {
memmove (mod->pmi_packed_data + mod->pmi_packed_data_off, data, data_len);
mod->pmi_packed_data_off += data_len;
}
return OPAL_SUCCESS;
}
static int pmi_get_packed(mca_dstore_pmi_module_t *mod,
opal_identifier_t proc,
char **packed_data, size_t *len)
{
char *tmp_encoded = NULL, *pmikey, *pmi_tmp;
int remote_key, size;
size_t bytes_read;
int rc;
/* set default */
*packed_data = NULL;
*len = 0;
pmi_tmp = calloc (mod->pmi_vallen_max, 1);
if (NULL == pmi_tmp) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
/* read all of the packed data from this proc */
for (remote_key = 0, bytes_read = 0 ; ; ++remote_key) {
char tmp_key[32];
sprintf (tmp_key, "key%d", remote_key);
if (NULL == (pmikey = setup_key(mod, proc, tmp_key))) {
rc = OPAL_ERR_OUT_OF_RESOURCE;
OPAL_ERROR_LOG(rc);
return rc;
}
OPAL_OUTPUT_VERBOSE((10, opal_dstore_base_framework.framework_output,
"GETTING KEY %s", pmikey));
rc = kvs_get(mod, pmikey, pmi_tmp, mod->pmi_vallen_max);
free (pmikey);
if (PMI_SUCCESS != rc) {
break;
}
size = strlen (pmi_tmp);
if (NULL == tmp_encoded) {
tmp_encoded = malloc (size + 1);
} else {
tmp_encoded = realloc (tmp_encoded, bytes_read + size + 1);
}
strcpy (tmp_encoded + bytes_read, pmi_tmp);
bytes_read += size;
/* is the string terminator present? */
if ('-' == tmp_encoded[bytes_read-1]) {
break;
}
}
free (pmi_tmp);
OPAL_OUTPUT_VERBOSE((10, opal_dstore_base_framework.framework_output,
"Read data %s\n",
(NULL == tmp_encoded) ? "NULL" : tmp_encoded));
if (NULL != tmp_encoded) {
*packed_data = (char *) pmi_decode (tmp_encoded, len);
free (tmp_encoded);
if (NULL == *packed_data) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
}
return OPAL_SUCCESS;
}
static void cache_keys_locally(mca_dstore_pmi_module_t *mod,
opal_identifier_t id,
opal_dstore_proc_data_t *proc_data)
{
char *tmp, *tmp2, *tmp3, *tmp_val;
opal_data_type_t stored_type;
size_t len, offset;
int rc, size;
opal_value_t *kv;
OPAL_OUTPUT_VERBOSE((1, opal_dstore_base_framework.framework_output,
"dstore:pmi:fetch get all keys for proc %" PRIu64 " in KVS %s",
id, mod->pmi_kvs_name));
rc = pmi_get_packed(mod, id, &tmp_val, &len);
if (OPAL_SUCCESS != rc) {
return;
}
/* search for each key in the decoded data */
for (offset = 0 ; offset < len && '\0' != tmp_val[offset] ; ) {
/* type */
tmp = tmp_val + offset + strlen (tmp_val + offset) + 1;
/* size */
tmp2 = tmp + strlen (tmp) + 1;
/* data */
tmp3 = tmp2 + strlen (tmp2) + 1;
stored_type = (opal_data_type_t) strtol (tmp, NULL, 16);
size = strtol (tmp2, NULL, 16);
/* cache value locally so we don't have to look it up via pmi again */
kv = OBJ_NEW(opal_value_t);
kv->key = strdup(tmp_val + offset);
kv->type = stored_type;
opal_list_append(&proc_data->data, &kv->super);
switch (stored_type) {
case OPAL_BYTE:
kv->data.byte = *tmp3;
break;
case OPAL_STRING:
if (NULL != tmp3) {
kv->data.string = strdup(tmp3);
} else {
kv->data.string = NULL;
}
break;
case OPAL_PID:
kv->data.pid = strtoul(tmp3, NULL, 10);
break;
case OPAL_INT:
kv->data.integer = strtol(tmp3, NULL, 10);
break;
case OPAL_INT8:
kv->data.int8 = strtol(tmp3, NULL, 10);
break;
case OPAL_INT16:
kv->data.int16 = strtol(tmp3, NULL, 10);
break;
case OPAL_INT32:
kv->data.int32 = strtol(tmp3, NULL, 10);
break;
case OPAL_INT64:
kv->data.int64 = strtol(tmp3, NULL, 10);
break;
case OPAL_UINT:
kv->data.uint = strtoul(tmp3, NULL, 10);
break;
case OPAL_UINT8:
kv->data.uint8 = strtoul(tmp3, NULL, 10);
break;
case OPAL_UINT16:
kv->data.uint16 = strtoul(tmp3, NULL, 10);
break;
case OPAL_UINT32:
kv->data.uint32 = strtoul(tmp3, NULL, 10);
break;
case OPAL_UINT64:
kv->data.uint64 = strtoul(tmp3, NULL, 10);
break;
case OPAL_BYTE_OBJECT:
if (size == 0xffff) {
kv->data.bo.bytes = NULL;
kv->data.bo.size = 0;
} else {
kv->data.bo.bytes = malloc(size);
memcpy(kv->data.bo.bytes, tmp3, size);
kv->data.bo.size = size;
}
break;
default:
opal_output(0, "UNSUPPORTED TYPE %d", stored_type);
return;
}
/* keep going and cache everything locally */
offset = (size_t) (tmp3 - tmp_val) + size;
}
proc_data->loaded = true;
free (tmp_val);
}
static int store(struct opal_dstore_base_module_t *imod,
const opal_identifier_t *uid,
opal_value_t *val)
{
int rc;
opal_value_t *kv;
opal_dstore_proc_data_t *proc_data;
opal_identifier_t id;
mca_dstore_pmi_module_t *mod;
mod = (mca_dstore_pmi_module_t*)imod;
/* to protect alignment, copy the data across */
memcpy(&id, uid, sizeof(opal_identifier_t));
OPAL_OUTPUT_VERBOSE((5, opal_dstore_base_framework.framework_output,
"dstore:pmi:store: storing %s for proc %" PRIu64 "",
val->key, id));
/* lookup the proc data object for this proc */
if (NULL == (proc_data = opal_dstore_base_lookup_proc(&mod->hash_data, id))) {
/* unrecoverable error */
OPAL_OUTPUT_VERBOSE((5, opal_dstore_base_framework.framework_output,
"dstore:pmi:store: storing data for proc %" PRIu64 " unrecoverably failed",
id));
return OPAL_ERR_OUT_OF_RESOURCE;
}
if (proc_data->loaded) {
return OPAL_SUCCESS;
}
/* add it to our PMI payload */
if (OPAL_SUCCESS != (rc = pmi_store_encoded(mod, val->key, (void*)&val->data, val->type))) {
OPAL_ERROR_LOG(rc);
return rc;
}
/* retain a local copy */
kv = opal_dstore_base_lookup_keyval(proc_data, val->key);
OPAL_OUTPUT_VERBOSE((5, opal_dstore_base_framework.framework_output,
"dstore:hash:store: %s key %s[%s] for proc %" PRIu64 "",
(NULL == kv ? "storing" : "updating"),
val->key, opal_dss.lookup_data_type(val->type), id));
if (NULL != kv) {
opal_list_remove_item(&proc_data->data, &kv->super);
OBJ_RELEASE(kv);
}
/* create the copy */
if (OPAL_SUCCESS != (rc = opal_dss.copy((void**)&kv, val, OPAL_VALUE))) {
OPAL_ERROR_LOG(rc);
return rc;
}
opal_list_append(&proc_data->data, &kv->super);
return OPAL_SUCCESS;
}
static void commit(struct opal_dstore_base_module_t *imod,
const opal_identifier_t *uid)
{
mca_dstore_pmi_module_t *mod;
opal_identifier_t id;
mod = (mca_dstore_pmi_module_t*)imod;
/* to protect alignment, copy the identifier across */
memcpy(&id, uid, sizeof(opal_identifier_t));
/* commit the packed data to PMI */
pmi_commit_packed(mod, id);
#if WANT_PMI2_SUPPORT
PMI2_KVS_Fence();
#else
{
int rc;
if (PMI_SUCCESS != (rc = PMI_KVS_Commit(mod->pmi_kvs_name))) {
OPAL_PMI_ERROR(rc, "PMI_KVS_Commit");
return;
}
/* Barrier here to ensure all other procs have committed */
PMI_Barrier();
}
#endif
}
static int fetch(struct opal_dstore_base_module_t *imod,
const opal_identifier_t *uid,
const char *key, opal_list_t *kvs)
{
opal_dstore_proc_data_t *proc_data;
mca_dstore_pmi_module_t *mod;
opal_identifier_t id;
int rc;
opal_value_t *kv, *knew;
mod = (mca_dstore_pmi_module_t*)imod;
/* to protect alignment, copy the identifier across */
memcpy(&id, uid, sizeof(opal_identifier_t));
/* get the hash entry for this proc */
if (NULL == (proc_data = opal_dstore_base_lookup_proc(&mod->hash_data, id))) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
if (!proc_data->loaded) {
/* new proc - go get its data */
cache_keys_locally(mod, id, proc_data);
}
/* all keys will be available internally now. so
* retrieve the data from our hash table
*/
/* if the key is NULL, that we want everything */
if (NULL == key) {
OPAL_LIST_FOREACH(kv, &proc_data->data, opal_value_t) {
/* copy the value */
if (OPAL_SUCCESS != (rc = opal_dss.copy((void**)&knew, kv, OPAL_VALUE))) {
OPAL_ERROR_LOG(rc);
return rc;
}
/* add it to the output list */
opal_list_append(kvs, &knew->super);
}
return OPAL_SUCCESS;
}
/* find the value */
if (NULL == (kv = opal_dstore_base_lookup_keyval(proc_data, key))) {
OPAL_OUTPUT_VERBOSE((5, opal_dstore_base_framework.framework_output,
"dstore_pmi:fetch key %s for proc %" PRIu64 " not found",
(NULL == key) ? "NULL" : key, id));
return OPAL_ERR_NOT_FOUND;
}
/* create the copy */
if (OPAL_SUCCESS != (rc = opal_dss.copy((void**)&knew, kv, OPAL_VALUE))) {
OPAL_ERROR_LOG(rc);
return rc;
}
/* add it to the output list */
opal_list_append(kvs, &knew->super);
return OPAL_SUCCESS;
}
static int remove_data(struct opal_dstore_base_module_t *imod,
const opal_identifier_t *uid, const char *key)
{
opal_value_t *kv;
opal_identifier_t id;
mca_dstore_pmi_module_t *mod;
opal_dstore_proc_data_t *proc_data;
mod = (mca_dstore_pmi_module_t*)imod;
/* to protect alignment, copy the identifier across */
memcpy(&id, uid, sizeof(opal_identifier_t));
/* lookup the specified proc */
if (NULL == (proc_data = opal_dstore_base_lookup_proc(&mod->hash_data, id))) {
/* no data for this proc */
return OPAL_SUCCESS;
}
/* if key is NULL, remove all data for this proc */
if (NULL == key) {
while (NULL != (kv = (opal_value_t *) opal_list_remove_first(&proc_data->data))) {
OBJ_RELEASE(kv);
}
/* remove the proc_data object itself from the jtable */
opal_hash_table_remove_value_uint64(&mod->hash_data, id);
/* cleanup */
OBJ_RELEASE(proc_data);
return OPAL_SUCCESS;
}
/* remove this item */
OPAL_LIST_FOREACH(kv, &proc_data->data, opal_value_t) {
if (0 == strcmp(key, kv->key)) {
opal_list_remove_item(&proc_data->data, &kv->super);
OBJ_RELEASE(kv);
break;
}
}
return OPAL_SUCCESS;
}
static char* setup_key(mca_dstore_pmi_module_t *mod,
opal_identifier_t name, const char *key)
{
char *pmi_kvs_key;
if (mod->pmi_keylen_max <= asprintf(&pmi_kvs_key, "%" PRIu64 "-%s",
name, key)) {
free(pmi_kvs_key);
return NULL;
}
return pmi_kvs_key;
}
/* base64 encoding with illegal (to Cray PMI) characters removed ('=' is replaced by ' ') */
static inline unsigned char pmi_base64_encsym (unsigned char value) {
assert (value < 64);
if (value < 26) {
return 'A' + value;
} else if (value < 52) {
return 'a' + (value - 26);
} else if (value < 62) {
return '0' + (value - 52);
}
return (62 == value) ? '+' : '/';
}
static inline unsigned char pmi_base64_decsym (unsigned char value) {
if ('+' == value) {
return 62;
} else if ('/' == value) {
return 63;
} else if (' ' == value) {
return 64;
} else if (value <= '9') {
return (value - '0') + 52;
} else if (value <= 'Z') {
return (value - 'A');
} else if (value <= 'z') {
return (value - 'a') + 26;
}
return 64;
}
static inline void pmi_base64_encode_block (const unsigned char in[3], char out[4], int len) {
out[0] = pmi_base64_encsym (in[0] >> 2);
out[1] = pmi_base64_encsym (((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4));
/* Cray PMI doesn't allow = in PMI attributes so pad with spaces */
out[2] = 1 < len ? pmi_base64_encsym(((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6)) : ' ';
out[3] = 2 < len ? pmi_base64_encsym(in[2] & 0x3f) : ' ';
}
static inline int pmi_base64_decode_block (const char in[4], unsigned char out[3]) {
char in_dec[4];
in_dec[0] = pmi_base64_decsym (in[0]);
in_dec[1] = pmi_base64_decsym (in[1]);
in_dec[2] = pmi_base64_decsym (in[2]);
in_dec[3] = pmi_base64_decsym (in[3]);
out[0] = in_dec[0] << 2 | in_dec[1] >> 4;
if (64 == in_dec[2]) {
return 1;
}
out[1] = in_dec[1] << 4 | in_dec[2] >> 2;
if (64 == in_dec[3]) {
return 2;
}
out[2] = ((in_dec[2] << 6) & 0xc0) | in_dec[3];
return 3;
}
/* PMI only supports strings. For now, do a simple base64. */
static char *pmi_encode(const void *val, size_t vallen) {
char *outdata, *tmp;
size_t i;
outdata = calloc (((2 + vallen) * 4) / 3 + 2, 1);
if (NULL == outdata) {
return NULL;
}
for (i = 0, tmp = outdata ; i < vallen ; i += 3, tmp += 4) {
pmi_base64_encode_block((unsigned char *) val + i, tmp, vallen - i);
}
/* mark the end of the pmi string */
tmp[0] = (unsigned char)'-';
tmp[1] = (unsigned char)'\0';
return outdata;
}
static uint8_t *pmi_decode (const char *data, size_t *retlen) {
size_t input_len = (strlen (data) - 1) / 4;
unsigned char *ret;
int out_len;
size_t i;
/* default */
*retlen = 0;
ret = calloc (1, 3 * input_len + 1);
if (NULL == ret) {
return ret;
}
for (i = 0, out_len = 0 ; i < input_len ; i++, data += 4) {
out_len += pmi_base64_decode_block(data, ret + 3 * i);
}
ret[out_len] = '\0';
*retlen = out_len;
return ret;
}

37
opal/mca/dstore/pmi/dstore_pmi.h Обычный файл
Просмотреть файл

@ -0,0 +1,37 @@
/*
* Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_DSTORE_PMI_H
#define OPAL_DSTORE_PMI_H
#include "opal/util/error.h"
#include "opal/mca/dstore/dstore.h"
BEGIN_C_DECLS
OPAL_MODULE_DECLSPEC extern opal_dstore_base_component_t mca_dstore_pmi_component;
typedef struct {
opal_dstore_base_module_t api;
char *pmi_kvs_name;
int pmi_vallen_max;
int pmi_keylen_max;
char *pmi_packed_data;
int pmi_pack_key;
int pmi_packed_data_off;
opal_hash_table_t hash_data;
} mca_dstore_pmi_module_t;
OPAL_MODULE_DECLSPEC extern mca_dstore_pmi_module_t opal_dstore_pmi_module;
END_C_DECLS
#endif /* OPAL_DSTORE_PMI_H */

186
opal/mca/dstore/pmi/dstore_pmi_component.c Обычный файл
Просмотреть файл

@ -0,0 +1,186 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/constants.h"
#include <pmi.h>
#if WANT_PMI2_SUPPORT
#include <pmi2.h>
#endif
#include "opal/mca/base/base.h"
#include "opal/mca/common/pmi/common_pmi.h"
#include "opal/mca/dstore/dstore.h"
#include "opal/mca/dstore/base/base.h"
#include "dstore_pmi.h"
static int dstore_pmi_component_register(void);
static bool component_avail(void);
static opal_dstore_base_module_t *component_create(void);
static void component_finalize(void);
static int setup_pmi(void);
/* local storage */
static char *pmi_kvs_name = NULL;
static int pmi_vallen_max = -1;
static int pmi_keylen_max = -1;
/*
* Instantiate the public struct with all of our public information
* and pointers to our public functions in it
*/
opal_dstore_base_component_t mca_dstore_pmi_component = {
{
OPAL_DSTORE_BASE_VERSION_2_0_0,
/* Component name and version */
"pmi",
OPAL_MAJOR_VERSION,
OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION,
/* Component open and close functions */
NULL,
NULL,
NULL,
dstore_pmi_component_register
},
{
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
80,
component_avail,
component_create,
component_finalize
};
static int dstore_pmi_component_register(void)
{
mca_base_component_t *c = &mca_dstore_pmi_component.base_version;
mca_dstore_pmi_component.priority = 80;
(void) mca_base_component_var_register(c, "priority",
"Priority dictating order in which components will be considered",
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&mca_dstore_pmi_component.priority);
return OPAL_SUCCESS;
}
static bool component_avail(void)
{
/* only use PMI if available - the ESS pmi module
* will force our selection if we are direct-launched,
* and the orted will turn us "off" if indirectly launched
*/
if (mca_common_pmi_init() && OPAL_SUCCESS == setup_pmi()) {
return true;
}
/* if not, then we are not available */
return false;
}
static void component_finalize(void)
{
mca_common_pmi_finalize();
if (NULL != pmi_kvs_name) {
free(pmi_kvs_name);
}
}
static opal_dstore_base_module_t *component_create(void)
{
mca_dstore_pmi_module_t *mod;
mod = (mca_dstore_pmi_module_t*)malloc(sizeof(mca_dstore_pmi_module_t));
if (NULL == mod) {
OPAL_ERROR_LOG(OPAL_ERR_OUT_OF_RESOURCE);
return NULL;
}
/* copy the APIs across */
memcpy(mod, &opal_dstore_pmi_module.api, sizeof(opal_dstore_base_module_t));
/* copy the global values */
mod->pmi_kvs_name = strdup(pmi_kvs_name);
mod->pmi_vallen_max = pmi_vallen_max;
mod->pmi_keylen_max = pmi_keylen_max;
/* init the other values */
mod->pmi_packed_data = NULL;
mod->pmi_pack_key = 0;
mod->pmi_packed_data_off = 0;
OBJ_CONSTRUCT(&mod->hash_data, opal_hash_table_t);
opal_hash_table_init(&mod->hash_data, 256);
return (opal_dstore_base_module_t*)mod;
}
static int setup_pmi(void)
{
int max_length, rc;
#if WANT_PMI2_SUPPORT
pmi_vallen_max = PMI2_MAX_VALLEN;
max_length = PMI2_MAX_VALLEN;
#else
rc = PMI_KVS_Get_value_length_max(&pmi_vallen_max);
if (PMI_SUCCESS != rc) {
OPAL_OUTPUT_VERBOSE((1, opal_dstore_base_framework.framework_output,
"dstore:pmi:pmi_setup failed %s with error %s",
"PMI_Get_value_length_max",
opal_errmgr_base_pmi_error(rc)));
return OPAL_ERROR;
}
if (PMI_SUCCESS != (rc = PMI_KVS_Get_name_length_max(&max_length))) {
OPAL_OUTPUT_VERBOSE((1, opal_dstore_base_framework.framework_output,
"dstore:pmi:pmi_setup failed %s with error %s",
"PMI_KVS_Get_name_length_max",
opal_errmgr_base_pmi_error(rc)));
return OPAL_ERROR;
}
#endif
pmi_kvs_name = (char*)malloc(max_length);
if (NULL == pmi_kvs_name) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
#if WANT_PMI2_SUPPORT
rc = PMI2_Job_GetId(pmi_kvs_name, max_length);
#else
rc = PMI_KVS_Get_my_name(pmi_kvs_name,max_length);
#endif
if (PMI_SUCCESS != rc) {
OPAL_OUTPUT_VERBOSE((1, opal_dstore_base_framework.framework_output,
"dstore:pmi:pmi_setup failed %s with error %s on maxlength %d",
"PMI_KVS_Get_my_name",
opal_errmgr_base_pmi_error(rc), max_length));
return OPAL_ERROR;
}
#if WANT_PMI2_SUPPORT
pmi_keylen_max = PMI2_MAX_KEYLEN;
#else
if (PMI_SUCCESS != (rc = PMI_KVS_Get_key_length_max(&pmi_keylen_max))) {
OPAL_OUTPUT_VERBOSE((1, opal_dstore_base_framework.framework_output,
"dstore:pmi:pmi_setup failed %s with error %s",
"PMI_KVS_Get_key_length_max",
opal_errmgr_base_pmi_error(rc)));
return OPAL_ERROR;
}
#endif
return OPAL_SUCCESS;
}

Просмотреть файл

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow

Просмотреть файл

@ -1,6 +1,7 @@
/* /*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* *
* $COPYRIGHT$ * $COPYRIGHT$
* *
@ -32,14 +33,6 @@
BEGIN_C_DECLS BEGIN_C_DECLS
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
typedef unsigned char u_char;
typedef unsigned short u_short;
#endif
/* set the number of event priority levels */ /* set the number of event priority levels */
#define OPAL_EVENT_NUM_PRI 8 #define OPAL_EVENT_NUM_PRI 8
@ -56,15 +49,6 @@ typedef unsigned short u_short;
#define OPAL_TIMEOUT_DEFAULT {1, 0} #define OPAL_TIMEOUT_DEFAULT {1, 0}
/* This is to prevent event library from picking up the win32_ops
since this will be picked up over select(). By using select, we can
pretty much use the OOB and PTL as is. Otherwise, there would have
to be a lot of magic to be done to get this to work */
#if defined(__WINDOWS__)
/*extern const eventop opal_win32ops;*/
#endif /* defined(__WINDOWS__) */
/** /**
* Structure for event components. * Structure for event components.
*/ */

Просмотреть файл

@ -20,14 +20,15 @@
#include "opal/util/error.h" #include "opal/util/error.h"
#include "opal/util/output.h" #include "opal/util/output.h"
#include "opal/util/show_help.h" #include "opal/util/show_help.h"
#include "opal/mca/db/db.h" #include "opal/mca/dstore/dstore.h"
#include "opal/mca/sec/base/base.h" #include "opal/mca/sec/base/base.h"
#include "sec_basic.h" #include "sec_basic.h"
static int init(void); static int init(void);
static void finalize(void); static void finalize(void);
static int get_my_cred(opal_identifier_t *my_id, static int get_my_cred(int dstorehandle,
opal_identifier_t *my_id,
opal_sec_cred_t **cred); opal_sec_cred_t **cred);
static int authenticate(opal_sec_cred_t *cred); static int authenticate(opal_sec_cred_t *cred);
@ -53,23 +54,33 @@ static void finalize(void)
} }
} }
static int get_my_cred(opal_identifier_t *my_id, static int get_my_cred(int dstorehandle,
opal_identifier_t *my_id,
opal_sec_cred_t **cred) opal_sec_cred_t **cred)
{ {
opal_byte_object_t *cd; opal_list_t vals;
opal_value_t *kv;
if (!initialized) { if (!initialized) {
/* check first if a credential was stored for this job /* check first if a credential was stored for this job
* in the database * in the database
*/ */
if (OPAL_SUCCESS == opal_db.fetch(my_id, OPAL_DB_CREDENTIAL, OBJ_CONSTRUCT(&vals, opal_list_t);
(void**)&cd, OPAL_BYTE_OBJECT)) { if (OPAL_SUCCESS == opal_dstore.fetch(dstorehandle, my_id, OPAL_DSTORE_CREDENTIAL, &vals)) {
my_cred.credential = (char*)cd->bytes; kv = (opal_value_t*)opal_list_remove_first(&vals);
my_cred.size = cd->size; if (NULL == kv) {
my_cred.credential = strdup("12345");
my_cred.size = strlen(my_cred.credential)+1; // include the NULL
} else {
my_cred.credential = strdup(kv->data.string);
my_cred.size = strlen(kv->data.string);
OBJ_RELEASE(kv);
}
} else { } else {
my_cred.credential = strdup("12345"); my_cred.credential = strdup("12345");
my_cred.size = strlen(my_cred.credential)+1; // include the NULL my_cred.size = strlen(my_cred.credential)+1; // include the NULL
} }
OPAL_LIST_DESTRUCT(&vals);
} }
initialized = true; initialized = true;

Просмотреть файл

@ -32,7 +32,8 @@
static int init(void); static int init(void);
static void finalize(void); static void finalize(void);
static int get_my_cred(opal_identifier_t *my_id, static int get_my_cred(int dstorehandle,
opal_identifier_t *my_id,
opal_sec_cred_t **cred); opal_sec_cred_t **cred);
static int authenticate(opal_sec_cred_t *cred); static int authenticate(opal_sec_cred_t *cred);
@ -63,7 +64,8 @@ static size_t op_cbfunc(void *ptr, size_t size, size_t count, void *stream)
return size; return size;
} }
static int get_my_cred(opal_identifier_t *my_id, static int get_my_cred(int dstorehandle,
opal_identifier_t *my_id,
opal_sec_cred_t **cred) opal_sec_cred_t **cred)
{ {
char *cmd; char *cmd;

Просмотреть файл

@ -63,12 +63,18 @@ typedef void (*opal_sec_base_module_finalize_fn_t)(void);
* certificate as external security systems will have no idea what * certificate as external security systems will have no idea what
* it means. However, some modules may use it, and there is no way * it means. However, some modules may use it, and there is no way
* for the opal layer to know a process identifier without being told, * for the opal layer to know a process identifier without being told,
* do provide it here * so provide it here
*
* Likewise, the security framework isn't going to house its own datastore
* handle, and some modules may want to check to see if a credential
* was stored in the data store, so provide a means for passing in the
* handle where such data might be stored
* *
* Function returns OPAL_SUCCESS if a credential was assigned, or an error * Function returns OPAL_SUCCESS if a credential was assigned, or an error
* code indicating why it failed * code indicating why it failed
*/ */
typedef int (*opal_sec_base_module_get_my_cred_fn_t)(opal_identifier_t *my_id, typedef int (*opal_sec_base_module_get_my_cred_fn_t)(int dstorehandle,
opal_identifier_t *my_id,
opal_sec_cred_t **cred); opal_sec_cred_t **cred);
/* /*

33
orte/mca/db/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,33 @@
#
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2014 Intel, Inc. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
AM_CPPFLAGS = $(LTDLINCL)
# main library setup
noinst_LTLIBRARIES = libmca_db.la
libmca_db_la_SOURCES =
# pkgdata setup
dist_ompidata_DATA =
# local files
headers = db.h
libmca_db_la_SOURCES += $(headers)
# Conditionally install the header files
if WANT_INSTALL_HEADERS
ortedir = $(ompiincludedir)/$(subdir)
nobase_orte_HEADERS = $(headers)
endif
include base/Makefile.am
distclean-local:
rm -f base/static-components.h

Просмотреть файл

@ -1,6 +1,7 @@
# #
# Copyright (c) 2010-2014 Cisco Systems, Inc. All rights reserved. # Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved. # Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
# Copyright (c) 2014 Intel, Inc. All rights reserved.
# $COPYRIGHT$ # $COPYRIGHT$
# #
# Additional copyrights may follow # Additional copyrights may follow
@ -14,4 +15,4 @@ headers += \
libmca_db_la_SOURCES += \ libmca_db_la_SOURCES += \
base/db_base_frame.c \ base/db_base_frame.c \
base/db_base_select.c \ base/db_base_select.c \
base/db_base_fns.c base/db_base_stubs.c

101
orte/mca/db/base/base.h Обычный файл
Просмотреть файл

@ -0,0 +1,101 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/** @file:
*/
#ifndef MCA_DB_BASE_H
#define MCA_DB_BASE_H
#include "orte_config.h"
#include "orte/types.h"
#include "opal/mca/mca.h"
#include "opal/mca/base/mca_base_framework.h"
#include "opal/mca/event/event.h"
#include "opal/class/opal_list.h"
#include "opal/class/opal_pointer_array.h"
#include "opal/dss/dss.h"
#include "orte/mca/db/db.h"
BEGIN_C_DECLS
ORTE_DECLSPEC extern mca_base_framework_t orte_db_base_framework;
/**
* Select db modules for the specified handle
*/
ORTE_DECLSPEC int orte_db_base_select(void);
typedef struct {
opal_list_t actives;
opal_pointer_array_t handles;
opal_event_base_t *ev_base;
} orte_db_base_t;
typedef struct {
opal_list_item_t super;
orte_db_base_component_t *component;
} orte_db_base_active_component_t;
OBJ_CLASS_DECLARATION(orte_db_base_active_component_t);
typedef struct {
opal_object_t super;
opal_event_t ev;
int dbhandle;
orte_db_callback_fn_t cbfunc;
void *cbdata;
opal_list_t *properties;
char *primary_key;
char *key;
opal_list_t *kvs;
} orte_db_request_t;
OBJ_CLASS_DECLARATION(orte_db_request_t);
typedef struct {
opal_object_t super;
orte_db_base_component_t *component;
orte_db_base_module_t *module;
} orte_db_handle_t;
OBJ_CLASS_DECLARATION(orte_db_handle_t);
ORTE_DECLSPEC extern orte_db_base_t orte_db_base;
ORTE_DECLSPEC void orte_db_base_open(char *name,
opal_list_t *properties,
orte_db_callback_fn_t cbfunc,
void *cbdata);
ORTE_DECLSPEC void orte_db_base_close(int dbhandle,
orte_db_callback_fn_t cbfunc,
void *cbdata);
ORTE_DECLSPEC void orte_db_base_store(int dbhandle,
const char *primary_key,
opal_list_t *kvs,
orte_db_callback_fn_t cbfunc,
void *cbdata);
ORTE_DECLSPEC void orte_db_base_commit(int dbhandle,
orte_db_callback_fn_t cbfunc,
void *cbdata);
ORTE_DECLSPEC void orte_db_base_fetch(int dbhandle,
const char *primary_key,
const char *key,
opal_list_t *kvs,
orte_db_callback_fn_t cbfunc,
void *cbdata);
ORTE_DECLSPEC void orte_db_base_remove_data(int dbhandle,
const char *primary_key,
const char *key,
orte_db_callback_fn_t cbfunc,
void *cbdata);
END_C_DECLS
#endif

126
orte/mca/db/base/db_base_frame.c Обычный файл
Просмотреть файл

@ -0,0 +1,126 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "orte_config.h"
#include "orte/constants.h"
#include "opal/mca/mca.h"
#include "opal/util/output.h"
#include "opal/mca/base/base.h"
#include "opal/dss/dss_types.h"
#include "orte/runtime/orte_globals.h"
#include "orte/mca/db/base/base.h"
/*
* The following file was created by configure. It contains extern
* dbments and the definition of an array of pointers to each
* module's public mca_base_module_t struct.
*/
#include "orte/mca/db/base/static-components.h"
orte_db_API_module_t orte_db = {
orte_db_base_open,
orte_db_base_close,
orte_db_base_store,
orte_db_base_commit,
orte_db_base_fetch,
orte_db_base_remove_data
};
orte_db_base_t orte_db_base;
static bool orte_db_base_create_evbase;
static int orte_db_base_register(mca_base_register_flag_t flags)
{
orte_db_base_create_evbase = false;
mca_base_var_register("orte", "db", "base", "create_evbase",
"Create a separate event base for processing db operations",
MCA_BASE_VAR_TYPE_BOOL, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&orte_db_base_create_evbase);
return OPAL_SUCCESS;
}
static int orte_db_base_frame_close(void)
{
orte_db_base_component_t *component;
int i;
orte_db_handle_t *hdl;
/* cleanup the globals */
for (i=0; i < orte_db_base.handles.size; i++) {
if (NULL != (hdl = (orte_db_handle_t*)opal_pointer_array_get_item(&orte_db_base.handles, i))) {
OBJ_RELEASE(hdl);
}
}
OBJ_DESTRUCT(&orte_db_base.handles);
/* cycle across all the active db components and let them cleanup - order
* doesn't matter in this case
*/
while (NULL != (component = (orte_db_base_component_t*)opal_list_remove_first(&orte_db_base.actives))) {
if (NULL != component->finalize) {
component->finalize();
}
}
OBJ_DESTRUCT(&orte_db_base.actives);
return mca_base_framework_components_close(&orte_db_base_framework, NULL);
}
static int orte_db_base_frame_open(mca_base_open_flag_t flags)
{
OBJ_CONSTRUCT(&orte_db_base.actives, opal_list_t);
OBJ_CONSTRUCT(&orte_db_base.handles, opal_pointer_array_t);
opal_pointer_array_init(&orte_db_base.handles, 3, INT_MAX, 1);
if (orte_db_base_create_evbase) {
/* create our own event base */
/* spin off a progress thread for it */
} else {
/* tie us to the orte_event_base */
orte_db_base.ev_base = orte_event_base;
}
/* Open up all available components */
return mca_base_framework_components_open(&orte_db_base_framework, flags);
}
MCA_BASE_FRAMEWORK_DECLARE(orte, db, "ORTE Database Framework",
orte_db_base_register,
orte_db_base_frame_open,
orte_db_base_frame_close,
mca_db_base_static_components, 0);
static void req_con(orte_db_request_t *p)
{
p->properties = NULL;
p->primary_key = NULL;
p->key = NULL;
p->kvs = NULL;
}
OBJ_CLASS_INSTANCE(orte_db_request_t,
opal_object_t,
req_con, NULL);
OBJ_CLASS_INSTANCE(orte_db_handle_t,
opal_object_t,
NULL, NULL);
OBJ_CLASS_INSTANCE(orte_db_base_active_component_t,
opal_list_item_t,
NULL, NULL);

103
orte/mca/db/base/db_base_select.c Обычный файл
Просмотреть файл

@ -0,0 +1,103 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "orte_config.h"
#include "orte/constants.h"
#include "opal/class/opal_list.h"
#include "opal/mca/mca.h"
#include "opal/mca/base/base.h"
#include "opal/mca/base/mca_base_component_repository.h"
#include "opal/util/output.h"
#include "orte/mca/db/base/base.h"
static bool selected = false;
int orte_db_base_select(void)
{
mca_base_component_list_item_t *cli;
orte_db_base_component_t *component;
orte_db_base_active_component_t *active, *ncomponent;
bool inserted;
if (selected) {
/* ensure we don't do this twice */
return OPAL_SUCCESS;
}
selected = true;
/* Query all available components and ask if they have a module */
OPAL_LIST_FOREACH(cli, &orte_db_base_framework.framework_components, mca_base_component_list_item_t) {
component = (orte_db_base_component_t*)cli->cli_component;
opal_output_verbose(5, orte_db_base_framework.framework_output,
"mca:db:select: checking available component %s",
component->base_version.mca_component_name);
/* If there's no query function, skip it */
if (NULL == component->available) {
opal_output_verbose(5, orte_db_base_framework.framework_output,
"mca:db:select: Skipping component [%s]. It does not implement a query function",
component->base_version.mca_component_name );
continue;
}
/* Query the component */
opal_output_verbose(5, orte_db_base_framework.framework_output,
"mca:db:select: Querying component [%s]",
component->base_version.mca_component_name);
/* If the component is not available, then skip it as
* it has no available interfaces
*/
if (!component->available()) {
opal_output_verbose(5, orte_db_base_framework.framework_output,
"mca:db:select: Skipping component [%s] - not available",
component->base_version.mca_component_name );
continue;
}
/* maintain priority order */
inserted = false;
ncomponent = OBJ_NEW(orte_db_base_active_component_t);
ncomponent->component = component;
OPAL_LIST_FOREACH(active, &orte_db_base.actives, orte_db_base_active_component_t) {
if (component->priority > active->component->priority) {
opal_list_insert_pos(&orte_db_base.actives,
&active->super, &ncomponent->super);
inserted = true;
break;
}
}
if (!inserted) {
/* must be lowest priority - add to end */
opal_list_append(&orte_db_base.actives, &ncomponent->super);
}
}
/* if no components are available, that is an error */
if (0 == opal_list_get_size(&orte_db_base.actives)) {
return ORTE_ERR_NOT_FOUND;
}
if (4 < opal_output_get_verbosity(orte_db_base_framework.framework_output)) {
opal_output(0, "Final db priorities");
/* show the prioritized list */
OPAL_LIST_FOREACH(active, &orte_db_base.actives, orte_db_base_active_component_t) {
opal_output(0, "\tComponent: %s Store Priority: %d",
active->component->base_version.mca_component_name,
active->component->priority);
}
}
return OPAL_SUCCESS;;
}

354
orte/mca/db/base/db_base_stubs.c Обычный файл
Просмотреть файл

@ -0,0 +1,354 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013-2014 Intel Inc. All rights reserved
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "orte_config.h"
#include "orte/constants.h"
#include "opal_stdint.h"
#include "opal/mca/mca.h"
#include "opal/util/error.h"
#include "opal/util/output.h"
#include "opal/mca/base/base.h"
#include "opal/dss/dss_types.h"
#include "orte/mca/db/base/base.h"
static void process_open(int fd, short args, void *cbdata)
{
orte_db_request_t *req = (orte_db_request_t*)cbdata;
orte_db_handle_t *hdl;
orte_db_base_module_t *mod;
orte_db_base_component_t *component;
int i, index;
char **cmps = NULL;
opal_value_t *kv;
bool found;
/* see if the caller provided the magic "components" property */
if (NULL != req->properties) {
OPAL_LIST_FOREACH(kv, req->properties, opal_value_t) {
if (0 == strcmp(kv->key, "components")) {
cmps = opal_argv_split(kv->data.string, ',');
}
}
}
/* cycle thru the available components until one saids
* it can create a handle for these properties
*/
OPAL_LIST_FOREACH(component, &orte_db_base.actives, orte_db_base_component_t) {
found = true;
if (NULL != cmps) {
found = false;
for (i=0; NULL != cmps[i]; i++) {
if (0 == strcmp(cmps[i], component->base_version.mca_component_name)) {
found = true;
break;
}
}
}
if (found) {
/* let this component try */
if (NULL != (mod = component->create_handle(req->properties))) {
/* create the handle */
hdl = OBJ_NEW(orte_db_handle_t);
hdl->component = component;
hdl->module = mod;
index = opal_pointer_array_add(&orte_db_base.handles, hdl);
if (NULL != req->cbfunc) {
req->cbfunc(index, OPAL_SUCCESS, NULL, req->cbdata);
}
OBJ_RELEASE(req);
return;
}
}
}
/* if we get here, we were unable to create the handle */
if (NULL != req->cbfunc) {
req->cbfunc(-1, ORTE_ERROR, NULL, req->cbdata);
}
OBJ_RELEASE(req);
}
void orte_db_base_open(char *name,
opal_list_t *properties,
orte_db_callback_fn_t cbfunc,
void *cbdata)
{
orte_db_request_t *req;
/* push this request into our event_base
* for processing to ensure nobody else is
* using that dbhandle
*/
req = OBJ_NEW(orte_db_request_t);
/* transfer the name in the primary key */
req->primary_key = name;
req->properties = properties;
req->cbfunc = cbfunc;
req->cbdata = cbdata;
opal_event_set(orte_db_base.ev_base, &req->ev, -1,
OPAL_EV_WRITE,
process_open, req);
opal_event_set_priority(&req->ev, OPAL_EV_SYS_HI_PRI);
opal_event_active(&req->ev, OPAL_EV_WRITE, 1);
}
static void process_close(int fd, short args, void *cbdata)
{
orte_db_request_t *req = (orte_db_request_t*)cbdata;
orte_db_handle_t *hdl;
int rc;
/* get the handle object */
if (NULL == (hdl = (orte_db_handle_t*)opal_pointer_array_get_item(&orte_db_base.handles, req->dbhandle))) {
rc = ORTE_ERR_NOT_FOUND;
goto found;
}
if (NULL == hdl->module) {
rc = ORTE_ERR_NOT_FOUND;
goto found;
}
if (NULL != hdl->module->finalize) {
hdl->module->finalize((struct orte_db_base_module_t*)hdl->module);
rc = ORTE_SUCCESS;
}
found:
if (NULL != req->cbfunc) {
req->cbfunc(req->dbhandle, rc, NULL, req->cbdata);
}
/* release the handle */
opal_pointer_array_set_item(&orte_db_base.handles, req->dbhandle, NULL);
OBJ_RELEASE(hdl);
OBJ_RELEASE(req);
}
void orte_db_base_close(int dbhandle,
orte_db_callback_fn_t cbfunc,
void *cbdata)
{
orte_db_request_t *req;
/* push this request into our event_base
* for processing to ensure nobody else is
* using that dbhandle
*/
req = OBJ_NEW(orte_db_request_t);
req->dbhandle = dbhandle;
req->cbfunc = cbfunc;
req->cbdata = cbdata;
opal_event_set(orte_db_base.ev_base, &req->ev, -1,
OPAL_EV_WRITE,
process_close, req);
opal_event_set_priority(&req->ev, OPAL_EV_SYS_HI_PRI);
opal_event_active(&req->ev, OPAL_EV_WRITE, 1);
}
static void process_store(int fd, short args, void *cbdata)
{
orte_db_request_t *req = (orte_db_request_t*)cbdata;
orte_db_handle_t *hdl;
int rc;
/* get the handle object */
if (NULL == (hdl = (orte_db_handle_t*)opal_pointer_array_get_item(&orte_db_base.handles, req->dbhandle))) {
rc = ORTE_ERR_NOT_FOUND;
goto found;
}
if (NULL == hdl->module) {
rc = ORTE_ERR_NOT_FOUND;
goto found;
}
if (NULL != hdl->module->store) {
rc = hdl->module->store((struct orte_db_base_module_t*)hdl->module, req->primary_key, req->kvs);
}
found:
if (NULL != req->cbfunc) {
req->cbfunc(req->dbhandle, rc, req->kvs, req->cbdata);
}
OBJ_RELEASE(req);
}
void orte_db_base_store(int dbhandle,
const char *primary_key,
opal_list_t *kvs,
orte_db_callback_fn_t cbfunc,
void *cbdata)
{
orte_db_request_t *req;
/* push this request into our event_base
* for processing to ensure nobody else is
* using that dbhandle
*/
req = OBJ_NEW(orte_db_request_t);
req->dbhandle = dbhandle;
req->primary_key = (char*)primary_key;
req->kvs = kvs;
req->cbfunc = cbfunc;
req->cbdata = cbdata;
opal_event_set(orte_db_base.ev_base, &req->ev, -1,
OPAL_EV_WRITE,
process_store, req);
opal_event_set_priority(&req->ev, OPAL_EV_SYS_HI_PRI);
opal_event_active(&req->ev, OPAL_EV_WRITE, 1);
}
static void process_commit(int fd, short args, void *cbdata)
{
orte_db_request_t *req = (orte_db_request_t*)cbdata;
orte_db_handle_t *hdl;
int rc;
/* get the handle object */
if (NULL == (hdl = (orte_db_handle_t*)opal_pointer_array_get_item(&orte_db_base.handles, req->dbhandle))) {
rc = ORTE_ERR_NOT_FOUND;
goto found;
}
if (NULL == hdl->module) {
rc = ORTE_ERR_NOT_FOUND;
goto found;
}
if (NULL != hdl->module->commit) {
hdl->module->commit((struct orte_db_base_module_t*)hdl->module);
rc = ORTE_SUCCESS;
}
found:
if (NULL != req->cbfunc) {
req->cbfunc(req->dbhandle, rc, NULL, req->cbdata);
}
OBJ_RELEASE(req);
}
void orte_db_base_commit(int dbhandle,
orte_db_callback_fn_t cbfunc,
void *cbdata)
{
orte_db_request_t *req;
/* push this request into our event_base
* for processing to ensure nobody else is
* using that dbhandle
*/
req = OBJ_NEW(orte_db_request_t);
req->dbhandle = dbhandle;
req->cbfunc = cbfunc;
req->cbdata = cbdata;
opal_event_set(orte_db_base.ev_base, &req->ev, -1,
OPAL_EV_WRITE,
process_commit, req);
opal_event_set_priority(&req->ev, OPAL_EV_SYS_HI_PRI);
opal_event_active(&req->ev, OPAL_EV_WRITE, 1);
}
static void process_fetch(int fd, short args, void *cbdata)
{
orte_db_request_t *req = (orte_db_request_t*)cbdata;
orte_db_handle_t *hdl;
int rc;
/* get the handle object */
if (NULL == (hdl = (orte_db_handle_t*)opal_pointer_array_get_item(&orte_db_base.handles, req->dbhandle))) {
rc = ORTE_ERR_NOT_FOUND;
goto found;
}
if (NULL == hdl->module) {
rc = ORTE_ERR_NOT_FOUND;
goto found;
}
rc = hdl->module->fetch((struct orte_db_base_module_t*)hdl->module, req->primary_key, req->key, req->kvs);
found:
if (NULL != req->cbfunc) {
req->cbfunc(req->dbhandle, rc, req->kvs, req->cbdata);
}
OBJ_RELEASE(req);
}
void orte_db_base_fetch(int dbhandle,
const char *primary_key,
const char *key,
opal_list_t *kvs,
orte_db_callback_fn_t cbfunc,
void *cbdata)
{
orte_db_request_t *req;
/* push this request into our event_base
* for processing to ensure nobody else is
* using that dbhandle
*/
req = OBJ_NEW(orte_db_request_t);
req->dbhandle = dbhandle;
req->primary_key = (char*)primary_key;
req->key = (char*)key;
req->kvs = kvs;
req->cbfunc = cbfunc;
req->cbdata = cbdata;
opal_event_set(orte_db_base.ev_base, &req->ev, -1,
OPAL_EV_WRITE,
process_fetch, req);
opal_event_set_priority(&req->ev, OPAL_EV_SYS_HI_PRI);
opal_event_active(&req->ev, OPAL_EV_WRITE, 1);
}
static void process_remove(int fd, short args, void *cbdata)
{
orte_db_request_t *req = (orte_db_request_t*)cbdata;
orte_db_handle_t *hdl;
int rc;
/* get the handle object */
if (NULL == (hdl = (orte_db_handle_t*)opal_pointer_array_get_item(&orte_db_base.handles, req->dbhandle))) {
rc = ORTE_ERR_NOT_FOUND;
goto found;
}
if (NULL == hdl->module) {
rc = ORTE_ERR_NOT_FOUND;
goto found;
}
rc = hdl->module->remove((struct orte_db_base_module_t*)hdl->module, req->primary_key, req->key);
found:
if (NULL != req->cbfunc) {
req->cbfunc(req->dbhandle, rc, NULL, req->cbdata);
}
OBJ_RELEASE(req);
}
void orte_db_base_remove_data(int dbhandle,
const char *primary_key,
const char *key,
orte_db_callback_fn_t cbfunc,
void *cbdata)
{
orte_db_request_t *req;
/* push this request into our event_base
* for processing to ensure nobody else is
* using that dbhandle
*/
req = OBJ_NEW(orte_db_request_t);
req->dbhandle = dbhandle;
req->primary_key = (char*)primary_key;
req->key = (char*)key;
req->cbfunc = cbfunc;
req->cbdata = cbdata;
opal_event_set(orte_db_base.ev_base, &req->ev, -1,
OPAL_EV_WRITE,
process_remove, req);
opal_event_set_priority(&req->ev, OPAL_EV_SYS_HI_PRI);
opal_event_active(&req->ev, OPAL_EV_WRITE, 1);
}

210
orte/mca/db/db.h Обычный файл
Просмотреть файл

@ -0,0 +1,210 @@
/*
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/** @file:
*
* The Database Framework
*
*/
#ifndef ORTE_DB_H
#define ORTE_DB_H
#include "orte_config.h"
#include "orte/types.h"
#include "opal/mca/mca.h"
#include "opal/mca/event/event.h"
#include "opal/dss/dss_types.h"
/**
* DATABASE DESIGN
*
* DB APIs are non-blocking and executed by pushing the request onto the ORTE
* event base. Upon completion, the provided cbfunc will be called to return
* the status resulting from the operation (a NULL cbfunc is permitted). The
* cbfunc is responsible for releasing the returned list
*/
BEGIN_C_DECLS
/* forward declare */
struct orte_db_base_module_t;
/* callback function for async requests */
typedef void (*orte_db_callback_fn_t)(int dbhandle, int status,
opal_list_t *kvs, void *cbdata);
/*
* Initialize the module
*/
typedef int (*orte_db_base_module_init_fn_t)(struct orte_db_base_module_t *imod);
/*
* Finalize the module
*/
typedef void (*orte_db_base_module_finalize_fn_t)(struct orte_db_base_module_t *imod);
/*
* Open a database
*
* Open a database for access (read, write, etc.). The request
* can contain a user-specified name for this database that
* has nothing to do with the backend database - it is solely
* for use as a debug tool to help identify the database. The
* request can also optionally provide a list of opal_value_t
* properties - this is where one might specify the name of
* the backend database, a URI for contacting it, the name of
* a particular table for request, etc. Thus, it is important
* to note that the returned "handle" is associated solely with
* the defined request - i.e., if the properties specify a database
* and table, then the handle will be specific to that combination.
*
* NOTE: one special "property" allows you to specify the
* name(s) of the component(s) you want considered for this
* handle - i.e., the equivalent of specifying the MCA param
* "db=list" - using the reserved property name "components".
* The components will be queried in the order specified. The ^
* character is also supported, with the remaining components
* considered in priority order
*
* Just like the standard POSIX file open, the call will return
* a unique "handle" that must be provided with any subsequent
* call to store or fetch data from this database.
*/
typedef void (*orte_db_base_API_open_fn_t)(char *name,
opal_list_t *properties,
orte_db_callback_fn_t cbfunc,
void *cbdata);
/*
* Close a database handle
*
* Close the specified database handle. This may or may not invoke
* termination of a connection to a remote database or release of
* memory storage, depending on the precise implementation of the
* active database components. A -1 handle indicates that ALL open
* database handles are to be closed.
*/
typedef void (*orte_db_base_API_close_fn_t)(int dbhandle,
orte_db_callback_fn_t cbfunc,
void *cbdata);
/*
* Store one or more data elements against the primary key - overwrites any data
* of matching key that is already present. The data is copied into the database
* and therefore does not need to be preserved by the caller.
*/
typedef void (*orte_db_base_API_store_fn_t)(int dbhandle,
const char *primary_key,
opal_list_t *kvs,
orte_db_callback_fn_t cbfunc,
void *cbdata);
typedef int (*orte_db_base_module_store_fn_t)(struct orte_db_base_module_t *imod,
const char *primary_key,
opal_list_t *kvs);
/*
* Commit data to the database - action depends on implementation within
* each active component
*/
typedef void (*orte_db_base_API_commit_fn_t)(int dbhandle,
orte_db_callback_fn_t cbfunc,
void *cbdata);
typedef void (*orte_db_base_module_commit_fn_t)(struct orte_db_base_module_t *imod);
/*
* Retrieve data
*
* Retrieve data for the given primary key associated with the specified key. Wildcards
* are supported here as well. Caller is responsible for releasing the returned list
* of opal_keyval_t objects.
*/
typedef void (*orte_db_base_API_fetch_fn_t)(int dbhandle,
const char *primary_key,
const char *key,
opal_list_t *kvs,
orte_db_callback_fn_t cbfunc,
void *cbdata);
typedef int (*orte_db_base_module_fetch_fn_t)(struct orte_db_base_module_t *imod,
const char *primary_key,
const char *key,
opal_list_t *kvs);
/*
* Delete data
*
* Delete the data for the given primary key that is associated with the specified key.
* If a NULL key is provided, all data for the given primary key will be deleted.
*/
typedef void (*orte_db_base_API_remove_fn_t)(int dbhandle,
const char *primary_key,
const char *key,
orte_db_callback_fn_t cbfunc,
void *cbdata);
typedef int (*orte_db_base_module_remove_fn_t)(struct orte_db_base_module_t *imod,
const char *primary_key,
const char *key);
/*
* the standard module data structure
*/
typedef struct {
orte_db_base_module_init_fn_t init;
orte_db_base_module_finalize_fn_t finalize;
orte_db_base_module_store_fn_t store;
orte_db_base_module_commit_fn_t commit;
orte_db_base_module_fetch_fn_t fetch;
orte_db_base_module_remove_fn_t remove;
} orte_db_base_module_t;
typedef struct {
orte_db_base_API_open_fn_t open;
orte_db_base_API_close_fn_t close;
orte_db_base_API_store_fn_t store;
orte_db_base_API_commit_fn_t commit;
orte_db_base_API_fetch_fn_t fetch;
orte_db_base_API_remove_fn_t remove;
} orte_db_API_module_t;
/* function to determine if this component is available for use.
* Note that we do not use the standard component open
* function as we do not want/need return of a module.
*/
typedef bool (*mca_db_base_component_avail_fn_t)(void);
/* create and return a database module */
typedef orte_db_base_module_t* (*mca_db_base_component_create_hdl_fn_t)(opal_list_t *props);
/* provide a chance for the component to finalize */
typedef void (*mca_db_base_component_finalize_fn_t)(void);
typedef struct {
mca_base_component_t base_version;
mca_base_component_data_t base_data;
int priority;
mca_db_base_component_avail_fn_t available;
mca_db_base_component_create_hdl_fn_t create_handle;
mca_db_base_component_finalize_fn_t finalize;
} orte_db_base_component_t;
/*
* Macro for use in components that are of type db
*/
#define ORTE_DB_BASE_VERSION_2_0_0 \
MCA_BASE_VERSION_2_0_0, \
"db", 2, 0, 0
/* Global structure for accessing DB functions */
ORTE_DECLSPEC extern orte_db_API_module_t orte_db; /* holds API function pointers */
END_C_DECLS
#endif

Просмотреть файл

@ -16,7 +16,7 @@ sources = \
# mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la # mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la
# (for static builds). # (for static builds).
if MCA_BUILD_opal_db_postgres_DSO if MCA_BUILD_orte_db_postgres_DSO
component_noinst = component_noinst =
component_install = mca_db_postgres.la component_install = mca_db_postgres.la
else else

Просмотреть файл

@ -1,7 +1,7 @@
dnl -*- shell-script -*- dnl -*- shell-script -*-
dnl dnl
dnl Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved. dnl Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
dnl Copyright (c) 2013 Intel, Inc. All rights reserved. dnl Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
dnl $COPYRIGHT$ dnl $COPYRIGHT$
dnl dnl
dnl Additional copyrights may follow dnl Additional copyrights may follow
@ -11,31 +11,31 @@ dnl
# MCA_db_postgres_CONFIG([action-if-found], [action-if-not-found]) # MCA_db_postgres_CONFIG([action-if-found], [action-if-not-found])
# ----------------------------------------------------------- # -----------------------------------------------------------
AC_DEFUN([MCA_opal_db_postgres_CONFIG], [ AC_DEFUN([MCA_orte_db_postgres_CONFIG], [
AC_CONFIG_FILES([opal/mca/db/postgres/Makefile]) AC_CONFIG_FILES([orte/mca/db/postgres/Makefile])
AC_REQUIRE([OPAL_CHECK_POSTGRES]) AC_REQUIRE([OPAL_CHECK_POSTGRES])
# do not build if support not requested # do not build if support not requested
AS_IF([test "$opal_check_postgres_happy" == "yes"], AS_IF([test "$orte_check_postgres_happy" == "yes"],
[opal_db_postgres_check_save_CPPFLAGS=$CPPFLAGS [orte_db_postgres_check_save_CPPFLAGS=$CPPFLAGS
opal_db_postgres_check_save_LDFLAGS=$LDFLAGS orte_db_postgres_check_save_LDFLAGS=$LDFLAGS
opal_db_postgres_check_save_LIBS=$LIBS orte_db_postgres_check_save_LIBS=$LIBS
OMPI_CHECK_PACKAGE([db_postgres], OMPI_CHECK_PACKAGE([db_postgres],
[libpq-fe.h], [libpq-fe.h],
[pq], [pq],
[PQconnectdb], [PQconnectdb],
[], [],
[$opal_postgres_incdir], [$orte_postgres_incdir],
[], [],
[$1], [$1],
[AC_MSG_WARN([Postgres database support requested]) [AC_MSG_WARN([Postgres database support requested])
AC_MSG_WARN([but required library or header not found]) AC_MSG_WARN([but required library or header not found])
AC_MSG_ERROR([Cannot continue]) AC_MSG_ERROR([Cannot continue])
$2]) $2])
CPPFLAGS=$opal_db_postgres_check_save_CPPFLAGS CPPFLAGS=$orte_db_postgres_check_save_CPPFLAGS
LDFLAGS=$opal_db_postgres_check_save_LDFLAGS LDFLAGS=$orte_db_postgres_check_save_LDFLAGS
LIBS=$opal_db_postgres_check_save_LIBS], LIBS=$orte_db_postgres_check_save_LIBS],
[$2]) [$2])
AC_SUBST(db_postgres_CPPFLAGS) AC_SUBST(db_postgres_CPPFLAGS)

254
orte/mca/db/postgres/db_postgres.c Обычный файл
Просмотреть файл

@ -0,0 +1,254 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#include "orte_config.h"
#include "orte/constants.h"
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#include <stdio.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "libpq-fe.h"
#include "opal_stdint.h"
#include "opal/util/argv.h"
#include "opal/util/error.h"
#include "orte/mca/db/base/base.h"
#include "db_postgres.h"
#define ORTE_PG_MAX_LINE_LENGTH 4096
static int init(struct orte_db_base_module_t *imod);
static void finalize(struct orte_db_base_module_t *imod);
static int store(struct orte_db_base_module_t *imod,
const char *primary_key,
opal_list_t *kvs);
mca_db_postgres_module_t mca_db_postgres_module = {
{
init,
finalize,
store,
NULL,
NULL,
NULL
},
};
static int init(struct orte_db_base_module_t *imod)
{
mca_db_postgres_module_t *mod = (mca_db_postgres_module_t*)imod;
char **login=NULL;
char **connection=NULL;
/* break the user info into its login parts */
login = opal_argv_split(mod->user, ':');
if (2 != opal_argv_count(login)) {
opal_output(0, "db:postgres: User info is invalid: %s",
mod->user);
opal_argv_free(login);
return ORTE_ERR_BAD_PARAM;
}
/* break the uri */
connection = opal_argv_split(mod->pguri, ':');
if (2 != opal_argv_count(connection)) {
opal_argv_free(login);
opal_argv_free(connection);
opal_output(0, "db:postgres: Connection info is invalid: %s",
mod->pguri);
return ORTE_ERR_BAD_PARAM;
}
conn = PQsetdbLogin(connection[0], connection[1],
mod->pgoptions,
mod->pgtty,
mod->dbname,
login[0], login[1]);
opal_argv_free(login);
opal_argv_free(connection);
if (PQstatus(conn) != CONNECTION_OK) {
conn = NULL;
opal_output(0, "***********************************************\n");
opal_output(0, "db:postgres: Connection failed:\n\tURI: %s\n\tOPTIONS: %s\n\tTTY: %s\n\tDBNAME: %s\n\tUSER: %s",
mod->pguri,
(NULL == mod->pgoptions) ? "NULL" : mod->pgoptions,
(NULL == mod->pgtty) ? "NULL" : mod->pgtty,
mod->dbname,
mod->user);
opal_output(0, "\n***********************************************");
exit(ORTE_ERR_CONNECTION_FAILED);
return ORTE_ERR_CONNECTION_FAILED;
}
opal_output_verbose(5, orte_db_base_framework.framework_output,
"db:postgres: Connection established to %s",
mod->dbname);
return ORTE_SUCCESS;
}
static void finalize(struct orte_db_base_module_t *imod)
{
mca_db_postgres_module_t *mod = (mca_db_postgres_module_t*)imod;
if (NULL != mod->dbname) {
free(mod->dbname);
}
if (NULL != mod->table) {
free(mod->table);
}
if (NULL != mod->user) {
free(mod->user);
}
if (NULL != mod->pguri) {
free(mod->pguri);
}
if (NULL != mod->pgoptions) {
free(mod->pgoptions);
}
if (NULL != mod->pgtty) {
free(mod->pgtty);
}
if (NULL != mod->conn) {
PQfinish(mod->conn);
}
}
static int store(struct orte_db_base_module_t *imod,
const char *primary_key,
opal_list_t *kvs)
{
mca_db_postgres_module_t *mod = (mca_db_postgres_module_t*)imod;
char *query, *vstr;
PGresult *res;
char **cmdargs=NULL;
time_t nowtime;
struct tm *nowtm;
char tbuf[1024], buf[64];
int i;
opal_value_t *kv;
/* cycle through the provided values and construct
* an insert command for them - note that the values
* MUST be in column-order for the database!
*/
OPAL_LIST_FOREACH(kv, kvs, opal_value_t) {
switch (kv->type) {
case OPAL_STRING:
snprintf(tbuf, sizeof(tbuf), "%s", kv->data.string);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_SIZE:
snprintf(tbuf, sizeof(tbuf), "%" PRIsize_t "", kv->data.size);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT:
snprintf(tbuf, sizeof(tbuf), "%d", kv->data.integer);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT8:
snprintf(tbuf, sizeof(tbuf), "%" PRIi8 "", kv->data.int8);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT16:
snprintf(tbuf, sizeof(tbuf), "%" PRIi16 "", kv->data.int16);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT32:
snprintf(tbuf, sizeof(tbuf), "%" PRIi32 "", kv->data.int32);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT64:
snprintf(tbuf, sizeof(tbuf), "%" PRIi64 "", kv->data.int64);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT:
snprintf(tbuf, sizeof(tbuf), "%u", kv->data.uint);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT8:
snprintf(tbuf, sizeof(tbuf), "%" PRIu8 "", kv->data.uint8);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT16:
snprintf(tbuf, sizeof(tbuf), "%" PRIu16 "", kv->data.uint16);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT32:
snprintf(tbuf, sizeof(tbuf), "%" PRIu32 "", kv->data.uint32);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT64:
snprintf(tbuf, sizeof(tbuf), "%" PRIu64 "", kv->data.uint64);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_PID:
snprintf(tbuf, sizeof(tbuf), "%lu", (unsigned long)kv->data.pid);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_FLOAT:
snprintf(tbuf, sizeof(tbuf), "%f", kv->data.fval);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_TIMEVAL:
/* we only care about seconds */
nowtime = kv->data.tv.tv_sec;
(void)localtime_r(&nowtime, &nowtm);
strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", &nowtm);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
default:
snprintf(tbuf, sizeof(tbuf), "Unsupported type: %s",
opal_dss.lookup_data_type(kv->type));
opal_argv_append_nosize(&cmdargs, tbuf);
break;
}
}
/* assemble the value string */
vstr = opal_argv_join(cmdargs, ',');
opal_argv_free(cmdargs);
/* create the query */
asprintf(&query, "INSERT INTO %s values (%s)", mod->table, vstr);
free(vstr);
opal_output_verbose(2, orte_db_base_framework.framework_output,
"Executing query %s", query);
/* execute it */
res = PQexec(conn, query);
free(query);
if ((!res) || (PQresultStatus(res) != PGRES_COMMAND_OK)) {
opal_output(0, "***********************************************\n");
opal_output(0, "POSTGRES INSERT COMMAND FAILED - UNABLE TO LOG");
opal_output(0, "DATA. ABORTING");
opal_output(0, "\n***********************************************");
PQclear(res);
return ORTE_ERROR;
}
opal_output_verbose(2, orte_db_base_framework.framework_output,
"Query succeeded");
PQclear(res);
return OPAL_SUCCESS;
}

37
orte/mca/db/postgres/db_postgres.h Обычный файл
Просмотреть файл

@ -0,0 +1,37 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef ORTE_DB_POSTGRES_H
#define ORTE_DB_POSTGRES_H
#include "libpq-fe.h"
#include "orte/mca/db/db.h"
BEGIN_C_DECLS
ORTE_MODULE_DECLSPEC extern orte_db_base_component_t mca_db_postgres_component;
typedef struct {
orte_db_base_module_t api;
int num_worker_threads;
char *dbname;
char *table;
char *user;
char *pguri;
char *pgoptions;
char *pgtty;
PGconn *conn;
} mca_db_postgres_module_t;
ORTE_MODULE_DECLSPEC extern mca_db_postgres_module_t mca_db_postgres_module;
END_C_DECLS
#endif /* ORTE_DB_POSTGRES_H */

213
orte/mca/db/postgres/db_postgres_component.c Обычный файл
Просмотреть файл

@ -0,0 +1,213 @@
/*
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
* These symbols are in a file by themselves to provide nice linker
* semantics. Since linkers generally pull in symbols by object
* files, keeping these symbols as the only symbols in this file
* prevents utility programs such as "ompi_info" from having to import
* entire components just to query their version and parameters.
*/
#include "orte_config.h"
#include "orte/constants.h"
#include "opal/mca/base/base.h"
#include "opal/mca/base/mca_base_var.h"
#include "orte/mca/errmgr/errmgr.h"
#include "orte/mca/db/db.h"
#include "orte/mca/db/base/base.h"
#include "db_postgres.h"
static int component_register(void);
static bool component_avail(void);
static orte_db_base_module_t *component_create(opal_list_t *props);
/*
* Instantiate the public struct with all of our public information
* and pointers to our public functions in it
*/
orte_db_base_component_t mca_db_postgres_component = {
{
ORTE_DB_BASE_VERSION_2_0_0,
/* Component name and version */
"postgres",
ORTE_MAJOR_VERSION,
ORTE_MINOR_VERSION,
ORTE_RELEASE_VERSION,
/* Component open and close functions */
NULL,
NULL,
NULL,
component_register
},
{
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
75,
component_avail,
component_create,
NULL
};
static int num_worker_threads;
static char *dbname;
static char *table;
static char *user;
static char *pguri;
static char *pgoptions;
static char *pgtty;
static int component_register(void) {
mca_base_component_t *c = &mca_db_postgres_component.base_version;
/* retrieve the name of the database to be used */
dbname = NULL;
(void) mca_base_component_var_register (c, "database", "Name of database",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&dbname);
/* retrieve the name of the table to be used */
table = NULL;
(void) mca_base_component_var_register (c, "table", "Name of table",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&table);
/* retrieve the name of the user to be used */
user = NULL;
(void) mca_base_component_var_register (c, "user", "Name of database user:password",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&user);
/* retrieve the server:port */
pguri = NULL;
(void) mca_base_component_var_register (c, "uri", "Contact info for Postgres server as ip:port",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&pguri);
/* retrieve any options to be used */
pgoptions = NULL;
(void) mca_base_component_var_register (c, "options", "Options to pass to the database",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&pgoptions);
/* retrieve the tty argument */
pgtty = NULL;
(void) mca_base_component_var_register (c, "tty", "TTY option for database",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&pgtty);
/* retrieve the number of worker threads to be used */
num_worker_threads = -1;
(void) mca_base_component_var_register (c, "num_worker_threads",
"Number of worker threads to be used",
MCA_BASE_VAR_TYPE_INT, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&num_worker_threads);
return OPAL_SUCCESS;
}
static bool component_avail(void)
{
/* always available */
return true;
}
static orte_db_base_module_t *component_create(opal_list_t *props)
{
mca_db_postgres_module_t *mod;
opal_value_t *kv;
mod = (mca_db_postgres_module_t*)malloc(sizeof(mca_db_postgres_module_t));
if (NULL == mod) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
return NULL;
}
memset(mod, 0, sizeof(mca_db_postgres_module_t));
mod->num_worker_threads = -1;
/* copy the APIs across */
memcpy(mod, &mca_db_postgres_module.api, sizeof(orte_db_base_module_t));
/* if the props include db info, then use it */
OPAL_LIST_FOREACH(kv, props, opal_value_t) {
if (0 == strcmp(kv->key, "database")) {
mod->dbname = strdup(kv->data.string);
} else if (0 == strcmp(kv->key, "table")) {
mod->table = strdup(kv->data.string);
} else if (0 == strcmp(kv->key, "user")) {
mod->user = strdup(kv->data.string);
} else if (0 == strcmp(kv->key, "uri")) {
mod->pguri = strdup(kv->data.string);
} else if (0 == strcmp(kv->key, "options")) {
mod->pgoptions = strdup(kv->data.string);
} else if (0 == strcmp(kv->key, "tty")) {
mod->pgtty = strdup(kv->data.string);
} else if (0 == strcmp(kv->key, "num_worker_threads")) {
mod->num_worker_threads = kv->data.integer;
}
}
if (NULL == mod->dbname) {
if (NULL == dbname) {
/* nothing was provided - opt out */
free(mod);
return NULL;
}
mod->dbname = strdup(dbname);
}
if (NULL == mod->table) {
if (NULL == table) {
/* nothing was provided - opt out */
free(mod);
return NULL;
}
mod->table = strdup(table);
}
/* all other entries are optional */
if (NULL == mod->user && NULL != user) {
mod->user = strdup(user);
}
if (NULL == mod->pguri && NULL != pguri) {
mod->pguri = strdup(pguri);
}
if (NULL == mod->pgoptions && NULL != pgoptions) {
mod->pgoptions = strdup(pgoptions);
}
if (NULL == mod->pgtty && NULL != pgtty) {
mod->pgtty = strdup(pgtty);
}
if (0 > mod->num_worker_threads && 0 < num_worker_threads) {
mod->num_worker_threads = num_worker_threads;
}
/* let the module init */
if (ORTE_SUCCESS != mod->api.init((struct orte_db_base_module_t*)mod)) {
mod->api.finalize((struct orte_db_base_module_t*)mod);
free(mod);
return NULL;
}
return (orte_db_base_module_t*)mod;
}

Просмотреть файл

@ -16,7 +16,7 @@ sources = \
# mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la # mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la
# (for static builds). # (for static builds).
if MCA_BUILD_opal_db_print_DSO if MCA_BUILD_orte_db_print_DSO
component_noinst = component_noinst =
component_install = mca_db_print.la component_install = mca_db_print.la
else else

175
orte/mca/db/print/db_print.c Обычный файл
Просмотреть файл

@ -0,0 +1,175 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#include "orte_config.h"
#include "orte/constants.h"
#include <time.h>
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#include <stdio.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "opal/class/opal_pointer_array.h"
#include "opal/util/argv.h"
#include "opal/util/output.h"
#include "opal_stdint.h"
#include "orte/mca/db/base/base.h"
#include "db_print.h"
static int init(struct orte_db_base_module_t *imod);
static void finalize(struct orte_db_base_module_t *imod);
static int store(struct orte_db_base_module_t *imod,
const char *primary_key,
opal_list_t *kvs);
mca_db_print_module_t mca_db_print_module = {
{
init,
finalize,
store,
NULL,
NULL,
NULL
},
};
static int init(struct orte_db_base_module_t *imod)
{
mca_db_print_module_t *mod = (mca_db_print_module_t*)imod;
if (0 == strcmp(mod->file, "-")) {
mod->fp = stdout;
} else if (0 == strcmp(mod->file, "+")) {
mod->fp = stderr;
} else if (NULL == (mod->fp = fopen(mod->file, "w"))) {
opal_output(0, "ERROR: cannot open log file %s", mod->file);
return ORTE_ERROR;
}
return ORTE_SUCCESS;
}
static void finalize(struct orte_db_base_module_t *imod)
{
mca_db_print_module_t *mod = (mca_db_print_module_t*)imod;
if (NULL != mod->fp &&
stdout != mod->fp &&
stderr != mod->fp) {
fclose(mod->fp);
}
}
static int store(struct orte_db_base_module_t *imod,
const char *primary_key,
opal_list_t *kvs)
{
mca_db_print_module_t *mod = (mca_db_print_module_t*)imod;
char **cmdargs=NULL, *vstr;
time_t nowtime;
struct tm nowtm;
char tbuf[1024];
opal_value_t *kv;
/* cycle through the provided values and print them */
OPAL_LIST_FOREACH(kv, kvs, opal_value_t) {
switch (kv->type) {
case OPAL_STRING:
snprintf(tbuf, sizeof(tbuf), "%s", kv->data.string);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_SIZE:
snprintf(tbuf, sizeof(tbuf), "%" PRIsize_t "", kv->data.size);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT:
snprintf(tbuf, sizeof(tbuf), "%d", kv->data.integer);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT8:
snprintf(tbuf, sizeof(tbuf), "%" PRIi8 "", kv->data.int8);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT16:
snprintf(tbuf, sizeof(tbuf), "%" PRIi16 "", kv->data.int16);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT32:
snprintf(tbuf, sizeof(tbuf), "%" PRIi32 "", kv->data.int32);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_INT64:
snprintf(tbuf, sizeof(tbuf), "%" PRIi64 "", kv->data.int64);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT:
snprintf(tbuf, sizeof(tbuf), "%u", kv->data.uint);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT8:
snprintf(tbuf, sizeof(tbuf), "%" PRIu8 "", kv->data.uint8);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT16:
snprintf(tbuf, sizeof(tbuf), "%" PRIu16 "", kv->data.uint16);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT32:
snprintf(tbuf, sizeof(tbuf), "%" PRIu32 "", kv->data.uint32);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_UINT64:
snprintf(tbuf, sizeof(tbuf), "%" PRIu64 "", kv->data.uint64);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_PID:
snprintf(tbuf, sizeof(tbuf), "%lu", (unsigned long)kv->data.pid);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_FLOAT:
snprintf(tbuf, sizeof(tbuf), "%f", kv->data.fval);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
case OPAL_TIMEVAL:
/* we only care about seconds */
nowtime = kv->data.tv.tv_sec;
(void)localtime_r(&nowtime, &nowtm);
strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", &nowtm);
opal_argv_append_nosize(&cmdargs, tbuf);
break;
default:
snprintf(tbuf, sizeof(tbuf), "Unsupported type: %s",
opal_dss.lookup_data_type(kv->type));
opal_argv_append_nosize(&cmdargs, tbuf);
break;
}
}
/* assemble the value string */
vstr = opal_argv_join(cmdargs, ',');
/* print it */
fprintf(mod->fp, "%s\n", vstr);
free(vstr);
opal_argv_free(cmdargs);
return OPAL_SUCCESS;
}

33
orte/mca/db/print/db_print.h Обычный файл
Просмотреть файл

@ -0,0 +1,33 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef ORTE_DB_PRINT_H
#define ORTE_DB_PRINT_H
#include <stdio.h>
#include "opal/class/opal_pointer_array.h"
#include "orte/mca/db/db.h"
BEGIN_C_DECLS
ORTE_MODULE_DECLSPEC extern orte_db_base_component_t mca_db_print_component;
typedef struct {
orte_db_base_module_t api;
char *file;
FILE *fp;
} mca_db_print_module_t;
ORTE_MODULE_DECLSPEC extern mca_db_print_module_t mca_db_print_module;
END_C_DECLS
#endif /* ORTE_DB_PRINT_H */

120
orte/mca/db/print/db_print_component.c Обычный файл
Просмотреть файл

@ -0,0 +1,120 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "orte_config.h"
#include "orte/constants.h"
#include "opal/mca/base/base.h"
#include "orte/mca/errmgr/errmgr.h"
#include "orte/mca/db/db.h"
#include "orte/mca/db/base/base.h"
#include "db_print.h"
static int component_register(void);
static bool component_avail(void);
static orte_db_base_module_t *component_create(opal_list_t *props);
/*
* Instantiate the public struct with all of our public information
* and pointers to our public functions in it
*/
orte_db_base_component_t mca_db_print_component = {
{
ORTE_DB_BASE_VERSION_2_0_0,
/* Component name and version */
"print",
ORTE_MAJOR_VERSION,
ORTE_MINOR_VERSION,
ORTE_RELEASE_VERSION,
/* Component open and close functions */
NULL,
NULL,
NULL,
component_register
},
{
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
5,
component_avail,
component_create,
NULL
};
static char *filename;
static int component_register(void)
{
filename = NULL;
(void) mca_base_component_var_register (&mca_db_print_component.base_version,
"file", "Print to the indicated file (- => stdout, + => stderr)",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&filename);
return ORTE_SUCCESS;
}
static bool component_avail(void)
{
/* always available */
return true;
}
static orte_db_base_module_t *component_create(opal_list_t *props)
{
mca_db_print_module_t *mod;
opal_value_t *kv;
bool found;
char *file;
/* if the props include a filename, then use it */
found = false;
OPAL_LIST_FOREACH(kv, props, opal_value_t) {
if (0 == strcmp(kv->key, "printfile")) {
file = kv->data.string;
}
}
if (!found) {
/* otherwise, fall back to the default */
if (NULL != filename) {
file = filename;
} else {
/* nothing for us to do */
return NULL;
}
}
mod = (mca_db_print_module_t*)malloc(sizeof(mca_db_print_module_t));
if (NULL == mod) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
return NULL;
}
/* copy the APIs across */
memcpy(mod, &mca_db_print_module.api, sizeof(orte_db_base_module_t));
/* set the globals */
mod->file = strdup(file);
mod->fp = NULL;
/* let the module init */
if (ORTE_SUCCESS != mod->api.init((struct orte_db_base_module_t*)mod)) {
free(mod);
return NULL;
}
return (orte_db_base_module_t*)mod;
}

Просмотреть файл

@ -18,7 +18,7 @@ sources = \
# mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la # mca_<type>_<name>.la (for DSO builds) or libmca_<type>_<name>.la
# (for static builds). # (for static builds).
if MCA_BUILD_opal_db_sqlite_DSO if MCA_BUILD_orte_db_sqlite_DSO
component_noinst = component_noinst =
component_install = mca_db_sqlite.la component_install = mca_db_sqlite.la
else else

Просмотреть файл

@ -1,6 +1,7 @@
dnl -*- shell-script -*- dnl -*- shell-script -*-
dnl dnl
dnl Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved. dnl Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
dnl Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
dnl $COPYRIGHT$ dnl $COPYRIGHT$
dnl dnl
dnl Additional copyrights may follow dnl Additional copyrights may follow
@ -10,8 +11,8 @@ dnl
# MCA_db_sqlite_CONFIG([action-if-found], [action-if-not-found]) # MCA_db_sqlite_CONFIG([action-if-found], [action-if-not-found])
# ----------------------------------------------------------- # -----------------------------------------------------------
AC_DEFUN([MCA_opal_db_sqlite_CONFIG], [ AC_DEFUN([MCA_orte_db_sqlite_CONFIG], [
AC_CONFIG_FILES([opal/mca/db/sqlite/Makefile]) AC_CONFIG_FILES([orte/mca/db/sqlite/Makefile])
AC_ARG_WITH([sqlite3], AC_ARG_WITH([sqlite3],
[AC_HELP_STRING([--with-sqlite3], [AC_HELP_STRING([--with-sqlite3],
@ -21,13 +22,13 @@ AC_DEFUN([MCA_opal_db_sqlite_CONFIG], [
# do not build if rte is disabled or support not requested # do not build if rte is disabled or support not requested
AS_IF([test "$with_sqlite3" != "no"], AS_IF([test "$with_sqlite3" != "no"],
[AS_IF([test ! -z "$with_sqlite3" -a "$with_sqlite3" != "yes"], [AS_IF([test ! -z "$with_sqlite3" -a "$with_sqlite3" != "yes"],
[opal_check_sqlite3_dir="$with_sqlite3"]) [orte_check_sqlite3_dir="$with_sqlite3"])
OMPI_CHECK_PACKAGE([db_sqlite], OMPI_CHECK_PACKAGE([db_sqlite],
[sqlite3.h], [sqlite3.h],
[sqlite3], [sqlite3],
[sqlite3_open], [sqlite3_open],
[], [],
[$opal_check_sqlite3_dir], [$orte_check_sqlite3_dir],
[], [],
[$1], [$1],
[$2])], [$2])],

175
orte/mca/db/sqlite/db_sqlite.c Обычный файл
Просмотреть файл

@ -0,0 +1,175 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#include "orte_config.h"
#include "orte/constants.h"
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#include <stdio.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sqlite3.h>
#include "opal/dss/dss_types.h"
#include "opal/util/argv.h"
#include "opal/util/basename.h"
#include "opal/util/os_dirpath.h"
#include "opal/util/os_path.h"
#include "opal/util/output.h"
#include "opal/util/malloc.h"
#include "opal/util/basename.h"
#include "opal/mca/pstat/base/base.h"
#include "orte/util/show_help.h"
#include "orte/mca/db/base/base.h"
#include "db_sqlite.h"
static int init(struct orte_db_base_module_t *imod);
static void finalize(struct orte_db_base_module_t *imod);
static int store(struct orte_db_base_module_t *imod,
const char *primary_key,
opal_list_t *kvs);
mca_db_sqlite_module_t mca_db_sqlite_module = {
{
init,
finalize,
store,
NULL,
NULL,
NULL
},
};
static int init(struct orte_db_base_module_t *imod)
{
mca_db_sqlite_module_t *mod = (mca_db_sqlite_module_t*)imod;
int i;
/* get the required number of database handles */
mod->dbhandles = (sqlite3**)malloc(mod->nthreads * sizeof(sqlite3*));
/* open the database - this will create the database file if
* it doesn't already exist
*/
for (i=0; i < mod->nthreads; i++) {
if (SQLITE_OK != sqlite3_open(mod->dbfile, &mod->dbhandles[i])) {
orte_show_help("help-db-sqlite.txt", "cannot-create-sqlite", true, mod->dbfile);
return ORTE_ERR_FILE_OPEN_FAILURE;
}
}
return ORTE_SUCCESS;
}
static void finalize(struct orte_db_base_module_t *imod)
{
mca_db_sqlite_module_t *mod = (mca_db_sqlite_module_t*)imod;
int i;
/* if we are normally terminating, remove the recovery file */
if (NULL != mod->dbhandles) {
for (i=0; i < mod->nthreads; i++) {
if (SQLITE_OK != sqlite3_close(mod->dbhandles[i])) {
opal_output(0, "sqlite failed to close");
}
}
}
}
static int store(struct orte_db_base_module_t *imod,
const char *primary_key,
opal_list_t *kvs)
{
int i, rc;
char *sql, **cmd = NULL, *tmp;
sqlite3_stmt *stmt;
opal_value_t *kv;
mca_db_sqlite_module_t *mod = (mca_db_sqlite_module_t*)imod;
/* setup the insert statement */
for (i=0; i < (int)opal_list_get_size(kvs); i++) {
opal_argv_append_nosize(&cmd, "?");
}
tmp = opal_argv_join(cmd, ',');
asprintf(&sql, "INSERT INTO %s VALUES (%s)", mod->dbfile, tmp);
free(tmp);
opal_argv_free(cmd);
/* use the next worker thread */
ORTE_SQLITE_CMD(prepare_v2(mod->dbhandles[mod->active], sql, strlen(sql)+1, &stmt, NULL), mod->dbhandles[mod->active], &rc);
if (SQLITE_OK != rc) {
return ORTE_ERROR;
}
/* cycle through the provided values and construct
* an insert command for them - note that the values
* MUST be in column-order for the database!
*/
OPAL_LIST_FOREACH(kv, kvs, opal_value_t) {
switch (kv->type) {
case OPAL_STRING:
ORTE_SQLITE_CMD(bind_text(stmt, i, kv->data.string, strlen(kv->data.string), NULL),
mod->dbhandles[mod->active], &rc);
break;
case OPAL_INT32:
ORTE_SQLITE_CMD(bind_int(stmt, i, kv->data.int32), mod->dbhandles[mod->active], &rc);
break;
case OPAL_INT16:
ORTE_SQLITE_CMD(bind_int(stmt, i, kv->data.int16), mod->dbhandles[mod->active], &rc);
break;
case OPAL_PID:
ORTE_SQLITE_CMD(bind_int64(stmt, i, kv->data.pid), mod->dbhandles[mod->active], &rc);
break;
case OPAL_INT64:
ORTE_SQLITE_CMD(bind_int64(stmt, i, kv->data.int64), mod->dbhandles[mod->active], &rc);
break;
case OPAL_FLOAT:
ORTE_SQLITE_CMD(bind_double(stmt, i, kv->data.fval), mod->dbhandles[mod->active], &rc);
break;
case OPAL_TIMEVAL:
asprintf(&tmp, "%d.%06d", (int)kv->data.tv.tv_sec, (int)kv->data.tv.tv_usec);
ORTE_SQLITE_CMD(bind_text(stmt, i, tmp, strlen(tmp), NULL),
mod->dbhandles[mod->active], &rc);
free(tmp);
break;
}
if (SQLITE_OK != rc) {
return ORTE_ERROR;
}
}
ORTE_SQLITE_OP(step(stmt), DONE, mod->dbhandles[mod->active], &rc);
if (SQLITE_OK != rc) {
return ORTE_ERROR;
}
opal_output_verbose(2, orte_db_base_framework.framework_output,
"INSERTED ROW %d", (int)sqlite3_last_insert_rowid(mod->dbhandles[mod->active]));
/* cycle to the next worker thread */
mod->active++;
if (mod->nthreads < mod->active) {
mod->active = 0;
}
return ORTE_SUCCESS;
}

Просмотреть файл

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved. * Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -7,24 +8,29 @@
* $HEADER$ * $HEADER$
*/ */
#ifndef OPAL_DB_SQLITE_H #ifndef ORTE_DB_SQLITE_H
#define OPAL_DB_SQLITE_H #define ORTE_DB_SQLITE_H
#include "opal/mca/db/db.h" #include <sqlite3.h>
#include "orte/mca/db/db.h"
BEGIN_C_DECLS BEGIN_C_DECLS
ORTE_MODULE_DECLSPEC extern orte_db_base_component_t mca_db_sqlite_component;
typedef struct { typedef struct {
opal_db_base_component_t super; orte_db_base_module_t api;
int num_worker_threads; char *dbfile;
char *db_file; sqlite3 **dbhandles;
} opal_db_sqlite_component_t; int nthreads;
OPAL_MODULE_DECLSPEC extern opal_db_sqlite_component_t mca_db_sqlite_component; int active;
} mca_db_sqlite_module_t;
ORTE_MODULE_DECLSPEC extern mca_db_sqlite_module_t mca_db_sqlite_module;
OPAL_DECLSPEC extern opal_db_base_module_t opal_db_sqlite_module;
/* Macros for manipulating sqlite */ /* Macros for manipulating sqlite */
#define OPAL_SQLITE_CMD(f, db, r) \ #define ORTE_SQLITE_CMD(f, db, r) \
{ \ { \
*(r) = sqlite3_ ## f; \ *(r) = sqlite3_ ## f; \
if (*(r) != SQLITE_OK) { \ if (*(r) != SQLITE_OK) { \
@ -33,7 +39,7 @@ OPAL_DECLSPEC extern opal_db_base_module_t opal_db_sqlite_module;
} \ } \
} \ } \
#define OPAL_SQLITE_OP(f, x, db, r) \ #define ORTE_SQLITE_OP(f, x, db, r) \
{ \ { \
*(r) = sqlite3_ ## f; \ *(r) = sqlite3_ ## f; \
if (*(r) != SQLITE_ ## x) { \ if (*(r) != SQLITE_ ## x) { \
@ -44,4 +50,4 @@ OPAL_DECLSPEC extern opal_db_base_module_t opal_db_sqlite_module;
END_C_DECLS END_C_DECLS
#endif /* OPAL_DB_SQLITE_H */ #endif /* ORTE_DB_SQLITE_H */

157
orte/mca/db/sqlite/db_sqlite_component.c Обычный файл
Просмотреть файл

@ -0,0 +1,157 @@
/*
* Copyright (c) 2012-2013 Los Alamos National Security, Inc. All rights reserved.
* Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
* These symbols are in a file by themselves to provide nice linker
* semantics. Since linkers generally pull in symbols by object
* files, keeping these symbols as the only symbols in this file
* prevents utility programs such as "ompi_info" from having to import
* entire components just to query their version and parameters.
*/
#include "orte_config.h"
#include "orte/constants.h"
#include <sys/stat.h>
#include <sqlite3.h>
#include "opal/mca/base/base.h"
#include "orte/mca/errmgr/errmgr.h"
#include "orte/util/show_help.h"
#include "orte/mca/db/db.h"
#include "orte/mca/db/base/base.h"
#include "db_sqlite.h"
static int component_register(void);
static bool component_avail(void);
static orte_db_base_module_t *component_create(opal_list_t *props);
/*
* Instantiate the public struct with all of our public information
* and pointers to our public functions in it
*/
orte_db_base_component_t mca_db_sqlite_component = {
{
ORTE_DB_BASE_VERSION_2_0_0,
/* Component name and version */
"sqlite",
ORTE_MAJOR_VERSION,
ORTE_MINOR_VERSION,
ORTE_RELEASE_VERSION,
/* Component open and close functions */
NULL,
NULL,
NULL,
component_register
},
{
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
75,
component_avail,
component_create,
NULL
};
static char *db_file;
static int num_worker_threads;
static int thread_safe;
static int component_register(void)
{
mca_base_component_t *c = &mca_db_sqlite_component.base_version;
/* retrieve the name of the file to be used */
db_file = NULL;
(void) mca_base_component_var_register (c, "database", "Name of file to be used for database",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&db_file);
/* retrieve the number of worker threads to be used, if sqlite3 is thread-safe */
num_worker_threads = -1;
(void) mca_base_component_var_register (c, "num_worker_threads", "Number of worker threads to be used",
MCA_BASE_VAR_TYPE_STRING, NULL, 0, 0,
OPAL_INFO_LVL_9,
MCA_BASE_VAR_SCOPE_READONLY,
&num_worker_threads);
return OPAL_SUCCESS;
}
static bool component_avail(void)
{
/* initialize sqlite3 */
if (SQLITE_OK != sqlite3_initialize()) {
return false;
}
/* check if sqlite was built thread-safe - if not, we won't
* use worker threads for thruput
*/
thread_safe = sqlite3_threadsafe();
return true;
}
static orte_db_base_module_t *component_create(opal_list_t *props)
{
mca_db_sqlite_module_t *mod;
opal_value_t *kv;
mod = (mca_db_sqlite_module_t*)malloc(sizeof(mca_db_sqlite_module_t));
if (NULL == mod) {
ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE);
return NULL;
}
memset(mod, 0, sizeof(mca_db_sqlite_module_t));
mod->nthreads = -1;
/* copy the APIs across */
memcpy(mod, &mca_db_sqlite_module.api, sizeof(orte_db_base_module_t));
/* if the props include db info, then use it */
OPAL_LIST_FOREACH(kv, props, opal_value_t) {
if (0 == strcmp(kv->key, "database")) {
mod->dbfile = strdup(kv->data.string);
} else if (0 == strcmp(kv->key, "num_worker_threads")) {
mod->nthreads = kv->data.integer;
}
}
if (NULL == mod->dbfile) {
if (NULL == db_file) {
/* nothing was provided - opt out */
free(mod);
return NULL;
}
mod->dbfile = strdup(db_file);
}
if (0 != thread_safe) {
mod->nthreads = 1;
} else {
if (0 > mod->nthreads && 0 < num_worker_threads) {
mod->nthreads = num_worker_threads;
} else {
mod->nthreads = 1;
}
}
/* let the module init */
if (ORTE_SUCCESS != mod->api.init((struct orte_db_base_module_t*)mod)) {
mod->api.finalize((struct orte_db_base_module_t*)mod);
free(mod);
return NULL;
}
return (orte_db_base_module_t*)mod;
}

Просмотреть файл

@ -1,7 +1,6 @@
-*- text -*- -*- text -*-
# #
# Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved. # Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
# Copyright (c) 2014 Cisco Systems, Inc. All rights reserved.
# $COPYRIGHT$ # $COPYRIGHT$
# #
# Additional copyrights may follow # Additional copyrights may follow
@ -14,8 +13,3 @@ WARNING: Could not find specified database file
File: %s File: %s
Data logging into sqlite3 has been disabled. Data logging into sqlite3 has been disabled.
#
[cannot-create-sqlite]
WARNING: The SQLite component failed to initialize.
Data logging into sqlite3 has been disabled.

Просмотреть файл

@ -1,6 +1,7 @@
/* /*
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. * Copyright (c) 2012-2013 Los Alamos National Security, LLC.
* All rights reserved. * All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -26,7 +27,7 @@
#include "opal/util/output.h" #include "opal/util/output.h"
#include "opal/util/uri.h" #include "opal/util/uri.h"
#include "opal/dss/dss.h" #include "opal/dss/dss.h"
#include "opal/mca/db/db.h" #include "opal/mca/dstore/dstore.h"
#include "orte/util/error_strings.h" #include "orte/util/error_strings.h"
#include "orte/util/name_fns.h" #include "orte/util/name_fns.h"
@ -502,7 +503,8 @@ static void process_opens(int fd, short args, void *cbdata)
opal_buffer_t *buffer; opal_buffer_t *buffer;
char *scheme, *host, *filename; char *scheme, *host, *filename;
orte_process_name_t daemon; orte_process_name_t daemon;
orte_vpid_t *v; opal_list_t myvals;
opal_value_t *kv;
/* get the scheme to determine if we can process locally or not */ /* get the scheme to determine if we can process locally or not */
if (NULL == (scheme = opal_uri_get_scheme(dfs->uri))) { if (NULL == (scheme = opal_uri_get_scheme(dfs->uri))) {
@ -552,11 +554,17 @@ static void process_opens(int fd, short args, void *cbdata)
opal_output_verbose(1, orte_dfs_base_framework.framework_output, opal_output_verbose(1, orte_dfs_base_framework.framework_output,
"%s looking for daemon on host %s", "%s looking for daemon on host %s",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), host); ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), host);
v = &daemon.vpid; OBJ_CONSTRUCT(&myvals, opal_list_t);
if (ORTE_SUCCESS != (rc = opal_db.fetch((opal_identifier_t*)ORTE_NAME_WILDCARD, host, (void**)&v, ORTE_VPID))) { if (ORTE_SUCCESS != (rc = opal_dstore.fetch(opal_dstore_internal,
(opal_identifier_t*)ORTE_NAME_WILDCARD,
host, &myvals))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
OPAL_LIST_DESTRUCT(&myvals);
goto complete; goto complete;
} }
kv = (opal_value_t*)opal_list_get_first(&myvals);
daemon.vpid = kv->data.uint32;
OPAL_LIST_DESTRUCT(&myvals);
opal_output_verbose(1, orte_dfs_base_framework.framework_output, opal_output_verbose(1, orte_dfs_base_framework.framework_output,
"%s file %s on host %s daemon %s", "%s file %s on host %s daemon %s",

Просмотреть файл

@ -1,6 +1,7 @@
/* /*
* Copyright (c) 2012-2013 Los Alamos National Security, LLC. * Copyright (c) 2012-2013 Los Alamos National Security, LLC.
* All rights reserved. * All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -26,7 +27,7 @@
#include "opal/util/output.h" #include "opal/util/output.h"
#include "opal/util/uri.h" #include "opal/util/uri.h"
#include "opal/dss/dss.h" #include "opal/dss/dss.h"
#include "opal/mca/db/db.h" #include "opal/mca/dstore/dstore.h"
#include "orte/util/error_strings.h" #include "orte/util/error_strings.h"
#include "orte/util/name_fns.h" #include "orte/util/name_fns.h"
@ -447,6 +448,8 @@ static void process_opens(int fd, short args, void *cbdata)
orte_process_name_t daemon; orte_process_name_t daemon;
bool found; bool found;
orte_vpid_t v; orte_vpid_t v;
opal_list_t myvals;
opal_value_t *kv;
opal_output(0, "%s PROCESSING OPEN", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME)); opal_output(0, "%s PROCESSING OPEN", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME));
/* get the scheme to determine if we can process locally or not */ /* get the scheme to determine if we can process locally or not */
@ -478,10 +481,17 @@ static void process_opens(int fd, short args, void *cbdata)
for (v=0; v < orte_process_info.num_daemons; v++) { for (v=0; v < orte_process_info.num_daemons; v++) {
daemon.vpid = v; daemon.vpid = v;
/* fetch the hostname where this daemon is located */ /* fetch the hostname where this daemon is located */
if (ORTE_SUCCESS != (rc = opal_db.fetch_pointer((opal_identifier_t*)&daemon, ORTE_DB_HOSTNAME, (void**)&hostname, OPAL_STRING))) { OBJ_CONSTRUCT(&myvals, opal_list_t);
if (ORTE_SUCCESS != (rc = opal_dstore.fetch(opal_dstore_internal,
(opal_identifier_t*)&daemon,
ORTE_DB_HOSTNAME, &myvals))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
OPAL_LIST_DESTRUCT(&myvals);
goto complete; goto complete;
} }
kv = (opal_value_t*)opal_list_get_first(&myvals);
hostname = strdup(kv->data.string);
OPAL_LIST_DESTRUCT(&myvals);
opal_output(0, "%s GOT HOST %s HOSTNAME %s", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), host, hostname); opal_output(0, "%s GOT HOST %s HOSTNAME %s", ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), host, hostname);
if (0 == strcmp(host, hostname)) { if (0 == strcmp(host, hostname)) {
found = true; found = true;

Просмотреть файл

@ -30,7 +30,7 @@
#include <errno.h> #include <errno.h>
#include "opal/util/output.h" #include "opal/util/output.h"
#include "opal/mca/db/db.h" #include "opal/mca/dstore/dstore.h"
#include "opal/mca/hwloc/base/base.h" #include "opal/mca/hwloc/base/base.h"
#include "orte/mca/errmgr/errmgr.h" #include "orte/mca/errmgr/errmgr.h"
@ -54,6 +54,7 @@ int orte_ess_base_proc_binding(void)
int ret; int ret;
char *error; char *error;
hwloc_cpuset_t mycpus; hwloc_cpuset_t mycpus;
opal_value_t kv;
/* Determine if we were pre-bound or not */ /* Determine if we were pre-bound or not */
if (NULL != getenv("OMPI_MCA_orte_bound_at_launch")) { if (NULL != getenv("OMPI_MCA_orte_bound_at_launch")) {
@ -293,13 +294,18 @@ int orte_ess_base_proc_binding(void)
/* store our cpuset for exchange with non-peers /* store our cpuset for exchange with non-peers
* so that other procs in a comm_spawn can know it * so that other procs in a comm_spawn can know it
*/ */
if (ORTE_SUCCESS != (ret = opal_db.store((opal_identifier_t*)ORTE_PROC_MY_NAME, OBJ_CONSTRUCT(&kv, opal_value_t);
OPAL_SCOPE_NON_PEER, kv.key = strdup(OPAL_DSTORE_CPUSET);
OPAL_DB_CPUSET, orte_process_info.cpuset, OPAL_STRING))) { kv.type = OPAL_STRING;
kv.data.string = strdup(orte_process_info.cpuset);
if (OPAL_SUCCESS != (ret = opal_dstore.store(opal_dstore_nonpeer,
(opal_identifier_t*)ORTE_PROC_MY_NAME,
&kv))) {
ORTE_ERROR_LOG(ret); ORTE_ERROR_LOG(ret);
OBJ_DESTRUCT(&kv);
goto error; goto error;
} }
OBJ_DESTRUCT(&kv);
return ORTE_SUCCESS; return ORTE_SUCCESS;
error: error:

Просмотреть файл

@ -33,7 +33,7 @@
#endif #endif
#include "opal/mca/event/event.h" #include "opal/mca/event/event.h"
#include "opal/mca/db/base/base.h" #include "opal/mca/dstore/base/base.h"
#include "orte/util/show_help.h" #include "orte/util/show_help.h"
#include "opal/util/os_path.h" #include "opal/util/os_path.h"
#include "opal/util/output.h" #include "opal/util/output.h"
@ -74,6 +74,7 @@ int orte_ess_base_app_setup(bool db_restrict_local)
{ {
int ret; int ret;
char *error = NULL; char *error = NULL;
opal_value_t kv;
/* /*
* stdout/stderr buffering * stdout/stderr buffering
@ -163,19 +164,33 @@ int orte_ess_base_app_setup(bool db_restrict_local)
goto error; goto error;
} }
/* database */ /* data store */
if (ORTE_SUCCESS != (ret = mca_base_framework_open(&opal_db_base_framework, 0))) { if (ORTE_SUCCESS != (ret = mca_base_framework_open(&opal_dstore_base_framework, 0))) {
ORTE_ERROR_LOG(ret); ORTE_ERROR_LOG(ret);
error = "opal_db_base_open"; error = "opal_dstore_base_open";
goto error; goto error;
} }
if (ORTE_SUCCESS != (ret = opal_db_base_select(db_restrict_local))) { if (ORTE_SUCCESS != (ret = opal_dstore_base_select())) {
ORTE_ERROR_LOG(ret); ORTE_ERROR_LOG(ret);
error = "orte_db_base_select"; error = "orte_dstore_base_select";
goto error;
}
/* create the handles */
if (0 > (opal_dstore_peer = opal_dstore.open("PEER"))) {
error = "opal dstore global";
ret = ORTE_ERR_FATAL;
goto error;
}
if (0 > (opal_dstore_internal = opal_dstore.open("INTERNAL"))) {
error = "opal dstore internal";
ret = ORTE_ERR_FATAL;
goto error;
}
if (0 > (opal_dstore_nonpeer = opal_dstore.open("NONPEER"))) {
error = "opal dstore nonpeer";
ret = ORTE_ERR_FATAL;
goto error; goto error;
} }
/* set our id */
opal_db.set_id((opal_identifier_t*)ORTE_PROC_MY_NAME);
/* /*
* Group communications * Group communications
@ -242,24 +257,34 @@ int orte_ess_base_app_setup(bool db_restrict_local)
"output-", NULL, NULL); "output-", NULL, NULL);
/* store the session directory location in the database */ /* store the session directory location in the database */
if (OPAL_SUCCESS != (ret = opal_db.store((opal_identifier_t*)ORTE_PROC_MY_NAME, OBJ_CONSTRUCT(&kv, opal_value_t);
OPAL_SCOPE_INTERNAL, kv.key = strdup(OPAL_DSTORE_JOB_SDIR);
OPAL_DB_JOB_SDIR, kv.type = OPAL_STRING;
orte_process_info.job_session_dir, OPAL_STRING))) { kv.data.string = strdup(orte_process_info.job_session_dir);
if (OPAL_SUCCESS != (ret = opal_dstore.store(opal_dstore_internal,
(opal_identifier_t*)ORTE_PROC_MY_NAME,
&kv))) {
ORTE_ERROR_LOG(ret); ORTE_ERROR_LOG(ret);
error = "store job session dir"; OBJ_DESTRUCT(&kv);
error = "opal dstore store";
goto error; goto error;
} }
if (OPAL_SUCCESS != (ret = opal_db.store((opal_identifier_t*)ORTE_PROC_MY_NAME, OBJ_DESTRUCT(&kv);
OPAL_SCOPE_INTERNAL, OBJ_CONSTRUCT(&kv, opal_value_t);
OPAL_DB_MY_SDIR, kv.key = strdup(OPAL_DSTORE_MY_SDIR);
orte_process_info.proc_session_dir, OPAL_STRING))) { kv.type = OPAL_STRING;
kv.data.string = strdup(orte_process_info.proc_session_dir);
if (OPAL_SUCCESS != (ret = opal_dstore.store(opal_dstore_internal,
(opal_identifier_t*)ORTE_PROC_MY_NAME,
&kv))) {
ORTE_ERROR_LOG(ret); ORTE_ERROR_LOG(ret);
error = "store job session dir"; OBJ_DESTRUCT(&kv);
error = "opal dstore store";
goto error; goto error;
} }
OBJ_DESTRUCT(&kv);
} }
/* setup the routed info */ /* setup the routed info */
if (ORTE_SUCCESS != (ret = orte_routed.init_routes(ORTE_PROC_MY_NAME->jobid, NULL))) { if (ORTE_SUCCESS != (ret = orte_routed.init_routes(ORTE_PROC_MY_NAME->jobid, NULL))) {
ORTE_ERROR_LOG(ret); ORTE_ERROR_LOG(ret);
@ -352,7 +377,7 @@ int orte_ess_base_app_finalize(void)
/* now can close the rml and its friendly group comm */ /* now can close the rml and its friendly group comm */
(void) mca_base_framework_close(&orte_grpcomm_base_framework); (void) mca_base_framework_close(&orte_grpcomm_base_framework);
(void) mca_base_framework_close(&opal_db_base_framework); (void) mca_base_framework_close(&opal_dstore_base_framework);
(void) mca_base_framework_close(&orte_dfs_base_framework); (void) mca_base_framework_close(&orte_dfs_base_framework);
(void) mca_base_framework_close(&orte_routed_base_framework); (void) mca_base_framework_close(&orte_routed_base_framework);

Просмотреть файл

@ -35,7 +35,7 @@
#endif #endif
#include "opal/dss/dss.h" #include "opal/dss/dss.h"
#include "opal/mca/db/base/base.h" #include "opal/mca/dstore/base/base.h"
#include "opal/mca/event/event.h" #include "opal/mca/event/event.h"
#include "opal/runtime/opal.h" #include "opal/runtime/opal.h"
#include "opal/runtime/opal_cr.h" #include "opal/runtime/opal_cr.h"
@ -274,20 +274,38 @@ int orte_ess_base_orted_setup(char **hosts)
goto error; goto error;
} }
/* database */ /* datastore - ensure we don't pickup the pmi component, but
if (ORTE_SUCCESS != (ret = mca_base_framework_open(&opal_db_base_framework, 0))) { * don't override anything set by user
*/
if (NULL == getenv("OMPI_MCA_dstore")) {
putenv("OMPI_MCA_dstore=^pmi");
}
if (ORTE_SUCCESS != (ret = mca_base_framework_open(&opal_dstore_base_framework, 0))) {
ORTE_ERROR_LOG(ret); ORTE_ERROR_LOG(ret);
error = "orte_db_base_open"; error = "opal_dstore_base_open";
goto error; goto error;
} }
/* always restrict daemons to local database components */ if (ORTE_SUCCESS != (ret = opal_dstore_base_select())) {
if (ORTE_SUCCESS != (ret = opal_db_base_select(true))) {
ORTE_ERROR_LOG(ret); ORTE_ERROR_LOG(ret);
error = "orte_db_base_select"; error = "opal_dstore_base_select";
goto error;
}
/* create the handles */
if (0 > (opal_dstore_peer = opal_dstore.open("PEER"))) {
error = "opal dstore global";
ret = ORTE_ERR_FATAL;
goto error;
}
if (0 > (opal_dstore_internal = opal_dstore.open("INTERNAL"))) {
error = "opal dstore internal";
ret = ORTE_ERR_FATAL;
goto error;
}
if (0 > (opal_dstore_nonpeer = opal_dstore.open("NONPEER"))) {
error = "opal dstore nonpeer";
ret = ORTE_ERR_FATAL;
goto error; goto error;
} }
/* set our id */
opal_db.set_id((opal_identifier_t*)ORTE_PROC_MY_NAME);
/* /*
* Group communications * Group communications
@ -662,7 +680,7 @@ int orte_ess_base_orted_finalize(void)
(void) mca_base_framework_close(&orte_oob_base_framework); (void) mca_base_framework_close(&orte_oob_base_framework);
(void) mca_base_framework_close(&orte_state_base_framework); (void) mca_base_framework_close(&orte_state_base_framework);
(void) mca_base_framework_close(&opal_db_base_framework); (void) mca_base_framework_close(&opal_dstore_base_framework);
/* cleanup any lingering session directories */ /* cleanup any lingering session directories */
orte_session_dir_cleanup(ORTE_JOBID_WILDCARD); orte_session_dir_cleanup(ORTE_JOBID_WILDCARD);

9
orte/mca/ess/env/ess_env_module.c поставляемый
Просмотреть файл

@ -10,7 +10,7 @@
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2011-2012 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2013 Intel, Inc. All rights reserved. * Copyright (c) 2013-2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -422,11 +422,16 @@ static int rte_ft_event(int state)
exit_status = ret; exit_status = ret;
goto cleanup; goto cleanup;
} }
if (OPAL_SUCCESS != (ret = opal_db.remove(NULL, NULL))) { /* RHC: you can't pass NULL as the identifier - what you'll need to do is
* close all open dstore handles, and then open the ones you need
*/
#if 0
if (OPAL_SUCCESS != (ret = opal_dstore.remove(NULL, NULL))) {
ORTE_ERROR_LOG(ret); ORTE_ERROR_LOG(ret);
exit_status = ret; exit_status = ret;
goto cleanup; goto cleanup;
} }
#endif
/* /*
* Restart the PLM - Does nothing at the moment, but included for completeness * Restart the PLM - Does nothing at the moment, but included for completeness

Просмотреть файл

@ -37,7 +37,7 @@
#include "opal/hash_string.h" #include "opal/hash_string.h"
#include "opal/class/opal_hash_table.h" #include "opal/class/opal_hash_table.h"
#include "opal/class/opal_list.h" #include "opal/class/opal_list.h"
#include "opal/mca/db/base/base.h" #include "opal/mca/dstore/base/base.h"
#include "opal/mca/event/event.h" #include "opal/mca/event/event.h"
#include "opal/runtime/opal.h" #include "opal/runtime/opal.h"
#include "opal/runtime/opal_cr.h" #include "opal/runtime/opal_cr.h"
@ -454,19 +454,38 @@ static int rte_init(void)
goto error; goto error;
} }
/* database */ /* datastore - ensure we don't pickup the pmi component, but
if (ORTE_SUCCESS != (ret = mca_base_framework_open(&opal_db_base_framework, 0))) { * don't override anything set by user
*/
if (NULL == getenv("OMPI_MCA_dstore")) {
putenv("OMPI_MCA_dstore=^pmi");
}
if (ORTE_SUCCESS != (ret = mca_base_framework_open(&opal_dstore_base_framework, 0))) {
ORTE_ERROR_LOG(ret); ORTE_ERROR_LOG(ret);
error = "orte_db_base_open"; error = "opal_dstore_base_open";
goto error; goto error;
} }
if (ORTE_SUCCESS != (ret = opal_db_base_select(true))) { if (ORTE_SUCCESS != (ret = opal_dstore_base_select())) {
ORTE_ERROR_LOG(ret); ORTE_ERROR_LOG(ret);
error = "orte_db_base_select"; error = "opal_dstore_base_select";
goto error;
}
/* create the handles */
if (0 > (opal_dstore_peer = opal_dstore.open("PEER"))) {
error = "opal dstore global";
ret = ORTE_ERR_FATAL;
goto error;
}
if (0 > (opal_dstore_internal = opal_dstore.open("INTERNAL"))) {
error = "opal dstore internal";
ret = ORTE_ERR_FATAL;
goto error;
}
if (0 > (opal_dstore_nonpeer = opal_dstore.open("NONPEER"))) {
error = "opal dstore nonpeer";
ret = ORTE_ERR_FATAL;
goto error; goto error;
} }
/* set our id */
opal_db.set_id((opal_identifier_t*)ORTE_PROC_MY_NAME);
/* /*
* Group communications * Group communications
@ -816,7 +835,7 @@ static int rte_finalize(void)
(void) mca_base_framework_close(&orte_rmaps_base_framework); (void) mca_base_framework_close(&orte_rmaps_base_framework);
(void) mca_base_framework_close(&orte_ras_base_framework); (void) mca_base_framework_close(&orte_ras_base_framework);
(void) mca_base_framework_close(&orte_grpcomm_base_framework); (void) mca_base_framework_close(&orte_grpcomm_base_framework);
(void) mca_base_framework_close(&opal_db_base_framework); (void) mca_base_framework_close(&opal_dstore_base_framework);
(void) mca_base_framework_close(&orte_routed_base_framework); (void) mca_base_framework_close(&orte_routed_base_framework);
(void) mca_base_framework_close(&orte_plm_base_framework); (void) mca_base_framework_close(&orte_plm_base_framework);
(void) mca_base_framework_close(&orte_errmgr_base_framework); (void) mca_base_framework_close(&orte_errmgr_base_framework);

Просмотреть файл

@ -65,7 +65,7 @@ static int pmi_component_open(void)
static int pmi_component_query(mca_base_module_t **module, int *priority) static int pmi_component_query(mca_base_module_t **module, int *priority)
{ {
/* we are available anywhere PMI is available, but not for HNP itself */ /* we are available anywhere PMI is available, but not for HNP itself */
if (!ORTE_PROC_IS_HNP && mca_common_pmi_init ()) { if (!ORTE_PROC_IS_HNP && mca_common_pmi_init()) {
/* if PMI is available, use it */ /* if PMI is available, use it */
*priority = 35; *priority = 35;
*module = (mca_base_module_t *)&orte_ess_pmi_module; *module = (mca_base_module_t *)&orte_ess_pmi_module;

Просмотреть файл

@ -47,11 +47,11 @@
#include "opal/util/output.h" #include "opal/util/output.h"
#include "opal/util/argv.h" #include "opal/util/argv.h"
#include "opal/class/opal_pointer_array.h" #include "opal/class/opal_pointer_array.h"
#include "opal/mca/dstore/dstore.h"
#include "opal/mca/hwloc/base/base.h" #include "opal/mca/hwloc/base/base.h"
#include "opal/util/printf.h" #include "opal/util/printf.h"
#include "opal/mca/common/pmi/common_pmi.h" #include "opal/mca/common/pmi/common_pmi.h"
#include "opal/mca/db/db.h"
#include "orte/mca/errmgr/errmgr.h" #include "orte/mca/errmgr/errmgr.h"
#include "orte/mca/grpcomm/grpcomm.h" #include "orte/mca/grpcomm/grpcomm.h"
#include "orte/mca/rml/rml.h" #include "orte/mca/rml/rml.h"
@ -96,6 +96,7 @@ static int rte_init(void)
orte_jobid_t jobid; orte_jobid_t jobid;
char *rmluri; char *rmluri;
orte_process_name_t ldr; orte_process_name_t ldr;
opal_value_t kv;
/* run the prolog */ /* run the prolog */
if (ORTE_SUCCESS != (ret = orte_ess_base_std_prolog())) { if (ORTE_SUCCESS != (ret = orte_ess_base_std_prolog())) {
@ -132,6 +133,7 @@ static int rte_init(void)
goto error; goto error;
} }
ORTE_PROC_MY_NAME->jobid = jobid; ORTE_PROC_MY_NAME->jobid = jobid;
opal_output(0, "GETTING RANK");
/* get our rank from PMI */ /* get our rank from PMI */
if (!mca_common_pmi_rank(&i)) { if (!mca_common_pmi_rank(&i)) {
error = "could not get PMI rank"; error = "could not get PMI rank";
@ -343,11 +345,17 @@ static int rte_init(void)
/* store the name of the local leader */ /* store the name of the local leader */
ldr.jobid = ORTE_PROC_MY_NAME->jobid; ldr.jobid = ORTE_PROC_MY_NAME->jobid;
ldr.vpid = ranks[0]; ldr.vpid = ranks[0];
if (ORTE_SUCCESS != (ret = opal_db.store((opal_identifier_t*)ORTE_PROC_MY_NAME, OPAL_SCOPE_INTERNAL, OBJ_CONSTRUCT(&kv, opal_value_t);
OPAL_DB_LOCALLDR, (opal_identifier_t*)&ldr, OPAL_ID_T))) { kv.key = strdup(OPAL_DSTORE_LOCALLDR);
kv.type = OPAL_ID_T;
kv.data.uint64 = *(opal_identifier_t*)&ldr;
if (ORTE_SUCCESS != (ret = opal_dstore.store(opal_dstore_internal,
(opal_identifier_t*)ORTE_PROC_MY_NAME, &kv))) {
error = "storing local leader"; error = "storing local leader";
OBJ_DESTRUCT(&kv);
goto error; goto error;
} }
OBJ_DESTRUCT(&kv);
free(ranks); free(ranks);
/* setup process binding */ /* setup process binding */
@ -368,40 +376,66 @@ static int rte_init(void)
/* construct the PMI RTE string */ /* construct the PMI RTE string */
rmluri = orte_rml.get_contact_info(); rmluri = orte_rml.get_contact_info();
/* store our info as marked for distribution to both our peers and non-peers OBJ_CONSTRUCT(&kv, opal_value_t);
* as there is no daemons available for routed communication kv.key = strdup(ORTE_DB_RMLURI);
*/ kv.type = OPAL_STRING;
if (ORTE_SUCCESS != (ret = opal_db.store((opal_identifier_t*)ORTE_PROC_MY_NAME, kv.data.string = strdup(rmluri);
OPAL_SCOPE_GLOBAL, ORTE_DB_RMLURI, if (ORTE_SUCCESS != (ret = opal_dstore.store(opal_dstore_peer,
rmluri, OPAL_STRING))) { (opal_identifier_t*)ORTE_PROC_MY_NAME, &kv))) {
error = "db store uri"; error = "db store uri";
OBJ_DESTRUCT(&kv);
goto error; goto error;
} }
OBJ_DESTRUCT(&kv);
free(rmluri); free(rmluri);
if (ORTE_SUCCESS != (ret = opal_db.store((opal_identifier_t*)ORTE_PROC_MY_NAME,
OPAL_SCOPE_GLOBAL, ORTE_DB_HOSTNAME, OBJ_CONSTRUCT(&kv, opal_value_t);
orte_process_info.nodename, OPAL_STRING))) { kv.key = strdup(ORTE_DB_HOSTNAME);
kv.type = OPAL_STRING;
kv.data.string = strdup(orte_process_info.nodename);
if (ORTE_SUCCESS != (ret = opal_dstore.store(opal_dstore_peer,
(opal_identifier_t*)ORTE_PROC_MY_NAME, &kv))) {
error = "db store hostname"; error = "db store hostname";
OBJ_DESTRUCT(&kv);
goto error; goto error;
} }
if (ORTE_SUCCESS != (ret = opal_db.store((opal_identifier_t*)ORTE_PROC_MY_NAME, OBJ_DESTRUCT(&kv);
OPAL_SCOPE_GLOBAL, OPAL_DB_CPUSET,
orte_process_info.cpuset, OPAL_STRING))) { OBJ_CONSTRUCT(&kv, opal_value_t);
kv.key = strdup(OPAL_DSTORE_CPUSET);
kv.type = OPAL_STRING;
kv.data.string = strdup(orte_process_info.cpuset);
if (ORTE_SUCCESS != (ret = opal_dstore.store(opal_dstore_peer,
(opal_identifier_t*)ORTE_PROC_MY_NAME, &kv))) {
error = "db store cpuset"; error = "db store cpuset";
OBJ_DESTRUCT(&kv);
goto error; goto error;
} }
if (ORTE_SUCCESS != (ret = opal_db.store((opal_identifier_t*)ORTE_PROC_MY_NAME, OBJ_DESTRUCT(&kv);
OPAL_SCOPE_GLOBAL, OPAL_DB_LOCALRANK,
&orte_process_info.my_local_rank, ORTE_LOCAL_RANK))) { OBJ_CONSTRUCT(&kv, opal_value_t);
kv.key = strdup(OPAL_DSTORE_LOCALRANK);
kv.type = OPAL_UINT16;
kv.data.uint16 = orte_process_info.my_local_rank;
if (ORTE_SUCCESS != (ret = opal_dstore.store(opal_dstore_peer,
(opal_identifier_t*)ORTE_PROC_MY_NAME, &kv))) {
error = "db store local rank"; error = "db store local rank";
OBJ_DESTRUCT(&kv);
goto error; goto error;
} }
if (ORTE_SUCCESS != (ret = opal_db.store((opal_identifier_t*)ORTE_PROC_MY_NAME, OBJ_DESTRUCT(&kv);
OPAL_SCOPE_GLOBAL, ORTE_DB_NODERANK,
&orte_process_info.my_node_rank, ORTE_NODE_RANK))) { OBJ_CONSTRUCT(&kv, opal_value_t);
kv.key = strdup(ORTE_DB_NODERANK);
kv.type = OPAL_UINT16;
kv.data.uint16 = orte_process_info.my_node_rank;
if (ORTE_SUCCESS != (ret = opal_dstore.store(opal_dstore_peer,
(opal_identifier_t*)ORTE_PROC_MY_NAME, &kv))) {
error = "db store node rank"; error = "db store node rank";
OBJ_DESTRUCT(&kv);
goto error; goto error;
} }
OBJ_DESTRUCT(&kv);
/* if we are an ORTE app - and not an MPI app - then /* if we are an ORTE app - and not an MPI app - then
* we need to exchange our connection info here. * we need to exchange our connection info here.

Просмотреть файл

@ -69,7 +69,6 @@ typedef struct {
typedef struct { typedef struct {
opal_list_item_t super; opal_list_item_t super;
orte_process_name_t peer; orte_process_name_t peer;
opal_scope_t scope;
} orte_grpcomm_modex_req_t; } orte_grpcomm_modex_req_t;
OBJ_CLASS_DECLARATION(orte_grpcomm_modex_req_t); OBJ_CLASS_DECLARATION(orte_grpcomm_modex_req_t);
@ -111,7 +110,7 @@ ORTE_DECLSPEC void orte_grpcomm_base_rollup_recv(int status, orte_process_name_t
/* modex support */ /* modex support */
ORTE_DECLSPEC void orte_grpcomm_base_store_modex(opal_buffer_t *rbuf, void *cbdata); ORTE_DECLSPEC void orte_grpcomm_base_store_modex(opal_buffer_t *rbuf, void *cbdata);
ORTE_DECLSPEC void orte_grpcomm_base_modex(int fd, short args, void *cbdata); ORTE_DECLSPEC void orte_grpcomm_base_modex(int fd, short args, void *cbdata);
ORTE_DECLSPEC int orte_grpcomm_base_pack_modex_entries(opal_buffer_t *buf, opal_scope_t scope); ORTE_DECLSPEC int orte_grpcomm_base_pack_modex_entries(opal_buffer_t *buf, int handle);
/* comm support */ /* comm support */
ORTE_DECLSPEC int orte_grpcomm_base_comm_start(void); ORTE_DECLSPEC int orte_grpcomm_base_comm_start(void);

Просмотреть файл

@ -35,7 +35,7 @@
#include "opal/util/output.h" #include "opal/util/output.h"
#include "opal/class/opal_hash_table.h" #include "opal/class/opal_hash_table.h"
#include "opal/dss/dss.h" #include "opal/dss/dss.h"
#include "opal/mca/db/db.h" #include "opal/mca/dstore/dstore.h"
#include "opal/mca/hwloc/base/base.h" #include "opal/mca/hwloc/base/base.h"
#include "orte/util/proc_info.h" #include "orte/util/proc_info.h"
@ -73,7 +73,6 @@ void orte_grpcomm_base_modex(int fd, short args, void *cbdata)
opal_list_item_t *item; opal_list_item_t *item;
bool found; bool found;
orte_grpcomm_collective_t *cptr; orte_grpcomm_collective_t *cptr;
opal_scope_t scope;
OPAL_OUTPUT_VERBOSE((1, orte_grpcomm_base_framework.framework_output, OPAL_OUTPUT_VERBOSE((1, orte_grpcomm_base_framework.framework_output,
"%s grpcomm:base:modex: performing modex", "%s grpcomm:base:modex: performing modex",
@ -108,7 +107,10 @@ void orte_grpcomm_base_modex(int fd, short args, void *cbdata)
} }
/* this is between our peers, so only collect info marked for them */ /* this is between our peers, so only collect info marked for them */
scope = OPAL_SCOPE_PEER; if (ORTE_SUCCESS != (rc = orte_grpcomm_base_pack_modex_entries(&modex->buffer, opal_dstore_peer))) {
ORTE_ERROR_LOG(rc);
goto cleanup;
}
/* add a wildcard name to the participants so the daemon knows /* add a wildcard name to the participants so the daemon knows
* the jobid that is involved in this collective * the jobid that is involved in this collective
@ -181,14 +183,19 @@ void orte_grpcomm_base_modex(int fd, short args, void *cbdata)
* Thus, we need to include the non-peer info as well as our peers * Thus, we need to include the non-peer info as well as our peers
* since we can't tell what the other participants may already have * since we can't tell what the other participants may already have
*/ */
scope = OPAL_SCOPE_GLOBAL; if (ORTE_SUCCESS != (rc = orte_grpcomm_base_pack_modex_entries(&modex->buffer, opal_dstore_peer))) {
ORTE_ERROR_LOG(rc);
} goto cleanup;
}
/* pack the requested entries */ /* pack our name to keep things straight during unpack */
if (ORTE_SUCCESS != (rc = orte_grpcomm_base_pack_modex_entries(&modex->buffer, scope))) { if (ORTE_SUCCESS != (rc = opal_dss.pack(&modex->buffer, ORTE_PROC_MY_NAME, 1, ORTE_NAME))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
goto cleanup; goto cleanup;
}
if (ORTE_SUCCESS != (rc = orte_grpcomm_base_pack_modex_entries(&modex->buffer, opal_dstore_nonpeer))) {
ORTE_ERROR_LOG(rc);
goto cleanup;
}
} }
OPAL_OUTPUT_VERBOSE((2, orte_grpcomm_base_framework.framework_output, OPAL_OUTPUT_VERBOSE((2, orte_grpcomm_base_framework.framework_output,
@ -252,19 +259,20 @@ void orte_grpcomm_base_store_modex(opal_buffer_t *rbuf, void *cbdata)
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
ORTE_NAME_PRINT(&pname), kv->key)); ORTE_NAME_PRINT(&pname), kv->key));
/* if this is me, dump the data - we already have it in the db */ /* if this is me, dump the data - we already have it in the db */
if (ORTE_PROC_MY_NAME->jobid == pname.jobid && if (ORTE_PROC_MY_NAME->jobid != pname.jobid ||
ORTE_PROC_MY_NAME->vpid == pname.vpid) { ORTE_PROC_MY_NAME->vpid != pname.vpid) {
OBJ_RELEASE(kv); /* store it in the database - we store this as "nonpeer"
} else { * since the "peer" datastore is for storing our own data - i.e.,
/* store it in the database */ * it contains data we will share with our peers
if (ORTE_SUCCESS != (rc = opal_db.store_pointer((opal_identifier_t*)&pname, kv))) { */
if (ORTE_SUCCESS != (rc = opal_dstore.store(opal_dstore_nonpeer,
(opal_identifier_t*)&pname, kv))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
goto cleanup; goto cleanup;
} }
/* do not release the kv - the db holds that pointer */
} }
OBJ_RELEASE(kv);
} }
OPAL_OUTPUT_VERBOSE((5, orte_grpcomm_base_framework.framework_output, OPAL_OUTPUT_VERBOSE((5, orte_grpcomm_base_framework.framework_output,
"%s store:peer:modex: completed modex entry for proc %s", "%s store:peer:modex: completed modex entry for proc %s",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
@ -294,7 +302,7 @@ void orte_grpcomm_base_store_modex(opal_buffer_t *rbuf, void *cbdata)
modex->active = false; modex->active = false;
} }
int orte_grpcomm_base_pack_modex_entries(opal_buffer_t *buf, opal_scope_t scope) int orte_grpcomm_base_pack_modex_entries(opal_buffer_t *buf, int handle)
{ {
int rc; int rc;
int32_t num_entries; int32_t num_entries;
@ -303,8 +311,9 @@ int orte_grpcomm_base_pack_modex_entries(opal_buffer_t *buf, opal_scope_t scope)
/* fetch any global or local data */ /* fetch any global or local data */
OBJ_CONSTRUCT(&data, opal_list_t); OBJ_CONSTRUCT(&data, opal_list_t);
if (ORTE_SUCCESS != (rc = opal_db.fetch_multiple((opal_identifier_t*)ORTE_PROC_MY_NAME, if (ORTE_SUCCESS != (rc = opal_dstore.fetch(handle,
scope, NULL, &data))) { (opal_identifier_t*)ORTE_PROC_MY_NAME,
NULL, &data))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
goto cleanup; goto cleanup;
} }
@ -333,10 +342,7 @@ int orte_grpcomm_base_pack_modex_entries(opal_buffer_t *buf, opal_scope_t scope)
} }
cleanup: cleanup:
while (NULL != (kv = (opal_value_t*)opal_list_remove_first(&data))) { OPAL_LIST_DESTRUCT(&data);
OBJ_RELEASE(kv);
}
OBJ_DESTRUCT(&data);
return rc; return rc;
} }

Просмотреть файл

@ -12,6 +12,7 @@
* All rights reserved. * All rights reserved.
* Copyright (c) 2011-2012 Los Alamos National Security, LLC. * Copyright (c) 2011-2012 Los Alamos National Security, LLC.
* All rights reserved. * All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -29,6 +30,7 @@
#include "opal/dss/dss.h" #include "opal/dss/dss.h"
#include "opal/mca/dstore/dstore.h"
#include "orte/util/proc_info.h" #include "orte/util/proc_info.h"
#include "orte/util/error_strings.h" #include "orte/util/error_strings.h"
@ -337,7 +339,7 @@ void orte_grpcomm_base_process_modex(int fd, short args, void *cbdata)
} }
/* collect the desired data */ /* collect the desired data */
if (ORTE_SUCCESS != (rc = orte_grpcomm_base_pack_modex_entries(buf, req->scope))) { if (ORTE_SUCCESS != (rc = orte_grpcomm_base_pack_modex_entries(buf, opal_dstore_peer))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
} }
@ -356,8 +358,7 @@ static void direct_modex(int status, orte_process_name_t* sender,
void* cbdata) void* cbdata)
{ {
opal_buffer_t *buf; opal_buffer_t *buf;
int rc, cnt; int rc;
opal_scope_t scope;
orte_grpcomm_modex_req_t *req; orte_grpcomm_modex_req_t *req;
OPAL_OUTPUT_VERBOSE((5, orte_grpcomm_base_framework.framework_output, OPAL_OUTPUT_VERBOSE((5, orte_grpcomm_base_framework.framework_output,
@ -370,13 +371,6 @@ static void direct_modex(int status, orte_process_name_t* sender,
*/ */
buf = OBJ_NEW(opal_buffer_t); buf = OBJ_NEW(opal_buffer_t);
/* get the desired scope */
cnt = 1;
if (OPAL_SUCCESS != (rc = opal_dss.unpack(buffer, &scope, &cnt, OPAL_DATA_SCOPE_T))) {
ORTE_ERROR_LOG(rc);
goto respond;
}
/* if we haven't made it to our own modex, then we may /* if we haven't made it to our own modex, then we may
* not yet have all the required info * not yet have all the required info
*/ */
@ -391,7 +385,6 @@ static void direct_modex(int status, orte_process_name_t* sender,
*/ */
req = OBJ_NEW(orte_grpcomm_modex_req_t); req = OBJ_NEW(orte_grpcomm_modex_req_t);
req->peer = *sender; req->peer = *sender;
req->scope = scope;
opal_list_append(&orte_grpcomm_base.modex_requests, &req->super); opal_list_append(&orte_grpcomm_base.modex_requests, &req->super);
OBJ_RELEASE(buf); OBJ_RELEASE(buf);
return; return;
@ -406,7 +399,7 @@ static void direct_modex(int status, orte_process_name_t* sender,
} }
/* collect the desired data */ /* collect the desired data */
if (ORTE_SUCCESS != (rc = orte_grpcomm_base_pack_modex_entries(buf, scope))) { if (ORTE_SUCCESS != (rc = orte_grpcomm_base_pack_modex_entries(buf, opal_dstore_peer))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
} }

Просмотреть файл

@ -71,8 +71,6 @@ int orte_grpcomm_pmi_open(void)
int orte_grpcomm_pmi_close(void) int orte_grpcomm_pmi_close(void)
{ {
mca_common_pmi_finalize ();
return ORTE_SUCCESS; return ORTE_SUCCESS;
} }
@ -82,7 +80,7 @@ int orte_grpcomm_pmi_component_query(mca_base_module_t **module, int *priority)
* selection will have been turned "off" for us * selection will have been turned "off" for us
*/ */
if (ORTE_PROC_IS_APP && if (ORTE_PROC_IS_APP &&
mca_common_pmi_init ()) { mca_common_pmi_init()) {
/* if PMI is available, make it available for use by MPI procs */ /* if PMI is available, make it available for use by MPI procs */
*priority = my_priority; *priority = my_priority;
*module = (mca_base_module_t *)&orte_grpcomm_pmi_module; *module = (mca_base_module_t *)&orte_grpcomm_pmi_module;

Просмотреть файл

@ -26,7 +26,7 @@
#include "opal/dss/dss.h" #include "opal/dss/dss.h"
#include "opal/mca/hwloc/base/base.h" #include "opal/mca/hwloc/base/base.h"
#include "opal/mca/common/pmi/common_pmi.h" #include "opal/mca/common/pmi/common_pmi.h"
#include "opal/mca/db/db.h" #include "opal/mca/dstore/dstore.h"
#include "orte/mca/errmgr/errmgr.h" #include "orte/mca/errmgr/errmgr.h"
#include "orte/mca/rml/rml.h" #include "orte/mca/rml/rml.h"
@ -150,6 +150,8 @@ static int modex(orte_grpcomm_collective_t *coll)
orte_vpid_t v; orte_vpid_t v;
bool local; bool local;
int rc, i; int rc, i;
opal_list_t myvals;
opal_value_t *kv, kvn;
OPAL_OUTPUT_VERBOSE((1, orte_grpcomm_base_framework.framework_output, OPAL_OUTPUT_VERBOSE((1, orte_grpcomm_base_framework.framework_output,
"%s grpcomm:pmi: modex entered", "%s grpcomm:pmi: modex entered",
@ -177,8 +179,8 @@ static int modex(orte_grpcomm_collective_t *coll)
} }
OPAL_OUTPUT_VERBOSE((1, orte_grpcomm_base_framework.framework_output, OPAL_OUTPUT_VERBOSE((1, orte_grpcomm_base_framework.framework_output,
"%s: pmapping: %s my_node=%d lr_count=%d\n", "%s: pmapping: %s my_node=%d lr_count=%d\n",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), pmapping, my_node, local_rank_count)); ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), pmapping, my_node, local_rank_count));
free(pmapping); free(pmapping);
} }
@ -205,10 +207,9 @@ static int modex(orte_grpcomm_collective_t *coll)
/* our RTE data was constructed and pushed in the ESS pmi component */ /* our RTE data was constructed and pushed in the ESS pmi component */
/* commit our modex info */ /* cycle thru all my local peers and collect their RTE info - we need
opal_db.commit((opal_identifier_t *)ORTE_PROC_MY_NAME); * that info to support some of the BTLs such as shared memory
*/
/* cycle thru all my peers and collect their RTE info */
name.jobid = ORTE_PROC_MY_NAME->jobid; name.jobid = ORTE_PROC_MY_NAME->jobid;
for (v=0; v < orte_process_info.num_procs; v++) { for (v=0; v < orte_process_info.num_procs; v++) {
if (v == ORTE_PROC_MY_NAME->vpid) { if (v == ORTE_PROC_MY_NAME->vpid) {
@ -228,12 +229,16 @@ static int modex(orte_grpcomm_collective_t *coll)
* this here will prevent the MPI layer from fetching data for all ranks * this here will prevent the MPI layer from fetching data for all ranks
*/ */
if (local) { if (local) {
if (ORTE_SUCCESS != (rc = opal_db.fetch_pointer((opal_identifier_t*)&name, OPAL_DB_CPUSET, OBJ_CONSTRUCT(&myvals, opal_list_t);
(void **)&cpuset, OPAL_STRING))) { if (ORTE_SUCCESS != (rc = opal_dstore.fetch(opal_dstore_nonpeer,
(opal_identifier_t*)&name,
OPAL_DSTORE_CPUSET, &myvals))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
OPAL_LIST_DESTRUCT(&myvals);
return rc; return rc;
} }
kv = (opal_value_t*)opal_list_get_first(&myvals);
cpuset = kv->data.string;
if (NULL == cpuset) { if (NULL == cpuset) {
/* if we share a node, but we don't know anything more, then /* if we share a node, but we don't know anything more, then
* mark us as on the node as this is all we know * mark us as on the node as this is all we know
@ -245,21 +250,28 @@ static int modex(orte_grpcomm_collective_t *coll)
orte_process_info.cpuset, orte_process_info.cpuset,
(char *) cpuset); (char *) cpuset);
} }
OPAL_LIST_DESTRUCT(&myvals);
} else { } else {
/* this is on a different node, then mark as non-local */ /* this is on a different node, then mark as non-local */
locality = OPAL_PROC_NON_LOCAL; locality = OPAL_PROC_NON_LOCAL;
} }
OPAL_OUTPUT_VERBOSE((1, orte_grpcomm_base_framework.framework_output, OPAL_OUTPUT_VERBOSE((1, orte_grpcomm_base_framework.framework_output,
"%s grpcomm:pmi proc %s locality %s", "%s grpcomm:pmi proc %s locality %s",
ORTE_NAME_PRINT(ORTE_PROC_MY_NAME), ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
ORTE_NAME_PRINT(&name), opal_hwloc_base_print_locality(locality))); ORTE_NAME_PRINT(&name), opal_hwloc_base_print_locality(locality)));
if (ORTE_SUCCESS != (rc = opal_db.store((opal_identifier_t*)&name, OPAL_SCOPE_INTERNAL, OBJ_CONSTRUCT(&kvn, opal_value_t);
OPAL_DB_LOCALITY, &locality, OPAL_HWLOC_LOCALITY_T))) { kvn.key = strdup(OPAL_DSTORE_LOCALITY);
kvn.type = OPAL_UINT16;
kvn.data.uint16 = locality;
if (ORTE_SUCCESS != (rc = opal_dstore.store(opal_dstore_internal,
(opal_identifier_t*)&name, &kvn))) {
OBJ_DESTRUCT(&kvn);
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
return rc; return rc;
} }
OBJ_DESTRUCT(&kvn);
} }
/* execute the callback */ /* execute the callback */

Просмотреть файл

@ -14,7 +14,7 @@
#include "orte/constants.h" #include "orte/constants.h"
#include "opal/util/output.h" #include "opal/util/output.h"
#include "opal/mca/db/db.h" #include "opal/mca/dstore/dstore.h"
#include "opal/util/argv.h" #include "opal/util/argv.h"
#include "orte/mca/errmgr/errmgr.h" #include "orte/mca/errmgr/errmgr.h"
@ -39,7 +39,8 @@ void orte_oob_base_send_nb(int fd, short args, void *cbdata)
bool msg_sent; bool msg_sent;
mca_oob_base_component_t *component; mca_oob_base_component_t *component;
bool reachable; bool reachable;
char *rmluri; opal_list_t myvals;
opal_value_t *kv;
opal_output_verbose(5, orte_oob_base_framework.framework_output, opal_output_verbose(5, orte_oob_base_framework.framework_output,
"%s oob:base:send to target %s", "%s oob:base:send to target %s",
@ -59,20 +60,33 @@ void orte_oob_base_send_nb(int fd, short args, void *cbdata)
* so check there next - if it is, the peer object will be added * so check there next - if it is, the peer object will be added
* to our hash table * to our hash table
*/ */
if (OPAL_SUCCESS == opal_db.fetch_pointer((opal_identifier_t*)&msg->dst, ORTE_DB_RMLURI, OBJ_CONSTRUCT(&myvals, opal_list_t);
(void **)&rmluri, OPAL_STRING)) { if (OPAL_SUCCESS == opal_dstore.fetch(opal_dstore_peer,
process_uri(rmluri); (opal_identifier_t*)&msg->dst,
free(rmluri); ORTE_DB_RMLURI, &myvals)) {
if (OPAL_SUCCESS != opal_hash_table_get_value_uint64(&orte_oob_base.peers, kv = (opal_value_t*)opal_list_get_first(&myvals);
ui64, (void**)&pr) || if (NULL != kv) {
NULL == pr) { process_uri(kv->data.string);
/* that is just plain wrong */ if (OPAL_SUCCESS != opal_hash_table_get_value_uint64(&orte_oob_base.peers,
ui64, (void**)&pr) ||
NULL == pr) {
/* that is just plain wrong */
ORTE_ERROR_LOG(ORTE_ERR_ADDRESSEE_UNKNOWN);
msg->status = ORTE_ERR_ADDRESSEE_UNKNOWN;
ORTE_RML_SEND_COMPLETE(msg);
OBJ_RELEASE(cd);
OPAL_LIST_DESTRUCT(&myvals);
return;
}
} else {
ORTE_ERROR_LOG(ORTE_ERR_ADDRESSEE_UNKNOWN); ORTE_ERROR_LOG(ORTE_ERR_ADDRESSEE_UNKNOWN);
msg->status = ORTE_ERR_ADDRESSEE_UNKNOWN; msg->status = ORTE_ERR_ADDRESSEE_UNKNOWN;
ORTE_RML_SEND_COMPLETE(msg); ORTE_RML_SEND_COMPLETE(msg);
OBJ_RELEASE(cd); OBJ_RELEASE(cd);
OPAL_LIST_DESTRUCT(&myvals);
return; return;
} }
OPAL_LIST_DESTRUCT(&myvals);
} else { } else {
/* even though we don't know about this peer yet, we still might /* even though we don't know about this peer yet, we still might
* be able to get to it via routing, so ask each component if * be able to get to it via routing, so ask each component if

Просмотреть файл

@ -51,6 +51,7 @@
#include "opal_stdint.h" #include "opal_stdint.h"
#include "opal/mca/backtrace/backtrace.h" #include "opal/mca/backtrace/backtrace.h"
#include "opal/mca/base/mca_base_var.h" #include "opal/mca/base/mca_base_var.h"
#include "opal/mca/dstore/dstore.h"
#include "opal/mca/sec/sec.h" #include "opal/mca/sec/sec.h"
#include "opal/util/output.h" #include "opal/util/output.h"
#include "opal/util/net.h" #include "opal/util/net.h"
@ -339,7 +340,8 @@ static int tcp_peer_send_connect_ack(mca_oob_tcp_module_t *mod,
hdr.tag = 0; hdr.tag = 0;
/* get our security credential*/ /* get our security credential*/
if (OPAL_SUCCESS != (rc = opal_sec.get_my_credential((opal_identifier_t*)ORTE_PROC_MY_NAME, &cred))) { if (OPAL_SUCCESS != (rc = opal_sec.get_my_credential(opal_dstore_internal,
(opal_identifier_t*)ORTE_PROC_MY_NAME, &cred))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
return rc; return rc;
} }

Просмотреть файл

@ -29,7 +29,7 @@
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#include "opal/mca/db/db.h" #include "opal/mca/dstore/dstore.h"
#include "opal/mca/hwloc/hwloc.h" #include "opal/mca/hwloc/hwloc.h"
#include "opal/util/argv.h" #include "opal/util/argv.h"
#include "opal/util/output.h" #include "opal/util/output.h"
@ -483,6 +483,8 @@ char* orte_get_proc_hostname(orte_process_name_t *proc)
orte_proc_t *proct; orte_proc_t *proct;
char *hostname; char *hostname;
int rc; int rc;
opal_list_t myvals;
opal_value_t *kv;
if (ORTE_PROC_IS_DAEMON || ORTE_PROC_IS_HNP) { if (ORTE_PROC_IS_DAEMON || ORTE_PROC_IS_HNP) {
/* look it up on our arrays */ /* look it up on our arrays */
@ -497,21 +499,32 @@ char* orte_get_proc_hostname(orte_process_name_t *proc)
return proct->node->name; return proct->node->name;
} }
/* if we are an app, get the pointer from the modex db */ /* if we are an app, get the data from the modex db */
if (ORTE_SUCCESS != (rc = opal_db.fetch_pointer((opal_identifier_t*)proc, OBJ_CONSTRUCT(&myvals, opal_list_t);
ORTE_DB_HOSTNAME, if (ORTE_SUCCESS != (rc = opal_dstore.fetch(opal_dstore_internal,
(void**)&hostname, OPAL_STRING))) { (opal_identifier_t*)proc,
ORTE_DB_HOSTNAME,
&myvals))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
OPAL_LIST_DESTRUCT(&myvals);
return NULL; return NULL;
} }
kv = (opal_value_t*)opal_list_get_first(&myvals);
hostname = kv->data.string;
/* protect the data */
kv->data.string = NULL;
OPAL_LIST_DESTRUCT(&myvals);
/* user is responsible for releasing the data */
return hostname; return hostname;
} }
orte_node_rank_t orte_get_proc_node_rank(orte_process_name_t *proc) orte_node_rank_t orte_get_proc_node_rank(orte_process_name_t *proc)
{ {
orte_proc_t *proct; orte_proc_t *proct;
orte_node_rank_t noderank, *nr; orte_node_rank_t noderank;
int rc; int rc;
opal_list_t myvals;
opal_value_t *kv;
if (ORTE_PROC_IS_DAEMON || ORTE_PROC_IS_HNP) { if (ORTE_PROC_IS_DAEMON || ORTE_PROC_IS_HNP) {
/* look it up on our arrays */ /* look it up on our arrays */
@ -523,13 +536,18 @@ orte_node_rank_t orte_get_proc_node_rank(orte_process_name_t *proc)
} }
/* if we are an app, get the value from the modex db */ /* if we are an app, get the value from the modex db */
nr = &noderank; OBJ_CONSTRUCT(&myvals, opal_list_t);
if (ORTE_SUCCESS != (rc = opal_db.fetch_pointer((opal_identifier_t*)proc, if (ORTE_SUCCESS != (rc = opal_dstore.fetch(opal_dstore_internal,
ORTE_DB_NODERANK, (opal_identifier_t*)proc,
(void**)&nr, ORTE_NODE_RANK))) { ORTE_DB_NODERANK,
&myvals))) {
ORTE_ERROR_LOG(rc); ORTE_ERROR_LOG(rc);
OPAL_LIST_DESTRUCT(&myvals);
return ORTE_NODE_RANK_INVALID; return ORTE_NODE_RANK_INVALID;
} }
kv = (opal_value_t*)opal_list_get_first(&myvals);
noderank = kv->data.uint16;
OPAL_LIST_DESTRUCT(&myvals);
return noderank; return noderank;
} }

Просмотреть файл

@ -1710,6 +1710,12 @@ static int create_app(int argc, char* argv[],
opal_setenv("OMPI_MCA_pubsub_orte_server", ompi_server, true, &app->env); opal_setenv("OMPI_MCA_pubsub_orte_server", ompi_server, true, &app->env);
} }
/* when launching this way, ensure the app doesn't
* pickup the pmi datastore component unless specifically
* directed otherwise
*/
opal_setenv("OMPI_MCA_dstore", "^pmi", false, &app->env);
/* Did the user request to export any environment variables on the cmd line? */ /* Did the user request to export any environment variables on the cmd line? */
if (opal_cmd_line_is_taken(&cmd_line, "x")) { if (opal_cmd_line_is_taken(&cmd_line, "x")) {
j = opal_cmd_line_get_ninsts(&cmd_line, "x"); j = opal_cmd_line_get_ninsts(&cmd_line, "x");

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше