[Ocfs2-commits] zab commits r2546 - branches/locking-changes/fs/ocfs2

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Thu Aug 25 17:05:55 CDT 2005


Author: zab
Date: 2005-08-25 17:05:53 -0500 (Thu, 25 Aug 2005)
New Revision: 2546

Modified:
   branches/locking-changes/fs/ocfs2/dlmglue.c
   branches/locking-changes/fs/ocfs2/dlmglue.h
   branches/locking-changes/fs/ocfs2/journal.c
   branches/locking-changes/fs/ocfs2/ocfs2.h
Log:
o get rid of the callback interface from dlmglue now that ocfs2 aio isn't
  using it


Modified: branches/locking-changes/fs/ocfs2/dlmglue.c
===================================================================
--- branches/locking-changes/fs/ocfs2/dlmglue.c	2005-08-25 21:24:37 UTC (rev 2545)
+++ branches/locking-changes/fs/ocfs2/dlmglue.c	2005-08-25 22:05:53 UTC (rev 2546)
@@ -54,6 +54,14 @@
 
 #include "buffer_head_io.h"
 
+struct ocfs2_mask_waiter {
+	struct list_head	mw_item;
+	int			mw_status;
+	struct completion	mw_complete;
+	unsigned long		mw_mask;
+	unsigned long		mw_goal;
+};
+
 static void ocfs2_inode_ast_func(void *opaque);
 static void ocfs2_inode_bast_func(void *opaque,
 				  int level);
@@ -159,9 +167,7 @@
 static int ocfs2_cluster_lock(ocfs2_super *osb,
 			      struct ocfs2_lock_res *lockres,
 			      int level,
-			      int lkm_flags,
-			      ocfs2_lock_callback cb,
-			      unsigned long cb_data);
+			      int lkm_flags);
 static void ocfs2_cluster_unlock(ocfs2_super *osb,
 				 struct ocfs2_lock_res *lockres,
 				 int level);
@@ -314,7 +320,7 @@
 	spin_lock_init(&res->l_lock);
 	init_waitqueue_head(&res->l_event);
 	INIT_LIST_HEAD(&res->l_blocked_list);
