Fix loop with multiple files
authorJens Axboe <jens.axboe@oracle.com>
Thu, 29 Mar 2007 09:15:06 +0000 (11:15 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 29 Mar 2007 09:15:06 +0000 (11:15 +0200)
The random lookup would loop infinitely, if no files were
open. So check for that and check for number of files
done.

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

index e9dc72db740669952d4c8d4fb24dea38855fdfeb..aad0720f97e9429248f31fd439e2a6e5d1098170 100644 (file)
@@ -523,6 +523,7 @@ void put_file(struct thread_data *td, struct fio_file *f)
 
        if (td->io_ops->close_file)
                td->io_ops->close_file(td, f);
+
        td->nr_open_files--;
        f->flags &= ~FIO_FILE_OPEN;
 }
diff --git a/fio.h b/fio.h
index 92e6a88d66881378eb4d6d407e158775fa11e097..07b40ff47780a17e6ed3b0248e2e3c708e91b547 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -449,6 +449,7 @@ struct thread_data {
        struct fio_file *files;
        unsigned int files_index;
        unsigned int nr_open_files;
+       unsigned int nr_done_files;
        unsigned int nr_normal_files;
        union {
                unsigned int next_file;
diff --git a/io_u.c b/io_u.c
index 17e188ad022ee05f3bb6dceedb153a24027b2fb3..b48c99dad3ed4a3eb25650de53f59203463af850 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -452,7 +452,7 @@ static struct fio_file *get_next_file(struct thread_data *td)
 
        assert(td->o.nr_files <= td->files_index);
 
-       if (!td->nr_open_files)
+       if (!td->nr_open_files || td->nr_done_files >= td->o.nr_files)
                return NULL;
 
        f = td->file_service_file;
@@ -473,6 +473,9 @@ static struct fio_file *find_next_new_file(struct thread_data *td)
 {
        struct fio_file *f;
 
+       if (!td->nr_open_files || td->nr_done_files >= td->o.nr_files)
+               return NULL;
+
        if (td->o.file_service_type == FIO_FSERVICE_RR)
                f = get_next_file_rr(td, 0, FIO_FILE_OPEN);
        else
@@ -548,6 +551,7 @@ set_file:
                io_u->file = NULL;
                td_io_close_file(td, f);
                f->flags |= FIO_FILE_DONE;
+               td->nr_done_files++;
 
                /*
                 * probably not the right place to do this, but see