cfg.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  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 <assert.h>
  50. #include <corosync/corotypes.h>
  51. #include <qb/qbipc_common.h>
  52. #include <corosync/cfg.h>
  53. #include <corosync/list.h>
  54. #include <corosync/mar_gen.h>
  55. #include <corosync/totem/totemip.h>
  56. #include <corosync/totem/totem.h>
  57. #include <corosync/ipc_cfg.h>
  58. #include <corosync/lcr/lcr_comp.h>
  59. #include <corosync/engine/logsys.h>
  60. #include <corosync/engine/coroapi.h>
  61. #include <corosync/corodefs.h>
  62. LOGSYS_DECLARE_SUBSYS ("CFG");
  63. enum cfg_message_req_types {
  64. MESSAGE_REQ_EXEC_CFG_RINGREENABLE = 0,
  65. MESSAGE_REQ_EXEC_CFG_KILLNODE = 1,
  66. MESSAGE_REQ_EXEC_CFG_SHUTDOWN = 2,
  67. MESSAGE_REQ_EXEC_CFG_CRYPTO_SET = 3
  68. };
  69. #define DEFAULT_SHUTDOWN_TIMEOUT 5
  70. static struct list_head trackers_list;
  71. /*
  72. * Variables controlling a requested shutdown
  73. */
  74. static corosync_timer_handle_t shutdown_timer;
  75. static struct cfg_info *shutdown_con;
  76. static uint32_t shutdown_flags;
  77. static int shutdown_yes;
  78. static int shutdown_no;
  79. static int shutdown_expected;
  80. struct cfg_info
  81. {
  82. struct list_head list;
  83. void *conn;
  84. void *tracker_conn;
  85. enum {SHUTDOWN_REPLY_UNKNOWN, SHUTDOWN_REPLY_YES, SHUTDOWN_REPLY_NO} shutdown_reply;
  86. };
  87. static void cfg_confchg_fn (
  88. enum totem_configuration_type configuration_type,
  89. const unsigned int *member_list, size_t member_list_entries,
  90. const unsigned int *left_list, size_t left_list_entries,
  91. const unsigned int *joined_list, size_t joined_list_entries,
  92. const struct memb_ring_id *ring_id);
  93. static int cfg_exec_init_fn (struct corosync_api_v1 *corosync_api_v1);
  94. static struct corosync_api_v1 *api;
  95. static int cfg_lib_init_fn (void *conn);
  96. static int cfg_lib_exit_fn (void *conn);
  97. static void message_handler_req_exec_cfg_ringreenable (
  98. const void *message,
  99. unsigned int nodeid);
  100. static void message_handler_req_exec_cfg_killnode (
  101. const void *message,
  102. unsigned int nodeid);
  103. static void message_handler_req_exec_cfg_shutdown (
  104. const void *message,
  105. unsigned int nodeid);
  106. static void message_handler_req_exec_cfg_crypto_set (
  107. const void *message,
  108. unsigned int nodeid);
  109. static void exec_cfg_killnode_endian_convert (void *msg);
  110. static void message_handler_req_lib_cfg_ringstatusget (
  111. void *conn,
  112. const void *msg);
  113. static void message_handler_req_lib_cfg_ringreenable (
  114. void *conn,
  115. const void *msg);
  116. static void message_handler_req_lib_cfg_statetrack (
  117. void *conn,
  118. const void *msg);
  119. static void message_handler_req_lib_cfg_statetrackstop (
  120. void *conn,
  121. const void *msg);
  122. static void message_handler_req_lib_cfg_administrativestateset (
  123. void *conn,
  124. const void *msg);
  125. static void message_handler_req_lib_cfg_administrativestateget (
  126. void *conn,
  127. const void *msg);
  128. static void message_handler_req_lib_cfg_serviceload (
  129. void *conn,
  130. const void *msg);
  131. static void message_handler_req_lib_cfg_serviceunload (
  132. void *conn,
  133. const void *msg);
  134. static void message_handler_req_lib_cfg_killnode (
  135. void *conn,
  136. const void *msg);
  137. static void message_handler_req_lib_cfg_tryshutdown (
  138. void *conn,
  139. const void *msg);
  140. static void message_handler_req_lib_cfg_replytoshutdown (
  141. void *conn,
  142. const void *msg);
  143. static void message_handler_req_lib_cfg_get_node_addrs (
  144. void *conn,
  145. const void *msg);
  146. static void message_handler_req_lib_cfg_local_get (
  147. void *conn,
  148. const void *msg);
  149. static void message_handler_req_lib_cfg_crypto_set (
  150. void *conn,
  151. const void *msg);
  152. /*
  153. * Service Handler Definition
  154. */
  155. static struct corosync_lib_handler cfg_lib_engine[] =
  156. {
  157. { /* 0 */
  158. .lib_handler_fn = message_handler_req_lib_cfg_ringstatusget,
  159. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  160. },
  161. { /* 1 */
  162. .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
  163. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  164. },
  165. { /* 2 */
  166. .lib_handler_fn = message_handler_req_lib_cfg_statetrack,
  167. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  168. },
  169. { /* 3 */
  170. .lib_handler_fn = message_handler_req_lib_cfg_statetrackstop,
  171. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  172. },
  173. { /* 4 */
  174. .lib_handler_fn = message_handler_req_lib_cfg_administrativestateset,
  175. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  176. },
  177. { /* 5 */
  178. .lib_handler_fn = message_handler_req_lib_cfg_administrativestateget,
  179. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  180. },
  181. { /* 6 */
  182. .lib_handler_fn = message_handler_req_lib_cfg_serviceload,
  183. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  184. },
  185. { /* 7 */
  186. .lib_handler_fn = message_handler_req_lib_cfg_serviceunload,
  187. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  188. },
  189. { /* 8 */
  190. .lib_handler_fn = message_handler_req_lib_cfg_killnode,
  191. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  192. },
  193. { /* 9 */
  194. .lib_handler_fn = message_handler_req_lib_cfg_tryshutdown,
  195. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  196. },
  197. { /* 10 */
  198. .lib_handler_fn = message_handler_req_lib_cfg_replytoshutdown,
  199. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  200. },
  201. { /* 11 */
  202. .lib_handler_fn = message_handler_req_lib_cfg_get_node_addrs,
  203. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  204. },
  205. { /* 12 */
  206. .lib_handler_fn = message_handler_req_lib_cfg_local_get,
  207. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  208. },
  209. { /* 13 */
  210. .lib_handler_fn = message_handler_req_lib_cfg_crypto_set,
  211. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  212. }
  213. };
  214. static struct corosync_exec_handler cfg_exec_engine[] =
  215. {
  216. { /* 0 */
  217. .exec_handler_fn = message_handler_req_exec_cfg_ringreenable,
  218. },
  219. { /* 1 */
  220. .exec_handler_fn = message_handler_req_exec_cfg_killnode,
  221. .exec_endian_convert_fn = exec_cfg_killnode_endian_convert
  222. },
  223. { /* 2 */
  224. .exec_handler_fn = message_handler_req_exec_cfg_shutdown,
  225. },
  226. { /* 3 */
  227. .exec_handler_fn = message_handler_req_exec_cfg_crypto_set,
  228. }
  229. };
  230. /*
  231. * Exports the interface for the service
  232. */
  233. struct corosync_service_engine cfg_service_engine = {
  234. .name = "corosync configuration service",
  235. .id = CFG_SERVICE,
  236. .priority = 1,
  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 = sizeof (cfg_exec_engine) / sizeof (struct corosync_exec_handler),
  247. .confchg_fn = cfg_confchg_fn,
  248. .sync_mode = CS_SYNC_V1
  249. };
  250. /*
  251. * Dynamic Loader definition
  252. */
  253. static struct corosync_service_engine *cfg_get_service_engine_ver0 (void);
  254. static struct corosync_service_engine_iface_ver0 cfg_service_engine_iface = {
  255. .corosync_get_service_engine_ver0 = cfg_get_service_engine_ver0
  256. };
  257. static struct lcr_iface corosync_cfg_ver0[1] = {
  258. {
  259. .name = "corosync_cfg",
  260. .version = 0,
  261. .versions_replace = 0,
  262. .versions_replace_count = 0,
  263. .dependencies = 0,
  264. .dependency_count = 0,
  265. .constructor = NULL,
  266. .destructor = NULL,
  267. .interfaces = NULL
  268. }
  269. };
  270. static struct lcr_comp cfg_comp_ver0 = {
  271. .iface_count = 1,
  272. .ifaces = corosync_cfg_ver0
  273. };
  274. static struct corosync_service_engine *cfg_get_service_engine_ver0 (void)
  275. {
  276. return (&cfg_service_engine);
  277. }
  278. #ifdef COROSYNC_SOLARIS
  279. void corosync_lcr_component_register (void);
  280. void corosync_lcr_component_register (void) {
  281. #else
  282. __attribute__ ((constructor)) static void corosync_lcr_component_register (void) {
  283. #endif
  284. lcr_interfaces_set (&corosync_cfg_ver0[0], &cfg_service_engine_iface);
  285. lcr_component_register (&cfg_comp_ver0);
  286. }
  287. struct req_exec_cfg_ringreenable {
  288. struct qb_ipc_request_header header __attribute__((aligned(8)));
  289. mar_message_source_t source __attribute__((aligned(8)));
  290. };
  291. struct req_exec_cfg_killnode {
  292. struct qb_ipc_request_header header __attribute__((aligned(8)));
  293. mar_uint32_t nodeid __attribute__((aligned(8)));
  294. mar_name_t reason __attribute__((aligned(8)));
  295. };
  296. struct req_exec_cfg_crypto_set {
  297. struct qb_ipc_request_header header __attribute__((aligned(8)));
  298. mar_uint32_t type __attribute__((aligned(8)));
  299. };
  300. struct req_exec_cfg_shutdown {
  301. struct qb_ipc_request_header header __attribute__((aligned(8)));
  302. };
  303. /* IMPL */
  304. static int cfg_exec_init_fn (
  305. struct corosync_api_v1 *corosync_api_v1)
  306. {
  307. #ifdef COROSYNC_SOLARIS
  308. logsys_subsys_init();
  309. #endif
  310. api = corosync_api_v1;
  311. list_init(&trackers_list);
  312. return (0);
  313. }
  314. static void cfg_confchg_fn (
  315. enum totem_configuration_type configuration_type,
  316. const unsigned int *member_list, size_t member_list_entries,
  317. const unsigned int *left_list, size_t left_list_entries,
  318. const unsigned int *joined_list, size_t joined_list_entries,
  319. const struct memb_ring_id *ring_id)
  320. {
  321. }
  322. /*
  323. * Tell other nodes we are shutting down
  324. */
  325. static int send_shutdown(void)
  326. {
  327. struct req_exec_cfg_shutdown req_exec_cfg_shutdown;
  328. struct iovec iovec;
  329. ENTER();
  330. req_exec_cfg_shutdown.header.size =
  331. sizeof (struct req_exec_cfg_shutdown);
  332. req_exec_cfg_shutdown.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  333. MESSAGE_REQ_EXEC_CFG_SHUTDOWN);
  334. iovec.iov_base = (char *)&req_exec_cfg_shutdown;
  335. iovec.iov_len = sizeof (struct req_exec_cfg_shutdown);
  336. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  337. LEAVE();
  338. return 0;
  339. }
  340. static void send_test_shutdown(void *only_conn, void *exclude_conn, int status)
  341. {
  342. struct res_lib_cfg_testshutdown res_lib_cfg_testshutdown;
  343. struct list_head *iter;
  344. ENTER();
  345. res_lib_cfg_testshutdown.header.size = sizeof(struct res_lib_cfg_testshutdown);
  346. res_lib_cfg_testshutdown.header.id = MESSAGE_RES_CFG_TESTSHUTDOWN;
  347. res_lib_cfg_testshutdown.header.error = status;
  348. res_lib_cfg_testshutdown.flags = shutdown_flags;
  349. if (only_conn) {
  350. TRACE1("sending testshutdown to only %p", only_conn);
  351. api->ipc_dispatch_send(only_conn, &res_lib_cfg_testshutdown,
  352. sizeof(res_lib_cfg_testshutdown));
  353. } else {
  354. for (iter = trackers_list.next; iter != &trackers_list; iter = iter->next) {
  355. struct cfg_info *ci = list_entry(iter, struct cfg_info, list);
  356. if (ci->conn != exclude_conn) {
  357. TRACE1("sending testshutdown to %p", ci->tracker_conn);
  358. api->ipc_dispatch_send(ci->tracker_conn, &res_lib_cfg_testshutdown,
  359. sizeof(res_lib_cfg_testshutdown));
  360. }
  361. }
  362. }
  363. LEAVE();
  364. }
  365. static void check_shutdown_status(void)
  366. {
  367. ENTER();
  368. /*
  369. * Shutdown client might have gone away
  370. */
  371. if (!shutdown_con) {
  372. LEAVE();
  373. return;
  374. }
  375. /*
  376. * All replies safely gathered in ?
  377. */
  378. if (shutdown_yes + shutdown_no >= shutdown_expected) {
  379. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  380. api->timer_delete(shutdown_timer);
  381. if (shutdown_yes >= shutdown_expected ||
  382. shutdown_flags == CFG_SHUTDOWN_FLAG_REGARDLESS) {
  383. TRACE1("shutdown confirmed");
  384. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  385. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  386. res_lib_cfg_tryshutdown.header.error = CS_OK;
  387. /*
  388. * Tell originator that shutdown was confirmed
  389. */
  390. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  391. sizeof(res_lib_cfg_tryshutdown));
  392. shutdown_con = NULL;
  393. /*
  394. * Tell other nodes we are going down
  395. */
  396. send_shutdown();
  397. }
  398. else {
  399. TRACE1("shutdown cancelled");
  400. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  401. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  402. res_lib_cfg_tryshutdown.header.error = CS_ERR_BUSY;
  403. /*
  404. * Tell originator that shutdown was cancelled
  405. */
  406. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  407. sizeof(res_lib_cfg_tryshutdown));
  408. shutdown_con = NULL;
  409. }
  410. log_printf(LOGSYS_LEVEL_DEBUG, "shutdown decision is: (yes count: %d, no count: %d) flags=%x\n", shutdown_yes, shutdown_no, shutdown_flags);
  411. }
  412. LEAVE();
  413. }
  414. /*
  415. * Not all nodes responded to the shutdown (in time)
  416. */
  417. static void shutdown_timer_fn(void *arg)
  418. {
  419. ENTER();
  420. /*
  421. * Mark undecideds as "NO"
  422. */
  423. shutdown_no = shutdown_expected;
  424. check_shutdown_status();
  425. send_test_shutdown(NULL, NULL, CS_ERR_TIMEOUT);
  426. LEAVE();
  427. }
  428. static void remove_ci_from_shutdown(struct cfg_info *ci)
  429. {
  430. ENTER();
  431. /*
  432. * If the controlling shutdown process has quit, then cancel the
  433. * shutdown session
  434. */
  435. if (ci == shutdown_con) {
  436. shutdown_con = NULL;
  437. api->timer_delete(shutdown_timer);
  438. }
  439. if (!list_empty(&ci->list)) {
  440. list_del(&ci->list);
  441. list_init(&ci->list);
  442. /*
  443. * Remove our option
  444. */
  445. if (shutdown_con) {
  446. if (ci->shutdown_reply == SHUTDOWN_REPLY_YES)
  447. shutdown_yes--;
  448. if (ci->shutdown_reply == SHUTDOWN_REPLY_NO)
  449. shutdown_no--;
  450. }
  451. /*
  452. * If we are leaving, then that's an implicit YES to shutdown
  453. */
  454. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  455. shutdown_yes++;
  456. check_shutdown_status();
  457. }
  458. LEAVE();
  459. }
  460. int cfg_lib_exit_fn (void *conn)
  461. {
  462. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  463. ENTER();
  464. remove_ci_from_shutdown(ci);
  465. LEAVE();
  466. return (0);
  467. }
  468. static int cfg_lib_init_fn (void *conn)
  469. {
  470. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  471. ENTER();
  472. list_init(&ci->list);
  473. LEAVE();
  474. return (0);
  475. }
  476. /*
  477. * Executive message handlers
  478. */
  479. static void message_handler_req_exec_cfg_ringreenable (
  480. const void *message,
  481. unsigned int nodeid)
  482. {
  483. const struct req_exec_cfg_ringreenable *req_exec_cfg_ringreenable
  484. = message;
  485. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  486. ENTER();
  487. api->totem_ring_reenable ();
  488. if (api->ipc_source_is_local(&req_exec_cfg_ringreenable->source)) {
  489. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  490. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  491. res_lib_cfg_ringreenable.header.error = CS_OK;
  492. api->ipc_response_send (
  493. req_exec_cfg_ringreenable->source.conn,
  494. &res_lib_cfg_ringreenable,
  495. sizeof (struct res_lib_cfg_ringreenable));
  496. api->ipc_refcnt_dec(req_exec_cfg_ringreenable->source.conn);
  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. api->ipc_refcnt_inc(conn);
  598. iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
  599. iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
  600. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  601. LEAVE();
  602. }
  603. static void message_handler_req_lib_cfg_statetrack (
  604. void *conn,
  605. const void *msg)
  606. {
  607. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  608. struct res_lib_cfg_statetrack res_lib_cfg_statetrack;
  609. ENTER();
  610. /*
  611. * We only do shutdown tracking at the moment
  612. */
  613. if (list_empty(&ci->list)) {
  614. list_add(&ci->list, &trackers_list);
  615. ci->tracker_conn = conn;
  616. if (shutdown_con) {
  617. /*
  618. * Shutdown already in progress, ask the newcomer's opinion
  619. */
  620. ci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  621. shutdown_expected++;
  622. send_test_shutdown(conn, NULL, CS_OK);
  623. }
  624. }
  625. res_lib_cfg_statetrack.header.size = sizeof(struct res_lib_cfg_statetrack);
  626. res_lib_cfg_statetrack.header.id = MESSAGE_RES_CFG_STATETRACKSTART;
  627. res_lib_cfg_statetrack.header.error = CS_OK;
  628. api->ipc_response_send(conn, &res_lib_cfg_statetrack,
  629. sizeof(res_lib_cfg_statetrack));
  630. LEAVE();
  631. }
  632. static void message_handler_req_lib_cfg_statetrackstop (
  633. void *conn,
  634. const void *msg)
  635. {
  636. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  637. // struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
  638. ENTER();
  639. remove_ci_from_shutdown(ci);
  640. LEAVE();
  641. }
  642. static void message_handler_req_lib_cfg_administrativestateset (
  643. void *conn,
  644. const void *msg)
  645. {
  646. // struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
  647. ENTER();
  648. LEAVE();
  649. }
  650. static void message_handler_req_lib_cfg_administrativestateget (
  651. void *conn,
  652. const void *msg)
  653. {
  654. // struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;
  655. ENTER();
  656. LEAVE();
  657. }
  658. static void message_handler_req_lib_cfg_serviceload (
  659. void *conn,
  660. const void *msg)
  661. {
  662. const struct req_lib_cfg_serviceload *req_lib_cfg_serviceload = msg;
  663. struct res_lib_cfg_serviceload res_lib_cfg_serviceload;
  664. ENTER();
  665. api->service_link_and_init (
  666. api,
  667. (const char *)req_lib_cfg_serviceload->service_name,
  668. req_lib_cfg_serviceload->service_ver);
  669. res_lib_cfg_serviceload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  670. res_lib_cfg_serviceload.header.size = sizeof (struct res_lib_cfg_serviceload);
  671. res_lib_cfg_serviceload.header.error = CS_OK;
  672. api->ipc_response_send (
  673. conn,
  674. &res_lib_cfg_serviceload,
  675. sizeof (struct res_lib_cfg_serviceload));
  676. LEAVE();
  677. }
  678. static void message_handler_req_lib_cfg_serviceunload (
  679. void *conn,
  680. const void *msg)
  681. {
  682. const struct req_lib_cfg_serviceunload *req_lib_cfg_serviceunload = msg;
  683. struct res_lib_cfg_serviceunload res_lib_cfg_serviceunload;
  684. ENTER();
  685. api->service_unlink_and_exit (
  686. api,
  687. (const char *)req_lib_cfg_serviceunload->service_name,
  688. req_lib_cfg_serviceunload->service_ver);
  689. res_lib_cfg_serviceunload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  690. res_lib_cfg_serviceunload.header.size = sizeof (struct res_lib_cfg_serviceunload);
  691. res_lib_cfg_serviceunload.header.error = CS_OK;
  692. api->ipc_response_send (
  693. conn,
  694. &res_lib_cfg_serviceunload,
  695. sizeof (struct res_lib_cfg_serviceunload));
  696. LEAVE();
  697. }
  698. static void message_handler_req_lib_cfg_killnode (
  699. void *conn,
  700. const void *msg)
  701. {
  702. const struct req_lib_cfg_killnode *req_lib_cfg_killnode = msg;
  703. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  704. struct req_exec_cfg_killnode req_exec_cfg_killnode;
  705. struct iovec iovec;
  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. (void)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. char *addr_buf;
  874. if (nodeid == 0)
  875. nodeid = api->totem_nodeid_get();
  876. api->totem_ifaces_get(nodeid, node_ifs, &status, &num_interfaces);
  877. res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
  878. res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
  879. res_lib_cfg_get_node_addrs->header.error = ret;
  880. res_lib_cfg_get_node_addrs->num_addrs = num_interfaces;
  881. if (num_interfaces) {
  882. res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
  883. for (i = 0, addr_buf = (char *)res_lib_cfg_get_node_addrs->addrs;
  884. i < num_interfaces; i++, addr_buf += TOTEMIP_ADDRLEN) {
  885. memcpy(addr_buf, node_ifs[i].addr, TOTEMIP_ADDRLEN);
  886. }
  887. }
  888. else {
  889. res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
  890. }
  891. api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
  892. }
  893. static void message_handler_req_lib_cfg_local_get (void *conn, const void *msg)
  894. {
  895. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  896. res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
  897. res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
  898. res_lib_cfg_local_get.header.error = CS_OK;
  899. res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
  900. api->ipc_response_send(conn, &res_lib_cfg_local_get,
  901. sizeof(res_lib_cfg_local_get));
  902. }
  903. static void message_handler_req_lib_cfg_crypto_set (
  904. void *conn,
  905. const void *msg)
  906. {
  907. const struct req_lib_cfg_crypto_set *req_lib_cfg_crypto_set = msg;
  908. struct res_lib_cfg_crypto_set res_lib_cfg_crypto_set;
  909. struct req_exec_cfg_crypto_set req_exec_cfg_crypto_set;
  910. struct iovec iovec;
  911. int ret = CS_ERR_INVALID_PARAM;
  912. req_exec_cfg_crypto_set.header.size =
  913. sizeof (struct req_exec_cfg_crypto_set);
  914. req_exec_cfg_crypto_set.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  915. MESSAGE_REQ_EXEC_CFG_CRYPTO_SET);
  916. /*
  917. * Set it locally first so we can tell if it is allowed
  918. */
  919. if (api->totem_crypto_set(req_lib_cfg_crypto_set->type) == 0) {
  920. req_exec_cfg_crypto_set.type = req_lib_cfg_crypto_set->type;
  921. iovec.iov_base = (char *)&req_exec_cfg_crypto_set;
  922. iovec.iov_len = sizeof (struct req_exec_cfg_crypto_set);
  923. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  924. ret = CS_OK;
  925. }
  926. res_lib_cfg_crypto_set.header.size = sizeof(res_lib_cfg_crypto_set);
  927. res_lib_cfg_crypto_set.header.id = MESSAGE_RES_CFG_CRYPTO_SET;
  928. res_lib_cfg_crypto_set.header.error = ret;
  929. api->ipc_response_send(conn, &res_lib_cfg_crypto_set,
  930. sizeof(res_lib_cfg_crypto_set));
  931. }