-	INIT_LIST_HEAD(&res->l_flag_cb_list);
+	INIT_LIST_HEAD(&res->l_mask_waiters);
 }
 
 void ocfs2_inode_lock_res_init(struct ocfs2_lock_res *res,
@@ -366,8 +372,8 @@
 	mlog_bug_on_msg(!list_empty(&res->l_blocked_list),
 			"Lockres %s is on the blocked list\n",
 			res->l_name);
-	mlog_bug_on_msg(!list_empty(&res->l_flag_cb_list),
-			"Lockres %s has flag callbacks pending\n",
+	mlog_bug_on_msg(!list_empty(&res->l_mask_waiters),
+			"Lockres %s has mask waiters pending\n",
 			res->l_name);
 	mlog_bug_on_msg(spin_is_locked(&res->l_lock),
 			"Lockres %s is locked\n",
@@ -444,35 +450,32 @@
 	return new_level;
 }
 
-/* XXX must be called with lockres->l_lock held */
-static void lockres_set_flags(struct ocfs2_lock_res *lockres, unsigned long newflags)
+static void lockres_set_flags(struct ocfs2_lock_res *lockres,
+			      unsigned long newflags)
 {
 	struct list_head *pos, *tmp;
-	struct ocfs2_lockres_flag_callback *fcb;
+	struct ocfs2_mask_waiter *mw;
 
-	assert_spin_locked(&lockres->l_lock);
+ 	assert_spin_locked(&lockres->l_lock);
 
 	lockres->l_flags = newflags;
 
-	list_for_each_safe(pos, tmp, &lockres->l_flag_cb_list) {
-		fcb = list_entry(pos, struct ocfs2_lockres_flag_callback,
-				 fc_lockres_item);
-		if ((lockres->l_flags & fcb->fc_flag_mask) !=
-		    fcb->fc_flag_goal)
+	list_for_each_safe(pos, tmp, &lockres->l_mask_waiters) {
+		mw = list_entry(pos, struct ocfs2_mask_waiter, mw_item);
+		if ((lockres->l_flags & mw->mw_mask) != mw->mw_goal)
 			continue;
 
-		list_del_init(&fcb->fc_lockres_item);
-		fcb->fc_cb(0, fcb->fc_data);
-		if (fcb->fc_free_once_called)
-			kfree(fcb);
+		list_del_init(&mw->mw_item);
+		mw->mw_status = 0;
+		complete(&mw->mw_complete);
 	}
 }
-
 static void lockres_or_flags(struct ocfs2_lock_res *lockres, unsigned long or)
 {
 	lockres_set_flags(lockres, lockres->l_flags | or);
 }
-static void lockres_clear_flags(struct ocfs2_lock_res *lockres, unsigned long clear)
+static void lockres_clear_flags(struct ocfs2_lock_res *lockres,
+				unsigned long clear)
 {
 	lockres_set_flags(lockres, lockres->l_flags & ~clear);
 }
@@ -860,20 +863,6 @@
 		   !ocfs2_check_wait_flag(lockres, OCFS2_LOCK_REFRESHING));
 }
 
-static void lockres_add_flag_callback(struct ocfs2_lock_res *lockres,
-				      struct ocfs2_lockres_flag_callback *fcb,
-				      unsigned long mask, unsigned long goal)
-{
-	BUG_ON(!list_empty(&fcb->fc_lockres_item));
-	BUG_ON(fcb->fc_cb == NULL);
-
-	assert_spin_locked(&lockres->l_lock);
-
-	list_add_tail(&fcb->fc_lockres_item, &lockres->l_flag_cb_list);
-	fcb->fc_flag_mask = mask;
-	fcb->fc_flag_goal = goal;
-}
-
 /* predict what lock level we'll be dropping down to on behalf
  * of another node, and return true if the currently wanted
  * level will be compatible with it. */
@@ -885,88 +874,51 @@
 	return wanted <= ocfs2_highest_compat_lock_level(lockres->l_blocking);
 }
 
-/* these are generic and could be used elsewhere */
-struct ocfs2_status_completion {
-	int			sc_status;
-	struct completion	sc_complete;
-};
-
-static void ocfs2_status_completion_cb(int rc, unsigned long data)
+static void ocfs2_init_mask_waiter(struct ocfs2_mask_waiter *mw)
 {
-	struct ocfs2_status_completion *sc;
-
-	sc = (struct ocfs2_status_completion *)data;
-	sc->sc_status = rc;
-	complete(&sc->sc_complete);
+	INIT_LIST_HEAD(&mw->mw_item);
+	init_completion(&mw->mw_complete);
 }
 
-static int ocfs2_wait_for_status_completion(struct ocfs2_status_completion *sc)
+static int ocfs2_wait_for_mask(struct ocfs2_mask_waiter *mw)
 {
-	wait_for_completion(&sc->sc_complete);
+	wait_for_completion(&mw->mw_complete);
 	/* Re-arm the completion in case we want to wait on it again */
-	INIT_COMPLETION(sc->sc_complete);
-	return sc->sc_status;
+	INIT_COMPLETION(mw->mw_complete);
+	return mw->mw_status;
 }
 
-static void ocfs2_init_fcb(struct ocfs2_lockres_flag_callback *fcb,
-			   ocfs2_lock_callback cb,
-			   unsigned long cb_data,
-			   int stack_allocated)
+static void lockres_add_mask_waiter(struct ocfs2_lock_res *lockres,
+				    struct ocfs2_mask_waiter *mw,
+				    unsigned long mask,
+				    unsigned long goal)
 {
-	fcb->fc_cb = cb;
-	fcb->fc_data = cb_data;
-	fcb->fc_free_once_called = !stack_allocated;
-	INIT_LIST_HEAD(&fcb->fc_lockres_item);
-}
+	BUG_ON(!list_empty(&mw->mw_item));
 
