bool sysfTmrCreate(void) { NCS_PATRICIA_PARAMS pat_param; uint32_t rc = NCSCC_RC_SUCCESS; if (ncs_tmr_create_done == false) ncs_tmr_create_done = true; else return true; /* Empty Timer Service control block. */ memset(&gl_tcb, '\0', sizeof(SYSF_TMR_CB)); /* put local persistent guard in start state */ ncslpg_create(&gl_tcb.persist); /* Initialize the locks */ m_NCS_LOCK_INIT(&gl_tcb.safe.enter_lock); m_NCS_LOCK_INIT(&gl_tcb.safe.free_lock); memset((void *)&pat_param, 0, sizeof(NCS_PATRICIA_PARAMS)); pat_param.key_size = sizeof(uint64_t); rc = ncs_patricia_tree_init(&gl_tcb.tmr_pat_tree, &pat_param); if (rc != NCSCC_RC_SUCCESS) { return NCSCC_RC_FAILURE; } rc = m_NCS_SEL_OBJ_CREATE(&gl_tcb.sel_obj); if (rc != NCSCC_RC_SUCCESS) { ncs_patricia_tree_destroy(&gl_tcb.tmr_pat_tree); return NCSCC_RC_FAILURE; } tmr_destroying = false; /* create expiry thread */ int policy = SCHED_RR; /*root defaults */ int max_prio = sched_get_priority_max(policy); int min_prio = sched_get_priority_min(policy); int prio_val = ((max_prio - min_prio) * 0.87); if (m_NCS_TASK_CREATE((NCS_OS_CB)ncs_tmr_wait, 0, (char *)"OSAF_TMR", prio_val, policy, NCS_TMR_STACKSIZE, &gl_tcb.p_tsk_hdl) != NCSCC_RC_SUCCESS) { ncs_patricia_tree_destroy(&gl_tcb.tmr_pat_tree); m_NCS_SEL_OBJ_DESTROY(&gl_tcb.sel_obj); return false; } if (m_NCS_TASK_START(gl_tcb.p_tsk_hdl) != NCSCC_RC_SUCCESS) { m_NCS_TASK_RELEASE(gl_tcb.p_tsk_hdl); ncs_patricia_tree_destroy(&gl_tcb.tmr_pat_tree); m_NCS_SEL_OBJ_DESTROY(&gl_tcb.sel_obj); return false; } return true; }
NCS_BOOL sysfTmrCreate(void) { NCS_PATRICIA_PARAMS pat_param; uns32 rc = NCSCC_RC_SUCCESS; if (ncs_tmr_create_done == FALSE) ncs_tmr_create_done = TRUE; else return TRUE; /* Empty Timer Service control block. */ memset(&gl_tcb, '\0', sizeof(SYSF_TMR_CB)); /* put local persistent guard in start state */ ncslpg_create(&gl_tcb.persist); /* Initialize the locks */ m_NCS_LOCK_INIT(&gl_tcb.safe.enter_lock); m_NCS_LOCK_INIT(&gl_tcb.safe.free_lock); memset((void *)&pat_param, 0, sizeof(NCS_PATRICIA_PARAMS)); pat_param.key_size = sizeof(uns64); rc = ncs_patricia_tree_init(&gl_tcb.tmr_pat_tree, &pat_param); if (rc != NCSCC_RC_SUCCESS) { return NCSCC_RC_FAILURE; } rc = m_NCS_SEL_OBJ_CREATE(&gl_tcb.sel_obj); if (rc != NCSCC_RC_SUCCESS) { ncs_patricia_tree_destroy(&gl_tcb.tmr_pat_tree); return NCSCC_RC_FAILURE; } tmr_destroying = FALSE; /* create expiry thread */ if (m_NCS_TASK_CREATE((NCS_OS_CB)ncs_tmr_wait, 0, NCS_TMR_TASKNAME, NCS_TMR_PRIORITY, NCS_TMR_STACKSIZE, &gl_tcb.p_tsk_hdl) != NCSCC_RC_SUCCESS) { ncs_patricia_tree_destroy(&gl_tcb.tmr_pat_tree); m_NCS_SEL_OBJ_DESTROY(gl_tcb.sel_obj); return FALSE; } if (m_NCS_TASK_START(gl_tcb.p_tsk_hdl) != NCSCC_RC_SUCCESS) { m_NCS_TASK_RELEASE(gl_tcb.p_tsk_hdl); ncs_patricia_tree_destroy(&gl_tcb.tmr_pat_tree); m_NCS_SEL_OBJ_DESTROY(gl_tcb.sel_obj); return FALSE; } return TRUE; }
/**************************************************************************** * PROCEDURE: mbcsv_lib_init * * Description : This is the function which initalize the mbcsv libarary. * This function creates an global lock, creates MBCSV linked * list, etc. * * Arguments : req_info - Request info. * * Return Values : SA_AIS_OK/Failure code. * * Notes : None. *****************************************************************************/ uint32_t mbcsv_lib_init(NCS_LIB_REQ_INFO *req_info) { NCS_PATRICIA_PARAMS pt_params; uint32_t rc = SA_AIS_OK; TRACE_ENTER(); if (mbcsv_cb.created == true) { TRACE_LEAVE2("Lib init request failed: MBCA already created"); return SA_AIS_ERR_INIT; } /* * Create global lock */ m_NCS_LOCK_INIT(&mbcsv_cb.global_lock); /* * Create patricia tree for the MBCA registration instance */ pt_params.key_size = sizeof(uint32_t); if (ncs_patricia_tree_init(&mbcsv_cb.reg_list, &pt_params) != NCSCC_RC_SUCCESS) { TRACE_4("pat tree init failed"); rc = SA_AIS_ERR_FAILED_OPERATION; goto err1; } if (NCSCC_RC_SUCCESS != mbcsv_initialize_mbx_list()) { TRACE_4("pat tree init for mailbox failed"); rc = SA_AIS_ERR_FAILED_OPERATION; goto err2; } /* * Create patricia tree for the peer list */ if (mbcsv_initialize_peer_list() != NCSCC_RC_SUCCESS) { TRACE_4("pat tree init for peer list failed"); rc = SA_AIS_ERR_FAILED_OPERATION; goto err3; } mbcsv_cb.created = true; return rc; /* Handle Different Error Situations */ err3: ncs_patricia_tree_destroy(&mbcsv_cb.mbx_list); m_NCS_LOCK_DESTROY(&mbcsv_cb.mbx_list_lock); err2: ncs_patricia_tree_destroy(&mbcsv_cb.reg_list); err1: m_NCS_LOCK_DESTROY(&mbcsv_cb.global_lock); TRACE_LEAVE(); return rc; }
uint32_t ncshm_init(void) { /* Hdl Mgr does bit-fields; here we do a few exercises up front to make */ /* sure YOUR target system can cope with bit-stuff we do............... */ HM_HDL ha; HM_HDL hb; HM_HDL *p_hdl; uint32_t *p_temp; uint32_t cnt = 0; gl_im_created++; if (gl_im_created > 1) return NCSCC_RC_SUCCESS; assert(sizeof(HM_FREE) == sizeof(HM_CELL)); /* must be same size */ assert(sizeof(uint32_t) == sizeof(HM_HDL)); /* must be same size */ ha.idx1 = 1; /* make up a fake handle with values */ ha.idx2 = 2; ha.idx3 = 3; ha.seq_id = 6; /* cast to INT PTR, to HDL PTR, deref to HDL; bit-fields still stable ? */ p_temp = (uint32_t *)(&ha); p_hdl = (HM_HDL *)p_temp; hb = *p_hdl; /* are all the bitfields still in tact?? .............................. */ assert(((ha.idx1 == hb.idx1) && (ha.idx2 == hb.idx2) && (ha.idx3 == hb.idx3) && (ha.seq_id == hb.seq_id))); /* Done with basic tests; now we move on to normal initialization */ memset(&gl_hm, 0, sizeof(HM_CORE)); for (cnt = 0; cnt < HM_POOL_CNT; cnt++) m_NCS_LOCK_INIT(&gl_hm.lock[cnt]); if (hm_init_pools(gl_hm.pool, gl_hpool) != NCSCC_RC_SUCCESS) return m_LEAP_DBG_SINK(NCSCC_RC_FAILURE); return NCSCC_RC_SUCCESS; }
/**************************************************************************** Name : mqa_create Description : This routine creates & initializes the MQA control block. Arguments : create_info - ptr to the create info Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE Notes : None ******************************************************************************/ static uint32_t mqa_create(NCS_LIB_CREATE *create_info) { MQA_CB *cb = &mqa_cb; uint32_t rc = NCSCC_RC_SUCCESS; TRACE_ENTER(); /* validate create info */ if (create_info == NULL) return NCSCC_RC_FAILURE; memset(cb, 0, sizeof(MQA_CB)); /* assign the MQA pool-id (used by hdl-mngr) */ cb->pool_id = NCS_HM_POOL_ID_COMMON; /* create the association with hdl-mngr */ if (!(cb->agent_handle_id = ncshm_create_hdl(cb->pool_id, NCS_SERVICE_ID_MQA, (NCSCONTEXT)cb))) { TRACE_2("Handle Registration Failed"); return NCSCC_RC_FAILURE; } TRACE_1("Handle Registration Success"); /* everything went off well.. store the hdl in the global variable */ gl_mqa_hdl = cb->agent_handle_id; /* get the process id */ cb->process_id = getpid(); /* initialize the mqa cb lock */ if ((rc = m_NCS_LOCK_INIT(&cb->cb_lock)) != NCSCC_RC_SUCCESS) { TRACE_2("Cotnrol Block Lock Initialisation Failed eith return value %d", rc); goto error1; } TRACE_1("Control Block lock initialization Success"); /* initialize the client tree */ if ((rc = mqa_client_tree_init(cb)) != NCSCC_RC_SUCCESS) { TRACE_2("FAILURE: Client database Initialization Failed"); goto error2; } TRACE_1("Client Database Initialization Success"); /* initialize the queue tree */ if ((rc = mqa_queue_tree_init(cb)) != NCSCC_RC_SUCCESS) { TRACE_2("FAILURE: Queue database Initialization Failed"); goto error3; } TRACE_1("Queue Database Initialization Success"); /* EDU initialisation */ if ((rc = m_NCS_EDU_HDL_INIT(&cb->edu_hdl)) != NCSCC_RC_SUCCESS) { TRACE_2("Edu Handle Initialization Failed"); goto error4; } TRACE_1("EDU Handle Initialization Success"); /* register with MDS */ if ((rc = mqa_mds_register(cb)) != NCSCC_RC_SUCCESS) { TRACE_2("FAILURE: MDS registration Failed"); goto error5; } else TRACE_1("MDS Registration Success"); /* Update clm_node_joined flag to 1 */ cb->clm_node_joined = 1; mqa_sync_with_mqd(cb); mqa_sync_with_mqnd(cb); /* initialize the timeout linked list */ if ((rc = mqa_timer_table_init(cb)) != NCSCC_RC_SUCCESS) { TRACE_2("FAILURE: Tmr Initialization Failed"); goto error6; } if ((rc = mqa_asapi_register(cb)) != NCSCC_RC_SUCCESS) { TRACE_2("FAILURE: Registration with ASAPi Failed"); goto error7; } TRACE_LEAVE(); return NCSCC_RC_SUCCESS; error7: mqa_timer_table_destroy(cb); error6: /* MDS unregister. */ mqa_mds_unregister(cb); error5: m_NCS_EDU_HDL_FLUSH(&cb->edu_hdl); error4: /* delete the tree */ mqa_queue_tree_destroy(cb); error3: /* delete the tree */ mqa_client_tree_destroy(cb); error2: /* destroy the lock */ m_NCS_LOCK_DESTROY(&cb->cb_lock); error1: /* remove the association with hdl-mngr */ ncshm_destroy_hdl(NCS_SERVICE_ID_MQA, cb->agent_handle_id); return NCSCC_RC_FAILURE; }
/**************************************************************************** Name : avnd_cb_create Description : This routine creates & initializes AvND control block. Arguments : None. Return Values : if successfull, ptr to AvND control block else, 0 Notes : None ******************************************************************************/ AVND_CB *avnd_cb_create() { AVND_CB *cb = avnd_cb; uns32 rc = NCSCC_RC_SUCCESS; SaVersionT ntfVersion = { 'A', 0x01, 0x01 }; SaNtfCallbacksT ntfCallbacks = { NULL, NULL }; SaVersionT immVersion = { 'A', 2, 1 }; char *val; TRACE_ENTER(); /* assign the AvND pool-id (used by hdl-mngr) */ cb->pool_id = NCS_HM_POOL_ID_COMMON; /* assign the default states */ cb->admin_state = SA_AMF_ADMIN_UNLOCKED; cb->oper_state = SA_AMF_OPERATIONAL_ENABLED; cb->term_state = AVND_TERM_STATE_UP; cb->led_state = AVND_LED_STATE_RED; cb->stby_sync_state = AVND_STBY_IN_SYNC; /* assign the default timeout values (in nsec) */ cb->msg_resp_intv = AVND_AVD_MSG_RESP_TIME * 1000000; cb->hb_duration_tmr.is_active = FALSE; cb->hb_duration_tmr.type = AVND_TMR_HB_DURATION; cb->hb_duration = AVSV_DEF_HB_DURATION; if ((val = getenv("AVSV_HB_DURATION")) != NULL) { cb->hb_duration = strtoll(val, NULL, 0); if (cb->hb_duration == 0) { /* no value or non convertable value, revert to default */ cb->hb_duration = AVSV_DEF_HB_DURATION; } } /* initialize the AvND cb lock */ m_NCS_LOCK_INIT(&cb->lock); TRACE_1("Initialized the AvND lock"); /* initialize the PID monitor lock */ m_NCS_LOCK_INIT(&cb->mon_lock); /* iniialize the error escaltion paramaets */ cb->node_err_esc_level = AVND_ERR_ESC_LEVEL_0; immutil_saImmOmInitialize(&cb->immOmHandle, NULL, &immVersion); /*** initialize avnd dbs ***/ /* initialize su db */ if (NCSCC_RC_SUCCESS != avnd_sudb_init(cb)) goto err; /* initialize comp db */ if (NCSCC_RC_SUCCESS != avnd_compdb_init(cb)) goto err; /* initialize healthcheck db */ avnd_hcdb_init(cb); avnd_cb->type = get_node_type(); /* initialize pg db */ if (NCSCC_RC_SUCCESS != avnd_pgdb_init(cb)) goto err; /* initialize pid_mon list */ avnd_pid_mon_list_init(cb); /* initialize nodeid to mdsdest mapping db */ if (NCSCC_RC_SUCCESS != avnd_nodeid_to_mdsdest_map_db_init(cb)) goto err; /* initialize available internode components db */ if (NCSCC_RC_SUCCESS != avnd_internode_avail_comp_db_init(cb)) goto err; /* NTFA Initialization */ rc = saNtfInitialize(&cb->ntfHandle, &ntfCallbacks, &ntfVersion); if (rc != SA_AIS_OK) { /* log the error code here */ LOG_ER("saNtfInitialize Failed (%u)", rc); goto err; } immutil_saImmOmInitialize(&cb->immOmHandle, NULL, &immVersion); TRACE_LEAVE(); return cb; err: if (cb) avnd_cb_destroy(cb); TRACE_LEAVE(); return 0; }
/***********************************************************************//** * @brief This routine creates and initializes the PLMA Control block. * * @param[in] create_info - A pointer to the structure that has creation * parameters, if any, are provided to libraries * in a command-line arguments style. * * @return NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE. ***************************************************************************/ uns32 plma_create(NCS_LIB_CREATE *create_info) { PLMA_CB *plma_cb; uns32 rc = NCSCC_RC_SUCCESS; if(!plma_ctrlblk){ plma_ctrlblk = &_plma_cb; } plma_cb = plma_ctrlblk; TRACE_ENTER(); /** validate create info */ if (create_info == NULL){ LOG_ER("PLMA : INVALID create_info RECEIVED"); rc = NCSCC_RC_FAILURE; goto end; } memset(plma_cb, 0, sizeof(PLMA_CB)); /** Initialize the PLMA_CB lock */ if (m_NCS_LOCK_INIT(&plma_cb->cb_lock) != NCSCC_RC_SUCCESS) { LOG_ER("PLMA: cb_lock INIT FAILED"); rc = NCSCC_RC_FAILURE; goto lock_fail; } /** initialize the client tree */ if (plma_client_tree_init() != NCSCC_RC_SUCCESS) { LOG_ER("PLMA: CLIENT TREE INIT FAILED"); rc = NCSCC_RC_FAILURE; goto cl_tree_init_fail; } /** initialize the group tree */ if (plma_group_tree_init() != NCSCC_RC_SUCCESS) { LOG_ER("PLMA: GROUP INFO TREE INIT FAILED"); rc = NCSCC_RC_FAILURE; goto gr_tree_init_fail; } /** register with MDS */ if (plma_mds_register() != NCSCC_RC_SUCCESS) { LOG_ER("PLMA: MDS REGISTER FAILED"); rc = NCSCC_RC_FAILURE; goto mds_reg_fail; } /** EDU initialisation */ if (m_NCS_EDU_HDL_INIT(&plma_cb->edu_hdl) != NCSCC_RC_SUCCESS) { LOG_ER("PLMA: EDU HDL INIT FAILED"); rc = NCSCC_RC_FAILURE; goto edu_init_fail; } plma_sync_with_plms(); TRACE_LEAVE(); return NCSCC_RC_SUCCESS; edu_init_fail: plma_mds_unregister(); mds_reg_fail: plma_group_tree_destroy(); gr_tree_init_fail: plma_client_tree_destroy(); cl_tree_init_fail: /** destroy the lock */ m_NCS_LOCK_DESTROY(&plma_cb->cb_lock); lock_fail: /** make reference to plma_cb obsolete */ plma_ctrlblk = NULL; end: TRACE_LEAVE(); return rc; }
/**************************************************************************** Name : cpa_create Description : This routine creates & initializes the CPA control block. Arguments : create_info - ptr to the create info Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE Notes : None ******************************************************************************/ static uint32_t cpa_create(NCS_LIB_CREATE *create_info) { CPA_CB *cb = NULL; uint32_t rc; /* validate create info */ if (create_info == NULL) return NCSCC_RC_FAILURE; /* Malloc the CB for CPA */ cb = m_MMGR_ALLOC_CPA_CB; if (cb == NULL) { TRACE_4("cpa mem alloc failed for CPA_CB"); goto cb_alloc_fail; } memset(cb, 0, sizeof(CPA_CB)); /* assign the CPA pool-id (used by hdl-mngr) */ cb->pool_id = NCS_HM_POOL_ID_COMMON; /* create the association with hdl-mngr */ if (!(cb->agent_handle_id = ncshm_create_hdl(cb->pool_id, NCS_SERVICE_ID_CPA, (NCSCONTEXT)cb))) { TRACE_4("cpa create failed int ncsshm_create_hdl"); goto hm_create_fail; } /*store the hdl in the global variable */ gl_cpa_hdl = cb->agent_handle_id; /* get the process id */ cb->process_id = getpid(); /* initialize the cpa cb lock */ if (m_NCS_LOCK_INIT(&cb->cb_lock) != NCSCC_RC_SUCCESS) { TRACE_4("cpa create failed in LOCK_INIT "); goto lock_init_fail; } /* Initalize the CPA Trees & Linked lists */ rc = cpa_db_init(cb); if (rc != NCSCC_RC_SUCCESS) { /* No need to log here, already logged in cpa_db_init */ goto db_init_fail; } /* register with MDS */ if (cpa_mds_register(cb) != NCSCC_RC_SUCCESS) { /* No need to log here, already logged in cpa_mds_register */ goto mds_reg_fail; } cpa_sync_with_cpnd(cb); /* EDU initialisation */ if (m_NCS_EDU_HDL_INIT(&cb->edu_hdl) != NCSCC_RC_SUCCESS) { TRACE_4("cpa create failed in EDU_INIT:"); goto edu_init_fail; } TRACE_1("cpa create sucess,Lib init success"); return NCSCC_RC_SUCCESS; /* error8: m_NCS_EDU_HDL_FLUSH(&cb->edu_hdl); */ edu_init_fail: /* MDS unregister. */ cpa_mds_unregister(cb); mds_reg_fail: cb->is_cpnd_joined_clm = false; cpa_db_destroy(cb); db_init_fail: /* destroy the lock */ cb->is_cpnd_joined_clm = false; m_NCS_LOCK_DESTROY(&cb->cb_lock); lock_init_fail: /* remove the association with hdl-mngr */ ncshm_destroy_hdl(NCS_SERVICE_ID_CPA, cb->agent_handle_id); gl_cpa_hdl = 0; hm_create_fail: /* Free the CB */ m_MMGR_FREE_CPA_CB(cb); cb_alloc_fail: return NCSCC_RC_FAILURE; }
/**************************************************************************** Name : ava_create Description : This routine creates & initializes the AvA control block. Arguments : create_info - ptr to the create info Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE Notes : None ******************************************************************************/ uns32 ava_create(NCS_LIB_CREATE *create_info) { AVA_CB *cb = 0; NCS_SEL_OBJ_SET set; uns32 rc = NCSCC_RC_SUCCESS, timeout = 300; EDU_ERR err; TRACE_ENTER(); /* allocate AvA cb */ if (!(cb = calloc(1, sizeof(AVA_CB)))) { LOG_ER("AVA Create: Calloc failed"); rc = NCSCC_RC_FAILURE; goto error; } /* fetch the comp name from the env variable */ if (getenv("SA_AMF_COMPONENT_NAME")) { if (strlen(getenv("SA_AMF_COMPONENT_NAME")) < SA_MAX_NAME_LENGTH) { strcpy((char *)cb->comp_name.value, getenv("SA_AMF_COMPONENT_NAME")); cb->comp_name.length = (uns16)strlen((char *)cb->comp_name.value); m_AVA_FLAG_SET(cb, AVA_FLAG_COMP_NAME); TRACE("Component name = %s",cb->comp_name.value); } else { TRACE_2("Length of SA_AMF_COMPONENT_NAME exceeds SA_MAX_NAME_LENGTH bytes"); rc = NCSCC_RC_FAILURE; goto error; } } /* assign the AvA pool-id (used by hdl-mngr) */ cb->pool_id = NCS_HM_POOL_ID_COMMON; /* create the association with hdl-mngr */ if (!(cb->cb_hdl = ncshm_create_hdl(cb->pool_id, NCS_SERVICE_ID_AVA, (NCSCONTEXT)cb))) { LOG_ER("Unable to create handle for control block"); rc = NCSCC_RC_FAILURE; goto error; } TRACE("Created handle for the control block"); /* initialize the AvA cb lock */ m_NCS_LOCK_INIT(&cb->lock); TRACE("Initialized the AVA control block lock"); /* EDU initialisation */ m_NCS_EDU_HDL_INIT(&cb->edu_hdl); TRACE("EDU Initialization success"); rc = m_NCS_EDU_COMPILE_EDP(&cb->edu_hdl, avsv_edp_nda_msg, &err); if (rc != NCSCC_RC_SUCCESS) { TRACE_4("EDU Compilation failed"); goto error; } /* create the sel obj (for mds sync) */ m_NCS_SEL_OBJ_CREATE(&cb->sel_obj); /* initialize the hdl db */ if (NCSCC_RC_SUCCESS != ava_hdl_init(&cb->hdl_db)) { TRACE_4("AVA Handles DB initialization failed"); rc = NCSCC_RC_FAILURE; goto error; } TRACE("AVA Handles DB created successfully"); m_NCS_SEL_OBJ_ZERO(&set); m_NCS_SEL_OBJ_SET(cb->sel_obj, &set); m_AVA_FLAG_SET(cb, AVA_FLAG_FD_VALID); /* register with MDS */ if ((NCSCC_RC_SUCCESS != ava_mds_reg(cb))) { LOG_ER("AVA MDS Registration failed"); rc = NCSCC_RC_FAILURE; goto error; } TRACE("AVA MDS Registration success"); TRACE_1("Waiting on select till AMF Node Director is up"); /* block until mds detects avnd */ m_NCS_SEL_OBJ_SELECT(cb->sel_obj, &set, 0, 0, &timeout); /* reset the fd validity flag */ m_NCS_LOCK(&cb->lock, NCS_LOCK_WRITE); m_AVA_FLAG_RESET(cb, AVA_FLAG_FD_VALID); m_NCS_UNLOCK(&cb->lock, NCS_LOCK_WRITE); /* This sel obj is no more used */ m_NCS_SEL_OBJ_DESTROY(cb->sel_obj); /* everything went off well.. store the cb hdl in the global variable */ gl_ava_hdl = cb->cb_hdl; TRACE_LEAVE(); return rc; error: if (cb) { /* remove the association with hdl-mngr */ if (cb->cb_hdl) ncshm_destroy_hdl(NCS_SERVICE_ID_AVA, cb->cb_hdl); /* delete the hdl db */ ava_hdl_del(cb); /* Flush the edu hdl */ m_NCS_EDU_HDL_FLUSH(&cb->edu_hdl); /* destroy the lock */ m_NCS_LOCK_DESTROY(&cb->lock); /* free the control block */ free(cb); } TRACE_LEAVE(); return rc; }
/**************************************************************************** Name : eda_create Description : This routine creates & initializes the EDA control block. Arguments : create_info - ptr to the create info Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE Notes : None ******************************************************************************/ uns32 eda_create(NCS_LIB_CREATE *create_info) { EDA_CB *cb = 0; uns32 rc = NCSCC_RC_SUCCESS; if (NULL == create_info) return NCSCC_RC_FAILURE; /* Register with the Logging subsystem */ eda_flx_log_reg(); /* allocate EDA cb */ if (NULL == (cb = m_MMGR_ALLOC_EDA_CB)) { m_LOG_EDSV_A(EDA_MEMALLOC_FAILED, NCSFL_LC_EDSV_INIT, NCSFL_SEV_ERROR, 0, __FILE__, __LINE__, 0); rc = NCSCC_RC_FAILURE; goto error; } memset(cb, 0, sizeof(EDA_CB)); /* assign the EDA pool-id (used by hdl-mngr) */ cb->pool_id = NCS_HM_POOL_ID_COMMON; /* create the association with hdl-mngr */ if (0 == (cb->cb_hdl = ncshm_create_hdl(cb->pool_id, NCS_SERVICE_ID_EDA, (NCSCONTEXT)cb))) { m_LOG_EDSV_A(EDA_CB_HDL_CREATE_FAILED, NCSFL_LC_EDSV_INIT, NCSFL_SEV_ERROR, 0, __FILE__, __LINE__, 0); rc = NCSCC_RC_FAILURE; goto error; } /* get the process id */ cb->prc_id = getpid(); /* initialize the eda cb lock */ m_NCS_LOCK_INIT(&cb->cb_lock); m_NCS_LOCK_INIT(&cb->eds_sync_lock); /* Store the cb hdl in the global variable */ gl_eda_hdl = cb->cb_hdl; /* register with MDS */ if ((NCSCC_RC_SUCCESS != (rc = eda_mds_init(cb)))) { m_LOG_EDSV_A(EDA_MDS_INIT_FAILED, NCSFL_LC_EDSV_INIT, NCSFL_SEV_ERROR, rc, __FILE__, __LINE__, 0); rc = NCSCC_RC_FAILURE; goto error; } eda_sync_with_eds(cb); cb->node_status = SA_CLM_NODE_JOINED; return rc; error: if (cb) { /* remove the association with hdl-mngr */ if (cb->cb_hdl) ncshm_destroy_hdl(NCS_SERVICE_ID_EDA, cb->cb_hdl); /* delete the eda init instances */ eda_hdl_list_del(&cb->eda_init_rec_list); /* destroy the lock */ m_NCS_LOCK_DESTROY(&cb->cb_lock); /* free the control block */ m_MMGR_FREE_EDA_CB(cb); } return rc; }
/**************************************************************************** Name : mqa_create Description : This routine creates & initializes the MQA control block. Arguments : create_info - ptr to the create info Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE Notes : None ******************************************************************************/ static uns32 mqa_create(NCS_LIB_CREATE *create_info) { MQA_CB *cb = &mqa_cb; uns32 rc = NCSCC_RC_SUCCESS; /* validate create info */ if (create_info == NULL) return NCSCC_RC_FAILURE; /* Register with Logging subsystem */ mqa_flx_log_reg(); memset(cb, 0, sizeof(MQA_CB)); /* assign the MQA pool-id (used by hdl-mngr) */ cb->pool_id = NCS_HM_POOL_ID_COMMON; /* create the association with hdl-mngr */ if (!(cb->agent_handle_id = ncshm_create_hdl(cb->pool_id, NCS_SERVICE_ID_MQA, (NCSCONTEXT)cb))) { m_LOG_MQSV_A(MQA_CREATE_HANDLE_FAILED, NCSFL_LC_MQSV_INIT, NCSFL_SEV_ERROR, 0, __FILE__, __LINE__); goto error1; } m_LOG_MQSV_A(MQA_CREATE_HANDLE_SUCCESS, NCSFL_LC_MQSV_INIT, NCSFL_SEV_NOTICE, 1, __FILE__, __LINE__); /* everything went off well.. store the hdl in the global variable */ gl_mqa_hdl = cb->agent_handle_id; /* get the process id */ cb->process_id = getpid(); /* initialize the mqa cb lock */ if ((rc = m_NCS_LOCK_INIT(&cb->cb_lock)) != NCSCC_RC_SUCCESS) { m_LOG_MQSV_A(MQA_CB_LOCK_INIT_FAILED, NCSFL_LC_MQSV_INIT, NCSFL_SEV_ERROR, 0, __FILE__, __LINE__); goto error2; } m_LOG_MQSV_A(MQA_CB_LOCK_INIT_SUCCESS, NCSFL_LC_MQSV_INIT, NCSFL_SEV_NOTICE, rc, __FILE__, __LINE__); /* initialize the client tree */ if ((rc = mqa_client_tree_init(cb)) != NCSCC_RC_SUCCESS) { m_LOG_MQSV_A(MQA_CLIENT_TREE_INIT_FAILED, NCSFL_LC_MQSV_INIT, NCSFL_SEV_ERROR, rc, __FILE__, __LINE__); goto error3; } m_LOG_MQSV_A(MQA_CLIENT_TREE_INIT_SUCCESS, NCSFL_LC_MQSV_INIT, NCSFL_SEV_NOTICE, rc, __FILE__, __LINE__); /* initialize the queue tree */ if ((rc = mqa_queue_tree_init(cb)) != NCSCC_RC_SUCCESS) { m_LOG_MQSV_A(MQA_QUEUE_TREE_INIT_FAILED, NCSFL_LC_MQSV_INIT, NCSFL_SEV_ERROR, rc, __FILE__, __LINE__); goto error4; } m_LOG_MQSV_A(MQA_QUEUE_TREE_INIT_SUCCESS, NCSFL_LC_MQSV_INIT, NCSFL_SEV_NOTICE, rc, __FILE__, __LINE__); /* EDU initialisation */ if ((rc = m_NCS_EDU_HDL_INIT(&cb->edu_hdl)) != NCSCC_RC_SUCCESS) { m_LOG_MQSV_A(MQA_EDU_HDL_INIT_FAILED, NCSFL_LC_MQSV_INIT, NCSFL_SEV_ERROR, rc, __FILE__, __LINE__); goto error5; } m_LOG_MQSV_A(MQA_EDU_HDL_INIT_SUCCESS, NCSFL_LC_MQSV_INIT, NCSFL_SEV_NOTICE, rc, __FILE__, __LINE__); /* register with MDS */ if ((rc = mqa_mds_register(cb)) != NCSCC_RC_SUCCESS) { m_LOG_MQSV_A(MQA_MDS_REGISTER_FAILED, NCSFL_LC_MQSV_INIT, NCSFL_SEV_ERROR, rc, __FILE__, __LINE__); goto error6; } else m_LOG_MQSV_A(MQA_MDS_REGISTER_SUCCESS, NCSFL_LC_MQSV_INIT, NCSFL_SEV_INFO, rc, __FILE__, __LINE__); /* Update clm_node_joined flag to 1 */ cb->clm_node_joined = 1; mqa_sync_with_mqd(cb); mqa_sync_with_mqnd(cb); /* initialize the timeout linked list */ if ((rc = mqa_timer_table_init(cb)) != NCSCC_RC_SUCCESS) { m_LOG_MQSV_A(MQA_TIMER_TABLE_INIT_FAILED, NCSFL_LC_MQSV_INIT, NCSFL_SEV_ERROR, rc, __FILE__, __LINE__); goto error7; } if ((rc = mqa_asapi_register(cb)) != NCSCC_RC_SUCCESS) { m_LOG_MQSV_A(MQA_REGISTER_WITH_ASAPi_FAILED, NCSFL_LC_MQSV_INIT, NCSFL_SEV_ERROR, rc, __FILE__, __LINE__); goto error8; } return NCSCC_RC_SUCCESS; error8: mqa_timer_table_destroy(cb); error7: /* MDS unregister. */ mqa_mds_unregister(cb); error6: m_NCS_EDU_HDL_FLUSH(&cb->edu_hdl); error5: /* delete the tree */ mqa_queue_tree_destroy(cb); error4: /* delete the tree */ mqa_client_tree_destroy(cb); error3: /* destroy the lock */ m_NCS_LOCK_DESTROY(&cb->cb_lock); error2: /* remove the association with hdl-mngr */ ncshm_destroy_hdl(NCS_SERVICE_ID_MQA, cb->agent_handle_id); error1: /* de register with the flex log */ mqa_flx_log_dereg(); return NCSCC_RC_FAILURE; }
/**************************************************************************\ * * init_exec_mod_cb * * Description: Initialize execute module control block lock. * * Synopsis: * * Call Arguments: * SUCCESS/FAILURE * * Returns: * None. * * Notes: * \**************************************************************************/ uns32 init_exec_mod_cb(void) { memset(&module_cb, '\0', sizeof(SYSF_EXECUTE_MODULE_CB)); m_NCS_LOCK_INIT(&module_cb.tree_lock); return NCSCC_RC_SUCCESS; }
/**************************************************************************** * Name : eds_se_lib_init * * Description : Invoked to Initialize the EDS * * * Arguments : * Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.. * * Notes : None. *****************************************************************************/ static uint32_t eds_se_lib_init(NCS_LIB_REQ_INFO *req_info) { EDS_CB *eds_cb; uint32_t rc = NCSCC_RC_SUCCESS; TRACE_ENTER(); /* Allocate and initialize the control block */ if (NULL == (eds_cb = m_MMGR_ALLOC_EDS_CB)) { LOG_CR("malloc failed for control block"); TRACE_LEAVE(); return NCSCC_RC_FAILURE; } memset(eds_cb, '\0', sizeof(EDS_CB)); /* Obtain the hdl for EDS_CB from hdl-mgr */ gl_eds_hdl = eds_cb->my_hdl = ncshm_create_hdl(1, NCS_SERVICE_ID_EDS, (NCSCONTEXT)eds_cb); if (0 == eds_cb->my_hdl) { LOG_ER("Handle create failed for global eds handle"); ncshm_destroy_hdl(NCS_SERVICE_ID_EDS, gl_eds_hdl); gl_eds_hdl = 0; m_MMGR_FREE_EDS_CB(eds_cb); TRACE_LEAVE(); return NCSCC_RC_FAILURE; } /* initialize the eds cb lock */ m_NCS_LOCK_INIT(&eds_cb->cb_lock); /* Initialize eds control block */ if (NCSCC_RC_SUCCESS != (rc = eds_cb_init(eds_cb))) { /* Destroy the hdl for this CB */ ncshm_destroy_hdl(NCS_SERVICE_ID_EDS, gl_eds_hdl); gl_eds_hdl = 0; /* clean up the CB */ m_MMGR_FREE_EDS_CB(eds_cb); /* log the error */ TRACE_4("EDS control block init failed"); TRACE_LEAVE(); return rc; } m_NCS_EDU_HDL_INIT(&eds_cb->edu_hdl); /* Create the mbx to communicate with the EDS thread */ if (NCSCC_RC_SUCCESS != (rc = m_NCS_IPC_CREATE(&eds_cb->mbx))) { LOG_ER("EDS IPC mailbox create failed"); /* Release EDU handle */ m_NCS_EDU_HDL_FLUSH(&eds_cb->edu_hdl); /* Destroy the hdl for this CB */ ncshm_destroy_hdl(NCS_SERVICE_ID_EDS, gl_eds_hdl); gl_eds_hdl = 0; /* Free the control block */ m_MMGR_FREE_EDS_CB(eds_cb); TRACE_LEAVE(); return rc; } /* Attach the IPC to the created thread */ m_NCS_IPC_ATTACH(&eds_cb->mbx); /* Bind to MDS */ if (NCSCC_RC_SUCCESS != (rc = eds_mds_init(eds_cb))) { TRACE_4("eds mds init failed"); m_NCS_IPC_RELEASE(&eds_cb->mbx, NULL); /* Release EDU handle */ m_NCS_EDU_HDL_FLUSH(&eds_cb->edu_hdl); ncshm_destroy_hdl(NCS_SERVICE_ID_EDS, gl_eds_hdl); gl_eds_hdl = 0; m_MMGR_FREE_EDS_CB(eds_cb); TRACE_LEAVE(); return rc; } /* Initialize and Register with CLM */ rc = eds_clm_init(eds_cb); if (rc != SA_AIS_OK) { TRACE_4("CLM Init failed. Exiting"); exit(EXIT_FAILURE); } /* Initialize and Register with AMF */ rc = eds_amf_register(eds_cb); if (rc != NCSCC_RC_SUCCESS) { LOG_ER("AMF Init failed: Exiting."); exit(EXIT_FAILURE); } /* Initialize mbcsv interface */ if (NCSCC_RC_SUCCESS != (rc = eds_mbcsv_init(eds_cb))) { LOG_ER("eds mbcsv init failed"); /* Log it */ } TRACE("eds init done."); TRACE_LEAVE(); return (rc); }
/**************************************************************************** Name : eda_create Description : This routine creates & initializes the EDA control block. Arguments : create_info - ptr to the create info Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE Notes : None ******************************************************************************/ uint32_t eda_create(NCS_LIB_CREATE *create_info) { EDA_CB *cb = 0; uint32_t rc = NCSCC_RC_SUCCESS; TRACE_ENTER(); if (NULL == create_info) { TRACE_LEAVE2("create_info is NULL"); return NCSCC_RC_FAILURE; } /* allocate EDA cb */ if (NULL == (cb = m_MMGR_ALLOC_EDA_CB)) { TRACE_4("malloc failed"); rc = NCSCC_RC_FAILURE; goto error; } memset(cb, 0, sizeof(EDA_CB)); /* assign the EDA pool-id (used by hdl-mngr) */ cb->pool_id = NCS_HM_POOL_ID_COMMON; /* create the association with hdl-mngr */ if (0 == (cb->cb_hdl = ncshm_create_hdl(cb->pool_id, NCS_SERVICE_ID_EDA, (NCSCONTEXT)cb))) { TRACE_4("create handle failed"); rc = NCSCC_RC_FAILURE; goto error; } /* get the process id */ cb->prc_id = getpid(); /* initialize the eda cb lock */ m_NCS_LOCK_INIT(&cb->cb_lock); m_NCS_LOCK_INIT(&cb->eds_sync_lock); /* Store the cb hdl in the global variable */ gl_eda_hdl = cb->cb_hdl; TRACE_1("global eda library handle is: %u", gl_eda_hdl); /* register with MDS */ if ((NCSCC_RC_SUCCESS != (rc = eda_mds_init(cb)))) { TRACE_4("mds init failed"); rc = NCSCC_RC_FAILURE; goto error; } eda_sync_with_eds(cb); cb->node_status = SA_CLM_NODE_JOINED; TRACE_LEAVE2("Default local node membership status: %u", cb->node_status); return rc; error: if (cb) { /* remove the association with hdl-mngr */ if (cb->cb_hdl) ncshm_destroy_hdl(NCS_SERVICE_ID_EDA, cb->cb_hdl); /* delete the eda init instances */ eda_hdl_list_del(&cb->eda_init_rec_list); /* destroy the lock */ m_NCS_LOCK_DESTROY(&cb->cb_lock); /* free the control block */ m_MMGR_FREE_EDA_CB(cb); } TRACE_LEAVE(); return rc; }