Parcourir la source

Patch from Patrick to enable configuring the list of dynamic service handlers
in the configuration file.


git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@915 fd59a12c-fef9-0310-b244-a6a79926bd2f

Steven Dake il y a 20 ans
Parent
commit
e2d327e599
4 fichiers modifiés avec 158 ajouts et 83 suppressions
  1. 1 0
      exec/handlers.h
  2. 61 80
      exec/main.c
  3. 79 3
      exec/mainconfig.c
  4. 17 0
      exec/mainconfig.h

+ 1 - 0
exec/handlers.h

@@ -70,6 +70,7 @@ struct openais_service_handler {
 	int lib_handlers_count;
 	int lib_handlers_count;
 	struct openais_exec_handler *exec_handlers;
 	struct openais_exec_handler *exec_handlers;
 	int (*exec_init_fn) (struct openais_config *);
 	int (*exec_init_fn) (struct openais_config *);
+	int (*config_init_fn) (struct openais_config *);
 	void (*exec_dump_fn) (void);
 	void (*exec_dump_fn) (void);
 	int exec_handlers_count;
 	int exec_handlers_count;
 	void (*confchg_fn) (
 	void (*confchg_fn) (

+ 61 - 80
exec/main.c

@@ -90,72 +90,6 @@
 int ais_uid = 0;
 int ais_uid = 0;
 int gid_valid = 0;
 int gid_valid = 0;
 
 
-/*
- * All service handlers in the AIS
- */
-#ifdef BUILD_DYNAMIC
-struct dynamic_service {
-	char *name;
-	unsigned int ver;
-	unsigned int handle;
-	struct openais_service_handler_iface_ver0 *iface_ver0;
-};
-
-/*
- * Still need to know the name of the service interface and version number
- */
-struct dynamic_service dynamic_services[128] = {
-	{
-		.name			= "openais_evs",
-		.ver			= 0,
-		.handle			= 0,
-		.iface_ver0		= NULL
-	},
-	{
-		.name			= "openais_clm",
-		.ver			= 0,
-		.handle			= 0,
-		.iface_ver0		= NULL
-	},
-	{
-		.name			= "openais_amf",
-		.ver			= 0,
-		.handle			= 0,
-		.iface_ver0		= NULL
-	},
-	{
-		.name			= "openais_ckpt",
-		.ver			= 0,
-		.handle			= 0,
-		.iface_ver0		= NULL
-	},
-	{
-		.name			= "openais_evt",
-		.ver			= 0,
-		.handle			= 0,
-		.iface_ver0		= NULL
-	},
-	{
-		.name			= "openais_lck",
-		.ver			= 0,
-		.handle			= 0,
-		.iface_ver0		= NULL
-	},
-	{
-		.name			= "openais_msg",
-		.ver			= 0,
-		.handle			= 0,
-		.iface_ver0		= NULL
-	},
-	{
-		.name			= "openais_cfg",
-		.ver			= 0,
-		.handle			= 0,
-		.iface_ver0		= NULL
-	}
-};
-#endif /* BUILD_DYNAMIC */
-		
 static struct openais_service_handler *ais_service_handlers[32];
 static struct openais_service_handler *ais_service_handlers[32];
 
 
 static unsigned int service_handlers_count = 32;
 static unsigned int service_handlers_count = 32;
@@ -214,6 +148,7 @@ enum e_ais_done {
 	AIS_DONE_MAINCONFIGREAD = -9,
 	AIS_DONE_MAINCONFIGREAD = -9,
 	AIS_DONE_LOGSETUP = -10,
 	AIS_DONE_LOGSETUP = -10,
 	AIS_DONE_AMFCONFIGREAD = -11,
 	AIS_DONE_AMFCONFIGREAD = -11,
+	AIS_DONE_DYNAMICLOAD = -12,
 };
 };
 
 
 extern int openais_amf_config_read (char **error_string);
 extern int openais_amf_config_read (char **error_string);
@@ -1180,10 +1115,22 @@ int service_handler_register (
 	assert (ais_service_handlers[handler->id] == NULL);
 	assert (ais_service_handlers[handler->id] == NULL);
 	log_printf (LOG_LEVEL_NOTICE, "Registering service handler '%s'\n", handler->name);
 	log_printf (LOG_LEVEL_NOTICE, "Registering service handler '%s'\n", handler->name);
 	ais_service_handlers[handler->id] = handler;
 	ais_service_handlers[handler->id] = handler;
+	if (ais_service_handlers[handler->id]->config_init_fn) {
+		res = ais_service_handlers[handler->id]->config_init_fn (config);
+	}
+	return (res);
+}
+
+int service_handler_init (
+	struct openais_service_handler *handler,
+	struct openais_config *config)
+{
+	int res = 0;
+	assert (ais_service_handlers[handler->id] != NULL);
+	log_printf (LOG_LEVEL_NOTICE, "Initialising service handler '%s'\n", handler->name);
 	if (ais_service_handlers[handler->id]->exec_init_fn) {
 	if (ais_service_handlers[handler->id]->exec_init_fn) {
 		res = ais_service_handlers[handler->id]->exec_init_fn (config);
 		res = ais_service_handlers[handler->id]->exec_init_fn (config);
 	}
 	}
-	
 	return (res);
 	return (res);
 }
 }
 
 
@@ -1192,16 +1139,20 @@ void default_services_register (struct openais_config *openais_config)
 #ifdef BUILD_DYNAMIC
 #ifdef BUILD_DYNAMIC
 	int i;
 	int i;
 
 
-	for (i = 0; i < 8; i++) {
+	for (i = 0; i < openais_config->num_dynamic_services; i++) {
 		lcr_ifact_reference (
 		lcr_ifact_reference (
-			&dynamic_services[i].handle,
-			dynamic_services[i].name,
-			dynamic_services[i].ver,
-			(void **)&dynamic_services[i].iface_ver0,
+			&openais_config->dynamic_services[i].handle,
+			openais_config->dynamic_services[i].name,
+			openais_config->dynamic_services[i].ver,
+			(void **)&openais_config->dynamic_services[i].iface_ver0,
 			(void *)0);
 			(void *)0);
 
 
+		if (!openais_config->dynamic_services[i].iface_ver0) {
+			log_printf(LOG_LEVEL_ERROR, "AIS Component %s did not load.\n", openais_config->dynamic_services[i].name);
+			ais_done(AIS_DONE_DYNAMICLOAD);
+		}
 		service_handler_register (
 		service_handler_register (
-			dynamic_services[i].iface_ver0->openais_get_service_handler_ver0(),
+			openais_config->dynamic_services[i].iface_ver0->openais_get_service_handler_ver0(),
 			openais_config);
 			openais_config);
 	}
 	}
 
 
@@ -1221,6 +1172,32 @@ void default_services_register (struct openais_config *openais_config)
 #endif /* BUILD_DYNAMIC */
 #endif /* BUILD_DYNAMIC */
 }
 }
 
 
