[PATCH] Fix a bunch of bugs
[fio.git] / engines / fio-engine-libaio.c
index 703808b66a8628a8116e145ada01b783fc186b72..57daf1b6b49a5c8b2933eac060b025318594803e 100644 (file)
@@ -17,17 +17,20 @@ struct libaio_data {
        struct io_event *aio_events;
 };
 
-static int fio_libaio_sync(struct thread_data *td)
+static int fio_libaio_sync(struct thread_data fio_unused *td,
+                          struct fio_file *f)
 {
-       return fsync(td->fd);
+       return fsync(f->fd);
 }
 
-static int fio_libaio_prep(struct thread_data *td, struct io_u *io_u)
+static int fio_libaio_prep(struct thread_data fio_unused *td, struct io_u *io_u)
 {
+       struct fio_file *f = io_u->file;
+
        if (io_u->ddir == DDIR_READ)
-               io_prep_pread(&io_u->iocb, td->fd, io_u->buf, io_u->buflen, io_u->offset);
+               io_prep_pread(&io_u->iocb, f->fd, io_u->buf, io_u->buflen, io_u->offset);
        else
-               io_prep_pwrite(&io_u->iocb, td->fd, io_u->buf, io_u->buflen, io_u->offset);
+               io_prep_pwrite(&io_u->iocb, f->fd, io_u->buf, io_u->buflen, io_u->offset);
 
        return 0;
 }
@@ -52,7 +55,7 @@ static int fio_libaio_getevents(struct thread_data *td, int min, int max,
                        continue;
                } else if (r == -EINTR)
                        continue;
-               else
+               else if (r != 0)
                        break;
        } while (1);
 
@@ -69,7 +72,7 @@ static int fio_libaio_queue(struct thread_data *td, struct io_u *io_u)
                ret = io_submit(ld->aio_ctx, 1, &iocb);
                if (ret == 1)
                        return 0;
-               else if (ret == -EAGAIN)
+               else if (ret == -EAGAIN || !ret)
                        usleep(100);
                else if (ret == -EINTR)
                        continue;
@@ -77,8 +80,9 @@ static int fio_libaio_queue(struct thread_data *td, struct io_u *io_u)
                        break;
        } while (1);
 
-       return (int) ret;
+       assert(ret);
 
+       return (int) ret;
 }
 
 static int fio_libaio_cancel(struct thread_data *td, struct io_u *io_u)
@@ -113,6 +117,7 @@ static int fio_libaio_init(struct thread_data *td)
        }
 
        ld->aio_events = malloc(td->iodepth * sizeof(struct io_event));
+       memset(ld->aio_events, 0, td->iodepth * sizeof(struct io_event));
        td->io_ops->data = ld;
        return 0;
 }