[Ocfs2-commits] khackel commits r1919 - branches/dlm-reco-mig/fs/ocfs2/dlm

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Mon Feb 28 17:02:17 CST 2005


Author: khackel
Date: 2005-02-28 17:02:15 -0600 (Mon, 28 Feb 2005)
New Revision: 1919

Modified:
   branches/dlm-reco-mig/fs/ocfs2/dlm/dlmmaster.c
Log:
* introduce dlm_find_mle as the standard method for searching the
  master list and getting a ref if a matching mle is found


Modified: branches/dlm-reco-mig/fs/ocfs2/dlm/dlmmaster.c
===================================================================
--- branches/dlm-reco-mig/fs/ocfs2/dlm/dlmmaster.c	2005-02-28 22:26:34 UTC (rev 1918)
+++ branches/dlm-reco-mig/fs/ocfs2/dlm/dlmmaster.c	2005-02-28 23:02:15 UTC (rev 1919)
@@ -59,12 +59,15 @@
 			unsigned int namelen,
 			int locked);
 static void dlm_put_mle(dlm_master_list_entry *mle);
-static int dlm_do_master_request(dlm_master_list_entry *mle, int to);
-static int dlm_do_assert_master(dlm_master_list_entry *mle);
+static int dlm_find_mle(dlm_ctxt *dlm, dlm_master_list_entry **mle,
+			char *name, unsigned int namelen);
 static void dlm_mle_node_up(struct inode *group, struct inode *node, 
 		     int idx, void *data);
 static void dlm_mle_node_down(struct inode *group, struct inode *node, 
 		       int idx, void *data);
+
+static int dlm_do_master_request(dlm_master_list_entry *mle, int to);
+static int dlm_do_assert_master(dlm_master_list_entry *mle);
 static dlm_lock_resource *dlm_new_lockres(dlm_ctxt *dlm,
 					  const char *name,
 					  unsigned int namelen);
@@ -98,6 +101,8 @@
 	res->owner = owner;
 }
 
+
+
 /* remove from list and free */
 static void dlm_put_mle(dlm_master_list_entry *mle)
 {
@@ -172,6 +177,27 @@
 	return ret;
 }
 
+
+/* returns 1 if found, 0 if not */
+static int dlm_find_mle(dlm_ctxt *dlm, dlm_master_list_entry **mle,
+			char *name, unsigned int namelen)
+{
+	dlm_master_list_entry *tmpmle;
+	struct list_head *iter;
+
+	list_for_each(iter, &dlm->master_list) {
+		tmpmle = list_entry(iter, dlm_master_list_entry, list);
+		if (!dlm_mle_equal(dlm, tmpmle, name, namelen))
+			continue;
+		dlm_get_mle(tmpmle);
+		*mle = tmpmle;
+		return 1;
+	}
+	return 0;
+}
+
+
+
 /////////////////////////////////////////////////
 //
 // TODO: change these comments to reflect reality
