cfg.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /*
  2. * Copyright (c) 2005-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2007 Red Hat, Inc.
  4. * Copyright (c) 2006 Sun Microsystems, Inc.
  5. *
  6. * All rights reserved.
  7. *
  8. * Author: Steven Dake (sdake@redhat.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 ("CFG", 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. static void message_handler_req_lib_cfg_serviceload (
  104. void *conn,
  105. void *msg);
  106. static void message_handler_req_lib_cfg_serviceunload (
  107. void *conn,
  108. void *msg);
  109. /*
  110. * Service Handler Definition
  111. */
  112. static struct openais_lib_handler cfg_lib_service[] =
  113. {
  114. { /* 0 */
  115. .lib_handler_fn = message_handler_req_lib_cfg_ringstatusget,
  116. .response_size = sizeof (struct res_lib_cfg_ringstatusget),
  117. .response_id = MESSAGE_RES_CFG_RINGSTATUSGET,
  118. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  119. },
  120. { /* 1 */
  121. .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
  122. .response_size = sizeof (struct res_lib_cfg_ringreenable),
  123. .response_id = MESSAGE_RES_CFG_RINGREENABLE,
  124. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  125. },
  126. { /* 2 */
  127. .lib_handler_fn = message_handler_req_lib_cfg_statetrack,
  128. .response_size = sizeof (struct res_lib_cfg_statetrack),
  129. .response_id = MESSAGE_RES_CFG_STATETRACKSTART,
  130. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  131. },
  132. { /* 3 */
  133. .lib_handler_fn = message_handler_req_lib_cfg_statetrackstop,
  134. .response_size = sizeof (struct res_lib_cfg_statetrackstop),
  135. .response_id = MESSAGE_RES_CFG_STATETRACKSTOP,
  136. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  137. },
  138. { /* 4 */
  139. .lib_handler_fn = message_handler_req_lib_cfg_administrativestateset,
  140. .response_size = sizeof (struct res_lib_cfg_administrativestateset),
  141. .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATESET,
  142. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  143. },
  144. { /* 5 */
  145. .lib_handler_fn = message_handler_req_lib_cfg_administrativestateget,
  146. .response_size = sizeof (struct res_lib_cfg_administrativestateget),
  147. .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATEGET,
  148. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  149. },
  150. { /* 6 */
  151. .lib_handler_fn = message_handler_req_lib_cfg_serviceload,
  152. .response_size = sizeof (struct res_lib_cfg_serviceload),
  153. .response_id = MESSAGE_RES_CFG_SERVICELOAD,
  154. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  155. },
  156. { /* 7 */
  157. .lib_handler_fn = message_handler_req_lib_cfg_serviceunload,
  158. .response_size = sizeof (struct res_lib_cfg_serviceunload),
  159. .response_id = MESSAGE_RES_CFG_SERVICEUNLOAD,
  160. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  161. }
  162. };
  163. static struct openais_exec_handler cfg_exec_service[] =
  164. {
  165. {
  166. message_handler_req_exec_cfg_ringreenable
  167. }
  168. };
  169. /*
  170. * Exports the interface for the service
  171. */
  172. struct openais_service_handler cfg_service_handler = {
  173. .name = "openais configuration service",
  174. .id = CFG_SERVICE,
  175. .private_data_size = 0,
  176. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED,
  177. .lib_init_fn = cfg_lib_init_fn,
  178. .lib_exit_fn = cfg_lib_exit_fn,
  179. .lib_service = cfg_lib_service,
  180. .lib_service_count = sizeof (cfg_lib_service) / sizeof (struct openais_lib_handler),
  181. .exec_init_fn = cfg_exec_init_fn,
  182. .exec_service = cfg_exec_service,
  183. .exec_service_count = 0, /* sizeof (cfg_aisexec_handler_fns) / sizeof (openais_exec_handler), */
  184. .confchg_fn = cfg_confchg_fn,
  185. };
  186. static struct objdb_iface_ver0 *my_objdb;
  187. /*
  188. * Dynamic Loader definition
  189. */
  190. static struct openais_service_handler *cfg_get_handler_ver0 (void);
  191. static struct openais_service_handler_iface_ver0 cfg_service_handler_iface = {
  192. .openais_get_service_handler_ver0 = cfg_get_handler_ver0
  193. };
  194. static struct lcr_iface openais_cfg_ver0[1] = {
  195. {
  196. .name = "openais_cfg",
  197. .version = 0,
  198. .versions_replace = 0,
  199. .versions_replace_count = 0,
  200. .dependencies = 0,
  201. .dependency_count = 0,
  202. .constructor = NULL,
  203. .destructor = NULL,
  204. .interfaces = NULL
  205. }
  206. };
  207. static struct lcr_comp cfg_comp_ver0 = {
  208. .iface_count = 1,
  209. .ifaces = openais_cfg_ver0
  210. };
  211. static struct openais_service_handler *cfg_get_handler_ver0 (void)
  212. {
  213. return (&cfg_service_handler);
  214. }
  215. __attribute__ ((constructor)) static void register_this_component (void) {
  216. lcr_interfaces_set (&openais_cfg_ver0[0], &cfg_service_handler_iface);
  217. lcr_component_register (&cfg_comp_ver0);
  218. }
  219. struct req_exec_cfg_ringreenable {
  220. mar_req_header_t header __attribute__((aligned(8)));
  221. mar_message_source_t source __attribute__((aligned(8)));
  222. };
  223. /* IMPL */
  224. static int cfg_exec_init_fn (struct objdb_iface_ver0 *objdb)
  225. {
  226. my_objdb = objdb;
  227. return (0);
  228. }
  229. static void cfg_confchg_fn (
  230. enum totem_configuration_type configuration_type,
  231. unsigned int *member_list, int member_list_entries,
  232. unsigned int *left_list, int left_list_entries,
  233. unsigned int *joined_list, int joined_list_entries,
  234. struct memb_ring_id *ring_id)
  235. {
  236. }
  237. int cfg_lib_exit_fn (void *conn)
  238. {
  239. return (0);
  240. }
  241. static int cfg_lib_init_fn (void *conn)
  242. {
  243. ENTER("");
  244. LEAVE("");
  245. return (0);
  246. }
  247. /*
  248. * Executive message handlers
  249. */
  250. static void message_handler_req_exec_cfg_ringreenable (
  251. void *message,
  252. unsigned int nodeid)
  253. {
  254. struct req_exec_cfg_ringreenable *req_exec_cfg_ringreenable =
  255. (struct req_exec_cfg_ringreenable *)message;
  256. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  257. ENTER("");
  258. totempg_ring_reenable ();
  259. if (message_source_is_local(&req_exec_cfg_ringreenable->source)) {
  260. res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
  261. res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
  262. res_lib_cfg_ringreenable.header.error = SA_AIS_OK;
  263. openais_conn_send_response (
  264. req_exec_cfg_ringreenable->source.conn,
  265. &res_lib_cfg_ringreenable,
  266. sizeof (struct res_lib_cfg_ringreenable));
  267. }
  268. LEAVE("");
  269. }
  270. /*
  271. * Library Interface Implementation
  272. */
  273. static void message_handler_req_lib_cfg_ringstatusget (
  274. void *conn,
  275. void *msg)
  276. {
  277. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  278. struct totem_ip_address interfaces[INTERFACE_MAX];
  279. unsigned int iface_count;
  280. char **status;
  281. char *totem_ip_string;
  282. unsigned int i;
  283. ENTER("");
  284. res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
  285. res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
  286. res_lib_cfg_ringstatusget.header.error = SA_AIS_OK;
  287. totempg_ifaces_get (
  288. totempg_my_nodeid_get(),
  289. interfaces,
  290. &status,
  291. &iface_count);
  292. res_lib_cfg_ringstatusget.interface_count = iface_count;
  293. for (i = 0; i < iface_count; i++) {
  294. totem_ip_string = (char *)totemip_print (&interfaces[i]);
  295. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
  296. status[i]);
  297. strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
  298. totem_ip_string);
  299. }
  300. openais_conn_send_response (
  301. conn,
  302. &res_lib_cfg_ringstatusget,
  303. sizeof (struct res_lib_cfg_ringstatusget));
  304. LEAVE("");
  305. }
  306. static void message_handler_req_lib_cfg_ringreenable (
  307. void *conn,
  308. void *msg)
  309. {
  310. struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
  311. struct iovec iovec;
  312. ENTER("");
  313. req_exec_cfg_ringreenable.header.size =
  314. sizeof (struct req_exec_cfg_ringreenable);
  315. req_exec_cfg_ringreenable.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
  316. MESSAGE_REQ_EXEC_CFG_RINGREENABLE);
  317. message_source_set (&req_exec_cfg_ringreenable.source, conn);
  318. iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
  319. iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
  320. assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1,
  321. TOTEMPG_SAFE) == 0);
  322. LEAVE("");
  323. }
  324. static void message_handler_req_lib_cfg_statetrack (
  325. void *conn,
  326. void *msg)
  327. {
  328. // struct req_lib_cfg_statetrack *req_lib_cfg_statetrack = (struct req_lib_cfg_statetrack *)message;
  329. ENTER("");
  330. LEAVE("");
  331. }
  332. static void message_handler_req_lib_cfg_statetrackstop (
  333. void *conn,
  334. void *msg)
  335. {
  336. // struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
  337. ENTER("");
  338. LEAVE("");
  339. }
  340. static void message_handler_req_lib_cfg_administrativestateset (
  341. void *conn,
  342. void *msg)
  343. {
  344. // struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
  345. ENTER("");
  346. LEAVE("");
  347. }
  348. static void message_handler_req_lib_cfg_administrativestateget (
  349. void *conn,
  350. void *msg)
  351. {
  352. // struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;
  353. ENTER("");
  354. LEAVE("");
  355. }
  356. static void message_handler_req_lib_cfg_serviceload (
  357. void *conn,
  358. void *msg)
  359. {
  360. struct req_lib_cfg_serviceload *req_lib_cfg_serviceload =
  361. (struct req_lib_cfg_serviceload *)msg;
  362. struct res_lib_cfg_serviceload res_lib_cfg_serviceload;
  363. ENTER("");
  364. openais_service_link_and_init (
  365. my_objdb,
  366. (char *)req_lib_cfg_serviceload->service_name,
  367. req_lib_cfg_serviceload->service_ver);
  368. res_lib_cfg_serviceload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  369. res_lib_cfg_serviceload.header.size = sizeof (struct res_lib_cfg_serviceload);
  370. res_lib_cfg_serviceload.header.error = SA_AIS_OK;
  371. openais_conn_send_response (
  372. conn,
  373. &res_lib_cfg_serviceload,
  374. sizeof (struct res_lib_cfg_serviceload));
  375. LEAVE("");
  376. }
  377. static void message_handler_req_lib_cfg_serviceunload (
  378. void *conn,
  379. void *msg)
  380. {
  381. struct req_lib_cfg_serviceunload *req_lib_cfg_serviceunload =
  382. (struct req_lib_cfg_serviceunload *)msg;
  383. struct res_lib_cfg_serviceunload res_lib_cfg_serviceunload;
  384. ENTER("");
  385. openais_service_unlink_and_exit (
  386. my_objdb,
  387. (char *)req_lib_cfg_serviceunload->service_name,
  388. req_lib_cfg_serviceunload->service_ver);
  389. res_lib_cfg_serviceunload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
  390. res_lib_cfg_serviceunload.header.size = sizeof (struct res_lib_cfg_serviceunload);
  391. res_lib_cfg_serviceunload.header.error = SA_AIS_OK;
  392. openais_conn_send_response (
  393. conn,
  394. &res_lib_cfg_serviceunload,
  395. sizeof (struct res_lib_cfg_serviceunload));
  396. LEAVE("");
  397. }