cfg.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  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/lcr/lcr_comp.h>
  59. #include <corosync/logsys.h>
  60. #include <corosync/coroapi.h>
  61. #include <corosync/icmap.h>
  62. #include <corosync/corodefs.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. /*
  252. * Dynamic Loader definition
  253. */
  254. static struct corosync_service_engine *cfg_get_service_engine_ver0 (void);
  255. static struct corosync_service_engine_iface_ver0 cfg_service_engine_iface = {
  256. .corosync_get_service_engine_ver0 = cfg_get_service_engine_ver0
  257. };
  258. static struct lcr_iface corosync_cfg_ver0[1] = {
  259. {
  260. .name = "corosync_cfg",
  261. .version = 0,
  262. .versions_replace = 0,
  263. .versions_replace_count = 0,
  264. .dependencies = 0,
  265. .dependency_count = 0,
  266. .constructor = NULL,
  267. .destructor = NULL,
  268. .interfaces = NULL
  269. }
  270. };
  271. static struct lcr_comp cfg_comp_ver0 = {
  272. .iface_count = 1,
  273. .ifaces = corosync_cfg_ver0
  274. };
  275. static struct corosync_service_engine *cfg_get_service_engine_ver0 (void)
  276. {
  277. return (&cfg_service_engine);
  278. }
  279. #ifdef COROSYNC_SOLARIS
  280. void corosync_lcr_component_register (void);
  281. void corosync_lcr_component_register (void) {
  282. #else
  283. __attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
  284. #endif
  285. lcr_interfaces_set (&corosync_cfg_ver0[0], &cfg_service_engine_iface);
  286. lcr_component_register (&cfg_comp_ver0);
  287. }
  288. struct req_exec_cfg_ringreenable {
  289. struct qb_ipc_request_header header __attribute__((aligned(8)));
  290. mar_message_source_t source __attribute__((aligned(8)));
  291. };
  292. struct req_exec_cfg_killnode {
  293. struct qb_ipc_request_header header __attribute__((aligned(8)));
  294. mar_uint32_t nodeid __attribute__((aligned(8)));
  295. mar_name_t reason __attribute__((aligned(8)));
  296. };
  297. struct req_exec_cfg_crypto_set {
  298. struct qb_ipc_request_header header __attribute__((aligned(8)));
  299. mar_uint32_t type __attribute__((aligned(8)));
  300. };
  301. struct req_exec_cfg_shutdown {
  302. struct qb_ipc_request_header header __attribute__((aligned(8)));
  303. };
  304. /* IMPL */
  305. static int cfg_exec_init_fn (
  306. struct corosync_api_v1 *corosync_api_v1)
  307. {
  308. #ifdef COROSYNC_SOLARIS
  309. logsys_subsys_init();
  310. #endif
  311. api = corosync_api_v1;
  312. list_init(&trackers_list);
  313. return (0);
  314. }
  315. static void cfg_confchg_fn (
  316. enum totem_configuration_type configuration_type,
  317. const unsigned int *member_list, size_t member_list_entries,
  318. const unsigned int *left_list, size_t left_list_entries,
  319. const unsigned int *joined_list, size_t joined_list_entries,
  320. const struct memb_ring_id *ring_id)
  321. {
  322. }
  323. /*
  324. * Tell other nodes we are shutting down
  325. */
  326. static int send_shutdown(void)
  327. {
  328. struct req_exec_cfg_shutdown req_exec_cfg_shutdown;
  329. struct iovec iovec;
  330. ENTER();
  331. req_exec_cfg_shutdown.header.size =
  332. sizeof (struct req_exec_cfg_shutdown);
  333. req_exec_cfg_shutdown.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  334. MESSAGE_REQ_EXEC_CFG_SHUTDOWN);
  335. iovec.iov_base = (char *)&req_exec_cfg_shutdown;
  336. iovec.iov_len = sizeof (struct req_exec_cfg_shutdown);
  337. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  338. LEAVE();
  339. return 0;
  340. }
  341. static void send_test_shutdown(void *only_conn, void *exclude_conn, int status)
  342. {
  343. struct res_lib_cfg_testshutdown res_lib_cfg_testshutdown;
  344. struct list_head *iter;
  345. ENTER();
  346. res_lib_cfg_testshutdown.header.size = sizeof(struct res_lib_cfg_testshutdown);
  347. res_lib_cfg_testshutdown.header.id = MESSAGE_RES_CFG_TESTSHUTDOWN;
  348. res_lib_cfg_testshutdown.header.error = status;
  349. res_lib_cfg_testshutdown.flags = shutdown_flags;
  350. if (only_conn) {
  351. TRACE1("sending testshutdown to only %p", only_conn);
  352. api->ipc_dispatch_send(only_conn, &res_lib_cfg_testshutdown,
  353. sizeof(res_lib_cfg_testshutdown));
  354. } else {
  355. for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
  356. struct cfg_info *ci = list_entry(iter, struct cfg_info, list);
  357. if (ci->conn != exclude_conn) {
  358. TRACE1("sending testshutdown to %p", ci->tracker_conn);
  359. api->ipc_dispatch_send(ci->tracker_conn, &res_lib_cfg_testshutdown,
  360. sizeof(res_lib_cfg_testshutdown));
  361. }
  362. }
  363. }
  364. LEAVE();
  365. }
  366. static void check_shutdown_status(void)
  367. {
  368. ENTER();
  369. /*
  370. * Shutdown client might have gone away
  371. */
  372. if (!shutdown_con) {
  373. LEAVE();
  374. return;
  375. }
  376. /*
  377. * All replies safely gathered in ?
  378. */
  379. if (shutdown_yes + shutdown_no >= shutdown_expected) {
  380. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  381. api->timer_delete(shutdown_timer);
  382. if (shutdown_yes >= shutdown_expected ||
  383. shutdown_flags == CFG_SHUTDOWN_FLAG_REGARDLESS) {
  384. TRACE1("shutdown confirmed");
  385. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  386. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  387. res_lib_cfg_tryshutdown.header.error = CS_OK;
  388. /*
  389. * Tell originator that shutdown was confirmed
  390. */
  391. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  392. sizeof(res_lib_cfg_tryshutdown));
  393. shutdown_con = NULL;
  394. /*
  395. * Tell other nodes we are going down
  396. */
  397. send_shutdown();
  398. }
  399. else {
  400. TRACE1("shutdown cancelled");
  401. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  402. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  403. res_lib_cfg_tryshutdown.header.error = CS_ERR_BUSY;
  404. /*
  405. * Tell originator that shutdown was cancelled
  406. */
  407. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  408. sizeof(res_lib_cfg_tryshutdown));
  409. shutdown_con = NULL;
  410. }
  411. log_printf(LOGSYS_LEVEL_DEBUG, "shutdown decision is: (yes count: %d, no count: %d) flags=%x\n", shutdown_yes, shutdown_no, shutdown_flags);
  412. }
  413. LEAVE();
  414. }
  415. /*
  416. * Not all nodes responded to the shutdown (in time)
  417. */
  418. static void shutdown_timer_fn(void *arg)
  419. {
  420. ENTER();
  421. /*
  422. * Mark undecideds as "NO"
  423. */
  424. shutdown_no = shutdown_expected;
  425. check_shutdown_status();
  426. send_test_shutdown(NULL, NULL, CS_ERR_TIMEOUT);
  427. LEAVE();
  428. }
  429. static void remove_ci_from_shutdown(struct cfg_info *ci)
  430. {
  431. ENTER();
  432. /*
  433. * If the controlling shutdown process has quit, then cancel the
  434. * shutdown session
  435. */
  436. if (ci == shutdown_con) {
  437. shutdown_con = NULL;
  438. api->timer_delete(shutdown_timer);
  439. }
  440. if (!list_empty(&ci->list)) {
  441. list_del(&ci->list);
  442. list_init(&ci->list);
  443. /*
  444. * Remove our option
  445. */
  446. if (shutdown_con) {
  447. if (ci->shutdown_reply == SHUTDOWN_REPLY_YES)
  448. shutdown_yes--;
  449. if (ci->shutdown_reply == SHUTDOWN_REPLY_NO)
  450. shutdown_no--;
  451. }
  452. /*
  453. * If we are leaving, then that's an implicit YES to shutdown
  454. */
  455. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  456. shutdown_yes++;
  457. check_shutdown_status();
  458. }
  459. LEAVE();
  460. }
  461. int cfg_lib_exit_fn (void *conn)
  462. {
  463. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  464. ENTER();
  465. remove_ci_from_shutdown(ci);
  466. LEAVE();
  467. return (0);
  468. }
  469. static int cfg_lib_init_fn (void *conn)
  470. {
  471. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  472. ENTER();
  473. list_init(&ci->list);
  474. LEAVE();
  475. return (0);
  476. }
  477. /*
  478. * Executive message handlers
  479. */
  480. static void message_handler_req_exec_cfg_ringreenable (
  481. const void *message,
  482. unsigned int nodeid)
  483. {
  484. const struct req_exec_cfg_ringreenable *req_exec_cfg_ringreenable
  485. = message;
  486. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  487. ENTER();
  488. api->totem_ring_reenable ();
  489. if (api->ipc_source_is_local(&req_exec_cfg_ringreenable->source)) {
  490. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  491. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  492. res_lib_cfg_ringreenable.header.error = CS_OK;
  493. api->ipc_response_send (
  494. req_exec_cfg_ringreenable->source.conn,
  495. &res_lib_cfg_ringreenable,
  496. sizeof (struct res_lib_cfg_ringreenable));
  497. api->ipc_refcnt_dec(req_exec_cfg_ringreenable->source.conn);
  498. }
  499. LEAVE();
  500. }
  501. static void exec_cfg_killnode_endian_convert (void *msg)
  502. {
  503. struct req_exec_cfg_killnode *req_exec_cfg_killnode =
  504. (struct req_exec_cfg_killnode *)msg;
  505. ENTER();
  506. swab_mar_name_t(&req_exec_cfg_killnode->reason);
  507. LEAVE();
  508. }
  509. static void message_handler_req_exec_cfg_killnode (
  510. const void *message,
  511. unsigned int nodeid)
  512. {
  513. const struct req_exec_cfg_killnode *req_exec_cfg_killnode = message;
  514. cs_name_t reason;
  515. ENTER();
  516. 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);
  517. if (req_exec_cfg_killnode->nodeid == api->totem_nodeid_get()) {
  518. marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
  519. log_printf(LOGSYS_LEVEL_NOTICE, "Killed by node %d: %s\n",
  520. nodeid, reason.value);
  521. corosync_fatal_error(COROSYNC_FATAL_ERROR_EXIT);
  522. }
  523. LEAVE();
  524. }
  525. /*
  526. * Self shutdown
  527. */
  528. static void message_handler_req_exec_cfg_shutdown (
  529. const void *message,
  530. unsigned int nodeid)
  531. {
  532. ENTER();
  533. log_printf(LOGSYS_LEVEL_NOTICE, "Node %d was shut down by sysadmin\n", nodeid);
  534. if (nodeid == api->totem_nodeid_get()) {
  535. api->shutdown_request();
  536. }
  537. LEAVE();
  538. }
  539. static void message_handler_req_exec_cfg_crypto_set (
  540. const void *message,
  541. unsigned int nodeid)
  542. {
  543. const struct req_exec_cfg_crypto_set *req_exec_cfg_crypto_set = message;
  544. ENTER();
  545. log_printf(LOGSYS_LEVEL_NOTICE, "Node %d requested set crypto to %d\n", nodeid, req_exec_cfg_crypto_set->type);
  546. api->totem_crypto_set(req_exec_cfg_crypto_set->type);
  547. LEAVE();
  548. }
  549. /*
  550. * Library Interface Implementation
  551. */
  552. static void message_handler_req_lib_cfg_ringstatusget (
  553. void *conn,
  554. const void *msg)
  555. {
  556. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  557. struct totem_ip_address interfaces[INTERFACE_MAX];
  558. unsigned int iface_count;
  559. char **status;
  560. const char *totem_ip_string;
  561. unsigned int i;
  562. ENTER();
  563. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  564. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  565. res_lib_cfg_ringstatusget.header.error = CS_OK;
  566. api->totem_ifaces_get (
  567. api->totem_nodeid_get(),
  568. interfaces,
  569. &status,
  570. &iface_count);
  571. res_lib_cfg_ringstatusget.interface_count = iface_count;
  572. for (i = 0; i < iface_count; i++) {
  573. totem_ip_string
  574. = (const char *)api->totem_ip_print (&interfaces[i]);
  575. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  576. status[i]);
  577. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  578. totem_ip_string);
  579. }
  580. api->ipc_response_send (
  581. conn,
  582. &res_lib_cfg_ringstatusget,
  583. sizeof (struct res_lib_cfg_ringstatusget));
  584. LEAVE();
  585. }
  586. static void message_handler_req_lib_cfg_ringreenable (
  587. void *conn,
  588. const void *msg)
  589. {
  590. struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
  591. struct iovec iovec;
  592. ENTER();
  593. req_exec_cfg_ringreenable.header.size =
  594. sizeof (struct req_exec_cfg_ringreenable);
  595. req_exec_cfg_ringreenable.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  596. MESSAGE_REQ_EXEC_CFG_RINGREENABLE);
  597. api->ipc_source_set (&req_exec_cfg_ringreenable.source, conn);
  598. api->ipc_refcnt_inc(conn);
  599. iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
  600. iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
  601. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  602. LEAVE();
  603. }
  604. static void message_handler_req_lib_cfg_statetrack (
  605. void *conn,
  606. const void *msg)
  607. {
  608. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  609. struct res_lib_cfg_statetrack res_lib_cfg_statetrack;
  610. ENTER();
  611. /*
  612. * We only do shutdown tracking at the moment
  613. */
  614. if (list_empty(&ci->list)) {
  615. list_add(&ci->list, &trackers_list);
  616. ci->tracker_conn = conn;
  617. if (shutdown_con) {
  618. /*
  619. * Shutdown already in progress, ask the newcomer's opinion
  620. */
  621. ci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  622. shutdown_expected++;
  623. send_test_shutdown(conn, NULL, CS_OK);
  624. }
  625. }
  626. res_lib_cfg_statetrack.header.size = sizeof(struct res_lib_cfg_statetrack);
  627. res_lib_cfg_statetrack.header.id = MESSAGE_RES_CFG_STATETRACKSTART;
  628. res_lib_cfg_statetrack.header.error = CS_OK;
  629. api->ipc_response_send(conn, &res_lib_cfg_statetrack,
  630. sizeof(res_lib_cfg_statetrack));
  631. LEAVE();
  632. }
  633. static void message_handler_req_lib_cfg_statetrackstop (
  634. void *conn,
  635. const void *msg)
  636. {
  637. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  638. // struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
  639. ENTER();
  640. remove_ci_from_shutdown(ci);
  641. LEAVE();
  642. }
  643. static void message_handler_req_lib_cfg_administrativestateset (
  644. void *conn,
  645. const void *msg)
  646. {
  647. // struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
  648. ENTER();
  649. LEAVE();
  650. }
  651. static void message_handler_req_lib_cfg_administrativestateget (
  652. void *conn,
  653. const void *msg)
  654. {
  655. // struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;
  656. ENTER();
  657. LEAVE();
  658. }
  659. static void message_handler_req_lib_cfg_serviceload (
  660. void *conn,
  661. const void *msg)
  662. {
  663. const struct req_lib_cfg_serviceload *req_lib_cfg_serviceload = msg;
  664. struct res_lib_cfg_serviceload res_lib_cfg_serviceload;
  665. ENTER();
  666. api->service_link_and_init (
  667. api,
  668. (const char *)req_lib_cfg_serviceload->service_name,
  669. req_lib_cfg_serviceload->service_ver);
  670. res_lib_cfg_serviceload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  671. res_lib_cfg_serviceload.header.size = sizeof (struct res_lib_cfg_serviceload);
  672. res_lib_cfg_serviceload.header.error = CS_OK;
  673. api->ipc_response_send (
  674. conn,
  675. &res_lib_cfg_serviceload,
  676. sizeof (struct res_lib_cfg_serviceload));
  677. LEAVE();
  678. }
  679. static void message_handler_req_lib_cfg_serviceunload (
  680. void *conn,
  681. const void *msg)
  682. {
  683. const struct req_lib_cfg_serviceunload *req_lib_cfg_serviceunload = msg;
  684. struct res_lib_cfg_serviceunload res_lib_cfg_serviceunload;
  685. ENTER();
  686. api->service_unlink_and_exit (
  687. api,
  688. (const char *)req_lib_cfg_serviceunload->service_name,
  689. req_lib_cfg_serviceunload->service_ver);
  690. res_lib_cfg_serviceunload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  691. res_lib_cfg_serviceunload.header.size = sizeof (struct res_lib_cfg_serviceunload);
  692. res_lib_cfg_serviceunload.header.error = CS_OK;
  693. api->ipc_response_send (
  694. conn,
  695. &res_lib_cfg_serviceunload,
  696. sizeof (struct res_lib_cfg_serviceunload));
  697. LEAVE();
  698. }
  699. static void message_handler_req_lib_cfg_killnode (
  700. void *conn,
  701. const void *msg)
  702. {
  703. const struct req_lib_cfg_killnode *req_lib_cfg_killnode = msg;
  704. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  705. struct req_exec_cfg_killnode req_exec_cfg_killnode;
  706. struct iovec iovec;
  707. ENTER();
  708. req_exec_cfg_killnode.header.size =
  709. sizeof (struct req_exec_cfg_killnode);
  710. req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  711. MESSAGE_REQ_EXEC_CFG_KILLNODE);
  712. req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
  713. marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
  714. iovec.iov_base = (char *)&req_exec_cfg_killnode;
  715. iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
  716. (void)api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  717. res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
  718. res_lib_cfg_killnode.header.id = MESSAGE_RES_CFG_KILLNODE;
  719. res_lib_cfg_killnode.header.error = CS_OK;
  720. api->ipc_response_send(conn, &res_lib_cfg_killnode,
  721. sizeof(res_lib_cfg_killnode));
  722. LEAVE();
  723. }
  724. static void message_handler_req_lib_cfg_tryshutdown (
  725. void *conn,
  726. const void *msg)
  727. {
  728. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  729. const struct req_lib_cfg_tryshutdown *req_lib_cfg_tryshutdown = msg;
  730. struct list_head *iter;
  731. ENTER();
  732. if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
  733. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  734. /*
  735. * Tell other nodes
  736. */
  737. send_shutdown();
  738. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  739. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  740. res_lib_cfg_tryshutdown.header.error = CS_OK;
  741. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  742. sizeof(res_lib_cfg_tryshutdown));
  743. LEAVE();
  744. return;
  745. }
  746. /*
  747. * Shutdown in progress, return an error
  748. */
  749. if (shutdown_con) {
  750. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  751. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  752. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  753. res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
  754. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  755. sizeof(res_lib_cfg_tryshutdown));
  756. LEAVE();
  757. return;
  758. }
  759. ci->conn = conn;
  760. shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
  761. shutdown_flags = req_lib_cfg_tryshutdown->flags;
  762. shutdown_yes = 0;
  763. shutdown_no = 0;
  764. /*
  765. * Count the number of listeners
  766. */
  767. shutdown_expected = 0;
  768. for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
  769. struct cfg_info *testci = list_entry(iter, struct cfg_info, list);
  770. /*
  771. * It is assumed that we will allow shutdown
  772. */
  773. if (testci != ci) {
  774. testci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  775. shutdown_expected++;
  776. }
  777. }
  778. /*
  779. * If no-one is listening for events then we can just go down now
  780. */
  781. if (shutdown_expected == 0) {
  782. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  783. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  784. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  785. res_lib_cfg_tryshutdown.header.error = CS_OK;
  786. /*
  787. * Tell originator that shutdown was confirmed
  788. */
  789. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  790. sizeof(res_lib_cfg_tryshutdown));
  791. send_shutdown();
  792. LEAVE();
  793. return;
  794. }
  795. else {
  796. unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
  797. /*
  798. * Look for a shutdown timeout in configuration map
  799. */
  800. icmap_get_uint32("cfg.shutdown_timeout", &shutdown_timeout);
  801. /*
  802. * Start the timer. If we don't get a full set of replies before this goes
  803. * off we'll cancel the shutdown
  804. */
  805. api->timer_add_duration((unsigned long long)shutdown_timeout*1000000000, NULL,
  806. shutdown_timer_fn, &shutdown_timer);
  807. /*
  808. * Tell the users we would like to shut down
  809. */
  810. send_test_shutdown(NULL, conn, CS_OK);
  811. }
  812. /*
  813. * We don't sent a reply to the caller here.
  814. * We send it when we know if we can shut down or not
  815. */
  816. LEAVE();
  817. }
  818. static void message_handler_req_lib_cfg_replytoshutdown (
  819. void *conn,
  820. const void *msg)
  821. {
  822. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  823. const struct req_lib_cfg_replytoshutdown *req_lib_cfg_replytoshutdown = msg;
  824. struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
  825. int status = CS_OK;
  826. ENTER();
  827. if (!shutdown_con) {
  828. status = CS_ERR_ACCESS;
  829. goto exit_fn;
  830. }
  831. if (req_lib_cfg_replytoshutdown->response) {
  832. shutdown_yes++;
  833. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  834. }
  835. else {
  836. shutdown_no++;
  837. ci->shutdown_reply = SHUTDOWN_REPLY_NO;
  838. }
  839. check_shutdown_status();
  840. exit_fn:
  841. res_lib_cfg_replytoshutdown.header.error = status;
  842. res_lib_cfg_replytoshutdown.header.id = MESSAGE_RES_CFG_REPLYTOSHUTDOWN;
  843. res_lib_cfg_replytoshutdown.header.size = sizeof(res_lib_cfg_replytoshutdown);
  844. api->ipc_response_send(conn, &res_lib_cfg_replytoshutdown,
  845. sizeof(res_lib_cfg_replytoshutdown));
  846. LEAVE();
  847. }
  848. static void message_handler_req_lib_cfg_get_node_addrs (void *conn,
  849. const void *msg)
  850. {
  851. struct totem_ip_address node_ifs[INTERFACE_MAX];
  852. char buf[PIPE_BUF];
  853. char **status;
  854. unsigned int num_interfaces = 0;
  855. int ret = CS_OK;
  856. int i;
  857. const struct req_lib_cfg_get_node_addrs *req_lib_cfg_get_node_addrs = msg;
  858. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)buf;
  859. unsigned int nodeid = req_lib_cfg_get_node_addrs->nodeid;
  860. char *addr_buf;
  861. if (nodeid == 0)
  862. nodeid = api->totem_nodeid_get();
  863. api->totem_ifaces_get(nodeid, node_ifs, &status, &num_interfaces);
  864. res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
  865. res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
  866. res_lib_cfg_get_node_addrs->header.error = ret;
  867. res_lib_cfg_get_node_addrs->num_addrs = num_interfaces;
  868. if (num_interfaces) {
  869. res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
  870. for (i = 0, addr_buf = (char *)res_lib_cfg_get_node_addrs->addrs;
  871. i < num_interfaces; i++, addr_buf += TOTEMIP_ADDRLEN) {
  872. memcpy(addr_buf, node_ifs[i].addr, TOTEMIP_ADDRLEN);
  873. }
  874. }
  875. else {
  876. res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
  877. }
  878. api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
  879. }
  880. static void message_handler_req_lib_cfg_local_get (void *conn, const void *msg)
  881. {
  882. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  883. res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
  884. res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
  885. res_lib_cfg_local_get.header.error = CS_OK;
  886. res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
  887. api->ipc_response_send(conn, &res_lib_cfg_local_get,
  888. sizeof(res_lib_cfg_local_get));
  889. }
  890. static void message_handler_req_lib_cfg_crypto_set (
  891. void *conn,
  892. const void *msg)
  893. {
  894. const struct req_lib_cfg_crypto_set *req_lib_cfg_crypto_set = msg;
  895. struct res_lib_cfg_crypto_set res_lib_cfg_crypto_set;
  896. struct req_exec_cfg_crypto_set req_exec_cfg_crypto_set;
  897. struct iovec iovec;
  898. int ret = CS_ERR_INVALID_PARAM;
  899. req_exec_cfg_crypto_set.header.size =
  900. sizeof (struct req_exec_cfg_crypto_set);
  901. req_exec_cfg_crypto_set.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  902. MESSAGE_REQ_EXEC_CFG_CRYPTO_SET);
  903. /*
  904. * Set it locally first so we can tell if it is allowed
  905. */
  906. if (api->totem_crypto_set(req_lib_cfg_crypto_set->type) == 0) {
  907. req_exec_cfg_crypto_set.type = req_lib_cfg_crypto_set->type;
  908. iovec.iov_base = (char *)&req_exec_cfg_crypto_set;
  909. iovec.iov_len = sizeof (struct req_exec_cfg_crypto_set);
  910. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  911. ret = CS_OK;
  912. }
  913. res_lib_cfg_crypto_set.header.size = sizeof(res_lib_cfg_crypto_set);
  914. res_lib_cfg_crypto_set.header.id = MESSAGE_RES_CFG_CRYPTO_SET;
  915. res_lib_cfg_crypto_set.header.error = ret;
  916. api->ipc_response_send(conn, &res_lib_cfg_crypto_set,
  917. sizeof(res_lib_cfg_crypto_set));
  918. }