4 * IO engine that does regular read(2)/write(2) with lseek(2) to transfer
5 * data and IO engine that does regular pread(2)/pwrite(2) to transfer data.
16 static int fio_syncio_prep(struct thread_data *td, struct io_u *io_u)
18 struct fio_file *f = io_u->file;
20 if (io_u->ddir == DDIR_SYNC)
22 if (io_u->offset == f->last_completed_pos)
25 if (lseek(f->fd, io_u->offset, SEEK_SET) == -1) {
26 td_verror(td, errno, "lseek");
33 static int fio_io_end(struct thread_data *td, struct io_u *io_u, int ret)
35 if (ret != (int) io_u->xfer_buflen) {
37 io_u->resid = io_u->xfer_buflen - ret;
39 return FIO_Q_COMPLETED;
45 td_verror(td, io_u->error, "xfer");
47 return FIO_Q_COMPLETED;
50 static int fio_psyncio_queue(struct thread_data *td, struct io_u *io_u)
52 struct fio_file *f = io_u->file;
55 fio_ro_check(td, io_u);
57 if (io_u->ddir == DDIR_READ)
58 ret = pread(f->fd, io_u->xfer_buf, io_u->xfer_buflen, io_u->offset);
59 else if (io_u->ddir == DDIR_WRITE)
60 ret = pwrite(f->fd, io_u->xfer_buf, io_u->xfer_buflen, io_u->offset);
64 return fio_io_end(td, io_u, ret);
67 static int fio_syncio_queue(struct thread_data *td, struct io_u *io_u)
69 struct fio_file *f = io_u->file;
72 fio_ro_check(td, io_u);
74 if (io_u->ddir == DDIR_READ)
75 ret = read(f->fd, io_u->xfer_buf, io_u->xfer_buflen);
76 else if (io_u->ddir == DDIR_WRITE)
77 ret = write(f->fd, io_u->xfer_buf, io_u->xfer_buflen);
81 return fio_io_end(td, io_u, ret);
84 static struct ioengine_ops ioengine_rw = {
86 .version = FIO_IOOPS_VERSION,
87 .prep = fio_syncio_prep,
88 .queue = fio_syncio_queue,
89 .open_file = generic_open_file,
90 .close_file = generic_close_file,
94 static struct ioengine_ops ioengine_prw = {
96 .version = FIO_IOOPS_VERSION,
97 .queue = fio_psyncio_queue,
98 .open_file = generic_open_file,
99 .close_file = generic_close_file,
103 static void fio_init fio_syncio_register(void)
105 register_ioengine(&ioengine_rw);
106 register_ioengine(&ioengine_prw);
109 static void fio_exit fio_syncio_unregister(void)
111 unregister_ioengine(&ioengine_rw);
112 unregister_ioengine(&ioengine_prw);