- if (td->io_ops->data) {
- free(td->io_ops->data);
- td->io_ops->data = NULL;
+ int ret, flags;
+
+ ret = generic_open_file(td, f);
+ if (ret)
+ return ret;
+
+ /*
+ * for size checkup, don't mmap anything.
+ */
+ if (!f->io_size)
+ return 0;
+
+ if (td_rw(td))
+ flags = PROT_READ | PROT_WRITE;
+ else if (td_write(td)) {
+ flags = PROT_WRITE;
+
+ if (td->o.verify != VERIFY_NONE)
+ flags |= PROT_READ;
+ } else
+ flags = PROT_READ;
+
+ f->mmap = mmap(NULL, f->io_size, flags, MAP_SHARED, f->fd, f->file_offset);
+ if (f->mmap == MAP_FAILED) {
+ f->mmap = NULL;
+ td_verror(td, errno, "mmap");
+ goto err;
+ }
+
+ if (file_invalidate_cache(td, f))
+ goto err;
+
+ if (!td_random(td)) {
+ if (madvise(f->mmap, f->io_size, MADV_SEQUENTIAL) < 0) {
+ td_verror(td, errno, "madvise");
+ goto err;
+ }
+ } else {
+ if (madvise(f->mmap, f->io_size, MADV_RANDOM) < 0) {
+ td_verror(td, errno, "madvise");
+ goto err;
+ }