Fix bug with file references
authorJens Axboe <jens.axboe@oracle.com>
Thu, 26 Apr 2007 08:21:15 +0000 (10:21 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 26 Apr 2007 08:21:15 +0000 (10:21 +0200)
This could cause premature exit of fio with an error at the end of
the run.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
io_u.c
ioengines.c

diff --git a/io_u.c b/io_u.c
index 99f07288376f5cd7f668f169cdfb24f130091299..7fe5242f51287b4bd72102400686eb6f1fcd31f7 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -265,6 +265,9 @@ 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;
 
        assert((io_u->flags & IO_U_F_FREE) == 0);
        io_u->flags |= IO_U_F_FREE;
 
+       if (io_u->file)
+               put_file(td, io_u->file);
+
        io_u->file = NULL;
        list_del(&io_u->list);
        list_add(&io_u->list, &td->io_u_freelist);
        io_u->file = NULL;
        list_del(&io_u->list);
        list_add(&io_u->list, &td->io_u_freelist);
@@ -540,12 +543,14 @@ struct io_u *get_io_u(struct thread_data *td)
 
 set_file:
                io_u->file = f;
 
 set_file:
                io_u->file = f;
+               get_file(f);
 
                if (!fill_io_u(td, io_u))
                        break;
 
                /*
 
                if (!fill_io_u(td, io_u))
                        break;
 
                /*
-                * No more to do for this file, close it
+                * td_io_close() does a put_file() as well, so no need to
+                * do that here.
                 */
                io_u->file = NULL;
                td_io_close_file(td, f);
                 */
                io_u->file = NULL;
                td_io_close_file(td, f);
@@ -627,8 +632,6 @@ static void io_completed(struct thread_data *td, struct io_u *io_u,
        assert(io_u->flags & IO_U_F_FLIGHT);
        io_u->flags &= ~IO_U_F_FLIGHT;
 
        assert(io_u->flags & IO_U_F_FLIGHT);
        io_u->flags &= ~IO_U_F_FLIGHT;
 
-       put_file(td, io_u->file);
-
        if (io_u->ddir == DDIR_SYNC) {
                td->last_was_sync = 1;
                return;
        if (io_u->ddir == DDIR_SYNC) {
                td->last_was_sync = 1;
                return;
index 34ae91671a4348c43bacdf9f7eddc2f5e81f020d..28cdfd49b00cd24915f39c7b117e3d2e96e9e31f 100644 (file)
@@ -207,9 +207,6 @@ int td_io_queue(struct thread_data *td, struct io_u *io_u)
 
        ret = td->io_ops->queue(td, io_u);
 
 
        ret = td->io_ops->queue(td, io_u);
 
-       if (ret == FIO_Q_QUEUED || ret == FIO_Q_COMPLETED)
-               get_file(io_u->file);
-
        if (ret == FIO_Q_QUEUED) {
                int r;
 
        if (ret == FIO_Q_QUEUED) {
                int r;