cfg.c 32 KB

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