Fix loop with multiple files
[fio.git] / io_u.c
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);
 
 
        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;
                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;
 
 {
        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
        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;
                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
 
                /*
                 * probably not the right place to do this, but see