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 #define is_psync(td) ((td)->io_ops->data == (void *) 1)
18 static int fio_syncio_prep(struct thread_data *td, struct io_u *io_u)
20 struct fio_file *f = io_u->file;
22 if (io_u->ddir == DDIR_SYNC)
24 if (io_u->offset == f->last_completed_pos)
27 if (lseek(f->fd, io_u->offset, SEEK_SET) == -1) {
28 td_verror(td, errno, "lseek");
35 static int fio_syncio_queue(struct thread_data *td, struct io_u *io_u)
37 struct fio_file *f = io_u->file;
40 fio_ro_check(td, io_u);
42 if (io_u->ddir == DDIR_READ) {
44 ret = pread(f->fd, io_u->xfer_buf, io_u->xfer_buflen,io_u->offset);
46 ret = read(f->fd, io_u->xfer_buf, io_u->xfer_buflen);
47 } else if (io_u->ddir == DDIR_WRITE) {
49 ret = pwrite(f->fd, io_u->xfer_buf, io_u->xfer_buflen,io_u->offset);
51 ret = write(f->fd, io_u->xfer_buf, io_u->xfer_buflen);
55 if (ret != (int) io_u->xfer_buflen) {
57 io_u->resid = io_u->xfer_buflen - ret;
59 return FIO_Q_COMPLETED;
65 td_verror(td, io_u->error, "xfer");
67 return FIO_Q_COMPLETED;
70 static int fio_psyncio_init(struct thread_data *td)
72 td->io_ops->data = (void *) 1;
76 static struct ioengine_ops ioengine_rw = {
78 .version = FIO_IOOPS_VERSION,
79 .prep = fio_syncio_prep,
80 .queue = fio_syncio_queue,
81 .open_file = generic_open_file,
82 .close_file = generic_close_file,
86 static struct ioengine_ops ioengine_prw = {
88 .version = FIO_IOOPS_VERSION,
89 .queue = fio_syncio_queue,
90 .init = fio_psyncio_init,
91 .open_file = generic_open_file,
92 .close_file = generic_close_file,
96 static void fio_init fio_syncio_register(void)
98 register_ioengine(&ioengine_rw);
99 register_ioengine(&ioengine_prw);
102 static void fio_exit fio_syncio_unregister(void)
104 unregister_ioengine(&ioengine_rw);
105 unregister_ioengine(&ioengine_prw);