Don't malloc/memcpy ioengine_ops on td initialization
[fio.git] / engines / glusterfs.c
index 94daab5a2936a0052ed6fb8f3a3b11b068c76358..2abc283fc048f1580271cb257e1831454e5a3f18 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "gfapi.h"
+#include "../optgroup.h"
 
 struct fio_option gfapi_options[] = {
        {
@@ -40,7 +41,7 @@ int fio_gf_setup(struct thread_data *td)
 
        dprint(FD_IO, "fio setup\n");
 
-       if (td->io_ops->data)
+       if (td->io_ops_data)
                return 0;
 
        g = malloc(sizeof(struct gf_data));
@@ -76,23 +77,19 @@ int fio_gf_setup(struct thread_data *td)
                goto cleanup;
        }
        dprint(FD_FILE, "fio setup %p\n", g->fs);
-       td->io_ops->data = g;
+       td->io_ops_data = g;
+       return 0;
 cleanup:
-       if (r) {
-               if (g) {
-                       if (g->fs) {
-                               glfs_fini(g->fs);
-                       }
-                       free(g);
-                       td->io_ops->data = NULL;
-               }
-       }
+       if (g->fs)
+               glfs_fini(g->fs);
+       free(g);
+       td->io_ops_data = NULL;
        return r;
 }
 
 void fio_gf_cleanup(struct thread_data *td)
 {
-       struct gf_data *g = td->io_ops->data;
+       struct gf_data *g = td->io_ops_data;
 
        if (g) {
                if (g->aio_events)
@@ -102,7 +99,7 @@ void fio_gf_cleanup(struct thread_data *td)
                if (g->fs)
                        glfs_fini(g->fs);
                free(g);
-               td->io_ops->data = NULL;
+               td->io_ops_data = NULL;
        }
 }
 
@@ -110,7 +107,7 @@ int fio_gf_get_file_size(struct thread_data *td, struct fio_file *f)
 {
        struct stat buf;
        int ret;
-       struct gf_data *g = td->io_ops->data;
+       struct gf_data *g = td->io_ops_data;
 
        dprint(FD_FILE, "get file size %s\n", f->file_name);
 
@@ -138,7 +135,7 @@ int fio_gf_open_file(struct thread_data *td, struct fio_file *f)
 
        int flags = 0;
        int ret = 0;
-       struct gf_data *g = td->io_ops->data;
+       struct gf_data *g = td->io_ops_data;
        struct stat sb = { 0, };
 
        if (td_write(td)) {
@@ -160,8 +157,9 @@ int fio_gf_open_file(struct thread_data *td, struct fio_file *f)
               flags & O_RDONLY ? "ro" : "rw", td_read(td) ? "read" : "write");
        g->fd = glfs_creat(g->fs, f->file_name, flags, 0644);
        if (!g->fd) {
-               log_err("glfs_creat failed.\n");
                ret = errno;
+               log_err("glfs_creat failed.\n");
+               return ret;
        }
        /* file for read doesn't exist or shorter than required, create/extend it */
        if (td_read(td)) {
@@ -226,10 +224,10 @@ int fio_gf_open_file(struct thread_data *td, struct fio_file *f)
                                        free(b);
                                glfs_lseek(g->fd, 0, SEEK_SET);
 
-                               if (td->terminate) {
+                               if (td->terminate && td->o.unlink) {
                                        dprint(FD_FILE, "terminate unlink %s\n",
                                               f->file_name);
-                                       unlink(f->file_name);
+                                       glfs_unlink(g->fs, f->file_name);
                                } else if (td->o.create_fsync) {
                                        if (glfs_fsync(g->fd) < 0) {
                                                dprint(FD_FILE,
@@ -263,20 +261,38 @@ int fio_gf_open_file(struct thread_data *td, struct fio_file *f)
        dprint(FD_FILE, "fio %p created %s\n", g->fs, f->file_name);
        f->fd = -1;
        f->shadow_fd = -1;
-
+       td->o.open_files ++;
        return ret;
 }
 
 int fio_gf_close_file(struct thread_data *td, struct fio_file *f)
 {
        int ret = 0;
-       struct gf_data *g = td->io_ops->data;
+       struct gf_data *g = td->io_ops_data;
 
        dprint(FD_FILE, "fd close %s\n", f->file_name);
 
        if (g) {
                if (g->fd && glfs_close(g->fd) < 0)
                        ret = errno;
+               g->fd = NULL;
+       }
+
+       return ret;
+}
+
+int fio_gf_unlink_file(struct thread_data *td, struct fio_file *f)
+{
+       int ret = 0;
+       struct gf_data *g = td->io_ops_data;
+
+       dprint(FD_FILE, "fd unlink %s\n", f->file_name);
+
+       if (g) {
+               if (g->fd && glfs_close(g->fd) < 0)
+                       ret = errno;
+
+               glfs_unlink(g->fs, f->file_name);
 
                if (g->fs)
                        glfs_fini(g->fs);
@@ -284,8 +300,7 @@ int fio_gf_close_file(struct thread_data *td, struct fio_file *f)
                g->fd = NULL;
                free(g);
        }
-       td->io_ops->data = NULL;
-       f->engine_data = 0;
+       td->io_ops_data = NULL;
 
        return ret;
 }