X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=engines%2Ffio-engine-libaio.c;h=c0f280b51ed447e1d125f2ee4c2806ffbd10c87b;hb=34cfcdafa994a0a75120e498c51eda08bde5df72;hp=c3fefdaccda7ea97cf660c0db4007b158807310e;hpb=7a16dd027f83d7ff8ff0e72bb6bb12fae046fcbf;p=fio.git diff --git a/engines/fio-engine-libaio.c b/engines/fio-engine-libaio.c index c3fefdac..c0f280b5 100644 --- a/engines/fio-engine-libaio.c +++ b/engines/fio-engine-libaio.c @@ -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 { @@ -17,20 +19,18 @@ struct libaio_data { struct io_event *aio_events; }; -static int fio_libaio_sync(struct thread_data fio_unused *td, - struct fio_file *f) -{ - return fsync(f->fd); -} - 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, f->fd, io_u->buf, io_u->buflen, io_u->offset); - else + else if (io_u->ddir == DDIR_WRITE) io_prep_pwrite(&io_u->iocb, f->fd, io_u->buf, io_u->buflen, io_u->offset); + else if (io_u->ddir == DDIR_SYNC) + io_prep_fsync(&io_u->iocb, f->fd); + else + return 1; return 0; } @@ -55,10 +55,13 @@ 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); + if (r < 0) + r = -r; + return (int) r; } @@ -72,7 +75,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; @@ -80,8 +83,13 @@ static int fio_libaio_queue(struct thread_data *td, struct io_u *io_u) break; } while (1); - return (int) ret; + if (ret <= 0) { + io_u->resid = io_u->buflen; + io_u->error = -ret; + return 1; + } + return 0; } static int fio_libaio_cancel(struct thread_data *td, struct io_u *io_u) @@ -116,6 +124,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; } @@ -130,5 +139,25 @@ struct ioengine_ops ioengine = { .getevents = fio_libaio_getevents, .event = fio_libaio_event, .cleanup = fio_libaio_cleanup, - .sync = fio_libaio_sync, }; + +#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