Example #1
0
/****************************************************************************
  Name          : ava_hdl_rec_add
 
  Description   : This routine adds the handle record to the handle db.
 
  Arguments     : cb       - ptr tot he AvA control block
                  hdl_db   - ptr to the hdl db
                  reg_cbks - ptr to the set of registered callbacks
 
  Return Values : ptr to the handle record
 
  Notes         : None
******************************************************************************/
AVA_HDL_REC *ava_hdl_rec_add(AVA_CB *cb, AVA_HDL_DB *hdl_db, const SaAmfCallbacksT *reg_cbks)
{
	AVA_HDL_REC *rec = 0;
	TRACE_ENTER();

	/* allocate the hdl rec */
	if (!(rec = calloc(1, sizeof(AVA_HDL_REC)))) {
		LOG_CR("Error occurred calling calloc");
		osafassert(0);
	}

	/* create the association with hdl-mngr */
	if (!(rec->hdl = ncshm_create_hdl(cb->pool_id, NCS_SERVICE_ID_AVA, (NCSCONTEXT)rec))) {
		LOG_CR("Error occurred during creation of handle");
		osafassert(0);
	}

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

	/* add the record to the hdl db */
	rec->hdl_node.key_info = (uint8_t *)&rec->hdl;
	if (ncs_patricia_tree_add(&hdl_db->hdl_db_anchor, &rec->hdl_node)
	    != NCSCC_RC_SUCCESS) {
		LOG_CR("Patricia tree add failed ");
		osafassert(0);
	}

	/* update the no of records */
	hdl_db->num++;

	TRACE_LEAVE2("Handle = %x successfully added to Handle DB, num hdls = %d",rec->hdl,hdl_db->num);
	return rec;
}
Example #2
0
/****************************************************************************
  Name          : lga_mds_msg_async_send
 
  Description   : This routine sends the LGA message to LGS.
 
  Arguments     : cb  - ptr to the LGA CB
                  i_msg - ptr to the LGSv message
 
  Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE
 
  Notes         : None.
******************************************************************************/
uint32_t lga_mds_msg_async_send(lga_cb_t *cb, struct lgsv_msg *i_msg, uint32_t prio)
{
	NCSMDS_INFO mds_info;
	uint32_t rc = NCSCC_RC_SUCCESS;

	TRACE_ENTER();
	osafassert(cb != NULL && i_msg != NULL);

	memset(&mds_info, '\0', sizeof(NCSMDS_INFO));
	mds_info.i_mds_hdl = cb->mds_hdl;
	mds_info.i_svc_id = NCSMDS_SVC_ID_LGA;
	mds_info.i_op = MDS_SEND;

	/* fill the main send structure */
	mds_info.info.svc_send.i_msg = (NCSCONTEXT)i_msg;
	mds_info.info.svc_send.i_priority = prio;
	mds_info.info.svc_send.i_to_svc = NCSMDS_SVC_ID_LGS;
	mds_info.info.svc_send.i_sendtype = MDS_SENDTYPE_SND;

	/* fill the sub send strcuture */
	mds_info.info.svc_send.info.snd.i_to_dest = cb->lgs_mds_dest;

	/* send the message */
	rc = ncsmds_api(&mds_info);
	if (rc != NCSCC_RC_SUCCESS)
		TRACE("failed");

	TRACE_LEAVE();
	return rc;
}
Example #3
0
/****************************************************************************
  Name          : lga_mds_msg_sync_send
 
  Description   : This routine sends the LGA message to LGS. The send 
                  operation is a synchronous call that 
                  blocks until the response is received from LGS.
 
  Arguments     : cb  - ptr to the LGA CB
                  i_msg - ptr to the LGSv message
                  o_msg - double ptr to LGSv message response
 
  Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE/timeout
 
  Notes         : None.
******************************************************************************/
uint32_t lga_mds_msg_sync_send(lga_cb_t *cb, lgsv_msg_t *i_msg, lgsv_msg_t **o_msg, uint32_t timeout, uint32_t prio)
{
	NCSMDS_INFO mds_info;
	uint32_t rc = NCSCC_RC_SUCCESS;

	TRACE_ENTER();

	osafassert(cb != NULL && i_msg != NULL && o_msg != NULL);

	memset(&mds_info, '\0', sizeof(NCSMDS_INFO));
	mds_info.i_mds_hdl = cb->mds_hdl;
	mds_info.i_svc_id = NCSMDS_SVC_ID_LGA;
	mds_info.i_op = MDS_SEND;

	/* Fill the send structure */
	mds_info.info.svc_send.i_msg = (NCSCONTEXT)i_msg;
	mds_info.info.svc_send.i_to_svc = NCSMDS_SVC_ID_LGS;
	mds_info.info.svc_send.i_sendtype = MDS_SENDTYPE_SNDRSP;
	mds_info.info.svc_send.i_priority = prio;	/* fixme? */
	/* fill the sub send rsp strcuture */
	mds_info.info.svc_send.info.sndrsp.i_time_to_wait = timeout;	/* timeto wait in 10ms FIX!!! */
	mds_info.info.svc_send.info.sndrsp.i_to_dest = cb->lgs_mds_dest;

	/* send the message */
	if (NCSCC_RC_SUCCESS == (rc = ncsmds_api(&mds_info))) {
		/* Retrieve the response and take ownership of the memory  */
		*o_msg = (lgsv_msg_t *)mds_info.info.svc_send.info.sndrsp.o_rsp;
		mds_info.info.svc_send.info.sndrsp.o_rsp = NULL;
	} else
		TRACE("lga_mds_msg_sync_send FAILED: %u", rc);

	TRACE_LEAVE();
	return rc;
}
Example #4
0
SaAisErrorT immnd_mds_client_not_busy(IMMSV_SEND_INFO *s_info) 
{
	if(!(s_info->to_svc)) {
		/* No current syncronous reply pending. */
		osafassert(!(s_info->mSynReqCount));
		return SA_AIS_OK;
	}

	/* Client is currently blocked waiting on reply. 
	   This can happen if client has timed out in library
	   on previous syncronous call. The call is here still
	   being processed in the server. The server can then
	   only reply immediately to this client, on *this* call.

	   It could also happen if one handle is used concurrently
	   by several client threads, making concurrent synchronous calls.
	   This is not allowed though, see osaf/services/saf/immsv/README.
	*/

	if(s_info->mSynReqCount < 255) {
		s_info->mSynReqCount++;
		TRACE_2("ERR_TRY_AGAIN: Handle is busy with other syncronous call");
		return SA_AIS_ERR_TRY_AGAIN;
	}

	LOG_WA("ERR_BAD_HANDLE: Handle use is blocked by pending reply on syncronous call");
	return SA_AIS_ERR_BAD_HANDLE;
}
Example #5
0
/****************************************************************************
  Name          : ava_hdl_cbk_dispatch
 
  Description   : This routine dispatches the pending callbacks as per the 
                  dispatch flags.
 
  Arguments     : cb      - ptr to the AvA control block
                  hdl_rec - ptr to the handle record
                  flags   - dispatch flags
 
  Return Values : SA_AIS_OK/SA_AIS_ERR_<CODE>
 
  Notes         : None
******************************************************************************/
uint32_t ava_hdl_cbk_dispatch(AVA_CB **cb, AVA_HDL_REC **hdl_rec, SaDispatchFlagsT flags)
{
	uint32_t rc = SA_AIS_OK;
	TRACE_ENTER();

	switch (flags) {
	case SA_DISPATCH_ONE:
		rc = ava_hdl_cbk_dispatch_one(cb, hdl_rec);
		break;

	case SA_DISPATCH_ALL:
		rc = ava_hdl_cbk_dispatch_all(cb, hdl_rec);
		break;

	case SA_DISPATCH_BLOCKING:
		rc = ava_hdl_cbk_dispatch_block(cb, hdl_rec);
		break;

	default:
		osafassert(0);
	}			/* switch */

	TRACE_LEAVE();
	return rc;
}
Example #6
0
void ntfsv_get_ntf_header(ntfsv_send_not_req_t *notif, SaNtfNotificationHeaderT **ntfHeader)
{
	TRACE_ENTER();
	switch (notif->notificationType) {
	case SA_NTF_TYPE_ALARM:
		*ntfHeader = &notif->notification.alarm.notificationHeader;
		break;
	case SA_NTF_TYPE_OBJECT_CREATE_DELETE:
		*ntfHeader = &notif->notification.objectCreateDelete.notificationHeader;
		break;
	case SA_NTF_TYPE_ATTRIBUTE_CHANGE:
		*ntfHeader = &notif->notification.attributeChange.notificationHeader;
		break;
	case SA_NTF_TYPE_STATE_CHANGE:
		*ntfHeader = &notif->notification.stateChange.notificationHeader;
		break;
	case SA_NTF_TYPE_SECURITY_ALARM:
		*ntfHeader = &notif->notification.securityAlarm.notificationHeader;
		break;
	default:
		TRACE("notificationType not valid");
		osafassert(0);
	}
	TRACE_LEAVE();
}
Example #7
0
/*************************************************************************** 
@brief		: 1. If the cb->cbk_list does not have inv node corersponding 
		  to the inv_id, then create inv node and add at the head of the 
		  cb->cbk_list. Create the hdl node for hdl and add at the head
		  of the cb->cbk_list->hdl_list.
		  2. If inv node exists, then create only hdl node and add at the head
		  of the cb->cbk_list->hdl_list.

		  This function will be hit only for the first time when the hdl node
		  is created and hence optimized taking this into consideration.

@param[in]	: inv_id - Node to be added, represents a cbk.
@param[in]	: hdl - Handle. 
@return		: SMFA_CBK_HDL_LIST * 
***************************************************************************/ 
SMFA_CBK_HDL_LIST * smfa_inv_hdl_add(SaInvocationT inv_id, SaSmfHandleT hdl)
{
	SMFA_CB *cb = &_smfa_cb;
	SMFA_CBK_LIST *cbk_list = cb->cbk_list;
	SMFA_CBK_HDL_LIST *hdl_list;
	
	while (cbk_list){
		if(inv_id == cbk_list->inv_id)
			break;
		cbk_list = cbk_list->next_cbk;
	}

	if (NULL == cbk_list){
		/* First filter matching. 1. Create inv node 2. Create hdl node.*/
		cbk_list = (SMFA_CBK_LIST *)calloc(1,sizeof(SMFA_CBK_LIST));
		if (!cbk_list){
			LOG_ER("SMFA: calloc FAILED, error: %s",strerror(errno));
			osafassert(0);
		}
		cbk_list->inv_id = inv_id;
		cbk_list->hdl_list = (SMFA_CBK_HDL_LIST *)calloc(1,sizeof(SMFA_CBK_HDL_LIST));
		if(!cbk_list->hdl_list){
			LOG_ER("SMFA: calloc FAILED, error: %s",strerror(errno));
			osafassert(0);
		}
		cbk_list->hdl_list->hdl = hdl;
		/* Add at the head.*/
		cbk_list->next_cbk = cb->cbk_list;
		cb->cbk_list = cbk_list;
		return cbk_list->hdl_list;
	}else{
		/* Inv_id matched ==> this might not the first hdl for this inv_id but first filter 
		   matching for this hdl. So create hdl node.*/
		hdl_list = (SMFA_CBK_HDL_LIST *)calloc(1,sizeof(SMFA_CBK_HDL_LIST));
		if(!hdl_list){
			LOG_ER("SMFA: calloc FAILED, error: %s",strerror(errno));
			osafassert(0);
		}
		hdl_list->hdl = hdl;
		/* Add at the head.*/
		hdl_list->next_hdl = cbk_list->hdl_list;
		cbk_list->hdl_list = hdl_list;
		return hdl_list;
	}
}
Example #8
0
/**
 * Initialize a DN by searching for needle in haystack
 * @param haystack
 * @param dn
 * @param needle
 */
