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

config: Don't free pointers used by transports

reload failed for UDP[U] because they had saved pointers
to the interfaces[] array. so memcpy into that rather then
re-allocate it.

Also, move the check for different IP address families so
it also gets run at reload time.

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
Reviewed-by: Jan Friesse <jfriesse@redhat.com>
Christine Caulfield 5 лет назад
Родитель
Сommit
4ddc96cd4e
3 измененных файлов с 42 добавлено и 26 удалено
  1. 10 1
      exec/cfg.c
  2. 27 23
      exec/totemconfig.c
  3. 5 2
      exec/totempg.c

+ 10 - 1
exec/cfg.c

@@ -45,6 +45,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <stddef.h>
 #include <limits.h>
 #include <errno.h>
 #include <string.h>
@@ -722,6 +723,14 @@ static void message_handler_req_exec_cfg_reload_config (
 	assert(new_config.interfaces != NULL);
 	memset(new_config.interfaces, 0, sizeof (struct totem_interface) * INTERFACE_MAX);
 
+	/* For UDP[U] the configuration on link0 is static (apart from the nodelist) and only read at
+	   startup. So preserve it here */
+	if ( (new_config.transport_number == TOTEM_TRANSPORT_UDP) ||
+	     (new_config.transport_number == TOTEM_TRANSPORT_UDPU)) {
+		memcpy(&new_config.interfaces[0], &new_config.orig_interfaces[0],
+		       sizeof(struct totem_interface));
+	}
+
 	/* Calculate new node and interface definitions */
 	if (totemconfig_configure_new_params(&new_config, temp_map, &error_string) == -1) {
 		log_printf (LOGSYS_LEVEL_ERROR, "Cannot configure new interface definitions: %s\n", error_string);
@@ -750,8 +759,8 @@ static void message_handler_req_exec_cfg_reload_config (
 
 	/* Copy into live system */
 	totempg_put_config(&new_config);
-
 	totemconfig_commit_new_params(&new_config, temp_map);
+	free(new_config.interfaces);
 
 reload_fini:
 	/* All done - let clients know */

+ 27 - 23
exec/totemconfig.c

@@ -210,12 +210,12 @@ static void totem_volatile_config_set_string_value (struct totem_config *totem_c
 	const char *key_name, const char *deleted_key, const char *default_value)
 {
 	char runtime_key_name[ICMAP_KEYNAME_MAXLEN];
-	void **config_value;
+	void **config_value = NULL; /* compiler placation */
 	void *old_config_ptr;
 
 	config_value = totem_get_param_by_name(totem_config, key_name);
 	old_config_ptr = *config_value;
-	if (icmap_get_string_r(map, key_name, (char **)config_value) != CS_OK ||
+	if (icmap_get_string(key_name, (char **)config_value) != CS_OK ||
 	    (deleted_key != NULL && strcmp(deleted_key, key_name) == 0)) {
 
 		/* Need to strdup() here so that the free() below works for a default and a configured value */
@@ -364,11 +364,13 @@ int totem_volatile_config_validate (
 	icmap_map_t temp_map,
 	const char **error_string)
 {
+	/* Static just to keep them off the stack */
 	static char local_error_reason[512];
+	static char addr_str_buf[INET6_ADDRSTRLEN];
 	const char *error_reason = local_error_reason;
 	char name_key[ICMAP_KEYNAME_MAXLEN];
 	char *name_str;
-	int i, num_configured, members;
+	int i, j, num_configured, members;
 	uint32_t tmp_config_value;
 
 	if (totem_config->max_network_delay < MINIMUM_TIMEOUT) {
@@ -488,6 +490,27 @@ int totem_volatile_config_validate (
 		}
 	}
 
+	/* Verify that all nodes on the same link have the same IP family */
+	for (i=0; i < INTERFACE_MAX; i++) {
+		for (j=1; j<totem_config->interfaces[i].member_count; j++) {
+			if (totem_config->interfaces[i].configured) {
+				if (totem_config->interfaces[i].member_list[j].family !=
+				    totem_config->interfaces[i].member_list[0].family) {
+					memcpy(addr_str_buf,
+					    totemip_print(&(totem_config->interfaces[i].member_list[j])),
+					    sizeof(addr_str_buf));
+
+					snprintf (local_error_reason, sizeof(local_error_reason),
+						  "Nodes for link %d have different IP families "
+						  "(compared %s with %s)", i,
+						  addr_str_buf,
+						  totemip_print(&(totem_config->interfaces[i].member_list[0])));
+					goto parse_error;
+				}
+			}
+		}
+	}
+
 	return 0;
 
 parse_error:
@@ -1905,9 +1928,8 @@ int totem_config_validate (
 {
 	static char local_error_reason[512];
 	char parse_error[512];
-	static char addr_str_buf[INET6_ADDRSTRLEN];
 	const char *error_reason = local_error_reason;
-	int i,j;
+	int i;
 	uint32_t u32;
 	int num_configured = 0;
 	unsigned int interface_max = INTERFACE_MAX;
@@ -1990,24 +2012,6 @@ int totem_config_validate (
 				goto parse_error;
 			}
 		}
-		/* Verify that all nodes on the same knet link have the same IP family */
-		for (j=1; j<totem_config->interfaces[i].member_count; j++) {
-			if (totem_config->interfaces[i].configured) {
-				if (totem_config->interfaces[i].member_list[j].family !=
-				    totem_config->interfaces[i].member_list[0].family) {
-					memcpy(addr_str_buf,
-					    totemip_print(&(totem_config->interfaces[i].member_list[j])),
-					    sizeof(addr_str_buf));
-
-					snprintf (local_error_reason, sizeof(local_error_reason),
-						  "Nodes for link %d have different IP families "
-						  "(compared %s with %s)", i,
-						  addr_str_buf,
-						  totemip_print(&(totem_config->interfaces[i].member_list[0])));
-					goto parse_error;
-				}
-			}
-		}
 	}
 
 	if (totem_config->version != 2) {

+ 5 - 2
exec/totempg.c

@@ -1599,7 +1599,10 @@ void totempg_get_config(struct totem_config *config)
 
 void totempg_put_config(struct totem_config *config)
 {
-	/* Free this before we overwite the pointer */
-	free(totempg_totem_config->interfaces);
+	struct totem_interface *temp_if = totempg_totem_config->interfaces;
+
+	/* Preseve the existing interfaces[] array as transports might have pointers saved */
+	memcpy(totempg_totem_config->interfaces, config->interfaces, sizeof(struct totem_interface) * INTERFACE_MAX);
 	memcpy(totempg_totem_config, config, sizeof(struct totem_config));
+	totempg_totem_config->interfaces = temp_if;
 }