cfg.c 29 KB

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