From 910a56a7cb10a1928e6a3edaa5eb15d086460425 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Thu, 12 Dec 2013 12:27:10 -0600 Subject: [PATCH 1/3] vfs_glusterfs: Comment the top of the file. Change-Id: I98b512da2e0e56f061247a7c48ce576287b43827 Signed-off-by: Christopher R. Hertel Reviewed-by: Jose A. Rivera Reviewed-by: Ira Cooper --- source3/modules/vfs_glusterfs.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index 9bcd0cb..f9f8ce1 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -19,6 +19,24 @@ along with this program. If not, see . */ +/** + * @file vfs_glusterfs.c + * @author Anand Avati + * @date May 2013 + * @brief Samba VFS module for glusterfs + * + * @todo + * - AIO support\n + * See, for example \c vfs_aio_linux.c in the \c sourc3/modules directory + * - sendfile/recvfile support + * + * A Samba VFS module for GlusterFS, based on Gluster's libgfapi. + * This is a "bottom" vfs module (not something to be stacked on top of + * another module), and translates (most) calls to the closest actions + * available in libgfapi. + * + */ + #include "includes.h" #include "smbd/smbd.h" #include @@ -27,14 +45,6 @@ #define DEFAULT_VOLFILE_SERVER "localhost" -/* - TODO - ---- - Short term: - - AIO support - - sendfile/recvfile support -*/ - /* Helpers to provide 'integer' fds */ /* This is global. gfapi's FD operations do not -- 1.9.3 From 86aa43c73ce9fd16892f0489ddf41bd7fef4eaba Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Thu, 12 Dec 2013 12:29:20 -0600 Subject: [PATCH 2/3] vfs_glusterfs: smb_stat_ex_from_stat commenting and cleanup. Change-Id: If1b54e62b4fc2240aa17e5d1eae8f279f2fdfc42 Signed-off-by: Christopher R. Hertel Reviewed-by: Jose A. Rivera Reviewed-by: Ira Cooper --- source3/modules/vfs_glusterfs.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index f9f8ce1..6807df7 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -111,8 +111,9 @@ static glfs_fd_t *glfd_fd_clear(int i) return glfd; } -/* Helper to convert stat to stat_ex */ - +/** + * Helper to convert struct stat to struct stat_ex. + */ static void smb_stat_ex_from_stat(struct stat_ex *dst, const struct stat *src) { ZERO_STRUCTP(dst); @@ -126,23 +127,17 @@ static void smb_stat_ex_from_stat(struct stat_ex *dst, const struct stat *src) dst->st_ex_rdev = src->st_rdev; dst->st_ex_size = src->st_size; dst->st_ex_atime.tv_sec = src->st_atime; -#ifdef STAT_HAVE_NSEC - dst->st_ex_atime.tv_nsec = src->st_atime_nsec; -#endif dst->st_ex_mtime.tv_sec = src->st_mtime; -#ifdef STAT_HAVE_NSEC - dst->st_ex_mtime.tv_nsec = src->st_mtime_nsec; -#endif dst->st_ex_ctime.tv_sec = src->st_ctime; -#ifdef STAT_HAVE_NSEC - dst->st_ex_ctime.tv_nsec = src->st_ctime_nsec; -#endif dst->st_ex_btime.tv_sec = src->st_mtime; + dst->st_ex_blksize = src->st_blksize; + dst->st_ex_blocks = src->st_blocks; #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_blksize = src->st_blksize; - dst->st_ex_blocks = src->st_blocks; } /* pre-opened glfs_t */ -- 1.9.3 From 64bae74f565e7f07a408effb2665eba80fde5370 Mon Sep 17 00:00:00 2001 From: "Jose A. Rivera" Date: Thu, 12 Dec 2013 16:06:36 -0600 Subject: [PATCH 3/3] vfs_glusterfs: Remove "integer fd" code and store the glfs pointers. Change-Id: I74347199e54be0d1dc031985534da1e56fd3e280 Signed-off-by: Jose A. Rivera Reviewed-by: Christopher R. Hertel Reviewed-by: Ira Cooper --- source3/modules/vfs_glusterfs.c | 122 +++++++++++----------------------------- 1 file changed, 32 insertions(+), 90 deletions(-) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index 6807df7..ba2d8e8 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -45,72 +45,6 @@ #define DEFAULT_VOLFILE_SERVER "localhost" -/* Helpers to provide 'integer' fds */ - -/* This is global. gfapi's FD operations do not - require filesystem context. -*/ - -static glfs_fd_t **glfd_fd; -static int glfd_fd_size; -static int glfd_fd_used; - -static int glfd_fd_store(glfs_fd_t *glfd) -{ - int i; - void *tmp; - - if (glfd_fd_size == glfd_fd_used) { - if (glfd_fd_size >= INT_MAX - 1) { - errno = ENOMEM; - return -1; - } - - tmp = talloc_realloc(glfd_fd, glfd_fd, glfs_fd_t *, - glfd_fd_size + 1); - if (tmp == NULL) { - errno = ENOMEM; - return -1; - } - - glfd_fd = tmp; - glfd_fd[glfd_fd_size] = 0; - glfd_fd_size++; - } - - for (i = 0; i < glfd_fd_size; i++) { - if (glfd_fd[i] == NULL) { - break; - } - } - glfd_fd_used++; - glfd_fd[i] = glfd; - return i; -} - -static glfs_fd_t *glfd_fd_get(int i) -{ - if (i < 0 || i >= glfd_fd_size) { - return NULL; - } - return glfd_fd[i]; -} - -static glfs_fd_t *glfd_fd_clear(int i) -{ - glfs_fd_t *glfd = NULL; - - if (i < 0 || i >= glfd_fd_size) { - return NULL; - } - - glfd = glfd_fd[i]; - - glfd_fd[i] = 0; - glfd_fd_used--; - return glfd; -} - /** * Helper to convert struct stat to struct stat_ex. */ @@ -412,7 +346,7 @@ static DIR *vfs_gluster_fdopendir(struct vfs_handle_struct *handle, files_struct *fsp, const char *mask, uint32 attributes) { - return (DIR *) glfd_fd_get(fsp->fh->fd); + return (DIR *) *(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp); } static int vfs_gluster_closedir(struct vfs_handle_struct *handle, DIR *dirp) @@ -484,6 +418,7 @@ static int vfs_gluster_open(struct vfs_handle_struct *handle, int flags, mode_t mode) { glfs_fd_t *glfd; + glfs_fd_t **p_tmp; if (flags & O_DIRECTORY) { glfd = glfs_opendir(handle->data, smb_fname->base_name); @@ -497,26 +432,33 @@ static int vfs_gluster_open(struct vfs_handle_struct *handle, if (glfd == NULL) { return -1; } - return glfd_fd_store(glfd); + p_tmp = (glfs_fd_t **)VFS_ADD_FSP_EXTENSION(handle, fsp, + glfs_fd_t *, NULL); + *p_tmp = glfd; + /* An arbitrary value for error reporting, so you know its us. */ + return 13371337; } static int vfs_gluster_close(struct vfs_handle_struct *handle, files_struct *fsp) { - return glfs_close(glfd_fd_clear(fsp->fh->fd)); + glfs_fd_t *glfd; + glfd = *(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp); + 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(glfd_fd_get(fsp->fh->fd), data, n, 0); + return glfs_read(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), data, n, 0); } 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(glfd_fd_get(fsp->fh->fd), data, n, offset, 0); + return glfs_pread(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), data, n, offset, 0); } static struct tevent_req *vfs_gluster_pread_send(struct vfs_handle_struct @@ -538,14 +480,14 @@ static ssize_t vfs_gluster_pread_recv(struct tevent_req *req, int *err) static ssize_t vfs_gluster_write(struct vfs_handle_struct *handle, files_struct *fsp, const void *data, size_t n) { - return glfs_write(glfd_fd_get(fsp->fh->fd), data, n, 0); + return glfs_write(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), data, n, 0); } 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(glfd_fd_get(fsp->fh->fd), data, n, offset, 0); + return glfs_pwrite(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), data, n, offset, 0); } static struct tevent_req *vfs_gluster_pwrite_send(struct vfs_handle_struct @@ -568,7 +510,7 @@ static ssize_t vfs_gluster_pwrite_recv(struct tevent_req *req, int *err) static off_t vfs_gluster_lseek(struct vfs_handle_struct *handle, files_struct *fsp, off_t offset, int whence) { - return glfs_lseek(glfd_fd_get(fsp->fh->fd), offset, whence); + return glfs_lseek(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), offset, whence); } static ssize_t vfs_gluster_sendfile(struct vfs_handle_struct *handle, int tofd, @@ -599,7 +541,7 @@ static int vfs_gluster_rename(struct vfs_handle_struct *handle, static int vfs_gluster_fsync(struct vfs_handle_struct *handle, files_struct *fsp) { - return glfs_fsync(glfd_fd_get(fsp->fh->fd)); + return glfs_fsync(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp)); } static struct tevent_req *vfs_gluster_fsync_send(struct vfs_handle_struct @@ -640,7 +582,7 @@ static int vfs_gluster_fstat(struct vfs_handle_struct *handle, struct stat st; int ret; - ret = glfs_fstat(glfd_fd_get(fsp->fh->fd), &st); + ret = glfs_fstat(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), &st); if (ret == 0) { smb_stat_ex_from_stat(sbuf, &st); } @@ -690,7 +632,7 @@ static int vfs_gluster_chmod(struct vfs_handle_struct *handle, static int vfs_gluster_fchmod(struct vfs_handle_struct *handle, files_struct *fsp, mode_t mode) { - return glfs_fchmod(glfd_fd_get(fsp->fh->fd), mode); + return glfs_fchmod(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), mode); } static int vfs_gluster_chown(struct vfs_handle_struct *handle, @@ -702,7 +644,7 @@ static int vfs_gluster_chown(struct vfs_handle_struct *handle, static int vfs_gluster_fchown(struct vfs_handle_struct *handle, files_struct *fsp, uid_t uid, gid_t gid) { - return glfs_fchown(glfd_fd_get(fsp->fh->fd), uid, gid); + return glfs_fchown(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), uid, gid); } static int vfs_gluster_lchown(struct vfs_handle_struct *handle, @@ -768,7 +710,7 @@ static int vfs_gluster_ntimes(struct vfs_handle_struct *handle, static int vfs_gluster_ftruncate(struct vfs_handle_struct *handle, files_struct *fsp, off_t offset) { - return glfs_ftruncate(glfd_fd_get(fsp->fh->fd), offset); + return glfs_ftruncate(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), offset); } static int vfs_gluster_fallocate(struct vfs_handle_struct *handle, @@ -799,7 +741,7 @@ static bool vfs_gluster_lock(struct vfs_handle_struct *handle, flock.l_len = count; flock.l_pid = 0; - ret = glfs_posix_lock(glfd_fd_get(fsp->fh->fd), op, &flock); + ret = glfs_posix_lock(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), op, &flock); if (op == F_GETLK) { /* lock query, true if someone else has locked */ @@ -846,7 +788,7 @@ static bool vfs_gluster_getlock(struct vfs_handle_struct *handle, flock.l_len = *pcount; flock.l_pid = 0; - ret = glfs_posix_lock(glfd_fd_get(fsp->fh->fd), F_GETLK, &flock); + ret = glfs_posix_lock(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), F_GETLK, &flock); if (ret == -1) { return false; @@ -954,7 +896,7 @@ 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(glfd_fd_get(fsp->fh->fd), name, value, size); + return glfs_fgetxattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), name, value, size); } static ssize_t vfs_gluster_listxattr(struct vfs_handle_struct *handle, @@ -967,7 +909,7 @@ static ssize_t vfs_gluster_flistxattr(struct vfs_handle_struct *handle, files_struct *fsp, char *list, size_t size) { - return glfs_flistxattr(glfd_fd_get(fsp->fh->fd), list, size); + return glfs_flistxattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), list, size); } static int vfs_gluster_removexattr(struct vfs_handle_struct *handle, @@ -979,7 +921,7 @@ 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(glfd_fd_get(fsp->fh->fd), name); + return glfs_fremovexattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), name); } static int vfs_gluster_setxattr(struct vfs_handle_struct *handle, @@ -993,7 +935,7 @@ 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(glfd_fd_get(fsp->fh->fd), name, value, size, + return glfs_fsetxattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), name, value, size, flags); } @@ -1370,16 +1312,16 @@ static SMB_ACL_T vfs_gluster_sys_acl_get_fd(struct vfs_handle_struct *handle, struct smb_acl_t *result; int ret; char *buf; + glfs_fd_t *glfd; - ret = glfs_fgetxattr(glfd_fd_get(fsp->fh->fd), - "system.posix_acl_access", 0, 0); + glfd = *(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp); + ret = glfs_fgetxattr(glfd, "system.posix_acl_access", 0, 0); if (ret <= 0) { return NULL; } buf = alloca(ret); - ret = glfs_fgetxattr(glfd_fd_get(fsp->fh->fd), - "system.posix_acl_access", buf, ret); + ret = glfs_fgetxattr(glfd, "system.posix_acl_access", buf, ret); if (ret <= 0) { return NULL; } @@ -1440,7 +1382,7 @@ static int vfs_gluster_sys_acl_set_fd(struct vfs_handle_struct *handle, return -1; } - ret = glfs_fsetxattr(glfd_fd_get(fsp->fh->fd), + ret = glfs_fsetxattr(*(glfs_fd_t **)VFS_FETCH_FSP_EXTENSION(handle, fsp), "system.posix_acl_access", buf, size, 0); return ret; } -- 1.9.3