+static struct fio_file *get_next_file(struct thread_data *td)
+{
+ struct fio_file *f;
+
+ assert(td->o.nr_files <= td->files_index);
+
+ if (td->nr_done_files >= td->o.nr_files) {
+ dprint(FD_FILE, "get_next_file: nr_open=%d, nr_done=%d,"
+ " nr_files=%d\n", td->nr_open_files,
+ td->nr_done_files,
+ td->o.nr_files);
+ return NULL;
+ }
+
+ f = td->file_service_file;
+ if (f && (f->flags & FIO_FILE_OPEN) && !(f->flags & FIO_FILE_CLOSING)) {
+ if (td->o.file_service_type == FIO_FSERVICE_SEQ)
+ goto out;
+ if (td->file_service_left--)
+ goto out;
+ }
+
+ if (td->o.file_service_type == FIO_FSERVICE_RR ||
+ td->o.file_service_type == FIO_FSERVICE_SEQ)
+ f = get_next_file_rr(td, FIO_FILE_OPEN, FIO_FILE_CLOSING);
+ else
+ f = get_next_file_rand(td, FIO_FILE_OPEN, FIO_FILE_CLOSING);
+
+ td->file_service_file = f;
+ td->file_service_left = td->file_service_nr - 1;
+out:
+ dprint(FD_FILE, "get_next_file: %p [%s]\n", f, f->file_name);
+ return f;
+}
+
+static int set_io_u_file(struct thread_data *td, struct io_u *io_u)
+{
+ struct fio_file *f;
+
+ do {
+ f = get_next_file(td);
+ if (!f)
+ return 1;
+
+ io_u->file = f;
+ get_file(f);
+
+ if (!fill_io_u(td, io_u))
+ break;
+
+ put_file_log(td, f);
+ td_io_close_file(td, f);
+ io_u->file = NULL;
+ 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);
+ } while (1);
+
+ return 0;
+}
+
+