cfg.c 30 KB

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