cfg.c 29 KB

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