From 860a3044085c676632f9832a78133cd9847cbe62 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 8 Mar 2007 14:09:18 +0100 Subject: [PATCH] Add ->open to struct fio_file Don't use ->fd == -1 to check for the file being open or not, an io engine could be non-fd based. Signed-off-by: Jens Axboe --- fio.h | 1 + io_u.c | 4 ++-- ioengines.c | 10 +++++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/fio.h b/fio.h index 641ecdaf..ceeb6e6f 100644 --- a/fio.h +++ b/fio.h @@ -244,6 +244,7 @@ struct fio_file { unsigned int last_free_lookup; unsigned int unlink; + unsigned int open; }; /* diff --git a/io_u.c b/io_u.c index 4698b34d..94bf3003 100644 --- a/io_u.c +++ b/io_u.c @@ -337,7 +337,7 @@ static struct fio_file *get_next_file_rand(struct thread_data *td) fileno = (unsigned int) ((double) (td->open_files * r) / (RAND_MAX + 1.0)); f = &td->files[fileno]; - if (f->fd != -1) + if (f->open) return f; } while (1); } @@ -357,7 +357,7 @@ static struct fio_file *get_next_file_rr(struct thread_data *td) if (td->next_file >= td->open_files) td->next_file = 0; - if (f->fd != -1) + if (f->open) break; f = NULL; diff --git a/ioengines.c b/ioengines.c index 9d7453ba..c1648a01 100644 --- a/ioengines.c +++ b/ioengines.c @@ -261,6 +261,7 @@ int td_io_commit(struct thread_data *td) int td_io_open_file(struct thread_data *td, struct fio_file *f) { if (!td->io_ops->open_file(td, f)) { + f->open = 1; td->nr_open_files++; return 0; } @@ -270,7 +271,10 @@ int td_io_open_file(struct thread_data *td, struct fio_file *f) void td_io_close_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--; + if (f->open) { + if (td->io_ops->close_file) + td->io_ops->close_file(td, f); + td->nr_open_files--; + f->open = 0; + } } -- 2.25.1