void avsv_sanamet_init(const SaNameT *haystack, SaNameT *dn, const char *needle)
{
	char *p;

	memset(dn, 0, sizeof(SaNameT));
	p = strstr((char*)haystack->value, needle);
	osafassert(p);
	dn->length = strlen(p);
	memcpy(dn->value, p, dn->length);
}
Example #9
0
void hm_block_me(HM_CELL *cell, uint8_t pool_id)
{
	int rc;
	sem_t sem;
	m_HM_STAT_CRASH(gl_hm.woulda_crashed);

	rc = sem_init(&sem, 0, 0);		/* Create a semaphor to block this thread */
	osafassert(rc == 0);
	cell->data = &sem;
	m_NCS_UNLOCK(&gl_hm.lock[pool_id], NCS_LOCK_WRITE);	/* let others run */

wait_again:						/* stay here till refcount == 1 */
	if (sem_wait(&sem) == -1) {
		if (errno == EINTR)
			goto wait_again;
		else
			osafassert(0);
	}

	(void)sem_destroy(&sem);	/* OK, all set, continue on.... */
}
Example #10
0
/**
 * Function to process the incoming connection request
 *
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
static uint32_t dtm_intranode_process_incoming_conn(void)
{
	 int flags;
	/* Accept processing */
	int accept_fd = 0,  retry_count = 0, size = DTM_INTRANODE_SOCK_SIZE;
	socklen_t len = sizeof(struct sockaddr_un);
	struct sockaddr_un cli_addr;
	/* Accept should be non_block */
	TRACE_ENTER();
	accept_fd = accept(dtm_intranode_cb->server_sockfd, (struct sockaddr *)&cli_addr, &len);

	/* Error Checking */
	if (accept_fd < 0) {
		LOG_ER("DTM: Connection accept fail");
		return NCSCC_RC_FAILURE;
	}

tryagain:
	/*Make the socket Non-Blocking for accepting */
	if ((flags = fcntl(accept_fd, F_GETFL, NULL)) < 0) {
                LOG_ER("DTM :fcntl(F_SETFL, O_NONBLOCK) err :%s ", strerror(errno));
                return false;
        }
	flags |= O_NONBLOCK;	
	if (fcntl(accept_fd, F_SETFL, flags) < 0) {
		LOG_ER("DTM: accept_fd Non-Blocking hasnt been Set");
		retry_count++;
		/* Non-Blocking Options hasnt been set */
		if (retry_count > 3) {
			osafassert(0);
		} else {
			goto tryagain;
		}
	}
	if (setsockopt(accept_fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)) != 0) {
		LOG_ER("DTM: Unable to set the SO_RCVBUF ");
		close(accept_fd);
		return NCSCC_RC_FAILURE;
	}
	if (setsockopt(accept_fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) != 0) {
		LOG_ER("DTM: Unable to set the SO_SNDBUF ");
		close(accept_fd);
		return NCSCC_RC_FAILURE;
	}
	dtm_intranode_add_poll_fdlist(accept_fd, POLLIN);
	dtm_intranode_create_pid_info(accept_fd);
	TRACE_LEAVE();
	return NCSCC_RC_SUCCESS;
}
Example #11
0
/****************************************************************************
  Name          : lga_dec_finalize_rsp_msg
 
  Description   : This routine decodes an finalize sync response message
 
  Arguments     : NCS_UBAID *msg,
                  LGSV_MSG *msg
                  
  Return Values : uint32_t
 
  Notes         : None.
******************************************************************************/
static uint32_t lga_dec_finalize_rsp_msg(NCS_UBAID *uba, lgsv_msg_t *msg)
{
	uint8_t *p8;
	uint32_t total_bytes = 0;
	lgsv_finalize_rsp_t *param = &msg->info.api_resp_info.param.finalize_rsp;
	uint8_t local_data[100];

	osafassert(uba != NULL);

	p8 = ncs_dec_flatten_space(uba, local_data, 4);
	param->client_id = ncs_decode_32bit(&p8);
	ncs_dec_skip_space(uba, 4);
	total_bytes += 4;

	return total_bytes;
}
Example #12
0
/**
 *  @Brief: Return the length of string specified in SaNameT type.
 *
 */
size_t ntfs_sanamet_length(const SaNameT* pName)
{
	if (osaf_is_an_extended_name(pName))
		return osaf_extended_name_length(pName);
	
	/* In case of unextended name, sometimes @.length includes the count on
	 * null-termination, and osaf_extended_name_length returns the length
	 * excluding the null-termination which less 1 than the @.length. Here
	 * we need the length specified in @.length. This case mainly applies
	 * in encodeSaNameT/decodeSaNameT in order to preserve the original
	 * @.length value
	 */
	size_t length = *((SaUint16T*)pName);
	osafassert(length < SA_MAX_UNEXTENDED_NAME_LENGTH);
	return length;
}
Example #13
0
/****************************************************************************
  Name          : lga_dec_write_ckb_msg
 
  Description   : This routine decodes an initialize sync response message
 
  Arguments     : NCS_UBAID *msg,
                  LGSV_MSG *msg
                  
  Return Values : uint32_t
 
  Notes         : None.
******************************************************************************/
static uint32_t lga_dec_write_cbk_msg(NCS_UBAID *uba, lgsv_msg_t *msg)
{
	uint8_t *p8;
	uint32_t total_bytes = 0;
	lgsv_write_log_callback_ind_t *param = &msg->info.cbk_info.write_cbk;
	uint8_t local_data[100];

	osafassert(uba != NULL);

	p8 = ncs_dec_flatten_space(uba, local_data, 4);
	param->error = ncs_decode_32bit(&p8);
	ncs_dec_skip_space(uba, 4);
	total_bytes += 4;

	return total_bytes;
}
Example #14
0
/****************************************************************************
  Name          : lga_dec_lstr_open_sync_rsp_msg
 
  Description   : This routine decodes a log stream open sync response message
 
  Arguments     : NCS_UBAID *msg,
                  LGSV_MSG *msg
                  
  Return Values : uint32_t
 
  Notes         : None.
******************************************************************************/
static uint32_t lga_dec_lstr_open_sync_rsp_msg(NCS_UBAID *uba, lgsv_msg_t *msg)
{
	uint8_t *p8;
	uint32_t total_bytes = 0;
	lgsv_stream_open_rsp_t *param = &msg->info.api_resp_info.param.lstr_open_rsp;
	uint8_t local_data[100];

	osafassert(uba != NULL);

	/* chan_id */
	p8 = ncs_dec_flatten_space(uba, local_data, 4);
	param->lstr_id = ncs_decode_32bit(&p8);
	ncs_dec_skip_space(uba, 4);
	total_bytes += 4;

	return total_bytes;
}
Example #15
0
/*************************************************************************** 
@brief		: MDS callback. 
@param[in]	: info - MDS callback info.
@return		: NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE
*****************************************************************************/
uint32_t smfa_mds_callback(struct ncsmds_callback_info *info)
{
	uint32_t rc = NCSCC_RC_SUCCESS;
	SMFSV_EVT *evt;
	NCS_UBAID *uba;
	
	switch(info->i_op){
		case MDS_CALLBACK_COPY:
			break;
		case MDS_CALLBACK_ENC_FLAT:
		case MDS_CALLBACK_ENC:
			evt = (SMFSV_EVT *) info->info.enc.i_msg;
			uba = info->info.enc.io_uba;
			rc = smfsv_evt_enc(evt, uba);
			if (NCSCC_RC_SUCCESS != rc) {
				LOG_ER("SMFA: Encoding failed");
			}
			break;
		case MDS_CALLBACK_DEC_FLAT:
		case MDS_CALLBACK_DEC:
			uba = info->info.dec.io_uba;
			if (NULL == (evt = calloc(1, sizeof(SMFSV_EVT)))) {
				LOG_ER("SMFA: Decode Calloc failed");
				osafassert(0);
			}
			info->info.dec.o_msg = (uint8_t *) evt;
			rc = smfsv_evt_dec(uba,evt);
			if (NCSCC_RC_SUCCESS != rc) {
				LOG_ER("SMFA: Decoding failed");
			}
			break;
		case MDS_CALLBACK_RECEIVE:
			rc = smfa_mds_rcv_cbk(&info->info.receive);
			break;
		case MDS_CALLBACK_SVC_EVENT:
			rc = smfa_mds_svc_evt_cbk(&info->info.svc_evt);
			break;
		default:
			rc = NCSCC_RC_FAILURE;
			LOG_ER("SMFA: Received mds cbk for: %d",info->i_op);
	}
	return rc;
}
/**
 * Function to process the pollout
 *
 * @param fd
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
uint32_t dtm_intranode_process_pollout(int fd)
{
	DTM_INTRANODE_PID_INFO *pid_node = NULL;
	pid_node = dtm_intranode_get_pid_info_using_fd(fd);
	if (NULL == pid_node) {
		LOG_ER("DTM INTRA: PID info coressponding to fd doesnt exist, database mismatch. fd :%d",fd);
		osafassert(0);
		return NCSCC_RC_FAILURE;
	} else {
		/* Get the unsent messages from the list and send them */
		DTM_INTRANODE_UNSENT_MSGS *hdr = pid_node->msgs_hdr;
		if (NULL == hdr) {
			/* No messages to be sent, reset the POLLOUT event on this fd */
			dtm_intranode_reset_poll_fdlist(fd);
		} else {
			dtm_intranode_snd_unsent_msg(pid_node, fd);
		}
	}
	return NCSCC_RC_SUCCESS;
}
Example #17
0
/****************************************************************************
 * Name          : immnd_mds_send_rsp
 *
 * Description   : Send the Response to Sync Requests
 *
 * Arguments     : 
 *
 * Return Values : 
 *
 * Notes         :
 *****************************************************************************/
