public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
* master - cman: tidy objdb_get_int
@ 2008-08-04 13:59 Christine Caulfield
  0 siblings, 0 replies; only message in thread
From: Christine Caulfield @ 2008-08-04 13:59 UTC (permalink / raw)
  To: cluster-cvs-relay

Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=87f7e54e6b463275cbc663698e8af060ebc8ebf8
Commit:        87f7e54e6b463275cbc663698e8af060ebc8ebf8
Parent:        324bde4df67558329fa9acaa9062edd090f05bab
Author:        Christine Caulfield <ccaulfie@redhat.com>
AuthorDate:    Mon Aug 4 08:30:23 2008 +0100
Committer:     Christine Caulfield <ccaulfie@redhat.com>
CommitterDate: Mon Aug 4 08:30:23 2008 +0100

cman: tidy objdb_get_int

Make objdb_get_int take a default value tat gets filled in then there
is no value in the objdb. This tidies the situation hugely as well
as fixing bugs that arose because of the ambiguous nature of the
function's returned values.

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
---
 cman/daemon/ais.c            |    8 ++++----
 cman/daemon/cman-preconfig.c |   16 ++++------------
 cman/daemon/cman.h           |    9 +++++++++
 cman/daemon/cmanconfig.c     |   27 +++++++++++----------------
 cman/daemon/cmanconfig.h     |    4 +++-
 cman/daemon/commands.c       |    6 +++---
 cman/daemon/daemon.c         |    2 +-
 7 files changed, 35 insertions(+), 37 deletions(-)

diff --git a/cman/daemon/ais.c b/cman/daemon/ais.c
index c73e507..615afcb 100644
--- a/cman/daemon/ais.c
+++ b/cman/daemon/ais.c
@@ -156,10 +156,10 @@ static int cman_exec_init_fn(struct objdb_iface_ver0 *objdb)
 	objdb->object_find_reset(cluster_parent_handle);
 	if (objdb->object_find(cluster_parent_handle, "cman", strlen("cman"), &object_handle) == 0)
 	{
-		objdb_get_int(objdb, object_handle, "quorum_dev_poll", &quorumdev_poll);
-		objdb_get_int(objdb, object_handle, "shutdown_timeout", &shutdown_timeout);
-		objdb_get_int(objdb, object_handle, "ccsd_poll", &ccsd_poll_interval);
-		objdb_get_int(objdb, object_handle, "debug_mask", &debug_mask);
+		objdb_get_int(objdb, object_handle, "quorum_dev_poll", &quorumdev_poll, DEFAULT_QUORUMDEV_POLL);
+		objdb_get_int(objdb, object_handle, "shutdown_timeout", &shutdown_timeout, DEFAULT_SHUTDOWN_TIMEOUT);
+		objdb_get_int(objdb, object_handle, "ccsd_poll", &ccsd_poll_interval, DEFAULT_CCSD_POLL);
+		objdb_get_int(objdb, object_handle, "debug_mask", &debug_mask, 0);
 
 		/* All other debugging options should already have been set in preconfig */
 		set_debuglog(debug_mask);
diff --git a/cman/daemon/cman-preconfig.c b/cman/daemon/cman-preconfig.c
index f15ede0..0cc2f73 100644
--- a/cman/daemon/cman-preconfig.c
+++ b/cman/daemon/cman-preconfig.c
@@ -14,10 +14,6 @@
 #include <ifaddrs.h>
 #include <arpa/inet.h>
 
-#define DEFAULT_PORT            5405
-#define DEFAULT_CLUSTER_NAME    "RHCluster"
-#define NOCCS_KEY_FILENAME      "/etc/cluster/cman_authkey"
-
 /* openais headers */
 #include <openais/service/objdb.h>
 #include <openais/service/swab.h>
@@ -587,9 +583,7 @@ static int get_nodename(struct objdb_iface_ver0 *objdb)
 
 	/* optional port */
 	if (!portnum) {
-		objdb_get_int(objdb, object_handle, "port", &portnum);
-		if (!portnum)
-			portnum = DEFAULT_PORT;
+		objdb_get_int(objdb, object_handle, "port", &portnum, DEFAULT_PORT);
 	}
 
 	if (add_ifaddr(objdb, mcast_name, nodename, portnum))
@@ -609,9 +603,7 @@ static int get_nodename(struct objdb_iface_ver0 *objdb)
 			continue;
 		}
 
