The branch, v4-1-test has been updated via 43fbaf6 vfs_glusterfs: Remove "integer fd" code and store the glfs pointers. via ad4629b vfs_glusterfs: smb_stat_ex_from_stat commenting and cleanup. via 6a2496a vfs_glusterfs: Comment the top of the file. via 1883e25 nss_winbind: add getgroupmembership for FreeBSD from 0548c9e VERSION: Bump version up to 4.1.14...
https://git.samba.org/?p=samba.git;a=shortlog;h=v4-1-test - Log ----------------------------------------------------------------- commit 43fbaf6348d5dc882c30edfa142586ddbbe3ffd5 Author: Jose A. Rivera <jar...@redhat.com> Date: Thu Dec 12 16:06:36 2013 -0600 vfs_glusterfs: Remove "integer fd" code and store the glfs pointers. Change-Id: I74347199e54be0d1dc031985534da1e56fd3e280 Signed-off-by: Jose A. Rivera <jar...@redhat.com> Reviewed-by: Christopher R. Hertel <c...@samba.org> Reviewed-by: Ira Cooper <i...@samba.org> The last 3 patches address bug #10889 (Backport remaining vfs_glusterfs patches in master/4.2 to 4.1). Autobuild-User(v4-1-test): Karolin Seeger <ksee...@samba.org> Autobuild-Date(v4-1-test): Sun Oct 26 23:51:26 CET 2014 on sn-devel-104 commit ad4629bbe95f25b3fb7f6c1fbbe96fd2b8d53f1c Author: Christopher R. Hertel <c...@samba.org> Date: Thu Dec 12 12:29:20 2013 -0600 vfs_glusterfs: smb_stat_ex_from_stat commenting and cleanup. Change-Id: If1b54e62b4fc2240aa17e5d1eae8f279f2fdfc42 Signed-off-by: Christopher R. Hertel <c...@samba.org> Reviewed-by: Jose A. Rivera <jar...@redhat.com> Reviewed-by: Ira Cooper <i...@samba.org> commit 6a2496a1c6d2c2a8e79085c740000d6fd0d02a3a Author: Christopher R. Hertel <c...@samba.org> Date: Thu Dec 12 12:27:10 2013 -0600 vfs_glusterfs: Comment the top of the file. Change-Id: I98b512da2e0e56f061247a7c48ce576287b43827 Signed-off-by: Christopher R. Hertel <c...@samba.org> Reviewed-by: Jose A. Rivera <jar...@redhat.com> Reviewed-by: Ira Cooper <i...@samba.org> commit 1883e25c243ab093bf392ba26566ea620ff588e9 Author: Björn Jacke <b...@sernet.de> Date: Sun Oct 19 15:48:45 2014 +0200 nss_winbind: add getgroupmembership for FreeBSD The getgroupmembership call on FreeBSD is needed for "winbind expand groups=0" (the new default in 4.2) to work. Thanks to Timur I. Bakeyev for the enhancement patch. BUG: https://bugzilla.samba.org/show_bug.cgi?id=10835 Signed-off-by: Bjoern Jacke <b...@sernet.de> Reviewed-by: Volker Lendecke <v...@samba.org> (cherry picked from commit 8ccf5f66691e2bbf0883afa658282ef2ac60b015) ----------------------------------------------------------------------- Summary of changes: nsswitch/winbind_nss_freebsd.c | 74 +++++++++++++++++- source3/modules/vfs_glusterfs.c | 169 +++++++++++++------------------------- 2 files changed, 131 insertions(+), 112 deletions(-) Changeset truncated at 500 lines: diff --git a/nsswitch/winbind_nss_freebsd.c b/nsswitch/winbind_nss_freebsd.c index 5fcd557..476349f 100644 --- a/nsswitch/winbind_nss_freebsd.c +++ b/nsswitch/winbind_nss_freebsd.c @@ -5,6 +5,7 @@ routines against Samba winbind/Windows NT Domain Copyright (C) Aaron Collins 2003 + Copyright (C) Timur I. Bakeyev 2013 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -23,7 +24,6 @@ #include "winbind_client.h" /* Make sure that the module gets registered needed by freebsd 5.1 */ - extern enum nss_status _nss_winbind_getgrent_r(struct group *, char *, size_t, int *); extern enum nss_status _nss_winbind_getgrnam_r(const char *, struct group *, @@ -32,6 +32,8 @@ extern enum nss_status _nss_winbind_getgrgid_r(gid_t gid, struct group *, char * size_t, int *); extern enum nss_status _nss_winbind_setgrent(void); extern enum nss_status _nss_winbind_endgrent(void); +extern enum nss_status _nss_winbind_initgroups_dyn(char *, gid_t, long int *, + long int *, gid_t **, long int , int *); extern enum nss_status _nss_winbind_getpwent_r(struct passwd *, char *, size_t, int *); @@ -41,6 +43,7 @@ extern enum nss_status _nss_winbind_getpwuid_r(gid_t gid, struct passwd *, char size_t, int *); extern enum nss_status _nss_winbind_setpwent(void); extern enum nss_status _nss_winbind_endpwent(void); +ns_mtab *nss_module_register(const char *, unsigned int *, nss_module_unregister_fn *); NSS_METHOD_PROTOTYPE(__nss_compat_getgrnam_r); NSS_METHOD_PROTOTYPE(__nss_compat_getgrgid_r); @@ -53,6 +56,9 @@ NSS_METHOD_PROTOTYPE(__nss_compat_getpwuid_r); NSS_METHOD_PROTOTYPE(__nss_compat_getpwent_r); NSS_METHOD_PROTOTYPE(__nss_compat_setpwent); NSS_METHOD_PROTOTYPE(__nss_compat_endpwent); +NSS_METHOD_PROTOTYPE(__nss_compat_endpwent); + +NSS_METHOD_PROTOTYPE(__freebsd_getgroupmembership); static ns_mtab methods[] = { { NSDB_GROUP, "getgrnam_r", __nss_compat_getgrnam_r, _nss_winbind_getgrnam_r }, @@ -60,6 +66,7 @@ static ns_mtab methods[] = { { NSDB_GROUP, "getgrent_r", __nss_compat_getgrent_r, _nss_winbind_getgrent_r }, { NSDB_GROUP, "setgrent", __nss_compat_setgrent, _nss_winbind_setgrent }, { NSDB_GROUP, "endgrent", __nss_compat_endgrent, _nss_winbind_endgrent }, +{ NSDB_GROUP, "getgroupmembership", __freebsd_getgroupmembership, NULL }, { NSDB_PASSWD, "getpwnam_r", __nss_compat_getpwnam_r, _nss_winbind_getpwnam_r }, { NSDB_PASSWD, "getpwuid_r", __nss_compat_getpwuid_r, _nss_winbind_getpwuid_r }, @@ -69,6 +76,71 @@ static ns_mtab methods[] = { }; +/* Taken from libc */ +static int +gr_addgid(gid_t gid, gid_t *groups, int maxgrp, int *grpcnt) +{ + int ret, dupc; + + /* skip duplicates */ + for (dupc = 0; dupc < MIN(maxgrp, *grpcnt); dupc++) { + if (groups[dupc] == gid) + return 1; + } + + ret = 1; + if (*grpcnt < maxgrp) /* add this gid */ + groups[*grpcnt] = gid; + else + ret = 0; + + (*grpcnt)++; + + return ret; +} + +/* + rv = _nsdispatch(NULL, dtab, NSDB_GROUP, "getgroupmembership", + defaultsrc, uname, agroup, groups, maxgrp, grpcnt); +*/ + +int +__freebsd_getgroupmembership(void *retval, void *mdata, va_list ap) +{ + const char *uname = va_arg(ap, const char *); + gid_t group = va_arg(ap, gid_t); + gid_t *groups = va_arg(ap, gid_t *); + int maxgrp = va_arg(ap, int); + int *groupc = va_arg(ap, int *); + + NSS_STATUS ret; + long int lcount, lsize; + int i, errnop; + gid_t *tmpgroups; + + /* Can be realloc() inside _nss_winbind_initgroups_dyn() */ + if ((tmpgroups=calloc(maxgrp, sizeof(gid_t))) == NULL) { + errno = ENOMEM; + return NS_TRYAGAIN; + } + + lcount = 0; + lsize = maxgrp; + /* insert primary membership(possibly already there) */ + gr_addgid(group, groups, maxgrp, groupc); + /* Don't limit number of groups, we want to know total size */ + ret = _nss_winbind_initgroups_dyn(uname, group, &lcount, &lsize, + &tmpgroups, 0, &errnop); + if (ret == NSS_STATUS_SUCCESS) { + /* lcount potentially can be bigger than maxgrp, so would groupc */ + for (i = 0; i < lcount; i++) + gr_addgid(tmpgroups[i], groups, maxgrp, groupc); + } + free(tmpgroups); + /* Let following nsswitch backend(s) add more groups(?) */ + return NSS_STATUS_NOTFOUND; +} + ns_mtab * nss_module_register(const char *source, unsigned int *mtabsize, nss_module_unregister_fn *unreg) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index 9bcd0cb..ba2d8e8 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -19,6 +19,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/** + * @file vfs_glusterfs.c + * @author Anand Avati <av...@redhat.com> + * @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 <stdio.h> @@ -27,82 +45,9 @@ #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 - 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 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); @@ -116,23 +61,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 */ @@ -407,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) @@ -479,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); @@ -492,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 @@ -533,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 @@ -563,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, @@ -594,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 @@ -635,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); } @@ -685,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, @@ -697,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, @@ -763,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, @@ -794,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 */ @@ -841,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; @@ -949,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, @@ -962,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, @@ -974,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, @@ -988,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); } @@ -1365,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; } @@ -1435,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; } -- Samba Shared Repository