2 * Copyright (c) 2008 Red Hat, Inc.
6 * Author: Christine Caulfield (ccaulfie@redhat.com)
8 * This software licensed under BSD license, the text of which follows:
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * - Neither the name of the MontaVista Software, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
41 #include "../include/saAis.h"
42 #include "../include/ipc_gen.h"
43 #include "../include/ipc_confdb.h"
44 #include "../include/mar_gen.h"
45 #include "../lcr/lcr_comp.h"
54 LOGSYS_DECLARE_SUBSYS ("CONFDB", LOG_INFO
);
56 static struct objdb_iface_ver0
*global_objdb
;
58 static int confdb_exec_init_fn (struct objdb_iface_ver0
*objdb
);
60 static int confdb_lib_init_fn (void *conn
);
61 static int confdb_lib_exit_fn (void *conn
);
63 static void message_handler_req_lib_confdb_object_create (void *conn
, void *message
);
64 static void message_handler_req_lib_confdb_object_destroy (void *conn
, void *message
);
66 static void message_handler_req_lib_confdb_key_create (void *conn
, void *message
);
67 static void message_handler_req_lib_confdb_key_get (void *conn
, void *message
);
68 static void message_handler_req_lib_confdb_key_replace (void *conn
, void *message
);
69 static void message_handler_req_lib_confdb_key_delete (void *conn
, void *message
);
70 static void message_handler_req_lib_confdb_key_iter (void *conn
, void *message
);
72 static void message_handler_req_lib_confdb_object_iter (void *conn
, void *message
);
73 static void message_handler_req_lib_confdb_object_find (void *conn
, void *message
);
75 static void message_handler_req_lib_confdb_object_parent_get (void *conn
, void *message
);
76 static void message_handler_req_lib_confdb_write (void *conn
, void *message
);
78 static void message_handler_req_lib_confdb_track_start (void *conn
, void *message
);
79 static void message_handler_req_lib_confdb_track_stop (void *conn
, void *message
);
83 * Library Handler Definition
85 static struct openais_lib_handler confdb_lib_service
[] =
88 .lib_handler_fn
= message_handler_req_lib_confdb_object_create
,
89 .response_size
= sizeof (mar_res_header_t
),
90 .response_id
= MESSAGE_RES_CONFDB_OBJECT_CREATE
,
91 .flow_control
= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
94 .lib_handler_fn
= message_handler_req_lib_confdb_object_destroy
,
95 .response_size
= sizeof (mar_res_header_t
),
96 .response_id
= MESSAGE_RES_CONFDB_OBJECT_DESTROY
,
97 .flow_control
= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
100 .lib_handler_fn
= message_handler_req_lib_confdb_object_find
,
101 .response_size
= sizeof (struct res_lib_confdb_object_find
),
102 .response_id
= MESSAGE_RES_CONFDB_OBJECT_FIND
,
103 .flow_control
= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
106 .lib_handler_fn
= message_handler_req_lib_confdb_key_create
,
107 .response_size
= sizeof (mar_res_header_t
),
108 .response_id
= MESSAGE_RES_CONFDB_KEY_CREATE
,
109 .flow_control
= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
112 .lib_handler_fn
= message_handler_req_lib_confdb_key_get
,
113 .response_size
= sizeof (struct res_lib_confdb_key_get
),
114 .response_id
= MESSAGE_RES_CONFDB_KEY_GET
,
115 .flow_control
= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
118 .lib_handler_fn
= message_handler_req_lib_confdb_key_replace
,
119 .response_size
= sizeof (mar_res_header_t
),
120 .response_id
= MESSAGE_RES_CONFDB_KEY_REPLACE
,
121 .flow_control
= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
124 .lib_handler_fn
= message_handler_req_lib_confdb_key_delete
,
125 .response_size
= sizeof (mar_res_header_t
),
126 .response_id
= MESSAGE_RES_CONFDB_KEY_DELETE
,
127 .flow_control
= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
130 .lib_handler_fn
= message_handler_req_lib_confdb_object_iter
,
131 .response_size
= sizeof (struct res_lib_confdb_object_iter
),
132 .response_id
= MESSAGE_RES_CONFDB_OBJECT_ITER
,
133 .flow_control
= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
136 .lib_handler_fn
= message_handler_req_lib_confdb_object_parent_get
,
137 .response_size
= sizeof (struct res_lib_confdb_object_parent_get
),
138 .response_id
= MESSAGE_RES_CONFDB_OBJECT_PARENT_GET
,
139 .flow_control
= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
142 .lib_handler_fn
= message_handler_req_lib_confdb_key_iter
,
143 .response_size
= sizeof (struct res_lib_confdb_key_iter
),
144 .response_id
= MESSAGE_RES_CONFDB_KEY_ITER
,
145 .flow_control
= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
148 .lib_handler_fn
= message_handler_req_lib_confdb_track_start
,
149 .response_size
= sizeof (mar_res_header_t
),
150 .response_id
= MESSAGE_RES_CONFDB_TRACK_START
,
151 .flow_control
= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
154 .lib_handler_fn
= message_handler_req_lib_confdb_track_stop
,
155 .response_size
= sizeof (mar_res_header_t
),
156 .response_id
= MESSAGE_RES_CONFDB_TRACK_START
,
157 .flow_control
= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
160 .lib_handler_fn
= message_handler_req_lib_confdb_write
,
161 .response_size
= sizeof (struct res_lib_confdb_write
),
162 .response_id
= MESSAGE_RES_CONFDB_WRITE
,
163 .flow_control
= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
168 struct openais_service_handler confdb_service_handler
= {
169 .name
= "openais cluster config database access v1.01",
170 .id
= CONFDB_SERVICE
,
171 .private_data_size
= 0,
172 .flow_control
= OPENAIS_FLOW_CONTROL_NOT_REQUIRED
,
173 .lib_init_fn
= confdb_lib_init_fn
,
174 .lib_exit_fn
= confdb_lib_exit_fn
,
175 .lib_service
= confdb_lib_service
,
176 .lib_service_count
= sizeof (confdb_lib_service
) / sizeof (struct openais_lib_handler
),
177 .exec_init_fn
= confdb_exec_init_fn
,
181 * Dynamic loader definition
183 static struct openais_service_handler
*confdb_get_service_handler_ver0 (void);
185 static struct openais_service_handler_iface_ver0 confdb_service_handler_iface
= {
186 .openais_get_service_handler_ver0
= confdb_get_service_handler_ver0
189 static struct lcr_iface openais_confdb_ver0
[1] = {
191 .name
= "openais_confdb",
193 .versions_replace
= 0,
194 .versions_replace_count
= 0,
196 .dependency_count
= 0,
203 static struct lcr_comp confdb_comp_ver0
= {
205 .ifaces
= openais_confdb_ver0
209 static struct openais_service_handler
*confdb_get_service_handler_ver0 (void)
211 return (&confdb_service_handler
);
214 __attribute__ ((constructor
)) static void confdb_comp_register (void) {
215 lcr_interfaces_set (&openais_confdb_ver0
[0], &confdb_service_handler_iface
);
217 lcr_component_register (&confdb_comp_ver0
);
220 static int confdb_exec_init_fn (struct objdb_iface_ver0
*objdb
)
222 global_objdb
= objdb
;
226 static int confdb_lib_init_fn (void *conn
)
228 log_printf(LOG_LEVEL_DEBUG
, "lib_init_fn: conn=%p\n", conn
);
232 static int confdb_lib_exit_fn (void *conn
)
235 log_printf(LOG_LEVEL_DEBUG
, "exit_fn for conn=%p\n", conn
);
239 static void message_handler_req_lib_confdb_object_create (void *conn
, void *message
)
241 struct req_lib_confdb_object_create
*req_lib_confdb_object_create
= (struct req_lib_confdb_object_create
*)message
;
242 struct res_lib_confdb_object_create res_lib_confdb_object_create
;
243 unsigned int object_handle
;
246 if (global_objdb
->object_create(req_lib_confdb_object_create
->parent_object_handle
,
248 req_lib_confdb_object_create
->object_name
.value
,
249 req_lib_confdb_object_create
->object_name
.length
))
250 ret
= SA_AIS_ERR_ACCESS
;
252 res_lib_confdb_object_create
.object_handle
= object_handle
;
253 res_lib_confdb_object_create
.header
.size
= sizeof(res_lib_confdb_object_create
);
254 res_lib_confdb_object_create
.header
.id
= MESSAGE_RES_CONFDB_OBJECT_CREATE
;
255 res_lib_confdb_object_create
.header
.error
= ret
;
256 openais_conn_send_response(conn
, &res_lib_confdb_object_create
, sizeof(res_lib_confdb_object_create
));
259 static void message_handler_req_lib_confdb_object_destroy (void *conn
, void *message
)
261 struct req_lib_confdb_object_destroy
*req_lib_confdb_object_destroy
= (struct req_lib_confdb_object_destroy
*)message
;
262 mar_res_header_t res
;
265 if (global_objdb
->object_destroy(req_lib_confdb_object_destroy
->object_handle
))
266 ret
= SA_AIS_ERR_ACCESS
;
268 res
.size
= sizeof(res
);
269 res
.id
= MESSAGE_RES_CONFDB_OBJECT_CREATE
;
271 openais_conn_send_response(conn
, &res
, sizeof(res
));
275 static void message_handler_req_lib_confdb_key_create (void *conn
, void *message
)
277 struct req_lib_confdb_key_create
*req_lib_confdb_key_create
= (struct req_lib_confdb_key_create
*)message
;
278 mar_res_header_t res
;
281 if (global_objdb
->object_key_create(req_lib_confdb_key_create
->object_handle
,
282 req_lib_confdb_key_create
->key_name
.value
,
283 req_lib_confdb_key_create
->key_name
.length
,
284 req_lib_confdb_key_create
->value
.value
,
285 req_lib_confdb_key_create
->value
.length
))
286 ret
= SA_AIS_ERR_ACCESS
;
288 res
.size
= sizeof(res
);
289 res
.id
= MESSAGE_RES_CONFDB_KEY_CREATE
;
291 openais_conn_send_response(conn
, &res
, sizeof(res
));
294 static void message_handler_req_lib_confdb_key_get (void *conn
, void *message
)
296 struct req_lib_confdb_key_get
*req_lib_confdb_key_get
= (struct req_lib_confdb_key_get
*)message
;
297 struct res_lib_confdb_key_get res_lib_confdb_key_get
;
302 if (global_objdb
->object_key_get(req_lib_confdb_key_get
->parent_object_handle
,
303 req_lib_confdb_key_get
->key_name
.value
,
304 req_lib_confdb_key_get
->key_name
.length
,
307 ret
= SA_AIS_ERR_ACCESS
;
309 memcpy(res_lib_confdb_key_get
.value
.value
, value
, value_len
);
310 res_lib_confdb_key_get
.value
.length
= value_len
;
313 res_lib_confdb_key_get
.header
.size
= sizeof(res_lib_confdb_key_get
);
314 res_lib_confdb_key_get
.header
.id
= MESSAGE_RES_CONFDB_KEY_GET
;
315 res_lib_confdb_key_get
.header
.error
= ret
;
316 openais_conn_send_response(conn
, &res_lib_confdb_key_get
, sizeof(res_lib_confdb_key_get
));
319 static void message_handler_req_lib_confdb_key_replace (void *conn
, void *message
)
321 struct req_lib_confdb_key_replace
*req_lib_confdb_key_replace
= (struct req_lib_confdb_key_replace
*)message
;
322 mar_res_header_t res
;
325 if (global_objdb
->object_key_replace(req_lib_confdb_key_replace
->object_handle
,
326 req_lib_confdb_key_replace
->key_name
.value
,
327 req_lib_confdb_key_replace
->key_name
.length
,
328 req_lib_confdb_key_replace
->old_value
.value
,
329 req_lib_confdb_key_replace
->old_value
.length
,
330 req_lib_confdb_key_replace
->new_value
.value
,
331 req_lib_confdb_key_replace
->new_value
.length
))
332 ret
= SA_AIS_ERR_ACCESS
;
334 res
.size
= sizeof(res
);
335 res
.id
= MESSAGE_RES_CONFDB_KEY_REPLACE
;
337 openais_conn_send_response(conn
, &res
, sizeof(res
));
340 static void message_handler_req_lib_confdb_key_delete (void *conn
, void *message
)
342 struct req_lib_confdb_key_delete
*req_lib_confdb_key_delete
= (struct req_lib_confdb_key_delete
*)message
;
343 mar_res_header_t res
;
346 if (global_objdb
->object_key_delete(req_lib_confdb_key_delete
->object_handle
,
347 req_lib_confdb_key_delete
->key_name
.value
,
348 req_lib_confdb_key_delete
->key_name
.length
,
349 req_lib_confdb_key_delete
->value
.value
,
350 req_lib_confdb_key_delete
->value
.length
))
351 ret
= SA_AIS_ERR_ACCESS
;
353 res
.size
= sizeof(res
);
354 res
.id
= MESSAGE_RES_CONFDB_KEY_DELETE
;
356 openais_conn_send_response(conn
, &res
, sizeof(res
));
359 static void message_handler_req_lib_confdb_object_parent_get (void *conn
, void *message
)
361 struct req_lib_confdb_object_parent_get
*req_lib_confdb_object_parent_get
= (struct req_lib_confdb_object_parent_get
*)message
;
362 struct res_lib_confdb_object_parent_get res_lib_confdb_object_parent_get
;
363 unsigned int object_handle
;
366 if (global_objdb
->object_parent_get(req_lib_confdb_object_parent_get
->object_handle
,
368 ret
= SA_AIS_ERR_ACCESS
;
370 res_lib_confdb_object_parent_get
.parent_object_handle
= object_handle
;
371 res_lib_confdb_object_parent_get
.header
.size
= sizeof(res_lib_confdb_object_parent_get
);
372 res_lib_confdb_object_parent_get
.header
.id
= MESSAGE_RES_CONFDB_OBJECT_CREATE
;
373 res_lib_confdb_object_parent_get
.header
.error
= ret
;
374 openais_conn_send_response(conn
, &res_lib_confdb_object_parent_get
, sizeof(res_lib_confdb_object_parent_get
));
378 static void message_handler_req_lib_confdb_key_iter (void *conn
, void *message
)
380 struct req_lib_confdb_key_iter
*req_lib_confdb_key_iter
= (struct req_lib_confdb_key_iter
*)message
;
381 struct res_lib_confdb_key_iter res_lib_confdb_key_iter
;
388 if (global_objdb
->object_key_iter_from(req_lib_confdb_key_iter
->parent_object_handle
,
389 req_lib_confdb_key_iter
->next_entry
,
394 ret
= SA_AIS_ERR_ACCESS
;
396 memcpy(res_lib_confdb_key_iter
.key_name
.value
, key_name
, key_name_len
);
397 memcpy(res_lib_confdb_key_iter
.value
.value
, value
, value_len
);
398 res_lib_confdb_key_iter
.key_name
.length
= key_name_len
;
399 res_lib_confdb_key_iter
.value
.length
= value_len
;
401 res_lib_confdb_key_iter
.header
.size
= sizeof(res_lib_confdb_key_iter
);
402 res_lib_confdb_key_iter
.header
.id
= MESSAGE_RES_CONFDB_KEY_ITER
;
403 res_lib_confdb_key_iter
.header
.error
= ret
;
405 openais_conn_send_response(conn
, &res_lib_confdb_key_iter
, sizeof(res_lib_confdb_key_iter
));
408 static void message_handler_req_lib_confdb_object_iter (void *conn
, void *message
)
410 struct req_lib_confdb_object_iter
*req_lib_confdb_object_iter
= (struct req_lib_confdb_object_iter
*)message
;
411 struct res_lib_confdb_object_iter res_lib_confdb_object_iter
;
416 if (global_objdb
->object_iter_from(req_lib_confdb_object_iter
->parent_object_handle
,
417 req_lib_confdb_object_iter
->next_entry
,
420 &res_lib_confdb_object_iter
.object_handle
))
421 ret
= SA_AIS_ERR_ACCESS
;
423 res_lib_confdb_object_iter
.object_name
.length
= object_name_len
;
424 memcpy(res_lib_confdb_object_iter
.object_name
.value
, object_name
, object_name_len
);
426 res_lib_confdb_object_iter
.header
.size
= sizeof(res_lib_confdb_object_iter
);
427 res_lib_confdb_object_iter
.header
.id
= MESSAGE_RES_CONFDB_OBJECT_ITER
;
428 res_lib_confdb_object_iter
.header
.error
= ret
;
430 openais_conn_send_response(conn
, &res_lib_confdb_object_iter
, sizeof(res_lib_confdb_object_iter
));
433 static void message_handler_req_lib_confdb_object_find (void *conn
, void *message
)
435 struct req_lib_confdb_object_find
*req_lib_confdb_object_find
= (struct req_lib_confdb_object_find
*)message
;
436 struct res_lib_confdb_object_find res_lib_confdb_object_find
;
439 if (global_objdb
->object_find_from(req_lib_confdb_object_find
->parent_object_handle
,
440 req_lib_confdb_object_find
->next_entry
,
441 req_lib_confdb_object_find
->object_name
.value
,
442 req_lib_confdb_object_find
->object_name
.length
,
443 &res_lib_confdb_object_find
.object_handle
,
444 &res_lib_confdb_object_find
.next_entry
))
445 ret
= SA_AIS_ERR_ACCESS
;
447 res_lib_confdb_object_find
.header
.size
= sizeof(res_lib_confdb_object_find
);
448 res_lib_confdb_object_find
.header
.id
= MESSAGE_RES_CONFDB_OBJECT_FIND
;
449 res_lib_confdb_object_find
.header
.error
= ret
;
451 openais_conn_send_response(conn
, &res_lib_confdb_object_find
, sizeof(res_lib_confdb_object_find
));
454 static void message_handler_req_lib_confdb_write (void *conn
, void *message
)
456 struct res_lib_confdb_write res_lib_confdb_write
;
460 if (global_objdb
->object_write_config(&error_string
))
461 ret
= SA_AIS_ERR_ACCESS
;
463 res_lib_confdb_write
.header
.size
= sizeof(res_lib_confdb_write
);
464 res_lib_confdb_write
.header
.id
= MESSAGE_RES_CONFDB_WRITE
;
465 res_lib_confdb_write
.header
.error
= ret
;
466 strcpy((char *)res_lib_confdb_write
.error
.value
, error_string
);
467 res_lib_confdb_write
.error
.length
= strlen(error_string
) + 1;
469 openais_conn_send_response(conn
, &res_lib_confdb_write
, sizeof(res_lib_confdb_write
));
472 /* TODO: when we have notification in the objdb. */
473 static void message_handler_req_lib_confdb_track_start (void *conn
, void *message
)
475 mar_res_header_t res
;
477 res
.size
= sizeof(res
);
478 res
.id
= MESSAGE_RES_CONFDB_TRACK_START
;
479 res
.error
= SA_AIS_ERR_NOT_SUPPORTED
;
480 openais_conn_send_response(conn
, &res
, sizeof(res
));
483 static void message_handler_req_lib_confdb_track_stop (void *conn
, void *message
)
485 mar_res_header_t res
;
487 res
.size
= sizeof(res
);
488 res
.id
= MESSAGE_RES_CONFDB_TRACK_STOP
;
489 res
.error
= SA_AIS_ERR_NOT_SUPPORTED
;
490 openais_conn_send_response(conn
, &res
, sizeof(res
));