cfg.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  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 <limits.h>
  47. #include <errno.h>
  48. #include <string.h>
  49. #include <assert.h>
  50. #include <corosync/corotypes.h>
  51. #include <qb/qbipc_common.h>
  52. #include <corosync/cfg.h>
  53. #include <qb/qblist.h>
  54. #include <corosync/mar_gen.h>
  55. #include <corosync/totem/totemip.h>
  56. #include <corosync/totem/totem.h>
  57. #include <corosync/ipc_cfg.h>
  58. #include <corosync/logsys.h>
  59. #include <corosync/coroapi.h>
  60. #include <corosync/icmap.h>
  61. #include <corosync/corodefs.h>
  62. #include "service.h"
  63. #include "main.h"
  64. LOGSYS_DECLARE_SUBSYS ("CFG");
  65. enum cfg_message_req_types {
  66. MESSAGE_REQ_EXEC_CFG_RINGREENABLE = 0,
  67. MESSAGE_REQ_EXEC_CFG_KILLNODE = 1,
  68. MESSAGE_REQ_EXEC_CFG_SHUTDOWN = 2,
  69. MESSAGE_REQ_EXEC_CFG_RELOAD_CONFIG = 3
  70. };
  71. #define DEFAULT_SHUTDOWN_TIMEOUT 5
  72. static struct qb_list_head trackers_list;
  73. /*
  74. * Variables controlling a requested shutdown
  75. */
  76. static corosync_timer_handle_t shutdown_timer;
  77. static struct cfg_info *shutdown_con;
  78. static uint32_t shutdown_flags;
  79. static int shutdown_yes;
  80. static int shutdown_no;
  81. static int shutdown_expected;
  82. struct cfg_info
  83. {
  84. struct qb_list_head list;
  85. void *conn;
  86. void *tracker_conn;
  87. enum {SHUTDOWN_REPLY_UNKNOWN, SHUTDOWN_REPLY_YES, SHUTDOWN_REPLY_NO} shutdown_reply;
  88. };
  89. static void cfg_confchg_fn (
  90. enum totem_configuration_type configuration_type,
  91. const unsigned int *member_list, size_t member_list_entries,
  92. const unsigned int *left_list, size_t left_list_entries,
  93. const unsigned int *joined_list, size_t joined_list_entries,
  94. const struct memb_ring_id *ring_id);
  95. static char *cfg_exec_init_fn (struct corosync_api_v1 *corosync_api_v1);
  96. static struct corosync_api_v1 *api;
  97. static int cfg_lib_init_fn (void *conn);
  98. static int cfg_lib_exit_fn (void *conn);
  99. static void message_handler_req_exec_cfg_ringreenable (
  100. const void *message,
  101. unsigned int nodeid);
  102. static void message_handler_req_exec_cfg_killnode (
  103. const void *message,
  104. unsigned int nodeid);
  105. static void message_handler_req_exec_cfg_shutdown (
  106. const void *message,
  107. unsigned int nodeid);
  108. static void message_handler_req_exec_cfg_reload_config (
  109. const void *message,
  110. unsigned int nodeid);
  111. static void exec_cfg_killnode_endian_convert (void *msg);
  112. static void message_handler_req_lib_cfg_ringstatusget (
  113. void *conn,
  114. const void *msg);
  115. static void message_handler_req_lib_cfg_ringreenable (
  116. void *conn,
  117. const void *msg);
  118. static void message_handler_req_lib_cfg_killnode (
  119. void *conn,
  120. const void *msg);
  121. static void message_handler_req_lib_cfg_tryshutdown (
  122. void *conn,
  123. const void *msg);
  124. static void message_handler_req_lib_cfg_replytoshutdown (
  125. void *conn,
  126. const void *msg);
  127. static void message_handler_req_lib_cfg_get_node_addrs (
  128. void *conn,
  129. const void *msg);
  130. static void message_handler_req_lib_cfg_local_get (
  131. void *conn,
  132. const void *msg);
  133. static void message_handler_req_lib_cfg_reload_config (
  134. void *conn,
  135. const void *msg);
  136. static void message_handler_req_lib_cfg_reopen_log_files (
  137. void *conn,
  138. const void *msg);
  139. /*
  140. * Service Handler Definition
  141. */
  142. static struct corosync_lib_handler cfg_lib_engine[] =
  143. {
  144. { /* 0 */
  145. .lib_handler_fn = message_handler_req_lib_cfg_ringstatusget,
  146. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  147. },
  148. { /* 1 */
  149. .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
  150. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  151. },
  152. { /* 2 */
  153. .lib_handler_fn = message_handler_req_lib_cfg_killnode,
  154. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  155. },
  156. { /* 3 */
  157. .lib_handler_fn = message_handler_req_lib_cfg_tryshutdown,
  158. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  159. },
  160. { /* 4 */
  161. .lib_handler_fn = message_handler_req_lib_cfg_replytoshutdown,
  162. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  163. },
  164. { /* 5 */
  165. .lib_handler_fn = message_handler_req_lib_cfg_get_node_addrs,
  166. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  167. },
  168. { /* 6 */
  169. .lib_handler_fn = message_handler_req_lib_cfg_local_get,
  170. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  171. },
  172. { /* 7 */
  173. .lib_handler_fn = message_handler_req_lib_cfg_reload_config,
  174. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  175. },
  176. { /* 8 */
  177. .lib_handler_fn = message_handler_req_lib_cfg_reopen_log_files,
  178. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  179. }
  180. };
  181. static struct corosync_exec_handler cfg_exec_engine[] =
  182. {
  183. { /* 0 */
  184. .exec_handler_fn = message_handler_req_exec_cfg_ringreenable,
  185. },
  186. { /* 1 */
  187. .exec_handler_fn = message_handler_req_exec_cfg_killnode,
  188. .exec_endian_convert_fn = exec_cfg_killnode_endian_convert
  189. },
  190. { /* 2 */
  191. .exec_handler_fn = message_handler_req_exec_cfg_shutdown,
  192. },
  193. { /* 3 */
  194. .exec_handler_fn = message_handler_req_exec_cfg_reload_config,
  195. }
  196. };
  197. /*
  198. * Exports the interface for the service
  199. */
  200. struct corosync_service_engine cfg_service_engine = {
  201. .name = "corosync configuration service",
  202. .id = CFG_SERVICE,
  203. .priority = 1,
  204. .private_data_size = sizeof(struct cfg_info),
  205. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED,
  206. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  207. .lib_init_fn = cfg_lib_init_fn,
  208. .lib_exit_fn = cfg_lib_exit_fn,
  209. .lib_engine = cfg_lib_engine,
  210. .lib_engine_count = sizeof (cfg_lib_engine) / sizeof (struct corosync_lib_handler),
  211. .exec_init_fn = cfg_exec_init_fn,
  212. .exec_engine = cfg_exec_engine,
  213. .exec_engine_count = sizeof (cfg_exec_engine) / sizeof (struct corosync_exec_handler),
  214. .confchg_fn = cfg_confchg_fn
  215. };
  216. struct corosync_service_engine *cfg_get_service_engine_ver0 (void)
  217. {
  218. return (&cfg_service_engine);
  219. }
  220. struct req_exec_cfg_ringreenable {
  221. struct qb_ipc_request_header header __attribute__((aligned(8)));
  222. mar_message_source_t source __attribute__((aligned(8)));
  223. };
  224. struct req_exec_cfg_reload_config {
  225. struct qb_ipc_request_header header __attribute__((aligned(8)));
  226. mar_message_source_t source __attribute__((aligned(8)));
  227. };
  228. struct req_exec_cfg_killnode {
  229. struct qb_ipc_request_header header __attribute__((aligned(8)));
  230. mar_uint32_t nodeid __attribute__((aligned(8)));
  231. mar_name_t reason __attribute__((aligned(8)));
  232. };
  233. struct req_exec_cfg_shutdown {
  234. struct qb_ipc_request_header header __attribute__((aligned(8)));
  235. };
  236. /* IMPL */
  237. static char *cfg_exec_init_fn (
  238. struct corosync_api_v1 *corosync_api_v1)
  239. {
  240. api = corosync_api_v1;
  241. qb_list_init(&trackers_list);
  242. return (NULL);
  243. }
  244. static void cfg_confchg_fn (
  245. enum totem_configuration_type configuration_type,
  246. const unsigned int *member_list, size_t member_list_entries,
  247. const unsigned int *left_list, size_t left_list_entries,
  248. const unsigned int *joined_list, size_t joined_list_entries,
  249. const struct memb_ring_id *ring_id)
  250. {
  251. }
  252. /*
  253. * Tell other nodes we are shutting down
  254. */
  255. static int send_shutdown(void)
  256. {
  257. struct req_exec_cfg_shutdown req_exec_cfg_shutdown;
  258. struct iovec iovec;
  259. ENTER();
  260. req_exec_cfg_shutdown.header.size =
  261. sizeof (struct req_exec_cfg_shutdown);
  262. req_exec_cfg_shutdown.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  263. MESSAGE_REQ_EXEC_CFG_SHUTDOWN);
  264. iovec.iov_base = (char *)&req_exec_cfg_shutdown;
  265. iovec.iov_len = sizeof (struct req_exec_cfg_shutdown);
  266. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  267. LEAVE();
  268. return 0;
  269. }
  270. static void send_test_shutdown(void *only_conn, void *exclude_conn, int status)
  271. {
  272. struct res_lib_cfg_testshutdown res_lib_cfg_testshutdown;
  273. struct qb_list_head *iter;
  274. ENTER();
  275. res_lib_cfg_testshutdown.header.size = sizeof(struct res_lib_cfg_testshutdown);
  276. res_lib_cfg_testshutdown.header.id = MESSAGE_RES_CFG_TESTSHUTDOWN;
  277. res_lib_cfg_testshutdown.header.error = status;
  278. res_lib_cfg_testshutdown.flags = shutdown_flags;
  279. if (only_conn) {
  280. TRACE1("sending testshutdown to only %p", only_conn);
  281. api->ipc_dispatch_send(only_conn, &res_lib_cfg_testshutdown,
  282. sizeof(res_lib_cfg_testshutdown));
  283. } else {
  284. qb_list_for_each(iter, &trackers_list) {
  285. struct cfg_info *ci = qb_list_entry(iter, struct cfg_info, list);
  286. if (ci->conn != exclude_conn) {
  287. TRACE1("sending testshutdown to %p", ci->tracker_conn);
  288. api->ipc_dispatch_send(ci->tracker_conn, &res_lib_cfg_testshutdown,
  289. sizeof(res_lib_cfg_testshutdown));
  290. }
  291. }
  292. }
  293. LEAVE();
  294. }
  295. static void check_shutdown_status(void)
  296. {
  297. ENTER();
  298. /*
  299. * Shutdown client might have gone away
  300. */
  301. if (!shutdown_con) {
  302. LEAVE();
  303. return;
  304. }
  305. /*
  306. * All replies safely gathered in ?
  307. */
  308. if (shutdown_yes + shutdown_no >= shutdown_expected) {
  309. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  310. api->timer_delete(shutdown_timer);
  311. if (shutdown_yes >= shutdown_expected ||
  312. shutdown_flags == CFG_SHUTDOWN_FLAG_REGARDLESS) {
  313. TRACE1("shutdown confirmed");
  314. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  315. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  316. res_lib_cfg_tryshutdown.header.error = CS_OK;
  317. /*
  318. * Tell originator that shutdown was confirmed
  319. */
  320. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  321. sizeof(res_lib_cfg_tryshutdown));
  322. shutdown_con = NULL;
  323. /*
  324. * Tell other nodes we are going down
  325. */
  326. send_shutdown();
  327. }
  328. else {
  329. TRACE1("shutdown cancelled");
  330. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  331. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  332. res_lib_cfg_tryshutdown.header.error = CS_ERR_BUSY;
  333. /*
  334. * Tell originator that shutdown was cancelled
  335. */
  336. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  337. sizeof(res_lib_cfg_tryshutdown));
  338. shutdown_con = NULL;
  339. }
  340. log_printf(LOGSYS_LEVEL_DEBUG, "shutdown decision is: (yes count: %d, no count: %d) flags=%x",
  341. shutdown_yes, shutdown_no, shutdown_flags);
  342. }
  343. LEAVE();
  344. }
  345. /*
  346. * Not all nodes responded to the shutdown (in time)
  347. */
  348. static void shutdown_timer_fn(void *arg)
  349. {
  350. ENTER();
  351. /*
  352. * Mark undecideds as "NO"
  353. */
  354. shutdown_no = shutdown_expected;
  355. check_shutdown_status();
  356. send_test_shutdown(NULL, NULL, CS_ERR_TIMEOUT);
  357. LEAVE();
  358. }
  359. static void remove_ci_from_shutdown(struct cfg_info *ci)
  360. {
  361. ENTER();
  362. /*
  363. * If the controlling shutdown process has quit, then cancel the
  364. * shutdown session
  365. */
  366. if (ci == shutdown_con) {
  367. shutdown_con = NULL;
  368. api->timer_delete(shutdown_timer);
  369. }
  370. if (!qb_list_empty(&ci->list)) {
  371. qb_list_del(&ci->list);
  372. qb_list_init(&ci->list);
  373. /*
  374. * Remove our option
  375. */
  376. if (shutdown_con) {
  377. if (ci->shutdown_reply == SHUTDOWN_REPLY_YES)
  378. shutdown_yes--;
  379. if (ci->shutdown_reply == SHUTDOWN_REPLY_NO)
  380. shutdown_no--;
  381. }
  382. /*
  383. * If we are leaving, then that's an implicit YES to shutdown
  384. */
  385. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  386. shutdown_yes++;
  387. check_shutdown_status();
  388. }
  389. LEAVE();
  390. }
  391. int cfg_lib_exit_fn (void *conn)
  392. {
  393. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  394. ENTER();
  395. remove_ci_from_shutdown(ci);
  396. LEAVE();
  397. return (0);
  398. }
  399. static int cfg_lib_init_fn (void *conn)
  400. {
  401. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  402. ENTER();
  403. qb_list_init(&ci->list);
  404. LEAVE();
  405. return (0);
  406. }
  407. /*
  408. * Executive message handlers
  409. */
  410. static void message_handler_req_exec_cfg_ringreenable (
  411. const void *message,
  412. unsigned int nodeid)
  413. {
  414. ENTER();
  415. LEAVE();
  416. }
  417. static void exec_cfg_killnode_endian_convert (void *msg)
  418. {
  419. struct req_exec_cfg_killnode *req_exec_cfg_killnode =
  420. (struct req_exec_cfg_killnode *)msg;
  421. ENTER();
  422. swab_mar_name_t(&req_exec_cfg_killnode->reason);
  423. LEAVE();
  424. }
  425. static void message_handler_req_exec_cfg_killnode (
  426. const void *message,
  427. unsigned int nodeid)
  428. {
  429. const struct req_exec_cfg_killnode *req_exec_cfg_killnode = message;
  430. cs_name_t reason;
  431. ENTER();
  432. log_printf(LOGSYS_LEVEL_DEBUG, "request to kill node %d(us=%d)",
  433. req_exec_cfg_killnode->nodeid, api->totem_nodeid_get());
  434. if (req_exec_cfg_killnode->nodeid == api->totem_nodeid_get()) {
  435. marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
  436. log_printf(LOGSYS_LEVEL_NOTICE, "Killed by node %d: %s",
  437. nodeid, reason.value);
  438. corosync_fatal_error(COROSYNC_FATAL_ERROR_EXIT);
  439. }
  440. LEAVE();
  441. }
  442. /*
  443. * Self shutdown
  444. */
  445. static void message_handler_req_exec_cfg_shutdown (
  446. const void *message,
  447. unsigned int nodeid)
  448. {
  449. ENTER();
  450. log_printf(LOGSYS_LEVEL_NOTICE, "Node %d was shut down by sysadmin", nodeid);
  451. if (nodeid == api->totem_nodeid_get()) {
  452. api->shutdown_request();
  453. }
  454. LEAVE();
  455. }
  456. /* strcmp replacement that can handle NULLs */
  457. static int nullcheck_strcmp(const char* left, const char *right)
  458. {
  459. if (!left && right)
  460. return -1;
  461. if (left && !right)
  462. return 1;
  463. if (!left && !right)
  464. return 0;
  465. return strcmp(left, right);
  466. }
  467. /*
  468. * If a key has changed value in the new file, then warn the user and remove it from the temp_map
  469. */
  470. static void delete_and_notify_if_changed(icmap_map_t temp_map, const char *key_name)
  471. {
  472. if (!(icmap_key_value_eq(temp_map, key_name, icmap_get_global_map(), key_name))) {
  473. if (icmap_delete_r(temp_map, key_name) == CS_OK) {
  474. log_printf(LOGSYS_LEVEL_NOTICE, "Modified entry '%s' in corosync.conf cannot be changed at run-time", key_name);
  475. }
  476. }
  477. }
  478. /*
  479. * Remove any keys from the new config file that in the new corosync.conf but that
  480. * cannot be changed at run time. A log message will be issued for each
  481. * entry that the user wants to change but they cannot.
  482. *
  483. * Add more here as needed.
  484. */
  485. static void remove_ro_entries(icmap_map_t temp_map)
  486. {
  487. delete_and_notify_if_changed(temp_map, "totem.secauth");
  488. delete_and_notify_if_changed(temp_map, "totem.crypto_hash");
  489. delete_and_notify_if_changed(temp_map, "totem.crypto_cipher");
  490. delete_and_notify_if_changed(temp_map, "totem.version");
  491. delete_and_notify_if_changed(temp_map, "totem.threads");
  492. delete_and_notify_if_changed(temp_map, "totem.ip_version");
  493. delete_and_notify_if_changed(temp_map, "totem.rrp_mode");
  494. delete_and_notify_if_changed(temp_map, "totem.netmtu");
  495. delete_and_notify_if_changed(temp_map, "totem.interface.ringnumber");
  496. delete_and_notify_if_changed(temp_map, "totem.interface.bindnetaddr");
  497. delete_and_notify_if_changed(temp_map, "totem.interface.mcastaddr");
  498. delete_and_notify_if_changed(temp_map, "totem.interface.broadcast");
  499. delete_and_notify_if_changed(temp_map, "totem.interface.mcastport");
  500. delete_and_notify_if_changed(temp_map, "totem.interface.ttl");
  501. delete_and_notify_if_changed(temp_map, "totem.vsftype");
  502. delete_and_notify_if_changed(temp_map, "totem.transport");
  503. delete_and_notify_if_changed(temp_map, "totem.cluster_name");
  504. delete_and_notify_if_changed(temp_map, "quorum.provider");
  505. delete_and_notify_if_changed(temp_map, "system.move_to_root_cgroup");
  506. delete_and_notify_if_changed(temp_map, "system.sched_rr");
  507. delete_and_notify_if_changed(temp_map, "system.priority");
  508. delete_and_notify_if_changed(temp_map, "system.qb_ipc_type");
  509. delete_and_notify_if_changed(temp_map, "system.state_dir");
  510. }
  511. /*
  512. * Remove entries that exist in the global map, but not in the temp_map, this will
  513. * cause delete notifications to be sent to any listeners.
  514. *
  515. * NOTE: This routine depends entirely on the keys returned by the iterators
  516. * being in alpha-sorted order.
  517. */
  518. static void remove_deleted_entries(icmap_map_t temp_map, const char *prefix)
  519. {
  520. icmap_iter_t old_iter;
  521. icmap_iter_t new_iter;
  522. const char *old_key, *new_key;
  523. int ret;
  524. old_iter = icmap_iter_init(prefix);
  525. new_iter = icmap_iter_init_r(temp_map, prefix);
  526. old_key = icmap_iter_next(old_iter, NULL, NULL);
  527. new_key = icmap_iter_next(new_iter, NULL, NULL);
  528. while (old_key || new_key) {
  529. ret = nullcheck_strcmp(old_key, new_key);
  530. if ((ret < 0 && old_key) || !new_key) {
  531. /*
  532. * new_key is greater, a line (or more) has been deleted
  533. * Continue until old is >= new
  534. */
  535. do {
  536. /* Remove it from icmap & send notifications */
  537. icmap_delete(old_key);
  538. old_key = icmap_iter_next(old_iter, NULL, NULL);
  539. ret = nullcheck_strcmp(old_key, new_key);
  540. } while (ret < 0 && old_key);
  541. }
  542. else if ((ret > 0 && new_key) || !old_key) {
  543. /*
  544. * old_key is greater, a line (or more) has been added
  545. * Continue until new is >= old
  546. *
  547. * we don't need to do anything special with this like tell
  548. * icmap. That will happen when we copy the values over
  549. */
  550. do {
  551. new_key = icmap_iter_next(new_iter, NULL, NULL);
  552. ret = nullcheck_strcmp(old_key, new_key);
  553. } while (ret > 0 && new_key);
  554. }
  555. if (ret == 0) {
  556. new_key = icmap_iter_next(new_iter, NULL, NULL);
  557. old_key = icmap_iter_next(old_iter, NULL, NULL);
  558. }
  559. }
  560. icmap_iter_finalize(new_iter);
  561. icmap_iter_finalize(old_iter);
  562. }
  563. /*
  564. * Reload configuration file
  565. */
  566. static void message_handler_req_exec_cfg_reload_config (
  567. const void *message,
  568. unsigned int nodeid)
  569. {
  570. const struct req_exec_cfg_reload_config *req_exec_cfg_reload_config = message;
  571. struct res_lib_cfg_reload_config res_lib_cfg_reload_config;
  572. icmap_map_t temp_map;
  573. const char *error_string;
  574. int res = CS_OK;
  575. ENTER();
  576. log_printf(LOGSYS_LEVEL_NOTICE, "Config reload requested by node %d", nodeid);
  577. /*
  578. * Set up a new hashtable as a staging area.
  579. */
  580. if ((res = icmap_init_r(&temp_map)) != CS_OK) {
  581. log_printf(LOGSYS_LEVEL_ERROR, "Unable to create temporary icmap. config file reload cancelled\n");
  582. goto reload_fini;
  583. }
  584. /*
  585. * Load new config into the temporary map
  586. */
  587. res = coroparse_configparse(temp_map, &error_string);
  588. if (res == -1) {
  589. log_printf (LOGSYS_LEVEL_ERROR, "Unable to reload config file: %s", error_string);
  590. res = CS_ERR_LIBRARY;
  591. goto reload_return;
  592. }
  593. /* Tell interested listeners that we have started a reload */
  594. icmap_set_uint8("config.reload_in_progress", 1);
  595. /* Detect deleted entries and remove them from the main icmap hashtable */
  596. remove_deleted_entries(temp_map, "logging.");
  597. remove_deleted_entries(temp_map, "totem.");
  598. remove_deleted_entries(temp_map, "nodelist.");
  599. remove_deleted_entries(temp_map, "quorum.");
  600. remove_deleted_entries(temp_map, "uidgid.config.");
  601. remove_deleted_entries(temp_map, "nozzle.");
  602. /* Remove entries that cannot be changed */
  603. remove_ro_entries(temp_map);
  604. /*
  605. * Copy new keys into live config.
  606. * If this fails we will have a partially loaded config because some keys (above) might
  607. * have been reset to defaults - I'm not sure what to do here, we might have to quit.
  608. */
  609. if ( (res = icmap_copy_map(icmap_get_global_map(), temp_map)) != CS_OK) {
  610. log_printf (LOGSYS_LEVEL_ERROR, "Error making new config live. cmap database may be inconsistent\n");
  611. }
  612. /* All done - let clients know */
  613. icmap_set_uint8("config.reload_in_progress", 0);
  614. reload_fini:
  615. /* Finished with the temporary storage */
  616. icmap_fini_r(temp_map);
  617. reload_return:
  618. /* All done, return result to the caller if it was on this system */
  619. if (nodeid == api->totem_nodeid_get()) {
  620. res_lib_cfg_reload_config.header.size = sizeof(res_lib_cfg_reload_config);
  621. res_lib_cfg_reload_config.header.id = MESSAGE_RES_CFG_RELOAD_CONFIG;
  622. res_lib_cfg_reload_config.header.error = res;
  623. api->ipc_response_send(req_exec_cfg_reload_config->source.conn,
  624. &res_lib_cfg_reload_config,
  625. sizeof(res_lib_cfg_reload_config));
  626. api->ipc_refcnt_dec(req_exec_cfg_reload_config->source.conn);;
  627. }
  628. LEAVE();
  629. }
  630. /*
  631. * Library Interface Implementation
  632. */
  633. static void message_handler_req_lib_cfg_ringstatusget (
  634. void *conn,
  635. const void *msg)
  636. {
  637. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  638. struct totem_ip_address interfaces[INTERFACE_MAX];
  639. unsigned int iface_count;
  640. char **status;
  641. const char *totem_ip_string;
  642. char ifname[CFG_INTERFACE_NAME_MAX_LEN];
  643. unsigned int iface_ids[INTERFACE_MAX];
  644. unsigned int i;
  645. cs_error_t res = CS_OK;
  646. ENTER();
  647. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  648. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  649. api->totem_ifaces_get (
  650. api->totem_nodeid_get(),
  651. iface_ids,
  652. interfaces,
  653. INTERFACE_MAX,
  654. &status,
  655. &iface_count);
  656. assert(iface_count <= CFG_MAX_INTERFACES);
  657. res_lib_cfg_ringstatusget.interface_count = iface_count;
  658. for (i = 0; i < iface_count; i++) {
  659. totem_ip_string
  660. = (const char *)api->totem_ip_print (&interfaces[i]);
  661. if (!totem_ip_string) {
  662. totem_ip_string="";
  663. }
  664. /* Allow for i/f number at the start */
  665. if (strlen(totem_ip_string) >= CFG_INTERFACE_NAME_MAX_LEN-3) {
  666. log_printf(LOGSYS_LEVEL_ERROR, "String representation of interface %u is too long", i);
  667. res = CS_ERR_NAME_TOO_LONG;
  668. goto send_response;
  669. }
  670. snprintf(ifname, sizeof(ifname), "%d %s", iface_ids[i], totem_ip_string);
  671. if (strlen(status[i]) >= CFG_INTERFACE_STATUS_MAX_LEN) {
  672. log_printf(LOGSYS_LEVEL_ERROR, "Status string for interface %u is too long", i);
  673. res = CS_ERR_NAME_TOO_LONG;
  674. goto send_response;
  675. }
  676. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  677. status[i]);
  678. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  679. ifname);
  680. }
  681. send_response:
  682. res_lib_cfg_ringstatusget.header.error = res;
  683. api->ipc_response_send (
  684. conn,
  685. &res_lib_cfg_ringstatusget,
  686. sizeof (struct res_lib_cfg_ringstatusget));
  687. LEAVE();
  688. }
  689. static void message_handler_req_lib_cfg_ringreenable (
  690. void *conn,
  691. const void *msg)
  692. {
  693. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  694. ENTER();
  695. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  696. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  697. res_lib_cfg_ringreenable.header.error = CS_ERR_NOT_SUPPORTED;
  698. api->ipc_response_send (
  699. conn, &res_lib_cfg_ringreenable,
  700. sizeof (struct res_lib_cfg_ringreenable));
  701. LEAVE();
  702. }
  703. static void message_handler_req_lib_cfg_killnode (
  704. void *conn,
  705. const void *msg)
  706. {
  707. const struct req_lib_cfg_killnode *req_lib_cfg_killnode = msg;
  708. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  709. struct req_exec_cfg_killnode req_exec_cfg_killnode;
  710. struct iovec iovec;
  711. ENTER();
  712. req_exec_cfg_killnode.header.size =
  713. sizeof (struct req_exec_cfg_killnode);
  714. req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  715. MESSAGE_REQ_EXEC_CFG_KILLNODE);
  716. req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
  717. marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
  718. iovec.iov_base = (char *)&req_exec_cfg_killnode;
  719. iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
  720. (void)api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  721. res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
  722. res_lib_cfg_killnode.header.id = MESSAGE_RES_CFG_KILLNODE;
  723. res_lib_cfg_killnode.header.error = CS_OK;
  724. api->ipc_response_send(conn, &res_lib_cfg_killnode,
  725. sizeof(res_lib_cfg_killnode));
  726. LEAVE();
  727. }
  728. static void message_handler_req_lib_cfg_tryshutdown (
  729. void *conn,
  730. const void *msg)
  731. {
  732. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  733. const struct req_lib_cfg_tryshutdown *req_lib_cfg_tryshutdown = msg;
  734. struct qb_list_head *iter;
  735. ENTER();
  736. if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
  737. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  738. /*
  739. * Tell other nodes
  740. */
  741. send_shutdown();
  742. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  743. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  744. res_lib_cfg_tryshutdown.header.error = CS_OK;
  745. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  746. sizeof(res_lib_cfg_tryshutdown));
  747. LEAVE();
  748. return;
  749. }
  750. /*
  751. * Shutdown in progress, return an error
  752. */
  753. if (shutdown_con) {
  754. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  755. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  756. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  757. res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
  758. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  759. sizeof(res_lib_cfg_tryshutdown));
  760. LEAVE();
  761. return;
  762. }
  763. ci->conn = conn;
  764. shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
  765. shutdown_flags = req_lib_cfg_tryshutdown->flags;
  766. shutdown_yes = 0;
  767. shutdown_no = 0;
  768. /*
  769. * Count the number of listeners
  770. */
  771. shutdown_expected = 0;
  772. qb_list_for_each(iter, &trackers_list) {
  773. struct cfg_info *testci = qb_list_entry(iter, struct cfg_info, list);
  774. /*
  775. * It is assumed that we will allow shutdown
  776. */
  777. if (testci != ci) {
  778. testci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  779. shutdown_expected++;
  780. }
  781. }
  782. /*
  783. * If no-one is listening for events then we can just go down now
  784. */
  785. if (shutdown_expected == 0) {
  786. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  787. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  788. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  789. res_lib_cfg_tryshutdown.header.error = CS_OK;
  790. /*
  791. * Tell originator that shutdown was confirmed
  792. */
  793. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  794. sizeof(res_lib_cfg_tryshutdown));
  795. send_shutdown();
  796. LEAVE();
  797. return;
  798. }
  799. else {
  800. unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
  801. /*
  802. * Look for a shutdown timeout in configuration map
  803. */
  804. icmap_get_uint32("cfg.shutdown_timeout", &shutdown_timeout);
  805. /*
  806. * Start the timer. If we don't get a full set of replies before this goes
  807. * off we'll cancel the shutdown
  808. */
  809. api->timer_add_duration((unsigned long long)shutdown_timeout*1000000000, NULL,
  810. shutdown_timer_fn, &shutdown_timer);
  811. /*
  812. * Tell the users we would like to shut down
  813. */
  814. send_test_shutdown(NULL, conn, CS_OK);
  815. }
  816. /*
  817. * We don't sent a reply to the caller here.
  818. * We send it when we know if we can shut down or not
  819. */
  820. LEAVE();
  821. }
  822. static void message_handler_req_lib_cfg_replytoshutdown (
  823. void *conn,
  824. const void *msg)
  825. {
  826. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  827. const struct req_lib_cfg_replytoshutdown *req_lib_cfg_replytoshutdown = msg;
  828. struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
  829. int status = CS_OK;
  830. ENTER();
  831. if (!shutdown_con) {
  832. status = CS_ERR_ACCESS;
  833. goto exit_fn;
  834. }
  835. if (req_lib_cfg_replytoshutdown->response) {
  836. shutdown_yes++;
  837. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  838. }
  839. else {
  840. shutdown_no++;
  841. ci->shutdown_reply = SHUTDOWN_REPLY_NO;
  842. }
  843. check_shutdown_status();
  844. exit_fn:
  845. res_lib_cfg_replytoshutdown.header.error = status;
  846. res_lib_cfg_replytoshutdown.header.id = MESSAGE_RES_CFG_REPLYTOSHUTDOWN;
  847. res_lib_cfg_replytoshutdown.header.size = sizeof(res_lib_cfg_replytoshutdown);
  848. api->ipc_response_send(conn, &res_lib_cfg_replytoshutdown,
  849. sizeof(res_lib_cfg_replytoshutdown));
  850. LEAVE();
  851. }
  852. static void message_handler_req_lib_cfg_get_node_addrs (void *conn,
  853. const void *msg)
  854. {
  855. struct totem_ip_address node_ifs[INTERFACE_MAX];
  856. unsigned int iface_ids[INTERFACE_MAX];
  857. char buf[PIPE_BUF];
  858. char **status;
  859. unsigned int num_interfaces = 0;
  860. struct sockaddr_storage *ss;
  861. int ret = CS_OK;
  862. int i;
  863. int live_addrs = 0;
  864. const struct req_lib_cfg_get_node_addrs *req_lib_cfg_get_node_addrs = msg;
  865. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)buf;
  866. unsigned int nodeid = req_lib_cfg_get_node_addrs->nodeid;
  867. char *addr_buf;
  868. if (nodeid == 0)
  869. nodeid = api->totem_nodeid_get();
  870. if (api->totem_ifaces_get(nodeid, iface_ids, node_ifs, INTERFACE_MAX, &status, &num_interfaces)) {
  871. ret = CS_ERR_EXIST;
  872. num_interfaces = 0;
  873. }
  874. res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
  875. res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
  876. res_lib_cfg_get_node_addrs->header.error = ret;
  877. if (num_interfaces) {
  878. res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
  879. for (i = 0, addr_buf = (char *)res_lib_cfg_get_node_addrs->addrs;
  880. i < num_interfaces; i++) {
  881. ss = (struct sockaddr_storage *)&node_ifs[i].addr;
  882. if (ss->ss_family) {
  883. memcpy(addr_buf, node_ifs[i].addr, TOTEMIP_ADDRLEN);
  884. live_addrs++;
  885. addr_buf += TOTEMIP_ADDRLEN;
  886. }
  887. }
  888. res_lib_cfg_get_node_addrs->num_addrs = live_addrs;
  889. } else {
  890. res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
  891. }
  892. api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
  893. }
  894. static void message_handler_req_lib_cfg_local_get (void *conn, const void *msg)
  895. {
  896. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  897. res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
  898. res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
  899. res_lib_cfg_local_get.header.error = CS_OK;
  900. res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
  901. api->ipc_response_send(conn, &res_lib_cfg_local_get,
  902. sizeof(res_lib_cfg_local_get));
  903. }
  904. static void message_handler_req_lib_cfg_reload_config (void *conn, const void *msg)
  905. {
  906. struct req_exec_cfg_reload_config req_exec_cfg_reload_config;
  907. struct iovec iovec;
  908. ENTER();
  909. req_exec_cfg_reload_config.header.size =
  910. sizeof (struct req_exec_cfg_reload_config);
  911. req_exec_cfg_reload_config.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  912. MESSAGE_REQ_EXEC_CFG_RELOAD_CONFIG);
  913. api->ipc_source_set (&req_exec_cfg_reload_config.source, conn);
  914. api->ipc_refcnt_inc(conn);
  915. iovec.iov_base = (char *)&req_exec_cfg_reload_config;
  916. iovec.iov_len = sizeof (struct req_exec_cfg_reload_config);
  917. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  918. LEAVE();
  919. }
  920. static void message_handler_req_lib_cfg_reopen_log_files (void *conn, const void *msg)
  921. {
  922. struct res_lib_cfg_reopen_log_files res_lib_cfg_reopen_log_files;
  923. cs_error_t res;
  924. ENTER();
  925. log_printf(LOGSYS_LEVEL_DEBUG, "Reopening logging files\n");
  926. res = logsys_reopen_log_files();
  927. res_lib_cfg_reopen_log_files.header.size = sizeof(res_lib_cfg_reopen_log_files);
  928. res_lib_cfg_reopen_log_files.header.id = MESSAGE_RES_CFG_REOPEN_LOG_FILES;
  929. res_lib_cfg_reopen_log_files.header.error = res;
  930. api->ipc_response_send(conn,
  931. &res_lib_cfg_reopen_log_files,
  932. sizeof(res_lib_cfg_reopen_log_files));
  933. LEAVE();
  934. }