Ejemplo n.º 1
0
/****************************************************************************
  Name          : avnd_mbx_create
 
  Description   : This routine creates & attaches AvND mailbox.
 
  Arguments     : cb - ptr to AvND control block
 
  Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE
 
  Notes         : None
******************************************************************************/
uns32 avnd_mbx_create(AVND_CB *cb)
{
	uns32 rc = NCSCC_RC_SUCCESS;
	TRACE_ENTER();

	/* create the mail box */
	rc = m_NCS_IPC_CREATE(&cb->mbx);
	if (NCSCC_RC_SUCCESS != rc) {
		LOG_CR("AvND Mailbox creation failed");
		goto err;
	}
	TRACE("AvND mailbox creation success");

	/* attach the mail box */
	rc = m_NCS_IPC_ATTACH(&cb->mbx);
	if (NCSCC_RC_SUCCESS != rc) {
		LOG_CR("AvND mailbox attach failed");
		goto err;
	}
	TRACE_LEAVE2("AvND mailbox attach success");

	return rc;

 err:
	/* destroy the mailbox */
	if (cb->mbx)
		avnd_mbx_destroy(cb);
	TRACE_LEAVE();
	return rc;
}
Ejemplo n.º 2
0
/**
 * This function initializes the DTMS_CB including the Patricia trees
 *
 * @param dtms_cb
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
uns32 dtm_cb_init(DTM_INTERNODE_CB * dtms_cb)
{
	NCS_PATRICIA_PARAMS nodeid_param;
	NCS_PATRICIA_PARAMS comm_socket_param;
	NCS_PATRICIA_PARAMS ipaddr_param;

	TRACE_ENTER();

	memset(&nodeid_param, 0, sizeof(NCS_PATRICIA_PARAMS));
	memset(&comm_socket_param, 0, sizeof(NCS_PATRICIA_PARAMS));
	memset(&ipaddr_param, 0, sizeof(NCS_PATRICIA_PARAMS));

	nodeid_param.key_size = sizeof(uns32);
	comm_socket_param.key_size = sizeof(uns32);
	ipaddr_param.key_size = IPV6_ADDR_UNS8_CNT;

	/* Initialize patricia tree for nodeid list */
	if (NCSCC_RC_SUCCESS != ncs_patricia_tree_init(&dtms_cb->nodeid_tree, &nodeid_param)) {
		LOG_ER("DTM: ncs_patricia_tree_init FAILED");
		return NCSCC_RC_FAILURE;
	}

	/* Initialize comm_socket patricia tree */
	if (NCSCC_RC_SUCCESS != ncs_patricia_tree_init(&dtms_cb->comm_sock_tree, &comm_socket_param)) {
		LOG_ER("DTM:ncs_patricia_tree_init FAILED");
		return NCSCC_RC_FAILURE;
	}

	/* Initialize comm_socket patricia tree */
	if (NCSCC_RC_SUCCESS != ncs_patricia_tree_init(&dtms_cb->ip_addr_tree, &ipaddr_param)) {
		LOG_ER("DTM:ncs_patricia_tree_init FAILED");
		return NCSCC_RC_FAILURE;
	}

	if (m_NCS_IPC_CREATE(&dtms_cb->mbx) != NCSCC_RC_SUCCESS) {
		/* Mail box creation failed */
		LOG_ER("DTM:IPC create FAILED");
		return NCSCC_RC_FAILURE;
	} else {

		NCS_SEL_OBJ obj;

		if (NCSCC_RC_SUCCESS != m_NCS_IPC_ATTACH(&dtms_cb->mbx)) {
			m_NCS_IPC_RELEASE(&dtms_cb->mbx, NULL);
			LOG_ER("DTM: Internode Mailbox  Attach failed");
			return NCSCC_RC_FAILURE;
		}

		obj = m_NCS_IPC_GET_SEL_OBJ(&dtms_cb->mbx);

		/* retreive the corresponding fd for mailbox and fill it in cb */
		dtms_cb->mbx_fd = m_GET_FD_FROM_SEL_OBJ(obj);	/* extract and fill value needs to be extracted */
	}

	TRACE_LEAVE();
	return NCSCC_RC_SUCCESS;
}
Ejemplo n.º 3
0
/**
 * Initialize smfnd
 * 
 * @return uns32
 */
