cfg.c 11 KB

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