4
0

main.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  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. /**
  36. * \mainpage Corosync
  37. *
  38. * This is the doxygen generated developer documentation for the Corosync
  39. * project. For more information about Corosync, please see the project
  40. * web site, <a href="http://www.corosync.org">corosync.org</a>.
  41. *
  42. * \section license License
  43. *
  44. * This software licensed under BSD license, the text of which follows:
  45. *
  46. * Redistribution and use in source and binary forms, with or without
  47. * modification, are permitted provided that the following conditions are met:
  48. *
  49. * - Redistributions of source code must retain the above copyright notice,
  50. * this list of conditions and the following disclaimer.
  51. * - Redistributions in binary form must reproduce the above copyright notice,
  52. * this list of conditions and the following disclaimer in the documentation
  53. * and/or other materials provided with the distribution.
  54. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  55. * contributors may be used to endorse or promote products derived from this
  56. * software without specific prior written permission.
  57. *
  58. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  59. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  60. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  61. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  62. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  63. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  64. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  65. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  66. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  67. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  68. * THE POSSIBILITY OF SUCH DAMAGE.
  69. */
  70. #include <config.h>
  71. #include <pthread.h>
  72. #include <assert.h>
  73. #include <sys/types.h>
  74. #include <sys/file.h>
  75. #include <sys/poll.h>
  76. #include <sys/uio.h>
  77. #include <sys/mman.h>
  78. #include <sys/socket.h>
  79. #include <sys/un.h>
  80. #include <sys/time.h>
  81. #include <sys/resource.h>
  82. #include <sys/stat.h>
  83. #include <netinet/in.h>
  84. #include <arpa/inet.h>
  85. #include <unistd.h>
  86. #include <fcntl.h>
  87. #include <stdlib.h>
  88. #include <stdio.h>
  89. #include <errno.h>
  90. #include <signal.h>
  91. #include <sched.h>
  92. #include <time.h>
  93. #include <semaphore.h>
  94. #include <qb/qbdefs.h>
  95. #include <qb/qblog.h>
  96. #include <qb/qbloop.h>
  97. #include <qb/qbutil.h>
  98. #include <qb/qbipcs.h>
  99. #include <corosync/swab.h>
  100. #include <corosync/corotypes.h>
  101. #include <corosync/corodefs.h>
  102. #include <corosync/list.h>
  103. #include <corosync/totem/totempg.h>
  104. #include <corosync/logsys.h>
  105. #include <corosync/icmap.h>
  106. #include "quorum.h"
  107. #include "totemsrp.h"
  108. #include "mainconfig.h"
  109. #include "totemconfig.h"
  110. #include "main.h"
  111. #include "sync.h"
  112. #include "timer.h"
  113. #include "util.h"
  114. #include "apidef.h"
  115. #include "service.h"
  116. #include "schedwrk.h"
  117. #ifdef HAVE_SMALL_MEMORY_FOOTPRINT
  118. #define IPC_LOGSYS_SIZE 1024*64
  119. #else
  120. #define IPC_LOGSYS_SIZE 8192*128
  121. #endif
  122. LOGSYS_DECLARE_SYSTEM ("corosync",
  123. LOGSYS_MODE_OUTPUT_STDERR,
  124. LOG_DAEMON,
  125. LOG_INFO);
  126. LOGSYS_DECLARE_SUBSYS ("MAIN");
  127. #define SERVER_BACKLOG 5
  128. static int sched_priority = 0;
  129. static unsigned int service_count = 32;
  130. static struct totem_logging_configuration totem_logging_configuration;
  131. static struct corosync_api_v1 *api = NULL;
  132. static int sync_in_process = 1;
  133. static qb_loop_t *corosync_poll_handle;
  134. struct sched_param global_sched_param;
  135. static corosync_timer_handle_t corosync_stats_timer_handle;
  136. static const char *corosync_lock_file = LOCALSTATEDIR"/run/corosync.pid";
  137. qb_loop_t *cs_poll_handle_get (void)
  138. {
  139. return (corosync_poll_handle);
  140. }
  141. int cs_poll_dispatch_add (qb_loop_t * handle,
  142. int fd,
  143. int events,
  144. void *data,
  145. int (*dispatch_fn) (int fd,
  146. int revents,
  147. void *data))
  148. {
  149. return qb_loop_poll_add(handle, QB_LOOP_MED, fd, events, data,
  150. dispatch_fn);
  151. }
  152. int cs_poll_dispatch_delete(qb_loop_t * handle, int fd)
  153. {
  154. return qb_loop_poll_del(handle, fd);
  155. }
  156. void corosync_state_dump (void)
  157. {
  158. int i;
  159. for (i = 0; i < SERVICE_HANDLER_MAXIMUM_COUNT; i++) {
  160. if (corosync_service[i] && corosync_service[i]->exec_dump_fn) {
  161. corosync_service[i]->exec_dump_fn ();
  162. }
  163. }
  164. }
  165. static void unlink_all_completed (void)
  166. {
  167. api->timer_delete (corosync_stats_timer_handle);
  168. qb_loop_stop (corosync_poll_handle);
  169. }
  170. void corosync_shutdown_request (void)
  171. {
  172. corosync_service_unlink_all (api, unlink_all_completed);
  173. }
  174. static int32_t sig_diag_handler (int num, void *data)
  175. {
  176. corosync_state_dump ();
  177. qb_log_blackbox_write_to_file(LOCALSTATEDIR "/lib/corosync/fdata");
  178. return 0;
  179. }
  180. static int32_t sig_exit_handler (int num, void *data)
  181. {
  182. corosync_service_unlink_all (api, unlink_all_completed);
  183. return 0;
  184. }
  185. static void sigsegv_handler (int num)
  186. {
  187. (void)signal (SIGSEGV, SIG_DFL);
  188. qb_log_blackbox_write_to_file(LOCALSTATEDIR "/lib/corosync/fdata");
  189. qb_log_fini();
  190. raise (SIGSEGV);
  191. }
  192. static void sigabrt_handler (int num)
  193. {
  194. (void)signal (SIGABRT, SIG_DFL);
  195. qb_log_blackbox_write_to_file(LOCALSTATEDIR "/lib/corosync/fdata");
  196. qb_log_fini();
  197. raise (SIGABRT);
  198. }
  199. #define LOCALHOST_IP inet_addr("127.0.0.1")
  200. static void *corosync_group_handle;
  201. static struct totempg_group corosync_group = {
  202. .group = "a",
  203. .group_len = 1
  204. };
  205. static void serialize_lock (void)
  206. {
  207. }
  208. static void serialize_unlock (void)
  209. {
  210. }
  211. static void corosync_sync_completed (void)
  212. {
  213. log_printf (LOGSYS_LEVEL_NOTICE,
  214. "Completed service synchronization, ready to provide service.");
  215. sync_in_process = 0;
  216. cs_ipcs_sync_state_changed(sync_in_process);
  217. cs_ipc_allow_connections(1);
  218. }
  219. static int corosync_sync_callbacks_retrieve (
  220. int service_id,
  221. struct sync_callbacks *callbacks)
  222. {
  223. if (corosync_service[service_id] == NULL) {
  224. return (-1);
  225. }
  226. callbacks->name = corosync_service[service_id]->name;
  227. callbacks->sync_init = corosync_service[service_id]->sync_init;
  228. callbacks->sync_process = corosync_service[service_id]->sync_process;
  229. callbacks->sync_activate = corosync_service[service_id]->sync_activate;
  230. callbacks->sync_abort = corosync_service[service_id]->sync_abort;
  231. return (0);
  232. }
  233. static struct memb_ring_id corosync_ring_id;
  234. static void member_object_joined (unsigned int nodeid)
  235. {
  236. char member_ip[ICMAP_KEYNAME_MAXLEN];
  237. char member_join_count[ICMAP_KEYNAME_MAXLEN];
  238. char member_status[ICMAP_KEYNAME_MAXLEN];
  239. snprintf(member_ip, ICMAP_KEYNAME_MAXLEN,
  240. "runtime.totem.pg.mrp.srp.members.%u.ip", nodeid);
  241. snprintf(member_join_count, ICMAP_KEYNAME_MAXLEN,
  242. "runtime.totem.pg.mrp.srp.members.%u.join_count", nodeid);
  243. snprintf(member_status, ICMAP_KEYNAME_MAXLEN,
  244. "runtime.totem.pg.mrp.srp.members.%u.status", nodeid);
  245. if (icmap_get(member_ip, NULL, NULL, NULL) == CS_OK) {
  246. icmap_inc(member_join_count);
  247. icmap_set_string(member_status, "joined");
  248. } else {
  249. icmap_set_string(member_ip, (char*)api->totem_ifaces_print (nodeid));
  250. icmap_set_uint32(member_join_count, 1);
  251. icmap_set_string(member_status, "joined");
  252. }
  253. log_printf (LOGSYS_LEVEL_DEBUG,
  254. "Member joined: %s", api->totem_ifaces_print (nodeid));
  255. }
  256. static void member_object_left (unsigned int nodeid)
  257. {
  258. char member_status[ICMAP_KEYNAME_MAXLEN];
  259. snprintf(member_status, ICMAP_KEYNAME_MAXLEN,
  260. "runtime.totem.pg.mrp.srp.members.%u.status", nodeid);
  261. icmap_set_string(member_status, "left");
  262. log_printf (LOGSYS_LEVEL_DEBUG,
  263. "Member left: %s", api->totem_ifaces_print (nodeid));
  264. }
  265. static void confchg_fn (
  266. enum totem_configuration_type configuration_type,
  267. const unsigned int *member_list, size_t member_list_entries,
  268. const unsigned int *left_list, size_t left_list_entries,
  269. const unsigned int *joined_list, size_t joined_list_entries,
  270. const struct memb_ring_id *ring_id)
  271. {
  272. int i;
  273. int abort_activate = 0;
  274. if (sync_in_process == 1) {
  275. abort_activate = 1;
  276. }
  277. sync_in_process = 1;
  278. cs_ipcs_sync_state_changed(sync_in_process);
  279. memcpy (&corosync_ring_id, ring_id, sizeof (struct memb_ring_id));
  280. for (i = 0; i < left_list_entries; i++) {
  281. member_object_left (left_list[i]);
  282. }
  283. for (i = 0; i < joined_list_entries; i++) {
  284. member_object_joined (joined_list[i]);
  285. }
  286. /*
  287. * Call configuration change for all services
  288. */
  289. for (i = 0; i < service_count; i++) {
  290. if (corosync_service[i] && corosync_service[i]->confchg_fn) {
  291. corosync_service[i]->confchg_fn (configuration_type,
  292. member_list, member_list_entries,
  293. left_list, left_list_entries,
  294. joined_list, joined_list_entries, ring_id);
  295. }
  296. }
  297. if (abort_activate) {
  298. sync_abort ();
  299. }
  300. if (configuration_type == TOTEM_CONFIGURATION_TRANSITIONAL) {
  301. sync_save_transitional (member_list, member_list_entries, ring_id);
  302. }
  303. if (configuration_type == TOTEM_CONFIGURATION_REGULAR) {
  304. sync_start (member_list, member_list_entries, ring_id);
  305. }
  306. }
  307. static void priv_drop (void)
  308. {
  309. return; /* TODO: we are still not dropping privs */
  310. }
  311. static void corosync_tty_detach (void)
  312. {
  313. FILE *r;
  314. /*
  315. * Disconnect from TTY if this is not a debug run
  316. */
  317. switch (fork ()) {
  318. case -1:
  319. corosync_exit_error (COROSYNC_DONE_FORK);
  320. break;
  321. case 0:
  322. /*
  323. * child which is disconnected, run this process
  324. */
  325. break;
  326. default:
  327. exit (0);
  328. break;
  329. }
  330. /* Create new session */
  331. (void)setsid();
  332. /*
  333. * Map stdin/out/err to /dev/null.
  334. */
  335. r = freopen("/dev/null", "r", stdin);
  336. if (r == NULL) {
  337. corosync_exit_error (COROSYNC_DONE_STD_TO_NULL_REDIR);
  338. }
  339. r = freopen("/dev/null", "a", stderr);
  340. if (r == NULL) {
  341. corosync_exit_error (COROSYNC_DONE_STD_TO_NULL_REDIR);
  342. }
  343. r = freopen("/dev/null", "a", stdout);
  344. if (r == NULL) {
  345. corosync_exit_error (COROSYNC_DONE_STD_TO_NULL_REDIR);
  346. }
  347. }
  348. static void corosync_mlockall (void)
  349. {
  350. #if !defined(COROSYNC_BSD) || defined(COROSYNC_FREEBSD_GE_8)
  351. int res;
  352. #endif
  353. struct rlimit rlimit;
  354. rlimit.rlim_cur = RLIM_INFINITY;
  355. rlimit.rlim_max = RLIM_INFINITY;
  356. #ifndef COROSYNC_SOLARIS
  357. setrlimit (RLIMIT_MEMLOCK, &rlimit);
  358. #else
  359. setrlimit (RLIMIT_VMEM, &rlimit);
  360. #endif
  361. #if defined(COROSYNC_BSD) && !defined(COROSYNC_FREEBSD_GE_8)
  362. /* under FreeBSD < 8 a process with locked page cannot call dlopen
  363. * code disabled until FreeBSD bug i386/93396 was solved
  364. */
  365. log_printf (LOGSYS_LEVEL_WARNING, "Could not lock memory of service to avoid page faults");
  366. #else
  367. res = mlockall (MCL_CURRENT | MCL_FUTURE);
  368. if (res == -1) {
  369. LOGSYS_PERROR (errno, LOGSYS_LEVEL_WARNING,
  370. "Could not lock memory of service to avoid page faults");
  371. };
  372. #endif
  373. }
  374. static void corosync_totem_stats_updater (void *data)
  375. {
  376. totempg_stats_t * stats;
  377. uint32_t total_mtt_rx_token;
  378. uint32_t total_backlog_calc;
  379. uint32_t total_token_holdtime;
  380. int t, prev, i;
  381. int32_t token_count;
  382. char key_name[ICMAP_KEYNAME_MAXLEN];
  383. stats = api->totem_get_stats();
  384. icmap_set_uint32("runtime.totem.pg.msg_reserved", stats->msg_reserved);
  385. icmap_set_uint32("runtime.totem.pg.msg_queue_avail", stats->msg_queue_avail);
  386. icmap_set_uint64("runtime.totem.pg.mrp.srp.orf_token_tx", stats->mrp->srp->orf_token_tx);
  387. icmap_set_uint64("runtime.totem.pg.mrp.srp.orf_token_rx", stats->mrp->srp->orf_token_rx);
  388. icmap_set_uint64("runtime.totem.pg.mrp.srp.memb_merge_detect_tx", stats->mrp->srp->memb_merge_detect_tx);
  389. icmap_set_uint64("runtime.totem.pg.mrp.srp.memb_merge_detect_rx", stats->mrp->srp->memb_merge_detect_rx);
  390. icmap_set_uint64("runtime.totem.pg.mrp.srp.memb_join_tx", stats->mrp->srp->memb_join_tx);
  391. icmap_set_uint64("runtime.totem.pg.mrp.srp.memb_join_rx", stats->mrp->srp->memb_join_rx);
  392. icmap_set_uint64("runtime.totem.pg.mrp.srp.mcast_tx", stats->mrp->srp->mcast_tx);
  393. icmap_set_uint64("runtime.totem.pg.mrp.srp.mcast_retx", stats->mrp->srp->mcast_retx);
  394. icmap_set_uint64("runtime.totem.pg.mrp.srp.mcast_rx", stats->mrp->srp->mcast_rx);
  395. icmap_set_uint64("runtime.totem.pg.mrp.srp.memb_commit_token_tx", stats->mrp->srp->memb_commit_token_tx);
  396. icmap_set_uint64("runtime.totem.pg.mrp.srp.memb_commit_token_rx", stats->mrp->srp->memb_commit_token_rx);
  397. icmap_set_uint64("runtime.totem.pg.mrp.srp.token_hold_cancel_tx", stats->mrp->srp->token_hold_cancel_tx);
  398. icmap_set_uint64("runtime.totem.pg.mrp.srp.token_hold_cancel_rx", stats->mrp->srp->token_hold_cancel_rx);
  399. icmap_set_uint64("runtime.totem.pg.mrp.srp.operational_entered", stats->mrp->srp->operational_entered);
  400. icmap_set_uint64("runtime.totem.pg.mrp.srp.operational_token_lost", stats->mrp->srp->operational_token_lost);
  401. icmap_set_uint64("runtime.totem.pg.mrp.srp.gather_entered", stats->mrp->srp->gather_entered);
  402. icmap_set_uint64("runtime.totem.pg.mrp.srp.gather_token_lost", stats->mrp->srp->gather_token_lost);
  403. icmap_set_uint64("runtime.totem.pg.mrp.srp.commit_entered", stats->mrp->srp->commit_entered);
  404. icmap_set_uint64("runtime.totem.pg.mrp.srp.commit_token_lost", stats->mrp->srp->commit_token_lost);
  405. icmap_set_uint64("runtime.totem.pg.mrp.srp.recovery_entered", stats->mrp->srp->recovery_entered);
  406. icmap_set_uint64("runtime.totem.pg.mrp.srp.recovery_token_lost", stats->mrp->srp->recovery_token_lost);
  407. icmap_set_uint64("runtime.totem.pg.mrp.srp.consensus_timeouts", stats->mrp->srp->consensus_timeouts);
  408. icmap_set_uint64("runtime.totem.pg.mrp.srp.rx_msg_dropped", stats->mrp->srp->rx_msg_dropped);
  409. icmap_set_uint32("runtime.totem.pg.mrp.srp.continuous_gather", stats->mrp->srp->continuous_gather);
  410. icmap_set_uint8("runtime.totem.pg.mrp.srp.firewall_enabled_or_nic_failure",
  411. stats->mrp->srp->continuous_gather > MAX_NO_CONT_GATHER ? 1 : 0);
  412. for (i = 0; i < stats->mrp->srp->rrp->interface_count; i++) {
  413. snprintf(key_name, ICMAP_KEYNAME_MAXLEN, "runtime.totem.pg.mrp.rrp.%u.faulty", i);
  414. icmap_set_uint8(key_name, stats->mrp->srp->rrp->faulty[i]);
  415. }
  416. total_mtt_rx_token = 0;
  417. total_token_holdtime = 0;
  418. total_backlog_calc = 0;
  419. token_count = 0;
  420. t = stats->mrp->srp->latest_token;
  421. while (1) {
  422. if (t == 0)
  423. prev = TOTEM_TOKEN_STATS_MAX - 1;
  424. else
  425. prev = t - 1;
  426. if (prev == stats->mrp->srp->earliest_token)
  427. break;
  428. /* if tx == 0, then dropped token (not ours) */
  429. if (stats->mrp->srp->token[t].tx != 0 ||
  430. (stats->mrp->srp->token[t].rx - stats->mrp->srp->token[prev].rx) > 0 ) {
  431. total_mtt_rx_token += (stats->mrp->srp->token[t].rx - stats->mrp->srp->token[prev].rx);
  432. total_token_holdtime += (stats->mrp->srp->token[t].tx - stats->mrp->srp->token[t].rx);
  433. total_backlog_calc += stats->mrp->srp->token[t].backlog_calc;
  434. token_count++;
  435. }
  436. t = prev;
  437. }
  438. if (token_count) {
  439. icmap_set_uint32("runtime.totem.pg.mrp.srp.mtt_rx_token", (total_mtt_rx_token / token_count));
  440. icmap_set_uint32("runtime.totem.pg.mrp.srp.avg_token_workload", (total_token_holdtime / token_count));
  441. icmap_set_uint32("runtime.totem.pg.mrp.srp.avg_backlog_calc", (total_backlog_calc / token_count));
  442. }
  443. cs_ipcs_stats_update();
  444. api->timer_add_duration (1500 * MILLI_2_NANO_SECONDS, NULL,
  445. corosync_totem_stats_updater,
  446. &corosync_stats_timer_handle);
  447. }
  448. static void totem_dynamic_notify(
  449. int32_t event,
  450. const char *key_name,
  451. struct icmap_notify_value new_val,
  452. struct icmap_notify_value old_val,
  453. void *user_data)
  454. {
  455. int res;
  456. int ring_no;
  457. int member_no;
  458. struct totem_ip_address member;
  459. int add_new_member = 0;
  460. int remove_old_member = 0;
  461. char tmp_str[ICMAP_KEYNAME_MAXLEN];
  462. res = sscanf(key_name, "nodelist.node.%u.ring%u%s", &member_no, &ring_no, tmp_str);
  463. if (res != 3)
  464. return ;
  465. if (strcmp(tmp_str, "_addr") != 0) {
  466. return;
  467. }
  468. if (event == ICMAP_TRACK_ADD && new_val.type == ICMAP_VALUETYPE_STRING) {
  469. add_new_member = 1;
  470. }
  471. if (event == ICMAP_TRACK_DELETE && old_val.type == ICMAP_VALUETYPE_STRING) {
  472. remove_old_member = 1;
  473. }
  474. if (event == ICMAP_TRACK_MODIFY && new_val.type == ICMAP_VALUETYPE_STRING &&
  475. old_val.type == ICMAP_VALUETYPE_STRING) {
  476. add_new_member = 1;
  477. remove_old_member = 1;
  478. }
  479. if (remove_old_member) {
  480. log_printf(LOGSYS_LEVEL_DEBUG,
  481. "removing dynamic member %s for ring %u", (char *)old_val.data, ring_no);
  482. if (totemip_parse(&member, (char *)old_val.data, 0) == 0) {
  483. totempg_member_remove (&member, ring_no);
  484. }
  485. }
  486. if (add_new_member) {
  487. log_printf(LOGSYS_LEVEL_DEBUG,
  488. "adding dynamic member %s for ring %u", (char *)new_val.data, ring_no);
  489. if (totemip_parse(&member, (char *)new_val.data, 0) == 0) {
  490. totempg_member_add (&member, ring_no);
  491. }
  492. }
  493. }
  494. static void corosync_totem_dynamic_init (void)
  495. {
  496. icmap_track_t icmap_track = NULL;
  497. icmap_track_add("nodelist.node.",
  498. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  499. totem_dynamic_notify,
  500. NULL,
  501. &icmap_track);
  502. }
  503. static void corosync_totem_stats_init (void)
  504. {
  505. icmap_set_uint32("runtime.totem.pg.mrp.srp.mtt_rx_token", 0);
  506. icmap_set_uint32("runtime.totem.pg.mrp.srp.avg_token_workload", 0);
  507. icmap_set_uint32("runtime.totem.pg.mrp.srp.avg_backlog_calc", 0);
  508. /* start stats timer */
  509. api->timer_add_duration (1500 * MILLI_2_NANO_SECONDS, NULL,
  510. corosync_totem_stats_updater,
  511. &corosync_stats_timer_handle);
  512. }
  513. static void deliver_fn (
  514. unsigned int nodeid,
  515. const void *msg,
  516. unsigned int msg_len,
  517. int endian_conversion_required)
  518. {
  519. const struct qb_ipc_request_header *header;
  520. int32_t service;
  521. int32_t fn_id;
  522. uint32_t id;
  523. header = msg;
  524. if (endian_conversion_required) {
  525. id = swab32 (header->id);
  526. } else {
  527. id = header->id;
  528. }
  529. /*
  530. * Call the proper executive handler
  531. */
  532. service = id >> 16;
  533. fn_id = id & 0xffff;
  534. if (!corosync_service[service]) {
  535. return;
  536. }
  537. if (fn_id >= corosync_service[service]->exec_engine_count) {
  538. log_printf(LOGSYS_LEVEL_WARNING, "discarded unknown message %d for service %d (max id %d)",
  539. fn_id, service, corosync_service[service]->exec_engine_count);
  540. return;
  541. }
  542. icmap_fast_inc(service_stats_rx[service][fn_id]);
  543. if (endian_conversion_required) {
  544. assert(corosync_service[service]->exec_engine[fn_id].exec_endian_convert_fn != NULL);
  545. corosync_service[service]->exec_engine[fn_id].exec_endian_convert_fn
  546. ((void *)msg);
  547. }
  548. corosync_service[service]->exec_engine[fn_id].exec_handler_fn
  549. (msg, nodeid);
  550. }
  551. int main_mcast (
  552. const struct iovec *iovec,
  553. unsigned int iov_len,
  554. unsigned int guarantee)
  555. {
  556. const struct qb_ipc_request_header *req = iovec->iov_base;
  557. int32_t service;
  558. int32_t fn_id;
  559. service = req->id >> 16;
  560. fn_id = req->id & 0xffff;
  561. if (corosync_service[service]) {
  562. icmap_fast_inc(service_stats_tx[service][fn_id]);
  563. }
  564. return (totempg_groups_mcast_joined (corosync_group_handle, iovec, iov_len, guarantee));
  565. }
  566. static qb_loop_timer_handle recheck_the_q_level_timer;
  567. void corosync_recheck_the_q_level(void *data)
  568. {
  569. totempg_check_q_level(corosync_group_handle);
  570. if (cs_ipcs_q_level_get() == TOTEM_Q_LEVEL_CRITICAL) {
  571. qb_loop_timer_add(cs_poll_handle_get(), QB_LOOP_MED, 1*QB_TIME_NS_IN_MSEC,
  572. NULL, corosync_recheck_the_q_level, &recheck_the_q_level_timer);
  573. }
  574. }
  575. struct sending_allowed_private_data_struct {
  576. int reserved_msgs;
  577. };
  578. int corosync_sending_allowed (
  579. unsigned int service,
  580. unsigned int id,
  581. const void *msg,
  582. void *sending_allowed_private_data)
  583. {
  584. struct sending_allowed_private_data_struct *pd =
  585. (struct sending_allowed_private_data_struct *)sending_allowed_private_data;
  586. struct iovec reserve_iovec;
  587. struct qb_ipc_request_header *header = (struct qb_ipc_request_header *)msg;
  588. int sending_allowed;
  589. reserve_iovec.iov_base = (char *)header;
  590. reserve_iovec.iov_len = header->size;
  591. pd->reserved_msgs = totempg_groups_joined_reserve (
  592. corosync_group_handle,
  593. &reserve_iovec, 1);
  594. if (pd->reserved_msgs == -1) {
  595. return -EINVAL;
  596. }
  597. sending_allowed = QB_FALSE;
  598. if (corosync_quorum_is_quorate() == 1 ||
  599. corosync_service[service]->allow_inquorate == CS_LIB_ALLOW_INQUORATE) {
  600. // we are quorate
  601. // now check flow control
  602. if (corosync_service[service]->lib_engine[id].flow_control == CS_LIB_FLOW_CONTROL_NOT_REQUIRED) {
  603. sending_allowed = QB_TRUE;
  604. } else if (pd->reserved_msgs && sync_in_process == 0) {
  605. sending_allowed = QB_TRUE;
  606. } else if (pd->reserved_msgs == 0) {
  607. return -ENOBUFS;
  608. } else /* (sync_in_process) */ {
  609. return -EINPROGRESS;
  610. }
  611. } else {
  612. return -EHOSTUNREACH;
  613. }
  614. return (sending_allowed);
  615. }
  616. void corosync_sending_allowed_release (void *sending_allowed_private_data)
  617. {
  618. struct sending_allowed_private_data_struct *pd =
  619. (struct sending_allowed_private_data_struct *)sending_allowed_private_data;
  620. if (pd->reserved_msgs == -1) {
  621. return;
  622. }
  623. totempg_groups_joined_release (pd->reserved_msgs);
  624. }
  625. int message_source_is_local (const mar_message_source_t *source)
  626. {
  627. int ret = 0;
  628. assert (source != NULL);
  629. if (source->nodeid == totempg_my_nodeid_get ()) {
  630. ret = 1;
  631. }
  632. return ret;
  633. }
  634. void message_source_set (
  635. mar_message_source_t *source,
  636. void *conn)
  637. {
  638. assert ((source != NULL) && (conn != NULL));
  639. memset (source, 0, sizeof (mar_message_source_t));
  640. source->nodeid = totempg_my_nodeid_get ();
  641. source->conn = conn;
  642. }
  643. static void corosync_setscheduler (void)
  644. {
  645. #if defined(HAVE_PTHREAD_SETSCHEDPARAM) && defined(HAVE_SCHED_GET_PRIORITY_MAX) && defined(HAVE_SCHED_SETSCHEDULER)
  646. int res;
  647. sched_priority = sched_get_priority_max (SCHED_RR);
  648. if (sched_priority != -1) {
  649. global_sched_param.sched_priority = sched_priority;
  650. res = sched_setscheduler (0, SCHED_RR, &global_sched_param);
  651. if (res == -1) {
  652. LOGSYS_PERROR(errno, LOGSYS_LEVEL_WARNING,
  653. "Could not set SCHED_RR at priority %d",
  654. global_sched_param.sched_priority);
  655. global_sched_param.sched_priority = 0;
  656. #ifdef HAVE_QB_LOG_THREAD_PRIORITY_SET
  657. qb_log_thread_priority_set (SCHED_OTHER, 0);
  658. #endif
  659. } else {
  660. /*
  661. * Turn on SCHED_RR in logsys system
  662. */
  663. #ifdef HAVE_QB_LOG_THREAD_PRIORITY_SET
  664. res = qb_log_thread_priority_set (SCHED_RR, sched_priority);
  665. #else
  666. res = -1;
  667. #endif
  668. if (res == -1) {
  669. log_printf (LOGSYS_LEVEL_ERROR,
  670. "Could not set logsys thread priority."
  671. " Can't continue because of priority inversions.");
  672. corosync_exit_error (COROSYNC_DONE_LOGSETUP);
  673. }
  674. }
  675. } else {
  676. LOGSYS_PERROR (errno, LOGSYS_LEVEL_WARNING,
  677. "Could not get maximum scheduler priority");
  678. sched_priority = 0;
  679. }
  680. #else
  681. log_printf(LOGSYS_LEVEL_WARNING,
  682. "The Platform is missing process priority setting features. Leaving at default.");
  683. #endif
  684. }
  685. static void
  686. _logsys_log_printf(int level, int subsys,
  687. const char *function_name,
  688. const char *file_name,
  689. int file_line,
  690. const char *format,
  691. ...) __attribute__((format(printf, 6, 7)));
  692. static void
  693. _logsys_log_printf(int level, int subsys,
  694. const char *function_name,
  695. const char *file_name,
  696. int file_line,
  697. const char *format, ...)
  698. {
  699. va_list ap;
  700. va_start(ap, format);
  701. qb_log_from_external_source_va(function_name, file_name,
  702. format, level, file_line,
  703. subsys, ap);
  704. va_end(ap);
  705. }
  706. static void fplay_key_change_notify_fn (
  707. int32_t event,
  708. const char *key_name,
  709. struct icmap_notify_value new_val,
  710. struct icmap_notify_value old_val,
  711. void *user_data)
  712. {
  713. if (strcmp(key_name, "runtime.blackbox.dump_flight_data") == 0) {
  714. fprintf(stderr,"Writetofile\n");
  715. qb_log_blackbox_write_to_file (LOCALSTATEDIR "/lib/corosync/fdata");
  716. }
  717. if (strcmp(key_name, "runtime.blackbox.dump_state") == 0) {
  718. fprintf(stderr,"statefump\n");
  719. corosync_state_dump ();
  720. }
  721. }
  722. static void corosync_fplay_control_init (void)
  723. {
  724. icmap_track_t track = NULL;
  725. icmap_set_string("runtime.blackbox.dump_flight_data", "no");
  726. icmap_set_string("runtime.blackbox.dump_state", "no");
  727. icmap_track_add("runtime.blackbox.dump_flight_data",
  728. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY,
  729. fplay_key_change_notify_fn,
  730. NULL, &track);
  731. icmap_track_add("runtime.blackbox.dump_state",
  732. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY,
  733. fplay_key_change_notify_fn,
  734. NULL, &track);
  735. }
  736. /*
  737. * Set RO flag for keys, which ether doesn't make sense to change by user (statistic)
  738. * or which when changed are not reflected by runtime (totem.crypto_cipher, ...).
  739. *
  740. * Also some RO keys cannot be determined in this stage, so they are set later in
  741. * other functions (like nodelist.local_node_pos, ...)
  742. */
  743. static void set_icmap_ro_keys_flag (void)
  744. {
  745. /*
  746. * Set RO flag for all keys of internal configuration and runtime statistics
  747. */
  748. icmap_set_ro_access("internal_configuration.", CS_TRUE, CS_TRUE);
  749. icmap_set_ro_access("runtime.connections.", CS_TRUE, CS_TRUE);
  750. icmap_set_ro_access("runtime.totem.", CS_TRUE, CS_TRUE);
  751. icmap_set_ro_access("runtime.services.", CS_TRUE, CS_TRUE);
  752. /*
  753. * Set RO flag for constrete keys of configuration which can't be changed
  754. * during runtime
  755. */
  756. icmap_set_ro_access("totem.crypto_cipher", CS_FALSE, CS_TRUE);
  757. icmap_set_ro_access("totem.crypto_hash", CS_FALSE, CS_TRUE);
  758. icmap_set_ro_access("totem.secauth", CS_FALSE, CS_TRUE);
  759. icmap_set_ro_access("totem.rrp_mode", CS_FALSE, CS_TRUE);
  760. icmap_set_ro_access("totem.netmtu", CS_FALSE, CS_TRUE);
  761. }
  762. static void main_service_ready (void)
  763. {
  764. int res;
  765. /*
  766. * This must occur after totempg is initialized because "this_ip" must be set
  767. */
  768. res = corosync_service_defaults_link_and_init (api);
  769. if (res == -1) {
  770. log_printf (LOGSYS_LEVEL_ERROR, "Could not initialize default services");
  771. corosync_exit_error (COROSYNC_DONE_INIT_SERVICES);
  772. }
  773. cs_ipcs_init();
  774. corosync_totem_stats_init ();
  775. corosync_fplay_control_init ();
  776. corosync_totem_dynamic_init ();
  777. sync_init (
  778. corosync_sync_callbacks_retrieve,
  779. corosync_sync_completed);
  780. }
  781. static enum e_corosync_done corosync_flock (const char *lockfile, pid_t pid)
  782. {
  783. struct flock lock;
  784. enum e_corosync_done err;
  785. char pid_s[17];
  786. int fd_flag;
  787. int lf;
  788. err = COROSYNC_DONE_EXIT;
  789. lf = open (lockfile, O_WRONLY | O_CREAT, 0640);
  790. if (lf == -1) {
  791. log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't create lock file.");
  792. return (COROSYNC_DONE_AQUIRE_LOCK);
  793. }
  794. retry_fcntl:
  795. lock.l_type = F_WRLCK;
  796. lock.l_start = 0;
  797. lock.l_whence = SEEK_SET;
  798. lock.l_len = 0;
  799. if (fcntl (lf, F_SETLK, &lock) == -1) {
  800. switch (errno) {
  801. case EINTR:
  802. goto retry_fcntl;
  803. break;
  804. case EAGAIN:
  805. case EACCES:
  806. log_printf (LOGSYS_LEVEL_ERROR, "Another Corosync instance is already running.");
  807. err = COROSYNC_DONE_ALREADY_RUNNING;
  808. goto error_close;
  809. break;
  810. default:
  811. log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't aquire lock. Error was %s",
  812. strerror(errno));
  813. err = COROSYNC_DONE_AQUIRE_LOCK;
  814. goto error_close;
  815. break;
  816. }
  817. }
  818. if (ftruncate (lf, 0) == -1) {
  819. log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't truncate lock file. Error was %s",
  820. strerror (errno));
  821. err = COROSYNC_DONE_AQUIRE_LOCK;
  822. goto error_close_unlink;
  823. }
  824. memset (pid_s, 0, sizeof (pid_s));
  825. snprintf (pid_s, sizeof (pid_s) - 1, "%u\n", pid);
  826. retry_write:
  827. if (write (lf, pid_s, strlen (pid_s)) != strlen (pid_s)) {
  828. if (errno == EINTR) {
  829. goto retry_write;
  830. } else {
  831. log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't write pid to lock file. "
  832. "Error was %s", strerror (errno));
  833. err = COROSYNC_DONE_AQUIRE_LOCK;
  834. goto error_close_unlink;
  835. }
  836. }
  837. if ((fd_flag = fcntl (lf, F_GETFD, 0)) == -1) {
  838. log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't get close-on-exec flag from lock file. "
  839. "Error was %s", strerror (errno));
  840. err = COROSYNC_DONE_AQUIRE_LOCK;
  841. goto error_close_unlink;
  842. }
  843. fd_flag |= FD_CLOEXEC;
  844. if (fcntl (lf, F_SETFD, fd_flag) == -1) {
  845. log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't set close-on-exec flag to lock file. "
  846. "Error was %s", strerror (errno));
  847. err = COROSYNC_DONE_AQUIRE_LOCK;
  848. goto error_close_unlink;
  849. }
  850. return (err);
  851. error_close_unlink:
  852. unlink (lockfile);
  853. error_close:
  854. close (lf);
  855. return (err);
  856. }
  857. int main (int argc, char **argv, char **envp)
  858. {
  859. const char *error_string;
  860. struct totem_config totem_config;
  861. int res, ch;
  862. int background, setprio;
  863. struct stat stat_out;
  864. char corosync_lib_dir[PATH_MAX];
  865. enum e_corosync_done flock_err;
  866. uint64_t totem_config_warnings;
  867. /* default configuration
  868. */
  869. background = 1;
  870. setprio = 0;
  871. while ((ch = getopt (argc, argv, "fprv")) != EOF) {
  872. switch (ch) {
  873. case 'f':
  874. background = 0;
  875. logsys_config_mode_set (NULL, LOGSYS_MODE_OUTPUT_STDERR|LOGSYS_MODE_THREADED|LOGSYS_MODE_FORK);
  876. break;
  877. case 'p':
  878. break;
  879. case 'r':
  880. setprio = 1;
  881. break;
  882. case 'v':
  883. printf ("Corosync Cluster Engine, version '%s'\n", VERSION);
  884. printf ("Copyright (c) 2006-2009 Red Hat, Inc.\n");
  885. return EXIT_SUCCESS;
  886. break;
  887. default:
  888. fprintf(stderr, \
  889. "usage:\n"\
  890. " -f : Start application in foreground.\n"\
  891. " -p : Does nothing. \n"\
  892. " -r : Set round robin realtime scheduling \n"\
  893. " -v : Display version and SVN revision of Corosync and exit.\n");
  894. return EXIT_FAILURE;
  895. }
  896. }
  897. /*
  898. * Set round robin realtime scheduling with priority 99
  899. * Lock all memory to avoid page faults which may interrupt
  900. * application healthchecking
  901. */
  902. if (setprio) {
  903. corosync_setscheduler ();
  904. }
  905. corosync_mlockall ();
  906. log_printf (LOGSYS_LEVEL_NOTICE, "Corosync Cluster Engine ('%s'): started and ready to provide service.", VERSION);
  907. log_printf (LOGSYS_LEVEL_INFO, "Corosync built-in features:" PACKAGE_FEATURES "");
  908. corosync_poll_handle = qb_loop_create ();
  909. qb_loop_signal_add(corosync_poll_handle, QB_LOOP_LOW,
  910. SIGUSR2, NULL, sig_diag_handler, NULL);
  911. qb_loop_signal_add(corosync_poll_handle, QB_LOOP_HIGH,
  912. SIGINT, NULL, sig_exit_handler, NULL);
  913. qb_loop_signal_add(corosync_poll_handle, QB_LOOP_HIGH,
  914. SIGQUIT, NULL, sig_exit_handler, NULL);
  915. qb_loop_signal_add(corosync_poll_handle, QB_LOOP_HIGH,
  916. SIGTERM, NULL, sig_exit_handler, NULL);
  917. (void)signal (SIGSEGV, sigsegv_handler);
  918. (void)signal (SIGABRT, sigabrt_handler);
  919. #if MSG_NOSIGNAL != 0
  920. (void)signal (SIGPIPE, SIG_IGN);
  921. #endif
  922. if (icmap_init() != CS_OK) {
  923. log_printf (LOGSYS_LEVEL_ERROR, "Corosync Executive couldn't initialize configuration component.");
  924. corosync_exit_error (COROSYNC_DONE_ICMAP);
  925. }
  926. set_icmap_ro_keys_flag();
  927. /*
  928. * Initialize the corosync_api_v1 definition
  929. */
  930. api = apidef_get ();
  931. res = coroparse_configparse(&error_string);
  932. if (res == -1) {
  933. log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
  934. corosync_exit_error (COROSYNC_DONE_MAINCONFIGREAD);
  935. }
  936. res = corosync_main_config_read (&error_string);
  937. if (res == -1) {
  938. /*
  939. * if we are here, we _must_ flush the logsys queue
  940. * and try to inform that we couldn't read the config.
  941. * this is a desperate attempt before certain death
  942. * and there is no guarantee that we can print to stderr
  943. * nor that logsys is sending the messages where we expect.
  944. */
  945. log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
  946. fprintf(stderr, "%s", error_string);
  947. syslog (LOGSYS_LEVEL_ERROR, "%s", error_string);
  948. corosync_exit_error (COROSYNC_DONE_MAINCONFIGREAD);
  949. }
  950. /*
  951. * Make sure required directory is present
  952. */
  953. sprintf (corosync_lib_dir, "%s/lib/corosync", LOCALSTATEDIR);
  954. res = stat (corosync_lib_dir, &stat_out);
  955. if ((res == -1) || (res == 0 && !S_ISDIR(stat_out.st_mode))) {
  956. log_printf (LOGSYS_LEVEL_ERROR, "Required directory not present %s. Please create it.", corosync_lib_dir);
  957. corosync_exit_error (COROSYNC_DONE_DIR_NOT_PRESENT);
  958. }
  959. res = totem_config_read (&totem_config, &error_string, &totem_config_warnings);
  960. if (res == -1) {
  961. log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
  962. corosync_exit_error (COROSYNC_DONE_MAINCONFIGREAD);
  963. }
  964. if (totem_config_warnings & TOTEM_CONFIG_WARNING_MEMBERS_IGNORED) {
  965. log_printf (LOGSYS_LEVEL_WARNING, "member section is used together with nodelist. Members ignored.");
  966. }
  967. if (totem_config_warnings & TOTEM_CONFIG_WARNING_MEMBERS_DEPRECATED) {
  968. log_printf (LOGSYS_LEVEL_WARNING, "member section is deprecated.");
  969. }
  970. if (totem_config_warnings & TOTEM_CONFIG_WARNING_TOTEM_NODEID_IGNORED) {
  971. log_printf (LOGSYS_LEVEL_WARNING, "nodeid appears both in totem section and nodelist. Nodelist one is used.");
  972. }
  973. if (totem_config_warnings != 0) {
  974. log_printf (LOGSYS_LEVEL_WARNING, "Please migrate config file to nodelist.");
  975. }
  976. res = totem_config_keyread (&totem_config, &error_string);
  977. if (res == -1) {
  978. log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
  979. corosync_exit_error (COROSYNC_DONE_MAINCONFIGREAD);
  980. }
  981. res = totem_config_validate (&totem_config, &error_string);
  982. if (res == -1) {
  983. log_printf (LOGSYS_LEVEL_ERROR, "%s", error_string);
  984. corosync_exit_error (COROSYNC_DONE_MAINCONFIGREAD);
  985. }
  986. totem_config.totem_logging_configuration = totem_logging_configuration;
  987. totem_config.totem_logging_configuration.log_subsys_id = _logsys_subsys_create("TOTEM", "totem");
  988. totem_config.totem_logging_configuration.log_level_security = LOGSYS_LEVEL_WARNING;
  989. totem_config.totem_logging_configuration.log_level_error = LOGSYS_LEVEL_ERROR;
  990. totem_config.totem_logging_configuration.log_level_warning = LOGSYS_LEVEL_WARNING;
  991. totem_config.totem_logging_configuration.log_level_notice = LOGSYS_LEVEL_NOTICE;
  992. totem_config.totem_logging_configuration.log_level_debug = LOGSYS_LEVEL_DEBUG;
  993. totem_config.totem_logging_configuration.log_printf = _logsys_log_printf;
  994. logsys_config_apply();
  995. /*
  996. * Now we are fully initialized.
  997. */
  998. if (background) {
  999. corosync_tty_detach ();
  1000. }
  1001. qb_log_thread_start();
  1002. if ((flock_err = corosync_flock (corosync_lock_file, getpid ())) != COROSYNC_DONE_EXIT) {
  1003. corosync_exit_error (flock_err);
  1004. }
  1005. /*
  1006. * if totempg_initialize doesn't have root priveleges, it cannot
  1007. * bind to a specific interface. This only matters if
  1008. * there is more then one interface in a system, so
  1009. * in this case, only a warning is printed
  1010. */
  1011. /*
  1012. * Join multicast group and setup delivery
  1013. * and configuration change functions
  1014. */
  1015. totempg_initialize (
  1016. corosync_poll_handle,
  1017. &totem_config);
  1018. totempg_service_ready_register (
  1019. main_service_ready);
  1020. totempg_groups_initialize (
  1021. &corosync_group_handle,
  1022. deliver_fn,
  1023. confchg_fn);
  1024. totempg_groups_join (
  1025. corosync_group_handle,
  1026. &corosync_group,
  1027. 1);
  1028. /*
  1029. * Drop root privleges to user 'corosync'
  1030. * TODO: Don't really need full root capabilities;
  1031. * needed capabilities are:
  1032. * CAP_NET_RAW (bindtodevice)
  1033. * CAP_SYS_NICE (setscheduler)
  1034. * CAP_IPC_LOCK (mlockall)
  1035. */
  1036. priv_drop ();
  1037. schedwrk_init (
  1038. serialize_lock,
  1039. serialize_unlock);
  1040. /*
  1041. * Start main processing loop
  1042. */
  1043. qb_loop_run (corosync_poll_handle);
  1044. /*
  1045. * Exit was requested
  1046. */
  1047. totempg_finalize ();
  1048. /*
  1049. * free the loop resources
  1050. */
  1051. qb_loop_destroy (corosync_poll_handle);
  1052. /*
  1053. * free up the icmap
  1054. */
  1055. /*
  1056. * Remove pid lock file
  1057. */
  1058. unlink (corosync_lock_file);
  1059. corosync_exit_error (COROSYNC_DONE_EXIT);
  1060. return EXIT_SUCCESS;
  1061. }