diff --git a/corosync.spec.in b/corosync.spec.in index d450726b..090457b3 100644 --- a/corosync.spec.in +++ b/corosync.spec.in @@ -237,8 +237,6 @@ This package contains corosync libraries. %{_libdir}/libevs.so.* %{_libdir}/libtotem_pg.so.* %{_libdir}/liblogsys.so.* -%{_libdir}/libcoroipcc.so.* -%{_libdir}/libcoroipcs.so.* %{_libdir}/libquorum.so.* %{_libdir}/libvotequorum.so.* %{_libdir}/libpload.so.* @@ -266,9 +264,6 @@ The Corosync Cluster Engine APIs. %dir %{_includedir}/corosync/ %{_includedir}/corosync/cs_config.h %{_includedir}/corosync/corodefs.h -%{_includedir}/corosync/coroipc_types.h -%{_includedir}/corosync/coroipcs.h -%{_includedir}/corosync/coroipcc.h %{_includedir}/corosync/cfg.h %{_includedir}/corosync/confdb.h %{_includedir}/corosync/corotypes.h @@ -301,8 +296,6 @@ The Corosync Cluster Engine APIs. %{_libdir}/libevs.so %{_libdir}/libtotem_pg.so %{_libdir}/liblogsys.so -%{_libdir}/libcoroipcc.so -%{_libdir}/libcoroipcs.so %{_libdir}/libquorum.so %{_libdir}/libvotequorum.so %{_libdir}/libpload.so @@ -318,7 +311,6 @@ The Corosync Cluster Engine APIs. %{_mandir}/man8/confdb_overview.8* %{_mandir}/man8/logsys_overview.8* %{_mandir}/man8/votequorum_overview.8* -%{_mandir}/man8/coroipc_overview.8* %{_mandir}/man8/sam_overview.8* %changelog diff --git a/cts/agents/Makefile.am b/cts/agents/Makefile.am index c75cad57..110d87f0 100644 --- a/cts/agents/Makefile.am +++ b/cts/agents/Makefile.am @@ -58,19 +58,19 @@ endif noinst_HEADERS = common_test_agent.h cpg_test_agent_SOURCES = cpg_test_agent.c common_test_agent.c -cpg_test_agent_LDADD = -lcpg -lcfg -lcoroipcc ../../exec/crypto.o $(LIBQB_LIBS) +cpg_test_agent_LDADD = -lcpg -lcfg ../../exec/crypto.o $(LIBQB_LIBS) cpg_test_agent_LDFLAGS = -L../../lib -L. confdb_test_agent_SOURCES = confdb_test_agent.c common_test_agent.c -confdb_test_agent_LDADD = -lconfdb -lcoroipcc $(LIBQB_LIBS) +confdb_test_agent_LDADD = -lconfdb $(LIBQB_LIBS) confdb_test_agent_LDFLAGS = -L../../lib sam_test_agent_SOURCES = sam_test_agent.c common_test_agent.c -sam_test_agent_LDADD = -lsam -lquorum -lcoroipcc -lconfdb $(LIBQB_LIBS) +sam_test_agent_LDADD = -lsam -lquorum -lconfdb $(LIBQB_LIBS) sam_test_agent_LDFLAGS = -L../../lib votequorum_test_agent_SOURCES = votequorum_test_agent.c common_test_agent.c -votequorum_test_agent_LDADD = -lvotequorum -lquorum -lcoroipcc $(LIBQB_LIBS) +votequorum_test_agent_LDADD = -lvotequorum -lquorum $(LIBQB_LIBS) votequorum_test_agent_LDFLAGS = -L../../lib if BUILD_DARWIN diff --git a/cts/agents/cpg_test_agent.c b/cts/agents/cpg_test_agent.c index e585c716..5be6beb2 100644 --- a/cts/agents/cpg_test_agent.c +++ b/cts/agents/cpg_test_agent.c @@ -92,7 +92,7 @@ static struct list_head msg_log_head; static pid_t my_pid; static uint32_t my_nodeid; static int32_t my_seq; -static int32_t use_zcb = 0; +static int32_t use_zcb = QB_FALSE; static int32_t my_msgs_to_send; static int32_t total_stored_msgs = 0; static int32_t in_cnchg = 0; @@ -332,8 +332,6 @@ static void send_some_more_messages_later (void) &more_messages_timer_handle); } - - static void send_some_more_messages_zcb (void) { msg_t *my_msg; @@ -399,7 +397,6 @@ free_buffer: cpg_zcb_free (cpg_handle, zcb_buffer); } - #define cs_repeat(counter, max, code) do { \ code; \ if(res == CS_ERR_TRY_AGAIN) { \ @@ -490,7 +487,7 @@ static void send_some_more_messages_normal (void) static void send_some_more_messages (void * unused) { if (use_zcb) { - send_some_more_messages_zcb (); +// send_some_more_messages_zcb (); } else { send_some_more_messages_normal (); } @@ -502,7 +499,7 @@ static void msg_blaster (int sock, char* num_to_send_str) my_seq = 1; my_pid = getpid(); - use_zcb = 0; + use_zcb = QB_FALSE; total_stored_msgs = 0; cpg_local_get (cpg_handle, &my_nodeid); @@ -539,7 +536,7 @@ static void msg_blaster_zcb (int sock, char* num_to_send_str) my_seq = 1; my_pid = getpid(); - use_zcb = 1; + use_zcb = QB_TRUE; total_stored_msgs = 0; cpg_local_get (cpg_handle, &my_nodeid); diff --git a/cts/agents/syncv2.c b/cts/agents/syncv2.c index 68595e99..354fab4e 100644 --- a/cts/agents/syncv2.c +++ b/cts/agents/syncv2.c @@ -53,7 +53,7 @@ #include #include -#include +#include #include #include #include @@ -61,8 +61,6 @@ #include #include -#include "../exec/tlist.h" - LOGSYS_DECLARE_SUBSYS ("TST2"); /* diff --git a/exec/Makefile.am b/exec/Makefile.am index fd6d63d8..b728bf20 100644 --- a/exec/Makefile.am +++ b/exec/Makefile.am @@ -43,29 +43,25 @@ TOTEM_SRC += totemiba.c endif LOGSYS_SRC = wthread.c logsys.c -COROIPCS_SRC = coroipcs.c - LCRSO_SRC = objdb.c vsf_ykd.c coroparse.c vsf_quorum.c LCRSO_OBJS = $(LCRSO_SRC:%.c=%.o) LCRSO = $(LCRSO_SRC:%.c=%.lcrso) -lib_LIBRARIES = libtotem_pg.a liblogsys.a libcoroipcs.a +lib_LIBRARIES = libtotem_pg.a liblogsys.a sbin_PROGRAMS = corosync libtotem_pg_a_SOURCES = $(TOTEM_SRC) liblogsys_a_SOURCES = $(LOGSYS_SRC) -libcoroipcs_a_SOURCES = $(COROIPCS_SRC) -corosync_SOURCES = main.c util.c sync.c apidef.c service.c \ +corosync_SOURCES = main.c ipc_glue.c util.c sync.c apidef.c service.c \ timer.c totemconfig.c mainconfig.c quorum.c schedwrk.c \ ../lcr/lcr_ifact.c evil.c syncv2.c -corosync_LDADD = -ltotem_pg -llogsys -lcoroipcs $(statgrab_LIBS) $(LIBQB_LIBS) -corosync_DEPENDENCIES = libtotem_pg.so.$(SONAME) liblogsys.so.$(SONAME) libcoroipcs.so.$(SONAME) +corosync_LDADD = -ltotem_pg -llogsys $(LIBQB_LIBS) $(statgrab_LIBS) +corosync_DEPENDENCIES = libtotem_pg.so.$(SONAME) liblogsys.so.$(SONAME) corosync_LDFLAGS = $(OS_DYFLAGS) -L./ TOTEM_OBJS = $(TOTEM_SRC:%.c=%.o) LOGSYS_OBJS = $(LOGSYS_SRC:%.c=%.o) -COROIPCS_OBJS = $(COROIPCS_SRC:%.c=%.o) SHARED_LIBS = $(lib_LIBRARIES:%.a=%.so.$(SONAME)) SHARED_LIBS_SO = $(SHARED_LIBS:%.so.$(SONAME)=%.so) @@ -93,11 +89,6 @@ liblogsys.so.$(SONAME): $(LOGSYS_OBJS) ln -sf liblogsys.so.$(SONAME) liblogsys.so ln -sf liblogsys.so.$(SONAME) liblogsys.so.$(SOMAJOR) -libcoroipcs.so.$(SONAME): $(COROIPCS_OBJS) - $(CC) $(LDFLAGS) $(DARWIN_OPTS) $(COROIPCS_OBJS) -o $@ -lpthread - ln -sf libcoroipcs.so.$(SONAME) libcoroipcs.so - ln -sf libcoroipcs.so.$(SONAME) libcoroipcs.so.$(SOMAJOR) - else if BUILD_SOLARIS @@ -114,11 +105,6 @@ liblogsys.so.$(SONAME): $(LOGSYS_OBJS) ln -sf liblogsys.so.$(SONAME) liblogsys.so ln -sf liblogsys.so.$(SONAME) liblogsys.so.$(SOMAJOR) -libcoroipcs.so.$(SONAME): $(COROIPCS_OBJS) - $(LD) $(LDFLAGS) -G $(COROIPCS_OBJS) -o $@ -lpthread - ln -sf libcoroipcs.so.$(SONAME) libcoroipcs.so - ln -sf libcoroipcs.so.$(SONAME) libcoroipcs.so.$(SOMAJOR) - else %.lcrso: %.o @@ -138,13 +124,6 @@ liblogsys.so.$(SONAME): $(LOGSYS_OBJS) ln -sf liblogsys.so.$(SONAME) liblogsys.so ln -sf liblogsys.so.$(SONAME) liblogsys.so.$(SOMAJOR) -libcoroipcs.so.$(SONAME): $(COROIPCS_OBJS) - $(CC) -shared -o $@ \ - -Wl,-soname=libcoroipcs.so.$(SOMAJOR) \ - $(LDFLAGS) $^ -lpthread - ln -sf libcoroipcs.so.$(SONAME) libcoroipcs.so - ln -sf libcoroipcs.so.$(SONAME) libcoroipcs.so.$(SOMAJOR) - endif endif diff --git a/exec/apidef.c b/exec/apidef.c index e4711a7e..c2681081 100644 --- a/exec/apidef.c +++ b/exec/apidef.c @@ -38,13 +38,12 @@ #include #include -#include #include #include #include #include #include -#include +#include #include "util.h" #include "timer.h" #include "sync.h" @@ -101,13 +100,13 @@ static struct corosync_api_v1 apidef_corosync_api_v1 = { .timer_expire_time_get = corosync_timer_expire_time_get, .ipc_source_set = message_source_set, .ipc_source_is_local = message_source_is_local, - .ipc_private_data_get = coroipcs_private_data_get, - .ipc_response_iov_send = coroipcs_response_iov_send, - .ipc_response_send = coroipcs_response_send, - .ipc_dispatch_send = coroipcs_dispatch_send, - .ipc_dispatch_iov_send = coroipcs_dispatch_iov_send, - .ipc_refcnt_inc = coroipcs_refcount_inc, - .ipc_refcnt_dec = coroipcs_refcount_dec, + .ipc_private_data_get = cs_ipcs_private_data_get, + .ipc_response_iov_send = cs_ipcs_response_iov_send, + .ipc_response_send = cs_ipcs_response_send, + .ipc_dispatch_send = cs_ipcs_dispatch_send, + .ipc_dispatch_iov_send = cs_ipcs_dispatch_iov_send, + .ipc_refcnt_inc = cs_ipc_refcnt_inc, + .ipc_refcnt_dec = cs_ipc_refcnt_dec, .totem_nodeid_get = totempg_my_nodeid_get, .totem_family_get = totempg_my_family_get, .totem_ring_reenable = totempg_ring_reenable, diff --git a/exec/coroipcs.c b/exec/coroipcs.c deleted file mode 100644 index 1422c090..00000000 --- a/exec/coroipcs.c +++ /dev/null @@ -1,1775 +0,0 @@ -/* - * Copyright (c) 2006-2009 Red Hat, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * 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 - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE 1 -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if defined(HAVE_GETPEERUCRED) -#include -#endif -#include - -#include - -#include -#include - -#include -#include -#include -#include - -#define LOGSYS_UTILS_ONLY 1 -#include - -#if _POSIX_THREAD_PROCESS_SHARED > 0 -#include -#else -#include -#endif -#include "util.h" - -#ifndef MSG_NOSIGNAL -#define MSG_NOSIGNAL 0 -#endif - -#define SERVER_BACKLOG 5 - -#define MSG_SEND_LOCKED 0 -#define MSG_SEND_UNLOCKED 1 - -#define POLL_STATE_IN 1 -#define POLL_STATE_INOUT 2 - -static struct coroipcs_init_state_v2 *api = NULL; - -DECLARE_LIST_INIT (conn_info_list_head); - -DECLARE_LIST_INIT (conn_info_exit_list_head); - -struct outq_item { - void *msg; - size_t mlen; - struct list_head list; -}; - -struct zcb_mapped { - struct list_head list; - void *addr; - size_t size; -}; - - -enum conn_state { - CONN_STATE_THREAD_INACTIVE = 0, - CONN_STATE_THREAD_ACTIVE = 1, - CONN_STATE_THREAD_REQUEST_EXIT = 2, - CONN_STATE_THREAD_DESTROYED = 3, - CONN_STATE_LIB_EXIT_CALLED = 4, - CONN_STATE_DISCONNECT_INACTIVE = 5 -}; - -struct conn_info { - int fd; - pthread_t thread; - pid_t client_pid; - unsigned int service; - enum conn_state state; - int refcount; - hdb_handle_t stats_handle; -#if _POSIX_THREAD_PROCESS_SHARED < 1 - key_t semkey; -#endif - unsigned int pending_semops; - pthread_mutex_t mutex; - struct control_buffer *control_buffer; - char *request_buffer; - char *response_buffer; - char *dispatch_buffer; - size_t control_size; - size_t request_size; - size_t response_size; - size_t dispatch_size; - struct list_head outq_head; - void *private_data; - struct list_head list; - char setup_msg[sizeof (mar_req_setup_t)]; - unsigned int setup_bytes_read; - struct list_head zcb_mapped_list_head; - char *sending_allowed_private_data[64]; - int poll_state; -}; - -static int shared_mem_dispatch_bytes_left (const struct conn_info *conn_info); - -static void outq_flush (struct conn_info *conn_info); - -static int priv_change (struct conn_info *conn_info); - -static void ipc_disconnect (struct conn_info *conn_info); - -static void msg_send (void *conn, const struct iovec *iov, unsigned int iov_len, - int locked); - -static void _corosync_ipc_init(void); - -#define log_printf(level, format, args...) \ -do { \ - if (api->log_printf) \ - api->log_printf ( \ - LOGSYS_ENCODE_RECID(level, \ - api->log_subsys_id, \ - LOGSYS_RECID_LOG), \ - __FUNCTION__, __FILE__, __LINE__, \ - (const char *)format, ##args); \ - else \ - api->old_log_printf ((const char *)format, ##args); \ -} while (0) - -static hdb_handle_t dummy_stats_create_connection ( - const char *name, - pid_t pid, - int fd) -{ - return (0ULL); -} - -static void dummy_stats_destroy_connection ( - hdb_handle_t handle) -{ -} - -static void dummy_stats_update_value ( - hdb_handle_t handle, - const char *name, - const void *value, - size_t value_size) -{ -} - -static void dummy_stats_increment_value ( - hdb_handle_t handle, - const char *name) -{ -} - -static int -memory_map ( - const char *path, - size_t bytes, - void **buf) -{ - int32_t fd; - void *addr_orig; - void *addr; - int32_t res; - - fd = open (path, O_RDWR, 0600); - - unlink (path); - - if (fd == -1) { - return (-1); - } - - res = ftruncate (fd, bytes); - if (res == -1) { - goto error_close_unlink; - } - - addr_orig = mmap (NULL, bytes, PROT_NONE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - - if (addr_orig == MAP_FAILED) { - goto error_close_unlink; - } - - addr = mmap (addr_orig, bytes, PROT_READ | PROT_WRITE, - MAP_FIXED | MAP_SHARED, fd, 0); - - if (addr != addr_orig) { - munmap(addr_orig, bytes); - goto error_close_unlink; - } -#ifdef COROSYNC_BSD - madvise(addr, bytes, MADV_NOSYNC); -#endif - - res = close (fd); - if (res) { - return (-1); - } - *buf = addr_orig; - return (0); - -error_close_unlink: - close (fd); - unlink(path); - return -1; -} - -static int -circular_memory_map ( - const char *path, - size_t bytes, - void **buf) -{ - int32_t fd; - void *addr_orig; - void *addr; - int32_t res; - - fd = open (path, O_RDWR, 0600); - - unlink (path); - - if (fd == -1) { - return (-1); - } - res = ftruncate (fd, bytes); - if (res == -1) { - goto error_close_unlink; - } - - addr_orig = mmap (NULL, bytes << 1, PROT_NONE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - - if (addr_orig == MAP_FAILED) { - munmap(addr_orig, bytes); - goto error_close_unlink; - } - - addr = mmap (addr_orig, bytes, PROT_READ | PROT_WRITE, - MAP_FIXED | MAP_SHARED, fd, 0); - - if (addr != addr_orig) { - munmap(addr_orig, bytes); - goto error_close_unlink; - } -#ifdef COROSYNC_BSD - madvise(addr_orig, bytes, MADV_NOSYNC); -#endif - - addr = mmap (((char *)addr_orig) + bytes, - bytes, PROT_READ | PROT_WRITE, - MAP_FIXED | MAP_SHARED, fd, 0); - if (addr == MAP_FAILED) { - munmap(addr_orig, bytes); - munmap(addr, bytes); - goto error_close_unlink; - } -#ifdef COROSYNC_BSD - madvise(((char *)addr_orig) + bytes, bytes, MADV_NOSYNC); -#endif - - res = close (fd); - if (res) { - munmap(addr_orig, bytes); - munmap(addr, bytes); - return (-1); - } - *buf = addr_orig; - return (0); - -error_close_unlink: - close (fd); - unlink(path); - return (-1); -} - -static inline int -circular_memory_unmap (void *buf, size_t bytes) -{ - int res; - - res = munmap (buf, bytes << 1); - - return (res); -} - -static int32_t flow_control_state_set ( - struct conn_info *conn_info, - int flow_control_state) -{ - if (conn_info->control_buffer->flow_control_enabled == flow_control_state) { - return 0; - } - if (flow_control_state == 0) { - log_printf (LOGSYS_LEVEL_DEBUG, - "Disabling flow control for %d\n", - conn_info->client_pid); - } else - if (flow_control_state == 1) { - log_printf (LOGSYS_LEVEL_DEBUG, - "Enabling flow control for %d\n", - conn_info->client_pid); - } - - conn_info->control_buffer->flow_control_enabled = flow_control_state; - return 1; -} - -static void flow_control_stats_update ( - hdb_handle_t stats_handle, - int flow_control_state) -{ - uint32_t fc_state = flow_control_state; - api->stats_update_value (stats_handle, "flow_control", - &fc_state, sizeof(fc_state)); - api->stats_increment_value (stats_handle, "flow_control_count"); -} - -static inline int zcb_free (struct zcb_mapped *zcb_mapped) -{ - unsigned int res; - - res = munmap (zcb_mapped->addr, zcb_mapped->size); - list_del (&zcb_mapped->list); - free (zcb_mapped); - return (res); -} - -static inline int zcb_by_addr_free (struct conn_info *conn_info, void *addr) -{ - struct list_head *list; - struct zcb_mapped *zcb_mapped; - unsigned int res = 0; - - for (list = conn_info->zcb_mapped_list_head.next; - list != &conn_info->zcb_mapped_list_head; list = list->next) { - - zcb_mapped = list_entry (list, struct zcb_mapped, list); - - if (zcb_mapped->addr == addr) { - res = zcb_free (zcb_mapped); - break; - } - - } - return (res); -} - -static inline int zcb_all_free ( - struct conn_info *conn_info) -{ - struct list_head *list; - struct zcb_mapped *zcb_mapped; - - for (list = conn_info->zcb_mapped_list_head.next; - list != &conn_info->zcb_mapped_list_head;) { - - zcb_mapped = list_entry (list, struct zcb_mapped, list); - - list = list->next; - - zcb_free (zcb_mapped); - } - return (0); -} - -static inline int zcb_alloc ( - struct conn_info *conn_info, - const char *path_to_file, - size_t size, - void **addr) -{ - struct zcb_mapped *zcb_mapped; - unsigned int res; - - zcb_mapped = malloc (sizeof (struct zcb_mapped)); - if (zcb_mapped == NULL) { - return (-1); - } - - res = memory_map ( - path_to_file, - size, - addr); - if (res == -1) { - free (zcb_mapped); - return (-1); - } - - list_init (&zcb_mapped->list); - zcb_mapped->addr = *addr; - zcb_mapped->size = size; - list_add_tail (&zcb_mapped->list, &conn_info->zcb_mapped_list_head); - return (0); -} - -static int ipc_thread_active (void *conn) -{ - struct conn_info *conn_info = (struct conn_info *)conn; - int retval = 0; - - pthread_mutex_lock (&conn_info->mutex); - if (conn_info->state == CONN_STATE_THREAD_ACTIVE) { - retval = 1; - } - pthread_mutex_unlock (&conn_info->mutex); - return (retval); -} - -static int ipc_thread_exiting (void *conn) -{ - struct conn_info *conn_info = (struct conn_info *)conn; - int retval = 1; - - pthread_mutex_lock (&conn_info->mutex); - if (conn_info->state == CONN_STATE_THREAD_INACTIVE) { - retval = 0; - } else - if (conn_info->state == CONN_STATE_THREAD_ACTIVE) { - retval = 0; - } - pthread_mutex_unlock (&conn_info->mutex); - return (retval); -} - -/* - * returns 0 if should be called again, -1 if finished - */ -static inline int conn_info_destroy (struct conn_info *conn_info) -{ - unsigned int res; - void *retval; - - list_del (&conn_info->list); - list_init (&conn_info->list); - list_add (&conn_info->list, &conn_info_exit_list_head); - - if (conn_info->state == CONN_STATE_THREAD_REQUEST_EXIT) { - res = pthread_join (conn_info->thread, &retval); - conn_info->state = CONN_STATE_THREAD_DESTROYED; - return (0); - } - - if (conn_info->state == CONN_STATE_THREAD_INACTIVE || - conn_info->state == CONN_STATE_DISCONNECT_INACTIVE) { - list_del (&conn_info->list); - close (conn_info->fd); - api->free (conn_info); - return (-1); - } - - if (conn_info->state == CONN_STATE_THREAD_ACTIVE) { - ipc_sem_post (conn_info->control_buffer, SEMAPHORE_REQUEST_OR_FLUSH_OR_EXIT); - return (0); - } - - /* - * Retry library exit function if busy - */ - if (conn_info->state == CONN_STATE_THREAD_DESTROYED) { - api->serialize_lock (); - res = api->exit_fn_get (conn_info->service) (conn_info); - api->serialize_unlock (); - api->stats_destroy_connection (conn_info->stats_handle); - if (res == -1) { - return (0); - } else { - conn_info->state = CONN_STATE_LIB_EXIT_CALLED; - } - } - - pthread_mutex_lock (&conn_info->mutex); - if (conn_info->refcount > 0) { - pthread_mutex_unlock (&conn_info->mutex); - return (0); - } - list_del (&conn_info->list); - pthread_mutex_unlock (&conn_info->mutex); - - /* - * Let library know, that connection is now closed - */ - conn_info->control_buffer->ipc_closed = 1; - ipc_sem_post (conn_info->control_buffer, SEMAPHORE_RESPONSE); - ipc_sem_post (conn_info->control_buffer, SEMAPHORE_DISPATCH); - -#if _POSIX_THREAD_PROCESS_SHARED > 0 - sem_destroy (&conn_info->control_buffer->sem_request_or_flush_or_exit); - sem_destroy (&conn_info->control_buffer->sem_request); - sem_destroy (&conn_info->control_buffer->sem_response); - sem_destroy (&conn_info->control_buffer->sem_dispatch); -#else - semctl (conn_info->control_buffer->semid, 0, IPC_RMID); -#endif - /* - * Destroy shared memory segment and semaphore - */ - res = munmap ((void *)conn_info->control_buffer, conn_info->control_size); - res = munmap ((void *)conn_info->request_buffer, conn_info->request_size); - res = munmap ((void *)conn_info->response_buffer, conn_info->response_size); - - /* - * Free allocated data needed to retry exiting library IPC connection - */ - if (conn_info->private_data) { - api->free (conn_info->private_data); - } - close (conn_info->fd); - res = circular_memory_unmap (conn_info->dispatch_buffer, conn_info->dispatch_size); - zcb_all_free (conn_info); - api->free (conn_info); - return (-1); -} - -union u { - uint64_t server_addr; - void *server_ptr; -}; - -static uint64_t void2serveraddr (void *server_ptr) -{ - union u u; - - u.server_ptr = server_ptr; - return (u.server_addr); -} - -static void *serveraddr2void (uint64_t server_addr) -{ - union u u; - - u.server_addr = server_addr; - return (u.server_ptr); -}; - -static inline void zerocopy_operations_process ( - struct conn_info *conn_info, - coroipc_request_header_t **header_out, - unsigned int *new_message) -{ - coroipc_request_header_t *header; - - header = (coroipc_request_header_t *)conn_info->request_buffer; - if (header->id == ZC_ALLOC_HEADER) { - mar_req_coroipcc_zc_alloc_t *hdr = (mar_req_coroipcc_zc_alloc_t *)header; - coroipc_response_header_t res_header; - void *addr = NULL; - struct coroipcs_zc_header *zc_header; - unsigned int res; - - res = zcb_alloc (conn_info, hdr->path_to_file, hdr->map_size, - &addr); - - zc_header = (struct coroipcs_zc_header *)addr; - zc_header->server_address = void2serveraddr(addr); - - res_header.size = sizeof (coroipc_response_header_t); - res_header.id = 0; - coroipcs_response_send ( - conn_info, &res_header, - res_header.size); - *new_message = 0; - return; - } else - if (header->id == ZC_FREE_HEADER) { - mar_req_coroipcc_zc_free_t *hdr = (mar_req_coroipcc_zc_free_t *)header; - coroipc_response_header_t res_header; - void *addr = NULL; - - addr = serveraddr2void (hdr->server_address); - - zcb_by_addr_free (conn_info, addr); - - res_header.size = sizeof (coroipc_response_header_t); - res_header.id = 0; - coroipcs_response_send ( - conn_info, &res_header, - res_header.size); - - *new_message = 0; - return; - } else - if (header->id == ZC_EXECUTE_HEADER) { - mar_req_coroipcc_zc_execute_t *hdr = (mar_req_coroipcc_zc_execute_t *)header; - - header = (coroipc_request_header_t *)(((char *)serveraddr2void(hdr->server_address) + sizeof (struct coroipcs_zc_header))); - } - *header_out = header; - *new_message = 1; -} - -static void *pthread_ipc_consumer (void *conn) -{ - struct conn_info *conn_info = (struct conn_info *)conn; - int res; - coroipc_request_header_t *header; - coroipc_response_header_t coroipc_response_header; - int send_ok; - unsigned int new_message; - int sem_value = 0; - -#if defined(HAVE_PTHREAD_SETSCHEDPARAM) && defined(HAVE_SCHED_GET_PRIORITY_MAX) - if (api->sched_policy != 0) { - res = pthread_setschedparam (conn_info->thread, - api->sched_policy, api->sched_param); - } -#endif - - for (;;) { - ipc_sem_wait (conn_info->control_buffer, SEMAPHORE_REQUEST_OR_FLUSH_OR_EXIT, IPC_SEMWAIT_NOFILE); - if (ipc_thread_active (conn_info) == 0) { - coroipcs_refcount_dec (conn_info); - pthread_exit (0); - } - - outq_flush (conn_info); - - ipc_sem_getvalue (conn_info->control_buffer, SEMAPHORE_REQUEST, &sem_value); - if (sem_value > 0) { - - res = ipc_sem_wait (conn_info->control_buffer, SEMAPHORE_REQUEST, IPC_SEMWAIT_NOFILE); - } else { - continue; - } - - zerocopy_operations_process (conn_info, &header, &new_message); - /* - * There is no new message to process, continue for loop - */ - if (new_message == 0) { - continue; - } - - coroipcs_refcount_inc (conn); - - send_ok = api->sending_allowed (conn_info->service, - header->id, - header, - conn_info->sending_allowed_private_data); - - /* - * This happens when the message contains some kind of invalid - * parameter, such as an invalid size - */ - if (send_ok == -1) { - api->stats_increment_value (conn_info->stats_handle, "invalid_request"); - coroipc_response_header.size = sizeof (coroipc_response_header_t); - coroipc_response_header.id = 0; - coroipc_response_header.error = CS_ERR_INVALID_PARAM; - coroipcs_response_send (conn_info, - &coroipc_response_header, - sizeof (coroipc_response_header_t)); - } else - if (send_ok) { - api->stats_increment_value (conn_info->stats_handle, "requests"); - api->serialize_lock(); - api->handler_fn_get (conn_info->service, header->id) (conn_info, header); - api->serialize_unlock(); - } else { - /* - * Overload, tell library to retry - */ - api->stats_increment_value (conn_info->stats_handle, "overload"); - coroipc_response_header.size = sizeof (coroipc_response_header_t); - coroipc_response_header.id = 0; - coroipc_response_header.error = CS_ERR_TRY_AGAIN; - coroipcs_response_send (conn_info, - &coroipc_response_header, - sizeof (coroipc_response_header_t)); - } - - api->sending_allowed_release (conn_info->sending_allowed_private_data); - coroipcs_refcount_dec (conn); - } - pthread_exit (0); -} - -static int -req_setup_send ( - struct conn_info *conn_info, - int error) -{ - mar_res_setup_t res_setup; - unsigned int res; - - memset (&res_setup, 0, sizeof (res_setup)); - res_setup.error = error; - -retry_send: - res = send (conn_info->fd, &res_setup, sizeof (mar_res_setup_t), MSG_WAITALL); - if (res == -1 && errno == EINTR) { - api->stats_increment_value (conn_info->stats_handle, "send_retry_count"); - goto retry_send; - } else - if (res == -1 && errno == EAGAIN) { - api->stats_increment_value (conn_info->stats_handle, "send_retry_count"); - goto retry_send; - } - return (0); -} - -static cs_error_t -req_setup_recv ( - struct conn_info *conn_info) -{ - int res; - struct msghdr msg_recv; - struct iovec iov_recv; - cs_error_t auth_res = CS_ERR_LIBRARY; - -#ifdef COROSYNC_LINUX - struct cmsghdr *cmsg; - char cmsg_cred[CMSG_SPACE (sizeof (struct ucred))]; - int off = 0; - int on = 1; - struct ucred *cred; -#endif - msg_recv.msg_flags = 0; - msg_recv.msg_iov = &iov_recv; - msg_recv.msg_iovlen = 1; - msg_recv.msg_name = 0; - msg_recv.msg_namelen = 0; -#ifdef COROSYNC_LINUX - msg_recv.msg_control = (void *)cmsg_cred; - msg_recv.msg_controllen = sizeof (cmsg_cred); -#endif -#ifdef COROSYNC_SOLARIS - msg_recv.msg_accrights = 0; - msg_recv.msg_accrightslen = 0; -#endif /* COROSYNC_SOLARIS */ - - iov_recv.iov_base = &conn_info->setup_msg[conn_info->setup_bytes_read]; - iov_recv.iov_len = sizeof (mar_req_setup_t) - conn_info->setup_bytes_read; -#ifdef COROSYNC_LINUX - setsockopt(conn_info->fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on)); -#endif - -retry_recv: - res = recvmsg (conn_info->fd, &msg_recv, MSG_NOSIGNAL); - if (res == -1 && errno == EINTR) { - api->stats_increment_value (conn_info->stats_handle, "recv_retry_count"); - goto retry_recv; - } else - if (res == -1 && errno != EAGAIN) { - return (CS_ERR_LIBRARY); - } else - if (res == 0) { -#if defined(COROSYNC_SOLARIS) || defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN) - /* On many OS poll never return POLLHUP or POLLERR. - * EOF is detected when recvmsg return 0. - */ - ipc_disconnect (conn_info); - return (CS_ERR_LIBRARY); -#else - return (CS_ERR_SECURITY); -#endif - } - conn_info->setup_bytes_read += res; - -/* - * currently support getpeerucred, getpeereid, and SO_PASSCRED credential - * retrieval mechanisms for various Platforms - */ -#ifdef HAVE_GETPEERUCRED -/* - * Solaris and some BSD systems - */ - { - ucred_t *uc = NULL; - uid_t euid = -1; - gid_t egid = -1; - - if (getpeerucred (conn_info->fd, &uc) == 0) { - euid = ucred_geteuid (uc); - egid = ucred_getegid (uc); - conn_info->client_pid = ucred_getpid (uc); - if (api->security_valid (euid, egid)) { - auth_res = CS_OK; - } else { - auth_res = hdb_error_to_cs(errno); - } - ucred_free(uc); - } - } -#elif HAVE_GETPEEREID -/* - * Usually MacOSX systems - */ - - { - uid_t euid; - gid_t egid; - - /* - * TODO get the peer's pid. - * conn_info->client_pid = ?; - */ - euid = -1; - egid = -1; - if (getpeereid (conn_info->fd, &euid, &egid) == 0) { - if (api->security_valid (euid, egid)) { - auth_res = CS_OK; - } else { - auth_res = hdb_error_to_cs(errno); - } - } - } - -#elif SO_PASSCRED -/* - * Usually Linux systems - */ - cmsg = CMSG_FIRSTHDR (&msg_recv); - assert (cmsg); - cred = (struct ucred *)CMSG_DATA (cmsg); - if (cred) { - conn_info->client_pid = cred->pid; - if (api->security_valid (cred->uid, cred->gid)) { - auth_res = CS_OK; - } else { - auth_res = hdb_error_to_cs(errno); - } - } - -#else /* no credentials */ - auth_res = CS_OK; - log_printf (LOGSYS_LEVEL_ERROR, "Platform does not support IPC authentication. Using no authentication\n"); -#endif /* no credentials */ - - if (auth_res != CS_OK) { - ipc_disconnect (conn_info); - if (auth_res == CS_ERR_NO_RESOURCES) { - log_printf (LOGSYS_LEVEL_ERROR, - "Not enough file desciptors for IPC connection.\n"); - } else { - log_printf (LOGSYS_LEVEL_ERROR, "Invalid IPC credentials.\n"); - } - return auth_res; - } - - if (conn_info->setup_bytes_read == sizeof (mar_req_setup_t)) { -#ifdef COROSYNC_LINUX - setsockopt(conn_info->fd, SOL_SOCKET, SO_PASSCRED, - &off, sizeof (off)); -#endif - return (CS_OK); - } - return (CS_ERR_LIBRARY); -} - -static void ipc_disconnect (struct conn_info *conn_info) -{ - if (conn_info->state == CONN_STATE_THREAD_INACTIVE) { - conn_info->state = CONN_STATE_DISCONNECT_INACTIVE; - return; - } - if (conn_info->state != CONN_STATE_THREAD_ACTIVE) { - return; - } - pthread_mutex_lock (&conn_info->mutex); - conn_info->state = CONN_STATE_THREAD_REQUEST_EXIT; - pthread_mutex_unlock (&conn_info->mutex); - - ipc_sem_post (conn_info->control_buffer, SEMAPHORE_REQUEST_OR_FLUSH_OR_EXIT); -} - -static int conn_info_create (int fd) -{ - struct conn_info *conn_info; - - conn_info = api->malloc (sizeof (struct conn_info)); - if (conn_info == NULL) { - return (-1); - } - memset (conn_info, 0, sizeof (struct conn_info)); - - conn_info->fd = fd; - conn_info->client_pid = 0; - conn_info->service = SOCKET_SERVICE_INIT; - conn_info->state = CONN_STATE_THREAD_INACTIVE; - conn_info->poll_state = POLL_STATE_IN; - list_init (&conn_info->outq_head); - list_init (&conn_info->list); - list_init (&conn_info->zcb_mapped_list_head); - list_add (&conn_info->list, &conn_info_list_head); - - api->poll_dispatch_add (fd, conn_info); - - return (0); -} - -#if defined(COROSYNC_LINUX) || defined(COROSYNC_SOLARIS) -/* SUN_LEN is broken for abstract namespace - */ -#define COROSYNC_SUN_LEN(a) sizeof(*(a)) -#else -#define COROSYNC_SUN_LEN(a) SUN_LEN(a) -#endif - - -/* - * Exported functions - */ -extern void coroipcs_ipc_init_v2 ( - struct coroipcs_init_state_v2 *init_state_v2) -{ - api = init_state_v2; - api->old_log_printf = NULL; - - log_printf (LOGSYS_LEVEL_DEBUG, "you are using ipc api v2\n"); - _corosync_ipc_init (); -} - -extern void coroipcs_ipc_init ( - struct coroipcs_init_state *init_state) -{ - api = calloc (sizeof(struct coroipcs_init_state_v2), 1); - /* v2 api */ - api->stats_create_connection = dummy_stats_create_connection; - api->stats_destroy_connection = dummy_stats_destroy_connection; - api->stats_update_value = dummy_stats_update_value; - api->stats_increment_value = dummy_stats_increment_value; - api->log_printf = NULL; - - /* v1 api */ - api->socket_name = init_state->socket_name; - api->sched_policy = init_state->sched_policy; - api->sched_param = init_state->sched_param; - api->malloc = init_state->malloc; - api->free = init_state->free; - api->old_log_printf = init_state->log_printf; - api->fatal_error = init_state->fatal_error; - api->security_valid = init_state->security_valid; - api->service_available = init_state->service_available; - api->private_data_size_get = init_state->private_data_size_get; - api->serialize_lock = init_state->serialize_lock; - api->serialize_unlock = init_state->serialize_unlock; - api->sending_allowed = init_state->sending_allowed; - api->sending_allowed_release = init_state->sending_allowed_release; - api->poll_accept_add = init_state->poll_accept_add; - api->poll_dispatch_add = init_state->poll_dispatch_add; - api->poll_dispatch_modify = init_state->poll_dispatch_modify; - api->init_fn_get = init_state->init_fn_get; - api->exit_fn_get = init_state->exit_fn_get; - api->handler_fn_get = init_state->handler_fn_get; - - log_printf (LOGSYS_LEVEL_DEBUG, "you are using ipc api v1\n"); - - _corosync_ipc_init (); -} - -static void _corosync_ipc_init(void) -{ - int server_fd; - struct sockaddr_un un_addr; - int res; - - /* - * Create socket for IPC clients, name socket, listen for connections - */ -#if defined(COROSYNC_SOLARIS) - server_fd = socket (PF_UNIX, SOCK_STREAM, 0); -#else - server_fd = socket (PF_LOCAL, SOCK_STREAM, 0); -#endif - if (server_fd == -1) { - log_printf (LOGSYS_LEVEL_CRIT, "Cannot create client connections socket.\n"); - api->fatal_error ("Can't create library listen socket"); - } - - res = fcntl (server_fd, F_SETFL, O_NONBLOCK); - if (res == -1) { - LOGSYS_PERROR (errno, LOGSYS_LEVEL_CRIT, - "Could not set non-blocking operation on server socket"); - api->fatal_error ("Could not set non-blocking operation on server socket"); - } - - memset (&un_addr, 0, sizeof (struct sockaddr_un)); - un_addr.sun_family = AF_UNIX; -#if defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN) - un_addr.sun_len = SUN_LEN(&un_addr); -#endif - -#if defined(COROSYNC_LINUX) - sprintf (un_addr.sun_path + 1, "%s", api->socket_name); -#else - { - struct stat stat_out; - res = stat (SOCKETDIR, &stat_out); - if (res == -1 || (res == 0 && !S_ISDIR(stat_out.st_mode))) { - log_printf (LOGSYS_LEVEL_CRIT, "Required directory not present %s\n", SOCKETDIR); - api->fatal_error ("Please create required directory."); - } - sprintf (un_addr.sun_path, "%s/%s", SOCKETDIR, api->socket_name); - unlink (un_addr.sun_path); - } -#endif - - res = bind (server_fd, (struct sockaddr *)&un_addr, COROSYNC_SUN_LEN(&un_addr)); - if (res) { - LOGSYS_PERROR (errno, LOGSYS_LEVEL_CRIT, - "Could not bind AF_UNIX (%s)", un_addr.sun_path); - api->fatal_error ("Could not bind to AF_UNIX socket\n"); - } - - /* - * Allow eveyrone to write to the socket since the IPC layer handles - * security automatically - */ -#if !defined(COROSYNC_LINUX) - res = chmod (un_addr.sun_path, S_IRWXU|S_IRWXG|S_IRWXO); -#endif - listen (server_fd, SERVER_BACKLOG); - - /* - * Setup connection dispatch routine - */ - api->poll_accept_add (server_fd); -} - -void coroipcs_ipc_exit (void) -{ - struct list_head *list; - struct conn_info *conn_info; - unsigned int res; - - for (list = conn_info_list_head.next; list != &conn_info_list_head; - list = list->next) { - - conn_info = list_entry (list, struct conn_info, list); - - if (conn_info->state != CONN_STATE_THREAD_ACTIVE) - continue; - - ipc_disconnect (conn_info); - -#if _POSIX_THREAD_PROCESS_SHARED > 0 - sem_destroy (&conn_info->control_buffer->sem_request_or_flush_or_exit); - sem_destroy (&conn_info->control_buffer->sem_request); - sem_destroy (&conn_info->control_buffer->sem_response); - sem_destroy (&conn_info->control_buffer->sem_dispatch); -#else - semctl (conn_info->control_buffer->semid, 0, IPC_RMID); -#endif - - /* - * Unmap memory segments - */ - res = munmap ((void *)conn_info->control_buffer, - conn_info->control_size); - res = munmap ((void *)conn_info->request_buffer, - conn_info->request_size); - res = munmap ((void *)conn_info->response_buffer, - conn_info->response_size); - res = circular_memory_unmap (conn_info->dispatch_buffer, - conn_info->dispatch_size); - } -} - -int coroipcs_ipc_service_exit (unsigned int service) -{ - struct list_head *list, *list_next; - struct conn_info *conn_info; - - for (list = conn_info_list_head.next; list != &conn_info_list_head; - list = list_next) { - - list_next = list->next; - - conn_info = list_entry (list, struct conn_info, list); - - if (conn_info->service != service || - (conn_info->state != CONN_STATE_THREAD_ACTIVE && conn_info->state != CONN_STATE_THREAD_REQUEST_EXIT)) { - continue; - } - - ipc_disconnect (conn_info); - api->poll_dispatch_destroy (conn_info->fd, NULL); - while (conn_info_destroy (conn_info) != -1) - ; - - /* - * We will return to prevent token loss. Schedwrk will call us again. - */ - return (-1); - } - - /* - * No conn info left in active list. We will traverse thru exit list. If there is any - * conn_info->service == service, we will wait to proper end -> return -1 - */ - - for (list = conn_info_exit_list_head.next; list != &conn_info_exit_list_head; list = list->next) { - conn_info = list_entry (list, struct conn_info, list); - - if (conn_info->service == service) { - return (-1); - } - } - - return (0); -} - -/* - * Get the conn info private data - */ -void *coroipcs_private_data_get (void *conn) -{ - struct conn_info *conn_info = (struct conn_info *)conn; - - return (conn_info->private_data); -} - -int coroipcs_response_send (void *conn, const void *msg, size_t mlen) -{ - struct conn_info *conn_info = (struct conn_info *)conn; - - memcpy (conn_info->response_buffer, msg, mlen); - - ipc_sem_post (conn_info->control_buffer, SEMAPHORE_RESPONSE); - - api->stats_increment_value (conn_info->stats_handle, "responses"); - return (0); -} - -int coroipcs_response_iov_send (void *conn, const struct iovec *iov, unsigned int iov_len) -{ - struct conn_info *conn_info = (struct conn_info *)conn; - int write_idx = 0; - int i; - - for (i = 0; i < iov_len; i++) { - memcpy (&conn_info->response_buffer[write_idx], - iov[i].iov_base, iov[i].iov_len); - write_idx += iov[i].iov_len; - } - - ipc_sem_post (conn_info->control_buffer, SEMAPHORE_RESPONSE); - - api->stats_increment_value (conn_info->stats_handle, "responses"); - return (0); -} - -static int shared_mem_dispatch_bytes_left (const struct conn_info *conn_info) -{ - unsigned int n_read; - unsigned int n_write; - unsigned int bytes_left; - - n_read = conn_info->control_buffer->read; - n_write = conn_info->control_buffer->write; - - if (n_read <= n_write) { - bytes_left = conn_info->dispatch_size - n_write + n_read; - } else { - bytes_left = n_read - n_write; - } - if (bytes_left > 0) { - bytes_left--; - } - - return (bytes_left); -} - -static void memcpy_dwrap (struct conn_info *conn_info, void *msg, unsigned int len) -{ - unsigned int write_idx; - - write_idx = conn_info->control_buffer->write; - - memcpy (&conn_info->dispatch_buffer[write_idx], msg, len); - conn_info->control_buffer->write = ((write_idx + len + 7) & 0xFFFFFFF8) % conn_info->dispatch_size; -} - -static void msg_send (void *conn, const struct iovec *iov, unsigned int iov_len, - int locked) -{ - struct conn_info *conn_info = (struct conn_info *)conn; - int res; - int i; - char buf; - - for (i = 0; i < iov_len; i++) { - memcpy_dwrap (conn_info, iov[i].iov_base, iov[i].iov_len); - } - - buf = list_empty (&conn_info->outq_head); - res = send (conn_info->fd, &buf, 1, MSG_NOSIGNAL); - if (res != 1) { - conn_info->pending_semops += 1; - if (conn_info->poll_state == POLL_STATE_IN) { - conn_info->poll_state = POLL_STATE_INOUT; - api->poll_dispatch_modify (conn_info->fd, - POLLIN|POLLOUT|POLLNVAL, conn_info); - } - } - - ipc_sem_post (conn_info->control_buffer, SEMAPHORE_DISPATCH); -} - -static void outq_flush (struct conn_info *conn_info) { - struct list_head *list, *list_next; - struct outq_item *outq_item; - unsigned int bytes_left; - struct iovec iov; - int32_t q_size_dec = 0; - int32_t i; - int32_t fc_set; - - pthread_mutex_lock (&conn_info->mutex); - if (list_empty (&conn_info->outq_head)) { - fc_set = flow_control_state_set (conn_info, 0); - pthread_mutex_unlock (&conn_info->mutex); - if (fc_set) { - flow_control_stats_update (conn_info->stats_handle, 0); - } - return; - } - for (list = conn_info->outq_head.next; - list != &conn_info->outq_head; list = list_next) { - - list_next = list->next; - outq_item = list_entry (list, struct outq_item, list); - bytes_left = shared_mem_dispatch_bytes_left (conn_info); - if (bytes_left > outq_item->mlen) { - iov.iov_base = outq_item->msg; - iov.iov_len = outq_item->mlen; - msg_send (conn_info, &iov, 1, MSG_SEND_UNLOCKED); - list_del (list); - api->free (iov.iov_base); - api->free (outq_item); - q_size_dec++; - } else { - break; - } - } - pthread_mutex_unlock (&conn_info->mutex); - - /* - * these need to be sent out of the conn_info->mutex - */ - for (i = 0; i < q_size_dec; i++) { - api->stats_decrement_value (conn_info->stats_handle, "queue_size"); - api->stats_increment_value (conn_info->stats_handle, "dispatched"); - } -} - -static int priv_change (struct conn_info *conn_info) -{ - mar_req_priv_change req_priv_change; - unsigned int res; -#if _POSIX_THREAD_PROCESS_SHARED < 1 - union semun semun; - struct semid_ds ipc_set; - int i; -#endif - -retry_recv: - res = recv (conn_info->fd, &req_priv_change, - sizeof (mar_req_priv_change), - MSG_NOSIGNAL); - if (res == -1 && errno == EINTR) { - api->stats_increment_value (conn_info->stats_handle, "recv_retry_count"); - goto retry_recv; - } - if (res == -1 && errno == EAGAIN) { - api->stats_increment_value (conn_info->stats_handle, "recv_retry_count"); - goto retry_recv; - } - if (res == -1 && errno != EAGAIN) { - return (-1); - } -#if defined(COROSYNC_SOLARIS) || defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN) - /* Error on socket, EOF is detected when recv return 0 - */ - if (res == 0) { - return (-1); - } -#endif - -#if _POSIX_THREAD_PROCESS_SHARED < 1 - ipc_set.sem_perm.uid = req_priv_change.euid; - ipc_set.sem_perm.gid = req_priv_change.egid; - ipc_set.sem_perm.mode = 0600; - - semun.buf = &ipc_set; - - for (i = 0; i < 3; i++) { - res = semctl (conn_info->control_buffer->semid, 0, IPC_SET, semun); - if (res == -1) { - return (-1); - } - } -#endif - return (0); -} - -static void msg_send_or_queue (void *conn, const struct iovec *iov, unsigned int iov_len) -{ - struct conn_info *conn_info = (struct conn_info *)conn; - unsigned int bytes_left; - unsigned int bytes_msg = 0; - int i; - struct outq_item *outq_item; - char *write_buf = 0; - - /* - * Exit transmission if the connection is dead - */ - if (ipc_thread_active (conn) == 0) { - return; - } - - bytes_left = shared_mem_dispatch_bytes_left (conn_info); - for (i = 0; i < iov_len; i++) { - bytes_msg += iov[i].iov_len; - } - if (bytes_left < bytes_msg || list_empty (&conn_info->outq_head) == 0) { - if (flow_control_state_set (conn_info, 1)) { - flow_control_stats_update(conn_info->stats_handle, 1); - } - outq_item = api->malloc (sizeof (struct outq_item)); - if (outq_item == NULL) { - ipc_disconnect (conn); - return; - } - outq_item->msg = api->malloc (bytes_msg); - if (outq_item->msg == 0) { - api->free (outq_item); - ipc_disconnect (conn); - return; - } - - write_buf = outq_item->msg; - for (i = 0; i < iov_len; i++) { - memcpy (write_buf, iov[i].iov_base, iov[i].iov_len); - write_buf += iov[i].iov_len; - } - outq_item->mlen = bytes_msg; - list_init (&outq_item->list); - pthread_mutex_lock (&conn_info->mutex); - list_add_tail (&outq_item->list, &conn_info->outq_head); - pthread_mutex_unlock (&conn_info->mutex); - api->stats_increment_value (conn_info->stats_handle, "queue_size"); - return; - } - msg_send (conn, iov, iov_len, MSG_SEND_LOCKED); - api->stats_increment_value (conn_info->stats_handle, "dispatched"); -} - -void coroipcs_refcount_inc (void *conn) -{ - struct conn_info *conn_info = (struct conn_info *)conn; - - pthread_mutex_lock (&conn_info->mutex); - conn_info->refcount++; - pthread_mutex_unlock (&conn_info->mutex); -} - -void coroipcs_refcount_dec (void *conn) -{ - struct conn_info *conn_info = (struct conn_info *)conn; - - pthread_mutex_lock (&conn_info->mutex); - conn_info->refcount--; - pthread_mutex_unlock (&conn_info->mutex); -} - -int coroipcs_dispatch_send (void *conn, const void *msg, size_t mlen) -{ - struct iovec iov; - - iov.iov_base = (void *)msg; - iov.iov_len = mlen; - - msg_send_or_queue (conn, &iov, 1); - return (0); -} - -int coroipcs_dispatch_iov_send (void *conn, const struct iovec *iov, unsigned int iov_len) -{ - msg_send_or_queue (conn, iov, iov_len); - return (0); -} - -int coroipcs_handler_accept ( - int fd, - int revent, - void *data) -{ - socklen_t addrlen; - struct sockaddr_un un_addr; - int new_fd; -#ifdef COROSYNC_LINUX - int on = 1; -#endif - int res; - - addrlen = sizeof (struct sockaddr_un); - -retry_accept: - new_fd = accept (fd, (struct sockaddr *)&un_addr, &addrlen); - if (new_fd == -1 && errno == EINTR) { - goto retry_accept; - } - - if (new_fd == -1) { - LOGSYS_PERROR (errno, LOGSYS_LEVEL_ERROR, - "Could not accept Library connection"); - return (0); /* This is an error, but -1 would indicate disconnect from poll loop */ - } - - res = fcntl (new_fd, F_SETFL, O_NONBLOCK); - if (res == -1) { - LOGSYS_PERROR (errno, LOGSYS_LEVEL_ERROR, - "Could not set non-blocking operation on library connection"); - close (new_fd); - return (0); /* This is an error, but -1 would indicate disconnect from poll loop */ - } - - /* - * Valid accept - */ - - /* - * Request credentials of sender provided by kernel - */ -#ifdef COROSYNC_LINUX - setsockopt(new_fd, SOL_SOCKET, SO_PASSCRED, &on, sizeof (on)); -#endif - - res = conn_info_create (new_fd); - if (res != 0) { - close (new_fd); - } - - return (0); -} - -static char * pid_to_name (pid_t pid, char *out_name, size_t name_len) -{ - char *name; - char *rest; - FILE *fp; - char fname[32]; - char buf[256]; - - snprintf (fname, 32, "/proc/%d/stat", pid); - fp = fopen (fname, "r"); - if (!fp) { - return NULL; - } - - if (fgets (buf, sizeof (buf), fp) == NULL) { - fclose (fp); - return NULL; - } - fclose (fp); - - name = strrchr (buf, '('); - if (!name) { - return NULL; - } - - /* move past the bracket */ - name++; - - rest = strrchr (buf, ')'); - - if (rest == NULL || rest[1] != ' ') { - return NULL; - } - - *rest = '\0'; - /* move past the NULL and space */ - rest += 2; - - /* copy the name */ - strncpy (out_name, name, name_len); - out_name[name_len - 1] = '\0'; - return out_name; -} - -static void coroipcs_init_conn_stats ( - struct conn_info *conn) -{ - char conn_name[CS_MAX_NAME_LENGTH]; - char proc_name[CS_MAX_NAME_LENGTH]; - char int_str[4]; - - if (conn->client_pid > 0) { - if (pid_to_name (conn->client_pid, proc_name, sizeof(proc_name))) { - snprintf (conn_name, sizeof(conn_name), - "%s:%s:%d:%d", proc_name, - short_service_name_get(conn->service, int_str, 4), - conn->client_pid, conn->fd); - } else { - snprintf (conn_name, sizeof(conn_name), - "proc:%s:%d:%d", - short_service_name_get(conn->service, int_str, 4), - conn->client_pid, - conn->fd); - } - } else { - snprintf (conn_name, sizeof(conn_name), - "proc:%s:pid:%d", - short_service_name_get(conn->service, int_str, 4), - conn->fd); - } - conn->stats_handle = api->stats_create_connection (conn_name, conn->client_pid, conn->fd); - api->stats_update_value (conn->stats_handle, "service_id", - &conn->service, sizeof(conn->service)); -} - -int coroipcs_handler_dispatch ( - int fd, - int revent, - void *context) -{ - mar_req_setup_t *req_setup; - struct conn_info *conn_info = (struct conn_info *)context; - int res; - char buf = 0; - - if (ipc_thread_exiting (conn_info)) { - return conn_info_destroy (conn_info); - } - - /* - * If an error occurs, request exit - */ - if (revent & (POLLERR|POLLHUP)) { - ipc_disconnect (conn_info); - return (0); - } - - /* - * Read the header and process it - */ - if (conn_info->service == SOCKET_SERVICE_INIT && (revent & POLLIN)) { - pthread_attr_t thread_attr; - - /* - * Receive in a nonblocking fashion the request - * IF security invalid, send ERR_SECURITY, otherwise - * send OK - */ - res = req_setup_recv (conn_info); - if (res != CS_OK && res != CS_ERR_LIBRARY) { - req_setup_send (conn_info, res); - } - if (res != CS_OK) { - return (0); - } - - pthread_mutex_init (&conn_info->mutex, NULL); - req_setup = (mar_req_setup_t *)conn_info->setup_msg; - /* - * Is the service registered ? - * Has service init function ? - */ - if (api->service_available (req_setup->service) == 0 || - api->init_fn_get (req_setup->service) == NULL) { - req_setup_send (conn_info, CS_ERR_NOT_EXIST); - ipc_disconnect (conn_info); - return (0); - } -#if _POSIX_THREAD_PROCESS_SHARED < 1 - conn_info->semkey = req_setup->semkey; -#endif - res = memory_map ( - req_setup->control_file, - req_setup->control_size, - (void *)&conn_info->control_buffer); - if (res == -1) { - goto send_setup_response; - } - conn_info->control_size = req_setup->control_size; - - res = memory_map ( - req_setup->request_file, - req_setup->request_size, - (void *)&conn_info->request_buffer); - if (res == -1) { - goto send_setup_response; - } - conn_info->request_size = req_setup->request_size; - - res = memory_map ( - req_setup->response_file, - req_setup->response_size, - (void *)&conn_info->response_buffer); - if (res == -1) { - goto send_setup_response; - } - conn_info->response_size = req_setup->response_size; - - res = circular_memory_map ( - req_setup->dispatch_file, - req_setup->dispatch_size, - (void *)&conn_info->dispatch_buffer); - if (res == -1) { - goto send_setup_response; - } - conn_info->dispatch_size = req_setup->dispatch_size; - - send_setup_response: - if (res == 0) { - req_setup_send (conn_info, CS_OK); - } else { - req_setup_send (conn_info, CS_ERR_LIBRARY); - ipc_disconnect (conn_info); - return (0); - } - - conn_info->service = req_setup->service; - conn_info->refcount = 0; - conn_info->setup_bytes_read = 0; - -#if _POSIX_THREAD_PROCESS_SHARED < 1 - conn_info->control_buffer->semid = semget (conn_info->semkey, 3, 0600); -#endif - conn_info->pending_semops = 0; - - /* - * ipc thread is the only reference at startup - */ - conn_info->refcount = 1; - conn_info->state = CONN_STATE_THREAD_ACTIVE; - - conn_info->private_data = api->malloc (api->private_data_size_get (conn_info->service)); - memset (conn_info->private_data, 0, - api->private_data_size_get (conn_info->service)); - - api->init_fn_get (conn_info->service) (conn_info); - - /* create stats objects */ - coroipcs_init_conn_stats (conn_info); - - pthread_attr_init (&thread_attr); - /* - * IA64 needs more stack space then other arches - */ - #if defined(__ia64__) - pthread_attr_setstacksize (&thread_attr, 400000); - #else - pthread_attr_setstacksize (&thread_attr, 200000); - #endif - - pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_JOINABLE); - res = pthread_create (&conn_info->thread, - &thread_attr, - pthread_ipc_consumer, - conn_info); - pthread_attr_destroy (&thread_attr); - - /* - * Security check - disallow multiple configurations of - * the ipc connection - */ - if (conn_info->service == SOCKET_SERVICE_INIT) { - conn_info->service = SOCKET_SERVICE_SECURITY_VIOLATION; - } - } else - if (revent & POLLIN) { - coroipcs_refcount_inc (conn_info); - res = recv (fd, &buf, 1, MSG_NOSIGNAL); - if (res == 1) { - switch (buf) { - case MESSAGE_REQ_CHANGE_EUID: - if (priv_change (conn_info) == -1) { - ipc_disconnect (conn_info); - } - break; - default: - res = 0; - break; - } - } -#if defined(COROSYNC_SOLARIS) || defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN) - /* On many OS poll never return POLLHUP or POLLERR. - * EOF is detected when recvmsg return 0. - */ - if (res == 0) { - ipc_disconnect (conn_info); - coroipcs_refcount_dec (conn_info); - return (0); - } -#endif - coroipcs_refcount_dec (conn_info); - } - - if (revent & POLLOUT) { - int psop = conn_info->pending_semops; - int i; - - assert (psop != 0); - for (i = 0; i < psop; i++) { - res = send (conn_info->fd, &buf, 1, MSG_NOSIGNAL); - if (res != 1) { - return (0); - } else { - conn_info->pending_semops -= 1; - } - } - if (conn_info->poll_state == POLL_STATE_INOUT) { - conn_info->poll_state = POLL_STATE_IN; - api->poll_dispatch_modify (conn_info->fd, POLLIN|POLLNVAL, conn_info); - } - } - - return (0); -} - diff --git a/exec/coroparse.c b/exec/coroparse.c index 29b44a67..29875b90 100644 --- a/exec/coroparse.c +++ b/exec/coroparse.c @@ -231,6 +231,7 @@ static int parser_check_item_uidgid(struct objdb_iface_ver0 *objdb, return 1; } + static int read_uidgid_files_into_objdb( struct objdb_iface_ver0 *objdb, const char **error_string) diff --git a/exec/evil.c b/exec/evil.c index 9d61c5bc..9ad8a21f 100644 --- a/exec/evil.c +++ b/exec/evil.c @@ -67,7 +67,6 @@ #include #include #include -#include #include #include #include @@ -75,7 +74,7 @@ #include #include #include -#include +#include #include "sync.h" #include "evil.h" @@ -255,11 +254,6 @@ enum clm_message_req_types { #define SA_MAX_NAME_LENGTH 256 -typedef struct { - int size __attribute__((aligned(8))); - int id __attribute__((aligned(8))); -} mar_req_header_t __attribute__((aligned(8))); - typedef enum { MAR_CLM_AF_INET = 1, MAR_CLM_AF_INET6 = 2 @@ -296,7 +290,7 @@ typedef struct { mar_clm_cluster_node_t my_cluster_node; struct req_exec_clm_nodejoin { - mar_req_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_clm_cluster_node_t cluster_node __attribute__((aligned(8))); }; @@ -450,7 +444,7 @@ enum evt_message_req_types { }; struct req_evt_chan_command { - mar_req_header_t chc_head __attribute__((aligned(8))); + struct qb_ipc_request_header chc_head __attribute__((aligned(8))); mar_uint32_t chc_op __attribute__((aligned(8))); }; diff --git a/exec/ipc_glue.c b/exec/ipc_glue.c new file mode 100644 index 00000000..ab0c8666 --- /dev/null +++ b/exec/ipc_glue.c @@ -0,0 +1,749 @@ +/* + * Copyright (c) 2010 Red Hat, Inc. + * + * All rights reserved. + * + * Author: Angus Salkeld + * + * 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 Red Hat, 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 + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "mainconfig.h" +#include "sync.h" +#include "syncv2.h" +#include "timer.h" +#include "main.h" +#include "util.h" +#include "apidef.h" +#include "service.h" + +LOGSYS_DECLARE_SUBSYS ("MAIN"); + +static struct corosync_api_v1 *api = NULL; +static int ipc_subsys_id = -1; +static int32_t ipc_not_enough_fds_left = 0; +static int32_t ipc_fc_is_quorate; /* boolean */ +static int32_t ipc_fc_totem_queue_level; /* percentage used */ +static int32_t ipc_fc_sync_in_process; /* boolean */ +static qb_handle_t object_connection_handle; + +struct cs_ipcs_mapper { + int32_t id; + qb_ipcs_service_t *inst; + char name[256]; +}; + +static struct cs_ipcs_mapper ipcs_mapper[SERVICE_HANDLER_MAXIMUM_COUNT]; + +static int32_t cs_ipcs_job_add(enum qb_loop_priority p, void *data, qb_loop_job_dispatch_fn fn); +static int32_t cs_ipcs_dispatch_add(enum qb_loop_priority p, int32_t fd, int32_t events, + void *data, qb_ipcs_dispatch_fn_t fn); +static int32_t cs_ipcs_dispatch_mod(enum qb_loop_priority p, int32_t fd, int32_t events, + void *data, qb_ipcs_dispatch_fn_t fn); +static int32_t cs_ipcs_dispatch_del(int32_t fd); + + +static struct qb_ipcs_poll_handlers corosync_poll_funcs = { + .job_add = cs_ipcs_job_add, + .dispatch_add = cs_ipcs_dispatch_add, + .dispatch_mod = cs_ipcs_dispatch_mod, + .dispatch_del = cs_ipcs_dispatch_del, +}; + +static int32_t cs_ipcs_connection_accept (qb_ipcs_connection_t *c, uid_t euid, gid_t egid); +static void cs_ipcs_connection_created(qb_ipcs_connection_t *c); +static int32_t cs_ipcs_msg_process(qb_ipcs_connection_t *c, + void *data, size_t size); +static int32_t cs_ipcs_connection_closed (qb_ipcs_connection_t *c); +static void cs_ipcs_connection_destroyed (qb_ipcs_connection_t *c); + +static struct qb_ipcs_service_handlers corosync_service_funcs = { + .connection_accept = cs_ipcs_connection_accept, + .connection_created = cs_ipcs_connection_created, + .msg_process = cs_ipcs_msg_process, + .connection_closed = cs_ipcs_connection_closed, + .connection_destroyed = cs_ipcs_connection_destroyed, +}; + +static const char* cs_ipcs_serv_short_name(int32_t service_id) +{ + const char *name; + switch (service_id) { + case EVS_SERVICE: + name = "evs"; + break; + case CLM_SERVICE: + name = "saClm"; + break; + case AMF_SERVICE: + name = "saAmf"; + break; + case CKPT_SERVICE: + name = "saCkpt"; + break; + case EVT_SERVICE: + name = "saEvt"; + break; + case LCK_SERVICE: + name = "saLck"; + break; + case MSG_SERVICE: + name = "saMsg"; + break; + case CFG_SERVICE: + name = "cfg"; + break; + case CPG_SERVICE: + name = "cpg"; + break; + case CMAN_SERVICE: + name = "cman"; + break; + case PCMK_SERVICE: + name = "pacemaker.engine"; + break; + case CONFDB_SERVICE: + name = "confdb"; + break; + case QUORUM_SERVICE: + name = "quorum"; + break; + case PLOAD_SERVICE: + name = "pload"; + break; + case TMR_SERVICE: + name = "saTmr"; + break; + case VOTEQUORUM_SERVICE: + name = "votequorum"; + break; + case NTF_SERVICE: + name = "saNtf"; + break; + case AMF_V2_SERVICE: + name = "saAmfV2"; + break; + case TST_SV1_SERVICE: + name = "tst"; + break; + case TST_SV2_SERVICE: + name = "tst2"; + break; + case MON_SERVICE: + name = "mon"; + break; + case WD_SERVICE: + name = "wd"; + break; + default: + name = NULL; + break; + } + return name; +} + +int32_t cs_ipcs_service_destroy(int32_t service_id) +{ + qb_ipcs_destroy(ipcs_mapper[service_id].inst); + return 0; +} + +static int32_t cs_ipcs_connection_accept (qb_ipcs_connection_t *c, uid_t euid, gid_t egid) +{ + struct list_head *iter; + int32_t service = qb_ipcs_service_id_get(c); + + if (ais_service[service] == NULL || ais_service_exiting[service]) { + return -ENOSYS; + } + + if (ipc_not_enough_fds_left) { + return -EMFILE; + } + + if (euid == 0 || egid == 0) { + return 0; + } + + for (iter = uidgid_list_head.next; iter != &uidgid_list_head; + iter = iter->next) { + + struct uidgid_item *ugi = qb_list_entry (iter, struct uidgid_item, + list); + + if (euid == ugi->uid || egid == ugi->gid) + return 0; + } + log_printf(LOGSYS_LEVEL_ERROR, "Denied connection attempt from %d:%d", euid, egid); + + return -EACCES; +} + +static char * pid_to_name (pid_t pid, char *out_name, size_t name_len) +{ + char *name; + char *rest; + FILE *fp; + char fname[32]; + char buf[256]; + + snprintf (fname, 32, "/proc/%d/stat", pid); + fp = fopen (fname, "r"); + if (!fp) { + return NULL; + } + + if (fgets (buf, sizeof (buf), fp) == NULL) { + fclose (fp); + return NULL; + } + fclose (fp); + + name = strrchr (buf, '('); + if (!name) { + return NULL; + } + + /* move past the bracket */ + name++; + + rest = strrchr (buf, ')'); + + if (rest == NULL || rest[1] != ' ') { + return NULL; + } + + *rest = '\0'; + /* move past the NULL and space */ + rest += 2; + + /* copy the name */ + strncpy (out_name, name, name_len); + out_name[name_len - 1] = '\0'; + return out_name; +} + + +struct cs_ipcs_conn_context { + qb_handle_t stats_handle; + char data[1]; +}; + +static void cs_ipcs_connection_created(qb_ipcs_connection_t *c) +{ + int32_t service = 0; + uint32_t zero_32 = 0; + uint64_t zero_64 = 0; + unsigned int key_incr_dummy; + qb_handle_t object_handle; + struct cs_ipcs_conn_context *context; + char conn_name[42]; + char proc_name[32]; + struct qb_ipcs_connection_stats stats; + int32_t size = sizeof(struct cs_ipcs_conn_context); + + log_printf(LOG_INFO, "%s() new connection", __func__); + + service = qb_ipcs_service_id_get(c); + + size += ais_service[service]->private_data_size; + context = calloc(1, size); + qb_ipcs_context_set(c, context); + + ais_service[service]->lib_init_fn(c); + + api->object_key_increment (object_connection_handle, + "active", strlen("active"), + &key_incr_dummy); + + qb_ipcs_connection_stats_get(c, &stats, QB_FALSE); + + if (stats.client_pid > 0) { + if (pid_to_name (stats.client_pid, proc_name, sizeof(proc_name))) { + snprintf (conn_name, + sizeof(conn_name), + "%s:%d:%p", proc_name, + stats.client_pid, c); + } else { + snprintf (conn_name, + sizeof(conn_name), + "%d:%p", + stats.client_pid, c); + } + } else { + snprintf (conn_name, + sizeof(conn_name), + "%p", c); + } + + api->object_create (object_connection_handle, + &object_handle, + conn_name, + strlen (conn_name)); + context->stats_handle = object_handle; + + api->object_key_create_typed (object_handle, + "service_id", + &zero_32, sizeof (zero_32), + OBJDB_VALUETYPE_UINT32); + + api->object_key_create_typed (object_handle, + "client_pid", + &zero_32, sizeof (zero_32), + OBJDB_VALUETYPE_INT32); + + api->object_key_create_typed (object_handle, + "responses", + &zero_64, sizeof (zero_64), + OBJDB_VALUETYPE_UINT64); + + api->object_key_create_typed (object_handle, + "dispatched", + &zero_64, sizeof (zero_64), + OBJDB_VALUETYPE_UINT64); + + api->object_key_create_typed (object_handle, + "requests", + &zero_64, sizeof (zero_64), + OBJDB_VALUETYPE_INT64); + + api->object_key_create_typed (object_handle, + "send_retries", + &zero_64, sizeof (zero_64), + OBJDB_VALUETYPE_UINT64); + + api->object_key_create_typed (object_handle, + "recv_retries", + &zero_64, sizeof (zero_64), + OBJDB_VALUETYPE_UINT64); + + api->object_key_create_typed (object_handle, + "flow_control", + &zero_32, sizeof (zero_32), + OBJDB_VALUETYPE_UINT32); + + api->object_key_create_typed (object_handle, + "flow_control_count", + &zero_64, sizeof (zero_64), + OBJDB_VALUETYPE_UINT64); +} + +void cs_ipc_refcnt_inc(void *conn) +{ + qb_ipcs_connection_ref(conn); +} + +void cs_ipc_refcnt_dec(void *conn) +{ + qb_ipcs_connection_unref(conn); +} + +void *cs_ipcs_private_data_get(void *conn) +{ + struct cs_ipcs_conn_context *cnx; + cnx = qb_ipcs_context_get(conn); + return &cnx->data[0]; +} + +static void cs_ipcs_connection_destroyed (qb_ipcs_connection_t *c) +{ + struct cs_ipcs_conn_context *cnx; + log_printf(LOG_INFO, "%s() ", __func__); + cnx = qb_ipcs_context_get(c); + + if (cnx) { + free(cnx); + } +} + +static int32_t cs_ipcs_connection_closed (qb_ipcs_connection_t *c) +{ + struct cs_ipcs_conn_context *cnx; + unsigned int key_incr_dummy; + int32_t res = 0; + int32_t service = qb_ipcs_service_id_get(c); + + log_printf(LOG_INFO, "%s() ", __func__); + res = ais_service[service]->lib_exit_fn(c); + if (res != 0) { + return res; + } + + cnx = qb_ipcs_context_get(c); + api->object_destroy (cnx->stats_handle); + + api->object_key_increment (object_connection_handle, + "closed", strlen("closed"), + &key_incr_dummy); + api->object_key_decrement (object_connection_handle, + "active", strlen("active"), + &key_incr_dummy); + + return 0; +} + +int cs_ipcs_response_iov_send (void *conn, + const struct iovec *iov, + unsigned int iov_len) +{ + int32_t rc = qb_ipcs_response_sendv(conn, iov, iov_len); + if (rc >= 0) { + return 0; + } + return rc; +} + +int cs_ipcs_response_send(void *conn, const void *msg, size_t mlen) +{ + int32_t rc = qb_ipcs_response_send(conn, msg, mlen); + if (rc >= 0) { + return 0; + } + return rc; +} + +int cs_ipcs_dispatch_send(void *conn, const void *msg, size_t mlen) +{ + int32_t rc = qb_ipcs_event_send(conn, msg, mlen); + if (rc >= 0) { + return 0; + } + return rc; +} + +int cs_ipcs_dispatch_iov_send (void *conn, + const struct iovec *iov, + unsigned int iov_len) +{ + int32_t rc = qb_ipcs_event_sendv(conn, iov, iov_len); + if (rc >= 0) { + return 0; + } + return rc; +} + +static int32_t cs_ipcs_msg_process(qb_ipcs_connection_t *c, + void *data, size_t size) +{ + struct qb_ipc_response_header response; + struct qb_ipc_request_header *request_pt = (struct qb_ipc_request_header *)data; + int32_t service = qb_ipcs_service_id_get(c); + int32_t send_ok; + ssize_t res = -1; + int sending_allowed_private_data; + + send_ok = corosync_sending_allowed (service, + request_pt->id, + request_pt, + &sending_allowed_private_data); + + /* + * This happens when the message contains some kind of invalid + * parameter, such as an invalid size + */ + if (send_ok == -1) { + response.size = sizeof (response); + response.id = 0; + response.error = CS_ERR_INVALID_PARAM; + log_printf(LOG_INFO, "%s() invalid message! size:%d error:%d", + __func__, response.size, response.error); + qb_ipcs_response_send (c, + &response, + sizeof (response)); + res = -EINVAL; + } else { + if (send_ok) { + ais_service[service]->lib_engine[request_pt->id].lib_handler_fn(c, request_pt); + res = 0; + } else { + /* + * Overload, tell library to retry + */ + response.size = sizeof (response); + response.id = 0; + response.error = CS_ERR_TRY_AGAIN; + qb_ipcs_response_send (c, + &response, + sizeof (response)); + res = -ENOBUFS; + } + } + corosync_sending_allowed_release (&sending_allowed_private_data); + return res; +} + + +static int32_t cs_ipcs_job_add(enum qb_loop_priority p, void *data, qb_loop_job_dispatch_fn fn) +{ + return qb_loop_job_add(corosync_poll_handle_get(), p, data, fn); +} + +static int32_t cs_ipcs_dispatch_add(enum qb_loop_priority p, int32_t fd, int32_t events, + void *data, qb_ipcs_dispatch_fn_t fn) +{ + return qb_loop_poll_add(corosync_poll_handle_get(), p, fd, events, data, fn); +} + +static int32_t cs_ipcs_dispatch_mod(enum qb_loop_priority p, int32_t fd, int32_t events, + void *data, qb_ipcs_dispatch_fn_t fn) +{ + return qb_loop_poll_mod(corosync_poll_handle_get(), p, fd, events, data, fn); +} + +static int32_t cs_ipcs_dispatch_del(int32_t fd) +{ + return qb_loop_poll_del(corosync_poll_handle_get(), fd); +} + +static void cs_ipcs_low_fds_event(int32_t not_enough, int32_t fds_available) +{ + ipc_not_enough_fds_left = not_enough; + if (not_enough) { + log_printf(LOGSYS_LEVEL_WARNING, "refusing new connections (fds_available:%d)\n", + fds_available); + } else { + log_printf(LOGSYS_LEVEL_NOTICE, "allowing new connections (fds_available:%d)\n", + fds_available); + + } +} + +int32_t cs_ipcs_q_level_get(void) +{ + return ipc_fc_totem_queue_level; +} + +static void cs_ipcs_check_for_flow_control(void) +{ + int32_t i; + int32_t fc_enabled; + qb_loop_timer_handle tm; + + for (i = 0; i < SERVICE_HANDLER_MAXIMUM_COUNT; i++) { + if (ais_service[i] == NULL) { + continue; + } + fc_enabled = QB_TRUE; + if (ipc_fc_is_quorate == 1 || + ais_service[i]->allow_inquorate == CS_LIB_ALLOW_INQUORATE) { + /* + * we are quorate + * now check flow control + */ + if (ipc_fc_totem_queue_level != TOTEM_Q_LEVEL_CRITICAL && + ipc_fc_sync_in_process == 0) { + fc_enabled = QB_FALSE; + } + } + if (fc_enabled) { + qb_ipcs_request_rate_limit(ipcs_mapper[i].inst, QB_IPCS_RATE_OFF); + + qb_loop_timer_add(corosync_poll_handle_get(), QB_LOOP_MED, 1, + NULL, corosync_recheck_the_q_level, &tm); + } else if (ipc_fc_totem_queue_level == TOTEM_Q_LEVEL_LOW) { + qb_ipcs_request_rate_limit(ipcs_mapper[i].inst, QB_IPCS_RATE_FAST); + } else if (ipc_fc_totem_queue_level == TOTEM_Q_LEVEL_GOOD) { + qb_ipcs_request_rate_limit(ipcs_mapper[i].inst, QB_IPCS_RATE_NORMAL); + } else if (ipc_fc_totem_queue_level == TOTEM_Q_LEVEL_HIGH) { + qb_ipcs_request_rate_limit(ipcs_mapper[i].inst, QB_IPCS_RATE_SLOW); + } + } +} + +static void cs_ipcs_fc_quorum_changed(int quorate, void *context) +{ + ipc_fc_is_quorate = quorate; + cs_ipcs_check_for_flow_control(); +} + +static void cs_ipcs_totem_queue_level_changed(enum totem_q_level level) +{ + ipc_fc_totem_queue_level = level; + cs_ipcs_check_for_flow_control(); +} + +void cs_ipcs_sync_state_changed(int32_t sync_in_process) +{ + ipc_fc_sync_in_process = sync_in_process; + cs_ipcs_check_for_flow_control(); +} + +static void cs_ipcs_libqb_log_fn(const char *file_name, + int32_t file_line, + int32_t severity, + const char *msg) +{ + int32_t level = severity; + if (severity > LOG_DEBUG) { + level = LOGSYS_LEVEL_DEBUG; + } + + _logsys_log_printf (LOGSYS_ENCODE_RECID(level, + ipc_subsys_id, + LOGSYS_RECID_LOG), + __func__, file_name, file_line, "%s", msg); +} + +void cs_ipcs_stats_update(void) +{ + int32_t i; + struct qb_ipcs_stats srv_stats; + struct qb_ipcs_connection_stats stats; + qb_ipcs_connection_t *c; + struct cs_ipcs_conn_context *cnx; + + for (i = 0; i < SERVICE_HANDLER_MAXIMUM_COUNT; i++) { + if (ais_service[i] == NULL) { + continue; + } + qb_ipcs_stats_get(ipcs_mapper[i].inst, &srv_stats, QB_FALSE); + + for (c = qb_ipcs_connection_first_get(ipcs_mapper[i].inst); c; + c = qb_ipcs_connection_next_get(ipcs_mapper[i].inst, c)) { + + cnx = qb_ipcs_context_get(c); + if (cnx == NULL) continue; + + qb_ipcs_connection_stats_get(c, &stats, QB_FALSE); + + api->object_key_replace(cnx->stats_handle, + "client_pid", strlen("client_pid"), + &stats.client_pid, sizeof(uint32_t)); + + api->object_key_replace(cnx->stats_handle, + "requests", strlen("requests"), + &stats.requests, sizeof(uint64_t)); + api->object_key_replace(cnx->stats_handle, + "responses", strlen("responses"), + &stats.responses, sizeof(uint64_t)); + api->object_key_replace(cnx->stats_handle, + "dispatched", strlen("dispatched"), + &stats.events, sizeof(uint64_t)); + api->object_key_replace(cnx->stats_handle, + "send_retries", strlen("send_retries"), + &stats.send_retries, sizeof(uint64_t)); + api->object_key_replace(cnx->stats_handle, + "recv_retries", strlen("recv_retries"), + &stats.recv_retries, sizeof(uint64_t)); + api->object_key_replace(cnx->stats_handle, + "flow_control_count", strlen("flow_control_count"), + &stats.flow_control_count, sizeof(uint64_t)); + api->object_key_replace(cnx->stats_handle, + "flow_control_state", strlen("flow_control_state"), + &stats.flow_control_state, sizeof(uint32_t)); + + qb_ipcs_connection_unref(c); + } + } +} + +void cs_ipcs_service_init(struct corosync_service_engine *service) +{ + ipcs_mapper[service->id].id = service->id; + strcpy(ipcs_mapper[service->id].name, cs_ipcs_serv_short_name(service->id)); + log_printf (LOGSYS_LEVEL_INFO, + "Initializing IPC on %s [%d]", + ipcs_mapper[service->id].name, + ipcs_mapper[service->id].id); + ipcs_mapper[service->id].inst = qb_ipcs_create(ipcs_mapper[service->id].name, + ipcs_mapper[service->id].id, + QB_IPC_SHM, + &corosync_service_funcs); + assert(ipcs_mapper[service->id].inst); + qb_ipcs_poll_handlers_set(ipcs_mapper[service->id].inst, + &corosync_poll_funcs); + qb_ipcs_run(ipcs_mapper[service->id].inst); +} + +void cs_ipcs_init(void) +{ + qb_handle_t object_find_handle; + qb_handle_t object_runtime_handle; + uint64_t zero_64 = 0; + + api = apidef_get (); + + qb_loop_poll_low_fds_event_set(corosync_poll_handle_get(), cs_ipcs_low_fds_event); + + ipc_subsys_id = _logsys_subsys_create ("IPC"); + if (ipc_subsys_id < 0) { + log_printf (LOGSYS_LEVEL_ERROR, + "Could not initialize IPC logging subsystem\n"); + corosync_exit_error (AIS_DONE_INIT_SERVICES); + } + + qb_util_set_log_function (cs_ipcs_libqb_log_fn); + + api->quorum_register_callback (cs_ipcs_fc_quorum_changed, NULL); + totempg_queue_level_register_callback (cs_ipcs_totem_queue_level_changed); + + api->object_find_create (OBJECT_PARENT_HANDLE, + "runtime", strlen ("runtime"), + &object_find_handle); + + if (api->object_find_next (object_find_handle, + &object_runtime_handle) != 0) { + log_printf (LOGSYS_LEVEL_ERROR,"arrg no runtime"); + return; + } + + /* Connection objects */ + api->object_create (object_runtime_handle, + &object_connection_handle, + "connections", strlen ("connections")); + + api->object_key_create_typed (object_connection_handle, + "active", &zero_64, sizeof (zero_64), + OBJDB_VALUETYPE_UINT64); + api->object_key_create_typed (object_connection_handle, + "closed", &zero_64, sizeof (zero_64), + OBJDB_VALUETYPE_UINT64); +} + diff --git a/exec/main.c b/exec/main.c index a0e12386..56933ebc 100644 --- a/exec/main.c +++ b/exec/main.c @@ -97,10 +97,11 @@ #include #include +#include +#include #include #include -#include #include #include #include @@ -108,7 +109,6 @@ #include #include #include -#include #include "quorum.h" #include "totemsrp.h" @@ -117,7 +117,6 @@ #include "main.h" #include "sync.h" #include "syncv2.h" -#include "tlist.h" #include "timer.h" #include "util.h" #include "apidef.h" @@ -150,7 +149,7 @@ static int sched_priority = 0; static unsigned int service_count = 32; -static pthread_mutex_t serialize_mutex = PTHREAD_MUTEX_INITIALIZER; +static qb_thread_lock_t *serialize_lock_f; static struct totem_logging_configuration totem_logging_configuration; @@ -170,8 +169,6 @@ static qb_loop_t *corosync_poll_handle; struct sched_param global_sched_param; -static hdb_handle_t object_connection_handle; - static hdb_handle_t object_memb_handle; static corosync_timer_handle_t corosync_stats_timer_handle; @@ -182,8 +179,6 @@ static sem_t corosync_exit_sem; static const char *corosync_lock_file = LOCALSTATEDIR"/run/corosync.pid"; -static int32_t corosync_not_enough_fds_left = 0; - static void serialize_unlock (void); static void serialize_lock (void); @@ -313,16 +308,14 @@ static struct totempg_group corosync_group = { .group_len = 1 }; - - static void serialize_lock (void) { - pthread_mutex_lock (&serialize_mutex); + qb_thread_lock (serialize_lock_f); } static void serialize_unlock (void) { - pthread_mutex_unlock (&serialize_mutex); + qb_thread_unlock (serialize_lock_f); } static void corosync_sync_completed (void) @@ -330,6 +323,8 @@ static void corosync_sync_completed (void) log_printf (LOGSYS_LEVEL_NOTICE, "Completed service synchronization, ready to provide service.\n"); sync_in_process = 0; + + cs_ipcs_sync_state_changed(sync_in_process); } static int corosync_sync_callbacks_retrieve (int sync_id, @@ -491,6 +486,7 @@ static void confchg_fn ( abort_activate = 1; } sync_in_process = 1; + cs_ipcs_sync_state_changed(sync_in_process); serialize_lock (); memcpy (&corosync_ring_id, ring_id, sizeof (struct memb_ring_id)); @@ -737,6 +733,9 @@ static void corosync_totem_stats_updater (void *data) "avg_backlog_calc", strlen("avg_backlog_calc"), &avg_backlog_calc, sizeof (avg_backlog_calc)); } + + cs_ipcs_stats_update(); + api->timer_add_duration (1500 * MILLI_2_NANO_SECONDS, NULL, corosync_totem_stats_updater, &corosync_stats_timer_handle); @@ -887,17 +886,20 @@ static void deliver_fn ( unsigned int msg_len, int endian_conversion_required) { - const coroipc_request_header_t *header; - int service; - int fn_id; - unsigned int id; - unsigned int key_incr_dummy; + const struct qb_ipc_request_header *header; + int32_t service; + int32_t fn_id; + uint32_t id; + uint32_t size; + uint32_t key_incr_dummy; header = msg; if (endian_conversion_required) { id = swab32 (header->id); + size = swab32 (header->size); } else { id = header->id; + size = header->size; } /* @@ -951,10 +953,10 @@ int main_mcast ( unsigned int iov_len, unsigned int guarantee) { - const coroipc_request_header_t *req = iovec->iov_base; - int service; - int fn_id; - unsigned int key_incr_dummy; + const struct qb_ipc_request_header *req = iovec->iov_base; + int32_t service; + int32_t fn_id; + uint32_t key_incr_dummy; service = req->id >> 16; fn_id = req->id & 0xffff; @@ -967,6 +969,85 @@ int main_mcast ( return (totempg_groups_mcast_joined (corosync_group_handle, iovec, iov_len, guarantee)); } +void corosync_recheck_the_q_level(void *data) +{ + qb_loop_timer_handle tm; + + totempg_check_q_level(corosync_group_handle); + if (cs_ipcs_q_level_get() == TOTEM_Q_LEVEL_CRITICAL) { + qb_loop_timer_add(corosync_poll_handle_get(), QB_LOOP_MED, 1, + NULL, corosync_recheck_the_q_level, &tm); + } +} + +struct sending_allowed_private_data_struct { + int reserved_msgs; +}; + + +int corosync_sending_allowed ( + unsigned int service, + unsigned int id, + const void *msg, + void *sending_allowed_private_data) +{ + struct sending_allowed_private_data_struct *pd = + (struct sending_allowed_private_data_struct *)sending_allowed_private_data; + struct iovec reserve_iovec; + struct qb_ipc_request_header *header = (struct qb_ipc_request_header *)msg; + int sending_allowed; + + reserve_iovec.iov_base = (char *)header; + reserve_iovec.iov_len = header->size; + + pd->reserved_msgs = totempg_groups_joined_reserve ( + corosync_group_handle, + &reserve_iovec, 1); + if (pd->reserved_msgs == -1) { + return (-1); + } + + sending_allowed = QB_FALSE; + if (corosync_quorum_is_quorate() == 1 || + ais_service[service]->allow_inquorate == CS_LIB_ALLOW_INQUORATE) { + // we are quorate + // now check flow control + if (ais_service[service]->lib_engine[id].flow_control == CS_LIB_FLOW_CONTROL_NOT_REQUIRED) { + sending_allowed = QB_TRUE; + } else if (pd->reserved_msgs && sync_in_process == 0) { + sending_allowed = QB_TRUE; + } else { + log_printf(LOGSYS_LEVEL_NOTICE, + "no tx: (have quorum) (FC req) reserved:%d sync:%d", + pd->reserved_msgs, sync_in_process); + } + } else { + log_printf(LOGSYS_LEVEL_NOTICE, "no tx: not quorate!"); + } + +/* + sending_allowed = + (corosync_quorum_is_quorate() == 1 || + ais_service[service]->allow_inquorate == CS_LIB_ALLOW_INQUORATE) && + ((ais_service[service]->lib_engine[id].flow_control == CS_LIB_FLOW_CONTROL_NOT_REQUIRED) || + ((ais_service[service]->lib_engine[id].flow_control == CS_LIB_FLOW_CONTROL_REQUIRED) && + (pd->reserved_msgs) && + (sync_in_process == 0))); +*/ + return (sending_allowed); +} + +void corosync_sending_allowed_release (void *sending_allowed_private_data) +{ + struct sending_allowed_private_data_struct *pd = + (struct sending_allowed_private_data_struct *)sending_allowed_private_data; + + if (pd->reserved_msgs == -1) { + return; + } + totempg_groups_joined_release (pd->reserved_msgs); +} + int message_source_is_local (const mar_message_source_t *source) { int ret = 0; @@ -988,330 +1069,6 @@ void message_source_set ( source->conn = conn; } -/* - * Provides the glue from corosync to the IPC Service - */ -static int corosync_private_data_size_get (unsigned int service) -{ - return (ais_service[service]->private_data_size); -} - -static coroipcs_init_fn_lvalue corosync_init_fn_get (unsigned int service) -{ - return (ais_service[service]->lib_init_fn); -} - -static coroipcs_exit_fn_lvalue corosync_exit_fn_get (unsigned int service) -{ - return (ais_service[service]->lib_exit_fn); -} - -static coroipcs_handler_fn_lvalue corosync_handler_fn_get (unsigned int service, unsigned int id) -{ - return (ais_service[service]->lib_engine[id].lib_handler_fn); -} - - -static int corosync_security_valid (int euid, int egid) -{ - struct list_head *iter; - - if (corosync_not_enough_fds_left) { - errno = EMFILE; - return (0); - } - - if (euid == 0 || egid == 0) { - return (1); - } - - for (iter = uidgid_list_head.next; iter != &uidgid_list_head; - iter = iter->next) { - - struct uidgid_item *ugi = list_entry (iter, struct uidgid_item, - list); - - if (euid == ugi->uid || egid == ugi->gid) - return (1); - } - - errno = EACCES; - return (0); -} - -static int corosync_service_available (unsigned int service) -{ - return (ais_service[service] != NULL && !ais_service_exiting[service]); -} - -struct sending_allowed_private_data_struct { - int reserved_msgs; -}; - -static int corosync_sending_allowed ( - unsigned int service, - unsigned int id, - const void *msg, - void *sending_allowed_private_data) -{ - struct sending_allowed_private_data_struct *pd = - (struct sending_allowed_private_data_struct *)sending_allowed_private_data; - struct iovec reserve_iovec; - coroipc_request_header_t *header = (coroipc_request_header_t *)msg; - int sending_allowed; - - reserve_iovec.iov_base = (char *)header; - reserve_iovec.iov_len = header->size; - - pd->reserved_msgs = totempg_groups_joined_reserve ( - corosync_group_handle, - &reserve_iovec, 1); - if (pd->reserved_msgs == -1) { - return (-1); - } - - sending_allowed = - (corosync_quorum_is_quorate() == 1 || - ais_service[service]->allow_inquorate == CS_LIB_ALLOW_INQUORATE) && - ((ais_service[service]->lib_engine[id].flow_control == CS_LIB_FLOW_CONTROL_NOT_REQUIRED) || - ((ais_service[service]->lib_engine[id].flow_control == CS_LIB_FLOW_CONTROL_REQUIRED) && - (pd->reserved_msgs) && - (sync_in_process == 0))); - - return (sending_allowed); -} - -static void corosync_sending_allowed_release (void *sending_allowed_private_data) -{ - struct sending_allowed_private_data_struct *pd = - (struct sending_allowed_private_data_struct *)sending_allowed_private_data; - - if (pd->reserved_msgs == -1) { - return; - } - totempg_groups_joined_release (pd->reserved_msgs); -} - -static int ipc_subsys_id = -1; - - -static void ipc_fatal_error(const char *error_msg) __attribute__((noreturn)); - -static void ipc_fatal_error(const char *error_msg) { - _logsys_log_printf ( - LOGSYS_ENCODE_RECID(LOGSYS_LEVEL_ERROR, - ipc_subsys_id, - LOGSYS_RECID_LOG), - __FUNCTION__, __FILE__, __LINE__, - "%s", error_msg); - exit(EXIT_FAILURE); -} - -static int corosync_poll_handler_accept ( - int fd, - int revent, - void *context) -{ - return (coroipcs_handler_accept (fd, revent, context)); -} - -static int corosync_poll_handler_dispatch ( - int fd, - int revent, - void *context) -{ - return (coroipcs_handler_dispatch (fd, revent, context)); -} - - -static void corosync_poll_accept_add ( - int fd) -{ - qb_loop_poll_add (corosync_poll_handle, QB_LOOP_MED, fd, POLLIN|POLLNVAL, 0, - corosync_poll_handler_accept); -} - -static void corosync_poll_dispatch_add ( - int fd, - void *context) -{ - qb_loop_poll_add (corosync_poll_handle, QB_LOOP_MED, fd, POLLIN|POLLNVAL, context, - corosync_poll_handler_dispatch); -} - -static void corosync_poll_dispatch_modify ( - int fd, - int events, - void *context) -{ - qb_loop_poll_mod (corosync_poll_handle, QB_LOOP_MED, fd, events, context, - corosync_poll_handler_dispatch); -} - -static void corosync_poll_dispatch_destroy ( - int fd, - void *context) -{ - qb_loop_poll_del (corosync_poll_handle, fd); -} - -static hdb_handle_t corosync_stats_create_connection (const char* name, - const pid_t pid, const int fd) -{ - uint32_t zero_32 = 0; - uint64_t zero_64 = 0; - unsigned int key_incr_dummy; - hdb_handle_t object_handle; - - objdb->object_key_increment (object_connection_handle, - "active", strlen("active"), - &key_incr_dummy); - - - objdb->object_create (object_connection_handle, - &object_handle, - name, - strlen (name)); - - objdb->object_key_create_typed (object_handle, - "service_id", - &zero_32, sizeof (zero_32), - OBJDB_VALUETYPE_UINT32); - - objdb->object_key_create_typed (object_handle, - "client_pid", - &pid, sizeof (pid), - OBJDB_VALUETYPE_INT32); - - objdb->object_key_create_typed (object_handle, - "responses", - &zero_64, sizeof (zero_64), - OBJDB_VALUETYPE_UINT64); - - objdb->object_key_create_typed (object_handle, - "dispatched", - &zero_64, sizeof (zero_64), - OBJDB_VALUETYPE_UINT64); - - objdb->object_key_create_typed (object_handle, - "requests", - &zero_64, sizeof (zero_64), - OBJDB_VALUETYPE_INT64); - - objdb->object_key_create_typed (object_handle, - "sem_retry_count", - &zero_64, sizeof (zero_64), - OBJDB_VALUETYPE_UINT64); - - objdb->object_key_create_typed (object_handle, - "send_retry_count", - &zero_64, sizeof (zero_64), - OBJDB_VALUETYPE_UINT64); - - objdb->object_key_create_typed (object_handle, - "recv_retry_count", - &zero_64, sizeof (zero_64), - OBJDB_VALUETYPE_UINT64); - - objdb->object_key_create_typed (object_handle, - "flow_control", - &zero_32, sizeof (zero_32), - OBJDB_VALUETYPE_UINT32); - - objdb->object_key_create_typed (object_handle, - "flow_control_count", - &zero_64, sizeof (zero_64), - OBJDB_VALUETYPE_UINT64); - - objdb->object_key_create_typed (object_handle, - "queue_size", - &zero_64, sizeof (zero_64), - OBJDB_VALUETYPE_UINT64); - - objdb->object_key_create_typed (object_handle, - "invalid_request", - &zero_64, sizeof (zero_64), - OBJDB_VALUETYPE_UINT64); - - objdb->object_key_create_typed (object_handle, - "overload", - &zero_64, sizeof (zero_64), - OBJDB_VALUETYPE_UINT64); - - return object_handle; -} - -static void corosync_stats_destroy_connection (hdb_handle_t handle) -{ - unsigned int key_incr_dummy; - - objdb->object_destroy (handle); - - objdb->object_key_increment (object_connection_handle, - "closed", strlen("closed"), - &key_incr_dummy); - objdb->object_key_decrement (object_connection_handle, - "active", strlen("active"), - &key_incr_dummy); -} - -static void corosync_stats_update_value (hdb_handle_t handle, - const char *name, const void *value, - size_t value_len) -{ - objdb->object_key_replace (handle, - name, strlen(name), - value, value_len); -} - -static void corosync_stats_increment_value (hdb_handle_t handle, - const char* name) -{ - unsigned int key_incr_dummy; - - objdb->object_key_increment (handle, - name, strlen(name), - &key_incr_dummy); -} -static void corosync_stats_decrement_value (hdb_handle_t handle, - const char* name) -{ - unsigned int key_incr_dummy; - - objdb->object_key_decrement (handle, - name, strlen(name), - &key_incr_dummy); -} - -static struct coroipcs_init_state_v2 ipc_init_state_v2 = { - .socket_name = COROSYNC_SOCKET_NAME, - .sched_policy = SCHED_OTHER, - .sched_param = &global_sched_param, - .malloc = malloc, - .free = free, - .log_printf = _logsys_log_printf, - .fatal_error = ipc_fatal_error, - .security_valid = corosync_security_valid, - .service_available = corosync_service_available, - .private_data_size_get = corosync_private_data_size_get, - .serialize_lock = serialize_lock, - .serialize_unlock = serialize_unlock, - .sending_allowed = corosync_sending_allowed, - .sending_allowed_release = corosync_sending_allowed_release, - .poll_accept_add = corosync_poll_accept_add, - .poll_dispatch_add = corosync_poll_dispatch_add, - .poll_dispatch_modify = corosync_poll_dispatch_modify, - .poll_dispatch_destroy = corosync_poll_dispatch_destroy, - .init_fn_get = corosync_init_fn_get, - .exit_fn_get = corosync_exit_fn_get, - .handler_fn_get = corosync_handler_fn_get, - .stats_create_connection = corosync_stats_create_connection, - .stats_destroy_connection = corosync_stats_destroy_connection, - .stats_update_value = corosync_stats_update_value, - .stats_increment_value = corosync_stats_increment_value, - .stats_decrement_value = corosync_stats_decrement_value, -}; - static void corosync_setscheduler (void) { #if defined(HAVE_PTHREAD_SETSCHEDPARAM) && defined(HAVE_SCHED_GET_PRIORITY_MAX) && defined(HAVE_SCHED_SETSCHEDULER) @@ -1329,10 +1086,6 @@ static void corosync_setscheduler (void) global_sched_param.sched_priority = 0; logsys_thread_priority_set (SCHED_OTHER, NULL, 1); } else { - /* - * Turn on SCHED_RR in ipc system - */ - ipc_init_state_v2.sched_policy = SCHED_RR; /* * Turn on SCHED_RR in logsys system @@ -1407,49 +1160,10 @@ static void corosync_fplay_control_init (void) NULL, NULL, NULL, NULL); } -static void corosync_stats_init (void) -{ - hdb_handle_t object_find_handle; - hdb_handle_t object_runtime_handle; - uint64_t zero_64 = 0; - - objdb->object_find_create (OBJECT_PARENT_HANDLE, - "runtime", strlen ("runtime"), - &object_find_handle); - - if (objdb->object_find_next (object_find_handle, - &object_runtime_handle) != 0) { - return; - } - - /* Connection objects */ - objdb->object_create (object_runtime_handle, - &object_connection_handle, - "connections", strlen ("connections")); - - objdb->object_key_create_typed (object_connection_handle, - "active", &zero_64, sizeof (zero_64), - OBJDB_VALUETYPE_UINT64); - objdb->object_key_create_typed (object_connection_handle, - "closed", &zero_64, sizeof (zero_64), - OBJDB_VALUETYPE_UINT64); -} - -static void main_low_fds_event(int32_t not_enough, int32_t fds_available) -{ - corosync_not_enough_fds_left = not_enough; - if (not_enough) { - log_printf(LOGSYS_LEVEL_WARNING, "refusing new connections (fds_available:%d)\n", - fds_available); - } else { - log_printf(LOGSYS_LEVEL_NOTICE, "allowing new connections (fds_available:%d)\n", - fds_available); - } -} - static void main_service_ready (void) { int res; + /* * This must occur after totempg is initialized because "this_ip" must be set */ @@ -1459,7 +1173,7 @@ static void main_service_ready (void) corosync_exit_error (AIS_DONE_INIT_SERVICES); } evil_init (api); - corosync_stats_init (); + cs_ipcs_init(); corosync_totem_stats_init (); corosync_fplay_control_init (); if (minimum_sync_mode == CS_SYNC_V2) { @@ -1592,7 +1306,9 @@ int main (int argc, char **argv, char **envp) hdb_handle_t object_runtime_handle; enum e_ais_done flock_err; - /* default configuration + serialize_lock_f = qb_thread_lock_create (QB_THREAD_LOCK_SHORT); + + /* default configuration */ background = 1; setprio = 1; @@ -1820,7 +1536,6 @@ int main (int argc, char **argv, char **envp) sched_priority); corosync_poll_handle = qb_loop_create (); - qb_loop_poll_low_fds_event_set(corosync_poll_handle, main_low_fds_event); /* * Sleep for a while to let other nodes in the cluster @@ -1886,16 +1601,6 @@ int main (int argc, char **argv, char **envp) serialize_lock, serialize_unlock); - ipc_subsys_id = _logsys_subsys_create ("IPC"); - if (ipc_subsys_id < 0) { - log_printf (LOGSYS_LEVEL_ERROR, - "Could not initialize IPC logging subsystem\n"); - corosync_exit_error (AIS_DONE_INIT_SERVICES); - } - - ipc_init_state_v2.log_subsys_id = ipc_subsys_id; - coroipcs_ipc_init_v2 (&ipc_init_state_v2); - /* * Start main processing loop */ diff --git a/exec/main.h b/exec/main.h index a9c90b4c..2efedef6 100644 --- a/exec/main.h +++ b/exec/main.h @@ -85,4 +85,42 @@ extern int cs_poll_dispatch_delete ( int fd); +extern int corosync_sending_allowed ( + unsigned int service, + unsigned int id, + const void *msg, + void *sending_allowed_private_data); + +extern void corosync_sending_allowed_release (void *sending_allowed_private_data); + +extern void corosync_recheck_the_q_level(void *data); + +extern void cs_ipcs_init(void); + +extern void cs_ipcs_service_init(struct corosync_service_engine *service); + +extern void cs_ipcs_stats_update(void); + +extern int32_t cs_ipcs_service_destroy(int32_t service_id); + +extern int32_t cs_ipcs_q_level_get(void); + +extern int cs_ipcs_dispatch_send(void *conn, const void *msg, size_t mlen); +extern int cs_ipcs_dispatch_iov_send (void *conn, + const struct iovec *iov, + unsigned int iov_len); + +extern int cs_ipcs_response_send(void *conn, const void *msg, size_t mlen); +extern int cs_ipcs_response_iov_send (void *conn, + const struct iovec *iov, + unsigned int iov_len); + +extern void cs_ipcs_sync_state_changed(int32_t sync_in_process); + +extern void *cs_ipcs_private_data_get(void *conn); + +extern void cs_ipc_refcnt_inc(void *conn); + +extern void cs_ipc_refcnt_dec(void *conn); + #endif /* MAIN_H_DEFINED */ diff --git a/exec/objdb.c b/exec/objdb.c index baadda3f..db56631e 100644 --- a/exec/objdb.c +++ b/exec/objdb.c @@ -39,6 +39,7 @@ #include #include +#include #include @@ -48,7 +49,7 @@ #include #include #include -#include +#include #include "main.h" diff --git a/exec/quorum.c b/exec/quorum.c index 3e159bbd..b81708c3 100644 --- a/exec/quorum.c +++ b/exec/quorum.c @@ -51,7 +51,6 @@ #include #include -#include #include #include #include diff --git a/exec/service.c b/exec/service.c index dc304061..908527cb 100644 --- a/exec/service.c +++ b/exec/service.c @@ -43,7 +43,6 @@ #include #include -#include #include "mainconfig.h" #include "util.h" #include @@ -55,7 +54,7 @@ #include #include "service.h" -#include +#include LOGSYS_DECLARE_SUBSYS ("SERV"); @@ -248,33 +247,35 @@ unsigned int corosync_service_link_and_init ( name_sufix = (char*)service_name; corosync_api->object_create (object_stats_services_handle, - &object_stats_handle, - name_sufix, strlen (name_sufix)); + &object_stats_handle, + name_sufix, strlen (name_sufix)); corosync_api->object_key_create_typed (object_stats_handle, - "service_id", - &service->id, sizeof (service->id), - OBJDB_VALUETYPE_INT16); + "service_id", + &service->id, sizeof (service->id), + OBJDB_VALUETYPE_INT16); for (fn = 0; fn < service->exec_engine_count; fn++) { snprintf (object_name, 32, "%d", fn); corosync_api->object_create (object_stats_handle, - &service_stats_handle[service->id][fn], - object_name, strlen (object_name)); + &service_stats_handle[service->id][fn], + object_name, strlen (object_name)); corosync_api->object_key_create_typed (service_stats_handle[service->id][fn], - "tx", - &zero_64, sizeof (zero_64), - OBJDB_VALUETYPE_UINT64); + "tx", + &zero_64, sizeof (zero_64), + OBJDB_VALUETYPE_UINT64); corosync_api->object_key_create_typed (service_stats_handle[service->id][fn], - "rx", - &zero_64, sizeof (zero_64), - OBJDB_VALUETYPE_UINT64); + "rx", + &zero_64, sizeof (zero_64), + OBJDB_VALUETYPE_UINT64); } - log_printf (LOGSYS_LEVEL_NOTICE, "Service engine loaded: %s\n", service->name); + log_printf (LOGSYS_LEVEL_NOTICE, + "Service engine loaded: %s [%d]\n", service->name, service->id); + cs_ipcs_service_init(service); return (res); } @@ -580,7 +581,7 @@ static int service_unlink_schedwrk_handler (const void *data) { /* * Exit all ipc connections dependent on this service */ - if (coroipcs_ipc_service_exit (cb_data->service_engine) == -1) + if (cs_ipcs_service_destroy (cb_data->service_engine) == -1) return -1; log_printf(LOGSYS_LEVEL_NOTICE, diff --git a/exec/sync.c b/exec/sync.c index 5f48e5b2..b9cc84a5 100644 --- a/exec/sync.c +++ b/exec/sync.c @@ -56,7 +56,7 @@ #include #include #include -#include +#include #include "quorum.h" #include "sync.h" @@ -145,7 +145,7 @@ static struct totempg_group sync_group = { static hdb_handle_t sync_group_handle; struct req_exec_sync_barrier_start { - coroipc_request_header_t header; + struct qb_ipc_request_header header; struct memb_ring_id ring_id; }; diff --git a/exec/syncv2.c b/exec/syncv2.c index 7b474240..efa37785 100644 --- a/exec/syncv2.c +++ b/exec/syncv2.c @@ -55,7 +55,7 @@ #include #include #include -#include +#include #include "schedwrk.h" #include "quorum.h" #include "sync.h" @@ -96,19 +96,19 @@ struct processor_entry { }; struct req_exec_memb_determine_message { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); struct memb_ring_id ring_id __attribute__((aligned(8))); }; struct req_exec_service_build_message { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); struct memb_ring_id ring_id __attribute__((aligned(8))); int service_list_entries __attribute__((aligned(8))); int service_list[128] __attribute__((aligned(8))); }; struct req_exec_barrier_message { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); struct memb_ring_id ring_id __attribute__((aligned(8))); }; @@ -383,7 +383,7 @@ static void sync_deliver_fn ( unsigned int msg_len, int endian_conversion_required) { - coroipc_request_header_t *header = (coroipc_request_header_t *)msg; + struct qb_ipc_request_header *header = (struct qb_ipc_request_header *)msg; switch (header->id) { case MESSAGE_REQ_SYNC_BARRIER: diff --git a/exec/timer.c b/exec/timer.c index bd83afc7..0f560b5a 100644 --- a/exec/timer.c +++ b/exec/timer.c @@ -59,7 +59,6 @@ #include #include -#include #include #include #include diff --git a/exec/totempg.c b/exec/totempg.c index 131813ef..36d5a448 100644 --- a/exec/totempg.c +++ b/exec/totempg.c @@ -164,6 +164,8 @@ static int totempg_reserved = 1; static unsigned int totempg_size_limit; +static totem_queue_level_changed_fn totem_queue_level_changed = NULL; + /* * Function and data used to log messages */ @@ -244,6 +246,7 @@ struct totempg_group_instance { struct totempg_group *groups; int groups_cnt; + int32_t q_level; }; DECLARE_HDB_DATABASE (totempg_groups_instance_database,NULL); @@ -1061,6 +1064,7 @@ int totempg_groups_initialize ( instance->confchg_fn = confchg_fn; instance->groups = 0; instance->groups_cnt = 0; + instance->q_level = QB_LOOP_MED; hdb_handle_put (&totempg_groups_instance_database, *handle); @@ -1178,6 +1182,42 @@ error_exit: return (res); } +static void check_q_level(struct totempg_group_instance *instance) +{ + int32_t old_level; + int32_t percent_used = 0; + + old_level = instance->q_level; + percent_used = 100 - (totemmrp_avail () * 100 / 800); /*(1024*1024/1500)*/ + + if (percent_used > 90 && instance->q_level != TOTEM_Q_LEVEL_CRITICAL) { + instance->q_level = TOTEM_Q_LEVEL_CRITICAL; + } else if (percent_used < 30 && instance->q_level != TOTEM_Q_LEVEL_LOW) { + instance->q_level = TOTEM_Q_LEVEL_LOW; + } else if (percent_used > 40 && percent_used < 60 && instance->q_level != TOTEM_Q_LEVEL_GOOD) { + instance->q_level = TOTEM_Q_LEVEL_GOOD; + } else if (percent_used > 70 && percent_used < 80 && instance->q_level != TOTEM_Q_LEVEL_HIGH) { + instance->q_level = TOTEM_Q_LEVEL_HIGH; + } + if (totem_queue_level_changed && old_level != instance->q_level) { + totem_queue_level_changed(instance->q_level); + } + +} + +void totempg_check_q_level(qb_handle_t handle) +{ + struct totempg_group_instance *instance; + + if (hdb_handle_get (&totempg_groups_instance_database, handle, + (void *)&instance) != 0) { + return; + } + check_q_level(instance); + + hdb_handle_put (&totempg_groups_instance_database, handle); +} + int totempg_groups_joined_reserve ( hdb_handle_t handle, const struct iovec *iovec, @@ -1203,6 +1243,8 @@ int totempg_groups_joined_reserve ( for (i = 0; i < iov_len; i++) { size += iovec[i].iov_len; } + check_q_level(instance); + if (size >= totempg_size_limit) { reserved = -1; goto error_put; @@ -1404,6 +1446,11 @@ extern void totempg_service_ready_register ( totemmrp_service_ready_register (totem_service_ready); } +void totempg_queue_level_register_callback (totem_queue_level_changed_fn fn) +{ + totem_queue_level_changed = fn; +} + extern int totempg_member_add ( const struct totem_ip_address *member, int ring_no); diff --git a/exec/totemudp.c b/exec/totemudp.c index a149bfa8..b3ae4bdf 100644 --- a/exec/totemudp.c +++ b/exec/totemudp.c @@ -59,9 +59,9 @@ #include #include +#include #include #include -#include #include #define LOGSYS_UTILS_ONLY 1 #include diff --git a/exec/tsafe.c b/exec/tsafe.c index b5b0f84d..1a71b8ae 100644 --- a/exec/tsafe.c +++ b/exec/tsafe.c @@ -978,19 +978,6 @@ void setutxent(void) } #endif -char *strerror(int errnum) -{ - static char *(*real_strerror)(int errnum) = NULL; - if (!tsafe_inited || tsafe_disabled) { - if (real_strerror == NULL) { - real_strerror = _get_real_func_ ("strerror"); - } - return real_strerror (errnum); - } - assert(0); - return NULL; -} - char *strsignal(int sig) { static char *(*real_strsignal)(int sig) = NULL; diff --git a/exec/util.c b/exec/util.c index 9f31dfb5..6c7b60bc 100644 --- a/exec/util.c +++ b/exec/util.c @@ -47,7 +47,6 @@ #include #include #include -#include #include "util.h" LOGSYS_DECLARE_SUBSYS ("MAIN"); diff --git a/exec/util.h b/exec/util.h index 9e149e5f..4228ae81 100644 --- a/exec/util.h +++ b/exec/util.h @@ -71,17 +71,17 @@ static inline cs_error_t hdb_error_to_cs (int res) \ if (res == 0) { \ return (CS_OK); \ } else { \ - if (errno == EBADF) { \ + if (res == -EBADF) { \ return (CS_ERR_BAD_HANDLE); \ } else \ - if (errno == ENOMEM) { \ + if (res == -ENOMEM) { \ return (CS_ERR_NO_MEMORY); \ } else \ - if (errno == EMFILE) { \ + if (res == -EMFILE) { \ return (CS_ERR_NO_RESOURCES); \ } else \ - if (errno == EACCES) { \ - return (CS_ERR_SECURITY); \ + if (res == -EACCES) { \ + return (CS_ERR_ACCESS); \ } \ return (CS_ERR_LIBRARY); \ } \ diff --git a/exec/vsf_quorum.c b/exec/vsf_quorum.c index 4db696cb..ede7786d 100644 --- a/exec/vsf_quorum.c +++ b/exec/vsf_quorum.c @@ -55,7 +55,7 @@ #include #include -#include +#include #include #include #include @@ -440,7 +440,7 @@ static void message_handler_req_lib_quorum_trackstart (void *conn, const void *msg) { const struct req_lib_quorum_trackstart *req_lib_quorum_trackstart = msg; - coroipc_response_header_t res; + struct qb_ipc_response_header res; struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn); log_printf(LOGSYS_LEVEL_DEBUG, "got trackstart request on %p\n", conn); @@ -471,12 +471,12 @@ static void message_handler_req_lib_quorum_trackstart (void *conn, res.size = sizeof(res); res.id = MESSAGE_RES_QUORUM_TRACKSTART; res.error = CS_OK; - corosync_api->ipc_response_send(conn, &res, sizeof(coroipc_response_header_t)); + corosync_api->ipc_response_send(conn, &res, sizeof(struct qb_ipc_response_header)); } static void message_handler_req_lib_quorum_trackstop (void *conn, const void *msg) { - coroipc_response_header_t res; + struct qb_ipc_response_header res; struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn); log_printf(LOGSYS_LEVEL_DEBUG, "got trackstop request on %p\n", conn); @@ -494,5 +494,5 @@ static void message_handler_req_lib_quorum_trackstop (void *conn, const void *ms res.size = sizeof(res); res.id = MESSAGE_RES_QUORUM_TRACKSTOP; res.error = CS_OK; - corosync_api->ipc_response_send(conn, &res, sizeof(coroipc_response_header_t)); + corosync_api->ipc_response_send(conn, &res, sizeof(struct qb_ipc_response_header)); } diff --git a/exec/vsf_ykd.c b/exec/vsf_ykd.c index db63e804..ccc26c63 100644 --- a/exec/vsf_ykd.c +++ b/exec/vsf_ykd.c @@ -58,7 +58,7 @@ #include #include -#include +#include #include #include #include diff --git a/include/Makefile.am b/include/Makefile.am index 732c3da9..2c934d98 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -32,11 +32,11 @@ MAINTAINERCLEANFILES = Makefile.in corosync/config.h.in CS_H = hdb.h cs_config.h cpg.h cfg.h evs.h mar_gen.h swab.h \ - coroipcc.h coroipcs.h coroipc_types.h corodefs.h \ + corodefs.h \ confdb.h list.h corotypes.h quorum.h votequorum.h sam.h CS_INTERNAL_H = ipc_cfg.h ipc_confdb.h ipc_cpg.h ipc_evs.h ipc_pload.h ipc_quorum.h \ - jhash.h pload.h cs_queue.h quorum.h sq.h ipc_votequorum.h coroipc_ipc.h + jhash.h pload.h cs_queue.h quorum.h sq.h ipc_votequorum.h LCR_H = lcr_ckpt.h lcr_comp.h lcr_ifact.h diff --git a/include/corosync/corodefs.h b/include/corosync/corodefs.h index a1e65391..7d036444 100644 --- a/include/corosync/corodefs.h +++ b/include/corosync/corodefs.h @@ -37,8 +37,6 @@ #include -#define COROSYNC_SOCKET_NAME "corosync.ipc" - enum corosync_service_types { EVS_SERVICE = 0, CLM_SERVICE = 1, diff --git a/include/corosync/coroipc_ipc.h b/include/corosync/coroipc_ipc.h deleted file mode 100644 index f04134de..00000000 --- a/include/corosync/coroipc_ipc.h +++ /dev/null @@ -1,384 +0,0 @@ -/* - * Copyright (c) 2009 Red Hat, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * 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 COROIPC_IPC_H_DEFINED -#define COROIPC_IPC_H_DEFINED - -#include -#include -#include -#include "corotypes.h" -#include "config.h" - -/* - * Darwin claims to support process shared synchronization - * but it really does not. The unistd.h header file is wrong. - */ -#if defined(COROSYNC_DARWIN) || defined(__UCLIBC__) -#undef _POSIX_THREAD_PROCESS_SHARED -#define _POSIX_THREAD_PROCESS_SHARED -1 -#endif - -#ifndef _POSIX_THREAD_PROCESS_SHARED -#define _POSIX_THREAD_PROCESS_SHARED -1 -#endif - -#if _POSIX_THREAD_PROCESS_SHARED > 0 -#include -#else -#include - -#if defined(_SEM_SEMUN_UNDEFINED) -union semun { - int val; - struct semid_ds *buf; - unsigned short int *array; - struct seminfo *__buf; -}; -#endif -#endif - -/* - * Define sem_wait timeout (real timeout will be (n-1;n) ) - */ -#define IPC_SEMWAIT_TIMEOUT 2 - -#define IPC_SEMWAIT_NOFILE 0 - -enum req_init_types { - MESSAGE_REQ_RESPONSE_INIT = 0, - MESSAGE_REQ_DISPATCH_INIT = 1 -}; - -#define MESSAGE_REQ_CHANGE_EUID 1 - -enum ipc_semaphore_identifiers { - SEMAPHORE_REQUEST_OR_FLUSH_OR_EXIT = 0, - SEMAPHORE_REQUEST = 1, - SEMAPHORE_RESPONSE = 2, - SEMAPHORE_DISPATCH = 3 -}; - -struct control_buffer { - unsigned int read; - unsigned int write; - int flow_control_enabled; -#if _POSIX_THREAD_PROCESS_SHARED > 0 - sem_t sem_request_or_flush_or_exit; - sem_t sem_response; - sem_t sem_dispatch; - sem_t sem_request; -#else - int semid; -#endif - int ipc_closed; -}; - -enum res_init_types { - MESSAGE_RES_INIT -}; - -typedef struct { - int service __attribute__((aligned(8))); - unsigned long long semkey __attribute__((aligned(8))); - char control_file[PATH_MAX] __attribute__((aligned(8))); - char request_file[PATH_MAX] __attribute__((aligned(8))); - char response_file[PATH_MAX] __attribute__((aligned(8))); - char dispatch_file[PATH_MAX] __attribute__((aligned(8))); - size_t control_size __attribute__((aligned(8))); - size_t request_size __attribute__((aligned(8))); - size_t response_size __attribute__((aligned(8))); - size_t dispatch_size __attribute__((aligned(8))); -} mar_req_setup_t __attribute__((aligned(8))); - -typedef struct { - int error __attribute__((aligned(8))); -} mar_res_setup_t __attribute__((aligned(8))); - -typedef struct { - uid_t euid __attribute__((aligned(8))); - gid_t egid __attribute__((aligned(8))); -} mar_req_priv_change __attribute__((aligned(8))); - -typedef struct { - coroipc_response_header_t header __attribute__((aligned(8))); - uint64_t conn_info __attribute__((aligned(8))); -} mar_res_lib_response_init_t __attribute__((aligned(8))); - -typedef struct { - coroipc_response_header_t header __attribute__((aligned(8))); -} mar_res_lib_dispatch_init_t __attribute__((aligned(8))); - -typedef struct { - uint32_t nodeid __attribute__((aligned(8))); - void *conn __attribute__((aligned(8))); -} mar_message_source_t __attribute__((aligned(8))); - -typedef struct { - coroipc_request_header_t header __attribute__((aligned(8))); - size_t map_size __attribute__((aligned(8))); - char path_to_file[128] __attribute__((aligned(8))); -} mar_req_coroipcc_zc_alloc_t __attribute__((aligned(8))); - -typedef struct { - coroipc_request_header_t header __attribute__((aligned(8))); - size_t map_size __attribute__((aligned(8))); - uint64_t server_address __attribute__((aligned(8))); -} mar_req_coroipcc_zc_free_t __attribute__((aligned(8))); - -typedef struct { - coroipc_request_header_t header __attribute__((aligned(8))); - uint64_t server_address __attribute__((aligned(8))); -} mar_req_coroipcc_zc_execute_t __attribute__((aligned(8))); - -struct coroipcs_zc_header { - int map_size; - uint64_t server_address; -}; - -#define SOCKET_SERVICE_INIT 0xFFFFFFFF -#define SOCKET_SERVICE_SECURITY_VIOLATION 0xFFFFFFFE - -#define ZC_ALLOC_HEADER 0xFFFFFFFF -#define ZC_FREE_HEADER 0xFFFFFFFE -#define ZC_EXECUTE_HEADER 0xFFFFFFFD - -static inline cs_error_t -ipc_sem_wait ( - struct control_buffer *control_buffer, - enum ipc_semaphore_identifiers sem_id, - int fd) -{ -#if _POSIX_THREAD_PROCESS_SHARED < 1 - struct sembuf sop; -#else - struct timespec timeout; - struct pollfd pfd; - sem_t *sem = NULL; -#endif - int res; - -#if _POSIX_THREAD_PROCESS_SHARED > 0 - switch (sem_id) { - case SEMAPHORE_REQUEST_OR_FLUSH_OR_EXIT: - sem = &control_buffer->sem_request_or_flush_or_exit; - break; - case SEMAPHORE_RESPONSE: - sem = &control_buffer->sem_request; - break; - case SEMAPHORE_DISPATCH: - sem = &control_buffer->sem_response; - break; - case SEMAPHORE_REQUEST: - sem = &control_buffer->sem_dispatch; - break; - } - - if (fd == IPC_SEMWAIT_NOFILE) { -retry_sem_wait: - res = sem_wait (sem); - if (res == -1 && errno == EINTR) { - goto retry_sem_wait; - } else - if (res == -1) { - return (CS_ERR_LIBRARY); - } - } else { - if (control_buffer->ipc_closed) { - return (CS_ERR_LIBRARY); - } - - timeout.tv_sec = time(NULL) + IPC_SEMWAIT_TIMEOUT; - timeout.tv_nsec = 0; - -retry_sem_timedwait: - res = sem_timedwait (sem, &timeout); - if (res == -1 && errno == ETIMEDOUT) { - pfd.fd = fd; - pfd.events = 0; - - /* - * Determine if server has failed (ERR_LIBRARY) or - * is just performing slowly or in configuration change - * (retry sem op) - */ - -retry_poll: - res = poll (&pfd, 1, 0); - if (res == -1 && errno == EINTR) { - goto retry_poll; - } else - if (res == -1) { - return (CS_ERR_LIBRARY); - } - - if (res == 1) { - if (pfd.revents == POLLERR || - pfd.revents == POLLHUP || - pfd.revents == POLLNVAL) { - - return (CS_ERR_LIBRARY); - } - } - goto retry_sem_timedwait; - } else - if (res == -1 && errno == EINTR) { - goto retry_sem_timedwait; - } else - if (res == -1) { - return (CS_ERR_LIBRARY); - } - - if (res == 0 && control_buffer->ipc_closed) { - return (CS_ERR_LIBRARY); - } - } -#else - sop.sem_num = sem_id; - sop.sem_op = -1; - sop.sem_flg = 0; - -retry_semop: - res = semop (control_buffer->semid, &sop, 1); - if (res == -1 && errno == EINTR) { - return (CS_ERR_TRY_AGAIN); - goto retry_semop; - } else - if (res == -1 && errno == EACCES) { - return (CS_ERR_TRY_AGAIN); - } else - if (res == -1) { - return (CS_ERR_LIBRARY); - } -#endif - return (CS_OK); -} - -static inline cs_error_t -ipc_sem_post ( - struct control_buffer *control_buffer, - enum ipc_semaphore_identifiers sem_id) -{ -#if _POSIX_THREAD_PROCESS_SHARED < 1 - struct sembuf sop; -#else - sem_t *sem = NULL; -#endif - int res; - -#if _POSIX_THREAD_PROCESS_SHARED > 0 - switch (sem_id) { - case SEMAPHORE_REQUEST_OR_FLUSH_OR_EXIT: - sem = &control_buffer->sem_request_or_flush_or_exit; - break; - case SEMAPHORE_RESPONSE: - sem = &control_buffer->sem_request; - break; - case SEMAPHORE_DISPATCH: - sem = &control_buffer->sem_response; - break; - case SEMAPHORE_REQUEST: - sem = &control_buffer->sem_dispatch; - break; - } - - res = sem_post (sem); - if (res == -1) { - return (CS_ERR_LIBRARY); - } -#else - sop.sem_num = sem_id; - sop.sem_op = 1; - sop.sem_flg = 0; - -retry_semop: - res = semop (control_buffer->semid, &sop, 1); - if (res == -1 && errno == EINTR) { - goto retry_semop; - } else - if (res == -1) { - return (CS_ERR_LIBRARY); - } -#endif - return (CS_OK); -} - -static inline cs_error_t -ipc_sem_getvalue ( - struct control_buffer *control_buffer, - enum ipc_semaphore_identifiers sem_id, - int *sem_value) -{ -#if _POSIX_THREAD_PROCESS_SHARED < 1 - int sem_value_hold; - union semun semun; -#else - sem_t *sem = NULL; - int res; -#endif - -#if _POSIX_THREAD_PROCESS_SHARED > 0 - switch (sem_id) { - case SEMAPHORE_REQUEST_OR_FLUSH_OR_EXIT: - sem = &control_buffer->sem_request_or_flush_or_exit; - break; - case SEMAPHORE_RESPONSE: - sem = &control_buffer->sem_request; - break; - case SEMAPHORE_DISPATCH: - sem = &control_buffer->sem_response; - break; - case SEMAPHORE_REQUEST: - sem = &control_buffer->sem_dispatch; - break; - } - - res = sem_getvalue (sem, sem_value); - if (res == -1) { - return (CS_ERR_LIBRARY); - } -#else -retry_semctl: - sem_value_hold = semctl (control_buffer->semid, sem_id, GETVAL, semun); - if (sem_value_hold == -1 && errno == EINTR) { - goto retry_semctl; - } else - if (sem_value_hold == -1) { - return (CS_ERR_LIBRARY); - } - *sem_value = sem_value_hold; -#endif - return (CS_OK); -} - -#endif /* COROIPC_IPC_H_DEFINED */ diff --git a/include/corosync/coroipc_types.h b/include/corosync/coroipc_types.h deleted file mode 100644 index b589fee2..00000000 --- a/include/corosync/coroipc_types.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2009 Red Hat, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * 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 COROIPC_TYPES_H_DEFINED -#define COROIPC_TYPES_H_DEFINED - -typedef struct { - int size __attribute__((aligned(8))); - int id __attribute__((aligned(8))); -} coroipc_request_header_t __attribute__((aligned(8))); - -typedef struct { - int size __attribute__((aligned(8))); - int id __attribute__((aligned(8))); - cs_error_t error __attribute__((aligned(8))); -} coroipc_response_header_t __attribute__((aligned(8))); - -#endif /* COROIPC_TYPES_H_DEFINED */ diff --git a/include/corosync/coroipcc.h b/include/corosync/coroipcc.h deleted file mode 100644 index bc912ca1..00000000 --- a/include/corosync/coroipcc.h +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2002-2003 MontaVista Software, Inc. - * Copyright (c) 2006-2007, 2009 Red Hat, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * 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 COROIPCC_H_DEFINED -#define COROIPCC_H_DEFINED - -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -extern cs_error_t -coroipcc_service_connect ( - const char *socket_name, - unsigned int service, - size_t request_size, - size_t respnse__size, - size_t dispatch_size, - hdb_handle_t *handle); - -extern cs_error_t -coroipcc_service_disconnect ( - hdb_handle_t handle); - -extern cs_error_t -coroipcc_fd_get ( - hdb_handle_t handle, - int *fd); - -extern cs_error_t -coroipcc_dispatch_get ( - hdb_handle_t handle, - void **buf, - int timeout); - -extern cs_error_t -coroipcc_dispatch_put ( - hdb_handle_t handle); - -extern cs_error_t -coroipcc_dispatch_flow_control_get ( - hdb_handle_t handle, - unsigned int *flow_control_state); - -extern cs_error_t -coroipcc_msg_send_reply_receive ( - hdb_handle_t handle, - const struct iovec *iov, - unsigned int iov_len, - void *res_msg, - size_t res_len); - -extern cs_error_t -coroipcc_msg_send_reply_receive_in_buf_get ( - hdb_handle_t handle, - const struct iovec *iov, - unsigned int iov_len, - void **res_msg); - -extern cs_error_t -coroipcc_msg_send_reply_receive_in_buf_put ( - hdb_handle_t handle); - -extern cs_error_t -coroipcc_zcb_alloc ( - hdb_handle_t handle, - void **buffer, - size_t size, - size_t header_size); - -extern cs_error_t -coroipcc_zcb_free ( - hdb_handle_t handle, - void *buffer); - -extern cs_error_t -coroipcc_zcb_msg_send_reply_receive ( - hdb_handle_t handle, - void *msg, - void *res_msg, - size_t res_len); - -#ifdef __cplusplus -} -#endif - -#endif /* COROIPCC_H_DEFINED */ diff --git a/include/corosync/coroipcs.h b/include/corosync/coroipcs.h deleted file mode 100644 index 57645af6..00000000 --- a/include/corosync/coroipcs.h +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2006-2009 Red Hat, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * 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 COROIPCS_H_DEFINED -#define COROIPCS_H_DEFINED - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct iovec; - -typedef int (*coroipcs_init_fn_lvalue) (void *conn); -typedef int (*coroipcs_exit_fn_lvalue) (void *conn); -typedef void (*coroipcs_handler_fn_lvalue) (void *conn, const void *msg); - -struct coroipcs_init_state { - const char *socket_name; - int sched_policy; - const struct sched_param *sched_param; - void *(*malloc) (size_t size); - void (*free) (void *ptr); - void (*log_printf) ( - const char *format, - ...) __attribute__((format(printf, 1, 2))); - int (*service_available)(unsigned int service); - int (*private_data_size_get)(unsigned int service); - int (*security_valid)(int uid, int gid); - void (*serialize_lock)(void); - void (*serialize_unlock)(void); - int (*sending_allowed)(unsigned int service, unsigned int id, - const void *msg, void *sending_allowed_private_data); - void (*sending_allowed_release)(void *sending_allowed_private_data); - void (*poll_accept_add)(int fd); - void (*poll_dispatch_add)(int fd, void *context); - void (*poll_dispatch_modify)(int fd, int events, void *context); - void (*poll_dispatch_destroy)(int fd, void *context); - void (*fatal_error)(const char *error_msg) __attribute__ ((noreturn)); - coroipcs_init_fn_lvalue (*init_fn_get)(unsigned int service); - coroipcs_exit_fn_lvalue (*exit_fn_get)(unsigned int service); - coroipcs_handler_fn_lvalue (*handler_fn_get)(unsigned int service, unsigned int id); -}; - -struct coroipcs_init_state_v2 { - const char *socket_name; - int sched_policy; - const struct sched_param *sched_param; - void *(*malloc) (size_t size); - void (*free) (void *ptr); - void (*old_log_printf) ( - const char *format, - ...) __attribute__((format(printf, 1, 2))); - int (*service_available)(unsigned int service); - int (*private_data_size_get)(unsigned int service); - int (*security_valid)(int uid, int gid); - void (*serialize_lock)(void); - void (*serialize_unlock)(void); - int (*sending_allowed)(unsigned int service, unsigned int id, - const void *msg, void *sending_allowed_private_data); - void (*sending_allowed_release)(void *sending_allowed_private_data); - void (*poll_accept_add)(int fd); - void (*poll_dispatch_add)(int fd, void *context); - void (*poll_dispatch_modify)(int fd, int events, void *context); - void (*poll_dispatch_destroy)(int fd, void *context); - void (*fatal_error)(const char *error_msg) __attribute__ ((noreturn)); - coroipcs_init_fn_lvalue (*init_fn_get)(unsigned int service); - coroipcs_exit_fn_lvalue (*exit_fn_get)(unsigned int service); - coroipcs_handler_fn_lvalue (*handler_fn_get)(unsigned int service, unsigned int id); - /* v2 functions */ - hdb_handle_t (*stats_create_connection) (const char* name, - pid_t pid, int fd); - void (*stats_destroy_connection) (hdb_handle_t handle); - void (*stats_update_value) (hdb_handle_t handle, - const char *name, const void *value, size_t value_len); - void (*stats_increment_value) (hdb_handle_t handle, const char* name); - void (*log_printf) ( - unsigned int rec_ident, - const char *function_name, - const char *file_name, - int file_line, - const char *format, - ...) __attribute__((format(printf, 5, 6))); - int log_subsys_id; - void (*stats_decrement_value) (hdb_handle_t handle, const char* name); -}; - -extern void coroipcs_ipc_init ( - struct coroipcs_init_state *init_state); - -extern void coroipcs_ipc_init_v2 ( - struct coroipcs_init_state_v2 *init_state_v2); - -extern void *coroipcs_private_data_get (void *conn); - -extern int coroipcs_response_send ( - void *conn, - const void *msg, - size_t mlen); - -extern int coroipcs_response_iov_send ( - void *conn, - const struct iovec *iov, - unsigned int iov_len); - -extern int coroipcs_dispatch_send ( - void *conn, - const void *msg, - size_t mlen); - -extern int coroipcs_dispatch_iov_send ( - void *conn, - const struct iovec *iov, - unsigned int iov_len); - -extern void coroipcs_refcount_inc (void *conn); - -extern void coroipcs_refcount_dec (void *conn); - -extern void coroipcs_ipc_exit (void); - -extern int coroipcs_ipc_service_exit (unsigned int service); - -extern int coroipcs_handler_accept ( - int fd, - int revent, - void *context); - -extern int coroipcs_handler_dispatch ( - int fd, - int revent, - void *context); - -#ifdef __cplusplus -} -#endif - -#endif /* COROIPCS_H_DEFINED */ diff --git a/include/corosync/corotypes.h b/include/corosync/corotypes.h index dcb83258..9f6259be 100644 --- a/include/corosync/corotypes.h +++ b/include/corosync/corotypes.h @@ -40,6 +40,7 @@ #else #include #endif +#include #include #include @@ -132,6 +133,82 @@ static inline uint64_t cs_timestamp_get(void) return result; } +static inline cs_error_t qb_to_cs_error (int result) +{ + int32_t res; + cs_error_t err = CS_ERR_LIBRARY; + + if (result >= 0) { + return CS_OK; + } + res = -result; + + switch (res) { + case EBADF: + err = CS_ERR_BAD_HANDLE; + break; + case ENOMEM: + err = CS_ERR_NO_MEMORY; + break; + case EAGAIN: + err = CS_ERR_TRY_AGAIN; + break; + case EBADE: + err = CS_ERR_FAILED_OPERATION; + break; + case ETIME: + case ETIMEDOUT: + err = CS_ERR_TIMEOUT; + break; + case EINVAL: + err = CS_ERR_INVALID_PARAM; + break; + case EBUSY: + err = CS_ERR_BUSY; + break; + case EACCES: + err = CS_ERR_ACCESS; + break; + case EOVERFLOW: + err = CS_ERR_NAME_TOO_LONG; + break; + case EEXIST: + err = CS_ERR_EXIST; + break; + case ENOBUFS: + err = CS_ERR_QUEUE_FULL; + break; + case ENOSPC: + err = CS_ERR_NO_SPACE; + break; + case EINTR: + err = CS_ERR_INTERRUPT; + break; + case ENOENT: + case ENODEV: + err = CS_ERR_NOT_EXIST; + break; + case ENOSYS: + case ENOTSUP: + err = CS_ERR_NOT_SUPPORTED; + break; + case EBADMSG: + err = CS_ERR_MESSAGE_ERROR; + break; + case EMSGSIZE: + case E2BIG: + err = CS_ERR_TOO_BIG; + break; + case ECONNREFUSED: + case ENOTCONN: + default: + err = CS_ERR_LIBRARY; + break; + } + + return err; +} + /* * DEPRECATED diff --git a/include/corosync/ipc_cfg.h b/include/corosync/ipc_cfg.h index eca0c3db..43859cc7 100644 --- a/include/corosync/ipc_cfg.h +++ b/include/corosync/ipc_cfg.h @@ -75,145 +75,145 @@ enum res_lib_cfg_types { }; struct req_lib_cfg_statetrack { - coroipc_request_header_t header; + struct qb_ipc_request_header header; uint8_t track_flags; corosync_cfg_state_notification_t *notification_buffer_address; }; struct res_lib_cfg_statetrack { - coroipc_response_header_t header; + struct qb_ipc_response_header header; }; struct req_lib_cfg_statetrackstop { - coroipc_request_header_t header; + struct qb_ipc_request_header header; }; struct res_lib_cfg_statetrackstop { - coroipc_response_header_t header; + struct qb_ipc_response_header header; }; struct req_lib_cfg_administrativestateset { - coroipc_request_header_t header; + struct qb_ipc_request_header header; cs_name_t comp_name; corosync_cfg_administrative_target_t administrative_target; corosync_cfg_administrative_state_t administrative_state; }; struct res_lib_cfg_administrativestateset { - coroipc_response_header_t header; + struct qb_ipc_response_header header; }; struct req_lib_cfg_administrativestateget { - coroipc_request_header_t header; + struct qb_ipc_request_header header; cs_name_t comp_name; corosync_cfg_administrative_target_t administrative_target; corosync_cfg_administrative_state_t administrative_state; }; struct res_lib_cfg_administrativestateget { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; struct req_lib_cfg_ringstatusget { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); }; struct res_lib_cfg_ringstatusget { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint32_t interface_count __attribute__((aligned(8))); char interface_name[16][128] __attribute__((aligned(8))); char interface_status[16][512] __attribute__((aligned(8))); }; struct req_lib_cfg_ringreenable { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); }; struct res_lib_cfg_ringreenable { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; struct req_lib_cfg_serviceload { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); char service_name[256] __attribute__((aligned(8))); unsigned int service_ver; }; struct res_lib_cfg_serviceload { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; struct req_lib_cfg_serviceunload { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); char service_name[256] __attribute__((aligned(8))); unsigned int service_ver; }; struct res_lib_cfg_serviceunload { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; struct req_lib_cfg_killnode { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); unsigned int nodeid __attribute__((aligned(8))); cs_name_t reason __attribute__((aligned(8))); }; struct res_lib_cfg_killnode { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; struct req_lib_cfg_tryshutdown { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); unsigned int flags; }; struct res_lib_cfg_tryshutdown { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; struct req_lib_cfg_replytoshutdown { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); unsigned int response; }; struct res_lib_cfg_replytoshutdown { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; struct res_lib_cfg_testshutdown { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); unsigned int flags; }; struct req_lib_cfg_get_node_addrs { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); unsigned int nodeid; }; struct res_lib_cfg_get_node_addrs { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); unsigned int family; unsigned int num_addrs; char addrs[TOTEMIP_ADDRLEN][0]; }; struct req_lib_cfg_local_get { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); }; struct res_lib_cfg_local_get { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint32_t local_nodeid __attribute__((aligned(8))); }; struct req_lib_cfg_crypto_set { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint32_t type __attribute__((aligned(8))); }; struct res_lib_cfg_crypto_set { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; typedef enum { diff --git a/include/corosync/ipc_confdb.h b/include/corosync/ipc_confdb.h index 856c8a67..760ad374 100644 --- a/include/corosync/ipc_confdb.h +++ b/include/corosync/ipc_confdb.h @@ -91,50 +91,50 @@ enum res_confdb_types { struct req_lib_confdb_object_create { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint64_t parent_object_handle __attribute__((aligned(8))); mar_name_t object_name __attribute__((aligned(8))); }; struct res_lib_confdb_object_create { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint64_t object_handle __attribute__((aligned(8))); }; struct req_lib_confdb_object_destroy { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint64_t object_handle __attribute__((aligned(8))); }; struct req_lib_confdb_object_parent_get { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint64_t object_handle __attribute__((aligned(8))); }; struct res_lib_confdb_object_parent_get { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint64_t parent_object_handle __attribute__((aligned(8))); }; struct req_lib_confdb_object_name_get { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint64_t object_handle __attribute__((aligned(8))); }; struct res_lib_confdb_object_name_get { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_name_t object_name __attribute__((aligned(8))); }; struct req_lib_confdb_key_create { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint64_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_create_typed { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint64_t object_handle __attribute__((aligned(8))); mar_name_t key_name __attribute__((aligned(8))); mar_name_t value __attribute__((aligned(8))); @@ -142,14 +142,14 @@ struct req_lib_confdb_key_create_typed { }; struct req_lib_confdb_key_delete { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint64_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_replace { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint64_t object_handle __attribute__((aligned(8))); mar_name_t key_name __attribute__((aligned(8))); mar_name_t old_value __attribute__((aligned(8))); @@ -157,92 +157,92 @@ struct req_lib_confdb_key_replace { }; struct req_lib_confdb_object_find { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint64_t parent_object_handle __attribute__((aligned(8))); mar_name_t object_name __attribute__((aligned(8))); mar_uint64_t find_handle __attribute__((aligned(8))); }; struct res_lib_confdb_object_find { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint64_t object_handle __attribute__((aligned(8))); mar_uint64_t find_handle __attribute__((aligned(8))); }; struct req_lib_confdb_object_iter { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint64_t parent_object_handle __attribute__((aligned(8))); mar_uint64_t find_handle __attribute__((aligned(8))); }; struct res_lib_confdb_object_iter { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_name_t object_name __attribute__((aligned(8))); mar_uint64_t object_handle __attribute__((aligned(8))); mar_uint64_t find_handle __attribute__((aligned(8))); }; struct req_lib_confdb_key_iter { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint64_t parent_object_handle __attribute__((aligned(8))); mar_uint64_t next_entry __attribute__((aligned(8))); }; struct res_lib_confdb_key_iter { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_name_t key_name __attribute__((aligned(8))); mar_name_t value __attribute__((aligned(8))); }; struct res_lib_confdb_key_iter_typed { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_name_t key_name __attribute__((aligned(8))); mar_name_t value __attribute__((aligned(8))); mar_int32_t type __attribute__((aligned(8))); }; struct req_lib_confdb_key_get { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint64_t parent_object_handle __attribute__((aligned(8))); mar_name_t key_name __attribute__((aligned(8))); }; struct req_lib_confdb_object_find_destroy { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint64_t find_handle __attribute__((aligned(8))); }; struct res_lib_confdb_key_get { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_name_t value __attribute__((aligned(8))); }; struct res_lib_confdb_key_get_typed { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_name_t value __attribute__((aligned(8))); mar_int32_t type __attribute__((aligned(8))); }; struct res_lib_confdb_key_incdec { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint32_t value __attribute__((aligned(8))); }; struct res_lib_confdb_write { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_name_t error __attribute__((aligned(8))); }; struct req_lib_confdb_reload { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_int32_t flush __attribute__((aligned(8))); }; struct res_lib_confdb_reload { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_name_t error __attribute__((aligned(8))); }; struct res_lib_confdb_key_change_callback { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint64_t change_type __attribute__((aligned(8))); mar_uint64_t parent_object_handle __attribute__((aligned(8))); mar_uint64_t object_handle __attribute__((aligned(8))); @@ -252,25 +252,25 @@ struct res_lib_confdb_key_change_callback { }; struct res_lib_confdb_object_create_callback { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint64_t parent_object_handle __attribute__((aligned(8))); mar_uint64_t object_handle __attribute__((aligned(8))); mar_name_t name __attribute__((aligned(8))); }; struct res_lib_confdb_object_destroy_callback { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint64_t parent_object_handle __attribute__((aligned(8))); mar_name_t name __attribute__((aligned(8))); }; struct res_lib_confdb_reload_callback { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint32_t type __attribute__((aligned(8))); }; struct req_lib_confdb_object_track_start { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint64_t object_handle __attribute__((aligned(8))); mar_uint32_t flags __attribute__((aligned(8))); }; diff --git a/include/corosync/ipc_cpg.h b/include/corosync/ipc_cpg.h index 664f8147..5e8095ef 100644 --- a/include/corosync/ipc_cpg.h +++ b/include/corosync/ipc_cpg.h @@ -36,6 +36,7 @@ #define IPC_CPG_H_DEFINED #include +#include #include #include @@ -48,7 +49,10 @@ enum req_cpg_types { MESSAGE_REQ_CPG_ITERATIONINITIALIZE = 5, MESSAGE_REQ_CPG_ITERATIONNEXT = 6, MESSAGE_REQ_CPG_ITERATIONFINALIZE = 7, - MESSAGE_REQ_CPG_FINALIZE = 8 + MESSAGE_REQ_CPG_FINALIZE = 8, + MESSAGE_REQ_CPG_ZC_ALLOC = 9, + MESSAGE_REQ_CPG_ZC_FREE = 10, + MESSAGE_REQ_CPG_ZC_EXECUTE = 11, }; enum res_cpg_types { @@ -66,6 +70,9 @@ enum res_cpg_types { MESSAGE_RES_CPG_ITERATIONFINALIZE = 11, MESSAGE_RES_CPG_FINALIZE = 12, MESSAGE_RES_CPG_TOTEM_CONFCHG_CALLBACK = 13, + MESSAGE_RES_CPG_ZC_ALLOC = 14, + MESSAGE_RES_CPG_ZC_FREE = 15, + MESSAGE_RES_CPG_ZC_EXECUTE = 16, }; enum lib_cpg_confchg_reason { @@ -164,69 +171,69 @@ static inline void marshall_from_mar_cpg_ring_id_t ( } struct req_lib_cpg_join { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_cpg_name_t group_name __attribute__((aligned(8))); mar_uint32_t pid __attribute__((aligned(8))); mar_uint32_t flags __attribute__((aligned(8))); }; struct res_lib_cpg_join { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; struct req_lib_cpg_finalize { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); }; struct res_lib_cpg_finalize { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; struct req_lib_cpg_trackstart { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_cpg_name_t group_name __attribute__((aligned(8))); mar_uint32_t pid __attribute__((aligned(8))); }; struct res_lib_cpg_trackstart { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; struct req_lib_cpg_trackstop { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_cpg_name_t group_name __attribute__((aligned(8))); mar_uint32_t pid __attribute__((aligned(8))); }; struct res_lib_cpg_trackstop { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; struct req_lib_cpg_local_get { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); }; struct res_lib_cpg_local_get { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint32_t local_nodeid __attribute__((aligned(8))); }; struct req_lib_cpg_mcast { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint32_t guarantee __attribute__((aligned(8))); mar_uint32_t msglen __attribute__((aligned(8))); mar_uint8_t message[] __attribute__((aligned(8))); }; struct res_lib_cpg_mcast { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; /** * Message from another node */ struct res_lib_cpg_deliver_callback { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_cpg_name_t group_name __attribute__((aligned(8))); mar_uint32_t msglen __attribute__((aligned(8))); mar_uint32_t nodeid __attribute__((aligned(8))); @@ -235,23 +242,23 @@ struct res_lib_cpg_deliver_callback { }; struct res_lib_cpg_flowcontrol_callback { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint32_t flow_control_state __attribute__((aligned(8))); }; struct req_lib_cpg_membership_get { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_cpg_name_t group_name __attribute__((aligned(8))); }; struct res_lib_cpg_membership_get { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint32_t member_count __attribute__((aligned(8))); mar_cpg_address_t member_list[PROCESSOR_COUNT_MAX]; }; struct res_lib_cpg_confchg_callback { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_cpg_name_t group_name __attribute__((aligned(8))); mar_uint32_t member_list_entries __attribute__((aligned(8))); mar_uint32_t joined_list_entries __attribute__((aligned(8))); @@ -262,50 +269,71 @@ struct res_lib_cpg_confchg_callback { }; struct res_lib_cpg_totem_confchg_callback { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_cpg_ring_id_t ring_id __attribute__((aligned(8))); mar_uint32_t member_list_entries __attribute__((aligned(8))); mar_uint32_t member_list[]; }; struct req_lib_cpg_leave { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_cpg_name_t group_name __attribute__((aligned(8))); mar_uint32_t pid __attribute__((aligned(8))); }; struct res_lib_cpg_leave { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; struct req_lib_cpg_iterationinitialize { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_cpg_name_t group_name __attribute__((aligned(8))); mar_uint32_t iteration_type __attribute__((aligned(8))); }; struct res_lib_cpg_iterationinitialize { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); hdb_handle_t iteration_handle __attribute__((aligned(8))); }; struct req_lib_cpg_iterationnext { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); hdb_handle_t iteration_handle __attribute__((aligned(8))); }; struct res_lib_cpg_iterationnext { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_cpg_iteration_description_t description __attribute__((aligned(8))); }; struct req_lib_cpg_iterationfinalize { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); hdb_handle_t iteration_handle __attribute__((aligned(8))); }; struct res_lib_cpg_iterationfinalize { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; +typedef struct { + struct qb_ipc_request_header header __attribute__((aligned(8))); + size_t map_size __attribute__((aligned(8))); + char path_to_file[128] __attribute__((aligned(8))); +} mar_req_coroipcc_zc_alloc_t __attribute__((aligned(8))); + +typedef struct { + struct qb_ipc_request_header header __attribute__((aligned(8))); + size_t map_size __attribute__((aligned(8))); + uint64_t server_address __attribute__((aligned(8))); +} mar_req_coroipcc_zc_free_t __attribute__((aligned(8))); + +typedef struct { + struct qb_ipc_request_header header __attribute__((aligned(8))); + uint64_t server_address __attribute__((aligned(8))); +} mar_req_coroipcc_zc_execute_t __attribute__((aligned(8))); + +struct coroipcs_zc_header { + int map_size; + uint64_t server_address; +}; #endif /* IPC_CPG_H_DEFINED */ diff --git a/include/corosync/ipc_evs.h b/include/corosync/ipc_evs.h index 05c6feab..e3f4e8b3 100644 --- a/include/corosync/ipc_evs.h +++ b/include/corosync/ipc_evs.h @@ -36,6 +36,7 @@ #include #include +#include #include enum req_lib_evs_types { @@ -57,14 +58,14 @@ enum res_lib_evs_types { }; struct res_evs_deliver_callback { - coroipc_response_header_t header; + struct qb_ipc_response_header header; unsigned int local_nodeid; size_t msglen; char msg[0]; }; struct res_evs_confchg_callback { - coroipc_response_header_t header; + struct qb_ipc_response_header header; size_t member_list_entries; size_t left_list_entries; size_t joined_list_entries; @@ -74,38 +75,38 @@ struct res_evs_confchg_callback { }; struct req_lib_evs_join { - coroipc_response_header_t header; + struct qb_ipc_response_header header; size_t group_entries; struct evs_group groups[0]; }; struct res_lib_evs_join { - coroipc_response_header_t header; + struct qb_ipc_response_header header; }; struct req_lib_evs_leave { - coroipc_response_header_t header; + struct qb_ipc_response_header header; size_t group_entries; struct evs_group groups[0]; }; struct res_lib_evs_leave { - coroipc_response_header_t header; + struct qb_ipc_response_header header; }; struct req_lib_evs_mcast_joined { - coroipc_response_header_t header; + struct qb_ipc_response_header header; evs_guarantee_t guarantee; size_t msg_len; char msg[0]; }; struct res_lib_evs_mcast_joined { - coroipc_response_header_t header; + struct qb_ipc_response_header header; }; struct req_lib_evs_mcast_groups { - coroipc_response_header_t header; + struct qb_ipc_response_header header; evs_guarantee_t guarantee; size_t msg_len; size_t group_entries; @@ -113,12 +114,12 @@ struct req_lib_evs_mcast_groups { }; struct res_lib_evs_mcast_groups { - coroipc_response_header_t header; + struct qb_ipc_response_header header; }; struct req_exec_evs_mcast { - coroipc_request_header_t header; + struct qb_ipc_request_header header; size_t group_entries; size_t msg_len; struct evs_group groups[0]; @@ -126,11 +127,11 @@ struct req_exec_evs_mcast { }; struct req_lib_evs_membership_get { - coroipc_request_header_t header; + struct qb_ipc_request_header header; }; struct res_lib_evs_membership_get { - coroipc_response_header_t header; + struct qb_ipc_response_header header; unsigned int local_nodeid; unsigned int member_list[PROCESSOR_COUNT_MAX]; size_t member_list_entries; diff --git a/include/corosync/ipc_pload.h b/include/corosync/ipc_pload.h index a4d27450..4e11c85e 100644 --- a/include/corosync/ipc_pload.h +++ b/include/corosync/ipc_pload.h @@ -46,16 +46,16 @@ enum res_lib_evs_types { }; struct res_lib_pload_start { - coroipc_response_header_t header; + struct qb_ipc_response_header header; unsigned int dataset[1024]; }; struct res_lib_pload_mcast { - coroipc_response_header_t header; + struct qb_ipc_response_header header; }; struct req_lib_pload_start { - coroipc_request_header_t header; + struct qb_ipc_request_header header; unsigned int msg_code; unsigned int msg_size; unsigned int msg_count; @@ -63,7 +63,7 @@ struct req_lib_pload_start { }; struct req_lib_pload_mcast { - coroipc_request_header_t header; + struct qb_ipc_request_header header; unsigned int code; }; diff --git a/include/corosync/ipc_quorum.h b/include/corosync/ipc_quorum.h index 240070ef..01e63c38 100644 --- a/include/corosync/ipc_quorum.h +++ b/include/corosync/ipc_quorum.h @@ -51,18 +51,18 @@ enum res_quorum_types { }; struct req_lib_quorum_trackstart { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); unsigned int track_flags; }; struct res_lib_quorum_getquorate { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint32_t quorate; }; struct res_lib_quorum_notification { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_int32_t quorate __attribute__((aligned(8))); mar_uint64_t ring_seq __attribute__((aligned(8))); mar_uint32_t view_list_entries __attribute__((aligned(8))); diff --git a/include/corosync/ipc_votequorum.h b/include/corosync/ipc_votequorum.h index 253380b5..ef58cc89 100644 --- a/include/corosync/ipc_votequorum.h +++ b/include/corosync/ipc_votequorum.h @@ -62,35 +62,35 @@ enum res_votequorum_types { }; struct req_lib_votequorum_setvotes { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); unsigned int votes; int nodeid; }; struct req_lib_votequorum_qdisk_register { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); unsigned int votes; char name[VOTEQUORUM_MAX_QDISK_NAME_LEN]; }; struct req_lib_votequorum_qdisk_poll { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); int state; }; struct req_lib_votequorum_setexpected { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); unsigned int expected_votes; }; struct req_lib_votequorum_trackstart { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); uint64_t context; unsigned int track_flags; }; struct req_lib_votequorum_general { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); }; #define VOTEQUORUM_REASON_KILL_REJECTED 1 @@ -98,12 +98,12 @@ struct req_lib_votequorum_general { #define VOTEQUORUM_REASON_KILL_REJOIN 3 struct req_lib_votequorum_getinfo { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); int nodeid; }; struct res_lib_votequorum_status { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); }; #define VOTEQUORUM_INFO_FLAG_HASSTATE 1 @@ -112,7 +112,7 @@ struct res_lib_votequorum_status { #define VOTEQUORUM_INFO_FLAG_QUORATE 8 struct res_lib_votequorum_getinfo { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); int nodeid; unsigned int votes; unsigned int expected_votes; @@ -123,7 +123,7 @@ struct res_lib_votequorum_getinfo { }; struct res_lib_votequorum_qdisk_getinfo { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); unsigned int votes; unsigned int state; char name[VOTEQUORUM_MAX_QDISK_NAME_LEN]; @@ -135,7 +135,7 @@ struct votequorum_node { }; struct res_lib_votequorum_notification { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint32_t quorate __attribute__((aligned(8))); mar_uint64_t context __attribute__((aligned(8))); mar_uint32_t node_list_entries __attribute__((aligned(8))); @@ -143,7 +143,7 @@ struct res_lib_votequorum_notification { }; struct res_lib_votequorum_expectedvotes_notification { - coroipc_response_header_t header __attribute__((aligned(8))); + struct qb_ipc_response_header header __attribute__((aligned(8))); mar_uint64_t context __attribute__((aligned(8))); mar_uint32_t expected_votes __attribute__((aligned(8))); }; diff --git a/include/corosync/mar_gen.h b/include/corosync/mar_gen.h index d875e488..58a3ba7f 100644 --- a/include/corosync/mar_gen.h +++ b/include/corosync/mar_gen.h @@ -178,7 +178,7 @@ static inline void swab_mar_size_t (mar_size_t *to_swab) swab_mar_uint64_t (to_swab); } -static inline void swab_coroipc_request_header_t (coroipc_request_header_t *to_swab) +static inline void swab_coroipc_request_header_t (struct qb_ipc_request_header *to_swab) { swab_mar_int32_t (&to_swab->size); swab_mar_int32_t (&to_swab->id); diff --git a/include/corosync/totem/totempg.h b/include/corosync/totem/totempg.h index d098d4ea..30ccfe46 100644 --- a/include/corosync/totem/totempg.h +++ b/include/corosync/totem/totempg.h @@ -170,6 +170,19 @@ extern int totempg_member_remove ( const struct totem_ip_address *member, int ring_no); +enum totem_q_level { + TOTEM_Q_LEVEL_LOW, + TOTEM_Q_LEVEL_GOOD, + TOTEM_Q_LEVEL_HIGH, + TOTEM_Q_LEVEL_CRITICAL +}; + +void totempg_check_q_level(hdb_handle_t handle); + +typedef void (*totem_queue_level_changed_fn) (enum totem_q_level level); +extern void totempg_queue_level_register_callback (totem_queue_level_changed_fn); + + #ifdef __cplusplus } #endif diff --git a/lcr/lcr_ifact.c b/lcr/lcr_ifact.c index f1142966..bf2b7214 100644 --- a/lcr/lcr_ifact.c +++ b/lcr/lcr_ifact.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -43,8 +44,6 @@ #include #include #include -#include -#include struct lcr_component_instance { struct lcr_iface *ifaces; diff --git a/lib/Makefile.am b/lib/Makefile.am index c4ee3c03..2794d553 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -36,8 +36,6 @@ get_soname=$(if $($(call uc,$1)_SONAME),$($(call uc,$1)_SONAME),$(SONAME)) get_major=$(firstword $(subst ., ,$(call get_soname,$1))) get_sharedlibs=$(foreach lib,$(SHARED_LIBS_SO:lib%.so=%),lib$(lib).so.$(call get_soname,$(lib))) get_sharedlibs_two=$(foreach lib,$(SHARED_LIBS_SO:lib%.so=%),lib$(lib).so.$(call get_major,$(lib))) -get_explicit_sharedlibs=$(foreach lib,$(EXPLICIT_SHARED_LIBS_SO:lib%.so=%),lib$(lib).so.$(call get_soname,$(lib))) -get_explicit_sharedlibs_two=$(foreach lib,$(EXPLICIT_SHARED_LIBS_SO:lib%.so=%),lib$(lib).so.$(call get_major,$(lib))) get_linker_add=$(if $($(call uc,$1)_LINKER_ADD),$($(call uc,$1)_LINKER_ADD)) MAINTAINERCLEANFILES = Makefile.in @@ -48,10 +46,9 @@ AM_LDFLAGS = -lpthread INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -lib_LIBRARIES = libcpg.a libconfdb.a libevs.a libcfg.a libquorum.a \ - libvotequorum.a libpload.a libcoroipcc.a libsam.a -SHARED_LIBS_SO = $(filter-out $(EXPLICIT_SHARED_LIBS_SO), $(lib_LIBRARIES:%.a=%.so)) -EXPLICIT_SHARED_LIBS_SO = libcoroipcc.so +lib_LIBRARIES = libcpg.a libconfdb.a libquorum.a libevs.a libcfg.a \ + libvotequorum.a libpload.a libsam.a +SHARED_LIBS_SO = $(lib_LIBRARIES:%.a=%.so) libcpg_a_SOURCES = cpg.c libcfg_a_SOURCES = cfg.c @@ -63,12 +60,11 @@ libconfdb_a_SOURCES = confdb.c sa-confdb.c libconfdb_a_LIBADD = ../lcr/lcr_ifact.o CONFDB_LINKER_ADD = $(OS_DYFLAGS) $(OS_LDL) SAM_LINKER_ADD = -L. -lquorum -lconfdb -libcoroipcc_a_SOURCES = coroipcc.c libsam_a_SOURCES = sam.c noinst_HEADERS = sa-confdb.h util.h \ libcfg.versions libconfdb.versions \ - libcoroipcc.versions libcpg.versions \ + libcpg.versions \ libevs.versions libpload.versions \ libquorum.versions libvotequorum.versions \ libsam.versions @@ -78,12 +74,7 @@ noinst_HEADERS = sa-confdb.h util.h \ if BUILD_DARWIN -libcoroipcc.so.$(SONAME): coroipcc.o - $(CC) $(LDFLAGS) $(DARWIN_OPTS) coroipcc.o -o $@ $(AM_LDFLAGS) - ln -sf libcoroipcc.so.$(SONAME) libcoroipcc.so - ln -sf libcoroipcc.so.$(SONAME) libcoroipcc.so.$(SOMAJOR) - -lib%.so: lib%.a libcoroipcc.so.$(SONAME) +lib%.so: lib%.a $(LIBQB_LIBS) $(CC) $(DARWIN_OPTS) $(call get_linker_add,$*) -Wl,-whole-archive $^ -Wl,-no-whole-archive -o $@ ln -sf lib$*.so.$(call get_soname,$*) lib$*.so ln -sf lib$*.so.$(call get_soname,$*) lib$*.so.$(call get_major,$*) @@ -92,35 +83,20 @@ else if BUILD_SOLARIS -libcoroipcc.so.$(SONAME): coroipcc.o - $(LD) $(LDFLAGS) $(SOLARIS_OPTS) -G coroipcc.o -o $@ $(AM_LDFLAGS) -lsocket -lnsl - ln -sf libcoroipcc.so.$(SONAME) libcoroipcc.so - ln -sf libcoroipcc.so.$(SONAME) libcoroipcc.so.$(SOMAJOR) - -lib%.so.$(SONAME): lib%.a libcoroipcc.so.$(SONAME) +lib%.so.$(SONAME): lib%.a $(LD) $(SOLARIS_OPTS) $(call get_linker_add,$*) -G -whole-archive $^ -no-whole-archive -o $@ ln -sf lib$*.so.$(call get_soname,$*) lib$*.so ln -sf lib$*.so.$(call get_soname,$*) lib$*.so.$(call get_major,$*) else -libcoroipcc.so.$(SONAME): coroipcc.o - $(CC) -shared -o $@ \ - -Wl,-soname=libcoroipcc.so.$(SOMAJOR) \ - -Wl,-version-script=$(srcdir)/libcoroipcc.versions \ - $(LDFLAGS) $^ $(AM_LDFLAGS) - ln -sf libcoroipcc.so.$(SONAME) libcoroipcc.so - ln -sf libcoroipcc.so.$(SONAME) libcoroipcc.so.$(SOMAJOR) - -lib%.so: lib%.a libcoroipcc.so.$(SONAME) - if [ ! "$@" = "libcoroipcc.so" ] ; then \ +lib%.so: lib%.a $(CC) -shared -o $@.$(call get_soname,$*) \ -Wl,-soname=lib$*.so.$(call get_major,$*) \ -Wl,-version-script=$(srcdir)/lib$*.versions \ - -Wl,-whole-archive $^ -Wl,-no-whole-archive $(LDFLAGS) $(AM_LDFLAGS) $(call get_linker_add,$*) ;\ - ln -sf lib$*.so.$(call get_soname,$*) lib$*.so ;\ - ln -sf lib$*.so.$(call get_soname,$*) lib$*.so.$(call get_major,$*) ;\ - fi + -Wl,-whole-archive $^ -Wl,-no-whole-archive $(LDFLAGS) $(LIBQB_LIBS) $(AM_LDFLAGS) $(call get_linker_add,$*) + ln -sf lib$*.so.$(call get_soname,$*) lib$*.so + ln -sf lib$*.so.$(call get_soname,$*) lib$*.so.$(call get_major,$*) endif @@ -131,8 +107,8 @@ all-local: $(get_explicit_sharedlibs) $(SHARED_LIBS_SO) install-exec-local: $(INSTALL) -d $(DESTDIR)/$(libdir) - $(INSTALL) -m 755 $(get_sharedlibs) $(get_explicit_sharedlibs) $(DESTDIR)/$(libdir) - $(CP) -a $(SHARED_LIBS_SO) $(EXPLICIT_SHARED_LIBS_SO) $(get_sharedlibs_two) $(get_explicit_sharedlibs_two) $(DESTDIR)/$(libdir) + $(INSTALL) -m 755 $(get_sharedlibs) $(DESTDIR)/$(libdir) + $(CP) -a $(SHARED_LIBS_SO) $(get_sharedlibs_two) $(DESTDIR)/$(libdir) uninstall-local: cd $(DESTDIR)/$(libdir)/ && \ diff --git a/lib/cfg.c b/lib/cfg.c index a3aee9c0..3a662d45 100644 --- a/lib/cfg.c +++ b/lib/cfg.c @@ -47,9 +47,9 @@ #include #include +#include + #include -#include -#include #include #include @@ -61,8 +61,8 @@ /* * Data structure for instance data */ -struct cfg_instance { - hdb_handle_t handle; +struct cfg_inst { + qb_ipcc_connection_t *c; corosync_cfg_callbacks_t callbacks; cs_name_t comp_name; int comp_registered; @@ -83,32 +83,30 @@ corosync_cfg_initialize ( corosync_cfg_handle_t *cfg_handle, const corosync_cfg_callbacks_t *cfg_callbacks) { - struct cfg_instance *cfg_instance; + struct cfg_inst *cfg_inst; cs_error_t error = CS_OK; - error = hdb_error_to_cs (hdb_handle_create (&cfg_hdb, sizeof (struct cfg_instance), cfg_handle)); + error = hdb_error_to_cs (hdb_handle_create (&cfg_hdb, sizeof (struct cfg_inst), cfg_handle)); if (error != CS_OK) { goto error_no_destroy; } - error = hdb_error_to_cs (hdb_handle_get (&cfg_hdb, *cfg_handle, (void *)&cfg_instance)); + error = hdb_error_to_cs (hdb_handle_get (&cfg_hdb, *cfg_handle, (void *)&cfg_inst)); if (error != CS_OK) { goto error_destroy; } - error = coroipcc_service_connect ( - COROSYNC_SOCKET_NAME, - CFG_SERVICE, - IPC_REQUEST_SIZE, - IPC_RESPONSE_SIZE, - IPC_DISPATCH_SIZE, - &cfg_instance->handle); + cfg_inst->c = qb_ipcc_connect ("cfg", IPC_REQUEST_SIZE); + if (cfg_inst->c == NULL) { + error = qb_to_cs_error(-errno); + goto error_put_destroy; + } if (error != CS_OK) { goto error_put_destroy; } if (cfg_callbacks) { - memcpy (&cfg_instance->callbacks, cfg_callbacks, sizeof (corosync_cfg_callbacks_t)); + memcpy (&cfg_inst->callbacks, cfg_callbacks, sizeof (corosync_cfg_callbacks_t)); } (void)hdb_handle_put (&cfg_hdb, *cfg_handle); @@ -128,15 +126,15 @@ corosync_cfg_fd_get ( corosync_cfg_handle_t cfg_handle, int32_t *selection_fd) { - struct cfg_instance *cfg_instance; + struct cfg_inst *cfg_inst; cs_error_t error; - error = hdb_error_to_cs (hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_instance)); + error = hdb_error_to_cs (hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_inst)); if (error != CS_OK) { return (error); } - error = coroipcc_fd_get (cfg_instance->handle, selection_fd); + error = qb_to_cs_error (qb_ipcc_fd_get (cfg_inst->c, selection_fd)); (void)hdb_handle_put (&cfg_hdb, cfg_handle); return (error); @@ -150,13 +148,14 @@ corosync_cfg_dispatch ( int timeout = -1; cs_error_t error; int cont = 1; /* always continue do loop except when set to 0 */ - struct cfg_instance *cfg_instance; + struct cfg_inst *cfg_inst; struct res_lib_cfg_testshutdown *res_lib_cfg_testshutdown; corosync_cfg_callbacks_t callbacks; - coroipc_response_header_t *dispatch_data; + struct qb_ipc_response_header *dispatch_data; + char dispatch_buf[IPC_DISPATCH_SIZE]; error = hdb_error_to_cs (hdb_handle_get (&cfg_hdb, cfg_handle, - (void *)&cfg_instance)); + (void *)&cfg_inst)); if (error != CS_OK) { return (error); } @@ -168,12 +167,13 @@ corosync_cfg_dispatch ( timeout = 0; } + dispatch_data = (struct qb_ipc_response_header *)dispatch_buf; do { - - error = coroipcc_dispatch_get ( - cfg_instance->handle, - (void **)&dispatch_data, - timeout); + error = qb_to_cs_error (qb_ipcc_event_recv ( + cfg_inst->c, + dispatch_buf, + IPC_DISPATCH_SIZE, + timeout)); if (error == CS_ERR_BAD_HANDLE) { error = CS_OK; goto error_put; @@ -195,7 +195,7 @@ corosync_cfg_dispatch ( * A risk of this dispatch method is that the callback routines may * operate at the same time that cfgFinalize has been called in another thread. */ - memcpy (&callbacks, &cfg_instance->callbacks, sizeof (corosync_cfg_callbacks_t)); + memcpy (&callbacks, &cfg_inst->callbacks, sizeof (corosync_cfg_callbacks_t)); /* * Dispatch incoming response @@ -210,12 +210,10 @@ corosync_cfg_dispatch ( callbacks.corosync_cfg_shutdown_callback(cfg_handle, res_lib_cfg_testshutdown->flags); break; default: - coroipcc_dispatch_put (cfg_instance->handle); error = CS_ERR_LIBRARY; goto error_nounlock; break; } - coroipcc_dispatch_put (cfg_instance->handle); /* * Determine if more messages should be processed @@ -235,10 +233,10 @@ cs_error_t corosync_cfg_finalize ( corosync_cfg_handle_t cfg_handle) { - struct cfg_instance *cfg_instance; + struct cfg_inst *cfg_inst; cs_error_t error; - error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_instance)); + error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_inst)); if (error != CS_OK) { return (error); } @@ -246,14 +244,14 @@ corosync_cfg_finalize ( /* * Another thread has already started finalizing */ - if (cfg_instance->finalize) { + if (cfg_inst->finalize) { (void)hdb_handle_put (&cfg_hdb, cfg_handle); return (CS_ERR_BAD_HANDLE); } - cfg_instance->finalize = 1; + cfg_inst->finalize = 1; - coroipcc_service_disconnect (cfg_instance->handle); + qb_ipcc_disconnect (cfg_inst->c); (void)hdb_handle_destroy (&cfg_hdb, cfg_handle); @@ -269,14 +267,14 @@ corosync_cfg_ring_status_get ( char ***status, unsigned int *interface_count) { - struct cfg_instance *cfg_instance; + struct cfg_inst *cfg_inst; struct req_lib_cfg_ringstatusget req_lib_cfg_ringstatusget; struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget; unsigned int i, j; cs_error_t error; struct iovec iov; - error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_instance)); + error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_inst)); if (error != CS_OK) { return (error); } @@ -287,11 +285,11 @@ corosync_cfg_ring_status_get ( iov.iov_base = (void *)&req_lib_cfg_ringstatusget, iov.iov_len = sizeof (struct req_lib_cfg_ringstatusget), - error = coroipcc_msg_send_reply_receive(cfg_instance->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv(cfg_inst->c, &iov, 1, &res_lib_cfg_ringstatusget, - sizeof (struct res_lib_cfg_ringstatusget)); + sizeof (struct res_lib_cfg_ringstatusget), -1)); *interface_count = res_lib_cfg_ringstatusget.interface_count; *interface_names = malloc (sizeof (char *) * *interface_count); @@ -350,13 +348,13 @@ cs_error_t corosync_cfg_ring_reenable ( corosync_cfg_handle_t cfg_handle) { - struct cfg_instance *cfg_instance; + struct cfg_inst *cfg_inst; struct req_lib_cfg_ringreenable req_lib_cfg_ringreenable; struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable; cs_error_t error; struct iovec iov; - error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_instance)); + error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_inst)); if (error != CS_OK) { return (error); } @@ -367,11 +365,11 @@ corosync_cfg_ring_reenable ( iov.iov_base = (void *)&req_lib_cfg_ringreenable, iov.iov_len = sizeof (struct req_lib_cfg_ringreenable); - error = coroipcc_msg_send_reply_receive (cfg_instance->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c, &iov, 1, &res_lib_cfg_ringreenable, - sizeof (struct res_lib_cfg_ringreenable)); + sizeof (struct res_lib_cfg_ringreenable), -1)); (void)hdb_handle_put (&cfg_hdb, cfg_handle); @@ -384,13 +382,13 @@ corosync_cfg_service_load ( const char *service_name, unsigned int service_ver) { - struct cfg_instance *cfg_instance; + struct cfg_inst *cfg_inst; struct req_lib_cfg_serviceload req_lib_cfg_serviceload; struct res_lib_cfg_serviceload res_lib_cfg_serviceload; cs_error_t error; struct iovec iov; - error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_instance)); + error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_inst)); if (error != CS_OK) { return (error); } @@ -406,11 +404,11 @@ corosync_cfg_service_load ( iov.iov_base = (void *)&req_lib_cfg_serviceload; iov.iov_len = sizeof (req_lib_cfg_serviceload); - error = coroipcc_msg_send_reply_receive (cfg_instance->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c, &iov, 1, &res_lib_cfg_serviceload, - sizeof (struct res_lib_cfg_serviceload)); + sizeof (struct res_lib_cfg_serviceload), -1)); (void)hdb_handle_put (&cfg_hdb, cfg_handle); @@ -423,13 +421,13 @@ corosync_cfg_service_unload ( const char *service_name, unsigned int service_ver) { - struct cfg_instance *cfg_instance; + struct cfg_inst *cfg_inst; struct req_lib_cfg_serviceunload req_lib_cfg_serviceunload; struct res_lib_cfg_serviceunload res_lib_cfg_serviceunload; cs_error_t error; struct iovec iov; - error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_instance)); + error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_inst)); if (error != CS_OK) { return (error); } @@ -445,11 +443,11 @@ corosync_cfg_service_unload ( iov.iov_base = (void *)&req_lib_cfg_serviceunload; iov.iov_len = sizeof (req_lib_cfg_serviceunload); - error = coroipcc_msg_send_reply_receive (cfg_instance->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c, &iov, 1, &res_lib_cfg_serviceunload, - sizeof (struct res_lib_cfg_serviceunload)); + sizeof (struct res_lib_cfg_serviceunload), -1)); (void)hdb_handle_put (&cfg_hdb, cfg_handle); @@ -461,7 +459,7 @@ corosync_cfg_state_track ( uint8_t track_flags, const corosync_cfg_state_notification_t *notification_buffer) { - struct cfg_instance *cfg_instance; + struct cfg_inst *cfg_inst; struct req_lib_cfg_statetrack req_lib_cfg_statetrack; struct res_lib_cfg_statetrack res_lib_cfg_statetrack; cs_error_t error; @@ -473,7 +471,7 @@ corosync_cfg_state_track ( req_lib_cfg_statetrack.notification_buffer_address = (corosync_cfg_state_notification_t *)notification_buffer; error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, - (void *)&cfg_instance)); + (void *)&cfg_inst)); if (error != CS_OK) { return (error); } @@ -481,11 +479,11 @@ corosync_cfg_state_track ( iov.iov_base = (void *)&req_lib_cfg_statetrack, iov.iov_len = sizeof (struct req_lib_cfg_statetrack), - error = coroipcc_msg_send_reply_receive (cfg_instance->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c, &iov, 1, &res_lib_cfg_statetrack, - sizeof (struct res_lib_cfg_statetrack)); + sizeof (struct res_lib_cfg_statetrack), -1)); (void)hdb_handle_put (&cfg_hdb, cfg_handle); @@ -496,14 +494,14 @@ cs_error_t corosync_cfg_state_track_stop ( corosync_cfg_handle_t cfg_handle) { - struct cfg_instance *cfg_instance; + struct cfg_inst *cfg_inst; struct req_lib_cfg_statetrackstop req_lib_cfg_statetrackstop; struct res_lib_cfg_statetrackstop res_lib_cfg_statetrackstop; cs_error_t error; struct iovec iov; error = hdb_error_to_cs (hdb_handle_get (&cfg_hdb, cfg_handle, - (void *)&cfg_instance)); + (void *)&cfg_inst)); if (error != CS_OK) { return (error); } @@ -514,11 +512,11 @@ corosync_cfg_state_track_stop ( iov.iov_base = (void *)&req_lib_cfg_statetrackstop, iov.iov_len = sizeof (struct req_lib_cfg_statetrackstop), - error = coroipcc_msg_send_reply_receive (cfg_instance->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c, &iov, 1, &res_lib_cfg_statetrackstop, - sizeof (struct res_lib_cfg_statetrackstop)); + sizeof (struct res_lib_cfg_statetrackstop), -1)); (void)hdb_handle_put (&cfg_hdb, cfg_handle); @@ -531,7 +529,7 @@ corosync_cfg_kill_node ( unsigned int nodeid, const char *reason) { - struct cfg_instance *cfg_instance; + struct cfg_inst *cfg_inst; struct req_lib_cfg_killnode req_lib_cfg_killnode; struct res_lib_cfg_killnode res_lib_cfg_killnode; cs_error_t error; @@ -541,7 +539,7 @@ corosync_cfg_kill_node ( return CS_ERR_NAME_TOO_LONG; error = hdb_error_to_cs (hdb_handle_get (&cfg_hdb, cfg_handle, - (void *)&cfg_instance)); + (void *)&cfg_inst)); if (error != CS_OK) { return (error); } @@ -555,11 +553,11 @@ corosync_cfg_kill_node ( iov.iov_base = (void *)&req_lib_cfg_killnode; iov.iov_len = sizeof (struct req_lib_cfg_killnode); - error = coroipcc_msg_send_reply_receive (cfg_instance->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c, &iov, 1, &res_lib_cfg_killnode, - sizeof (struct res_lib_cfg_killnode)); + sizeof (struct res_lib_cfg_killnode), -1)); error = res_lib_cfg_killnode.header.error; @@ -573,14 +571,14 @@ corosync_cfg_try_shutdown ( corosync_cfg_handle_t cfg_handle, corosync_cfg_shutdown_flags_t flags) { - struct cfg_instance *cfg_instance; + struct cfg_inst *cfg_inst; struct req_lib_cfg_tryshutdown req_lib_cfg_tryshutdown; struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown; cs_error_t error; struct iovec iov; error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, - (void *)&cfg_instance)); + (void *)&cfg_inst)); if (error != CS_OK) { return (error); } @@ -592,11 +590,11 @@ corosync_cfg_try_shutdown ( iov.iov_base = (void *)&req_lib_cfg_tryshutdown; iov.iov_len = sizeof (req_lib_cfg_tryshutdown); - error = coroipcc_msg_send_reply_receive (cfg_instance->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c, &iov, 1, &res_lib_cfg_tryshutdown, - sizeof (struct res_lib_cfg_tryshutdown)); + sizeof (struct res_lib_cfg_tryshutdown), -1)); (void)hdb_handle_put (&cfg_hdb, cfg_handle); @@ -608,14 +606,14 @@ corosync_cfg_replyto_shutdown ( corosync_cfg_handle_t cfg_handle, corosync_cfg_shutdown_reply_flags_t response) { - struct cfg_instance *cfg_instance; + struct cfg_inst *cfg_inst; struct req_lib_cfg_replytoshutdown req_lib_cfg_replytoshutdown; struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown; struct iovec iov; cs_error_t error; error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, - (void *)&cfg_instance)); + (void *)&cfg_inst)); if (error != CS_OK) { return (error); } @@ -627,11 +625,11 @@ corosync_cfg_replyto_shutdown ( iov.iov_base = (void *)&req_lib_cfg_replytoshutdown; iov.iov_len = sizeof (struct req_lib_cfg_replytoshutdown); - error = coroipcc_msg_send_reply_receive (cfg_instance->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c, &iov, 1, &res_lib_cfg_replytoshutdown, - sizeof (struct res_lib_cfg_replytoshutdown)); + sizeof (struct res_lib_cfg_replytoshutdown), -1)); return (error); } @@ -646,15 +644,16 @@ cs_error_t corosync_cfg_get_node_addrs ( cs_error_t error; struct req_lib_cfg_get_node_addrs req_lib_cfg_get_node_addrs; struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs; - struct cfg_instance *cfg_instance; + struct cfg_inst *cfg_inst; int addrlen = 0; int i; struct iovec iov; void *return_address; const char *addr_buf; + char response_buf[IPC_RESPONSE_SIZE]; error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, - (void *)&cfg_instance)); + (void *)&cfg_inst)); if (error != CS_OK) { return (error); } @@ -666,12 +665,11 @@ cs_error_t corosync_cfg_get_node_addrs ( iov.iov_base = (char *)&req_lib_cfg_get_node_addrs; iov.iov_len = sizeof (req_lib_cfg_get_node_addrs); - error = coroipcc_msg_send_reply_receive_in_buf_get ( - cfg_instance->handle, - &iov, - 1, - &return_address); - res_lib_cfg_get_node_addrs = return_address; + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + cfg_inst->c, + &iov, 1, + response_buf, IPC_RESPONSE_SIZE, -1)); + res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)response_buf; if (error != CS_OK) { goto error_put; @@ -705,7 +703,6 @@ cs_error_t corosync_cfg_get_node_addrs ( errno = error = res_lib_cfg_get_node_addrs->header.error; error_put: - error = coroipcc_msg_send_reply_receive_in_buf_put (cfg_instance->handle); hdb_handle_put (&cfg_hdb, cfg_handle); return (error); @@ -716,7 +713,7 @@ cs_error_t corosync_cfg_local_get ( unsigned int *local_nodeid) { cs_error_t error; - struct cfg_instance *cfg_inst; + struct cfg_inst *cfg_inst; struct iovec iov; struct req_lib_cfg_local_get req_lib_cfg_local_get; struct res_lib_cfg_local_get res_lib_cfg_local_get; @@ -726,18 +723,18 @@ cs_error_t corosync_cfg_local_get ( return (error); } - req_lib_cfg_local_get.header.size = sizeof (coroipc_request_header_t); + req_lib_cfg_local_get.header.size = sizeof (struct qb_ipc_request_header); req_lib_cfg_local_get.header.id = MESSAGE_REQ_CFG_LOCAL_GET; iov.iov_base = (void *)&req_lib_cfg_local_get; iov.iov_len = sizeof (struct req_lib_cfg_local_get); - error = coroipcc_msg_send_reply_receive ( - cfg_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + cfg_inst->c, &iov, 1, &res_lib_cfg_local_get, - sizeof (struct res_lib_cfg_local_get)); + sizeof (struct res_lib_cfg_local_get), -1)); if (error != CS_OK) { goto error_exit; @@ -758,14 +755,14 @@ corosync_cfg_crypto_set ( corosync_cfg_handle_t handle, unsigned int type) { - struct cfg_instance *cfg_instance; + struct cfg_inst *cfg_inst; struct req_lib_cfg_crypto_set req_lib_cfg_crypto_set; struct res_lib_cfg_crypto_set res_lib_cfg_crypto_set; struct iovec iov; cs_error_t error; - error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, handle, (void *)&cfg_instance)); + error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, handle, (void *)&cfg_inst)); if (error != CS_OK) { return (error); } @@ -777,11 +774,11 @@ corosync_cfg_crypto_set ( iov.iov_base = (void *)&req_lib_cfg_crypto_set; iov.iov_len = sizeof (struct req_lib_cfg_crypto_set); - error = coroipcc_msg_send_reply_receive (cfg_instance->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c, &iov, 1, &res_lib_cfg_crypto_set, - sizeof (struct res_lib_cfg_crypto_set)); + sizeof (struct res_lib_cfg_crypto_set), -1)); if (error == CS_OK) error = res_lib_cfg_crypto_set.header.error; diff --git a/lib/confdb.c b/lib/confdb.c index 7bea08ee..51a8c340 100644 --- a/lib/confdb.c +++ b/lib/confdb.c @@ -45,11 +45,10 @@ #include #include -#include -#include #include #include #include +#include #include #include @@ -58,9 +57,6 @@ #include "sa-confdb.h" -#undef MIN -#define MIN(x,y) ((x) < (y) ? (x) : (y)) - /* Hold the information for iterators so that callers can do recursive tree traversals. each object_handle can have its own iterator */ @@ -72,7 +68,7 @@ struct iter_context { }; struct confdb_inst { - hdb_handle_t handle; + qb_ipcc_connection_t *c; int finalize; int standalone; confdb_callbacks_t callbacks; @@ -147,13 +143,12 @@ cs_error_t confdb_initialize ( confdb_inst->standalone = 1; } else { - error = coroipcc_service_connect ( - COROSYNC_SOCKET_NAME, - CONFDB_SERVICE, - IPC_REQUEST_SIZE, - IPC_RESPONSE_SIZE, - IPC_DISPATCH_SIZE, - &confdb_inst->handle); + error = CS_OK; + confdb_inst->c = qb_ipcc_connect ("confdb", IPC_REQUEST_SIZE); + if (confdb_inst->c == NULL) { + error = qb_to_cs_error(-errno); + goto error_put_destroy; + } } if (error != CS_OK) goto error_put_destroy; @@ -205,7 +200,7 @@ cs_error_t confdb_finalize ( free_context_list(confdb_inst, &confdb_inst->key_iter_head); if (!confdb_inst->standalone) { - coroipcc_service_disconnect (confdb_inst->handle); + qb_ipcc_disconnect (confdb_inst->c); } (void)hdb_handle_destroy (&confdb_handle_t_db, handle); @@ -227,7 +222,7 @@ cs_error_t confdb_fd_get ( return (error); } - error = coroipcc_fd_get (confdb_inst->handle, fd); + error = qb_to_cs_error (qb_ipcc_fd_get (confdb_inst->c, fd)); (void)hdb_handle_put (&confdb_handle_t_db, handle); @@ -285,7 +280,8 @@ cs_error_t confdb_dispatch ( struct res_lib_confdb_object_create_callback *res_object_created_pt; struct res_lib_confdb_object_destroy_callback *res_object_destroyed_pt; struct res_lib_confdb_reload_callback *res_reload_pt; - coroipc_response_header_t *dispatch_data; + struct qb_ipc_response_header *dispatch_data; + char dispatch_buf[IPC_DISPATCH_SIZE]; error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst)); if (error != CS_OK) { @@ -305,11 +301,13 @@ cs_error_t confdb_dispatch ( timeout = 0; } + dispatch_data = (struct qb_ipc_response_header *)dispatch_buf; do { - error = coroipcc_dispatch_get ( - confdb_inst->handle, - (void **)&dispatch_data, - timeout); + error = qb_to_cs_error(qb_ipcc_event_recv ( + confdb_inst->c, + dispatch_buf, + IPC_DISPATCH_SIZE, + timeout)); if (error == CS_ERR_BAD_HANDLE) { error = CS_OK; goto error_put; @@ -397,12 +395,10 @@ cs_error_t confdb_dispatch ( break; default: - coroipcc_dispatch_put (confdb_inst->handle); error = CS_ERR_LIBRARY; goto error_noput; break; } - coroipcc_dispatch_put (confdb_inst->handle); /* * Determine if more messages should be processed @@ -455,12 +451,12 @@ cs_error_t confdb_object_create ( iov.iov_base = (char *)&req_lib_confdb_object_create; iov.iov_len = sizeof (struct req_lib_confdb_object_create); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res_lib_confdb_object_create, - sizeof (struct res_lib_confdb_object_create)); + sizeof (struct res_lib_confdb_object_create), -1)); if (error != CS_OK) { goto error_exit; @@ -483,7 +479,7 @@ cs_error_t confdb_object_destroy ( struct confdb_inst *confdb_inst; struct iovec iov; struct req_lib_confdb_object_destroy req_lib_confdb_object_destroy; - coroipc_response_header_t res; + struct qb_ipc_response_header res; error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst)); if (error != CS_OK) { @@ -505,12 +501,12 @@ cs_error_t confdb_object_destroy ( iov.iov_base = (char *)&req_lib_confdb_object_destroy; iov.iov_len = sizeof (struct req_lib_confdb_object_destroy); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res, - sizeof (coroipc_response_header_t)); + sizeof (struct qb_ipc_response_header), -1)); if (error != CS_OK) { goto error_exit; @@ -555,12 +551,12 @@ cs_error_t confdb_object_parent_get ( iov.iov_base = (char *)&req_lib_confdb_object_parent_get; iov.iov_len = sizeof (struct req_lib_confdb_object_parent_get); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res_lib_confdb_object_parent_get, - sizeof (struct res_lib_confdb_object_parent_get)); + sizeof (struct res_lib_confdb_object_parent_get), -1)); if (error != CS_OK) { goto error_exit; @@ -607,12 +603,12 @@ cs_error_t confdb_object_name_get ( iov.iov_base = (char *)&request; iov.iov_len = sizeof (struct req_lib_confdb_object_name_get); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &response, - sizeof (struct res_lib_confdb_object_name_get)); + sizeof (struct res_lib_confdb_object_name_get), -1)); if (error != CS_OK) { goto error_exit; @@ -637,7 +633,7 @@ static cs_error_t do_find_destroy( cs_error_t error; struct iovec iov; struct req_lib_confdb_object_find_destroy req_lib_confdb_object_find_destroy; - coroipc_response_header_t res; + struct qb_ipc_response_header res; if (!find_handle) return CS_OK; @@ -657,12 +653,12 @@ static cs_error_t do_find_destroy( iov.iov_base = (char *)&req_lib_confdb_object_find_destroy; iov.iov_len = sizeof (struct req_lib_confdb_object_find_destroy); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res, - sizeof (coroipc_response_header_t)); + sizeof (struct qb_ipc_response_header), -1)); if (error != CS_OK) { goto error_exit; @@ -736,7 +732,7 @@ cs_error_t confdb_key_create ( struct confdb_inst *confdb_inst; struct iovec iov; struct req_lib_confdb_key_create req_lib_confdb_key_create; - coroipc_response_header_t res; + struct qb_ipc_response_header res; error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst)); if (error != CS_OK) { @@ -764,12 +760,12 @@ cs_error_t confdb_key_create ( iov.iov_base = (char *)&req_lib_confdb_key_create; iov.iov_len = sizeof (struct req_lib_confdb_key_create); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res, - sizeof (res)); + sizeof (res), -1)); if (error != CS_OK) { goto error_exit; @@ -796,7 +792,7 @@ cs_error_t confdb_key_create_typed ( struct confdb_inst *confdb_inst; struct iovec iov; struct req_lib_confdb_key_create_typed request; - coroipc_response_header_t res; + struct qb_ipc_response_header res; error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst)); if (error != CS_OK) { @@ -824,12 +820,12 @@ cs_error_t confdb_key_create_typed ( iov.iov_base = (char *)&request; iov.iov_len = sizeof (struct req_lib_confdb_key_create_typed); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res, - sizeof (res)); + sizeof (res), -1)); if (error != CS_OK) { goto error_exit; @@ -857,7 +853,7 @@ cs_error_t confdb_key_delete ( struct confdb_inst *confdb_inst; struct iovec iov; struct req_lib_confdb_key_delete req_lib_confdb_key_delete; - coroipc_response_header_t res; + struct qb_ipc_response_header res; error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst)); if (error != CS_OK) { @@ -885,12 +881,12 @@ cs_error_t confdb_key_delete ( iov.iov_base = (char *)&req_lib_confdb_key_delete; iov.iov_len = sizeof (struct req_lib_confdb_key_delete); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res, - sizeof (res)); + sizeof (res), -1)); if (error != CS_OK) { goto error_exit; @@ -942,12 +938,12 @@ cs_error_t confdb_key_get ( iov.iov_base = (char *)&req_lib_confdb_key_get; iov.iov_len = sizeof (struct req_lib_confdb_key_get); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res_lib_confdb_key_get, - sizeof (struct res_lib_confdb_key_get)); + sizeof (struct res_lib_confdb_key_get), -1)); if (error != CS_OK) { goto error_exit; @@ -1003,12 +999,12 @@ cs_error_t confdb_key_get_typed ( iov.iov_base = (char *)&req_lib_confdb_key_get; iov.iov_len = sizeof (struct req_lib_confdb_key_get); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &response, - sizeof (struct res_lib_confdb_key_get_typed)); + sizeof (struct res_lib_confdb_key_get_typed), -1)); if (error != CS_OK) { goto error_exit; @@ -1065,12 +1061,12 @@ cs_error_t confdb_key_increment ( iov.iov_base = (char *)&req_lib_confdb_key_get; iov.iov_len = sizeof (struct req_lib_confdb_key_get); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res_lib_confdb_key_incdec, - sizeof (struct res_lib_confdb_key_incdec)); + sizeof (struct res_lib_confdb_key_incdec), -1)); if (error != CS_OK) { goto error_exit; @@ -1124,12 +1120,12 @@ cs_error_t confdb_key_decrement ( iov.iov_base = (char *)&req_lib_confdb_key_get; iov.iov_len = sizeof (struct req_lib_confdb_key_get); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res_lib_confdb_key_incdec, - sizeof (struct res_lib_confdb_key_incdec)); + sizeof (struct res_lib_confdb_key_incdec), -1)); if (error != CS_OK) { goto error_exit; @@ -1160,7 +1156,7 @@ cs_error_t confdb_key_replace ( struct confdb_inst *confdb_inst; struct iovec iov; struct req_lib_confdb_key_replace req_lib_confdb_key_replace; - coroipc_response_header_t res; + struct qb_ipc_response_header res; error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst)); if (error != CS_OK) { @@ -1190,12 +1186,12 @@ cs_error_t confdb_key_replace ( iov.iov_base = (char *)&req_lib_confdb_key_replace; iov.iov_len = sizeof (struct req_lib_confdb_key_replace); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res, - sizeof (res)); + sizeof (res), -1)); if (error != CS_OK) { goto error_exit; @@ -1362,12 +1358,12 @@ cs_error_t confdb_object_find ( iov.iov_base = (char *)&req_lib_confdb_object_find; iov.iov_len = sizeof (struct req_lib_confdb_object_find); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res_lib_confdb_object_find, - sizeof (struct res_lib_confdb_object_find)); + sizeof (struct res_lib_confdb_object_find), -1)); if (error != CS_OK) { goto error_exit; @@ -1431,12 +1427,12 @@ cs_error_t confdb_object_iter ( iov.iov_base = (char *)&req_lib_confdb_object_iter; iov.iov_len = sizeof (struct req_lib_confdb_object_iter); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res_lib_confdb_object_iter, - sizeof (struct res_lib_confdb_object_iter)); + sizeof (struct res_lib_confdb_object_iter), -1)); if (error != CS_OK) { goto error_exit; @@ -1503,12 +1499,12 @@ cs_error_t confdb_key_iter ( iov.iov_base = (char *)&req_lib_confdb_key_iter; iov.iov_len = sizeof (struct req_lib_confdb_key_iter); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res_lib_confdb_key_iter, - sizeof (struct res_lib_confdb_key_iter)); + sizeof (struct res_lib_confdb_key_iter), -1)); if (error != CS_OK) { goto error_exit; @@ -1579,12 +1575,12 @@ cs_error_t confdb_key_iter_typed ( iov.iov_base = (char *)&req_lib_confdb_key_iter; iov.iov_len = sizeof (struct req_lib_confdb_key_iter); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &response, - sizeof (struct res_lib_confdb_key_iter_typed)); + sizeof (struct res_lib_confdb_key_iter_typed), -1)); if (error != CS_OK) { goto error_exit; @@ -1616,7 +1612,7 @@ cs_error_t confdb_write ( cs_error_t error; struct confdb_inst *confdb_inst; struct iovec iov; - coroipc_request_header_t req; + struct qb_ipc_request_header req; struct res_lib_confdb_write res_lib_confdb_write; error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst)); @@ -1633,18 +1629,18 @@ cs_error_t confdb_write ( goto error_exit; } - req.size = sizeof (coroipc_request_header_t); + req.size = sizeof (struct qb_ipc_request_header); req.id = MESSAGE_REQ_CONFDB_WRITE; iov.iov_base = (char *)&req; - iov.iov_len = sizeof (coroipc_request_header_t); + iov.iov_len = sizeof (struct qb_ipc_request_header); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res_lib_confdb_write, - sizeof (struct res_lib_confdb_write)); + sizeof (struct res_lib_confdb_write), -1)); if (error != CS_OK) { /* FIXME: set error_text */ @@ -1654,7 +1650,7 @@ cs_error_t confdb_write ( error = res_lib_confdb_write.header.error; if (res_lib_confdb_write.error.length) { memcpy(error_text, res_lib_confdb_write.error.value, - MIN(res_lib_confdb_write.error.length,errbuf_len)); + QB_MIN(res_lib_confdb_write.error.length,errbuf_len)); error_text[errbuf_len-1] = '\0'; } @@ -1697,12 +1693,12 @@ cs_error_t confdb_reload ( iov.iov_base = (char *)&req_lib_confdb_reload; iov.iov_len = sizeof (req_lib_confdb_reload); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res_lib_confdb_reload, - sizeof (struct res_lib_confdb_reload)); + sizeof (struct res_lib_confdb_reload), -1)); if (error != CS_OK) { /* FIXME: set error_text */ @@ -1712,7 +1708,7 @@ cs_error_t confdb_reload ( error = res_lib_confdb_reload.header.error; if(res_lib_confdb_reload.error.length) { memcpy(error_text, res_lib_confdb_reload.error.value, - MIN(res_lib_confdb_reload.error.length,errbuf_len)); + QB_MIN(res_lib_confdb_reload.error.length,errbuf_len)); error_text[errbuf_len-1] = '\0'; } @@ -1731,7 +1727,7 @@ cs_error_t confdb_track_changes ( struct confdb_inst *confdb_inst; struct iovec iov; struct req_lib_confdb_object_track_start req; - coroipc_response_header_t res; + struct qb_ipc_response_header res; error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst)); if (error != CS_OK) { @@ -1751,12 +1747,12 @@ cs_error_t confdb_track_changes ( iov.iov_base = (char *)&req; iov.iov_len = sizeof (struct req_lib_confdb_object_track_start); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res, - sizeof (coroipc_response_header_t)); + sizeof (struct qb_ipc_response_header), -1)); if (error != CS_OK) { goto error_exit; @@ -1775,8 +1771,8 @@ cs_error_t confdb_stop_track_changes (confdb_handle_t handle) cs_error_t error; struct confdb_inst *confdb_inst; struct iovec iov; - coroipc_request_header_t req; - coroipc_response_header_t res; + struct qb_ipc_request_header req; + struct qb_ipc_response_header res; error = hdb_error_to_cs(hdb_handle_get (&confdb_handle_t_db, handle, (void *)&confdb_inst)); if (error != CS_OK) { @@ -1788,18 +1784,18 @@ cs_error_t confdb_stop_track_changes (confdb_handle_t handle) goto error_exit; } - req.size = sizeof (coroipc_request_header_t); + req.size = sizeof (struct qb_ipc_request_header); req.id = MESSAGE_REQ_CONFDB_TRACK_STOP; iov.iov_base = (char *)&req; - iov.iov_len = sizeof (coroipc_request_header_t); + iov.iov_len = sizeof (struct qb_ipc_request_header); - error = coroipcc_msg_send_reply_receive ( - confdb_inst->handle, + error = qb_to_cs_error (qb_ipcc_sendv_recv ( + confdb_inst->c, &iov, 1, &res, - sizeof (coroipc_response_header_t)); + sizeof (struct qb_ipc_response_header), -1)); if (error != CS_OK) { goto error_exit; @@ -1813,6 +1809,3 @@ error_exit: return (error); } -/** - * @} - */ diff --git a/lib/coroipcc.c b/lib/coroipcc.c deleted file mode 100644 index 14860e2d..00000000 --- a/lib/coroipcc.c +++ /dev/null @@ -1,1174 +0,0 @@ -/* - * vi: set autoindent tabstop=4 shiftwidth=4 : - * - * Copyright (c) 2002-2006 MontaVista Software, Inc. - * Copyright (c) 2006-2009 Red Hat, Inc. - * - * All rights reserved. - * - * Author: Steven Dake (sdake@redhat.com) - * - * 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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#if _POSIX_THREAD_PROCESS_SHARED > 0 -#include -#else -#include -#endif - -#include "util.h" - -struct ipc_instance { - int fd; - struct control_buffer *control_buffer; - char *request_buffer; - char *response_buffer; - char *dispatch_buffer; - size_t control_size; - size_t request_size; - size_t response_size; - size_t dispatch_size; - uid_t euid; - pthread_mutex_t mutex; -}; - -void ipc_hdb_destructor (void *context); - -DECLARE_HDB_DATABASE(ipc_hdb,ipc_hdb_destructor); - -#if defined(COROSYNC_LINUX) || defined(COROSYNC_SOLARIS) -#define COROSYNC_SUN_LEN(a) sizeof(*(a)) -#else -#define COROSYNC_SUN_LEN(a) SUN_LEN(a) -#endif - -#ifdef SO_NOSIGPIPE -static void socket_nosigpipe(int s) -{ - int on = 1; - setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (void *)&on, sizeof(on)); -} -#endif - -#ifndef MSG_NOSIGNAL -#define MSG_NOSIGNAL 0 -#endif - -static inline int shared_mem_dispatch_bytes_left (struct ipc_instance *context) -{ - unsigned int n_read; - unsigned int n_write; - unsigned int bytes_left; - - n_read = context->control_buffer->read; - n_write = context->control_buffer->write; - - if (n_read <= n_write) { - bytes_left = context->dispatch_size - n_write + n_read; - } else { - bytes_left = n_read - n_write; - } - return (bytes_left); -} - -static cs_error_t -socket_send ( - int s, - void *msg, - size_t len) -{ - cs_error_t res = CS_OK; - int result; - struct msghdr msg_send; - struct iovec iov_send; - char *rbuf = msg; - int processed = 0; - - msg_send.msg_iov = &iov_send; - msg_send.msg_iovlen = 1; - msg_send.msg_name = 0; - msg_send.msg_namelen = 0; - -#if !defined(COROSYNC_SOLARIS) - msg_send.msg_control = 0; - msg_send.msg_controllen = 0; - msg_send.msg_flags = 0; -#else - msg_send.msg_accrights = NULL; - msg_send.msg_accrightslen = 0; -#endif - -retry_send: - iov_send.iov_base = &rbuf[processed]; - iov_send.iov_len = len - processed; - - result = sendmsg (s, &msg_send, MSG_NOSIGNAL); - if (result == -1) { - switch (errno) { - case EINTR: - res = CS_ERR_TRY_AGAIN; - goto res_exit; - case EAGAIN: - goto retry_send; - break; - default: - res = CS_ERR_LIBRARY; - goto res_exit; - } - } - - processed += result; - if (processed != len) { - goto retry_send; - } - - return (CS_OK); - -res_exit: - return (res); -} - -static cs_error_t -socket_recv ( - int s, - void *msg, - size_t len) -{ - cs_error_t res = CS_OK; - int result; - struct msghdr msg_recv; - struct iovec iov_recv; - char *rbuf = msg; - int processed = 0; - - msg_recv.msg_iov = &iov_recv; - msg_recv.msg_iovlen = 1; - msg_recv.msg_name = 0; - msg_recv.msg_namelen = 0; -#if !defined (COROSYNC_SOLARIS) - msg_recv.msg_control = 0; - msg_recv.msg_controllen = 0; - msg_recv.msg_flags = 0; -#else - msg_recv.msg_accrights = NULL; - msg_recv.msg_accrightslen = 0; -#endif - - -retry_recv: - iov_recv.iov_base = (void *)&rbuf[processed]; - iov_recv.iov_len = len - processed; - - result = recvmsg (s, &msg_recv, MSG_NOSIGNAL|MSG_WAITALL); - if (result == -1) { - switch (errno) { - case EINTR: - res = CS_ERR_TRY_AGAIN; - goto res_exit; - case EAGAIN: - goto retry_recv; - break; - default: - res = CS_ERR_LIBRARY; - goto res_exit; - } - } - /* - * EOF is also detected when recvmsg return 0. - */ - if (result == 0) { - res = CS_ERR_LIBRARY; - goto res_exit; - } - - processed += result; - if (processed != len) { - goto retry_recv; - } - assert (processed == len); -res_exit: - return (res); -} - -static int -priv_change_send (struct ipc_instance *ipc_instance) -{ -#if _POSIX_THREAD_PROCESS_SHARED < 1 - char buf_req; - mar_req_priv_change req_priv_change; - unsigned int res; - - req_priv_change.euid = geteuid(); - /* - * Don't resend request unless euid has changed - */ - if (ipc_instance->euid == req_priv_change.euid) { - return (0); - } - req_priv_change.egid = getegid(); - - buf_req = MESSAGE_REQ_CHANGE_EUID; - res = socket_send (ipc_instance->fd, &buf_req, 1); - if (res == -1) { - return (-1); - } - - res = socket_send (ipc_instance->fd, &req_priv_change, - sizeof (req_priv_change)); - if (res == -1) { - return (-1); - } - - ipc_instance->euid = req_priv_change.euid; -#else - ipc_instance = NULL; -#endif - return (0); -} - -static int -circular_memory_map (char *path, const char *file, void **buf, size_t bytes) -{ - int32_t fd; - void *addr_orig; - void *addr; - int32_t res; - int32_t i; - int32_t written; - char *buffer; - long page_size; - - snprintf (path, PATH_MAX, "/dev/shm/%s", file); - - fd = mkstemp (path); - if (fd == -1) { - snprintf (path, PATH_MAX, LOCALSTATEDIR "/run/%s", file); - fd = mkstemp (path); - if (fd == -1) { - return (-1); - } - } - - res = ftruncate (fd, bytes); - if (res == -1) { - goto error_close_unlink; - } - - page_size = sysconf(_SC_PAGESIZE); - if (page_size == -1) { - goto error_close_unlink; - } - - buffer = malloc (page_size); - if (buffer == NULL) { - goto error_close_unlink; - } - memset (buffer, 0, page_size); - for (i = 0; i < (bytes / page_size); i++) { -retry_write: - written = write (fd, buffer, page_size); - if (written == -1 && errno == EINTR) { - goto retry_write; - } - if (written != page_size) { - free (buffer); - goto error_close_unlink; - } - } - free (buffer); - - addr_orig = mmap (NULL, bytes << 1, PROT_NONE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - - if (addr_orig == MAP_FAILED) { - goto error_close_unlink; - } - - addr = mmap (addr_orig, bytes, PROT_READ | PROT_WRITE, - MAP_FIXED | MAP_SHARED, fd, 0); - - if (addr != addr_orig) { - goto error_close_unlink; - } -#ifdef COROSYNC_BSD - madvise(addr_orig, bytes, MADV_NOSYNC); -#endif - - addr = mmap (((char *)addr_orig) + bytes, - bytes, PROT_READ | PROT_WRITE, - MAP_FIXED | MAP_SHARED, fd, 0); - if (addr == MAP_FAILED) { - goto error_close_unlink; - } -#ifdef COROSYNC_BSD - madvise(((char *)addr_orig) + bytes, bytes, MADV_NOSYNC); -#endif - - res = close (fd); - if (res) { - return (-1); - } - *buf = addr_orig; - return (0); - -error_close_unlink: - close (fd); - unlink(path); - return (-1); -} - -static void -memory_unmap (void *addr, size_t bytes) -{ - (void)munmap (addr, bytes); -} - -void ipc_hdb_destructor (void *context ) { - struct ipc_instance *ipc_instance = (struct ipc_instance *)context; - - /* - * << 1 (or multiplied by 2) because this is a wrapped memory buffer - */ - memory_unmap (ipc_instance->control_buffer, ipc_instance->control_size); - memory_unmap (ipc_instance->request_buffer, ipc_instance->request_size); - memory_unmap (ipc_instance->response_buffer, ipc_instance->response_size); - memory_unmap (ipc_instance->dispatch_buffer, (ipc_instance->dispatch_size) << 1); -} - -static int -memory_map (char *path, const char *file, void **buf, size_t bytes) -{ - int32_t fd; - void *addr_orig; - void *addr; - int32_t res; - char *buffer; - int32_t i; - int32_t written; - long page_size; - - snprintf (path, PATH_MAX, "/dev/shm/%s", file); - - fd = mkstemp (path); - if (fd == -1) { - snprintf (path, PATH_MAX, LOCALSTATEDIR "/run/%s", file); - fd = mkstemp (path); - if (fd == -1) { - return (-1); - } - } - - res = ftruncate (fd, bytes); - if (res == -1) { - goto error_close_unlink; - } - page_size = sysconf(_SC_PAGESIZE); - if (page_size == -1) { - goto error_close_unlink; - } - - buffer = malloc (page_size); - if (buffer == NULL) { - goto error_close_unlink; - } - memset (buffer, 0, page_size); - for (i = 0; i < (bytes / page_size); i++) { -retry_write: - written = write (fd, buffer, page_size); - if (written == -1 && errno == EINTR) { - goto retry_write; - } - if (written != page_size) { - free (buffer); - goto error_close_unlink; - } - } - free (buffer); - - addr_orig = mmap (NULL, bytes, PROT_NONE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - - if (addr_orig == MAP_FAILED) { - goto error_close_unlink; - } - - addr = mmap (addr_orig, bytes, PROT_READ | PROT_WRITE, - MAP_FIXED | MAP_SHARED, fd, 0); - - if (addr != addr_orig) { - goto error_close_unlink; - } -#ifdef COROSYNC_BSD - madvise(addr_orig, bytes, MADV_NOSYNC); -#endif - - res = close (fd); - if (res) { - return (-1); - } - *buf = addr_orig; - - return 0; - -error_close_unlink: - close (fd); - unlink(path); - return -1; -} - -static cs_error_t -msg_send ( - struct ipc_instance *ipc_instance, - const struct iovec *iov, - unsigned int iov_len) -{ - int i; - int res; - int req_buffer_idx = 0; - - for (i = 0; i < iov_len; i++) { - if ((req_buffer_idx + iov[i].iov_len) > - ipc_instance->request_size) { - return (CS_ERR_INVALID_PARAM); - } - memcpy (&ipc_instance->request_buffer[req_buffer_idx], - iov[i].iov_base, - iov[i].iov_len); - req_buffer_idx += iov[i].iov_len; - } - - /* - * Signal semaphore #3 and #0 indicting a new message from client - * to server request queue - */ - res = ipc_sem_post (ipc_instance->control_buffer, SEMAPHORE_REQUEST); - if (res != CS_OK) { - return (CS_ERR_LIBRARY); - } - res = ipc_sem_post (ipc_instance->control_buffer, SEMAPHORE_REQUEST_OR_FLUSH_OR_EXIT); - if (res != CS_OK) { - return (CS_ERR_LIBRARY); - } - return (CS_OK); -} - -static cs_error_t -reply_receive ( - struct ipc_instance *ipc_instance, - void *res_msg, - size_t res_len) -{ - coroipc_response_header_t *response_header; - cs_error_t res; - -retry_ipc_sem_wait: - res = ipc_sem_wait (ipc_instance->control_buffer, SEMAPHORE_RESPONSE, ipc_instance->fd); - if (res != CS_OK) { - if (res == CS_ERR_TRY_AGAIN) { - priv_change_send (ipc_instance); - goto retry_ipc_sem_wait; - } else { - return (res); - } - } - - response_header = (coroipc_response_header_t *)ipc_instance->response_buffer; - if (response_header->error == CS_ERR_TRY_AGAIN) { - return (CS_ERR_TRY_AGAIN); - } - - memcpy (res_msg, ipc_instance->response_buffer, res_len); - return (CS_OK); -} - -static cs_error_t -reply_receive_in_buf ( - struct ipc_instance *ipc_instance, - void **res_msg) -{ - cs_error_t res; - -retry_ipc_sem_wait: - res = ipc_sem_wait (ipc_instance->control_buffer, SEMAPHORE_RESPONSE, ipc_instance->fd); - if (res != CS_OK) { - if (res == CS_ERR_TRY_AGAIN) { - priv_change_send (ipc_instance); - goto retry_ipc_sem_wait; - } else { - return (res); - } - } - - *res_msg = (char *)ipc_instance->response_buffer; - return (CS_OK); -} - -/* - * External API - */ -cs_error_t -coroipcc_service_connect ( - const char *socket_name, - unsigned int service, - size_t request_size, - size_t response_size, - size_t dispatch_size, - hdb_handle_t *handle) - -{ - int request_fd; - struct sockaddr_un address; - cs_error_t res; - struct ipc_instance *ipc_instance; -#if _POSIX_THREAD_PROCESS_SHARED < 1 - key_t semkey = 0; - union semun semun; -#endif - int sys_res; - mar_req_setup_t req_setup; - mar_res_setup_t res_setup; - char control_map_path[PATH_MAX]; - char request_map_path[PATH_MAX]; - char response_map_path[PATH_MAX]; - char dispatch_map_path[PATH_MAX]; - - res = hdb_error_to_cs (hdb_handle_create (&ipc_hdb, - sizeof (struct ipc_instance), handle)); - if (res != CS_OK) { - return (res); - } - - res = hdb_error_to_cs (hdb_handle_get (&ipc_hdb, *handle, (void **)&ipc_instance)); - if (res != CS_OK) { - return (res); - } - - res_setup.error = CS_ERR_LIBRARY; - -#if defined(COROSYNC_SOLARIS) - request_fd = socket (PF_UNIX, SOCK_STREAM, 0); -#else - request_fd = socket (PF_LOCAL, SOCK_STREAM, 0); -#endif - if (request_fd == -1) { - return (CS_ERR_LIBRARY); - } -#ifdef SO_NOSIGPIPE - socket_nosigpipe (request_fd); -#endif - - memset (&address, 0, sizeof (struct sockaddr_un)); - address.sun_family = AF_UNIX; -#if defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN) - address.sun_len = SUN_LEN(&address); -#endif - -#if defined(COROSYNC_LINUX) - sprintf (address.sun_path + 1, "%s", socket_name); -#else - sprintf (address.sun_path, "%s/%s", SOCKETDIR, socket_name); -#endif - sys_res = connect (request_fd, (struct sockaddr *)&address, - COROSYNC_SUN_LEN(&address)); - if (sys_res == -1) { - res = CS_ERR_TRY_AGAIN; - goto error_connect; - } - - sys_res = memory_map ( - control_map_path, - "control_buffer-XXXXXX", - (void *)&ipc_instance->control_buffer, - 8192); - if (sys_res == -1) { - res = CS_ERR_LIBRARY; - goto error_connect; - } - - sys_res = memory_map ( - request_map_path, - "request_buffer-XXXXXX", - (void *)&ipc_instance->request_buffer, - request_size); - if (sys_res == -1) { - res = CS_ERR_LIBRARY; - goto error_request_buffer; - } - - sys_res = memory_map ( - response_map_path, - "response_buffer-XXXXXX", - (void *)&ipc_instance->response_buffer, - response_size); - if (sys_res == -1) { - res = CS_ERR_LIBRARY; - goto error_response_buffer; - } - - sys_res = circular_memory_map ( - dispatch_map_path, - "dispatch_buffer-XXXXXX", - (void *)&ipc_instance->dispatch_buffer, - dispatch_size); - if (sys_res == -1) { - res = CS_ERR_LIBRARY; - goto error_dispatch_buffer; - } - -#if _POSIX_THREAD_PROCESS_SHARED > 0 - sem_init (&ipc_instance->control_buffer->sem_request_or_flush_or_exit, 1, 0); - sem_init (&ipc_instance->control_buffer->sem_request, 1, 0); - sem_init (&ipc_instance->control_buffer->sem_response, 1, 0); - sem_init (&ipc_instance->control_buffer->sem_dispatch, 1, 0); -#else -{ - int i; - - /* - * Allocate a semaphore segment - */ - while (1) { - semkey = random(); - ipc_instance->euid = geteuid (); - if ((ipc_instance->control_buffer->semid - = semget (semkey, 4, IPC_CREAT|IPC_EXCL|0600)) != -1) { - break; - } - /* - * EACCESS can be returned as non root user when opening a different - * users semaphore. - * - * EEXIST can happen when we are a root or nonroot user opening - * an existing shared memory segment for which we have access - */ - if (errno != EEXIST && errno != EACCES) { - res = CS_ERR_LIBRARY; - goto error_exit; - } - } - - for (i = 0; i < 4; i++) { - semun.val = 0; - sys_res = semctl (ipc_instance->control_buffer->semid, i, SETVAL, semun); - if (sys_res != 0) { - res = CS_ERR_LIBRARY; - goto error_exit; - } - } -} -#endif - - /* - * Initialize IPC setup message - */ - req_setup.service = service; - strcpy (req_setup.control_file, control_map_path); - strcpy (req_setup.request_file, request_map_path); - strcpy (req_setup.response_file, response_map_path); - strcpy (req_setup.dispatch_file, dispatch_map_path); - req_setup.control_size = 8192; - req_setup.request_size = request_size; - req_setup.response_size = response_size; - req_setup.dispatch_size = dispatch_size; - -#if _POSIX_THREAD_PROCESS_SHARED < 1 - req_setup.semkey = semkey; -#endif - - res = socket_send (request_fd, &req_setup, sizeof (mar_req_setup_t)); - if (res != CS_OK) { - goto error_exit; - } - res = socket_recv (request_fd, &res_setup, sizeof (mar_res_setup_t)); - if (res != CS_OK) { - goto error_exit; - } - - ipc_instance->fd = request_fd; - - if (res_setup.error == CS_ERR_TRY_AGAIN) { - res = res_setup.error; - goto error_exit; - } - - ipc_instance->control_size = 8192; - ipc_instance->request_size = request_size; - ipc_instance->response_size = response_size; - ipc_instance->dispatch_size = dispatch_size; - - pthread_mutex_init (&ipc_instance->mutex, NULL); - - hdb_handle_put (&ipc_hdb, *handle); - - return (res_setup.error); - -error_exit: -#if _POSIX_THREAD_PROCESS_SHARED < 1 - if (ipc_instance->control_buffer->semid > 0) - semctl (ipc_instance->control_buffer->semid, 0, IPC_RMID); -#endif - memory_unmap (ipc_instance->dispatch_buffer, dispatch_size); -error_dispatch_buffer: - memory_unmap (ipc_instance->response_buffer, response_size); -error_response_buffer: - memory_unmap (ipc_instance->request_buffer, request_size); -error_request_buffer: - memory_unmap (ipc_instance->control_buffer, 8192); -error_connect: - close (request_fd); - - hdb_handle_destroy (&ipc_hdb, *handle); - hdb_handle_put (&ipc_hdb, *handle); - - return (res); -} - -cs_error_t -coroipcc_service_disconnect ( - hdb_handle_t handle) -{ - cs_error_t res; - struct ipc_instance *ipc_instance; - - res = hdb_error_to_cs (hdb_handle_get (&ipc_hdb, handle, (void **)&ipc_instance)); - if (res != CS_OK) { - return (res); - } - - shutdown (ipc_instance->fd, SHUT_RDWR); - close (ipc_instance->fd); - hdb_handle_destroy (&ipc_hdb, handle); - hdb_handle_put (&ipc_hdb, handle); - return (CS_OK); -} - -cs_error_t -coroipcc_dispatch_flow_control_get ( - hdb_handle_t handle, - unsigned int *flow_control_state) -{ - struct ipc_instance *ipc_instance; - cs_error_t res; - - res = hdb_error_to_cs (hdb_handle_get (&ipc_hdb, handle, (void **)&ipc_instance)); - if (res != CS_OK) { - return (res); - } - - *flow_control_state = ipc_instance->control_buffer->flow_control_enabled; - - hdb_handle_put (&ipc_hdb, handle); - return (res); -} - -cs_error_t -coroipcc_fd_get ( - hdb_handle_t handle, - int *fd) -{ - struct ipc_instance *ipc_instance; - cs_error_t res; - - res = hdb_error_to_cs (hdb_handle_get (&ipc_hdb, handle, (void **)&ipc_instance)); - if (res != CS_OK) { - return (res); - } - - *fd = ipc_instance->fd; - - hdb_handle_put (&ipc_hdb, handle); - return (res); -} - -cs_error_t -coroipcc_dispatch_get ( - hdb_handle_t handle, - void **data, - int timeout) -{ - struct pollfd ufds; - int poll_events; - char buf; - struct ipc_instance *ipc_instance; - char *data_addr; - cs_error_t error = CS_OK; - int res; - - error = hdb_error_to_cs (hdb_handle_get (&ipc_hdb, handle, (void **)&ipc_instance)); - if (error != CS_OK) { - return (error); - } - - if (shared_mem_dispatch_bytes_left (ipc_instance) > (ipc_instance->dispatch_size/2)) { - /* - * Notify coroipcs to flush any pending dispatch messages - */ - res = ipc_sem_post (ipc_instance->control_buffer, SEMAPHORE_REQUEST_OR_FLUSH_OR_EXIT); - if (res != CS_OK) { - error = CS_ERR_LIBRARY; - goto error_put; - } - } - - *data = NULL; - - ufds.fd = ipc_instance->fd; - ufds.events = POLLIN; - ufds.revents = 0; - - poll_events = poll (&ufds, 1, timeout); - if (poll_events == -1 && errno == EINTR) { - error = CS_ERR_TRY_AGAIN; - goto error_put; - } else - if (poll_events == -1) { - error = CS_ERR_LIBRARY; - goto error_put; - } else - if (poll_events == 0) { - error = CS_ERR_TRY_AGAIN; - goto error_put; - } - if (poll_events == 1 && (ufds.revents & (POLLERR|POLLHUP))) { - error = CS_ERR_LIBRARY; - goto error_put; - } - - error = socket_recv (ipc_instance->fd, &buf, 1); -#if defined(COROSYNC_SOLARIS) || defined(COROSYNC_BSD) || defined(COROSYNC_DARWIN) - /* On many OS poll() never returns POLLHUP or POLLERR. - * EOF is detected when recvmsg() return 0. - */ - if ( error == CS_ERR_LIBRARY ) - goto error_put; -#endif - assert (error == CS_OK); - - if (shared_mem_dispatch_bytes_left (ipc_instance) > (ipc_instance->dispatch_size/2)) { - /* - * Notify coroipcs to flush any pending dispatch messages - */ - - res = ipc_sem_post (ipc_instance->control_buffer, SEMAPHORE_REQUEST_OR_FLUSH_OR_EXIT); - if (res != CS_OK) { - error = CS_ERR_LIBRARY; - goto error_put; - } - - - } - - data_addr = ipc_instance->dispatch_buffer; - - data_addr = &data_addr[ipc_instance->control_buffer->read]; - - *data = (void *)data_addr; - - return (CS_OK); -error_put: - hdb_handle_put (&ipc_hdb, handle); - return (error); -} - -cs_error_t -coroipcc_dispatch_put (hdb_handle_t handle) -{ - coroipc_response_header_t *header; - struct ipc_instance *ipc_instance; - cs_error_t res; - char *addr; - unsigned int read_idx; - - res = hdb_error_to_cs (hdb_handle_get_always (&ipc_hdb, handle, (void **)&ipc_instance)); - if (res != CS_OK) { - return (res); - } - -retry_ipc_sem_wait: - res = ipc_sem_wait (ipc_instance->control_buffer, SEMAPHORE_DISPATCH, ipc_instance->fd); - if (res != CS_OK) { - if (res == CS_ERR_TRY_AGAIN) { - priv_change_send (ipc_instance); - goto retry_ipc_sem_wait; - } else { - goto error_exit; - } - } - - addr = ipc_instance->dispatch_buffer; - - read_idx = ipc_instance->control_buffer->read; - header = (coroipc_response_header_t *) &addr[read_idx]; - ipc_instance->control_buffer->read = - ((read_idx + header->size + 7) & 0xFFFFFFF8) % - ipc_instance->dispatch_size; - - /* - * Put from dispatch get and also from this call's get - */ - res = CS_OK; - -error_exit: - hdb_handle_put (&ipc_hdb, handle); - hdb_handle_put (&ipc_hdb, handle); - - return (res); -} - -cs_error_t -coroipcc_msg_send_reply_receive ( - hdb_handle_t handle, - const struct iovec *iov, - unsigned int iov_len, - void *res_msg, - size_t res_len) -{ - cs_error_t res; - struct ipc_instance *ipc_instance; - - res = hdb_error_to_cs (hdb_handle_get (&ipc_hdb, handle, (void **)&ipc_instance)); - if (res != CS_OK) { - return (res); - } - - pthread_mutex_lock (&ipc_instance->mutex); - - res = msg_send (ipc_instance, iov, iov_len); - if (res != CS_OK) { - goto error_exit; - } - - res = reply_receive (ipc_instance, res_msg, res_len); - -error_exit: - pthread_mutex_unlock (&ipc_instance->mutex); - hdb_handle_put (&ipc_hdb, handle); - - return (res); -} - -cs_error_t -coroipcc_msg_send_reply_receive_in_buf_get ( - hdb_handle_t handle, - const struct iovec *iov, - unsigned int iov_len, - void **res_msg) -{ - unsigned int res; - struct ipc_instance *ipc_instance; - - res = hdb_error_to_cs (hdb_handle_get (&ipc_hdb, handle, (void **)&ipc_instance)); - if (res != CS_OK) { - return (res); - } - - pthread_mutex_lock (&ipc_instance->mutex); - - res = msg_send (ipc_instance, iov, iov_len); - if (res != CS_OK) { - goto error_exit; - } - - res = reply_receive_in_buf (ipc_instance, res_msg); - -error_exit: - pthread_mutex_unlock (&ipc_instance->mutex); - - return (res); -} - -cs_error_t -coroipcc_msg_send_reply_receive_in_buf_put ( - hdb_handle_t handle) -{ - unsigned int res; - struct ipc_instance *ipc_instance; - - res = hdb_error_to_cs (hdb_handle_get (&ipc_hdb, handle, (void **)&ipc_instance)); - if (res != CS_OK) { - return (res); - } - hdb_handle_put (&ipc_hdb, handle); - hdb_handle_put (&ipc_hdb, handle); - - return (res); -} - -cs_error_t -coroipcc_zcb_alloc ( - hdb_handle_t handle, - void **buffer, - size_t size, - size_t header_size) -{ - struct ipc_instance *ipc_instance; - void *buf = NULL; - char path[PATH_MAX]; - unsigned int res; - mar_req_coroipcc_zc_alloc_t req_coroipcc_zc_alloc; - coroipc_response_header_t res_coroipcs_zc_alloc; - size_t map_size; - struct iovec iovec; - struct coroipcs_zc_header *hdr; - - res = hdb_error_to_cs (hdb_handle_get (&ipc_hdb, handle, (void **)&ipc_instance)); - if (res != CS_OK) { - return (res); - } - map_size = size + header_size + sizeof (struct coroipcs_zc_header); - res = memory_map (path, "corosync_zerocopy-XXXXXX", &buf, map_size); - assert (res != -1); - - req_coroipcc_zc_alloc.header.size = sizeof (mar_req_coroipcc_zc_alloc_t); - req_coroipcc_zc_alloc.header.id = ZC_ALLOC_HEADER; - req_coroipcc_zc_alloc.map_size = map_size; - strcpy (req_coroipcc_zc_alloc.path_to_file, path); - - - iovec.iov_base = (void *)&req_coroipcc_zc_alloc; - iovec.iov_len = sizeof (mar_req_coroipcc_zc_alloc_t); - - res = coroipcc_msg_send_reply_receive ( - handle, - &iovec, - 1, - &res_coroipcs_zc_alloc, - sizeof (coroipc_response_header_t)); - - hdr = (struct coroipcs_zc_header *)buf; - hdr->map_size = map_size; - *buffer = ((char *)buf) + sizeof (struct coroipcs_zc_header); - - hdb_handle_put (&ipc_hdb, handle); - return (res); -} - -cs_error_t -coroipcc_zcb_free ( - hdb_handle_t handle, - void *buffer) -{ - struct ipc_instance *ipc_instance; - mar_req_coroipcc_zc_free_t req_coroipcc_zc_free; - coroipc_response_header_t res_coroipcs_zc_free; - struct iovec iovec; - unsigned int res; - struct coroipcs_zc_header *header = (struct coroipcs_zc_header *)((char *)buffer - sizeof (struct coroipcs_zc_header)); - - res = hdb_error_to_cs (hdb_handle_get (&ipc_hdb, handle, (void **)&ipc_instance)); - if (res != CS_OK) { - return (res); - } - - req_coroipcc_zc_free.header.size = sizeof (mar_req_coroipcc_zc_free_t); - req_coroipcc_zc_free.header.id = ZC_FREE_HEADER; - req_coroipcc_zc_free.map_size = header->map_size; - req_coroipcc_zc_free.server_address = header->server_address; - - iovec.iov_base = (void *)&req_coroipcc_zc_free; - iovec.iov_len = sizeof (mar_req_coroipcc_zc_free_t); - - res = coroipcc_msg_send_reply_receive ( - handle, - &iovec, - 1, - &res_coroipcs_zc_free, - sizeof (coroipc_response_header_t)); - - munmap ((void *)header, header->map_size); - - hdb_handle_put (&ipc_hdb, handle); - - return (res); -} - -cs_error_t -coroipcc_zcb_msg_send_reply_receive ( - hdb_handle_t handle, - void *msg, - void *res_msg, - size_t res_len) -{ - struct ipc_instance *ipc_instance; - mar_req_coroipcc_zc_execute_t req_coroipcc_zc_execute; - struct coroipcs_zc_header *hdr; - struct iovec iovec; - cs_error_t res; - - res = hdb_error_to_cs (hdb_handle_get (&ipc_hdb, handle, (void **)&ipc_instance)); - if (res != CS_OK) { - return (res); - } - hdr = (struct coroipcs_zc_header *)(((char *)msg) - sizeof (struct coroipcs_zc_header)); - - req_coroipcc_zc_execute.header.size = sizeof (mar_req_coroipcc_zc_execute_t); - req_coroipcc_zc_execute.header.id = ZC_EXECUTE_HEADER; - req_coroipcc_zc_execute.server_address = hdr->server_address; - - iovec.iov_base = (void *)&req_coroipcc_zc_execute; - iovec.iov_len = sizeof (mar_req_coroipcc_zc_execute_t); - - res = coroipcc_msg_send_reply_receive ( - handle, - &iovec, - 1, - res_msg, - res_len); - - hdb_handle_put (&ipc_hdb, handle); - return (res); -} diff --git a/lib/cpg.c b/lib/cpg.c index f61efde9..caf3efed 100644 --- a/lib/cpg.c +++ b/lib/cpg.c @@ -41,26 +41,29 @@ #include #include +#include #include #include #include #include +#include #include +#include + +#include +#include -#include -#include -#include -#include #include #include - +#include +#include #include #include #include "util.h" struct cpg_inst { - hdb_handle_t handle; + qb_ipcc_connection_t *c; int finalize; void *context; union { @@ -74,7 +77,7 @@ DECLARE_HDB_DATABASE(cpg_handle_t_db,NULL); struct cpg_iteration_instance_t { cpg_iteration_handle_t cpg_iteration_handle; - hdb_handle_t conn_handle; + qb_ipcc_connection_t *conn; hdb_handle_t executive_iteration_handle; struct list_head list; }; @@ -86,6 +89,17 @@ DECLARE_HDB_DATABASE(cpg_iteration_handle_t_db,NULL); * Internal (not visible by API) functions */ +static cs_error_t +coroipcc_msg_send_reply_receive ( + qb_ipcc_connection_t *c, + const struct iovec *iov, + unsigned int iov_len, + void *res_msg, + size_t res_len) +{ + return qb_to_cs_error(qb_ipcc_sendv_recv(c, iov, iov_len, res_msg, res_len, -1)); +} + static void cpg_iteration_instance_finalize (struct cpg_iteration_instance_t *cpg_iteration_instance) { list_del (&cpg_iteration_instance->list); @@ -157,14 +171,9 @@ cs_error_t cpg_model_initialize ( goto error_destroy; } - error = coroipcc_service_connect ( - COROSYNC_SOCKET_NAME, - CPG_SERVICE, - IPC_REQUEST_SIZE, - IPC_RESPONSE_SIZE, - IPC_DISPATCH_SIZE, - &cpg_inst->handle); - if (error != CS_OK) { + cpg_inst->c = qb_ipcc_connect ("cpg", IPC_REQUEST_SIZE); + if (cpg_inst->c == NULL) { + error = qb_to_cs_error(-errno); goto error_put_destroy; } @@ -235,13 +244,13 @@ cs_error_t cpg_finalize ( iov.iov_base = (void *)&req_lib_cpg_finalize; iov.iov_len = sizeof (struct req_lib_cpg_finalize); - error = coroipcc_msg_send_reply_receive (cpg_inst->handle, + error = coroipcc_msg_send_reply_receive (cpg_inst->c, &iov, 1, &res_lib_cpg_finalize, sizeof (struct res_lib_cpg_finalize)); - coroipcc_service_disconnect (cpg_inst->handle); + qb_ipcc_disconnect(cpg_inst->c); cpg_inst_finalize (cpg_inst, handle); hdb_handle_put (&cpg_handle_t_db, handle); @@ -261,7 +270,7 @@ cs_error_t cpg_fd_get ( return (error); } - error = coroipcc_fd_get (cpg_inst->handle, fd); + error = qb_to_cs_error (qb_ipcc_fd_get (cpg_inst->c, fd)); hdb_handle_put (&cpg_handle_t_db, handle); @@ -318,7 +327,7 @@ cs_error_t cpg_dispatch ( struct res_lib_cpg_deliver_callback *res_cpg_deliver_callback; struct res_lib_cpg_totem_confchg_callback *res_cpg_totem_confchg_callback; struct cpg_inst cpg_inst_copy; - coroipc_response_header_t *dispatch_data; + struct qb_ipc_response_header *dispatch_data; struct cpg_address member_list[CPG_MEMBERS_MAX]; struct cpg_address left_list[CPG_MEMBERS_MAX]; struct cpg_address joined_list[CPG_MEMBERS_MAX]; @@ -328,6 +337,8 @@ cs_error_t cpg_dispatch ( unsigned int i; struct cpg_ring_id ring_id; uint32_t totem_member_list[CPG_MEMBERS_MAX]; + int32_t errno_res; + char dispatch_buf[IPC_DISPATCH_SIZE]; error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst)); if (error != CS_OK) { @@ -342,11 +353,14 @@ cs_error_t cpg_dispatch ( timeout = 0; } + dispatch_data = (struct qb_ipc_response_header *)dispatch_buf; do { - error = coroipcc_dispatch_get ( - cpg_inst->handle, - (void **)&dispatch_data, + errno_res = qb_ipcc_event_recv ( + cpg_inst->c, + dispatch_buf, + IPC_DISPATCH_SIZE, timeout); + error = qb_to_cs_error (errno_res); if (error == CS_ERR_BAD_HANDLE) { error = CS_OK; goto error_put; @@ -369,7 +383,6 @@ cs_error_t cpg_dispatch ( * operate at the same time that cpgFinalize has been called. */ memcpy (&cpg_inst_copy, cpg_inst, sizeof (struct cpg_inst)); - switch (cpg_inst_copy.model_data.model) { case CPG_MODEL_V1: /* @@ -451,14 +464,12 @@ cs_error_t cpg_dispatch ( totem_member_list); break; default: - coroipcc_dispatch_put (cpg_inst->handle); error = CS_ERR_LIBRARY; goto error_put; break; } /* - switch (dispatch_data->id) */ break; /* case CPG_MODEL_V1 */ } /* - switch (cpg_inst_copy.model_data.model) */ - coroipcc_dispatch_put (cpg_inst->handle); /* * Determine if more messages should be processed @@ -481,7 +492,7 @@ cs_error_t cpg_join ( struct cpg_inst *cpg_inst; struct iovec iov[2]; struct req_lib_cpg_join req_lib_cpg_join; - struct res_lib_cpg_join res_lib_cpg_join; + struct res_lib_cpg_join response; error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst)); if (error != CS_OK) { @@ -507,15 +518,15 @@ cs_error_t cpg_join ( iov[0].iov_len = sizeof (struct req_lib_cpg_join); do { - error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov, 1, - &res_lib_cpg_join, sizeof (struct res_lib_cpg_join)); + error = coroipcc_msg_send_reply_receive (cpg_inst->c, iov, 1, + &response, sizeof (struct res_lib_cpg_join)); if (error != CS_OK) { goto error_exit; } - } while (res_lib_cpg_join.header.error == CPG_ERR_BUSY); + } while (response.header.error == CPG_ERR_BUSY); - error = res_lib_cpg_join.header.error; + error = response.header.error; error_exit: hdb_handle_put (&cpg_handle_t_db, handle); @@ -548,7 +559,7 @@ cs_error_t cpg_leave ( iov[0].iov_len = sizeof (struct req_lib_cpg_leave); do { - error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov, 1, + error = coroipcc_msg_send_reply_receive (cpg_inst->c, iov, 1, &res_lib_cpg_leave, sizeof (struct res_lib_cpg_leave)); if (error != CS_OK) { @@ -596,14 +607,14 @@ cs_error_t cpg_membership_get ( sizeof (struct cpg_name)); iov.iov_base = (void *)&req_lib_cpg_membership_get; - iov.iov_len = sizeof (coroipc_request_header_t); + iov.iov_len = sizeof (struct qb_ipc_request_header); do { - error = coroipcc_msg_send_reply_receive (cpg_inst->handle, &iov, 1, - &res_lib_cpg_membership_get, sizeof (res_lib_cpg_membership_get)); + error = coroipcc_msg_send_reply_receive (cpg_inst->c, &iov, 1, + &res_lib_cpg_membership_get, sizeof (res_lib_cpg_membership_get)); - if (error != CS_OK) { - goto error_exit; + if (error != CS_OK) { + goto error_exit; } } while (res_lib_cpg_membership_get.header.error == CPG_ERR_BUSY); @@ -641,13 +652,13 @@ cs_error_t cpg_local_get ( return (error); } - req_lib_cpg_local_get.header.size = sizeof (coroipc_request_header_t); + req_lib_cpg_local_get.header.size = sizeof (struct qb_ipc_request_header); req_lib_cpg_local_get.header.id = MESSAGE_REQ_CPG_LOCAL_GET; iov.iov_base = (void *)&req_lib_cpg_local_get; iov.iov_len = sizeof (struct req_lib_cpg_local_get); - error = coroipcc_msg_send_reply_receive (cpg_inst->handle, &iov, 1, + error = coroipcc_msg_send_reply_receive (cpg_inst->c, &iov, 1, &res_lib_cpg_local_get, sizeof (res_lib_cpg_local_get)); if (error != CS_OK) { @@ -675,19 +686,103 @@ cs_error_t cpg_flow_control_state_get ( if (error != CS_OK) { return (error); } - - error = coroipcc_dispatch_flow_control_get (cpg_inst->handle, (unsigned int *)flow_control_state); + *flow_control_state = CPG_FLOW_CONTROL_DISABLED; + error = CS_OK; hdb_handle_put (&cpg_handle_t_db, handle); return (error); } +static int +memory_map (char *path, const char *file, void **buf, size_t bytes) +{ + int32_t fd; + void *addr_orig; + void *addr; + int32_t res; + char *buffer; + int32_t i; + int32_t written; + long page_size; + + snprintf (path, PATH_MAX, "/dev/shm/%s", file); + + fd = mkstemp (path); + if (fd == -1) { + snprintf (path, PATH_MAX, LOCALSTATEDIR "/run/%s", file); + fd = mkstemp (path); + if (fd == -1) { + return (-1); + } + } + + res = ftruncate (fd, bytes); + if (res == -1) { + goto error_close_unlink; + } + page_size = sysconf(_SC_PAGESIZE); + buffer = malloc (page_size); + if (buffer == NULL) { + goto error_close_unlink; + } + memset (buffer, 0, page_size); + for (i = 0; i < (bytes / page_size); i++) { +retry_write: + written = write (fd, buffer, page_size); + if (written == -1 && errno == EINTR) { + goto retry_write; + } + if (written != page_size) { + free (buffer); + goto error_close_unlink; + } + } + free (buffer); + + addr_orig = mmap (NULL, bytes, PROT_NONE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + + if (addr_orig == MAP_FAILED) { + goto error_close_unlink; + } + + addr = mmap (addr_orig, bytes, PROT_READ | PROT_WRITE, + MAP_FIXED | MAP_SHARED, fd, 0); + + if (addr != addr_orig) { + goto error_close_unlink; + } +#ifdef COROSYNC_BSD + madvise(addr_orig, bytes, MADV_NOSYNC); +#endif + + res = close (fd); + if (res) { + return (-1); + } + *buf = addr_orig; + + return 0; + +error_close_unlink: + close (fd); + unlink(path); + return -1; +} + cs_error_t cpg_zcb_alloc ( cpg_handle_t handle, size_t size, void **buffer) { + void *buf = NULL; + char path[128]; + mar_req_coroipcc_zc_alloc_t req_coroipcc_zc_alloc; + struct qb_ipc_response_header res_coroipcs_zc_alloc; + size_t map_size; + struct iovec iovec; + struct coroipcs_zc_header *hdr; cs_error_t error; struct cpg_inst *cpg_inst; @@ -696,10 +791,27 @@ cs_error_t cpg_zcb_alloc ( return (error); } - error = coroipcc_zcb_alloc (cpg_inst->handle, - buffer, - size, - sizeof (struct req_lib_cpg_mcast)); + map_size = size + sizeof (struct req_lib_cpg_mcast) + sizeof (struct coroipcs_zc_header); + assert(memory_map (path, "corosync_zerocopy-XXXXXX", &buf, map_size) != -1); + + req_coroipcc_zc_alloc.header.size = sizeof (mar_req_coroipcc_zc_alloc_t); + req_coroipcc_zc_alloc.header.id = MESSAGE_REQ_CPG_ZC_ALLOC; + req_coroipcc_zc_alloc.map_size = map_size; + strcpy (req_coroipcc_zc_alloc.path_to_file, path); + + iovec.iov_base = (void *)&req_coroipcc_zc_alloc; + iovec.iov_len = sizeof (mar_req_coroipcc_zc_alloc_t); + + error = coroipcc_msg_send_reply_receive ( + cpg_inst->c, + &iovec, + 1, + &res_coroipcs_zc_alloc, + sizeof (struct qb_ipc_response_header)); + + hdr = (struct coroipcs_zc_header *)buf; + hdr->map_size = map_size; + *buffer = ((char *)buf) + sizeof (struct coroipcs_zc_header); hdb_handle_put (&cpg_handle_t_db, handle); *buffer = ((char *)*buffer) + sizeof (struct req_lib_cpg_mcast); @@ -713,13 +825,32 @@ cs_error_t cpg_zcb_free ( { cs_error_t error; struct cpg_inst *cpg_inst; + mar_req_coroipcc_zc_free_t req_coroipcc_zc_free; + struct qb_ipc_response_header res_coroipcs_zc_free; + struct iovec iovec; + struct coroipcs_zc_header *header = (struct coroipcs_zc_header *)((char *)buffer - sizeof (struct coroipcs_zc_header)); error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst)); if (error != CS_OK) { return (error); } - coroipcc_zcb_free (cpg_inst->handle, ((char *)buffer) - sizeof (struct req_lib_cpg_mcast)); + req_coroipcc_zc_free.header.size = sizeof (mar_req_coroipcc_zc_free_t); + req_coroipcc_zc_free.header.id = MESSAGE_REQ_CPG_ZC_FREE; + req_coroipcc_zc_free.map_size = header->map_size; + req_coroipcc_zc_free.server_address = header->server_address; + + iovec.iov_base = (void *)&req_coroipcc_zc_free; + iovec.iov_len = sizeof (mar_req_coroipcc_zc_free_t); + + error = coroipcc_msg_send_reply_receive ( + cpg_inst->c, + &iovec, + 1, + &res_coroipcs_zc_free, + sizeof (struct qb_ipc_response_header)); + + munmap ((void *)header, header->map_size); hdb_handle_put (&cpg_handle_t_db, handle); @@ -736,12 +867,14 @@ cs_error_t cpg_zcb_mcast_joined ( struct cpg_inst *cpg_inst; struct req_lib_cpg_mcast *req_lib_cpg_mcast; struct res_lib_cpg_mcast res_lib_cpg_mcast; + mar_req_coroipcc_zc_execute_t req_coroipcc_zc_execute; + struct coroipcs_zc_header *hdr; + struct iovec iovec; error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst)); if (error != CS_OK) { return (error); } - req_lib_cpg_mcast = (struct req_lib_cpg_mcast *)(((char *)msg) - sizeof (struct req_lib_cpg_mcast)); req_lib_cpg_mcast->header.size = sizeof (struct req_lib_cpg_mcast) + msg_len; @@ -750,11 +883,21 @@ cs_error_t cpg_zcb_mcast_joined ( req_lib_cpg_mcast->guarantee = guarantee; req_lib_cpg_mcast->msglen = msg_len; - error = coroipcc_zcb_msg_send_reply_receive ( - cpg_inst->handle, - req_lib_cpg_mcast, + hdr = (struct coroipcs_zc_header *)(((char *)req_lib_cpg_mcast) - sizeof (struct coroipcs_zc_header)); + + req_coroipcc_zc_execute.header.size = sizeof (mar_req_coroipcc_zc_execute_t); + req_coroipcc_zc_execute.header.id = MESSAGE_REQ_CPG_ZC_EXECUTE; + req_coroipcc_zc_execute.server_address = hdr->server_address; + + iovec.iov_base = (void *)&req_coroipcc_zc_execute; + iovec.iov_len = sizeof (mar_req_coroipcc_zc_execute_t); + + error = coroipcc_msg_send_reply_receive ( + cpg_inst->c, + &iovec, + 1, &res_lib_cpg_mcast, - sizeof (res_lib_cpg_mcast)); + sizeof(res_lib_cpg_mcast)); if (error != CS_OK) { goto error_exit; @@ -779,7 +922,6 @@ cs_error_t cpg_mcast_joined ( struct cpg_inst *cpg_inst; struct iovec iov[64]; struct req_lib_cpg_mcast req_lib_cpg_mcast; - struct res_lib_cpg_mcast res_lib_cpg_mcast; size_t msg_len = 0; error = hdb_error_to_cs (hdb_handle_get (&cpg_handle_t_db, handle, (void *)&cpg_inst)); @@ -802,16 +944,8 @@ cs_error_t cpg_mcast_joined ( iov[0].iov_len = sizeof (struct req_lib_cpg_mcast); memcpy (&iov[1], iovec, iov_len * sizeof (struct iovec)); - error = coroipcc_msg_send_reply_receive (cpg_inst->handle, iov, - iov_len + 1, &res_lib_cpg_mcast, sizeof (res_lib_cpg_mcast)); + error = qb_to_cs_error(qb_ipcc_sendv(cpg_inst->c, iov, iov_len + 1)); - if (error != CS_OK) { - goto error_exit; - } - - error = res_lib_cpg_mcast.header.error; - -error_exit: hdb_handle_put (&cpg_handle_t_db, handle); return (error); @@ -862,7 +996,7 @@ cs_error_t cpg_iteration_initialize( goto error_destroy; } - cpg_iteration_instance->conn_handle = cpg_inst->handle; + cpg_iteration_instance->conn = cpg_inst->c; list_init (&cpg_iteration_instance->list); @@ -876,7 +1010,7 @@ cs_error_t cpg_iteration_initialize( iov.iov_base = (void *)&req_lib_cpg_iterationinitialize; iov.iov_len = sizeof (struct req_lib_cpg_iterationinitialize); - error = coroipcc_msg_send_reply_receive (cpg_inst->handle, + error = coroipcc_msg_send_reply_receive (cpg_inst->c, &iov, 1, &res_lib_cpg_iterationinitialize, @@ -914,9 +1048,7 @@ cs_error_t cpg_iteration_next( cs_error_t error; struct cpg_iteration_instance_t *cpg_iteration_instance; struct req_lib_cpg_iterationnext req_lib_cpg_iterationnext; - struct res_lib_cpg_iterationnext *res_lib_cpg_iterationnext; - struct iovec iov; - void *return_address; + struct res_lib_cpg_iterationnext res_lib_cpg_iterationnext; if (description == NULL) { return CS_ERR_INVALID_PARAM; @@ -932,27 +1064,25 @@ cs_error_t cpg_iteration_next( req_lib_cpg_iterationnext.header.id = MESSAGE_REQ_CPG_ITERATIONNEXT; req_lib_cpg_iterationnext.iteration_handle = cpg_iteration_instance->executive_iteration_handle; - iov.iov_base = (void *)&req_lib_cpg_iterationnext; - iov.iov_len = sizeof (struct req_lib_cpg_iterationnext); - - error = coroipcc_msg_send_reply_receive_in_buf_get (cpg_iteration_instance->conn_handle, - &iov, - 1, - &return_address); - res_lib_cpg_iterationnext = return_address; + error = qb_to_cs_error (qb_ipcc_send (cpg_iteration_instance->conn, + &req_lib_cpg_iterationnext, + req_lib_cpg_iterationnext.header.size)); + if (error != CS_OK) { + goto error_put; + } + error = qb_to_cs_error (qb_ipcc_recv (cpg_iteration_instance->conn, + &res_lib_cpg_iterationnext, + sizeof(struct res_lib_cpg_iterationnext), -1)); if (error != CS_OK) { goto error_put; } marshall_from_mar_cpg_iteration_description_t( description, - &res_lib_cpg_iterationnext->description); + &res_lib_cpg_iterationnext.description); - error = res_lib_cpg_iterationnext->header.error; - - coroipcc_msg_send_reply_receive_in_buf_put( - cpg_iteration_instance->conn_handle); + error = res_lib_cpg_iterationnext.header.error; error_put: hdb_handle_put (&cpg_iteration_handle_t_db, handle); @@ -983,7 +1113,7 @@ cs_error_t cpg_iteration_finalize ( iov.iov_base = (void *)&req_lib_cpg_iterationfinalize; iov.iov_len = sizeof (struct req_lib_cpg_iterationfinalize); - error = coroipcc_msg_send_reply_receive (cpg_iteration_instance->conn_handle, + error = coroipcc_msg_send_reply_receive (cpg_iteration_instance->conn, &iov, 1, &res_lib_cpg_iterationfinalize, diff --git a/lib/evs.c b/lib/evs.c index 6d37ff79..50a4e6d8 100644 --- a/lib/evs.c +++ b/lib/evs.c @@ -47,10 +47,9 @@ #include #include +#include #include -#include -#include #include #include @@ -59,11 +58,8 @@ #include "util.h" -#undef MIN -#define MIN(x,y) ((x) < (y) ? (x) : (y)) - struct evs_inst { - hdb_handle_t handle; + qb_ipcc_connection_t *c; int finalize; evs_callbacks_t callbacks; void *context; @@ -105,13 +101,11 @@ evs_error_t evs_initialize ( goto error_destroy; } - error = coroipcc_service_connect ( - COROSYNC_SOCKET_NAME, - EVS_SERVICE, - IPC_REQUEST_SIZE, - IPC_RESPONSE_SIZE, - IPC_DISPATCH_SIZE, - &evs_inst->handle); + evs_inst->c = qb_ipcc_connect ("evs", IPC_REQUEST_SIZE); + if (evs_inst->c == NULL) { + error = qb_to_cs_error(-errno); + goto error_put_destroy; + } if (error != EVS_OK) { goto error_put_destroy; } @@ -153,7 +147,7 @@ evs_error_t evs_finalize ( evs_inst->finalize = 1; - coroipcc_service_disconnect (evs_inst->handle); + qb_ipcc_disconnect (evs_inst->c); hdb_handle_destroy (&evs_handle_t_db, handle); @@ -174,7 +168,7 @@ evs_error_t evs_fd_get ( return (error); } - coroipcc_fd_get (evs_inst->handle, fd); + qb_ipcc_fd_get (evs_inst->c, fd); hdb_handle_put (&evs_handle_t_db, handle); @@ -230,7 +224,8 @@ evs_error_t evs_dispatch ( struct res_evs_confchg_callback *res_evs_confchg_callback; struct res_evs_deliver_callback *res_evs_deliver_callback; evs_callbacks_t callbacks; - coroipc_response_header_t *dispatch_data; + struct qb_ipc_response_header *dispatch_data; + char dispatch_buf[IPC_DISPATCH_SIZE]; error = hdb_error_to_cs(hdb_handle_get (&evs_handle_t_db, handle, (void *)&evs_inst)); if (error != CS_OK) { @@ -245,11 +240,13 @@ evs_error_t evs_dispatch ( timeout = 0; } + dispatch_data = (struct qb_ipc_response_header *)dispatch_buf; do { - error = coroipcc_dispatch_get ( - evs_inst->handle, - (void **)&dispatch_data, - timeout); + error = qb_to_cs_error(qb_ipcc_event_recv ( + evs_inst->c, + dispatch_buf, + IPC_DISPATCH_SIZE, + timeout)); if (error == CS_ERR_BAD_HANDLE) { error = CS_OK; goto error_put; @@ -308,12 +305,10 @@ evs_error_t evs_dispatch ( break; default: - coroipcc_dispatch_put (evs_inst->handle); error = CS_ERR_LIBRARY; goto error_put; break; } - coroipcc_dispatch_put (evs_inst->handle); /* * Determine if more messages should be processed @@ -354,8 +349,8 @@ evs_error_t evs_join ( iov[1].iov_base = (void*) groups; /* cast away const */ iov[1].iov_len = (group_entries * sizeof (struct evs_group)); - error = coroipcc_msg_send_reply_receive (evs_inst->handle, iov, 2, - &res_lib_evs_join, sizeof (struct res_lib_evs_join)); + error = qb_to_cs_error(qb_ipcc_sendv_recv (evs_inst->c, iov, 2, + &res_lib_evs_join, sizeof (struct res_lib_evs_join), -1)); if (error != CS_OK) { goto error_exit; @@ -395,8 +390,8 @@ evs_error_t evs_leave ( iov[1].iov_base = (void *) groups; /* cast away const */ iov[1].iov_len = (group_entries * sizeof (struct evs_group)); - error = coroipcc_msg_send_reply_receive (evs_inst->handle, iov, 2, - &res_lib_evs_leave, sizeof (struct res_lib_evs_leave)); + error = qb_to_cs_error(qb_ipcc_sendv_recv (evs_inst->c, iov, 2, + &res_lib_evs_leave, sizeof (struct res_lib_evs_leave), -1)); if (error != CS_OK) { goto error_exit; @@ -444,10 +439,10 @@ evs_error_t evs_mcast_joined ( iov[0].iov_len = sizeof (struct req_lib_evs_mcast_joined); memcpy (&iov[1], iovec, iov_len * sizeof (struct iovec)); - error = coroipcc_msg_send_reply_receive (evs_inst->handle, iov, + error = qb_to_cs_error(qb_ipcc_sendv_recv (evs_inst->c, iov, iov_len + 1, &res_lib_evs_mcast_joined, - sizeof (struct res_lib_evs_mcast_joined)); + sizeof (struct res_lib_evs_mcast_joined), -1)); if (error != CS_OK) { goto error_exit; @@ -497,10 +492,10 @@ evs_error_t evs_mcast_groups ( iov[1].iov_len = (group_entries * sizeof (struct evs_group)); memcpy (&iov[2], iovec, iov_len * sizeof (struct iovec)); - error = coroipcc_msg_send_reply_receive (evs_inst->handle, iov, + error = qb_to_cs_error(qb_ipcc_sendv_recv (evs_inst->c, iov, iov_len + 2, &res_lib_evs_mcast_groups, - sizeof (struct res_lib_evs_mcast_groups)); + sizeof (struct res_lib_evs_mcast_groups), -1)); if (error != CS_OK) { goto error_exit; @@ -537,11 +532,11 @@ evs_error_t evs_membership_get ( iov.iov_base = (void *)&req_lib_evs_membership_get; iov.iov_len = sizeof (struct req_lib_evs_membership_get); - error = coroipcc_msg_send_reply_receive (evs_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv (evs_inst->c, &iov, 1, &res_lib_evs_membership_get, - sizeof (struct res_lib_evs_membership_get)); + sizeof (struct res_lib_evs_membership_get), -1)); if (error != CS_OK) { goto error_exit; @@ -555,7 +550,7 @@ evs_error_t evs_membership_get ( if (local_nodeid) { *local_nodeid = res_lib_evs_membership_get.local_nodeid; } - *member_list_entries = MIN (*member_list_entries, + *member_list_entries = QB_MIN (*member_list_entries, res_lib_evs_membership_get.member_list_entries); if (member_list) { memcpy (member_list, &res_lib_evs_membership_get.member_list, diff --git a/lib/libcfg.versions b/lib/libcfg.versions index 6b1a68ac..a87727c0 100644 --- a/lib/libcfg.versions +++ b/lib/libcfg.versions @@ -14,17 +14,4 @@ COROSYNC_CFG_0.82 { corosync_cfg_ring_reenable; corosync_cfg_service_load; corosync_cfg_service_unload; - - - local: - coroipcc_service_connect; - coroipcc_service_disconnect; - coroipcc_dispatch_flow_control_get; - coroipcc_fd_get; - coroipcc_dispatch_recv; - coroipcc_msg_send_reply_receive; - coroipcc_msg_send_reply_receive_in_buf; - coroipcc_zcb_alloc; - coroipcc_zcb_free; - coroipcc_zcb_msg_send_reply_receive; }; diff --git a/lib/libconfdb.versions b/lib/libconfdb.versions index fa4e97d2..588ce9fd 100644 --- a/lib/libconfdb.versions +++ b/lib/libconfdb.versions @@ -21,16 +21,4 @@ COROSYNC_CONFDB_1.0 { confdb_object_iter; confdb_key_iter_start; confdb_key_iter; - - local: - coroipcc_service_connect; - coroipcc_service_disconnect; - coroipcc_dispatch_flow_control_get; - coroipcc_fd_get; - coroipcc_dispatch_recv; - coroipcc_msg_send_reply_receive; - coroipcc_msg_send_reply_receive_in_buf; - coroipcc_zcb_alloc; - coroipcc_zcb_free; - coroipcc_zcb_msg_send_reply_receive; }; diff --git a/lib/libcoroipcc.versions b/lib/libcoroipcc.versions deleted file mode 100644 index de178646..00000000 --- a/lib/libcoroipcc.versions +++ /dev/null @@ -1,15 +0,0 @@ -# Version and symbol export for libcoroipcc.so - -COROSYNC_COROIPCC_3.0 { - global: - coroipcc_service_connect; - coroipcc_service_disconnect; - coroipcc_dispatch_flow_control_get; - coroipcc_fd_get; - coroipcc_dispatch_recv; - coroipcc_msg_send_reply_receive; - coroipcc_msg_send_reply_receive_in_buf; - coroipcc_zcb_alloc; - coroipcc_zcb_free; - coroipcc_zcb_msg_send_reply_receive; -}; diff --git a/lib/libcpg.versions b/lib/libcpg.versions index 21b0f0dd..93eeb529 100644 --- a/lib/libcpg.versions +++ b/lib/libcpg.versions @@ -14,16 +14,4 @@ COROSYNC_CPG_1.0 { cpg_context_set; cpg_zcb_alloc; cpg_zcb_free; - - local: - coroipcc_service_connect; - coroipcc_service_disconnect; - coroipcc_dispatch_flow_control_get; - coroipcc_fd_get; - coroipcc_dispatch_recv; - coroipcc_msg_send_reply_receive; - coroipcc_msg_send_reply_receive_in_buf; - coroipcc_zcb_alloc; - coroipcc_zcb_free; - coroipcc_zcb_msg_send_reply_receive; }; diff --git a/lib/libevs.versions b/lib/libevs.versions index e132c71f..abcaf50b 100644 --- a/lib/libevs.versions +++ b/lib/libevs.versions @@ -11,16 +11,4 @@ COROSYNC_EVS_2.0 { evs_mcast_joined; evs_mcast_groups; evs_membership_get; - - local: - coroipcc_service_connect; - coroipcc_service_disconnect; - coroipcc_dispatch_flow_control_get; - coroipcc_fd_get; - coroipcc_dispatch_recv; - coroipcc_msg_send_reply_receive; - coroipcc_msg_send_reply_receive_in_buf; - coroipcc_zcb_alloc; - coroipcc_zcb_free; - coroipcc_zcb_msg_send_reply_receive; }; diff --git a/lib/libpload.versions b/lib/libpload.versions index b8381ebf..b5cf01a9 100644 --- a/lib/libpload.versions +++ b/lib/libpload.versions @@ -3,16 +3,4 @@ COROSYNC_PLOAD_1.0 { global: pload_start; - - local: - coroipcc_service_connect; - coroipcc_service_disconnect; - coroipcc_dispatch_flow_control_get; - coroipcc_fd_get; - coroipcc_dispatch_recv; - coroipcc_msg_send_reply_receive; - coroipcc_msg_send_reply_receive_in_buf; - coroipcc_zcb_alloc; - coroipcc_zcb_free; - coroipcc_zcb_msg_send_reply_receive; }; diff --git a/lib/libquorum.versions b/lib/libquorum.versions index 6d5a7b69..b1f0a883 100644 --- a/lib/libquorum.versions +++ b/lib/libquorum.versions @@ -8,16 +8,4 @@ COROSYNC_QUORUM_1.0 { quorum_initialize; quorum_finalize; quorum_dispatch; - - local: - coroipcc_service_connect; - coroipcc_service_disconnect; - coroipcc_dispatch_flow_control_get; - coroipcc_fd_get; - coroipcc_dispatch_recv; - coroipcc_msg_send_reply_receive; - coroipcc_msg_send_reply_receive_in_buf; - coroipcc_zcb_alloc; - coroipcc_zcb_free; - coroipcc_zcb_msg_send_reply_receive; }; diff --git a/lib/libvotequorum.versions b/lib/libvotequorum.versions index b813926c..9ad0b5d1 100644 --- a/lib/libvotequorum.versions +++ b/lib/libvotequorum.versions @@ -17,16 +17,4 @@ COROSYNC_VOTEQUORUM_1.0 { votequorum_trackstop; votequorum_context_get; votequorum_context_set; - - local: - coroipcc_service_connect; - coroipcc_service_disconnect; - coroipcc_dispatch_flow_control_get; - coroipcc_fd_get; - coroipcc_dispatch_recv; - coroipcc_msg_send_reply_receive; - coroipcc_msg_send_reply_receive_in_buf; - coroipcc_zcb_alloc; - coroipcc_zcb_free; - coroipcc_zcb_msg_send_reply_receive; }; diff --git a/lib/pload.c b/lib/pload.c index 6aa82dc4..8f41e720 100644 --- a/lib/pload.c +++ b/lib/pload.c @@ -41,9 +41,9 @@ #include #include +#include + #include -#include -#include #include #include @@ -53,7 +53,7 @@ #include "util.h" struct pload_inst { - hdb_handle_t handle; + qb_ipcc_connection_t *c; unsigned int finalize; }; @@ -88,14 +88,9 @@ unsigned int pload_initialize ( goto error_destroy; } - error = coroipcc_service_connect ( - COROSYNC_SOCKET_NAME, - PLOAD_SERVICE, - IPC_REQUEST_SIZE, - IPC_RESPONSE_SIZE, - IPC_DISPATCH_SIZE, - &pload_inst->handle); - if (error != CS_OK) { + pload_inst->c = qb_ipcc_connect ("pload", IPC_REQUEST_SIZE); + if (pload_inst->c == NULL) { + error = qb_to_cs_error(-errno); goto error_put_destroy; } @@ -132,7 +127,7 @@ unsigned int pload_finalize ( pload_inst->finalize = 1; - coroipcc_service_disconnect(pload_inst->handle); + qb_ipcc_disconnect(pload_inst->c); (void)hdb_handle_destroy (&pload_handle_t_db, handle); @@ -153,7 +148,7 @@ unsigned int pload_fd_get ( return (error); } - coroipcc_fd_get (pload_inst->handle, fd); + qb_ipcc_fd_get (pload_inst->c, fd); (void)hdb_handle_put (&pload_handle_t_db, handle); @@ -186,11 +181,11 @@ unsigned int pload_start ( iov.iov_base = (char *)&req_lib_pload_start; iov.iov_len = sizeof (struct req_lib_pload_start); - error = coroipcc_msg_send_reply_receive(pload_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv(pload_inst->c, &iov, 1, &res_lib_pload_start, - sizeof (struct res_lib_pload_start)); + sizeof (struct res_lib_pload_start), -1)); if (error != CS_OK) { goto error_exit; diff --git a/lib/quorum.c b/lib/quorum.c index 136c5635..8fc7ef0f 100644 --- a/lib/quorum.c +++ b/lib/quorum.c @@ -44,9 +44,8 @@ #include #include +#include #include -#include -#include #include #include @@ -56,7 +55,7 @@ #include "util.h" struct quorum_inst { - hdb_handle_t handle; + qb_ipcc_connection_t *c; int finalize; const void *context; quorum_callbacks_t callbacks; @@ -81,14 +80,10 @@ cs_error_t quorum_initialize ( goto error_destroy; } - error = coroipcc_service_connect ( - COROSYNC_SOCKET_NAME, - QUORUM_SERVICE, - IPC_REQUEST_SIZE, - IPC_RESPONSE_SIZE, - IPC_DISPATCH_SIZE, - &quorum_inst->handle); - if (error != CS_OK) { + error = CS_OK; + quorum_inst->c = qb_ipcc_connect ("quorum", IPC_REQUEST_SIZE); + if (quorum_inst->c == NULL) { + error = qb_to_cs_error(-errno); goto error_put_destroy; } @@ -130,7 +125,7 @@ cs_error_t quorum_finalize ( quorum_inst->finalize = 1; - coroipcc_service_disconnect (quorum_inst->handle); + qb_ipcc_disconnect (quorum_inst->c); (void)hdb_handle_destroy (&quorum_handle_t_db, handle); @@ -146,7 +141,7 @@ cs_error_t quorum_getquorate ( cs_error_t error; struct quorum_inst *quorum_inst; struct iovec iov; - coroipc_request_header_t req; + struct qb_ipc_request_header req; struct res_lib_quorum_getquorate res_lib_quorum_getquorate; error = hdb_error_to_cs(hdb_handle_get (&quorum_handle_t_db, handle, (void *)&quorum_inst)); @@ -160,12 +155,12 @@ cs_error_t quorum_getquorate ( iov.iov_base = (char *)&req; iov.iov_len = sizeof (req); - error = coroipcc_msg_send_reply_receive ( - quorum_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv ( + quorum_inst->c, &iov, 1, &res_lib_quorum_getquorate, - sizeof (struct res_lib_quorum_getquorate)); + sizeof (struct res_lib_quorum_getquorate), -1)); if (error != CS_OK) { goto error_exit; @@ -193,7 +188,7 @@ cs_error_t quorum_fd_get ( return (error); } - error = coroipcc_fd_get (quorum_inst->handle, fd); + error = qb_to_cs_error(qb_ipcc_fd_get (quorum_inst->c, fd)); (void)hdb_handle_put (&quorum_handle_t_db, handle); @@ -248,7 +243,7 @@ cs_error_t quorum_trackstart ( struct quorum_inst *quorum_inst; struct iovec iov; struct req_lib_quorum_trackstart req_lib_quorum_trackstart; - coroipc_response_header_t res; + struct qb_ipc_response_header res; error = hdb_error_to_cs(hdb_handle_get (&quorum_handle_t_db, handle, (void *)&quorum_inst)); if (error != CS_OK) { @@ -262,12 +257,12 @@ cs_error_t quorum_trackstart ( iov.iov_base = (char *)&req_lib_quorum_trackstart; iov.iov_len = sizeof (struct req_lib_quorum_trackstart); - error = coroipcc_msg_send_reply_receive ( - quorum_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv ( + quorum_inst->c, &iov, 1, &res, - sizeof (res)); + sizeof (res), -1)); if (error != CS_OK) { goto error_exit; @@ -287,8 +282,8 @@ cs_error_t quorum_trackstop ( cs_error_t error; struct quorum_inst *quorum_inst; struct iovec iov; - coroipc_request_header_t req; - coroipc_response_header_t res; + struct qb_ipc_request_header req; + struct qb_ipc_response_header res; error = hdb_error_to_cs(hdb_handle_get (&quorum_handle_t_db, handle, (void *)&quorum_inst)); if (error != CS_OK) { @@ -301,12 +296,12 @@ cs_error_t quorum_trackstop ( iov.iov_base = (char *)&req; iov.iov_len = sizeof (req); - error = coroipcc_msg_send_reply_receive ( - quorum_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv ( + quorum_inst->c, &iov, 1, &res, - sizeof (res)); + sizeof (res), -1)); if (error != CS_OK) { goto error_exit; @@ -329,7 +324,8 @@ cs_error_t quorum_dispatch ( int cont = 1; /* always continue do loop except when set to 0 */ struct quorum_inst *quorum_inst; quorum_callbacks_t callbacks; - coroipc_response_header_t *dispatch_data; + struct qb_ipc_response_header *dispatch_data; + char dispatch_buf[IPC_DISPATCH_SIZE]; struct res_lib_quorum_notification *res_lib_quorum_notification; if (dispatch_types != CS_DISPATCH_ONE && @@ -353,11 +349,13 @@ cs_error_t quorum_dispatch ( timeout = 0; } + dispatch_data = (struct qb_ipc_response_header *)dispatch_buf; do { - error = coroipcc_dispatch_get ( - quorum_inst->handle, - (void **)&dispatch_data, - timeout); + error = qb_to_cs_error (qb_ipcc_event_recv ( + quorum_inst->c, + dispatch_buf, + IPC_DISPATCH_SIZE, + timeout)); if (error == CS_ERR_BAD_HANDLE) { error = CS_OK; goto error_put; @@ -399,12 +397,10 @@ cs_error_t quorum_dispatch ( break; default: - coroipcc_dispatch_put (quorum_inst->handle); error = CS_ERR_LIBRARY; goto error_put; break; } - coroipcc_dispatch_put (quorum_inst->handle); /* * Determine if more messages should be processed diff --git a/lib/sa-confdb.c b/lib/sa-confdb.c index 03995e34..bd97234f 100644 --- a/lib/sa-confdb.c +++ b/lib/sa-confdb.c @@ -45,7 +45,7 @@ #include #include -#include +#include #include #include #include diff --git a/lib/sam.c b/lib/sam.c index 6bf644e6..50092641 100644 --- a/lib/sam.c +++ b/lib/sam.c @@ -48,8 +48,7 @@ #include #include -#include -#include +#include #include #include #include diff --git a/lib/util.h b/lib/util.h index c228b423..1d86debd 100644 --- a/lib/util.h +++ b/lib/util.h @@ -36,28 +36,9 @@ #ifndef AIS_UTIL_H_DEFINED #define AIS_UTIL_H_DEFINED -#include +#include -static inline cs_error_t hdb_error_to_cs (int res) \ -{ \ - if (res == 0) { \ - return (CS_OK); \ - } else { \ - if (errno == EBADF) { \ - return (CS_ERR_BAD_HANDLE); \ - } else \ - if (errno == ENOMEM) { \ - return (CS_ERR_NO_MEMORY); \ - } else \ - if (errno == EMFILE) { \ - return (CS_ERR_NO_RESOURCES); \ - } else \ - if (errno == EACCES) { \ - return (CS_ERR_SECURITY); \ - } \ - return (CS_ERR_LIBRARY); \ - } \ -} +#define hdb_error_to_cs(_result_) qb_to_cs_error(-_result_) #ifdef HAVE_SMALL_MEMORY_FOOTPRINT #define IPC_REQUEST_SIZE 1024*64 @@ -69,4 +50,103 @@ static inline cs_error_t hdb_error_to_cs (int res) \ #define IPC_DISPATCH_SIZE 8192*128 #endif /* HAVE_SMALL_MEMORY_FOOTPRINT */ +static inline const char * cs_strerror(cs_error_t err) +{ + switch (err) { + case CS_OK: + return "success"; + + case CS_ERR_LIBRARY: + return "CS_ERR_LIBRARY"; + + case CS_ERR_VERSION: + return "CS_ERR_VERSION"; + + case CS_ERR_INIT: + return "CS_ERR_INIT"; + + case CS_ERR_NO_MEMORY: + return "CS_ERR_NO_MEMORY"; + + case CS_ERR_NAME_TOO_LONG : + return "CS_ERR_NAME_TOO_LONG "; + + case CS_ERR_TIMEOUT: + return "CS_ERR_TIMEOUT"; + + case CS_ERR_TRY_AGAIN: + return "CS_ERR_TRY_AGAIN"; + + case CS_ERR_INVALID_PARAM: + return "CS_ERR_INVALID_PARAM"; + + case CS_ERR_BAD_HANDLE: + return "CS_ERR_BAD_HANDLE"; + + case CS_ERR_BUSY : + return "CS_ERR_BUSY "; + + case CS_ERR_ACCESS : + return "CS_ERR_ACCESS "; + + case CS_ERR_NOT_EXIST : + return "CS_ERR_NOT_EXIST "; + + case CS_ERR_EXIST : + return "CS_ERR_EXIST "; + + case CS_ERR_NO_SPACE : + return "CS_ERR_NO_SPACE "; + + case CS_ERR_INTERRUPT : + return "CS_ERR_INTERRUPT "; + + case CS_ERR_NAME_NOT_FOUND : + return "CS_ERR_NAME_NOT_FOUND "; + + case CS_ERR_NO_RESOURCES : + return "CS_ERR_NO_RESOURCES "; + + case CS_ERR_NOT_SUPPORTED : + return "CS_ERR_NOT_SUPPORTED "; + + case CS_ERR_BAD_OPERATION : + return "CS_ERR_BAD_OPERATION "; + + case CS_ERR_FAILED_OPERATION : + return "CS_ERR_FAILED_OPERATION "; + + case CS_ERR_MESSAGE_ERROR : + return "CS_ERR_MESSAGE_ERROR "; + + case CS_ERR_QUEUE_FULL : + return "CS_ERR_QUEUE_FULL "; + + case CS_ERR_QUEUE_NOT_AVAILABLE : + return "CS_ERR_QUEUE_NOT_AVAILABLE "; + + case CS_ERR_BAD_FLAGS : + return "CS_ERR_BAD_FLAGS "; + + case CS_ERR_TOO_BIG : + return "CS_ERR_TOO_BIG "; + + case CS_ERR_NO_SECTIONS : + return "CS_ERR_NO_SECTIONS "; + + case CS_ERR_CONTEXT_NOT_FOUND : + return "CS_ERR_CONTEXT_NOT_FOUND "; + + case CS_ERR_TOO_MANY_GROUPS : + return "CS_ERR_TOO_MANY_GROUPS "; + + case CS_ERR_SECURITY : + return "CS_ERR_SECURITY "; + + default: + return "unknown error"; + } +} + + #endif /* AIS_UTIL_H_DEFINED */ diff --git a/lib/votequorum.c b/lib/votequorum.c index e235a2dd..35d2b5b6 100644 --- a/lib/votequorum.c +++ b/lib/votequorum.c @@ -45,10 +45,9 @@ #include #include +#include #include -#include -#include #include #include @@ -58,7 +57,7 @@ #include "util.h" struct votequorum_inst { - hdb_handle_t handle; + qb_ipcc_connection_t *c; int finalize; void *context; votequorum_callbacks_t callbacks; @@ -83,13 +82,11 @@ cs_error_t votequorum_initialize ( goto error_destroy; } - error = coroipcc_service_connect ( - COROSYNC_SOCKET_NAME, - VOTEQUORUM_SERVICE, - IPC_REQUEST_SIZE, - IPC_RESPONSE_SIZE, - IPC_DISPATCH_SIZE, - &votequorum_inst->handle); + votequorum_inst->c = qb_ipcc_connect ("votequorum", IPC_REQUEST_SIZE); + if (votequorum_inst->c == NULL) { + error = qb_to_cs_error(-errno); + goto error_put_destroy; + } if (error != CS_OK) { goto error_put_destroy; } @@ -132,7 +129,7 @@ cs_error_t votequorum_finalize ( votequorum_inst->finalize = 1; - coroipcc_service_disconnect (votequorum_inst->handle); + qb_ipcc_disconnect (votequorum_inst->c); hdb_handle_destroy (&votequorum_handle_t_db, handle); @@ -165,12 +162,12 @@ cs_error_t votequorum_getinfo ( iov.iov_base = (char *)&req_lib_votequorum_getinfo; iov.iov_len = sizeof (struct req_lib_votequorum_getinfo); - error = coroipcc_msg_send_reply_receive ( - votequorum_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv ( + votequorum_inst->c, &iov, 1, &res_lib_votequorum_getinfo, - sizeof (struct res_lib_votequorum_getinfo)); + sizeof (struct res_lib_votequorum_getinfo), -1)); if (error != CS_OK) { goto error_exit; @@ -215,12 +212,12 @@ cs_error_t votequorum_setexpected ( iov.iov_base = (char *)&req_lib_votequorum_setexpected; iov.iov_len = sizeof (struct req_lib_votequorum_setexpected); - error = coroipcc_msg_send_reply_receive ( - votequorum_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv ( + votequorum_inst->c, &iov, 1, &res_lib_votequorum_status, - sizeof (struct res_lib_votequorum_status)); + sizeof (struct res_lib_votequorum_status), -1)); if (error != CS_OK) { goto error_exit; @@ -258,12 +255,12 @@ cs_error_t votequorum_setvotes ( iov.iov_base = (char *)&req_lib_votequorum_setvotes; iov.iov_len = sizeof (struct req_lib_votequorum_setvotes); - error = coroipcc_msg_send_reply_receive ( - votequorum_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv ( + votequorum_inst->c, &iov, 1, &res_lib_votequorum_status, - sizeof (struct res_lib_votequorum_status)); + sizeof (struct res_lib_votequorum_status), -1)); if (error != CS_OK) { goto error_exit; @@ -305,12 +302,12 @@ cs_error_t votequorum_qdisk_register ( iov.iov_base = (char *)&req_lib_votequorum_qdisk_register; iov.iov_len = sizeof (struct req_lib_votequorum_qdisk_register); - error = coroipcc_msg_send_reply_receive ( - votequorum_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv ( + votequorum_inst->c, &iov, 1, &res_lib_votequorum_status, - sizeof (struct res_lib_votequorum_status)); + sizeof (struct res_lib_votequorum_status), -1)); if (error != CS_OK) { goto error_exit; @@ -347,12 +344,12 @@ cs_error_t votequorum_qdisk_poll ( iov.iov_base = (char *)&req_lib_votequorum_qdisk_poll; iov.iov_len = sizeof (struct req_lib_votequorum_qdisk_poll); - error = coroipcc_msg_send_reply_receive ( - votequorum_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv ( + votequorum_inst->c, &iov, 1, &res_lib_votequorum_status, - sizeof (struct res_lib_votequorum_status)); + sizeof (struct res_lib_votequorum_status), -1)); if (error != CS_OK) { goto error_exit; @@ -386,12 +383,12 @@ cs_error_t votequorum_qdisk_unregister ( iov.iov_base = (char *)&req_lib_votequorum_general; iov.iov_len = sizeof (struct req_lib_votequorum_general); - error = coroipcc_msg_send_reply_receive ( - votequorum_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv ( + votequorum_inst->c, &iov, 1, &res_lib_votequorum_status, - sizeof (struct res_lib_votequorum_status)); + sizeof (struct res_lib_votequorum_status), -1)); if (error != CS_OK) { goto error_exit; @@ -429,12 +426,12 @@ cs_error_t votequorum_qdisk_getinfo ( iov.iov_base = (char *)&req_lib_votequorum_general; iov.iov_len = sizeof (struct req_lib_votequorum_general); - error = coroipcc_msg_send_reply_receive ( - votequorum_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv ( + votequorum_inst->c, &iov, 1, &res_lib_votequorum_qdisk_getinfo, - sizeof (struct res_lib_votequorum_qdisk_getinfo)); + sizeof (struct res_lib_votequorum_qdisk_getinfo), -1)); if (error != CS_OK) { goto error_exit; @@ -473,12 +470,12 @@ cs_error_t votequorum_setstate ( iov.iov_base = (char *)&req_lib_votequorum_general; iov.iov_len = sizeof (struct req_lib_votequorum_general); - error = coroipcc_msg_send_reply_receive ( - votequorum_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv ( + votequorum_inst->c, &iov, 1, &res_lib_votequorum_status, - sizeof (struct res_lib_votequorum_status)); + sizeof (struct res_lib_votequorum_status), -1)); if (error != CS_OK) { goto error_exit; @@ -513,12 +510,12 @@ cs_error_t votequorum_leaving ( iov.iov_base = (char *)&req_lib_votequorum_general; iov.iov_len = sizeof (struct req_lib_votequorum_general); - error = coroipcc_msg_send_reply_receive ( - votequorum_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv ( + votequorum_inst->c, &iov, 1, &res_lib_votequorum_status, - sizeof (struct res_lib_votequorum_status)); + sizeof (struct res_lib_votequorum_status), -1)); if (error != CS_OK) { goto error_exit; @@ -556,12 +553,12 @@ cs_error_t votequorum_trackstart ( iov.iov_base = (char *)&req_lib_votequorum_trackstart; iov.iov_len = sizeof (struct req_lib_votequorum_trackstart); - error = coroipcc_msg_send_reply_receive ( - votequorum_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv ( + votequorum_inst->c, &iov, 1, &res_lib_votequorum_status, - sizeof (struct res_lib_votequorum_status)); + sizeof (struct res_lib_votequorum_status), -1)); if (error != CS_OK) { goto error_exit; @@ -595,12 +592,12 @@ cs_error_t votequorum_trackstop ( iov.iov_base = (char *)&req_lib_votequorum_general; iov.iov_len = sizeof (struct req_lib_votequorum_general); - error = coroipcc_msg_send_reply_receive ( - votequorum_inst->handle, + error = qb_to_cs_error(qb_ipcc_sendv_recv ( + votequorum_inst->c, &iov, 1, &res_lib_votequorum_status, - sizeof (struct res_lib_votequorum_status)); + sizeof (struct res_lib_votequorum_status), -1)); if (error != CS_OK) { goto error_exit; @@ -666,7 +663,7 @@ cs_error_t votequorum_fd_get ( return (error); } - error = coroipcc_fd_get (votequorum_inst->handle, fd); + error = qb_to_cs_error(qb_ipcc_fd_get (votequorum_inst->c, fd)); (void)hdb_handle_put (&votequorum_handle_t_db, handle); @@ -682,9 +679,10 @@ cs_error_t votequorum_dispatch ( int cont = 1; /* always continue do loop except when set to 0 */ struct votequorum_inst *votequorum_inst; votequorum_callbacks_t callbacks; - coroipc_response_header_t *dispatch_data; + struct qb_ipc_response_header *dispatch_data; struct res_lib_votequorum_notification *res_lib_votequorum_notification; struct res_lib_votequorum_expectedvotes_notification *res_lib_votequorum_expectedvotes_notification; + char dispatch_buf[IPC_DISPATCH_SIZE]; if (dispatch_types != CS_DISPATCH_ONE && dispatch_types != CS_DISPATCH_ALL && @@ -707,11 +705,13 @@ cs_error_t votequorum_dispatch ( timeout = 0; } + dispatch_data = (struct qb_ipc_response_header *)dispatch_buf; do { - error = coroipcc_dispatch_get ( - votequorum_inst->handle, - (void **)&dispatch_data, - timeout); + error = qb_to_cs_error (qb_ipcc_event_recv ( + votequorum_inst->c, + dispatch_buf, + IPC_DISPATCH_SIZE, + timeout)); if (error == CS_ERR_BAD_HANDLE) { error = CS_OK; goto error_put; @@ -766,12 +766,10 @@ cs_error_t votequorum_dispatch ( break; default: - coroipcc_dispatch_put (votequorum_inst->handle); error = CS_ERR_LIBRARY; goto error_put; break; } - coroipcc_dispatch_put (votequorum_inst->handle); /* * Determine if more messages should be processed diff --git a/man/Makefile.am b/man/Makefile.am index 33d15853..11e9aba1 100644 --- a/man/Makefile.am +++ b/man/Makefile.am @@ -52,9 +52,7 @@ dist_man_MANS = \ corosync_overview.8 \ cpg_overview.8 \ evs_overview.8 \ - logsys_overview.8 \ votequorum_overview.8 \ - coroipc_overview.8 \ confdb_dispatch.3 \ confdb_fd_get.3 \ confdb_finalize.3 \ diff --git a/man/logsys_overview.8 b/man/logsys_overview.8 index d8002283..fb2a26ae 100644 --- a/man/logsys_overview.8 +++ b/man/logsys_overview.8 @@ -32,7 +32,7 @@ .\" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF .\" * THE POSSIBILITY OF SUCH DAMAGE. .\" */ -.TH LOGSYS_OVERVIEW 8 2009-06-16 "corosync Man Page" "Corosync Cluster Engine Programmer's Manual" +.TH QB_LOGSYS_OVERVIEW 8 2009-06-16 "corosync Man Page" "Corosync Cluster Engine Programmer's Manual" .SH NAME logsys_overview \- Logsys Library Overview .SH OVERVIEW @@ -56,14 +56,14 @@ The logsys library is initially configured by including logsys.h and declaring a logger. Once the logger is declared, optional subsystem loggers can be declared in every file. -The definition LOGSYS_DECLARE_SYSTEM is placed after the include section of one +The definition QB_LOGSYS_DECLARE_SYSTEM is placed after the include section of one C file in the application. This declaration creates a constructor function which will be called automatically before main() is executed. This technique avoids the need for calling any setup functions in short applications that don't require it and enables full logging capabilities before any application code is executed. -#define LOGSYS_DECLARE_SYSTEM (name, mode, debug, file, file_priority, +#define QB_LOGSYS_DECLARE_SYSTEM (name, mode, debug, file, file_priority, syslog_facility, syslog_priority, format, fltsize) The name parameter is the name of the application or system. @@ -71,17 +71,17 @@ The name parameter is the name of the application or system. The mode parameter is the logging mode of the system. The following modes can be configured by logically ORing these flags: -LOGSYS_MODE_OUTPUT_FILE: Output all log data to the file parameter of this declaration +QB_LOGSYS_MODE_OUTPUT_FILE: Output all log data to the file parameter of this declaration -LOGSYS_MODE_OUTPUT_STDERR: Output all log data to the stderr descriptor +QB_LOGSYS_MODE_OUTPUT_STDERR: Output all log data to the stderr descriptor -LOGSYS_MODE_OUTPUT_SYSLOG: Output all log data to syslog using a non-blocking thread +QB_LOGSYS_MODE_OUTPUT_SYSLOG: Output all log data to syslog using a non-blocking thread -LOGSYS_MODE_FORK: This flags tells logsys to queue all data untill the application +QB_LOGSYS_MODE_FORK: This flags tells logsys to queue all data untill the application has forked. The application is then responsible to call logsys_fork_completed to flush the queue and start logging. -LOGSYS_MODE_THREADED: Starts a separate thread to handle non-blocking logging operations. +QB_LOGSYS_MODE_THREADED: Starts a separate thread to handle non-blocking logging operations. If this flag is not specified, the logging operations are blocking. The debug parameter, if enabled, turns off all messages priority filtering, recording @@ -110,13 +110,13 @@ An example declaration would be: ... (other #includes) -LOGSYS_DECLARE_SYSTEM ("test", /* name */ - LOGSYS_MODE_OUTPUT_STDERR | LOGSYS_MODE_THREADED, /* mode */ +QB_LOGSYS_DECLARE_SYSTEM ("test", /* name */ + QB_LOGSYS_MODE_OUTPUT_STDERR | QB_LOGSYS_MODE_THREADED, /* mode */ 0, /* debug */ NULL, /* logfile path */ - LOGSYS_LEVEL_INFO, /* logfile_priority */ + QB_LOGSYS_LEVEL_INFO, /* logfile_priority */ LOG_DAEMON, /* syslog facility */ - LOGSYS_LEVEL_INFO, /* syslog level */ + QB_LOGSYS_LEVEL_INFO, /* syslog level */ NULL, /* use default format */ 1000000); /* flight recorder size */ @@ -128,7 +128,7 @@ and it is entirely optional. An example: -LOGSYS_DECLARE_SUBSYS ("subsystest"); +QB_LOGSYS_DECLARE_SUBSYS ("subsystest"); It is possible to use the same subsystem name in separate object files. In this case, the individual logging parameters for those subsystem identifier @@ -144,18 +144,18 @@ throught the configuration API. The definition log_printf is used to log information to the log. It works in a similiar fashion to printf, except it has a first parameter of level which may be the following: -LOGSYS_LEVEL_EMERG -LOGSYS_LEVEL_ALERT -LOGSYS_LEVEL_CRIT -LOGSYS_LEVEL_ERR -LOGSYS_LEVEL_WARNING -LOGSYS_LEVEL_NOTICE -LOGSYS_LEVEL_INFO -LOGSYS_LEVEL_DEBUG +QB_LOGSYS_LEVEL_EMERG +QB_LOGSYS_LEVEL_ALERT +QB_LOGSYS_LEVEL_CRIT +QB_LOGSYS_LEVEL_ERR +QB_LOGSYS_LEVEL_WARNING +QB_LOGSYS_LEVEL_NOTICE +QB_LOGSYS_LEVEL_INFO +QB_LOGSYS_LEVEL_DEBUG An example of using log_printf would be -log_printf (LOGSYS_LEVEL_EMERG, "This is an emergency %s value %d\n", string, value); +log_printf (QB_LOGSYS_LEVEL_EMERG, "This is an emergency %s value %d\n", string, value); Tracing of functions can be done using ENTER(), LEAVE(); diff --git a/pkgconfig/Makefile.am b/pkgconfig/Makefile.am index cc9abf1c..24141990 100644 --- a/pkgconfig/Makefile.am +++ b/pkgconfig/Makefile.am @@ -32,7 +32,7 @@ MAINTAINERCLEANFILES = Makefile.in EXTRA_DIST = libtemplate.pc.in corosync.pc.in -LIBS = cfg confdb coroipcc coroipcs cpg evs logsys pload quorum \ +LIBS = cfg confdb cpg evs pload quorum \ totem_pg votequorum sam target_LIBS = $(LIBS:%=lib%.pc) diff --git a/services/cfg.c b/services/cfg.c index b7aa63b4..eafa559a 100644 --- a/services/cfg.c +++ b/services/cfg.c @@ -48,9 +48,10 @@ #include #include #include +#include #include -#include +#include #include #include #include @@ -329,23 +330,23 @@ __attribute__ ((constructor)) static void corosync_lcr_component_register (void) } struct req_exec_cfg_ringreenable { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_message_source_t source __attribute__((aligned(8))); }; struct req_exec_cfg_killnode { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint32_t nodeid __attribute__((aligned(8))); mar_name_t reason __attribute__((aligned(8))); }; struct req_exec_cfg_crypto_set { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint32_t type __attribute__((aligned(8))); }; struct req_exec_cfg_shutdown { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); }; /* IMPL */ diff --git a/services/confdb.c b/services/confdb.c index baa9ec85..f70f2efd 100644 --- a/services/confdb.c +++ b/services/confdb.c @@ -41,9 +41,10 @@ #include #include #include +#include #include -#include +#include #include #include #include @@ -411,7 +412,7 @@ static void message_handler_req_lib_confdb_object_destroy (void *conn, { const struct req_lib_confdb_object_destroy *req_lib_confdb_object_destroy = message; - coroipc_response_header_t res; + struct qb_ipc_response_header res; int ret = CS_OK; if (api->object_destroy(req_lib_confdb_object_destroy->object_handle)) @@ -428,7 +429,7 @@ static void message_handler_req_lib_confdb_object_find_destroy (void *conn, { const struct req_lib_confdb_object_find_destroy *req_lib_confdb_object_find_destroy = message; - coroipc_response_header_t res; + struct qb_ipc_response_header res; int ret = CS_OK; if (api->object_find_destroy(req_lib_confdb_object_find_destroy->find_handle)) @@ -446,7 +447,7 @@ static void message_handler_req_lib_confdb_key_create (void *conn, { const struct req_lib_confdb_key_create *req_lib_confdb_key_create = message; - coroipc_response_header_t res; + struct qb_ipc_response_header res; int ret = CS_OK; if (api->object_key_create(req_lib_confdb_key_create->object_handle, @@ -467,7 +468,7 @@ static void message_handler_req_lib_confdb_key_create_typed (void *conn, { const struct req_lib_confdb_key_create_typed *req_lib_confdb_key_create = message; - coroipc_response_header_t res; + struct qb_ipc_response_header res; int ret = CS_OK; if (api->object_key_create_typed(req_lib_confdb_key_create->object_handle, @@ -581,7 +582,7 @@ static void message_handler_req_lib_confdb_key_replace (void *conn, { const struct req_lib_confdb_key_replace *req_lib_confdb_key_replace = message; - coroipc_response_header_t res; + struct qb_ipc_response_header res; int ret = CS_OK; if (api->object_key_replace(req_lib_confdb_key_replace->object_handle, @@ -602,7 +603,7 @@ static void message_handler_req_lib_confdb_key_delete (void *conn, { const struct req_lib_confdb_key_delete *req_lib_confdb_key_delete = message; - coroipc_response_header_t res; + struct qb_ipc_response_header res; int ret = CS_OK; if (api->object_key_delete(req_lib_confdb_key_delete->object_handle, @@ -1056,7 +1057,7 @@ static void message_handler_req_lib_confdb_track_start (void *conn, const void *message) { const struct req_lib_confdb_object_track_start *req = message; - coroipc_response_header_t res; + struct qb_ipc_response_header res; api->object_track_start(req->object_handle, req->flags, @@ -1074,7 +1075,7 @@ static void message_handler_req_lib_confdb_track_start (void *conn, static void message_handler_req_lib_confdb_track_stop (void *conn, const void *message) { - coroipc_response_header_t res; + struct qb_ipc_response_header res; api->object_track_stop(confdb_notify_lib_of_key_change, confdb_notify_lib_of_new_object, diff --git a/services/cpg.c b/services/cpg.c index 6669fbda..42e13770 100644 --- a/services/cpg.c +++ b/services/cpg.c @@ -50,12 +50,14 @@ #include #include #include +#include #include #include #include +#include #include -#include +#include #include #include #include @@ -79,6 +81,11 @@ enum cpg_message_req_types { MESSAGE_REQ_EXEC_CPG_DOWNLIST = 5 }; +struct zcb_mapped { + struct list_head list; + void *addr; + size_t size; +}; /* * state` exec deliver * match group name, pid -> if matched deliver for YES: @@ -99,22 +106,22 @@ enum cpg_message_req_types { * * * library accept join error codes - * UNJOINED YES(CPG_OK) set JOIN_STARTED - * LEAVE_STARTED NO(CPG_ERR_BUSY) - * JOIN_STARTED NO(CPG_ERR_EXIST) - * JOIN_COMPlETED NO(CPG_ERR_EXIST) + * UNJOINED YES(CS_OK) set JOIN_STARTED + * LEAVE_STARTED NO(CS_ERR_BUSY) + * JOIN_STARTED NO(CS_ERR_EXIST) + * JOIN_COMPlETED NO(CS_ERR_EXIST) * * library accept leave error codes - * UNJOINED NO(CPG_ERR_NOT_EXIST) - * LEAVE_STARTED NO(CPG_ERR_NOT_EXIST) - * JOIN_STARTED NO(CPG_ERR_BUSY) - * JOIN_COMPLETED YES(CPG_OK) set LEAVE_STARTED + * UNJOINED NO(CS_ERR_NOT_EXIST) + * LEAVE_STARTED NO(CS_ERR_NOT_EXIST) + * JOIN_STARTED NO(CS_ERR_BUSY) + * JOIN_COMPLETED YES(CS_OK) set LEAVE_STARTED * * library accept mcast - * UNJOINED NO(CPG_ERR_NOT_EXIST) - * LEAVE_STARTED NO(CPG_ERR_NOT_EXIST) - * JOIN_STARTED YES(CPG_OK) - * JOIN_COMPLETED YES(CPG_OK) + * UNJOINED NO(CS_ERR_NOT_EXIST) + * LEAVE_STARTED NO(CS_ERR_NOT_EXIST) + * JOIN_STARTED YES(CS_OK) + * JOIN_COMPLETED YES(CS_OK) */ enum cpd_state { CPD_STATE_UNJOINED, @@ -145,6 +152,7 @@ struct cpg_pd { int initial_totem_conf_sent; struct list_head list; struct list_head iteration_instance_list_head; + struct list_head zcb_mapped_list_head; }; struct cpg_iteration_instance { @@ -254,6 +262,18 @@ static void message_handler_req_lib_cpg_iteration_finalize ( void *conn, const void *message); +static void message_handler_req_lib_cpg_zc_alloc ( + void *conn, + const void *message); + +static void message_handler_req_lib_cpg_zc_free ( + void *conn, + const void *message); + +static void message_handler_req_lib_cpg_zc_execute ( + void *conn, + const void *message); + static int cpg_node_joinleave_send (unsigned int pid, const mar_cpg_name_t *group_name, int fn, int reason); static int cpg_exec_send_downlist(void); @@ -282,6 +302,9 @@ static int notify_lib_totem_membership ( int member_list_entries, const unsigned int *member_list); +static inline int zcb_all_free ( + struct cpg_pd *cpd); + /* * Library Handler Definition */ @@ -323,6 +346,20 @@ static struct corosync_lib_handler cpg_lib_engine[] = .lib_handler_fn = message_handler_req_lib_cpg_finalize, .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED }, + { /* 9 */ + .lib_handler_fn = message_handler_req_lib_cpg_zc_alloc, + .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED + }, + { /* 10 */ + .lib_handler_fn = message_handler_req_lib_cpg_zc_free, + .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED + }, + { /* 11 */ + .lib_handler_fn = message_handler_req_lib_cpg_zc_execute, + .flow_control = CS_LIB_FLOW_CONTROL_REQUIRED + }, + + }; static struct corosync_exec_handler cpg_exec_engine[] = @@ -422,14 +459,14 @@ __attribute__ ((constructor)) static void corosync_lcr_component_register (void) } struct req_exec_cpg_procjoin { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_cpg_name_t group_name __attribute__((aligned(8))); mar_uint32_t pid __attribute__((aligned(8))); mar_uint32_t reason __attribute__((aligned(8))); }; struct req_exec_cpg_mcast { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_cpg_name_t group_name __attribute__((aligned(8))); mar_uint32_t msglen __attribute__((aligned(8))); mar_uint32_t pid __attribute__((aligned(8))); @@ -438,13 +475,13 @@ struct req_exec_cpg_mcast { }; struct req_exec_cpg_downlist_old { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); mar_uint32_t left_nodes __attribute__((aligned(8))); mar_uint32_t nodeids[PROCESSOR_COUNT_MAX] __attribute__((aligned(8))); }; struct req_exec_cpg_downlist { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); /* merge decisions */ mar_uint32_t old_members __attribute__((aligned(8))); /* downlist below */ @@ -557,7 +594,7 @@ static int notify_lib_totem_membership ( sizeof(mar_uint32_t) * (member_list_entries); buf = alloca(size); if (!buf) - return CPG_ERR_LIBRARY; + return CS_ERR_LIBRARY; res = (struct res_lib_cpg_totem_confchg_callback *)buf; res->member_list_entries = member_list_entries; @@ -577,7 +614,7 @@ static int notify_lib_totem_membership ( api->ipc_dispatch_send (conn, buf, size); } - return CPG_OK; + return CS_OK; } static int notify_lib_joinlist( @@ -619,7 +656,7 @@ static int notify_lib_joinlist( sizeof(mar_cpg_address_t) * (count + left_list_entries + joined_list_entries); buf = alloca(size); if (!buf) - return CPG_ERR_LIBRARY; + return CS_ERR_LIBRARY; res = (struct res_lib_cpg_confchg_callback *)buf; res->joined_list_entries = joined_list_entries; @@ -708,7 +745,7 @@ static int notify_lib_joinlist( } } - return CPG_OK; + return CS_OK; } static void downlist_log(int loglevel, const char *msg, struct downlist_msg* dl) @@ -848,6 +885,7 @@ static void cpg_pd_finalize (struct cpg_pd *cpd) struct list_head *iter, *iter_next; struct cpg_iteration_instance *cpii; + zcb_all_free(cpd); for (iter = cpd->iteration_instance_list_head.next; iter != &cpd->iteration_instance_list_head; iter = iter_next) { @@ -913,8 +951,8 @@ static void exec_cpg_procjoin_endian_convert (void *msg) static void exec_cpg_joinlist_endian_convert (void *msg_v) { char *msg = msg_v; - coroipc_response_header_t *res = (coroipc_response_header_t *)msg; - struct join_list_entry *jle = (struct join_list_entry *)(msg + sizeof(coroipc_response_header_t)); + struct qb_ipc_response_header *res = (struct qb_ipc_response_header *)msg; + struct join_list_entry *jle = (struct join_list_entry *)(msg + sizeof(struct qb_ipc_response_header)); swab_mar_int32_t (&res->size); @@ -1126,8 +1164,8 @@ static void message_handler_req_exec_cpg_joinlist ( unsigned int nodeid) { const char *message = message_v; - const coroipc_response_header_t *res = (const coroipc_response_header_t *)message; - const struct join_list_entry *jle = (const struct join_list_entry *)(message + sizeof(coroipc_response_header_t)); + const struct qb_ipc_response_header *res = (const struct qb_ipc_response_header *)message; + const struct join_list_entry *jle = (const struct join_list_entry *)(message + sizeof(struct qb_ipc_response_header)); log_printf(LOGSYS_LEVEL_DEBUG, "got joinlist message from node %x\n", nodeid); @@ -1193,7 +1231,7 @@ static void message_handler_req_exec_cpg_mcast ( } if (!known_node) { - /* Unknown node -> we will not deliver message */ + log_printf(LOGSYS_LEVEL_WARNING, "Unknown node -> we will not deliver message"); return ; } @@ -1222,7 +1260,7 @@ static int cpg_exec_send_joinlist(void) { int count = 0; struct list_head *iter; - coroipc_response_header_t *res; + struct qb_ipc_response_header *res; char *buf; struct join_list_entry *jle; struct iovec req_exec_cpg_iovec; @@ -1239,27 +1277,27 @@ static int cpg_exec_send_joinlist(void) if (!count) return 0; - buf = alloca(sizeof(coroipc_response_header_t) + sizeof(struct join_list_entry) * count); + buf = alloca(sizeof(struct qb_ipc_response_header) + sizeof(struct join_list_entry) * count); if (!buf) { log_printf(LOGSYS_LEVEL_WARNING, "Unable to allocate joinlist buffer"); return -1; } - jle = (struct join_list_entry *)(buf + sizeof(coroipc_response_header_t)); - res = (coroipc_response_header_t *)buf; + jle = (struct join_list_entry *)(buf + sizeof(struct qb_ipc_response_header)); + res = (struct qb_ipc_response_header *)buf; for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) { struct process_info *pi = list_entry (iter, struct process_info, list); - if (pi->nodeid == api->totem_nodeid_get ()) { - memcpy (&jle->group_name, &pi->group, sizeof (mar_cpg_name_t)); - jle->pid = pi->pid; - jle++; + if (pi->nodeid == api->totem_nodeid_get ()) { + memcpy (&jle->group_name, &pi->group, sizeof (mar_cpg_name_t)); + jle->pid = pi->pid; + jle++; } } res->id = SERVICE_ID_MAKE(CPG_SERVICE, MESSAGE_REQ_EXEC_CPG_JOINLIST); - res->size = sizeof(coroipc_response_header_t)+sizeof(struct join_list_entry) * count; + res->size = sizeof(struct qb_ipc_response_header)+sizeof(struct join_list_entry) * count; req_exec_cpg_iovec.iov_base = buf; req_exec_cpg_iovec.iov_len = res->size; @@ -1275,6 +1313,7 @@ static int cpg_lib_init_fn (void *conn) list_add (&cpd->list, &cpg_pd_list_head); list_init (&cpd->iteration_instance_list_head); + list_init (&cpd->zcb_mapped_list_head); api->ipc_refcnt_inc (conn); log_printf(LOGSYS_LEVEL_DEBUG, "lib_init_fn: conn=%p, cpd=%p\n", conn, cpd); @@ -1287,7 +1326,7 @@ static void message_handler_req_lib_cpg_join (void *conn, const void *message) const struct req_lib_cpg_join *req_lib_cpg_join = message; struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn); struct res_lib_cpg_join res_lib_cpg_join; - cs_error_t error = CPG_OK; + cs_error_t error = CS_OK; struct list_head *iter; /* Test, if we don't have same pid and group name joined */ @@ -1298,7 +1337,7 @@ static void message_handler_req_lib_cpg_join (void *conn, const void *message) mar_name_compare(&req_lib_cpg_join->group_name, &cpd_item->group_name) == 0) { /* We have same pid and group name joined -> return error */ - error = CPG_ERR_EXIST; + error = CS_ERR_EXIST; goto response_send; } } @@ -1313,14 +1352,14 @@ static void message_handler_req_lib_cpg_join (void *conn, const void *message) if (pi->nodeid == api->totem_nodeid_get () && pi->pid == req_lib_cpg_join->pid && mar_name_compare(&req_lib_cpg_join->group_name, &pi->group) == 0) { /* We have same pid and group name joined -> return error */ - error = CPG_ERR_TRY_AGAIN; + error = CS_ERR_TRY_AGAIN; goto response_send; } } switch (cpd->cpd_state) { case CPD_STATE_UNJOINED: - error = CPG_OK; + error = CS_OK; cpd->cpd_state = CPD_STATE_JOIN_STARTED; cpd->pid = req_lib_cpg_join->pid; cpd->flags = req_lib_cpg_join->flags; @@ -1332,13 +1371,13 @@ static void message_handler_req_lib_cpg_join (void *conn, const void *message) MESSAGE_REQ_EXEC_CPG_PROCJOIN, CONFCHG_CPG_REASON_JOIN); break; case CPD_STATE_LEAVE_STARTED: - error = CPG_ERR_BUSY; + error = CS_ERR_BUSY; break; case CPD_STATE_JOIN_STARTED: - error = CPG_ERR_EXIST; + error = CS_ERR_EXIST; break; case CPD_STATE_JOIN_COMPLETED: - error = CPG_ERR_EXIST; + error = CS_ERR_EXIST; break; } @@ -1353,7 +1392,7 @@ response_send: static void message_handler_req_lib_cpg_leave (void *conn, const void *message) { struct res_lib_cpg_leave res_lib_cpg_leave; - cs_error_t error = CPG_OK; + cs_error_t error = CS_OK; struct req_lib_cpg_leave *req_lib_cpg_leave = (struct req_lib_cpg_leave *)message; struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn); @@ -1361,16 +1400,16 @@ static void message_handler_req_lib_cpg_leave (void *conn, const void *message) switch (cpd->cpd_state) { case CPD_STATE_UNJOINED: - error = CPG_ERR_NOT_EXIST; + error = CS_ERR_NOT_EXIST; break; case CPD_STATE_LEAVE_STARTED: - error = CPG_ERR_NOT_EXIST; + error = CS_ERR_NOT_EXIST; break; case CPD_STATE_JOIN_STARTED: - error = CPG_ERR_BUSY; + error = CS_ERR_BUSY; break; case CPD_STATE_JOIN_COMPLETED: - error = CPG_OK; + error = CS_OK; cpd->cpd_state = CPD_STATE_LEAVE_STARTED; cpg_node_joinleave_send (req_lib_cpg_leave->pid, &req_lib_cpg_leave->group_name, @@ -1412,11 +1451,215 @@ static void message_handler_req_lib_cpg_finalize ( sizeof (res_lib_cpg_finalize)); } +static int +memory_map ( + const char *path, + size_t bytes, + void **buf) +{ + int32_t fd; + void *addr_orig; + void *addr; + int32_t res; + + fd = open (path, O_RDWR, 0600); + + unlink (path); + + if (fd == -1) { + return (-1); + } + + res = ftruncate (fd, bytes); + if (res == -1) { + goto error_close_unlink; + } + + addr_orig = mmap (NULL, bytes, PROT_NONE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + + if (addr_orig == MAP_FAILED) { + goto error_close_unlink; + } + + addr = mmap (addr_orig, bytes, PROT_READ | PROT_WRITE, + MAP_FIXED | MAP_SHARED, fd, 0); + + if (addr != addr_orig) { + munmap(addr_orig, bytes); + goto error_close_unlink; + } +#ifdef COROSYNC_BSD + madvise(addr, bytes, MADV_NOSYNC); +#endif + + res = close (fd); + if (res) { + return (-1); + } + *buf = addr_orig; + return (0); + +error_close_unlink: + close (fd); + unlink(path); + return -1; +} + +static inline int zcb_alloc ( + struct cpg_pd *cpd, + const char *path_to_file, + size_t size, + void **addr) +{ + struct zcb_mapped *zcb_mapped; + unsigned int res; + + zcb_mapped = malloc (sizeof (struct zcb_mapped)); + if (zcb_mapped == NULL) { + return (-1); + } + + res = memory_map ( + path_to_file, + size, + addr); + if (res == -1) { + free (zcb_mapped); + return (-1); + } + + list_init (&zcb_mapped->list); + zcb_mapped->addr = *addr; + zcb_mapped->size = size; + list_add_tail (&zcb_mapped->list, &cpd->zcb_mapped_list_head); + return (0); +} + + +static inline int zcb_free (struct zcb_mapped *zcb_mapped) +{ + unsigned int res; + + res = munmap (zcb_mapped->addr, zcb_mapped->size); + list_del (&zcb_mapped->list); + free (zcb_mapped); + return (res); +} + +static inline int zcb_by_addr_free (struct cpg_pd *cpd, void *addr) +{ + struct list_head *list; + struct zcb_mapped *zcb_mapped; + unsigned int res = 0; + + for (list = cpd->zcb_mapped_list_head.next; + list != &cpd->zcb_mapped_list_head; list = list->next) { + + zcb_mapped = list_entry (list, struct zcb_mapped, list); + + if (zcb_mapped->addr == addr) { + res = zcb_free (zcb_mapped); + break; + } + + } + return (res); +} + +static inline int zcb_all_free ( + struct cpg_pd *cpd) +{ + struct list_head *list; + struct zcb_mapped *zcb_mapped; + + for (list = cpd->zcb_mapped_list_head.next; + list != &cpd->zcb_mapped_list_head;) { + + zcb_mapped = list_entry (list, struct zcb_mapped, list); + + list = list->next; + + zcb_free (zcb_mapped); + } + return (0); +} + +union u { + uint64_t server_addr; + void *server_ptr; +}; + +static uint64_t void2serveraddr (void *server_ptr) +{ + union u u; + + u.server_ptr = server_ptr; + return (u.server_addr); +} + +static void *serveraddr2void (uint64_t server_addr) +{ + union u u; + + u.server_addr = server_addr; + return (u.server_ptr); +}; + +static void message_handler_req_lib_cpg_zc_alloc ( + void *conn, + const void *message) +{ + mar_req_coroipcc_zc_alloc_t *hdr = (mar_req_coroipcc_zc_alloc_t *)message; + struct qb_ipc_response_header res_header; + void *addr = NULL; + struct coroipcs_zc_header *zc_header; + unsigned int res; + struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn); + + log_printf(LOGSYS_LEVEL_DEBUG, "path: %s", hdr->path_to_file); + + res = zcb_alloc (cpd, hdr->path_to_file, hdr->map_size, + &addr); + assert(res == 0); + + zc_header = (struct coroipcs_zc_header *)addr; + zc_header->server_address = void2serveraddr(addr); + + res_header.size = sizeof (struct qb_ipc_response_header); + res_header.id = 0; + api->ipc_response_send (conn, + &res_header, + res_header.size); +} + +static void message_handler_req_lib_cpg_zc_free ( + void *conn, + const void *message) +{ + mar_req_coroipcc_zc_free_t *hdr = (mar_req_coroipcc_zc_free_t *)message; + struct qb_ipc_response_header res_header; + void *addr = NULL; + struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn); + + log_printf(LOGSYS_LEVEL_DEBUG, " free'ing"); + + addr = serveraddr2void (hdr->server_address); + + zcb_by_addr_free (cpd, addr); + + res_header.size = sizeof (struct qb_ipc_response_header); + res_header.id = 0; + api->ipc_response_send ( + conn, &res_header, + res_header.size); +} + /* Mcast message from the library */ static void message_handler_req_lib_cpg_mcast (void *conn, const void *message) { const struct req_lib_cpg_mcast *req_lib_cpg_mcast = message; - struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn); + struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn); mar_cpg_name_t group_name = cpd->group_name; struct iovec req_exec_cpg_iovec[2]; @@ -1424,49 +1667,117 @@ static void message_handler_req_lib_cpg_mcast (void *conn, const void *message) struct res_lib_cpg_mcast res_lib_cpg_mcast; int msglen = req_lib_cpg_mcast->msglen; int result; - cs_error_t error = CPG_ERR_NOT_EXIST; + cs_error_t error = CS_ERR_NOT_EXIST; log_printf(LOGSYS_LEVEL_DEBUG, "got mcast request on %p\n", conn); - switch (cpd->cpd_state) { - case CPD_STATE_UNJOINED: - error = CPG_ERR_NOT_EXIST; - break; - case CPD_STATE_LEAVE_STARTED: - error = CPG_ERR_NOT_EXIST; - break; - case CPD_STATE_JOIN_STARTED: - error = CPG_OK; - break; - case CPD_STATE_JOIN_COMPLETED: - error = CPG_OK; - break; + switch (cpd->cpd_state) { + case CPD_STATE_UNJOINED: + error = CS_ERR_NOT_EXIST; + break; + case CPD_STATE_LEAVE_STARTED: + error = CS_ERR_NOT_EXIST; + break; + case CPD_STATE_JOIN_STARTED: + error = CS_OK; + break; + case CPD_STATE_JOIN_COMPLETED: + error = CS_OK; + break; } - if (error == CPG_OK) { - req_exec_cpg_mcast.header.size = sizeof(req_exec_cpg_mcast) + msglen; - req_exec_cpg_mcast.header.id = SERVICE_ID_MAKE(CPG_SERVICE, - MESSAGE_REQ_EXEC_CPG_MCAST); - req_exec_cpg_mcast.pid = cpd->pid; - req_exec_cpg_mcast.msglen = msglen; - api->ipc_source_set (&req_exec_cpg_mcast.source, conn); - memcpy(&req_exec_cpg_mcast.group_name, &group_name, - sizeof(mar_cpg_name_t)); + if (error == CS_OK) { + req_exec_cpg_mcast.header.size = sizeof(req_exec_cpg_mcast) + msglen; + req_exec_cpg_mcast.header.id = SERVICE_ID_MAKE(CPG_SERVICE, + MESSAGE_REQ_EXEC_CPG_MCAST); + req_exec_cpg_mcast.pid = cpd->pid; + req_exec_cpg_mcast.msglen = msglen; + api->ipc_source_set (&req_exec_cpg_mcast.source, conn); + memcpy(&req_exec_cpg_mcast.group_name, &group_name, + sizeof(mar_cpg_name_t)); - req_exec_cpg_iovec[0].iov_base = (char *)&req_exec_cpg_mcast; - req_exec_cpg_iovec[0].iov_len = sizeof(req_exec_cpg_mcast); - req_exec_cpg_iovec[1].iov_base = (char *)&req_lib_cpg_mcast->message; - req_exec_cpg_iovec[1].iov_len = msglen; + req_exec_cpg_iovec[0].iov_base = (char *)&req_exec_cpg_mcast; + req_exec_cpg_iovec[0].iov_len = sizeof(req_exec_cpg_mcast); + req_exec_cpg_iovec[1].iov_base = (char *)&req_lib_cpg_mcast->message; + req_exec_cpg_iovec[1].iov_len = msglen; - result = api->totem_mcast (req_exec_cpg_iovec, 2, TOTEM_AGREED); - assert(result == 0); - } + result = api->totem_mcast (req_exec_cpg_iovec, 2, TOTEM_AGREED); + assert(result == 0); + } res_lib_cpg_mcast.header.size = sizeof(res_lib_cpg_mcast); res_lib_cpg_mcast.header.id = MESSAGE_RES_CPG_MCAST; - res_lib_cpg_mcast.header.error = error; - api->ipc_response_send (conn, &res_lib_cpg_mcast, - sizeof (res_lib_cpg_mcast)); + res_lib_cpg_mcast.header.error = error; + api->ipc_response_send (conn, &res_lib_cpg_mcast, + sizeof (res_lib_cpg_mcast)); +} + +static void message_handler_req_lib_cpg_zc_execute ( + void *conn, + const void *message) +{ + mar_req_coroipcc_zc_execute_t *hdr = (mar_req_coroipcc_zc_execute_t *)message; + struct qb_ipc_request_header *header; + struct res_lib_cpg_mcast res_lib_cpg_mcast; + struct cpg_pd *cpd = (struct cpg_pd *)api->ipc_private_data_get (conn); + struct iovec req_exec_cpg_iovec[2]; + struct req_exec_cpg_mcast req_exec_cpg_mcast; + struct req_lib_cpg_mcast *req_lib_cpg_mcast; + int result; + cs_error_t error = CS_ERR_NOT_EXIST; + struct coroipcs_zc_header *zc_hdr; + + log_printf(LOGSYS_LEVEL_DEBUG, "got ZC mcast request on %p\n", conn); + + zc_hdr = (struct coroipcs_zc_header *)((char *)serveraddr2void(hdr->server_address)); + header = (struct qb_ipc_request_header *)(((char *)serveraddr2void(hdr->server_address) + sizeof (struct coroipcs_zc_header))); + req_lib_cpg_mcast = (struct req_lib_cpg_mcast *)header; + + switch (cpd->cpd_state) { + case CPD_STATE_UNJOINED: + error = CS_ERR_NOT_EXIST; + break; + case CPD_STATE_LEAVE_STARTED: + error = CS_ERR_NOT_EXIST; + break; + case CPD_STATE_JOIN_STARTED: + error = CS_OK; + break; + case CPD_STATE_JOIN_COMPLETED: + error = CS_OK; + break; + } + + res_lib_cpg_mcast.header.size = sizeof(res_lib_cpg_mcast); + res_lib_cpg_mcast.header.id = MESSAGE_RES_CPG_MCAST; + if (error == CS_OK) { + req_exec_cpg_mcast.header.size = sizeof(req_exec_cpg_mcast) + req_lib_cpg_mcast->msglen; + req_exec_cpg_mcast.header.id = SERVICE_ID_MAKE(CPG_SERVICE, + MESSAGE_REQ_EXEC_CPG_MCAST); + req_exec_cpg_mcast.pid = cpd->pid; + req_exec_cpg_mcast.msglen = req_lib_cpg_mcast->msglen; + api->ipc_source_set (&req_exec_cpg_mcast.source, conn); + memcpy(&req_exec_cpg_mcast.group_name, &cpd->group_name, + sizeof(mar_cpg_name_t)); + + req_exec_cpg_iovec[0].iov_base = (char *)&req_exec_cpg_mcast; + req_exec_cpg_iovec[0].iov_len = sizeof(req_exec_cpg_mcast); + req_exec_cpg_iovec[1].iov_base = (char *)header + sizeof(struct req_lib_cpg_mcast); + req_exec_cpg_iovec[1].iov_len = req_exec_cpg_mcast.msglen; + + result = api->totem_mcast (req_exec_cpg_iovec, 2, TOTEM_AGREED); + if (result == 0) { + res_lib_cpg_mcast.header.error = CS_OK; + } else { + res_lib_cpg_mcast.header.error = CS_ERR_TRY_AGAIN; + } + } else { + res_lib_cpg_mcast.header.error = error; + } + + api->ipc_response_send (conn, &res_lib_cpg_mcast, + sizeof (res_lib_cpg_mcast)); + } static void message_handler_req_lib_cpg_membership (void *conn, @@ -1479,7 +1790,7 @@ static void message_handler_req_lib_cpg_membership (void *conn, int member_count = 0; res_lib_cpg_membership_get.header.id = MESSAGE_RES_CPG_MEMBERSHIP; - res_lib_cpg_membership_get.header.error = CPG_OK; + res_lib_cpg_membership_get.header.error = CS_OK; res_lib_cpg_membership_get.header.size = sizeof (struct req_lib_cpg_membership_get); @@ -1506,7 +1817,7 @@ static void message_handler_req_lib_cpg_local_get (void *conn, res_lib_cpg_local_get.header.size = sizeof (res_lib_cpg_local_get); res_lib_cpg_local_get.header.id = MESSAGE_RES_CPG_LOCAL_GET; - res_lib_cpg_local_get.header.error = CPG_OK; + res_lib_cpg_local_get.header.error = CS_OK; res_lib_cpg_local_get.local_nodeid = api->totem_nodeid_get (); api->ipc_response_send (conn, &res_lib_cpg_local_get, diff --git a/services/evs.c b/services/evs.c index d76d784f..43c65d64 100644 --- a/services/evs.c +++ b/services/evs.c @@ -46,13 +46,14 @@ #include #include #include +#include #include #include #include #include #include -#include +#include #include #include #include diff --git a/services/pload.c b/services/pload.c index 809476fe..63896f21 100644 --- a/services/pload.c +++ b/services/pload.c @@ -50,10 +50,13 @@ #include #include #include +#include + +#include +#include #include #include -#include #include #include #include @@ -116,7 +119,7 @@ static unsigned int msgs_sent = 0; static struct corosync_api_v1 *api; struct req_exec_pload_start { - coroipc_request_header_t header; + struct qb_ipc_request_header header; unsigned int msg_code; unsigned int msg_count; unsigned int msg_size; @@ -124,7 +127,7 @@ struct req_exec_pload_start { }; struct req_exec_pload_mcast { - coroipc_request_header_t header; + struct qb_ipc_request_header header; unsigned int msg_code; }; diff --git a/services/testquorum.c b/services/testquorum.c index 745d550d..20c4c0b2 100644 --- a/services/testquorum.c +++ b/services/testquorum.c @@ -55,7 +55,7 @@ #include #include -#include +#include #include #include diff --git a/services/votequorum.c b/services/votequorum.c index 65308747..a3d45339 100644 --- a/services/votequorum.c +++ b/services/votequorum.c @@ -56,7 +56,7 @@ #include #include -#include +#include #include #include #include @@ -391,7 +391,7 @@ static void votequorum_init(struct corosync_api_v1 *api, } struct req_exec_quorum_nodeinfo { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); unsigned int first_trans; unsigned int votes; unsigned int expected_votes; @@ -410,14 +410,14 @@ struct req_exec_quorum_nodeinfo { #define RECONFIG_PARAM_LEAVING 3 struct req_exec_quorum_reconfigure { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); unsigned int param; unsigned int nodeid; unsigned int value; }; struct req_exec_quorum_killnode { - coroipc_request_header_t header __attribute__((aligned(8))); + struct qb_ipc_request_header header __attribute__((aligned(8))); unsigned int reason; unsigned int nodeid; }; diff --git a/test/Makefile.am b/test/Makefile.am index b3462d67..c79071f4 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -35,44 +35,45 @@ INCLUDES = -I$(top_builddir)/include/corosync -I$(top_srcdir)/include noinst_PROGRAMS = testevs evsbench evsverify cpgverify testcpg testcpg2 cpgbench testconfdb \ logsysbench logsysrec testquorum testvotequorum1 testvotequorum2 \ - logsys_s logsys_t1 logsys_t2 testcpgzc cpgbenchzc testzcgc \ - stress_cpgzc stress_cpgfdget stress_cpgcontext cpgbound testsam + logsys_s logsys_t1 logsys_t2 \ + stress_cpgfdget stress_cpgcontext cpgbound testsam \ + testcpgzc cpgbenchzc testzcgc stress_cpgzc -testevs_LDADD = -levs -lcoroipcc $(LIBQB_LIBS) +testevs_LDADD = -levs $(LIBQB_LIBS) testevs_LDFLAGS = -L../lib -testcpg_LDADD = -lcpg -lcoroipcc $(LIBQB_LIBS) +testcpg_LDADD = -lcpg $(LIBQB_LIBS) testcpg_LDFLAGS = -L../lib -testcpg2_LDADD = -lcpg -lcoroipcc $(LIBQB_LIBS) +testcpg2_LDADD = -lcpg $(LIBQB_LIBS) testcpg2_LDFLAGS = -L../lib -testcpgzc_LDADD = -lcpg -lcoroipcc $(LIBQB_LIBS) +testcpgzc_LDADD = -lcpg $(LIBQB_LIBS) testcpgzc_LDFLAGS = -L../lib -testzcgc_LDADD = -lcpg -lcoroipcc $(LIBQB_LIBS) +testzcgc_LDADD = -lcpg $(LIBQB_LIBS) testzcgc_LDFLAGS = -L../lib -stress_cpgzc_LDADD = -lcpg -lcoroipcc $(LIBQB_LIBS) +stress_cpgzc_LDADD = -lcpg $(LIBQB_LIBS) stress_cpgzc_LDFLAGS = -L../lib -stress_cpgfdget_LDADD = -lcpg -lcoroipcc $(LIBQB_LIBS) +stress_cpgfdget_LDADD = -lcpg $(LIBQB_LIBS) stress_cpgfdget_LDFLAGS = -L../lib -stress_cpgcontext_LDADD = -lcpg -lcoroipcc $(LIBQB_LIBS) +stress_cpgcontext_LDADD = -lcpg $(LIBQB_LIBS) stress_cpgcontext_LDFLAGS = -L../lib -testconfdb_LDADD = -lconfdb ../lcr/liblcr.a -lcoroipcc $(LIBQB_LIBS) +testconfdb_LDADD = -lconfdb ../lcr/liblcr.a $(LIBQB_LIBS) testconfdb_LDFLAGS = -L../lib -testquorum_LDADD = -lquorum -lcoroipcc $(LIBQB_LIBS) +testquorum_LDADD = -lquorum $(LIBQB_LIBS) testquorum_LDFLAGS = -L../lib -testvotequorum1_LDADD = -lvotequorum -lcoroipcc $(LIBQB_LIBS) +testvotequorum1_LDADD = -lvotequorum $(LIBQB_LIBS) testvotequorum1_LDFLAGS = -L../lib -testvotequorum2_LDADD = -lvotequorum -lcoroipcc $(LIBQB_LIBS) +testvotequorum2_LDADD = -lvotequorum $(LIBQB_LIBS) testvotequorum2_LDFLAGS = -L../lib -evsverify_LDADD = -levs -ltotem_pg -lcoroipcc $(LIBQB_LIBS) +evsverify_LDADD = -levs -ltotem_pg $(LIBQB_LIBS) evsverify_LDFLAGS = -L../lib -L../exec -cpgverify_LDADD = -lcpg -ltotem_pg -lcoroipcc $(LIBQB_LIBS) +cpgverify_LDADD = -lcpg -ltotem_pg $(LIBQB_LIBS) cpgverify_LDFLAGS = -L../lib -L../exec -cpgbound_LDADD = -lcpg -lcoroipcc $(LIBQB_LIBS) +cpgbound_LDADD = -lcpg $(LIBQB_LIBS) cpgbound_LDFLAGS = -L../lib -evsbench_LDADD = -levs -lcoroipcc $(LIBQB_LIBS) +evsbench_LDADD = -levs $(LIBQB_LIBS) evsbench_LDFLAGS = -L../lib -cpgbench_LDADD = -lcpg -lcoroipcc $(LIBQB_LIBS) +cpgbench_LDADD = -lcpg $(LIBQB_LIBS) cpgbench_LDFLAGS = -L../lib -cpgbenchzc_LDADD = -lcpg -lcoroipcc $(LIBQB_LIBS) +cpgbenchzc_LDADD = -lcpg $(LIBQB_LIBS) cpgbenchzc_LDFLAGS = -L../lib logsysbench_LDADD = -llogsys logsysbench_LDFLAGS = -L../exec @@ -85,7 +86,7 @@ logsys_t1_LDADD = -llogsys logsys_t1_LDFLAGS = -L../exec logsys_t2_LDADD = -llogsys logsys_t2_LDFLAGS = -L../exec -testsam_LDADD = -lsam -lconfdb -lquorum -lcoroipcc +testsam_LDADD = -lsam -lconfdb -lquorum $(LIBQB_LIBS) testsam_LDFLAGS = -L../lib LINT_FILES1:=$(filter-out sa_error.c, $(wildcard *.c)) diff --git a/test/cpgbench.c b/test/cpgbench.c index 7cb76616..30cd0459 100644 --- a/test/cpgbench.c +++ b/test/cpgbench.c @@ -50,10 +50,17 @@ #include #include #include +#include + +#include #include #include +static cpg_handle_t handle; + +static pthread_t thread; + #ifndef timersub #define timersub(a, b, result) \ do { \ @@ -69,7 +76,7 @@ static int alarm_notice; static void cpg_bm_confchg_fn ( - cpg_handle_t handle, + cpg_handle_t handle_in, const struct cpg_name *group_name, const struct cpg_address *member_list, size_t member_list_entries, const struct cpg_address *left_list, size_t left_list_entries, @@ -80,7 +87,7 @@ static void cpg_bm_confchg_fn ( static unsigned int write_count; static void cpg_bm_deliver_fn ( - cpg_handle_t handle, + cpg_handle_t handle_in, const struct cpg_name *group_name, uint32_t nodeid, uint32_t pid, @@ -98,13 +105,12 @@ static cpg_callbacks_t callbacks = { static char data[500000]; static void cpg_benchmark ( - cpg_handle_t handle, + cpg_handle_t handle_in, int write_size) { struct timeval tv1, tv2, tv_elapsed; struct iovec iov; unsigned int res; - cpg_flow_control_state_t flow_control_state; alarm_notice = 0; iov.iov_base = data; @@ -115,23 +121,8 @@ static void cpg_benchmark ( gettimeofday (&tv1, NULL); do { - /* - * Test checkpoint write - */ - cpg_flow_control_state_get (handle, &flow_control_state); - if (flow_control_state == CPG_FLOW_CONTROL_DISABLED) { -retry: - res = cpg_mcast_joined (handle, CPG_TYPE_AGREED, &iov, 1); - if (res == CS_ERR_TRY_AGAIN) { - goto retry; - } - } - res = cpg_dispatch (handle, CS_DISPATCH_ALL); - if (res != CS_OK) { - printf ("cpg dispatch returned error %d\n", res); - exit (1); - } - } while (alarm_notice == 0); + res = cpg_mcast_joined (handle_in, CPG_TYPE_AGREED, &iov, 1); + } while (alarm_notice == 0 && (res == CS_OK || res == CS_ERR_TRY_AGAIN)); gettimeofday (&tv2, NULL); timersub (&tv2, &tv1, &tv_elapsed); @@ -155,19 +146,35 @@ static struct cpg_name group_name = { .length = 6 }; + +static void libqb_log_writer(const char *file_name, + int32_t file_line, + int32_t severity, const char *msg) +{ + printf("libqb: %s:%d [%d] %s\n", file_name, file_line, severity, msg); +} + +static void* dispatch_thread (void *arg) +{ + cpg_dispatch (handle, CPG_DISPATCH_BLOCKING); + return NULL; +} + int main (void) { - cpg_handle_t handle; unsigned int size; int i; unsigned int res; - size = 1000; + qb_util_set_log_function(libqb_log_writer); + + size = 64; signal (SIGALRM, sigalrm_handler); res = cpg_initialize (&handle, &callbacks); if (res != CS_OK) { printf ("cpg_initialize failed with result %d\n", res); exit (1); } + pthread_create (&thread, NULL, dispatch_thread, NULL); res = cpg_join (handle, &group_name); if (res != CS_OK) { @@ -175,10 +182,10 @@ int main (void) { exit (1); } - for (i = 0; i < 50; i++) { /* number of repetitions - up to 50k */ + for (i = 0; i < 10; i++) { /* number of repetitions - up to 50k */ cpg_benchmark (handle, size); signal (SIGALRM, sigalrm_handler); - size += 1000; + size *= 2; } res = cpg_finalize (handle); diff --git a/test/testsam.c b/test/testsam.c index d29605ab..28bc7dc2 100644 --- a/test/testsam.c +++ b/test/testsam.c @@ -39,6 +39,7 @@ #include #include +#include #include #include #include diff --git a/tools/Makefile.am b/tools/Makefile.am index 6112725e..f88e7416 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -42,16 +42,17 @@ bin_SCRIPTS = corosync-blackbox EXTRA_DIST = $(bin_SCRIPTS) corosync-notifyd.sysconfig.example -corosync_pload_LDADD = -lpload -lcoroipcc $(LIBQB_LIBS) +corosync_fplay_LDADD = $(LIBQB_LIBS) +corosync_pload_LDADD = -lpload $(LIBQB_LIBS) corosync_pload_LDFLAGS = -L../lib -corosync_objctl_LDADD = -lconfdb ../lcr/liblcr.a -lcoroipcc $(LIBQB_LIBS) +corosync_objctl_LDADD = -lconfdb ../lcr/liblcr.a $(LIBQB_LIBS) corosync_objctl_LDFLAGS = -L../lib -corosync_cfgtool_LDADD = -lcfg -lcoroipcc $(LIBQB_LIBS) +corosync_cfgtool_LDADD = -lcfg $(LIBQB_LIBS) corosync_cfgtool_LDFLAGS= -L../lib -corosync_cpgtool_LDADD = -lcfg -lcpg -lcoroipcc $(LIBQB_LIBS) +corosync_cpgtool_LDADD = -lcfg -lcpg $(LIBQB_LIBS) corosync_cpgtool_LDFLAGS= -L../lib corosync_quorumtool_LDADD = -lconfdb -lcfg -lquorum \ - -lvotequorum -lcoroipcc ../lcr/liblcr.a $(LIBQB_LIBS) + -lvotequorum ../lcr/liblcr.a $(LIBQB_LIBS) corosync_quorumtool_LDFLAGS = -L../lib corosync_notifyd_LDADD = -lcfg -lconfdb ../lcr/liblcr.a -lcoroipcc \