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 if (io_u->ddir == DDIR_READ)
39 ret = read(f->fd, io_u->xfer_buf, io_u->xfer_buflen);
40 else if (io_u->ddir == DDIR_WRITE)
41 ret = write(f->fd, io_u->xfer_buf, io_u->xfer_buflen);
45 if (ret != (int) io_u->xfer_buflen) {
47 io_u->resid = io_u->xfer_buflen - ret;
49 return FIO_Q_COMPLETED;
55 td_verror(td, io_u->error, "xfer");
57 return FIO_Q_COMPLETED;
60 static struct ioengine_ops ioengine = {
62 .version = FIO_IOOPS_VERSION,
63 .prep = fio_syncio_prep,
64 .queue = fio_syncio_queue,
65 .open_file = generic_open_file,
66 .close_file = generic_close_file,
70 static void fio_init fio_syncio_register(void)
72 register_ioengine(&ioengine);
75 static void fio_exit fio_syncio_unregister(void)
77 unregister_ioengine(&ioengine);