->getevents() should take unsigned args
[fio.git] / engines / posixaio.c
index a56ab3a691e9251c9684c91104774981e811684e..65a88e90756ceeb6b8640a99aff46d752abd0a80 100644 (file)
@@ -1,5 +1,7 @@
 /*
 /*
- * posix aio io engine
+ * posixaio engine
+ *
+ * IO engine that uses the posix defined aio interface.
  *
  */
 #include <stdio.h>
  *
  */
 #include <stdio.h>
@@ -9,7 +11,6 @@
 #include <assert.h>
 
 #include "../fio.h"
 #include <assert.h>
 
 #include "../fio.h"
-#include "../os.h"
 
 #ifdef FIO_HAVE_POSIXAIO
 
 
 #ifdef FIO_HAVE_POSIXAIO
 
@@ -75,8 +76,8 @@ static int fio_posixaio_prep(struct thread_data fio_unused *td,
        return 0;
 }
 
        return 0;
 }
 
-static int fio_posixaio_getevents(struct thread_data *td, int min, int max,
-                                 struct timespec *t)
+static int fio_posixaio_getevents(struct thread_data *td, unsigned int min,
+                                 unsigned int max, struct timespec *t)
 {
        struct posixaio_data *pd = td->io_ops->data;
        struct list_head *entry;
 {
        struct posixaio_data *pd = td->io_ops->data;
        struct list_head *entry;
@@ -96,17 +97,20 @@ restart:
                        continue;
 
                err = aio_error(&io_u->aiocb);
                        continue;
 
                err = aio_error(&io_u->aiocb);
-               switch (err) {
-                       default:
-                               io_u->error = err;
-                       case ECANCELED:
-                       case 0:
-                               pd->aio_events[r++] = io_u;
-                               io_u->seen = 1;
-                               break;
-                       case EINPROGRESS:
-                               break;
-               }
+               if (err == EINPROGRESS)
+                       continue;
+
+               io_u->seen = 1;
+               pd->aio_events[r++] = io_u;
+
+               if (err == ECANCELED)
+                       io_u->resid = io_u->xfer_buflen;
+               else if (!err) {
+                       ssize_t retval = aio_return(&io_u->aiocb);
+
+                       io_u->resid = io_u->xfer_buflen - retval;
+               } else
+                       io_u->error = err;
 
                if (r >= max)
                        break;
 
                if (r >= max)
                        break;
@@ -144,6 +148,8 @@ static int fio_posixaio_queue(struct thread_data fio_unused *td,
        struct aiocb *aiocb = &io_u->aiocb;
        int ret;
 
        struct aiocb *aiocb = &io_u->aiocb;
        int ret;
 
+       fio_ro_check(td, io_u);
+
        if (io_u->ddir == DDIR_READ)
                ret = aio_read(aiocb);
        else if (io_u->ddir == DDIR_WRITE)
        if (io_u->ddir == DDIR_READ)
                ret = aio_read(aiocb);
        else if (io_u->ddir == DDIR_WRITE)
@@ -153,7 +159,7 @@ static int fio_posixaio_queue(struct thread_data fio_unused *td,
 
        if (ret) {
                io_u->error = errno;
 
        if (ret) {
                io_u->error = errno;
-               td_verror(td, io_u->error);
+               td_verror(td, io_u->error, "xfer");
                return FIO_Q_COMPLETED;
        }
 
                return FIO_Q_COMPLETED;
        }
 
@@ -176,8 +182,8 @@ static int fio_posixaio_init(struct thread_data *td)
        struct posixaio_data *pd = malloc(sizeof(*pd));
 
        memset(pd, 0, sizeof(*pd));
        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 *));
+       pd->aio_events = malloc(td->o.iodepth * sizeof(struct io_u *));
+       memset(pd->aio_events, 0, td->o.iodepth * sizeof(struct io_u *));
 
        td->io_ops->data = pd;
        return 0;
 
        td->io_ops->data = pd;
        return 0;
@@ -193,6 +199,8 @@ static struct ioengine_ops ioengine = {
        .getevents      = fio_posixaio_getevents,
        .event          = fio_posixaio_event,
        .cleanup        = fio_posixaio_cleanup,
        .getevents      = fio_posixaio_getevents,
        .event          = fio_posixaio_event,
        .cleanup        = fio_posixaio_cleanup,
+       .open_file      = generic_open_file,
+       .close_file     = generic_close_file,
 };
 
 #else /* FIO_HAVE_POSIXAIO */
 };
 
 #else /* FIO_HAVE_POSIXAIO */