4 * IO engine that does regular read(2)/write(2) with lseek(2) to transfer
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_syncio_queue(struct thread_data *td, struct io_u *io_u)
35 struct fio_file *f = io_u->file;
38 fio_ro_check(td, io_u);
40 if (io_u->ddir == DDIR_READ)
41 ret = read(f->fd, io_u->xfer_buf, io_u->xfer_buflen);
42 else if (io_u->ddir == DDIR_WRITE)
43 ret = write(f->fd, io_u->xfer_buf, io_u->xfer_buflen);
47 if (ret != (int) io_u->xfer_buflen) {
49 io_u->resid = io_u->xfer_buflen - ret;
51 return FIO_Q_COMPLETED;
57 td_verror(td, io_u->error, "xfer");
59 return FIO_Q_COMPLETED;
62 static struct ioengine_ops ioengine = {
64 .version = FIO_IOOPS_VERSION,
65 .prep = fio_syncio_prep,
66 .queue = fio_syncio_queue,
67 .open_file = generic_open_file,
68 .close_file = generic_close_file,
72 static void fio_init fio_syncio_register(void)
74 register_ioengine(&ioengine);
77 static void fio_exit fio_syncio_unregister(void)
79 unregister_ioengine(&ioengine);