cfg.c 43 KB

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