cfg.c 30 KB

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