I think it's handy to have a _local_get() call in most libraries. Lots
of applications only use one library and most need to know the local nodeid.
This patch adds it to libcfg.
Chrissie
Index: include/corosync/ipc_cfg.h
===================================================================
--- include/corosync/ipc_cfg.h (revision 1758)
+++ include/corosync/ipc_cfg.h (working copy)
@@ -52,7 +52,8 @@
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 @@
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 @@
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,
Index: include/corosync/cfg.h
===================================================================
--- include/corosync/cfg.h (revision 1758)
+++ include/corosync/cfg.h (working copy)
@@ -235,6 +235,10 @@
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
}
Index: services/cfg.c
===================================================================
--- services/cfg.c (revision 1758)
+++ services/cfg.c (working copy)
@@ -166,6 +166,10 @@
void *conn,
void *msg);
+static void message_handler_req_lib_cfg_local_get (
+ void *conn,
+ void *msg);
+
/*
* Service Handler Definition
*/
@@ -242,6 +246,12 @@
.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 @@
}
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));
+}
Index: tools/corosync-cfgtool.c
===================================================================
--- tools/corosync-cfgtool.c (revision 1758)
+++ tools/corosync-cfgtool.c (working copy)
@@ -58,6 +58,7 @@
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 @@
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,
Index: lib/cfg.c
===================================================================
--- lib/cfg.c (revision 1758)
+++ lib/cfg.c (working copy)
@@ -870,3 +870,45 @@
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);
+}
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais