cfg.c 25 KB

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