*/
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)
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;
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;