cfg.c 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477
  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.netmtu");
  538. delete_and_notify_if_changed(temp_map, "totem.interface.bindnetaddr");
  539. delete_and_notify_if_changed(temp_map, "totem.interface.mcastaddr");
  540. delete_and_notify_if_changed(temp_map, "totem.interface.broadcast");
  541. delete_and_notify_if_changed(temp_map, "totem.interface.mcastport");
  542. delete_and_notify_if_changed(temp_map, "totem.interface.ttl");
  543. delete_and_notify_if_changed(temp_map, "totem.transport");
  544. delete_and_notify_if_changed(temp_map, "totem.cluster_name");
  545. delete_and_notify_if_changed(temp_map, "quorum.provider");
  546. delete_and_notify_if_changed(temp_map, "system.move_to_root_cgroup");
  547. delete_and_notify_if_changed(temp_map, "system.allow_knet_handle_fallback");
  548. delete_and_notify_if_changed(temp_map, "system.sched_rr");
  549. delete_and_notify_if_changed(temp_map, "system.priority");
  550. delete_and_notify_if_changed(temp_map, "system.qb_ipc_type");
  551. delete_and_notify_if_changed(temp_map, "system.state_dir");
  552. }
  553. /*
  554. * Remove entries that exist in the global map, but not in the temp_map, this will
  555. * cause delete notifications to be sent to any listeners.
  556. *
  557. * NOTE: This routine depends entirely on the keys returned by the iterators
  558. * being in alpha-sorted order.
  559. */
  560. static void remove_deleted_entries(icmap_map_t temp_map, const char *prefix)
  561. {
  562. icmap_iter_t old_iter;
  563. icmap_iter_t new_iter;
  564. const char *old_key, *new_key;
  565. int ret;
  566. old_iter = icmap_iter_init(prefix);
  567. new_iter = icmap_iter_init_r(temp_map, prefix);
  568. old_key = icmap_iter_next(old_iter, NULL, NULL);
  569. new_key = icmap_iter_next(new_iter, NULL, NULL);
  570. while (old_key || new_key) {
  571. ret = nullcheck_strcmp(old_key, new_key);
  572. if ((ret < 0 && old_key) || !new_key) {
  573. /*
  574. * new_key is greater, a line (or more) has been deleted
  575. * Continue until old is >= new
  576. */
  577. do {
  578. /* Remove it from icmap & send notifications */
  579. icmap_delete(old_key);
  580. old_key = icmap_iter_next(old_iter, NULL, NULL);
  581. ret = nullcheck_strcmp(old_key, new_key);
  582. } while (ret < 0 && old_key);
  583. }
  584. else if ((ret > 0 && new_key) || !old_key) {
  585. /*
  586. * old_key is greater, a line (or more) has been added
  587. * Continue until new is >= old
  588. *
  589. * we don't need to do anything special with this like tell
  590. * icmap. That will happen when we copy the values over
  591. */
  592. do {
  593. new_key = icmap_iter_next(new_iter, NULL, NULL);
  594. ret = nullcheck_strcmp(old_key, new_key);
  595. } while (ret > 0 && new_key);
  596. }
  597. if (ret == 0) {
  598. new_key = icmap_iter_next(new_iter, NULL, NULL);
  599. old_key = icmap_iter_next(old_iter, NULL, NULL);
  600. }
  601. }
  602. icmap_iter_finalize(new_iter);
  603. icmap_iter_finalize(old_iter);
  604. }
  605. /*
  606. * Reload configuration file
  607. */
  608. static void message_handler_req_exec_cfg_reload_config (
  609. const void *message,
  610. unsigned int nodeid)
  611. {
  612. const struct req_exec_cfg_reload_config *req_exec_cfg_reload_config = message;
  613. struct res_lib_cfg_reload_config res_lib_cfg_reload_config;
  614. struct totem_config new_config;
  615. icmap_map_t temp_map;
  616. const char *error_string;
  617. int res = CS_OK;
  618. ENTER();
  619. log_printf(LOGSYS_LEVEL_NOTICE, "Config reload requested by node " CS_PRI_NODE_ID, nodeid);
  620. // Clear this out in case it all goes well
  621. icmap_delete("config.reload_error_message");
  622. icmap_set_uint8("config.totemconfig_reload_in_progress", 1);
  623. /* Make sure there is no rubbish in this that might be checked, even on error */
  624. memset(&new_config, 0, sizeof(new_config));
  625. /*
  626. * Set up a new hashtable as a staging area.
  627. */
  628. if ((res = icmap_init_r(&temp_map)) != CS_OK) {
  629. log_printf(LOGSYS_LEVEL_ERROR, "Unable to create temporary icmap. config file reload cancelled\n");
  630. goto reload_fini_nomap;
  631. }
  632. /*
  633. * Load new config into the temporary map
  634. */
  635. res = coroparse_configparse(temp_map, &error_string);
  636. if (res == -1) {
  637. log_printf (LOGSYS_LEVEL_ERROR, "Unable to reload config file: %s", error_string);
  638. res = CS_ERR_INVALID_PARAM;
  639. goto reload_fini_nofree;
  640. }
  641. /* Signal start of the reload process */
  642. icmap_set_uint8("config.reload_in_progress", 1);
  643. /* Detect deleted entries and remove them from the main icmap hashtable */
  644. remove_deleted_entries(temp_map, "logging.");
  645. remove_deleted_entries(temp_map, "totem.");
  646. remove_deleted_entries(temp_map, "nodelist.");
  647. remove_deleted_entries(temp_map, "quorum.");
  648. remove_deleted_entries(temp_map, "uidgid.config.");
  649. remove_deleted_entries(temp_map, "nozzle.");
  650. /* Remove entries that cannot be changed */
  651. remove_ro_entries(temp_map);
  652. /* Take a copy of the current setup so we can check what has changed */
  653. memset(&new_config, 0, sizeof(new_config));
  654. new_config.orig_interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
  655. assert(new_config.orig_interfaces != NULL);
  656. totempg_get_config(&new_config);
  657. new_config.crypto_changed = 0;
  658. new_config.interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
  659. assert(new_config.interfaces != NULL);
  660. memset(new_config.interfaces, 0, sizeof (struct totem_interface) * INTERFACE_MAX);
  661. /* For UDP[U] the configuration on link0 is static (apart from the nodelist) and only read at
  662. startup. So preserve it here */
  663. if ( (new_config.transport_number == TOTEM_TRANSPORT_UDP) ||
  664. (new_config.transport_number == TOTEM_TRANSPORT_UDPU)) {
  665. memcpy(&new_config.interfaces[0], &new_config.orig_interfaces[0],
  666. sizeof(struct totem_interface));
  667. }
  668. /* Calculate new node and interface definitions */
  669. if (totemconfig_configure_new_params(&new_config, temp_map, &error_string) == -1) {
  670. log_printf (LOGSYS_LEVEL_ERROR, "Cannot configure new interface definitions: %s\n", error_string);
  671. res = CS_ERR_INVALID_PARAM;
  672. goto reload_fini;
  673. }
  674. /* Read from temp_map into new_config */
  675. totem_volatile_config_read(&new_config, temp_map, NULL);
  676. /* Get updated crypto parameters. Will set a flag in new_config if things have changed */
  677. if (totem_reread_crypto_config(&new_config, temp_map, &error_string) == -1) {
  678. log_printf (LOGSYS_LEVEL_ERROR, "Crypto configuration is not valid: %s\n", error_string);
  679. res = CS_ERR_INVALID_PARAM;
  680. goto reload_fini;
  681. }
  682. /* Validate dynamic parameters */
  683. if (totem_volatile_config_validate(&new_config, temp_map, &error_string) == -1) {
  684. log_printf (LOGSYS_LEVEL_ERROR, "Configuration is not valid: %s\n", error_string);
  685. res = CS_ERR_INVALID_PARAM;
  686. goto reload_fini;
  687. }
  688. /* Save this here so we can get at it for the later phases of crypto change */
  689. if (new_config.crypto_changed) {
  690. #ifndef HAVE_KNET_CRYPTO_RECONF
  691. new_config.crypto_changed = 0;
  692. log_printf (LOGSYS_LEVEL_ERROR, "Crypto reconfiguration is not supported by the linked version of knet\n");
  693. res = CS_ERR_INVALID_PARAM;
  694. goto reload_fini;
  695. #endif
  696. }
  697. /*
  698. * Copy new keys into live config.
  699. */
  700. if ( (res = icmap_copy_map(icmap_get_global_map(), temp_map)) != CS_OK) {
  701. log_printf (LOGSYS_LEVEL_ERROR, "Error making new config live. cmap database may be inconsistent\n");
  702. /* Return res from icmap */
  703. goto reload_fini;
  704. }
  705. /* Copy into live system */
  706. totempg_put_config(&new_config);
  707. totemconfig_commit_new_params(&new_config, temp_map);
  708. reload_fini:
  709. /* All done - let clients know */
  710. icmap_set_int32("config.reload_status", res);
  711. icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
  712. icmap_set_uint8("config.reload_in_progress", 0);
  713. /* Finished with the temporary storage */
  714. free(new_config.interfaces);
  715. free(new_config.orig_interfaces);
  716. reload_fini_nofree:
  717. icmap_fini_r(temp_map);
  718. reload_fini_nomap:
  719. /* If crypto was changed, now it's loaded on all nodes we can enable it.
  720. * Each node sends its own PHASE message so we're not relying on the leader
  721. * node to survive the transition
  722. */
  723. if (new_config.crypto_changed) {
  724. struct req_exec_cfg_crypto_reconfig req_exec_cfg_crypto_reconfig;
  725. struct iovec iovec;
  726. req_exec_cfg_crypto_reconfig.header.size =
  727. sizeof (struct req_exec_cfg_crypto_reconfig);
  728. req_exec_cfg_crypto_reconfig.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  729. MESSAGE_REQ_EXEC_CFG_CRYPTO_RECONFIG);
  730. req_exec_cfg_crypto_reconfig.phase = CRYPTO_RECONFIG_PHASE_ACTIVATE;
  731. iovec.iov_base = (char *)&req_exec_cfg_crypto_reconfig;
  732. iovec.iov_len = sizeof (struct req_exec_cfg_crypto_reconfig);
  733. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  734. }
  735. /* All done, return result to the caller if it was on this system */
  736. if (nodeid == api->totem_nodeid_get()) {
  737. res_lib_cfg_reload_config.header.size = sizeof(res_lib_cfg_reload_config);
  738. res_lib_cfg_reload_config.header.id = MESSAGE_RES_CFG_RELOAD_CONFIG;
  739. res_lib_cfg_reload_config.header.error = res;
  740. api->ipc_response_send(req_exec_cfg_reload_config->source.conn,
  741. &res_lib_cfg_reload_config,
  742. sizeof(res_lib_cfg_reload_config));
  743. api->ipc_refcnt_dec(req_exec_cfg_reload_config->source.conn);;
  744. }
  745. LEAVE();
  746. }
  747. /* Handle the phases of crypto reload
  748. * The first time we are called is after the new crypto config has been loaded
  749. * but not activated.
  750. *
  751. * 1 - activate the new crypto configuration
  752. * 2 - clear out the old configuration
  753. */
  754. static void message_handler_req_exec_cfg_reconfig_crypto (
  755. const void *message,
  756. unsigned int nodeid)
  757. {
  758. const struct req_exec_cfg_crypto_reconfig *req_exec_cfg_crypto_reconfig = message;
  759. /* Got our own reconfig message */
  760. if (nodeid == api->totem_nodeid_get()) {
  761. log_printf (LOGSYS_LEVEL_DEBUG, "Crypto reconfiguration phase %d", req_exec_cfg_crypto_reconfig->phase);
  762. /* Do the deed */
  763. totempg_crypto_reconfigure_phase(req_exec_cfg_crypto_reconfig->phase);
  764. /* Move to the next phase if not finished */
  765. if (req_exec_cfg_crypto_reconfig->phase < CRYPTO_RECONFIG_PHASE_CLEANUP) {
  766. struct req_exec_cfg_crypto_reconfig req_exec_cfg_crypto_reconfig2;
  767. struct iovec iovec;
  768. req_exec_cfg_crypto_reconfig2.header.size =
  769. sizeof (struct req_exec_cfg_crypto_reconfig);
  770. req_exec_cfg_crypto_reconfig2.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  771. MESSAGE_REQ_EXEC_CFG_CRYPTO_RECONFIG);
  772. req_exec_cfg_crypto_reconfig2.phase = CRYPTO_RECONFIG_PHASE_CLEANUP;
  773. iovec.iov_base = (char *)&req_exec_cfg_crypto_reconfig2;
  774. iovec.iov_len = sizeof (struct req_exec_cfg_crypto_reconfig);
  775. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  776. }
  777. }
  778. }
  779. /*
  780. * Library Interface Implementation
  781. */
  782. static void message_handler_req_lib_cfg_ringstatusget (
  783. void *conn,
  784. const void *msg)
  785. {
  786. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  787. struct totem_ip_address interfaces[INTERFACE_MAX];
  788. unsigned int iface_count;
  789. char **status;
  790. const char *totem_ip_string;
  791. char ifname[CFG_INTERFACE_NAME_MAX_LEN];
  792. unsigned int iface_ids[INTERFACE_MAX];
  793. unsigned int i;
  794. cs_error_t res = CS_OK;
  795. ENTER();
  796. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  797. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  798. api->totem_ifaces_get (
  799. api->totem_nodeid_get(),
  800. iface_ids,
  801. interfaces,
  802. INTERFACE_MAX,
  803. &status,
  804. &iface_count);
  805. assert(iface_count <= CFG_MAX_INTERFACES);
  806. res_lib_cfg_ringstatusget.interface_count = iface_count;
  807. for (i = 0; i < iface_count; i++) {
  808. totem_ip_string
  809. = (const char *)api->totem_ip_print (&interfaces[i]);
  810. if (!totem_ip_string) {
  811. totem_ip_string="";
  812. }
  813. /* Allow for i/f number at the start */
  814. if (strlen(totem_ip_string) >= CFG_INTERFACE_NAME_MAX_LEN-3) {
  815. log_printf(LOGSYS_LEVEL_ERROR, "String representation of interface %u is too long", i);
  816. res = CS_ERR_NAME_TOO_LONG;
  817. goto send_response;
  818. }
  819. snprintf(ifname, sizeof(ifname), "%d %s", iface_ids[i], totem_ip_string);
  820. if (strlen(status[i]) >= CFG_INTERFACE_STATUS_MAX_LEN) {
  821. log_printf(LOGSYS_LEVEL_ERROR, "Status string for interface %u is too long", i);
  822. res = CS_ERR_NAME_TOO_LONG;
  823. goto send_response;
  824. }
  825. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  826. status[i]);
  827. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  828. ifname);
  829. }
  830. send_response:
  831. res_lib_cfg_ringstatusget.header.error = res;
  832. api->ipc_response_send (
  833. conn,
  834. &res_lib_cfg_ringstatusget,
  835. sizeof (struct res_lib_cfg_ringstatusget));
  836. LEAVE();
  837. }
  838. static void message_handler_req_lib_cfg_nodestatusget (
  839. void *conn,
  840. const void *msg)
  841. {
  842. struct res_lib_cfg_nodestatusget_version res_lib_cfg_nodestatusget_version;
  843. struct res_lib_cfg_nodestatusget_v1 res_lib_cfg_nodestatusget_v1;
  844. void *res_lib_cfg_nodestatusget_ptr = NULL;
  845. size_t res_lib_cfg_nodestatusget_size;
  846. struct req_lib_cfg_nodestatusget *req_lib_cfg_nodestatusget = (struct req_lib_cfg_nodestatusget *)msg;
  847. struct totem_node_status node_status;
  848. int i;
  849. ENTER();
  850. memset(&node_status, 0, sizeof(node_status));
  851. if (totempg_nodestatus_get(req_lib_cfg_nodestatusget->nodeid, &node_status) != 0) {
  852. res_lib_cfg_nodestatusget_ptr = &res_lib_cfg_nodestatusget_version;
  853. res_lib_cfg_nodestatusget_size = sizeof(res_lib_cfg_nodestatusget_version);
  854. res_lib_cfg_nodestatusget_version.header.error = CS_ERR_FAILED_OPERATION;
  855. res_lib_cfg_nodestatusget_version.header.id = MESSAGE_RES_CFG_NODESTATUSGET;
  856. res_lib_cfg_nodestatusget_version.header.size = res_lib_cfg_nodestatusget_size;
  857. goto ipc_response_send;
  858. }
  859. /* Currently only one structure version supported */
  860. switch (req_lib_cfg_nodestatusget->version) {
  861. case CFG_NODE_STATUS_V1:
  862. res_lib_cfg_nodestatusget_ptr = &res_lib_cfg_nodestatusget_v1;
  863. res_lib_cfg_nodestatusget_size = sizeof(res_lib_cfg_nodestatusget_v1);
  864. res_lib_cfg_nodestatusget_v1.header.error = CS_OK;
  865. res_lib_cfg_nodestatusget_v1.header.id = MESSAGE_RES_CFG_NODESTATUSGET;
  866. res_lib_cfg_nodestatusget_v1.header.size = res_lib_cfg_nodestatusget_size;
  867. res_lib_cfg_nodestatusget_v1.node_status.version = CFG_NODE_STATUS_V1;
  868. res_lib_cfg_nodestatusget_v1.node_status.nodeid = req_lib_cfg_nodestatusget->nodeid;
  869. res_lib_cfg_nodestatusget_v1.node_status.reachable = node_status.reachable;
  870. res_lib_cfg_nodestatusget_v1.node_status.remote = node_status.remote;
  871. res_lib_cfg_nodestatusget_v1.node_status.external = node_status.external;
  872. res_lib_cfg_nodestatusget_v1.node_status.onwire_min = node_status.onwire_min;
  873. res_lib_cfg_nodestatusget_v1.node_status.onwire_max = node_status.onwire_max;
  874. res_lib_cfg_nodestatusget_v1.node_status.onwire_ver = node_status.onwire_ver;
  875. for (i=0; i < KNET_MAX_LINK; i++) {
  876. res_lib_cfg_nodestatusget_v1.node_status.link_status[i].enabled = node_status.link_status[i].enabled;
  877. res_lib_cfg_nodestatusget_v1.node_status.link_status[i].connected = node_status.link_status[i].connected;
  878. res_lib_cfg_nodestatusget_v1.node_status.link_status[i].dynconnected = node_status.link_status[i].dynconnected;
  879. res_lib_cfg_nodestatusget_v1.node_status.link_status[i].mtu = node_status.link_status[i].mtu;
  880. memcpy(res_lib_cfg_nodestatusget_v1.node_status.link_status[i].src_ipaddr,
  881. node_status.link_status[i].src_ipaddr, CFG_MAX_HOST_LEN);
  882. memcpy(res_lib_cfg_nodestatusget_v1.node_status.link_status[i].dst_ipaddr,
  883. node_status.link_status[i].dst_ipaddr, CFG_MAX_HOST_LEN);
  884. }
  885. break;
  886. default:
  887. /*
  888. * Unsupported version requested
  889. */
  890. res_lib_cfg_nodestatusget_ptr = &res_lib_cfg_nodestatusget_version;
  891. res_lib_cfg_nodestatusget_size = sizeof(res_lib_cfg_nodestatusget_version);
  892. res_lib_cfg_nodestatusget_version.header.error = CS_ERR_NOT_SUPPORTED;
  893. res_lib_cfg_nodestatusget_version.header.id = MESSAGE_RES_CFG_NODESTATUSGET;
  894. res_lib_cfg_nodestatusget_version.header.size = res_lib_cfg_nodestatusget_size;
  895. break;
  896. }
  897. ipc_response_send:
  898. api->ipc_response_send (
  899. conn,
  900. res_lib_cfg_nodestatusget_ptr,
  901. res_lib_cfg_nodestatusget_size);
  902. LEAVE();
  903. }
  904. static void message_handler_req_lib_cfg_trackstart (
  905. void *conn,
  906. const void *msg)
  907. {
  908. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  909. struct res_lib_cfg_trackstart res_lib_cfg_trackstart;
  910. ENTER();
  911. /*
  912. * We only do shutdown tracking at the moment
  913. */
  914. if (qb_list_empty(&ci->list)) {
  915. qb_list_add(&ci->list, &trackers_list);
  916. ci->tracker_conn = conn;
  917. if (shutdown_con) {
  918. /*
  919. * Shutdown already in progress, ask the newcomer's opinion
  920. */
  921. ci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  922. shutdown_expected++;
  923. send_test_shutdown(conn, NULL, CS_OK);
  924. }
  925. }
  926. res_lib_cfg_trackstart.header.size = sizeof(struct res_lib_cfg_trackstart);
  927. res_lib_cfg_trackstart.header.id = MESSAGE_RES_CFG_STATETRACKSTART;
  928. res_lib_cfg_trackstart.header.error = CS_OK;
  929. api->ipc_response_send(conn, &res_lib_cfg_trackstart,
  930. sizeof(res_lib_cfg_trackstart));
  931. LEAVE();
  932. }
  933. static void message_handler_req_lib_cfg_trackstop (
  934. void *conn,
  935. const void *msg)
  936. {
  937. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  938. struct res_lib_cfg_trackstop res_lib_cfg_trackstop;
  939. ENTER();
  940. remove_ci_from_shutdown(ci);
  941. res_lib_cfg_trackstop.header.size = sizeof(struct res_lib_cfg_trackstop);
  942. res_lib_cfg_trackstop.header.id = MESSAGE_RES_CFG_STATETRACKSTOP;
  943. res_lib_cfg_trackstop.header.error = CS_OK;
  944. api->ipc_response_send(conn, &res_lib_cfg_trackstop,
  945. sizeof(res_lib_cfg_trackstop));
  946. LEAVE();
  947. }
  948. static void message_handler_req_lib_cfg_ringreenable (
  949. void *conn,
  950. const void *msg)
  951. {
  952. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  953. ENTER();
  954. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  955. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  956. res_lib_cfg_ringreenable.header.error = CS_ERR_NOT_SUPPORTED;
  957. api->ipc_response_send (
  958. conn, &res_lib_cfg_ringreenable,
  959. sizeof (struct res_lib_cfg_ringreenable));
  960. LEAVE();
  961. }
  962. static void message_handler_req_lib_cfg_killnode (
  963. void *conn,
  964. const void *msg)
  965. {
  966. const struct req_lib_cfg_killnode *req_lib_cfg_killnode = msg;
  967. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  968. struct req_exec_cfg_killnode req_exec_cfg_killnode;
  969. struct iovec iovec;
  970. char key_name[ICMAP_KEYNAME_MAXLEN];
  971. char tmp_key[ICMAP_KEYNAME_MAXLEN + 1];
  972. icmap_map_t map;
  973. icmap_iter_t iter;
  974. const char *iter_key;
  975. uint32_t nodeid;
  976. char *status_str = NULL;
  977. int match_nodeid_flag = 0;
  978. cs_error_t error = CS_OK;
  979. ENTER();
  980. map = icmap_get_global_map();
  981. iter = icmap_iter_init_r(map, "runtime.members.");
  982. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  983. if (sscanf(iter_key, "runtime.members.%u.%s", &nodeid, key_name) != 2) {
  984. continue;
  985. }
  986. if (strcmp(key_name, "status") != 0) {
  987. continue;
  988. }
  989. if (nodeid != req_lib_cfg_killnode->nodeid) {
  990. continue;
  991. }
  992. match_nodeid_flag = 1;
  993. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "runtime.members.%u.status", nodeid);
  994. if (icmap_get_string_r(map, tmp_key, &status_str) != CS_OK) {
  995. error = CS_ERR_LIBRARY;
  996. goto send_response;
  997. }
  998. if (strcmp(status_str, "joined") != 0) {
  999. error = CS_ERR_NOT_EXIST;
  1000. goto send_response;
  1001. }
  1002. break;
  1003. }
  1004. if (!match_nodeid_flag) {
  1005. error = CS_ERR_NOT_EXIST;
  1006. goto send_response;
  1007. }
  1008. req_exec_cfg_killnode.header.size =
  1009. sizeof (struct req_exec_cfg_killnode);
  1010. req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  1011. MESSAGE_REQ_EXEC_CFG_KILLNODE);
  1012. req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
  1013. marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
  1014. iovec.iov_base = (char *)&req_exec_cfg_killnode;
  1015. iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
  1016. (void)api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  1017. send_response:
  1018. res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
  1019. res_lib_cfg_killnode.header.id = MESSAGE_RES_CFG_KILLNODE;
  1020. res_lib_cfg_killnode.header.error = error;
  1021. api->ipc_response_send(conn, &res_lib_cfg_killnode,
  1022. sizeof(res_lib_cfg_killnode));
  1023. free(status_str);
  1024. icmap_iter_finalize(iter);
  1025. LEAVE();
  1026. }
  1027. static void message_handler_req_lib_cfg_tryshutdown (
  1028. void *conn,
  1029. const void *msg)
  1030. {
  1031. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  1032. const struct req_lib_cfg_tryshutdown *req_lib_cfg_tryshutdown = msg;
  1033. struct qb_list_head *iter;
  1034. ENTER();
  1035. if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
  1036. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  1037. /*
  1038. * Tell other nodes
  1039. */
  1040. send_shutdown();
  1041. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  1042. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  1043. res_lib_cfg_tryshutdown.header.error = CS_OK;
  1044. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  1045. sizeof(res_lib_cfg_tryshutdown));
  1046. LEAVE();
  1047. return;
  1048. }
  1049. /*
  1050. * Shutdown in progress, return an error
  1051. */
  1052. if (shutdown_con) {
  1053. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  1054. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  1055. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  1056. res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
  1057. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  1058. sizeof(res_lib_cfg_tryshutdown));
  1059. LEAVE();
  1060. return;
  1061. }
  1062. ci->conn = conn;
  1063. shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
  1064. shutdown_flags = req_lib_cfg_tryshutdown->flags;
  1065. shutdown_yes = 0;
  1066. shutdown_no = 0;
  1067. /*
  1068. * Count the number of listeners
  1069. */
  1070. shutdown_expected = 0;
  1071. qb_list_for_each(iter, &trackers_list) {
  1072. struct cfg_info *testci = qb_list_entry(iter, struct cfg_info, list);
  1073. /*
  1074. * It is assumed that we will allow shutdown
  1075. */
  1076. if (testci != ci) {
  1077. testci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  1078. shutdown_expected++;
  1079. }
  1080. }
  1081. /*
  1082. * If no-one is listening for events then we can just go down now
  1083. */
  1084. if (shutdown_expected == 0) {
  1085. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  1086. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  1087. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  1088. res_lib_cfg_tryshutdown.header.error = CS_OK;
  1089. /*
  1090. * Tell originator that shutdown was confirmed
  1091. */
  1092. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  1093. sizeof(res_lib_cfg_tryshutdown));
  1094. send_shutdown();
  1095. LEAVE();
  1096. return;
  1097. }
  1098. else {
  1099. unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
  1100. /*
  1101. * Look for a shutdown timeout in configuration map
  1102. */
  1103. icmap_get_uint32("cfg.shutdown_timeout", &shutdown_timeout);
  1104. /*
  1105. * Start the timer. If we don't get a full set of replies before this goes
  1106. * off we'll cancel the shutdown
  1107. */
  1108. api->timer_add_duration((unsigned long long)shutdown_timeout*QB_TIME_NS_IN_MSEC, NULL,
  1109. shutdown_timer_fn, &shutdown_timer);
  1110. /*
  1111. * Tell the users we would like to shut down
  1112. */
  1113. send_test_shutdown(NULL, conn, CS_OK);
  1114. }
  1115. /*
  1116. * We don't sent a reply to the caller here.
  1117. * We send it when we know if we can shut down or not
  1118. */
  1119. LEAVE();
  1120. }
  1121. static void message_handler_req_lib_cfg_replytoshutdown (
  1122. void *conn,
  1123. const void *msg)
  1124. {
  1125. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  1126. const struct req_lib_cfg_replytoshutdown *req_lib_cfg_replytoshutdown = msg;
  1127. struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
  1128. int status = CS_OK;
  1129. ENTER();
  1130. if (!shutdown_con) {
  1131. status = CS_ERR_ACCESS;
  1132. goto exit_fn;
  1133. }
  1134. if (req_lib_cfg_replytoshutdown->response) {
  1135. shutdown_yes++;
  1136. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  1137. }
  1138. else {
  1139. shutdown_no++;
  1140. ci->shutdown_reply = SHUTDOWN_REPLY_NO;
  1141. }
  1142. check_shutdown_status();
  1143. exit_fn:
  1144. res_lib_cfg_replytoshutdown.header.error = status;
  1145. res_lib_cfg_replytoshutdown.header.id = MESSAGE_RES_CFG_REPLYTOSHUTDOWN;
  1146. res_lib_cfg_replytoshutdown.header.size = sizeof(res_lib_cfg_replytoshutdown);
  1147. api->ipc_response_send(conn, &res_lib_cfg_replytoshutdown,
  1148. sizeof(res_lib_cfg_replytoshutdown));
  1149. LEAVE();
  1150. }
  1151. static void message_handler_req_lib_cfg_get_node_addrs (void *conn,
  1152. const void *msg)
  1153. {
  1154. struct totem_ip_address node_ifs[INTERFACE_MAX];
  1155. unsigned int iface_ids[INTERFACE_MAX];
  1156. char **status;
  1157. unsigned int num_interfaces = 0;
  1158. int ret = CS_OK;
  1159. int i;
  1160. int live_addrs = 0;
  1161. const struct req_lib_cfg_get_node_addrs *req_lib_cfg_get_node_addrs = msg;
  1162. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs;
  1163. size_t res_lib_cfg_get_node_addrs_size;
  1164. unsigned int nodeid = req_lib_cfg_get_node_addrs->nodeid;
  1165. char *addr_buf;
  1166. if (nodeid == 0)
  1167. nodeid = api->totem_nodeid_get();
  1168. if (api->totem_ifaces_get(nodeid, iface_ids, node_ifs, INTERFACE_MAX, &status, &num_interfaces)) {
  1169. ret = CS_ERR_EXIST;
  1170. num_interfaces = 0;
  1171. }
  1172. res_lib_cfg_get_node_addrs_size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
  1173. res_lib_cfg_get_node_addrs = alloca(res_lib_cfg_get_node_addrs_size);
  1174. memset(res_lib_cfg_get_node_addrs, 0, res_lib_cfg_get_node_addrs_size);
  1175. res_lib_cfg_get_node_addrs->header.size = res_lib_cfg_get_node_addrs_size;
  1176. res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
  1177. res_lib_cfg_get_node_addrs->header.error = ret;
  1178. if (num_interfaces) {
  1179. res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
  1180. for (i = 0, addr_buf = (char *)res_lib_cfg_get_node_addrs->addrs;
  1181. i < num_interfaces; i++) {
  1182. if (node_ifs[i].family) {
  1183. memcpy(addr_buf, node_ifs[i].addr, TOTEMIP_ADDRLEN);
  1184. live_addrs++;
  1185. addr_buf += TOTEMIP_ADDRLEN;
  1186. }
  1187. }
  1188. res_lib_cfg_get_node_addrs->num_addrs = live_addrs;
  1189. } else {
  1190. res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
  1191. }
  1192. api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
  1193. }
  1194. static void message_handler_req_lib_cfg_local_get (void *conn, const void *msg)
  1195. {
  1196. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  1197. res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
  1198. res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
  1199. res_lib_cfg_local_get.header.error = CS_OK;
  1200. res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
  1201. api->ipc_response_send(conn, &res_lib_cfg_local_get,
  1202. sizeof(res_lib_cfg_local_get));
  1203. }
  1204. static void message_handler_req_lib_cfg_reload_config (void *conn, const void *msg)
  1205. {
  1206. struct req_exec_cfg_reload_config req_exec_cfg_reload_config;
  1207. struct iovec iovec;
  1208. ENTER();
  1209. req_exec_cfg_reload_config.header.size =
  1210. sizeof (struct req_exec_cfg_reload_config);
  1211. req_exec_cfg_reload_config.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  1212. MESSAGE_REQ_EXEC_CFG_RELOAD_CONFIG);
  1213. api->ipc_source_set (&req_exec_cfg_reload_config.source, conn);
  1214. api->ipc_refcnt_inc(conn);
  1215. iovec.iov_base = (char *)&req_exec_cfg_reload_config;
  1216. iovec.iov_len = sizeof (struct req_exec_cfg_reload_config);
  1217. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  1218. LEAVE();
  1219. }
  1220. static void message_handler_req_lib_cfg_reopen_log_files (void *conn, const void *msg)
  1221. {
  1222. struct res_lib_cfg_reopen_log_files res_lib_cfg_reopen_log_files;
  1223. cs_error_t res;
  1224. ENTER();
  1225. log_printf(LOGSYS_LEVEL_DEBUG, "Reopening logging files\n");
  1226. res = logsys_reopen_log_files();
  1227. res_lib_cfg_reopen_log_files.header.size = sizeof(res_lib_cfg_reopen_log_files);
  1228. res_lib_cfg_reopen_log_files.header.id = MESSAGE_RES_CFG_REOPEN_LOG_FILES;
  1229. res_lib_cfg_reopen_log_files.header.error = res;
  1230. api->ipc_response_send(conn,
  1231. &res_lib_cfg_reopen_log_files,
  1232. sizeof(res_lib_cfg_reopen_log_files));
  1233. LEAVE();
  1234. }