Initial blktrace support

This doesn't work yet, just committing what little bits I did as not
to lose them.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/blktrace.c b/blktrace.c
new file mode 100644
index 0000000..178a2a3
--- /dev/null
+++ b/blktrace.c
@@ -0,0 +1,95 @@
+/*
+ * blktrace support code for fio
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include "list.h"
+#include "fio.h"
+#include "blktrace_api.h"
+
+static int discard_pdu(int fd, struct blk_io_trace *t)
+{
+	if (t->pdu_len == 0)
+		return 0;
+
+	if (lseek(fd, t->pdu_len, SEEK_CUR) < 0)
+		return errno;
+		
+	return 0;
+}
+
+int is_blktrace(const char *filename)
+{
+	struct blk_io_trace t;
+	int fd, ret;
+
+	fd = open(filename, O_RDONLY);
+	if (fd < 0) {
+		perror("open blktrace");
+		return 0;
+	}
+
+	ret = read(fd, &t, sizeof(t));
+	close(fd);
+
+	if (ret < 0) {
+		perror("read blktrace");
+		return 0;
+	} else if (ret != sizeof(t)) {
+		log_err("fio: short read on blktrace file\n");
+		return 0;
+	}
+
+	if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC)
+		return 1;
+
+	return 0;
+}
+
+static void handle_trace(struct thread_data *td, struct blk_io_trace *t)
+{
+}
+
+int load_blktrace(struct thread_data *td, const char *filename)
+{
+	struct blk_io_trace t;
+	int fd;
+
+	fd = open(filename, O_RDONLY);
+	if (fd < 0) {
+		td_verror(td, errno, "open blktrace file");
+		return 1;
+	}
+
+	do {
+		int ret = read(fd, &t, sizeof(t));
+
+		if (ret < 0) {
+			td_verror(td, errno, "read blktrace file");
+			return 1;
+		} else if (!ret) {
+			break;
+		} else if (ret != sizeof(t)) {
+			log_err("fio: short read on blktrace file\n");
+			return 1;
+		}
+
+		if ((t.magic & 0xffffff00) != BLK_IO_TRACE_MAGIC) {
+			log_err("fio: bad magic in blktrace data\n");
+			return 1;
+		}
+		if ((t.magic & 0xff) != BLK_IO_TRACE_VERSION) {
+			log_err("fio: bad blktrace version %d\n", t.magic & 0xff);
+			return 1;
+		}
+		ret = discard_pdu(fd, &t);
+		if (ret) {
+			td_verror(td, ret, "blktrace lseek");
+			return 1;
+		}
+		handle_trace(td, &t);
+	} while (1);
+
+	close(fd);
+	return 0;
+}