[PATCH] Fix busy-looping with aio engine and depth > 1
[fio.git] / engines / fio-engine-libaio.c
index c0f280b51ed447e1d125f2ee4c2806ffbd10c87b..da43f18ce1571b7c729ceb35fce02ec1aae00e12 100644 (file)
@@ -7,8 +7,9 @@
 #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
 
@@ -50,7 +51,9 @@ static int fio_libaio_getevents(struct thread_data *td, int min, int max,
 
        do {
                r = io_getevents(ld->aio_ctx, min, max, ld->aio_events, t);
-               if (r == -EAGAIN) {
+               if (r >= min)
+                       break;
+               else if (r == -EAGAIN) {
                        usleep(100);
                        continue;
                } else if (r == -EINTR)
@@ -120,6 +123,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;
        }
 
@@ -129,7 +133,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,
@@ -154,10 +158,20 @@ static int fio_libaio_init(struct thread_data fio_unused *td)
        return 1;
 }
 
-struct ioengine_ops ioengine = {
+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);
+}