Fix bug with openfiles
authorJens Axboe <jens.axboe@oracle.com>
Wed, 4 Mar 2009 08:39:47 +0000 (09:39 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Wed, 4 Mar 2009 08:39:47 +0000 (09:39 +0100)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
io_u.c

diff --git a/io_u.c b/io_u.c
index efe838998d7a0d2dccecefab2e04c0f4ea430673..e4671e42ac741557006ce7056dd863508b60280c 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -628,6 +628,7 @@ static struct fio_file *get_next_file_rand(struct thread_data *td, int goodf,
 
        do {
                long r = os_random_long(&td->next_file_state);
 
        do {
                long r = os_random_long(&td->next_file_state);
+               int opened = 0;
 
                fno = (unsigned int) ((double) td->o.nr_files
                        * (r / (OS_RAND_MAX + 1.0)));
 
                fno = (unsigned int) ((double) td->o.nr_files
                        * (r / (OS_RAND_MAX + 1.0)));
@@ -635,10 +636,21 @@ static struct fio_file *get_next_file_rand(struct thread_data *td, int goodf,
                if (f->flags & FIO_FILE_DONE)
                        continue;
 
                if (f->flags & FIO_FILE_DONE)
                        continue;
 
+               if (!(f->flags & FIO_FILE_OPEN)) {
+                       int err;
+
+                       err = td_io_open_file(td, f);
+                       if (err)
+                               continue;
+                       opened = 1;
+               }
+
                if ((!goodf || (f->flags & goodf)) && !(f->flags & badf)) {
                        dprint(FD_FILE, "get_next_file_rand: %p\n", f);
                        return f;
                }
                if ((!goodf || (f->flags & goodf)) && !(f->flags & badf)) {
                        dprint(FD_FILE, "get_next_file_rand: %p\n", f);
                        return f;
                }
+               if (opened)
+                       td_io_close_file(td, f);
        } while (1);
 }
 
        } while (1);
 }
 
@@ -652,20 +664,35 @@ static struct fio_file *get_next_file_rr(struct thread_data *td, int goodf,
        struct fio_file *f;
 
        do {
        struct fio_file *f;
 
        do {
+               int opened = 0;
+
                f = td->files[td->next_file];
 
                td->next_file++;
                if (td->next_file >= td->o.nr_files)
                        td->next_file = 0;
 
                f = td->files[td->next_file];
 
                td->next_file++;
                if (td->next_file >= td->o.nr_files)
                        td->next_file = 0;
 
+               dprint(FD_FILE, "trying file %s %x\n", f->file_name, f->flags);
                if (f->flags & FIO_FILE_DONE) {
                        f = NULL;
                        continue;
                }
 
                if (f->flags & FIO_FILE_DONE) {
                        f = NULL;
                        continue;
                }
 
+               if (!(f->flags & FIO_FILE_OPEN)) {
+                       int err;
+
+                       err = td_io_open_file(td, f);
+                       if (err)
+                               continue;
+                       opened = 1;
+               }
+
                if ((!goodf || (f->flags & goodf)) && !(f->flags & badf))
                        break;
 
                if ((!goodf || (f->flags & goodf)) && !(f->flags & badf))
                        break;
 
+               if (opened)
+                       td_io_close_file(td, f);
+
                f = NULL;
        } while (td->next_file != old_next_file);
 
                f = NULL;
        } while (td->next_file != old_next_file);
 
@@ -753,11 +780,11 @@ set_file:
                 * td_io_close() does a put_file() as well, so no need to
                 * do that here.
                 */
                 * td_io_close() does a put_file() as well, so no need to
                 * do that here.
                 */
-               dprint(FD_FILE, "%s: is done\n", f->file_name);
                io_u->file = NULL;
                td_io_close_file(td, f);
                f->flags |= FIO_FILE_DONE;
                td->nr_done_files++;
                io_u->file = NULL;
                td_io_close_file(td, f);
                f->flags |= FIO_FILE_DONE;
                td->nr_done_files++;
+               dprint(FD_FILE, "%s: is done (%d of %d)\n", f->file_name, td->nr_done_files, td->o.nr_files);
 
                /*
                 * probably not the right place to do this, but see
 
                /*
                 * probably not the right place to do this, but see