This patch is a forward port of the patch previously posted to rid
ourselves of the race condition introduced when using totem token
received callbacks.
This adds two new apis to allow the scheduling of work for a later time
(or destroying that request).
Regards
-steve
Index: include/corosync/engine/coroapi.h
===================================================================
--- include/corosync/engine/coroapi.h (revision 1886)
+++ include/corosync/engine/coroapi.h (working copy)
@@ -423,14 +423,6 @@
char *(*totem_ip_print) (struct totem_ip_address *addr);
-
- int (*totem_callback_token_create) (
- void **handle_out,
- enum totem_callback_token_type type,
- int delete,
- int (*callback_fn) (enum totem_callback_token_type type, void *),
- void *data);
-
/*
* Totem open process groups API for those service engines
* wanting their own groups
@@ -496,6 +488,13 @@
int (*tpg_groups_release) (
int reserved_msgs);
+ int (*schedwrk_create) (
+ unsigned int *handle,
+ int (schedwrk_fn) (void *),
+ void *context);
+
+ void (*schedwrk_destroy) (unsigned int handle);
+
int (*sync_request) (
char *service_name);
@@ -503,14 +502,20 @@
* User plugin-callable functions for quorum
*/
int (*quorum_is_quorate) (void);
- int (*quorum_register_callback) (quorum_callback_fn_t callback_fn, void *context);
- int (*quorum_unregister_callback) (quorum_callback_fn_t callback_fn, void *context);
+ int (*quorum_register_callback) (
+ quorum_callback_fn_t callback_fn,
+ void *context);
+
+ int (*quorum_unregister_callback) (
+ quorum_callback_fn_t callback_fn, void *context);
+
/*
* This one is for the quorum management plugin's use
*/
- int (*quorum_initialize)(struct quorum_callin_functions *fns,
- sync_callback_fn_t *sync_callback_fn);
+ int (*quorum_initialize) (
+ struct quorum_callin_functions *fns,
+ sync_callback_fn_t *sync_callback_fn);
/*
* Plugin loading and unloading
@@ -541,6 +546,7 @@
* Error handling APIs
*/
void (*error_memory_failure) (void);
+
#define corosync_fatal_error(err) api->fatal_error ((err), __FILE__, __LINE__)
void (*fatal_error) (cs_fatal_error_t err, const char *file, unsigned int line);
};
Index: services/pload.c
===================================================================
--- services/pload.c (revision 1886)
+++ services/pload.c (working copy)
@@ -293,15 +293,13 @@
}
}
-void *token_callback;
+hdb_handle_t start_mcasting_handle;
void start_mcasting (void)
{
- api->totem_callback_token_create (
- &token_callback,
- TOTEM_CALLBACK_TOKEN_RECEIVED,
- 1,
+ api->schedwrk_create (
+ &start_mcasting_handle,
send_message,
- &token_callback);
+ &start_mcasting_handle);
}
static void message_handler_req_exec_pload_start (
Index: exec/schedwrk.c
===================================================================
--- exec/schedwrk.c (revision 0)
+++ exec/schedwrk.c (revision 0)
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2009 Red Hat, Inc.
+ *
+ * All rights reserved.
+ *
+ * Author: Steven Dake ([email protected])
+ *
+ * This software licensed under BSD license, the text of which follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * - Neither the name of the MontaVista Software, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <corosync/totem/totempg.h>
+#include <corosync/hdb.h>
+
+static void (*serialize_lock) (void);
+static void (*serialize_unlock) (void);
+
+static struct hdb_handle_database schedwrk_instance_database = {
+ .handle_count = 0,
+ .handles = 0,
+ .iterator = 0,
+ .mutex = PTHREAD_MUTEX_INITIALIZER
+};
+
+struct schedwrk_instance {
+ int (*schedwrk_fn) (void *);
+ void *context;
+ void *callback_handle;
+};
+
+static int schedwrk_do (enum totem_callback_token_type type, void *context)
+{
+ hdb_handle_t *handle = (hdb_handle_t *)context;
+ struct schedwrk_instance *instance;
+ int res;
+
+ res = hdb_handle_get (&schedwrk_instance_database, *handle,
+ (void *)&instance);
+ if (res != 0) {
+ goto error_exit;
+ }
+
+ serialize_lock ();
+ res = instance->schedwrk_fn (instance->context);
+ serialize_unlock ();
+
+ if (res == -1) {
+ hdb_handle_destroy (&schedwrk_instance_database, *handle);
+ }
+ hdb_handle_put (&schedwrk_instance_database, *handle);
+ return (res);
+
+error_exit:
+ return (-1);
+}
+
+void schedwrk_init (
+ void (*serialize_lock_fn) (void),
+ void (*serialize_unlock_fn) (void))
+{
+ serialize_lock = serialize_lock_fn;
+ serialize_unlock = serialize_unlock_fn;
+}
+
+int schedwrk_create (
+ hdb_handle_t *handle,
+ int (schedwrk_fn) (void *),
+ void *context)
+{
+ struct schedwrk_instance *instance;
+ int res;
+
+ res = hdb_handle_create (&schedwrk_instance_database,
+ sizeof (struct schedwrk_instance), handle);
+ if (res != 0) {
+ goto error_exit;
+ }
+ res = hdb_handle_get (&schedwrk_instance_database, *handle,
+ (void *)&instance);
+ if (res != 0) {
+ goto error_destroy;
+ }
+
+ totempg_callback_token_create (
+ &instance->callback_handle,
+ TOTEM_CALLBACK_TOKEN_SENT,
+ 1,
+ schedwrk_do,
+ handle);
+
+ instance->schedwrk_fn = schedwrk_fn;
+ instance->context = context;
+
+ hdb_handle_put (&schedwrk_instance_database, *handle);
+
+ return (0);
+
+error_destroy:
+ hdb_handle_destroy (&schedwrk_instance_database, *handle);
+
+error_exit:
+ return (-1);
+}
+
+void schedwrk_destroy (hdb_handle_t handle)
+{
+ hdb_handle_destroy (&schedwrk_instance_database, handle);
+}
Index: exec/schedwrk.h
===================================================================
--- exec/schedwrk.h (revision 0)
+++ exec/schedwrk.h (revision 0)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2009 Red Hat, Inc.
+ *
+ * All rights reserved.
+ *
+ * Author: Steven Dake ([email protected])
+ *
+ * This software licensed under BSD license, the text of which follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * - Neither the name of the MontaVista Software, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from this
+ * software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef SCHEDWRK_H_DEFINED
+#define SCHEDWRK_H_DEFINED
+
+void schedwrk_init (
+ void (*serialize_lock_fn) (void),
+ void (*serialize_unlock_fn) (void));
+
+int schedwrk_create (
+ hdb_handle_t *handle,
+ int (schedwrk_fn) (void *),
+ void *context);
+
+void schedwrk_destroy (hdb_handle_t handle);
+
+#endif /* SCHEDWRK_H_DEFINED */
Index: exec/apidef.c
===================================================================
--- exec/apidef.c (revision 1886)
+++ exec/apidef.c (working copy)
@@ -52,6 +52,7 @@
#include <corosync/engine/coroapi.h>
#include "service.h"
#include <corosync/lcr/lcr_ifact.h>
+#include "schedwrk.h"
LOGSYS_DECLARE_SUBSYS ("APIDEF", LOG_INFO);
@@ -91,7 +92,6 @@
.totem_ifaces_get = totempg_ifaces_get,
.totem_ifaces_print = totempg_ifaces_print,
.totem_ip_print = totemip_print,
- .totem_callback_token_create = totempg_callback_token_create,
.tpg_init = totempg_groups_initialize,
.tpg_exit = NULL, /* missing from totempg api */
.tpg_join = (typedef_tpg_join)totempg_groups_join,
@@ -102,6 +102,8 @@
.tpg_groups_mcast = (typedef_tpg_groups_mcast)totempg_groups_mcast_groups,
.tpg_groups_reserve = NULL,
.tpg_groups_release = NULL,
+ .schedwrk_create = schedwrk_create,
+ .schedwrk_destroy = schedwrk_destroy,
.sync_request = sync_request,
.quorum_is_quorate = corosync_quorum_is_quorate,
.quorum_register_callback = corosync_quorum_register_callback,
Index: exec/vsf_ykd.c
===================================================================
--- exec/vsf_ykd.c (revision 1886)
+++ exec/vsf_ykd.c (working copy)
@@ -138,9 +138,9 @@
static struct memb_ring_id ykd_ring_id;
-static void *ykd_attempt_send_callback_token_handle = 0;
+hdb_handle_t schedwrk_attempt_send_callback_handle;
-static void *ykd_state_send_callback_token_handle = 0;
+hdb_handle_t schedwrk_state_send_callback_handle;
static struct corosync_api_v1 *api;
@@ -159,7 +159,7 @@
ykd_state.last_primary.member_list_entries = 0;
}
-static int ykd_state_send_msg (enum totem_callback_token_type type, void *context)
+static int ykd_state_send_msg (void *context)
{
struct iovec iovec[2];
struct ykd_header header;
@@ -180,15 +180,13 @@
static void ykd_state_send (void)
{
- api->totem_callback_token_create (
- &ykd_state_send_callback_token_handle,
- TOTEM_CALLBACK_TOKEN_SENT,
- 1, /* delete after callback */
+ api->schedwrk_create (
+ &schedwrk_state_send_callback_handle,
ykd_state_send_msg,
NULL);
}
-static int ykd_attempt_send_msg (enum totem_callback_token_type type, void *context)
+static int ykd_attempt_send_msg (void *context)
{
struct iovec iovec;
struct ykd_header header;
@@ -207,10 +205,8 @@
static void ykd_attempt_send (void)
{
- api->totem_callback_token_create (
- &ykd_attempt_send_callback_token_handle,
- TOTEM_CALLBACK_TOKEN_SENT,
- 1, /* delete after callback */
+ api->schedwrk_create (
+ schedwrk_attempt_send_callback_handle,
ykd_attempt_send_msg,
NULL);
}
Index: exec/main.c
===================================================================
--- exec/main.c (revision 1886)
+++ exec/main.c (working copy)
@@ -901,6 +901,10 @@
corosync_mempool_init ();
+ schedwrk_init (
+ serialize_lock,
+ serialize_unlock);
+
ipc_subsys_id = _logsys_subsys_create ("IPC", LOG_INFO);
coroipcs_ipc_init (&ipc_init_state);
Index: exec/Makefile.am
===================================================================
--- exec/Makefile.am (revision 1886)
+++ exec/Makefile.am (working copy)
@@ -52,7 +52,8 @@
libcoroipcs_a_SOURCES = $(COROIPCS_SRC)
corosync_SOURCES = main.c mempool.c util.c sync.c apidef.c service.c \
- timer.c totemconfig.c mainconfig.c quorum.c ../lcr/lcr_ifact.c
+ timer.c totemconfig.c mainconfig.c quorum.c schedwrk.c \
+ ../lcr/lcr_ifact.c
corosync_LDADD = -ltotem_pg -llogsys -lcoroipcs
corosync_DEPENDENCIES = libtotem_pg.so.$(SONAME) liblogsys.so.$(SONAME) libcoroipcs.so.$(SONAME)
corosync_LDFLAGS = $(OS_DYFLAGS) -L./
@@ -68,7 +69,7 @@
noinst_HEADERS = apidef.h crypto.h mainconfig.h main.h mempool.h \
quorum.h service.h sync.h timer.h tlist.h totemconfig.h \
totemmrp.h totemnet.h totemrrp.h totemsrp.h util.h \
- version.h vsf.h wthread.h
+ version.h vsf.h wthread.h schedwrk.h
EXTRA_DIST = $(LCRSO_SRC)
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais