2 * Copyright (c) 2005-2006 MontaVista Software, Inc.
3 * Copyright (c) 2006-2007 Red Hat, Inc.
4 * Copyright (c) 2006 Sun Microsystems, Inc.
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>
38 #include <sys/socket.h>
40 #include <netinet/in.h>
41 #include <arpa/inet.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"
61 #include "../include/queue.h"
62 #include "../lcr/lcr_comp.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 (
94 static void message_handler_req_lib_cfg_ringstatusget (
98 static void message_handler_req_lib_cfg_ringreenable (
102 static void message_handler_req_lib_cfg_statetrack (
106 static void message_handler_req_lib_cfg_statetrackstop (
110 static void message_handler_req_lib_cfg_administrativestateset (
114 static void message_handler_req_lib_cfg_administrativestateget (
118 static void message_handler_req_lib_cfg_serviceload (
122 static void message_handler_req_lib_cfg_serviceunload (
127 * Service Handler Definition
129 static struct openais_lib_handler cfg_lib_service
[] =
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
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
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
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
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
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
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
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",
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",
221 .versions_replace
= 0,
222 .versions_replace_count
= 0,
224 .dependency_count
= 0,
231 static struct lcr_comp cfg_comp_ver0
= {
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)));
254 static int cfg_exec_init_fn (struct objdb_iface_ver0
*objdb
)
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
)
274 static int cfg_lib_init_fn (void *conn
)
284 * Executive message handlers
286 static void message_handler_req_exec_cfg_ringreenable (
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
;
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
));
310 * Library Interface Implementation
312 static void message_handler_req_lib_cfg_ringstatusget (
316 struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget
;
317 struct totem_ip_address interfaces
[INTERFACE_MAX
];
318 unsigned int iface_count
;
320 char *totem_ip_string
;
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
;
330 totempg_my_nodeid_get(),
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
],
341 strcpy ((char *)&res_lib_cfg_ringstatusget
.interface_name
[i
],
344 openais_conn_send_response (
346 &res_lib_cfg_ringstatusget
,
347 sizeof (struct res_lib_cfg_ringstatusget
));
352 static void message_handler_req_lib_cfg_ringreenable (
356 struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable
;
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,
375 static void message_handler_req_lib_cfg_statetrack (
379 // struct req_lib_cfg_statetrack *req_lib_cfg_statetrack = (struct req_lib_cfg_statetrack *)message;
385 static void message_handler_req_lib_cfg_statetrackstop (
389 // struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
395 static void message_handler_req_lib_cfg_administrativestateset (
399 // struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
403 static void message_handler_req_lib_cfg_administrativestateget (
407 // struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;
412 static void message_handler_req_lib_cfg_serviceload (
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
;
421 openais_service_link_and_init (
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 (
431 &res_lib_cfg_serviceload
,
432 sizeof (struct res_lib_cfg_serviceload
));
436 static void message_handler_req_lib_cfg_serviceunload (
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
;
445 openais_service_unlink_and_exit (
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 (
454 &res_lib_cfg_serviceunload
,
455 sizeof (struct res_lib_cfg_serviceunload
));