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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
|
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2012-2015 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2017 IBM Corporation. All rights reserved.
* Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights reserved.
* Copyright (c) 2018 Triad National Security, LLC. All rights
* reserved.
* Copyright (c) 2023 Jeffrey M. Squyres. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal/include/opal_config.h"
#include "opal/include/opal/constants.h"
#include "opal/util/output.h"
#include "opal/util/printf.h"
#include "mca_base_framework.h"
#include "mca_base_var.h"
#include "opal/mca/base/base.h"
bool mca_base_framework_is_registered(struct mca_base_framework_t *framework)
{
return !!(framework->framework_flags & MCA_BASE_FRAMEWORK_FLAG_REGISTERED);
}
bool mca_base_framework_is_open(struct mca_base_framework_t *framework)
{
return !!(framework->framework_flags & MCA_BASE_FRAMEWORK_FLAG_OPEN);
}
static void framework_open_output(struct mca_base_framework_t *framework)
{
if (0 < framework->framework_verbose) {
if (-1 == framework->framework_output) {
framework->framework_output = opal_output_open(NULL);
}
opal_output_set_verbosity(framework->framework_output, framework->framework_verbose);
} else if (-1 != framework->framework_output) {
opal_output_close(framework->framework_output);
framework->framework_output = -1;
}
}
static void framework_close_output(struct mca_base_framework_t *framework)
{
if (-1 != framework->framework_output) {
opal_output_close(framework->framework_output);
framework->framework_output = -1;
}
}
int mca_base_framework_register(struct mca_base_framework_t *framework,
mca_base_register_flag_t flags)
{
char *desc;
int ret;
assert(NULL != framework);
framework->framework_refcnt++;
if (mca_base_framework_is_registered(framework)) {
return OPAL_SUCCESS;
}
OBJ_CONSTRUCT(&framework->framework_components, opal_list_t);
OBJ_CONSTRUCT(&framework->framework_failed_components, opal_list_t);
if (framework->framework_flags & MCA_BASE_FRAMEWORK_FLAG_NO_DSO) {
flags |= MCA_BASE_REGISTER_STATIC_ONLY;
}
if (!(MCA_BASE_FRAMEWORK_FLAG_NOREGISTER & framework->framework_flags)) {
/* register this framework with the MCA variable system */
ret = mca_base_var_group_register(framework->framework_project, framework->framework_name,
NULL, framework->framework_description);
if (0 > ret) {
return ret;
}
opal_asprintf(&desc,
"Default selection set of components for the %s framework (<none>"
" means use all components that can be found)",
framework->framework_name);
ret = mca_base_var_register(framework->framework_project, framework->framework_name, NULL,
NULL, desc, MCA_BASE_VAR_TYPE_STRING, NULL, 0,
MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_2,
MCA_BASE_VAR_SCOPE_ALL_EQ, &framework->framework_selection);
free(desc);
if (0 > ret) {
return ret;
}
/* register a verbosity variable for this framework */
ret = opal_asprintf(&desc, "Verbosity level for the %s framework (default: 0)",
framework->framework_name);
if (0 > ret) {
return OPAL_ERR_OUT_OF_RESOURCE;
}
framework->framework_verbose = MCA_BASE_VERBOSE_ERROR;
ret = mca_base_framework_var_register(framework, "verbose", desc, MCA_BASE_VAR_TYPE_INT,
&mca_base_var_enum_verbose, 0,
MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_8,
MCA_BASE_VAR_SCOPE_LOCAL,
&framework->framework_verbose);
free(desc);
if (0 > ret) {
return ret;
}
/* check the initial verbosity and open the output if necessary. we
will recheck this on open */
framework_open_output(framework);
/* register framework variables */
if (NULL != framework->framework_register) {
ret = framework->framework_register(flags);
if (OPAL_SUCCESS != ret) {
return ret;
}
}
/* register components variables */
ret = mca_base_framework_components_register(framework, flags);
if (OPAL_SUCCESS != ret) {
return ret;
}
}
framework->framework_flags |= MCA_BASE_FRAMEWORK_FLAG_REGISTERED;
/* framework did not provide a register function */
return OPAL_SUCCESS;
}
int mca_base_framework_register_list(mca_base_framework_t **frameworks,
mca_base_register_flag_t flags)
{
if (NULL == frameworks) {
return OPAL_ERR_BAD_PARAM;
}
for (int i = 0; frameworks[i]; ++i) {
int ret = mca_base_framework_register(frameworks[i], flags);
if (OPAL_UNLIKELY(OPAL_SUCCESS != ret && OPAL_ERR_NOT_AVAILABLE != ret)) {
return ret;
}
}
return OPAL_SUCCESS;
}
int mca_base_framework_open(struct mca_base_framework_t *framework, mca_base_open_flag_t flags)
{
int ret;
assert(NULL != framework);
/* register this framework before opening it */
ret = mca_base_framework_register(framework, MCA_BASE_REGISTER_DEFAULT);
if (OPAL_SUCCESS != ret) {
return ret;
}
/* check if this framework is already open */
if (mca_base_framework_is_open(framework)) {
return OPAL_SUCCESS;
}
if (MCA_BASE_FRAMEWORK_FLAG_NOREGISTER & framework->framework_flags) {
flags |= MCA_BASE_OPEN_FIND_COMPONENTS;
if (MCA_BASE_FRAMEWORK_FLAG_NO_DSO & framework->framework_flags) {
flags |= MCA_BASE_OPEN_STATIC_ONLY;
}
}
/* lock all of this frameworks's variables */
ret = mca_base_var_group_find(framework->framework_project, framework->framework_name, NULL);
mca_base_var_group_set_var_flag(ret, MCA_BASE_VAR_FLAG_SETTABLE, false);
/* check the verbosity level and open (or close) the output */
framework_open_output(framework);
if (NULL != framework->framework_open) {
ret = framework->framework_open(flags);
} else {
ret = mca_base_framework_components_open(framework, flags);
}
if (OPAL_SUCCESS != ret) {
framework->framework_refcnt--;
} else {
framework->framework_flags |= MCA_BASE_FRAMEWORK_FLAG_OPEN;
}
return ret;
}
int mca_base_framework_open_list(mca_base_framework_t **frameworks, mca_base_open_flag_t flags)
{
if (NULL == frameworks) {
return OPAL_ERR_BAD_PARAM;
}
for (int i = 0; frameworks[i]; ++i) {
int ret = mca_base_framework_open(frameworks[i], flags);
if (OPAL_UNLIKELY(OPAL_SUCCESS != ret && OPAL_ERR_NOT_AVAILABLE != ret)) {
return ret;
}
}
return OPAL_SUCCESS;
}
int mca_base_framework_close(struct mca_base_framework_t *framework)
{
bool is_open = mca_base_framework_is_open(framework);
bool is_registered = mca_base_framework_is_registered(framework);
int ret, group_id;
assert(NULL != framework);
if (!(is_open || is_registered)) {
return OPAL_SUCCESS;
}
assert(framework->framework_refcnt);
if (--framework->framework_refcnt) {
return OPAL_SUCCESS;
}
/* find and deregister all component groups and variables */
group_id = mca_base_var_group_find(framework->framework_project, framework->framework_name,
NULL);
if (0 <= group_id) {
(void) mca_base_var_group_deregister(group_id);
}
/* close the framework and all of its components */
if (is_open) {
ret = OPAL_SUCCESS;
if (NULL != framework->framework_close) {
ret = framework->framework_close();
}
if (OPAL_SUCCESS == ret) {
ret = mca_base_framework_components_close(framework, NULL);
}
if (OPAL_SUCCESS != ret) {
return ret;
}
} else {
opal_list_item_t *item;
while (NULL != (item = opal_list_remove_first(&framework->framework_components))) {
mca_base_component_list_item_t *cli;
cli = (mca_base_component_list_item_t *) item;
mca_base_component_unload(cli->cli_component, framework->framework_output);
OBJ_RELEASE(item);
}
while (NULL != (item = opal_list_remove_first(&framework->framework_failed_components))) {
OBJ_RELEASE(item);
}
ret = OPAL_SUCCESS;
}
framework->framework_flags &= ~(MCA_BASE_FRAMEWORK_FLAG_REGISTERED
| MCA_BASE_FRAMEWORK_FLAG_OPEN);
OBJ_DESTRUCT(&framework->framework_components);
OBJ_DESTRUCT(&framework->framework_failed_components);
framework_close_output(framework);
return ret;
}
int mca_base_framework_close_list(mca_base_framework_t **frameworks)
{
if (NULL == frameworks) {
return OPAL_ERR_BAD_PARAM;
}
for (int i = 0; frameworks[i]; ++i) {
int ret = mca_base_framework_close(frameworks[i]);
if (OPAL_UNLIKELY(OPAL_SUCCESS != ret)) {
return ret;
}
}
return OPAL_SUCCESS;
}
|