As promised here's the patch to add a limited subset of confdb facilities to whitetank. --
Chrissie
Index: test/Makefile =================================================================== --- test/Makefile (revision 1672) +++ test/Makefile (working copy) @@ -33,7 +33,7 @@ # include ../Makefile.inc -LIBRARIES= ../lib/libSaClm.a ../lib/libSaAmf.a ../lib/libSaCkpt.a ../lib/libSaEvt.a ../lib/libSaLck.a ../lib/libSaMsg.a ../lib/libevs.a ../lib/libcpg.a ../lib/libcfg.a +LIBRARIES= ../lib/libSaClm.a ../lib/libSaAmf.a ../lib/libSaCkpt.a ../lib/libSaEvt.a ../lib/libSaLck.a ../lib/libSaMsg.a ../lib/libevs.a ../lib/libcpg.a ../lib/libcfg.a ../lib/libconfdb.a LIBS = $(LIBRARIES) CFLAGS += -I../include @@ -45,13 +45,13 @@ testckpt.c ckptstress.c ckptbench.c \ ckptbenchth.c testevt.c testevs.c evsbench.c \ subscription.c publish.c evtbench.c \ - sa_error.c unlink.c testclm2.c testlck.c testmsg.c + sa_error.c unlink.c testclm2.c testlck.c testmsg.c testconfdb.c all: testclm testamf1 \ testckpt ckptstress ckptbench \ ckptbenchth ckpt-rd ckpt-wr ckpt-overload-exit testevt testevs \ evsbench subscription publish evtbench unlink testclm2 testlck \ - testmsg testcpg testcpg2 cpgbench openais-cfgtool + testmsg testcpg testcpg2 testconfdb cpgbench openais-cfgtool testtimer: testtimer.o $(LIBRARIES) $(CC) $(LDFLAGS) -o testtimer testtimer.o ../exec/timer.o @@ -146,6 +146,9 @@ testcpg2: testcpg2.o $(LIBRARIES) $(CC) $(LDFLAGS) -o testcpg2 testcpg2.o $(LIBS) +testconfdb: testconfdb.o $(LIBRARIES) + $(CC) $(LDFLAGS) -o testconfdb testconfdb.o $(LIBS) + cpgbench: cpgbench.o $(LIBRARIES) $(CC) $(LDFLAGS) -o cpgbench cpgbench.o $(LIBS) @@ -157,7 +160,7 @@ testamf5 testamf6 testamfth testckpt ckptstress testtimer \ ckptbench ckptbenchth testevt testevs ckpt-wr ckpt-rd \ evsbench subscription publish evtbench unlink testmsg testcpg \ - testclm2 testlck cpgbench openais-cfgtool + testclm2 testlck testconfdb cpgbench openais-cfgtool %.o: %.c $(CC) $(CFLAGS) $(CPPFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< Index: test/testconfdb.c =================================================================== --- test/testconfdb.c (revision 0) +++ test/testconfdb.c (revision 0) @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2008-2009 Red Hat Inc + * + * All rights reserved. + * + * Author: Christine Caulfield <[email protected]> + * + * This software licensed under BSD license, the text of which follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the MontaVista Software, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <signal.h> +#include <unistd.h> +#include <string.h> +#include <sys/types.h> +#include <sys/un.h> + +#include <corosync/corotypes.h> +#include <corosync/confdb.h> + + +int main (int argc, char *argv[]) { + confdb_handle_t handle; + int result; + unsigned int totem_handle; + unsigned int object_handle; + char key_value[256]; + int value_len; + + result = confdb_initialize (&handle, NULL); + if (result != CS_OK) { + printf ("Could not initialize Cluster Configuration Database API instance error %d\n", result); + exit (1); + } + + + if (argc == 1) { + + /* Find "totem" and dump bits of it again, to test the direct APIs */ + result = confdb_object_find_start(handle, OBJECT_PARENT_HANDLE); + if (result != CS_OK) { + printf ("Could not start object_find %d\n", result); + exit (1); + } + + result = confdb_object_find(handle, OBJECT_PARENT_HANDLE, "totem", strlen("totem"), &totem_handle); + if (result != CS_OK) { + printf ("Could not object_find \"totem\": %d\n", result); + exit (1); + } + + result = confdb_key_get(handle, totem_handle, "version", strlen("version"), key_value, &value_len); + if (result != CS_OK) { + printf ("Could not get \"version\" key: %d\n", result); + exit (1); + } + key_value[value_len] = '\0'; + printf("totem.version = '%s'\n", key_value); + + result = confdb_key_get(handle, totem_handle, "secauth", strlen("secauth"), key_value, &value_len); + if (result != CS_OK) { + printf ("Could not get \"secauth\" key: %d\n", result); + exit (1); + } + key_value[value_len] = '\0'; + printf("totem.secauth = '%s'\n", key_value); + } + else { + /* Use argv[1] as the object name, and argv[2...] as the key names and dump what we find + * (if anything). + */ + int i; + + result = confdb_object_find_start(handle, OBJECT_PARENT_HANDLE); + if (result != CS_OK) { + printf ("Could not start object_find %d\n", result); + exit (1); + } + + result = confdb_object_find(handle, OBJECT_PARENT_HANDLE, argv[1], strlen(argv[1]), &object_handle); + if (result != CS_OK) { + printf ("Could not find object \"%s\": %d\n", argv[1], result); + goto finish; + } + + i=1; + while (argv[++i]) { + result = confdb_key_get(handle, object_handle, argv[i], strlen(argv[i]), key_value, &value_len); + if (result != CS_OK) { + printf ("Could not get \"%s\" : %d\n", argv[i], result); + } + else { + key_value[value_len] = '\0'; + printf("%s.%s = '%s'\n", argv[1], argv[i], key_value); + } + } + } + +finish: + result = confdb_finalize (handle); + return (0); +} Index: include/confdb.h =================================================================== --- include/confdb.h (revision 0) +++ include/confdb.h (revision 0) @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2008 Red Hat, Inc. + * + * All rights reserved. + * + * Author: Christine Caulfield ([email protected]) + * + * This software licensed under BSD license, the text of which follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the MontaVista Software, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef OPENAIS_CONFDB_H_DEFINED +#define OPENAIS_CONFDB_H_DEFINED + +/** + * @addtogroup confdb_openais + * + * @{ + */ +typedef uint64_t confdb_handle_t; + +#define OBJECT_PARENT_HANDLE 0 + +typedef enum { + CONFDB_DISPATCH_ONE, + CONFDB_DISPATCH_ALL, + CONFDB_DISPATCH_BLOCKING +} confdb_dispatch_t; + +typedef enum { + CONFDB_OK = 1, + CONFDB_ERR_LIBRARY = 2, + CONFDB_ERR_TIMEOUT = 5, + CONFDB_ERR_TRY_AGAIN = 6, + CONFDB_ERR_INVALID_PARAM = 7, + CONFDB_ERR_NO_MEMORY = 8, + CONFDB_ERR_BAD_HANDLE = 9, + CONFDB_ERR_ACCESS = 11, + CONFDB_ERR_NOT_EXIST = 12, + CONFDB_ERR_EXIST = 14, + CONFDB_ERR_CONTEXT_NOT_FOUND = 17, + CONFDB_ERR_NOT_SUPPORTED = 20, + CONFDB_ERR_SECURITY = 29, +} confdb_error_t; + + +typedef void (*confdb_change_notify_fn_t) ( + confdb_handle_t handle, + unsigned int parent_object_handle, + unsigned int object_handle, + void *object_name, + int object_name_len, + void *key_name, + int key_name_len, + void *key_value, + int key_value_len); + +typedef struct { + confdb_change_notify_fn_t confdb_change_notify_fn; +} confdb_callbacks_t; + +/** @} */ + +/* + * Create a new confdb connection + */ +confdb_error_t confdb_initialize ( + confdb_handle_t *handle, + confdb_callbacks_t *callbacks); + +/* + * Close the confdb handle + */ +confdb_error_t confdb_finalize ( + confdb_handle_t handle); + + +/* + * Write back the configuration + */ +confdb_error_t confdb_write ( + confdb_handle_t handle, + char *error_text); + +/* + * Get a file descriptor on which to poll. confdb_handle_t is NOT a + * file descriptor and may not be used directly. + */ +confdb_error_t confdb_fd_get ( + confdb_handle_t handle, + int *fd); + +/* + * Dispatch configuration changes + */ +confdb_error_t confdb_dispatch ( + confdb_handle_t handle, + confdb_dispatch_t dispatch_types); + + +/* + * Change notification + */ +confdb_error_t confdb_track_changes ( + confdb_handle_t handle, + unsigned int object_handle, + unsigned int flags); + +confdb_error_t confdb_stop_track_changes ( + confdb_handle_t handle); + +/* + * Manipulate objects + */ +confdb_error_t confdb_object_create ( + confdb_handle_t handle, + unsigned int parent_object_handle, + void *object_name, + int object_name_len, + unsigned int *object_handle); + +confdb_error_t confdb_object_destroy ( + confdb_handle_t handle, + unsigned int object_handle); + +confdb_error_t confdb_object_parent_get ( + confdb_handle_t handle, + unsigned int object_handle, + unsigned int *parent_object_handle); + +/* + * Manipulate keys + */ +confdb_error_t confdb_key_create ( + confdb_handle_t handle, + unsigned int parent_object_handle, + void *key_name, + int key_name_len, + void *value, + int value_len); + +confdb_error_t confdb_key_delete ( + confdb_handle_t handle, + unsigned int parent_object_handle, + void *key_name, + int key_name_len, + void *value, + int value_len); + +/* + * Key queries + */ +confdb_error_t confdb_key_get ( + confdb_handle_t handle, + unsigned int parent_object_handle, + void *key_name, + int key_name_len, + void *value, + int *value_len); + +confdb_error_t confdb_key_replace ( + confdb_handle_t handle, + unsigned int parent_object_handle, + void *key_name, + int key_name_len, + void *old_value, + int old_value_len, + void *new_value, + int new_value_len); + +/* + * Object queries + * "find" loops through all objects of a given name and is also + * a quick way of finding a specific object, + * "iter" returns ech object in sequence. + */ +confdb_error_t confdb_object_find_start ( + confdb_handle_t handle, + unsigned int parent_object_handle); + +confdb_error_t confdb_object_find ( + confdb_handle_t handle, + unsigned int parent_object_handle, + void *object_name, + int object_name_len, + unsigned int *object_handle); + +confdb_error_t confdb_object_iter_start ( + confdb_handle_t handle, + unsigned int parent_object_handle); + +confdb_error_t confdb_object_iter ( + confdb_handle_t handle, + unsigned int parent_object_handle, + unsigned int *object_handle, + void *object_name, + int *object_name_len); + +/* + * Key iterator + */ +confdb_error_t confdb_key_iter_start ( + confdb_handle_t handle, + unsigned int object_handle); + +confdb_error_t confdb_key_iter ( + confdb_handle_t handle, + unsigned int parent_object_handle, + void *key_name, + int *key_name_len, + void *value, + int *value_len); + + +#endif /* OPENAIS_CONFDB_H_DEFINED */ Index: include/ipc_gen.h =================================================================== --- include/ipc_gen.h (revision 1672) +++ include/ipc_gen.h (working copy) @@ -45,7 +45,8 @@ LCK_SERVICE = 5, MSG_SERVICE = 6, CFG_SERVICE = 7, - CPG_SERVICE = 8 + CPG_SERVICE = 8, + CONFDB_SERVICE = 10 }; enum req_init_types { Index: include/ipc_confdb.h =================================================================== --- include/ipc_confdb.h (revision 0) +++ include/ipc_confdb.h (revision 0) @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2008-2009 Red Hat, Inc. + * + * All rights reserved. + * + * Author: Christine Caulfield ([email protected]) + * + * This software licensed under BSD license, the text of which follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the MontaVista Software, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef IPC_CONFDB_H_DEFINED +#define IPC_CONFDB_H_DEFINED + +#include <netinet/in.h> +#include "saAis.h" +#include "ipc_gen.h" + +enum req_confdb_types { + MESSAGE_REQ_CONFDB_OBJECT_CREATE = 0, + MESSAGE_REQ_CONFDB_OBJECT_DESTROY = 1, + MESSAGE_REQ_CONFDB_OBJECT_FIND = 2, + MESSAGE_REQ_CONFDB_KEY_CREATE = 3, + MESSAGE_REQ_CONFDB_KEY_GET = 4, + MESSAGE_REQ_CONFDB_OBJECT_FIND_RESET = 5 +}; + +enum res_confdb_types { + MESSAGE_RES_CONFDB_OBJECT_CREATE = 0, + MESSAGE_RES_CONFDB_OBJECT_DESTROY = 1, + MESSAGE_RES_CONFDB_OBJECT_FIND = 2, + MESSAGE_RES_CONFDB_KEY_CREATE = 3, + MESSAGE_RES_CONFDB_KEY_GET = 4, + MESSAGE_RES_CONFDB_OBJECT_FIND_RESET = 5 +}; + +struct req_lib_confdb_object_create { + mar_req_header_t header __attribute__((aligned(8))); + mar_uint32_t parent_object_handle __attribute__((aligned(8))); + mar_name_t object_name __attribute__((aligned(8))); +}; + +struct res_lib_confdb_object_create { + mar_res_header_t header __attribute__((aligned(8))); + mar_uint32_t object_handle __attribute__((aligned(8))); +}; + +struct req_lib_confdb_object_destroy { + mar_req_header_t header __attribute__((aligned(8))); + mar_uint32_t object_handle __attribute__((aligned(8))); +}; + +struct req_lib_confdb_key_create { + mar_req_header_t header __attribute__((aligned(8))); + mar_uint32_t object_handle __attribute__((aligned(8))); + mar_name_t key_name __attribute__((aligned(8))); + mar_name_t value __attribute__((aligned(8))); +}; + +struct req_lib_confdb_key_delete { + mar_req_header_t header __attribute__((aligned(8))); + mar_uint32_t object_handle __attribute__((aligned(8))); + mar_name_t key_name __attribute__((aligned(8))); + mar_name_t value __attribute__((aligned(8))); +}; + +struct req_lib_confdb_object_find { + mar_req_header_t header __attribute__((aligned(8))); + mar_uint32_t parent_object_handle __attribute__((aligned(8))); + mar_name_t object_name __attribute__((aligned(8))); +}; + +struct res_lib_confdb_object_find { + mar_res_header_t header __attribute__((aligned(8))); + mar_uint32_t object_handle __attribute__((aligned(8))); +}; + +struct req_lib_confdb_object_find_reset { + mar_res_header_t header __attribute__((aligned(8))); + mar_uint32_t object_handle __attribute__((aligned(8))); +}; + +struct res_lib_confdb_object_find_reset { + mar_res_header_t header __attribute__((aligned(8))); +}; + +struct req_lib_confdb_key_get { + mar_req_header_t header __attribute__((aligned(8))); + mar_uint32_t parent_object_handle __attribute__((aligned(8))); + mar_name_t key_name __attribute__((aligned(8))); +}; + +struct res_lib_confdb_key_get { + mar_res_header_t header __attribute__((aligned(8))); + mar_name_t value __attribute__((aligned(8))); +}; + + +#endif /* IPC_CONFDB_H_DEFINED */ Index: exec/Makefile =================================================================== --- exec/Makefile (revision 1672) +++ exec/Makefile (working copy) @@ -54,8 +54,8 @@ AMF_OBJS = amf.o amfutil.o amfnode.o amfcluster.o amfapp.o amfsg.o amfsu.o amfcomp.o amfsi.o # LCR objects -LCR_SRC = evs.c clm.c ckpt.c evt.c lck.c msg.c cfg.c cpg.c aisparser.c vsf_ykd.c $(AMF_SRC) -LCR_OBJS = evs.o clm.o ckpt.o evt.o lck.o msg.o cfg.o cpg.o aisparser.o vsf_ykd.o $(AMF_OBJS) +LCR_SRC = evs.c clm.c ckpt.c evt.c lck.c msg.c cfg.c cpg.c aisparser.c vsf_ykd.c confdb.c $(AMF_SRC) +LCR_OBJS = evs.o clm.o ckpt.o evt.o lck.o msg.o cfg.o cpg.o aisparser.o vsf_ykd.o confdb.o $(AMF_OBJS) # main executive objects MAIN_SRC = main.c print.c mempool.c util.c sync.c service.c ipc.c flow.c timer.c \ @@ -72,7 +72,7 @@ aisexec \ service_evs.lcrso service_clm.lcrso service_amf.lcrso \ service_ckpt.lcrso service_evt.lcrso service_lck.lcrso \ - service_msg.lcrso service_cfg.lcrso service_cpg.lcrso \ + service_msg.lcrso service_cfg.lcrso service_cpg.lcrso service_confdb.lcrso \ objdb.lcrso aisparser.lcrso vsf_ykd.lcrso keygen openais-instantiate else EXEC_OBJS = $(TOTEM_OBJS) $(MAIN_OBJS) $(OTHER_OBJS) $(LCR_OBJS) @@ -109,6 +109,9 @@ service_cpg.lcrso: cpg.o $(CC) $(LDFLAGS) -bundle $(LDFLAGS) -bundle_loader ./aisexec -bind_at_load cpg.o -o $@ +service_confdb.lcrso: confdb.o + $(CC) $(LDFLAGS) -bundle $(LDFLAGS) -bundle_loader ./aisexec -bind_at_load confdb.o -o $@ + aisparser.lcrso: aisparser.o $(CC) $(LDFLAGS) -bundle $(LDFLAGS) -bundle_loader ./aisexec -bind_at_load aisparser.o -o $@ @@ -148,6 +151,9 @@ service_cpg.lcrso: cpg.o $(CC) -shared -Wl,-soname,service_cpg.lcrso cpg.o -o $@ +service_confdb.lcrso: confdb.o + $(CC) -shared -Wl,-soname,service_confdb.lcrso confdb.o -o $@ + aisparser.lcrso: aisparser.o $(CC) -shared -Wl,-soname,aisparser.lcrso aisparser.o -o $@ @@ -229,6 +235,9 @@ objdb.o: objdb.c $(CC) $(CFLAGS) -c -o $@ $(*F).c +confdb.o: confdb.c + $(CC) $(CFLAGS) -c -o $@ $(*F).c + # -fPIC rules required for lib totem aispoll.o: aispoll.c $(CC) $(CFLAGS) $(CPPFLAGS) -fPIC -c -o $@ $(*F).c Index: exec/service.c =================================================================== --- exec/service.c (revision 1672) +++ exec/service.c (working copy) @@ -84,6 +84,10 @@ { .name = "openais_cpg", .ver = 0, + }, + { + .name = "openais_confdb", + .ver = 0, } }; Index: exec/confdb.c =================================================================== --- exec/confdb.c (revision 0) +++ exec/confdb.c (revision 0) @@ -0,0 +1,309 @@ +/* + * Copyright (c) 2008-2009 Red Hat, Inc. + * + * All rights reserved. + * + * Author: Christine Caulfield ([email protected]) + * + * This software licensed under BSD license, the text of which follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the MontaVista Software, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ +#include <sys/types.h> +#include <unistd.h> +#include <fcntl.h> +#include <stdlib.h> +#include <errno.h> +#include <unistd.h> + +#include "../include/saAis.h" +#include "../include/ipc_gen.h" +#include "../include/ipc_confdb.h" +#include "../include/mar_gen.h" +#include "../lcr/lcr_comp.h" +#include "main.h" +#include "flow.h" +#include "ipc.h" +#include "objdb.h" +#include "service.h" +#include "ipc.h" +#include "print.h" + +static struct objdb_iface_ver0 *global_objdb; + +static int confdb_exec_init_fn (struct objdb_iface_ver0 *objdb); + +static int confdb_lib_init_fn (void *conn); +static int confdb_lib_exit_fn (void *conn); + +static void message_handler_req_lib_confdb_object_create (void *conn, void *message); +static void message_handler_req_lib_confdb_object_destroy (void *conn, void *message); +static void message_handler_req_lib_confdb_object_find (void *conn, void *message); +static void message_handler_req_lib_confdb_object_find_reset (void *conn, void *message); + +static void message_handler_req_lib_confdb_key_create (void *conn, void *message); +static void message_handler_req_lib_confdb_key_get (void *conn, void *message); + + +/* + * Library Handler Definition + */ +static struct openais_lib_handler confdb_lib_service[] = +{ + { /* 0 */ + .lib_handler_fn = message_handler_req_lib_confdb_object_create, + .response_size = sizeof (mar_res_header_t), + .response_id = MESSAGE_RES_CONFDB_OBJECT_CREATE, + .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED + }, + { /* 1 */ + .lib_handler_fn = message_handler_req_lib_confdb_object_destroy, + .response_size = sizeof (mar_res_header_t), + .response_id = MESSAGE_RES_CONFDB_OBJECT_DESTROY, + .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED + }, + { /* 2 */ + .lib_handler_fn = message_handler_req_lib_confdb_object_find, + .response_size = sizeof (struct res_lib_confdb_object_find), + .response_id = MESSAGE_RES_CONFDB_OBJECT_FIND, + .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED + }, + { /* 3 */ + .lib_handler_fn = message_handler_req_lib_confdb_key_create, + .response_size = sizeof (mar_res_header_t), + .response_id = MESSAGE_RES_CONFDB_KEY_CREATE, + .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED + }, + { /* 4 */ + .lib_handler_fn = message_handler_req_lib_confdb_key_get, + .response_size = sizeof (struct res_lib_confdb_key_get), + .response_id = MESSAGE_RES_CONFDB_KEY_GET, + .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED + }, + { /* 5 */ + .lib_handler_fn = message_handler_req_lib_confdb_object_find_reset, + .response_size = sizeof (struct res_lib_confdb_object_find_reset), + .response_id = MESSAGE_RES_CONFDB_OBJECT_FIND_RESET, + .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED + } +}; + + +struct openais_service_handler confdb_service_handler = { + .name = (unsigned char *)"openais cluster config database access v1.01", + .id = CONFDB_SERVICE, + .private_data_size = 0, + .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED, + .lib_init_fn = confdb_lib_init_fn, + .lib_exit_fn = confdb_lib_exit_fn, + .lib_service = confdb_lib_service, + .lib_service_count = sizeof (confdb_lib_service) / sizeof (struct openais_lib_handler), + .exec_init_fn = confdb_exec_init_fn, +}; + +/* + * Dynamic loader definition + */ +static struct openais_service_handler *confdb_get_service_handler_ver0 (void); + +static struct openais_service_handler_iface_ver0 confdb_service_handler_iface = { + .openais_get_service_handler_ver0 = confdb_get_service_handler_ver0 +}; + +static struct lcr_iface openais_confdb_ver0[1] = { + { + .name = "openais_confdb", + .version = 0, + .versions_replace = 0, + .versions_replace_count = 0, + .dependencies = 0, + .dependency_count = 0, + .constructor = NULL, + .destructor = NULL, + .interfaces = NULL + } +}; + +static struct lcr_comp confdb_comp_ver0 = { + .iface_count = 1, + .ifaces = openais_confdb_ver0 +}; + + +static struct openais_service_handler *confdb_get_service_handler_ver0 (void) +{ + return (&confdb_service_handler); +} + +__attribute__ ((constructor)) static void confdb_comp_register (void) { + lcr_interfaces_set (&openais_confdb_ver0[0], &confdb_service_handler_iface); + + lcr_component_register (&confdb_comp_ver0); +} + +static int confdb_exec_init_fn (struct objdb_iface_ver0 *objdb) +{ + global_objdb = objdb; + return 0; +} + +static int confdb_lib_init_fn (void *conn) +{ + log_printf(LOG_LEVEL_DEBUG, "lib_init_fn: conn=%p\n", conn); + return (0); +} + +static int confdb_lib_exit_fn (void *conn) +{ + + log_printf(LOG_LEVEL_DEBUG, "exit_fn for conn=%p\n", conn); + return (0); +} + +static void message_handler_req_lib_confdb_object_create (void *conn, void *message) +{ + struct req_lib_confdb_object_create *req_lib_confdb_object_create = (struct req_lib_confdb_object_create *)message; + struct res_lib_confdb_object_create res_lib_confdb_object_create; + unsigned int object_handle; + int ret = SA_AIS_OK; + + if (global_objdb->object_create(req_lib_confdb_object_create->parent_object_handle, + &object_handle, + req_lib_confdb_object_create->object_name.value, + req_lib_confdb_object_create->object_name.length)) + ret = SA_AIS_ERR_ACCESS; + + res_lib_confdb_object_create.object_handle = object_handle; + res_lib_confdb_object_create.header.size = sizeof(res_lib_confdb_object_create); + res_lib_confdb_object_create.header.id = MESSAGE_RES_CONFDB_OBJECT_CREATE; + res_lib_confdb_object_create.header.error = ret; + openais_response_send(conn, &res_lib_confdb_object_create, sizeof(res_lib_confdb_object_create)); +} + +static void message_handler_req_lib_confdb_object_destroy (void *conn, void *message) +{ + struct req_lib_confdb_object_destroy *req_lib_confdb_object_destroy = (struct req_lib_confdb_object_destroy *)message; + mar_res_header_t res; + int ret = SA_AIS_OK; + + if (global_objdb->object_destroy(req_lib_confdb_object_destroy->object_handle)) + ret = SA_AIS_ERR_ACCESS; + + res.size = sizeof(res); + res.id = MESSAGE_RES_CONFDB_OBJECT_CREATE; + res.error = ret; + openais_response_send(conn, &res, sizeof(res)); +} + + +static void message_handler_req_lib_confdb_key_create (void *conn, void *message) +{ + struct req_lib_confdb_key_create *req_lib_confdb_key_create = (struct req_lib_confdb_key_create *)message; + mar_res_header_t res; + int ret = SA_AIS_OK; + + if (global_objdb->object_key_create(req_lib_confdb_key_create->object_handle, + req_lib_confdb_key_create->key_name.value, + req_lib_confdb_key_create->key_name.length, + req_lib_confdb_key_create->value.value, + req_lib_confdb_key_create->value.length)) + ret = SA_AIS_ERR_ACCESS; + + res.size = sizeof(res); + res.id = MESSAGE_RES_CONFDB_KEY_CREATE; + res.error = ret; + openais_response_send(conn, &res, sizeof(res)); +} + +static void message_handler_req_lib_confdb_key_get (void *conn, void *message) +{ + struct req_lib_confdb_key_get *req_lib_confdb_key_get = (struct req_lib_confdb_key_get *)message; + struct res_lib_confdb_key_get res_lib_confdb_key_get; + int value_len; + void *value = NULL; + int ret = SA_AIS_OK; + + log_printf(LOG_LEVEL_DEBUG, "confdb_key_get: conn=%p, name=%s\n", conn, req_lib_confdb_key_get->key_name.value); + + global_objdb->object_key_get(req_lib_confdb_key_get->parent_object_handle, + req_lib_confdb_key_get->key_name.value, + req_lib_confdb_key_get->key_name.length, + &value, + &value_len); + if (value) { + memcpy(res_lib_confdb_key_get.value.value, value, value_len); + res_lib_confdb_key_get.value.length = value_len; + } + else { + ret = SA_AIS_ERR_ACCESS; + } + + res_lib_confdb_key_get.header.size = sizeof(res_lib_confdb_key_get); + res_lib_confdb_key_get.header.id = MESSAGE_RES_CONFDB_KEY_GET; + res_lib_confdb_key_get.header.error = ret; + openais_response_send(conn, &res_lib_confdb_key_get, sizeof(res_lib_confdb_key_get)); +} + + +static void message_handler_req_lib_confdb_object_find (void *conn, void *message) +{ + struct req_lib_confdb_object_find *req_lib_confdb_object_find = (struct req_lib_confdb_object_find *)message; + struct res_lib_confdb_object_find res_lib_confdb_object_find; + int ret = SA_AIS_OK; + + log_printf(LOG_LEVEL_DEBUG, "confdb_object_find: conn=%p, name=(%d) '%s'\n", conn, req_lib_confdb_object_find->object_name.length, req_lib_confdb_object_find->object_name.value); + + if (global_objdb->object_find(req_lib_confdb_object_find->parent_object_handle, + req_lib_confdb_object_find->object_name.value, + req_lib_confdb_object_find->object_name.length, + &res_lib_confdb_object_find.object_handle)) + ret = SA_AIS_ERR_ACCESS; + + res_lib_confdb_object_find.header.size = sizeof(res_lib_confdb_object_find); + res_lib_confdb_object_find.header.id = MESSAGE_RES_CONFDB_OBJECT_FIND; + res_lib_confdb_object_find.header.error = ret; + + openais_response_send(conn, &res_lib_confdb_object_find, sizeof(res_lib_confdb_object_find)); +} + + +static void message_handler_req_lib_confdb_object_find_reset (void *conn, void *message) +{ + struct req_lib_confdb_object_find_reset *req_lib_confdb_object_find_reset = (struct req_lib_confdb_object_find_reset *)message; + struct res_lib_confdb_object_find_reset res_lib_confdb_object_find_reset; + int ret = SA_AIS_OK; + + log_printf(LOG_LEVEL_DEBUG, "confdb_object_find_reset: conn=%p, object=%d\n", conn, req_lib_confdb_object_find_reset->object_handle); + + if (global_objdb->object_find_reset(req_lib_confdb_object_find_reset->object_handle)) + ret = SA_AIS_ERR_ACCESS; + + res_lib_confdb_object_find_reset.header.size = sizeof(res_lib_confdb_object_find_reset); + res_lib_confdb_object_find_reset.header.id = MESSAGE_RES_CONFDB_OBJECT_FIND_RESET; + res_lib_confdb_object_find_reset.header.error = ret; + + openais_response_send(conn, &res_lib_confdb_object_find_reset, sizeof(res_lib_confdb_object_find_reset)); +} + Index: lib/confdb.c =================================================================== --- lib/confdb.c (revision 0) +++ lib/confdb.c (revision 0) @@ -0,0 +1,432 @@ +/* + * Copyright (c) 2008-2009 Red Hat, Inc. + * + * All rights reserved. + * + * Author: Christine Caulfield ([email protected]) + * + * This software licensed under BSD license, the text of which follows: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the MontaVista Software, Inc. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Provides access to data in the openais object database + */ + +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <pthread.h> +#include <sys/types.h> +#include <errno.h> + +#include "../include/saAis.h" +#include "../include/confdb.h" +#include "../include/ipc_confdb.h" +#include "../include/mar_gen.h" +#include "util.h" + +struct confdb_inst { + int response_fd; + int dispatch_fd; + int finalize; + pthread_mutex_t response_mutex; + pthread_mutex_t dispatch_mutex; +}; + +static void confdb_instance_destructor (void *instance); + +static struct saHandleDatabase confdb_handle_t_db = { + .handleCount = 0, + .handles = 0, + .mutex = PTHREAD_MUTEX_INITIALIZER, + .handleInstanceDestructor = confdb_instance_destructor +}; + +/* + * Clean up function for a confdb instance (confdb_initialize) handle + */ +static void confdb_instance_destructor (void *instance) +{ + struct confdb_inst *confdb_inst = instance; + + pthread_mutex_destroy (&confdb_inst->response_mutex); + pthread_mutex_destroy (&confdb_inst->dispatch_mutex); +} + +/** + * @defgroup confdb_openais + * @ingroup openais + * + * @{ + */ + +confdb_error_t confdb_initialize ( + confdb_handle_t *handle, + confdb_callbacks_t *callbacks) +{ + SaAisErrorT error; + struct confdb_inst *confdb_inst; + + error = saHandleCreate (&confdb_handle_t_db, sizeof (struct confdb_inst), handle); + if (error != SA_AIS_OK) { + goto error_no_destroy; + } + + error = saHandleInstanceGet (&confdb_handle_t_db, *handle, (void *)&confdb_inst); + if (error != SA_AIS_OK) { + goto error_destroy; + } + + error = saServiceConnect ( &confdb_inst->response_fd, + &confdb_inst->dispatch_fd, + CONFDB_SERVICE); + + if (error != SA_AIS_OK) + goto error_put_destroy; + + pthread_mutex_init (&confdb_inst->response_mutex, NULL); + pthread_mutex_init (&confdb_inst->dispatch_mutex, NULL); + + saHandleInstancePut (&confdb_handle_t_db, *handle); + + return (SA_AIS_OK); + +error_put_destroy: + saHandleInstancePut (&confdb_handle_t_db, *handle); +error_destroy: + saHandleDestroy (&confdb_handle_t_db, *handle); +error_no_destroy: + return (error); +} + +confdb_error_t confdb_finalize ( + confdb_handle_t handle) +{ + struct confdb_inst *confdb_inst; + SaAisErrorT error; + + error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst); + if (error != SA_AIS_OK) { + return (error); + } + + pthread_mutex_lock (&confdb_inst->response_mutex); + + /* + * Another thread has already started finalizing + */ + if (confdb_inst->finalize) { + pthread_mutex_unlock (&confdb_inst->response_mutex); + saHandleInstancePut (&confdb_handle_t_db, handle); + return (CONFDB_ERR_BAD_HANDLE); + } + + confdb_inst->finalize = 1; + + pthread_mutex_unlock (&confdb_inst->response_mutex); + + saHandleDestroy (&confdb_handle_t_db, handle); + + saHandleInstancePut (&confdb_handle_t_db, handle); + + return (CONFDB_OK); +} + +confdb_error_t confdb_object_create ( + confdb_handle_t handle, + unsigned int parent_object_handle, + void *object_name, + int object_name_len, + unsigned int *object_handle) +{ + confdb_error_t error; + struct confdb_inst *confdb_inst; + struct iovec iov[2]; + struct req_lib_confdb_object_create req_lib_confdb_object_create; + struct res_lib_confdb_object_create res_lib_confdb_object_create; + + error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst); + if (error != SA_AIS_OK) { + return (error); + } + + req_lib_confdb_object_create.header.size = sizeof (struct req_lib_confdb_object_create); + req_lib_confdb_object_create.header.id = MESSAGE_REQ_CONFDB_OBJECT_CREATE; + req_lib_confdb_object_create.parent_object_handle = parent_object_handle; + memcpy(req_lib_confdb_object_create.object_name.value, object_name, object_name_len); + req_lib_confdb_object_create.object_name.length = object_name_len; + + iov[0].iov_base = (char *)&req_lib_confdb_object_create; + iov[0].iov_len = sizeof (struct req_lib_confdb_object_create); + + pthread_mutex_lock (&confdb_inst->response_mutex); + + error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1, + &res_lib_confdb_object_create, sizeof (struct res_lib_confdb_object_create)); + + pthread_mutex_unlock (&confdb_inst->response_mutex); + if (error != SA_AIS_OK) { + goto error_exit; + } + + error = res_lib_confdb_object_create.header.error; + *object_handle = res_lib_confdb_object_create.object_handle; + +error_exit: + saHandleInstancePut (&confdb_handle_t_db, handle); + + return (error); +} + +confdb_error_t confdb_object_destroy ( + confdb_handle_t handle, + unsigned int object_handle) +{ + confdb_error_t error; + struct confdb_inst *confdb_inst; + struct iovec iov[2]; + struct req_lib_confdb_object_destroy req_lib_confdb_object_destroy; + mar_res_header_t res; + + error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst); + if (error != SA_AIS_OK) { + return (error); + } + + req_lib_confdb_object_destroy.header.size = sizeof (struct req_lib_confdb_object_destroy); + req_lib_confdb_object_destroy.header.id = MESSAGE_REQ_CONFDB_OBJECT_DESTROY; + req_lib_confdb_object_destroy.object_handle = object_handle; + + iov[0].iov_base = (char *)&req_lib_confdb_object_destroy; + iov[0].iov_len = sizeof (struct req_lib_confdb_object_destroy); + + pthread_mutex_lock (&confdb_inst->response_mutex); + + error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1, + &res, sizeof ( mar_res_header_t)); + + pthread_mutex_unlock (&confdb_inst->response_mutex); + if (error != SA_AIS_OK) { + goto error_exit; + } + + error = res.error; + +error_exit: + saHandleInstancePut (&confdb_handle_t_db, handle); + + return (error); +} + + +confdb_error_t confdb_key_create ( + confdb_handle_t handle, + unsigned int parent_object_handle, + void *key_name, + int key_name_len, + void *value, + int value_len) +{ + confdb_error_t error; + struct confdb_inst *confdb_inst; + struct iovec iov[2]; + struct req_lib_confdb_key_create req_lib_confdb_key_create; + mar_res_header_t res; + + error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst); + if (error != SA_AIS_OK) { + return (error); + } + + req_lib_confdb_key_create.header.size = sizeof (struct req_lib_confdb_key_create); + req_lib_confdb_key_create.header.id = MESSAGE_REQ_CONFDB_KEY_CREATE; + req_lib_confdb_key_create.object_handle = parent_object_handle; + memcpy(req_lib_confdb_key_create.key_name.value, key_name, key_name_len); + req_lib_confdb_key_create.key_name.length = key_name_len; + memcpy(req_lib_confdb_key_create.value.value, value, value_len); + req_lib_confdb_key_create.value.length = value_len; + + iov[0].iov_base = (char *)&req_lib_confdb_key_create; + iov[0].iov_len = sizeof (struct req_lib_confdb_key_create); + + pthread_mutex_lock (&confdb_inst->response_mutex); + + error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1, + &res, sizeof (res)); + + pthread_mutex_unlock (&confdb_inst->response_mutex); + if (error != SA_AIS_OK) { + goto error_exit; + } + + error = res.error; + +error_exit: + saHandleInstancePut (&confdb_handle_t_db, handle); + + return (error); +} + +confdb_error_t confdb_key_get ( + confdb_handle_t handle, + unsigned int parent_object_handle, + void *key_name, + int key_name_len, + void *value, + int *value_len) +{ + confdb_error_t error; + struct confdb_inst *confdb_inst; + struct iovec iov[2]; + struct req_lib_confdb_key_get req_lib_confdb_key_get; + struct res_lib_confdb_key_get res_lib_confdb_key_get; + + error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst); + if (error != SA_AIS_OK) { + return (error); + } + + req_lib_confdb_key_get.header.size = sizeof (struct req_lib_confdb_key_get); + req_lib_confdb_key_get.header.id = MESSAGE_REQ_CONFDB_KEY_GET; + req_lib_confdb_key_get.parent_object_handle = parent_object_handle; + memcpy(req_lib_confdb_key_get.key_name.value, key_name, key_name_len); + req_lib_confdb_key_get.key_name.length = key_name_len; + + iov[0].iov_base = (char *)&req_lib_confdb_key_get; + iov[0].iov_len = sizeof (struct req_lib_confdb_key_get); + + pthread_mutex_lock (&confdb_inst->response_mutex); + + error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1, + &res_lib_confdb_key_get, sizeof (struct res_lib_confdb_key_get)); + + pthread_mutex_unlock (&confdb_inst->response_mutex); + if (error != SA_AIS_OK) { + goto error_exit; + } + + error = res_lib_confdb_key_get.header.error; + if (error == SA_AIS_OK) { + *value_len = res_lib_confdb_key_get.value.length; + memcpy(value, res_lib_confdb_key_get.value.value, *value_len); + } + +error_exit: + saHandleInstancePut (&confdb_handle_t_db, handle); + + return (error); +} + + +confdb_error_t confdb_object_find_start ( + confdb_handle_t handle, + unsigned int parent_object_handle) +{ + struct confdb_inst *confdb_inst; + struct iovec iov[2]; + struct req_lib_confdb_object_find_reset req_lib_confdb_object_find_reset; + struct res_lib_confdb_object_find_reset res_lib_confdb_object_find_reset; + + confdb_error_t error = SA_AIS_OK; + + error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst); + if (error != SA_AIS_OK) { + return (error); + } + + req_lib_confdb_object_find_reset.header.size = sizeof (struct req_lib_confdb_object_find_reset); + req_lib_confdb_object_find_reset.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND_RESET; + req_lib_confdb_object_find_reset.object_handle = parent_object_handle; + + iov[0].iov_base = (char *)&req_lib_confdb_object_find_reset; + iov[0].iov_len = sizeof (struct req_lib_confdb_object_find_reset); + + pthread_mutex_lock (&confdb_inst->response_mutex); + + error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1, + &res_lib_confdb_object_find_reset, sizeof (struct res_lib_confdb_object_find_reset)); + + pthread_mutex_unlock (&confdb_inst->response_mutex); + if (error != SA_AIS_OK) { + goto error_exit; + } + + error = res_lib_confdb_object_find_reset.header.error; + +error_exit: + + saHandleInstancePut (&confdb_handle_t_db, handle); + + return error; +} + +confdb_error_t confdb_object_find ( + confdb_handle_t handle, + unsigned int parent_object_handle, + void *object_name, + int object_name_len, + unsigned int *object_handle) +{ + confdb_error_t error; + struct confdb_inst *confdb_inst; + struct iovec iov[2]; + struct req_lib_confdb_object_find req_lib_confdb_object_find; + struct res_lib_confdb_object_find res_lib_confdb_object_find; + + error = saHandleInstanceGet (&confdb_handle_t_db, handle, (void *)&confdb_inst); + if (error != SA_AIS_OK) { + return (error); + } + + req_lib_confdb_object_find.header.size = sizeof (struct req_lib_confdb_object_find); + req_lib_confdb_object_find.header.id = MESSAGE_REQ_CONFDB_OBJECT_FIND; + req_lib_confdb_object_find.parent_object_handle = parent_object_handle; + memcpy(req_lib_confdb_object_find.object_name.value, object_name, object_name_len); + req_lib_confdb_object_find.object_name.length = object_name_len; + + iov[0].iov_base = (char *)&req_lib_confdb_object_find; + iov[0].iov_len = sizeof (struct req_lib_confdb_object_find); + + pthread_mutex_lock (&confdb_inst->response_mutex); + + error = saSendMsgReceiveReply (confdb_inst->response_fd, iov, 1, + &res_lib_confdb_object_find, sizeof (struct res_lib_confdb_object_find)); + + pthread_mutex_unlock (&confdb_inst->response_mutex); + if (error != SA_AIS_OK) { + goto error_exit; + } + + error = res_lib_confdb_object_find.header.error; + *object_handle = res_lib_confdb_object_find.object_handle; + +error_exit: + saHandleInstancePut (&confdb_handle_t_db, handle); + + return (error); +} + + Index: lib/Makefile =================================================================== --- lib/Makefile (revision 1672) +++ lib/Makefile (working copy) @@ -44,7 +44,8 @@ libcpg.a libcpg.so.2.0.0 \ libais.a libais.so.2.0.0 \ libevs.a libevs.so.2.0.0 \ - libcfg.a libcfg.so.2.0.0 + libcfg.a libcfg.so.2.0.0 \ + libconfdb.a libconfdb.so.2.0.0 LIBAIS_SRC = util.c amf.c clm.c ckpt.c evt.c @@ -85,6 +86,9 @@ libcfg.so.2.0.0: util.o cfg.o $(CC) -bundle -bind_at_load util.o cfg.o -o $@ +libconfdb.so.2.0.0: util.o cfg.o + $(CC) -bundle -bind_at_load util.o confdb.o -o $@ + else libSaClm.so.2.0.0: util.o clm.o @@ -117,6 +121,9 @@ libcfg.so.2.0.0: util.o cfg.o $(CC) -shared -Wl,-soname,libcfg.so.2,-version-script=libcfg.versions util.o cfg.o -o $@ +libconfdb.so.2.0.0: util.o confdb.o + $(CC) -shared -Wl,-soname,libcfg.so.2,-version-script=libcfg.versions util.o confdb.o -o $@ + endif libSaAmf.a: util.o amf.o @@ -146,11 +153,14 @@ libcfg.a: util.o cfg.o $(AR) -rc libcfg.a util.o cfg.o +libconfdb.a: util.o confdb.o + $(AR) -rc libconfdb.a util.o confdb.o + clean: rm -f *.o libais.so* libais.a libSaClm.so* libSaClm.a* libSaAmf.so* libSaAmf.a \ libSaCkpt.so* libSaCkpt.a* libSaEvt.so* libSaEvt.a libSaLck.so* libSaLck.a \ libSaMsg.so* libSaMsg.a libcfg.a libcfg.so* libOpenaisCfg.a \ - libevs.so* libevs.a libcpg.so* libcpg.a *.da *.bb *.bbg + libevs.so* libevs.a libcpg.so* libcpg.a libconfdb.a libconfdb.so.* *.da *.bb *.bbg # -fPIC rules required for all libraries %.o: %.c
_______________________________________________ Openais mailing list [email protected] https://lists.linux-foundation.org/mailman/listinfo/openais
