Răsfoiți Sursa

Merge the object iteration repair patch into corosync so openais services load.

git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1611 fd59a12c-fef9-0310-b244-a6a79926bd2f
Steven Dake 17 ani în urmă
părinte
comite
5c257afb8c

+ 3 - 2
corosync/exec/apidef.c

@@ -86,8 +86,9 @@ void apidef_init (struct objdb_iface_ver0 *objdb) {
 	apidef_corosync_api_v1.object_destroy = objdb->object_destroy;
 	apidef_corosync_api_v1.object_valid_set = objdb->object_valid_set;
 	apidef_corosync_api_v1.object_key_valid_set = objdb->object_key_valid_set;
-	apidef_corosync_api_v1.object_find_reset = objdb->object_find_reset;
-	apidef_corosync_api_v1.object_find = objdb->object_find;
+	apidef_corosync_api_v1.object_find_create = objdb->object_find_create;
+	apidef_corosync_api_v1.object_find_next = objdb->object_find_next;
+	apidef_corosync_api_v1.object_find_destroy = objdb->object_find_destroy;
 	apidef_corosync_api_v1.object_key_get = objdb->object_key_get;
 	apidef_corosync_api_v1.object_priv_get = objdb->object_priv_get;
 	apidef_corosync_api_v1.object_key_replace = objdb->object_key_replace;

+ 69 - 37
corosync/exec/mainconfig.c

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2002-2005 MontaVista Software, Inc.
+ * Copyright (c) 2006-2008 Red Hat, Inc.
  *
  * All rights reserved.
  *
@@ -105,18 +106,23 @@ int openais_main_config_read (
 	unsigned int object_logger_subsys_handle;
 	char *value;
 	char *error_reason = error_string_response;
+	unsigned int object_find_handle;
+	unsigned int object_find_logsys_handle;
 	int global_debug = 0;
 
+
 	memset (main_config, 0, sizeof (struct main_config));
 
-	objdb->object_find_reset (OBJECT_PARENT_HANDLE);
+	objdb->object_find_create (
+		OBJECT_PARENT_HANDLE,
+		"logging",
+		strlen ("logging"),
+		&object_find_handle);
 
 	main_config->logmode = LOG_MODE_FLUSH_AFTER_CONFIG;
-	if (objdb->object_find (
-		    OBJECT_PARENT_HANDLE,
-		    "logging",
-		    strlen ("logging"),
-		    &object_service_handle) == 0) {
+	if (objdb->object_find_next (
+		object_find_handle,
+		&object_service_handle) == 0) {
 
 		if (!objdb_get_string (objdb,object_service_handle, "to_file", &value)) {
 			if (strcmp (value, "yes") == 0) {
@@ -144,15 +150,15 @@ int openais_main_config_read (
 		}
 
 		if (!objdb_get_string (objdb,object_service_handle, "debug", &value)) {
-			if (strcmp (value, "on") == 0) {
-				global_debug = 1;
-			} else
-			if (strcmp (value, "off") == 0) {
-				global_debug = 0;
-			} else {
-				goto parse_error;
-			}
-		}
+                        if (strcmp (value, "on") == 0) {
+                                global_debug = 1;
+                        } else
+                        if (strcmp (value, "off") == 0) {
+                                global_debug = 0;
+                        } else {
+                                goto parse_error;
+                        }
+                }
 		if (!objdb_get_string (objdb,object_service_handle, "timestamp", &value)) {
 			if (strcmp (value, "on") == 0) {
 				main_config->logmode |= LOG_MODE_DISPLAY_TIMESTAMP;
@@ -179,17 +185,46 @@ int openais_main_config_read (
 		}
 
 		if (!objdb_get_string (objdb,object_service_handle, "syslog_facility", &value)) {
-			main_config->syslog_facility = logsys_facility_id_get(value);
-			if (main_config->syslog_facility < 0) {
+			if (strcmp (value, "daemon") == 0) {
+				main_config->syslog_facility = LOG_DAEMON;
+			} else
+			if (strcmp (value, "local0") == 0) {
+				main_config->syslog_facility = LOG_LOCAL0;
+			} else
+			if (strcmp (value, "local1") == 0) {
+				main_config->syslog_facility = LOG_LOCAL1;
+			} else
+			if (strcmp (value, "local2") == 0) {
+				main_config->syslog_facility = LOG_LOCAL2;
+			} else
+			if (strcmp (value, "local3") == 0) {
+				main_config->syslog_facility = LOG_LOCAL3;
+			} else
+			if (strcmp (value, "local4") == 0) {
+				main_config->syslog_facility = LOG_LOCAL4;
+			} else
+			if (strcmp (value, "local5") == 0) {
+				main_config->syslog_facility = LOG_LOCAL5;
+			} else
+			if (strcmp (value, "local6") == 0) {
+				main_config->syslog_facility = LOG_LOCAL6;
+			} else
+			if (strcmp (value, "local7") == 0) {
+				main_config->syslog_facility = LOG_LOCAL7;
+			} else {
 				error_reason = "unknown syslog facility specified";
 				goto parse_error;
 			}
 		}
 
-		objdb->object_find_reset(object_service_handle);
-		while (objdb->object_find (object_service_handle,
+		objdb->object_find_create (
+			object_service_handle,
 			"logger_subsys",
 			strlen ("logger_subsys"),
+			&object_find_logsys_handle);
+
+		while (objdb->object_find_next (
+			object_find_logsys_handle,
 			&object_logger_subsys_handle) == 0) {
 
 			if (!objdb_get_string (objdb,
@@ -208,22 +243,11 @@ int openais_main_config_read (
 					logsys_logger.priority = LOG_LEVEL_DEBUG;
 				} else
 				if (strcmp (value, "off") == 0) {
-					logsys_logger.priority = LOG_LEVEL_INFO;
+					logsys_logger.priority &= ~LOG_LEVEL_DEBUG;
 				} else {
 					goto parse_error;
 				}
 			}
-			else {
-				if (global_debug)
-					logsys_logger.priority = LOG_LEVEL_DEBUG;
-			}
-			if (logsys_logger.priority != LOG_LEVEL_DEBUG) {
-				if (!objdb_get_string (objdb, object_logger_subsys_handle, "syslog_level", &value)) {
-					logsys_logger.priority = logsys_priority_id_get(value);
-					if (logsys_logger.priority < 0)
-						logsys_logger.priority = LOG_LEVEL_INFO;
-				}
-			}
 			if (!objdb_get_string (objdb, object_logger_subsys_handle, "tags", &value)) {
 				char *token = strtok (value, "|");
 
@@ -265,14 +289,20 @@ int openais_main_config_read (
 				logsys_logger.priority);
 			
 		}
+		objdb->object_find_destroy (object_find_logsys_handle);
 	}
 
-	objdb->object_find_reset (OBJECT_PARENT_HANDLE);
-	if (objdb->object_find (
-		    OBJECT_PARENT_HANDLE,
-		    "aisexec",
-		    strlen ("aisexec"),
-		    &object_service_handle) == 0) {
+	objdb->object_find_destroy (object_find_handle);
+
+	objdb->object_find_create (
+		OBJECT_PARENT_HANDLE,
+		"aisexec",
+		strlen ("aisexec"),
+		&object_find_handle);
+
+	if (objdb->object_find_next (
+		object_find_handle,
+		&object_service_handle) == 0) {
 
 		if (!objdb_get_string (objdb,object_service_handle, "user", &value)) {
 			main_config->user = strdup(value);
@@ -282,6 +312,8 @@ int openais_main_config_read (
 		}
 	}
 
+	objdb->object_find_destroy (object_find_handle);
+
 	/* Default user/group */
 	if (!main_config->user)
 		main_config->user = "ais";

+ 75 - 26
corosync/exec/objdb.c

@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2006 MontaVista Software, Inc.
- * Copyright (c) 2008 Red Hat, Inc.
+ * Copyright (c) 2007-2008 Red Hat, Inc.
  *
  * All rights reserved.
  *
@@ -68,6 +68,13 @@ struct object_instance {
 	int object_key_valid_list_entries;
 };
 
+struct object_find_instance {
+	struct list_head *find_child_list;
+	struct list_head *child_head;
+	void *object_name;
+	int object_len;
+};
+
 struct objdb_iface_ver0 objdb_iface;
 
 static struct hdb_handle_database object_instance_database = {
@@ -77,6 +84,13 @@ static struct hdb_handle_database object_instance_database = {
 	.mutex		= PTHREAD_MUTEX_INITIALIZER
 };
 
+static struct hdb_handle_database object_find_instance_database = {
+	.handle_count	= 0,
+	.handles	= 0,
+	.iterator	= 0,
+	.mutex		= PTHREAD_MUTEX_INITIALIZER
+};
+
 
 static int objdb_init (void)
 {
@@ -439,61 +453,89 @@ error_exit:
 /*
  * object db reading
  */
-static int object_find_reset (
-	unsigned int object_handle)
+static int object_find_create (
+	unsigned int object_handle,
+	void *object_name,
+	int object_len,
+	unsigned int *object_find_handle)
 {
 	unsigned int res;
-	struct object_instance *instance;
+	struct object_instance *object_instance;
+	struct object_find_instance *object_find_instance;
 
 	res = hdb_handle_get (&object_instance_database,
-		object_handle, (void *)&instance);
+		object_handle, (void *)&object_instance);
 	if (res != 0) {
 		goto error_exit;
 	}
-	instance->find_child_list = &instance->child_head;
+
+	res = hdb_handle_create (&object_find_instance_database,
+		sizeof (struct object_find_instance), object_find_handle);
+	if (res != 0) {
+		goto error_put;
+	}
+	res = hdb_handle_get (&object_find_instance_database,
+		*object_find_handle, (void *)&object_find_instance);
+	if (res != 0) {
+		goto error_destroy;
+	}
+
+	object_find_instance->find_child_list = &object_instance->child_head;
+	object_find_instance->child_head = &object_instance->child_head;
+	object_find_instance->object_name = object_name;
+	object_find_instance->object_len = object_len;
 
 	hdb_handle_put (&object_instance_database, object_handle);
+	hdb_handle_put (&object_find_instance_database, *object_find_handle);
 	return (0);
 
+error_destroy:
+	hdb_handle_destroy (&object_instance_database, *object_find_handle);
+
+error_put:
+	hdb_handle_put (&object_instance_database, object_handle);
+
 error_exit:
 	return (-1);
 }
 
-static int object_find (
-	unsigned int parent_object_handle,
-	void *object_name,
-	int object_name_len,
+static int object_find_next (
+	unsigned int object_find_handle,
 	unsigned int *object_handle)
 {
 	unsigned int res;
-	struct object_instance *instance;
-	struct object_instance *find_instance = NULL;
+	struct object_find_instance *object_find_instance;
+	struct object_instance *object_instance = NULL;
 	struct list_head *list;
 	unsigned int found = 0;
 
-	res = hdb_handle_get (&object_instance_database,
-		parent_object_handle, (void *)&instance);
+	res = hdb_handle_get (&object_find_instance_database,
+		object_find_handle, (void *)&object_find_instance);
 	if (res != 0) {
 		goto error_exit;
 	}
-	res = -ENOENT;
-	for (list = instance->find_child_list->next;
-		list != &instance->child_head; list = list->next) {
+	res = -1;
+	for (list = object_find_instance->find_child_list->next;
+		list != object_find_instance->child_head; list = list->next) {
 
-                find_instance = list_entry (list, struct object_instance,
+                object_instance = list_entry (list, struct object_instance,
 			child_list);
 
-		if ((find_instance->object_name_len == object_name_len) &&
-			(memcmp (find_instance->object_name, object_name,
-			object_name_len) == 0)) {
+		if ((object_instance->object_name_len ==
+			object_find_instance->object_len) &&
+
+			(memcmp (object_instance->object_name,
+				object_find_instance->object_name,
+				object_find_instance->object_len) == 0)) {
+
 			found = 1;
 			break;
 		}
 	}
-	instance->find_child_list = list;
-	hdb_handle_put (&object_instance_database, parent_object_handle);
+	object_find_instance->find_child_list = list;
+	hdb_handle_put (&object_find_instance_database, object_find_handle);
 	if (found) {
-		*object_handle = find_instance->object_handle;
+		*object_handle = object_instance->object_handle;
 		res = 0;
 	}
 	return (res);
@@ -502,6 +544,12 @@ error_exit:
 	return (-1);
 }
 
+static int object_find_destroy (
+	unsigned int object_find_handle)
+{
+	return (0);
+}
+
 static int object_key_get (
 	unsigned int object_handle,
 	void *key_name,
@@ -1117,8 +1165,9 @@ struct objdb_iface_ver0 objdb_iface = {
 	.object_destroy		= object_destroy,
 	.object_valid_set	= object_valid_set,
 	.object_key_valid_set	= object_key_valid_set,
-	.object_find_reset	= object_find_reset,
-	.object_find		= object_find,
+	.object_find_create	= object_find_create,
+	.object_find_next	= object_find_next,
+	.object_find_destroy	= object_find_destroy,
 	.object_find_from	= object_find_from,
 	.object_key_get		= object_key_get,
 	.object_key_iter	= object_key_iter,

+ 9 - 4
corosync/exec/objdb.h

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2006 MontaVista Software, Inc.
+ * Copyright (c) 2007-2008 Red Hat, Inc.
  *
  * All rights reserved.
  *
@@ -83,15 +84,19 @@ struct objdb_iface_ver0 {
 		struct object_key_valid *object_key_valid_list,
 		unsigned int object_key_valid_list_entries);
 
-	int (*object_find_reset) (
-		unsigned int parent_object_handle);
-
-	int (*object_find) (
+	int (*object_find_create) (
 		unsigned int parent_object_handle,
 		void *object_name,
 		int object_name_len,
+		unsigned int *object_find_handle);
+
+	int (*object_find_next) (
+		unsigned int object_find_handle,
 		unsigned int *object_handle);
 
+	int (*object_find_destroy) (
+		unsigned int object_find_handle);
+
 	int (*object_key_get) (
 		unsigned int object_handle,
 		void *key_name,

+ 93 - 47
corosync/exec/service.c

@@ -52,6 +52,7 @@
 #include "../include/coroapi.h"
 #include "service.h"
 
+
 LOGSYS_DECLARE_SUBSYS ("SERV", LOG_INFO);
 
 struct default_service {
@@ -65,7 +66,6 @@ static struct default_service default_services[] = {
 		.ver			 = 0,
 	},
 	{
-
 		.name			 = "corosync_cfg",
 		.ver			 = 0,
 	},
@@ -83,22 +83,27 @@ struct corosync_service_engine *ais_service[SERVICE_HANDLER_MAXIMUM_COUNT];
 
 static unsigned int object_internal_configuration_handle;
 
-static unsigned int default_services_requested (struct corosync_api_v1 *api)
+
+static unsigned int default_services_requested (struct corosync_api_v1 *corosync_api)
 {
 	unsigned int object_service_handle;
+	unsigned int object_find_handle;
 	char *value;
 
 	/*
 	 * Don't link default services if they have been disabled
 	 */
-	api->object_find_reset (OBJECT_PARENT_HANDLE);
-	if (api->object_find (
+	corosync_api->object_find_create (
 		OBJECT_PARENT_HANDLE,
 		"aisexec",
 		strlen ("aisexec"),
+		&object_find_handle);
+
+	if (corosync_api->object_find_next (
+		object_find_handle,
 		&object_service_handle) == 0) {
 
-		if ( ! api->object_key_get (object_service_handle,
+		if ( ! corosync_api->object_key_get (object_service_handle,
 			"defaultservices",
 			strlen ("defaultservices"),
 			(void *)&value,
@@ -109,11 +114,14 @@ static unsigned int default_services_requested (struct corosync_api_v1 *api)
 			}
 		}
 	}
-		return (-1);
+
+	corosync_api->object_find_destroy (object_find_handle);
+
+	return (-1);
 }
 
 unsigned int openais_service_link_and_init (
-	struct corosync_api_v1 *api,
+	struct corosync_api_v1 *corosync_api,
 	char *service_name,
 	unsigned int service_ver)
 {
@@ -135,7 +143,7 @@ unsigned int openais_service_link_and_init (
 		&iface_ver0_p,
 		(void *)0);
 
-	iface_ver0 = (struct corosync_service_engine_iface_ver0 *)iface_ver0_p;
+	iface_ver0 = (struct openais_service_engine_iface_ver0 *)iface_ver0_p;
 
 	if (iface_ver0 == 0) {
 		log_printf(LOG_LEVEL_ERROR, "Service failed to load '%s'.\n", service_name);
@@ -150,40 +158,40 @@ unsigned int openais_service_link_and_init (
 
 	ais_service[service->id] = service;
 	if (service->config_init_fn) {
-		res = service->config_init_fn (api);
+		res = service->config_init_fn (corosync_api);
 	}
 
 	if (service->exec_init_fn) {
-		res = service->exec_init_fn (api);
+		res = service->exec_init_fn (corosync_api);
 	}
 
 	/*
 	 * Store service in object database
 	 */
-	api->object_create (object_internal_configuration_handle,
+	corosync_api->object_create (object_internal_configuration_handle,
 		&object_service_handle,
 		"service",
 		strlen ("service"));
 
-	api->object_key_create (object_service_handle,
+	corosync_api->object_key_create (object_service_handle,
 		"name",
 		strlen ("name"),
 		service_name,
 		strlen (service_name) + 1);
 
-	api->object_key_create (object_service_handle,
+	corosync_api->object_key_create (object_service_handle,
 		"ver",
 		strlen ("ver"),
 		&service_ver,
 		sizeof (service_ver));
 
-	res = api->object_key_create (object_service_handle,
+	res = corosync_api->object_key_create (object_service_handle,
 		"handle",
 		strlen ("handle"),
 		&handle,
 		sizeof (handle));
 
-	api->object_key_create (object_service_handle,
+	corosync_api->object_key_create (object_service_handle,
 		"service_id",
 		strlen ("service_id"),
 		&service->id,
@@ -194,7 +202,7 @@ unsigned int openais_service_link_and_init (
 }
 
 static int openais_service_unlink_common (
-	struct corosync_api_v1 *api,
+	struct corosync_api_v1 *corosync_api,
 	unsigned int object_service_handle,
 	const char *service_name,
 	unsigned int service_version) 
@@ -203,13 +211,13 @@ static int openais_service_unlink_common (
 	unsigned short *service_id;
 	unsigned int *found_service_handle;
 
-	res = api->object_key_get (object_service_handle,
+	res = corosync_api->object_key_get (object_service_handle,
 		"handle",
 		strlen ("handle"),
 		(void *)&found_service_handle,
 		NULL);
 	
-	res = api->object_key_get (object_service_handle,
+	res = corosync_api->object_key_get (object_service_handle,
 		"service_id",
 		strlen ("service_id"),
 		(void *)&service_id,
@@ -227,7 +235,7 @@ static int openais_service_unlink_common (
 }
 
 extern unsigned int openais_service_unlink_and_exit (
-	struct corosync_api_v1 *api,
+	struct corosync_api_v1 *corosync_api,
 	char *service_name,
 	unsigned int service_ver)
 {
@@ -235,20 +243,25 @@ extern unsigned int openais_service_unlink_and_exit (
 	unsigned int object_service_handle;
 	char *found_service_name;
 	unsigned int *found_service_ver;
+	unsigned int object_find_handle;
 
-	while (api->object_find (
+	corosync_api->object_find_create (
 		object_internal_configuration_handle,
 		"service",
 		strlen ("service"),
+		&object_find_handle);
+
+	while (corosync_api->object_find_next (
+		object_find_handle,
 		&object_service_handle) == 0) {
 
-		api->object_key_get (object_service_handle,
+		corosync_api->object_key_get (object_service_handle,
 			"name",
 			strlen ("name"),
 			(void *)&found_service_name,
 			NULL);
 
-		api->object_key_get (object_service_handle,
+		corosync_api->object_key_get (object_service_handle,
 			"ver",
 			strlen ("ver"),
 			(void *)&found_service_ver,
@@ -261,49 +274,76 @@ extern unsigned int openais_service_unlink_and_exit (
 			(service_ver == *found_service_ver)) {
 
 			res = openais_service_unlink_common (
-				api, object_service_handle,
+				corosync_api, object_service_handle,
 				service_name, service_ver);
 
-			api->object_destroy (object_service_handle);
+			corosync_api->object_destroy (object_service_handle);
 			return res;
 		}
 	}
+
+	corosync_api->object_find_destroy (object_find_handle);
+
 	return (-1);
 }
 
 extern unsigned int openais_service_unlink_all (
-	struct corosync_api_v1 *api)
+	struct corosync_api_v1 *corosync_api)
 {
 	char *service_name;
 	unsigned int *service_ver;
 	unsigned int object_service_handle;
+	unsigned int object_find_handle;
+	unsigned int res;
 
 	log_printf(LOG_LEVEL_NOTICE, "Unloading all openais components\n");
 	
-	api->object_find_reset (object_internal_configuration_handle);
+	res = 0;
+	/*
+	 * TODO
+	 * Deleting of keys not supported during iteration at this time
+	 * hence this ugly hack
+	 */
+	for (;;) {
+		corosync_api->object_find_create (
+			object_internal_configuration_handle,
+			"service",
+			strlen ("service"),
+			&object_find_handle);
 
-	while (api->object_find (object_internal_configuration_handle,
-		"service",
-		strlen ("service"),
-		&object_service_handle) == 0) {
-		
-		api->object_key_get (object_service_handle,
+		res = corosync_api->object_find_next (
+			object_find_handle,
+			&object_service_handle);
+
+		/*
+		 * Exit from unloading
+		 */
+		if (res == -1) {
+			break;
+		}
+			
+		corosync_api->object_key_get (
+			object_service_handle,
 			"name",
 			strlen ("name"),
 			(void *)&service_name,
 			NULL);
 
-		api->object_key_get (object_service_handle,
+		corosync_api->object_key_get (
+			object_service_handle,
 			"ver",
 			strlen ("ver"),
 			(void *)&service_ver,
 			NULL);
-				
+					
 		openais_service_unlink_common (
-			api, object_service_handle, service_name, *service_ver);
+			corosync_api, object_service_handle,
+			service_name, *service_ver);
+
+		corosync_api->object_destroy (object_service_handle);
+
+		corosync_api->object_find_destroy (object_find_handle);
 
-		api->object_destroy (object_service_handle);
-		api->object_find_reset (object_internal_configuration_handle);
 	}
 
 	return (0);
@@ -312,7 +352,7 @@ extern unsigned int openais_service_unlink_all (
 /*
  * Links default services into the executive
  */
-unsigned int openais_service_defaults_link_and_init (struct corosync_api_v1 *api)
+unsigned int openais_service_defaults_link_and_init (struct corosync_api_v1 *corosync_api)
 {
 	unsigned int i;
 
@@ -320,27 +360,30 @@ unsigned int openais_service_defaults_link_and_init (struct corosync_api_v1 *api
 	char *found_service_name;
 	char *found_service_ver;
 	unsigned int found_service_ver_atoi;
+	unsigned int object_find_handle;
  
-	api->object_create (OBJECT_PARENT_HANDLE,
+	corosync_api->object_create (OBJECT_PARENT_HANDLE,
 		&object_internal_configuration_handle,
 		"internal_configuration",
 		strlen ("internal_configuration"));
 
-	api->object_find_reset (OBJECT_PARENT_HANDLE);
-
-	while (api->object_find (
+	corosync_api->object_find_create (
 		OBJECT_PARENT_HANDLE,
 		"service",
 		strlen ("service"),
+		&object_find_handle);
+
+	while (corosync_api->object_find_next (
+		object_find_handle,
 		&object_service_handle) == 0) {
 
-		api->object_key_get (object_service_handle,
+		corosync_api->object_key_get (object_service_handle,
 			"name",
 			strlen ("name"),
 			(void *)&found_service_name,
 			NULL);
 
-		api->object_key_get (object_service_handle,
+		corosync_api->object_key_get (object_service_handle,
 			"ver",
 			strlen ("ver"),
 			(void *)&found_service_ver,
@@ -349,19 +392,22 @@ unsigned int openais_service_defaults_link_and_init (struct corosync_api_v1 *api
 		found_service_ver_atoi = atoi (found_service_ver);
 
 		openais_service_link_and_init (
-			api,
+			corosync_api,
 			found_service_name,
 			found_service_ver_atoi);
 	}
 
- 	if (default_services_requested (api) == 0) {
+	corosync_api->object_find_destroy (object_find_handle);
+
+ 	if (default_services_requested (corosync_api) == 0) {
  		return (0);
  	}
+
 	for (i = 0;
 		i < sizeof (default_services) / sizeof (struct default_service); i++) {
 
 		openais_service_link_and_init (
-			api,
+			corosync_api,
 			default_services[i].name,
 			default_services[i].ver);
 	}

+ 146 - 108
corosync/exec/totemconfig.c

@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2002-2005 MontaVista Software, Inc.
- * Copyright (c) 2006-2007 Red Hat, Inc.
+ * Copyright (c) 2006-2008 Red Hat, Inc.
  *
  * All rights reserved.
  *
@@ -46,16 +46,14 @@
 #include <arpa/inet.h>
 #include <sys/param.h>
 
-#include "../include/list.h"
+#include "swab.h"
+#include "list.h"
 #include "util.h"
 #include "totem.h"
 #include "totemconfig.h"
 #include "logsys.h"
 #include "objdb.h"
-
-#if defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
-	#define HZ 100  /* 10ms */
-#endif
+#include "tlist.h" /* for HZ */
 
 #define TOKEN_RETRANSMITS_BEFORE_LOSS_CONST	4
 #define TOKEN_TIMEOUT				1000
@@ -79,19 +77,22 @@ static char error_string_response[512];
 
 /* These just makes the code below a little neater */
 static inline int objdb_get_string (
-	struct objdb_iface_ver0 *objdb, unsigned int object_service_handle,
+	struct objdb_iface_ver0 *objdb,
+	unsigned int object_service_handle,
 	char *key, char **value)
 {
 	int res;
 
 	*value = NULL;
 	if ( !(res = objdb->object_key_get (object_service_handle,
-					    key,
-					    strlen (key),
-					    (void *)value,
-					    NULL))) {
-		if (*value)
+		key,
+		strlen (key),
+		(void *)value,
+		NULL))) {
+
+		if (*value) {
 			return 0;
+		}
 	}
 	return -1;
 }
@@ -103,16 +104,62 @@ static inline void objdb_get_int (
 	char *value = NULL;
 
 	if (!objdb->object_key_get (object_service_handle,
-				    key,
-				    strlen (key),
-				    (void *)&value,
-				    NULL)) {
+		key,
+		strlen (key),
+		(void *)&value,
+		NULL)) {
+
 		if (value) {
 			*intvalue = atoi(value);
 		}
 	}
 }
 
+static unsigned int totem_handle_find (
+	struct objdb_iface_ver0 *objdb,
+	unsigned int *totem_find_handle)  {
+
+	unsigned int object_find_handle;
+	unsigned int res;
+
+	/*
+	 * Find a network section
+	 */
+	objdb->object_find_create (
+		OBJECT_PARENT_HANDLE,
+		"network",
+		strlen ("network"),
+		&object_find_handle);
+
+	res = objdb->object_find_next (
+		object_find_handle,
+		totem_find_handle);
+
+	objdb->object_find_destroy (object_find_handle);
+
+	/*
+	 * Network section not found in configuration, checking for totem
+	 */
+	if (res == -1) {
+		objdb->object_find_create (
+			OBJECT_PARENT_HANDLE,
+			"totem",
+			strlen ("totem"),
+			&object_find_handle);
+
+		res = objdb->object_find_next (
+			object_find_handle,
+			totem_find_handle);
+
+		objdb->object_find_destroy (object_find_handle);
+	}
+
+	if (res == -1) {
+		return (-1);
+	}
+
+	return (0);
+}
 
 extern int totem_config_read (
 	struct objdb_iface_ver0 *objdb,
@@ -124,6 +171,13 @@ extern int totem_config_read (
 	unsigned int object_interface_handle;
 	char *str;
 	unsigned int ringnumber = 0;
+	unsigned int object_find_interface_handle;
+
+	res = totem_handle_find (objdb, &object_totem_handle);
+	if (res == -1) {
+printf ("couldn't find totem handle\n");
+		return (-1);
+	}
 
 	memset (totem_config, 0, sizeof (struct totem_config));
 	totem_config->interfaces = malloc (sizeof (struct totem_interface) * INTERFACE_MAX);
@@ -139,87 +193,78 @@ extern int totem_config_read (
 
 	strcpy (totem_config->rrp_mode, "none");
 
-	objdb->object_find_reset (OBJECT_PARENT_HANDLE);
-
-	if (objdb->object_find (
-		    OBJECT_PARENT_HANDLE,
-		    "network",
-		    strlen ("network"),
-		    &object_totem_handle) == 0 ||
-	    objdb->object_find (
-		    OBJECT_PARENT_HANDLE,
-		    "totem",
-		    strlen ("totem"),
-		    &object_totem_handle) == 0) {
-
-		if (!objdb_get_string (objdb,object_totem_handle, "version", &str)) {
-			if (strcmp (str, "2") == 0) {
-				totem_config->version = 2;
-			}
+	if (!objdb_get_string (objdb, object_totem_handle, "version", &str)) {
+		if (strcmp (str, "2") == 0) {
+			totem_config->version = 2;
 		}
-		if (!objdb_get_string (objdb,object_totem_handle, "secauth", &str)) {
-			if (strcmp (str, "on") == 0) {
-				totem_config->secauth = 1;
-			}
-			if (strcmp (str, "off") == 0) {
-				totem_config->secauth = 0;
-			}
+	}
+	if (!objdb_get_string (objdb, object_totem_handle, "secauth", &str)) {
+		if (strcmp (str, "on") == 0) {
+			totem_config->secauth = 1;
 		}
-		if (!objdb_get_string (objdb, object_totem_handle, "rrp_mode", &str)) {
-			strcpy (totem_config->rrp_mode, str);
+		if (strcmp (str, "off") == 0) {
+			totem_config->secauth = 0;
 		}
+	}
+	if (!objdb_get_string (objdb, object_totem_handle, "rrp_mode", &str)) {
+		strcpy (totem_config->rrp_mode, str);
+	}
 
-		/*
-		 * Get interface node id
-		 */
-		objdb_get_int (objdb, object_totem_handle, "nodeid", &totem_config->node_id);
+	/*
+	 * Get interface node id
+	 */
+	objdb_get_int (objdb, object_totem_handle, "nodeid", &totem_config->node_id);
 
-		objdb_get_int (objdb,object_totem_handle, "threads", &totem_config->threads);
+	objdb_get_int (objdb,object_totem_handle, "threads", &totem_config->threads);
 
 
-		objdb_get_int (objdb,object_totem_handle, "netmtu", &totem_config->net_mtu);
+	objdb_get_int (objdb,object_totem_handle, "netmtu", &totem_config->net_mtu);
 
-		objdb_get_int (objdb,object_totem_handle, "token", &totem_config->token_timeout);
+	objdb_get_int (objdb,object_totem_handle, "token", &totem_config->token_timeout);
 
-		objdb_get_int (objdb,object_totem_handle, "token_retransmit", &totem_config->token_retransmit_timeout);
+	objdb_get_int (objdb,object_totem_handle, "token_retransmit", &totem_config->token_retransmit_timeout);
 
-		objdb_get_int (objdb,object_totem_handle, "hold", &totem_config->token_hold_timeout);
+	objdb_get_int (objdb,object_totem_handle, "hold", &totem_config->token_hold_timeout);
 
-		objdb_get_int (objdb,object_totem_handle, "token_retransmits_before_loss_const", &totem_config->token_retransmits_before_loss_const);
+	objdb_get_int (objdb,object_totem_handle, "token_retransmits_before_loss_const", &totem_config->token_retransmits_before_loss_const);
 
-		objdb_get_int (objdb,object_totem_handle, "join", &totem_config->join_timeout);
-		objdb_get_int (objdb,object_totem_handle, "send_join", &totem_config->send_join_timeout);
+	objdb_get_int (objdb,object_totem_handle, "join", &totem_config->join_timeout);
+	objdb_get_int (objdb,object_totem_handle, "send_join", &totem_config->send_join_timeout);
 
-		objdb_get_int (objdb,object_totem_handle, "consensus", &totem_config->consensus_timeout);
+	objdb_get_int (objdb,object_totem_handle, "consensus", &totem_config->consensus_timeout);
 
-		objdb_get_int (objdb,object_totem_handle, "merge", &totem_config->merge_timeout);
+	objdb_get_int (objdb,object_totem_handle, "merge", &totem_config->merge_timeout);
 
-		objdb_get_int (objdb,object_totem_handle, "downcheck", &totem_config->downcheck_timeout);
+	objdb_get_int (objdb,object_totem_handle, "downcheck", &totem_config->downcheck_timeout);
 
-		objdb_get_int (objdb,object_totem_handle, "fail_recv_const", &totem_config->fail_to_recv_const);
+	objdb_get_int (objdb,object_totem_handle, "fail_recv_const", &totem_config->fail_to_recv_const);
 
-		objdb_get_int (objdb,object_totem_handle, "seqno_unchanged_const", &totem_config->seqno_unchanged_const);
+	objdb_get_int (objdb,object_totem_handle, "seqno_unchanged_const", &totem_config->seqno_unchanged_const);
 
-		objdb_get_int (objdb,object_totem_handle, "rrp_token_expired_timeout", &totem_config->rrp_token_expired_timeout);
+	objdb_get_int (objdb,object_totem_handle, "rrp_token_expired_timeout", &totem_config->rrp_token_expired_timeout);
 
-		objdb_get_int (objdb,object_totem_handle, "rrp_problem_count_timeout", &totem_config->rrp_problem_count_timeout);
+	objdb_get_int (objdb,object_totem_handle, "rrp_problem_count_timeout", &totem_config->rrp_problem_count_timeout);
 
-		objdb_get_int (objdb,object_totem_handle, "rrp_problem_count_threshold", &totem_config->rrp_problem_count_threshold);
+	objdb_get_int (objdb,object_totem_handle, "rrp_problem_count_threshold", &totem_config->rrp_problem_count_threshold);
 
-		objdb_get_int (objdb,object_totem_handle, "heartbeat_failures_allowed", &totem_config->heartbeat_failures_allowed);
+	objdb_get_int (objdb,object_totem_handle, "heartbeat_failures_allowed", &totem_config->heartbeat_failures_allowed);
 
-		objdb_get_int (objdb,object_totem_handle, "max_network_delay", &totem_config->max_network_delay);
+	objdb_get_int (objdb,object_totem_handle, "max_network_delay", &totem_config->max_network_delay);
 
-		objdb_get_int (objdb,object_totem_handle, "window_size", &totem_config->window_size);
-		objdb_get_string (objdb, object_totem_handle, "vsftype", &totem_config->vsf_type);
+	objdb_get_int (objdb,object_totem_handle, "window_size", &totem_config->window_size);
+	objdb_get_string (objdb, object_totem_handle, "vsftype", &totem_config->vsf_type);
 
-		objdb_get_int (objdb,object_totem_handle, "max_messages", &totem_config->max_messages);
-	}
-	while (objdb->object_find (
-		    object_totem_handle,
-		    "interface",
-		    strlen ("interface"),
-		    &object_interface_handle) == 0) {
+	objdb_get_int (objdb,object_totem_handle, "max_messages", &totem_config->max_messages);
+
+	objdb->object_find_create (
+		object_totem_handle,
+		"interface",
+		strlen ("interface"),
+		&object_find_interface_handle);
+
+	while (objdb->object_find_next (
+		object_find_interface_handle,
+		&object_interface_handle) == 0) {
 
 		objdb_get_int (objdb, object_interface_handle, "ringnumber", &ringnumber);
 
@@ -234,7 +279,7 @@ extern int totem_config_read (
 		 * Get mcast port
 		 */
 		if (!objdb_get_string (objdb, object_interface_handle, "mcastport", &str)) {
-			totem_config->interfaces[ringnumber].ip_port = htons (atoi (str));
+			totem_config->interfaces[ringnumber].ip_port = atoi (str);
 		}
 
 		/*
@@ -248,9 +293,9 @@ extern int totem_config_read (
 		totem_config->interface_count++;
 	}
 
-	return 0;
+	objdb->object_find_destroy (object_find_interface_handle);
 
-	return (-1);
+	return 0;
 }
 
 int totem_config_validate (
@@ -555,7 +600,7 @@ int totem_config_keyread (
 {
 	int got_key = 0;
 	char *key_location = NULL;
-	unsigned int object_service_handle;
+	unsigned int object_totem_handle;
 	int res;
 
 	memset (totem_config->private_key, 0, 128);
@@ -565,38 +610,31 @@ int totem_config_keyread (
 		return (0);
 	}
 
-	if (objdb->object_find (
-		    OBJECT_PARENT_HANDLE,
-		    "network",
-		    strlen ("network"),
-		    &object_service_handle) == 0 ||
-	    objdb->object_find (
-		    OBJECT_PARENT_HANDLE,
-		    "totem",
-		    strlen ("totem"),
-		    &object_service_handle) == 0) {
-
-		/* objdb may store the location of the key file */
-		if (!objdb_get_string (objdb,object_service_handle, "keyfile", &key_location)
-		    && key_location) {
-			res = read_keyfile(key_location, totem_config, error_string);
-			if (res)
-				goto key_error;
-			got_key = 1;
+	res = totem_handle_find (objdb, &object_totem_handle);
+	if (res == -1) {
+		return (-1);
+	}
+	/* objdb may store the location of the key file */
+	if (!objdb_get_string (objdb,object_totem_handle, "keyfile", &key_location)
+	    && key_location) {
+		res = read_keyfile(key_location, totem_config, error_string);
+		if (res)  {
+			goto key_error;
 		}
-		else { /* Or the key itself may be in the objdb */
-			char *key = NULL;
-			int key_len;
-			res = objdb->object_key_get (object_service_handle,
-						     "key",
-						     strlen ("key"),
-						     (void *)&key,
-						     &key_len);
-			if (res == 0 && key) {
-				memcpy(totem_config->private_key, key, key_len);
-				totem_config->private_key_len = key_len;
-				got_key = 1;
-			}
+		got_key = 1;
+	} else { /* Or the key itself may be in the objdb */
+		char *key = NULL;
+		int key_len;
+		res = objdb->object_key_get (object_totem_handle,
+			"key",
+			strlen ("key"),
+			(void *)&key,
+			&key_len);
+
+		if (res == 0 && key) {
+			memcpy(totem_config->private_key, key, key_len);
+			totem_config->private_key_len = key_len;
+			got_key = 1;
 		}
 	}
 

+ 8 - 4
corosync/include/coroapi.h

@@ -132,15 +132,19 @@ struct corosync_api_v1 {
 		struct object_key_valid *object_key_valid_list,
 		unsigned int object_key_valid_list_entries);
 
-	int (*object_find_reset) (
-		unsigned int parent_object_handle);
-
-	int (*object_find) (
+	int (*object_find_create) (
 		unsigned int parent_object_handle,
 		void *object_name,
 		int object_name_len,
+		unsigned int *object_find_handle);
+
+	int (*object_find_next) (
+		unsigned int object_find_handle,
 		unsigned int *object_handle);
 
+	int (*object_find_destroy) (
+		unsigned int object_find_handle);
+
 	int (*object_key_get) (
 		unsigned int object_handle,
 		void *key_name,

+ 10 - 3
openais/services/amfutil.c

@@ -10,6 +10,8 @@
  * - Refactoring of code into several AMF files
  * - Serializers/deserializers
  *
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ *
  * All rights reserved.
  *
  * This software licensed under BSD license, the text of which follows:
@@ -51,7 +53,6 @@
 #include <errno.h>
 #include <sys/types.h>
 #include <regex.h>
-#include <assert.h>
 
 #include "../include/saAis.h"
 #include "../include/saAmf.h"
@@ -1010,12 +1011,16 @@ int amf_enabled (struct objdb_iface_ver0 *objdb)
 	unsigned int object_service_handle;
 	char *value;
 	int enabled = 0;
+	unsigned int object_find_handle;
 
-	objdb->object_find_reset (OBJECT_PARENT_HANDLE);
-	if (objdb->object_find (
+	objdb->object_find_create (
 		OBJECT_PARENT_HANDLE,
 		"amf",
 		strlen ("amf"),
+		&object_find_handle);
+
+	if (objdb->object_find_next (
+		object_find_handle,
 		&object_service_handle) == 0) {
 
 		value = NULL;
@@ -1034,6 +1039,8 @@ int amf_enabled (struct objdb_iface_ver0 *objdb)
 		}
 	}
 
+	objdb->object_find_destroy (object_find_handle);
+
 	return enabled;
 }
 

+ 10 - 6
openais/services/evt.c

@@ -3114,18 +3114,22 @@ static int evt_lib_exit(void *conn)
 static int evt_exec_init(struct corosync_api_v1 *corosync_api)
 {
 	unsigned int object_service_handle;
+	unsigned int object_find_handle;
 	char *value;
 
 	api = corosync_api;
 
 	log_printf(LOG_LEVEL_DEBUG, "Evt exec init request\n");
 
-	api->object_find_reset (OBJECT_PARENT_HANDLE);
-	if (api->object_find (
-		    OBJECT_PARENT_HANDLE,
-		    "event",
-		    strlen ("event"),
-		    &object_service_handle) == 0) {
+	api->object_find_create (
+		OBJECT_PARENT_HANDLE,
+		"event",
+		strlen ("event"),
+		&object_find_handle);
+
+	if (api->object_find_next (
+		object_find_handle,
+		&object_service_handle) == 0) {
 
 		value = NULL;
 		if ( !api->object_key_get (object_service_handle,

+ 0 - 2
openais/services/openaisparser.c

@@ -227,7 +227,6 @@ static int read_config_file_into_objdb(
 	objdb->object_key_create(object_handle, "ver", strlen("ver"),
 		"0", 2);
 
-#ifdef OUTAA
 	/*
 	 * Load msg module
 	 */
@@ -247,7 +246,6 @@ static int read_config_file_into_objdb(
 		"openais_lck", strlen("openais_lck") + 1);
 	objdb->object_key_create(object_handle, "ver", strlen("ver"),
 		"0", 2);
-#endif
 
 	sprintf (error_reason, "Successfully read main configuration file '%s'.\n", filename);
 	*error_string = error_reason;