Silence put_file() complaint
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index 7f52a243fbdbc8e2b12706c1f45c52716729a8ab..92cdd71701a9df3973eb4158b0a8fcb6bab4eed5 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -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);
@@ -650,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.