Whamcloud - gitweb
Branch b1_4
[fs/lustre-release.git] / lnet / include / libcfs / linux / linux-prim.h
index 41eeb8a..9ae57cd 100644 (file)
@@ -30,7 +30,7 @@
 #endif
 
 #ifdef __KERNEL__
-#ifdef HAVE_KERNEL_CONFIG_H
+#ifndef AUTOCONF_INCLUDED
 #include <linux/config.h>
 #endif
 #include <linux/module.h>
@@ -39,6 +39,8 @@
 #include <linux/proc_fs.h>
 #include <linux/mm.h>
 #include <linux/timer.h>
+#include <linux/signal.h>
+#include <linux/sched.h>
 
 #include <linux/miscdevice.h>
 #include <libcfs/linux/portals_compat25.h>
@@ -59,8 +61,12 @@ typedef struct miscdevice            cfs_psdev_t;
 typedef struct ctl_table               cfs_sysctl_table_t;
 typedef struct ctl_table_header                cfs_sysctl_table_header_t;
 
+#ifdef HAVE_2ARGS_REGISTER_SYSCTL
 #define cfs_register_sysctl_table(t, a)        register_sysctl_table(t, a)
-#define cfs_unregister_sysctl_table(t) unregister_sysctl_table(t, a)
+#else
+#define cfs_register_sysctl_table(t, a) register_sysctl_table(t)
+#endif
+#define cfs_unregister_sysctl_table(t) unregister_sysctl_table(t)
 
 /*
  * Symbol register
@@ -195,6 +201,94 @@ static inline void cfs_pause(cfs_duration_t ticks)
         schedule_timeout(ticks);
 }
 
+#ifndef wait_event_timeout /* Only for RHEL3 2.4.21 kernel */
+#define __wait_event_timeout(wq, condition, timeout, ret)        \
+do {                                                             \
+       int __ret = 0;                                           \
+       if (!(condition)) {                                      \
+               wait_queue_t __wait;                             \
+               unsigned long expire;                            \
+                                                                 \
+               init_waitqueue_entry(&__wait, current);          \
+               expire = timeout + jiffies;                      \
+               add_wait_queue(&wq, &__wait);                    \
+               for (;;) {                                       \
+                       set_current_state(TASK_UNINTERRUPTIBLE); \
+                       if (condition)                           \
+                               break;                           \
+                       if (jiffies > expire) {                  \
+                               ret = jiffies - expire;          \
+                               break;                           \
+                       }                                        \
+                       schedule_timeout(timeout);               \
+               }                                                \
+               current->state = TASK_RUNNING;                   \
+               remove_wait_queue(&wq, &__wait);                 \
+       }                                                        \
+} while (0)
+/*
+   retval == 0; condition met; we're good.
+   retval > 0; timed out.
+*/
+#define cfs_waitq_wait_event_timeout(wq, condition, timeout)         \
+({                                                                   \
+       int __ret = 0;                                               \
+       if (!(condition))                                            \
+               __wait_event_timeout(wq, condition, timeout, __ret); \
+       __ret;                                                       \
+})
+#else
+#define cfs_waitq_wait_event_timeout  wait_event_timeout
+#endif
+
+#ifndef wait_event_interruptible_timeout /* Only for RHEL3 2.4.21 kernel */
+#define __wait_event_interruptible_timeout(wq, condition, timeout, ret)   \
+do {                                                           \
+       int __ret = 0;                                         \
+       if (!(condition)) {                                    \
+               wait_queue_t __wait;                           \
+               unsigned long expire;                          \
+                                                               \
+               init_waitqueue_entry(&__wait, current);        \
+               expire = timeout + jiffies;                    \
+               add_wait_queue(&wq, &__wait);                  \
+               for (;;) {                                     \
+                       set_current_state(TASK_INTERRUPTIBLE); \
+                       if (condition)                         \
+                               break;                         \
+                       if (jiffies > expire) {                \
+                               ret = jiffies - expire;        \
+                               break;                         \
+                       }                                      \
+                       if (!signal_pending(current)) {        \
+                               schedule_timeout(timeout);     \
+                               continue;                      \
+                       }                                      \
+                       ret = -ERESTARTSYS;                    \
+                       break;                                 \
+               }                                              \
+               current->state = TASK_RUNNING;                 \
+               remove_wait_queue(&wq, &__wait);               \
+       }                                                      \
+} while (0)
+
+/*
+   retval == 0; condition met; we're good.
+   retval < 0; interrupted by signal.
+   retval > 0; timed out.
+*/
+#define cfs_waitq_wait_event_interruptible_timeout(wq, condition, timeout) \
+({                                                                \
+       int __ret = 0;                                            \
+       if (!(condition))                                         \
+               __wait_event_interruptible_timeout(wq, condition, \
+                                               timeout, __ret);  \
+       __ret;                                                    \
+})
+#else
+#define cfs_waitq_wait_event_interruptible_timeout wait_event_interruptible_timeout
+#endif
+
 #else   /* !__KERNEL__ */
 
 typedef struct proc_dir_entry           cfs_proc_dir_entry_t;