From: Jens Axboe Date: Wed, 7 Feb 2007 12:14:57 +0000 (+0100) Subject: [PATCH] Don't create files for engines that don't need them X-Git-Tag: fio-1.12~128 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=4d9345ae968ca92ace3dab06c25a9b73159cb329 [PATCH] Don't create files for engines that don't need them Introduce FIO_NULLIO as a way to control that from the io engine. Signed-off-by: Jens Axboe --- diff --git a/engines/cpu.c b/engines/cpu.c index f65f91d9..27ec6da1 100644 --- a/engines/cpu.c +++ b/engines/cpu.c @@ -24,7 +24,7 @@ static struct ioengine_ops ioengine = { .version = FIO_IOOPS_VERSION, .init = fio_cpuio_init, .setup = fio_cpuio_setup, - .flags = FIO_CPUIO, + .flags = FIO_CPUIO | FIO_NULLIO, }; static void fio_init fio_cpuio_register(void) diff --git a/engines/null.c b/engines/null.c index fc829473..7b4b2176 100644 --- a/engines/null.c +++ b/engines/null.c @@ -70,7 +70,7 @@ static struct ioengine_ops ioengine = { .getevents = fio_null_getevents, .event = fio_null_event, .cleanup = fio_null_cleanup, - .flags = FIO_SYNCIO, + .flags = FIO_SYNCIO | FIO_NULLIO, }; static void fio_init fio_null_register(void) diff --git a/filesetup.c b/filesetup.c index 610981b4..1f1259d1 100644 --- a/filesetup.c +++ b/filesetup.c @@ -15,7 +15,7 @@ static int file_ok(struct thread_data *td, struct fio_file *f) { struct stat st; - if (td->filetype != FIO_TYPE_FILE) + if (td->filetype != FIO_TYPE_FILE || (td->io_ops->flags & FIO_NULLIO)) return 0; if (stat(f->file_name, &st) == -1) @@ -332,29 +332,38 @@ static int setup_file(struct thread_data *td, struct fio_file *f) if (td->io_ops->flags & FIO_NETIO) return 0; - if (td->odirect) - flags |= OS_O_DIRECT; - if (td->sync_io) - flags |= O_SYNC; - if (td_write(td) || td_rw(td)) { - flags |= O_RDWR; + /* + * we need a valid file descriptor, but don't create a real file. + * lets just dup stdout, seems like a sensible approach. + */ + if (td->io_ops->flags & FIO_NULLIO) + f->fd = dup(STDOUT_FILENO); + else { + if (td->odirect) + flags |= OS_O_DIRECT; + if (td->sync_io) + flags |= O_SYNC; + + if (td_write(td) || td_rw(td)) { + flags |= O_RDWR; - if (td->filetype == FIO_TYPE_FILE) { - if (!td->overwrite) - flags |= O_TRUNC; + if (td->filetype == FIO_TYPE_FILE) { + if (!td->overwrite) + flags |= O_TRUNC; - flags |= O_CREAT; - } + flags |= O_CREAT; + } - f->fd = open(f->file_name, flags, 0600); - } else { - if (td->filetype == FIO_TYPE_CHAR) - flags |= O_RDWR; - else - flags |= O_RDONLY; + f->fd = open(f->file_name, flags, 0600); + } else { + if (td->filetype == FIO_TYPE_CHAR) + flags |= O_RDWR; + else + flags |= O_RDONLY; - f->fd = open(f->file_name, flags); + f->fd = open(f->file_name, flags); + } } if (f->fd == -1) { diff --git a/fio.h b/fio.h index 56ed2485..e42d67bb 100644 --- a/fio.h +++ b/fio.h @@ -147,6 +147,7 @@ enum fio_ioengine_flags { FIO_MMAPIO = 1 << 2, FIO_RAWIO = 1 << 3, FIO_NETIO = 1 << 4, + FIO_NULLIO = 1 << 5, }; struct fio_file { diff --git a/stat.c b/stat.c index a98539fc..a9e87aa7 100644 --- a/stat.c +++ b/stat.c @@ -205,7 +205,7 @@ void init_disk_util(struct thread_data *td) dev_t dev; char *p; - if (!td->do_disk_util || (td->io_ops->flags & FIO_NETIO)) + if (!td->do_disk_util || (td->io_ops->flags & (FIO_NETIO | FIO_NULLIO))) return; /*