cfg.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159
  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 = sizeof (cfg_exec_engine) / sizeof (struct corosync_exec_handler),
  246. .confchg_fn = cfg_confchg_fn,
  247. .sync_mode = CS_SYNC_V1
  248. };
  249. /*
  250. * Dynamic Loader definition
  251. */
  252. static struct corosync_service_engine *cfg_get_service_engine_ver0 (void);
  253. static struct corosync_service_engine_iface_ver0 cfg_service_engine_iface = {
  254. .corosync_get_service_engine_ver0 = cfg_get_service_engine_ver0
  255. };
  256. static struct lcr_iface corosync_cfg_ver0[1] = {
  257. {
  258. .name = "corosync_cfg",
  259. .version = 0,
  260. .versions_replace = 0,
  261. .versions_replace_count = 0,
  262. .dependencies = 0,
  263. .dependency_count = 0,
  264. .constructor = NULL,
  265. .destructor = NULL,
  266. .interfaces = NULL
  267. }
  268. };
  269. static struct lcr_comp cfg_comp_ver0 = {
  270. .iface_count = 1,
  271. .ifaces = corosync_cfg_ver0
  272. };
  273. static struct corosync_service_engine *cfg_get_service_engine_ver0 (void)
  274. {
  275. return (&cfg_service_engine);
  276. }
  277. #ifdef COROSYNC_SOLARIS
  278. void corosync_lcr_component_register (void);
  279. void corosync_lcr_component_register (void) {
  280. #else
  281. __attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
  282. #endif
  283. lcr_interfaces_set (&corosync_cfg_ver0[0], &cfg_service_engine_iface);
  284. lcr_component_register (&cfg_comp_ver0);
  285. }
  286. struct req_exec_cfg_ringreenable {
  287. coroipc_request_header_t header __attribute__((aligned(8)));
  288. mar_message_source_t source __attribute__((aligned(8)));
  289. };
  290. struct req_exec_cfg_killnode {
  291. coroipc_request_header_t header __attribute__((aligned(8)));
  292. mar_uint32_t nodeid __attribute__((aligned(8)));
  293. mar_name_t reason __attribute__((aligned(8)));
  294. };
  295. struct req_exec_cfg_crypto_set {
  296. coroipc_request_header_t header __attribute__((aligned(8)));
  297. mar_uint32_t type __attribute__((aligned(8)));
  298. };
  299. struct req_exec_cfg_shutdown {
  300. coroipc_request_header_t header __attribute__((aligned(8)));
  301. };
  302. /* IMPL */
  303. static int cfg_exec_init_fn (
  304. struct corosync_api_v1 *corosync_api_v1)
  305. {
  306. #ifdef COROSYNC_SOLARIS
  307. logsys_subsys_init();
  308. #endif
  309. api = corosync_api_v1;
  310. list_init(&trackers_list);
  311. return (0);
  312. }
  313. static void cfg_confchg_fn (
  314. enum totem_configuration_type configuration_type,
  315. const unsigned int *member_list, size_t member_list_entries,
  316. const unsigned int *left_list, size_t left_list_entries,
  317. const unsigned int *joined_list, size_t joined_list_entries,
  318. const struct memb_ring_id *ring_id)
  319. {
  320. }
  321. /*
  322. * Tell other nodes we are shutting down
  323. */
  324. static int send_shutdown(void)
  325. {
  326. struct req_exec_cfg_shutdown req_exec_cfg_shutdown;
  327. struct iovec iovec;
  328. int result;
  329. ENTER();
  330. req_exec_cfg_shutdown.header.size =
  331. sizeof (struct req_exec_cfg_shutdown);
  332. req_exec_cfg_shutdown.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  333. MESSAGE_REQ_EXEC_CFG_SHUTDOWN);
  334. iovec.iov_base = (char *)&req_exec_cfg_shutdown;
  335. iovec.iov_len = sizeof (struct req_exec_cfg_shutdown);
  336. result = api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  337. LEAVE();
  338. return (result);
  339. }
  340. static void send_test_shutdown(void *only_conn, void *exclude_conn, int status)
  341. {
  342. struct res_lib_cfg_testshutdown res_lib_cfg_testshutdown;
  343. struct list_head *iter;
  344. ENTER();
  345. res_lib_cfg_testshutdown.header.size = sizeof(struct res_lib_cfg_testshutdown);
  346. res_lib_cfg_testshutdown.header.id = MESSAGE_RES_CFG_TESTSHUTDOWN;
  347. res_lib_cfg_testshutdown.header.error = status;
  348. res_lib_cfg_testshutdown.flags = shutdown_flags;
  349. if (only_conn) {
  350. TRACE1("sending testshutdown to only %p", only_conn);
  351. api->ipc_dispatch_send(only_conn, &res_lib_cfg_testshutdown,
  352. sizeof(res_lib_cfg_testshutdown));
  353. } else {
  354. for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
  355. struct cfg_info *ci = list_entry(iter, struct cfg_info, list);
  356. if (ci->conn != exclude_conn) {
  357. TRACE1("sending testshutdown to %p", ci->tracker_conn);
  358. api->ipc_dispatch_send(ci->tracker_conn, &res_lib_cfg_testshutdown,
  359. sizeof(res_lib_cfg_testshutdown));
  360. }
  361. }
  362. }
  363. LEAVE();
  364. }
  365. static void check_shutdown_status(void)
  366. {
  367. int result;
  368. cs_error_t error = CS_OK;
  369. ENTER();
  370. /*
  371. * Shutdown client might have gone away
  372. */
  373. if (!shutdown_con) {
  374. LEAVE();
  375. return;
  376. }
  377. /*
  378. * All replies safely gathered in ?
  379. */
  380. if (shutdown_yes + shutdown_no >= shutdown_expected) {
  381. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  382. api->timer_delete(shutdown_timer);
  383. if (shutdown_yes >= shutdown_expected ||
  384. shutdown_flags == CFG_SHUTDOWN_FLAG_REGARDLESS) {
  385. TRACE1("shutdown confirmed");
  386. /*
  387. * Tell other nodes we are going down
  388. */
  389. result = send_shutdown();
  390. if (result == -1) {
  391. error = CS_ERR_TRY_AGAIN;
  392. }
  393. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  394. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  395. res_lib_cfg_tryshutdown.header.error = error;
  396. /*
  397. * Tell originator that shutdown was confirmed
  398. */
  399. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  400. sizeof(res_lib_cfg_tryshutdown));
  401. shutdown_con = NULL;
  402. }
  403. else {
  404. TRACE1("shutdown cancelled");
  405. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  406. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  407. res_lib_cfg_tryshutdown.header.error = CS_ERR_BUSY;
  408. /*
  409. * Tell originator that shutdown was cancelled
  410. */
  411. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  412. sizeof(res_lib_cfg_tryshutdown));
  413. shutdown_con = NULL;
  414. }
  415. log_printf(LOGSYS_LEVEL_DEBUG, "shutdown decision is: (yes count: %d, no count: %d) flags=%x\n", shutdown_yes, shutdown_no, shutdown_flags);
  416. }
  417. LEAVE();
  418. }
  419. /*
  420. * Not all nodes responded to the shutdown (in time)
  421. */
  422. static void shutdown_timer_fn(void *arg)
  423. {
  424. ENTER();
  425. /*
  426. * Mark undecideds as "NO"
  427. */
  428. shutdown_no = shutdown_expected;
  429. check_shutdown_status();
  430. send_test_shutdown(NULL, NULL, CS_ERR_TIMEOUT);
  431. LEAVE();
  432. }
  433. static void remove_ci_from_shutdown(struct cfg_info *ci)
  434. {
  435. ENTER();
  436. /*
  437. * If the controlling shutdown process has quit, then cancel the
  438. * shutdown session
  439. */
  440. if (ci == shutdown_con) {
  441. shutdown_con = NULL;
  442. api->timer_delete(shutdown_timer);
  443. }
  444. if (!list_empty(&ci->list)) {
  445. list_del(&ci->list);
  446. list_init(&ci->list);
  447. /*
  448. * Remove our option
  449. */
  450. if (shutdown_con) {
  451. if (ci->shutdown_reply == SHUTDOWN_REPLY_YES)
  452. shutdown_yes--;
  453. if (ci->shutdown_reply == SHUTDOWN_REPLY_NO)
  454. shutdown_no--;
  455. }
  456. /*
  457. * If we are leaving, then that's an implicit YES to shutdown
  458. */
  459. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  460. shutdown_yes++;
  461. check_shutdown_status();
  462. }
  463. LEAVE();
  464. }
  465. int cfg_lib_exit_fn (void *conn)
  466. {
  467. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  468. ENTER();
  469. remove_ci_from_shutdown(ci);
  470. LEAVE();
  471. return (0);
  472. }
  473. static int cfg_lib_init_fn (void *conn)
  474. {
  475. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  476. ENTER();
  477. list_init(&ci->list);
  478. LEAVE();
  479. return (0);
  480. }
  481. /*
  482. * Executive message handlers
  483. */
  484. static void message_handler_req_exec_cfg_ringreenable (
  485. const void *message,
  486. unsigned int nodeid)
  487. {
  488. const struct req_exec_cfg_ringreenable *req_exec_cfg_ringreenable
  489. = message;
  490. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  491. ENTER();
  492. api->totem_ring_reenable ();
  493. if (api->ipc_source_is_local(&req_exec_cfg_ringreenable->source)) {
  494. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  495. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  496. res_lib_cfg_ringreenable.header.error = CS_OK;
  497. api->ipc_response_send (
  498. req_exec_cfg_ringreenable->source.conn,
  499. &res_lib_cfg_ringreenable,
  500. sizeof (struct res_lib_cfg_ringreenable));
  501. api->ipc_refcnt_dec(req_exec_cfg_ringreenable->source.conn);
  502. }
  503. LEAVE();
  504. }
  505. static void exec_cfg_killnode_endian_convert (void *msg)
  506. {
  507. struct req_exec_cfg_killnode *req_exec_cfg_killnode =
  508. (struct req_exec_cfg_killnode *)msg;
  509. ENTER();
  510. swab_mar_name_t(&req_exec_cfg_killnode->reason);
  511. LEAVE();
  512. }
  513. static void message_handler_req_exec_cfg_killnode (
  514. const void *message,
  515. unsigned int nodeid)
  516. {
  517. const struct req_exec_cfg_killnode *req_exec_cfg_killnode = message;
  518. cs_name_t reason;
  519. ENTER();
  520. 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);
  521. if (req_exec_cfg_killnode->nodeid == api->totem_nodeid_get()) {
  522. marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
  523. log_printf(LOGSYS_LEVEL_NOTICE, "Killed by node %d: %s\n",
  524. nodeid, reason.value);
  525. corosync_fatal_error(COROSYNC_FATAL_ERROR_EXIT);
  526. }
  527. LEAVE();
  528. }
  529. /*
  530. * Self shutdown
  531. */
  532. static void message_handler_req_exec_cfg_shutdown (
  533. const void *message,
  534. unsigned int nodeid)
  535. {
  536. ENTER();
  537. log_printf(LOGSYS_LEVEL_NOTICE, "Node %d was shut down by sysadmin\n", nodeid);
  538. if (nodeid == api->totem_nodeid_get()) {
  539. api->shutdown_request();
  540. }
  541. LEAVE();
  542. }
  543. static void message_handler_req_exec_cfg_crypto_set (
  544. const void *message,
  545. unsigned int nodeid)
  546. {
  547. const struct req_exec_cfg_crypto_set *req_exec_cfg_crypto_set = message;
  548. ENTER();
  549. log_printf(LOGSYS_LEVEL_NOTICE, "Node %d requested set crypto to %d\n", nodeid, req_exec_cfg_crypto_set->type);
  550. api->totem_crypto_set(req_exec_cfg_crypto_set->type);
  551. LEAVE();
  552. }
  553. /*
  554. * Library Interface Implementation
  555. */
  556. static void message_handler_req_lib_cfg_ringstatusget (
  557. void *conn,
  558. const void *msg)
  559. {
  560. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  561. struct totem_ip_address interfaces[INTERFACE_MAX];
  562. unsigned int iface_count;
  563. char **status;
  564. const char *totem_ip_string;
  565. unsigned int i;
  566. ENTER();
  567. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  568. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  569. res_lib_cfg_ringstatusget.header.error = CS_OK;
  570. api->totem_ifaces_get (
  571. api->totem_nodeid_get(),
  572. interfaces,
  573. &status,
  574. &iface_count);
  575. res_lib_cfg_ringstatusget.interface_count = iface_count;
  576. for (i = 0; i < iface_count; i++) {
  577. totem_ip_string
  578. = (const char *)api->totem_ip_print (&interfaces[i]);
  579. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  580. status[i]);
  581. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  582. totem_ip_string);
  583. }
  584. api->ipc_response_send (
  585. conn,
  586. &res_lib_cfg_ringstatusget,
  587. sizeof (struct res_lib_cfg_ringstatusget));
  588. LEAVE();
  589. }
  590. static void message_handler_req_lib_cfg_ringreenable (
  591. void *conn,
  592. const void *msg)
  593. {
  594. struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
  595. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  596. struct iovec iovec;
  597. int result;
  598. ENTER();
  599. req_exec_cfg_ringreenable.header.size =
  600. sizeof (struct req_exec_cfg_ringreenable);
  601. req_exec_cfg_ringreenable.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  602. MESSAGE_REQ_EXEC_CFG_RINGREENABLE);
  603. api->ipc_source_set (&req_exec_cfg_ringreenable.source, conn);
  604. api->ipc_refcnt_inc(conn);
  605. iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
  606. iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
  607. result = api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  608. if (result == -1) {
  609. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  610. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  611. res_lib_cfg_ringreenable.header.error = CS_ERR_TRY_AGAIN;
  612. api->ipc_response_send (
  613. conn,
  614. &res_lib_cfg_ringreenable,
  615. sizeof (struct res_lib_cfg_ringreenable));
  616. api->ipc_refcnt_dec(conn);
  617. }
  618. LEAVE();
  619. }
  620. static void message_handler_req_lib_cfg_statetrack (
  621. void *conn,
  622. const void *msg)
  623. {
  624. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  625. struct res_lib_cfg_statetrack res_lib_cfg_statetrack;
  626. ENTER();
  627. /*
  628. * We only do shutdown tracking at the moment
  629. */
  630. if (list_empty(&ci->list)) {
  631. list_add(&ci->list, &trackers_list);
  632. ci->tracker_conn = conn;
  633. if (shutdown_con) {
  634. /*
  635. * Shutdown already in progress, ask the newcomer's opinion
  636. */
  637. ci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  638. shutdown_expected++;
  639. send_test_shutdown(conn, NULL, CS_OK);
  640. }
  641. }
  642. res_lib_cfg_statetrack.header.size = sizeof(struct res_lib_cfg_statetrack);
  643. res_lib_cfg_statetrack.header.id = MESSAGE_RES_CFG_STATETRACKSTART;
  644. res_lib_cfg_statetrack.header.error = CS_OK;
  645. api->ipc_response_send(conn, &res_lib_cfg_statetrack,
  646. sizeof(res_lib_cfg_statetrack));
  647. LEAVE();
  648. }
  649. static void message_handler_req_lib_cfg_statetrackstop (
  650. void *conn,
  651. const void *msg)
  652. {
  653. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  654. // struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
  655. ENTER();
  656. remove_ci_from_shutdown(ci);
  657. LEAVE();
  658. }
  659. static void message_handler_req_lib_cfg_administrativestateset (
  660. void *conn,
  661. const void *msg)
  662. {
  663. // struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
  664. ENTER();
  665. LEAVE();
  666. }
  667. static void message_handler_req_lib_cfg_administrativestateget (
  668. void *conn,
  669. const void *msg)
  670. {
  671. // struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;
  672. ENTER();
  673. LEAVE();
  674. }
  675. static void message_handler_req_lib_cfg_serviceload (
  676. void *conn,
  677. const void *msg)
  678. {
  679. const struct req_lib_cfg_serviceload *req_lib_cfg_serviceload = msg;
  680. struct res_lib_cfg_serviceload res_lib_cfg_serviceload;
  681. ENTER();
  682. api->service_link_and_init (
  683. api,
  684. (const char *)req_lib_cfg_serviceload->service_name,
  685. req_lib_cfg_serviceload->service_ver);
  686. res_lib_cfg_serviceload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  687. res_lib_cfg_serviceload.header.size = sizeof (struct res_lib_cfg_serviceload);
  688. res_lib_cfg_serviceload.header.error = CS_OK;
  689. api->ipc_response_send (
  690. conn,
  691. &res_lib_cfg_serviceload,
  692. sizeof (struct res_lib_cfg_serviceload));
  693. LEAVE();
  694. }
  695. static void message_handler_req_lib_cfg_serviceunload (
  696. void *conn,
  697. const void *msg)
  698. {
  699. const struct req_lib_cfg_serviceunload *req_lib_cfg_serviceunload = msg;
  700. struct res_lib_cfg_serviceunload res_lib_cfg_serviceunload;
  701. ENTER();
  702. api->service_unlink_and_exit (
  703. api,
  704. (const char *)req_lib_cfg_serviceunload->service_name,
  705. req_lib_cfg_serviceunload->service_ver);
  706. res_lib_cfg_serviceunload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  707. res_lib_cfg_serviceunload.header.size = sizeof (struct res_lib_cfg_serviceunload);
  708. res_lib_cfg_serviceunload.header.error = CS_OK;
  709. api->ipc_response_send (
  710. conn,
  711. &res_lib_cfg_serviceunload,
  712. sizeof (struct res_lib_cfg_serviceunload));
  713. LEAVE();
  714. }
  715. static void message_handler_req_lib_cfg_killnode (
  716. void *conn,
  717. const void *msg)
  718. {
  719. const struct req_lib_cfg_killnode *req_lib_cfg_killnode = msg;
  720. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  721. struct req_exec_cfg_killnode req_exec_cfg_killnode;
  722. struct iovec iovec;
  723. int result;
  724. cs_error_t error = CS_OK;
  725. ENTER();
  726. req_exec_cfg_killnode.header.size =
  727. sizeof (struct req_exec_cfg_killnode);
  728. req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  729. MESSAGE_REQ_EXEC_CFG_KILLNODE);
  730. req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
  731. marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
  732. iovec.iov_base = (char *)&req_exec_cfg_killnode;
  733. iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
  734. result = api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  735. if (result == -1) {
  736. error = CS_ERR_TRY_AGAIN;
  737. }
  738. res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
  739. res_lib_cfg_killnode.header.id = MESSAGE_RES_CFG_KILLNODE;
  740. res_lib_cfg_killnode.header.error = error;
  741. api->ipc_response_send(conn, &res_lib_cfg_killnode,
  742. sizeof(res_lib_cfg_killnode));
  743. LEAVE();
  744. }
  745. static void message_handler_req_lib_cfg_tryshutdown (
  746. void *conn,
  747. const void *msg)
  748. {
  749. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  750. const struct req_lib_cfg_tryshutdown *req_lib_cfg_tryshutdown = msg;
  751. struct list_head *iter;
  752. int result;
  753. cs_error_t error = CS_OK;
  754. ENTER();
  755. if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
  756. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  757. /*
  758. * Tell other nodes
  759. */
  760. result = send_shutdown();
  761. if (result == -1) {
  762. error = CS_ERR_TRY_AGAIN;
  763. }
  764. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  765. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  766. res_lib_cfg_tryshutdown.header.error = error;
  767. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  768. sizeof(res_lib_cfg_tryshutdown));
  769. LEAVE();
  770. return;
  771. }
  772. /*
  773. * Shutdown in progress, return an error
  774. */
  775. if (shutdown_con) {
  776. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  777. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  778. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  779. res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
  780. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  781. sizeof(res_lib_cfg_tryshutdown));
  782. LEAVE();
  783. return;
  784. }
  785. ci->conn = conn;
  786. shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
  787. shutdown_flags = req_lib_cfg_tryshutdown->flags;
  788. shutdown_yes = 0;
  789. shutdown_no = 0;
  790. /*
  791. * Count the number of listeners
  792. */
  793. shutdown_expected = 0;
  794. for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
  795. struct cfg_info *testci = list_entry(iter, struct cfg_info, list);
  796. /*
  797. * It is assumed that we will allow shutdown
  798. */
  799. if (testci != ci) {
  800. testci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  801. shutdown_expected++;
  802. }
  803. }
  804. /*
  805. * If no-one is listening for events then we can just go down now
  806. */
  807. if (shutdown_expected == 0) {
  808. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  809. result = send_shutdown();
  810. if (result == -1) {
  811. error = CS_ERR_TRY_AGAIN;
  812. shutdown_con = NULL;
  813. }
  814. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  815. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  816. res_lib_cfg_tryshutdown.header.error = error;
  817. /*
  818. * Tell originator that shutdown was confirmed
  819. */
  820. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  821. sizeof(res_lib_cfg_tryshutdown));
  822. LEAVE();
  823. return;
  824. }
  825. else {
  826. hdb_handle_t cfg_handle;
  827. hdb_handle_t find_handle;
  828. char *timeout_str;
  829. unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
  830. /*
  831. * Look for a shutdown timeout in objdb
  832. */
  833. api->object_find_create(OBJECT_PARENT_HANDLE, "cfg", strlen("cfg"), &find_handle);
  834. api->object_find_next(find_handle, &cfg_handle);
  835. api->object_find_destroy(find_handle);
  836. if (cfg_handle) {
  837. if ( !api->object_key_get(cfg_handle,
  838. "shutdown_timeout",
  839. strlen("shutdown_timeout"),
  840. (void *)&timeout_str,
  841. NULL)) {
  842. shutdown_timeout = atoi(timeout_str);
  843. }
  844. }
  845. /*
  846. * Start the timer. If we don't get a full set of replies before this goes
  847. * off we'll cancel the shutdown
  848. */
  849. api->timer_add_duration((unsigned long long)shutdown_timeout*1000000000, NULL,
  850. shutdown_timer_fn, &shutdown_timer);
  851. /*
  852. * Tell the users we would like to shut down
  853. */
  854. send_test_shutdown(NULL, conn, CS_OK);
  855. }
  856. /*
  857. * We don't sent a reply to the caller here.
  858. * We send it when we know if we can shut down or not
  859. */
  860. LEAVE();
  861. }
  862. static void message_handler_req_lib_cfg_replytoshutdown (
  863. void *conn,
  864. const void *msg)
  865. {
  866. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  867. const struct req_lib_cfg_replytoshutdown *req_lib_cfg_replytoshutdown = msg;
  868. struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
  869. int status = CS_OK;
  870. ENTER();
  871. if (!shutdown_con) {
  872. status = CS_ERR_ACCESS;
  873. goto exit_fn;
  874. }
  875. if (req_lib_cfg_replytoshutdown->response) {
  876. shutdown_yes++;
  877. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  878. }
  879. else {
  880. shutdown_no++;
  881. ci->shutdown_reply = SHUTDOWN_REPLY_NO;
  882. }
  883. check_shutdown_status();
  884. exit_fn:
  885. res_lib_cfg_replytoshutdown.header.error = status;
  886. res_lib_cfg_replytoshutdown.header.id = MESSAGE_RES_CFG_REPLYTOSHUTDOWN;
  887. res_lib_cfg_replytoshutdown.header.size = sizeof(res_lib_cfg_replytoshutdown);
  888. api->ipc_response_send(conn, &res_lib_cfg_replytoshutdown,
  889. sizeof(res_lib_cfg_replytoshutdown));
  890. LEAVE();
  891. }
  892. static void message_handler_req_lib_cfg_get_node_addrs (void *conn,
  893. const void *msg)
  894. {
  895. struct totem_ip_address node_ifs[INTERFACE_MAX];
  896. char buf[PIPE_BUF];
  897. char **status;
  898. unsigned int num_interfaces = 0;
  899. int ret = CS_OK;
  900. int i;
  901. const struct req_lib_cfg_get_node_addrs *req_lib_cfg_get_node_addrs = msg;
  902. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)buf;
  903. unsigned int nodeid = req_lib_cfg_get_node_addrs->nodeid;
  904. char *addr_buf;
  905. if (nodeid == 0)
  906. nodeid = api->totem_nodeid_get();
  907. api->totem_ifaces_get(nodeid, node_ifs, &status, &num_interfaces);
  908. res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
  909. res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
  910. res_lib_cfg_get_node_addrs->header.error = ret;
  911. res_lib_cfg_get_node_addrs->num_addrs = num_interfaces;
  912. if (num_interfaces) {
  913. res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
  914. for (i = 0, addr_buf = (char *)res_lib_cfg_get_node_addrs->addrs;
  915. i < num_interfaces; i++, addr_buf += TOTEMIP_ADDRLEN) {
  916. memcpy(addr_buf, node_ifs[i].addr, TOTEMIP_ADDRLEN);
  917. }
  918. }
  919. else {
  920. res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
  921. }
  922. api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
  923. }
  924. static void message_handler_req_lib_cfg_local_get (void *conn, const void *msg)
  925. {
  926. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  927. res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
  928. res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
  929. res_lib_cfg_local_get.header.error = CS_OK;
  930. res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
  931. api->ipc_response_send(conn, &res_lib_cfg_local_get,
  932. sizeof(res_lib_cfg_local_get));
  933. }
  934. static void message_handler_req_lib_cfg_crypto_set (
  935. void *conn,
  936. const void *msg)
  937. {
  938. const struct req_lib_cfg_crypto_set *req_lib_cfg_crypto_set = msg;
  939. struct res_lib_cfg_crypto_set res_lib_cfg_crypto_set;
  940. struct req_exec_cfg_crypto_set req_exec_cfg_crypto_set;
  941. struct iovec iovec;
  942. cs_error_t error = CS_ERR_INVALID_PARAM;
  943. int result;
  944. req_exec_cfg_crypto_set.header.size =
  945. sizeof (struct req_exec_cfg_crypto_set);
  946. req_exec_cfg_crypto_set.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  947. MESSAGE_REQ_EXEC_CFG_CRYPTO_SET);
  948. /*
  949. * Set it locally first so we can tell if it is allowed
  950. */
  951. if (api->totem_crypto_set(req_lib_cfg_crypto_set->type) == 0) {
  952. req_exec_cfg_crypto_set.type = req_lib_cfg_crypto_set->type;
  953. iovec.iov_base = (char *)&req_exec_cfg_crypto_set;
  954. iovec.iov_len = sizeof (struct req_exec_cfg_crypto_set);
  955. result = api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  956. if (result == -1) {
  957. error = CS_ERR_TRY_AGAIN;
  958. } else {
  959. error = CS_OK;
  960. }
  961. }
  962. res_lib_cfg_crypto_set.header.size = sizeof(res_lib_cfg_crypto_set);
  963. res_lib_cfg_crypto_set.header.id = MESSAGE_RES_CFG_CRYPTO_SET;
  964. res_lib_cfg_crypto_set.header.error = error;
  965. api->ipc_response_send(conn, &res_lib_cfg_crypto_set,
  966. sizeof(res_lib_cfg_crypto_set));
  967. }