cfg.c 44 KB

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