main.c 35 KB

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