Browse Source

Honor exec_init_fn call

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.  This patch adds ykd and makes other suggestions
from Fabio Di Nitto.

Signed-off-by: Steven Dake <sdake@redhat.com>
Reviewed-by: Fabio Di Nitto <fdinitto@redhat.com>
Steven Dake 14 năm trước cách đây
mục cha
commit
007e5c9458
16 tập tin đã thay đổi với 87 bổ sung72 xóa
  1. 3 3
      exec/cfg.c
  2. 3 3
      exec/cmap.c
  3. 3 3
      exec/cpg.c
  4. 3 3
      exec/evs.c
  5. 3 5
      exec/mon.c
  6. 3 5
      exec/pload.c
  7. 18 6
      exec/service.c
  8. 1 1
      exec/service.h
  9. 1 0
      exec/util.h
  10. 21 17
      exec/votequorum.c
  11. 2 2
      exec/votequorum.h
  12. 14 12
      exec/vsf_quorum.c
  13. 6 4
      exec/vsf_ykd.c
  14. 2 2
      exec/vsf_ykd.h
  15. 3 5
      exec/wd.c
  16. 1 1
      include/corosync/coroapi.h

+ 3 - 3
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 (

+ 3 - 3
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)

+ 3 - 3
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)

+ 3 - 3
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;

+ 3 - 5
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;
 }
 
 

+ 3 - 5
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 (

+ 18 - 6
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);

+ 1 - 1
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);
 

+ 1 - 0
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)		\

+ 21 - 17
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);
 }
 
 /*

+ 2 - 2
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 */

+ 14 - 12
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();
@@ -275,20 +276,21 @@ static int quorum_exec_init_fn (struct corosync_api_v1 *api)
 		log_printf (LOGSYS_LEVEL_NOTICE,
 			    "Using quorum provider %s", quorum_module);
 
+		error = (char *)"Invalid quorum provider";
+
 		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);
+			quorum_type = 1;
 		}
 		if (strcmp (quorum_module, "corosync_ykd") == 0) {
-			if (ykd_init (api, quorum_api_set_quorum) == CS_OK) {
-				quorum_type = 1;
-			}
+			error = ykd_init (api, quorum_api_set_quorum);
+			quorum_type = 1;
 		}
-
-		if (quorum_type == 0) {
+		if (error) {
 			log_printf (LOGSYS_LEVEL_CRIT, 
-				    "Quorum provider: %s failed to initialize", quorum_module);
+				"Quorum provider: %s failed to initialize.",
+				 quorum_module);
+			return (error);
 		}
 	}
 
@@ -306,7 +308,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)

+ 6 - 4
exec/vsf_ykd.c

@@ -508,15 +508,17 @@ struct corosync_tpg_group ykd_group = {
 	.group_len	= 3
 };
 
-cs_error_t ykd_init (
+char *ykd_init (
 	struct corosync_api_v1 *corosync_api,
 	quorum_set_quorate_fn_t set_primary)
 {
+	char *error;
+
 	ykd_primary_callback_fn = set_primary;
 	api = corosync_api;
 
-	if ((!corosync_api) || (!set_primary)) {
-		return CS_ERR_INVALID_PARAM;
+	if (set_primary == 0) {
+		error = (char *)"set primary not set";
 	}
 
 	api->tpg_init (
@@ -531,5 +533,5 @@ cs_error_t ykd_init (
 
 	ykd_state_init ();
 
-	return CS_OK;
+	return ((char *)error);
 }

+ 2 - 2
exec/vsf_ykd.h

@@ -38,7 +38,7 @@
 #include <corosync/list.h>
 #include <corosync/coroapi.h>
 
-extern cs_error_t ykd_init(struct corosync_api_v1 *api,
-				  quorum_set_quorate_fn_t set_primary);
+char *ykd_init(struct corosync_api_v1 *api,
+	quorum_set_quorate_fn_t set_primary);
 
 #endif /* VFS_YKD_H_DEFINED */

+ 3 - 5
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)

+ 1 - 1
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);