cfg.c 29 KB

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