cfg.c 11 KB

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