options: split out option grouping code
[fio.git] / engines / glusterfs.c
index b233b207eb49dec4e5477b16d83de48d1a7f31b0..dec9fb5f6597c0754f8ee97da2193f253ebf8346 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include "gfapi.h"
+#include "../optgroup.h"
 
 struct fio_option gfapi_options[] = {
        {
@@ -77,16 +78,12 @@ int fio_gf_setup(struct thread_data *td)
        }
        dprint(FD_FILE, "fio setup %p\n", g->fs);
        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;
 }
 
@@ -150,12 +147,19 @@ int fio_gf_open_file(struct thread_data *td, struct fio_file *f)
                else
                        flags = O_RDONLY;
        }
+
+       if (td->o.odirect)
+               flags |= OS_O_DIRECT;
+       if (td->o.sync_io)
+               flags |= O_SYNC;
+
        dprint(FD_FILE, "fio file %s open mode %s td rw %s\n", f->file_name,
-              flags == O_RDONLY ? "ro" : "rw", td_read(td) ? "read" : "write");
+              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)) {
@@ -220,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,
@@ -257,7 +261,7 @@ 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;
 }
 
@@ -271,6 +275,24 @@ int fio_gf_close_file(struct thread_data *td, struct fio_file *f)
        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);
@@ -279,7 +301,6 @@ int fio_gf_close_file(struct thread_data *td, struct fio_file *f)
                free(g);
        }
        td->io_ops->data = NULL;
-       f->engine_data = 0;
 
        return ret;
 }