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