cfg.c 29 KB

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