#include <unistd.h>
#include <errno.h>
#include <assert.h>
-#include "fio.h"
-#include "os.h"
+
+#include "../fio.h"
+#include "../os.h"
+
+#ifdef FIO_HAVE_POSIXAIO
struct posixaio_data {
struct io_u **aio_events;
return sec + nsec;
}
-static int fio_posixaio_sync(struct thread_data *td)
+static int fio_posixaio_cancel(struct thread_data fio_unused *td,
+ struct io_u *io_u)
{
- return fsync(td->fd);
-}
-
-static int fio_posixaio_cancel(struct thread_data *td, struct io_u *io_u)
-{
- int r = aio_cancel(td->fd, &io_u->aiocb);
+ struct fio_file *f = io_u->file;
+ int r = aio_cancel(f->fd, &io_u->aiocb);
if (r == 1 || r == AIO_CANCELED)
return 0;
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;
- aiocb->aio_fildes = td->fd;
+ aiocb->aio_fildes = f->fd;
aiocb->aio_buf = io_u->buf;
aiocb->aio_nbytes = io_u->buflen;
aiocb->aio_offset = io_u->offset;
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;
{
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;
}
-struct ioengine_ops ioengine = {
+static struct ioengine_ops ioengine = {
.name = "posixaio",
.version = FIO_IOOPS_VERSION,
.init = fio_posixaio_init,
.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;
+}
+
+static struct ioengine_ops ioengine = {
+ .name = "posixaio",
+ .version = FIO_IOOPS_VERSION,
+ .init = fio_posixaio_init,
+};
+
+#endif
+
+static void fio_init fio_posixaio_register(void)
+{
+ register_ioengine(&ioengine);
+}
+
+static void fio_exit fio_posixaio_unregister(void)
+{
+ unregister_ioengine(&ioengine);
+}