[PATCH] totemconfig: check for duplicate node IDs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Having duplicate nodeids in corosync.conf can play havoc with a cluster,
so (as suggested by someone on this list) here is some code to check
that all nodeids are unique.

It logs all non-unique nodeids to syslog, but only the last is reported
on the command-line to the user which should be enough to get them to
check further.

Signed-off-by: Christine Caulfield <ccaulfie@xxxxxxxxxx>

diff --git a/exec/totemconfig.c b/exec/totemconfig.c
index b678752..a0ad26c 100644
--- a/exec/totemconfig.c
+++ b/exec/totemconfig.c
@@ -481,6 +481,71 @@ static int get_cluster_mcast_addr (
 	return (err);
 }
 
+static int check_for_duplicate_nodeids(
+	struct totem_config *totem_config,
+	const char **error_string)
+{
+	icmap_iter_t iter;
+	icmap_iter_t subiter;
+	const char *iter_key;
+	int res = 0;
+	int retval = 0;
+	char tmp_key[ICMAP_KEYNAME_MAXLEN];
+	unsigned int node_pos;
+	unsigned int node_pos1;
+	unsigned int nodeid;
+	unsigned int nodeid1;
+
+	iter = icmap_iter_init("nodelist.node.");
+	while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
+		res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
+		if (res != 2) {
+			continue;
+		}
+
+		if (strcmp(tmp_key, "ring0_addr") != 0) {
+			continue;
+		}
+
+		snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos);
+		if (icmap_get_uint32(tmp_key, &nodeid) != CS_OK) {
+			continue;
+		}
+
+		node_pos1 = 0;
+		subiter = icmap_iter_init("nodelist.node.");
+		while ((iter_key = icmap_iter_next(subiter, NULL, NULL)) != NULL && node_pos1 < node_pos) {
+			res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos1, tmp_key);
+			if (res != 2) {
+				continue;
+			}
+
+			if (strcmp(tmp_key, "ring0_addr") != 0) {
+				continue;
+			}
+
+			snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos1);
+			if (icmap_get_uint32(tmp_key, &nodeid1) != CS_OK) {
+				continue;
+			}
+			if (nodeid == nodeid1) {
+				retval = -1;
+
+				/* This makes sure we log all duplicate nodeids, the error system only allows us to report 1 */
+				snprintf (error_string_response, sizeof(error_string_response),
+					   "nodeid %d appears twice in corosync.conf", nodeid);
+				log_printf (LOGSYS_LEVEL_ERROR, error_string_response);
+				*error_string = error_string_response;
+				break;
+			}
+		}
+		icmap_iter_finalize(subiter);
+	}
+	icmap_iter_finalize(iter);
+	return retval;
+}
+
+
 static int find_local_node_in_nodelist(struct totem_config *totem_config)
 {
 	icmap_iter_t iter;
@@ -1236,6 +1301,10 @@ int totem_config_validate (
 		return (-1);
 	}
 
+	if (check_for_duplicate_nodeids(totem_config, error_string) == -1) {
+		return (-1);
+	}
+
 	/*
 	 * RRP values validation
 	 */
_______________________________________________
discuss mailing list
discuss@xxxxxxxxxxxx
http://lists.corosync.org/mailman/listinfo/discuss

[Index of Archives]     [Linux Clusters]     [Corosync Project]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [X.Org]

  Powered by Linux