cfg.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  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. cs_error_t res = CS_OK;
  458. ENTER();
  459. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  460. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  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. if (strlen(totem_ip_string) >= CFG_INTERFACE_NAME_MAX_LEN) {
  473. log_printf(LOGSYS_LEVEL_ERROR, "String representation of interface %u is too long", i);
  474. res = CS_ERR_NAME_TOO_LONG;
  475. goto send_response;
  476. }
  477. if (strlen(status[i]) >= CFG_INTERFACE_STATUS_MAX_LEN) {
  478. log_printf(LOGSYS_LEVEL_ERROR, "Status string for interface %u is too long", i);
  479. res = CS_ERR_NAME_TOO_LONG;
  480. goto send_response;
  481. }
  482. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  483. status[i]);
  484. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  485. totem_ip_string);
  486. }
  487. send_response:
  488. res_lib_cfg_ringstatusget.header.error = res;
  489. api->ipc_response_send (
  490. conn,
  491. &res_lib_cfg_ringstatusget,
  492. sizeof (struct res_lib_cfg_ringstatusget));
  493. LEAVE();
  494. }
  495. static void message_handler_req_lib_cfg_ringreenable (
  496. void *conn,
  497. const void *msg)
  498. {
  499. struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
  500. struct iovec iovec;
  501. ENTER();
  502. req_exec_cfg_ringreenable.header.size =
  503. sizeof (struct req_exec_cfg_ringreenable);
  504. req_exec_cfg_ringreenable.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  505. MESSAGE_REQ_EXEC_CFG_RINGREENABLE);
  506. api->ipc_source_set (&req_exec_cfg_ringreenable.source, conn);
  507. api->ipc_refcnt_inc(conn);
  508. iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
  509. iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
  510. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  511. LEAVE();
  512. }
  513. static void message_handler_req_lib_cfg_killnode (
  514. void *conn,
  515. const void *msg)
  516. {
  517. const struct req_lib_cfg_killnode *req_lib_cfg_killnode = msg;
  518. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  519. struct req_exec_cfg_killnode req_exec_cfg_killnode;
  520. struct iovec iovec;
  521. ENTER();
  522. req_exec_cfg_killnode.header.size =
  523. sizeof (struct req_exec_cfg_killnode);
  524. req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  525. MESSAGE_REQ_EXEC_CFG_KILLNODE);
  526. req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
  527. marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
  528. iovec.iov_base = (char *)&req_exec_cfg_killnode;
  529. iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
  530. (void)api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  531. res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
  532. res_lib_cfg_killnode.header.id = MESSAGE_RES_CFG_KILLNODE;
  533. res_lib_cfg_killnode.header.error = CS_OK;
  534. api->ipc_response_send(conn, &res_lib_cfg_killnode,
  535. sizeof(res_lib_cfg_killnode));
  536. LEAVE();
  537. }
  538. static void message_handler_req_lib_cfg_tryshutdown (
  539. void *conn,
  540. const void *msg)
  541. {
  542. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  543. const struct req_lib_cfg_tryshutdown *req_lib_cfg_tryshutdown = msg;
  544. struct list_head *iter;
  545. ENTER();
  546. if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
  547. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  548. /*
  549. * Tell other nodes
  550. */
  551. send_shutdown();
  552. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  553. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  554. res_lib_cfg_tryshutdown.header.error = CS_OK;
  555. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  556. sizeof(res_lib_cfg_tryshutdown));
  557. LEAVE();
  558. return;
  559. }
  560. /*
  561. * Shutdown in progress, return an error
  562. */
  563. if (shutdown_con) {
  564. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  565. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  566. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  567. res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
  568. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  569. sizeof(res_lib_cfg_tryshutdown));
  570. LEAVE();
  571. return;
  572. }
  573. ci->conn = conn;
  574. shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
  575. shutdown_flags = req_lib_cfg_tryshutdown->flags;
  576. shutdown_yes = 0;
  577. shutdown_no = 0;
  578. /*
  579. * Count the number of listeners
  580. */
  581. shutdown_expected = 0;
  582. for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
  583. struct cfg_info *testci = list_entry(iter, struct cfg_info, list);
  584. /*
  585. * It is assumed that we will allow shutdown
  586. */
  587. if (testci != ci) {
  588. testci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  589. shutdown_expected++;
  590. }
  591. }
  592. /*
  593. * If no-one is listening for events then we can just go down now
  594. */
  595. if (shutdown_expected == 0) {
  596. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  597. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  598. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  599. res_lib_cfg_tryshutdown.header.error = CS_OK;
  600. /*
  601. * Tell originator that shutdown was confirmed
  602. */
  603. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  604. sizeof(res_lib_cfg_tryshutdown));
  605. send_shutdown();
  606. LEAVE();
  607. return;
  608. }
  609. else {
  610. unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
  611. /*
  612. * Look for a shutdown timeout in configuration map
  613. */
  614. icmap_get_uint32("cfg.shutdown_timeout", &shutdown_timeout);
  615. /*
  616. * Start the timer. If we don't get a full set of replies before this goes
  617. * off we'll cancel the shutdown
  618. */
  619. api->timer_add_duration((unsigned long long)shutdown_timeout*1000000000, NULL,
  620. shutdown_timer_fn, &shutdown_timer);
  621. /*
  622. * Tell the users we would like to shut down
  623. */
  624. send_test_shutdown(NULL, conn, CS_OK);
  625. }
  626. /*
  627. * We don't sent a reply to the caller here.
  628. * We send it when we know if we can shut down or not
  629. */
  630. LEAVE();
  631. }
  632. static void message_handler_req_lib_cfg_replytoshutdown (
  633. void *conn,
  634. const void *msg)
  635. {
  636. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  637. const struct req_lib_cfg_replytoshutdown *req_lib_cfg_replytoshutdown = msg;
  638. struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
  639. int status = CS_OK;
  640. ENTER();
  641. if (!shutdown_con) {
  642. status = CS_ERR_ACCESS;
  643. goto exit_fn;
  644. }
  645. if (req_lib_cfg_replytoshutdown->response) {
  646. shutdown_yes++;
  647. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  648. }
  649. else {
  650. shutdown_no++;
  651. ci->shutdown_reply = SHUTDOWN_REPLY_NO;
  652. }
  653. check_shutdown_status();
  654. exit_fn:
  655. res_lib_cfg_replytoshutdown.header.error = status;
  656. res_lib_cfg_replytoshutdown.header.id = MESSAGE_RES_CFG_REPLYTOSHUTDOWN;
  657. res_lib_cfg_replytoshutdown.header.size = sizeof(res_lib_cfg_replytoshutdown);
  658. api->ipc_response_send(conn, &res_lib_cfg_replytoshutdown,
  659. sizeof(res_lib_cfg_replytoshutdown));
  660. LEAVE();
  661. }
  662. static void message_handler_req_lib_cfg_get_node_addrs (void *conn,
  663. const void *msg)
  664. {
  665. struct totem_ip_address node_ifs[INTERFACE_MAX];
  666. char buf[PIPE_BUF];
  667. char **status;
  668. unsigned int num_interfaces = 0;
  669. int ret = CS_OK;
  670. int i;
  671. const struct req_lib_cfg_get_node_addrs *req_lib_cfg_get_node_addrs = msg;
  672. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)buf;
  673. unsigned int nodeid = req_lib_cfg_get_node_addrs->nodeid;
  674. char *addr_buf;
  675. if (nodeid == 0)
  676. nodeid = api->totem_nodeid_get();
  677. api->totem_ifaces_get(nodeid, node_ifs, INTERFACE_MAX, &status, &num_interfaces);
  678. res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
  679. res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
  680. res_lib_cfg_get_node_addrs->header.error = ret;
  681. res_lib_cfg_get_node_addrs->num_addrs = num_interfaces;
  682. if (num_interfaces) {
  683. res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
  684. for (i = 0, addr_buf = (char *)res_lib_cfg_get_node_addrs->addrs;
  685. i < num_interfaces; i++, addr_buf += TOTEMIP_ADDRLEN) {
  686. memcpy(addr_buf, node_ifs[i].addr, TOTEMIP_ADDRLEN);
  687. }
  688. }
  689. else {
  690. res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
  691. }
  692. api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
  693. }
  694. static void message_handler_req_lib_cfg_local_get (void *conn, const void *msg)
  695. {
  696. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  697. res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
  698. res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
  699. res_lib_cfg_local_get.header.error = CS_OK;
  700. res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
  701. api->ipc_response_send(conn, &res_lib_cfg_local_get,
  702. sizeof(res_lib_cfg_local_get));
  703. }