All of lore.kernel.org
 help / color / mirror / Atom feed
From: teigland@sourceware.org <teigland@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] cluster/group/dlm_controld action.c
Date: 6 Jun 2007 21:10:04 -0000	[thread overview]
Message-ID: <20070606211004.26609.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/cluster
Module name:	cluster
Branch: 	RHEL5
Changes by:	teigland at sourceware.org	2007-06-06 21:10:03

Modified files:
	group/dlm_controld: action.c 

Log message:
	Split the new get_weight() function into two pieces so it's easier to
	understand (still does exactly the same steps).

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/group/dlm_controld/action.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.8.2.4&r2=1.8.2.5

--- cluster/group/dlm_controld/action.c	2007/06/05 20:12:43	1.8.2.4
+++ cluster/group/dlm_controld/action.c	2007/06/06 21:10:03	1.8.2.5
@@ -211,60 +211,94 @@
 #define MASTER_NAME   MASTER_PATH "/@name"
 #define MASTER_WEIGHT MASTER_PATH "[@name=\"%s\"]/@weight"
 
-static int get_weight(int cd, int nodeid, char *lockspace)
-{
-	char path[PATH_MAX], *str, *name;
-	int error, weight, flag = 0, count = 0;
+/* look for node's weight in the dlm/lockspace section */
 
-	name = nodeid2name(nodeid);
-	if (!name) {
-		log_error("no name for nodeid %d", nodeid);
-		return 1;
-	}
+static int get_weight_lockspace(int cd, char *node, char *lockspace)
+{
+	char path[PATH_MAX], *str;
+	int error, weight;
+	int master_count = 0, node_is_master = 0;
 
 	memset(path, 0, PATH_MAX);
 	sprintf(path, MASTER_NAME, lockspace);
 
-	while (1)
-	{
+	while (1) {
 		error = ccs_get_list(cd, path, &str);
-		if (error || !str) {
+		if (error || !str)
 			break;
-		}
-		count++;
-		if (strcmp(str, name) == 0) {
-			flag = 1;
-		}
+		master_count++;
+		if (strcmp(str, node) == 0)
+			node_is_master = 1;
 		free(str);
 	}
 
-	if (count > 0) {
-		if (flag) {
-			memset(path, 0, PATH_MAX);
-			sprintf(path, MASTER_WEIGHT, lockspace, name);
-
-			error = ccs_get(cd, path, &str);
-			if (error || !str)
-				return 1;
-
-			weight = atoi(str);
-			free(str);
-			return weight;
-		} else {
-			return 0;
-		}
-	} else {
-		memset(path, 0, PATH_MAX);
-		sprintf(path, WEIGHT_PATH, name);
+	/* if there are no masters, next check for a clusternode weight */
 
-		error = ccs_get(cd, path, &str);
-		if (error || !str)
-			return 1;
+	if (!master_count)
+		return -1;
 
-		weight = atoi(str);
-		free(str);
-		return weight;
+	/* if there's a master and this node isn't it, it gets weight 0 */
+
+	if (!node_is_master)
+		return 0;
+
+	/* master gets its specified weight or 1 if none is given */
+
+	memset(path, 0, PATH_MAX);
+	sprintf(path, MASTER_WEIGHT, lockspace, node);
+
+	error = ccs_get(cd, path, &str);
+	if (error || !str)
+		return 1;
+
+	weight = atoi(str);
+	free(str);
+	return weight;
+}
+
+/* look for node's weight on its clusternode line */
+
+static int get_weight_clusternode(int cd, char *node, char *lockspace)
+{
+	char path[PATH_MAX], *str;
+	int error, weight;
+
+	memset(path, 0, PATH_MAX);
+	sprintf(path, WEIGHT_PATH, node);
+
+	error = ccs_get(cd, path, &str);
+	if (error || !str)
+		return -1;
+
+	weight = atoi(str);
+	free(str);
+	return weight;
+}
+
+static int get_weight(int cd, int nodeid, char *lockspace)
+{
+	char *node;
+	int w;
+
+	node = nodeid2name(nodeid);
+	if (!node) {
+		log_error("no name for nodeid %d", nodeid);
+		w = 1;
+		goto out;
 	}
+
+	w = get_weight_lockspace(cd, node, lockspace);
+	if (w >= 0)
+		goto out;
+
+	w = get_weight_clusternode(cd, node, lockspace);
+	if (w >= 0)
+		goto out;
+
+	/* default weight is 1 */
+	w = 1;
+ out:
+	return w;
 }
 
 int set_members(char *name, int new_count, int *new_members)



             reply	other threads:[~2007-06-06 21:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-06 21:10 teigland [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-06-06 21:12 [Cluster-devel] cluster/group/dlm_controld action.c teigland
2007-06-05 20:12 rohara
2006-07-24 18:50 teigland
2006-07-14 13:59 rpeterso
2006-06-14 20:03 teigland
2006-06-14 16:37 teigland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070606211004.26609.qmail@sourceware.org \
    --to=teigland@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.