From 9c0d224129b0c59698e4c77e7fed00dc8cbb50e1 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 1 Jul 2009 12:26:28 +0200 Subject: [PATCH] Don't allow pre_read on IO engines that cannot seek We cannot pre-read files, if we cannot seek back and read the same data again. So just disable it with a warning to the user. Signed-off-by: Jens Axboe --- HOWTO | 5 ++++- engines/net.c | 4 ++-- engines/splice.c | 2 +- filesetup.c | 3 +++ fio.1 | 4 +++- init.c | 6 +++++- ioengine.h | 1 + 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/HOWTO b/HOWTO index 3107d3a1..708eca00 100644 --- a/HOWTO +++ b/HOWTO @@ -741,7 +741,10 @@ create_on_open=bool Don't pre-setup the files for IO, just create open() pre_read=bool If this is given, files will be pre-read into memory before starting the given IO operation. This will also clear the 'invalidate' flag, since it is pointless to pre-read - and then drop the cache. + and then drop the cache. This will only work for IO engines + that are seekable, since they allow you to read the same data + multiple times. Thus it will not work on eg network or splice + IO. unlink=bool Unlink the job files when done. Not the default, as repeated runs of that job would then waste time recreating the file diff --git a/engines/net.c b/engines/net.c index 4ddacf28..c0a793e8 100644 --- a/engines/net.c +++ b/engines/net.c @@ -633,7 +633,7 @@ static struct ioengine_ops ioengine_splice = { .open_file = fio_netio_open_file, .close_file = generic_close_file, .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR | - FIO_SIGQUIT, + FIO_SIGQUIT | FIO_PIPEIO, }; #endif @@ -648,7 +648,7 @@ static struct ioengine_ops ioengine_rw = { .open_file = fio_netio_open_file, .close_file = fio_netio_close_file, .flags = FIO_SYNCIO | FIO_DISKLESSIO | FIO_UNIDIR | - FIO_SIGQUIT, + FIO_SIGQUIT | FIO_PIPEIO, }; static void fio_init fio_netio_register(void) diff --git a/engines/splice.c b/engines/splice.c index 28e1fb04..ca43e434 100644 --- a/engines/splice.c +++ b/engines/splice.c @@ -297,7 +297,7 @@ static struct ioengine_ops ioengine = { .open_file = generic_open_file, .close_file = generic_close_file, .get_file_size = generic_get_file_size, - .flags = FIO_SYNCIO, + .flags = FIO_SYNCIO | FIO_PIPEIO, }; #else /* FIO_HAVE_SPLICE */ diff --git a/filesetup.c b/filesetup.c index a0a4b80d..1a5a7ecc 100644 --- a/filesetup.c +++ b/filesetup.c @@ -156,6 +156,9 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f) unsigned int bs; char *b; + if (td->io_ops->flags & FIO_PIPEIO) + return 0; + if (!fio_file_open(f)) { if (td->io_ops->open_file(td, f)) { log_err("fio: cannot pre-read, failed to open file\n"); diff --git a/fio.1 b/fio.1 index aa7b9d67..32993b61 100644 --- a/fio.1 +++ b/fio.1 @@ -544,7 +544,9 @@ If true, the files are not created until they are opened for IO by the job. .BI pre_read \fR=\fPbool If this is given, files will be pre-read into memory before starting the given IO operation. This will also clear the \fR \fBinvalidate\fR flag, since it is -pointless to pre-read and then drop the cache. +pointless to pre-read and then drop the cache. This will only work for IO +engines that are seekable, since they allow you to read the same data +multiple times. Thus it will not work on eg network or splice IO. .TP .BI unlink \fR=\fPbool Unlink job files when done. Default: false. diff --git a/init.c b/init.c index 305f6605..160bdffc 100644 --- a/init.c +++ b/init.c @@ -350,8 +350,12 @@ static int fixup_options(struct thread_data *td) if (td->o.verify != VERIFY_NONE) td->o.refill_buffers = 1; - if (td->o.pre_read) + if (td->o.pre_read) { td->o.invalidate_cache = 0; + if (td->io_ops->flags & FIO_PIPEIO) + log_info("fio: cannot pre-read files with an IO engine" + " that isn't seekable. Pre-read disabled.\n"); + } if (td->o.mem_align) { if (td->o.odirect && !is_power_of_2(td->o.mem_align)) { diff --git a/ioengine.h b/ioengine.h index 6190977d..f9777999 100644 --- a/ioengine.h +++ b/ioengine.h @@ -112,6 +112,7 @@ enum fio_ioengine_flags { FIO_UNIDIR = 1 << 5, /* engine is uni-directional */ FIO_NOIO = 1 << 6, /* thread does only pseudo IO */ FIO_SIGQUIT = 1 << 7, /* needs SIGQUIT to exit */ + FIO_PIPEIO = 1 << 8, /* input/output no seekable */ }; /* -- 2.25.1