X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=io_u.c;h=6df4b5eee80190187aa0015b11aca7da73e714b4;hp=426a5f8a38b49b1f2e7a1b18de199ddccf53a536;hb=b58cf3dc6945d661bd5c40c0856a99e0f9c8a9e6;hpb=9bf2061e2b76a396936c5fe70060574a6c96b8f8 diff --git a/io_u.c b/io_u.c index 426a5f8a..6df4b5ee 100644 --- 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;