SaUint32T plms_quiesced_state_handler(SaInvocationT invocation) { PLMS_CB * cb = plms_cb; V_DEST_RL mds_role; /* Unregister with IMM as OI */ plms_proc_active_quiesced_role_change(); mds_role = V_DEST_RL_QUIESCED; TRACE_ENTER(); m_NCS_LOCK(&cb->cb_lock,NCS_LOCK_WRITE); /** set the CB's anchor value & mds role */ cb->mds_role = mds_role; plms_mds_change_role(); cb->amf_invocation_id = invocation; cb->is_quisced_set = true; LOG_IN("I AM IN HA AMF QUIESCED STATE\n"); m_NCS_UNLOCK(&cb->cb_lock,NCS_LOCK_WRITE); TRACE_LEAVE(); return NCSCC_RC_SUCCESS; }
/**************************************************************************** * Name : plms_amf_CSI_set_callback * * Description : AMF callback function called * when there is any change in the HA state. * * Arguments : invocation - This parameter designated a particular * invocation of this callback function. The * invoke process return invocation when it * responds to the Avilability Management * FrameWork using the saAmfResponse() * function. * compName - A pointer to the name of the component * whose readiness stae the Availability * Management Framework is setting. * haState - The new HA state to be assumeb by the * component service instance identified by * csiName. * csiDescriptor - This will indicate whether or not the * component service instance for * ativeCompName went through quiescing. * * Return Values : None. * * Notes : None. *****************************************************************************/ void plms_amf_CSI_set_callback(SaInvocationT invocation, const SaNameT *compName, SaAmfHAStateT new_haState, SaAmfCSIDescriptorT csiDescriptor) { PLMS_CB *cb = plms_cb; SaAisErrorT error = SA_AIS_OK; SaAmfHAStateT prev_haState; bool role_change = true; uint32_t rc = NCSCC_RC_SUCCESS; TRACE_ENTER(); m_NCS_LOCK(&cb->cb_lock,NCS_LOCK_WRITE); prev_haState = cb->ha_state; /* Invoke the appropriate state handler routine */ switch (new_haState) { case SA_AMF_HA_ACTIVE: cb->mds_role = V_DEST_RL_ACTIVE; TRACE("MY HA ROLE : AMF ACTIVE\n"); if (prev_haState == SA_AMF_HA_QUIESCED) { plms_proc_quiesced_active_role_change(); } else if (prev_haState == SA_AMF_HA_STANDBY) { plms_proc_standby_active_role_change(); } if(cb->hpi_cfg.hpi_support){ if (cb->hpi_intf_up == false) { TRACE("Got Active role, spawning HSM & HRB"); rc = plms_hsm_hrb_init(); if(NCSCC_RC_FAILURE == rc) { LOG_ER("hsm & hrb initialization failed"); error = SA_AIS_ERR_FAILED_OPERATION; goto response; } cb->hpi_intf_up = true; } if (prev_haState == SA_AMF_HA_STANDBY) { /* Build entity_path_to_entity mapping tree */ rc = plms_build_epath_to_entity_map_tree(); if( NCSCC_RC_SUCCESS != rc ){ LOG_ER("Failed to build entity_path_to_entity mapping tree"); error = SA_AIS_ERR_FAILED_OPERATION; goto response; } } } if( cb->hpi_intf_up ) { TRACE("PLMS sending Active role to HSM"); pthread_mutex_lock(&hsm_ha_state.mutex); hsm_ha_state.state = V_DEST_RL_ACTIVE; pthread_cond_signal(&hsm_ha_state.cond); pthread_mutex_unlock(&hsm_ha_state.mutex); TRACE("PLMS sending Active role to HRB"); pthread_mutex_lock(&hrb_ha_state.mutex); hrb_ha_state.state = SA_AMF_HA_ACTIVE; pthread_cond_signal(&hrb_ha_state.cond); pthread_mutex_unlock(&hrb_ha_state.mutex); } /* PLMC initialize */ if(!cb->hpi_cfg.hpi_support && !cb->plmc_initialized){ TRACE("Initializing PLMC"); rc = plmc_initialize(plms_plmc_connect_cbk, plms_plmc_udp_cbk, plms_plmc_error_cbk); if (rc){ LOG_ER("PLMC initialize failed."); rc = NCSCC_RC_FAILURE; goto response; } TRACE("PLMC initialize success."); cb->plmc_initialized = true; } cb->mds_role = V_DEST_RL_ACTIVE; break; case SA_AMF_HA_STANDBY: cb->mds_role = V_DEST_RL_STANDBY; LOG_IN("MY HA ROLE : AMF STANDBY\n"); TRACE("Send signal to HSM indicating standby state"); pthread_mutex_lock(&hsm_ha_state.mutex); hsm_ha_state.state = SA_AMF_HA_STANDBY; pthread_mutex_unlock(&hsm_ha_state.mutex); TRACE("Send signal to HRB indicating standby state"); pthread_mutex_lock(&hrb_ha_state.mutex); hrb_ha_state.state = SA_AMF_HA_STANDBY; pthread_mutex_unlock(&hrb_ha_state.mutex); SaUint32T (* hsm_func_ptr)() = NULL; if(cb->hpi_cfg.hpi_support){ /* Get the hsm Init func ptr */ hsm_func_ptr = dlsym(cb->hpi_intf_hdl, "plms_hsm_session_close"); if ( NULL == hsm_func_ptr ) { LOG_ER("dlsym() failed to get the hsm_func_ptr,error %s", dlerror()); goto response; } /* Initialize HSM */ rc = (* hsm_func_ptr)(); if ( NCSCC_RC_SUCCESS != rc ) { LOG_ER("plms_session_close failed"); goto response; } } /* PLMC finalize */ if(cb->plmc_initialized){ rc = plmc_destroy(); if (rc){ LOG_ER("PLMC destroy failed."); rc = NCSCC_RC_FAILURE; } cb->plmc_initialized = false; } if (prev_haState == SA_AMF_HA_QUIESCED) { plms_proc_quiesced_standby_role_change(); } break; case SA_AMF_HA_QUIESCED: plms_quiesced_state_handler(invocation); break; case SA_AMF_HA_QUIESCING: plms_quiescing_state_handler(invocation); break; default: LOG_IN("INVALID HA AMF STATE\n"); plms_invalid_state_handler(invocation); } if (new_haState == SA_AMF_HA_QUIESCED) return; /* Update control block */ cb->ha_state = new_haState; if (cb->csi_assigned == false) { cb->csi_assigned = true; /* We shall open checkpoint only once in our life time. currently doing at lib init */ } else if ((new_haState == SA_AMF_HA_ACTIVE) || (new_haState == SA_AMF_HA_STANDBY)) { /* It is a switch over */ /* check if this step is required */ /* cb->ckpt_state = COLD_SYNC_IDLE; */ } if ((prev_haState == SA_AMF_HA_ACTIVE) && (new_haState == SA_AMF_HA_ACTIVE)) { role_change = false; } if ((prev_haState == SA_AMF_HA_STANDBY) && (new_haState == SA_AMF_HA_STANDBY)) { role_change = false; } if (role_change == true) { if ((rc = plms_mds_change_role()) != NCSCC_RC_SUCCESS) { LOG_ER("plms_mds_change_role FAILED"); error = SA_AIS_ERR_FAILED_OPERATION; goto response; } else { if (cb->ha_state == SA_AMF_HA_ACTIVE) { /* FIXME: Is there any overhead to be done on New Active */ // if (plms_imm_declare_implementer(cb->immOiHandle) != SA_AIS_OK) // printf("ClassImplementer Set Failed\n"); } if (cb->ha_state == SA_AMF_HA_STANDBY) { /* FIXME : Do the over head processing needed to be done for standby state */ } } TRACE_5("Inform MBCSV of HA state change to %s", (new_haState == SA_AMF_HA_ACTIVE) ? "ACTIVE" : "STANDBY"); if (plms_mbcsv_chgrole() != NCSCC_RC_SUCCESS) { LOG_ER("Failed to change role"); error = SA_AIS_ERR_FAILED_OPERATION; goto response; } } response: /* Send the response to AMF */ saAmfResponse(cb->amf_hdl, invocation, error); m_NCS_UNLOCK(&cb->cb_lock,NCS_LOCK_WRITE); TRACE_LEAVE(); } /* End of PLMS CSI Set callback */
/**************************************************************************** Name : plms_mds_register Description : This routine registers the PLMS Service with MDS. Arguments : NULL Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE Notes : None. ****************************************************************************/ SaUint32T plms_mds_register() { uns32 rc = NCSCC_RC_SUCCESS; NCSMDS_INFO svc_info; MDS_SVC_ID svc_id[1] = { NCSMDS_SVC_ID_PLMA }; MDS_SVC_ID plms_id[1] = { NCSMDS_SVC_ID_PLMS }; MDS_SVC_ID plms_hrb_id[1] = { NCSMDS_SVC_ID_PLMS_HRB }; PLMS_CB *cb = plms_cb; TRACE_ENTER(); /* Create the virtual Destination for PLMS */ rc = plms_mds_vdest_create(); if (NCSCC_RC_SUCCESS != rc) { LOG_ER("PLMS - VDEST CREATE FAILED"); return rc; } /* Set the role of MDS */ if (cb->ha_state == SA_AMF_HA_ACTIVE) { TRACE_5("Set MDS role to ACTIVE"); cb->mds_role = V_DEST_RL_ACTIVE; } else if (cb->ha_state == SA_AMF_HA_STANDBY) { TRACE_5("Set MDS role to STANDBY"); cb->mds_role = V_DEST_RL_STANDBY; } else { TRACE_5("Could not set MDS role"); } if (NCSCC_RC_SUCCESS != (rc = plms_mds_change_role())) { LOG_ER("MDS role change to %d FAILED", cb->mds_role); return rc; } memset(&svc_info, 0, sizeof(NCSMDS_INFO)); /* STEP 2 : Install with MDS with service ID NCSMDS_SVC_ID_PLMS. */ svc_info.i_mds_hdl = cb->mds_hdl; svc_info.i_svc_id = NCSMDS_SVC_ID_PLMS; svc_info.i_op = MDS_INSTALL; svc_info.info.svc_install.i_yr_svc_hdl = 0; svc_info.info.svc_install.i_install_scope = NCSMDS_SCOPE_NONE; /*node specific */ svc_info.info.svc_install.i_svc_cb = plms_mds_callback; /* callback */ svc_info.info.svc_install.i_mds_q_ownership = FALSE; svc_info.info.svc_install.i_mds_svc_pvt_ver = PLMS_MDS_PVT_SUBPART_VERSION; if (ncsmds_api(&svc_info) == NCSCC_RC_FAILURE) { LOG_ER("PLMS - MDS Install Failed"); return NCSCC_RC_FAILURE; } /* STEP 3: Subscribe to PLMS for redundancy events */ memset(&svc_info, 0, sizeof(NCSMDS_INFO)); svc_info.i_mds_hdl = cb->mds_hdl; svc_info.i_svc_id = NCSMDS_SVC_ID_PLMS; svc_info.i_op = MDS_RED_SUBSCRIBE; svc_info.info.svc_subscribe.i_num_svcs = 1; svc_info.info.svc_subscribe.i_scope = NCSMDS_SCOPE_NONE; svc_info.info.svc_subscribe.i_svc_ids = plms_id; if (ncsmds_api(&svc_info) == NCSCC_RC_FAILURE) { LOG_ER("PLMS - MDS Subscribe for redundancy Failed"); plms_mds_unregister(); return NCSCC_RC_FAILURE; } /* STEP 4: Subscribe to PLMA up/down events */ memset(&svc_info, 0, sizeof(NCSMDS_INFO)); svc_info.i_mds_hdl = cb->mds_hdl; svc_info.i_svc_id = NCSMDS_SVC_ID_PLMS; svc_info.i_op = MDS_SUBSCRIBE; svc_info.info.svc_subscribe.i_num_svcs = 1; svc_info.info.svc_subscribe.i_scope = NCSMDS_SCOPE_NONE; svc_info.info.svc_subscribe.i_svc_ids = svc_id; if (ncsmds_api(&svc_info) == NCSCC_RC_FAILURE) { LOG_ER("PLMS - MDS Subscribe for PLMA up/down Failed"); plms_mds_unregister(); return NCSCC_RC_FAILURE; } /* STEP 5: Subscribe to HRB up/down events */ memset(&svc_info, 0, sizeof(NCSMDS_INFO)); svc_info.i_mds_hdl = cb->mds_hdl; svc_info.i_svc_id = NCSMDS_SVC_ID_PLMS; svc_info.i_op = MDS_SUBSCRIBE; svc_info.info.svc_subscribe.i_num_svcs = 1; svc_info.info.svc_subscribe.i_scope = NCSMDS_SCOPE_NONE; svc_info.info.svc_subscribe.i_svc_ids = plms_hrb_id; if (ncsmds_api(&svc_info) == NCSCC_RC_FAILURE) { LOG_ER("PLMS - MDS Subscribe for PLMS_HRB up/down Failed"); plms_mds_unregister(); return NCSCC_RC_FAILURE; } /* Get the node id of local PLMS */ cb->node_id = m_NCS_GET_NODE_ID; cb->plms_self_id = plms_get_slot_and_subslot_id_from_node_id(cb->node_id); TRACE_5("NodeId:%x SelfId:%x", cb->node_id, cb->plms_self_id); TRACE_LEAVE(); return NCSCC_RC_SUCCESS; }