4 * IO engine that does regular read(2)/write(2) with lseek(2) to transfer
17 static int fio_syncio_prep(struct thread_data *td, struct io_u *io_u)
19 struct fio_file *f = io_u->file;
21 if (io_u->ddir == DDIR_SYNC)
23 if (io_u->offset == f->last_completed_pos)
26 if (lseek(f->fd, io_u->offset, SEEK_SET) == -1) {
27 td_verror(td, errno, "lseek");
34 static int fio_syncio_queue(struct thread_data *td, struct io_u *io_u)
36 struct fio_file *f = io_u->file;
39 if (io_u->ddir == DDIR_READ)
40 ret = read(f->fd, io_u->xfer_buf, io_u->xfer_buflen);
41 else if (io_u->ddir == DDIR_WRITE)
42 ret = write(f->fd, io_u->xfer_buf, io_u->xfer_buflen);
46 if (ret != (int) io_u->xfer_buflen) {
48 io_u->resid = io_u->xfer_buflen - ret;
50 return FIO_Q_COMPLETED;
56 td_verror(td, io_u->error, "xfer");
58 return FIO_Q_COMPLETED;
61 static struct ioengine_ops ioengine = {
63 .version = FIO_IOOPS_VERSION,
64 .prep = fio_syncio_prep,
65 .queue = fio_syncio_queue,
66 .open_file = generic_open_file,
67 .close_file = generic_close_file,
71 static void fio_init fio_syncio_register(void)
73 register_ioengine(&ioengine);
76 static void fio_exit fio_syncio_unregister(void)
78 unregister_ioengine(&ioengine);