static uns32 initialize_smfnd(void)
{
	uns32 rc;

	TRACE_ENTER();

	if (ncs_agents_startup() != NCSCC_RC_SUCCESS) {
		LOG_ER("ncs_agents_startup FAILED");
		rc = NCSCC_RC_FAILURE;
		goto done;
	}

	/* Initialize smfnd control block */
	if (smfnd_cb_init(smfnd_cb) != NCSCC_RC_SUCCESS) {
		TRACE("smfnd_cb_init FAILED");
		rc = NCSCC_RC_FAILURE;
		goto done;
	}

	/* Create the mailbox used for communication with SMFD/SMFA */
	if ((rc = m_NCS_IPC_CREATE(&smfnd_cb->mbx)) != NCSCC_RC_SUCCESS) {
		LOG_ER("m_NCS_IPC_CREATE FAILED %d", rc);
		goto done;
	}

	/* Attach mailbox to this thread */
	if ((rc = m_NCS_IPC_ATTACH(&smfnd_cb->mbx) != NCSCC_RC_SUCCESS)) {
		LOG_ER("m_NCS_IPC_ATTACH FAILED %d", rc);
		goto done;
	}

	/* Create a selection object for USR1 signal handling */
	if ((rc = ncs_sel_obj_create(&smfnd_cb->usr1_sel_obj)) != NCSCC_RC_SUCCESS) {
		LOG_ER("ncs_sel_obj_create failed");
		goto done;
	}

	/* Initialize mds communication */
	if ((rc = smfnd_mds_init(smfnd_cb)) != NCSCC_RC_SUCCESS) {
		TRACE("smfnd_mds_init FAILED %d", rc);
		return rc;
	}

	/* Check if AMF started */
	if (smfnd_cb->nid_started == 0) {
		/* Started by AMF, so let's init AMF */
		if ((rc = smfnd_amf_init(smfnd_cb)) != NCSCC_RC_SUCCESS) {
			LOG_ER("init amf failed");
			goto done;
		}
	}

 done:
	TRACE_LEAVE();
	return (rc);
}
Ejemplo n.º 4
0
/****************************************************************************
  Name          : glsv_gla_callback_queue_init
  
  Description   : This routine is used to initialize the queue for the callbacks.
 
  Arguments     : client_info - pointer to the client info
                   
  Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE
 
  Notes         : None
******************************************************************************/
uns32 glsv_gla_callback_queue_init(GLA_CLIENT_INFO *client_info)
{
	if (m_NCS_IPC_CREATE(&client_info->callbk_mbx) == NCSCC_RC_SUCCESS) {
		if (m_NCS_IPC_ATTACH(&client_info->callbk_mbx) == NCSCC_RC_SUCCESS) {
			return NCSCC_RC_SUCCESS;
		}
		m_NCS_IPC_RELEASE(&client_info->callbk_mbx, NULL);
	}
	m_LOG_GLA_SYS_CALL(GLA_GET_SEL_OBJ_FAIL, __FILE__, __LINE__, client_info->lock_handle_id);
	return NCSCC_RC_FAILURE;
}
Ejemplo n.º 5
0
/***********************************************************************
* Name          : plms_hrb_initialize
*
* Description   : This function initializes the HRB control block
*                 and creates plms_hrb thread, It registers to MDS  
*		  to receive requests from PLMS
*
* Arguments     : 
*
* Return Values : NCSCC_RC_SUCCESS
*		  NCSCC_RC_FAILURE
***********************************************************************/
SaUint32T plms_hrb_initialize()
{
	PLMS_HRB_CB      *cb =  hrb_cb;
	pthread_t        thread_id;
	pthread_attr_t   attr;
	struct sched_param thread_priority;
	SaUint32T        policy;
	SaUint32T	 rc;

	TRACE_ENTER();

	/* create the mail box and attach it */
	if ((rc = m_NCS_IPC_CREATE(&cb->mbx)) != NCSCC_RC_SUCCESS){
		LOG_ER("error creating mail box err val:%d",rc);
		return NCSCC_RC_FAILURE;
	}

	if ((rc = m_NCS_IPC_ATTACH(&cb->mbx)) != NCSCC_RC_SUCCESS){
		LOG_ER("error attaching mail box err val:%d",rc);
		return NCSCC_RC_FAILURE;
	}

	/* Initialize with the MDS */
	if(hrb_mds_initialize() != NCSCC_RC_SUCCESS){
		LOG_ER("HRB: mds initialization failed");
		return NCSCC_RC_FAILURE;
	}

	/* Initialize thread attribute */
	pthread_attr_init(&attr);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

	pthread_attr_setstacksize(&attr, PLMS_HRB_STACKSIZE);

	/* Create PLMS_HRB thread */
	rc = pthread_create(&thread_id, &attr, plms_hrb, NULL);
	if(rc){
		LOG_ER("pthread_create FAILED ret code:%d error:%s",
				rc,strerror(errno));
		return NCSCC_RC_FAILURE;
	}
	
	/*scheduling parameters of the thread */
        memset(&thread_priority, 0, sizeof(thread_priority));
	thread_priority.sched_priority = PLMS_HRB_TASK_PRIORITY;
	policy = SCHED_OTHER;
	pthread_setschedparam(thread_id, policy, &thread_priority);

	TRACE_LEAVE();
	return NCSCC_RC_SUCCESS;
}
Ejemplo n.º 6
0
static uint32_t dtm_intranode_create_pid_info(int fd)
{
	DTM_INTRANODE_PID_INFO *pid_node = NULL;
	TRACE_ENTER();
	if (NULL == (pid_node = calloc(1, sizeof(DTM_INTRANODE_PID_INFO)))) {
		TRACE("\nMemory allocation failed for DTM_INTRANODE_PID_INFO");
		return NCSCC_RC_FAILURE;
	}

	pid_node->accepted_fd = fd;
	pid_node->pid = 0; /* Yet to be filled from the PID Message which is yet to come */
	pid_node->node_id = m_NCS_GET_NODE_ID;
	pid_node->fd_node.key_info = (uint8_t *)&pid_node->accepted_fd;

	if (m_NCS_IPC_CREATE(&pid_node->mbx) != NCSCC_RC_SUCCESS) {
		/* Mail box creation failed */
		TRACE("Mailbox creation failed,dtm_accept msg");
		free(pid_node);
		return NCSCC_RC_FAILURE;
	} else {

		NCS_SEL_OBJ obj;
		/* Code added for attaching the mailbox */
		if (NCSCC_RC_SUCCESS != m_NCS_IPC_ATTACH(&pid_node->mbx)) {
			TRACE("\nMailbox attach failed,dtm_intranode_process_pid_msg");
			m_NCS_IPC_RELEASE(&pid_node->mbx, NULL);
			free(pid_node);
			return NCSCC_RC_FAILURE;
		}

		obj = m_NCS_IPC_GET_SEL_OBJ(&pid_node->mbx);

		/* retreive the corresponding fd for mailbox */
		pid_node->mbx_fd = m_GET_FD_FROM_SEL_OBJ(obj);	/* extract and fill value needs to be extracted */
	}
	ncs_patricia_tree_add(&dtm_intranode_cb->dtm_intranode_fd_list, (NCS_PATRICIA_NODE *)&pid_node->fd_node);
	TRACE_LEAVE();
	return NCSCC_RC_SUCCESS;
}
Ejemplo n.º 7
0
/*************************************************************************** 
@brief		: saSmfInitialize. Even if no cbk is registered, we create 
		  MBX for the client as we have to return the sel obj later.
@param[out]	: smfHandle - Will have a valid handle if initialization is
 		  successful.
@param[in]	: smfCallbacks - Cbks to be registered.
@param[in]	: version - Supported smf-api version.
@return		: SA_AIS_OK if successful otherwise appropiate err code.
*****************************************************************************/
SaAisErrorT saSmfInitialize(SaSmfHandleT *smfHandle, 
			const SaSmfCallbacksT *smfCallbacks,
			SaVersionT *version)
{
	SMFA_CB			*cb = &_smfa_cb;
	SMFA_CLIENT_INFO	*client_info;
	SaAisErrorT		rc = SA_AIS_OK;

	TRACE_ENTER();

	if (!smfHandle || !version){
		LOG_ER("SMFA: smfHandle or version is NULL.");
		return SA_AIS_ERR_INVALID_PARAM;
	}
	
	if (!m_SMFA_VERSION_VALIDATE(version)){
		LOG_ER("SMFA: Unsupported version. ReleaseCode: %c, MajorVersion: %x",
		version->releaseCode,version->majorVersion);
		version->releaseCode = SMF_RELEASE_CODE;
		version->majorVersion = SMF_MAJOR_VERSION;
		version->minorVersion = SMF_MINOR_VERSION;
		TRACE_LEAVE();
		return SA_AIS_ERR_VERSION;
	}
	version->minorVersion = SMF_MINOR_VERSION;

	if (NCSCC_RC_SUCCESS != smfa_init()){
		LOG_ER("smfa_init() FAILED.");
		ncs_agents_shutdown();
		TRACE_LEAVE();
		return SA_AIS_ERR_LIBRARY;	
	}
		
	client_info = (SMFA_CLIENT_INFO *)calloc(1,sizeof(SMFA_CLIENT_INFO));
	if (NULL == client_info){
		LOG_ER("SMFA client info: calloc FAILED, error: %s",strerror(errno));
		rc = SA_AIS_ERR_NO_MEMORY;
		goto smfa_init_failed;
	}
	
	/* Fill the handle.*/
	if ( MAX_SMFA_HDL <= smfa_hdl){
		smfa_hdl = 0;
	}
	smfa_hdl++;
	client_info->client_hdl = smfa_hdl;
	 
	/* Fill the callback info. */
	if (NULL != smfCallbacks)
		client_info->reg_cbk = *smfCallbacks;
	else
		TRACE_2("SMFA: No cbk registered.");

	/* Create MBX for this client.*/
	if (NCSCC_RC_SUCCESS != m_NCS_IPC_CREATE(&client_info->cbk_mbx)){
		LOG_ER("SMFA: MBX create FAILED.");
		rc = SA_AIS_ERR_LIBRARY;
		goto smfa_mbx_create_failed;
	}else {
		if (NCSCC_RC_SUCCESS != m_NCS_IPC_ATTACH(&client_info->cbk_mbx)){
			LOG_ER("SMFA: MBX attach FAILED.");
			rc = SA_AIS_ERR_LIBRARY;
			goto smfa_mbx_attach_failed;
		}
	}
	
	/* Add the client info to the database. */
	if (NCSCC_RC_SUCCESS != m_NCS_LOCK(&cb->cb_lock,NCS_LOCK_WRITE)){
		LOG_ER("SMFA: Cb lock acquire FAILED.");
		rc = SA_AIS_ERR_NO_RESOURCES;
		goto smfa_take_lock_failed;
	}
	smfa_client_info_add(client_info);
	m_NCS_UNLOCK(&cb->cb_lock,NCS_LOCK_WRITE);
	
	/* Initialization is successful. Pass the handle to the application.*/
	*smfHandle = client_info->client_hdl;
	TRACE_2("SMFA: Handle returned: %llu.",*smfHandle);
	TRACE_LEAVE();
	return SA_AIS_OK;
	
smfa_take_lock_failed:
	m_NCS_IPC_DETACH(&client_info->cbk_mbx,smfa_client_mbx_clnup,client_info);
smfa_mbx_attach_failed:
	m_NCS_IPC_RELEASE(&client_info->cbk_mbx,NULL);
smfa_mbx_create_failed:
	if (client_info){
		free(client_info);
		client_info = NULL;
	}
smfa_init_failed:
	smfa_finalize();
	TRACE_LEAVE();
	return rc;
}
Ejemplo n.º 8
0
/**
 * Initialize immd
 * 
 * @return uns32
 */
