From: Jens Axboe Date: Thu, 29 Mar 2007 09:15:06 +0000 (+0200) Subject: Fix loop with multiple files X-Git-Tag: fio-1.15.1~11 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=1020a139beff50faf1bb18f761b024b664a09e14;hp=0401bca6b35ee32681462713ce9bc0cc2accbbf2 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 --- diff --git a/filesetup.c b/filesetup.c index e9dc72db..aad0720f 100644 --- a/filesetup.c +++ b/filesetup.c @@ -523,6 +523,7 @@ void put_file(struct thread_data *td, struct fio_file *f) if (td->io_ops->close_file) td->io_ops->close_file(td, f); + td->nr_open_files--; f->flags &= ~FIO_FILE_OPEN; } diff --git a/fio.h b/fio.h index 92e6a88d..07b40ff4 100644 --- a/fio.h +++ b/fio.h @@ -449,6 +449,7 @@ struct thread_data { struct fio_file *files; unsigned int files_index; unsigned int nr_open_files; + unsigned int nr_done_files; unsigned int nr_normal_files; union { unsigned int next_file; diff --git a/io_u.c b/io_u.c index 17e188ad..b48c99da 100644 --- a/io_u.c +++ b/io_u.c @@ -452,7 +452,7 @@ static struct fio_file *get_next_file(struct thread_data *td) 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 @@ static struct fio_file *find_next_new_file(struct thread_data *td) { 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 @@ set_file: 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