public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Teigland <teigland@redhat.com>
To: akpm@osdl.org
Cc: linux-kernel@vger.kernel.org
Subject: [patch 04/12] dlm: node weights
Date: Fri, 15 Jul 2005 18:36:07 +0800	[thread overview]
Message-ID: <20050715103607.GG17316@redhat.com> (raw)

[-- Attachment #1: node-weights.patch --]
[-- Type: text/plain, Size: 4115 bytes --]

Use node weights in directory mapping.  Allows nodes to be configured to
be responsible for more or less of the directory.

Signed-off-by: David Teigland <teigland@redhat.com>

Index: linux-2.6.12-mm1/drivers/dlm/dir.c
===================================================================
--- linux-2.6.12-mm1.orig/drivers/dlm/dir.c
+++ linux-2.6.12-mm1/drivers/dlm/dir.c
@@ -89,13 +89,17 @@ int dlm_dir_name2nodeid(struct dlm_ls *l
 	}
 
 	hash = dlm_hash(name, length);
-	node = (hash >> 16) % ls->ls_num_nodes;
 
 	if (ls->ls_node_array) {
+		node = (hash >> 16) % ls->ls_total_weight;
 		nodeid = ls->ls_node_array[node];
 		goto out;
 	}
 
+	/* make_member_array() failed to kmalloc ls_node_array... */
+
+	node = (hash >> 16) % ls->ls_num_nodes;
+
 	list_for_each(tmp, &ls->ls_nodes) {
 		if (n++ != node)
 			continue;
Index: linux-2.6.12-mm1/drivers/dlm/dlm_internal.h
===================================================================
--- linux-2.6.12-mm1.orig/drivers/dlm/dlm_internal.h
+++ linux-2.6.12-mm1/drivers/dlm/dlm_internal.h
@@ -134,6 +134,7 @@ struct dlm_member {
 	struct list_head	list;
 	int			nodeid;
 	int			gone_event;
+	int			weight;
 };
 
 /*
@@ -457,6 +458,7 @@ struct dlm_ls {
 	struct list_head	ls_nodes_gone;	/* dead node list, recovery */
 	int			ls_num_nodes;	/* number of nodes in ls */
 	int			ls_low_nodeid;
+	int			ls_total_weight;
 	int			*ls_node_array;
 	int			*ls_nodeids_next;
 	int			ls_nodeids_next_count;
Index: linux-2.6.12-mm1/drivers/dlm/lowcomms.c
===================================================================
--- linux-2.6.12-mm1.orig/drivers/dlm/lowcomms.c
+++ linux-2.6.12-mm1/drivers/dlm/lowcomms.c
@@ -254,6 +254,19 @@ static int nodeid_to_addr(int nodeid, st
 	return 0;
 }
 
+int dlm_node_weight(int nodeid)
+{
+	struct dlm_node *node;
+	int weight = -1;
+
+	down(&nodes_sem);
+	node = search_node(nodeid);
+	if (node)
+		weight = node->weight;
+	up(&nodes_sem);
+	return weight;
+}
+
 int dlm_set_node(int nodeid, int weight, char *addr_buf)
 {
 	struct dlm_node *node;
Index: linux-2.6.12-mm1/drivers/dlm/lowcomms.h
===================================================================
--- linux-2.6.12-mm1.orig/drivers/dlm/lowcomms.h
+++ linux-2.6.12-mm1/drivers/dlm/lowcomms.h
@@ -23,6 +23,7 @@ void dlm_lowcomms_commit_buffer(void *mh
 int dlm_set_node(int nodeid, int weight, char *addr_buf);
 int dlm_set_local(int nodeid, int weight, char *addr_buf);
 int dlm_our_nodeid(void);
+int dlm_node_weight(int nodeid);
 
 #endif				/* __LOWCOMMS_DOT_H__ */
 
Index: linux-2.6.12-mm1/drivers/dlm/member.c
===================================================================
--- linux-2.6.12-mm1.orig/drivers/dlm/member.c
+++ linux-2.6.12-mm1/drivers/dlm/member.c
@@ -56,6 +56,7 @@ static int dlm_add_member(struct dlm_ls 
 		return -ENOMEM;
 
 	memb->nodeid = nodeid;
+	memb->weight = dlm_node_weight(nodeid);
 	add_ordered_member(ls, memb);
 	ls->ls_num_nodes++;
 	return 0;
@@ -126,19 +127,43 @@ void dlm_clear_members_finish(struct dlm
 static void make_member_array(struct dlm_ls *ls)
 {
 	struct dlm_member *memb;
-	int i = 0, *array;
+	int i, w, x = 0, total = 0, all_zero = 0, *array;
 
-	if (ls->ls_node_array) {
-		kfree(ls->ls_node_array);
-		ls->ls_node_array = NULL;
+	kfree(ls->ls_node_array);
+	ls->ls_node_array = NULL;
+
+	list_for_each_entry(memb, &ls->ls_nodes, list) {
+		if (memb->weight)
+			total += memb->weight;
 	}
 
-	array = kmalloc(sizeof(int) * ls->ls_num_nodes, GFP_KERNEL);
+	/* all nodes revert to weight of 1 if all have weight 0 */
+
+	if (!total) {
+		total = ls->ls_num_nodes;
+		all_zero = 1;
+	}
+
+	ls->ls_total_weight = total;
+
+	array = kmalloc(sizeof(int) * total, GFP_KERNEL);
 	if (!array)
 		return;
 
-	list_for_each_entry(memb, &ls->ls_nodes, list)
-		array[i++] = memb->nodeid;
+	list_for_each_entry(memb, &ls->ls_nodes, list) {
+		if (!all_zero && !memb->weight)
+			continue;
+
+		if (all_zero)
+			w = 1;
+		else
+			w = memb->weight;
+
+		DLM_ASSERT(x < total, printk("total %d x %d\n", total, x););
+
+		for (i = 0; i < w; i++)
+			array[x++] = memb->nodeid;
+	}
 
 	ls->ls_node_array = array;
 }

--

                 reply	other threads:[~2005-07-15 10:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20050715103607.GG17316@redhat.com \
    --to=teigland@redhat.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox