s3: VFS: vfs_media_harmony. Implement symlinkat().
[samba.git] / source3 / modules / vfs_glusterfs.c
index 7a42d869d40ed2ecfdc385e4ce893f5624880104..3c0648ba28b5506db147ce58d04db713eb839200 100644 (file)
 #include "includes.h"
 #include "smbd/smbd.h"
 #include <stdio.h>
-#include "api/glfs.h"
+#include <glusterfs/api/glfs.h>
 #include "lib/util/dlinklist.h"
 #include "lib/util/tevent_unix.h"
 #include "smbd/globals.h"
 #include "lib/util/sys_rw.h"
 #include "smbprofile.h"
 #include "modules/posixacl_xattr.h"
+#include "lib/pthreadpool/pthreadpool_tevent.h"
 
 #define DEFAULT_VOLFILE_SERVER "localhost"
-
-static int read_fd = -1;
-static int write_fd = -1;
-static struct tevent_fd *aio_read_event = NULL;
+#define GLUSTER_NAME_MAX 255
 
 /**
  * Helper to convert struct stat to struct stat_ex.
@@ -73,12 +71,16 @@ static void smb_stat_ex_from_stat(struct stat_ex *dst, const struct stat *src)
        dst->st_ex_btime.tv_sec = src->st_mtime;
        dst->st_ex_blksize = src->st_blksize;
        dst->st_ex_blocks = src->st_blocks;
+       dst->st_ex_file_id = dst->st_ex_ino;
+       dst->st_ex_iflags |= ST_EX_IFLAG_CALCULATED_FILE_ID;
 #ifdef STAT_HAVE_NSEC
        dst->st_ex_atime.tv_nsec = src->st_atime_nsec;
        dst->st_ex_mtime.tv_nsec = src->st_mtime_nsec;
        dst->st_ex_ctime.tv_nsec = src->st_ctime_nsec;
        dst->st_ex_btime.tv_nsec = src->st_mtime_nsec;
 #endif
+       dst->st_ex_itime = dst->st_ex_btime;
+       dst->st_ex_iflags |= ST_EX_IFLAG_CALCULATED_ITIME;
 }
 
 /* pre-opened glfs_t */