uint32_t immnd_mds_send_rsp(IMMND_CB *cb, IMMSV_SEND_INFO *s_info, IMMSV_EVT *evt)
{
	NCSMDS_INFO mds_info;
	uint32_t rc;

	if(!(s_info->to_svc)) {
		LOG_WA(">>s_info->to_svc == 0<< reply context destroyed before "
			"this reply could be made");
		return NCSCC_RC_FAILURE;
	}

	osafassert(s_info->stype == MDS_SENDTYPE_SNDRSP);

	memset(&mds_info, 0, sizeof(NCSMDS_INFO));
	mds_info.i_mds_hdl = cb->immnd_mds_hdl;
	mds_info.i_svc_id = NCSMDS_SVC_ID_IMMND;
	mds_info.i_op = MDS_SEND;

	/* fill the send structure */
	mds_info.info.svc_send.i_msg = (NCSCONTEXT)evt;
	mds_info.info.svc_send.i_priority = MDS_SEND_PRIORITY_MEDIUM;

	mds_info.info.svc_send.i_to_svc = s_info->to_svc;
	mds_info.info.svc_send.i_sendtype = MDS_SENDTYPE_RSP;
	mds_info.info.svc_send.info.rsp.i_msg_ctxt = s_info->ctxt;
	mds_info.info.svc_send.info.rsp.i_sender_dest = s_info->dest;

	immsv_msg_trace_send(s_info->dest, evt);

	/* send the message */
	rc = ncsmds_api(&mds_info);

	/* Destroy reply context after reply has been sent
	   Will also zero mSyncReqCount */
	memset(s_info, 0, sizeof(IMMSV_SEND_INFO));

	if (rc != NCSCC_RC_SUCCESS)
		LOG_WA("MDS Send Failed");

	return rc;
}
Example #18
0
/****************************************************************************
  Name          : ava_hdl_del
 
  Description   : This routine deletes the handle database.
 
  Arguments     : cb  - ptr to the AvA control block
 
  Return Values : None
 
  Notes         : None
******************************************************************************/
void ava_hdl_del(AVA_CB *cb)
{
	AVA_HDL_DB *hdl_db = &cb->hdl_db;
	AVA_HDL_REC *hdl_rec = 0;
	TRACE_ENTER();

	/* scan the entire handle db & delete each record */
	while ((hdl_rec = (AVA_HDL_REC *)
		ncs_patricia_tree_getnext(&hdl_db->hdl_db_anchor, 0))) {
		ava_hdl_rec_del(cb, hdl_db, &hdl_rec);
	}

	/* there shouldn't be any record left */
	osafassert(!hdl_db->num);

	/* destroy the hdl db tree */
	ncs_patricia_tree_destroy(&hdl_db->hdl_db_anchor);

	TRACE_LEAVE();
	return;
}
Example #19
0
/****************************************************************************
  Name          : lga_enc_lstr_close_msg
 
  Description   : This routine encodes a log stream close API msg
 
  Arguments     : NCS_UBAID *msg,
                  LGSV_MSG *msg
                  
  Return Values : uint32_t
 
  Notes         : None.
******************************************************************************/
static uint32_t lga_enc_lstr_close_msg(NCS_UBAID *uba, lgsv_msg_t *msg)
{
	uint8_t *p8;
	uint32_t total_bytes = 0;
	lgsv_stream_close_req_t *param = &msg->info.api_info.param.lstr_close;

	osafassert(uba != NULL);

    /** encode the contents **/
	p8 = ncs_enc_reserve_space(uba, 8);
	if (!p8) {
		TRACE("p8 NULL!!!");
		return 0;
	}
	ncs_encode_32bit(&p8, param->client_id);
	ncs_encode_32bit(&p8, param->lstr_id);
	ncs_enc_claim_space(uba, 8);
	total_bytes += 8;

	return total_bytes;
}
Example #20
0
/**
 * Get the operation invoker name.
 * If ccb id is 0 or >0 return the value in SaImmAttrImplementerName or
 * SaImmAttrAdminOwnerName respective.
 *
 * Note:
 *
 * @param ccbId[in]
 * @param attrMods[in]
 * 
 * @return SaNameT *operation_invoke_name
 *			Note must be used before next call
 */
