corosync  2.3.5
main.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2006 MontaVista Software, Inc.
3  * Copyright (c) 2006-2012 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 
72 #include <config.h>
73 
74 #include <pthread.h>
75 #include <assert.h>
76 #include <sys/types.h>
77 #include <sys/file.h>
78 #include <sys/poll.h>
79 #include <sys/uio.h>
80 #include <sys/mman.h>
81 #include <sys/socket.h>
82 #include <sys/un.h>
83 #include <sys/time.h>
84 #include <sys/resource.h>
85 #include <sys/stat.h>
86 #include <netinet/in.h>
87 #include <arpa/inet.h>
88 #include <unistd.h>
89 #include <fcntl.h>
90 #include <stdlib.h>
91 #include <stdio.h>
92 #include <errno.h>
93 #include <signal.h>
94 #include <sched.h>
95 #include <time.h>
96 #include <semaphore.h>
97 
98 #ifdef HAVE_LIBSYSTEMD
99 #include <systemd/sd-daemon.h>
100 #endif
101 
102 #include <qb/qbdefs.h>
103 #include <qb/qblog.h>
104 #include <qb/qbloop.h>
105 #include <qb/qbutil.h>
106 #include <qb/qbipcs.h>
107 
108 #include <corosync/swab.h>
109 #include <corosync/corotypes.h>
110 #include <corosync/corodefs.h>
111 #include <corosync/list.h>
112 #include <corosync/totem/totempg.h>
113 #include <corosync/logsys.h>
114 #include <corosync/icmap.h>
115 
116 #include "quorum.h"
117 #include "totemsrp.h"
118 #include "logconfig.h"
119 #include "totemconfig.h"
120 #include "main.h"
121 #include "sync.h"
122 #include "timer.h"
123 #include "util.h"
124 #include "apidef.h"
125 #include "service.h"
126 #include "schedwrk.h"
127 
128 #ifdef HAVE_SMALL_MEMORY_FOOTPRINT
129 #define IPC_LOGSYS_SIZE 1024*64
130 #else
131 #define IPC_LOGSYS_SIZE 8192*128
132 #endif
133 
134 LOGSYS_DECLARE_SYSTEM ("corosync",
136  LOG_DAEMON,
137  LOG_INFO);
138 
139 LOGSYS_DECLARE_SUBSYS ("MAIN");
140 
141 #define SERVER_BACKLOG 5
142 
143 static int sched_priority = 0;
144 
145 static unsigned int service_count = 32;
146 
148 
149 static struct corosync_api_v1 *api = NULL;
150 
151 static int sync_in_process = 1;
152 
153 static qb_loop_t *corosync_poll_handle;
154 
155 struct sched_param global_sched_param;
156 
157 static corosync_timer_handle_t corosync_stats_timer_handle;
158 
159 static const char *corosync_lock_file = LOCALSTATEDIR"/run/corosync.pid";
160 
161 static int ip_version = AF_INET;
162 
163 qb_loop_t *cs_poll_handle_get (void)
164 {
165  return (corosync_poll_handle);
166 }
167 
168 int cs_poll_dispatch_add (qb_loop_t * handle,
169  int fd,
170  int events,
171  void *data,
172 
173  int (*dispatch_fn) (int fd,
174  int revents,
175  void *data))
176 {
177  return qb_loop_poll_add(handle, QB_LOOP_MED, fd, events, data,
178  dispatch_fn);
179 }
180 
181 int cs_poll_dispatch_delete(qb_loop_t * handle, int fd)
182 {
183  return qb_loop_poll_del(handle, fd);
184 }
185 
187 {
188  int i;
189 
190  for (i = 0; i < SERVICES_COUNT_MAX; i++) {
191  if (corosync_service[i] && corosync_service[i]->exec_dump_fn) {
193  }
194  }
195 }
196 
197 static void corosync_blackbox_write_to_file (void)
198 {
199  char fname[PATH_MAX];
200  char fdata_fname[PATH_MAX];
201  char time_str[PATH_MAX];
202  struct tm cur_time_tm;
203  time_t cur_time_t;
204  ssize_t res;
205 
206  cur_time_t = time(NULL);
207  localtime_r(&cur_time_t, &cur_time_tm);
208 
209  strftime(time_str, PATH_MAX, "%Y-%m-%dT%H:%M:%S", &cur_time_tm);
210  snprintf(fname, PATH_MAX, "%s/fdata-%s-%lld",
211  get_run_dir(),
212  time_str,
213  (long long int)getpid());
214 
215  if ((res = qb_log_blackbox_write_to_file(fname)) < 0) {
216  LOGSYS_PERROR(-res, LOGSYS_LEVEL_ERROR, "Can't store blackbox file");
217  }
218  snprintf(fdata_fname, sizeof(fdata_fname), "%s/fdata", get_run_dir());
219  unlink(fdata_fname);
220  if (symlink(fname, fdata_fname) == -1) {
221  log_printf(LOGSYS_LEVEL_ERROR, "Can't create symlink to '%s' for corosync blackbox file '%s'",
222  fname, fdata_fname);
223  }
224 }
225 
226 static void unlink_all_completed (void)
227 {
228  api->timer_delete (corosync_stats_timer_handle);
229  qb_loop_stop (corosync_poll_handle);
230  icmap_fini();
231 }
232 
234 {
235  corosync_service_unlink_all (api, unlink_all_completed);
236 }
237 
238 static int32_t sig_diag_handler (int num, void *data)
239 {
241  return 0;
242 }
243 
244 static int32_t sig_exit_handler (int num, void *data)
245 {
246  log_printf(LOGSYS_LEVEL_NOTICE, "Node was shut down by a signal");
247  corosync_service_unlink_all (api, unlink_all_completed);
248  return 0;
249 }
250 
251 static void sigsegv_handler (int num)
252 {
253  (void)signal (SIGSEGV, SIG_DFL);
254  corosync_blackbox_write_to_file ();
255  qb_log_fini();
256  raise (SIGSEGV);
257 }
258 
259 /*
260  * QB wrapper for real signal handler
261  */
262 static int32_t sig_segv_handler (int num, void *data)
263 {
264 
265  sigsegv_handler(num);
266 
267  return 0;
268 }
269 
270 static void sigabrt_handler (int num)
271 {
272  (void)signal (SIGABRT, SIG_DFL);
273  corosync_blackbox_write_to_file ();
274  qb_log_fini();
275  raise (SIGABRT);
276 }
277 
278 /*
279  * QB wrapper for real signal handler
280  */
281 static int32_t sig_abrt_handler (int num, void *data)
282 {
283 
284  sigabrt_handler(num);
285 
286  return 0;
287 }
288 
289 #define LOCALHOST_IP inet_addr("127.0.0.1")
290 
291 static void *corosync_group_handle;
292 
293 static struct totempg_group corosync_group = {
294  .group = "a",
295  .group_len = 1
296 };
297 
298 static void serialize_lock (void)
299 {
300 }
301 
302 static void serialize_unlock (void)
303 {
304 }
305 
306 static void corosync_sync_completed (void)
307 {
309  "Completed service synchronization, ready to provide service.");
310  sync_in_process = 0;
311 
312  cs_ipcs_sync_state_changed(sync_in_process);
314  /*
315  * Inform totem to start using new message queue again
316  */
318 
319 #ifdef HAVE_LIBSYSTEMD
320  sd_notify (0, "READY=1");
321 #endif
322 }
323 
324 static int corosync_sync_callbacks_retrieve (
325  int service_id,
326  struct sync_callbacks *callbacks)
327 {
328  if (corosync_service[service_id] == NULL) {
329  return (-1);
330  }
331 
332  if (callbacks == NULL) {
333  return (0);
334  }
335 
336  callbacks->name = corosync_service[service_id]->name;
337 
338  callbacks->sync_init = corosync_service[service_id]->sync_init;
339  callbacks->sync_process = corosync_service[service_id]->sync_process;
340  callbacks->sync_activate = corosync_service[service_id]->sync_activate;
341  callbacks->sync_abort = corosync_service[service_id]->sync_abort;
342  return (0);
343 }
344 
345 static struct memb_ring_id corosync_ring_id;
346 
347 static void member_object_joined (unsigned int nodeid)
348 {
349  char member_ip[ICMAP_KEYNAME_MAXLEN];
350  char member_join_count[ICMAP_KEYNAME_MAXLEN];
351  char member_status[ICMAP_KEYNAME_MAXLEN];
352 
353  snprintf(member_ip, ICMAP_KEYNAME_MAXLEN,
354  "runtime.totem.pg.mrp.srp.members.%u.ip", nodeid);
355  snprintf(member_join_count, ICMAP_KEYNAME_MAXLEN,
356  "runtime.totem.pg.mrp.srp.members.%u.join_count", nodeid);
357  snprintf(member_status, ICMAP_KEYNAME_MAXLEN,
358  "runtime.totem.pg.mrp.srp.members.%u.status", nodeid);
359 
360  if (icmap_get(member_ip, NULL, NULL, NULL) == CS_OK) {
361  icmap_inc(member_join_count);
362  icmap_set_string(member_status, "joined");
363  } else {
364  icmap_set_string(member_ip, (char*)api->totem_ifaces_print (nodeid));
365  icmap_set_uint32(member_join_count, 1);
366  icmap_set_string(member_status, "joined");
367  }
368 
370  "Member joined: %s", api->totem_ifaces_print (nodeid));
371 }
372 
373 static void member_object_left (unsigned int nodeid)
374 {
375  char member_status[ICMAP_KEYNAME_MAXLEN];
376 
377  snprintf(member_status, ICMAP_KEYNAME_MAXLEN,
378  "runtime.totem.pg.mrp.srp.members.%u.status", nodeid);
379  icmap_set_string(member_status, "left");
380 
382  "Member left: %s", api->totem_ifaces_print (nodeid));
383 }
384 
385 static void confchg_fn (
386  enum totem_configuration_type configuration_type,
387  const unsigned int *member_list, size_t member_list_entries,
388  const unsigned int *left_list, size_t left_list_entries,
389  const unsigned int *joined_list, size_t joined_list_entries,
390  const struct memb_ring_id *ring_id)
391 {
392  int i;
393  int abort_activate = 0;
394 
395  if (sync_in_process == 1) {
396  abort_activate = 1;
397  }
398  sync_in_process = 1;
399  cs_ipcs_sync_state_changed(sync_in_process);
400  memcpy (&corosync_ring_id, ring_id, sizeof (struct memb_ring_id));
401 
402  for (i = 0; i < left_list_entries; i++) {
403  member_object_left (left_list[i]);
404  }
405  for (i = 0; i < joined_list_entries; i++) {
406  member_object_joined (joined_list[i]);
407  }
408  /*
409  * Call configuration change for all services
410  */
411  for (i = 0; i < service_count; i++) {
412  if (corosync_service[i] && corosync_service[i]->confchg_fn) {
413  corosync_service[i]->confchg_fn (configuration_type,
414  member_list, member_list_entries,
415  left_list, left_list_entries,
416  joined_list, joined_list_entries, ring_id);
417  }
418  }
419 
420  if (abort_activate) {
421  sync_abort ();
422  }
423  if (configuration_type == TOTEM_CONFIGURATION_TRANSITIONAL) {
424  sync_save_transitional (member_list, member_list_entries, ring_id);
425  }
426  if (configuration_type == TOTEM_CONFIGURATION_REGULAR) {
427  sync_start (member_list, member_list_entries, ring_id);
428  }
429 }
430 
431 static void priv_drop (void)
432 {
433  return; /* TODO: we are still not dropping privs */
434 }
435 
436 static void corosync_tty_detach (void)
437 {
438  int devnull;
439 
440  /*
441  * Disconnect from TTY if this is not a debug run
442  */
443 
444  switch (fork ()) {
445  case -1:
447  break;
448  case 0:
449  /*
450  * child which is disconnected, run this process
451  */
452  break;
453  default:
454  exit (0);
455  break;
456  }
457 
458  /* Create new session */
459  (void)setsid();
460 
461  /*
462  * Map stdin/out/err to /dev/null.
463  */
464  devnull = open("/dev/null", O_RDWR);
465  if (devnull == -1) {
467  }
468 
469  if (dup2(devnull, 0) < 0 || dup2(devnull, 1) < 0
470  || dup2(devnull, 2) < 0) {
471  close(devnull);
473  }
474  close(devnull);
475 }
476 
477 static void corosync_mlockall (void)
478 {
479  int res;
480  struct rlimit rlimit;
481 
482  rlimit.rlim_cur = RLIM_INFINITY;
483  rlimit.rlim_max = RLIM_INFINITY;
484 
485 #ifndef RLIMIT_MEMLOCK
486 #define RLIMIT_MEMLOCK RLIMIT_VMEM
487 #endif
488 
489  setrlimit (RLIMIT_MEMLOCK, &rlimit);
490 
491  res = mlockall (MCL_CURRENT | MCL_FUTURE);
492  if (res == -1) {
494  "Could not lock memory of service to avoid page faults");
495  };
496 }
497 
498 
499 static void corosync_totem_stats_updater (void *data)
500 {
501  totempg_stats_t * stats;
502  uint32_t total_mtt_rx_token;
503  uint32_t total_backlog_calc;
504  uint32_t total_token_holdtime;
505  int t, prev, i;
506  int32_t token_count;
507  char key_name[ICMAP_KEYNAME_MAXLEN];
508 
509  stats = api->totem_get_stats();
510 
511  icmap_set_uint32("runtime.totem.pg.msg_reserved", stats->msg_reserved);
512  icmap_set_uint32("runtime.totem.pg.msg_queue_avail", stats->msg_queue_avail);
513  icmap_set_uint64("runtime.totem.pg.mrp.srp.orf_token_tx", stats->mrp->srp->orf_token_tx);
514  icmap_set_uint64("runtime.totem.pg.mrp.srp.orf_token_rx", stats->mrp->srp->orf_token_rx);
515  icmap_set_uint64("runtime.totem.pg.mrp.srp.memb_merge_detect_tx", stats->mrp->srp->memb_merge_detect_tx);
516  icmap_set_uint64("runtime.totem.pg.mrp.srp.memb_merge_detect_rx", stats->mrp->srp->memb_merge_detect_rx);
517  icmap_set_uint64("runtime.totem.pg.mrp.srp.memb_join_tx", stats->mrp->srp->memb_join_tx);
518  icmap_set_uint64("runtime.totem.pg.mrp.srp.memb_join_rx", stats->mrp->srp->memb_join_rx);
519  icmap_set_uint64("runtime.totem.pg.mrp.srp.mcast_tx", stats->mrp->srp->mcast_tx);
520  icmap_set_uint64("runtime.totem.pg.mrp.srp.mcast_retx", stats->mrp->srp->mcast_retx);
521  icmap_set_uint64("runtime.totem.pg.mrp.srp.mcast_rx", stats->mrp->srp->mcast_rx);
522  icmap_set_uint64("runtime.totem.pg.mrp.srp.memb_commit_token_tx", stats->mrp->srp->memb_commit_token_tx);
523  icmap_set_uint64("runtime.totem.pg.mrp.srp.memb_commit_token_rx", stats->mrp->srp->memb_commit_token_rx);
524  icmap_set_uint64("runtime.totem.pg.mrp.srp.token_hold_cancel_tx", stats->mrp->srp->token_hold_cancel_tx);
525  icmap_set_uint64("runtime.totem.pg.mrp.srp.token_hold_cancel_rx", stats->mrp->srp->token_hold_cancel_rx);
526  icmap_set_uint64("runtime.totem.pg.mrp.srp.operational_entered", stats->mrp->srp->operational_entered);
527  icmap_set_uint64("runtime.totem.pg.mrp.srp.operational_token_lost", stats->mrp->srp->operational_token_lost);
528  icmap_set_uint64("runtime.totem.pg.mrp.srp.gather_entered", stats->mrp->srp->gather_entered);
529  icmap_set_uint64("runtime.totem.pg.mrp.srp.gather_token_lost", stats->mrp->srp->gather_token_lost);
530  icmap_set_uint64("runtime.totem.pg.mrp.srp.commit_entered", stats->mrp->srp->commit_entered);
531  icmap_set_uint64("runtime.totem.pg.mrp.srp.commit_token_lost", stats->mrp->srp->commit_token_lost);
532  icmap_set_uint64("runtime.totem.pg.mrp.srp.recovery_entered", stats->mrp->srp->recovery_entered);
533  icmap_set_uint64("runtime.totem.pg.mrp.srp.recovery_token_lost", stats->mrp->srp->recovery_token_lost);
534  icmap_set_uint64("runtime.totem.pg.mrp.srp.consensus_timeouts", stats->mrp->srp->consensus_timeouts);
535  icmap_set_uint64("runtime.totem.pg.mrp.srp.rx_msg_dropped", stats->mrp->srp->rx_msg_dropped);
536  icmap_set_uint32("runtime.totem.pg.mrp.srp.continuous_gather", stats->mrp->srp->continuous_gather);
537  icmap_set_uint32("runtime.totem.pg.mrp.srp.continuous_sendmsg_failures",
539 
540  icmap_set_uint8("runtime.totem.pg.mrp.srp.firewall_enabled_or_nic_failure",
541  stats->mrp->srp->continuous_gather > MAX_NO_CONT_GATHER ? 1 : 0);
542 
543  if (stats->mrp->srp->continuous_gather > MAX_NO_CONT_GATHER ||
546  "Totem is unable to form a cluster because of an "
547  "operating system or network fault. The most common "
548  "cause of this message is that the local firewall is "
549  "configured improperly.");
550  icmap_set_uint8("runtime.totem.pg.mrp.srp.firewall_enabled_or_nic_failure", 1);
551  } else {
552  icmap_set_uint8("runtime.totem.pg.mrp.srp.firewall_enabled_or_nic_failure", 0);
553  }
554 
555  for (i = 0; i < stats->mrp->srp->rrp->interface_count; i++) {
556  snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "runtime.totem.pg.mrp.rrp.%u.faulty", i);
557  icmap_set_uint8(key_name, stats->mrp->srp->rrp->faulty[i]);
558  }
559  total_mtt_rx_token = 0;
560  total_token_holdtime = 0;
561  total_backlog_calc = 0;
562  token_count = 0;
563  t = stats->mrp->srp->latest_token;
564  while (1) {
565  if (t == 0)
566  prev = TOTEM_TOKEN_STATS_MAX - 1;
567  else
568  prev = t - 1;
569  if (prev == stats->mrp->srp->earliest_token)
570  break;
571  /* if tx == 0, then dropped token (not ours) */
572  if (stats->mrp->srp->token[t].tx != 0 ||
573  (stats->mrp->srp->token[t].rx - stats->mrp->srp->token[prev].rx) > 0 ) {
574  total_mtt_rx_token += (stats->mrp->srp->token[t].rx - stats->mrp->srp->token[prev].rx);
575  total_token_holdtime += (stats->mrp->srp->token[t].tx - stats->mrp->srp->token[t].rx);
576  total_backlog_calc += stats->mrp->srp->token[t].backlog_calc;
577  token_count++;
578  }
579  t = prev;
580  }
581  if (token_count) {
582  icmap_set_uint32("runtime.totem.pg.mrp.srp.mtt_rx_token", (total_mtt_rx_token / token_count));
583  icmap_set_uint32("runtime.totem.pg.mrp.srp.avg_token_workload", (total_token_holdtime / token_count));
584  icmap_set_uint32("runtime.totem.pg.mrp.srp.avg_backlog_calc", (total_backlog_calc / token_count));
585  }
586 
588 
589  api->timer_add_duration (1500 * MILLI_2_NANO_SECONDS, NULL,
590  corosync_totem_stats_updater,
591  &corosync_stats_timer_handle);
592 }
593 
594 static void corosync_totem_stats_init (void)
595 {
596  icmap_set_uint32("runtime.totem.pg.mrp.srp.mtt_rx_token", 0);
597  icmap_set_uint32("runtime.totem.pg.mrp.srp.avg_token_workload", 0);
598  icmap_set_uint32("runtime.totem.pg.mrp.srp.avg_backlog_calc", 0);
599 
600  /* start stats timer */
601  api->timer_add_duration (1500 * MILLI_2_NANO_SECONDS, NULL,
602  corosync_totem_stats_updater,
603  &corosync_stats_timer_handle);
604 }
605 
606 static void deliver_fn (
607  unsigned int nodeid,
608  const void *msg,
609  unsigned int msg_len,
610  int endian_conversion_required)
611 {
612  const struct qb_ipc_request_header *header;
613  int32_t service;
614  int32_t fn_id;
615  uint32_t id;
616 
617  header = msg;
618  if (endian_conversion_required) {
619  id = swab32 (header->id);
620  } else {
621  id = header->id;
622  }
623 
624  /*
625  * Call the proper executive handler
626  */
627  service = id >> 16;
628  fn_id = id & 0xffff;
629 
630  if (!corosync_service[service]) {
631  return;
632  }
633  if (fn_id >= corosync_service[service]->exec_engine_count) {
634  log_printf(LOGSYS_LEVEL_WARNING, "discarded unknown message %d for service %d (max id %d)",
635  fn_id, service, corosync_service[service]->exec_engine_count);
636  return;
637  }
638 
639  icmap_fast_inc(service_stats_rx[service][fn_id]);
640 
641  if (endian_conversion_required) {
642  assert(corosync_service[service]->exec_engine[fn_id].exec_endian_convert_fn != NULL);
644  ((void *)msg);
645  }
646 
648  (msg, nodeid);
649 }
650 
652  const struct iovec *iovec,
653  unsigned int iov_len,
654  unsigned int guarantee)
655 {
656  const struct qb_ipc_request_header *req = iovec->iov_base;
657  int32_t service;
658  int32_t fn_id;
659 
660  service = req->id >> 16;
661  fn_id = req->id & 0xffff;
662 
663  if (corosync_service[service]) {
664  icmap_fast_inc(service_stats_tx[service][fn_id]);
665  }
666 
667  return (totempg_groups_mcast_joined (corosync_group_handle, iovec, iov_len, guarantee));
668 }
669 
670 static void corosync_ring_id_create_or_load (
671  struct memb_ring_id *memb_ring_id,
672  const struct totem_ip_address *addr)
673 {
674  int fd;
675  int res = 0;
676  char filename[PATH_MAX];
677 
678  snprintf (filename, sizeof(filename), "%s/ringid_%s",
679  get_run_dir(), totemip_print (addr));
680  fd = open (filename, O_RDONLY, 0700);
681  /*
682  * If file can be opened and read, read the ring id
683  */
684  if (fd != -1) {
685  res = read (fd, &memb_ring_id->seq, sizeof (uint64_t));
686  close (fd);
687  }
688  /*
689  * If file could not be opened or read, create a new ring id
690  */
691  if ((fd == -1) || (res != sizeof (uint64_t))) {
692  memb_ring_id->seq = 0;
693  umask(0);
694  fd = open (filename, O_CREAT|O_RDWR, 0700);
695  if (fd != -1) {
696  res = write (fd, &memb_ring_id->seq, sizeof (uint64_t));
697  close (fd);
698  if (res == -1) {
700  "Couldn't write ringid file '%s'", filename);
701 
703  }
704  } else {
706  "Couldn't create ringid file '%s'", filename);
707 
709  }
710  }
711 
712  totemip_copy(&memb_ring_id->rep, addr);
713  assert (!totemip_zero_check(&memb_ring_id->rep));
714 }
715 
716 static void corosync_ring_id_store (
717  const struct memb_ring_id *memb_ring_id,
718  const struct totem_ip_address *addr)
719 {
720  char filename[PATH_MAX];
721  int fd;
722  int res;
723 
724  snprintf (filename, sizeof(filename), "%s/ringid_%s",
725  get_run_dir(), totemip_print (addr));
726 
727  fd = open (filename, O_WRONLY, 0700);
728  if (fd == -1) {
729  fd = open (filename, O_CREAT|O_RDWR, 0700);
730  }
731  if (fd == -1) {
733  "Couldn't store new ring id %llx to stable storage",
734  memb_ring_id->seq);
735 
737  }
739  "Storing new sequence id for ring %llx", memb_ring_id->seq);
740  res = write (fd, &memb_ring_id->seq, sizeof(memb_ring_id->seq));
741  close (fd);
742  if (res != sizeof(memb_ring_id->seq)) {
744  "Couldn't store new ring id %llx to stable storage",
745  memb_ring_id->seq);
746 
748  }
749 }
750 
751 static qb_loop_timer_handle recheck_the_q_level_timer;
753 {
754  totempg_check_q_level(corosync_group_handle);
756  qb_loop_timer_add(cs_poll_handle_get(), QB_LOOP_MED, 1*QB_TIME_NS_IN_MSEC,
757  NULL, corosync_recheck_the_q_level, &recheck_the_q_level_timer);
758  }
759 }
760 
763 };
764 
765 
767  unsigned int service,
768  unsigned int id,
769  const void *msg,
770  void *sending_allowed_private_data)
771 {
773  (struct sending_allowed_private_data_struct *)sending_allowed_private_data;
774  struct iovec reserve_iovec;
775  struct qb_ipc_request_header *header = (struct qb_ipc_request_header *)msg;
776  int sending_allowed;
777 
778  reserve_iovec.iov_base = (char *)header;
779  reserve_iovec.iov_len = header->size;
780 
782  corosync_group_handle,
783  &reserve_iovec, 1);
784  if (pd->reserved_msgs == -1) {
785  return -EINVAL;
786  }
787 
788  sending_allowed = QB_FALSE;
789  if (corosync_quorum_is_quorate() == 1 ||
790  corosync_service[service]->allow_inquorate == CS_LIB_ALLOW_INQUORATE) {
791  // we are quorate
792  // now check flow control
793  if (corosync_service[service]->lib_engine[id].flow_control == CS_LIB_FLOW_CONTROL_NOT_REQUIRED) {
794  sending_allowed = QB_TRUE;
795  } else if (pd->reserved_msgs && sync_in_process == 0) {
796  sending_allowed = QB_TRUE;
797  } else if (pd->reserved_msgs == 0) {
798  return -ENOBUFS;
799  } else /* (sync_in_process) */ {
800  return -EINPROGRESS;
801  }
802  } else {
803  return -EHOSTUNREACH;
804  }
805 
806  return (sending_allowed);
807 }
808 
809 void corosync_sending_allowed_release (void *sending_allowed_private_data)
810 {
812  (struct sending_allowed_private_data_struct *)sending_allowed_private_data;
813 
814  if (pd->reserved_msgs == -1) {
815  return;
816  }
818 }
819 
821 {
822  int ret = 0;
823 
824  assert (source != NULL);
825  if (source->nodeid == totempg_my_nodeid_get ()) {
826  ret = 1;
827  }
828  return ret;
829 }
830 
832  mar_message_source_t *source,
833  void *conn)
834 {
835  assert ((source != NULL) && (conn != NULL));
836  memset (source, 0, sizeof (mar_message_source_t));
837  source->nodeid = totempg_my_nodeid_get ();
838  source->conn = conn;
839 }
840 
843  qb_loop_timer_handle handle;
844  unsigned long long tv_prev;
845  unsigned long long max_tv_diff;
846 };
847 
848 static void timer_function_scheduler_timeout (void *data)
849 {
850  struct scheduler_pause_timeout_data *timeout_data = (struct scheduler_pause_timeout_data *)data;
851  unsigned long long tv_current;
852  unsigned long long tv_diff;
853 
854  tv_current = qb_util_nano_current_get ();
855 
856  if (timeout_data->tv_prev == 0) {
857  /*
858  * Initial call -> just pretent everything is ok
859  */
860  timeout_data->tv_prev = tv_current;
861  timeout_data->max_tv_diff = 0;
862  }
863 
864  tv_diff = tv_current - timeout_data->tv_prev;
865  timeout_data->tv_prev = tv_current;
866 
867  if (tv_diff > timeout_data->max_tv_diff) {
868  log_printf (LOGSYS_LEVEL_WARNING, "Corosync main process was not scheduled for %0.4f ms "
869  "(threshold is %0.4f ms). Consider token timeout increase.",
870  (float)tv_diff / QB_TIME_NS_IN_MSEC, (float)timeout_data->max_tv_diff / QB_TIME_NS_IN_MSEC);
871  }
872 
873  /*
874  * Set next threshold, because token_timeout can change
875  */
876  timeout_data->max_tv_diff = timeout_data->totem_config->token_timeout * QB_TIME_NS_IN_MSEC * 0.8;
877  qb_loop_timer_add (corosync_poll_handle,
878  QB_LOOP_MED,
879  timeout_data->totem_config->token_timeout * QB_TIME_NS_IN_MSEC / 3,
880  timeout_data,
881  timer_function_scheduler_timeout,
882  &timeout_data->handle);
883 }
884 
885 
886 static void corosync_setscheduler (void)
887 {
888 #if defined(HAVE_PTHREAD_SETSCHEDPARAM) && defined(HAVE_SCHED_GET_PRIORITY_MAX) && defined(HAVE_SCHED_SETSCHEDULER)
889  int res;
890 
891  sched_priority = sched_get_priority_max (SCHED_RR);
892  if (sched_priority != -1) {
893  global_sched_param.sched_priority = sched_priority;
894  res = sched_setscheduler (0, SCHED_RR, &global_sched_param);
895  if (res == -1) {
897  "Could not set SCHED_RR at priority %d",
898  global_sched_param.sched_priority);
899 
900  global_sched_param.sched_priority = 0;
901 #ifdef HAVE_QB_LOG_THREAD_PRIORITY_SET
902  qb_log_thread_priority_set (SCHED_OTHER, 0);
903 #endif
904  } else {
905 
906  /*
907  * Turn on SCHED_RR in logsys system
908  */
909 #ifdef HAVE_QB_LOG_THREAD_PRIORITY_SET
910  res = qb_log_thread_priority_set (SCHED_RR, sched_priority);
911 #else
912  res = -1;
913 #endif
914  if (res == -1) {
916  "Could not set logsys thread priority."
917  " Can't continue because of priority inversions.");
919  }
920  }
921  } else {
923  "Could not get maximum scheduler priority");
924  sched_priority = 0;
925  }
926 #else
928  "The Platform is missing process priority setting features. Leaving at default.");
929 #endif
930 }
931 
932 static void
933 _logsys_log_printf(int level, int subsys,
934  const char *function_name,
935  const char *file_name,
936  int file_line,
937  const char *format,
938  ...) __attribute__((format(printf, 6, 7)));
939 
940 static void
941 _logsys_log_printf(int level, int subsys,
942  const char *function_name,
943  const char *file_name,
944  int file_line,
945  const char *format, ...)
946 {
947  va_list ap;
948 
949  va_start(ap, format);
950  qb_log_from_external_source_va(function_name, file_name,
951  format, level, file_line,
952  subsys, ap);
953  va_end(ap);
954 }
955 
956 static void fplay_key_change_notify_fn (
957  int32_t event,
958  const char *key_name,
959  struct icmap_notify_value new_val,
960  struct icmap_notify_value old_val,
961  void *user_data)
962 {
963  if (strcmp(key_name, "runtime.blackbox.dump_flight_data") == 0) {
964  fprintf(stderr,"Writetofile\n");
965  corosync_blackbox_write_to_file ();
966  }
967  if (strcmp(key_name, "runtime.blackbox.dump_state") == 0) {
968  fprintf(stderr,"statefump\n");
970  }
971 }
972 
973 static void corosync_fplay_control_init (void)
974 {
975  icmap_track_t track = NULL;
976 
977  icmap_set_string("runtime.blackbox.dump_flight_data", "no");
978  icmap_set_string("runtime.blackbox.dump_state", "no");
979 
980  icmap_track_add("runtime.blackbox.dump_flight_data",
982  fplay_key_change_notify_fn,
983  NULL, &track);
984  icmap_track_add("runtime.blackbox.dump_state",
986  fplay_key_change_notify_fn,
987  NULL, &track);
988 }
989 
990 /*
991  * Set RO flag for keys, which ether doesn't make sense to change by user (statistic)
992  * or which when changed are not reflected by runtime (totem.crypto_cipher, ...).
993  *
994  * Also some RO keys cannot be determined in this stage, so they are set later in
995  * other functions (like nodelist.local_node_pos, ...)
996  */
997 static void set_icmap_ro_keys_flag (void)
998 {
999  /*
1000  * Set RO flag for all keys of internal configuration and runtime statistics
1001  */
1002  icmap_set_ro_access("internal_configuration.", CS_TRUE, CS_TRUE);
1003  icmap_set_ro_access("runtime.connections.", CS_TRUE, CS_TRUE);
1004  icmap_set_ro_access("runtime.totem.", CS_TRUE, CS_TRUE);
1005  icmap_set_ro_access("runtime.services.", CS_TRUE, CS_TRUE);
1006  icmap_set_ro_access("runtime.config.", CS_TRUE, CS_TRUE);
1007 
1008  /*
1009  * Set RO flag for constrete keys of configuration which can't be changed
1010  * during runtime
1011  */
1012  icmap_set_ro_access("totem.crypto_cipher", CS_FALSE, CS_TRUE);
1013  icmap_set_ro_access("totem.crypto_hash", CS_FALSE, CS_TRUE);
1014  icmap_set_ro_access("totem.secauth", CS_FALSE, CS_TRUE);
1015  icmap_set_ro_access("totem.ip_version", CS_FALSE, CS_TRUE);
1016  icmap_set_ro_access("totem.rrp_mode", CS_FALSE, CS_TRUE);
1017  icmap_set_ro_access("totem.netmtu", CS_FALSE, CS_TRUE);
1018  icmap_set_ro_access("qb.ipc_type", CS_FALSE, CS_TRUE);
1019  icmap_set_ro_access("config.reload_in_progress", CS_FALSE, CS_TRUE);
1020  icmap_set_ro_access("config.totemconfig_reload_in_progress", CS_FALSE, CS_TRUE);
1021 }
1022 
1023 static void main_service_ready (void)
1024 {
1025  int res;
1026 
1027  /*
1028  * This must occur after totempg is initialized because "this_ip" must be set
1029  */
1031  if (res == -1) {
1032  log_printf (LOGSYS_LEVEL_ERROR, "Could not initialize default services");
1034  }
1035  cs_ipcs_init();
1036  corosync_totem_stats_init ();
1037  corosync_fplay_control_init ();
1038  sync_init (
1039  corosync_sync_callbacks_retrieve,
1040  corosync_sync_completed);
1041 }
1042 
1043 static enum e_corosync_done corosync_flock (const char *lockfile, pid_t pid)
1044 {
1045  struct flock lock;
1046  enum e_corosync_done err;
1047  char pid_s[17];
1048  int fd_flag;
1049  int lf;
1050 
1051  err = COROSYNC_DONE_EXIT;
1052 
1053  lf = open (lockfile, O_WRONLY | O_CREAT, 0640);
1054  if (lf == -1) {
1055  log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't create lock file.");
1056  return (COROSYNC_DONE_AQUIRE_LOCK);
1057  }
1058 
1059 retry_fcntl:
1060  lock.l_type = F_WRLCK;
1061  lock.l_start = 0;
1062  lock.l_whence = SEEK_SET;
1063  lock.l_len = 0;
1064  if (fcntl (lf, F_SETLK, &lock) == -1) {
1065  switch (errno) {
1066  case EINTR:
1067  goto retry_fcntl;
1068  break;
1069  case EAGAIN:
1070  case EACCES:
1071  log_printf (LOGSYS_LEVEL_ERROR, "Another Corosync instance is already running.");
1073  goto error_close;
1074  break;
1075  default:
1076  log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't aquire lock. Error was %s",
1077  strerror(errno));
1079  goto error_close;
1080  break;
1081  }
1082  }
1083 
1084  if (ftruncate (lf, 0) == -1) {
1085  log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't truncate lock file. Error was %s",
1086  strerror (errno));
1088  goto error_close_unlink;
1089  }
1090 
1091  memset (pid_s, 0, sizeof (pid_s));
1092  snprintf (pid_s, sizeof (pid_s) - 1, "%u\n", pid);
1093 
1094 retry_write:
1095  if (write (lf, pid_s, strlen (pid_s)) != strlen (pid_s)) {
1096  if (errno == EINTR) {
1097  goto retry_write;
1098  } else {
1099  log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't write pid to lock file. "
1100  "Error was %s", strerror (errno));
1102  goto error_close_unlink;
1103  }
1104  }
1105 
1106  if ((fd_flag = fcntl (lf, F_GETFD, 0)) == -1) {
1107  log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't get close-on-exec flag from lock file. "
1108  "Error was %s", strerror (errno));
1110  goto error_close_unlink;
1111  }
1112  fd_flag |= FD_CLOEXEC;
1113  if (fcntl (lf, F_SETFD, fd_flag) == -1) {
1114  log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't set close-on-exec flag to lock file. "
1115  "Error was %s", strerror (errno));
1117  goto error_close_unlink;
1118  }
1119 
1120  return (err);
1121 
1122 error_close_unlink:
1123  unlink (lockfile);
1124 error_close:
1125  close (lf);
1126 
1127  return (err);
1128 }
1129 
1130 int main (int argc, char **argv, char **envp)
1131 {
1132  const char *error_string;
1133  struct totem_config totem_config;
1134  int res, ch;
1135  int background, setprio, testonly;
1136  struct stat stat_out;
1137  enum e_corosync_done flock_err;
1138  uint64_t totem_config_warnings;
1139  struct scheduler_pause_timeout_data scheduler_pause_timeout_data;
1140 
1141  /* default configuration
1142  */
1143  background = 1;
1144  setprio = 1;
1145  testonly = 0;
1146 
1147  while ((ch = getopt (argc, argv, "fprtv")) != EOF) {
1148 
1149  switch (ch) {
1150  case 'f':
1151  background = 0;
1152  break;
1153  case 'p':
1154  setprio = 0;
1155  break;
1156  case 'r':
1157  setprio = 1;
1158  break;
1159  case 't':
1160  testonly = 1;
1161  break;
1162  case 'v':
1163  printf ("Corosync Cluster Engine, version '%s'\n", VERSION);
1164  printf ("Copyright (c) 2006-2009 Red Hat, Inc.\n");
1166  return EXIT_SUCCESS;
1167 
1168  break;
1169  default:
1170  fprintf(stderr, \
1171  "usage:\n"\
1172  " -f : Start application in foreground.\n"\
1173  " -p : Do not set process priority.\n"\
1174  " -t : Test configuration and exit.\n"\
1175  " -r : Set round robin realtime scheduling (default).\n"\
1176  " -v : Display version and SVN revision of Corosync and exit.\n");
1178  return EXIT_FAILURE;
1179  }
1180  }
1181 
1182  /*
1183  * Set round robin realtime scheduling with priority 99
1184  * Lock all memory to avoid page faults which may interrupt
1185  * application healthchecking
1186  */
1187  if (setprio) {
1188  corosync_setscheduler ();
1189  }
1190 
1191  corosync_mlockall ();
1192 
1193  /*
1194  * Other signals are registered later via qb_loop_signal_add
1195  */
1196  (void)signal (SIGSEGV, sigsegv_handler);
1197  (void)signal (SIGABRT, sigabrt_handler);
1198 #if MSG_NOSIGNAL != 0
1199  (void)signal (SIGPIPE, SIG_IGN);
1200 #endif
1201 
1202  if (icmap_init() != CS_OK) {
1203  log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't initialize configuration component.");
1205  }
1206  set_icmap_ro_keys_flag();
1207 
1208  /*
1209  * Initialize the corosync_api_v1 definition
1210  */
1211  api = apidef_get ();
1212 
1213  res = coroparse_configparse(icmap_get_global_map(), &error_string);
1214  if (res == -1) {
1215  log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
1217  }
1218 
1219  res = corosync_log_config_read (&error_string);
1220  if (res == -1) {
1221  /*
1222  * if we are here, we _must_ flush the logsys queue
1223  * and try to inform that we couldn't read the config.
1224  * this is a desperate attempt before certain death
1225  * and there is no guarantee that we can print to stderr
1226  * nor that logsys is sending the messages where we expect.
1227  */
1228  log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
1229  fprintf(stderr, "%s", error_string);
1230  syslog (LOGSYS_LEVEL_ERROR, "%s", error_string);
1232  }
1233 
1234  if (!testonly) {
1235  log_printf (LOGSYS_LEVEL_NOTICE, "Corosync Cluster Engine ('%s'): started and ready to provide service.", VERSION);
1236  log_printf (LOGSYS_LEVEL_INFO, "Corosync built-in features:" PACKAGE_FEATURES "");
1237  }
1238 
1239  /*
1240  * Make sure required directory is present
1241  */
1242  res = stat (get_run_dir(), &stat_out);
1243  if ((res == -1) || (res == 0 && !S_ISDIR(stat_out.st_mode))) {
1244  log_printf (LOGSYS_LEVEL_ERROR, "Required directory not present %s. Please create it.", get_run_dir());
1246  }
1247 
1248  res = chdir(get_run_dir());
1249  if (res == -1) {
1250  log_printf (LOGSYS_LEVEL_ERROR, "Cannot chdir to run directory %s. "
1251  "Please make sure it has correct context and rights.", get_run_dir());
1253  }
1254 
1255  res = totem_config_read (&totem_config, &error_string, &totem_config_warnings);
1256  if (res == -1) {
1257  log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
1259  }
1260 
1261  if (totem_config_warnings & TOTEM_CONFIG_WARNING_MEMBERS_IGNORED) {
1262  log_printf (LOGSYS_LEVEL_WARNING, "member section is used together with nodelist. Members ignored.");
1263  }
1264 
1265  if (totem_config_warnings & TOTEM_CONFIG_WARNING_MEMBERS_DEPRECATED) {
1266  log_printf (LOGSYS_LEVEL_WARNING, "member section is deprecated.");
1267  }
1268 
1269  if (totem_config_warnings & TOTEM_CONFIG_WARNING_TOTEM_NODEID_IGNORED) {
1270  log_printf (LOGSYS_LEVEL_WARNING, "nodeid appears both in totem section and nodelist. Nodelist one is used.");
1271  }
1272 
1273  if (totem_config_warnings != 0) {
1274  log_printf (LOGSYS_LEVEL_WARNING, "Please migrate config file to nodelist.");
1275  }
1276 
1277  res = totem_config_keyread (&totem_config, &error_string);
1278  if (res == -1) {
1279  log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
1281  }
1282 
1283  res = totem_config_validate (&totem_config, &error_string);
1284  if (res == -1) {
1285  log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
1287  }
1288 
1289  if (testonly) {
1291  }
1292 
1293  ip_version = totem_config.ip_version;
1294 
1295  totem_config.totem_memb_ring_id_create_or_load = corosync_ring_id_create_or_load;
1296  totem_config.totem_memb_ring_id_store = corosync_ring_id_store;
1297 
1299  totem_config.totem_logging_configuration.log_subsys_id = _logsys_subsys_create("TOTEM", "totem,"
1300  "totemmrp.c,totemrrp.c,totemip.c,totemconfig.c,totemcrypto.c,totemsrp.c,"
1301  "totempg.c,totemiba.c,totemudp.c,totemudpu.c,totemnet.c");
1302 
1309  totem_config.totem_logging_configuration.log_printf = _logsys_log_printf;
1311 
1312  /*
1313  * Now we are fully initialized.
1314  */
1315  if (background) {
1316  corosync_tty_detach ();
1317  }
1318 
1319  corosync_poll_handle = qb_loop_create ();
1320 
1321  memset(&scheduler_pause_timeout_data, 0, sizeof(scheduler_pause_timeout_data));
1322  scheduler_pause_timeout_data.totem_config = &totem_config;
1323  timer_function_scheduler_timeout (&scheduler_pause_timeout_data);
1324 
1325  qb_loop_signal_add(corosync_poll_handle, QB_LOOP_LOW,
1326  SIGUSR2, NULL, sig_diag_handler, NULL);
1327  qb_loop_signal_add(corosync_poll_handle, QB_LOOP_HIGH,
1328  SIGINT, NULL, sig_exit_handler, NULL);
1329  qb_loop_signal_add(corosync_poll_handle, QB_LOOP_HIGH,
1330  SIGSEGV, NULL, sig_segv_handler, NULL);
1331  qb_loop_signal_add(corosync_poll_handle, QB_LOOP_HIGH,
1332  SIGABRT, NULL, sig_abrt_handler, NULL);
1333  qb_loop_signal_add(corosync_poll_handle, QB_LOOP_HIGH,
1334  SIGQUIT, NULL, sig_exit_handler, NULL);
1335  qb_loop_signal_add(corosync_poll_handle, QB_LOOP_HIGH,
1336  SIGTERM, NULL, sig_exit_handler, NULL);
1337 
1338  if (logsys_thread_start() != 0) {
1339  log_printf (LOGSYS_LEVEL_ERROR, "Can't initialize log thread");
1341  }
1342 
1343  if ((flock_err = corosync_flock (corosync_lock_file, getpid ())) != COROSYNC_DONE_EXIT) {
1344  corosync_exit_error (flock_err);
1345  }
1346 
1347  /*
1348  * if totempg_initialize doesn't have root priveleges, it cannot
1349  * bind to a specific interface. This only matters if
1350  * there is more then one interface in a system, so
1351  * in this case, only a warning is printed
1352  */
1353  /*
1354  * Join multicast group and setup delivery
1355  * and configuration change functions
1356  */
1358  corosync_poll_handle,
1359  &totem_config);
1360 
1362  main_service_ready);
1363 
1365  &corosync_group_handle,
1366  deliver_fn,
1367  confchg_fn);
1368 
1370  corosync_group_handle,
1371  &corosync_group,
1372  1);
1373 
1374  /*
1375  * Drop root privleges to user 'corosync'
1376  * TODO: Don't really need full root capabilities;
1377  * needed capabilities are:
1378  * CAP_NET_RAW (bindtodevice)
1379  * CAP_SYS_NICE (setscheduler)
1380  * CAP_IPC_LOCK (mlockall)
1381  */
1382  priv_drop ();
1383 
1384  schedwrk_init (
1385  serialize_lock,
1386  serialize_unlock);
1387 
1388  /*
1389  * Start main processing loop
1390  */
1391  qb_loop_run (corosync_poll_handle);
1392 
1393  /*
1394  * Exit was requested
1395  */
1396  totempg_finalize ();
1397 
1398  /*
1399  * free the loop resources
1400  */
1401  qb_loop_destroy (corosync_poll_handle);
1402 
1403  /*
1404  * free up the icmap
1405  */
1406 
1407  /*
1408  * Remove pid lock file
1409  */
1410  unlink (corosync_lock_file);
1411 
1413 
1414  return EXIT_SUCCESS;
1415 }
#define CS_TRUE
Definition: corotypes.h:51
const char * name
Definition: coroapi.h:432
int32_t cs_ipcs_q_level_get(void)
Definition: ipc_glue.c:682
unsigned int corosync_service_defaults_link_and_init(struct corosync_api_v1 *corosync_api)
Load all of the default services.
Definition: service.c:339
uint64_t gather_entered
Definition: totem.h:260
const char * get_run_dir(void)
Definition: util.c:174
int corosync_quorum_is_quorate(void)
Definition: exec/quorum.c:67
void(* timer_delete)(corosync_timer_handle_t timer_handle)
Definition: coroapi.h:193
void totempg_finalize(void)
Definition: totempg.c:845
Totem Single Ring Protocol.
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:181
uint64_t memb_commit_token_rx
Definition: totem.h:255
#define LOGSYS_LEVEL_INFO
Definition: logsys.h:73
#define LOGSYS_LEVEL_TRACE
Definition: logsys.h:75
void totempg_trans_ack(void)
Definition: totempg.c:1542
struct totem_config * totem_config
Definition: main.c:842
void *(* totem_get_stats)(void)
Definition: coroapi.h:388
#define PACKAGE_FEATURES
Definition: config.h:364
#define CS_FALSE
Definition: corotypes.h:50
void sync_start(const unsigned int *member_list, size_t member_list_entries, const struct memb_ring_id *ring_id)
Definition: sync.c:573
uint64_t memb_join_tx
Definition: totem.h:249
qb_loop_timer_handle handle
Definition: main.c:843
void sync_abort(void)
Definition: sync.c:602
void(* exec_dump_fn)(void)
Definition: coroapi.h:442
void(* sync_abort)(void)
Definition: sync.h:47
totemsrp_token_stats_t token[TOTEM_TOKEN_STATS_MAX]
Definition: totem.h:274
const char * totemip_print(const struct totem_ip_address *addr)
Definition: totemip.c:214
Totem Single Ring Protocol.
void(* sync_init)(const unsigned int *trans_list, size_t trans_list_entries, const unsigned int *member_list, size_t member_list_entries, const struct memb_ring_id *ring_id)
Definition: sync.h:39
int sync_init(int(*sync_callbacks_retrieve)(int service_id, struct sync_callbacks *callbacks), void(*synchronization_completed)(void))
Definition: sync.c:175
void(* sync_init)(const unsigned int *trans_list, size_t trans_list_entries, const unsigned int *member_list, size_t member_list_entries, const struct memb_ring_id *ring_id)
Definition: coroapi.h:456
uint64_t mcast_rx
Definition: totem.h:253
int coroparse_configparse(icmap_map_t config_map, const char **error_string)
Definition: coroparse.c:247
qb_loop_t * cs_poll_handle_get(void)
Definition: main.c:163
void corosync_recheck_the_q_level(void *data)
Definition: main.c:752
#define corosync_exit_error(err)
Definition: exec/util.h:70
int totempg_groups_joined_release(int msg_count)
Definition: totempg.c:1336
#define VERSION
Definition: config.h:433
totem_configuration_type
Definition: coroapi.h:110
#define LOCALSTATEDIR
Definition: config.h:349
struct message_header header
Definition: totemsrp.c:60
uint64_t memb_merge_detect_rx
Definition: totem.h:248
LOGSYS_DECLARE_SUBSYS("MAIN")
int guarantee
Definition: totemsrp.c:66
unsigned char addr[TOTEMIP_ADDRLEN]
Definition: coroapi.h:67
void(* sync_activate)(void)
Definition: coroapi.h:463
void schedwrk_init(void(*serialize_lock_fn)(void), void(*serialize_unlock_fn)(void))
Definition: schedwrk.c:93
cs_error_t icmap_set_string(const char *key_name, const char *value)
Definition: icmap.c:641
int earliest_token
Definition: totem.h:271
void(* confchg_fn)(enum totem_configuration_type configuration_type, const unsigned int *member_list, size_t member_list_entries, const unsigned int *left_list, size_t left_list_entries, const unsigned int *joined_list, size_t joined_list_entries, const struct memb_ring_id *ring_id)
Definition: coroapi.h:450
uint64_t orf_token_tx
Definition: totem.h:245
int cs_poll_dispatch_add(qb_loop_t *handle, int fd, int events, void *data, int(*dispatch_fn)(int fd, int revents, void *data))
Definition: main.c:168
int totempg_groups_initialize(void **instance, void(*deliver_fn)(unsigned int nodeid, const void *msg, unsigned int msg_len, int endian_conversion_required), void(*confchg_fn)(enum totem_configuration_type configuration_type, const unsigned int *member_list, size_t member_list_entries, const unsigned int *left_list, size_t left_list_entries, const unsigned int *joined_list, size_t joined_list_entries, const struct memb_ring_id *ring_id))
Initialize a groups instance.
Definition: totempg.c:1124
uint64_t gather_token_lost
Definition: totem.h:261
#define RLIMIT_MEMLOCK
void totemip_copy(struct totem_ip_address *addr1, const struct totem_ip_address *addr2)
Definition: totemip.c:95
icmap_map_t icmap_get_global_map(void)
Definition: icmap.c:278
unsigned long long max_tv_diff
Definition: main.c:845
struct corosync_service_engine * corosync_service[SERVICES_COUNT_MAX]
Definition: service.c:110
int _logsys_subsys_create(const char *subsys, const char *filename)
Definition: logsys.c:436
uint64_t memb_commit_token_tx
Definition: totem.h:254
#define LOGSYS_PERROR(err_num, level, fmt, args...)
Definition: logsys.h:211
cs_error_t icmap_inc(const char *key_name)
Definition: icmap.c:1057
#define log_printf(level, format, args...)
Definition: logsys.h:217
#define MAX_NO_CONT_SENDMSG_FAILURES
Definition: totem.h:62
#define TOTEM_TOKEN_STATS_MAX
Definition: totem.h:273
void(* sync_abort)(void)
Definition: coroapi.h:464
void(* exec_handler_fn)(const void *msg, unsigned int nodeid)
Definition: coroapi.h:423
void cs_ipcs_sync_state_changed(int32_t sync_in_process)
Definition: ipc_glue.c:745
int corosync_sending_allowed(unsigned int service, unsigned int id, const void *msg, void *sending_allowed_private_data)
Definition: main.c:766
void icmap_fini(void)
Definition: icmap.c:261
int main_mcast(const struct iovec *iovec, unsigned int iov_len, unsigned int guarantee)
Definition: main.c:651
void cs_ipc_allow_connections(int32_t allow)
Definition: ipc_glue.c:155
void corosync_service_unlink_all(struct corosync_api_v1 *api, void(*unlink_all_complete)(void))
Unlink and exit all corosync services.
Definition: service.c:394
uint64_t operational_entered
Definition: totem.h:258
void(* sync_activate)(void)
Definition: sync.h:46
#define ICMAP_TRACK_DELETE
Definition: icmap.h:77
void(*) in log_level_security)
Definition: totem.h:82
void totempg_service_ready_register(void(*totem_service_ready)(void))
Definition: totempg.c:1511
#define ICMAP_KEYNAME_MAXLEN
Definition: icmap.h:48
int latest_token
Definition: totem.h:272
uint64_t operational_token_lost
Definition: totem.h:259
#define MAX_NO_CONT_GATHER
Maximum number of continuous gather states.
Definition: totem.h:58
uint64_t consensus_timeouts
Definition: totem.h:266
int totem_config_keyread(struct totem_config *totem_config, const char **error_string)
Definition: totemconfig.c:1443
const char * name
Definition: sync.h:48
uint64_t recovery_token_lost
Definition: totem.h:265
#define LOGSYS_LEVEL_WARNING
Definition: logsys.h:71
#define ICMAP_TRACK_MODIFY
Definition: icmap.h:78
struct corosync_exec_handler * exec_engine
Definition: coroapi.h:447
unsigned int totempg_my_nodeid_get(void)
Definition: totempg.c:1502
cs_error_t icmap_set_uint32(const char *key_name, uint32_t value)
Definition: icmap.c:611
uint64_t commit_token_lost
Definition: totem.h:263
void * user_data
Definition: sam.c:126
uint64_t token_hold_cancel_rx
Definition: totem.h:257
int logsys_thread_start(void)
Definition: logsys.c:820
int(* sync_process)(void)
Definition: coroapi.h:462
int totem_config_validate(struct totem_config *totem_config, const char **error_string)
Definition: totemconfig.c:1257
#define LOGSYS_MODE_OUTPUT_SYSLOG
Definition: logsys.h:60
#define ICMAP_TRACK_ADD
Definition: icmap.h:76
int totempg_groups_joined_reserve(void *instance, const struct iovec *iovec, unsigned int iov_len)
Definition: totempg.c:1292
const void * group
Definition: totempg.h:56
#define LOGSYS_LEVEL_ERROR
Definition: logsys.h:70
Linked list API.
struct totem_ip_address rep
Definition: coroapi.h:104
void sync_save_transitional(const unsigned int *member_list, size_t member_list_entries, const struct memb_ring_id *ring_id)
Definition: sync.c:591
int totempg_groups_mcast_joined(void *instance, const struct iovec *iovec, unsigned int iov_len, int guarantee)
Definition: totempg.c:1222
const char * service_stats_tx[SERVICES_COUNT_MAX][SERVICE_HANDLER_MAXIMUM_COUNT]
Definition: service.c:113
uint64_t mcast_retx
Definition: totem.h:252
cs_error_t icmap_get(const char *key_name, void *value, size_t *value_len, icmap_value_types_t *type)
Definition: icmap.c:739
int corosync_log_config_read(cmap_handle_t cmap_h, const char *default_logfile, const char **error_string)
Definition: logconfig.c:607
#define LOGSYS_LEVEL_DEBUG
Definition: logsys.h:74
void cs_ipcs_init(void)
Definition: ipc_glue.c:888
totemmrp_stats_t * mrp
Definition: totem.h:288
typedef __attribute__
#define TOTEM_CONFIG_WARNING_MEMBERS_DEPRECATED
Definition: totemconfig.h:47
uint32_t msg_queue_avail
Definition: totem.h:290
uint64_t rx_msg_dropped
Definition: totem.h:267
void(* log_printf)(int level, int subsys, const char *function_name, const char *file_name, int file_line, const char *format,...) __attribute__((format(printf
Definition: totem.h:75
#define TOTEM_CONFIG_WARNING_MEMBERS_IGNORED
Definition: totemconfig.h:46
#define swab32(x)
Definition: swab.h:43
uint32_t continuous_gather
Definition: totem.h:268
cs_error_t icmap_set_uint64(const char *key_name, uint64_t value)
Definition: icmap.c:623
totemrrp_stats_t * rrp
Definition: totem.h:244
cs_error_t icmap_fast_inc(const char *key_name)
Definition: icmap.c:1077
#define MILLI_2_NANO_SECONDS
Definition: coroapi.h:92
void message_source_set(mar_message_source_t *source, void *conn)
Definition: main.c:831
void logsys_config_apply(void)
Definition: logsys.c:770
uint64_t token_hold_cancel_tx
Definition: totem.h:256
void(* totem_memb_ring_id_create_or_load)(struct memb_ring_id *memb_ring_id, const struct totem_ip_address *addr)
Definition: totem.h:191
int ip_version
Definition: totem.h:189
unsigned int token_timeout
Definition: totem.h:129
void totempg_check_q_level(void *instance)
Definition: totempg.c:1284
uint64_t mcast_tx
Definition: totem.h:251
const char * service_stats_rx[SERVICES_COUNT_MAX][SERVICE_HANDLER_MAXIMUM_COUNT]
Definition: service.c:112
void(* exec_endian_convert_fn)(void *msg)
Definition: coroapi.h:424
struct corosync_api_v1 * apidef_get(void)
Definition: apidef.c:147
void corosync_sending_allowed_release(void *sending_allowed_private_data)
Definition: main.c:809
void cs_ipcs_stats_update(void)
Definition: ipc_glue.c:751
uint64_t memb_merge_detect_tx
Definition: totem.h:247
uint32_t msg_reserved
Definition: totem.h:289
totemsrp_stats_t * srp
Definition: totem.h:283
#define SERVICES_COUNT_MAX
Definition: coroapi.h:415
unsigned long long tv_prev
Definition: main.c:844
const char *(* totem_ifaces_print)(unsigned int nodeid)
Definition: coroapi.h:243
uint64_t memb_join_rx
Definition: totem.h:250
void corosync_state_dump(void)
Definition: main.c:186
qb_loop_timer_handle corosync_timer_handle_t
Definition: coroapi.h:64
int cs_poll_dispatch_delete(qb_loop_t *handle, int fd)
Definition: main.c:181
e_corosync_done
Definition: exec/util.h:47
int message_source_is_local(const mar_message_source_t *source)
Definition: main.c:820
struct totem_logging_configuration totem_logging_configuration
Definition: totem.h:163
int totempg_groups_join(void *instance, const struct totempg_group *groups, size_t group_cnt)
Definition: totempg.c:1172
#define LOGSYS_LEVEL_NOTICE
Definition: logsys.h:72
unsigned long long seq
Definition: coroapi.h:105
cs_error_t icmap_set_uint8(const char *key_name, uint8_t value)
Definition: icmap.c:587
uint64_t recovery_entered
Definition: totem.h:264
cs_error_t icmap_set_ro_access(const char *key_name, int prefix, int ro_access)
Definition: icmap.c:1233
int totempg_initialize(qb_loop_t *poll_handle, struct totem_config *totem_config)
Initialize the totem process groups abstraction.
Definition: totempg.c:799
void corosync_shutdown_request(void)
Definition: main.c:233
uint32_t interface_count
Definition: totem.h:232
struct sched_param global_sched_param
Definition: main.c:155
unsigned int nodeid
Definition: coroapi.h:65
uint32_t continuous_sendmsg_failures
Definition: totem.h:269
uint8_t * faulty
Definition: totem.h:231
struct memb_ring_id ring_id
Definition: totemsrp.c:64
int main(int argc, char **argv, char **envp)
Definition: main.c:1130
cs_error_t icmap_init(void)
Definition: icmap.c:221
uint64_t commit_entered
Definition: totem.h:262
#define TOTEM_CONFIG_WARNING_TOTEM_NODEID_IGNORED
Definition: totemconfig.h:48
LOGSYS_DECLARE_SYSTEM("corosync", LOGSYS_MODE_OUTPUT_STDERR|LOGSYS_MODE_OUTPUT_SYSLOG, LOG_DAEMON, LOG_INFO)
#define LOGSYS_MODE_OUTPUT_STDERR
Definition: logsys.h:59
uint64_t orf_token_rx
Definition: totem.h:246
void(* totem_memb_ring_id_store)(const struct memb_ring_id *memb_ring_id, const struct totem_ip_address *addr)
Definition: totem.h:195
cs_error_t icmap_track_add(const char *key_name, int32_t track_type, icmap_notify_fn_t notify_fn, void *user_data, icmap_track_t *icmap_track)
Definition: icmap.c:1167
int totem_config_read(struct totem_config *totem_config, const char **error_string, uint64_t *warnings)
Definition: totemconfig.c:972
int(* sync_process)(void)
Definition: sync.h:45
void logsys_system_fini(void)
Definition: logsys.c:285