-/* Init a stack allocated FCB and an ocfs2_status_completion together. */
-static void ocfs2_init_completion_fcb(struct ocfs2_lockres_flag_callback *fcb,
-				      struct ocfs2_status_completion *sc)
-{
-	init_completion(&sc->sc_complete);
-	ocfs2_init_fcb(fcb, ocfs2_status_completion_cb, (unsigned long) sc, 1);
+	assert_spin_locked(&lockres->l_lock);
+
+	list_add_tail(&mw->mw_item, &lockres->l_mask_waiters);
+	mw->mw_mask = mask;
+	mw->mw_goal = goal;
 }
 
 static int ocfs2_cluster_lock(ocfs2_super *osb,
 			      struct ocfs2_lock_res *lockres,
 			      int level,
-			      int lkm_flags,
-			      ocfs2_lock_callback cb,
-			      unsigned long cb_data)
+			      int lkm_flags)
 {
-	struct ocfs2_lockres_flag_callback sync_fcb, *fcb;
-	struct ocfs2_status_completion sc;
+	struct ocfs2_mask_waiter mw;
 	enum dlm_status status;
-	int ret;
-	int catch_signals = 1;
-	int sync = 1;
+	int wait, catch_signals = 1;
+	int ret = 0; /* gcc doesn't realize wait = 1 guarantees ret is set */
 
 	mlog_entry_void();
 
-	if (cb != NULL) {
-		fcb = kmalloc(sizeof(*fcb), GFP_NOFS);
-		if (fcb == NULL) {
-			ret = -ENOMEM;
-			goto out;
-		}
+	ocfs2_init_mask_waiter(&mw);
 
-		ocfs2_init_fcb(fcb, cb, cb_data, 0);
-
-		/* A callback passed in means we'll assume async
-		 * behavior - no waiting on dlm operations will be
-		 * done here and the allocated fcb will call the
-		 * callback when done. */
-		sync = 0;
-	} else {
-		/* No callback passed which means the caller wants
-		 * synchronous behavior - we avoid kmalloc and use a
-		 * stack allocated fcb for this. The status completion
-		 * helpers defined above come in handy here. */
-		fcb = &sync_fcb;
-		ocfs2_init_completion_fcb(fcb, &sc);
-	}
-
 again:
+	wait = 0;
+
 	if (catch_signals && signal_pending(current)) {
 		ret = -ERESTARTSYS;
 		goto out;
@@ -975,8 +927,8 @@
 	spin_lock(&lockres->l_lock);
 
 	mlog_bug_on_msg(lockres->l_flags & OCFS2_LOCK_FREEING,
-			"Cluster lock called on freeing lockres %s! flags 0x%lx\n",
-			lockres->l_name, lockres->l_flags);
+			"Cluster lock called on freeing lockres %s! flags "
+			"0x%lx\n", lockres->l_name, lockres->l_flags);
 
 	/* We only compare against the currently granted level
 	 * here. If the lock is blocked waiting on a downconvert,
@@ -985,8 +937,8 @@
 	    level > lockres->l_level) {
 		/* is someone sitting in dlm_lock? If so, wait on
 		 * them. */
-		lockres_add_flag_callback(lockres, fcb, OCFS2_LOCK_BUSY, 0);
-		ret = -EIOCBRETRY;
+		lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BUSY, 0);
+		wait = 1;
 		goto unlock;
 	}
 
@@ -1006,8 +958,8 @@
 	    !ocfs2_may_continue_on_blocked_lock(lockres, level)) {
 		/* is the lock is currently blocked on behalf of
 		 * another node */
-		lockres_add_flag_callback(lockres, fcb, OCFS2_LOCK_BLOCKED, 0);
-		ret = -EIOCBRETRY;
+		lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_BLOCKED, 0);
+		wait = 1;
 		goto unlock;
 	}
 
