cfg.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. /*
  2. * Copyright (c) 2005-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2009 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 <sys/types.h>
  36. #include <sys/uio.h>
  37. #include <sys/socket.h>
  38. #include <sys/un.h>
  39. #include <netinet/in.h>
  40. #include <arpa/inet.h>
  41. #include <unistd.h>
  42. #include <fcntl.h>
  43. #include <stdlib.h>
  44. #include <stdio.h>
  45. #include <limits.h>
  46. #include <errno.h>
  47. #include <signal.h>
  48. #include <string.h>
  49. #include <corosync/corotypes.h>
  50. #include <corosync/cfg.h>
  51. #include <corosync/list.h>
  52. #include <corosync/queue.h>
  53. #include <corosync/mar_gen.h>
  54. #include <corosync/ipc_gen.h>
  55. #include <corosync/totem/totemip.h>
  56. #include <corosync/ipc_cfg.h>
  57. #include <corosync/lcr/lcr_comp.h>
  58. #include <corosync/engine/logsys.h>
  59. #include <corosync/engine/coroapi.h>
  60. LOGSYS_DECLARE_SUBSYS ("CFG", LOG_INFO);
  61. enum cfg_message_req_types {
  62. MESSAGE_REQ_EXEC_CFG_RINGREENABLE = 0,
  63. MESSAGE_REQ_EXEC_CFG_KILLNODE = 1,
  64. MESSAGE_REQ_EXEC_CFG_SHUTDOWN = 2
  65. };
  66. #define DEFAULT_SHUTDOWN_TIMEOUT 5
  67. static struct list_head trackers_list;
  68. /*
  69. * Variables controlling a requested shutdown
  70. */
  71. static corosync_timer_handle_t shutdown_timer;
  72. static struct cfg_info *shutdown_con;
  73. static uint32_t shutdown_flags;
  74. static int shutdown_yes;
  75. static int shutdown_no;
  76. static int shutdown_expected;
  77. struct cfg_info
  78. {
  79. struct list_head list;
  80. void *conn;
  81. void *tracker_conn;
  82. enum {SHUTDOWN_REPLY_UNKNOWN, SHUTDOWN_REPLY_YES, SHUTDOWN_REPLY_NO} shutdown_reply;
  83. };
  84. static void cfg_confchg_fn (
  85. enum totem_configuration_type configuration_type,
  86. unsigned int *member_list, int member_list_entries,
  87. unsigned int *left_list, int left_list_entries,
  88. unsigned int *joined_list, int joined_list_entries,
  89. struct memb_ring_id *ring_id);
  90. static int cfg_exec_init_fn (struct corosync_api_v1 *corosync_api_v1);
  91. static struct corosync_api_v1 *api;
  92. static int cfg_lib_init_fn (void *conn);
  93. static int cfg_lib_exit_fn (void *conn);
  94. static void message_handler_req_exec_cfg_ringreenable (
  95. void *message,
  96. unsigned int nodeid);
  97. static void message_handler_req_exec_cfg_killnode (
  98. void *message,
  99. unsigned int nodeid);
  100. static void message_handler_req_exec_cfg_shutdown (
  101. void *message,
  102. unsigned int nodeid);
  103. static void exec_cfg_killnode_endian_convert (void *msg);
  104. static void message_handler_req_lib_cfg_ringstatusget (
  105. void *conn,
  106. void *msg);
  107. static void message_handler_req_lib_cfg_ringreenable (
  108. void *conn,
  109. void *msg);
  110. static void message_handler_req_lib_cfg_statetrack (
  111. void *conn,
  112. void *msg);
  113. static void message_handler_req_lib_cfg_statetrackstop (
  114. void *conn,
  115. void *msg);
  116. static void message_handler_req_lib_cfg_administrativestateset (
  117. void *conn,
  118. void *msg);
  119. static void message_handler_req_lib_cfg_administrativestateget (
  120. void *conn,
  121. void *msg);
  122. static void message_handler_req_lib_cfg_serviceload (
  123. void *conn,
  124. void *msg);
  125. static void message_handler_req_lib_cfg_serviceunload (
  126. void *conn,
  127. void *msg);
  128. static void message_handler_req_lib_cfg_killnode (
  129. void *conn,
  130. void *msg);
  131. static void message_handler_req_lib_cfg_tryshutdown (
  132. void *conn,
  133. void *msg);
  134. static void message_handler_req_lib_cfg_replytoshutdown (
  135. void *conn,
  136. void *msg);
  137. static void message_handler_req_lib_cfg_get_node_addrs (
  138. void *conn,
  139. void *msg);
  140. /*
  141. * Service Handler Definition
  142. */
  143. static struct corosync_lib_handler cfg_lib_engine[] =
  144. {
  145. { /* 0 */
  146. .lib_handler_fn = message_handler_req_lib_cfg_ringstatusget,
  147. .response_size = sizeof (struct res_lib_cfg_ringstatusget),
  148. .response_id = MESSAGE_RES_CFG_RINGSTATUSGET,
  149. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  150. },
  151. { /* 1 */
  152. .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
  153. .response_size = sizeof (struct res_lib_cfg_ringreenable),
  154. .response_id = MESSAGE_RES_CFG_RINGREENABLE,
  155. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  156. },
  157. { /* 2 */
  158. .lib_handler_fn = message_handler_req_lib_cfg_statetrack,
  159. .response_size = sizeof (struct res_lib_cfg_statetrack),
  160. .response_id = MESSAGE_RES_CFG_STATETRACKSTART,
  161. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  162. },
  163. { /* 3 */
  164. .lib_handler_fn = message_handler_req_lib_cfg_statetrackstop,
  165. .response_size = sizeof (struct res_lib_cfg_statetrackstop),
  166. .response_id = MESSAGE_RES_CFG_STATETRACKSTOP,
  167. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  168. },
  169. { /* 4 */
  170. .lib_handler_fn = message_handler_req_lib_cfg_administrativestateset,
  171. .response_size = sizeof (struct res_lib_cfg_administrativestateset),
  172. .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATESET,
  173. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  174. },
  175. { /* 5 */
  176. .lib_handler_fn = message_handler_req_lib_cfg_administrativestateget,
  177. .response_size = sizeof (struct res_lib_cfg_administrativestateget),
  178. .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATEGET,
  179. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  180. },
  181. { /* 6 */
  182. .lib_handler_fn = message_handler_req_lib_cfg_serviceload,
  183. .response_size = sizeof (struct res_lib_cfg_serviceload),
  184. .response_id = MESSAGE_RES_CFG_SERVICELOAD,
  185. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  186. },
  187. { /* 7 */
  188. .lib_handler_fn = message_handler_req_lib_cfg_serviceunload,
  189. .response_size = sizeof (struct res_lib_cfg_serviceunload),
  190. .response_id = MESSAGE_RES_CFG_SERVICEUNLOAD,
  191. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  192. },
  193. { /* 8 */
  194. .lib_handler_fn = message_handler_req_lib_cfg_killnode,
  195. .response_size = sizeof (struct res_lib_cfg_killnode),
  196. .response_id = MESSAGE_RES_CFG_KILLNODE,
  197. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  198. },
  199. { /* 9 */
  200. .lib_handler_fn = message_handler_req_lib_cfg_tryshutdown,
  201. .response_size = sizeof (struct res_lib_cfg_tryshutdown),
  202. .response_id = MESSAGE_RES_CFG_TRYSHUTDOWN,
  203. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  204. },
  205. { /* 10 */
  206. .lib_handler_fn = message_handler_req_lib_cfg_replytoshutdown,
  207. .response_size = 0,
  208. .response_id = 0,
  209. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  210. },
  211. { /* 11 */
  212. .lib_handler_fn = message_handler_req_lib_cfg_get_node_addrs,
  213. .response_size = sizeof (struct res_lib_cfg_get_node_addrs),
  214. .response_id = MESSAGE_RES_CFG_GET_NODE_ADDRS,
  215. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  216. }
  217. };
  218. static struct corosync_exec_handler cfg_exec_engine[] =
  219. {
  220. { /* 0 */
  221. .exec_handler_fn = message_handler_req_exec_cfg_ringreenable,
  222. },
  223. { /* 1 */
  224. .exec_handler_fn = message_handler_req_exec_cfg_killnode,
  225. .exec_endian_convert_fn = exec_cfg_killnode_endian_convert
  226. },
  227. { /* 2 */
  228. .exec_handler_fn = message_handler_req_exec_cfg_shutdown,
  229. }
  230. };
  231. /*
  232. * Exports the interface for the service
  233. */
  234. struct corosync_service_engine cfg_service_engine = {
  235. .name = "corosync configuration service",
  236. .id = CFG_SERVICE,
  237. .private_data_size = sizeof(struct cfg_info),
  238. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED,
  239. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  240. .lib_init_fn = cfg_lib_init_fn,
  241. .lib_exit_fn = cfg_lib_exit_fn,
  242. .lib_engine = cfg_lib_engine,
  243. .lib_engine_count = sizeof (cfg_lib_engine) / sizeof (struct corosync_lib_handler),
  244. .exec_init_fn = cfg_exec_init_fn,
  245. .exec_engine = cfg_exec_engine,
  246. .exec_engine_count = 0, /* sizeof (cfg_aisexec_handler_fns) / sizeof (coroync_exec_handler), */
  247. .confchg_fn = cfg_confchg_fn,
  248. };
  249. /*
  250. * Dynamic Loader definition
  251. */
  252. static struct corosync_service_engine *cfg_get_service_engine_ver0 (void);
  253. static struct corosync_service_engine_iface_ver0 cfg_service_engine_iface = {
  254. .corosync_get_service_engine_ver0 = cfg_get_service_engine_ver0
  255. };
  256. static struct lcr_iface corosync_cfg_ver0[1] = {
  257. {
  258. .name = "corosync_cfg",
  259. .version = 0,
  260. .versions_replace = 0,
  261. .versions_replace_count = 0,
  262. .dependencies = 0,
  263. .dependency_count = 0,
  264. .constructor = NULL,
  265. .destructor = NULL,
  266. .interfaces = NULL
  267. }
  268. };
  269. static struct lcr_comp cfg_comp_ver0 = {
  270. .iface_count = 1,
  271. .ifaces = corosync_cfg_ver0
  272. };
  273. static struct corosync_service_engine *cfg_get_service_engine_ver0 (void)
  274. {
  275. return (&cfg_service_engine);
  276. }
  277. __attribute__ ((constructor)) static void register_this_component (void) {
  278. lcr_interfaces_set (&corosync_cfg_ver0[0], &cfg_service_engine_iface);
  279. lcr_component_register (&cfg_comp_ver0);
  280. }
  281. struct req_exec_cfg_ringreenable {
  282. mar_req_header_t header __attribute__((aligned(8)));
  283. mar_message_source_t source __attribute__((aligned(8)));
  284. };
  285. struct req_exec_cfg_killnode {
  286. mar_req_header_t header __attribute__((aligned(8)));
  287. mar_uint32_t nodeid __attribute__((aligned(8)));
  288. mar_name_t reason __attribute__((aligned(8)));
  289. };
  290. struct req_exec_cfg_shutdown {
  291. mar_req_header_t header __attribute__((aligned(8)));
  292. };
  293. /* IMPL */
  294. static int cfg_exec_init_fn (
  295. struct corosync_api_v1 *corosync_api_v1)
  296. {
  297. api = corosync_api_v1;
  298. list_init(&trackers_list);
  299. return (0);
  300. }
  301. static void cfg_confchg_fn (
  302. enum totem_configuration_type configuration_type,
  303. unsigned int *member_list, int member_list_entries,
  304. unsigned int *left_list, int left_list_entries,
  305. unsigned int *joined_list, int joined_list_entries,
  306. struct memb_ring_id *ring_id)
  307. {
  308. }
  309. /*
  310. * Tell other nodes we are shutting down
  311. */
  312. static int send_shutdown()
  313. {
  314. struct req_exec_cfg_shutdown req_exec_cfg_shutdown;
  315. struct iovec iovec;
  316. ENTER();
  317. req_exec_cfg_shutdown.header.size =
  318. sizeof (struct req_exec_cfg_shutdown);
  319. req_exec_cfg_shutdown.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  320. MESSAGE_REQ_EXEC_CFG_SHUTDOWN);
  321. iovec.iov_base = (char *)&req_exec_cfg_shutdown;
  322. iovec.iov_len = sizeof (struct req_exec_cfg_shutdown);
  323. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  324. LEAVE();
  325. return 0;
  326. }
  327. static void send_test_shutdown(void * conn, int status)
  328. {
  329. struct res_lib_cfg_testshutdown res_lib_cfg_testshutdown;
  330. struct list_head *iter;
  331. ENTER();
  332. res_lib_cfg_testshutdown.header.size = sizeof(struct res_lib_cfg_testshutdown);
  333. res_lib_cfg_testshutdown.header.id = MESSAGE_RES_CFG_TESTSHUTDOWN;
  334. res_lib_cfg_testshutdown.header.error = status;
  335. res_lib_cfg_testshutdown.flags = shutdown_flags;
  336. if (conn) {
  337. TRACE1("sending testshutdown to %p", conn);
  338. api->ipc_conn_send_response(conn, &res_lib_cfg_testshutdown,
  339. sizeof(res_lib_cfg_testshutdown));
  340. } else {
  341. for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
  342. struct cfg_info *ci = list_entry(iter, struct cfg_info, list);
  343. TRACE1("sending testshutdown to %p", ci->tracker_conn);
  344. api->ipc_conn_send_response(ci->tracker_conn, &res_lib_cfg_testshutdown,
  345. sizeof(res_lib_cfg_testshutdown));
  346. }
  347. }
  348. LEAVE();
  349. }
  350. static void check_shutdown_status()
  351. {
  352. ENTER();
  353. /*
  354. * Shutdown client might have gone away
  355. */
  356. if (!shutdown_con) {
  357. LEAVE();
  358. return;
  359. }
  360. /*
  361. * All replies safely gathered in ?
  362. */
  363. if (shutdown_yes + shutdown_no >= shutdown_expected) {
  364. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  365. api->timer_delete(shutdown_timer);
  366. if (shutdown_yes >= shutdown_expected ||
  367. shutdown_flags == CFG_SHUTDOWN_FLAG_REGARDLESS) {
  368. TRACE1("shutdown confirmed");
  369. /*
  370. * Tell other nodes we are going down
  371. */
  372. send_shutdown();
  373. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  374. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  375. res_lib_cfg_tryshutdown.header.error = CS_OK;
  376. /*
  377. * Tell originator that shutdown was confirmed
  378. */
  379. api->ipc_conn_send_response(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  380. sizeof(res_lib_cfg_tryshutdown));
  381. shutdown_con = NULL;
  382. }
  383. else {
  384. TRACE1("shutdown cancelled");
  385. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  386. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  387. res_lib_cfg_tryshutdown.header.error = CS_ERR_BUSY;
  388. /*
  389. * Tell originator that shutdown was cancelled
  390. */
  391. api->ipc_conn_send_response(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  392. sizeof(res_lib_cfg_tryshutdown));
  393. shutdown_con = NULL;
  394. }
  395. log_printf(LOG_DEBUG, "shutdown decision is: (yes count: %d, no count: %d) flags=%x\n", shutdown_yes, shutdown_no, shutdown_flags);
  396. }
  397. LEAVE();
  398. }
  399. /*
  400. * Not all nodes responded to the shutdown (in time)
  401. */
  402. static void shutdown_timer_fn(void *arg)
  403. {
  404. ENTER();
  405. /*
  406. * Mark undecideds as "NO"
  407. */
  408. shutdown_no = shutdown_expected;
  409. check_shutdown_status();
  410. send_test_shutdown(NULL, CS_ERR_TIMEOUT);
  411. LEAVE();
  412. }
  413. static void remove_ci_from_shutdown(struct cfg_info *ci)
  414. {
  415. ENTER();
  416. /*
  417. * If the controlling shutdown process has quit, then cancel the
  418. * shutdown session
  419. */
  420. if (ci == shutdown_con) {
  421. shutdown_con = NULL;
  422. api->timer_delete(shutdown_timer);
  423. }
  424. if (!list_empty(&ci->list)) {
  425. list_del(&ci->list);
  426. list_init(&ci->list);
  427. /*
  428. * Remove our option
  429. */
  430. if (shutdown_con) {
  431. if (ci->shutdown_reply == SHUTDOWN_REPLY_YES)
  432. shutdown_yes--;
  433. if (ci->shutdown_reply == SHUTDOWN_REPLY_NO)
  434. shutdown_no--;
  435. }
  436. /*
  437. * If we are leaving, then that's an implicit YES to shutdown
  438. */
  439. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  440. shutdown_yes++;
  441. check_shutdown_status();
  442. }
  443. LEAVE();
  444. }
  445. int cfg_lib_exit_fn (void *conn)
  446. {
  447. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  448. ENTER();
  449. if (!list_empty(&ci->list)) {
  450. list_del(&ci->list);
  451. remove_ci_from_shutdown(ci);
  452. }
  453. LEAVE();
  454. return (0);
  455. }
  456. static int cfg_lib_init_fn (void *conn)
  457. {
  458. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  459. ENTER();
  460. list_init(&ci->list);
  461. LEAVE();
  462. return (0);
  463. }
  464. /*
  465. * Executive message handlers
  466. */
  467. static void message_handler_req_exec_cfg_ringreenable (
  468. void *message,
  469. unsigned int nodeid)
  470. {
  471. struct req_exec_cfg_ringreenable *req_exec_cfg_ringreenable =
  472. (struct req_exec_cfg_ringreenable *)message;
  473. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  474. ENTER();
  475. api->totem_ring_reenable ();
  476. if (api->ipc_source_is_local(&req_exec_cfg_ringreenable->source)) {
  477. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  478. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  479. res_lib_cfg_ringreenable.header.error = CS_OK;
  480. api->ipc_conn_send_response (
  481. req_exec_cfg_ringreenable->source.conn,
  482. &res_lib_cfg_ringreenable,
  483. sizeof (struct res_lib_cfg_ringreenable));
  484. }
  485. LEAVE();
  486. }
  487. static void exec_cfg_killnode_endian_convert (void *msg)
  488. {
  489. struct req_exec_cfg_killnode *req_exec_cfg_killnode =
  490. (struct req_exec_cfg_killnode *)msg;
  491. ENTER();
  492. swab_mar_name_t(&req_exec_cfg_killnode->reason);
  493. LEAVE();
  494. }
  495. static void message_handler_req_exec_cfg_killnode (
  496. void *message,
  497. unsigned int nodeid)
  498. {
  499. struct req_exec_cfg_killnode *req_exec_cfg_killnode =
  500. (struct req_exec_cfg_killnode *)message;
  501. cs_name_t reason;
  502. ENTER();
  503. log_printf(LOG_DEBUG, "request to kill node %d(us=%d): %s\n", req_exec_cfg_killnode->nodeid, api->totem_nodeid_get(), reason.value);
  504. if (req_exec_cfg_killnode->nodeid == api->totem_nodeid_get()) {
  505. marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
  506. log_printf(LOG_NOTICE, "Killed by node %d: %s\n",
  507. nodeid, reason.value);
  508. corosync_fatal_error(COROSYNC_FATAL_ERROR_EXIT);
  509. }
  510. LEAVE();
  511. }
  512. /*
  513. * Self shutdown
  514. */
  515. static void message_handler_req_exec_cfg_shutdown (
  516. void *message,
  517. unsigned int nodeid)
  518. {
  519. ENTER();
  520. log_printf(LOG_NOTICE, "Node %d was shut down by sysadmin\n", nodeid);
  521. if (nodeid == api->totem_nodeid_get()) {
  522. corosync_fatal_error(COROSYNC_FATAL_ERROR_EXIT);
  523. }
  524. LEAVE();
  525. }
  526. /*
  527. * Library Interface Implementation
  528. */
  529. static void message_handler_req_lib_cfg_ringstatusget (
  530. void *conn,
  531. void *msg)
  532. {
  533. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  534. struct totem_ip_address interfaces[INTERFACE_MAX];
  535. unsigned int iface_count;
  536. char **status;
  537. char *totem_ip_string;
  538. unsigned int i;
  539. ENTER();
  540. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  541. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  542. res_lib_cfg_ringstatusget.header.error = CS_OK;
  543. api->totem_ifaces_get (
  544. api->totem_nodeid_get(),
  545. interfaces,
  546. &status,
  547. &iface_count);
  548. res_lib_cfg_ringstatusget.interface_count = iface_count;
  549. for (i = 0; i < iface_count; i++) {
  550. totem_ip_string = (char *)api->totem_ip_print (&interfaces[i]);
  551. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  552. status[i]);
  553. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  554. totem_ip_string);
  555. }
  556. api->ipc_conn_send_response (
  557. conn,
  558. &res_lib_cfg_ringstatusget,
  559. sizeof (struct res_lib_cfg_ringstatusget));
  560. LEAVE();
  561. }
  562. static void message_handler_req_lib_cfg_ringreenable (
  563. void *conn,
  564. void *msg)
  565. {
  566. struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
  567. struct iovec iovec;
  568. ENTER();
  569. req_exec_cfg_ringreenable.header.size =
  570. sizeof (struct req_exec_cfg_ringreenable);
  571. req_exec_cfg_ringreenable.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  572. MESSAGE_REQ_EXEC_CFG_RINGREENABLE);
  573. api->ipc_source_set (&req_exec_cfg_ringreenable.source, conn);
  574. iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
  575. iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
  576. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  577. LEAVE();
  578. }
  579. static void message_handler_req_lib_cfg_statetrack (
  580. void *conn,
  581. void *msg)
  582. {
  583. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  584. // struct req_lib_cfg_statetrack *req_lib_cfg_statetrack = (struct req_lib_cfg_statetrack *)message;
  585. struct res_lib_cfg_statetrack res_lib_cfg_statetrack;
  586. ENTER();
  587. /*
  588. * We only do shutdown tracking at the moment
  589. */
  590. if (list_empty(&ci->list)) {
  591. list_add(&ci->list, &trackers_list);
  592. ci->tracker_conn = api->ipc_conn_partner_get (conn);
  593. if (shutdown_con) {
  594. /*
  595. * Shutdown already in progress, ask the newcomer's opinion
  596. */
  597. ci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  598. shutdown_expected++;
  599. send_test_shutdown(ci->tracker_conn, CS_OK);
  600. }
  601. }
  602. res_lib_cfg_statetrack.header.size = sizeof(struct res_lib_cfg_statetrack);
  603. res_lib_cfg_statetrack.header.id = MESSAGE_RES_CFG_STATETRACKSTART;
  604. res_lib_cfg_statetrack.header.error = CS_OK;
  605. api->ipc_conn_send_response(conn, &res_lib_cfg_statetrack,
  606. sizeof(res_lib_cfg_statetrack));
  607. LEAVE();
  608. }
  609. static void message_handler_req_lib_cfg_statetrackstop (
  610. void *conn,
  611. void *msg)
  612. {
  613. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  614. // struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
  615. ENTER();
  616. remove_ci_from_shutdown(ci);
  617. LEAVE();
  618. }
  619. static void message_handler_req_lib_cfg_administrativestateset (
  620. void *conn,
  621. void *msg)
  622. {
  623. // struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
  624. ENTER();
  625. LEAVE();
  626. }
  627. static void message_handler_req_lib_cfg_administrativestateget (
  628. void *conn,
  629. void *msg)
  630. {
  631. // struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;
  632. ENTER();
  633. LEAVE();
  634. }
  635. static void message_handler_req_lib_cfg_serviceload (
  636. void *conn,
  637. void *msg)
  638. {
  639. struct req_lib_cfg_serviceload *req_lib_cfg_serviceload =
  640. (struct req_lib_cfg_serviceload *)msg;
  641. struct res_lib_cfg_serviceload res_lib_cfg_serviceload;
  642. ENTER();
  643. api->service_link_and_init (
  644. api,
  645. (char *)req_lib_cfg_serviceload->service_name,
  646. req_lib_cfg_serviceload->service_ver);
  647. res_lib_cfg_serviceload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  648. res_lib_cfg_serviceload.header.size = sizeof (struct res_lib_cfg_serviceload);
  649. res_lib_cfg_serviceload.header.error = CS_OK;
  650. api->ipc_conn_send_response (
  651. conn,
  652. &res_lib_cfg_serviceload,
  653. sizeof (struct res_lib_cfg_serviceload));
  654. LEAVE();
  655. }
  656. static void message_handler_req_lib_cfg_serviceunload (
  657. void *conn,
  658. void *msg)
  659. {
  660. struct req_lib_cfg_serviceunload *req_lib_cfg_serviceunload =
  661. (struct req_lib_cfg_serviceunload *)msg;
  662. struct res_lib_cfg_serviceunload res_lib_cfg_serviceunload;
  663. ENTER();
  664. api->service_unlink_and_exit (
  665. api,
  666. (char *)req_lib_cfg_serviceunload->service_name,
  667. req_lib_cfg_serviceunload->service_ver);
  668. res_lib_cfg_serviceunload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  669. res_lib_cfg_serviceunload.header.size = sizeof (struct res_lib_cfg_serviceunload);
  670. res_lib_cfg_serviceunload.header.error = CS_OK;
  671. api->ipc_conn_send_response (
  672. conn,
  673. &res_lib_cfg_serviceunload,
  674. sizeof (struct res_lib_cfg_serviceunload));
  675. LEAVE();
  676. }
  677. static void message_handler_req_lib_cfg_killnode (
  678. void *conn,
  679. void *msg)
  680. {
  681. struct req_lib_cfg_killnode *req_lib_cfg_killnode = (struct req_lib_cfg_killnode *)msg;
  682. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  683. struct req_exec_cfg_killnode req_exec_cfg_killnode;
  684. struct iovec iovec;
  685. int res;
  686. ENTER();
  687. req_exec_cfg_killnode.header.size =
  688. sizeof (struct req_exec_cfg_killnode);
  689. req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  690. MESSAGE_REQ_EXEC_CFG_KILLNODE);
  691. req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
  692. marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
  693. iovec.iov_base = (char *)&req_exec_cfg_killnode;
  694. iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
  695. res = api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  696. res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
  697. res_lib_cfg_killnode.header.id = MESSAGE_RES_CFG_KILLNODE;
  698. res_lib_cfg_killnode.header.error = CS_OK;
  699. api->ipc_conn_send_response(conn, &res_lib_cfg_killnode,
  700. sizeof(res_lib_cfg_killnode));
  701. LEAVE();
  702. }
  703. static void message_handler_req_lib_cfg_tryshutdown (
  704. void *conn,
  705. void *msg)
  706. {
  707. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  708. struct req_lib_cfg_tryshutdown *req_lib_cfg_tryshutdown = (struct req_lib_cfg_tryshutdown *)msg;
  709. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  710. struct list_head *iter;
  711. ENTER();
  712. if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
  713. /*
  714. * Tell other nodes
  715. */
  716. send_shutdown();
  717. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  718. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  719. res_lib_cfg_tryshutdown.header.error = CS_OK;
  720. api->ipc_conn_send_response(conn, &res_lib_cfg_tryshutdown,
  721. sizeof(res_lib_cfg_tryshutdown));
  722. LEAVE();
  723. return;
  724. }
  725. /*
  726. * Shutdown in progress, return an error
  727. */
  728. if (shutdown_con) {
  729. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  730. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  731. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  732. res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
  733. api->ipc_conn_send_response(conn, &res_lib_cfg_tryshutdown,
  734. sizeof(res_lib_cfg_tryshutdown));
  735. LEAVE();
  736. return;
  737. }
  738. ci->conn = conn;
  739. shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
  740. shutdown_flags = req_lib_cfg_tryshutdown->flags;
  741. shutdown_yes = 0;
  742. shutdown_no = 0;
  743. /*
  744. * Count the number of listeners
  745. */
  746. shutdown_expected = 0;
  747. for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
  748. struct cfg_info *ci = list_entry(iter, struct cfg_info, list);
  749. ci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  750. shutdown_expected++;
  751. }
  752. /*
  753. * If no-one is listening for events then we can just go down now
  754. */
  755. if (shutdown_expected == 0) {
  756. send_shutdown();
  757. LEAVE();
  758. return;
  759. }
  760. else {
  761. unsigned int cfg_handle;
  762. unsigned int find_handle;
  763. char *timeout_str;
  764. unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
  765. /*
  766. * Look for a shutdown timeout in objdb
  767. */
  768. api->object_find_create(OBJECT_PARENT_HANDLE, "cfg", strlen("cfg"), &find_handle);
  769. api->object_find_next(find_handle, &cfg_handle);
  770. api->object_find_destroy(find_handle);
  771. if (cfg_handle) {
  772. if ( !api->object_key_get(cfg_handle,
  773. "shutdown_timeout",
  774. strlen("shutdown_timeout"),
  775. (void *)&timeout_str,
  776. NULL)) {
  777. shutdown_timeout = atoi(timeout_str);
  778. }
  779. }
  780. /*
  781. * Start the timer. If we don't get a full set of replies before this goes
  782. * off we'll cancel the shutdown
  783. */
  784. api->timer_add_duration((unsigned long long)shutdown_timeout*1000000000, NULL,
  785. shutdown_timer_fn, &shutdown_timer);
  786. /*
  787. * Tell the users we would like to shut down
  788. */
  789. send_test_shutdown(NULL, CS_OK);
  790. }
  791. /*
  792. * We don't sent a reply to the caller here.
  793. * We send it when we know if we can shut down or not
  794. */
  795. LEAVE();
  796. }
  797. static void message_handler_req_lib_cfg_replytoshutdown (
  798. void *conn,
  799. void *msg)
  800. {
  801. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  802. struct req_lib_cfg_replytoshutdown *req_lib_cfg_replytoshutdown = (struct req_lib_cfg_replytoshutdown *)msg;
  803. ENTER();
  804. if (!shutdown_con) {
  805. LEAVE();
  806. return;
  807. }
  808. if (req_lib_cfg_replytoshutdown->response) {
  809. shutdown_yes++;
  810. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  811. }
  812. else {
  813. shutdown_no++;
  814. ci->shutdown_reply = SHUTDOWN_REPLY_NO;
  815. }
  816. check_shutdown_status();
  817. LEAVE();
  818. }
  819. static void message_handler_req_lib_cfg_get_node_addrs (void *conn, void *msg)
  820. {
  821. struct totem_ip_address node_ifs[INTERFACE_MAX];
  822. char buf[PIPE_BUF];
  823. char **status;
  824. unsigned int num_interfaces = 0;
  825. int ret = 0;
  826. int i;
  827. struct req_lib_cfg_get_node_addrs *req_lib_cfg_get_node_addrs = (struct req_lib_cfg_get_node_addrs *)msg;
  828. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)buf;
  829. if (req_lib_cfg_get_node_addrs->nodeid == 0)
  830. req_lib_cfg_get_node_addrs->nodeid = api->totem_nodeid_get();
  831. api->totem_ifaces_get(req_lib_cfg_get_node_addrs->nodeid, node_ifs, &status, &num_interfaces);
  832. res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
  833. res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
  834. res_lib_cfg_get_node_addrs->header.error = ret;
  835. res_lib_cfg_get_node_addrs->num_addrs = num_interfaces;
  836. if (num_interfaces) {
  837. res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
  838. for (i = 0; i<num_interfaces; i++) {
  839. memcpy(&res_lib_cfg_get_node_addrs->addrs[i][0], node_ifs[i].addr, TOTEMIP_ADDRLEN);
  840. }
  841. }
  842. else {
  843. res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
  844. }
  845. api->ipc_conn_send_response(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
  846. }