static SaNameT *get_operation_invoke_name_modify(
			SaImmOiCcbIdT ccbId,
			const SaImmAttrModificationT_2 **attrMods)
{
	int i = 0;
	char *attrName;

	TRACE_ENTER();

	s_get_operation_invoke_name_modify.iname_ptr = &s_get_operation_invoke_name_modify.iname;

	if (ccbId == 0) {
		attrName = NTFIMCN_IMPLEMENTER_NAME;
	} else {
		attrName = NTFIMCN_ADMIN_OWNER_NAME;
	}

	/* Get the value from Admin owner name or Implementer name */
	s_get_operation_invoke_name_modify.iname.length = 0;
	s_get_operation_invoke_name_modify.iname.value[0] = 0;
	for (i=0; attrMods[i] != NULL; i++) {
		if( strcmp(attrMods[i]->modAttr.attrName, attrName) == 0) {
			strncpy((char*)s_get_operation_invoke_name_modify.iname.value,
					*((char**)attrMods[i]->modAttr.attrValues[0]),
					SA_MAX_NAME_LENGTH);
			s_get_operation_invoke_name_modify.iname.value[SA_MAX_NAME_LENGTH-1] = '\0';
			s_get_operation_invoke_name_modify.iname.length =
					strlen((char*)s_get_operation_invoke_name_modify.iname.value);
			goto done;
		}
	}
	/* If we get here no name is found! */
	LOG_ER("%s no name was found",__FUNCTION__);
	osafassert(0);

done:
	TRACE_LEAVE();
	return s_get_operation_invoke_name_modify.iname_ptr;
}
Example #21
0
/****************************************************************************
  Name          : lga_enc_finalize_msg
 
  Description   : This routine encodes a finalize API msg
 
  Arguments     : NCS_UBAID *msg,
                  LGSV_MSG *msg
                  
  Return Values : uint32_t
 
  Notes         : None.
******************************************************************************/
static uint32_t lga_enc_finalize_msg(NCS_UBAID *uba, lgsv_msg_t *msg)
{
	uint8_t *p8;
	uint32_t total_bytes = 0;
	lgsv_finalize_req_t *param = &msg->info.api_info.param.finalize;

	TRACE_ENTER();

	osafassert(uba != NULL);

    /** encode the contents **/
	p8 = ncs_enc_reserve_space(uba, 4);
	if (!p8) {
		TRACE("NULL pointer");
		return 0;
	}
	ncs_encode_32bit(&p8, param->client_id);
	ncs_enc_claim_space(uba, 4);
	total_bytes += 4;

	TRACE_LEAVE();
	return total_bytes;
}
/**
 * Function to process pollout
 *
 * @param fd
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
uint32_t dtm_internode_process_pollout(int fd)
{
	DTM_NODE_DB *node = NULL;

	TRACE_ENTER();
	node = dtm_node_get_by_comm_socket((uint32_t)fd);
	if (NULL == node) {
		TRACE("DTM :No node matching the fd for pollout, delete this fd from fd list ");
		osafassert(0);
		return NCSCC_RC_FAILURE;
	} else {
		/* Get the unsent messages from the list and send them */
		DTM_INTERNODE_UNSENT_MSGS *hdr = node->msgs_hdr;
		if (NULL == hdr) {
			/* No messages to be sent, reset the POLLOUT event on this fd */
			dtm_internode_reset_poll_fdlist(node->comm_socket);
		} else {
			dtm_internode_snd_unsent_msg(node);
		}
	}
	TRACE_LEAVE();
	return NCSCC_RC_SUCCESS;
}
Example #23
0
/****************************************************************************
  Name          : lga_enc_initialize_msg
 
  Description   : This routine encodes an initialize API msg
 
  Arguments     : NCS_UBAID *msg,
                  LGSV_MSG *msg
                  
  Return Values : uint32_t
 
  Notes         : None.
******************************************************************************/
static uint32_t lga_enc_initialize_msg(NCS_UBAID *uba, lgsv_msg_t *msg)
{
	uint8_t *p8;
	uint32_t total_bytes = 0;
	lgsv_initialize_req_t *param = &msg->info.api_info.param.init;

	TRACE_ENTER();
	osafassert(uba != NULL);

    /** encode the contents **/
	p8 = ncs_enc_reserve_space(uba, 3);
	if (!p8) {
		TRACE("NULL pointer");
		return 0;
	}
	ncs_encode_8bit(&p8, param->version.releaseCode);
	ncs_encode_8bit(&p8, param->version.majorVersion);
	ncs_encode_8bit(&p8, param->version.minorVersion);
	ncs_enc_claim_space(uba, 3);
	total_bytes += 3;

	TRACE_LEAVE();
	return total_bytes;
}
Example #24
0
void hm_unblock_him(HM_CELL *cell)
{
	int rc = sem_post((sem_t*)cell->data);	/* unblock that destroy thread */
	osafassert(rc == 0);
}
Example #25
0
/**
 * Function to process internode poll and rcv message
 *
 * @param fd close_conn node_info_hrd node_info_buffer_len
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
void dtm_internode_process_poll_rcv_msg(int fd, int *close_conn, uint8_t *node_info_hrd, uint16_t node_info_buffer_len)
{
	DTM_NODE_DB *node = NULL;
	TRACE_ENTER();

	node = dtm_node_get_by_comm_socket(fd);

	if (NULL == node) {
		LOG_ER("DTM: database mismatch");
		osafassert(0);
	}
	if (0 == node->bytes_tb_read) {
		if (0 == node->num_by_read_for_len_buff) {
			uint8_t *data;
			int recd_bytes = 0;

			/*******************************************************/
			/* Receive all incoming data on this socket */
			/*******************************************************/

			recd_bytes = recv(fd, node->len_buff, 2, 0);
			if (0 == recd_bytes) {
				*close_conn = true;
				return;
			} else if (2 == recd_bytes) {
				uint16_t local_len_buf = 0;

				data = node->len_buff;
				local_len_buf = ncs_decode_16bit(&data);
				node->buff_total_len = local_len_buf;
				node->num_by_read_for_len_buff = 2;

				if (NULL == (node->buffer = calloc(1, (local_len_buf + 3)))) {
					/* Length + 2 is done to reuse the same buffer 
					   while sending to other nodes */
					LOG_ER("\nMemory allocation failed in dtm_internode_processing");
					return;
				}
				recd_bytes = recv(fd, &node->buffer[2], local_len_buf, 0);

				if (recd_bytes < 0) {
					return;
				} else if (0 == recd_bytes) {
					*close_conn = true;
					return;
				} else if (local_len_buf > recd_bytes) {
					/* can happen only in two cases, system call interrupt or half data, */
					TRACE("DTM: less data recd, recd bytes : %d, actual len : %d", recd_bytes,
					       local_len_buf);
					node->bytes_tb_read = node->buff_total_len - recd_bytes;
					return;
				} else if (local_len_buf == recd_bytes) {
					/* Call the common rcv function */
					dtm_internode_process_poll_rcv_msg_common(node, local_len_buf, node_info_hrd,
										  node_info_buffer_len, fd, close_conn);
				} else {
					LOG_ER("DTM :unknown corrupted data received on this file descriptor \n");
					osafassert(0);
				}
			} else {
				/* we had recd some bytes */
				if (recd_bytes < 0) {
					/* This can happen due to system call interrupt */
					return;
				} else if (1 == recd_bytes) {
					/* We recd one byte of the length part */
					node->num_by_read_for_len_buff = recd_bytes;
				} else {
					LOG_ER("DTM :unknown corrupted data received on this file descriptor \n");
					osafassert(0);
				}
			}
		} else if (1 == node->num_by_read_for_len_buff) {
			int recd_bytes = 0;

			recd_bytes = recv(fd, &node->len_buff[1], 1, 0);
			if (recd_bytes < 0) {
				/* This can happen due to system call interrupt */
				return;
			} else if (1 == recd_bytes) {
				/* We recd one byte(remaining) of the length part */
				uint8_t *data = node->len_buff;
				node->num_by_read_for_len_buff = 2;
				node->buff_total_len = ncs_decode_16bit(&data);
				return;
			} else if (0 == recd_bytes) {
				*close_conn = true;
				return;
			} else {
				LOG_ER("DTM :unknown corrupted data received on this file descriptor \n");
				osafassert(0);	/* This should never occur */
			}
		} else if (2 == node->num_by_read_for_len_buff) {
			int recd_bytes = 0;

			if (NULL == (node->buffer = calloc(1, (node->buff_total_len + 3)))) {
				/* Length + 2 is done to reuse the same buffer 
				   while sending to other nodes */
				LOG_ER("DTM :Memory allocation failed in dtm_internode_processing \n");
				return;
			}
			recd_bytes = recv(fd, &node->buffer[2], node->buff_total_len, 0);

			if (recd_bytes < 0) {
				return;
			} else if (0 == recd_bytes) {
				*close_conn = true;
				return;
			} else if (node->buff_total_len > recd_bytes) {
				/* can happen only in two cases, system call interrupt or half data, */
				TRACE("DTM: less data recd, recd bytes : %d, actual len : %d", recd_bytes,
				       node->buff_total_len);
				node->bytes_tb_read = node->buff_total_len - recd_bytes;
				return;
			} else if (node->buff_total_len == recd_bytes) {
				/* Call the common rcv function */
				dtm_internode_process_poll_rcv_msg_common(node, node->buff_total_len, node_info_hrd,
									  node_info_buffer_len, fd, close_conn);
			} else {
				LOG_ER("DTM :unknown corrupted data received on this file descriptor \n");
				osafassert(0);
			}
		} else {
			LOG_ER("DTM :unknown corrupted data received on this file descriptor \n");
			osafassert(0);
		}

	} else {
		/* Partial data already read */
		int recd_bytes = 0;

		recd_bytes =
		    recv(fd, &node->buffer[2 + (node->buff_total_len - node->bytes_tb_read)], node->bytes_tb_read, 0);

		if (recd_bytes < 0) {
			return;
		} else if (0 == recd_bytes) {
			*close_conn = true;
			return;
		} else if (node->bytes_tb_read > recd_bytes) {
			/* can happen only in two cases, system call interrupt or half data, */
			TRACE("DTM: less data recd, recd bytes : %d, actual len : %d", recd_bytes, node->bytes_tb_read);
			node->bytes_tb_read = node->bytes_tb_read - recd_bytes;
			return;
		} else if (node->bytes_tb_read == recd_bytes) {
			/* Call the common rcv function */
			dtm_internode_process_poll_rcv_msg_common(node, node->buff_total_len, node_info_hrd,
								  node_info_buffer_len, fd, close_conn);
		} else {
			LOG_ER("DTM :unknown corrupted data received on this file descriptor \n");
			osafassert(0);
		}
	}
	TRACE_LEAVE();
	return;
}
Example #26
0
/**
 * Function to process the node info hdr
 *
 * @param dtms_cb stream_sock buffer node_info_hrd buffer_len
 *
 * @return NCSCC_RC_SUCCESS
 * @return NCSCC_RC_FAILURE
 *
 */
