4
0

cfg.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*
  2. * Copyright (c) 2005-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006 Red Hat, Inc.
  4. * Copyright (c) 2006 Sun Microsystems, Inc.
  5. *
  6. * All rights reserved.
  7. *
  8. * Author: Steven Dake (sdake@mvista.com)
  9. *
  10. * This software licensed under BSD license, the text of which follows:
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * - Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  21. * contributors may be used to endorse or promote products derived from this
  22. * software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  34. * THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  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 <errno.h>
  47. #include <signal.h>
  48. #include <string.h>
  49. #include "../include/saAis.h"
  50. #include "../include/cfg.h"
  51. #include "../include/mar_gen.h"
  52. #include "../include/ipc_gen.h"
  53. #include "../include/ipc_cfg.h"
  54. #include "../include/list.h"
  55. #include "totem.h"
  56. #include "totempg.h"
  57. #include "ipc.h"
  58. #include "../include/queue.h"
  59. #include "../lcr/lcr_comp.h"
  60. #include "service.h"
  61. #include "totempg.h"
  62. #include "mempool.h"
  63. #include "util.h"
  64. #include "logsys.h"
  65. #include "main.h"
  66. LOGSYS_DECLARE_SUBSYS ("AMF", LOG_INFO);
  67. enum cfg_message_req_types {
  68. MESSAGE_REQ_EXEC_CFG_RINGREENABLE = 0
  69. };
  70. static void cfg_confchg_fn (
  71. enum totem_configuration_type configuration_type,
  72. unsigned int *member_list, int member_list_entries,
  73. unsigned int *left_list, int left_list_entries,
  74. unsigned int *joined_list, int joined_list_entries,
  75. struct memb_ring_id *ring_id);
  76. static int cfg_exec_init_fn (struct objdb_iface_ver0 *objdb);
  77. static int cfg_lib_init_fn (void *conn);
  78. static int cfg_lib_exit_fn (void *conn);
  79. static void message_handler_req_exec_cfg_ringreenable (
  80. void *message,
  81. unsigned int nodeid);
  82. static void message_handler_req_lib_cfg_ringstatusget (
  83. void *conn,
  84. void *msg);
  85. static void message_handler_req_lib_cfg_ringreenable (
  86. void *conn,
  87. void *msg);
  88. static void message_handler_req_lib_cfg_statetrack (
  89. void *conn,
  90. void *msg);
  91. static void message_handler_req_lib_cfg_statetrackstop (
  92. void *conn,
  93. void *msg);
  94. static void message_handler_req_lib_cfg_administrativestateset (
  95. void *conn,
  96. void *msg);
  97. static void message_handler_req_lib_cfg_administrativestateget (
  98. void *conn,
  99. void *msg);
  100. /*
  101. * Service Handler Definition
  102. */
  103. static struct openais_lib_handler cfg_lib_service[] =
  104. {
  105. { /* 0 */
  106. .lib_handler_fn = message_handler_req_lib_cfg_ringstatusget,
  107. .response_size = sizeof (struct res_lib_cfg_ringstatusget),
  108. .response_id = MESSAGE_RES_CFG_RINGSTATUSGET,
  109. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  110. },
  111. { /* 0 */
  112. .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
  113. .response_size = sizeof (struct res_lib_cfg_ringreenable),
  114. .response_id = MESSAGE_RES_CFG_RINGREENABLE,
  115. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  116. },
  117. { /* 0 */
  118. .lib_handler_fn = message_handler_req_lib_cfg_statetrack,
  119. .response_size = sizeof (struct res_lib_cfg_statetrack),
  120. .response_id = MESSAGE_RES_CFG_STATETRACKSTART,
  121. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  122. },
  123. { /* 1 */
  124. .lib_handler_fn = message_handler_req_lib_cfg_statetrackstop,
  125. .response_size = sizeof (struct res_lib_cfg_statetrackstop),
  126. .response_id = MESSAGE_RES_CFG_STATETRACKSTOP,
  127. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  128. },
  129. { /* 2 */
  130. .lib_handler_fn = message_handler_req_lib_cfg_administrativestateset,
  131. .response_size = sizeof (struct res_lib_cfg_administrativestateset),
  132. .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATESET,
  133. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  134. },
  135. { /* 3 */
  136. .lib_handler_fn = message_handler_req_lib_cfg_administrativestateget,
  137. .response_size = sizeof (struct res_lib_cfg_administrativestateget),
  138. .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATEGET,
  139. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  140. }
  141. };
  142. static struct openais_exec_handler cfg_exec_service[] =
  143. {
  144. {
  145. message_handler_req_exec_cfg_ringreenable
  146. }
  147. };
  148. /*
  149. * Exports the interface for the service
  150. */
  151. struct openais_service_handler cfg_service_handler = {
  152. .name = "openais configuration service",
  153. .id = CFG_SERVICE,
  154. .private_data_size = 0,
  155. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED,
  156. .lib_init_fn = cfg_lib_init_fn,
  157. .lib_exit_fn = cfg_lib_exit_fn,
  158. .lib_service = cfg_lib_service,
  159. .lib_service_count = sizeof (cfg_lib_service) / sizeof (struct openais_lib_handler),
  160. .exec_init_fn = cfg_exec_init_fn,
  161. .exec_service = cfg_exec_service,
  162. .exec_service_count = 0, /* sizeof (cfg_aisexec_handler_fns) / sizeof (openais_exec_handler), */
  163. .confchg_fn = cfg_confchg_fn,
  164. };
  165. /*
  166. * Dynamic Loader definition
  167. */
  168. static struct openais_service_handler *cfg_get_handler_ver0 (void);
  169. static struct openais_service_handler_iface_ver0 cfg_service_handler_iface = {
  170. .openais_get_service_handler_ver0 = cfg_get_handler_ver0
  171. };
  172. static struct lcr_iface openais_cfg_ver0[1] = {
  173. {
  174. .name = "openais_cfg",
  175. .version = 0,
  176. .versions_replace = 0,
  177. .versions_replace_count = 0,
  178. .dependencies = 0,
  179. .dependency_count = 0,
  180. .constructor = NULL,
  181. .destructor = NULL,
  182. .interfaces = NULL
  183. }
  184. };
  185. static struct lcr_comp cfg_comp_ver0 = {
  186. .iface_count = 1,
  187. .ifaces = openais_cfg_ver0
  188. };
  189. static struct openais_service_handler *cfg_get_handler_ver0 (void)
  190. {
  191. return (&cfg_service_handler);
  192. }
  193. __attribute__ ((constructor)) static void register_this_component (void) {
  194. lcr_interfaces_set (&openais_cfg_ver0[0], &cfg_service_handler_iface);
  195. lcr_component_register (&cfg_comp_ver0);
  196. }
  197. struct req_exec_cfg_ringreenable {
  198. mar_req_header_t header __attribute__((aligned(8)));
  199. mar_message_source_t source __attribute__((aligned(8)));
  200. };
  201. /* IMPL */
  202. static int cfg_exec_init_fn (struct objdb_iface_ver0 *objdb)
  203. {
  204. return (0);
  205. }
  206. static void cfg_confchg_fn (
  207. enum totem_configuration_type configuration_type,
  208. unsigned int *member_list, int member_list_entries,
  209. unsigned int *left_list, int left_list_entries,
  210. unsigned int *joined_list, int joined_list_entries,
  211. struct memb_ring_id *ring_id)
  212. {
  213. }
  214. int cfg_lib_exit_fn (void *conn)
  215. {
  216. return (0);
  217. }
  218. static int cfg_lib_init_fn (void *conn)
  219. {
  220. ENTER("");
  221. LEAVE("");
  222. return (0);
  223. }
  224. /*
  225. * Executive message handlers
  226. */
  227. static void message_handler_req_exec_cfg_ringreenable (
  228. void *message,
  229. unsigned int nodeid)
  230. {
  231. struct req_exec_cfg_ringreenable *req_exec_cfg_ringreenable =
  232. (struct req_exec_cfg_ringreenable *)message;
  233. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  234. ENTER("");
  235. totempg_ring_reenable ();
  236. if (message_source_is_local(&req_exec_cfg_ringreenable->source)) {
  237. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  238. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  239. res_lib_cfg_ringreenable.header.error = SA_AIS_OK;
  240. openais_conn_send_response (
  241. req_exec_cfg_ringreenable->source.conn,
  242. &res_lib_cfg_ringreenable,
  243. sizeof (struct res_lib_cfg_ringreenable));
  244. }
  245. LEAVE("");
  246. }
  247. /*
  248. * Library Interface Implementation
  249. */
  250. static void message_handler_req_lib_cfg_ringstatusget (
  251. void *conn,
  252. void *msg)
  253. {
  254. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  255. struct totem_ip_address interfaces[INTERFACE_MAX];
  256. unsigned int iface_count;
  257. char **status;
  258. char *totem_ip_string;
  259. unsigned int i;
  260. ENTER("");
  261. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  262. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  263. res_lib_cfg_ringstatusget.header.error = SA_AIS_OK;
  264. totempg_ifaces_get (
  265. totempg_my_nodeid_get(),
  266. interfaces,
  267. &status,
  268. &iface_count);
  269. res_lib_cfg_ringstatusget.interface_count = iface_count;
  270. for (i = 0; i < iface_count; i++) {
  271. totem_ip_string = (char *)totemip_print (&interfaces[i]);
  272. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  273. status[i]);
  274. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  275. totem_ip_string);
  276. }
  277. openais_conn_send_response (
  278. conn,
  279. &res_lib_cfg_ringstatusget,
  280. sizeof (struct res_lib_cfg_ringstatusget));
  281. LEAVE("");
  282. }
  283. static void message_handler_req_lib_cfg_ringreenable (
  284. void *conn,
  285. void *msg)
  286. {
  287. struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
  288. struct iovec iovec;
  289. ENTER("");
  290. req_exec_cfg_ringreenable.header.size =
  291. sizeof (struct req_exec_cfg_ringreenable);
  292. req_exec_cfg_ringreenable.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  293. MESSAGE_REQ_EXEC_CFG_RINGREENABLE);
  294. message_source_set (&req_exec_cfg_ringreenable.source, conn);
  295. iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
  296. iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
  297. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1,
  298. TOTEMPG_SAFE) == 0);
  299. LEAVE("");
  300. }
  301. static void message_handler_req_lib_cfg_statetrack (
  302. void *conn,
  303. void *msg)
  304. {
  305. // struct req_lib_cfg_statetrack *req_lib_cfg_statetrack = (struct req_lib_cfg_statetrack *)message;
  306. ENTER("");
  307. LEAVE("");
  308. }
  309. static void message_handler_req_lib_cfg_statetrackstop (
  310. void *conn,
  311. void *msg)
  312. {
  313. // struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
  314. ENTER("");
  315. LEAVE("");
  316. }
  317. static void message_handler_req_lib_cfg_administrativestateset (
  318. void *conn,
  319. void *msg)
  320. {
  321. // struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
  322. ENTER("");
  323. LEAVE("");
  324. }
  325. static void message_handler_req_lib_cfg_administrativestateget (
  326. void *conn,
  327. void *msg)
  328. {
  329. // struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;
  330. ENTER("");
  331. LEAVE("");
  332. }