From 991ab17e59a12954cb839627b0c542486cc3603e Mon Sep 17 00:00:00 2001 From: yangsheng Date: Tue, 25 Dec 2007 13:00:13 +0000 Subject: [PATCH] Branch b1_4 b=13752 i=adilger i=shadow Add 2.4 kernel support for lnet. --- lnet/include/libcfs/linux/kp30.h | 7 +++ lnet/include/libcfs/linux/linux-prim.h | 88 ++++++++++++++++++++++++++++++++++ lnet/selftest/conrpc.c | 2 +- lnet/selftest/timer.c | 2 +- 4 files changed, 97 insertions(+), 2 deletions(-) diff --git a/lnet/include/libcfs/linux/kp30.h b/lnet/include/libcfs/linux/kp30.h index 46bab8b..fb1ae3e 100644 --- a/lnet/include/libcfs/linux/kp30.h +++ b/lnet/include/libcfs/linux/kp30.h @@ -173,6 +173,13 @@ static inline void our_cond_resched(void) # define printf(format, b...) CDEBUG(D_OTHER, format , ## b) # define time(a) CURRENT_TIME +#ifndef num_possible_cpus +#define num_possible_cpus() NR_CPUS +#endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) +#define i_size_read(a) ((a)->i_size) +#endif + #else /* !__KERNEL__ */ # include # include diff --git a/lnet/include/libcfs/linux/linux-prim.h b/lnet/include/libcfs/linux/linux-prim.h index a8153dd..9ae57cd 100644 --- a/lnet/include/libcfs/linux/linux-prim.h +++ b/lnet/include/libcfs/linux/linux-prim.h @@ -201,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; diff --git a/lnet/selftest/conrpc.c b/lnet/selftest/conrpc.c index 45c8031..b47fbe1 100644 --- a/lnet/selftest/conrpc.c +++ b/lnet/selftest/conrpc.c @@ -318,7 +318,7 @@ lstcon_rpc_trans_postwait(lstcon_rpc_trans_t *trans, int timeout) mutex_up(&console_session.ses_mutex); - rc = wait_event_interruptible_timeout(trans->tas_waitq, + rc = cfs_waitq_wait_event_interruptible_timeout(trans->tas_waitq, lstcon_rpc_trans_check(trans), timeout * HZ); diff --git a/lnet/selftest/timer.c b/lnet/selftest/timer.c index eb72a78..e847e48 100644 --- a/lnet/selftest/timer.c +++ b/lnet/selftest/timer.c @@ -154,7 +154,7 @@ stt_timer_main (void *arg) while (!stt_data.stt_shuttingdown) { stt_check_timers(&stt_data.stt_prev_slot); - wait_event_timeout(stt_data.stt_waitq, + cfs_waitq_wait_event_timeout(stt_data.stt_waitq, stt_data.stt_shuttingdown, cfs_time_seconds(STTIMER_SLOTTIME)); } -- 1.8.3.1