@@ -327,7 +353,6 @@
 {
 	dlm_lock_resource *tmpres=NULL, *res=NULL;
 	dlm_master_list_entry *mle = NULL, *tmpmle = NULL;
-	struct list_head *iter;
 	int blocked = 0;
 	int map_changed = 0, restart = 0, assert = 0;
 	int ret, start, bit;
@@ -389,22 +414,14 @@
 
 	/* check master list to see if another node has started mastering it */
 	spin_lock(&dlm->master_lock);
-	list_for_each(iter, &dlm->master_list) {
-		tmpmle = list_entry(iter, dlm_master_list_entry, list);
-		if (!dlm_mle_equal(dlm, tmpmle, lockid, namelen))
-			continue;
-
+	blocked = dlm_find_mle(dlm, &tmpmle, (char *)lockid, namelen);
+	if (blocked) {
 		if (tmpmle->type == DLM_MLE_MASTER) {
 			dlmprintk0("eek! master entry for nonexistent "
 				   "lock!\n");
 			BUG();
 		}
-		dlm_get_mle(tmpmle);
-		blocked = 1;
-		// found a block, wait for lock to be mastered by another node
-		break;
 	}
-
 	if (!blocked) {
 		/* go ahead and try to master lock on this node */
 		if (dlm_init_mle(mle, DLM_MLE_MASTER, dlm, res, NULL, 0, 1)) {
@@ -634,7 +651,6 @@
 	char *name;
 	unsigned int namelen;
 	int found;
-	struct list_head *iter;
 
 	if (!dlm_grab(dlm))
 		return DLM_MASTER_RESP_NO;
@@ -682,39 +698,33 @@
 		}
 
 		// dlmprintk0("lockres is in progress...\n");
-		found = 0;
 		spin_lock(&dlm->master_lock);
-		list_for_each(iter, &dlm->master_list) {
-			tmpmle = list_entry(iter, dlm_master_list_entry, list);
-			if (!dlm_mle_equal(dlm, tmpmle, name, namelen))
-				continue;
-
-			dlm_get_mle(tmpmle);
-			spin_lock(&tmpmle->spinlock);
-			if (tmpmle->type == DLM_MLE_BLOCK) {
-				// dlmprintk0("this node is waiting for "
-				// "lockres to be mastered\n");
-				response = DLM_MASTER_RESP_NO;
-			} else {
-				// dlmprintk0("this node is attempting to "
-				// "master lockres\n");
-				response = DLM_MASTER_RESP_MAYBE;
-			}
-			set_bit(request->node_idx, tmpmle->maybe_map);
-			spin_unlock(&tmpmle->spinlock);
-
-			spin_unlock(&dlm->master_lock);
-			spin_unlock(&res->spinlock);
-
-			dlm_put_mle(tmpmle);
-			if (mle)
-				kfree(mle);
-			goto send_response;
+		found = dlm_find_mle(dlm, &tmpmle, name, namelen);
+		if (!found) {
+			dlmprintk0("bug bug bug!!!  "
+				   "no mle found for this lock!\n");
+			BUG();
 		}
+		spin_lock(&tmpmle->spinlock);
+		if (tmpmle->type == DLM_MLE_BLOCK) {
+			// dlmprintk0("this node is waiting for "
+			// "lockres to be mastered\n");
+			response = DLM_MASTER_RESP_NO;
+		} else {
+			// dlmprintk0("this node is attempting to "
+			// "master lockres\n");
+			response = DLM_MASTER_RESP_MAYBE;
+		}
+		set_bit(request->node_idx, tmpmle->maybe_map);
+		spin_unlock(&tmpmle->spinlock);
+
 		spin_unlock(&dlm->master_lock);
 		spin_unlock(&res->spinlock);
-		dlmprintk0("bug bug bug!!!  no mle found for this lock!\n");
-		BUG();
+
+		dlm_put_mle(tmpmle);
+		if (mle)
+			kfree(mle);
+		goto send_response;
 	}
 
 	/* 
@@ -723,17 +733,8 @@
 	 * if there is an MLE_MASTER, return MAYBE
 	 * otherwise, add an MLE_BLOCK, return NO 
 	 */
-	found = 0;
 	spin_lock(&dlm->master_lock);
-	list_for_each(iter, &dlm->master_list) {
-		tmpmle = list_entry(iter, dlm_master_list_entry, list);
-		if (!dlm_mle_equal(dlm, tmpmle, name, namelen))
-			continue;
-		dlm_get_mle(tmpmle);
-		found = 1;
-		break;
-	}
-
+	found = dlm_find_mle(dlm, &tmpmle, name, namelen);
 	if (!found) {
 		/* this lockid has never been seen on this node yet */
 		// dlmprintk0("no mle found\n");
@@ -772,11 +773,13 @@
 			response = DLM_MASTER_RESP_MAYBE;
 		set_bit(request->node_idx, tmpmle->maybe_map);
 		spin_unlock(&tmpmle->spinlock);
-		dlm_put_mle(tmpmle);
 	}
 	spin_unlock(&dlm->master_lock);
 	spin_unlock(&dlm->spinlock);
 
+	if (found) {
+		dlm_put_mle(tmpmle);
+	}
 send_response:
 	dlm_put(dlm);
 	return response;
@@ -797,8 +800,7 @@
 	dlm_ctxt *dlm = data;
 	dlm_master_list_entry *mle = NULL;
 	dlm_master_request_resp *resp = (dlm_master_request_resp *) msg->buf;
-	int found = 0, wake = 0;
-	struct list_head *iter;
+	int wake = 0;
 
 	if (!dlm_grab(dlm))
 		return 0;
@@ -811,67 +813,63 @@
 	}
 
 	spin_lock(&dlm->master_lock);
-	list_for_each(iter, &dlm->master_list) {
-		mle = list_entry(iter, dlm_master_list_entry, list);
-		if (!dlm_mle_equal(dlm, mle, resp->name, resp->namelen)) {
-			mle = NULL;
-			continue;
-		}
+	if (!dlm_find_mle(dlm, &mle, resp->name, resp->namelen))
+		goto leave;
 
-		dlm_get_mle(mle);
-		if (mle->type == DLM_MLE_BLOCK) {
-			dlmprintk0("eek! cannot get a response for a block!\n");
+	if (mle->type == DLM_MLE_BLOCK) {
+		dlmprintk0("eek! cannot get a response for a block!\n");
+		goto leave;
+	}
+
+	wake = 0;
+	spin_lock(&mle->spinlock);
+	switch (resp->response) {
+		case DLM_MASTER_RESP_YES:
+			set_bit(resp->node_idx, mle->response_map);
+			// dlmprintk("woot!  node %u is the master!\n",
+			// resp->node_idx);
+			mle->master = resp->node_idx;
+			wake = 1;
 			break;
-		}
-		found = 1;
-		wake = 0;
-		spin_lock(&mle->spinlock);
-		switch (resp->response) {
-			case DLM_MASTER_RESP_YES:
-				set_bit(resp->node_idx, mle->response_map);
-				// dlmprintk("woot!  node %u is the master!\n",
-				// resp->node_idx);
-				mle->master = resp->node_idx;
+		case DLM_MASTER_RESP_NO:
+			// dlmprintk("node %u is not the master, not "
+			// "in-progress\n", resp->node_idx);
+			set_bit(resp->node_idx, mle->response_map);
+			if (memcmp(mle->response_map, mle->vote_map, 
+				   sizeof(mle->vote_map))==0)
 				wake = 1;
-				break;
-			case DLM_MASTER_RESP_NO:
-				// dlmprintk("node %u is not the master, not "
-				// "in-progress\n", resp->node_idx);
-				set_bit(resp->node_idx, mle->response_map);
-				if (memcmp(mle->response_map, mle->vote_map, 
-					   sizeof(mle->vote_map))==0)
-					wake = 1;
-				break;
-			case DLM_MASTER_RESP_MAYBE:
-				//dlmprintk("node %u is not the master, but IS"
-				//" in-progress\n", resp->node_idx);
-				set_bit(resp->node_idx, mle->response_map);
-				set_bit(resp->node_idx, mle->maybe_map);
-				if (memcmp(mle->response_map, mle->vote_map, 
-					   sizeof(mle->vote_map))==0)
-					wake = 1;
-				break;
-			case DLM_MASTER_RESP_ERROR:
-				dlmprintk("node %u hit an -ENOMEM!  try this "
-					  "whole thing again\n", 
-					  resp->node_idx);
-				mle->error = 1;
+			break;
+		case DLM_MASTER_RESP_MAYBE:
+			//dlmprintk("node %u is not the master, but IS"
+			//" in-progress\n", resp->node_idx);
+			set_bit(resp->node_idx, mle->response_map);
+			set_bit(resp->node_idx, mle->maybe_map);
+			if (memcmp(mle->response_map, mle->vote_map, 
+				   sizeof(mle->vote_map))==0)
 				wake = 1;
-				break;
-			default:
-				dlmprintk("bad response! %u\n", resp->response);
-				break;
-		}
-		if (wake) {		
-			atomic_set(&mle->woken, 1);
-			wake_up(&mle->wq);
-		}
-		spin_unlock(&mle->spinlock);
-		break;
+			break;
+		case DLM_MASTER_RESP_ERROR:
+			dlmprintk("node %u hit an -ENOMEM!  try this "
+				  "whole thing again\n", 
+				  resp->node_idx);
+			mle->error = 1;
+			wake = 1;
+			break;
+		default:
+			dlmprintk("bad response! %u\n", resp->response);
+			break;
 	}
+	spin_unlock(&mle->spinlock);
+
+leave:
 	spin_unlock(&dlm->master_lock);
 
-	if (found)
+	if (wake) {		
+		atomic_set(&mle->woken, 1);
+		wake_up(&mle->wq);
+	}
+
+	if (mle)
 		dlm_put_mle(mle);
 	else
 		dlmprintk0("hrrm... got a master resp but found no matching "
@@ -897,8 +895,6 @@
 	dlm_master_list_entry *mle = NULL;
 	dlm_assert_master *assert = (dlm_assert_master *)msg->buf;
 	dlm_lock_resource *res;
-	int bit;
-	struct list_head *iter;
 	char *name;
 	unsigned int namelen;
 
@@ -918,37 +914,26 @@
 
 	/* find the MLE */
 	spin_lock(&dlm->master_lock);
-	list_for_each(iter, &dlm->master_list) {
-		mle = list_entry(iter, dlm_master_list_entry, list);
-		if (dlm_mle_equal(dlm, mle, name, namelen)) {
-			dlm_get_mle(mle);
-			break;
+	if (!dlm_find_mle(dlm, &mle, name, namelen)) {
+		dlmprintk("just got an assert_master from %u, but no "
+			  "MLE for it!\n", assert->node_idx);
+	} else {
+		int bit = find_next_bit (mle->maybe_map, NM_MAX_NODES, 0);
+		if (bit >= NM_MAX_NODES) {
+			dlmprintk("EEK! no bits set in the maybe_map, but %u "
+				  "is asserting!\n", assert->node_idx);
+			BUG();
+		} else if (bit != assert->node_idx) {
+			/* TODO: is this ok?  */
+			dlmprintk("EEK! expected %u to be the master, but %u "
+				  "is asserting!\n", bit, assert->node_idx);
+			BUG();
 		}
-		mle = NULL;
 	}
-	if (!mle) {
-		dlmprintk("EEEEEEK!  just got an assert_master from %u, but no "
-			  "MLE for it!\n",
-		       assert->node_idx);
-		spin_unlock(&dlm->master_lock);
-		goto check_lockres;
-	}
-	bit = find_next_bit (mle->maybe_map, NM_MAX_NODES, 0);
-	if (bit >= NM_MAX_NODES) {
-		dlmprintk("EEK! no bits set in the maybe_map, but %u is "
-			  "asserting!\n", assert->node_idx);
-		BUG();
-	} else if (bit != assert->node_idx) {
-		/* TODO: is this ok?  */
-		dlmprintk("EEK! expected %u to be the master, but %u is "
-			  "asserting!\n", bit, assert->node_idx);
-		BUG();
-	}
 	spin_unlock(&dlm->master_lock);
 
 	/* ok everything checks out with the MLE
 	 * now check to see if there is a lockres */
-check_lockres:
 	res = __dlm_lookup_lock(dlm, name, namelen);
 	if (res) {
 		spin_lock(&res->spinlock);



More information about the Ocfs2-commits mailing list