Add file locking hooks
[fio.git] / filesetup.c
index b29db3f3f237032db28c1ec1d4fdc4cc6b6c050f..188b0ce88c476633b0a42931ef901dc9000b171c 100644 (file)
@@ -209,11 +209,16 @@ int file_invalidate_cache(struct thread_data *td, struct fio_file *f)
        return ret;
 }
 
-void generic_close_file(struct thread_data fio_unused *td, struct fio_file *f)
+int generic_close_file(struct thread_data fio_unused *td, struct fio_file *f)
 {
+       int ret = 0;
+
        dprint(FD_FILE, "fd close %s\n", f->file_name);
-       close(f->fd);
+       if (close(f->fd) < 0)
+               ret = errno;
+
        f->fd = -1;
+       return ret;
 }
 
 int generic_open_file(struct thread_data *td, struct fio_file *f)
@@ -520,6 +525,15 @@ void close_files(struct thread_data *td)
        struct fio_file *f;
        unsigned int i;
 
+       for_each_file(td, f, i)
+               td_io_close_file(td, f);
+}
+
+void close_and_free_files(struct thread_data *td)
+{
+       struct fio_file *f;
+       unsigned int i;
+
        dprint(FD_FILE, "close files\n");
 
        for_each_file(td, f, i) {
@@ -571,12 +585,14 @@ int add_file(struct thread_data *td, const char *fname)
 
        dprint(FD_FILE, "add file %s\n", fname);
 
-       td->files = realloc(td->files, (cur_files + 1) * sizeof(*f));
-
-       f = &td->files[cur_files];
+       f = malloc(sizeof(*f));
        memset(f, 0, sizeof(*f));
        f->fd = -1;
 
+       td->files = realloc(td->files, (cur_files + 1) * sizeof(f));
+
+       td->files[cur_files] = f;
+
        /*
         * init function, io engine may not be loaded yet
         */
@@ -605,25 +621,36 @@ void get_file(struct fio_file *f)
        f->references++;
 }
 
-void put_file(struct thread_data *td, struct fio_file *f)
+int put_file(struct thread_data *td, struct fio_file *f)
 {
+       int ret = 0;
+
        dprint(FD_FILE, "put file %s, ref=%d\n", f->file_name, f->references);
 
        if (!(f->flags & FIO_FILE_OPEN))
-               return;
+               return 0;
 
        assert(f->references);
        if (--f->references)
-               return;
+               return 0;
 
        if (should_fsync(td) && td->o.fsync_on_close)
                fsync(f->fd);
 
        if (td->io_ops->close_file)
-               td->io_ops->close_file(td, f);
+               ret = td->io_ops->close_file(td, f);
 
        td->nr_open_files--;
        f->flags &= ~FIO_FILE_OPEN;
+       return ret;
+}
+
+void lock_file(struct thread_data *td, struct fio_file *f)
+{
+}
+
+void unlock_file(struct fio_file *f)
+{
 }
 
 static int recurse_dir(struct thread_data *td, const char *dirname)