cfg.c 30 KB

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