+void default_services_init (struct openais_config *openais_config)
+{
+#ifdef BUILD_DYNAMIC
+	int i;
+
+	for (i = 0; i < openais_config->num_dynamic_services; i++) {
+		service_handler_init (openais_config->dynamic_services[i].iface_ver0->openais_get_service_handler_ver0(),
+				      openais_config);
+	}
+
+#else /* NOT BUILD_DYNAMIC */
+	/*
+	 * link everything together - better for debugging - smaller memory footprint
+	 */
+
+	service_handler_init (&evs_service_handler, openais_config);
+	service_handler_init (&clm_service_handler, openais_config);
+	service_handler_init (&amf_service_handler, openais_config);
+	service_handler_init (&ckpt_service_handler, openais_config);
+	service_handler_init (&evt_service_handler, openais_config);
+	service_handler_init (&lck_service_handler, openais_config);
+	service_handler_init (&msg_service_handler, openais_config);
+	service_handler_init (&cfg_service_handler, openais_config);
+#endif /* BUILD_DYNAMIC */
+}
+
 int main (int argc, char **argv)
 int main (int argc, char **argv)
 {
 {
 	int libais_server_fd;
 	int libais_server_fd;
@@ -1260,12 +1237,14 @@ int main (int argc, char **argv)
 		log_printf (LOG_LEVEL_ERROR, error_string);
 		log_printf (LOG_LEVEL_ERROR, error_string);
 		ais_done (AIS_DONE_AMFCONFIGREAD);
 		ais_done (AIS_DONE_AMFCONFIGREAD);
 	}
 	}