uint32_t dtm_process_node_info(DTM_INTERNODE_CB * dtms_cb, int stream_sock, uint8_t *buffer, uint8_t *node_info_hrd,
			    int buffer_len)
{
	uint32_t node_id;
	DTM_NODE_DB *node;
	uint32_t nodename_len;
	char nodename[MAX_NAME_LENGTH];
	int rc = 0;
	uint8_t *data = buffer;
	TRACE_ENTER();

	node_id = ncs_decode_32bit(&data);
	nodename_len = ncs_decode_32bit(&data);
	strncpy((char *)nodename, (char *)data, nodename_len);

	node = dtm_node_get_by_comm_socket(stream_sock);

	if (node == NULL) {
		rc = NCSCC_RC_FAILURE;
		goto done;
	}

	if (!node->comm_status) {

		/*****************************************************/
		/* nodeinfo data back to the client  NODE is still */
		/*****************************************************/

		if (node->node_id == 0) {
			node->node_id = node_id;
			strncpy((char *)&node->node_name, nodename, nodename_len);
			node->comm_status = true;
			if (dtm_node_add(node, 0) != NCSCC_RC_SUCCESS) {
				LOG_ER("DTM:  Node already exit in the cluster with smiler configuration , correct the other joining Node configuration ");				
				osafassert(0);
			
			}

		} else if (node->node_id == node_id) {
			strncpy((char *)&node->node_name, nodename, nodename_len);
			rc = dtm_comm_socket_send(stream_sock, node_info_hrd, buffer_len);
			if (rc != NCSCC_RC_SUCCESS) {

				LOG_ER("DTM: dtm_comm_socket_send() failed rc : %d", rc);
				rc = NCSCC_RC_FAILURE;
				goto done;
			}
			node->comm_status = true;

		} else {
			LOG_ER("DTM: Node already exit in the cluster with smiler configuration , correct the other joining Node configuration ");
			osafassert(0);
		}

		TRACE("DTM: dtm_process_node_info node_ip:%s, node_id:%u i_addr_family:%d ", node->node_ip, node->node_id, node->i_addr_family);
		rc = dtm_process_node_up_down(node->node_id, node->node_name, node->node_ip , node->i_addr_family, node->comm_status);

		if (rc != NCSCC_RC_SUCCESS) {
			LOG_ER("DTM: dtm_process_node_up_down() failed rc : %d ", rc);
			rc = NCSCC_RC_FAILURE;
		}
	} else {
		LOG_ER("DTM: Node down already  received  for this node ");
		osafassert(0);
	}

 done:
	TRACE_LEAVE();
	return rc;
}
Example #27
0
/**
 * Handler for mds register requests
 * Note: executed by and in context of the auth thread!
 * Communicates with the main thread (where the
 * real work is done) to get outcome of initialization request which is then
 * sent back to the client.
 * @param fd
 * @param creds credentials for client
 */
