"Fossies" - the Fresh Open Source Software Archive

Member "opensaf-5.21.09/src/clm/clmnd/amf.cc" (31 May 2021, 7144 Bytes) of package /linux/misc/opensaf-5.21.09.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "amf.cc" see the Fossies "Dox" file reference documentation.

    1 /*      -*- OpenSAF  -*-
    2  *
    3  * (C) Copyright 2010 The OpenSAF Foundation
    4  *
    5  * This program is distributed in the hope that it will be useful, but
    6  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    7  * or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed
    8  * under the GNU Lesser General Public License Version 2.1, February 1999.
    9  * The complete license can be accessed from the following location:
   10  * http://opensource.org/licenses/lgpl-license.php
   11  * See the Copying file included with the OpenSAF distribution for full
   12  * licensing terms.
   13  *
   14  * Author(s):  GoAhead Software
   15  *
   16  */
   17 
   18 #include "clm/clmnd/clmna.h"
   19 #include "nid/agent/nid_start_util.h"
   20 
   21 /*
   22  * This is the callback function which will be called when the AMF
   23  * health checksfor the component.
   24  *
   25  * @param invocation - Designates a particular invocation.
   26  * @param compName       - A pointer to the name of the component
   27  * whose readiness stae the AMF  is setting.
   28  * @param checkType      - The type of healthcheck to be executed.
   29  */
   30 static void clmna_amf_health_chk_callback(SaInvocationT invocation,
   31                                           const SaNameT *compName,
   32                                           SaAmfHealthcheckKeyT *checkType) {
   33   saAmfResponse(clmna_cb->amf_hdl, invocation, SA_AIS_OK);
   34 }
   35 
   36 /*
   37  * The AMF callback function called when there is any
   38  * change in the HA state.
   39  * @param invocation - This parameter designated a particular invocation of
   40  * this callback function. The invoke process return invocation when it
   41  * responds to the AMF using the saAmfResponse() function.
   42  * @compName - A pointer to the name of the component whose readiness state
   43  * the AMF is setting.
   44  * @param haState - The new HA state to be assumed by the CSI identified by
   45  * csiName.
   46  * @csiDescriptor - This will indicate whether or not the CSI for
   47  * ativeCompName went through quiescing.
   48  */
   49 static void clmna_amf_csi_set_callback(SaInvocationT invocation,
   50                                        const SaNameT *compName,
   51                                        SaAmfHAStateT haState,
   52                                        SaAmfCSIDescriptorT csiDescriptor) {
   53   SaAisErrorT error = SA_AIS_OK;
   54   TRACE_ENTER();
   55 
   56   /* Update control block */
   57   clmna_cb->ha_state = haState;
   58 
   59   saAmfResponse(clmna_cb->amf_hdl, invocation, error);
   60   TRACE_LEAVE();
   61 }
   62 
   63 /*
   64  * This is the callback function which will be called
   65  * when the AMF framework needs to terminate CLMS. This does
   66  * all required to destroy CLMS(except to unregister from AMF)
   67  *
   68  * @invocation - This parameter designated a particular
   69  * invocation of this callback function. The invoke process return
   70  * invocation when it responds to the AMF using the saAmfResponse()
   71  * function.
   72  * @compName - A pointer to the name of the component whose readiness
   73  * state the AMF is setting.
   74  */
   75 void clmna_amf_comp_terminate_callback(SaInvocationT invocation,
   76                                        const SaNameT *compName) {
   77   TRACE_ENTER();
   78 
   79   saAmfResponse(clmna_cb->amf_hdl, invocation, SA_AIS_OK);
   80 
   81   /* Detach from IPC */
   82   m_NCS_IPC_DETACH(&clmna_cb->mbx, nullptr, clmna_cb);
   83 
   84   TRACE_LEAVE();
   85   LOG_NO("Received AMF component terminate callback, exiting");
   86   _Exit(EXIT_SUCCESS);
   87 }
   88 
   89 /*
   90  * This callback routine is invoked by AMF during a CSI set removal operation.
   91  *
   92  * @param invocation - This parameter designated a particular invocation of
   93  * this callback function. The invoke process return invocation when it
   94  * responds to the AMF FrameWork using the saAmfResponse() function.
   95  * @param compName - A pointer to the name of the component whose readiness
   96  * state the AMF is setting.
   97  * @csiName        - A const pointer to csiName i
   98  * @csiFlags       - csi Flags
   99  */
  100 void clmna_amf_csi_rmv_callback(SaInvocationT invocation,
  101                                 const SaNameT *compName, const SaNameT *csiName,
  102                                 const SaAmfCSIFlagsT csiFlags) {
  103   TRACE_ENTER();
  104 
  105   saAmfResponse(clmna_cb->amf_hdl, invocation, SA_AIS_OK);
  106 
  107   TRACE_LEAVE();
  108 }
  109 
  110 /*
  111  * Function to start the health checking with AMF
  112  * @param:  CLMNA_CB - Control Block
  113  * @return: SaAisErrorT
  114  */
  115 SaAisErrorT clmna_amf_healthcheck_start(CLMNA_CB *clmna_cb) {
  116   SaAisErrorT error;
  117   SaAmfHealthcheckKeyT healthy;
  118   char *health_key;
  119 
  120   TRACE_ENTER();
  121 
  122   /** start the AMF health check **/
  123   memset(&healthy, 0, sizeof(healthy));
  124   health_key = getenv("CLMNA_ENV_HEALTHCHECK_KEY");
  125 
  126   if (health_key == nullptr)
  127     strcpy((char *)healthy.key, "Default");
  128   else {
  129     if (strlen(health_key) > SA_AMF_HEALTHCHECK_KEY_MAX) {
  130       LOG_ER("amf_healthcheck_start(): Helthcheck key to long");
  131       return SA_AIS_ERR_NAME_TOO_LONG;
  132     }
  133     strcpy((char *)healthy.key, health_key);
  134   }
  135 
  136   healthy.keyLen = strlen((char *)healthy.key);
  137 
  138   error = saAmfHealthcheckStart(clmna_cb->amf_hdl, &clmna_cb->comp_name,
  139                                 &healthy, SA_AMF_HEALTHCHECK_AMF_INVOKED,
  140                                 SA_AMF_COMPONENT_FAILOVER);
  141 
  142   if (error != SA_AIS_OK) LOG_ER("saAmfHealthcheckStart FAILED: %u", error);
  143 
  144   TRACE_LEAVE();
  145   return error;
  146 }
  147 
  148 /*
  149  * Initializes and registers with AMF.
  150  * @param: control block to CLMNA
  151  * @return : SaAisErrorT
  152  */
  153 
  154 SaAisErrorT clmna_amf_init(CLMNA_CB *cb) {
  155   SaAmfCallbacksT amfCallbacks;
  156   SaVersionT amf_version;
  157   SaAisErrorT error = SA_AIS_OK;
  158 
  159   TRACE_ENTER();
  160 
  161   if (cb->nid_started &&
  162       amf_comp_name_get_set_from_file("CLMNA_COMP_NAME_FILE", &cb->comp_name) !=
  163           NCSCC_RC_SUCCESS)
  164     goto done;
  165 
  166   /* Initialize AMF callbacks */
  167   memset(&amfCallbacks, 0, sizeof(SaAmfCallbacksT));
  168   amfCallbacks.saAmfHealthcheckCallback = clmna_amf_health_chk_callback;
  169   amfCallbacks.saAmfCSISetCallback = clmna_amf_csi_set_callback;
  170   amfCallbacks.saAmfComponentTerminateCallback =
  171       clmna_amf_comp_terminate_callback;
  172   amfCallbacks.saAmfCSIRemoveCallback = clmna_amf_csi_rmv_callback;
  173 
  174   amf_version.releaseCode = 'B';
  175   amf_version.majorVersion = 0x01;
  176   amf_version.minorVersion = 0x01;
  177 
  178   /* Initialize the AMF library */
  179   error = saAmfInitialize(&cb->amf_hdl, &amfCallbacks, &amf_version);
  180   if (error != SA_AIS_OK) {
  181     LOG_ER("saAmfInitialize() FAILED: %u", error);
  182     goto done;
  183   }
  184 
  185   /* Obtain the AMF selection object to wait for AMF events */
  186   error = saAmfSelectionObjectGet(cb->amf_hdl, &cb->amf_sel_obj);
  187   if (error != SA_AIS_OK) {
  188     LOG_ER("saAmfSelectionObjectGet() FAILED: %u", error);
  189     goto done;
  190   }
  191 
  192   /* Get the component name */
  193   error = saAmfComponentNameGet(cb->amf_hdl, &cb->comp_name);
  194   if (error != SA_AIS_OK) {
  195     LOG_ER("saAmfComponentNameGet() FAILED: %u", error);
  196     goto done;
  197   }
  198 
  199   /* Register component with AMF */
  200   error = saAmfComponentRegister(cb->amf_hdl, &cb->comp_name,
  201                                  static_cast<SaNameT *>(nullptr));
  202   if (error != SA_AIS_OK) {
  203     LOG_ER("saAmfComponentRegister() FAILED: %u", error);
  204     goto done;
  205   }
  206 
  207   /* Start AMF healthchecks */
  208   if ((error = clmna_amf_healthcheck_start(cb)) != SA_AIS_OK) {
  209     LOG_ER("clmna_amf_healthcheck_start() FAILED: %u", error);
  210     goto done;
  211   }
  212 
  213 done:
  214   TRACE_LEAVE();
  215   return error;
  216 }