Add corosync_cfg_local_get() call to get the local NodeID in libcfg

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1759 fd59a12c-fef9-0310-b244-a6a79926bd2f
This commit is contained in:
Christine Caulfield 2009-02-13 09:21:57 +00:00
parent e1239b96f4
commit 7e5a3e4c87
5 changed files with 91 additions and 2 deletions

View File

@ -235,6 +235,10 @@ corosync_cfg_get_node_addrs (
int *num_addrs,
corosync_cfg_node_address_t *addrs);
cs_error_t
corosync_cfg_local_get (
corosync_cfg_handle_t handle,
unsigned int *local_nodeid);
#ifdef __cplusplus
}

View File

@ -52,7 +52,8 @@ enum req_lib_cfg_types {
MESSAGE_REQ_CFG_KILLNODE = 8,
MESSAGE_REQ_CFG_TRYSHUTDOWN = 9,
MESSAGE_REQ_CFG_REPLYTOSHUTDOWN = 10,
MESSAGE_REQ_CFG_GET_NODE_ADDRS = 11
MESSAGE_REQ_CFG_GET_NODE_ADDRS = 11,
MESSAGE_REQ_CFG_LOCAL_GET = 12
};
enum res_lib_cfg_types {
@ -67,7 +68,8 @@ enum res_lib_cfg_types {
MESSAGE_RES_CFG_KILLNODE = 8,
MESSAGE_RES_CFG_TRYSHUTDOWN = 9,
MESSAGE_RES_CFG_TESTSHUTDOWN = 10,
MESSAGE_RES_CFG_GET_NODE_ADDRS = 11
MESSAGE_RES_CFG_GET_NODE_ADDRS = 11,
MESSAGE_RES_CFG_LOCAL_GET = 12
};
struct req_lib_cfg_statetrack {
@ -190,6 +192,15 @@ struct res_lib_cfg_get_node_addrs {
char addrs[TOTEMIP_ADDRLEN][0];
};
struct req_lib_cfg_local_get {
mar_req_header_t header __attribute__((aligned(8)));
};
struct res_lib_cfg_local_get {
mar_res_header_t header __attribute__((aligned(8)));
mar_uint32_t local_nodeid __attribute__((aligned(8)));
};
typedef enum {
AIS_AMF_ADMINISTRATIVETARGET_SERVICEUNIT = 0,
AIS_AMF_ADMINISTRATIVETARGET_SERVICEGROUP = 1,

View File

@ -870,3 +870,45 @@ error_exit:
pthread_mutex_unlock (&cfg_instance->response_mutex);
return (error);
}
cs_error_t corosync_cfg_local_get (
corosync_cfg_handle_t handle,
unsigned int *local_nodeid)
{
cs_error_t error;
struct cfg_instance *cfg_inst;
struct iovec iov;
struct req_lib_cfg_local_get req_lib_cfg_local_get;
struct res_lib_cfg_local_get res_lib_cfg_local_get;
error = saHandleInstanceGet (&cfg_hdb, handle, (void *)&cfg_inst);
if (error != CS_OK) {
return (error);
}
req_lib_cfg_local_get.header.size = sizeof (mar_req_header_t);
req_lib_cfg_local_get.header.id = MESSAGE_REQ_CFG_LOCAL_GET;
iov.iov_base = &req_lib_cfg_local_get;
iov.iov_len = sizeof (struct req_lib_cfg_local_get);
pthread_mutex_lock (&cfg_inst->response_mutex);
error = saSendMsgReceiveReply (cfg_inst->response_fd, &iov, 1,
&res_lib_cfg_local_get, sizeof (res_lib_cfg_local_get));
pthread_mutex_unlock (&cfg_inst->response_mutex);
if (error != CS_OK) {
goto error_exit;
}
error = res_lib_cfg_local_get.header.error;
*local_nodeid = res_lib_cfg_local_get.local_nodeid;
error_exit:
(void)saHandleInstancePut (&cfg_hdb, handle);
return (error);
}

View File

@ -166,6 +166,10 @@ static void message_handler_req_lib_cfg_get_node_addrs (
void *conn,
void *msg);
static void message_handler_req_lib_cfg_local_get (
void *conn,
void *msg);
/*
* Service Handler Definition
*/
@ -242,6 +246,12 @@ static struct corosync_lib_handler cfg_lib_engine[] =
.response_size = sizeof (struct res_lib_cfg_get_node_addrs),
.response_id = MESSAGE_RES_CFG_GET_NODE_ADDRS,
.flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
},
{ /* 12 */
.lib_handler_fn = message_handler_req_lib_cfg_local_get,
.response_size = sizeof (struct res_lib_cfg_local_get),
.response_id = MESSAGE_RES_CFG_LOCAL_GET,
.flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
}
};
@ -1001,3 +1011,16 @@ static void message_handler_req_lib_cfg_get_node_addrs (void *conn, void *msg)
}
api->ipc_conn_send_response(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
}
static void message_handler_req_lib_cfg_local_get (void *conn, void *message)
{
struct res_lib_cfg_local_get res_lib_cfg_local_get;
res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
res_lib_cfg_local_get.header.error = CS_OK;
res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
api->ipc_conn_send_response(conn, &res_lib_cfg_local_get,
sizeof(res_lib_cfg_local_get));
}

View File

@ -58,6 +58,7 @@ static void ringstatusget_do (void)
char **interface_names;
char **interface_status;
unsigned int i;
unsigned int nodeid;
printf ("Printing ring status.\n");
result = corosync_cfg_initialize (&handle, NULL);
@ -66,6 +67,14 @@ static void ringstatusget_do (void)
exit (1);
}
result = corosync_cfg_local_get(handle, &nodeid);
if (result != CS_OK) {
printf ("Could not get the local node id, the error is: %d\n", result);
}
else {
printf ("Local node ID %d\n", nodeid);
}
result = corosync_cfg_ring_status_get (handle,
&interface_names,
&interface_status,