Add file locking hooks
[fio.git] / ioengines.c
index 979ac28322fdff473b31dbda5a3240cced718324..5a2d6b90fb0c6d73d45d0b6c5ce5307f505691d2 100644 (file)
@@ -168,10 +168,14 @@ int td_io_prep(struct thread_data *td, struct io_u *io_u)
        dprint_io_u(io_u, "prep");
        fio_ro_check(td, io_u);
 
+       lock_file(td, io_u->file);
+
        if (td->io_ops->prep) {
                int ret = td->io_ops->prep(td, io_u);
 
                dprint(FD_IO, "->prep(%p)=%d\n", io_u, ret);
+               if (ret)
+                       unlock_file(io_u->file);
                return ret;
        }
 
@@ -228,6 +232,8 @@ int td_io_queue(struct thread_data *td, struct io_u *io_u)
 
        ret = td->io_ops->queue(td, io_u);
 
+       unlock_file(io_u->file);
+
        if (ret != FIO_Q_BUSY)
                io_u_mark_depth(td, io_u);
 
@@ -303,7 +309,6 @@ int td_io_open_file(struct thread_data *td, struct fio_file *f)
        }
 
        f->last_free_lookup = 0;
-       f->last_completed_pos = 0;
        f->last_pos = f->file_offset;
        f->flags |= FIO_FILE_OPEN;
        f->flags &= ~FIO_FILE_CLOSING;
@@ -344,7 +349,7 @@ err:
        return 1;
 }
 
-void td_io_close_file(struct thread_data *td, struct fio_file *f)
+int td_io_close_file(struct thread_data *td, struct fio_file *f)
 {
        if (!(f->flags & FIO_FILE_CLOSING))
                log_file(td, f, FIO_LOG_CLOSE_FILE);
@@ -354,5 +359,5 @@ void td_io_close_file(struct thread_data *td, struct fio_file *f)
         */
        f->flags |= FIO_FILE_CLOSING;
 
-       put_file(td, f);
+       return put_file(td, f);
 }