From ac40000d4bde21f807a68cb2add326ea5d77385c Mon Sep 17 00:00:00 2001 From: James Simmons Date: Mon, 6 Aug 2018 13:56:55 -0400 Subject: [PATCH] LU-11200 libcfs: handle DECLARE_TIMER reduced to two arguments For the linux kernel their exist two ways to initialize a struct timer_list. One method is with setup_timer() and the other is with the DEFINE_TIMER macro. For earlier kernels both methods employed callbacked with a argument of the type unsigned long. In kernels 4.15+ both methods of initialization use struct timer_list pointer for its callback argument. During the 4.14 development phase we have setup_timer() using struct timer_list as an argument for its callback but DEFINE_TIMER was still using unsigned long. Additionally when DEFINE_TIMER did move to using struct timer_list it reduced the number of arguments to the macro. This patch handles the 4.14 kernel state of development for the timer API. Test-Parameters: trivial Change-Id: I1c509838153328ed4bbdfa50468a396e13037d50 Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/32939 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Li Dongyang Reviewed-by: Yang Sheng Reviewed-by: Oleg Drokin --- libcfs/autoconf/lustre-libcfs.m4 | 20 ++++++++++++++++++++ libcfs/include/libcfs/linux/linux-time.h | 20 ++++++++++++++++---- lustre/ldlm/ldlm_lockd.c | 4 ++-- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index 4774cac..0803c70 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -858,6 +858,25 @@ EXTRA_KCFLAGS="$tmp_flags" ]) # LIBCFS_NEW_KERNEL_WRITE # +# LIBCFS_DEFINE_TIMER +# +# Kernel version 4.14 commit 1d27e3e2252ba9d949ca82fbdb73cde102cb2067 +# remove expires and data arguments from DEFINE_TIMER. Also the callback +# when from using unsigned long argument to using struct timer_list pointer. +# +AC_DEFUN([LIBCFS_DEFINE_TIMER], [ +LB_CHECK_COMPILE([if DEFINE_TIMER takes only 2 arguments], +define_timer, [ + #include +],[ + static DEFINE_TIMER(my_timer, NULL); +],[ + AC_DEFINE(HAVE_NEW_DEFINE_TIMER, 1, + [DEFINE_TIMER uses only 2 arguements]) +]) +]) # LIBCFS_DEFINE_TIMER + +# # LIBCFS_TIMER_SETUP # # Kernel version 4.15 commit e99e88a9d2b067465adaa9c111ada99a041bef9a @@ -958,6 +977,7 @@ LIBCFS_SCHED_HEADERS # 4.13 LIBCFS_WAIT_QUEUE_ENTRY # 4.14 +LIBCFS_DEFINE_TIMER LIBCFS_NEW_KERNEL_WRITE # 4.15 LIBCFS_TIMER_SETUP diff --git a/libcfs/include/libcfs/linux/linux-time.h b/libcfs/include/libcfs/linux/linux-time.h index b5be95e..5af8134 100644 --- a/libcfs/include/libcfs/linux/linux-time.h +++ b/libcfs/include/libcfs/linux/linux-time.h @@ -197,22 +197,34 @@ static inline unsigned long cfs_time_seconds(time64_t seconds) return nsecs_to_jiffies(seconds * NSEC_PER_SEC); } +#ifdef HAVE_NEW_DEFINE_TIMER +# ifndef TIMER_DATA_TYPE +# define TIMER_DATA_TYPE struct timer_list * +# endif + +#define CFS_DEFINE_TIMER(_name, _function, _expires, _data) \ + DEFINE_TIMER((_name), (_function)) +#else +# ifndef TIMER_DATA_TYPE +# define TIMER_DATA_TYPE unsigned long +# endif + +#define CFS_DEFINE_TIMER(_name, _function, _expires, _data) \ + DEFINE_TIMER((_name), (_function), (_expires), (_data)) +#endif + #ifdef HAVE_TIMER_SETUP #define cfs_timer_cb_arg_t struct timer_list * #define cfs_from_timer(var, callback_timer, timer_fieldname) \ from_timer(var, callback_timer, timer_fieldname) #define cfs_timer_setup(timer, callback, data, flags) \ timer_setup((timer), (callback), (flags)) -#define CFS_DEFINE_TIMER(_name, _function, _expires, _data) \ - DEFINE_TIMER((_name), (_function)) #define cfs_timer_cb_arg(var, timer_fieldname) (&(var)->timer_fieldname) #else #define cfs_timer_cb_arg_t unsigned long #define cfs_from_timer(var, data, timer_fieldname) (typeof(var))(data) #define cfs_timer_setup(timer, callback, data, flags) \ setup_timer((timer), (callback), (data)) -#define CFS_DEFINE_TIMER(_name, _function, _expires, _data) \ - DEFINE_TIMER((_name), (_function), (_expires), (_data)) #define cfs_timer_cb_arg(var, timer_fieldname) (cfs_timer_cb_arg_t)(var) #endif diff --git a/lustre/ldlm/ldlm_lockd.c b/lustre/ldlm/ldlm_lockd.c index 3273fdc..c0b4edc 100644 --- a/lustre/ldlm/ldlm_lockd.c +++ b/lustre/ldlm/ldlm_lockd.c @@ -131,7 +131,7 @@ static DEFINE_SPINLOCK(waiting_locks_spinlock); /* BH lock (timer) */ * All access to it should be under waiting_locks_spinlock. */ static LIST_HEAD(waiting_locks_list); -static void waiting_locks_callback(cfs_timer_cb_arg_t unused); +static void waiting_locks_callback(TIMER_DATA_TYPE unused); static CFS_DEFINE_TIMER(waiting_locks_timer, waiting_locks_callback, 0, 0); enum elt_state { @@ -303,7 +303,7 @@ static int ldlm_lock_busy(struct ldlm_lock *lock) } /* This is called from within a timer interrupt and cannot schedule */ -static void waiting_locks_callback(cfs_timer_cb_arg_t unused) +static void waiting_locks_callback(TIMER_DATA_TYPE unused) { struct ldlm_lock *lock; int need_dump = 0; -- 1.8.3.1