staging/lustre: use 64-bit time for selftest
authorArnd Bergmann <arnd@arndb.de>
Sun, 27 Sep 2015 20:45:23 +0000 (16:45 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 29 Sep 2015 02:03:37 +0000 (04:03 +0200)
The lustre selftest code has multiple time stamps that are kept
as 'time_t' or 'unsigned long' and can therefore overflow on
32-bit systems.

This changes the code to use time64_t instead.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Oleg Drokin <green@linuxhacker.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lnet/selftest/brw_test.c
drivers/staging/lustre/lnet/selftest/conctl.c
drivers/staging/lustre/lnet/selftest/conrpc.c
drivers/staging/lustre/lnet/selftest/console.c
drivers/staging/lustre/lnet/selftest/console.h
drivers/staging/lustre/lnet/selftest/framework.c
drivers/staging/lustre/lnet/selftest/rpc.c
drivers/staging/lustre/lnet/selftest/selftest.h
drivers/staging/lustre/lnet/selftest/timer.c
drivers/staging/lustre/lnet/selftest/timer.h

index de11f1bc8be767577d5d17b2a5a1a5f07dbc7120..0605c651f7973966ac747ea56c902c4158ac4c85 100644 (file)
@@ -134,14 +134,14 @@ brw_client_init(sfw_test_instance_t *tsi)
 static int
 brw_inject_one_error(void)
 {
-       struct timeval tv;
+       struct timespec64 ts;
 
        if (brw_inject_errors <= 0)
                return 0;
 
-       do_gettimeofday(&tv);
+       ktime_get_ts64(&ts);
 
-       if ((tv.tv_usec & 1) == 0)
+       if (((ts.tv_nsec / NSEC_PER_USEC) & 1) == 0)
                return 0;
 
        return brw_inject_errors--;
index 1a7870e91f23a51dc178329109282bff4a94161b..817396638652451c954ba64d70430f1233153c86 100644 (file)
@@ -837,7 +837,7 @@ lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data)
 
        mutex_lock(&console_session.ses_mutex);
 
-       console_session.ses_laststamp = get_seconds();
+       console_session.ses_laststamp = ktime_get_real_seconds();
 
        if (console_session.ses_shutdown) {
                rc = -ESHUTDOWN;
index bf29683105165556638ba9efb7291329f53fa7a0..b70680b8bdbe2c6bfb407ec5fe8ba48527ef3f43 100644 (file)
@@ -1176,7 +1176,7 @@ lstcon_rpc_pinger(void *arg)
        srpc_debug_reqst_t *drq;
        lstcon_ndlink_t *ndl;
        lstcon_node_t *nd;
-       time_t intv;
+       int intv;
        int count = 0;
        int rc;
 
@@ -1191,8 +1191,8 @@ lstcon_rpc_pinger(void *arg)
        }
 
        if (!console_session.ses_expired &&
-           get_seconds() - console_session.ses_laststamp >
-           (time_t)console_session.ses_timeout)
+           ktime_get_real_seconds() - console_session.ses_laststamp >
+           (time64_t)console_session.ses_timeout)
                console_session.ses_expired = 1;
 
        trans = console_session.ses_ping;
@@ -1248,9 +1248,8 @@ lstcon_rpc_pinger(void *arg)
                if (nd->nd_state != LST_NODE_ACTIVE)
                        continue;
 
-               intv = cfs_duration_sec(cfs_time_sub(cfs_time_current(),
-                                                    nd->nd_stamp));
-               if (intv < (time_t)nd->nd_timeout / 2)
+               intv = (jiffies - nd->nd_stamp) / HZ;
+               if (intv < nd->nd_timeout / 2)
                        continue;
 
                rc = lstcon_rpc_init(nd, SRPC_SERVICE_DEBUG,
@@ -1278,7 +1277,7 @@ lstcon_rpc_pinger(void *arg)
 
        CDEBUG(D_NET, "Ping %d nodes in session\n", count);
 
-       ptimer->stt_expires = (unsigned long)(get_seconds() + LST_PING_INTERVAL);
+       ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
        stt_add_timer(ptimer);
 
        mutex_unlock(&console_session.ses_mutex);
@@ -1301,7 +1300,7 @@ lstcon_rpc_pinger_start(void)
        }
 
        ptimer = &console_session.ses_ping_timer;