@@ -1067,24 +1019,13 @@
 unlock:
 	spin_unlock(&lockres->l_lock);
 out:
-	/* Non-async callers will always wait here for dlm operations
-	 * to complete. We must be careful to re-initialize the
-	 * completion before looping back. */
-	if (ret == -EIOCBRETRY && sync) {
-		ret = ocfs2_wait_for_status_completion(&sc);
+	if (wait) {
+		ret = ocfs2_wait_for_mask(&mw);
 		if (ret == 0)
 			goto again;
 		mlog_errno(ret);
 	}
 
-	/* Only free the async fcb on error. */
-	if (ret && ret != -EIOCBRETRY && !sync) {
-		mlog_bug_on_msg(!list_empty(&fcb->fc_lockres_item),
-				"Lockres %s, freeing flag callback in use\n",
-				lockres->l_name);
-		kfree(fcb);
-	}
-
 	mlog_exit(ret);
 	return ret;
 }
@@ -1178,8 +1119,7 @@
 
 	level = write ? LKM_EXMODE : LKM_PRMODE;
 
-	status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, level, 0,
-				    NULL, 0);
+	status = ocfs2_cluster_lock(OCFS2_SB(inode->i_sb), lockres, level, 0);
 	if (status < 0)
 		mlog_errno(status);
 
@@ -1592,9 +1532,7 @@
 			 ocfs2_journal_handle *handle,
 			 struct buffer_head **ret_bh,
 			 int ex,
