cfg.c 30 KB

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