[Ocfs2-commits] zab commits r1883 - in trunk: . fs/ocfs2/cluster fs/ocfs2/dlm kapi-compat/include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue Feb 1 19:47:27 CST 2005


Author: zab
Date: 2005-02-01 19:47:26 -0600 (Tue, 01 Feb 2005)
New Revision: 1883

Added:
   trunk/kapi-compat/include/wait_event_interruptible_timeout.h
Modified:
   trunk/configure.in
   trunk/fs/ocfs2/cluster/tcp.c
   trunk/fs/ocfs2/cluster/util.c
   trunk/fs/ocfs2/cluster/util.h
   trunk/fs/ocfs2/dlm/dlmmaster.c
   trunk/fs/ocfs2/dlm/dlmrecovery.c
   trunk/fs/ocfs2/dlm/util.c
   trunk/fs/ocfs2/dlm/util.h
Log:
o use wait_event_interruptible_timeout instead of our util_wait_atomic_eq()
o provide a w_e_i_t for kernels that don't have it


Modified: trunk/configure.in
===================================================================
--- trunk/configure.in	2005-02-02 01:27:56 UTC (rev 1882)
+++ trunk/configure.in	2005-02-02 01:47:26 UTC (rev 1883)
@@ -302,6 +302,14 @@
   AC_MSG_RESULT(no)
 fi
 
+AC_MSG_CHECKING([for wait_event_interruptible_timeout])
+if grep "\<wait_event_interruptible_timeout(" "$KERNELINC/linux/wait.h" >/dev/null 2>&1 ; then
+  AC_MSG_RESULT(yes)
+else
+  KAPI_COMPAT_HEADERS="$KAPI_COMPAT_HEADERS wait_event_interruptible_timeout.h"
+  AC_MSG_RESULT(no)
+fi
+
 # using -include has two advantages:
 #  the source doesn't need to know to include compat headers
 #  the compat header file names don't go through the search path

