corosync  3.1.9
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 
73 LOGSYS_DECLARE_SUBSYS ("CFG");
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)));
309  mar_uint32_t nodeid __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  // Clear this out in case it all goes well
726  icmap_delete("config.reload_error_message");
727 
728  icmap_set_uint8("config.totemconfig_reload_in_progress", 1);
729 
730  /* Make sure there is no rubbish in this that might be checked, even on error */
731  memset(&new_config, 0, sizeof(new_config));
732  /*
733  * Set up a new hashtable as a staging area.
734  */
735  if ((res = icmap_init_r(&temp_map)) != CS_OK) {
736  log_printf(LOGSYS_LEVEL_ERROR, "Unable to create temporary icmap. config file reload cancelled\n");
737  goto reload_fini_nomap;
738  }
739 
740  /*
741  * Load new config into the temporary map
742  */
743  res = coroparse_configparse(temp_map, &error_string);
744  if (res == -1) {
745  log_printf (LOGSYS_LEVEL_ERROR, "Unable to reload config file: %s", error_string);
746  res = CS_ERR_INVALID_PARAM;
747  goto reload_fini_nofree;
748  }
749 
750  /* Signal start of the reload process */
751  icmap_set_uint8("config.reload_in_progress", 1);
752 
753  /* Detect deleted entries and remove them from the main icmap hashtable */
754  remove_deleted_entries(temp_map, "logging.");
755  remove_deleted_entries(temp_map, "totem.");
756  remove_deleted_entries(temp_map, "nodelist.");
757  remove_deleted_entries(temp_map, "quorum.");
758  remove_deleted_entries(temp_map, "uidgid.config.");
759  remove_deleted_entries(temp_map, "nozzle.");
760 
761  /* Remove entries that cannot be changed */
762  remove_ro_entries(temp_map);
763 
764  /* Take a copy of the current setup so we can check what has changed */
765  memset(&new_config, 0, sizeof(new_config));
766  new_config.orig_interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
767  assert(new_config.orig_interfaces != NULL);
768 
769  totempg_get_config(&new_config);
770  new_config.crypto_changed = 0;
771 
772  new_config.interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
773  assert(new_config.interfaces != NULL);
774  memset(new_config.interfaces, 0, sizeof (struct totem_interface) * INTERFACE_MAX);
775 
776  /* For UDP[U] the configuration on link0 is static (apart from the nodelist) and only read at
777  startup. So preserve it here */
778  if ( (new_config.transport_number == TOTEM_TRANSPORT_UDP) ||
779  (new_config.transport_number == TOTEM_TRANSPORT_UDPU)) {
780  memcpy(&new_config.interfaces[0], &new_config.orig_interfaces[0],
781  sizeof(struct totem_interface));
782  }
783 
784  /* Calculate new node and interface definitions */
785  if (totemconfig_configure_new_params(&new_config, temp_map, &error_string) == -1) {
786  log_printf (LOGSYS_LEVEL_ERROR, "Cannot configure new interface definitions: %s\n", error_string);
787  res = CS_ERR_INVALID_PARAM;
788  goto reload_fini;
789  }
790 
791  /* Read from temp_map into new_config */
792  totem_volatile_config_read(&new_config, temp_map, NULL);
793 
794  /* Get updated crypto parameters. Will set a flag in new_config if things have changed */
795  if (totem_reread_crypto_config(&new_config, temp_map, &error_string) == -1) {
796  log_printf (LOGSYS_LEVEL_ERROR, "Crypto configuration is not valid: %s\n", error_string);
797  res = CS_ERR_INVALID_PARAM;
798  goto reload_fini;
799  }
800 
801  /* Validate dynamic parameters */
802  if (totem_volatile_config_validate(&new_config, temp_map, &error_string) == -1) {
803  log_printf (LOGSYS_LEVEL_ERROR, "Configuration is not valid: %s\n", error_string);
804  res = CS_ERR_INVALID_PARAM;
805  goto reload_fini;
806  }
807 
808  /* Save this here so we can get at it for the later phases of crypto change */
809  if (new_config.crypto_changed) {
810 #ifndef HAVE_KNET_CRYPTO_RECONF
811  new_config.crypto_changed = 0;
812  log_printf (LOGSYS_LEVEL_ERROR, "Crypto reconfiguration is not supported by the linked version of knet\n");
813  res = CS_ERR_INVALID_PARAM;
814  goto reload_fini;
815 #endif
816  }
817 
818  /*
819  * Copy new keys into live config.
820  */
821  if ( (res = icmap_copy_map(icmap_get_global_map(), temp_map)) != CS_OK) {
822  log_printf (LOGSYS_LEVEL_ERROR, "Error making new config live. cmap database may be inconsistent\n");
823  /* Return res from icmap */
824  goto reload_fini;
825  }
826 
827  /* Copy into live system */
828  totempg_put_config(&new_config);
829  totemconfig_commit_new_params(&new_config, temp_map);
830 
831 reload_fini:
832  /* All done - let clients know */
833  icmap_set_int32("config.reload_status", res);
834  icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
835  icmap_set_uint8("config.reload_in_progress", 0);
836 
837  /* Finished with the temporary storage */
838  free(new_config.interfaces);
839  free(new_config.orig_interfaces);
840 
841 reload_fini_nofree:
842  icmap_fini_r(temp_map);
843 
844 reload_fini_nomap:
845 
846  /* If crypto was changed, now it's loaded on all nodes we can enable it.
847  * Each node sends its own PHASE message so we're not relying on the leader
848  * node to survive the transition
849  */
850  if (new_config.crypto_changed) {
852  struct iovec iovec;
853 
854  req_exec_cfg_crypto_reconfig.header.size =
855  sizeof (struct req_exec_cfg_crypto_reconfig);
859 
860  iovec.iov_base = (char *)&req_exec_cfg_crypto_reconfig;
861  iovec.iov_len = sizeof (struct req_exec_cfg_crypto_reconfig);
862 
863  assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
864  }
865 
866  /* All done, return result to the caller if it was on this system */
867  if (nodeid == api->totem_nodeid_get()) {
870  res_lib_cfg_reload_config.header.error = res;
871  api->ipc_response_send(req_exec_cfg_reload_config->source.conn,
873  sizeof(res_lib_cfg_reload_config));
874  api->ipc_refcnt_dec(req_exec_cfg_reload_config->source.conn);;
875  }
876 
877  LEAVE();
878 }
879 
880 /* Handle the phases of crypto reload
881  * The first time we are called is after the new crypto config has been loaded
882  * but not activated.
883  *
884  * 1 - activate the new crypto configuration
885  * 2 - clear out the old configuration
886  */
887 static void message_handler_req_exec_cfg_reconfig_crypto (
888  const void *message,
889  unsigned int nodeid)
890 {
892 
893  /* Got our own reconfig message */
894  if (nodeid == api->totem_nodeid_get()) {
895  log_printf (LOGSYS_LEVEL_DEBUG, "Crypto reconfiguration phase %d", req_exec_cfg_crypto_reconfig->phase);
896 
897  /* Do the deed */
898  totempg_crypto_reconfigure_phase(req_exec_cfg_crypto_reconfig->phase);
899 
900  /* Move to the next phase if not finished */
901  if (req_exec_cfg_crypto_reconfig->phase < CRYPTO_RECONFIG_PHASE_CLEANUP) {
902  struct req_exec_cfg_crypto_reconfig req_exec_cfg_crypto_reconfig2;
903  struct iovec iovec;
904 
905  req_exec_cfg_crypto_reconfig2.header.size =
906  sizeof (struct req_exec_cfg_crypto_reconfig);
907  req_exec_cfg_crypto_reconfig2.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
909  req_exec_cfg_crypto_reconfig2.phase = CRYPTO_RECONFIG_PHASE_CLEANUP;
910 
911  iovec.iov_base = (char *)&req_exec_cfg_crypto_reconfig2;
912  iovec.iov_len = sizeof (struct req_exec_cfg_crypto_reconfig);
913 
914  assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
915  }
916  }
917 }
918 
919 
920 /*
921  * Library Interface Implementation
922  */
923 static void message_handler_req_lib_cfg_ringstatusget (
924  void *conn,
925  const void *msg)
926 {
928  struct totem_ip_address interfaces[INTERFACE_MAX];
929  unsigned int iface_count;
930  char **status;
931  const char *totem_ip_string;
932  char ifname[CFG_INTERFACE_NAME_MAX_LEN];
933  unsigned int iface_ids[INTERFACE_MAX];
934  unsigned int i;
935  cs_error_t res = CS_OK;
936 
937  ENTER();
938 
940  res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
941 
942  api->totem_ifaces_get (
943  api->totem_nodeid_get(),
944  iface_ids,
945  interfaces,
947  &status,
948  &iface_count);
949 
950  assert(iface_count <= CFG_MAX_INTERFACES);
951 
952  res_lib_cfg_ringstatusget.interface_count = iface_count;
953 
954  for (i = 0; i < iface_count; i++) {
955  totem_ip_string
956  = (const char *)api->totem_ip_print (&interfaces[i]);
957 
958  if (!totem_ip_string) {
959  totem_ip_string="";
960  }
961 
962  /* Allow for i/f number at the start */
963  if (strlen(totem_ip_string) >= CFG_INTERFACE_NAME_MAX_LEN-3) {
964  log_printf(LOGSYS_LEVEL_ERROR, "String representation of interface %u is too long", i);
965  res = CS_ERR_NAME_TOO_LONG;
966  goto send_response;
967  }
968  snprintf(ifname, sizeof(ifname), "%d %s", iface_ids[i], totem_ip_string);
969 
970  if (strlen(status[i]) >= CFG_INTERFACE_STATUS_MAX_LEN) {
971  log_printf(LOGSYS_LEVEL_ERROR, "Status string for interface %u is too long", i);
972  res = CS_ERR_NAME_TOO_LONG;
973  goto send_response;
974  }
975 
976  strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
977  status[i]);
978  strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
979  ifname);
980  }
981 
982 send_response:
983  res_lib_cfg_ringstatusget.header.error = res;
984  api->ipc_response_send (
985  conn,
987  sizeof (struct res_lib_cfg_ringstatusget));
988 
989  LEAVE();
990 }
991 
992 
993 static void message_handler_req_lib_cfg_nodestatusget (
994  void *conn,
995  const void *msg)
996 {
999  void *res_lib_cfg_nodestatusget_ptr = NULL;
1000  size_t res_lib_cfg_nodestatusget_size;
1001  struct req_lib_cfg_nodestatusget *req_lib_cfg_nodestatusget = (struct req_lib_cfg_nodestatusget *)msg;
1002  struct totem_node_status node_status;
1003  int i;
1004 
1005  ENTER();
1006 
1007  memset(&node_status, 0, sizeof(node_status));
1008  if (totempg_nodestatus_get(req_lib_cfg_nodestatusget->nodeid, &node_status) != 0) {
1009  res_lib_cfg_nodestatusget_ptr = &res_lib_cfg_nodestatusget_version;
1010  res_lib_cfg_nodestatusget_size = sizeof(res_lib_cfg_nodestatusget_version);
1011 
1014  res_lib_cfg_nodestatusget_version.header.size = res_lib_cfg_nodestatusget_size;
1015 
1016  goto ipc_response_send;
1017  }
1018 
1019  /* Currently only one structure version supported */
1020  switch (req_lib_cfg_nodestatusget->version) {
1021  case CFG_NODE_STATUS_V1:
1022  res_lib_cfg_nodestatusget_ptr = &res_lib_cfg_nodestatusget_v1;
1023  res_lib_cfg_nodestatusget_size = sizeof(res_lib_cfg_nodestatusget_v1);
1024 
1025  res_lib_cfg_nodestatusget_v1.header.error = CS_OK;
1027  res_lib_cfg_nodestatusget_v1.header.size = res_lib_cfg_nodestatusget_size;
1028 
1029  res_lib_cfg_nodestatusget_v1.node_status.version = CFG_NODE_STATUS_V1;
1030  res_lib_cfg_nodestatusget_v1.node_status.nodeid = req_lib_cfg_nodestatusget->nodeid;
1031  res_lib_cfg_nodestatusget_v1.node_status.reachable = node_status.reachable;
1032  res_lib_cfg_nodestatusget_v1.node_status.remote = node_status.remote;
1033  res_lib_cfg_nodestatusget_v1.node_status.external = node_status.external;
1034  res_lib_cfg_nodestatusget_v1.node_status.onwire_min = node_status.onwire_min;
1035  res_lib_cfg_nodestatusget_v1.node_status.onwire_max = node_status.onwire_max;
1036  res_lib_cfg_nodestatusget_v1.node_status.onwire_ver = node_status.onwire_ver;
1037 
1038  for (i=0; i < KNET_MAX_LINK; i++) {
1039  res_lib_cfg_nodestatusget_v1.node_status.link_status[i].enabled = node_status.link_status[i].enabled;
1040  res_lib_cfg_nodestatusget_v1.node_status.link_status[i].connected = node_status.link_status[i].connected;
1041  res_lib_cfg_nodestatusget_v1.node_status.link_status[i].dynconnected = node_status.link_status[i].dynconnected;
1042  res_lib_cfg_nodestatusget_v1.node_status.link_status[i].mtu = node_status.link_status[i].mtu;
1043  memcpy(res_lib_cfg_nodestatusget_v1.node_status.link_status[i].src_ipaddr,
1044  node_status.link_status[i].src_ipaddr, CFG_MAX_HOST_LEN);
1045  memcpy(res_lib_cfg_nodestatusget_v1.node_status.link_status[i].dst_ipaddr,
1046  node_status.link_status[i].dst_ipaddr, CFG_MAX_HOST_LEN);
1047  }
1048  break;
1049  default:
1050  /*
1051  * Unsupported version requested
1052  */
1053  res_lib_cfg_nodestatusget_ptr = &res_lib_cfg_nodestatusget_version;
1054  res_lib_cfg_nodestatusget_size = sizeof(res_lib_cfg_nodestatusget_version);
1055 
1058  res_lib_cfg_nodestatusget_version.header.size = res_lib_cfg_nodestatusget_size;
1059  break;
1060  }
1061 
1062 ipc_response_send:
1063  api->ipc_response_send (
1064  conn,
1065  res_lib_cfg_nodestatusget_ptr,
1066  res_lib_cfg_nodestatusget_size);
1067 
1068  LEAVE();
1069 }
1070 
1071 static void message_handler_req_lib_cfg_trackstart (
1072  void *conn,
1073  const void *msg)
1074 {
1075  struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
1077 
1078  ENTER();
1079 
1080  /*
1081  * We only do shutdown tracking at the moment
1082  */
1083  if (qb_list_empty(&ci->list)) {
1084  qb_list_add(&ci->list, &trackers_list);
1085  ci->tracker_conn = conn;
1086 
1087  if (shutdown_con) {
1088  /*
1089  * Shutdown already in progress, ask the newcomer's opinion
1090  */
1091  ci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
1092  shutdown_expected++;
1093  send_test_shutdown(conn, NULL, CS_OK);
1094  }
1095  }
1096 
1100 
1102  sizeof(res_lib_cfg_trackstart));
1103 
1104  LEAVE();
1105 }
1106 
1107 static void message_handler_req_lib_cfg_trackstop (
1108  void *conn,
1109  const void *msg)
1110 {
1111  struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
1113 
1114  ENTER();
1115  remove_ci_from_shutdown(ci);
1116 
1117  res_lib_cfg_trackstop.header.size = sizeof(struct res_lib_cfg_trackstop);
1120 
1122  sizeof(res_lib_cfg_trackstop));
1123  LEAVE();
1124 }
1125 
1126 static void message_handler_req_lib_cfg_ringreenable (
1127  void *conn,
1128  const void *msg)
1129 {
1131  ENTER();
1132 
1134  res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
1136  api->ipc_response_send (
1137  conn, &res_lib_cfg_ringreenable,
1138  sizeof (struct res_lib_cfg_ringreenable));
1139 
1140  LEAVE();
1141 }
1142 
1143 static void message_handler_req_lib_cfg_killnode (
1144  void *conn,
1145  const void *msg)
1146 {
1147  const struct req_lib_cfg_killnode *req_lib_cfg_killnode = msg;
1149  struct req_exec_cfg_killnode req_exec_cfg_killnode;
1150  struct iovec iovec;
1151  char key_name[ICMAP_KEYNAME_MAXLEN];
1152  char tmp_key[ICMAP_KEYNAME_MAXLEN + 1];
1153  icmap_map_t map;
1154  icmap_iter_t iter;
1155  const char *iter_key;
1156  uint32_t nodeid;
1157  char *status_str = NULL;
1158  int match_nodeid_flag = 0;
1159  cs_error_t error = CS_OK;
1160 
1161  ENTER();
1162 
1163  map = icmap_get_global_map();
1164  iter = icmap_iter_init_r(map, "runtime.members.");
1165  while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
1166  if (sscanf(iter_key, "runtime.members.%u.%s", &nodeid, key_name) != 2) {
1167  continue;
1168  }
1169  if (strcmp(key_name, "status") != 0) {
1170  continue;
1171  }
1172  if (nodeid != req_lib_cfg_killnode->nodeid) {
1173  continue;
1174  }
1175  match_nodeid_flag = 1;
1176  snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "runtime.members.%u.status", nodeid);
1177  if (icmap_get_string_r(map, tmp_key, &status_str) != CS_OK) {
1178  error = CS_ERR_LIBRARY;
1179  goto send_response;
1180  }
1181  if (strcmp(status_str, "joined") != 0) {
1182  error = CS_ERR_NOT_EXIST;
1183  goto send_response;
1184  }
1185  break;
1186  }
1187 
1188  if (!match_nodeid_flag) {
1189  error = CS_ERR_NOT_EXIST;
1190  goto send_response;
1191  }
1192 
1193  req_exec_cfg_killnode.header.size =
1194  sizeof (struct req_exec_cfg_killnode);
1195  req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
1197  req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
1198  marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
1199 
1200  iovec.iov_base = (char *)&req_exec_cfg_killnode;
1201  iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
1202 
1203  (void)api->totem_mcast (&iovec, 1, TOTEM_SAFE);
1204 
1205 send_response:
1206  res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
1208  res_lib_cfg_killnode.header.error = error;
1209 
1211  sizeof(res_lib_cfg_killnode));
1212 
1213  free(status_str);
1214  icmap_iter_finalize(iter);
1215  LEAVE();
1216 }
1217 
1218 
1219 static void message_handler_req_lib_cfg_tryshutdown (
1220  void *conn,
1221  const void *msg)
1222 {
1223  struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
1225  struct qb_list_head *iter;
1226 
1227  ENTER();
1228 
1229  if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
1231 
1232  /*
1233  * Tell other nodes
1234  */
1235  send_shutdown();
1236 
1237  res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
1239  res_lib_cfg_tryshutdown.header.error = CS_OK;
1241  sizeof(res_lib_cfg_tryshutdown));
1242 
1243  LEAVE();
1244  return;
1245  }
1246 
1247  /*
1248  * Shutdown in progress, return an error
1249  */
1250  if (shutdown_con) {
1252 
1253  res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
1255  res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
1256 
1258  sizeof(res_lib_cfg_tryshutdown));
1259 
1260 
1261  LEAVE();
1262 
1263  return;
1264  }
1265 
1266  ci->conn = conn;
1267  shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
1268  shutdown_flags = req_lib_cfg_tryshutdown->flags;
1269  shutdown_yes = 0;
1270  shutdown_no = 0;
1271 
1272  /*
1273  * Count the number of listeners
1274  */
1275  shutdown_expected = 0;
1276 
1277  qb_list_for_each(iter, &trackers_list) {
1278  struct cfg_info *testci = qb_list_entry(iter, struct cfg_info, list);
1279  /*
1280  * It is assumed that we will allow shutdown
1281  */
1282  if (testci != ci) {
1284  shutdown_expected++;
1285  }
1286  }
1287 
1288  /*
1289  * If no-one is listening for events then we can just go down now
1290  */
1291  if (shutdown_expected == 0) {
1293 
1294  res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
1296  res_lib_cfg_tryshutdown.header.error = CS_OK;
1297 
1298  /*
1299  * Tell originator that shutdown was confirmed
1300  */
1302  sizeof(res_lib_cfg_tryshutdown));
1303 
1304  send_shutdown();
1305  LEAVE();
1306  return;
1307  }
1308  else {
1309  unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
1310 
1311  /*
1312  * Look for a shutdown timeout in configuration map
1313  */
1314  icmap_get_uint32("cfg.shutdown_timeout", &shutdown_timeout);
1315 
1316  /*
1317  * Start the timer. If we don't get a full set of replies before this goes
1318  * off we'll cancel the shutdown
1319  */
1320  api->timer_add_duration((unsigned long long)shutdown_timeout*QB_TIME_NS_IN_MSEC, NULL,
1321  shutdown_timer_fn, &shutdown_timer);
1322 
1323  /*
1324  * Tell the users we would like to shut down
1325  */
1326  send_test_shutdown(NULL, conn, CS_OK);
1327  }
1328 
1329  /*
1330  * We don't sent a reply to the caller here.
1331  * We send it when we know if we can shut down or not
1332  */
1333 
1334  LEAVE();
1335 }
1336 
1337 static void message_handler_req_lib_cfg_replytoshutdown (
1338  void *conn,
1339  const void *msg)
1340 {
1341  struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
1344  int status = CS_OK;
1345 
1346  ENTER();
1347  if (!shutdown_con) {
1348  status = CS_ERR_ACCESS;
1349  goto exit_fn;
1350  }
1351 
1352  if (req_lib_cfg_replytoshutdown->response) {
1353  shutdown_yes++;
1354  ci->shutdown_reply = SHUTDOWN_REPLY_YES;
1355  }
1356  else {
1357  shutdown_no++;
1358  ci->shutdown_reply = SHUTDOWN_REPLY_NO;
1359  }
1360  check_shutdown_status();
1361 
1362 exit_fn:
1363  res_lib_cfg_replytoshutdown.header.error = status;
1366 
1368  sizeof(res_lib_cfg_replytoshutdown));
1369 
1370  LEAVE();
1371 }
1372 
1373 static void message_handler_req_lib_cfg_get_node_addrs (void *conn,
1374  const void *msg)
1375 {
1376  struct totem_ip_address node_ifs[INTERFACE_MAX];
1377  unsigned int iface_ids[INTERFACE_MAX];
1378  char buf[PIPE_BUF];
1379  char **status;
1380  unsigned int num_interfaces = 0;
1381  struct sockaddr_storage *ss;
1382  int ret = CS_OK;
1383  int i;
1384  int live_addrs = 0;
1386  struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)buf;
1387  unsigned int nodeid = req_lib_cfg_get_node_addrs->nodeid;
1388  char *addr_buf;
1389 
1390  if (nodeid == 0)
1391  nodeid = api->totem_nodeid_get();
1392 
1393  if (api->totem_ifaces_get(nodeid, iface_ids, node_ifs, INTERFACE_MAX, &status, &num_interfaces)) {
1394  ret = CS_ERR_EXIST;
1395  num_interfaces = 0;
1396  }
1397 
1398  res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
1399  res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
1400  res_lib_cfg_get_node_addrs->header.error = ret;
1401  if (num_interfaces) {
1402  res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
1403  for (i = 0, addr_buf = (char *)res_lib_cfg_get_node_addrs->addrs;
1404  i < num_interfaces; i++) {
1405  ss = (struct sockaddr_storage *)&node_ifs[i].addr;
1406  if (ss->ss_family) {
1407  memcpy(addr_buf, node_ifs[i].addr, TOTEMIP_ADDRLEN);
1408  live_addrs++;
1409  addr_buf += TOTEMIP_ADDRLEN;
1410  }
1411  }
1412  res_lib_cfg_get_node_addrs->num_addrs = live_addrs;
1413  } else {
1414  res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
1415  }
1416  api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
1417 }
1418 
1419 static void message_handler_req_lib_cfg_local_get (void *conn, const void *msg)
1420 {
1422 
1423  res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
1425  res_lib_cfg_local_get.header.error = CS_OK;
1426  res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
1427 
1429  sizeof(res_lib_cfg_local_get));
1430 }
1431 
1432 static void message_handler_req_lib_cfg_reload_config (void *conn, const void *msg)
1433 {
1434  struct req_exec_cfg_reload_config req_exec_cfg_reload_config;
1435  struct iovec iovec;
1436 
1437  ENTER();
1438 
1439  req_exec_cfg_reload_config.header.size =
1440  sizeof (struct req_exec_cfg_reload_config);
1441  req_exec_cfg_reload_config.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
1443  api->ipc_source_set (&req_exec_cfg_reload_config.source, conn);
1444  api->ipc_refcnt_inc(conn);
1445 
1446  iovec.iov_base = (char *)&req_exec_cfg_reload_config;
1447  iovec.iov_len = sizeof (struct req_exec_cfg_reload_config);
1448 
1449  assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
1450 
1451  LEAVE();
1452 }
1453 
1454 static void message_handler_req_lib_cfg_reopen_log_files (void *conn, const void *msg)
1455 {
1457  cs_error_t res;
1458 
1459  ENTER();
1460 
1461  log_printf(LOGSYS_LEVEL_DEBUG, "Reopening logging files\n");
1462 
1463  res = logsys_reopen_log_files();
1464 
1467  res_lib_cfg_reopen_log_files.header.error = res;
1468  api->ipc_response_send(conn,
1471 
1472  LEAVE();
1473 }
struct qb_ipc_request_header header __attribute__((aligned(8)))
void *(* ipc_private_data_get)(void *conn)
Definition: coroapi.h:256
const char * name
Definition: coroapi.h:491
The res_lib_cfg_reopen_log_files struct.
Definition: ipc_cfg.h:256
void(* timer_delete)(corosync_timer_handle_t timer_handle)
Definition: coroapi.h:241
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:1099
#define CFG_INTERFACE_STATUS_MAX_LEN
Definition: ipc_cfg.h:43
struct qb_list_head list
Definition: exec/cfg.c:100
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:1302
The res_lib_cfg_replytoshutdown struct.
Definition: ipc_cfg.h:186
The res_lib_cfg_testshutdown struct.
Definition: ipc_cfg.h:193
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:1120
void(* shutdown_request)(void)
Definition: coroapi.h:429
cs_error_t logsys_reopen_log_files(void)
Definition: logsys.c:909
uint8_t value[CS_MAX_NAME_LENGTH]
Definition: corotypes.h:68
int coroparse_configparse(icmap_map_t config_map, const char **error_string)
Definition: coroparse.c:259
#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
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:125
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:389
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:209
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:201
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:242
icmap_map_t icmap_get_global_map(void)
Return global icmap.
Definition: icmap.c:268
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:332
void(* exec_handler_fn)(const void *msg, unsigned int nodeid)
Definition: coroapi.h:476
int totemconfig_commit_new_params(struct totem_config *totem_config, icmap_map_t map)
Definition: totemconfig.c:2421
void * tracker_conn
Definition: exec/cfg.c:102
#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
The res_lib_cfg_local_get struct.
Definition: ipc_cfg.h:227
The res_lib_cfg_killnode struct.
Definition: ipc_cfg.h:156
#define TOTEM_SAFE
Definition: coroapi.h:103
unsigned int num_addrs
Definition: ipc_cfg.h:212
unsigned int flags
Definition: ipc_cfg.h:195
The req_lib_cfg_tryshutdown struct.
Definition: ipc_cfg.h:163
unsigned int(* totem_nodeid_get)(void)
Definition: coroapi.h:275
void(* ipc_refcnt_dec)(void *conn)
Definition: coroapi.h:270
struct qb_ipc_request_header header __attribute__((aligned(8)))
The res_lib_cfg_ringreenable struct.
Definition: ipc_cfg.h:140
cs_error_t icmap_get_string_r(const icmap_map_t map, const char *key_name, char **str)
Definition: icmap.c:739
int totem_volatile_config_validate(struct totem_config *totem_config, icmap_map_t temp_map, const char **error_string)
Definition: totemconfig.c:380
#define LOGSYS_LEVEL_ERROR
Definition: logsys.h:72
#define TRACE1(format, args...)
Definition: logsys.h:335
#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:657
#define CFG_MAX_HOST_LEN
Definition: cfg.h:169
cs_error_t
The cs_error_t enum.
Definition: corotypes.h:98
#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:178
The res_lib_cfg_tryshutdown struct.
Definition: ipc_cfg.h:171
cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
Definition: icmap.c:896
#define DEFAULT_SHUTDOWN_TIMEOUT
Definition: exec/cfg.c:84
#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:333
cs_error_t icmap_set_int32(const char *key_name, int32_t value)
Definition: icmap.c:595
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:311
cfg_message_req_types
Definition: exec/cfg.c:75
The memb_ring_id struct.
Definition: coroapi.h:122
unsigned int flags
Definition: ipc_cfg.h:165
cs_error_t icmap_delete_r(const icmap_map_t map, const char *key_name)
icmap_delete_r
Definition: icmap.c:637
struct qb_ipc_response_header header
Definition: ipc_cfg.h:274
The res_lib_cfg_ringstatusget struct.
Definition: ipc_cfg.h:101
int totemconfig_configure_new_params(struct totem_config *totem_config, icmap_map_t map, const char **error_string)
Definition: totemconfig.c:2398
cs_error_t icmap_init_r(icmap_map_t *result)
Initialize additional (local, reentrant) icmap_map.
Definition: icmap.c:188
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:2293
void * conn
Definition: exec/cfg.c:101
struct corosync_service_engine cfg_service_engine
Definition: exec/cfg.c:270
The req_lib_cfg_nodestatusget struct.
Definition: ipc_cfg.h:111
struct qb_ipc_request_header header __attribute__((aligned(8)))
struct qb_ipc_request_header header __attribute__((aligned(8)))
The res_lib_cfg_reload_config struct.
Definition: ipc_cfg.h:242
#define LOGSYS_LEVEL_NOTICE
Definition: logsys.h:74
cs_error_t icmap_set_uint8(const char *key_name, uint8_t value)
Definition: icmap.c:577
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:287
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:1088
icmap_iter_t icmap_iter_init(const char *prefix)
Initialize iterator with given prefix.
Definition: icmap.c:1093
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
struct qb_ipc_response_header header
Definition: ipc_cfg.h:266
The req_lib_cfg_killnode struct.
Definition: ipc_cfg.h:147
#define LEAVE
Definition: logsys.h:334
qb_map_iter_t * icmap_iter_t
Itterator type.
Definition: icmap.h:123
The cs_name_t struct.
Definition: corotypes.h:66
The mar_message_source_t struct.
Definition: coroapi.h:50
void(* ipc_refcnt_inc)(void *conn)
Definition: coroapi.h:268