[PATCH] Missing memset and free-on-error in io engines
[fio.git] / engines / fio-engine-libaio.c
index daee65930b956984991ee0fce9482bff0e19310b..12ddc98b26ac800d86ed78e15cefa21513cb32ff 100644 (file)
@@ -10,6 +10,8 @@
 #include "fio.h"
 #include "os.h"
 
+#ifdef FIO_HAVE_LIBAIO
+
 #define ev_to_iou(ev)  (struct io_u *) ((unsigned long) (ev)->obj)
 
 struct libaio_data {
@@ -57,7 +59,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)
@@ -115,6 +120,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;
        }
 
@@ -135,3 +141,24 @@ 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;
+}
+
+struct ioengine_ops ioengine = {
+       .name           = "libaio",
+       .version        = FIO_IOOPS_VERSION,
+       .init           = fio_libaio_init,
+};
+
+#endif