cfg.c 29 KB

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