4
0

cfg.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  1. /*
  2. * Copyright (c) 2005-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2018 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <config.h>
  36. #include <sys/types.h>
  37. #include <sys/uio.h>
  38. #include <sys/socket.h>
  39. #include <sys/un.h>
  40. #include <netinet/in.h>
  41. #include <arpa/inet.h>
  42. #include <unistd.h>
  43. #include <fcntl.h>
  44. #include <stdlib.h>
  45. #include <stdio.h>
  46. #include <stddef.h>
  47. #include <limits.h>
  48. #include <errno.h>
  49. #include <string.h>
  50. #include <assert.h>
  51. #include <corosync/corotypes.h>
  52. #include <qb/qbipc_common.h>
  53. #include <corosync/cfg.h>
  54. #include <qb/qblist.h>
  55. #include <corosync/mar_gen.h>
  56. #include <corosync/totem/totemip.h>
  57. #include <corosync/totem/totem.h>
  58. #include <corosync/ipc_cfg.h>
  59. #include <corosync/logsys.h>
  60. #include <corosync/coroapi.h>
  61. #include <corosync/icmap.h>
  62. #include <corosync/corodefs.h>
  63. #include "totemconfig.h"
  64. #include "service.h"
  65. #include "main.h"
  66. LOGSYS_DECLARE_SUBSYS ("CFG");
  67. enum cfg_message_req_types {
  68. MESSAGE_REQ_EXEC_CFG_RINGREENABLE = 0,
  69. MESSAGE_REQ_EXEC_CFG_KILLNODE = 1,
  70. MESSAGE_REQ_EXEC_CFG_SHUTDOWN = 2,
  71. MESSAGE_REQ_EXEC_CFG_RELOAD_CONFIG = 3,
  72. MESSAGE_REQ_EXEC_CFG_CRYPTO_RECONFIG = 4
  73. };
  74. #define DEFAULT_SHUTDOWN_TIMEOUT 5
  75. static struct qb_list_head trackers_list;
  76. /*
  77. * Variables controlling a requested shutdown
  78. */
  79. static corosync_timer_handle_t shutdown_timer;
  80. static struct cfg_info *shutdown_con;
  81. static uint32_t shutdown_flags;
  82. static int shutdown_yes;
  83. static int shutdown_no;
  84. static int shutdown_expected;
  85. struct cfg_info
  86. {
  87. struct qb_list_head list;
  88. void *conn;
  89. void *tracker_conn;
  90. enum {SHUTDOWN_REPLY_UNKNOWN, SHUTDOWN_REPLY_YES, SHUTDOWN_REPLY_NO} shutdown_reply;
  91. };
  92. static void cfg_confchg_fn (
  93. enum totem_configuration_type configuration_type,
  94. const unsigned int *member_list, size_t member_list_entries,
  95. const unsigned int *left_list, size_t left_list_entries,
  96. const unsigned int *joined_list, size_t joined_list_entries,
  97. const struct memb_ring_id *ring_id);
  98. static char *cfg_exec_init_fn (struct corosync_api_v1 *corosync_api_v1);
  99. static struct corosync_api_v1 *api;
  100. static int cfg_lib_init_fn (void *conn);
  101. static int cfg_lib_exit_fn (void *conn);
  102. static void message_handler_req_exec_cfg_ringreenable (
  103. const void *message,
  104. unsigned int nodeid);
  105. static void message_handler_req_exec_cfg_killnode (
  106. const void *message,
  107. unsigned int nodeid);
  108. static void message_handler_req_exec_cfg_shutdown (
  109. const void *message,
  110. unsigned int nodeid);
  111. static void message_handler_req_exec_cfg_reload_config (
  112. const void *message,
  113. unsigned int nodeid);
  114. static void message_handler_req_exec_cfg_reconfig_crypto (
  115. const void *message,
  116. unsigned int nodeid);
  117. static void exec_cfg_killnode_endian_convert (void *msg);
  118. static void message_handler_req_lib_cfg_ringstatusget (
  119. void *conn,
  120. const void *msg);
  121. static void message_handler_req_lib_cfg_ringreenable (
  122. void *conn,
  123. const void *msg);
  124. static void message_handler_req_lib_cfg_killnode (
  125. void *conn,
  126. const void *msg);
  127. static void message_handler_req_lib_cfg_tryshutdown (
  128. void *conn,
  129. const void *msg);
  130. static void message_handler_req_lib_cfg_replytoshutdown (
  131. void *conn,
  132. const void *msg);
  133. static void message_handler_req_lib_cfg_get_node_addrs (
  134. void *conn,
  135. const void *msg);
  136. static void message_handler_req_lib_cfg_local_get (
  137. void *conn,
  138. const void *msg);
  139. static void message_handler_req_lib_cfg_reload_config (
  140. void *conn,
  141. const void *msg);
  142. static void message_handler_req_lib_cfg_reopen_log_files (
  143. void *conn,
  144. const void *msg);
  145. /*
  146. * Service Handler Definition
  147. */
  148. static struct corosync_lib_handler cfg_lib_engine[] =
  149. {
  150. { /* 0 */
  151. .lib_handler_fn = message_handler_req_lib_cfg_ringstatusget,
  152. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  153. },
  154. { /* 1 */
  155. .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
  156. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  157. },
  158. { /* 2 */
  159. .lib_handler_fn = message_handler_req_lib_cfg_killnode,
  160. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  161. },
  162. { /* 3 */
  163. .lib_handler_fn = message_handler_req_lib_cfg_tryshutdown,
  164. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  165. },
  166. { /* 4 */
  167. .lib_handler_fn = message_handler_req_lib_cfg_replytoshutdown,
  168. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  169. },
  170. { /* 5 */
  171. .lib_handler_fn = message_handler_req_lib_cfg_get_node_addrs,
  172. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  173. },
  174. { /* 6 */
  175. .lib_handler_fn = message_handler_req_lib_cfg_local_get,
  176. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  177. },
  178. { /* 7 */
  179. .lib_handler_fn = message_handler_req_lib_cfg_reload_config,
  180. .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED
  181. },
  182. { /* 8 */
  183. .lib_handler_fn = message_handler_req_lib_cfg_reopen_log_files,
  184. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
  185. }
  186. };
  187. static struct corosync_exec_handler cfg_exec_engine[] =
  188. {
  189. { /* 0 */
  190. .exec_handler_fn = message_handler_req_exec_cfg_ringreenable,
  191. },
  192. { /* 1 */
  193. .exec_handler_fn = message_handler_req_exec_cfg_killnode,
  194. .exec_endian_convert_fn = exec_cfg_killnode_endian_convert
  195. },
  196. { /* 2 */
  197. .exec_handler_fn = message_handler_req_exec_cfg_shutdown,
  198. },
  199. { /* 3 */
  200. .exec_handler_fn = message_handler_req_exec_cfg_reload_config,
  201. },
  202. { /* 4 */
  203. .exec_handler_fn = message_handler_req_exec_cfg_reconfig_crypto,
  204. }
  205. };
  206. /*
  207. * Exports the interface for the service
  208. */
  209. struct corosync_service_engine cfg_service_engine = {
  210. .name = "corosync configuration service",
  211. .id = CFG_SERVICE,
  212. .priority = 1,
  213. .private_data_size = sizeof(struct cfg_info),
  214. .flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED,
  215. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  216. .lib_init_fn = cfg_lib_init_fn,
  217. .lib_exit_fn = cfg_lib_exit_fn,
  218. .lib_engine = cfg_lib_engine,
  219. .lib_engine_count = sizeof (cfg_lib_engine) / sizeof (struct corosync_lib_handler),
  220. .exec_init_fn = cfg_exec_init_fn,
  221. .exec_engine = cfg_exec_engine,
  222. .exec_engine_count = sizeof (cfg_exec_engine) / sizeof (struct corosync_exec_handler),
  223. .confchg_fn = cfg_confchg_fn
  224. };
  225. struct corosync_service_engine *cfg_get_service_engine_ver0 (void)
  226. {
  227. return (&cfg_service_engine);
  228. }
  229. struct req_exec_cfg_ringreenable {
  230. struct qb_ipc_request_header header __attribute__((aligned(8)));
  231. mar_message_source_t source __attribute__((aligned(8)));
  232. };
  233. struct req_exec_cfg_reload_config {
  234. struct qb_ipc_request_header header __attribute__((aligned(8)));
  235. mar_message_source_t source __attribute__((aligned(8)));
  236. };
  237. struct req_exec_cfg_crypto_reconfig {
  238. struct qb_ipc_request_header header __attribute__((aligned(8)));
  239. mar_uint32_t phase __attribute__((aligned(8)));
  240. };
  241. struct req_exec_cfg_killnode {
  242. struct qb_ipc_request_header header __attribute__((aligned(8)));
  243. mar_uint32_t nodeid __attribute__((aligned(8)));
  244. mar_name_t reason __attribute__((aligned(8)));
  245. };
  246. struct req_exec_cfg_shutdown {
  247. struct qb_ipc_request_header header __attribute__((aligned(8)));
  248. };
  249. /* IMPL */
  250. static char *cfg_exec_init_fn (
  251. struct corosync_api_v1 *corosync_api_v1)
  252. {
  253. api = corosync_api_v1;
  254. qb_list_init(&trackers_list);
  255. return (NULL);
  256. }
  257. static void cfg_confchg_fn (
  258. enum totem_configuration_type configuration_type,
  259. const unsigned int *member_list, size_t member_list_entries,
  260. const unsigned int *left_list, size_t left_list_entries,
  261. const unsigned int *joined_list, size_t joined_list_entries,
  262. const struct memb_ring_id *ring_id)
  263. {
  264. }
  265. /*
  266. * Tell other nodes we are shutting down
  267. */
  268. static int send_shutdown(void)
  269. {
  270. struct req_exec_cfg_shutdown req_exec_cfg_shutdown;
  271. struct iovec iovec;
  272. ENTER();
  273. req_exec_cfg_shutdown.header.size =
  274. sizeof (struct req_exec_cfg_shutdown);
  275. req_exec_cfg_shutdown.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  276. MESSAGE_REQ_EXEC_CFG_SHUTDOWN);
  277. iovec.iov_base = (char *)&req_exec_cfg_shutdown;
  278. iovec.iov_len = sizeof (struct req_exec_cfg_shutdown);
  279. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  280. LEAVE();
  281. return 0;
  282. }
  283. static void send_test_shutdown(void *only_conn, void *exclude_conn, int status)
  284. {
  285. struct res_lib_cfg_testshutdown res_lib_cfg_testshutdown;
  286. struct qb_list_head *iter;
  287. ENTER();
  288. res_lib_cfg_testshutdown.header.size = sizeof(struct res_lib_cfg_testshutdown);
  289. res_lib_cfg_testshutdown.header.id = MESSAGE_RES_CFG_TESTSHUTDOWN;
  290. res_lib_cfg_testshutdown.header.error = status;
  291. res_lib_cfg_testshutdown.flags = shutdown_flags;
  292. if (only_conn) {
  293. TRACE1("sending testshutdown to only %p", only_conn);
  294. api->ipc_dispatch_send(only_conn, &res_lib_cfg_testshutdown,
  295. sizeof(res_lib_cfg_testshutdown));
  296. } else {
  297. qb_list_for_each(iter, &trackers_list) {
  298. struct cfg_info *ci = qb_list_entry(iter, struct cfg_info, list);
  299. if (ci->conn != exclude_conn) {
  300. TRACE1("sending testshutdown to %p", ci->tracker_conn);
  301. api->ipc_dispatch_send(ci->tracker_conn, &res_lib_cfg_testshutdown,
  302. sizeof(res_lib_cfg_testshutdown));
  303. }
  304. }
  305. }
  306. LEAVE();
  307. }
  308. static void check_shutdown_status(void)
  309. {
  310. ENTER();
  311. /*
  312. * Shutdown client might have gone away
  313. */
  314. if (!shutdown_con) {
  315. LEAVE();
  316. return;
  317. }
  318. /*
  319. * All replies safely gathered in ?
  320. */
  321. if (shutdown_yes + shutdown_no >= shutdown_expected) {
  322. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  323. api->timer_delete(shutdown_timer);
  324. if (shutdown_yes >= shutdown_expected ||
  325. shutdown_flags == CFG_SHUTDOWN_FLAG_REGARDLESS) {
  326. TRACE1("shutdown confirmed");
  327. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  328. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  329. res_lib_cfg_tryshutdown.header.error = CS_OK;
  330. /*
  331. * Tell originator that shutdown was confirmed
  332. */
  333. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  334. sizeof(res_lib_cfg_tryshutdown));
  335. shutdown_con = NULL;
  336. /*
  337. * Tell other nodes we are going down
  338. */
  339. send_shutdown();
  340. }
  341. else {
  342. TRACE1("shutdown cancelled");
  343. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  344. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  345. res_lib_cfg_tryshutdown.header.error = CS_ERR_BUSY;
  346. /*
  347. * Tell originator that shutdown was cancelled
  348. */
  349. api->ipc_response_send(shutdown_con->conn, &res_lib_cfg_tryshutdown,
  350. sizeof(res_lib_cfg_tryshutdown));
  351. shutdown_con = NULL;
  352. }
  353. log_printf(LOGSYS_LEVEL_DEBUG, "shutdown decision is: (yes count: %d, no count: %d) flags=%x",
  354. shutdown_yes, shutdown_no, shutdown_flags);
  355. }
  356. LEAVE();
  357. }
  358. /*
  359. * Not all nodes responded to the shutdown (in time)
  360. */
  361. static void shutdown_timer_fn(void *arg)
  362. {
  363. ENTER();
  364. /*
  365. * Mark undecideds as "NO"
  366. */
  367. shutdown_no = shutdown_expected;
  368. check_shutdown_status();
  369. send_test_shutdown(NULL, NULL, CS_ERR_TIMEOUT);
  370. LEAVE();
  371. }
  372. static void remove_ci_from_shutdown(struct cfg_info *ci)
  373. {
  374. ENTER();
  375. /*
  376. * If the controlling shutdown process has quit, then cancel the
  377. * shutdown session
  378. */
  379. if (ci == shutdown_con) {
  380. shutdown_con = NULL;
  381. api->timer_delete(shutdown_timer);
  382. }
  383. if (!qb_list_empty(&ci->list)) {
  384. qb_list_del(&ci->list);
  385. qb_list_init(&ci->list);
  386. /*
  387. * Remove our option
  388. */
  389. if (shutdown_con) {
  390. if (ci->shutdown_reply == SHUTDOWN_REPLY_YES)
  391. shutdown_yes--;
  392. if (ci->shutdown_reply == SHUTDOWN_REPLY_NO)
  393. shutdown_no--;
  394. }
  395. /*
  396. * If we are leaving, then that's an implicit YES to shutdown
  397. */
  398. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  399. shutdown_yes++;
  400. check_shutdown_status();
  401. }
  402. LEAVE();
  403. }
  404. int cfg_lib_exit_fn (void *conn)
  405. {
  406. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  407. ENTER();
  408. remove_ci_from_shutdown(ci);
  409. LEAVE();
  410. return (0);
  411. }
  412. static int cfg_lib_init_fn (void *conn)
  413. {
  414. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  415. ENTER();
  416. qb_list_init(&ci->list);
  417. LEAVE();
  418. return (0);
  419. }
  420. /*
  421. * Executive message handlers
  422. */
  423. static void message_handler_req_exec_cfg_ringreenable (
  424. const void *message,
  425. unsigned int nodeid)
  426. {
  427. ENTER();
  428. LEAVE();
  429. }
  430. static void exec_cfg_killnode_endian_convert (void *msg)
  431. {
  432. struct req_exec_cfg_killnode *req_exec_cfg_killnode =
  433. (struct req_exec_cfg_killnode *)msg;
  434. ENTER();
  435. swab_mar_name_t(&req_exec_cfg_killnode->reason);
  436. LEAVE();
  437. }
  438. static void message_handler_req_exec_cfg_killnode (
  439. const void *message,
  440. unsigned int nodeid)
  441. {
  442. const struct req_exec_cfg_killnode *req_exec_cfg_killnode = message;
  443. cs_name_t reason;
  444. ENTER();
  445. log_printf(LOGSYS_LEVEL_DEBUG, "request to kill node " CS_PRI_NODE_ID " (us=" CS_PRI_NODE_ID ")",
  446. req_exec_cfg_killnode->nodeid, api->totem_nodeid_get());
  447. if (req_exec_cfg_killnode->nodeid == api->totem_nodeid_get()) {
  448. marshall_from_mar_name_t(&reason, &req_exec_cfg_killnode->reason);
  449. log_printf(LOGSYS_LEVEL_NOTICE, "Killed by node " CS_PRI_NODE_ID " : %s",
  450. nodeid, reason.value);
  451. corosync_fatal_error(COROSYNC_FATAL_ERROR_EXIT);
  452. }
  453. LEAVE();
  454. }
  455. /*
  456. * Self shutdown
  457. */
  458. static void message_handler_req_exec_cfg_shutdown (
  459. const void *message,
  460. unsigned int nodeid)
  461. {
  462. ENTER();
  463. log_printf(LOGSYS_LEVEL_NOTICE, "Node " CS_PRI_NODE_ID " was shut down by sysadmin", nodeid);
  464. if (nodeid == api->totem_nodeid_get()) {
  465. api->shutdown_request();
  466. }
  467. LEAVE();
  468. }
  469. /* strcmp replacement that can handle NULLs */
  470. static int nullcheck_strcmp(const char* left, const char *right)
  471. {
  472. if (!left && right)
  473. return -1;
  474. if (left && !right)
  475. return 1;
  476. if (!left && !right)
  477. return 0;
  478. return strcmp(left, right);
  479. }
  480. /*
  481. * If a key has changed value in the new file, then warn the user and remove it from the temp_map
  482. */
  483. static void delete_and_notify_if_changed(icmap_map_t temp_map, const char *key_name)
  484. {
  485. if (!(icmap_key_value_eq(temp_map, key_name, icmap_get_global_map(), key_name))) {
  486. if (icmap_delete_r(temp_map, key_name) == CS_OK) {
  487. log_printf(LOGSYS_LEVEL_NOTICE, "Modified entry '%s' in corosync.conf cannot be changed at run-time", key_name);
  488. }
  489. }
  490. }
  491. /*
  492. * Remove any keys from the new config file that in the new corosync.conf but that
  493. * cannot be changed at run time. A log message will be issued for each
  494. * entry that the user wants to change but they cannot.
  495. *
  496. * Add more here as needed.
  497. */
  498. static void remove_ro_entries(icmap_map_t temp_map)
  499. {
  500. #ifndef HAVE_KNET_CRYPTO_RECONF
  501. delete_and_notify_if_changed(temp_map, "totem.secauth");
  502. delete_and_notify_if_changed(temp_map, "totem.crypto_hash");
  503. delete_and_notify_if_changed(temp_map, "totem.crypto_cipher");
  504. delete_and_notify_if_changed(temp_map, "totem.keyfile");
  505. delete_and_notify_if_changed(temp_map, "totem.key");
  506. #endif
  507. delete_and_notify_if_changed(temp_map, "totem.version");
  508. delete_and_notify_if_changed(temp_map, "totem.threads");
  509. delete_and_notify_if_changed(temp_map, "totem.ip_version");
  510. delete_and_notify_if_changed(temp_map, "totem.rrp_mode");
  511. delete_and_notify_if_changed(temp_map, "totem.netmtu");
  512. delete_and_notify_if_changed(temp_map, "totem.interface.ringnumber");
  513. delete_and_notify_if_changed(temp_map, "totem.interface.bindnetaddr");
  514. delete_and_notify_if_changed(temp_map, "totem.interface.mcastaddr");
  515. delete_and_notify_if_changed(temp_map, "totem.interface.broadcast");
  516. delete_and_notify_if_changed(temp_map, "totem.interface.mcastport");
  517. delete_and_notify_if_changed(temp_map, "totem.interface.ttl");
  518. delete_and_notify_if_changed(temp_map, "totem.transport");
  519. delete_and_notify_if_changed(temp_map, "totem.cluster_name");
  520. delete_and_notify_if_changed(temp_map, "quorum.provider");
  521. delete_and_notify_if_changed(temp_map, "system.move_to_root_cgroup");
  522. delete_and_notify_if_changed(temp_map, "system.sched_rr");
  523. delete_and_notify_if_changed(temp_map, "system.priority");
  524. delete_and_notify_if_changed(temp_map, "system.qb_ipc_type");
  525. delete_and_notify_if_changed(temp_map, "system.state_dir");
  526. }
  527. /*
  528. * Remove entries that exist in the global map, but not in the temp_map, this will
  529. * cause delete notifications to be sent to any listeners.
  530. *
  531. * NOTE: This routine depends entirely on the keys returned by the iterators
  532. * being in alpha-sorted order.
  533. */
  534. static void remove_deleted_entries(icmap_map_t temp_map, const char *prefix)
  535. {
  536. icmap_iter_t old_iter;
  537. icmap_iter_t new_iter;
  538. const char *old_key, *new_key;
  539. int ret;
  540. old_iter = icmap_iter_init(prefix);
  541. new_iter = icmap_iter_init_r(temp_map, prefix);
  542. old_key = icmap_iter_next(old_iter, NULL, NULL);
  543. new_key = icmap_iter_next(new_iter, NULL, NULL);
  544. while (old_key || new_key) {
  545. ret = nullcheck_strcmp(old_key, new_key);
  546. if ((ret < 0 && old_key) || !new_key) {
  547. /*
  548. * new_key is greater, a line (or more) has been deleted
  549. * Continue until old is >= new
  550. */
  551. do {
  552. /* Remove it from icmap & send notifications */
  553. icmap_delete(old_key);
  554. old_key = icmap_iter_next(old_iter, NULL, NULL);
  555. ret = nullcheck_strcmp(old_key, new_key);
  556. } while (ret < 0 && old_key);
  557. }
  558. else if ((ret > 0 && new_key) || !old_key) {
  559. /*
  560. * old_key is greater, a line (or more) has been added
  561. * Continue until new is >= old
  562. *
  563. * we don't need to do anything special with this like tell
  564. * icmap. That will happen when we copy the values over
  565. */
  566. do {
  567. new_key = icmap_iter_next(new_iter, NULL, NULL);
  568. ret = nullcheck_strcmp(old_key, new_key);
  569. } while (ret > 0 && new_key);
  570. }
  571. if (ret == 0) {
  572. new_key = icmap_iter_next(new_iter, NULL, NULL);
  573. old_key = icmap_iter_next(old_iter, NULL, NULL);
  574. }
  575. }
  576. icmap_iter_finalize(new_iter);
  577. icmap_iter_finalize(old_iter);
  578. }
  579. /*
  580. * Reload configuration file
  581. */
  582. static void message_handler_req_exec_cfg_reload_config (
  583. const void *message,
  584. unsigned int nodeid)
  585. {
  586. const struct req_exec_cfg_reload_config *req_exec_cfg_reload_config = message;
  587. struct res_lib_cfg_reload_config res_lib_cfg_reload_config;
  588. struct totem_config new_config;
  589. icmap_map_t temp_map;
  590. const char *error_string;
  591. int res = CS_OK;
  592. ENTER();
  593. log_printf(LOGSYS_LEVEL_NOTICE, "Config reload requested by node " CS_PRI_NODE_ID, nodeid);
  594. icmap_set_uint8("config.totemconfig_reload_in_progress", 1);
  595. /* Make sure there is no rubbish in this that might be checked, even on error */
  596. memset(&new_config, 0, sizeof(new_config));
  597. /*
  598. * Set up a new hashtable as a staging area.
  599. */
  600. if ((res = icmap_init_r(&temp_map)) != CS_OK) {
  601. log_printf(LOGSYS_LEVEL_ERROR, "Unable to create temporary icmap. config file reload cancelled\n");
  602. goto reload_fini_nomap;
  603. }
  604. /*
  605. * Load new config into the temporary map
  606. */
  607. res = coroparse_configparse(temp_map, &error_string);
  608. if (res == -1) {
  609. log_printf (LOGSYS_LEVEL_ERROR, "Unable to reload config file: %s", error_string);
  610. res = CS_ERR_INVALID_PARAM;
  611. goto reload_fini_nofree;
  612. }
  613. /* Signal start of the reload process */
  614. icmap_set_uint8("config.reload_in_progress", 1);
  615. /* Detect deleted entries and remove them from the main icmap hashtable */
  616. remove_deleted_entries(temp_map, "logging.");
  617. remove_deleted_entries(temp_map, "totem.");
  618. remove_deleted_entries(temp_map, "nodelist.");
  619. remove_deleted_entries(temp_map, "quorum.");
  620. remove_deleted_entries(temp_map, "uidgid.config.");
  621. remove_deleted_entries(temp_map, "nozzle.");
  622. /* Remove entries that cannot be changed */
  623. remove_ro_entries(temp_map);
  624. /* Take a copy of the current setup so we can check what has changed */
  625. memset(&new_config, 0, sizeof(new_config));
  626. new_config.orig_interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
  627. assert(new_config.orig_interfaces != NULL);
  628. totempg_get_config(&new_config);
  629. new_config.crypto_changed = 0;
  630. new_config.interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
  631. assert(new_config.interfaces != NULL);
  632. memset(new_config.interfaces, 0, sizeof (struct totem_interface) * INTERFACE_MAX);
  633. /* For UDP[U] the configuration on link0 is static (apart from the nodelist) and only read at
  634. startup. So preserve it here */
  635. if ( (new_config.transport_number == TOTEM_TRANSPORT_UDP) ||
  636. (new_config.transport_number == TOTEM_TRANSPORT_UDPU)) {
  637. memcpy(&new_config.interfaces[0], &new_config.orig_interfaces[0],
  638. sizeof(struct totem_interface));
  639. }
  640. /* Calculate new node and interface definitions */
  641. if (totemconfig_configure_new_params(&new_config, temp_map, &error_string) == -1) {
  642. log_printf (LOGSYS_LEVEL_ERROR, "Cannot configure new interface definitions: %s\n", error_string);
  643. res = CS_ERR_INVALID_PARAM;
  644. goto reload_fini;
  645. }
  646. /* Read from temp_map into new_config */
  647. totem_volatile_config_read(&new_config, temp_map, NULL);
  648. /* Get updated crypto parameters. Will set a flag in new_config if things have changed */
  649. if (totem_reread_crypto_config(&new_config, temp_map, &error_string) == -1) {
  650. log_printf (LOGSYS_LEVEL_ERROR, "Crypto configuration is not valid: %s\n", error_string);
  651. res = CS_ERR_INVALID_PARAM;
  652. goto reload_fini;
  653. }
  654. /* Validate dynamic parameters */
  655. if (totem_volatile_config_validate(&new_config, temp_map, &error_string) == -1) {
  656. log_printf (LOGSYS_LEVEL_ERROR, "Configuration is not valid: %s\n", error_string);
  657. res = CS_ERR_INVALID_PARAM;
  658. goto reload_fini;
  659. }
  660. /* Save this here so we can get at it for the later phases of crypto change */
  661. if (new_config.crypto_changed) {
  662. #ifndef HAVE_KNET_CRYPTO_RECONF
  663. new_config.crypto_changed = 0;
  664. log_printf (LOGSYS_LEVEL_ERROR, "Crypto reconfiguration is not supported by the linked version of knet\n");
  665. res = CS_ERR_INVALID_PARAM;
  666. goto reload_fini;
  667. #endif
  668. }
  669. /*
  670. * Copy new keys into live config.
  671. */
  672. if ( (res = icmap_copy_map(icmap_get_global_map(), temp_map)) != CS_OK) {
  673. log_printf (LOGSYS_LEVEL_ERROR, "Error making new config live. cmap database may be inconsistent\n");
  674. /* Return res from icmap */
  675. goto reload_fini;
  676. }
  677. /* Copy into live system */
  678. totempg_put_config(&new_config);
  679. totemconfig_commit_new_params(&new_config, temp_map);
  680. free(new_config.interfaces);
  681. reload_fini:
  682. /* All done - let clients know */
  683. icmap_set_int32("config.reload_status", res);
  684. icmap_set_uint8("config.totemconfig_reload_in_progress", 0);
  685. icmap_set_uint8("config.reload_in_progress", 0);
  686. /* Finished with the temporary storage */
  687. free(new_config.orig_interfaces);
  688. reload_fini_nofree:
  689. icmap_fini_r(temp_map);
  690. reload_fini_nomap:
  691. /* If crypto was changed, now it's loaded on all nodes we can enable it.
  692. * Each node sends its own PHASE message so we're not relying on the leader
  693. * node to survive the transition
  694. */
  695. if (new_config.crypto_changed) {
  696. struct req_exec_cfg_crypto_reconfig req_exec_cfg_crypto_reconfig;
  697. struct iovec iovec;
  698. req_exec_cfg_crypto_reconfig.header.size =
  699. sizeof (struct req_exec_cfg_crypto_reconfig);
  700. req_exec_cfg_crypto_reconfig.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  701. MESSAGE_REQ_EXEC_CFG_CRYPTO_RECONFIG);
  702. req_exec_cfg_crypto_reconfig.phase = CRYPTO_RECONFIG_PHASE_ACTIVATE;
  703. iovec.iov_base = (char *)&req_exec_cfg_crypto_reconfig;
  704. iovec.iov_len = sizeof (struct req_exec_cfg_crypto_reconfig);
  705. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  706. }
  707. /* All done, return result to the caller if it was on this system */
  708. if (nodeid == api->totem_nodeid_get()) {
  709. res_lib_cfg_reload_config.header.size = sizeof(res_lib_cfg_reload_config);
  710. res_lib_cfg_reload_config.header.id = MESSAGE_RES_CFG_RELOAD_CONFIG;
  711. res_lib_cfg_reload_config.header.error = res;
  712. api->ipc_response_send(req_exec_cfg_reload_config->source.conn,
  713. &res_lib_cfg_reload_config,
  714. sizeof(res_lib_cfg_reload_config));
  715. api->ipc_refcnt_dec(req_exec_cfg_reload_config->source.conn);;
  716. }
  717. LEAVE();
  718. }
  719. /* Handle the phases of crypto reload
  720. * The first time we are called is after the new crypto config has been loaded
  721. * but not activated.
  722. *
  723. * 1 - activate the new crypto configuration
  724. * 2 - clear out the old configuration
  725. */
  726. static void message_handler_req_exec_cfg_reconfig_crypto (
  727. const void *message,
  728. unsigned int nodeid)
  729. {
  730. const struct req_exec_cfg_crypto_reconfig *req_exec_cfg_crypto_reconfig = message;
  731. /* Got our own reconfig message */
  732. if (nodeid == api->totem_nodeid_get()) {
  733. log_printf (LOGSYS_LEVEL_DEBUG, "Crypto reconfiguration phase %d", req_exec_cfg_crypto_reconfig->phase);
  734. /* Do the deed */
  735. totempg_crypto_reconfigure_phase(req_exec_cfg_crypto_reconfig->phase);
  736. /* Move to the next phase if not finished */
  737. if (req_exec_cfg_crypto_reconfig->phase < CRYPTO_RECONFIG_PHASE_CLEANUP) {
  738. struct req_exec_cfg_crypto_reconfig req_exec_cfg_crypto_reconfig2;
  739. struct iovec iovec;
  740. req_exec_cfg_crypto_reconfig2.header.size =
  741. sizeof (struct req_exec_cfg_crypto_reconfig);
  742. req_exec_cfg_crypto_reconfig2.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  743. MESSAGE_REQ_EXEC_CFG_CRYPTO_RECONFIG);
  744. req_exec_cfg_crypto_reconfig2.phase = CRYPTO_RECONFIG_PHASE_CLEANUP;
  745. iovec.iov_base = (char *)&req_exec_cfg_crypto_reconfig2;
  746. iovec.iov_len = sizeof (struct req_exec_cfg_crypto_reconfig);
  747. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  748. }
  749. }
  750. }
  751. /*
  752. * Library Interface Implementation
  753. */
  754. static void message_handler_req_lib_cfg_ringstatusget (
  755. void *conn,
  756. const void *msg)
  757. {
  758. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  759. struct totem_ip_address interfaces[INTERFACE_MAX];
  760. unsigned int iface_count;
  761. char **status;
  762. const char *totem_ip_string;
  763. char ifname[CFG_INTERFACE_NAME_MAX_LEN];
  764. unsigned int iface_ids[INTERFACE_MAX];
  765. unsigned int i;
  766. cs_error_t res = CS_OK;
  767. ENTER();
  768. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  769. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  770. api->totem_ifaces_get (
  771. api->totem_nodeid_get(),
  772. iface_ids,
  773. interfaces,
  774. INTERFACE_MAX,
  775. &status,
  776. &iface_count);
  777. assert(iface_count <= CFG_MAX_INTERFACES);
  778. res_lib_cfg_ringstatusget.interface_count = iface_count;
  779. for (i = 0; i < iface_count; i++) {
  780. totem_ip_string
  781. = (const char *)api->totem_ip_print (&interfaces[i]);
  782. if (!totem_ip_string) {
  783. totem_ip_string="";
  784. }
  785. /* Allow for i/f number at the start */
  786. if (strlen(totem_ip_string) >= CFG_INTERFACE_NAME_MAX_LEN-3) {
  787. log_printf(LOGSYS_LEVEL_ERROR, "String representation of interface %u is too long", i);
  788. res = CS_ERR_NAME_TOO_LONG;
  789. goto send_response;
  790. }
  791. snprintf(ifname, sizeof(ifname), "%d %s", iface_ids[i], totem_ip_string);
  792. if (strlen(status[i]) >= CFG_INTERFACE_STATUS_MAX_LEN) {
  793. log_printf(LOGSYS_LEVEL_ERROR, "Status string for interface %u is too long", i);
  794. res = CS_ERR_NAME_TOO_LONG;
  795. goto send_response;
  796. }
  797. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  798. status[i]);
  799. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  800. ifname);
  801. }
  802. send_response:
  803. res_lib_cfg_ringstatusget.header.error = res;
  804. api->ipc_response_send (
  805. conn,
  806. &res_lib_cfg_ringstatusget,
  807. sizeof (struct res_lib_cfg_ringstatusget));
  808. LEAVE();
  809. }
  810. static void message_handler_req_lib_cfg_ringreenable (
  811. void *conn,
  812. const void *msg)
  813. {
  814. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  815. ENTER();
  816. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  817. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  818. res_lib_cfg_ringreenable.header.error = CS_ERR_NOT_SUPPORTED;
  819. api->ipc_response_send (
  820. conn, &res_lib_cfg_ringreenable,
  821. sizeof (struct res_lib_cfg_ringreenable));
  822. LEAVE();
  823. }
  824. static void message_handler_req_lib_cfg_killnode (
  825. void *conn,
  826. const void *msg)
  827. {
  828. const struct req_lib_cfg_killnode *req_lib_cfg_killnode = msg;
  829. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  830. struct req_exec_cfg_killnode req_exec_cfg_killnode;
  831. struct iovec iovec;
  832. char key_name[ICMAP_KEYNAME_MAXLEN];
  833. char tmp_key[ICMAP_KEYNAME_MAXLEN + 1];
  834. icmap_map_t map;
  835. icmap_iter_t iter;
  836. const char *iter_key;
  837. uint32_t nodeid;
  838. char *status_str = NULL;
  839. int match_nodeid_flag = 0;
  840. cs_error_t error = CS_OK;
  841. ENTER();
  842. map = icmap_get_global_map();
  843. iter = icmap_iter_init_r(map, "runtime.members.");
  844. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  845. if (sscanf(iter_key, "runtime.members.%u.%s", &nodeid, key_name) != 2) {
  846. continue;
  847. }
  848. if (strcmp(key_name, "status") != 0) {
  849. continue;
  850. }
  851. if (nodeid != req_lib_cfg_killnode->nodeid) {
  852. continue;
  853. }
  854. match_nodeid_flag = 1;
  855. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "runtime.members.%u.status", nodeid);
  856. if (icmap_get_string_r(map, tmp_key, &status_str) != CS_OK) {
  857. error = CS_ERR_LIBRARY;
  858. goto send_response;
  859. }
  860. if (strcmp(status_str, "joined") != 0) {
  861. error = CS_ERR_NOT_EXIST;
  862. goto send_response;
  863. }
  864. break;
  865. }
  866. if (!match_nodeid_flag) {
  867. error = CS_ERR_NOT_EXIST;
  868. goto send_response;
  869. }
  870. req_exec_cfg_killnode.header.size =
  871. sizeof (struct req_exec_cfg_killnode);
  872. req_exec_cfg_killnode.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  873. MESSAGE_REQ_EXEC_CFG_KILLNODE);
  874. req_exec_cfg_killnode.nodeid = req_lib_cfg_killnode->nodeid;
  875. marshall_to_mar_name_t(&req_exec_cfg_killnode.reason, &req_lib_cfg_killnode->reason);
  876. iovec.iov_base = (char *)&req_exec_cfg_killnode;
  877. iovec.iov_len = sizeof (struct req_exec_cfg_killnode);
  878. (void)api->totem_mcast (&iovec, 1, TOTEM_SAFE);
  879. send_response:
  880. res_lib_cfg_killnode.header.size = sizeof(struct res_lib_cfg_killnode);
  881. res_lib_cfg_killnode.header.id = MESSAGE_RES_CFG_KILLNODE;
  882. res_lib_cfg_killnode.header.error = error;
  883. api->ipc_response_send(conn, &res_lib_cfg_killnode,
  884. sizeof(res_lib_cfg_killnode));
  885. free(status_str);
  886. icmap_iter_finalize(iter);
  887. LEAVE();
  888. }
  889. static void message_handler_req_lib_cfg_tryshutdown (
  890. void *conn,
  891. const void *msg)
  892. {
  893. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  894. const struct req_lib_cfg_tryshutdown *req_lib_cfg_tryshutdown = msg;
  895. struct qb_list_head *iter;
  896. ENTER();
  897. if (req_lib_cfg_tryshutdown->flags == CFG_SHUTDOWN_FLAG_IMMEDIATE) {
  898. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  899. /*
  900. * Tell other nodes
  901. */
  902. send_shutdown();
  903. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  904. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  905. res_lib_cfg_tryshutdown.header.error = CS_OK;
  906. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  907. sizeof(res_lib_cfg_tryshutdown));
  908. LEAVE();
  909. return;
  910. }
  911. /*
  912. * Shutdown in progress, return an error
  913. */
  914. if (shutdown_con) {
  915. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  916. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  917. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  918. res_lib_cfg_tryshutdown.header.error = CS_ERR_EXIST;
  919. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  920. sizeof(res_lib_cfg_tryshutdown));
  921. LEAVE();
  922. return;
  923. }
  924. ci->conn = conn;
  925. shutdown_con = (struct cfg_info *)api->ipc_private_data_get (conn);
  926. shutdown_flags = req_lib_cfg_tryshutdown->flags;
  927. shutdown_yes = 0;
  928. shutdown_no = 0;
  929. /*
  930. * Count the number of listeners
  931. */
  932. shutdown_expected = 0;
  933. qb_list_for_each(iter, &trackers_list) {
  934. struct cfg_info *testci = qb_list_entry(iter, struct cfg_info, list);
  935. /*
  936. * It is assumed that we will allow shutdown
  937. */
  938. if (testci != ci) {
  939. testci->shutdown_reply = SHUTDOWN_REPLY_UNKNOWN;
  940. shutdown_expected++;
  941. }
  942. }
  943. /*
  944. * If no-one is listening for events then we can just go down now
  945. */
  946. if (shutdown_expected == 0) {
  947. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  948. res_lib_cfg_tryshutdown.header.size = sizeof(struct res_lib_cfg_tryshutdown);
  949. res_lib_cfg_tryshutdown.header.id = MESSAGE_RES_CFG_TRYSHUTDOWN;
  950. res_lib_cfg_tryshutdown.header.error = CS_OK;
  951. /*
  952. * Tell originator that shutdown was confirmed
  953. */
  954. api->ipc_response_send(conn, &res_lib_cfg_tryshutdown,
  955. sizeof(res_lib_cfg_tryshutdown));
  956. send_shutdown();
  957. LEAVE();
  958. return;
  959. }
  960. else {
  961. unsigned int shutdown_timeout = DEFAULT_SHUTDOWN_TIMEOUT;
  962. /*
  963. * Look for a shutdown timeout in configuration map
  964. */
  965. icmap_get_uint32("cfg.shutdown_timeout", &shutdown_timeout);
  966. /*
  967. * Start the timer. If we don't get a full set of replies before this goes
  968. * off we'll cancel the shutdown
  969. */
  970. api->timer_add_duration((unsigned long long)shutdown_timeout*1000000000, NULL,
  971. shutdown_timer_fn, &shutdown_timer);
  972. /*
  973. * Tell the users we would like to shut down
  974. */
  975. send_test_shutdown(NULL, conn, CS_OK);
  976. }
  977. /*
  978. * We don't sent a reply to the caller here.
  979. * We send it when we know if we can shut down or not
  980. */
  981. LEAVE();
  982. }
  983. static void message_handler_req_lib_cfg_replytoshutdown (
  984. void *conn,
  985. const void *msg)
  986. {
  987. struct cfg_info *ci = (struct cfg_info *)api->ipc_private_data_get (conn);
  988. const struct req_lib_cfg_replytoshutdown *req_lib_cfg_replytoshutdown = msg;
  989. struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
  990. int status = CS_OK;
  991. ENTER();
  992. if (!shutdown_con) {
  993. status = CS_ERR_ACCESS;
  994. goto exit_fn;
  995. }
  996. if (req_lib_cfg_replytoshutdown->response) {
  997. shutdown_yes++;
  998. ci->shutdown_reply = SHUTDOWN_REPLY_YES;
  999. }
  1000. else {
  1001. shutdown_no++;
  1002. ci->shutdown_reply = SHUTDOWN_REPLY_NO;
  1003. }
  1004. check_shutdown_status();
  1005. exit_fn:
  1006. res_lib_cfg_replytoshutdown.header.error = status;
  1007. res_lib_cfg_replytoshutdown.header.id = MESSAGE_RES_CFG_REPLYTOSHUTDOWN;
  1008. res_lib_cfg_replytoshutdown.header.size = sizeof(res_lib_cfg_replytoshutdown);
  1009. api->ipc_response_send(conn, &res_lib_cfg_replytoshutdown,
  1010. sizeof(res_lib_cfg_replytoshutdown));
  1011. LEAVE();
  1012. }
  1013. static void message_handler_req_lib_cfg_get_node_addrs (void *conn,
  1014. const void *msg)
  1015. {
  1016. struct totem_ip_address node_ifs[INTERFACE_MAX];
  1017. unsigned int iface_ids[INTERFACE_MAX];
  1018. char buf[PIPE_BUF];
  1019. char **status;
  1020. unsigned int num_interfaces = 0;
  1021. struct sockaddr_storage *ss;
  1022. int ret = CS_OK;
  1023. int i;
  1024. int live_addrs = 0;
  1025. const struct req_lib_cfg_get_node_addrs *req_lib_cfg_get_node_addrs = msg;
  1026. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)buf;
  1027. unsigned int nodeid = req_lib_cfg_get_node_addrs->nodeid;
  1028. char *addr_buf;
  1029. if (nodeid == 0)
  1030. nodeid = api->totem_nodeid_get();
  1031. if (api->totem_ifaces_get(nodeid, iface_ids, node_ifs, INTERFACE_MAX, &status, &num_interfaces)) {
  1032. ret = CS_ERR_EXIST;
  1033. num_interfaces = 0;
  1034. }
  1035. res_lib_cfg_get_node_addrs->header.size = sizeof(struct res_lib_cfg_get_node_addrs) + (num_interfaces * TOTEMIP_ADDRLEN);
  1036. res_lib_cfg_get_node_addrs->header.id = MESSAGE_RES_CFG_GET_NODE_ADDRS;
  1037. res_lib_cfg_get_node_addrs->header.error = ret;
  1038. if (num_interfaces) {
  1039. res_lib_cfg_get_node_addrs->family = node_ifs[0].family;
  1040. for (i = 0, addr_buf = (char *)res_lib_cfg_get_node_addrs->addrs;
  1041. i < num_interfaces; i++) {
  1042. ss = (struct sockaddr_storage *)&node_ifs[i].addr;
  1043. if (ss->ss_family) {
  1044. memcpy(addr_buf, node_ifs[i].addr, TOTEMIP_ADDRLEN);
  1045. live_addrs++;
  1046. addr_buf += TOTEMIP_ADDRLEN;
  1047. }
  1048. }
  1049. res_lib_cfg_get_node_addrs->num_addrs = live_addrs;
  1050. } else {
  1051. res_lib_cfg_get_node_addrs->header.error = CS_ERR_NOT_EXIST;
  1052. }
  1053. api->ipc_response_send(conn, res_lib_cfg_get_node_addrs, res_lib_cfg_get_node_addrs->header.size);
  1054. }
  1055. static void message_handler_req_lib_cfg_local_get (void *conn, const void *msg)
  1056. {
  1057. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  1058. res_lib_cfg_local_get.header.size = sizeof(res_lib_cfg_local_get);
  1059. res_lib_cfg_local_get.header.id = MESSAGE_RES_CFG_LOCAL_GET;
  1060. res_lib_cfg_local_get.header.error = CS_OK;
  1061. res_lib_cfg_local_get.local_nodeid = api->totem_nodeid_get ();
  1062. api->ipc_response_send(conn, &res_lib_cfg_local_get,
  1063. sizeof(res_lib_cfg_local_get));
  1064. }
  1065. static void message_handler_req_lib_cfg_reload_config (void *conn, const void *msg)
  1066. {
  1067. struct req_exec_cfg_reload_config req_exec_cfg_reload_config;
  1068. struct iovec iovec;
  1069. ENTER();
  1070. req_exec_cfg_reload_config.header.size =
  1071. sizeof (struct req_exec_cfg_reload_config);
  1072. req_exec_cfg_reload_config.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  1073. MESSAGE_REQ_EXEC_CFG_RELOAD_CONFIG);
  1074. api->ipc_source_set (&req_exec_cfg_reload_config.source, conn);
  1075. api->ipc_refcnt_inc(conn);
  1076. iovec.iov_base = (char *)&req_exec_cfg_reload_config;
  1077. iovec.iov_len = sizeof (struct req_exec_cfg_reload_config);
  1078. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  1079. LEAVE();
  1080. }
  1081. static void message_handler_req_lib_cfg_reopen_log_files (void *conn, const void *msg)
  1082. {
  1083. struct res_lib_cfg_reopen_log_files res_lib_cfg_reopen_log_files;
  1084. cs_error_t res;
  1085. ENTER();
  1086. log_printf(LOGSYS_LEVEL_DEBUG, "Reopening logging files\n");
  1087. res = logsys_reopen_log_files();
  1088. res_lib_cfg_reopen_log_files.header.size = sizeof(res_lib_cfg_reopen_log_files);
  1089. res_lib_cfg_reopen_log_files.header.id = MESSAGE_RES_CFG_REOPEN_LOG_FILES;
  1090. res_lib_cfg_reopen_log_files.header.error = res;
  1091. api->ipc_response_send(conn,
  1092. &res_lib_cfg_reopen_log_files,
  1093. sizeof(res_lib_cfg_reopen_log_files));
  1094. LEAVE();
  1095. }