Fix bad interaction with file open/close and queuing
authorJens Axboe <jens.axboe@oracle.com>
Thu, 15 May 2008 08:19:46 +0000 (10:19 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 15 May 2008 08:19:46 +0000 (10:19 +0200)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
fio.h
io_u.c
ioengines.c

diff --git a/fio.h b/fio.h
index 5ee43e0..47b6d48 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -980,6 +980,12 @@ extern void close_ioengine(struct thread_data *);
        }       \
 } while (0)
 
+static inline void fio_file_reset(struct fio_file *f)
+{
+       f->last_free_lookup = 0;
+       f->last_pos = f->file_offset;
+}
+
 static inline void clear_error(struct thread_data *td)
 {
        td->error = 0;
diff --git a/io_u.c b/io_u.c
index 7f52a24..55ac826 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);
@@ -650,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.
index d3ee4b9..9e1c556 100644 (file)
@@ -327,8 +327,7 @@ int td_io_open_file(struct thread_data *td, struct fio_file *f)
                }
        }
 
-       f->last_free_lookup = 0;
-       f->last_pos = f->file_offset;
+       fio_file_reset(f);
        f->flags |= FIO_FILE_OPEN;
        f->flags &= ~FIO_FILE_CLOSING;