Fix loop with multiple files

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>
diff --git a/io_u.c b/io_u.c
index 17e188a..b48c99d 100644
--- a/io_u.c
+++ b/io_u.c
@@ -452,7 +452,7 @@
 
 	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 @@
 {
 	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 @@
 		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