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->xfer_buf, io_u->xfer_buflen);
67 else if (io_u->ddir == DDIR_WRITE)
68 ret = write(f->fd, io_u->xfer_buf, io_u->xfer_buflen);
72 if (ret != (int) io_u->xfer_buflen) {
74 io_u->resid = io_u->xfer_buflen - ret;
84 td_verror(td, io_u->error);
89 static void fio_syncio_cleanup(struct thread_data *td)
91 if (td->io_ops->data) {
92 free(td->io_ops->data);
93 td->io_ops->data = NULL;
97 static int fio_syncio_init(struct thread_data *td)
99 struct syncio_data *sd = malloc(sizeof(*sd));
101 sd->last_io_u = NULL;
102 td->io_ops->data = sd;
106 static struct ioengine_ops ioengine = {
108 .version = FIO_IOOPS_VERSION,
109 .init = fio_syncio_init,
110 .prep = fio_syncio_prep,
111 .queue = fio_syncio_queue,
112 .getevents = fio_syncio_getevents,
113 .event = fio_syncio_event,
114 .cleanup = fio_syncio_cleanup,
118 static void fio_init fio_syncio_register(void)
120 register_ioengine(&ioengine);
123 static void fio_exit fio_syncio_unregister(void)
125 unregister_ioengine(&ioengine);