cfg.c 30 KB

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