[PATCH] Implement file syncing as data direction

Instead of defining a seperate ->sync() operation for the io engine,
reuse the io_u infrastructure for committing and reaping sync
events as well. It's a nice cleanup as well.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/io_u.c b/io_u.c
index 962c17a..738f3e2 100644
--- a/io_u.c
+++ b/io_u.c
@@ -190,6 +190,16 @@
 		return read_iolog_get(td, io_u);
 
 	/*
+	 * see if it's time to sync
+	 */
+	if (td->fsync_blocks && !(td->io_blocks[DDIR_WRITE] % td->fsync_blocks)
+	    && should_fsync(td)) {
+		io_u->ddir = DDIR_SYNC;
+		io_u->file = f;
+		return 0;
+	}
+
+	/*
 	 * No log, let the seq/rand engine retrieve the next position.
 	 */
 	if (!get_next_offset(td, f, &io_u->offset)) {
@@ -260,19 +270,21 @@
 		io_u->buflen = f->file_size - io_u->offset;
 	}
 
-	if (!io_u->buflen) {
-		put_io_u(td, io_u);
-		return NULL;
+	if (io_u->ddir != DDIR_SYNC) {
+		if (!io_u->buflen) {
+			put_io_u(td, io_u);
+			return NULL;
+		}
+
+		if (!td->read_iolog && !td->sequential)
+			mark_random_map(td, f, io_u);
+
+		f->last_pos += io_u->buflen;
+
+		if (td->verify != VERIFY_NONE)
+			populate_verify_io_u(td, io_u);
 	}
 
-	if (!td->read_iolog && !td->sequential)
-		mark_random_map(td, f, io_u);
-
-	f->last_pos += io_u->buflen;
-
-	if (td->verify != VERIFY_NONE)
-		populate_verify_io_u(td, io_u);
-
 	if (td_io_prep(td, io_u)) {
 		put_io_u(td, io_u);
 		return NULL;
@@ -288,6 +300,13 @@
 	struct timeval e;
 	unsigned long msec;
 
+	if (io_u->ddir == DDIR_SYNC) {
+		td->last_was_sync = 1;
+		return;
+	}
+
+	td->last_was_sync = 0;
+
 	gettimeofday(&e, NULL);
 
 	if (!io_u->error) {