Просмотр исходного кода

defect 1139
reorg of code to better support creating external service handlers


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

Steven Dake 20 лет назад
Родитель
Сommit
6a49f1befc
8 измененных файлов с 57 добавлено и 111 удалено
  1. 1 0
      exec/amf.c
  2. 2 2
      exec/ckpt.c
  3. 28 29
      exec/main.c
  4. 17 52
      exec/mainconfig.c
  5. 2 15
      exec/mainconfig.h
  6. 1 1
      exec/objdb.c
  7. 2 3
      exec/service.c
  8. 4 9
      exec/service.h

+ 1 - 0
exec/amf.c

@@ -859,6 +859,7 @@ static int amf_exec_init_fn (struct objdb_iface_ver0 *objdb)
 						    strlen ("mode"),
 						    (void *)&value,
 						    NULL) && value) {
+
 			if (strcmp (value, "enabled") == 0) {
 				enabled = 1;
 			} else

+ 2 - 2
exec/ckpt.c

@@ -129,7 +129,7 @@ struct ckpt_identifier {
 
 /* TODO static totempg_recovery_plug_handle ckpt_checkpoint_recovery_plug_handle; */
 
-static int ckpt_exec_init_fn (struct openais_config *);
+static int ckpt_exec_init_fn (struct objdb_iface_ver0 *);
 
 static int ckpt_lib_exit_fn (void *conn);
 
@@ -1508,7 +1508,7 @@ int ckpt_checkpoint_close (struct saCkptCheckpoint *checkpoint) {
 	return (-1);
 }
 
-static int ckpt_exec_init_fn (struct openais_config *openais_config)
+static int ckpt_exec_init_fn (struct objdb_iface_ver0 *objdb)
 {
 	/*
 	 *  Initialize the saved ring ID.

+ 28 - 29
exec/main.c

@@ -976,22 +976,22 @@ static void confchg_fn (
 	}
 }
 
-static void aisexec_uid_determine (struct openais_config *openais_config)
+static void aisexec_uid_determine (struct main_config *main_config)
 {
 	struct passwd *passwd;
 
-	passwd = getpwnam(openais_config->user);
+	passwd = getpwnam(main_config->user);
 	if (passwd == 0) {
-		log_printf (LOG_LEVEL_ERROR, "ERROR: The '%s' user is not found in /etc/passwd, please read the documentation.\n", openais_config->user);
+		log_printf (LOG_LEVEL_ERROR, "ERROR: The '%s' user is not found in /etc/passwd, please read the documentation.\n", main_config->user);
 		openais_exit_error (AIS_DONE_UID_DETERMINE);
 	}
 	ais_uid = passwd->pw_uid;
 }
 
-static void aisexec_gid_determine (struct openais_config *openais_config)
+static void aisexec_gid_determine (struct main_config *main_config)
 {
 	struct group *group;
-	group = getgrnam (openais_config->group);
+	group = getgrnam (main_config->group);
 	if (group == 0) {
 		log_printf (LOG_LEVEL_ERROR, "ERROR: The '%s' group is not found in /etc/group, please read the documentation.\n", group);
 		openais_exit_error (AIS_DONE_GID_DETERMINE);
@@ -1155,7 +1155,8 @@ int main (int argc, char **argv)
 {
 	int libais_server_fd;
 	char *error_string;
-	struct openais_config openais_config;
+	struct main_config main_config;
+	struct totem_config totem_config;
 	unsigned int objdb_handle;
 	unsigned int config_handle;
 	unsigned int config_version = 0;
@@ -1214,9 +1215,9 @@ int main (int argc, char **argv)
 
 	openais_service_default_objdb_set (objdb);
 
-	openais_service_link_all (objdb, &openais_config);
+	openais_service_link_all (objdb);
 
-	res = openais_main_config_read (objdb, &error_string, &openais_config, 1);
+	res = openais_main_config_read (objdb, &error_string, &main_config, 1);
 	if (res == -1) {
 		log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: Copyright (C) 2002-2006 MontaVista Software, Inc and contributors.\n");
 
@@ -1224,36 +1225,34 @@ int main (int argc, char **argv)
 		openais_exit_error (AIS_DONE_MAINCONFIGREAD);
 	}
 
-	if (!openais_config.totem_config.interface_count) {
-		res = totem_config_read (objdb, &openais_config.totem_config, &error_string, 1);
-		if (res == -1) {
-			log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: Copyright (C) 2002-2006 MontaVista Software, Inc and contributors.\n");
-			log_printf (LOG_LEVEL_ERROR, error_string);
-			openais_exit_error (AIS_DONE_MAINCONFIGREAD);
-		}
+	res = totem_config_read (objdb, &totem_config, &error_string, 1);
+	if (res == -1) {
+		log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: Copyright (C) 2002-2006 MontaVista Software, Inc and contributors.\n");
+		log_printf (LOG_LEVEL_ERROR, error_string);
+		openais_exit_error (AIS_DONE_MAINCONFIGREAD);
 	}
 
-	res = totem_config_keyread (objdb, &openais_config.totem_config, &error_string);
+	res = totem_config_keyread (objdb, &totem_config, &error_string);
 	if (res == -1) {
 		log_printf (LOG_LEVEL_ERROR, error_string);
 		openais_exit_error (AIS_DONE_MAINCONFIGREAD);
 	}
 
-	res = totem_config_validate (&openais_config.totem_config, &error_string);
+	res = totem_config_validate (&totem_config, &error_string);
 	if (res == -1) {
 		log_printf (LOG_LEVEL_ERROR, error_string);
 		openais_exit_error (AIS_DONE_MAINCONFIGREAD);
 	}
 
-	res = log_setup (&error_string, openais_config.logmode, openais_config.logfile);
+	res = log_setup (&error_string, main_config.logmode, main_config.logfile);
 	if (res == -1) {
 		log_printf (LOG_LEVEL_ERROR, error_string);
 		openais_exit_error (AIS_DONE_LOGSETUP);
 	}
 
-	aisexec_uid_determine (&openais_config);
+	aisexec_uid_determine (&main_config);
 
-	aisexec_gid_determine (&openais_config);
+	aisexec_gid_determine (&main_config);
 
 	log_printf (LOG_LEVEL_NOTICE, "AIS Executive Service: Copyright (C) 2002-2006 MontaVista Software, Inc. and contributors.\n");
 
@@ -1266,14 +1265,14 @@ int main (int argc, char **argv)
 
 	aisexec_mlockall ();
 
-	openais_config.totem_config.totem_logging_configuration = totem_logging_configuration;
+	totem_config.totem_logging_configuration = totem_logging_configuration;
 
-	openais_config.totem_config.totem_logging_configuration.log_level_security = mklog (LOG_LEVEL_SECURITY, LOG_SERVICE_GMI);
-	openais_config.totem_config.totem_logging_configuration.log_level_error = mklog (LOG_LEVEL_ERROR, LOG_SERVICE_GMI);
-	openais_config.totem_config.totem_logging_configuration.log_level_warning = mklog (LOG_LEVEL_WARNING, LOG_SERVICE_GMI);
-	openais_config.totem_config.totem_logging_configuration.log_level_notice = mklog (LOG_LEVEL_NOTICE, 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;
+	totem_config.totem_logging_configuration.log_level_security = mklog (LOG_LEVEL_SECURITY, LOG_SERVICE_GMI);
+	totem_config.totem_logging_configuration.log_level_error = mklog (LOG_LEVEL_ERROR, LOG_SERVICE_GMI);
+	totem_config.totem_logging_configuration.log_level_warning = mklog (LOG_LEVEL_WARNING, LOG_SERVICE_GMI);
+	totem_config.totem_logging_configuration.log_level_notice = mklog (LOG_LEVEL_NOTICE, LOG_SERVICE_GMI);
+	totem_config.totem_logging_configuration.log_level_debug = mklog (LOG_LEVEL_DEBUG, LOG_SERVICE_GMI);
+	totem_config.totem_logging_configuration.log_printf = internal_log_printf;
 
 	/*
 	 * if totempg_initialize doesn't have root priveleges, it cannot
@@ -1283,7 +1282,7 @@ int main (int argc, char **argv)
 	 */
 	totempg_initialize (
 		aisexec_poll_handle,
-		&openais_config.totem_config);
+		&totem_config);
 
 	totempg_groups_initialize (
 		&openais_group_handle,
@@ -1298,7 +1297,7 @@ int main (int argc, char **argv)
 	/*
 	 * This must occur after totempg is initialized because "this_ip" must be set
 	 */
-	this_ip = &openais_config.totem_config.interfaces[0].boundto;
+	this_ip = &totem_config.interfaces[0].boundto;
 	openais_service_init_all (service_count, objdb);
 
 

+ 17 - 52
exec/mainconfig.c

@@ -80,14 +80,14 @@ static inline int objdb_get_string(struct objdb_iface_ver0 *objdb, unsigned int
 extern int openais_main_config_read (
 	struct objdb_iface_ver0 *objdb,
 	char **error_string,
-	struct openais_config *openais_config,
+	struct main_config *main_config,
 	int interface_max)
 {
 	unsigned int object_service_handle;
 	char *value;
 	char *error_reason = error_string_response;
 
-	memset (openais_config, 0, sizeof (struct openais_config));
+	memset (main_config, 0, sizeof (struct main_config));
 
 	objdb->object_find_reset (OBJECT_PARENT_HANDLE);
 
@@ -99,77 +99,42 @@ extern int openais_main_config_read (
 
 		if (!objdb_get_string (objdb,object_service_handle, "logoutput", &value)) {
 			if (strcmp (value, "file") == 0) {
-				openais_config->logmode |= LOG_MODE_FILE;
+				main_config->logmode |= LOG_MODE_FILE;
 			} else
 			if (strcmp (value, "syslog") == 0) {
-				openais_config->logmode |= LOG_MODE_SYSLOG;
+				main_config->logmode |= LOG_MODE_SYSLOG;
 			} else
 			if (strcmp (value, "stderr") == 0) {
-				openais_config->logmode |= LOG_MODE_STDERR;
+				main_config->logmode |= LOG_MODE_STDERR;
 			} else {
 				goto parse_error;
 			}
 		}
 		if (!objdb_get_string (objdb,object_service_handle, "debug", &value)) {
 			if (strcmp (value, "on") == 0) {
-				openais_config->logmode |= LOG_MODE_DEBUG;
+				main_config->logmode |= LOG_MODE_DEBUG;
 			} else
 			if (strcmp (value, "off") == 0) {
-		       		openais_config->logmode &= ~LOG_MODE_DEBUG;
+		       		main_config->logmode &= ~LOG_MODE_DEBUG;
 			} else {
 				goto parse_error;
 			}
 		}
 		if (!objdb_get_string (objdb,object_service_handle, "timestamp", &value)) {
 			if (strcmp (value, "on") == 0) {
-				openais_config->logmode |= LOG_MODE_TIMESTAMP;
+				main_config->logmode |= LOG_MODE_TIMESTAMP;
 			} else
 			if (strcmp (value, "off") == 0) {
-				openais_config->logmode &= ~LOG_MODE_TIMESTAMP;
+				main_config->logmode &= ~LOG_MODE_TIMESTAMP;
 			} else {
 				goto parse_error;
 			}
 		}
 		if (!objdb_get_string (objdb,object_service_handle, "logfile", &value)) {
-			openais_config->logfile = strdup (value);
+			main_config->logfile = strdup (value);
 		}
 	}
 
-	if (objdb->object_find (
-		    OBJECT_PARENT_HANDLE,
-		    "event",
-		    strlen ("event"),
-		    &object_service_handle) == 0) {
-
-		if (!objdb_get_string (objdb,object_service_handle, "delivery_queue_size", &value)) {
-			    openais_config->evt_delivery_queue_size = atoi(value);
-		}
-		if (!objdb_get_string (objdb,object_service_handle, "delivery_queue_resume", &value)) {
-				openais_config->evt_delivery_queue_resume = atoi(value);
-		}
-	}
-
-	if (objdb->object_find (
-		    OBJECT_PARENT_HANDLE,
-		    "amf",
-		    strlen ("amf"),
-		    &object_service_handle) == 0) {
-
-		if (!objdb_get_string (objdb,object_service_handle, "mode", &value)) {
-			if (strcmp (value, "enabled") == 0) {
-				openais_config->amf_enabled = 1;
-			} else
-			if (strcmp (value, "disabled") == 0) {
-				openais_config->amf_enabled = 0;
-			} else {
-				goto parse_error;
-			}
-		}
-	}
-
-	openais_config->user = NULL;
-	openais_config->group = NULL;
-
 	if (objdb->object_find (
 		    OBJECT_PARENT_HANDLE,
 		    "aisexec",
@@ -177,21 +142,21 @@ extern int openais_main_config_read (
 		    &object_service_handle) == 0) {
 
 		if (!objdb_get_string (objdb,object_service_handle, "user", &value)) {
-			openais_config->user = strdup(value);
+			main_config->user = strdup(value);
 		}
 		if (!objdb_get_string (objdb,object_service_handle, "group", &value)) {
-			openais_config->group = strdup(value);
+			main_config->group = strdup(value);
 		}
 	}
 
 	/* Default user/group */
-	if (!openais_config->user)
-		openais_config->user = OPENAIS_USER;
+	if (!main_config->user)
+		main_config->user = OPENAIS_USER;
 
-	if (!openais_config->group)
-		openais_config->group = OPENAIS_GROUP;
+	if (!main_config->group)
+		main_config->group = OPENAIS_GROUP;
 
-	if ((openais_config->logmode & LOG_MODE_FILE) && openais_config->logfile == 0) {
+	if ((main_config->logmode & LOG_MODE_FILE) && main_config->logfile == 0) {
 		error_reason = "logmode set to 'file' but no logfile specified";
 		goto parse_error;
 	}

+ 2 - 15
exec/mainconfig.h

@@ -53,7 +53,7 @@ struct dynamic_service {
 };
 #define MAX_DYNAMIC_SERVICES 128
 
-struct openais_config {
+struct main_config {
 	/*
 	 * logging
 	 */
@@ -63,19 +63,6 @@ struct openais_config {
 	/* user/group to run as */
 	char *user;
 	char *group;
-
-	/*
-	 * Event service
-	 */
-	unsigned int evt_delivery_queue_size;
-	unsigned int evt_delivery_queue_resume;
-
-	/*
-	 * AMF service
-	 */
-	unsigned int amf_enabled;
-
-	struct totem_config totem_config;
 };
 
 extern char *strstr_rs (const char *haystack, const char *needle);
@@ -83,7 +70,7 @@ extern char *strstr_rs (const char *haystack, const char *needle);
 extern int openais_main_config_read (
 	struct objdb_iface_ver0 *objdb,
 	char **error_string,
-	struct openais_config *openais_config,
+	struct main_config *main_config,
 	int interface_max);
 	
 #endif /* MAINCONFIG_H_DEFINED */

+ 1 - 1
exec/objdb.c

@@ -522,7 +522,7 @@ struct lcr_iface objdb_iface_ver0[1] = {
 		.dependency_count	= 0,
 		.constructor		= NULL,
 		.destructor		= NULL,
-		.interfaces		= (void **)&objdb_iface,
+		.interfaces		= (void **)(void *)&objdb_iface,
 	}
 };
 

+ 2 - 3
exec/service.c

@@ -167,8 +167,7 @@ int openais_service_default_objdb_set (struct objdb_iface_ver0 *objdb)
 /*
  * Links dynamic services into the executive
  */
-int openais_service_link_all (struct objdb_iface_ver0 *objdb,
-		struct openais_config *openais_config)
+int openais_service_link_all (struct objdb_iface_ver0 *objdb)
 {
 	char *service_name;
 	unsigned char *service_ver;
@@ -206,7 +205,7 @@ int openais_service_link_all (struct objdb_iface_ver0 *objdb,
 			&handle,
 			service_name,
 			ver_int,
-			(void **)&iface_ver0,
+			(void **)(void *)&iface_ver0,
 			(void *)0);
 
 		if (iface_ver0 == 0) {

+ 4 - 9
exec/service.h

@@ -34,15 +34,12 @@
 #ifndef OPENAIS_SERVICE_H_DEFINED
 #define OPENAIS_SERVICE_H_DEFINED
 
-#include <netinet/in.h>
-#include "mainconfig.h" /* openais_config */
-#include "totemip.h"
+//#include <netinet/in.h>
+#include "totem.h"
 #include "objdb.h"
 
 #define SERVICE_ID_MAKE(a,b) ( ((a)<<16) | (b) )
 
-// TODO we need to abstract the conn_info data structure to make dynamic loading work perfectly
-
 enum openais_flow_control {
 	OPENAIS_FLOW_CONTROL_REQUIRED = 1,
 	OPENAIS_FLOW_CONTROL_NOT_REQUIRED = 2
@@ -97,14 +94,12 @@ extern int openais_service_objdb_add (
 
 
 extern int openais_service_handler_register (
-	struct openais_service_handler *handler,
-	struct openais_config *config);
+	struct openais_service_handler *handler);
 
 extern int openais_service_default_objdb_set (struct objdb_iface_ver0 *objdb);
 
 extern int openais_service_link_all (
-	struct objdb_iface_ver0 *objdb,
-	struct openais_config *openais_config);
+	struct objdb_iface_ver0 *objdb);
 
 extern int openais_service_init_all (
 	int service_count,