Whamcloud - gitweb
New tag 2.15.91
[fs/lustre-release.git] / libcfs / include / libcfs / linux / linux-wait.h
index d3fbf60..b54370f 100644 (file)
 #define wait_queue_entry_t wait_queue_t
 #endif
 
+#ifndef HAVE_PREPARE_TO_WAIT_EVENT
+#define __add_wait_queue_entry_tail __add_wait_queue_tail
+#endif
+
 #ifndef HAVE_WAIT_BIT_HEADER_H
 struct wait_bit_queue_entry {
        struct wait_bit_key     key;
@@ -136,6 +140,20 @@ do {                                                                       \
                __ret = __wait_var_event_timeout(var, condition, timeout); \
        __ret;                                                          \
 })
+#else /* !HAVE_WAIT_VAR_EVENT */
+/* linux-3.10.0-1062.el7 defines wait_var_event_timeout() using
+ * __wait_cond_timeout(), but doesn't define __wait_cond_timeout !!!
+ */
+# ifndef __wait_cond_timeout
+# define ___wait_cond_timeout(condition)                               \
+({                                                                     \
+       bool __cond = (condition);                                      \
+       if (__cond && !__ret)                                           \
+               __ret = 1;                                              \
+       __cond || !__ret;                                               \
+})
+# endif /* __wait_cond_timeout */
+
 #endif /* ! HAVE_WAIT_VAR_EVENT */
 
 /*
@@ -176,12 +194,12 @@ static inline void prepare_to_wait_exclusive_head(
 #define ___wait_event(wq_head, condition, state, exclusive, ret, cmd)  \
 ({                                                                     \
        __label__ __out;                                                \
-       wait_queue_entry_ __wq_entry;                                   \
+       wait_queue_entry_t __wq_entry;                                  \
        long __ret = ret;       /* explicit shadow */                   \
                                                                        \
        init_wait(&__wq_entry);                                         \
        if (exclusive)                                                  \
-               __wq_entry.flags = WQ_FLAG_EXCLUSIVE                    \
+               __wq_entry.flags = WQ_FLAG_EXCLUSIVE;                   \
        for (;;) {                                                      \
                long __int = prepare_to_wait_event(&wq_head,            \
                                                  &__wq_entry, state);  \
@@ -203,14 +221,17 @@ __out:    __ret;                                                          \
 
 #ifndef TASK_NOLOAD
 
+#define TASK_IDLE TASK_INTERRUPTIBLE
+
 #define ___wait_event_idle(wq_head, condition, exclusive, ret, cmd)    \
 ({                                                                     \
        wait_queue_entry_t __wq_entry;                                  \
        unsigned long flags;                                            \
        long __ret = ret;       /* explicit shadow */                   \
-       sigset_t __blocked;                                             \
+       sigset_t __old_blocked, __new_blocked;                          \
                                                                        \
-       __blocked = cfs_block_sigsinv(0);                               \
+       siginitset(&__new_blocked, LUSTRE_FATAL_SIGS);                  \
+       sigprocmask(0, &__new_blocked, &__old_blocked);                 \
        init_wait(&__wq_entry);                                         \
        if (exclusive)                                                  \
                __wq_entry.flags = WQ_FLAG_EXCLUSIVE;                   \
@@ -221,7 +242,13 @@ __out:     __ret;                                                          \
                                                                        \
                if (condition)                                          \
                        break;                                          \
-               /* See justification in __l_wait_event */               \
+               /* We have to do this here because some signals */      \
+               /* are not blockable - ie from strace(1).       */      \
+               /* In these cases we want to schedule_timeout() */      \
+               /* again, because we don't want that to return  */      \
+               /* -EINTR when the RPC actually succeeded.      */      \
+               /* the recalc_sigpending() below will deliver the */    \
+               /* signal properly.                             */      \
                if (signal_pending(current)) {                          \
                        spin_lock_irqsave(&current->sighand->siglock,   \
                                          flags);                       \
@@ -232,7 +259,7 @@ __out:      __ret;                                                          \
                cmd;                                                    \
        }                                                               \
        finish_wait(&wq_head, &__wq_entry);                             \
-       cfs_restore_sigs(__blocked);                                    \
+       sigprocmask(SIG_SETMASK, &__old_blocked, NULL);                 \
        __ret;                                                          \
 })
 
@@ -275,7 +302,6 @@ do {                                                                        \
                                              cmd1, cmd2)               \
 ({                                                                     \
        long __ret = timeout;                                           \
-       might_sleep();                                                  \
        if (!___wait_cond_timeout1(condition))                          \
                __ret = __wait_event_idle_exclusive_timeout_cmd(        \
                        wq_head, condition, timeout, cmd1, cmd2);       \
@@ -394,7 +420,6 @@ do {                                                                        \
                                              cmd1, cmd2)               \
 ({                                                                     \
        long __ret = timeout;                                           \
-       might_sleep();                                                  \
        if (!___wait_cond_timeout1(condition))                          \
                __ret = __wait_event_idle_exclusive_timeout_cmd(        \
                        wq_head, condition, timeout, cmd1, cmd2);       \
@@ -469,9 +494,10 @@ do {                                                                       \
        wait_queue_entry_t __wq_entry;                                  \
        unsigned long flags;                                            \
        long __ret = ret;       /* explicit shadow */                   \
-       sigset_t __blocked;                                             \
+       sigset_t __old_blocked, __new_blocked;                          \
                                                                        \
-       __blocked = cfs_block_sigsinv(0);                               \
+       siginitset(&__new_blocked, LUSTRE_FATAL_SIGS);                  \
+       sigprocmask(0, &__new_blocked, &__old_blocked);                 \
        init_wait(&__wq_entry);                                         \
        __wq_entry.flags = WQ_FLAG_EXCLUSIVE;                           \
        for (;;) {                                                      \
@@ -481,7 +507,7 @@ do {                                                                        \
                                                                        \
                if (condition)                                          \
                        break;                                          \
-               /* See justification in __l_wait_event */               \
+               /* See justification in ___wait_event_idle */           \
                if (signal_pending(current)) {                          \
                        spin_lock_irqsave(&current->sighand->siglock,   \
                                          flags);                       \
@@ -491,7 +517,7 @@ do {                                                                        \
                }                                                       \
                cmd;                                                    \
        }                                                               \
-       cfs_restore_sigs(__blocked);                                    \
+       sigprocmask(SIG_SETMASK, &__old_blocked, NULL);                 \
        finish_wait(&wq_head, &__wq_entry);                             \
        __ret;                                                          \
 })
@@ -561,4 +587,11 @@ do {                                                                       \
        __ret;                                                          \
 })
 
+#ifndef HAVE_WAIT_WOKEN
+#define WQ_FLAG_WOKEN          0x02
+long wait_woken(wait_queue_entry_t *wait, unsigned int mode, long timeout);
+int woken_wake_function(wait_queue_entry_t *wait, unsigned int mode,
+                       int sync, void *key);
+#endif /* HAVE_WAIT_WOKEN */
+
 #endif /* __LICBFS_LINUX_WAIT_BIT_H */