cfg.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  1. /*
  2. * Copyright (c) 2005-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2012 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 char *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_killnode (
  118. void *conn,
  119. const void *msg);
  120. static void message_handler_req_lib_cfg_tryshutdown (
  121. void *conn,
  122. const void *msg);
  123. static void message_handler_req_lib_cfg_replytoshutdown (
  124. void *conn,
  125. const void *msg);
  126. static void message_handler_req_lib_cfg_get_node_addrs (
  127. void *conn,
  128. const void *msg);
  129. static void message_handler_req_lib_cfg_local_get (
  130. void *conn,
  131. const void *msg);
  132. static void message_handler_req_lib_cfg_crypto_set (
  133. void *conn,
  134. const void *msg);
  135. /*
  136. * Service Handler Definition
  137. */
  138. static struct corosync_lib_handler cfg_lib_engine[] =
  139. {
  140. { /* 0 */
  141. .lib_handler_fn = message_handler_req_lib_cfg_ringstatusget,
  142. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  143. },
  144. { /* 1 */
  145. .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
  146. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  147. },
  148. { /* 2 */
  149. .lib_handler_fn = message_handler_req_lib_cfg_killnode,
  150. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  151. },
  152. { /* 3 */
  153. .lib_handler_fn = message_handler_req_lib_cfg_tryshutdown,
  154. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  155. },
  156. { /* 4 */
  157. .lib_handler_fn = message_handler_req_lib_cfg_replytoshutdown,
  158. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  159. },
  160. { /* 5 */
  161. .lib_handler_fn = message_handler_req_lib_cfg_get_node_addrs,
  162. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  163. },
  164. { /* 6 */
  165. .lib_handler_fn = message_handler_req_lib_cfg_local_get,
  166. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  167. },
  168. { /* 7 */
  169. .lib_handler_fn = message_handler_req_lib_cfg_crypto_set,
  170. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  171. }
  172. };
  173. static struct corosync_exec_handler cfg_exec_engine[] =
  174. {
  175. { /* 0 */
  176. .exec_handler_fn = message_handler_req_exec_cfg_ringreenable,
  177. },
  178. { /* 1 */
  179. .exec_handler_fn = message_handler_req_exec_cfg_killnode,
  180. .exec_endian_convert_fn = exec_cfg_killnode_endian_convert
  181. },
  182. { /* 2 */
  183. .exec_handler_fn = message_handler_req_exec_cfg_shutdown,
  184. },
  185. { /* 3 */
  186. .exec_handler_fn = message_handler_req_exec_cfg_crypto_set,
  187. }
  188. };
  189. /*
  190. * Exports the interface for the service
  191. */
  192. struct corosync_service_engine cfg_service_engine = {
  193. .name = "corosync configuration service",
  194. .id = CFG_SERVICE,
  195. .priority = 1,
  196. .private_data_size = sizeof(struct cfg_info),
  197. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED,
  198. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  199. .lib_init_fn = cfg_lib_init_fn,
  200. .lib_exit_fn = cfg_lib_exit_fn,
  201. .lib_engine = cfg_lib_engine,
  202. .lib_engine_count = sizeof (cfg_lib_engine) / sizeof (struct corosync_lib_handler),
  203. .exec_init_fn = cfg_exec_init_fn,
  204. .exec_engine = cfg_exec_engine,
  205. .exec_engine_count = sizeof (cfg_exec_engine) / sizeof (struct corosync_exec_handler),
  206. .confchg_fn = cfg_confchg_fn
  207. };
  208. struct corosync_service_engine *cfg_get_service_engine_ver0 (void)
  209. {
  210. return (&cfg_service_engine);
  211. }
  212. struct req_exec_cfg_ringreenable {
  213. struct qb_ipc_request_header header __attribute__((aligned(8)));
  214. mar_message_source_t source __attribute__((aligned(8)));
  215. };
  216. struct req_exec_cfg_killnode {
  217. struct qb_ipc_request_header header __attribute__((aligned(8)));
  218. mar_uint32_t nodeid __attribute__((aligned(8)));
  219. mar_name_t reason __attribute__((aligned(8)));
  220. };
  221. struct req_exec_cfg_crypto_set {
  222. struct qb_ipc_request_header header __attribute__((aligned(8)));
  223. mar_uint32_t type __attribute__((aligned(8)));
  224. };
  225. struct req_exec_cfg_shutdown {
  226. struct qb_ipc_request_header header __attribute__((aligned(8)));
  227. };
  228. /* IMPL */
  229. static char *cfg_exec_init_fn (
  230. struct corosync_api_v1 *corosync_api_v1)
  231. {
  232. #ifdef COROSYNC_SOLARIS
  233. logsys_subsys_init();
  234. #endif
  235. api = corosync_api_v1;
  236. list_init(&trackers_list);
  237. return (NULL);
  238. }
  239. static void cfg_confchg_fn (
  240. enum totem_configuration_type configuration_type,
  241. const unsigned int *member_list, size_t member_list_entries,
  242. const unsigned int *left_list, size_t left_list_entries,
  243. const unsigned int *joined_list, size_t joined_list_entries,
  244. const struct memb_ring_id *ring_id)
  245. {
  246. }
  247. /*
  248. * Tell other nodes we are shutting down
  249. */
  250. static int send_shutdown(void)
  251. {
  252. struct req_exec_cfg_shutdown req_exec_cfg_shutdown;
  253. struct iovec iovec;
  254. ENTER();
  255. req_exec_cfg_shutdown.header.size =
  256. sizeof (struct req_exec_cfg_shutdown);
  257. req_exec_cfg_shutdown.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  258. MESSAGE_REQ_EXEC_CFG_SHUTDOWN);
  259. iovec.iov_base = (char *)&req_exec_cfg_shutdown;
  260. iovec.iov_len = sizeof (struct req_exec_cfg_shutdown);
  261. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  262. LEAVE();
  263. return 0;
  264. }
  265. static void send_test_shutdown(void *only_conn, void *exclude_conn, int status)
  266. {
  267. struct res_lib_cfg_testshutdown res_lib_cfg_testshutdown;
  268. struct list_head *iter;
  269. ENTER();
  270. res_lib_cfg_testshutdown.header.size = sizeof(struct res_lib_cfg_testshutdown);
  271. res_lib_cfg_testshutdown.header.id = MESSAGE_RES_CFG_TESTSHUTDOWN;
  272. res_lib_cfg_testshutdown.header.error = status;
  273. res_lib_cfg_testshutdown.flags = shutdown_flags;
  274. if (only_conn) {
  275. TRACE1("sending testshutdown to only %p", only_conn);
  276. api->ipc_dispatch_send(only_conn, &res_lib_cfg_testshutdown,
  277. sizeof(res_lib_cfg_testshutdown));
  278. } else {
  279. for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
  280. struct cfg_info *ci = list_entry(iter, struct cfg_info, list);
  281. if (ci->conn != exclude_conn) {
  282. TRACE1("sending testshutdown to %p", ci->tracker_conn);
  283. api->ipc_dispatch_send(ci->tracker_conn, &res_lib_cfg_testshutdown,
  284. sizeof(res_lib_cfg_testshutdown));
  285. }
  286. }
  287. }
  288. LEAVE();
  289. }
  290. static void check_shutdown_status(void)
  291. {
  292. ENTER();
  293. /*
  294. * Shutdown client might have gone away
  295. */
  296. if (!shutdown_con) {
  297. LEAVE();
  298. return;
  299. }
  300. /*
  301. * All replies safely gathered in ?
  302. */
  303. if (shutdown_yes + shutdown_no >= shutdown_expected) {
  304. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  305. api->timer_delete(shutdown_timer);
  306. if (shutdown_yes >= shutdown_expected ||
  307. shutdown_flags == CFG_SHUTDOWN_FLAG_REGARDLESS) {
  308. TRACE1("shutdown confirmed");
  309. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  310. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  311. res_lib_cfg_tryshutdown.header.error = CS_OK;
  312. /*
  313. * Tell originator that shutdown was confirmed
  314. */
  315. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  316. sizeof(res_lib_cfg_tryshutdown));
  317. shutdown_con = NULL;
  318. /*
  319. * Tell other nodes we are going down
  320. */
  321. send_shutdown();
  322. }
  323. else {
  324. TRACE1("shutdown cancelled");
  325. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  326. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  327. res_lib_cfg_tryshutdown.header.error = CS_ERR_BUSY;
  328. /*
  329. * Tell originator that shutdown was cancelled
  330. */
  331. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  332. sizeof(res_lib_cfg_tryshutdown));
  333. shutdown_con = NULL;
  334. }
  335. log_printf(LOGSYS_LEVEL_DEBUG, "shutdown decision is: (yes count: %d, no count: %d) flags=%x",
  336. shutdown_yes, shutdown_no, shutdown_flags);
  337. }
  338. LEAVE();
  339. }
  340. /*
  341. * Not all nodes responded to the shutdown (in time)
  342. */
  343. static void shutdown_timer_fn(void *arg)
  344. {
  345. ENTER();
  346. /*
  347. * Mark undecideds as "NO"
  348. */
  349. shutdown_no = shutdown_expected;
  350. check_shutdown_status();
  351. send_test_shutdown(NULL, NULL, CS_ERR_TIMEOUT);
  352. LEAVE();
  353. }
  354. static void remove_ci_from_shutdown(struct cfg_info *ci)
  355. {
  356. ENTER();
  357. /*
  358. * If the controlling shutdown process has quit, then cancel the
  359. * shutdown session
  360. */
  361. if (ci == shutdown_con) {
  362. shutdown_con = NULL;
  363. api->timer_delete(shutdown_timer);
  364. }
  365. if (!list_empty(&ci->list)) {
  366. list_del(&ci->list);
  367. list_init(&ci->list);
  368. /*
  369. * Remove our option
  370. */
  371. if (shutdown_con) {
  372. if (ci->shutdown_reply == SHUTDOWN_REPLY_YES)
  373. shutdown_yes--;
  374. if (ci->shutdown_reply == SHUTDOWN_REPLY_NO)
  375. shutdown_no--;
  376. }
  377. /*
  378. * If we are leaving, then that's an implicit YES to shutdown
  379. */
  380. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  381. shutdown_yes++;
  382. check_shutdown_status();
  383. }
  384. LEAVE();
  385. }
  386. int cfg_lib_exit_fn (void *conn)
  387. {
  388. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  389. ENTER();
  390. remove_ci_from_shutdown(ci);
  391. LEAVE();
  392. return (0);
  393. }
  394. static int cfg_lib_init_fn (void *conn)
  395. {
  396. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  397. ENTER();
  398. list_init(&ci->list);
  399. LEAVE();
  400. return (0);
  401. }
  402. /*
  403. * Executive message handlers
  404. */
  405. static void message_handler_req_exec_cfg_ringreenable (
  406. const void *message,
  407. unsigned int nodeid)
  408. {
  409. const struct req_exec_cfg_ringreenable *req_exec_cfg_ringreenable
  410. = message;
  411. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  412. ENTER();
  413. api->totem_ring_reenable ();
  414. if (api->ipc_source_is_local(&req_exec_cfg_ringreenable->source)) {
  415. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  416. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  417. res_lib_cfg_ringreenable.header.error = CS_OK;
  418. api->ipc_response_send (
  419. req_exec_cfg_ringreenable->source.conn,
  420. &res_lib_cfg_ringreenable,
  421. sizeof (struct res_lib_cfg_ringreenable));
  422. api->ipc_refcnt_dec(req_exec_cfg_ringreenable->source.conn);
  423. }
  424. LEAVE();
  425. }
  426. static void exec_cfg_killnode_endian_convert (void *msg)
  427. {
  428. struct req_exec_cfg_killnode *req_exec_cfg_killnode =
  429. (struct req_exec_cfg_killnode *)msg;
  430. ENTER();
  431. swab_mar_name_t(&req_exec_cfg_killnode->reason);
  432. LEAVE();
  433. }
  434. static void message_handler_req_exec_cfg_killnode (
  435. const void *message,
  436. unsigned int nodeid)
  437. {
  438. const struct req_exec_cfg_killnode *req_exec_cfg_killnode = message;
  439. cs_name_t reason;
  440. ENTER();
  441. log_printf(LOGSYS_LEVEL_DEBUG, "request to kill node %d(us=%d): %s",
  442. req_exec_cfg_killnode->nodeid, api->totem_nodeid_get(), reason.value);
  443. if (req_exec_cfg_killnode->nodeid == api->totem_nodeid_get()) {
  444. marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
  445. log_printf(LOGSYS_LEVEL_NOTICE, "Killed by node %d: %s",
  446. nodeid, reason.value);
  447. corosync_fatal_error(COROSYNC_FATAL_ERROR_EXIT);
  448. }
  449. LEAVE();
  450. }
  451. /*
  452. * Self shutdown
  453. */
  454. static void message_handler_req_exec_cfg_shutdown (
  455. const void *message,
  456. unsigned int nodeid)
  457. {
  458. ENTER();
  459. log_printf(LOGSYS_LEVEL_NOTICE, "Node %d was shut down by sysadmin", nodeid);
  460. if (nodeid == api->totem_nodeid_get()) {
  461. api->shutdown_request();
  462. }
  463. LEAVE();
  464. }
  465. static void message_handler_req_exec_cfg_crypto_set (
  466. const void *message,
  467. unsigned int nodeid)
  468. {
  469. const struct req_exec_cfg_crypto_set *req_exec_cfg_crypto_set = message;
  470. ENTER();
  471. log_printf(LOGSYS_LEVEL_NOTICE, "Node %d requested set crypto to %d",
  472. nodeid, req_exec_cfg_crypto_set->type);
  473. api->totem_crypto_set(req_exec_cfg_crypto_set->type);
  474. LEAVE();
  475. }
  476. /*
  477. * Library Interface Implementation
  478. */
  479. static void message_handler_req_lib_cfg_ringstatusget (
  480. void *conn,
  481. const void *msg)
  482. {
  483. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  484. struct totem_ip_address interfaces[INTERFACE_MAX];
  485. unsigned int iface_count;
  486. char **status;
  487. const char *totem_ip_string;
  488. unsigned int i;
  489. ENTER();
  490. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  491. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  492. res_lib_cfg_ringstatusget.header.error = CS_OK;
  493. api->totem_ifaces_get (
  494. api->totem_nodeid_get(),
  495. interfaces,
  496. &status,
  497. &iface_count);
  498. res_lib_cfg_ringstatusget.interface_count = iface_count;
  499. for (i = 0; i < iface_count; i++) {
  500. totem_ip_string
  501. = (const char *)api->totem_ip_print (&interfaces[i]);
  502. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  503. status[i]);
  504. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  505. totem_ip_string);
  506. }
  507. api->ipc_response_send (
  508. conn,
  509. &res_lib_cfg_ringstatusget,
  510. sizeof (struct res_lib_cfg_ringstatusget));
  511. LEAVE();
  512. }
  513. static void message_handler_req_lib_cfg_ringreenable (
  514. void *conn,
  515. const void *msg)
  516. {
  517. struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
  518. struct iovec iovec;
  519. ENTER();
  520. req_exec_cfg_ringreenable.header.size =
  521. sizeof (struct req_exec_cfg_ringreenable);
  522. req_exec_cfg_ringreenable.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  523. MESSAGE_REQ_EXEC_CFG_RINGREENABLE);
  524. api->ipc_source_set (&req_exec_cfg_ringreenable.source, conn);
  525. api->ipc_refcnt_inc(conn);
  526. iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
  527. iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
  528. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  529. LEAVE();
  530. }
  531. static void message_handler_req_lib_cfg_killnode (
  532. void *conn,
  533. const void *msg)
  534. {
  535. const struct req_lib_cfg_killnode *req_lib_cfg_killnode = msg;
  536. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  537. struct req_exec_cfg_killnode req_exec_cfg_killnode;
  538. struct iovec iovec;
  539. ENTER();
  540. req_exec_cfg_killnode.header.size =
  541. sizeof (struct req_exec_cfg_killnode);
  542. req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  543. MESSAGE_REQ_EXEC_CFG_KILLNODE);
  544. req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
  545. marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
  546. iovec.iov_base = (char *)&req_exec_cfg_killnode;
  547. iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
  548. (void)api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  549. res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
  550. res_lib_cfg_killnode.header.id = MESSAGE_RES_CFG_KILLNODE;
  551. res_lib_cfg_killnode.header.error = CS_OK;
  552. api->ipc_response_send(conn, &res_lib_cfg_killnode,
  553. sizeof(res_lib_cfg_killnode));
  554. LEAVE();
  555. }
  556. static void message_handler_req_lib_cfg_tryshutdown (
  557. void *conn,
  558. const void *msg)
  559. {
  560. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  561. const struct req_lib_cfg_tryshutdown *req_lib_cfg_tryshutdown = msg;
  562. struct list_head *iter;
  563. ENTER();
  564. if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
  565. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  566. /*
  567. * Tell other nodes
  568. */
  569. send_shutdown();
  570. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  571. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  572. res_lib_cfg_tryshutdown.header.error = CS_OK;
  573. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  574. sizeof(res_lib_cfg_tryshutdown));
  575. LEAVE();
  576. return;
  577. }
  578. /*
  579. * Shutdown in progress, return an error
  580. */
  581. if (shutdown_con) {
  582. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  583. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  584. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  585. res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
  586. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  587. sizeof(res_lib_cfg_tryshutdown));
  588. LEAVE();
  589. return;
  590. }
  591. ci->conn = conn;
  592. shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
  593. shutdown_flags = req_lib_cfg_tryshutdown->flags;
  594. shutdown_yes = 0;
  595. shutdown_no = 0;
  596. /*
  597. * Count the number of listeners
  598. */
  599. shutdown_expected = 0;
  600. for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
  601. struct cfg_info *testci = list_entry(iter, struct cfg_info, list);
  602. /*
  603. * It is assumed that we will allow shutdown
  604. */
  605. if (testci != ci) {
  606. testci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  607. shutdown_expected++;
  608. }
  609. }
  610. /*
  611. * If no-one is listening for events then we can just go down now
  612. */
  613. if (shutdown_expected == 0) {
  614. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  615. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  616. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  617. res_lib_cfg_tryshutdown.header.error = CS_OK;
  618. /*
  619. * Tell originator that shutdown was confirmed
  620. */
  621. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  622. sizeof(res_lib_cfg_tryshutdown));
  623. send_shutdown();
  624. LEAVE();
  625. return;
  626. }
  627. else {
  628. unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
  629. /*
  630. * Look for a shutdown timeout in configuration map
  631. */
  632. icmap_get_uint32("cfg.shutdown_timeout", &shutdown_timeout);
  633. /*
  634. * Start the timer. If we don't get a full set of replies before this goes
  635. * off we'll cancel the shutdown
  636. */
  637. api->timer_add_duration((unsigned long long)shutdown_timeout*1000000000, NULL,
  638. shutdown_timer_fn, &shutdown_timer);
  639. /*
  640. * Tell the users we would like to shut down
  641. */
  642. send_test_shutdown(NULL, conn, CS_OK);
  643. }
  644. /*
  645. * We don't sent a reply to the caller here.
  646. * We send it when we know if we can shut down or not
  647. */
  648. LEAVE();
  649. }
  650. static void message_handler_req_lib_cfg_replytoshutdown (
  651. void *conn,
  652. const void *msg)
  653. {
  654. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  655. const struct req_lib_cfg_replytoshutdown *req_lib_cfg_replytoshutdown = msg;
  656. struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
  657. int status = CS_OK;
  658. ENTER();
  659. if (!shutdown_con) {
  660. status = CS_ERR_ACCESS;
  661. goto exit_fn;
  662. }
  663. if (req_lib_cfg_replytoshutdown->response) {
  664. shutdown_yes++;
  665. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  666. }
  667. else {
  668. shutdown_no++;
  669. ci->shutdown_reply = SHUTDOWN_REPLY_NO;
  670. }
  671. check_shutdown_status();
  672. exit_fn:
  673. res_lib_cfg_replytoshutdown.header.error = status;
  674. res_lib_cfg_replytoshutdown.header.id = MESSAGE_RES_CFG_REPLYTOSHUTDOWN;
  675. res_lib_cfg_replytoshutdown.header.size = sizeof(res_lib_cfg_replytoshutdown);
  676. api->ipc_response_send(conn, &res_lib_cfg_replytoshutdown,
  677. sizeof(res_lib_cfg_replytoshutdown));
  678. LEAVE();
  679. }
  680. static void message_handler_req_lib_cfg_get_node_addrs (void *conn,
  681. const void *msg)
  682. {
  683. struct totem_ip_address node_ifs[INTERFACE_MAX];
  684. char buf[PIPE_BUF];
  685. char **status;
  686. unsigned int num_interfaces = 0;
  687. int ret = CS_OK;
  688. int i;
  689. const struct req_lib_cfg_get_node_addrs *req_lib_cfg_get_node_addrs = msg;
  690. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)buf;
  691. unsigned int nodeid = req_lib_cfg_get_node_addrs->nodeid;
  692. char *addr_buf;
  693. if (nodeid == 0)
  694. nodeid = api->totem_nodeid_get();
  695. api->totem_ifaces_get(nodeid, node_ifs, &status, &num_interfaces);
  696. res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
  697. res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
  698. res_lib_cfg_get_node_addrs->header.error = ret;
  699. res_lib_cfg_get_node_addrs->num_addrs = num_interfaces;
  700. if (num_interfaces) {
  701. res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
  702. for (i = 0, addr_buf = (char *)res_lib_cfg_get_node_addrs->addrs;
  703. i < num_interfaces; i++, addr_buf += TOTEMIP_ADDRLEN) {
  704. memcpy(addr_buf, node_ifs[i].addr, TOTEMIP_ADDRLEN);
  705. }
  706. }
  707. else {
  708. res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
  709. }
  710. api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
  711. }
  712. static void message_handler_req_lib_cfg_local_get (void *conn, const void *msg)
  713. {
  714. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  715. res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
  716. res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
  717. res_lib_cfg_local_get.header.error = CS_OK;
  718. res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
  719. api->ipc_response_send(conn, &res_lib_cfg_local_get,
  720. sizeof(res_lib_cfg_local_get));
  721. }
  722. static void message_handler_req_lib_cfg_crypto_set (
  723. void *conn,
  724. const void *msg)
  725. {
  726. const struct req_lib_cfg_crypto_set *req_lib_cfg_crypto_set = msg;
  727. struct res_lib_cfg_crypto_set res_lib_cfg_crypto_set;
  728. struct req_exec_cfg_crypto_set req_exec_cfg_crypto_set;
  729. struct iovec iovec;
  730. int ret = CS_ERR_INVALID_PARAM;
  731. req_exec_cfg_crypto_set.header.size =
  732. sizeof (struct req_exec_cfg_crypto_set);
  733. req_exec_cfg_crypto_set.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  734. MESSAGE_REQ_EXEC_CFG_CRYPTO_SET);
  735. /*
  736. * Set it locally first so we can tell if it is allowed
  737. */
  738. if (api->totem_crypto_set(req_lib_cfg_crypto_set->type) == 0) {
  739. req_exec_cfg_crypto_set.type = req_lib_cfg_crypto_set->type;
  740. iovec.iov_base = (char *)&req_exec_cfg_crypto_set;
  741. iovec.iov_len = sizeof (struct req_exec_cfg_crypto_set);
  742. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  743. ret = CS_OK;
  744. }
  745. res_lib_cfg_crypto_set.header.size = sizeof(res_lib_cfg_crypto_set);
  746. res_lib_cfg_crypto_set.header.id = MESSAGE_RES_CFG_CRYPTO_SET;
  747. res_lib_cfg_crypto_set.header.error = ret;
  748. api->ipc_response_send(conn, &res_lib_cfg_crypto_set,
  749. sizeof(res_lib_cfg_crypto_set));
  750. }