fio: build warning fix on gcc-3.4.6-3
[fio.git] / engines / sync.c
1 /*
2  * sync engine
3  *
4  * IO engine that does regular read(2)/write(2) with lseek(2) to transfer
5  * data.
6  *
7  */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <errno.h>
12 #include <assert.h>
13
14 #include "../fio.h"
15
16 static int fio_syncio_prep(struct thread_data *td, struct io_u *io_u)
17 {
18         struct fio_file *f = io_u->file;
19
20         if (io_u->ddir == DDIR_SYNC)
21                 return 0;
22         if (io_u->offset == f->last_completed_pos)
23                 return 0;
24
25         if (lseek(f->fd, io_u->offset, SEEK_SET) == -1) {
26                 td_verror(td, errno, "lseek");
27                 return 1;
28         }
29
30         return 0;
31 }
32
33 static int fio_syncio_queue(struct thread_data *td, struct io_u *io_u)
34 {
35         struct fio_file *f = io_u->file;
36         int ret;
37
38         fio_ro_check(td, io_u);
39
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);
44         else
45                 ret = fsync(f->fd);
46
47         if (ret != (int) io_u->xfer_buflen) {
48                 if (ret >= 0) {
49                         io_u->resid = io_u->xfer_buflen - ret;
50                         io_u->error = 0;
51                         return FIO_Q_COMPLETED;
52                 } else
53                         io_u->error = errno;
54         }
55
56         if (io_u->error)
57                 td_verror(td, io_u->error, "xfer");
58
59         return FIO_Q_COMPLETED;
60 }
61
62 static struct ioengine_ops ioengine = {
63         .name           = "sync",
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,
69         .flags          = FIO_SYNCIO,
70 };
71
72 static void fio_init fio_syncio_register(void)
73 {
74         register_ioengine(&ioengine);
75 }
76
77 static void fio_exit fio_syncio_unregister(void)
78 {
79         unregister_ioengine(&ioengine);
80 }