static uns32 immd_initialize(void)
{
	uns32 rc = NCSCC_RC_SUCCESS;

	TRACE_ENTER();

	if (ncs_agents_startup() != NCSCC_RC_SUCCESS) {
		LOG_ER("ncs_agents_startup FAILED");
		goto done;
	}

	if ((rc = rda_get_role(&immd_cb->ha_state)) != NCSCC_RC_SUCCESS) {
		LOG_ER("rda_get_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;
	}

	/* Init the EDU Handle */
	m_NCS_EDU_HDL_INIT(&immd_cb->edu_hdl);

	if ((rc = immd_cb_db_init(immd_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("immd_cb_db_init FAILED");
		goto done;
	}

	/* Create a mail box */
	if ((rc = m_NCS_IPC_CREATE(&immd_cb->mbx)) != NCSCC_RC_SUCCESS) {
		LOG_ER("m_NCS_IPC_CREATE FAILED");
		goto done;
	}

	/* Attach the IPC to mail box */
	if ((rc = m_NCS_IPC_ATTACH(&immd_cb->mbx)) != NCSCC_RC_SUCCESS) {
		LOG_ER("m_NCS_IPC_ATTACH FAILED");
		goto done;
	}

	if ((rc = immd_mds_register(immd_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("immd_mds_register FAILED %d", rc);
		goto done;
	}

	/* Initialise with the MBCSV service  */
	if ((rc = immd_mbcsv_register(immd_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("immd_mbcsv_register FAILED %d", rc);
		goto done;
	}

	if ((rc = immd_mbcsv_chgrole(immd_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("immd_mbcsv_chgrole FAILED %d", rc);
		goto done;
	}

	/* Create a selection object */
	if ((rc = ncs_sel_obj_create(&immd_cb->usr1_sel_obj)) != NCSCC_RC_SUCCESS) {
		LOG_ER("ncs_sel_obj_create failed");
		goto done;
	}

	/*
	 * Initialize a signal handler that will use the selection object.
	 * The signal is sent from our script when AMF does instantiate.
	 */
	if ((signal(SIGUSR1, sigusr1_handler)) == SIG_ERR) {
		LOG_ER("signal USR1 failed: %s", strerror(errno));
		rc = NCSCC_RC_FAILURE;
		goto done;
	}

	syslog(LOG_INFO, "Initialization Success, role %s",
	       (immd_cb->ha_state == SA_AMF_HA_ACTIVE) ? "ACTIVE" : "STANDBY");

done:
	if (nid_notify("IMMD", rc, NULL) != NCSCC_RC_SUCCESS) {
		LOG_ER("nid_notify failed");
		rc = NCSCC_RC_FAILURE;
	}

	TRACE_LEAVE();
	return rc;
}
Ejemplo n.º 9
0
/*****************************************************************************

PROCEDURE NAME:       main

DESCRIPTION:          Main routine for FM

*****************************************************************************/
int main(int argc, char *argv[])
{
	NCS_SEL_OBJ mbx_sel_obj, pipe_sel_obj, highest_sel_obj;
	NCS_SEL_OBJ amf_sel_obj = {0, 0};
	NCS_SEL_OBJ_SET sel_obj_set;
	FM_EVT *fm_mbx_evt = NULL;

	daemonize(argc, argv);

	if (fm_agents_startup() != NCSCC_RC_SUCCESS) {
/* notify the NID */
		fm_nid_notify((uns32)NCSCC_RC_FAILURE);
		goto fm_agents_startup_failed;
	}

/* Allocate memory for FM_CB. */
	fm_cb = m_MMGR_ALLOC_FM_CB;
	if (NULL == fm_cb) {
/* notify the NID */
		syslog(LOG_ERR, "CB Allocation failed.");
		fm_nid_notify((uns32)NCSCC_RC_FAILURE);
		goto fm_agents_startup_failed;
	}

	memset(fm_cb, 0, sizeof(FM_CB));

/* Create CB handle */
	gl_fm_hdl = ncshm_create_hdl(NCS_HM_POOL_ID_COMMON, NCS_SERVICE_ID_GFM, (NCSCONTEXT)fm_cb);

/* Take CB handle */
	ncshm_take_hdl(NCS_SERVICE_ID_GFM, gl_fm_hdl);

	if (fm_get_args(fm_cb) != NCSCC_RC_SUCCESS) {
/* notify the NID */
		fm_nid_notify((uns32)NCSCC_RC_FAILURE);
		goto fm_get_args_failed;
	}

/* Create MBX. */
	if (m_NCS_IPC_CREATE(&fm_cb->mbx) != NCSCC_RC_SUCCESS) {
		syslog(LOG_ERR, "m_NCS_IPC_CREATE() failed.");
		fm_nid_notify((uns32)NCSCC_RC_FAILURE);
		goto fm_get_args_failed;
	}

/* Attach MBX */
	if (m_NCS_IPC_ATTACH(&fm_cb->mbx) != NCSCC_RC_SUCCESS) {
		syslog(LOG_ERR, "m_NCS_IPC_ATTACH() failed.");
		fm_nid_notify((uns32)NCSCC_RC_FAILURE);
		goto fm_mbx_attach_failure;
	}

/* MDS initialization */
	if (fm_mds_init(fm_cb) != NCSCC_RC_SUCCESS) {
		fm_nid_notify((uns32)NCSCC_RC_FAILURE);
		goto fm_mds_init_failed;
	}

/* RDA initialization */
	if (fm_rda_init(fm_cb) != NCSCC_RC_SUCCESS) {
		fm_nid_notify((uns32)NCSCC_RC_FAILURE);
		goto fm_rda_init_failed;
	}

/* Open FM pipe for receiving AMF up intimation */
	if (fm_amf_open(&fm_cb->fm_amf_cb) != NCSCC_RC_SUCCESS) {
		fm_nid_notify((uns32)NCSCC_RC_FAILURE);
		goto fm_hpl_lib_init_failed;
	}

/* Get mailbox selection object */
	mbx_sel_obj = m_NCS_IPC_GET_SEL_OBJ(&fm_cb->mbx);

/* Get pipe selection object */
	m_SET_FD_IN_SEL_OBJ(fm_cb->fm_amf_cb.pipe_fd, pipe_sel_obj);

/* Give CB hdl */
	ncshm_give_hdl(gl_fm_hdl);

/* notify the NID */
	fm_nid_notify(NCSCC_RC_SUCCESS);

/* clear selection object set */
	m_NCS_SEL_OBJ_ZERO(&sel_obj_set);

/* Set only one pipe eelection object in set */
	m_NCS_SEL_OBJ_SET(pipe_sel_obj, &sel_obj_set);

	highest_sel_obj = pipe_sel_obj;

/* Wait for pipe selection object */
	if (m_NCS_SEL_OBJ_SELECT(highest_sel_obj, &sel_obj_set, NULL, NULL, NULL) != -1) {
/* following if will be true only first time */
		if (m_NCS_SEL_OBJ_ISSET(pipe_sel_obj, &sel_obj_set)) {
/* Take handle */
			ncshm_take_hdl(NCS_SERVICE_ID_GFM, gl_fm_hdl);

/* Process the message received on pipe */
			if (fm_amf_pipe_process_msg(&fm_cb->fm_amf_cb) != NCSCC_RC_SUCCESS)
				goto done;

/* Get amf selection object */
			m_SET_FD_IN_SEL_OBJ(fm_cb->fm_amf_cb.amf_fd, amf_sel_obj);

/* Release handle */
			ncshm_give_hdl(gl_fm_hdl);
		}
	}

/* clear selection object set */
	m_NCS_SEL_OBJ_ZERO(&sel_obj_set);
	m_NCS_SEL_OBJ_SET(amf_sel_obj, &sel_obj_set);
	m_NCS_SEL_OBJ_SET(mbx_sel_obj, &sel_obj_set);
	highest_sel_obj = m_GET_HIGHER_SEL_OBJ(amf_sel_obj, mbx_sel_obj);

/* Wait infinitely on  */
	while ((m_NCS_SEL_OBJ_SELECT(highest_sel_obj, &sel_obj_set, NULL, NULL, NULL) != -1)) {
		if (m_NCS_SEL_OBJ_ISSET(mbx_sel_obj, &sel_obj_set)) {
/* Take handle */
			ncshm_take_hdl(NCS_SERVICE_ID_GFM, gl_fm_hdl);

			fm_mbx_evt = (FM_EVT *)m_NCS_IPC_NON_BLK_RECEIVE(&fm_cb->mbx, msg);
			if (fm_mbx_evt) {
				fm_mbx_msg_handler(fm_cb, fm_mbx_evt);
			}
/* Release handle */
			ncshm_give_hdl(gl_fm_hdl);
		}

		if (m_NCS_SEL_OBJ_ISSET(amf_sel_obj, &sel_obj_set)) {
/* Take handle */
			ncshm_take_hdl(NCS_SERVICE_ID_GFM, gl_fm_hdl);

/* Process the message received on amf selection object */
			fm_amf_process_msg(&fm_cb->fm_amf_cb);

/* Release handle */
			ncshm_give_hdl(gl_fm_hdl);
		}

		m_NCS_SEL_OBJ_SET(amf_sel_obj, &sel_obj_set);
		m_NCS_SEL_OBJ_SET(mbx_sel_obj, &sel_obj_set);
		highest_sel_obj = m_GET_HIGHER_SEL_OBJ(amf_sel_obj, mbx_sel_obj);
	}

	fm_amf_close(&fm_cb->fm_amf_cb);

 fm_hpl_lib_init_failed:

	fm_rda_finalize(fm_cb);

 fm_rda_init_failed:

	fm_mds_finalize(fm_cb);

 fm_mds_init_failed:

	m_NCS_IPC_DETACH(&fm_cb->mbx, NULL, NULL);

 fm_mbx_attach_failure:

	m_NCS_IPC_RELEASE(&fm_cb->mbx, NULL);

 fm_get_args_failed:

	ncshm_destroy_hdl(NCS_SERVICE_ID_GFM, gl_fm_hdl);
	gl_fm_hdl = 0;
	m_MMGR_FREE_FM_CB(fm_cb);

 fm_agents_startup_failed:

	fm_agents_shutdown();
 done:
	return 1;
}
Ejemplo n.º 10
0
/**
 * Function to init the intranode processing
 *
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
uint32_t dtm_intra_processing_init(char *node_ip, DTM_IP_ADDR_TYPE i_addr_family)
{

	int servlen, size = DTM_INTRANODE_SOCK_SIZE;	/* For socket fd and server len */
	struct sockaddr_un serv_addr;	/* For Unix Sock address */
	char server_ux_name[255];
	NCS_PATRICIA_PARAMS pat_tree_params;
	struct sockaddr_in serveraddr;
	struct sockaddr_in6 serveraddr6;
	int flags;

	TRACE_ENTER();
	/* UNIX is default transport for intranode */
	dtm_socket_domain = AF_UNIX;

	if (NULL == (dtm_intranode_cb = calloc(1, sizeof(DTM_INTRANODE_CB)))) {
		LOG_ER("DTM: Memory allocation failed for dtm_intranode_cb");
		return NCSCC_RC_FAILURE;
	}
	dtm_intranode_cb->sock_domain = dtm_socket_domain;

	/* Open a socket, If socket opens to fail return Error */
	dtm_intranode_cb->server_sockfd = socket(dtm_socket_domain, SOCK_STREAM, 0);

	if (dtm_intranode_cb->server_sockfd < 0) {
		LOG_ER("DTM: Socket creation failed err :%s ", strerror(errno));
		free(dtm_intranode_cb);
		return NCSCC_RC_FAILURE;
	}

	/*Make the socket Non-Blocking for accepting */
	if ((flags = fcntl(dtm_intranode_cb->server_sockfd, F_GETFL, NULL)) < 0) {
		LOG_ER("DTM :fcntl(F_SETFL, O_NONBLOCK) err :%s ", strerror(errno));
		return false;
	}
	flags |= O_NONBLOCK;
	if(fcntl(dtm_intranode_cb->server_sockfd, F_SETFL, flags) < 0) {
		/*Non-Blocking Options hasnt been set, what shall we do now */
		LOG_ER("DTM: Socket NON Block set failed err :%s ", strerror(errno));
		close(dtm_intranode_cb->server_sockfd);
		free(dtm_intranode_cb);
		return NCSCC_RC_FAILURE;
	}

	/* Increase the socket buffer size */
	if (setsockopt(dtm_intranode_cb->server_sockfd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)) != 0) {
		LOG_ER("DTM: Unable to set the SO_RCVBUF err :%s ", strerror(errno)); 
		close(dtm_intranode_cb->server_sockfd);
		free(dtm_intranode_cb);
		return NCSCC_RC_FAILURE;
	}
	if (setsockopt(dtm_intranode_cb->server_sockfd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) != 0) {
		LOG_ER("DTM: Unable to set the SO_SNDBUF err :%s ", strerror(errno));
		close(dtm_intranode_cb->server_sockfd);
		free(dtm_intranode_cb);
		return NCSCC_RC_FAILURE;
	}

	dtm_intranode_cb->nodeid = m_NCS_GET_NODE_ID;

	bzero((char *)&serv_addr, sizeof(serv_addr));

	if (dtm_socket_domain == AF_UNIX) {
#define UX_SOCK_NAME_PREFIX PKGLOCALSTATEDIR "/osaf_dtm_intra_server"

		sprintf(server_ux_name, "%s", UX_SOCK_NAME_PREFIX);
		serv_addr.sun_family = AF_UNIX;
		strcpy(serv_addr.sun_path, server_ux_name);

		unlink(serv_addr.sun_path);

		servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family);

		/* Bind the created socket here with the address  NODEID, 
		 *  if bind fails return error by the closing the
		 * created socket*/

		if (bind(dtm_intranode_cb->server_sockfd, (struct sockaddr *)&serv_addr, servlen) < 0) {
			LOG_ER("DTM: Bind failed err :%s ", strerror(errno));
			close(dtm_intranode_cb->server_sockfd);
			free(dtm_intranode_cb);
			return NCSCC_RC_FAILURE;
		}

		if (chmod(UX_SOCK_NAME_PREFIX, (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)) < 0) { 
			LOG_ER("chmod %s failed - %s", UX_SOCK_NAME_PREFIX, strerror(errno));
			close(dtm_intranode_cb->server_sockfd);
			free(dtm_intranode_cb);
			return NCSCC_RC_FAILURE;
		}
	} else {
 		if (dtm_socket_domain == AF_INET) {
 			memset(&serveraddr, 0, sizeof(serveraddr));
			serveraddr.sin_family      = AF_INET;
 			serveraddr.sin_port        = htons(DTM_INTRA_SERVER_PORT);
 			serveraddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
 
 			if (bind(dtm_intranode_cb->server_sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr) ) < 0) {
 				LOG_ER("DTM: Bind failed err :%s ", strerror(errno));
 				close(dtm_intranode_cb->server_sockfd);
 				free(dtm_intranode_cb);
 				return NCSCC_RC_FAILURE;
 			}
 		} else {
 			memset(&serveraddr6, 0, sizeof(serveraddr6));
 			serveraddr6.sin6_family      = AF_INET6;
 			serveraddr.sin_port        = htons(DTM_INTRA_SERVER_PORT);
 			inet_pton(AF_INET6, "localhost", &serveraddr6.sin6_addr);
 
 			if (bind(dtm_intranode_cb->server_sockfd, (struct sockaddr *)&serveraddr6, sizeof(serveraddr6) ) < 0) {
 				LOG_ER("DTM_INTRA: Bind failed");
 				close(dtm_intranode_cb->server_sockfd);
 				free(dtm_intranode_cb);
 				return NCSCC_RC_FAILURE;
 			}
 		}
	}

	listen(dtm_intranode_cb->server_sockfd, 20);
	memset(&pat_tree_params, 0, sizeof(pat_tree_params));
	pat_tree_params.key_size = sizeof(uint32_t);
	if (NCSCC_RC_SUCCESS != ncs_patricia_tree_init(&dtm_intranode_cb->dtm_intranode_pid_list, &pat_tree_params)) {
		LOG_ER("DTM: ncs_patricia_tree_init failed for dtm_intranode_pid_list");
		close(dtm_intranode_cb->server_sockfd);
		free(dtm_intranode_cb);
		return NCSCC_RC_FAILURE;
	}

	pat_tree_params.key_size = sizeof(int);
	if (NCSCC_RC_SUCCESS != ncs_patricia_tree_init(&dtm_intranode_cb->dtm_intranode_fd_list, &pat_tree_params)) {
		LOG_ER("DTM: ncs_patricia_tree_init failed for dtm_intranode_pid_list");
		close(dtm_intranode_cb->server_sockfd);
		free(dtm_intranode_cb);
		return NCSCC_RC_FAILURE;
	}

	pat_tree_params.key_size = sizeof(uint32_t);
	if (NCSCC_RC_SUCCESS != ncs_patricia_tree_init(&dtm_intranode_cb->dtm_svc_subscr_list, &pat_tree_params)) {
		LOG_ER("DTM: ncs_patricia_tree_init failed for dtm_intranode_pid_list");
		close(dtm_intranode_cb->server_sockfd);
		free(dtm_intranode_cb);
		return NCSCC_RC_FAILURE;
	}

	pat_tree_params.key_size = sizeof(uint32_t);
	if (NCSCC_RC_SUCCESS != ncs_patricia_tree_init(&dtm_intranode_cb->dtm_svc_install_list, &pat_tree_params)) {
		LOG_ER("DTM: ncs_patricia_tree_init failed for dtm_intranode_pid_list");
		close(dtm_intranode_cb->server_sockfd);
		free(dtm_intranode_cb);
		return NCSCC_RC_FAILURE;
	}

	dtm_intranode_add_self_node_to_node_db(dtm_intranode_cb->nodeid, node_ip, i_addr_family);

	if (m_NCS_IPC_CREATE(&dtm_intranode_cb->mbx) != NCSCC_RC_SUCCESS) {
		/* Mail box creation failed */
		LOG_ER("DTM : Intranode Mailbox Creation failed");
		close(dtm_intranode_cb->server_sockfd);
		free(dtm_intranode_cb);
		return NCSCC_RC_FAILURE;
	} else {

		NCS_SEL_OBJ obj;

		/* Code added for attaching the mailbox, to eliminate the DBG Print at sysf_ipc.c: 640 */
		if (NCSCC_RC_SUCCESS != m_NCS_IPC_ATTACH(&dtm_intranode_cb->mbx)) {
			m_NCS_IPC_RELEASE(&dtm_intranode_cb->mbx, NULL);
			close(dtm_intranode_cb->server_sockfd);
			free(dtm_intranode_cb);
			LOG_ER("DTM: Intranode Mailbox  Attach failed");
			return NCSCC_RC_FAILURE;
		}

		obj = m_NCS_IPC_GET_SEL_OBJ(&dtm_intranode_cb->mbx);

		/* retreive the corresponding fd for mailbox and fill it in cb */
		dtm_intranode_cb->mbx_fd = m_GET_FD_FROM_SEL_OBJ(obj);	/* extract and fill value needs to be extracted */
	}

	dtm_intranode_add_poll_fdlist(dtm_intranode_cb->server_sockfd, POLLIN);
	dtm_intranode_add_poll_fdlist(dtm_intranode_cb->mbx_fd, POLLIN);

	if (dtm_intranode_create_rcv_task(dtm_intranode_cb->task_hdl) != NCSCC_RC_SUCCESS) {
		LOG_ER("MDS:MDTM: Receive Task Creation Failed in MDTM_INIT\n");
		close(dtm_intranode_cb->server_sockfd);
		free(dtm_intranode_cb);
		return NCSCC_RC_FAILURE;
	}

	TRACE_LEAVE();
	return NCSCC_RC_SUCCESS;

}
Ejemplo n.º 11
0
/****************************************************************************
 * Name          : gld_se_lib_init
 *
 * Description   : Invoked to Initialize the GLD
 *                 
 *
 * Arguments     : 
 * Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE..
 *
 * Notes         : None.
 *****************************************************************************/
uns32 gld_se_lib_init(NCS_LIB_REQ_INFO *req_info)
{
	GLSV_GLD_CB *gld_cb;
	SaAisErrorT amf_error;
	uns32 res = NCSCC_RC_SUCCESS;
	SaAmfHealthcheckKeyT Healthy;
	int8 *health_key;

	/* Register with Logging subsystem */
	if (NCS_GLSV_LOG == 1)
		gld_flx_log_reg();

	/* Allocate and initialize the control block */
	gld_cb = m_MMGR_ALLOC_GLSV_GLD_CB;

	if (gld_cb == NULL) {
		m_LOG_GLD_MEMFAIL(GLD_CB_ALLOC_FAILED, __FILE__, __LINE__);
		return NCSCC_RC_FAILURE;
	}
	memset(gld_cb, 0, sizeof(GLSV_GLD_CB));

	/* TBD- Pool id is to be set */
	gl_gld_hdl = gld_cb->my_hdl = ncshm_create_hdl(gld_cb->hm_poolid, NCS_SERVICE_ID_GLD, (NCSCONTEXT)gld_cb);
	if (0 == gld_cb->my_hdl) {
		m_LOG_GLD_HEADLINE(GLD_CREATE_HANDLE_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__, 0);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return NCSCC_RC_FAILURE;
	}

	/* Initialize the cb parameters */
	if (gld_cb_init(gld_cb) != NCSCC_RC_SUCCESS) {
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return NCSCC_RC_FAILURE;
	}

	/* Initialize amf framework */
	if (gld_amf_init(gld_cb) != NCSCC_RC_SUCCESS) {
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_INIT_ERROR, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return NCSCC_RC_FAILURE;
	}
	m_LOG_GLD_SVC_PRVDR(GLD_AMF_INIT_SUCCESS, NCSFL_SEV_INFO, __FILE__, __LINE__);

	/* Bind to MDS */
	if (gld_mds_init(gld_cb) != NCSCC_RC_SUCCESS) {
		saAmfFinalize(gld_cb->amf_hdl);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		m_LOG_GLD_SVC_PRVDR(GLD_MDS_INSTALL_FAIL, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		return NCSCC_RC_FAILURE;
	} else
		m_LOG_GLD_SVC_PRVDR(GLD_MDS_INSTALL_SUCCESS, NCSFL_SEV_INFO, __FILE__, __LINE__);

	/*   Initialise with the MBCSV service  */
	if (glsv_gld_mbcsv_register(gld_cb) != NCSCC_RC_SUCCESS) {
		m_LOG_GLD_MBCSV(GLD_MBCSV_INIT_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		gld_mds_shut(gld_cb);
		saAmfFinalize(gld_cb->amf_hdl);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return NCSCC_RC_FAILURE;

	} else {
		m_LOG_GLD_MBCSV(GLD_MBCSV_INIT_SUCCESS, NCSFL_SEV_INFO, __FILE__, __LINE__);

	}

	/* register glsv with imm */
	amf_error = gld_imm_init(gld_cb);
	if (amf_error != SA_AIS_OK) {
		glsv_gld_mbcsv_unregister(gld_cb);
		gld_mds_shut(gld_cb);
		saAmfFinalize(gld_cb->amf_hdl);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		gld_log(NCSFL_SEV_ERROR, "Imm Init Failed %u\n", amf_error);
		return NCSCC_RC_FAILURE;
	}

	/* TASK CREATION AND INITIALIZING THE MAILBOX */
	if ((m_NCS_IPC_CREATE(&gld_cb->mbx) != NCSCC_RC_SUCCESS) ||
	    (m_NCS_IPC_ATTACH(&gld_cb->mbx) != NCSCC_RC_SUCCESS) ||
	    (m_NCS_TASK_CREATE((NCS_OS_CB)gld_main_process,
			       &gld_cb->mbx, "GLD", m_GLD_TASK_PRIORITY,
			       m_GLD_STACKSIZE,
			       &gld_cb->task_hdl) != NCSCC_RC_SUCCESS) ||
	    (m_NCS_TASK_START(gld_cb->task_hdl) != NCSCC_RC_SUCCESS)) {
		m_LOG_GLD_HEADLINE(GLD_IPC_TASK_INIT, NCSFL_SEV_ERROR, __FILE__, __LINE__, 0);
		saImmOiFinalize(gld_cb->immOiHandle);
		glsv_gld_mbcsv_unregister(gld_cb);
		gld_mds_shut(gld_cb);
		saAmfFinalize(gld_cb->amf_hdl);
		m_NCS_TASK_RELEASE(gld_cb->task_hdl);
		m_NCS_IPC_RELEASE(&gld_cb->mbx, NULL);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return (NCSCC_RC_FAILURE);
	}

	m_NCS_EDU_HDL_INIT(&gld_cb->edu_hdl);

	/* register GLD component with AvSv */
	amf_error = saAmfComponentRegister(gld_cb->amf_hdl, &gld_cb->comp_name, (SaNameT *)NULL);
	if (amf_error != SA_AIS_OK) {
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_REG_ERROR, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		m_NCS_EDU_HDL_FLUSH(&gld_cb->edu_hdl);
		m_NCS_TASK_RELEASE(gld_cb->task_hdl);
		m_NCS_IPC_RELEASE(&gld_cb->mbx, NULL);
		saImmOiFinalize(gld_cb->immOiHandle);
		glsv_gld_mbcsv_unregister(gld_cb);
		gld_mds_shut(gld_cb);
		saAmfFinalize(gld_cb->amf_hdl);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
		return NCSCC_RC_FAILURE;
	} else
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_REG_SUCCESS, NCSFL_SEV_INFO, __FILE__, __LINE__);

   /** start the AMF health check **/
	memset(&Healthy, 0, sizeof(Healthy));
	health_key = (int8 *)getenv("GLSV_ENV_HEALTHCHECK_KEY");
	if (health_key == NULL) {
		if (strlen("A1B2") < sizeof(Healthy.key))
			strncpy((char *)Healthy.key, "A1B2", sizeof(Healthy.key));
		m_LOG_GLD_HEADLINE(GLD_HEALTH_KEY_DEFAULT_SET, NCSFL_SEV_INFO, __FILE__, __LINE__, 0);
	} else {
		if (strlen((char *)health_key) < sizeof(Healthy.key))
			strncpy((char *)Healthy.key, (char *)health_key, SA_AMF_HEALTHCHECK_KEY_MAX - 1);
	}
	Healthy.keyLen = strlen((char *)Healthy.key);

	amf_error = saAmfHealthcheckStart(gld_cb->amf_hdl, &gld_cb->comp_name, &Healthy,
					  SA_AMF_HEALTHCHECK_AMF_INVOKED, SA_AMF_COMPONENT_FAILOVER);
	if (amf_error != SA_AIS_OK) {
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_HLTH_CHK_START_FAIL, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		saAmfComponentUnregister(gld_cb->amf_hdl, &gld_cb->comp_name, (SaNameT *)NULL);
		m_NCS_EDU_HDL_FLUSH(&gld_cb->edu_hdl);
		m_NCS_TASK_RELEASE(gld_cb->task_hdl);
		m_NCS_IPC_RELEASE(&gld_cb->mbx, NULL);
		saImmOiFinalize(gld_cb->immOiHandle);
		glsv_gld_mbcsv_unregister(gld_cb);
		gld_mds_shut(gld_cb);
		saAmfFinalize(gld_cb->amf_hdl);
		m_MMGR_FREE_GLSV_GLD_CB(gld_cb);
	} else
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_HLTH_CHK_START_DONE, NCSFL_SEV_INFO, __FILE__, __LINE__);

	return (res);
}
Ejemplo n.º 12
0
/****************************************************************************
  Name          : ntfa_hdl_rec_add
 
  Description   : This routine adds the handle record to the ntfa cb.
 
  Arguments     : cb       - ptr tot he NTFA control block
                  reg_cbks - ptr to the set of registered callbacks
                  client_id   - obtained from NTFS.
 
  Return Values : ptr to the ntfa handle record
 
  Notes         : None
******************************************************************************/
ntfa_client_hdl_rec_t *ntfa_hdl_rec_add(ntfa_cb_t *cb, const SaNtfCallbacksT *reg_cbks, uns32 client_id)
{
	ntfa_client_hdl_rec_t *rec = calloc(1, sizeof(ntfa_client_hdl_rec_t));

	if (rec == NULL) {
		TRACE("calloc failed");
		goto done;
	}

	/* create the association with hdl-mngr */
	if (0 == (rec->local_hdl = ncshm_create_hdl(NCS_HM_POOL_ID_COMMON, NCS_SERVICE_ID_NTFA, (NCSCONTEXT)rec))) {
		TRACE("ncshm_create_hdl failed");
		goto err_free;
	}

	/* store the registered callbacks */
	if (reg_cbks)
		memcpy((void *)&rec->reg_cbk, (void *)reg_cbks, sizeof(SaNtfCallbacksT));

    /** Associate with the client_id obtained from NTFS
     **/
	rec->ntfs_client_id = client_id;

    /** Initialize and attach the IPC/Priority queue
     **/

	if (m_NCS_IPC_CREATE(&rec->mbx) != NCSCC_RC_SUCCESS) {
		TRACE("m_NCS_IPC_CREATE failed");
		goto err_destroy_hdl;
	}

	if (m_NCS_IPC_ATTACH(&rec->mbx) != NCSCC_RC_SUCCESS) {
		TRACE("m_NCS_IPC_ATTACH failed");
		goto err_ipc_release;
	}

    /** Add this to the Link List of 
     ** CLIENT_HDL_RECORDS for this NTFA_CB 
     **/

	pthread_mutex_lock(&cb->cb_lock);
	/* add this to the start of the list */
	rec->next = cb->client_list;
	cb->client_list = rec;
	pthread_mutex_unlock(&cb->cb_lock);

	goto done;

 err_ipc_release:
	(void)m_NCS_IPC_RELEASE(&rec->mbx, NULL);

 err_destroy_hdl:
	ncshm_destroy_hdl(NCS_SERVICE_ID_NTFA, rec->local_hdl);

 err_free:
	free(rec);
	rec = NULL;

 done:
	return rec;
}
Ejemplo n.º 13
0
/****************************************************************************
 * Name          : dts_lib_init
 *
 * Description   : This is the function which initalize the dts libarary.
 *                 This function creates an IPC mail Box and spawns DTS
 *                 thread.
 *                 This function initializes the CB, handle manager and MDS.
 *
 * Arguments     : req_info - Request info.
 *
 * Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
 *
 * Notes         : None.
 *****************************************************************************/
uns32 dts_lib_init(NCS_LIB_REQ_INFO *req_info)
{
	NCSCONTEXT task_handle;
	DTS_CB *inst = &dts_cb;
	PCS_RDA_REQ pcs_rda_req;
	uns32 rc = NCSCC_RC_SUCCESS;

	memset(inst, 0, sizeof(DTS_CB));

#if (DTS_SIM_TEST_ENV == 1)
	if ('n' == ncs_util_get_char_option(req_info->info.create.argc, req_info->info.create.argv, "DTS_TEST=")) {
		inst->is_test = FALSE;
	} else
		inst->is_test = TRUE;
#endif

	/* Initialize SAF stuff */
	/* Fill in the Health check key */
	strcpy((char *)inst->health_chk_key.key, DTS_AMF_HEALTH_CHECK_KEY);
	inst->health_chk_key.keyLen = strlen((char *)inst->health_chk_key.key);

	inst->invocationType = DTS_HB_INVOCATION_TYPE;
	/* Recommended recovery is to failover */
	inst->recommendedRecovery = DTS_RECOVERY;

	/* RDA init */
	memset(&pcs_rda_req, '\0', sizeof(pcs_rda_req));
	pcs_rda_req.req_type = PCS_RDA_LIB_INIT;
	rc = pcs_rda_request(&pcs_rda_req);
	if (rc != PCSRDA_RC_SUCCESS) {
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_lib_init: pcs_rda_request() failed for PCS_RDA_LIB_INIT");
	}

	/* Get initial role from RDA */
	memset(&pcs_rda_req, '\0', sizeof(pcs_rda_req));
	pcs_rda_req.req_type = PCS_RDA_GET_ROLE;
	rc = pcs_rda_request(&pcs_rda_req);
	if (rc != PCSRDA_RC_SUCCESS) {
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_lib_init: Failed to get initial role from RDA");
	}

	/* Set initial role now */
	switch (pcs_rda_req.info.io_role) {
	case PCS_RDA_ACTIVE:
		inst->ha_state = SA_AMF_HA_ACTIVE;
		m_DTS_DBG_SINK(NCSCC_RC_SUCCESS, "DTS init role is ACTIVE");
		m_LOG_DTS_API(DTS_INIT_ROLE_ACTIVE);
		break;
	case PCS_RDA_STANDBY:
		inst->ha_state = SA_AMF_HA_STANDBY;
		m_DTS_DBG_SINK(NCSCC_RC_SUCCESS, "DTS init role is STANDBY");
		m_LOG_DTS_API(DTS_INIT_ROLE_STANDBY);
		break;
	default:
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_lib_init: Failed to get initial role from RDA");
	}

	/* RDA finalize */
	memset(&pcs_rda_req, '\0', sizeof(pcs_rda_req));
	pcs_rda_req.req_type = PCS_RDA_LIB_DESTROY;
	rc = pcs_rda_request(&pcs_rda_req);
	if (rc != PCSRDA_RC_SUCCESS) {
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_lib_init: Failed to perform lib destroy on RDA");
	}

	inst->in_sync = TRUE;

	/* Attempt to open console device for logging */
	inst->cons_fd = -1;
	if ((inst->cons_fd = dts_cons_open(O_RDWR | O_NOCTTY)) < 0) {
		/* Should we return frm here on failure?? I guess NOT */
		m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_lib_init: Failed to open console");
	}

	/* Create DTS mailbox */
	if (m_NCS_IPC_CREATE(&gl_dts_mbx) != NCSCC_RC_SUCCESS) {
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_lib_init: Failed to create DTS mail box");
	}

	if (NCSCC_RC_SUCCESS != m_NCS_IPC_ATTACH(&gl_dts_mbx)) {
		m_NCS_IPC_RELEASE(&gl_dts_mbx, NULL);
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_lib_init: IPC attach failed.");
	}
#if (DTS_FLOW == 1)
	/* Keeping count of messages in DTS mailbox */
	if (NCSCC_RC_SUCCESS != m_NCS_IPC_CONFIG_USR_COUNTERS(&gl_dts_mbx, NCS_IPC_PRIORITY_LOW, &inst->msg_count)) {
		m_NCS_IPC_DETACH(&gl_dts_mbx, dts_clear_mbx, inst);
		m_NCS_IPC_RELEASE(&gl_dts_mbx, NULL);
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE,
				      "dts_lib_init: Failed to initialize DTS msg counters with LEAP");
	}
#endif

	/* Smik - initialize the signal handler */
	if ((dts_app_signal_install(SIGUSR1, dts_amf_sigusr1_handler)) == -1) {
		m_NCS_IPC_DETACH(&gl_dts_mbx, dts_clear_mbx, inst);
		m_NCS_IPC_RELEASE(&gl_dts_mbx, NULL);
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_lib_init: Failed to install signal handler");
	}

	{
		DTS_LM_ARG arg;
		memset(&arg, 0, sizeof(DTS_LM_ARG));

		arg.i_op = DTS_LM_OP_CREATE;
		arg.info.create.i_hmpool_id = NCS_HM_POOL_ID_COMMON;
		arg.info.create.i_vrid = 1;
		arg.info.create.task_handle = task_handle;

		/* Now create and initialize DTS control block */
		if (dts_lm(&arg) != NCSCC_RC_SUCCESS) {
			m_NCS_IPC_DETACH(&gl_dts_mbx, dts_clear_mbx, inst);
			m_NCS_IPC_RELEASE(&gl_dts_mbx, NULL);
			return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_lib_init: Failed to create and init DTS CB");
		}
	}

	/* Create DTS's task */
	if (m_NCS_TASK_CREATE((NCS_OS_CB)dts_do_evts,
			      &gl_dts_mbx, NCS_DTS_TASKNAME,
			      NCS_DTS_PRIORITY, NCS_DTS_STACKSIZE, &task_handle) != NCSCC_RC_SUCCESS) {
		m_NCS_IPC_DETACH(&gl_dts_mbx, dts_clear_mbx, inst);
		m_NCS_IPC_RELEASE(&gl_dts_mbx, NULL);
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_lib_init: Failed to create DTS thread.");
	}

	/* Start DTS task */
	if (m_NCS_TASK_START(task_handle) != NCSCC_RC_SUCCESS) {
		m_NCS_TASK_RELEASE(task_handle);
		m_NCS_IPC_DETACH(&gl_dts_mbx, dts_clear_mbx, inst);
		m_NCS_IPC_RELEASE(&gl_dts_mbx, NULL);
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_lib_init: Failed to start DTS task");
	}

	inst->task_handle = task_handle;

	if (dts_log_bind() != NCSCC_RC_SUCCESS) {
		m_DTS_LK(&inst->lock);
		m_LOG_DTS_LOCK(DTS_LK_LOCKED, &inst->lock);
		/* Do cleanup activities */
		m_NCS_TASK_STOP(task_handle);
		m_NCS_TASK_RELEASE(task_handle);
		m_NCS_IPC_DETACH(&gl_dts_mbx, dts_clear_mbx, inst);
		m_NCS_IPC_RELEASE(&gl_dts_mbx, NULL);
		inst->created = FALSE;
		dtsv_mbcsv_deregister(inst);
		dts_mds_unreg(inst, TRUE);
		dtsv_clear_asciispec_tree(inst);
		dtsv_clear_libname_tree(inst);
		ncs_patricia_tree_destroy(&inst->svcid_asciispec_tree);
		ncs_patricia_tree_destroy(&inst->libname_asciispec_tree);
		ncs_patricia_tree_destroy(&inst->svc_tbl);
		ncs_patricia_tree_destroy(&inst->dta_list);
		m_DTS_UNLK(&inst->lock);
		m_LOG_DTS_LOCK(DTS_LK_UNLOCKED, &inst->lock);
		return m_DTS_DBG_SINK(NCSCC_RC_FAILURE, "dts_lib_init: Unable to bind DTS with DTSv");
	}

	return NCSCC_RC_SUCCESS;
}
Ejemplo n.º 14
0
/****************************************************************************
  Name          : eda_hdl_rec_add
 
  Description   : This routine adds the handle record to the eda cb.
 
  Arguments     : cb       - ptr tot he EDA control block
                  reg_cbks - ptr to the set of registered callbacks
                  reg_id   - obtained from EDS.
                  version  - version of the client.
 
  Return Values : ptr to the eda handle record
 
  Notes         : None
******************************************************************************/
EDA_CLIENT_HDL_REC *eda_hdl_rec_add(EDA_CB **eda_cb, const SaEvtCallbacksT *reg_cbks, uns32 reg_id, SaVersionT version)
{
	EDA_CLIENT_HDL_REC *rec = 0;

	/* allocate the hdl rec */
	if (NULL == (rec = m_MMGR_ALLOC_EDA_CLIENT_HDL_REC)) {
		m_LOG_EDSV_A(EDA_MEMALLOC_FAILED, NCSFL_LC_EDSV_INIT, NCSFL_SEV_ERROR, 0, __FILE__, __LINE__, 0);
		goto error;
	}

	memset(rec, '\0', sizeof(EDA_CLIENT_HDL_REC));

	/* create the association with hdl-mngr */
	if (0 == (rec->local_hdl = ncshm_create_hdl((*eda_cb)->pool_id, NCS_SERVICE_ID_EDA, (NCSCONTEXT)rec))) {
		m_LOG_EDSV_A(EDA_FAILURE, NCSFL_LC_EDSV_INIT, NCSFL_SEV_ERROR, 0, __FILE__, __LINE__, 0);
		goto error;
	}

	/* store the registered callbacks */
	if (reg_cbks)
		memcpy((void *)&rec->reg_cbk, (void *)reg_cbks, sizeof(SaEvtCallbacksT));

   /** Associate with the reg_id obtained from EDS
    **/
	rec->eds_reg_id = reg_id;
	rec->version.releaseCode = version.releaseCode;
	rec->version.majorVersion = version.majorVersion;
	rec->version.minorVersion = version.minorVersion;

   /** Initialize and attach the IPC/Priority queue
    **/
	if (m_NCS_IPC_CREATE(&rec->mbx) != NCSCC_RC_SUCCESS) {
		m_LOG_EDSV_A(EDA_FAILURE, NCSFL_LC_EDSV_INIT, NCSFL_SEV_ERROR, 0, __FILE__, __LINE__, 0);
		goto error;
	}
	if (m_NCS_IPC_ATTACH(&rec->mbx) != NCSCC_RC_SUCCESS) {
		m_LOG_EDSV_A(EDA_FAILURE, NCSFL_LC_EDSV_INIT, NCSFL_SEV_ERROR, 0, __FILE__, __LINE__, 0);
		goto error;
	}
   /** Add this to the Link List of 
    ** CLIENT_HDL_RECORDS for this EDA_CB 
    **/

	m_NCS_LOCK(&((*eda_cb)->cb_lock), NCS_LOCK_WRITE);
	/* add this to the start of the list */
	rec->next = (*eda_cb)->eda_init_rec_list;
	(*eda_cb)->eda_init_rec_list = rec;
	m_NCS_UNLOCK(&((*eda_cb)->cb_lock), NCS_LOCK_WRITE);

	return rec;

 error:
	if (rec) {
		/* remove the association with hdl-mngr */
		if (rec->local_hdl)
			ncshm_destroy_hdl(NCS_SERVICE_ID_EDA, rec->local_hdl);

      /** detach and release the IPC 
       **/
		m_NCS_IPC_DETACH(&rec->mbx, eda_clear_mbx, NULL);
		m_NCS_IPC_RELEASE(&rec->mbx, NULL);

		m_MMGR_FREE_EDA_CLIENT_HDL_REC(rec);
	}
	return NULL;
}
Ejemplo n.º 15
0
/****************************************************************************
 * 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);
}
Ejemplo n.º 16
0
/**
 * Initialize smfd
 * 
 * @return uns32
 */
static uns32 initialize_smfd(void)
{
	uns32 rc;

	TRACE_ENTER();

	/* Set the behaviour of SMF-IMM interactions */
	immutilWrapperProfile.errorsAreFatal = 0;   /* False, no reboot when fail */
	immutilWrapperProfile.nTries         = 500; /* Times */
	immutilWrapperProfile.retryInterval  = 400; /* MS */

	if (ncs_agents_startup() != NCSCC_RC_SUCCESS) {
		LOG_ER("ncs_agents_startup FAILED");
		rc = NCSCC_RC_FAILURE;
		goto done;
	}

	/* Initialize smfd control block */
	if (smfd_cb_init(smfd_cb) != NCSCC_RC_SUCCESS) {
		TRACE("smfd_cb_init FAILED");
		rc = NCSCC_RC_FAILURE;
		goto done;
	}

	/* Create the mailbox used for communication with SMFND */
	if ((rc = m_NCS_IPC_CREATE(&smfd_cb->mbx)) != NCSCC_RC_SUCCESS) {
		LOG_ER("m_NCS_IPC_CREATE FAILED %d", rc);
		goto done;
	}

	/* Attach mailbox to this thread */
	if ((rc = m_NCS_IPC_ATTACH(&smfd_cb->mbx) != NCSCC_RC_SUCCESS)) {
		LOG_ER("m_NCS_IPC_ATTACH FAILED %d", rc);
		goto done;
	}

	/* Create a selection object for USR1 signal handling */
	if ((rc =
	     ncs_sel_obj_create(&smfd_cb->usr1_sel_obj)) != NCSCC_RC_SUCCESS) {
		LOG_ER("ncs_sel_obj_create failed");
		goto done;
	}

	/* Init mds communication */
	if ((rc = smfd_mds_init(smfd_cb)) != NCSCC_RC_SUCCESS) {
		TRACE("smfd_mds_init FAILED %d", rc);
		return rc;
	}

	/* Init campaign OI */
	if ((rc = campaign_oi_init(smfd_cb)) != NCSCC_RC_SUCCESS) {
		TRACE("campaign_oi_init FAILED %d", rc);
		return rc;
	}

	/* Check if AMF started */
	if (smfd_cb->nid_started == 0) {
		/* Started by AMF, so let's init AMF */
		if ((rc = smfd_amf_init(smfd_cb)) != NCSCC_RC_SUCCESS) {
			LOG_ER("init amf failed");
			goto done;
		}
	}

 done:
	TRACE_LEAVE();
	return (rc);
}
Ejemplo n.º 17
0
/**
 * Initialize clm
 * 
 * @return uns32
 */
static uint32_t clms_init(void)
{
	uint32_t rc = NCSCC_RC_FAILURE;

	TRACE_ENTER();

	/* Determine how this process was started, by NID or AMF */
	if (getenv("SA_AMF_COMPONENT_NAME") == NULL)
		clms_cb->nid_started = true;

	if (ncs_agents_startup() != NCSCC_RC_SUCCESS) {
		TRACE("ncs_core_agents_startup FAILED");
		goto done;
	}

	/* Initialize clms control block */
	if ((rc = clms_cb_init(clms_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("clms_cb_init FAILED");
		goto done;
	}

	if ((rc = rda_get_role(&clms_cb->ha_state)) != NCSCC_RC_SUCCESS) {
		LOG_ER("rda_get_role FAILED");
		goto done;
	}
	TRACE("Current RDA Role %d", clms_cb->ha_state);

	if ((rc = rda_register_callback(0, rda_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("rda_register_callback FAILED %u", rc);
		goto done;
	}

	/* Create the mailbox used for communication with CLMS */
	if ((rc = m_NCS_IPC_CREATE(&clms_cb->mbx)) != NCSCC_RC_SUCCESS) {
		LOG_ER("m_NCS_IPC_CREATE FAILED %d", rc);
		goto done;
	}

	/* Attach mailbox to this thread */
	if ((rc = m_NCS_IPC_ATTACH(&clms_cb->mbx) != NCSCC_RC_SUCCESS)) {
		LOG_ER("m_NCS_IPC_ATTACH FAILED %d", rc);
		goto done;
	}

	/*Initialize mds */
	if ((rc = clms_mds_init(clms_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("clms_mds_init FAILED %d", rc);
		goto done;
	}

	/* Initialize with MBCSV */
	if ((rc = clms_mbcsv_init(clms_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("clms_mbcsv_init FAILED");
		goto done;
	}

	/* Initialize with IMMSv */
	if ((rc = clms_imm_init(clms_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("clms_imm_init FAILED");
		goto done;
	}

	/* Declare as implementer && Read configuration data from IMM */
	if ((rc = clms_imm_activate(clms_cb)) != SA_AIS_OK) {
		LOG_ER("clms_imm_activate FAILED");
		goto done;
	}

	if ((rc = clms_ntf_init(clms_cb)) != SA_AIS_OK) {
		LOG_ER("clms_ntf_init FAILED");
		goto done;
	}

#ifdef ENABLE_AIS_PLM
	if ((rc = clms_plm_init(clms_cb)) != SA_AIS_OK) {
		LOG_ER("clms_plm_init FAILED");
		goto done;
	}
#endif

	/*Self Node update */
	if ((rc = clms_self_node_info()) != NCSCC_RC_SUCCESS)
		goto done;

	/* Create a selection object */
	if (clms_cb->nid_started &&
		(rc = ncs_sel_obj_create(&usr1_sel_obj)) != NCSCC_RC_SUCCESS) {
		LOG_ER("ncs_sel_obj_create failed");
		goto done;
	}

	/*
	 ** Initialize a signal handler that will use the selection object.
	 ** The signal is sent from our script when AMF does instantiate.
	 */
	if (clms_cb->nid_started &&
		signal(SIGUSR1, sigusr1_handler) == SIG_ERR) {
		LOG_ER("signal USR1 failed: %s", strerror(errno));
		goto done;
	}

	if (!clms_cb->nid_started &&
		clms_amf_init(clms_cb) != NCSCC_RC_SUCCESS) {
		LOG_ER("AMF Initialization failed");
		goto done;
	}

	/* Initialize with saflog. This is necessary to avoid
	 *  getting blocked by LOG during role change (switchover/failover)
	 */
	saflog_init();

	rc = NCSCC_RC_SUCCESS;

 done:
	if (clms_cb->nid_started &&
		nid_notify("CLMD", rc, NULL) != NCSCC_RC_SUCCESS) {
		LOG_ER("nid_notify failed");
		rc = NCSCC_RC_FAILURE;
	}

	TRACE_LEAVE();
	return rc;
}
Ejemplo n.º 18
0
/****************************************************************************
 * Name          : glnd_cb_create
 *
 * Description   : This will create the CB and create the internal structures
 *
 * Arguments     : pool id - pool id for the handle manager
 *
 * Return Values : GLND CB Pointer
 *
 * Notes         : None.
 *****************************************************************************/
GLND_CB *glnd_cb_create(uns32 pool_id)
{
	GLND_CB *glnd_cb = NULL;
	NCS_PATRICIA_PARAMS params = { 0 };
	SaAmfHealthcheckKeyT healthy;
	int8 *health_key = NULL;
	SaAisErrorT amf_error;

	/* register with the Log service */
	glnd_flx_log_reg();

	/* allocate the memory */
	glnd_cb = m_MMGR_ALLOC_GLND_CB;

	if (!glnd_cb) {
		m_LOG_GLND_MEMFAIL(GLND_CB_ALLOC_FAILED, __FILE__, __LINE__);
		glnd_flx_log_dereg();
		return NULL;
	}

	memset(glnd_cb, 0, sizeof(GLND_CB));
	glnd_cb->pool_id = pool_id;

	/* create the handle */
	glnd_cb->cb_hdl_id = ncshm_create_hdl((uns8)pool_id, NCS_SERVICE_ID_GLND, (NCSCONTEXT)glnd_cb);
	if (!glnd_cb->cb_hdl_id) {
		m_LOG_GLND_HEADLINE(GLND_CB_TAKE_HANDLE_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		goto hdl_err;
	}

	/* create the internal strucutures */
	/* create the client Tree */
	params.key_size = sizeof(SaLckHandleT);
	params.info_size = 0;
	if ((ncs_patricia_tree_init(&glnd_cb->glnd_client_tree, &params)) != NCSCC_RC_SUCCESS) {
		m_LOG_GLND_HEADLINE(GLND_CLIENT_TREE_INIT_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		goto client_err;
	}

	/* create the agent tree */
	params.key_size = sizeof(MDS_DEST);
	params.info_size = 0;
	if ((ncs_patricia_tree_init(&glnd_cb->glnd_agent_tree, &params)) != NCSCC_RC_SUCCESS) {
		m_LOG_GLND_HEADLINE(GLND_AGENT_TREE_INIT_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		goto agent_err;
	}

	/* create the Resource tree */
	params.key_size = sizeof(SaLckResourceIdT);
	params.info_size = 0;
	if ((ncs_patricia_tree_init(&glnd_cb->glnd_res_tree, &params)) != NCSCC_RC_SUCCESS) {
		m_LOG_GLND_HEADLINE(GLND_RSC_TREE_INIT_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		goto res_err;
	}

	/* create the mail box and attach it */
	if (m_NCS_IPC_CREATE(&glnd_cb->glnd_mbx) != NCSCC_RC_SUCCESS) {
		m_LOG_GLND_HEADLINE(GLND_IPC_CREATE_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		goto mbx_create_err;
	}

	if (m_NCS_IPC_ATTACH(&glnd_cb->glnd_mbx) != NCSCC_RC_SUCCESS) {
		m_LOG_GLND_HEADLINE(GLND_IPC_ATTACH_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		goto mbx_attach_err;
	}

	/* EDU initialisation */
	m_NCS_EDU_HDL_INIT(&glnd_cb->glnd_edu_hdl);

	/* resigter with the MDS */
	if (glnd_mds_register(glnd_cb) != NCSCC_RC_SUCCESS) {
		m_LOG_GLND_HEADLINE(GLND_MDS_REGISTER_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		goto mds_err;
	} else
		m_LOG_GLND_HEADLINE(GLND_MDS_REGISTER_SUCCESS, NCSFL_SEV_NOTICE, __FILE__, __LINE__);

	/* Initialise with the AMF service */
	if (glnd_amf_init(glnd_cb) != NCSCC_RC_SUCCESS) {
		m_LOG_GLND_HEADLINE(GLND_AMF_INIT_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		goto amf_init_err;
	} else
		m_LOG_GLND_HEADLINE(GLND_AMF_INIT_SUCCESS, NCSFL_SEV_NOTICE, __FILE__, __LINE__);

	/* register with the AMF service */
	if (glnd_amf_register(glnd_cb) != NCSCC_RC_SUCCESS) {
		m_LOG_GLND_HEADLINE(GLND_AMF_REGISTER_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		goto amf_reg_err;
	} else
		m_LOG_GLND_HEADLINE(GLND_AMF_REGISTER_SUCCESS, NCSFL_SEV_NOTICE, __FILE__, __LINE__);

	/* everything went off well.. store the hdl in the global variable */
	gl_glnd_hdl = glnd_cb->cb_hdl_id;

	/*   start the AMF Health Check  */

	memset(&healthy, 0, sizeof(healthy));

	health_key = (int8 *)getenv("GLSV_ENV_HEALTHCHECK_KEY");
	if (health_key == NULL) {
		if (strlen("A1B2") < sizeof(healthy.key))
			strncpy((char *)healthy.key, "A1B2", sizeof(healthy.key));
		/* TBD Log the info */
	} else {
		if (strlen((char *)health_key) <= sizeof(healthy.key))
			strncpy((char *)healthy.key, (char *)health_key, SA_AMF_HEALTHCHECK_KEY_MAX - 1);
	}
	healthy.keyLen = strlen((char *)healthy.key);

	amf_error = saAmfHealthcheckStart(glnd_cb->amf_hdl, &glnd_cb->comp_name, &healthy,
					  SA_AMF_HEALTHCHECK_AMF_INVOKED, SA_AMF_COMPONENT_RESTART);
	if (amf_error != SA_AIS_OK) {
		m_LOG_GLND_HEADLINE(GLND_AMF_HEALTHCHECK_START_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__);
	} else
		m_LOG_GLND_HEADLINE(GLND_AMF_HEALTHCHECK_START_SUCCESS, NCSFL_SEV_NOTICE, __FILE__, __LINE__);

	if (glnd_cb->node_state != GLND_CLIENT_INFO_GET_STATE) {
		TRACE("setting the state as  GLND_OPERATIONAL_STATE");
		/* GLND HAS STRTED */
		glnd_cb->node_state = GLND_OPERATIONAL_STATE;

	}

	/*create a shared memory segment to Checkpint Resource info, lck_info & backup_event info */
	if (glnd_shm_create(glnd_cb) != NCSCC_RC_SUCCESS)
		goto glnd_shm_create_fail;

	return glnd_cb;
 glnd_shm_create_fail:
	glnd_amf_deregister(glnd_cb);
 amf_reg_err:
	glnd_amf_de_init(glnd_cb);
 amf_init_err:
	glnd_mds_unregister(glnd_cb);
 mds_err:
	m_NCS_EDU_HDL_FLUSH(&glnd_cb->glnd_edu_hdl);
	m_NCS_IPC_DETACH(&glnd_cb->glnd_mbx, glnd_cleanup_mbx, glnd_cb);
 mbx_attach_err:
	m_NCS_IPC_RELEASE(&glnd_cb->glnd_mbx, NULL);
 mbx_create_err:
	ncs_patricia_tree_destroy(&glnd_cb->glnd_res_tree);
 res_err:
	ncs_patricia_tree_destroy(&glnd_cb->glnd_agent_tree);
 agent_err:
	ncs_patricia_tree_destroy(&glnd_cb->glnd_client_tree);
 client_err:
	ncshm_destroy_hdl(NCS_SERVICE_ID_GLND, glnd_cb->cb_hdl_id);
 hdl_err:
	glnd_flx_log_dereg();
	/* free the control block */
	m_MMGR_FREE_GLND_CB(glnd_cb);

	return NULL;
}