/
db_base_select.c
135 lines (117 loc) · 4.84 KB
/
db_base_select.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* 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/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(void)
{
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);
/* 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;;
}