From: Arnd Bergmann Date: Tue, 25 Oct 2016 01:58:26 +0000 (-0400) Subject: LU-4423 libcfs: use 64-bit times for cfs_srand seed X-Git-Tag: 2.9.52~68 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=2d1be90507fc1f42f565d9e672c634b3855cb978 LU-4423 libcfs: use 64-bit times for cfs_srand seed Several functions in Lustre call cfs_srand with do_gettimeofday as the seed to get a pseudo-random number. There is no bug here, but changing it to use ktime_get_ts64() gets us closer to deprecating do_gettimeofday() and makes it slightly more random. Affected functions are: lnet_shuffle_seed, init_lustre_lite and class_handle_init Linux-commit: 1f4fc343c008981d3a91351c030e2c29f5cd1b1c Signed-off-by: Arnd Bergmann Change-Id: I86d156afd71456d7d5412ebb8a2e519367d4f81d Signed-off-by: Oleg Drokin Signed-off-by: Greg Kroah-Hartman Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/23351 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Frank Zago Reviewed-by: Dmitry Eremin Reviewed-by: Oleg Drokin --- diff --git a/lnet/lnet/router.c b/lnet/lnet/router.c index 6d15c6c..f8a0788 100644 --- a/lnet/lnet/router.c +++ b/lnet/lnet/router.c @@ -239,7 +239,7 @@ static void lnet_shuffle_seed(void) static int seeded; __u32 lnd_type; __u32 seed[2]; - struct timeval tv; + struct timespec64 ts; lnet_ni_t *ni; struct list_head *tmp; @@ -258,8 +258,8 @@ static void lnet_shuffle_seed(void) seed[0] ^= (LNET_NIDADDR(ni->ni_nid) | lnd_type); } - do_gettimeofday(&tv); - cfs_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]); + ktime_get_ts64(&ts); + cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]); seeded = 1; return; } diff --git a/lustre/llite/super25.c b/lustre/llite/super25.c index c2ebb76..3b9f748 100644 --- a/lustre/llite/super25.c +++ b/lustre/llite/super25.c @@ -102,7 +102,7 @@ static int __init lustre_init(void) { struct proc_dir_entry *entry; lnet_process_id_t lnet_id; - struct timeval tv; + struct timespec64 ts; int i, rc, seed[2]; CLASSERT(sizeof(LUSTRE_VOLATILE_HDR) == LUSTRE_VOLATILE_HDR_LEN + 1); @@ -147,8 +147,8 @@ static int __init lustre_init(void) seed[0] ^= LNET_NIDADDR(lnet_id.nid); } - do_gettimeofday(&tv); - cfs_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]); + ktime_get_ts64(&ts); + cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]); rc = vvp_global_init(); if (rc != 0) diff --git a/lustre/obdclass/lustre_handles.c b/lustre/obdclass/lustre_handles.c index 2736695..dcdc4fa 100644 --- a/lustre/obdclass/lustre_handles.c +++ b/lustre/obdclass/lustre_handles.c @@ -198,7 +198,7 @@ EXPORT_SYMBOL(class_handle_free_cb); int class_handle_init(void) { struct handle_bucket *bucket; - struct timeval tv; + struct timespec64 ts; int seed[2]; LASSERT(handle_hash == NULL); @@ -216,8 +216,8 @@ int class_handle_init(void) /** bug 21430: add randomness to the initial base */ cfs_get_random_bytes(seed, sizeof(seed)); - do_gettimeofday(&tv); - cfs_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]); + ktime_get_ts64(&ts); + cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]); cfs_get_random_bytes(&handle_base, sizeof(handle_base)); LASSERT(handle_base != 0ULL);