cluster: STABLE3 - qdiskd: Reject invalid vote counts

Lon Hohberger lon at fedoraproject.org
Mon Mar 1 14:00:12 UTC 2010


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=b0836467149ce13739f5f96e21fdd3568c665a4a
Commit:        b0836467149ce13739f5f96e21fdd3568c665a4a
Parent:        24932ca16c5501bc54d8a8fe8daa61006bea9a66
Author:        Lon Hohberger <lhh at redhat.com>
AuthorDate:    Fri Feb 26 18:28:06 2010 -0500
Committer:     Lon Hohberger <lhh at redhat.com>
CommitterDate: Mon Mar 1 08:59:34 2010 -0500

qdiskd: Reject invalid vote counts

Qdiskd can not determine proper vote counts if
people use weighted voting.  Refuse to start
if someone does this.

Original patch from Fabio M. Di Nitto; I tweaked
the error messages slightly.

Signed-off-by: Lon Hohberger <lhh at redhat.com>
---
 cman/qdisk/main.c |   59 ++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 43 insertions(+), 16 deletions(-)

diff --git a/cman/qdisk/main.c b/cman/qdisk/main.c
index bf5b459..81218d0 100644
--- a/cman/qdisk/main.c
+++ b/cman/qdisk/main.c
@@ -1338,37 +1338,61 @@ get_log_config_data(int ccsfd)
 }
 
 
+/*
+ * return number of nodes - 1 on success
+ *        -1 on generic error
+ *        -2 if one of the node votes is != 1
+ */
 static int
 auto_qdisk_votes(int desc)
 {
-	int x = 0, ret = 0;
-	char buf[128];
+	int ret = 1;
+	char buf[PATH_MAX];
 	char *name;
 
-	if (desc < 0) {
-		return 1;
-	}
+	while (1) {
+		int votes=0;
 
-	while (++x) {
 		snprintf(buf, sizeof(buf)-1,
-			"/cluster/clusternodes/clusternode[%d]/@name", x);
+			"/cluster/clusternodes/clusternode[%d]/@votes", ret);
 
 		name = NULL;
 		if (ccs_get(desc, buf, &name) != 0)
 			break;
 
-		free(name);
-		ret = x;
-	}
+		votes=atoi(name);
+		if (votes != 1) {
+			free(name);
 
-	--ret;
-	if (ret <= 0) {
-		ret = 1;
-	}
+			snprintf(buf, sizeof(buf)-1,
+			    "/cluster/clusternodes/clusternode[%d]/@name",
+			    ret);
 
-	logt_print(LOG_DEBUG, "Setting votes to %d\n", ret);
+			if (ccs_get(desc, buf, &name) == 0) {
+				logt_print(LOG_ERR, "%s's vote count is %d\n",
+					   name, votes);
+				free(name);
+			}
 
-	return (ret);
+			logt_print(LOG_ERR, "Set all node vote counts to 1 "
+				   "or specify qdiskd's votes\n");
+			return -2;
+		}
+
+		free(name);
+		ret++;
+ 	}
+ 
+	// adjust count (one from init and one from the node count)
+	ret = ret - 2;
+ 
+	if (ret <= 0)
+		logt_print(LOG_ERR, "Unable to determine qdiskd votes "
+			   "automatically\n");
+	else
+		logt_print(LOG_DEBUG, "Setting votes to %d\n", ret);
+ 
+ 	return (ret);
 }
 
 
@@ -1518,6 +1542,9 @@ get_dynamic_config_data(qd_ctx *ctx, int ccsfd)
 					   "new vote value; retaining old "
 					   "value of %d\n", old_votes);
 				ctx->qc_votes = old_votes;
+			} else {
+				/* During startup, this is fatal */
+				return -1;
 			}
 		}
 	}


More information about the cluster-commits mailing list