static void mds_register_callback(int fd, const struct ucred *creds)
{
	uint8_t buf[32];
	uint8_t *p = buf;

	TRACE_ENTER2("fd:%d, pid:%u", fd, creds->pid);

	int n = recv(fd, buf, sizeof(buf), 0);
	if (n == -1) {
		syslog(LOG_ERR, "%s: recv failed - %s", __FUNCTION__, strerror(errno));
		goto done;
	}

	if (n != 16) {
		syslog(LOG_ERR, "%s: recv failed - %d bytes", __FUNCTION__, n);
		goto done;
	}

	int type = ncs_decode_32bit(&p);

	NCSMDS_SVC_ID svc_id = ncs_decode_32bit(&p);
	MDS_DEST mds_dest = ncs_decode_64bit(&p);

	TRACE("mds: received %d from %"PRIx64", pid %d", type, mds_dest, creds->pid);

	if (type == MDS_REGISTER_REQ) {
		osaf_mutex_lock_ordie(&gl_mds_library_mutex);

		MDS_PROCESS_INFO *info = mds_process_info_get(mds_dest, svc_id);
		if (info == NULL) {
			MDS_PROCESS_INFO *info = calloc(1, sizeof(MDS_PROCESS_INFO));
			osafassert(info);
			info->mds_dest = mds_dest;
			info->svc_id = svc_id;
			info->uid = creds->uid;
			info->pid = creds->pid;
			info->gid = creds->gid;
			int rc = mds_process_info_add(info);
			osafassert(rc == NCSCC_RC_SUCCESS);
		} else {
			/* when can this happen? */
			LOG_NO("%s: dest %"PRIx64" already exist", __FUNCTION__, mds_dest);

			// just update credentials
			info->uid = creds->uid;
			info->pid = creds->pid;
			info->gid = creds->gid;
		}

		osaf_mutex_unlock_ordie(&gl_mds_library_mutex);

		p = buf;
		uint32_t sz = ncs_encode_32bit(&p, MDS_REGISTER_RESP);
		sz += ncs_encode_32bit(&p, 0); // result OK

		if ((n = send(fd, buf, sz, 0)) == -1)
			syslog(LOG_ERR, "%s: send to pid %d failed - %s",
					__FUNCTION__, creds->pid, strerror(errno));
	} else if (type == MDS_UNREGISTER_REQ) {
		osaf_mutex_lock_ordie(&gl_mds_library_mutex);

		MDS_PROCESS_INFO *info = mds_process_info_get(mds_dest, svc_id);
		if (info != NULL) {
			(void)mds_process_info_del(info);
		}
		osaf_mutex_unlock_ordie(&gl_mds_library_mutex);

		p = buf;
		uint32_t sz = ncs_encode_32bit(&p, MDS_UNREGISTER_RESP);
		sz += ncs_encode_32bit(&p, 0);  // result OK

		if ((n = send(fd, buf, sz, 0)) == -1)
			syslog(LOG_ERR, "%s: send to pid %d failed - %s",
					__FUNCTION__, creds->pid, strerror(errno));
	} else {
		syslog(LOG_ERR, "%s: recv failed - wrong type %d", __FUNCTION__, type);
		goto done;
	}

done:
	TRACE_LEAVE();
}
Example #28
0
static uint32_t immnd_mds_svc_evt(IMMND_CB *cb, MDS_CALLBACK_SVC_EVENT_INFO *svc_evt)
{
	IMMSV_EVT *evt;
	uint32_t rc = NCSCC_RC_SUCCESS, priority = NCS_IPC_PRIORITY_HIGH;
	TRACE_ENTER();

	if (svc_evt->i_svc_id == NCSMDS_SVC_ID_IMMD) {
		m_NCS_LOCK(&cb->immnd_immd_up_lock, NCS_LOCK_WRITE);

		switch (svc_evt->i_change) {
		case NCSMDS_DOWN:
			TRACE("IMMD SERVICE DOWN => CLUSTER GOING DOWN");
			cb->fevs_replies_pending = 0;
			break;

		case NCSMDS_UP:
			TRACE("NCSMDS_UP for IMMD. cb->is_immd_up = true; (v)dest:%llu",
				(long long unsigned int) svc_evt->i_dest);
			cb->is_immd_up = true;
			cb->immd_mdest_id = svc_evt->i_dest;
			break;

		case NCSMDS_NO_ACTIVE:
			/* Do NOT set cb->is_immd_up to false, messages to IMMD vdest buffered */
			if (cb->fevs_replies_pending) {
				LOG_WA("Director Service in NOACTIVE state - "
				       "fevs replies pending:%u fevs highest processed:%llu",
				       cb->fevs_replies_pending, cb->highestProcessed);
				TRACE("Resetting fevs replies pending to zero");
				cb->fevs_replies_pending = 0;
			} else {
				TRACE("Director Service in NOACTIVE state");
			}
			break;

		case NCSMDS_NEW_ACTIVE:
			TRACE("NCSMDS_NEW_ACTIVE IMMD"); 
			cb->immd_mdest_id = svc_evt->i_dest;
			break;

		case NCSMDS_RED_UP:
			LOG_ER("NCSMDS_RED_UP: SHOULD NOT HAPPEN");
			break;

		case NCSMDS_RED_DOWN:
			LOG_ER("NCSMDS_RED_DOWN: SHOULD NOT HAPPEN");
			break;

		case NCSMDS_CHG_ROLE:
			LOG_ER("NCSMDS_CHG_ROLE: SHOULD NOT HAPPEN");
			break;

		default:
			break;
		}

		priority = NCS_IPC_PRIORITY_VERY_HIGH;

		m_NCS_UNLOCK(&cb->immnd_immd_up_lock, NCS_LOCK_WRITE);
	}

	/* IMMA events from other nodes can not happen */
	if ((svc_evt->i_svc_id == NCSMDS_SVC_ID_IMMA_OM) || (svc_evt->i_svc_id == NCSMDS_SVC_ID_IMMA_OI))
		osafassert(m_NCS_NODE_ID_FROM_MDS_DEST(cb->immnd_mdest_id) == m_NCS_NODE_ID_FROM_MDS_DEST(svc_evt->i_dest));

	/* Send the IMMND_EVT_MDS_INFO to IMMND */
	evt = calloc(1, sizeof(IMMSV_EVT));
	if (evt == NULL) {
		LOG_WA("calloc failed");
		return NCSCC_RC_FAILURE;
	}
	evt->type = IMMSV_EVT_TYPE_IMMND;
	evt->info.immnd.type = IMMND_EVT_MDS_INFO;
	evt->info.immnd.info.mds_info.change = svc_evt->i_change;
	evt->info.immnd.info.mds_info.dest = svc_evt->i_dest;
	evt->info.immnd.info.mds_info.svc_id = svc_evt->i_svc_id;
	evt->info.immnd.info.mds_info.role = svc_evt->i_role;

	/* Put it in IMMND's Event Queue */
	rc = m_NCS_IPC_SEND(&cb->immnd_mbx, (NCSCONTEXT)evt, priority);
	if (rc != NCSCC_RC_SUCCESS) {
		LOG_WA("NCS IPC Send Failed");
	}
	TRACE_LEAVE();
	return rc;
}
Example #29
0
/**
 * Get name of rdn attribute from IMM
 *
 * Note:
 * A valid ntf_cb.immOmHandle must exist
 * Uses in file global struct s_get_rdn_attr_name
 *
 * @param className[in]
 * 
 * @return String with name
 */
static char *get_rdn_attr_name(const SaImmClassNameT className)
{
	SaAisErrorT rc;
	int msecs_waited;
	int i = 0;

	SaImmClassCategoryT classCategory;
	SaImmAttrDefinitionT_2 **attrDescr;

	TRACE_ENTER();

	/* Just return the name if already looked up */
	if (strcmp(className, s_get_rdn_attr_name.saved_className) == 0) {
		goto done;
	}
	strncpy(s_get_rdn_attr_name.saved_className, className, SA_MAX_NAME_LENGTH-1);

	/* Get class description */
	msecs_waited = 0;
	rc = saImmOmClassDescriptionGet_2(ntfimcn_cb.immOmHandle,
			className,
			&classCategory,
			&attrDescr);
	while ((rc == SA_AIS_ERR_TRY_AGAIN) && (msecs_waited < max_waiting_time_7s)) {
		usleep(sleep_delay_ms * 1000);
		msecs_waited += sleep_delay_ms;
		rc = saImmOmClassDescriptionGet_2(ntfimcn_cb.immOmHandle,
				className,
				&classCategory,
				&attrDescr);
	}
	if (rc != SA_AIS_OK) {
		LOG_ER("saImmOmClassDescriptionGet_2 failed %s", saf_error(rc));
		goto error;
	}

	/* Find the name of the attribute with the RDN flag set */
	s_get_rdn_attr_name.attrName[0] = '\0';
	for (i=0; attrDescr[i] != NULL; i++) {
		if (attrDescr[i]->attrFlags & SA_IMM_ATTR_RDN) {
			strncpy(s_get_rdn_attr_name.attrName,attrDescr[i]->attrName,SA_MAX_NAME_LENGTH);
			s_get_rdn_attr_name.attrName[SA_MAX_NAME_LENGTH-1] = '\0';
			break;
		}
	}

	/* Free memory allocated for attribute descriptions */
	msecs_waited = 0;
	rc = saImmOmClassDescriptionMemoryFree_2(ntfimcn_cb.immOmHandle,attrDescr);
	while ((rc == SA_AIS_ERR_TRY_AGAIN) && (msecs_waited < max_waiting_time_7s)) {
		usleep(sleep_delay_ms * 1000);
		msecs_waited += sleep_delay_ms;
		rc = saImmOmClassDescriptionMemoryFree_2(ntfimcn_cb.immOmHandle,attrDescr);
	}
	if (rc != SA_AIS_OK) {
		LOG_ER("saImmOmClassDescriptionMemoryFree_2 failed %s", saf_error(rc));
		goto error;
	}

done:
	TRACE_LEAVE();
	return s_get_rdn_attr_name.attrName;
error:
	osafassert(0);
	return 0; /* Dummy */
}
Example #30
0
/**
 * Function to process intranode poll and rcv message
 *
 *
 *
 */
