[PATCH] Link in known io engines
[fio.git] / engines / fio-engine-sync.c
index abc29f40f9a27a613c43127aec31372ffad634b5..5919830edcc6cf0a4fe91e57d20fbabad6e7d4bc 100644 (file)
@@ -7,18 +7,14 @@
 #include <unistd.h>
 #include <errno.h>
 #include <assert.h>
 #include <unistd.h>
 #include <errno.h>
 #include <assert.h>
-#include "fio.h"
-#include "os.h"
+
+#include "../fio.h"
+#include "../os.h"
 
 struct syncio_data {
        struct io_u *last_io_u;
 };
 
 
 struct syncio_data {
        struct io_u *last_io_u;
 };
 
-static int fio_syncio_sync(struct thread_data *td)
-{
-       return fsync(td->fd);
-}
-
 static int fio_syncio_getevents(struct thread_data *td, int fio_unused min,
                                int max, struct timespec fio_unused *t)
 {
 static int fio_syncio_getevents(struct thread_data *td, int fio_unused min,
                                int max, struct timespec fio_unused *t)
 {
@@ -45,7 +41,12 @@ static struct io_u *fio_syncio_event(struct thread_data *td, int event)
 
 static int fio_syncio_prep(struct thread_data *td, struct io_u *io_u)
 {
 
 static int fio_syncio_prep(struct thread_data *td, struct io_u *io_u)
 {
-       if (lseek(td->fd, io_u->offset, SEEK_SET) == -1) {
+       struct fio_file *f = io_u->file;
+
+       if (io_u->ddir == DDIR_SYNC)
+               return 0;
+
+       if (lseek(f->fd, io_u->offset, SEEK_SET) == -1) {
                td_verror(td, errno);
                return 1;
        }
                td_verror(td, errno);
                return 1;
        }
@@ -56,14 +57,17 @@ static int fio_syncio_prep(struct thread_data *td, struct io_u *io_u)
 static int fio_syncio_queue(struct thread_data *td, struct io_u *io_u)
 {
        struct syncio_data *sd = td->io_ops->data;
 static int fio_syncio_queue(struct thread_data *td, struct io_u *io_u)
 {
        struct syncio_data *sd = td->io_ops->data;
-       int ret;
+       struct fio_file *f = io_u->file;
+       unsigned int ret;
 
        if (io_u->ddir == DDIR_READ)
 
        if (io_u->ddir == DDIR_READ)
-               ret = read(td->fd, io_u->buf, io_u->buflen);
+               ret = read(f->fd, io_u->buf, io_u->buflen);
+       else if (io_u->ddir == DDIR_WRITE)
+               ret = write(f->fd, io_u->buf, io_u->buflen);
        else
        else
-               ret = write(td->fd, io_u->buf, io_u->buflen);
+               ret = fsync(f->fd);
 
 
-       if ((unsigned int) ret != io_u->buflen) {
+       if (ret != io_u->buflen) {
                if (ret > 0) {
                        io_u->resid = io_u->buflen - ret;
                        io_u->error = EIO;
                if (ret > 0) {
                        io_u->resid = io_u->buflen - ret;
                        io_u->error = EIO;
@@ -94,7 +98,7 @@ static int fio_syncio_init(struct thread_data *td)
        return 0;
 }
 
        return 0;
 }
 
-struct ioengine_ops ioengine = {
+static struct ioengine_ops ioengine = {
        .name           = "sync",
        .version        = FIO_IOOPS_VERSION,
        .init           = fio_syncio_init,
        .name           = "sync",
        .version        = FIO_IOOPS_VERSION,
        .init           = fio_syncio_init,
@@ -103,6 +107,15 @@ struct ioengine_ops ioengine = {
        .getevents      = fio_syncio_getevents,
        .event          = fio_syncio_event,
        .cleanup        = fio_syncio_cleanup,
        .getevents      = fio_syncio_getevents,
        .event          = fio_syncio_event,
        .cleanup        = fio_syncio_cleanup,
-       .sync           = fio_syncio_sync,
        .flags          = FIO_SYNCIO,
 };
        .flags          = FIO_SYNCIO,
 };
+
+static void fio_init fio_syncio_register(void)
+{
+       register_ioengine(&ioengine);
+}
+
+static void fio_exit fio_syncio_unregister(void)
+{
+       unregister_ioengine(&ioengine);
+}