cfg.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. /*
  2. * Copyright (c) 2005-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2009 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. #include <config.h>
  36. #include <sys/types.h>
  37. #include <sys/uio.h>
  38. #include <sys/socket.h>
  39. #include <sys/un.h>
  40. #include <netinet/in.h>
  41. #include <arpa/inet.h>
  42. #include <unistd.h>
  43. #include <fcntl.h>
  44. #include <stdlib.h>
  45. #include <stdio.h>
  46. #include <limits.h>
  47. #include <errno.h>
  48. #include <string.h>
  49. #include <corosync/corotypes.h>
  50. #include <corosync/coroipc_types.h>
  51. #include <corosync/cfg.h>
  52. #include <corosync/list.h>
  53. #include <corosync/mar_gen.h>
  54. #include <corosync/totem/totemip.h>
  55. #include <corosync/totem/totem.h>
  56. #include <corosync/ipc_cfg.h>
  57. #include <corosync/lcr/lcr_comp.h>
  58. #include <corosync/engine/logsys.h>
  59. #include <corosync/engine/coroapi.h>
  60. #include <corosync/corodefs.h>
  61. LOGSYS_DECLARE_SUBSYS ("CFG");
  62. enum cfg_message_req_types {
  63. MESSAGE_REQ_EXEC_CFG_RINGREENABLE = 0,
  64. MESSAGE_REQ_EXEC_CFG_KILLNODE = 1,
  65. MESSAGE_REQ_EXEC_CFG_SHUTDOWN = 2,
  66. MESSAGE_REQ_EXEC_CFG_CRYPTO_SET = 3
  67. };
  68. #define DEFAULT_SHUTDOWN_TIMEOUT 5
  69. static struct list_head trackers_list;
  70. /*
  71. * Variables controlling a requested shutdown
  72. */
  73. static corosync_timer_handle_t shutdown_timer;
  74. static struct cfg_info *shutdown_con;
  75. static uint32_t shutdown_flags;
  76. static int shutdown_yes;
  77. static int shutdown_no;
  78. static int shutdown_expected;
  79. struct cfg_info
  80. {
  81. struct list_head list;
  82. void *conn;
  83. void *tracker_conn;
  84. enum {SHUTDOWN_REPLY_UNKNOWN, SHUTDOWN_REPLY_YES, SHUTDOWN_REPLY_NO} shutdown_reply;
  85. };
  86. static void cfg_confchg_fn (
  87. enum totem_configuration_type configuration_type,
  88. const unsigned int *member_list, size_t member_list_entries,
  89. const unsigned int *left_list, size_t left_list_entries,
  90. const unsigned int *joined_list, size_t joined_list_entries,
  91. const struct memb_ring_id *ring_id);
  92. static int cfg_exec_init_fn (struct corosync_api_v1 *corosync_api_v1);
  93. static struct corosync_api_v1 *api;
  94. static int cfg_lib_init_fn (void *conn);
  95. static int cfg_lib_exit_fn (void *conn);
  96. static void message_handler_req_exec_cfg_ringreenable (
  97. const void *message,
  98. unsigned int nodeid);
  99. static void message_handler_req_exec_cfg_killnode (
  100. const void *message,
  101. unsigned int nodeid);
  102. static void message_handler_req_exec_cfg_shutdown (
  103. const void *message,
  104. unsigned int nodeid);
  105. static void message_handler_req_exec_cfg_crypto_set (
  106. const void *message,
  107. unsigned int nodeid);
  108. static void exec_cfg_killnode_endian_convert (void *msg);
  109. static void message_handler_req_lib_cfg_ringstatusget (
  110. void *conn,
  111. const void *msg);
  112. static void message_handler_req_lib_cfg_ringreenable (
  113. void *conn,
  114. const void *msg);
  115. static void message_handler_req_lib_cfg_statetrack (
  116. void *conn,
  117. const void *msg);
  118. static void message_handler_req_lib_cfg_statetrackstop (
  119. void *conn,
  120. const void *msg);
  121. static void message_handler_req_lib_cfg_administrativestateset (
  122. void *conn,
  123. const void *msg);
  124. static void message_handler_req_lib_cfg_administrativestateget (
  125. void *conn,
  126. const void *msg);
  127. static void message_handler_req_lib_cfg_serviceload (
  128. void *conn,
  129. const void *msg);
  130. static void message_handler_req_lib_cfg_serviceunload (
  131. void *conn,
  132. const void *msg);
  133. static void message_handler_req_lib_cfg_killnode (
  134. void *conn,
  135. const void *msg);
  136. static void message_handler_req_lib_cfg_tryshutdown (
  137. void *conn,
  138. const void *msg);
  139. static void message_handler_req_lib_cfg_replytoshutdown (
  140. void *conn,
  141. const void *msg);
  142. static void message_handler_req_lib_cfg_get_node_addrs (
  143. void *conn,
  144. const void *msg);
  145. static void message_handler_req_lib_cfg_local_get (
  146. void *conn,
  147. const void *msg);
  148. static void message_handler_req_lib_cfg_crypto_set (
  149. void *conn,
  150. const void *msg);
  151. /*
  152. * Service Handler Definition
  153. */
  154. static struct corosync_lib_handler cfg_lib_engine[] =
  155. {
  156. { /* 0 */
  157. .lib_handler_fn = message_handler_req_lib_cfg_ringstatusget,
  158. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  159. },
  160. { /* 1 */
  161. .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
  162. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  163. },
  164. { /* 2 */
  165. .lib_handler_fn = message_handler_req_lib_cfg_statetrack,
  166. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  167. },
  168. { /* 3 */
  169. .lib_handler_fn = message_handler_req_lib_cfg_statetrackstop,
  170. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  171. },
  172. { /* 4 */
  173. .lib_handler_fn = message_handler_req_lib_cfg_administrativestateset,
  174. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  175. },
  176. { /* 5 */
  177. .lib_handler_fn = message_handler_req_lib_cfg_administrativestateget,
  178. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  179. },
  180. { /* 6 */
  181. .lib_handler_fn = message_handler_req_lib_cfg_serviceload,
  182. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  183. },
  184. { /* 7 */
  185. .lib_handler_fn = message_handler_req_lib_cfg_serviceunload,
  186. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  187. },
  188. { /* 8 */
  189. .lib_handler_fn = message_handler_req_lib_cfg_killnode,
  190. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  191. },
  192. { /* 9 */
  193. .lib_handler_fn = message_handler_req_lib_cfg_tryshutdown,
  194. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  195. },
  196. { /* 10 */
  197. .lib_handler_fn = message_handler_req_lib_cfg_replytoshutdown,
  198. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  199. },
  200. { /* 11 */
  201. .lib_handler_fn = message_handler_req_lib_cfg_get_node_addrs,
  202. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  203. },
  204. { /* 12 */
  205. .lib_handler_fn = message_handler_req_lib_cfg_local_get,
  206. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  207. },
  208. { /* 13 */
  209. .lib_handler_fn = message_handler_req_lib_cfg_crypto_set,
  210. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  211. }
  212. };
  213. static struct corosync_exec_handler cfg_exec_engine[] =
  214. {
  215. { /* 0 */
  216. .exec_handler_fn = message_handler_req_exec_cfg_ringreenable,
  217. },
  218. { /* 1 */
  219. .exec_handler_fn = message_handler_req_exec_cfg_killnode,
  220. .exec_endian_convert_fn = exec_cfg_killnode_endian_convert
  221. },
  222. { /* 2 */
  223. .exec_handler_fn = message_handler_req_exec_cfg_shutdown,
  224. },
  225. { /* 3 */
  226. .exec_handler_fn = message_handler_req_exec_cfg_crypto_set,
  227. }
  228. };
  229. /*
  230. * Exports the interface for the service
  231. */
  232. struct corosync_service_engine cfg_service_engine = {
  233. .name = "corosync configuration service",
  234. .id = CFG_SERVICE,
  235. .priority = 1,
  236. .private_data_size = sizeof(struct cfg_info),
  237. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED,
  238. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  239. .lib_init_fn = cfg_lib_init_fn,
  240. .lib_exit_fn = cfg_lib_exit_fn,
  241. .lib_engine = cfg_lib_engine,
  242. .lib_engine_count = sizeof (cfg_lib_engine) / sizeof (struct corosync_lib_handler),
  243. .exec_init_fn = cfg_exec_init_fn,
  244. .exec_engine = cfg_exec_engine,
  245. .exec_engine_count = 0, /* sizeof (cfg_aisexec_handler_fns) / sizeof (coroync_exec_handler), */
  246. .confchg_fn = cfg_confchg_fn,
  247. };
  248. /*
  249. * Dynamic Loader definition
  250. */
  251. static struct corosync_service_engine *cfg_get_service_engine_ver0 (void);
  252. static struct corosync_service_engine_iface_ver0 cfg_service_engine_iface = {
  253. .corosync_get_service_engine_ver0 = cfg_get_service_engine_ver0
  254. };
  255. static struct lcr_iface corosync_cfg_ver0[1] = {
  256. {
  257. .name = "corosync_cfg",
  258. .version = 0,
  259. .versions_replace = 0,
  260. .versions_replace_count = 0,
  261. .dependencies = 0,
  262. .dependency_count = 0,
  263. .constructor = NULL,
  264. .destructor = NULL,
  265. .interfaces = NULL
  266. }
  267. };
  268. static struct lcr_comp cfg_comp_ver0 = {
  269. .iface_count = 1,
  270. .ifaces = corosync_cfg_ver0
  271. };
  272. static struct corosync_service_engine *cfg_get_service_engine_ver0 (void)
  273. {
  274. return (&cfg_service_engine);
  275. }
  276. #ifdef COROSYNC_SOLARIS
  277. void corosync_lcr_component_register (void);
  278. void corosync_lcr_component_register (void) {
  279. #else
  280. __attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
  281. #endif
  282. lcr_interfaces_set (&corosync_cfg_ver0[0], &cfg_service_engine_iface);
  283. lcr_component_register (&cfg_comp_ver0);
  284. }
  285. struct req_exec_cfg_ringreenable {
  286. coroipc_request_header_t header __attribute__((aligned(8)));
  287. mar_message_source_t source __attribute__((aligned(8)));
  288. };
  289. struct req_exec_cfg_killnode {
  290. coroipc_request_header_t header __attribute__((aligned(8)));
  291. mar_uint32_t nodeid __attribute__((aligned(8)));
  292. mar_name_t reason __attribute__((aligned(8)));
  293. };
  294. struct req_exec_cfg_crypto_set {
  295. coroipc_request_header_t header __attribute__((aligned(8)));
  296. mar_uint32_t type __attribute__((aligned(8)));
  297. };
  298. struct req_exec_cfg_shutdown {
  299. coroipc_request_header_t header __attribute__((aligned(8)));
  300. };
  301. /* IMPL */
  302. static int cfg_exec_init_fn (
  303. struct corosync_api_v1 *corosync_api_v1)
  304. {
  305. api = corosync_api_v1;
  306. list_init(&trackers_list);
  307. return (0);
  308. }
  309. static void cfg_confchg_fn (
  310. enum totem_configuration_type configuration_type,
  311. const unsigned int *member_list, size_t member_list_entries,
  312. const unsigned int *left_list, size_t left_list_entries,
  313. const unsigned int *joined_list, size_t joined_list_entries,
  314. const struct memb_ring_id *ring_id)
  315. {
  316. }
  317. /*
  318. * Tell other nodes we are shutting down
  319. */
  320. static int send_shutdown(void)
  321. {
  322. struct req_exec_cfg_shutdown req_exec_cfg_shutdown;
  323. struct iovec iovec;
  324. ENTER();
  325. req_exec_cfg_shutdown.header.size =
  326. sizeof (struct req_exec_cfg_shutdown);
  327. req_exec_cfg_shutdown.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  328. MESSAGE_REQ_EXEC_CFG_SHUTDOWN);
  329. iovec.iov_base = (char *)&req_exec_cfg_shutdown;
  330. iovec.iov_len = sizeof (struct req_exec_cfg_shutdown);
  331. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  332. LEAVE();
  333. return 0;
  334. }
  335. static void send_test_shutdown(void *only_conn, void *exclude_conn, int status)
  336. {
  337. struct res_lib_cfg_testshutdown res_lib_cfg_testshutdown;
  338. struct list_head *iter;
  339. ENTER();
  340. res_lib_cfg_testshutdown.header.size = sizeof(struct res_lib_cfg_testshutdown);
  341. res_lib_cfg_testshutdown.header.id = MESSAGE_RES_CFG_TESTSHUTDOWN;
  342. res_lib_cfg_testshutdown.header.error = status;
  343. res_lib_cfg_testshutdown.flags = shutdown_flags;
  344. if (only_conn) {
  345. TRACE1("sending testshutdown to only %p", only_conn);
  346. api->ipc_dispatch_send(only_conn, &res_lib_cfg_testshutdown,
  347. sizeof(res_lib_cfg_testshutdown));
  348. } else {
  349. for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
  350. struct cfg_info *ci = list_entry(iter, struct cfg_info, list);
  351. if (ci->conn != exclude_conn) {
  352. TRACE1("sending testshutdown to %p", ci->tracker_conn);
  353. api->ipc_dispatch_send(ci->tracker_conn, &res_lib_cfg_testshutdown,
  354. sizeof(res_lib_cfg_testshutdown));
  355. }
  356. }
  357. }
  358. LEAVE();
  359. }
  360. static void check_shutdown_status(void)
  361. {
  362. ENTER();
  363. /*
  364. * Shutdown client might have gone away
  365. */
  366. if (!shutdown_con) {
  367. LEAVE();
  368. return;
  369. }
  370. /*
  371. * All replies safely gathered in ?
  372. */
  373. if (shutdown_yes + shutdown_no >= shutdown_expected) {
  374. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  375. api->timer_delete(shutdown_timer);
  376. if (shutdown_yes >= shutdown_expected ||
  377. shutdown_flags == CFG_SHUTDOWN_FLAG_REGARDLESS) {
  378. TRACE1("shutdown confirmed");
  379. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  380. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  381. res_lib_cfg_tryshutdown.header.error = CS_OK;
  382. /*
  383. * Tell originator that shutdown was confirmed
  384. */
  385. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  386. sizeof(res_lib_cfg_tryshutdown));
  387. shutdown_con = NULL;
  388. /*
  389. * Tell other nodes we are going down
  390. */
  391. send_shutdown();
  392. }
  393. else {
  394. TRACE1("shutdown cancelled");
  395. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  396. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  397. res_lib_cfg_tryshutdown.header.error = CS_ERR_BUSY;
  398. /*
  399. * Tell originator that shutdown was cancelled
  400. */
  401. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  402. sizeof(res_lib_cfg_tryshutdown));
  403. shutdown_con = NULL;
  404. }
  405. log_printf(LOGSYS_LEVEL_DEBUG, "shutdown decision is: (yes count: %d, no count: %d) flags=%x\n", shutdown_yes, shutdown_no, shutdown_flags);
  406. }
  407. LEAVE();
  408. }
  409. /*
  410. * Not all nodes responded to the shutdown (in time)
  411. */
  412. static void shutdown_timer_fn(void *arg)
  413. {
  414. ENTER();
  415. /*
  416. * Mark undecideds as "NO"
  417. */
  418. shutdown_no = shutdown_expected;
  419. check_shutdown_status();
  420. send_test_shutdown(NULL, NULL, CS_ERR_TIMEOUT);
  421. LEAVE();
  422. }
  423. static void remove_ci_from_shutdown(struct cfg_info *ci)
  424. {
  425. ENTER();
  426. /*
  427. * If the controlling shutdown process has quit, then cancel the
  428. * shutdown session
  429. */
  430. if (ci == shutdown_con) {
  431. shutdown_con = NULL;
  432. api->timer_delete(shutdown_timer);
  433. }
  434. if (!list_empty(&ci->list)) {
  435. list_del(&ci->list);
  436. list_init(&ci->list);
  437. /*
  438. * Remove our option
  439. */
  440. if (shutdown_con) {
  441. if (ci->shutdown_reply == SHUTDOWN_REPLY_YES)
  442. shutdown_yes--;
  443. if (ci->shutdown_reply == SHUTDOWN_REPLY_NO)
  444. shutdown_no--;
  445. }
  446. /*
  447. * If we are leaving, then that's an implicit YES to shutdown
  448. */
  449. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  450. shutdown_yes++;
  451. check_shutdown_status();
  452. }
  453. LEAVE();
  454. }
  455. int cfg_lib_exit_fn (void *conn)
  456. {
  457. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  458. ENTER();
  459. if (!list_empty(&ci->list)) {
  460. list_del(&ci->list);
  461. remove_ci_from_shutdown(ci);
  462. }
  463. LEAVE();
  464. return (0);
  465. }
  466. static int cfg_lib_init_fn (void *conn)
  467. {
  468. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  469. ENTER();
  470. list_init(&ci->list);
  471. LEAVE();
  472. return (0);
  473. }
  474. /*
  475. * Executive message handlers
  476. */
  477. static void message_handler_req_exec_cfg_ringreenable (
  478. const void *message,
  479. unsigned int nodeid)
  480. {
  481. const struct req_exec_cfg_ringreenable *req_exec_cfg_ringreenable
  482. = message;
  483. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  484. ENTER();
  485. api->totem_ring_reenable ();
  486. if (api->ipc_source_is_local(&req_exec_cfg_ringreenable->source)) {
  487. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  488. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  489. res_lib_cfg_ringreenable.header.error = CS_OK;
  490. api->ipc_response_send (
  491. req_exec_cfg_ringreenable->source.conn,
  492. &res_lib_cfg_ringreenable,
  493. sizeof (struct res_lib_cfg_ringreenable));
  494. }
  495. LEAVE();
  496. }
  497. static void exec_cfg_killnode_endian_convert (void *msg)
  498. {
  499. struct req_exec_cfg_killnode *req_exec_cfg_killnode =
  500. (struct req_exec_cfg_killnode *)msg;
  501. ENTER();
  502. swab_mar_name_t(&req_exec_cfg_killnode->reason);
  503. LEAVE();
  504. }
  505. static void message_handler_req_exec_cfg_killnode (
  506. const void *message,
  507. unsigned int nodeid)
  508. {
  509. const struct req_exec_cfg_killnode *req_exec_cfg_killnode = message;
  510. cs_name_t reason;
  511. ENTER();
  512. log_printf(LOGSYS_LEVEL_DEBUG, "request to kill node %d(us=%d): %s\n", req_exec_cfg_killnode->nodeid, api->totem_nodeid_get(), reason.value);
  513. if (req_exec_cfg_killnode->nodeid == api->totem_nodeid_get()) {
  514. marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
  515. log_printf(LOGSYS_LEVEL_NOTICE, "Killed by node %d: %s\n",
  516. nodeid, reason.value);
  517. corosync_fatal_error(COROSYNC_FATAL_ERROR_EXIT);
  518. }
  519. LEAVE();
  520. }
  521. /*
  522. * Self shutdown
  523. */
  524. static void message_handler_req_exec_cfg_shutdown (
  525. const void *message,
  526. unsigned int nodeid)
  527. {
  528. ENTER();
  529. log_printf(LOGSYS_LEVEL_NOTICE, "Node %d was shut down by sysadmin\n", nodeid);
  530. if (nodeid == api->totem_nodeid_get()) {
  531. api->request_shutdown();
  532. }
  533. LEAVE();
  534. }
  535. static void message_handler_req_exec_cfg_crypto_set (
  536. const void *message,
  537. unsigned int nodeid)
  538. {
  539. const struct req_exec_cfg_crypto_set *req_exec_cfg_crypto_set = message;
  540. ENTER();
  541. log_printf(LOGSYS_LEVEL_NOTICE, "Node %d requested set crypto to %d\n", nodeid, req_exec_cfg_crypto_set->type);
  542. api->totem_crypto_set(req_exec_cfg_crypto_set->type);
  543. LEAVE();
  544. }
  545. /*
  546. * Library Interface Implementation
  547. */
  548. static void message_handler_req_lib_cfg_ringstatusget (
  549. void *conn,
  550. const void *msg)
  551. {
  552. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  553. struct totem_ip_address interfaces[INTERFACE_MAX];
  554. unsigned int iface_count;
  555. char **status;
  556. const char *totem_ip_string;
  557. unsigned int i;
  558. ENTER();
  559. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  560. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  561. res_lib_cfg_ringstatusget.header.error = CS_OK;
  562. api->totem_ifaces_get (
  563. api->totem_nodeid_get(),
  564. interfaces,
  565. &status,
  566. &iface_count);
  567. res_lib_cfg_ringstatusget.interface_count = iface_count;
  568. for (i = 0; i < iface_count; i++) {
  569. totem_ip_string
  570. = (const char *)api->totem_ip_print (&interfaces[i]);
  571. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  572. status[i]);
  573. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  574. totem_ip_string);
  575. }
  576. api->ipc_response_send (
  577. conn,
  578. &res_lib_cfg_ringstatusget,
  579. sizeof (struct res_lib_cfg_ringstatusget));
  580. LEAVE();
  581. }
  582. static void message_handler_req_lib_cfg_ringreenable (
  583. void *conn,
  584. const void *msg)
  585. {
  586. struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
  587. struct iovec iovec;
  588. ENTER();
  589. req_exec_cfg_ringreenable.header.size =
  590. sizeof (struct req_exec_cfg_ringreenable);
  591. req_exec_cfg_ringreenable.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  592. MESSAGE_REQ_EXEC_CFG_RINGREENABLE);
  593. api->ipc_source_set (&req_exec_cfg_ringreenable.source, conn);
  594. iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
  595. iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
  596. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  597. LEAVE();
  598. }
  599. static void message_handler_req_lib_cfg_statetrack (
  600. void *conn,
  601. const void *msg)
  602. {
  603. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  604. struct res_lib_cfg_statetrack res_lib_cfg_statetrack;
  605. ENTER();
  606. /*
  607. * We only do shutdown tracking at the moment
  608. */
  609. if (list_empty(&ci->list)) {
  610. list_add(&ci->list, &trackers_list);
  611. ci->tracker_conn = conn;
  612. if (shutdown_con) {
  613. /*
  614. * Shutdown already in progress, ask the newcomer's opinion
  615. */
  616. ci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  617. shutdown_expected++;
  618. send_test_shutdown(conn, NULL, CS_OK);
  619. }
  620. }
  621. res_lib_cfg_statetrack.header.size = sizeof(struct res_lib_cfg_statetrack);
  622. res_lib_cfg_statetrack.header.id = MESSAGE_RES_CFG_STATETRACKSTART;
  623. res_lib_cfg_statetrack.header.error = CS_OK;
  624. api->ipc_response_send(conn, &res_lib_cfg_statetrack,
  625. sizeof(res_lib_cfg_statetrack));
  626. LEAVE();
  627. }
  628. static void message_handler_req_lib_cfg_statetrackstop (
  629. void *conn,
  630. const void *msg)
  631. {
  632. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  633. // struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
  634. ENTER();
  635. remove_ci_from_shutdown(ci);
  636. LEAVE();
  637. }
  638. static void message_handler_req_lib_cfg_administrativestateset (
  639. void *conn,
  640. const void *msg)
  641. {
  642. // struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
  643. ENTER();
  644. LEAVE();
  645. }
  646. static void message_handler_req_lib_cfg_administrativestateget (
  647. void *conn,
  648. const void *msg)
  649. {
  650. // struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;
  651. ENTER();
  652. LEAVE();
  653. }
  654. static void message_handler_req_lib_cfg_serviceload (
  655. void *conn,
  656. const void *msg)
  657. {
  658. const struct req_lib_cfg_serviceload *req_lib_cfg_serviceload = msg;
  659. struct res_lib_cfg_serviceload res_lib_cfg_serviceload;
  660. ENTER();
  661. api->service_link_and_init (
  662. api,
  663. (const char *)req_lib_cfg_serviceload->service_name,
  664. req_lib_cfg_serviceload->service_ver);
  665. res_lib_cfg_serviceload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  666. res_lib_cfg_serviceload.header.size = sizeof (struct res_lib_cfg_serviceload);
  667. res_lib_cfg_serviceload.header.error = CS_OK;
  668. api->ipc_response_send (
  669. conn,
  670. &res_lib_cfg_serviceload,
  671. sizeof (struct res_lib_cfg_serviceload));
  672. LEAVE();
  673. }
  674. static void message_handler_req_lib_cfg_serviceunload (
  675. void *conn,
  676. const void *msg)
  677. {
  678. const struct req_lib_cfg_serviceunload *req_lib_cfg_serviceunload = msg;
  679. struct res_lib_cfg_serviceunload res_lib_cfg_serviceunload;
  680. ENTER();
  681. api->service_unlink_and_exit (
  682. api,
  683. (const char *)req_lib_cfg_serviceunload->service_name,
  684. req_lib_cfg_serviceunload->service_ver);
  685. res_lib_cfg_serviceunload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  686. res_lib_cfg_serviceunload.header.size = sizeof (struct res_lib_cfg_serviceunload);
  687. res_lib_cfg_serviceunload.header.error = CS_OK;
  688. api->ipc_response_send (
  689. conn,
  690. &res_lib_cfg_serviceunload,
  691. sizeof (struct res_lib_cfg_serviceunload));
  692. LEAVE();
  693. }
  694. static void message_handler_req_lib_cfg_killnode (
  695. void *conn,
  696. const void *msg)
  697. {
  698. const struct req_lib_cfg_killnode *req_lib_cfg_killnode = msg;
  699. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  700. struct req_exec_cfg_killnode req_exec_cfg_killnode;
  701. struct iovec iovec;
  702. int res;
  703. ENTER();
  704. req_exec_cfg_killnode.header.size =
  705. sizeof (struct req_exec_cfg_killnode);
  706. req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  707. MESSAGE_REQ_EXEC_CFG_KILLNODE);
  708. req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
  709. marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
  710. iovec.iov_base = (char *)&req_exec_cfg_killnode;
  711. iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
  712. res = api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  713. res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
  714. res_lib_cfg_killnode.header.id = MESSAGE_RES_CFG_KILLNODE;
  715. res_lib_cfg_killnode.header.error = CS_OK;
  716. api->ipc_response_send(conn, &res_lib_cfg_killnode,
  717. sizeof(res_lib_cfg_killnode));
  718. LEAVE();
  719. }
  720. static void message_handler_req_lib_cfg_tryshutdown (
  721. void *conn,
  722. const void *msg)
  723. {
  724. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  725. const struct req_lib_cfg_tryshutdown *req_lib_cfg_tryshutdown = msg;
  726. struct list_head *iter;
  727. ENTER();
  728. if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
  729. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  730. /*
  731. * Tell other nodes
  732. */
  733. send_shutdown();
  734. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  735. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  736. res_lib_cfg_tryshutdown.header.error = CS_OK;
  737. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  738. sizeof(res_lib_cfg_tryshutdown));
  739. LEAVE();
  740. return;
  741. }
  742. /*
  743. * Shutdown in progress, return an error
  744. */
  745. if (shutdown_con) {
  746. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  747. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  748. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  749. res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
  750. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  751. sizeof(res_lib_cfg_tryshutdown));
  752. LEAVE();
  753. return;
  754. }
  755. ci->conn = conn;
  756. shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
  757. shutdown_flags = req_lib_cfg_tryshutdown->flags;
  758. shutdown_yes = 0;
  759. shutdown_no = 0;
  760. /*
  761. * Count the number of listeners
  762. */
  763. shutdown_expected = 0;
  764. for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
  765. struct cfg_info *testci = list_entry(iter, struct cfg_info, list);
  766. /*
  767. * It is assumed that we will allow shutdown
  768. */
  769. if (testci != ci) {
  770. testci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  771. shutdown_expected++;
  772. }
  773. }
  774. /*
  775. * If no-one is listening for events then we can just go down now
  776. */
  777. if (shutdown_expected == 0) {
  778. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  779. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  780. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  781. res_lib_cfg_tryshutdown.header.error = CS_OK;
  782. /*
  783. * Tell originator that shutdown was confirmed
  784. */
  785. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  786. sizeof(res_lib_cfg_tryshutdown));
  787. send_shutdown();
  788. LEAVE();
  789. return;
  790. }
  791. else {
  792. hdb_handle_t cfg_handle;
  793. hdb_handle_t find_handle;
  794. char *timeout_str;
  795. unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
  796. /*
  797. * Look for a shutdown timeout in objdb
  798. */
  799. api->object_find_create(OBJECT_PARENT_HANDLE, "cfg", strlen("cfg"), &find_handle);
  800. api->object_find_next(find_handle, &cfg_handle);
  801. api->object_find_destroy(find_handle);
  802. if (cfg_handle) {
  803. if ( !api->object_key_get(cfg_handle,
  804. "shutdown_timeout",
  805. strlen("shutdown_timeout"),
  806. (void *)&timeout_str,
  807. NULL)) {
  808. shutdown_timeout = atoi(timeout_str);
  809. }
  810. }
  811. /*
  812. * Start the timer. If we don't get a full set of replies before this goes
  813. * off we'll cancel the shutdown
  814. */
  815. api->timer_add_duration((unsigned long long)shutdown_timeout*1000000000, NULL,
  816. shutdown_timer_fn, &shutdown_timer);
  817. /*
  818. * Tell the users we would like to shut down
  819. */
  820. send_test_shutdown(NULL, conn, CS_OK);
  821. }
  822. /*
  823. * We don't sent a reply to the caller here.
  824. * We send it when we know if we can shut down or not
  825. */
  826. LEAVE();
  827. }
  828. static void message_handler_req_lib_cfg_replytoshutdown (
  829. void *conn,
  830. const void *msg)
  831. {
  832. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  833. const struct req_lib_cfg_replytoshutdown *req_lib_cfg_replytoshutdown = msg;
  834. struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
  835. int status = CS_OK;
  836. ENTER();
  837. if (!shutdown_con) {
  838. status = CS_ERR_ACCESS;
  839. goto exit_fn;
  840. }
  841. if (req_lib_cfg_replytoshutdown->response) {
  842. shutdown_yes++;
  843. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  844. }
  845. else {
  846. shutdown_no++;
  847. ci->shutdown_reply = SHUTDOWN_REPLY_NO;
  848. }
  849. check_shutdown_status();
  850. exit_fn:
  851. res_lib_cfg_replytoshutdown.header.error = status;
  852. res_lib_cfg_replytoshutdown.header.id = MESSAGE_RES_CFG_REPLYTOSHUTDOWN;
  853. res_lib_cfg_replytoshutdown.header.size = sizeof(res_lib_cfg_replytoshutdown);
  854. api->ipc_response_send(conn, &res_lib_cfg_replytoshutdown,
  855. sizeof(res_lib_cfg_replytoshutdown));
  856. LEAVE();
  857. }
  858. static void message_handler_req_lib_cfg_get_node_addrs (void *conn,
  859. const void *msg)
  860. {
  861. struct totem_ip_address node_ifs[INTERFACE_MAX];
  862. char buf[PIPE_BUF];
  863. char **status;
  864. unsigned int num_interfaces = 0;
  865. int ret = CS_OK;
  866. int i;
  867. const struct req_lib_cfg_get_node_addrs *req_lib_cfg_get_node_addrs = msg;
  868. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)buf;
  869. unsigned int nodeid = req_lib_cfg_get_node_addrs->nodeid;
  870. if (nodeid == 0)
  871. nodeid = api->totem_nodeid_get();
  872. api->totem_ifaces_get(nodeid, node_ifs, &status, &num_interfaces);
  873. res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
  874. res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
  875. res_lib_cfg_get_node_addrs->header.error = ret;
  876. res_lib_cfg_get_node_addrs->num_addrs = num_interfaces;
  877. if (num_interfaces) {
  878. res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
  879. for (i = 0; i<num_interfaces; i++) {
  880. memcpy(&res_lib_cfg_get_node_addrs->addrs[i][0], node_ifs[i].addr, TOTEMIP_ADDRLEN);
  881. }
  882. }
  883. else {
  884. res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
  885. }
  886. api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
  887. }
  888. static void message_handler_req_lib_cfg_local_get (void *conn, const void *msg)
  889. {
  890. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  891. res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
  892. res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
  893. res_lib_cfg_local_get.header.error = CS_OK;
  894. res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
  895. api->ipc_response_send(conn, &res_lib_cfg_local_get,
  896. sizeof(res_lib_cfg_local_get));
  897. }
  898. static void message_handler_req_lib_cfg_crypto_set (
  899. void *conn,
  900. const void *msg)
  901. {
  902. const struct req_lib_cfg_crypto_set *req_lib_cfg_crypto_set = msg;
  903. struct res_lib_cfg_crypto_set res_lib_cfg_crypto_set;
  904. struct req_exec_cfg_crypto_set req_exec_cfg_crypto_set;
  905. struct iovec iovec;
  906. int ret = CS_ERR_INVALID_PARAM;
  907. req_exec_cfg_crypto_set.header.size =
  908. sizeof (struct req_exec_cfg_crypto_set);
  909. req_exec_cfg_crypto_set.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  910. MESSAGE_REQ_EXEC_CFG_CRYPTO_SET);
  911. /*
  912. * Set it locally first so we can tell if it is allowed
  913. */
  914. if (api->totem_crypto_set(req_lib_cfg_crypto_set->type) == 0) {
  915. req_exec_cfg_crypto_set.type = req_lib_cfg_crypto_set->type;
  916. iovec.iov_base = (char *)&req_exec_cfg_crypto_set;
  917. iovec.iov_len = sizeof (struct req_exec_cfg_crypto_set);
  918. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  919. ret = CS_OK;
  920. }
  921. res_lib_cfg_crypto_set.header.size = sizeof(res_lib_cfg_crypto_set);
  922. res_lib_cfg_crypto_set.header.id = MESSAGE_RES_CFG_CRYPTO_SET;
  923. res_lib_cfg_crypto_set.header.error = ret;
  924. api->ipc_response_send(conn, &res_lib_cfg_crypto_set,
  925. sizeof(res_lib_cfg_crypto_set));
  926. }