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 (c) 2016 Intel, Inc. All rights reserved.
18 * $COPYRIGHT$
19 *
20 * Additional copyrights may follow
21 *
22 * $HEADER$
23 */
24
25 #include <src/include/pmix_config.h>
26
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdlib.h>
30
31 #include "src/class/pmix_list.h"
32 #include "src/util/argv.h"
33 #include "src/util/error.h"
34 #include "src/util/output.h"
35 #include "src/mca/mca.h"
36 #include "src/mca/base/base.h"
37 #include "pmix_common.h"
38
39 /*
40 * Local functions
41 */
42 static int open_components(pmix_mca_base_framework_t *framework);
43
44 struct pmix_mca_base_dummy_framework_list_item_t {
45 pmix_list_item_t super;
46 pmix_mca_base_framework_t framework;
47 };
48
49 /**
50 * Function for finding and opening either all MCA components, or the
51 * one that was specifically requested via a MCA parameter.
52 */
53 int pmix_mca_base_framework_components_open (pmix_mca_base_framework_t *framework,
54 pmix_mca_base_open_flag_t flags)
55 {
56 /* Open flags are not used at this time. Suppress compiler warning. */
57 if (flags & PMIX_MCA_BASE_OPEN_FIND_COMPONENTS) {
58 bool open_dso_components = !(flags & PMIX_MCA_BASE_OPEN_STATIC_ONLY);
59 /* Find and load requested components */
60 int ret = pmix_mca_base_component_find(NULL, framework, false, open_dso_components);
61 if (PMIX_SUCCESS != ret) {
62 return ret;
63 }
64 }
65
66 /* Open all registered components */
67 return open_components (framework);
68 }
69
70 /*
71 * Traverse the entire list of found components (a list of
72 * pmix_mca_base_component_t instances). If the requested_component_names
73 * array is empty, or the name of each component in the list of found
74 * components is in the requested_components_array, try to open it.
75 * If it opens, add it to the components_available list.
76 */
77 static int open_components(pmix_mca_base_framework_t *framework)
78 {
79 pmix_list_t *components = &framework->framework_components;
80 uint32_t open_only_flags = PMIX_MCA_BASE_METADATA_PARAM_NONE;
81 int output_id = framework->framework_output;
82 pmix_mca_base_component_list_item_t *cli, *next;
83 int ret;
84
85 /*
86 * Pre-process the list with parameter constraints
87 * e.g., If requested to select only CR enabled components
88 * then only make available those components.
89 *
90 * JJH Note: Currently checkpoint/restart is the only user of this
91 * functionality. If other component constraint options are
92 * added, then this logic can be used for all contraint
93 * options.
94 *
95 * NTH: Logic moved to pmix_mca_base_components_filter.
96 */
97
98 /* If pmix_mca_base_framework_register_components was called with the MCA_BASE_COMPONENTS_ALL flag
99 we need to trim down and close any extra components we do not want open */
100 ret = pmix_mca_base_components_filter (framework, open_only_flags);
101 if (PMIX_SUCCESS != ret) {
102 return ret;
103 }
104
105 /* Announce */
106 pmix_output_verbose (PMIX_MCA_BASE_VERBOSE_COMPONENT, output_id,
107 "mca: base: components_open: opening %s components",
108 framework->framework_name);
109
110 /* Traverse the list of components */
111 PMIX_LIST_FOREACH_SAFE(cli, next, components, pmix_mca_base_component_list_item_t) {
112 const pmix_mca_base_component_t *component = cli->cli_component;
113
114 pmix_output_verbose (PMIX_MCA_BASE_VERBOSE_COMPONENT, output_id,
115 "mca: base: components_open: found loaded component %s",
116 component->pmix_mca_component_name);
117
118 if (NULL != component->pmix_mca_open_component) {
119 /* Call open if register didn't call it already */
120 ret = component->pmix_mca_open_component();
121
122 if (PMIX_SUCCESS == ret) {
123 pmix_output_verbose (PMIX_MCA_BASE_VERBOSE_COMPONENT, output_id,
124 "mca: base: components_open: "
125 "component %s open function successful",
126 component->pmix_mca_component_name);
127 } else {
128 if (PMIX_ERR_NOT_AVAILABLE != ret) {
129 /* If the component returns PMIX_ERR_NOT_AVAILABLE,
130 it's a cue to "silently ignore me" -- it's not a
131 failure, it's just a way for the component to say
132 "nope!".
133
134 Otherwise, however, display an error. We may end
135 up displaying this twice, but it may go to separate
136 streams. So better to be redundant than to not
137 display the error in the stream where it was
138 expected. */
139
140 if (pmix_mca_base_component_show_load_errors) {
141 pmix_output_verbose (PMIX_MCA_BASE_VERBOSE_ERROR, output_id,
142 "mca: base: components_open: component %s "
143 "/ %s open function failed",
144 component->pmix_mca_type_name,
145 component->pmix_mca_component_name);
146 }
147 pmix_output_verbose (PMIX_MCA_BASE_VERBOSE_COMPONENT, output_id,
148 "mca: base: components_open: "
149 "component %s open function failed",
150 component->pmix_mca_component_name);
151 }
152
153 pmix_mca_base_component_close (component, output_id);
154
155 pmix_list_remove_item (components, &cli->super);
156 PMIX_RELEASE(cli);
157 }
158 }
159 }
160
161 /* All done */
162
163 return PMIX_SUCCESS;
164 }