corosync  3.1.0
exec/cfg.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005-2006 MontaVista Software, Inc.
3  * Copyright (c) 2006-2018 Red Hat, Inc.
4  *
5  * All rights reserved.
6  *
7  * Author: Steven Dake (sdake@redhat.com)
8  *
9  * This software licensed under BSD license, the text of which follows:
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are met:
13  *
14  * - Redistributions of source code must retain the above copyright notice,
15  * this list of conditions and the following disclaimer.
16  * - Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  * - Neither the name of the MontaVista Software, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived from this
21  * software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33  * THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #include <config.h>
37 
38 #include <sys/types.h>
39 #include <sys/uio.h>
40 #include <sys/socket.h>
41 #include <sys/un.h>
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
44 #include <unistd.h>
45 #include <fcntl.h>
46 #include <stdlib.h>
47 #include <stdio.h>
48 #include <stddef.h>
49 #include <limits.h>
50 #include <errno.h>
51 #include <string.h>
52 #include <assert.h>
53 
54 #include <corosync/corotypes.h>
55 #include <qb/qbipc_common.h>
56 #include <corosync/cfg.h>
57 #include <qb/qblist.h>
58 #include <corosync/mar_gen.h>
59 #include <corosync/totem/totemip.h>
60 #include <corosync/totem/totem.h>
61 #include <corosync/ipc_cfg.h>
62 #include <corosync/logsys.h>
63 #include <corosync/coroapi.h>
64 #include <corosync/icmap.h>
65 #include <corosync/corodefs.h>
66 
67 #include "totemconfig.h"
68 #include "totemknet.h"
69 #include "service.h"
70 #include "main.h"
71 
72 LOGSYS_DECLARE_SUBSYS ("CFG");
73 
80 };
81 
82 #define DEFAULT_SHUTDOWN_TIMEOUT 5
83 
84 static struct qb_list_head trackers_list;
85 
86 /*
87  * Variables controlling a requested shutdown
88  */
89 static corosync_timer_handle_t shutdown_timer;
90 static struct cfg_info *shutdown_con;
91 static uint32_t shutdown_flags;
92 static int shutdown_yes;
93 static int shutdown_no;
94 static int shutdown_expected;
95 
96 struct cfg_info
97 {
98  struct qb_list_head list;
99  void *conn;
102 };
103 
104 static void cfg_confchg_fn (
105  enum totem_configuration_type configuration_type,
106  const unsigned int *member_list, size_t member_list_entries,
107  const unsigned int *left_list, size_t left_list_entries,
108  const unsigned int *joined_list, size_t joined_list_entries,
109  const struct memb_ring_id *ring_id);
110 
111 static char *cfg_exec_init_fn (struct corosync_api_v1 *corosync_api_v1);
112 
113 static struct corosync_api_v1 *api;
114 
115 static int cfg_lib_init_fn (void *conn);
116 
117 static int cfg_lib_exit_fn (void *conn);
118 
119 static void message_handler_req_exec_cfg_ringreenable (
120  const void *message,
121  unsigned int nodeid);
122 
123 static void message_handler_req_exec_cfg_killnode (
124  const void *message,
125  unsigned int nodeid);
126 
127 static void message_handler_req_exec_cfg_shutdown (
128  const void *message,
129  unsigned int nodeid);
130 
131 static void message_handler_req_exec_cfg_reload_config (
132  const void *message,
133  unsigned int nodeid);
134 
135 static void message_handler_req_exec_cfg_reconfig_crypto (
136  const void *message,
137  unsigned int nodeid);
138 
139 static void exec_cfg_killnode_endian_convert (void *msg);
140 
141 static void message_handler_req_lib_cfg_ringstatusget (
142  void *conn,
143  const void *msg);
144 
145 static void message_handler_req_lib_cfg_nodestatusget (
146  void *conn,
147  const void *msg);
148 
149 static void message_handler_req_lib_cfg_ringreenable (
150  void *conn,
151  const void *msg);
152 
153 static void message_handler_req_lib_cfg_killnode (
154  void *conn,
155  const void *msg);
156 
157 static void message_handler_req_lib_cfg_tryshutdown (
158  void *conn,
159  const void *msg);
160 
161 static void message_handler_req_lib_cfg_replytoshutdown (
162  void *conn,
163  const void *msg);
164 
165 static void message_handler_req_lib_cfg_get_node_addrs (
166  void *conn,
167  const void *msg);
168 
169 static void message_handler_req_lib_cfg_local_get (
170  void *conn,
171  const void *msg);
172 
173 static void message_handler_req_lib_cfg_reload_config (
174  void *conn,
175  const void *msg);
176 
177 static void message_handler_req_lib_cfg_reopen_log_files (
178  void *conn,
179  const void *msg);
180 
181 /*
182  * Service Handler Definition
183  */
184 static struct corosync_lib_handler cfg_lib_engine[] =
185 {
186  { /* 0 */
187  .lib_handler_fn = message_handler_req_lib_cfg_ringstatusget,
188  .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
189  },
190  { /* 1 */
191  .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
192  .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
193  },
194  { /* 2 */
195  .lib_handler_fn = message_handler_req_lib_cfg_killnode,
196  .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
197  },
198  { /* 3 */
199  .lib_handler_fn = message_handler_req_lib_cfg_tryshutdown,
200  .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
201  },
202  { /* 4 */
203  .lib_handler_fn = message_handler_req_lib_cfg_replytoshutdown,
204  .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
205  },
206  { /* 5 */
207  .lib_handler_fn = message_handler_req_lib_cfg_get_node_addrs,
208  .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
209  },
210  { /* 6 */
211  .lib_handler_fn = message_handler_req_lib_cfg_local_get,
212  .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
213  },
214  { /* 7 */
215  .lib_handler_fn = message_handler_req_lib_cfg_reload_config,
216  .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
217  },
218  { /* 8 */
219  .lib_handler_fn = message_handler_req_lib_cfg_reopen_log_files,
220  .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
221  },
222  { /* 9 */
223  .lib_handler_fn = message_handler_req_lib_cfg_nodestatusget,
224  .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
225  }
226 };
227 
228 static struct corosync_exec_handler cfg_exec_engine[] =
229 {
230  { /* 0 */
231  .exec_handler_fn = message_handler_req_exec_cfg_ringreenable,
232  },
233  { /* 1 */
234  .exec_handler_fn = message_handler_req_exec_cfg_killnode,
235  .exec_endian_convert_fn = exec_cfg_killnode_endian_convert
236  },
237  { /* 2 */
238  .exec_handler_fn = message_handler_req_exec_cfg_shutdown,
239  },
240  { /* 3 */
241  .exec_handler_fn = message_handler_req_exec_cfg_reload_config,
242  },
243  { /* 4 */
244  .exec_handler_fn = message_handler_req_exec_cfg_reconfig_crypto,
245  }
246 };
247 
248 /*
249  * Exports the interface for the service
250  */
252  .name = "corosync configuration service",
253  .id = CFG_SERVICE,
254  .priority = 1,
255  .private_data_size = sizeof(struct cfg_info),
256  .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED,
257  .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
258  .lib_init_fn = cfg_lib_init_fn,
259  .lib_exit_fn = cfg_lib_exit_fn,
260  .lib_engine = cfg_lib_engine,
261  .lib_engine_count = sizeof (cfg_lib_engine) / sizeof (struct corosync_lib_handler),
262  .exec_init_fn = cfg_exec_init_fn,
263  .exec_engine = cfg_exec_engine,
264  .exec_engine_count = sizeof (cfg_exec_engine) / sizeof (struct corosync_exec_handler),
265  .confchg_fn = cfg_confchg_fn
266 };
267 
269 {
270  return (&cfg_service_engine);
271 }
272 
274  struct qb_ipc_request_header header __attribute__((aligned(8)));
275  mar_message_source_t source __attribute__((aligned(8)));
276 };
277 
279  struct qb_ipc_request_header header __attribute__((aligned(8)));
280  mar_message_source_t source __attribute__((aligned(8)));
281 };
282 
284  struct qb_ipc_request_header header __attribute__((aligned(8)));
285  mar_uint32_t phase __attribute__((aligned(8)));
286 };
287 
289  struct qb_ipc_request_header header __attribute__((aligned(8)));
290  mar_uint32_t nodeid __attribute__((aligned(8)));
291  mar_name_t reason __attribute__((aligned(8)));
292 };
293 
295  struct qb_ipc_request_header header __attribute__((aligned(8)));
296 };
297 
298 /* IMPL */
299 
300 static char *cfg_exec_init_fn (
301  struct corosync_api_v1 *corosync_api_v1)
302 {
303  api = corosync_api_v1;
304 
305  qb_list_init(&trackers_list);
306  return (NULL);
307 }
308 
309 static void cfg_confchg_fn (
310  enum totem_configuration_type configuration_type,
311  const unsigned int *member_list, size_t member_list_entries,
312  const unsigned int *left_list, size_t left_list_entries,
313  const unsigned int *joined_list, size_t joined_list_entries,
314  const struct memb_ring_id *ring_id)
315 {
316 }
317 
318 /*
319  * Tell other nodes we are shutting down
320  */
321 static int send_shutdown(void)
322 {
323  struct req_exec_cfg_shutdown req_exec_cfg_shutdown;
324  struct iovec iovec;
325 
326  ENTER();
327  req_exec_cfg_shutdown.header.size =
328  sizeof (struct req_exec_cfg_shutdown);
329  req_exec_cfg_shutdown.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
331 
332  iovec.iov_base = (char *)&req_exec_cfg_shutdown;
333  iovec.iov_len = sizeof (struct req_exec_cfg_shutdown);
334 
335  assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
336 
337  LEAVE();
338  return 0;
339 }
340 
341 static void send_test_shutdown(void *only_conn, void *exclude_conn, int status)
342 {
343  struct res_lib_cfg_testshutdown res_lib_cfg_testshutdown;
344  struct qb_list_head *iter;
345 
346  ENTER();
347  res_lib_cfg_testshutdown.header.size = sizeof(struct res_lib_cfg_testshutdown);
348  res_lib_cfg_testshutdown.header.id = MESSAGE_RES_CFG_TESTSHUTDOWN;
349  res_lib_cfg_testshutdown.header.error = status;
350  res_lib_cfg_testshutdown.flags = shutdown_flags;
351 
352  if (only_conn) {
353  TRACE1("sending testshutdown to only %p", only_conn);
354  api->ipc_dispatch_send(only_conn, &res_lib_cfg_testshutdown,
355  sizeof(res_lib_cfg_testshutdown));
356  } else {
357  qb_list_for_each(iter, &trackers_list) {
358  struct cfg_info *ci = qb_list_entry(iter, struct cfg_info, list);
359 
360  if (ci->conn != exclude_conn) {
361  TRACE1("sending testshutdown to %p", ci->tracker_conn);
362  api->ipc_dispatch_send(ci->tracker_conn, &res_lib_cfg_testshutdown,
363  sizeof(res_lib_cfg_testshutdown));
364  }
365  }
366  }
367  LEAVE();
368 }
369 
370 static void check_shutdown_status(void)
371 {
372  ENTER();
373 
374  /*
375  * Shutdown client might have gone away
376  */
377  if (!shutdown_con) {
378  LEAVE();
379  return;
380  }
381 
382  /*
383  * All replies safely gathered in ?
384  */
385  if (shutdown_yes + shutdown_no >= shutdown_expected) {
386  struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
387 
388  api->timer_delete(shutdown_timer);
389 
390  if (shutdown_yes >= shutdown_expected ||
391  shutdown_flags == CFG_SHUTDOWN_FLAG_REGARDLESS) {
392  TRACE1("shutdown confirmed");
393 
394  res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
395  res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
396  res_lib_cfg_tryshutdown.header.error = CS_OK;
397 
398  /*
399  * Tell originator that shutdown was confirmed
400  */
401  api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
402  sizeof(res_lib_cfg_tryshutdown));
403  shutdown_con = NULL;
404 
405  /*
406  * Tell other nodes we are going down
407  */
408  send_shutdown();
409 
410  }
411  else {
412 
413  TRACE1("shutdown cancelled");
414  res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
415  res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
416  res_lib_cfg_tryshutdown.header.error = CS_ERR_BUSY;
417 
418  /*
419  * Tell originator that shutdown was cancelled
420  */
421  api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
422  sizeof(res_lib_cfg_tryshutdown));
423  shutdown_con = NULL;
424  }
425 
426  log_printf(LOGSYS_LEVEL_DEBUG, "shutdown decision is: (yes count: %d, no count: %d) flags=%x",
427  shutdown_yes, shutdown_no, shutdown_flags);
428  }
429  LEAVE();
430 }
431 
432 
433 /*
434  * Not all nodes responded to the shutdown (in time)
435  */
436 static void shutdown_timer_fn(void *arg)
437 {
438  ENTER();
439 
440  /*
441  * Mark undecideds as "NO"
442  */
443  shutdown_no = shutdown_expected;
444  check_shutdown_status();
445 
446  send_test_shutdown(NULL, NULL, CS_ERR_TIMEOUT);
447  LEAVE();
448 }
449 
450 static void remove_ci_from_shutdown(struct cfg_info *ci)
451 {
452  ENTER();
453 
454  /*
455  * If the controlling shutdown process has quit, then cancel the
456  * shutdown session
457  */
458  if (ci == shutdown_con) {
459  shutdown_con = NULL;
460  api->timer_delete(shutdown_timer);
461  }
462 
463  if (!qb_list_empty(&ci->list)) {
464  qb_list_del(&ci->list);
465  qb_list_init(&ci->list);
466 
467  /*
468  * Remove our option
469  */
470  if (shutdown_con) {
472  shutdown_yes--;
474  shutdown_no--;
475  }
476 
477  /*
478  * If we are leaving, then that's an implicit YES to shutdown
479  */
481  shutdown_yes++;
482 
483  check_shutdown_status();
484  }
485  LEAVE();
486 }
487 
488 
489 int cfg_lib_exit_fn (void *conn)
490 {
491  struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
492 
493  ENTER();
494  remove_ci_from_shutdown(ci);
495  LEAVE();
496  return (0);
497 }
498 
499 static int cfg_lib_init_fn (void *conn)
500 {
501  struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
502 
503  ENTER();
504  qb_list_init(&ci->list);
505  LEAVE();
506 
507  return (0);
508 }
509 
510 /*
511  * Executive message handlers
512  */
513 static void message_handler_req_exec_cfg_ringreenable (
514  const void *message,
515  unsigned int nodeid)
516 {
517  ENTER();
518 
519  LEAVE();
520 }
521 
522 static void exec_cfg_killnode_endian_convert (void *msg)
523 {
525  (struct req_exec_cfg_killnode *)msg;
526  ENTER();
527 
528  swab_mar_name_t(&req_exec_cfg_killnode->reason);
529  LEAVE();
530 }
531 
532 
533 static void message_handler_req_exec_cfg_killnode (
534  const void *message,
535  unsigned int nodeid)
536 {
537  const struct req_exec_cfg_killnode *req_exec_cfg_killnode = message;
538  cs_name_t reason;
539 
540  ENTER();
541  log_printf(LOGSYS_LEVEL_DEBUG, "request to kill node " CS_PRI_NODE_ID " (us=" CS_PRI_NODE_ID ")",
542  req_exec_cfg_killnode->nodeid, api->totem_nodeid_get());
543  if (req_exec_cfg_killnode->nodeid == api->totem_nodeid_get()) {
544  marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
545  log_printf(LOGSYS_LEVEL_NOTICE, "Killed by node " CS_PRI_NODE_ID " : %s",
546  nodeid, reason.value);
548  }
549  LEAVE();
550 }
551 
552 /*
553  * Self shutdown
554  */
555 static void message_handler_req_exec_cfg_shutdown (
556  const void *message,
557  unsigned int nodeid)
558 {
559  ENTER();
560 
561  log_printf(LOGSYS_LEVEL_NOTICE, "Node " CS_PRI_NODE_ID " was shut down by sysadmin", nodeid);
562  if (nodeid == api->totem_nodeid_get()) {
563  api->shutdown_request();
564  }
565  LEAVE();
566 }
567 
568 /* strcmp replacement that can handle NULLs */
569 static int nullcheck_strcmp(const char* left, const char *right)
570 {
571  if (!left && right)
572  return -1;
573  if (left && !right)
574  return 1;
575 
576  if (!left && !right)
577  return 0;
578 
579  return strcmp(left, right);
580 }
581 
582 /*
583  * If a key has changed value in the new file, then warn the user and remove it from the temp_map
584  */
585 static void delete_and_notify_if_changed(icmap_map_t temp_map, const char *key_name)
586 {
587  if (!(icmap_key_value_eq(temp_map, key_name, icmap_get_global_map(), key_name))) {
588  if (icmap_delete_r(temp_map, key_name) == CS_OK) {
589  log_printf(LOGSYS_LEVEL_NOTICE, "Modified entry '%s' in corosync.conf cannot be changed at run-time", key_name);
590  }
591  }
592 }
593 /*
594  * Remove any keys from the new config file that in the new corosync.conf but that
595  * cannot be changed at run time. A log message will be issued for each
596  * entry that the user wants to change but they cannot.
597  *
598  * Add more here as needed.
599  */
600 static void remove_ro_entries(icmap_map_t temp_map)
601 {
602 #ifndef HAVE_KNET_CRYPTO_RECONF
603  delete_and_notify_if_changed(temp_map, "totem.secauth");
604  delete_and_notify_if_changed(temp_map, "totem.crypto_hash");
605  delete_and_notify_if_changed(temp_map, "totem.crypto_cipher");
606  delete_and_notify_if_changed(temp_map, "totem.keyfile");
607  delete_and_notify_if_changed(temp_map, "totem.key");
608 #endif
609  delete_and_notify_if_changed(temp_map, "totem.version");
610  delete_and_notify_if_changed(temp_map, "totem.threads");
611  delete_and_notify_if_changed(temp_map, "totem.ip_version");
612  delete_and_notify_if_changed(temp_map, "totem.rrp_mode");
613  delete_and_notify_if_changed(temp_map, "totem.netmtu");
614  delete_and_notify_if_changed(temp_map, "totem.interface.ringnumber");
615  delete_and_notify_if_changed(temp_map, "totem.interface.bindnetaddr");
616  delete_and_notify_if_changed(temp_map, "totem.interface.mcastaddr");
617  delete_and_notify_if_changed(temp_map, "totem.interface.broadcast");
618  delete_and_notify_if_changed(temp_map, "totem.interface.mcastport");
619  delete_and_notify_if_changed(temp_map, "totem.interface.ttl");
620  delete_and_notify_if_changed(temp_map, "totem.transport");
621  delete_and_notify_if_changed(temp_map, "totem.cluster_name");
622  delete_and_notify_if_changed(temp_map, "quorum.provider");
623  delete_and_notify_if_changed(temp_map, "system.move_to_root_cgroup");
624  delete_and_notify_if_changed(temp_map, "system.sched_rr");
625  delete_and_notify_if_changed(temp_map, "system.priority");
626  delete_and_notify_if_changed(temp_map, "system.qb_ipc_type");
627  delete_and_notify_if_changed(temp_map, "system.state_dir");
628 }
629 
630 /*
631  * Remove entries that exist in the global map, but not in the temp_map, this will
632  * cause delete notifications to be sent to any listeners.
633  *
634  * NOTE: This routine depends entirely on the keys returned by the iterators
635  * being in alpha-sorted order.
636  */
637 static void remove_deleted_entries(icmap_map_t temp_map, const char *prefix)
638 {
639  icmap_iter_t old_iter;
640  icmap_iter_t new_iter;
641  const char *old_key, *new_key;
642  int ret;
643 
644  old_iter = icmap_iter_init(prefix);
645  new_iter = icmap_iter_init_r(temp_map, prefix);
646 
647  old_key = icmap_iter_next(old_iter, NULL, NULL);
648  new_key = icmap_iter_next(new_iter, NULL, NULL);
649 
650  while (old_key || new_key) {
651  ret = nullcheck_strcmp(old_key, new_key);
652  if ((ret < 0 && old_key) || !new_key) {
653  /*
654  * new_key is greater, a line (or more) has been deleted
655  * Continue until old is >= new
656  */
657  do {
658  /* Remove it from icmap & send notifications */
659  icmap_delete(old_key);
660 
661  old_key = icmap_iter_next(old_iter, NULL, NULL);
662  ret = nullcheck_strcmp(old_key, new_key);
663  } while (ret < 0 && old_key);
664  }
665  else if ((ret > 0 && new_key) || !old_key) {
666  /*
667  * old_key is greater, a line (or more) has been added
668  * Continue until new is >= old
669  *
670  * we don't need to do anything special with this like tell
671  * icmap. That will happen when we copy the values over
672  */
673  do {
674  new_key = icmap_iter_next(new_iter, NULL, NULL);
675  ret = nullcheck_strcmp(old_key, new_key);
676  } while (ret > 0 && new_key);
677  }
678  if (ret == 0) {
679  new_key = icmap_iter_next(new_iter, NULL, NULL);
680  old_key = icmap_iter_next(old_iter, NULL, NULL);
681  }
682  }
683  icmap_iter_finalize(new_iter);
684  icmap_iter_finalize(old_iter);
685 }
686 
687 /*
688  * Reload configuration file
689  */
690 static void message_handler_req_exec_cfg_reload_config (
691  const void *message,
692  unsigned int nodeid)
693 {
695  struct res_lib_cfg_reload_config res_lib_cfg_reload_config;
696  struct totem_config new_config;
697  icmap_map_t temp_map;
698  const char *error_string;
699  int res = CS_OK;
700 
701  ENTER();
702 
703  log_printf(LOGSYS_LEVEL_NOTICE, "Config reload requested by node " CS_PRI_NODE_ID, nodeid);
704 
705  icmap_set_uint8("config.totemconfig_reload_in_progress", 1);
706 
707  /* Make sure there is no rubbish in this that might be checked, even on error */
708  memset(&new_config, 0, sizeof(new_config));
709  /*
710  * Set up a new hashtable as a staging area.
711  */
712  if ((res = icmap_init_r(&temp_map)) != CS_OK) {
713  log_printf(LOGSYS_LEVEL_ERROR, "Unable to create temporary icmap. config file reload cancelled\n");
714  goto reload_fini_nomap;
715  }
716 
717  /*
718  * Load new config into the temporary map
719  */
720  res = coroparse_configparse(temp_map, &error_string);
721  if (res == -1) {
722  log_printf (LOGSYS_LEVEL_ERROR, "Unable to reload config file: %s", error_string);
723  res = CS_ERR_INVALID_PARAM;
724  goto reload_fini_nofree;
725  }
726 
727  /* Signal start of the reload process */
728  icmap_set_uint8("config.reload_in_progress", 1);
729 
730  /* Detect deleted entries and remove them from the main icmap hashtable */
731  remove_deleted_entries(temp_map, "logging.");
732  remove_deleted_entries(temp_map, "totem.");
733  remove_deleted_entries(temp_map, "nodelist.");
734  remove_deleted_entries(temp_map, "quorum.");
735  remove_deleted_entries(temp_map, "uidgid.config.");
736  remove_deleted_entries(temp_map, "nozzle.");
737 
738  /* Remove entries that cannot be changed */
739  remove_ro_entries(temp_map);
740 
741  /* Take a copy of the current setup so we can check what has changed */
742  memset(&new_config, 0, sizeof(new_config));
743  new_config.orig_interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
744  assert(new_config.orig_interfaces != NULL);
745 
746  totempg_get_config(&new_config);
747  new_config.crypto_changed = 0;
748 
749  new_config.interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
750  assert(new_config.interfaces != NULL);
751  memset(new_config.interfaces, 0, sizeof (struct totem_interface) * INTERFACE_MAX);
752 
753  /* For UDP[U] the configuration on link0 is static (apart from the nodelist) and only read at
754  startup. So preserve it here */
755  if ( (new_config.transport_number == TOTEM_TRANSPORT_UDP) ||
756  (new_config.transport_number == TOTEM_TRANSPORT_UDPU)) {
757  memcpy(&new_config.interfaces[0], &new_config.orig_interfaces[0],
758  sizeof(struct totem_interface));
759  }
760 
761  /* Calculate new node and interface definitions */
762  if (totemconfig_configure_new_params(&new_config, temp_map, &error_string) == -1) {
763  log_printf (LOGSYS_LEVEL_ERROR, "Cannot configure new interface definitions: %s\n", error_string);
764  res = CS_ERR_INVALID_PARAM;
765  goto reload_fini;
766  }
767 
768  /* Read from temp_map into new_config */
769  totem_volatile_config_read(&new_config, temp_map, NULL);
770 
771  /* Get updated crypto parameters. Will set a flag in new_config if things have changed */
772  if (totem_reread_crypto_config(&new_config, temp_map, &error_string) == -1) {
773  log_printf (LOGSYS_LEVEL_ERROR, "Crypto configuration is not valid: %s\n", error_string);
774  res = CS_ERR_INVALID_PARAM;
775  goto reload_fini;
776  }
777 
778  /* Validate dynamic parameters */
779  if (totem_volatile_config_validate(&new_config, temp_map, &error_string) == -1) {
780  log_printf (LOGSYS_LEVEL_ERROR, "Configuration is not valid: %s\n", error_string);
781  res = CS_ERR_INVALID_PARAM;
782  goto reload_fini;
783  }
784 
785  /* Save this here so we can get at it for the later phases of crypto change */
786  if (new_config.crypto_changed) {
787 #ifndef HAVE_KNET_CRYPTO_RECONF
788  new_config.crypto_changed = 0;
789  log_printf (LOGSYS_LEVEL_ERROR, "Crypto reconfiguration is not supported by the linked version of knet\n");
790  res = CS_ERR_INVALID_PARAM;
791  goto reload_fini;
792 #endif
793  }
794 
795  /*
796  * Copy new keys into live config.
797  */
798  if ( (res = icmap_copy_map(icmap_get_global_map(), temp_map)) != CS_OK) {
799  log_printf (LOGSYS_LEVEL_ERROR, "Error making new config live. cmap database may be inconsistent\n");
800  /* Return res from icmap */
801  goto reload_fini;
802  }
803 
804  /* Copy into live system */
805  totempg_put_config(&new_config);
806  totemconfig_commit_new_params(&new_config, temp_map);
807  free(new_config.interfaces);
808 
809 reload_fini:
810  /* All done - let clients know */
811  icmap_set_int32("config.reload_status", res);
812  icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
813  icmap_set_uint8("config.reload_in_progress", 0);
814 
815  /* Finished with the temporary storage */
816  free(new_config.orig_interfaces);
817 
818 reload_fini_nofree:
819  icmap_fini_r(temp_map);
820 
821 reload_fini_nomap:
822 
823  /* If crypto was changed, now it's loaded on all nodes we can enable it.
824  * Each node sends its own PHASE message so we're not relying on the leader
825  * node to survive the transition
826  */
827  if (new_config.crypto_changed) {
828  struct req_exec_cfg_crypto_reconfig req_exec_cfg_crypto_reconfig;
829  struct iovec iovec;
830 
831  req_exec_cfg_crypto_reconfig.header.size =
832  sizeof (struct req_exec_cfg_crypto_reconfig);
833  req_exec_cfg_crypto_reconfig.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
835  req_exec_cfg_crypto_reconfig.phase = CRYPTO_RECONFIG_PHASE_ACTIVATE;
836 
837  iovec.iov_base = (char *)&req_exec_cfg_crypto_reconfig;
838  iovec.iov_len = sizeof (struct req_exec_cfg_crypto_reconfig);
839 
840  assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
841  }
842 
843  /* All done, return result to the caller if it was on this system */
844  if (nodeid == api->totem_nodeid_get()) {
845  res_lib_cfg_reload_config.header.size = sizeof(res_lib_cfg_reload_config);
846  res_lib_cfg_reload_config.header.id = MESSAGE_RES_CFG_RELOAD_CONFIG;
847  res_lib_cfg_reload_config.header.error = res;
848  api->ipc_response_send(req_exec_cfg_reload_config->source.conn,
849  &res_lib_cfg_reload_config,
850  sizeof(res_lib_cfg_reload_config));
851  api->ipc_refcnt_dec(req_exec_cfg_reload_config->source.conn);;
852  }
853 
854  LEAVE();
855 }
856 
857 /* Handle the phases of crypto reload
858  * The first time we are called is after the new crypto config has been loaded
859  * but not activated.
860  *
861  * 1 - activate the new crypto configuration
862  * 2 - clear out the old configuration
863  */
864 static void message_handler_req_exec_cfg_reconfig_crypto (
865  const void *message,
866  unsigned int nodeid)
867 {
869 
870  /* Got our own reconfig message */
871  if (nodeid == api->totem_nodeid_get()) {
872  log_printf (LOGSYS_LEVEL_DEBUG, "Crypto reconfiguration phase %d", req_exec_cfg_crypto_reconfig->phase);
873 
874  /* Do the deed */
875  totempg_crypto_reconfigure_phase(req_exec_cfg_crypto_reconfig->phase);
876 
877  /* Move to the next phase if not finished */
878  if (req_exec_cfg_crypto_reconfig->phase < CRYPTO_RECONFIG_PHASE_CLEANUP) {
879  struct req_exec_cfg_crypto_reconfig req_exec_cfg_crypto_reconfig2;
880  struct iovec iovec;
881 
882  req_exec_cfg_crypto_reconfig2.header.size =
883  sizeof (struct req_exec_cfg_crypto_reconfig);
884  req_exec_cfg_crypto_reconfig2.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
886  req_exec_cfg_crypto_reconfig2.phase = CRYPTO_RECONFIG_PHASE_CLEANUP;
887 
888  iovec.iov_base = (char *)&req_exec_cfg_crypto_reconfig2;
889  iovec.iov_len = sizeof (struct req_exec_cfg_crypto_reconfig);
890 
891  assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
892  }
893  }
894 }
895 
896 
897 /*
898  * Library Interface Implementation
899  */
900 static void message_handler_req_lib_cfg_ringstatusget (
901  void *conn,
902  const void *msg)
903 {
904  struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
905  struct totem_ip_address interfaces[INTERFACE_MAX];
906  unsigned int iface_count;
907  char **status;
908  const char *totem_ip_string;
909  char ifname[CFG_INTERFACE_NAME_MAX_LEN];
910  unsigned int iface_ids[INTERFACE_MAX];
911  unsigned int i;
912  cs_error_t res = CS_OK;
913 
914  ENTER();
915 
916  res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
917  res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
918 
919  api->totem_ifaces_get (
920  api->totem_nodeid_get(),
921  iface_ids,
922  interfaces,
924  &status,
925  &iface_count);
926 
927  assert(iface_count <= CFG_MAX_INTERFACES);
928 
929  res_lib_cfg_ringstatusget.interface_count = iface_count;
930 
931  for (i = 0; i < iface_count; i++) {
932  totem_ip_string
933  = (const char *)api->totem_ip_print (&interfaces[i]);
934 
935  if (!totem_ip_string) {
936  totem_ip_string="";
937  }
938 
939  /* Allow for i/f number at the start */
940  if (strlen(totem_ip_string) >= CFG_INTERFACE_NAME_MAX_LEN-3) {
941  log_printf(LOGSYS_LEVEL_ERROR, "String representation of interface %u is too long", i);
942  res = CS_ERR_NAME_TOO_LONG;
943  goto send_response;
944  }
945  snprintf(ifname, sizeof(ifname), "%d %s", iface_ids[i], totem_ip_string);
946 
947  if (strlen(status[i]) >= CFG_INTERFACE_STATUS_MAX_LEN) {
948  log_printf(LOGSYS_LEVEL_ERROR, "Status string for interface %u is too long", i);
949  res = CS_ERR_NAME_TOO_LONG;
950  goto send_response;
951  }
952 
953  strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
954  status[i]);
955  strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
956  ifname);
957  }
958 
959 send_response:
960  res_lib_cfg_ringstatusget.header.error = res;
961  api->ipc_response_send (
962  conn,
963  &res_lib_cfg_ringstatusget,
964  sizeof (struct res_lib_cfg_ringstatusget));
965 
966  LEAVE();
967 }
968 
969 
970 static void message_handler_req_lib_cfg_nodestatusget (
971  void *conn,
972  const void *msg)
973 {
974  struct res_lib_cfg_nodestatusget_version res_lib_cfg_nodestatusget_version;
975  struct res_lib_cfg_nodestatusget_v1 res_lib_cfg_nodestatusget_v1;
976  void *res_lib_cfg_nodestatusget_ptr = NULL;
977  size_t res_lib_cfg_nodestatusget_size;
978  struct req_lib_cfg_nodestatusget *req_lib_cfg_nodestatusget = (struct req_lib_cfg_nodestatusget *)msg;
979  struct totem_node_status node_status;
980  int i;
981 
982  ENTER();
983 
984  memset(&node_status, 0, sizeof(node_status));
985  if (totempg_nodestatus_get(req_lib_cfg_nodestatusget->nodeid, &node_status) != 0) {
986  res_lib_cfg_nodestatusget_ptr = &res_lib_cfg_nodestatusget_version;
987  res_lib_cfg_nodestatusget_size = sizeof(res_lib_cfg_nodestatusget_version);
988 
989  res_lib_cfg_nodestatusget_version.header.error = CS_ERR_FAILED_OPERATION;
990  res_lib_cfg_nodestatusget_version.header.id = MESSAGE_RES_CFG_NODESTATUSGET;
991  res_lib_cfg_nodestatusget_version.header.size = res_lib_cfg_nodestatusget_size;
992 
993  goto ipc_response_send;
994  }
995 
996  /* Currently only one structure version supported */
997  switch (req_lib_cfg_nodestatusget->version) {
998  case CFG_NODE_STATUS_V1:
999  res_lib_cfg_nodestatusget_ptr = &res_lib_cfg_nodestatusget_v1;
1000  res_lib_cfg_nodestatusget_size = sizeof(res_lib_cfg_nodestatusget_v1);
1001 
1002  res_lib_cfg_nodestatusget_v1.header.error = CS_OK;
1003  res_lib_cfg_nodestatusget_v1.header.id = MESSAGE_RES_CFG_NODESTATUSGET;
1004  res_lib_cfg_nodestatusget_v1.header.size = res_lib_cfg_nodestatusget_size;
1005 
1006  res_lib_cfg_nodestatusget_v1.node_status.version = CFG_NODE_STATUS_V1;
1007  res_lib_cfg_nodestatusget_v1.node_status.nodeid = req_lib_cfg_nodestatusget->nodeid;
1008  res_lib_cfg_nodestatusget_v1.node_status.reachable = node_status.reachable;
1009  res_lib_cfg_nodestatusget_v1.node_status.remote = node_status.remote;
1010  res_lib_cfg_nodestatusget_v1.node_status.external = node_status.external;
1011  res_lib_cfg_nodestatusget_v1.node_status.onwire_min = node_status.onwire_min;
1012  res_lib_cfg_nodestatusget_v1.node_status.onwire_max = node_status.onwire_max;
1013  res_lib_cfg_nodestatusget_v1.node_status.onwire_ver = node_status.onwire_ver;
1014 
1015  for (i=0; i < KNET_MAX_LINK; i++) {
1016  res_lib_cfg_nodestatusget_v1.node_status.link_status[i].enabled = node_status.link_status[i].enabled;
1017  res_lib_cfg_nodestatusget_v1.node_status.link_status[i].connected = node_status.link_status[i].connected;
1018  res_lib_cfg_nodestatusget_v1.node_status.link_status[i].dynconnected = node_status.link_status[i].dynconnected;
1019  res_lib_cfg_nodestatusget_v1.node_status.link_status[i].mtu = node_status.link_status[i].mtu;
1020  memcpy(res_lib_cfg_nodestatusget_v1.node_status.link_status[i].src_ipaddr,
1021  node_status.link_status[i].src_ipaddr, CFG_MAX_HOST_LEN);
1022  memcpy(res_lib_cfg_nodestatusget_v1.node_status.link_status[i].dst_ipaddr,
1023  node_status.link_status[i].dst_ipaddr, CFG_MAX_HOST_LEN);
1024  }
1025  break;
1026  default:
1027  /*
1028  * Unsupported version requested
1029  */
1030  res_lib_cfg_nodestatusget_ptr = &res_lib_cfg_nodestatusget_version;
1031  res_lib_cfg_nodestatusget_size = sizeof(res_lib_cfg_nodestatusget_version);
1032 
1033  res_lib_cfg_nodestatusget_version.header.error = CS_ERR_NOT_SUPPORTED;
1034  res_lib_cfg_nodestatusget_version.header.id = MESSAGE_RES_CFG_NODESTATUSGET;
1035  res_lib_cfg_nodestatusget_version.header.size = res_lib_cfg_nodestatusget_size;
1036  break;
1037  }
1038 
1039 ipc_response_send:
1040  api->ipc_response_send (
1041  conn,
1042  res_lib_cfg_nodestatusget_ptr,
1043  res_lib_cfg_nodestatusget_size);
1044 
1045  LEAVE();
1046 }
1047 
1048 
1049 static void message_handler_req_lib_cfg_ringreenable (
1050  void *conn,
1051  const void *msg)
1052 {
1053  struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
1054  ENTER();
1055 
1056  res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
1057  res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
1058  res_lib_cfg_ringreenable.header.error = CS_ERR_NOT_SUPPORTED;
1059  api->ipc_response_send (
1060  conn, &res_lib_cfg_ringreenable,
1061  sizeof (struct res_lib_cfg_ringreenable));
1062 
1063  LEAVE();
1064 }
1065 
1066 static void message_handler_req_lib_cfg_killnode (
1067  void *conn,
1068  const void *msg)
1069 {
1070  const struct req_lib_cfg_killnode *req_lib_cfg_killnode = msg;
1071  struct res_lib_cfg_killnode res_lib_cfg_killnode;
1072  struct req_exec_cfg_killnode req_exec_cfg_killnode;
1073  struct iovec iovec;
1074  char key_name[ICMAP_KEYNAME_MAXLEN];
1075  char tmp_key[ICMAP_KEYNAME_MAXLEN + 1];
1076  icmap_map_t map;
1077  icmap_iter_t iter;
1078  const char *iter_key;
1079  uint32_t nodeid;
1080  char *status_str = NULL;
1081  int match_nodeid_flag = 0;
1082  cs_error_t error = CS_OK;
1083 
1084  ENTER();
1085 
1086  map = icmap_get_global_map();
1087  iter = icmap_iter_init_r(map, "runtime.members.");
1088  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
1089  if (sscanf(iter_key, "runtime.members.%u.%s", &nodeid, key_name) != 2) {
1090  continue;
1091  }
1092  if (strcmp(key_name, "status") != 0) {
1093  continue;
1094  }
1095  if (nodeid != req_lib_cfg_killnode->nodeid) {
1096  continue;
1097  }
1098  match_nodeid_flag = 1;
1099  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "runtime.members.%u.status", nodeid);
1100  if (icmap_get_string_r(map, tmp_key, &status_str) != CS_OK) {
1101  error = CS_ERR_LIBRARY;
1102  goto send_response;
1103  }
1104  if (strcmp(status_str, "joined") != 0) {
1105  error = CS_ERR_NOT_EXIST;
1106  goto send_response;
1107  }
1108  break;
1109  }
1110 
1111  if (!match_nodeid_flag) {
1112  error = CS_ERR_NOT_EXIST;
1113  goto send_response;
1114  }
1115 
1116  req_exec_cfg_killnode.header.size =
1117  sizeof (struct req_exec_cfg_killnode);
1118  req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
1120  req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
1121  marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
1122 
1123  iovec.iov_base = (char *)&req_exec_cfg_killnode;
1124  iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
1125 
1126  (void)api->totem_mcast (&iovec, 1, TOTEM_SAFE);
1127 
1128 send_response:
1129  res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
1130  res_lib_cfg_killnode.header.id = MESSAGE_RES_CFG_KILLNODE;
1131  res_lib_cfg_killnode.header.error = error;
1132 
1133  api->ipc_response_send(conn, &res_lib_cfg_killnode,
1134  sizeof(res_lib_cfg_killnode));
1135 
1136  free(status_str);
1137  icmap_iter_finalize(iter);
1138  LEAVE();
1139 }
1140 
1141 
1142 static void message_handler_req_lib_cfg_tryshutdown (
1143  void *conn,
1144  const void *msg)
1145 {
1146  struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
1148  struct qb_list_head *iter;
1149 
1150  ENTER();
1151 
1152  if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
1153  struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
1154 
1155  /*
1156  * Tell other nodes
1157  */
1158  send_shutdown();
1159 
1160  res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
1161  res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
1162  res_lib_cfg_tryshutdown.header.error = CS_OK;
1163  api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
1164  sizeof(res_lib_cfg_tryshutdown));
1165 
1166  LEAVE();
1167  return;
1168  }
1169 
1170  /*
1171  * Shutdown in progress, return an error
1172  */
1173  if (shutdown_con) {
1174  struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
1175 
1176  res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
1177  res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
1178  res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
1179 
1180  api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
1181  sizeof(res_lib_cfg_tryshutdown));
1182 
1183 
1184  LEAVE();
1185 
1186  return;
1187  }
1188 
1189  ci->conn = conn;
1190  shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
1191  shutdown_flags = req_lib_cfg_tryshutdown->flags;
1192  shutdown_yes = 0;
1193  shutdown_no = 0;
1194 
1195  /*
1196  * Count the number of listeners
1197  */
1198  shutdown_expected = 0;
1199 
1200  qb_list_for_each(iter, &trackers_list) {
1201  struct cfg_info *testci = qb_list_entry(iter, struct cfg_info, list);
1202  /*
1203  * It is assumed that we will allow shutdown
1204  */
1205  if (testci != ci) {
1207  shutdown_expected++;
1208  }
1209  }
1210 
1211  /*
1212  * If no-one is listening for events then we can just go down now
1213  */
1214  if (shutdown_expected == 0) {
1215  struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
1216 
1217  res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
1218  res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
1219  res_lib_cfg_tryshutdown.header.error = CS_OK;
1220 
1221  /*
1222  * Tell originator that shutdown was confirmed
1223  */
1224  api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
1225  sizeof(res_lib_cfg_tryshutdown));
1226 
1227  send_shutdown();
1228  LEAVE();
1229  return;
1230  }
1231  else {
1232  unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
1233 
1234  /*
1235  * Look for a shutdown timeout in configuration map
1236  */
1237  icmap_get_uint32("cfg.shutdown_timeout", &shutdown_timeout);
1238 
1239  /*
1240  * Start the timer. If we don't get a full set of replies before this goes
1241  * off we'll cancel the shutdown
1242  */
1243  api->timer_add_duration((unsigned long long)shutdown_timeout*1000000000, NULL,
1244  shutdown_timer_fn, &shutdown_timer);
1245 
1246  /*
1247  * Tell the users we would like to shut down
1248  */
1249  send_test_shutdown(NULL, conn, CS_OK);
1250  }
1251 
1252  /*
1253  * We don't sent a reply to the caller here.
1254  * We send it when we know if we can shut down or not
1255  */
1256 
1257  LEAVE();
1258 }
1259 
1260 static void message_handler_req_lib_cfg_replytoshutdown (
1261  void *conn,
1262  const void *msg)
1263 {
1264  struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
1266  struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
1267  int status = CS_OK;
1268 
1269  ENTER();
1270  if (!shutdown_con) {
1271  status = CS_ERR_ACCESS;
1272  goto exit_fn;
1273  }
1274 
1275  if (req_lib_cfg_replytoshutdown->response) {
1276  shutdown_yes++;
1278  }
1279  else {
1280  shutdown_no++;
1282  }
1283  check_shutdown_status();
1284 
1285 exit_fn:
1286  res_lib_cfg_replytoshutdown.header.error = status;
1287  res_lib_cfg_replytoshutdown.header.id = MESSAGE_RES_CFG_REPLYTOSHUTDOWN;
1288  res_lib_cfg_replytoshutdown.header.size = sizeof(res_lib_cfg_replytoshutdown);
1289 
1290  api->ipc_response_send(conn, &res_lib_cfg_replytoshutdown,
1291  sizeof(res_lib_cfg_replytoshutdown));
1292 
1293  LEAVE();
1294 }
1295 
1296 static void message_handler_req_lib_cfg_get_node_addrs (void *conn,
1297  const void *msg)
1298 {
1299  struct totem_ip_address node_ifs[INTERFACE_MAX];
1300  unsigned int iface_ids[INTERFACE_MAX];
1301  char buf[PIPE_BUF];
1302  char **status;
1303  unsigned int num_interfaces = 0;
1304  struct sockaddr_storage *ss;
1305  int ret = CS_OK;
1306  int i;
1307  int live_addrs = 0;
1309  struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)buf;
1310  unsigned int nodeid = req_lib_cfg_get_node_addrs->nodeid;
1311  char *addr_buf;
1312 
1313  if (nodeid == 0)
1314  nodeid = api->totem_nodeid_get();
1315 
1316  if (api->totem_ifaces_get(nodeid, iface_ids, node_ifs, INTERFACE_MAX, &status, &num_interfaces)) {
1317  ret = CS_ERR_EXIST;
1318  num_interfaces = 0;
1319  }
1320 
1321  res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
1322  res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
1323  res_lib_cfg_get_node_addrs->header.error = ret;
1324  if (num_interfaces) {
1325  res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
1326  for (i = 0, addr_buf = (char *)res_lib_cfg_get_node_addrs->addrs;
1327  i < num_interfaces; i++) {
1328  ss = (struct sockaddr_storage *)&node_ifs[i].addr;
1329  if (ss->ss_family) {
1330  memcpy(addr_buf, node_ifs[i].addr, TOTEMIP_ADDRLEN);
1331  live_addrs++;
1332  addr_buf += TOTEMIP_ADDRLEN;
1333  }
1334  }
1335  res_lib_cfg_get_node_addrs->num_addrs = live_addrs;
1336  } else {
1337  res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
1338  }
1339  api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
1340 }
1341 
1342 static void message_handler_req_lib_cfg_local_get (void *conn, const void *msg)
1343 {
1344  struct res_lib_cfg_local_get res_lib_cfg_local_get;
1345 
1346  res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
1347  res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
1348  res_lib_cfg_local_get.header.error = CS_OK;
1349  res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
1350 
1351  api->ipc_response_send(conn, &res_lib_cfg_local_get,
1352  sizeof(res_lib_cfg_local_get));
1353 }
1354 
1355 static void message_handler_req_lib_cfg_reload_config (void *conn, const void *msg)
1356 {
1357  struct req_exec_cfg_reload_config req_exec_cfg_reload_config;
1358  struct iovec iovec;
1359 
1360  ENTER();
1361 
1362  req_exec_cfg_reload_config.header.size =
1363  sizeof (struct req_exec_cfg_reload_config);
1364  req_exec_cfg_reload_config.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
1366  api->ipc_source_set (&req_exec_cfg_reload_config.source, conn);
1367  api->ipc_refcnt_inc(conn);
1368 
1369  iovec.iov_base = (char *)&req_exec_cfg_reload_config;
1370  iovec.iov_len = sizeof (struct req_exec_cfg_reload_config);
1371 
1372  assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
1373 
1374  LEAVE();
1375 }
1376 
1377 static void message_handler_req_lib_cfg_reopen_log_files (void *conn, const void *msg)
1378 {
1379  struct res_lib_cfg_reopen_log_files res_lib_cfg_reopen_log_files;
1380  cs_error_t res;
1381 
1382  ENTER();
1383 
1384  log_printf(LOGSYS_LEVEL_DEBUG, "Reopening logging files\n");
1385 
1386  res = logsys_reopen_log_files();
1387 
1388  res_lib_cfg_reopen_log_files.header.size = sizeof(res_lib_cfg_reopen_log_files);
1389  res_lib_cfg_reopen_log_files.header.id = MESSAGE_RES_CFG_REOPEN_LOG_FILES;
1390  res_lib_cfg_reopen_log_files.header.error = res;
1391  api->ipc_response_send(conn,
1392  &res_lib_cfg_reopen_log_files,
1393  sizeof(res_lib_cfg_reopen_log_files));
1394 
1395  LEAVE();
1396 }
void *(* ipc_private_data_get)(void *conn)
Definition: coroapi.h:256
const char * name
Definition: coroapi.h:491
unsigned short family
Definition: coroapi.h:113
The res_lib_cfg_reopen_log_files struct.
Definition: ipc_cfg.h:254
struct knet_link_status link_status[KNET_MAX_LINK]
Definition: totem.h:271
void(* timer_delete)(corosync_timer_handle_t timer_handle)
Definition: coroapi.h:241
int crypto_changed
Definition: totem.h:231
int(* timer_add_duration)(unsigned long long nanoseconds_in_future, void *data, void(*timer_nf)(void *data), corosync_timer_handle_t *handle)
Definition: coroapi.h:229
const char * icmap_iter_next(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
Return next item in iterator iter.
Definition: icmap.c:1095
#define CFG_INTERFACE_STATUS_MAX_LEN
Definition: ipc_cfg.h:43
struct totem_interface * interfaces
Definition: totem.h:165
struct qb_list_head list
Definition: exec/cfg.c:98
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.
Definition: icmap.c:1298
The res_lib_cfg_replytoshutdown struct.
Definition: ipc_cfg.h:184
The res_lib_cfg_testshutdown struct.
Definition: ipc_cfg.h:191
The totem_ip_address struct.
Definition: coroapi.h:111
The corosync_service_engine struct.
Definition: coroapi.h:490
void icmap_iter_finalize(icmap_iter_t iter)
Finalize iterator.
Definition: icmap.c:1116
totem_transport_t transport_number
Definition: totem.h:239
void(* shutdown_request)(void)
Definition: coroapi.h:429
cs_error_t logsys_reopen_log_files(void)
Definition: logsys.c:890
uint8_t value[CS_MAX_NAME_LENGTH]
Definition: corotypes.h:67
int coroparse_configparse(icmap_map_t config_map, const char **error_string)
Definition: coroparse.c:258
#define corosync_fatal_error(err)
Definition: coroapi.h:424
int(* ipc_response_send)(void *conn, const void *msg, size_t mlen)
Definition: coroapi.h:258
void totemconfig_commit_new_params(struct totem_config *totem_config, icmap_map_t map)
Definition: totemconfig.c:2364
LOGSYS_DECLARE_SUBSYS("CFG")
#define CS_PRI_NODE_ID
Definition: corotypes.h:59
int totempg_crypto_reconfigure_phase(cfg_message_crypto_reconfig_phase_t phase)
Definition: totempg.c:1571
The res_lib_cfg_nodestatusget struct.
Definition: ipc_cfg.h:123
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.
Definition: icmap.c:385
totem_configuration_type
The totem_configuration_type enum.
Definition: coroapi.h:132
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)
Definition: coroapi.h:282
The res_lib_cfg_get_node_addrs struct.
Definition: ipc_cfg.h:207
The corosync_lib_handler struct.
Definition: coroapi.h:467
void totempg_put_config(struct totem_config *config)
Definition: totempg.c:1612
unsigned char addr[TOTEMIP_ADDRLEN]
Definition: coroapi.h:77
mar_name_t struct
Definition: mar_gen.h:166
The req_lib_cfg_get_node_addrs struct.
Definition: ipc_cfg.h:199
void totempg_get_config(struct totem_config *config)
Definition: totempg.c:1602
The corosync_exec_handler struct.
Definition: coroapi.h:475
void icmap_fini_r(const icmap_map_t map)
Finalize local, reentrant icmap.
Definition: icmap.c:238
icmap_map_t icmap_get_global_map(void)
Return global icmap.
Definition: icmap.c:264
enum cfg_info::@8 shutdown_reply
int(* totem_mcast)(const struct iovec *iovec, unsigned int iov_len, unsigned int guarantee)
Definition: coroapi.h:279
#define log_printf(level, format, args...)
Definition: logsys.h:323
void(* exec_handler_fn)(const void *msg, unsigned int nodeid)
Definition: coroapi.h:476
uint8_t reachable
Definition: totem.h:265
void * tracker_conn
Definition: exec/cfg.c:100
#define SERVICE_ID_MAKE(a, b)
Definition: coroapi.h:458
#define INTERFACE_MAX
Definition: coroapi.h:88
#define ICMAP_KEYNAME_MAXLEN
Maximum length of key in icmap.
Definition: icmap.h:48
uint8_t onwire_ver
Definition: totem.h:270
The res_lib_cfg_local_get struct.
Definition: ipc_cfg.h:225
The res_lib_cfg_killnode struct.
Definition: ipc_cfg.h:154
#define TOTEM_SAFE
Definition: coroapi.h:103
unsigned int num_addrs
Definition: ipc_cfg.h:210
unsigned int flags
Definition: ipc_cfg.h:193
The req_lib_cfg_tryshutdown struct.
Definition: ipc_cfg.h:161
unsigned int(* totem_nodeid_get)(void)
Definition: coroapi.h:275
void(* ipc_refcnt_dec)(void *conn)
Definition: coroapi.h:270
The res_lib_cfg_ringreenable struct.
Definition: ipc_cfg.h:138
cs_error_t icmap_get_string_r(const icmap_map_t map, const char *key_name, char **str)
Definition: icmap.c:735
int totem_volatile_config_validate(struct totem_config *totem_config, icmap_map_t temp_map, const char **error_string)
Definition: totemconfig.c:368
#define LOGSYS_LEVEL_ERROR
Definition: logsys.h:72
#define TRACE1(format, args...)
Definition: logsys.h:326
#define CFG_INTERFACE_NAME_MAX_LEN
Definition: ipc_cfg.h:42
cs_error_t icmap_delete(const char *key_name)
Delete key from map.
Definition: icmap.c:653
uint8_t onwire_min
Definition: totem.h:268
#define CFG_MAX_HOST_LEN
Definition: cfg.h:169
cs_error_t
The cs_error_t enum.
Definition: corotypes.h:97
#define LOGSYS_LEVEL_DEBUG
Definition: logsys.h:76
The corosync_api_v1 struct.
Definition: coroapi.h:225
The req_lib_cfg_replytoshutdown struct.
Definition: ipc_cfg.h:176
The res_lib_cfg_tryshutdown struct.
Definition: ipc_cfg.h:169
cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
Definition: icmap.c:892
#define DEFAULT_SHUTDOWN_TIMEOUT
Definition: exec/cfg.c:82
#define TOTEMIP_ADDRLEN
Definition: coroapi.h:86
#define CFG_MAX_INTERFACES
Definition: ipc_cfg.h:48
const char *(* totem_ip_print)(const struct totem_ip_address *addr)
Definition: coroapi.h:292
#define ENTER
Definition: logsys.h:324
cs_error_t icmap_set_int32(const char *key_name, int32_t value)
Definition: icmap.c:591
uint32_t mar_uint32_t
Definition: mar_gen.h:53
void totem_volatile_config_read(struct totem_config *totem_config, icmap_map_t temp_map, const char *deleted_key)
Definition: totemconfig.c:303
cfg_message_req_types
Definition: exec/cfg.c:74
uint8_t external
Definition: totem.h:267
The memb_ring_id struct.
Definition: coroapi.h:122
unsigned int flags
Definition: ipc_cfg.h:163
cs_error_t icmap_delete_r(const icmap_map_t map, const char *key_name)
icmap_delete_r
Definition: icmap.c:633
The res_lib_cfg_ringstatusget struct.
Definition: ipc_cfg.h:99
int totemconfig_configure_new_params(struct totem_config *totem_config, icmap_map_t map, const char **error_string)
Definition: totemconfig.c:2341
cs_error_t icmap_init_r(icmap_map_t *result)
Initialize additional (local, reentrant) icmap_map.
Definition: icmap.c:188
uint8_t onwire_max
Definition: totem.h:269
qb_loop_timer_handle corosync_timer_handle_t
corosync_timer_handle_t
Definition: coroapi.h:74
int totem_reread_crypto_config(struct totem_config *totem_config, icmap_map_t map, const char **error_string)
Definition: totemconfig.c:2236
struct totem_interface * orig_interfaces
Definition: totem.h:166
void * conn
Definition: exec/cfg.c:99
struct corosync_service_engine cfg_service_engine
Definition: exec/cfg.c:251
The req_lib_cfg_nodestatusget struct.
Definition: ipc_cfg.h:109
The res_lib_cfg_reload_config struct.
Definition: ipc_cfg.h:240
typedef __attribute__
#define LOGSYS_LEVEL_NOTICE
Definition: logsys.h:74
cs_error_t icmap_set_uint8(const char *key_name, uint8_t value)
Definition: icmap.c:573
uint8_t remote
Definition: totem.h:266
void(* lib_handler_fn)(void *conn, const void *msg)
Definition: coroapi.h:468
struct corosync_service_engine * cfg_get_service_engine_ver0(void)
Definition: exec/cfg.c:268
int(* ipc_dispatch_send)(void *conn, const void *msg, size_t mlen)
Definition: coroapi.h:263
int totempg_nodestatus_get(unsigned int nodeid, struct totem_node_status *node_status)
Definition: totempg.c:1450
unsigned int nodeid
Definition: coroapi.h:75
icmap_iter_t icmap_iter_init_r(const icmap_map_t map, const char *prefix)
icmap_iter_init_r
Definition: icmap.c:1084
icmap_iter_t icmap_iter_init(const char *prefix)
Initialize iterator with given prefix.
Definition: icmap.c:1089
struct memb_ring_id ring_id
Definition: totemsrp.c:264
void(* ipc_source_set)(mar_message_source_t *source, void *conn)
Definition: coroapi.h:252
The req_lib_cfg_killnode struct.
Definition: ipc_cfg.h:145
#define LEAVE
Definition: logsys.h:325
qb_map_iter_t * icmap_iter_t
Itterator type.
Definition: icmap.h:123
The cs_name_t struct.
Definition: corotypes.h:65
The mar_message_source_t struct.
Definition: coroapi.h:50
void(* ipc_refcnt_inc)(void *conn)
Definition: coroapi.h:268