[PATCH 24/37] staging/lustre: use 64-bit time for selftest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxx>
---
 drivers/staging/lustre/lnet/selftest/brw_test.c  |  6 +++---
 drivers/staging/lustre/lnet/selftest/conctl.c    |  2 +-
 drivers/staging/lustre/lnet/selftest/conrpc.c    | 15 +++++++--------
 drivers/staging/lustre/lnet/selftest/console.c   |  2 +-
 drivers/staging/lustre/lnet/selftest/console.h   |  2 +-
 drivers/staging/lustre/lnet/selftest/framework.c |  3 +--
 drivers/staging/lustre/lnet/selftest/rpc.c       |  9 ++++-----
 drivers/staging/lustre/lnet/selftest/selftest.h  |  2 +-
 drivers/staging/lustre/lnet/selftest/timer.c     | 14 +++++++-------
 drivers/staging/lustre/lnet/selftest/timer.h     |  2 +-
 10 files changed, 27 insertions(+), 30 deletions(-)

diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
index de11f1bc8be7..0605c651f797 100644
--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
@@ -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--;
diff --git a/drivers/staging/lustre/lnet/selftest/conctl.c b/drivers/staging/lustre/lnet/selftest/conctl.c
index 1a7870e91f23..817396638652 100644
--- a/drivers/staging/lustre/lnet/selftest/conctl.c
+++ b/drivers/staging/lustre/lnet/selftest/conctl.c
@@ -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;
diff --git a/drivers/staging/lustre/lnet/selftest/conrpc.c b/drivers/staging/lustre/lnet/selftest/conrpc.c
index bf2968310516..b70680b8bdbe 100644
--- a/drivers/staging/lustre/lnet/selftest/conrpc.c
+++ b/drivers/staging/lustre/lnet/selftest/conrpc.c
@@ -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);
 
diff --git a/drivers/staging/lustre/lnet/selftest/console.c b/drivers/staging/lustre/lnet/selftest/console.c
index 5c624e19eaa1..024aaee76b7f 100644
--- a/drivers/staging/lustre/lnet/selftest/console.c
+++ b/drivers/staging/lustre/lnet/selftest/console.c
@@ -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);
 
diff --git a/drivers/staging/lustre/lnet/selftest/console.h b/drivers/staging/lustre/lnet/selftest/console.h
index cdce2dd6be7c..acd131218dd9 100644
--- a/drivers/staging/lustre/lnet/selftest/console.h
+++ b/drivers/staging/lustre/lnet/selftest/console.h
@@ -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
 					       */
diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
index c448037a3c9f..177beaf496c4 100644
--- a/drivers/staging/lustre/lnet/selftest/framework.c
+++ b/drivers/staging/lustre/lnet/selftest/framework.c
@@ -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;
 }
diff --git a/drivers/staging/lustre/lnet/selftest/rpc.c b/drivers/staging/lustre/lnet/selftest/rpc.c
index 6ae133138b17..5798a71ae30a 100644
--- a/drivers/staging/lustre/lnet/selftest/rpc.c
+++ b/drivers/staging/lustre/lnet/selftest/rpc.c
@@ -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;
 
diff --git a/drivers/staging/lustre/lnet/selftest/selftest.h b/drivers/staging/lustre/lnet/selftest/selftest.h
index 160d68ce6ffd..48322539a3a3 100644
--- a/drivers/staging/lustre/lnet/selftest/selftest.h
+++ b/drivers/staging/lustre/lnet/selftest/selftest.h
@@ -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 */
diff --git a/drivers/staging/lustre/lnet/selftest/timer.c b/drivers/staging/lustre/lnet/selftest/timer.c
index 6133b54f4a82..ebd5f79126c9 100644
--- a/drivers/staging/lustre/lnet/selftest/timer.c
+++ b/drivers/staging/lustre/lnet/selftest/timer.c
@@ -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++)
diff --git a/drivers/staging/lustre/lnet/selftest/timer.h b/drivers/staging/lustre/lnet/selftest/timer.h
index 2a8803d89de4..03e2ee294c1c 100644
--- a/drivers/staging/lustre/lnet/selftest/timer.h
+++ b/drivers/staging/lustre/lnet/selftest/timer.h
@@ -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;
-- 
2.1.0.rc2

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux