Move thread options into a seperate structure
[fio.git] / engines / posixaio.c
index 10340571af57fa79f2621027f937bcb424d6b554..4aa7420c020dffbfff36a77d74c3d15b7fb6dc3b 100644 (file)
@@ -1,5 +1,7 @@
 /*
- * posix aio io engine
+ * posixaio engine
+ *
+ * IO engine that uses the posix defined aio interface.
  *
  */
 #include <stdio.h>
@@ -96,18 +98,20 @@ restart:
                        continue;
 
                err = aio_error(&io_u->aiocb);
-               switch (err) {
-                       default:
-                               io_u->error = err;
-                       case ECANCELED:
-                               io_u->resid = io_u->xfer_buflen;
-                       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;
@@ -177,8 +181,8 @@ 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 *));
+       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;
@@ -194,6 +198,8 @@ static struct ioengine_ops ioengine = {
        .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 */