[PATCH] Missing memset and free-on-error in io engines
[fio.git] / engines / fio-engine-posixaio.c
index 8cd3cf465998cb6fca2c961130f3e09d56d5114c..894a410a459117571518c00b66abe2d790a81183 100644 (file)
@@ -10,6 +10,8 @@
 #include "fio.h"
 #include "os.h"
 
+#ifdef FIO_HAVE_POSIXAIO
+
 struct posixaio_data {
        struct io_u **aio_events;
 };
@@ -45,12 +47,8 @@ static unsigned long long ts_utime_since_now(struct timespec *t)
        return sec + nsec;
 }
 
-static int fio_posixaio_sync(struct thread_data *td, struct fio_file *f)
-{
-       return fsync(f->fd);
-}
-
-static int fio_posixaio_cancel(struct thread_data *td, struct io_u *io_u)
+static int fio_posixaio_cancel(struct thread_data fio_unused *td,
+                              struct io_u *io_u)
 {
        struct fio_file *f = io_u->file;
        int r = aio_cancel(f->fd, &io_u->aiocb);
@@ -61,7 +59,8 @@ static int fio_posixaio_cancel(struct thread_data *td, struct io_u *io_u)
        return 1;
 }
 
-static int fio_posixaio_prep(struct thread_data *td, struct io_u *io_u)
+static int fio_posixaio_prep(struct thread_data fio_unused *td,
+                            struct io_u *io_u)
 {
        struct aiocb *aiocb = &io_u->aiocb;
        struct fio_file *f = io_u->file;
@@ -146,8 +145,10 @@ static int fio_posixaio_queue(struct thread_data fio_unused *td,
 
        if (io_u->ddir == DDIR_READ)
                ret = aio_read(aiocb);
-       else
+       else if (io_u->ddir == DDIR_WRITE)
                ret = aio_write(aiocb);
+       else
+               ret = aio_fsync(O_SYNC, aiocb);
 
        if (ret)
                io_u->error = errno;
@@ -170,7 +171,9 @@ static int fio_posixaio_init(struct thread_data *td)
 {
        struct posixaio_data *pd = malloc(sizeof(*pd));
 
+       memset(pd, 0, sizeof(*pd));
        pd->aio_events = malloc(td->iodepth * sizeof(struct io_u *));
+       memset(pd->aio_events, 0, td->iodepth * sizeof(struct io_u *));
 
        td->io_ops->data = pd;
        return 0;
@@ -186,5 +189,25 @@ struct ioengine_ops ioengine = {
        .getevents      = fio_posixaio_getevents,
        .event          = fio_posixaio_event,
        .cleanup        = fio_posixaio_cleanup,
-       .sync           = fio_posixaio_sync,
 };
+
+#else /* FIO_HAVE_POSIXAIO */
+
+/*
+ * When we have a proper configure system in place, we simply wont build
+ * and install this io engine. For now install a crippled version that
+ * just complains and fails to load.
+ */
+static int fio_posixaio_init(struct thread_data fio_unused *td)
+{
+       fprintf(stderr, "fio: posixaio not available\n");
+       return 1;
+}
+
+struct ioengine_ops ioengine = {
+       .name           = "posixaio",
+       .version        = FIO_IOOPS_VERSION,
+       .init           = fio_posixaio_init,
+};
+
+#endif