Add pre_read option

With this option set, files will be pre-read into memory before
starting the given IO operation(s).

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/filesetup.c b/filesetup.c
index 04d7b98..2858018 100644
--- a/filesetup.c
+++ b/filesetup.c
@@ -119,6 +119,39 @@
 	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 @@
 	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;