4
0

cfg.c 26 KB

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