[PATCH] Link in known io engines
[fio.git] / engines / fio-engine-libaio.c
index 5e394e3e477f0961ad65c8f65a619b1151c30ee6..45e69e90b600704df35dfb1d2f23a91857531c7f 100644 (file)
@@ -7,8 +7,11 @@
 #include <unistd.h>
 #include <errno.h>
 #include <assert.h>
-#include "fio.h"
-#include "os.h"
+
+#include "../fio.h"
+#include "../os.h"
+
+#ifdef FIO_HAVE_LIBAIO
 
 #define ev_to_iou(ev)  (struct io_u *) ((unsigned long) (ev)->obj)
 
@@ -57,7 +60,10 @@ static int fio_libaio_getevents(struct thread_data *td, int min, int max,
                        break;
        } while (1);
 
-       return (int) -r;
+       if (r < 0)
+               r = -r;
+
+       return (int) r;
 }
 
 static int fio_libaio_queue(struct thread_data *td, struct io_u *io_u)
@@ -78,9 +84,13 @@ static int fio_libaio_queue(struct thread_data *td, struct io_u *io_u)
                        break;
        } while (1);
 
-       assert(ret);
+       if (ret <= 0) {
+               io_u->resid = io_u->buflen;
+               io_u->error = -ret;
+               return 1;
+       }
 
-       return (int) -ret;
+       return 0;
 }
 
 static int fio_libaio_cancel(struct thread_data *td, struct io_u *io_u)
@@ -111,6 +121,7 @@ static int fio_libaio_init(struct thread_data *td)
        memset(ld, 0, sizeof(*ld));
        if (io_queue_init(td->iodepth, &ld->aio_ctx)) {
                td_verror(td, errno);
+               free(ld);
                return 1;
        }
 
@@ -120,7 +131,7 @@ static int fio_libaio_init(struct thread_data *td)
        return 0;
 }
 
-struct ioengine_ops ioengine = {
+static struct ioengine_ops ioengine = {
        .name           = "libaio",
        .version        = FIO_IOOPS_VERSION,
        .init           = fio_libaio_init,
@@ -131,3 +142,34 @@ struct ioengine_ops ioengine = {
        .event          = fio_libaio_event,
        .cleanup        = fio_libaio_cleanup,
 };
+
+#else /* FIO_HAVE_LIBAIO */
+
+/*
+ * 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_libaio_init(struct thread_data fio_unused *td)
+{
+       fprintf(stderr, "fio: libaio not available\n");
+       return 1;
+}
+
+static struct ioengine_ops ioengine = {
+       .name           = "libaio",
+       .version        = FIO_IOOPS_VERSION,
+       .init           = fio_libaio_init,
+};
+
+#endif
+
+static void fio_init fio_libaio_register(void)
+{
+       register_ioengine(&ioengine);
+}
+
+static void fio_exit fio_libaio_unregister(void)
+{
+       unregister_ioengine(&ioengine);
+}