exec_init_fn now either returns NULL (success) or a string which indicates the error that occured during service engine initialization. If an error occurs, corosync will exit. Signed-off-by: Steven Dake <sdake@xxxxxxxxxx> --- exec/cfg.c | 6 +++--- exec/cmap.c | 6 +++--- exec/cpg.c | 6 +++--- exec/evs.c | 6 +++--- exec/mon.c | 8 +++----- exec/pload.c | 8 +++----- exec/service.c | 24 ++++++++++++++++++------ exec/service.h | 2 +- exec/util.h | 1 + exec/votequorum.c | 38 +++++++++++++++++++++----------------- exec/votequorum.h | 4 ++-- exec/vsf_quorum.c | 16 ++++++++++------ exec/wd.c | 8 +++----- include/corosync/coroapi.h | 2 +- 14 files changed, 75 insertions(+), 60 deletions(-) diff --git a/exec/cfg.c b/exec/cfg.c index fe1abe2..f195395 100644 --- a/exec/cfg.c +++ b/exec/cfg.c @@ -103,7 +103,7 @@ static void cfg_confchg_fn ( const unsigned int *joined_list, size_t joined_list_entries, const struct memb_ring_id *ring_id); -static int cfg_exec_init_fn (struct corosync_api_v1 *corosync_api_v1); +static char *cfg_exec_init_fn (struct corosync_api_v1 *corosync_api_v1); static struct corosync_api_v1 *api; @@ -313,7 +313,7 @@ struct req_exec_cfg_shutdown { /* IMPL */ -static int cfg_exec_init_fn ( +static char *cfg_exec_init_fn ( struct corosync_api_v1 *corosync_api_v1) { #ifdef COROSYNC_SOLARIS @@ -323,7 +323,7 @@ static int cfg_exec_init_fn ( api = corosync_api_v1; list_init(&trackers_list); - return (0); + return (NULL); } static void cfg_confchg_fn ( diff --git a/exec/cmap.c b/exec/cmap.c index 0f7d2e2..9cff299 100644 --- a/exec/cmap.c +++ b/exec/cmap.c @@ -77,7 +77,7 @@ struct cmap_track_user_data { static struct corosync_api_v1 *api; -static int cmap_exec_init_fn (struct corosync_api_v1 *corosync_api); +static char *cmap_exec_init_fn (struct corosync_api_v1 *corosync_api); static int cmap_exec_exit_fn(void); static int cmap_lib_init_fn (void *conn); @@ -168,7 +168,7 @@ static int cmap_exec_exit_fn(void) return 0; } -static int cmap_exec_init_fn ( +static char *cmap_exec_init_fn ( struct corosync_api_v1 *corosync_api) { @@ -177,7 +177,7 @@ static int cmap_exec_init_fn ( #endif api = corosync_api; - return (0); + return (NULL); } static int cmap_lib_init_fn (void *conn) diff --git a/exec/cpg.c b/exec/cpg.c index 7b26678..0fdcc30 100644 --- a/exec/cpg.c +++ b/exec/cpg.c @@ -198,7 +198,7 @@ struct join_list_entry { /* * Service Interfaces required by service_message_handler struct */ -static int cpg_exec_init_fn (struct corosync_api_v1 *); +static char *cpg_exec_init_fn (struct corosync_api_v1 *); static int cpg_lib_init_fn (void *conn); @@ -864,14 +864,14 @@ static void downlist_messages_delete (void) } -static int cpg_exec_init_fn (struct corosync_api_v1 *corosync_api) +static char *cpg_exec_init_fn (struct corosync_api_v1 *corosync_api) { #ifdef COROSYNC_SOLARIS logsys_subsys_init(); #endif list_init (&downlist_messages_head); api = corosync_api; - return (0); + return (NULL); } static void cpg_iteration_instance_finalize (struct cpg_iteration_instance *cpg_iteration_instance) diff --git a/exec/evs.c b/exec/evs.c index 24a1f4b..0fe2d3d 100644 --- a/exec/evs.c +++ b/exec/evs.c @@ -74,7 +74,7 @@ enum evs_exec_message_req_types { /* * Service Interfaces required by service_message_handler struct */ -static int evs_exec_init_fn ( +static char *evs_exec_init_fn ( struct corosync_api_v1 *corosync_api); static void evs_confchg_fn ( @@ -163,7 +163,7 @@ struct corosync_service_engine *evs_get_service_engine_ver0 (void) return (&evs_service_engine); } -static int evs_exec_init_fn ( +static char *evs_exec_init_fn ( struct corosync_api_v1 *corosync_api) { #ifdef COROSYNC_SOLARIS @@ -172,7 +172,7 @@ static int evs_exec_init_fn ( api = corosync_api; - return 0; + return NULL; } struct res_evs_confchg_callback res_evs_confchg_callback; diff --git a/exec/mon.c b/exec/mon.c index 95d07fb..344ff0a 100644 --- a/exec/mon.c +++ b/exec/mon.c @@ -54,8 +54,7 @@ LOGSYS_DECLARE_SUBSYS ("MON"); /* * Service Interfaces required by service_message_handler struct */ -static int mon_exec_init_fn ( - struct corosync_api_v1 *corosync_api); +static char *mon_exec_init_fn (struct corosync_api_v1 *corosync_api); static struct corosync_api_v1 *api; #define MON_DEFAULT_PERIOD 3000 @@ -484,8 +483,7 @@ static void mon_instance_init (struct resource_instance* inst) mon_key_changed_cb, inst, &icmap_track); } -static int mon_exec_init_fn ( - struct corosync_api_v1 *corosync_api) +static char *mon_exec_init_fn (struct corosync_api_v1 *corosync_api) { #ifdef HAVE_LIBSTATGRAB @@ -500,7 +498,7 @@ static int mon_exec_init_fn ( mon_instance_init (&memory_used_inst); mon_instance_init (&load_15min_inst); - return 0; + return NULL; } diff --git a/exec/pload.c b/exec/pload.c index 35fc239..edefe25 100644 --- a/exec/pload.c +++ b/exec/pload.c @@ -77,8 +77,7 @@ enum pload_exec_message_req_types { /* * Service Interfaces required by service_message_handler struct */ -static int pload_exec_init_fn ( - struct corosync_api_v1 *corosync_api); +static char *pload_exec_init_fn (struct corosync_api_v1 *corosync_api); static void pload_confchg_fn ( enum totem_configuration_type configuration_type, @@ -176,15 +175,14 @@ struct corosync_service_engine *pload_get_service_engine_ver0 (void) return (&pload_service_engine); } -static int pload_exec_init_fn ( - struct corosync_api_v1 *corosync_api) +static char *pload_exec_init_fn (struct corosync_api_v1 *corosync_api) { #ifdef COROSYNC_SOLARIS logsys_subsys_init(); #endif api = corosync_api; - return 0; + return NULL; } static void pload_confchg_fn ( diff --git a/exec/service.c b/exec/service.c index fc87f45..3239d0f 100644 --- a/exec/service.c +++ b/exec/service.c @@ -123,15 +123,15 @@ int corosync_service_exiting[SERVICE_HANDLER_MAXIMUM_COUNT]; static void (*service_unlink_all_complete) (void) = NULL; -unsigned int corosync_service_link_and_init ( +char *corosync_service_link_and_init ( struct corosync_api_v1 *corosync_api, struct default_service *service) { struct corosync_service_engine *service_engine; - int res = 0; int fn; char *name_sufix; char key_name[ICMAP_KEYNAME_MAXLEN]; + char *init_result; /* * Initialize service @@ -141,11 +141,14 @@ unsigned int corosync_service_link_and_init ( corosync_service[service_engine->id] = service_engine; if (service_engine->config_init_fn) { - res = service_engine->config_init_fn (corosync_api); + service_engine->config_init_fn (corosync_api); } if (service_engine->exec_init_fn) { - res = service_engine->exec_init_fn (corosync_api); + init_result = service_engine->exec_init_fn (corosync_api); + if (init_result) { + return (init_result); + } } /* @@ -181,7 +184,8 @@ unsigned int corosync_service_link_and_init ( log_printf (LOGSYS_LEVEL_NOTICE, "Service engine loaded: %s [%d]", service_engine->name, service_engine->id); cs_ipcs_service_init(service_engine); - return (res); + + return NULL; } static int service_priority_max(void) @@ -342,14 +346,22 @@ static unsigned int service_unlink_and_exit ( unsigned int corosync_service_defaults_link_and_init (struct corosync_api_v1 *corosync_api) { unsigned int i; + char *error; for (i = 0; i < sizeof (default_services) / sizeof (struct default_service); i++) { default_services[i].loader(); - corosync_service_link_and_init ( + error = corosync_service_link_and_init ( corosync_api, &default_services[i]); + if (error) { + log_printf(LOGSYS_LEVEL_ERROR, + "Service engine '%s' failed to load for reason '%s'", + default_services[i].name, + error); + corosync_exit_error (COROSYNC_DONE_SERVICE_ENGINE_INIT); + } } return (0); diff --git a/exec/service.h b/exec/service.h index 67d4b94..d339702 100644 --- a/exec/service.h +++ b/exec/service.h @@ -48,7 +48,7 @@ struct default_service { /** * Link and initialize a service */ -unsigned int corosync_service_link_and_init ( +char *corosync_service_link_and_init ( struct corosync_api_v1 *objdb, struct default_service *service_engine); diff --git a/exec/util.h b/exec/util.h index 9462ac2..78777ed 100644 --- a/exec/util.h +++ b/exec/util.h @@ -64,6 +64,7 @@ enum e_corosync_done { COROSYNC_DONE_AQUIRE_LOCK = 17, COROSYNC_DONE_ALREADY_RUNNING = 18, COROSYNC_DONE_STD_TO_NULL_REDIR = 19, + COROSYNC_DONE_SERVICE_ENGINE_INIT = 20 }; static inline cs_error_t hdb_error_to_cs (int res) \ diff --git a/exec/votequorum.c b/exec/votequorum.c index 79ac459..7e977ed 100644 --- a/exec/votequorum.c +++ b/exec/votequorum.c @@ -218,7 +218,7 @@ static quorum_set_quorate_fn_t quorum_callback; * votequorum_exec handler and definitions */ -static int votequorum_exec_init_fn (struct corosync_api_v1 *api); +static char *votequorum_exec_init_fn (struct corosync_api_v1 *api); static void message_handler_req_exec_votequorum_nodeinfo ( const void *message, @@ -714,7 +714,7 @@ static int votequorum_read_nodelist_configuration(uint32_t *votes, * votequorum_readconfig_dynamic */ -static int votequorum_readconfig_static(void) +static char *votequorum_readconfig_static(void) { uint32_t node_votes, node_expected_votes, expected_votes; @@ -735,9 +735,7 @@ static int votequorum_readconfig_static(void) if ((votequorum_read_nodelist_configuration(&node_votes, &node_expected_votes)) && (icmap_get_uint32("quorum.expected_votes", &expected_votes) != CS_OK)) { - log_printf(LOGSYS_LEVEL_CRIT, - "configuration error: nodelist or quorum.expected_votes must be configured!"); - return -1; + return ((char *)"configuration error: nodelist or quorum.expected_votes must be configured!"); } if (wait_for_all) { @@ -746,7 +744,7 @@ static int votequorum_readconfig_static(void) LEAVE(); - return 0; + return (NULL); } static void votequorum_readconfig_dynamic(void) @@ -1146,7 +1144,7 @@ static void message_handler_req_exec_votequorum_reconfigure ( LEAVE(); } -static int votequorum_exec_init_fn (struct corosync_api_v1 *api) +static char *votequorum_exec_init_fn (struct corosync_api_v1 *api) { #ifdef COROSYNC_SOLARIS logsys_subsys_init(); @@ -1163,7 +1161,7 @@ static int votequorum_exec_init_fn (struct corosync_api_v1 *api) us = allocate_node(corosync_api->totem_nodeid_get()); if (!us) { LEAVE(); - return (1); + return ((char *)"Could not allocate node."); } us->flags |= NODE_FLAGS_US; @@ -1185,7 +1183,7 @@ static int votequorum_exec_init_fn (struct corosync_api_v1 *api) LEAVE(); - return (0); + return (NULL); } /* @@ -1268,28 +1266,34 @@ static void votequorum_confchg_fn ( } -cs_error_t votequorum_init(struct corosync_api_v1 *api, +char *votequorum_init(struct corosync_api_v1 *api, quorum_set_quorate_fn_t q_set_quorate_fn) { + char *error; + ENTER(); - if ((!api) || (!q_set_quorate_fn)) { - return CS_ERR_INVALID_PARAM; + if (q_set_quorate_fn == NULL) { + return ((char *)"Quorate function not set"); } corosync_api = api; quorum_callback = q_set_quorate_fn; - if (votequorum_readconfig_static()) { - return CS_ERR_INVALID_PARAM; + error = votequorum_readconfig_static(); + if (error) { + return (error); } - corosync_service_link_and_init(corosync_api, - &votequorum_service[0]); + error = corosync_service_link_and_init(corosync_api, + &votequorum_service[0]); + if (error) { + return (error); + } LEAVE(); - return CS_OK; + return (NULL); } /* diff --git a/exec/votequorum.h b/exec/votequorum.h index 60b6049..a6701a8 100644 --- a/exec/votequorum.h +++ b/exec/votequorum.h @@ -38,7 +38,7 @@ #include <corosync/list.h> #include <corosync/coroapi.h> -extern cs_error_t votequorum_init(struct corosync_api_v1 *api, - quorum_set_quorate_fn_t q_set_quorate_fn); +char *votequorum_init(struct corosync_api_v1 *api, + quorum_set_quorate_fn_t q_set_quorate_fn); #endif /* VOTEQUORUM_H_DEFINED */ diff --git a/exec/vsf_quorum.c b/exec/vsf_quorum.c index 173b482..7de9bc4 100644 --- a/exec/vsf_quorum.c +++ b/exec/vsf_quorum.c @@ -96,7 +96,7 @@ static void message_handler_req_lib_quorum_gettype (void *conn, const void *msg); static void send_library_notification(void *conn); static void send_internal_notification(void); -static int quorum_exec_init_fn (struct corosync_api_v1 *api); +static char *quorum_exec_init_fn (struct corosync_api_v1 *api); static int quorum_lib_init_fn (void *conn); static int quorum_lib_exit_fn (void *conn); @@ -252,9 +252,10 @@ static struct quorum_callin_functions callins = { /* --------------------------------------------------------------------- */ -static int quorum_exec_init_fn (struct corosync_api_v1 *api) +static char *quorum_exec_init_fn (struct corosync_api_v1 *api) { char *quorum_module = NULL; + char *error; #ifdef COROSYNC_SOLARIS logsys_subsys_init(); @@ -276,9 +277,11 @@ static int quorum_exec_init_fn (struct corosync_api_v1 *api) "Using quorum provider %s", quorum_module); if (strcmp (quorum_module, "corosync_votequorum") == 0) { - if (votequorum_init (api, quorum_api_set_quorum) == CS_OK) { - quorum_type = 1; + error = votequorum_init (api, quorum_api_set_quorum); + if (error) { + return (error); } + quorum_type = 1; } if (strcmp (quorum_module, "corosync_ykd") == 0) { if (ykd_init (api, quorum_api_set_quorum) == CS_OK) { @@ -288,7 +291,8 @@ static int quorum_exec_init_fn (struct corosync_api_v1 *api) if (quorum_type == 0) { log_printf (LOGSYS_LEVEL_CRIT, - "Quorum provider: %s failed to initialize", quorum_module); + "Quorum provider: %s failed to initialize.", + quorum_module); } } @@ -306,7 +310,7 @@ static int quorum_exec_init_fn (struct corosync_api_v1 *api) primary_designated = 1; } - return (0); + return (NULL); } static int quorum_lib_init_fn (void *conn) diff --git a/exec/wd.c b/exec/wd.c index 551962a..1a6f685 100644 --- a/exec/wd.c +++ b/exec/wd.c @@ -75,8 +75,7 @@ LOGSYS_DECLARE_SUBSYS("WD"); /* * Service Interfaces required by service_message_handler struct */ -static int wd_exec_init_fn ( - struct corosync_api_v1 *corosync_api); +static char *wd_exec_init_fn (struct corosync_api_v1 *corosync_api); static int wd_exec_exit_fn (void); static void wd_resource_check_fn (void* resource_ref); @@ -671,8 +670,7 @@ static void watchdog_timeout_get_initial (void) } -static int wd_exec_init_fn ( - struct corosync_api_v1 *corosync_api) +static char *wd_exec_init_fn (struct corosync_api_v1 *corosync_api) { ENTER(); @@ -690,7 +688,7 @@ static int wd_exec_init_fn ( api->timer_add_duration(tickle_timeout*MILLI_2_NANO_SECONDS, NULL, wd_tickle_fn, &wd_timer); - return 0; + return NULL; } static int wd_exec_exit_fn (void) diff --git a/include/corosync/coroapi.h b/include/corosync/coroapi.h index fa6a510..ca20469 100644 --- a/include/corosync/coroapi.h +++ b/include/corosync/coroapi.h @@ -443,7 +443,7 @@ struct corosync_service_engine { unsigned int private_data_size; enum cs_lib_flow_control flow_control; enum cs_lib_allow_inquorate allow_inquorate; - int (*exec_init_fn) (struct corosync_api_v1 *); + char *(*exec_init_fn) (struct corosync_api_v1 *); int (*exec_exit_fn) (void); void (*exec_dump_fn) (void); int (*lib_init_fn) (void *conn); -- 1.7.7.5 _______________________________________________ discuss mailing list discuss@xxxxxxxxxxxx http://lists.corosync.org/mailman/listinfo/discuss