From 230f33fbb6e0713d1189ea5d3295a8f536bac8d8 Mon Sep 17 00:00:00 2001 From: Adam Kupczyk Date: Thu, 9 Aug 2018 12:53:29 +0200 Subject: [PATCH] iolog replay: Treat 'open' on file that is scheduled to close as cancel of 'close' operation. Problem occurs when processing generated iolog files, such as this: fio version 2 iolog rbd_data.0 add rbd_data.0 open rbd_data.0 write 0 4096 rbd_data.0 close rbd_data.0 open rbd_data.0 write 0 4096 rbd_data.0 close Signed-off-by: Adam Kupczyk --- filesetup.c | 6 ++++++ ioengines.c | 13 ++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/filesetup.c b/filesetup.c index accb67ac..94a025e6 100644 --- a/filesetup.c +++ b/filesetup.c @@ -1675,6 +1675,11 @@ int put_file(struct thread_data *td, struct fio_file *f) if (--f->references) return 0; + disk_util_dec(f->du); + + if (td->o.file_lock_mode != FILE_LOCK_NONE) + unlock_file_all(td, f); + if (should_fsync(td) && td->o.fsync_on_close) { f_ret = fsync(f->fd); if (f_ret < 0) @@ -1688,6 +1693,7 @@ int put_file(struct thread_data *td, struct fio_file *f) ret = f_ret; td->nr_open_files--; + fio_file_clear_closing(f); fio_file_clear_open(f); assert(f->fd == -1); return ret; diff --git a/ioengines.c b/ioengines.c index e5fbcd43..433da604 100644 --- a/ioengines.c +++ b/ioengines.c @@ -431,6 +431,14 @@ void td_io_commit(struct thread_data *td) int td_io_open_file(struct thread_data *td, struct fio_file *f) { + if (fio_file_closing(f)) { + /* + * Open translates to undo closing. + */ + fio_file_clear_closing(f); + get_file(f); + return 0; + } assert(!fio_file_open(f)); assert(f->fd == -1); assert(td->io_ops->open_file); @@ -540,11 +548,6 @@ int td_io_close_file(struct thread_data *td, struct fio_file *f) */ fio_file_set_closing(f); - disk_util_dec(f->du); - - if (td->o.file_lock_mode != FILE_LOCK_NONE) - unlock_file_all(td, f); - return put_file(td, f); } -- 2.25.1