cfg.c 22 KB

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