Allow make from the exec directory.
[openais.git] / exec / cfg.c
blob6a43952b9c55af495b217aeab15721580a5bb4b5
1 /*
2 * Copyright (c) 2005-2006 MontaVista Software, Inc.
3 * Copyright (c) 2006-2007 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 ("CFG", 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);
118 static void message_handler_req_lib_cfg_serviceload (
119 void *conn,
120 void *msg);
122 static void message_handler_req_lib_cfg_serviceunload (
123 void *conn,
124 void *msg);
127 * Service Handler Definition
129 static struct openais_lib_handler cfg_lib_service[] =
131 { /* 0 */
132 .lib_handler_fn = message_handler_req_lib_cfg_ringstatusget,
133 .response_size = sizeof (struct res_lib_cfg_ringstatusget),
134 .response_id = MESSAGE_RES_CFG_RINGSTATUSGET,
135 .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
137 { /* 1 */
138 .lib_handler_fn = message_handler_req_lib_cfg_ringreenable,
139 .response_size = sizeof (struct res_lib_cfg_ringreenable),
140 .response_id = MESSAGE_RES_CFG_RINGREENABLE,
141 .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
143 { /* 2 */
144 .lib_handler_fn = message_handler_req_lib_cfg_statetrack,
145 .response_size = sizeof (struct res_lib_cfg_statetrack),
146 .response_id = MESSAGE_RES_CFG_STATETRACKSTART,
147 .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
149 { /* 3 */
150 .lib_handler_fn = message_handler_req_lib_cfg_statetrackstop,
151 .response_size = sizeof (struct res_lib_cfg_statetrackstop),
152 .response_id = MESSAGE_RES_CFG_STATETRACKSTOP,
153 .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
155 { /* 4 */
156 .lib_handler_fn = message_handler_req_lib_cfg_administrativestateset,
157 .response_size = sizeof (struct res_lib_cfg_administrativestateset),
158 .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATESET,
159 .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
161 { /* 5 */
162 .lib_handler_fn = message_handler_req_lib_cfg_administrativestateget,
163 .response_size = sizeof (struct res_lib_cfg_administrativestateget),
164 .response_id = MESSAGE_RES_CFG_ADMINISTRATIVESTATEGET,
165 .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
167 { /* 6 */
168 .lib_handler_fn = message_handler_req_lib_cfg_serviceload,
169 .response_size = sizeof (struct res_lib_cfg_serviceload),
170 .response_id = MESSAGE_RES_CFG_SERVICELOAD,
171 .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
173 { /* 7 */
174 .lib_handler_fn = message_handler_req_lib_cfg_serviceunload,
175 .response_size = sizeof (struct res_lib_cfg_serviceunload),
176 .response_id = MESSAGE_RES_CFG_SERVICEUNLOAD,
177 .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
181 static struct openais_exec_handler cfg_exec_service[] =
184 message_handler_req_exec_cfg_ringreenable
189 * Exports the interface for the service
191 struct openais_service_handler cfg_service_handler = {
192 .name = "openais configuration service",
193 .id = CFG_SERVICE,
194 .private_data_size = 0,
195 .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED,
196 .lib_init_fn = cfg_lib_init_fn,
197 .lib_exit_fn = cfg_lib_exit_fn,
198 .lib_service = cfg_lib_service,
199 .lib_service_count = sizeof (cfg_lib_service) / sizeof (struct openais_lib_handler),
200 .exec_init_fn = cfg_exec_init_fn,
201 .exec_service = cfg_exec_service,
202 .exec_service_count = 0, /* sizeof (cfg_aisexec_handler_fns) / sizeof (openais_exec_handler), */
203 .confchg_fn = cfg_confchg_fn,
206 static struct objdb_iface_ver0 *my_objdb;
209 * Dynamic Loader definition
211 static struct openais_service_handler *cfg_get_handler_ver0 (void);
213 static struct openais_service_handler_iface_ver0 cfg_service_handler_iface = {
214 .openais_get_service_handler_ver0 = cfg_get_handler_ver0
217 static struct lcr_iface openais_cfg_ver0[1] = {
219 .name = "openais_cfg",
220 .version = 0,
221 .versions_replace = 0,
222 .versions_replace_count = 0,
223 .dependencies = 0,
224 .dependency_count = 0,
225 .constructor = NULL,
226 .destructor = NULL,
227 .interfaces = NULL
231 static struct lcr_comp cfg_comp_ver0 = {
232 .iface_count = 1,
233 .ifaces = openais_cfg_ver0
236 static struct openais_service_handler *cfg_get_handler_ver0 (void)
238 return (&cfg_service_handler);
241 __attribute__ ((constructor)) static void register_this_component (void) {
242 lcr_interfaces_set (&openais_cfg_ver0[0], &cfg_service_handler_iface);
244 lcr_component_register (&cfg_comp_ver0);
247 struct req_exec_cfg_ringreenable {
248 mar_req_header_t header __attribute__((aligned(8)));
249 mar_message_source_t source __attribute__((aligned(8)));
252 /* IMPL */
254 static int cfg_exec_init_fn (struct objdb_iface_ver0 *objdb)
256 my_objdb = objdb;
257 return (0);
260 static void cfg_confchg_fn (
261 enum totem_configuration_type configuration_type,
262 unsigned int *member_list, int member_list_entries,
263 unsigned int *left_list, int left_list_entries,
264 unsigned int *joined_list, int joined_list_entries,
265 struct memb_ring_id *ring_id)
269 int cfg_lib_exit_fn (void *conn)
271 return (0);
274 static int cfg_lib_init_fn (void *conn)
277 ENTER("");
278 LEAVE("");
280 return (0);
284 * Executive message handlers
286 static void message_handler_req_exec_cfg_ringreenable (
287 void *message,
288 unsigned int nodeid)
290 struct req_exec_cfg_ringreenable *req_exec_cfg_ringreenable =
291 (struct req_exec_cfg_ringreenable *)message;
292 struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
294 ENTER("");
295 totempg_ring_reenable ();
296 if (message_source_is_local(&req_exec_cfg_ringreenable->source)) {
297 res_lib_cfg_ringreenable.header.id = MESSAGE_RES_CFG_RINGREENABLE;
298 res_lib_cfg_ringreenable.header.size = sizeof (struct res_lib_cfg_ringreenable);
299 res_lib_cfg_ringreenable.header.error = SA_AIS_OK;
300 openais_conn_send_response (
301 req_exec_cfg_ringreenable->source.conn,
302 &res_lib_cfg_ringreenable,
303 sizeof (struct res_lib_cfg_ringreenable));
305 LEAVE("");
310 * Library Interface Implementation
312 static void message_handler_req_lib_cfg_ringstatusget (
313 void *conn,
314 void *msg)
316 struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
317 struct totem_ip_address interfaces[INTERFACE_MAX];
318 unsigned int iface_count;
319 char **status;
320 char *totem_ip_string;
321 unsigned int i;
323 ENTER("");
325 res_lib_cfg_ringstatusget.header.id = MESSAGE_RES_CFG_RINGSTATUSGET;
326 res_lib_cfg_ringstatusget.header.size = sizeof (struct res_lib_cfg_ringstatusget);
327 res_lib_cfg_ringstatusget.header.error = SA_AIS_OK;
329 totempg_ifaces_get (
330 totempg_my_nodeid_get(),
331 interfaces,
332 &status,
333 &iface_count);
335 res_lib_cfg_ringstatusget.interface_count = iface_count;
337 for (i = 0; i < iface_count; i++) {
338 totem_ip_string = (char *)totemip_print (&interfaces[i]);
339 strcpy ((char *)&res_lib_cfg_ringstatusget.interface_status[i],
340 status[i]);
341 strcpy ((char *)&res_lib_cfg_ringstatusget.interface_name[i],
342 totem_ip_string);
344 openais_conn_send_response (
345 conn,
346 &res_lib_cfg_ringstatusget,
347 sizeof (struct res_lib_cfg_ringstatusget));
349 LEAVE("");
352 static void message_handler_req_lib_cfg_ringreenable (
353 void *conn,
354 void *msg)
356 struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable;
357 struct iovec iovec;
359 ENTER("");
360 req_exec_cfg_ringreenable.header.size =
361 sizeof (struct req_exec_cfg_ringreenable);
362 req_exec_cfg_ringreenable.header.id = SERVICE_ID_MAKE (CFG_SERVICE,
363 MESSAGE_REQ_EXEC_CFG_RINGREENABLE);
364 message_source_set (&req_exec_cfg_ringreenable.source, conn);
366 iovec.iov_base = (char *)&req_exec_cfg_ringreenable;
367 iovec.iov_len = sizeof (struct req_exec_cfg_ringreenable);
369 assert (totempg_groups_mcast_joined (openais_group_handle, &iovec, 1,
370 TOTEMPG_SAFE) == 0);
372 LEAVE("");
375 static void message_handler_req_lib_cfg_statetrack (
376 void *conn,
377 void *msg)
379 // struct req_lib_cfg_statetrack *req_lib_cfg_statetrack = (struct req_lib_cfg_statetrack *)message;
381 ENTER("");
382 LEAVE("");
385 static void message_handler_req_lib_cfg_statetrackstop (
386 void *conn,
387 void *msg)
389 // struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
391 ENTER("");
392 LEAVE("");
395 static void message_handler_req_lib_cfg_administrativestateset (
396 void *conn,
397 void *msg)
399 // struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
400 ENTER("");
401 LEAVE("");
403 static void message_handler_req_lib_cfg_administrativestateget (
404 void *conn,
405 void *msg)
407 // struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;
408 ENTER("");
409 LEAVE("");
412 static void message_handler_req_lib_cfg_serviceload (
413 void *conn,
414 void *msg)
416 struct req_lib_cfg_serviceload *req_lib_cfg_serviceload =
417 (struct req_lib_cfg_serviceload *)msg;
418 struct res_lib_cfg_serviceload res_lib_cfg_serviceload;
420 ENTER("");
421 openais_service_link_and_init (
422 my_objdb,
423 (char *)req_lib_cfg_serviceload->service_name,
424 req_lib_cfg_serviceload->service_ver);
426 res_lib_cfg_serviceload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
427 res_lib_cfg_serviceload.header.size = sizeof (struct res_lib_cfg_serviceload);
428 res_lib_cfg_serviceload.header.error = SA_AIS_OK;
429 openais_conn_send_response (
430 conn,
431 &res_lib_cfg_serviceload,
432 sizeof (struct res_lib_cfg_serviceload));
433 LEAVE("");
436 static void message_handler_req_lib_cfg_serviceunload (
437 void *conn,
438 void *msg)
440 struct req_lib_cfg_serviceunload *req_lib_cfg_serviceunload =
441 (struct req_lib_cfg_serviceunload *)msg;
442 struct res_lib_cfg_serviceunload res_lib_cfg_serviceunload;
444 ENTER("");
445 openais_service_unlink_and_exit (
446 my_objdb,
447 (char *)req_lib_cfg_serviceunload->service_name,
448 req_lib_cfg_serviceunload->service_ver);
449 res_lib_cfg_serviceunload.header.id = MESSAGE_RES_CFG_SERVICEUNLOAD;
450 res_lib_cfg_serviceunload.header.size = sizeof (struct res_lib_cfg_serviceunload);
451 res_lib_cfg_serviceunload.header.error = SA_AIS_OK;
452 openais_conn_send_response (
453 conn,
454 &res_lib_cfg_serviceunload,
455 sizeof (struct res_lib_cfg_serviceunload));
456 LEAVE("");