Add support for using '-' as filename for stdin/stdout
authorJens Axboe <jens.axboe@oracle.com>
Mon, 16 Apr 2007 19:54:24 +0000 (21:54 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Mon, 16 Apr 2007 19:54:24 +0000 (21:54 +0200)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
HOWTO
filesetup.c
ioengines.c

diff --git a/HOWTO b/HOWTO
index 7cab05379f612034abdc173f03acb8d7850f902f..08a2b68dac71cdbd2cd101d02fa2f2859b22cd8c 100644 (file)
--- 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.
index bb25cd5c20bf43ea46646f3b5fb799637e23f5f2..85141dc3725a26b870fe8afe83876199e2142163 100644 (file)
@@ -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)
index b9c6d71400ec672b0288e0abe17f6cff345f9941..34ae91671a4348c43bacdf9f7eddc2f5e81f020d 100644 (file)
@@ -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))