[Ocfs2-commits] khackel commits r2653 - trunk/fs/ocfs2/dlm

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Fri Oct 14 19:38:48 CDT 2005


Author: khackel
Signed-off-by: mfasheh
Date: 2005-10-14 19:38:47 -0500 (Fri, 14 Oct 2005)
New Revision: 2653

Modified:
   trunk/fs/ocfs2/dlm/dlmmaster.c
Log:
* simplify the deallocation paths in dlm_get_lock_resource to make the next
  few patches easier to apply and reduce complexity

Signed-off-by: mfasheh


Modified: trunk/fs/ocfs2/dlm/dlmmaster.c
===================================================================
--- trunk/fs/ocfs2/dlm/dlmmaster.c	2005-10-14 18:21:51 UTC (rev 2652)
+++ trunk/fs/ocfs2/dlm/dlmmaster.c	2005-10-15 00:38:47 UTC (rev 2653)
@@ -658,7 +658,8 @@
 					  int flags)
 {
 	struct dlm_lock_resource *tmpres=NULL, *res=NULL;
-	struct dlm_master_list_entry *mle = NULL, *tmpmle = NULL;
+	struct dlm_master_list_entry *mle = NULL;
+	struct dlm_master_list_entry *alloc_mle = NULL;
 	int blocked = 0;
 	int ret, nodenum;
 	struct dlm_node_iter iter;
@@ -676,26 +677,23 @@
 	if (tmpres) {
 		spin_unlock(&dlm->spinlock);
 		mlog(0, "found in hash!\n");
-		if (mle)
-			kmem_cache_free(dlm_mle_cache, mle);
 		if (res)
 			dlm_lockres_put(res);
-		return tmpres;
+		res = tmpres;
+		goto leave;
 	}
 
 	if (!res) {
 		spin_unlock(&dlm->spinlock);
 		mlog(0, "allocating a new resource\n");
 		/* nothing found and we need to allocate one. */
-		mle = (struct dlm_master_list_entry *)kmem_cache_alloc(dlm_mle_cache,
-								GFP_KERNEL);
-		if (!mle)
-			return NULL;
+		alloc_mle = (struct dlm_master_list_entry *)
+			kmem_cache_alloc(dlm_mle_cache, GFP_KERNEL);
+		if (!alloc_mle)
+			goto leave;
 		res = dlm_new_lockres(dlm, lockid, namelen);
-		if (!res) {
-			kmem_cache_free(dlm_mle_cache, mle);
-			return NULL;
-		}
+		if (!res)
+			goto leave;
 		goto lookup;
 	}
 
@@ -710,8 +708,6 @@
 		spin_unlock(&res->spinlock);
 		spin_unlock(&dlm->spinlock);
 		/* lockres still marked IN_PROGRESS */
-		/* need to free the unused mle */
-		kmem_cache_free(dlm_mle_cache, mle);
 		goto wake_waiters;
 	}
 
@@ -719,12 +715,12 @@
 	spin_lock(&dlm->master_lock);
 
 	/* if we found a block, wait for lock to be mastered by another node */
-	blocked = dlm_find_mle(dlm, &tmpmle, (char *)lockid, namelen);
+	blocked = dlm_find_mle(dlm, &mle, (char *)lockid, namelen);
 	if (blocked) {
-		if (tmpmle->type == DLM_MLE_MASTER) {
+		if (mle->type == DLM_MLE_MASTER) {
 			mlog(ML_ERROR, "master entry for nonexistent lock!\n");
 			BUG();
-		} else if (tmpmle->type == DLM_MLE_MIGRATION) {
+		} else if (mle->type == DLM_MLE_MIGRATION) {
 			/* migration is in progress! */
 			/* the good news is that we now know the
 			 * "current" master (mle->master). */
@@ -734,22 +730,22 @@
 
 			/* set the lockres owner and hash it */
 			spin_lock(&res->spinlock);
-			dlm_set_lockres_owner(dlm, res, tmpmle->master);
+			dlm_set_lockres_owner(dlm, res, mle->master);
 			__dlm_insert_lockres(dlm, res);
 			spin_unlock(&res->spinlock);
 			spin_unlock(&dlm->spinlock);
 
 			/* master is known, detach */
-			dlm_mle_detach_hb_events(dlm, tmpmle);
-			dlm_put_mle(tmpmle);
-
-			/* need to free the unused mle */
-			kmem_cache_free(dlm_mle_cache, mle);
+			dlm_mle_detach_hb_events(dlm, mle);
+			dlm_put_mle(mle);
+			mle = NULL;
 			goto wake_waiters;
 		}
-	}
-	if (!blocked) {
+	} else {
 		/* go ahead and try to master lock on this node */
+		mle = alloc_mle;
+		/* make sure this does not get freed below */
+		alloc_mle = NULL;
 		dlm_init_mle(mle, DLM_MLE_MASTER, dlm, res, NULL, 0);
 		list_add(&mle->list, &dlm->master_list);
 	}
@@ -764,12 +760,9 @@
 	spin_unlock(&dlm->master_lock);
 	spin_unlock(&dlm->spinlock);
 
-	if (blocked) {
-		/* must wait for lock to be mastered elsewhere */
-		kmem_cache_free(dlm_mle_cache, mle);
-		mle = tmpmle;
+	/* must wait for lock to be mastered elsewhere */
+	if (blocked)
 		goto wait;
-	}
 
 redo_request:
 	ret = -EINVAL;
@@ -817,6 +810,11 @@
 	spin_unlock(&res->spinlock);
 	wake_up(&res->wq);
 
+leave:
+	/* need to free the unused mle */
+	if (alloc_mle)
+		kmem_cache_free(dlm_mle_cache, alloc_mle);
+
 	return res;
 }
 



More information about the Ocfs2-commits mailing list