void dtm_intranode_process_poll_rcv_msg(int fd)
{
	DTM_INTRANODE_PID_INFO *node = NULL;

	node = dtm_intranode_get_pid_info_using_fd(fd);

	if (NULL == node) {
		LOG_ER("DTM INTRA : PID info coressponding to fd doesnt exist, database mismatch. fd :%d",fd);
		osafassert(0);
	}
	if (0 == node->bytes_tb_read) {
		if (0 == node->num_by_read_for_len_buff) {
			uint8_t *data;
			int recd_bytes = 0;

			/*******************************************************/
			/* Receive all incoming data on this socket */
			/*******************************************************/

			recd_bytes = recv(fd, node->len_buff, 2, 0);
			if (0 == recd_bytes) {
				TRACE("DTM_INTRA: Socket close: %d  err :%s", fd, strerror(errno));
				dtm_intranode_process_pid_down(fd);
				dtm_intranode_del_poll_fdlist(fd);
				return;
			} else if (2 == recd_bytes) {
				uint16_t local_len_buf = 0;

				data = node->len_buff;
				local_len_buf = ncs_decode_16bit(&data);
				node->buff_total_len = local_len_buf;
				node->num_by_read_for_len_buff = 2;

				if (NULL == (node->buffer = calloc(1, (local_len_buf + 3)))) {
					/* Length + 2 is done to reuse the same buffer 
					   while sending to other nodes */
					LOG_ER("Memory allocation failed in dtm_intranode_processing");
					return;
				}
				recd_bytes = recv(fd, &node->buffer[2], local_len_buf, 0);

				if (recd_bytes < 0) {
					return;
				} else if (0 == recd_bytes) {
					TRACE("DTM_INTRA: Socket close: %d  err :%s", fd, strerror(errno));
					dtm_intranode_process_pid_down(fd);
					dtm_intranode_del_poll_fdlist(fd);
					return;
				} else if (local_len_buf > recd_bytes) {
					/* can happen only in two cases, system call interrupt or half data, */
					TRACE("less data recd, recd bytes = %d, actual len = %d", recd_bytes,
					       local_len_buf);
					node->bytes_tb_read = node->buff_total_len - recd_bytes;
					return;
				} else if (local_len_buf == recd_bytes) {
					/* Call the common rcv function */
					dtm_intranode_process_poll_rcv_msg_common(node);
				} else {
					osafassert(0);
				}
			} else {
				/* we had recd some bytes */
				if (recd_bytes < 0) {
					/* This can happen due to system call interrupt */
					return;
				} else if (1 == recd_bytes) {
					/* We recd one byte of the length part */
					node->num_by_read_for_len_buff = recd_bytes;
				} else {
					osafassert(0);
				}
			}
		} else if (1 == node->num_by_read_for_len_buff) {
			int recd_bytes = 0;

			recd_bytes = recv(fd, &node->len_buff[1], 1, 0);
			if (recd_bytes < 0) {
				/* This can happen due to system call interrupt */
				return;
			} else if (1 == recd_bytes) {
				/* We recd one byte(remaining) of the length part */
				uint8_t *data = node->len_buff;
				node->num_by_read_for_len_buff = 2;
				node->buff_total_len = ncs_decode_16bit(&data);
				return;
			} else if (0 == recd_bytes) {
				TRACE("DTM_INTRA: Socket close: %d  err :%s", fd, strerror(errno));
				dtm_intranode_process_pid_down(fd);
				dtm_intranode_del_poll_fdlist(fd);
				return;
			} else {
				osafassert(0);	/* This should never occur */
			}
		} else if (2 == node->num_by_read_for_len_buff) {
			int recd_bytes = 0;

			if (NULL == (node->buffer = calloc(1, (node->buff_total_len + 3)))) {
				/* Length + 2 is done to reuse the same buffer 
				   while sending to other nodes */
				LOG_ER("\nMemory allocation failed in dtm_internode_processing");
				return;
			}
			recd_bytes = recv(fd, &node->buffer[2], node->buff_total_len, 0);

			if (recd_bytes < 0) {
				return;
			} else if (0 == recd_bytes) {
				TRACE("DTM_INTRA: Socket close: %d  err :%s", fd, strerror(errno));
				dtm_intranode_process_pid_down(fd);
				dtm_intranode_del_poll_fdlist(fd);
				return;
			} else if (node->buff_total_len > recd_bytes) {
				/* can happen only in two cases, system call interrupt or half data, */
				TRACE("less data recd, recd bytes = %d, actual len = %d", recd_bytes,
				       node->buff_total_len);
				node->bytes_tb_read = node->buff_total_len - recd_bytes;
				return;
			} else if (node->buff_total_len == recd_bytes) {
				/* Call the common rcv function */
				dtm_intranode_process_poll_rcv_msg_common(node);
			} else {
				osafassert(0);
			}
		} else {
			osafassert(0);
		}

	} else {
		/* Partial data already read */
		int recd_bytes = 0;

		recd_bytes =
		    recv(fd, &node->buffer[2 + (node->buff_total_len - node->bytes_tb_read)], node->bytes_tb_read, 0);

		if (recd_bytes < 0) {
			return;
		} else if (0 == recd_bytes) {
			TRACE("DTM_INTRA: Socket close: %d  err :%s", fd, strerror(errno));
			/* Close the connection */
			dtm_intranode_process_pid_down(fd);
			dtm_intranode_del_poll_fdlist(fd);
			return;
		} else if (node->bytes_tb_read > recd_bytes) {
			/* can happen only in two cases, system call interrupt or half data, */
			TRACE("less data recd, recd bytes = %d, actual len = %d", recd_bytes, node->bytes_tb_read);
			node->bytes_tb_read = node->bytes_tb_read - recd_bytes;
			return;
		} else if (node->bytes_tb_read == recd_bytes) {
			/* Call the common rcv function */
			dtm_intranode_process_poll_rcv_msg_common(node);
		} else {
			osafassert(0);
		}
	}
	return;
}