Build on latest glibc.
[openais.git] / exec / cfg.c
bloba439dac880574d537d3c7d64da6a5fefc2774065
1 /*
2 * Copyright (c) 2005-2006 MontaVista Software, Inc.
3 * Copyright (c) 2006 Red Hat, Inc.
4 * Copyright (c) 2006 Sun Microsystems, Inc.
6 * All rights reserved.
8 * Author: Steven Dake (sdake@mvista.com)
10 * This software licensed under BSD license, the text of which follows:
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
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.
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.
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>
50 #include "../include/saAis.h"
51 #include "../include/cfg.h"
52 #include "../include/mar_gen.h"
53 #include "../include/ipc_gen.h"
54 #include "../include/ipc_cfg.h"
55 #include "../include/list.h"
56 #include "totem.h"
57 #include "totempg.h"
58 #include "flow.h"
59 #include "tlist.h"
60 #include "ipc.h"
61 #include "../include/queue.h"
62 #include "../lcr/lcr_comp.h"
63 #include "objdb.h"
64 #include "service.h"
65 #include "totempg.h"
66 #include "mempool.h"
67 #include "util.h"
68 #include "logsys.h"
69 #include "main.h"
71 LOGSYS_DECLARE_SUBSYS ("AMF", LOG_INFO);
73 enum cfg_message_req_types {
74 MESSAGE_REQ_EXEC_CFG_RINGREENABLE = 0
77 static void cfg_confchg_fn (
78 enum totem_configuration_type configuration_type,
79 unsigned int *member_list, int member_list_entries,
80 unsigned int *left_list, int left_list_entries,
81 unsigned int *joined_list, int joined_list_entries,
82 struct memb_ring_id *ring_id);
84 static int cfg_exec_init_fn (struct objdb_iface_ver0 *objdb);
86 static int cfg_lib_init_fn (void *conn);
88 static int cfg_lib_exit_fn (void *conn);
90 static void message_handler_req_exec_cfg_ringreenable (
91 void *message,
92 unsigned int nodeid);
94 static void message_handler_req_lib_cfg_ringstatusget (
95 void *conn,
96 void *msg);
98 static void message_handler_req_lib_cfg_ringreenable (
99 void *conn,
100 void *msg);
102 static void message_handler_req_lib_cfg_statetrack (
103 void *conn,
104 void *msg);
106 static void message_handler_req_lib_cfg_statetrackstop (
107 void *conn,
108 void *msg);
110 static void message_handler_req_lib_cfg_administrativestateset (
111 void *conn,
112 void *msg);
114 static void message_handler_req_lib_cfg_administrativestateget (
115 void *conn,
116 void *msg);
119 * Service Handler Definition
121 static struct openais_lib_handler cfg_lib_service[] =
123 { /* 0 */
124 .lib_handler_fn = message_handler_req_lib_cfg_ringstatusget,
125 .response_size = sizeof (struct res_lib_cfg_ringstatusget),
126 .response_id = MESSAGE_RES_CFG_RINGSTATUSGET,
127 .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
129 { /* 0 */
130 .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
131 .response_size = sizeof (struct res_lib_cfg_ringreenable),
132 .response_id = MESSAGE_RES_CFG_RINGREENABLE,
133 .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
135 { /* 0 */
136 .lib_handler_fn = message_handler_req_lib_cfg_statetrack,
137 .response_size = sizeof (struct res_lib_cfg_statetrack),
138 .response_id = MESSAGE_RES_CFG_STATETRACKSTART,
139 .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
141 { /* 1 */
142 .lib_handler_fn = message_handler_req_lib_cfg_statetrackstop,
143 .response_size = sizeof (struct res_lib_cfg_statetrackstop),
144 .response_id = MESSAGE_RES_CFG_STATETRACKSTOP,
145 .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
147 { /* 2 */
148 .lib_handler_fn = message_handler_req_lib_cfg_administrativestateset,
149 .response_size = sizeof (struct res_lib_cfg_administrativestateset),
150 .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATESET,
151 .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
153 { /* 3 */
154 .lib_handler_fn = message_handler_req_lib_cfg_administrativestateget,
155 .response_size = sizeof (struct res_lib_cfg_administrativestateget),
156 .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATEGET,
157 .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
161 static struct openais_exec_handler cfg_exec_service[] =
164 message_handler_req_exec_cfg_ringreenable
169 * Exports the interface for the service
171 struct openais_service_handler cfg_service_handler = {
172 .name = "openais configuration service",
173 .id = CFG_SERVICE,
174 .private_data_size = 0,
175 .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED,
176 .lib_init_fn = cfg_lib_init_fn,
177 .lib_exit_fn = cfg_lib_exit_fn,
178 .lib_service = cfg_lib_service,
179 .lib_service_count = sizeof (cfg_lib_service) / sizeof (struct openais_lib_handler),
180 .exec_init_fn = cfg_exec_init_fn,
181 .exec_service = cfg_exec_service,
182 .exec_service_count = 0, /* sizeof (cfg_aisexec_handler_fns) / sizeof (openais_exec_handler), */
183 .confchg_fn = cfg_confchg_fn,
187 * Dynamic Loader definition
189 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
195 static struct lcr_iface openais_cfg_ver0[1] = {
197 .name = "openais_cfg",
198 .version = 0,
199 .versions_replace = 0,
200 .versions_replace_count = 0,
201 .dependencies = 0,
202 .dependency_count = 0,
203 .constructor = NULL,
204 .destructor = NULL,
205 .interfaces = NULL
209 static struct lcr_comp cfg_comp_ver0 = {
210 .iface_count = 1,
211 .ifaces = openais_cfg_ver0
214 static struct openais_service_handler *cfg_get_handler_ver0 (void)
216 return (&cfg_service_handler);
219 __attribute__ ((constructor)) static void register_this_component (void) {
220 lcr_interfaces_set (&openais_cfg_ver0[0], &cfg_service_handler_iface);
222 lcr_component_register (&cfg_comp_ver0);
225 struct req_exec_cfg_ringreenable {
226 mar_req_header_t header __attribute__((aligned(8)));
227 mar_message_source_t source __attribute__((aligned(8)));
230 /* IMPL */
232 static int cfg_exec_init_fn (struct objdb_iface_ver0 *objdb)
234 return (0);
237 static void cfg_confchg_fn (
238 enum totem_configuration_type configuration_type,
239 unsigned int *member_list, int member_list_entries,
240 unsigned int *left_list, int left_list_entries,
241 unsigned int *joined_list, int joined_list_entries,
242 struct memb_ring_id *ring_id)
246 int cfg_lib_exit_fn (void *conn)
248 return (0);
251 static int cfg_lib_init_fn (void *conn)
254 ENTER("");
255 LEAVE("");
257 return (0);
261 * Executive message handlers
263 static void message_handler_req_exec_cfg_ringreenable (
264 void *message,
265 unsigned int nodeid)
267 struct req_exec_cfg_ringreenable *req_exec_cfg_ringreenable =
268 (struct req_exec_cfg_ringreenable *)message;
269 struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
271 ENTER("");
272 totempg_ring_reenable ();
273 if (message_source_is_local(&req_exec_cfg_ringreenable->source)) {
274 res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
275 res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
276 res_lib_cfg_ringreenable.header.error = SA_AIS_OK;
277 openais_conn_send_response (
278 req_exec_cfg_ringreenable->source.conn,
279 &res_lib_cfg_ringreenable,
280 sizeof (struct res_lib_cfg_ringreenable));
282 LEAVE("");
287 * Library Interface Implementation
289 static void message_handler_req_lib_cfg_ringstatusget (
290 void *conn,
291 void *msg)
293 struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
294 struct totem_ip_address interfaces[INTERFACE_MAX];
295 unsigned int iface_count;
296 char **status;
297 char *totem_ip_string;
298 unsigned int i;
300 ENTER("");
302 res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
303 res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
304 res_lib_cfg_ringstatusget.header.error = SA_AIS_OK;
306 totempg_ifaces_get (
307 totempg_my_nodeid_get(),
308 interfaces,
309 &status,
310 &iface_count);
312 res_lib_cfg_ringstatusget.interface_count = iface_count;
314 for (i = 0; i < iface_count; i++) {
315 totem_ip_string = (char *)totemip_print (&interfaces[i]);
316 strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
317 status[i]);
318 strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
319 totem_ip_string);
321 openais_conn_send_response (
322 conn,
323 &res_lib_cfg_ringstatusget,
324 sizeof (struct res_lib_cfg_ringstatusget));
326 LEAVE("");
329 static void message_handler_req_lib_cfg_ringreenable (
330 void *conn,
331 void *msg)
333 struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
334 struct iovec iovec;
336 ENTER("");
337 req_exec_cfg_ringreenable.header.size =
338 sizeof (struct req_exec_cfg_ringreenable);
339 req_exec_cfg_ringreenable.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
340 MESSAGE_REQ_EXEC_CFG_RINGREENABLE);
341 message_source_set (&req_exec_cfg_ringreenable.source, conn);
343 iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
344 iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
346 assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1,
347 TOTEMPG_SAFE) == 0);
349 LEAVE("");
352 static void message_handler_req_lib_cfg_statetrack (
353 void *conn,
354 void *msg)
356 // struct req_lib_cfg_statetrack *req_lib_cfg_statetrack = (struct req_lib_cfg_statetrack *)message;
358 ENTER("");
359 LEAVE("");
362 static void message_handler_req_lib_cfg_statetrackstop (
363 void *conn,
364 void *msg)
366 // struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
368 ENTER("");
369 LEAVE("");
372 static void message_handler_req_lib_cfg_administrativestateset (
373 void *conn,
374 void *msg)
376 // struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
377 ENTER("");
378 LEAVE("");
380 static void message_handler_req_lib_cfg_administrativestateget (
381 void *conn,
382 void *msg)
384 // struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;
385 ENTER("");
386 LEAVE("");