root/opal/mca/base/mca_base_framework.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mca_base_framework_is_registered
  2. mca_base_framework_is_open
  3. framework_open_output
  4. framework_close_output
  5. mca_base_framework_register
  6. mca_base_framework_register_list
  7. mca_base_framework_open
  8. mca_base_framework_open_list
  9. mca_base_framework_close
  10. mca_base_framework_close_list

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2012-2015 Los Alamos National Security, LLC. All rights
   4  *                         reserved.
   5  * Copyright (c) 2015 Cisco Systems, Inc.  All rights reserved.
   6  * Copyright (c) 2017 IBM Corporation.  All rights reserved.
   7  * Copyright (c) 2018      Amazon.com, Inc. or its affiliates.  All Rights reserved.
   8  * Copyright (c) 2018      Triad National Security, LLC. All rights
   9  *                         reserved.
  10  * $COPYRIGHT$
  11  *
  12  * Additional copyrights may follow
  13  *
  14  * $HEADER$
  15  */
  16 
  17 #include "opal/include/opal_config.h"
  18 
  19 #include "opal/include/opal/constants.h"
  20 #include "opal/util/output.h"
  21 #include "opal/util/printf.h"
  22 
  23 #include "mca_base_framework.h"
  24 #include "mca_base_var.h"
  25 #include "opal/mca/base/base.h"
  26 
  27 bool mca_base_framework_is_registered (struct mca_base_framework_t *framework)
  28 {
  29     return !!(framework->framework_flags & MCA_BASE_FRAMEWORK_FLAG_REGISTERED);
  30 }
  31 
  32 bool mca_base_framework_is_open (struct mca_base_framework_t *framework)
  33 {
  34     return !!(framework->framework_flags & MCA_BASE_FRAMEWORK_FLAG_OPEN);
  35 }
  36 
  37 static void framework_open_output (struct mca_base_framework_t *framework)
  38 {
  39     if (0 < framework->framework_verbose) {
  40         if (-1 == framework->framework_output) {
  41             framework->framework_output = opal_output_open (NULL);
  42         }
  43         opal_output_set_verbosity(framework->framework_output,
  44                                   framework->framework_verbose);
  45     } else if (-1 != framework->framework_output) {
  46         opal_output_close (framework->framework_output);
  47         framework->framework_output = -1;
  48     }
  49 }
  50 
  51 static void framework_close_output (struct mca_base_framework_t *framework)
  52 {
  53     if (-1 != framework->framework_output) {
  54         opal_output_close (framework->framework_output);
  55         framework->framework_output = -1;
  56     }
  57 }
  58 
  59 int mca_base_framework_register (struct mca_base_framework_t *framework,
  60                                  mca_base_register_flag_t flags)
  61 {
  62     char *desc;
  63     int ret;
  64 
  65     assert (NULL != framework);
  66 
  67     framework->framework_refcnt++;
  68 
  69     if (mca_base_framework_is_registered (framework)) {
  70         return OPAL_SUCCESS;
  71     }
  72 
  73     OBJ_CONSTRUCT(&framework->framework_components, opal_list_t);
  74     OBJ_CONSTRUCT(&framework->framework_failed_components, opal_list_t);
  75 
  76     if (framework->framework_flags & MCA_BASE_FRAMEWORK_FLAG_NO_DSO) {
  77         flags |= MCA_BASE_REGISTER_STATIC_ONLY;
  78     }
  79 
  80     if (!(MCA_BASE_FRAMEWORK_FLAG_NOREGISTER & framework->framework_flags)) {
  81         /* register this framework with the MCA variable system */
  82         ret = mca_base_var_group_register (framework->framework_project,
  83                                            framework->framework_name,
  84                                            NULL, framework->framework_description);
  85         if (0 > ret) {
  86             return ret;
  87         }
  88 
  89         opal_asprintf (&desc, "Default selection set of components for the %s framework (<none>"
  90                   " means use all components that can be found)", framework->framework_name);
  91         ret = mca_base_var_register (framework->framework_project, framework->framework_name,
  92                                      NULL, NULL, desc, MCA_BASE_VAR_TYPE_STRING, NULL, 0,
  93                                      MCA_BASE_VAR_FLAG_SETTABLE, OPAL_INFO_LVL_2,
  94                                      MCA_BASE_VAR_SCOPE_ALL_EQ, &framework->framework_selection);
  95         free (desc);
  96         if (0 > ret) {
  97             return ret;
  98         }
  99 
 100         /* register a verbosity variable for this framework */
 101         ret = opal_asprintf (&desc, "Verbosity level for the %s framework (default: 0)",
 102                         framework->framework_name);
 103         if (0 > ret) {
 104             return OPAL_ERR_OUT_OF_RESOURCE;
 105         }
 106 
 107         framework->framework_verbose = MCA_BASE_VERBOSE_ERROR;
 108         ret = mca_base_framework_var_register (framework, "verbose", desc,
 109                                                MCA_BASE_VAR_TYPE_INT,
 110                                                &mca_base_var_enum_verbose, 0,
 111                                                MCA_BASE_VAR_FLAG_SETTABLE,
 112                                                OPAL_INFO_LVL_8,
 113                                                MCA_BASE_VAR_SCOPE_LOCAL,
 114                                                &framework->framework_verbose);
 115         free(desc);
 116         if (0 > ret) {
 117             return ret;
 118         }
 119 
 120         /* check the initial verbosity and open the output if necessary. we
 121            will recheck this on open */
 122         framework_open_output (framework);
 123 
 124         /* register framework variables */
 125         if (NULL != framework->framework_register) {
 126             ret = framework->framework_register (flags);
 127             if (OPAL_SUCCESS != ret) {
 128                 return ret;
 129             }
 130         }
 131 
 132         /* register components variables */
 133         ret = mca_base_framework_components_register (framework, flags);
 134         if (OPAL_SUCCESS != ret) {
 135             return ret;
 136         }
 137     }
 138 
 139     framework->framework_flags |= MCA_BASE_FRAMEWORK_FLAG_REGISTERED;
 140 
 141     /* framework did not provide a register function */
 142     return OPAL_SUCCESS;
 143 }
 144 
 145 int mca_base_framework_register_list (mca_base_framework_t **frameworks, mca_base_register_flag_t flags)
 146 {
 147     if (NULL == frameworks) {
 148         return OPAL_ERR_BAD_PARAM;
 149     }
 150 
 151     for (int i = 0 ; frameworks[i] ; ++i) {
 152         int ret = mca_base_framework_register (frameworks[i], flags);
 153         if (OPAL_UNLIKELY(OPAL_SUCCESS != ret && OPAL_ERR_NOT_AVAILABLE != ret)) {
 154             return ret;
 155         }
 156     }
 157 
 158     return OPAL_SUCCESS;
 159 }
 160 
 161 int mca_base_framework_open (struct mca_base_framework_t *framework,
 162                              mca_base_open_flag_t flags) {
 163     int ret;
 164 
 165     assert (NULL != framework);
 166 
 167     /* register this framework before opening it */
 168     ret = mca_base_framework_register (framework, MCA_BASE_REGISTER_DEFAULT);
 169     if (OPAL_SUCCESS != ret) {
 170         return ret;
 171     }
 172 
 173     /* check if this framework is already open */
 174     if (mca_base_framework_is_open (framework)) {
 175         return OPAL_SUCCESS;
 176     }
 177 
 178     if (MCA_BASE_FRAMEWORK_FLAG_NOREGISTER & framework->framework_flags) {
 179         flags |= MCA_BASE_OPEN_FIND_COMPONENTS;
 180 
 181         if (MCA_BASE_FRAMEWORK_FLAG_NO_DSO & framework->framework_flags) {
 182             flags |= MCA_BASE_OPEN_STATIC_ONLY;
 183         }
 184     }
 185 
 186     /* lock all of this frameworks's variables */
 187     ret = mca_base_var_group_find (framework->framework_project,
 188                                    framework->framework_name,
 189                                    NULL);
 190     mca_base_var_group_set_var_flag (ret, MCA_BASE_VAR_FLAG_SETTABLE, false);
 191 
 192     /* check the verbosity level and open (or close) the output */
 193     framework_open_output (framework);
 194 
 195     if (NULL != framework->framework_open) {
 196         ret = framework->framework_open (flags);
 197     } else {
 198         ret = mca_base_framework_components_open (framework, flags);
 199     }
 200 
 201     if (OPAL_SUCCESS != ret) {
 202         framework->framework_refcnt--;
 203     } else {
 204         framework->framework_flags |= MCA_BASE_FRAMEWORK_FLAG_OPEN;
 205     }
 206 
 207     return ret;
 208 }
 209 
 210 int mca_base_framework_open_list (mca_base_framework_t **frameworks, mca_base_open_flag_t flags)
 211 {
 212     if (NULL == frameworks) {
 213         return OPAL_ERR_BAD_PARAM;
 214     }
 215 
 216     for (int i = 0 ; frameworks[i] ; ++i) {
 217         int ret = mca_base_framework_open (frameworks[i], flags);
 218         if (OPAL_UNLIKELY(OPAL_SUCCESS != ret && OPAL_ERR_NOT_AVAILABLE != ret)) {
 219             return ret;
 220         }
 221     }
 222 
 223     return OPAL_SUCCESS;
 224 }
 225 
 226 int mca_base_framework_close (struct mca_base_framework_t *framework) {
 227     bool is_open = mca_base_framework_is_open (framework);
 228     bool is_registered = mca_base_framework_is_registered (framework);
 229     int ret, group_id;
 230 
 231     assert (NULL != framework);
 232 
 233     if (!(is_open || is_registered)) {
 234         return OPAL_SUCCESS;
 235     }
 236 
 237     assert (framework->framework_refcnt);
 238     if (--framework->framework_refcnt) {
 239         return OPAL_SUCCESS;
 240     }
 241 
 242     /* find and deregister all component groups and variables */
 243     group_id = mca_base_var_group_find (framework->framework_project,
 244                                         framework->framework_name, NULL);
 245     if (0 <= group_id) {
 246         (void) mca_base_var_group_deregister (group_id);
 247     }
 248 
 249     /* close the framework and all of its components */
 250     if (is_open) {
 251         if (NULL != framework->framework_close) {
 252             ret = framework->framework_close ();
 253         } else {
 254             ret = mca_base_framework_components_close (framework, NULL);
 255         }
 256 
 257         if (OPAL_SUCCESS != ret) {
 258             return ret;
 259         }
 260     } else {
 261         opal_list_item_t *item;
 262         while (NULL != (item = opal_list_remove_first (&framework->framework_components))) {
 263             mca_base_component_list_item_t *cli;
 264             cli = (mca_base_component_list_item_t*) item;
 265             mca_base_component_unload(cli->cli_component,
 266                                       framework->framework_output);
 267             OBJ_RELEASE(item);
 268         }
 269         while (NULL != (item = opal_list_remove_first (&framework->framework_failed_components))) {
 270             OBJ_RELEASE(item);
 271         }
 272         ret = OPAL_SUCCESS;
 273     }
 274 
 275     framework->framework_flags &= ~(MCA_BASE_FRAMEWORK_FLAG_REGISTERED | MCA_BASE_FRAMEWORK_FLAG_OPEN);
 276 
 277     OBJ_DESTRUCT(&framework->framework_components);
 278     OBJ_DESTRUCT(&framework->framework_failed_components);
 279 
 280     framework_close_output (framework);
 281 
 282     return ret;
 283 }
 284 
 285 int mca_base_framework_close_list (mca_base_framework_t **frameworks)
 286 {
 287     if (NULL == frameworks) {
 288         return OPAL_ERR_BAD_PARAM;
 289     }
 290 
 291     for (int i = 0 ; frameworks[i] ; ++i) {
 292         int ret = mca_base_framework_close (frameworks[i]);
 293         if (OPAL_UNLIKELY(OPAL_SUCCESS != ret)) {
 294             return ret;
 295         }
 296     }
 297 
 298     return OPAL_SUCCESS;
 299 }

/* [<][>][^][v][top][bottom][index][help] */