-	
-	res = totem_config_read (&openais_config.totem_config, &error_string, 1);
-	if (res == -1) {
-		log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: Copyright (C) 2002-2004 MontaVista Software, Inc and contributors.\n");
-		log_printf (LOG_LEVEL_ERROR, error_string);
-		ais_done (AIS_DONE_MAINCONFIGREAD);
+
+	if (!openais_config.totem_config.interface_count) {
+		res = totem_config_read (&openais_config.totem_config, &error_string, 1);
+		if (res == -1) {
+			log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: Copyright (C) 2002-2004 MontaVista Software, Inc and contributors.\n");
+			log_printf (LOG_LEVEL_ERROR, error_string);
+			ais_done (AIS_DONE_MAINCONFIGREAD);
+		}
 	}
 	}
 
 
 	res = totem_config_keyread ("/etc/ais/authkey", &openais_config.totem_config, &error_string);
 	res = totem_config_keyread ("/etc/ais/authkey", &openais_config.totem_config, &error_string);
@@ -1306,6 +1285,8 @@ int main (int argc, char **argv)
 	openais_config.totem_config.totem_logging_configuration.log_level_debug = mklog (LOG_LEVEL_DEBUG, LOG_SERVICE_GMI);
 	openais_config.totem_config.totem_logging_configuration.log_level_debug = mklog (LOG_LEVEL_DEBUG, LOG_SERVICE_GMI);
 	openais_config.totem_config.totem_logging_configuration.log_printf = internal_log_printf;
 	openais_config.totem_config.totem_logging_configuration.log_printf = internal_log_printf;
 
 
+	default_services_register(&openais_config); 
+	
 	totempg_initialize (
 	totempg_initialize (
 		aisexec_poll_handle,
 		aisexec_poll_handle,
 		&openais_config.totem_config);
 		&openais_config.totem_config);
@@ -1322,7 +1303,7 @@ int main (int argc, char **argv)
 
 
 	this_ip = &openais_config.totem_config.interfaces[0].boundto;
 	this_ip = &openais_config.totem_config.interfaces[0].boundto;
 
 
-	default_services_register(&openais_config);
+	default_services_init(&openais_config); 
 
 
 	sync_register (openais_sync_callbacks_retrieve, openais_sync_completed);
 	sync_register (openais_sync_callbacks_retrieve, openais_sync_completed);
 
 

+ 79 - 3
exec/mainconfig.c

@@ -56,7 +56,8 @@ typedef enum {
 	MAIN_HEAD,
 	MAIN_HEAD,
 	MAIN_LOGGING,
 	MAIN_LOGGING,
 	MAIN_EVENT,
 	MAIN_EVENT,
-	MAIN_AMF
+	MAIN_AMF,
+	MAIN_COMPONENTS
 } main_parse_t;
 } main_parse_t;
 
 
 char *strstr_rs (const char *haystack, const char *needle)
 char *strstr_rs (const char *haystack, const char *needle)
@@ -87,6 +88,55 @@ char *strstr_rs (const char *haystack, const char *needle)
 	return (end_address);
 	return (end_address);
 }
 }
 
 
+#ifdef BUILD_DYNAMIC
+static void set_default_services(struct openais_config *config)
+{
+	config->dynamic_services[0].name = "openais_evs";
+	config->dynamic_services[0].ver = 0;
+	config->dynamic_services[1].name = "openais_clm";
+	config->dynamic_services[1].ver = 0;
+	config->dynamic_services[2].name = "openais_amf";
+	config->dynamic_services[2].ver = 0;
+	config->dynamic_services[3].name = "openais_ckpt";
+	config->dynamic_services[3].ver = 0;
+	config->dynamic_services[4].name = "openais_evt";
+	config->dynamic_services[4].ver = 0;
+	config->dynamic_services[5].name = "openais_lck";
+	config->dynamic_services[5].ver = 0;
+	config->dynamic_services[6].name = "openais_msg";
+	config->dynamic_services[6].ver = 0;
+	config->dynamic_services[7].name = "openais_cfg";
+	config->dynamic_services[7].ver = 0;
+	config->num_dynamic_services = 8;
+}
+
+/* Returns an allocated string */
+static char *get_component(const char *line, int *version)
+{
+	char *start_address;
+	char *end_address;
+	char *newline;
+	char *compname;
+
+	newline = strdup(line);
+
+	start_address = newline + strspn(newline, " \t");
+	end_address = start_address + strcspn(start_address, " \t:");
+
+	*end_address = '\0';
+	compname = strdup(start_address);
+
+	/* Now get version */
+	start_address = end_address+1;
+	start_address = start_address + strspn(start_address, " \t:");
+
+	*version = atoi(start_address);
+	free(newline);
+
+	return compname;
+}
+#endif
+
 extern int openais_main_config_read (char **error_string,
 extern int openais_main_config_read (char **error_string,
     struct openais_config *openais_config,
     struct openais_config *openais_config,
 	int interface_max)
 	int interface_max)
