Silence put_file() complaint
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index 985c99b2bb7f1094ee28804bfcef060987cb3446..92cdd71701a9df3973eb4158b0a8fcb6bab4eed5 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);
@@ -312,17 +319,21 @@ static enum fio_ddir get_rw_ddir(struct thread_data *td)
                return DDIR_WRITE;
 }
 
+static void put_file_log(struct thread_data *td, struct fio_file *f)
+{
+       int ret = put_file(td, f);
+
+       if (ret)
+               td_verror(td, ret, "file close");
+}
+
 void put_io_u(struct thread_data *td, struct io_u *io_u)
 {
        assert((io_u->flags & IO_U_F_FREE) == 0);
        io_u->flags |= IO_U_F_FREE;
 
-       if (io_u->file) {
-               int ret = put_file(td, io_u->file);
-
-               if (ret)
-                       td_verror(td, ret, "file close");
-       }
+       if (io_u->file)
+               put_file_log(td, io_u->file);
 
        io_u->file = NULL;
        list_del(&io_u->list);
@@ -410,13 +421,10 @@ out:
        return 0;
 }
 
-void io_u_mark_depth(struct thread_data *td, struct io_u *io_u)
+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;
@@ -439,8 +447,7 @@ void io_u_mark_depth(struct thread_data *td, struct io_u *io_u)
                break;
        }
 
-       td->ts.io_u_map[index]++;
-       td->ts.total_io_u[io_u->ddir]++;
+       td->ts.io_u_map[index] += nr;
 }
 
 static void io_u_mark_lat_usec(struct thread_data *td, unsigned long usec)
@@ -654,6 +661,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_log(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.