-       ptimer->stt_expires = (unsigned long)(get_seconds() + LST_PING_INTERVAL);
+       ptimer->stt_expires = ktime_get_real_seconds() + LST_PING_INTERVAL;
 
        stt_add_timer(ptimer);
 
index 5c624e19eaa17501f518cf7f2696be2f711edc5c..024aaee76b7f805860b2d664839f92dc394413b8 100644 (file)
@@ -2004,7 +2004,7 @@ lstcon_console_init(void)
        console_session.ses_expired       = 0;
        console_session.ses_feats_updated = 0;
        console_session.ses_features      = LST_FEATS_MASK;
-       console_session.ses_laststamp     = get_seconds();
+       console_session.ses_laststamp     = ktime_get_real_seconds();
 
        mutex_init(&console_session.ses_mutex);
 
index cdce2dd6be7c4b8809a0554e080d05df1d69245b..acd131218dd9dbce581523b201d891915e70418d 100644 (file)
@@ -142,7 +142,7 @@ typedef struct {
        int                 ses_key;          /* local session key */
        int                 ses_state;        /* state of session */
        int                 ses_timeout;      /* timeout in seconds */
-       time_t              ses_laststamp;    /* last operation stamp (seconds)
+       time64_t            ses_laststamp;    /* last operation stamp (seconds)
                                               */
        unsigned            ses_features;     /* tests features of the session
                                               */
index c448037a3c9f3bdddde05e7f8342544db1ae69d5..177beaf496c4daf8795326f7f28838a6e0cc93a2 100644 (file)
@@ -170,8 +170,7 @@ sfw_add_session_timer(void)
        LASSERT(!sn->sn_timer_active);
 
        sn->sn_timer_active = 1;
-       timer->stt_expires = cfs_time_add(sn->sn_timeout,
-                                         get_seconds());
+       timer->stt_expires = ktime_get_real_seconds() + sn->sn_timeout;
        stt_add_timer(timer);
        return;
 }
index 6ae133138b17976ace3a7e9998b6bbb8c7ad6d9d..9fc3ce33ec7be64d40da1e3157931d520d158148 100644 (file)
@@ -565,7 +565,7 @@ srpc_add_buffer(struct swi_workitem *wi)
        }
 
        if (rc != 0) {
-               scd->scd_buf_err_stamp = get_seconds();
+               scd->scd_buf_err_stamp = ktime_get_real_seconds();
                scd->scd_buf_err = rc;
 
                LASSERT(scd->scd_buf_posting > 0);
@@ -1100,8 +1100,7 @@ srpc_add_client_rpc_timer(srpc_client_rpc_t *rpc)
        INIT_LIST_HEAD(&timer->stt_list);
        timer->stt_data    = rpc;
        timer->stt_func    = srpc_client_rpc_expired;
-       timer->stt_expires = cfs_time_add(rpc->crpc_timeout,
-                                         get_seconds());
+       timer->stt_expires = ktime_get_real_seconds() + rpc->crpc_timeout;
        stt_add_timer(timer);
        return;
 }
