cfg.c 43 KB

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