4
0

cfg.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /*
  2. * Copyright (c) 2005-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@mvista.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 "totem.h"
  55. #include "totempg.h"
  56. #include "ipc.h"
  57. #include "../include/queue.h"
  58. #include "../lcr/lcr_comp.h"
  59. #include "service.h"
  60. #include "totempg.h"
  61. #include "mempool.h"
  62. #include "util.h"
  63. #include "print.h"
  64. #include "main.h"
  65. enum cfg_message_req_types {
  66. MESSAGE_REQ_EXEC_CFG_RINGREENABLE = 0
  67. };
  68. static void cfg_confchg_fn (
  69. enum totem_configuration_type configuration_type,
  70. unsigned int *member_list, int member_list_entries,
  71. unsigned int *left_list, int left_list_entries,
  72. unsigned int *joined_list, int joined_list_entries,
  73. struct memb_ring_id *ring_id);
  74. static int cfg_exec_init_fn (struct objdb_iface_ver0 *objdb);
  75. static int cfg_lib_init_fn (void *conn);
  76. static int cfg_lib_exit_fn (void *conn);
  77. static void message_handler_req_exec_cfg_ringreenable (
  78. void *message,
  79. unsigned int nodeid);
  80. static void message_handler_req_lib_cfg_ringstatusget (
  81. void *conn,
  82. void *msg);
  83. static void message_handler_req_lib_cfg_ringreenable (
  84. void *conn,
  85. void *msg);
  86. static void message_handler_req_lib_cfg_statetrack (
  87. void *conn,
  88. void *msg);
  89. static void message_handler_req_lib_cfg_statetrackstop (
  90. void *conn,
  91. void *msg);
  92. static void message_handler_req_lib_cfg_administrativestateset (
  93. void *conn,
  94. void *msg);
  95. static void message_handler_req_lib_cfg_administrativestateget (
  96. void *conn,
  97. void *msg);
  98. /*
  99. * Service Handler Definition
  100. */
  101. static struct openais_lib_handler cfg_lib_service[] =
  102. {
  103. { /* 0 */
  104. .lib_handler_fn = message_handler_req_lib_cfg_ringstatusget,
  105. .response_size = sizeof (struct res_lib_cfg_ringstatusget),
  106. .response_id = MESSAGE_RES_CFG_RINGSTATUSGET,
  107. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  108. },
  109. { /* 0 */
  110. .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
  111. .response_size = sizeof (struct res_lib_cfg_ringreenable),
  112. .response_id = MESSAGE_RES_CFG_RINGREENABLE,
  113. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  114. },
  115. { /* 0 */
  116. .lib_handler_fn = message_handler_req_lib_cfg_statetrack,
  117. .response_size = sizeof (struct res_lib_cfg_statetrack),
  118. .response_id = MESSAGE_RES_CFG_STATETRACKSTART,
  119. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  120. },
  121. { /* 1 */
  122. .lib_handler_fn = message_handler_req_lib_cfg_statetrackstop,
  123. .response_size = sizeof (struct res_lib_cfg_statetrackstop),
  124. .response_id = MESSAGE_RES_CFG_STATETRACKSTOP,
  125. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  126. },
  127. { /* 2 */
  128. .lib_handler_fn = message_handler_req_lib_cfg_administrativestateset,
  129. .response_size = sizeof (struct res_lib_cfg_administrativestateset),
  130. .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATESET,
  131. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  132. },
  133. { /* 3 */
  134. .lib_handler_fn = message_handler_req_lib_cfg_administrativestateget,
  135. .response_size = sizeof (struct res_lib_cfg_administrativestateget),
  136. .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATEGET,
  137. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  138. }
  139. };
  140. static struct openais_exec_handler cfg_exec_service[] =
  141. {
  142. {
  143. message_handler_req_exec_cfg_ringreenable
  144. }
  145. };
  146. /*
  147. * Exports the interface for the service
  148. */
  149. struct openais_service_handler cfg_service_handler = {
  150. .name = (unsigned char*)"openais configuration service",
  151. .id = CFG_SERVICE,
  152. .private_data_size = 0,
  153. .lib_init_fn = cfg_lib_init_fn,
  154. .lib_exit_fn = cfg_lib_exit_fn,
  155. .lib_service = cfg_lib_service,
  156. .lib_service_count = sizeof (cfg_lib_service) / sizeof (struct openais_lib_handler),
  157. .exec_init_fn = cfg_exec_init_fn,
  158. .exec_service = cfg_exec_service,
  159. .exec_service_count = 0, /* sizeof (cfg_aisexec_handler_fns) / sizeof (openais_exec_handler), */
  160. .confchg_fn = cfg_confchg_fn,
  161. };
  162. /*
  163. * Dynamic Loader definition
  164. */
  165. static struct openais_service_handler *cfg_get_handler_ver0 (void);
  166. static struct openais_service_handler_iface_ver0 cfg_service_handler_iface = {
  167. .openais_get_service_handler_ver0 = cfg_get_handler_ver0
  168. };
  169. static struct lcr_iface openais_cfg_ver0[1] = {
  170. {
  171. .name = "openais_cfg",
  172. .version = 0,
  173. .versions_replace = 0,
  174. .versions_replace_count = 0,
  175. .dependencies = 0,
  176. .dependency_count = 0,
  177. .constructor = NULL,
  178. .destructor = NULL,
  179. .interfaces = NULL
  180. }
  181. };
  182. static struct lcr_comp cfg_comp_ver0 = {
  183. .iface_count = 1,
  184. .ifaces = openais_cfg_ver0
  185. };
  186. static struct openais_service_handler *cfg_get_handler_ver0 (void)
  187. {
  188. return (&cfg_service_handler);
  189. }
  190. __attribute__ ((constructor)) static void register_this_component (void) {
  191. lcr_interfaces_set (&openais_cfg_ver0[0], &cfg_service_handler_iface);
  192. lcr_component_register (&cfg_comp_ver0);
  193. }
  194. struct req_exec_cfg_ringreenable {
  195. mar_req_header_t header __attribute__((aligned(8)));
  196. mar_message_source_t source __attribute__((aligned(8)));
  197. };
  198. /* IMPL */
  199. static int cfg_exec_init_fn (struct objdb_iface_ver0 *objdb)
  200. {
  201. log_init ("CFG");
  202. return (0);
  203. }
  204. static void cfg_confchg_fn (
  205. enum totem_configuration_type configuration_type,
  206. unsigned int *member_list, int member_list_entries,
  207. unsigned int *left_list, int left_list_entries,
  208. unsigned int *joined_list, int joined_list_entries,
  209. struct memb_ring_id *ring_id)
  210. {
  211. }
  212. int cfg_lib_exit_fn (void *conn)
  213. {
  214. return (0);
  215. }
  216. static int cfg_lib_init_fn (void *conn)
  217. {
  218. ENTER("");
  219. LEAVE("");
  220. return (0);
  221. }
  222. /*
  223. * Executive message handlers
  224. */
  225. static void message_handler_req_exec_cfg_ringreenable (
  226. void *message,
  227. unsigned int nodeid)
  228. {
  229. struct req_exec_cfg_ringreenable *req_exec_cfg_ringreenable =
  230. (struct req_exec_cfg_ringreenable *)message;
  231. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  232. ENTER("");
  233. totempg_ring_reenable ();
  234. if (message_source_is_local(&req_exec_cfg_ringreenable->source)) {
  235. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  236. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  237. res_lib_cfg_ringreenable.header.error = SA_AIS_OK;
  238. openais_conn_send_response (
  239. req_exec_cfg_ringreenable->source.conn,
  240. &res_lib_cfg_ringreenable,
  241. sizeof (struct res_lib_cfg_ringreenable));
  242. }
  243. LEAVE("");
  244. }
  245. /*
  246. * Library Interface Implementation
  247. */
  248. static void message_handler_req_lib_cfg_ringstatusget (
  249. void *conn,
  250. void *msg)
  251. {
  252. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  253. struct totem_ip_address interfaces[INTERFACE_MAX];
  254. unsigned int iface_count;
  255. char **status;
  256. char *totem_ip_string;
  257. unsigned int i;
  258. ENTER("");
  259. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  260. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  261. res_lib_cfg_ringstatusget.header.error = SA_AIS_OK;
  262. totempg_ifaces_get (
  263. this_ip->nodeid,
  264. interfaces,
  265. &status,
  266. &iface_count);
  267. res_lib_cfg_ringstatusget.interface_count = iface_count;
  268. for (i = 0; i < iface_count; i++) {
  269. totem_ip_string = (char *)totemip_print (&interfaces[i]);
  270. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  271. status[i]);
  272. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  273. totem_ip_string);
  274. }
  275. openais_conn_send_response (
  276. conn,
  277. &res_lib_cfg_ringstatusget,
  278. sizeof (struct res_lib_cfg_ringstatusget));
  279. LEAVE("");
  280. }
  281. static void message_handler_req_lib_cfg_ringreenable (
  282. void *conn,
  283. void *msg)
  284. {
  285. struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
  286. struct iovec iovec;
  287. ENTER("");
  288. req_exec_cfg_ringreenable.header.size =
  289. sizeof (struct req_exec_cfg_ringreenable);
  290. req_exec_cfg_ringreenable.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  291. MESSAGE_REQ_EXEC_CFG_RINGREENABLE);
  292. message_source_set (&req_exec_cfg_ringreenable.source, conn);
  293. iovec.iov_base = &req_exec_cfg_ringreenable;
  294. iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
  295. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1,
  296. TOTEMPG_SAFE) == 0);
  297. LEAVE("");
  298. }
  299. static void message_handler_req_lib_cfg_statetrack (
  300. void *conn,
  301. void *msg)
  302. {
  303. // struct req_lib_cfg_statetrack *req_lib_cfg_statetrack = (struct req_lib_cfg_statetrack *)message;
  304. ENTER("");
  305. LEAVE("");
  306. }
  307. static void message_handler_req_lib_cfg_statetrackstop (
  308. void *conn,
  309. void *msg)
  310. {
  311. // struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
  312. ENTER("");
  313. LEAVE("");
  314. }
  315. static void message_handler_req_lib_cfg_administrativestateset (
  316. void *conn,
  317. void *msg)
  318. {
  319. // struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
  320. ENTER("");
  321. LEAVE("");
  322. }
  323. static void message_handler_req_lib_cfg_administrativestateget (
  324. void *conn,
  325. void *msg)
  326. {
  327. // struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;
  328. ENTER("");
  329. LEAVE("");
  330. }