4
0

cfg.c 44 KB

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