osaf/services/saf/amf/amfd/avd.cc | 201 ------------------------------- osaf/services/saf/amf/amfd/avd_proc.cc | 209 ++++++++++++++++++++++++++++++++- 2 files changed, 207 insertions(+), 203 deletions(-)
diff --git a/osaf/services/saf/amf/amfd/avd.cc b/osaf/services/saf/amf/amfd/avd.cc --- a/osaf/services/saf/amf/amfd/avd.cc +++ b/osaf/services/saf/amf/amfd/avd.cc @@ -57,204 +57,3 @@ #include <avd_sutype.h> #include <avd_si_dep.h> -/* -** The singleton AVD Cluster Control Block. Statically allocated which is -** good for debugging core dumps -*/ -static AVD_CL_CB _avd_cb; - -/* A handy global reference to the control block */ -AVD_CL_CB *avd_cb = &_avd_cb; - -/** - * Callback from RDA. Post a message to the AVD mailbox. - * @param notused - * @param cb_info - * @param error_code - */ -static void rda_cb(uint32_t notused, PCS_RDA_CB_INFO *cb_info, PCSRDA_RETURN_CODE error_code) -{ - (void) notused; - - TRACE_ENTER(); - - if (((avd_cb->avail_state_avd == SA_AMF_HA_STANDBY) || - (avd_cb->avail_state_avd == SA_AMF_HA_QUIESCED)) && - (cb_info->info.io_role == PCS_RDA_ACTIVE)) { - - uint32_t rc; - AVD_EVT *evt; - - evt = static_cast<AVD_EVT*>(malloc(sizeof(AVD_EVT))); - if (evt == NULL) { - LOG_ER("malloc failed"); - osafassert(0); - } - evt->rcv_evt = AVD_EVT_ROLE_CHANGE; - evt->info.avd_msg = static_cast<AVD_D2D_MSG*>(malloc(sizeof(AVD_D2D_MSG))); - if (evt->info.avd_msg == NULL) { - LOG_ER("malloc failed"); - osafassert(0); - } - evt->info.avd_msg->msg_type = AVD_D2D_CHANGE_ROLE_REQ; - evt->info.avd_msg->msg_info.d2d_chg_role_req.cause = AVD_FAIL_OVER; - evt->info.avd_msg->msg_info.d2d_chg_role_req.role = (SaAmfHAStateT) cb_info->info.io_role; - - rc = ncs_ipc_send(&avd_cb->avd_mbx, (NCS_IPC_MSG *)evt, (NCS_IPC_PRIORITY) MDS_SEND_PRIORITY_HIGH); - osafassert(rc == NCSCC_RC_SUCCESS); - } else - TRACE("Ignoring change from %u to %u", avd_cb->avail_state_avd, cb_info->info.io_role); - - TRACE_LEAVE(); -} - -/** - * Initialize everything... - * - * @return uint32_t NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE - */ -uint32_t avd_initialize(void) -{ - AVD_CL_CB *cb = avd_cb; - NCS_PATRICIA_PARAMS patricia_params = {0}; - int rc = NCSCC_RC_FAILURE; - SaVersionT ntfVersion = { 'A', 0x01, 0x01 }; - SaAmfHAStateT role; - char *val; - - TRACE_ENTER(); - - /* run the class constructors */ - avd_apptype_constructor(); - avd_app_constructor(); - avd_compglobalattrs_constructor(); - avd_compcstype_constructor(); - avd_comp_constructor(); - avd_ctcstype_constructor(); - avd_comptype_constructor(); - avd_cluster_constructor(); - avd_cstype_constructor(); - avd_csi_constructor(); - avd_csiattr_constructor(); - avd_hctype_constructor(); - avd_hc_constructor(); - avd_node_constructor(); - avd_ng_constructor(); - avd_nodeswbundle_constructor(); - avd_sgtype_constructor(); - avd_sg_constructor(); - avd_svctypecstypes_constructor(); - avd_svctype_constructor(); - avd_si_constructor(); - avd_sirankedsu_constructor(); - avd_sidep_constructor(); - avd_sutcomptype_constructor(); - avd_su_constructor(); - avd_sutype_constructor(); - - if (ncs_ipc_create(&cb->avd_mbx) != NCSCC_RC_SUCCESS) { - LOG_ER("ncs_ipc_create FAILED"); - goto done; - } - - if (ncs_ipc_attach(&cb->avd_mbx) != NCSCC_RC_SUCCESS) { - LOG_ER("ncs_ipc_attach FAILED"); - goto done; - } - - cb->init_state = AVD_INIT_BGN; - cb->swap_switch = SA_FALSE; - cb->active_services_exist = true; - cb->stby_sync_state = AVD_STBY_IN_SYNC; - cb->sync_required = true; - - cb->heartbeat_tmr.is_active = false; - cb->heartbeat_tmr.type = AVD_TMR_SND_HB; - cb->heartbeat_tmr_period = AVSV_DEF_HB_PERIOD; - - if ((val = getenv("AVSV_HB_PERIOD")) != NULL) { - cb->heartbeat_tmr_period = strtoll(val, NULL, 0); - if (cb->heartbeat_tmr_period == 0) { - /* no value or non convertable value, revert to default */ - cb->heartbeat_tmr_period = AVSV_DEF_HB_PERIOD; - } - } - - patricia_params.key_size = sizeof(SaClmNodeIdT); - if (ncs_patricia_tree_init(&cb->node_list, &patricia_params) != NCSCC_RC_SUCCESS) { - LOG_ER("ncs_patricia_tree_init FAILED"); - goto done; - } - - /* get the node id of the node on which the AVD is running. */ - cb->node_id_avd = m_NCS_GET_NODE_ID; - - if (avd_mds_init(cb) != NCSCC_RC_SUCCESS) { - LOG_ER("avd_mds_init FAILED"); - goto done; - } - - if (NCSCC_RC_FAILURE == avsv_mbcsv_register(cb)) { - LOG_ER("avsv_mbcsv_register FAILED"); - goto done; - } - - if (avd_clm_init() != SA_AIS_OK) { - LOG_EM("avd_clm_init FAILED"); - goto done; - } - - if (avd_imm_init(cb) != SA_AIS_OK) { - LOG_ER("avd_imm_init FAILED"); - goto done; - } - - if ((rc = saNtfInitialize(&cb->ntfHandle, NULL, &ntfVersion)) != SA_AIS_OK) { - LOG_ER("saNtfInitialize Failed (%u)", rc); - rc = NCSCC_RC_FAILURE; - goto done; - } - - if ((rc = rda_get_role(&role)) != NCSCC_RC_SUCCESS) { - LOG_ER("rda_get_role FAILED"); - goto done; - } - - cb->avail_state_avd = role; - - if (NCSCC_RC_SUCCESS != avd_mds_set_vdest_role(cb, role)) { - LOG_ER("avd_mds_set_vdest_role FAILED"); - goto done; - } - - if (NCSCC_RC_SUCCESS != avsv_set_ckpt_role(cb, role)) { - LOG_ER("avsv_set_ckpt_role FAILED"); - goto done; - } - - if ((rc = rda_register_callback(0, rda_cb)) != NCSCC_RC_SUCCESS) { - LOG_ER("rda_register_callback FAILED %u", rc); - goto done; - } - - if (role == SA_AMF_HA_ACTIVE) { - rc = avd_active_role_initialization(cb, role); - if (rc != NCSCC_RC_SUCCESS) { - LOG_ER("avd_active_role_initialization FAILED"); - goto done; - } - } - else { - rc = avd_standby_role_initialization(cb); - if (rc != NCSCC_RC_SUCCESS) { - LOG_ER("avd_standby_role_initialization FAILED"); - goto done; - } - } - - rc = NCSCC_RC_SUCCESS; -done: - TRACE_LEAVE(); - return rc; -} - diff --git a/osaf/services/saf/amf/amfd/avd_proc.cc b/osaf/services/saf/amf/amfd/avd_proc.cc --- a/osaf/services/saf/amf/amfd/avd_proc.cc +++ b/osaf/services/saf/amf/amfd/avd_proc.cc @@ -25,13 +25,20 @@ */ #include <poll.h> + #include <daemon.h> #include <logtrace.h> #include <nid_api.h> +#include <rda_papi.h> + #include <avd.h> #include <avd_imm.h> #include <avd_cluster.h> #include <avd_si_dep.h> +#include <avd_hlt.h> +#include <avd_clm.h> +#include <avd_su.h> +#include <avd_sutype.h> enum { FD_TERM = 0, @@ -41,6 +48,12 @@ enum { FD_IMM }; +// Singleton Control Block. Statically allocated +static AVD_CL_CB _control_block; + +// Global reference to the control block +AVD_CL_CB *avd_cb = &_control_block; + static nfds_t nfds = FD_IMM + 1; static struct pollfd fds[FD_IMM + 1]; @@ -415,6 +428,198 @@ static void handle_event_in_failover_sta TRACE_LEAVE(); } +/** + * Callback from RDA. Post a message to the AVD mailbox. + * @param notused + * @param cb_info + * @param error_code + */ +static void rda_cb(uint32_t notused, PCS_RDA_CB_INFO *cb_info, PCSRDA_RETURN_CODE error_code) +{ + (void) notused; + + TRACE_ENTER(); + + if (((avd_cb->avail_state_avd == SA_AMF_HA_STANDBY) || + (avd_cb->avail_state_avd == SA_AMF_HA_QUIESCED)) && + (cb_info->info.io_role == PCS_RDA_ACTIVE)) { + + uint32_t rc; + AVD_EVT *evt; + + evt = static_cast<AVD_EVT*>(malloc(sizeof(AVD_EVT))); + if (evt == NULL) { + LOG_ER("malloc failed"); + osafassert(0); + } + evt->rcv_evt = AVD_EVT_ROLE_CHANGE; + evt->info.avd_msg = static_cast<AVD_D2D_MSG*>(malloc(sizeof(AVD_D2D_MSG))); + if (evt->info.avd_msg == NULL) { + LOG_ER("malloc failed"); + osafassert(0); + } + evt->info.avd_msg->msg_type = AVD_D2D_CHANGE_ROLE_REQ; + evt->info.avd_msg->msg_info.d2d_chg_role_req.cause = AVD_FAIL_OVER; + evt->info.avd_msg->msg_info.d2d_chg_role_req.role = (SaAmfHAStateT) cb_info->info.io_role; + + rc = ncs_ipc_send(&avd_cb->avd_mbx, (NCS_IPC_MSG *)evt, (NCS_IPC_PRIORITY) MDS_SEND_PRIORITY_HIGH); + osafassert(rc == NCSCC_RC_SUCCESS); + } else + TRACE("Ignoring change from %u to %u", avd_cb->avail_state_avd, cb_info->info.io_role); + + TRACE_LEAVE(); +} + +/** + * Initialize everything... + * + * @return uint32_t NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE + */ +static uint32_t initialize(void) +{ + AVD_CL_CB *cb = avd_cb; + NCS_PATRICIA_PARAMS patricia_params = {0}; + int rc = NCSCC_RC_FAILURE; + SaVersionT ntfVersion = { 'A', 0x01, 0x01 }; + SaAmfHAStateT role; + char *val; + + TRACE_ENTER(); + + /* run the class constructors */ + avd_apptype_constructor(); + avd_app_constructor(); + avd_compglobalattrs_constructor(); + avd_compcstype_constructor(); + avd_comp_constructor(); + avd_ctcstype_constructor(); + avd_comptype_constructor(); + avd_cluster_constructor(); + avd_cstype_constructor(); + avd_csi_constructor(); + avd_csiattr_constructor(); + avd_hctype_constructor(); + avd_hc_constructor(); + avd_node_constructor(); + avd_ng_constructor(); + avd_nodeswbundle_constructor(); + avd_sgtype_constructor(); + avd_sg_constructor(); + avd_svctypecstypes_constructor(); + avd_svctype_constructor(); + avd_si_constructor(); + avd_sirankedsu_constructor(); + avd_sidep_constructor(); + avd_sutcomptype_constructor(); + avd_su_constructor(); + avd_sutype_constructor(); + + if (ncs_ipc_create(&cb->avd_mbx) != NCSCC_RC_SUCCESS) { + LOG_ER("ncs_ipc_create FAILED"); + goto done; + } + + if (ncs_ipc_attach(&cb->avd_mbx) != NCSCC_RC_SUCCESS) { + LOG_ER("ncs_ipc_attach FAILED"); + goto done; + } + + cb->init_state = AVD_INIT_BGN; + cb->swap_switch = SA_FALSE; + cb->active_services_exist = true; + cb->stby_sync_state = AVD_STBY_IN_SYNC; + cb->sync_required = true; + + cb->heartbeat_tmr.is_active = false; + cb->heartbeat_tmr.type = AVD_TMR_SND_HB; + cb->heartbeat_tmr_period = AVSV_DEF_HB_PERIOD; + + if ((val = getenv("AVSV_HB_PERIOD")) != NULL) { + cb->heartbeat_tmr_period = strtoll(val, NULL, 0); + if (cb->heartbeat_tmr_period == 0) { + /* no value or non convertable value, revert to default */ + cb->heartbeat_tmr_period = AVSV_DEF_HB_PERIOD; + } + } + + patricia_params.key_size = sizeof(SaClmNodeIdT); + if (ncs_patricia_tree_init(&cb->node_list, &patricia_params) != NCSCC_RC_SUCCESS) { + LOG_ER("ncs_patricia_tree_init FAILED"); + goto done; + } + + /* get the node id of the node on which the AVD is running. */ + cb->node_id_avd = m_NCS_GET_NODE_ID; + + if (avd_mds_init(cb) != NCSCC_RC_SUCCESS) { + LOG_ER("avd_mds_init FAILED"); + goto done; + } + + if (NCSCC_RC_FAILURE == avsv_mbcsv_register(cb)) { + LOG_ER("avsv_mbcsv_register FAILED"); + goto done; + } + + if (avd_clm_init() != SA_AIS_OK) { + LOG_EM("avd_clm_init FAILED"); + goto done; + } + + if (avd_imm_init(cb) != SA_AIS_OK) { + LOG_ER("avd_imm_init FAILED"); + goto done; + } + + if ((rc = saNtfInitialize(&cb->ntfHandle, NULL, &ntfVersion)) != SA_AIS_OK) { + LOG_ER("saNtfInitialize Failed (%u)", rc); + rc = NCSCC_RC_FAILURE; + goto done; + } + + if ((rc = rda_get_role(&role)) != NCSCC_RC_SUCCESS) { + LOG_ER("rda_get_role FAILED"); + goto done; + } + + cb->avail_state_avd = role; + + if (NCSCC_RC_SUCCESS != avd_mds_set_vdest_role(cb, role)) { + LOG_ER("avd_mds_set_vdest_role FAILED"); + goto done; + } + + if (NCSCC_RC_SUCCESS != avsv_set_ckpt_role(cb, role)) { + LOG_ER("avsv_set_ckpt_role FAILED"); + goto done; + } + + if ((rc = rda_register_callback(0, rda_cb)) != NCSCC_RC_SUCCESS) { + LOG_ER("rda_register_callback FAILED %u", rc); + goto done; + } + + if (role == SA_AMF_HA_ACTIVE) { + rc = avd_active_role_initialization(cb, role); + if (rc != NCSCC_RC_SUCCESS) { + LOG_ER("avd_active_role_initialization FAILED"); + goto done; + } + } + else { + rc = avd_standby_role_initialization(cb); + if (rc != NCSCC_RC_SUCCESS) { + LOG_ER("avd_standby_role_initialization FAILED"); + goto done; + } + } + + rc = NCSCC_RC_SUCCESS; +done: + TRACE_LEAVE(); + return rc; +} + /***************************************************************************** * Function: avd_main_proc * @@ -440,8 +645,8 @@ void avd_main_proc(void) int polltmo = -1; int term_fd; - if (avd_initialize() != NCSCC_RC_SUCCESS) { - LOG_ER("main: avd_initialize FAILED, exiting..."); + if (initialize() != NCSCC_RC_SUCCESS) { + LOG_ER("main: initialize FAILED, exiting..."); (void) nid_notify(const_cast<char*>("AMFD"), NCSCC_RC_FAILURE, NULL); exit(EXIT_FAILURE); } ------------------------------------------------------------------------------ Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! Discover the easy way to master current and previous Microsoft technologies and advance your career. Get an incredible 1,500+ hours of step-by-step tutorial videos with LearnDevNow. Subscribe today and save! http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel