2 * regular read/write sync io engine
15 struct io_u *last_io_u;
18 static int fio_syncio_getevents(struct thread_data *td, int fio_unused min,
19 int max, struct timespec fio_unused *t)
24 * we can only have one finished io_u for sync io, since the depth
27 if (list_empty(&td->io_u_busylist))
33 static struct io_u *fio_syncio_event(struct thread_data *td, int event)
35 struct syncio_data *sd = td->io_ops->data;
42 static int fio_syncio_prep(struct thread_data *td, struct io_u *io_u)
44 struct fio_file *f = io_u->file;
46 if (io_u->ddir == DDIR_SYNC)
48 if (io_u->offset == f->last_completed_pos)
51 if (lseek(f->fd, io_u->offset, SEEK_SET) == -1) {
59 static int fio_syncio_queue(struct thread_data *td, struct io_u *io_u)
61 struct syncio_data *sd = td->io_ops->data;
62 struct fio_file *f = io_u->file;
65 if (io_u->ddir == DDIR_READ)
66 ret = read(f->fd, io_u->buf, io_u->buflen);
67 else if (io_u->ddir == DDIR_WRITE)
68 ret = write(f->fd, io_u->buf, io_u->buflen);
72 if (ret != io_u->buflen) {
74 io_u->resid = io_u->buflen - ret;
86 static void fio_syncio_cleanup(struct thread_data *td)
88 if (td->io_ops->data) {
89 free(td->io_ops->data);
90 td->io_ops->data = NULL;
94 static int fio_syncio_init(struct thread_data *td)
96 struct syncio_data *sd = malloc(sizeof(*sd));
99 td->io_ops->data = sd;
103 static struct ioengine_ops ioengine = {
105 .version = FIO_IOOPS_VERSION,
106 .init = fio_syncio_init,
107 .prep = fio_syncio_prep,
108 .queue = fio_syncio_queue,
109 .getevents = fio_syncio_getevents,
110 .event = fio_syncio_event,
111 .cleanup = fio_syncio_cleanup,
115 static void fio_init fio_syncio_register(void)
117 register_ioengine(&ioengine);
120 static void fio_exit fio_syncio_unregister(void)
122 unregister_ioengine(&ioengine);