[PATCH] Make ->buflen == 0 on SYNC io_u's
[fio.git] / engines / fio-engine-sync.c
index d5be4c8256ecda8415cbe438883d141758acfda7..43f42ca2ffcace7068656a0ebd4453453af69d7b 100644 (file)
@@ -14,12 +14,6 @@ struct syncio_data {
        struct io_u *last_io_u;
 };
 
-static int fio_syncio_sync(struct thread_data fio_unused *td,
-                          struct fio_file *f)
-{
-       return fsync(f->fd);
-}
-
 static int fio_syncio_getevents(struct thread_data *td, int fio_unused min,
                                int max, struct timespec fio_unused *t)
 {
@@ -48,6 +42,9 @@ static int fio_syncio_prep(struct thread_data *td, struct io_u *io_u)
 {
        struct fio_file *f = io_u->file;
 
+       if (io_u->ddir == DDIR_SYNC)
+               return 0;
+
        if (lseek(f->fd, io_u->offset, SEEK_SET) == -1) {
                td_verror(td, errno);
                return 1;
@@ -60,14 +57,16 @@ static int fio_syncio_queue(struct thread_data *td, struct io_u *io_u)
 {
        struct syncio_data *sd = td->io_ops->data;
        struct fio_file *f = io_u->file;
-       int ret;
+       unsigned int ret;
 
        if (io_u->ddir == DDIR_READ)
                ret = read(f->fd, io_u->buf, io_u->buflen);
-       else
+       else if (io_u->ddir == DDIR_WRITE)
                ret = write(f->fd, io_u->buf, io_u->buflen);
+       else
+               ret = fsync(f->fd);
 
-       if ((unsigned int) ret != io_u->buflen) {
+       if (ret != io_u->buflen) {
                if (ret > 0) {
                        io_u->resid = io_u->buflen - ret;
                        io_u->error = EIO;
@@ -107,6 +106,5 @@ struct ioengine_ops ioengine = {
        .getevents      = fio_syncio_getevents,
        .event          = fio_syncio_event,
        .cleanup        = fio_syncio_cleanup,
-       .sync           = fio_syncio_sync,
        .flags          = FIO_SYNCIO,
 };