Add support for using '-' as filename for stdin/stdout

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/HOWTO b/HOWTO
index 7cab053..08a2b68 100644
--- a/HOWTO
+++ b/HOWTO
@@ -211,7 +211,9 @@
 		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 bb25cd5..85141dc 100644
--- a/filesetup.c
+++ b/filesetup.c
@@ -200,8 +200,17 @@
 
 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 @@
 		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 @@
 {
 	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 @@
 	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 b9c6d71..34ae916 100644
--- a/ioengines.c
+++ b/ioengines.c
@@ -271,6 +271,13 @@
 		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 @@
 	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))