corosync  2.4.2-dirty
exec/cfg.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005-2006 MontaVista Software, Inc.
3  * Copyright (c) 2006-2013 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 <limits.h>
49 #include <errno.h>
50 #include <string.h>
51 #include <assert.h>
52 
53 #include <corosync/corotypes.h>
54 #include <qb/qbipc_common.h>
55 #include <corosync/cfg.h>
56 #include <corosync/list.h>
57 #include <corosync/mar_gen.h>
58 #include <corosync/totem/totemip.h>
59 #include <corosync/totem/totem.h>
60 #include <corosync/ipc_cfg.h>
61 #include <corosync/logsys.h>
62 #include <corosync/coroapi.h>
63 #include <corosync/icmap.h>
64 #include <corosync/corodefs.h>
65 
66 #include "service.h"
67 #include "main.h"
68 
69 LOGSYS_DECLARE_SUBSYS ("CFG");
70 
76 };
77 
78 #define DEFAULT_SHUTDOWN_TIMEOUT 5
79 
80 static struct list_head trackers_list;
81 
82 /*
83  * Variables controlling a requested shutdown
84  */
85 static corosync_timer_handle_t shutdown_timer;
86 static struct cfg_info *shutdown_con;
87 static uint32_t shutdown_flags;
88 static int shutdown_yes;
89 static int shutdown_no;
90 static int shutdown_expected;
91 
92 struct cfg_info
93 {
94  struct list_head list;
95  void *conn;
96  void *tracker_conn;
98 };
99 
100 static void cfg_confchg_fn (
101  enum totem_configuration_type configuration_type,
102  const unsigned int *member_list, size_t member_list_entries,
103  const unsigned int *left_list, size_t left_list_entries,
104  const unsigned int *joined_list, size_t joined_list_entries,
105  const struct memb_ring_id *ring_id);
106 
107 static char *cfg_exec_init_fn (struct corosync_api_v1 *corosync_api_v1);
108 
109 static struct corosync_api_v1 *api;
110 
111 static int cfg_lib_init_fn (void *conn);
112 
113 static int cfg_lib_exit_fn (void *conn);
114 
115 static void message_handler_req_exec_cfg_ringreenable (
116  const void *message,
117  unsigned int nodeid);
118 
119 static void message_handler_req_exec_cfg_killnode (
120  const void *message,
121  unsigned int nodeid);
122 
123 static void message_handler_req_exec_cfg_shutdown (
124  const void *message,
125  unsigned int nodeid);
126 
127 static void message_handler_req_exec_cfg_reload_config (
128  const void *message,
129  unsigned int nodeid);
130 
131 static void exec_cfg_killnode_endian_convert (void *msg);
132 
133 static void message_handler_req_lib_cfg_ringstatusget (
134  void *conn,
135  const void *msg);
136 
137 static void message_handler_req_lib_cfg_ringreenable (
138  void *conn,
139  const void *msg);
140 
141 static void message_handler_req_lib_cfg_killnode (
142  void *conn,
143  const void *msg);
144 
145 static void message_handler_req_lib_cfg_tryshutdown (
146  void *conn,
147  const void *msg);
148 
149 static void message_handler_req_lib_cfg_replytoshutdown (
150  void *conn,
151  const void *msg);
152 
153 static void message_handler_req_lib_cfg_get_node_addrs (
154  void *conn,
155  const void *msg);
156 
157 static void message_handler_req_lib_cfg_local_get (
158  void *conn,
159  const void *msg);
160 
161 static void message_handler_req_lib_cfg_reload_config (
162  void *conn,
163  const void *msg);
164 
165 /*
166  * Service Handler Definition
167  */
168 static struct corosync_lib_handler cfg_lib_engine[] =
169 {
170  { /* 0 */
171  .lib_handler_fn = message_handler_req_lib_cfg_ringstatusget,
172  .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
173  },
174  { /* 1 */
175  .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
176  .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
177  },
178  { /* 2 */
179  .lib_handler_fn = message_handler_req_lib_cfg_killnode,
180  .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
181  },
182  { /* 3 */
183  .lib_handler_fn = message_handler_req_lib_cfg_tryshutdown,
184  .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
185  },
186  { /* 4 */
187  .lib_handler_fn = message_handler_req_lib_cfg_replytoshutdown,
188  .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
189  },
190  { /* 5 */
191  .lib_handler_fn = message_handler_req_lib_cfg_get_node_addrs,
192  .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
193  },
194  { /* 6 */
195  .lib_handler_fn = message_handler_req_lib_cfg_local_get,
196  .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
197  },
198  { /* 7 */
199  .lib_handler_fn = message_handler_req_lib_cfg_reload_config,
200  .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
201  }
202 };
203 
204 static struct corosync_exec_handler cfg_exec_engine[] =
205 {
206  { /* 0 */
207  .exec_handler_fn = message_handler_req_exec_cfg_ringreenable,
208  },
209  { /* 1 */
210  .exec_handler_fn = message_handler_req_exec_cfg_killnode,
211  .exec_endian_convert_fn = exec_cfg_killnode_endian_convert
212  },
213  { /* 2 */
214  .exec_handler_fn = message_handler_req_exec_cfg_shutdown,
215  },
216  { /* 3 */
217  .exec_handler_fn = message_handler_req_exec_cfg_reload_config,
218  }
219 };
220 
221 /*
222  * Exports the interface for the service
223  */
225  .name = "corosync configuration service",
226  .id = CFG_SERVICE,
227  .priority = 1,
228  .private_data_size = sizeof(struct cfg_info),
229  .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED,
230  .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
231  .lib_init_fn = cfg_lib_init_fn,
232  .lib_exit_fn = cfg_lib_exit_fn,
233  .lib_engine = cfg_lib_engine,
234  .lib_engine_count = sizeof (cfg_lib_engine) / sizeof (struct corosync_lib_handler),
235  .exec_init_fn = cfg_exec_init_fn,
236  .exec_engine = cfg_exec_engine,
237  .exec_engine_count = sizeof (cfg_exec_engine) / sizeof (struct corosync_exec_handler),
238  .confchg_fn = cfg_confchg_fn
239 };
240 
242 {
243  return (&cfg_service_engine);
244 }
245 
247  struct qb_ipc_request_header header __attribute__((aligned(8)));
248  mar_message_source_t source __attribute__((aligned(8)));
249 };
250 
252  struct qb_ipc_request_header header __attribute__((aligned(8)));
253  mar_message_source_t source __attribute__((aligned(8)));
254 };
255 
257  struct qb_ipc_request_header header __attribute__((aligned(8)));
258  mar_uint32_t nodeid __attribute__((aligned(8)));
259  mar_name_t reason __attribute__((aligned(8)));
260 };
261 
263  struct qb_ipc_request_header header __attribute__((aligned(8)));
264 };
265 
266 /* IMPL */
267 
268 static char *cfg_exec_init_fn (
269  struct corosync_api_v1 *corosync_api_v1)
270 {
271  api = corosync_api_v1;
272 
273  list_init(&trackers_list);
274  return (NULL);
275 }
276 
277 static void cfg_confchg_fn (
278  enum totem_configuration_type configuration_type,
279  const unsigned int *member_list, size_t member_list_entries,
280  const unsigned int *left_list, size_t left_list_entries,
281  const unsigned int *joined_list, size_t joined_list_entries,
282  const struct memb_ring_id *ring_id)
283 {
284 }
285 
286 /*
287  * Tell other nodes we are shutting down
288  */
289 static int send_shutdown(void)
290 {
291  struct req_exec_cfg_shutdown req_exec_cfg_shutdown;
292  struct iovec iovec;
293 
294  ENTER();
295  req_exec_cfg_shutdown.header.size =
296  sizeof (struct req_exec_cfg_shutdown);
297  req_exec_cfg_shutdown.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
299 
300  iovec.iov_base = (char *)&req_exec_cfg_shutdown;
301  iovec.iov_len = sizeof (struct req_exec_cfg_shutdown);
302 
303  assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
304 
305  LEAVE();
306  return 0;
307 }
308 
309 static void send_test_shutdown(void *only_conn, void *exclude_conn, int status)
310 {
311  struct res_lib_cfg_testshutdown res_lib_cfg_testshutdown;
312  struct list_head *iter;
313 
314  ENTER();
315  res_lib_cfg_testshutdown.header.size = sizeof(struct res_lib_cfg_testshutdown);
316  res_lib_cfg_testshutdown.header.id = MESSAGE_RES_CFG_TESTSHUTDOWN;
317  res_lib_cfg_testshutdown.header.error = status;
318  res_lib_cfg_testshutdown.flags = shutdown_flags;
319 
320  if (only_conn) {
321  TRACE1("sending testshutdown to only %p", only_conn);
322  api->ipc_dispatch_send(only_conn, &res_lib_cfg_testshutdown,
323  sizeof(res_lib_cfg_testshutdown));
324  } else {
325  for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
326  struct cfg_info *ci = list_entry(iter, struct cfg_info, list);
327 
328  if (ci->conn != exclude_conn) {
329  TRACE1("sending testshutdown to %p", ci->tracker_conn);
330  api->ipc_dispatch_send(ci->tracker_conn, &res_lib_cfg_testshutdown,
331  sizeof(res_lib_cfg_testshutdown));
332  }
333  }
334  }
335  LEAVE();
336 }
337 
338 static void check_shutdown_status(void)
339 {
340  ENTER();
341 
342  /*
343  * Shutdown client might have gone away
344  */
345  if (!shutdown_con) {
346  LEAVE();
347  return;
348  }
349 
350  /*
351  * All replies safely gathered in ?
352  */
353  if (shutdown_yes + shutdown_no >= shutdown_expected) {
354  struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
355 
356  api->timer_delete(shutdown_timer);
357 
358  if (shutdown_yes >= shutdown_expected ||
359  shutdown_flags == CFG_SHUTDOWN_FLAG_REGARDLESS) {
360  TRACE1("shutdown confirmed");
361 
362  res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
363  res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
364  res_lib_cfg_tryshutdown.header.error = CS_OK;
365 
366  /*
367  * Tell originator that shutdown was confirmed
368  */
369  api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
370  sizeof(res_lib_cfg_tryshutdown));
371  shutdown_con = NULL;
372 
373  /*
374  * Tell other nodes we are going down
375  */
376  send_shutdown();
377 
378  }
379  else {
380 
381  TRACE1("shutdown cancelled");
382  res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
383  res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
384  res_lib_cfg_tryshutdown.header.error = CS_ERR_BUSY;
385 
386  /*
387  * Tell originator that shutdown was cancelled
388  */
389  api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
390  sizeof(res_lib_cfg_tryshutdown));
391  shutdown_con = NULL;
392  }
393 
394  log_printf(LOGSYS_LEVEL_DEBUG, "shutdown decision is: (yes count: %d, no count: %d) flags=%x",
395  shutdown_yes, shutdown_no, shutdown_flags);
396  }
397  LEAVE();
398 }
399 
400 
401 /*
402  * Not all nodes responded to the shutdown (in time)
403  */
404 static void shutdown_timer_fn(void *arg)
405 {
406  ENTER();
407 
408  /*
409  * Mark undecideds as "NO"
410  */
411  shutdown_no = shutdown_expected;
412  check_shutdown_status();
413 
414  send_test_shutdown(NULL, NULL, CS_ERR_TIMEOUT);
415  LEAVE();
416 }
417 
418 static void remove_ci_from_shutdown(struct cfg_info *ci)
419 {
420  ENTER();
421 
422  /*
423  * If the controlling shutdown process has quit, then cancel the
424  * shutdown session
425  */
426  if (ci == shutdown_con) {
427  shutdown_con = NULL;
428  api->timer_delete(shutdown_timer);
429  }
430 
431  if (!list_empty(&ci->list)) {
432  list_del(&ci->list);
433  list_init(&ci->list);
434 
435  /*
436  * Remove our option
437  */
438  if (shutdown_con) {
440  shutdown_yes--;
442  shutdown_no--;
443  }
444 
445  /*
446  * If we are leaving, then that's an implicit YES to shutdown
447  */
449  shutdown_yes++;
450 
451  check_shutdown_status();
452  }
453  LEAVE();
454 }
455 
456 
457 int cfg_lib_exit_fn (void *conn)
458 {
459  struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
460 
461  ENTER();
462  remove_ci_from_shutdown(ci);
463  LEAVE();
464  return (0);
465 }
466 
467 static int cfg_lib_init_fn (void *conn)
468 {
469  struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
470 
471  ENTER();
472  list_init(&ci->list);
473  LEAVE();
474 
475  return (0);
476 }
477 
478 /*
479  * Executive message handlers
480  */
481 static void message_handler_req_exec_cfg_ringreenable (
482  const void *message,
483  unsigned int nodeid)
484 {
486  = message;
487  struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
488 
489  ENTER();
490  api->totem_ring_reenable ();
491  if (api->ipc_source_is_local(&req_exec_cfg_ringreenable->source)) {
492  res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
493  res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
494  res_lib_cfg_ringreenable.header.error = CS_OK;
495  api->ipc_response_send (
496  req_exec_cfg_ringreenable->source.conn,
497  &res_lib_cfg_ringreenable,
498  sizeof (struct res_lib_cfg_ringreenable));
499 
500  api->ipc_refcnt_dec(req_exec_cfg_ringreenable->source.conn);
501  }
502  LEAVE();
503 }
504 
505 static void exec_cfg_killnode_endian_convert (void *msg)
506 {
508  (struct req_exec_cfg_killnode *)msg;
509  ENTER();
510 
511  swab_mar_name_t(&req_exec_cfg_killnode->reason);
512  LEAVE();
513 }
514 
515 
516 static void message_handler_req_exec_cfg_killnode (
517  const void *message,
518  unsigned int nodeid)
519 {
520  const struct req_exec_cfg_killnode *req_exec_cfg_killnode = message;
521  cs_name_t reason;
522 
523  ENTER();
524  log_printf(LOGSYS_LEVEL_DEBUG, "request to kill node %d(us=%d)",
525  req_exec_cfg_killnode->nodeid, api->totem_nodeid_get());
526  if (req_exec_cfg_killnode->nodeid == api->totem_nodeid_get()) {
527  marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
528  log_printf(LOGSYS_LEVEL_NOTICE, "Killed by node %d: %s",
529  nodeid, reason.value);
531  }
532  LEAVE();
533 }
534 
535 /*
536  * Self shutdown
537  */
538 static void message_handler_req_exec_cfg_shutdown (
539  const void *message,
540  unsigned int nodeid)
541 {
542  ENTER();
543 
544  log_printf(LOGSYS_LEVEL_NOTICE, "Node %d was shut down by sysadmin", nodeid);
545  if (nodeid == api->totem_nodeid_get()) {
546  api->shutdown_request();
547  }
548  LEAVE();
549 }
550 
551 /* strcmp replacement that can handle NULLs */
552 static int nullcheck_strcmp(const char* left, const char *right)
553 {
554  if (!left && right)
555  return -1;
556  if (left && !right)
557  return 1;
558 
559  if (!left && !right)
560  return 0;
561 
562  return strcmp(left, right);
563 }
564 
565 /*
566  * If a key has changed value in the new file, then warn the user and remove it from the temp_map
567  */
568 static void delete_and_notify_if_changed(icmap_map_t temp_map, const char *key_name)
569 {
570  if (!(icmap_key_value_eq(temp_map, key_name, icmap_get_global_map(), key_name))) {
571  if (icmap_delete_r(temp_map, key_name) == CS_OK) {
572  log_printf(LOGSYS_LEVEL_NOTICE, "Modified entry '%s' in corosync.conf cannot be changed at run-time", key_name);
573  }
574  }
575 }
576 /*
577  * Remove any keys from the new config file that in the new corosync.conf but that
578  * cannot be changed at run time. A log message will be issued for each
579  * entry that the user wants to change but they cannot.
580  *
581  * Add more here as needed.
582  */
583 static void remove_ro_entries(icmap_map_t temp_map)
584 {
585  delete_and_notify_if_changed(temp_map, "totem.secauth");
586  delete_and_notify_if_changed(temp_map, "totem.crypto_hash");
587  delete_and_notify_if_changed(temp_map, "totem.crypto_cipher");
588  delete_and_notify_if_changed(temp_map, "totem.version");
589  delete_and_notify_if_changed(temp_map, "totem.threads");
590  delete_and_notify_if_changed(temp_map, "totem.ip_version");
591  delete_and_notify_if_changed(temp_map, "totem.rrp_mode");
592  delete_and_notify_if_changed(temp_map, "totem.netmtu");
593  delete_and_notify_if_changed(temp_map, "totem.interface.ringnumber");
594  delete_and_notify_if_changed(temp_map, "totem.interface.bindnetaddr");
595  delete_and_notify_if_changed(temp_map, "totem.interface.mcastaddr");
596  delete_and_notify_if_changed(temp_map, "totem.interface.broadcast");
597  delete_and_notify_if_changed(temp_map, "totem.interface.mcastport");
598  delete_and_notify_if_changed(temp_map, "totem.interface.ttl");
599  delete_and_notify_if_changed(temp_map, "totem.vsftype");
600  delete_and_notify_if_changed(temp_map, "totem.transport");
601  delete_and_notify_if_changed(temp_map, "totem.cluster_name");
602  delete_and_notify_if_changed(temp_map, "quorum.provider");
603  delete_and_notify_if_changed(temp_map, "qb.ipc_type");
604 }
605 
606 /*
607  * Remove entries that exist in the global map, but not in the temp_map, this will
608  * cause delete notifications to be sent to any listeners.
609  *
610  * NOTE: This routine depends entirely on the keys returned by the iterators
611  * being in alpha-sorted order.
612  */
613 static void remove_deleted_entries(icmap_map_t temp_map, const char *prefix)
614 {
615  icmap_iter_t old_iter;
616  icmap_iter_t new_iter;
617  const char *old_key, *new_key;
618  int ret;
619 
620  old_iter = icmap_iter_init(prefix);
621  new_iter = icmap_iter_init_r(temp_map, prefix);
622 
623  old_key = icmap_iter_next(old_iter, NULL, NULL);
624  new_key = icmap_iter_next(new_iter, NULL, NULL);
625 
626  while (old_key || new_key) {
627  ret = nullcheck_strcmp(old_key, new_key);
628  if ((ret < 0 && old_key) || !new_key) {
629  /*
630  * new_key is greater, a line (or more) has been deleted
631  * Continue until old is >= new
632  */
633  do {
634  /* Remove it from icmap & send notifications */
635  icmap_delete(old_key);
636 
637  old_key = icmap_iter_next(old_iter, NULL, NULL);
638  ret = nullcheck_strcmp(old_key, new_key);
639  } while (ret < 0 && old_key);
640  }
641  else if ((ret > 0 && new_key) || !old_key) {
642  /*
643  * old_key is greater, a line (or more) has been added
644  * Continue until new is >= old
645  *
646  * we don't need to do anything special with this like tell
647  * icmap. That will happen when we copy the values over
648  */
649  do {
650  new_key = icmap_iter_next(new_iter, NULL, NULL);
651  ret = nullcheck_strcmp(old_key, new_key);
652  } while (ret > 0 && new_key);
653  }
654  if (ret == 0) {
655  new_key = icmap_iter_next(new_iter, NULL, NULL);
656  old_key = icmap_iter_next(old_iter, NULL, NULL);
657  }
658  }
659  icmap_iter_finalize(new_iter);
660  icmap_iter_finalize(old_iter);
661 }
662 
663 /*
664  * Reload configuration file
665  */
666 static void message_handler_req_exec_cfg_reload_config (
667  const void *message,
668  unsigned int nodeid)
669 {
671  struct res_lib_cfg_reload_config res_lib_cfg_reload_config;
672  icmap_map_t temp_map;
673  const char *error_string;
674  int res = CS_OK;
675 
676  ENTER();
677 
678  log_printf(LOGSYS_LEVEL_NOTICE, "Config reload requested by node %d", nodeid);
679 
680  /*
681  * Set up a new hashtable as a staging area.
682  */
683  if ((res = icmap_init_r(&temp_map)) != CS_OK) {
684  log_printf(LOGSYS_LEVEL_ERROR, "Unable to create temporary icmap. config file reload cancelled\n");
685  goto reload_fini;
686  }
687 
688  /*
689  * Load new config into the temporary map
690  */
691  res = coroparse_configparse(temp_map, &error_string);
692  if (res == -1) {
693  log_printf (LOGSYS_LEVEL_ERROR, "Unable to reload config file: %s", error_string);
694  res = CS_ERR_LIBRARY;
695  goto reload_return;
696  }
697 
698  /* Tell interested listeners that we have started a reload */
699  icmap_set_uint8("config.reload_in_progress", 1);
700 
701  /* Detect deleted entries and remove them from the main icmap hashtable */
702  remove_deleted_entries(temp_map, "logging.");
703  remove_deleted_entries(temp_map, "totem.");
704  remove_deleted_entries(temp_map, "nodelist.");
705  remove_deleted_entries(temp_map, "quorum.");
706  remove_deleted_entries(temp_map, "uidgid.config.");
707 
708  /* Remove entries that cannot be changed */
709  remove_ro_entries(temp_map);
710 
711  /*
712  * Copy new keys into live config.
713  * If this fails we will have a partially loaded config because some keys (above) might
714  * have been reset to defaults - I'm not sure what to do here, we might have to quit.
715  */
716  if ( (res = icmap_copy_map(icmap_get_global_map(), temp_map)) != CS_OK) {
717  log_printf (LOGSYS_LEVEL_ERROR, "Error making new config live. cmap database may be inconsistent\n");
718  }
719 
720  /* All done - let clients know */
721  icmap_set_uint8("config.reload_in_progress", 0);
722 
723 reload_fini:
724  /* Finished with the temporary storage */
725  icmap_fini_r(temp_map);
726 
727 reload_return:
728  /* All done, return result to the caller if it was on this system */
729  if (nodeid == api->totem_nodeid_get()) {
730  res_lib_cfg_reload_config.header.size = sizeof(res_lib_cfg_reload_config);
731  res_lib_cfg_reload_config.header.id = MESSAGE_RES_CFG_RELOAD_CONFIG;
732  res_lib_cfg_reload_config.header.error = res;
733  api->ipc_response_send(req_exec_cfg_reload_config->source.conn,
734  &res_lib_cfg_reload_config,
735  sizeof(res_lib_cfg_reload_config));
736  api->ipc_refcnt_dec(req_exec_cfg_reload_config->source.conn);;
737  }
738 
739  LEAVE();
740 }
741 
742 /*
743  * Library Interface Implementation
744  */
745 static void message_handler_req_lib_cfg_ringstatusget (
746  void *conn,
747  const void *msg)
748 {
749  struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
750  struct totem_ip_address interfaces[INTERFACE_MAX];
751  unsigned int iface_count;
752  char **status;
753  const char *totem_ip_string;
754  unsigned int i;
755  cs_error_t res = CS_OK;
756 
757  ENTER();
758 
759  res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
760  res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
761 
762  api->totem_ifaces_get (
763  api->totem_nodeid_get(),
764  interfaces,
766  &status,
767  &iface_count);
768 
769  assert(iface_count <= CFG_MAX_INTERFACES);
770 
771  res_lib_cfg_ringstatusget.interface_count = iface_count;
772 
773  for (i = 0; i < iface_count; i++) {
774  totem_ip_string
775  = (const char *)api->totem_ip_print (&interfaces[i]);
776 
777  if (strlen(totem_ip_string) >= CFG_INTERFACE_NAME_MAX_LEN) {
778  log_printf(LOGSYS_LEVEL_ERROR, "String representation of interface %u is too long", i);
779  res = CS_ERR_NAME_TOO_LONG;
780  goto send_response;
781  }
782 
783  if (strlen(status[i]) >= CFG_INTERFACE_STATUS_MAX_LEN) {
784  log_printf(LOGSYS_LEVEL_ERROR, "Status string for interface %u is too long", i);
785  res = CS_ERR_NAME_TOO_LONG;
786  goto send_response;
787  }
788 
789  strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
790  status[i]);
791  strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
792  totem_ip_string);
793  }
794 
795 send_response:
796  res_lib_cfg_ringstatusget.header.error = res;
797  api->ipc_response_send (
798  conn,
799  &res_lib_cfg_ringstatusget,
800  sizeof (struct res_lib_cfg_ringstatusget));
801 
802  LEAVE();
803 }
804 
805 static void message_handler_req_lib_cfg_ringreenable (
806  void *conn,
807  const void *msg)
808 {
809  struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
810  struct iovec iovec;
811 
812  ENTER();
813  req_exec_cfg_ringreenable.header.size =
814  sizeof (struct req_exec_cfg_ringreenable);
815  req_exec_cfg_ringreenable.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
817  api->ipc_source_set (&req_exec_cfg_ringreenable.source, conn);
818  api->ipc_refcnt_inc(conn);
819 
820  iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
821  iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
822 
823  assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
824 
825  LEAVE();
826 }
827 
828 static void message_handler_req_lib_cfg_killnode (
829  void *conn,
830  const void *msg)
831 {
832  const struct req_lib_cfg_killnode *req_lib_cfg_killnode = msg;
833  struct res_lib_cfg_killnode res_lib_cfg_killnode;
834  struct req_exec_cfg_killnode req_exec_cfg_killnode;
835  struct iovec iovec;
836 
837  ENTER();
838  req_exec_cfg_killnode.header.size =
839  sizeof (struct req_exec_cfg_killnode);
840  req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
842  req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
843  marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
844 
845  iovec.iov_base = (char *)&req_exec_cfg_killnode;
846  iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
847 
848  (void)api->totem_mcast (&iovec, 1, TOTEM_SAFE);
849 
850  res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
851  res_lib_cfg_killnode.header.id = MESSAGE_RES_CFG_KILLNODE;
852  res_lib_cfg_killnode.header.error = CS_OK;
853 
854  api->ipc_response_send(conn, &res_lib_cfg_killnode,
855  sizeof(res_lib_cfg_killnode));
856 
857  LEAVE();
858 }
859 
860 
861 static void message_handler_req_lib_cfg_tryshutdown (
862  void *conn,
863  const void *msg)
864 {
865  struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
867  struct list_head *iter;
868 
869  ENTER();
870 
871  if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
872  struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
873 
874  /*
875  * Tell other nodes
876  */
877  send_shutdown();
878 
879  res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
880  res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
881  res_lib_cfg_tryshutdown.header.error = CS_OK;
882  api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
883  sizeof(res_lib_cfg_tryshutdown));
884 
885  LEAVE();
886  return;
887  }
888 
889  /*
890  * Shutdown in progress, return an error
891  */
892  if (shutdown_con) {
893  struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
894 
895  res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
896  res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
897  res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
898 
899  api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
900  sizeof(res_lib_cfg_tryshutdown));
901 
902 
903  LEAVE();
904 
905  return;
906  }
907 
908  ci->conn = conn;
909  shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
910  shutdown_flags = req_lib_cfg_tryshutdown->flags;
911  shutdown_yes = 0;
912  shutdown_no = 0;
913 
914  /*
915  * Count the number of listeners
916  */
917  shutdown_expected = 0;
918 
919  for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
920  struct cfg_info *testci = list_entry(iter, struct cfg_info, list);
921  /*
922  * It is assumed that we will allow shutdown
923  */
924  if (testci != ci) {
926  shutdown_expected++;
927  }
928  }
929 
930  /*
931  * If no-one is listening for events then we can just go down now
932  */
933  if (shutdown_expected == 0) {
934  struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
935 
936  res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
937  res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
938  res_lib_cfg_tryshutdown.header.error = CS_OK;
939 
940  /*
941  * Tell originator that shutdown was confirmed
942  */
943  api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
944  sizeof(res_lib_cfg_tryshutdown));
945 
946  send_shutdown();
947  LEAVE();
948  return;
949  }
950  else {
951  unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
952 
953  /*
954  * Look for a shutdown timeout in configuration map
955  */
956  icmap_get_uint32("cfg.shutdown_timeout", &shutdown_timeout);
957 
958  /*
959  * Start the timer. If we don't get a full set of replies before this goes
960  * off we'll cancel the shutdown
961  */
962  api->timer_add_duration((unsigned long long)shutdown_timeout*1000000000, NULL,
963  shutdown_timer_fn, &shutdown_timer);
964 
965  /*
966  * Tell the users we would like to shut down
967  */
968  send_test_shutdown(NULL, conn, CS_OK);
969  }
970 
971  /*
972  * We don't sent a reply to the caller here.
973  * We send it when we know if we can shut down or not
974  */
975 
976  LEAVE();
977 }
978 
979 static void message_handler_req_lib_cfg_replytoshutdown (
980  void *conn,
981  const void *msg)
982 {
983  struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
985  struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
986  int status = CS_OK;
987 
988  ENTER();
989  if (!shutdown_con) {
990  status = CS_ERR_ACCESS;
991  goto exit_fn;
992  }
993 
994  if (req_lib_cfg_replytoshutdown->response) {
995  shutdown_yes++;
997  }
998  else {
999  shutdown_no++;
1001  }
1002  check_shutdown_status();
1003 
1004 exit_fn:
1005  res_lib_cfg_replytoshutdown.header.error = status;
1006  res_lib_cfg_replytoshutdown.header.id = MESSAGE_RES_CFG_REPLYTOSHUTDOWN;
1007  res_lib_cfg_replytoshutdown.header.size = sizeof(res_lib_cfg_replytoshutdown);
1008 
1009  api->ipc_response_send(conn, &res_lib_cfg_replytoshutdown,
1010  sizeof(res_lib_cfg_replytoshutdown));
1011 
1012  LEAVE();
1013 }
1014 
1015 static void message_handler_req_lib_cfg_get_node_addrs (void *conn,
1016  const void *msg)
1017 {
1018  struct totem_ip_address node_ifs[INTERFACE_MAX];
1019  char buf[PIPE_BUF];
1020  char **status;
1021  unsigned int num_interfaces = 0;
1022  int ret = CS_OK;
1023  int i;
1025  struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)buf;
1026  unsigned int nodeid = req_lib_cfg_get_node_addrs->nodeid;
1027  char *addr_buf;
1028 
1029  if (nodeid == 0)
1030  nodeid = api->totem_nodeid_get();
1031 
1032  api->totem_ifaces_get(nodeid, node_ifs, INTERFACE_MAX, &status, &num_interfaces);
1033 
1034  res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
1035  res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
1036  res_lib_cfg_get_node_addrs->header.error = ret;
1037  res_lib_cfg_get_node_addrs->num_addrs = num_interfaces;
1038  if (num_interfaces) {
1039  res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
1040  for (i = 0, addr_buf = (char *)res_lib_cfg_get_node_addrs->addrs;
1041  i < num_interfaces; i++, addr_buf += TOTEMIP_ADDRLEN) {
1042  memcpy(addr_buf, node_ifs[i].addr, TOTEMIP_ADDRLEN);
1043  }
1044  } else {
1045  res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
1046  }
1047  api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
1048 }
1049 
1050 static void message_handler_req_lib_cfg_local_get (void *conn, const void *msg)
1051 {
1052  struct res_lib_cfg_local_get res_lib_cfg_local_get;
1053 
1054  res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
1055  res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
1056  res_lib_cfg_local_get.header.error = CS_OK;
1057  res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
1058 
1059  api->ipc_response_send(conn, &res_lib_cfg_local_get,
1060  sizeof(res_lib_cfg_local_get));
1061 }
1062 
1063 static void message_handler_req_lib_cfg_reload_config (void *conn, const void *msg)
1064 {
1065  struct req_exec_cfg_reload_config req_exec_cfg_reload_config;
1066  struct iovec iovec;
1067 
1068  ENTER();
1069 
1070  req_exec_cfg_reload_config.header.size =
1071  sizeof (struct req_exec_cfg_reload_config);
1072  req_exec_cfg_reload_config.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
1074  api->ipc_source_set (&req_exec_cfg_reload_config.source, conn);
1075  api->ipc_refcnt_inc(conn);
1076 
1077  iovec.iov_base = (char *)&req_exec_cfg_reload_config;
1078  iovec.iov_len = sizeof (struct req_exec_cfg_reload_config);
1079 
1080  assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
1081 
1082  LEAVE();
1083 }
void *(* ipc_private_data_get)(void *conn)
Definition: coroapi.h:256
const char * name
Definition: coroapi.h:492
unsigned short family
Definition: coroapi.h:113
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:1103
#define CFG_INTERFACE_STATUS_MAX_LEN
Definition: ipc_cfg.h:43
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:1306
The res_lib_cfg_replytoshutdown struct.
Definition: ipc_cfg.h:160
struct list_head * next
Definition: list.h:47
The res_lib_cfg_testshutdown struct.
Definition: ipc_cfg.h:167
The totem_ip_address struct.
Definition: coroapi.h:111
The corosync_service_engine struct.
Definition: coroapi.h:491
void icmap_iter_finalize(icmap_iter_t iter)
Finalize iterator.
Definition: icmap.c:1124
void(* shutdown_request)(void)
Definition: coroapi.h:430
uint8_t value[CS_MAX_NAME_LENGTH]
Definition: corotypes.h:64
int coroparse_configparse(icmap_map_t config_map, const char **error_string)
Definition: coroparse.c:251
#define corosync_fatal_error(err)
Definition: coroapi.h:425
int(* ipc_response_send)(void *conn, const void *msg, size_t mlen)
Definition: coroapi.h:258
LOGSYS_DECLARE_SUBSYS("CFG")
int icmap_key_value_eq(const icmap_map_t map1, const char *key_name1, const icmap_map_t map2, const char *key_name2)
Compare value of key with name key_name1 in map1 with key with name key_name2 in map2.
Definition: icmap.c:399
int(* totem_ifaces_get)(unsigned int nodeid, struct totem_ip_address *interfaces, unsigned int interfaces_size, char ***status, unsigned int *iface_count)
Definition: coroapi.h:284
totem_configuration_type
The totem_configuration_type enum.
Definition: coroapi.h:132
The res_lib_cfg_get_node_addrs struct.
Definition: ipc_cfg.h:183
The corosync_lib_handler struct.
Definition: coroapi.h:468
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:175
The corosync_exec_handler struct.
Definition: coroapi.h:476
void icmap_fini_r(const icmap_map_t map)
Finalize local, reentrant icmap.
Definition: icmap.c:252
icmap_map_t icmap_get_global_map(void)
Return global icmap.
Definition: icmap.c:278
int(* totem_mcast)(const struct iovec *iovec, unsigned int iov_len, unsigned int guarantee)
Definition: coroapi.h:281
Definition: list.h:46
#define log_printf(level, format, args...)
Definition: logsys.h:319
void(* exec_handler_fn)(const void *msg, unsigned int nodeid)
Definition: coroapi.h:477
void * tracker_conn
Definition: exec/cfg.c:96
struct list_head list
Definition: exec/cfg.c:94
#define SERVICE_ID_MAKE(a, b)
Definition: coroapi.h:459
#define INTERFACE_MAX
Definition: coroapi.h:88
int(* ipc_source_is_local)(const mar_message_source_t *source)
Definition: coroapi.h:254
The res_lib_cfg_local_get struct.
Definition: ipc_cfg.h:201
The res_lib_cfg_killnode struct.
Definition: ipc_cfg.h:130
#define TOTEM_SAFE
Definition: coroapi.h:103
unsigned int num_addrs
Definition: ipc_cfg.h:186
unsigned int flags
Definition: ipc_cfg.h:169
The req_lib_cfg_tryshutdown struct.
Definition: ipc_cfg.h:137
unsigned int(* totem_nodeid_get)(void)
Definition: coroapi.h:275
void(* ipc_refcnt_dec)(void *conn)
Definition: coroapi.h:270
The res_lib_cfg_ringreenable struct.
Definition: ipc_cfg.h:114
#define LOGSYS_LEVEL_ERROR
Definition: logsys.h:70
#define TRACE1(format, args...)
Definition: logsys.h:322
Linked list API.
#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:667
cs_error_t
The cs_error_t enum.
Definition: corotypes.h:94
#define LOGSYS_LEVEL_DEBUG
Definition: logsys.h:74
enum cfg_info::@5 shutdown_reply
The corosync_api_v1 struct.
Definition: coroapi.h:225
typedef __attribute__
The req_lib_cfg_replytoshutdown struct.
Definition: ipc_cfg.h:152
The res_lib_cfg_tryshutdown struct.
Definition: ipc_cfg.h:145
cs_error_t icmap_get_uint32(const char *key_name, uint32_t *u32)
Definition: icmap.c:866
#define DEFAULT_SHUTDOWN_TIMEOUT
Definition: exec/cfg.c:78
#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:293
#define ENTER
Definition: logsys.h:320
uint32_t mar_uint32_t
Definition: mar_gen.h:53
cfg_message_req_types
Definition: exec/cfg.c:71
The memb_ring_id struct.
Definition: coroapi.h:122
unsigned int flags
Definition: ipc_cfg.h:139
cs_error_t icmap_delete_r(const icmap_map_t map, const char *key_name)
icmap_delete_r
Definition: icmap.c:647
The res_lib_cfg_ringstatusget struct.
Definition: ipc_cfg.h:97
cs_error_t icmap_init_r(icmap_map_t *result)
Initialize additional (local, reentrant) icmap_map.
Definition: icmap.c:203
qb_loop_timer_handle corosync_timer_handle_t
corosync_timer_handle_t
Definition: coroapi.h:74
void * conn
Definition: exec/cfg.c:95
struct corosync_service_engine cfg_service_engine
Definition: exec/cfg.c:224
#define list_entry(ptr, type, member)
Definition: list.h:84
int(* totem_ring_reenable)(void)
Definition: coroapi.h:279
The res_lib_cfg_reload_config struct.
Definition: ipc_cfg.h:216
#define LOGSYS_LEVEL_NOTICE
Definition: logsys.h:72
cs_error_t icmap_set_uint8(const char *key_name, uint8_t value)
Definition: icmap.c:587
void(* lib_handler_fn)(void *conn, const void *msg)
Definition: coroapi.h:469
struct corosync_service_engine * cfg_get_service_engine_ver0(void)
Definition: exec/cfg.c:241
int(* ipc_dispatch_send)(void *conn, const void *msg, size_t mlen)
Definition: coroapi.h:263
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:1092
icmap_iter_t icmap_iter_init(const char *prefix)
Initialize iterator with given prefix.
Definition: icmap.c:1097
struct memb_ring_id ring_id
Definition: totemsrp.c:64
void(* ipc_source_set)(mar_message_source_t *source, void *conn)
Definition: coroapi.h:252
The req_lib_cfg_killnode struct.
Definition: ipc_cfg.h:121
#define LEAVE
Definition: logsys.h:321
qb_map_iter_t * icmap_iter_t
Itterator type.
Definition: icmap.h:123
The cs_name_t struct.
Definition: corotypes.h:62
The mar_message_source_t struct.
Definition: coroapi.h:50
void(* ipc_refcnt_inc)(void *conn)
Definition: coroapi.h:268