Fix bad interaction with file open/close and queuing
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index 0ba484169d31d024a041ddfc43b3baedc4b0f193..55ac82659cc81670640ab04941849fb7d52772f2 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -83,7 +83,7 @@ static inline unsigned long long last_block(struct thread_data *td,
        if (!max_blocks)
                return 0;
 
-       return max_blocks - 1;
+       return max_blocks;
 }
 
 /*
@@ -188,7 +188,14 @@ static int get_next_offset(struct thread_data *td, struct io_u *io_u)
                        b = (f->last_pos - f->file_offset) / td->o.min_bs[ddir];
        }
 
-       io_u->offset = (b * td->o.min_bs[ddir]) + f->file_offset;
+       io_u->offset = b * td->o.min_bs[ddir];
+       if (io_u->offset >= f->io_size) {
+               dprint(FD_IO, "get_next_offset: offset %llu >= io_size %llu\n",
+                                       io_u->offset, f->io_size);
+               return 1;
+       }
+
+       io_u->offset += f->file_offset;
        if (io_u->offset >= f->real_file_size) {
                dprint(FD_IO, "get_next_offset: offset %llu >= size %llu\n",
                                        io_u->offset, f->real_file_size);
@@ -410,14 +417,10 @@ out:
        return 0;
 }
 
-void io_u_mark_depth(struct thread_data *td, struct io_u *io_u,
-                    unsigned int nr)
+void io_u_mark_depth(struct thread_data *td, unsigned int nr)
 {
        int index = 0;
 
-       if (io_u->ddir == DDIR_SYNC)
-               return;
-
        switch (td->cur_depth) {
        default:
                index = 6;
@@ -441,7 +444,6 @@ void io_u_mark_depth(struct thread_data *td, struct io_u *io_u,
        }
 
        td->ts.io_u_map[index] += nr;
-       td->ts.total_io_u[io_u->ddir] += nr;
 }
 
 static void io_u_mark_lat_usec(struct thread_data *td, unsigned long usec)
@@ -655,6 +657,16 @@ set_file:
                if (!fill_io_u(td, io_u))
                        break;
 
+               /*
+                * optimization to prevent close/open of the same file. This
+                * way we preserve queueing etc.
+                */
+               if (td->o.nr_files == 1 && td->o.time_based) {
+                       put_file(td, f);
+                       fio_file_reset(f);
+                       goto set_file;
+               }
+
                /*
                 * td_io_close() does a put_file() as well, so no need to
                 * do that here.