@@ -1488,7 +1487,7 @@ srpc_lnet_ev_handler(lnet_event_t *ev)
                }
 
                if (scd->scd_buf_err_stamp != 0 &&
-                   scd->scd_buf_err_stamp < get_seconds()) {
+                   scd->scd_buf_err_stamp < ktime_get_real_seconds()) {
                        /* re-enable adding buffer */
                        scd->scd_buf_err_stamp = 0;
                        scd->scd_buf_err = 0;
@@ -1593,7 +1592,7 @@ srpc_startup(void)
        /* 1 second pause to avoid timestamp reuse */
        set_current_state(TASK_UNINTERRUPTIBLE);
        schedule_timeout(cfs_time_seconds(1));
-       srpc_data.rpc_matchbits = ((__u64) get_seconds()) << 48;
+       srpc_data.rpc_matchbits = ((__u64)ktime_get_real_seconds()) << 48;
 
        srpc_data.rpc_state = SRPC_STATE_NONE;
 
index 160d68ce6ffdcc719afe25e5c0cabf04aab94045..48322539a3a3e3ebcf63be87738936036e0961d0 100644 (file)
@@ -279,7 +279,7 @@ struct srpc_service_cd {
        /** error code for scd_buf_wi */
        int                     scd_buf_err;
        /** timestamp for scd_buf_err */
-       unsigned long           scd_buf_err_stamp;
+       time64_t                scd_buf_err_stamp;
        /** total # request buffers */
        int                     scd_buf_total;
        /** # posted request buffers */
index 6133b54f4a8204d4c3c036b5e110b5904da069d4..ebd5f79126c97d0b5be3c7dad775cc2d713309e3 100644 (file)
@@ -78,13 +78,13 @@ stt_add_timer(stt_timer_t *timer)
        LASSERT(!stt_data.stt_shuttingdown);
        LASSERT(timer->stt_func != NULL);
        LASSERT(list_empty(&timer->stt_list));
-       LASSERT(cfs_time_after(timer->stt_expires, get_seconds()));
+       LASSERT(timer->stt_expires > ktime_get_real_seconds());
 
        /* a simple insertion sort */
        list_for_each_prev(pos, STTIMER_SLOT(timer->stt_expires)) {
                stt_timer_t *old = list_entry(pos, stt_timer_t, stt_list);
 
-               if (cfs_time_aftereq(timer->stt_expires, old->stt_expires))
+               if (timer->stt_expires >= old->stt_expires)
                        break;
        }
        list_add(&timer->stt_list, pos);
@@ -122,7 +122,7 @@ stt_del_timer(stt_timer_t *timer)
 
 /* called with stt_data.stt_lock held */
 static int
-stt_expire_list(struct list_head *slot, unsigned long now)
+stt_expire_list(struct list_head *slot, time64_t now)
 {
        int expired = 0;
        stt_timer_t *timer;
@@ -130,7 +130,7 @@ stt_expire_list(struct list_head *slot, unsigned long now)
        while (!list_empty(slot)) {
                timer = list_entry(slot->next, stt_timer_t, stt_list);
 
-               if (cfs_time_after(timer->stt_expires, now))
+               if (timer->stt_expires > now)
                        break;
 
                list_del_init(&timer->stt_list);
@@ -149,10 +149,10 @@ static int
 stt_check_timers(unsigned long *last)
 {
        int expired = 0;
-       unsigned long now;
+       time64_t now;
        unsigned long this_slot;
 
-       now = get_seconds();
+       now = ktime_get_real_seconds();
        this_slot = now & STTIMER_SLOTTIMEMASK;
 
        spin_lock(&stt_data.stt_lock);
@@ -212,7 +212,7 @@ stt_startup(void)
        int i;
 
        stt_data.stt_shuttingdown = 0;
-       stt_data.stt_prev_slot = get_seconds() & STTIMER_SLOTTIMEMASK;
+       stt_data.stt_prev_slot = ktime_get_real_seconds() & STTIMER_SLOTTIMEMASK;
 
        spin_lock_init(&stt_data.stt_lock);
        for (i = 0; i < STTIMER_NSLOTS; i++)
index 2a8803d89de46345d1499c1cb3337fe7a5430bf1..03e2ee294c1c3cf3122b3a1810d0df0cdf335d46 100644 (file)
@@ -40,7 +40,7 @@
 
 typedef struct {
        struct list_head stt_list;
-       unsigned long    stt_expires;
+       time64_t         stt_expires;
        void             (*stt_func) (void *);
        void             *stt_data;
 } stt_timer_t;