dlm: master - dlm_controld: fence config error handling

David Teigland teigland at fedoraproject.org
Thu Apr 5 18:51:02 UTC 2012


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=82f3290001c891e833e0b676bd4a07181c8081f9
Commit:        82f3290001c891e833e0b676bd4a07181c8081f9
Parent:        113c0ac73265bab222e5c11cbd6ac17ec109cf6a
Author:        David Teigland <teigland at redhat.com>
AuthorDate:    Mon Apr 2 16:35:07 2012 -0500
Committer:     David Teigland <teigland at redhat.com>
CommitterDate: Mon Apr 2 16:35:07 2012 -0500

dlm_controld: fence config error handling

Distinguish between errors for a config that doesn't
exist and a config with problems.

Signed-off-by: David Teigland <teigland at redhat.com>
---
 dlm_controld/daemon_cpg.c   |   13 ++++++++++---
 dlm_controld/fence.c        |    9 ++++++++-
 dlm_controld/fence_config.c |   36 ++++++++++++++++++++++++++----------
 dlm_controld/fence_config.h |   10 ++++++++++
 4 files changed, 54 insertions(+), 14 deletions(-)

diff --git a/dlm_controld/daemon_cpg.c b/dlm_controld/daemon_cpg.c
index 0339b5d..9f48da0 100644
--- a/dlm_controld/daemon_cpg.c
+++ b/dlm_controld/daemon_cpg.c
@@ -434,6 +434,7 @@ static struct node_daemon *add_node_daemon(int nodeid)
 {
 	struct node_daemon *node;
 	struct fence_config *fc;
+	int rv;
 
 	node = get_node_daemon(nodeid);
 	if (node)
@@ -462,12 +463,18 @@ static struct node_daemon *add_node_daemon(int nodeid)
 
 	/* explicit config file setting has second priority */
 
-	fence_config_init(fc, (unsigned int)nodeid, (char *)CONF_FILE_PATH);
+	rv = fence_config_init(fc, (unsigned int)nodeid, (char *)CONF_FILE_PATH);
+	if (!rv)
+		goto out;
 
-	/* no command line, no config file, use default, third priority */
+	/* no command line, no config file, so use default */
 
-	if (!fc->dev[0] && fence_all_agent[0])
+	if (rv == -ENOENT) {
 		fc->dev[0] = &fence_all_device;
+		goto out;
+	}
+
+	log_error("fence config %d error %d", nodeid, rv);
  out:
 	return node;
 }
diff --git a/dlm_controld/fence.c b/dlm_controld/fence.c
index 633b8d4..bf5d316 100644
--- a/dlm_controld/fence.c
+++ b/dlm_controld/fence.c
@@ -188,8 +188,15 @@ int unfence_node(int nodeid)
 	memset(&config, 0, sizeof(config));
 
 	rv = fence_config_init(&config, nodeid, (char *)CONF_FILE_PATH);
-	if (rv < 0)
+	if (rv == -ENOENT) {
+		/* file doesn't exist or doesn't contain config for nodeid */
 		return 0;
+	}
+	if (rv < 0) {
+		/* there's a problem with the config */
+		log_error("fence config %d error %d", nodeid, rv);
+		return rv;
+	}
 
 	memset(action, 0, sizeof(action));
 	snprintf(action, FENCE_CONFIG_NAME_MAX-1, "action=on\n");
diff --git a/dlm_controld/fence_config.c b/dlm_controld/fence_config.c
index 0c1782d..f886630 100644
--- a/dlm_controld/fence_config.c
+++ b/dlm_controld/fence_config.c
@@ -137,14 +137,15 @@ static int read_config_section(unsigned int nodeid, FILE *file, char *dev_line,
 			continue;
 
 		if (!strncmp(line, "unfence", strlen("unfence"))) {
-			/* TODO: verify dev_name matches */
+			if (!strstr(line, dev_name))
+				return -EINVAL;
 			unfence = 1;
 			continue;
 		}
 
 		/* invalid config */
 		if (strncmp(line, "connect", strlen("connect")))
-			return -1;
+			return -EINVAL;
 
 		/* once we've found the connect line we want, continue
 		   scanning lines until end of section so we pick up an
@@ -158,11 +159,11 @@ static int read_config_section(unsigned int nodeid, FILE *file, char *dev_line,
 
 		rv = sscanf(line, "%s %s %[^\n]s", unused, con_name, con_args);
 		if (rv < 3)
-			return -1;
+			return -EINVAL;
 
 		/* invalid config */
 		if (strncmp(dev_name, con_name, FENCE_CONFIG_NAME_MAX))
-			return -1;
+			return -EINVAL;
 
 		/* skip connection for another node */
 		if (con_args_nodeid(con_args) != nodeid)
@@ -197,8 +198,8 @@ static int read_config_section(unsigned int nodeid, FILE *file, char *dev_line,
 
 	if (dev)
 		return 0;
-
-	return -1;
+	else
+		return -ENOENT;
 }
 
 void fence_config_free(struct fence_config *fc)
@@ -232,7 +233,7 @@ int fence_config_init(struct fence_config *fc, unsigned int nodeid, char *path)
 
 	file = fopen(path, "r");
 	if (!file)
-		return -1;
+		return -ENOENT;
 
 	while (fgets(line, MAX_LINE, file)) {
 		if (line[0] == '#')
@@ -272,18 +273,33 @@ int fence_config_init(struct fence_config *fc, unsigned int nodeid, char *path)
 		if (strncmp(line, "device", strlen("device")))
 			continue;
 
-		/* read connect and unfence lines following a device line */
+		dev = NULL;
+		con = NULL;
 
+		/* read connect and unfence lines following a device line */
 		rv = read_config_section(nodeid, file, line, &dev, &con);
-		if (rv < 0)
+
+		/* nodeid not listed in this section */
+		if (rv == -ENOENT)
 			continue;
 
+		/* an error parsing the section, may be config to free */
+		if (rv < 0) {
+			if (dev)
+				free(dev);
+			if (con)
+				free(con);
+			goto out;
+		}
+
 		fc->dev[pos] = dev;
 		fc->con[pos] = con;
 		pos++;
 	}
 
-	if (pos)
+	if (!pos)
+		rv = -ENOENT;
+	else
 		rv = 0;
  out:
 	fclose(file);
diff --git a/dlm_controld/fence_config.h b/dlm_controld/fence_config.h
index 47e7bda..b55a964 100644
--- a/dlm_controld/fence_config.h
+++ b/dlm_controld/fence_config.h
@@ -35,7 +35,17 @@ struct fence_config {
 };
 
 
+/*
+ * Returns -ENOENT if path does not exist or there is no
+ * config for nodeid in the file.
+ *
+ * Returns -EXYZ if there's a problem with the config.
+ *
+ * Returns 0 if a config was found with no problems.
+ */
+
 int fence_config_init(struct fence_config *fc, unsigned int nodeid, char *path);
+
 void fence_config_free(struct fence_config *fc);
 
 /*


More information about the cluster-commits mailing list