42 #include <sys/types.h>
44 #include <sys/socket.h>
46 #include <netinet/in.h>
47 #include <arpa/inet.h>
59 #include <qb/qbipc_common.h>
61 #include <qb/qblist.h>
62 #include <qb/qbutil.h>
88 #define DEFAULT_SHUTDOWN_TIMEOUT 5000
90 static struct qb_list_head trackers_list;
96 static struct cfg_info *shutdown_con;
97 static uint32_t shutdown_flags;
98 static int shutdown_yes;
99 static int shutdown_no;
100 static int shutdown_expected;
110 static void cfg_confchg_fn (
112 const unsigned int *member_list,
size_t member_list_entries,
113 const unsigned int *left_list,
size_t left_list_entries,
114 const unsigned int *joined_list,
size_t joined_list_entries,
121 static int cfg_lib_init_fn (
void *conn);
123 static int cfg_lib_exit_fn (
void *conn);
125 static void message_handler_req_exec_cfg_ringreenable (
129 static void message_handler_req_exec_cfg_killnode (
133 static void message_handler_req_exec_cfg_shutdown (
137 static void message_handler_req_exec_cfg_reload_config (
141 static void message_handler_req_exec_cfg_reconfig_crypto (
145 static void exec_cfg_killnode_endian_convert (
void *msg);
147 static void message_handler_req_lib_cfg_ringstatusget (
151 static void message_handler_req_lib_cfg_nodestatusget (
155 static void message_handler_req_lib_cfg_ringreenable (
159 static void message_handler_req_lib_cfg_killnode (
163 static void message_handler_req_lib_cfg_tryshutdown (
167 static void message_handler_req_lib_cfg_replytoshutdown (
171 static void message_handler_req_lib_cfg_trackstart (
175 static void message_handler_req_lib_cfg_trackstop (
179 static void message_handler_req_lib_cfg_get_node_addrs (
183 static void message_handler_req_lib_cfg_local_get (
187 static void message_handler_req_lib_cfg_reload_config (
191 static void message_handler_req_lib_cfg_reopen_log_files (
205 .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
209 .lib_handler_fn = message_handler_req_lib_cfg_killnode,
213 .lib_handler_fn = message_handler_req_lib_cfg_tryshutdown,
217 .lib_handler_fn = message_handler_req_lib_cfg_replytoshutdown,
221 .lib_handler_fn = message_handler_req_lib_cfg_get_node_addrs,
225 .lib_handler_fn = message_handler_req_lib_cfg_local_get,
229 .lib_handler_fn = message_handler_req_lib_cfg_reload_config,
233 .lib_handler_fn = message_handler_req_lib_cfg_reopen_log_files,
237 .lib_handler_fn = message_handler_req_lib_cfg_nodestatusget,
241 .lib_handler_fn = message_handler_req_lib_cfg_trackstart,
245 .lib_handler_fn = message_handler_req_lib_cfg_trackstop,
257 .exec_handler_fn = message_handler_req_exec_cfg_killnode,
258 .exec_endian_convert_fn = exec_cfg_killnode_endian_convert
261 .exec_handler_fn = message_handler_req_exec_cfg_shutdown,
264 .exec_handler_fn = message_handler_req_exec_cfg_reload_config,
267 .exec_handler_fn = message_handler_req_exec_cfg_reconfig_crypto,
275 .
name =
"corosync configuration service",
278 .private_data_size =
sizeof(
struct cfg_info),
281 .lib_init_fn = cfg_lib_init_fn,
282 .lib_exit_fn = cfg_lib_exit_fn,
283 .lib_engine = cfg_lib_engine,
285 .exec_init_fn = cfg_exec_init_fn,
286 .exec_engine = cfg_exec_engine,
288 .confchg_fn = cfg_confchg_fn
293 return (&cfg_service_engine);
297 struct qb_ipc_request_header header __attribute__((aligned(8)));
302 struct qb_ipc_request_header header __attribute__((aligned(8)));
307 struct qb_ipc_request_header header __attribute__((aligned(8)));
312 struct qb_ipc_request_header header __attribute__((aligned(8)));
318 struct qb_ipc_request_header header __attribute__((aligned(8)));
323 static char *cfg_exec_init_fn (
326 api = corosync_api_v1;
328 qb_list_init(&trackers_list);
332 static void cfg_confchg_fn (
334 const unsigned int *member_list,
size_t member_list_entries,
335 const unsigned int *left_list,
size_t left_list_entries,
336 const unsigned int *joined_list,
size_t joined_list_entries,
344 static int send_shutdown(
void)
364 static void send_test_shutdown(
void *only_conn,
void *exclude_conn,
int status)
367 struct qb_list_head *iter;
376 TRACE1(
"sending testshutdown to only %p", only_conn);
380 qb_list_for_each(iter, &trackers_list) {
383 if (ci->
conn != exclude_conn) {
393 static void check_shutdown_status(
void)
408 if (shutdown_yes + shutdown_no >= shutdown_expected) {
413 if (shutdown_yes >= shutdown_expected ||
415 TRACE1(
"shutdown confirmed");
436 TRACE1(
"shutdown cancelled");
450 shutdown_yes, shutdown_no, shutdown_flags);
459 static void shutdown_timer_fn(
void *arg)
466 shutdown_no = shutdown_expected;
467 check_shutdown_status();
473 static void remove_ci_from_shutdown(
struct cfg_info *ci)
481 if (ci == shutdown_con) {
486 if (!qb_list_empty(&ci->
list)) {
487 qb_list_del(&ci->
list);
488 qb_list_init(&ci->
list);
506 check_shutdown_status();
512 int cfg_lib_exit_fn (
void *conn)
517 remove_ci_from_shutdown(ci);
522 static int cfg_lib_init_fn (
void *conn)
527 qb_list_init(&ci->
list);
536 static void message_handler_req_exec_cfg_ringreenable (
545 static void exec_cfg_killnode_endian_convert (
void *msg)
548 (
struct req_exec_cfg_killnode *)msg;
551 swab_mar_name_t(&req_exec_cfg_killnode->reason);
556 static void message_handler_req_exec_cfg_killnode (
567 marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
569 nodeid, reason.
value);
578 static void message_handler_req_exec_cfg_shutdown (
592 static int nullcheck_strcmp(
const char* left,
const char *right)
602 return strcmp(left, right);
608 static void delete_and_notify_if_changed(
icmap_map_t temp_map,
const char *key_name)
623 static void remove_ro_entries(
icmap_map_t temp_map)
625 #ifndef HAVE_KNET_CRYPTO_RECONF
626 delete_and_notify_if_changed(temp_map,
"totem.secauth");
627 delete_and_notify_if_changed(temp_map,
"totem.crypto_hash");
628 delete_and_notify_if_changed(temp_map,
"totem.crypto_cipher");
629 delete_and_notify_if_changed(temp_map,
"totem.keyfile");
630 delete_and_notify_if_changed(temp_map,
"totem.key");
632 delete_and_notify_if_changed(temp_map,
"totem.version");
633 delete_and_notify_if_changed(temp_map,
"totem.threads");
634 delete_and_notify_if_changed(temp_map,
"totem.ip_version");
635 delete_and_notify_if_changed(temp_map,
"totem.ip_dscp");
636 delete_and_notify_if_changed(temp_map,
"totem.netmtu");
637 delete_and_notify_if_changed(temp_map,
"totem.interface.bindnetaddr");
638 delete_and_notify_if_changed(temp_map,
"totem.interface.mcastaddr");
639 delete_and_notify_if_changed(temp_map,
"totem.interface.broadcast");
640 delete_and_notify_if_changed(temp_map,
"totem.interface.mcastport");
641 delete_and_notify_if_changed(temp_map,
"totem.interface.ttl");
642 delete_and_notify_if_changed(temp_map,
"totem.transport");
643 delete_and_notify_if_changed(temp_map,
"totem.cluster_name");
644 delete_and_notify_if_changed(temp_map,
"quorum.provider");
645 delete_and_notify_if_changed(temp_map,
"system.move_to_root_cgroup");
646 delete_and_notify_if_changed(temp_map,
"system.allow_knet_handle_fallback");
647 delete_and_notify_if_changed(temp_map,
"system.sched_rr");
648 delete_and_notify_if_changed(temp_map,
"system.priority");
649 delete_and_notify_if_changed(temp_map,
"system.qb_ipc_type");
650 delete_and_notify_if_changed(temp_map,
"system.state_dir");
660 static void remove_deleted_entries(
icmap_map_t temp_map,
const char *prefix)
664 const char *old_key, *new_key;
673 while (old_key || new_key) {
674 ret = nullcheck_strcmp(old_key, new_key);
675 if ((ret < 0 && old_key) || !new_key) {
685 ret = nullcheck_strcmp(old_key, new_key);
686 }
while (ret < 0 && old_key);
688 else if ((ret > 0 && new_key) || !old_key) {
698 ret = nullcheck_strcmp(old_key, new_key);
699 }
while (ret > 0 && new_key);
713 static void message_handler_req_exec_cfg_reload_config (
721 const char *error_string;
734 memset(&new_config, 0,
sizeof(new_config));
740 goto reload_fini_nomap;
750 goto reload_fini_nofree;
757 remove_deleted_entries(temp_map,
"logging.");
758 remove_deleted_entries(temp_map,
"totem.");
759 remove_deleted_entries(temp_map,
"nodelist.");
760 remove_deleted_entries(temp_map,
"quorum.");
761 remove_deleted_entries(temp_map,
"uidgid.config.");
762 remove_deleted_entries(temp_map,
"nozzle.");
765 remove_ro_entries(temp_map);
768 memset(&new_config, 0,
sizeof(new_config));
770 assert(new_config.orig_interfaces != NULL);
773 new_config.crypto_changed = 0;
776 assert(new_config.interfaces != NULL);
783 memcpy(&new_config.interfaces[0], &new_config.orig_interfaces[0],
812 if (new_config.crypto_changed) {
813 #ifndef HAVE_KNET_CRYPTO_RECONF
814 new_config.crypto_changed = 0;
841 free(new_config.interfaces);
842 free(new_config.orig_interfaces);
853 if (new_config.crypto_changed) {
890 static void message_handler_req_exec_cfg_reconfig_crypto (
905 struct req_exec_cfg_crypto_reconfig req_exec_cfg_crypto_reconfig2;
908 req_exec_cfg_crypto_reconfig2.header.size =
909 sizeof (
struct req_exec_cfg_crypto_reconfig);
914 iovec.iov_base = (
char *)&req_exec_cfg_crypto_reconfig2;
915 iovec.iov_len =
sizeof (
struct req_exec_cfg_crypto_reconfig);
926 static void message_handler_req_lib_cfg_ringstatusget (
932 unsigned int iface_count;
934 const char *totem_ip_string;
957 for (i = 0; i < iface_count; i++) {
961 if (!totem_ip_string) {
971 snprintf(ifname,
sizeof(ifname),
"%d %s", iface_ids[i], totem_ip_string);
996 static void message_handler_req_lib_cfg_nodestatusget (
1002 void *res_lib_cfg_nodestatusget_ptr = NULL;
1003 size_t res_lib_cfg_nodestatusget_size;
1010 memset(&node_status, 0,
sizeof(node_status));
1019 goto ipc_response_send;
1023 switch (req_lib_cfg_nodestatusget->version) {
1041 for (i=0; i < KNET_MAX_LINK; i++) {
1068 res_lib_cfg_nodestatusget_ptr,
1069 res_lib_cfg_nodestatusget_size);
1074 static void message_handler_req_lib_cfg_trackstart (
1086 if (qb_list_empty(&ci->
list)) {
1087 qb_list_add(&ci->
list, &trackers_list);
1095 shutdown_expected++;
1096 send_test_shutdown(conn, NULL,
CS_OK);
1110 static void message_handler_req_lib_cfg_trackstop (
1118 remove_ci_from_shutdown(ci);
1129 static void message_handler_req_lib_cfg_ringreenable (
1146 static void message_handler_req_lib_cfg_killnode (
1152 struct req_exec_cfg_killnode req_exec_cfg_killnode;
1158 const char *iter_key;
1160 char *status_str = NULL;
1161 int match_nodeid_flag = 0;
1169 if (sscanf(iter_key,
"runtime.members.%u.%s", &nodeid, key_name) != 2) {
1172 if (strcmp(key_name,
"status") != 0) {
1175 if (nodeid != req_lib_cfg_killnode->nodeid) {
1178 match_nodeid_flag = 1;
1184 if (strcmp(status_str,
"joined") != 0) {
1191 if (!match_nodeid_flag) {
1196 req_exec_cfg_killnode.header.size =
1197 sizeof (
struct req_exec_cfg_killnode);
1200 req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
1201 marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
1203 iovec.iov_base = (
char *)&req_exec_cfg_killnode;
1204 iovec.iov_len =
sizeof (
struct req_exec_cfg_killnode);
1222 static void message_handler_req_lib_cfg_tryshutdown (
1228 struct qb_list_head *iter;
1271 shutdown_flags = req_lib_cfg_tryshutdown->
flags;
1278 shutdown_expected = 0;
1280 qb_list_for_each(iter, &trackers_list) {
1287 shutdown_expected++;
1294 if (shutdown_expected == 0) {
1323 api->
timer_add_duration((
unsigned long long)shutdown_timeout*QB_TIME_NS_IN_MSEC, NULL,
1324 shutdown_timer_fn, &shutdown_timer);
1329 send_test_shutdown(NULL, conn,
CS_OK);
1340 static void message_handler_req_lib_cfg_replytoshutdown (
1350 if (!shutdown_con) {
1355 if (req_lib_cfg_replytoshutdown->
response) {
1363 check_shutdown_status();
1376 static void message_handler_req_lib_cfg_get_node_addrs (
void *conn,
1382 unsigned int num_interfaces = 0;
1388 size_t res_lib_cfg_get_node_addrs_size;
1389 unsigned int nodeid = req_lib_cfg_get_node_addrs->
nodeid;
1395 if (api->
totem_ifaces_get(nodeid, iface_ids, node_ifs, INTERFACE_MAX, &status, &num_interfaces)) {
1400 res_lib_cfg_get_node_addrs_size =
sizeof(
struct res_lib_cfg_get_node_addrs) + (num_interfaces *
TOTEMIP_ADDRLEN);
1401 res_lib_cfg_get_node_addrs = alloca(res_lib_cfg_get_node_addrs_size);
1402 memset(res_lib_cfg_get_node_addrs, 0, res_lib_cfg_get_node_addrs_size);
1404 res_lib_cfg_get_node_addrs->header.size = res_lib_cfg_get_node_addrs_size;
1406 res_lib_cfg_get_node_addrs->header.error = ret;
1407 if (num_interfaces) {
1408 res_lib_cfg_get_node_addrs->
family = node_ifs[0].family;
1409 for (i = 0, addr_buf = (
char *)res_lib_cfg_get_node_addrs->
addrs;
1410 i < num_interfaces; i++) {
1411 if (node_ifs[i].
family) {
1417 res_lib_cfg_get_node_addrs->
num_addrs = live_addrs;
1421 api->
ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
1424 static void message_handler_req_lib_cfg_local_get (
void *conn,
const void *msg)
1437 static void message_handler_req_lib_cfg_reload_config (
void *conn,
const void *msg)
1439 struct req_exec_cfg_reload_config req_exec_cfg_reload_config;
1444 req_exec_cfg_reload_config.header.size =
1445 sizeof (
struct req_exec_cfg_reload_config);
1451 iovec.iov_base = (
char *)&req_exec_cfg_reload_config;
1452 iovec.iov_len =
sizeof (
struct req_exec_cfg_reload_config);
1459 static void message_handler_req_lib_cfg_reopen_log_files (
void *conn,
const void *msg)
struct qb_ipc_request_header header __attribute__((aligned(8)))
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 totempg_crypto_reconfigure_phase(cfg_message_crypto_reconfig_phase_t phase)
The res_lib_cfg_nodestatusget struct.
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.
void totempg_put_config(struct totem_config *config)
unsigned char addr[TOTEMIP_ADDRLEN]
The req_lib_cfg_get_node_addrs struct.
void totempg_get_config(struct totem_config *config)
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.
enum cfg_info::@8 shutdown_reply
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)
int totemconfig_commit_new_params(struct totem_config *totem_config, icmap_map_t map)
#define SERVICE_ID_MAKE(a, b)
#define ICMAP_KEYNAME_MAXLEN
Maximum length of key in icmap.
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)
struct qb_ipc_request_header header __attribute__((aligned(8)))
The res_lib_cfg_ringreenable struct.
cs_error_t icmap_get_string_r(const icmap_map_t map, const char *key_name, char **str)
int totem_volatile_config_validate(struct totem_config *totem_config, icmap_map_t temp_map, const char **error_string)
#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_set_int32(const char *key_name, int32_t value)
void totem_volatile_config_read(struct totem_config *totem_config, icmap_map_t temp_map, const char *deleted_key)
cs_error_t icmap_delete_r(const icmap_map_t map, const char *key_name)
icmap_delete_r
struct qb_ipc_response_header header
The res_lib_cfg_ringstatusget struct.
int totemconfig_configure_new_params(struct totem_config *totem_config, icmap_map_t map, const char **error_string)
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
int totem_reread_crypto_config(struct totem_config *totem_config, icmap_map_t map, const char **error_string)
struct corosync_service_engine cfg_service_engine
The req_lib_cfg_nodestatusget struct.
struct qb_ipc_request_header header __attribute__((aligned(8)))
struct qb_ipc_request_header header __attribute__((aligned(8)))
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)
int totempg_nodestatus_get(unsigned int nodeid, struct totem_node_status *node_status)
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)
struct qb_ipc_response_header header
The req_lib_cfg_killnode struct.
qb_map_iter_t * icmap_iter_t
Itterator type.
The mar_message_source_t struct.
void(* ipc_refcnt_inc)(void *conn)