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 5ee43e0a2f8ae495ba50b57699a87bbe15f01192..47b6d488e66eb7b4026d71933bbdb15a7359ed4d 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 7f52a243fbdbc8e2b12706c1f45c52716729a8ab..55ac82659cc81670640ab04941849fb7d52772f2 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 d3ee4b98e3dc3741c614ea366c2c21378c8405b8..9e1c55639a477db0031b9b8583aeb7b87deb73a5 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;