@@ -97,6 +147,7 @@ extern int openais_main_config_read (char **error_string,
 	int logging_parsed = 0;
 	int logging_parsed = 0;
 	int event_parsed = 0;
 	int event_parsed = 0;
 	int amf_parsed = 0;
 	int amf_parsed = 0;
+	int components_parsed = 0;
 	char *loc;
 	char *loc;
 	int i;
 	int i;
 	int parse_done = 0;
 	int parse_done = 0;
@@ -147,6 +198,10 @@ extern int openais_main_config_read (char **error_string,
 			if (amf_parsed == 0 && strstr_rs (line, "amf{")) {
 			if (amf_parsed == 0 && strstr_rs (line, "amf{")) {
 				amf_parsed = 1;
 				amf_parsed = 1;
 				parse = MAIN_AMF;
 				parse = MAIN_AMF;
+			} else
+			if (components_parsed == 0 && strstr_rs (line, "components{")) {
+				components_parsed = 1;
+				parse = MAIN_COMPONENTS;
 			} else {
 			} else {
 				continue;
 				continue;
 			}
 			}
@@ -225,10 +280,25 @@ extern int openais_main_config_read (char **error_string,
 				goto parse_error;
 				goto parse_error;
 			}
 			}
 			break;
 			break;
-
+		case MAIN_COMPONENTS:
+			if ((loc = strstr_rs (line, "}"))) {
+				parse = MAIN_HEAD;
+			}
+#ifdef BUILD_DYNAMIC
+			else {
+				int version;
+				char *name = get_component(line, &version);
+				if (name) {
+					openais_config->dynamic_services[openais_config->num_dynamic_services].name = name;
+					openais_config->dynamic_services[openais_config->num_dynamic_services].ver = version;
+					openais_config->num_dynamic_services++;
+				}
+			}
+#endif
+			break;
 		default:
 		default:
 			assert (0 == 1); /* SHOULDN'T HAPPEN */
 			assert (0 == 1); /* SHOULDN'T HAPPEN */
-			break;	
+			break;
 		}
 		}
 	}
 	}
 
 
@@ -237,6 +307,12 @@ extern int openais_main_config_read (char **error_string,
 		goto parse_error;
 		goto parse_error;
 	}
 	}
 
 
+#ifdef BUILD_DYNAMIC
+	/* Load default services if the config file doesn't specify */
+	if (!openais_config->num_dynamic_services) {
+		set_default_services(openais_config);
+	}
+#endif
 	if (parse == MAIN_HEAD) {
 	if (parse == MAIN_HEAD) {
 		fclose (fp);
 		fclose (fp);
 		return (0);
 		return (0);

+ 17 - 0
exec/mainconfig.h

@@ -41,6 +41,19 @@
 #ifndef MAINCONFIG_H_DEFINED
 #ifndef MAINCONFIG_H_DEFINED
 #define MAINCONFIG_H_DEFINED
 #define MAINCONFIG_H_DEFINED
 
 
+/*
+ * All service handlers in the AIS
+ */
+#ifdef BUILD_DYNAMIC
+struct dynamic_service {
+	char *name;
+	unsigned int ver;
+	unsigned int handle;
+	struct openais_service_handler_iface_ver0 *iface_ver0;
+};
+#define MAX_DYNAMIC_SERVICES 128
+#endif
+
 struct openais_config {
 struct openais_config {
 	/*
 	/*
 	 * logging
 	 * logging
@@ -60,6 +73,10 @@ struct openais_config {
 	unsigned int amf_enabled;
 	unsigned int amf_enabled;
 
 
 	struct totem_config totem_config;
 	struct totem_config totem_config;
+#ifdef BUILD_DYNAMIC
+	struct dynamic_service dynamic_services[MAX_DYNAMIC_SERVICES];
+	int num_dynamic_services;
+#endif
 };
 };
 
 
 extern char *strstr_rs (const char *haystack, const char *needle);
 extern char *strstr_rs (const char *haystack, const char *needle);