⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lustre_lib.h

📁 lustre 1.6.5 source code
💻 H
📖 第 1 页 / 共 3 页
字号:
 *                                           intr_handler, callback_data); * rc = l_wait_event(waitq, condition, &lwi); * * l_wait_event() makes the current process wait on 'waitq' until 'condition' * is TRUE or a "killable" signal (SIGTERM, SIKGILL, SIGINT) is pending.  It * returns 0 to signify 'condition' is TRUE, but if a signal wakes it before * 'condition' becomes true, it optionally calls the specified 'intr_handler' * if not NULL, and returns -EINTR. * * If a non-zero timeout is specified, signals are ignored until the timeout * has expired.  At this time, if 'timeout_handler' is not NULL it is called. * If it returns FALSE l_wait_event() continues to wait as described above with * signals enabled.  Otherwise it returns -ETIMEDOUT. * * LWI_INTR(intr_handler, callback_data) is shorthand for * LWI_TIMEOUT_INTR(0, NULL, intr_handler, callback_data) * * The second form of usage looks like this: * * struct l_wait_info lwi = LWI_TIMEOUT(timeout, timeout_handler); * rc = l_wait_event(waitq, condition, &lwi); * * This form is the same as the first except that it COMPLETELY IGNORES * SIGNALS.  The caller must therefore beware that if 'timeout' is zero, or if * 'timeout_handler' is not NULL and returns FALSE, then the ONLY thing that * can unblock the current process is 'condition' becoming TRUE. * * Another form of usage is: * struct l_wait_info lwi = LWI_TIMEOUT_INTERVAL(timeout, interval, *                                               timeout_handler); * rc = l_wait_event(waitq, condition, &lwi); * This is the same as previous case, but condition is checked once every * 'interval' jiffies (if non-zero). * * Subtle synchronization point: this macro does *not* necessary takes * wait-queue spin-lock before returning, and, hence, following idiom is safe * ONLY when caller provides some external locking: * *             Thread1                            Thread2 * *   l_wait_event(&obj->wq, ....);                                       (1) * *                                    wake_up(&obj->wq):                 (2) *                                         spin_lock(&q->lock);          (2.1) *                                         __wake_up_common(q, ...);     (2.2) *                                         spin_unlock(&q->lock, flags); (2.3) * *   OBD_FREE_PTR(obj);                                                  (3) * * As l_wait_event() may "short-cut" execution and return without taking * wait-queue spin-lock, some additional synchronization is necessary to * guarantee that step (3) can begin only after (2.3) finishes. * * XXX nikita: some ptlrpc daemon threads have races of that sort. * */#define LWI_ON_SIGNAL_NOOP ((void (*)(void *))(-1))struct l_wait_info {        cfs_duration_t lwi_timeout;        cfs_duration_t lwi_interval;        int  (*lwi_on_timeout)(void *);        void (*lwi_on_signal)(void *);        void  *lwi_cb_data;};/* NB: LWI_TIMEOUT ignores signals completely */#define LWI_TIMEOUT(time, cb, data)             \((struct l_wait_info) {                         \        .lwi_timeout    = time,                 \        .lwi_on_timeout = cb,                   \        .lwi_cb_data    = data,                 \        .lwi_interval   = 0                     \})#define LWI_TIMEOUT_INTERVAL(time, interval, cb, data)  \((struct l_wait_info) {                                 \        .lwi_timeout    = time,                         \        .lwi_on_timeout = cb,                           \        .lwi_cb_data    = data,                         \        .lwi_interval   = interval                      \})#define LWI_TIMEOUT_INTR(time, time_cb, sig_cb, data)   \((struct l_wait_info) {                                 \        .lwi_timeout    = time,                         \        .lwi_on_timeout = time_cb,                      \        .lwi_on_signal = sig_cb,                        \        .lwi_cb_data    = data,                         \        .lwi_interval    = 0                            \})#define LWI_INTR(cb, data)  LWI_TIMEOUT_INTR(0, NULL, cb, data)#ifdef __KERNEL__/* * wait for @condition to become true, but no longer than timeout, specified * by @info. */#define __l_wait_event(wq, condition, info, ret, excl)                         \do {                                                                           \        cfs_waitlink_t __wait;                                                 \        cfs_duration_t __timeout = info->lwi_timeout;                          \        cfs_sigset_t   __blocked;                                              \                                                                               \        ret = 0;                                                               \        if (condition)                                                         \                break;                                                         \                                                                               \        cfs_waitlink_init(&__wait);                                            \        if (excl)                                                              \                cfs_waitq_add_exclusive(&wq, &__wait);                         \        else                                                                   \                cfs_waitq_add(&wq, &__wait);                                   \                                                                               \        /* Block all signals (just the non-fatal ones if no timeout). */       \        if (info->lwi_on_signal != NULL && __timeout == 0)                     \                __blocked = l_w_e_set_sigs(LUSTRE_FATAL_SIGS);                 \        else                                                                   \                __blocked = l_w_e_set_sigs(0);                                 \                                                                               \        for (;;) {                                                             \                set_current_state(TASK_INTERRUPTIBLE);                         \                                                                               \                if (condition)                                                 \                        break;                                                 \                                                                               \                if (__timeout == 0) {                                          \                        cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE);       \                } else {                                                       \                        cfs_duration_t interval = info->lwi_interval?          \                                             min_t(cfs_duration_t,             \                                                 info->lwi_interval,__timeout):\                                             __timeout;                        \                        cfs_duration_t remaining = cfs_waitq_timedwait(&__wait,\                                                   CFS_TASK_INTERRUPTIBLE,     \                                                   interval);                  \                        __timeout = cfs_time_sub(__timeout,                    \                                            cfs_time_sub(interval, remaining));\                        if (__timeout == 0) {                                  \                                if (info->lwi_on_timeout == NULL ||            \                                    info->lwi_on_timeout(info->lwi_cb_data)) { \                                        ret = -ETIMEDOUT;                      \                                        break;                                 \                                }                                              \                                /* Take signals after the timeout expires. */  \                                if (info->lwi_on_signal != NULL)               \                                    (void)l_w_e_set_sigs(LUSTRE_FATAL_SIGS);   \                        }                                                      \                }                                                              \                                                                               \                if (condition)                                                 \                        break;                                                 \                if (cfs_signal_pending()) {                                    \                        if (info->lwi_on_signal != NULL && __timeout == 0) {   \                                if (info->lwi_on_signal != LWI_ON_SIGNAL_NOOP) \                                        info->lwi_on_signal(info->lwi_cb_data);\                                ret = -EINTR;                                  \                                break;                                         \                        }                                                      \                        /* 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.                             */     \                        cfs_clear_sigpending();                                \                }                                                              \        }                                                                      \                                                                               \        cfs_block_sigs(__blocked);                                             \                                                                               \        set_current_state(TASK_RUNNING);                                       \        cfs_waitq_del(&wq, &__wait);                                           \} while (0)#else /* !__KERNEL__ */#define __l_wait_event(wq, condition, info, ret, excl)                         \do {                                                                    \        long __timeout = info->lwi_timeout;                             \        long __now;                                                     \        long __then = 0;                                                \        int  __timed_out = 0;                                           \        int  __interval = obd_timeout;                                  \                                                                        \        ret = 0;                                                        \        if (condition)                                                  \                break;                                                  \                                                                        \        if (__timeout != 0)                                             \                __then = time(NULL);                                    \                                                                        \        if (__timeout && __timeout < __interval)                        \                __interval = __timeout;                                 \        if (info->lwi_interval && info->lwi_interval < __interval)      \                __interval = info->lwi_interval;                        \                                                                        \        while (!(condition)) {                                          \                liblustre_wait_event(__interval);                       \                if (condition)                                          \                        break;                                          \                                                                        \                if (!__timed_out && info->lwi_timeout != 0) {           \                        __now = time(NULL);                             \                        __timeout -= __now - __then;                    \                        __then = __now;                                 \                                                                        \                        if (__timeout > 0)                              \                                continue;                               \                                                                        \                        __timeout = 0;                                  \                        __timed_out = 1;                                \                        if (info->lwi_on_timeout == NULL ||             \                            info->lwi_on_timeout(info->lwi_cb_data)) {  \                                ret = -ETIMEDOUT;                       \                                break;                                  \                        }                                               \                }                                                       \        }                                                               \} while (0)#endif /* __KERNEL__ */#define l_wait_event(wq, condition, info)                       \({                                                              \        int                 __ret;                              \        struct l_wait_info *__info = (info);                    \                                                                \        __l_wait_event(wq, condition, __info, __ret, 0);        \        __ret;                                                  \})#define l_wait_event_exclusive(wq, condition, info)             \({                                                              \        int                 __ret;                              \        struct l_wait_info *__info = (info);                    \                                                                \        __l_wait_event(wq, condition, __info, __ret, 1);        \        __ret;                                                  \})#ifdef __KERNEL__#define LIBLUSTRE_CLIENT (0)#else#define LIBLUSTRE_CLIENT (1)#endif#endif /* _LUSTRE_LIB_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -