cfg.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. /*
  2. * Copyright (c) 2005-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2008 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 <sys/types.h>
  36. #include <sys/uio.h>
  37. #include <sys/socket.h>
  38. #include <sys/un.h>
  39. #include <netinet/in.h>
  40. #include <arpa/inet.h>
  41. #include <unistd.h>
  42. #include <fcntl.h>
  43. #include <stdlib.h>
  44. #include <stdio.h>
  45. #include <errno.h>
  46. #include <signal.h>
  47. #include <string.h>
  48. #include "../include/saAis.h"
  49. #include "../include/cfg.h"
  50. #include "../include/mar_gen.h"
  51. #include "../include/ipc_gen.h"
  52. #include "../include/ipc_cfg.h"
  53. #include "../include/list.h"
  54. #include "../include/queue.h"
  55. #include "../lcr/lcr_comp.h"
  56. #include "../exec/logsys.h"
  57. #include "../include/coroapi.h"
  58. LOGSYS_DECLARE_SUBSYS ("CFG", LOG_INFO);
  59. enum cfg_message_req_types {
  60. MESSAGE_REQ_EXEC_CFG_RINGREENABLE = 0
  61. };
  62. static void cfg_confchg_fn (
  63. enum totem_configuration_type configuration_type,
  64. unsigned int *member_list, int member_list_entries,
  65. unsigned int *left_list, int left_list_entries,
  66. unsigned int *joined_list, int joined_list_entries,
  67. struct memb_ring_id *ring_id);
  68. static int cfg_exec_init_fn (struct corosync_api_v1 *corosync_api_v1);
  69. static struct corosync_api_v1 *api;
  70. static int cfg_lib_init_fn (void *conn);
  71. static int cfg_lib_exit_fn (void *conn);
  72. static void message_handler_req_exec_cfg_ringreenable (
  73. void *message,
  74. unsigned int nodeid);
  75. static void message_handler_req_lib_cfg_ringstatusget (
  76. void *conn,
  77. void *msg);
  78. static void message_handler_req_lib_cfg_ringreenable (
  79. void *conn,
  80. void *msg);
  81. static void message_handler_req_lib_cfg_statetrack (
  82. void *conn,
  83. void *msg);
  84. static void message_handler_req_lib_cfg_statetrackstop (
  85. void *conn,
  86. void *msg);
  87. static void message_handler_req_lib_cfg_administrativestateset (
  88. void *conn,
  89. void *msg);
  90. static void message_handler_req_lib_cfg_administrativestateget (
  91. void *conn,
  92. void *msg);
  93. static void message_handler_req_lib_cfg_serviceload (
  94. void *conn,
  95. void *msg);
  96. static void message_handler_req_lib_cfg_serviceunload (
  97. void *conn,
  98. void *msg);
  99. /*
  100. * Service Handler Definition
  101. */
  102. static struct corosync_lib_handler cfg_lib_engine[] =
  103. {
  104. { /* 0 */
  105. .lib_handler_fn = message_handler_req_lib_cfg_ringstatusget,
  106. .response_size = sizeof (struct res_lib_cfg_ringstatusget),
  107. .response_id = MESSAGE_RES_CFG_RINGSTATUSGET,
  108. .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED
  109. },
  110. { /* 1 */
  111. .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
  112. .response_size = sizeof (struct res_lib_cfg_ringreenable),
  113. .response_id = MESSAGE_RES_CFG_RINGREENABLE,
  114. .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED
  115. },
  116. { /* 2 */
  117. .lib_handler_fn = message_handler_req_lib_cfg_statetrack,
  118. .response_size = sizeof (struct res_lib_cfg_statetrack),
  119. .response_id = MESSAGE_RES_CFG_STATETRACKSTART,
  120. .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED
  121. },
  122. { /* 3 */
  123. .lib_handler_fn = message_handler_req_lib_cfg_statetrackstop,
  124. .response_size = sizeof (struct res_lib_cfg_statetrackstop),
  125. .response_id = MESSAGE_RES_CFG_STATETRACKSTOP,
  126. .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED
  127. },
  128. { /* 4 */
  129. .lib_handler_fn = message_handler_req_lib_cfg_administrativestateset,
  130. .response_size = sizeof (struct res_lib_cfg_administrativestateset),
  131. .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATESET,
  132. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  133. },
  134. { /* 5 */
  135. .lib_handler_fn = message_handler_req_lib_cfg_administrativestateget,
  136. .response_size = sizeof (struct res_lib_cfg_administrativestateget),
  137. .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATEGET,
  138. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  139. },
  140. { /* 6 */
  141. .lib_handler_fn = message_handler_req_lib_cfg_serviceload,
  142. .response_size = sizeof (struct res_lib_cfg_serviceload),
  143. .response_id = MESSAGE_RES_CFG_SERVICELOAD,
  144. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  145. },
  146. { /* 7 */
  147. .lib_handler_fn = message_handler_req_lib_cfg_serviceunload,
  148. .response_size = sizeof (struct res_lib_cfg_serviceunload),
  149. .response_id = MESSAGE_RES_CFG_SERVICEUNLOAD,
  150. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  151. }
  152. };
  153. static struct corosync_exec_handler cfg_exec_engine[] =
  154. {
  155. {
  156. message_handler_req_exec_cfg_ringreenable
  157. }
  158. };
  159. /*
  160. * Exports the interface for the service
  161. */
  162. struct corosync_service_engine cfg_service_engine = {
  163. .name = "corosync configuration service",
  164. .id = CFG_SERVICE,
  165. .private_data_size = 0,
  166. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED,
  167. .lib_init_fn = cfg_lib_init_fn,
  168. .lib_exit_fn = cfg_lib_exit_fn,
  169. .lib_engine = cfg_lib_engine,
  170. .lib_engine_count = sizeof (cfg_lib_engine) / sizeof (struct corosync_lib_handler),
  171. .exec_init_fn = cfg_exec_init_fn,
  172. .exec_engine = cfg_exec_engine,
  173. .exec_engine_count = 0, /* sizeof (cfg_aisexec_handler_fns) / sizeof (coroync_exec_handler), */
  174. .confchg_fn = cfg_confchg_fn,
  175. };
  176. /*
  177. * Dynamic Loader definition
  178. */
  179. static struct corosync_service_engine *cfg_get_service_engine_ver0 (void);
  180. static struct corosync_service_engine_iface_ver0 cfg_service_engine_iface = {
  181. .corosync_get_service_engine_ver0 = cfg_get_service_engine_ver0
  182. };
  183. static struct lcr_iface corosync_cfg_ver0[1] = {
  184. {
  185. .name = "corosync_cfg",
  186. .version = 0,
  187. .versions_replace = 0,
  188. .versions_replace_count = 0,
  189. .dependencies = 0,
  190. .dependency_count = 0,
  191. .constructor = NULL,
  192. .destructor = NULL,
  193. .interfaces = NULL
  194. }
  195. };
  196. static struct lcr_comp cfg_comp_ver0 = {
  197. .iface_count = 1,
  198. .ifaces = corosync_cfg_ver0
  199. };
  200. static struct corosync_service_engine *cfg_get_service_engine_ver0 (void)
  201. {
  202. return (&cfg_service_engine);
  203. }
  204. __attribute__ ((constructor)) static void register_this_component (void) {
  205. lcr_interfaces_set (&corosync_cfg_ver0[0], &cfg_service_engine_iface);
  206. lcr_component_register (&cfg_comp_ver0);
  207. }
  208. struct req_exec_cfg_ringreenable {
  209. mar_req_header_t header __attribute__((aligned(8)));
  210. mar_message_source_t source __attribute__((aligned(8)));
  211. };
  212. /* IMPL */
  213. static int cfg_exec_init_fn (
  214. struct corosync_api_v1 *corosync_api_v1)
  215. {
  216. api = corosync_api_v1;
  217. return (0);
  218. }
  219. static void cfg_confchg_fn (
  220. enum totem_configuration_type configuration_type,
  221. unsigned int *member_list, int member_list_entries,
  222. unsigned int *left_list, int left_list_entries,
  223. unsigned int *joined_list, int joined_list_entries,
  224. struct memb_ring_id *ring_id)
  225. {
  226. }
  227. int cfg_lib_exit_fn (void *conn)
  228. {
  229. return (0);
  230. }
  231. static int cfg_lib_init_fn (void *conn)
  232. {
  233. ENTER("");
  234. LEAVE("");
  235. return (0);
  236. }
  237. /*
  238. * Executive message handlers
  239. */
  240. static void message_handler_req_exec_cfg_ringreenable (
  241. void *message,
  242. unsigned int nodeid)
  243. {
  244. struct req_exec_cfg_ringreenable *req_exec_cfg_ringreenable =
  245. (struct req_exec_cfg_ringreenable *)message;
  246. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  247. ENTER("");
  248. api->totem_ring_reenable ();
  249. if (api->ipc_source_is_local(&req_exec_cfg_ringreenable->source)) {
  250. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  251. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  252. res_lib_cfg_ringreenable.header.error = SA_AIS_OK;
  253. api->ipc_conn_send_response (
  254. req_exec_cfg_ringreenable->source.conn,
  255. &res_lib_cfg_ringreenable,
  256. sizeof (struct res_lib_cfg_ringreenable));
  257. }
  258. LEAVE("");
  259. }
  260. /*
  261. * Library Interface Implementation
  262. */
  263. static void message_handler_req_lib_cfg_ringstatusget (
  264. void *conn,
  265. void *msg)
  266. {
  267. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  268. struct totem_ip_address interfaces[INTERFACE_MAX];
  269. unsigned int iface_count;
  270. char **status;
  271. char *totem_ip_string;
  272. unsigned int i;
  273. ENTER("");
  274. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  275. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  276. res_lib_cfg_ringstatusget.header.error = SA_AIS_OK;
  277. api->totem_ifaces_get (
  278. api->totem_nodeid_get(),
  279. interfaces,
  280. &status,
  281. &iface_count);
  282. res_lib_cfg_ringstatusget.interface_count = iface_count;
  283. for (i = 0; i < iface_count; i++) {
  284. totem_ip_string = (char *)api->totem_ip_print (&interfaces[i]);
  285. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  286. status[i]);
  287. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  288. totem_ip_string);
  289. }
  290. api->ipc_conn_send_response (
  291. conn,
  292. &res_lib_cfg_ringstatusget,
  293. sizeof (struct res_lib_cfg_ringstatusget));
  294. LEAVE("");
  295. }
  296. static void message_handler_req_lib_cfg_ringreenable (
  297. void *conn,
  298. void *msg)
  299. {
  300. struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
  301. struct iovec iovec;
  302. ENTER("");
  303. req_exec_cfg_ringreenable.header.size =
  304. sizeof (struct req_exec_cfg_ringreenable);
  305. req_exec_cfg_ringreenable.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  306. MESSAGE_REQ_EXEC_CFG_RINGREENABLE);
  307. api->ipc_source_set (&req_exec_cfg_ringreenable.source, conn);
  308. iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
  309. iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
  310. assert (api->totem_mcast (&iovec, 1, TOTEM_SAFE) == 0);
  311. LEAVE("");
  312. }
  313. static void message_handler_req_lib_cfg_statetrack (
  314. void *conn,
  315. void *msg)
  316. {
  317. // struct req_lib_cfg_statetrack *req_lib_cfg_statetrack = (struct req_lib_cfg_statetrack *)message;
  318. ENTER("");
  319. LEAVE("");
  320. }
  321. static void message_handler_req_lib_cfg_statetrackstop (
  322. void *conn,
  323. void *msg)
  324. {
  325. // struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
  326. ENTER("");
  327. LEAVE("");
  328. }
  329. static void message_handler_req_lib_cfg_administrativestateset (
  330. void *conn,
  331. void *msg)
  332. {
  333. // struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
  334. ENTER("");
  335. LEAVE("");
  336. }
  337. static void message_handler_req_lib_cfg_administrativestateget (
  338. void *conn,
  339. void *msg)
  340. {
  341. // struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;
  342. ENTER("");
  343. LEAVE("");
  344. }
  345. static void message_handler_req_lib_cfg_serviceload (
  346. void *conn,
  347. void *msg)
  348. {
  349. struct req_lib_cfg_serviceload *req_lib_cfg_serviceload =
  350. (struct req_lib_cfg_serviceload *)msg;
  351. struct res_lib_cfg_serviceload res_lib_cfg_serviceload;
  352. ENTER("");
  353. api->service_link_and_init (
  354. api,
  355. (char *)req_lib_cfg_serviceload->service_name,
  356. req_lib_cfg_serviceload->service_ver);
  357. res_lib_cfg_serviceload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  358. res_lib_cfg_serviceload.header.size = sizeof (struct res_lib_cfg_serviceload);
  359. res_lib_cfg_serviceload.header.error = SA_AIS_OK;
  360. api->ipc_conn_send_response (
  361. conn,
  362. &res_lib_cfg_serviceload,
  363. sizeof (struct res_lib_cfg_serviceload));
  364. LEAVE("");
  365. }
  366. static void message_handler_req_lib_cfg_serviceunload (
  367. void *conn,
  368. void *msg)
  369. {
  370. struct req_lib_cfg_serviceunload *req_lib_cfg_serviceunload =
  371. (struct req_lib_cfg_serviceunload *)msg;
  372. struct res_lib_cfg_serviceunload res_lib_cfg_serviceunload;
  373. ENTER("");
  374. api->service_unlink_and_exit (
  375. api,
  376. (char *)req_lib_cfg_serviceunload->service_name,
  377. req_lib_cfg_serviceunload->service_ver);
  378. res_lib_cfg_serviceunload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  379. res_lib_cfg_serviceunload.header.size = sizeof (struct res_lib_cfg_serviceunload);
  380. res_lib_cfg_serviceunload.header.error = SA_AIS_OK;
  381. api->ipc_conn_send_response (
  382. conn,
  383. &res_lib_cfg_serviceunload,
  384. sizeof (struct res_lib_cfg_serviceunload));
  385. LEAVE("");
  386. }