From 782ff36d50c77652d0358dc2d0bbddf81fac8759 Mon Sep 17 00:00:00 2001 From: Li Dongyang Date: Sun, 6 May 2018 10:28:58 -0400 Subject: [PATCH] LU-10805 libcfs: timer_setup() API changes Linux kernel 4.15 replaced setup_timer() with the new interface timer_setup(). Introduce cfs wrappers to handle the API changes. Linux-commit: e99e88a9d2b067465adaa9c111ada99a041bef9a Signed-off-by: Li Dongyang Change-Id: Ib79495f9ab7e955d6f72f1e9390cec0e23e2d641 Reviewed-on: https://review.whamcloud.com/31790 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Bob Glossman Reviewed-by: Jinshan Xiong Reviewed-by: Oleg Drokin --- contrib/scripts/spelling.txt | 4 ++++ libcfs/autoconf/lustre-libcfs.m4 | 23 ++++++++++++++++++++++- libcfs/include/libcfs/linux/linux-time.h | 19 +++++++++++++++++++ libcfs/libcfs/watchdog.c | 6 +++--- lnet/lnet/net_fault.c | 9 ++++----- lustre/ldlm/ldlm_lib.c | 8 ++++---- lustre/ldlm/ldlm_lockd.c | 6 +++--- lustre/obdclass/genops.c | 1 - lustre/osp/osp_precreate.c | 8 ++++---- lustre/ptlrpc/service.c | 10 +++++----- 10 files changed, 68 insertions(+), 26 deletions(-) diff --git a/contrib/scripts/spelling.txt b/contrib/scripts/spelling.txt index bab5813..9061f01 100644 --- a/contrib/scripts/spelling.txt +++ b/contrib/scripts/spelling.txt @@ -140,3 +140,7 @@ return seq_printf||seq_printf wait_queue_t|wait_queue_entry_t DN_MAX_BONUSLEN||DN_BONUS_SIZE(dnodesize) DN_OLD_MAX_BONUSLEN||DN_BONUS_SIZE(DNODE_MIN_SIZE) +setup_timer||cfs_timer_setup +timer_setup||cfs_timer_setup +from_timer||cfs_from_timer +DEFINE_TIMER||CFS_DEFINE_TIMER diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index 2df490a..ba6a0dd 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -542,8 +542,8 @@ ktime_to_timespec64, [ #include #include ],[ + ktime_t now = ktime_set(0, 0); struct timespec64 ts; - ktime_t now = { }; ts = ktime_to_timespec64(now); ],[ @@ -882,6 +882,25 @@ EXTRA_KCFLAGS="$tmp_flags" ]) # LIBCFS_NEW_KERNEL_WRITE # +# LIBCFS_TIMER_SETUP +# +# Kernel version 4.15 commit e99e88a9d2b067465adaa9c111ada99a041bef9a +# setup_timer() was replaced by timer_setup(), where the callback +# argument is the structure already holding the struct timer_list. +# +AC_DEFUN([LIBCFS_TIMER_SETUP], [ +LB_CHECK_COMPILE([if setup_timer has been replaced with timer_setup], +timer_setup, [ + #include +],[ + timer_setup(NULL, NULL, 0); +],[ + AC_DEFINE(HAVE_TIMER_SETUP, 1, + [timer_setup has replaced setup_timer]) +]) +]) # LIBCFS_TIMER_SETUP + +# # LIBCFS_PROG_LINUX # # LibCFS linux kernel checks @@ -966,6 +985,8 @@ LIBCFS_SCHED_HEADERS LIBCFS_WAIT_QUEUE_ENTRY # 4.14 LIBCFS_NEW_KERNEL_WRITE +# 4.15 +LIBCFS_TIMER_SETUP ]) # LIBCFS_PROG_LINUX # diff --git a/libcfs/include/libcfs/linux/linux-time.h b/libcfs/include/libcfs/linux/linux-time.h index eeced6b..b5be95e 100644 --- a/libcfs/include/libcfs/linux/linux-time.h +++ b/libcfs/include/libcfs/linux/linux-time.h @@ -197,4 +197,23 @@ static inline unsigned long cfs_time_seconds(time64_t seconds) return nsecs_to_jiffies(seconds * NSEC_PER_SEC); } +#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 + #endif /* __LIBCFS_LINUX_LINUX_TIME_H__ */ diff --git a/libcfs/libcfs/watchdog.c b/libcfs/libcfs/watchdog.c index 524b4b5..4c437ab 100644 --- a/libcfs/libcfs/watchdog.c +++ b/libcfs/libcfs/watchdog.c @@ -118,9 +118,9 @@ lcw_dump(struct lc_watchdog *lcw) EXIT; } -static void lcw_cb(uintptr_t data) +static void lcw_cb(cfs_timer_cb_arg_t data) { - struct lc_watchdog *lcw = (struct lc_watchdog *)data; + struct lc_watchdog *lcw = cfs_from_timer(lcw, data, lcw_timer); ENTRY; if (lcw->lcw_state != LC_WATCHDOG_ENABLED) { @@ -364,7 +364,7 @@ struct lc_watchdog *lc_watchdog_add(int timeout, lcw->lcw_state = LC_WATCHDOG_DISABLED; INIT_LIST_HEAD(&lcw->lcw_list); - setup_timer(&lcw->lcw_timer, lcw_cb, (unsigned long)lcw); + cfs_timer_setup(&lcw->lcw_timer, lcw_cb, (unsigned long)lcw, 0); mutex_lock(&lcw_refcount_mutex); if (++lcw_refcount == 1) diff --git a/lnet/lnet/net_fault.c b/lnet/lnet/net_fault.c index 398864e..05daed2 100644 --- a/lnet/lnet/net_fault.c +++ b/lnet/lnet/net_fault.c @@ -695,9 +695,9 @@ lnet_delay_rule_daemon(void *arg) } static void -delay_timer_cb(unsigned long arg) +delay_timer_cb(cfs_timer_cb_arg_t data) { - struct lnet_delay_rule *rule = (struct lnet_delay_rule *)arg; + struct lnet_delay_rule *rule = cfs_from_timer(rule, data, dl_timer); spin_lock_bh(&delay_dd.dd_lock); if (list_empty(&rule->dl_sched_link) && delay_dd.dd_running) { @@ -760,9 +760,8 @@ lnet_delay_rule_add(struct lnet_fault_attr *attr) wait_event(delay_dd.dd_ctl_waitq, delay_dd.dd_running); } - init_timer(&rule->dl_timer); - rule->dl_timer.function = delay_timer_cb; - rule->dl_timer.data = (unsigned long)rule; + cfs_timer_setup(&rule->dl_timer, delay_timer_cb, + (unsigned long)rule, 0); spin_lock_init(&rule->dl_lock); INIT_LIST_HEAD(&rule->dl_msg_list); diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c index 27deb36..278e5d5 100644 --- a/lustre/ldlm/ldlm_lib.c +++ b/lustre/ldlm/ldlm_lib.c @@ -2605,9 +2605,9 @@ void target_recovery_fini(struct obd_device *obd) } EXPORT_SYMBOL(target_recovery_fini); -static void target_recovery_expired(unsigned long castmeharder) +static void target_recovery_expired(cfs_timer_cb_arg_t data) { - struct obd_device *obd = (struct obd_device *)castmeharder; + struct obd_device *obd = cfs_from_timer(obd, data, obd_recovery_timer); CDEBUG(D_HA, "%s: recovery timed out; %d clients are still in recovery" " after %llus (%d clients connected)\n", obd->obd_name, atomic_read(&obd->obd_lock_replay_clients), @@ -2639,8 +2639,8 @@ void target_recovery_init(struct lu_target *lut, svc_handler_t handler) obd->obd_recovery_start = 0; obd->obd_recovery_end = 0; - setup_timer(&obd->obd_recovery_timer, target_recovery_expired, - (unsigned long)obd); + cfs_timer_setup(&obd->obd_recovery_timer, target_recovery_expired, + (unsigned long)obd, 0); target_start_recovery_thread(lut, handler); } EXPORT_SYMBOL(target_recovery_init); diff --git a/lustre/ldlm/ldlm_lockd.c b/lustre/ldlm/ldlm_lockd.c index b502b17..22b1a18 100644 --- a/lustre/ldlm/ldlm_lockd.c +++ b/lustre/ldlm/ldlm_lockd.c @@ -131,8 +131,8 @@ 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(unsigned long unused); -static DEFINE_TIMER(waiting_locks_timer, waiting_locks_callback, 0, 0); +static void waiting_locks_callback(cfs_timer_cb_arg_t unused); +static CFS_DEFINE_TIMER(waiting_locks_timer, waiting_locks_callback, 0, 0); enum elt_state { ELT_STOPPED, @@ -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(unsigned long unused) +static void waiting_locks_callback(cfs_timer_cb_arg_t unused) { struct ldlm_lock *lock; int need_dump = 0; diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 5f679de..22ad827 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -431,7 +431,6 @@ struct obd_device *class_newdev(const char *type_name, const char *name, /* XXX belongs in setup not attach */ init_rwsem(&newdev->obd_observer_link_sem); /* recovery data */ - init_timer(&newdev->obd_recovery_timer); spin_lock_init(&newdev->obd_recovery_task_lock); init_waitqueue_head(&newdev->obd_next_transno_waitq); init_waitqueue_head(&newdev->obd_evict_inprogress_waitq); diff --git a/lustre/osp/osp_precreate.c b/lustre/osp/osp_precreate.c index 468763c..bbcd7b3 100644 --- a/lustre/osp/osp_precreate.c +++ b/lustre/osp/osp_precreate.c @@ -88,9 +88,9 @@ static inline bool osp_precreate_stopped(struct osp_device *d) return !!(d->opd_pre_thread.t_flags & SVC_STOPPED); } -static void osp_statfs_timer_cb(unsigned long _d) +static void osp_statfs_timer_cb(cfs_timer_cb_arg_t data) { - struct osp_device *d = (struct osp_device *) _d; + struct osp_device *d = cfs_from_timer(d, data, opd_statfs_timer); LASSERT(d); if (d->opd_pre != NULL && osp_precreate_running(d)) @@ -1707,8 +1707,8 @@ int osp_init_precreate(struct osp_device *d) CDEBUG(D_OTHER, "current %lldns, fresh till %lldns\n", ktime_get_ns(), ktime_to_ns(d->opd_statfs_fresh_till)); - setup_timer(&d->opd_statfs_timer, osp_statfs_timer_cb, - (unsigned long)d); + cfs_timer_setup(&d->opd_statfs_timer, osp_statfs_timer_cb, + (unsigned long)d, 0); if (d->opd_storage->dd_rdonly) RETURN(0); diff --git a/lustre/ptlrpc/service.c b/lustre/ptlrpc/service.c index ab7aea1..5f2322f 100644 --- a/lustre/ptlrpc/service.c +++ b/lustre/ptlrpc/service.c @@ -475,11 +475,11 @@ ptlrpc_server_post_idle_rqbds(struct ptlrpc_service_part *svcpt) return -1; } -static void ptlrpc_at_timer(unsigned long castmeharder) +static void ptlrpc_at_timer(cfs_timer_cb_arg_t data) { struct ptlrpc_service_part *svcpt; - svcpt = (struct ptlrpc_service_part *)castmeharder; + svcpt = cfs_from_timer(svcpt, data, scp_at_timer); svcpt->scp_at_check = 1; svcpt->scp_at_checktime = ktime_get(); @@ -646,8 +646,8 @@ ptlrpc_service_part_init(struct ptlrpc_service *svc, if (array->paa_reqs_count == NULL) goto failed; - setup_timer(&svcpt->scp_at_timer, ptlrpc_at_timer, - (unsigned long)svcpt); + cfs_timer_setup(&svcpt->scp_at_timer, ptlrpc_at_timer, + (unsigned long)svcpt, 0); /* At SOW, service time should be quick; 10s seems generous. If client * timeout is less than this, we'll be sending an early reply. */ @@ -1194,7 +1194,7 @@ static void ptlrpc_at_set_timer(struct ptlrpc_service_part *svcpt) next = array->paa_deadline - ktime_get_real_seconds() - at_early_margin; if (next <= 0) { - ptlrpc_at_timer((unsigned long)svcpt); + ptlrpc_at_timer(cfs_timer_cb_arg(svcpt, scp_at_timer)); } else { mod_timer(&svcpt->scp_at_timer, jiffies + nsecs_to_jiffies(next * NSEC_PER_SEC)); -- 1.8.3.1