From f718273e7180208fc0cf5c88b99f32b371d6d75f Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 10 Mar 2008 13:57:58 +0100 Subject: [PATCH] Extend ipo file action capabilities Add FIO_LOG_UNLINK_FILE and move the handling of special ipo's into a dedicated function. Signed-off-by: Jens Axboe --- fio.h | 1 + log.c | 66 ++++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/fio.h b/fio.h index dab66d2b..34f02d69 100644 --- a/fio.h +++ b/fio.h @@ -755,6 +755,7 @@ enum file_log_act { FIO_LOG_ADD_FILE, FIO_LOG_OPEN_FILE, FIO_LOG_CLOSE_FILE, + FIO_LOG_UNLINK_FILE, }; extern int __must_check read_iolog_get(struct thread_data *, struct io_u *); diff --git a/log.c b/log.c index 8ac8ec32..63c0a332 100644 --- a/log.c +++ b/log.c @@ -61,35 +61,59 @@ static void iolog_delay(struct thread_data *td, unsigned long delay) usec_sleep(td, delay); } +static int ipo_special(struct thread_data *td, struct io_piece *ipo) +{ + struct fio_file *f; + int ret; + + /* + * Not a special ipo + */ + if (ipo->ddir != DDIR_INVAL) + return 0; + + f = td->files[ipo->fileno]; + + switch (ipo->file_action) { + case FIO_LOG_OPEN_FILE: + ret = td_io_open_file(td, f); + if (!ret) { + free(ipo); + break; + } + td_verror(td, ret, "iolog open file"); + return -1; + case FIO_LOG_CLOSE_FILE: + td_io_close_file(td, f); + break; + case FIO_LOG_UNLINK_FILE: + unlink(f->file_name); + break; + default: + log_err("fio: bad file action %d\n", ipo->file_action); + break; + } + + return 1; +} + int read_iolog_get(struct thread_data *td, struct io_u *io_u) { struct io_piece *ipo; while (!list_empty(&td->io_log_list)) { + int ret; + ipo = list_entry(td->io_log_list.next, struct io_piece, list); list_del(&ipo->list); - /* - * invalid ddir, this is a file action - */ - if (ipo->ddir == DDIR_INVAL) { - struct fio_file *f = td->files[ipo->fileno]; - - if (ipo->file_action == FIO_LOG_OPEN_FILE) { - int ret; - - ret = td_io_open_file(td, f); - if (!ret) { - free(ipo); - continue; - } - td_verror(td, ret, "iolog open file"); - return 1; - } else if (ipo->file_action == FIO_LOG_CLOSE_FILE) { - td_io_close_file(td, f); - free(ipo); - continue; - } + ret = ipo_special(td, ipo); + if (ret < 0) { + free(ipo); + break; + } else if (ret > 0) { + free(ipo); + continue; } io_u->offset = ipo->offset; -- 2.25.1