[Ocfs2-commits] khackel commits r1759 - trunk/cluster

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Wed Jan 12 13:45:35 CST 2005


Author: khackel
Date: 2005-01-12 13:45:33 -0600 (Wed, 12 Jan 2005)
New Revision: 1759

Modified:
   trunk/cluster/dlmmod.c
Log:
* fix lockres spinlock unlocking in dlmlock_local path
* fix the kmalloc that was occurring under a spinlock in this path



Modified: trunk/cluster/dlmmod.c
===================================================================
--- trunk/cluster/dlmmod.c	2005-01-12 19:23:12 UTC (rev 1758)
+++ trunk/cluster/dlmmod.c	2005-01-12 19:45:33 UTC (rev 1759)
@@ -91,6 +91,26 @@
 void __dlm_wait_on_lockres(dlm_lock_resource *res);
 
 
+
+/* fetch next node-local (u8 nodenum + u56 cookie) into u64 */
+static inline void dlm_get_next_cookie(u16 node_num, u64 *cookie)
+{
+	/* why did I make node_num 16 bit to begin with? */
+	u64 tmpnode = (u8)(node_num & (u16)0x00ff);
+
+	/* shift single byte of node num into top 8 bits */
+	tmpnode <<= 56;
+
+	spin_lock(&dlm_cookie_lock);
+	*cookie = (dlm_next_cookie & tmpnode);
+	if (++dlm_next_cookie & 0xff00000000000000ull) {
+		dlmprintk0("eek! this node's cookie will now wrap!\n");
+		dlm_next_cookie = 1;
+	}
+	spin_unlock(&dlm_cookie_lock);
+}
+
+
 /* ----------------------------------------------------------------- */
 
 extern spinlock_t dlm_master_lock;
@@ -221,11 +241,18 @@
 		if (q.len > DLM_LOCKID_NAME_MAX)
 			goto error;
 
+		/* take care of all allocs before any locking */
 		status = DLM_SYSERR;
 		buf = kmalloc(q.len+1, GFP_KERNEL);
 		if (!buf)
 			goto error;
 
+		lock = kmalloc(sizeof(dlm_lock), GFP_KERNEL);
+		if (!lock)
+			goto error;
+
+		lksb->lockid = lock;
+
 		memcpy(buf, name, q.len);
 		buf[q.len] = 0;
 		q.name = buf;
@@ -254,7 +281,10 @@
 error:
 	if (buf)
 		kfree(buf);
-	lksb->lockid = NULL;
+	if (lock && !convert) {
+		kfree(lock);
+		lksb->lockid = NULL;
+	}
 
 error_status:
 	// this is kind of unnecessary
@@ -267,16 +297,13 @@
 		      int type, dlm_astlockfunc_t *ast, dlm_bastlockfunc_t *bast, void *data)
 {
 	dlm_lock *tmplock;
-       	dlm_status status;
-	u8 *c;
 
 	dlmprintk("type=%d\n", type);
 
-	status = DLM_SYSERR;
-	tmplock = kmalloc(sizeof(dlm_lock), GFP_KERNEL);
-	if (!tmplock)
-		goto error;
+	tmplock = lksb->lockid;
 
+	DLM_ASSERT(tmplock);
+
 	memset(tmplock, 0, sizeof(dlm_lock));
 	INIT_LIST_HEAD(&tmplock->list);
 	INIT_LIST_HEAD(&tmplock->ast_list);
@@ -292,37 +319,19 @@
 	tmplock->astdata = data;
 	tmplock->lksb = lksb;
 
-	lksb->lockid = tmplock;
+	dlm_get_next_cookie(tmplock->node, &tmplock->cookie);
 
-	c = (u8 *)(&tmplock->cookie);
-
-	spin_lock(&dlm_cookie_lock);
-	tmplock->cookie = dlm_next_cookie;
-	dlm_next_cookie++;
-	if (dlm_next_cookie & 0xff00000000000000ull) {
-		dlmprintk0("eek! this node's cookie will now wrap!\n");
-		dlm_next_cookie = 1;
-	}
-	c[7] = (u8)(tmplock->node & 0x00ff);
-	spin_unlock(&dlm_cookie_lock);
-
 	if (res->owner == dlm->group_index)
-		status = dlmlock_local(dlm, res, tmplock, flags);
+		return dlmlock_local(dlm, res, tmplock, flags);
 	else 
-		status = dlmlock_remote(dlm, res, tmplock, flags);
-error:
-	if (status != DLM_NORMAL) {
-		if (tmplock)
-			kfree(tmplock);
-		lksb->lockid = NULL;
-	}
-	return status;
+		return dlmlock_remote(dlm, res, tmplock, flags);
 }
 
 
 
 
-/* must be already holding lockres->spinlock */
+/* caller must be already holding lockres->spinlock 
+ * will return with lockres->spinlock UNLOCKED */
 dlm_status dlmlock_local(dlm_ctxt *dlm, dlm_lock_resource *res, dlm_lock *lock, int flags)
 {
 	struct list_head *iter;
@@ -1657,7 +1666,6 @@
 		spin_lock(&res->spinlock);
 		newlock->lockres = res;
 		status = dlmlock_local(dlm, res, newlock, create->flags);
-		spin_unlock(&res->spinlock);
 
 		if (create->flags & LKM_NOQUEUE &&
 		    status == DLM_NOTQUEUED) {



More information about the Ocfs2-commits mailing list