-		objdb_get_int(objdb, alt_object, "port", &port);
-		if (!port)
-			port = portnum;
+		objdb_get_int(objdb, alt_object, "port", &port, portnum);
 
 		if (objdb_get_string(objdb, alt_object, "mcast", &mcast)) {
 			mcast = mcast_name;
@@ -944,13 +936,13 @@ static int get_cman_globals(struct objdb_iface_ver0 *objdb)
 			       "cman", strlen("cman"),
 			       &object_handle) == 0) {
 		if (!portnum)
-			objdb_get_int(objdb, object_handle, "port", &portnum);
+			objdb_get_int(objdb, object_handle, "port", &portnum, DEFAULT_PORT);
 
 		if (!key_filename)
 			objdb_get_string(objdb, object_handle, "keyfile", &key_filename);
 
 		if (!cluster_id)
-			objdb_get_int(objdb, object_handle, "cluster_id", &cluster_id);
+			objdb_get_int(objdb, object_handle, "cluster_id", &cluster_id, 0);
 
 		if (!cluster_id)
 			cluster_id = generate_cluster_id(cluster_name);
diff --git a/cman/daemon/cman.h b/cman/daemon/cman.h
index 748602a..bba91aa 100644
--- a/cman/daemon/cman.h
+++ b/cman/daemon/cman.h
@@ -4,3 +4,12 @@ extern void close_cman_pipe(void);
 
 /* How we announce ourself in syslog */
 #define CMAN_NAME "CMAN"
+
+/* Defaults for configuration variables */
+#define NOCCS_KEY_FILENAME      "/etc/cluster/cman_authkey"
+#define DEFAULT_PORT            5405
+#define DEFAULT_CLUSTER_NAME    "RHCluster"
+#define DEFAULT_MAX_QUEUED       128
+#define DEFAULT_QUORUMDEV_POLL   10000
+#define DEFAULT_SHUTDOWN_TIMEOUT 5000
+#define DEFAULT_CCSD_POLL        1000
diff --git a/cman/daemon/cmanconfig.c b/cman/daemon/cmanconfig.c
index 98b615b..3a6091e 100644
--- a/cman/daemon/cmanconfig.c
+++ b/cman/daemon/cmanconfig.c
@@ -49,7 +49,7 @@ int read_cman_nodes(struct objdb_iface_ver0 *objdb, unsigned int *config_version
     char *nodename;
 
     /* New config version */
-    objdb_get_int(objdb, cluster_parent_handle, "config_version", config_version);
+    objdb_get_int(objdb, cluster_parent_handle, "config_version", config_version, 0);
 
     objdb->object_find_reset(cluster_parent_handle);
 
@@ -59,11 +59,11 @@ int read_cman_nodes(struct objdb_iface_ver0 *objdb, unsigned int *config_version
     {
 	    /* This overrides any other expected votes calculation /except/ for
 	       one specified on a join command-line */
-	    objdb_get_int(objdb, object_handle, "expected_votes", &expected);
-	    objdb_get_int(objdb, object_handle, "two_node", (unsigned int *)&two_node);
-	    objdb_get_int(objdb, object_handle, "cluster_id", &cluster_id);
+	    objdb_get_int(objdb, object_handle, "expected_votes", &expected, 0);
+	    objdb_get_int(objdb, object_handle, "two_node", (unsigned int *)&two_node, 0);
+	    objdb_get_int(objdb, object_handle, "cluster_id", &cluster_id, 0);
 	    objdb_get_string(objdb, object_handle, "nodename", &our_nodename);
-	    objdb_get_int(objdb, object_handle, "max_queued", &max_outstanding_messages);
+	    objdb_get_int(objdb, object_handle, "max_queued", &max_outstanding_messages, DEFAULT_MAX_QUEUED);
     }
 
     clear_reread_flags();
@@ -76,11 +76,11 @@ int read_cman_nodes(struct objdb_iface_ver0 *objdb, unsigned int *config_version
 		    continue;
 	    }
 
-	    objdb_get_int(objdb, nodes_handle, "votes", (unsigned int *)&votes);
+	    objdb_get_int(objdb, nodes_handle, "votes", (unsigned int *)&votes, 0);
 	    if (votes == 0)
 		    votes = 1;
 
-	    objdb_get_int(objdb, nodes_handle, "nodeid", (unsigned int *)&nodeid);
+	    objdb_get_int(objdb, nodes_handle, "nodeid", (unsigned int *)&nodeid, 0);
 
 	    if (check_nodeids && nodeid == 0) {
 		    char message[132];
@@ -173,7 +173,7 @@ static int get_cman_join_info(struct objdb_iface_ver0 *objdb)
 
 			node_count++;
 
-			objdb_get_int(objdb, nodes_handle, "votes", (unsigned int *)&votes);
+			objdb_get_int(objdb, nodes_handle, "votes", (unsigned int *)&votes, 0);
 			if (votes == 0)
 				votes = 1;
 
@@ -194,7 +194,7 @@ static int get_cman_join_info(struct objdb_iface_ver0 *objdb)
 		{
 
 			/* optional expected_votes supercedes vote sum */
-			objdb_get_int(objdb, object_handle, "expected_votes", (unsigned int *)&expected_votes);
+			objdb_get_int(objdb, object_handle, "expected_votes", (unsigned int *)&expected_votes, 0);
 			if (!expected_votes)
 				expected_votes = vote_sum;
 		}
@@ -215,9 +215,7 @@ static int get_cman_join_info(struct objdb_iface_ver0 *objdb)
 
 	if (!votes) {
 		unsigned int votestmp=-1;
-		objdb_get_int(objdb, node_object, "votes", &votestmp);
-		if (votestmp == -1)
-			votestmp = 1;
+		objdb_get_int(objdb, node_object, "votes", &votestmp, 1);
 
 		if (votestmp < 0 || votestmp > 255) {
 			log_printf(LOG_ERR, "invalid votes value %d", votestmp);
@@ -226,9 +224,6 @@ static int get_cman_join_info(struct objdb_iface_ver0 *objdb)
 		}
 		votes = votestmp;
 	}
-	if (!votes) {
-		votes = 1;
-	}
 	our_votes = votes;
 
 	/* nodeid */
@@ -238,7 +233,7 @@ static int get_cman_join_info(struct objdb_iface_ver0 *objdb)
 	}
 
 	if (!nodeid) {
-		objdb_get_int(objdb, node_object, "nodeid", (unsigned int *)&nodeid);
+		objdb_get_int(objdb, node_object, "nodeid", (unsigned int *)&nodeid, 0);
 	}
 
 	if (!nodeid) {
diff --git a/cman/daemon/cmanconfig.h b/cman/daemon/cmanconfig.h
index 9881a05..aa30f65 100644
--- a/cman/daemon/cmanconfig.h
+++ b/cman/daemon/cmanconfig.h
@@ -20,10 +20,12 @@ static inline int objdb_get_string(struct objdb_iface_ver0 *objdb, unsigned int
 }
 
 static inline void objdb_get_int(struct objdb_iface_ver0 *objdb, unsigned int object_service_handle,
-				   char *key, unsigned int *intvalue)
+				 char *key, unsigned int *intvalue, unsigned int default_value)
 {
 	char *value = NULL;
 
+	*intvalue = default_value;
+
 	if (!objdb->object_key_get(object_service_handle, key, strlen(key),
 				   (void *)&value, NULL)) {
 		if (value) {
diff --git a/cman/daemon/commands.c b/cman/daemon/commands.c
index d814d76..65e4df4 100644
--- a/cman/daemon/commands.c
+++ b/cman/daemon/commands.c
@@ -56,9 +56,9 @@ static LIST_INIT(cluster_members_list);
 static struct cluster_node *us;
 static int quorum;
 extern int two_node;
-       unsigned int quorumdev_poll=10000;
-       unsigned int shutdown_timeout=5000;
-       unsigned int ccsd_poll_interval=1000;
+       unsigned int quorumdev_poll=DEFAULT_QUORUMDEV_POLL;
+       unsigned int shutdown_timeout=DEFAULT_SHUTDOWN_TIMEOUT;
+       unsigned int ccsd_poll_interval=DEFAULT_CCSD_POLL;
 static int cluster_is_quorate;
        char cluster_name[MAX_CLUSTER_NAME_LEN+1];
 static char nodename[MAX_CLUSTER_MEMBER_NAME_LEN+1];
diff --git a/cman/daemon/daemon.c b/cman/daemon/daemon.c
index 3c18fc7..3934b0f 100644
--- a/cman/daemon/daemon.c
+++ b/cman/daemon/daemon.c
@@ -49,7 +49,7 @@ volatile sig_atomic_t quit_threads=0;
 
 int num_connections = 0;
 poll_handle ais_poll_handle;
-uint32_t max_outstanding_messages = 128;
+uint32_t max_outstanding_messages = DEFAULT_MAX_QUEUED;
 
 static int process_client(poll_handle handle, int fd, int revent, void *data);
 static void remove_client(poll_handle handle, struct connection *con);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-08-04  7:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-04 13:59 master - cman: tidy objdb_get_int Christine Caulfield

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).