Don't require 'all' argument to --cmdhelp to dump all options
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index 426a5f8a38b49b1f2e7a1b18de199ddccf53a536..6df4b5eee80190187aa0015b11aca7da73e714b4 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -329,11 +329,12 @@ static void io_u_mark_latency(struct thread_data *td, unsigned long msec)
  */
 static struct fio_file *get_next_file_rand(struct thread_data *td)
 {
-       long r = os_random_long(&td->next_file_state);
        unsigned int fileno;
        struct fio_file *f;
 
        do {
+               long r = os_random_long(&td->next_file_state);
+
                fileno = (unsigned int) ((double) (td->nr_files - 1) * r / (RAND_MAX + 1.0));
                f = &td->files[fileno];
                if (f->fd != -1)
@@ -365,6 +366,17 @@ static struct fio_file *get_next_file_rr(struct thread_data *td)
        return f;
 }
 
+static struct fio_file *get_next_file(struct thread_data *td)
+{
+       if (!td->nr_open_files)
+               return NULL;
+
+       if (td->file_service_type == FIO_FSERVICE_RR)
+               return get_next_file_rr(td);
+       else
+               return get_next_file_rand(td);
+}
+
 struct io_u *__get_io_u(struct thread_data *td)
 {
        struct io_u *io_u = NULL;
@@ -413,23 +425,24 @@ struct io_u *get_io_u(struct thread_data *td)
        if (io_u->file)
                goto out;
 
-       if (td->file_service_type == FIO_FSERVICE_RR)
-               f = get_next_file_rr(td);
-       else
-               f = get_next_file_rand(td);
-
-       if (!f) {
-               put_io_u(td, io_u);
-               return NULL;
-       }
+       do {
+               f = get_next_file(td);
+               if (!f) {
+                       put_io_u(td, io_u);
+                       return NULL;
+               }
 
-       io_u->file = f;
+               io_u->file = f;
 
+               if (!fill_io_u(td, io_u))
+                       break;
 
-       if (fill_io_u(td, io_u)) {
-               put_io_u(td, io_u);
-               return NULL;
-       }
+               /*
+                * No more to do for this file, close it
+                */
+               io_u->file = NULL;
+               close_file(td, f);
+       } while (1);
 
        if (td->zone_bytes >= td->zone_size) {
                td->zone_bytes = 0;