2 * Copyright (c) 2005-2006 MontaVista Software, Inc.
3 * Copyright (c) 2006 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 ("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 (
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 (
119 * Service Handler Definition
121 static struct openais_lib_handler cfg_lib_service
[] =
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
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
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
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
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
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",
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",
199 .versions_replace
= 0,
200 .versions_replace_count
= 0,
202 .dependency_count
= 0,
209 static struct lcr_comp cfg_comp_ver0
= {
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)));
232 static int cfg_exec_init_fn (struct objdb_iface_ver0
*objdb
)
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
)
251 static int cfg_lib_init_fn (void *conn
)
261 * Executive message handlers
263 static void message_handler_req_exec_cfg_ringreenable (
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
;
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
));
287 * Library Interface Implementation
289 static void message_handler_req_lib_cfg_ringstatusget (
293 struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget
;
294 struct totem_ip_address interfaces
[INTERFACE_MAX
];
295 unsigned int iface_count
;
297 char *totem_ip_string
;
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
;
307 totempg_my_nodeid_get(),
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
],
318 strcpy ((char *)&res_lib_cfg_ringstatusget
.interface_name
[i
],
321 openais_conn_send_response (
323 &res_lib_cfg_ringstatusget
,
324 sizeof (struct res_lib_cfg_ringstatusget
));
329 static void message_handler_req_lib_cfg_ringreenable (
333 struct req_exec_cfg_ringreenable req_exec_cfg_ringreenable
;
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,
352 static void message_handler_req_lib_cfg_statetrack (
356 // struct req_lib_cfg_statetrack *req_lib_cfg_statetrack = (struct req_lib_cfg_statetrack *)message;
362 static void message_handler_req_lib_cfg_statetrackstop (
366 // struct req_lib_cfg_statetrackstop *req_lib_cfg_statetrackstop = (struct req_lib_cfg_statetrackstop *)message;
372 static void message_handler_req_lib_cfg_administrativestateset (
376 // struct req_lib_cfg_administrativestateset *req_lib_cfg_administrativestateset = (struct req_lib_cfg_administrativestateset *)message;
380 static void message_handler_req_lib_cfg_administrativestateget (
384 // struct req_lib_cfg_administrativestateget *req_lib_cfg_administrativestateget = (struct req_lib_cfg_administrativestateget *)message;