Whamcloud - gitweb
LU-10805 libcfs: timer_setup() API changes 90/31790/4
authorLi Dongyang <dongyangli@ddn.com>
Sun, 6 May 2018 14:28:58 +0000 (10:28 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Sat, 12 May 2018 03:53:25 +0000 (03:53 +0000)
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 <dongyangli@ddn.com>
Change-Id: Ib79495f9ab7e955d6f72f1e9390cec0e23e2d641
Reviewed-on: https://review.whamcloud.com/31790
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: Jinshan Xiong <jinshan.xiong@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
contrib/scripts/spelling.txt
libcfs/autoconf/lustre-libcfs.m4
libcfs/include/libcfs/linux/linux-time.h
libcfs/libcfs/watchdog.c
lnet/lnet/net_fault.c
lustre/ldlm/ldlm_lib.c
lustre/ldlm/ldlm_lockd.c
lustre/obdclass/genops.c
lustre/osp/osp_precreate.c
lustre/ptlrpc/service.c

index bab5813..9061f01 100644 (file)
@@ -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)
 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
index 2df490a..ba6a0dd 100644 (file)
@@ -542,8 +542,8 @@ ktime_to_timespec64, [
        #include <linux/hrtimer.h>
        #include <linux/ktime.h>
 ],[
        #include <linux/hrtimer.h>
        #include <linux/ktime.h>
 ],[
+       ktime_t now = ktime_set(0, 0);
        struct timespec64 ts;
        struct timespec64 ts;
-       ktime_t now = { };
 
        ts = ktime_to_timespec64(now);
 ],[
 
        ts = ktime_to_timespec64(now);
 ],[
@@ -882,6 +882,25 @@ EXTRA_KCFLAGS="$tmp_flags"
 ]) # LIBCFS_NEW_KERNEL_WRITE
 
 #
 ]) # 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 <linux/timer.h>
+],[
+       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
 # LIBCFS_PROG_LINUX
 #
 # LibCFS linux kernel checks
@@ -966,6 +985,8 @@ LIBCFS_SCHED_HEADERS
 LIBCFS_WAIT_QUEUE_ENTRY
 # 4.14
 LIBCFS_NEW_KERNEL_WRITE
 LIBCFS_WAIT_QUEUE_ENTRY
 # 4.14
 LIBCFS_NEW_KERNEL_WRITE
+# 4.15
+LIBCFS_TIMER_SETUP
 ]) # LIBCFS_PROG_LINUX
 
 #
 ]) # LIBCFS_PROG_LINUX
 
 #
index eeced6b..b5be95e 100644 (file)
@@ -197,4 +197,23 @@ static inline unsigned long cfs_time_seconds(time64_t seconds)
        return nsecs_to_jiffies(seconds * NSEC_PER_SEC);
 }
 
        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__ */
 #endif /* __LIBCFS_LINUX_LINUX_TIME_H__ */
index 524b4b5..4c437ab 100644 (file)
@@ -118,9 +118,9 @@ lcw_dump(struct lc_watchdog *lcw)
         EXIT;
 }
 
         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) {
         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);
        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)
 
        mutex_lock(&lcw_refcount_mutex);
        if (++lcw_refcount == 1)
index 398864e..05daed2 100644 (file)
@@ -695,9 +695,9 @@ lnet_delay_rule_daemon(void *arg)
 }
 
 static void
 }
 
 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) {
 
        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);
        }
 
                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);
 
        spin_lock_init(&rule->dl_lock);
        INIT_LIST_HEAD(&rule->dl_msg_list);
index 27deb36..278e5d5 100644 (file)
@@ -2605,9 +2605,9 @@ void target_recovery_fini(struct obd_device *obd)
 }
 EXPORT_SYMBOL(target_recovery_fini);
 
 }
 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),
        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;
 
         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);
        target_start_recovery_thread(lut, handler);
 }
 EXPORT_SYMBOL(target_recovery_init);
index b502b17..22b1a18 100644 (file)
@@ -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);
  * 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,
 
 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 */
 }
 
 /* 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;
 {
        struct ldlm_lock        *lock;
        int                     need_dump = 0;
index 5f679de..22ad827 100644 (file)
@@ -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 */
        /* 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);
        spin_lock_init(&newdev->obd_recovery_task_lock);
        init_waitqueue_head(&newdev->obd_next_transno_waitq);
        init_waitqueue_head(&newdev->obd_evict_inprogress_waitq);
index 468763c..bbcd7b3 100644 (file)
@@ -88,9 +88,9 @@ static inline bool osp_precreate_stopped(struct osp_device *d)
        return !!(d->opd_pre_thread.t_flags & SVC_STOPPED);
 }
 
        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))
 
        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));
        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);
 
        if (d->opd_storage->dd_rdonly)
                RETURN(0);
index ab7aea1..5f2322f 100644 (file)
@@ -475,11 +475,11 @@ ptlrpc_server_post_idle_rqbds(struct ptlrpc_service_part *svcpt)
        return -1;
 }
 
        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;
 
 {
        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();
 
        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;
 
        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. */
 
        /* 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) {
        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));
        } else {
                mod_timer(&svcpt->scp_at_timer,
                          jiffies + nsecs_to_jiffies(next * NSEC_PER_SEC));