38 #include <sys/types.h>
40 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
54 #include <qb/qbipc_common.h>
78 #define DEFAULT_SHUTDOWN_TIMEOUT 5
86 static struct cfg_info *shutdown_con;
87 static uint32_t shutdown_flags;
88 static int shutdown_yes;
89 static int shutdown_no;
90 static int shutdown_expected;
100 static void cfg_confchg_fn (
102 const unsigned int *member_list,
size_t member_list_entries,
103 const unsigned int *left_list,
size_t left_list_entries,
104 const unsigned int *joined_list,
size_t joined_list_entries,
111 static int cfg_lib_init_fn (
void *conn);
113 static int cfg_lib_exit_fn (
void *conn);
115 static void message_handler_req_exec_cfg_ringreenable (
119 static void message_handler_req_exec_cfg_killnode (
123 static void message_handler_req_exec_cfg_shutdown (
127 static void message_handler_req_exec_cfg_reload_config (
131 static void exec_cfg_killnode_endian_convert (
void *msg);
133 static void message_handler_req_lib_cfg_ringstatusget (
137 static void message_handler_req_lib_cfg_ringreenable (
141 static void message_handler_req_lib_cfg_killnode (
145 static void message_handler_req_lib_cfg_tryshutdown (
149 static void message_handler_req_lib_cfg_replytoshutdown (
153 static void message_handler_req_lib_cfg_get_node_addrs (
157 static void message_handler_req_lib_cfg_local_get (
161 static void message_handler_req_lib_cfg_reload_config (
175 .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
179 .lib_handler_fn = message_handler_req_lib_cfg_killnode,
183 .lib_handler_fn = message_handler_req_lib_cfg_tryshutdown,
187 .lib_handler_fn = message_handler_req_lib_cfg_replytoshutdown,
191 .lib_handler_fn = message_handler_req_lib_cfg_get_node_addrs,
195 .lib_handler_fn = message_handler_req_lib_cfg_local_get,
199 .lib_handler_fn = message_handler_req_lib_cfg_reload_config,
210 .exec_handler_fn = message_handler_req_exec_cfg_killnode,
211 .exec_endian_convert_fn = exec_cfg_killnode_endian_convert
214 .exec_handler_fn = message_handler_req_exec_cfg_shutdown,
217 .exec_handler_fn = message_handler_req_exec_cfg_reload_config,
225 .
name =
"corosync configuration service",
228 .private_data_size =
sizeof(
struct cfg_info),
231 .lib_init_fn = cfg_lib_init_fn,
232 .lib_exit_fn = cfg_lib_exit_fn,
233 .lib_engine = cfg_lib_engine,
235 .exec_init_fn = cfg_exec_init_fn,
236 .exec_engine = cfg_exec_engine,
238 .confchg_fn = cfg_confchg_fn
243 return (&cfg_service_engine);
247 struct qb_ipc_request_header header __attribute__((aligned(8)));
252 struct qb_ipc_request_header header __attribute__((aligned(8)));
257 struct qb_ipc_request_header header __attribute__((aligned(8)));
263 struct qb_ipc_request_header header __attribute__((aligned(8)));
268 static char *cfg_exec_init_fn (
271 api = corosync_api_v1;
273 list_init(&trackers_list);
277 static void cfg_confchg_fn (
279 const unsigned int *member_list,
size_t member_list_entries,
280 const unsigned int *left_list,
size_t left_list_entries,
281 const unsigned int *joined_list,
size_t joined_list_entries,
289 static int send_shutdown(
void)
309 static void send_test_shutdown(
void *only_conn,
void *exclude_conn,
int status)
321 TRACE1(
"sending testshutdown to only %p", only_conn);
325 for (iter = trackers_list.
next; iter != &trackers_list; iter = iter->
next) {
328 if (ci->
conn != exclude_conn) {
338 static void check_shutdown_status(
void)
353 if (shutdown_yes + shutdown_no >= shutdown_expected) {
358 if (shutdown_yes >= shutdown_expected ||
360 TRACE1(
"shutdown confirmed");
381 TRACE1(
"shutdown cancelled");
395 shutdown_yes, shutdown_no, shutdown_flags);
404 static void shutdown_timer_fn(
void *arg)
411 shutdown_no = shutdown_expected;
412 check_shutdown_status();
418 static void remove_ci_from_shutdown(
struct cfg_info *ci)
426 if (ci == shutdown_con) {
431 if (!list_empty(&ci->
list)) {
433 list_init(&ci->
list);
451 check_shutdown_status();
457 int cfg_lib_exit_fn (
void *conn)
462 remove_ci_from_shutdown(ci);
467 static int cfg_lib_init_fn (
void *conn)
472 list_init(&ci->
list);
481 static void message_handler_req_exec_cfg_ringreenable (
496 req_exec_cfg_ringreenable->source.conn,
505 static void exec_cfg_killnode_endian_convert (
void *msg)
508 (
struct req_exec_cfg_killnode *)msg;
511 swab_mar_name_t(&req_exec_cfg_killnode->reason);
516 static void message_handler_req_exec_cfg_killnode (
527 marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
529 nodeid, reason.
value);
538 static void message_handler_req_exec_cfg_shutdown (
552 static int nullcheck_strcmp(
const char* left,
const char *right)
562 return strcmp(left, right);
568 static void delete_and_notify_if_changed(
icmap_map_t temp_map,
const char *key_name)
583 static void remove_ro_entries(
icmap_map_t temp_map)
585 delete_and_notify_if_changed(temp_map,
"totem.secauth");
586 delete_and_notify_if_changed(temp_map,
"totem.crypto_hash");
587 delete_and_notify_if_changed(temp_map,
"totem.crypto_cipher");
588 delete_and_notify_if_changed(temp_map,
"totem.version");
589 delete_and_notify_if_changed(temp_map,
"totem.threads");
590 delete_and_notify_if_changed(temp_map,
"totem.ip_version");
591 delete_and_notify_if_changed(temp_map,
"totem.rrp_mode");
592 delete_and_notify_if_changed(temp_map,
"totem.netmtu");
593 delete_and_notify_if_changed(temp_map,
"totem.interface.ringnumber");
594 delete_and_notify_if_changed(temp_map,
"totem.interface.bindnetaddr");
595 delete_and_notify_if_changed(temp_map,
"totem.interface.mcastaddr");
596 delete_and_notify_if_changed(temp_map,
"totem.interface.broadcast");
597 delete_and_notify_if_changed(temp_map,
"totem.interface.mcastport");
598 delete_and_notify_if_changed(temp_map,
"totem.interface.ttl");
599 delete_and_notify_if_changed(temp_map,
"totem.vsftype");
600 delete_and_notify_if_changed(temp_map,
"totem.transport");
601 delete_and_notify_if_changed(temp_map,
"totem.cluster_name");
602 delete_and_notify_if_changed(temp_map,
"quorum.provider");
603 delete_and_notify_if_changed(temp_map,
"qb.ipc_type");
613 static void remove_deleted_entries(
icmap_map_t temp_map,
const char *prefix)
617 const char *old_key, *new_key;
626 while (old_key || new_key) {
627 ret = nullcheck_strcmp(old_key, new_key);
628 if ((ret < 0 && old_key) || !new_key) {
638 ret = nullcheck_strcmp(old_key, new_key);
639 }
while (ret < 0 && old_key);
641 else if ((ret > 0 && new_key) || !old_key) {
651 ret = nullcheck_strcmp(old_key, new_key);
652 }
while (ret > 0 && new_key);
666 static void message_handler_req_exec_cfg_reload_config (
673 const char *error_string;
702 remove_deleted_entries(temp_map,
"logging.");
703 remove_deleted_entries(temp_map,
"totem.");
704 remove_deleted_entries(temp_map,
"nodelist.");
705 remove_deleted_entries(temp_map,
"quorum.");
708 remove_ro_entries(temp_map);
744 static void message_handler_req_lib_cfg_ringstatusget (
750 unsigned int iface_count;
752 const char *totem_ip_string;
772 for (i = 0; i < iface_count; i++) {
804 static void message_handler_req_lib_cfg_ringreenable (
808 struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
812 req_exec_cfg_ringreenable.header.size =
813 sizeof (
struct req_exec_cfg_ringreenable);
819 iovec.iov_base = (
char *)&req_exec_cfg_ringreenable;
820 iovec.iov_len =
sizeof (
struct req_exec_cfg_ringreenable);
827 static void message_handler_req_lib_cfg_killnode (
833 struct req_exec_cfg_killnode req_exec_cfg_killnode;
837 req_exec_cfg_killnode.header.size =
838 sizeof (
struct req_exec_cfg_killnode);
841 req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
842 marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
844 iovec.iov_base = (
char *)&req_exec_cfg_killnode;
845 iovec.iov_len =
sizeof (
struct req_exec_cfg_killnode);
860 static void message_handler_req_lib_cfg_tryshutdown (
909 shutdown_flags = req_lib_cfg_tryshutdown->
flags;
916 shutdown_expected = 0;
918 for (iter = trackers_list.
next; iter != &trackers_list; iter = iter->
next) {
932 if (shutdown_expected == 0) {
962 shutdown_timer_fn, &shutdown_timer);
967 send_test_shutdown(NULL, conn,
CS_OK);
978 static void message_handler_req_lib_cfg_replytoshutdown (
993 if (req_lib_cfg_replytoshutdown->
response) {
1001 check_shutdown_status();
1014 static void message_handler_req_lib_cfg_get_node_addrs (
void *conn,
1020 unsigned int num_interfaces = 0;
1025 unsigned int nodeid = req_lib_cfg_get_node_addrs->
nodeid;
1031 api->
totem_ifaces_get(nodeid, node_ifs, INTERFACE_MAX, &status, &num_interfaces);
1033 res_lib_cfg_get_node_addrs->header.size =
sizeof(
struct res_lib_cfg_get_node_addrs) + (num_interfaces *
TOTEMIP_ADDRLEN);
1035 res_lib_cfg_get_node_addrs->header.error = ret;
1036 res_lib_cfg_get_node_addrs->
num_addrs = num_interfaces;
1037 if (num_interfaces) {
1038 res_lib_cfg_get_node_addrs->
family = node_ifs[0].family;
1039 for (i = 0, addr_buf = (
char *)res_lib_cfg_get_node_addrs->
addrs;
1047 api->
ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
1050 static void message_handler_req_lib_cfg_local_get (
void *conn,
const void *msg)
1063 static void message_handler_req_lib_cfg_reload_config (
void *conn,
const void *msg)
1065 struct req_exec_cfg_reload_config req_exec_cfg_reload_config;
1070 req_exec_cfg_reload_config.header.size =
1071 sizeof (
struct req_exec_cfg_reload_config);
1077 iovec.iov_base = (
char *)&req_exec_cfg_reload_config;
1078 iovec.iov_len =
sizeof (
struct req_exec_cfg_reload_config);