@@ -161,8 +163,8 @@ static int vfs_gluster_set_volfile_servers(glfs_t *fs,
                                           const char *volfile_servers)
 {
        char *server = NULL;
-       int   server_count = 0;
-       int   server_success = 0;
+       size_t server_count = 0;
+       size_t server_success = 0;
        int   ret = -1;
        TALLOC_CTX *frame = talloc_stackframe();
 
@@ -174,7 +176,7 @@ static int vfs_gluster_set_volfile_servers(glfs_t *fs,
                int   port = 0;
 
                server_count++;
-               DBG_INFO("server %d %s\n", server_count, server);
+               DBG_INFO("server %zu %s\n", server_count, server);
 
                /* Determine the transport type */
                if (strncmp(server, "unix+", 5) == 0) {
@@ -251,7 +253,7 @@ out:
        if (server_count == 0) {
                ret = -1;
        } else if (server_success < server_count) {
-               DBG_WARNING("Failed to set %d out of %d servers parsed\n",
+               DBG_WARNING("Failed to set %zu out of %zu servers parsed\n",
                            server_count - server_success, server_count);
                ret = 0;
        }
@@ -352,6 +354,21 @@ static int vfs_gluster_connect(struct vfs_handle_struct *handle,
                          volume, strerror(errno)));
                goto done;
        }
+
+       /*
+        * The shadow_copy2 module will fail to export subdirectories
+        * of a gluster volume unless we specify the mount point,
+        * because the detection fails if the file system is not
+        * locally mounted:
+        * https://bugzilla.samba.org/show_bug.cgi?id=13091
+        */
+       lp_do_parameter(SNUM(handle->conn), "shadow:mountpoint", "/");
+
+       /*
+        * Unless we have an async implementation of getxattrat turn this off.
+        */
+       lp_do_parameter(SNUM(handle->conn), "smbd async dosmode", "false");
+
 done:
        if (ret < 0) {
                if (fs)
@@ -454,6 +471,10 @@ static uint32_t vfs_gluster_fs_capabilities(struct vfs_handle_struct *handle,
 {
        uint32_t caps = FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
 
+#ifdef HAVE_GFAPI_VER_6
+       caps |= FILE_SUPPORTS_SPARSE_FILES;
+#endif
+
 #ifdef STAT_HAVE_NSEC
        *p_ts_res = TIMESTAMP_SET_NT_OR_BETTER;
 #endif
@@ -468,25 +489,57 @@ static DIR *vfs_gluster_opendir(struct vfs_handle_struct *handle,
 {
        glfs_fd_t *fd;
 
+       START_PROFILE(syscall_opendir);
+
        fd = glfs_opendir(handle->data, smb_fname->base_name);
        if (fd == NULL) {
                DEBUG(0, ("glfs_opendir(%s) failed: %s\n",
                          smb_fname->base_name, strerror(errno)));
        }
 
+       END_PROFILE(syscall_opendir);
+
        return (DIR *) fd;
 }
 
+static glfs_fd_t *vfs_gluster_fetch_glfd(struct vfs_handle_struct *handle,
+                                        files_struct *fsp)
+{
+       glfs_fd_t **glfd = (glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp);
+       if (glfd == NULL) {
+               DBG_INFO("Failed to fetch fsp extension\n");
+               return NULL;
+       }
+       if (*glfd == NULL) {
+               DBG_INFO("Empty glfs_fd_t pointer\n");
+               return NULL;
+       }
+
+       return *glfd;
+}
+
 static DIR *vfs_gluster_fdopendir(struct vfs_handle_struct *handle,
                                  files_struct *fsp, const char *mask,
                                  uint32_t attributes)
 {
-       return (DIR *) *(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp);
+       glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return NULL;
+       }
+
+       return (DIR *)glfd;
 }
 
 static int vfs_gluster_closedir(struct vfs_handle_struct *handle, DIR *dirp)
 {
-       return glfs_closedir((void *)dirp);
+       int ret;
+
+       START_PROFILE(syscall_closedir);
+       ret = glfs_closedir((void *)dirp);
+       END_PROFILE(syscall_closedir);
+
+       return ret;
 }
 
 static struct dirent *vfs_gluster_readdir(struct vfs_handle_struct *handle,
@@ -497,6 +550,7 @@ static struct dirent *vfs_gluster_readdir(struct vfs_handle_struct *handle,
        struct stat stat;
        struct dirent *dirent = 0;
 
+       START_PROFILE(syscall_readdir);
        if (sbuf != NULL) {
                ret = glfs_readdirplus_r((void *)dirp, &stat, (void *)direntbuf,
                                         &dirent);
@@ -505,6 +559,7 @@ static struct dirent *vfs_gluster_readdir(struct vfs_handle_struct *handle,
        }
 
        if ((ret < 0) || (dirent == NULL)) {
+               END_PROFILE(syscall_readdir);
                return NULL;
        }
 
@@ -512,42 +567,59 @@ static struct dirent *vfs_gluster_readdir(struct vfs_handle_struct *handle,
                smb_stat_ex_from_stat(sbuf, &stat);
        }
 
+       END_PROFILE(syscall_readdir);
        return dirent;
 }
 
 static long vfs_gluster_telldir(struct vfs_handle_struct *handle, DIR *dirp)
 {
-       return glfs_telldir((void *)dirp);
+       long ret;
+
+       START_PROFILE(syscall_telldir);
+       ret = glfs_telldir((void *)dirp);
+       END_PROFILE(syscall_telldir);
+
+       return ret;
 }
 
 static void vfs_gluster_seekdir(struct vfs_handle_struct *handle, DIR *dirp,
                                long offset)
 {
+       START_PROFILE(syscall_seekdir);
        glfs_seekdir((void *)dirp, offset);
+       END_PROFILE(syscall_seekdir);
 }
 
 static void vfs_gluster_rewinddir(struct vfs_handle_struct *handle, DIR *dirp)
 {
+       START_PROFILE(syscall_rewinddir);
        glfs_seekdir((void *)dirp, 0);
-}
-
-static void vfs_gluster_init_search_op(struct vfs_handle_struct *handle,
-                                      DIR *dirp)
-{
-       return;
+       END_PROFILE(syscall_rewinddir);
 }
 
 static int vfs_gluster_mkdir(struct vfs_handle_struct *handle,
                             const struct smb_filename *smb_fname,
                             mode_t mode)
 {
-       return glfs_mkdir(handle->data, smb_fname->base_name, mode);
+       int ret;
+
+       START_PROFILE(syscall_mkdir);
+       ret = glfs_mkdir(handle->data, smb_fname->base_name, mode);
+       END_PROFILE(syscall_mkdir);
+
+       return ret;
 }
 
 static int vfs_gluster_rmdir(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname)
 {
-       return glfs_rmdir(handle->data, smb_fname->base_name);
+       int ret;
+
+       START_PROFILE(syscall_rmdir);
+       ret = glfs_rmdir(handle->data, smb_fname->base_name);
+       END_PROFILE(syscall_rmdir);
+
+       return ret;
 }
 
 static int vfs_gluster_open(struct vfs_handle_struct *handle,
@@ -557,6 +629,15 @@ static int vfs_gluster_open(struct vfs_handle_struct *handle,
        glfs_fd_t *glfd;
        glfs_fd_t **p_tmp;
 
+       START_PROFILE(syscall_open);
+
+       p_tmp = VFS_ADD_FSP_EXTENSION(handle, fsp, glfs_fd_t *, NULL);
+       if (p_tmp == NULL) {
+               END_PROFILE(syscall_open);
+               errno = ENOMEM;
+               return -1;
+       }
+
        if (flags & O_DIRECTORY) {
                glfd = glfs_opendir(handle->data, smb_fname->base_name);
        } else if (flags & O_CREAT) {
@@ -567,11 +648,15 @@ static int vfs_gluster_open(struct vfs_handle_struct *handle,
        }
 
        if (glfd == NULL) {
+               END_PROFILE(syscall_open);
+               /* no extension destroy_fn, so no need to save errno */
+               VFS_REMOVE_FSP_EXTENSION(handle, fsp);
                return -1;
        }
-       p_tmp = (glfs_fd_t **)VFS_ADD_FSP_EXTENSION(handle, fsp,
-                                                         glfs_fd_t *, NULL);
+
        *p_tmp = glfd;
+
+       END_PROFILE(syscall_open);
        /* An arbitrary value for error reporting, so you know its us. */
        return 13371337;
 }
@@ -579,324 +664,376 @@ static int vfs_gluster_open(struct vfs_handle_struct *handle,
 static int vfs_gluster_close(struct vfs_handle_struct *handle,
                             files_struct *fsp)
 {
-       glfs_fd_t *glfd;
-       glfd = *(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp);
+       int ret;
+       glfs_fd_t *glfd = NULL;
+
+       START_PROFILE(syscall_close);
+
+       glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               END_PROFILE(syscall_close);
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return -1;
+       }
+
        VFS_REMOVE_FSP_EXTENSION(handle, fsp);
-       return glfs_close(glfd);
-}
 
-static ssize_t vfs_gluster_read(struct vfs_handle_struct *handle,
-                               files_struct *fsp, void *data, size_t n)
-{
-       return glfs_read(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), data, n, 0);
+       ret = glfs_close(glfd);
+       END_PROFILE(syscall_close);
+
+       return ret;
 }
 
 static ssize_t vfs_gluster_pread(struct vfs_handle_struct *handle,
                                 files_struct *fsp, void *data, size_t n,
                                 off_t offset)
 {
-       return glfs_pread(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), data, n, offset, 0);
-}
+       ssize_t ret;
+       glfs_fd_t *glfd = NULL;
 
-struct glusterfs_aio_state;
+       START_PROFILE_BYTES(syscall_pread, n);
 
-struct glusterfs_aio_wrapper {
-       struct glusterfs_aio_state *state;
-};
+       glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               END_PROFILE_BYTES(syscall_pread);
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return -1;
+       }
+
+#ifdef HAVE_GFAPI_VER_7_6
+       ret = glfs_pread(glfd, data, n, offset, 0, NULL);
+#else
+       ret = glfs_pread(glfd, data, n, offset, 0);
+#endif
+       END_PROFILE_BYTES(syscall_pread);
+
+       return ret;
+}
 
-struct glusterfs_aio_state {
+struct vfs_gluster_pread_state {
        ssize_t ret;
-       struct tevent_req *req;
-       bool cancelled;
+       glfs_fd_t *fd;
+       void *buf;
+       size_t count;
+       off_t offset;
+
        struct vfs_aio_state vfs_aio_state;
-       struct timespec start;
+       SMBPROFILE_BYTES_ASYNC_STATE(profile_bytes);
 };
 
-static int aio_wrapper_destructor(struct glusterfs_aio_wrapper *wrap)
-{
-       if (wrap->state != NULL) {
-               wrap->state->cancelled = true;
-       }
-
-       return 0;
-}
+static void vfs_gluster_pread_do(void *private_data);
+static void vfs_gluster_pread_done(struct tevent_req *subreq);
+static int vfs_gluster_pread_state_destructor(struct vfs_gluster_pread_state *state);
 
-/*
- * This function is the callback that will be called on glusterfs
- * threads once the async IO submitted is complete. To notify
- * Samba of the completion we use a pipe based queue.
- */
-static void aio_glusterfs_done(glfs_fd_t *fd, ssize_t ret, void *data)
+static struct tevent_req *vfs_gluster_pread_send(struct vfs_handle_struct
+                                                 *handle, TALLOC_CTX *mem_ctx,
+                                                 struct tevent_context *ev,
+                                                 files_struct *fsp,
+                                                 void *data, size_t n,
+                                                 off_t offset)
 {
-       struct glusterfs_aio_state *state = NULL;
-       int sts = 0;
-       struct timespec end;
-
-       state = (struct glusterfs_aio_state *)data;
+       struct vfs_gluster_pread_state *state;
+       struct tevent_req *req, *subreq;
 
-       PROFILE_TIMESTAMP(&end);
+       glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return NULL;
+       }
 
-       if (ret < 0) {
-               state->ret = -1;
-               state->vfs_aio_state.error = errno;
-       } else {
-               state->ret = ret;
+       req = tevent_req_create(mem_ctx, &state, struct vfs_gluster_pread_state);
+       if (req == NULL) {
+               return NULL;
        }
-       state->vfs_aio_state.duration = nsec_time_diff(&end, &state->start);
 
-       /*
-        * Write the state pointer to glusterfs_aio_state to the
-        * pipe, so we can call tevent_req_done() from the main thread,
-        * because tevent_req_done() is not designed to be executed in
-        * the multithread environment, so tevent_req_done() must be
-        * executed from the smbd main thread.
-        *
-        * write(2) on pipes with sizes under _POSIX_PIPE_BUF
-        * in size is atomic, without this, the use op pipes in this
-        * code would not work.
-        *
-        * sys_write is a thin enough wrapper around write(2)
-        * that we can trust it here.
-        */
+       state->ret = -1;
+       state->fd = glfd;
+       state->buf = data;
+       state->count = n;
+       state->offset = offset;
 
-       sts = sys_write(write_fd, &state, sizeof(struct glusterfs_aio_state *));
-       if (sts < 0) {
-               DEBUG(0,("\nWrite to pipe failed (%s)", strerror(errno)));
+       SMBPROFILE_BYTES_ASYNC_START(syscall_asys_pread, profile_p,
+                                    state->profile_bytes, n);
+       SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
+
+       subreq = pthreadpool_tevent_job_send(
+               state, ev, handle->conn->sconn->pool,
+               vfs_gluster_pread_do, state);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
        }
+       tevent_req_set_callback(subreq, vfs_gluster_pread_done, req);
+
+       talloc_set_destructor(state, vfs_gluster_pread_state_destructor);
 
-       return;
+       return req;
 }
 
-/*
- * Read each req off the pipe and process it.
- */
-static void aio_tevent_fd_done(struct tevent_context *event_ctx,
-                               struct tevent_fd *fde,
-                               uint16_t flags, void *data)
+static void vfs_gluster_pread_do(void *private_data)
 {
-       struct tevent_req *req = NULL;
-       struct glusterfs_aio_state *state = NULL;
-       int sts = 0;
+       struct vfs_gluster_pread_state *state = talloc_get_type_abort(
+               private_data, struct vfs_gluster_pread_state);
+       struct timespec start_time;
+       struct timespec end_time;
 
-       /*
-        * read(2) on pipes is atomic if the needed data is available
-        * in the pipe, per SUS and POSIX.  Because we always write
-        * to the pipe in sizeof(struct tevent_req *) chunks, we can
-        * always read in those chunks, atomically.
-        *
-        * sys_read is a thin enough wrapper around read(2) that we
-        * can trust it here.
-        */
+       SMBPROFILE_BYTES_ASYNC_SET_BUSY(state->profile_bytes);
 
-       sts = sys_read(read_fd, &state, sizeof(struct glusterfs_aio_state *));
+       PROFILE_TIMESTAMP(&start_time);
 
-       if (sts < 0) {
-               DEBUG(0,("\nRead from pipe failed (%s)", strerror(errno)));
-       }
+       do {
+#ifdef HAVE_GFAPI_VER_7_6
+               state->ret = glfs_pread(state->fd, state->buf, state->count,
+                                       state->offset, 0, NULL);
+#else
+               state->ret = glfs_pread(state->fd, state->buf, state->count,
+                                       state->offset, 0);
+#endif
+       } while ((state->ret == -1) && (errno == EINTR));
 
-       /* if we've cancelled the op, there is no req, so just clean up. */
-       if (state->cancelled == true) {
-               TALLOC_FREE(state);
-               return;
+       if (state->ret == -1) {
+               state->vfs_aio_state.error = errno;
        }
 
-       req = state->req;
+       PROFILE_TIMESTAMP(&end_time);
 
-       if (req) {
-               tevent_req_done(req);
-       }
-       return;
+       state->vfs_aio_state.duration = nsec_time_diff(&end_time, &start_time);
+
+       SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
 }
 
-static bool init_gluster_aio(struct vfs_handle_struct *handle)
+static int vfs_gluster_pread_state_destructor(struct vfs_gluster_pread_state *state)
 {
-       int fds[2];
-       int ret = -1;
+       return -1;
+}
 
-       if (read_fd != -1) {
+static void vfs_gluster_pread_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct vfs_gluster_pread_state *state = tevent_req_data(
+               req, struct vfs_gluster_pread_state);
+       int ret;
+
+       ret = pthreadpool_tevent_job_recv(subreq);
+       TALLOC_FREE(subreq);
+       SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
+       talloc_set_destructor(state, NULL);
+       if (ret != 0) {
+               if (ret != EAGAIN) {
+                       tevent_req_error(req, ret);
+                       return;
+               }
                /*
-                * Already initialized.
+                * If we get EAGAIN from pthreadpool_tevent_job_recv() this
+                * means the lower level pthreadpool failed to create a new
+                * thread. Fallback to sync processing in that case to allow
+                * some progress for the client.
                 */
-               return true;
+               vfs_gluster_pread_do(state);
        }
 
-       ret = pipe(fds);
-       if (ret == -1) {
-               goto fail;
-       }
-
-       read_fd = fds[0];
-       write_fd = fds[1];
-
-       aio_read_event = tevent_add_fd(handle->conn->sconn->ev_ctx,
-                                       NULL,
-                                       read_fd,
-                                       TEVENT_FD_READ,
-                                       aio_tevent_fd_done,
-                                       NULL);
-       if (aio_read_event == NULL) {
-               goto fail;
-       }
-
-       return true;
-fail:
-       TALLOC_FREE(aio_read_event);
-       if (read_fd != -1) {
-               close(read_fd);
-               close(write_fd);
-               read_fd = -1;
-               write_fd = -1;
-       }
-       return false;
+       tevent_req_done(req);
 }
 
-static struct glusterfs_aio_state *aio_state_create(TALLOC_CTX *mem_ctx)
+static ssize_t vfs_gluster_pread_recv(struct tevent_req *req,
+                                     struct vfs_aio_state *vfs_aio_state)
 {
-       struct tevent_req *req = NULL;
-       struct glusterfs_aio_state *state = NULL;
-       struct glusterfs_aio_wrapper *wrapper = NULL;
+       struct vfs_gluster_pread_state *state = tevent_req_data(
+               req, struct vfs_gluster_pread_state);
 
-       req = tevent_req_create(mem_ctx, &wrapper, struct glusterfs_aio_wrapper);
-
-       if (req == NULL) {
-               return NULL;
+       if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
+               return -1;
        }
 
-       state = talloc_zero(NULL, struct glusterfs_aio_state);
-
-       if (state == NULL) {
-               TALLOC_FREE(req);
-               return NULL;
-       }
+       *vfs_aio_state = state->vfs_aio_state;
+       return state->ret;
+}
 
-       talloc_set_destructor(wrapper, aio_wrapper_destructor);
-       state->cancelled = false;
-       state->req = req;
+struct vfs_gluster_pwrite_state {
+       ssize_t ret;
+       glfs_fd_t *fd;
+       const void *buf;
+       size_t count;
+       off_t offset;
 
-       wrapper->state = state;
+       struct vfs_aio_state vfs_aio_state;
+       SMBPROFILE_BYTES_ASYNC_STATE(profile_bytes);
+};
 
-       return state;
-}
+static void vfs_gluster_pwrite_do(void *private_data);
+static void vfs_gluster_pwrite_done(struct tevent_req *subreq);
+static int vfs_gluster_pwrite_state_destructor(struct vfs_gluster_pwrite_state *state);
 
-static struct tevent_req *vfs_gluster_pread_send(struct vfs_handle_struct
+static struct tevent_req *vfs_gluster_pwrite_send(struct vfs_handle_struct
                                                  *handle, TALLOC_CTX *mem_ctx,
                                                  struct tevent_context *ev,
                                                  files_struct *fsp,
-                                                 void *data, size_t n,
+                                                 const void *data, size_t n,
                                                  off_t offset)
 {
-       struct glusterfs_aio_state *state = NULL;
-       struct tevent_req *req = NULL;
-       int ret = 0;
+       struct tevent_req *req, *subreq;
+       struct vfs_gluster_pwrite_state *state;
 
-       state = aio_state_create(mem_ctx);
+       glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return NULL;
+       }
 
-       if (state == NULL) {
+       req = tevent_req_create(mem_ctx, &state, struct vfs_gluster_pwrite_state);
+       if (req == NULL) {
                return NULL;
        }
 
-       req = state->req;
+       state->ret = -1;
+       state->fd = glfd;
+       state->buf = data;
+       state->count = n;
+       state->offset = offset;
 
-       if (!init_gluster_aio(handle)) {
-               tevent_req_error(req, EIO);
-               return tevent_req_post(req, ev);
-       }
+       SMBPROFILE_BYTES_ASYNC_START(syscall_asys_pwrite, profile_p,
+                                    state->profile_bytes, n);
+       SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
 
-       PROFILE_TIMESTAMP(&state->start);
-       ret = glfs_pread_async(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle,
-                               fsp), data, n, offset, 0, aio_glusterfs_done,
-                               state);
-       if (ret < 0) {
-               tevent_req_error(req, -ret);
+       subreq = pthreadpool_tevent_job_send(
+               state, ev, handle->conn->sconn->pool,
+               vfs_gluster_pwrite_do, state);
+       if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
+       tevent_req_set_callback(subreq, vfs_gluster_pwrite_done, req);
+
+       talloc_set_destructor(state, vfs_gluster_pwrite_state_destructor);
 
        return req;
 }
 
-static struct tevent_req *vfs_gluster_pwrite_send(struct vfs_handle_struct
-                                                 *handle, TALLOC_CTX *mem_ctx,
-                                                 struct tevent_context *ev,
-                                                 files_struct *fsp,
-                                                 const void *data, size_t n,
-                                                 off_t offset)
+static void vfs_gluster_pwrite_do(void *private_data)
 {
-       struct glusterfs_aio_state *state = NULL;
-       struct tevent_req *req = NULL;
-       int ret = 0;
+       struct vfs_gluster_pwrite_state *state = talloc_get_type_abort(
+               private_data, struct vfs_gluster_pwrite_state);
+       struct timespec start_time;
+       struct timespec end_time;
 
-       state = aio_state_create(mem_ctx);
+       SMBPROFILE_BYTES_ASYNC_SET_BUSY(state->profile_bytes);
 
-       if (state == NULL) {
-               return NULL;
-       }
+       PROFILE_TIMESTAMP(&start_time);
 
-       req = state->req;
+       do {
+#ifdef HAVE_GFAPI_VER_7_6
+               state->ret = glfs_pwrite(state->fd, state->buf, state->count,
+                                        state->offset, 0, NULL, NULL);
+#else
+               state->ret = glfs_pwrite(state->fd, state->buf, state->count,
+                                        state->offset, 0);
+#endif
+       } while ((state->ret == -1) && (errno == EINTR));
 
-       if (!init_gluster_aio(handle)) {
-               tevent_req_error(req, EIO);
-               return tevent_req_post(req, ev);
+       if (state->ret == -1) {
+               state->vfs_aio_state.error = errno;
        }
 
-       PROFILE_TIMESTAMP(&state->start);
-       ret = glfs_pwrite_async(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle,
-                               fsp), data, n, offset, 0, aio_glusterfs_done,
-                               state);
-       if (ret < 0) {
-               tevent_req_error(req, -ret);
-               return tevent_req_post(req, ev);
-       }
+       PROFILE_TIMESTAMP(&end_time);
 
-       return req;
+       state->vfs_aio_state.duration = nsec_time_diff(&end_time, &start_time);
+
+       SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
 }
 
-static ssize_t vfs_gluster_recv(struct tevent_req *req,
-                               struct vfs_aio_state *vfs_aio_state)
+static int vfs_gluster_pwrite_state_destructor(struct vfs_gluster_pwrite_state *state)
 {
-       struct glusterfs_aio_wrapper *wrapper = NULL;
-       int ret = 0;
+       return -1;
+}
 
-       wrapper = tevent_req_data(req, struct glusterfs_aio_wrapper);
+static void vfs_gluster_pwrite_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct vfs_gluster_pwrite_state *state = tevent_req_data(
+               req, struct vfs_gluster_pwrite_state);
+       int ret;
 
-       if (wrapper == NULL) {
-               return -1;
+       ret = pthreadpool_tevent_job_recv(subreq);
+       TALLOC_FREE(subreq);
+       SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
+       talloc_set_destructor(state, NULL);
+       if (ret != 0) {
+               if (ret != EAGAIN) {
+                       tevent_req_error(req, ret);
+                       return;
+               }
+               /*
+                * If we get EAGAIN from pthreadpool_tevent_job_recv() this
+                * means the lower level pthreadpool failed to create a new
+                * thread. Fallback to sync processing in that case to allow
+                * some progress for the client.
+                */
+               vfs_gluster_pwrite_do(state);
        }
 
-       if (wrapper->state == NULL) {
-               return -1;
-       }
+       tevent_req_done(req);
+}
+
+static ssize_t vfs_gluster_pwrite_recv(struct tevent_req *req,
+                                      struct vfs_aio_state *vfs_aio_state)
+{
+       struct vfs_gluster_pwrite_state *state = tevent_req_data(
+               req, struct vfs_gluster_pwrite_state);
 
        if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
                return -1;
        }
 
-       *vfs_aio_state = wrapper->state->vfs_aio_state;
-       ret = wrapper->state->ret;
-
-       /* Clean up the state, it is in a NULL context. */
+       *vfs_aio_state = state->vfs_aio_state;
 
-       TALLOC_FREE(wrapper->state);
-
-       return ret;
-}
-
-static ssize_t vfs_gluster_write(struct vfs_handle_struct *handle,
-                                files_struct *fsp, const void *data, size_t n)
-{
-       return glfs_write(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), data, n, 0);
+       return state->ret;
 }
 
 static ssize_t vfs_gluster_pwrite(struct vfs_handle_struct *handle,
                                  files_struct *fsp, const void *data,
                                  size_t n, off_t offset)
 {
-       return glfs_pwrite(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), data, n, offset, 0);
+       ssize_t ret;
+       glfs_fd_t *glfd = NULL;
+
+       START_PROFILE_BYTES(syscall_pwrite, n);
+
+       glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               END_PROFILE_BYTES(syscall_pwrite);
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return -1;
+       }
+
+#ifdef HAVE_GFAPI_VER_7_6
+       ret = glfs_pwrite(glfd, data, n, offset, 0, NULL, NULL);
+#else
+       ret = glfs_pwrite(glfd, data, n, offset, 0);
+#endif
+       END_PROFILE_BYTES(syscall_pwrite);
+
+       return ret;
 }
 
 static off_t vfs_gluster_lseek(struct vfs_handle_struct *handle,
                               files_struct *fsp, off_t offset, int whence)
 {
-       return glfs_lseek(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), offset, whence);
+       off_t ret = 0;
+       glfs_fd_t *glfd = NULL;
+
+       START_PROFILE(syscall_lseek);
+
+       glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               END_PROFILE(syscall_lseek);
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return -1;
+       }
+
+       ret = glfs_lseek(glfd, offset, whence);
+       END_PROFILE(syscall_lseek);
+
+       return ret;
 }
 
 static ssize_t vfs_gluster_sendfile(struct vfs_handle_struct *handle, int tofd,
@@ -916,59 +1053,148 @@ static ssize_t vfs_gluster_recvfile(struct vfs_handle_struct *handle,
        return -1;
 }
 
-static int vfs_gluster_rename(struct vfs_handle_struct *handle,
-                             const struct smb_filename *smb_fname_src,
-                             const struct smb_filename *smb_fname_dst)
+static int vfs_gluster_renameat(struct vfs_handle_struct *handle,
+                       files_struct *srcfsp,
+                       const struct smb_filename *smb_fname_src,
+                       files_struct *dstfsp,
+                       const struct smb_filename *smb_fname_dst)
 {
-       return glfs_rename(handle->data, smb_fname_src->base_name,
-                          smb_fname_dst->base_name);
-}
+       int ret;
 
-static int vfs_gluster_fsync(struct vfs_handle_struct *handle,
-                            files_struct *fsp)
-{
-       return glfs_fsync(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp));
+       START_PROFILE(syscall_renameat);
+       ret = glfs_rename(handle->data, smb_fname_src->base_name,
+                         smb_fname_dst->base_name);
+       END_PROFILE(syscall_renameat);
+
+       return ret;
 }
 
+struct vfs_gluster_fsync_state {
+       ssize_t ret;
+       glfs_fd_t *fd;
+
+       struct vfs_aio_state vfs_aio_state;
+       SMBPROFILE_BYTES_ASYNC_STATE(profile_bytes);
+};
+
+static void vfs_gluster_fsync_do(void *private_data);
+static void vfs_gluster_fsync_done(struct tevent_req *subreq);
+static int vfs_gluster_fsync_state_destructor(struct vfs_gluster_fsync_state *state);
+
 static struct tevent_req *vfs_gluster_fsync_send(struct vfs_handle_struct
                                                 *handle, TALLOC_CTX *mem_ctx,
                                                 struct tevent_context *ev,
                                                 files_struct *fsp)
 {
-       struct tevent_req *req = NULL;
-       struct glusterfs_aio_state *state = NULL;
-       int ret = 0;
+       struct tevent_req *req, *subreq;
+       struct vfs_gluster_fsync_state *state;
 
-       state = aio_state_create(mem_ctx);
+       glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return NULL;
+       }
 
-       if (state == NULL) {
+       req = tevent_req_create(mem_ctx, &state, struct vfs_gluster_fsync_state);
+       if (req == NULL) {
                return NULL;
        }
 
-       req = state->req;
+       state->ret = -1;
+       state->fd = glfd;
 
-       if (!init_gluster_aio(handle)) {
-               tevent_req_error(req, EIO);
-               return tevent_req_post(req, ev);
-       }
+       SMBPROFILE_BYTES_ASYNC_START(syscall_asys_fsync, profile_p,
+                                     state->profile_bytes, 0);
+       SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
 
-       PROFILE_TIMESTAMP(&state->start);
-       ret = glfs_fsync_async(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle,
-                               fsp), aio_glusterfs_done, req);
-       if (ret < 0) {
-               tevent_req_error(req, -ret);
+       subreq = pthreadpool_tevent_job_send(
+               state, ev, handle->conn->sconn->pool, vfs_gluster_fsync_do, state);
+       if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
+       tevent_req_set_callback(subreq, vfs_gluster_fsync_done, req);
+
+       talloc_set_destructor(state, vfs_gluster_fsync_state_destructor);
+
        return req;
 }
 
+static void vfs_gluster_fsync_do(void *private_data)
+{
+       struct vfs_gluster_fsync_state *state = talloc_get_type_abort(
+               private_data, struct vfs_gluster_fsync_state);
+       struct timespec start_time;
+       struct timespec end_time;
+
+       SMBPROFILE_BYTES_ASYNC_SET_BUSY(state->profile_bytes);
+
+       PROFILE_TIMESTAMP(&start_time);
+
+       do {
+#ifdef HAVE_GFAPI_VER_7_6
+               state->ret = glfs_fsync(state->fd, NULL, NULL);
+#else
+               state->ret = glfs_fsync(state->fd);
+#endif
+       } while ((state->ret == -1) && (errno == EINTR));
+
+       if (state->ret == -1) {
+               state->vfs_aio_state.error = errno;
+       }
+
+       PROFILE_TIMESTAMP(&end_time);
+
+       state->vfs_aio_state.duration = nsec_time_diff(&end_time, &start_time);
+
+       SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
+}
+
+static int vfs_gluster_fsync_state_destructor(struct vfs_gluster_fsync_state *state)
+{
+       return -1;
+}
+
+static void vfs_gluster_fsync_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct vfs_gluster_fsync_state *state = tevent_req_data(
+               req, struct vfs_gluster_fsync_state);
+       int ret;
+
+       ret = pthreadpool_tevent_job_recv(subreq);
+       TALLOC_FREE(subreq);
+       SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
+       talloc_set_destructor(state, NULL);
+       if (ret != 0) {
+               if (ret != EAGAIN) {
+                       tevent_req_error(req, ret);
+                       return;
+               }
+               /*
+                * If we get EAGAIN from pthreadpool_tevent_job_recv() this
+                * means the lower level pthreadpool failed to create a new
+                * thread. Fallback to sync processing in that case to allow
+                * some progress for the client.
+                */
+               vfs_gluster_fsync_do(state);
+       }
+
+       tevent_req_done(req);
+}
+
 static int vfs_gluster_fsync_recv(struct tevent_req *req,
                                  struct vfs_aio_state *vfs_aio_state)
 {
-       /*
-        * Use implicit conversion ssize_t->int
-        */
-       return vfs_gluster_recv(req, vfs_aio_state);
+       struct vfs_gluster_fsync_state *state = tevent_req_data(
+               req, struct vfs_gluster_fsync_state);
+
+       if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
+               return -1;
+       }
+
+       *vfs_aio_state = state->vfs_aio_state;
+       return state->ret;
 }
 
 static int vfs_gluster_stat(struct vfs_handle_struct *handle,
@@ -977,6 +1203,7 @@ static int vfs_gluster_stat(struct vfs_handle_struct *handle,
        struct stat st;
        int ret;
 
+       START_PROFILE(syscall_stat);
        ret = glfs_stat(handle->data, smb_fname->base_name, &st);
        if (ret == 0) {
                smb_stat_ex_from_stat(&smb_fname->st, &st);
@@ -985,6 +1212,8 @@ static int vfs_gluster_stat(struct vfs_handle_struct *handle,
                DEBUG(0, ("glfs_stat(%s) failed: %s\n",
                          smb_fname->base_name, strerror(errno)));
        }
+       END_PROFILE(syscall_stat);
+
        return ret;
 }
 
@@ -993,8 +1222,18 @@ static int vfs_gluster_fstat(struct vfs_handle_struct *handle,
 {
        struct stat st;
        int ret;
+       glfs_fd_t *glfd = NULL;
+
+       START_PROFILE(syscall_fstat);
 
-       ret = glfs_fstat(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), &st);
+       glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               END_PROFILE(syscall_fstat);
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return -1;
+       }
+
+       ret = glfs_fstat(glfd, &st);
        if (ret == 0) {
                smb_stat_ex_from_stat(sbuf, &st);
        }
@@ -1002,6 +1241,8 @@ static int vfs_gluster_fstat(struct vfs_handle_struct *handle,
                DEBUG(0, ("glfs_fstat(%d) failed: %s\n",
                          fsp->fh->fd, strerror(errno)));
        }
+       END_PROFILE(syscall_fstat);
+
        return ret;
 }
 
@@ -1011,6 +1252,7 @@ static int vfs_gluster_lstat(struct vfs_handle_struct *handle,
        struct stat st;
        int ret;
 
+       START_PROFILE(syscall_lstat);
        ret = glfs_lstat(handle->data, smb_fname->base_name, &st);
        if (ret == 0) {
                smb_stat_ex_from_stat(&smb_fname->st, &st);
@@ -1019,6 +1261,8 @@ static int vfs_gluster_lstat(struct vfs_handle_struct *handle,
                DEBUG(0, ("glfs_lstat(%s) failed: %s\n",
                          smb_fname->base_name, strerror(errno)));
        }
+       END_PROFILE(syscall_lstat);
+
        return ret;
 }
 
@@ -1026,26 +1270,59 @@ static uint64_t vfs_gluster_get_alloc_size(struct vfs_handle_struct *handle,
                                           files_struct *fsp,
                                           const SMB_STRUCT_STAT *sbuf)
 {
-       return sbuf->st_ex_blocks * 512;
+       uint64_t ret;
+
+       START_PROFILE(syscall_get_alloc_size);
+       ret = sbuf->st_ex_blocks * 512;
+       END_PROFILE(syscall_get_alloc_size);
+
+       return ret;
 }
 
 static int vfs_gluster_unlink(struct vfs_handle_struct *handle,
                              const struct smb_filename *smb_fname)
 {
-       return glfs_unlink(handle->data, smb_fname->base_name);
+       int ret;
+
+       START_PROFILE(syscall_unlink);
+       ret = glfs_unlink(handle->data, smb_fname->base_name);
+       END_PROFILE(syscall_unlink);
+
+       return ret;
 }
 
 static int vfs_gluster_chmod(struct vfs_handle_struct *handle,
                                const struct smb_filename *smb_fname,
                                mode_t mode)
 {
-       return glfs_chmod(handle->data, smb_fname->base_name, mode);
+       int ret;
+
+       START_PROFILE(syscall_chmod);
+       ret = glfs_chmod(handle->data, smb_fname->base_name, mode);
+       END_PROFILE(syscall_chmod);
+
+       return ret;
 }
 
 static int vfs_gluster_fchmod(struct vfs_handle_struct *handle,
                              files_struct *fsp, mode_t mode)
 {
-       return glfs_fchmod(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), mode);
+       int ret;
+       glfs_fd_t *glfd = NULL;
+
+       START_PROFILE(syscall_fchmod);
+
+       glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               END_PROFILE(syscall_fchmod);
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return -1;
+       }
+
+       ret = glfs_fchmod(glfd, mode);
+       END_PROFILE(syscall_fchmod);
+
+       return ret;
 }
 
 static int vfs_gluster_chown(struct vfs_handle_struct *handle,
@@ -1053,13 +1330,34 @@ static int vfs_gluster_chown(struct vfs_handle_struct *handle,
                        uid_t uid,
                        gid_t gid)
 {
-       return glfs_chown(handle->data, smb_fname->base_name, uid, gid);
+       int ret;
+
+       START_PROFILE(syscall_chown);
+       ret = glfs_chown(handle->data, smb_fname->base_name, uid, gid);
+       END_PROFILE(syscall_chown);
+
+       return ret;
 }
 
 static int vfs_gluster_fchown(struct vfs_handle_struct *handle,
                              files_struct *fsp, uid_t uid, gid_t gid)
 {
-       return glfs_fchown(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), uid, gid);
+       int ret;
+       glfs_fd_t *glfd = NULL;
+
+       START_PROFILE(syscall_fchown);
+
+       glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               END_PROFILE(syscall_fchown);
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return -1;
+       }
+
+       ret = glfs_fchown(glfd, uid, gid);
+       END_PROFILE(syscall_fchown);
+
+       return ret;
 }
 
 static int vfs_gluster_lchown(struct vfs_handle_struct *handle,
@@ -1067,37 +1365,67 @@ static int vfs_gluster_lchown(struct vfs_handle_struct *handle,
                        uid_t uid,
                        gid_t gid)
 {
-       return glfs_lchown(handle->data, smb_fname->base_name, uid, gid);
+       int ret;
+
+       START_PROFILE(syscall_lchown);
+       ret = glfs_lchown(handle->data, smb_fname->base_name, uid, gid);
+       END_PROFILE(syscall_lchown);
+
+       return ret;
 }
 
-static int vfs_gluster_chdir(struct vfs_handle_struct *handle, const char *path)
+static int vfs_gluster_chdir(struct vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname)
 {
-       return glfs_chdir(handle->data, path);
+       int ret;
+
+       START_PROFILE(syscall_chdir);
+       ret = glfs_chdir(handle->data, smb_fname->base_name);
+       END_PROFILE(syscall_chdir);
+
+       return ret;
 }
 
-static char *vfs_gluster_getwd(struct vfs_handle_struct *handle)
+static struct smb_filename *vfs_gluster_getwd(struct vfs_handle_struct *handle,
+                               TALLOC_CTX *ctx)
 {
        char *cwd;
        char *ret;
+       struct smb_filename *smb_fname = NULL;
+
+       START_PROFILE(syscall_getwd);
 
        cwd = SMB_CALLOC_ARRAY(char, PATH_MAX);
        if (cwd == NULL) {
+               END_PROFILE(syscall_getwd);
                return NULL;
        }
 
        ret = glfs_getcwd(handle->data, cwd, PATH_MAX - 1);
-       if (ret == 0) {
-               free(cwd);
+       END_PROFILE(syscall_getwd);
+
+       if (ret == NULL) {
+               SAFE_FREE(cwd);
+               return NULL;
        }
-       return ret;
+       smb_fname = synthetic_smb_fname(ctx,
+                                       ret,
+                                       NULL,
+                                       NULL,
+                                       0);
+       SAFE_FREE(cwd);
+       return smb_fname;
 }
 
 static int vfs_gluster_ntimes(struct vfs_handle_struct *handle,
                              const struct smb_filename *smb_fname,
                              struct smb_file_time *ft)
 {
+       int ret = -1;
        struct timespec times[2];
 
+       START_PROFILE(syscall_ntimes);
+
        if (null_timespec(ft->atime)) {
                times[0].tv_sec = smb_fname->st.st_ex_atime.tv_sec;
                times[0].tv_nsec = smb_fname->st.st_ex_atime.tv_nsec;
@@ -1118,16 +1446,39 @@ static int vfs_gluster_ntimes(struct vfs_handle_struct *handle,
                              &smb_fname->st.st_ex_atime) == 0) &&
            (timespec_compare(&times[1],
                              &smb_fname->st.st_ex_mtime) == 0)) {
+               END_PROFILE(syscall_ntimes);
                return 0;
        }
 
-       return glfs_utimens(handle->data, smb_fname->base_name, times);
+       ret = glfs_utimens(handle->data, smb_fname->base_name, times);
+       END_PROFILE(syscall_ntimes);
+
+       return ret;
 }
 
 static int vfs_gluster_ftruncate(struct vfs_handle_struct *handle,
                                 files_struct *fsp, off_t offset)
 {
-       return glfs_ftruncate(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), offset);
+       int ret;
+       glfs_fd_t *glfd = NULL;
+
+       START_PROFILE(syscall_ftruncate);
+
+       glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               END_PROFILE(syscall_ftruncate);
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return -1;
+       }
+
+#ifdef HAVE_GFAPI_VER_7_6
+       ret = glfs_ftruncate(glfd, offset, NULL, NULL);
+#else
+       ret = glfs_ftruncate(glfd, offset);
+#endif
+       END_PROFILE(syscall_ftruncate);
+
+       return ret;
 }
 
 static int vfs_gluster_fallocate(struct vfs_handle_struct *handle,
@@ -1135,28 +1486,71 @@ static int vfs_gluster_fallocate(struct vfs_handle_struct *handle,
                                 uint32_t mode,
                                 off_t offset, off_t len)
 {
-       /* TODO: add support using glfs_fallocate() and glfs_zerofill() */
+       int ret;
+#ifdef HAVE_GFAPI_VER_6
+       glfs_fd_t *glfd = NULL;
+       int keep_size, punch_hole;
+
+       START_PROFILE(syscall_fallocate);
+
+       glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               END_PROFILE(syscall_fallocate);
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return -1;
+       }
+
+       keep_size = mode & VFS_FALLOCATE_FL_KEEP_SIZE;
+       punch_hole = mode & VFS_FALLOCATE_FL_PUNCH_HOLE;
+
+       mode &= ~(VFS_FALLOCATE_FL_KEEP_SIZE|VFS_FALLOCATE_FL_PUNCH_HOLE);
+       if (mode != 0) {
+               END_PROFILE(syscall_fallocate);
+               errno = ENOTSUP;
+               return -1;
+       }
+
+       if (punch_hole) {
+               ret = glfs_discard(glfd, offset, len);
+       }
+
+       ret = glfs_fallocate(glfd, keep_size, offset, len);
+       END_PROFILE(syscall_fallocate);
+#else
        errno = ENOTSUP;
-       return -1;
+       ret = -1;
+#endif
+       return ret;
 }
 
-static char *vfs_gluster_realpath(struct vfs_handle_struct *handle,
-                                 const char *path)
+static struct smb_filename *vfs_gluster_realpath(struct vfs_handle_struct *handle,
+                               TALLOC_CTX *ctx,
+                               const struct smb_filename *smb_fname)
 {
        char *result = NULL;
-       char *resolved_path = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
+       struct smb_filename *result_fname = NULL;
+       char *resolved_path = NULL;
+
+       START_PROFILE(syscall_realpath);
 
+       resolved_path = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
        if (resolved_path == NULL) {
+               END_PROFILE(syscall_realpath);
                errno = ENOMEM;
                return NULL;
        }
 
-       result = glfs_realpath(handle->data, path, resolved_path);
-       if (result == NULL) {
-               SAFE_FREE(resolved_path);
+       result = glfs_realpath(handle->data,
+                       smb_fname->base_name,
+                       resolved_path);
+       if (result != NULL) {
+               result_fname = synthetic_smb_fname(ctx, result, NULL, NULL, 0);
        }
 
-       return result;
+       SAFE_FREE(resolved_path);
+       END_PROFILE(syscall_realpath);
+
+       return result_fname;
 }
 
 static bool vfs_gluster_lock(struct vfs_handle_struct *handle,
@@ -1165,6 +1559,17 @@ static bool vfs_gluster_lock(struct vfs_handle_struct *handle,
 {
        struct flock flock = { 0, };
        int ret;
+       glfs_fd_t *glfd = NULL;
+       bool ok = false;
+
+       START_PROFILE(syscall_fcntl_lock);
+
+       glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               DBG_ERR("Failed to fetch gluster fd\n");
+               ok = false;
+               goto out;
+       }
 
        flock.l_type = type;
        flock.l_whence = SEEK_SET;
@@ -1172,23 +1577,31 @@ static bool vfs_gluster_lock(struct vfs_handle_struct *handle,
        flock.l_len = count;
        flock.l_pid = 0;
 
-       ret = glfs_posix_lock(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), op, &flock);
+       ret = glfs_posix_lock(glfd, op, &flock);
 
        if (op == F_GETLK) {
                /* lock query, true if someone else has locked */
                if ((ret != -1) &&
                    (flock.l_type != F_UNLCK) &&
-                   (flock.l_pid != 0) && (flock.l_pid != getpid()))
-                       return true;
+                   (flock.l_pid != 0) && (flock.l_pid != getpid())) {
+                       ok = true;
+                       goto out;
+               }
                /* not me */
-               return false;
+               ok = false;
+               goto out;
        }
 
        if (ret == -1) {
-               return false;
+               ok = false;
+               goto out;
        }
 
-       return true;
+       ok = true;
+out:
+       END_PROFILE(syscall_fcntl_lock);
+
+       return ok;
 }
 
 static int vfs_gluster_kernel_flock(struct vfs_handle_struct *handle,
@@ -1212,6 +1625,16 @@ static bool vfs_gluster_getlock(struct vfs_handle_struct *handle,
 {
        struct flock flock = { 0, };
        int ret;
+       glfs_fd_t *glfd = NULL;
+
+       START_PROFILE(syscall_fcntl_getlock);
+
+       glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               END_PROFILE(syscall_fcntl_getlock);
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return false;
+       }
 
        flock.l_type = *ptype;
        flock.l_whence = SEEK_SET;
@@ -1219,9 +1642,10 @@ static bool vfs_gluster_getlock(struct vfs_handle_struct *handle,
        flock.l_len = *pcount;
        flock.l_pid = 0;
 
-       ret = glfs_posix_lock(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), F_GETLK, &flock);
+       ret = glfs_posix_lock(glfd, F_GETLK, &flock);
 
        if (ret == -1) {
+               END_PROFILE(syscall_fcntl_getlock);
                return false;
        }
 
@@ -1229,37 +1653,95 @@ static bool vfs_gluster_getlock(struct vfs_handle_struct *handle,
        *poffset = flock.l_start;
        *pcount = flock.l_len;
        *ppid = flock.l_pid;
+       END_PROFILE(syscall_fcntl_getlock);
 
        return true;
 }
 
 static int vfs_gluster_symlink(struct vfs_handle_struct *handle,
-                              const char *oldpath, const char *newpath)
+                               const char *link_target,
+                               const struct smb_filename *new_smb_fname)
+{
+       int ret;
+
+       START_PROFILE(syscall_symlink);
+       ret = glfs_symlink(handle->data,
+                       link_target,
+                       new_smb_fname->base_name);
+       END_PROFILE(syscall_symlink);
+
+       return ret;
+}
+
+static int vfs_gluster_symlinkat(struct vfs_handle_struct *handle,
+                               const char *link_target,
+                               struct files_struct *dirfsp,
+                               const struct smb_filename *new_smb_fname)
 {
-       return glfs_symlink(handle->data, oldpath, newpath);
+       int ret;
+
+       START_PROFILE(syscall_symlinkat);
+       SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
+       ret = glfs_symlink(handle->data,
+                       link_target,
+                       new_smb_fname->base_name);
+       END_PROFILE(syscall_symlinkat);
+
+       return ret;
 }
 
-static int vfs_gluster_readlink(struct vfs_handle_struct *handle,
-                               const char *path, char *buf, size_t bufsiz)
+static int vfs_gluster_readlinkat(struct vfs_handle_struct *handle,
+                               files_struct *dirfsp,
+                               const struct smb_filename *smb_fname,
+                               char *buf,
+                               size_t bufsiz)
 {
-       return glfs_readlink(handle->data, path, buf, bufsiz);
+       int ret;
+
+       START_PROFILE(syscall_readlinkat);
+       SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
+       ret = glfs_readlink(handle->data, smb_fname->base_name, buf, bufsiz);
+       END_PROFILE(syscall_readlinkat);
+
+       return ret;
 }
 
-static int vfs_gluster_link(struct vfs_handle_struct *handle,
+static int vfs_gluster_linkat(struct vfs_handle_struct *handle,
+                               files_struct *srcfsp,
                                const struct smb_filename *old_smb_fname,
-                               const struct smb_filename *new_smb_fname)
+                               files_struct *dstfsp,
+                               const struct smb_filename *new_smb_fname,
+                               int flags)
 {
-       return glfs_link(handle->data,
+       int ret;
+
+       START_PROFILE(syscall_linkat);
+
+       SMB_ASSERT(srcfsp == srcfsp->conn->cwd_fsp);
+       SMB_ASSERT(dstfsp == dstfsp->conn->cwd_fsp);
+
+       ret = glfs_link(handle->data,
                        old_smb_fname->base_name,
                        new_smb_fname->base_name);
+       END_PROFILE(syscall_linkat);
+
+       return ret;
 }
 
-static int vfs_gluster_mknod(struct vfs_handle_struct *handle,
+static int vfs_gluster_mknodat(struct vfs_handle_struct *handle,
+                               files_struct *dirfsp,
                                const struct smb_filename *smb_fname,
                                mode_t mode,
                                SMB_DEV_T dev)
 {
-       return glfs_mknod(handle->data, smb_fname->base_name, mode, dev);
+       int ret;
+
+       START_PROFILE(syscall_mknodat);
+       SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
+       ret = glfs_mknod(handle->data, smb_fname->base_name, mode, dev);
+       END_PROFILE(syscall_mknodat);
+
+       return ret;
 }
 
 static int vfs_gluster_chflags(struct vfs_handle_struct *handle,
@@ -1275,21 +1757,22 @@ static int vfs_gluster_get_real_filename(struct vfs_handle_struct *handle,
                                         TALLOC_CTX *mem_ctx, char **found_name)
 {
        int ret;
-       char key_buf[NAME_MAX + 64];
-       char val_buf[NAME_MAX + 1];
+       char key_buf[GLUSTER_NAME_MAX + 64];
+       char val_buf[GLUSTER_NAME_MAX + 1];
 
-       if (strlen(name) >= NAME_MAX) {
+       if (strlen(name) >= GLUSTER_NAME_MAX) {
                errno = ENAMETOOLONG;
                return -1;
        }
 
-       snprintf(key_buf, NAME_MAX + 64,
+       snprintf(key_buf, GLUSTER_NAME_MAX + 64,
                 "glusterfs.get_real_filename:%s", name);
 
-       ret = glfs_getxattr(handle->data, path, key_buf, val_buf, NAME_MAX + 1);
+       ret = glfs_getxattr(handle->data, path, key_buf, val_buf,
+                           GLUSTER_NAME_MAX + 1);
        if (ret == -1) {
-               if (errno == ENODATA) {
-                       errno = EOPNOTSUPP;
+               if (errno == ENOATTR) {
+                       errno = ENOENT;
                }
                return -1;
        }
@@ -1303,7 +1786,7 @@ static int vfs_gluster_get_real_filename(struct vfs_handle_struct *handle,
 }
 
 static const char *vfs_gluster_connectpath(struct vfs_handle_struct *handle,
-                                          const char *filename)
+                               const struct smb_filename *smb_fname)
 {
        return handle->conn->connectpath;
 }
@@ -1317,14 +1800,20 @@ static ssize_t vfs_gluster_getxattr(struct vfs_handle_struct *handle,
                                size_t size)
 {
        return glfs_getxattr(handle->data, smb_fname->base_name,
-                       name, value, size);
+                            name, value, size);
 }
 
 static ssize_t vfs_gluster_fgetxattr(struct vfs_handle_struct *handle,
                                     files_struct *fsp, const char *name,
                                     void *value, size_t size)
 {
-       return glfs_fgetxattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), name, value, size);
+       glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return -1;
+       }
+
+       return glfs_fgetxattr(glfd, name, value, size);
 }
 
 static ssize_t vfs_gluster_listxattr(struct vfs_handle_struct *handle,
@@ -1339,7 +1828,13 @@ static ssize_t vfs_gluster_flistxattr(struct vfs_handle_struct *handle,
                                      files_struct *fsp, char *list,
                                      size_t size)
 {
-       return glfs_flistxattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), list, size);
+       glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return -1;
+       }
+
+       return glfs_flistxattr(glfd, list, size);
 }
 
 static int vfs_gluster_removexattr(struct vfs_handle_struct *handle,
@@ -1352,7 +1847,13 @@ static int vfs_gluster_removexattr(struct vfs_handle_struct *handle,
 static int vfs_gluster_fremovexattr(struct vfs_handle_struct *handle,
                                    files_struct *fsp, const char *name)
 {
-       return glfs_fremovexattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), name);
+       glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return -1;
+       }
+
+       return glfs_fremovexattr(glfd, name);
 }
 
 static int vfs_gluster_setxattr(struct vfs_handle_struct *handle,
@@ -1367,8 +1868,13 @@ static int vfs_gluster_fsetxattr(struct vfs_handle_struct *handle,
                                 files_struct *fsp, const char *name,
                                 const void *value, size_t size, int flags)
 {
-       return glfs_fsetxattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), name, value, size,
-                             flags);
+       glfs_fd_t *glfd = vfs_gluster_fetch_glfd(handle, fsp);
+       if (glfd == NULL) {
+               DBG_ERR("Failed to fetch gluster fd\n");
+               return -1;
+       }
+
+       return glfs_fsetxattr(glfd, name, value, size, flags);
 }
 
 /* AIO Operations */
@@ -1404,26 +1910,22 @@ static struct vfs_fn_pointers glusterfs_fns = {
        .mkdir_fn = vfs_gluster_mkdir,
        .rmdir_fn = vfs_gluster_rmdir,
        .closedir_fn = vfs_gluster_closedir,
-       .init_search_op_fn = vfs_gluster_init_search_op,
 
        /* File Operations */
 
        .open_fn = vfs_gluster_open,
        .create_file_fn = NULL,
        .close_fn = vfs_gluster_close,
-       .read_fn = vfs_gluster_read,
        .pread_fn = vfs_gluster_pread,
        .pread_send_fn = vfs_gluster_pread_send,
-       .pread_recv_fn = vfs_gluster_recv,
-       .write_fn = vfs_gluster_write,
+       .pread_recv_fn = vfs_gluster_pread_recv,
        .pwrite_fn = vfs_gluster_pwrite,
        .pwrite_send_fn = vfs_gluster_pwrite_send,
-       .pwrite_recv_fn = vfs_gluster_recv,
+       .pwrite_recv_fn = vfs_gluster_pwrite_recv,
        .lseek_fn = vfs_gluster_lseek,
        .sendfile_fn = vfs_gluster_sendfile,
        .recvfile_fn = vfs_gluster_recvfile,
-       .rename_fn = vfs_gluster_rename,
-       .fsync_fn = vfs_gluster_fsync,
+       .renameat_fn = vfs_gluster_renameat,
        .fsync_send_fn = vfs_gluster_fsync_send,
        .fsync_recv_fn = vfs_gluster_fsync_recv,
 
@@ -1448,23 +1950,20 @@ static struct vfs_fn_pointers glusterfs_fns = {
        .linux_setlease_fn = vfs_gluster_linux_setlease,
        .getlock_fn = vfs_gluster_getlock,
        .symlink_fn = vfs_gluster_symlink,
-       .readlink_fn = vfs_gluster_readlink,
-       .link_fn = vfs_gluster_link,
-       .mknod_fn = vfs_gluster_mknod,
+       .symlinkat_fn = vfs_gluster_symlinkat,
+       .readlinkat_fn = vfs_gluster_readlinkat,
+       .linkat_fn = vfs_gluster_linkat,
+       .mknodat_fn = vfs_gluster_mknodat,
        .realpath_fn = vfs_gluster_realpath,
        .chflags_fn = vfs_gluster_chflags,
        .file_id_create_fn = NULL,
-       .copy_chunk_send_fn = NULL,
-       .copy_chunk_recv_fn = NULL,
        .streaminfo_fn = NULL,
        .get_real_filename_fn = vfs_gluster_get_real_filename,
        .connectpath_fn = vfs_gluster_connectpath,
 
        .brl_lock_windows_fn = NULL,
        .brl_unlock_windows_fn = NULL,
-       .brl_cancel_windows_fn = NULL,
-       .strict_lock_fn = NULL,
-       .strict_unlock_fn = NULL,
+       .strict_lock_check_fn = NULL,
        .translate_name_fn = NULL,
        .fsctl_fn = NULL,
 
@@ -1475,8 +1974,6 @@ static struct vfs_fn_pointers glusterfs_fns = {
        .audit_file_fn = NULL,
 
        /* Posix ACL Operations */
-       .chmod_acl_fn = NULL,   /* passthrough to default */
-       .fchmod_acl_fn = NULL,  /* passthrough to default */
        .sys_acl_get_file_fn = posixacl_xattr_acl_get_file,
        .sys_acl_get_fd_fn = posixacl_xattr_acl_get_fd,
        .sys_acl_blob_get_file_fn = posix_sys_acl_blob_get_file,
@@ -1487,6 +1984,8 @@ static struct vfs_fn_pointers glusterfs_fns = {
 
        /* EA Operations */
        .getxattr_fn = vfs_gluster_getxattr,
+       .getxattrat_send_fn = vfs_not_implemented_getxattrat_send,
+       .getxattrat_recv_fn = vfs_not_implemented_getxattrat_recv,
        .fgetxattr_fn = vfs_gluster_fgetxattr,
        .listxattr_fn = vfs_gluster_listxattr,
        .flistxattr_fn = vfs_gluster_flistxattr,
@@ -1504,7 +2003,7 @@ static struct vfs_fn_pointers glusterfs_fns = {
        .durable_reconnect_fn = NULL,
 };
 
-NTSTATUS vfs_glusterfs_init(TALLOC_CTX *);
+static_decl_vfs;
 NTSTATUS vfs_glusterfs_init(TALLOC_CTX *ctx)
 {
        return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,