-			 int flags,
-			 ocfs2_lock_callback cb,
-			 unsigned long cb_data)
+			 int flags)
 {
 	int status, level, dlm_flags, acquired;
 	struct ocfs2_lock_res *lockres;
@@ -1627,8 +1565,7 @@
 	if (flags & OCFS2_META_LOCK_NOQUEUE)
 		dlm_flags |= LKM_NOQUEUE;
 
-	status = ocfs2_cluster_lock(osb, lockres, level, dlm_flags, cb,
-				    cb_data);
+	status = ocfs2_cluster_lock(osb, lockres, level, dlm_flags);
 	if (status < 0) {
 		if (status != -EAGAIN && status != -EIOCBRETRY)
 			mlog_errno(status);
@@ -1718,7 +1655,7 @@
 
 	mlog_entry_void();
 
-	status = ocfs2_cluster_lock(osb, lockres, level, 0, NULL, 0);
+	status = ocfs2_cluster_lock(osb, lockres, level, 0);
 	if (status < 0) {
 		mlog_errno(status);
 		goto bail;
@@ -1764,7 +1701,7 @@
 	int status;
 	struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres;
 
-	status = ocfs2_cluster_lock(osb, lockres, LKM_EXMODE, 0, NULL, 0);
+	status = ocfs2_cluster_lock(osb, lockres, LKM_EXMODE, 0);
 	if (status < 0)
 		mlog_errno(status);
 
@@ -2005,20 +1942,19 @@
 void ocfs2_mark_lockres_freeing(struct ocfs2_lock_res *lockres)
 {
 	int status;
-	struct ocfs2_status_completion sc;
-	struct ocfs2_lockres_flag_callback fcb;
+	struct ocfs2_mask_waiter mw;
 
-	ocfs2_init_completion_fcb(&fcb, &sc);
+	ocfs2_init_mask_waiter(&mw);
 
 	spin_lock(&lockres->l_lock);
 	lockres->l_flags |= OCFS2_LOCK_FREEING;
 	while (lockres->l_flags & OCFS2_LOCK_QUEUED) {
-		lockres_add_flag_callback(lockres, &fcb, OCFS2_LOCK_QUEUED, 0);
+		lockres_add_mask_waiter(lockres, &mw, OCFS2_LOCK_QUEUED, 0);
 		spin_unlock(&lockres->l_lock);
 
 		mlog(0, "Waiting on lockres %s\n", lockres->l_name);
 
-		status = ocfs2_wait_for_status_completion(&sc);
+		status = ocfs2_wait_for_mask(&mw);
 		if (status)
 			mlog_errno(status);
 

Modified: branches/locking-changes/fs/ocfs2/dlmglue.h
===================================================================
--- branches/locking-changes/fs/ocfs2/dlmglue.h	2005-08-25 21:24:37 UTC (rev 2545)
+++ branches/locking-changes/fs/ocfs2/dlmglue.h	2005-08-25 22:05:53 UTC (rev 2546)
@@ -99,12 +99,10 @@
 			 ocfs2_journal_handle *handle,
 			 struct buffer_head **ret_bh,
 			 int ex,
-			 int flags,
-			 ocfs2_lock_callback cb,
-			 unsigned long cb_data);
+			 int flags);
 /* 99% of the time we don't want to supply any additional flags --
  * those are for very specific cases only. */
-#define ocfs2_meta_lock(i, h, b, e) ocfs2_meta_lock_full(i, h, b, e, 0, NULL, 0)
+#define ocfs2_meta_lock(i, h, b, e) ocfs2_meta_lock_full(i, h, b, e, 0)
 void ocfs2_meta_unlock(struct inode *inode,
 		       int ex);
 int ocfs2_super_lock(ocfs2_super *osb,

Modified: branches/locking-changes/fs/ocfs2/journal.c
===================================================================
--- branches/locking-changes/fs/ocfs2/journal.c	2005-08-25 21:24:37 UTC (rev 2545)
+++ branches/locking-changes/fs/ocfs2/journal.c	2005-08-25 22:05:53 UTC (rev 2546)
@@ -1100,7 +1100,7 @@
 	SET_INODE_JOURNAL(inode);
 
 	status = ocfs2_meta_lock_full(inode, NULL, &bh, 1,
-				      OCFS2_META_LOCK_RECOVERY, NULL, 0);
+				      OCFS2_META_LOCK_RECOVERY);
 	if (status < 0) {
 		mlog(0, "status returned from ocfs2_meta_lock=%d\n", status);
 		if (status != -ERESTARTSYS)
@@ -1289,7 +1289,7 @@
 	SET_INODE_JOURNAL(inode);
 
 	flags = OCFS2_META_LOCK_RECOVERY | OCFS2_META_LOCK_NOQUEUE;
-	status = ocfs2_meta_lock_full(inode, NULL, NULL, 1, flags, NULL, 0);
+	status = ocfs2_meta_lock_full(inode, NULL, NULL, 1, flags);
 	if (status < 0) {
 		if (status != -EAGAIN)
 			mlog_errno(status);

Modified: branches/locking-changes/fs/ocfs2/ocfs2.h
===================================================================
--- branches/locking-changes/fs/ocfs2/ocfs2.h	2005-08-25 21:24:37 UTC (rev 2545)
+++ branches/locking-changes/fs/ocfs2/ocfs2.h	2005-08-25 22:05:53 UTC (rev 2546)
@@ -108,24 +108,13 @@
 
 typedef void (*ocfs2_lock_callback)(int status, unsigned long data);
 
-struct ocfs2_lockres_flag_callback {
-	struct list_head	fc_lockres_item;
-	unsigned		fc_free_once_called:1;
-
-	unsigned long		fc_flag_mask;
-	unsigned long		fc_flag_goal;
-
-	ocfs2_lock_callback	fc_cb;
-	unsigned long		fc_data;
-};
-
 struct ocfs2_lock_res {
 	void                    *l_priv;
 	struct ocfs2_lock_res_ops *l_ops;
 	spinlock_t               l_lock;
 
 	struct list_head         l_blocked_list;
-	struct list_head         l_flag_cb_list;
+	struct list_head         l_mask_waiters;
 
 	enum ocfs2_lock_type     l_type;
 	unsigned long		 l_flags;



More information about the Ocfs2-commits mailing list