cfg.c 30 KB

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