cfg.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115
  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 = 0, /* sizeof (cfg_aisexec_handler_fns) / sizeof (coroync_exec_handler), */
  246. .confchg_fn = cfg_confchg_fn,
  247. };
  248. /*
  249. * Dynamic Loader definition
  250. */
  251. static struct corosync_service_engine *cfg_get_service_engine_ver0 (void);
  252. static struct corosync_service_engine_iface_ver0 cfg_service_engine_iface = {
  253. .corosync_get_service_engine_ver0 = cfg_get_service_engine_ver0
  254. };
  255. static struct lcr_iface corosync_cfg_ver0[1] = {
  256. {
  257. .name = "corosync_cfg",
  258. .version = 0,
  259. .versions_replace = 0,
  260. .versions_replace_count = 0,
  261. .dependencies = 0,
  262. .dependency_count = 0,
  263. .constructor = NULL,
  264. .destructor = NULL,
  265. .interfaces = NULL
  266. }
  267. };
  268. static struct lcr_comp cfg_comp_ver0 = {
  269. .iface_count = 1,
  270. .ifaces = corosync_cfg_ver0
  271. };
  272. static struct corosync_service_engine *cfg_get_service_engine_ver0 (void)
  273. {
  274. return (&cfg_service_engine);
  275. }
  276. #ifdef COROSYNC_SOLARIS
  277. void corosync_lcr_component_register (void);
  278. void corosync_lcr_component_register (void) {
  279. #else
  280. __attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
  281. #endif
  282. lcr_interfaces_set (&corosync_cfg_ver0[0], &cfg_service_engine_iface);
  283. lcr_component_register (&cfg_comp_ver0);
  284. }
  285. struct req_exec_cfg_ringreenable {
  286. coroipc_request_header_t header __attribute__((aligned(8)));
  287. mar_message_source_t source __attribute__((aligned(8)));
  288. };
  289. struct req_exec_cfg_killnode {
  290. coroipc_request_header_t header __attribute__((aligned(8)));
  291. mar_uint32_t nodeid __attribute__((aligned(8)));
  292. mar_name_t reason __attribute__((aligned(8)));
  293. };
  294. struct req_exec_cfg_crypto_set {
  295. coroipc_request_header_t header __attribute__((aligned(8)));
  296. mar_uint32_t type __attribute__((aligned(8)));
  297. };
  298. struct req_exec_cfg_shutdown {
  299. coroipc_request_header_t header __attribute__((aligned(8)));
  300. };
  301. /* IMPL */
  302. static int cfg_exec_init_fn (
  303. struct corosync_api_v1 *corosync_api_v1)
  304. {
  305. #ifdef COROSYNC_SOLARIS
  306. logsys_subsys_init();
  307. #endif
  308. api = corosync_api_v1;
  309. list_init(&trackers_list);
  310. return (0);
  311. }
  312. static void cfg_confchg_fn (
  313. enum totem_configuration_type configuration_type,
  314. const unsigned int *member_list, size_t member_list_entries,
  315. const unsigned int *left_list, size_t left_list_entries,
  316. const unsigned int *joined_list, size_t joined_list_entries,
  317. const struct memb_ring_id *ring_id)
  318. {
  319. }
  320. /*
  321. * Tell other nodes we are shutting down
  322. */
  323. static int send_shutdown(void)
  324. {
  325. struct req_exec_cfg_shutdown req_exec_cfg_shutdown;
  326. struct iovec iovec;
  327. ENTER();
  328. req_exec_cfg_shutdown.header.size =
  329. sizeof (struct req_exec_cfg_shutdown);
  330. req_exec_cfg_shutdown.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  331. MESSAGE_REQ_EXEC_CFG_SHUTDOWN);
  332. iovec.iov_base = (char *)&req_exec_cfg_shutdown;
  333. iovec.iov_len = sizeof (struct req_exec_cfg_shutdown);
  334. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  335. LEAVE();
  336. return 0;
  337. }
  338. static void send_test_shutdown(void *only_conn, void *exclude_conn, int status)
  339. {
  340. struct res_lib_cfg_testshutdown res_lib_cfg_testshutdown;
  341. struct list_head *iter;
  342. ENTER();
  343. res_lib_cfg_testshutdown.header.size = sizeof(struct res_lib_cfg_testshutdown);
  344. res_lib_cfg_testshutdown.header.id = MESSAGE_RES_CFG_TESTSHUTDOWN;
  345. res_lib_cfg_testshutdown.header.error = status;
  346. res_lib_cfg_testshutdown.flags = shutdown_flags;
  347. if (only_conn) {
  348. TRACE1("sending testshutdown to only %p", only_conn);
  349. api->ipc_dispatch_send(only_conn, &res_lib_cfg_testshutdown,
  350. sizeof(res_lib_cfg_testshutdown));
  351. } else {
  352. for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
  353. struct cfg_info *ci = list_entry(iter, struct cfg_info, list);
  354. if (ci->conn != exclude_conn) {
  355. TRACE1("sending testshutdown to %p", ci->tracker_conn);
  356. api->ipc_dispatch_send(ci->tracker_conn, &res_lib_cfg_testshutdown,
  357. sizeof(res_lib_cfg_testshutdown));
  358. }
  359. }
  360. }
  361. LEAVE();
  362. }
  363. static void check_shutdown_status(void)
  364. {
  365. ENTER();
  366. /*
  367. * Shutdown client might have gone away
  368. */
  369. if (!shutdown_con) {
  370. LEAVE();
  371. return;
  372. }
  373. /*
  374. * All replies safely gathered in ?
  375. */
  376. if (shutdown_yes + shutdown_no >= shutdown_expected) {
  377. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  378. api->timer_delete(shutdown_timer);
  379. if (shutdown_yes >= shutdown_expected ||
  380. shutdown_flags == CFG_SHUTDOWN_FLAG_REGARDLESS) {
  381. TRACE1("shutdown confirmed");
  382. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  383. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  384. res_lib_cfg_tryshutdown.header.error = CS_OK;
  385. /*
  386. * Tell originator that shutdown was confirmed
  387. */
  388. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  389. sizeof(res_lib_cfg_tryshutdown));
  390. shutdown_con = NULL;
  391. /*
  392. * Tell other nodes we are going down
  393. */
  394. send_shutdown();
  395. }
  396. else {
  397. TRACE1("shutdown cancelled");
  398. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  399. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  400. res_lib_cfg_tryshutdown.header.error = CS_ERR_BUSY;
  401. /*
  402. * Tell originator that shutdown was cancelled
  403. */
  404. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  405. sizeof(res_lib_cfg_tryshutdown));
  406. shutdown_con = NULL;
  407. }
  408. log_printf(LOGSYS_LEVEL_DEBUG, "shutdown decision is: (yes count: %d, no count: %d) flags=%x\n", shutdown_yes, shutdown_no, shutdown_flags);
  409. }
  410. LEAVE();
  411. }
  412. /*
  413. * Not all nodes responded to the shutdown (in time)
  414. */
  415. static void shutdown_timer_fn(void *arg)
  416. {
  417. ENTER();
  418. /*
  419. * Mark undecideds as "NO"
  420. */
  421. shutdown_no = shutdown_expected;
  422. check_shutdown_status();
  423. send_test_shutdown(NULL, NULL, CS_ERR_TIMEOUT);
  424. LEAVE();
  425. }
  426. static void remove_ci_from_shutdown(struct cfg_info *ci)
  427. {
  428. ENTER();
  429. /*
  430. * If the controlling shutdown process has quit, then cancel the
  431. * shutdown session
  432. */
  433. if (ci == shutdown_con) {
  434. shutdown_con = NULL;
  435. api->timer_delete(shutdown_timer);
  436. }
  437. if (!list_empty(&ci->list)) {
  438. list_del(&ci->list);
  439. list_init(&ci->list);
  440. /*
  441. * Remove our option
  442. */
  443. if (shutdown_con) {
  444. if (ci->shutdown_reply == SHUTDOWN_REPLY_YES)
  445. shutdown_yes--;
  446. if (ci->shutdown_reply == SHUTDOWN_REPLY_NO)
  447. shutdown_no--;
  448. }
  449. /*
  450. * If we are leaving, then that's an implicit YES to shutdown
  451. */
  452. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  453. shutdown_yes++;
  454. check_shutdown_status();
  455. }
  456. LEAVE();
  457. }
  458. int cfg_lib_exit_fn (void *conn)
  459. {
  460. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  461. ENTER();
  462. if (!list_empty(&ci->list)) {
  463. list_del(&ci->list);
  464. remove_ci_from_shutdown(ci);
  465. }
  466. LEAVE();
  467. return (0);
  468. }
  469. static int cfg_lib_init_fn (void *conn)
  470. {
  471. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  472. ENTER();
  473. list_init(&ci->list);
  474. LEAVE();
  475. return (0);
  476. }
  477. /*
  478. * Executive message handlers
  479. */
  480. static void message_handler_req_exec_cfg_ringreenable (
  481. const void *message,
  482. unsigned int nodeid)
  483. {
  484. const struct req_exec_cfg_ringreenable *req_exec_cfg_ringreenable
  485. = message;
  486. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  487. ENTER();
  488. api->totem_ring_reenable ();
  489. if (api->ipc_source_is_local(&req_exec_cfg_ringreenable->source)) {
  490. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  491. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  492. res_lib_cfg_ringreenable.header.error = CS_OK;
  493. api->ipc_response_send (
  494. req_exec_cfg_ringreenable->source.conn,
  495. &res_lib_cfg_ringreenable,
  496. sizeof (struct res_lib_cfg_ringreenable));
  497. }
  498. LEAVE();
  499. }
  500. static void exec_cfg_killnode_endian_convert (void *msg)
  501. {
  502. struct req_exec_cfg_killnode *req_exec_cfg_killnode =
  503. (struct req_exec_cfg_killnode *)msg;
  504. ENTER();
  505. swab_mar_name_t(&req_exec_cfg_killnode->reason);
  506. LEAVE();
  507. }
  508. static void message_handler_req_exec_cfg_killnode (
  509. const void *message,
  510. unsigned int nodeid)
  511. {
  512. const struct req_exec_cfg_killnode *req_exec_cfg_killnode = message;
  513. cs_name_t reason;
  514. ENTER();
  515. 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);
  516. if (req_exec_cfg_killnode->nodeid == api->totem_nodeid_get()) {
  517. marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
  518. log_printf(LOGSYS_LEVEL_NOTICE, "Killed by node %d: %s\n",
  519. nodeid, reason.value);
  520. corosync_fatal_error(COROSYNC_FATAL_ERROR_EXIT);
  521. }
  522. LEAVE();
  523. }
  524. /*
  525. * Self shutdown
  526. */
  527. static void message_handler_req_exec_cfg_shutdown (
  528. const void *message,
  529. unsigned int nodeid)
  530. {
  531. ENTER();
  532. log_printf(LOGSYS_LEVEL_NOTICE, "Node %d was shut down by sysadmin\n", nodeid);
  533. if (nodeid == api->totem_nodeid_get()) {
  534. api->shutdown_request();
  535. }
  536. LEAVE();
  537. }
  538. static void message_handler_req_exec_cfg_crypto_set (
  539. const void *message,
  540. unsigned int nodeid)
  541. {
  542. const struct req_exec_cfg_crypto_set *req_exec_cfg_crypto_set = message;
  543. ENTER();
  544. log_printf(LOGSYS_LEVEL_NOTICE, "Node %d requested set crypto to %d\n", nodeid, req_exec_cfg_crypto_set->type);
  545. api->totem_crypto_set(req_exec_cfg_crypto_set->type);
  546. LEAVE();
  547. }
  548. /*
  549. * Library Interface Implementation
  550. */
  551. static void message_handler_req_lib_cfg_ringstatusget (
  552. void *conn,
  553. const void *msg)
  554. {
  555. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  556. struct totem_ip_address interfaces[INTERFACE_MAX];
  557. unsigned int iface_count;
  558. char **status;
  559. const char *totem_ip_string;
  560. unsigned int i;
  561. ENTER();
  562. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  563. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  564. res_lib_cfg_ringstatusget.header.error = CS_OK;
  565. api->totem_ifaces_get (
  566. api->totem_nodeid_get(),
  567. interfaces,
  568. &status,
  569. &iface_count);
  570. res_lib_cfg_ringstatusget.interface_count = iface_count;
  571. for (i = 0; i < iface_count; i++) {
  572. totem_ip_string
  573. = (const char *)api->totem_ip_print (&interfaces[i]);
  574. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  575. status[i]);
  576. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  577. totem_ip_string);
  578. }
  579. api->ipc_response_send (
  580. conn,
  581. &res_lib_cfg_ringstatusget,
  582. sizeof (struct res_lib_cfg_ringstatusget));
  583. LEAVE();
  584. }
  585. static void message_handler_req_lib_cfg_ringreenable (
  586. void *conn,
  587. const void *msg)
  588. {
  589. struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
  590. struct iovec iovec;
  591. ENTER();
  592. req_exec_cfg_ringreenable.header.size =
  593. sizeof (struct req_exec_cfg_ringreenable);
  594. req_exec_cfg_ringreenable.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  595. MESSAGE_REQ_EXEC_CFG_RINGREENABLE);
  596. api->ipc_source_set (&req_exec_cfg_ringreenable.source, conn);
  597. iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
  598. iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
  599. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  600. LEAVE();
  601. }
  602. static void message_handler_req_lib_cfg_statetrack (
  603. void *conn,
  604. const void *msg)
  605. {
  606. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  607. struct res_lib_cfg_statetrack res_lib_cfg_statetrack;
  608. ENTER();
  609. /*
  610. * We only do shutdown tracking at the moment
  611. */
  612. if (list_empty(&ci->list)) {
  613. list_add(&ci->list, &trackers_list);
  614. ci->tracker_conn = conn;
  615. if (shutdown_con) {
  616. /*
  617. * Shutdown already in progress, ask the newcomer's opinion
  618. */
  619. ci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  620. shutdown_expected++;
  621. send_test_shutdown(conn, NULL, CS_OK);
  622. }
  623. }
  624. res_lib_cfg_statetrack.header.size = sizeof(struct res_lib_cfg_statetrack);
  625. res_lib_cfg_statetrack.header.id = MESSAGE_RES_CFG_STATETRACKSTART;
  626. res_lib_cfg_statetrack.header.error = CS_OK;
  627. api->ipc_response_send(conn, &res_lib_cfg_statetrack,
  628. sizeof(res_lib_cfg_statetrack));
  629. LEAVE();
  630. }
  631. static void message_handler_req_lib_cfg_statetrackstop (
  632. void *conn,
  633. const void *msg)
  634. {
  635. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  636. // struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
  637. ENTER();
  638. remove_ci_from_shutdown(ci);
  639. LEAVE();
  640. }
  641. static void message_handler_req_lib_cfg_administrativestateset (
  642. void *conn,
  643. const void *msg)
  644. {
  645. // struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
  646. ENTER();
  647. LEAVE();
  648. }
  649. static void message_handler_req_lib_cfg_administrativestateget (
  650. void *conn,
  651. const void *msg)
  652. {
  653. // struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;
  654. ENTER();
  655. LEAVE();
  656. }
  657. static void message_handler_req_lib_cfg_serviceload (
  658. void *conn,
  659. const void *msg)
  660. {
  661. const struct req_lib_cfg_serviceload *req_lib_cfg_serviceload = msg;
  662. struct res_lib_cfg_serviceload res_lib_cfg_serviceload;
  663. ENTER();
  664. api->service_link_and_init (
  665. api,
  666. (const char *)req_lib_cfg_serviceload->service_name,
  667. req_lib_cfg_serviceload->service_ver);
  668. res_lib_cfg_serviceload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  669. res_lib_cfg_serviceload.header.size = sizeof (struct res_lib_cfg_serviceload);
  670. res_lib_cfg_serviceload.header.error = CS_OK;
  671. api->ipc_response_send (
  672. conn,
  673. &res_lib_cfg_serviceload,
  674. sizeof (struct res_lib_cfg_serviceload));
  675. LEAVE();
  676. }
  677. static void message_handler_req_lib_cfg_serviceunload (
  678. void *conn,
  679. const void *msg)
  680. {
  681. const struct req_lib_cfg_serviceunload *req_lib_cfg_serviceunload = msg;
  682. struct res_lib_cfg_serviceunload res_lib_cfg_serviceunload;
  683. ENTER();
  684. api->service_unlink_and_exit (
  685. api,
  686. (const char *)req_lib_cfg_serviceunload->service_name,
  687. req_lib_cfg_serviceunload->service_ver);
  688. res_lib_cfg_serviceunload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  689. res_lib_cfg_serviceunload.header.size = sizeof (struct res_lib_cfg_serviceunload);
  690. res_lib_cfg_serviceunload.header.error = CS_OK;
  691. api->ipc_response_send (
  692. conn,
  693. &res_lib_cfg_serviceunload,
  694. sizeof (struct res_lib_cfg_serviceunload));
  695. LEAVE();
  696. }
  697. static void message_handler_req_lib_cfg_killnode (
  698. void *conn,
  699. const void *msg)
  700. {
  701. const struct req_lib_cfg_killnode *req_lib_cfg_killnode = msg;
  702. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  703. struct req_exec_cfg_killnode req_exec_cfg_killnode;
  704. struct iovec iovec;
  705. int res;
  706. ENTER();
  707. req_exec_cfg_killnode.header.size =
  708. sizeof (struct req_exec_cfg_killnode);
  709. req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  710. MESSAGE_REQ_EXEC_CFG_KILLNODE);
  711. req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
  712. marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
  713. iovec.iov_base = (char *)&req_exec_cfg_killnode;
  714. iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
  715. res = api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  716. res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
  717. res_lib_cfg_killnode.header.id = MESSAGE_RES_CFG_KILLNODE;
  718. res_lib_cfg_killnode.header.error = CS_OK;
  719. api->ipc_response_send(conn, &res_lib_cfg_killnode,
  720. sizeof(res_lib_cfg_killnode));
  721. LEAVE();
  722. }
  723. static void message_handler_req_lib_cfg_tryshutdown (
  724. void *conn,
  725. const void *msg)
  726. {
  727. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  728. const struct req_lib_cfg_tryshutdown *req_lib_cfg_tryshutdown = msg;
  729. struct list_head *iter;
  730. ENTER();
  731. if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
  732. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  733. /*
  734. * Tell other nodes
  735. */
  736. send_shutdown();
  737. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  738. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  739. res_lib_cfg_tryshutdown.header.error = CS_OK;
  740. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  741. sizeof(res_lib_cfg_tryshutdown));
  742. LEAVE();
  743. return;
  744. }
  745. /*
  746. * Shutdown in progress, return an error
  747. */
  748. if (shutdown_con) {
  749. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  750. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  751. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  752. res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
  753. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  754. sizeof(res_lib_cfg_tryshutdown));
  755. LEAVE();
  756. return;
  757. }
  758. ci->conn = conn;
  759. shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
  760. shutdown_flags = req_lib_cfg_tryshutdown->flags;
  761. shutdown_yes = 0;
  762. shutdown_no = 0;
  763. /*
  764. * Count the number of listeners
  765. */
  766. shutdown_expected = 0;
  767. for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
  768. struct cfg_info *testci = list_entry(iter, struct cfg_info, list);
  769. /*
  770. * It is assumed that we will allow shutdown
  771. */
  772. if (testci != ci) {
  773. testci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  774. shutdown_expected++;
  775. }
  776. }
  777. /*
  778. * If no-one is listening for events then we can just go down now
  779. */
  780. if (shutdown_expected == 0) {
  781. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  782. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  783. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  784. res_lib_cfg_tryshutdown.header.error = CS_OK;
  785. /*
  786. * Tell originator that shutdown was confirmed
  787. */
  788. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  789. sizeof(res_lib_cfg_tryshutdown));
  790. send_shutdown();
  791. LEAVE();
  792. return;
  793. }
  794. else {
  795. hdb_handle_t cfg_handle;
  796. hdb_handle_t find_handle;
  797. char *timeout_str;
  798. unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
  799. /*
  800. * Look for a shutdown timeout in objdb
  801. */
  802. api->object_find_create(OBJECT_PARENT_HANDLE, "cfg", strlen("cfg"), &find_handle);
  803. api->object_find_next(find_handle, &cfg_handle);
  804. api->object_find_destroy(find_handle);
  805. if (cfg_handle) {
  806. if ( !api->object_key_get(cfg_handle,
  807. "shutdown_timeout",
  808. strlen("shutdown_timeout"),
  809. (void *)&timeout_str,
  810. NULL)) {
  811. shutdown_timeout = atoi(timeout_str);
  812. }
  813. }
  814. /*
  815. * Start the timer. If we don't get a full set of replies before this goes
  816. * off we'll cancel the shutdown
  817. */
  818. api->timer_add_duration((unsigned long long)shutdown_timeout*1000000000, NULL,
  819. shutdown_timer_fn, &shutdown_timer);
  820. /*
  821. * Tell the users we would like to shut down
  822. */
  823. send_test_shutdown(NULL, conn, CS_OK);
  824. }
  825. /*
  826. * We don't sent a reply to the caller here.
  827. * We send it when we know if we can shut down or not
  828. */
  829. LEAVE();
  830. }
  831. static void message_handler_req_lib_cfg_replytoshutdown (
  832. void *conn,
  833. const void *msg)
  834. {
  835. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  836. const struct req_lib_cfg_replytoshutdown *req_lib_cfg_replytoshutdown = msg;
  837. struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
  838. int status = CS_OK;
  839. ENTER();
  840. if (!shutdown_con) {
  841. status = CS_ERR_ACCESS;
  842. goto exit_fn;
  843. }
  844. if (req_lib_cfg_replytoshutdown->response) {
  845. shutdown_yes++;
  846. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  847. }
  848. else {
  849. shutdown_no++;
  850. ci->shutdown_reply = SHUTDOWN_REPLY_NO;
  851. }
  852. check_shutdown_status();
  853. exit_fn:
  854. res_lib_cfg_replytoshutdown.header.error = status;
  855. res_lib_cfg_replytoshutdown.header.id = MESSAGE_RES_CFG_REPLYTOSHUTDOWN;
  856. res_lib_cfg_replytoshutdown.header.size = sizeof(res_lib_cfg_replytoshutdown);
  857. api->ipc_response_send(conn, &res_lib_cfg_replytoshutdown,
  858. sizeof(res_lib_cfg_replytoshutdown));
  859. LEAVE();
  860. }
  861. static void message_handler_req_lib_cfg_get_node_addrs (void *conn,
  862. const void *msg)
  863. {
  864. struct totem_ip_address node_ifs[INTERFACE_MAX];
  865. char buf[PIPE_BUF];
  866. char **status;
  867. unsigned int num_interfaces = 0;
  868. int ret = CS_OK;
  869. int i;
  870. const struct req_lib_cfg_get_node_addrs *req_lib_cfg_get_node_addrs = msg;
  871. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)buf;
  872. unsigned int nodeid = req_lib_cfg_get_node_addrs->nodeid;
  873. if (nodeid == 0)
  874. nodeid = api->totem_nodeid_get();
  875. api->totem_ifaces_get(nodeid, node_ifs, &status, &num_interfaces);
  876. res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
  877. res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
  878. res_lib_cfg_get_node_addrs->header.error = ret;
  879. res_lib_cfg_get_node_addrs->num_addrs = num_interfaces;
  880. if (num_interfaces) {
  881. res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
  882. for (i = 0; i<num_interfaces; i++) {
  883. memcpy(&res_lib_cfg_get_node_addrs->addrs[i][0], node_ifs[i].addr, TOTEMIP_ADDRLEN);
  884. }
  885. }
  886. else {
  887. res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
  888. }
  889. api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
  890. }
  891. static void message_handler_req_lib_cfg_local_get (void *conn, const void *msg)
  892. {
  893. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  894. res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
  895. res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
  896. res_lib_cfg_local_get.header.error = CS_OK;
  897. res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
  898. api->ipc_response_send(conn, &res_lib_cfg_local_get,
  899. sizeof(res_lib_cfg_local_get));
  900. }
  901. static void message_handler_req_lib_cfg_crypto_set (
  902. void *conn,
  903. const void *msg)
  904. {
  905. const struct req_lib_cfg_crypto_set *req_lib_cfg_crypto_set = msg;
  906. struct res_lib_cfg_crypto_set res_lib_cfg_crypto_set;
  907. struct req_exec_cfg_crypto_set req_exec_cfg_crypto_set;
  908. struct iovec iovec;
  909. int ret = CS_ERR_INVALID_PARAM;
  910. req_exec_cfg_crypto_set.header.size =
  911. sizeof (struct req_exec_cfg_crypto_set);
  912. req_exec_cfg_crypto_set.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  913. MESSAGE_REQ_EXEC_CFG_CRYPTO_SET);
  914. /*
  915. * Set it locally first so we can tell if it is allowed
  916. */
  917. if (api->totem_crypto_set(req_lib_cfg_crypto_set->type) == 0) {
  918. req_exec_cfg_crypto_set.type = req_lib_cfg_crypto_set->type;
  919. iovec.iov_base = (char *)&req_exec_cfg_crypto_set;
  920. iovec.iov_len = sizeof (struct req_exec_cfg_crypto_set);
  921. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  922. ret = CS_OK;
  923. }
  924. res_lib_cfg_crypto_set.header.size = sizeof(res_lib_cfg_crypto_set);
  925. res_lib_cfg_crypto_set.header.id = MESSAGE_RES_CFG_CRYPTO_SET;
  926. res_lib_cfg_crypto_set.header.error = ret;
  927. api->ipc_response_send(conn, &res_lib_cfg_crypto_set,
  928. sizeof(res_lib_cfg_crypto_set));
  929. }