Modified: trunk/fs/ocfs2/cluster/tcp.c
===================================================================
--- trunk/fs/ocfs2/cluster/tcp.c	2005-02-02 01:27:56 UTC (rev 1882)
+++ trunk/fs/ocfs2/cluster/tcp.c	2005-02-02 01:47:26 UTC (rev 1883)
@@ -698,7 +698,8 @@
 	if (status) {
 		if (ret >= 0) {
 			/* wait on other node's handler */
-			tmpret = util_wait_atomic_eq(&nsc.wq, &nsc.woken, 1, 0);
+			tmpret = wait_event_interruptible(nsc.wq,
+					(atomic_read(&nsc.woken) == 1));
 			if (tmpret==0) {
 				*status = nsc.status;
 				netprintk("status return requested, status is %d\n", *status);

Modified: trunk/fs/ocfs2/cluster/util.c
===================================================================
--- trunk/fs/ocfs2/cluster/util.c	2005-02-02 01:27:56 UTC (rev 1882)
+++ trunk/fs/ocfs2/cluster/util.c	2005-02-02 01:47:26 UTC (rev 1883)
@@ -36,8 +36,6 @@
 
 #include "util.h"
 
-static void util_timeout_func(unsigned long data);
-
 /* block all but 'mask' sigs, optionally saving off our previous
  * signal state. */
 void util_block_sigs(sigset_t *oldsigs, unsigned long mask)
@@ -111,28 +109,6 @@
 }				/* util_daemonize */
 #endif
 
-/*
- * util_sleep()
- *
- * The interval time is in milliseconds
- *
- * This function needs to be removed.
- * Instead call schedule_timeout() directly and handle signals.
- */
-int util_sleep (__u32 ms)
-{
-	__u32 numJiffies;
-
-	/* 10ms = 1 jiffy, minimum resolution is one jiffy */
-	numJiffies = ms * HZ / 1000;
-	numJiffies = (numJiffies < 1) ? 1 : numJiffies;
-
-	set_current_state (TASK_INTERRUPTIBLE);
-	numJiffies = schedule_timeout (numJiffies);
-
-	return 0;
-}				/* util_sleep */
-
 /* prefetch has been declared to allow to build in debug mode */
 #ifdef DEBUG
 #ifndef ARCH_HAS_PREFETCH
@@ -142,88 +118,6 @@
 #endif
 #endif
 
-
-static void util_timeout_func(unsigned long data)
-{
-	util_timeout *to = (util_timeout *)data; 
-
-	to->timed_out = 1;
-	wake_up(&to->wait);
-}
-
-void util_init_timeout(util_timeout *to)
-{
-	init_timer(&to->timer);
-	to->timer.data = (unsigned long)to;
-	to->timer.function = util_timeout_func;
-	to->timed_out = 0;
-	init_waitqueue_head(&to->wait);
-}
-
-void util_set_timeout(util_timeout *to, __u32 timeout)
-{
-	__u32 how_long;
-
-	if (!timeout) {
-		to->timed_out = 1;
-		return ;
-	}
-
-	how_long = (timeout * HZ / 1000);
-	if (how_long < 1)
-		how_long = 1;
-
-	to->timer.expires = jiffies + how_long;
-	add_timer(&to->timer);
-}
-
-void util_clear_timeout(util_timeout *to)
-{
-	del_timer_sync(&to->timer);
-}
-
-int __util_wait_atomic_eq(wait_queue_head_t *wq, atomic_t *var, int val, int ms)
-{
-	int ret;
-	util_timeout timeout;
-	DECLARE_WAITQUEUE(wait, current);
-	DECLARE_WAITQUEUE(to_wait, current);
-
-	util_init_timeout(&timeout);
-
-	if (ms) {
-		util_set_timeout(&timeout, ms);
-		if (timeout.timed_out) {
-			util_clear_timeout(&timeout);
-		}
-	}
-	add_wait_queue(wq, &wait);
-	add_wait_queue(&timeout.wait, &to_wait);
-	do { 
-		ret = 0;
-		set_current_state(TASK_INTERRUPTIBLE);
-		if (atomic_read(var)==val)
-			break;
-		ret = -ETIMEDOUT;
-		if (timeout.timed_out)
-			break;
-		schedule();
-		if (signal_pending(current)) {
-			ret = -EINTR;
-			break;
-		}
-	} while (1);
-	
-	set_current_state(TASK_RUNNING);
-	remove_wait_queue(wq, &wait);
-	remove_wait_queue(&timeout.wait, &to_wait);
-
-	if (ms)
-		util_clear_timeout(&timeout);
-
-	return ret;
-}
-
 /* resizable (using chained pages) array stuff */
 void util_init_rarray(util_rarray *arr, u16 elem_size)
 {

Modified: trunk/fs/ocfs2/cluster/util.h
===================================================================
--- trunk/fs/ocfs2/cluster/util.h	2005-02-02 01:27:56 UTC (rev 1882)
+++ trunk/fs/ocfs2/cluster/util.h	2005-02-02 01:47:26 UTC (rev 1883)
@@ -46,19 +46,9 @@
 void util_show_stack(unsigned long *esp);
 void util_show_trace(unsigned long *stack);
 int util_sleep(__u32 ms);
-int __util_wait_atomic_eq(wait_queue_head_t *wq, atomic_t *var, int val, int ms);
 void util_block_sigs(sigset_t *oldsigs, unsigned long mask);
 void util_unblock_sigs(sigset_t newsig);
 
-/* exits when var == val, or on timeout */
-static inline int util_wait_atomic_eq(wait_queue_head_t *wq, atomic_t *var, int val, int timeout)
-{
-	int ret = 0;
-	if (atomic_read(var) != val)
-		ret = __util_wait_atomic_eq(wq, var, val, timeout);
-	return ret;
-}
-
 #endif  /* __KERNEL__ */
 
 /* resizable array */

Modified: trunk/fs/ocfs2/dlm/dlmmaster.c
===================================================================
--- trunk/fs/ocfs2/dlm/dlmmaster.c	2005-02-02 01:27:56 UTC (rev 1882)
+++ trunk/fs/ocfs2/dlm/dlmmaster.c	2005-02-02 01:47:26 UTC (rev 1883)
@@ -448,17 +448,19 @@
 		}
 
 		atomic_set(&mle->woken, 0);
-		ret = util_wait_atomic_eq(&mle->wq, &mle->woken, 1, 5000);
-		if (ret == -EINTR) {
-			dlmprintk0("interrupted during lock mastery!\n");
-			break;
-		}
-		if (ret == -ETIMEDOUT) {
+		ret = wait_event_interruptible_timeout(mle->wq, 
+					(atomic_read(&mle->woken) == 1), 
+					msecs_to_jiffies(5000));
+		if (ret == 0) {
 			dlmprintk("timed out during lock mastery: "
 				  "vote_map=%0lx, response_map=%0lx\n",
 				  mle->vote_map[0], mle->response_map[0]);
 			continue;
 		}
+		if (ret < 0) {
+			dlmprintk0("interrupted during lock mastery!\n");
+			break;
+		}
 	}
 	dlm_put_mle(mle);
 

Modified: trunk/fs/ocfs2/dlm/dlmrecovery.c
===================================================================
--- trunk/fs/ocfs2/dlm/dlmrecovery.c	2005-02-02 01:27:56 UTC (rev 1882)
+++ trunk/fs/ocfs2/dlm/dlmrecovery.c	2005-02-02 01:47:26 UTC (rev 1883)
@@ -215,10 +215,12 @@
 				  dlm->reco.new_master, dlm->reco.dead_node);
 sleep:
 			atomic_set(&dlm->reco.thread.woken, 0);
-			status = util_wait_atomic_eq(&dlm->reco.thread.thread_wq,
-						     &dlm->reco.thread.woken,
-						     1, DLM_RECOVERY_THREAD_MS);
-			if (status == 0 || status == -ETIMEDOUT) {
+			status = wait_event_interruptible_timeout(
+				  dlm->reco.thread.thread_wq,
+				  (atomic_read(&dlm->reco.thread.woken) == 1),
+				  msecs_to_jiffies(DLM_RECOVERY_THREAD_MS));
+
+			if (status >= 0) {
 				if (atomic_read(&dlm->reco.thread.woken))
 					dlmprintk0("aha!!! recovery thread woken!\n");
 				else
@@ -338,10 +340,10 @@
 		/* wait to be signalled, with periodic timeout
 		 * to check for node death */
 		atomic_set(&dlm->reco.thread.woken, 0);
-		ret = util_wait_atomic_eq(&dlm->reco.thread.thread_wq,
-					     &dlm->reco.thread.woken, 1,
-					     DLM_RECOVERY_THREAD_MS);
-		if (ret == 0 || ret == -ETIMEDOUT) {
+		ret = wait_event_interruptible_timeout(dlm->reco.thread.thread_wq,
+				(atomic_read(&dlm->reco.thread.woken) ==  1),
+				msecs_to_jiffies(DLM_RECOVERY_THREAD_MS));
+		if (ret >= 0) {
 			if (atomic_read(&dlm->reco.thread.woken))
 				dlmprintk0("waiting on reco data... aha!!! recovery thread woken!\n");
 			else

Modified: trunk/fs/ocfs2/dlm/util.c
===================================================================
--- trunk/fs/ocfs2/dlm/util.c	2005-02-02 01:27:56 UTC (rev 1882)
+++ trunk/fs/ocfs2/dlm/util.c	2005-02-02 01:47:26 UTC (rev 1883)
@@ -34,8 +34,6 @@
 
 #include "util.h"
 
-static void util_timeout_func(unsigned long data);
-
 /* block all but 'mask' sigs, optionally saving off our previous
  * signal state. */
 void util_block_sigs(sigset_t *oldsigs, unsigned long mask)
@@ -109,28 +107,6 @@
 }				/* util_daemonize */
 #endif
 
-/*
- * util_sleep()
- *
- * The interval time is in milliseconds
- *
- * This function needs to be removed.
- * Instead call schedule_timeout() directly and handle signals.
- */
-int util_sleep (__u32 ms)
-{
-	__u32 numJiffies;
-
-	/* 10ms = 1 jiffy, minimum resolution is one jiffy */
-	numJiffies = ms * HZ / 1000;
-	numJiffies = (numJiffies < 1) ? 1 : numJiffies;
-
-	set_current_state (TASK_INTERRUPTIBLE);
-	numJiffies = schedule_timeout (numJiffies);
-
-	return 0;
-}				/* util_sleep */
-
 /* prefetch has been declared to allow to build in debug mode */
 #ifdef DEBUG
 #ifndef ARCH_HAS_PREFETCH
@@ -140,88 +116,6 @@
 #endif
 #endif
 
-
-static void util_timeout_func(unsigned long data)
-{
-	util_timeout *to = (util_timeout *)data; 
-
-	to->timed_out = 1;
-	wake_up(&to->wait);
-}
-
-void util_init_timeout(util_timeout *to)
-{
-	init_timer(&to->timer);
-	to->timer.data = (unsigned long)to;
-	to->timer.function = util_timeout_func;
-	to->timed_out = 0;
-	init_waitqueue_head(&to->wait);
-}
-
-void util_set_timeout(util_timeout *to, __u32 timeout)
-{
-	__u32 how_long;
-
-	if (!timeout) {
-		to->timed_out = 1;
-		return ;
-	}
-
-	how_long = (timeout * HZ / 1000);
-	if (how_long < 1)
-		how_long = 1;
-
-	to->timer.expires = jiffies + how_long;
-	add_timer(&to->timer);
-}
-
-void util_clear_timeout(util_timeout *to)
-{
-	del_timer_sync(&to->timer);
-}
-
-int __util_wait_atomic_eq(wait_queue_head_t *wq, atomic_t *var, int val, int ms)
-{
-	int ret;
-	util_timeout timeout;
-	DECLARE_WAITQUEUE(wait, current);
-	DECLARE_WAITQUEUE(to_wait, current);
-
-	util_init_timeout(&timeout);
-
-	if (ms) {
-		util_set_timeout(&timeout, ms);
-		if (timeout.timed_out) {
-			util_clear_timeout(&timeout);
-		}
-	}
-	add_wait_queue(wq, &wait);
-	add_wait_queue(&timeout.wait, &to_wait);
-	do { 
-		ret = 0;
-		set_current_state(TASK_INTERRUPTIBLE);
-		if (atomic_read(var)==val)
-			break;
-		ret = -ETIMEDOUT;
-		if (timeout.timed_out)
-			break;
-		schedule();
-		if (signal_pending(current)) {
-			ret = -EINTR;
-			break;
-		}
-	} while (1);
-	
-	set_current_state(TASK_RUNNING);
-	remove_wait_queue(wq, &wait);
-	remove_wait_queue(&timeout.wait, &to_wait);
-
-	if (ms)
-		util_clear_timeout(&timeout);
-
-	return ret;
-}
-
 /* resizable (using chained pages) array stuff */
 void util_init_rarray(util_rarray *arr, u16 elem_size)
 {

Modified: trunk/fs/ocfs2/dlm/util.h
===================================================================
--- trunk/fs/ocfs2/dlm/util.h	2005-02-02 01:27:56 UTC (rev 1882)
+++ trunk/fs/ocfs2/dlm/util.h	2005-02-02 01:47:26 UTC (rev 1883)
@@ -49,19 +49,9 @@
 void util_show_stack(unsigned long *esp);
 void util_show_trace(unsigned long *stack);
 int util_sleep(__u32 ms);
-int __util_wait_atomic_eq(wait_queue_head_t *wq, atomic_t *var, int val, int ms);
 void util_block_sigs(sigset_t *oldsigs, unsigned long mask);
 void util_unblock_sigs(sigset_t newsig);
 
-/* exits when var == val, or on timeout */
-static inline int util_wait_atomic_eq(wait_queue_head_t *wq, atomic_t *var, int val, int timeout)
-{
-	int ret = 0;
-	if (atomic_read(var) != val)
-		ret = __util_wait_atomic_eq(wq, var, val, timeout);
-	return ret;
-}
-
 #endif  /* __KERNEL__ */
 
 /* resizable array */

Added: trunk/kapi-compat/include/wait_event_interruptible_timeout.h
===================================================================
--- trunk/kapi-compat/include/wait_event_interruptible_timeout.h	2005-02-02 01:27:56 UTC (rev 1882)
+++ trunk/kapi-compat/include/wait_event_interruptible_timeout.h	2005-02-02 01:47:26 UTC (rev 1883)
@@ -0,0 +1,37 @@
+#ifndef KAPI_WAIT_EVENT_INTERRUPTIBLE_TIMEOUT_H
+#define KAPI_WAIT_EVENT_INTERRUPTIBLE_TIMEOUT_H
+
+#include <linux/wait.h>
+
+#define __wait_event_interruptible_timeout(wq, condition, ret)		\
+do {									\
+	wait_queue_t __wait;                                            \
+	init_waitqueue_entry(&__wait, current);                         \
+									\
+	add_wait_queue(&wq, &__wait);                                   \
+	for (;;) {							\
+		set_current_state(TASK_INTERRUPTIBLE);			\
+		if (condition)						\
+			break;						\
+		if (!signal_pending(current)) {				\
+			ret = schedule_timeout(ret);			\
+			if (!ret)					\
+				break;					\
+			continue;					\
+		}							\
+		ret = -ERESTARTSYS;					\
+		break;							\
+	}								\
+	current->state = TASK_RUNNING;					\
+	remove_wait_queue(&wq, &__wait);				\
+} while (0)
+
+#define wait_event_interruptible_timeout(wq, condition, timeout)	\
+({									\
+	long __ret = timeout;						\
+	if (!(condition))						\
+		__wait_event_interruptible_timeout(wq, condition, __ret); \
+	__ret;								\
+})
+
+#endif



More information about the Ocfs2-commits mailing list