1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3 * Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2013 The University of Tennessee and The University
7 * of Tennessee Research Foundation. All rights
8 * reserved.
9 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10 * University of Stuttgart. All rights reserved.
11 * Copyright (c) 2004-2005 The Regents of the University of California.
12 * All rights reserved.
13 * Copyright (c) 2008-2012 Cisco Systems, Inc. All rights reserved.
14 * Copyright (c) 2011-2015 Los Alamos National Security, LLC.
15 * All rights reserved.
16 * Copyright (c) 2014 Hochschule Esslingen. All rights reserved.
17 * $COPYRIGHT$
18 *
19 * Additional copyrights may follow
20 *
21 * $HEADER$
22 */
23
24 #include "opal_config.h"
25
26 #include <stdio.h>
27 #include <string.h>
28 #include <stdlib.h>
29
30 #include "opal/class/opal_list.h"
31 #include "opal/util/argv.h"
32 #include "opal/util/output.h"
33 #include "opal/mca/mca.h"
34 #include "opal/mca/base/base.h"
35 #include "opal/constants.h"
36 #if OPAL_ENABLE_FT_CR == 1
37 #include "opal/runtime/opal_params.h"
38 #endif
39
40 /*
41 * Local functions
42 */
43 static int open_components(mca_base_framework_t *framework);
44
45 struct mca_base_dummy_framework_list_item_t {
46 opal_list_item_t super;
47 mca_base_framework_t framework;
48 };
49
50 /**
51 * Function for finding and opening either all MCA components, or the
52 * one that was specifically requested via a MCA parameter.
53 */
mca_base_framework_components_open(mca_base_framework_t * framework,mca_base_open_flag_t flags)54 int mca_base_framework_components_open (mca_base_framework_t *framework,
55 mca_base_open_flag_t flags)
56 {
57 /* Open flags are not used at this time. Suppress compiler warning. */
58 if (flags & MCA_BASE_OPEN_FIND_COMPONENTS) {
59 bool open_dso_components = !(flags & MCA_BASE_OPEN_STATIC_ONLY);
60 /* Find and load requested components */
61 int ret = mca_base_component_find(NULL, framework, false, open_dso_components);
62 if (OPAL_SUCCESS != ret) {
63 return ret;
64 }
65 }
66
67 /* Open all registered components */
68 return open_components (framework);
69 }
70
71 /*
72 * Traverse the entire list of found components (a list of
73 * mca_base_component_t instances). If the requested_component_names
74 * array is empty, or the name of each component in the list of found
75 * components is in the requested_components_array, try to open it.
76 * If it opens, add it to the components_available list.
77 */
open_components(mca_base_framework_t * framework)78 static int open_components(mca_base_framework_t *framework)
79 {
80 opal_list_t *components = &framework->framework_components;
81 uint32_t open_only_flags = MCA_BASE_METADATA_PARAM_NONE;
82 int output_id = framework->framework_output;
83 mca_base_component_list_item_t *cli, *next;
84 int ret;
85
86 /*
87 * Pre-process the list with parameter constraints
88 * e.g., If requested to select only CR enabled components
89 * then only make available those components.
90 *
91 * JJH Note: Currently checkpoint/restart is the only user of this
92 * functionality. If other component constraint options are
93 * added, then this logic can be used for all contraint
94 * options.
95 *
96 * NTH: Logic moved to mca_base_components_filter.
97 */
98 #if (OPAL_ENABLE_FT == 1) && (OPAL_ENABLE_FT_CR == 1)
99 if (opal_base_distill_checkpoint_ready) {
100 open_only_flags |= MCA_BASE_METADATA_PARAM_CHECKPOINT;
101 }
102 #endif /* (OPAL_ENABLE_FT == 1) && (OPAL_ENABLE_FT_CR == 1) */
103
104 /* If mca_base_framework_register_components was called with the MCA_BASE_COMPONENTS_ALL flag
105 we need to trim down and close any extra components we do not want open */
106 ret = mca_base_components_filter (framework, open_only_flags);
107 if (OPAL_SUCCESS != ret) {
108 return ret;
109 }
110
111 /* Announce */
112 opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id, "mca: base: components_open: opening %s components",
113 framework->framework_name);
114
115 /* Traverse the list of components */
116 OPAL_LIST_FOREACH_SAFE(cli, next, components, mca_base_component_list_item_t) {
117 const mca_base_component_t *component = cli->cli_component;
118
119 opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id,
120 "mca: base: components_open: found loaded component %s",
121 component->mca_component_name);
122
123 if (NULL != component->mca_open_component) {
124 /* Call open if register didn't call it already */
125 ret = component->mca_open_component();
126
127 if (OPAL_SUCCESS == ret) {
128 opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id,
129 "mca: base: components_open: "
130 "component %s open function successful",
131 component->mca_component_name);
132 } else {
133 if (OPAL_ERR_NOT_AVAILABLE != ret) {
134 /* If the component returns OPAL_ERR_NOT_AVAILABLE,
135 it's a cue to "silently ignore me" -- it's not a
136 failure, it's just a way for the component to say
137 "nope!".
138
139 Otherwise, however, display an error. We may end
140 up displaying this twice, but it may go to separate
141 streams. So better to be redundant than to not
142 display the error in the stream where it was
143 expected. */
144
145 if (mca_base_component_show_load_errors) {
146 opal_output_verbose (MCA_BASE_VERBOSE_ERROR, output_id,
147 "mca: base: components_open: component %s "
148 "/ %s open function failed",
149 component->mca_type_name,
150 component->mca_component_name);
151 }
152 opal_output_verbose (MCA_BASE_VERBOSE_COMPONENT, output_id,
153 "mca: base: components_open: "
154 "component %s open function failed",
155 component->mca_component_name);
156 }
157
158 mca_base_component_close (component, output_id);
159
160 opal_list_remove_item (components, &cli->super);
161 OBJ_RELEASE(cli);
162 }
163 }
164 }
165
166 /* All done */
167
168 return OPAL_SUCCESS;
169 }
170