Add pre_read option
[fio.git] / filesetup.c
index 04d7b987085f00eb2e195e8a469d39adffede7b4..28580188c1e98fc56aeb73d3e465c6d7d63e1cc2 100644 (file)
@@ -119,6 +119,39 @@ err:
        return 1;
 }
 
+static int pre_read_file(struct thread_data *td, struct fio_file *f)
+{
+       int r;
+       unsigned long long left;
+       unsigned int bs;
+       char *b;
+
+       bs = td->o.max_bs[DDIR_READ];
+       b = malloc(bs);
+       memset(b, 0, bs);
+
+       lseek(f->fd, f->file_offset, SEEK_SET);
+       left = f->io_size;
+
+       while (left && !td->terminate) {
+               if (bs > left)
+                       bs = left;
+
+               r = read(f->fd, b, bs);
+
+               if (r == (int) bs) {
+                       left -= bs;
+                       continue;
+               } else {
+                       td_verror(td, EIO, "pre_read");
+                       break;
+               }
+       }
+
+       free(b);
+       return 0;
+}
+
 static unsigned long long get_rand_file_size(struct thread_data *td)
 {
        unsigned long long ret, sized;
@@ -572,6 +605,20 @@ err_offset:
        return 1;
 }
 
+int pre_read_files(struct thread_data *td)
+{
+       struct fio_file *f;
+       unsigned int i;
+
+       dprint(FD_FILE, "pre_read files\n");
+
+       for_each_file(td, f, i) {
+               pre_read_file(td, f);
+       }
+
+       return 1;
+}
+
 int init_random_map(struct thread_data *td)
 {
        unsigned long long blocks, num_maps;