Ensure that lfsr_init() is always called
[fio.git] / filesetup.c
index c488eb471caa8a2d442c8cf58a1c203ff18309e7..b70bd45439e2fc59787230fcc0b263dc97bba48a 100644 (file)
@@ -13,6 +13,7 @@
 #include "filehash.h"
 #include "os/os.h"
 #include "hash.h"
+#include "lib/bitmap.h"
 
 #ifdef FIO_HAVE_LINUX_FALLOCATE
 #include <linux/falloc.h>
@@ -904,28 +905,26 @@ static int init_rand_distribution(struct thread_data *td)
 
 int init_random_map(struct thread_data *td)
 {
-       unsigned long long blocks, num_maps;
+       unsigned long long blocks;
        struct fio_file *f;
        unsigned int i;
 
        if (init_rand_distribution(td))
                return 0;
-       if (td->o.norandommap || !td_random(td))
+       if (!td_random(td))
                return 0;
 
        for_each_file(td, f, i) {
                blocks = (f->real_file_size + td->o.rw_min_bs - 1) /
                                (unsigned long long) td->o.rw_min_bs;
-               num_maps = (blocks + BLOCKS_PER_MAP - 1) /
-                               (unsigned long long) BLOCKS_PER_MAP;
-               if (num_maps == (unsigned long) num_maps) {
-                       f->file_map = smalloc(num_maps * sizeof(unsigned long));
-                       if (f->file_map) {
-                               f->num_maps = num_maps;
+               if (td->o.random_generator == FIO_RAND_GEN_LFSR) {
+                       if (!lfsr_init(&f->lfsr, blocks))
                                continue;
-                       }
-               } else
-                       f->file_map = NULL;
+               } else if (!td->o.norandommap) {
+                       f->io_bitmap = bitmap_new(blocks);
+                       if (f->io_bitmap)
+                               continue;
+               }
 
                if (!td->o.softrandommap) {
                        log_err("fio: failed allocating random map. If running"
@@ -937,7 +936,6 @@ int init_random_map(struct thread_data *td)
 
                log_info("fio: file %s failed allocating random map. Running "
                         "job without.\n", f->file_name);
-               f->num_maps = 0;
        }
 
        return 0;
@@ -974,8 +972,8 @@ void close_and_free_files(struct thread_data *td)
 
                sfree(f->file_name);
                f->file_name = NULL;
-               sfree(f->file_map);
-               f->file_map = NULL;
+               bitmap_free(f->io_bitmap);
+               f->io_bitmap = NULL;
                sfree(f);
        }