4
0

cfg.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  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 " CS_PRI_NODE_ID " (us=" CS_PRI_NODE_ID ")",
  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 " CS_PRI_NODE_ID " : %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 " CS_PRI_NODE_ID " 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.keyfile");
  491. delete_and_notify_if_changed(temp_map, "totem.key");
  492. delete_and_notify_if_changed(temp_map, "totem.version");
  493. delete_and_notify_if_changed(temp_map, "totem.threads");
  494. delete_and_notify_if_changed(temp_map, "totem.ip_version");
  495. delete_and_notify_if_changed(temp_map, "totem.rrp_mode");
  496. delete_and_notify_if_changed(temp_map, "totem.netmtu");
  497. delete_and_notify_if_changed(temp_map, "totem.interface.ringnumber");
  498. delete_and_notify_if_changed(temp_map, "totem.interface.bindnetaddr");
  499. delete_and_notify_if_changed(temp_map, "totem.interface.mcastaddr");
  500. delete_and_notify_if_changed(temp_map, "totem.interface.broadcast");
  501. delete_and_notify_if_changed(temp_map, "totem.interface.mcastport");
  502. delete_and_notify_if_changed(temp_map, "totem.interface.ttl");
  503. delete_and_notify_if_changed(temp_map, "totem.vsftype");
  504. delete_and_notify_if_changed(temp_map, "totem.transport");
  505. delete_and_notify_if_changed(temp_map, "totem.cluster_name");
  506. delete_and_notify_if_changed(temp_map, "quorum.provider");
  507. delete_and_notify_if_changed(temp_map, "system.move_to_root_cgroup");
  508. delete_and_notify_if_changed(temp_map, "system.sched_rr");
  509. delete_and_notify_if_changed(temp_map, "system.priority");
  510. delete_and_notify_if_changed(temp_map, "system.qb_ipc_type");
  511. delete_and_notify_if_changed(temp_map, "system.state_dir");
  512. }
  513. /*
  514. * Remove entries that exist in the global map, but not in the temp_map, this will
  515. * cause delete notifications to be sent to any listeners.
  516. *
  517. * NOTE: This routine depends entirely on the keys returned by the iterators
  518. * being in alpha-sorted order.
  519. */
  520. static void remove_deleted_entries(icmap_map_t temp_map, const char *prefix)
  521. {
  522. icmap_iter_t old_iter;
  523. icmap_iter_t new_iter;
  524. const char *old_key, *new_key;
  525. int ret;
  526. old_iter = icmap_iter_init(prefix);
  527. new_iter = icmap_iter_init_r(temp_map, prefix);
  528. old_key = icmap_iter_next(old_iter, NULL, NULL);
  529. new_key = icmap_iter_next(new_iter, NULL, NULL);
  530. while (old_key || new_key) {
  531. ret = nullcheck_strcmp(old_key, new_key);
  532. if ((ret < 0 && old_key) || !new_key) {
  533. /*
  534. * new_key is greater, a line (or more) has been deleted
  535. * Continue until old is >= new
  536. */
  537. do {
  538. /* Remove it from icmap & send notifications */
  539. icmap_delete(old_key);
  540. old_key = icmap_iter_next(old_iter, NULL, NULL);
  541. ret = nullcheck_strcmp(old_key, new_key);
  542. } while (ret < 0 && old_key);
  543. }
  544. else if ((ret > 0 && new_key) || !old_key) {
  545. /*
  546. * old_key is greater, a line (or more) has been added
  547. * Continue until new is >= old
  548. *
  549. * we don't need to do anything special with this like tell
  550. * icmap. That will happen when we copy the values over
  551. */
  552. do {
  553. new_key = icmap_iter_next(new_iter, NULL, NULL);
  554. ret = nullcheck_strcmp(old_key, new_key);
  555. } while (ret > 0 && new_key);
  556. }
  557. if (ret == 0) {
  558. new_key = icmap_iter_next(new_iter, NULL, NULL);
  559. old_key = icmap_iter_next(old_iter, NULL, NULL);
  560. }
  561. }
  562. icmap_iter_finalize(new_iter);
  563. icmap_iter_finalize(old_iter);
  564. }
  565. /*
  566. * Reload configuration file
  567. */
  568. static void message_handler_req_exec_cfg_reload_config (
  569. const void *message,
  570. unsigned int nodeid)
  571. {
  572. const struct req_exec_cfg_reload_config *req_exec_cfg_reload_config = message;
  573. struct res_lib_cfg_reload_config res_lib_cfg_reload_config;
  574. icmap_map_t temp_map;
  575. const char *error_string;
  576. int res = CS_OK;
  577. ENTER();
  578. log_printf(LOGSYS_LEVEL_NOTICE, "Config reload requested by node " CS_PRI_NODE_ID, nodeid);
  579. /*
  580. * Set up a new hashtable as a staging area.
  581. */
  582. if ((res = icmap_init_r(&temp_map)) != CS_OK) {
  583. log_printf(LOGSYS_LEVEL_ERROR, "Unable to create temporary icmap. config file reload cancelled\n");
  584. goto reload_fini;
  585. }
  586. /*
  587. * Load new config into the temporary map
  588. */
  589. res = coroparse_configparse(temp_map, &error_string);
  590. if (res == -1) {
  591. log_printf (LOGSYS_LEVEL_ERROR, "Unable to reload config file: %s", error_string);
  592. res = CS_ERR_LIBRARY;
  593. goto reload_return;
  594. }
  595. /* Tell interested listeners that we have started a reload */
  596. icmap_set_uint8("config.reload_in_progress", 1);
  597. /* Detect deleted entries and remove them from the main icmap hashtable */
  598. remove_deleted_entries(temp_map, "logging.");
  599. remove_deleted_entries(temp_map, "totem.");
  600. remove_deleted_entries(temp_map, "nodelist.");
  601. remove_deleted_entries(temp_map, "quorum.");
  602. remove_deleted_entries(temp_map, "uidgid.config.");
  603. remove_deleted_entries(temp_map, "nozzle.");
  604. /* Remove entries that cannot be changed */
  605. remove_ro_entries(temp_map);
  606. /*
  607. * Copy new keys into live config.
  608. * If this fails we will have a partially loaded config because some keys (above) might
  609. * have been reset to defaults - I'm not sure what to do here, we might have to quit.
  610. */
  611. if ( (res = icmap_copy_map(icmap_get_global_map(), temp_map)) != CS_OK) {
  612. log_printf (LOGSYS_LEVEL_ERROR, "Error making new config live. cmap database may be inconsistent\n");
  613. }
  614. /* All done - let clients know */
  615. icmap_set_uint8("config.reload_in_progress", 0);
  616. reload_fini:
  617. /* Finished with the temporary storage */
  618. icmap_fini_r(temp_map);
  619. reload_return:
  620. /* All done, return result to the caller if it was on this system */
  621. if (nodeid == api->totem_nodeid_get()) {
  622. res_lib_cfg_reload_config.header.size = sizeof(res_lib_cfg_reload_config);
  623. res_lib_cfg_reload_config.header.id = MESSAGE_RES_CFG_RELOAD_CONFIG;
  624. res_lib_cfg_reload_config.header.error = res;
  625. api->ipc_response_send(req_exec_cfg_reload_config->source.conn,
  626. &res_lib_cfg_reload_config,
  627. sizeof(res_lib_cfg_reload_config));
  628. api->ipc_refcnt_dec(req_exec_cfg_reload_config->source.conn);;
  629. }
  630. LEAVE();
  631. }
  632. /*
  633. * Library Interface Implementation
  634. */
  635. static void message_handler_req_lib_cfg_ringstatusget (
  636. void *conn,
  637. const void *msg)
  638. {
  639. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  640. struct totem_ip_address interfaces[INTERFACE_MAX];
  641. unsigned int iface_count;
  642. char **status;
  643. const char *totem_ip_string;
  644. char ifname[CFG_INTERFACE_NAME_MAX_LEN];
  645. unsigned int iface_ids[INTERFACE_MAX];
  646. unsigned int i;
  647. cs_error_t res = CS_OK;
  648. ENTER();
  649. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  650. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  651. api->totem_ifaces_get (
  652. api->totem_nodeid_get(),
  653. iface_ids,
  654. interfaces,
  655. INTERFACE_MAX,
  656. &status,
  657. &iface_count);
  658. assert(iface_count <= CFG_MAX_INTERFACES);
  659. res_lib_cfg_ringstatusget.interface_count = iface_count;
  660. for (i = 0; i < iface_count; i++) {
  661. totem_ip_string
  662. = (const char *)api->totem_ip_print (&interfaces[i]);
  663. if (!totem_ip_string) {
  664. totem_ip_string="";
  665. }
  666. /* Allow for i/f number at the start */
  667. if (strlen(totem_ip_string) >= CFG_INTERFACE_NAME_MAX_LEN-3) {
  668. log_printf(LOGSYS_LEVEL_ERROR, "String representation of interface %u is too long", i);
  669. res = CS_ERR_NAME_TOO_LONG;
  670. goto send_response;
  671. }
  672. snprintf(ifname, sizeof(ifname), "%d %s", iface_ids[i], totem_ip_string);
  673. if (strlen(status[i]) >= CFG_INTERFACE_STATUS_MAX_LEN) {
  674. log_printf(LOGSYS_LEVEL_ERROR, "Status string for interface %u is too long", i);
  675. res = CS_ERR_NAME_TOO_LONG;
  676. goto send_response;
  677. }
  678. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  679. status[i]);
  680. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  681. ifname);
  682. }
  683. send_response:
  684. res_lib_cfg_ringstatusget.header.error = res;
  685. api->ipc_response_send (
  686. conn,
  687. &res_lib_cfg_ringstatusget,
  688. sizeof (struct res_lib_cfg_ringstatusget));
  689. LEAVE();
  690. }
  691. static void message_handler_req_lib_cfg_ringreenable (
  692. void *conn,
  693. const void *msg)
  694. {
  695. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  696. ENTER();
  697. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  698. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  699. res_lib_cfg_ringreenable.header.error = CS_ERR_NOT_SUPPORTED;
  700. api->ipc_response_send (
  701. conn, &res_lib_cfg_ringreenable,
  702. sizeof (struct res_lib_cfg_ringreenable));
  703. LEAVE();
  704. }
  705. static void message_handler_req_lib_cfg_killnode (
  706. void *conn,
  707. const void *msg)
  708. {
  709. const struct req_lib_cfg_killnode *req_lib_cfg_killnode = msg;
  710. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  711. struct req_exec_cfg_killnode req_exec_cfg_killnode;
  712. struct iovec iovec;
  713. ENTER();
  714. req_exec_cfg_killnode.header.size =
  715. sizeof (struct req_exec_cfg_killnode);
  716. req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  717. MESSAGE_REQ_EXEC_CFG_KILLNODE);
  718. req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
  719. marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
  720. iovec.iov_base = (char *)&req_exec_cfg_killnode;
  721. iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
  722. (void)api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  723. res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
  724. res_lib_cfg_killnode.header.id = MESSAGE_RES_CFG_KILLNODE;
  725. res_lib_cfg_killnode.header.error = CS_OK;
  726. api->ipc_response_send(conn, &res_lib_cfg_killnode,
  727. sizeof(res_lib_cfg_killnode));
  728. LEAVE();
  729. }
  730. static void message_handler_req_lib_cfg_tryshutdown (
  731. void *conn,
  732. const void *msg)
  733. {
  734. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  735. const struct req_lib_cfg_tryshutdown *req_lib_cfg_tryshutdown = msg;
  736. struct qb_list_head *iter;
  737. ENTER();
  738. if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
  739. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  740. /*
  741. * Tell other nodes
  742. */
  743. send_shutdown();
  744. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  745. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  746. res_lib_cfg_tryshutdown.header.error = CS_OK;
  747. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  748. sizeof(res_lib_cfg_tryshutdown));
  749. LEAVE();
  750. return;
  751. }
  752. /*
  753. * Shutdown in progress, return an error
  754. */
  755. if (shutdown_con) {
  756. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  757. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  758. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  759. res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
  760. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  761. sizeof(res_lib_cfg_tryshutdown));
  762. LEAVE();
  763. return;
  764. }
  765. ci->conn = conn;
  766. shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
  767. shutdown_flags = req_lib_cfg_tryshutdown->flags;
  768. shutdown_yes = 0;
  769. shutdown_no = 0;
  770. /*
  771. * Count the number of listeners
  772. */
  773. shutdown_expected = 0;
  774. qb_list_for_each(iter, &trackers_list) {
  775. struct cfg_info *testci = qb_list_entry(iter, struct cfg_info, list);
  776. /*
  777. * It is assumed that we will allow shutdown
  778. */
  779. if (testci != ci) {
  780. testci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  781. shutdown_expected++;
  782. }
  783. }
  784. /*
  785. * If no-one is listening for events then we can just go down now
  786. */
  787. if (shutdown_expected == 0) {
  788. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  789. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  790. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  791. res_lib_cfg_tryshutdown.header.error = CS_OK;
  792. /*
  793. * Tell originator that shutdown was confirmed
  794. */
  795. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  796. sizeof(res_lib_cfg_tryshutdown));
  797. send_shutdown();
  798. LEAVE();
  799. return;
  800. }
  801. else {
  802. unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
  803. /*
  804. * Look for a shutdown timeout in configuration map
  805. */
  806. icmap_get_uint32("cfg.shutdown_timeout", &shutdown_timeout);
  807. /*
  808. * Start the timer. If we don't get a full set of replies before this goes
  809. * off we'll cancel the shutdown
  810. */
  811. api->timer_add_duration((unsigned long long)shutdown_timeout*1000000000, NULL,
  812. shutdown_timer_fn, &shutdown_timer);
  813. /*
  814. * Tell the users we would like to shut down
  815. */
  816. send_test_shutdown(NULL, conn, CS_OK);
  817. }
  818. /*
  819. * We don't sent a reply to the caller here.
  820. * We send it when we know if we can shut down or not
  821. */
  822. LEAVE();
  823. }
  824. static void message_handler_req_lib_cfg_replytoshutdown (
  825. void *conn,
  826. const void *msg)
  827. {
  828. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  829. const struct req_lib_cfg_replytoshutdown *req_lib_cfg_replytoshutdown = msg;
  830. struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
  831. int status = CS_OK;
  832. ENTER();
  833. if (!shutdown_con) {
  834. status = CS_ERR_ACCESS;
  835. goto exit_fn;
  836. }
  837. if (req_lib_cfg_replytoshutdown->response) {
  838. shutdown_yes++;
  839. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  840. }
  841. else {
  842. shutdown_no++;
  843. ci->shutdown_reply = SHUTDOWN_REPLY_NO;
  844. }
  845. check_shutdown_status();
  846. exit_fn:
  847. res_lib_cfg_replytoshutdown.header.error = status;
  848. res_lib_cfg_replytoshutdown.header.id = MESSAGE_RES_CFG_REPLYTOSHUTDOWN;
  849. res_lib_cfg_replytoshutdown.header.size = sizeof(res_lib_cfg_replytoshutdown);
  850. api->ipc_response_send(conn, &res_lib_cfg_replytoshutdown,
  851. sizeof(res_lib_cfg_replytoshutdown));
  852. LEAVE();
  853. }
  854. static void message_handler_req_lib_cfg_get_node_addrs (void *conn,
  855. const void *msg)
  856. {
  857. struct totem_ip_address node_ifs[INTERFACE_MAX];
  858. unsigned int iface_ids[INTERFACE_MAX];
  859. char buf[PIPE_BUF];
  860. char **status;
  861. unsigned int num_interfaces = 0;
  862. struct sockaddr_storage *ss;
  863. int ret = CS_OK;
  864. int i;
  865. int live_addrs = 0;
  866. const struct req_lib_cfg_get_node_addrs *req_lib_cfg_get_node_addrs = msg;
  867. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)buf;
  868. unsigned int nodeid = req_lib_cfg_get_node_addrs->nodeid;
  869. char *addr_buf;
  870. if (nodeid == 0)
  871. nodeid = api->totem_nodeid_get();
  872. if (api->totem_ifaces_get(nodeid, iface_ids, node_ifs, INTERFACE_MAX, &status, &num_interfaces)) {
  873. ret = CS_ERR_EXIST;
  874. num_interfaces = 0;
  875. }
  876. res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
  877. res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
  878. res_lib_cfg_get_node_addrs->header.error = ret;
  879. if (num_interfaces) {
  880. res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
  881. for (i = 0, addr_buf = (char *)res_lib_cfg_get_node_addrs->addrs;
  882. i < num_interfaces; i++) {
  883. ss = (struct sockaddr_storage *)&node_ifs[i].addr;
  884. if (ss->ss_family) {
  885. memcpy(addr_buf, node_ifs[i].addr, TOTEMIP_ADDRLEN);
  886. live_addrs++;
  887. addr_buf += TOTEMIP_ADDRLEN;
  888. }
  889. }
  890. res_lib_cfg_get_node_addrs->num_addrs = live_addrs;
  891. } else {
  892. res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
  893. }
  894. api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
  895. }
  896. static void message_handler_req_lib_cfg_local_get (void *conn, const void *msg)
  897. {
  898. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  899. res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
  900. res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
  901. res_lib_cfg_local_get.header.error = CS_OK;
  902. res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
  903. api->ipc_response_send(conn, &res_lib_cfg_local_get,
  904. sizeof(res_lib_cfg_local_get));
  905. }
  906. static void message_handler_req_lib_cfg_reload_config (void *conn, const void *msg)
  907. {
  908. struct req_exec_cfg_reload_config req_exec_cfg_reload_config;
  909. struct iovec iovec;
  910. ENTER();
  911. req_exec_cfg_reload_config.header.size =
  912. sizeof (struct req_exec_cfg_reload_config);
  913. req_exec_cfg_reload_config.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  914. MESSAGE_REQ_EXEC_CFG_RELOAD_CONFIG);
  915. api->ipc_source_set (&req_exec_cfg_reload_config.source, conn);
  916. api->ipc_refcnt_inc(conn);
  917. iovec.iov_base = (char *)&req_exec_cfg_reload_config;
  918. iovec.iov_len = sizeof (struct req_exec_cfg_reload_config);
  919. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  920. LEAVE();
  921. }
  922. static void message_handler_req_lib_cfg_reopen_log_files (void *conn, const void *msg)
  923. {
  924. struct res_lib_cfg_reopen_log_files res_lib_cfg_reopen_log_files;
  925. cs_error_t res;
  926. ENTER();
  927. log_printf(LOGSYS_LEVEL_DEBUG, "Reopening logging files\n");
  928. res = logsys_reopen_log_files();
  929. res_lib_cfg_reopen_log_files.header.size = sizeof(res_lib_cfg_reopen_log_files);
  930. res_lib_cfg_reopen_log_files.header.id = MESSAGE_RES_CFG_REOPEN_LOG_FILES;
  931. res_lib_cfg_reopen_log_files.header.error = res;
  932. api->ipc_response_send(conn,
  933. &res_lib_cfg_reopen_log_files,
  934. sizeof(res_lib_cfg_reopen_log_files));
  935. LEAVE();
  936. }