cfg.c 40 KB

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