rand: fix truncated rand_seed on Windows
authorMing-Hung Tsai <mingnus@gmail.com>
Wed, 17 Apr 2019 04:25:10 +0000 (12:25 +0800)
committerMing-Hung Tsai <mingnus@gmail.com>
Wed, 17 Apr 2019 07:34:19 +0000 (15:34 +0800)
The long data type is 32-bit on LLP64 platforms

filesetup.c
fio.h
init.c
lib/lfsr.c
lib/lfsr.h
lib/rand.c
lib/rand.h
os/os-windows.h
os/os.h
verify.c
verify.h

index aa1a39455c1ee12285f795d668780ca8f7e8bceb..47c889a0bfe87a4d77285a8bff93b48e01177b15 100644 (file)
@@ -1287,7 +1287,7 @@ bool init_random_map(struct thread_data *td)
                        return false;
 
                if (td->o.random_generator == FIO_RAND_GEN_LFSR) {
                        return false;
 
                if (td->o.random_generator == FIO_RAND_GEN_LFSR) {
-                       unsigned long seed;
+                       uint64_t seed;
 
                        seed = td->rand_seeds[FIO_RAND_BLOCK_OFF];
 
 
                        seed = td->rand_seeds[FIO_RAND_BLOCK_OFF];
 
diff --git a/fio.h b/fio.h
index b3ba5db2e95ac9e16cd0633bc8912b125c08e333..2103151d9b42b3b318cb16d4e3519bc6ed354da1 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -245,7 +245,7 @@ struct thread_data {
        void *iolog_buf;
        FILE *iolog_f;
 
        void *iolog_buf;
        FILE *iolog_f;
 
-       unsigned long rand_seeds[FIO_RAND_NR_OFFS];
+       uint64_t rand_seeds[FIO_RAND_NR_OFFS];
 
        struct frand_state bsrange_state[DDIR_RWDIR_CNT];
        struct frand_state verify_state;
 
        struct frand_state bsrange_state[DDIR_RWDIR_CNT];
        struct frand_state verify_state;
diff --git a/init.c b/init.c
index e6378715b2fe4d42b882da45bc0c43ac44dcba66..738342799c5cc391494b43d3de8433939698cb35 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1217,7 +1217,7 @@ static void init_flags(struct thread_data *td)
 
 static int setup_random_seeds(struct thread_data *td)
 {
 
 static int setup_random_seeds(struct thread_data *td)
 {
-       unsigned long seed;
+       uint64_t seed;
        unsigned int i;
 
        if (!td->o.rand_repeatable && !fio_option_is_set(&td->o, rand_seed)) {
        unsigned int i;
 
        if (!td->o.rand_repeatable && !fio_option_is_set(&td->o, rand_seed)) {
index 32fbec566432d300f65b028e1534cd2a435898c6..1ef6ebbf1a22d39b6a4ff86d936bfebb08e32f96 100644 (file)
@@ -232,7 +232,7 @@ static int prepare_spin(struct fio_lfsr *fl, unsigned int spin)
        return 0;
 }
 
        return 0;
 }
 
-int lfsr_reset(struct fio_lfsr *fl, unsigned long seed)
+int lfsr_reset(struct fio_lfsr *fl, uint64_t seed)
 {
        uint64_t bitmask = (fl->cached_bit << 1) - 1;
 
 {
        uint64_t bitmask = (fl->cached_bit << 1) - 1;
 
@@ -246,8 +246,8 @@ int lfsr_reset(struct fio_lfsr *fl, unsigned long seed)
        return 0;
 }
 
        return 0;
 }
 
-int lfsr_init(struct fio_lfsr *fl, uint64_t nums, unsigned long seed,
-               unsigned int spin)
+int lfsr_init(struct fio_lfsr *fl, uint64_t nums, uint64_t seed,
+             unsigned int spin)
 {
        uint8_t *taps;
 
 {
        uint8_t *taps;
 
index c2d55693e89aa4869eec1280ea1e431cc039689c..95bc07fd57da905b150f893926aee9cbc92ef1be 100644 (file)
@@ -24,7 +24,7 @@ struct fio_lfsr {
 
 int lfsr_next(struct fio_lfsr *fl, uint64_t *off);
 int lfsr_init(struct fio_lfsr *fl, uint64_t size,
 
 int lfsr_next(struct fio_lfsr *fl, uint64_t *off);
 int lfsr_init(struct fio_lfsr *fl, uint64_t size,
-               unsigned long seed, unsigned int spin);
-int lfsr_reset(struct fio_lfsr *fl, unsigned long seed);
+             uint64_t seed, unsigned int spin);
+int lfsr_reset(struct fio_lfsr *fl, uint64_t seed);
 
 #endif
 
 #endif
index f18bd8d84e9cf021cd49a8df3dc931f47d7f35e2..69acb06c14410296f959da96f27fe842f57eede1 100644 (file)
@@ -95,7 +95,7 @@ void init_rand_seed(struct frand_state *state, unsigned int seed, bool use64)
                __init_rand64(&state->state64, seed);
 }
 
                __init_rand64(&state->state64, seed);
 }
 
-void __fill_random_buf(void *buf, unsigned int len, unsigned long seed)
+void __fill_random_buf(void *buf, unsigned int len, uint64_t seed)
 {
        void *ptr = buf;
 
 {
        void *ptr = buf;
 
@@ -122,10 +122,10 @@ void __fill_random_buf(void *buf, unsigned int len, unsigned long seed)
        }
 }
 
        }
 }
 
-unsigned long fill_random_buf(struct frand_state *fs, void *buf,
-                             unsigned int len)
+uint64_t fill_random_buf(struct frand_state *fs, void *buf,
+                        unsigned int len)
 {
 {
-       unsigned long r = __rand(fs);
+       uint64_t r = __rand(fs);
 
        if (sizeof(int) != sizeof(long *))
                r *= (unsigned long) __rand(fs);
 
        if (sizeof(int) != sizeof(long *))
                r *= (unsigned long) __rand(fs);
@@ -134,7 +134,7 @@ unsigned long fill_random_buf(struct frand_state *fs, void *buf,
        return r;
 }
 
        return r;
 }
 
-void __fill_random_buf_percentage(unsigned long seed, void *buf,
+void __fill_random_buf_percentage(uint64_t seed, void *buf,
                                  unsigned int percentage,
                                  unsigned int segment, unsigned int len,
                                  char *pattern, unsigned int pbytes)
                                  unsigned int percentage,
                                  unsigned int segment, unsigned int len,
                                  char *pattern, unsigned int pbytes)
@@ -183,12 +183,12 @@ void __fill_random_buf_percentage(unsigned long seed, void *buf,
        }
 }
 
        }
 }
 
-unsigned long fill_random_buf_percentage(struct frand_state *fs, void *buf,
-                                        unsigned int percentage,
-                                        unsigned int segment, unsigned int len,
-                                        char *pattern, unsigned int pbytes)
+uint64_t fill_random_buf_percentage(struct frand_state *fs, void *buf,
+                                   unsigned int percentage,
+                                   unsigned int segment, unsigned int len,
+                                   char *pattern, unsigned int pbytes)
 {
 {
-       unsigned long r = __rand(fs);
+       uint64_t r = __rand(fs);
 
        if (sizeof(int) != sizeof(long *))
                r *= (unsigned long) __rand(fs);
 
        if (sizeof(int) != sizeof(long *))
                r *= (unsigned long) __rand(fs);
index 1676cf98ed567653cded97eaf00a1beabe808b58..95d4f6d4966d88a60700a09fba7a6487c032abd5 100644 (file)
@@ -150,9 +150,9 @@ static inline uint64_t rand_between(struct frand_state *state, uint64_t start,
 
 extern void init_rand(struct frand_state *, bool);
 extern void init_rand_seed(struct frand_state *, unsigned int seed, bool);
 
 extern void init_rand(struct frand_state *, bool);
 extern void init_rand_seed(struct frand_state *, unsigned int seed, bool);
-extern void __fill_random_buf(void *buf, unsigned int len, unsigned long seed);
-extern unsigned long fill_random_buf(struct frand_state *, void *buf, unsigned int len);
-extern void __fill_random_buf_percentage(unsigned long, void *, unsigned int, unsigned int, unsigned int, char *, unsigned int);
-extern unsigned long fill_random_buf_percentage(struct frand_state *, void *, unsigned int, unsigned int, unsigned int, char *, unsigned int);
+extern void __fill_random_buf(void *buf, unsigned int len, uint64_t seed);
+extern uint64_t fill_random_buf(struct frand_state *, void *buf, unsigned int len);
+extern void __fill_random_buf_percentage(uint64_t, void *, unsigned int, unsigned int, unsigned int, char *, unsigned int);
+extern uint64_t fill_random_buf_percentage(struct frand_state *, void *, unsigned int, unsigned int, unsigned int, char *, unsigned int);
 
 #endif
 
 #endif
index ef955dc36f4fd18fe1cab5f7ffc38da750e1352b..dc958f5c17189465310a48fb2a1ff28bcc3b6581 100644 (file)
@@ -167,7 +167,7 @@ static inline int gettid(void)
        return GetCurrentThreadId();
 }
 
        return GetCurrentThreadId();
 }
 
-static inline int init_random_seeds(unsigned long *rand_seeds, int size)
+static inline int init_random_seeds(uint64_t *rand_seeds, int size)
 {
        HCRYPTPROV hCryptProv;
 
 {
        HCRYPTPROV hCryptProv;
 
diff --git a/os/os.h b/os/os.h
index 36b6bb2ed5662671d3116cee533ef81e9240688b..756ece4b1916874da24ab18441406ad5a84e6de9 100644 (file)
--- a/os/os.h
+++ b/os/os.h
@@ -323,7 +323,7 @@ static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
 #endif
 
 #ifdef FIO_USE_GENERIC_INIT_RANDOM_STATE
 #endif
 
 #ifdef FIO_USE_GENERIC_INIT_RANDOM_STATE
-static inline int init_random_seeds(unsigned long *rand_seeds, int size)
+static inline int init_random_seeds(uint64_t *rand_seeds, int size)
 {
        int fd;
 
 {
        int fd;
 
index da429e793a86e8f0198a8cffaa5bf8a964898fcc..f79ab43aab6b97b0721f52485fad31053e8d6ca9 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -39,14 +39,14 @@ void fill_buffer_pattern(struct thread_data *td, void *p, unsigned int len)
        (void)cpy_pattern(td->o.buffer_pattern, td->o.buffer_pattern_bytes, p, len);
 }
 
        (void)cpy_pattern(td->o.buffer_pattern, td->o.buffer_pattern_bytes, p, len);
 }
 
-static void __fill_buffer(struct thread_options *o, unsigned long seed, void *p,
+static void __fill_buffer(struct thread_options *o, uint64_t seed, void *p,
                          unsigned int len)
 {
        __fill_random_buf_percentage(seed, p, o->compress_percentage, len, len, o->buffer_pattern, o->buffer_pattern_bytes);
 }
 
                          unsigned int len)
 {
        __fill_random_buf_percentage(seed, p, o->compress_percentage, len, len, o->buffer_pattern, o->buffer_pattern_bytes);
 }
 
-static unsigned long fill_buffer(struct thread_data *td, void *p,
-                                unsigned int len)
+static uint64_t fill_buffer(struct thread_data *td, void *p,
+                           unsigned int len)
 {
        struct frand_state *fs = &td->verify_state;
        struct thread_options *o = &td->o;
 {
        struct frand_state *fs = &td->verify_state;
        struct thread_options *o = &td->o;
@@ -55,7 +55,7 @@ static unsigned long fill_buffer(struct thread_data *td, void *p,
 }
 
 void fill_verify_pattern(struct thread_data *td, void *p, unsigned int len,
 }
 
 void fill_verify_pattern(struct thread_data *td, void *p, unsigned int len,
-                        struct io_u *io_u, unsigned long seed, int use_seed)
+                        struct io_u *io_u, uint64_t seed, int use_seed)
 {
        struct thread_options *o = &td->o;
 
 {
        struct thread_options *o = &td->o;
 
@@ -100,7 +100,7 @@ static unsigned int get_hdr_inc(struct thread_data *td, struct io_u *io_u)
 }
 
 static void fill_pattern_headers(struct thread_data *td, struct io_u *io_u,
 }
 
 static void fill_pattern_headers(struct thread_data *td, struct io_u *io_u,
-                                unsigned long seed, int use_seed)
+                                uint64_t seed, int use_seed)
 {
        unsigned int hdr_inc, header_num;
        struct verify_header *hdr;
 {
        unsigned int hdr_inc, header_num;
        struct verify_header *hdr;
index 64121a51af97d68e75fefe12dc178f3b3218b0ce..539e6f6cf5c1accf7a88af9cd9d6287e8fb09163 100644 (file)
--- a/verify.h
+++ b/verify.h
@@ -97,7 +97,7 @@ extern void populate_verify_io_u(struct thread_data *, struct io_u *);
 extern int __must_check get_next_verify(struct thread_data *td, struct io_u *);
 extern int __must_check verify_io_u(struct thread_data *, struct io_u **);
 extern int verify_io_u_async(struct thread_data *, struct io_u **);
 extern int __must_check get_next_verify(struct thread_data *td, struct io_u *);
 extern int __must_check verify_io_u(struct thread_data *, struct io_u **);
 extern int verify_io_u_async(struct thread_data *, struct io_u **);
-extern void fill_verify_pattern(struct thread_data *td, void *p, unsigned int len, struct io_u *io_u, unsigned long seed, int use_seed);
+extern void fill_verify_pattern(struct thread_data *td, void *p, unsigned int len, struct io_u *io_u, uint64_t seed, int use_seed);
 extern void fill_buffer_pattern(struct thread_data *td, void *p, unsigned int len);
 extern void fio_verify_init(struct thread_data *td);
 
 extern void fill_buffer_pattern(struct thread_data *td, void *p, unsigned int len);
 extern void fio_verify_init(struct thread_data *td);