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> 56 #include <qb/qblist.h> 78 #define DEFAULT_SHUTDOWN_TIMEOUT 5 80 static struct qb_list_head trackers_list;
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,
109 static struct corosync_api_v1 *api;
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 (
165 static void message_handler_req_lib_cfg_reopen_log_files (
179 .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
183 .lib_handler_fn = message_handler_req_lib_cfg_killnode,
187 .lib_handler_fn = message_handler_req_lib_cfg_tryshutdown,
191 .lib_handler_fn = message_handler_req_lib_cfg_replytoshutdown,
195 .lib_handler_fn = message_handler_req_lib_cfg_get_node_addrs,
199 .lib_handler_fn = message_handler_req_lib_cfg_local_get,
203 .lib_handler_fn = message_handler_req_lib_cfg_reload_config,
207 .lib_handler_fn = message_handler_req_lib_cfg_reopen_log_files,
218 .exec_handler_fn = message_handler_req_exec_cfg_killnode,
219 .exec_endian_convert_fn = exec_cfg_killnode_endian_convert
222 .exec_handler_fn = message_handler_req_exec_cfg_shutdown,
225 .exec_handler_fn = message_handler_req_exec_cfg_reload_config,
233 .
name =
"corosync configuration service",
236 .private_data_size =
sizeof(
struct cfg_info),
239 .lib_init_fn = cfg_lib_init_fn,
240 .lib_exit_fn = cfg_lib_exit_fn,
241 .lib_engine = cfg_lib_engine,
243 .exec_init_fn = cfg_exec_init_fn,
244 .exec_engine = cfg_exec_engine,
246 .confchg_fn = cfg_confchg_fn
251 return (&cfg_service_engine);
255 struct qb_ipc_request_header header __attribute__((aligned(8)));
260 struct qb_ipc_request_header header __attribute__((aligned(8)));
265 struct qb_ipc_request_header header __attribute__((aligned(8)));
271 struct qb_ipc_request_header header __attribute__((aligned(8)));
276 static char *cfg_exec_init_fn (
277 struct corosync_api_v1 *corosync_api_v1)
279 api = corosync_api_v1;
281 qb_list_init(&trackers_list);
285 static void cfg_confchg_fn (
287 const unsigned int *member_list,
size_t member_list_entries,
288 const unsigned int *left_list,
size_t left_list_entries,
289 const unsigned int *joined_list,
size_t joined_list_entries,
297 static int send_shutdown(
void)
303 req_exec_cfg_shutdown.header.size =
304 sizeof (
struct req_exec_cfg_shutdown);
308 iovec.iov_base = (
char *)&req_exec_cfg_shutdown;
309 iovec.iov_len =
sizeof (
struct req_exec_cfg_shutdown);
317 static void send_test_shutdown(
void *only_conn,
void *exclude_conn,
int status)
320 struct qb_list_head *iter;
323 res_lib_cfg_testshutdown.header.size =
sizeof(
struct res_lib_cfg_testshutdown);
325 res_lib_cfg_testshutdown.header.error = status;
326 res_lib_cfg_testshutdown.
flags = shutdown_flags;
329 TRACE1(
"sending testshutdown to only %p", only_conn);
331 sizeof(res_lib_cfg_testshutdown));
333 qb_list_for_each(iter, &trackers_list) {
336 if (ci->
conn != exclude_conn) {
339 sizeof(res_lib_cfg_testshutdown));
346 static void check_shutdown_status(
void)
361 if (shutdown_yes + shutdown_no >= shutdown_expected) {
366 if (shutdown_yes >= shutdown_expected ||
368 TRACE1(
"shutdown confirmed");
370 res_lib_cfg_tryshutdown.header.size =
sizeof(
struct res_lib_cfg_tryshutdown);
372 res_lib_cfg_tryshutdown.header.error =
CS_OK;
378 sizeof(res_lib_cfg_tryshutdown));
389 TRACE1(
"shutdown cancelled");
390 res_lib_cfg_tryshutdown.header.size =
sizeof(
struct res_lib_cfg_tryshutdown);
392 res_lib_cfg_tryshutdown.header.error =
CS_ERR_BUSY;
398 sizeof(res_lib_cfg_tryshutdown));
403 shutdown_yes, shutdown_no, shutdown_flags);
412 static void shutdown_timer_fn(
void *arg)
419 shutdown_no = shutdown_expected;
420 check_shutdown_status();
426 static void remove_ci_from_shutdown(
struct cfg_info *ci)
434 if (ci == shutdown_con) {
439 if (!qb_list_empty(&ci->
list)) {
440 qb_list_del(&ci->
list);
441 qb_list_init(&ci->
list);
459 check_shutdown_status();
465 int cfg_lib_exit_fn (
void *
conn)
470 remove_ci_from_shutdown(ci);
475 static int cfg_lib_init_fn (
void *
conn)
480 qb_list_init(&ci->
list);
489 static void message_handler_req_exec_cfg_ringreenable (
498 static void exec_cfg_killnode_endian_convert (
void *msg)
501 (
struct req_exec_cfg_killnode *)msg;
504 swab_mar_name_t(&req_exec_cfg_killnode->reason);
509 static void message_handler_req_exec_cfg_killnode (
520 marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
522 nodeid, reason.
value);
531 static void message_handler_req_exec_cfg_shutdown (
545 static int nullcheck_strcmp(
const char* left,
const char *right)
555 return strcmp(left, right);
561 static void delete_and_notify_if_changed(
icmap_map_t temp_map,
const char *key_name)
576 static void remove_ro_entries(
icmap_map_t temp_map)
578 delete_and_notify_if_changed(temp_map,
"totem.secauth");
579 delete_and_notify_if_changed(temp_map,
"totem.crypto_hash");
580 delete_and_notify_if_changed(temp_map,
"totem.crypto_cipher");
581 delete_and_notify_if_changed(temp_map,
"totem.keyfile");
582 delete_and_notify_if_changed(temp_map,
"totem.key");
583 delete_and_notify_if_changed(temp_map,
"totem.version");
584 delete_and_notify_if_changed(temp_map,
"totem.threads");
585 delete_and_notify_if_changed(temp_map,
"totem.ip_version");
586 delete_and_notify_if_changed(temp_map,
"totem.rrp_mode");
587 delete_and_notify_if_changed(temp_map,
"totem.netmtu");
588 delete_and_notify_if_changed(temp_map,
"totem.interface.ringnumber");
589 delete_and_notify_if_changed(temp_map,
"totem.interface.bindnetaddr");
590 delete_and_notify_if_changed(temp_map,
"totem.interface.mcastaddr");
591 delete_and_notify_if_changed(temp_map,
"totem.interface.broadcast");
592 delete_and_notify_if_changed(temp_map,
"totem.interface.mcastport");
593 delete_and_notify_if_changed(temp_map,
"totem.interface.ttl");
594 delete_and_notify_if_changed(temp_map,
"totem.vsftype");
595 delete_and_notify_if_changed(temp_map,
"totem.transport");
596 delete_and_notify_if_changed(temp_map,
"totem.cluster_name");
597 delete_and_notify_if_changed(temp_map,
"quorum.provider");
598 delete_and_notify_if_changed(temp_map,
"system.move_to_root_cgroup");
599 delete_and_notify_if_changed(temp_map,
"system.sched_rr");
600 delete_and_notify_if_changed(temp_map,
"system.priority");
601 delete_and_notify_if_changed(temp_map,
"system.qb_ipc_type");
602 delete_and_notify_if_changed(temp_map,
"system.state_dir");
612 static void remove_deleted_entries(
icmap_map_t temp_map,
const char *prefix)
616 const char *old_key, *new_key;
625 while (old_key || new_key) {
626 ret = nullcheck_strcmp(old_key, new_key);
627 if ((ret < 0 && old_key) || !new_key) {
637 ret = nullcheck_strcmp(old_key, new_key);
638 }
while (ret < 0 && old_key);
640 else if ((ret > 0 && new_key) || !old_key) {
650 ret = nullcheck_strcmp(old_key, new_key);
651 }
while (ret > 0 && new_key);
665 static void message_handler_req_exec_cfg_reload_config (
672 const char *error_string;
701 remove_deleted_entries(temp_map,
"logging.");
702 remove_deleted_entries(temp_map,
"totem.");
703 remove_deleted_entries(temp_map,
"nodelist.");
704 remove_deleted_entries(temp_map,
"quorum.");
705 remove_deleted_entries(temp_map,
"uidgid.config.");
706 remove_deleted_entries(temp_map,
"nozzle.");
709 remove_ro_entries(temp_map);
730 res_lib_cfg_reload_config.header.size =
sizeof(res_lib_cfg_reload_config);
732 res_lib_cfg_reload_config.header.error = res;
734 &res_lib_cfg_reload_config,
735 sizeof(res_lib_cfg_reload_config));
745 static void message_handler_req_lib_cfg_ringstatusget (
751 unsigned int iface_count;
753 const char *totem_ip_string;
762 res_lib_cfg_ringstatusget.header.size =
sizeof (
struct res_lib_cfg_ringstatusget);
774 res_lib_cfg_ringstatusget.interface_count = iface_count;
776 for (i = 0; i < iface_count; i++) {
780 if (!totem_ip_string) {
790 snprintf(ifname,
sizeof(ifname),
"%d %s", iface_ids[i], totem_ip_string);
798 strcpy ((
char *)&res_lib_cfg_ringstatusget.interface_status[i],
800 strcpy ((
char *)&res_lib_cfg_ringstatusget.interface_name[i],
805 res_lib_cfg_ringstatusget.header.error = res;
808 &res_lib_cfg_ringstatusget,
809 sizeof (
struct res_lib_cfg_ringstatusget));
814 static void message_handler_req_lib_cfg_ringreenable (
822 res_lib_cfg_ringreenable.header.size =
sizeof (
struct res_lib_cfg_ringreenable);
825 conn, &res_lib_cfg_ringreenable,
826 sizeof (
struct res_lib_cfg_ringreenable));
831 static void message_handler_req_lib_cfg_killnode (
841 req_exec_cfg_killnode.header.size =
842 sizeof (
struct req_exec_cfg_killnode);
845 req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
846 marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
848 iovec.iov_base = (
char *)&req_exec_cfg_killnode;
849 iovec.iov_len =
sizeof (
struct req_exec_cfg_killnode);
853 res_lib_cfg_killnode.header.size =
sizeof(
struct res_lib_cfg_killnode);
855 res_lib_cfg_killnode.header.error =
CS_OK;
858 sizeof(res_lib_cfg_killnode));
864 static void message_handler_req_lib_cfg_tryshutdown (
870 struct qb_list_head *iter;
882 res_lib_cfg_tryshutdown.header.size =
sizeof(
struct res_lib_cfg_tryshutdown);
884 res_lib_cfg_tryshutdown.header.error =
CS_OK;
886 sizeof(res_lib_cfg_tryshutdown));
898 res_lib_cfg_tryshutdown.header.size =
sizeof(
struct res_lib_cfg_tryshutdown);
903 sizeof(res_lib_cfg_tryshutdown));
913 shutdown_flags = req_lib_cfg_tryshutdown->
flags;
920 shutdown_expected = 0;
922 qb_list_for_each(iter, &trackers_list) {
936 if (shutdown_expected == 0) {
939 res_lib_cfg_tryshutdown.header.size =
sizeof(
struct res_lib_cfg_tryshutdown);
941 res_lib_cfg_tryshutdown.header.error =
CS_OK;
947 sizeof(res_lib_cfg_tryshutdown));
966 shutdown_timer_fn, &shutdown_timer);
982 static void message_handler_req_lib_cfg_replytoshutdown (
997 if (req_lib_cfg_replytoshutdown->
response) {
1005 check_shutdown_status();
1008 res_lib_cfg_replytoshutdown.header.error = status;
1010 res_lib_cfg_replytoshutdown.header.size =
sizeof(res_lib_cfg_replytoshutdown);
1013 sizeof(res_lib_cfg_replytoshutdown));
1018 static void message_handler_req_lib_cfg_get_node_addrs (
void *
conn,
1025 unsigned int num_interfaces = 0;
1026 struct sockaddr_storage *ss;
1032 unsigned int nodeid = req_lib_cfg_get_node_addrs->
nodeid;
1038 if (api->
totem_ifaces_get(nodeid, iface_ids, node_ifs, INTERFACE_MAX, &status, &num_interfaces)) {
1043 res_lib_cfg_get_node_addrs->header.size =
sizeof(
struct res_lib_cfg_get_node_addrs) + (num_interfaces *
TOTEMIP_ADDRLEN);
1045 res_lib_cfg_get_node_addrs->header.error = ret;
1046 if (num_interfaces) {
1047 res_lib_cfg_get_node_addrs->
family = node_ifs[0].
family;
1048 for (i = 0, addr_buf = (
char *)res_lib_cfg_get_node_addrs->
addrs;
1049 i < num_interfaces; i++) {
1050 ss = (
struct sockaddr_storage *)&node_ifs[i].
addr;
1051 if (ss->ss_family) {
1057 res_lib_cfg_get_node_addrs->
num_addrs = live_addrs;
1064 static void message_handler_req_lib_cfg_local_get (
void *
conn,
const void *msg)
1068 res_lib_cfg_local_get.header.size =
sizeof(res_lib_cfg_local_get);
1070 res_lib_cfg_local_get.header.error =
CS_OK;
1074 sizeof(res_lib_cfg_local_get));
1077 static void message_handler_req_lib_cfg_reload_config (
void *
conn,
const void *msg)
1084 req_exec_cfg_reload_config.header.size =
1085 sizeof (
struct req_exec_cfg_reload_config);
1091 iovec.iov_base = (
char *)&req_exec_cfg_reload_config;
1092 iovec.iov_len =
sizeof (
struct req_exec_cfg_reload_config);
1099 static void message_handler_req_lib_cfg_reopen_log_files (
void *
conn,
const void *msg)
1110 res_lib_cfg_reopen_log_files.header.size =
sizeof(res_lib_cfg_reopen_log_files);
1112 res_lib_cfg_reopen_log_files.header.error = res;
1114 &res_lib_cfg_reopen_log_files,
1115 sizeof(res_lib_cfg_reopen_log_files));
void *(* ipc_private_data_get)(void *conn)
The res_lib_cfg_reopen_log_files struct.
void(* timer_delete)(corosync_timer_handle_t timer_handle)
int(* timer_add_duration)(unsigned long long nanoseconds_in_future, void *data, void(*timer_nf)(void *data), corosync_timer_handle_t *handle)
const char * icmap_iter_next(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
Return next item in iterator iter.
#define CFG_INTERFACE_STATUS_MAX_LEN
cs_error_t icmap_copy_map(icmap_map_t dst_map, const icmap_map_t src_map)
Copy content of src_map icmap to dst_map icmap.
The res_lib_cfg_replytoshutdown struct.
The res_lib_cfg_testshutdown struct.
The totem_ip_address struct.
The corosync_service_engine struct.
void icmap_iter_finalize(icmap_iter_t iter)
Finalize iterator.
void(* shutdown_request)(void)
cs_error_t logsys_reopen_log_files(void)
uint8_t value[CS_MAX_NAME_LENGTH]
int coroparse_configparse(icmap_map_t config_map, const char **error_string)
#define corosync_fatal_error(err)
int(* ipc_response_send)(void *conn, const void *msg, size_t mlen)
LOGSYS_DECLARE_SUBSYS("CFG")
int icmap_key_value_eq(const icmap_map_t map1, const char *key_name1, const icmap_map_t map2, const char *key_name2)
Compare value of key with name key_name1 in map1 with key with name key_name2 in map2.
totem_configuration_type
The totem_configuration_type enum.
int(* totem_ifaces_get)(unsigned int nodeid, unsigned int *interface_ids, struct totem_ip_address *interfaces, unsigned int interfaces_size, char ***status, unsigned int *iface_count)
The res_lib_cfg_get_node_addrs struct.
The corosync_lib_handler struct.
unsigned char addr[TOTEMIP_ADDRLEN]
The req_lib_cfg_get_node_addrs struct.
The corosync_exec_handler struct.
void icmap_fini_r(const icmap_map_t map)
Finalize local, reentrant icmap.
icmap_map_t icmap_get_global_map(void)
Return global icmap.
int(* totem_mcast)(const struct iovec *iovec, unsigned int iov_len, unsigned int guarantee)
#define log_printf(level, format, args...)
void(* exec_handler_fn)(const void *msg, unsigned int nodeid)
#define SERVICE_ID_MAKE(a, b)
The res_lib_cfg_local_get struct.
The res_lib_cfg_killnode struct.
The req_lib_cfg_tryshutdown struct.
unsigned int(* totem_nodeid_get)(void)
void(* ipc_refcnt_dec)(void *conn)
The res_lib_cfg_ringreenable struct.
#define LOGSYS_LEVEL_ERROR
#define TRACE1(format, args...)
#define CFG_INTERFACE_NAME_MAX_LEN
cs_error_t icmap_delete(const char *key_name)
Delete key from map.
cs_error_t
The cs_error_t enum.
#define LOGSYS_LEVEL_DEBUG
The corosync_api_v1 struct.
The req_lib_cfg_replytoshutdown struct.
The res_lib_cfg_tryshutdown struct.
cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
#define DEFAULT_SHUTDOWN_TIMEOUT
#define CFG_MAX_INTERFACES
const char *(* totem_ip_print)(const struct totem_ip_address *addr)
cs_error_t icmap_delete_r(const icmap_map_t map, const char *key_name)
icmap_delete_r
The res_lib_cfg_ringstatusget struct.
cs_error_t icmap_init_r(icmap_map_t *result)
Initialize additional (local, reentrant) icmap_map.
qb_loop_timer_handle corosync_timer_handle_t
corosync_timer_handle_t
struct corosync_service_engine cfg_service_engine
The res_lib_cfg_reload_config struct.
#define LOGSYS_LEVEL_NOTICE
cs_error_t icmap_set_uint8(const char *key_name, uint8_t value)
void(* lib_handler_fn)(void *conn, const void *msg)
struct corosync_service_engine * cfg_get_service_engine_ver0(void)
int(* ipc_dispatch_send)(void *conn, const void *msg, size_t mlen)
icmap_iter_t icmap_iter_init_r(const icmap_map_t map, const char *prefix)
icmap_iter_init_r
icmap_iter_t icmap_iter_init(const char *prefix)
Initialize iterator with given prefix.
struct memb_ring_id ring_id
void(* ipc_source_set)(mar_message_source_t *source, void *conn)
The req_lib_cfg_killnode struct.
qb_map_iter_t * icmap_iter_t
Itterator type.
enum cfg_info::@6 shutdown_reply
The mar_message_source_t struct.
void(* ipc_refcnt_inc)(void *conn)