1 From f2f684d4eadadeebf725b513bf4945ccf0aa7371 Mon Sep 17 00:00:00 2001
2 From: Anand Avati <avati@redhat.com>
3 Date: Wed, 29 May 2013 07:21:46 -0400
4 Subject: [PATCH 1/9] PATCHSET13: vfs_glusterfs: Samba VFS module for glusterfs
6 Implement a Samba VFS plugin for glusterfs based on gluster's gfapi.
7 This is a "bottom" vfs plugin (not something to be stacked on top of
8 another module), and translates (most) calls into closest actions
11 Reviewed-by: Andrew Bartlett <abartlet@samba.org>
12 Reviewed-by: Simo Sorce <idra@samba.org>
13 Signed-off-by: Anand Avati <avati@redhat.com>
15 source3/Makefile.in | 5 +
16 source3/configure.in | 23 +
17 source3/modules/vfs_glusterfs.c | 1461 +++++++++++++++++++++++++++++++++++++++
18 source3/modules/wscript_build | 9 +
19 source3/wscript | 22 +
20 5 files changed, 1520 insertions(+)
21 create mode 100644 source3/modules/vfs_glusterfs.c
23 diff --git a/source3/Makefile.in b/source3/Makefile.in
24 index 9e8e03d..27bc43e 100644
25 --- a/source3/Makefile.in
26 +++ b/source3/Makefile.in
27 @@ -848,6 +848,7 @@ VFS_SCANNEDONLY_OBJ = modules/vfs_scannedonly.o
28 VFS_CROSSRENAME_OBJ = modules/vfs_crossrename.o
29 VFS_LINUX_XFS_SGID_OBJ = modules/vfs_linux_xfs_sgid.o
30 VFS_TIME_AUDIT_OBJ = modules/vfs_time_audit.o
31 +VFS_GLUSTERFS_OBJ = modules/vfs_glusterfs.o
33 PAM_ERRORS_OBJ = ../libcli/auth/pam_errors.o
34 PLAINTEXT_AUTH_OBJ = auth/pampass.o auth/pass_check.o $(PAM_ERRORS_OBJ)
35 @@ -3191,6 +3192,10 @@ bin/time_audit.@SHLIBEXT@: $(BINARY_PREREQS) $(VFS_TIME_AUDIT_OBJ)
36 @echo "Building plugin $@"
37 @$(SHLD_MODULE) $(VFS_TIME_AUDIT_OBJ)
39 +bin/glusterfs.@SHLIBEXT@: $(BINARY_PREREQS) $(VFS_GLUSTERFS_OBJ)
40 + @echo "Building plugin $@"
41 + $(SHLD_MODULE) $(VFS_GLUSTERFS_OBJ) @GLUSTERFS_LIBS@
43 #########################################################
46 diff --git a/source3/configure.in b/source3/configure.in
47 index 42c23e3..3cc78e9 100644
48 --- a/source3/configure.in
49 +++ b/source3/configure.in
50 @@ -6688,6 +6688,29 @@
55 +AC_ARG_ENABLE([glusterfs],
56 + AC_HELP_STRING([--disable-glusterfs],[Do not build vfs_glusterfs module]))
60 +if test "x$enable_glusterfs" != "xno"; then
61 + PKG_CHECK_MODULES([GLFS], [glusterfs-api >= 4], glfs_found=yes, glfs_found=no)
64 +if test "x$enable_glusterfs" = "xyes" -a "x$glfs_found" != "xyes"; then
65 + echo "GFAPI not found in build system"
69 +if test "x$glfs_found" = "xyes"; then
70 + CFLAGS="$CFLAGS $GLFS_CFLAGS"
71 + GLUSTERFS_LIBS="$GLFS_LIBS"
72 + default_shared_modules="$default_shared_modules vfs_glusterfs"
74 +AC_SUBST(GLUSTERFS_LIBS)
77 #################################################
81 SMB_MODULE(vfs_crossrename, \$(VFS_CROSSRENAME_OBJ), "bin/crossrename.$SHLIBEXT", VFS)
82 SMB_MODULE(vfs_linux_xfs_sgid, \$(VFS_LINUX_XFS_SGID_OBJ), "bin/linux_xfs_sgid.$SHLIBEXT", VFS)
83 SMB_MODULE(vfs_time_audit, \$(VFS_TIME_AUDIT_OBJ), "bin/time_audit.$SHLIBEXT", VFS)
84 +SMB_MODULE(vfs_glusterfs, \$(VFS_GLUSTERFS_OBJ), "bin/glusterfs.$SHLIBEXT", VFS)
86 SMB_SUBSYSTEM(VFS,smbd/vfs.o)
88 diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c
90 index 0000000..4beac1d
92 +++ b/source3/modules/vfs_glusterfs.c
95 + Unix SMB/CIFS implementation.
97 + Wrap GlusterFS GFAPI calls in vfs functions.
99 + Copyright (c) 2013 Anand Avati <avati@redhat.com>
101 + This program is free software; you can redistribute it and/or modify
102 + it under the terms of the GNU General Public License as published by
103 + the Free Software Foundation; either version 3 of the License, or
104 + (at your option) any later version.
106 + This program is distributed in the hope that it will be useful,
107 + but WITHOUT ANY WARRANTY; without even the implied warranty of
108 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
109 + GNU General Public License for more details.
111 + You should have received a copy of the GNU General Public License
112 + along with this program. If not, see <http://www.gnu.org/licenses/>.
115 +#include "includes.h"
116 +#include "smbd/smbd.h"
118 +#include "api/glfs.h"
120 +#define DEFAULT_VOLFILE_SERVER "localhost"
127 + - sendfile/recvfile support
130 +/* Helpers to provide 'integer' fds */
132 +/* This is global. gfapi's FD operations do not
133 + require filesystem context.
135 +static glfs_fd_t **glfd_fd;
136 +static int glfd_fd_size;
137 +static int glfd_fd_used;
138 +static int glfd_fd_store(glfs_fd_t *glfd)
143 + if (glfd_fd_size == glfd_fd_used) {
144 + if (glfd_fd_size >= INT_MAX - 1) {
149 + tmp = talloc_realloc(glfd_fd, glfd_fd, glfs_fd_t *,
157 + glfd_fd[glfd_fd_size] = 0;
161 + for (i = 0; i < glfd_fd_size; i++) {
171 +static glfs_fd_t *glfd_fd_get(int i)
173 + if (i < 0 || i >= glfd_fd_size) {
179 +static glfs_fd_t *glfd_fd_clear(int i)
181 + glfs_fd_t *glfd = NULL;
183 + if (i < 0 || i >= glfd_fd_size) {
193 +/* Helper to convert stat to stat_ex */
195 +static void smb_stat_ex_from_stat(struct stat_ex *dst, const struct stat *src)
199 + dst->st_ex_dev = src->st_dev;
200 + dst->st_ex_ino = src->st_ino;
201 + dst->st_ex_mode = src->st_mode;
202 + dst->st_ex_nlink = src->st_nlink;
203 + dst->st_ex_uid = src->st_uid;
204 + dst->st_ex_gid = src->st_gid;
205 + dst->st_ex_rdev = src->st_rdev;
206 + dst->st_ex_size = src->st_size;
207 + dst->st_ex_atime.tv_sec = src->st_atime;
208 +#ifdef STAT_HAVE_NSEC
209 + dst->st_ex_atime.tv_nsec = src->st_atime_nsec;
211 + dst->st_ex_mtime.tv_sec = src->st_mtime;
212 +#ifdef STAT_HAVE_NSEC
213 + dst->st_ex_mtime.tv_nsec = src->st_mtime_nsec;
215 + dst->st_ex_ctime.tv_sec = src->st_ctime;
216 +#ifdef STAT_HAVE_NSEC
217 + dst->st_ex_ctime.tv_nsec = src->st_ctime_nsec;
219 + dst->st_ex_btime.tv_sec = src->st_mtime;
220 +#ifdef STAT_HAVE_NSEC
221 + dst->st_ex_btime.tv_nsec = src->st_mtime_nsec;
223 + dst->st_ex_blksize = src->st_blksize;
224 + dst->st_ex_blocks = src->st_blocks;
227 +/* pre-opened glfs_t */
229 +static struct glfs_preopened {
233 + struct glfs_preopened *next, *prev;
237 +int glfs_set_preopened(const char *volume, glfs_t *fs)
239 + struct glfs_preopened *entry = NULL;
241 + entry = talloc_zero(NULL, struct glfs_preopened);
247 + entry->volume = talloc_strdup(entry, volume);
248 + if (!entry->volume) {
249 + talloc_free(entry);
257 + DLIST_ADD(glfs_preopened, entry);
262 +static glfs_t *glfs_find_preopened(const char *volume)
264 + struct glfs_preopened *entry = NULL;
266 + for (entry = glfs_preopened; entry; entry = entry->next) {
267 + if (strcmp(entry->volume, volume) == 0) {
276 +static void glfs_clear_preopened(glfs_t *fs)
279 + struct glfs_preopened *entry = NULL;
281 + for (entry = glfs_preopened; entry; entry = entry->next) {
282 + if (entry->fs == fs) {
286 + DLIST_REMOVE(glfs_preopened, entry);
288 + glfs_fini(entry->fs);
289 + talloc_free(entry);
294 +/* Disk Operations */
296 +static int vfs_gluster_connect(struct vfs_handle_struct *handle,
297 + const char *service, const char *user)
299 + const char *volfile_server;
300 + const char *volume;
301 + const char *logfile;
306 + logfile = lp_parm_const_string(SNUM(handle->conn), "glusterfs",
309 + loglevel = lp_parm_int(SNUM(handle->conn), "glusterfs", "loglevel", -1);
311 + volfile_server = lp_parm_const_string(SNUM(handle->conn), "glusterfs",
312 + "volfile_server", NULL);
313 + if (volfile_server == NULL) {
314 + volfile_server = DEFAULT_VOLFILE_SERVER;
317 + volume = lp_parm_const_string(SNUM(handle->conn), "glusterfs", "volume",
319 + if (volume == NULL) {
323 + fs = glfs_find_preopened(volume);
328 + fs = glfs_new(volume);
333 + ret = glfs_set_volfile_server(fs, "tcp", volfile_server, 0);
335 + DEBUG(0, ("Failed to set volfile_server %s\n", volfile_server));
340 + ret = glfs_set_xlator_option(fs, "*-md-cache", "cache-posix-acl",
343 + DEBUG(0, ("%s: Failed to set xlator options\n", volume));
348 + ret = glfs_set_logging(fs, logfile, loglevel);
350 + DEBUG(0, ("%s: Failed to set logfile %s loglevel %d\n",
351 + volume, logfile, loglevel));
356 + ret = glfs_init(fs);
358 + DEBUG(0, ("%s: Failed to initialize volume (%s)\n",
359 + volume, strerror(errno)));
364 + ret = glfs_set_preopened(volume, fs);
366 + DEBUG(0, ("%s: Failed to register volume (%s)\n",
367 + volume, strerror(errno)));
372 + DEBUG(0, ("%s: Initialized volume from server %s\n",
373 + volume, volfile_server));
378 +static void vfs_gluster_disconnect(struct vfs_handle_struct *handle)
384 + glfs_clear_preopened(fs);
388 +vfs_gluster_disk_free(struct vfs_handle_struct *handle, const char *path,
389 + bool small_query, uint64_t *bsize_p, uint64_t *dfree_p,
392 + struct statvfs statvfs = { 0, };
393 + uint64_t dfree = 0;
396 + ret = glfs_statvfs(handle->data, path, &statvfs);
398 + DEBUG(0, ("glfs_statvfs(%s) failed: %s\n",
399 + path, strerror(errno)));
403 + dfree = statvfs.f_bsize * statvfs.f_bavail;
406 + *bsize_p = statvfs.f_bsize;
412 + *dsize_p = statvfs.f_bsize * statvfs.f_blocks;
419 +vfs_gluster_get_quota(struct vfs_handle_struct *handle,
420 + enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
427 +vfs_gluster_set_quota(struct vfs_handle_struct *handle,
428 + enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
434 +static int vfs_gluster_statvfs(struct vfs_handle_struct *handle,
436 + struct vfs_statvfs_struct *vfs_statvfs)
438 + struct statvfs statvfs = { 0, };
441 + ret = glfs_statvfs(handle->data, path, &statvfs);
443 + DEBUG(0, ("glfs_statvfs(%s) failed: %s\n",
444 + path, strerror(errno)));
448 + ZERO_STRUCTP(vfs_statvfs);
450 + vfs_statvfs->OptimalTransferSize = statvfs.f_frsize;
451 + vfs_statvfs->BlockSize = statvfs.f_bsize;
452 + vfs_statvfs->TotalBlocks = statvfs.f_blocks;
453 + vfs_statvfs->BlocksAvail = statvfs.f_bfree;
454 + vfs_statvfs->UserBlocksAvail = statvfs.f_bavail;
455 + vfs_statvfs->TotalFileNodes = statvfs.f_files;
456 + vfs_statvfs->FreeFileNodes = statvfs.f_ffree;
457 + vfs_statvfs->FsIdentifier = statvfs.f_fsid;
458 + vfs_statvfs->FsCapabilities =
459 + FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
464 +static uint32_t vfs_gluster_fs_capabilities(struct vfs_handle_struct *handle,
465 + enum timestamp_set_resolution *p_ts_res)
467 + uint32_t caps = FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
469 +#ifdef STAT_HAVE_NSEC
470 + *p_ts_res = TIMESTAMP_SET_NT_OR_BETTER;
476 +static DIR *vfs_gluster_opendir(struct vfs_handle_struct *handle,
477 + const char *path, const char *mask,
482 + fd = glfs_opendir(handle->data, path);
484 + DEBUG(0, ("glfs_opendir(%s) failed: %s\n",
485 + path, strerror(errno)));
491 +static DIR *vfs_gluster_fdopendir(struct vfs_handle_struct *handle,
492 + files_struct *fsp, const char *mask,
495 + return (DIR *) glfd_fd_get(fsp->fh->fd);
498 +static int vfs_gluster_closedir(struct vfs_handle_struct *handle, DIR *dirp)
500 + return glfs_closedir((void *)dirp);
503 +static SMB_STRUCT_DIRENT *vfs_gluster_readdir(struct vfs_handle_struct *handle,
504 + SMB_STRUCT_DIR *dirp,
505 + SMB_STRUCT_STAT *sbuf)
507 + char direntbuf[512];
510 + struct dirent *dirent = 0;
511 + static SMB_STRUCT_DIRENT result;
513 + if (sbuf != NULL) {
514 + ret = glfs_readdirplus_r((void *)dirp, &stat, (void *)direntbuf,
517 + ret = glfs_readdir_r((void *)dirp, (void *)direntbuf, &dirent);
520 + if (ret < 0 || (dirent == NULL)) {
524 + if (sbuf != NULL) {
525 + smb_stat_ex_from_stat(sbuf, &stat);
528 + result.d_ino = dirent->d_ino;
529 + result.d_off = dirent->d_off;
530 + result.d_reclen = dirent->d_reclen;
531 + result.d_type = dirent->d_type;
532 + strncpy(result.d_name, dirent->d_name, 256);
537 +static long vfs_gluster_telldir(struct vfs_handle_struct *handle, DIR *dirp)
539 + return glfs_telldir((void *)dirp);
542 +static void vfs_gluster_seekdir(struct vfs_handle_struct *handle, DIR *dirp,
545 + glfs_seekdir((void *)dirp, offset);
548 +static void vfs_gluster_rewinddir(struct vfs_handle_struct *handle,
551 + glfs_seekdir((void *)dirp, 0);
554 +static void vfs_gluster_init_search_op(struct vfs_handle_struct *handle,
560 +static int vfs_gluster_mkdir(struct vfs_handle_struct *handle, const char *path,
563 + return glfs_mkdir(handle->data, path, mode);
566 +static int vfs_gluster_rmdir(struct vfs_handle_struct *handle, const char *path)
568 + return glfs_rmdir(handle->data, path);
571 +static int vfs_gluster_open(struct vfs_handle_struct *handle,
572 + struct smb_filename *smb_fname, files_struct *fsp,
573 + int flags, mode_t mode)
577 + if (flags & O_DIRECTORY) {
578 + glfd = glfs_opendir(handle->data, smb_fname->base_name);
579 + } else if (flags & O_CREAT) {
580 + glfd = glfs_creat(handle->data, smb_fname->base_name, flags,
583 + glfd = glfs_open(handle->data, smb_fname->base_name, flags);
586 + if (glfd == NULL) {
587 + DEBUG(0, ("glfs_{open[dir],creat}(%s) failed: %s\n",
588 + smb_fname->base_name, strerror(errno)));
592 + return glfd_fd_store(glfd);
595 +static int vfs_gluster_close(struct vfs_handle_struct *handle,
598 + return glfs_close(glfd_fd_clear(fsp->fh->fd));
601 +static ssize_t vfs_gluster_read(struct vfs_handle_struct *handle,
602 + files_struct *fsp, void *data, size_t n)
604 + return glfs_read(glfd_fd_get(fsp->fh->fd), data, n, 0);
607 +static ssize_t vfs_gluster_pread(struct vfs_handle_struct *handle,
608 + files_struct *fsp, void *data, size_t n,
611 + return glfs_pread(glfd_fd_get(fsp->fh->fd), data, n, offset, 0);
614 +static ssize_t vfs_gluster_write(struct vfs_handle_struct *handle,
615 + files_struct *fsp, const void *data, size_t n)
617 + return glfs_write(glfd_fd_get(fsp->fh->fd), data, n, 0);
620 +static ssize_t vfs_gluster_pwrite(struct vfs_handle_struct *handle,
621 + files_struct *fsp, const void *data, size_t n,
624 + return glfs_pwrite(glfd_fd_get(fsp->fh->fd), data, n, offset, 0);
627 +static off_t vfs_gluster_lseek(struct vfs_handle_struct *handle,
628 + files_struct *fsp, off_t offset, int whence)
630 + return glfs_lseek(glfd_fd_get(fsp->fh->fd), offset, whence);
633 +static ssize_t vfs_gluster_sendfile(struct vfs_handle_struct *handle, int tofd,
634 + files_struct *fromfsp, const DATA_BLOB *hdr,
635 + off_t offset, size_t n)
641 +static ssize_t vfs_gluster_recvfile(struct vfs_handle_struct *handle,
642 + int fromfd, files_struct *tofsp,
643 + off_t offset, size_t n)
649 +static int vfs_gluster_rename(struct vfs_handle_struct *handle,
650 + const struct smb_filename *smb_fname_src,
651 + const struct smb_filename *smb_fname_dst)
653 + return glfs_rename(handle->data, smb_fname_src->base_name,
654 + smb_fname_dst->base_name);
657 +static int vfs_gluster_fsync(struct vfs_handle_struct *handle,
660 + return glfs_fsync(glfd_fd_get(fsp->fh->fd));
663 +static int vfs_gluster_stat(struct vfs_handle_struct *handle,
664 + struct smb_filename *smb_fname)
669 + ret = glfs_stat(handle->data, smb_fname->base_name, &st);
671 + smb_stat_ex_from_stat(&smb_fname->st, &st);
673 + if (ret < 0 && errno != ENOENT) {
674 + DEBUG(0, ("glfs_stat(%s) failed: %s\n",
675 + smb_fname->base_name, strerror(errno)));
680 +static int vfs_gluster_fstat(struct vfs_handle_struct *handle,
681 + files_struct *fsp, SMB_STRUCT_STAT *sbuf)
686 + ret = glfs_fstat(glfd_fd_get(fsp->fh->fd), &st);
688 + smb_stat_ex_from_stat(sbuf, &st);
691 + DEBUG(0, ("glfs_ftat(%d) failed: %s\n",
692 + fsp->fh->fd, strerror(errno)));
697 +static int vfs_gluster_lstat(struct vfs_handle_struct *handle,
698 + struct smb_filename *smb_fname)
703 + ret = glfs_lstat(handle->data, smb_fname->base_name, &st);
705 + smb_stat_ex_from_stat(&smb_fname->st, &st);
707 + if (ret < 0 && errno != ENOENT) {
708 + DEBUG(0, ("glfs_lstat(%s) failed: %s\n",
709 + smb_fname->base_name, strerror(errno)));
715 +static uint64_t vfs_gluster_get_alloc_size(struct vfs_handle_struct *handle,
717 + const SMB_STRUCT_STAT *sbuf)
719 + return sbuf->st_ex_blocks * 512;
722 +static int vfs_gluster_unlink(struct vfs_handle_struct *handle,
723 + const struct smb_filename *smb_fname)
725 + return glfs_unlink(handle->data, smb_fname->base_name);
728 +static int vfs_gluster_chmod(struct vfs_handle_struct *handle,
729 + const char *path, mode_t mode)
731 + return glfs_chmod(handle->data, path, mode);
734 +static int vfs_gluster_fchmod(struct vfs_handle_struct *handle,
735 + files_struct *fsp, mode_t mode)
737 + return glfs_fchmod(glfd_fd_get(fsp->fh->fd), mode);
740 +static int vfs_gluster_chown(struct vfs_handle_struct *handle,
741 + const char *path, uid_t uid, gid_t gid)
743 + return glfs_chown(handle->data, path, uid, gid);
746 +static int vfs_gluster_fchown(struct vfs_handle_struct *handle,
747 + files_struct *fsp, uid_t uid, gid_t gid)
749 + return glfs_fchown(glfd_fd_get(fsp->fh->fd), uid, gid);
752 +static int vfs_gluster_lchown(struct vfs_handle_struct *handle,
753 + const char *path, uid_t uid, gid_t gid)
755 + return glfs_lchown(handle->data, path, uid, gid);
758 +static int vfs_gluster_chdir(struct vfs_handle_struct *handle, const char *path)
760 + return glfs_chdir(handle->data, path);
763 +static char *vfs_gluster_getwd(struct vfs_handle_struct *handle, char *path)
765 + return glfs_getcwd(handle->data, path, PATH_MAX);
768 +static int vfs_gluster_ntimes(struct vfs_handle_struct *handle,
769 + const struct smb_filename *smb_fname,
770 + struct smb_file_time *ft)
772 + struct timespec times[2];
774 + times[0].tv_sec = ft->atime.tv_sec;
775 + times[0].tv_nsec = ft->atime.tv_nsec;
776 + times[1].tv_sec = ft->mtime.tv_sec;
777 + times[1].tv_nsec = ft->mtime.tv_nsec;
779 + return glfs_utimens(handle->data, smb_fname->base_name, times);
782 +static int vfs_gluster_ftruncate(struct vfs_handle_struct *handle,
783 + files_struct *fsp, off_t offset)
785 + return glfs_ftruncate(glfd_fd_get(fsp->fh->fd), offset);
788 +static int vfs_gluster_fallocate(struct vfs_handle_struct *handle,
789 + struct files_struct *fsp,
790 + enum vfs_fallocate_mode mode,
791 + off_t offset, off_t len)
797 +static char *vfs_gluster_realpath(struct vfs_handle_struct *handle,
800 + return glfs_realpath(handle->data, path, 0);
803 +static bool vfs_gluster_lock(struct vfs_handle_struct *handle,
804 + files_struct *fsp, int op, off_t offset,
805 + off_t count, int type)
807 + struct flock flock = { 0, };
810 + flock.l_type = type;
811 + flock.l_whence = SEEK_SET;
812 + flock.l_start = offset;
813 + flock.l_len = count;
816 + ret = glfs_posix_lock(glfd_fd_get(fsp->fh->fd), op, &flock);
818 + if (op == F_GETLK) {
819 + /* lock query, true if someone else has locked */
821 + (flock.l_type != F_UNLCK) &&
822 + (flock.l_pid != 0) && (flock.l_pid != getpid()))
835 +static int vfs_gluster_kernel_flock(struct vfs_handle_struct *handle,
836 + files_struct *fsp, uint32 share_mode,
837 + uint32_t access_mask)
842 +static int vfs_gluster_linux_setlease(struct vfs_handle_struct *handle,
843 + files_struct *fsp, int leasetype)
849 +static bool vfs_gluster_getlock(struct vfs_handle_struct *handle,
850 + files_struct *fsp, off_t *poffset,
851 + off_t *pcount, int *ptype, pid_t *ppid)
853 + struct flock flock = { 0, };
856 + flock.l_type = *ptype;
857 + flock.l_whence = SEEK_SET;
858 + flock.l_start = *poffset;
859 + flock.l_len = *pcount;
862 + ret = glfs_posix_lock(glfd_fd_get(fsp->fh->fd), F_GETLK, &flock);
868 + *ptype = flock.l_type;
869 + *poffset = flock.l_start;
870 + *pcount = flock.l_len;
871 + *ppid = flock.l_pid;
876 +static int vfs_gluster_symlink(struct vfs_handle_struct *handle,
877 + const char *oldpath, const char *newpath)
879 + return glfs_symlink(handle->data, oldpath, newpath);
882 +static int vfs_gluster_readlink(struct vfs_handle_struct *handle,
883 + const char *path, char *buf, size_t bufsiz)
885 + return glfs_readlink(handle->data, path, buf, bufsiz);
888 +static int vfs_gluster_link(struct vfs_handle_struct *handle,
889 + const char *oldpath, const char *newpath)
891 + return glfs_link(handle->data, oldpath, newpath);
894 +static int vfs_gluster_mknod(struct vfs_handle_struct *handle, const char *path,
895 + mode_t mode, SMB_DEV_T dev)
897 + return glfs_mknod(handle->data, path, mode, dev);
900 +static NTSTATUS vfs_gluster_notify_watch(struct vfs_handle_struct *vfs_handle,
901 + struct sys_notify_context *ctx,
902 + struct notify_entry *e,
903 + void (*callback) (struct sys_notify_context *ctx,
904 + void *private_data,
905 + struct notify_event *ev),
906 + void *private_data, void *handle)
908 + return NT_STATUS_NOT_IMPLEMENTED;
911 +static int vfs_gluster_chflags(struct vfs_handle_struct *handle,
912 + const char *path, unsigned int flags)
918 +static int vfs_gluster_get_real_filename(struct vfs_handle_struct *handle,
919 + const char *path, const char *name,
920 + TALLOC_CTX *mem_ctx, char **found_name)
923 + char key_buf[NAME_MAX + 64];
924 + char val_buf[NAME_MAX + 1];
926 + if (strlen(name) >= NAME_MAX) {
927 + errno = ENAMETOOLONG;
931 + snprintf(key_buf, NAME_MAX + 64,
932 + "user.glusterfs.get_real_filename:%s", name);
934 + ret = glfs_getxattr(handle->data, path, key_buf, val_buf, NAME_MAX + 1);
935 + if (ret == -1 && errno == ENODATA) {
936 + errno = EOPNOTSUPP;
940 + *found_name = talloc_strdup(mem_ctx, val_buf);
941 + if (found_name[0] == NULL) {
948 +static const char *vfs_gluster_connectpath(struct vfs_handle_struct *handle,
949 + const char *filename)
951 + return handle->conn->connectpath;
956 +static ssize_t vfs_gluster_getxattr(struct vfs_handle_struct *handle,
957 + const char *path, const char *name,
958 + void *value, size_t size)
960 + return glfs_getxattr(handle->data, path, name, value, size);
963 +static ssize_t vfs_gluster_lgetxattr(struct vfs_handle_struct *handle,
964 + const char *path, const char *name,
965 + void *value, size_t size)
967 + return glfs_lgetxattr(handle->data, path, name, value, size);
970 +static ssize_t vfs_gluster_fgetxattr(struct vfs_handle_struct *handle,
971 + files_struct *fsp, const char *name,
972 + void *value, size_t size)
974 + return glfs_fgetxattr(glfd_fd_get(fsp->fh->fd), name, value, size);
977 +static ssize_t vfs_gluster_listxattr(struct vfs_handle_struct *handle,
978 + const char *path, char *list, size_t size)
980 + return glfs_listxattr(handle->data, path, list, size);
983 +static ssize_t vfs_gluster_llistxattr(struct vfs_handle_struct *handle,
984 + const char *path, char *list, size_t size)
986 + return glfs_llistxattr(handle->data, path, list, size);
989 +static ssize_t vfs_gluster_flistxattr(struct vfs_handle_struct *handle,
990 + files_struct *fsp, char *list,
993 + return glfs_flistxattr(glfd_fd_get(fsp->fh->fd), list, size);
996 +static int vfs_gluster_removexattr(struct vfs_handle_struct *handle,
997 + const char *path, const char *name)
999 + return glfs_removexattr(handle->data, path, name);
1002 +static int vfs_gluster_lremovexattr(struct vfs_handle_struct *handle,
1003 + const char *path, const char *name)
1005 + return glfs_lremovexattr(handle->data, path, name);
1008 +static int vfs_gluster_fremovexattr(struct vfs_handle_struct *handle,
1009 + files_struct *fsp, const char *name)
1011 + return glfs_fremovexattr(glfd_fd_get(fsp->fh->fd), name);
1014 +static int vfs_gluster_setxattr(struct vfs_handle_struct *handle,
1015 + const char *path, const char *name,
1016 + const void *value, size_t size, int flags)
1018 + return glfs_setxattr(handle->data, path, name, value, size, flags);
1021 +static int vfs_gluster_lsetxattr(struct vfs_handle_struct *handle,
1022 + const char *path, const char *name,
1023 + const void *value, size_t size, int flags)
1025 + return glfs_lsetxattr(handle->data, path, name, value, size, flags);
1028 +static int vfs_gluster_fsetxattr(struct vfs_handle_struct *handle,
1029 + files_struct *fsp, const char *name,
1030 + const void *value, size_t size, int flags)
1032 + return glfs_fsetxattr(glfd_fd_get(fsp->fh->fd), name, value, size,
1036 +/* AIO Operations */
1038 +static bool vfs_gluster_aio_force(struct vfs_handle_struct *handle,
1039 + files_struct *fsp)
1044 +/* Offline Operations */
1046 +static bool vfs_gluster_is_offline(struct vfs_handle_struct *handle,
1047 + const struct smb_filename *fname,
1048 + SMB_STRUCT_STAT *sbuf)
1053 +static int vfs_gluster_set_offline(struct vfs_handle_struct *handle,
1054 + const struct smb_filename *fname)
1060 +/* Posix ACL Operations */
1062 +#define GLUSTER_ACL_VERSION 2
1063 +#define GLUSTER_ACL_READ 0x04
1064 +#define GLUSTER_ACL_WRITE 0x02
1065 +#define GLUSTER_ACL_EXECUTE 0x01
1067 +#define GLUSTER_ACL_UNDEFINED_TAG 0x00
1068 +#define GLUSTER_ACL_USER_OBJ 0x01
1069 +#define GLUSTER_ACL_USER 0x02
1070 +#define GLUSTER_ACL_GROUP_OBJ 0x04
1071 +#define GLUSTER_ACL_GROUP 0x08
1072 +#define GLUSTER_ACL_MASK 0x10
1073 +#define GLUSTER_ACL_OTHER 0x20
1075 +#define GLUSTER_ACL_UNDEFINED_ID (-1)
1077 +struct gluster_ace {
1083 +struct gluster_acl_header {
1085 + struct gluster_ace entries[];
1088 +static SMB_ACL_T gluster_to_smb_acl(const char *buf, size_t xattr_size)
1092 + struct gluster_ace *ace;
1093 + struct smb_acl_entry *smb_ace;
1094 + struct gluster_acl_header *hdr;
1095 + struct smb_acl_t *result;
1101 + size = xattr_size;
1103 + if (size < sizeof(*hdr)) {
1104 + /* ACL should be at least as big as the header */
1109 + size -= sizeof(*hdr);
1111 + if (size % sizeof(*ace)) {
1112 + /* Size of entries must strictly be a multiple of
1119 + count = size / sizeof(*ace);
1121 + hdr = (void *)buf;
1123 + if (ntohl(hdr->version) != GLUSTER_ACL_VERSION) {
1124 + DEBUG(0, ("Unknown gluster ACL version: %d\n",
1125 + ntohl(hdr->version)));
1129 + result = SMB_MALLOC(sizeof(struct smb_acl_t) + (sizeof(struct smb_acl_entry) * count));
1135 + result->count = count;
1137 + smb_ace = result->acl;
1138 + ace = hdr->entries;
1140 + for (i = 0; i < count; i++) {
1141 + tag = ntohs(ace->tag);
1144 + case GLUSTER_ACL_USER:
1145 + smb_ace->a_type = SMB_ACL_USER;
1147 + case GLUSTER_ACL_USER_OBJ:
1148 + smb_ace->a_type = SMB_ACL_USER_OBJ;
1150 + case GLUSTER_ACL_GROUP:
1151 + smb_ace->a_type = SMB_ACL_GROUP;
1153 + case GLUSTER_ACL_GROUP_OBJ:
1154 + smb_ace->a_type = SMB_ACL_GROUP_OBJ;
1156 + case GLUSTER_ACL_OTHER:
1157 + smb_ace->a_type = SMB_ACL_OTHER;
1159 + case GLUSTER_ACL_MASK:
1160 + smb_ace->a_type = SMB_ACL_MASK;
1163 + DEBUG(0, ("unknown tag type %d\n", (unsigned int) tag));
1167 + id = ntohl(ace->id);
1169 + switch(smb_ace->a_type) {
1170 + case SMB_ACL_USER:
1171 + smb_ace->uid = id;
1173 + case SMB_ACL_GROUP:
1174 + smb_ace->gid = id;
1180 + perm = ntohs(ace->perm);
1182 + smb_ace->a_perm = 0;
1183 + smb_ace->a_perm |=
1184 + ((perm & GLUSTER_ACL_READ) ? SMB_ACL_READ : 0);
1185 + smb_ace->a_perm |=
1186 + ((perm & GLUSTER_ACL_WRITE) ? SMB_ACL_WRITE : 0);
1187 + smb_ace->a_perm |=
1188 + ((perm & GLUSTER_ACL_EXECUTE) ? SMB_ACL_EXECUTE : 0);
1197 +static ssize_t smb_to_gluster_acl(SMB_ACL_T theacl, char *buf, size_t len)
1200 + struct gluster_ace *ace;
1201 + struct smb_acl_entry *smb_ace;
1202 + struct gluster_acl_header *hdr;
1209 + count = theacl->count;
1211 + size = sizeof(*hdr) + (count * sizeof(*ace));
1221 + hdr = (void *)buf;
1222 + ace = hdr->entries;
1223 + smb_ace = theacl->acl;
1225 + hdr->version = htonl(GLUSTER_ACL_VERSION);
1227 + for (i = 0; i < count; i++) {
1228 + switch(smb_ace->a_type) {
1229 + case SMB_ACL_USER:
1230 + tag = GLUSTER_ACL_USER;
1232 + case SMB_ACL_USER_OBJ:
1233 + tag = GLUSTER_ACL_USER_OBJ;
1235 + case SMB_ACL_GROUP:
1236 + tag = GLUSTER_ACL_GROUP;
1238 + case SMB_ACL_GROUP_OBJ:
1239 + tag = GLUSTER_ACL_GROUP_OBJ;
1241 + case SMB_ACL_OTHER:
1242 + tag = GLUSTER_ACL_OTHER;
1244 + case SMB_ACL_MASK:
1245 + tag = GLUSTER_ACL_MASK;
1248 + DEBUG(0, ("Unknown tag value %d\n",
1249 + smb_ace->a_type));
1254 + ace->tag = ntohs(tag);
1256 + switch(smb_ace->a_type) {
1257 + case SMB_ACL_USER:
1258 + id = smb_ace->uid;
1260 + case SMB_ACL_GROUP:
1261 + id = smb_ace->gid;
1264 + id = GLUSTER_ACL_UNDEFINED_ID;
1268 + ace->id = ntohl(id);
1272 + ((smb_ace->a_perm & SMB_ACL_READ) ? GLUSTER_ACL_READ : 0);
1274 + ((smb_ace->a_perm & SMB_ACL_WRITE) ? GLUSTER_ACL_WRITE : 0);
1276 + ((smb_ace->a_perm & SMB_ACL_EXECUTE) ? GLUSTER_ACL_EXECUTE : 0);
1286 +static SMB_ACL_T vfs_gluster_sys_acl_get_file(struct vfs_handle_struct *handle,
1287 + const char *path_p,
1288 + SMB_ACL_TYPE_T type)
1290 + struct smb_acl_t *result;
1296 + case SMB_ACL_TYPE_ACCESS:
1297 + key = "system.posix_acl_access";
1299 + case SMB_ACL_TYPE_DEFAULT:
1300 + key = "system.posix_acl_default";
1307 + ret = glfs_getxattr(handle->data, path_p, key, 0, 0);
1312 + buf = alloca(ret);
1313 + ret = glfs_getxattr(handle->data, path_p, key, buf, ret);
1318 + result = gluster_to_smb_acl(buf, ret);
1323 +static SMB_ACL_T vfs_gluster_sys_acl_get_fd(struct vfs_handle_struct *handle,
1324 + struct files_struct *fsp)
1326 + struct smb_acl_t *result;
1330 + ret = glfs_fgetxattr(glfd_fd_get(fsp->fh->fd),
1331 + "system.posix_acl_access", 0, 0);
1336 + buf = alloca(ret);
1337 + ret = glfs_fgetxattr(glfd_fd_get(fsp->fh->fd),
1338 + "system.posix_acl_access", buf, ret);
1343 + result = gluster_to_smb_acl(buf, ret);
1348 +static int vfs_gluster_sys_acl_set_file(struct vfs_handle_struct *handle,
1350 + SMB_ACL_TYPE_T acltype,
1358 + switch (acltype) {
1359 + case SMB_ACL_TYPE_ACCESS:
1360 + key = "system.posix_acl_access";
1362 + case SMB_ACL_TYPE_DEFAULT:
1363 + key = "system.posix_acl_default";
1370 + size = smb_to_gluster_acl(theacl, 0, 0);
1371 + buf = alloca(size);
1373 + size = smb_to_gluster_acl(theacl, buf, size);
1378 + ret = glfs_setxattr(handle->data, name, key, buf, size, 0);
1383 +static int vfs_gluster_sys_acl_set_fd(struct vfs_handle_struct *handle,
1384 + struct files_struct *fsp,
1391 + size = smb_to_gluster_acl(theacl, 0, 0);
1392 + buf = alloca(size);
1394 + size = smb_to_gluster_acl(theacl, buf, size);
1399 + ret = glfs_fsetxattr(glfd_fd_get(fsp->fh->fd),
1400 + "system.posix_acl_access", buf, size, 0);
1404 +static int vfs_gluster_sys_acl_delete_def_file(struct vfs_handle_struct *handle,
1407 + return glfs_removexattr(handle->data, path, "system.posix_acl_default");
1410 +static struct vfs_fn_pointers glusterfs_fns = {
1412 + /* Disk Operations */
1414 + .connect_fn = vfs_gluster_connect,
1415 + .disconnect = vfs_gluster_disconnect,
1416 + .disk_free = vfs_gluster_disk_free,
1417 + .get_quota = vfs_gluster_get_quota,
1418 + .set_quota = vfs_gluster_set_quota,
1419 + .statvfs = vfs_gluster_statvfs,
1420 + .fs_capabilities = vfs_gluster_fs_capabilities,
1422 + /* Directory Operations */
1424 + .opendir = vfs_gluster_opendir,
1425 + .fdopendir = vfs_gluster_fdopendir,
1426 + .readdir = vfs_gluster_readdir,
1427 + .seekdir = vfs_gluster_seekdir,
1428 + .telldir = vfs_gluster_telldir,
1429 + .rewind_dir = vfs_gluster_rewinddir,
1430 + .mkdir = vfs_gluster_mkdir,
1431 + .rmdir = vfs_gluster_rmdir,
1432 + .closedir = vfs_gluster_closedir,
1433 + .init_search_op = vfs_gluster_init_search_op,
1435 + /* File Operations */
1437 + .open_fn = vfs_gluster_open,
1438 + .create_file = NULL,
1439 + .close_fn = vfs_gluster_close,
1440 + .vfs_read = vfs_gluster_read,
1441 + .pread = vfs_gluster_pread,
1442 + .write = vfs_gluster_write,
1443 + .pwrite = vfs_gluster_pwrite,
1444 + .lseek = vfs_gluster_lseek,
1445 + .sendfile = vfs_gluster_sendfile,
1446 + .recvfile = vfs_gluster_recvfile,
1447 + .rename = vfs_gluster_rename,
1448 + .fsync = vfs_gluster_fsync,
1449 + .stat = vfs_gluster_stat,
1450 + .fstat = vfs_gluster_fstat,
1451 + .lstat = vfs_gluster_lstat,
1452 + .get_alloc_size = vfs_gluster_get_alloc_size,
1453 + .unlink = vfs_gluster_unlink,
1455 + .chmod = vfs_gluster_chmod,
1456 + .fchmod = vfs_gluster_fchmod,
1457 + .chown = vfs_gluster_chown,
1458 + .fchown = vfs_gluster_fchown,
1459 + .lchown = vfs_gluster_lchown,
1460 + .chdir = vfs_gluster_chdir,
1461 + .getwd = vfs_gluster_getwd,
1462 + .ntimes = vfs_gluster_ntimes,
1463 + .ftruncate = vfs_gluster_ftruncate,
1464 + .fallocate = vfs_gluster_fallocate,
1465 + .lock = vfs_gluster_lock,
1466 + .kernel_flock = vfs_gluster_kernel_flock,
1467 + .linux_setlease = vfs_gluster_linux_setlease,
1468 + .getlock = vfs_gluster_getlock,
1469 + .symlink = vfs_gluster_symlink,
1470 + .vfs_readlink = vfs_gluster_readlink,
1471 + .link = vfs_gluster_link,
1472 + .mknod = vfs_gluster_mknod,
1473 + .realpath = vfs_gluster_realpath,
1474 + .notify_watch = vfs_gluster_notify_watch,
1475 + .chflags = vfs_gluster_chflags,
1476 + .file_id_create = NULL,
1477 + .streaminfo = NULL,
1478 + .get_real_filename = vfs_gluster_get_real_filename,
1479 + .connectpath = vfs_gluster_connectpath,
1481 + .brl_lock_windows = NULL,
1482 + .brl_unlock_windows = NULL,
1483 + .brl_cancel_windows = NULL,
1484 + .strict_lock = NULL,
1485 + .strict_unlock = NULL,
1486 + .translate_name = NULL,
1488 + /* NT ACL Operations */
1489 + .fget_nt_acl = NULL,
1490 + .get_nt_acl = NULL,
1491 + .fset_nt_acl = NULL,
1493 + /* Posix ACL Operations */
1494 + .chmod_acl = NULL, /* passthrough to default */
1495 + .fchmod_acl = NULL, /* passthrough to default */
1497 + .sys_acl_get_entry = NULL,
1498 + .sys_acl_get_tag_type = NULL,
1499 + .sys_acl_get_permset = NULL,
1500 + .sys_acl_get_qualifier = NULL,
1501 + .sys_acl_get_file = vfs_gluster_sys_acl_get_file,
1502 + .sys_acl_get_fd = vfs_gluster_sys_acl_get_fd,
1503 + .sys_acl_clear_perms = NULL,
1504 + .sys_acl_add_perm = NULL,
1505 + .sys_acl_to_text = NULL,
1506 + .sys_acl_init = NULL,
1507 + .sys_acl_create_entry = NULL,
1508 + .sys_acl_set_tag_type = NULL,
1509 + .sys_acl_set_qualifier = NULL,
1510 + .sys_acl_set_permset = NULL,
1511 + .sys_acl_valid = NULL,
1512 + .sys_acl_set_file = vfs_gluster_sys_acl_set_file,
1513 + .sys_acl_set_fd = vfs_gluster_sys_acl_set_fd,
1514 + .sys_acl_delete_def_file = vfs_gluster_sys_acl_delete_def_file,
1515 + .sys_acl_get_perm = NULL,
1516 + .sys_acl_free_text = NULL,
1517 + .sys_acl_free_acl = NULL,
1518 + .sys_acl_free_qualifier = NULL,
1520 + /* EA Operations */
1521 + .getxattr = vfs_gluster_getxattr,
1522 + .lgetxattr = vfs_gluster_lgetxattr,
1523 + .fgetxattr = vfs_gluster_fgetxattr,
1524 + .listxattr = vfs_gluster_listxattr,
1525 + .llistxattr = vfs_gluster_llistxattr,
1526 + .flistxattr = vfs_gluster_flistxattr,
1527 + .removexattr = vfs_gluster_removexattr,
1528 + .lremovexattr = vfs_gluster_lremovexattr,
1529 + .fremovexattr = vfs_gluster_fremovexattr,
1530 + .setxattr = vfs_gluster_setxattr,
1531 + .lsetxattr = vfs_gluster_lsetxattr,
1532 + .fsetxattr = vfs_gluster_fsetxattr,
1534 + /* AIO Operations */
1536 + .aio_write = NULL,
1537 + .aio_return_fn = NULL,
1538 + .aio_cancel = NULL,
1539 + .aio_error_fn = NULL,
1540 + .aio_fsync = NULL,
1541 + .aio_suspend = NULL,
1542 + .aio_force = vfs_gluster_aio_force,
1544 + /* Offline Operations */
1545 + .is_offline = vfs_gluster_is_offline,
1546 + .set_offline = vfs_gluster_set_offline,
1549 +NTSTATUS vfs_glusterfs_init(void);
1550 +NTSTATUS vfs_glusterfs_init(void)
1552 + return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
1553 + "glusterfs", &glusterfs_fns);
1555 diff --git a/source3/modules/wscript_build b/source3/modules/wscript_build
1556 index ff7163f..31c93be 100644
1557 --- a/source3/modules/wscript_build
1558 +++ b/source3/modules/wscript_build
1559 @@ -50,6 +50,7 @@ VFS_SCANNEDONLY_SRC = 'vfs_scannedonly.c'
1560 VFS_CROSSRENAME_SRC = 'vfs_crossrename.c'
1561 VFS_LINUX_XFS_SGID_SRC = 'vfs_linux_xfs_sgid.c'
1562 VFS_TIME_AUDIT_SRC = 'vfs_time_audit.c'
1563 +VFS_GLUSTERFS_SRC = 'vfs_glusterfs.c'
1566 bld.SAMBA3_SUBSYSTEM('NFS4_ACLS',
1567 @@ -408,6 +409,14 @@ bld.SAMBA3_MODULE('vfs_time_audit',
1568 internal_module=bld.SAMBA3_IS_STATIC_MODULE('vfs_time_audit'),
1569 enabled=bld.SAMBA3_IS_ENABLED_MODULE('vfs_time_audit'))
1571 +bld.SAMBA3_MODULE('vfs_glusterfs',
1573 + source=VFS_GLUSTERFS_SRC,
1574 + deps='samba-util gfapi',
1576 + internal_module=bld.SAMBA3_IS_STATIC_MODULE('vfs_glusterfs'),
1577 + enabled=bld.SAMBA3_IS_ENABLED_MODULE('vfs_glusterfs'),
1578 + allow_undefined_symbols=False)
1581 CHARSET_WEIRD_SRC = 'weird.c'
1582 diff --git a/source3/wscript b/source3/wscript
1583 index bcc6ce1..7e34db5 100644
1584 --- a/source3/wscript
1585 +++ b/source3/wscript
1586 @@ -60,6 +60,7 @@ def set_options(opt):
1587 opt.SAMBA3_ADD_OPTION('automount')
1588 opt.SAMBA3_ADD_OPTION('aio-support')
1589 opt.SAMBA3_ADD_OPTION('profiling-data')
1590 + opt.SAMBA3_ADD_OPTION('glusterfs', with_name="enable", without_name="disable", default=True)
1592 opt.SAMBA3_ADD_OPTION('cluster-support')
1594 @@ -1701,6 +1702,24 @@ main() {
1595 conf.undefine('CLUSTER_SUPPORT')
1599 + # Checking for GlusterFS
1601 + if Options.options.with_glusterfs:
1602 + conf.check_cfg(package='glusterfs-api', args='"glusterfs-api >= 4" --cflags --libs',
1603 + msg='Checking for glusterfs-api >= 4', uselib_store="GFAPI")
1604 + conf.CHECK_HEADERS('api/glfs.h', lib='gfapi')
1605 + conf.CHECK_LIB('gfapi', shlib=True)
1607 + if conf.CONFIG_SET('HAVE_API_GLFS_H'):
1608 + conf.DEFINE('HAVE_GLUSTERFS', '1')
1610 + conf.SET_TARGET_TYPE('gfapi', 'EMPTY')
1611 + conf.undefine('HAVE_GLUSTERFS')
1613 + conf.SET_TARGET_TYPE('gfapi', 'EMPTY')
1614 + conf.undefine('HAVE_GLUSTERFS')
1617 conf.CHECK_CODE('__attribute__((destructor)) static void cleanup(void) { }',
1618 'HAVE_FUNCTION_ATTRIBUTE_DESTRUCTOR',
1619 @@ -1794,6 +1813,9 @@ main() {
1620 if conf.CONFIG_SET('HAVE_GPFS'):
1621 default_shared_modules.extend(TO_LIST('vfs_gpfs vfs_gpfs_hsm_notify'))
1623 + if conf.CONFIG_SET('HAVE_GLUSTERFS'):
1624 + default_shared_modules.extend(TO_LIST('vfs_glusterfs'))
1626 explicit_shared_modules = TO_LIST(Options.options.shared_modules, delimiter=',')
1627 explicit_static_modules = TO_LIST(Options.options.static_modules, delimiter=',')
1633 From e2b70ae1e9b072173de2b7d6140381b910d436b4 Mon Sep 17 00:00:00 2001
1634 From: Raghavendra Talur <rtalur@redhat.com>
1635 Date: Thu, 20 Jun 2013 17:58:15 -0700
1636 Subject: [PATCH 2/9] PATCHSET13: vfs_glusterfs: New file creation fix.
1638 When a new document is created in explorer, a check for file_exist is made.
1639 vfs_gluster_get_real_filename was returning 0 even when the file did not
1642 source3/modules/vfs_glusterfs.c | 6 ++++--
1643 1 file changed, 4 insertions(+), 2 deletions(-)
1645 diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c
1646 index 4beac1d..3752940 100644
1647 --- a/source3/modules/vfs_glusterfs.c
1648 +++ b/source3/modules/vfs_glusterfs.c
1649 @@ -839,8 +839,10 @@ static int vfs_gluster_get_real_filename(struct vfs_handle_struct *handle,
1650 "user.glusterfs.get_real_filename:%s", name);
1652 ret = glfs_getxattr(handle->data, path, key_buf, val_buf, NAME_MAX + 1);
1653 - if (ret == -1 && errno == ENODATA) {
1654 - errno = EOPNOTSUPP;
1656 + if (errno == ENODATA) {
1657 + errno = EOPNOTSUPP;
1666 From e963ec42b17cdc7369e4b79387447bb3ddc99d2a Mon Sep 17 00:00:00 2001
1667 From: susant <spalai@redhat.com>
1668 Date: Wed, 7 Aug 2013 01:00:31 -0500
1669 Subject: [PATCH 3/9] PATCHSET13: vfs_glusterfs: Volume capacity reported to
1670 Windows is incorrect
1672 VFS plugin was sending the actual size of the volume instead of the
1673 total number of block units because of which windows was getting the
1674 wrong volume capacity.
1676 Signed-off-by: susant <spalai@redhat.com>
1677 Reviewed-by: Anand Avati <avati@redhat.com>
1679 source3/modules/vfs_glusterfs.c | 11 ++++-------
1680 1 file changed, 4 insertions(+), 7 deletions(-)
1682 diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c
1683 index 3752940..1502776 100644
1684 --- a/source3/modules/vfs_glusterfs.c
1685 +++ b/source3/modules/vfs_glusterfs.c
1686 @@ -297,7 +297,6 @@ vfs_gluster_disk_free(struct vfs_handle_struct *handle, const char *path,
1689 struct statvfs statvfs = { 0, };
1690 - uint64_t dfree = 0;
1693 ret = glfs_statvfs(handle->data, path, &statvfs);
1694 @@ -307,19 +306,17 @@ vfs_gluster_disk_free(struct vfs_handle_struct *handle, const char *path,
1698 - dfree = statvfs.f_bsize * statvfs.f_bavail;
1701 - *bsize_p = statvfs.f_bsize;
1702 + *bsize_p = (uint64_t)statvfs.f_bsize; /* Block size */
1706 + *dfree_p = (uint64_t)statvfs.f_bavail; /* Available Block units */
1709 - *dsize_p = statvfs.f_bsize * statvfs.f_blocks;
1710 + *dsize_p = (uint64_t)statvfs.f_blocks; /* Total Block units */
1714 + return (uint64_t)statvfs.f_bavail;
1722 From 1d41227866ede7ae14857105abd6b322e8e41525 Mon Sep 17 00:00:00 2001
1723 From: Anand Avati <avati@redhat.com>
1724 Date: Mon, 12 Aug 2013 14:59:24 -0500
1725 Subject: [PATCH 4/9] PATCHSET13: vfs_glusterfs: Implement proper
1726 mashalling/unmarshalling of ACLs
1728 Use the primitives available in Samba byteorder.h for implementing
1729 proper (un)marshalling of ACL xattrs.
1731 Signed-off-by: Anand Avati <avati@redhat.com>
1732 Reviewed-by: Raghavendra Talur <rtalur@redhat.com>
1733 Reviewed-by: Jeremy Allison <jra@samba.org>
1734 Tested-by: "Jose A. Rivera" <jarrpa@redhat.com>
1736 source3/modules/vfs_glusterfs.c | 154 +++++++++++++++++++++++++++++-----------
1737 1 file changed, 112 insertions(+), 42 deletions(-)
1739 diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c
1740 index 1502776..1b81d06 100644
1741 --- a/source3/modules/vfs_glusterfs.c
1742 +++ b/source3/modules/vfs_glusterfs.c
1743 @@ -963,13 +963,36 @@ static int vfs_gluster_set_offline(struct vfs_handle_struct *handle,
1747 -/* Posix ACL Operations */
1749 + Gluster ACL Format:
1751 + Size = 4 (header) + N * 8 (entry)
1753 + Offset Size Field (Little Endian)
1754 + -------------------------------------
1755 + 0-3 4-byte Version
1757 + 4-5 2-byte Entry-1 tag
1758 + 6-7 2-byte Entry-1 perm
1759 + 8-11 4-byte Entry-1 id
1761 + 12-13 2-byte Entry-2 tag
1762 + 14-15 2-byte Entry-2 perm
1763 + 16-19 4-byte Entry-2 id
1769 +/* header version */
1770 #define GLUSTER_ACL_VERSION 2
1773 #define GLUSTER_ACL_READ 0x04
1774 #define GLUSTER_ACL_WRITE 0x02
1775 #define GLUSTER_ACL_EXECUTE 0x01
1778 #define GLUSTER_ACL_UNDEFINED_TAG 0x00
1779 #define GLUSTER_ACL_USER_OBJ 0x01
1780 #define GLUSTER_ACL_USER 0x02
1781 @@ -980,57 +1003,48 @@ static int vfs_gluster_set_offline(struct vfs_handle_struct *handle,
1783 #define GLUSTER_ACL_UNDEFINED_ID (-1)
1785 -struct gluster_ace {
1791 -struct gluster_acl_header {
1793 - struct gluster_ace entries[];
1795 +#define GLUSTER_ACL_HEADER_SIZE 4
1796 +#define GLUSTER_ACL_ENTRY_SIZE 8
1798 static SMB_ACL_T gluster_to_smb_acl(const char *buf, size_t xattr_size)
1802 - struct gluster_ace *ace;
1803 struct smb_acl_entry *smb_ace;
1804 - struct gluster_acl_header *hdr;
1805 struct smb_acl_t *result;
1814 - if (size < sizeof(*hdr)) {
1815 - /* ACL should be at least as big as the header */
1816 + if (size < GLUSTER_ACL_HEADER_SIZE) {
1817 + /* ACL should be at least as big as the header (4 bytes) */
1822 - size -= sizeof(*hdr);
1823 + size -= GLUSTER_ACL_HEADER_SIZE; /* size of header = 4 bytes */
1825 - if (size % sizeof(*ace)) {
1826 + if (size % GLUSTER_ACL_ENTRY_SIZE) {
1827 /* Size of entries must strictly be a multiple of
1829 + size of an ACE (8 bytes)
1835 - count = size / sizeof(*ace);
1837 - hdr = (void *)buf;
1838 + count = size / GLUSTER_ACL_ENTRY_SIZE;
1840 - if (ntohl(hdr->version) != GLUSTER_ACL_VERSION) {
1841 + /* Version is the first 4 bytes of the ACL */
1842 + if (IVAL(buf, 0) != GLUSTER_ACL_VERSION) {
1843 DEBUG(0, ("Unknown gluster ACL version: %d\n",
1844 - ntohl(hdr->version)));
1848 + offset = GLUSTER_ACL_HEADER_SIZE;
1850 result = SMB_MALLOC(sizeof(struct smb_acl_t) + (sizeof(struct smb_acl_entry) * count));
1852 @@ -1041,10 +1055,19 @@ static SMB_ACL_T gluster_to_smb_acl(const char *buf, size_t xattr_size)
1853 result->count = count;
1855 smb_ace = result->acl;
1856 - ace = hdr->entries;
1858 for (i = 0; i < count; i++) {
1859 - tag = ntohs(ace->tag);
1860 + /* TAG is the first 2 bytes of an entry */
1861 + tag = SVAL(buf, offset);
1864 + /* PERM is the next 2 bytes of an entry */
1865 + perm = SVAL(buf, offset);
1868 + /* ID is the last 4 bytes of an entry */
1869 + id = IVAL(buf, offset);
1873 case GLUSTER_ACL_USER:
1874 @@ -1070,7 +1093,6 @@ static SMB_ACL_T gluster_to_smb_acl(const char *buf, size_t xattr_size)
1878 - id = ntohl(ace->id);
1880 switch(smb_ace->a_type) {
1882 @@ -1083,8 +1105,6 @@ static SMB_ACL_T gluster_to_smb_acl(const char *buf, size_t xattr_size)
1886 - perm = ntohs(ace->perm);
1888 smb_ace->a_perm = 0;
1890 ((perm & GLUSTER_ACL_READ) ? SMB_ACL_READ : 0);
1891 @@ -1093,28 +1113,61 @@ static SMB_ACL_T gluster_to_smb_acl(const char *buf, size_t xattr_size)
1893 ((perm & GLUSTER_ACL_EXECUTE) ? SMB_ACL_EXECUTE : 0);
1903 +static int gluster_ace_cmp(const void *left, const void *right)
1906 + uint16_t tag_left, tag_right;
1907 + uint32_t id_left, id_right;
1910 + Sorting precedence:
1912 + - Smaller TAG values must be earlier.
1914 + - Within same TAG, smaller identifiers must be earlier, E.g:
1915 + UID 0 entry must be earlier than UID 200
1916 + GID 17 entry must be earlier than GID 19
1919 + /* TAG is the first element in the entry */
1920 + tag_left = SVAL(left, 0);
1921 + tag_right = SVAL(right, 0);
1923 + ret = (tag_left - tag_right);
1925 + /* ID is the third element in the entry, after two short
1926 + integers (tag and perm), i.e at offset 4.
1928 + id_left = IVAL(left, 4);
1929 + id_right = IVAL(right, 4);
1930 + ret = id_left - id_right;
1937 static ssize_t smb_to_gluster_acl(SMB_ACL_T theacl, char *buf, size_t len)
1940 - struct gluster_ace *ace;
1941 struct smb_acl_entry *smb_ace;
1942 - struct gluster_acl_header *hdr;
1950 count = theacl->count;
1952 - size = sizeof(*hdr) + (count * sizeof(*ace));
1953 + size = GLUSTER_ACL_HEADER_SIZE + (count * GLUSTER_ACL_ENTRY_SIZE);
1957 @@ -1124,13 +1177,14 @@ static ssize_t smb_to_gluster_acl(SMB_ACL_T theacl, char *buf, size_t len)
1961 - hdr = (void *)buf;
1962 - ace = hdr->entries;
1963 smb_ace = theacl->acl;
1965 - hdr->version = htonl(GLUSTER_ACL_VERSION);
1966 + /* Version is the first 4 bytes of the ACL */
1967 + SIVAL(buf, 0, GLUSTER_ACL_VERSION);
1968 + offset = GLUSTER_ACL_HEADER_SIZE;
1970 for (i = 0; i < count; i++) {
1971 + /* Calculate tag */
1972 switch(smb_ace->a_type) {
1974 tag = GLUSTER_ACL_USER;
1975 @@ -1157,8 +1211,8 @@ static ssize_t smb_to_gluster_acl(SMB_ACL_T theacl, char *buf, size_t len)
1979 - ace->tag = ntohs(tag);
1981 + /* Calculate id */
1982 switch(smb_ace->a_type) {
1985 @@ -1171,20 +1225,36 @@ static ssize_t smb_to_gluster_acl(SMB_ACL_T theacl, char *buf, size_t len)
1989 - ace->id = ntohl(id);
1990 + /* Calculate perm */
1996 ((smb_ace->a_perm & SMB_ACL_READ) ? GLUSTER_ACL_READ : 0);
1999 ((smb_ace->a_perm & SMB_ACL_WRITE) ? GLUSTER_ACL_WRITE : 0);
2002 ((smb_ace->a_perm & SMB_ACL_EXECUTE) ? GLUSTER_ACL_EXECUTE : 0);
2006 + /* TAG is the first 2 bytes of an entry */
2007 + SSVAL(buf, offset, tag);
2010 + /* PERM is the next 2 bytes of an entry */
2011 + SSVAL(buf, offset, perm);
2014 + /* ID is the last 4 bytes of an entry */
2015 + SIVAL(buf, offset, id);
2021 + /* Skip the header, sort @count number of 8-byte entries */
2022 + qsort(buf+GLUSTER_ACL_HEADER_SIZE, count, GLUSTER_ACL_ENTRY_SIZE,
2032 From 26673935299da8ce830ff9d0ea5df18f52092092 Mon Sep 17 00:00:00 2001
2033 From: "Christopher R. Hertel" <crh@redhat.com>
2034 Date: Thu, 29 Aug 2013 11:01:24 -0500
2035 Subject: [PATCH 5/9] PATCHSET13: vfs_glusterfs: Fix excessive debug output
2036 from vfs_gluster_open().
2038 The vfs_gluster_open() function generates a debug message (at level 0)
2039 for every failed attempt to open a pathname. This includes cases in
2040 which attempts are made to open a directory as a file (those attempts
2041 are retried calling vfs_gluster_opendir()). The result is that the log
2042 file fills with messages about failed attempts to open directories,
2043 because they are directories. This patch ensures that failed attempts
2044 to open directories as files are logged at log level 4, not 0. In
2045 addition, other failed open attempts are logged at level 1, not 0.
2047 Signed-off-by: Christopher R. Hertel <crh@redhat.com>
2048 Reviewed-by : Susant Palai <spalai@redhat.com>
2049 Reviewed-by : Raghavendra Talur <rtalur@redhat.com>
2050 Reviewed-by : Jose A. Rivera <jarrpa@redhat.com>
2052 source3/modules/vfs_glusterfs.c | 3 ---
2053 1 file changed, 3 deletions(-)
2055 diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c
2056 index 1b81d06..b92c7fd 100644
2057 --- a/source3/modules/vfs_glusterfs.c
2058 +++ b/source3/modules/vfs_glusterfs.c
2059 @@ -488,11 +488,8 @@ static int vfs_gluster_open(struct vfs_handle_struct *handle,
2063 - DEBUG(0, ("glfs_{open[dir],creat}(%s) failed: %s\n",
2064 - smb_fname->base_name, strerror(errno)));
2068 return glfd_fd_store(glfd);
2075 From f396be725dd8e8f93b0eed1b23fcf0a0f61303a9 Mon Sep 17 00:00:00 2001
2076 From: Andreas Schneider <asn@samba.org>
2077 Date: Mon, 4 Nov 2013 12:32:05 +0100
2078 Subject: [PATCH 6/9] PATCHSET13: vfs: Fix some build warnings in glusterfs.
2080 Signed-off-by: Andreas Schneider <asn@samba.org>
2081 Reviewed-by: David Disseldorp <ddiss@samba.org>
2083 source3/modules/vfs_glusterfs.c | 4 ++--
2084 1 file changed, 2 insertions(+), 2 deletions(-)
2086 diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c
2087 index b92c7fd..4b8da4a 100644
2088 --- a/source3/modules/vfs_glusterfs.c
2089 +++ b/source3/modules/vfs_glusterfs.c
2090 @@ -1262,7 +1262,7 @@ static SMB_ACL_T vfs_gluster_sys_acl_get_file(struct vfs_handle_struct *handle,
2092 struct smb_acl_t *result;
2099 @@ -1324,7 +1324,7 @@ static int vfs_gluster_sys_acl_set_file(struct vfs_handle_struct *handle,
2112 From 2b136f8999e171d15736d0a532353799b7251ae2 Mon Sep 17 00:00:00 2001
2113 From: Andreas Schneider <asn@samba.org>
2114 Date: Fri, 15 Nov 2013 17:02:19 +0100
2115 Subject: [PATCH 7/9] PATCHSET13: s3-vfs: Make glfs_set_preopened() static.
2117 Signed-off-by: Andreas Schneider <asn@samba.org>
2118 Reviewed-by: Jeremy Allison <jra@samba.org>
2120 source3/modules/vfs_glusterfs.c | 2 +-
2121 1 file changed, 1 insertion(+), 1 deletion(-)
2123 diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c
2124 index 4b8da4a..ef505a3 100644
2125 --- a/source3/modules/vfs_glusterfs.c
2126 +++ b/source3/modules/vfs_glusterfs.c
2127 @@ -141,7 +141,7 @@ static struct glfs_preopened {
2131 -int glfs_set_preopened(const char *volume, glfs_t *fs)
2132 +static int glfs_set_preopened(const char *volume, glfs_t *fs)
2134 struct glfs_preopened *entry = NULL;
2140 From 9b2c8854a5a27e4fdbe5191abf174d3152b0edfd Mon Sep 17 00:00:00 2001
2141 From: Poornima Gurusiddaiah <pgurusid@redhat.com>
2142 Date: Sun, 24 Nov 2013 21:37:53 +0000
2143 Subject: [PATCH 8/9] PATCHSET13: vfs_glusterfs: Enable per client log file
2145 In Samba configuration file, one of the options of gluster type is
2146 log file, the value of this option was not allowed to contain any
2147 variables, as a result all the clients would have a single log file,
2148 which complicated debugging.
2149 In this patch, variable substitution is performed for gluster log file.
2150 Hence allowing user to customise the gluster log file name.
2152 Signed-off-by: Poornima Gurusiddaiah <pgurusid@redhat.com>
2153 Reviewed-by: Ira Cooper <ira@samba.org>
2155 source3/modules/vfs_glusterfs.c | 41 ++++++++++++++++++++++-------------------
2156 1 file changed, 22 insertions(+), 19 deletions(-)
2158 diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c
2159 index ef505a3..3757968 100644
2160 --- a/source3/modules/vfs_glusterfs.c
2161 +++ b/source3/modules/vfs_glusterfs.c
2162 @@ -205,12 +205,12 @@ static int vfs_gluster_connect(struct vfs_handle_struct *handle,
2164 const char *volfile_server;
2166 - const char *logfile;
2173 - logfile = lp_parm_const_string(SNUM(handle->conn), "glusterfs",
2174 + logfile = lp_parm_talloc_string(SNUM(handle->conn), "glusterfs",
2177 loglevel = lp_parm_int(SNUM(handle->conn), "glusterfs", "loglevel", -1);
2178 @@ -229,57 +229,60 @@ static int vfs_gluster_connect(struct vfs_handle_struct *handle,
2180 fs = glfs_find_preopened(volume);
2186 fs = glfs_new(volume);
2193 ret = glfs_set_volfile_server(fs, "tcp", volfile_server, 0);
2195 DEBUG(0, ("Failed to set volfile_server %s\n", volfile_server));
2201 ret = glfs_set_xlator_option(fs, "*-md-cache", "cache-posix-acl",
2204 DEBUG(0, ("%s: Failed to set xlator options\n", volume));
2210 ret = glfs_set_logging(fs, logfile, loglevel);
2212 DEBUG(0, ("%s: Failed to set logfile %s loglevel %d\n",
2213 volume, logfile, loglevel));
2219 ret = glfs_init(fs);
2221 DEBUG(0, ("%s: Failed to initialize volume (%s)\n",
2222 volume, strerror(errno)));
2228 ret = glfs_set_preopened(volume, fs);
2230 DEBUG(0, ("%s: Failed to register volume (%s)\n",
2231 volume, strerror(errno)));
2236 + talloc_free(logfile);
2242 + DEBUG(0, ("%s: Initialized volume from server %s\n",
2243 + volume, volfile_server));
2244 + handle->data = fs;
2248 - DEBUG(0, ("%s: Initialized volume from server %s\n",
2249 - volume, volfile_server));
2250 - handle->data = fs;
2254 static void vfs_gluster_disconnect(struct vfs_handle_struct *handle)
2259 From 8577c573dcd44e26579a6594b83a6d582faef14c Mon Sep 17 00:00:00 2001
2260 From: Niels de Vos <ndevos@redhat.com>
2261 Date: Fri, 10 Jan 2014 16:26:18 +0100
2262 Subject: [PATCH 9/9] PATCHSET13: vfs/glusterfs: in case atime is not passed,
2263 set it to the current atime
2265 The Linux CIFS client does not pass an updated atime when a write() is
2266 done. This causes the vfs/glusterfs module to set the atime to -1 on the
2267 Gluster backend, resulting in an atime far in the future (year 2106).
2269 Signed-off-by: Niels de Vos <ndevos@redhat.com>
2270 Reviewed-by: Ira Cooper <ira@samba.org>
2271 Reviewed-by: Jeremy Allison <jra@samba.org>
2273 Autobuild-User(master): Jeremy Allison <jra@samba.org>
2274 Autobuild-Date(master): Wed Jan 15 21:31:30 CET 2014 on sn-devel-104
2276 source3/modules/vfs_glusterfs.c | 26 ++++++++++++++++++++++----
2277 1 file changed, 22 insertions(+), 4 deletions(-)
2279 diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c
2280 index 3757968..24f80dd 100644
2281 --- a/source3/modules/vfs_glusterfs.c
2282 +++ b/source3/modules/vfs_glusterfs.c
2283 @@ -675,10 +675,28 @@ static int vfs_gluster_ntimes(struct vfs_handle_struct *handle,
2285 struct timespec times[2];
2287 - times[0].tv_sec = ft->atime.tv_sec;
2288 - times[0].tv_nsec = ft->atime.tv_nsec;
2289 - times[1].tv_sec = ft->mtime.tv_sec;
2290 - times[1].tv_nsec = ft->mtime.tv_nsec;
2291 + if (null_timespec(ft->atime)) {
2292 + times[0].tv_sec = smb_fname->st.st_ex_atime.tv_sec;
2293 + times[0].tv_nsec = smb_fname->st.st_ex_atime.tv_nsec;
2295 + times[0].tv_sec = ft->atime.tv_sec;
2296 + times[0].tv_nsec = ft->atime.tv_nsec;
2299 + if (null_timespec(ft->mtime)) {
2300 + times[1].tv_sec = smb_fname->st.st_ex_mtime.tv_sec;
2301 + times[1].tv_nsec = smb_fname->st.st_ex_mtime.tv_nsec;
2303 + times[1].tv_sec = ft->mtime.tv_sec;
2304 + times[1].tv_nsec = ft->mtime.tv_nsec;
2307 + if ((timespec_compare(×[0],
2308 + &smb_fname->st.st_ex_atime) == 0) &&
2309 + (timespec_compare(×[1],
2310 + &smb_fname->st.st_ex_mtime) == 0)) {
2314 return glfs_utimens(handle->data, smb_fname->base_name, times);