4
0

cfg.c 22 KB

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