cfg.c 37 KB

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