From 661598287ecc3b8987f312cf8403936552ce686a Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 16 Apr 2007 21:54:24 +0200 Subject: [PATCH] Add support for using '-' as filename for stdin/stdout Signed-off-by: Jens Axboe --- HOWTO | 4 +++- filesetup.c | 27 +++++++++++++++++++++++---- ioengines.c | 11 ++++++++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/HOWTO b/HOWTO index 7cab0537..08a2b68d 100644 --- a/HOWTO +++ b/HOWTO @@ -211,7 +211,9 @@ filename=str Fio normally makes up a filename based on the job name, ioengine is file based, you can specify a number of files by seperating the names with a ':' colon. So if you wanted a job to open /dev/sda and /dev/sdb as the two working files, - you would use filename=/dev/sda:/dev/sdb + you would use filename=/dev/sda:/dev/sdb. '-' is a reserved + name, meaning stdin or stdout. Which of the two depends + on the read/write direction set. opendir=str Tell fio to recursively add any file it can find in this directory and down the file system tree. diff --git a/filesetup.c b/filesetup.c index bb25cd5c..85141dc3 100644 --- a/filesetup.c +++ b/filesetup.c @@ -200,8 +200,17 @@ void generic_close_file(struct thread_data fio_unused *td, struct fio_file *f) int generic_open_file(struct thread_data *td, struct fio_file *f) { + int is_std = 0; int flags = 0; + if (!strcmp(f->file_name, "-")) { + if (td_rw(td)) { + log_err("fio: can't read/write to stdin/out\n"); + return 1; + } + is_std = 1; + } + if (td->o.odirect) flags |= OS_O_DIRECT; if (td->o.sync_io) @@ -213,14 +222,20 @@ int generic_open_file(struct thread_data *td, struct fio_file *f) if (f->filetype == FIO_TYPE_FILE) flags |= O_CREAT; - f->fd = open(f->file_name, flags, 0600); + if (is_std) + f->fd = dup(STDOUT_FILENO); + else + f->fd = open(f->file_name, flags, 0600); } else { if (f->filetype == FIO_TYPE_CHAR) flags |= O_RDWR; else flags |= O_RDONLY; - f->fd = open(f->file_name, flags); + if (is_std) + f->fd = dup(STDIN_FILENO); + else + f->fd = open(f->file_name, flags); } if (f->fd == -1) { @@ -478,7 +493,10 @@ static void get_file_type(struct fio_file *f) { struct stat sb; - f->filetype = FIO_TYPE_FILE; + if (!strcmp(f->file_name, "-")) + f->filetype = FIO_TYPE_PIPE; + else + f->filetype = FIO_TYPE_FILE; if (!lstat(f->file_name, &sb)) { if (S_ISBLK(sb.st_mode)) @@ -536,7 +554,8 @@ void put_file(struct thread_data *td, struct fio_file *f) if (--f->references) return; - if (should_fsync(td) && td->o.fsync_on_close) + if (should_fsync(td) && td->o.fsync_on_close && + (f->filetype == FIO_TYPE_FILE || f->filetype == FIO_TYPE_BD)) fsync(f->fd); if (td->io_ops->close_file) diff --git a/ioengines.c b/ioengines.c index b9c6d714..34ae9167 100644 --- a/ioengines.c +++ b/ioengines.c @@ -271,6 +271,13 @@ int td_io_open_file(struct thread_data *td, struct fio_file *f) return 1; } + if (f->filetype == FIO_TYPE_PIPE) { + if (td_random(td)) { + log_err("fio: can't seek on pipes (no random io)\n"); + goto err; + } + } + f->last_free_lookup = 0; f->last_completed_pos = 0; f->last_pos = 0; @@ -283,7 +290,9 @@ int td_io_open_file(struct thread_data *td, struct fio_file *f) if (td->o.invalidate_cache && file_invalidate_cache(td, f)) goto err; - if (td->o.fadvise_hint) { + if (td->o.fadvise_hint && + (f->filetype == FIO_TYPE_BD || f->filetype == FIO_TYPE_FILE)) { + int flags; if (td_random(td)) -- 2.25.1