From 21972cdef7db6b557c2d56138f8434658a9d1e49 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 23 Nov 2006 12:39:16 +0100 Subject: [PATCH 1/1] [PATCH] Always open the files from the job itself This way we don't fork or spawn threads and make them inherit the open file. Signed-off-by: Jens Axboe --- filesetup.c | 46 +++++++++++++++++++++++++++++++--------------- fio.c | 2 ++ fio.h | 1 + 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/filesetup.c b/filesetup.c index 705eb4a9..4fa04ecd 100644 --- a/filesetup.c +++ b/filesetup.c @@ -351,10 +351,24 @@ static int setup_file(struct thread_data *td, struct fio_file *f) return 0; } +int open_files(struct thread_data *td) +{ + struct fio_file *f; + int i, err = 0; + + for_each_file(td, f, i) { + err = setup_file(td, f); + if (err) + break; + } + + return err; +} + int setup_files(struct thread_data *td) { struct fio_file *f; - int i, err; + int err, i; /* * if ioengine defines a setup() method, it's responsible for @@ -366,13 +380,7 @@ int setup_files(struct thread_data *td) if (create_files(td)) return 1; - err = 0; - for_each_file(td, f, i) { - err = setup_file(td, f); - if (err) - break; - } - + err = open_files(td); if (err) return err; @@ -396,9 +404,18 @@ int setup_files(struct thread_data *td) td->total_io_size = td->io_size * td->loops; if (td->io_ops->flags & FIO_MMAPIO) - return setup_files_mmap(td); + err = setup_files_mmap(td); else - return setup_files_plain(td); + err = setup_files_plain(td); + + for_each_file(td, f, i) { + if (f->fd != -1) { + close(f->fd); + f->fd = -1; + } + } + + return err; } void close_files(struct thread_data *td) @@ -407,16 +424,15 @@ void close_files(struct thread_data *td) int i; for_each_file(td, f, i) { - if (f->fd != -1) { - file_invalidate_cache(td, f); - close(f->fd); - f->fd = -1; - } if (td->unlink && td->filetype == FIO_TYPE_FILE) { unlink(f->file_name); free(f->file_name); f->file_name = NULL; } + if (f->fd != -1) { + close(f->fd); + f->fd = -1; + } if (f->mmap) { munmap(f->mmap, f->file_size); f->mmap = NULL; diff --git a/fio.c b/fio.c index d005625a..ed14c41f 100644 --- a/fio.c +++ b/fio.c @@ -656,6 +656,8 @@ static void *thread_main(void *data) if (!td->create_serialize && setup_files(td)) goto err; + if (open_files(td)) + goto err; gettimeofday(&td->epoch, NULL); diff --git a/fio.h b/fio.h index 9f5201b6..1115c62e 100644 --- a/fio.h +++ b/fio.h @@ -472,6 +472,7 @@ extern int init_random_state(struct thread_data *); */ extern void close_files(struct thread_data *); extern int setup_files(struct thread_data *); +extern int open_files(struct thread_data *); extern int file_invalidate_cache(struct thread_data *, struct fio_file *); /* -- 2.25.1