⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientlib.c

📁 在LINUX下实现HA的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
}lrm_rsc_t*lrm_get_rsc (ll_lrm_t* lrm, rsc_id_t rsc_id){	struct ha_msg* msg;	struct ha_msg* ret;	char* params = NULL;	lrm_rsc_t* rsc = NULL;	client_log(LOG_INFO, 1, "lrm_get_rsc: start.");	/*check whether the channel to lrmd is available */	if (NULL == ch_cmd)	{		client_log(LOG_ERR, -1, "lrm_get_rsc: ch_mod is null.");		return NULL;	}	/*create the msg of get resource */	msg = create_lrm_rsc_msg(rsc_id, GETRSC);	if ( NULL == msg) {		client_log(LOG_ERR, -1,"lrm_get_rsc: can not create types msg");		return NULL;	}	/*send the msg to lrmd */	if (HA_OK != msg2ipcchan(msg,ch_cmd)) {		ha_msg_del(msg);		client_log(LOG_ERR, -1,"lrm_get_rsc: can not send msg to lrmd");		return NULL;	}	ha_msg_del(msg);	/*get the return msg from lrmd */	ret = msgfromIPC_noauth(ch_cmd);	if (NULL == ret) {		client_log(LOG_ERR, -1, "lrm_get_rsc: can not recieve ret msg");		return NULL;	}	/*get the rc of return message */	if (HA_FAIL == get_rc_from_msg(ret)) {		ha_msg_del(ret);		client_log(LOG_ERR, -1, "lrm_get_rsc: rc from msg is fail");		return NULL;	}	/*create a new resource structure */	rsc = g_new(lrm_rsc_t, 1);	/*fill the field of resource with the data from msg */	ha_msg_value_uuid(msg,F_LRM_RID, rsc->id);	rsc->name = g_strdup(ha_msg_value(msg, F_LRM_RNAME));	rsc->ra_type = g_strdup(ha_msg_value(msg, F_LRM_RTYPE));	rsc->params = NULL;	params = g_strdup(ha_msg_value(msg, F_LRM_PARAM));	if (NULL != params) {		rsc->params = string_to_hash_table(params);	}	else {		rsc->params = NULL;	}	rsc->ops = &rsc_ops_instance;	ha_msg_del(ret);	client_log(LOG_INFO, -1, "lrm_get_rsc: end.");	/*return the new resource */	return rsc;}intlrm_add_rsc (ll_lrm_t* lrm, rsc_id_t rsc_id, const char* rsc_type, 			 const char* rsc_name, GHashTable* parameter){	struct ha_msg* msg;	client_log(LOG_INFO, 1, "lrm_add_rsc: start.");	/*check whether the channel to lrmd is available */	if (NULL == ch_cmd)	{		client_log(LOG_ERR, -1, "lrm_add_rsc: ch_mod is null.");		return HA_FAIL;	}	/*create the message of add resource */	msg = create_lrm_addrsc_msg(rsc_id, rsc_name, rsc_type, parameter);	if ( NULL == msg) {		client_log(LOG_ERR, -1,"lrm_add_rsc: can not create types msg");		return HA_FAIL;	}	/*send to lrmd */	if (HA_OK != msg2ipcchan(msg,ch_cmd)) {		ha_msg_del(msg);		client_log(LOG_ERR, -1,"lrm_add_rsc: can not send msg to lrmd");		return HA_FAIL;	}	ha_msg_del(msg);	/*check the result */	if (HA_OK != get_rc_from_ch(ch_cmd)) {		client_log(LOG_ERR, -1,"lrm_add_rsc: rc is fail");		return HA_FAIL;	}	client_log(LOG_INFO, -1, "lrm_add_rsc: end.");	return HA_OK;}intlrm_delete_rsc (ll_lrm_t* lrm, rsc_id_t rsc_id){	struct ha_msg* msg;	GList* op_node = NULL;	GList* mon_node = NULL;	client_log(LOG_INFO, 1, "lrm_delete_rsc: start.");	/*check whether the channel to lrmd is available */	if (NULL == ch_cmd)	{		client_log(LOG_ERR, -1, "lrm_delete_rsc: ch_mod is null.");		return HA_FAIL;	}	/*create the msg of del resource */	msg = create_lrm_rsc_msg(rsc_id, DELRSC);	if ( NULL == msg) {		client_log(LOG_ERR, -1,			"lrm_delete_rsc: can not create types msg");		return HA_FAIL;	}	/*send the msg to lrmd */	if (HA_OK != msg2ipcchan(msg,ch_cmd)) {		ha_msg_del(msg);		client_log(LOG_ERR, -1,			"lrm_delete_rsc: can not send msg to lrmd");		return HA_FAIL;	}	ha_msg_del(msg);	/*check the response of the msg */	if (HA_FAIL == get_rc_from_ch(ch_cmd)) {		client_log(LOG_ERR, -1, "lrm_delete_rsc: rc from msg is fail");		return HA_FAIL;	}	/*remove all ops belong to this resource */	op_node = g_list_first(op_list);	while (NULL != op_node) {		lrm_op_t* op = (lrm_op_t*)op_node->data;		if (0 == uuid_compare(op->rsc->id, rsc_id)) {			op_node = g_list_next(op_node);			op_list = g_list_remove(op_list, op);			free_op(op);		}		else {			op_node = g_list_next(op_node);		}	}	/*remove all monitors belong to this resource */	mon_node = g_list_first(mon_list);	while (NULL != mon_node) {		lrm_mon_t* mon = (lrm_mon_t*)mon_node->data;		if (0 == uuid_compare(mon->rsc->id, rsc_id)) {			mon_node = g_list_next(mon_node);			mon_list = g_list_remove(mon_list, mon);			free_mon(mon);		}		else {			mon_node = g_list_next(mon_node);		}	}	client_log(LOG_INFO, -1, "lrm_delete_rsc: end.");	return HA_OK;}intlrm_inputfd (ll_lrm_t* lrm){	client_log(LOG_INFO, 1, "lrm_inputfd: start.");	if (NULL == ch_cbk) {		client_log(LOG_ERR, -1, 			"lrm_inputfd: callback channel is null.");		return -1;	}	client_log(LOG_INFO, -1, "lrm_inputfd: end.");	return ch_cbk->ops->get_recv_select_fd(ch_cbk);}gbooleanlrm_msgready (ll_lrm_t* lrm){	client_log(LOG_INFO, 1, "lrm_msgready: start.");	if (NULL == ch_cbk) {		client_log(LOG_ERR, -1, 			"lrm_msgready: callback channel is null.");		return FALSE;	}	client_log(LOG_INFO, -1, "lrm_msgready: end.");	return ch_cbk->ops->is_message_pending(ch_cbk);}intlrm_rcvmsg (ll_lrm_t* lrm, int blocking){	int msg_count = 0;	int call_id = 0;	struct ha_msg* msg = NULL;	lrm_op_t* op = NULL;	client_log(LOG_INFO, 1, "lrm_rcvmsg: start.");	/*if it is not blocking mode and no message in the channel, return */	if ((!lrm_msgready(lrm)) && (!blocking)) {		client_log(LOG_INFO, -1, 			"lrm_rcvmsg: no message and non-block.");		return msg_count;	}	/*wait until message ready */	if (!lrm_msgready(lrm)) {		ch_cbk->ops->waitin(ch_cbk);	}	while (lrm_msgready(lrm)) {		/*get the message */		msg = msgfromIPC_noauth(ch_cbk);		if (msg == NULL) {			client_log(LOG_ERR, -1, 				"lrm_rcvmsg: recieve a null msg.");			return msg_count;		}		msg_count++;		/*get tthe call_id from message */		if (HA_FAIL == ha_msg_value_int(msg, F_LRM_CALLID, &call_id)) {			client_log(LOG_ERR, -1, 				"lrm_rcvmsg: can not get call id from msg.");			return msg_count;		}		/*check whether it is an op done call back. */		op = lookup_op(call_id);		if (NULL != op ) {			/*if it is an op done call back, call on_op_done */			on_op_done (call_id, op, msg);		}		else {			/*if it is an monitor notify msg, call on_monitor */			lrm_mon_t* mon = lookup_mon(call_id);			if (NULL != mon) {				on_monitor(call_id, mon, msg);			}			else {				client_log(LOG_ERR, 0,				"lrm_rcvmsg: get a msg with unknown call id.");			}		}		ha_msg_del(msg);	}	client_log(LOG_INFO, -1, "lrm_rcvmsg: end.");	return msg_count;}/* following are the functions for rsc_ops */intrsc_perform_op (lrm_rsc_t* rsc, lrm_op_t* op_in){	int rc = 0;	lrm_op_t* op = NULL;	struct ha_msg* msg = NULL;	client_log(LOG_INFO, 1, "rsc_perform_op: start.");	/*check whether the channel to lrmd is available*/	if (NULL == ch_cmd)	{		client_log(LOG_ERR, -1, "rsc_perform_op: ch_mod is null.");		return HA_FAIL;	}	/*check the parameters */	if (NULL == rsc) {		client_log(LOG_ERR, -1, "rsc_perform_op: rsc is null.");		return HA_FAIL;	}	if (NULL == op_in || NULL == op_in->op_type) {		client_log(LOG_ERR, -1, 			"rsc_perform_op: op or op_type is null.");		return HA_FAIL;	}	/*copy the op */	op_in->rsc = rsc;	op_in->app_name = NULL;	op_in->data = NULL;	op = copy_op(op_in);	/*create the msg of perform op */	msg = create_rsc_perform_op_msg(rsc->id, op);	if ( NULL == msg) {		client_log(LOG_ERR, -1,"rsc_perform_op: can not create msg");		return HA_FAIL;	}	/*send it to lrmd */	if (HA_OK != msg2ipcchan(msg,ch_cmd)) {		ha_msg_del(msg);		client_log(LOG_ERR, -1,			"rsc_perform_op: can not send msg to lrmd");		return HA_FAIL;	}	ha_msg_del(msg);	/*check return code, the return code is the call_id of the op */	rc = get_rc_from_ch(ch_cmd);	/*add the op to op_list */	if (rc > 0) {		op->call_id = rc;		op_list = g_list_append(op_list, op);	}else {		client_log(LOG_ERR, 0,"rsc_perform_op: lrmd return 0");	}	client_log(LOG_INFO, -1, "rsc_perform_op: end.");	return rc;}intrsc_flush_ops (lrm_rsc_t* rsc){	int rc;	struct ha_msg* msg = NULL;	client_log(LOG_INFO, 1, "rsc_flush_ops: start.");	/*check whether the channel to lrmd is available */	if (NULL == ch_cmd)	{		client_log(LOG_ERR, -1, "rsc_flush_ops: ch_mod is null.");		return HA_FAIL;	}	/*check parameter */	if (NULL == rsc) {		client_log(LOG_ERR, -1, "rsc_flush_ops: rsc is null.");		return HA_FAIL;	}	/*create the msg of flush ops */	msg = create_lrm_rsc_msg(rsc->id,FLUSHOPS);	if ( NULL == msg) {		client_log(LOG_ERR, -1,"rsc_flush_ops: can not create msg");		return HA_FAIL;	}	/*send the msg to lrmd */	if (HA_OK != msg2ipcchan(msg,ch_cmd)) {		ha_msg_del(msg);		client_log(LOG_ERR, -1,			"rsc_flush_ops: can not send msg to lrmd");		return HA_FAIL;	}	ha_msg_del(msg);	rc = get_rc_from_ch(ch_cmd);	client_log(LOG_INFO, -1, "rsc_flush_ops: end.");	return rc;}intrsc_set_monitor (lrm_rsc_t* rsc, lrm_mon_t* mon_in){	lrm_mon_t* mon = NULL;	int rc;	struct ha_msg* msg = NULL;	client_log(LOG_INFO, 1, "rsc_set_monitor: start.");	/*check whether the channel to lrmd is available */	if (NULL == ch_cmd)	{		client_log(LOG_ERR, -1, "rsc_set_monitor: ch_mod is null.");		return HA_FAIL;	}	/*check parameter */	if (NULL == mon_in) {		client_log(LOG_ERR, -1, "rsc_set_monitor: mon is null.");		return HA_FAIL;	}	if (NULL == rsc) {		client_log(LOG_ERR, -1, "rsc_set_monitor: rsc is null.");		return HA_FAIL;	}	/*copy the mon */	mon_in->rsc = rsc;	mon = copy_mon(mon_in);	/*create the message for set a monitor */	msg = create_rsc_set_monitor_msg(rsc->id, mon);	if (NULL == msg) {		client_log(LOG_ERR, -1,"rsc_set_monitor: can not create msg");		return HA_FAIL;	}	/*send the message */	if (HA_OK != msg2ipcchan(msg,ch_cmd)) {		ha_msg_del(msg);		client_log(LOG_ERR, -1,			"rsc_set_monitor: can not send msg to lrmd");		return HA_FAIL;	}	ha_msg_del(msg);	/*get the rc of the mesage and add the monitor to mon_list */	rc = get_rc_from_ch(ch_cmd);	if (rc > 0) {		mon->call_id = rc;		mon_list = g_list_append(mon_list, mon);	}else {		client_log(LOG_ERR, 0,"rsc_set_monitor: lrmd return 0");	}	client_log(LOG_INFO, -1, "rsc_set_monitor: end.");	return rc;}GList*rsc_get_monitors (lrm_rsc_t* rsc){	GList* rsc_mon_list = NULL;	GList* node;	client_log(LOG_INFO, 1, "rsc_get_monitors: start.");	for(node = g_list_first(mon_list); NULL != node; 		node = g_list_next(node)){		lrm_mon_t* mon = (lrm_mon_t*)node->data;		if (rsc == mon->rsc) {			rsc_mon_list = g_list_append(rsc_mon_list, 							copy_mon(mon));		}	}	client_log(LOG_INFO, -1, "rsc_get_monitors: end.");	return rsc_mon_list;}GList*rsc_get_cur_state (lrm_rsc_t* rsc, state_flag_t* cur_state){	GList* pending_op_list = NULL;	struct ha_msg* msg = NULL;	struct ha_msg* ret = NULL;	lrm_op_t* op = NULL;	int state;	client_log(LOG_INFO, 1, "rsc_get_cur_state: start.");	/*check whether the channel to lrmd is available */	if (NULL == ch_cmd)	{		client_log(LOG_ERR, -1, "rsc_get_cur_state: ch_mod is null.");		return HA_FAIL;	}	/*check paramter */	if (NULL == rsc) {		client_log(LOG_ERR, -1, "rsc_get_cur_state: rsc is null.");		return NULL;	}	/*create the msg of get current state of resource */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -