cfg.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  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 = 0,
  211. .response_id = 0,
  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 * 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 (conn) {
  346. TRACE1("sending testshutdown to %p", conn);
  347. api->ipc_response_send(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. TRACE1("sending testshutdown to %p", ci->tracker_conn);
  353. api->ipc_dispatch_send(ci->tracker_conn, &res_lib_cfg_testshutdown,
  354. sizeof(res_lib_cfg_testshutdown));
  355. }
  356. }
  357. LEAVE();
  358. }
  359. static void check_shutdown_status()
  360. {
  361. ENTER();
  362. /*
  363. * Shutdown client might have gone away
  364. */
  365. if (!shutdown_con) {
  366. LEAVE();
  367. return;
  368. }
  369. /*
  370. * All replies safely gathered in ?
  371. */
  372. if (shutdown_yes + shutdown_no >= shutdown_expected) {
  373. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  374. api->timer_delete(shutdown_timer);
  375. if (shutdown_yes >= shutdown_expected ||
  376. shutdown_flags == CFG_SHUTDOWN_FLAG_REGARDLESS) {
  377. TRACE1("shutdown confirmed");
  378. /*
  379. * Tell other nodes we are going down
  380. */
  381. send_shutdown();
  382. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  383. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  384. res_lib_cfg_tryshutdown.header.error = CS_OK;
  385. /*
  386. * Tell originator that shutdown was confirmed
  387. */
  388. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  389. sizeof(res_lib_cfg_tryshutdown));
  390. shutdown_con = NULL;
  391. }
  392. else {
  393. TRACE1("shutdown cancelled");
  394. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  395. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  396. res_lib_cfg_tryshutdown.header.error = CS_ERR_BUSY;
  397. /*
  398. * Tell originator that shutdown was cancelled
  399. */
  400. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  401. sizeof(res_lib_cfg_tryshutdown));
  402. shutdown_con = NULL;
  403. }
  404. log_printf(LOG_DEBUG, "shutdown decision is: (yes count: %d, no count: %d) flags=%x\n", shutdown_yes, shutdown_no, shutdown_flags);
  405. }
  406. LEAVE();
  407. }
  408. /*
  409. * Not all nodes responded to the shutdown (in time)
  410. */
  411. static void shutdown_timer_fn(void *arg)
  412. {
  413. ENTER();
  414. /*
  415. * Mark undecideds as "NO"
  416. */
  417. shutdown_no = shutdown_expected;
  418. check_shutdown_status();
  419. send_test_shutdown(NULL, CS_ERR_TIMEOUT);
  420. LEAVE();
  421. }
  422. static void remove_ci_from_shutdown(struct cfg_info *ci)
  423. {
  424. ENTER();
  425. /*
  426. * If the controlling shutdown process has quit, then cancel the
  427. * shutdown session
  428. */
  429. if (ci == shutdown_con) {
  430. shutdown_con = NULL;
  431. api->timer_delete(shutdown_timer);
  432. }
  433. if (!list_empty(&ci->list)) {
  434. list_del(&ci->list);
  435. list_init(&ci->list);
  436. /*
  437. * Remove our option
  438. */
  439. if (shutdown_con) {
  440. if (ci->shutdown_reply == SHUTDOWN_REPLY_YES)
  441. shutdown_yes--;
  442. if (ci->shutdown_reply == SHUTDOWN_REPLY_NO)
  443. shutdown_no--;
  444. }
  445. /*
  446. * If we are leaving, then that's an implicit YES to shutdown
  447. */
  448. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  449. shutdown_yes++;
  450. check_shutdown_status();
  451. }
  452. LEAVE();
  453. }
  454. int cfg_lib_exit_fn (void *conn)
  455. {
  456. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  457. ENTER();
  458. if (!list_empty(&ci->list)) {
  459. list_del(&ci->list);
  460. remove_ci_from_shutdown(ci);
  461. }
  462. LEAVE();
  463. return (0);
  464. }
  465. static int cfg_lib_init_fn (void *conn)
  466. {
  467. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  468. ENTER();
  469. list_init(&ci->list);
  470. LEAVE();
  471. return (0);
  472. }
  473. /*
  474. * Executive message handlers
  475. */
  476. static void message_handler_req_exec_cfg_ringreenable (
  477. void *message,
  478. unsigned int nodeid)
  479. {
  480. struct req_exec_cfg_ringreenable *req_exec_cfg_ringreenable =
  481. (struct req_exec_cfg_ringreenable *)message;
  482. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  483. ENTER();
  484. api->totem_ring_reenable ();
  485. if (api->ipc_source_is_local(&req_exec_cfg_ringreenable->source)) {
  486. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  487. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  488. res_lib_cfg_ringreenable.header.error = CS_OK;
  489. api->ipc_response_send (
  490. req_exec_cfg_ringreenable->source.conn,
  491. &res_lib_cfg_ringreenable,
  492. sizeof (struct res_lib_cfg_ringreenable));
  493. }
  494. LEAVE();
  495. }
  496. static void exec_cfg_killnode_endian_convert (void *msg)
  497. {
  498. struct req_exec_cfg_killnode *req_exec_cfg_killnode =
  499. (struct req_exec_cfg_killnode *)msg;
  500. ENTER();
  501. swab_mar_name_t(&req_exec_cfg_killnode->reason);
  502. LEAVE();
  503. }
  504. static void message_handler_req_exec_cfg_killnode (
  505. void *message,
  506. unsigned int nodeid)
  507. {
  508. struct req_exec_cfg_killnode *req_exec_cfg_killnode =
  509. (struct req_exec_cfg_killnode *)message;
  510. cs_name_t reason;
  511. ENTER();
  512. log_printf(LOG_DEBUG, "request to kill node %d(us=%d): %s\n", req_exec_cfg_killnode->nodeid, api->totem_nodeid_get(), reason.value);
  513. if (req_exec_cfg_killnode->nodeid == api->totem_nodeid_get()) {
  514. marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
  515. log_printf(LOG_NOTICE, "Killed by node %d: %s\n",
  516. nodeid, reason.value);
  517. corosync_fatal_error(COROSYNC_FATAL_ERROR_EXIT);
  518. }
  519. LEAVE();
  520. }
  521. /*
  522. * Self shutdown
  523. */
  524. static void message_handler_req_exec_cfg_shutdown (
  525. void *message,
  526. unsigned int nodeid)
  527. {
  528. ENTER();
  529. log_printf(LOG_NOTICE, "Node %d was shut down by sysadmin\n", nodeid);
  530. if (nodeid == api->totem_nodeid_get()) {
  531. corosync_fatal_error(COROSYNC_FATAL_ERROR_EXIT);
  532. }
  533. LEAVE();
  534. }
  535. /*
  536. * Library Interface Implementation
  537. */
  538. static void message_handler_req_lib_cfg_ringstatusget (
  539. void *conn,
  540. void *msg)
  541. {
  542. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  543. struct totem_ip_address interfaces[INTERFACE_MAX];
  544. unsigned int iface_count;
  545. char **status;
  546. char *totem_ip_string;
  547. unsigned int i;
  548. ENTER();
  549. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  550. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  551. res_lib_cfg_ringstatusget.header.error = CS_OK;
  552. api->totem_ifaces_get (
  553. api->totem_nodeid_get(),
  554. interfaces,
  555. &status,
  556. &iface_count);
  557. res_lib_cfg_ringstatusget.interface_count = iface_count;
  558. for (i = 0; i < iface_count; i++) {
  559. totem_ip_string = (char *)api->totem_ip_print (&interfaces[i]);
  560. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  561. status[i]);
  562. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  563. totem_ip_string);
  564. }
  565. api->ipc_response_send (
  566. conn,
  567. &res_lib_cfg_ringstatusget,
  568. sizeof (struct res_lib_cfg_ringstatusget));
  569. LEAVE();
  570. }
  571. static void message_handler_req_lib_cfg_ringreenable (
  572. void *conn,
  573. void *msg)
  574. {
  575. struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
  576. struct iovec iovec;
  577. ENTER();
  578. req_exec_cfg_ringreenable.header.size =
  579. sizeof (struct req_exec_cfg_ringreenable);
  580. req_exec_cfg_ringreenable.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  581. MESSAGE_REQ_EXEC_CFG_RINGREENABLE);
  582. api->ipc_source_set (&req_exec_cfg_ringreenable.source, conn);
  583. iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
  584. iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
  585. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  586. LEAVE();
  587. }
  588. static void message_handler_req_lib_cfg_statetrack (
  589. void *conn,
  590. void *msg)
  591. {
  592. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  593. // struct req_lib_cfg_statetrack *req_lib_cfg_statetrack = (struct req_lib_cfg_statetrack *)message;
  594. struct res_lib_cfg_statetrack res_lib_cfg_statetrack;
  595. ENTER();
  596. /*
  597. * We only do shutdown tracking at the moment
  598. */
  599. if (list_empty(&ci->list)) {
  600. list_add(&ci->list, &trackers_list);
  601. ci->tracker_conn = conn;
  602. if (shutdown_con) {
  603. /*
  604. * Shutdown already in progress, ask the newcomer's opinion
  605. */
  606. ci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  607. shutdown_expected++;
  608. send_test_shutdown(conn, CS_OK);
  609. }
  610. }
  611. res_lib_cfg_statetrack.header.size = sizeof(struct res_lib_cfg_statetrack);
  612. res_lib_cfg_statetrack.header.id = MESSAGE_RES_CFG_STATETRACKSTART;
  613. res_lib_cfg_statetrack.header.error = CS_OK;
  614. api->ipc_response_send(conn, &res_lib_cfg_statetrack,
  615. sizeof(res_lib_cfg_statetrack));
  616. LEAVE();
  617. }
  618. static void message_handler_req_lib_cfg_statetrackstop (
  619. void *conn,
  620. void *msg)
  621. {
  622. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  623. // struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
  624. ENTER();
  625. remove_ci_from_shutdown(ci);
  626. LEAVE();
  627. }
  628. static void message_handler_req_lib_cfg_administrativestateset (
  629. void *conn,
  630. void *msg)
  631. {
  632. // struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
  633. ENTER();
  634. LEAVE();
  635. }
  636. static void message_handler_req_lib_cfg_administrativestateget (
  637. void *conn,
  638. void *msg)
  639. {
  640. // struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;
  641. ENTER();
  642. LEAVE();
  643. }
  644. static void message_handler_req_lib_cfg_serviceload (
  645. void *conn,
  646. void *msg)
  647. {
  648. struct req_lib_cfg_serviceload *req_lib_cfg_serviceload =
  649. (struct req_lib_cfg_serviceload *)msg;
  650. struct res_lib_cfg_serviceload res_lib_cfg_serviceload;
  651. ENTER();
  652. api->service_link_and_init (
  653. api,
  654. (char *)req_lib_cfg_serviceload->service_name,
  655. req_lib_cfg_serviceload->service_ver);
  656. res_lib_cfg_serviceload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  657. res_lib_cfg_serviceload.header.size = sizeof (struct res_lib_cfg_serviceload);
  658. res_lib_cfg_serviceload.header.error = CS_OK;
  659. api->ipc_response_send (
  660. conn,
  661. &res_lib_cfg_serviceload,
  662. sizeof (struct res_lib_cfg_serviceload));
  663. LEAVE();
  664. }
  665. static void message_handler_req_lib_cfg_serviceunload (
  666. void *conn,
  667. void *msg)
  668. {
  669. struct req_lib_cfg_serviceunload *req_lib_cfg_serviceunload =
  670. (struct req_lib_cfg_serviceunload *)msg;
  671. struct res_lib_cfg_serviceunload res_lib_cfg_serviceunload;
  672. ENTER();
  673. api->service_unlink_and_exit (
  674. api,
  675. (char *)req_lib_cfg_serviceunload->service_name,
  676. req_lib_cfg_serviceunload->service_ver);
  677. res_lib_cfg_serviceunload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  678. res_lib_cfg_serviceunload.header.size = sizeof (struct res_lib_cfg_serviceunload);
  679. res_lib_cfg_serviceunload.header.error = CS_OK;
  680. api->ipc_response_send (
  681. conn,
  682. &res_lib_cfg_serviceunload,
  683. sizeof (struct res_lib_cfg_serviceunload));
  684. LEAVE();
  685. }
  686. static void message_handler_req_lib_cfg_killnode (
  687. void *conn,
  688. void *msg)
  689. {
  690. struct req_lib_cfg_killnode *req_lib_cfg_killnode = (struct req_lib_cfg_killnode *)msg;
  691. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  692. struct req_exec_cfg_killnode req_exec_cfg_killnode;
  693. struct iovec iovec;
  694. int res;
  695. ENTER();
  696. req_exec_cfg_killnode.header.size =
  697. sizeof (struct req_exec_cfg_killnode);
  698. req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  699. MESSAGE_REQ_EXEC_CFG_KILLNODE);
  700. req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
  701. marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
  702. iovec.iov_base = (char *)&req_exec_cfg_killnode;
  703. iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
  704. res = api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  705. res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
  706. res_lib_cfg_killnode.header.id = MESSAGE_RES_CFG_KILLNODE;
  707. res_lib_cfg_killnode.header.error = CS_OK;
  708. api->ipc_response_send(conn, &res_lib_cfg_killnode,
  709. sizeof(res_lib_cfg_killnode));
  710. LEAVE();
  711. }
  712. static void message_handler_req_lib_cfg_tryshutdown (
  713. void *conn,
  714. void *msg)
  715. {
  716. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  717. struct req_lib_cfg_tryshutdown *req_lib_cfg_tryshutdown = (struct req_lib_cfg_tryshutdown *)msg;
  718. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  719. struct list_head *iter;
  720. ENTER();
  721. if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
  722. /*
  723. * Tell other nodes
  724. */
  725. send_shutdown();
  726. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  727. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  728. res_lib_cfg_tryshutdown.header.error = CS_OK;
  729. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  730. sizeof(res_lib_cfg_tryshutdown));
  731. LEAVE();
  732. return;
  733. }
  734. /*
  735. * Shutdown in progress, return an error
  736. */
  737. if (shutdown_con) {
  738. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  739. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  740. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  741. res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
  742. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  743. sizeof(res_lib_cfg_tryshutdown));
  744. LEAVE();
  745. return;
  746. }
  747. ci->conn = conn;
  748. shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
  749. shutdown_flags = req_lib_cfg_tryshutdown->flags;
  750. shutdown_yes = 0;
  751. shutdown_no = 0;
  752. /*
  753. * Count the number of listeners
  754. */
  755. shutdown_expected = 0;
  756. for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
  757. struct cfg_info *ci = list_entry(iter, struct cfg_info, list);
  758. ci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  759. shutdown_expected++;
  760. }
  761. /*
  762. * If no-one is listening for events then we can just go down now
  763. */
  764. if (shutdown_expected == 0) {
  765. send_shutdown();
  766. LEAVE();
  767. return;
  768. }
  769. else {
  770. unsigned int cfg_handle;
  771. unsigned int find_handle;
  772. char *timeout_str;
  773. unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
  774. /*
  775. * Look for a shutdown timeout in objdb
  776. */
  777. api->object_find_create(OBJECT_PARENT_HANDLE, "cfg", strlen("cfg"), &find_handle);
  778. api->object_find_next(find_handle, &cfg_handle);
  779. api->object_find_destroy(find_handle);
  780. if (cfg_handle) {
  781. if ( !api->object_key_get(cfg_handle,
  782. "shutdown_timeout",
  783. strlen("shutdown_timeout"),
  784. (void *)&timeout_str,
  785. NULL)) {
  786. shutdown_timeout = atoi(timeout_str);
  787. }
  788. }
  789. /*
  790. * Start the timer. If we don't get a full set of replies before this goes
  791. * off we'll cancel the shutdown
  792. */
  793. api->timer_add_duration((unsigned long long)shutdown_timeout*1000000000, NULL,
  794. shutdown_timer_fn, &shutdown_timer);
  795. /*
  796. * Tell the users we would like to shut down
  797. */
  798. send_test_shutdown(NULL, CS_OK);
  799. }
  800. /*
  801. * We don't sent a reply to the caller here.
  802. * We send it when we know if we can shut down or not
  803. */
  804. LEAVE();
  805. }
  806. static void message_handler_req_lib_cfg_replytoshutdown (
  807. void *conn,
  808. void *msg)
  809. {
  810. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  811. struct req_lib_cfg_replytoshutdown *req_lib_cfg_replytoshutdown = (struct req_lib_cfg_replytoshutdown *)msg;
  812. ENTER();
  813. if (!shutdown_con) {
  814. LEAVE();
  815. return;
  816. }
  817. if (req_lib_cfg_replytoshutdown->response) {
  818. shutdown_yes++;
  819. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  820. }
  821. else {
  822. shutdown_no++;
  823. ci->shutdown_reply = SHUTDOWN_REPLY_NO;
  824. }
  825. check_shutdown_status();
  826. LEAVE();
  827. }
  828. static void message_handler_req_lib_cfg_get_node_addrs (void *conn, void *msg)
  829. {
  830. struct totem_ip_address node_ifs[INTERFACE_MAX];
  831. char buf[PIPE_BUF];
  832. char **status;
  833. unsigned int num_interfaces = 0;
  834. int ret = CS_OK;
  835. int i;
  836. struct req_lib_cfg_get_node_addrs *req_lib_cfg_get_node_addrs = (struct req_lib_cfg_get_node_addrs *)msg;
  837. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)buf;
  838. if (req_lib_cfg_get_node_addrs->nodeid == 0)
  839. req_lib_cfg_get_node_addrs->nodeid = api->totem_nodeid_get();
  840. api->totem_ifaces_get(req_lib_cfg_get_node_addrs->nodeid, node_ifs, &status, &num_interfaces);
  841. res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
  842. res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
  843. res_lib_cfg_get_node_addrs->header.error = ret;
  844. res_lib_cfg_get_node_addrs->num_addrs = num_interfaces;
  845. if (num_interfaces) {
  846. res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
  847. for (i = 0; i<num_interfaces; i++) {
  848. memcpy(&res_lib_cfg_get_node_addrs->addrs[i][0], node_ifs[i].addr, TOTEMIP_ADDRLEN);
  849. }
  850. }
  851. else {
  852. res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
  853. }
  854. api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
  855. }
  856. static void message_handler_req_lib_cfg_local_get (void *conn, void *message)
  857. {
  858. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  859. res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
  860. res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
  861. res_lib_cfg_local_get.header.error = CS_OK;
  862. res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
  863. api->ipc_response_send(conn, &res_lib_cfg_local_get,
  864. sizeof(res_lib_cfg_local_get));
  865. }