cfg.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. /*
  2. * Copyright (c) 2005-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2018 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 <stddef.h>
  47. #include <limits.h>
  48. #include <errno.h>
  49. #include <string.h>
  50. #include <assert.h>
  51. #include <corosync/corotypes.h>
  52. #include <qb/qbipc_common.h>
  53. #include <corosync/cfg.h>
  54. #include <qb/qblist.h>
  55. #include <corosync/mar_gen.h>
  56. #include <corosync/totem/totemip.h>
  57. #include <corosync/totem/totem.h>
  58. #include <corosync/ipc_cfg.h>
  59. #include <corosync/logsys.h>
  60. #include <corosync/coroapi.h>
  61. #include <corosync/icmap.h>
  62. #include <corosync/corodefs.h>
  63. #include "totemconfig.h"
  64. #include "totemknet.h"
  65. #include "service.h"
  66. #include "main.h"
  67. LOGSYS_DECLARE_SUBSYS ("CFG");
  68. enum cfg_message_req_types {
  69. MESSAGE_REQ_EXEC_CFG_RINGREENABLE = 0,
  70. MESSAGE_REQ_EXEC_CFG_KILLNODE = 1,
  71. MESSAGE_REQ_EXEC_CFG_SHUTDOWN = 2,
  72. MESSAGE_REQ_EXEC_CFG_RELOAD_CONFIG = 3,
  73. MESSAGE_REQ_EXEC_CFG_CRYPTO_RECONFIG = 4
  74. };
  75. #define DEFAULT_SHUTDOWN_TIMEOUT 5
  76. static struct qb_list_head trackers_list;
  77. /*
  78. * Variables controlling a requested shutdown
  79. */
  80. static corosync_timer_handle_t shutdown_timer;
  81. static struct cfg_info *shutdown_con;
  82. static uint32_t shutdown_flags;
  83. static int shutdown_yes;
  84. static int shutdown_no;
  85. static int shutdown_expected;
  86. struct cfg_info
  87. {
  88. struct qb_list_head list;
  89. void *conn;
  90. void *tracker_conn;
  91. enum {SHUTDOWN_REPLY_UNKNOWN, SHUTDOWN_REPLY_YES, SHUTDOWN_REPLY_NO} shutdown_reply;
  92. };
  93. static void cfg_confchg_fn (
  94. enum totem_configuration_type configuration_type,
  95. const unsigned int *member_list, size_t member_list_entries,
  96. const unsigned int *left_list, size_t left_list_entries,
  97. const unsigned int *joined_list, size_t joined_list_entries,
  98. const struct memb_ring_id *ring_id);
  99. static char *cfg_exec_init_fn (struct corosync_api_v1 *corosync_api_v1);
  100. static struct corosync_api_v1 *api;
  101. static int cfg_lib_init_fn (void *conn);
  102. static int cfg_lib_exit_fn (void *conn);
  103. static void message_handler_req_exec_cfg_ringreenable (
  104. const void *message,
  105. unsigned int nodeid);
  106. static void message_handler_req_exec_cfg_killnode (
  107. const void *message,
  108. unsigned int nodeid);
  109. static void message_handler_req_exec_cfg_shutdown (
  110. const void *message,
  111. unsigned int nodeid);
  112. static void message_handler_req_exec_cfg_reload_config (
  113. const void *message,
  114. unsigned int nodeid);
  115. static void message_handler_req_exec_cfg_reconfig_crypto (
  116. const void *message,
  117. unsigned int nodeid);
  118. static void exec_cfg_killnode_endian_convert (void *msg);
  119. static void message_handler_req_lib_cfg_ringstatusget (
  120. void *conn,
  121. const void *msg);
  122. static void message_handler_req_lib_cfg_nodestatusget (
  123. void *conn,
  124. const void *msg);
  125. static void message_handler_req_lib_cfg_ringreenable (
  126. void *conn,
  127. const void *msg);
  128. static void message_handler_req_lib_cfg_killnode (
  129. void *conn,
  130. const void *msg);
  131. static void message_handler_req_lib_cfg_tryshutdown (
  132. void *conn,
  133. const void *msg);
  134. static void message_handler_req_lib_cfg_replytoshutdown (
  135. void *conn,
  136. const void *msg);
  137. static void message_handler_req_lib_cfg_get_node_addrs (
  138. void *conn,
  139. const void *msg);
  140. static void message_handler_req_lib_cfg_local_get (
  141. void *conn,
  142. const void *msg);
  143. static void message_handler_req_lib_cfg_reload_config (
  144. void *conn,
  145. const void *msg);
  146. static void message_handler_req_lib_cfg_reopen_log_files (
  147. void *conn,
  148. const void *msg);
  149. /*
  150. * Service Handler Definition
  151. */
  152. static struct corosync_lib_handler cfg_lib_engine[] =
  153. {
  154. { /* 0 */
  155. .lib_handler_fn = message_handler_req_lib_cfg_ringstatusget,
  156. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  157. },
  158. { /* 1 */
  159. .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
  160. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  161. },
  162. { /* 2 */
  163. .lib_handler_fn = message_handler_req_lib_cfg_killnode,
  164. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  165. },
  166. { /* 3 */
  167. .lib_handler_fn = message_handler_req_lib_cfg_tryshutdown,
  168. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  169. },
  170. { /* 4 */
  171. .lib_handler_fn = message_handler_req_lib_cfg_replytoshutdown,
  172. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  173. },
  174. { /* 5 */
  175. .lib_handler_fn = message_handler_req_lib_cfg_get_node_addrs,
  176. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  177. },
  178. { /* 6 */
  179. .lib_handler_fn = message_handler_req_lib_cfg_local_get,
  180. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  181. },
  182. { /* 7 */
  183. .lib_handler_fn = message_handler_req_lib_cfg_reload_config,
  184. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  185. },
  186. { /* 8 */
  187. .lib_handler_fn = message_handler_req_lib_cfg_reopen_log_files,
  188. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  189. },
  190. { /* 9 */
  191. .lib_handler_fn = message_handler_req_lib_cfg_nodestatusget,
  192. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  193. }
  194. };
  195. static struct corosync_exec_handler cfg_exec_engine[] =
  196. {
  197. { /* 0 */
  198. .exec_handler_fn = message_handler_req_exec_cfg_ringreenable,
  199. },
  200. { /* 1 */
  201. .exec_handler_fn = message_handler_req_exec_cfg_killnode,
  202. .exec_endian_convert_fn = exec_cfg_killnode_endian_convert
  203. },
  204. { /* 2 */
  205. .exec_handler_fn = message_handler_req_exec_cfg_shutdown,
  206. },
  207. { /* 3 */
  208. .exec_handler_fn = message_handler_req_exec_cfg_reload_config,
  209. },
  210. { /* 4 */
  211. .exec_handler_fn = message_handler_req_exec_cfg_reconfig_crypto,
  212. }
  213. };
  214. /*
  215. * Exports the interface for the service
  216. */
  217. struct corosync_service_engine cfg_service_engine = {
  218. .name = "corosync configuration service",
  219. .id = CFG_SERVICE,
  220. .priority = 1,
  221. .private_data_size = sizeof(struct cfg_info),
  222. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED,
  223. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  224. .lib_init_fn = cfg_lib_init_fn,
  225. .lib_exit_fn = cfg_lib_exit_fn,
  226. .lib_engine = cfg_lib_engine,
  227. .lib_engine_count = sizeof (cfg_lib_engine) / sizeof (struct corosync_lib_handler),
  228. .exec_init_fn = cfg_exec_init_fn,
  229. .exec_engine = cfg_exec_engine,
  230. .exec_engine_count = sizeof (cfg_exec_engine) / sizeof (struct corosync_exec_handler),
  231. .confchg_fn = cfg_confchg_fn
  232. };
  233. struct corosync_service_engine *cfg_get_service_engine_ver0 (void)
  234. {
  235. return (&cfg_service_engine);
  236. }
  237. struct req_exec_cfg_ringreenable {
  238. struct qb_ipc_request_header header __attribute__((aligned(8)));
  239. mar_message_source_t source __attribute__((aligned(8)));
  240. };
  241. struct req_exec_cfg_reload_config {
  242. struct qb_ipc_request_header header __attribute__((aligned(8)));
  243. mar_message_source_t source __attribute__((aligned(8)));
  244. };
  245. struct req_exec_cfg_crypto_reconfig {
  246. struct qb_ipc_request_header header __attribute__((aligned(8)));
  247. mar_uint32_t phase __attribute__((aligned(8)));
  248. };
  249. struct req_exec_cfg_killnode {
  250. struct qb_ipc_request_header header __attribute__((aligned(8)));
  251. mar_uint32_t nodeid __attribute__((aligned(8)));
  252. mar_name_t reason __attribute__((aligned(8)));
  253. };
  254. struct req_exec_cfg_shutdown {
  255. struct qb_ipc_request_header header __attribute__((aligned(8)));
  256. };
  257. /* IMPL */
  258. static char *cfg_exec_init_fn (
  259. struct corosync_api_v1 *corosync_api_v1)
  260. {
  261. api = corosync_api_v1;
  262. qb_list_init(&trackers_list);
  263. return (NULL);
  264. }
  265. static void cfg_confchg_fn (
  266. enum totem_configuration_type configuration_type,
  267. const unsigned int *member_list, size_t member_list_entries,
  268. const unsigned int *left_list, size_t left_list_entries,
  269. const unsigned int *joined_list, size_t joined_list_entries,
  270. const struct memb_ring_id *ring_id)
  271. {
  272. }
  273. /*
  274. * Tell other nodes we are shutting down
  275. */
  276. static int send_shutdown(void)
  277. {
  278. struct req_exec_cfg_shutdown req_exec_cfg_shutdown;
  279. struct iovec iovec;
  280. ENTER();
  281. req_exec_cfg_shutdown.header.size =
  282. sizeof (struct req_exec_cfg_shutdown);
  283. req_exec_cfg_shutdown.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  284. MESSAGE_REQ_EXEC_CFG_SHUTDOWN);
  285. iovec.iov_base = (char *)&req_exec_cfg_shutdown;
  286. iovec.iov_len = sizeof (struct req_exec_cfg_shutdown);
  287. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  288. LEAVE();
  289. return 0;
  290. }
  291. static void send_test_shutdown(void *only_conn, void *exclude_conn, int status)
  292. {
  293. struct res_lib_cfg_testshutdown res_lib_cfg_testshutdown;
  294. struct qb_list_head *iter;
  295. ENTER();
  296. res_lib_cfg_testshutdown.header.size = sizeof(struct res_lib_cfg_testshutdown);
  297. res_lib_cfg_testshutdown.header.id = MESSAGE_RES_CFG_TESTSHUTDOWN;
  298. res_lib_cfg_testshutdown.header.error = status;
  299. res_lib_cfg_testshutdown.flags = shutdown_flags;
  300. if (only_conn) {
  301. TRACE1("sending testshutdown to only %p", only_conn);
  302. api->ipc_dispatch_send(only_conn, &res_lib_cfg_testshutdown,
  303. sizeof(res_lib_cfg_testshutdown));
  304. } else {
  305. qb_list_for_each(iter, &trackers_list) {
  306. struct cfg_info *ci = qb_list_entry(iter, struct cfg_info, list);
  307. if (ci->conn != exclude_conn) {
  308. TRACE1("sending testshutdown to %p", ci->tracker_conn);
  309. api->ipc_dispatch_send(ci->tracker_conn, &res_lib_cfg_testshutdown,
  310. sizeof(res_lib_cfg_testshutdown));
  311. }
  312. }
  313. }
  314. LEAVE();
  315. }
  316. static void check_shutdown_status(void)
  317. {
  318. ENTER();
  319. /*
  320. * Shutdown client might have gone away
  321. */
  322. if (!shutdown_con) {
  323. LEAVE();
  324. return;
  325. }
  326. /*
  327. * All replies safely gathered in ?
  328. */
  329. if (shutdown_yes + shutdown_no >= shutdown_expected) {
  330. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  331. api->timer_delete(shutdown_timer);
  332. if (shutdown_yes >= shutdown_expected ||
  333. shutdown_flags == CFG_SHUTDOWN_FLAG_REGARDLESS) {
  334. TRACE1("shutdown confirmed");
  335. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  336. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  337. res_lib_cfg_tryshutdown.header.error = CS_OK;
  338. /*
  339. * Tell originator that shutdown was confirmed
  340. */
  341. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  342. sizeof(res_lib_cfg_tryshutdown));
  343. shutdown_con = NULL;
  344. /*
  345. * Tell other nodes we are going down
  346. */
  347. send_shutdown();
  348. }
  349. else {
  350. TRACE1("shutdown cancelled");
  351. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  352. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  353. res_lib_cfg_tryshutdown.header.error = CS_ERR_BUSY;
  354. /*
  355. * Tell originator that shutdown was cancelled
  356. */
  357. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  358. sizeof(res_lib_cfg_tryshutdown));
  359. shutdown_con = NULL;
  360. }
  361. log_printf(LOGSYS_LEVEL_DEBUG, "shutdown decision is: (yes count: %d, no count: %d) flags=%x",
  362. shutdown_yes, shutdown_no, shutdown_flags);
  363. }
  364. LEAVE();
  365. }
  366. /*
  367. * Not all nodes responded to the shutdown (in time)
  368. */
  369. static void shutdown_timer_fn(void *arg)
  370. {
  371. ENTER();
  372. /*
  373. * Mark undecideds as "NO"
  374. */
  375. shutdown_no = shutdown_expected;
  376. check_shutdown_status();
  377. send_test_shutdown(NULL, NULL, CS_ERR_TIMEOUT);
  378. LEAVE();
  379. }
  380. static void remove_ci_from_shutdown(struct cfg_info *ci)
  381. {
  382. ENTER();
  383. /*
  384. * If the controlling shutdown process has quit, then cancel the
  385. * shutdown session
  386. */
  387. if (ci == shutdown_con) {
  388. shutdown_con = NULL;
  389. api->timer_delete(shutdown_timer);
  390. }
  391. if (!qb_list_empty(&ci->list)) {
  392. qb_list_del(&ci->list);
  393. qb_list_init(&ci->list);
  394. /*
  395. * Remove our option
  396. */
  397. if (shutdown_con) {
  398. if (ci->shutdown_reply == SHUTDOWN_REPLY_YES)
  399. shutdown_yes--;
  400. if (ci->shutdown_reply == SHUTDOWN_REPLY_NO)
  401. shutdown_no--;
  402. }
  403. /*
  404. * If we are leaving, then that's an implicit YES to shutdown
  405. */
  406. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  407. shutdown_yes++;
  408. check_shutdown_status();
  409. }
  410. LEAVE();
  411. }
  412. int cfg_lib_exit_fn (void *conn)
  413. {
  414. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  415. ENTER();
  416. remove_ci_from_shutdown(ci);
  417. LEAVE();
  418. return (0);
  419. }
  420. static int cfg_lib_init_fn (void *conn)
  421. {
  422. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  423. ENTER();
  424. qb_list_init(&ci->list);
  425. LEAVE();
  426. return (0);
  427. }
  428. /*
  429. * Executive message handlers
  430. */
  431. static void message_handler_req_exec_cfg_ringreenable (
  432. const void *message,
  433. unsigned int nodeid)
  434. {
  435. ENTER();
  436. LEAVE();
  437. }
  438. static void exec_cfg_killnode_endian_convert (void *msg)
  439. {
  440. struct req_exec_cfg_killnode *req_exec_cfg_killnode =
  441. (struct req_exec_cfg_killnode *)msg;
  442. ENTER();
  443. swab_mar_name_t(&req_exec_cfg_killnode->reason);
  444. LEAVE();
  445. }
  446. static void message_handler_req_exec_cfg_killnode (
  447. const void *message,
  448. unsigned int nodeid)
  449. {
  450. const struct req_exec_cfg_killnode *req_exec_cfg_killnode = message;
  451. cs_name_t reason;
  452. ENTER();
  453. log_printf(LOGSYS_LEVEL_DEBUG, "request to kill node " CS_PRI_NODE_ID " (us=" CS_PRI_NODE_ID ")",
  454. req_exec_cfg_killnode->nodeid, api->totem_nodeid_get());
  455. if (req_exec_cfg_killnode->nodeid == api->totem_nodeid_get()) {
  456. marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
  457. log_printf(LOGSYS_LEVEL_NOTICE, "Killed by node " CS_PRI_NODE_ID " : %s",
  458. nodeid, reason.value);
  459. corosync_fatal_error(COROSYNC_FATAL_ERROR_EXIT);
  460. }
  461. LEAVE();
  462. }
  463. /*
  464. * Self shutdown
  465. */
  466. static void message_handler_req_exec_cfg_shutdown (
  467. const void *message,
  468. unsigned int nodeid)
  469. {
  470. ENTER();
  471. log_printf(LOGSYS_LEVEL_NOTICE, "Node " CS_PRI_NODE_ID " was shut down by sysadmin", nodeid);
  472. if (nodeid == api->totem_nodeid_get()) {
  473. api->shutdown_request();
  474. }
  475. LEAVE();
  476. }
  477. /* strcmp replacement that can handle NULLs */
  478. static int nullcheck_strcmp(const char* left, const char *right)
  479. {
  480. if (!left && right)
  481. return -1;
  482. if (left && !right)
  483. return 1;
  484. if (!left && !right)
  485. return 0;
  486. return strcmp(left, right);
  487. }
  488. /*
  489. * If a key has changed value in the new file, then warn the user and remove it from the temp_map
  490. */
  491. static void delete_and_notify_if_changed(icmap_map_t temp_map, const char *key_name)
  492. {
  493. if (!(icmap_key_value_eq(temp_map, key_name, icmap_get_global_map(), key_name))) {
  494. if (icmap_delete_r(temp_map, key_name) == CS_OK) {
  495. log_printf(LOGSYS_LEVEL_NOTICE, "Modified entry '%s' in corosync.conf cannot be changed at run-time", key_name);
  496. }
  497. }
  498. }
  499. /*
  500. * Remove any keys from the new config file that in the new corosync.conf but that
  501. * cannot be changed at run time. A log message will be issued for each
  502. * entry that the user wants to change but they cannot.
  503. *
  504. * Add more here as needed.
  505. */
  506. static void remove_ro_entries(icmap_map_t temp_map)
  507. {
  508. #ifndef HAVE_KNET_CRYPTO_RECONF
  509. delete_and_notify_if_changed(temp_map, "totem.secauth");
  510. delete_and_notify_if_changed(temp_map, "totem.crypto_hash");
  511. delete_and_notify_if_changed(temp_map, "totem.crypto_cipher");
  512. delete_and_notify_if_changed(temp_map, "totem.keyfile");
  513. delete_and_notify_if_changed(temp_map, "totem.key");
  514. #endif
  515. delete_and_notify_if_changed(temp_map, "totem.version");
  516. delete_and_notify_if_changed(temp_map, "totem.threads");
  517. delete_and_notify_if_changed(temp_map, "totem.ip_version");
  518. delete_and_notify_if_changed(temp_map, "totem.rrp_mode");
  519. delete_and_notify_if_changed(temp_map, "totem.netmtu");
  520. delete_and_notify_if_changed(temp_map, "totem.interface.ringnumber");
  521. delete_and_notify_if_changed(temp_map, "totem.interface.bindnetaddr");
  522. delete_and_notify_if_changed(temp_map, "totem.interface.mcastaddr");
  523. delete_and_notify_if_changed(temp_map, "totem.interface.broadcast");
  524. delete_and_notify_if_changed(temp_map, "totem.interface.mcastport");
  525. delete_and_notify_if_changed(temp_map, "totem.interface.ttl");
  526. delete_and_notify_if_changed(temp_map, "totem.transport");
  527. delete_and_notify_if_changed(temp_map, "totem.cluster_name");
  528. delete_and_notify_if_changed(temp_map, "quorum.provider");
  529. delete_and_notify_if_changed(temp_map, "system.move_to_root_cgroup");
  530. delete_and_notify_if_changed(temp_map, "system.sched_rr");
  531. delete_and_notify_if_changed(temp_map, "system.priority");
  532. delete_and_notify_if_changed(temp_map, "system.qb_ipc_type");
  533. delete_and_notify_if_changed(temp_map, "system.state_dir");
  534. }
  535. /*
  536. * Remove entries that exist in the global map, but not in the temp_map, this will
  537. * cause delete notifications to be sent to any listeners.
  538. *
  539. * NOTE: This routine depends entirely on the keys returned by the iterators
  540. * being in alpha-sorted order.
  541. */
  542. static void remove_deleted_entries(icmap_map_t temp_map, const char *prefix)
  543. {
  544. icmap_iter_t old_iter;
  545. icmap_iter_t new_iter;
  546. const char *old_key, *new_key;
  547. int ret;
  548. old_iter = icmap_iter_init(prefix);
  549. new_iter = icmap_iter_init_r(temp_map, prefix);
  550. old_key = icmap_iter_next(old_iter, NULL, NULL);
  551. new_key = icmap_iter_next(new_iter, NULL, NULL);
  552. while (old_key || new_key) {
  553. ret = nullcheck_strcmp(old_key, new_key);
  554. if ((ret < 0 && old_key) || !new_key) {
  555. /*
  556. * new_key is greater, a line (or more) has been deleted
  557. * Continue until old is >= new
  558. */
  559. do {
  560. /* Remove it from icmap & send notifications */
  561. icmap_delete(old_key);
  562. old_key = icmap_iter_next(old_iter, NULL, NULL);
  563. ret = nullcheck_strcmp(old_key, new_key);
  564. } while (ret < 0 && old_key);
  565. }
  566. else if ((ret > 0 && new_key) || !old_key) {
  567. /*
  568. * old_key is greater, a line (or more) has been added
  569. * Continue until new is >= old
  570. *
  571. * we don't need to do anything special with this like tell
  572. * icmap. That will happen when we copy the values over
  573. */
  574. do {
  575. new_key = icmap_iter_next(new_iter, NULL, NULL);
  576. ret = nullcheck_strcmp(old_key, new_key);
  577. } while (ret > 0 && new_key);
  578. }
  579. if (ret == 0) {
  580. new_key = icmap_iter_next(new_iter, NULL, NULL);
  581. old_key = icmap_iter_next(old_iter, NULL, NULL);
  582. }
  583. }
  584. icmap_iter_finalize(new_iter);
  585. icmap_iter_finalize(old_iter);
  586. }
  587. /*
  588. * Reload configuration file
  589. */
  590. static void message_handler_req_exec_cfg_reload_config (
  591. const void *message,
  592. unsigned int nodeid)
  593. {
  594. const struct req_exec_cfg_reload_config *req_exec_cfg_reload_config = message;
  595. struct res_lib_cfg_reload_config res_lib_cfg_reload_config;
  596. struct totem_config new_config;
  597. icmap_map_t temp_map;
  598. const char *error_string;
  599. int res = CS_OK;
  600. ENTER();
  601. log_printf(LOGSYS_LEVEL_NOTICE, "Config reload requested by node " CS_PRI_NODE_ID, nodeid);
  602. icmap_set_uint8("config.totemconfig_reload_in_progress", 1);
  603. /* Make sure there is no rubbish in this that might be checked, even on error */
  604. memset(&new_config, 0, sizeof(new_config));
  605. /*
  606. * Set up a new hashtable as a staging area.
  607. */
  608. if ((res = icmap_init_r(&temp_map)) != CS_OK) {
  609. log_printf(LOGSYS_LEVEL_ERROR, "Unable to create temporary icmap. config file reload cancelled\n");
  610. goto reload_fini_nomap;
  611. }
  612. /*
  613. * Load new config into the temporary map
  614. */
  615. res = coroparse_configparse(temp_map, &error_string);
  616. if (res == -1) {
  617. log_printf (LOGSYS_LEVEL_ERROR, "Unable to reload config file: %s", error_string);
  618. res = CS_ERR_INVALID_PARAM;
  619. goto reload_fini_nofree;
  620. }
  621. /* Signal start of the reload process */
  622. icmap_set_uint8("config.reload_in_progress", 1);
  623. /* Detect deleted entries and remove them from the main icmap hashtable */
  624. remove_deleted_entries(temp_map, "logging.");
  625. remove_deleted_entries(temp_map, "totem.");
  626. remove_deleted_entries(temp_map, "nodelist.");
  627. remove_deleted_entries(temp_map, "quorum.");
  628. remove_deleted_entries(temp_map, "uidgid.config.");
  629. remove_deleted_entries(temp_map, "nozzle.");
  630. /* Remove entries that cannot be changed */
  631. remove_ro_entries(temp_map);
  632. /* Take a copy of the current setup so we can check what has changed */
  633. memset(&new_config, 0, sizeof(new_config));
  634. new_config.orig_interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
  635. assert(new_config.orig_interfaces != NULL);
  636. totempg_get_config(&new_config);
  637. new_config.crypto_changed = 0;
  638. new_config.interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
  639. assert(new_config.interfaces != NULL);
  640. memset(new_config.interfaces, 0, sizeof (struct totem_interface) * INTERFACE_MAX);
  641. /* For UDP[U] the configuration on link0 is static (apart from the nodelist) and only read at
  642. startup. So preserve it here */
  643. if ( (new_config.transport_number == TOTEM_TRANSPORT_UDP) ||
  644. (new_config.transport_number == TOTEM_TRANSPORT_UDPU)) {
  645. memcpy(&new_config.interfaces[0], &new_config.orig_interfaces[0],
  646. sizeof(struct totem_interface));
  647. }
  648. /* Calculate new node and interface definitions */
  649. if (totemconfig_configure_new_params(&new_config, temp_map, &error_string) == -1) {
  650. log_printf (LOGSYS_LEVEL_ERROR, "Cannot configure new interface definitions: %s\n", error_string);
  651. res = CS_ERR_INVALID_PARAM;
  652. goto reload_fini;
  653. }
  654. /* Read from temp_map into new_config */
  655. totem_volatile_config_read(&new_config, temp_map, NULL);
  656. /* Get updated crypto parameters. Will set a flag in new_config if things have changed */
  657. if (totem_reread_crypto_config(&new_config, temp_map, &error_string) == -1) {
  658. log_printf (LOGSYS_LEVEL_ERROR, "Crypto configuration is not valid: %s\n", error_string);
  659. res = CS_ERR_INVALID_PARAM;
  660. goto reload_fini;
  661. }
  662. /* Validate dynamic parameters */
  663. if (totem_volatile_config_validate(&new_config, temp_map, &error_string) == -1) {
  664. log_printf (LOGSYS_LEVEL_ERROR, "Configuration is not valid: %s\n", error_string);
  665. res = CS_ERR_INVALID_PARAM;
  666. goto reload_fini;
  667. }
  668. /* Save this here so we can get at it for the later phases of crypto change */
  669. if (new_config.crypto_changed) {
  670. #ifndef HAVE_KNET_CRYPTO_RECONF
  671. new_config.crypto_changed = 0;
  672. log_printf (LOGSYS_LEVEL_ERROR, "Crypto reconfiguration is not supported by the linked version of knet\n");
  673. res = CS_ERR_INVALID_PARAM;
  674. goto reload_fini;
  675. #endif
  676. }
  677. /*
  678. * Copy new keys into live config.
  679. */
  680. if ( (res = icmap_copy_map(icmap_get_global_map(), temp_map)) != CS_OK) {
  681. log_printf (LOGSYS_LEVEL_ERROR, "Error making new config live. cmap database may be inconsistent\n");
  682. /* Return res from icmap */
  683. goto reload_fini;
  684. }
  685. /* Copy into live system */
  686. totempg_put_config(&new_config);
  687. totemconfig_commit_new_params(&new_config, temp_map);
  688. free(new_config.interfaces);
  689. reload_fini:
  690. /* All done - let clients know */
  691. icmap_set_int32("config.reload_status", res);
  692. icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
  693. icmap_set_uint8("config.reload_in_progress", 0);
  694. /* Finished with the temporary storage */
  695. free(new_config.orig_interfaces);
  696. reload_fini_nofree:
  697. icmap_fini_r(temp_map);
  698. reload_fini_nomap:
  699. /* If crypto was changed, now it's loaded on all nodes we can enable it.
  700. * Each node sends its own PHASE message so we're not relying on the leader
  701. * node to survive the transition
  702. */
  703. if (new_config.crypto_changed) {
  704. struct req_exec_cfg_crypto_reconfig req_exec_cfg_crypto_reconfig;
  705. struct iovec iovec;
  706. req_exec_cfg_crypto_reconfig.header.size =
  707. sizeof (struct req_exec_cfg_crypto_reconfig);
  708. req_exec_cfg_crypto_reconfig.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  709. MESSAGE_REQ_EXEC_CFG_CRYPTO_RECONFIG);
  710. req_exec_cfg_crypto_reconfig.phase = CRYPTO_RECONFIG_PHASE_ACTIVATE;
  711. iovec.iov_base = (char *)&req_exec_cfg_crypto_reconfig;
  712. iovec.iov_len = sizeof (struct req_exec_cfg_crypto_reconfig);
  713. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  714. }
  715. /* All done, return result to the caller if it was on this system */
  716. if (nodeid == api->totem_nodeid_get()) {
  717. res_lib_cfg_reload_config.header.size = sizeof(res_lib_cfg_reload_config);
  718. res_lib_cfg_reload_config.header.id = MESSAGE_RES_CFG_RELOAD_CONFIG;
  719. res_lib_cfg_reload_config.header.error = res;
  720. api->ipc_response_send(req_exec_cfg_reload_config->source.conn,
  721. &res_lib_cfg_reload_config,
  722. sizeof(res_lib_cfg_reload_config));
  723. api->ipc_refcnt_dec(req_exec_cfg_reload_config->source.conn);;
  724. }
  725. LEAVE();
  726. }
  727. /* Handle the phases of crypto reload
  728. * The first time we are called is after the new crypto config has been loaded
  729. * but not activated.
  730. *
  731. * 1 - activate the new crypto configuration
  732. * 2 - clear out the old configuration
  733. */
  734. static void message_handler_req_exec_cfg_reconfig_crypto (
  735. const void *message,
  736. unsigned int nodeid)
  737. {
  738. const struct req_exec_cfg_crypto_reconfig *req_exec_cfg_crypto_reconfig = message;
  739. /* Got our own reconfig message */
  740. if (nodeid == api->totem_nodeid_get()) {
  741. log_printf (LOGSYS_LEVEL_DEBUG, "Crypto reconfiguration phase %d", req_exec_cfg_crypto_reconfig->phase);
  742. /* Do the deed */
  743. totempg_crypto_reconfigure_phase(req_exec_cfg_crypto_reconfig->phase);
  744. /* Move to the next phase if not finished */
  745. if (req_exec_cfg_crypto_reconfig->phase < CRYPTO_RECONFIG_PHASE_CLEANUP) {
  746. struct req_exec_cfg_crypto_reconfig req_exec_cfg_crypto_reconfig2;
  747. struct iovec iovec;
  748. req_exec_cfg_crypto_reconfig2.header.size =
  749. sizeof (struct req_exec_cfg_crypto_reconfig);
  750. req_exec_cfg_crypto_reconfig2.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  751. MESSAGE_REQ_EXEC_CFG_CRYPTO_RECONFIG);
  752. req_exec_cfg_crypto_reconfig2.phase = CRYPTO_RECONFIG_PHASE_CLEANUP;
  753. iovec.iov_base = (char *)&req_exec_cfg_crypto_reconfig2;
  754. iovec.iov_len = sizeof (struct req_exec_cfg_crypto_reconfig);
  755. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  756. }
  757. }
  758. }
  759. /*
  760. * Library Interface Implementation
  761. */
  762. static void message_handler_req_lib_cfg_ringstatusget (
  763. void *conn,
  764. const void *msg)
  765. {
  766. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  767. struct totem_ip_address interfaces[INTERFACE_MAX];
  768. unsigned int iface_count;
  769. char **status;
  770. const char *totem_ip_string;
  771. char ifname[CFG_INTERFACE_NAME_MAX_LEN];
  772. unsigned int iface_ids[INTERFACE_MAX];
  773. unsigned int i;
  774. cs_error_t res = CS_OK;
  775. ENTER();
  776. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  777. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  778. api->totem_ifaces_get (
  779. api->totem_nodeid_get(),
  780. iface_ids,
  781. interfaces,
  782. INTERFACE_MAX,
  783. &status,
  784. &iface_count);
  785. assert(iface_count <= CFG_MAX_INTERFACES);
  786. res_lib_cfg_ringstatusget.interface_count = iface_count;
  787. for (i = 0; i < iface_count; i++) {
  788. totem_ip_string
  789. = (const char *)api->totem_ip_print (&interfaces[i]);
  790. if (!totem_ip_string) {
  791. totem_ip_string="";
  792. }
  793. /* Allow for i/f number at the start */
  794. if (strlen(totem_ip_string) >= CFG_INTERFACE_NAME_MAX_LEN-3) {
  795. log_printf(LOGSYS_LEVEL_ERROR, "String representation of interface %u is too long", i);
  796. res = CS_ERR_NAME_TOO_LONG;
  797. goto send_response;
  798. }
  799. snprintf(ifname, sizeof(ifname), "%d %s", iface_ids[i], totem_ip_string);
  800. if (strlen(status[i]) >= CFG_INTERFACE_STATUS_MAX_LEN) {
  801. log_printf(LOGSYS_LEVEL_ERROR, "Status string for interface %u is too long", i);
  802. res = CS_ERR_NAME_TOO_LONG;
  803. goto send_response;
  804. }
  805. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  806. status[i]);
  807. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  808. ifname);
  809. }
  810. send_response:
  811. res_lib_cfg_ringstatusget.header.error = res;
  812. api->ipc_response_send (
  813. conn,
  814. &res_lib_cfg_ringstatusget,
  815. sizeof (struct res_lib_cfg_ringstatusget));
  816. LEAVE();
  817. }
  818. static void message_handler_req_lib_cfg_nodestatusget (
  819. void *conn,
  820. const void *msg)
  821. {
  822. struct res_lib_cfg_nodestatusget_version res_lib_cfg_nodestatusget_version;
  823. struct res_lib_cfg_nodestatusget_v1 res_lib_cfg_nodestatusget_v1;
  824. void *res_lib_cfg_nodestatusget_ptr = NULL;
  825. size_t res_lib_cfg_nodestatusget_size;
  826. struct req_lib_cfg_nodestatusget *req_lib_cfg_nodestatusget = (struct req_lib_cfg_nodestatusget *)msg;
  827. struct totem_node_status node_status;
  828. int i;
  829. ENTER();
  830. memset(&node_status, 0, sizeof(node_status));
  831. if (totempg_nodestatus_get(req_lib_cfg_nodestatusget->nodeid, &node_status) != 0) {
  832. res_lib_cfg_nodestatusget_ptr = &res_lib_cfg_nodestatusget_version;
  833. res_lib_cfg_nodestatusget_size = sizeof(res_lib_cfg_nodestatusget_version);
  834. res_lib_cfg_nodestatusget_version.header.error = CS_ERR_FAILED_OPERATION;
  835. res_lib_cfg_nodestatusget_version.header.id = MESSAGE_RES_CFG_NODESTATUSGET;
  836. res_lib_cfg_nodestatusget_version.header.size = res_lib_cfg_nodestatusget_size;
  837. goto ipc_response_send;
  838. }
  839. /* Currently only one structure version supported */
  840. switch (req_lib_cfg_nodestatusget->version) {
  841. case CFG_NODE_STATUS_V1:
  842. res_lib_cfg_nodestatusget_ptr = &res_lib_cfg_nodestatusget_v1;
  843. res_lib_cfg_nodestatusget_size = sizeof(res_lib_cfg_nodestatusget_v1);
  844. res_lib_cfg_nodestatusget_v1.header.error = CS_OK;
  845. res_lib_cfg_nodestatusget_v1.header.id = MESSAGE_RES_CFG_NODESTATUSGET;
  846. res_lib_cfg_nodestatusget_v1.header.size = res_lib_cfg_nodestatusget_size;
  847. res_lib_cfg_nodestatusget_v1.node_status.version = CFG_NODE_STATUS_V1;
  848. res_lib_cfg_nodestatusget_v1.node_status.nodeid = req_lib_cfg_nodestatusget->nodeid;
  849. res_lib_cfg_nodestatusget_v1.node_status.reachable = node_status.reachable;
  850. res_lib_cfg_nodestatusget_v1.node_status.remote = node_status.remote;
  851. res_lib_cfg_nodestatusget_v1.node_status.external = node_status.external;
  852. res_lib_cfg_nodestatusget_v1.node_status.onwire_min = node_status.onwire_min;
  853. res_lib_cfg_nodestatusget_v1.node_status.onwire_max = node_status.onwire_max;
  854. res_lib_cfg_nodestatusget_v1.node_status.onwire_ver = node_status.onwire_ver;
  855. for (i=0; i < KNET_MAX_LINK; i++) {
  856. res_lib_cfg_nodestatusget_v1.node_status.link_status[i].enabled = node_status.link_status[i].enabled;
  857. res_lib_cfg_nodestatusget_v1.node_status.link_status[i].connected = node_status.link_status[i].connected;
  858. res_lib_cfg_nodestatusget_v1.node_status.link_status[i].dynconnected = node_status.link_status[i].dynconnected;
  859. res_lib_cfg_nodestatusget_v1.node_status.link_status[i].mtu = node_status.link_status[i].mtu;
  860. memcpy(res_lib_cfg_nodestatusget_v1.node_status.link_status[i].src_ipaddr,
  861. node_status.link_status[i].src_ipaddr, CFG_MAX_HOST_LEN);
  862. memcpy(res_lib_cfg_nodestatusget_v1.node_status.link_status[i].dst_ipaddr,
  863. node_status.link_status[i].dst_ipaddr, CFG_MAX_HOST_LEN);
  864. }
  865. break;
  866. default:
  867. /*
  868. * Unsupported version requested
  869. */
  870. res_lib_cfg_nodestatusget_ptr = &res_lib_cfg_nodestatusget_version;
  871. res_lib_cfg_nodestatusget_size = sizeof(res_lib_cfg_nodestatusget_version);
  872. res_lib_cfg_nodestatusget_version.header.error = CS_ERR_NOT_SUPPORTED;
  873. res_lib_cfg_nodestatusget_version.header.id = MESSAGE_RES_CFG_NODESTATUSGET;
  874. res_lib_cfg_nodestatusget_version.header.size = res_lib_cfg_nodestatusget_size;
  875. break;
  876. }
  877. ipc_response_send:
  878. api->ipc_response_send (
  879. conn,
  880. res_lib_cfg_nodestatusget_ptr,
  881. res_lib_cfg_nodestatusget_size);
  882. LEAVE();
  883. }
  884. static void message_handler_req_lib_cfg_ringreenable (
  885. void *conn,
  886. const void *msg)
  887. {
  888. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  889. ENTER();
  890. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  891. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  892. res_lib_cfg_ringreenable.header.error = CS_ERR_NOT_SUPPORTED;
  893. api->ipc_response_send (
  894. conn, &res_lib_cfg_ringreenable,
  895. sizeof (struct res_lib_cfg_ringreenable));
  896. LEAVE();
  897. }
  898. static void message_handler_req_lib_cfg_killnode (
  899. void *conn,
  900. const void *msg)
  901. {
  902. const struct req_lib_cfg_killnode *req_lib_cfg_killnode = msg;
  903. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  904. struct req_exec_cfg_killnode req_exec_cfg_killnode;
  905. struct iovec iovec;
  906. char key_name[ICMAP_KEYNAME_MAXLEN];
  907. char tmp_key[ICMAP_KEYNAME_MAXLEN + 1];
  908. icmap_map_t map;
  909. icmap_iter_t iter;
  910. const char *iter_key;
  911. uint32_t nodeid;
  912. char *status_str = NULL;
  913. int match_nodeid_flag = 0;
  914. cs_error_t error = CS_OK;
  915. ENTER();
  916. map = icmap_get_global_map();
  917. iter = icmap_iter_init_r(map, "runtime.members.");
  918. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  919. if (sscanf(iter_key, "runtime.members.%u.%s", &nodeid, key_name) != 2) {
  920. continue;
  921. }
  922. if (strcmp(key_name, "status") != 0) {
  923. continue;
  924. }
  925. if (nodeid != req_lib_cfg_killnode->nodeid) {
  926. continue;
  927. }
  928. match_nodeid_flag = 1;
  929. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "runtime.members.%u.status", nodeid);
  930. if (icmap_get_string_r(map, tmp_key, &status_str) != CS_OK) {
  931. error = CS_ERR_LIBRARY;
  932. goto send_response;
  933. }
  934. if (strcmp(status_str, "joined") != 0) {
  935. error = CS_ERR_NOT_EXIST;
  936. goto send_response;
  937. }
  938. break;
  939. }
  940. if (!match_nodeid_flag) {
  941. error = CS_ERR_NOT_EXIST;
  942. goto send_response;
  943. }
  944. req_exec_cfg_killnode.header.size =
  945. sizeof (struct req_exec_cfg_killnode);
  946. req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  947. MESSAGE_REQ_EXEC_CFG_KILLNODE);
  948. req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
  949. marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
  950. iovec.iov_base = (char *)&req_exec_cfg_killnode;
  951. iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
  952. (void)api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  953. send_response:
  954. res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
  955. res_lib_cfg_killnode.header.id = MESSAGE_RES_CFG_KILLNODE;
  956. res_lib_cfg_killnode.header.error = error;
  957. api->ipc_response_send(conn, &res_lib_cfg_killnode,
  958. sizeof(res_lib_cfg_killnode));
  959. free(status_str);
  960. icmap_iter_finalize(iter);
  961. LEAVE();
  962. }
  963. static void message_handler_req_lib_cfg_tryshutdown (
  964. void *conn,
  965. const void *msg)
  966. {
  967. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  968. const struct req_lib_cfg_tryshutdown *req_lib_cfg_tryshutdown = msg;
  969. struct qb_list_head *iter;
  970. ENTER();
  971. if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
  972. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  973. /*
  974. * Tell other nodes
  975. */
  976. send_shutdown();
  977. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  978. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  979. res_lib_cfg_tryshutdown.header.error = CS_OK;
  980. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  981. sizeof(res_lib_cfg_tryshutdown));
  982. LEAVE();
  983. return;
  984. }
  985. /*
  986. * Shutdown in progress, return an error
  987. */
  988. if (shutdown_con) {
  989. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  990. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  991. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  992. res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
  993. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  994. sizeof(res_lib_cfg_tryshutdown));
  995. LEAVE();
  996. return;
  997. }
  998. ci->conn = conn;
  999. shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
  1000. shutdown_flags = req_lib_cfg_tryshutdown->flags;
  1001. shutdown_yes = 0;
  1002. shutdown_no = 0;
  1003. /*
  1004. * Count the number of listeners
  1005. */
  1006. shutdown_expected = 0;
  1007. qb_list_for_each(iter, &trackers_list) {
  1008. struct cfg_info *testci = qb_list_entry(iter, struct cfg_info, list);
  1009. /*
  1010. * It is assumed that we will allow shutdown
  1011. */
  1012. if (testci != ci) {
  1013. testci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  1014. shutdown_expected++;
  1015. }
  1016. }
  1017. /*
  1018. * If no-one is listening for events then we can just go down now
  1019. */
  1020. if (shutdown_expected == 0) {
  1021. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  1022. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  1023. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  1024. res_lib_cfg_tryshutdown.header.error = CS_OK;
  1025. /*
  1026. * Tell originator that shutdown was confirmed
  1027. */
  1028. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  1029. sizeof(res_lib_cfg_tryshutdown));
  1030. send_shutdown();
  1031. LEAVE();
  1032. return;
  1033. }
  1034. else {
  1035. unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
  1036. /*
  1037. * Look for a shutdown timeout in configuration map
  1038. */
  1039. icmap_get_uint32("cfg.shutdown_timeout", &shutdown_timeout);
  1040. /*
  1041. * Start the timer. If we don't get a full set of replies before this goes
  1042. * off we'll cancel the shutdown
  1043. */
  1044. api->timer_add_duration((unsigned long long)shutdown_timeout*1000000000, NULL,
  1045. shutdown_timer_fn, &shutdown_timer);
  1046. /*
  1047. * Tell the users we would like to shut down
  1048. */
  1049. send_test_shutdown(NULL, conn, CS_OK);
  1050. }
  1051. /*
  1052. * We don't sent a reply to the caller here.
  1053. * We send it when we know if we can shut down or not
  1054. */
  1055. LEAVE();
  1056. }
  1057. static void message_handler_req_lib_cfg_replytoshutdown (
  1058. void *conn,
  1059. const void *msg)
  1060. {
  1061. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  1062. const struct req_lib_cfg_replytoshutdown *req_lib_cfg_replytoshutdown = msg;
  1063. struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
  1064. int status = CS_OK;
  1065. ENTER();
  1066. if (!shutdown_con) {
  1067. status = CS_ERR_ACCESS;
  1068. goto exit_fn;
  1069. }
  1070. if (req_lib_cfg_replytoshutdown->response) {
  1071. shutdown_yes++;
  1072. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  1073. }
  1074. else {
  1075. shutdown_no++;
  1076. ci->shutdown_reply = SHUTDOWN_REPLY_NO;
  1077. }
  1078. check_shutdown_status();
  1079. exit_fn:
  1080. res_lib_cfg_replytoshutdown.header.error = status;
  1081. res_lib_cfg_replytoshutdown.header.id = MESSAGE_RES_CFG_REPLYTOSHUTDOWN;
  1082. res_lib_cfg_replytoshutdown.header.size = sizeof(res_lib_cfg_replytoshutdown);
  1083. api->ipc_response_send(conn, &res_lib_cfg_replytoshutdown,
  1084. sizeof(res_lib_cfg_replytoshutdown));
  1085. LEAVE();
  1086. }
  1087. static void message_handler_req_lib_cfg_get_node_addrs (void *conn,
  1088. const void *msg)
  1089. {
  1090. struct totem_ip_address node_ifs[INTERFACE_MAX];
  1091. unsigned int iface_ids[INTERFACE_MAX];
  1092. char buf[PIPE_BUF];
  1093. char **status;
  1094. unsigned int num_interfaces = 0;
  1095. struct sockaddr_storage *ss;
  1096. int ret = CS_OK;
  1097. int i;
  1098. int live_addrs = 0;
  1099. const struct req_lib_cfg_get_node_addrs *req_lib_cfg_get_node_addrs = msg;
  1100. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)buf;
  1101. unsigned int nodeid = req_lib_cfg_get_node_addrs->nodeid;
  1102. char *addr_buf;
  1103. if (nodeid == 0)
  1104. nodeid = api->totem_nodeid_get();
  1105. if (api->totem_ifaces_get(nodeid, iface_ids, node_ifs, INTERFACE_MAX, &status, &num_interfaces)) {
  1106. ret = CS_ERR_EXIST;
  1107. num_interfaces = 0;
  1108. }
  1109. res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
  1110. res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
  1111. res_lib_cfg_get_node_addrs->header.error = ret;
  1112. if (num_interfaces) {
  1113. res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
  1114. for (i = 0, addr_buf = (char *)res_lib_cfg_get_node_addrs->addrs;
  1115. i < num_interfaces; i++) {
  1116. ss = (struct sockaddr_storage *)&node_ifs[i].addr;
  1117. if (ss->ss_family) {
  1118. memcpy(addr_buf, node_ifs[i].addr, TOTEMIP_ADDRLEN);
  1119. live_addrs++;
  1120. addr_buf += TOTEMIP_ADDRLEN;
  1121. }
  1122. }
  1123. res_lib_cfg_get_node_addrs->num_addrs = live_addrs;
  1124. } else {
  1125. res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
  1126. }
  1127. api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
  1128. }
  1129. static void message_handler_req_lib_cfg_local_get (void *conn, const void *msg)
  1130. {
  1131. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  1132. res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
  1133. res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
  1134. res_lib_cfg_local_get.header.error = CS_OK;
  1135. res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
  1136. api->ipc_response_send(conn, &res_lib_cfg_local_get,
  1137. sizeof(res_lib_cfg_local_get));
  1138. }
  1139. static void message_handler_req_lib_cfg_reload_config (void *conn, const void *msg)
  1140. {
  1141. struct req_exec_cfg_reload_config req_exec_cfg_reload_config;
  1142. struct iovec iovec;
  1143. ENTER();
  1144. req_exec_cfg_reload_config.header.size =
  1145. sizeof (struct req_exec_cfg_reload_config);
  1146. req_exec_cfg_reload_config.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  1147. MESSAGE_REQ_EXEC_CFG_RELOAD_CONFIG);
  1148. api->ipc_source_set (&req_exec_cfg_reload_config.source, conn);
  1149. api->ipc_refcnt_inc(conn);
  1150. iovec.iov_base = (char *)&req_exec_cfg_reload_config;
  1151. iovec.iov_len = sizeof (struct req_exec_cfg_reload_config);
  1152. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  1153. LEAVE();
  1154. }
  1155. static void message_handler_req_lib_cfg_reopen_log_files (void *conn, const void *msg)
  1156. {
  1157. struct res_lib_cfg_reopen_log_files res_lib_cfg_reopen_log_files;
  1158. cs_error_t res;
  1159. ENTER();
  1160. log_printf(LOGSYS_LEVEL_DEBUG, "Reopening logging files\n");
  1161. res = logsys_reopen_log_files();
  1162. res_lib_cfg_reopen_log_files.header.size = sizeof(res_lib_cfg_reopen_log_files);
  1163. res_lib_cfg_reopen_log_files.header.id = MESSAGE_RES_CFG_REOPEN_LOG_FILES;
  1164. res_lib_cfg_reopen_log_files.header.error = res;
  1165. api->ipc_response_send(conn,
  1166. &res_lib_cfg_reopen_log_files,
  1167. sizeof(res_lib_cfg_reopen_log_files));
  1168. LEAVE();
  1169. }