cfg.c 43 KB

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