[PATCH] Implement file syncing as data direction
[fio.git] / engines / fio-engine-posixaio.c
index 871db77c03152f51dbb42fc058a4b60b11b099cb..2d0fd3114b6469729997721643f8d66e3826451f 100644 (file)
@@ -45,14 +45,11 @@ static unsigned long long ts_utime_since_now(struct timespec *t)
        return sec + nsec;
 }
 
-static int fio_posixaio_sync(struct thread_data *td)
+static int fio_posixaio_cancel(struct thread_data fio_unused *td,
+                              struct io_u *io_u)
 {
-       return fsync(td->fd);
-}
-
-static int fio_posixaio_cancel(struct thread_data *td, struct io_u *io_u)
-{
-       int r = aio_cancel(td->fd, &io_u->aiocb);
+       struct fio_file *f = io_u->file;
+       int r = aio_cancel(f->fd, &io_u->aiocb);
 
        if (r == 1 || r == AIO_CANCELED)
                return 0;
@@ -60,11 +57,13 @@ static int fio_posixaio_cancel(struct thread_data *td, struct io_u *io_u)
        return 1;
 }
 
-static int fio_posixaio_prep(struct thread_data *td, struct io_u *io_u)
+static int fio_posixaio_prep(struct thread_data fio_unused *td,
+                            struct io_u *io_u)
 {
        struct aiocb *aiocb = &io_u->aiocb;
+       struct fio_file *f = io_u->file;
 
-       aiocb->aio_fildes = td->fd;
+       aiocb->aio_fildes = f->fd;
        aiocb->aio_buf = io_u->buf;
        aiocb->aio_nbytes = io_u->buflen;
        aiocb->aio_offset = io_u->offset;
@@ -144,8 +143,10 @@ static int fio_posixaio_queue(struct thread_data fio_unused *td,
 
        if (io_u->ddir == DDIR_READ)
                ret = aio_read(aiocb);
-       else
+       else if (io_u->ddir == DDIR_WRITE)
                ret = aio_write(aiocb);
+       else
+               ret = aio_fsync(O_SYNC, aiocb);
 
        if (ret)
                io_u->error = errno;
@@ -184,5 +185,4 @@ struct ioengine_ops ioengine = {
        .getevents      = fio_posixaio_getevents,
        .event          = fio_posixaio_event,
        .cleanup        = fio_posixaio_cleanup,
-       .sync           = fio_posixaio_sync,
 };