diff options
| author | Amar Tumballi <amarts@redhat.com> | 2012-07-11 22:25:30 +0530 | 
|---|---|---|
| committer | Anand Avati <avati@redhat.com> | 2012-07-11 16:29:58 -0700 | 
| commit | ea08bf886732d9680f2d6de19f3d68908a55143b (patch) | |
| tree | e7531a52b1ece148ad049e3d150e1dbe3c00a41f | |
| parent | cb60a046bbb24cc864aa007707c75bdadf2157e3 (diff) | |
core: remove unused code
BUG: 764890
Change-Id: Ia8bcaa7a4daeb706bcb0bba24b2e634e9ca20d49
Signed-off-by: Amar Tumballi <amarts@redhat.com>
Reviewed-on: http://review.gluster.com/3657
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
75 files changed, 0 insertions, 42027 deletions
diff --git a/booster/Makefile.am b/booster/Makefile.am deleted file mode 100644 index e1c45f3051c..00000000000 --- a/booster/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS=src
\ No newline at end of file diff --git a/booster/src/Makefile.am b/booster/src/Makefile.am deleted file mode 100644 index d7d83abf5ee..00000000000 --- a/booster/src/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ -ldpreload_LTLIBRARIES = libglusterfs-booster.la -ldpreloaddir = $(libdir)/glusterfs -noinst_HEADERS = booster_fstab.h booster-fd.h -libglusterfs_booster_la_SOURCES = booster.c booster_stat.c booster_fstab.c booster-fd.c -libglusterfs_booster_la_CFLAGS = -I$(top_srcdir)/libglusterfsclient/src/ -D_GNU_SOURCE -D$(GF_HOST_OS) -fPIC -Wall \ -	-pthread $(GF_BOOSTER_CFLAGS) -shared -nostartfiles  -libglusterfs_booster_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE  \ -	-I$(top_srcdir)/libglusterfsclient/src \ -	-I$(top_srcdir)/libglusterfs/src -DDATADIR=\"$(localstatedir)\" \ -	-DCONFDIR=\"$(sysconfdir)/glusterfs\" $(ARGP_STANDALONE_CPPFLAGS) - -libglusterfs_booster_la_LDFLAGS = -module -avoidversion -libglusterfs_booster_la_LIBADD =  $(top_builddir)/libglusterfs/src/libglusterfs.la $(top_builddir)/libglusterfsclient/src/libglusterfsclient.la - -CLEANFILES = - -uninstall-local: -	rm -f $(DESTDIR)$(ldpreloaddir)/glusterfs-booster.so - -install-data-hook: -	ln -sf libglusterfs-booster.so $(DESTDIR)$(ldpreloaddir)/glusterfs-booster.so diff --git a/booster/src/booster-fd.c b/booster/src/booster-fd.c deleted file mode 100644 index fa5b0cde2d3..00000000000 --- a/booster/src/booster-fd.c +++ /dev/null @@ -1,342 +0,0 @@ -/* -  Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - - - -#include "booster-fd.h" -#include <logging.h> -#include <mem-pool.h> -#include <stdlib.h> -#include <errno.h> -#include <common-utils.h> -#include <string.h> - -#include <assert.h> - -extern fd_t * -fd_ref (fd_t *fd); - -extern void -fd_unref (fd_t *fd); -/* -   Allocate in memory chunks of power of 2 starting from 1024B -   Assumes fdtable->lock is held -   */ -static inline uint -gf_roundup_power_of_two (uint nr) -{ -        uint result = 1; - -        if (nr < 0) { -                gf_log ("booster-fd", GF_LOG_ERROR, "Negative number passed"); -                return -1; -        } -         -        while (result <= nr) -                result *= 2; - -        return result; -} - -#define BOOSTER_NFDBITS (sizeof (unsigned long)) - -#define BOOSTER_FDMASK(d)             (1UL << ((d) % BOOSTER_NFDBITS)) -#define BOOSTER_FDELT(d)              (d / BOOSTER_NFDBITS) -#define BOOSTER_FD_SET(set, d)        (set->fd_bits[BOOSTER_FDELT(d)] |= BOOSTER_FDMASK(d)) -#define BOOSTER_FD_CLR(set, d)        (set->fd_bits[BOOSTER_FDELT(d)] &= ~BOOSTER_FDMASK(d)) -#define BOOSTER_FD_ISSET(set, d)      (set->fd_bits[BOOSTER_FDELT(d)] & BOOSTER_FDMASK(d)) - -inline int -booster_get_close_on_exec (booster_fdtable_t *fdtable, int fd) -{ -        return BOOSTER_FD_ISSET(fdtable->close_on_exec, fd); -} - -inline void -booster_set_close_on_exec (booster_fdtable_t *fdtable, int fd) -{ -        BOOSTER_FD_SET(fdtable->close_on_exec, fd); -} - -int -booster_fdtable_expand (booster_fdtable_t *fdtable, uint nr) -{ -        fd_t    **oldfds = NULL, **tmp = NULL; -        uint    oldmax_fds = -1; -        uint    cpy = 0; -        int32_t ret = -1, bytes = 0; -        booster_fd_set_t *oldclose_on_exec = NULL; - -        if (fdtable == NULL || nr < 0) { -                gf_log ("booster-fd", GF_LOG_ERROR, "Invalid argument"); -                errno = EINVAL; -                ret = -1; -                goto out; -        } - -        nr /= (1024 / sizeof (fd_t *)); -        nr = gf_roundup_power_of_two (nr + 1); -        nr *= (1024 / sizeof (fd_t *)); - -        oldfds = fdtable->fds; -        oldmax_fds = fdtable->max_fds; -        oldclose_on_exec = fdtable->close_on_exec; - -        fdtable->fds = CALLOC (nr, sizeof (fd_t *)); -        if (fdtable->fds == NULL) { -                gf_log ("booster-fd", GF_LOG_ERROR, "Memory allocation failed"); -                fdtable->fds = oldfds; -                oldfds = NULL; -                ret = -1; -                goto out; -        } - -        fdtable->max_fds = nr; - -        if (oldfds) { -                cpy = oldmax_fds * sizeof (fd_t *); -                memcpy (fdtable->fds, oldfds, cpy); -        } - -        /* nr will be either less than 8 or a multiple of 8 */ -        bytes = nr/8; -        bytes = bytes ? bytes : 1; -        fdtable->close_on_exec = CALLOC (bytes, 1); -        if (fdtable->close_on_exec == NULL) { -                gf_log ("booster-fd", GF_LOG_ERROR, "Memory allocation " -                        "failed"); -                tmp = fdtable->fds; -                fdtable->fds = oldfds; -                oldfds = tmp; -                ret = -1; -                goto out; -        } - -        if (oldclose_on_exec != NULL) { -                bytes = oldmax_fds/8; -                cpy = bytes ? bytes : 1; -                memcpy (fdtable->close_on_exec, oldclose_on_exec, cpy); -        } -        gf_log ("booster-fd", GF_LOG_TRACE, "FD-table expanded: Old: %d,New: %d" -                , oldmax_fds, nr); -        ret = 0; - -out: -        FREE (oldfds); -        FREE (oldclose_on_exec); - -        return ret; -} - -booster_fdtable_t * -booster_fdtable_alloc (void) -{ -        booster_fdtable_t *fdtable = NULL; -        int32_t            ret = -1; - -        fdtable = CALLOC (1, sizeof (*fdtable)); -        GF_VALIDATE_OR_GOTO ("booster-fd", fdtable, out); - -        LOCK_INIT (&fdtable->lock); - -        LOCK (&fdtable->lock); -        { -                ret = booster_fdtable_expand (fdtable, 0); -        } -        UNLOCK (&fdtable->lock); - -        if (ret == -1) { -                gf_log ("booster-fd", GF_LOG_ERROR, "FD-table allocation " -                        "failed"); -                FREE (fdtable); -                fdtable = NULL; -        } - -out: -        return fdtable; -} - -fd_t ** -__booster_fdtable_get_all_fds (booster_fdtable_t *fdtable, uint *count) -{ -        fd_t **fds = NULL; - -        if (count == NULL) -                goto out; - -        fds = fdtable->fds; -        fdtable->fds = calloc (fdtable->max_fds, sizeof (fd_t *)); -        *count = fdtable->max_fds; - -out: -        return fds; -} - -fd_t ** -booster_fdtable_get_all_fds (booster_fdtable_t *fdtable, uint *count) -{ -        fd_t **fds = NULL; -        if (!fdtable) -                return NULL; - -        LOCK (&fdtable->lock); -        { -                fds = __booster_fdtable_get_all_fds (fdtable, count); -        } -        UNLOCK (&fdtable->lock); - -        return fds; -} - -void -booster_fdtable_destroy (booster_fdtable_t *fdtable) -{ -        fd_t                    *fd = NULL; -        fd_t                    **fds = NULL; -        uint                    fd_count = 0; -        int                     i = 0; - -        if (!fdtable) -                return; - -        LOCK (&fdtable->lock); -        { -                fds = __booster_fdtable_get_all_fds (fdtable, &fd_count); -                FREE (fdtable->fds); -        } -        UNLOCK (&fdtable->lock); - -        if (!fds) -                goto free_table; -         -        for (i = 0; i < fd_count; i++) { -                fd = fds[i]; -                if (fd != NULL) -                        fd_unref (fd); -        } -        FREE (fds); -free_table: -        LOCK_DESTROY (&fdtable->lock); -        FREE (fdtable); -} - -int -booster_fd_unused_get (booster_fdtable_t *fdtable, fd_t *fdptr, int fd) -{ -        int ret = -1; -        int error = 0; - -        if (fdtable == NULL || fdptr == NULL || fd < 0) { -                gf_log ("booster-fd", GF_LOG_ERROR, "invalid argument"); -                errno = EINVAL; -                return -1; -        } - -        gf_log ("booster-fd", GF_LOG_TRACE, "Requested fd: %d", fd); -        LOCK (&fdtable->lock); -        { -                while (fdtable->max_fds < fd) { -                        error = 0; -                        error = booster_fdtable_expand (fdtable, -                                                        fdtable->max_fds + 1); -                        if (error) { -                                gf_log ("booster-fd", GF_LOG_ERROR, -                                        "Cannot expand fdtable:%s", -                                        strerror (error)); -                                goto err; -                        } -                } - -                if (!fdtable->fds[fd]) { -                        fdtable->fds[fd] = fdptr; -                        fd_ref (fdptr); -                        ret = fd; -                } else -                        gf_log ("booster-fd", GF_LOG_ERROR, "Cannot allocate fd" -                                " %d (slot not empty in fdtable)", fd); -        } -err: -        UNLOCK (&fdtable->lock); - -        return ret; -} - -void -booster_fd_put (booster_fdtable_t *fdtable, int fd) -{ -        fd_t *fdptr = NULL; -        if (fdtable == NULL || fd < 0) { -                gf_log ("booster-fd", GF_LOG_ERROR, "invalid argument"); -                return; -        } - -        gf_log ("booster-fd", GF_LOG_TRACE, "FD put: %d", fd); -        if (!(fd < fdtable->max_fds)) { -                gf_log ("booster-fd", GF_LOG_ERROR, "FD not in booster fd" -                        " table"); -                return; -        } - -        LOCK (&fdtable->lock); -        { -                fdptr = fdtable->fds[fd]; -                fdtable->fds[fd] = NULL; -        } -        UNLOCK (&fdtable->lock); - -        if (fdptr) -                fd_unref (fdptr); -} - -fd_t * -booster_fdptr_get (booster_fdtable_t *fdtable, int fd) -{ -        fd_t *fdptr = NULL; - -        if (fdtable == NULL || fd < 0) { -                gf_log ("booster-fd", GF_LOG_ERROR, "invalid argument"); -                errno = EINVAL; -                return NULL; -        } - -        gf_log ("booster-fd", GF_LOG_TRACE, "FD ptr request: %d", fd); -        if (!(fd < fdtable->max_fds)) { -                gf_log ("booster-fd", GF_LOG_ERROR, "FD not in booster fd" -                        " table"); -                errno = EINVAL; -                return NULL; -        } - -        LOCK (&fdtable->lock); -        { -                fdptr = fdtable->fds[fd]; -                if (fdptr) -                        fd_ref (fdptr); -        } -        UNLOCK (&fdtable->lock); - -        return fdptr; -} - -void -booster_fdptr_put (fd_t *booster_fd) -{ -        if (booster_fd) -                fd_unref (booster_fd); -} diff --git a/booster/src/booster-fd.h b/booster/src/booster-fd.h deleted file mode 100644 index 595a112bd8d..00000000000 --- a/booster/src/booster-fd.h +++ /dev/null @@ -1,83 +0,0 @@ -/* -  Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _BOOSTER_FD_H -#define _BOOSTER_FD_H - -#include <libglusterfsclient.h> -#include <locking.h> -#include <list.h> - -/* This struct must be updated if the fd_t in fd.h changes. - * We cannot include those headers here because unistd.h, included - * by glusterfs headers, conflicts with the syscall prototypes we - * define for booster. - */ -struct _fd { -        pid_t             pid; -	int32_t           flags; -        int32_t           refcount; -        struct list_head  inode_list; -        struct _inode    *inode; -        struct _dict     *ctx; -        gf_lock_t         lock; /* used ONLY for manipulating -                                   'struct _fd_ctx' array (_ctx).*/ -	struct _fd_ctx   *_ctx; -}; -typedef struct _fd fd_t; - -struct _booster_fd_set { -        unsigned long fd_bits[0]; -}; -typedef struct _booster_fd_set booster_fd_set_t; - -struct _booster_fdtable { -        booster_fd_set_t *close_on_exec; -        int               refcount; -        unsigned int      max_fds; -        gf_lock_t         lock; -        fd_t            **fds; -}; -typedef struct _booster_fdtable booster_fdtable_t; - -void -booster_set_close_on_exec (booster_fdtable_t *fdtable, int fd); - -int -booster_get_close_on_exec (booster_fdtable_t *fdtable, int fd); - -extern int -booster_fd_unused_get (booster_fdtable_t *fdtable, fd_t *fdptr, int fd); - -extern void -booster_fd_put (booster_fdtable_t *fdtable, int fd); - -extern fd_t * -booster_fdptr_get (booster_fdtable_t *fdtable, int fd); - -extern void -booster_fdptr_put (fd_t *fdptr); - -extern void -booster_fdtable_destroy (booster_fdtable_t *fdtable); - -booster_fdtable_t * -booster_fdtable_alloc (void); - -#endif /* #ifndef _BOOSTER_FD_H */ diff --git a/booster/src/booster.c b/booster/src/booster.c deleted file mode 100644 index c34ec114645..00000000000 --- a/booster/src/booster.c +++ /dev/null @@ -1,3172 +0,0 @@ -/* -   Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> -   This file is part of GlusterFS. - -   GlusterFS is free software; you can redistribute it and/or modify -   it under the terms of the GNU General Public License as published -   by the Free Software Foundation; either version 3 of the License, -   or (at your option) any later version. - -   GlusterFS is distributed in the hope that it will be useful, but -   WITHOUT ANY WARRANTY; without even the implied warranty of -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -   General Public License for more details. - -   You should have received a copy of the GNU General Public License -   along with this program.  If not, see -   <http://www.gnu.org/licenses/>. -*/ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include <dlfcn.h> -#include <sys/types.h> -#include <sys/uio.h> -#include <stdio.h> -#include <stdarg.h> -#include <stdlib.h> -#include <inttypes.h> -#include <libglusterfsclient.h> -#include <list.h> -#include <pthread.h> -#include <sys/xattr.h> -#include <string.h> -#include <assert.h> -#include <errno.h> -#include <ctype.h> -#include <logging.h> -#include <utime.h> -#include <dirent.h> -#include <sys/statfs.h> -#include <sys/statvfs.h> -#include <fcntl.h> -#include "booster-fd.h" - -#ifndef GF_UNIT_KB -#define GF_UNIT_KB 1024 -#endif - -static pthread_mutex_t cwdlock   = PTHREAD_MUTEX_INITIALIZER; - -/* attr constructor registers this function with libc's - * _init function as a function that must be called before - * the main() of the program. - */ -static void booster_lib_init (void) __attribute__((constructor)); - -extern fd_t * -fd_ref (fd_t *fd); - -extern void -fd_unref (fd_t *fd); - -extern int pipe (int filedes[2]); -/* We define these flags so that we can remove fcntl.h from the include path. - * fcntl.h has certain defines and other lines of code that redirect the - * application's open and open64 calls to the syscalls defined by - * libc, for us, thats not a Good Thing (TM). - */ -#ifndef GF_O_CREAT -#define GF_O_CREAT      0x40 -#endif - -#ifndef GF_O_TRUNC -#define GF_O_TRUNC      0x200 -#endif - -#ifndef GF_O_RDWR -#define GF_O_RDWR       0x2 -#endif - -#ifndef GF_O_WRONLY -#define GF_O_WRONLY     0x1 -#endif - -#ifndef UNIX_PATH_MAX -#define UNIX_PATH_MAX 108 -#endif - -typedef enum { -        BOOSTER_OPEN, -        BOOSTER_CREAT -} booster_op_t; - -struct _inode; -struct _dict; - -ssize_t -write (int fd, const void *buf, size_t count); - -/* open, open64, creat */ -static int (*real_open) (const char *pathname, int flags, ...); -static int (*real_open64) (const char *pathname, int flags, ...); -static int (*real_creat) (const char *pathname, mode_t mode); -static int (*real_creat64) (const char *pathname, mode_t mode); - -/* read, readv, pread, pread64 */ -static ssize_t (*real_read) (int fd, void *buf, size_t count); -static ssize_t (*real_readv) (int fd, const struct iovec *vector, int count); -static ssize_t (*real_pread) (int fd, void *buf, size_t count, -                              unsigned long offset); -static ssize_t (*real_pread64) (int fd, void *buf, size_t count, -                                uint64_t offset); - -/* write, writev, pwrite, pwrite64 */ -static ssize_t (*real_write) (int fd, const void *buf, size_t count); -static ssize_t (*real_writev) (int fd, const struct iovec *vector, int count); -static ssize_t (*real_pwrite) (int fd, const void *buf, size_t count, -                               unsigned long offset); -static ssize_t (*real_pwrite64) (int fd, const void *buf, size_t count, -                                 uint64_t offset); - -/* lseek, llseek, lseek64 */ -static off_t (*real_lseek) (int fildes, unsigned long offset, int whence); -static off_t (*real_lseek64) (int fildes, uint64_t offset, int whence); - -/* close */ -static int (*real_close) (int fd); - -/* dup dup2 */ -static int (*real_dup) (int fd); -static int (*real_dup2) (int oldfd, int newfd); - -static pid_t (*real_fork) (void); -static int (*real_mkdir) (const char *pathname, mode_t mode); -static int (*real_rmdir) (const char *pathname); -static int (*real_chmod) (const char *pathname, mode_t mode); -static int (*real_chown) (const char *pathname, uid_t owner, gid_t group); -static int (*real_fchmod) (int fd, mode_t mode); -static int (*real_fchown) (int fd, uid_t, gid_t gid); -static int (*real_fsync) (int fd); -static int (*real_ftruncate) (int fd, off_t length); -static int (*real_ftruncate64) (int fd, loff_t length); -static int (*real_link) (const char *oldpath, const char *newname); -static int (*real_rename) (const char *oldpath, const char *newpath); -static int (*real_utimes) (const char *path, const struct timeval times[2]); -static int (*real_utime) (const char *path, const struct utimbuf *buf); -static int (*real_mknod) (const char *path, mode_t mode, dev_t dev); -static int (*real_mkfifo) (const char *path, mode_t mode); -static int (*real_unlink) (const char *path); -static int (*real_symlink) (const char *oldpath, const char *newpath); -static int (*real_readlink) (const char *path, char *buf, size_t bufsize); -static char * (*real_realpath) (const char *path, char *resolved); -static DIR * (*real_opendir) (const char *path); -static struct dirent * (*real_readdir) (DIR *dir); -static struct dirent64 * (*real_readdir64) (DIR *dir); -static int (*real_readdir_r) (DIR *dir, struct dirent *entry, -                              struct dirent **result); -static int (*real_readdir64_r) (DIR *dir, struct dirent64 *entry, -                                struct dirent64 **result); -static int (*real_closedir) (DIR *dh); -static int (*real___xstat) (int ver, const char *path, struct stat *buf); -static int (*real___xstat64) (int ver, const char *path, struct stat64 *buf); -static int (*real_stat) (const char *path, struct stat *buf); -static int (*real_stat64) (const char *path, struct stat64 *buf); -static int (*real___fxstat) (int ver, int fd, struct stat *buf); -static int (*real___fxstat64) (int ver, int fd, struct stat64 *buf); -static int (*real_fstat) (int fd, struct stat *buf); -static int (*real_fstat64) (int fd , struct stat64 *buf); -static int (*real___lxstat) (int ver, const char *path, struct stat *buf); -static int (*real___lxstat64) (int ver, const char *path, struct stat64 *buf); -static int (*real_lstat) (const char *path, struct stat *buf); -static int (*real_lstat64) (const char *path, struct stat64 *buf); -static int (*real_statfs) (const char *path, struct statfs *buf); -static int (*real_statfs64) (const char *path, struct statfs64 *buf); -static int (*real_statvfs) (const char *path, struct statvfs *buf); -static int (*real_statvfs64) (const char *path, struct statvfs64 *buf); -static ssize_t (*real_getxattr) (const char *path, const char *name, -                                 void *value, size_t size); -static ssize_t (*real_lgetxattr) (const char *path, const char *name, -                                  void *value, size_t size); -static int (*real_remove) (const char* path); -static int (*real_lchown) (const char *path, uid_t owner, gid_t group); -static void (*real_rewinddir) (DIR *dirp); -static void (*real_seekdir) (DIR *dirp, off_t offset); -static off_t (*real_telldir) (DIR *dirp); - -static ssize_t (*real_sendfile) (int out_fd, int in_fd, off_t *offset, -                                 size_t count); -static ssize_t (*real_sendfile64) (int out_fd, int in_fd, off_t *offset, -                                   size_t count); -static int (*real_fcntl) (int fd, int cmd, ...); -static int (*real_chdir) (const char *path); -static int (*real_fchdir) (int fd);   -static char * (*real_getcwd) (char *buf, size_t size); -static int (*real_truncate) (const char *path, off_t length); -static int (*real_truncate64) (const char *path, loff_t length); -static int (*real_setxattr) (const char *path, const char *name, -                             const void *value, size_t size, int flags); -static int (*real_lsetxattr) (const char *path, const char *name, -                              const void *value, size_t size, int flags); -static int (*real_fsetxattr) (int filedes, const char *name, -                              const void *value, size_t size, int flags); - - -#define RESOLVE(sym) do {                                       \ -                if (!real_##sym)                                \ -                        real_##sym = dlsym (RTLD_NEXT, #sym);   \ -        } while (0) - -/*TODO: set proper value */ -#define MOUNT_HASH_SIZE 256 - -struct booster_mount { -        dev_t st_dev; -        glusterfs_handle_t handle; -        struct list_head device_list; -}; -typedef struct booster_mount booster_mount_t; - -static booster_fdtable_t *booster_fdtable = NULL; - -extern int booster_configure (char *confpath); -/* This is dup'ed every time VMP open/creat wants a new fd. - * This is needed so we occupy an entry in the process' file - * table. - */ -int process_piped_fd = -1; - -static int -booster_get_process_fd () -{ -        return real_dup (process_piped_fd); -} - -/* The following two define which file contains - * the FSTAB configuration for VMP-based usage. - */ -#define DEFAULT_BOOSTER_CONF    CONFDIR"/booster.conf" -#define BOOSTER_CONF_ENV_VAR    "GLUSTERFS_BOOSTER_FSTAB" - - -/* The following define which log file is used when - * using the old mount point bypass approach. - */ -#define BOOSTER_DEFAULT_LOG     CONFDIR"/booster.log" -#define BOOSTER_LOG_ENV_VAR     "GLUSTERFS_BOOSTER_LOG" - -void -do_open (int fd, const char *pathname, int flags, mode_t mode, booster_op_t op) -{ -        char                   *specfile = NULL; -        char                   *mount_point = NULL;  -        int32_t                 size = 0; -        int32_t                 ret = -1; -        FILE                   *specfp = NULL; -        glusterfs_file_t        fh = NULL; -        char                   *logfile = NULL; -        glusterfs_init_params_t iparams = { -                .loglevel = "error", -                .lookup_timeout = 600, -                .stat_timeout = 600, -        }; -       -        gf_log ("booster", GF_LOG_DEBUG, "Opening using MPB: %s", pathname); -        size = fgetxattr (fd, "user.glusterfs-booster-volfile", NULL, 0); -        if (size == -1) { -                gf_log ("booster", GF_LOG_ERROR, "Xattr " -                        "user.glusterfs-booster-volfile not found: %s", -                        strerror (errno)); -                goto out; -        } -		 -        specfile = calloc (1, size); -        if (!specfile) { -                gf_log ("booster", GF_LOG_ERROR, "Memory allocation failed"); -                goto out; -        } - -        ret = fgetxattr (fd, "user.glusterfs-booster-volfile", specfile, -                         size); -        if (ret == -1) { -                gf_log ("booster", GF_LOG_ERROR, "Xattr " -                        "user.glusterfs-booster-volfile not found: %s", -                        strerror (errno)); -                goto out; -        } -     -        specfp = tmpfile (); -        if (!specfp) { -                gf_log ("booster", GF_LOG_ERROR, "Temp file creation failed" -                        ": %s", strerror (errno)); -                goto out; -        } - -        ret = fwrite (specfile, size, 1, specfp); -        if (ret != 1) { -                gf_log ("booster", GF_LOG_ERROR, "Failed to write volfile: %s", -                        strerror (errno)); -                goto out; -        } -		 -        fseek (specfp, 0L, SEEK_SET); - -        size = fgetxattr (fd, "user.glusterfs-booster-mount", NULL, 0); -        if (size == -1) { -                gf_log ("booster", GF_LOG_ERROR, "Xattr " -                        "user.glusterfs-booster-mount not found: %s", -                        strerror (errno)); -                goto out; -        } -         -        mount_point = calloc (size, sizeof (char)); -        if (!mount_point) { -                gf_log ("booster", GF_LOG_ERROR, "Memory allocation failed"); -                goto out; -        } -	 -        ret = fgetxattr (fd, "user.glusterfs-booster-mount", mount_point, size); -        if (ret == -1) { -                gf_log ("booster", GF_LOG_ERROR, "Xattr " -                        "user.glusterfs-booster-mount not found: %s", -                        strerror (errno)); -                goto out; -        } - -        logfile = getenv (BOOSTER_LOG_ENV_VAR); -        if (logfile) { -                if (strlen (logfile) > 0) -                        iparams.logfile = strdup (logfile); -                else -                        iparams.logfile = strdup (BOOSTER_DEFAULT_LOG); -        } else { -                iparams.logfile = strdup (BOOSTER_DEFAULT_LOG); -        } - -        gf_log ("booster", GF_LOG_TRACE, "Using log-file: %s", iparams.logfile); -        iparams.specfp = specfp; - -        ret = glusterfs_mount (mount_point, &iparams); -        if (ret == -1) { -                if (errno != EEXIST) { -                        gf_log ("booster", GF_LOG_ERROR, "Mount failed over" -                                " glusterfs"); -                        goto out; -                } else -                        gf_log ("booster", GF_LOG_ERROR, "Already mounted"); -        } - -        switch (op) { -        case BOOSTER_OPEN: -                gf_log ("booster", GF_LOG_TRACE, "Booster open call"); -                fh = glusterfs_open (pathname, flags, mode); -                break; - -        case BOOSTER_CREAT: -                gf_log ("booster", GF_LOG_TRACE, "Booster create call"); -                fh = glusterfs_creat (pathname, mode); -                break; -        } - -        if (!fh) { -                gf_log ("booster", GF_LOG_ERROR, "Error performing operation"); -                goto out; -        } - -        if (booster_fd_unused_get (booster_fdtable, fh, fd) == -1) { -                gf_log ("booster", GF_LOG_ERROR, "Failed to get unused FD"); -                goto out; -        } -        fh = NULL; - -out: -        if (specfile) { -                free (specfile); -        } - -        if (specfp) { -                fclose (specfp); -        } - -        if (mount_point) { -                free (mount_point); -        } - -        if (fh) { -                glusterfs_close (fh); -        } - -        return; -} - -int -vmp_open (const char *pathname, int flags, ...) -{ -        mode_t                  mode = 0; -        int                     fd = -1; -        glusterfs_file_t        fh = NULL; -        va_list                 ap; - -        if (flags & GF_O_CREAT) { -                va_start (ap, flags); -                mode = va_arg (ap, mode_t); -                va_end (ap); - -                fh = glusterfs_open (pathname, flags, mode); -        } -        else -                fh = glusterfs_open (pathname, flags); - -        if (!fh) { -                gf_log ("booster", GF_LOG_ERROR, "VMP open failed"); -                goto out; -        } - -        fd = booster_get_process_fd (); -        if (fd == -1) { -                gf_log ("booster", GF_LOG_ERROR, "Failed to create open fd"); -                goto fh_close_out; -        } - -        if (booster_fd_unused_get (booster_fdtable, fh, fd) == -1) { -                gf_log ("booster", GF_LOG_ERROR, "Failed to map fd into table"); -                goto realfd_close_out; -        } - -        return fd; - -realfd_close_out: -        real_close (fd); -        fd = -1; - -fh_close_out: -        glusterfs_close (fh); - -out: -        return fd; -} - -#define BOOSTER_USE_OPEN64          1 -#define BOOSTER_DONT_USE_OPEN64     0 - -int -booster_open (const char *pathname, int use64, int flags, ...) -{ -        int     ret = -1; -        mode_t  mode = 0; -        va_list ap; -        int     (*my_open) (const char *pathname, int flags, ...); - -        if (!pathname) { -                errno = EINVAL; -                goto out; -        } - -        gf_log ("booster", GF_LOG_TRACE, "Open: %s", pathname); -        /* First try opening through the virtual mount point. -         * The difference lies in the fact that: -         * 1. We depend on libglusterfsclient library to perform -         * the translation from the path to handle. -         * 2. We do not go to the file system for the fd, instead -         * we use booster_get_process_fd (), which returns a dup'ed -         * fd of a pipe created in booster_init. -         */ -        if (flags & GF_O_CREAT) { -                va_start (ap, flags); -                mode = va_arg (ap, mode_t); -                va_end (ap); -                ret = vmp_open (pathname, flags, mode); -        } -        else -                ret = vmp_open (pathname, flags); - -        /* We receive an ENODEV if the VMP does not exist. If we -         * receive an error other than ENODEV, it means, there -         * actually was an error performing vmp_open. This must -         * be returned to the user. -         */ -        if ((ret < 0) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "Error in opening file over " -                        " VMP: %s", strerror (errno)); -                goto out; -        } - -        if (ret > 0) { -                gf_log ("booster", GF_LOG_TRACE, "File opened"); -                goto out; -        } - -        if (use64) { -                gf_log ("booster", GF_LOG_TRACE, "Using 64-bit open"); -		my_open = real_open64; -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Using 32-bit open"); -		my_open = real_open; -        } - -        /* It is possible the RESOLVE macro is not able -         * to resolve the symbol of a function, in that case -         * we dont want to seg-fault on calling a NULL functor. -         */ -        if (my_open == NULL) { -                gf_log ("booster", GF_LOG_ERROR, "open not resolved"); -                ret = -1; -                errno = ENOSYS; -                goto out; -        } - -	if (flags & GF_O_CREAT) { -		va_start (ap, flags); -		mode = va_arg (ap, mode_t); -		va_end (ap); - -                ret = my_open (pathname, flags, mode); -	} else -                ret = my_open (pathname, flags); - -        if (ret != -1) { -                do_open (ret, pathname, flags, mode, BOOSTER_OPEN); -        } - -out: -        return ret; -} - -/* This is done to over-write existing definitions of open and open64 inside - * libc with our own copies. __REDIRECT is provided by libc. - * - * XXX: This will not work anywhere other than libc based systems. - */ -int __REDIRECT (booster_false_open, (__const char *__file, int __oflag, ...), -                open) __nonnull ((1)); -int __REDIRECT (booster_false_open64, (__const char *__file, int __oflag, ...), -                open64) __nonnull ((1)); -int -booster_false_open (const char *pathname, int flags, ...) -{ -        int     ret; -        mode_t  mode = 0; -        va_list ap; - -        if (flags & GF_O_CREAT) { -                va_start (ap, flags); -                mode = va_arg (ap, mode_t); -                va_end (ap); - -                ret = booster_open (pathname, BOOSTER_DONT_USE_OPEN64, flags, -                                    mode); -        } -        else -                ret = booster_open (pathname, BOOSTER_DONT_USE_OPEN64, flags); - -        return ret; -} - -int -booster_false_open64 (const char *pathname, int flags, ...) -{ -        int     ret; -        mode_t  mode = 0; -        va_list ap; - -        if (flags & GF_O_CREAT) { -                va_start (ap, flags); -                mode = va_arg (ap, mode_t); -                va_end (ap); - -                ret = booster_open (pathname, BOOSTER_USE_OPEN64, flags, mode); -        } -        else -                ret = booster_open (pathname, BOOSTER_USE_OPEN64, flags); - -        return ret; -} - -int -vmp_creat (const char *pathname, mode_t mode) -{ -        int                     fd = -1; -        glusterfs_file_t        fh = NULL; - -        fh = glusterfs_creat (pathname, mode); -        if (!fh) { -                gf_log ("booster", GF_LOG_ERROR, "Create failed: %s: %s", -                        pathname, strerror (errno)); -                goto out; -        } - -        fd = booster_get_process_fd (); -        if (fd == -1) { -                gf_log ("booster", GF_LOG_ERROR, "Failed to create fd"); -                goto close_out; -        } - -        if ((booster_fd_unused_get (booster_fdtable, fh, fd)) == -1) { -                gf_log ("booster", GF_LOG_ERROR, "Failed to map unused fd"); -                goto real_close_out; -        } - -        return fd; - -real_close_out: -        real_close (fd); -        fd = -1; - -close_out: -        glusterfs_close (fh); - -out: -        return -1; -} - -int __REDIRECT (booster_false_creat, (const char *pathname, mode_t mode), -                creat) __nonnull ((1)); -int __REDIRECT (booster_false_creat64, (const char *pathname, mode_t mode), -                creat64) __nonnull ((1)); - -int -booster_false_creat (const char *pathname, mode_t mode) -{ -        int     ret = -1; -        if (!pathname) { -                errno = EINVAL; -                goto out; -        } - -        gf_log ("booster", GF_LOG_TRACE, "Create: %s", pathname); -        ret = vmp_creat (pathname, mode); - -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "VMP create failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret > 0) { -                gf_log ("booster", GF_LOG_TRACE, "File created"); -                goto out; -        } - -        if (real_creat == NULL) { -                errno = ENOSYS; -                ret = -1; -                goto out; -        } - -        ret = real_creat (pathname, mode); - -        if (ret != -1) { -                do_open (ret, pathname, GF_O_WRONLY | GF_O_TRUNC, mode, -                         BOOSTER_CREAT); -        } else -                gf_log ("booster", GF_LOG_ERROR, "real create failed: %s", -                        strerror (errno)); - -out: -        return ret; -} - - -int -booster_false_creat64 (const char *pathname, mode_t mode) -{ -        int     ret = -1; -        if (!pathname) { -                errno = EINVAL; -                goto out; -        } - -        gf_log ("booster", GF_LOG_TRACE, "Create: %s", pathname); -        ret = vmp_creat (pathname, mode); - -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "VMP create failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret > 0) { -                gf_log ("booster", GF_LOG_TRACE, "File created"); -                goto out; -        } - -        if (real_creat64 == NULL) { -                errno = ENOSYS; -                ret = -1; -                goto out; -        } - -        ret = real_creat64 (pathname, mode); - -        if (ret != -1) { -                do_open (ret, pathname, GF_O_WRONLY | GF_O_TRUNC, mode, -                         BOOSTER_CREAT); -        } else -                gf_log ("booster", GF_LOG_ERROR, "real create failed: %s", -                        strerror (errno)); - -out: -        return ret; -} - - -/* pread */ - -ssize_t -pread (int fd, void *buf, size_t count, unsigned long offset) -{ -        ssize_t ret; -        glusterfs_file_t glfs_fd = 0; - -        gf_log ("booster", GF_LOG_TRACE, "pread: fd %d, count %lu, offset %lu" -                ,fd, (long unsigned)count, offset); -        glfs_fd = booster_fdptr_get (booster_fdtable, fd); -        if (!glfs_fd) {  -                gf_log ("booster", GF_LOG_TRACE, "Not booster fd"); -                if (real_pread == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_pread (fd, buf, count, offset); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_pread (glfs_fd, buf, count, offset); -                booster_fdptr_put (glfs_fd); -        } - -        return ret; -} - - -ssize_t -pread64 (int fd, void *buf, size_t count, uint64_t offset) -{ -        ssize_t ret; -        glusterfs_file_t glfs_fd = 0; - -        gf_log ("booster", GF_LOG_TRACE, "pread64: fd %d, count %lu, offset %" -                PRIu64, fd, (long unsigned)count, offset); -        glfs_fd = booster_fdptr_get (booster_fdtable, fd); -        if (!glfs_fd) {  -                gf_log ("booster", GF_LOG_TRACE, "Not booster fd"); -                if (real_pread64 == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_pread64 (fd, buf, count, offset); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_pread (glfs_fd, buf, count, offset); -                booster_fdptr_put (glfs_fd); -        } - -        return ret; -} - - -ssize_t -read (int fd, void *buf, size_t count) -{ -        int ret; -        glusterfs_file_t glfs_fd; - -        gf_log ("booster", GF_LOG_TRACE, "read: fd %d, count %lu", fd, -                (long unsigned)count); -        glfs_fd = booster_fdptr_get (booster_fdtable, fd); -        if (!glfs_fd) { -                gf_log ("booster", GF_LOG_TRACE, "Not booster fd"); -                if (real_read == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_read (fd, buf, count); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_read (glfs_fd, buf, count); -                booster_fdptr_put (glfs_fd); -        } - -        return ret; -} - - -ssize_t -readv (int fd, const struct iovec *vector, int count) -{ -        int ret; -        glusterfs_file_t glfs_fd = 0; - -        gf_log ("booster", GF_LOG_TRACE, "readv: fd %d, iovecs %d", fd, count); -        glfs_fd = booster_fdptr_get (booster_fdtable, fd); -        if (!glfs_fd) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_readv == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_readv (fd, vector, count); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -		ret = glusterfs_readv (glfs_fd, vector, count); -                booster_fdptr_put (glfs_fd); -        } - -        return ret; -} - - -ssize_t -write (int fd, const void *buf, size_t count) -{ -        int ret; -        glusterfs_file_t glfs_fd = 0; - -        gf_log ("booster", GF_LOG_TRACE, "write: fd %d, count %"GF_PRI_SIZET, -                fd, count); - -        glfs_fd = booster_fdptr_get (booster_fdtable, fd); - -        if (!glfs_fd) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_write == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_write (fd, buf, count); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_write (glfs_fd, buf, count); -                booster_fdptr_put (glfs_fd); -        } -  -        return ret; -} - -ssize_t -writev (int fd, const struct iovec *vector, int count) -{ -        int ret = 0; -        glusterfs_file_t glfs_fd = 0;  - -        gf_log ("booster", GF_LOG_TRACE, "writev: fd %d, iovecs %d", fd, count); -        glfs_fd = booster_fdptr_get (booster_fdtable, fd); - -        if (!glfs_fd) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_writev == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_writev (fd, vector, count); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_writev (glfs_fd, vector, count); -                booster_fdptr_put (glfs_fd); -        } - -        return ret; -} - - -ssize_t -pwrite (int fd, const void *buf, size_t count, unsigned long offset) -{ -        int ret; -        glusterfs_file_t glfs_fd = 0; - -        gf_log ("booster", GF_LOG_TRACE, "pwrite: fd %d, count %"GF_PRI_SIZET -                ", offset %lu", fd, count, offset); -        glfs_fd = booster_fdptr_get (booster_fdtable, fd); - -        if (!glfs_fd) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_pwrite == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_pwrite (fd, buf, count, offset); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_pwrite (glfs_fd, buf, count, offset); -                booster_fdptr_put (glfs_fd); -        } - -        return ret; -} - - -ssize_t -pwrite64 (int fd, const void *buf, size_t count, uint64_t offset) -{ -        int ret; -        glusterfs_file_t glfs_fd = 0; - -        gf_log ("booster", GF_LOG_TRACE, "pwrite64: fd %d, count %"GF_PRI_SIZET -                ", offset %"PRIu64, fd, count, offset); -        glfs_fd = booster_fdptr_get (booster_fdtable, fd); - -        if (!glfs_fd) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_pwrite64 == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_pwrite64 (fd, buf, count, offset); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_pwrite (glfs_fd, buf, count, offset); -                booster_fdptr_put (glfs_fd); -        } - -        return ret; -} - - -int -close (int fd) -{ -        int ret = -1; -        glusterfs_file_t glfs_fd = 0; - -        gf_log ("booster", GF_LOG_TRACE, "close: fd %d", fd); -	glfs_fd = booster_fdptr_get (booster_fdtable, fd); -     -	if (glfs_fd) { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -		booster_fd_put (booster_fdtable, fd); -		ret = glusterfs_close (glfs_fd); -		booster_fdptr_put (glfs_fd); -	} - -        ret = real_close (fd); - -        return ret; -} - -#ifndef _LSEEK_DECLARED -#define _LSEEK_DECLARED -off_t -lseek (int filedes, unsigned long offset, int whence) -{ -        int ret; -        glusterfs_file_t glfs_fd = 0; - -        gf_log ("booster", GF_LOG_TRACE, "lseek: fd %d, offset %ld", -                filedes, offset); - -        glfs_fd = booster_fdptr_get (booster_fdtable, filedes); -        if (glfs_fd) { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_lseek (glfs_fd, offset, whence); -                booster_fdptr_put (glfs_fd); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_lseek == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_lseek (filedes, offset, whence); -        } - -        return ret; -} -#endif - -off_t -lseek64 (int filedes, uint64_t offset, int whence) -{ -        int ret; -        glusterfs_file_t glfs_fd = 0; - - -        gf_log ("booster", GF_LOG_TRACE, "lseek: fd %d, offset %"PRIu64, -                filedes, offset); -        glfs_fd = booster_fdptr_get (booster_fdtable, filedes); -        if (glfs_fd) { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_lseek (glfs_fd, offset, whence); -                booster_fdptr_put (glfs_fd); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_lseek64 == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_lseek64 (filedes, offset, whence); -        } - -        return ret; -} - -int  -dup (int oldfd) -{ -        int ret = -1, new_fd = -1; -        glusterfs_file_t glfs_fd = 0; - -        gf_log ("booster", GF_LOG_TRACE, "dup: fd %d", oldfd); -        glfs_fd = booster_fdptr_get (booster_fdtable, oldfd); -        new_fd = real_dup (oldfd); - -        if (new_fd >=0 && glfs_fd) { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = booster_fd_unused_get (booster_fdtable, glfs_fd, -                                             new_fd); -                fd_ref ((fd_t *)glfs_fd); -                if (ret == -1) { -                        gf_log ("booster", GF_LOG_ERROR,"Failed to map new fd"); -                        real_close (new_fd); -                }  -        } - -        if (glfs_fd) { -                booster_fdptr_put (glfs_fd); -        } - -        return new_fd; -} - - -int  -dup2 (int oldfd, int newfd) -{ -        int ret = -1; -        glusterfs_file_t old_glfs_fd = NULL, new_glfs_fd = NULL; - -        if (oldfd == newfd) { -                return newfd; -        } - -        old_glfs_fd = booster_fdptr_get (booster_fdtable, oldfd); -        new_glfs_fd = booster_fdptr_get (booster_fdtable, newfd); -  -        ret = real_dup2 (oldfd, newfd);  -        if (ret >= 0) { -                if (new_glfs_fd) { -                        glusterfs_close (new_glfs_fd); -                        booster_fdptr_put (new_glfs_fd); -                        booster_fd_put (booster_fdtable, newfd); -                        new_glfs_fd = 0; -                } - -                if (old_glfs_fd) { -                        ret = booster_fd_unused_get (booster_fdtable, -                                                     old_glfs_fd, newfd); -                        fd_ref ((fd_t *)old_glfs_fd); -                        if (ret == -1) { -                                real_close (newfd); -                        } -                } -        }  - -        if (old_glfs_fd) { -                booster_fdptr_put (old_glfs_fd); -        } - -        if (new_glfs_fd) { -                booster_fdptr_put (new_glfs_fd); -        } - -        return ret; -} - -int -mkdir (const char *pathname, mode_t mode) -{ -        int     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "mkdir: path %s", pathname); -        ret = glusterfs_mkdir (pathname, mode); - -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "mkdir failed: %s", -                        strerror (errno)); -                return ret; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "directory created"); -                return ret; -        } - -        if (real_mkdir == NULL) { -                ret = -1; -                errno = ENOSYS; -        } else -                ret = real_mkdir (pathname, mode); - -        return ret; -} - -int -rmdir (const char *pathname) -{ -        int     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "rmdir: path %s", pathname); -        ret = glusterfs_rmdir (pathname); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "rmdir failed: %s", -                        strerror (errno)); -                return ret; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "directory removed"); -                return ret; -        } - -        if (real_rmdir == NULL) { -                errno = ENOSYS; -                ret = -1; -        } else -                ret = real_rmdir (pathname); - -        return ret; -} - -int -chmod (const char *pathname, mode_t mode) -{ -        int     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "chmod: path %s", pathname); -        ret = glusterfs_chmod (pathname, mode); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "chmod failed: %s", -                        strerror (errno)); -                return ret; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "chmod succeeded"); -                return ret; -        } - -        if (real_chmod == NULL) { -                errno = ENOSYS; -                ret = -1; -        } else -                ret = real_chmod (pathname, mode); - -        return ret; -} - -int -chown (const char *pathname, uid_t owner, gid_t group) -{ -        int     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "chown: path: %s", pathname); -        ret = glusterfs_chown (pathname, owner, group); - -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "chown failed: %s\n", -                        strerror (errno)); -                return ret; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "chown succeeded"); -                return ret; -        } - -        if (real_chown == NULL) { -                errno = ENOSYS; -                ret = -1; -        } else -                ret = real_chown (pathname, owner, group); - -        return ret; -} - -int -fchown (int fd, uid_t owner, gid_t group) -{ -        int                     ret = -1; -        glusterfs_file_t        fh = NULL; - -        gf_log ("booster", GF_LOG_TRACE, "fchown: fd %d, uid %d, gid %d", fd, -                owner, group); -        fh = booster_fdptr_get (booster_fdtable, fd); -        if (!fh) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_fchown == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_fchown (fd, owner, group); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_fchown (fh, owner, group); -                booster_fdptr_put (fh); -        } - -        return ret; -} - - -#define MOUNT_TABLE_HASH_SIZE 256 - - -static void booster_cleanup (void); -static int  -booster_init (void) -{ -        char    *booster_conf_path = NULL; -        int     ret = -1; -        int     pipefd[2]; - -        booster_fdtable = booster_fdtable_alloc (); -        if (!booster_fdtable) { -                fprintf (stderr, "cannot allocate fdtable: %s\n", -                         strerror (errno)); -		goto err; -        } -  -        if (pipe (pipefd) == -1) { -                gf_log ("booster-fstab", GF_LOG_ERROR, "Pipe creation failed:%s" -                        , strerror (errno)); -                goto err; -        } - -        process_piped_fd = pipefd[0]; -        real_close (pipefd[1]); -        /* libglusterfsclient based VMPs should be inited only -         * after the file tables are inited so that if the socket -         * calls use the fd based syscalls, the fd tables are -         * correctly initialized to return a NULL handle, on which the -         * socket calls will fall-back to the real API. -         */ -        booster_conf_path = getenv (BOOSTER_CONF_ENV_VAR); -        if (booster_conf_path != NULL) { -                if (strlen (booster_conf_path) > 0) -                        ret = booster_configure (booster_conf_path); -                else { -                        gf_log ("booster", GF_LOG_ERROR, "%s not defined, " -                                "using default path: %s", BOOSTER_CONF_ENV_VAR, -                                DEFAULT_BOOSTER_CONF); -                        ret = booster_configure (DEFAULT_BOOSTER_CONF); -                } -        } else { -                gf_log ("booster", GF_LOG_ERROR, "%s not defined, using default" -                        " path: %s", BOOSTER_CONF_ENV_VAR,DEFAULT_BOOSTER_CONF); -                ret = booster_configure (DEFAULT_BOOSTER_CONF); -        } - -        atexit (booster_cleanup); -        if (ret == 0) -                gf_log ("booster", GF_LOG_DEBUG, "booster is inited"); -	return 0; - -err: -        /* Sure we return an error value here -         * but who cares about booster. -         */ -	return -1;  -} - - -static void -booster_cleanup (void) -{ -        /* Ideally, we should be de-initing the fd-table -         * here but the problem is that I've seen file accesses through booster -         * continuing while the atexit registered function is called. That means -         * , we cannot dealloc the fd-table since then there could be a crash -         * while trying to determine whether a given fd is for libc or for -         * libglusterfsclient. -         * We should be satisfied with having cleaned up glusterfs contexts. -         */ -        glusterfs_umount_all (); -	glusterfs_reset (); -} - -int -fchmod (int fd, mode_t mode) -{ -        int                     ret = -1; -        glusterfs_file_t        fh = NULL; - -        gf_log ("booster", GF_LOG_TRACE, "fchmod: fd %d, mode: 0x%x", fd, mode); -        fh = booster_fdptr_get (booster_fdtable, fd); -        if (!fh) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_fchmod == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_fchmod (fd, mode); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_fchmod (fh, mode); -                booster_fdptr_put (fh); -        } - -        return ret; -} - -int -fsync (int fd) -{ -        int                     ret = -1; -        glusterfs_file_t        fh = NULL; - -        gf_log ("booster", GF_LOG_TRACE, "fsync: fd %d", fd); -        fh = booster_fdptr_get (booster_fdtable, fd); -        if (!fh) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_fsync == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_fsync (fd); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_fsync (fh); -                booster_fdptr_put (fh); -        } - -        return ret; -} - -int __REDIRECT (booster_false_ftruncate, (int fd, off_t length), -                ftruncate); -int __REDIRECT (booster_false_ftruncate64, (int fd, loff_t length), -                ftruncate64); - -int -booster_false_ftruncate (int fd, off_t length) -{ -        int                     ret = -1; -        glusterfs_file_t        fh = NULL; - -        gf_log ("booster", GF_LOG_TRACE, "ftruncate: fd %d, length: %"PRIu64,fd -                , length); -        fh = booster_fdptr_get (booster_fdtable, fd); -        if (!fh) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_ftruncate == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_ftruncate (fd, length); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_ftruncate (fh, length); -                booster_fdptr_put (fh); -        } - -        return ret; -} - -int -booster_false_ftruncate64 (int fd, loff_t length) -{ -        int                     ret = -1; -        glusterfs_file_t        fh = NULL; - -        gf_log ("booster", GF_LOG_TRACE, "ftruncate: fd %d, length: %"PRIu64,fd -                , length); -        fh = booster_fdptr_get (booster_fdtable, fd); -        if (!fh) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_ftruncate == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_ftruncate64 (fd, length); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_ftruncate (fh, length); -                booster_fdptr_put (fh); -        } - -        return ret; -} - -int -link (const char *old, const char *new) -{ -        int             ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "link: old: %s, new: %s", old, new); -        ret = glusterfs_link (old, new); - -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "Link failed: %s", -                        strerror (errno)); -                return ret; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "link call succeeded"); -                return ret; -        } - -        if (real_link == NULL) { -                errno = ENOSYS; -                ret = -1; -        } else -                ret = real_link (old, new); - -        return ret; -} - -int -rename (const char *old, const char *new) -{ -        int             ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "link: old: %s, new: %s", old, new); -        ret = glusterfs_rename (old, new); - -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "Rename failed: %s", -                        strerror (errno)); -                return ret; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "Rename succeeded"); -                return ret; -        } - -        if (real_rename == NULL) { -                errno = ENOSYS; -                ret = -1; -        } else -                ret = real_rename (old, new); - -        return ret; -} - -int -utimes (const char *path, const struct timeval times[2]) -{ -        int             ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "utimes: path %s", path); -        ret = glusterfs_utimes (path, times); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "utimes failed: %s", -                        strerror (errno)); -                return ret; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "utimes succeeded"); -                return ret; -        } - -        if (real_utimes == NULL) { -                errno = ENOSYS; -                ret = -1; -        } else -                ret = real_utimes (path, times); - -        return ret; -} - -int -utime (const char *path, const struct utimbuf *buf) -{ -        int     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "utime: path %s", path); -        ret = glusterfs_utime (path, buf); - -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "utime failed: %s", -                        strerror (errno)); -                return ret; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "utime succeeded"); -                return ret; -        } - -        if (real_utime == NULL) { -                errno = ENOSYS; -                ret = -1; -        } else -                ret = real_utime (path, buf); - -        return ret; -} - -int -mknod (const char *path, mode_t mode, dev_t dev) -{ -        int     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "mknod: path %s", path); -        ret = glusterfs_mknod (path, mode, dev); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "mknod failed: %s", -                        strerror (errno)); -                return ret; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "mknod succeeded"); -                return ret; -        } - -        if (real_mknod) { -                errno = ENOSYS; -                ret = -1; -        } else -                ret = real_mknod (path, mode, dev); - -        return ret; -} - -int -mkfifo (const  char *path, mode_t mode) -{ -        int     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "mkfifo: path %s", path); -        ret = glusterfs_mkfifo (path, mode); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "mkfifo failed: %s", -                        strerror (errno)); -                return ret; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "mkfifo succeeded"); -                return ret; -        } - -        if (real_mkfifo == NULL) { -                errno = ENOSYS; -                ret = -1; -        } else -                ret = real_mkfifo (path, mode); - -        return ret; -} - -int -unlink (const char *path) -{ -        int     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "unlink: path %s", path); -        ret = glusterfs_unlink (path); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "unlink failed: %s", -                        strerror (errno)); -                return ret; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "unlink succeeded"); -                return ret; -        } - -        if (real_unlink == NULL) { -                errno = ENOSYS; -                ret = -1; -        } else -                ret = real_unlink (path); - -        return ret; -} - -int -symlink (const char *oldpath, const char *newpath) -{ -        int     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "symlink: old: %s, new: %s", -                oldpath, newpath); -        ret = glusterfs_symlink (oldpath, newpath); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "symlink failed: %s", -                        strerror (errno)); -                return ret; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "symlink succeeded"); -                return ret; -        } - -        if (real_symlink == NULL) { -                errno = ENOSYS; -                ret = -1; -        } else -                ret = real_symlink (oldpath, newpath); - -        return ret; -} - -int -readlink (const char *path, char *buf, size_t bufsize) -{ -        int     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "readlink: path %s", path); -        ret = glusterfs_readlink (path, buf, bufsize); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "readlink failed: %s", -                        strerror (errno)); -                return ret; -        } - -        if (ret > 0) { -                gf_log ("booster", GF_LOG_TRACE, "readlink succeeded"); -                return ret; -        } - -        if (real_readlink == NULL) { -                errno = ENOSYS; -                ret = -1; -        } else -                ret = real_readlink (path, buf, bufsize); - -        return ret; -} - -char * -realpath (const char *path, char *resolved_path) -{ -        char    *res = NULL; - -        gf_log ("booster", GF_LOG_TRACE, "realpath: path %s", path); -        res = glusterfs_realpath (path, resolved_path); -        if ((res == NULL) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "realpath failed: %s", -                        strerror (errno)); -                return res; -        } - -        if (res != NULL) { -                gf_log ("booster", GF_LOG_TRACE, "realpath succeeded"); -                return res; -        } - -        if (real_realpath == NULL) { -                errno = ENOSYS; -                res = NULL; -        } else -                res = real_realpath (path, resolved_path); - -        return res; -} - -#define BOOSTER_GL_DIR          1 -#define BOOSTER_POSIX_DIR       2 - -struct booster_dir_handle { -        int type; -        void *dirh; -}; - -DIR * -opendir (const char *path) -{ -        glusterfs_dir_t                 gdir = NULL; -        struct booster_dir_handle       *bh = NULL; -        DIR                             *pdir = NULL; - -        gf_log ("booster", GF_LOG_TRACE, "opendir: path: %s", path); -        bh = calloc (1, sizeof (struct booster_dir_handle)); -        if (!bh) { -                gf_log ("booster", GF_LOG_ERROR, "memory allocation failed"); -                errno = ENOMEM; -                goto out; -        } - -        gdir = glusterfs_opendir (path); -        if (gdir) { -                gf_log ("booster", GF_LOG_TRACE, "Gluster dir opened"); -                bh->type = BOOSTER_GL_DIR; -                bh->dirh = (void *)gdir; -                goto out; -        } else if ((!gdir) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "Opendir failed"); -                goto free_out; -        } - -        if (real_opendir == NULL) { -                errno = ENOSYS; -                goto free_out; -        } - -        pdir = real_opendir (path); - -        if (pdir) { -                bh->type = BOOSTER_POSIX_DIR; -                bh->dirh = (void *)pdir; -                goto out; -        } - -free_out: -        if (bh) { -                free (bh); -                bh = NULL; -        } -out: -        return (DIR *)bh; -} - -int __REDIRECT (booster_false_readdir_r, (DIR *dir, struct dirent *entry, -                struct dirent **result), readdir_r) __nonnull ((1)); -int __REDIRECT (booster_false_readdir64_r, (DIR *dir, struct dirent64 *entry, -                struct dirent64 **result), readdir64_r) __nonnull ((1)); - -int -booster_false_readdir_r (DIR *dir, struct dirent *entry, struct dirent **result) -{ -        struct booster_dir_handle       *bh = (struct booster_dir_handle *)dir; -        int                              ret = 0;   - -        if (!bh) { -                ret = errno = EFAULT; -                goto out; -        } - -        if (bh->type == BOOSTER_GL_DIR) { -                gf_log ("booster", GF_LOG_TRACE, "readdir_r on gluster"); -                ret = glusterfs_readdir_r ((glusterfs_dir_t)bh->dirh, entry, -                                           result); -                 -        } else if (bh->type == BOOSTER_POSIX_DIR) { -                gf_log ("booster", GF_LOG_TRACE, "readdir_r on posix"); -                if (real_readdir_r == NULL) { -                        ret = errno = ENOSYS; -                        goto out; -                } - -                ret = real_readdir_r ((DIR *)bh->dirh, entry, result); -        } else { -                ret = errno = EINVAL; -        } - -out: -        return  ret; -} - -int -booster_false_readdir64_r (DIR *dir, struct dirent64 *entry, -                           struct dirent64 **result) -{ -        struct booster_dir_handle       *bh = (struct booster_dir_handle *)dir; -        int                              ret = 0;   - -        if (!bh) { -                ret = errno = EFAULT; -                goto out; -        } - -        if (bh->type == BOOSTER_GL_DIR) { -                gf_log ("booster", GF_LOG_TRACE, "readdir_r on gluster"); -                ret = glusterfs_readdir_r ((glusterfs_dir_t)bh->dirh, -                                           (struct dirent *)entry, -                                           (struct dirent **)result); -        } else if (bh->type == BOOSTER_POSIX_DIR) { -                gf_log ("booster", GF_LOG_TRACE, "readdir_r on posix"); -                if (real_readdir64_r == NULL) { -                        ret = errno = ENOSYS; -                        goto out; -                } - -                ret = real_readdir64_r ((DIR *)bh->dirh, entry, result); -        } else { -                ret = errno = EINVAL; -        } - -out: -        return  ret; -} - -struct dirent * -__REDIRECT (booster_false_readdir, (DIR *dir), readdir) __nonnull ((1)); - -struct dirent64 * -__REDIRECT (booster_false_readdir64, (DIR *dir), readdir64) __nonnull ((1)); - -struct dirent * -booster_false_readdir (DIR *dir) -{ -        struct booster_dir_handle       *bh = (struct booster_dir_handle *)dir; -        struct dirent                   *dirp = NULL; - -        if (!bh) { -                errno = EFAULT; -                goto out; -        } - -        if (bh->type == BOOSTER_GL_DIR) { -                gf_log ("booster", GF_LOG_TRACE, "readdir on gluster"); -                dirp = glusterfs_readdir ((glusterfs_dir_t)bh->dirh); -        } else if (bh->type == BOOSTER_POSIX_DIR) { -                gf_log ("booster", GF_LOG_TRACE, "readdir on posix"); -                if (real_readdir == NULL) { -                        errno = ENOSYS; -                        dirp = NULL; -                        goto out; -                } - -                dirp = real_readdir ((DIR *)bh->dirh); -        } else { -                dirp = NULL; -                errno = EINVAL; -        } - -out: -        return  dirp; -} - -struct dirent64 * -booster_false_readdir64 (DIR *dir) -{ -        struct booster_dir_handle       *bh = (struct booster_dir_handle *)dir; -        struct dirent64                 *dirp = NULL; - -        if (!bh) { -                errno = EFAULT; -                goto out; -        } - -        if (bh->type == BOOSTER_GL_DIR) { -                gf_log ("booster", GF_LOG_TRACE, "readdir on gluster"); -                dirp = glusterfs_readdir ((glusterfs_dir_t)bh->dirh); -        } else if (bh->type == BOOSTER_POSIX_DIR) { -                gf_log ("booster", GF_LOG_TRACE, "readdir on posix"); -                if (real_readdir == NULL) { -                        errno = ENOSYS; -                        dirp = NULL; -                        goto out; -                } - -                dirp = real_readdir64 ((DIR *)bh->dirh); -        } else { -                dirp = NULL; -                errno = EINVAL; -        } - -out: -        return  dirp; -} - -int -closedir (DIR *dh) -{ -        struct booster_dir_handle       *bh = (struct booster_dir_handle *)dh; -        int                             ret = -1; - -        if (!bh) { -                errno = EFAULT; -                goto out; -        } - -        if (bh->type == BOOSTER_GL_DIR) { -                gf_log ("booster", GF_LOG_TRACE, "closedir on gluster"); -                ret = glusterfs_closedir ((glusterfs_dir_t)bh->dirh); -        } else if (bh->type == BOOSTER_POSIX_DIR) { -                gf_log ("booster", GF_LOG_TRACE, "closedir on posix"); -                if (real_closedir == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else -                        ret = real_closedir ((DIR *)bh->dirh); -        } else { -                errno = EBADF; -        } - -        if (ret == 0) { -                free (bh); -                bh = NULL; -        } -out: -        return ret; -} - -/* The real stat functions reside in booster_stat.c to - * prevent clash with the statX prototype and functions - * declared from sys/stat.h - */ -int -booster_xstat (int ver, const char *path, void *buf) -{ -        struct stat     *sbuf = (struct stat *)buf; -        int             ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "xstat: path: %s", path); -        ret = glusterfs_stat (path, sbuf); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "xstat failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "xstat succeeded"); -                goto out; -        } - -        if (real___xstat == NULL) { -                ret = -1; -                errno = ENOSYS; -                goto out; -        } - -        ret = real___xstat (ver, path, sbuf); -out: -        return ret; -} - -int -booster_xstat64 (int ver, const char *path, void *buf) -{ -        int             ret = -1; -        struct stat64   *sbuf = (struct stat64 *)buf; - -        gf_log ("booster", GF_LOG_TRACE, "xstat64: path: %s", path); -        ret = glusterfs_stat (path, (struct stat *)sbuf); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "xstat64 failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "xstat64 succeeded"); -                goto out; -        } - -        if (real___xstat64 == NULL) { -                errno = ENOSYS; -                ret = -1; -                goto out; -        } - -        ret = real___xstat64 (ver, path, sbuf); -out: -        return ret; -} - -int -booster_stat (const char *path, void *buf) -{ -        struct stat     *sbuf = (struct stat *)buf; -        int             ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "stat: path: %s", path); -        ret = glusterfs_stat (path, sbuf); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "stat failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "stat succeeded"); -                goto out; -        } - -        if (real_stat != NULL) -                ret = real_stat (path, sbuf); -        else if (real___xstat != NULL) -                ret = real___xstat (0, path, sbuf); -        else { -                errno = ENOSYS; -                ret = -1; -                goto out; -        } - - -out: -        return ret; -} - -int -booster_stat64 (const char *path, void *buf) -{ -        int             ret = -1; -        struct stat64   *sbuf = (struct stat64 *)buf; - -        gf_log ("booster", GF_LOG_TRACE, "stat64: %s", path); -        ret = glusterfs_stat (path, (struct stat *)sbuf); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "stat64 failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "stat64 succeeded"); -                goto out; -        } - -        if (real_stat64 != NULL) -                ret = real_stat64 (path, sbuf); -        else if (real___xstat64 != NULL) -                ret = real___xstat64 (0, path, sbuf); -        else { -                errno = ENOSYS; -                ret = -1; -                goto out; -        } - -out: -        return ret; -} - -int -booster_fxstat (int ver, int fd, void *buf) -{ -        struct stat             *sbuf = (struct stat *)buf; -        int                     ret = -1; -        glusterfs_file_t        fh = NULL; - -        gf_log ("booster", GF_LOG_TRACE, "fxstat: fd %d", fd); -        fh = booster_fdptr_get (booster_fdtable, fd); -        if (!fh) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real___fxstat == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                        goto out; -                } - -                ret = real___fxstat (ver, fd, sbuf); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_fstat (fh, sbuf); -                booster_fdptr_put (fh); -        } - -out: -        return ret; -} - -int -booster_fxstat64 (int ver, int fd, void *buf) -{ -        int                     ret = -1; -        struct stat64           *sbuf = (struct stat64 *)buf; -        glusterfs_file_t        fh = NULL; - -        gf_log ("booster", GF_LOG_TRACE, "fxstat64: fd %d", fd); -        fh = booster_fdptr_get (booster_fdtable, fd); -        if (!fh) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real___fxstat64 == NULL) { -                        ret = -1; -                        errno = ENOSYS; -                        goto out; -                } -                ret = real___fxstat64 (ver, fd, sbuf); -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_fstat (fh, (struct stat *)sbuf); -                booster_fdptr_put (fh); -        } - -out: -        return ret; -} - -int -booster_fstat (int fd, void *buf) -{ -        struct stat             *sbuf = (struct stat *)buf; -        int                     ret = -1; -        glusterfs_file_t        fh = NULL; - -        gf_log ("booster", GF_LOG_TRACE, "fstat: fd %d", fd); -        fh = booster_fdptr_get (booster_fdtable, fd); -        if (!fh) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_fstat != NULL) -                        ret = real_fstat (fd, sbuf); -                else if (real___fxstat != NULL) -                        ret = real___fxstat (0, fd, sbuf); -                else { -                        ret = -1; -                        errno = ENOSYS; -                        goto out; -                } -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_fstat (fh, sbuf); -                booster_fdptr_put (fh); -        } - -out: -        return ret; -} - -int -booster_fstat64 (int fd, void *buf) -{ -        int                     ret = -1; -        struct stat64           *sbuf = (struct stat64 *)buf; -        glusterfs_file_t        fh = NULL; - -        gf_log ("booster", GF_LOG_TRACE, "fstat64: fd %d", fd); -        fh = booster_fdptr_get (booster_fdtable, fd); -        if (!fh) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_fstat64 != NULL) -                        ret = real_fstat64 (fd, sbuf); -                else if (real___fxstat64 != NULL) -                        /* Not sure how portable the use of 0 for -                         * version number is but it works over glibc. -                         * We need this because, I've -                         * observed that all the above real* functors can be -                         * NULL. In that case, this is our last and only option. -                         */ -                        ret = real___fxstat64 (0, fd, sbuf); -                else { -                        ret = -1; -                        errno = ENOSYS; -                        goto out; -                } -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_fstat (fh, (struct stat *)sbuf); -                booster_fdptr_put (fh); -        } - -out: -        return ret; -} - -int -booster_lxstat (int ver, const char *path, void *buf) -{ -        struct stat     *sbuf = (struct stat *)buf; -        int             ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "lxstat: path %s", path); -        ret = glusterfs_lstat (path, sbuf); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "lxstat failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "lxstat succeeded"); -                goto out; -        } - -        if (real___lxstat == NULL) { -                ret = -1; -                errno = ENOSYS; -                goto out; -        } - -        ret = real___lxstat (ver, path, sbuf); -out: -        return ret; -} - -int -booster_lxstat64 (int ver, const char *path, void *buf) -{ -        int             ret = -1; -        struct stat64   *sbuf = (struct stat64 *)buf; - -        gf_log ("booster", GF_LOG_TRACE, "lxstat64: path %s", path); -        ret = glusterfs_lstat (path, (struct stat *)sbuf); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "lxstat64 failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "lxstat64 succeeded"); -                goto out; -        } - -        if (real___lxstat64 == NULL) { -                errno = ENOSYS; -                ret = -1; -                goto out; -        } - -        ret = real___lxstat64 (ver, path, sbuf); -out: -        return ret; -} - -int -booster_lstat (const char *path, void *buf) -{ -        struct stat     *sbuf = (struct stat *)buf; -        int             ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "lstat: path %s", path); -        ret = glusterfs_lstat (path, sbuf); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "lstat failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "lstat succeeded"); -                goto out; -        } - -        if (real_lstat != NULL) -                ret = real_lstat (path, sbuf); -        else if (real___lxstat != NULL) -                ret = real___lxstat (0, path, sbuf); -        else { -                errno = ENOSYS; -                ret = -1; -                goto out; -        } - - -out: -        return ret; -} - -int -booster_lstat64 (const char *path, void *buf) -{ -        int             ret = -1; -        struct stat64   *sbuf = (struct stat64 *)buf; - -        gf_log ("booster", GF_LOG_TRACE, "lstat64: path %s", path); -        ret = glusterfs_lstat (path, (struct stat *)sbuf); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "lstat64 failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "lstat64 succeeded"); -                goto out; -        } - -        if (real_lstat64 != NULL) -                ret = real_lstat64 (path, sbuf); -        else if (real___lxstat64 != NULL) -                ret = real___lxstat64 (0, path, sbuf); -        else { -                errno = ENOSYS; -                ret = -1; -                goto out; -        } - -out: -        return ret; -} - -int -booster_statfs (const char *pathname, struct statfs *buf) -{ -        int             ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "statfs: path %s", pathname); -        ret = glusterfs_statfs (pathname, buf); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "statfs failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "statfs succeeded"); -                goto out; -        } - -        if (real_statfs == NULL) { -                ret = -1; -                errno = ENOSYS; -                goto out; -        } - -        ret = real_statfs (pathname, buf); - -out: -        return ret; -} - -int -booster_statfs64 (const char *pathname, struct statfs64 *buf) -{ -        int             ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "stat64: path %s", pathname); -        ret = glusterfs_statfs (pathname, (struct statfs *)buf); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "statfs64 failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "statfs64 succeeded"); -                goto out; -        } - -        if (real_statfs64 == NULL) { -                ret = -1; -                errno = ENOSYS; -                goto out; -        } - -        ret = real_statfs64 (pathname, buf); - -out: -        return ret; -} - -int -booster_statvfs (const char *pathname, struct statvfs *buf) -{ -        int             ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "statvfs: path %s", pathname); -        ret = glusterfs_statvfs (pathname, buf); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "statvfs failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "statvfs succeeded"); -                goto out; -        } - -        if (real_statvfs == NULL) { -                ret = -1; -                errno = ENOSYS; -                goto out; -        } - -        ret = real_statvfs (pathname, buf); - -out: -        return ret; -} - -int -booster_statvfs64 (const char *pathname, struct statvfs64 *buf) -{ -        int             ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "statvfs64: path %s", pathname); -        ret = glusterfs_statvfs (pathname, (struct statvfs *)buf); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "statvfs64 failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "statvfs64 succeeded"); -                goto out; -        } - -        if (real_statvfs64 == NULL) { -                ret = -1; -                errno = ENOSYS; -                goto out; -        } - -        ret = real_statvfs64 (pathname, buf); - -out: -        return ret; -} - -ssize_t -getxattr (const char *path, const char *name, void *value, size_t size) -{ -        int     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "getxattr: path %s, name %s", path, -                name); -        ret = glusterfs_getxattr (path, name, value, size); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "getxattr failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret > 0) { -                gf_log ("booster", GF_LOG_TRACE, "getxattr succeeded"); -                return ret; -        } - -        if (real_getxattr == NULL) { -                ret = -1; -                errno = ENOSYS; -                goto out; -        } - -        ret = real_getxattr (path, name, value, size); -out: -        return ret; -} - - -ssize_t -lgetxattr (const char *path, const char *name, void *value, size_t size) -{ -        int     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "lgetxattr: path %s, name %s", path, -                name); -        ret = glusterfs_lgetxattr (path, name, value, size); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "lgetxattr failed: %s", -                        strerror (errno)); - -                goto out; -        } - -        if (ret > 0) { -                gf_log ("booster", GF_LOG_TRACE, "lgetxattr succeeded"); -                return ret; -        } - -        if (real_lgetxattr == NULL) { -                ret = -1; -                errno = ENOSYS; -                goto out; -        } - -        ret = real_lgetxattr (path, name, value, size); -out: -        return ret; -} - -int -remove (const char *path) -{ -        int     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "remove: %s", path); -        ret = glusterfs_remove (path); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "remove failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "remove succeeded"); -                goto out; -        } - -        if (real_remove == NULL) { -                errno = ENOSYS; -                ret = -1; -                goto out; -        } - -        ret = real_remove (path); - -out: -        return ret; -} - -int -lchown (const char *path, uid_t owner, gid_t group) -{ -        int     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "lchown: path %s", path); -        ret = glusterfs_lchown (path, owner, group); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "lchown failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_ERROR, "lchown succeeded"); -                goto out; -        } - -        if (real_lchown == NULL) { -                errno = ENOSYS; -                ret = -1; -                goto out; -        } - -        ret = real_lchown (path, owner, group); - -out: -        return ret; -} - -void -booster_rewinddir (DIR *dir) -{ -        struct booster_dir_handle       *bh = (struct booster_dir_handle *)dir; - -        if (!bh) { -                errno = EFAULT; -                goto out; -        } - -        if (bh->type == BOOSTER_GL_DIR) { -                gf_log ("booster", GF_LOG_TRACE, "rewinddir on glusterfs"); -                glusterfs_rewinddir ((glusterfs_dir_t)bh->dirh); -        } else if (bh->type == BOOSTER_POSIX_DIR) { -                if (real_rewinddir == NULL) { -                        errno = ENOSYS; -                        goto out; -                } -                gf_log ("booster", GF_LOG_TRACE, "rewinddir on posix"); -                real_rewinddir ((DIR *)bh->dirh); -        } else -                errno = EINVAL; -out: -        return; -} - -void -booster_seekdir (DIR *dir, off_t offset) -{ -        struct booster_dir_handle       *bh = (struct booster_dir_handle *)dir; - -        if (!bh) { -                errno = EFAULT; -                goto out; -        } - -        if (bh->type == BOOSTER_GL_DIR) { -                gf_log ("booster", GF_LOG_TRACE, "seekdir on glusterfs"); -                glusterfs_seekdir ((glusterfs_dir_t)bh->dirh, offset); -         } else if (bh->type == BOOSTER_POSIX_DIR) { -                if (real_seekdir == NULL) { -                        errno = ENOSYS; -                        goto out; -                } - -                gf_log ("booster", GF_LOG_TRACE, "seekdir on posix"); -                real_seekdir ((DIR *)bh->dirh, offset); -        } else -                errno = EINVAL; -out: -        return; -} - -off_t -booster_telldir (DIR *dir) -{ -        struct booster_dir_handle       *bh = (struct booster_dir_handle *)dir; -        off_t	offset = -1; - -        if (!bh) { -                errno = EFAULT; -                goto out; -        } - -        if (bh->type == BOOSTER_GL_DIR) { -                gf_log ("booster", GF_LOG_TRACE, "telldir on glusterfs"); -                offset = glusterfs_telldir ((glusterfs_dir_t)bh->dirh); -        } else if (bh->type == BOOSTER_POSIX_DIR) { -                if (real_telldir == NULL) { -                        errno = ENOSYS; -                        goto out; -                } - -                gf_log ("booster", GF_LOG_TRACE, "telldir on posix"); -                offset = real_telldir ((DIR *)bh->dirh); -        } else -                errno = EINVAL; -out: -        return offset; -} - - -pid_t  -fork (void) -{ -	pid_t pid = 0; -	char child = 0; - -	glusterfs_log_lock (); -	{ -		pid = real_fork (); -	} -	glusterfs_log_unlock (); - -	child = (pid == 0); -	if (child) { -		booster_cleanup (); -		booster_init (); -	} - -	return pid; -} - -ssize_t -sendfile (int out_fd, int in_fd, off_t *offset, size_t count) -{ -        glusterfs_file_t            in_fh = NULL; -        ssize_t                     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "sendfile: in fd %d, out fd %d, offset" -                " %"PRIu64", count %"GF_PRI_SIZET, in_fd, out_fd, *offset, -                count); -        /* -         * handle sendfile in booster only if in_fd corresponds to a glusterfs -         * file handle  -         */ -        in_fh = booster_fdptr_get (booster_fdtable, in_fd); -        if (!in_fh) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_sendfile == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else { -                        ret = real_sendfile (out_fd, in_fd, offset, count); -                } -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_sendfile (out_fd, in_fh, offset, count); -                booster_fdptr_put (in_fh); -        } -         -        return ret; -} - -ssize_t -sendfile64 (int out_fd, int in_fd, off_t *offset, size_t count) -{ -        glusterfs_file_t            in_fh = NULL; -        ssize_t                     ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "sendfile64: in fd %d, out fd %d," -                " offset %"PRIu64", count %"GF_PRI_SIZET, in_fd, out_fd, -                *offset, count); -        /* -         * handle sendfile in booster only if in_fd corresponds to a glusterfs -         * file handle  -         */ -        in_fh = booster_fdptr_get (booster_fdtable, in_fd); -        if (!in_fh) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_sendfile64 == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else { -                        ret = real_sendfile64 (out_fd, in_fd, offset, count); -                } -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_sendfile (out_fd, in_fh, offset, count); -                booster_fdptr_put (in_fh); -        } -         -        return ret; -} - - -int -fcntl (int fd, int cmd, ...) -{ -        va_list           ap; -        int               ret = -1; -        long              arg = 0; -        struct flock     *lock = NULL; -        glusterfs_file_t  glfs_fd = 0;  - -        glfs_fd = booster_fdptr_get (booster_fdtable, fd); - -        gf_log ("booster", GF_LOG_TRACE, "fcntl: fd %d, cmd %d", fd, cmd); -	switch (cmd) { -	case F_DUPFD: -                ret = dup (fd); -                break; -                /*  -                 * FIXME: Consider this case when implementing F_DUPFD, F_GETFD -                 *        etc flags in libglusterfsclient. Commenting it out for -                 *        timebeing since it is defined only in linux kernel  -                 *        versions >= 2.6.24. -                 */ -                /* case F_DUPFD_CLOEXEC: */ -	case F_GETFD: -                if (glfs_fd != NULL) { -                        ret = booster_get_close_on_exec (booster_fdtable, fd) -                                ? FD_CLOEXEC : 0; -                } else { -                        if (real_fcntl == NULL) { -                                ret = -1; -                                errno = ENOSYS; -                        } else { -                                ret = real_fcntl (fd, cmd); -                        } -                } -                break; - -	case F_GETFL: -	case F_GETOWN: -	case F_GETSIG: -	case F_GETLEASE: -                if (glfs_fd) { -                        gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                        ret = glusterfs_fcntl (glfs_fd, cmd); -                } else { -                        if (!real_fcntl) { -                                errno = ENOSYS; -                                goto out; -                        } - -                        gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                        ret = real_fcntl (fd, cmd); -                } -		break; - -	case F_SETFD: -                if (glfs_fd != NULL) { -                        booster_set_close_on_exec (booster_fdtable, fd); -                        ret = 0; -                } else { -                        if (real_fcntl == NULL) { -                                ret = -1; -                                errno = ENOSYS; -                        } else { -                                ret = real_fcntl (fd, cmd); -                        } -                } -                break; - -	case F_SETFL: -	case F_SETOWN: -	case F_SETSIG: -	case F_SETLEASE: -	case F_NOTIFY: -                va_start (ap, cmd); -                arg = va_arg (ap, long); -                va_end (ap); - -                if (glfs_fd) { -                        gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                        ret = glusterfs_fcntl (glfs_fd, cmd, arg); -                } else { -                        if (!real_fcntl) { -                                errno = ENOSYS; -                                goto out; -                        } - -                        gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                        ret = real_fcntl (fd, cmd, arg); -                } -		break; - -	case F_GETLK: -	case F_SETLK: -	case F_SETLKW: -#if F_GETLK != F_GETLK64  -        case F_GETLK64: -#endif -#if F_SETLK != F_SETLK64 -        case F_SETLK64: -#endif -#if F_SETLKW != F_SETLKW64 -        case F_SETLKW64: -#endif -                va_start (ap, cmd); -                lock = va_arg (ap, struct flock *); -                va_end (ap); - -                if (lock == NULL) { -                        errno = EINVAL; -                        goto out; -                } - -                if (glfs_fd) { -                        gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                        ret = glusterfs_fcntl (glfs_fd, cmd, lock); -                } else { -                        if (!real_fcntl) { -                                errno = ENOSYS; -                                goto out; -                        } - -                        gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                        ret = real_fcntl (fd, cmd, lock); -                } -		break; - -	default: -                errno = EINVAL; -		break; -	} - -out: -        if (glfs_fd) { -                booster_fdptr_put (glfs_fd); -        } - -        return ret; -} - - -int -chdir (const char *path) -{ -        int     ret = -1; -        char    cwd[PATH_MAX]; -        char   *res = NULL; - -        gf_log ("booster", GF_LOG_TRACE, "chdir: path %s", path); - -        pthread_mutex_lock (&cwdlock); -        { -                res = glusterfs_getcwd (cwd, PATH_MAX); -                if (res == NULL) { -                        gf_log ("booster", GF_LOG_ERROR, "getcwd failed: %s", -                                strerror (errno)); -                        goto unlock; -                } - -                ret = glusterfs_chdir (path); -                if ((ret == -1) && (errno != ENODEV)) { -                        gf_log ("booster", GF_LOG_ERROR, "chdir failed: %s", -                                strerror (errno)); -                        goto unlock; -                } - -                if (ret == 0) { -                        gf_log ("booster", GF_LOG_TRACE, "chdir succeeded"); -                        goto unlock; -                } - -                if (real_chdir == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                        goto unlock; -                } - -                ret = real_chdir (path); -                if (ret == -1) { -                        glusterfs_chdir (cwd); -                } -        } -unlock: -        pthread_mutex_unlock (&cwdlock); - -        return ret; -} - - -int -fchdir (int fd) -{ -        int              ret     = -1; -        glusterfs_file_t glfs_fd = 0; -        char             cwd[PATH_MAX];  -        char            *res     = NULL; - -        glfs_fd = booster_fdptr_get (booster_fdtable, fd); - -        if (!glfs_fd) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_write == NULL) { -                        errno = ENOSYS; -                        ret = -1; -                } else { -                        ret = real_fchdir (fd); -                        if (ret == 0) { -                                res = real_getcwd (cwd, PATH_MAX); -                                if (res == NULL) { -                                        gf_log ("booster", GF_LOG_ERROR, -                                                "getcwd failed (%s)", -                                                strerror (errno)); -                                        ret = -1; -                                } else { -                                        glusterfs_chdir (cwd); -                                } -                        } -                } -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_fchdir (glfs_fd); -                booster_fdptr_put (glfs_fd); -        } -  -        return ret; -} - - -char * -getcwd (char *buf, size_t size) -{ -        char *res = NULL; - -        res = glusterfs_getcwd (buf, size); -        if ((res == NULL) && (errno == ENODEV)) { -                res = real_getcwd (buf, size); -        } - -        return res; -} - - -int __REDIRECT (booster_false_truncate, (const char *path, off_t length), -                truncate) __nonnull ((1)); -int __REDIRECT (booster_false_truncate64, (const char *path, loff_t length), -                truncate64) __nonnull ((1));; - -int -booster_false_truncate (const char *path, off_t length) -{ -        int             ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "truncate: path (%s) length (%"PRIu64 -                ")", path, length); - -        ret = glusterfs_truncate (path, length); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "truncate failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "truncate succeeded"); -                goto out; -        } - -        if (real_truncate != NULL) -                ret = real_truncate (path, length); -        else { -                errno = ENOSYS; -                ret = -1; -                goto out; -        } - -out: -        return ret; -} - - -int -booster_false_truncate64 (const char *path, loff_t length) -{ -        int             ret = -1; -   -        gf_log ("booster", GF_LOG_TRACE, "truncate64: path (%s) length " -                "(%"PRIu64")", path, length); - -        ret = glusterfs_truncate (path, length); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "truncate64 failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "truncate64 succeeded"); -                goto out; -        } - -        if (real_truncate64 != NULL) -                ret = real_truncate64 (path, length); -        else { -                errno = ENOSYS; -                ret = -1; -                goto out; -        } - -out: -        return ret; -} - - -int -setxattr (const char *path, const char *name, const void *value, size_t size, -          int flags) -{ -        int             ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "setxattr: path: %s", path); -        ret = glusterfs_setxattr (path, name, value, size, flags); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "setxattr failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "setxattr succeeded"); -                goto out; -        } - -        if (real_setxattr != NULL) -                ret = real_setxattr (path, name, value, size, flags); -        else { -                errno = ENOSYS; -                ret = -1; -                goto out; -        } - -out: -        return ret; -} - - -int -lsetxattr (const char *path, const char *name, const void *value, size_t size, -           int flags) -{ -        int             ret = -1; - -        gf_log ("booster", GF_LOG_TRACE, "lsetxattr: path: %s", path); -        ret = glusterfs_lsetxattr (path, name, value, size, flags); -        if ((ret == -1) && (errno != ENODEV)) { -                gf_log ("booster", GF_LOG_ERROR, "lsetxattr failed: %s", -                        strerror (errno)); -                goto out; -        } - -        if (ret == 0) { -                gf_log ("booster", GF_LOG_TRACE, "lsetxattr succeeded"); -                goto out; -        } - -        if (real_lsetxattr != NULL) -                ret = real_lsetxattr (path, name, value, size, flags); -        else { -                errno = ENOSYS; -                ret = -1; -                goto out; -        } - -out: -        return ret; -} - - -int -fsetxattr (int fd, const char *name, const void *value, size_t size, int flags) -{ -        int                     ret = -1; -        glusterfs_file_t        fh = NULL; - -        gf_log ("booster", GF_LOG_TRACE, "fsetxattr: fd %d", fd); -        fh = booster_fdptr_get (booster_fdtable, fd); -        if (!fh) { -                gf_log ("booster", GF_LOG_TRACE, "Not a booster fd"); -                if (real_fsetxattr != NULL) -                        ret = real_fsetxattr (fd, name, value, size, flags); -                else { -                        ret = -1; -                        errno = ENOSYS; -                        goto out; -                } -        } else { -                gf_log ("booster", GF_LOG_TRACE, "Is a booster fd"); -                ret = glusterfs_fsetxattr (fh, name, value, size, flags); -                booster_fdptr_put (fh); -        } - -out: -        return ret; -} - - -void -booster_lib_init (void) -{ - -        RESOLVE (open); -        RESOLVE (open64); -        RESOLVE (creat); -        RESOLVE (creat64); - -        RESOLVE (read); -        RESOLVE (readv); -        RESOLVE (pread); -        RESOLVE (pread64); - -        RESOLVE (write); -        RESOLVE (writev); -        RESOLVE (pwrite); -        RESOLVE (pwrite64); - -        RESOLVE (lseek); -        RESOLVE (lseek64); - -        RESOLVE (close); - -        RESOLVE (dup); -        RESOLVE (dup2); - -	RESOLVE (fork);  -        RESOLVE (mkdir); -        RESOLVE (rmdir); -        RESOLVE (chmod); -        RESOLVE (chown); -        RESOLVE (fchmod); -        RESOLVE (fchown); -        RESOLVE (fsync); -        RESOLVE (ftruncate); -        RESOLVE (ftruncate64); -        RESOLVE (link); -        RESOLVE (rename); -        RESOLVE (utimes); -        RESOLVE (utime); -        RESOLVE (mknod); -        RESOLVE (mkfifo); -        RESOLVE (unlink); -        RESOLVE (symlink); -        RESOLVE (readlink); -        RESOLVE (realpath); -        RESOLVE (opendir); -        RESOLVE (readdir); -        RESOLVE (readdir64); -        RESOLVE (closedir); -        RESOLVE (__xstat); -        RESOLVE (__xstat64); -        RESOLVE (stat); -        RESOLVE (stat64); -        RESOLVE (__fxstat); -        RESOLVE (__fxstat64); -        RESOLVE (fstat); -        RESOLVE (fstat64); -        RESOLVE (__lxstat); -        RESOLVE (__lxstat64); -        RESOLVE (lstat); -        RESOLVE (lstat64); -        RESOLVE (statfs); -        RESOLVE (statfs64); -        RESOLVE (statvfs); -        RESOLVE (statvfs64); -        RESOLVE (getxattr); -        RESOLVE (lgetxattr); -        RESOLVE (remove); -        RESOLVE (lchown); -	RESOLVE (rewinddir); -	RESOLVE (seekdir); -	RESOLVE (telldir); -        RESOLVE (sendfile); -        RESOLVE (sendfile64); -        RESOLVE (readdir_r); -        RESOLVE (readdir64_r); -        RESOLVE (fcntl); -        RESOLVE (chdir); -        RESOLVE (fchdir); -        RESOLVE (getcwd); -        RESOLVE (truncate); -        RESOLVE (truncate64); -        RESOLVE (setxattr); -        RESOLVE (lsetxattr); -        RESOLVE (fsetxattr); - -        /* This must be called after resolving real functions -         * above so that the socket based IO calls in libglusterfsclient -         * can fall back to a non-NULL real_XXX function pointer. -         * Calling booster_init before resolving the names above -         * results in seg-faults because the function symbols above are NULL. -         */ -	booster_init (); -} - diff --git a/booster/src/booster_fstab.c b/booster/src/booster_fstab.c deleted file mode 100644 index 202249cadf3..00000000000 --- a/booster/src/booster_fstab.c +++ /dev/null @@ -1,452 +0,0 @@ -/* Utilities for reading/writing fstab, mtab, etc. -   Copyright (C) 1995-2000, 2001, 2002, 2003, 2006 -   Free Software Foundation, Inc. -   This file is part of the GNU C Library. - -   The GNU C Library is free software; you can redistribute it and/or -   modify it under the terms of the GNU Lesser General Public -   License as published by the Free Software Foundation; either -   version 2.1 of the License, or (at your option) any later version. - -   The GNU C Library is distributed in the hope that it will be useful, -   but WITHOUT ANY WARRANTY; without even the implied warranty of -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -   Lesser General Public License for more details. - -   You should have received a copy of the GNU Lesser General Public -   License along with the GNU C Library; if not, write to the Free -   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -   02111-1307 USA.  */ - -#include <alloca.h> -#include <stdio.h> -#include <string.h> -#include <sys/types.h> -#include "booster_fstab.h" -#include <stdlib.h> -#include <libglusterfsclient.h> -#include <errno.h> - -/* The default timeout for inode and stat cache. */ -#define BOOSTER_DEFAULT_ATTR_TIMEO      5 /* In Secs */ - -/* Prepare to begin reading and/or writing mount table entries from the -   beginning of FILE.  MODE is as for `fopen'.  */ -glusterfs_fstab_t * -glusterfs_fstab_init (const char *file, const char *mode) -{ -        glusterfs_fstab_t *handle = NULL; -        handle = calloc (1, sizeof (glusterfs_fstab_t)); -        if (!handle) { -                gf_log ("booster-fstab", GF_LOG_ERROR, "Memory allocation" -                        " failed"); -                goto out; -        } - -        gf_log ("booster-fstab", GF_LOG_DEBUG, "FSTAB file: %s", file); -        FILE *result = fopen (file,mode); -        if (result != NULL) { -                handle->fp = result; -        } else { -                gf_log ("booster-fstab", GF_LOG_ERROR, "FSTAB file open failed:" -                        " %s", strerror (errno)); -                free (handle); -                handle = NULL; -        } - -out: - -        return handle; -} - -int -glusterfs_fstab_close (glusterfs_fstab_t *h) -{ -        if (!h) -                return -1; - -        if (h->fp) -                fclose (h->fp); - -        return 0; -} - -/* Since the values in a line are separated by spaces, a name cannot -   contain a space.  Therefore some programs encode spaces in names -   by the strings "\040".  We undo the encoding when reading an entry. -   The decoding happens in place.  */ -static char * -decode_name (char *buf) -{ -        char *rp = buf; -        char *wp = buf; - -        do -                if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '4' -                                && rp[3] == '0') -                { -                        /* \040 is a SPACE.  */ -                        *wp++ = ' '; -                        rp += 3; -                } -                else if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '1' -                                && rp[3] == '1') -                { -                        /* \011 is a TAB.  */ -                        *wp++ = '\t'; -                        rp += 3; -                } -                else if (rp[0] == '\\' && rp[1] == '0' && rp[2] == '1' -                                && rp[3] == '2') -                { -                        /* \012 is a NEWLINE.  */ -                        *wp++ = '\n'; -                        rp += 3; -                } -                else if (rp[0] == '\\' && rp[1] == '\\') -                { -                        /* We have to escape \\ to be able to represent all -                         * characters.  */ -                        *wp++ = '\\'; -                        rp += 1; -                } -                else if (rp[0] == '\\' && rp[1] == '1' && rp[2] == '3' -                                && rp[3] == '4') -                { -                        /* \134 is also \\.  */ -                        *wp++ = '\\'; -                        rp += 3; -                } -                else -                        *wp++ = *rp; -        while (*rp++ != '\0'); - -        return buf; -} - - -/* Read one mount table entry from STREAM.  Returns a pointer to storage -   reused on the next call, or null for EOF or error (use feof/ferror to -   check).  */ -struct glusterfs_mntent * -__glusterfs_fstab_getent (FILE *stream, struct glusterfs_mntent *mp, -                          char *buffer, int bufsiz) -{ -        char *cp; -        char *head; - -        do -        { -                char *end_ptr; - -                if (fgets (buffer, bufsiz, stream) == NULL) -                { -                        return NULL; -                } - -                end_ptr = strchr (buffer, '\n'); -                if (end_ptr != NULL)	/* chop newline */ -                        *end_ptr = '\0'; -                else -                { -                        /* Not the whole line was read.  Do it now but forget -                         * it.  */ -                        char tmp[1024]; -                        while (fgets (tmp, sizeof tmp, stream) != NULL) -                                if (strchr (tmp, '\n') != NULL) -                                        break; -                } - -                head = buffer + strspn (buffer, " \t"); -                /* skip empty lines and comment lines:  */ -        } -        while (head[0] == '\0' || head[0] == '#'); - -        cp = strsep (&head, " \t"); -        mp->mnt_fsname = cp != NULL ? decode_name (cp) : (char *) ""; -        if (head) -                head += strspn (head, " \t"); -        cp = strsep (&head, " \t"); -        mp->mnt_dir = cp != NULL ? decode_name (cp) : (char *) ""; -        if (head) -                head += strspn (head, " \t"); -        cp = strsep (&head, " \t"); -        mp->mnt_type = cp != NULL ? decode_name (cp) : (char *) ""; -        if (head) -                head += strspn (head, " \t"); -        cp = strsep (&head, " \t"); -        mp->mnt_opts = cp != NULL ? decode_name (cp) : (char *) ""; -        switch (head ? sscanf (head, " %d %d ", &mp->mnt_freq, -                               &mp->mnt_passno) : 0) -        { -                case 0: -                        mp->mnt_freq = 0; -                case 1: -                        mp->mnt_passno = 0; -                case 2: -                        break; -        } - -        return mp; -} - -struct glusterfs_mntent * -glusterfs_fstab_getent (glusterfs_fstab_t *h) -{ -        if (!h) -                return NULL; - -        if (!h->fp) -                return NULL; - -        return __glusterfs_fstab_getent (h->fp, &h->tmpent, h->buf, -                                         GF_MNTENT_BUFSIZE); -} - -/* We have to use an encoding for names if they contain spaces or tabs. -   To be able to represent all characters we also have to escape the -   backslash itself.  This "function" must be a macro since we use -   `alloca'.  */ -#define encode_name(name)                                               \ -        do {                                                            \ -                const char *rp = name;		                        \ -                                                                        \ -                while (*rp != '\0')     	                        \ -                        if (*rp == ' ' || *rp == '\t' || *rp == '\\')   \ -                                break;                                  \ -                        else	                                        \ -                                ++rp;                                   \ -                                                                        \ -                if (*rp != '\0')                                        \ -                {                                               \ -                /* In the worst case the length of the string   \ -                 * can increase to four times the current       \ -                 * length.  */				        \ -                        char *wp;				\ -                                                                \ -                        rp = name;				\ -                        name = wp = (char *) alloca (strlen (name) * 4 + 1);                                                                 \ -                                                                \ -                        do {                            \ -                                if (*rp == ' ')		\ -                                {       		\ -                                        *wp++ = '\\';   \ -                                        *wp++ = '0';	\ -                                        *wp++ = '4';	\ -                                        *wp++ = '0';    \ -                                }			\ -                                else if (*rp == '\t')	\ -                                {			\ -                                        *wp++ = '\\';	\ -                                        *wp++ = '0';	\ -                                        *wp++ = '1';	\ -                                        *wp++ = '1';	\ -                                }			\ -                                else if (*rp == '\n')	\ -                                {	                \ -                                        *wp++ = '\\';	\ -                                        *wp++ = '0';	\ -                                        *wp++ = '1';	\ -                                        *wp++ = '2';	\ -                                }	                \ -                                else if (*rp == '\\')	\ -                                {                       \ -                                        *wp++ = '\\';	\ -                                        *wp++ = '\\';	\ -                                }                       \ -                                else	                \ -                                        *wp++ = *rp;	\ -                        } while (*rp++ != '\0');	\ -                }                                       \ -        } while (0)                                     \ - - -int -glusterfs_fstab_addent (glusterfs_fstab_t *h, -                const struct glusterfs_mntent *mnt) -{ -        struct glusterfs_mntent mntcopy = *mnt; -        if (!h) -                return -1; - -        if (!h->fp) -                return -1; - -        if (fseek (h->fp, 0, SEEK_END)) -                return -1; - -        /* Encode spaces and tabs in the names.  */ -        encode_name (mntcopy.mnt_fsname); -        encode_name (mntcopy.mnt_dir); -        encode_name (mntcopy.mnt_type); -        encode_name (mntcopy.mnt_opts); - -        return (fprintf (h->fp, "%s %s %s %s %d %d\n", -                                mntcopy.mnt_fsname, -                                mntcopy.mnt_dir, -                                mntcopy.mnt_type, -                                mntcopy.mnt_opts, -                                mntcopy.mnt_freq, -                                mntcopy.mnt_passno) -                        < 0 ? 1 : 0); -} - - -/* Search MNT->mnt_opts for an option matching OPT. -   Returns the address of the substring, or null if none found.  */ -char * -glusterfs_fstab_hasoption (const struct glusterfs_mntent *mnt, const char *opt) -{ -        const size_t optlen = strlen (opt); -        char *rest = mnt->mnt_opts, *p; - -        while ((p = strstr (rest, opt)) != NULL) -        { -                if ((p == rest || p[-1] == ',') -                                && (p[optlen] == '\0' || p[optlen] == '=' || p[optlen] == ',')) -                        return p; - -                rest = strchr (p, ','); -                if (rest == NULL) -                        break; -                ++rest; -        } - -        return NULL; -} - -void -clean_init_params (glusterfs_init_params_t *ipars) -{ -        if (!ipars) -                return; - -        if (ipars->volume_name) -                free (ipars->volume_name); - -        if (ipars->specfile) -                free (ipars->specfile); - -        if (ipars->logfile) -                free (ipars->logfile); - -        if (ipars->loglevel) -                free (ipars->loglevel); - -        return; -} - -char * -get_option_value (char *opt) -{ -        char *val = NULL; -        char *saveptr = NULL; -        char *copy_opt = NULL; -        char *retval = NULL; - -        copy_opt = strdup (opt); - -        /* Get the = before the value of the option. */ -        val = index (copy_opt, '='); -        if (val) { -                /* Move to start of option */ -                ++val; - -                /* Now, to create a '\0' delimited string out of the -                 * options string, first get the position where the -                 * next option starts, that would be the next ','. -                 */ -                saveptr = index (val, ','); -                if (saveptr) -                        *saveptr = '\0'; -                retval = strdup (val); -        } - -        free (copy_opt); - -        return retval; -} - -void -booster_mount (struct glusterfs_mntent *ent) -{ -        char                    *opt = NULL; -        glusterfs_init_params_t ipars; -        time_t                  timeout = BOOSTER_DEFAULT_ATTR_TIMEO; -        char                    *timeostr = NULL; -        char                    *endptr = NULL; - -        if (!ent) -                return; - -        gf_log ("booster-fstab", GF_LOG_DEBUG, "Mount entry: volfile: %s," -                " VMP: %s, Type: %s, Options: %s", ent->mnt_fsname, -                ent->mnt_dir, ent->mnt_type, ent->mnt_opts); -        if ((strcmp (ent->mnt_type, "glusterfs") != 0)) { -                gf_log ("booster-fstab", GF_LOG_ERROR, "Type is not glusterfs"); -                return; -        } - -        memset (&ipars, 0, sizeof (glusterfs_init_params_t)); -        if (ent->mnt_fsname) -                ipars.specfile = strdup (ent->mnt_fsname); - -        opt = glusterfs_fstab_hasoption (ent, "subvolume"); -        if (opt) -                ipars.volume_name = get_option_value (opt); - -        opt = glusterfs_fstab_hasoption (ent, "log-file"); -        if (!opt) -                opt = glusterfs_fstab_hasoption (ent, "logfile"); - -        if (opt) -                ipars.logfile = get_option_value (opt); - -        opt = glusterfs_fstab_hasoption (ent, "log-level"); -        if (!opt) -                opt = glusterfs_fstab_hasoption (ent, "loglevel"); - -        if (opt) -                ipars.loglevel = get_option_value (opt); - -        /* Attribute cache timeout */ -        opt = glusterfs_fstab_hasoption (ent, "attr_timeout"); -        if (opt) { -                 timeostr = get_option_value (opt); -                 if (timeostr) -                         timeout = strtol (timeostr, &endptr, 10); -        } - -        ipars.lookup_timeout = timeout; -        ipars.stat_timeout = timeout; - -        if ((glusterfs_mount (ent->mnt_dir, &ipars)) == -1) -                gf_log ("booster-fstab", GF_LOG_ERROR, "VMP mounting failed"); - -        clean_init_params (&ipars); -} - -int -booster_configure (char *confpath) -{ -        int                     ret = -1; -        glusterfs_fstab_t       *handle = NULL; -        struct glusterfs_mntent *ent = NULL; - -        if (!confpath) -                goto out; - -        handle = glusterfs_fstab_init (confpath, "r"); -        if (!handle) -                goto out; - -        while ((ent = glusterfs_fstab_getent (handle)) != NULL) -                booster_mount (ent); - -        glusterfs_fstab_close (handle); -        ret = 0; -out: -        return ret; -} - - diff --git a/booster/src/booster_fstab.h b/booster/src/booster_fstab.h deleted file mode 100644 index 9bab04c5aa0..00000000000 --- a/booster/src/booster_fstab.h +++ /dev/null @@ -1,83 +0,0 @@ -/* Utilities for reading/writing fstab, mtab, etc. -   Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc. -   This file is part of the GNU C Library. - -   The GNU C Library is free software; you can redistribute it and/or -   modify it under the terms of the GNU Lesser General Public -   License as published by the Free Software Foundation; either -   version 2.1 of the License, or (at your option) any later version. - -   The GNU C Library is distributed in the hope that it will be useful, -   but WITHOUT ANY WARRANTY; without even the implied warranty of -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -   Lesser General Public License for more details. - -   You should have received a copy of the GNU Lesser General Public -   License along with the GNU C Library; if not, write to the Free -   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -   02111-1307 USA.  */ - -#ifndef	GLUSTERFS_FSTAB_MNTENT_H -#define	GLUSTERFS_FSTAB_MNTENT_H	1 -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif -  -#include "compat.h" - -/* General filesystem types.  */ -#define GF_MNTTYPE_IGNORE	"ignore"	/* Ignore this entry.  */ -#define GF_MNTTYPE_NFS	"nfs"		/* Network file system.  */ -#define GF_MNTTYPE_SWAP	"swap"		/* Swap device.  */ - - -/* Generic mount options.  */ -#define GF_MNTOPT_DEFAULTS	"defaults"	/* Use all default options.  */ -#define GF_MNTOPT_RO	        "ro"		/* Read only.  */ -#define GF_MNTOPT_RW	        "rw"		/* Read/write.  */ -#define GF_MNTOPT_SUID	        "suid"		/* Set uid allowed.  */ -#define GF_MNTOPT_NOSUID	"nosuid"	/* No set uid allowed.  */ -#define GF_MNTOPT_NOAUTO	"noauto"	/* Do not auto mount.  */ - - -/* Structure describing a mount table entry.  */ -struct glusterfs_mntent -{ -        char *mnt_fsname;		/* Device or server for filesystem.  */ -        char *mnt_dir;		/* Directory mounted on.  */ -        char *mnt_type;		/* Type of filesystem: ufs, nfs, etc.  */ -        char *mnt_opts;		/* Comma-separated options for fs.  */ -        int mnt_freq;		/* Dump frequency (in days).  */ -        int mnt_passno;		/* Pass number for `fsck'.  */ -}; - -#define GF_MNTENT_BUFSIZE       1024 -typedef struct glusterfs_fstab_handle { -        FILE *fp; -        char buf[GF_MNTENT_BUFSIZE]; -        struct glusterfs_mntent tmpent; -}glusterfs_fstab_t; - - -/* Prepare to begin reading and/or writing mount table entries from the -   beginning of FILE.  MODE is as for `fopen'.  */ -extern glusterfs_fstab_t *glusterfs_fstab_init (const char *file, -                const char *mode); - -extern struct glusterfs_mntent *glusterfs_fstab_getent (glusterfs_fstab_t *h); - -/* Write the mount table entry described by MNT to STREAM. -   Return zero on success, nonzero on failure.  */ -extern int glusterfs_fstab_addent (glusterfs_fstab_t *h, -                const struct glusterfs_mntent *mnt); - -/* Close a stream opened with `glusterfs_fstab_init'.  */ -extern int glusterfs_fstab_close (glusterfs_fstab_t *h); - -/* Search MNT->mnt_opts for an option matching OPT. -   Returns the address of the substring, or null if none found.  */ -extern char *glusterfs_fstab_hasoption (const struct glusterfs_mntent *mnt, -                const char *opt); - -#endif diff --git a/booster/src/booster_stat.c b/booster/src/booster_stat.c deleted file mode 100644 index 8f76cfe37dd..00000000000 --- a/booster/src/booster_stat.c +++ /dev/null @@ -1,188 +0,0 @@ -/* -   Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> -   This file is part of GlusterFS. - -   GlusterFS is free software; you can redistribute it and/or modify -   it under the terms of the GNU General Public License as published -   by the Free Software Foundation; either version 3 of the License, -   or (at your option) any later version. - -   GlusterFS is distributed in the hope that it will be useful, but -   WITHOUT ANY WARRANTY; without even the implied warranty of -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -   General Public License for more details. - -   You should have received a copy of the GNU General Public License -   along with this program.  If not, see -   <http://www.gnu.org/licenses/>. -*/ - -#include <sys/types.h> - -extern int -booster_stat (const char *path, void *buf); - -extern int -booster_stat64 (const char *path, void *buf); - -extern int -booster_xstat (int ver, const char *path, void *buf); - -extern int -booster_xstat64 (int ver, const char *path, void *buf); - -extern int -booster_fxstat (int ver, int fd, void *buf); -extern int -booster_fxstat64 (int ver, int fd, void *buf); -extern int -booster_fstat (int fd, void *buf); -extern int -booster_fstat64 (int fd, void *buf); - -extern int -booster_lstat (const char *path, void *buf); -extern int -booster_lstat64 (const char *path, void *buf); -extern int -booster_lxstat (int ver, const char *path, void *buf); -extern int -booster_lxstat64 (int ver, const char *path, void *buf); - - -extern int -booster_statfs (const char *path, void *buf); -extern int -booster_statfs64 (const char *path, void *buf); - -extern int -booster_statvfs (const char *path, void *buf); - -extern int -booster_statvfs64 (const char *path, void *buf); - -extern void * -booster_readdir (void *dir); - -extern void -booster_rewinddir (void *dir); - -extern void -booster_seekdir (void *dir, off_t offset); - -extern off_t -booster_telldir (void *dir); - -int -stat (const char *path, void *buf) -{ -        return booster_stat (path, buf); -} - -int -stat64 (const char *path, void *buf) -{ -        return booster_stat64 (path, buf); -} - -int -__xstat (int ver, const char *path, void *buf) -{ -        return booster_xstat (ver, path, buf); -} - -int -__xstat64 (int ver, const char *path, void *buf) -{ -        return booster_xstat64 (ver, path, buf); -} - -int -__fxstat (int ver, int fd, void *buf) -{ -        return booster_fxstat (ver, fd, buf); -} - -int -__fxstat64 (int ver, int fd, void *buf) -{ -        return booster_fxstat64 (ver, fd, buf); -} - -int -fstat (int fd, void *buf) -{ -        return booster_fstat (fd, buf); -} - -int -fstat64 (int fd, void *buf) -{ -        return booster_fstat64 (fd, buf); -} - -int -lstat (const char *path, void *buf) -{ -        return booster_lstat (path, buf); -} - -int -lstat64 (const char *path, void *buf) -{ -        return booster_lstat64 (path, buf); -} - -int -__lxstat (int ver, const char *path, void *buf) -{ -        return booster_lxstat (ver, path, buf); -} - -int -__lxstat64 (int ver, const char *path, void *buf) -{ -        return booster_lxstat64 (ver, path, buf); -} - -int -statfs (const char *pathname, void *buf) -{ -        return booster_statfs (pathname, buf); -} - -int -statfs64 (const char *pathname, void *buf) -{ -        return booster_statfs64 (pathname, buf); -} - -int -statvfs (const char *pathname, void *buf) -{ -        return booster_statvfs (pathname, buf); -} - -int -statvfs64 (const char *pathname, void *buf) -{ -        return booster_statvfs64 (pathname, buf); -} - -void -rewinddir (void *dir) -{ -	return booster_rewinddir (dir); -} - -void -seekdir (void *dir, off_t offset) -{ -	return booster_seekdir (dir, offset); -} - -off_t -telldir (void *dir) -{ -	return booster_telldir (dir); -} diff --git a/mod_glusterfs/Makefile.am b/mod_glusterfs/Makefile.am deleted file mode 100644 index 0abe8dcfcbb..00000000000 --- a/mod_glusterfs/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = apache lighttpd - -CLEANFILES =  diff --git a/mod_glusterfs/apache/1.3/Makefile.am b/mod_glusterfs/apache/1.3/Makefile.am deleted file mode 100644 index d471a3f9243..00000000000 --- a/mod_glusterfs/apache/1.3/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = src - -CLEANFILES =  diff --git a/mod_glusterfs/apache/1.3/src/Makefile.am b/mod_glusterfs/apache/1.3/src/Makefile.am deleted file mode 100644 index 6bb3075f564..00000000000 --- a/mod_glusterfs/apache/1.3/src/Makefile.am +++ /dev/null @@ -1,30 +0,0 @@ -mod_glusterfs_PROGRAMS = mod_glusterfs.so -mod_glusterfsdir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/apache/1.3 - -mod_glusterfs_so_SOURCES = mod_glusterfs.c - -all: mod_glusterfs.so - -mod_glusterfs.so: $(top_srcdir)/mod_glusterfs/apache/1.3/src/mod_glusterfs.c $(top_builddir)/libglusterfsclient/src/libglusterfsclient.la -	ln -sf $(top_srcdir)/mod_glusterfs/apache/1.3/src/mod_glusterfs.c $(top_builddir)/mod_glusterfs/apache/1.3/src/mod_glusterfs-build.c -	$(APXS) -c -Wc,-g3 -Wc,-O0 -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -D_GNU_SOURCE -I$(top_srcdir)/libglusterfsclient/src -Wl,-rpath,$(libdir) -Wl,-rpath,$(top_builddir)/libglusterfsclient/src/.libs/ $(top_builddir)/libglusterfsclient/src/.libs/libglusterfsclient.so mod_glusterfs-build.c -o $(top_builddir)/mod_glusterfs/apache/1.3/src/mod_glusterfs.so - -$(top_builddir)/libglusterfsclient/src/libglusterfsclient.la: -	$(MAKE) -C $(top_builddir)/libglusterfsclient/src/ all - -install-data-local: -	@echo "" -	@echo "" -	@echo "**********************************************************************************" -	@echo "* TO INSTALL MODGLUSTERFS, PLEASE USE,                                            " -	@echo "* $(APXS) -n glusterfs -ia $(mod_glusterfsdir)/mod_glusterfs.so                   " -	@echo "**********************************************************************************" -	@echo "" -	@echo "" - -#install: -#	cp -fv mod_glusterfs.so $(HTTPD_LIBEXECDIR) -#	cp -fv httpd.conf $(HTTPD_CONF_DIR) - -clean: -	-rm -fv *.so *.o mod_glusterfs-build.c diff --git a/mod_glusterfs/apache/1.3/src/README.txt b/mod_glusterfs/apache/1.3/src/README.txt deleted file mode 100644 index 378a51d79ae..00000000000 --- a/mod_glusterfs/apache/1.3/src/README.txt +++ /dev/null @@ -1,107 +0,0 @@ -What is mod_glusterfs? -====================== -* mod_glusterfs is a module for apache written for efficient serving of files from glusterfs.  -  mod_glusterfs interfaces with glusterfs using apis provided by libglusterfsclient. - -* this README speaks about installation of apache-1.3.x, where x is any minor version. - -Prerequisites for mod_glusterfs -=============================== -Though mod_glusterfs has been written as a module, with an intent of making no changes to the way apache has  -been built, currently following points have to be taken care of: - -* module "so" has to be enabled, for apache to support modules. -* since glusterfs is compiled with _FILE_OFFSET_BITS=64 and __USE_FILE_OFFSET64 flags, mod_glusterfs and apache  -  in turn have to be compiled with the above two flags. -  - $ tar xzvf apache-1.3.9.tar.gz - $ cd apache-1.3.9/ - $ # add -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 to EXTRA_CFLAGS in src/Configuration. - $ ./configure --prefix=/usr --enable-module=so  - $ cd src - $ ./Configure  - $ cd ../ - $ make install   - $ httpd -l | grep -i mod_so  -   mod_so.c - -* if multiple apache installations are present, make sure to pass --with-apxs=/path/to/apxs/of/proper/version to configure script while building glusterfs. - -Build/Install mod_glusterfs -=========================== -* mod_glusterfs is provided with glusterfs--mainline--3.0 and all releases from the same branch. - -* building glusterfs also builds mod_glusterfs. But 'make install' of glusterfs installs mod_glusterfs.so to  -  glusterfs install directory instead of the apache modules directory. - -* 'make install' of glusterfs will print a message similar to the one given below, which is self explanatory.  -  Make sure to use apxs of proper apache version in case of multiple apache installations. This will copy  -  mod_glusterfs.so to modules directory of proper apache version and modify the appropriate httpd.conf to enable -  mod_glusterfs.  - -********************************************************************************************** -* TO INSTALL MODGLUSTERFS, PLEASE USE,                                             -* apxs -n mod_glusterfs -ia /usr/lib/glusterfs/1.4.0pre2/apache-1.3/mod_glusterfs.so                -********************************************************************************************** - -Configuration -============= -* Following configuration has to be added to httpd.conf. - - <Location "/glusterfs"> - 	   GlusterfsLogfile "/var/log/glusterfs/glusterfs.log" -	   GlusterfsLoglevel "warning" - 	   GlusterfsVolumeSpecfile "/etc/glusterfs/glusterfs-client.spec" -	   GlusterfsCacheTimeout "600" -	   GlusterfsXattrFileSize "65536" - 	   SetHandler "glusterfs-handler" - </Location> - -* GlusterfsVolumeSpecfile (COMPULSORY) -  Path to the the glusterfs volume specification file. - -* GlusterfsLogfile (COMPULSORY) -  Path to the glusterfs logfile. - -* GlusterfsLoglevel (OPTIONAL, default = warning) -  Severity of messages that are to be logged. Allowed values are critical, error, warning, debug, none  -  in the decreasing order of severity. - -* GlusterfsCacheTimeOut (OPTIONAL, default = 0) -  Timeout values for glusterfs stat and lookup cache. - -* GlusterfsXattrFileSize (OPTIONAL, default = 0) -  Files with sizes upto and including this value are fetched through the extended attribute interface of  -  glusterfs rather than the usual open-read-close set of operations. For files of small sizes, it is recommended  -  to use extended attribute interface. - -* With the above configuration all the requests to httpd of the form www.example.org/glusterfs/path/to/file are  -  served from glusterfs. - -Miscellaneous points -==================== -* httpd by default runs with username "nobody" and group "nogroup". Permissions of logfile and specfile have to  -  be set suitably. - -* Since mod_glusterfs runs with permissions of nobody.nogroup, glusterfs has to use only login based  -  authentication. See docs/authentication.txt for more details.  - -* To copy the data served by httpd into glusterfs mountpoint, glusterfs can be started with the  -  volume-specification file provided to mod_glusterfs. Any tool like cp can then be used. - -* To run in gdb, apache has to be compiled with -lpthread, since libglusterfsclient is multithreaded.  -  If not on Linux gdb runs into errors like:  -  "Error while reading shared library symbols: -   Cannot find new threads: generic error" - -* when used with ib-verbs transport, ib_verbs initialization fails. -  reason for this is that apache runs as non-privileged user and the amount of memory that can be  -  locked by default is not sufficient for ib-verbs. to fix this, as root run, -   -  # ulimit -l unlimited - -  and then start apache. -  -TODO -==== -* directory listing for the directories accessed through mod_glusterfs. diff --git a/mod_glusterfs/apache/1.3/src/mod_glusterfs.c b/mod_glusterfs/apache/1.3/src/mod_glusterfs.c deleted file mode 100644 index c1380a4fda6..00000000000 --- a/mod_glusterfs/apache/1.3/src/mod_glusterfs.c +++ /dev/null @@ -1,507 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef CORE_PRIVATE -#define CORE_PRIVATE -#endif - -#include <httpd.h> -#include <http_config.h> -#include <http_core.h> -#include <http_request.h> -#include <http_protocol.h> -#include <http_log.h> -#include <http_main.h> -#include <util_script.h> -#include <libglusterfsclient.h> -#include <sys/uio.h> -#include <pthread.h> - -#define GLUSTERFS_INVALID_LOGLEVEL "mod_glusterfs: Unrecognized log-level "\ -                                   "\"%s\", possible values are \"DEBUG|"\ -                                   "WARNING|ERROR|CRITICAL|NONE\"\n" - -#define GLUSTERFS_HANDLER "glusterfs-handler" -#define GLUSTERFS_CHUNK_SIZE 131072  - -module MODULE_VAR_EXPORT glusterfs_module; - -/*TODO: verify error returns to server core */ - -typedef struct glusterfs_dir_config { -        char *logfile; -        char *loglevel; -        char *specfile; -        char *mount_dir; -        char *buf; -        size_t xattr_file_size; -        uint32_t cache_timeout; -} glusterfs_dir_config_t; - -typedef struct glusterfs_async_local { -        int op_ret; -        int op_errno; -        char async_read_complete; -        off_t length; -        off_t read_bytes; -        glusterfs_iobuf_t *buf; -        request_rec *request; -        pthread_mutex_t lock; -        pthread_cond_t cond; -}glusterfs_async_local_t; - -#define GLUSTERFS_CMD_PERMS ACCESS_CONF - -static glusterfs_dir_config_t * -mod_glusterfs_dconfig(request_rec *r) -{ -        glusterfs_dir_config_t *dir_config = NULL; -        if (r->per_dir_config != NULL) { -                dir_config = ap_get_module_config (r->per_dir_config, -                                                   &glusterfs_module); -        } - -        return dir_config; -} - -static  -const char *add_xattr_file_size(cmd_parms *cmd, void *dummy, char *arg) -{ -        glusterfs_dir_config_t *dir_config = dummy; -        dir_config->xattr_file_size = atoi (arg); -        return NULL; -} - -static -const char *set_cache_timeout(cmd_parms *cmd, void *dummy, char *arg) -{ -        glusterfs_dir_config_t *dir_config = dummy; -        dir_config->cache_timeout = atoi (arg); -        return NULL; -} - -static -const char *set_loglevel(cmd_parms *cmd, void *dummy, char *arg) -{ -        glusterfs_dir_config_t *dir_config = dummy; -        char *error = NULL; -        if (strncasecmp (arg, "DEBUG", strlen ("DEBUG"))  -            && strncasecmp (arg, "WARNING", strlen ("WARNING"))  -            && strncasecmp (arg, "CRITICAL", strlen ("CRITICAL"))  -            && strncasecmp (arg, "NONE", strlen ("NONE"))  -            && strncasecmp (arg, "ERROR", strlen ("ERROR"))) -                error = GLUSTERFS_INVALID_LOGLEVEL; -        else -                dir_config->loglevel = arg; - -        return error; -} - -static  -const char *add_logfile(cmd_parms *cmd, void *dummy, char *arg) -{ -        glusterfs_dir_config_t *dir_config = dummy; -        dir_config->logfile = arg; - -        return NULL; -} - -static  -const char *add_specfile(cmd_parms *cmd, void *dummy, char *arg) -{ -        glusterfs_dir_config_t *dir_config = dummy; - -        dir_config->specfile = arg; - -        return NULL; -} - -static void * -mod_glusterfs_create_dir_config(pool *p, char *dirspec) -{ -        glusterfs_dir_config_t *dir_config = NULL; - -        dir_config = (glusterfs_dir_config_t *) ap_pcalloc(p, -                                                           sizeof(*dir_config)); - -        dir_config->mount_dir = dirspec; -        dir_config->logfile = dir_config->specfile = (char *)0; -        dir_config->loglevel = "warning"; -        dir_config->cache_timeout = 0; -        dir_config->buf = NULL; - -        return (void *) dir_config; -} - -static void  -mod_glusterfs_child_init(server_rec *s, pool *p) -{ -        void **urls = NULL; -        int n, i; -        core_server_config *mod_core_config = ap_get_module_config (s->module_config, -                                                                    &core_module); -        glusterfs_dir_config_t *dir_config = NULL; -        glusterfs_init_params_t params = {0, }; -   -        n = mod_core_config->sec_url->nelts; -        urls = (void **)mod_core_config->sec_url->elts; -        for (i = 0; i < n; i++) { -                dir_config = ap_get_module_config (urls[i], &glusterfs_module); - -                if (dir_config) { -                        memset (¶ms, 0, sizeof (params)); - -                        params.logfile = dir_config->logfile; -                        params.loglevel = dir_config->loglevel; -                        params.lookup_timeout = dir_config->cache_timeout; -                        params.stat_timeout = dir_config->cache_timeout; -                        params.specfile = dir_config->specfile; - -                        glusterfs_mount (dir_config->mount_dir, ¶ms); -                } -                dir_config = NULL; -        } -} - -static void  -mod_glusterfs_child_exit(server_rec *s, pool *p) -{ -        void **urls = NULL; -        int n, i; -        core_server_config *mod_core_config = NULL; -        glusterfs_dir_config_t *dir_config = NULL; -   -        mod_core_config = ap_get_module_config (s->module_config, &core_module); -        n = mod_core_config->sec_url->nelts; -        urls = (void **)mod_core_config->sec_url->elts; -        for (i = 0; i < n; i++) { -                dir_config = ap_get_module_config (urls[i], &glusterfs_module); -                if (dir_config) { -                        glusterfs_umount (dir_config->mount_dir); -                } -        } -} - -static int mod_glusterfs_fixup(request_rec *r) -{ -        glusterfs_dir_config_t *dir_config = NULL; -        int access_status; -        int ret; -        char *path = NULL; - -        dir_config = mod_glusterfs_dconfig(r); - -        if (dir_config && dir_config->mount_dir -            && !(strncmp (ap_pstrcat (r->pool, dir_config->mount_dir, "/", -                                      NULL), -                          r->uri, strlen (dir_config->mount_dir) + 1) -                 && !r->handler))  -                r->handler = ap_pstrdup (r->pool, GLUSTERFS_HANDLER); - -        if (!r->handler || (r->handler && strcmp (r->handler, -                                                  GLUSTERFS_HANDLER))) -                return DECLINED; - -        path = r->uri; - -        memset (&r->finfo, 0, sizeof (r->finfo)); - -        dir_config->buf = calloc (1, dir_config->xattr_file_size); -        if (!dir_config->buf) { -                return HTTP_INTERNAL_SERVER_ERROR; -        } - -        ret = glusterfs_get (path, dir_config->buf,  -                             dir_config->xattr_file_size, &r->finfo); - -        if (ret == -1 || r->finfo.st_size > dir_config->xattr_file_size -            || S_ISDIR (r->finfo.st_mode)) { -                free (dir_config->buf); -                dir_config->buf = NULL; - -                if (ret == -1) { -                        int error = HTTP_NOT_FOUND; -                        char *emsg = NULL; -                        if (r->path_info == NULL) { -                                emsg = ap_pstrcat(r->pool, strerror (errno), -                                                  r->filename, NULL); -                        } -                        else { -                                emsg = ap_pstrcat(r->pool, strerror (errno), -                                                  r->filename, r->path_info, -                                                  NULL); -                        } -                        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, r, -                                      "%s", emsg); -                        if (errno != ENOENT) { -                                error = HTTP_INTERNAL_SERVER_ERROR; -                        } -                        return error; -                } -        } -     -        if (r->uri && strlen (r->uri) && r->uri[strlen(r->uri) - 1] == '/')  -                r->handler = NULL; - -        r->filename = ap_pstrcat (r->pool, r->filename, r->path_info, NULL); - -        if ((access_status = ap_find_types(r)) != 0) { -                return DECLINED; -        } - -        return OK; -} - - -int  -mod_glusterfs_readv_async_cbk (int32_t op_ret, int32_t op_errno, -                               glusterfs_iobuf_t *buf, void *cbk_data) -{ -        glusterfs_async_local_t *local = cbk_data; - -        pthread_mutex_lock (&local->lock); -        { -                local->async_read_complete = 1; -                local->buf = buf; -                local->op_ret = op_ret; -                local->op_errno = op_errno; -                pthread_cond_signal (&local->cond); -        } -        pthread_mutex_unlock (&local->lock); - -        return 0; -} - -/* use read_async just to avoid memcpy of read buffer in libglusterfsclient */ -static int -mod_glusterfs_read_async (request_rec *r, glusterfs_file_t fd, off_t offset, -                          off_t length) -{ -        glusterfs_async_local_t local; -        off_t end; -        int nbytes; -        int complete; -        pthread_cond_init (&local.cond, NULL); -        pthread_mutex_init (&local.lock, NULL); -   -        memset (&local, 0, sizeof (local)); -        local.request = r; - -        if (length > 0) -                end = offset + length; - -        do { -                glusterfs_iobuf_t *buf; -                int i; -                if (length > 0) { -                        nbytes = end - offset; -                        if (nbytes > GLUSTERFS_CHUNK_SIZE) -                                nbytes = GLUSTERFS_CHUNK_SIZE; -                } else -                        nbytes = GLUSTERFS_CHUNK_SIZE; - -                glusterfs_read_async(fd,  -                                     nbytes, -                                     offset, -                                     mod_glusterfs_readv_async_cbk, -                                     (void *)&local); - -                pthread_mutex_lock (&local.lock); -                { -                        while (!local.async_read_complete) { -                                pthread_cond_wait (&local.cond, &local.lock); -                        } - -                        local.async_read_complete = 0; -                        buf = local.buf; - -                        if (length < 0) -                                complete = (local.op_ret <= 0); -                        else { -                                local.read_bytes += local.op_ret; -                                complete = ((local.read_bytes == length)  -                                            || (local.op_ret < 0)); -                        } -                } -                pthread_mutex_unlock (&local.lock); - -                for (i = 0; i < buf->count; i++) { -                        if (ap_rwrite (buf->vector[i].iov_base, -                                       buf->vector[i].iov_len, r) < 0) { -                                local.op_ret = -1; -                                complete = 1; -                                break; -                        } -                }       - -                glusterfs_free (buf); - -                offset += nbytes; -        } while (!complete); - -        return (local.op_ret < 0 ? SERVER_ERROR : OK); -} - -static int  -mod_glusterfs_handler(request_rec *r) -{ -        glusterfs_dir_config_t *dir_config; -        char *path = NULL; -        int error = OK; -        int rangestatus = 0; -        int errstatus = OK; -        glusterfs_file_t fd; -   -        if (!r->handler || (r->handler && strcmp (r->handler, -                                                  GLUSTERFS_HANDLER))) -                return DECLINED; - -        if (r->uri[0] == '\0' || r->uri[strlen(r->uri) - 1] == '/') { -                return DECLINED; -        } -   -        dir_config = mod_glusterfs_dconfig (r); -   -        if (r->method_number != M_GET) { -                return METHOD_NOT_ALLOWED; -        } - -        ap_update_mtime(r, r->finfo.st_mtime); -        ap_set_last_modified(r); -        ap_set_etag(r); -        ap_table_setn(r->headers_out, "Accept-Ranges", "bytes"); -        if (((errstatus = ap_meets_conditions(r)) != OK) -            || (errstatus = ap_set_content_length(r, r->finfo.st_size))) { -                return errstatus; -        } -        rangestatus =  ap_set_byterange(r); -        ap_send_http_header(r); - -        if (r->finfo.st_size <= dir_config->xattr_file_size && dir_config->buf) { -                if (!r->header_only) { -                        error = OK; -                        ap_log_rerror (APLOG_MARK, APLOG_NOTICE, r,  -                                       "fetching data from glusterfs through " -                                       "xattr interface\n"); -       -                        if (!rangestatus) { -                                if (ap_rwrite (dir_config->buf, -                                               r->finfo.st_size, r) < 0) { -                                        error = HTTP_INTERNAL_SERVER_ERROR; -                                } -                        } else { -                                long offset, length; -                                while (ap_each_byterange (r, &offset, &length)) { -                                        if (ap_rwrite (dir_config->buf + offset, -                                                       length, r) < 0) { -                                                error = HTTP_INTERNAL_SERVER_ERROR; -                                                break; -                                        } -                                } -                        } -                } - -                free (dir_config->buf); -                dir_config->buf = NULL; - -                return error; -        } - -        path = r->uri; -        fd = glusterfs_open (path , O_RDONLY, 0); -   -        if (fd == 0) { -                ap_log_rerror(APLOG_MARK, APLOG_ERR, r, -                              "file permissions deny server access: %s", -                              r->filename); -                return FORBIDDEN; -        } -   -        if (!r->header_only) { -                if (!rangestatus) { -                        mod_glusterfs_read_async (r, fd, 0, -1); -                } else { -                        long offset, length; -                        while (ap_each_byterange(r, &offset, &length)) { -                                mod_glusterfs_read_async (r, fd, offset, length); -                        } -                } -        } -   -        glusterfs_close (fd); -        return error; -} - -static const command_rec mod_glusterfs_cmds[] = -{ -        {"GlusterfsLogfile", add_logfile, NULL, -         GLUSTERFS_CMD_PERMS, TAKE1, -         "Glusterfs Logfile"}, -        {"GlusterfsLoglevel", set_loglevel, NULL, -         GLUSTERFS_CMD_PERMS, TAKE1, -         "Glusterfs Loglevel:anyone of none, critical, error, warning, debug"}, -        {"GlusterfsCacheTimeout", set_cache_timeout, NULL, -         GLUSTERFS_CMD_PERMS, TAKE1, -         "Timeout value in seconds for caching lookups and stats"}, -        {"GlusterfsVolumeSpecfile", add_specfile, NULL, -         GLUSTERFS_CMD_PERMS, TAKE1, -         "Glusterfs Specfile required to access contents of this directory"}, -        {"GlusterfsXattrFileSize", add_xattr_file_size, NULL,  -         GLUSTERFS_CMD_PERMS, TAKE1, -         "Maximum size of the file to be fetched using xattr interface of " -         "glusterfs"}, -        {NULL} -}; - -static const handler_rec mod_glusterfs_handlers[] = -{ -        {GLUSTERFS_HANDLER, mod_glusterfs_handler}, -        {NULL} -}; - -module glusterfs_module = -{ -        STANDARD_MODULE_STUFF, -        NULL,  -        mod_glusterfs_create_dir_config,  /* per-directory config creator */ -        NULL, -        NULL,       /* server config creator */ -        NULL,        /* server config merger */ -        mod_glusterfs_cmds,               /* command table */ -        mod_glusterfs_handlers,           /* [7] list of handlers */ -        NULL,  /* [2] filename-to-URI translation */ -        NULL,      /* [5] check/validate user_id */ -        NULL,       /* [6] check user_id is valid *here* */ -        NULL,     /* [4] check access by host address */ -        NULL,       /* [7] MIME type checker/setter */ -        mod_glusterfs_fixup,        /* [8] fixups */ -        NULL,             /* [10] logger */ -#if MODULE_MAGIC_NUMBER >= 19970103 -        NULL,      /* [3] header parser */ -#endif -#if MODULE_MAGIC_NUMBER >= 19970719 -        mod_glusterfs_child_init,         /* process initializer */ -#endif -#if MODULE_MAGIC_NUMBER >= 19970728 -        mod_glusterfs_child_exit,         /* process exit/cleanup */ -#endif -#if MODULE_MAGIC_NUMBER >= 19970902 -        NULL   /* [1] post read_request handling */ -#endif -}; diff --git a/mod_glusterfs/apache/2.2/Makefile.am b/mod_glusterfs/apache/2.2/Makefile.am deleted file mode 100644 index d471a3f9243..00000000000 --- a/mod_glusterfs/apache/2.2/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = src - -CLEANFILES =  diff --git a/mod_glusterfs/apache/2.2/src/Makefile.am b/mod_glusterfs/apache/2.2/src/Makefile.am deleted file mode 100644 index 1e8f3a31ea0..00000000000 --- a/mod_glusterfs/apache/2.2/src/Makefile.am +++ /dev/null @@ -1,31 +0,0 @@ -mod_glusterfs_PROGRAMS = mod_glusterfs.so -mod_glusterfsdir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/apache/2.2 - -mod_glusterfs_so_SOURCES = mod_glusterfs.c - -all: mod_glusterfs.so - -mod_glusterfs.so: $(top_srcdir)/mod_glusterfs/apache/2.2/src/mod_glusterfs.c $(top_builddir)/libglusterfsclient/src/libglusterfsclient.la -	ln -sf $(top_srcdir)/mod_glusterfs/apache/2.2/src/mod_glusterfs.c $(top_builddir)/mod_glusterfs/apache/2.2/src/mod_glusterfs-build.c -	$(APXS) -c -o mod_glusterfs.la -Wc,-g3 -Wc,-O0 -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -I$(top_srcdir)/libglusterfsclient/src -L$(top_builddir)/libglusterfsclient/src/.libs/ -lglusterfsclient mod_glusterfs-build.c  -	-ln -sf .libs/mod_glusterfs.so mod_glusterfs.so - -$(top_builddir)/libglusterfsclient/src/libglusterfsclient.la: -	$(MAKE) -C $(top_builddir)/libglusterfsclient/src/ all - -install-data-local: -	@echo "" -	@echo "" -	@echo "**********************************************************************************" -	@echo "* TO INSTALL MODGLUSTERFS, PLEASE USE,                                            " -	@echo "* $(APXS) -n glusterfs -ia $(mod_glusterfsdir)/mod_glusterfs.so                " -	@echo "**********************************************************************************" -	@echo "" -	@echo "" - -#install: -#	cp -fv mod_glusterfs.so $(HTTPD_LIBEXECDIR) -#	cp -fv httpd.conf $(HTTPD_CONF_DIR) - -clean: -	rm -fv *.so *.o diff --git a/mod_glusterfs/apache/2.2/src/README.txt b/mod_glusterfs/apache/2.2/src/README.txt deleted file mode 100644 index 214a2535b5a..00000000000 --- a/mod_glusterfs/apache/2.2/src/README.txt +++ /dev/null @@ -1,105 +0,0 @@ -What is mod_glusterfs? -====================== -* mod_glusterfs is a module for apache written for efficient serving of files from glusterfs.  -  mod_glusterfs interfaces with glusterfs using apis provided by libglusterfsclient. - -* this README speaks about installing mod_glusterfs for httpd-2.2 and higher. - -Prerequisites for mod_glusterfs -=============================== -Though mod_glusterfs has been written as a module, with an intent of making no changes to  -the way apache has been built, currently following points have to be taken care of: - -* since glusterfs is compiled with _FILE_OFFSET_BITS=64 and __USE_FILE_OFFSET64 flags, mod_glusterfs and apache  -  in turn have to be compiled with the above two flags. -  - $ tar xzf httpd-2.2.10.tar.gz  - $ cd httpd-2.2.10/ - $ export CFLAGS='-D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64' - $ ./configure --prefix=/usr  - $ make  - $ make install - $ httpd -l | grep -i mod_so  -   mod_so.c - -* if multiple apache installations are present, make sure to pass --with-apxs=/path/to/apxs/of/proper/version  -  to configure script while building glusterfs. - -Build/Install mod_glusterfs -=========================== -* mod_glusterfs is provided with glusterfs--mainline--3.0 and all releases from the same branch. - -* building glusterfs also builds mod_glusterfs. But 'make install' of glusterfs installs mod_glusterfs.so to  -  glusterfs install directory instead of the apache modules directory. - -* 'make install' of glusterfs will print a message similar to the one given below, which is self explanatory.  -  Make sure to use apxs of proper apache version in case of multiple apache installations. This will copy  -  mod_glusterfs.so to modules directory of proper apache version and modify the appropriate httpd.conf to enable -  mod_glusterfs.  - -********************************************************************************** -* TO INSTALL MODGLUSTERFS, PLEASE USE,                                             -* apxs -n glusterfs -ia /usr/lib/glusterfs/2.0.0rc4/apache/2.2/mod_glusterfs.so                 -********************************************************************************** - -Configuration -============= -* Following configuration has to be added to httpd.conf. - - <Location "/glusterfs"> - 	   GlusterfsLogfile "/var/log/glusterfs/glusterfs.log" -	   GlusterfsLoglevel "warning" - 	   GlusterfsVolumeSpecfile "/etc/glusterfs/glusterfs-client.spec" -	   GlusterfsCacheTimeout "600" -	   GlusterfsXattrFileSize "65536" - 	   SetHandler "glusterfs-handler" - </Location> - -* GlusterfsVolumeSpecfile (COMPULSORY) -  Path to the the glusterfs volume specification file. - -* GlusterfsLogfile (COMPULSORY) -  Path to the glusterfs logfile. - -* GlusterfsLoglevel (OPTIONAL, default = warning) -  Severity of messages that are to be logged. Allowed values are critical, error, warning, debug, none  -  in the decreasing order of severity. - -* GlusterfsCacheTimeOut (OPTIONAL, default = 0) -  Timeout values for glusterfs stat and lookup cache. - -* GlusterfsXattrFileSize (OPTIONAL, default = 0) -  Files with sizes upto and including this value are fetched through the extended attribute interface of  -  glusterfs rather than the usual open-read-close set of operations. For files of small sizes, it is recommended  -  to use extended attribute interface. - -* With the above configuration all the requests to httpd of the form www.example.org/glusterfs/path/to/file are  -  served from glusterfs. - -* mod_glusterfs also implements mod_dir and mod_autoindex behaviour for files under glusterfs mount. -  Hence it also takes the directives related to both of these modules. For more details, refer the  -  documentation for both of these modules.  - -Miscellaneous points -==================== -* httpd by default runs with username "nobody" and group "nogroup". Permissions of logfile and specfile have to  -  be set suitably. - -* Since mod_glusterfs runs with permissions of nobody.nogroup, glusterfs has to use only login based  -  authentication. See docs/authentication.txt for more details.  - -* To copy the data served by httpd into glusterfs mountpoint, glusterfs can be started with the  -  volume-specification file provided to mod_glusterfs. Any tool like cp can then be used. - -* To run in gdb, apache has to be compiled with -lpthread, since libglusterfsclient is  -  multithreaded. If not on Linux gdb runs into errors like:  -  "Error while reading shared library symbols: -   Cannot find new threads: generic error" - -* when used with ib-verbs transport, ib_verbs initialization fails. -  reason for this is that apache runs as non-privileged user and the amount of memory that can be  -  locked by default is not sufficient for ib-verbs. to fix this, as root run, -   -  # ulimit -l unlimited - -  and then start apache. diff --git a/mod_glusterfs/apache/2.2/src/mod_glusterfs.c b/mod_glusterfs/apache/2.2/src/mod_glusterfs.c deleted file mode 100644 index d2b9f323266..00000000000 --- a/mod_glusterfs/apache/2.2/src/mod_glusterfs.c +++ /dev/null @@ -1,3627 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef CORE_PRIVATE -#define CORE_PRIVATE -#endif - -#ifndef NO_CONTENT_TYPE -#define NO_CONTENT_TYPE "none" -#endif - -#define BYTERANGE_FMT "%" APR_OFF_T_FMT "-%" APR_OFF_T_FMT "/%" APR_OFF_T_FMT - -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> - -#include <httpd.h> -#include <http_config.h> -#include <http_core.h> -#include <http_request.h> -#include <http_protocol.h> -#include <http_log.h> -#include <http_main.h> -#include <util_script.h> -#include <util_filter.h> -#include <libglusterfsclient.h> -#include <sys/uio.h> -#include <pthread.h> -#include <apr.h> -#include <apr_strings.h> -#include <apr_buckets.h> -#include <apr_fnmatch.h> -#include <apr_lib.h> - -#define GLUSTERFS_INVALID_LOGLEVEL "mod_glfs: Unrecognized log-level \"%s\", "\ -                                   " possible values are \"DEBUG|WARNING|"\ -                                   "ERROR|CRITICAL|NONE\"\n" - -#define GLUSTERFS_HANDLER "glusterfs-handler" -#define GLUSTERFS_CHUNK_SIZE 131072  - -static char c_by_encoding, c_by_type, c_by_path; - -#define BY_ENCODING &c_by_encoding -#define BY_TYPE &c_by_type -#define BY_PATH &c_by_path - -module AP_MODULE_DECLARE_DATA glusterfs_module; -extern module core_module; - -#define NO_OPTIONS          (1 <<  0)  /* Indexing options */ -#define ICONS_ARE_LINKS     (1 <<  1) -#define SCAN_HTML_TITLES    (1 <<  2) -#define SUPPRESS_ICON       (1 <<  3) -#define SUPPRESS_LAST_MOD   (1 <<  4) -#define SUPPRESS_SIZE       (1 <<  5) -#define SUPPRESS_DESC       (1 <<  6) -#define SUPPRESS_PREAMBLE   (1 <<  7) -#define SUPPRESS_COLSORT    (1 <<  8) -#define SUPPRESS_RULES      (1 <<  9) -#define FOLDERS_FIRST       (1 << 10) -#define VERSION_SORT        (1 << 11) -#define TRACK_MODIFIED      (1 << 12) -#define FANCY_INDEXING      (1 << 13) -#define TABLE_INDEXING      (1 << 14) -#define IGNORE_CLIENT       (1 << 15) -#define IGNORE_CASE         (1 << 16) -#define EMIT_XHTML          (1 << 17) -#define SHOW_FORBIDDEN      (1 << 18) - -#define K_NOADJUST 0 -#define K_ADJUST 1 -#define K_UNSET 2 - -/* - * Define keys for sorting. - */ -#define K_NAME 'N'              /* Sort by file name (default) */ -#define K_LAST_MOD 'M'          /* Last modification date */ -#define K_SIZE 'S'              /* Size (absolute, not as displayed) */ -#define K_DESC 'D'              /* Description */ -#define K_VALID "NMSD"          /* String containing _all_ valid K_ opts */ - -#define D_ASCENDING 'A' -#define D_DESCENDING 'D' -#define D_VALID "AD"            /* String containing _all_ valid D_ opts */ - -/* - * These are the dimensions of the default icons supplied with Apache. - */ -#define DEFAULT_ICON_WIDTH 20 -#define DEFAULT_ICON_HEIGHT 22 - -/* - * Other default dimensions. - */ -#define DEFAULT_NAME_WIDTH 23 -#define DEFAULT_DESC_WIDTH 23 - -struct mod_glfs_ai_item { -        char *type; -        char *apply_to; -        char *apply_path; -        char *data; -}; - -typedef struct mod_glfs_ai_desc_t { -        char *pattern; -        char *description; -        int full_path; -        int wildcards; -} mod_glfs_ai_desc_t; - -typedef enum { -        SLASH_OFF = 0, -        SLASH_ON, -        SLASH_UNSET -} mod_glfs_dir_slash_cfg; - -/* static ap_filter_rec_t *mod_glfs_output_filter_handle; */ - -/*TODO: verify error returns to server core */ - -typedef struct glusterfs_dir_config { -        char                   *logfile; -        char                   *loglevel; -        char                   *specfile; -        char                   *mount_dir; -        char                   *buf; - -        size_t                  xattr_file_size; -        uint32_t                cache_timeout; -         -        /* mod_dir options */ -        apr_array_header_t     *index_names; -        mod_glfs_dir_slash_cfg  do_slash; - -        /* autoindex options */ -        char                   *default_icon; -        char                   *style_sheet; -        apr_int32_t             opts; -        apr_int32_t             incremented_opts; -        apr_int32_t             decremented_opts; -        int                     name_width; -        int                     name_adjust; -        int                     desc_width; -        int                     desc_adjust; -        int                     icon_width; -        int                     icon_height; -        char                    default_keyid; -        char                    default_direction; - -        apr_array_header_t     *icon_list; -        apr_array_header_t     *alt_list; -        apr_array_header_t     *desc_list; -        apr_array_header_t     *ign_list; -        apr_array_header_t     *hdr_list; -        apr_array_header_t     *rdme_list; - -        char                   *ctype; -        char                   *charset; -} glusterfs_dir_config_t; - -typedef struct glusterfs_async_local { -        int                op_ret; -        int                op_errno; -        char               async_read_complete; -        off_t              length; -        off_t              read_bytes; -        glusterfs_iobuf_t *buf; -        request_rec       *request; -        pthread_mutex_t    lock; -        pthread_cond_t     cond; -}glusterfs_async_local_t; - -#define GLUSTERFS_CMD_PERMS ACCESS_CONF - - -static glusterfs_dir_config_t * -mod_glfs_dconfig (request_rec *r) -{ -        glusterfs_dir_config_t *dir_config = NULL; -        if (r->per_dir_config != NULL) { -                dir_config = ap_get_module_config (r->per_dir_config, -                                                   &glusterfs_module); -        } - -        return dir_config; -} - - -static const char * -cmd_add_xattr_file_size (cmd_parms *cmd, void *dummy, const char *arg) -{ -        glusterfs_dir_config_t *dir_config = dummy; -        dir_config->xattr_file_size = atoi (arg); -        return NULL; -} - - -static const char * -cmd_set_cache_timeout (cmd_parms *cmd, void *dummy, const char *arg) -{ -        glusterfs_dir_config_t *dir_config = dummy; -        dir_config->cache_timeout = atoi (arg); -        return NULL; -} - - -static const char * -cmd_set_loglevel (cmd_parms *cmd, void *dummy, const char *arg) -{ -        glusterfs_dir_config_t *dir_config = dummy; -        char                   *error = NULL; -        if (strncasecmp (arg, "DEBUG", strlen ("DEBUG"))  -            && strncasecmp (arg, "WARNING", strlen ("WARNING"))  -            && strncasecmp (arg, "CRITICAL", strlen ("CRITICAL"))  -            && strncasecmp (arg, "NONE", strlen ("NONE"))  -            && strncasecmp (arg, "ERROR", strlen ("ERROR"))) -                error = GLUSTERFS_INVALID_LOGLEVEL; -        else -                dir_config->loglevel = apr_pstrdup (cmd->pool, arg); - -        return error; -} - -static const char * -cmd_add_logfile (cmd_parms *cmd, void *dummy, const char *arg) -{ -        glusterfs_dir_config_t *dir_config = dummy; -        dir_config->logfile = apr_pstrdup (cmd->pool, arg); - -        return NULL; -} - - -static const char * -cmd_add_volume_specfile (cmd_parms *cmd, void *dummy, const char *arg) -{ -        glusterfs_dir_config_t *dir_config = dummy; - -        dir_config->specfile = apr_pstrdup (cmd->pool, arg); - -        return NULL; -} - -#define WILDCARDS_REQUIRED 0 - -static const char * -cmd_add_desc (cmd_parms *cmd, void *d, const char *desc, -              const char *to) -{ -        glusterfs_dir_config_t *dcfg = NULL; -        mod_glfs_ai_desc_t     *desc_entry = NULL; -        char                   *prefix = ""; - -        dcfg = (glusterfs_dir_config_t *) d; -        desc_entry = (mod_glfs_ai_desc_t *) apr_array_push(dcfg->desc_list); -        desc_entry->full_path = (ap_strchr_c(to, '/') == NULL) ? 0 : 1; -        desc_entry->wildcards = (WILDCARDS_REQUIRED -                                 || desc_entry->full_path -                                 || apr_fnmatch_test(to)); -        if (desc_entry->wildcards) { -                prefix = desc_entry->full_path ? "*/" : "*"; -                desc_entry->pattern = apr_pstrcat(dcfg->desc_list->pool, -                                                  prefix, to, "*", NULL); -        } -        else { -                desc_entry->pattern = apr_pstrdup(dcfg->desc_list->pool, to); -        } -        desc_entry->description = apr_pstrdup(dcfg->desc_list->pool, desc); -        return NULL; -} - - -static void push_item(apr_array_header_t *arr, char *type, const char *to, -                      const char *path, const char *data) -{ -        struct mod_glfs_ai_item *p = NULL; - -        p = (struct mod_glfs_ai_item *) apr_array_push(arr); - -        if (!to) { -                to = ""; -        } -        if (!path) { -                path = ""; -        } - -        p->type = type; -        p->data = data ? apr_pstrdup(arr->pool, data) : NULL; -        p->apply_path = apr_pstrcat(arr->pool, path, "*", NULL); - -        if ((type == BY_PATH) && (!ap_is_matchexp(to))) { -                p->apply_to = apr_pstrcat(arr->pool, "*", to, NULL); -        } -        else if (to) { -                p->apply_to = apr_pstrdup(arr->pool, to); -        } -        else { -                p->apply_to = NULL; -        } -} - - -static const char * -cmd_add_ignore (cmd_parms *cmd, void *d, const char *ext) -{ -        push_item(((glusterfs_dir_config_t *) d)->ign_list, 0, ext, cmd->path, -                  NULL); -        return NULL; -} - - -static const char * -cmd_add_header (cmd_parms *cmd, void *d, const char *name) -{ -        push_item(((glusterfs_dir_config_t *) d)->hdr_list, 0, NULL, cmd->path, -                  name); -        return NULL; -} - - -static const char * -cmd_add_readme (cmd_parms *cmd, void *d, const char *name) -{ -        push_item(((glusterfs_dir_config_t *) d)->rdme_list, 0, NULL, cmd->path, -                  name); -        return NULL; -} - - -static const char * -cmd_add_opts (cmd_parms *cmd, void *d, int argc, char *const argv[]) -{ -        int                     i = 0, option = 0; -        char                   *w = NULL; -        apr_int32_t             opts; -        apr_int32_t             opts_add; -        apr_int32_t             opts_remove; -        char                    action = 0; -        glusterfs_dir_config_t *d_cfg = (glusterfs_dir_config_t *) d; - -        opts = d_cfg->opts; -        opts_add = d_cfg->incremented_opts; -        opts_remove = d_cfg->decremented_opts; - -        for (i = 0; i < argc; i++) { -                w = argv[i]; - -                if ((*w == '+') || (*w == '-')) { -                        action = *(w++); -                } -                else { -                        action = '\0'; -                } -                if (!strcasecmp(w, "FancyIndexing")) { -                        option = FANCY_INDEXING; -                } -                else if (!strcasecmp(w, "FoldersFirst")) { -                        option = FOLDERS_FIRST; -                } -                else if (!strcasecmp(w, "HTMLTable")) { -                        option = TABLE_INDEXING; -                } -                else if (!strcasecmp(w, "IconsAreLinks")) { -                        option = ICONS_ARE_LINKS; -                } -                else if (!strcasecmp(w, "IgnoreCase")) { -                        option = IGNORE_CASE; -                } -                else if (!strcasecmp(w, "IgnoreClient")) { -                        option = IGNORE_CLIENT; -                } -                else if (!strcasecmp(w, "ScanHTMLTitles")) { -                        option = SCAN_HTML_TITLES; -                } -                else if (!strcasecmp(w, "SuppressColumnSorting")) { -                        option = SUPPRESS_COLSORT; -                } -                else if (!strcasecmp(w, "SuppressDescription")) { -                        option = SUPPRESS_DESC; -                } -                else if (!strcasecmp(w, "SuppressHTMLPreamble")) { -                        option = SUPPRESS_PREAMBLE; -                } -                else if (!strcasecmp(w, "SuppressIcon")) { -                        option = SUPPRESS_ICON; -                } -                else if (!strcasecmp(w, "SuppressLastModified")) { -                        option = SUPPRESS_LAST_MOD; -                } -                else if (!strcasecmp(w, "SuppressSize")) { -                        option = SUPPRESS_SIZE; -                } -                else if (!strcasecmp(w, "SuppressRules")) { -                        option = SUPPRESS_RULES; -                } -                else if (!strcasecmp(w, "TrackModified")) { -                        option = TRACK_MODIFIED; -                } -                else if (!strcasecmp(w, "VersionSort")) { -                        option = VERSION_SORT; -                } -                else if (!strcasecmp(w, "XHTML")) { -                        option = EMIT_XHTML; -                } -                else if (!strcasecmp(w, "ShowForbidden")) { -                        option = SHOW_FORBIDDEN; -                } -                else if (!strcasecmp(w, "None")) { -                        if (action != '\0') { -                                return "Cannot combine '+' or '-' with 'None' " -                                        "keyword"; -                        } -                        opts = NO_OPTIONS; -                        opts_add = 0; -                        opts_remove = 0; -                } -                else if (!strcasecmp(w, "IconWidth")) { -                        if (action != '-') { -                                d_cfg->icon_width = DEFAULT_ICON_WIDTH; -                        } -                        else { -                                d_cfg->icon_width = 0; -                        } -                } -                else if (!strncasecmp(w, "IconWidth=", 10)) { -                        if (action == '-') { -                                return "Cannot combine '-' with IconWidth=n"; -                        } -                        d_cfg->icon_width = atoi(&w[10]); -                } -                else if (!strcasecmp(w, "IconHeight")) { -                        if (action != '-') { -                                d_cfg->icon_height = DEFAULT_ICON_HEIGHT; -                        } -                        else { -                                d_cfg->icon_height = 0; -                        } -                } -                else if (!strncasecmp(w, "IconHeight=", 11)) { -                        if (action == '-') { -                                return "Cannot combine '-' with IconHeight=n"; -                        } -                        d_cfg->icon_height = atoi(&w[11]); -                } -                else if (!strcasecmp(w, "NameWidth")) { -                        if (action != '-') { -                                return "NameWidth with no value may only appear" -                                        " as " -                                        "'-NameWidth'"; -                        } -                        d_cfg->name_width = DEFAULT_NAME_WIDTH; -                        d_cfg->name_adjust = K_NOADJUST; -                } -                else if (!strncasecmp(w, "NameWidth=", 10)) { -                        if (action == '-') { -                                return "Cannot combine '-' with NameWidth=n"; -                        } -                        if (w[10] == '*') { -                                d_cfg->name_adjust = K_ADJUST; -                        } -                        else { -                                int width = atoi(&w[10]); - -                                if (width && (width < 5)) { -                                        return "NameWidth value must be greater" -                                                " than 5"; -                                } -                                d_cfg->name_width = width; -                                d_cfg->name_adjust = K_NOADJUST; -                        } -                } -                else if (!strcasecmp(w, "DescriptionWidth")) { -                        if (action != '-') { -                                return "DescriptionWidth with no value may only" -                                        " appear as " -                                        "'-DescriptionWidth'"; -                        } -                        d_cfg->desc_width = DEFAULT_DESC_WIDTH; -                        d_cfg->desc_adjust = K_NOADJUST; -                } -                else if (!strncasecmp(w, "DescriptionWidth=", 17)) { -                        if (action == '-') { -                                return "Cannot combine '-' with " -                                        "DescriptionWidth=n"; -                        } -                        if (w[17] == '*') { -                                d_cfg->desc_adjust = K_ADJUST; -                        } -                        else { -                                int width = atoi(&w[17]); - -                                if (width && (width < 12)) { -                                        return "DescriptionWidth value must be " -                                                "greater than 12"; -                                } -                                d_cfg->desc_width = width; -                                d_cfg->desc_adjust = K_NOADJUST; -                        } -                } -                else if (!strncasecmp(w, "Type=", 5)) { -                        d_cfg->ctype = apr_pstrdup(cmd->pool, &w[5]); -                } -                else if (!strncasecmp(w, "Charset=", 8)) { -                        d_cfg->charset = apr_pstrdup(cmd->pool, &w[8]); -                } -                else { -                        return "Invalid directory indexing option"; -                } -                if (action == '\0') { -                        opts |= option; -                        opts_add = 0; -                        opts_remove = 0; -                } -                else if (action == '+') { -                        opts_add |= option; -                        opts_remove &= ~option; -                } -                else { -                        opts_remove |= option; -                        opts_add &= ~option; -                } -        } -        if ((opts & NO_OPTIONS) && (opts & ~NO_OPTIONS)) { -                return "Cannot combine other IndexOptions keywords with 'None'"; -        } -        d_cfg->incremented_opts = opts_add; -        d_cfg->decremented_opts = opts_remove; -        d_cfg->opts = opts; -        return NULL; -} - - -static const char * -cmd_set_default_order(cmd_parms *cmd, void *m, -                      const char *direction, const char *key) -{ -        glusterfs_dir_config_t *d_cfg = (glusterfs_dir_config_t *) m; - -        if (!strcasecmp(direction, "Ascending")) { -                d_cfg->default_direction = D_ASCENDING; -        } -        else if (!strcasecmp(direction, "Descending")) { -                d_cfg->default_direction = D_DESCENDING; -        } -        else { -                return "First keyword must be 'Ascending' or 'Descending'"; -        } - -        if (!strcasecmp(key, "Name")) { -                d_cfg->default_keyid = K_NAME; -        } -        else if (!strcasecmp(key, "Date")) { -                d_cfg->default_keyid = K_LAST_MOD; -        } -        else if (!strcasecmp(key, "Size")) { -                d_cfg->default_keyid = K_SIZE; -        } -        else if (!strcasecmp(key, "Description")) { -                d_cfg->default_keyid = K_DESC; -        } -        else { -                return "Second keyword must be 'Name', 'Date', 'Size', or " -                        "'Description'"; -        } - -        return NULL; -} - - -static char c_by_encoding, c_by_type, c_by_path; - -#define BY_ENCODING &c_by_encoding -#define BY_TYPE &c_by_type -#define BY_PATH &c_by_path - -/* - * This routine puts the standard HTML header at the top of the index page. - * We include the DOCTYPE because we may be using features therefrom (i.e., - * HEIGHT and WIDTH attributes on the icons if we're FancyIndexing). - */ -static void emit_preamble(request_rec *r, int xhtml, const char *title) -{ -        glusterfs_dir_config_t *d; - -        d = (glusterfs_dir_config_t *) ap_get_module_config(r->per_dir_config, -                                                            &glusterfs_module); - -        if (xhtml) { -                ap_rvputs(r, DOCTYPE_XHTML_1_0T, -                          "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" -                          " <head>\n  <title>Index of ", title, -                          "</title>\n", NULL); -        } else { -                ap_rvputs(r, DOCTYPE_HTML_3_2, -                          "<html>\n <head>\n" -                          "  <title>Index of ", title, -                          "</title>\n", NULL); -        } - -        if (d->style_sheet != NULL) { -                ap_rvputs(r, "  <link rel=\"stylesheet\" href=\"", -                          d->style_sheet, "\" type=\"text/css\"", -                          xhtml ? " />\n" : ">\n", NULL); -        } -        ap_rvputs(r, " </head>\n <body>\n", NULL); -} - - -static const char *cmd_add_alt(cmd_parms *cmd, void *d, const char *alt, -                               const char *to) -{ -        if (cmd->info == BY_PATH) { -                if (!strcmp(to, "**DIRECTORY**")) { -                        to = "^^DIRECTORY^^"; -                } -        } -        if (cmd->info == BY_ENCODING) { -                char *tmp = apr_pstrdup(cmd->pool, to); -                ap_str_tolower(tmp); -                to = tmp; -        } - -        push_item(((glusterfs_dir_config_t *) d)->alt_list, cmd->info, to, -                  cmd->path, alt); -        return NULL; -} - -static const char *cmd_add_icon(cmd_parms *cmd, void *d, const char *icon, -                                const char *to) -{ -        char *iconbak = apr_pstrdup(cmd->pool, icon); -        char *alt = NULL, *cl = NULL, *tmp = NULL; - -        if (icon[0] == '(') { -                cl = strchr(iconbak, ')'); - -                if (cl == NULL) { -                        return "missing closing paren"; -                } -                alt = ap_getword_nc(cmd->pool, &iconbak, ','); -                *cl = '\0';                             /* Lose closing paren */ -                cmd_add_alt(cmd, d, &alt[1], to); -        } -        if (cmd->info == BY_PATH) { -                if (!strcmp(to, "**DIRECTORY**")) { -                        to = "^^DIRECTORY^^"; -                } -        } -        if (cmd->info == BY_ENCODING) { -                tmp = apr_pstrdup(cmd->pool, to); -                ap_str_tolower(tmp); -                to = tmp; -        } - -        push_item(((glusterfs_dir_config_t *) d)->icon_list, cmd->info, to, -                  cmd->path, iconbak); -        return NULL; -} - - -static void * -mod_glfs_create_dir_config(apr_pool_t *p, char *dirspec) -{ -        glusterfs_dir_config_t *dir_config = NULL; - -        dir_config = (glusterfs_dir_config_t *) apr_pcalloc(p, -                                                            sizeof(*dir_config)); - -        dir_config->mount_dir = dirspec; -        dir_config->logfile = dir_config->specfile = (char *)0; -        dir_config->loglevel = "warning"; -        dir_config->cache_timeout = 0; -        dir_config->buf = NULL; - -        /* mod_dir options init */ -        dir_config->index_names = NULL; -        dir_config->do_slash = SLASH_UNSET; - -        /* autoindex options init */ -        dir_config->icon_width = 0; -        dir_config->icon_height = 0; -        dir_config->name_width = DEFAULT_NAME_WIDTH; -        dir_config->name_adjust = K_UNSET; -        dir_config->desc_width = DEFAULT_DESC_WIDTH; -        dir_config->desc_adjust = K_UNSET; -        dir_config->icon_list = apr_array_make(p, 4, -                                               sizeof(struct mod_glfs_ai_item)); -        dir_config->alt_list = apr_array_make(p, 4, -                                              sizeof(struct mod_glfs_ai_item)); -        dir_config->desc_list = apr_array_make(p, 4, -                                               sizeof(mod_glfs_ai_desc_t)); -        dir_config->ign_list = apr_array_make(p, 4, -                                              sizeof(struct mod_glfs_ai_item)); -        dir_config->hdr_list = apr_array_make(p, 4, -                                              sizeof(struct mod_glfs_ai_item)); -        dir_config->rdme_list = apr_array_make(p, 4, -                                               sizeof(struct mod_glfs_ai_item)); -        dir_config->opts = 0; -        dir_config->incremented_opts = 0; -        dir_config->decremented_opts = 0; -        dir_config->default_keyid = '\0'; -        dir_config->default_direction = '\0'; - -        return (void *) dir_config; -} - - -static void * -mod_glfs_merge_dir_config(apr_pool_t *p, void *parent_conf, -                          void *newloc_conf) -{ -        glusterfs_dir_config_t *new = NULL; -        glusterfs_dir_config_t *add = NULL; -        glusterfs_dir_config_t *base = NULL; - -        new = (glusterfs_dir_config_t *)  -                apr_pcalloc(p, sizeof(glusterfs_dir_config_t)); -        add = newloc_conf; -        base = parent_conf; - -        if (add->logfile) -                new->logfile = apr_pstrdup (p, add->logfile); - -        if (add->loglevel) -                new->loglevel = apr_pstrdup (p, add->loglevel); - -        if (add->specfile) -                new->specfile = apr_pstrdup (p, add->specfile); - -        if (add->mount_dir) -                new->mount_dir = apr_pstrdup (p, add->mount_dir); - -        new->xattr_file_size = add->xattr_file_size; -        new->cache_timeout = add->cache_timeout; -        new->buf = add->buf; - -        /* mod_dir */ -        new->index_names = add->index_names ?  -                add->index_names : base->index_names; -        new->do_slash = -                (add->do_slash == SLASH_UNSET) ? base->do_slash : add->do_slash; - -        /* auto index */ -        new->default_icon = add->default_icon ? add->default_icon -                : base->default_icon; -        new->style_sheet = add->style_sheet ? add->style_sheet -                : base->style_sheet; -        new->icon_height = add->icon_height ?  -                add->icon_height : base->icon_height; -        new->icon_width = add->icon_width ? add->icon_width : base->icon_width; - -        new->ctype = add->ctype ? add->ctype : base->ctype; -        new->charset = add->charset ? add->charset : base->charset; - -        new->alt_list = apr_array_append(p, add->alt_list, base->alt_list); -        new->ign_list = apr_array_append(p, add->ign_list, base->ign_list); -        new->hdr_list = apr_array_append(p, add->hdr_list, base->hdr_list); -        new->desc_list = apr_array_append(p, add->desc_list, base->desc_list); -        new->icon_list = apr_array_append(p, add->icon_list, base->icon_list); -        new->rdme_list = apr_array_append(p, add->rdme_list, base->rdme_list); -        if (add->opts & NO_OPTIONS) { -                /* -                 * If the current directory says 'no options' then we also -                 * clear any incremental mods from being inheritable further down. -                 */ -                new->opts = NO_OPTIONS; -                new->incremented_opts = 0; -                new->decremented_opts = 0; -        } -        else { -                /* -                 * If there were any nonincremental options selected for -                 * this directory, they dominate and we don't inherit *anything.* -                 * Contrariwise, we *do* inherit if the only settings here are -                 * incremental ones. -                 */ -                if (add->opts == 0) { -                        new->incremented_opts = (base->incremented_opts -                                                 | add->incremented_opts) -                                & ~add->decremented_opts; -                        new->decremented_opts = (base->decremented_opts -                                                 | add->decremented_opts); -                        /* -                         * We may have incremental settings, so make sure we  -                         * don't inadvertently inherit an IndexOptions None  -                         * from above. -                         */ -                        new->opts = (base->opts & ~NO_OPTIONS); -                } -                else { -                        /* -                         * There are local nonincremental settings, which clear -                         * all inheritance from above.  They *are* the new  -                         * base settings. -                         */ -                        new->opts = add->opts;; -                } -                /* -                 * We're guaranteed that there'll be no overlap between -                 * the add-options and the remove-options. -                 */ -                new->opts |= new->incremented_opts; -                new->opts &= ~new->decremented_opts; -        } -        /* -         * Inherit the NameWidth settings if there aren't any specific to -         * the new location; otherwise we'll end up using the defaults set  -         * in the config-rec creation routine. -         */ -        if (add->name_adjust == K_UNSET) { -                new->name_width = base->name_width; -                new->name_adjust = base->name_adjust; -        } -        else { -                new->name_width = add->name_width; -                new->name_adjust = add->name_adjust; -        } - -        /* -         * Likewise for DescriptionWidth. -         */ -        if (add->desc_adjust == K_UNSET) { -                new->desc_width = base->desc_width; -                new->desc_adjust = base->desc_adjust; -        } -        else { -                new->desc_width = add->desc_width; -                new->desc_adjust = add->desc_adjust; -        } - -        new->default_keyid = add->default_keyid ? add->default_keyid -                : base->default_keyid; -        new->default_direction = add->default_direction ? add->default_direction -                : base->default_direction; - -        return (void *) new; -} - - -static void  -mod_glfs_child_init(apr_pool_t *p, server_rec *s) -{ -        int                      i = 0, num_sec = 0, ret = 0; -        core_server_config      *sconf = NULL; -        ap_conf_vector_t       **sec_ent = NULL; -        glusterfs_dir_config_t  *dir_config = NULL; -        glusterfs_init_params_t  ctx = {0, }; -   -        sconf = (core_server_config *) ap_get_module_config (s->module_config, -                                                             &core_module); -        sec_ent = (ap_conf_vector_t **) sconf->sec_url->elts; -        num_sec = sconf->sec_url->nelts; - -        for (i = 0; i < num_sec; i++) { -                dir_config = ap_get_module_config (sec_ent[i], -                                                   &glusterfs_module); - -                if (dir_config) { -                        memset (&ctx, 0, sizeof (ctx)); - -                        ctx.logfile = dir_config->logfile; -                        ctx.loglevel = dir_config->loglevel; -                        ctx.lookup_timeout = dir_config->cache_timeout; -                        ctx.stat_timeout = dir_config->cache_timeout; -                        ctx.specfile = dir_config->specfile; - -                        ret = glusterfs_mount (dir_config->mount_dir, &ctx); -                        if (ret != 0) { -                                ap_log_error(APLOG_MARK, APLOG_ERR, -                                             APR_EGENERAL, s,  -                                             "mod_glfs_child_init: " -                                             "glusterfs_init failed, check " -                                             "glusterfs logfile %s for more " -                                             "details",  -                                             dir_config->logfile); -                        } -                } -                dir_config = NULL; -        } -} - - -static void  -mod_glfs_child_exit(server_rec *s, apr_pool_t *p) -{ -        int                      i = 0, num_sec = 0; -        core_server_config      *sconf = NULL; -        ap_conf_vector_t       **sec_ent = NULL; -        glusterfs_dir_config_t  *dir_config = NULL; -        glusterfs_init_params_t  ctx = {0, }; - -        sconf = ap_get_module_config(s->module_config, -                                     &core_module); -        sec_ent = (ap_conf_vector_t **) sconf->sec_url->elts; -        num_sec = sconf->sec_url->nelts; -        for (i = 0; i < num_sec; i++) { -                dir_config = ap_get_module_config (sec_ent[i], -                                                   &glusterfs_module); -                if (dir_config) { -                        glusterfs_umount (dir_config->mount_dir); -                } -        } -} - -static apr_filetype_e filetype_from_mode(mode_t mode) -{ -        apr_filetype_e type = APR_NOFILE; - -        if (S_ISREG(mode)) -                type = APR_REG; -        else if (S_ISDIR(mode)) -                type = APR_DIR; -        else if (S_ISCHR(mode)) -                type = APR_CHR; -        else if (S_ISBLK(mode)) -                type = APR_BLK; -        else if (S_ISFIFO(mode)) -                type = APR_PIPE; -        else if (S_ISLNK(mode)) -                type = APR_LNK; -        else if (S_ISSOCK(mode)) -                type = APR_SOCK; -        else -                type = APR_UNKFILE; -        return type; -} - - -static void fill_out_finfo(apr_finfo_t *finfo, struct stat *info, -                           apr_int32_t wanted) -{  -        finfo->valid = APR_FINFO_MIN | APR_FINFO_IDENT | APR_FINFO_NLINK -                | APR_FINFO_OWNER | APR_FINFO_PROT; -        finfo->protection = apr_unix_mode2perms(info->st_mode); -        finfo->filetype = filetype_from_mode(info->st_mode); -        finfo->user = info->st_uid; -        finfo->group = info->st_gid; -        finfo->size = info->st_size; -        finfo->device = info->st_dev; -        finfo->nlink = info->st_nlink; - -        /* Check for overflow if storing a 64-bit st_ino in a 32-bit -         * apr_ino_t for LFS builds: */ -        if (sizeof(apr_ino_t) >= sizeof(info->st_ino) -            || (apr_ino_t)info->st_ino == info->st_ino) { -                finfo->inode = info->st_ino; -        } else { -                finfo->valid &= ~APR_FINFO_INODE; -        } - -        apr_time_ansi_put(&finfo->atime, info->st_atime); -#ifdef HAVE_STRUCT_STAT_ST_ATIM_TV_NSEC -        finfo->atime += info->st_atim.tv_nsec / APR_TIME_C(1000); -#elif defined(HAVE_STRUCT_STAT_ST_ATIMENSEC) -        finfo->atime += info->st_atimensec / APR_TIME_C(1000); -#elif defined(HAVE_STRUCT_STAT_ST_ATIME_N) -        finfo->ctime += info->st_atime_n / APR_TIME_C(1000); -#endif - -        apr_time_ansi_put(&finfo->mtime, info->st_mtime); -#ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC -        finfo->mtime += info->st_mtim.tv_nsec / APR_TIME_C(1000); -#elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC) -        finfo->mtime += info->st_mtimensec / APR_TIME_C(1000); -#elif defined(HAVE_STRUCT_STAT_ST_MTIME_N) -        finfo->ctime += info->st_mtime_n / APR_TIME_C(1000); -#endif - -        apr_time_ansi_put(&finfo->ctime, info->st_ctime); -#ifdef HAVE_STRUCT_STAT_ST_CTIM_TV_NSEC -        finfo->ctime += info->st_ctim.tv_nsec / APR_TIME_C(1000); -#elif defined(HAVE_STRUCT_STAT_ST_CTIMENSEC) -        finfo->ctime += info->st_ctimensec / APR_TIME_C(1000); -#elif defined(HAVE_STRUCT_STAT_ST_CTIME_N) -        finfo->ctime += info->st_ctime_n / APR_TIME_C(1000); -#endif - -#ifdef HAVE_STRUCT_STAT_ST_BLOCKS -#ifdef DEV_BSIZE -        finfo->csize = (apr_off_t)info->st_blocks * (apr_off_t)DEV_BSIZE; -#else -        finfo->csize = (apr_off_t)info->st_blocks * (apr_off_t)512; -#endif -        finfo->valid |= APR_FINFO_CSIZE; -#endif -} - - -static int  -mod_glfs_map_to_storage(request_rec *r) -{ -        glusterfs_dir_config_t *dir_config = NULL, *tmp = NULL; -        int                     access_status = 0, ret = 0; -        char                   *path = NULL; -        struct stat             st = {0, }; -        core_server_config     *sconf = NULL; -        ap_conf_vector_t      **sec_ent = NULL; -        int                     num_sec = 0, i = 0; - -        sconf = (core_server_config *) ap_get_module_config (r->server->module_config, -                                                             &core_module); -        sec_ent = (ap_conf_vector_t **) sconf->sec_url->elts; -        num_sec = sconf->sec_url->nelts; - -        for (i = 0; i < num_sec; i++) { -                tmp = ap_get_module_config (sec_ent[i], &glusterfs_module); - -                if (tmp && !strncmp (tmp->mount_dir, r->uri, -                                     strlen (tmp->mount_dir))) { -                        if (!dir_config ||  -                            strlen (tmp->mount_dir)  -                            > strlen (dir_config->mount_dir)) { -                                dir_config = tmp; -                        } -                } - -        } - -        if (dir_config && dir_config->mount_dir  -            && !(strncmp (apr_pstrcat (r->pool, dir_config->mount_dir, "/", -                                       NULL), r->uri, -                          strlen (dir_config->mount_dir) + 1) -                 && !r->handler))  -                r->handler = GLUSTERFS_HANDLER; - -        if (!r->handler || (r->handler && strcmp (r->handler, -                                                  GLUSTERFS_HANDLER))) -                return DECLINED; - -        path = r->uri; - -        memset (&r->finfo, 0, sizeof (r->finfo)); - -        dir_config->buf = calloc (1, dir_config->xattr_file_size); -        if (!dir_config->buf) { -                return HTTP_INTERNAL_SERVER_ERROR; -        } - -        ret = glusterfs_get (path, dir_config->buf,  -                             dir_config->xattr_file_size, &st); - -        if (ret == -1 || st.st_size > dir_config->xattr_file_size  -            || S_ISDIR (st.st_mode)) { -                free (dir_config->buf); -                dir_config->buf = NULL; - -                if (ret == -1) { -                        int error = HTTP_NOT_FOUND; -                        char *emsg = NULL; -                        if (r->path_info == NULL) { -                                emsg = apr_pstrcat(r->pool, strerror (errno), -                                                   r->filename, NULL); -                        } -                        else { -                                emsg = apr_pstrcat(r->pool, strerror (errno), -                                                   r->filename, r->path_info, -                                                   NULL); -                        } -                        ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, -                                      r, "%s", emsg); -                        if (errno != ENOENT) { -                                error = HTTP_INTERNAL_SERVER_ERROR; -                        } -                        return error; -                } -        } - -        r->finfo.pool = r->pool; -        r->finfo.fname = r->filename; -        fill_out_finfo (&r->finfo, &st,  -                        APR_FINFO_MIN | APR_FINFO_IDENT | APR_FINFO_NLINK | -                        APR_FINFO_OWNER | APR_FINFO_PROT); -                         -        /* allow core module to run directory_walk() and location_walk() */ -        return DECLINED; -} - - -static int  -mod_glfs_readv_async_cbk (int32_t op_ret, int32_t op_errno, -                          glusterfs_iobuf_t *buf, void *cbk_data) -{ -        glusterfs_async_local_t *local = cbk_data; - -        pthread_mutex_lock (&local->lock); -        { -                local->async_read_complete = 1; -                local->buf = buf; -                local->op_ret = op_ret; -                local->op_errno = op_errno; -                pthread_cond_signal (&local->cond); -        } -        pthread_mutex_unlock (&local->lock); - -        return 0; -} - -/* use read_async just to avoid memcpy of read buffer in libglusterfsclient */ -static int -mod_glfs_read_async (request_rec *r, apr_bucket_brigade *bb, -                     glusterfs_file_t fd, -                     apr_off_t offset, apr_off_t length) -{ -        glusterfs_async_local_t local = {0, }; -        off_t                   end = 0; -        int                     nbytes = 0, complete = 0; -        conn_rec               *c = r->connection; -        apr_bucket             *e = NULL; -        apr_status_t            status = APR_SUCCESS; -        glusterfs_iobuf_t      *buf = NULL; -                 -        if (length == 0) { -                return 0; -        } - -        pthread_cond_init (&local.cond, NULL); -        pthread_mutex_init (&local.lock, NULL); -   -        memset (&local, 0, sizeof (local)); -        local.request = r; - -        if (length > 0) -                end = offset + length; - -        do { -                if (length > 0) { -                        nbytes = end - offset; -                        if (nbytes > GLUSTERFS_CHUNK_SIZE) -                                nbytes = GLUSTERFS_CHUNK_SIZE; -                } else -                        nbytes = GLUSTERFS_CHUNK_SIZE; - -                glusterfs_read_async(fd,  -                                     nbytes, -                                     offset, -                                     mod_glfs_readv_async_cbk, -                                     (void *)&local); - -                pthread_mutex_lock (&local.lock); -                { -                        while (!local.async_read_complete) { -                                pthread_cond_wait (&local.cond, &local.lock); -                        } - -                        local.async_read_complete = 0; -                        buf = local.buf; - -                        if (length < 0) -                                complete = (local.op_ret <= 0); -                        else { -                                local.read_bytes += local.op_ret; -                                complete = ((local.read_bytes == length) || -                                            (local.op_ret < 0)); -                        } -                } -                pthread_mutex_unlock (&local.lock); - -                if (!bb) { -                        bb = apr_brigade_create (r->pool, c->bucket_alloc);  -                } -                apr_brigade_writev (bb, NULL, NULL, buf->vector, buf->count); - -                /*  -                 * make sure all the data is written out, since we call  -                 * glusterfs_free on buf once ap_pass_brigade returns -                 */ -                e = apr_bucket_flush_create (c->bucket_alloc); -                APR_BRIGADE_INSERT_TAIL (bb, e); - -                status = ap_pass_brigade (r->output_filters, bb); -                if (status != APR_SUCCESS) { -                        /* no way to know what type of error occurred */ -                        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, -                                      "mod_glfs_handler: ap_pass_brigade " -                                      "returned %i", -                                      status); -                        complete = 1; -                        local.op_ret = -1; -                } - -                glusterfs_free (buf); - -                /*  -                 * bb has already been cleaned up by core_output_filter,  -                 * just being paranoid -                 */ -                apr_brigade_cleanup (bb); - -                offset += nbytes; -        } while (!complete); - -        return (local.op_ret < 0 ? HTTP_INTERNAL_SERVER_ERROR : OK); -} - -static int  -parse_byterange(char *range, apr_off_t clength, -                apr_off_t *start, apr_off_t *end) -{ -        char       *dash = NULL, *errp = NULL; -        apr_off_t   number; - -        dash = strchr(range, '-'); -        if (!dash) { -                return 0; -        } - -        if ((dash == range)) { -                /* In the form "-5" */ -                if (apr_strtoff(&number, dash+1, &errp, 10) || *errp) { -                        return 0; -                } -                *start = clength - number; -                *end = clength - 1;  -        } -        else { -                *dash++ = '\0'; -                if (apr_strtoff(&number, range, &errp, 10) || *errp) { -                        return 0; -                } -                *start = number; -                if (*dash) { -                        if (apr_strtoff(&number, dash, &errp, 10) || *errp) { -                                return 0; -                        } -                        *end = number; -                } -                else {                  /* "5-" */ -                        *end = clength - 1; -                } -        } - -        if (*start < 0) { -                *start = 0; -        } - -        if (*end >= clength) { -                *end = clength - 1; -        } - -        if (*start > *end) { -                return -1; -        } - -        return (*start > 0 || *end < clength); -} - - -static int use_range_x(request_rec *r) -{ -        const char *ua = NULL; -        return (apr_table_get(r->headers_in, "Request-Range") -                || ((ua = apr_table_get(r->headers_in, "User-Agent")) -                    && ap_strstr_c(ua, "MSIE 3"))); -} - - -static int ap_set_byterange(request_rec *r) -{ -        const char *range = NULL, *if_range = NULL, *match = NULL, *ct = NULL; -        int         num_ranges = 0; - -        if (r->assbackwards) { -                return 0; -        } - -        /* Check for Range request-header (HTTP/1.1) or Request-Range for -         * backwards-compatibility with second-draft Luotonen/Franks -         * byte-ranges (e.g. Netscape Navigator 2-3). -         * -         * We support this form, with Request-Range, and (farther down) we -         * send multipart/x-byteranges instead of multipart/byteranges for -         * Request-Range based requests to work around a bug in Netscape -         * Navigator 2-3 and MSIE 3. -         */ - -        if (!(range = apr_table_get(r->headers_in, "Range"))) { -                range = apr_table_get(r->headers_in, "Request-Range"); -        } - -        if (!range || strncasecmp(range, "bytes=", 6) || r->status != HTTP_OK) { -                return 0; -        } - -        /* is content already a single range? */ -        if (apr_table_get(r->headers_out, "Content-Range")) { -                return 0; -        } - -        /* is content already a multiple range? */ -        if ((ct = apr_table_get(r->headers_out, "Content-Type")) -            && (!strncasecmp(ct, "multipart/byteranges", 20) -                || !strncasecmp(ct, "multipart/x-byteranges", 22))) { -                return 0; -        } - -        /* Check the If-Range header for Etag or Date. -         * Note that this check will return false (as required) if either -         * of the two etags are weak. -         */ -        if ((if_range = apr_table_get(r->headers_in, "If-Range"))) { -                if (if_range[0] == '"') { -                        if (!(match = apr_table_get(r->headers_out, "Etag")) -                            || (strcmp(if_range, match) != 0)) { -                                return 0; -                        } -                } -                else if (!(match = apr_table_get(r->headers_out, -                                                 "Last-Modified")) -                         || (strcmp(if_range, match) != 0)) { -                        return 0; -                } -        } - -        if (!ap_strchr_c(range, ',')) { -                /* a single range */ -                num_ranges = 1; -        } -        else { -                /* a multiple range */ -                num_ranges = 2; -        } - -        r->status = HTTP_PARTIAL_CONTENT; -        r->range = range + 6; - -        return num_ranges; -} - - -static void -mod_glfs_handle_byte_ranges (request_rec *r, glusterfs_file_t fd, -                             int num_ranges) -{ -        conn_rec           *c = r->connection; -        char               *ts = NULL, *boundary = NULL, *bound_head = NULL; -        const char         *orig_ct = NULL; -        char               *current = NULL, *end = NULL; -        apr_bucket_brigade *bsend = NULL; -        apr_bucket         *e = NULL; -        apr_off_t           range_start, range_end; -        apr_status_t        rv = APR_SUCCESS; -        char                found = 0; -        apr_bucket         *e2 = NULL, *ec = NULL; - -        orig_ct = ap_make_content_type (r, r->content_type); - -        if (num_ranges > 1) { -                boundary = apr_psprintf(r->pool, "%" APR_UINT64_T_HEX_FMT "%lx", -                                        (apr_uint64_t)r->request_time, -                                        (long) getpid()); - -                ap_set_content_type(r, apr_pstrcat(r->pool, "multipart", -                                                   use_range_x(r) ? "/x-" : "/", -                                                   "byteranges; boundary=", -                                                   boundary, NULL)); - -                if (strcasecmp(orig_ct, NO_CONTENT_TYPE)) { -                        bound_head = apr_pstrcat(r->pool, -                                                 CRLF "--", boundary, -                                                 CRLF "Content-type: ", -                                                 orig_ct, -                                                 CRLF "Content-range: bytes ", -                                                 NULL); -                } -                else { -                        /* if we have no type for the content, do our best */ -                        bound_head = apr_pstrcat(r->pool, -                                                 CRLF "--", boundary, -                                                 CRLF "Content-range: bytes ", -                                                 NULL); -                } -        } - -        while ((current = ap_getword(r->pool, &r->range, ',')) -               && (rv = parse_byterange(current, r->finfo.size, &range_start, -                                        &range_end))) { -                bsend = NULL; -                if (rv == -1) { -                        continue; -                } - -                found = 1; - -                /* For single range requests, we must produce Content-Range  -                 * header. Otherwise, we need to produce the multipart  -                 * boundaries. -                 */ -                if (num_ranges == 1) { -                        apr_table_setn(r->headers_out, "Content-Range", -                                       apr_psprintf(r->pool, -                                                    "bytes " BYTERANGE_FMT, -                                                    range_start, range_end, -                                                    r->finfo.size)); -                } -                else { -                        /* this brigade holds what we will be sending */ -                        bsend = apr_brigade_create(r->pool, c->bucket_alloc); - -                        e = apr_bucket_pool_create(bound_head, -                                                   strlen(bound_head), -                                                   r->pool, c->bucket_alloc); -                        APR_BRIGADE_INSERT_TAIL(bsend, e); - -                        ts = apr_psprintf(r->pool, BYTERANGE_FMT CRLF CRLF, -                                          range_start, range_end, -                                          r->finfo.size); -                        e = apr_bucket_pool_create(ts, strlen(ts), r->pool, -                                                   c->bucket_alloc); -                        APR_BRIGADE_INSERT_TAIL(bsend, e); -                } -                mod_glfs_read_async (r, bsend, fd, range_start, -                                     (range_end + 1 - range_start)); -        } - -        bsend = apr_brigade_create (r->pool, c->bucket_alloc); - -        if (found == 0) { -                r->status = HTTP_OK; -                /* bsend is assumed to be empty if we get here. */ -                e = ap_bucket_error_create(HTTP_RANGE_NOT_SATISFIABLE, NULL, -                                           r->pool, c->bucket_alloc); -                APR_BRIGADE_INSERT_TAIL(bsend, e); -                e = apr_bucket_eos_create(c->bucket_alloc); -                APR_BRIGADE_INSERT_TAIL(bsend, e); -                ap_pass_brigade (r->output_filters, bsend); -                return; -        } - -        if (num_ranges > 1) { -                /* add the final boundary */ -                end = apr_pstrcat(r->pool, CRLF "--", boundary, "--" CRLF, -                                  NULL); -//                ap_xlate_proto_to_ascii(end, strlen(end)); -                e = apr_bucket_pool_create(end, strlen(end), r->pool, -                                           c->bucket_alloc); -                APR_BRIGADE_INSERT_TAIL(bsend, e); -        } - -        ap_pass_brigade (r->output_filters, bsend); -} - - - -/**************************************************************** - * - * Looking things up in config entries... - */ - -/* Structure used to hold entries when we're actually building an index */ - -struct ent { -        char       *name; -        char       *icon; -        char       *alt; -        char       *desc; -        apr_off_t   size; -        apr_time_t  lm; -        struct ent *next; -        int         ascending, ignore_case, version_sort; -        char        key; -        int         isdir; -}; - -static char *find_item(request_rec *r, apr_array_header_t *list, int path_only) -{ -        const char              *content_type = NULL; -        const char              *content_encoding = NULL; -        char                    *path = NULL; -        int                      i = 0; -        struct mod_glfs_ai_item *items = NULL; -        struct mod_glfs_ai_item *p = NULL; - -        content_type = ap_field_noparam(r->pool, r->content_type); -        content_encoding = r->content_encoding; -        path = r->filename; -        items = (struct mod_glfs_ai_item *) list->elts; - -        for (i = 0; i < list->nelts; ++i) { -                p = &items[i]; -                /* Special cased for ^^DIRECTORY^^ and ^^BLANKICON^^ */ -                if ((path[0] == '^') || (!ap_strcmp_match(path, -                                                          p->apply_path))) { -                        if (!*(p->apply_to)) { -                                return p->data; -                        } -                        else if (p->type == BY_PATH || path[0] == '^') { -                                if (!ap_strcmp_match(path, p->apply_to)) { -                                        return p->data; -                                } -                        } -                        else if (!path_only) { -                                if (!content_encoding) { -                                        if (p->type == BY_TYPE) { -                                                if (content_type -                                                    && !ap_strcasecmp_match(content_type, -                                                                            p->apply_to)) { -                                                        return p->data; -                                                } -                                        } -                                } -                                else { -                                        if (p->type == BY_ENCODING) { -                                                if (!ap_strcasecmp_match(content_encoding, -                                                                         p->apply_to)) { -                                                        return p->data; -                                                } -                                        } -                                } -                        } -                } -        } -        return NULL; -} - -#define find_icon(d,p,t) find_item(p,d->icon_list,t) -#define find_alt(d,p,t) find_item(p,d->alt_list,t) -#define find_header(d,p) find_item(p,d->hdr_list,0) -#define find_readme(d,p) find_item(p,d->rdme_list,0) - -static char *find_default_item(char *bogus_name, apr_array_header_t *list) -{ -        request_rec r; -        /* Bleah.  I tried to clean up find_item, and it lead to this bit -         * of ugliness.   Note that the fields initialized are precisely -         * those that find_item looks at... -         */ -        r.filename = bogus_name; -        r.content_type = r.content_encoding = NULL; -        return find_item(&r, list, 1); -} - -#define find_default_icon(d,n) find_default_item(n, d->icon_list) -#define find_default_alt(d,n) find_default_item(n, d->alt_list) - -/* - * Look through the list of pattern/description pairs and return the first one - * if any) that matches the filename in the request.  If multiple patterns - * match, only the first one is used; since the order in the array is the - * same as the order in which directives were processed, earlier matching - * directives will dominate. - */ - -#ifdef CASE_BLIND_FILESYSTEM -#define MATCH_FLAGS APR_FNM_CASE_BLIND -#else -#define MATCH_FLAGS 0 -#endif - -static char *find_desc(glusterfs_dir_config_t *dcfg, const char *filename_full) -{ -        int                 i = 0; -        mod_glfs_ai_desc_t *list = NULL; -        const char         *filename_only = NULL, *filename = NULL; -        mod_glfs_ai_desc_t *tuple = &list[i]; -        int                 found = 0; - -        list = (mod_glfs_ai_desc_t *) dcfg->desc_list->elts; -        /* -         * If the filename includes a path, extract just the name itself -         * for the simple matches. -         */ -        if ((filename_only = ap_strrchr_c(filename_full, '/')) == NULL) { -                filename_only = filename_full; -        } -        else { -                filename_only++; -        } -        for (i = 0; i < dcfg->desc_list->nelts; ++i) { -                /* -                 * Only use the full-path filename if the pattern contains '/'s. -                 */ -                filename = (tuple->full_path) ? filename_full : filename_only; -                /* -                 * Make the comparison using the cheapest method; only do -                 * wildcard checking if we must. -                 */ -                if (tuple->wildcards) { -                        found = (apr_fnmatch(tuple->pattern, filename, -                                             MATCH_FLAGS) == 0); -                } -                else { -                        found = (ap_strstr_c(filename, tuple->pattern) != NULL); -                } -                if (found) { -                        return tuple->description; -                } -        } -        return NULL; -} - -static int ignore_entry(glusterfs_dir_config_t *d, char *path) -{ -        apr_array_header_t      *list = d->ign_list; -        struct mod_glfs_ai_item *items = (struct mod_glfs_ai_item *) list->elts; -        char                    *tt = NULL, *ap = NULL; -        int                      i = 0; -        struct mod_glfs_ai_item *p = &items[i]; - -        if ((tt = strrchr(path, '/')) == NULL) { -                tt = path; -        } -        else { -                tt++; -        } - -        for (i = 0; i < list->nelts; ++i) { -                p = &items[i]; -                if ((ap = strrchr(p->apply_to, '/')) == NULL) { -                        ap = p->apply_to; -                } -                else { -                        ap++; -                } - -#ifndef CASE_BLIND_FILESYSTEM -                if (!ap_strcmp_match(path, p->apply_path) -                    && !ap_strcmp_match(tt, ap)) { -                        return 1; -                } -#else  /* !CASE_BLIND_FILESYSTEM */ -                /* -                 * On some platforms, the match must be case-blind.  This is really -                 * a factor of the filesystem involved, but we can't detect that -                 * reliably - so we have to granularise at the OS level. -                 */ -                if (!ap_strcasecmp_match(path, p->apply_path) -                    && !ap_strcasecmp_match(tt, ap)) { -                        return 1; -                } -#endif /* !CASE_BLIND_FILESYSTEM */ -        } -        return 0; -} - -/***************************************************************** - * - * Actually generating output - */ - -/* - * Elements of the emitted document: - *      Preamble - *              Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req - *              succeeds for the (content_type == text/html) header file. - *      Header file - *              Emitted if found (and able). - *      H1 tag line - *              Emitted if a header file is NOT emitted. - *      Directory stuff - *              Always emitted. - *      HR - *              Emitted if FANCY_INDEXING is set. - *      Readme file - *              Emitted if found (and able). - *      ServerSig - *              Emitted if ServerSignature is not Off AND a readme file - *              is NOT emitted. - *      Postamble - *              Emitted unless SUPPRESS_PREAMBLE is set AND ap_run_sub_req - *              succeeds for the (content_type == text/html) readme file. - */ - - -/* - * emit a plain text file - */ -static void do_emit_plain(request_rec *r, apr_file_t *f) -{ -        char         buf[AP_IOBUFSIZE + 1]; -        int          ch = 0; -        apr_size_t   i = 0, c = 0, n = 0; -        apr_status_t rv = APR_SUCCESS; - -        ap_rputs("<pre>\n", r); -        while (!apr_file_eof(f)) { -                do { -                        n = sizeof(char) * AP_IOBUFSIZE; -                        rv = apr_file_read(f, buf, &n); -                } while (APR_STATUS_IS_EINTR(rv)); -                if (n == 0 || rv != APR_SUCCESS) { -                        /* ###: better error here? */ -                        break; -                } -                buf[n] = '\0'; -                c = 0; -                while (c < n) { -                        for (i = c; i < n; i++) { -                                if (buf[i] == '<' || buf[i] == '>' -                                    || buf[i] == '&') { -                                        break; -                                } -                        } -                        ch = buf[i]; -                        buf[i] = '\0'; -                        ap_rputs(&buf[c], r); -                        if (ch == '<') { -                                ap_rputs("<", r); -                        } -                        else if (ch == '>') { -                                ap_rputs(">", r); -                        } -                        else if (ch == '&') { -                                ap_rputs("&", r); -                        } -                        c = i + 1; -                } -        } -        ap_rputs("</pre>\n", r); -} - -/* - * Handle the preamble through the H1 tag line, inclusive.  Locate - * the file with a subrequests.  Process text/html documents by actually - * running the subrequest; text/xxx documents get copied verbatim, - * and any other content type is ignored.  This means that a non-text - * document (such as HEADER.gif) might get multiviewed as the result - * instead of a text document, meaning nothing will be displayed, but - * oh well. - */ -static void emit_head(request_rec *r, char *header_fname, int suppress_amble, -                      int emit_xhtml, char *title) -{ -        apr_table_t *hdrs = r->headers_in; -        apr_file_t  *f = NULL; -        request_rec *rr = NULL; -        int          emit_amble = 1; -        int          emit_H1 = 1; -        const char  *r_accept = NULL; -        const char  *r_accept_enc = NULL; - -        /* -         * If there's a header file, send a subrequest to look for it.  If it's -         * found and html do the subrequest, otherwise handle it -         */ -        r_accept = apr_table_get(hdrs, "Accept"); -        r_accept_enc = apr_table_get(hdrs, "Accept-Encoding"); -        apr_table_setn(hdrs, "Accept", "text/html, text/plain"); -        apr_table_unset(hdrs, "Accept-Encoding"); - - -        if ((header_fname != NULL) && r->args) { -                header_fname = apr_pstrcat(r->pool, header_fname, "?", r->args, -                                           NULL); -        } - -        if ((header_fname != NULL) -            && (rr = ap_sub_req_lookup_uri(header_fname, r, r->output_filters)) -            && (rr->status == HTTP_OK) -            && (rr->filename != NULL) -            && (rr->finfo.filetype == APR_REG)) { -                /* -                 * Check for the two specific cases we allow: text/html and -                 * text/anything-else.  The former is allowed to be processed for -                 * SSIs. -                 */ -                if (rr->content_type != NULL) { -                        if (!strcasecmp(ap_field_noparam(r->pool, -                                                         rr->content_type), -                                        "text/html")) { -                                ap_filter_t *f = NULL; -         -                                /* Hope everything will work... */ -                                emit_amble = 0; -                                emit_H1 = 0; - -                                if (! suppress_amble) { -                                        emit_preamble(r, emit_xhtml, title); -                                } -                                /* This is a hack, but I can't find any better  -                                 * way to do this. The problem is that we have  -                                 * already created the sub-request, -                                 * but we just inserted the OLD_WRITE filter,  -                                 * and the sub-request needs to pass its data  -                                 * through the OLD_WRITE filter, or things go  -                                 * horribly wrong (missing data, data in -                                 * the wrong order, etc).  To fix it, if you  -                                 * create a sub-request and then insert the  -                                 * OLD_WRITE filter before you run the request,  -                                 * you need to make sure that the sub-request -                                 * data goes through the OLD_WRITE filter.  Just -                                 * steal this code.  The long-term solution is  -                                 * to remove the ap_r* functions. -                                 */ -                                for (f=rr->output_filters; -                                     f->frec != ap_subreq_core_filter_handle; -                                     f = f->next); -                                f->next = r->output_filters; - -                                /* -                                 * If there's a problem running the subrequest,  -                                 * display the preamble if we didn't do it  -                                 * before -- the header file didn't get displayed. -                                 */ -                                if (ap_run_sub_req(rr) != OK) { -                                        /* It didn't work */ -                                        emit_amble = suppress_amble; -                                        emit_H1 = 1; -                                } -                        } -                        else if (!strncasecmp("text/", rr->content_type, 5)) { -                                /* -                                 * If we can open the file, prefix it with the  -                                 * preamble regardless; since we'll be sending  -                                 * a <pre> block around the file's contents,  -                                 * any HTML header it had won't end up -                                 * where it belongs. -                                 */ -                                if (apr_file_open(&f, rr->filename, APR_READ, -                                                  APR_OS_DEFAULT, r->pool)  -                                    == APR_SUCCESS) { -                                        emit_preamble(r, emit_xhtml, title); -                                        emit_amble = 0; -                                        do_emit_plain(r, f); -                                        apr_file_close(f); -                                        emit_H1 = 0; -                                } -                        } -                } -        } - -        if (r_accept) { -                apr_table_setn(hdrs, "Accept", r_accept); -        } -        else { -                apr_table_unset(hdrs, "Accept"); -        } - -        if (r_accept_enc) { -                apr_table_setn(hdrs, "Accept-Encoding", r_accept_enc); -        } - -        if (emit_amble) { -                emit_preamble(r, emit_xhtml, title); -        } -        if (emit_H1) { -                ap_rvputs(r, "<h1>Index of ", title, "</h1>\n", NULL); -        } -        if (rr != NULL) { -                ap_destroy_sub_req(rr); -        } -} - - -/* - * Handle the Readme file through the postamble, inclusive.  Locate - * the file with a subrequests.  Process text/html documents by actually - * running the subrequest; text/xxx documents get copied verbatim, - * and any other content type is ignored.  This means that a non-text - * document (such as FOOTER.gif) might get multiviewed as the result - * instead of a text document, meaning nothing will be displayed, but - * oh well. - */ -static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble) -{ -        apr_file_t  *f = NULL; -        request_rec *rr = NULL; -        int          suppress_post = 0, suppress_sig = 0; - -        /* -         * If there's a readme file, send a subrequest to look for it.  If it's -         * found and a text file, handle it -- otherwise fall through and -         * pretend there's nothing there. -         */ -        if ((readme_fname != NULL) -            && (rr = ap_sub_req_lookup_uri(readme_fname, r, r->output_filters)) -            && (rr->status == HTTP_OK) -            && (rr->filename != NULL) -            && rr->finfo.filetype == APR_REG) { -                /* -                 * Check for the two specific cases we allow: text/html and -                 * text/anything-else.  The former is allowed to be processed for -                 * SSIs. -                 */ -                if (rr->content_type != NULL) { -                        if (!strcasecmp(ap_field_noparam(r->pool, -                                                         rr->content_type), -                                        "text/html")) { -                                ap_filter_t *f; -                                for (f=rr->output_filters; -                                     f->frec != ap_subreq_core_filter_handle; -                                     f = f->next); -                                f->next = r->output_filters; - - -                                if (ap_run_sub_req(rr) == OK) { -                                        /* worked... */ -                                        suppress_sig = 1; -                                        suppress_post = suppress_amble; -                                } -                        } -                        else if (!strncasecmp("text/", rr->content_type, 5)) { -                                /* -                                 * If we can open the file, suppress the signature. -                                 */ -                                if (apr_file_open(&f, rr->filename, APR_READ, -                                                  APR_OS_DEFAULT, r->pool) -                                    == APR_SUCCESS) { -                                        do_emit_plain(r, f); -                                        apr_file_close(f); -                                        suppress_sig = 1; -                                } -                        } -                } -        } - -        if (!suppress_sig) { -                ap_rputs(ap_psignature("", r), r); -        } -        if (!suppress_post) { -                ap_rputs("</body></html>\n", r); -        } -        if (rr != NULL) { -                ap_destroy_sub_req(rr); -        } -} - - -static char *find_title(request_rec *r) -{ -        char        titlebuf[MAX_STRING_LEN], *find = "<title>"; -        apr_file_t *thefile = NULL; -        int         x = 0, y = 0, p = 0; -        apr_size_t  n; - -        if (r->status != HTTP_OK) { -                return NULL; -        } -        if ((r->content_type != NULL) -            && (!strcasecmp(ap_field_noparam(r->pool, r->content_type), -                            "text/html") -                || !strcmp(r->content_type, INCLUDES_MAGIC_TYPE)) -            && !r->content_encoding) { -                if (apr_file_open(&thefile, r->filename, APR_READ, -                                  APR_OS_DEFAULT, r->pool) != APR_SUCCESS) { -                        return NULL; -                } -                n = sizeof(char) * (MAX_STRING_LEN - 1); -                apr_file_read(thefile, titlebuf, &n); -                if (n <= 0) { -                        apr_file_close(thefile); -                        return NULL; -                } -                titlebuf[n] = '\0'; -                for (x = 0, p = 0; titlebuf[x]; x++) { -                        if (apr_tolower(titlebuf[x]) == find[p]) { -                                if (!find[++p]) { -                                        if ((p = ap_ind(&titlebuf[++x], '<')) -                                            != -1) { -                                                titlebuf[x + p] = '\0'; -                                        } -                                        /* Scan for line breaks for Tanmoy's  -                                           secretary -                                        */ -                                        for (y = x; titlebuf[y]; y++) { -                                                if ((titlebuf[y] == CR)  -                                                    || (titlebuf[y] == LF)) { -                                                        if (y == x) { -                                                                x++; -                                                        } -                                                        else { -                                                                titlebuf[y] = ' '; -                                                        } -                                                } -                                        } -                                        apr_file_close(thefile); -                                        return apr_pstrdup(r->pool, -                                                           &titlebuf[x]); -                                } -                        } -                        else { -                                p = 0; -                        } -                } -                apr_file_close(thefile); -        } -        return NULL; -} - -static struct ent *make_parent_entry(apr_int32_t autoindex_opts, -                                     glusterfs_dir_config_t *d, -                                     request_rec *r, char keyid, -                                     char direction) -{ -        struct ent *p = NULL; -        char       *testpath = NULL; -        /* -         * p->name is now the true parent URI. -         * testpath is a crafted lie, so that the syntax '/some/..' -         * (or simply '..')be used to describe 'up' from '/some/' -         * when processeing IndexIgnore, and Icon|Alt|Desc configs. -         */ - -        p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent)); -        /* The output has always been to the parent.  Don't make ourself -         * our own parent (worthless cyclical reference). -         */ -        if (!(p->name = ap_make_full_path(r->pool, r->uri, "../"))) { -                return (NULL); -        } -        ap_getparents(p->name); -        if (!*p->name) { -                return (NULL); -        } - -        /* IndexIgnore has always compared "/thispath/.." */ -        testpath = ap_make_full_path(r->pool, r->filename, ".."); -        if (ignore_entry(d, testpath)) { -                return (NULL); -        } - -        p->size = -1; -        p->lm = -1; -        p->key = apr_toupper(keyid); -        p->ascending = (apr_toupper(direction) == D_ASCENDING); -        p->version_sort = autoindex_opts & VERSION_SORT; -        if (autoindex_opts & FANCY_INDEXING) { -                if (!(p->icon = find_default_icon(d, testpath))) { -                        p->icon = find_default_icon(d, "^^DIRECTORY^^"); -                } -                if (!(p->alt = find_default_alt(d, testpath))) { -                        if (!(p->alt = find_default_alt(d, "^^DIRECTORY^^"))) { -                                p->alt = "DIR"; -                        } -                } -                p->desc = find_desc(d, testpath); -        } -        return p; -} - -static struct ent *make_autoindex_entry(const apr_finfo_t *dirent, -                                        int autoindex_opts, -                                        glusterfs_dir_config_t *d, -                                        request_rec *r, char keyid, -                                        char direction, -                                        const char *pattern) -{ -        request_rec *rr = NULL; -        struct ent  *p = NULL; -        int          show_forbidden = 0; - -        /* Dot is ignored, Parent is handled by make_parent_entry() */ -        if ((dirent->name[0] == '.') && (!dirent->name[1] -                                         || ((dirent->name[1] == '.') -                                             && !dirent->name[2]))) -                return (NULL); - -        /* -         * On some platforms, the match must be case-blind.  This is really -         * a factor of the filesystem involved, but we can't detect that -         * reliably - so we have to granularise at the OS level. -         */ -        if (pattern && (apr_fnmatch(pattern, dirent->name, -                                    APR_FNM_NOESCAPE | APR_FNM_PERIOD -#ifdef CASE_BLIND_FILESYSTEM -                                    | APR_FNM_CASE_BLIND -#endif -                                ) -                        != APR_SUCCESS)) { -                return (NULL); -        } - -        if (ignore_entry(d, ap_make_full_path(r->pool, -                                              r->filename, dirent->name))) { -                return (NULL); -        } - -        if (!(rr = ap_sub_req_lookup_dirent(dirent, r, AP_SUBREQ_NO_ARGS, -                                            NULL))) { -                return (NULL); -        } - -        if((autoindex_opts & SHOW_FORBIDDEN) -           && (rr->status == HTTP_UNAUTHORIZED -               || rr->status == HTTP_FORBIDDEN)) { -                show_forbidden = 1; -        } - -        if ((rr->finfo.filetype != APR_DIR && rr->finfo.filetype != APR_REG) -            || !(rr->status == OK || ap_is_HTTP_SUCCESS(rr->status) -                 || ap_is_HTTP_REDIRECT(rr->status) -                 || show_forbidden == 1)) { -                ap_destroy_sub_req(rr); -                return (NULL); -        } - -        p = (struct ent *) apr_pcalloc(r->pool, sizeof(struct ent)); -        if (dirent->filetype == APR_DIR) { -                p->name = apr_pstrcat(r->pool, dirent->name, "/", NULL); -        } -        else { -                p->name = apr_pstrdup(r->pool, dirent->name); -        } -        p->size = -1; -        p->icon = NULL; -        p->alt = NULL; -        p->desc = NULL; -        p->lm = -1; -        p->isdir = 0; -        p->key = apr_toupper(keyid); -        p->ascending = (apr_toupper(direction) == D_ASCENDING); -        p->version_sort = !!(autoindex_opts & VERSION_SORT); -        p->ignore_case = !!(autoindex_opts & IGNORE_CASE); - -        if (autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING)) { -                p->lm = rr->finfo.mtime; -                if (dirent->filetype == APR_DIR) { -                        if (autoindex_opts & FOLDERS_FIRST) { -                                p->isdir = 1; -                        } -                        rr->filename = ap_make_dirstr_parent (rr->pool, -                                                              rr->filename); - -                        /* omit the trailing slash (1.3 compat) */ -                        rr->filename[strlen(rr->filename) - 1] = '\0'; - -                        if (!(p->icon = find_icon(d, rr, 1))) { -                                p->icon = find_default_icon(d, "^^DIRECTORY^^"); -                        } -                        if (!(p->alt = find_alt(d, rr, 1))) { -                                if (!(p->alt = find_default_alt(d, -                                                                "^^DIRECTORY^^"))) { -                                        p->alt = "DIR"; -                                } -                        } -                } -                else { -                        p->icon = find_icon(d, rr, 0); -                        p->alt = find_alt(d, rr, 0); -                        p->size = rr->finfo.size; -                } - -                p->desc = find_desc(d, rr->filename); - -                if ((!p->desc) && (autoindex_opts & SCAN_HTML_TITLES)) { -                        p->desc = apr_pstrdup(r->pool, find_title(rr)); -                } -        } -        ap_destroy_sub_req(rr); -        /* -         * We don't need to take any special action for the file size key. -         * If we did, it would go here. -         */ -        if (keyid == K_LAST_MOD) { -                if (p->lm < 0) { -                        p->lm = 0; -                } -        } -        return (p); -} - -static char *terminate_description(glusterfs_dir_config_t *d, char *desc, -                                   apr_int32_t autoindex_opts, int desc_width) -{ -        int          maxsize = desc_width; -        register int x = 0; - -        /* -         * If there's no DescriptionWidth in effect, default to the old -         * behaviour of adjusting the description size depending upon -         * what else is being displayed.  Otherwise, stick with the -         * setting. -         */ -        if (d->desc_adjust == K_UNSET) { -                if (autoindex_opts & SUPPRESS_ICON) { -                        maxsize += 6; -                } -                if (autoindex_opts & SUPPRESS_LAST_MOD) { -                        maxsize += 19; -                } -                if (autoindex_opts & SUPPRESS_SIZE) { -                        maxsize += 7; -                } -        } -        for (x = 0; desc[x] && ((maxsize > 0) || (desc[x] == '<')); x++) { -                if (desc[x] == '<') { -                        while (desc[x] != '>') { -                                if (!desc[x]) { -                                        maxsize = 0; -                                        break; -                                } -                                ++x; -                        } -                } -                else if (desc[x] == '&') { -                        /* entities like ä count as one character */ -                        --maxsize; -                        for ( ; desc[x] != ';'; ++x) { -                                if (desc[x] == '\0') { -                                        maxsize = 0; -                                        break; -                                } -                        } -                } -                else { -                        --maxsize; -                } -        } -        if (!maxsize && desc[x] != '\0') { -                desc[x - 1] = '>';      /* Grump. */ -                desc[x] = '\0';         /* Double Grump! */ -        } -        return desc; -} - -/* - * Emit the anchor for the specified field.  If a field is the key for the - * current request, the link changes its meaning to reverse the order when - * selected again.  Non-active fields always start in ascending order. - */ -static void emit_link(request_rec *r, const char *anchor, char column, -                      char curkey, char curdirection, -                      const char *colargs, int nosort) -{ -        char qvalue[9]; - -        if (!nosort) { - -                qvalue[0] = '?'; -                qvalue[1] = 'C'; -                qvalue[2] = '='; -                qvalue[3] = column; -                qvalue[4] = ';'; -                qvalue[5] = 'O'; -                qvalue[6] = '='; -                /* reverse? */ -                qvalue[7] = ((curkey == column) && (curdirection == D_ASCENDING)) -                        ? D_DESCENDING : D_ASCENDING; -                qvalue[8] = '\0'; -                ap_rvputs(r, "<a href=\"", qvalue, colargs ? colargs : "", -                          "\">", anchor, "</a>", NULL); -        } -        else { -                ap_rputs(anchor, r); -        } -} - -static void output_directories(struct ent **ar, int n, -                               glusterfs_dir_config_t *d, request_rec *r, -                               apr_int32_t autoindex_opts, char keyid, -                               char direction, const char *colargs) -{ -        int            x = 0; -        apr_size_t     rv = APR_SUCCESS; -        char          *name = NULL, *tp = NULL; -        int            static_columns = 0; -        apr_pool_t    *scratch = NULL; -        int            name_width = 0, desc_width = 0, cols = 0; -        char          *name_scratch = NULL, *pad_scratch = NULL, *breakrow = ""; -        char          *anchor = NULL, *t = NULL, *t2 = NULL; -        int            nwidth = 0; -        char           time_str[MAX_STRING_LEN]; -        apr_time_exp_t ts = {0, }; -        char           buf[5]; - -        name = r->uri; -        static_columns = !!(autoindex_opts & SUPPRESS_COLSORT); -        apr_pool_create(&scratch, r->pool); -        if (name[0] == '\0') { -                name = "/"; -        } - -        name_width = d->name_width; -        desc_width = d->desc_width; - -        if ((autoindex_opts & (FANCY_INDEXING | TABLE_INDEXING)) -            == FANCY_INDEXING) { -                if (d->name_adjust == K_ADJUST) { -                        for (x = 0; x < n; x++) { -                                int t = 0; -                                t = strlen(ar[x]->name); -                                if (t > name_width) { -                                        name_width = t; -                                } -                        } -                } - -                if (d->desc_adjust == K_ADJUST) { -                        for (x = 0; x < n; x++) { -                                if (ar[x]->desc != NULL) { -                                        int t = 0; -                                        t = strlen(ar[x]->desc); -                                        if (t > desc_width) { -                                                desc_width = t; -                                        } -                                } -                        } -                } -        } -        name_scratch = apr_palloc(r->pool, name_width + 1); -        pad_scratch = apr_palloc(r->pool, name_width + 1); -        memset(pad_scratch, ' ', name_width); -        pad_scratch[name_width] = '\0'; - -        if (autoindex_opts & TABLE_INDEXING) { -                cols = 1; -                ap_rputs("<table><tr>", r); -                if (!(autoindex_opts & SUPPRESS_ICON)) { -                        ap_rputs("<th>", r); -                        if ((tp = find_default_icon(d, "^^BLANKICON^^"))) { -                                ap_rvputs(r, "<img src=\"", -                                          ap_escape_html(scratch, tp), -                                          "\" alt=\"[ICO]\"", NULL); -                                if (d->icon_width) { -                                        ap_rprintf(r, " width=\"%d\"", -                                                   d->icon_width); -                                } -                                if (d->icon_height) { -                                        ap_rprintf(r, " height=\"%d\"", -                                                   d->icon_height); -                                } - -                                if (autoindex_opts & EMIT_XHTML) { -                                        ap_rputs(" /", r); -                                } -                                ap_rputs("></th>", r); -                        } -                        else { -                                ap_rputs(" </th>", r); -                        } - -                        ++cols; -                } -                ap_rputs("<th>", r); -                emit_link(r, "Name", K_NAME, keyid, direction, -                          colargs, static_columns); -                if (!(autoindex_opts & SUPPRESS_LAST_MOD)) { -                        ap_rputs("</th><th>", r); -                        emit_link(r, "Last modified", K_LAST_MOD, keyid, -                                  direction, colargs, static_columns); -                        ++cols; -                } -                if (!(autoindex_opts & SUPPRESS_SIZE)) { -                        ap_rputs("</th><th>", r); -                        emit_link(r, "Size", K_SIZE, keyid, direction, -                                  colargs, static_columns); -                        ++cols; -                } -                if (!(autoindex_opts & SUPPRESS_DESC)) { -                        ap_rputs("</th><th>", r); -                        emit_link(r, "Description", K_DESC, keyid, direction, -                                  colargs, static_columns); -                        ++cols; -                } -                if (!(autoindex_opts & SUPPRESS_RULES)) { -                        breakrow = apr_psprintf(r->pool, -                                                "<tr><th colspan=\"%d\">" -                                                "<hr%s></th></tr>\n", cols, -                                                (autoindex_opts & EMIT_XHTML)  -                                                ? " /" : ""); -                } -                ap_rvputs(r, "</th></tr>", breakrow, NULL); -        } -        else if (autoindex_opts & FANCY_INDEXING) { -                ap_rputs("<pre>", r); -                if (!(autoindex_opts & SUPPRESS_ICON)) { -                        if ((tp = find_default_icon(d, "^^BLANKICON^^"))) { -                                ap_rvputs(r, "<img src=\"", -                                          ap_escape_html(scratch, tp), -                                          "\" alt=\"Icon \"", NULL); -                                if (d->icon_width) { -                                        ap_rprintf(r, " width=\"%d\"", -                                                   d->icon_width); -                                } -                                if (d->icon_height) { -                                        ap_rprintf(r, " height=\"%d\"", -                                                   d->icon_height); -                                } - -                                if (autoindex_opts & EMIT_XHTML) { -                                        ap_rputs(" /", r); -                                } -                                ap_rputs("> ", r); -                        } -                        else { -                                ap_rputs("      ", r); -                        } -                } -                emit_link(r, "Name", K_NAME, keyid, direction, -                          colargs, static_columns); -                ap_rputs(pad_scratch + 4, r); -                /* -                 * Emit the guaranteed-at-least-one-space-between-columns byte. -                 */ -                ap_rputs(" ", r); -                if (!(autoindex_opts & SUPPRESS_LAST_MOD)) { -                        emit_link(r, "Last modified", K_LAST_MOD, keyid, -                                  direction, colargs, static_columns); -                        ap_rputs("      ", r); -                } -                if (!(autoindex_opts & SUPPRESS_SIZE)) { -                        emit_link(r, "Size", K_SIZE, keyid, direction, -                                  colargs, static_columns); -                        ap_rputs("  ", r); -                } -                if (!(autoindex_opts & SUPPRESS_DESC)) { -                        emit_link(r, "Description", K_DESC, keyid, direction, -                                  colargs, static_columns); -                } -                if (!(autoindex_opts & SUPPRESS_RULES)) { -                        ap_rputs("<hr", r); -                        if (autoindex_opts & EMIT_XHTML) { -                                ap_rputs(" /", r); -                        } -                        ap_rputs(">", r); -                } -                else { -                        ap_rputc('\n', r); -                } -        } -        else { -                ap_rputs("<ul>", r); -        } - -        for (x = 0; x < n; x++) { -                apr_pool_clear(scratch); - -                t = ar[x]->name; -                anchor = ap_escape_html(scratch, ap_os_escape_path(scratch, t, -                                                                   0)); - -                if (!x && t[0] == '/') { -                        t2 = "Parent Directory"; -                } -                else { -                        t2 = t; -                } - -                if (autoindex_opts & TABLE_INDEXING) { -                        ap_rputs("<tr>", r); -                        if (!(autoindex_opts & SUPPRESS_ICON)) { -                                ap_rputs("<td valign=\"top\">", r); -                                if (autoindex_opts & ICONS_ARE_LINKS) { -                                        ap_rvputs(r, "<a href=\"", anchor, -                                                  "\">", NULL); -                                } -                                if ((ar[x]->icon) || d->default_icon) { -                                        ap_rvputs(r, "<img src=\"", -                                                  ap_escape_html(scratch, -                                                                 ar[x]->icon ? -                                                                 ar[x]->icon -                                                                 : d->default_icon), -                                                  "\" alt=\"[", -                                                  (ar[x]->alt ?  -                                                   ar[x]->alt : "   "), -                                                  "]\"", NULL); -                                        if (d->icon_width) { -                                                ap_rprintf(r, " width=\"%d\"", -                                                           d->icon_width); -                                        } -                                        if (d->icon_height) { -                                                ap_rprintf(r, " height=\"%d\"", -                                                           d->icon_height); -                                        } - -                                        if (autoindex_opts & EMIT_XHTML) { -                                                ap_rputs(" /", r); -                                        } -                                        ap_rputs(">", r); -                                } -                                else { -                                        ap_rputs(" ", r); -                                } -                                if (autoindex_opts & ICONS_ARE_LINKS) { -                                        ap_rputs("</a></td>", r); -                                } -                                else { -                                        ap_rputs("</td>", r); -                                } -                        } -                        if (d->name_adjust == K_ADJUST) { -                                ap_rvputs(r, "<td><a href=\"", anchor, "\">", -                                          ap_escape_html(scratch, t2), "</a>", -                                          NULL); -                        } -                        else { -                                nwidth = strlen(t2); -                                if (nwidth > name_width) { -                                        memcpy(name_scratch, t2, name_width - 3); -                                        name_scratch[name_width - 3] = '.'; -                                        name_scratch[name_width - 2] = '.'; -                                        name_scratch[name_width - 1] = '>'; -                                        name_scratch[name_width] = 0; -                                        t2 = name_scratch; -                                        nwidth = name_width; -                                } -                                ap_rvputs(r, "<td><a href=\"", anchor, "\">", -                                          ap_escape_html(scratch, t2), -                                          "</a>", pad_scratch + nwidth, NULL); -                        } -                        if (!(autoindex_opts & SUPPRESS_LAST_MOD)) { -                                if (ar[x]->lm != -1) { -                                        char time_str[MAX_STRING_LEN]; -                                        apr_time_exp_t ts; -                                        apr_time_exp_lt(&ts, ar[x]->lm); -                                        apr_strftime(time_str, &rv, -                                                     MAX_STRING_LEN, -                                                     "</td><td align=\"right\"" -                                                     ">%d-%b-%Y %H:%M  ", -                                                     &ts); -                                        ap_rputs(time_str, r); -                                } -                                else { -                                        ap_rputs("</td><td> ", r); -                                } -                        } -                        if (!(autoindex_opts & SUPPRESS_SIZE)) { -                                ap_rvputs(r, "</td><td align=\"right\">", -                                          apr_strfsize(ar[x]->size, buf), NULL); -                        } -                        if (!(autoindex_opts & SUPPRESS_DESC)) { -                                if (ar[x]->desc) { -                                        if (d->desc_adjust == K_ADJUST) { -                                                ap_rvputs(r, "</td><td>", -                                                          ar[x]->desc, NULL); -                                        } -                                        else { -                                                ap_rvputs(r, "</td><td>", -                                                          terminate_description(d, ar[x]->desc, -                                                                                autoindex_opts, -                                                                                desc_width), NULL); -                                        } -                                } -                        } -                        else { -                                ap_rputs("</td><td> ", r); -                        } -                        ap_rputs("</td></tr>\n", r); -                } -                else if (autoindex_opts & FANCY_INDEXING) { -                        if (!(autoindex_opts & SUPPRESS_ICON)) { -                                if (autoindex_opts & ICONS_ARE_LINKS) { -                                        ap_rvputs(r, "<a href=\"", anchor, -                                                  "\">", NULL); -                                } -                                if ((ar[x]->icon) || d->default_icon) { -                                        ap_rvputs(r, "<img src=\"", -                                                  ap_escape_html(scratch, -                                                                 ar[x]->icon ? -                                                                 ar[x]->icon -                                                                 : d->default_icon), -                                                  "\" alt=\"[", -                                                  (ar[x]->alt ? ar[x]->alt  -                                                   : "   "), -                                                  "]\"", NULL); -                                        if (d->icon_width) { -                                                ap_rprintf(r, " width=\"%d\"", -                                                           d->icon_width); -                                        } -                                        if (d->icon_height) { -                                                ap_rprintf(r, " height=\"%d\"", -                                                           d->icon_height); -                                        } - -                                        if (autoindex_opts & EMIT_XHTML) { -                                                ap_rputs(" /", r); -                                        } -                                        ap_rputs(">", r); -                                } -                                else { -                                        ap_rputs("     ", r); -                                } -                                if (autoindex_opts & ICONS_ARE_LINKS) { -                                        ap_rputs("</a> ", r); -                                } -                                else { -                                        ap_rputc(' ', r); -                                } -                        } -                        nwidth = strlen(t2); -                        if (nwidth > name_width) { -                                memcpy(name_scratch, t2, name_width - 3); -                                name_scratch[name_width - 3] = '.'; -                                name_scratch[name_width - 2] = '.'; -                                name_scratch[name_width - 1] = '>'; -                                name_scratch[name_width] = 0; -                                t2 = name_scratch; -                                nwidth = name_width; -                        } -                        ap_rvputs(r, "<a href=\"", anchor, "\">", -                                  ap_escape_html(scratch, t2), -                                  "</a>", pad_scratch + nwidth, NULL); -                        /* -                         * The blank before the storm.. er, before the next -                         * field. -                         */ -                        ap_rputs(" ", r); -                        if (!(autoindex_opts & SUPPRESS_LAST_MOD)) { -                                if (ar[x]->lm != -1) { -                                        apr_time_exp_lt(&ts, ar[x]->lm); -                                        apr_strftime(time_str, &rv, -                                                     MAX_STRING_LEN, -                                                     "%d-%b-%Y %H:%M  ", &ts); -                                        ap_rputs(time_str, r); -                                } -                                else { -                                        /* Length="22-Feb-1998 23:42  "  -                                         * (see 4 lines above) -                                         */ -                                        ap_rputs("                   ", r); -                                } -                        } -                        if (!(autoindex_opts & SUPPRESS_SIZE)) { -                                ap_rputs(apr_strfsize(ar[x]->size, buf), r); -                                ap_rputs("  ", r); -                        } -                        if (!(autoindex_opts & SUPPRESS_DESC)) { -                                if (ar[x]->desc) { -                                        ap_rputs(terminate_description(d, -                                                                       ar[x]->desc, -                                                                       autoindex_opts, -                                                                       desc_width), r); -                                } -                        } -                        ap_rputc('\n', r); -                } -                else { -                        ap_rvputs(r, "<li><a href=\"", anchor, "\"> ", -                                  ap_escape_html(scratch, t2), -                                  "</a></li>\n", NULL); -                } -        } -        if (autoindex_opts & TABLE_INDEXING) { -                ap_rvputs(r, breakrow, "</table>\n", NULL); -        } -        else if (autoindex_opts & FANCY_INDEXING) { -                if (!(autoindex_opts & SUPPRESS_RULES)) { -                        ap_rputs("<hr", r); -                        if (autoindex_opts & EMIT_XHTML) { -                                ap_rputs(" /", r); -                        } -                        ap_rputs("></pre>\n", r); -                } -                else { -                        ap_rputs("</pre>\n", r); -                } -        } -        else { -                ap_rputs("</ul>\n", r); -        } -} - -/* - * Compare two file entries according to the sort criteria.  The return - * is essentially a signum function value. - */ - -static int dsortf(struct ent **e1, struct ent **e2) -{ -        struct ent *c1 = NULL, *c2 = NULL; -        int         result = 0; - -        /* -         * First, see if either of the entries is for the parent directory. -         * If so, that *always* sorts lower than anything else. -         */ -        if ((*e1)->name[0] == '/') { -                return -1; -        } -        if ((*e2)->name[0] == '/') { -                return 1; -        } -        /* -         * Now see if one's a directory and one isn't, if we're set -         * isdir for FOLDERS_FIRST. -         */ -        if ((*e1)->isdir != (*e2)->isdir) { -                return (*e1)->isdir ? -1 : 1; -        } -        /* -         * All of our comparisons will be of the c1 entry against the c2 one, -         * so assign them appropriately to take care of the ordering. -         */ -        if ((*e1)->ascending) { -                c1 = *e1; -                c2 = *e2; -        } -        else { -                c1 = *e2; -                c2 = *e1; -        } - -        switch (c1->key) { -        case K_LAST_MOD: -                if (c1->lm > c2->lm) { -                        return 1; -                } -                else if (c1->lm < c2->lm) { -                        return -1; -                } -                break; -        case K_SIZE: -                if (c1->size > c2->size) { -                        return 1; -                } -                else if (c1->size < c2->size) { -                        return -1; -                } -                break; -        case K_DESC: -                if (c1->version_sort) { -                        result = apr_strnatcmp(c1->desc ? c1->desc : "", -                                               c2->desc ? c2->desc : ""); -                } -                else { -                        result = strcmp(c1->desc ? c1->desc : "", -                                        c2->desc ? c2->desc : ""); -                } -                if (result) { -                        return result; -                } -                break; -        } - -        /* names may identical when treated case-insensitively, -         * so always fall back on strcmp() flavors to put entries -         * in deterministic order.  This means that 'ABC' and 'abc' -         * will always appear in the same order, rather than -         * variably between 'ABC abc' and 'abc ABC' order. -         */ - -        if (c1->version_sort) { -                if (c1->ignore_case) { -                        result = apr_strnatcasecmp (c1->name, c2->name); -                } -                if (!result) { -                        result = apr_strnatcmp(c1->name, c2->name); -                } -        } - -        /* The names may be identical in respects other other than -         * filename case when strnatcmp is used above, so fall back -         * to strcmp on conflicts so that fn1.01.zzz and fn1.1.zzz -         * are also sorted in a deterministic order. -         */ - -        if (!result && c1->ignore_case) { -                result = strcasecmp (c1->name, c2->name); -        } - -        if (!result) { -                result = strcmp (c1->name, c2->name); -        } - -        return result; -} - - -static int  -mod_glfs_index_directory (request_rec *r, -                          glusterfs_dir_config_t *autoindex_conf) -{ -        char                   *title_name = NULL, *title_endp = NULL; -        char                   *pstring = NULL, *colargs = NULL; -        char                   *path = NULL, *fname = NULL, *charset = NULL; -        char                   *fullpath = NULL, *name = NULL, *ctype = NULL; -        apr_finfo_t             dirent; -        glusterfs_file_t        fd = NULL; -        apr_status_t            status = APR_SUCCESS; -        int                     num_ent = 0, x; -        struct ent             *head = NULL, *p = NULL; -        struct ent            **ar = NULL; -        const char             *qstring = NULL; -        apr_int32_t             autoindex_opts = autoindex_conf->opts; -        char                    keyid, direction; -        apr_size_t              dirpathlen; -        glusterfs_dir_config_t *dir_config = NULL; -        int                     ret = -1; -        struct dirent          *entry = NULL; -        struct stat             st = {0, }; - -        name = r->filename; -        title_name = ap_escape_html(r->pool, r->uri); -        ctype = "text/html"; -        dir_config = mod_glfs_dconfig (r); -        if (dir_config == NULL)  { -                return HTTP_INTERNAL_SERVER_ERROR; -        } - -        path = r->uri; -        fd = glusterfs_open (path, O_RDONLY, 0); -        if (fd == 0) { -                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, -                              "file permissions deny server access: %s", -                              r->filename); -                return HTTP_FORBIDDEN; -        } - -        if (autoindex_conf->ctype) { -                ctype = autoindex_conf->ctype; -        } -        if (autoindex_conf->charset) { -                charset = autoindex_conf->charset; -        } -        else { -#if APR_HAS_UNICODE_FS -                charset = "UTF-8"; -#else -                charset = "ISO-8859-1"; -#endif -        } -        if (*charset) { -                ap_set_content_type(r, apr_pstrcat(r->pool, ctype, ";charset=", -                                                   charset, NULL)); -        } -        else { -                ap_set_content_type(r, ctype); -        } - -        if (autoindex_opts & TRACK_MODIFIED) { -                ap_update_mtime(r, r->finfo.mtime); -                ap_set_last_modified(r); -                ap_set_etag(r); -        } -        if (r->header_only) { -                glusterfs_close (fd); -                return 0; -        } - -        /* -         * If there is no specific ordering defined for this directory, -         * default to ascending by filename. -         */ -        keyid = autoindex_conf->default_keyid -                ? autoindex_conf->default_keyid : K_NAME; -        direction = autoindex_conf->default_direction -                ? autoindex_conf->default_direction : D_ASCENDING; - -        /* -         * Figure out what sort of indexing (if any) we're supposed to use. -         * -         * If no QUERY_STRING was specified or client query strings have been -         * explicitly disabled. -         * If we are ignoring the client, suppress column sorting as well. -         */ -        if (autoindex_opts & IGNORE_CLIENT) { -                qstring = NULL; -                autoindex_opts |= SUPPRESS_COLSORT; -                colargs = ""; -        } -        else { -                char fval[5], vval[5], *ppre = "", *epattern = ""; -                fval[0] = '\0'; vval[0] = '\0'; -                qstring = r->args; - -                while (qstring && *qstring) { - -                        /* C= First Sort key Column (N, M, S, D) */ -                        if (   qstring[0] == 'C' && qstring[1] == '=' -                               && qstring[2] && strchr(K_VALID, qstring[2]) -                               && (   qstring[3] == '&' || qstring[3] == ';' -                                      || !qstring[3])) { -                                keyid = qstring[2]; -                                qstring += qstring[3] ? 4 : 3; -                        } - -                        /* O= Sort order (A, D) */ -                        else if (   qstring[0] == 'O' && qstring[1] == '=' -                                    && (   (qstring[2] == D_ASCENDING) -                                           || (qstring[2] == D_DESCENDING)) -                                    && (   qstring[3] == '&'  -                                           || qstring[3] == ';' -                                           || !qstring[3])) { -                                direction = qstring[2]; -                                qstring += qstring[3] ? 4 : 3; -                        } - -                        /* F= Output Format (0 plain, 1 fancy (pre), 2 table) */ -                        else if (   qstring[0] == 'F' && qstring[1] == '=' -                                    && qstring[2] && strchr("012", qstring[2]) -                                    && (   qstring[3] == '&' || qstring[3] == ';' -                                           || !qstring[3])) { -                                if (qstring[2] == '0') { -                                        autoindex_opts &= ~(FANCY_INDEXING -                                                            | TABLE_INDEXING); -                                } -                                else if (qstring[2] == '1') { -                                        autoindex_opts = (autoindex_opts -                                                          | FANCY_INDEXING) -                                                & ~TABLE_INDEXING; -                                } -                                else if (qstring[2] == '2') { -                                        autoindex_opts |= FANCY_INDEXING -                                                | TABLE_INDEXING; -                                } -                                strcpy(fval, ";F= "); -                                fval[3] = qstring[2]; -                                qstring += qstring[3] ? 4 : 3; -                        } - -                        /* V= Version sort (0, 1) */ -                        else if (   qstring[0] == 'V' && qstring[1] == '=' -                                    && (qstring[2] == '0' || qstring[2] == '1') -                                    && (   qstring[3] == '&' || qstring[3] == ';' -                                           || !qstring[3])) { -                                if (qstring[2] == '0') { -                                        autoindex_opts &= ~VERSION_SORT; -                                } -                                else if (qstring[2] == '1') { -                                        autoindex_opts |= VERSION_SORT; -                                } -                                strcpy(vval, ";V= "); -                                vval[3] = qstring[2]; -                                qstring += qstring[3] ? 4 : 3; -                        } - -                        /* P= wildcard pattern (*.foo) */ -                        else if (qstring[0] == 'P' && qstring[1] == '=') { -                                const char *eos = qstring += 2; /* for efficiency */ - -                                while (*eos && *eos != '&' && *eos != ';') { -                                        ++eos; -                                } - -                                if (eos == qstring) { -                                        pstring = NULL; -                                } -                                else { -                                        pstring = apr_pstrndup(r->pool, qstring, -                                                               eos - qstring); -                                        if (ap_unescape_url(pstring) != OK) { -                                                /* ignore the pattern, if it's bad. */ -                                                pstring = NULL; -                                        } -                                        else { -                                                ppre = ";P="; -                                                /* be correct */ -                                                epattern = ap_escape_uri(r->pool, -                                                                         pstring); -                                        } -                                } - -                                if (*eos && *++eos) { -                                        qstring = eos; -                                } -                                else { -                                        qstring = NULL; -                                } -                        } - -                        /* Syntax error?  Ignore the remainder! */ -                        else { -                                qstring = NULL; -                        } -                } -                colargs = apr_pstrcat(r->pool, fval, vval, ppre, epattern, -                                      NULL); -        } - -        /* Spew HTML preamble */ -        title_endp = title_name + strlen(title_name) - 1; - -        while (title_endp > title_name && *title_endp == '/') { -                *title_endp-- = '\0'; -        } - -        emit_head(r, find_header(autoindex_conf, r), -                  autoindex_opts & SUPPRESS_PREAMBLE, -                  autoindex_opts & EMIT_XHTML, title_name); - -        /* -         * Since we don't know how many dir. entries there are, put them into a -         * linked list and then arrayificate them so qsort can use them. -         */ -        head = NULL; -        p = make_parent_entry(autoindex_opts, autoindex_conf, r, keyid, -                              direction); -        if (p != NULL) { -                p->next = head; -                head = p; -                num_ent++; -        } -        fullpath = apr_palloc(r->pool, APR_PATH_MAX); -        dirpathlen = strlen(name); -        memcpy(fullpath, name, dirpathlen); - -        do { -                entry = glusterfs_readdir (fd); -                if (entry == NULL) { -                        break; -                } - -                fname = apr_pstrcat (r->pool, path, entry->d_name, NULL); - -                ret = glusterfs_stat (fname, &st); -                if (ret != 0) { -                        break; -                } -                 -                dirent.fname = fname; -                dirent.name = apr_pstrdup (r->pool, entry->d_name); -                fill_out_finfo (&dirent, &st,  -                                APR_FINFO_MIN | APR_FINFO_IDENT -                                | APR_FINFO_NLINK | APR_FINFO_OWNER -                                | APR_FINFO_PROT); - -                p = make_autoindex_entry(&dirent, autoindex_opts, -                                         autoindex_conf, r, -                                         keyid, direction, pstring); -                if (p != NULL) { -                        p->next = head; -                        head = p; -                        num_ent++; -                } -        } while (1); - -        if (num_ent > 0) { -                ar = (struct ent **) apr_palloc(r->pool, -                                                num_ent * sizeof(struct ent *)); -                p = head; -                x = 0; -                while (p) { -                        ar[x++] = p; -                        p = p->next; -                } - -                qsort((void *) ar, num_ent, sizeof(struct ent *), -                      (int (*)(const void *, const void *)) dsortf); -        } -        output_directories(ar, num_ent, autoindex_conf, r, autoindex_opts, -                           keyid, direction, colargs); -        glusterfs_close (fd); - -        emit_tail(r, find_readme(autoindex_conf, r), -                  autoindex_opts & SUPPRESS_PREAMBLE); - -        return 0; -} - - -static int  -handle_autoindex(request_rec *r) -{ -        glusterfs_dir_config_t *dir_config = NULL; -        int allow_opts; - -        allow_opts = ap_allow_options(r); - -        r->allowed |= (AP_METHOD_BIT << M_GET); -        if (r->method_number != M_GET) { -                return DECLINED; -        } - -        dir_config = mod_glfs_dconfig (r); - -        /* OK, nothing easy.  Trot out the heavy artillery... */ - -        if (allow_opts & OPT_INDEXES) { -                int errstatus; - -                if ((errstatus = ap_discard_request_body(r)) != OK) { -                        return errstatus; -                } - -                /* KLUDGE --- make the sub_req lookups happen in the right  -                 * directory. Fixing this in the sub_req_lookup functions  -                 * themselves is difficult, and would probably break  -                 * virtual includes... -                 */ - -                if (r->filename[strlen(r->filename) - 1] != '/') { -                        r->filename = apr_pstrcat(r->pool, r->filename, "/", -                                                  NULL); -                } -                return mod_glfs_index_directory(r, dir_config); -        } else { -                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, -                              "Directory index forbidden by " -                              "Options directive: %s", r->filename); -                return HTTP_FORBIDDEN; -        } -} - - -static int  -mod_glfs_handler (request_rec *r) -{ -        conn_rec               *c = r->connection; -        apr_bucket_brigade     *bb; -        apr_bucket             *e; -        core_dir_config        *d; -        int                     errstatus; -        glusterfs_file_t        fd = NULL; -        apr_status_t            status; -        glusterfs_dir_config_t *dir_config = NULL; -        char                   *path = NULL; -        int                     num_ranges = 0; -        apr_size_t              size = 0; -        apr_off_t               range_start = 0, range_end = 0; -        char                   *current = NULL; -        apr_status_t            rv = 0; -        core_request_config    *req_cfg = NULL; - -        /* XXX if/when somebody writes a content-md5 filter we either need to -         *     remove this support or coordinate when to use the filter vs. -         *     when to use this code -         *     The current choice of when to compute the md5 here matches the 1.3 -         *     support fairly closely (unlike 1.3, we don't handle computing md5 -         *     when the charset is translated). -         */ - -        int bld_content_md5; -        if (!r->handler || (r->handler -                            && strcmp (r->handler, GLUSTERFS_HANDLER))) -                return DECLINED; - -        if (r->uri[0] == '\0') { -                return DECLINED; -        } -   -        if (r->finfo.filetype == APR_DIR) { -                return handle_autoindex (r); -        } - -        dir_config = mod_glfs_dconfig (r); - -        ap_allow_standard_methods(r, MERGE_ALLOW, M_GET, -1); -   -        /* We understood the (non-GET) method, but it might not be legal for -           this particular resource. Check to see if the 'deliver_script' -           flag is set. If so, then we go ahead and deliver the file since -           it isn't really content (only GET normally returns content). - -           Note: based on logic further above, the only possible non-GET -           method at this point is POST. In the future, we should enable -           script delivery for all methods.  */ -        if (r->method_number != M_GET) { -                req_cfg = ap_get_module_config(r->request_config, &core_module); -                if (!req_cfg->deliver_script) { -                        /* The flag hasn't been set for this request. Punt. */ -                        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, -                                      "This resource does not accept the %s " -                                      "method.", -                                      r->method); -                        return HTTP_METHOD_NOT_ALLOWED; -                } -        } - -        d = (core_dir_config *)ap_get_module_config(r->per_dir_config, -                                                    &core_module); -        bld_content_md5 = (d->content_md5 & 1) -                && r->output_filters->frec->ftype != AP_FTYPE_RESOURCE; - -        if ((errstatus = ap_discard_request_body(r)) != OK) { -                return errstatus; -        } - -        if (r->finfo.filetype == 0) { -                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, -                              "File does not exist: %s", r->filename); -                return HTTP_NOT_FOUND; -        } - -        if ((r->used_path_info != AP_REQ_ACCEPT_PATH_INFO) && -            r->path_info && *r->path_info) -        { -                /* default to reject */ -                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, -                              "File does not exist: %s", -                              apr_pstrcat(r->pool, r->filename, r->path_info, -                                          NULL)); -                return HTTP_NOT_FOUND; -        } - -        ap_update_mtime (r, r->finfo.mtime); -        ap_set_last_modified (r); -        ap_set_etag (r); -        apr_table_setn (r->headers_out, "Accept-Ranges", "bytes"); - -        num_ranges = ap_set_byterange(r); -        if (num_ranges == 0) { -                size = r->finfo.size; -        } else { -                char *tmp = apr_pstrdup (r->pool, r->range); -                while ((current = ap_getword(r->pool, (const char **)&tmp, ',')) -                       && (rv = parse_byterange(current, r->finfo.size, -                                                &range_start, &range_end))) { -                        size += (range_end - range_start); -                } -        } - -        ap_set_content_length (r, size); -                         -        if ((errstatus = ap_meets_conditions(r)) != OK) { -                r->status = errstatus; -        } - -        /*  -         * file is small enough to have already got the content in  -         * glusterfs_lookup -        */ -        if (r->finfo.size <= dir_config->xattr_file_size && dir_config->buf) { -                if (bld_content_md5) { -                        apr_table_setn (r->headers_out, "Content-MD5", -                                        (const char *)ap_md5_binary(r->pool, -                                                                    dir_config->buf -                                                                    , r->finfo.size)); -                } - -                ap_log_rerror (APLOG_MARK, APLOG_NOTICE, 0, r,  -                               "fetching data from glusterfs through xattr " -                               "interface\n"); -                 -                bb = apr_brigade_create(r->pool, c->bucket_alloc); - -                e = apr_bucket_heap_create (dir_config->buf, r->finfo.size, -                                            free, c->bucket_alloc); -                APR_BRIGADE_INSERT_TAIL (bb, e); -                 -                e = apr_bucket_eos_create(c->bucket_alloc); -                APR_BRIGADE_INSERT_TAIL(bb, e); - -                dir_config->buf = NULL; - -                /* let the byterange_filter handle multipart requests */ -                status = ap_pass_brigade(r->output_filters, bb); -                if (status == APR_SUCCESS -                    || r->status != HTTP_OK -                    || c->aborted) { -                        return OK; -                } -                else { -                        /* no way to know what type of error occurred */ -                        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, status, r, -                                      "mod_glfs_handler: ap_pass_brigade " -                                      "returned %i", -                                      status); -                        return HTTP_INTERNAL_SERVER_ERROR; -                } -        } -         -        /* do standard open/read/close to fetch content */ -        path = r->uri; -         -        fd = glusterfs_open (path, O_RDONLY, 0); -        if (fd == 0) { -                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, -                              "file permissions deny server access: %s", -                              r->filename); -                return HTTP_FORBIDDEN; -        } - -        /*  -         * byterange_filter cannot handle range requests, since we are not  -         * sending the whole data in a single brigade -         */ - - -        if (num_ranges == 0) { -                mod_glfs_read_async (r, NULL, fd, 0, -1); -        } else { -                mod_glfs_handle_byte_ranges (r, fd, num_ranges); -        } -                 -        glusterfs_close (fd); -} - - -#if 0 -static apr_status_t  -mod_glfs_output_filter (ap_filter_t *f, -                        apr_bucket_brigade *b) -{ -        size_t size = 0; -        apr_bucket_t *e = NULL;  -        size = atol (apr_table_get (r->notes, MOD_GLFS_SIZE)); -         -        for (e = APR_BRIGADE_FIRST(b); -             e != APR_BRIGADE_SENTINEL(b); -             e = APR_BUCKET_NEXT(e)) -        { -                /* FIXME: can there be more than one heap buckets? */ -                if (e->type == &apr_bucket_type_heap) { -                        break; -                } -        } - -        if (e != APR_BRIGADE_SENTINEL(b)) { -                e->length = size; -        } - -        return ap_pass_brigade (f->next, b); -} -#endif - -static int  -mod_glfs_fixup_dir(request_rec *r) -{ -        glusterfs_dir_config_t  *d = NULL; -        char                    *dummy_ptr[1]; -        char                   **names_ptr = NULL, *name_ptr = NULL; -        int                      num_names; -        int                      error_notfound = 0; -        char                    *ifile = NULL; -        request_rec             *rr = NULL; - -        /* only handle requests against directories */ -        if (r->finfo.filetype != APR_DIR) { -                return DECLINED; -        } - -        if (!r->handler || strcmp (r->handler, GLUSTERFS_HANDLER)) { -                return DECLINED; -        } - -        /* Never tolerate path_info on dir requests */ -        if (r->path_info && *r->path_info) { -                return DECLINED; -        } - -        d = (glusterfs_dir_config_t *)ap_get_module_config(r->per_dir_config, -                                                           &glusterfs_module); - -        /* Redirect requests that are not '/' terminated */ -        if (r->uri[0] == '\0' || r->uri[strlen(r->uri) - 1] != '/') -        { -                if (!d->do_slash) { -                        return DECLINED; -                } - -                /* Only redirect non-get requests if we have no note to warn -                 * that this browser cannot handle redirs on non-GET requests -                 * (such as Microsoft's WebFolders). -                 */ -                if ((r->method_number != M_GET) -                    && apr_table_get(r->subprocess_env, "redirect-carefully")) { -                        return DECLINED; -                } - -                if (r->args != NULL) { -                        ifile = apr_pstrcat(r->pool, ap_escape_uri(r->pool, -                                                                   r->uri), -                                            "/", "?", r->args, NULL); -                } -                else { -                        ifile = apr_pstrcat(r->pool, ap_escape_uri(r->pool, -                                                                   r->uri), -                                            "/", NULL); -                } - -                apr_table_setn(r->headers_out, "Location", -                               ap_construct_url(r->pool, ifile, r)); -                return HTTP_MOVED_PERMANENTLY; -        } - -        if (d->index_names) { -                names_ptr = (char **)d->index_names->elts; -                num_names = d->index_names->nelts; -        } -        else { -                dummy_ptr[0] = AP_DEFAULT_INDEX; -                names_ptr = dummy_ptr; -                num_names = 1; -        } - -        for (; num_names; ++names_ptr, --num_names) { -                /* XXX: Is this name_ptr considered escaped yet, or not??? */ -                name_ptr = *names_ptr; - -                /* Once upon a time args were handled _after_ the successful -                 * redirect. But that redirect might then _refuse_ the  -                 * given r->args, creating a nasty tangle.  It seems safer to  -                 * consider the r->args while we determine if name_ptr is our  -                 * viable index, and therefore set them up correctly on redirect. -                 */ -                if (r->args != NULL) { -                        name_ptr = apr_pstrcat(r->pool, name_ptr, "?", r->args, -                                               NULL); -                } - -                rr = ap_sub_req_lookup_uri(name_ptr, r, NULL); - -                /* The sub request lookup is very liberal, and the core  -                 * map_to_storage handler will almost always result in HTTP_OK  -                 * as /foo/index.html may be /foo with PATH_INFO="/index.html", -                 * or even / with PATH_INFO="/foo/index.html". To get around  -                 * this we insist that the the index be a regular filetype. -                 * -                 * Another reason is that the core handler also makes the  -                 * assumption that if r->finfo is still NULL by the time it  -                 * gets called, the file does not exist. -                 */ -                if (rr->status == HTTP_OK -                    && (   (rr->handler && !strcmp(rr->handler, "proxy-server")) -                           || rr->finfo.filetype == APR_REG)) { -                        ap_internal_fast_redirect(rr, r); -                        return OK; -                } - -                /* If the request returned a redirect, propagate it to the  -                 * client -                 */ - -                if (ap_is_HTTP_REDIRECT(rr->status) -                    || (rr->status == HTTP_NOT_ACCEPTABLE && num_names == 1) -                    || (rr->status == HTTP_UNAUTHORIZED && num_names == 1)) { - -                        apr_pool_join(r->pool, rr->pool); -                        error_notfound = rr->status; -                        r->notes = apr_table_overlay(r->pool, r->notes, -                                                     rr->notes); -                        r->headers_out = apr_table_overlay(r->pool, -                                                           r->headers_out, -                                                           rr->headers_out); -                        r->err_headers_out = apr_table_overlay(r->pool, -                                                               r->err_headers_out, -                                                               rr->err_headers_out); -                        return error_notfound; -                } - -                /* If the request returned something other than 404 (or 200), -                 * it means the module encountered some sort of problem. To be -                 * secure, we should return the error, rather than allow  -                 * autoindex to create a (possibly unsafe) directory index. -                 * -                 * So we store the error, and if none of the listed files -                 * exist, we return the last error response we got, instead -                 * of a directory listing. -                 */ -                if (rr->status && rr->status != HTTP_NOT_FOUND -                    && rr->status != HTTP_OK) { -                        error_notfound = rr->status; -                } - -                ap_destroy_sub_req(rr); -        } - -        if (error_notfound) { -                return error_notfound; -        } - -        /* nothing for us to do, pass on through */ -        return DECLINED; -} - - -static void  -mod_glfs_register_hooks(apr_pool_t *p) -{ -        ap_hook_child_init (mod_glfs_child_init, NULL, NULL, APR_HOOK_MIDDLE); -        ap_hook_handler (mod_glfs_handler, NULL, NULL, APR_HOOK_REALLY_FIRST); -        ap_hook_map_to_storage (mod_glfs_map_to_storage, NULL, NULL, -                                APR_HOOK_REALLY_FIRST); -        ap_hook_fixups(mod_glfs_fixup_dir,NULL,NULL,APR_HOOK_LAST); - -/*    mod_glfs_output_filter_handle =  -      ap_register_output_filter ("MODGLFS", mod_glfs_output_filter, -      NULL, AP_FTYPE_PROTOCOL); */ -} - -static const char * -cmd_add_index (cmd_parms *cmd, void *dummy, const char *arg) -{ -        glusterfs_dir_config_t *d = dummy; - -        if (!d->index_names) { -                d->index_names = apr_array_make(cmd->pool, 2, sizeof(char *)); -        } -        *(const char **)apr_array_push(d->index_names) = arg; -        return NULL; -} - -static const char * -cmd_configure_slash (cmd_parms *cmd, void *d_, int arg) -{ -        glusterfs_dir_config_t *d = d_; - -        d->do_slash = arg ? SLASH_ON : SLASH_OFF; -        return NULL; -} - -#define DIR_CMD_PERMS OR_INDEXES - -static const  -command_rec mod_glfs_cmds[] = -{ -        AP_INIT_TAKE1( -                "GlusterfsLogfile", -                cmd_add_logfile, -                NULL, -                ACCESS_CONF, /*FIXME: allow overriding in .htaccess files */ -                "Glusterfs logfile" -                ), - -        AP_INIT_TAKE1( -                "GlusterfsLoglevel", -                cmd_set_loglevel, -                NULL, -                ACCESS_CONF, -                "Glusterfs loglevel:anyone of none, critical, error, warning, " -                "debug" -                ), - -        AP_INIT_TAKE1( -                "GlusterfsCacheTimeout", -                cmd_set_cache_timeout, -                NULL, -                ACCESS_CONF, -                "Timeout value in seconds for lookup and stat cache of " -                "libglusterfsclient" -                ), - -        AP_INIT_TAKE1( -                "GlusterfsVolumeSpecfile", -                cmd_add_volume_specfile, -                NULL, -                ACCESS_CONF, -                "Glusterfs Volume specfication file specifying filesystem " -                "under this directory" -                ), - -        AP_INIT_TAKE1( -                "GlusterfsXattrFileSize", -                cmd_add_xattr_file_size, -                NULL, -                ACCESS_CONF, -                "Maximum size of the file that can be fetched through " -                "extended attribute interface of libglusterfsclient" -                ), - -        /* mod_dir cmds */ -        AP_INIT_ITERATE("DirectoryIndex", cmd_add_index,  -                        NULL, DIR_CMD_PERMS, -                        "a list of file names"), - -        AP_INIT_FLAG("DirectorySlash", cmd_configure_slash,  -                     NULL, DIR_CMD_PERMS, -                     "On or Off"), - -        /* autoindex cmds */ -        AP_INIT_ITERATE2("AddIcon", cmd_add_icon,  -                         BY_PATH, DIR_CMD_PERMS, -                         "an icon URL followed by one or more filenames"), - -        AP_INIT_ITERATE2("AddIconByType", cmd_add_icon,  -                         BY_TYPE, DIR_CMD_PERMS, -                         "an icon URL followed by one or more MIME types"), - -        AP_INIT_ITERATE2("AddIconByEncoding", cmd_add_icon,  -                         BY_ENCODING, DIR_CMD_PERMS, -                         "an icon URL followed by one or more content encodings"), - -        AP_INIT_ITERATE2("AddAlt", cmd_add_alt, BY_PATH,  -                         DIR_CMD_PERMS, -                         "alternate descriptive text followed by one or more " -                         "filenames"), - -        AP_INIT_ITERATE2("AddAltByType", cmd_add_alt,  -                         BY_TYPE, DIR_CMD_PERMS, -                         "alternate descriptive text followed by one or more " -                         "MIME types"), - -        AP_INIT_ITERATE2("AddAltByEncoding", cmd_add_alt,  -                         BY_ENCODING, DIR_CMD_PERMS, -                         "alternate descriptive text followed by one or more " -                         "content encodings"), - -        AP_INIT_TAKE_ARGV("IndexOptions", cmd_add_opts,  -                          NULL, DIR_CMD_PERMS, -                          "one or more index options [+|-][]"), - -        AP_INIT_TAKE2("IndexOrderDefault", cmd_set_default_order,  -                      NULL, DIR_CMD_PERMS, -                      "{Ascending,Descending} {Name,Size,Description,Date}"), - -        AP_INIT_ITERATE("IndexIgnore", cmd_add_ignore,  -                        NULL, DIR_CMD_PERMS, -                        "one or more file extensions"), - -        AP_INIT_ITERATE2("AddDescription", cmd_add_desc,  -                         BY_PATH, DIR_CMD_PERMS, -                         "Descriptive text followed by one or more filenames"), - -        AP_INIT_TAKE1("HeaderName", cmd_add_header,  -                      NULL, DIR_CMD_PERMS, -                      "a filename"), - -        AP_INIT_TAKE1("ReadmeName", cmd_add_readme,  -                      NULL, DIR_CMD_PERMS, -                      "a filename"), - -        AP_INIT_RAW_ARGS("FancyIndexing", ap_set_deprecated,  -                         NULL, OR_ALL, -                         "The FancyIndexing directive is no longer supported. " -                         "Use IndexOptions FancyIndexing."), - -        AP_INIT_TAKE1("DefaultIcon", ap_set_string_slot, -                      (void *)APR_OFFSETOF(glusterfs_dir_config_t, -                                           default_icon), -                      DIR_CMD_PERMS, "an icon URL"), - -        AP_INIT_TAKE1("IndexStyleSheet", ap_set_string_slot, -                      (void *)APR_OFFSETOF(glusterfs_dir_config_t, style_sheet), -                      DIR_CMD_PERMS, "URL to style sheet"), - -        {NULL} -}; - -module AP_MODULE_DECLARE_DATA glusterfs_module = -{ -        STANDARD20_MODULE_STUFF, -        mod_glfs_create_dir_config, -        mod_glfs_merge_dir_config, -        NULL, //mod_glfs_create_server_config, -        NULL, //mod_glfs_merge_server_config, -        mod_glfs_cmds, -        mod_glfs_register_hooks, -}; diff --git a/mod_glusterfs/apache/Makefile.am b/mod_glusterfs/apache/Makefile.am deleted file mode 100644 index bda03931052..00000000000 --- a/mod_glusterfs/apache/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -SUBDIRS = $(MOD_GLUSTERFS_HTTPD_VERSION) - -EXTRA_DIST = 1.3/Makefile.am 1.3/Makefile.in \ -	     1.3/src/Makefile.am 1.3/src/Makefile.in \ -	     1.3/src/mod_glusterfs.c \ -	     1.3/src/README.txt \ -	     2.2/Makefile.am 2.2/Makefile.in \ -	     2.2/src/Makefile.am 2.2/src/Makefile.in \ -	     2.2/src/mod_glusterfs.c -CLEANFILES =  diff --git a/mod_glusterfs/lighttpd/1.4/Makefile.am b/mod_glusterfs/lighttpd/1.4/Makefile.am deleted file mode 100644 index eda329111dc..00000000000 --- a/mod_glusterfs/lighttpd/1.4/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -EXTRA_DIST = Makefile.am.diff mod_glusterfs.c mod_glusterfs.h README.txt - -CLEANFILES =  diff --git a/mod_glusterfs/lighttpd/1.4/Makefile.am.diff b/mod_glusterfs/lighttpd/1.4/Makefile.am.diff deleted file mode 100644 index 375696b5d8f..00000000000 --- a/mod_glusterfs/lighttpd/1.4/Makefile.am.diff +++ /dev/null @@ -1,29 +0,0 @@ ---- lighttpd-1.4.19/src/Makefile.am	2008-04-16 18:42:18.000000000 +0400 -+++ lighttpd-1.4.19.mod/src/Makefile.am	2008-04-16 18:41:11.000000000 +0400 -@@ -1,4 +1,4 @@ --AM_CFLAGS = $(FAM_CFLAGS) -+AM_CFLAGS = $(FAM_CFLAGS)  -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -  - noinst_PROGRAMS=proc_open lemon # simple-fcgi #graphic evalo bench ajp ssl error_test adserver gen-license - sbin_PROGRAMS=lighttpd lighttpd-angel -@@ -241,6 +241,11 @@ - mod_accesslog_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined - mod_accesslog_la_LIBADD = $(common_libadd) -  -+lib_LTLIBRARIES += mod_glusterfs.la -+mod_glusterfs_la_SOURCES = mod_glusterfs.c -+mod_glusterfs_la_CFLAGS = $(AM_CFLAGS)  -+mod_glusterfs_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined -lglusterfsclient -lpthread -+mod_glusterfs_la_LIBADD = $(common_libadd)  -  - hdr = server.h buffer.h network.h log.h keyvalue.h \ -       response.h request.h fastcgi.h chunk.h \ -@@ -254,7 +259,7 @@ -       configparser.h mod_ssi_exprparser.h \ -       sys-mmap.h sys-socket.h mod_cml.h mod_cml_funcs.h \ -       splaytree.h proc_open.h status_counter.h \ --      mod_magnet_cache.h -+      mod_magnet_cache.h mod_glusterfs.h -  - DEFS= @DEFS@ -DLIBRARY_DIR="\"$(libdir)\"" -DSBIN_DIR="\"$(sbindir)\"" -  diff --git a/mod_glusterfs/lighttpd/1.4/README.txt b/mod_glusterfs/lighttpd/1.4/README.txt deleted file mode 100644 index 786a146e44d..00000000000 --- a/mod_glusterfs/lighttpd/1.4/README.txt +++ /dev/null @@ -1,57 +0,0 @@ -Introduction -============ -mod_glusterfs is a module written for lighttpd to speed up the access of files present on glusterfs. mod_glusterfs uses libglusterfsclient library provided for glusterfs and hence can be used without fuse (File System in User Space). - -Usage -===== -To use mod_glusterfs with lighttpd-1.4, copy mod_glusterfs.c and mod_glusterfs.h into src/ of lighttpd-1.4 source tree, and apply the Makefile.am.diff to src/Makefile.am. Re-run ./autogen.sh on the top level of the lighttpd-1.4 build tree and recompile. - -# cp mod_glusterfs.[ch] /home/glusterfs/lighttpd-1.4/src/ -# cp Makefile.am.diff /home/glusterfs/lighttpd-1.4/ -# cd /home/glusterfs/lighttpd-1.4 -# patch -p1 < Makefile.am.diff  -# ./autogen.sh -# ./configure -# make -# make install - -Configuration -============= -* mod_glusterfs should be listed at the begining of the list server.modules in lighttpd.conf.  - -Below is a snippet from lighttpd.conf concerning to mod_glusterfs. - -$HTTP["url"] =~ "^/glusterfs" { -	glusterfs.prefix = "/glusterfs"  -	glusterfs.document-root = "/home/glusterfs/document-root" -	glusterfs.logfile = "/var/log/glusterfs-logfile" -	glusterfs.volume-specfile = "/etc/glusterfs/glusterfs.vol" -	glusterfs.loglevel = "error" -	glusterfs.cache-timeout = 300 -	glusterfs.xattr-interface-size-limit = "65536" -} - -* $HTTP["url"] =~ "^/glusterfs" -  A perl style regular expression used to match against the url. If regular expression matches the url, the url is handled by mod_glusterfs. Note that the pattern given here should match glusterfs.prefix. - -* glusterfs.prefix (COMPULSORY) -  A string to be present at the starting of the file path in the url so that the file would be handled by glusterfs. -  Eg., A GET request on the url http://www.example.com/glusterfs-prefix/some-dir/example-file will result in fetching of the file "/some-dir/example-file" from glusterfs mount if glusterfs.prefix is set to "/glusterfs-prefix". - -* glusterfs.volume-specfile (COMPULSORY) -  Path to the the glusterfs volume specification file. - -* glusterfs.logfile (COMPULSORY) -  Path to the glusterfs logfile. - -* glusterfs.loglevel (OPTIONAL, default = warning) -  Allowed values are critical, error, warning, debug, none in the decreasing order of severity of error conditions. - -* glusterfs.cache-timeout (OPTIONAL, default = 0) -  Timeout values for glusterfs stat and lookup cache. - -* glusterfs.document-root (COMPULSORY) -  An absolute path, relative to which all the files are fetched from glusterfs. - -* glusterfs.xattr-interface-size-limit (OPTIONAL, default = 0) -  Files with sizes upto and including this value are fetched through the extended attribute interface of glusterfs rather than the usual open-read-close set of operations. For files of small sizes, it is recommended to use extended attribute interface. diff --git a/mod_glusterfs/lighttpd/1.4/mod_glusterfs.c b/mod_glusterfs/lighttpd/1.4/mod_glusterfs.c deleted file mode 100644 index 295c9704c92..00000000000 --- a/mod_glusterfs/lighttpd/1.4/mod_glusterfs.c +++ /dev/null @@ -1,1820 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#include <ctype.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <pthread.h> -#include <sys/types.h> -#include <fcntl.h> - -#include <sys/types.h> -#include <sys/stat.h> - -#include <errno.h> -#include <unistd.h> -#include <assert.h> - -#include "base.h" -#include "log.h" -#include "buffer.h" - -#include "plugin.h" - -#include "stat_cache.h" -#include "mod_glusterfs.h" -#include "etag.h" -#include "http_chunk.h" -#include "response.h" - -#include "fdevent.h" -#include <libglusterfsclient.h> - -#ifdef HAVE_ATTR_ATTRIBUTES_H -#include <attr/attributes.h> -#endif - -#ifdef HAVE_FAM_H -# include <fam.h> -#endif - -#include "sys-mmap.h" - -/* NetBSD 1.3.x needs it */ -#ifndef MAP_FAILED -# define MAP_FAILED -1 -#endif - -#ifndef O_LARGEFILE -# define O_LARGEFILE 0 -#endif - -#ifndef HAVE_LSTAT -#define lstat stat -#endif - -#if 0 -/*  -   enables debug code for testing if all nodes in the stat-cache as accessable -*/ -#define DEBUG_STAT_CACHE -#endif - -#ifdef HAVE_LSTAT -#undef HAVE_LSTAT -#endif - -#define GLUSTERFS_FILE_CHUNK (FILE_CHUNK + 1) - -/*  -   Keep this value large. Each glusterfs_async_read of GLUSTERFS_CHUNK_SIZE -   results in a network_backend_write of the read data -*/ - -#define GLUSTERFS_CHUNK_SIZE 8192 - -/** - * this is a staticfile for a lighttpd plugin - * - */ - -typedef struct glusterfs_async_local { -        int op_ret; -        int op_errno; -        char async_read_complete; -        off_t length; -        size_t read_bytes; -        glusterfs_iobuf_t *buf; -        pthread_mutex_t lock; -        pthread_cond_t cond; -} glusterfs_async_local_t; - - -typedef struct { -        glusterfs_file_t fd; -        void *buf; -        buffer *glusterfs_path; -        /*  off_t response_content_length; */ -        int prefix; -}mod_glusterfs_ctx_t; - -/* plugin config for all request/connections */ -typedef struct { -        buffer *logfile; -        buffer *loglevel; -        buffer *specfile; -        buffer *prefix; -        buffer *xattr_file_size; -        buffer *document_root; -        array *exclude_exts; -        unsigned short cache_timeout; -        char mounted; -} plugin_config; - -static int (*network_backend_write)(struct server *srv, connection *con, int fd, -                                    chunkqueue *cq); - -typedef struct { -        PLUGIN_DATA; -        buffer *range_buf; -        plugin_config **config_storage; -   -        plugin_config conf; -} plugin_data; - -typedef struct { -        chunkqueue *cq; -        glusterfs_iobuf_t *buf; -        size_t length; -}mod_glusterfs_chunkqueue; - -#ifdef HAVE_FAM_H -typedef struct { -        FAMRequest *req; -        FAMConnection *fc; - -        buffer *name; - -        int version; -} fam_dir_entry; -#endif - -/* the directory name is too long to always compare on it - * - we need a hash - * - the hash-key is used as sorting criteria for a tree - * - a splay-tree is used as we can use the caching effect of it - */ - -/* we want to cleanup the stat-cache every few seconds, let's say 10 - * - * - remove entries which are outdated since 30s - * - remove entries which are fresh but havn't been used since 60s - * - if we don't have a stat-cache entry for a directory, release it from the  - *   monitor - */ - -#ifdef DEBUG_STAT_CACHE -typedef struct { -        int *ptr; - -        size_t used; -        size_t size; -} fake_keys; - -static fake_keys ctrl; -#endif - -int  -mod_glusterfs_readv_async_cbk (int op_ret, int op_errno, -                               glusterfs_iobuf_t *buf, -                               void *cbk_data) -{ -        glusterfs_async_local_t *local = cbk_data; -        pthread_mutex_lock (&local->lock); -        { -                local->async_read_complete = 1; -                local->buf = buf; -                local->op_ret = op_ret; -                local->op_errno = op_errno; -                pthread_cond_signal (&local->cond); -        } -        pthread_mutex_unlock (&local->lock); - -        return 0; -} - -static int -mod_glusterfs_read_async (server *srv, connection *con, chunk *glusterfs_chunk) -{ -        glusterfs_async_local_t local; -        off_t end = 0; -        int nbytes; -        int complete; -        chunkqueue *cq = NULL; -        chunk *c = NULL; -        off_t offset = glusterfs_chunk->file.start; -        size_t length = glusterfs_chunk->file.length; -        glusterfs_file_t fd = glusterfs_chunk->file.name; - -        pthread_cond_init (&local.cond, NULL); -        pthread_mutex_init (&local.lock, NULL); -   -        //local.fd = fd; -        memset (&local, 0, sizeof (local)); - -        if (length > 0) -                end = offset + length; - -        cq = chunkqueue_init (); -        if (!cq) { -                con->http_status = 500; -                return HANDLER_FINISHED; -        } - -        do { -                glusterfs_iobuf_t *buf; -                int i; -                if (length > 0) { -                        nbytes = end - offset; -                        if (nbytes > GLUSTERFS_CHUNK_SIZE) -                                nbytes = GLUSTERFS_CHUNK_SIZE; -                } else -                        nbytes = GLUSTERFS_CHUNK_SIZE; - -                glusterfs_read_async(fd,  -                                     nbytes, -                                     offset, -                                     mod_glusterfs_readv_async_cbk, -                                     (void *)&local); - -                pthread_mutex_lock (&local.lock); -                { -                        while (!local.async_read_complete) { -                                pthread_cond_wait (&local.cond, &local.lock); -                        } - -                        local.async_read_complete = 0; -                        buf = local.buf; - -                        if ((int)length < 0) -                                complete = (local.op_ret <= 0); -                        else { -                                local.read_bytes += local.op_ret; -                                complete = ((local.read_bytes == length) -                                            || (local.op_ret <= 0)); -                        } -                } -                pthread_mutex_unlock (&local.lock); - -                if (local.op_ret > 0) { -                        unsigned long check = 0; -                        for (i = 0; i < buf->count; i++) { -                                buffer *nw_write_buf = buffer_init (); - -                                check += buf->vector[i].iov_len;         - -                                nw_write_buf->used = buf->vector[i].iov_len + 1; -                                nw_write_buf->size = buf->vector[i].iov_len; -                                nw_write_buf->ptr = buf->vector[i].iov_base; - -                                offset += local.op_ret; -                                chunkqueue_append_buffer_weak(cq, nw_write_buf); -                        } -   -                        network_backend_write (srv, con, con->fd, cq); -   -                        if (chunkqueue_written (cq) != local.op_ret) { -                                mod_glusterfs_chunkqueue *gf_cq; -                                glusterfs_chunk->file.start = offset; -                                if ((int)glusterfs_chunk->file.length > 0) -                                        glusterfs_chunk->file.length -= local.read_bytes; - -                                gf_cq = calloc (1, sizeof (*gf_cq)); -                                /* ERR_ABORT (gf_cq); */ -                                gf_cq->cq = cq; -                                gf_cq->buf = buf; -                                gf_cq->length = local.op_ret; -                                glusterfs_chunk->file.mmap.start =(char *)gf_cq; -                                return local.read_bytes; -                        } -       -                        for (c = cq->first ; c; c = c->next)  -                                c->mem->ptr = NULL; - -                        chunkqueue_reset (cq); -                } - -                glusterfs_free (buf); -        } while (!complete); - -        chunkqueue_free (cq); -        glusterfs_close (fd); - -        if (local.op_ret < 0) -                con->http_status = 500; - -        return (local.op_ret < 0 ? HANDLER_FINISHED : HANDLER_GO_ON); -} - -int mod_glusterfs_network_backend_write(struct server *srv, connection *con, -                                        int fd, chunkqueue *cq) -{ -        chunk *c, *prev, *first; -        int chunks_written = 0; -        int error = 0; - -        for (first = prev = c = cq->first; c; c = c->next, chunks_written++) { - -                if (c->type == MEM_CHUNK && c->mem->used && !c->mem->ptr) { -                        if (cq->first != c) { -                                prev->next = NULL; - -                                /* call stored network_backend_write */ -                                network_backend_write (srv, con, fd, cq); - -                                prev->next = c; -                        }  -                        cq->first = c->next; - -                        if (c->file.fd < 0) { -                                error = HANDLER_ERROR; -                                break; -                        } - -                        if (c->file.mmap.start) { -                                chunk *tmp; -                                mod_glusterfs_chunkqueue *gf_cq = NULL; - -                                gf_cq = (mod_glusterfs_chunkqueue *)c->file.mmap.start; - -                                network_backend_write (srv, con, fd, gf_cq->cq); - -                                if ((size_t)chunkqueue_written (gf_cq->cq)  -                                    != gf_cq->length) { -                                        cq->first = first; -                                        return chunks_written; -                                } -                                for (tmp = gf_cq->cq->first ; tmp; -                                     tmp = tmp->next) -                                        tmp->mem->ptr = NULL; - -                                chunkqueue_free (gf_cq->cq); -                                glusterfs_free (gf_cq->buf); -                                free (gf_cq); -                                c->file.mmap.start = NULL; -                        } -       -                        mod_glusterfs_read_async (srv, con, c); -                        if (c->file.mmap.start) { -                                /* pending chunkqueue from -                                   mod_glusterfs_read_async to be written to -                                   network */ -                                cq->first = first; -                                return chunks_written; -                        } - -                        buffer_free (c->mem); -                        c->mem = NULL; - -                        c->type = FILE_CHUNK; -                        c->offset = c->file.length = 0; -                        c->file.name = NULL; - -                        if (first == c) -                                first = c->next; - -                        if (cq->last == c) -                                cq->last = NULL; - -                        prev->next = c->next; - -                        free(c); -                }      -                prev = c; -        } - -        network_backend_write (srv, con, fd, cq); - -        cq->first = first; - -        return chunks_written; -} - -int chunkqueue_append_glusterfs_file (connection *con, glusterfs_file_t fd, -                                      off_t offset, size_t len, size_t buf_size) -{ -        chunk *c = NULL; -        c = chunkqueue_get_append_tempfile (con->write_queue); -   -        if (c->file.is_temp) { -                close (c->file.fd); -                unlink (c->file.name->ptr); -        } - -        c->type = MEM_CHUNK; - -        buffer_free (c->mem); - -        c->mem = buffer_init (); -        c->mem->used = len + 1; -        c->mem->size = buf_size; -        c->mem->ptr = NULL; -        c->offset = 0; - -        buffer_free (c->file.name); - -        /* fd returned by libglusterfsclient is a pointer */ -        c->file.name = (buffer *)fd; -        c->file.start = offset; -        c->file.length = len; - -        //c->file.fd = fd; -        c->file.mmap.start = NULL; -        return 0; -} - -/* init the plugin data */ -INIT_FUNC(mod_glusterfs_init) { -        plugin_data *p; - -        p = calloc(1, sizeof(*p)); -        network_backend_write = NULL; - -        return p; -} - -/* detroy the plugin data */ -FREE_FUNC(mod_glusterfs_free) { -        plugin_data *p = p_d; - -        UNUSED (srv); - -        if (!p) return HANDLER_GO_ON; -   -        if (p->config_storage) { -                size_t i; -                for (i = 0; i < srv->config_context->used; i++) { -                        plugin_config *s = p->config_storage[i]; -       -                        buffer_free (s->logfile); -                        buffer_free (s->loglevel); -                        buffer_free (s->specfile); -                        buffer_free (s->prefix); -                        buffer_free (s->xattr_file_size); -                        buffer_free (s->document_root); -                        array_free (s->exclude_exts); -   -                        free (s); -                } -                free (p->config_storage); -        } -        buffer_free (p->range_buf); - -        free (p); -   -        return HANDLER_GO_ON; -} - -SETDEFAULTS_FUNC(mod_glusterfs_set_defaults) { -        plugin_data *p = p_d; -        size_t i = 0; -   -        config_values_t cv[] = { -                { "glusterfs.logfile",              NULL, T_CONFIG_STRING, -                  T_CONFIG_SCOPE_CONNECTION }, -     -                { "glusterfs.loglevel",             NULL, T_CONFIG_STRING, -                  T_CONFIG_SCOPE_CONNECTION },     - -                { "glusterfs.volume-specfile",      NULL, T_CONFIG_STRING, -                  T_CONFIG_SCOPE_CONNECTION },  - -                { "glusterfs.cache-timeout",        NULL, T_CONFIG_SHORT, -                  T_CONFIG_SCOPE_CONNECTION }, -     -                { "glusterfs.exclude-extensions",   NULL, T_CONFIG_ARRAY, -                  T_CONFIG_SCOPE_CONNECTION }, -     -                /*TODO: get the prefix from config_conext and  -                  remove glusterfs.prefix from conf file */ -                { "glusterfs.prefix",               NULL, T_CONFIG_STRING, -                  T_CONFIG_SCOPE_CONNECTION }, -     -                { "glusterfs.xattr-interface-size-limit", NULL, T_CONFIG_STRING, -                  T_CONFIG_SCOPE_CONNECTION }, - -                { "glusterfs.document-root",        NULL, T_CONFIG_STRING, -                  T_CONFIG_SCOPE_CONNECTION }, -     -                { NULL,                          NULL, T_CONFIG_UNSET, -                  T_CONFIG_SCOPE_UNSET } -        }; -   -        p->config_storage = calloc(1, -                                   srv->config_context->used -                                   * sizeof(specific_config *)); -        /* ERR_ABORT (p->config_storage);*/ -        p->range_buf = buffer_init (); -   -        for (i = 0; i < srv->config_context->used; i++) { -                plugin_config *s; - -                s = calloc(1, sizeof(plugin_config)); -                /* ERR_ABORT (s); */ -                s->logfile = buffer_init (); -                s->loglevel = buffer_init (); -                s->specfile = buffer_init (); -                s->document_root = buffer_init (); -                s->exclude_exts = array_init (); -                s->prefix = buffer_init (); -                s->xattr_file_size = buffer_init (); -     -                cv[0].destination = s->logfile; -                cv[1].destination = s->loglevel; -                cv[2].destination = s->specfile; -                cv[3].destination = &s->cache_timeout; -                cv[4].destination = s->exclude_exts; -                cv[5].destination = s->prefix; -                cv[6].destination = s->xattr_file_size; -                cv[7].destination = s->document_root; -                p->config_storage[i] = s; -     -                if (0 != config_insert_values_global(srv, -                                                     ((data_config *)srv->config_context->data[i])->value, -                                                     cv)) { -                        return HANDLER_FINISHED; -                } -        } -   -        return HANDLER_GO_ON; -} - -#define PATCH(x)                                \ -        p->conf.x = s->x; - -static int mod_glusterfs_patch_connection(server *srv, connection *con, -                                          plugin_data *p) { -        size_t i, j; -        plugin_config *s; - -        /* skip the first, the global context */ -        /*  -           glusterfs related config can only occur inside  -           $HTTP["url"] == "<glusterfs-prefix>" -        */ -        p->conf.logfile = NULL; -        p->conf.loglevel = NULL; -        p->conf.specfile = NULL; -        p->conf.cache_timeout = 0; -        p->conf.exclude_exts = NULL; -        p->conf.prefix = NULL; -        p->conf.xattr_file_size = NULL; -        p->conf.document_root = NULL; - -        for (i = 1; i < srv->config_context->used; i++) { -                data_config *dc = (data_config *)srv->config_context->data[i]; -                s = p->config_storage[i]; - -                /* condition didn't match */ -                if (!config_check_cond(srv, con, dc)) continue; -     -                /* merge config */ -                for (j = 0; j < dc->value->used; j++) { -                        data_unset *du = dc->value->data[j]; -       -                        if (buffer_is_equal_string (du->key, -                                                    CONST_STR_LEN("glusterfs.logfile"))) { -                                PATCH (logfile); -                        } else if (buffer_is_equal_string (du->key, -                                                           CONST_STR_LEN("glusterfs.loglevel"))) { -                                PATCH (loglevel); -                        } else if (buffer_is_equal_string (du->key, -                                                           CONST_STR_LEN ("glusterfs.volume-specfile"))) { -                                PATCH (specfile); -                        } else if (buffer_is_equal_string (du->key, -                                                           CONST_STR_LEN("glusterfs.cache-timeout"))) { -                                PATCH (cache_timeout); -                        } else if (buffer_is_equal_string (du->key, -                                                           CONST_STR_LEN ("glusterfs.exclude-extensions"))) { -                                PATCH (exclude_exts); -                        } else if (buffer_is_equal_string (du->key, -                                                           CONST_STR_LEN ("glusterfs.prefix"))) { -                                PATCH (prefix); -                        } else if (buffer_is_equal_string (du->key, -                                                           CONST_STR_LEN ("glusterfs.xattr-interface-size-limit"))) { -                                PATCH (xattr_file_size); -                        } else if (buffer_is_equal_string (du->key, -                                                           CONST_STR_LEN ("glusterfs.document-root"))) { -                                PATCH (document_root); -                        } -                } -        } -        return 0; -} - -#undef PATCH - -static int http_response_parse_range(server *srv, connection *con, -                                     plugin_data *p) { -        int multipart = 0; -        int error; -        off_t start, end; -        const char *s, *minus; -        char *boundary = "fkj49sn38dcn3"; -        data_string *ds; -        stat_cache_entry *sce = NULL; -        buffer *content_type = NULL; -        size_t size = 0; -        mod_glusterfs_ctx_t *ctx = con->plugin_ctx[p->id]; - -        if (p->conf.xattr_file_size && p->conf.xattr_file_size->ptr) { -                size = atoi (p->conf.xattr_file_size->ptr); -        } - -        if (HANDLER_ERROR == stat_cache_get_entry(srv, con, con->physical.path, -                                                  &sce)) { -                SEGFAULT(); -        } -   -        start = 0; -        end = sce->st.st_size - 1; -   -        con->response.content_length = 0; -   -        if (NULL != (ds = (data_string *)array_get_element(con->response.headers, -                                                           "Content-Type"))) { -                content_type = ds->value; -        } -   -        for (s = con->request.http_range, error = 0; -             !error && *s && NULL != (minus = strchr(s, '-')); ) { -                char *err; -                off_t la, le; -     -                if (s == minus) { -                        /* -<stop> */ -       -                        le = strtoll(s, &err, 10); -       -                        if (le == 0) { -                                /* RFC 2616 - 14.35.1 */ -         -                                con->http_status = 416; -                                error = 1; -                        } else if (*err == '\0') { -                                /* end */ -                                s = err; -         -                                end = sce->st.st_size - 1; -                                start = sce->st.st_size + le; -                        } else if (*err == ',') { -                                multipart = 1; -                                s = err + 1; -         -                                end = sce->st.st_size - 1; -                                start = sce->st.st_size + le; -                        } else { -                                error = 1; -                        } -       -                } else if (*(minus+1) == '\0' || *(minus+1) == ',') { -                        /* <start>- */ -       -                        la = strtoll(s, &err, 10); -       -                        if (err == minus) { -                                /* ok */ -         -                                if (*(err + 1) == '\0') { -                                        s = err + 1; -           -                                        end = sce->st.st_size - 1; -                                        start = la; -           -                                } else if (*(err + 1) == ',') { -                                        multipart = 1; -                                        s = err + 2; -           -                                        end = sce->st.st_size - 1; -                                        start = la; -                                } else { -                                        error = 1; -                                } -                        } else { -                                /* error */ -                                error = 1; -                        } -                } else { -                        /* <start>-<stop> */ -       -                        la = strtoll(s, &err, 10); - -                        if (err == minus) { -                                le = strtoll(minus+1, &err, 10); -         -                                /* RFC 2616 - 14.35.1 */ -                                if (la > le) { -                                        error = 1; -                                } -         -                                if (*err == '\0') { -                                        /* ok, end*/ -                                        s = err; - -                                        end = le; -                                        start = la; -                                } else if (*err == ',') { -                                        multipart = 1; -                                        s = err + 1; -           -                                        end = le; -                                        start = la; -                                } else { -                                        /* error */ -           -                                        error = 1; -                                } -                        } else { -                                /* error */ -         -                                error = 1; -                        } -                } -     -                if (!error) { -                        if (start < 0) start = 0; -       -                        /* RFC 2616 - 14.35.1 */ -                        if (end > sce->st.st_size - 1) end = sce->st.st_size - 1; -       -                        if (start > sce->st.st_size - 1) { -                                error = 1; -         -                                con->http_status = 416; -                        } -                } -     -                if (!error) { -                        if (multipart) { -                                /* write boundary-header */ -                                buffer *b; -         -                                b = chunkqueue_get_append_buffer(con->write_queue); -         -                                buffer_copy_string(b, "\r\n--"); -                                buffer_append_string(b, boundary); -         -                                /* write Content-Range */ -                                buffer_append_string(b, "\r\nContent-Range: " -                                                     "bytes "); -                                buffer_append_off_t(b, start); -                                buffer_append_string(b, "-"); -                                buffer_append_off_t(b, end); -                                buffer_append_string(b, "/"); -                                buffer_append_off_t(b, sce->st.st_size); -         -                                buffer_append_string(b, "\r\nContent-Type: "); -                                buffer_append_string_buffer(b, content_type); -         -                                /* write END-OF-HEADER */ -                                buffer_append_string(b, "\r\n\r\n"); -         -                                con->response.content_length += b->used - 1; - -                        } - -                        if ((size_t)sce->st.st_size >= size) { -                                chunkqueue_append_glusterfs_file(con, ctx->fd, -                                                                 start, -                                                                 end - start, -                                                                 size); -                        } else { -                                if (!start) { -                                        buffer *mem = buffer_init (); -                                        mem->ptr = ctx->buf; -                                        mem->used = mem->size = sce->st.st_size; -                                        http_chunk_append_buffer (srv, con, mem); -                                        ctx->buf = NULL; -                                } else { -                                        chunkqueue_append_mem (con->write_queue, -                                                               ((char *)ctx->buf) -                                                               + start, -                                                               end - start + 1); -                                } -                        } - -                        con->response.content_length += end - start + 1; -                } -        } - -        if (ctx->buf) { -                free (ctx->buf); -                ctx->buf = NULL; -        } - -        /* something went wrong */ -        if (error) return -1; -   -        if (multipart) { -                /* add boundary end */ -                buffer *b; -     -                b = chunkqueue_get_append_buffer(con->write_queue); -     -                buffer_copy_string_len(b, "\r\n--", 4); -                buffer_append_string(b, boundary); -                buffer_append_string_len(b, "--\r\n", 4); -     -                con->response.content_length += b->used - 1; -     -                /* set header-fields */ - -                buffer_copy_string(p->range_buf, "multipart/byteranges; boundary="); -                buffer_append_string(p->range_buf, boundary); - -                /* overwrite content-type */ -                response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), -                                          CONST_BUF_LEN(p->range_buf)); -        } else { -                /* add Content-Range-header */ -     -                buffer_copy_string(p->range_buf, "bytes "); -                buffer_append_off_t(p->range_buf, start); -                buffer_append_string(p->range_buf, "-"); -                buffer_append_off_t(p->range_buf, end); -                buffer_append_string(p->range_buf, "/"); -                buffer_append_off_t(p->range_buf, sce->st.st_size); -     -                response_header_insert(srv, con, CONST_STR_LEN("Content-Range"), -                                       CONST_BUF_LEN(p->range_buf)); -        } -         -        /* ok, the file is set-up */ -        return 0; -} - -PHYSICALPATH_FUNC(mod_glusterfs_handle_physical) { -        plugin_data *p = p_d; -        stat_cache_entry *sce; -        mod_glusterfs_ctx_t *plugin_ctx = NULL; -        size_t size = 0; -        int ret = 0; - -        if (con->http_status != 0) return HANDLER_GO_ON; -        if (con->uri.path->used == 0) return HANDLER_GO_ON; -        if (con->physical.path->used == 0) return HANDLER_GO_ON; - -        if (con->mode != DIRECT) return HANDLER_GO_ON; - -        /* -          network_backend_write = srv->network_backend_write; -          srv->network_backend_write = mod_glusterfs_network_backend_write; -        */ - -        switch (con->request.http_method) { -        case HTTP_METHOD_GET: -        case HTTP_METHOD_POST: -        case HTTP_METHOD_HEAD: -                break; - -        default: -                return HANDLER_GO_ON; -        } - -        mod_glusterfs_patch_connection(srv, con, p); -        if (!p->conf.prefix || p->conf.prefix->used == 0) { -                return HANDLER_GO_ON; -        } - -        if (!p->conf.document_root || p->conf.document_root->used == 0) { -                log_error_write(srv, __FILE__, __LINE__, "s", -                                "glusterfs.document-root is not specified"); -                con->http_status = 500; -                return HANDLER_FINISHED; -        } - -        if (!p->conf.mounted) { -                glusterfs_init_params_t ctx; - -                if (!p->conf.specfile || p->conf.specfile->used == 0) { -                        return HANDLER_GO_ON; -                } -                memset (&ctx, 0, sizeof (ctx)); - -                ctx.specfile = p->conf.specfile->ptr; -                ctx.logfile = p->conf.logfile->ptr; -                ctx.loglevel = p->conf.loglevel->ptr; -                ctx.lookup_timeout = ctx.stat_timeout = p->conf.cache_timeout; - -                ret = glusterfs_mount (p->conf.prefix->ptr, &ctx); -                if (ret != 0) { -                        con->http_status = 500; -                        log_error_write(srv, __FILE__, __LINE__,  "sbs", -                                        "glusterfs initialization failed, " -                                        "please check your configuration. " -                                        "Glusterfs logfile ", -                                        p->conf.logfile, -                                        "might contain details"); -                        return HANDLER_FINISHED; -                } -                p->conf.mounted = 1; -        } - -        size = 0; -        if (p->conf.xattr_file_size && p->conf.xattr_file_size->ptr)  -                size = atoi (p->conf.xattr_file_size->ptr); - -        if (!con->plugin_ctx[p->id]) { -/* FIXME: what if multiple files are requested from a single connection? */  -/* TODO: check whether this works fine for HTTP protocol 1.1 */ - -                buffer *tmp_buf = buffer_init_buffer (con->physical.basedir); - -                plugin_ctx = calloc (1, sizeof (*plugin_ctx)); -                /* ERR_ABORT (plugin_ctx); */ -                con->plugin_ctx[p->id] = plugin_ctx; -     -                buffer_append_string_buffer (tmp_buf, p->conf.prefix); -                buffer_path_simplify (tmp_buf, tmp_buf); - -                plugin_ctx->prefix = tmp_buf->used - 1; -                if (tmp_buf->ptr[plugin_ctx->prefix - 1] == '/') -                        plugin_ctx->prefix--; - -                buffer_free (tmp_buf); -        } else  -                /*FIXME: error!! error!! */ -                plugin_ctx = con->plugin_ctx[p->id]; - - -        if (size)  -        { -                plugin_ctx->buf = malloc (size); -                /* ERR_ABORT (plugin_ctx->buf); */ -        } - -        plugin_ctx->glusterfs_path = buffer_init (); -        buffer_copy_string_buffer (plugin_ctx->glusterfs_path, -                                   p->conf.prefix); -        buffer_append_string (plugin_ctx->glusterfs_path, -                              p->conf.document_root->ptr); -        buffer_append_string (plugin_ctx->glusterfs_path, "/"); -        buffer_append_string (plugin_ctx->glusterfs_path, -                              con->physical.path->ptr + plugin_ctx->prefix); -        buffer_path_simplify (plugin_ctx->glusterfs_path, -                              plugin_ctx->glusterfs_path); -  -        if (glusterfs_stat_cache_get_entry (srv, con, -                                            plugin_ctx->glusterfs_path, -                                            con->physical.path, plugin_ctx->buf, -                                            size, &sce) == HANDLER_ERROR) { -                if (errno == ENOENT) -                        con->http_status = 404; -                else  -                        con->http_status = 403; - -                free (plugin_ctx->buf); -                buffer_free (plugin_ctx->glusterfs_path); -                plugin_ctx->glusterfs_path = NULL; -                plugin_ctx->buf = NULL; - -                free (plugin_ctx); -                con->plugin_ctx[p->id] = NULL; - -                return HANDLER_FINISHED; -        } - -        if (!(S_ISREG (sce->st.st_mode) && (size_t)sce->st.st_size < size)) { -                free (plugin_ctx->buf); -                plugin_ctx->buf = NULL; -        } - -        return HANDLER_GO_ON; -} - -static int http_chunk_append_len(server *srv, connection *con, size_t len) { -        size_t i, olen = len, j; -        buffer *b; - -        b = srv->tmp_chunk_len; - -        if (len == 0) { -                buffer_copy_string(b, "0"); -        } else { -                for (i = 0; i < 8 && len; i++) { -                        len >>= 4; -                } -     -                /* i is the number of hex digits we have */ -                buffer_prepare_copy(b, i + 1); -     -                for (j = i-1, len = olen; j+1 > 0; j--) { -                        b->ptr[j] = (len & 0xf) + (((len & 0xf) <= 9) ?  -                                                   '0' : 'a' - 10); -                        len >>= 4; -                } -                b->used = i; -                b->ptr[b->used++] = '\0'; -        } -   -        buffer_append_string(b, "\r\n"); -        chunkqueue_append_buffer(con->write_queue, b); -   -        return 0; -} - -int http_chunk_append_glusterfs_file_chunk(server *srv, connection *con, -                                           glusterfs_file_t fd, off_t offset, -                                           off_t len, size_t buf_size) { -        chunkqueue *cq; - -        if (!con) return -1; - -        cq = con->write_queue; - -        if (con->response.transfer_encoding & HTTP_TRANSFER_ENCODING_CHUNKED) { -                http_chunk_append_len(srv, con, len); -        } - -        chunkqueue_append_glusterfs_file (con, fd, offset, len, buf_size); - -        if ((con->response.transfer_encoding & HTTP_TRANSFER_ENCODING_CHUNKED)  -            && (len > 0)) { -                chunkqueue_append_mem(cq, "\r\n", 2 + 1); -        } - -        return 0; -} - -int http_chunk_append_glusterfs_mem(server *srv, connection *con, -                                    char * mem, size_t len, -                                    size_t buf_size)  -{ -        chunkqueue *cq = NULL; -        buffer *buf = NULL; -  -        if (!con) return -1; -   -        cq = con->write_queue; -   -        if (len == 0) { -                free (mem); -                if (con->response.transfer_encoding  -                    & HTTP_TRANSFER_ENCODING_CHUNKED) { -                        chunkqueue_append_mem(cq, "0\r\n\r\n", 5 + 1); -                } else { -                        chunkqueue_append_mem(cq, "", 1); -                } -                return 0; -        } - -        if (con->response.transfer_encoding & HTTP_TRANSFER_ENCODING_CHUNKED) { -                http_chunk_append_len(srv, con, len - 1); -        } -   -        buf = buffer_init (); - -        buf->used = len + 1; -        buf->size = buf_size; -        buf->ptr = (char *)mem; -        chunkqueue_append_buffer_weak (cq, buf); - -        if (con->response.transfer_encoding & HTTP_TRANSFER_ENCODING_CHUNKED) { -                chunkqueue_append_mem(cq, "\r\n", 2 + 1); -        } - -        return 0; -} - - - -URIHANDLER_FUNC(mod_glusterfs_subrequest) { -        plugin_data *p = p_d; -        stat_cache_entry *sce = NULL; -        int s_len; -        char allow_caching = 1; -        size_t size = 0; -        mod_glusterfs_ctx_t *ctx = con->plugin_ctx[p->id]; - -        /* someone else has done a decision for us */ -        if (con->http_status != 0) return HANDLER_GO_ON; -        if (con->uri.path->used == 0) return HANDLER_GO_ON; -        if (con->physical.path->used == 0) return HANDLER_GO_ON; -   -        /* someone else has handled this request */ -        if (con->mode != DIRECT) return HANDLER_GO_ON; -   -        /* we only handle GET, POST and HEAD */ -        switch(con->request.http_method) { -        case HTTP_METHOD_GET: -        case HTTP_METHOD_POST: -        case HTTP_METHOD_HEAD: -                break; -        default: -                return HANDLER_GO_ON; -        } -   -        mod_glusterfs_patch_connection(srv, con, p); -   -        if (!p->conf.prefix || !p->conf.prefix->used) -                return HANDLER_GO_ON; - -        s_len = con->uri.path->used - 1; -        /* ignore certain extensions */ -        /* -          for (k = 0; k < p->conf.exclude_exts->used; k++) { -          data_string *ds; -          ds = (data_string *)p->conf.exclude_exts->data[k]; -           -          if (ds->value->used == 0) continue; -     -          if (!strncmp (ds->value->ptr, con->uri.path->ptr, -                        strlen (ds->value->ptr))) -          break; -          } -   -          if (k == p->conf.exclude_exts->used) { -          return HANDLER_GO_ON; -          } -        */ - -        if (con->conf.log_request_handling) { -                log_error_write(srv, __FILE__, __LINE__,  "s", -                                "-- serving file from glusterfs"); -        } - -        if (HANDLER_ERROR == stat_cache_get_entry(srv, con, con->physical.path, -                                                  &sce)) { -                con->http_status = 403; -                 -                log_error_write(srv, __FILE__, __LINE__, "sbsb", -                                "not a regular file:", con->uri.path, -                                "->", con->physical.path); -     -                free (ctx); -                con->plugin_ctx[p->id] = NULL; - -                return HANDLER_FINISHED; -        } - -        if (con->uri.path->ptr[s_len] == '/' || !S_ISREG(sce->st.st_mode)) { -                free (ctx); -                con->plugin_ctx[p->id] = NULL; -                return HANDLER_FINISHED; -        } - -        if (p->conf.xattr_file_size && p->conf.xattr_file_size->ptr) -                size = atoi (p->conf.xattr_file_size->ptr); - -        if ((size_t)sce->st.st_size > size) { -                ctx->fd = glusterfs_open (ctx->glusterfs_path->ptr, O_RDONLY, -                                          0); -     -                if (((long)ctx->fd) == 0) { -                        con->http_status = 403; -                        free (ctx); -                        con->plugin_ctx[p->id] = NULL; -                        return HANDLER_FINISHED; -                } -        } - -        buffer_free (ctx->glusterfs_path); -        ctx->glusterfs_path = NULL; - -        /* we only handline regular files */ -#ifdef HAVE_LSTAT -        if ((sce->is_symlink == 1) && !con->conf.follow_symlink) { -                con->http_status = 403; -           -                if (con->conf.log_request_handling) { -                        log_error_write(srv, __FILE__, __LINE__,  "s", -                                        "-- access denied due symlink " -                                        "restriction"); -                        log_error_write(srv, __FILE__, __LINE__,  "sb", -                                        "Path         :", con->physical.path); -                } -     -                buffer_reset(con->physical.path); -                free (ctx); -                con->plugin_ctx[p->id] = NULL; -                return HANDLER_FINISHED; -        } -#endif -        if (!S_ISREG(sce->st.st_mode)) { -                con->http_status = 404; -     -                if (con->conf.log_file_not_found) { -                        log_error_write(srv, __FILE__, __LINE__, "sbsb", -                                        "not a regular file:", con->uri.path, -                                        "->", sce->name); -                } -     -                free (ctx); -                con->plugin_ctx[p->id] = NULL; - -                return HANDLER_FINISHED; -        } - -        /* mod_compress might set several data directly, don't overwrite them */ - -        /* set response content-type, if not set already */ -   -        if (NULL == array_get_element(con->response.headers, "Content-Type")) { -                if (buffer_is_empty(sce->content_type)) { -                        /* we are setting application/octet-stream, but also " -                         * announce that this header field might change in " -                         * the seconds few requests. This should fix the  -                         * aggressive caching of FF and the script download -                         * seen by the first installations -                         */ -                        response_header_overwrite(srv, con, -                                                  CONST_STR_LEN("Content-Type"), -                                                  CONST_STR_LEN("application/" -                                                                "octet-stream")); -       -                        allow_caching = 0; -                } else { -                        response_header_overwrite(srv, con, -                                                  CONST_STR_LEN("Content-Type"), -                                                  CONST_BUF_LEN(sce->content_type)); -                } -        } -   -        if (con->conf.range_requests) { -                response_header_overwrite(srv, con, -                                          CONST_STR_LEN("Accept-Ranges"), -                                          CONST_STR_LEN("bytes")); -        } - -        /* TODO: Allow Cachable requests */      -#if 0 -        if (allow_caching) { -                if (p->conf.etags_used && con->etag_flags != 0  -                    && !buffer_is_empty(sce->etag)) { -                        if (NULL == array_get_element(con->response.headers, -                                                      "ETag")) { -                                /* generate e-tag */ -                                etag_mutate(con->physical.etag, sce->etag); -         -                                response_header_overwrite(srv, con, -                                                          CONST_STR_LEN("ETag"), -                                                          CONST_BUF_LEN(con->physical.etag)); -                        } -                } -     -                /* prepare header */ -                if (NULL == (ds = (data_string *)array_get_element(con->response.headers, -                                                                   "Last-Modified"))) { -                        mtime = strftime_cache_get(srv, sce->st.st_mtime); -                        response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), -                                                  CONST_BUF_LEN(mtime)); -                } else { -                        mtime = ds->value; -                } -     -                if (HANDLER_FINISHED == http_response_handle_cachable(srv, con, -                                                                      mtime)) { -                        free (ctx); -                        con->plugin_ctx[p->id] = NULL; -                        return HANDLER_FINISHED; -                } -        } -#endif  -   -        /*TODO: Read about etags */ -        if (con->request.http_range && con->conf.range_requests) { -                int do_range_request = 1; -                data_string *ds = NULL; -                buffer *mtime = NULL; -                /* check if we have a conditional GET */ -     -                /* prepare header */ -                if (NULL == (ds = (data_string *)array_get_element(con->response.headers, -                                                                   "Last-Modified"))) { -                        mtime = strftime_cache_get(srv, sce->st.st_mtime); -                        response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), -                                                  CONST_BUF_LEN(mtime)); -                } else { -                        mtime = ds->value; -                } - -                if (NULL != (ds = (data_string *)array_get_element(con->request.headers, -                                                                   "If-Range"))) { -                        /* if the value is the same as our ETag, we do a Range-request, -                         * otherwise a full 200 */ -             -                        if (ds->value->ptr[0] == '"') { -                                /** -                                 * client wants a ETag -                                 */ -                                if (!con->physical.etag) { -                                        do_range_request = 0; -                                } else if (!buffer_is_equal(ds->value, -                                                            con->physical.etag)) { -                                        do_range_request = 0; -                                } -                        } else if (!mtime) { -                                /** -                                 * we don't have a Last-Modified and can match  -                                 * the If-Range:  -                                 * -                                 * sending all -                                 */ -                                do_range_request = 0; -                        } else if (!buffer_is_equal(ds->value, mtime)) { -                                do_range_request = 0; -                        } -                } -     -                if (do_range_request) { -                        /* content prepared, I'm done */ -                        con->file_finished = 1; -             -                        if (0 == http_response_parse_range(srv, con, p)) { -                                con->http_status = 206; -                        } - -                        free (ctx); -                        con->plugin_ctx[p->id] = NULL; -                        return HANDLER_FINISHED; -                } -        } -   -        /* if we are still here, prepare body */ - -        /* we add it here for all requests -         * the HEAD request will drop it afterwards again -         */ -        /*TODO check whether 1 should be subtracted */ - -        if (p->conf.xattr_file_size && p->conf.xattr_file_size->ptr) -                size = atoi (p->conf.xattr_file_size->ptr); - -        if (size <= (size_t)sce->st.st_size) { -                http_chunk_append_glusterfs_file_chunk (srv, con, ctx->fd, 0, -                                                        sce->st.st_size, size); -        } else { -                http_chunk_append_glusterfs_mem (srv, con, ctx->buf, -                                                 sce->st.st_size, size); -        } -         -        con->http_status = 200; -        con->file_finished = 1; -   -        free (ctx); -        con->plugin_ctx[p->id] = NULL; - -        return HANDLER_FINISHED; -} - -#if 0 -URIHANDLER_FUNC(mod_glusterfs_request_done) -{ -        mod_glusterfs_iobuf_t *cur = first, *prev; -        while (cur) { -                prev =  cur; -                glusterfs_free (cur->buf); -                cur = cur->next; -                free (prev); -        } -        first = NULL -                } -#endif - -/* this function is called at dlopen() time and inits the callbacks */ -CONNECTION_FUNC(mod_glusterfs_connection_reset)  -{ -        (void) p_d; -        (void) con; -        if (!network_backend_write) -                network_backend_write = srv->network_backend_write; - -        srv->network_backend_write = mod_glusterfs_network_backend_write; - -        return HANDLER_GO_ON; -} - -int mod_glusterfs_plugin_init(plugin *p) { -        p->version     = LIGHTTPD_VERSION_ID; -        p->name        = buffer_init_string("glusterfs"); -        p->init        = mod_glusterfs_init; -        p->handle_physical = mod_glusterfs_handle_physical; -        p->handle_subrequest_start = mod_glusterfs_subrequest; -        //      p->handle_request_done = mod_glusterfs_request_done; -        p->set_defaults  = mod_glusterfs_set_defaults; -        p->connection_reset = mod_glusterfs_connection_reset; -        p->cleanup     = mod_glusterfs_free; -   -        p->data        = NULL; -   -        return 0; -} - - -/* mod_glusterfs_stat_cache */ -static stat_cache_entry * stat_cache_entry_init(void) { -        stat_cache_entry *sce = NULL; -   -        sce = calloc(1, sizeof(*sce)); -        /* ERR_ABORT (sce); */ -   -        sce->name = buffer_init(); -        sce->etag = buffer_init(); -        sce->content_type = buffer_init(); - -        return sce; -} - -#ifdef HAVE_FAM_H -static fam_dir_entry * fam_dir_entry_init(void) { -        fam_dir_entry *fam_dir = NULL; -   -        fam_dir = calloc(1, sizeof(*fam_dir)); -        /* ERR_ABORT (fam_dir); */ -   -        fam_dir->name = buffer_init(); -   -        return fam_dir; -} - -static void fam_dir_entry_free(void *data) { -        fam_dir_entry *fam_dir = data; - -        if (!fam_dir) return; - -        FAMCancelMonitor(fam_dir->fc, fam_dir->req); - -        buffer_free(fam_dir->name); -        free(fam_dir->req); - -        free(fam_dir); -} -#endif - -#ifdef HAVE_XATTR -static int stat_cache_attr_get(buffer *buf, char *name) { -        int attrlen; -        int ret; -   -        attrlen = 1024; -        buffer_prepare_copy(buf, attrlen); -        attrlen--; -        if(0 == (ret = attr_get(name, "Content-Type", buf->ptr, &attrlen, 0))) { -                buf->used = attrlen + 1; -                buf->ptr[attrlen] = '\0'; -        } -        return ret; -} -#endif - -/* the famous DJB hash function for strings */ -static uint32_t hashme(buffer *str) { -        uint32_t hash = 5381; -        const char *s; -        for (s = str->ptr; *s; s++) { -                hash = ((hash << 5) + hash) + *s; -        } -   -        hash &= ~(1 << 31); /* strip the highest bit */ -   -        return hash; -} - - -#ifdef HAVE_LSTAT -static int stat_cache_lstat(server *srv, buffer *dname, struct stat *lst) { -        if (lstat(dname->ptr, lst) == 0) { -                return S_ISLNK(lst->st_mode) ? 0 : 1; -        } -        else { -                log_error_write(srv, __FILE__, __LINE__, "sbs", -                                "lstat failed for:", -                                dname, strerror(errno)); -        }; -        return -1; -} -#endif - -/*** - * - * - * - * returns: - *  - HANDLER_FINISHED on cache-miss (don't forget to reopen the file) - *  - HANDLER_ERROR on stat() failed -> see errno for problem - */ - -handler_t glusterfs_stat_cache_get_entry(server *srv,  -                                         connection *con,  -                                         buffer *glusterfs_path, -                                         buffer *name,  -                                         void *buf,  -                                         size_t size,  -                                         stat_cache_entry **ret_sce)  -{ -#ifdef HAVE_FAM_H -        fam_dir_entry *fam_dir = NULL; -        int dir_ndx = -1; -        splay_tree *dir_node = NULL; -#endif -        stat_cache_entry *sce = NULL; -        stat_cache *sc; -        struct stat st;  -        size_t k; -#ifdef DEBUG_STAT_CACHE -        size_t i; -#endif -        int file_ndx; -        splay_tree *file_node = NULL; - -        *ret_sce = NULL; -        memset (&st, 0, sizeof (st)); - -        /* -         * check if the directory for this file has changed -         */ - -        sc = srv->stat_cache; - -        buffer_copy_string_buffer(sc->hash_key, name); -        buffer_append_long(sc->hash_key, con->conf.follow_symlink); - -        file_ndx = hashme(sc->hash_key); -        sc->files = splaytree_splay(sc->files, file_ndx); - -#ifdef DEBUG_STAT_CACHE -        for (i = 0; i < ctrl.used; i++) { -                if (ctrl.ptr[i] == file_ndx) break; -        } -#endif - -        if (sc->files && (sc->files->key == file_ndx)) { -#ifdef DEBUG_STAT_CACHE -                /* it was in the cache */ -                assert(i < ctrl.used); -#endif - -                /* we have seen this file already and -                 * don't stat() it again in the same second */ - -                file_node = sc->files; - -                sce = file_node->data; - -                /* check if the name is the same, we might have a collision */ - -                if (buffer_is_equal(name, sce->name)) { -                        if (srv->srvconf.stat_cache_engine  -                            == STAT_CACHE_ENGINE_SIMPLE) { -                                if (sce->stat_ts == srv->cur_ts && !buf) { -                                        *ret_sce = sce; -                                        return HANDLER_GO_ON; -                                } -                        } -                } else { -                        /* oops, a collision, -                         * -                         * file_node is used by the FAM check below to see if  -                         * we know this file and if we can save a stat(). -                         * -                         * BUT, the sce is not reset here as the entry into  -                         * the cache is ok, we it is just not pointing to  -                         * our requested file. -                         */ - -                        file_node = NULL; -                } -        } else { -#ifdef DEBUG_STAT_CACHE -                if (i != ctrl.used) { -                        fprintf(stderr, "%s.%d: %08x was already inserted " -                                "but not found in cache, %s\n", -                                __FILE__, __LINE__, file_ndx, name->ptr); -                } -                assert(i == ctrl.used); -#endif -        } -        /* -         * *lol* -         * - open() + fstat() on a named-pipe results in a (intended) hang. -         * - stat() if regular file + open() to see if we can read from it is  -         *   better -         * -         * */ -        if (-1 == glusterfs_get (glusterfs_path->ptr, buf, size, &st)) { -                return HANDLER_ERROR; -        } - -        if (NULL == sce) { -                int osize = 0; - -                if (sc->files) { -                        osize = sc->files->size; -                } - -                sce = stat_cache_entry_init(); -                buffer_copy_string_buffer(sce->name, name); - -                sc->files = splaytree_insert(sc->files, file_ndx, sce); -#ifdef DEBUG_STAT_CACHE -                if (ctrl.size == 0) { -                        ctrl.size = 16; -                        ctrl.used = 0; -                        ctrl.ptr = malloc(ctrl.size * sizeof(*ctrl.ptr)); -                        /* ERR_ABORT (ctrl.ptr); */ -                } else if (ctrl.size == ctrl.used) { -                        ctrl.size += 16; -                        ctrl.ptr = realloc(ctrl.ptr, -                                           ctrl.size * sizeof(*ctrl.ptr)); -                        /* ERR_ABORT (ctrl.ptr); */ -                } - -                ctrl.ptr[ctrl.used++] = file_ndx; - -                assert(sc->files); -                assert(sc->files->data == sce); -                assert(osize + 1 == splaytree_size(sc->files)); -#endif -        } - -        sce->st = st; -        sce->stat_ts = srv->cur_ts; - -        /* catch the obvious symlinks -         * -         * this is not a secure check as we still have a race-condition between -         * the stat() and the open. We can only solve this by -         * 1. open() the file -         * 2. fstat() the fd -         * -         * and keeping the file open for the rest of the time. But this can -         * only be done at network level. -         * -         * per default it is not a symlink -         * */ -#ifdef HAVE_LSTAT -        sce->is_symlink = 0; - -        /* we want to only check for symlinks if we should block symlinks. -         */ -        if (!con->conf.follow_symlink) { -                if (stat_cache_lstat(srv, name, &lst)  == 0) { -#ifdef DEBUG_STAT_CACHE -                        log_error_write(srv, __FILE__, __LINE__, "sb", -                                        "found symlink", name); -#endif -                        sce->is_symlink = 1; -                } - -                /* -                 * we assume "/" can not be symlink, so -                 * skip the symlink stuff if our path is / -                 **/ -                else if ((name->used > 2)) { -                        buffer *dname; -                        char *s_cur; - -                        dname = buffer_init(); -                        buffer_copy_string_buffer(dname, name); - -                        while ((s_cur = strrchr(dname->ptr,'/'))) { -                                *s_cur = '\0'; -                                dname->used = s_cur - dname->ptr + 1; -                                if (dname->ptr == s_cur) { -#ifdef DEBUG_STAT_CACHE -                                        log_error_write(srv, __FILE__, __LINE__, -                                                        "s", "reached /"); -#endif -                                        break; -                                } -#ifdef DEBUG_STAT_CACHE -                                log_error_write(srv, __FILE__, __LINE__, "sbs", -                                                "checking if", dname, "is a " -                                                "symlink"); -#endif -                                if (stat_cache_lstat(srv, dname, &lst)  == 0) { -                                        sce->is_symlink = 1; -#ifdef DEBUG_STAT_CACHE -                                        log_error_write(srv, __FILE__, __LINE__, -                                                        "sb", -                                                        "found symlink", dname); -#endif -                                        break; -                                }; -                        }; -                        buffer_free(dname); -                }; -        }; -#endif - -        if (S_ISREG(st.st_mode)) { -                /* determine mimetype */ -                buffer_reset(sce->content_type); - -                for (k = 0; k < con->conf.mimetypes->used; k++) { -                        data_string *ds = NULL; -                        buffer *type = NULL; - -                        ds = (data_string *)con->conf.mimetypes->data[k]; -                        type = ds->key; -                        if (type->used == 0) continue; - -                        /* check if the right side is the same */ -                        if (type->used > name->used) continue; - -                        if (0 == strncasecmp(name->ptr + name->used - type->used, -                                             type->ptr, type->used - 1)) { -                                buffer_copy_string_buffer(sce->content_type, -                                                          ds->value); -                                break; -                        } -                } -                etag_create(sce->etag, &(sce->st), con->etag_flags); -#ifdef HAVE_XATTR -                if (con->conf.use_xattr && buffer_is_empty(sce->content_type)) { -                        stat_cache_attr_get(sce->content_type, name->ptr); -                } -#endif -        } else if (S_ISDIR(st.st_mode)) { -                etag_create(sce->etag, &(sce->st), con->etag_flags); -        } - -#ifdef HAVE_FAM_H -        if (sc->fam && -            (srv->srvconf.stat_cache_engine == STAT_CACHE_ENGINE_FAM)) { -                /* is this directory already registered ? */ -                if (!dir_node) { -                        fam_dir = fam_dir_entry_init(); -                        fam_dir->fc = sc->fam; - -                        buffer_copy_string_buffer(fam_dir->name, sc->dir_name); - -                        fam_dir->version = 1; - -                        fam_dir->req = calloc(1, sizeof(FAMRequest)); -                        /* ERR_ABORT (fam_dir->req); */ - -                        if (0 != FAMMonitorDirectory(sc->fam, fam_dir->name->ptr, -                                                     fam_dir->req, fam_dir)) { - -                                log_error_write(srv, __FILE__, __LINE__, "sbsbs", -                                                "monitoring dir failed:", -                                                fam_dir->name,  -                                                "file:", name, -                                                FamErrlist[FAMErrno]); - -                                fam_dir_entry_free(fam_dir); -                        } else { -                                int osize = 0; - -                                if (sc->dirs) { -                                        osize = sc->dirs->size; -                                } - -                                sc->dirs = splaytree_insert(sc->dirs, dir_ndx, -                                                            fam_dir); -                                assert(sc->dirs); -                                assert(sc->dirs->data == fam_dir); -                                assert(osize == (sc->dirs->size - 1)); -                        } -                } else { -                        fam_dir = dir_node->data; -                } - -                /* bind the fam_fc to the stat() cache entry */ - -                if (fam_dir) { -                        sce->dir_version = fam_dir->version; -                        sce->dir_ndx     = dir_ndx; -                } -        } -#endif - -        *ret_sce = sce; - -        return HANDLER_GO_ON; -} - -/** - * remove stat() from cache which havn't been stat()ed for - * more than 10 seconds - * - * - * walk though the stat-cache, collect the ids which are too old - * and remove them in a second loop - */ - -static int stat_cache_tag_old_entries(server *srv, splay_tree *t, int *keys, -                                      size_t *ndx) { -        stat_cache_entry *sce; - -        if (!t) return 0; - -        stat_cache_tag_old_entries(srv, t->left, keys, ndx); -        stat_cache_tag_old_entries(srv, t->right, keys, ndx); - -        sce = t->data; - -        if (srv->cur_ts - sce->stat_ts > 2) { -                keys[(*ndx)++] = t->key; -        } - -        return 0; -} diff --git a/mod_glusterfs/lighttpd/1.4/mod_glusterfs.h b/mod_glusterfs/lighttpd/1.4/mod_glusterfs.h deleted file mode 100644 index 9d73d6999ed..00000000000 --- a/mod_glusterfs/lighttpd/1.4/mod_glusterfs.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _MOD_GLUSTERFS_FILE_CACHE_H_ -#define _MOD_GLUSTERFS_FILE_CACHE_H_ - -#include "stat_cache.h" -#include <libglusterfsclient.h> -#include "base.h" - -handler_t glusterfs_stat_cache_get_entry(server *srv, connection *con, -                                         buffer *glusterfs_path, buffer *name, -                                         void *buf, size_t size, -                                         stat_cache_entry **fce); - -#endif diff --git a/mod_glusterfs/lighttpd/1.5/Makefile.am b/mod_glusterfs/lighttpd/1.5/Makefile.am deleted file mode 100644 index eda329111dc..00000000000 --- a/mod_glusterfs/lighttpd/1.5/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -EXTRA_DIST = Makefile.am.diff mod_glusterfs.c mod_glusterfs.h README.txt - -CLEANFILES =  diff --git a/mod_glusterfs/lighttpd/1.5/Makefile.am.diff b/mod_glusterfs/lighttpd/1.5/Makefile.am.diff deleted file mode 100644 index 375696b5d8f..00000000000 --- a/mod_glusterfs/lighttpd/1.5/Makefile.am.diff +++ /dev/null @@ -1,29 +0,0 @@ ---- lighttpd-1.4.19/src/Makefile.am	2008-04-16 18:42:18.000000000 +0400 -+++ lighttpd-1.4.19.mod/src/Makefile.am	2008-04-16 18:41:11.000000000 +0400 -@@ -1,4 +1,4 @@ --AM_CFLAGS = $(FAM_CFLAGS) -+AM_CFLAGS = $(FAM_CFLAGS)  -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -  - noinst_PROGRAMS=proc_open lemon # simple-fcgi #graphic evalo bench ajp ssl error_test adserver gen-license - sbin_PROGRAMS=lighttpd lighttpd-angel -@@ -241,6 +241,11 @@ - mod_accesslog_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined - mod_accesslog_la_LIBADD = $(common_libadd) -  -+lib_LTLIBRARIES += mod_glusterfs.la -+mod_glusterfs_la_SOURCES = mod_glusterfs.c -+mod_glusterfs_la_CFLAGS = $(AM_CFLAGS)  -+mod_glusterfs_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined -lglusterfsclient -lpthread -+mod_glusterfs_la_LIBADD = $(common_libadd)  -  - hdr = server.h buffer.h network.h log.h keyvalue.h \ -       response.h request.h fastcgi.h chunk.h \ -@@ -254,7 +259,7 @@ -       configparser.h mod_ssi_exprparser.h \ -       sys-mmap.h sys-socket.h mod_cml.h mod_cml_funcs.h \ -       splaytree.h proc_open.h status_counter.h \ --      mod_magnet_cache.h -+      mod_magnet_cache.h mod_glusterfs.h -  - DEFS= @DEFS@ -DLIBRARY_DIR="\"$(libdir)\"" -DSBIN_DIR="\"$(sbindir)\"" -  diff --git a/mod_glusterfs/lighttpd/1.5/README.txt b/mod_glusterfs/lighttpd/1.5/README.txt deleted file mode 100644 index bdbdfffbc50..00000000000 --- a/mod_glusterfs/lighttpd/1.5/README.txt +++ /dev/null @@ -1,57 +0,0 @@ -Introduction -============ -mod_glusterfs is a module written for lighttpd to speed up the access of files present on glusterfs. mod_glusterfs uses libglusterfsclient library provided for glusterfs and hence can be used without fuse (File System in User Space). - -Usage -===== -To use mod_glusterfs with lighttpd-1.5, copy mod_glusterfs.c and mod_glusterfs.h into src/ of lighttpd-1.5 source tree, and apply the Makefile.am.diff to src/Makefile.am. Re-run ./autogen.sh on the top level of the lighttpd-1.5 build tree and recompile. - -# cp mod_glusterfs.[ch] /home/glusterfs/lighttpd-1.5/src/ -# cp Makefile.am.diff /home/glusterfs/lighttpd-1.5/ -# cd /home/glusterfs/lighttpd-1.5 -# patch -p1 < Makefile.am.diff  -# ./autogen.sh -# ./configure -# make -# make install - -Configuration -============= -* mod_glusterfs should be listed at the begining of the list server.modules in lighttpd.conf.  - -Below is a snippet from lighttpd.conf concerning to mod_glusterfs. - -$HTTP["url"] =~ "^/glusterfs" { -	glusterfs.prefix = "/glusterfs"  -	glusterfs.logfile = "/var/log/glusterfs-logfile" -	glusterfs.document-root = "/home/glusterfs/document-root" -	glusterfs.volume-specfile = "/etc/glusterfs/glusterfs.vol" -	glusterfs.loglevel = "error" -	glusterfs.cache-timeout = 300 -	glusterfs.xattr-interface-size-limit = "65536" -} - -* $HTTP["url"] =~ "^/glusterfs" -  A perl style regular expression used to match against the url. If regular expression matches the url, the url is handled by mod_glusterfs. Note that the pattern given here should match glusterfs.prefix. - -* glusterfs.prefix (COMPULSORY) -  A string to be present at the starting of the file path in the url so that the file would be handled by glusterfs. -  Eg., A GET request on the url http://www.example.com/glusterfs-prefix/some-dir/example-file will result in fetching of the file "/some-dir/example-file" from glusterfs mount if glusterfs.prefix is set to "/glusterfs-prefix". - -* glusterfs.volume-specfile (COMPULSORY) -  Path to the the glusterfs volume specification file. - -* glusterfs.logfile (COMPULSORY) -  Path to the glusterfs logfile. - -* glusterfs.loglevel (OPTIONAL, default = warning) -  Allowed values are critical, error, warning, debug, none in the decreasing order of severity of error conditions. - -* glusterfs.cache-timeout (OPTIONAL, default = 0) -  Timeout values for glusterfs stat and lookup cache. - -* glusterfs.document-root (COMPULSORY) -  An absolute path, relative to which all the files are fetched from glusterfs. - -* glusterfs.xattr-interface-size-limit (OPTIONAL, default = 0) -  Files with sizes upto and including this value are fetched through the extended attribute interface of glusterfs rather than the usual open-read-close set of operations. For files of small sizes, it is recommended to use extended attribute interface. diff --git a/mod_glusterfs/lighttpd/1.5/mod_glusterfs.c b/mod_glusterfs/lighttpd/1.5/mod_glusterfs.c deleted file mode 100644 index 67f7a7eacf5..00000000000 --- a/mod_glusterfs/lighttpd/1.5/mod_glusterfs.c +++ /dev/null @@ -1,1476 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#include <ctype.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <pthread.h> -#include <sys/types.h> -#include <fcntl.h> - -#include <sys/types.h> -#include <sys/stat.h> - -#include <errno.h> -#include <unistd.h> -#include <assert.h> - -#include "base.h" -#include "log.h" -#include "buffer.h" - -#include "plugin.h" - -#include "stat_cache.h" -#include "mod_glusterfs.h" -#include "etag.h" -#include "response.h" - -#include "fdevent.h" -#include "joblist.h" -#include "http_req_range.h" -#include "connections.h" -#include "configfile.h" - -#include <libglusterfsclient.h> - -#ifdef HAVE_ATTR_ATTRIBUTES_H -#include <attr/attributes.h> -#endif - -#ifdef HAVE_FAM_H -# include <fam.h> -#endif - -#include "sys-mmap.h" - -/* NetBSD 1.3.x needs it */ -#ifndef MAP_FAILED -# define MAP_FAILED -1 -#endif - -#ifndef O_LARGEFILE -# define O_LARGEFILE 0 -#endif - -#ifndef HAVE_LSTAT -#define lstat stat -#endif - -#if 0 -/* enables debug code for testing if all nodes in the stat-cache as accessable */ -#define DEBUG_STAT_CACHE -#endif - -#ifdef HAVE_LSTAT -#undef HAVE_LSTAT -#endif - -#define GLUSTERFS_FILE_CHUNK (FILE_CHUNK + 1) - -/* Keep this value large. Each glusterfs_async_read of GLUSTERFS_CHUNK_SIZE results in a network_backend_write of the read data*/ - -#define GLUSTERFS_CHUNK_SIZE 8192 - -/** - * this is a staticfile for a lighttpd plugin - * - */ - - -/* plugin config for all request/connections */ - -typedef struct { -        buffer *logfile; -        buffer *loglevel; -        buffer *specfile; -        buffer *prefix; -        buffer *xattr_file_size; -        buffer *document_root; -        array *exclude_exts; -        unsigned short cache_timeout; - -        /* FIXME: its a pointer, hence cant be short */ -        unsigned long handle; -} plugin_config; - -static network_status_t (*network_backend_write)(struct server *srv, connection *con, iosocket *sock, chunkqueue *cq); - -typedef struct { -        PLUGIN_DATA; -        buffer *range_buf; -        plugin_config **config_storage; -        http_req_range *ranges; -        plugin_config conf; -} plugin_data; - -typedef struct glusterfs_async_local { -        int op_ret; -        int op_errno; -        pthread_mutex_t lock; -        pthread_cond_t cond; -        connection *con; -        server *srv; -        plugin_data *p; - -        union { -                struct { -                        char async_read_complete; -                        off_t length; -                        size_t read_bytes; -                        glusterfs_read_buf_t *buf; -                }readv; - -                struct { -                        buffer *name; -                        buffer *hash_key; -                        size_t size; -                }lookup; -        }fop; -} glusterfs_async_local_t; - -typedef struct { -        unsigned long fd; -        buffer *glusterfs_path; -        void *buf; -        off_t response_content_length; -        int prefix; -}mod_glusterfs_ctx_t; - -typedef struct { -        chunkqueue *cq; -        glusterfs_read_buf_t *buf; -        size_t length; -}mod_glusterfs_chunkqueue; - -#ifdef HAVE_FAM_H -typedef struct { -        FAMRequest *req; -        FAMConnection *fc; - -        buffer *name; - -        int version; -} fam_dir_entry; -#endif - -/* the directory name is too long to always compare on it - * - we need a hash - * - the hash-key is used as sorting criteria for a tree - * - a splay-tree is used as we can use the caching effect of it - */ - -/* we want to cleanup the stat-cache every few seconds, let's say 10 - * - * - remove entries which are outdated since 30s - * - remove entries which are fresh but havn't been used since 60s - * - if we don't have a stat-cache entry for a directory, release it from the monitor - */ - -#ifdef DEBUG_STAT_CACHE -typedef struct { -        int *ptr; - -        size_t used; -        size_t size; -} fake_keys; - -static fake_keys ctrl; -#endif - -static stat_cache_entry *  -stat_cache_entry_init(void)  -{ -        stat_cache_entry *sce = NULL; - -        sce = calloc(1, sizeof(*sce)); -        /* ERR_ABORT (sce); */ - -        sce->name = buffer_init(); -        sce->etag = buffer_init(); -        sce->content_type = buffer_init(); - -        return sce; -} - -int chunkqueue_append_glusterfs_mem (chunkqueue *cq, const char * mem, size_t len) { -        buffer *buf = NULL; -  -        buf = chunkqueue_get_append_buffer (cq); - -        if (buf->ptr) -                free (buf->ptr); - -        buf->used = len + 1; -        buf->ptr = (char *)mem; -        buf->size = len; - -        return 0; -} - -static int -glusterfs_lookup_async_cbk (int op_ret,  -                            int op_errno, -                            void *buf, -                            struct stat *st, -                            void *cbk_data) -{ -        glusterfs_async_local_t *local = cbk_data; - -        mod_glusterfs_ctx_t *ctx = NULL; -        ctx = local->con->plugin_ctx[local->p->id]; - -        assert (ctx->buf== buf); - -        if (op_ret || !(S_ISREG (st->st_mode) && (size_t)st->st_size <= local->fop.lookup.size)) { - -                free (ctx->buf); -                ctx->buf = NULL; - -                if (op_ret) { -                        buffer_free (ctx->glusterfs_path); -                        ctx->glusterfs_path = NULL; -                        free (ctx); -                        local->con->plugin_ctx[local->p->id] = NULL; - -                        if (op_errno == ENOENT) -                                local->con->http_status = 404; -                        else  -                                local->con->http_status = 403; -                } -        } - -        if (!op_ret) { -                stat_cache_entry *sce = NULL; -                stat_cache *sc = local->srv->stat_cache; - -                sce = (stat_cache_entry *)g_hash_table_lookup(sc->files, local->fop.lookup.hash_key); - -                if (!sce) { -                        sce = stat_cache_entry_init(); - -                        buffer_copy_string_buffer(sce->name, local->fop.lookup.name); -                        g_hash_table_insert(sc->files, buffer_init_string(BUF_STR(local->fop.lookup.hash_key)), sce); -                } - -                sce->state = STAT_CACHE_ENTRY_STAT_FINISHED; -                sce->stat_ts = time (NULL); -                memcpy (&sce->st, st, sizeof (*st)); -        } - -        g_async_queue_push (local->srv->joblist_queue, local->con); -        /* -          joblist_append (local->srv, local->con); -          kill (getpid(), SIGUSR1); -        */ -        free (local); -        return 0; -} - -static handler_t -glusterfs_stat_cache_get_entry_async (server *srv,  -                                      connection *con,  -                                      plugin_data *p, -                                      buffer *glusterfs_path, -                                      buffer *name, -                                      void *buf, -                                      size_t size, -                                      stat_cache_entry **ret_sce) -{ -        stat_cache_entry *sce = NULL; -        stat_cache *sc; -        glusterfs_async_local_t *local = NULL; - -        *ret_sce = NULL; - -        /* -         * check if the directory for this file has changed -         */ - -        sc = srv->stat_cache; - -        buffer_copy_string_buffer(sc->hash_key, name); -        buffer_append_long(sc->hash_key, con->conf.follow_symlink); - -        if ((sce = (stat_cache_entry *)g_hash_table_lookup(sc->files, sc->hash_key))) { -                /* know this entry already */ - -                if (sce->state == STAT_CACHE_ENTRY_STAT_FINISHED &&  -                    !buf) { -                        /* verify that this entry is still fresh */ - -                        *ret_sce = sce; - -                        return HANDLER_GO_ON; -                } -        } - - -        /* -         * *lol* -         * - open() + fstat() on a named-pipe results in a (intended) hang. -         * - stat() if regular file + open() to see if we can read from it is better -         * -         * */ - -        /* pass a job to the stat-queue */ - -        local = calloc (1, sizeof (*local)); -        /* ERR_ABORT (local); */ -        local->con = con; -        local->srv = srv; -        local->p = p; -        local->fop.lookup.name = buffer_init_buffer (name); -        local->fop.lookup.hash_key = buffer_init_buffer (sc->hash_key); -        local->fop.lookup.size = size; - -        if (glusterfs_lookup_async ((libglusterfs_handle_t )p->conf.handle, glusterfs_path->ptr, buf, size, glusterfs_lookup_async_cbk, (void *) local)) { -                free (local); -                return HANDLER_ERROR; -        } - -        return HANDLER_WAIT_FOR_EVENT; -} - -int  -mod_glusterfs_readv_async_cbk (glusterfs_read_buf_t *buf, -                               void *cbk_data) -{ -        glusterfs_async_local_t *local = cbk_data; -        pthread_mutex_lock (&local->lock); -        { -                local->fop.readv.async_read_complete = 1; -                local->fop.readv.buf = buf; - -                pthread_cond_signal (&local->cond); -        } -        pthread_mutex_unlock (&local->lock); - -        return 0; -} - -network_status_t  -mod_glusterfs_read_async (server *srv, connection *con, chunk *glusterfs_chunk) -{ -        glusterfs_async_local_t local; -        off_t end = 0; -        int nbytes; -        int complete; -        chunkqueue *cq = NULL; -        chunk *c = NULL; -        off_t offset = glusterfs_chunk->file.start; -        size_t length = glusterfs_chunk->file.length; -        unsigned long fd = (unsigned long)glusterfs_chunk->file.name; -        network_status_t ret; - -        pthread_cond_init (&local.cond, NULL); -        pthread_mutex_init (&local.lock, NULL); -   -        //local.fd = fd; -        memset (&local, 0, sizeof (local)); - -        if (length > 0) -                end = offset + length; - -        cq = chunkqueue_init (); -        if (!cq) { -                con->http_status = 500; -                return NETWORK_STATUS_FATAL_ERROR; -        } - -        do { -                glusterfs_read_buf_t *buf; -                int i; -                if (length > 0) { -                        nbytes = end - offset; -                        if (nbytes > GLUSTERFS_CHUNK_SIZE) -                                nbytes = GLUSTERFS_CHUNK_SIZE; -                } else -                        nbytes = GLUSTERFS_CHUNK_SIZE; - -                glusterfs_read_async(fd,  -                                     nbytes, -                                     offset, -                                     mod_glusterfs_readv_async_cbk, -                                     (void *)&local); - -                pthread_mutex_lock (&local.lock); -                { -                        while (!local.fop.readv.async_read_complete) { -                                pthread_cond_wait (&local.cond, &local.lock); -                        } - -                        local.op_ret = local.fop.readv.buf->op_ret; -                        local.op_errno = local.fop.readv.buf->op_errno; - -                        local.fop.readv.async_read_complete = 0; -                        buf = local.fop.readv.buf; - -                        if ((int)length < 0) -                                complete = (local.fop.readv.buf->op_ret <= 0); -                        else { -                                local.fop.readv.read_bytes += local.fop.readv.buf->op_ret; -                                complete = ((local.fop.readv.read_bytes == length) || (local.fop.readv.buf->op_ret <= 0)); -                        } -                } -                pthread_mutex_unlock (&local.lock); - -                if (local.op_ret > 0) { -                        for (i = 0; i < buf->count; i++) { -                                buffer *nw_write_buf = chunkqueue_get_append_buffer (cq); - -                                nw_write_buf->used = nw_write_buf->size = buf->vector[i].iov_len + 1; -                                nw_write_buf->ptr = buf->vector[i].iov_base; - -                                //      buffer_copy_memory (nw_write_buf, buf->vector[i].iov_base, buf->vector[i].iov_len + 1); -                                offset += local.op_ret; -                        } -   -                        ret = network_backend_write (srv, con, con->sock, cq); -   -                        if (chunkqueue_written (cq) != local.op_ret) { -                                mod_glusterfs_chunkqueue *gf_cq; -                                glusterfs_chunk->file.start = offset; -                                if ((int)glusterfs_chunk->file.length > 0) -                                        glusterfs_chunk->file.length -= local.fop.readv.read_bytes; - -                                gf_cq = calloc (1, sizeof (*gf_cq)); -                                /* ERR_ABORT (qf_cq); */ -                                gf_cq->cq = cq; -                                gf_cq->buf = buf; -                                gf_cq->length = local.op_ret; -                                glusterfs_chunk->file.mmap.start = (char *)gf_cq; -                                return ret; -                        } -       -                        for (c = cq->first ; c; c = c->next)  -                                c->mem->ptr = NULL; - -                        chunkqueue_reset (cq); -                } - -                glusterfs_free (buf); -        } while (!complete); - -        chunkqueue_free (cq); -        glusterfs_close (fd); - -        if (local.op_ret < 0) -                con->http_status = 500; - -        return (local.op_ret < 0 ? NETWORK_STATUS_FATAL_ERROR : NETWORK_STATUS_SUCCESS); -} - -network_status_t mod_glusterfs_network_backend_write(struct server *srv, connection *con, iosocket *sock, chunkqueue *cq) -{ -        chunk *c, *prev, *first; -        int chunks_written = 0; -        int error = 0; -        network_status_t ret; - -        for (first = prev = c = cq->first; c; c = c->next, chunks_written++) { - -                if (c->type == MEM_CHUNK && c->mem->used && !c->mem->ptr) { -                        if (cq->first != c) { -                                prev->next = NULL; - -                                /* call stored network_backend_write */ -                                ret = network_backend_write (srv, con, sock, cq); - -                                prev->next = c; -                                if (ret != NETWORK_STATUS_SUCCESS) { -                                        cq->first = first; -                                        return ret; -                                } -                        }  -                        cq->first = c->next; - -                        if (c->file.fd < 0) { -                                error = HANDLER_ERROR; -                                break; -                        } - -                        if (c->file.mmap.start) { -                                chunk *tmp; -                                size_t len; -                                mod_glusterfs_chunkqueue *gf_cq = (mod_glusterfs_chunkqueue *)c->file.mmap.start; - -                                ret = network_backend_write (srv, con, sock, gf_cq->cq); - -                                if ((len = (size_t)chunkqueue_written (gf_cq->cq)) != gf_cq->length) { -                                        gf_cq->length -= len; -                                        cq->first = first; -                                        chunkqueue_remove_finished_chunks (gf_cq->cq); -                                        return ret; -                                } - -                                for (tmp = gf_cq->cq->first ; tmp; tmp = tmp->next) -                                        tmp->mem->ptr = NULL; - -                                chunkqueue_free (gf_cq->cq); -                                glusterfs_free (gf_cq->buf); -                                free (gf_cq); -                                c->file.mmap.start = NULL; -                        } -       -                        ret = mod_glusterfs_read_async (srv, con, c); //c->file.fd, c->file.start, -1);//c->file.length); -                        if (c->file.mmap.start) { -                                /* pending chunkqueue from mod_glusterfs_read_async to be written to network */ -                                cq->first = first; -                                return ret; -                        } - -                        buffer_free (c->mem); -                        c->mem = NULL; - -                        c->type = FILE_CHUNK; -                        c->offset = c->file.length = 0; -                        c->file.name = NULL; - -                        if (first == c) -                                first = c->next; - -                        if (cq->last == c) -                                cq->last = NULL; - -                        prev->next = c->next; - -                        free(c); -                }      -                prev = c; -        } - -        ret = network_backend_write (srv, con, sock, cq); - -        cq->first = first; - -        return ret; -} - -#if 0 -int chunkqueue_append_glusterfs_file (chunkqueue *cq, unsigned long fd, off_t offset, off_t len) -{ -        chunk *c = NULL; -        c = chunkqueue_get_append_tempfile (cq); -   -        if (c->file.is_temp) { -                close (c->file.fd); -                unlink (c->file.name->ptr); -        } - -        c->type = MEM_CHUNK; - -        c->mem = buffer_init (); -        c->mem->used = len + 1; -        c->mem->ptr = NULL; -        c->offset = 0; - -        /*  buffer_copy_string_buffer (c->file.name, fn); */ -        c->file.start = offset; -        c->file.length = len; -        /*  buffer_free (c->file.name); */ - -        /* identify chunk as glusterfs related */ -        c->file.mmap.start = MAP_FAILED; -        /*  c->file.mmap.length = c->file.mmap.offset = len;*/ - -        return 0; -} -#endif - -int chunkqueue_append_dummy_mem_chunk (chunkqueue *cq, off_t len) -{ -        chunk *c = NULL; -        c = chunkqueue_get_append_tempfile (cq); -   -        if (c->file.is_temp) { -                close (c->file.fd); -                unlink (c->file.name->ptr); -                c->file.is_temp = 0; -        } - -        c->type = MEM_CHUNK; - -        c->mem->used = len + 1; -        c->offset = len; -        c->mem->ptr = NULL; - -        return 0; -} - -int chunkqueue_append_glusterfs_file (chunkqueue *cq, unsigned long fd, off_t offset, off_t len) -{ -        chunk *c = NULL; -        c = chunkqueue_get_append_tempfile (cq); -   -        if (c->file.is_temp) { -                close (c->file.fd); -                unlink (c->file.name->ptr); -                c->file.is_temp = 0; -        } - -        c->type = MEM_CHUNK; - -        c->mem = buffer_init (); -        c->mem->used = len + 1; -        c->mem->ptr = NULL; -        c->offset = 0; - -        /*  buffer_copy_string_buffer (c->file.name, fn); */ -        buffer_free (c->file.name); - -        /* fd returned by libglusterfsclient is a pointer */ -        c->file.name = (buffer *)fd; -        c->file.start = offset; -        c->file.length = len; - -        //c->file.fd = fd; -        c->file.mmap.start = NULL; -        return 0; -} - -/* init the plugin data */ -INIT_FUNC(mod_glusterfs_init) { -        plugin_data *p; - -        UNUSED (srv); -        p = calloc(1, sizeof(*p)); -        /* ERR_ABORT (p); */ -        network_backend_write = NULL; -        p->ranges = http_request_range_init(); -        return p; -} - -/* detroy the plugin data */ -FREE_FUNC(mod_glusterfs_free) { -        plugin_data *p = p_d; - -        UNUSED (srv); - -        if (!p) return HANDLER_GO_ON; -   -        if (p->config_storage) { -                size_t i; -                for (i = 0; i < srv->config_context->used; i++) { -                        plugin_config *s = p->config_storage[i]; -       -                        buffer_free (s->logfile); -                        buffer_free (s->loglevel); -                        buffer_free (s->specfile); -                        buffer_free (s->prefix); -                        buffer_free (s->xattr_file_size); -                        buffer_free (s->document_root); -                        array_free (s->exclude_exts); -   -                        free (s); -                } -                free (p->config_storage); -        } -        buffer_free (p->range_buf); -        http_request_range_free (p->ranges); - -        free (p); -   -        return HANDLER_GO_ON; -} - -SETDEFAULTS_FUNC(mod_glusterfs_set_defaults) { -        plugin_data *p = p_d; -        size_t i = 0; -   -        config_values_t cv[] = { -                { "glusterfs.logfile",              NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, -     -                { "glusterfs.loglevel",             NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },          -                { "glusterfs.volume-specfile",             NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },           -                { "glusterfs.cache-timeout",              NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, -     -                { "glusterfs.exclude-extensions",   NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, -     -                /*TODO: get the prefix from config_conext and remove glusterfs.prefix from conf file */ -                { "glusterfs.prefix", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, -     -                { "glusterfs.xattr-interface-size-limit", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, - -                { "glusterfs.document-root", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, -     -                { NULL,                          NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } -        }; -   -        p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *)); -        /* ERR_ABORT (p->config_storage); */ -        p->range_buf = buffer_init (); -   -        for (i = 0; i < srv->config_context->used; i++) { -                plugin_config *s; - -                s = calloc(1, sizeof(plugin_config)); -                /* ERR_ABORT (s); */ -                s->logfile = buffer_init (); -                s->loglevel = buffer_init (); -                s->specfile = buffer_init (); -                s->exclude_exts = array_init (); -                s->prefix = buffer_init (); -                s->xattr_file_size = buffer_init (); -                s->document_root = buffer_init (); -     -                cv[0].destination = s->logfile; -                cv[1].destination = s->loglevel; -                cv[2].destination = s->specfile; -                cv[3].destination = &s->cache_timeout; -                cv[4].destination = s->exclude_exts; -                cv[5].destination = s->prefix; -                cv[6].destination = s->xattr_file_size; -                cv[7].destination = s->document_root; - -                p->config_storage[i] = s; -     -                if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) { -                        return HANDLER_FINISHED; -                } -        } -   -        return HANDLER_GO_ON; -} - -#define PATCH(x)                                \ -        p->conf.x = s->x; - -static int mod_glusterfs_patch_connection(server *srv, connection *con, plugin_data *p) { -        size_t i, j; -        plugin_config *s; - -        p->conf.logfile = NULL; -        p->conf.loglevel = NULL; -        p->conf.specfile = NULL; -        p->conf.cache_timeout = 0; -        p->conf.exclude_exts = NULL; -        p->conf.prefix = NULL; -        p->conf.xattr_file_size = NULL; -        p->conf.exclude_exts = NULL; - -        /* skip the first, the global context */ -        /* glusterfs related config can only occur inside $HTTP["url"] == "<glusterfs-prefix>" */ -        for (i = 1; i < srv->config_context->used; i++) { -                data_config *dc = (data_config *)srv->config_context->data[i]; -                s = p->config_storage[i]; - -                /* condition didn't match */ -                if (!config_check_cond(srv, con, dc)) continue; -     -                /* merge config */ -                for (j = 0; j < dc->value->used; j++) { -                        data_unset *du = dc->value->data[j]; -       -                        if (buffer_is_equal_string (du->key, CONST_STR_LEN("glusterfs.logfile"))) { -                                PATCH (logfile); -                        } else if (buffer_is_equal_string (du->key, CONST_STR_LEN("glusterfs.loglevel"))) { -                                PATCH (loglevel); -                        } else if (buffer_is_equal_string (du->key, CONST_STR_LEN ("glusterfs.volume-specfile"))) { -                                PATCH (specfile); -                        } else if (buffer_is_equal_string (du->key, CONST_STR_LEN("glusterfs.cache-timeout"))) { -                                PATCH (cache_timeout); -                        } else if (buffer_is_equal_string (du->key, CONST_STR_LEN ("glusterfs.exclude-extensions"))) { -                                PATCH (exclude_exts); -                        } else if (buffer_is_equal_string (du->key, CONST_STR_LEN ("glusterfs.prefix"))) { -                                PATCH (prefix); -                        } else if (buffer_is_equal_string (du->key, CONST_STR_LEN ("glusterfs.xattr-interface-size-limit"))) { -                                PATCH (xattr_file_size); -                        } else if (buffer_is_equal_string (du->key, CONST_STR_LEN ("glusterfs.document-root"))) { -                                PATCH (document_root); -                        } -                } -        } -        return 0; -} - -#undef PATCH - -static int http_response_parse_range(server *srv, connection *con, plugin_data *p) { -        int multipart = 0; -        char *boundary = "fkj49sn38dcn3"; -        data_string *ds; -        stat_cache_entry *sce = NULL; -        buffer *content_type = NULL; -        buffer *range = NULL; -        http_req_range *ranges, *r; -        mod_glusterfs_ctx_t *ctx = con->plugin_ctx[p->id]; -        size_t size = 0; - -        if (!ctx) { -                return -1; -        } - -        if (NULL != (ds = (data_string *)array_get_element(con->request.headers, CONST_STR_LEN("Range")))) { -                range = ds->value; -        } else { -                /* we don't have a Range header */ - -                return -1; -        } - -        if (HANDLER_ERROR == stat_cache_get_entry(srv, con, con->physical.path, &sce)) { -                SEGFAULT(); -        } - -        ctx->response_content_length = con->response.content_length = 0; - -        if (NULL != (ds = (data_string *)array_get_element(con->response.headers, CONST_STR_LEN("Content-Type")))) { -                content_type = ds->value; -        } - -        /* start the range-header parser -         * bytes=<num>  */ - -        ranges = p->ranges; -        http_request_range_reset(ranges); -        switch (http_request_range_parse(range, ranges)) { -        case PARSE_ERROR: -                return -1; /* no range valid Range Header */ -        case PARSE_SUCCESS: -                break; -        default: -                TRACE("%s", "foobar"); -                return -1; -        } - -        if (ranges->next) { -                multipart = 1; -        } - -        if (p->conf.xattr_file_size && p->conf.xattr_file_size->ptr) { -                size = atoi (p->conf.xattr_file_size->ptr); -        } - -        /* patch the '-1' */ -        for (r = ranges; r; r = r->next) { -                if (r->start == -1) { -                        /* -<end> -                         * -                         * the last <end> bytes  */ -                        r->start = sce->st.st_size - r->end; -                        r->end = sce->st.st_size - 1; -                } -                if (r->end == -1) { -                        /* <start>- -                         * all but the first <start> bytes */ - -                        r->end = sce->st.st_size - 1; -                } - -                if (r->end > sce->st.st_size - 1) { -                        /* RFC 2616 - 14.35.1 -                         * -                         * if last-byte-pos not present or > size-of-file -                         * take the size-of-file -                         * -                         *  */ -                        r->end = sce->st.st_size - 1; -                } - -                if (r->start > sce->st.st_size - 1) { -                        /* RFC 2616 - 14.35.1 -                         * -                         * if first-byte-pos > file-size, 416 -                         */ - -                        con->http_status = 416; -                        return -1; -                } - -                if (r->start > r->end) { -                        /* RFC 2616 - 14.35.1 -                         * -                         * if last-byte-pos is present, it has to be >= first-byte-pos -                         * -                         * invalid ranges have to be handle as no Range specified -                         *  */ - -                        return -1; -                } -        } - -        if (r) { -                /* we ran into an range violation */ -                return -1; -        } - -        if (multipart) { -                buffer *b; -                for (r = ranges; r; r = r->next) { -                        /* write boundary-header */ - -                        b = chunkqueue_get_append_buffer(con->send); - -                        buffer_copy_string(b, "\r\n--"); -                        buffer_append_string(b, boundary); - -                        /* write Content-Range */ -                        buffer_append_string(b, "\r\nContent-Range: bytes "); -                        buffer_append_off_t(b, r->start); -                        buffer_append_string(b, "-"); -                        buffer_append_off_t(b, r->end); -                        buffer_append_string(b, "/"); -                        buffer_append_off_t(b, sce->st.st_size); - -                        buffer_append_string(b, "\r\nContent-Type: "); -                        buffer_append_string_buffer(b, content_type); - -                        /* write END-OF-HEADER */ -                        buffer_append_string(b, "\r\n\r\n"); - -                        con->response.content_length += b->used - 1; -                        ctx->response_content_length += b->used - 1; -                        con->send->bytes_in += b->used - 1; - -                        if ((size_t)sce->st.st_size > size) { -                                chunkqueue_append_glusterfs_file(con->send_raw, ctx->fd, r->start, r->end - r->start + 1); -                                con->send_raw->bytes_in += (r->end - r->start + 1); -                                chunkqueue_append_dummy_mem_chunk (con->send, r->end - r->start + 1); -                        } else { -                                chunkqueue_append_mem (con->send, ((char *)ctx->buf) + r->start, r->end - r->start + 1);  -                                free (ctx->buf); -                                ctx->buf = NULL; -                        } -                 -                        con->response.content_length += r->end - r->start + 1; -                        ctx->response_content_length += r->end - r->start + 1; -                        con->send->bytes_in += r->end - r->start + 1; -                } - -                /* add boundary end */ -                b = chunkqueue_get_append_buffer(con->send); - -                buffer_copy_string_len(b, "\r\n--", 4); -                buffer_append_string(b, boundary); -                buffer_append_string_len(b, "--\r\n", 4); - -                con->response.content_length += b->used - 1; -                ctx->response_content_length += b->used - 1; -                con->send->bytes_in += b->used - 1; - -                /* set header-fields */ - -                buffer_copy_string(p->range_buf, "multipart/byteranges; boundary="); -                buffer_append_string(p->range_buf, boundary); - -                /* overwrite content-type */ -                response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(p->range_buf)); - -        } else { -                r = ranges; - -                chunkqueue_append_glusterfs_file(con->send_raw, ctx->fd, r->start, r->end - r->start + 1); -                con->send_raw->bytes_in += (r->end - r->start + 1); -                chunkqueue_append_dummy_mem_chunk (con->send, r->end - r->start + 1); -                con->response.content_length += r->end - r->start + 1; -                ctx->response_content_length += r->end - r->start + 1; -                con->send->bytes_in += r->end - r->start + 1; - -                buffer_copy_string(p->range_buf, "bytes "); -                buffer_append_off_t(p->range_buf, r->start); -                buffer_append_string(p->range_buf, "-"); -                buffer_append_off_t(p->range_buf, r->end); -                buffer_append_string(p->range_buf, "/"); -                buffer_append_off_t(p->range_buf, sce->st.st_size); - -                response_header_insert(srv, con, CONST_STR_LEN("Content-Range"), CONST_BUF_LEN(p->range_buf)); -        } - -        /* ok, the file is set-up */ -        return 0; -} - -PHYSICALPATH_FUNC(mod_glusterfs_handle_physical) { -        plugin_data *p = p_d; -        stat_cache_entry *sce; -        size_t size = 0; -        handler_t ret = 0; -        mod_glusterfs_ctx_t *plugin_ctx = NULL; - -        if (con->http_status != 0) return HANDLER_GO_ON; -        if (con->uri.path->used == 0) return HANDLER_GO_ON; -        if (con->physical.path->used == 0) return HANDLER_GO_ON; - -        if (con->mode != DIRECT) return HANDLER_GO_ON; - -        /* -          network_backend_write = srv->network_backend_write; -          srv->network_backend_write = mod_glusterfs_network_backend_write; -        */ - -        switch (con->request.http_method) { -        case HTTP_METHOD_GET: -        case HTTP_METHOD_POST: -        case HTTP_METHOD_HEAD: -                break; - -        default: -                return HANDLER_GO_ON; -        } - -        mod_glusterfs_patch_connection(srv, con, p); - -        if (!p->conf.prefix || !p->conf.prefix->ptr) { -                return HANDLER_GO_ON; -        } - -        if (!p->conf.document_root || p->conf.document_root->used == 0) { -                log_error_write(srv, __FILE__, __LINE__, "s", "glusterfs.document-root is not specified"); -                con->http_status = 500; -                return HANDLER_FINISHED; -        } - -        if (p->conf.handle <= 0) { -                glusterfs_init_ctx_t ctx; - -                if (!p->conf.specfile || p->conf.specfile->used == 0) { -                        return HANDLER_GO_ON; -                } -                memset (&ctx, 0, sizeof (ctx)); - -                ctx.specfile = p->conf.specfile->ptr; -                ctx.logfile = p->conf.logfile->ptr; -                ctx.loglevel = p->conf.loglevel->ptr; -                ctx.lookup_timeout = ctx.stat_timeout = p->conf.cache_timeout; - -                p->conf.handle = (unsigned long)glusterfs_init (&ctx); - -                if (p->conf.handle <= 0) { -                        con->http_status = 500; -                        log_error_write(srv, __FILE__, __LINE__,  "sbs",  "glusterfs initialization failed, please check your configuration. Glusterfs logfile ", p->conf.logfile, "might contain details"); -                        return HANDLER_FINISHED; -                } -        } - -        size = 0; -        if (p->conf.xattr_file_size && p->conf.xattr_file_size->ptr)  -                size = atoi (p->conf.xattr_file_size->ptr); - -        if (!con->plugin_ctx[p->id]) { -                buffer *tmp_buf = buffer_init_buffer (con->physical.basedir); - -                plugin_ctx = calloc (1, sizeof (*plugin_ctx)); -                /* ERR_ABORT (plugin_ctx); */ -                con->plugin_ctx[p->id] = plugin_ctx; -     -                buffer_append_string_buffer (tmp_buf, p->conf.prefix); -                buffer_path_simplify (tmp_buf, tmp_buf); - -                plugin_ctx->prefix = tmp_buf->used - 1; -                if (tmp_buf->ptr[plugin_ctx->prefix - 1] == '/') -                        plugin_ctx->prefix--; - -                buffer_free (tmp_buf); -        } else  -                /*FIXME: error!! error!! */ -                plugin_ctx = con->plugin_ctx[p->id]; - - -        if (size)  -        { -                plugin_ctx->buf = malloc (size); -                /* ERR_ABORT (plugin_ctx->buf); */ -        } - -        plugin_ctx->glusterfs_path = buffer_init (); -        buffer_copy_string_buffer (plugin_ctx->glusterfs_path, p->conf.document_root); -        buffer_append_string (plugin_ctx->glusterfs_path, "/"); -        buffer_append_string (plugin_ctx->glusterfs_path, con->physical.path->ptr + plugin_ctx->prefix); -        buffer_path_simplify (plugin_ctx->glusterfs_path, plugin_ctx->glusterfs_path); - -        ret = glusterfs_stat_cache_get_entry_async (srv, con, p, plugin_ctx->glusterfs_path, con->physical.path, plugin_ctx->buf, size, &sce); - -        if (ret == HANDLER_ERROR) { -                free (plugin_ctx->buf); -                plugin_ctx->buf = NULL; - -                buffer_free (plugin_ctx->glusterfs_path); -                plugin_ctx->glusterfs_path = NULL; - -                free (plugin_ctx); -                con->plugin_ctx[p->id] = NULL; - -                con->http_status = 500; -                ret = HANDLER_FINISHED; -        } - -        return ret; -} - -URIHANDLER_FUNC(mod_glusterfs_subrequest) { -        plugin_data *p = p_d; -        stat_cache_entry *sce = NULL; -        int s_len; -        unsigned long fd; -        char allow_caching = 1; -        size_t size = 0; -        mod_glusterfs_ctx_t *ctx = con->plugin_ctx[p->id]; - -        /* someone else has done a decision for us */ -        if (con->http_status != 0) return HANDLER_GO_ON; -        if (con->uri.path->used == 0) return HANDLER_GO_ON; -        if (con->physical.path->used == 0) return HANDLER_GO_ON; -   -        /* someone else has handled this request */ -        if (con->mode != DIRECT) return HANDLER_GO_ON; -   -        /* we only handle GET, POST and HEAD */ -        switch(con->request.http_method) { -        case HTTP_METHOD_GET: -        case HTTP_METHOD_POST: -        case HTTP_METHOD_HEAD: -                break; -        default: -                return HANDLER_GO_ON; -        } -   -        mod_glusterfs_patch_connection(srv, con, p); -   -        if (!p->conf.prefix || !p->conf.prefix->ptr) -                return HANDLER_GO_ON; - -        if (!ctx) { -                con->http_status = 500; -                return HANDLER_FINISHED; -        } - -        s_len = con->uri.path->used - 1; -        /* ignore certain extensions */ -        /* -          for (k = 0; k < p->conf.exclude_exts->used; k++) { -          data_string *ds; -          ds = (data_string *)p->conf.exclude_exts->data[k]; -           -          if (ds->value->used == 0) continue; -     -          if (!strncmp (ds->value->ptr, con->uri.path->ptr, strlen (ds->value->ptr))) -          break; -          } -   -          if (k == p->conf.exclude_exts->used) { -          return HANDLER_GO_ON; -          } -        */ - -        if (con->conf.log_request_handling) { -                log_error_write(srv, __FILE__, __LINE__,  "s",  "-- serving file from glusterfs"); -        } - -        if (HANDLER_ERROR == stat_cache_get_entry(srv, con, con->physical.path, &sce)) { -                con->http_status = 403; - -                /* this might happen if the sce is removed from stat-cache after a successful glusterfs_lookup */ -                if (ctx) { -                        if (ctx->buf) { -                                free (ctx->buf); -                                ctx->buf = NULL; -                        } - -                        if (ctx->glusterfs_path) { -                                buffer_free (ctx->glusterfs_path); -                                ctx->glusterfs_path = NULL; -                        }                -                        free (ctx); -                        con->plugin_ctx[p->id] = NULL; -                } - -                log_error_write(srv, __FILE__, __LINE__, "sbsb", -                                "not a regular file:", con->uri.path, -                                "->", con->physical.path); -     -                return HANDLER_FINISHED; -        } - -        if (con->uri.path->ptr[s_len] == '/' || !S_ISREG(sce->st.st_mode)) { -                if (ctx) { -                        if (ctx->glusterfs_path) { -                                buffer_free (ctx->glusterfs_path); -                                ctx->glusterfs_path = NULL; -                        } - -                        free (ctx); -                        con->plugin_ctx[p->id] = NULL; -                } - -                return HANDLER_FINISHED; -        } - -        if (p->conf.xattr_file_size && p->conf.xattr_file_size->ptr) -                size = atoi (p->conf.xattr_file_size->ptr); - -        if ((size_t)sce->st.st_size > size) { -     -                fd = glusterfs_open ((libglusterfs_handle_t ) ((unsigned long)p->conf.handle), ctx->glusterfs_path->ptr, O_RDONLY, 0); -     -                if (!fd) { -                        if (ctx) { -                                if (ctx->glusterfs_path) { -                                        buffer_free (ctx->glusterfs_path); -                                        ctx->glusterfs_path = NULL; -                                } - -                                free (ctx); -                                con->plugin_ctx[p->id] = NULL; -                        } - -                        con->http_status = 403; -                        return HANDLER_FINISHED; -                } -                ctx->fd = fd; -        } - -        /* we only handline regular files */ -#ifdef HAVE_LSTAT -        if ((sce->is_symlink == 1) && !con->conf.follow_symlink) { -                con->http_status = 403; -           -                if (con->conf.log_request_handling) { -                        log_error_write(srv, __FILE__, __LINE__,  "s",  "-- access denied due symlink restriction"); -                        log_error_write(srv, __FILE__, __LINE__,  "sb", "Path         :", con->physical.path); -                } -     -                buffer_reset(con->physical.path); -                if (ctx) { -                        if (ctx->glusterfs_path) { -                                buffer_free (ctx->glusterfs_path); -                                ctx->glusterfs_path = NULL; -                        } - -                        free (ctx); -                        con->plugin_ctx[p->id] = NULL; -                } - -                return HANDLER_FINISHED; -        } -#endif -        if (!S_ISREG(sce->st.st_mode)) { -                con->http_status = 404; -     -                if (con->conf.log_file_not_found) { -                        log_error_write(srv, __FILE__, __LINE__, "sbsb", -                                        "not a regular file:", con->uri.path, -                                        "->", sce->name); -                } -     -                if (ctx) { -                        if (ctx->glusterfs_path) { -                                buffer_free (ctx->glusterfs_path); -                                ctx->glusterfs_path = NULL; -                        } - -                        free (ctx); -                        con->plugin_ctx[p->id] = NULL; -                } - -                return HANDLER_FINISHED; -        } - -        /* mod_compress might set several data directly, don't overwrite them */ - -        /* set response content-type, if not set already */ -   -        if (NULL == array_get_element(con->response.headers, CONST_STR_LEN("Content-Type"))) { -                if (buffer_is_empty(sce->content_type)) { -                        /* we are setting application/octet-stream, but also announce that -                         * this header field might change in the seconds few requests  -                         * -                         * This should fix the aggressive caching of FF and the script download -                         * seen by the first installations -                         */ -                        response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_STR_LEN("application/octet-stream")); -       -                        allow_caching = 0; -                } else { -                        response_header_overwrite(srv, con, CONST_STR_LEN("Content-Type"), CONST_BUF_LEN(sce->content_type)); -                } -        } -   -        if (con->conf.range_requests) { -                response_header_overwrite(srv, con, CONST_STR_LEN("Accept-Ranges"), CONST_STR_LEN("bytes")); -        } - -        /* TODO: Allow Cachable requests */      -#if 0 -        if (allow_caching) { -                if (p->conf.etags_used && con->etag_flags != 0 && !buffer_is_empty(sce->etag)) { -                        if (NULL == array_get_element(con->response.headers, "ETag")) { -                                /* generate e-tag */ -                                etag_mutate(con->physical.etag, sce->etag); -         -                                response_header_overwrite(srv, con, CONST_STR_LEN("ETag"), CONST_BUF_LEN(con->physical.etag)); -                        } -                } -     -                /* prepare header */ -                if (NULL == (ds = (data_string *)array_get_element(con->response.headers, "Last-Modified"))) { -                        mtime = strftime_cache_get(srv, sce->st.st_mtime); -                        response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime)); -                } else { -                        mtime = ds->value; -                } -     -                if (HANDLER_FINISHED == http_response_handle_cachable(srv, con, mtime)) { -                        if (ctx) { -                                if (ctx->glusterfs_path) { -                                        buffer_free (ctx->glusterfs_path); -                                        ctx->glusterfs_path = NULL; -                                } - -                                free (ctx); -                                con->plugin_ctx[p->id] = NULL; -                        } - -                        return HANDLER_FINISHED; -                } -        } -#endif  -   -        /*TODO: Read about etags */ -        if (NULL != array_get_element(con->request.headers, CONST_STR_LEN("Range")) && con->conf.range_requests) { -                int do_range_request = 1; -                data_string *ds = NULL; -                buffer *mtime = NULL; -                /* check if we have a conditional GET */ -     -                /* prepare header */ -                if (NULL == (ds = (data_string *)array_get_element(con->response.headers, CONST_STR_LEN("Last-Modified")))) { -                        mtime = strftime_cache_get(srv, sce->st.st_mtime); -                        response_header_overwrite(srv, con, CONST_STR_LEN("Last-Modified"), CONST_BUF_LEN(mtime)); -                } else { -                        mtime = ds->value; -                } - -                if (NULL != (ds = (data_string *)array_get_element(con->request.headers, CONST_STR_LEN("If-Range")))) { -                        /* if the value is the same as our ETag, we do a Range-request, -                         * otherwise a full 200 */ -             -                        if (ds->value->ptr[0] == '"') { -                                /** -                                 * client wants a ETag -                                 */ -                                if (!con->physical.etag) { -                                        do_range_request = 0; -                                } else if (!buffer_is_equal(ds->value, con->physical.etag)) { -                                        do_range_request = 0; -                                } -                        } else if (!mtime) { -                                /** -                                 * we don't have a Last-Modified and can match the If-Range:  -                                 * -                                 * sending all -                                 */ -                                do_range_request = 0; -                        } else if (!buffer_is_equal(ds->value, mtime)) { -                                do_range_request = 0; -                        } -                } -     -                if (do_range_request) { -                        /* content prepared, I'm done */ -                        con->send->is_closed = 1;  -             -                        if (0 == http_response_parse_range(srv, con, p)) { -                                con->http_status = 206; -                        } -                        if (ctx) { -                                if (ctx->glusterfs_path) { -                                        buffer_free (ctx->glusterfs_path); -                                        ctx->glusterfs_path = NULL; -                                } -                                free (ctx); -                                con->plugin_ctx[p->id] = NULL; -                        } - -                        return HANDLER_FINISHED; -                } -        } -   -        /* if we are still here, prepare body */ - -        /* we add it here for all requests -         * the HEAD request will drop it afterwards again -         */ - -        if (p->conf.xattr_file_size && p->conf.xattr_file_size->ptr) -                size = atoi (p->conf.xattr_file_size->ptr); - -        if (size < (size_t)sce->st.st_size) { -                chunkqueue_append_glusterfs_file (con->send_raw, fd, 0, sce->st.st_size); -                con->send_raw->bytes_in += sce->st.st_size; -                chunkqueue_append_dummy_mem_chunk (con->send, sce->st.st_size); -        } else { -                if (!ctx->buf) { -                        con->http_status = 404; -                        return HANDLER_ERROR; -                } -                chunkqueue_append_glusterfs_mem (con->send, ctx->buf, sce->st.st_size); -                ctx->buf = NULL; -        } -        ctx->response_content_length = con->response.content_length = sce->st.st_size; -   -        con->send->is_closed = 1; -        con->send->bytes_in = sce->st.st_size; - -        return HANDLER_FINISHED; -} - -/* this function is called at dlopen() time and inits the callbacks */ -CONNECTION_FUNC(mod_glusterfs_connection_reset)  -{ -        (void) p_d; -        (void) con; -        if (!network_backend_write) -                network_backend_write = srv->network_backend_write; - -        srv->network_backend_write = mod_glusterfs_network_backend_write; - -        return HANDLER_GO_ON; -} - -URIHANDLER_FUNC(mod_glusterfs_response_done) { -        plugin_data *p = p_d; -        UNUSED (srv); -        mod_glusterfs_ctx_t *ctx = con->plugin_ctx[p->id]; -         -        con->plugin_ctx[p->id] = NULL; -        if (ctx->glusterfs_path) { -                free (ctx->glusterfs_path); -        } - -        free (ctx); -        return HANDLER_GO_ON; -} - -int mod_glusterfs_plugin_init(plugin *p) { -        p->version     = LIGHTTPD_VERSION_ID; -        p->name        = buffer_init_string("glusterfs"); -        p->init        = mod_glusterfs_init; -        p->handle_physical = mod_glusterfs_handle_physical; -        p->handle_start_backend = mod_glusterfs_subrequest; -        p->handle_response_done = mod_glusterfs_response_done; -        p->set_defaults  = mod_glusterfs_set_defaults; -        p->connection_reset = mod_glusterfs_connection_reset; -        p->cleanup     = mod_glusterfs_free; -   -        p->data        = NULL; -   -        return 0; -} diff --git a/mod_glusterfs/lighttpd/1.5/mod_glusterfs.h b/mod_glusterfs/lighttpd/1.5/mod_glusterfs.h deleted file mode 100644 index 5f9bb2c5bf0..00000000000 --- a/mod_glusterfs/lighttpd/1.5/mod_glusterfs.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -   Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -   This file is part of GlusterFS. - -   GlusterFS is free software; you can redistribute it and/or modify -   it under the terms of the GNU General Public License as published -   by the Free Software Foundation; either version 3 of the License, -   or (at your option) any later version. - -   GlusterFS is distributed in the hope that it will be useful, but -   WITHOUT ANY WARRANTY; without even the implied warranty of -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -   General Public License for more details. - -   You should have received a copy of the GNU General Public License -   along with this program.  If not, see -   <http://www.gnu.org/licenses/>. -*/ - -#ifndef _MOD_GLUSTERFS_FILE_CACHE_H_ -#define _MOD_GLUSTERFS_FILE_CACHE_H_ - -#include "stat_cache.h" -#include <libglusterfsclient.h> -#include "base.h" - -handler_t glusterfs_stat_cache_get_entry(server *srv, connection *con, libglusterfs_handle_t handle, buffer *glusterfs_path, buffer *name, void *buf, size_t size, stat_cache_entry **fce); - -#endif diff --git a/mod_glusterfs/lighttpd/Makefile.am b/mod_glusterfs/lighttpd/Makefile.am deleted file mode 100644 index c934412b3dc..00000000000 --- a/mod_glusterfs/lighttpd/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = 1.4 1.5 - -CLEANFILES =  diff --git a/xlators/protocol/legacy/Makefile.am b/xlators/protocol/legacy/Makefile.am deleted file mode 100644 index 9914863021c..00000000000 --- a/xlators/protocol/legacy/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = lib transport client server - -CLEANFILES = diff --git a/xlators/protocol/legacy/client/Makefile.am b/xlators/protocol/legacy/client/Makefile.am deleted file mode 100644 index d471a3f9243..00000000000 --- a/xlators/protocol/legacy/client/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = src - -CLEANFILES =  diff --git a/xlators/protocol/legacy/client/src/Makefile.am b/xlators/protocol/legacy/client/src/Makefile.am deleted file mode 100644 index 2ae64ebd0fd..00000000000 --- a/xlators/protocol/legacy/client/src/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ - -xlator_LTLIBRARIES = client-old.la -xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/legacy/protocol - -client_old_la_LDFLAGS = -module -avoidversion - -client_old_la_SOURCES = client-protocol.c saved-frames.c - -client_old_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ -	$(top_builddir)/xlators/protocol/legacy/lib/src/libgfproto.la - -noinst_HEADERS = client-protocol.h saved-frames.h client-mem-types.h - -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \ -	-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS)  \ -	-I$(top_srcdir)/xlators/protocol/legacy/lib/src - -CLEANFILES =  - -install-data-hook: -	ln -sf client-old.so $(DESTDIR)$(xlatordir)/client.so diff --git a/xlators/protocol/legacy/client/src/client-mem-types.h b/xlators/protocol/legacy/client/src/client-mem-types.h deleted file mode 100644 index d2e2878c3db..00000000000 --- a/xlators/protocol/legacy/client/src/client-mem-types.h +++ /dev/null @@ -1,43 +0,0 @@ - -/* -   Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -   This file is part of GlusterFS. - -   GlusterFS is free software; you can redistribute it and/or modify -   it under the terms of the GNU General Public License as published -   by the Free Software Foundation; either version 3 of the License, -   or (at your option) any later version. - -   GlusterFS is distributed in the hope that it will be useful, but -   WITHOUT ANY WARRANTY; without even the implied warranty of -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -   General Public License for more details. - -   You should have received a copy of the GNU General Public License -   along with this program.  If not, see -   <http://www.gnu.org/licenses/>. -*/ - - -#ifndef __CLIENT_MEM_TYPES_H__ -#define __CLIENT_MEM_TYPES_H__ - -#include "mem-types.h" - -enum gf_client_mem_types_ { -        gf_client_mt_dir_entry_t = gf_common_mt_end + 1, -        gf_client_mt_volfile_ctx, -        gf_client_mt_client_state_t, -        gf_client_mt_client_conf_t, -        gf_client_mt_locker, -        gf_client_mt_lock_table, -        gf_client_mt_char, -        gf_client_mt_client_connection_t, -        gf_client_mt_client_fd_ctx_t, -        gf_client_mt_client_local_t, -        gf_client_mt_saved_frames, -        gf_client_mt_saved_frame, -        gf_client_mt_end -}; -#endif - diff --git a/xlators/protocol/legacy/client/src/client-protocol.c b/xlators/protocol/legacy/client/src/client-protocol.c deleted file mode 100644 index 804b93a5c14..00000000000 --- a/xlators/protocol/legacy/client/src/client-protocol.c +++ /dev/null @@ -1,6683 +0,0 @@ -/* -  Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif -#include <inttypes.h> - - -#include "glusterfs.h" -#include "client-protocol.h" -#include "compat.h" -#include "dict.h" -#include "protocol.h" -#include "transport.h" -#include "xlator.h" -#include "logging.h" -#include "timer.h" -#include "defaults.h" -#include "compat.h" -#include "compat-errno.h" -#include "statedump.h" -#include "client-mem-types.h" - -#include <sys/resource.h> -#include <inttypes.h> - -/* for default_*_cbk functions */ -#include "defaults.c" -#include "saved-frames.h" -#include "common-utils.h" - -int protocol_client_cleanup (transport_t *trans); -int protocol_client_interpret (xlator_t *this, transport_t *trans, -                               char *hdr_p, size_t hdrlen, -                               struct iobuf *iobuf); -int -protocol_client_xfer (call_frame_t *frame, xlator_t *this, transport_t *trans, -                      int type, int op, -                      gf_hdr_common_t *hdr, size_t hdrlen, -                      struct iovec *vector, int count, -                      struct iobref *iobref); - -int -protocol_client_post_handshake (call_frame_t *frame, xlator_t *this); - -static gf_op_t gf_fops[GF_PROTO_FOP_MAXVALUE]; -static gf_op_t gf_mops[GF_MOP_MAXVALUE]; -static gf_op_t gf_cbks[GF_CBK_MAXVALUE]; - - -transport_t * -client_channel (xlator_t *this, int id) -{ -        transport_t              *trans = NULL; -        client_conf_t            *conf = NULL; -        int                       i = 0; -        struct client_connection *conn = NULL; - -        conf = this->private; - -        trans = conf->transport[id]; -        conn = trans->xl_private; - -        if (conn->connected == 1) -                goto ret; - -        for (i = 0; i < CHANNEL_MAX; i++) { -                trans = conf->transport[i]; -                conn = trans->xl_private; -                if (conn->connected == 1) -                        break; -        } - -ret: -        return trans; -} - - -client_fd_ctx_t * -this_fd_del_ctx (fd_t *file, xlator_t *this) -{ -        int         dict_ret = -1; -        uint64_t    ctxaddr  = 0; - -        GF_VALIDATE_OR_GOTO ("client", this, out); -        GF_VALIDATE_OR_GOTO (this->name, file, out); - -        dict_ret = fd_ctx_del (file, this, &ctxaddr); - -        if (dict_ret < 0) { -                ctxaddr = 0; -        } - -out: -        return (client_fd_ctx_t *)(unsigned long)ctxaddr; -} - - -client_fd_ctx_t * -this_fd_get_ctx (fd_t *file, xlator_t *this) -{ -        int         dict_ret = -1; -        uint64_t    ctxaddr = 0; - -        GF_VALIDATE_OR_GOTO ("client", this, out); -        GF_VALIDATE_OR_GOTO (this->name, file, out); - -        dict_ret = fd_ctx_get (file, this, &ctxaddr); - -        if (dict_ret < 0) { -                ctxaddr = 0; -        } - -out: -        return (client_fd_ctx_t *)(unsigned long)ctxaddr; -} - - -static void -this_fd_set_ctx (fd_t *file, xlator_t *this, loc_t *loc, client_fd_ctx_t *ctx) -{ -        uint64_t oldaddr = 0; -        int32_t  ret = -1; - -        GF_VALIDATE_OR_GOTO ("client", this, out); -        GF_VALIDATE_OR_GOTO (this->name, file, out); - -        ret = fd_ctx_get (file, this, &oldaddr); -        if (ret >= 0) { -                if (loc) -                        gf_log (this->name, GF_LOG_DEBUG, -                                "%s (%"PRId64"): trying duplicate remote fd set. ", -                                loc->path, loc->inode->ino); -                else -                        gf_log (this->name, GF_LOG_DEBUG, -                                "%p: trying duplicate remote fd set. ", -                                file); -        } - -        ret = fd_ctx_set (file, this, (uint64_t)(unsigned long)ctx); -        if (ret < 0) { -                if (loc) -                        gf_log (this->name, GF_LOG_DEBUG, -                                "%s (%"PRId64"): failed to set remote fd", -                                loc->path, loc->inode->ino); -                else -                        gf_log (this->name, GF_LOG_DEBUG, -                                "%p: failed to set remote fd", -                                file); -        } -out: -        return; -} - - -static int -client_local_wipe (client_local_t *local) -{ -        if (local) { -                loc_wipe (&local->loc); - -                if (local->fd) -                        fd_unref (local->fd); - -                mem_put (local); -        } - -        return 0; -} - -/* - * lookup_frame - lookup call frame corresponding to a given callid - * @trans: transport object - * @callid: call id of the frame - * - * not for external reference - */ - -static call_frame_t * -lookup_frame (transport_t *trans, int32_t op, int8_t type, int64_t callid) -{ -        client_connection_t *conn = NULL; -        call_frame_t        *frame = NULL; - -        conn = trans->xl_private; - -        pthread_mutex_lock (&conn->lock); -        { -                frame = saved_frames_get (conn->saved_frames, -                                          op, type, callid); -        } -        pthread_mutex_unlock (&conn->lock); - -        return frame; -} - - -static void -call_bail (void *data) -{ -        client_connection_t  *conn = NULL; -        struct timeval        current; -        transport_t          *trans = NULL; -        struct list_head      list; -        struct saved_frame   *saved_frame = NULL; -        struct saved_frame   *trav = NULL; -        struct saved_frame   *tmp = NULL; -        call_frame_t         *frame = NULL; -        gf_hdr_common_t       hdr = {0, }; -        char                **gf_op_list = NULL; -        gf_op_t              *gf_ops = NULL; -        struct tm             frame_sent_tm; -        char                  frame_sent[32] = {0,}; -        struct timeval        timeout = {0,}; -        gf_timer_cbk_t        timer_cbk = NULL; - -        GF_VALIDATE_OR_GOTO ("client", data, out); -        trans = data; - -        conn = trans->xl_private; - -        gettimeofday (¤t, NULL); -        INIT_LIST_HEAD (&list); - -        pthread_mutex_lock (&conn->lock); -        { -                /* Chaining to get call-always functionality from -                   call-once timer */ -                if (conn->timer) { -                        timer_cbk = conn->timer->callbk; - -                        timeout.tv_sec = 10; -                        timeout.tv_usec = 0; - -                        gf_timer_call_cancel (trans->xl->ctx, conn->timer); -                        conn->timer = gf_timer_call_after (trans->xl->ctx, -                                                           timeout, -                                                           timer_cbk, -                                                           trans); -                        if (conn->timer == NULL) { -                                gf_log (trans->xl->name, GF_LOG_DEBUG, -                                        "Cannot create bailout timer"); -                        } -                } - -                do { -                        saved_frame = -                                saved_frames_get_timedout (conn->saved_frames, -                                                           GF_OP_TYPE_MOP_REQUEST, -                                                           conn->frame_timeout, -                                                           ¤t); -                        if (saved_frame) -                                list_add (&saved_frame->list, &list); - -                } while (saved_frame); - -                do { -                        saved_frame = -                                saved_frames_get_timedout (conn->saved_frames, -                                                           GF_OP_TYPE_FOP_REQUEST, -                                                           conn->frame_timeout, -                                                           ¤t); -                        if (saved_frame) -                                list_add (&saved_frame->list, &list); -                } while (saved_frame); - -                do { -                        saved_frame = -                                saved_frames_get_timedout (conn->saved_frames, -                                                           GF_OP_TYPE_CBK_REQUEST, -                                                           conn->frame_timeout, -                                                           ¤t); -                        if (saved_frame) -                                list_add (&saved_frame->list, &list); -                } while (saved_frame); -        } -        pthread_mutex_unlock (&conn->lock); - -        hdr.rsp.op_ret   = hton32 (-1); -        hdr.rsp.op_errno = hton32 (ENOTCONN); - -        list_for_each_entry_safe (trav, tmp, &list, list) { -                switch (trav->type) -                { -                case GF_OP_TYPE_FOP_REQUEST: -                        gf_ops = gf_fops; -                        gf_op_list = gf_fop_list; -                        break; -                case GF_OP_TYPE_MOP_REQUEST: -                        gf_ops = gf_mops; -                        gf_op_list = gf_mop_list; -                        break; -                case GF_OP_TYPE_CBK_REQUEST: -                        gf_ops = gf_cbks; -                        gf_op_list = gf_cbk_list; -                        break; -                default: -                        goto out; -                } - -                localtime_r (&trav->saved_at.tv_sec, &frame_sent_tm); -                strftime (frame_sent, 32, "%Y-%m-%d %H:%M:%S", &frame_sent_tm); - -                gf_log (trans->xl->name, GF_LOG_ERROR, -                        "bailing out frame %s(%d) " -                        "frame sent = %s. frame-timeout = %d", -                        gf_op_list[trav->op], trav->op, -                        frame_sent, conn->frame_timeout); - -                hdr.type = hton32 (trav->type); -                hdr.op   = hton32 (trav->op); - -                frame = trav->frame; - -                gf_ops[trav->op] (frame, &hdr, sizeof (hdr), NULL); - -                list_del_init (&trav->list); -                GF_FREE (trav); -        } -out: -        return; -} - - -void -save_frame (transport_t *trans, call_frame_t *frame, -            int32_t op, int8_t type, uint64_t callid) -{ -        client_connection_t *conn = NULL; -        struct timeval       timeout = {0, }; - - -        conn = trans->xl_private; - -        saved_frames_put (conn->saved_frames, frame, op, type, callid); - -        if (conn->timer == NULL && conn->frame_timeout) { -                timeout.tv_sec  = 10; -                timeout.tv_usec = 0; -                conn->timer = gf_timer_call_after (trans->xl->ctx, timeout, -                                                   call_bail, (void *) trans); -        } -} - - - -void -client_ping_timer_expired (void *data) -{ -        xlator_t            *this = NULL; -        transport_t         *trans = NULL; -        client_conf_t       *conf = NULL; -        client_connection_t *conn = NULL; -        int                  disconnect = 0; -        int                  transport_activity = 0; -        struct timeval       timeout = {0, }; -        struct timeval       current = {0, }; - -        trans = data; -        this  = trans->xl; -        conf  = this->private; -        conn  = trans->xl_private; - -        pthread_mutex_lock (&conn->lock); -        { -                if (conn->ping_timer) -                        gf_timer_call_cancel (trans->xl->ctx, -                                              conn->ping_timer); -                gettimeofday (¤t, NULL); - -                pthread_mutex_lock (&conf->mutex); -                { -                        if (((current.tv_sec - conf->last_received.tv_sec) < -                             conn->ping_timeout) -                            || ((current.tv_sec - conf->last_sent.tv_sec) < -                                conn->ping_timeout)) { -                                transport_activity = 1; -                        } -                } -                pthread_mutex_unlock (&conf->mutex); - -                if (transport_activity) { -                        gf_log (this->name, GF_LOG_TRACE, -                                "ping timer expired but transport activity " -                                "detected - not bailing transport"); -                        conn->transport_activity = 0; -                        timeout.tv_sec = conn->ping_timeout; -                        timeout.tv_usec = 0; - -                        conn->ping_timer = -                                gf_timer_call_after (trans->xl->ctx, timeout, -                                                     client_ping_timer_expired, -                                                     (void *) trans); -                        if (conn->ping_timer == NULL) -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "unable to setup timer"); - -                } else { -                        conn->ping_started = 0; -                        conn->ping_timer = NULL; -                        disconnect = 1; -                } -        } -        pthread_mutex_unlock (&conn->lock); -        if (disconnect) { -                gf_log (this->name, GF_LOG_ERROR, -                        "Server %s has not responded in the last %d " -                        "seconds, disconnecting.", -                        conf->transport[0]->peerinfo.identifier, -                        conn->ping_timeout); - -                transport_disconnect (conf->transport[0]); -                transport_disconnect (conf->transport[1]); -        } -} - - -void -client_start_ping (void *data) -{ -        xlator_t            *this = NULL; -        transport_t         *trans = NULL; -        client_conf_t       *conf = NULL; -        client_connection_t *conn = NULL; -        int32_t              ret = -1; -        gf_hdr_common_t     *hdr = NULL; -        struct timeval       timeout = {0, }; -        call_frame_t        *dummy_frame = NULL; -        size_t               hdrlen = -1; -        gf_mop_ping_req_t   *req = NULL; -        int                  frame_count = 0; - - -        trans = data; -        this  = trans->xl; -        conf  = this->private; -        conn  = trans->xl_private; - -        if (!conn->ping_timeout) -                return; - -        pthread_mutex_lock (&conn->lock); -        { -                if (conn->ping_timer) -                        gf_timer_call_cancel (trans->xl->ctx, conn->ping_timer); - -                conn->ping_timer = NULL; -                conn->ping_started = 0; - -                if (conn->saved_frames) -                        /* treat the case where conn->saved_frames is NULL -                           as no pending frames */ -                        frame_count = conn->saved_frames->count; - -                if ((frame_count == 0) || !conn->connected) { -                        /* using goto looked ugly here, -                         * hence getting out this way */ -                        /* unlock */ -                        pthread_mutex_unlock (&conn->lock); -                        return; -                } - -                if (frame_count < 0) { -                        gf_log (this->name, GF_LOG_TRACE, -                                "saved_frames->count is %"PRId64, -                                conn->saved_frames->count); -                        conn->saved_frames->count = 0; -                } - -                timeout.tv_sec = conn->ping_timeout; -                timeout.tv_usec = 0; - -                conn->ping_timer = -                        gf_timer_call_after (trans->xl->ctx, timeout, -                                             client_ping_timer_expired, -                                             (void *) trans); - -                if (conn->ping_timer == NULL) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "unable to setup timer"); -                } else { -                        conn->ping_started = 1; -                } -        } -        pthread_mutex_unlock (&conn->lock); - -        hdrlen = gf_hdr_len (req, 0); -        hdr    = gf_hdr_new (req, 0); -        if (!hdr) -                goto err; - -        dummy_frame = create_frame (this, this->ctx->pool); - -        if (!dummy_frame) -                goto err; - -        dummy_frame->local = trans; - -        ret = protocol_client_xfer (dummy_frame, this, trans, -                                    GF_OP_TYPE_MOP_REQUEST, GF_MOP_PING, -                                    hdr, hdrlen, NULL, 0, NULL); -        return; -err: -        if (hdr) -                GF_FREE (hdr); - -        if (dummy_frame) -                STACK_DESTROY (dummy_frame->root); - -        return; -} - - -int -client_ping_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        xlator_t            *this = NULL; -        transport_t         *trans = NULL; -        client_connection_t *conn = NULL; -        struct timeval       timeout = {0, }; -        int                  op_ret = 0; - -        trans  = frame->local; frame->local = NULL; -        this   = trans->xl; -        conn   = trans->xl_private; - -        op_ret = ntoh32 (hdr->rsp.op_ret); - -        if (op_ret == -1) { -                /* timer expired and transport bailed out */ -                gf_log (this->name, GF_LOG_DEBUG, "timer must have expired"); -                goto out; -        } - -        pthread_mutex_lock (&conn->lock); -        { -                timeout.tv_sec  = conn->ping_timeout; -                timeout.tv_usec = 0; - -                gf_timer_call_cancel (trans->xl->ctx, -                                      conn->ping_timer); - -                conn->ping_timer = -                        gf_timer_call_after (trans->xl->ctx, timeout, -                                             client_start_ping, (void *)trans); -                if (conn->ping_timer == NULL) -                        gf_log (this->name, GF_LOG_DEBUG, -                                "gf_timer_call_after() returned NULL"); -        } -        pthread_mutex_unlock (&conn->lock); -out: -        STACK_DESTROY (frame->root); -        return 0; -} - -int -client_encode_groups (call_frame_t *frame, gf_hdr_common_t *hdr) -{ -        int     i = 0; -        if ((!frame) || (!hdr)) -                return -1; - -        hdr->req.ngrps = hton32 (frame->root->ngrps); -        if (frame->root->ngrps == 0) -                return 0; - -        for (; i < frame->root->ngrps; ++i) -                hdr->req.groups[i] = hton32 (frame->root->groups[i]); - -        return 0; -} - - -int -protocol_client_xfer (call_frame_t *frame, xlator_t *this, transport_t *trans, -                      int type, int op, -                      gf_hdr_common_t *hdr, size_t hdrlen, -                      struct iovec *vector, int count, -                      struct iobref *iobref) -{ -        client_conf_t        *conf = NULL; -        client_connection_t  *conn = NULL; -        uint64_t              callid = 0; -        int32_t               ret = -1; -        int                   start_ping = 0; -        gf_hdr_common_t       rsphdr = {0, }; - -        conf  = this->private; - -        if (!trans) { -                /* default to bulk op since it is 'safer' */ -                trans = conf->transport[CHANNEL_BULK]; -        } -        conn  = trans->xl_private; - -        pthread_mutex_lock (&conn->lock); -        { -                callid = ++conn->callid; - -                hdr->callid = hton64 (callid); -                hdr->op     = hton32 (op); -                hdr->type   = hton32 (type); - -                if (frame) { -                        hdr->req.uid = hton32 (frame->root->uid); -                        hdr->req.gid = hton32 (frame->root->gid); -                        hdr->req.pid = hton32 (frame->root->pid); -                        hdr->req.lk_owner = hton64 (frame->root->lk_owner); -                        client_encode_groups (frame, hdr); -                } - -                if (conn->connected == 0) -                        transport_connect (trans); - -                ret = -1; - -                if (conn->connected || -                    ((type == GF_OP_TYPE_MOP_REQUEST) && -                     (op == GF_MOP_SETVOLUME))) { -                        ret = transport_submit (trans, (char *)hdr, hdrlen, -                                                vector, count, iobref); -                } - -                if ((ret >= 0) && frame) { -                        pthread_mutex_lock (&conf->mutex); -                        { -                                gettimeofday (&conf->last_sent, NULL); -                        } -                        pthread_mutex_unlock (&conf->mutex); -                        save_frame (trans, frame, op, type, callid); -                } - -                if (!conn->ping_started && (ret >= 0)) { -                        start_ping = 1; -                } -        } -        pthread_mutex_unlock (&conn->lock); - -        if (start_ping) -                client_start_ping ((void *) trans); - -        if (frame && (ret < 0)) { -                rsphdr.op = op; -                rsphdr.rsp.op_ret   = hton32 (-1); -                rsphdr.rsp.op_errno = hton32 (ENOTCONN); - -                if (type == GF_OP_TYPE_FOP_REQUEST) { -                        rsphdr.type = GF_OP_TYPE_FOP_REPLY; -                        gf_fops[op] (frame, &rsphdr, sizeof (rsphdr), NULL); -                } else if (type == GF_OP_TYPE_MOP_REQUEST) { -                        rsphdr.type = GF_OP_TYPE_MOP_REPLY; -                        gf_mops[op] (frame, &rsphdr, sizeof (rsphdr), NULL); -                } else { -                        rsphdr.type = GF_OP_TYPE_CBK_REPLY; -                        gf_cbks[op] (frame, &rsphdr, sizeof (rsphdr), NULL); -                } - -                GF_FREE (hdr); -        } - -        return ret; -} - - - -/** - * client_create - create function for client protocol - * @frame: call frame - * @this: this translator structure - * @path: complete path to file - * @flags: create flags - * @mode: create mode - * - * external reference through client_protocol_xlator->fops->create - */ - -int -client_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, -               mode_t mode, fd_t *fd, dict_t *params) -{ -        gf_hdr_common_t     *hdr = NULL; -        gf_fop_create_req_t *req = NULL; -        size_t               hdrlen = 0; -        size_t               pathlen = 0; -        size_t               baselen = 0; -        int32_t              ret = -1; -        ino_t                par = 0; -        uint64_t             gen = 0; -        client_local_t      *local = NULL; - - -        local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); -        GF_VALIDATE_OR_GOTO (this->name, local, unwind); - -        local->fd = fd_ref (fd); -        loc_copy (&local->loc, loc); -        local->flags = flags; - -        frame->local = local; - -        pathlen = STRLEN_0 (loc->path); -        baselen = STRLEN_0 (loc->name); - -        ret = inode_ctx_get2 (loc->parent, this, &par, &gen); -        if (loc->parent->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "CREATE %"PRId64"/%s (%s): failed to get remote inode " -                        "number for parent inode", -                        loc->parent->ino, loc->name, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, pathlen + baselen); -        hdr    = gf_hdr_new (req, pathlen + baselen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->flags   = hton32 (gf_flags_from_flags (flags)); -        req->mode    = hton32 (mode); -        req->par     = hton64 (par); -        req->gen     = hton64 (gen); -        strcpy (req->path, loc->path); -        strcpy (req->bname + pathlen, loc->name); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_CREATE, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL, fd, NULL, NULL); -        return 0; - -} - -/** - * client_open - open function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location of file - * @flags: open flags - * @mode: open modes - * - * external reference through client_protocol_xlator->fops->open - */ - -int -client_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, -             fd_t *fd, int32_t wbflags) -{ -        int                 ret = -1; -        gf_hdr_common_t    *hdr = NULL; -        size_t              hdrlen = 0; -        gf_fop_open_req_t  *req = NULL; -        size_t              pathlen = 0; -        ino_t               ino = 0; -        uint64_t            gen = 0; -        client_local_t     *local = NULL; - -        local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); -        GF_VALIDATE_OR_GOTO (this->name, local, unwind); - -        local->fd = fd_ref (fd); -        loc_copy (&local->loc, loc); -        local->flags = flags; -        local->wbflags = wbflags; - -        frame->local = local; - -        pathlen = STRLEN_0 (loc->path); - -        ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); -        if (loc->inode->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "OPEN %"PRId64" (%s): " -                        "failed to get remote inode number", -                        loc->inode->ino, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, pathlen); -        hdr    = gf_hdr_new (req, pathlen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->ino   = hton64 (ino); -        req->gen   = hton64 (gen); -        req->flags = hton32 (gf_flags_from_flags (flags)); -        req->wbflags = hton32 (wbflags); -        strcpy (req->path, loc->path); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_OPEN, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL, fd); -        return 0; - -} - - -/** - * client_stat - stat function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location - * - * external reference through client_protocol_xlator->fops->stat - */ - -int -client_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) -{ -        gf_hdr_common_t   *hdr = NULL; -        gf_fop_stat_req_t *req = NULL; -        size_t             hdrlen = -1; -        int32_t            ret = -1; -        size_t             pathlen = 0; -        ino_t              ino = 0; -        ino_t              gen = 0; - -        pathlen = STRLEN_0 (loc->path); - -        ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); -        if (loc->inode->ino && ret < 0) { -                gf_log (this->name, GF_LOG_TRACE, -                        "STAT %"PRId64" (%s): " -                        "failed to get remote inode number", -                        loc->inode->ino, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, pathlen); -        hdr    = gf_hdr_new (req, pathlen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->ino  = hton64 (ino); -        req->gen  = hton64 (gen); -        strcpy (req->path, loc->path); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_STAT, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL, NULL); -        return 0; - -} - - -/** - * client_readlink - readlink function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location - * @size: - * - * external reference through client_protocol_xlator->fops->readlink - */ -int -client_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size) -{ -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_readlink_req_t *req = NULL; -        size_t                 hdrlen = -1; -        int                    ret = -1; -        size_t                 pathlen = 0; -        ino_t                  ino = 0; -        uint64_t               gen = 0; - -        pathlen = STRLEN_0 (loc->path); - -        ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); -        if (loc->inode->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "READLINK %"PRId64" (%s): " -                        "failed to get remote inode number", -                        loc->inode->ino, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, pathlen); -        hdr    = gf_hdr_new (req, pathlen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->ino  = hton64 (ino); -        req->gen  = hton64 (gen); -        req->size = hton32 (size); -        strcpy (req->path, loc->path); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_READLINK, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND_STRICT (readlink, frame, -1, EINVAL, -                             NULL, NULL); -        return 0; - -} - - -/** - * client_mknod - mknod function for client protocol - * @frame: call frame - * @this: this translator structure - * @path: pathname of node - * @mode: - * @dev: - * - * external reference through client_protocol_xlator->fops->mknod - */ -int -client_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, -              dev_t dev, dict_t *params) -{ -        gf_hdr_common_t    *hdr = NULL; -        gf_fop_mknod_req_t *req = NULL; -        size_t              hdrlen = -1; -        int                 ret = -1; -        size_t              pathlen = 0; -        size_t              baselen = 0; -        ino_t               par = 0; -        uint64_t            gen = 0; -        client_local_t     *local = NULL; - -        local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); -        GF_VALIDATE_OR_GOTO (this->name, local, unwind); - -        loc_copy (&local->loc, loc); - -        frame->local = local; - -        pathlen = STRLEN_0 (loc->path); -        baselen = STRLEN_0 (loc->name); -        ret = inode_ctx_get2 (loc->parent, this, &par, &gen); -        if (loc->parent->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "MKNOD %"PRId64"/%s (%s): failed to get remote inode " -                        "number for parent", -                        loc->parent->ino, loc->name, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, pathlen + baselen); -        hdr    = gf_hdr_new (req, pathlen + baselen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->par  = hton64 (par); -        req->gen  = hton64 (gen); -        req->mode = hton32 (mode); -        req->dev  = hton64 (dev); -        strcpy (req->path, loc->path); -        strcpy (req->bname + pathlen, loc->name); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_MKNOD, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL, loc->inode, NULL); -        return 0; - -} - - -/** - * client_mkdir - mkdir function for client protocol - * @frame: call frame - * @this: this translator structure - * @path: pathname of directory - * @mode: - * - * external reference through client_protocol_xlator->fops->mkdir - */ -int -client_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, -              dict_t *params) -{ -        gf_hdr_common_t    *hdr = NULL; -        gf_fop_mkdir_req_t *req = NULL; -        size_t              hdrlen = -1; -        int                 ret = -1; -        size_t              pathlen = 0; -        size_t              baselen = 0; -        ino_t               par = 0; -        uint64_t            gen = 0; -        client_local_t     *local = NULL; - -        local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); -        GF_VALIDATE_OR_GOTO (this->name, local, unwind); - -        loc_copy (&local->loc, loc); - -        frame->local = local; - -        pathlen = STRLEN_0 (loc->path); -        baselen = STRLEN_0 (loc->name); -        ret = inode_ctx_get2 (loc->parent, this, &par, &gen); -        if (loc->parent->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "MKDIR %"PRId64"/%s (%s): failed to get remote inode " -                        "number for parent", -                        loc->parent->ino, loc->name, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, pathlen + baselen); -        hdr    = gf_hdr_new (req, pathlen + baselen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->par  = hton64 (par); -        req->gen  = hton64 (gen); -        req->mode = hton32 (mode); -        strcpy (req->path, loc->path); -        strcpy (req->bname + pathlen, loc->name); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_MKDIR, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL, loc->inode, NULL); -        return 0; - -} - -/** - * client_unlink - unlink function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location of file - * - * external reference through client_protocol_xlator->fops->unlink - */ - -int -client_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) -{ -        gf_hdr_common_t     *hdr = NULL; -        gf_fop_unlink_req_t *req = NULL; -        size_t               hdrlen = -1; -        int                  ret = -1; -        size_t               pathlen = 0; -        size_t               baselen = 0; -        ino_t                par = 0; -        uint64_t             gen = 0; - -        pathlen = STRLEN_0 (loc->path); -        baselen = STRLEN_0 (loc->name); -        ret = inode_ctx_get2 (loc->parent, this, &par, &gen); -        if (loc->parent->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "UNLINK %"PRId64"/%s (%s): failed to get remote inode " -                        "number for parent", -                        loc->parent->ino, loc->name, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, pathlen + baselen); -        hdr    = gf_hdr_new (req, pathlen + baselen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->par  = hton64 (par); -        req->gen  = hton64 (gen); -        strcpy (req->path, loc->path); -        strcpy (req->bname + pathlen, loc->name); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_UNLINK, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL); -        return 0; - -} - -/** - * client_rmdir - rmdir function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location - * - * external reference through client_protocol_xlator->fops->rmdir - */ - -int -client_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc) -{ -        gf_hdr_common_t    *hdr = NULL; -        gf_fop_rmdir_req_t *req = NULL; -        size_t              hdrlen = -1; -        int                 ret = -1; -        size_t              pathlen = 0; -        size_t              baselen = 0; -        ino_t               par = 0; -        uint64_t            gen = 0; - -        pathlen = STRLEN_0 (loc->path); -        baselen = STRLEN_0 (loc->name); -        ret = inode_ctx_get2 (loc->parent, this, &par, &gen); -        if (loc->parent->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "RMDIR %"PRId64"/%s (%s): failed to get remote inode " -                        "number for parent", -                        loc->parent->ino, loc->name, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, pathlen + baselen); -        hdr    = gf_hdr_new (req, pathlen + baselen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->par  = hton64 (par); -        req->gen  = hton64 (gen); -        strcpy (req->path, loc->path); -        strcpy (req->bname + pathlen, loc->name); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_RMDIR, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL); -        return 0; - -} - - -/** - * client_symlink - symlink function for client protocol - * @frame: call frame - * @this: this translator structure - * @oldpath: pathname of target - * @newpath: pathname of symlink - * - * external reference through client_protocol_xlator->fops->symlink - */ - -int -client_symlink (call_frame_t *frame, xlator_t *this, const char *linkname, -                loc_t *loc, dict_t *params) -{ -        int                   ret = -1; -        gf_hdr_common_t      *hdr = NULL; -        gf_fop_symlink_req_t *req = NULL; -        size_t                hdrlen  = 0; -        size_t                pathlen = 0; -        size_t                newlen  = 0; -        size_t                baselen = 0; -        ino_t                 par = 0; -        uint64_t              gen = 0; -        client_local_t       *local = NULL; - -        local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); -        GF_VALIDATE_OR_GOTO (this->name, local, unwind); - -        loc_copy (&local->loc, loc); - -        frame->local = local; - -        pathlen = STRLEN_0 (loc->path); -        baselen = STRLEN_0 (loc->name); -        newlen = STRLEN_0 (linkname); -        ret = inode_ctx_get2 (loc->parent, this, &par, &gen); -        if (loc->parent->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "SYMLINK %"PRId64"/%s (%s): failed to get remote inode" -                        " number parent", -                        loc->parent->ino, loc->name, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, pathlen + baselen + newlen); -        hdr    = gf_hdr_new (req, pathlen + baselen + newlen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->par =  hton64 (par); -        req->gen =  hton64 (gen); -        strcpy (req->path, loc->path); -        strcpy (req->bname + pathlen, loc->name); -        strcpy (req->linkname + pathlen + baselen, linkname); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_SYMLINK, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL, loc->inode, NULL); -        return 0; - -} - -/** - * client_rename - rename function for client protocol - * @frame: call frame - * @this: this translator structure - * @oldloc: location of old pathname - * @newloc: location of new pathname - * - * external reference through client_protocol_xlator->fops->rename - */ - -int -client_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, -               loc_t *newloc) -{ -        int                  ret = -1; -        gf_hdr_common_t     *hdr = NULL; -        gf_fop_rename_req_t *req = NULL; -        size_t               hdrlen = 0; -        size_t               oldpathlen = 0; -        size_t               oldbaselen = 0; -        size_t               newpathlen = 0; -        size_t               newbaselen = 0; -        ino_t                oldpar = 0; -        uint64_t             oldgen = 0; -        ino_t                newpar = 0; -        uint64_t             newgen = 0; - -        oldpathlen = STRLEN_0 (oldloc->path); -        oldbaselen = STRLEN_0 (oldloc->name); -        newpathlen = STRLEN_0 (newloc->path); -        newbaselen = STRLEN_0 (newloc->name); -        ret = inode_ctx_get2 (oldloc->parent, this, &oldpar, &oldgen); -        if (oldloc->parent->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "RENAME %"PRId64"/%s (%s): failed to get remote inode " -                        "number for source parent", -                        oldloc->parent->ino, oldloc->name, oldloc->path); -                goto unwind; -        } - -        ret = inode_ctx_get2 (newloc->parent, this, &newpar, &newgen); -        if (newloc->parent->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "CREATE %"PRId64"/%s (%s): failed to get remote inode " -                        "number for destination parent", -                        newloc->parent->ino, newloc->name, newloc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, (oldpathlen + oldbaselen + -                                   newpathlen + newbaselen)); -        hdr    = gf_hdr_new (req, (oldpathlen + oldbaselen + -                                   newpathlen + newbaselen)); - -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->oldpar = hton64 (oldpar); -        req->oldgen = hton64 (oldgen); -        req->newpar = hton64 (newpar); -        req->newgen = hton64 (newgen); - -        strcpy (req->oldpath, oldloc->path); -        strcpy (req->oldbname + oldpathlen, oldloc->name); -        strcpy (req->newpath  + oldpathlen + oldbaselen, newloc->path); -        strcpy (req->newbname + oldpathlen + oldbaselen + newpathlen, -                newloc->name); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_RENAME, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL, NULL); -        return 0; - -} - -/** - * client_link - link function for client protocol - * @frame: call frame - * @this: this translator structure - * @oldloc: location of old pathname - * @newpath: new pathname - * - * external reference through client_protocol_xlator->fops->link - */ - -int -client_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc) -{ -        int                ret = -1; -        gf_hdr_common_t   *hdr = NULL; -        gf_fop_link_req_t *req = NULL; -        size_t             hdrlen = 0; -        size_t             oldpathlen = 0; -        size_t             newpathlen = 0; -        size_t             newbaselen = 0; -        ino_t              oldino = 0; -        uint64_t           oldgen = 0; -        ino_t              newpar = 0; -        uint64_t           newgen = 0; -        client_local_t    *local = NULL; - -        local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); -        GF_VALIDATE_OR_GOTO (this->name, local, unwind); - -        loc_copy (&local->loc, oldloc); - -        frame->local = local; - -        oldpathlen = STRLEN_0 (oldloc->path); -        newpathlen = STRLEN_0 (newloc->path); -        newbaselen = STRLEN_0 (newloc->name); - -        ret = inode_ctx_get2 (oldloc->inode, this, &oldino, &oldgen); -        if (oldloc->inode->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "LINK %"PRId64"/%s (%s) ==> %"PRId64" (%s): " -                        "failed to get remote inode number for source inode", -                        newloc->parent->ino, newloc->name, newloc->path, -                        oldloc->ino, oldloc->path); -                goto unwind; -        } - -        ret = inode_ctx_get2 (newloc->parent, this, &newpar, &newgen); -        if (newloc->parent->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "LINK %"PRId64"/%s (%s) ==> %"PRId64" (%s): " -                        "failed to get remote inode number destination parent", -                        newloc->parent->ino, newloc->name, newloc->path, -                        oldloc->ino, oldloc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, oldpathlen + newpathlen + newbaselen); -        hdr    = gf_hdr_new (req, oldpathlen + newpathlen + newbaselen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        strcpy (req->oldpath, oldloc->path); -        strcpy (req->newpath  + oldpathlen, newloc->path); -        strcpy (req->newbname + oldpathlen + newpathlen, newloc->name); - -        req->oldino = hton64 (oldino); -        req->oldgen = hton64 (oldgen); -        req->newpar = hton64 (newpar); -        req->newgen = hton64 (newgen); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_LINK, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL, oldloc->inode, NULL); -        return 0; -} - - -/** - * client_truncate - truncate function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location - * @offset: - * - * external reference through client_protocol_xlator->fops->truncate - */ - -int -client_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset) -{ -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_truncate_req_t *req = NULL; -        size_t                 hdrlen = -1; -        int                    ret = -1; -        size_t                 pathlen = 0; -        ino_t                  ino = 0; -        uint64_t               gen = 0; - -        pathlen = STRLEN_0 (loc->path); -        ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); -        if (loc->inode->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "TRUNCATE %"PRId64" (%s): " -                        "failed to get remote inode number", -                        loc->inode->ino, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, pathlen); -        hdr    = gf_hdr_new (req, pathlen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->ino    = hton64 (ino); -        req->gen    = hton64 (gen); -        req->offset = hton64 (offset); -        strcpy (req->path, loc->path); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_TRUNCATE, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL, NULL); -        return 0; - -} - - -/** - * client_readv - readv function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * @size: - * @offset: - * - * external reference through client_protocol_xlator->fops->readv - */ - -int -client_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, -              off_t offset) -{ -        gf_hdr_common_t    *hdr = NULL; -        gf_fop_read_req_t  *req = NULL; -        size_t              hdrlen = 0; -        int64_t             remote_fd = -1; -        int                 ret = -1; -        client_fd_ctx_t    *fdctx = NULL; -        client_conf_t      *conf = NULL; - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx, EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD, NULL, 0, NULL); -                return 0; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx, EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD, NULL, 0, NULL); -                return 0; -        } - -        remote_fd = fdctx->remote_fd; -        hdrlen = gf_hdr_len (req, 0); -        hdr    = gf_hdr_new (req, 0); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->fd     = hton64 (remote_fd); -        req->size   = hton32 (size); -        req->offset = hton64 (offset); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_READ, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return 0; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL, NULL, 0, NULL); -        return 0; - -} - -/** - * client_writev - writev function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * @vector: - * @count: - * @offset: - * - * external reference through client_protocol_xlator->fops->writev - */ - -int -client_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, -               struct iovec *vector, int32_t count, off_t offset, -               struct iobref *iobref) -{ -        gf_hdr_common_t    *hdr = NULL; -        gf_fop_write_req_t *req = NULL; -        size_t              hdrlen = 0; -        int64_t             remote_fd = -1; -        int                 ret = -1; -        client_fd_ctx_t    *fdctx = NULL; -        client_conf_t      *conf = NULL; - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD, NULL); -                return 0; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD, NULL); -                return 0; -        } - -        remote_fd = fdctx->remote_fd; -        hdrlen = gf_hdr_len (req, 0); -        hdr    = gf_hdr_new (req, 0); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->fd     = hton64 (remote_fd); -        req->size   = hton32 (iov_length (vector, count)); -        req->offset = hton64 (offset); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_WRITE, -                                    hdr, hdrlen, vector, count, iobref); -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL, NULL); -        return 0; - -} - - -/** - * client_statfs - statfs function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location - * - * external reference through client_protocol_xlator->fops->statfs - */ - -int -client_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc) -{ -        gf_hdr_common_t     *hdr = NULL; -        gf_fop_statfs_req_t *req = NULL; -        size_t               hdrlen = -1; -        int                  ret = -1; -        size_t               pathlen = 0; -        ino_t                ino = 0; -        ino_t                gen = 0; - -        pathlen = STRLEN_0 (loc->path); - -        if (loc->inode) { -                ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); -                if (loc->inode->ino && ret < 0) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "STATFS %"PRId64" (%s): " -                                "failed to get remote inode number", -                                loc->inode->ino, loc->path); -                        goto unwind; -                } -        } - -        hdrlen = gf_hdr_len (req, pathlen); -        hdr    = gf_hdr_new (req, pathlen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->ino = hton64 (ino); -        req->gen = hton64 (gen); -        strcpy (req->path, loc->path); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_STATFS, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL, NULL); -        return 0; - -} - - -/** - * client_flush - flush function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * - * external reference through client_protocol_xlator->fops->flush - */ - -int -client_flush (call_frame_t *frame, xlator_t *this, fd_t *fd) -{ -        gf_hdr_common_t     *hdr = NULL; -        gf_fop_flush_req_t  *req = NULL; -        size_t               hdrlen = 0; -        int64_t              remote_fd = -1; -        int                  ret = -1; -        client_fd_ctx_t     *fdctx = NULL; -        client_conf_t       *conf = NULL; - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD); -                return 0; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD); -                return 0; -        } - -        remote_fd = fdctx->remote_fd; -        hdrlen = gf_hdr_len (req, 0); -        hdr    = gf_hdr_new (req, 0); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->fd = hton64 (remote_fd); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FLUSH, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return 0; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL); -        return 0; - -} - -/** - * client_fsync - fsync function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * @flags: - * - * external reference through client_protocol_xlator->fops->fsync - */ - -int -client_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags) -{ -        gf_hdr_common_t    *hdr = NULL; -        gf_fop_fsync_req_t *req = NULL; -        size_t              hdrlen = 0; -        int64_t             remote_fd = -1; -        int32_t             ret = -1; -        client_fd_ctx_t    *fdctx = NULL; -        client_conf_t      *conf = NULL; - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD); -                return 0; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD); -                return 0; -        } - -        remote_fd = fdctx->remote_fd; -        hdrlen = gf_hdr_len (req, 0); -        hdr    = gf_hdr_new (req, 0); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->fd   = hton64 (remote_fd); -        req->data = hton32 (flags); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FSYNC, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL); -        return 0; - -} - -int -client_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, -                gf_xattrop_flags_t flags, dict_t *dict) -{ -        gf_hdr_common_t      *hdr = NULL; -        gf_fop_xattrop_req_t *req = NULL; -        size_t                hdrlen = 0; -        size_t                dict_len = 0; -        int32_t               ret = -1; -        size_t                pathlen = 0; -        ino_t                 ino = 0; -        uint64_t              gen = 0; -        char                 *buf = NULL; - -        GF_VALIDATE_OR_GOTO ("client", this, unwind); - -        GF_VALIDATE_OR_GOTO (this->name, loc, unwind); - -        if (dict) { -                ret = dict_allocate_and_serialize (dict, &buf, &dict_len); -                if (ret < 0) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "failed to get serialized length of dict(%p)", -                                dict); -                        goto unwind; -                } -        } - -        pathlen = STRLEN_0 (loc->path); - -        ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); -        if (loc->inode->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "XATTROP %"PRId64" (%s): " -                        "failed to get remote inode number", -                        loc->inode->ino, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, dict_len + pathlen); -        hdr    = gf_hdr_new (req, dict_len + pathlen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->flags = hton32 (flags); -        req->dict_len = hton32 (dict_len); -        if (dict) { -                memcpy (req->dict, buf, dict_len); -                GF_FREE (buf); -        } - -        req->ino = hton64 (ino); -        req->gen = hton64 (gen); -        strcpy (req->path + dict_len, loc->path); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_XATTROP, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); - -        STACK_UNWIND (frame, -1, EINVAL, NULL); -        return 0; -} - - -int -client_fxattrop (call_frame_t *frame, xlator_t *this, fd_t *fd, -                 gf_xattrop_flags_t flags, dict_t *dict) -{ -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_fxattrop_req_t *req = NULL; -        size_t                 hdrlen = 0; -        size_t                 dict_len = 0; -        int64_t                remote_fd = -1; -        int32_t                ret = -1; -        ino_t                  ino = 0; -        client_fd_ctx_t       *fdctx = NULL; -        client_conf_t         *conf  = NULL; - -        conf = this->private; - -        if (dict) { -                dict_len = dict_serialized_length (dict); -                if (dict_len < 0) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "failed to get serialized length of dict(%p)", -                                dict); -                        goto unwind; -                } -        } - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. " -                        "returning EBADFD", -                        fd->inode->ino); -                goto unwind; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                goto unwind; -        } - -        ino = fd->inode->ino; -        remote_fd = fdctx->remote_fd; - -        hdrlen = gf_hdr_len (req, dict_len); -        hdr    = gf_hdr_new (req, dict_len); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->flags = hton32 (flags); -        req->dict_len = hton32 (dict_len); -        if (dict) { -                ret = dict_serialize (dict, req->dict); -                if (ret < 0) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "failed to serialize dictionary(%p)", -                                dict); -                        goto unwind; -                } -        } -        req->fd = hton64 (remote_fd); -        req->ino = hton64 (ino); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FXATTROP, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); - -        STACK_UNWIND (frame, -1, EBADFD, NULL); -        return 0; - -} - -/** - * client_setxattr - setxattr function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location - * @dict: dictionary which contains key:value to be set. - * @flags: - * - * external reference through client_protocol_xlator->fops->setxattr - */ - -int -client_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, -                 dict_t *dict, int32_t flags) -{ -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_setxattr_req_t *req = NULL; -        size_t                 hdrlen = 0; -        size_t                 dict_len = 0; -        int                    ret = -1; -        size_t                 pathlen = 0; -        ino_t                  ino = 0; -        uint64_t               gen = 0; - -        dict_len = dict_serialized_length (dict); -        if (dict_len < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "failed to get serialized length of dict(%p)", -                        dict); -                goto unwind; -        } - -        pathlen = STRLEN_0 (loc->path); - -        ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); -        if (loc->inode->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "SETXATTR %"PRId64" (%s): " -                        "failed to get remote inode number", -                        loc->inode->ino, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, dict_len + pathlen); -        hdr    = gf_hdr_new (req, dict_len + pathlen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->ino   = hton64 (ino); -        req->gen   = hton64 (gen); -        req->flags = hton32 (flags); -        req->dict_len = hton32 (dict_len); - -        ret = dict_serialize (dict, req->dict); -        if (ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "failed to serialize dictionary(%p)", -                        dict); -                goto unwind; -        } - -        strcpy (req->path + dict_len, loc->path); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_SETXATTR, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); - -        STACK_UNWIND (frame, -1, EINVAL); -        return 0; -} - -/** - * client_fsetxattr - fsetxattr function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: fd - * @dict: dictionary which contains key:value to be set. - * @flags: - * - * external reference through client_protocol_xlator->fops->fsetxattr - */ - -int -client_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, -                  dict_t *dict, int32_t flags) -{ -        gf_hdr_common_t        *hdr = NULL; -        gf_fop_fsetxattr_req_t *req = NULL; -        size_t                  hdrlen = 0; -        size_t                  dict_len = 0; -        ino_t                   ino; -        int                     ret = -1; -        int64_t                 remote_fd = -1; -        client_fd_ctx_t        *fdctx = NULL; -        client_conf_t          *conf  = NULL; - -        conf = this->private; - -        dict_len = dict_serialized_length (dict); -        if (dict_len < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "failed to get serialized length of dict(%p)", -                        dict); -                goto unwind; -        } - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                goto unwind; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                goto unwind; -        } - -        ino = fd->inode->ino; -        remote_fd = fdctx->remote_fd; - -        hdrlen = gf_hdr_len (req, dict_len); -        hdr    = gf_hdr_new (req, dict_len); - -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->ino   = hton64 (ino); -        req->fd    = hton64 (remote_fd); -        req->flags = hton32 (flags); -        req->dict_len = hton32 (dict_len); - -        ret = dict_serialize (dict, req->dict); -        if (ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "failed to serialize dictionary(%p)", -                        dict); -                goto unwind; -        } - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FSETXATTR, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); - -        STACK_UNWIND (frame, -1, EINVAL); -        return 0; -} - -/** - * client_getxattr - getxattr function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location structure - * - * external reference through client_protocol_xlator->fops->getxattr - */ - -int -client_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, -                 const char *name) -{ -        int                    ret = -1; -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_getxattr_req_t *req = NULL; -        size_t                 hdrlen = 0; -        size_t                 pathlen = 0; -        size_t                 namelen = 0; -        ino_t                  ino = 0; -        uint64_t               gen = 0; - -        pathlen = STRLEN_0 (loc->path); -        if (name) -                namelen = STRLEN_0 (name); - -        ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); -        if (loc->inode->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "GETXATTR %"PRId64" (%s): " -                        "failed to get remote inode number", -                        loc->inode->ino, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, pathlen + namelen); -        hdr    = gf_hdr_new (req, pathlen + namelen); -        GF_VALIDATE_OR_GOTO (frame->this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->ino   = hton64 (ino); -        req->gen   = hton64 (gen); -        req->namelen = hton32 (namelen); -        strcpy (req->path, loc->path); -        if (name) -                strcpy (req->name + pathlen, name); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_GETXATTR, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); - -        STACK_UNWIND (frame, -1, EINVAL, NULL); -        return 0; -} - - -/** - * client_fgetxattr - fgetxattr function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: fd - * - * external reference through client_protocol_xlator->fops->fgetxattr - */ - -int -client_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, -                  const char *name) -{ -        int                     ret = -1; -        gf_hdr_common_t        *hdr = NULL; -        gf_fop_fgetxattr_req_t *req = NULL; -        size_t                  hdrlen = 0; -        int64_t                 remote_fd = -1; -        size_t                  namelen = 0; -        ino_t                   ino = 0; -        client_fd_ctx_t        *fdctx = NULL; -        client_conf_t          *conf  = NULL; - -        if (name) -                namelen = STRLEN_0 (name); - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get remote fd. EBADFD", -                        fd->inode->ino); -                goto unwind; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                goto unwind; -        } - -        ino = fd->inode->ino; -        remote_fd = fdctx->remote_fd; - -        hdrlen = gf_hdr_len (req, namelen); -        hdr    = gf_hdr_new (req, namelen); - -        GF_VALIDATE_OR_GOTO (frame->this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->ino   = hton64 (ino); -        req->fd    = hton64 (remote_fd); -        req->namelen = hton32 (namelen); - -        if (name) -                strcpy (req->name, name); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FGETXATTR, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); - -        STACK_UNWIND (frame, -1, EINVAL, NULL); -        return 0; -} - - -/** - * client_removexattr - removexattr function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location structure - * @name: - * - * external reference through client_protocol_xlator->fops->removexattr - */ - -int -client_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc, -                    const char *name) -{ -        int                       ret = -1; -        gf_hdr_common_t          *hdr = NULL; -        gf_fop_removexattr_req_t *req = NULL; -        size_t                    hdrlen = 0; -        size_t                    namelen = 0; -        size_t                    pathlen = 0; -        ino_t                     ino = 0; -        uint64_t                  gen = 0; - -        pathlen = STRLEN_0 (loc->path); -        namelen = STRLEN_0 (name); - -        ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); -        if (loc->inode->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "REMOVEXATTR %"PRId64" (%s): " -                        "failed to get remote inode number", -                        loc->inode->ino, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, pathlen + namelen); -        hdr    = gf_hdr_new (req, pathlen + namelen); -        GF_VALIDATE_OR_GOTO (frame->this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->ino   = hton64 (ino); -        req->gen   = hton64 (gen); -        strcpy (req->path, loc->path); -        strcpy (req->name + pathlen, name); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_REMOVEXATTR, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL); -        return 0; -} - -/** - * client_opendir - opendir function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location structure - * - * external reference through client_protocol_xlator->fops->opendir - */ - -int -client_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, -                fd_t *fd) -{ -        gf_fop_opendir_req_t *req = NULL; -        gf_hdr_common_t      *hdr = NULL; -        size_t                hdrlen = 0; -        int                   ret = -1; -        ino_t                 ino = 0; -        uint64_t              gen = 0; -        size_t                pathlen = 0; -        client_local_t       *local = NULL; - -        local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); -        GF_VALIDATE_OR_GOTO (this->name, local, unwind); - -        loc_copy (&local->loc, loc); -        local->fd = fd_ref (fd); - -        frame->local = local; - -        ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); -        if (loc->inode->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "OPENDIR %"PRId64" (%s): " -                        "failed to get remote inode number", -                        loc->inode->ino, loc->path); -                goto unwind; -        } - -        pathlen = STRLEN_0 (loc->path); - -        hdrlen = gf_hdr_len (req, pathlen); -        hdr    = gf_hdr_new (req, pathlen); -        GF_VALIDATE_OR_GOTO (frame->this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->ino = hton64 (ino); -        req->gen = hton64 (gen); -        strcpy (req->path, loc->path); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_OPENDIR, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL, fd); -        return 0; - -} - -/** - * client_readdirp - readdirp function for client protocol - * @frame: call frame - * @this: this translator structure - * - * external reference through client_protocol_xlator->fops->readdirp - */ - -int -client_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, -                 off_t offset) -{ -        gf_hdr_common_t         *hdr = NULL; -        gf_fop_readdirp_req_t   *req = NULL; -        size_t                  hdrlen = 0; -        int64_t                 remote_fd = -1; -        int                     ret = -1; -        client_fd_ctx_t         *fdctx = NULL; -        client_conf_t           *conf  = NULL; - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, "(%"PRId64"): failed to get" -                        " fd ctx. EBADFD", fd->inode->ino); -                goto unwind; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, "(%"PRId64"): failed to get" -                        " fd ctx. EBADFD", fd->inode->ino); -                goto unwind; -        } - -        remote_fd = fdctx->remote_fd; -        hdrlen = gf_hdr_len (req, 0); -        hdr    = gf_hdr_new (req, 0); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req->fd     = hton64 (remote_fd); -        req->size   = hton32 (size); -        req->offset = hton64 (offset); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_READDIRP, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return 0; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EBADFD, NULL); -        return 0; - -} - - -/** - * client_readdir - readdir function for client protocol - * @frame: call frame - * @this: this translator structure - * - * external reference through client_protocol_xlator->fops->readdir - */ - -int -client_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, -                off_t offset) -{ -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_readdir_req_t  *req = NULL; -        size_t                 hdrlen = 0; -        int64_t                remote_fd = -1; -        int                    ret = -1; -        client_fd_ctx_t       *fdctx = NULL; -        client_conf_t         *conf  = NULL; - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                goto unwind; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, "(%"PRId64"): failed to get" -                        " fd ctx. EBADFD", fd->inode->ino); -                goto unwind; -        } - -        remote_fd = fdctx->remote_fd; -        hdrlen = gf_hdr_len (req, 0); -        hdr    = gf_hdr_new (req, 0); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req->fd     = hton64 (remote_fd); -        req->size   = hton32 (size); -        req->offset = hton64 (offset); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_READDIR, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return 0; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EBADFD, NULL); -        return 0; - -} - -/** - * client_fsyncdir - fsyncdir function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * @flags: - * - * external reference through client_protocol_xlator->fops->fsyncdir - */ - -int -client_fsyncdir (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags) -{ -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_fsyncdir_req_t *req = NULL; -        size_t                 hdrlen = 0; -        int64_t                remote_fd = -1; -        int32_t                ret = -1; -        client_fd_ctx_t       *fdctx = NULL; -        client_conf_t         *conf  = NULL; - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                goto unwind; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, "(%"PRId64"): failed to get" -                        " fd ctx. EBADFD", fd->inode->ino); -                goto unwind; -        } - -        remote_fd = fdctx->remote_fd; -        hdrlen = gf_hdr_len (req, 0); -        hdr    = gf_hdr_new (req, 0); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->data = hton32 (flags); -        req->fd   = hton64 (remote_fd); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FSYNCDIR, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        STACK_UNWIND (frame, -1, EBADFD); -        return 0; -} - -/** - * client_access - access function for client protocol - * @frame: call frame - * @this: this translator structure - * @loc: location structure - * @mode: - * - * external reference through client_protocol_xlator->fops->access - */ - -int -client_access (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask) -{ -        gf_hdr_common_t     *hdr = NULL; -        gf_fop_access_req_t *req = NULL; -        size_t               hdrlen = -1; -        int                  ret = -1; -        ino_t                ino = 0; -        uint64_t             gen = 0; -        size_t               pathlen = 0; - -        ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); -        if (loc->inode->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "ACCESS %"PRId64" (%s): " -                        "failed to get remote inode number", -                        loc->inode->ino, loc->path); -                goto unwind; -        } - -        pathlen = STRLEN_0 (loc->path); - -        hdrlen = gf_hdr_len (req, pathlen); -        hdr    = gf_hdr_new (req, pathlen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->ino  = hton64 (ino); -        req->gen  = hton64 (gen); -        req->mask = hton32 (mask); -        strcpy (req->path, loc->path); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_ACCESS, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); - -        STACK_UNWIND (frame, -1, EINVAL); -        return 0; - -} - -/** - * client_ftrucate - ftruncate function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * @offset: offset to truncate to - * - * external reference through client_protocol_xlator->fops->ftruncate - */ - -int -client_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, -                  off_t offset) -{ -        gf_hdr_common_t        *hdr = NULL; -        gf_fop_ftruncate_req_t *req = NULL; -        int64_t                 remote_fd = -1; -        size_t                  hdrlen = -1; -        int                     ret = -1; -        client_fd_ctx_t        *fdctx = NULL; -        client_conf_t          *conf  = NULL; - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD, NULL); -                return 0; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, "(%"PRId64"): failed to get" -                        " fd ctx. EBADFD", fd->inode->ino); -                goto unwind; -        } - -        remote_fd = fdctx->remote_fd; -        hdrlen = gf_hdr_len (req, 0); -        hdr    = gf_hdr_new (req, 0); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->fd     = hton64 (remote_fd); -        req->offset = hton64 (offset); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FTRUNCATE, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); - -        STACK_UNWIND (frame, -1, EINVAL, NULL); -        return 0; - -} - -/** - * client_fstat - fstat function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * - * external reference through client_protocol_xlator->fops->fstat - */ - -int -client_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd) -{ -        gf_hdr_common_t    *hdr = NULL; -        gf_fop_fstat_req_t *req = NULL; -        int64_t             remote_fd = -1; -        size_t              hdrlen = -1; -        int                 ret = -1; -        client_fd_ctx_t    *fdctx = NULL; -        client_conf_t      *conf  = NULL; - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD, NULL); -                return 0; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, "(%"PRId64"): failed to get" -                        " fd ctx. EBADFD", fd->inode->ino); -                goto unwind; -        } - -        remote_fd = fdctx->remote_fd; -        hdrlen = gf_hdr_len (req, 0); -        hdr    = gf_hdr_new (req, 0); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->fd = hton64 (remote_fd); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FSTAT, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); - -        STACK_UNWIND (frame, -1, EINVAL, NULL); -        return 0; - -} - -/** - * client_lk - lk function for client protocol - * @frame: call frame - * @this: this translator structure - * @fd: file descriptor structure - * @cmd: lock command - * @lock: - * - * external reference through client_protocol_xlator->fops->lk - */ - -int -client_lk (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd, -           struct gf_flock *flock) -{ -        int              ret = -1; -        gf_hdr_common_t *hdr = NULL; -        gf_fop_lk_req_t *req = NULL; -        size_t           hdrlen = 0; -        int64_t          remote_fd = -1; -        int32_t          gf_cmd = 0; -        int32_t          gf_type = 0; -        client_fd_ctx_t *fdctx = NULL; -        client_conf_t   *conf  = NULL; - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD, NULL); -                return 0; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, "(%"PRId64"): failed to get" -                        " fd ctx. EBADFD", fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD, NULL); -                return 0; -        } - -        remote_fd = fdctx->remote_fd; -        if (cmd == F_GETLK || cmd == F_GETLK64) -                gf_cmd = GF_LK_GETLK; -        else if (cmd == F_SETLK || cmd == F_SETLK64) -                gf_cmd = GF_LK_SETLK; -        else if (cmd == F_SETLKW || cmd == F_SETLKW64) -                gf_cmd = GF_LK_SETLKW; -        else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "Unknown cmd (%d)!", gf_cmd); -                goto unwind; -        } - -        switch (flock->l_type) { -        case F_RDLCK: -                gf_type = GF_LK_F_RDLCK; -                break; -        case F_WRLCK: -                gf_type = GF_LK_F_WRLCK; -                break; -        case F_UNLCK: -                gf_type = GF_LK_F_UNLCK; -                break; -        } - -        hdrlen = gf_hdr_len (req, 0); -        hdr    = gf_hdr_new (req, 0); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->fd   = hton64 (remote_fd); -        req->cmd  = hton32 (gf_cmd); -        req->type = hton32 (gf_type); -        gf_flock_from_flock (&req->flock, flock); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_LK, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); - -        STACK_UNWIND (frame, -1, EINVAL, NULL); -        return 0; -} - -/** - * client_inodelk - inodelk function for client protocol - * @frame: call frame - * @this: this translator structure - * @inode: inode structure - * @cmd: lock command - * @lock: flock struct - * - * external reference through client_protocol_xlator->fops->inodelk - */ - -int -client_inodelk (call_frame_t *frame, xlator_t *this, const char *volume, -                loc_t *loc, int32_t cmd, struct gf_flock *flock) -{ -        int                   ret = -1; -        gf_hdr_common_t      *hdr = NULL; -        gf_fop_inodelk_req_t *req = NULL; -        size_t                hdrlen = 0; -        int32_t               gf_cmd = 0; -        int32_t               gf_type = 0; -        ino_t                 ino  = 0; -        uint64_t              gen  = 0; -        size_t                pathlen = 0; -        size_t                vollen  = 0; - -        pathlen = STRLEN_0 (loc->path); -        vollen  = STRLEN_0 (volume); - -        ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); -        if (loc->inode->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "INODELK %"PRId64" (%s): " -                        "failed to get remote inode number", -                        loc->inode->ino, loc->path); -                goto unwind; -        } - -        if (cmd == F_GETLK || cmd == F_GETLK64) -                gf_cmd = GF_LK_GETLK; -        else if (cmd == F_SETLK || cmd == F_SETLK64) -                gf_cmd = GF_LK_SETLK; -        else if (cmd == F_SETLKW || cmd == F_SETLKW64) -                gf_cmd = GF_LK_SETLKW; -        else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "Unknown cmd (%d)!", gf_cmd); -                goto unwind; -        } - -        switch (flock->l_type) { -        case F_RDLCK: -                gf_type = GF_LK_F_RDLCK; -                break; -        case F_WRLCK: -                gf_type = GF_LK_F_WRLCK; -                break; -        case F_UNLCK: -                gf_type = GF_LK_F_UNLCK; -                break; -        } - -        hdrlen = gf_hdr_len (req, pathlen + vollen); -        hdr    = gf_hdr_new (req, pathlen + vollen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        strcpy (req->path, loc->path); -        strcpy (req->path + pathlen, volume); - -        req->ino  = hton64 (ino); -        req->gen  = hton64 (gen); - -        req->cmd  = hton32 (gf_cmd); -        req->type = hton32 (gf_type); -        gf_flock_from_flock (&req->flock, flock); - - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, -                                    GF_PROTO_FOP_INODELK, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); - -        STACK_UNWIND (frame, -1, EINVAL); -        return 0; - -} - - -/** - * client_finodelk - finodelk function for client protocol - * @frame: call frame - * @this: this translator structure - * @inode: inode structure - * @cmd: lock command - * @lock: flock struct - * - * external reference through client_protocol_xlator->fops->finodelk - */ - -int -client_finodelk (call_frame_t *frame, xlator_t *this, const char *volume, -                 fd_t *fd, int32_t cmd, struct gf_flock *flock) -{ -        int                    ret = -1; -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_finodelk_req_t *req = NULL; -        size_t                 hdrlen = 0; -        size_t                 vollen = 0; -        int32_t                gf_cmd = 0; -        int32_t                gf_type = 0; -        int64_t                remote_fd = -1; -        client_fd_ctx_t       *fdctx = NULL; -        client_conf_t         *conf  = NULL; - -        vollen = STRLEN_0 (volume); - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD); -                return 0; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD); -                return 0; -        } - -        remote_fd = fdctx->remote_fd; -        if (cmd == F_GETLK || cmd == F_GETLK64) -                gf_cmd = GF_LK_GETLK; -        else if (cmd == F_SETLK || cmd == F_SETLK64) -                gf_cmd = GF_LK_SETLK; -        else if (cmd == F_SETLKW || cmd == F_SETLKW64) -                gf_cmd = GF_LK_SETLKW; -        else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "Unknown cmd (%d)!", gf_cmd); -                goto unwind; -        } - -        switch (flock->l_type) { -        case F_RDLCK: -                gf_type = GF_LK_F_RDLCK; -                break; -        case F_WRLCK: -                gf_type = GF_LK_F_WRLCK; -                break; -        case F_UNLCK: -                gf_type = GF_LK_F_UNLCK; -                break; -        } - -        hdrlen = gf_hdr_len (req, vollen); -        hdr    = gf_hdr_new (req, vollen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        strcpy (req->volume, volume); - -        req->fd = hton64 (remote_fd); - -        req->cmd  = hton32 (gf_cmd); -        req->type = hton32 (gf_type); -        gf_flock_from_flock (&req->flock, flock); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, -                                    GF_PROTO_FOP_FINODELK, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); - -        STACK_UNWIND (frame, -1, EINVAL); -        return 0; -} - - -int -client_entrylk (call_frame_t *frame, xlator_t *this, const char *volume, -                loc_t *loc, const char *name, entrylk_cmd cmd, -                entrylk_type type) -{ -        gf_hdr_common_t      *hdr = NULL; -        gf_fop_entrylk_req_t *req = NULL; -        size_t                pathlen = 0; -        size_t                vollen  = 0; -        size_t                hdrlen = -1; -        int                   ret = -1; -        ino_t                 ino = 0; -        uint64_t              gen = 0; -        size_t                namelen = 0; - -        pathlen = STRLEN_0 (loc->path); -        vollen  = STRLEN_0 (volume); - -        if (name) -                namelen = STRLEN_0 (name); - -        ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); -        if (loc->inode->ino && ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "ENTRYLK %"PRId64" (%s): " -                        "failed to get remote inode number", -                        loc->inode->ino, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, pathlen + vollen + namelen); -        hdr    = gf_hdr_new (req, pathlen + vollen + namelen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->ino  = hton64 (ino); -        req->gen  = hton64 (gen); -        req->namelen = hton64 (namelen); - -        strcpy (req->path, loc->path); -        if (name) -                strcpy (req->name + pathlen, name); -        strcpy (req->volume + pathlen + namelen, volume); - -        req->cmd  = hton32 (cmd); -        req->type = hton32 (type); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_ENTRYLK, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); - -        STACK_UNWIND (frame, -1, EINVAL); -        return 0; - -} - - -int -client_fentrylk (call_frame_t *frame, xlator_t *this, const char *volume, -                 fd_t *fd, const char *name, entrylk_cmd cmd, -                 entrylk_type type) -{ -        gf_hdr_common_t        *hdr = NULL; -        gf_fop_fentrylk_req_t  *req = NULL; -        int64_t                 remote_fd = -1; -        size_t                  vollen  = 0; -        size_t                  namelen = 0; -        size_t                  hdrlen = -1; -        int                     ret = -1; -        client_fd_ctx_t        *fdctx = NULL; -        client_conf_t          *conf  = NULL; - -        if (name) -                namelen = STRLEN_0 (name); - -        conf = this->private; - -        vollen = STRLEN_0 (volume); - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD); -                return 0; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD); -                return 0; -        } - -        remote_fd = fdctx->remote_fd; -        hdrlen = gf_hdr_len (req, namelen + vollen); -        hdr    = gf_hdr_new (req, namelen + vollen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->fd = hton64 (remote_fd); -        req->namelen = hton64 (namelen); - -        if (name) -                strcpy (req->name, name); - -        strcpy (req->volume + namelen, volume); - -        req->cmd  = hton32 (cmd); -        req->type = hton32 (type); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FENTRYLK, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); - -        STACK_UNWIND (frame, -1, EINVAL); -        return 0; -} - -/* - * client_lookup - lookup function for client protocol - * @frame: call frame - * @this: - * @loc: location - * - * not for external reference - */ - -int -client_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, -               dict_t *xattr_req) -{ -        gf_hdr_common_t     *hdr = NULL; -        gf_fop_lookup_req_t *req = NULL; -        size_t               hdrlen = -1; -        int                  ret = -1; -        ino_t                ino = 0; -        ino_t                par = 0; -        uint64_t             gen = 0; -        size_t               dictlen = 0; -        size_t               pathlen = 0; -        size_t               baselen = 0; -        int32_t              op_ret = -1; -        int32_t              op_errno = EINVAL; -        client_local_t      *local = NULL; -        char                *buf = NULL; - -        GF_VALIDATE_OR_GOTO (this->name, loc, unwind); -        GF_VALIDATE_OR_GOTO (this->name, loc->path, unwind); - -        local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); -        GF_VALIDATE_OR_GOTO (this->name, local, unwind); - -        loc_copy (&local->loc, loc); - -        frame->local = local; - -        if (loc->ino != 1 && loc->parent) { -                ret = inode_ctx_get2 (loc->parent, this, &par, &gen); -                if (loc->parent->ino && ret < 0) { -                        gf_log (this->name, GF_LOG_TRACE, -                                "LOOKUP %"PRId64"/%s (%s): failed to get " -                                "remote inode number for parent", -                                loc->parent->ino, loc->name, loc->path); -                        goto unwind; -                } -                GF_VALIDATE_OR_GOTO (this->name, loc->name, unwind); -                baselen = STRLEN_0 (loc->name); -        } else { -                ino = 1; -        } - -        pathlen = STRLEN_0 (loc->path); - -        if (xattr_req) { -                ret = dict_allocate_and_serialize (xattr_req, &buf, &dictlen); -                if (ret < 0) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "failed to get serialized length of dict(%p)", -                                xattr_req); -                        goto unwind; -                } -        } - -        hdrlen = gf_hdr_len (req, pathlen + baselen + dictlen); -        hdr    = gf_hdr_new (req, pathlen + baselen + dictlen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->ino   = hton64 (ino); -        req->gen   = hton64 (gen); -        req->par   = hton64 (par); -        strcpy (req->path, loc->path); -        if (baselen) -                strcpy (req->path + pathlen, loc->name); - -        if (dictlen > 0) { -                memcpy (req->dict + pathlen + baselen, buf, dictlen); -                GF_FREE (buf); -        } - -        req->dictlen = hton32 (dictlen); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_LOOKUP, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; - -unwind: -        STACK_UNWIND (frame, op_ret, op_errno, (loc)?loc->inode:NULL, NULL, NULL); -        return ret; -} - - -int -client_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, -                struct iatt *stbuf, int32_t valid) -{ -        gf_hdr_common_t      *hdr = NULL; -        gf_fop_setattr_req_t *req = NULL; -        size_t                hdrlen = 0; -        size_t                pathlen = 0; -        ino_t                 ino = 0; -        uint64_t              gen = 0; -        int                   ret = -1; - -        GF_VALIDATE_OR_GOTO ("client", this, unwind); -        GF_VALIDATE_OR_GOTO (this->name, frame, unwind); - -        pathlen = STRLEN_0 (loc->path); - -        ret = inode_ctx_get2 (loc->inode, this, &ino, &gen); -        if (loc->inode->ino && ret < 0) { -                gf_log (this->name, GF_LOG_TRACE, -                        "SETATTR %"PRId64" (%s): " -                        "failed to get remote inode number", -                        loc->inode->ino, loc->path); -                goto unwind; -        } - -        hdrlen = gf_hdr_len (req, pathlen); -        hdr    = gf_hdr_new (req, pathlen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->ino  = hton64 (ino); -        req->gen  = hton64 (gen); -        strcpy (req->path, loc->path); - -        gf_stat_from_iatt (&req->stbuf, stbuf); -        req->valid = hton32 (valid); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_SETATTR, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        STACK_UNWIND (frame, -1, EINVAL, NULL); -        return 0; -} - - -int -client_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, -                 struct iatt *stbuf, int32_t valid) -{ -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_fsetattr_req_t *req = NULL; -        size_t                 hdrlen = 0; -        int                    ret = -1; -        client_fd_ctx_t       *fdctx = NULL; -        int64_t                remote_fd = -1; -        client_conf_t         *conf  = NULL; - -        GF_VALIDATE_OR_GOTO ("client", this, unwind); -        GF_VALIDATE_OR_GOTO (this->name, frame, unwind); - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD, NULL, NULL); -                return 0; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD, NULL, NULL); -                return 0; -        } - -        remote_fd = fdctx->remote_fd; -        hdrlen = gf_hdr_len (req, 0); -        hdr    = gf_hdr_new (req, 0); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req    = gf_param (hdr); - -        req->fd = hton64 (remote_fd); - -        gf_stat_from_iatt (&req->stbuf, stbuf); -        req->valid = hton32 (valid); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_FSETATTR, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        STACK_UNWIND (frame, -1, EINVAL, NULL, NULL); -        return 0; -} - - -int -client_fdctx_destroy (xlator_t *this, client_fd_ctx_t *fdctx) -{ -        call_frame_t             *fr = NULL; -        int32_t                   ret = -1; -        gf_hdr_common_t          *hdr = NULL; -        size_t                    hdrlen = 0; -        gf_cbk_release_req_t     *req = NULL; -        gf_cbk_releasedir_req_t  *reqdir = NULL; -        int64_t                   remote_fd = -1; -        int                       op = 0; - -        remote_fd = fdctx->remote_fd; - -        if (remote_fd == -1) -                goto out; - -        if (fdctx->is_dir) { -                hdrlen     = gf_hdr_len (reqdir, 0); -                hdr        = gf_hdr_new (reqdir, 0); -                op         = GF_CBK_RELEASEDIR; -                reqdir     = gf_param (hdr); -                reqdir->fd = hton64 (remote_fd); -        } else { -                hdrlen  = gf_hdr_len (req, 0); -                hdr     = gf_hdr_new (req, 0); -                op      = GF_CBK_RELEASE; -                req     = gf_param (hdr); -                req->fd = hton64 (remote_fd); -        } - -        fr = create_frame (this, this->ctx->pool); - -        ret = protocol_client_xfer (fr, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_CBK_REQUEST, op, -                                    hdr, hdrlen, NULL, 0, NULL); - -out: -        inode_unref (fdctx->inode); -        GF_FREE (fdctx); - -        return ret; -} - - -/** - * client_releasedir - releasedir function for client protocol - * @this: this translator structure - * @fd: file descriptor structure - * - * external reference through client_protocol_xlator->cbks->releasedir - */ - -int -client_releasedir (xlator_t *this, fd_t *fd) -{ -        int64_t                remote_fd = -1; -        client_conf_t         *conf = NULL; -        client_fd_ctx_t       *fdctx = NULL; - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_del_ctx (fd, this); -                if (fdctx != NULL) { -                        remote_fd = fdctx->remote_fd; - -                        /* fdctx->remote_fd == -1 indicates a reopen attempt -                           in progress. Just mark ->released = 1 and let -                           reopen_cbk handle releasing -                        */ - -                        if (remote_fd != -1) -                                list_del_init (&fdctx->sfd_pos); - -                        fdctx->released = 1; -                } -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (remote_fd != -1) -                client_fdctx_destroy (this, fdctx); - -        return 0; -} - - -/** - * client_release - release function for client protocol - * @this: this translator structure - * @fd: file descriptor structure - * - * external reference through client_protocol_xlator->cbks->release - * - */ -int -client_release (xlator_t *this, fd_t *fd) -{ -        int64_t                remote_fd = -1; -        client_conf_t         *conf = NULL; -        client_fd_ctx_t       *fdctx = NULL; - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_del_ctx (fd, this); -                if (fdctx != NULL) { -                        remote_fd = fdctx->remote_fd; - -                        /* fdctx->remote_fd == -1 indicates a reopen attempt -                           in progress. Just mark ->released = 1 and let -                           reopen_cbk handle releasing -                        */ - -                        if (remote_fd != -1) -                                list_del_init (&fdctx->sfd_pos); - -                        fdctx->released = 1; -                } -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (remote_fd != -1) -                client_fdctx_destroy (this, fdctx); - -        return 0; -} - -/* - * MGMT_OPS - */ - -/* Callbacks */ - -int -client_fxattrop_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                     struct iobuf *iobuf) -{ -        gf_fop_xattrop_rsp_t *rsp = NULL; -        int32_t               op_ret   = 0; -        int32_t               gf_errno = 0; -        int32_t               op_errno = 0; -        int32_t               dict_len = 0; -        dict_t               *dict = NULL; -        int32_t               ret = -1; -        char                 *dictbuf = NULL; - -        rsp = gf_param (hdr); -        GF_VALIDATE_OR_GOTO (frame->this->name, rsp, fail); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); - -        if (op_ret >= 0) { -                op_ret = -1; -                dict_len = ntoh32 (rsp->dict_len); - -                if (dict_len > 0) { -                        dictbuf = memdup (rsp->dict, dict_len); -                        GF_VALIDATE_OR_GOTO (frame->this->name, dictbuf, fail); - -                        dict = dict_new(); -                        GF_VALIDATE_OR_GOTO (frame->this->name, dict, fail); - -                        ret = dict_unserialize (dictbuf, dict_len, &dict); -                        if (ret < 0) { -                                gf_log (frame->this->name, GF_LOG_DEBUG, -                                        "failed to serialize dictionary(%p)", -                                        dict); -                                op_errno = -ret; -                                goto fail; -                        } else { -                                dict->extra_free = dictbuf; -                                dictbuf = NULL; -                        } -                } -                op_ret = 0; -        } -        gf_errno = ntoh32 (hdr->rsp.op_errno); -        op_errno = gf_error_to_errno (gf_errno); - -fail: -        STACK_UNWIND (frame, op_ret, op_errno, dict); - -        if (dictbuf) -                GF_FREE (dictbuf); - -        if (dict) -                dict_unref (dict); - -        return 0; -} - - -int -client_xattrop_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                    struct iobuf *iobuf) -{ -        gf_fop_xattrop_rsp_t *rsp = NULL; -        int32_t               op_ret   = -1; -        int32_t               gf_errno = EINVAL; -        int32_t               op_errno = 0; -        int32_t               dict_len = 0; -        dict_t               *dict = NULL; -        int32_t               ret = -1; -        char                 *dictbuf = NULL; - -        rsp = gf_param (hdr); -        GF_VALIDATE_OR_GOTO (frame->this->name, rsp, fail); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        if (op_ret >= 0) { -                op_ret = -1; -                dict_len = ntoh32 (rsp->dict_len); - -                if (dict_len > 0) { -                        dictbuf = memdup (rsp->dict, dict_len); -                        GF_VALIDATE_OR_GOTO (frame->this->name, dictbuf, fail); - -                        dict = get_new_dict(); -                        GF_VALIDATE_OR_GOTO (frame->this->name, dict, fail); -                        dict_ref (dict); - -                        ret = dict_unserialize (dictbuf, dict_len, &dict); -                        if (ret < 0) { -                                gf_log (frame->this->name, GF_LOG_DEBUG, -                                        "failed to serialize dictionary(%p)", -                                        dict); -                                goto fail; -                        } else { -                                dict->extra_free = dictbuf; -                                dictbuf = NULL; -                        } -                } -                op_ret = 0; -        } -        gf_errno = ntoh32 (hdr->rsp.op_errno); -        op_errno = gf_error_to_errno (gf_errno); - - -fail: -        STACK_UNWIND (frame, op_ret, op_errno, dict); - -        if (dictbuf) -                GF_FREE (dictbuf); -        if (dict) -                dict_unref (dict); - -        return 0; -} - -/* - * client_create_cbk - create callback function for client protocol - * @frame: call frame - * @args: arguments in dictionary - * - * not for external reference - */ - -int -client_create_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                   struct iobuf *iobuf) -{ -        gf_fop_create_rsp_t  *rsp = NULL; -        int32_t               op_ret = 0; -        int32_t               op_errno = 0; -        fd_t                 *fd = NULL; -        inode_t              *inode = NULL; -        struct iatt           stbuf = {0, }; -        struct iatt           preparent = {0, }; -        struct iatt           postparent = {0, }; -        int64_t               remote_fd = 0; -        int32_t               ret = -1; -        client_local_t       *local = NULL; -        client_conf_t        *conf = NULL; -        client_fd_ctx_t      *fdctx = NULL; -        ino_t                 ino = 0; -        uint64_t              gen = 0; - -        local = frame->local; frame->local = NULL; -        conf  = frame->this->private; -        fd    = local->fd; -        inode = local->loc.inode; - -        rsp = gf_param (hdr); - -        op_ret    = ntoh32 (hdr->rsp.op_ret); -        op_errno  = ntoh32 (hdr->rsp.op_errno); - -        if (op_ret >= 0) { -                remote_fd = ntoh64 (rsp->fd); -                gf_stat_to_iatt (&rsp->stat, &stbuf); - -                gf_stat_to_iatt (&rsp->preparent, &preparent); -                gf_stat_to_iatt (&rsp->postparent, &postparent); - -                ino = stbuf.ia_ino; -                gen = stbuf.ia_gen; -        } - -        if (op_ret >= 0) { -                ret = inode_ctx_put2 (local->loc.inode, frame->this, ino, gen); - -                if (ret < 0) { -                        gf_log (frame->this->name, GF_LOG_DEBUG, -                                "CREATE %"PRId64"/%s (%s): failed to set " -                                "remote inode number to inode ctx", -                                local->loc.parent->ino, local->loc.name, -                                local->loc.path); -                        op_ret = -1; -                        op_errno = EINVAL; -                        goto unwind_out; -                } - -                fdctx = GF_CALLOC (1, sizeof (*fdctx), -                                   gf_client_mt_client_fd_ctx_t); -                if (!fdctx) { -                        op_ret = -1; -                        op_errno = ENOMEM; -                        goto unwind_out; -                } - -                fdctx->remote_fd = remote_fd; -                fdctx->inode     = inode_ref (fd->inode); -                fdctx->ino       = ino; -                fdctx->gen       = gen; -                fdctx->flags     = local->flags; - -                INIT_LIST_HEAD (&fdctx->sfd_pos); - -                this_fd_set_ctx (fd, frame->this, &local->loc, fdctx); - -                pthread_mutex_lock (&conf->mutex); -                { -                        list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); -                } -                pthread_mutex_unlock (&conf->mutex); -        } -unwind_out: -        STACK_UNWIND (frame, op_ret, op_errno, fd, inode, &stbuf, -                      &preparent, &postparent); - -        client_local_wipe (local); - -        return 0; -} - - -/* - * client_open_cbk - open callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ -int -client_open_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        int32_t              op_ret = -1; -        int32_t              op_errno = ENOTCONN; -        fd_t                *fd = NULL; -        int64_t              remote_fd = 0; -        gf_fop_open_rsp_t   *rsp = NULL; -        client_local_t      *local = NULL; -        client_conf_t       *conf = NULL; -        client_fd_ctx_t     *fdctx = NULL; -        ino_t                ino = 0; -        uint64_t             gen = 0; - - -        local = frame->local; - -        if (local->op) { -                local->op (frame, hdr, hdrlen, iobuf); -                return 0; -        } - -        frame->local = NULL; -        conf  = frame->this->private; -        fd    = local->fd; - -        rsp = gf_param (hdr); - -        op_ret    = ntoh32 (hdr->rsp.op_ret); -        op_errno  = ntoh32 (hdr->rsp.op_errno); - -        if (op_ret >= 0) { -                remote_fd = ntoh64 (rsp->fd); -        } - -        if (op_ret >= 0) { -                fdctx = GF_CALLOC (1, sizeof (*fdctx), -                                   gf_client_mt_client_fd_ctx_t); -                if (!fdctx) { -                        op_ret = -1; -                        op_errno = ENOMEM; -                        goto unwind_out; -                } - -                inode_ctx_get2 (fd->inode, frame->this, &ino, &gen); - -                fdctx->remote_fd = remote_fd; -                fdctx->inode     = inode_ref (fd->inode); -                fdctx->ino       = ino; -                fdctx->gen       = gen; -                fdctx->flags     = local->flags; -                fdctx->wbflags   = local->wbflags; - -                INIT_LIST_HEAD (&fdctx->sfd_pos); - -                this_fd_set_ctx (fd, frame->this, &local->loc, fdctx); - -                pthread_mutex_lock (&conf->mutex); -                { -                        list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); -                } -                pthread_mutex_unlock (&conf->mutex); -        } -unwind_out: -        STACK_UNWIND (frame, op_ret, op_errno, fd); - -        client_local_wipe (local); - -        return 0; -} - -/* - * client_stat_cbk - stat callback for client protocol - * @frame: call frame - * @args: arguments dictionary - * - * not for external reference - */ - -int -client_stat_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        struct iatt        stbuf = {0, }; -        gf_fop_stat_rsp_t *rsp = NULL; -        int32_t            op_ret = 0; -        int32_t            op_errno = 0; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret == 0) { -                gf_stat_to_iatt (&rsp->stat, &stbuf); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - -        return 0; -} - - -/* - * client_mknod_cbk - mknod callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_mknod_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                  struct iobuf *iobuf) -{ -        gf_fop_mknod_rsp_t *rsp = NULL; -        int32_t             op_ret = 0; -        int32_t             op_errno = 0; -        struct iatt         stbuf = {0, }; -        inode_t            *inode = NULL; -        client_local_t     *local = NULL; -        int                 ret = 0; -        struct iatt         preparent = {0,}; -        struct iatt         postparent = {0,}; - -        local = frame->local; -        frame->local = NULL; -        inode = local->loc.inode; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret >= 0) { -                gf_stat_to_iatt (&rsp->stat, &stbuf); - -                ret = inode_ctx_put2 (local->loc.inode, frame->this, -                                      stbuf.ia_ino, stbuf.ia_gen); -                if (ret < 0) { -                        gf_log (frame->this->name, GF_LOG_DEBUG, -                                "MKNOD %"PRId64"/%s (%s): failed to set remote" -                                " inode number to inode ctx", -                                local->loc.parent->ino, local->loc.name, -                                local->loc.path); - -                        STACK_UNWIND (frame, -1, EINVAL, inode, NULL, -                                      NULL, NULL); -                        return 0; -                } - -                gf_stat_to_iatt (&rsp->preparent, &preparent); -                gf_stat_to_iatt (&rsp->postparent, &postparent); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, inode, &stbuf, -                      &preparent, &postparent); - -        client_local_wipe (local); - -        return 0; -} - -/* - * client_symlink_cbk - symlink callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_symlink_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                    struct iobuf *iobuf) -{ -        gf_fop_symlink_rsp_t *rsp = NULL; -        int32_t               op_ret = 0; -        int32_t               op_errno = 0; -        struct iatt           stbuf = {0, }; -        struct iatt           preparent = {0,}; -        struct iatt           postparent = {0,}; -        inode_t              *inode = NULL; -        client_local_t       *local = NULL; -        int                   ret = 0; - -        local = frame->local; -        frame->local = NULL; -        inode = local->loc.inode; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret >= 0) { -                gf_stat_to_iatt (&rsp->stat, &stbuf); - -                ret = inode_ctx_put2 (inode, frame->this, -                                      stbuf.ia_ino, stbuf.ia_gen); -                if (ret < 0) { -                        gf_log (frame->this->name, GF_LOG_DEBUG, -                                "SYMLINK %"PRId64"/%s (%s): failed to set " -                                "remote inode number to inode ctx", -                                local->loc.parent->ino, local->loc.name, -                                local->loc.path); -                        STACK_UNWIND (frame, -1, EINVAL, inode, NULL, -                                      NULL, NULL); -                        return 0; -                } -                gf_stat_to_iatt (&rsp->preparent, &preparent); -                gf_stat_to_iatt (&rsp->postparent, &postparent); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, inode, &stbuf, -                      &preparent, &postparent); - -        client_local_wipe (local); - -        return 0; -} - -/* - * client_link_cbk - link callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_link_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        gf_fop_link_rsp_t *rsp = NULL; -        int32_t            op_ret = 0; -        int32_t            op_errno = 0; -        struct iatt        stbuf = {0, }; -        inode_t           *inode = NULL; -        client_local_t    *local = NULL; -        struct iatt        preparent = {0,}; -        struct iatt        postparent = {0,}; - -        local = frame->local; -        frame->local = NULL; -        inode = local->loc.inode; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret >= 0) { -                gf_stat_to_iatt (&rsp->stat, &stbuf); - -                gf_stat_to_iatt (&rsp->preparent, &preparent); -                gf_stat_to_iatt (&rsp->postparent, &postparent); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, inode, &stbuf, -                      &preparent, &postparent); - -        client_local_wipe (local); - -        return 0; -} - -/* - * client_truncate_cbk - truncate callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_truncate_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                     struct iobuf *iobuf) -{ -        gf_fop_truncate_rsp_t *rsp = NULL; -        int32_t                op_ret = 0; -        int32_t                op_errno = 0; -        struct iatt         prestat = {0, }; -        struct iatt         poststat = {0, }; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret == 0) { -                gf_stat_to_iatt (&rsp->prestat, &prestat); -                gf_stat_to_iatt (&rsp->poststat, &poststat); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &prestat, &poststat); - -        return 0; -} - -/* client_fstat_cbk - fstat callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_fstat_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                  struct iobuf *iobuf) -{ -        struct iatt         stbuf = {0, }; -        gf_fop_fstat_rsp_t *rsp = NULL; -        int32_t             op_ret = 0; -        int32_t             op_errno = 0; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret == 0) { -                gf_stat_to_iatt (&rsp->stat, &stbuf); - -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - -        return 0; -} - -/* - * client_ftruncate_cbk - ftruncate callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ -int -client_ftruncate_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                      struct iobuf *iobuf) -{ -        gf_fop_ftruncate_rsp_t *rsp = NULL; -        int32_t                 op_ret = 0; -        int32_t                 op_errno = 0; -        struct iatt             prestat = {0, }; -        struct iatt             poststat = {0, }; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret == 0) { -                gf_stat_to_iatt (&rsp->prestat, &prestat); -                gf_stat_to_iatt (&rsp->poststat, &poststat); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &prestat, &poststat); - -        return 0; -} - - -/* client_readv_cbk - readv callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external referece - */ - -int -client_readv_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                  struct iobuf *iobuf) -{ -        gf_fop_read_rsp_t  *rsp = NULL; -        int32_t             op_ret = 0; -        int32_t             op_errno = 0; -        struct iovec        vector = {0, }; -        struct iatt         stbuf = {0, }; -        struct iobref      *iobref = NULL; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret != -1) { -                iobref = iobref_new (); -                gf_stat_to_iatt (&rsp->stat, &stbuf); -                vector.iov_len  = op_ret; - -                if (op_ret > 0) { -                        vector.iov_base = iobuf->ptr; -                        iobref_add (iobref, iobuf); -                } -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &vector, 1, &stbuf, iobref); - -        if (iobref) -                iobref_unref (iobref); - -        if (iobuf) -                iobuf_unref (iobuf); - -        return 0; -} - -/* - * client_write_cbk - write callback for client protocol - * @frame: cal frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_write_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                  struct iobuf *iobuf) -{ -        gf_fop_write_rsp_t *rsp = NULL; -        int32_t             op_ret = 0; -        int32_t             op_errno = 0; -        struct iatt         prestat = {0, }; -        struct iatt         poststat = {0, }; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret >= 0) { -                gf_stat_to_iatt (&rsp->prestat, &prestat); -                gf_stat_to_iatt (&rsp->poststat, &poststat); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &prestat, &poststat); - -        return 0; -} - - -int -client_readdirp_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                     struct iobuf *iobuf) -{ -        gf_fop_readdirp_rsp_t   *rsp = NULL; -        int32_t                 op_ret = 0; -        int32_t                 op_errno = 0; -        uint32_t                buf_size = 0; -        gf_dirent_t             entries; - -        rsp = gf_param (hdr); - -        op_ret    = ntoh32 (hdr->rsp.op_ret); -        op_errno  = ntoh32 (hdr->rsp.op_errno); - -        INIT_LIST_HEAD (&entries.list); -        if (op_ret > 0) { -                buf_size = ntoh32 (rsp->size); -                gf_dirent_unserialize (&entries, rsp->buf, buf_size); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &entries); - -        gf_dirent_free (&entries); - -        return 0; -} - - -int -client_readdir_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                    struct iobuf *iobuf) -{ -        gf_fop_readdir_rsp_t *rsp = NULL; -        int32_t               op_ret = 0; -        int32_t               op_errno = 0; -        uint32_t              buf_size = 0; -        gf_dirent_t           entries; - -        rsp = gf_param (hdr); - -        op_ret    = ntoh32 (hdr->rsp.op_ret); -        op_errno  = ntoh32 (hdr->rsp.op_errno); - -        INIT_LIST_HEAD (&entries.list); -        if (op_ret > 0) { -                buf_size = ntoh32 (rsp->size); -                gf_dirent_unserialize (&entries, rsp->buf, buf_size); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &entries); - -        gf_dirent_free (&entries); - -        return 0; -} - -/* - * client_fsync_cbk - fsync callback for client protocol - * - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_fsync_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                  struct iobuf *iobuf) -{ -        struct iatt         prestat = {0, }; -        struct iatt         poststat = {0,}; -        gf_fop_fsync_rsp_t *rsp = NULL; -        int32_t             op_ret = 0; -        int32_t             op_errno = 0; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret == 0) { -                gf_stat_to_iatt (&rsp->prestat, &prestat); -                gf_stat_to_iatt (&rsp->poststat, &poststat); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &prestat, &poststat); - -        return 0; -} - -/* - * client_unlink_cbk - unlink callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_unlink_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                   struct iobuf *iobuf) -{ -        gf_fop_unlink_rsp_t *rsp = NULL; -        int32_t              op_ret = 0; -        int32_t              op_errno = 0; -        struct iatt          preparent = {0,}; -        struct iatt          postparent = {0,}; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret == 0) { -                gf_stat_to_iatt (&rsp->preparent, &preparent); -                gf_stat_to_iatt (&rsp->postparent, &postparent); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &preparent, &postparent); - -        return 0; -} - -/* - * client_rename_cbk - rename callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_rename_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                   struct iobuf *iobuf) -{ -        struct iatt          stbuf = {0, }; -        gf_fop_rename_rsp_t *rsp = NULL; -        int32_t              op_ret = 0; -        int32_t              op_errno = 0; -        struct iatt          preoldparent = {0, }; -        struct iatt          postoldparent = {0, }; -        struct iatt          prenewparent = {0, }; -        struct iatt          postnewparent = {0, }; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret == 0) { -                gf_stat_to_iatt (&rsp->stat, &stbuf); -                gf_stat_to_iatt (&rsp->preoldparent, &preoldparent); -                gf_stat_to_iatt (&rsp->postoldparent, &postoldparent); -                gf_stat_to_iatt (&rsp->prenewparent, &prenewparent); -                gf_stat_to_iatt (&rsp->postnewparent, &postnewparent); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &stbuf, &preoldparent, -                      &postoldparent, &prenewparent, &postnewparent); - -        return 0; -} - - -/* - * client_readlink_cbk - readlink callback for client protocol - * - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ -int -client_readlink_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                     struct iobuf *iobuf) -{ -        gf_fop_readlink_rsp_t *rsp = NULL; -        int32_t                op_ret = 0; -        int32_t                op_errno = 0; -        char                  *link = NULL; -        struct iatt            stbuf = {0,}; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret > 0) { -                link = rsp->path; -                gf_stat_to_iatt (&rsp->buf, &stbuf); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, link, &stbuf); -        return 0; -} - -/* - * client_mkdir_cbk - mkdir callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_mkdir_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                  struct iobuf *iobuf) -{ -        gf_fop_mkdir_rsp_t *rsp = NULL; -        int32_t             op_ret = 0; -        int32_t             op_errno = 0; -        struct iatt         stbuf = {0, }; -        inode_t            *inode = NULL; -        client_local_t     *local = NULL; -        int                 ret = 0; -        struct iatt         preparent = {0,}; -        struct iatt         postparent = {0,}; - -        local = frame->local; -        inode = local->loc.inode; -        frame->local = NULL; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret >= 0) { -                gf_stat_to_iatt (&rsp->stat, &stbuf); - -                ret = inode_ctx_put2 (inode, frame->this, stbuf.ia_ino, -                                      stbuf.ia_gen); -                if (ret < 0) { -                        gf_log (frame->this->name, GF_LOG_DEBUG, -                                "MKDIR %"PRId64"/%s (%s): failed to set " -                                "remote inode number to inode ctx", -                                local->loc.parent->ino, local->loc.name, -                                local->loc.path); -                        STACK_UNWIND (frame, -1, EINVAL, inode, NULL, -                                      NULL, NULL); -                        return 0; -                } - -                gf_stat_to_iatt (&rsp->preparent, &preparent); -                gf_stat_to_iatt (&rsp->postparent, &postparent); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, inode, &stbuf, -                      &preparent, &postparent); - -        client_local_wipe (local); - -        return 0; -} - -/* - * client_flush_cbk - flush callback for client protocol - * - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_flush_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                  struct iobuf *iobuf) -{ -        int32_t op_ret = 0; -        int32_t op_errno = 0; - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        STACK_UNWIND (frame, op_ret, op_errno); - -        return 0; -} - -/* - * client_opendir_cbk - opendir callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_opendir_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                    struct iobuf *iobuf) -{ -        int32_t               op_ret   = -1; -        int32_t               op_errno = ENOTCONN; -        fd_t                 *fd       = NULL; -        int64_t               remote_fd = 0; -        gf_fop_opendir_rsp_t *rsp       = NULL; -        client_local_t       *local = NULL; -        client_conf_t        *conf = NULL; -        client_fd_ctx_t      *fdctx = NULL; -        ino_t                 ino = 0; -        uint64_t              gen = 0; - - -        local = frame->local; - -        if (local->op) { -                local->op (frame, hdr, hdrlen, iobuf); -                return 0; -        } - -        frame->local = NULL; -        conf  = frame->this->private; -        fd    = local->fd; - -        rsp = gf_param (hdr); - -        op_ret    = ntoh32 (hdr->rsp.op_ret); -        op_errno  = ntoh32 (hdr->rsp.op_errno); - -        if (op_ret >= 0) { -                remote_fd = ntoh64 (rsp->fd); -        } - -        if (op_ret >= 0) { -                fdctx = GF_CALLOC (1, sizeof (*fdctx), -                                   gf_client_mt_client_fd_ctx_t); -                if (!fdctx) { -                        op_ret = -1; -                        op_errno = ENOMEM; -                        goto unwind_out; -                } - -                inode_ctx_get2 (fd->inode, frame->this, &ino, &gen); - -                fdctx->remote_fd = remote_fd; -                fdctx->inode     = inode_ref (fd->inode); -                fdctx->ino       = ino; -                fdctx->gen       = gen; - -                fdctx->is_dir    = 1; - -                INIT_LIST_HEAD (&fdctx->sfd_pos); - -                this_fd_set_ctx (fd, frame->this, &local->loc, fdctx); - -                pthread_mutex_lock (&conf->mutex); -                { -                        list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); -                } -                pthread_mutex_unlock (&conf->mutex); -        } -unwind_out: -        STACK_UNWIND (frame, op_ret, op_errno, fd); - -        client_local_wipe (local); - -        return 0; -} - -/* - * client_rmdir_cbk - rmdir callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_rmdir_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                  struct iobuf *iobuf) -{ -        gf_fop_rmdir_rsp_t *rsp = NULL; -        int32_t             op_ret = 0; -        int32_t             op_errno = 0; -        struct iatt         preparent = {0,}; -        struct iatt         postparent = {0,}; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret == 0) { -                gf_stat_to_iatt (&rsp->preparent, &preparent); -                gf_stat_to_iatt (&rsp->postparent, &postparent); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &preparent, &postparent); - -        return 0; -} - -/* - * client_access_cbk - access callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_access_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                   struct iobuf *iobuf) -{ -        gf_fop_access_rsp_t *rsp = NULL; -        int32_t              op_ret = 0; -        int32_t              op_errno = 0; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        STACK_UNWIND (frame, op_ret, op_errno); - -        return 0; -} - -/* - * client_lookup_cbk - lookup callback for client protocol - * - * @frame: call frame - * @args: arguments dictionary - * - * not for external reference - */ - -int -client_lookup_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                   struct iobuf *iobuf) -{ -        struct iatt          stbuf = {0, }; -        struct iatt          postparent = {0, }; -        inode_t             *inode = NULL; -        dict_t              *xattr = NULL; -        gf_fop_lookup_rsp_t *rsp = NULL; -        int32_t              op_ret = 0; -        int32_t              op_errno = 0; -        size_t               dict_len = 0; -        char                *dictbuf = NULL; -        int32_t              ret = -1; -        int32_t              gf_errno = 0; -        client_local_t      *local = NULL; -        ino_t                oldino = 0; -        uint64_t             oldgen = 0; - -        local = frame->local; -        inode = local->loc.inode; -        frame->local = NULL; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); - -        gf_stat_to_iatt (&rsp->postparent, &postparent); - -        if (op_ret == 0) { -                op_ret = -1; -                gf_stat_to_iatt (&rsp->stat, &stbuf); - -                ret = inode_ctx_get2 (inode, frame->this, &oldino, &oldgen); -                if (oldino != stbuf.ia_ino || oldgen != stbuf.ia_gen) { -                        if (oldino) { -                                gf_log (frame->this->name, GF_LOG_DEBUG, -                                        "LOOKUP %"PRId64"/%s (%s): " -                                        "inode number changed from " -                                        "{%"PRId64",%"PRId64"} to {%"PRId64",%"PRId64"}", -                                        local->loc.parent ? -                                        local->loc.parent->ino : (uint64_t) 0, -                                        local->loc.name, -                                        local->loc.path, -                                        oldgen, oldino, stbuf.ia_gen, stbuf.ia_ino); -                                op_errno = ESTALE; -                                goto fail; -                        } - -                        ret = inode_ctx_put2 (inode, frame->this, -                                              stbuf.ia_ino, stbuf.ia_gen); -                        if (ret < 0) { -                                gf_log (frame->this->name, GF_LOG_DEBUG, -                                        "LOOKUP %"PRId64"/%s (%s) : " -                                        "failed to set remote inode " -                                        "number to inode ctx", -                                        local->loc.parent ? -                                        local->loc.parent->ino : (uint64_t) 0, -                                        local->loc.name, -                                        local->loc.path); -                                op_errno = EINVAL; -                                goto fail; -                        } -                } - -                dict_len = ntoh32 (rsp->dict_len); - -                if (dict_len > 0) { -                        dictbuf = memdup (rsp->dict, dict_len); -                        GF_VALIDATE_OR_GOTO (frame->this->name, dictbuf, fail); - -                        xattr = dict_new(); -                        GF_VALIDATE_OR_GOTO (frame->this->name, xattr, fail); - -                        ret = dict_unserialize (dictbuf, dict_len, &xattr); -                        if (ret < 0) { -                                gf_log (frame->this->name, GF_LOG_DEBUG, -                                        "%s (%"PRId64"): failed to " -                                        "unserialize dictionary", -                                        local->loc.path, inode->ino); -                                goto fail; -                        } else { -                                xattr->extra_free = dictbuf; -                                dictbuf = NULL; -                        } -                } -                op_ret = 0; -        } -        gf_errno = ntoh32 (hdr->rsp.op_errno); -        op_errno = gf_error_to_errno (gf_errno); - -fail: -        STACK_UNWIND (frame, op_ret, op_errno, inode, &stbuf, xattr, -                      &postparent); - -        client_local_wipe (local); - -        if (dictbuf) -                GF_FREE (dictbuf); - -        if (xattr) -                dict_unref (xattr); - -        return 0; -} - -static int32_t -client_setattr_cbk (call_frame_t *frame,gf_hdr_common_t *hdr, size_t hdrlen, -                    struct iobuf *iobuf) -{ -        struct iatt           statpre = {0, }; -        struct iatt           statpost = {0, }; -        gf_fop_setattr_rsp_t *rsp = NULL; -        int32_t               op_ret = 0; -        int32_t               op_errno = 0; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret == 0) { -                gf_stat_to_iatt (&rsp->statpre, &statpre); -                gf_stat_to_iatt (&rsp->statpost, &statpost); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &statpre, &statpost); - -        return 0; -} - -static int32_t -client_fsetattr_cbk (call_frame_t *frame,gf_hdr_common_t *hdr, size_t hdrlen, -                     struct iobuf *iobuf) -{ -        struct iatt           statpre = {0, }; -        struct iatt           statpost = {0, }; -        gf_fop_setattr_rsp_t *rsp = NULL; -        int32_t               op_ret = 0; -        int32_t               op_errno = 0; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret == 0) { -                gf_stat_to_iatt (&rsp->statpre, &statpre); -                gf_stat_to_iatt (&rsp->statpost, &statpost); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &statpre, &statpost); - -        return 0; -} - - -int -gf_free_direntry (dir_entry_t *head) -{ -        dir_entry_t *prev = NULL; -        dir_entry_t *trav = NULL; - -        prev = head; -        GF_VALIDATE_OR_GOTO ("client-protocol", prev, fail); - -        trav = head->next; -        while (trav) { -                prev->next = trav->next; -                GF_FREE (trav->name); -                if (IA_ISLNK (trav->buf.ia_type)) -                        GF_FREE (trav->link); -                GF_FREE (trav); -                trav = prev->next; -        } -        GF_FREE (head); -fail: -        return 0; -} - -/* - * client_statfs_cbk - statfs callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_statfs_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                   struct iobuf *iobuf) -{ -        struct statvfs       stbuf = {0, }; -        gf_fop_statfs_rsp_t *rsp = NULL; -        int32_t              op_ret = 0; -        int32_t              op_errno = 0; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret == 0) { -                gf_statfs_to_statfs (&rsp->statfs, &stbuf); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - -        return 0; -} - -/* - * client_fsyncdir_cbk - fsyncdir callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_fsyncdir_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                     struct iobuf *iobuf) -{ -        int32_t op_ret = 0; -        int32_t op_errno = 0; - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        STACK_UNWIND (frame, op_ret, op_errno); - -        return 0; -} - -/* - * client_setxattr_cbk - setxattr callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_setxattr_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                     struct iobuf *iobuf) -{ -        gf_fop_setxattr_rsp_t *rsp = NULL; -        int32_t                op_ret = 0; -        int32_t                op_errno = 0; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        STACK_UNWIND (frame, op_ret, op_errno); - -        return 0; -} - -/* - * client_getxattr_cbk - getxattr callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_getxattr_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                     struct iobuf *iobuf) -{ -        gf_fop_getxattr_rsp_t *rsp = NULL; -        int32_t                op_ret   = 0; -        int32_t                gf_errno = 0; -        int32_t                op_errno = 0; -        int32_t                dict_len = 0; -        dict_t                *dict = NULL; -        int32_t                ret = -1; -        char                  *dictbuf = NULL; -        client_local_t        *local = NULL; - -        local = frame->local; -        frame->local = NULL; - -        rsp = gf_param (hdr); -        GF_VALIDATE_OR_GOTO (frame->this->name, rsp, fail); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); - -        if (op_ret >= 0) { -                op_ret = -1; -                dict_len = ntoh32 (rsp->dict_len); - -                if (dict_len > 0) { -                        dictbuf = memdup (rsp->dict, dict_len); -                        GF_VALIDATE_OR_GOTO (frame->this->name, dictbuf, fail); - -                        dict = dict_new(); -                        GF_VALIDATE_OR_GOTO (frame->this->name, dict, fail); - -                        ret = dict_unserialize (dictbuf, dict_len, &dict); -                        if (ret < 0) { -                                gf_log (frame->this->name, GF_LOG_DEBUG, -                                        "%s (%"PRId64"): failed to " -                                        "unserialize xattr dictionary", -                                        local->loc.path, -                                        local->loc.inode->ino); -                                goto fail; -                        } else { -                                dict->extra_free = dictbuf; -                                dictbuf = NULL; -                        } -                } -                op_ret = 0; -        } -        gf_errno = ntoh32 (hdr->rsp.op_errno); -        op_errno = gf_error_to_errno (gf_errno); -fail: -        STACK_UNWIND (frame, op_ret, op_errno, dict); - -        client_local_wipe (local); - -        if (dictbuf) -                GF_FREE (dictbuf); - -        if (dict) -                dict_unref (dict); - -        return 0; -} - -/* - * client_removexattr_cbk - removexattr callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_removexattr_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, -                        size_t hdrlen, struct iobuf *iobuf) -{ -        int32_t op_ret = 0; -        int32_t op_errno = 0; - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        STACK_UNWIND (frame, op_ret, op_errno); - -        return 0; -} - -/* - * client_lk_cbk - lk callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_lk_common_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                      struct iobuf *iobuf) -{ -        struct gf_flock     lock = {0,}; -        gf_fop_lk_rsp_t *rsp = NULL; -        int32_t          op_ret = 0; -        int32_t          op_errno = 0; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret >= 0) { -                gf_flock_to_flock (&rsp->flock, &lock); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &lock); -        return 0; -} - -/* - * client_gf_file_lk_cbk - gf_file_lk callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_inodelk_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                    struct iobuf *iobuf) -{ -        gf_fop_inodelk_rsp_t *rsp = NULL; -        int32_t               op_ret = 0; -        int32_t               op_errno = 0; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        STACK_UNWIND (frame, op_ret, op_errno); -        return 0; -} - - -int -client_finodelk_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                     struct iobuf *iobuf) -{ -        gf_fop_finodelk_rsp_t *rsp = NULL; -        int32_t                op_ret = 0; -        int32_t                op_errno = 0; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        STACK_UNWIND (frame, op_ret, op_errno); -        return 0; -} - -/* - * client_entrylk_cbk - entrylk callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_entrylk_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                    struct iobuf *iobuf) -{ -        gf_fop_entrylk_rsp_t *rsp = NULL; -        int32_t               op_ret = 0; -        int32_t               op_errno = 0; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        STACK_UNWIND (frame, op_ret, op_errno); -        return 0; -} - -int -client_fentrylk_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                     struct iobuf *iobuf) -{ -        gf_fop_fentrylk_rsp_t *rsp = NULL; -        int32_t                op_ret = 0; -        int32_t                op_errno = 0; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        STACK_UNWIND (frame, op_ret, op_errno); -        return 0; -} - - - -/* - * client_getspec - getspec function for client protocol - * @frame: call frame - * @this: client protocol xlator structure - * @flag: - * - * external reference through client_protocol_xlator->fops->getspec - */ - -int -client_getspec (call_frame_t *frame, xlator_t *this, const char *key, -                int32_t flag) -{ -        gf_hdr_common_t      *hdr = NULL; -        gf_mop_getspec_req_t *req = NULL; -        size_t                hdrlen = -1; -        int                   keylen = 0; -        int                   ret = -1; - -        if (key) -                keylen = STRLEN_0 (key); - -        hdrlen = gf_hdr_len (req, keylen); -        hdr    = gf_hdr_new (req, keylen); -        GF_VALIDATE_OR_GOTO (this->name, hdr, unwind); - -        req        = gf_param (hdr); -        req->flags = hton32 (flag); -        req->keylen = hton32 (keylen); -        if (keylen) -                strcpy (req->key, key); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_MOP_REQUEST, GF_MOP_GETSPEC, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -unwind: -        if (hdr) -                GF_FREE (hdr); -        STACK_UNWIND (frame, -1, EINVAL, NULL); -        return 0; -} - -/* - * client_getspec_cbk - getspec callback for client protocol - * - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_getspec_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                    struct iobuf *iobuf) -{ -        gf_mop_getspec_rsp_t  *rsp = NULL; -        char                  *spec_data = NULL; -        int32_t                op_ret = 0; -        int32_t                op_errno = 0; -        int32_t                gf_errno = 0; - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        gf_errno = ntoh32 (hdr->rsp.op_errno); -        op_errno = gf_error_to_errno (gf_errno); -        rsp = gf_param (hdr); - -        if (op_ret >= 0) { -                spec_data = rsp->spec; -        } - -        STACK_UNWIND (frame, op_ret, op_errno, spec_data); -        return 0; -} - - -int -client_rchecksum (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, -                  int32_t len) -{ -        gf_hdr_common_t        *hdr = NULL; -        gf_fop_rchecksum_req_t *req = NULL; -        size_t                  hdrlen = -1; -        int                     ret = -1; - -        int64_t                remote_fd = -1; -        client_fd_ctx_t       *fdctx     = NULL; -        client_conf_t         *conf = NULL; - -        hdrlen = gf_hdr_len (req, 0); -        hdr    = gf_hdr_new (req, 0); -        req    = gf_param (hdr); - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx = this_fd_get_ctx (fd, this); -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx == NULL) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD, 0, NULL); -                return 0; -        } - -        if (fdctx->remote_fd == -1) { -                gf_log (this->name, GF_LOG_TRACE, -                        "(%"PRId64"): failed to get fd ctx. EBADFD", -                        fd->inode->ino); -                STACK_UNWIND (frame, -1, EBADFD, 0, NULL); -                return 0; -        } - -        remote_fd = fdctx->remote_fd; - -        req->fd     = hton64 (remote_fd); -        req->offset = hton64 (offset); -        req->len    = hton32 (len); - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_BULK), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_RCHECKSUM, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; -} - - -int -client_rchecksum_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                      struct iobuf *iobuf) -{ -        gf_fop_rchecksum_rsp_t *rsp = NULL; - -        int32_t                op_ret = 0; -        int32_t                op_errno = 0; -        int32_t                gf_errno = 0; -        uint32_t               weak_checksum = 0; -        unsigned char         *strong_checksum = NULL; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        gf_errno = ntoh32 (hdr->rsp.op_errno); -        op_errno = gf_error_to_errno (gf_errno); - -        if (op_ret >= 0) { -                weak_checksum   = rsp->weak_checksum; -                strong_checksum = rsp->strong_checksum; -        } - -        STACK_UNWIND (frame, op_ret, op_errno, weak_checksum, strong_checksum); - -        return 0; -} - - -/* - * client_setspec_cbk - setspec callback for client protocol - * @frame: call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_setspec_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                    struct iobuf *iobuf) -{ -        int32_t op_ret = 0; -        int32_t op_errno = 0; - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        STACK_UNWIND (frame, op_ret, op_errno); - -        return 0; -} - - - -int -protocol_client_reopendir_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, -                               size_t hdrlen, struct iobuf *iobuf) -{ -        int32_t              op_ret = -1; -        int32_t              op_errno = ENOTCONN; -        int64_t              remote_fd = -1; -        gf_fop_open_rsp_t   *rsp = NULL; -        client_local_t      *local = NULL; -        client_conf_t       *conf = NULL; -        client_fd_ctx_t     *fdctx = NULL; - - -        local = frame->local; frame->local = NULL; -        conf  = frame->this->private; -        fdctx = local->fdctx; - -        rsp = gf_param (hdr); - -        op_ret    = ntoh32 (hdr->rsp.op_ret); -        op_errno  = ntoh32 (hdr->rsp.op_errno); - -        if (op_ret >= 0) -                remote_fd = ntoh64 (rsp->fd); - -        gf_log (frame->this->name, GF_LOG_DEBUG, -                "reopendir on %s returned %d (%"PRId64")", -                local->loc.path, op_ret, remote_fd); - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx->remote_fd = remote_fd; - -                if (!fdctx->released) { -                        list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); -                        fdctx = NULL; -                } -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx) -                client_fdctx_destroy (frame->this, fdctx); - -        STACK_DESTROY (frame->root); - -        client_local_wipe (local); - -        return 0; -} - - - -int -protocol_client_reopendir (xlator_t *this, client_fd_ctx_t *fdctx) -{ -        int                    ret = -1; -        gf_hdr_common_t       *hdr = NULL; -        size_t                 hdrlen = 0; -        gf_fop_opendir_req_t  *req = NULL; -        size_t                 pathlen = 0; -        client_local_t        *local = NULL; -        inode_t               *inode = NULL; -        char                  *path = NULL; -        call_frame_t          *frame = NULL; - -        inode = fdctx->inode; - -        ret = inode_path (inode, NULL, &path); -        if (ret < 0) { -                goto out; -        } - -        local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); -        if (!local) { -                goto out; -        } - -        local->fdctx = fdctx; -        local->op = protocol_client_reopendir_cbk; -        local->loc.path = path; path = NULL; - -        frame = create_frame (this, this->ctx->pool); -        if (!frame) { -                goto out; -        } - -        pathlen = STRLEN_0 (local->loc.path); - -        hdrlen = gf_hdr_len (req, pathlen); -        hdr    = gf_hdr_new (req, pathlen); - -        req    = gf_param (hdr); - -        req->ino   = hton64 (fdctx->ino); -        req->gen   = hton64 (fdctx->gen); - -        strcpy (req->path, local->loc.path); - -        gf_log (frame->this->name, GF_LOG_DEBUG, -                "attempting reopendir on %s", local->loc.path); - -        frame->local = local; local = NULL; - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_OPENDIR, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; - -out: -        if (frame) -                STACK_DESTROY (frame->root); - -        if (local) -                client_local_wipe (local); - -        if (path) -                GF_FREE (path); - -        return 0; -} - - -int -protocol_client_reopen_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, -                            size_t hdrlen, struct iobuf *iobuf) -{ -        int32_t              op_ret = -1; -        int32_t              op_errno = ENOTCONN; -        int64_t              remote_fd = -1; -        gf_fop_open_rsp_t   *rsp = NULL; -        client_local_t      *local = NULL; -        client_conf_t       *conf = NULL; -        client_fd_ctx_t     *fdctx = NULL; - - -        local = frame->local; frame->local = NULL; -        conf  = frame->this->private; -        fdctx = local->fdctx; - -        rsp = gf_param (hdr); - -        op_ret    = ntoh32 (hdr->rsp.op_ret); -        op_errno  = ntoh32 (hdr->rsp.op_errno); - -        if (op_ret >= 0) -                remote_fd = ntoh64 (rsp->fd); - -        gf_log (frame->this->name, GF_LOG_DEBUG, -                "reopen on %s returned %d (%"PRId64")", -                local->loc.path, op_ret, remote_fd); - -        pthread_mutex_lock (&conf->mutex); -        { -                fdctx->remote_fd = remote_fd; - -                if (!fdctx->released) { -                        list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); -                        fdctx = NULL; -                } -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (fdctx) -                client_fdctx_destroy (frame->this, fdctx); - -        STACK_DESTROY (frame->root); - -        client_local_wipe (local); - -        return 0; -} - - -int -protocol_client_reopen (xlator_t *this, client_fd_ctx_t *fdctx) -{ -        int                 ret = -1; -        gf_hdr_common_t    *hdr = NULL; -        size_t              hdrlen = 0; -        gf_fop_open_req_t  *req = NULL; -        size_t              pathlen = 0; -        client_local_t     *local = NULL; -        inode_t            *inode = NULL; -        char               *path = NULL; -        call_frame_t       *frame = NULL; - -        inode = fdctx->inode; - -        ret = inode_path (inode, NULL, &path); -        if (ret < 0) { -                goto out; -        } - -        local = GF_CALLOC (1, sizeof (*local), gf_client_mt_client_local_t); -        if (!local) { -                goto out; -        } - -        local->fdctx = fdctx; -        local->op = protocol_client_reopen_cbk; -        local->loc.path = path; path = NULL; - -        frame = create_frame (this, this->ctx->pool); -        if (!frame) { -                goto out; -        } - -        pathlen = STRLEN_0 (local->loc.path); - -        hdrlen = gf_hdr_len (req, pathlen); -        hdr    = gf_hdr_new (req, pathlen); - -        req    = gf_param (hdr); - -        req->ino   = hton64 (fdctx->ino); -        req->gen   = hton64 (fdctx->gen); -        req->flags = hton32 (gf_flags_from_flags (fdctx->flags)); -        req->wbflags = hton32 (fdctx->wbflags); -        strcpy (req->path, local->loc.path); - -        gf_log (frame->this->name, GF_LOG_DEBUG, -                "attempting reopen on %s", local->loc.path); - -        frame->local = local; local = NULL; - -        ret = protocol_client_xfer (frame, this, -                                    CLIENT_CHANNEL (this, CHANNEL_LOWLAT), -                                    GF_OP_TYPE_FOP_REQUEST, GF_PROTO_FOP_OPEN, -                                    hdr, hdrlen, NULL, 0, NULL); - -        return ret; - -out: -        if (frame) -                STACK_DESTROY (frame->root); - -        if (local) -                client_local_wipe (local); - -        if (path) -                GF_FREE (path); - -        return 0; - -} - - -int -protocol_client_post_handshake (call_frame_t *frame, xlator_t *this) -{ -        client_conf_t            *conf = NULL; -        client_fd_ctx_t          *tmp = NULL; -        client_fd_ctx_t          *fdctx = NULL; -        xlator_list_t            *parent = NULL; -        struct list_head          reopen_head; - -        conf = this->private; -        INIT_LIST_HEAD (&reopen_head); - -        pthread_mutex_lock (&conf->mutex); -        { -                list_for_each_entry_safe (fdctx, tmp, &conf->saved_fds, -                                          sfd_pos) { -                        if (fdctx->remote_fd != -1) -                                continue; - -                        list_del (&fdctx->sfd_pos); -                        list_add_tail (&fdctx->sfd_pos, &reopen_head); -                } -        } -        pthread_mutex_unlock (&conf->mutex); - -        list_for_each_entry_safe (fdctx, tmp, &reopen_head, sfd_pos) { -                list_del_init (&fdctx->sfd_pos); - -                if (fdctx->is_dir) -                        protocol_client_reopendir (this, fdctx); -                else -                        protocol_client_reopen (this, fdctx); -        } - -        parent = this->parents; - -        while (parent) { -                xlator_notify (parent->xlator, GF_EVENT_CHILD_UP, -                               this); -                parent = parent->next; -        } - -        return 0; -} - -/* - * client_setvolume_cbk - setvolume callback for client protocol - * @frame:  call frame - * @args: argument dictionary - * - * not for external reference - */ - -int -client_setvolume_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                      struct iobuf *iobuf) -{ -        client_conf_t          *conf = NULL; -        gf_mop_setvolume_rsp_t *rsp = NULL; -        client_connection_t    *conn = NULL; -        glusterfs_ctx_t        *ctx = NULL; -        xlator_t               *this = NULL; -        xlator_list_t          *parent = NULL; -        transport_t            *trans = NULL; -        dict_t                 *reply = NULL; -        char                   *remote_subvol = NULL; -        char                   *remote_error = NULL; -        char                   *process_uuid = NULL; -        int32_t                 ret = -1; -        int32_t                 op_ret   = -1; -        int32_t                 op_errno = EINVAL; -        int32_t                 dict_len = 0; -        transport_t            *peer_trans = NULL; -        uint64_t                peer_trans_int = 0; - -        trans = frame->local; frame->local = NULL; -        this  = frame->this; -        conn  = trans->xl_private; -        conf  = this->private; - -        rsp = gf_param (hdr); - -        op_ret   = ntoh32 (hdr->rsp.op_ret); -        op_errno = gf_error_to_errno (ntoh32 (hdr->rsp.op_errno)); - -        if (op_ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "setvolume failed (%s)", -                        strerror (op_errno)); -                goto out; -        } - -        reply = dict_new (); -        GF_VALIDATE_OR_GOTO (this->name, reply, out); - -        dict_len = ntoh32 (rsp->dict_len); -        ret = dict_unserialize (rsp->buf, dict_len, &reply); -        if (ret < 0) { -                gf_log (frame->this->name, GF_LOG_DEBUG, -                        "failed to unserialize buffer(%p) to dictionary", -                        rsp->buf); -                goto out; -        } - -        ret = dict_get_str (reply, "ERROR", &remote_error); -        if (ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "failed to get ERROR string from reply dictionary"); -        } - -        ret = dict_get_str (reply, "process-uuid", &process_uuid); -        if (ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "failed to get 'process-uuid' from reply dictionary"); -        } - -        if (op_ret < 0) { -                gf_log (trans->xl->name, GF_LOG_ERROR, -                        "SETVOLUME on remote-host failed: %s", -                        remote_error ? remote_error : strerror (op_errno)); -                errno = op_errno; -                if (op_errno == ESTALE) { -                        parent = trans->xl->parents; -                        while (parent) { -                                xlator_notify (parent->xlator, -                                               GF_EVENT_VOLFILE_MODIFIED, -                                               trans->xl); -                                parent = parent->next; -                        } -                } - -        } else { -                ret = dict_get_str (this->options, "remote-subvolume", -                                    &remote_subvol); -                if (!remote_subvol) -                        goto out; - -                ctx = this->ctx; - -                if (process_uuid && !strcmp (ctx->process_uuid,process_uuid)) { -                        ret = dict_get_uint64 (reply, "transport-ptr", -                                               &peer_trans_int); - -                        peer_trans = (void *) (long) (peer_trans_int); - -                        gf_log (this->name, GF_LOG_WARNING, -                                "attaching to the local volume '%s'", -                                remote_subvol); - -                        transport_setpeer (trans, peer_trans); - -                } - -                gf_log (trans->xl->name, GF_LOG_INFO, -                        "Connected to %s, attached " -                        "to remote volume '%s'.", -                        trans->peerinfo.identifier, remote_subvol); - -                pthread_mutex_lock (&(conn->lock)); -                { -                        conn->connected = 1; -                } -                pthread_mutex_unlock (&(conn->lock)); - -                protocol_client_post_handshake (frame, frame->this); -        } - -        conf->connecting = 0; -out: - -        if (-1 == op_ret) { -                /* Let the connection/re-connection happen in -                 * background, for now, don't hang here, -                 * tell the parents that i am all ok.. -                 */ -                parent = trans->xl->parents; -                while (parent) { -                        xlator_notify (parent->xlator, -                                       GF_EVENT_CHILD_CONNECTING, trans->xl); -                        parent = parent->next; -                } -                conf->connecting= 1; -        } - -        STACK_DESTROY (frame->root); - -        if (reply) -                dict_unref (reply); - -        return op_ret; -} - -/* - * client_enosys_cbk - - * @frame: call frame - * - * not for external reference - */ - -int -client_enosys_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                   struct iobuf *iobuf) -{ -        STACK_DESTROY (frame->root); -        return 0; -} - - -void -client_protocol_reconnect (void *trans_ptr) -{ -        transport_t         *trans = NULL; -        client_connection_t *conn = NULL; -        struct timeval       tv = {0, 0}; -        int32_t              ret = 0; - -        trans = trans_ptr; -        conn  = trans->xl_private; -        pthread_mutex_lock (&conn->lock); -        { -                if (conn->reconnect) -                        gf_timer_call_cancel (trans->xl->ctx, -                                              conn->reconnect); -                conn->reconnect = 0; - -                if (conn->connected == 0) { -                        tv.tv_sec = 10; - -                        gf_log (trans->xl->name, GF_LOG_TRACE, -                                "attempting reconnect"); -                        ret = transport_connect (trans); - -                        conn->reconnect = -                                gf_timer_call_after (trans->xl->ctx, tv, -                                                     client_protocol_reconnect, -                                                     trans); -                } else { -                        gf_log (trans->xl->name, GF_LOG_TRACE, -                                "breaking reconnect chain"); -                } -        } -        pthread_mutex_unlock (&conn->lock); - -        if (ret == -1 && errno != EINPROGRESS) { -                default_notify (trans->xl, GF_EVENT_CHILD_DOWN, NULL); -        } -} - -int -protocol_client_mark_fd_bad (xlator_t *this) -{ -        client_conf_t            *conf = NULL; -        client_fd_ctx_t          *tmp = NULL; -        client_fd_ctx_t          *fdctx = NULL; - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                list_for_each_entry_safe (fdctx, tmp, &conf->saved_fds, -                                          sfd_pos) { -                        fdctx->remote_fd = -1; -                } -        } -        pthread_mutex_unlock (&conf->mutex); - -        return 0; -} - -/* - * client_protocol_cleanup - cleanup function - * @trans: transport object - * - */ - -int -protocol_client_cleanup (transport_t *trans) -{ -        client_connection_t    *conn = NULL; -        struct saved_frames    *saved_frames = NULL; - -        conn = trans->xl_private; - -        gf_log (trans->xl->name, GF_LOG_TRACE, -                "cleaning up state in transport object %p", trans); - -        pthread_mutex_lock (&conn->lock); -        { -                saved_frames = conn->saved_frames; -                conn->saved_frames = gf_client_saved_frames_new (); - -                /* bailout logic cleanup */ -                if (conn->timer) { -                        gf_timer_call_cancel (trans->xl->ctx, conn->timer); -                        conn->timer = NULL; -                } - -                if (conn->reconnect == NULL) { -                        /* :O This part is empty.. any thing missing? */ -                } -        } -        pthread_mutex_unlock (&conn->lock); - -        gf_client_saved_frames_destroy (trans->xl, saved_frames, -                                        gf_fops, gf_mops, gf_cbks); - -        return 0; -} - - -/* cbk callbacks */ -int -client_releasedir_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, -                       size_t hdrlen, struct iobuf *iobuf) -{ -        STACK_DESTROY (frame->root); -        return 0; -} - - -int -client_release_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                    struct iobuf *iobuf) -{ -        STACK_DESTROY (frame->root); -        return 0; -} - - -int -client_forget_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                   struct iobuf *iobuf) -{ -        gf_log ("", GF_LOG_CRITICAL, "fop not implemented"); -        return 0; -} - - -int -client_log_cbk (call_frame_t *frame, gf_hdr_common_t *hdr, size_t hdrlen, -                struct iobuf *iobuf) -{ -        gf_log ("", GF_LOG_CRITICAL, "fop not implemented"); -        return 0; -} - - -static gf_op_t gf_fops[] = { -        [GF_PROTO_FOP_STAT]           =  client_stat_cbk, -        [GF_PROTO_FOP_READLINK]       =  client_readlink_cbk, -        [GF_PROTO_FOP_MKNOD]          =  client_mknod_cbk, -        [GF_PROTO_FOP_MKDIR]          =  client_mkdir_cbk, -        [GF_PROTO_FOP_UNLINK]         =  client_unlink_cbk, -        [GF_PROTO_FOP_RMDIR]          =  client_rmdir_cbk, -        [GF_PROTO_FOP_SYMLINK]        =  client_symlink_cbk, -        [GF_PROTO_FOP_RENAME]         =  client_rename_cbk, -        [GF_PROTO_FOP_LINK]           =  client_link_cbk, -        [GF_PROTO_FOP_TRUNCATE]       =  client_truncate_cbk, -        [GF_PROTO_FOP_OPEN]           =  client_open_cbk, -        [GF_PROTO_FOP_READ]           =  client_readv_cbk, -        [GF_PROTO_FOP_WRITE]          =  client_write_cbk, -        [GF_PROTO_FOP_STATFS]         =  client_statfs_cbk, -        [GF_PROTO_FOP_FLUSH]          =  client_flush_cbk, -        [GF_PROTO_FOP_FSYNC]          =  client_fsync_cbk, -        [GF_PROTO_FOP_SETXATTR]       =  client_setxattr_cbk, -        [GF_PROTO_FOP_GETXATTR]       =  client_getxattr_cbk, -        [GF_PROTO_FOP_REMOVEXATTR]    =  client_removexattr_cbk, -        [GF_PROTO_FOP_OPENDIR]        =  client_opendir_cbk, -        [GF_PROTO_FOP_FSYNCDIR]       =  client_fsyncdir_cbk, -        [GF_PROTO_FOP_ACCESS]         =  client_access_cbk, -        [GF_PROTO_FOP_CREATE]         =  client_create_cbk, -        [GF_PROTO_FOP_FTRUNCATE]      =  client_ftruncate_cbk, -        [GF_PROTO_FOP_FSTAT]          =  client_fstat_cbk, -        [GF_PROTO_FOP_LK]             =  client_lk_common_cbk, -        [GF_PROTO_FOP_LOOKUP]         =  client_lookup_cbk, -        [GF_PROTO_FOP_READDIR]        =  client_readdir_cbk, -        [GF_PROTO_FOP_READDIRP]       =  client_readdirp_cbk, -        [GF_PROTO_FOP_INODELK]        =  client_inodelk_cbk, -        [GF_PROTO_FOP_FINODELK]       =  client_finodelk_cbk, -        [GF_PROTO_FOP_ENTRYLK]        =  client_entrylk_cbk, -        [GF_PROTO_FOP_FENTRYLK]       =  client_fentrylk_cbk, -        [GF_PROTO_FOP_RCHECKSUM]      =  client_rchecksum_cbk, -        [GF_PROTO_FOP_XATTROP]        =  client_xattrop_cbk, -        [GF_PROTO_FOP_FXATTROP]       =  client_fxattrop_cbk, -        [GF_PROTO_FOP_SETATTR]        =  client_setattr_cbk, -        [GF_PROTO_FOP_FSETATTR]       =  client_fsetattr_cbk -}; - -static gf_op_t gf_mops[] = { -        [GF_MOP_SETVOLUME]        =  client_setvolume_cbk, -        [GF_MOP_GETVOLUME]        =  client_enosys_cbk, -        [GF_MOP_SETSPEC]          =  client_setspec_cbk, -        [GF_MOP_GETSPEC]          =  client_getspec_cbk, -        [GF_MOP_PING]             =  client_ping_cbk, -        [GF_MOP_LOG]              =  client_log_cbk -}; - -static gf_op_t gf_cbks[] = { -        [GF_CBK_FORGET]           = client_forget_cbk, -        [GF_CBK_RELEASE]          = client_release_cbk, -        [GF_CBK_RELEASEDIR]       = client_releasedir_cbk -}; - -/* - * client_protocol_interpret - protocol interpreter - * @trans: transport object - * @blk: data block - * - */ -int -protocol_client_interpret (xlator_t *this, transport_t *trans, -                           char *hdr_p, size_t hdrlen, struct iobuf *iobuf) -{ -        int                  ret = -1; -        call_frame_t        *frame = NULL; -        gf_hdr_common_t     *hdr = NULL; -        uint64_t             callid = 0; -        int                  type = -1; -        int                  op = -1; -        client_connection_t *conn = NULL; - -        conn  = trans->xl_private; - -        hdr  = (gf_hdr_common_t *)hdr_p; - -        type   = ntoh32 (hdr->type); -        op     = ntoh32 (hdr->op); -        callid = ntoh64 (hdr->callid); - -        frame  = lookup_frame (trans, op, type, callid); -        if (frame == NULL) { -                gf_log (this->name, GF_LOG_WARNING, -                        "no frame for callid=%"PRId64" type=%d op=%d", -                        callid, type, op); -                return 0; -        } - -        switch (type) { -        case GF_OP_TYPE_FOP_REPLY: -                if ((op > GF_PROTO_FOP_MAXVALUE) || -                    (op < 0)) { -                        gf_log (trans->xl->name, GF_LOG_WARNING, -                                "invalid fop '%d'", op); -                } else { -                        ret = gf_fops[op] (frame, hdr, hdrlen, iobuf); -                } -                break; -        case GF_OP_TYPE_MOP_REPLY: -                if ((op > GF_MOP_MAXVALUE) || -                    (op < 0)) { -                        gf_log (trans->xl->name, GF_LOG_WARNING, -                                "invalid fop '%d'", op); -                } else { -                        ret = gf_mops[op] (frame, hdr, hdrlen, iobuf); -                } -                break; -        case GF_OP_TYPE_CBK_REPLY: -                if ((op > GF_CBK_MAXVALUE) || -                    (op < 0)) { -                        gf_log (trans->xl->name, GF_LOG_WARNING, -                                "invalid cbk '%d'", op); -                } else { -                        ret = gf_cbks[op] (frame, hdr, hdrlen, iobuf); -                } -                break; -        default: -                gf_log (trans->xl->name, GF_LOG_DEBUG, -                        "invalid packet type: %d", type); -                break; -        } - -        return ret; -} - -int32_t -mem_acct_init (xlator_t *this) -{ -        int     ret       = -1; - -        if (!this) -                return ret; - -        ret = xlator_mem_acct_init (this, gf_client_mt_end + 1); - -        if (ret != 0) { -                gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" -                                "failed"); -                return ret; -        } - -        return ret; -} - - -/* - * init - initiliazation function. called during loading of client protocol - * @this: - * - */ - -int -init (xlator_t *this) -{ -        transport_t               *trans = NULL; -        client_conf_t             *conf = NULL; -        client_connection_t       *conn = NULL; -        int32_t                    frame_timeout = 0; -        int32_t                    ping_timeout = 0; -        data_t                    *remote_subvolume = NULL; -        int32_t                    ret = -1; -        int                        i = 0; - -        if (this->children) { -                gf_log (this->name, GF_LOG_ERROR, -                        "FATAL: client protocol translator cannot have any " -                        "subvolumes"); -                goto out; -        } - -        if (!this->parents) { -                gf_log (this->name, GF_LOG_WARNING, -                        "Volume is dangling. "); -        } - -        remote_subvolume = dict_get (this->options, "remote-subvolume"); -        if (remote_subvolume == NULL) { -                gf_log (this->name, GF_LOG_ERROR, -                        "Option 'remote-subvolume' is not specified."); -                goto out; -        } - -        ret = dict_get_int32 (this->options, "frame-timeout", -                              &frame_timeout); -        if (ret >= 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "setting frame-timeout to %d", frame_timeout); -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "defaulting frame-timeout to 30mins"); -                frame_timeout = 1800; -        } - -        ret = dict_get_int32 (this->options, "ping-timeout", -                              &ping_timeout); -        if (ret >= 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "setting ping-timeout to %d", ping_timeout); -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "defaulting ping-timeout to 42"); -                ping_timeout = GF_UNIVERSAL_ANSWER; -        } - -        conf = GF_CALLOC (1, sizeof (client_conf_t), -                          gf_client_mt_client_conf_t); - -        protocol_common_init (); - -        pthread_mutex_init (&conf->mutex, NULL); -        INIT_LIST_HEAD (&conf->saved_fds); - -        this->private = conf; - -        for (i = 0; i < CHANNEL_MAX; i++) { -                if (CHANNEL_LOWLAT == i) { -                        dict_set (this->options, "transport.socket.lowlat", -                                  data_from_dynstr (gf_strdup ("true"))); -                } -                trans = transport_load (this->options, this); -                if (trans == NULL) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "Failed to load transport"); -                        ret = -1; -                        goto out; -                } - -                conn = GF_CALLOC (1, sizeof (*conn), -                                  gf_client_mt_client_connection_t); - -                conn->saved_frames = gf_client_saved_frames_new (); - -                conn->callid = 1; - -                conn->frame_timeout = frame_timeout; -                conn->ping_timeout = ping_timeout; - -                pthread_mutex_init (&conn->lock, NULL); - -                trans->xl_private = conn; -                conf->transport[i] = transport_ref (trans); -        } - -#ifndef GF_DARWIN_HOST_OS -        { -                struct rlimit lim; - -                lim.rlim_cur = 1048576; -                lim.rlim_max = 1048576; - -                ret = setrlimit (RLIMIT_NOFILE, &lim); -                if (ret == -1) { -                        gf_log (this->name, GF_LOG_WARNING, -                                "WARNING: Failed to set 'ulimit -n 1M': %s", -                                strerror(errno)); -                        lim.rlim_cur = 65536; -                        lim.rlim_max = 65536; - -                        ret = setrlimit (RLIMIT_NOFILE, &lim); -                        if (ret == -1) { -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "Failed to set max open fd to 64k: %s", -                                        strerror(errno)); -                        } else { -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "max open fd set to 64k"); -                        } - -                } -        } -#endif -        ret = 0; -out: -        return ret; -} - -/* - * fini - finish function called during unloading of client protocol - * @this: - * - */ -void -fini (xlator_t *this) -{ -        /* TODO: Check if its enough.. how to call transport's fini () */ -        client_conf_t *conf = NULL; - -        conf = this->private; -        this->private = NULL; - -        if (conf) { -                GF_FREE (conf); -        } -        return; -} - - -int -protocol_client_handshake (xlator_t *this, transport_t *trans) -{ -        gf_hdr_common_t        *hdr = NULL; -        gf_mop_setvolume_req_t *req = NULL; -        dict_t                 *options = NULL; -        int32_t                 ret = -1; -        int                     hdrlen = 0; -        int                     dict_len = 0; -        call_frame_t           *fr = NULL; -        char                   *process_uuid_xl; - -        options = this->options; -        ret = dict_set_str (options, "protocol-version", GF_PROTOCOL_VERSION); -        if (ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "failed to set protocol version(%s) in handshake msg", -                        GF_PROTOCOL_VERSION); -        } - -        ret = gf_asprintf (&process_uuid_xl, "%s-%s", this->ctx->process_uuid, -                           this->name); -        if (-1 == ret) { -                gf_log (this->name, GF_LOG_ERROR, -                        "asprintf failed while setting process_uuid"); -                goto fail; -        } -        ret = dict_set_dynstr (options, "process-uuid", -                               process_uuid_xl); -        if (ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "failed to set process-uuid(%s) in handshake msg", -                        process_uuid_xl); -        } - -        if (this->ctx->cmd_args.volfile_server) { -                if (this->ctx->cmd_args.volfile_id) -                        ret = dict_set_str (options, "volfile-key", -                                            this->ctx->cmd_args.volfile_id); -                ret = dict_set_uint32 (options, "volfile-checksum", -                                       this->graph->volfile_checksum); -        } - -        dict_len = dict_serialized_length (options); -        if (dict_len < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "failed to get serialized length of dict(%p)", -                        options); -                ret = dict_len; -                goto fail; -        } - -        hdrlen = gf_hdr_len (req, dict_len); -        hdr    = gf_hdr_new (req, dict_len); -        GF_VALIDATE_OR_GOTO (this->name, hdr, fail); - -        req    = gf_param (hdr); - -        ret = dict_serialize (options, req->buf); -        if (ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "failed to serialize dictionary(%p)", -                        options); -                goto fail; -        } - -        req->dict_len = hton32 (dict_len); -        fr  = create_frame (this, this->ctx->pool); -        GF_VALIDATE_OR_GOTO (this->name, fr, fail); - -        fr->local = trans; -        ret = protocol_client_xfer (fr, this, trans, -                                    GF_OP_TYPE_MOP_REQUEST, GF_MOP_SETVOLUME, -                                    hdr, hdrlen, NULL, 0, NULL); -        return ret; -fail: -        if (hdr) -                GF_FREE (hdr); -        return ret; -} - - -int -protocol_client_pollout (xlator_t *this, transport_t *trans) -{ -        client_conf_t *conf = NULL; - -        conf = trans->xl->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                gettimeofday (&conf->last_sent, NULL); -        } -        pthread_mutex_unlock (&conf->mutex); - -        return 0; -} - - -int -protocol_client_pollin (xlator_t *this, transport_t *trans) -{ -        client_conf_t *conf = NULL; -        int            ret = -1; -        struct iobuf  *iobuf = NULL; -        char          *hdr = NULL; -        size_t         hdrlen = 0; - -        conf = trans->xl->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                gettimeofday (&conf->last_received, NULL); -        } -        pthread_mutex_unlock (&conf->mutex); - -        ret = transport_receive (trans, &hdr, &hdrlen, &iobuf); - -        if (ret == 0) -        { -                ret = protocol_client_interpret (this, trans, hdr, hdrlen, -                                                 iobuf); -        } - -        /* TODO: use mem-pool */ -        GF_FREE (hdr); - -        return ret; -} - -int -client_priv_dump (xlator_t *this) -{ -        client_conf_t   *conf = NULL; -        int             ret   = -1; -        client_fd_ctx_t *tmp = NULL; -        int             i = 0; -        char            key[GF_DUMP_MAX_BUF_LEN]; -        char            key_prefix[GF_DUMP_MAX_BUF_LEN]; - -        if (!this) -                return -1; - -        conf = this->private; -        if (!conf) { -                gf_log (this->name, GF_LOG_WARNING, -                        "conf null in xlator"); -                return -1; -        } - -        ret = pthread_mutex_trylock(&conf->mutex); -        if (ret) { -                gf_log("", GF_LOG_WARNING, "Unable to lock client %s" -                       " errno: %d", this->name, errno); -                return -1; -        } - -        gf_proc_dump_build_key(key_prefix, "xlator.protocol.client", -                               "%s.priv", this->name); - -        gf_proc_dump_add_section(key_prefix); - -        list_for_each_entry(tmp, &conf->saved_fds, sfd_pos) { -                gf_proc_dump_build_key(key, key_prefix, -                                       "fd.%d.remote_fd", ++i); -                gf_proc_dump_write(key, "%d", tmp->remote_fd); -        } - -        gf_proc_dump_build_key(key, key_prefix, "connecting"); -        gf_proc_dump_write(key, "%d", conf->connecting); -        gf_proc_dump_build_key(key, key_prefix, "last_sent"); -        gf_proc_dump_write(key, "%s", ctime(&conf->last_sent.tv_sec)); -        gf_proc_dump_build_key(key, key_prefix, "last_received"); -        gf_proc_dump_write(key, "%s", ctime(&conf->last_received.tv_sec)); - -        pthread_mutex_unlock(&conf->mutex); - -        return 0; - -} - -int32_t -client_inodectx_dump (xlator_t *this, inode_t *inode) -{ -        ino_t   par = 0; -        int     ret = -1; -        char    key[GF_DUMP_MAX_BUF_LEN]; - -        if (!inode) -                return -1; - -        if (!this) -                return -1; - -        ret = inode_ctx_get (inode, this, &par); - -        if (ret != 0) -                return ret; - -        gf_proc_dump_build_key(key, "xlator.protocol.client", -                               "%s.inode.%ld.par", -                               this->name,inode->ino); -        gf_proc_dump_write(key, "%ld", par); - -        return 0; -} - -/* - * client_protocol_notify - notify function for client protocol - * @this: - * @trans: transport object - * @event - * - */ - -int -notify (xlator_t *this, int32_t event, void *data, ...) -{ -        int                  i          = 0; -        int                  ret        = 0; -        int                  child_down = 1; -        int                  was_not_down = 0; -        transport_t         *trans      = NULL; -        client_connection_t *conn       = NULL; -        client_conf_t       *conf       = NULL; -        xlator_list_t       *parent = NULL; - -        conf = this->private; -        trans = data; - -        switch (event) { -        case GF_EVENT_POLLOUT: -        { -                ret = protocol_client_pollout (this, trans); - -                break; -        } -        case GF_EVENT_POLLIN: -        { -                ret = protocol_client_pollin (this, trans); - -                break; -        } -        /* no break for ret check to happen below */ -        case GF_EVENT_POLLERR: -        { -                ret = -1; -                protocol_client_cleanup (trans); - -                if (conf->connecting == 0) { -                        /* Let the connection/re-connection happen in -                         * background, for now, don't hang here, -                         * tell the parents that i am all ok.. -                         */ -                        parent = trans->xl->parents; -                        while (parent) { -                                parent->xlator->notify (parent->xlator, -                                                        GF_EVENT_CHILD_CONNECTING, -                                                        trans->xl); -                                parent = parent->next; -                        } -                        conf->connecting = 1; -                } - -                was_not_down = 0; -                for (i = 0; i < CHANNEL_MAX; i++) { -                        conn = conf->transport[i]->xl_private; -                        if (conn->connected == 1) -                                was_not_down = 1; -                } - -                conn = trans->xl_private; -                if (conn->connected) { -                        conn->connected = 0; -                        if (conn->reconnect == 0) -                                client_protocol_reconnect (trans); -                } - -                child_down = 1; -                for (i = 0; i < CHANNEL_MAX; i++) { -                        trans = conf->transport[i]; -                        conn = trans->xl_private; -                        if (conn->connected == 1) -                                child_down = 0; -                } - -                if (child_down && was_not_down) { -                        gf_log (this->name, GF_LOG_INFO, "disconnected"); - -                        protocol_client_mark_fd_bad (this); - -                        parent = this->parents; -                        while (parent) { -                                xlator_notify (parent->xlator, -                                               GF_EVENT_CHILD_DOWN, this); -                                parent = parent->next; -                        } -                } -        } -        break; - -        case GF_EVENT_PARENT_UP: -        { -                client_conf_t *conf = NULL; -                int            i = 0; -                transport_t   *trans = NULL; - -                conf = this->private; -                for (i = 0; i < CHANNEL_MAX; i++) { -                        trans = conf->transport[i]; -                        if (!trans) { -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "transport init failed"); -                                return -1; -                        } - -                        conn = trans->xl_private; - -                        gf_log (this->name, GF_LOG_DEBUG, -                                "got GF_EVENT_PARENT_UP, attempting connect " -                                "on transport"); - -                        client_protocol_reconnect (trans); -                } -        } -        break; - -        case GF_EVENT_CHILD_UP: -        { -                char *handshake = NULL; - -                ret = dict_get_str (this->options, "disable-handshake", -                                    &handshake); -                gf_log (this->name, GF_LOG_DEBUG, -                        "got GF_EVENT_CHILD_UP"); -                if ((ret < 0) || -                    (strcasecmp (handshake, "on"))) { -                        ret = protocol_client_handshake (this, trans); -                } else { -                        conn = trans->xl_private; -                        conn->connected = 1; -                        ret = default_notify (this, event, trans); -                } - -                if (ret) -                        transport_disconnect (trans); - -        } -        break; - -        default: -                gf_log (this->name, GF_LOG_DEBUG, -                        "got %d, calling default_notify ()", event); - -                default_notify (this, event, data); -                break; -        } - -        return ret; -} - - -struct xlator_fops fops = { -        .stat        = client_stat, -        .readlink    = client_readlink, -        .mknod       = client_mknod, -        .mkdir       = client_mkdir, -        .unlink      = client_unlink, -        .rmdir       = client_rmdir, -        .symlink     = client_symlink, -        .rename      = client_rename, -        .link        = client_link, -        .truncate    = client_truncate, -        .open        = client_open, -        .readv       = client_readv, -        .writev      = client_writev, -        .statfs      = client_statfs, -        .flush       = client_flush, -        .fsync       = client_fsync, -        .setxattr    = client_setxattr, -        .getxattr    = client_getxattr, -        .fsetxattr   = client_fsetxattr, -        .fgetxattr   = client_fgetxattr, -        .removexattr = client_removexattr, -        .opendir     = client_opendir, -        .readdir     = client_readdir, -        .readdirp    = client_readdirp, -        .fsyncdir    = client_fsyncdir, -        .access      = client_access, -        .ftruncate   = client_ftruncate, -        .fstat       = client_fstat, -        .create      = client_create, -        .lk          = client_lk, -        .inodelk     = client_inodelk, -        .finodelk    = client_finodelk, -        .entrylk     = client_entrylk, -        .fentrylk    = client_fentrylk, -        .lookup      = client_lookup, -        .rchecksum   = client_rchecksum, -        .xattrop     = client_xattrop, -        .fxattrop    = client_fxattrop, -        .setattr     = client_setattr, -        .fsetattr    = client_fsetattr, -        .getspec   = client_getspec, -}; - -struct xlator_cbks cbks = { -        .release    = client_release, -        .releasedir = client_releasedir -}; - - -struct xlator_dumpops dumpops = { -        .priv      =  client_priv_dump, -        .inodectx  =  client_inodectx_dump, -}; - -struct volume_options options[] = { -        { .key   = {"username"}, -          .type  = GF_OPTION_TYPE_ANY -        }, -        { .key   = {"password"}, -          .type  = GF_OPTION_TYPE_ANY -        }, -        { .key   = {"transport-type"}, -          .value = {"tcp", "socket", "ib-verbs", "unix", "ib-sdp", -                    "tcp/client", "ib-verbs/client"}, -          .type  = GF_OPTION_TYPE_STR -        }, -        { .key   = {"remote-host"}, -          .type  = GF_OPTION_TYPE_INTERNET_ADDRESS -        }, -        { .key   = {"remote-subvolume"}, -          .type  = GF_OPTION_TYPE_ANY -        }, -        { .key   = {"frame-timeout"}, -          .type  = GF_OPTION_TYPE_TIME, -          .min   = 0, -          .max   = 86400, -        }, -        { .key   = {"ping-timeout"}, -          .type  = GF_OPTION_TYPE_TIME, -          .min   = 1, -          .max   = 1013, -        }, -        { .key   = {NULL} }, -}; diff --git a/xlators/protocol/legacy/client/src/client-protocol.h b/xlators/protocol/legacy/client/src/client-protocol.h deleted file mode 100644 index cd856d50e05..00000000000 --- a/xlators/protocol/legacy/client/src/client-protocol.h +++ /dev/null @@ -1,178 +0,0 @@ -/* -  Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _CLIENT_PROTOCOL_H -#define _CLIENT_PROTOCOL_H - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <arpa/inet.h> -#include "inode.h" -#include "timer.h" -#include "byte-order.h" -#include "saved-frames.h" - -#define CLIENT_PORT_CEILING        1023 - -#define GF_CLIENT_INODE_SELF   0 -#define GF_CLIENT_INODE_PARENT 1 - -#define CLIENT_CONF(this) ((client_conf_t *)(this->private)) - -#define RECEIVE_TIMEOUT(_cprivate,_current)     \ -        ((_cprivate->last_received.tv_sec +     \ -          _cprivate->frame_timeout) <           \ -         _current.tv_sec) - -#define SEND_TIMEOUT(_cprivate,_current)        \ -        ((_cprivate->last_sent.tv_sec +         \ -          _cprivate->frame_timeout) <           \ -         _current.tv_sec) - -enum { -	CHANNEL_BULK = 0, -	CHANNEL_LOWLAT = 1, -	CHANNEL_MAX -}; - -#define CLIENT_CHANNEL client_channel - -struct client_connection; -typedef struct client_connection client_connection_t; - -#include "stack.h" -#include "xlator.h" -#include "transport.h" -#include "protocol.h" - -typedef struct _client_fd_ctx { -        struct list_head  sfd_pos;      /*  Stores the reference to this -                                            fd's position in the saved_fds list. -                                        */ -        int64_t           remote_fd; -        inode_t          *inode; -        uint64_t          ino; -        uint64_t          gen; -        char              is_dir; -        char              released; -        int32_t           flags; -        int32_t           wbflags; -} client_fd_ctx_t; - -struct _client_conf { -	transport_t         *transport[CHANNEL_MAX]; -	struct list_head     saved_fds; -	struct timeval       last_sent; -	struct timeval       last_received; -	pthread_mutex_t      mutex; -        int                  connecting; -}; -typedef struct _client_conf client_conf_t; - -/* This will be stored in transport_t->xl_private */ -struct client_connection { -	pthread_mutex_t      lock; -	uint64_t             callid; -	struct saved_frames *saved_frames; -	int32_t              frame_timeout; -	int32_t              ping_started; -	int32_t              ping_timeout; -	int32_t              transport_activity; -	gf_timer_t          *reconnect; -	char                 connected; -	uint64_t             max_block_size; -	gf_timer_t          *timer; -	gf_timer_t          *ping_timer; -}; - -typedef struct { -	loc_t              loc; -	loc_t              loc2; -	fd_t              *fd; -        gf_op_t            op; -        client_fd_ctx_t   *fdctx; -        uint32_t           flags; -        uint32_t           wbflags; -} client_local_t; - - -static inline void -gf_string_to_stat(char *string, struct iatt *stbuf) -{ -	uint64_t dev        = 0; -	uint64_t ino        = 0; -	uint32_t mode       = 0; -	uint32_t nlink      = 0; -	uint32_t uid        = 0; -	uint32_t gid        = 0; -	uint64_t rdev       = 0; -	uint64_t size       = 0; -	uint32_t blksize    = 0; -	uint64_t blocks     = 0; -	uint32_t atime      = 0; -	uint32_t atime_nsec = 0; -	uint32_t mtime      = 0; -	uint32_t mtime_nsec = 0; -	uint32_t ctime      = 0; -	uint32_t ctime_nsec = 0; - -	sscanf (string, GF_STAT_PRINT_FMT_STR, -		&dev, -		&ino, -		&mode, -		&nlink, -		&uid, -		&gid, -		&rdev, -		&size, -		&blksize, -		&blocks, -		&atime, -		&atime_nsec, -		&mtime, -		&mtime_nsec, -		&ctime, -		&ctime_nsec); - -	stbuf->ia_gen   = dev; -	stbuf->ia_ino   = ino; -	stbuf->ia_prot  = ia_prot_from_st_mode (mode); -        stbuf->ia_type  = ia_type_from_st_mode (mode); -	stbuf->ia_nlink = nlink; -	stbuf->ia_uid   = uid; -	stbuf->ia_gid   = gid; -	stbuf->ia_rdev  = rdev; -	stbuf->ia_size  = size; -	stbuf->ia_blksize = blksize; -	stbuf->ia_blocks  = blocks; - -	stbuf->ia_atime = atime; -	stbuf->ia_mtime = mtime; -	stbuf->ia_ctime = ctime; - -	stbuf->ia_atime_nsec = atime_nsec; -	stbuf->ia_mtime_nsec = mtime_nsec; -	stbuf->ia_ctime_nsec = ctime_nsec; -} - -#endif diff --git a/xlators/protocol/legacy/client/src/saved-frames.c b/xlators/protocol/legacy/client/src/saved-frames.c deleted file mode 100644 index b884a9796fc..00000000000 --- a/xlators/protocol/legacy/client/src/saved-frames.c +++ /dev/null @@ -1,196 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - - -#include "saved-frames.h" -#include "common-utils.h" -#include "protocol.h" -#include "xlator.h" -#include "client-mem-types.h" - - - -struct saved_frames * -gf_client_saved_frames_new (void) -{ -	struct saved_frames *saved_frames = NULL; - -	saved_frames = GF_CALLOC (sizeof (*saved_frames), 1, -                                  gf_client_mt_saved_frames); -	if (!saved_frames) { -		return NULL; -	} - -        gf_log ("", 1, "here"); -	INIT_LIST_HEAD (&saved_frames->fops.list); -	INIT_LIST_HEAD (&saved_frames->mops.list); -	INIT_LIST_HEAD (&saved_frames->cbks.list); - -	return saved_frames; -} - - -struct saved_frame * -get_head_frame_for_type (struct saved_frames *frames, int8_t type) -{ -	struct saved_frame *head_frame = NULL; - -	switch (type) { -	case GF_OP_TYPE_FOP_REQUEST: -	case GF_OP_TYPE_FOP_REPLY: -		head_frame = &frames->fops; -		break; -	case GF_OP_TYPE_MOP_REQUEST: -	case GF_OP_TYPE_MOP_REPLY: -		head_frame = &frames->mops; -		break; -	case GF_OP_TYPE_CBK_REQUEST: -	case GF_OP_TYPE_CBK_REPLY: -		head_frame = &frames->cbks; -		break; -	} - -	return head_frame; -} - - -int -saved_frames_put (struct saved_frames *frames, call_frame_t *frame, -		  int32_t op, int8_t type, int64_t callid) -{ -	struct saved_frame *saved_frame = NULL; -	struct saved_frame *head_frame = NULL; - -	head_frame = get_head_frame_for_type (frames, type); - -	saved_frame = GF_CALLOC (sizeof (*saved_frame), 1, -                                gf_client_mt_saved_frame); -	if (!saved_frame) { -		return -ENOMEM; -	} - -	INIT_LIST_HEAD (&saved_frame->list); -	saved_frame->frame  = frame; -	saved_frame->op     = op; -	saved_frame->type   = type; -	saved_frame->callid = callid; - -	gettimeofday (&saved_frame->saved_at, NULL); - -	list_add_tail (&saved_frame->list, &head_frame->list); -	frames->count++; - -	return 0; -} - - -call_frame_t * -saved_frames_get (struct saved_frames *frames, int32_t op, -		  int8_t type, int64_t callid) -{ -	struct saved_frame *saved_frame = NULL; -	struct saved_frame *tmp = NULL; -	struct saved_frame *head_frame = NULL; -	call_frame_t       *frame = NULL; - -	head_frame = get_head_frame_for_type (frames, type); - -	list_for_each_entry (tmp, &head_frame->list, list) { -		if (tmp->callid == callid) { -			list_del_init (&tmp->list); -			frames->count--; -			saved_frame = tmp; -			break; -		} -	} - -	if (saved_frame) -		frame = saved_frame->frame; - -	GF_FREE (saved_frame); - -	return frame; -} - -struct saved_frame * -saved_frames_get_timedout (struct saved_frames *frames, int8_t type,  -			   uint32_t timeout, struct timeval *current) -{ -	struct saved_frame *bailout_frame = NULL, *tmp = NULL; -	struct saved_frame *head_frame = NULL; - -	head_frame = get_head_frame_for_type (frames, type); - -	if (!list_empty(&head_frame->list)) { -		tmp = list_entry (head_frame->list.next, typeof (*tmp), list); -		if ((tmp->saved_at.tv_sec + timeout) < current->tv_sec) { -			bailout_frame = tmp; -			list_del_init (&bailout_frame->list); -			frames->count--; -		} -	} - -	return bailout_frame; -} - -void -saved_frames_unwind (xlator_t *this, struct saved_frames *saved_frames, -		     struct saved_frame *head, -		     gf_op_t gf_ops[], char *gf_op_list[]) -{ -	struct saved_frame   *trav = NULL; -	struct saved_frame   *tmp = NULL; - -	gf_hdr_common_t       hdr = {0, }; -	call_frame_t         *frame = NULL; - -	hdr.rsp.op_ret   = hton32 (-1); -	hdr.rsp.op_errno = hton32 (ENOTCONN); - -	list_for_each_entry_safe (trav, tmp, &head->list, list) { -		gf_log (this->name, GF_LOG_ERROR, -			"forced unwinding frame type(%d) op(%s)", -			trav->type, gf_op_list[trav->op]); - -		hdr.type = hton32 (trav->type); -		hdr.op   = hton32 (trav->op); - -		frame = trav->frame; - -		saved_frames->count--; - -		gf_ops[trav->op] (frame, &hdr, sizeof (hdr), NULL); - -		list_del_init (&trav->list); -		GF_FREE (trav); -	} -} - - -void -gf_client_saved_frames_destroy (xlator_t *this, struct saved_frames *frames, -                                gf_op_t gf_fops[], gf_op_t gf_mops[], -                                gf_op_t gf_cbks[]) -{ -	saved_frames_unwind (this, frames, &frames->fops, gf_fops, gf_fop_list); -	saved_frames_unwind (this, frames, &frames->mops, gf_mops, gf_mop_list); -	saved_frames_unwind (this, frames, &frames->cbks, gf_cbks, gf_cbk_list); - -	GF_FREE (frames); -} diff --git a/xlators/protocol/legacy/client/src/saved-frames.h b/xlators/protocol/legacy/client/src/saved-frames.h deleted file mode 100644 index 9f7fe0a7d26..00000000000 --- a/xlators/protocol/legacy/client/src/saved-frames.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _SAVED_FRAMES_H -#define _SAVED_FRAMES_H - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include <stdint.h> -#include <sys/time.h> -#include "stack.h" -#include "list.h" -#include "protocol.h" - -/* UGLY: have common typedef b/w saved-frames.c and protocol-client.c */ -typedef int32_t (*gf_op_t) (call_frame_t *frame, -                            gf_hdr_common_t *hdr, size_t hdrlen, -                            struct iobuf *iobuf); - - -struct saved_frame { -	union { -		struct list_head list; -		struct { -			struct saved_frame *frame_next; -			struct saved_frame *frame_prev; -		}; -	}; - -	struct timeval  saved_at; -	call_frame_t   *frame; -	int32_t         op; -	int8_t          type; -	uint64_t        callid; -}; - - -struct saved_frames { -	int64_t            count; -	struct saved_frame fops; -	struct saved_frame mops; -	struct saved_frame cbks; -}; - - -struct saved_frames *gf_client_saved_frames_new (); -int saved_frames_put (struct saved_frames *frames, call_frame_t *frame, -		      int32_t op, int8_t type, int64_t callid); -call_frame_t *saved_frames_get (struct saved_frames *frames, int32_t op, -				int8_t type, int64_t callid); - -struct saved_frame * -saved_frames_get_timedout (struct saved_frames *frames, int8_t type,  -			   uint32_t timeout, struct timeval *current); - -void gf_client_saved_frames_destroy (xlator_t *this, struct saved_frames *frames, -                                     gf_op_t gf_fops[], gf_op_t gf_mops[], -                                     gf_op_t gf_cbks[]); - -#endif /* _SAVED_FRAMES_H */ diff --git a/xlators/protocol/legacy/lib/Makefile.am b/xlators/protocol/legacy/lib/Makefile.am deleted file mode 100644 index d471a3f9243..00000000000 --- a/xlators/protocol/legacy/lib/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = src - -CLEANFILES =  diff --git a/xlators/protocol/legacy/lib/src/Makefile.am b/xlators/protocol/legacy/lib/src/Makefile.am deleted file mode 100644 index 1f0e93e3047..00000000000 --- a/xlators/protocol/legacy/lib/src/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -lib_LTLIBRARIES = libgfproto.la - -libgfproto_la_CFLAGS = -fPIC  -Wall -g -shared -nostartfiles $(GF_CFLAGS) $(GF_DARWIN_LIBGLUSTERFS_CFLAGS) - -libgfproto_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -D_GNU_SOURCE  \ -	-D$(GF_HOST_OS) -DLIBDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/auth\"     \ -	-DTRANSPORTDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/transport\"          \ -	-I$(CONTRIBDIR)/rbtree -I$(top_srcdir)/libglusterfs/src/ - -libgfproto_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la - -libgfproto_la_SOURCES = transport.c protocol.c - -noinst_HEADERS = transport.h protocol.h diff --git a/xlators/protocol/legacy/lib/src/protocol.c b/xlators/protocol/legacy/lib/src/protocol.c deleted file mode 100644 index 63950f43dec..00000000000 --- a/xlators/protocol/legacy/lib/src/protocol.c +++ /dev/null @@ -1,108 +0,0 @@ - -#include "globals.h" -#include "compat.h" -#include "protocol.h" - -char *gf_mop_list[GF_MOP_MAXVALUE]; -char *gf_cbk_list[GF_CBK_MAXVALUE]; - -static int -gf_dirent_nb_size (gf_dirent_t *entries) -{ -	return (sizeof (struct gf_dirent_nb) + strlen (entries->d_name) + 1); -} - -int -gf_dirent_serialize (gf_dirent_t *entries, char *buf, size_t buf_size) -{ -	struct gf_dirent_nb *entry_nb = NULL; -	gf_dirent_t         *entry = NULL; -	int                  size = 0; -	int                  entry_size = 0; - - -	list_for_each_entry (entry, &entries->list, list) { -		entry_size = gf_dirent_nb_size (entry); - -		if (buf && (size + entry_size <= buf_size)) { -			entry_nb = (void *) (buf + size); - -			entry_nb->d_ino  = hton64 (entry->d_ino); -			entry_nb->d_off  = hton64 (entry->d_off); -			entry_nb->d_len  = hton32 (entry->d_len); -			entry_nb->d_type = hton32 (entry->d_type); - -                        gf_stat_from_iatt (&entry_nb->d_stat, &entry->d_stat); - -			strcpy (entry_nb->d_name, entry->d_name); -		} -		size += entry_size; -	} - -	return size; -} - - -int -gf_dirent_unserialize (gf_dirent_t *entries, const char *buf, size_t buf_size) -{ -	struct gf_dirent_nb *entry_nb = NULL; -	int                  remaining_size = 0; -	int                  least_dirent_size = 0; -	int                  count = 0; -	gf_dirent_t         *entry = NULL; -	int                  entry_strlen = 0; -	int                  entry_len = 0; - - -	remaining_size = buf_size; -	least_dirent_size = (sizeof (struct gf_dirent_nb) + 2); - -	while (remaining_size >= least_dirent_size) { -		entry_nb = (void *)(buf + (buf_size - remaining_size)); - -		entry_strlen = strnlen (entry_nb->d_name, remaining_size); -		if (entry_strlen == remaining_size) { -			break; -		} - -		entry_len = sizeof (gf_dirent_t) + entry_strlen + 1; -		entry = GF_CALLOC (1, entry_len, gf_common_mt_gf_dirent_t); -		if (!entry) { -			break; -		} - -		entry->d_ino  = ntoh64 (entry_nb->d_ino); -		entry->d_off  = ntoh64 (entry_nb->d_off); -		entry->d_len  = ntoh32 (entry_nb->d_len); -		entry->d_type = ntoh32 (entry_nb->d_type); - -                gf_stat_to_iatt (&entry_nb->d_stat, &entry->d_stat); - -		strcpy (entry->d_name, entry_nb->d_name); - -		list_add_tail (&entry->list, &entries->list); - -		remaining_size -= (sizeof (*entry_nb) + entry_strlen + 1); -		count++; -	} - -	return count; -} - -int -protocol_common_init (void) -{ -        gf_mop_list[GF_MOP_SETVOLUME]   = "SETVOLUME"; -        gf_mop_list[GF_MOP_GETVOLUME]   = "GETVOLUME"; -        gf_mop_list[GF_MOP_SETSPEC]     = "SETSPEC"; -        gf_mop_list[GF_MOP_GETSPEC]     = "GETSPEC"; -        gf_mop_list[GF_MOP_LOG]         = "LOG"; -        gf_mop_list[GF_MOP_PING]        = "PING"; - -        gf_cbk_list[GF_CBK_FORGET]      = "FORGET"; -        gf_cbk_list[GF_CBK_RELEASE]     = "RELEASE"; -        gf_cbk_list[GF_CBK_RELEASEDIR]  = "RELEASEDIR"; - -        return 0; -} diff --git a/xlators/protocol/legacy/lib/src/protocol.h b/xlators/protocol/legacy/lib/src/protocol.h deleted file mode 100644 index 6c568ed0d3a..00000000000 --- a/xlators/protocol/legacy/lib/src/protocol.h +++ /dev/null @@ -1,1118 +0,0 @@ -/* -  Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _PROTOCOL_H -#define _PROTOCOL_H - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include <inttypes.h> -#include <sys/time.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/statvfs.h> -#include <unistd.h> -#include <fcntl.h> - -#include "byte-order.h" -#include "iatt.h" - -/* Any changes in the protocol structure or adding new '[f,m]ops' needs to  - * bump the protocol version by "0.1"  - */ - -#define GF_PROTOCOL_VERSION "3.0" - -extern char *gf_mop_list[]; -extern char *gf_cbk_list[]; - -/* NOTE: add members ONLY at the end (just before _MAXVALUE) */ -typedef enum { -        GF_PROTO_FOP_STAT,       /* 0 */ -        GF_PROTO_FOP_READLINK,   /* 1 */ -        GF_PROTO_FOP_MKNOD,      /* 2 */ -        GF_PROTO_FOP_MKDIR, -        GF_PROTO_FOP_UNLINK, -        GF_PROTO_FOP_RMDIR,      /* 5 */ -        GF_PROTO_FOP_SYMLINK, -        GF_PROTO_FOP_RENAME, -        GF_PROTO_FOP_LINK, -        GF_PROTO_FOP_TRUNCATE, -        GF_PROTO_FOP_OPEN,       /* 10 */ -        GF_PROTO_FOP_READ, -        GF_PROTO_FOP_WRITE, -        GF_PROTO_FOP_STATFS,     /* 15 */ -        GF_PROTO_FOP_FLUSH, -        GF_PROTO_FOP_FSYNC, -        GF_PROTO_FOP_SETXATTR, -        GF_PROTO_FOP_GETXATTR, -        GF_PROTO_FOP_REMOVEXATTR,/* 20 */ -        GF_PROTO_FOP_OPENDIR, -        GF_PROTO_FOP_GETDENTS, -        GF_PROTO_FOP_FSYNCDIR, -        GF_PROTO_FOP_ACCESS, -        GF_PROTO_FOP_CREATE,     /* 25 */ -        GF_PROTO_FOP_FTRUNCATE, -        GF_PROTO_FOP_FSTAT, -        GF_PROTO_FOP_LK, -        GF_PROTO_FOP_LOOKUP, -        GF_PROTO_FOP_SETDENTS, -        GF_PROTO_FOP_READDIR, -        GF_PROTO_FOP_INODELK,   /* 35 */ -        GF_PROTO_FOP_FINODELK, -	GF_PROTO_FOP_ENTRYLK, -	GF_PROTO_FOP_FENTRYLK, -        GF_PROTO_FOP_CHECKSUM, -        GF_PROTO_FOP_XATTROP,  /* 40 */ -        GF_PROTO_FOP_FXATTROP, -        GF_PROTO_FOP_LOCK_NOTIFY, -        GF_PROTO_FOP_LOCK_FNOTIFY, -        GF_PROTO_FOP_FGETXATTR, -        GF_PROTO_FOP_FSETXATTR, /* 45 */ -        GF_PROTO_FOP_RCHECKSUM, -        GF_PROTO_FOP_SETATTR, -        GF_PROTO_FOP_FSETATTR, -        GF_PROTO_FOP_READDIRP, -        GF_PROTO_FOP_MAXVALUE, -} glusterfs_proto_fop_t; - -/* NOTE: add members ONLY at the end (just before _MAXVALUE) */ -typedef enum { -        GF_MOP_SETVOLUME, /* 0 */ -        GF_MOP_GETVOLUME, /* 1 */ -        GF_MOP_STATS, -        GF_MOP_SETSPEC, -        GF_MOP_GETSPEC, -	GF_MOP_PING,      /* 5 */ -        GF_MOP_LOG, -        GF_MOP_NOTIFY, -        GF_MOP_MAXVALUE,   /* 8 */ -} glusterfs_mop_t; - -typedef enum { -	GF_CBK_FORGET,      /* 0 */ -	GF_CBK_RELEASE,     /* 1 */ -	GF_CBK_RELEASEDIR,  /* 2 */ -	GF_CBK_MAXVALUE     /* 3 */ -} glusterfs_cbk_t; - -typedef enum { -        GF_OP_TYPE_FOP_REQUEST = 1, -        GF_OP_TYPE_MOP_REQUEST, -	GF_OP_TYPE_CBK_REQUEST, -        GF_OP_TYPE_FOP_REPLY, -        GF_OP_TYPE_MOP_REPLY, -	GF_OP_TYPE_CBK_REPLY -} glusterfs_op_type_t; - - -struct gf_stat { -	uint64_t ino; -	uint64_t size; -	uint64_t blocks; -	uint64_t dev; -	uint32_t rdev; -	uint32_t mode; -	uint32_t nlink; -	uint32_t uid; -	uint32_t gid; -	uint32_t blksize; -	uint32_t atime; -	uint32_t atime_nsec; -	uint32_t mtime ; -	uint32_t mtime_nsec; -	uint32_t ctime; -	uint32_t ctime_nsec; -} __attribute__((packed)); - - -static inline void -gf_stat_to_stat (struct gf_stat *gf_stat, struct stat *stat) -{ -	stat->st_dev          = ntoh64 (gf_stat->dev); -	stat->st_ino          = ntoh64 (gf_stat->ino); -	stat->st_mode         = ntoh32 (gf_stat->mode); -	stat->st_nlink        = ntoh32 (gf_stat->nlink); -	stat->st_uid          = ntoh32 (gf_stat->uid); -	stat->st_gid          = ntoh32 (gf_stat->gid); -	stat->st_rdev         = ntoh32 (gf_stat->rdev); -	stat->st_size         = ntoh64 (gf_stat->size); -	stat->st_blksize      = ntoh32 (gf_stat->blksize); -	stat->st_blocks       = ntoh64 (gf_stat->blocks); -	stat->st_atime        = ntoh32 (gf_stat->atime); -	stat->st_mtime        = ntoh32 (gf_stat->mtime); -	stat->st_ctime        = ntoh32 (gf_stat->ctime); -        ST_ATIM_NSEC_SET(stat, ntoh32 (gf_stat->atime_nsec)); -        ST_MTIM_NSEC_SET(stat, ntoh32 (gf_stat->mtime_nsec)); -        ST_CTIM_NSEC_SET(stat, ntoh32 (gf_stat->ctime_nsec)); -} - - -static inline void -gf_stat_from_stat (struct gf_stat *gf_stat, struct stat *stat) -{ -	gf_stat->dev         = hton64 (stat->st_dev); -	gf_stat->ino         = hton64 (stat->st_ino); -	gf_stat->mode        = hton32 (stat->st_mode); -	gf_stat->nlink       = hton32 (stat->st_nlink); -	gf_stat->uid         = hton32 (stat->st_uid); -	gf_stat->gid         = hton32 (stat->st_gid); -	gf_stat->rdev        = hton32 (stat->st_rdev); -	gf_stat->size        = hton64 (stat->st_size); -	gf_stat->blksize     = hton32 (stat->st_blksize); -	gf_stat->blocks      = hton64 (stat->st_blocks); -	gf_stat->atime       = hton32 (stat->st_atime); -	gf_stat->mtime       = hton32 (stat->st_mtime); -	gf_stat->ctime       = hton32 (stat->st_ctime); -        gf_stat->atime_nsec  = hton32 (ST_ATIM_NSEC(stat)); -        gf_stat->mtime_nsec  = hton32 (ST_MTIM_NSEC(stat)); -        gf_stat->ctime_nsec  = hton32 (ST_CTIM_NSEC(stat)); -} - - -static inline void -gf_stat_to_iatt (struct gf_stat *gf_stat, struct iatt *iatt) -{ -        iatt->ia_ino        = ntoh64 (gf_stat->ino); -        iatt->ia_dev        = ntoh64 (gf_stat->dev); -        iatt->ia_type       = ia_type_from_st_mode (ntoh32 (gf_stat->mode)); -        iatt->ia_prot       = ia_prot_from_st_mode (ntoh32 (gf_stat->mode)); -        iatt->ia_nlink      = ntoh32 (gf_stat->nlink); -        iatt->ia_uid        = ntoh32 (gf_stat->uid); -        iatt->ia_gid        = ntoh32 (gf_stat->gid); -        iatt->ia_rdev       = ntoh64 (gf_stat->rdev); -        iatt->ia_size       = ntoh64 (gf_stat->size); -        iatt->ia_blksize    = ntoh32 (gf_stat->blksize); -        iatt->ia_blocks     = ntoh64 (gf_stat->blocks); -        iatt->ia_atime      = ntoh32 (gf_stat->atime); -        iatt->ia_atime_nsec = ntoh32 (gf_stat->atime_nsec); -        iatt->ia_mtime      = ntoh32 (gf_stat->mtime); -        iatt->ia_mtime_nsec = ntoh32 (gf_stat->mtime_nsec); -        iatt->ia_ctime      = ntoh32 (gf_stat->ctime); -        iatt->ia_ctime_nsec = ntoh32 (gf_stat->ctime_nsec); - -        iatt->ia_gen        = ntoh64 (gf_stat->dev); -} - - -static inline void -gf_stat_from_iatt (struct gf_stat *gf_stat, struct iatt *iatt) -{ -        gf_stat->ino        = hton64 (iatt->ia_ino); -        gf_stat->dev        = hton64 (iatt->ia_dev); -        gf_stat->mode       = hton32 (st_mode_from_ia (iatt->ia_prot, -                                                       iatt->ia_type)); -        gf_stat->nlink      = hton32 (iatt->ia_nlink); -        gf_stat->uid        = hton32 (iatt->ia_uid); -        gf_stat->gid        = hton32 (iatt->ia_gid); -        gf_stat->rdev       = hton32 (iatt->ia_rdev); -        gf_stat->size       = hton64 (iatt->ia_size); -        gf_stat->blksize    = hton32 (iatt->ia_blksize); -        gf_stat->blocks     = hton64 (iatt->ia_blocks); -        gf_stat->atime      = hton32 (iatt->ia_atime); -        gf_stat->atime_nsec = hton32 (iatt->ia_atime_nsec); -        gf_stat->mtime      = hton32 (iatt->ia_mtime); -        gf_stat->mtime_nsec = hton32 (iatt->ia_mtime_nsec); -        gf_stat->ctime      = hton32 (iatt->ia_ctime); -        gf_stat->ctime_nsec = hton32 (iatt->ia_ctime_nsec); - -        gf_stat->dev        = hton64 (iatt->ia_gen); - -} - - -struct gf_statfs { -	uint64_t bsize; -	uint64_t frsize; -	uint64_t blocks; -	uint64_t bfree; -	uint64_t bavail; -	uint64_t files; -	uint64_t ffree; -	uint64_t favail; -	uint64_t fsid; -	uint64_t flag; -	uint64_t namemax; -} __attribute__((packed)); - - -static inline void -gf_statfs_to_statfs (struct gf_statfs *gf_stat, struct statvfs *stat) -{ -	stat->f_bsize   = ntoh64 (gf_stat->bsize); -	stat->f_frsize  = ntoh64 (gf_stat->frsize); -	stat->f_blocks  = ntoh64 (gf_stat->blocks); -	stat->f_bfree   = ntoh64 (gf_stat->bfree); -	stat->f_bavail  = ntoh64 (gf_stat->bavail); -	stat->f_files   = ntoh64 (gf_stat->files); -	stat->f_ffree   = ntoh64 (gf_stat->ffree); -	stat->f_favail  = ntoh64 (gf_stat->favail); -	stat->f_fsid    = ntoh64 (gf_stat->fsid); -	stat->f_flag    = ntoh64 (gf_stat->flag); -	stat->f_namemax = ntoh64 (gf_stat->namemax); -} - - -static inline void -gf_statfs_from_statfs (struct gf_statfs *gf_stat, struct statvfs *stat) -{ -	gf_stat->bsize   = hton64 (stat->f_bsize); -	gf_stat->frsize  = hton64 (stat->f_frsize); -	gf_stat->blocks  = hton64 (stat->f_blocks); -	gf_stat->bfree   = hton64 (stat->f_bfree); -	gf_stat->bavail  = hton64 (stat->f_bavail); -	gf_stat->files   = hton64 (stat->f_files); -	gf_stat->ffree   = hton64 (stat->f_ffree); -	gf_stat->favail  = hton64 (stat->f_favail); -	gf_stat->fsid    = hton64 (stat->f_fsid); -	gf_stat->flag    = hton64 (stat->f_flag); -	gf_stat->namemax = hton64 (stat->f_namemax); -} - - -struct gf_flock { -	uint16_t type; -	uint16_t whence; -	uint64_t start; -	uint64_t len; -	uint32_t pid; -} __attribute__((packed)); - - -static inline void -gf_flock_to_flock (struct gf_flock *gf_flock, struct gf_flock *flock) -{ -	flock->l_type   = ntoh16 (gf_flock->type); -	flock->l_whence = ntoh16 (gf_flock->whence); -	flock->l_start  = ntoh64 (gf_flock->start); -	flock->l_len    = ntoh64 (gf_flock->len); -	flock->l_pid    = ntoh32 (gf_flock->pid); -} - - -static inline void -gf_flock_from_flock (struct gf_flock *gf_flock, struct gf_flock *flock) -{ -	gf_flock->type   = hton16 (flock->l_type); -	gf_flock->whence = hton16 (flock->l_whence); -	gf_flock->start  = hton64 (flock->l_start); -	gf_flock->len    = hton64 (flock->l_len); -	gf_flock->pid    = hton32 (flock->l_pid); -} - - -struct gf_timespec { -	uint32_t tv_sec; -	uint32_t tv_nsec; -} __attribute__((packed)); - - -static inline void -gf_timespec_to_timespec (struct gf_timespec *gf_ts, struct timespec *ts) -{ - -	ts[0].tv_sec  = ntoh32 (gf_ts[0].tv_sec); -	ts[0].tv_nsec = ntoh32 (gf_ts[0].tv_nsec); -	ts[1].tv_sec  = ntoh32 (gf_ts[1].tv_sec); -	ts[1].tv_nsec = ntoh32 (gf_ts[1].tv_nsec); -} - - -static inline void -gf_timespec_from_timespec (struct gf_timespec *gf_ts, struct timespec *ts) -{ -	gf_ts[0].tv_sec  = hton32 (ts[0].tv_sec); -	gf_ts[0].tv_nsec = hton32 (ts[0].tv_nsec); -	gf_ts[1].tv_sec  = hton32 (ts[1].tv_sec); -	gf_ts[1].tv_nsec = hton32 (ts[1].tv_nsec); -} - - -#define GF_O_ACCMODE           003 -#define GF_O_RDONLY             00 -#define GF_O_WRONLY             01 -#define GF_O_RDWR               02 -#define GF_O_CREAT            0100 -#define GF_O_EXCL             0200 -#define GF_O_NOCTTY           0400 -#define GF_O_TRUNC           01000 -#define GF_O_APPEND          02000 -#define GF_O_NONBLOCK        04000 -#define GF_O_SYNC           010000 -#define GF_O_ASYNC          020000 - -#define GF_O_DIRECT         040000 -#define GF_O_DIRECTORY     0200000 -#define GF_O_NOFOLLOW      0400000 -#define GF_O_NOATIME      01000000 -#define GF_O_CLOEXEC      02000000 - -#define GF_O_LARGEFILE     0100000 - -#define XLATE_BIT(from, to, bit)    do {                \ -                if (from & bit)                         \ -                        to = to | GF_##bit;             \ -        } while (0) - -#define UNXLATE_BIT(from, to, bit)  do {                \ -                if (from & GF_##bit)                    \ -                        to = to | bit;                  \ -        } while (0) - -#define XLATE_ACCESSMODE(from, to) do {                 \ -                switch (from & O_ACCMODE) {             \ -                case O_RDONLY: to |= GF_O_RDONLY;       \ -                        break;                          \ -                case O_WRONLY: to |= GF_O_WRONLY;       \ -                        break;                          \ -                case O_RDWR: to |= GF_O_RDWR;           \ -                        break;                          \ -                }                                       \ -        } while (0) - -#define UNXLATE_ACCESSMODE(from, to) do {               \ -                switch (from & GF_O_ACCMODE) {          \ -                case GF_O_RDONLY: to |= O_RDONLY;       \ -                        break;                          \ -                case GF_O_WRONLY: to |= O_WRONLY;       \ -                        break;                          \ -                case GF_O_RDWR: to |= O_RDWR;           \ -                        break;                          \ -                }                                       \ -        } while (0) - -static inline uint32_t -gf_flags_from_flags (uint32_t flags) -{ -        uint32_t gf_flags = 0; - -        XLATE_ACCESSMODE (flags, gf_flags); - -        XLATE_BIT (flags, gf_flags, O_CREAT); -        XLATE_BIT (flags, gf_flags, O_EXCL); -        XLATE_BIT (flags, gf_flags, O_NOCTTY); -        XLATE_BIT (flags, gf_flags, O_TRUNC); -        XLATE_BIT (flags, gf_flags, O_APPEND); -        XLATE_BIT (flags, gf_flags, O_NONBLOCK); -        XLATE_BIT (flags, gf_flags, O_SYNC); -        XLATE_BIT (flags, gf_flags, O_ASYNC); - -        XLATE_BIT (flags, gf_flags, O_DIRECT); -        XLATE_BIT (flags, gf_flags, O_DIRECTORY); -        XLATE_BIT (flags, gf_flags, O_NOFOLLOW); -#ifdef O_NOATIME -        XLATE_BIT (flags, gf_flags, O_NOATIME); -#endif -#ifdef O_CLOEXEC -        XLATE_BIT (flags, gf_flags, O_CLOEXEC); -#endif -        XLATE_BIT (flags, gf_flags, O_LARGEFILE); - -        return gf_flags; -} - -static inline uint32_t -gf_flags_to_flags (uint32_t gf_flags) -{ -        uint32_t flags = 0; - -        UNXLATE_ACCESSMODE (gf_flags, flags); - -        UNXLATE_BIT (gf_flags, flags, O_CREAT); -        UNXLATE_BIT (gf_flags, flags, O_EXCL); -        UNXLATE_BIT (gf_flags, flags, O_NOCTTY); -        UNXLATE_BIT (gf_flags, flags, O_TRUNC); -        UNXLATE_BIT (gf_flags, flags, O_APPEND); -        UNXLATE_BIT (gf_flags, flags, O_NONBLOCK); -        UNXLATE_BIT (gf_flags, flags, O_SYNC); -        UNXLATE_BIT (gf_flags, flags, O_ASYNC); - -        UNXLATE_BIT (gf_flags, flags, O_DIRECT); -        UNXLATE_BIT (gf_flags, flags, O_DIRECTORY); -        UNXLATE_BIT (gf_flags, flags, O_NOFOLLOW); -#ifdef O_NOATIME -        UNXLATE_BIT (gf_flags, flags, O_NOATIME); -#endif -#ifdef O_CLOEXEC -        UNXLATE_BIT (gf_flags, flags, O_CLOEXEC); -#endif -        UNXLATE_BIT (gf_flags, flags, O_LARGEFILE); - -        return flags; -} - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	char     path[0];     /* NULL terminated */ -} __attribute__((packed)) gf_fop_stat_req_t;; -typedef struct { -	struct gf_stat stat; -} __attribute__((packed)) gf_fop_stat_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	uint32_t size; -	char     path[0];     /* NULL terminated */ -} __attribute__((packed)) gf_fop_readlink_req_t; -typedef struct { -        struct gf_stat buf; -	char     path[0]; /* NULL terminated */ -} __attribute__((packed)) gf_fop_readlink_rsp_t; - - -typedef struct { -	uint64_t par; -        uint64_t gen; -	uint64_t dev; -	uint32_t mode; -	char     path[0];     /* NULL terminated */ -	char     bname[0]; /* NULL terminated */ -} __attribute__((packed)) gf_fop_mknod_req_t; -typedef struct { -	struct gf_stat stat; -        struct gf_stat preparent; -        struct gf_stat postparent; -} __attribute__((packed)) gf_fop_mknod_rsp_t; - - -typedef struct { -	uint64_t par; -        uint64_t gen; -	uint32_t mode; -	char     path[0];     /* NULL terminated */ -	char     bname[0]; /* NULL terminated */ -} __attribute__((packed)) gf_fop_mkdir_req_t; -typedef struct { -	struct gf_stat stat; -        struct gf_stat preparent; -        struct gf_stat postparent; -} __attribute__((packed)) gf_fop_mkdir_rsp_t; - - -typedef struct { -	uint64_t par; -        uint64_t gen; -	char     path[0];     /* NULL terminated */ -	char     bname[0]; /* NULL terminated */ -} __attribute__((packed)) gf_fop_unlink_req_t; -typedef struct { -        struct gf_stat preparent; -        struct gf_stat postparent; -} __attribute__((packed)) gf_fop_unlink_rsp_t; - - -typedef struct { -	uint64_t par; -        uint64_t gen; -	char     path[0]; -	char     bname[0]; /* NULL terminated */ -} __attribute__((packed)) gf_fop_rmdir_req_t; -typedef struct { -        struct gf_stat preparent; -        struct gf_stat postparent; -} __attribute__((packed)) gf_fop_rmdir_rsp_t; - - -typedef struct { -	uint64_t par; -        uint64_t gen; -	char     path[0]; -	char     bname[0]; -	char     linkname[0]; -} __attribute__((packed)) gf_fop_symlink_req_t; -typedef struct { -	struct gf_stat stat; -        struct gf_stat preparent; -        struct gf_stat postparent; -}__attribute__((packed)) gf_fop_symlink_rsp_t; - - -typedef struct { -	uint64_t   oldpar; -        uint64_t   oldgen; -	uint64_t   newpar; -        uint64_t   newgen; -	char       oldpath[0]; -	char       oldbname[0]; /* NULL terminated */ -	char       newpath[0]; -	char       newbname[0]; /* NULL terminated */ -} __attribute__((packed)) gf_fop_rename_req_t; -typedef struct { -	struct gf_stat stat; -        struct gf_stat preoldparent; -        struct gf_stat postoldparent; -        struct gf_stat prenewparent; -        struct gf_stat postnewparent; -} __attribute__((packed)) gf_fop_rename_rsp_t; - - -typedef struct { -	uint64_t   oldino; -        uint64_t   oldgen; -	uint64_t   newpar; -        uint64_t   newgen; -	char       oldpath[0]; -	char       newpath[0]; -	char       newbname[0]; -}__attribute__((packed)) gf_fop_link_req_t; -typedef struct { -	struct gf_stat stat; -        struct gf_stat preparent; -        struct gf_stat postparent; -} __attribute__((packed)) gf_fop_link_rsp_t; - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	uint64_t offset; -	char     path[0]; -} __attribute__((packed)) gf_fop_truncate_req_t; -typedef struct { -	struct gf_stat prestat; -        struct gf_stat poststat; -} __attribute__((packed)) gf_fop_truncate_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	uint32_t flags; -        uint32_t wbflags; -	char     path[0]; -} __attribute__((packed)) gf_fop_open_req_t; -typedef struct { -	int64_t fd; -} __attribute__((packed)) gf_fop_open_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	int64_t  fd; -	uint64_t offset; -	uint32_t size; -} __attribute__((packed)) gf_fop_read_req_t; -typedef struct { -	struct gf_stat stat; -	char buf[0]; -} __attribute__((packed)) gf_fop_read_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	int64_t  fd; -	uint64_t offset; -	uint32_t size; -} __attribute__((packed)) gf_fop_write_req_t; -typedef struct { -	struct gf_stat prestat; -        struct gf_stat poststat; -} __attribute__((packed)) gf_fop_write_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	char     path[0]; -} __attribute__((packed)) gf_fop_statfs_req_t; -typedef struct { -	struct gf_statfs statfs; -} __attribute__((packed)) gf_fop_statfs_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	int64_t  fd; -} __attribute__((packed)) gf_fop_flush_req_t; -typedef struct { } __attribute__((packed)) gf_fop_flush_rsp_t; - - -typedef struct fsync_req { -	uint64_t ino; -        uint64_t gen; -	int64_t  fd; -	uint32_t data; -} __attribute__((packed)) gf_fop_fsync_req_t; -typedef struct { -        struct gf_stat prestat; -        struct gf_stat poststat; -} __attribute__((packed)) gf_fop_fsync_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	uint32_t flags; -	uint32_t dict_len; -	char     dict[0]; -	char     path[0]; -} __attribute__((packed)) gf_fop_setxattr_req_t; -typedef struct { } __attribute__((packed)) gf_fop_setxattr_rsp_t; - - -typedef struct { -        uint64_t ino; -        uint64_t gen; -	int64_t  fd; -	uint32_t flags; -	uint32_t dict_len; -	char     dict[0]; -} __attribute__((packed)) gf_fop_fsetxattr_req_t; -typedef struct { } __attribute__((packed)) gf_fop_fsetxattr_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	uint32_t flags; -	uint32_t dict_len; -	char     dict[0]; -	char     path[0]; -} __attribute__((packed)) gf_fop_xattrop_req_t; - -typedef struct { -	uint32_t dict_len; -	char  dict[0]; -} __attribute__((packed)) gf_fop_xattrop_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	int64_t  fd; -	uint32_t flags; -	uint32_t dict_len; -	char     dict[0]; -} __attribute__((packed)) gf_fop_fxattrop_req_t; - -typedef struct { -	uint32_t dict_len; -	char  dict[0]; -} __attribute__((packed)) gf_fop_fxattrop_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	uint32_t namelen; -	char     path[0]; -	char     name[0]; -} __attribute__((packed)) gf_fop_getxattr_req_t; -typedef struct { -	uint32_t dict_len; -	char     dict[0]; -} __attribute__((packed)) gf_fop_getxattr_rsp_t; - - -typedef struct { -        uint64_t ino; -        uint64_t gen; -	int64_t  fd; -        uint32_t namelen; -	char     name[0]; -} __attribute__((packed)) gf_fop_fgetxattr_req_t; -typedef struct { -	uint32_t dict_len; -	char     dict[0]; -} __attribute__((packed)) gf_fop_fgetxattr_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	char     path[0]; -	char     name[0]; -} __attribute__((packed)) gf_fop_removexattr_req_t; -typedef struct { } __attribute__((packed)) gf_fop_removexattr_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	char     path[0]; -} __attribute__((packed)) gf_fop_opendir_req_t; -typedef struct { -	int64_t fd; -} __attribute__((packed)) gf_fop_opendir_rsp_t; - - -typedef struct fsyncdir_req { -	uint64_t ino; -        uint64_t gen; -	int64_t  fd; -	int32_t  data; -} __attribute__((packed)) gf_fop_fsyncdir_req_t; -typedef struct { -} __attribute__((packed)) gf_fop_fsyncdir_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	int64_t  fd; -	uint64_t offset; -	uint32_t size; -} __attribute__((packed)) gf_fop_readdir_req_t; -typedef struct { -	uint32_t size; -	char     buf[0]; -} __attribute__((packed)) gf_fop_readdir_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	int64_t  fd; -	uint64_t offset; -	uint32_t size; -} __attribute__((packed)) gf_fop_readdirp_req_t; -typedef struct { -	uint32_t size; -	char     buf[0]; -} __attribute__((packed)) gf_fop_readdirp_rsp_t; - - -typedef struct  { -	uint64_t ino; -        uint64_t gen; -	uint32_t mask; -	char     path[0]; -} __attribute__((packed)) gf_fop_access_req_t; -typedef struct { -} __attribute__((packed)) gf_fop_access_rsp_t; - - -typedef struct { -	uint64_t par; -        uint64_t gen; -	uint32_t flags; -	uint32_t mode; -	char     path[0]; -	char     bname[0]; -} __attribute__((packed)) gf_fop_create_req_t; -typedef struct { -	struct gf_stat stat; -	uint64_t       fd; -        struct gf_stat preparent; -        struct gf_stat postparent; -} __attribute__((packed)) gf_fop_create_rsp_t; - - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	int64_t  fd; -	uint64_t offset; -} __attribute__((packed)) gf_fop_ftruncate_req_t; -typedef struct { -	struct gf_stat prestat; -        struct gf_stat poststat; -} __attribute__((packed)) gf_fop_ftruncate_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	int64_t  fd; -} __attribute__((packed)) gf_fop_fstat_req_t; -typedef struct { -	struct gf_stat stat; -} __attribute__((packed)) gf_fop_fstat_rsp_t; - - -typedef struct { -	uint64_t        ino; -        uint64_t        gen; -	int64_t         fd; -	uint32_t        cmd; -	uint32_t        type; -	struct gf_flock flock; -} __attribute__((packed)) gf_fop_lk_req_t; -typedef struct { -	struct gf_flock flock; -} __attribute__((packed)) gf_fop_lk_rsp_t; - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	uint32_t cmd; -	uint32_t type; -	struct gf_flock flock; -	char     path[0]; -        char     volume[0]; -} __attribute__((packed)) gf_fop_inodelk_req_t; -typedef struct { -} __attribute__((packed)) gf_fop_inodelk_rsp_t; - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	int64_t  fd; -	uint32_t cmd; -	uint32_t type; -	struct gf_flock flock; -        char volume[0]; -} __attribute__((packed)) gf_fop_finodelk_req_t; -typedef struct { -} __attribute__((packed)) gf_fop_finodelk_rsp_t; - -typedef struct { -	uint64_t  ino; -        uint64_t  gen; -	uint32_t  cmd; -	uint32_t  type; -	uint64_t  namelen; -	char      path[0]; -	char      name[0]; -        char      volume[0]; -} __attribute__((packed)) gf_fop_entrylk_req_t; -typedef struct { -} __attribute__((packed)) gf_fop_entrylk_rsp_t; - -typedef struct { -	uint64_t  ino; -        uint64_t  gen; -	int64_t   fd; -	uint32_t  cmd; -	uint32_t  type; -	uint64_t  namelen; -	char      name[0]; -        char      volume[0]; -} __attribute__((packed)) gf_fop_fentrylk_req_t; -typedef struct { -} __attribute__((packed)) gf_fop_fentrylk_rsp_t; - -typedef struct { -	uint64_t ino; /* NOTE: used only in case of 'root' lookup */ -	uint64_t par; -        uint64_t gen; -	uint32_t flags; -	uint32_t dictlen; -	char     path[0]; -	char     bname[0]; -	char     dict[0]; -} __attribute__((packed)) gf_fop_lookup_req_t; -typedef struct { -	struct gf_stat stat; -        struct gf_stat postparent; -	uint32_t       dict_len; -	char           dict[0]; -} __attribute__((packed)) gf_fop_lookup_rsp_t; - -typedef struct { -	uint64_t  ino; -        uint64_t  gen; -	uint32_t  flag; -	char      path[0]; -} __attribute__((packed)) gf_fop_checksum_req_t; -typedef struct { -	unsigned char fchecksum[0]; -	unsigned char dchecksum[0]; -} __attribute__((packed)) gf_fop_checksum_rsp_t; - -typedef struct { -        uint64_t       ino; -        uint64_t       gen; -        struct gf_stat stbuf; -        int32_t        valid; -        char           path[0]; -} __attribute__((packed)) gf_fop_setattr_req_t; -typedef struct { -        struct gf_stat statpre; -        struct gf_stat statpost; -} __attribute__((packed)) gf_fop_setattr_rsp_t; - -typedef struct { -        int64_t        fd; -        struct gf_stat stbuf; -        int32_t        valid; -} __attribute__((packed)) gf_fop_fsetattr_req_t; -typedef struct { -        struct gf_stat statpre; -        struct gf_stat statpost; -} __attribute__((packed)) gf_fop_fsetattr_rsp_t; - -typedef struct { -        int64_t   fd; -        uint64_t  offset; -        uint32_t  len; -} __attribute__((packed)) gf_fop_rchecksum_req_t; -typedef struct { -        uint32_t weak_checksum; -        unsigned char strong_checksum[0]; -} __attribute__((packed)) gf_fop_rchecksum_rsp_t; - -typedef struct { -	uint32_t flags; -	uint32_t keylen; -	char     key[0]; -} __attribute__((packed)) gf_mop_getspec_req_t; -typedef struct { -	char spec[0]; -} __attribute__((packed)) gf_mop_getspec_rsp_t; - - -typedef struct { -        uint32_t msglen; -	char     msg[0]; -} __attribute__((packed)) gf_mop_log_req_t; -typedef struct { -} __attribute__((packed)) gf_mop_log_rsp_t; - - -typedef struct { -	uint32_t dict_len; -	char buf[0]; -} __attribute__((packed)) gf_mop_setvolume_req_t; -typedef struct { -	uint32_t dict_len; -	char buf[0]; -} __attribute__((packed)) gf_mop_setvolume_rsp_t; - - -typedef struct { -} __attribute__((packed)) gf_mop_ping_req_t; -typedef struct { -} __attribute__((packed)) gf_mop_ping_rsp_t; - -typedef struct { -	uint32_t  flags; -        char buf[0]; -} __attribute__((packed)) gf_mop_notify_req_t; -typedef struct { -	uint32_t  flags; -        char buf[0]; -} __attribute__((packed)) gf_mop_notify_rsp_t; - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	int64_t  fd; -} __attribute__((packed)) gf_cbk_releasedir_req_t; -typedef struct { -} __attribute__((packed)) gf_cbk_releasedir_rsp_t; - - -typedef struct { -	uint64_t ino; -        uint64_t gen; -	int64_t  fd; -} __attribute__((packed)) gf_cbk_release_req_t; -typedef struct { -} __attribute__((packed)) gf_cbk_release_rsp_t; - - -typedef struct { -	uint32_t count; -	uint64_t ino_array[0]; -} __attribute__((packed)) gf_cbk_forget_req_t; -typedef struct { } __attribute__((packed)) gf_cbk_forget_rsp_t; - -typedef struct { -	uint32_t pid; -	uint32_t uid; -	uint32_t gid; - -        /* Number of groups being sent through the array above. */ -        uint32_t ngrps; - -        /* Array of groups to which the uid belongs apart from the primary group -         * in gid. -         */ -        uint32_t groups[GF_REQUEST_MAXGROUPS]; - -        uint64_t lk_owner; -} __attribute__ ((packed)) gf_hdr_req_t; - - -typedef struct { -	uint32_t op_ret; -	uint32_t op_errno; -} __attribute__ ((packed)) gf_hdr_rsp_t; - - -typedef struct { -	uint64_t callid; -	uint32_t type; -	uint32_t op; -	uint32_t size; -	union { -		gf_hdr_req_t req; -		gf_hdr_rsp_t rsp; -	} __attribute__ ((packed)); -} __attribute__ ((packed)) gf_hdr_common_t; - - -static inline gf_hdr_common_t * -__gf_hdr_new (int size) -{ -	gf_hdr_common_t *hdr = NULL; - -	/* TODO: use mem-pool */ -	hdr = GF_CALLOC (sizeof (gf_hdr_common_t) + size, 1, -                         gf_common_mt_gf_hdr_common_t); - -	if (!hdr) { -		return NULL; -	} - -	hdr->size = hton32 (size); - -	return hdr; -} - - -#define gf_hdr_len(type, x) (sizeof (gf_hdr_common_t) + sizeof (*type) + x) -#define gf_hdr_new(type, x) __gf_hdr_new (sizeof (*type) + x) - - -static inline void * -gf_param (gf_hdr_common_t *hdr) -{ -	return ((void *)hdr) + sizeof (*hdr); -} - - -struct gf_dirent_nb { -	uint64_t       d_ino; -	uint64_t       d_off; -	uint32_t       d_len; -	uint32_t       d_type; -        struct gf_stat d_stat; -	char           d_name[0]; -} __attribute__((packed)); - -int -gf_dirent_unserialize (gf_dirent_t *entries, const char *buf, size_t buf_size); -int -gf_dirent_serialize (gf_dirent_t *entries, char *buf, size_t buf_size); - -int protocol_common_init (void); - -#endif diff --git a/xlators/protocol/legacy/lib/src/transport.c b/xlators/protocol/legacy/lib/src/transport.c deleted file mode 100644 index 4396613ec2e..00000000000 --- a/xlators/protocol/legacy/lib/src/transport.c +++ /dev/null @@ -1,422 +0,0 @@ -/* -  Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#include <dlfcn.h> -#include <stdlib.h> -#include <stdio.h> -#include <sys/poll.h> -#include <fnmatch.h> -#include <stdint.h> - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "logging.h" -#include "transport.h" -#include "glusterfs.h" -#include "xlator.h" -#include "list.h" - - -transport_t * -transport_load (dict_t *options, -		xlator_t *xl) -{ -	struct transport *trans = NULL, *return_trans = NULL; -	char *name = NULL; -	void *handle = NULL; -	char *type = NULL; -	char str[] = "ERROR"; -	int32_t ret = -1; -	int8_t is_tcp = 0, is_unix = 0, is_ibsdp = 0; -	volume_opt_list_t *vol_opt = NULL; - -	GF_VALIDATE_OR_GOTO("transport", options, fail); -	GF_VALIDATE_OR_GOTO("transport", xl, fail); -   -	trans = GF_CALLOC (1, sizeof (struct transport), -                           gf_common_mt_transport); -	GF_VALIDATE_OR_GOTO("transport", trans, fail); - -	trans->xl = xl; -	type = str; - -	/* Backward compatibility */ -	ret = dict_get_str (options, "transport-type", &type); -	if (ret < 0) { -		ret = dict_set_str (options, "transport-type", "socket"); -		if (ret < 0) -			gf_log ("dict", GF_LOG_DEBUG, -				"setting transport-type failed"); -		gf_log ("transport", GF_LOG_WARNING, -			"missing 'option transport-type'. defaulting to " -			"\"socket\""); -	} else { -		{ -			/* Backword compatibility to handle * /client, -			 * * /server.  -			 */ -			char *tmp = strchr (type, '/'); -			if (tmp) -				*tmp = '\0'; -		} -		 -		is_tcp = strcmp (type, "tcp"); -		is_unix = strcmp (type, "unix"); -		is_ibsdp = strcmp (type, "ib-sdp"); -		if ((is_tcp == 0) || -		    (is_unix == 0) || -		    (is_ibsdp == 0)) { -			if (is_unix == 0) -				ret = dict_set_str (options,  -						    "transport.address-family", -						    "unix"); -			if (is_ibsdp == 0) -				ret = dict_set_str (options,  -						    "transport.address-family", -						    "inet-sdp"); - -			if (ret < 0) -				gf_log ("dict", GF_LOG_DEBUG, -					"setting address-family failed"); - -			ret = dict_set_str (options,  -					    "transport-type", "socket"); -			if (ret < 0) -				gf_log ("dict", GF_LOG_DEBUG, -					"setting transport-type failed"); -		} -	} - -	ret = dict_get_str (options, "transport-type", &type); -	if (ret < 0) { -		GF_FREE (trans); -		gf_log ("transport", GF_LOG_ERROR, -			"'option transport-type <xx>' missing in volume '%s'", -			xl->name); -		goto fail; -	} - -	ret = gf_asprintf (&name, "%s/%s.so", TRANSPORTDIR, type); -        if (-1 == ret) { -                gf_log ("transport", GF_LOG_ERROR, "asprintf failed"); -                goto fail; -        } -	gf_log ("transport", GF_LOG_DEBUG, -		"attempt to load file %s", name); - -	handle = dlopen (name, RTLD_NOW|RTLD_GLOBAL); -	if (handle == NULL) { -		gf_log ("transport", GF_LOG_ERROR, "%s", dlerror ()); -		gf_log ("transport", GF_LOG_ERROR, -			"volume '%s': transport-type '%s' is not valid or " -			"not found on this machine",  -			xl->name, type); -		GF_FREE (name); -		GF_FREE (trans); -		goto fail; -	} -	GF_FREE (name); -	 -	trans->ops = dlsym (handle, "tops"); -	if (trans->ops == NULL) { -		gf_log ("transport", GF_LOG_ERROR, -			"dlsym (transport_ops) on %s", dlerror ()); -		GF_FREE (trans); -		goto fail; -	} - -	trans->init = dlsym (handle, "init"); -	if (trans->init == NULL) { -		gf_log ("transport", GF_LOG_ERROR, -			"dlsym (gf_transport_init) on %s", dlerror ()); -		GF_FREE (trans); -		goto fail; -	} - -	trans->fini = dlsym (handle, "fini"); -	if (trans->fini == NULL) { -		gf_log ("transport", GF_LOG_ERROR, -			"dlsym (gf_transport_fini) on %s", dlerror ()); -		GF_FREE (trans); -		goto fail; -	} -	 -	vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), -                             gf_common_mt_volume_opt_list_t); -	vol_opt->given_opt = dlsym (handle, "options"); -	if (vol_opt->given_opt == NULL) { -		gf_log ("transport", GF_LOG_DEBUG, -			"volume option validation not specified"); -	} else { -		list_add_tail (&vol_opt->list, &xl->volume_options); -		if (-1 ==  -		    validate_xlator_volume_options (xl,  -						    vol_opt->given_opt)) { -			gf_log ("transport", GF_LOG_ERROR, -				"volume option validation failed"); -			GF_FREE (trans); -			goto fail; -		} -	} -	 -	ret = trans->init (trans); -	if (ret != 0) { -		gf_log ("transport", GF_LOG_ERROR, -			"'%s' initialization failed", type); -		GF_FREE (trans); -		goto fail; -	} - -	pthread_mutex_init (&trans->lock, NULL); -	return_trans = trans; -fail: -	return return_trans; -} - - -int32_t  -transport_submit (transport_t *this, char *buf, int32_t len, -		  struct iovec *vector, int count, -                  struct iobref *iobref) -{ -	int32_t               ret = -1; -        transport_t          *peer_trans = NULL; -        struct iobuf         *iobuf = NULL; -        struct transport_msg *msg = NULL; - -        if (this->peer_trans) { -                peer_trans = this->peer_trans; - -                msg = GF_CALLOC (1, sizeof (*msg), -                                gf_common_mt_transport_msg); -                if (!msg) { -                        return -ENOMEM; -                } - -                msg->hdr = buf; -                msg->hdrlen = len; - -                if (vector) { -                        iobuf = iobuf_get (this->xl->ctx->iobuf_pool); -                        if (!iobuf) { -                                GF_FREE (msg->hdr); -                                GF_FREE (msg); -                                return -ENOMEM; -                        } - -                        iov_unload (iobuf->ptr, vector, count); -                        msg->iobuf = iobuf; -                } - -                pthread_mutex_lock (&peer_trans->handover.mutex); -                { -                        list_add_tail (&msg->list, &peer_trans->handover.msgs); -                        pthread_cond_broadcast (&peer_trans->handover.cond); -                } -                pthread_mutex_unlock (&peer_trans->handover.mutex); - -                return 0; -        } - -	GF_VALIDATE_OR_GOTO("transport", this, fail); -	GF_VALIDATE_OR_GOTO("transport", this->ops, fail); -	 -	ret = this->ops->submit (this, buf, len, vector, count, iobref); -fail: -	return ret; -} - - -int32_t  -transport_connect (transport_t *this) -{ -	int ret = -1; -	 -	GF_VALIDATE_OR_GOTO("transport", this, fail); -   -	ret = this->ops->connect (this); -fail: -	return ret; -} - - -int32_t -transport_listen (transport_t *this) -{ -	int ret = -1; -	 -	GF_VALIDATE_OR_GOTO("transport", this, fail); -   -	ret = this->ops->listen (this); -fail: -	return ret; -} - - -int32_t  -transport_disconnect (transport_t *this) -{ -	int32_t ret = -1; -	 -	GF_VALIDATE_OR_GOTO("transport", this, fail); -   -	ret = this->ops->disconnect (this); -fail: -	return ret; -} - - -int32_t  -transport_destroy (transport_t *this) -{ -	int32_t ret = -1; - -	GF_VALIDATE_OR_GOTO("transport", this, fail); -   -	if (this->fini) -		this->fini (this); - -	pthread_mutex_destroy (&this->lock); -	GF_FREE (this); -fail: -	return ret; -} - - -transport_t * -transport_ref (transport_t *this) -{ -	transport_t *return_this = NULL; - -	GF_VALIDATE_OR_GOTO("transport", this, fail); -	 -	pthread_mutex_lock (&this->lock); -	{ -		this->refcount ++; -	} -	pthread_mutex_unlock (&this->lock); -	 -	return_this = this; -fail: -	return return_this; -} - - -int32_t -transport_receive (transport_t *this, char **hdr_p, size_t *hdrlen_p, -		   struct iobuf **iobuf_p) -{ -	int32_t ret = -1; - -	GF_VALIDATE_OR_GOTO("transport", this, fail); - -        if (this->peer_trans) { -                *hdr_p = this->handover.msg->hdr; -                *hdrlen_p = this->handover.msg->hdrlen; -                *iobuf_p = this->handover.msg->iobuf; - -                return 0; -        } - -	ret = this->ops->receive (this, hdr_p, hdrlen_p, iobuf_p); -fail: -	return ret; -} - - -int32_t -transport_unref (transport_t *this) -{ -	int32_t refcount = 0; -	int32_t ret = -1; - -	GF_VALIDATE_OR_GOTO("transport", this, fail); -   -	pthread_mutex_lock (&this->lock); -	{ -		refcount = --this->refcount; -	} -	pthread_mutex_unlock (&this->lock); - -	if (refcount == 0) { -		xlator_notify (this->xl, GF_EVENT_TRANSPORT_CLEANUP, this); -		transport_destroy (this); -	} -	 -	ret = 0; -fail: -	return ret; -} - - -void * -transport_peerproc (void *trans_data) -{ -        transport_t          *trans = NULL; -        struct transport_msg *msg = NULL; - -        trans = trans_data; - -        while (1) { -                pthread_mutex_lock (&trans->handover.mutex); -                { -                        while (list_empty (&trans->handover.msgs)) -                                pthread_cond_wait (&trans->handover.cond, -                                                   &trans->handover.mutex); - -                        msg = list_entry (trans->handover.msgs.next, -                                          struct transport_msg, list); - -                        list_del_init (&msg->list); -                } -                pthread_mutex_unlock (&trans->handover.mutex); - -                trans->handover.msg = msg; - -                xlator_notify (trans->xl, GF_EVENT_POLLIN, trans); - -                GF_FREE (msg); -        } -} - - -int -transport_setpeer (transport_t *trans, transport_t *peer_trans) -{ -        trans->peer_trans = transport_ref (peer_trans); - -        INIT_LIST_HEAD (&trans->handover.msgs); -        pthread_cond_init (&trans->handover.cond, NULL); -        pthread_mutex_init (&trans->handover.mutex, NULL); -        pthread_create (&trans->handover.thread, NULL, -                        transport_peerproc, trans); - -        peer_trans->peer_trans = transport_ref (trans); - -        INIT_LIST_HEAD (&peer_trans->handover.msgs); -        pthread_cond_init (&peer_trans->handover.cond, NULL); -        pthread_mutex_init (&peer_trans->handover.mutex, NULL); -        pthread_create (&peer_trans->handover.thread, NULL, -                        transport_peerproc, peer_trans); - -        return 0; -} diff --git a/xlators/protocol/legacy/lib/src/transport.h b/xlators/protocol/legacy/lib/src/transport.h deleted file mode 100644 index 5b8b62cafa6..00000000000 --- a/xlators/protocol/legacy/lib/src/transport.h +++ /dev/null @@ -1,106 +0,0 @@ -/* -  Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef __TRANSPORT_H__ -#define __TRANSPORT_H__ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include <inttypes.h> - -struct transport_ops; -typedef struct transport transport_t; - -#include "xlator.h" -#include "dict.h" -#include "compat.h" - -typedef struct peer_info { -	struct sockaddr_storage sockaddr; -	socklen_t sockaddr_len; -	char identifier[UNIX_PATH_MAX]; -}peer_info_t; - -struct transport_msg { -        struct list_head  list; -        char             *hdr; -        int               hdrlen; -        struct iobuf     *iobuf; -}; - -struct transport { -	struct transport_ops  *ops; -	void                  *private; -	void                  *xl_private; -	pthread_mutex_t        lock; -	int32_t                refcount; - -	xlator_t              *xl; -	void                  *dnscache; -	data_t                *buf; -	int32_t              (*init)   (transport_t *this); -	void                 (*fini)   (transport_t *this); -	/*  int                  (*notify) (transport_t *this, int event, void *data); */ -	peer_info_t     peerinfo; -	peer_info_t     myinfo; - -        transport_t    *peer_trans; -        struct { -                pthread_mutex_t       mutex; -                pthread_cond_t        cond; -                pthread_t             thread; -                struct list_head      msgs; -                struct transport_msg *msg; -        } handover; -                 -}; - -struct transport_ops { -	int32_t (*receive)    (transport_t *this, char **hdr_p, size_t *hdrlen_p, -                               struct iobuf **iobuf_p); -	int32_t (*submit)     (transport_t *this, char *buf, int len, -                               struct iovec *vector, int count, -                               struct iobref *iobref); -	int32_t (*connect)    (transport_t *this); -	int32_t (*listen)     (transport_t *this); -	int32_t (*disconnect) (transport_t *this); -}; - - -int32_t transport_listen     (transport_t *this); -int32_t transport_connect    (transport_t *this); -int32_t transport_disconnect (transport_t *this); -int32_t transport_notify     (transport_t *this, int event); -int32_t transport_submit     (transport_t *this, char *buf, int len, -                              struct iovec *vector, int count, -                              struct iobref *iobref); -int32_t transport_receive    (transport_t *this, char **hdr_p, size_t *hdrlen_p, -                              struct iobuf **iobuf_p); -int32_t transport_destroy    (transport_t *this); - -transport_t *transport_load  (dict_t *options, xlator_t *xl); -transport_t *transport_ref   (transport_t *trans); -int32_t      transport_unref (transport_t *trans); - -int transport_setpeer (transport_t *trans, transport_t *trans_peer); - -#endif /* __TRANSPORT_H__ */ diff --git a/xlators/protocol/legacy/server/Makefile.am b/xlators/protocol/legacy/server/Makefile.am deleted file mode 100644 index d471a3f9243..00000000000 --- a/xlators/protocol/legacy/server/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = src - -CLEANFILES =  diff --git a/xlators/protocol/legacy/server/src/Makefile.am b/xlators/protocol/legacy/server/src/Makefile.am deleted file mode 100644 index bfc0b7eb6b1..00000000000 --- a/xlators/protocol/legacy/server/src/Makefile.am +++ /dev/null @@ -1,26 +0,0 @@ - -xlator_LTLIBRARIES = server-old.la -xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/legacy/protocol - -server_old_la_LDFLAGS = -module -avoidversion - -server_old_la_SOURCES = server-protocol.c server-resolve.c server-helpers.c \ -			authenticate.c - -server_old_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la   \ -	$(top_builddir)/xlators/protocol/legacy/lib/src/libgfproto.la - -noinst_HEADERS = server-protocol.h server-helpers.h server-mem-types.h \ -	authenticate.h - -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \ -	-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles \ -	-DDATADIR=\"$(localstatedir)\" -DCONFDIR=\"$(sysconfdir)/glusterfs\" \ -	-DLIBDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/auth\" \ -	$(GF_CFLAGS) -I$(top_srcdir)/xlators/protocol/legacy/lib/src \ -	-I$(top_srcdir)/xlators/protocol/lib/src - -CLEANFILES = - -install-data-hook: -	ln -sf server-old.so $(DESTDIR)$(xlatordir)/server.so diff --git a/xlators/protocol/legacy/server/src/authenticate.c b/xlators/protocol/legacy/server/src/authenticate.c deleted file mode 100644 index a01d7003cd2..00000000000 --- a/xlators/protocol/legacy/server/src/authenticate.c +++ /dev/null @@ -1,249 +0,0 @@ -/* -  Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include <stdio.h> -#include <dlfcn.h> -#include <errno.h> -#include "authenticate.h" - -static void -init (dict_t *this, -      char *key, -      data_t *value, -      void *data) -{ -	void *handle = NULL; -	char *auth_file = NULL; -	auth_handle_t *auth_handle = NULL; -	auth_fn_t authenticate = NULL; -	int *error = NULL; -        int  ret = 0; - -	/* It gets over written */ -	error = data; - -	if (!strncasecmp (key, "ip", strlen ("ip"))) { -		gf_log ("authenticate", GF_LOG_ERROR, -			"AUTHENTICATION MODULE \"IP\" HAS BEEN REPLACED " -			"BY \"ADDR\""); -		dict_set (this, key, data_from_dynptr (NULL, 0)); -		/* TODO: 1.3.x backword compatibility */ -		// *error = -1; -		// return; -		key = "addr"; -	} - -	ret = gf_asprintf (&auth_file, "%s/%s.so", LIBDIR, key); -        if (-1 == ret) { -                gf_log ("authenticate", GF_LOG_ERROR, "asprintf failed"); -                dict_set (this, key, data_from_dynptr (NULL, 0)); -                *error = -1; -                return; -        } - -	handle = dlopen (auth_file, RTLD_LAZY); -	if (!handle) { -		gf_log ("authenticate", GF_LOG_ERROR, "dlopen(%s): %s\n", -			auth_file, dlerror ()); -		dict_set (this, key, data_from_dynptr (NULL, 0)); -		GF_FREE (auth_file); -		*error = -1; -		return; -	} -	GF_FREE (auth_file); - -	authenticate = dlsym (handle, "gf_auth"); -	if (!authenticate) { -		gf_log ("authenticate", GF_LOG_ERROR, -			"dlsym(gf_auth) on %s\n", dlerror ()); -		dict_set (this, key, data_from_dynptr (NULL, 0)); -		*error = -1; -		return; -	} - -	auth_handle = GF_CALLOC (1, sizeof (*auth_handle), -                                 gf_common_mt_auth_handle_t); -	if (!auth_handle) { -		gf_log ("authenticate", GF_LOG_ERROR, "Out of memory"); -		dict_set (this, key, data_from_dynptr (NULL, 0)); -		*error = -1; -		return; -	} -	auth_handle->vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), -                                       gf_common_mt_volume_opt_list_t); -	auth_handle->vol_opt->given_opt = dlsym (handle, "options"); -	if (auth_handle->vol_opt->given_opt == NULL) { -		gf_log ("authenticate", GF_LOG_DEBUG, -			"volume option validation not specified"); -	} - -	auth_handle->authenticate = authenticate; -	auth_handle->handle = handle; - -	dict_set (this, key, -		  data_from_dynptr (auth_handle, sizeof (*auth_handle))); -} - -static void -fini (dict_t *this, -      char *key, -      data_t *value, -      void *data) -{ -	auth_handle_t *handle = data_to_ptr (value); -	if (handle) { -		dlclose (handle->handle); -	} -} - -int32_t -gf_auth_init (xlator_t *xl, dict_t *auth_modules) -{ -	int ret = 0; -	auth_handle_t *handle = NULL; -	data_pair_t *pair = NULL; -	dict_foreach (auth_modules, init, &ret); -	if (!ret) { -		pair = auth_modules->members_list; -		while (pair) { -			handle = data_to_ptr (pair->value); -			if (handle) { -				list_add_tail (&(handle->vol_opt->list), -					       &(xl->volume_options)); -				if (-1 == -				    validate_xlator_volume_options (xl, -								    handle->vol_opt->given_opt)) { -					gf_log ("authenticate", GF_LOG_ERROR, -						"volume option validation " -						"failed"); -					ret = -1; -				} -			} -			pair = pair->next; -		} -	} -	if (ret) { -		gf_log (xl->name, GF_LOG_ERROR, "authentication init failed"); -		dict_foreach (auth_modules, fini, &ret); -		ret = -1; -	} -	return ret; -} - -static dict_t *__input_params; -static dict_t *__config_params; - -void -map (dict_t *this, -     char *key, -     data_t *value, -     void *data) -{ -	dict_t *res = data; -	auth_fn_t authenticate; -	auth_handle_t *handle = NULL; - -	if (value && (handle = data_to_ptr (value)) && -	    (authenticate = handle->authenticate)) { -		dict_set (res, key, -			  int_to_data (authenticate (__input_params, -						     __config_params))); -	} else { -		dict_set (res, key, int_to_data (AUTH_DONT_CARE)); -	} -} - -void -reduce (dict_t *this, -	char *key, -	data_t *value, -	void *data) -{ -	int64_t val = 0; -	int64_t *res = data; -	if (!data) -		return; - -	val = data_to_int64 (value); -	switch (val) -	{ -	case AUTH_ACCEPT: -		if (AUTH_DONT_CARE == *res) -			*res = AUTH_ACCEPT; -		break; - -	case AUTH_REJECT: -		*res = AUTH_REJECT; -		break; - -	case AUTH_DONT_CARE: -		break; -	} -} - - -auth_result_t -gf_authenticate (dict_t *input_params, -		 dict_t *config_params, -		 dict_t *auth_modules) -{ -	dict_t *results = NULL; -	int64_t result = AUTH_DONT_CARE; - -	results = get_new_dict (); -	__input_params = input_params; -	__config_params = config_params; - -	dict_foreach (auth_modules, map, results); - -	dict_foreach (results, reduce, &result); -	if (AUTH_DONT_CARE == result) { -		data_t *peerinfo_data = dict_get (input_params, "peer-info-name"); -		char *name = NULL; - -		if (peerinfo_data) { -			name = peerinfo_data->data; -		} - -		gf_log ("auth", GF_LOG_ERROR, -			"no authentication module is interested in " -			"accepting remote-client %s", name); -		result = AUTH_REJECT; -	} - -	dict_destroy (results); -	return result; -} - -void -gf_auth_fini (dict_t *auth_modules) -{ -	int32_t dummy; - -	dict_foreach (auth_modules, fini, &dummy); -} diff --git a/xlators/protocol/legacy/server/src/authenticate.h b/xlators/protocol/legacy/server/src/authenticate.h deleted file mode 100644 index d35304db266..00000000000 --- a/xlators/protocol/legacy/server/src/authenticate.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -  Copyright (c) 2007-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _AUTHENTICATE_H -#define _AUTHENTICATE_H - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include <stdio.h> -#include <fnmatch.h> -#include "dict.h" -#include "compat.h" -#include "list.h" -#include "xlator.h" - -typedef enum { -	AUTH_ACCEPT, -	AUTH_REJECT, -	AUTH_DONT_CARE -} auth_result_t; - -typedef auth_result_t (*auth_fn_t) (dict_t *input_params, -				    dict_t *config_params); - -typedef struct { -	void              *handle; -	auth_fn_t          authenticate; -	volume_opt_list_t *vol_opt; -} auth_handle_t; - -auth_result_t gf_authenticate (dict_t *input_params, -			       dict_t *config_params, -			       dict_t *auth_modules); -int32_t gf_auth_init (xlator_t *xl, dict_t *auth_modules); -void gf_auth_fini (dict_t *auth_modules); - -#endif /* _AUTHENTICATE_H */ diff --git a/xlators/protocol/legacy/server/src/server-helpers.c b/xlators/protocol/legacy/server/src/server-helpers.c deleted file mode 100644 index 15e46b3d6b8..00000000000 --- a/xlators/protocol/legacy/server/src/server-helpers.c +++ /dev/null @@ -1,622 +0,0 @@ -/* -  Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "server-protocol.h" -#include "server-helpers.h" - - - -void -old_server_loc_wipe (loc_t *loc) -{ -        if (loc->parent) { -                inode_unref (loc->parent); -                loc->parent = NULL; -        } - -        if (loc->inode) { -                inode_unref (loc->inode); -                loc->inode = NULL; -        } - -	if (loc->path) -		GF_FREE ((char *)loc->path); -} - - -static void -old_server_resolve_wipe (server_resolve_t *resolve) -{ -        struct resolve_comp *comp = NULL; -        int                  i = 0; - -        if (resolve->path) -                GF_FREE (resolve->path); - -        if (resolve->bname) -                GF_FREE (resolve->bname); - -        if (resolve->resolved) -                GF_FREE (resolve->resolved); - -        loc_wipe (&resolve->deep_loc); - -        comp = resolve->components; -        if (comp) { -                for (i = 0; comp[i].basename; i++) { -                        if (comp[i].inode) -                                inode_unref (comp[i].inode); -                } -                GF_FREE (resolve->components); -        } -} - - -void -free_old_server_state (server_state_t *state) -{ -        if (state->trans) { -                transport_unref (state->trans); -                state->trans = NULL; -        } - -        if (state->fd) { -                fd_unref (state->fd); -                state->fd = NULL; -        } - -        if (state->params) { -                dict_unref (state->params); -                state->params = NULL; -        } - -        if (state->iobref) { -                iobref_unref (state->iobref); -                state->iobref = NULL; -        } - -        if (state->iobuf) { -                iobuf_unref (state->iobuf); -                state->iobuf = NULL; -        } - -        if (state->dict) { -                dict_unref (state->dict); -                state->dict = NULL; -        } - -        if (state->volume) -                GF_FREE ((char *)state->volume); - -        if (state->name) -                GF_FREE (state->name); - -        old_server_loc_wipe (&state->loc); -        old_server_loc_wipe (&state->loc2); - -        old_server_resolve_wipe (&state->resolve); -        old_server_resolve_wipe (&state->resolve2); - -	GF_FREE (state); -} - -static struct _lock_table * -gf_lock_table_new (void) -{ -        struct _lock_table *new = NULL; - -	new = GF_CALLOC (1, sizeof (struct _lock_table), -                         gf_server_mt_lock_table); -        if (new == NULL) { -                gf_log ("server-protocol", GF_LOG_CRITICAL, -                        "failed to allocate memory for new lock table"); -                goto out; -        } -        INIT_LIST_HEAD (&new->dir_lockers); -        INIT_LIST_HEAD (&new->file_lockers); -        LOCK_INIT (&new->lock); -out: -        return new; -} - - -static int -gf_server_nop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                   int32_t op_ret, int32_t op_errno) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE(frame); - -        if (state) -                free_old_server_state (state); -        STACK_DESTROY (frame->root); -        return 0; -} - - -static int -do_lock_table_cleanup (xlator_t *this, server_connection_t *conn, -                       call_frame_t *frame, struct _lock_table *ltable) -{ -        struct list_head  file_lockers, dir_lockers; -        call_frame_t     *tmp_frame = NULL; -        struct gf_flock      flock = {0, }; -        xlator_t         *bound_xl = NULL; -        struct _locker   *locker = NULL, *tmp = NULL; -        int               ret = -1; - -        bound_xl = conn->bound_xl; -        INIT_LIST_HEAD (&file_lockers); -        INIT_LIST_HEAD (&dir_lockers); - -        LOCK (<able->lock); -        { -                list_splice_init (<able->file_lockers, -                                  &file_lockers); - -                list_splice_init (<able->dir_lockers, &dir_lockers); -        } -        UNLOCK (<able->lock); - -        GF_FREE (ltable); - -        flock.l_type  = F_UNLCK; -        flock.l_start = 0; -        flock.l_len   = 0; -        list_for_each_entry_safe (locker, -                                  tmp, &file_lockers, lockers) { -                tmp_frame = copy_frame (frame); -                if (tmp_frame == NULL) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "out of memory"); -                        goto out; -                } -                /* -                   pid = 0 is a special case that tells posix-locks -                   to release all locks from this transport -                */ -                tmp_frame->root->pid = 0; -                tmp_frame->root->trans = conn; - -                if (locker->fd) { -                        STACK_WIND (tmp_frame, gf_server_nop_cbk, -                                    bound_xl, -                                    bound_xl->fops->finodelk, -                                    locker->volume, -                                    locker->fd, F_SETLK, &flock); -                        fd_unref (locker->fd); -                } else { -                        STACK_WIND (tmp_frame, gf_server_nop_cbk, -                                    bound_xl, -                                    bound_xl->fops->inodelk, -                                    locker->volume, -                                    &(locker->loc), F_SETLK, &flock); -                        loc_wipe (&locker->loc); -                } - -                GF_FREE (locker->volume); -                 -                list_del_init (&locker->lockers); -                GF_FREE (locker); -        } - -        tmp = NULL; -        locker = NULL; -        list_for_each_entry_safe (locker, tmp, &dir_lockers, lockers) { -                tmp_frame = copy_frame (frame); - -                tmp_frame->root->pid = 0; -                tmp_frame->root->trans = conn; - -                if (locker->fd) { -                        STACK_WIND (tmp_frame, gf_server_nop_cbk, -                                    bound_xl, -                                    bound_xl->fops->fentrylk, -                                    locker->volume, -                                    locker->fd, NULL, -                                    ENTRYLK_UNLOCK, ENTRYLK_WRLCK); -                        fd_unref (locker->fd); -                } else { -                        STACK_WIND (tmp_frame, gf_server_nop_cbk, -                                    bound_xl, -                                    bound_xl->fops->entrylk, -                                    locker->volume, -                                    &(locker->loc), NULL, -                                    ENTRYLK_UNLOCK, ENTRYLK_WRLCK); -                        loc_wipe (&locker->loc); -                } - -                GF_FREE (locker->volume); -                 -                list_del_init (&locker->lockers); -                GF_FREE (locker); -        } -        ret = 0; - -out: -        return ret; -} - - -static int -server_connection_cleanup_flush_cbk (call_frame_t *frame, void *cookie, -                                     xlator_t *this, int32_t op_ret, -                                     int32_t op_errno) -{ -        fd_t *fd = NULL; - -        fd = frame->local; - -        fd_unref (fd); -        frame->local = NULL; - -        STACK_DESTROY (frame->root); -        return 0; -} - - -static int -do_fd_cleanup (xlator_t *this, server_connection_t *conn, call_frame_t *frame, -               fdentry_t *fdentries, int fd_count) -{ -        fd_t               *fd = NULL; -        int                 i = 0, ret = -1; -        call_frame_t       *tmp_frame = NULL; -        xlator_t           *bound_xl = NULL; - -        bound_xl = conn->bound_xl; -        for (i = 0;i < fd_count; i++) { -                fd = fdentries[i].fd; - -                if (fd != NULL) { -                        tmp_frame = copy_frame (frame); -                        if (tmp_frame == NULL) { -                                gf_log (this->name, GF_LOG_ERROR, -                                        "out of memory"); -                                goto out; -                        } -                        tmp_frame->local = fd; - -                        tmp_frame->root->pid = 0; -                        tmp_frame->root->trans = conn; -                        tmp_frame->root->lk_owner = 0; -                        STACK_WIND (tmp_frame, -                                    server_connection_cleanup_flush_cbk, -                                    bound_xl, bound_xl->fops->flush, fd); -                } -        } - -        GF_FREE (fdentries); -        ret = 0; - -out: -        return ret; -} - -static int -do_connection_cleanup (xlator_t *this, server_connection_t *conn, -                       struct _lock_table *ltable, fdentry_t *fdentries, int fd_count) -{ -        int             ret = 0; -        int             saved_ret = 0; -        call_frame_t   *frame = NULL; - -        frame = create_frame (this, this->ctx->pool); -        if (frame == NULL) { -                gf_log (this->name, GF_LOG_ERROR, "out of memory"); -                goto out; -        } - -        saved_ret = do_lock_table_cleanup (this, conn, frame, ltable); - -        if (fdentries != NULL) { -                ret = do_fd_cleanup (this, conn, frame, fdentries, fd_count); -        } - -        STACK_DESTROY (frame->root); - -        if (saved_ret || ret) { -                ret = -1; -        } - -out: -        return ret; -} - - -int -gf_server_connection_cleanup (xlator_t *this, server_connection_t *conn) -{ -        char                do_cleanup = 0; -        struct _lock_table *ltable = NULL; -        fdentry_t          *fdentries = NULL; -        uint32_t            fd_count = 0; -        int                 ret = 0;  - -        if (conn == NULL) { -                goto out; -        } - -        pthread_mutex_lock (&conn->lock); -        { -                conn->active_transports--; -                if (conn->active_transports == 0) { -                        if (conn->ltable) { -                                ltable = conn->ltable; -                                conn->ltable = gf_lock_table_new (); -                        } - -                        if (conn->fdtable) { -                                fdentries = gf_fd_fdtable_get_all_fds (conn->fdtable, -                                                                       &fd_count); -                        } -                        do_cleanup = 1; -                } -        } -        pthread_mutex_unlock (&conn->lock); - -        if (do_cleanup && conn->bound_xl) -                ret = do_connection_cleanup (this, conn, ltable, fdentries, fd_count); - -out: -        return ret; -} - - -static int -server_connection_destroy (xlator_t *this, server_connection_t *conn) -{ -        call_frame_t       *frame = NULL, *tmp_frame = NULL; -        xlator_t           *bound_xl = NULL; -        int32_t             ret = -1; -        struct list_head    file_lockers; -        struct list_head    dir_lockers; -        struct _lock_table *ltable = NULL; -        struct _locker     *locker = NULL, *tmp = NULL; -        struct gf_flock        flock = {0,}; -        fd_t               *fd = NULL; -        int32_t             i = 0; -        fdentry_t          *fdentries = NULL; -        uint32_t             fd_count = 0; - -        if (conn == NULL) { -                ret = 0; -                goto out; -        } - -        bound_xl = (xlator_t *) (conn->bound_xl); - -        if (bound_xl) { -                /* trans will have ref_count = 1 after this call, but its -                   ok since this function is called in -                   GF_EVENT_TRANSPORT_CLEANUP */ -                frame = create_frame (this, this->ctx->pool); - -                pthread_mutex_lock (&(conn->lock)); -                { -                        if (conn->ltable) { -                                ltable = conn->ltable; -                                conn->ltable = NULL; -                        } -                } -                pthread_mutex_unlock (&conn->lock); - -                INIT_LIST_HEAD (&file_lockers); -                INIT_LIST_HEAD (&dir_lockers); - -                if (ltable) { -                        LOCK (<able->lock); -                        { -                                list_splice_init (<able->file_lockers, -                                                  &file_lockers); - -                                list_splice_init (<able->dir_lockers, &dir_lockers); -                        } -                        UNLOCK (<able->lock); -                        GF_FREE (ltable); -                } - -                flock.l_type  = F_UNLCK; -                flock.l_start = 0; -                flock.l_len   = 0; -                list_for_each_entry_safe (locker, -                                          tmp, &file_lockers, lockers) { -                        tmp_frame = copy_frame (frame); -                        /* -                           pid = 0 is a special case that tells posix-locks -                           to release all locks from this transport -                        */ -                        tmp_frame->root->pid = 0; -                        tmp_frame->root->trans = conn; - -                        if (locker->fd) { -                                STACK_WIND (tmp_frame, gf_server_nop_cbk, -                                            bound_xl, -                                            bound_xl->fops->finodelk, -                                            locker->volume, -                                            locker->fd, F_SETLK, &flock); -                                fd_unref (locker->fd); -                        } else { -                                STACK_WIND (tmp_frame, gf_server_nop_cbk, -                                            bound_xl, -                                            bound_xl->fops->inodelk, -                                            locker->volume, -                                            &(locker->loc), F_SETLK, &flock); -                                loc_wipe (&locker->loc); -                        } - -                        GF_FREE (locker->volume); - -			list_del_init (&locker->lockers); -			GF_FREE (locker); -		} - -                tmp = NULL; -                locker = NULL; -                list_for_each_entry_safe (locker, tmp, &dir_lockers, lockers) { -                        tmp_frame = copy_frame (frame); - -                        tmp_frame->root->pid = 0; -                        tmp_frame->root->trans = conn; - -                        if (locker->fd) { -                                STACK_WIND (tmp_frame, gf_server_nop_cbk, -                                            bound_xl, -                                            bound_xl->fops->fentrylk, -                                            locker->volume, -                                            locker->fd, NULL, -                                            ENTRYLK_UNLOCK, ENTRYLK_WRLCK); -                                fd_unref (locker->fd); -                        } else { -                                STACK_WIND (tmp_frame, gf_server_nop_cbk, -                                            bound_xl, -                                            bound_xl->fops->entrylk, -                                            locker->volume, -                                            &(locker->loc), NULL, -                                            ENTRYLK_UNLOCK, ENTRYLK_WRLCK); -                                loc_wipe (&locker->loc); -                        } - -                        GF_FREE (locker->volume); - - -			list_del_init (&locker->lockers); -			GF_FREE (locker); -		} - -                pthread_mutex_lock (&(conn->lock)); -                { -                        if (conn->fdtable) { -                                fdentries = gf_fd_fdtable_get_all_fds (conn->fdtable, -                                                                       &fd_count); -                                gf_fd_fdtable_destroy (conn->fdtable); -                                conn->fdtable = NULL; -                        } -                } -                pthread_mutex_unlock (&conn->lock); - -                if (fdentries != NULL) { -                        for (i = 0; i < fd_count; i++) { -                                fd = fdentries[i].fd; -                                if (fd != NULL) { -                                        tmp_frame = copy_frame (frame); -                                        tmp_frame->local = fd; - -                                        STACK_WIND (tmp_frame, -                                                    server_connection_cleanup_flush_cbk, -                                                    bound_xl, -                                                    bound_xl->fops->flush, -                                                    fd); -                                } -                        } -                        GF_FREE (fdentries); -                } -        } - -        if (frame) { -                STACK_DESTROY (frame->root); -        } - -        gf_log (this->name, GF_LOG_INFO, "destroyed connection of %s", -                conn->id); - -	GF_FREE (conn->id); -	GF_FREE (conn); - -out: -        return ret; -} - - -server_connection_t * -gf_server_connection_get (xlator_t *this, const char *id) -{ -	server_connection_t *conn = NULL; -	server_connection_t *trav = NULL; -	server_conf_t       *conf = NULL; - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                list_for_each_entry (trav, &conf->conns, list) { -                        if (!strcmp (id, trav->id)) { -                                conn = trav; -                                break; -                        } -                } - -		if (!conn) { -			conn = (void *) GF_CALLOC (1, sizeof (*conn), -                                        gf_server_mt_server_connection_t); - -			conn->id = gf_strdup (id); -			conn->fdtable = gf_fd_fdtable_alloc (); -			conn->ltable  = gf_lock_table_new (); - -                        pthread_mutex_init (&conn->lock, NULL); - -			list_add (&conn->list, &conf->conns); -		} - -                conn->ref++; -                conn->active_transports++; -	} -	pthread_mutex_unlock (&conf->mutex); - -        return conn; -} - - -void -gf_server_connection_put (xlator_t *this, server_connection_t *conn) -{ -        server_conf_t       *conf = NULL; -        server_connection_t *todel = NULL; - -        if (conn == NULL) { -                goto out; -        } - -        conf = this->private; - -        pthread_mutex_lock (&conf->mutex); -        { -                conn->ref--; - -                if (!conn->ref) { -                        list_del_init (&conn->list); -                        todel = conn; -                } -        } -        pthread_mutex_unlock (&conf->mutex); - -        if (todel) { -                server_connection_destroy (this, todel); -        } - -out: -        return; -} diff --git a/xlators/protocol/legacy/server/src/server-helpers.h b/xlators/protocol/legacy/server/src/server-helpers.h deleted file mode 100644 index cda0c36ef20..00000000000 --- a/xlators/protocol/legacy/server/src/server-helpers.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -  Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef __SERVER_HELPERS_H__ -#define __SERVER_HELPERS_H__ - -#define CALL_STATE(frame)   ((server_state_t *)frame->root->state) - -#define BOUND_XL(frame)     ((xlator_t *) CALL_STATE(frame)->bound_xl) - -#define TRANSPORT_FROM_FRAME(frame) ((transport_t *) CALL_STATE(frame)->trans) - -#define SERVER_CONNECTION(frame)  \ -	((server_connection_t *) TRANSPORT_FROM_FRAME(frame)->xl_private) - -#define SERVER_CONF(frame) \ -	((server_conf_t *)TRANSPORT_FROM_FRAME(frame)->xl->private) - -#define TRANSPORT_FROM_XLATOR(this) ((((server_conf_t *)this->private))->trans) - -#define INODE_LRU_LIMIT(this)						\ -	(((server_conf_t *)(this->private))->inode_lru_limit) - -#define IS_ROOT_INODE(inode) (inode == inode->table->root) - -#define IS_NOT_ROOT(pathlen) ((pathlen > 2)? 1 : 0) - -void free_old_server_state (server_state_t *state); - -void old_server_loc_wipe (loc_t *loc); - -#endif /* __SERVER_HELPERS_H__ */ diff --git a/xlators/protocol/legacy/server/src/server-mem-types.h b/xlators/protocol/legacy/server/src/server-mem-types.h deleted file mode 100644 index 5e15fd90f71..00000000000 --- a/xlators/protocol/legacy/server/src/server-mem-types.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -   Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -   This file is part of GlusterFS. - -   GlusterFS is free software; you can redistribute it and/or modify -   it under the terms of the GNU General Public License as published -   by the Free Software Foundation; either version 3 of the License, -   or (at your option) any later version. - -   GlusterFS is distributed in the hope that it will be useful, but -   WITHOUT ANY WARRANTY; without even the implied warranty of -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -   General Public License for more details. - -   You should have received a copy of the GNU General Public License -   along with this program.  If not, see -   <http://www.gnu.org/licenses/>. -*/ - - -#ifndef __AFR_MEM_TYPES_H__ -#define __AFR_MEM_TYPES_H__ - -#include "mem-types.h" - -enum gf_server_mem_types_ { -        gf_server_mt_dir_entry_t = gf_common_mt_end + 1, -        gf_server_mt_volfile_ctx, -        gf_server_mt_server_state_t, -        gf_server_mt_server_conf_t, -        gf_server_mt_locker, -        gf_server_mt_lock_table, -        gf_server_mt_char, -        gf_server_mt_server_connection_t, -        gf_server_mt_resolve_comp, -        gf_server_mt_end -}; -#endif - diff --git a/xlators/protocol/legacy/server/src/server-protocol.c b/xlators/protocol/legacy/server/src/server-protocol.c deleted file mode 100644 index 0686398d10a..00000000000 --- a/xlators/protocol/legacy/server/src/server-protocol.c +++ /dev/null @@ -1,6587 +0,0 @@ -/* -  Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif -#include <time.h> -#include <sys/uio.h> -#include <sys/resource.h> - -#include <libgen.h> - -#include "transport.h" -#include "fnmatch.h" -#include "xlator.h" -#include "protocol.h" -#include "server-protocol.h" -#include "server-helpers.h" -#include "call-stub.h" -#include "defaults.h" -#include "list.h" -#include "dict.h" -#include "compat.h" -#include "compat-errno.h" -#include "statedump.h" -#include "md5.h" - - -static void -print_caller (char *str, int size, call_frame_t *frame) -{ -        int              filled = 0; -        server_state_t  *state = NULL; -        transport_t     *trans = NULL; - -        state = CALL_STATE (frame); -        trans = state->trans; - -        filled += snprintf (str + filled, size - filled, -                            " Callid=%"PRId64", Client=%s", -                            frame->root->unique, -                            trans->peerinfo.identifier); - -        return; -} - - -static void -server_print_resolve (char *str, int size, server_resolve_t *resolve) -{ -        int filled = 0; - -        if (!resolve) { -                snprintf (str, size, "<nul>"); -                return; -        } - -        filled += snprintf (str + filled, size - filled, -                            " Resolve={"); -        if (resolve->fd_no != -1) -                filled += snprintf (str + filled, size - filled, -                                    "fd=%"PRId64",", (uint64_t) resolve->fd_no); -        if (resolve->ino) -                filled += snprintf (str + filled, size - filled, -                                    "ino=%"PRIu64",", (uint64_t) resolve->ino); -        if (resolve->par) -                filled += snprintf (str + filled, size - filled, -                                    "par=%"PRIu64",", (uint64_t) resolve->par); -        if (resolve->gen) -                filled += snprintf (str + filled, size - filled, -                                    "gen=%"PRIu64",", (uint64_t) resolve->gen); -        if (resolve->bname) -                filled += snprintf (str + filled, size - filled, -                                    "bname=%s,", resolve->bname); -        if (resolve->path) -                filled += snprintf (str + filled, size - filled, -                                    "path=%s", resolve->path); - -        filled += snprintf (str + filled, size - filled, "}"); -} - - -static void -server_print_loc (char *str, int size, loc_t *loc) -{ -        int filled = 0; - -        if (!loc) { -                snprintf (str, size, "<nul>"); -                return; -        } - -        filled += snprintf (str + filled, size - filled, -                            " Loc={"); - -        if (loc->path) -                filled += snprintf (str + filled, size - filled, -                                    "path=%s,", loc->path); -        if (loc->inode) -                filled += snprintf (str + filled, size - filled, -                                    "inode=%p,", loc->inode); -        if (loc->parent) -                filled += snprintf (str + filled, size - filled, -                                    "parent=%p", loc->parent); - -        filled += snprintf (str + filled, size - filled, "}"); -} - - -static void -server_print_params (char *str, int size, server_state_t *state) -{ -        int filled = 0; - -        filled += snprintf (str + filled, size - filled, -                            " Params={"); - -        if (state->fd) -                filled += snprintf (str + filled, size - filled, -                                    "fd=%p,", state->fd); -        if (state->valid) -                filled += snprintf (str + filled, size - filled, -                                    "valid=%d,", state->valid); -        if (state->flags) -                filled += snprintf (str + filled, size - filled, -                                    "flags=%d,", state->flags); -        if (state->wbflags) -                filled += snprintf (str + filled, size - filled, -                                    "wbflags=%d,", state->wbflags); -        if (state->size) -                filled += snprintf (str + filled, size - filled, -                                    "size=%zu,", state->size); -        if (state->offset) -                filled += snprintf (str + filled, size - filled, -                                    "offset=%"PRId64",", state->offset); -        if (state->cmd) -                filled += snprintf (str + filled, size - filled, -                                    "cmd=%d,", state->cmd); -        if (state->type) -                filled += snprintf (str + filled, size - filled, -                                    "type=%d,", state->type); -        if (state->name) -                filled += snprintf (str + filled, size - filled, -                                    "name=%s,", state->name); -        if (state->mask) -                filled += snprintf (str + filled, size - filled, -                                    "mask=%d,", state->mask); -        if (state->volume) -                filled += snprintf (str + filled, size - filled, -                                    "volume=%s,", state->volume); - -        filled += snprintf (str + filled, size - filled, -                            "bound_xl=%s}", state->bound_xl->name); -} - - -static int -server_resolve_is_empty (server_resolve_t *resolve) -{ -        if (resolve->fd_no != -1) -                return 0; - -        if (resolve->ino != 0) -                return 0; - -        if (resolve->gen != 0) -                return 0; - -        if (resolve->par != 0) -                return 0; - -        if (resolve->path != 0) -                return 0; - -        if (resolve->bname != 0) -                return 0; - -        return 1; -} - -void -gf_server_print_request (call_frame_t *frame) -{ -        server_conf_t   *conf = NULL; -        xlator_t        *this = NULL; -        server_state_t  *state = NULL; -        char             resolve_vars[256]; -        char             resolve2_vars[256]; -        char             loc_vars[256]; -        char             loc2_vars[256]; -        char             other_vars[512]; -        char             caller[512]; -        char            *op = "UNKNOWN"; - -        this = frame->this; -        conf = this->private; - -        state = CALL_STATE (frame); - -        if (!conf->trace) -                return; - -        memset (resolve_vars, '\0', 256); -        memset (resolve2_vars, '\0', 256); -        memset (loc_vars, '\0', 256); -        memset (loc2_vars, '\0', 256); -        memset (other_vars, '\0', 256); - -        print_caller (caller, 256, frame); - -        if (!server_resolve_is_empty (&state->resolve)) { -                server_print_resolve (resolve_vars, 256, &state->resolve); -                server_print_loc (loc_vars, 256, &state->loc); -        } - -        if (!server_resolve_is_empty (&state->resolve2)) { -                server_print_resolve (resolve2_vars, 256, &state->resolve2); -                server_print_loc (loc2_vars, 256, &state->loc2); -        } - -        server_print_params (other_vars, 512, state); - -        switch (frame->root->type) { -        case GF_OP_TYPE_FOP_REQUEST: -        case GF_OP_TYPE_FOP_REPLY: -                op = gf_fop_list[frame->root->op]; -                break; -        case GF_OP_TYPE_MOP_REQUEST: -        case GF_OP_TYPE_MOP_REPLY: -                op = gf_mop_list[frame->root->op]; -                break; -        case GF_OP_TYPE_CBK_REQUEST: -        case GF_OP_TYPE_CBK_REPLY: -                op = gf_cbk_list[frame->root->op]; -                break; -        } - -        gf_log (this->name, GF_LOG_INFO, -                "%s%s%s%s%s%s%s", -                gf_fop_list[frame->root->op], caller, -                resolve_vars, loc_vars, resolve2_vars, loc2_vars, other_vars); -} - - -static void -server_print_reply (call_frame_t *frame, int op_ret, int op_errno) -{ -        server_conf_t   *conf = NULL; -        server_state_t  *state = NULL; -        xlator_t        *this = NULL; -        char             caller[512]; -        char             fdstr[32]; -        char            *op = "UNKNOWN"; - -        this = frame->this; -        conf = this->private; - -        if (!conf->trace) -                return; - -        state = CALL_STATE (frame); - -        print_caller (caller, 256, frame); - -        switch (frame->root->type) { -        case GF_OP_TYPE_FOP_REQUEST: -        case GF_OP_TYPE_FOP_REPLY: -                op = gf_fop_list[frame->root->op]; -                break; -        case GF_OP_TYPE_MOP_REQUEST: -        case GF_OP_TYPE_MOP_REPLY: -                op = gf_mop_list[frame->root->op]; -                break; -        case GF_OP_TYPE_CBK_REQUEST: -        case GF_OP_TYPE_CBK_REPLY: -                op = gf_cbk_list[frame->root->op]; -                break; -        } - -        fdstr[0] = '\0'; -        if (state->fd) -                snprintf (fdstr, 32, " fd=%p", state->fd); - -        gf_log (this->name, GF_LOG_INFO, -                "%s%s => (%d, %d)%s", -                op, caller, op_ret, op_errno, fdstr); -} - - - -static void -protocol_server_reply (call_frame_t *frame, int type, int op, -                       gf_hdr_common_t *hdr, size_t hdrlen, -                       struct iovec *vector, int count, -                       struct iobref *iobref) -{ -        server_state_t *state = NULL; -        xlator_t       *bound_xl = NULL; -        transport_t    *trans = NULL; -        int             ret = 0; - -        xlator_t       *this = NULL; - -        bound_xl = BOUND_XL (frame); -        state    = CALL_STATE (frame); -        trans    = state->trans; -        this     = frame->this; - -        hdr->callid = hton64 (frame->root->unique); -        hdr->type   = hton32 (type); -        hdr->op     = hton32 (op); - -        server_print_reply (frame, ntoh32 (hdr->rsp.op_ret), -                            gf_error_to_errno (ntoh32 (hdr->rsp.op_errno))); - -        ret = transport_submit (trans, (char *)hdr, hdrlen, vector, -                                count, iobref); -        if (ret < 0) { -                gf_log ("protocol/server", GF_LOG_ERROR, -                        "frame %"PRId64": failed to submit. op= %d, type= %d", -                        frame->root->unique, op, type); -        } - -        STACK_DESTROY (frame->root); - -        if (state) -                free_old_server_state (state); - -} - - -static int -gf_add_locker (struct _lock_table *table, const char *volume, -               loc_t *loc, fd_t *fd, pid_t pid) -{ -        int32_t         ret = -1; -        struct _locker *new = NULL; -        uint8_t         dir = 0; - -	new = GF_CALLOC (1, sizeof (struct _locker), -                         gf_server_mt_locker); -        if (new == NULL) { -                gf_log ("server", GF_LOG_ERROR, -                        "failed to allocate memory for \'struct _locker\'"); -                goto out; -        } -        INIT_LIST_HEAD (&new->lockers); - -        new->volume = gf_strdup (volume); - -        if (fd == NULL) { -                loc_copy (&new->loc, loc); -                dir = IA_ISDIR (new->loc.inode->ia_type); -        } else { -                new->fd = fd_ref (fd); -                dir = IA_ISDIR (fd->inode->ia_type); -        } - -        new->pid = pid; - -        LOCK (&table->lock); -        { -                if (dir) -                        list_add_tail (&new->lockers, &table->dir_lockers); -                else -                        list_add_tail (&new->lockers, &table->file_lockers); -        } -        UNLOCK (&table->lock); -out: -        return ret; -} - - -static int -gf_del_locker (struct _lock_table *table, const char *volume, -               loc_t *loc, fd_t *fd, pid_t pid) -{ -        struct _locker    *locker = NULL; -        struct _locker    *tmp = NULL; -        int32_t            ret = 0; -        uint8_t            dir = 0; -        struct list_head  *head = NULL; -        struct list_head   del; - -        INIT_LIST_HEAD (&del); - -        if (fd) { -                dir = IA_ISDIR (fd->inode->ia_type); -        } else { -                dir = IA_ISDIR (loc->inode->ia_type); -        } - -        LOCK (&table->lock); -        { -                if (dir) { -                        head = &table->dir_lockers; -                } else { -                        head = &table->file_lockers; -                } - -                list_for_each_entry_safe (locker, tmp, head, lockers) { -                        if (locker->fd && fd && -                            (locker->fd == fd) && (locker->pid == pid) -                            && !strcmp (locker->volume, volume)) { -                                list_move_tail (&locker->lockers, &del); -                        } else if (locker->loc.inode && -                                   loc && -                                   (locker->loc.inode == loc->inode) && -                                   (locker->pid == pid) -                                   && !strcmp (locker->volume, volume)) { -                                list_move_tail (&locker->lockers, &del); -                        } -                } -        } -        UNLOCK (&table->lock); - -        tmp = NULL; -        locker = NULL; - -        list_for_each_entry_safe (locker, tmp, &del, lockers) { -                list_del_init (&locker->lockers); -                if (locker->fd) -                        fd_unref (locker->fd); -                else -                        loc_wipe (&locker->loc); - -                GF_FREE (locker->volume); -		GF_FREE (locker); -	} - -        return ret; -} - - -/* - * server_lk_cbk - lk callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @lock: - * - * not for external reference - */ -static int -server_lk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -               int32_t op_ret, int32_t op_errno, struct gf_flock *lock) -{ -        gf_hdr_common_t     *hdr = NULL; -        gf_fop_lk_rsp_t     *rsp = NULL; -        size_t               hdrlen = 0; -        int32_t              gf_errno = 0; -        server_state_t      *state = NULL; - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret == 0) { -                gf_flock_from_flock (&rsp->flock, lock); -        } else if (op_errno != ENOSYS) { -                state = CALL_STATE(frame); - -                gf_log (this->name, GF_LOG_TRACE, -                        "%"PRId64": LK %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->resolve.fd_no, -                        state->fd ? state->fd->inode->ino : 0, op_ret, -                        strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_LK, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -static int -server_inodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                    int32_t op_ret, int32_t op_errno) -{ -        server_connection_t  *conn = NULL; -        gf_hdr_common_t      *hdr = NULL; -        gf_fop_inodelk_rsp_t *rsp = NULL; -        server_state_t       *state = NULL; -        size_t                hdrlen = 0; -        int32_t               gf_errno = 0; - -        conn = SERVER_CONNECTION(frame); - -        state = CALL_STATE(frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret >= 0) { -                if (state->flock.l_type == F_UNLCK) -                        gf_del_locker (conn->ltable, state->volume, -                                       &state->loc, NULL, frame->root->pid); -                else -                        gf_add_locker (conn->ltable, state->volume, -                                       &state->loc, NULL, frame->root->pid); -        } else if (op_errno != ENOSYS) { -                gf_log (this->name, GF_LOG_TRACE, -                        "%"PRId64": INODELK %s (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        state->loc.inode ? state->loc.inode->ino : 0, op_ret, -                        strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_INODELK, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -static int -server_finodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                     int32_t op_ret, int32_t op_errno) -{ -        server_connection_t   *conn = NULL; -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_finodelk_rsp_t *rsp = NULL; -        server_state_t        *state = NULL; -        size_t                 hdrlen = 0; -        int32_t                gf_errno = 0; - -        conn = SERVER_CONNECTION(frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        state = CALL_STATE(frame); - -        if (op_ret >= 0) { -                if (state->flock.l_type == F_UNLCK) -                        gf_del_locker (conn->ltable, state->volume, -                                       NULL, state->fd, -                                       frame->root->pid); -                else -                        gf_add_locker (conn->ltable, state->volume, -                                       NULL, state->fd, -                                       frame->root->pid); -        } else if (op_errno != ENOSYS) { -                gf_log (this->name, GF_LOG_TRACE, -                        "%"PRId64": FINODELK %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->resolve.fd_no, -                        state->fd ? state->fd->inode->ino : 0, op_ret, -                        strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FINODELK, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -/* - * server_entrylk_cbk - - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @lock: - * - * not for external reference - */ -static int -server_entrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                    int32_t op_ret, int32_t op_errno) -{ -        server_connection_t  *conn = NULL; -        gf_hdr_common_t      *hdr = NULL; -        gf_fop_entrylk_rsp_t *rsp = NULL; -        server_state_t       *state = NULL; -        size_t                hdrlen = 0; -        int32_t               gf_errno = 0; - -        conn = SERVER_CONNECTION(frame); - -        state = CALL_STATE(frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret >= 0) { -                if (state->cmd == ENTRYLK_UNLOCK) -                        gf_del_locker (conn->ltable, state->volume, -                                       &state->loc, NULL, frame->root->pid); -                else -                        gf_add_locker (conn->ltable, state->volume, -                                       &state->loc, NULL, frame->root->pid); -        } else if (op_errno != ENOSYS) { -                gf_log (this->name, GF_LOG_TRACE, -                        "%"PRId64": INODELK %s (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        state->loc.inode ? state->loc.inode->ino : 0, op_ret, -                        strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_ENTRYLK, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -static int -server_fentrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                     int32_t op_ret, int32_t op_errno) -{ -        server_connection_t   *conn = NULL; -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_fentrylk_rsp_t *rsp = NULL; -        server_state_t        *state = NULL; -        size_t                 hdrlen = 0; -        int32_t                gf_errno = 0; - -        conn = SERVER_CONNECTION(frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        state = CALL_STATE(frame); -        if (op_ret >= 0) { -                if (state->cmd == ENTRYLK_UNLOCK) -                        gf_del_locker (conn->ltable, state->volume, -                                       NULL, state->fd, frame->root->pid); -                else -                        gf_add_locker (conn->ltable, state->volume, -                                       NULL, state->fd, frame->root->pid); -        } else if (op_errno != ENOSYS) { -                gf_log (this->name, GF_LOG_TRACE, -                        "%"PRId64": FENTRYLK %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->resolve.fd_no, -                        state->fd ? state->fd->inode->ino : 0, op_ret, -                        strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FENTRYLK, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -/* - * server_access_cbk - access callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_access_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                   int32_t op_ret, int32_t op_errno) -{ -        gf_hdr_common_t     *hdr = NULL; -        gf_fop_access_rsp_t *rsp = NULL; -        server_state_t      *state = NULL; -        size_t               hdrlen = 0; -        int32_t              gf_errno = 0; - -        state = CALL_STATE(frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_ACCESS, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_rmdir_cbk - rmdir callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                  int32_t op_ret, int32_t op_errno, struct iatt *preparent, -                  struct iatt *postparent) -{ -        gf_hdr_common_t    *hdr = NULL; -        gf_fop_rmdir_rsp_t *rsp = NULL; -        server_state_t     *state = NULL; -        int32_t             gf_errno = 0; -        size_t              hdrlen = 0; -        inode_t            *parent = NULL; - -        state = CALL_STATE(frame); - -        if (op_ret == 0) { -                inode_unlink (state->loc.inode, state->loc.parent, -                              state->loc.name); -                parent = inode_parent (state->loc.inode, 0, NULL); -                if (parent) -                        inode_unref (parent); -                else -                        inode_forget (state->loc.inode, 0); -        } else { -                gf_log (this->name, GF_LOG_TRACE, -                        "%"PRId64": RMDIR %s (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        state->loc.inode ? state->loc.inode->ino : 0, -                        op_ret, strerror (op_errno)); -        } - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret == 0) { -                gf_stat_from_iatt (&rsp->preparent, preparent); -                gf_stat_from_iatt (&rsp->postparent, postparent); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_RMDIR, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_mkdir_cbk - mkdir callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                  int32_t op_ret, int32_t op_errno, inode_t *inode, -                  struct iatt *stbuf, struct iatt *preparent, -                  struct iatt *postparent) -{ -        gf_hdr_common_t    *hdr = NULL; -        gf_fop_mkdir_rsp_t *rsp = NULL; -        server_state_t     *state = NULL; -        size_t              hdrlen = 0; -        int32_t             gf_errno = 0; -        inode_t            *link_inode = NULL; - -        state = CALL_STATE(frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret >= 0) { -                gf_stat_from_iatt (&rsp->stat, stbuf); -                gf_stat_from_iatt (&rsp->preparent, preparent); -                gf_stat_from_iatt (&rsp->postparent, postparent); - -                link_inode = inode_link (inode, state->loc.parent, -                                         state->loc.name, stbuf); -                inode_lookup (link_inode); -                inode_unref (link_inode); -        } else { -                gf_log (this->name, GF_LOG_TRACE, -                        "%"PRId64": MKDIR %s  ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        op_ret, strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_MKDIR, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_mknod_cbk - mknod callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                  int32_t op_ret, int32_t op_errno, -                  inode_t *inode, struct iatt *stbuf, struct iatt *preparent, -                  struct iatt *postparent) -{ -        gf_hdr_common_t    *hdr = NULL; -        gf_fop_mknod_rsp_t *rsp = NULL; -        server_state_t     *state = NULL; -        int32_t             gf_errno = 0; -        size_t              hdrlen = 0; -        inode_t            *link_inode = NULL; - -        state = CALL_STATE(frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret >= 0) { -                gf_stat_from_iatt (&rsp->stat, stbuf); -                gf_stat_from_iatt (&rsp->preparent, preparent); -                gf_stat_from_iatt (&rsp->postparent, postparent); - -                link_inode = inode_link (inode, state->loc.parent, -                                         state->loc.name, stbuf); -                inode_lookup (link_inode); -                inode_unref (link_inode); -        } else { -                gf_log (this->name, GF_LOG_TRACE, -                        "%"PRId64": MKNOD %s ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        op_ret, strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_MKNOD, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_fsyncdir_cbk - fsyncdir callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_fsyncdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                     int32_t op_ret, int32_t op_errno) -{ -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_fsyncdir_rsp_t *rsp = NULL; -        size_t                 hdrlen = 0; -        int32_t                gf_errno = 0; -        server_state_t        *state = NULL; - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        if (op_ret < 0) { -                state = CALL_STATE(frame); - -                gf_log (this->name, GF_LOG_TRACE, -                        "%"PRId64": FSYNCDIR %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->resolve.fd_no, -                        state->fd ? state->fd->inode->ino : 0, op_ret, -                        strerror (op_errno)); -        } - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FSYNCDIR, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - - -/* - * server_readdir_cbk - getdents callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                    int32_t op_ret, int32_t op_errno, gf_dirent_t *entries) -{ -        gf_hdr_common_t      *hdr = NULL; -        gf_fop_readdir_rsp_t *rsp = NULL; -        size_t                hdrlen = 0; -        size_t                buf_size = 0; -        int32_t               gf_errno = 0; -        server_state_t       *state = NULL; - -        if (op_ret > 0) -                buf_size = gf_dirent_serialize (entries, NULL, 0); - -        hdrlen = gf_hdr_len (rsp, buf_size); -        hdr    = gf_hdr_new (rsp, buf_size); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret > 0) { -                rsp->size = hton32 (buf_size); -                gf_dirent_serialize (entries, rsp->buf, buf_size); -        } else { -                state = CALL_STATE(frame); - -                gf_log (this->name, GF_LOG_TRACE, -                        "%"PRId64": READDIR %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->resolve.fd_no, -                        state->fd ? state->fd->inode->ino : 0, op_ret, -                        strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_READDIR, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -/* - * server_releasedir_cbk - releasedir callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * - * not for external reference - */ -static int -server_releasedir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                       int32_t op_ret, int32_t op_errno) -{ -        gf_hdr_common_t         *hdr = NULL; -        gf_cbk_releasedir_rsp_t *rsp = NULL; -        size_t                   hdrlen = 0; -        int32_t                  gf_errno = 0; - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        protocol_server_reply (frame, GF_OP_TYPE_CBK_REPLY, GF_CBK_RELEASEDIR, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -/* - * server_opendir_cbk - opendir callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * @fd: file descriptor structure of opened directory - * - * not for external reference - */ -static int -server_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                    int32_t op_ret, int32_t op_errno, fd_t *fd) -{ -        server_connection_t   *conn = NULL; -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_opendir_rsp_t  *rsp = NULL; -        server_state_t        *state = NULL; -        size_t                 hdrlen = 0; -        int32_t                gf_errno = 0; -        uint64_t               fd_no = 0; - -        conn = SERVER_CONNECTION (frame); - -        state = CALL_STATE (frame); - -        if (op_ret >= 0) { -                fd_bind (fd); - -                fd_no = gf_fd_unused_get (conn->fdtable, fd); -                fd_ref (fd); // on behalf of the client -        } else { -                gf_log (this->name, GF_LOG_TRACE, -                        "%"PRId64": OPENDIR %s (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        state->loc.inode ? state->loc.inode->ino : 0, -                        op_ret, strerror (op_errno)); -        } - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); -        rsp->fd           = hton64 (fd_no); - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_OPENDIR, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_statfs_cbk - statfs callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * @buf: - * - * not for external reference - */ -static int -server_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                   int32_t op_ret, int32_t op_errno, struct statvfs *buf) -{ -        gf_hdr_common_t     *hdr = NULL; -        gf_fop_statfs_rsp_t *rsp = NULL; -        server_state_t      *state = NULL; -        size_t               hdrlen = 0; -        int32_t              gf_errno = 0; - -        state = CALL_STATE (frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret >= 0) { -                gf_statfs_from_statfs (&rsp->statfs, buf); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_STATFS, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_removexattr_cbk - removexattr callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * - * not for external reference - */ -static int -server_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                        int32_t op_ret, int32_t op_errno) -{ -        gf_hdr_common_t          *hdr = NULL; -        gf_fop_removexattr_rsp_t *rsp = NULL; -        server_state_t           *state = NULL; -        size_t                    hdrlen = 0; -        int32_t                   gf_errno = 0; - -        state = CALL_STATE (frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_REMOVEXATTR, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_getxattr_cbk - getxattr callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * @value: - * - * not for external reference - */ -static int -server_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                     int32_t op_ret, int32_t op_errno, dict_t *dict) -{ -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_getxattr_rsp_t *rsp = NULL; -        server_state_t        *state = NULL; -        size_t                 hdrlen = 0; -        int32_t                len = 0; -        int32_t                gf_errno = 0; -        int32_t                ret = -1; - -        state = CALL_STATE (frame); - -        if (op_ret >= 0) { -                len = dict_serialized_length (dict); -                if (len < 0) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "%s (%"PRId64"): failed to get serialized length of " -                                "reply dict", -                                state->loc.path, state->resolve.ino); -                        op_ret   = -1; -                        op_errno = EINVAL; -                        len = 0; -                } -        } - -        hdrlen = gf_hdr_len (rsp, len + 1); -        hdr    = gf_hdr_new (rsp, len + 1); -        rsp    = gf_param (hdr); - -        if (op_ret >= 0) { -                ret = dict_serialize (dict, rsp->dict); -                if (len < 0) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "%s (%"PRId64"): failed to serialize reply dict", -                                state->loc.path, state->resolve.ino); -                        op_ret = -1; -                        op_errno = -ret; -                } -        } -        rsp->dict_len = hton32 (len); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_GETXATTR, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -static int -server_fgetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                      int32_t op_ret, int32_t op_errno, dict_t *dict) -{ -        gf_hdr_common_t        *hdr  = NULL; -        gf_fop_fgetxattr_rsp_t *rsp = NULL; -        server_state_t         *state = NULL; -        size_t                  hdrlen = 0; -        int32_t                 len = 0; -        int32_t                 gf_errno = 0; -        int32_t                 ret = -1; - -        state = CALL_STATE (frame); - -        if (op_ret >= 0) { -                len = dict_serialized_length (dict); -                if (len < 0) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "%s (%"PRId64"): failed to get serialized length of " -                                "reply dict", -                                state->loc.path, state->resolve.ino); -                        op_ret   = -1; -                        op_errno = EINVAL; -                        len = 0; -                } -        } - -        hdrlen = gf_hdr_len (rsp, len + 1); -        hdr    = gf_hdr_new (rsp, len + 1); -        rsp    = gf_param (hdr); - -        if (op_ret >= 0) { -                ret = dict_serialize (dict, rsp->dict); -                if (len < 0) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "%s (%"PRId64"): failed to serialize reply dict", -                                state->loc.path, state->resolve.ino); -                        op_ret = -1; -                        op_errno = -ret; -                } -        } -        rsp->dict_len = hton32 (len); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FGETXATTR, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -/* - * server_setxattr_cbk - setxattr callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * - * not for external reference - */ -static int -server_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                     int32_t op_ret, int32_t op_errno) -{ -        gf_hdr_common_t        *hdr = NULL; -        gf_fop_setxattr_rsp_t  *rsp = NULL; -        server_state_t         *state = NULL; -        size_t                  hdrlen = 0; -        int32_t                 gf_errno = 0; - -        state = CALL_STATE (frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_SETXATTR, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -static int -server_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                      int32_t op_ret, int32_t op_errno) -{ -        gf_hdr_common_t        *hdr = NULL; -        gf_fop_fsetxattr_rsp_t *rsp = NULL; -        server_state_t         *state = NULL; -        size_t                  hdrlen = 0; -        int32_t                 gf_errno = 0; - -        state = CALL_STATE(frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FSETXATTR, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -/* - * server_rename_cbk - rename callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * - * not for external reference - */ -static int -server_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                   int32_t op_ret, int32_t op_errno, struct iatt *stbuf, -                   struct iatt *preoldparent, struct iatt *postoldparent, -                   struct iatt *prenewparent, struct iatt *postnewparent) -{ -        gf_hdr_common_t     *hdr = NULL; -        gf_fop_rename_rsp_t *rsp = NULL; -        server_state_t      *state = NULL; -        size_t               hdrlen = 0; -        int32_t              gf_errno = 0; - -        state = CALL_STATE(frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret == 0) { -                stbuf->ia_ino  = state->loc.inode->ino; -                stbuf->ia_type = state->loc.inode->ia_type; - -                gf_log (state->bound_xl->name, GF_LOG_TRACE, -                        "%"PRId64": RENAME_CBK (%"PRId64") %"PRId64"/%s " -                        "==> %"PRId64"/%s", -                        frame->root->unique, state->loc.inode->ino, -                        state->loc.parent->ino, state->loc.name, -                        state->loc2.parent->ino, state->loc2.name); - -                inode_rename (state->itable, -                              state->loc.parent, state->loc.name, -                              state->loc2.parent, state->loc2.name, -                              state->loc.inode, stbuf); -                gf_stat_from_iatt (&rsp->stat, stbuf); - -                gf_stat_from_iatt (&rsp->preoldparent, preoldparent); -                gf_stat_from_iatt (&rsp->postoldparent, postoldparent); - -                gf_stat_from_iatt (&rsp->prenewparent, prenewparent); -                gf_stat_from_iatt (&rsp->postnewparent, postnewparent); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_RENAME, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -/* - * server_unlink_cbk - unlink callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * - * not for external reference - */ -static int -server_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                   int32_t op_ret, int32_t op_errno, struct iatt *preparent, -                   struct iatt *postparent) -{ -        gf_hdr_common_t      *hdr = NULL; -        gf_fop_unlink_rsp_t  *rsp = NULL; -        server_state_t       *state = NULL; -        size_t                hdrlen = 0; -        int32_t               gf_errno = 0; -        inode_t              *parent = NULL; - -        state = CALL_STATE(frame); - -        if (op_ret == 0) { -                gf_log (state->bound_xl->name, GF_LOG_TRACE, -                        "%"PRId64": UNLINK_CBK %"PRId64"/%s (%"PRId64")", -                        frame->root->unique, state->loc.parent->ino, -                        state->loc.name, state->loc.inode->ino); - -                inode_unlink (state->loc.inode, state->loc.parent, -                              state->loc.name); - -                parent = inode_parent (state->loc.inode, 0, NULL); -                if (parent) -                        inode_unref (parent); -                else -                        inode_forget (state->loc.inode, 0); -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": UNLINK %s (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        state->loc.inode ? state->loc.inode->ino : 0, -                        op_ret, strerror (op_errno)); -        } - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret == 0) { -                gf_stat_from_iatt (&rsp->preparent, preparent); -                gf_stat_from_iatt (&rsp->postparent, postparent); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_UNLINK, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_symlink_cbk - symlink callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: return value - * @op_errno: errno - * - * not for external reference - */ -static int -server_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                    int32_t op_ret, int32_t op_errno, inode_t *inode, -                    struct iatt *stbuf, struct iatt *preparent, -                    struct iatt *postparent) -{ -        gf_hdr_common_t      *hdr = NULL; -        gf_fop_symlink_rsp_t *rsp = NULL; -        server_state_t       *state = NULL; -        size_t                hdrlen = 0; -        int32_t               gf_errno = 0; -        inode_t              *link_inode = NULL; - -        state = CALL_STATE(frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno_to_error (op_errno)); - -        if (op_ret >= 0) { -                gf_stat_from_iatt (&rsp->stat, stbuf); -                gf_stat_from_iatt (&rsp->preparent, preparent); -                gf_stat_from_iatt (&rsp->postparent, postparent); - -                link_inode = inode_link (inode, state->loc.parent, -                                         state->loc.name, stbuf); -                inode_lookup (link_inode); -                inode_unref (link_inode); -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": SYMLINK %s (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        state->loc.inode ? state->loc.inode->ino : 0, -                        op_ret, strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_SYMLINK, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -/* - * server_link_cbk - link callback for server protocol - * @frame: call frame - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                 int32_t op_ret, int32_t op_errno, inode_t *inode, -                 struct iatt *stbuf, struct iatt *preparent, -                 struct iatt *postparent) -{ -        gf_hdr_common_t   *hdr = NULL; -        gf_fop_link_rsp_t *rsp = NULL; -        server_state_t    *state = NULL; -        int32_t            gf_errno = 0; -        size_t             hdrlen = 0; -        inode_t           *link_inode = NULL; - -        state = CALL_STATE(frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret == 0) { -                stbuf->ia_ino = state->loc.inode->ino; - -                gf_stat_from_iatt (&rsp->stat, stbuf); -                gf_stat_from_iatt (&rsp->preparent, preparent); -                gf_stat_from_iatt (&rsp->postparent, postparent); - -                gf_log (state->bound_xl->name, GF_LOG_TRACE, -                        "%"PRId64": LINK (%"PRId64") %"PRId64"/%s ==> %"PRId64"/%s", -                        frame->root->unique, inode->ino, -                        state->loc2.parent->ino, -                        state->loc2.name, state->loc.parent->ino, -                        state->loc.name); - -                link_inode = inode_link (inode, state->loc2.parent, -                                         state->loc2.name, stbuf); -                inode_unref (link_inode); -        } else { -                gf_log (state->bound_xl->name, GF_LOG_DEBUG, -                        "%"PRId64": LINK (%"PRId64") %"PRId64"/%s ==> %"PRId64"/%s " -                        " ==> %"PRId32" (%s)", -                        frame->root->unique, state->resolve2.ino, -                        state->resolve2.par, -                        state->resolve2.bname, state->resolve.par, -                        state->resolve.bname, -                        op_ret, strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_LINK, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -/* - * server_truncate_cbk - truncate callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                     int32_t op_ret, int32_t op_errno, struct iatt *prebuf, -                     struct iatt *postbuf) -{ -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_truncate_rsp_t *rsp = NULL; -        server_state_t        *state = NULL; -        size_t                 hdrlen = 0; -        int32_t                gf_errno = 0; - -        state = CALL_STATE (frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret == 0) { -                gf_stat_from_iatt (&rsp->prestat, prebuf); -                gf_stat_from_iatt (&rsp->poststat, postbuf); -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": TRUNCATE %s (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        state->loc.inode ? state->loc.inode->ino : 0, -                        op_ret, strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_TRUNCATE, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_fstat_cbk - fstat callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                  int32_t op_ret, int32_t op_errno, struct iatt *stbuf) -{ -        gf_hdr_common_t    *hdr = NULL; -        gf_fop_fstat_rsp_t *rsp = NULL; -        size_t              hdrlen = 0; -        int32_t             gf_errno = 0; -        server_state_t     *state = NULL; - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret == 0) { -                gf_stat_from_iatt (&rsp->stat, stbuf); -        } else { -                state = CALL_STATE(frame); - -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": FSTAT %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->resolve.fd_no, -                        state->fd ? state->fd->inode->ino : 0, op_ret, -                        strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FSTAT, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_ftruncate_cbk - ftruncate callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                      int32_t op_ret, int32_t op_errno, struct iatt *prebuf, -                      struct iatt *postbuf) -{ -        gf_hdr_common_t        *hdr = NULL; -        gf_fop_ftruncate_rsp_t *rsp = NULL; -        size_t                  hdrlen = 0; -        int32_t                 gf_errno = 0; -        server_state_t         *state = NULL; - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret == 0) { -                gf_stat_from_iatt (&rsp->prestat, prebuf); -                gf_stat_from_iatt (&rsp->poststat, postbuf); -        } else { -                state = CALL_STATE (frame); - -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": FTRUNCATE %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->resolve.fd_no, -                        state->fd ? state->fd->inode->ino : 0, op_ret, -                        strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FTRUNCATE, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -/* - * server_flush_cbk - flush callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_flush_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                  int32_t op_ret, int32_t op_errno) -{ -        gf_hdr_common_t    *hdr = NULL; -        gf_fop_flush_rsp_t *rsp = NULL; -        size_t              hdrlen = 0; -        int32_t             gf_errno = 0; -        server_state_t     *state = NULL; - -        if (op_ret < 0) { -                state = CALL_STATE(frame); - -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": FLUSH %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->resolve.fd_no, -                        state->fd ? state->fd->inode->ino : 0, op_ret, -                        strerror (op_errno)); -        } - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FLUSH, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_fsync_cbk - fsync callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                  int32_t op_ret, int32_t op_errno, struct iatt *prebuf, -                  struct iatt *postbuf) -{ -        gf_hdr_common_t    *hdr = NULL; -        gf_fop_fsync_rsp_t *rsp = NULL; -        size_t              hdrlen = 0; -        int32_t             gf_errno = 0; -        server_state_t     *state = NULL; - -        if (op_ret < 0) { -                state = CALL_STATE(frame); - -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": FSYNC %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->resolve.fd_no, -                        state->fd ? state->fd->inode->ino : 0, op_ret, -                        strerror (op_errno)); -        } - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret >= 0) { -                gf_stat_from_iatt (&(rsp->prestat), prebuf); -                gf_stat_from_iatt (&(rsp->poststat), postbuf); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FSYNC, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_release_cbk - rleease callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_release_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                    int32_t op_ret, int32_t op_errno) -{ -        gf_hdr_common_t      *hdr = NULL; -        gf_cbk_release_rsp_t *rsp = NULL; -        size_t                hdrlen = 0; -        int32_t               gf_errno = 0; - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        protocol_server_reply (frame, GF_OP_TYPE_CBK_REPLY, GF_CBK_RELEASE, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -/* - * server_writev_cbk - writev callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ - -static int -server_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                   int32_t op_ret, int32_t op_errno, struct iatt *prebuf, -                   struct iatt *postbuf) -{ -        gf_hdr_common_t    *hdr = NULL; -        gf_fop_write_rsp_t *rsp = NULL; -        size_t              hdrlen = 0; -        int32_t             gf_errno = 0; -        server_state_t     *state = NULL; - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno_to_error (op_errno)); - -        if (op_ret >= 0) { -                gf_stat_from_iatt (&rsp->prestat, prebuf); -                gf_stat_from_iatt (&rsp->poststat, postbuf); -        } else { -                state = CALL_STATE(frame); - -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": WRITEV %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->resolve.fd_no, -                        state->fd ? state->fd->inode->ino : 0, op_ret, -                        strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_WRITE, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -/* - * server_readv_cbk - readv callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @vector: - * @count: - * - * not for external reference - */ -static int -server_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                  int32_t op_ret, int32_t op_errno, -                  struct iovec *vector, int32_t count, -                  struct iatt *stbuf, struct iobref *iobref) -{ -        gf_hdr_common_t   *hdr = NULL; -        gf_fop_read_rsp_t *rsp = NULL; -        size_t             hdrlen = 0; -        int32_t            gf_errno = 0; -        server_state_t    *state = NULL; - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret >= 0) { -                gf_stat_from_iatt (&rsp->stat, stbuf); -        } else { -                state = CALL_STATE(frame); - -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": READV %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->resolve.fd_no, -                        state->fd ? state->fd->inode->ino : 0, op_ret, -                        strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_READ, -                               hdr, hdrlen, vector, count, iobref); - -        return 0; -} - - -/* - * server_open_cbk - open callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @fd: - * - * not for external reference - */ -static int -server_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                 int32_t op_ret, int32_t op_errno, fd_t *fd) -{ -        server_connection_t  *conn = NULL; -        gf_hdr_common_t      *hdr = NULL; -        gf_fop_open_rsp_t    *rsp = NULL; -        server_state_t       *state = NULL; -        size_t                hdrlen = 0; -        int32_t               gf_errno = 0; -        uint64_t              fd_no = 0; - -        conn = SERVER_CONNECTION (frame); - -        state = CALL_STATE (frame); - -        if (op_ret >= 0) { -                fd_bind (fd); - -                fd_no = gf_fd_unused_get (conn->fdtable, fd); -                fd_ref (fd); -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": OPEN %s (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        state->loc.inode ? state->loc.inode->ino : 0, -                        op_ret, strerror (op_errno)); -        } - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); -        rsp->fd           = hton64 (fd_no); - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_OPEN, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -/* - * server_create_cbk - create callback for server - * @frame: call frame - * @cookie: - * @this:  translator structure - * @op_ret: - * @op_errno: - * @fd: file descriptor - * @inode: inode structure - * @stbuf: struct iatt of created file - * - * not for external reference - */ -static int -server_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                   int32_t op_ret, int32_t op_errno, -                   fd_t *fd, inode_t *inode, struct iatt *stbuf, -                   struct iatt *preparent, struct iatt *postparent) -{ -        server_connection_t *conn = NULL; -        gf_hdr_common_t     *hdr = NULL; -        gf_fop_create_rsp_t *rsp = NULL; -        server_state_t      *state = NULL; -        size_t               hdrlen = 0; -        int32_t              gf_errno = 0; -        uint64_t             fd_no = 0; -        inode_t             *link_inode = NULL; - -        conn = SERVER_CONNECTION (frame); - -        state = CALL_STATE (frame); - -        if (op_ret >= 0) { -                gf_log (state->bound_xl->name, GF_LOG_TRACE, -                        "%"PRId64": CREATE %"PRId64"/%s (%"PRId64")", -                        frame->root->unique, state->loc.parent->ino, -                        state->loc.name, stbuf->ia_ino); - -                link_inode = inode_link (inode, state->loc.parent, -                                         state->loc.name, stbuf); - -                if (link_inode != inode) { - -                        /* -                           VERY racy code (if used anywhere else) -                           -- don't do this without understanding -                        */ - -                        inode_unref (fd->inode); -                        fd->inode = inode_ref (link_inode); -                } - -                inode_lookup (link_inode); -                inode_unref (link_inode); - -                fd_bind (fd); - -                fd_no = gf_fd_unused_get (conn->fdtable, fd); -                fd_ref (fd); - -                if ((fd_no < 0) || (fd == 0)) { -                        op_ret = fd_no; -                        op_errno = errno; -                } -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": CREATE %s (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        state->loc.inode ? state->loc.inode->ino : 0, -                        op_ret, strerror (op_errno)); -        } - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); -        rsp->fd           = hton64 (fd_no); - -        if (op_ret >= 0) { -                gf_stat_from_iatt (&rsp->stat, stbuf); -                gf_stat_from_iatt (&rsp->preparent, preparent); -                gf_stat_from_iatt (&rsp->postparent, postparent); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_CREATE, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_readlink_cbk - readlink callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @buf: - * - * not for external reference - */ -static int -server_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                     int32_t op_ret, int32_t op_errno, const char *buf, -                     struct iatt *sbuf) -{ -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_readlink_rsp_t *rsp = NULL; -        server_state_t        *state = NULL; -        size_t                 hdrlen = 0; -        size_t                 linklen = 0; -        int32_t                gf_errno = 0; - -        state  = CALL_STATE(frame); - -        if (op_ret >= 0) { -                linklen = strlen (buf) + 1; -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": READLINK %s (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        state->loc.inode ? state->loc.inode->ino : 0, -                        op_ret, strerror (op_errno)); -        } - -        hdrlen = gf_hdr_len (rsp, linklen); -        hdr    = gf_hdr_new (rsp, linklen); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno_to_error (op_errno)); - -        if (op_ret >= 0) { -                gf_stat_from_iatt (&(rsp->buf), sbuf); -                strcpy (rsp->path, buf); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_READLINK, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_stat_cbk - stat callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                 int32_t op_ret, int32_t op_errno, struct iatt *stbuf) -{ -        gf_hdr_common_t   *hdr = NULL; -        gf_fop_stat_rsp_t *rsp = NULL; -        server_state_t    *state = NULL; -        size_t             hdrlen = 0; -        int32_t            gf_errno = 0; - -        state  = CALL_STATE (frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno_to_error (op_errno)); - -        if (op_ret == 0) { -                gf_stat_from_iatt (&rsp->stat, stbuf); -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": STAT %s (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        state->loc.inode ? state->loc.inode->ino : 0, -                        op_ret, strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_STAT, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_setattr_cbk - setattr callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ - -static int -server_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                    int32_t op_ret, int32_t op_errno, -                    struct iatt *statpre, struct iatt *statpost) -{ -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_setattr_rsp_t  *rsp = NULL; -        server_state_t        *state = NULL; -        size_t                 hdrlen = 0; -        int32_t                gf_errno = 0; - -        state  = CALL_STATE (frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno_to_error (op_errno)); - -        if (op_ret == 0) { -                gf_stat_from_iatt (&rsp->statpre, statpre); -                gf_stat_from_iatt (&rsp->statpost, statpost); -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": SETATTR %s (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        state->loc.inode ? state->loc.inode->ino : 0, -                        op_ret, strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_SETATTR, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* - * server_setattr_cbk - setattr callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @stbuf: - * - * not for external reference - */ -static int -server_fsetattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                     int32_t op_ret, int32_t op_errno, -                     struct iatt *statpre, struct iatt *statpost) -{ -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_fsetattr_rsp_t *rsp = NULL; -        server_state_t        *state = NULL; -        size_t                 hdrlen = 0; -        int32_t                gf_errno = 0; - -        state  = CALL_STATE (frame); - -        hdrlen = gf_hdr_len (rsp, 0); -        hdr    = gf_hdr_new (rsp, 0); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno_to_error (op_errno)); - -        if (op_ret == 0) { -                gf_stat_from_iatt (&rsp->statpre, statpre); -                gf_stat_from_iatt (&rsp->statpost, statpost); -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": FSETATTR %"PRId64" (%"PRId64") ==> " -                        "%"PRId32" (%s)", -                        frame->root->unique, state->resolve.fd_no, -                        state->fd ? state->fd->inode->ino : 0, -                        op_ret, strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FSETATTR, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -/* - * server_lookup_cbk - lookup callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * @inode: - * @stbuf: - * - * not for external reference - */ -static int -server_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                   int32_t op_ret, int32_t op_errno, -                   inode_t *inode, struct iatt *stbuf, dict_t *dict, -                   struct iatt *postparent) -{ -        gf_hdr_common_t     *hdr = NULL; -        gf_fop_lookup_rsp_t *rsp = NULL; -        server_state_t      *state = NULL; -        inode_t             *root_inode = NULL; -        int32_t              dict_len = 0; -        size_t               hdrlen = 0; -        int32_t              gf_errno = 0; -        int32_t              ret = -1; -        inode_t             *link_inode = NULL; -        loc_t                fresh_loc = {0,}; - -        state = CALL_STATE(frame); - -        if (state->is_revalidate == 1 && op_ret == -1) { -                state->is_revalidate = 2; -                loc_copy (&fresh_loc, &state->loc); -                inode_unref (fresh_loc.inode); -                fresh_loc.inode = inode_new (state->itable); - -                STACK_WIND (frame, server_lookup_cbk, -                            BOUND_XL (frame), BOUND_XL (frame)->fops->lookup, -                            &fresh_loc, state->dict); - -                loc_wipe (&fresh_loc); -                return 0; -        } - -        if (dict) { -                dict_len = dict_serialized_length (dict); -                if (dict_len < 0) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "%s (%"PRId64"): failed to get serialized " -                                "length of reply dict", -                                state->loc.path, state->loc.inode->ino); -                        op_ret   = -1; -                        op_errno = EINVAL; -                        dict_len = 0; -                } -        } - -        hdrlen = gf_hdr_len (rsp, dict_len); -        hdr    = gf_hdr_new (rsp, dict_len); -        rsp    = gf_param (hdr); - -        if ((op_ret >= 0) && dict) { -                ret = dict_serialize (dict, rsp->dict); -                if (ret < 0) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "%s (%"PRId64"): failed to serialize reply dict", -                                state->loc.path, state->loc.inode->ino); -                        op_ret = -1; -                        op_errno = -ret; -                        dict_len = 0; -                } -        } -        rsp->dict_len = hton32 (dict_len); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (postparent) -                gf_stat_from_iatt (&rsp->postparent, postparent); - -        if (op_ret == 0) { -                root_inode = BOUND_XL(frame)->itable->root; -                if (inode == root_inode) { -                        /* we just looked up root ("/") */ -                        stbuf->ia_ino = 1; -                        if (inode->ia_type == 0) -                                inode->ia_type = stbuf->ia_type; -                } - -                gf_stat_from_iatt (&rsp->stat, stbuf); - -                if (inode->ino != 1) { -                        link_inode = inode_link (inode, state->loc.parent, -                                                 state->loc.name, stbuf); -                        inode_lookup (link_inode); -                        inode_unref (link_inode); -                } -        } else { -                if (state->is_revalidate && op_errno == ENOENT) { -                        if (state->loc.inode->ino != 1) { -                                inode_unlink (state->loc.inode, -                                              state->loc.parent, -                                              state->loc.name); -                        } -                } - -                gf_log (this->name, -                        (op_errno == ENOENT ? GF_LOG_TRACE : GF_LOG_DEBUG), -                        "%"PRId64": LOOKUP %s (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        state->loc.inode ? state->loc.inode->ino : 0, -                        op_ret, strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_LOOKUP, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -static int -server_xattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                    int32_t op_ret, int32_t op_errno, dict_t *dict) -{ -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_xattrop_rsp_t  *rsp = NULL; -        server_state_t        *state = NULL; -        size_t                 hdrlen = 0; -        int32_t                len = 0; -        int32_t                gf_errno = 0; -        int32_t                ret = -1; - -        state = CALL_STATE (frame); - -        if (op_ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": XATTROP %s (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->loc.path, -                        state->loc.inode ? state->loc.inode->ino : 0, -                        op_ret, strerror (op_errno)); -        } - -        if ((op_ret >= 0) && dict) { -                len = dict_serialized_length (dict); -                if (len < 0) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "%s (%"PRId64"): failed to get serialized length" -                                " for reply dict", -                                state->loc.path, state->loc.inode->ino); -                        op_ret = -1; -                        op_errno = EINVAL; -                        len = 0; -                } -        } - -        hdrlen = gf_hdr_len (rsp, len + 1); -        hdr    = gf_hdr_new (rsp, len + 1); -        rsp    = gf_param (hdr); - -        if ((op_ret >= 0) && dict) { -                ret = dict_serialize (dict, rsp->dict); -                if (ret < 0) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "%s (%"PRId64"): failed to serialize reply dict", -                                state->loc.path, state->loc.inode->ino); -                        op_ret = -1; -                        op_errno = -ret; -                        len = 0; -                } -        } -        rsp->dict_len = hton32 (len); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_XATTROP, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -static int -server_fxattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                     int32_t op_ret, int32_t op_errno, dict_t *dict) -{ -        gf_hdr_common_t      *hdr = NULL; -        gf_fop_xattrop_rsp_t *rsp = NULL; -        size_t                hdrlen = 0; -        int32_t               len = 0; -        int32_t               gf_errno = 0; -        int32_t               ret = -1; -        server_state_t       *state = NULL; - -        state = CALL_STATE(frame); - -        if (op_ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "%"PRId64": FXATTROP %"PRId64" (%"PRId64") ==> %"PRId32" (%s)", -                        frame->root->unique, state->resolve.fd_no, -                        state->fd ? state->fd->inode->ino : 0, op_ret, -                        strerror (op_errno)); -        } - -        if ((op_ret >= 0) && dict) { -                len = dict_serialized_length (dict); -                if (len < 0) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "fd - %"PRId64" (%"PRId64"): failed to get " -                                "serialized length for reply dict", -                                state->resolve.fd_no, state->fd->inode->ino); -                        op_ret = -1; -                        op_errno = EINVAL; -                        len = 0; -                } -        } - -        hdrlen = gf_hdr_len (rsp, len + 1); -        hdr    = gf_hdr_new (rsp, len + 1); -        rsp    = gf_param (hdr); - -        if ((op_ret >= 0) && dict) { -                ret = dict_serialize (dict, rsp->dict); -                if (ret < 0) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "fd - %"PRId64" (%"PRId64"): failed to " -                                "serialize reply dict", -                                state->resolve.fd_no, state->fd->inode->ino); -                        op_ret = -1; -                        op_errno = -ret; -                        len = 0; -                } -        } -        rsp->dict_len = hton32 (len); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_FXATTROP, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - - -static int -server_lookup_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t    *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        if (!state->loc.inode) -                state->loc.inode = inode_new (state->itable); -        else -                state->is_revalidate = 1; - -        STACK_WIND (frame, server_lookup_cbk, -                    bound_xl, bound_xl->fops->lookup, -                    &state->loc, state->dict); - -        return 0; -err: -        server_lookup_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                           state->resolve.op_errno, NULL, NULL, NULL, NULL); - -        return 0; -} - - -static int -server_lookup (call_frame_t *frame, xlator_t *bound_xl, -               gf_hdr_common_t *hdr, size_t hdrlen, -               struct iobuf *iobuf) -{ -        gf_fop_lookup_req_t *req = NULL; -        server_state_t      *state = NULL; -        int32_t              ret = -1; -        size_t               pathlen = 0; -        size_t               baselen = 0; -        size_t               dictlen = 0; -        dict_t              *xattr_req = NULL; -        char                *req_dictbuf = NULL; - -        req = gf_param (hdr); - -        state = CALL_STATE (frame); - -        pathlen = STRLEN_0 (req->path); -        dictlen = ntoh32 (req->dictlen); - -        /* NOTE: lookup() uses req->ino only to identify if a lookup() -         *       is requested for 'root' or not -         */ -        state->resolve.ino    = ntoh64 (req->ino); -        if (state->resolve.ino != 1) -                state->resolve.ino = 0; - -        state->resolve.type   = RESOLVE_DONTCARE; -        state->resolve.par    = ntoh64 (req->par); -        state->resolve.gen    = ntoh64 (req->gen); -        state->resolve.path   = gf_strdup (req->path); - -        if (IS_NOT_ROOT (pathlen)) { -                state->resolve.bname = gf_strdup (req->bname + pathlen); -                baselen = STRLEN_0 (state->resolve.bname); -        } - -        if (dictlen) { -                /* Unserialize the dictionary */ -                req_dictbuf = memdup (req->dict + pathlen + baselen, dictlen); - -                xattr_req = dict_new (); - -                ret = dict_unserialize (req_dictbuf, dictlen, &xattr_req); -                if (ret < 0) { -                        gf_log (bound_xl->name, GF_LOG_ERROR, -                                "%"PRId64": %s (%"PRId64"): failed to " -                                "unserialize req-buffer to dictionary", -                                frame->root->unique, state->resolve.path, -                                state->resolve.ino); -                        GF_FREE (req_dictbuf); -                        goto err; -                } - -                xattr_req->extra_free = req_dictbuf; -                state->dict = xattr_req; -        } - -        gf_resolve_and_resume (frame, server_lookup_resume); - -        return 0; -err: -        if (xattr_req) -                dict_unref (xattr_req); - -        server_lookup_cbk (frame, NULL, frame->this, -1, EINVAL, NULL, NULL, -                           NULL, NULL); -        return 0; -} - - -/* - * server_forget - forget function for server protocol - * - * not for external reference - */ -static int -server_forget (call_frame_t *frame, xlator_t *bound_xl, -               gf_hdr_common_t *hdr, size_t hdrlen, -               struct iobuf *iobuf) -{ -        gf_log ("forget", GF_LOG_CRITICAL, "function not implemented"); -        return 0; -} - - -static int -server_stat_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_stat_cbk, -                    bound_xl, bound_xl->fops->stat, &state->loc); -        return 0; -err: -        server_stat_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                         state->resolve.op_errno, NULL); -        return 0; -} - - -static int -server_stat (call_frame_t *frame, xlator_t *bound_xl, -             gf_hdr_common_t *hdr, size_t hdrlen, -             struct iobuf *iobuf) -{ -        gf_fop_stat_req_t *req = NULL; -        server_state_t    *state = NULL; - -        req = gf_param (hdr); -        state = CALL_STATE (frame); -        { -                state->resolve.type  = RESOLVE_MUST; -                state->resolve.ino   = ntoh64 (req->ino); -                state->resolve.gen   = ntoh64 (req->gen); -                state->resolve.path  = gf_strdup (req->path); -        } - -        gf_resolve_and_resume (frame, server_stat_resume); - -        return 0; -} - - -static int -server_setattr_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_setattr_cbk, -                    bound_xl, bound_xl->fops->setattr, -                    &state->loc, &state->stbuf, state->valid); -        return 0; -err: -        server_setattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                            state->resolve.op_errno, NULL, NULL); - -        return 0; -} - - -static int -server_setattr (call_frame_t *frame, xlator_t *bound_xl, -                gf_hdr_common_t *hdr, size_t hdrlen, -                struct iobuf *iobuf) -{ -        gf_fop_setattr_req_t *req = NULL; -        server_state_t       *state = NULL; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        state->resolve.type  = RESOLVE_MUST; -        state->resolve.ino   = ntoh64 (req->ino); -        state->resolve.gen   = ntoh64 (req->gen); -        state->resolve.path  = gf_strdup (req->path); - -        gf_stat_to_iatt (&req->stbuf, &state->stbuf); -        state->valid = ntoh32 (req->valid); - -        gf_resolve_and_resume (frame, server_setattr_resume); - -        return 0; -} - - -static int -server_fsetattr_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_fsetattr_cbk, -                    bound_xl, bound_xl->fops->fsetattr, -                    state->fd, &state->stbuf, state->valid); -        return 0; -err: -        server_fsetattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                             state->resolve.op_errno, NULL, NULL); - -        return 0; -} - - -static int -server_fsetattr (call_frame_t *frame, xlator_t *bound_xl, -                 gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        gf_fop_fsetattr_req_t  *req = NULL; -        server_state_t         *state = NULL; - - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        state->resolve.type   = RESOLVE_MUST; -        state->resolve.fd_no  = ntoh64 (req->fd); - -        gf_stat_to_iatt (&req->stbuf, &state->stbuf); -        state->valid = ntoh32 (req->valid); - -        gf_resolve_and_resume (frame, server_fsetattr_resume); - -        return 0; -} - - -static int -server_readlink_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_readlink_cbk, -                    bound_xl, bound_xl->fops->readlink, -                    &state->loc, state->size); -        return 0; -err: -        server_readlink_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                             state->resolve.op_errno, NULL, NULL); -        return 0; -} - - -static int -server_readlink (call_frame_t *frame, xlator_t *bound_xl, -                 gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        gf_fop_readlink_req_t *req = NULL; -        server_state_t        *state = NULL; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        state->resolve.type = RESOLVE_MUST; -        state->resolve.ino  = ntoh64 (req->ino); -        state->resolve.gen  = ntoh64 (req->gen); -        state->resolve.path = gf_strdup (req->path); - -        state->size  = ntoh32 (req->size); - -        gf_resolve_and_resume (frame, server_readlink_resume); - -        return 0; -} - - -static int -server_create_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        state->loc.inode = inode_new (state->itable); - -        state->fd = fd_create (state->loc.inode, frame->root->pid); -        state->fd->flags = state->flags; - -        STACK_WIND (frame, server_create_cbk, -                    bound_xl, bound_xl->fops->create, -                    &(state->loc), state->flags, state->mode, -                    state->fd, state->params); - -        return 0; -err: -        server_create_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                           state->resolve.op_errno, NULL, NULL, NULL, -                           NULL, NULL); -        return 0; -} - - -static int -server_create (call_frame_t *frame, xlator_t *bound_xl, -               gf_hdr_common_t *hdr, size_t hdrlen, -               struct iobuf *iobuf) -{ -        gf_fop_create_req_t *req = NULL; -        server_state_t      *state = NULL; -        int                  pathlen = 0; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        pathlen = STRLEN_0 (req->path); - -        state->resolve.type   = RESOLVE_NOT; -        state->resolve.par    = ntoh64 (req->par); -        state->resolve.gen    = ntoh64 (req->gen); -        state->resolve.path   = gf_strdup (req->path); -        state->resolve.bname  = gf_strdup (req->bname + pathlen); -        state->mode           = ntoh32 (req->mode); -        state->flags          = gf_flags_to_flags (ntoh32 (req->flags)); - -        gf_resolve_and_resume (frame, server_create_resume); - -        return 0; -} - - -static int -server_open_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t  *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        state->fd = fd_create (state->loc.inode, frame->root->pid); -        state->fd->flags = state->flags; - -        STACK_WIND (frame, server_open_cbk, -                    bound_xl, bound_xl->fops->open, -                    &state->loc, state->flags, state->fd, 0); - -        return 0; -err: -        server_open_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                         state->resolve.op_errno, NULL); -        return 0; -} - - -static int -server_open (call_frame_t *frame, xlator_t *bound_xl, -             gf_hdr_common_t *hdr, size_t hdrlen, -             struct iobuf *iobuf) -{ -        gf_fop_open_req_t  *req = NULL; -        server_state_t     *state = NULL; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        state->resolve.type  = RESOLVE_MUST; -        state->resolve.ino   = ntoh64 (req->ino); -        state->resolve.gen   = ntoh64 (req->gen); -        state->resolve.path  = gf_strdup (req->path); - -        state->flags = gf_flags_to_flags (ntoh32 (req->flags)); - -        gf_resolve_and_resume (frame, server_open_resume); - -        return 0; -} - - -static int -server_readv_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t    *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_readv_cbk, -                    bound_xl, bound_xl->fops->readv, -                    state->fd, state->size, state->offset); - -        return 0; -err: -        server_readv_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                          state->resolve.op_errno, NULL, 0, NULL, NULL); -        return 0; -} - - -static int -server_readv (call_frame_t *frame, xlator_t *bound_xl, -              gf_hdr_common_t *hdr, size_t hdrlen, -              struct iobuf *iobuf) -{ -        gf_fop_read_req_t   *req = NULL; -        server_state_t      *state = NULL; - -        req = gf_param (hdr); -        state = CALL_STATE (frame); - -        state->resolve.type   = RESOLVE_MUST; -        state->resolve.fd_no  = ntoh64 (req->fd); -        state->size           = ntoh32 (req->size); -        state->offset         = ntoh64 (req->offset); - -        gf_resolve_and_resume (frame, server_readv_resume); - -        return 0; -} - - -static int -server_writev_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t   *state = NULL; -        struct iovec      iov = {0, }; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        iov.iov_len  = state->size; - -        if (state->iobuf) { -                iov.iov_base = state->iobuf->ptr; -        } - -        STACK_WIND (frame, server_writev_cbk, -                    bound_xl, bound_xl->fops->writev, -                    state->fd, &iov, 1, state->offset, state->iobref); - -        return 0; -err: -        server_writev_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                           state->resolve.op_errno, NULL, NULL); -        return 0; -} - - -static int -server_writev (call_frame_t *frame, xlator_t *bound_xl, -               gf_hdr_common_t *hdr, size_t hdrlen, -               struct iobuf *iobuf) -{ -        gf_fop_write_req_t  *req = NULL; -        server_state_t      *state = NULL; -        struct iobref       *iobref = NULL; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        state->resolve.type  = RESOLVE_MUST; -        state->resolve.fd_no = ntoh64 (req->fd); -        state->offset        = ntoh64 (req->offset); -        state->size          = ntoh32 (req->size); - -        if (iobuf) { -                iobref = iobref_new (); -                iobref_add (iobref, iobuf); - -                state->iobuf = iobuf; -                state->iobref = iobref; -        } - -        gf_resolve_and_resume (frame, server_writev_resume); - -        return 0; -} - - -static int -server_release (call_frame_t *frame, xlator_t *bound_xl, -                gf_hdr_common_t *hdr, size_t hdrlen, -                struct iobuf *iobuf) -{ -        gf_cbk_release_req_t  *req = NULL; -        server_state_t        *state = NULL; -        server_connection_t   *conn = NULL; - -        conn  = SERVER_CONNECTION (frame); -        state = CALL_STATE (frame); -        req   = gf_param (hdr); - -        state->resolve.fd_no = ntoh64 (req->fd); - -        gf_fd_put (conn->fdtable, state->resolve.fd_no); - -        server_release_cbk (frame, NULL, frame->this, 0, 0); - -        return 0; -} - - -static int -server_fsync_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t    *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_fsync_cbk, -                    bound_xl, bound_xl->fops->fsync, -                    state->fd, state->flags); -        return 0; -err: -        server_fsync_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                          state->resolve.op_errno, NULL, NULL); - -        return 0; -} - - -static int -server_fsync (call_frame_t *frame, xlator_t *bound_xl, -              gf_hdr_common_t *hdr, size_t hdrlen, -              struct iobuf *iobuf) -{ -        gf_fop_fsync_req_t  *req = NULL; -        server_state_t      *state = NULL; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        state->resolve.type  = RESOLVE_MUST; -        state->resolve.fd_no = ntoh64 (req->fd); -        state->flags         = ntoh32 (req->data); - -        gf_resolve_and_resume (frame, server_fsync_resume); - -        return 0; -} - - - -static int -server_flush_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t    *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_flush_cbk, -                    bound_xl, bound_xl->fops->flush, state->fd); -        return 0; -err: -        server_flush_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                          state->resolve.op_errno); - -        return 0; -} - - -static int -server_flush (call_frame_t *frame, xlator_t *bound_xl, -              gf_hdr_common_t *hdr, size_t hdrlen, -              struct iobuf *iobuf) -{ -        gf_fop_fsync_req_t  *req = NULL; -        server_state_t      *state = NULL; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        state->resolve.type  = RESOLVE_MUST; -        state->resolve.fd_no = ntoh64 (req->fd); - -        gf_resolve_and_resume (frame, server_flush_resume); - -        return 0; -} - - - -static int -server_ftruncate_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t    *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_ftruncate_cbk, -                    bound_xl, bound_xl->fops->ftruncate, -                    state->fd, state->offset); -        return 0; -err: -        server_ftruncate_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                              state->resolve.op_errno, NULL, NULL); - -        return 0; -} - - -static int -server_ftruncate (call_frame_t *frame, xlator_t *bound_xl, -                  gf_hdr_common_t *hdr, size_t hdrlen, -                  struct iobuf *iobuf) -{ -        gf_fop_ftruncate_req_t  *req = NULL; -        server_state_t          *state = NULL; - -        req = gf_param (hdr); -        state = CALL_STATE (frame); - -        state->resolve.type   = RESOLVE_MUST; -        state->resolve.fd_no  = ntoh64 (req->fd); -        state->offset         = ntoh64 (req->offset); - -        gf_resolve_and_resume (frame, server_ftruncate_resume); - -        return 0; -} - - -static int -server_fstat_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t     *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_fstat_cbk, -                    bound_xl, bound_xl->fops->fstat, -                    state->fd); -        return 0; -err: -        server_fstat_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                          state->resolve.op_errno, NULL); -        return 0; -} - - -static int -server_fstat (call_frame_t *frame, xlator_t *bound_xl, -              gf_hdr_common_t *hdr, size_t hdrlen, -              struct iobuf *iobuf) -{ -        gf_fop_fstat_req_t  *req = NULL; -        server_state_t      *state = NULL; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        state->resolve.type    = RESOLVE_MUST; -        state->resolve.fd_no   = ntoh64 (req->fd); - -        gf_resolve_and_resume (frame, server_fstat_resume); - -        return 0; -} - - -static int -server_truncate_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_truncate_cbk, -                    bound_xl, bound_xl->fops->truncate, -                    &state->loc, state->offset); -        return 0; -err: -        server_truncate_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                             state->resolve.op_errno, NULL, NULL); -        return 0; -} - - - -static int -server_truncate (call_frame_t *frame, xlator_t *bound_xl, -                 gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        gf_fop_truncate_req_t *req = NULL; -        server_state_t        *state = NULL; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        state->resolve.type  = RESOLVE_MUST; -        state->resolve.path  = gf_strdup (req->path); -        state->resolve.ino   = ntoh64 (req->ino); -        state->resolve.gen   = ntoh64 (req->gen); -        state->offset        = ntoh64 (req->offset); - -        gf_resolve_and_resume (frame, server_truncate_resume); - -        return 0; -} - - -static int -server_unlink_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_unlink_cbk, -                    bound_xl, bound_xl->fops->unlink, -                    &state->loc); -        return 0; -err: -        server_unlink_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                           state->resolve.op_errno, NULL, NULL); -        return 0; -} - - -static int -server_unlink (call_frame_t *frame, xlator_t *bound_xl, -               gf_hdr_common_t *hdr, size_t hdrlen, -               struct iobuf *iobuf) -{ -        gf_fop_unlink_req_t *req = NULL; -        server_state_t      *state = NULL; -        int                  pathlen = 0; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        pathlen = STRLEN_0 (req->path); - -        state->resolve.type   = RESOLVE_MUST; -        state->resolve.par    = ntoh64 (req->par); -        state->resolve.gen    = ntoh64 (req->gen); -        state->resolve.path   = gf_strdup (req->path); -        state->resolve.bname  = gf_strdup (req->bname + pathlen); - -        gf_resolve_and_resume (frame, server_unlink_resume); - -        return 0; -} - - -static int -server_setxattr_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_setxattr_cbk, -                    bound_xl, bound_xl->fops->setxattr, -                    &state->loc, state->dict, state->flags); -        return 0; -err: -        server_setxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                             state->resolve.op_errno); - -        return 0; -} - - -static int -server_setxattr (call_frame_t *frame, xlator_t *bound_xl, -                 gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        gf_fop_setxattr_req_t *req = NULL; -        server_state_t        *state = NULL; -        dict_t                *dict = NULL; -        int32_t                ret = -1; -        size_t                 dict_len = 0; -        char                  *req_dictbuf = NULL; - -        req = gf_param (hdr); -        state = CALL_STATE (frame); - -        dict_len = ntoh32 (req->dict_len); - -        state->resolve.type     = RESOLVE_MUST; -        state->resolve.path     = gf_strdup (req->path + dict_len); -        state->resolve.ino      = ntoh64 (req->ino); -        state->resolve.gen      = ntoh64 (req->gen); -        state->flags            = ntoh32 (req->flags); - -        if (dict_len) { -                req_dictbuf = memdup (req->dict, dict_len); - -                dict = dict_new (); - -                ret = dict_unserialize (req_dictbuf, dict_len, &dict); -                if (ret < 0) { -                        gf_log (bound_xl->name, GF_LOG_ERROR, -                                "%"PRId64": %s (%"PRId64"): failed to " -                                "unserialize request buffer to dictionary", -                                frame->root->unique, state->loc.path, -                                state->resolve.ino); -                        GF_FREE (req_dictbuf); -                        goto err; -                } - -                dict->extra_free = req_dictbuf; -                state->dict = dict; -        } - -        gf_resolve_and_resume (frame, server_setxattr_resume); - -        return 0; -err: -        if (dict) -                dict_unref (dict); - -        server_setxattr_cbk (frame, NULL, frame->this, -1, EINVAL); - -        return 0; - -} - - -static int -server_fsetxattr_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_setxattr_cbk, -                    bound_xl, bound_xl->fops->fsetxattr, -                    state->fd, state->dict, state->flags); -        return 0; -err: -        server_fsetxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                              state->resolve.op_errno); - -        return 0; -} - - -static int -server_fsetxattr (call_frame_t *frame, xlator_t *bound_xl, -                  gf_hdr_common_t *hdr, size_t hdrlen, -                  struct iobuf *iobuf) -{ -        gf_fop_fsetxattr_req_t *req = NULL; -        server_state_t         *state = NULL; -        dict_t                 *dict = NULL; -        int32_t                 ret = -1; -        size_t                  dict_len = 0; -        char                   *req_dictbuf = NULL; - -        req = gf_param (hdr); -        state = CALL_STATE (frame); - -        dict_len = ntoh32 (req->dict_len); - -        state->resolve.type      = RESOLVE_MUST; -        state->resolve.fd_no     = ntoh64 (req->fd); -        state->flags             = ntoh32 (req->flags); - -        if (dict_len) { -                req_dictbuf = memdup (req->dict, dict_len); - -                dict = dict_new (); - -                ret = dict_unserialize (req_dictbuf, dict_len, &dict); -                if (ret < 0) { -                        gf_log (bound_xl->name, GF_LOG_ERROR, -                                "%"PRId64": %s (%"PRId64"): failed to " -                                "unserialize request buffer to dictionary", -                                frame->root->unique, state->loc.path, -                                state->resolve.ino); -                        GF_FREE (req_dictbuf); -                        goto err; -                } - -                dict->extra_free = req_dictbuf; -                state->dict = dict; -        } - -        gf_resolve_and_resume (frame, server_fsetxattr_resume); - -        return 0; -err: -        if (dict) -                dict_unref (dict); - -        server_setxattr_cbk (frame, NULL, frame->this, -1, EINVAL); - -        return 0; -} - - -static int -server_fxattrop_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_fxattrop_cbk, -                    bound_xl, bound_xl->fops->fxattrop, -                    state->fd, state->flags, state->dict); -        return 0; -err: -        server_fxattrop_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                             state->resolve.op_errno, NULL); -        return 0; -} - - -static int -server_fxattrop (call_frame_t *frame, xlator_t *bound_xl, -                 gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        gf_fop_fxattrop_req_t *req = NULL; -        dict_t                *dict = NULL; -        server_state_t        *state = NULL; -        size_t                 dict_len = 0; -        char                  *req_dictbuf = NULL; -        int32_t                ret = -1; - -        req   = gf_param (hdr); -        state = CALL_STATE(frame); - -        dict_len = ntoh32 (req->dict_len); - -        state->resolve.type    = RESOLVE_MUST; -        state->resolve.fd_no   = ntoh64 (req->fd); - -        state->resolve.ino     = ntoh64 (req->ino); -        state->resolve.gen     = ntoh64 (req->gen); -        state->flags           = ntoh32 (req->flags); - -        if (dict_len) { -                /* Unserialize the dictionary */ -                req_dictbuf = memdup (req->dict, dict_len); - -                dict = dict_new (); - -                ret = dict_unserialize (req_dictbuf, dict_len, &dict); -                if (ret < 0) { -                        gf_log (bound_xl->name, GF_LOG_ERROR, -                                "fd - %"PRId64" (%"PRId64"): failed to unserialize " -                                "request buffer to dictionary", -                                state->resolve.fd_no, state->fd->inode->ino); -                        GF_FREE (req_dictbuf); -                        goto fail; -                } -                dict->extra_free = req_dictbuf; -                state->dict = dict; -                dict = NULL; -        } - -        gf_resolve_and_resume (frame, server_fxattrop_resume); - -        return 0; - -fail: -        if (dict) -                dict_unref (dict); - -        server_fxattrop_cbk (frame, NULL, frame->this, -1, EINVAL, NULL); -        return 0; -} - - -static int -server_xattrop_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_xattrop_cbk, -                    bound_xl, bound_xl->fops->xattrop, -                    &state->loc, state->flags, state->dict); -        return 0; -err: -        server_xattrop_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                            state->resolve.op_errno, NULL); -        return 0; -} - - -static int -server_xattrop (call_frame_t *frame, xlator_t *bound_xl, -                gf_hdr_common_t *hdr, size_t hdrlen, -                struct iobuf *iobuf) -{ -        gf_fop_xattrop_req_t  *req = NULL; -        dict_t                *dict = NULL; -        server_state_t        *state = NULL; -        size_t                 dict_len = 0; -        char                  *req_dictbuf = NULL; -        int32_t                ret = -1; - -        req   = gf_param (hdr); -        state = CALL_STATE(frame); - -        dict_len = ntoh32 (req->dict_len); - -        state->resolve.type    = RESOLVE_MUST; -        state->resolve.path    = gf_strdup (req->path + dict_len); -        state->resolve.ino     = ntoh64 (req->ino); -        state->resolve.gen     = ntoh64 (req->gen); -        state->flags           = ntoh32 (req->flags); - -        if (dict_len) { -                /* Unserialize the dictionary */ -                req_dictbuf = memdup (req->dict, dict_len); - -                dict = dict_new (); - -                ret = dict_unserialize (req_dictbuf, dict_len, &dict); -                if (ret < 0) { -                        gf_log (bound_xl->name, GF_LOG_ERROR, -                                "fd - %"PRId64" (%"PRId64"): failed to unserialize " -                                "request buffer to dictionary", -                                state->resolve.fd_no, state->fd->inode->ino); -                        GF_FREE (req_dictbuf); -                        goto fail; -                } -                dict->extra_free = req_dictbuf; -                state->dict = dict; -                dict = NULL; -        } - -        gf_resolve_and_resume (frame, server_xattrop_resume); - -        return 0; - -fail: -        if (dict) -                dict_unref (dict); - -        server_xattrop_cbk (frame, NULL, frame->this, -1, EINVAL, NULL); -        return 0; -} - - -static int -server_getxattr_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_getxattr_cbk, -                    bound_xl, bound_xl->fops->getxattr, -                    &state->loc, state->name); -        return 0; -err: -        server_getxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                             state->resolve.op_errno, NULL); -        return 0; -} - - -static int -server_getxattr (call_frame_t *frame, xlator_t *bound_xl, -                 gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        gf_fop_getxattr_req_t  *req = NULL; -        server_state_t         *state = NULL; -        size_t                  namelen = 0; -        size_t                  pathlen = 0; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        pathlen = STRLEN_0 (req->path); - -        state->resolve.type  = RESOLVE_MUST; -        state->resolve.path  = gf_strdup (req->path); -        state->resolve.ino   = ntoh64 (req->ino); -        state->resolve.gen   = ntoh64 (req->gen); - -        namelen = ntoh32 (req->namelen); -        if (namelen) -                state->name = gf_strdup (req->name + pathlen); - -        gf_resolve_and_resume (frame, server_getxattr_resume); - -        return 0; -} - - -static int -server_fgetxattr_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_fgetxattr_cbk, -                    bound_xl, bound_xl->fops->fgetxattr, -                    state->fd, state->name); -        return 0; -err: -        server_fgetxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                              state->resolve.op_errno, NULL); -        return 0; -} - - -static int -server_fgetxattr (call_frame_t *frame, xlator_t *bound_xl, -                  gf_hdr_common_t *hdr, size_t hdrlen, -                  struct iobuf *iobuf) -{ -        gf_fop_fgetxattr_req_t *req = NULL; -        server_state_t         *state = NULL; -        size_t                  namelen = 0; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        state->resolve.type  = RESOLVE_MUST; -        state->resolve.fd_no = ntoh64 (req->fd); - -        namelen = ntoh32 (req->namelen); -        if (namelen) -                state->name = gf_strdup (req->name); - -        gf_resolve_and_resume (frame, server_fgetxattr_resume); - -        return 0; -} - - -static int -server_removexattr_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_removexattr_cbk, -                    bound_xl, bound_xl->fops->removexattr, -                    &state->loc, state->name); -        return 0; -err: -        server_removexattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                                state->resolve.op_errno); -        return 0; -} - - -static int -server_removexattr (call_frame_t *frame, xlator_t *bound_xl, -                    gf_hdr_common_t *hdr, size_t hdrlen, -                    struct iobuf *iobuf) -{ -        gf_fop_removexattr_req_t  *req = NULL; -        server_state_t            *state = NULL; -        size_t                     pathlen = 0; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); -        pathlen = STRLEN_0 (req->path); - -        state->resolve.type   = RESOLVE_MUST; -        state->resolve.path   = gf_strdup (req->path); -        state->resolve.ino    = ntoh64 (req->ino); -        state->resolve.gen    = ntoh64 (req->gen); -        state->name           = gf_strdup (req->name + pathlen); - -        gf_resolve_and_resume (frame, server_removexattr_resume); - -        return 0; -} - - -static int -server_statfs_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t      *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret !=0) -                goto err; - -        STACK_WIND (frame, server_statfs_cbk, -                    bound_xl, bound_xl->fops->statfs, -                    &state->loc); -        return 0; - -err: -        server_statfs_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                           state->resolve.op_errno, NULL); -        return 0; -} - - -static int -server_statfs (call_frame_t *frame, xlator_t *bound_xl, -               gf_hdr_common_t *hdr, size_t hdrlen, -               struct iobuf *iobuf) -{ -        gf_fop_statfs_req_t *req = NULL; -        server_state_t      *state = NULL; - -        req = gf_param (hdr); - -        state = CALL_STATE (frame); - -        state->resolve.type   = RESOLVE_MUST; -        state->resolve.ino    = ntoh64 (req->ino); -        if (!state->resolve.ino) -                state->resolve.ino = 1; -        state->resolve.gen    = ntoh64 (req->gen); -        state->resolve.path   = gf_strdup (req->path); - -        gf_resolve_and_resume (frame, server_statfs_resume); - -        return 0; -} - - -static int -server_opendir_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t  *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        state->fd = fd_create (state->loc.inode, frame->root->pid); - -        STACK_WIND (frame, server_opendir_cbk, -                    bound_xl, bound_xl->fops->opendir, -                    &state->loc, state->fd); -        return 0; -err: -        server_opendir_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                            state->resolve.op_errno, NULL); -        return 0; -} - - -static int -server_opendir (call_frame_t *frame, xlator_t *bound_xl, -                gf_hdr_common_t *hdr, size_t hdrlen, -                struct iobuf *iobuf) -{ -        gf_fop_opendir_req_t  *req = NULL; -        server_state_t        *state = NULL; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        state->resolve.type   = RESOLVE_MUST; -        state->resolve.path   = gf_strdup (req->path); -        state->resolve.ino    = ntoh64 (req->ino); -        state->resolve.gen    = ntoh64 (req->gen); - -        gf_resolve_and_resume (frame, server_opendir_resume); - -        return 0; -} - - -static int -server_releasedir (call_frame_t *frame, xlator_t *bound_xl, -                   gf_hdr_common_t *hdr, size_t hdrlen, -                   struct iobuf *iobuf) -{ -        gf_cbk_releasedir_req_t *req = NULL; -        server_connection_t     *conn = NULL; -        uint64_t                 fd_no = 0; - -        conn = SERVER_CONNECTION (frame); - -        req = gf_param (hdr); - -        fd_no = ntoh64 (req->fd); - -        gf_fd_put (conn->fdtable, fd_no); - -        server_releasedir_cbk (frame, NULL, frame->this, 0, 0); - -        return 0; -} - -/* - * server_readdirp_cbk - getdents callback for server protocol - * @frame: call frame - * @cookie: - * @this: - * @op_ret: - * @op_errno: - * - * not for external reference - */ -static int -server_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                     int32_t op_ret, int32_t op_errno, gf_dirent_t *entries) -{ -        gf_hdr_common_t         *hdr = NULL; -        gf_fop_readdirp_rsp_t   *rsp = NULL; -        size_t                  hdrlen = 0; -        size_t                  buf_size = 0; -        int32_t                 gf_errno = 0; -        server_state_t          *state = NULL; - -        if (op_ret > 0) -                buf_size = gf_dirent_serialize (entries, NULL, 0); - -        hdrlen = gf_hdr_len (rsp, buf_size); -        hdr    = gf_hdr_new (rsp, buf_size); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret > 0) { -                rsp->size = hton32 (buf_size); -                gf_dirent_serialize (entries, rsp->buf, buf_size); -        } else { -                state = CALL_STATE(frame); - -                gf_log (this->name, GF_LOG_TRACE, -                        "%"PRId64": READDIRP %"PRId64" (%"PRId64") ==>" -                        "%"PRId32" (%s)", -                        frame->root->unique, state->resolve.fd_no, -                        state->fd ? state->fd->inode->ino : 0, op_ret, -                        strerror (op_errno)); -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_READDIRP, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -static int -server_readdirp_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t  *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_readdirp_cbk, bound_xl, -                    bound_xl->fops->readdirp, state->fd, state->size, -                    state->offset); - -        return 0; -err: -        server_readdirp_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                             state->resolve.op_errno, NULL); -        return 0; -} - -/* - * server_readdirp - readdirp function for server protocol - * @frame: call frame - * @bound_xl: - * @params: parameter dictionary - * - * not for external reference - */ -static int -server_readdirp (call_frame_t *frame, xlator_t *bound_xl, gf_hdr_common_t *hdr, -                 size_t hdrlen, struct iobuf *iobuf) -{ -        gf_fop_readdirp_req_t *req = NULL; -        server_state_t *state = NULL; -        server_connection_t *conn = NULL; - -        conn = SERVER_CONNECTION(frame); - -        req   = gf_param (hdr); -        state = CALL_STATE(frame); - -        state->resolve.type = RESOLVE_MUST; -        state->resolve.fd_no = ntoh64 (req->fd); -        state->size   = ntoh32 (req->size); -        state->offset = ntoh64 (req->offset); - -        gf_resolve_and_resume (frame, server_readdirp_resume); - -        return 0; -} - - -static int - server_readdir_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t  *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_readdir_cbk, -                    bound_xl, -                    bound_xl->fops->readdir, -                    state->fd, state->size, state->offset); - -        return 0; -err: -        server_readdir_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                            state->resolve.op_errno, NULL); -        return 0; -} -/* - * server_readdir - readdir function for server protocol - * @frame: call frame - * @bound_xl: - * @params: parameter dictionary - * - * not for external reference - */ -static int -server_readdir (call_frame_t *frame, xlator_t *bound_xl, -                gf_hdr_common_t *hdr, size_t hdrlen, -                struct iobuf *iobuf) -{ -        gf_fop_readdir_req_t *req = NULL; -        server_state_t *state = NULL; -        server_connection_t *conn = NULL; - -        conn = SERVER_CONNECTION(frame); - -        req   = gf_param (hdr); -        state = CALL_STATE(frame); - -        state->resolve.type = RESOLVE_MUST; -        state->resolve.fd_no = ntoh64 (req->fd); -        state->size   = ntoh32 (req->size); -        state->offset = ntoh64 (req->offset); - -        gf_resolve_and_resume (frame, server_readdir_resume); - -        return 0; -} - -static int -server_fsyncdir_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_fsyncdir_cbk, -                    bound_xl, -                    bound_xl->fops->fsyncdir, -                    state->fd, state->flags); -        return 0; - -err: -        server_fsyncdir_cbk (frame, NULL, frame->this, -                             state->resolve.op_ret, -                             state->resolve.op_errno); -        return 0; -} - -/* - * server_fsyncdir - fsyncdir function for server protocol - * @frame: call frame - * @bound_xl: - * @params: parameter dictionary - * - * not for external reference - */ -static int -server_fsyncdir (call_frame_t *frame, xlator_t *bound_xl, -                 gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        gf_fop_fsyncdir_req_t *req = NULL; -        server_state_t        *state = NULL; -        server_connection_t   *conn = NULL; - -        conn = SERVER_CONNECTION (frame); - -        req   = gf_param (hdr); -        state = CALL_STATE(frame); - -        state->resolve.type = RESOLVE_MUST; -        state->resolve.fd_no = ntoh64 (req->fd); -        state->flags = ntoh32 (req->data); - -        gf_resolve_and_resume (frame, server_fsyncdir_resume); - -        return 0; -} - - -static int -server_mknod_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        state->loc.inode = inode_new (state->itable); - -        STACK_WIND (frame, server_mknod_cbk, -                    bound_xl, bound_xl->fops->mknod, -                    &(state->loc), state->mode, state->dev, -                    state->params); - -        return 0; -err: -        server_mknod_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                          state->resolve.op_errno, NULL, NULL, NULL, NULL); -        return 0; -} - - - -static int -server_mknod (call_frame_t *frame, xlator_t *bound_xl, -              gf_hdr_common_t *hdr, size_t hdrlen, -              struct iobuf *iobuf) -{ -        gf_fop_mknod_req_t *req = NULL; -        server_state_t     *state = NULL; -        size_t              pathlen = 0; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); -        pathlen = STRLEN_0 (req->path); - -        state->resolve.type    = RESOLVE_NOT; -        state->resolve.par     = ntoh64 (req->par); -        state->resolve.gen     = ntoh64 (req->gen); -        state->resolve.path    = gf_strdup (req->path); -        state->resolve.bname   = gf_strdup (req->bname + pathlen); - -        state->mode = ntoh32 (req->mode); -        state->dev  = ntoh64 (req->dev); - -        gf_resolve_and_resume (frame, server_mknod_resume); - -        return 0; -} - - -static int -server_mkdir_resume (call_frame_t *frame, xlator_t *bound_xl) - -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        state->loc.inode = inode_new (state->itable); - -        STACK_WIND (frame, server_mkdir_cbk, -                    bound_xl, bound_xl->fops->mkdir, -                    &(state->loc), state->mode, -                    state->params); - -        return 0; -err: -        server_mkdir_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                          state->resolve.op_errno, NULL, NULL, NULL, NULL); -        return 0; -} - - -static int -server_mkdir (call_frame_t *frame, xlator_t *bound_xl, -              gf_hdr_common_t *hdr, size_t hdrlen, -              struct iobuf *iobuf) -{ -        gf_fop_mkdir_req_t *req = NULL; -        server_state_t     *state = NULL; -        size_t              pathlen = 0; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); -        pathlen = STRLEN_0 (req->path); - -        state->resolve.type    = RESOLVE_NOT; -        state->resolve.par     = ntoh64 (req->par); -        state->resolve.gen     = ntoh64 (req->gen); -        state->resolve.path    = gf_strdup (req->path); -        state->resolve.bname   = gf_strdup (req->bname + pathlen); - -        state->mode = ntoh32 (req->mode); - -        gf_resolve_and_resume (frame, server_mkdir_resume); - -        return 0; -} - - -static int -server_rmdir_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_rmdir_cbk, -                    bound_xl, bound_xl->fops->rmdir, &state->loc); -        return 0; -err: -        server_rmdir_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                          state->resolve.op_errno, NULL, NULL); -        return 0; -} - -static int -server_rmdir (call_frame_t *frame, xlator_t *bound_xl, -              gf_hdr_common_t *hdr, size_t hdrlen, -              struct iobuf *iobuf) -{ -        gf_fop_rmdir_req_t *req = NULL; -        server_state_t     *state = NULL; -        int                 pathlen = 0; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); -        pathlen = STRLEN_0 (req->path); - -        state->resolve.type    = RESOLVE_MUST; -        state->resolve.par     = ntoh64 (req->par); -        state->resolve.gen     = ntoh64 (req->gen); -        state->resolve.path    = gf_strdup (req->path); -        state->resolve.bname   = gf_strdup (req->bname + pathlen); - -        gf_resolve_and_resume (frame, server_rmdir_resume); - -        return 0; -} - - -static int -server_inodelk_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_inodelk_cbk, -                    bound_xl, bound_xl->fops->inodelk, -                    state->volume, &state->loc, state->cmd, &state->flock); -        return 0; -err: -        server_inodelk_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                            state->resolve.op_errno); -        return 0; -} - - -static int -server_inodelk (call_frame_t *frame, xlator_t *bound_xl, -                gf_hdr_common_t *hdr, size_t hdrlen, -                struct iobuf *iobuf) -{ -        gf_fop_inodelk_req_t *req = NULL; -        server_state_t       *state = NULL; -        size_t                pathlen = 0; -        size_t                vollen  = 0; -        int                   cmd = 0; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); -        pathlen = STRLEN_0 (req->path); -        vollen  = STRLEN_0 (req->volume + pathlen); - -        state->resolve.type    = RESOLVE_EXACT; -        state->resolve.ino     = ntoh64 (req->ino); -        state->resolve.gen     = ntoh64 (req->gen); -        state->resolve.path    = gf_strdup (req->path); - -        cmd = ntoh32 (req->cmd); -        switch (cmd) { -        case GF_LK_GETLK: -                state->cmd = F_GETLK; -                break; -        case GF_LK_SETLK: -                state->cmd = F_SETLK; -                break; -        case GF_LK_SETLKW: -                state->cmd = F_SETLKW; -                break; -        } - -        state->type = ntoh32 (req->type); -        state->volume = gf_strdup (req->volume + pathlen); - -        gf_flock_to_flock (&req->flock, &state->flock); - -        switch (state->type) { -        case GF_LK_F_RDLCK: -                state->flock.l_type = F_RDLCK; -                break; -        case GF_LK_F_WRLCK: -                state->flock.l_type = F_WRLCK; -                break; -        case GF_LK_F_UNLCK: -                state->flock.l_type = F_UNLCK; -                break; -        } - -        gf_resolve_and_resume (frame, server_inodelk_resume); - -        return 0; -} - -static int -server_finodelk_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_finodelk_cbk, -                    BOUND_XL(frame), -                    BOUND_XL(frame)->fops->finodelk, -                    state->volume, state->fd, state->cmd, &state->flock); - -        return 0; -err: -        server_finodelk_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                             state->resolve.op_errno); - -        return 0; -} - -static int -server_finodelk (call_frame_t *frame, xlator_t *bound_xl, -                 gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        gf_fop_finodelk_req_t  *req = NULL; -        server_state_t         *state = NULL; -        server_connection_t    *conn = NULL; - -        conn = SERVER_CONNECTION(frame); - -        req   = gf_param (hdr); -        state = CALL_STATE(frame); - -        state->resolve.type = RESOLVE_EXACT; -        state->volume = gf_strdup (req->volume); -        state->resolve.fd_no = ntoh64 (req->fd); -        state->cmd = ntoh32 (req->cmd); - -        switch (state->cmd) { -        case GF_LK_GETLK: -                state->cmd = F_GETLK; -                break; -        case GF_LK_SETLK: -                state->cmd = F_SETLK; -                break; -        case GF_LK_SETLKW: -                state->cmd = F_SETLKW; -                break; -        } - -        state->type = ntoh32 (req->type); - -        gf_flock_to_flock (&req->flock, &state->flock); - -        switch (state->type) { -        case GF_LK_F_RDLCK: -                state->flock.l_type = F_RDLCK; -                break; -        case GF_LK_F_WRLCK: -                state->flock.l_type = F_WRLCK; -                break; -        case GF_LK_F_UNLCK: -                state->flock.l_type = F_UNLCK; -                break; -        } - -        gf_resolve_and_resume (frame, server_finodelk_resume); - -        return 0; -} - - -static int -server_entrylk_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_entrylk_cbk, -                    bound_xl, bound_xl->fops->entrylk, -                    state->volume, &state->loc, state->name, -                    state->cmd, state->type); -        return 0; -err: -        server_entrylk_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                            state->resolve.op_errno); -        return 0; -} - - -static int -server_entrylk (call_frame_t *frame, xlator_t *bound_xl, -                gf_hdr_common_t *hdr, size_t hdrlen, -                struct iobuf *iobuf) -{ -        gf_fop_entrylk_req_t *req = NULL; -        server_state_t       *state = NULL; -        size_t                pathlen = 0; -        size_t                namelen = 0; -        size_t                vollen  = 0; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); -        pathlen = STRLEN_0 (req->path); -        namelen = ntoh64 (req->namelen); -        vollen = STRLEN_0(req->volume + pathlen + namelen); - -        state->resolve.type   = RESOLVE_EXACT; -        state->resolve.path   = gf_strdup (req->path); -        state->resolve.ino    = ntoh64 (req->ino); -        state->resolve.gen    = ntoh64 (req->gen); - -        if (namelen) -                state->name   = gf_strdup (req->name + pathlen); -        state->volume         = gf_strdup (req->volume + pathlen + namelen); - -        state->cmd            = ntoh32 (req->cmd); -        state->type           = ntoh32 (req->type); - -        gf_resolve_and_resume (frame, server_entrylk_resume); - -        return 0; -} - -static int -server_fentrylk_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_fentrylk_cbk, -                    BOUND_XL(frame), -                    BOUND_XL(frame)->fops->fentrylk, -                    state->volume, state->fd, state->name, -                    state->cmd, state->type); - -        return 0; -err: -        server_fentrylk_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                             state->resolve.op_errno); -        return 0; -} - -static int -server_fentrylk (call_frame_t *frame, xlator_t *bound_xl, -                 gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        gf_fop_fentrylk_req_t *req = NULL; -        server_state_t        *state = NULL; -        size_t                 namelen = 0; -        size_t                 vollen  = 0; -        server_connection_t   *conn = NULL; - -        conn = SERVER_CONNECTION (frame); - -        req   = gf_param (hdr); -        state = CALL_STATE(frame); -        vollen = STRLEN_0(req->volume + namelen); - -        state->resolve.type = RESOLVE_EXACT; -        state->resolve.fd_no = ntoh64 (req->fd); -        state->cmd  = ntoh32 (req->cmd); -        state->type = ntoh32 (req->type); -        namelen = ntoh64 (req->namelen); -        if (namelen) -                state->name = req->name; -        state->volume = gf_strdup (req->volume + namelen); - - -        gf_resolve_and_resume (frame, server_fentrylk_resume); - -        return 0; -} - - -static int -server_access_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_access_cbk, -                    bound_xl, bound_xl->fops->access, -                    &state->loc, state->mask); -        return 0; -err: -        server_access_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                           state->resolve.op_errno); -        return 0; -} - - -static int -server_access (call_frame_t *frame, xlator_t *bound_xl, -               gf_hdr_common_t *hdr, size_t hdrlen, -               struct iobuf *iobuf) -{ -        gf_fop_access_req_t *req = NULL; -        server_state_t      *state = NULL; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        state->resolve.type  = RESOLVE_MUST; -        state->resolve.ino   = hton64 (req->ino); -        state->resolve.gen   = hton64 (req->gen); -        state->resolve.path  = gf_strdup (req->path); - -        state->mask  = ntoh32 (req->mask); - -        gf_resolve_and_resume (frame, server_access_resume); - -        return 0; -} - - -static int -server_symlink_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        state->loc.inode = inode_new (state->itable); - -        STACK_WIND (frame, server_symlink_cbk, -                    bound_xl, bound_xl->fops->symlink, -                    state->name, &state->loc, state->params); - -        return 0; -err: -        server_symlink_cbk (frame, NULL, frame->this, state->resolve.op_ret, -                            state->resolve.op_errno, NULL, NULL, NULL, NULL); -        return 0; -} - - - -static int -server_symlink (call_frame_t *frame, xlator_t *bound_xl, -                gf_hdr_common_t *hdr, size_t hdrlen, -                struct iobuf *iobuf) -{ -        server_state_t       *state = NULL; -        gf_fop_symlink_req_t *req = NULL; -        size_t                pathlen = 0; -        size_t                baselen = 0; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); -        pathlen = STRLEN_0 (req->path); -        baselen = STRLEN_0 (req->bname + pathlen); - -        state->resolve.type   = RESOLVE_NOT; -        state->resolve.par    = ntoh64 (req->par); -        state->resolve.gen    = ntoh64 (req->gen); -        state->resolve.path   = gf_strdup (req->path); -        state->resolve.bname  = gf_strdup (req->bname + pathlen); -        state->name           = gf_strdup (req->linkname + pathlen + baselen); - -        gf_resolve_and_resume (frame, server_symlink_resume); - -        return 0; -} - - -static int -server_link_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; -        int             op_ret = 0; -        int             op_errno = 0; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) { -                op_ret   = state->resolve.op_ret; -                op_errno = state->resolve.op_errno; -                goto err; -        } - -        if (state->resolve2.op_ret != 0) { -                op_ret   = state->resolve2.op_ret; -                op_errno = state->resolve2.op_errno; -                goto err; -        } - -        state->loc2.inode = inode_ref (state->loc.inode); - -        STACK_WIND (frame, server_link_cbk, -                    bound_xl, bound_xl->fops->link, -                    &state->loc, &state->loc2); -        return 0; -err: -        server_link_cbk (frame, NULL, frame->this, op_ret, op_errno, -                         NULL, NULL, NULL, NULL); -        return 0; -} - - -static int -server_link (call_frame_t *frame, xlator_t *this, -             gf_hdr_common_t *hdr, size_t hdrlen, -             struct iobuf *iobuf) -{ -        gf_fop_link_req_t *req = NULL; -        server_state_t    *state = NULL; -        size_t             oldpathlen = 0; -        size_t             newpathlen = 0; -        size_t             newbaselen = 0; - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); -        oldpathlen = STRLEN_0 (req->oldpath); -        newpathlen = STRLEN_0 (req->newpath  + oldpathlen); -        newbaselen = STRLEN_0 (req->newbname + oldpathlen + newpathlen); - -        state->resolve.type    = RESOLVE_MUST; -        state->resolve.path    = gf_strdup (req->oldpath); -        state->resolve.ino     = ntoh64 (req->oldino); -        state->resolve.gen     = ntoh64 (req->oldgen); - -        state->resolve2.type   = RESOLVE_NOT; -        state->resolve2.path   = gf_strdup (req->newpath + oldpathlen); -        state->resolve2.bname  = gf_strdup (req->newbname + oldpathlen + newpathlen); -        state->resolve2.par    = ntoh64 (req->newpar); -        state->resolve2.gen    = ntoh64 (req->newgen); - -        gf_resolve_and_resume (frame, server_link_resume); - -        return 0; -} - - -static int -server_rename_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; -        int             op_ret = 0; -        int             op_errno = 0; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) { -                op_ret   = state->resolve.op_ret; -                op_errno = state->resolve.op_errno; -                goto err; -        } - -        if (state->resolve2.op_ret != 0) { -                op_ret   = state->resolve2.op_ret; -                op_errno = state->resolve2.op_errno; -                goto err; -        } - -        STACK_WIND (frame, server_rename_cbk, -                    bound_xl, bound_xl->fops->rename, -                    &state->loc, &state->loc2); -        return 0; -err: -        server_rename_cbk (frame, NULL, frame->this, op_ret, op_errno, -                           NULL, NULL, NULL, NULL, NULL); -        return 0; -} - - -static int -server_rename (call_frame_t *frame, xlator_t *bound_xl, -               gf_hdr_common_t *hdr, size_t hdrlen, -               struct iobuf *iobuf) -{ -        gf_fop_rename_req_t *req = NULL; -        server_state_t      *state = NULL; -        size_t               oldpathlen = 0; -        size_t               oldbaselen = 0; -        size_t               newpathlen = 0; -        size_t               newbaselen = 0; - -        req = gf_param (hdr); - -        state = CALL_STATE (frame); -        oldpathlen = STRLEN_0 (req->oldpath); -        oldbaselen = STRLEN_0 (req->oldbname + oldpathlen); -        newpathlen = STRLEN_0 (req->newpath  + oldpathlen + oldbaselen); -        newbaselen = STRLEN_0 (req->newbname + oldpathlen + -                               oldbaselen + newpathlen); - -        state->resolve.type   = RESOLVE_MUST; -        state->resolve.path   = gf_strdup (req->oldpath); -        state->resolve.bname  = gf_strdup (req->oldbname + oldpathlen); -        state->resolve.par    = ntoh64 (req->oldpar); -        state->resolve.gen    = ntoh64 (req->oldgen); - -        state->resolve2.type  = RESOLVE_MAY; -        state->resolve2.path  = gf_strdup (req->newpath  + oldpathlen + oldbaselen); -        state->resolve2.bname = gf_strdup (req->newbname + oldpathlen + oldbaselen + -                                        newpathlen); -        state->resolve2.par   = ntoh64 (req->newpar); -        state->resolve2.gen   = ntoh64 (req->newgen); - -        gf_resolve_and_resume (frame, server_rename_resume); - -        return 0; -} - -static int -server_lk_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) -                goto err; - -        STACK_WIND (frame, server_lk_cbk, -                    BOUND_XL(frame), -                    BOUND_XL(frame)->fops->lk, -                    state->fd, state->cmd, &state->flock); - -        return 0; - -err: -        server_lk_cbk (frame, NULL, frame->this, -                       state->resolve.op_ret, -                       state->resolve.op_errno, -                       NULL); -        return 0; -} - -/* - * server_lk - lk function for server protocol - * @frame: call frame - * @bound_xl: - * @params: parameter dictionary - * - * not for external reference - */ - -static int -server_lk (call_frame_t *frame, xlator_t *bound_xl, -           gf_hdr_common_t *hdr, size_t hdrlen, -           struct iobuf *iobuf) -{ -        gf_fop_lk_req_t     *req = NULL; -        server_state_t      *state = NULL; -        server_connection_t *conn = NULL; - -        conn = SERVER_CONNECTION (frame); - -        req   = gf_param (hdr); -        state = CALL_STATE (frame); - -        state->resolve.fd_no = ntoh64 (req->fd); -        state->cmd =  ntoh32 (req->cmd); -        state->type = ntoh32 (req->type); - -        switch (state->cmd) { -        case GF_LK_GETLK: -                state->cmd = F_GETLK; -                break; -        case GF_LK_SETLK: -                state->cmd = F_SETLK; -                break; -        case GF_LK_SETLKW: -                state->cmd = F_SETLKW; -                break; -        } - -        gf_flock_to_flock (&req->flock, &state->flock); - -        switch (state->type) { -        case GF_LK_F_RDLCK: -                state->flock.l_type = F_RDLCK; -                break; -        case GF_LK_F_WRLCK: -                state->flock.l_type = F_WRLCK; -                break; -        case GF_LK_F_UNLCK: -                state->flock.l_type = F_UNLCK; -                break; -        default: -                gf_log (bound_xl->name, GF_LOG_ERROR, -                        "fd - %"PRId64" (%"PRId64"): Unknown lock type: %"PRId32"!", -                        state->resolve.fd_no, state->fd->inode->ino, state->type); -                break; -        } - - -        gf_resolve_and_resume (frame, server_lk_resume); - -        return 0; -} - -/* xxx_MOPS */ -static int -_volfile_update_checksum (xlator_t *this, char *key, uint32_t checksum) -{ -        server_conf_t       *conf         = NULL; -        struct _volfile_ctx *temp_volfile = NULL; - -        conf         = this->private; -        temp_volfile = conf->volfile; - -        while (temp_volfile) { -                if ((NULL == key) && (NULL == temp_volfile->key)) -                        break; -                if ((NULL == key) || (NULL == temp_volfile->key)) { -                        temp_volfile = temp_volfile->next; -                        continue; -                } -                if (strcmp (temp_volfile->key, key) == 0) -                        break; -                temp_volfile = temp_volfile->next; -        } - -        if (!temp_volfile) { -                temp_volfile = GF_CALLOC (1, sizeof (struct _volfile_ctx), -                                          gf_server_mt_volfile_ctx); -                if (!temp_volfile) -                        goto out; -                temp_volfile->next  = conf->volfile; -                temp_volfile->key   = (key)? gf_strdup (key): NULL; -                temp_volfile->checksum = checksum; - -                conf->volfile = temp_volfile; -                goto out; -        } - -        if (temp_volfile->checksum != checksum) { -                gf_log (this->name, GF_LOG_CRITICAL, -                        "the volume file got modified between earlier access " -                        "and now, this may lead to inconsistency between " -                        "clients, advised to remount client"); -                temp_volfile->checksum  = checksum; -        } - - out: -        return 0; -} - - -size_t -build_volfile_path (xlator_t *this, const char *key, char *path, -                    size_t path_len) -{ -        int             ret = -1; -        int             free_filename = 0; -        int             free_conf_dir = 0; -        char            *filename = NULL; -        char            *conf_dir = CONFDIR; -        struct stat      buf      = {0,}; -        data_t *         conf_dir_data = NULL; -        char             data_key[256] = {0,}; - -        /* Inform users that this option is changed now */ -        ret = dict_get_str (this->options, "client-volume-filename", -                            &filename); -        if (ret == 0) { -                gf_log (this->name, GF_LOG_WARNING, -                        "option 'client-volume-filename' is changed to " -                        "'volume-filename.<key>' which now takes 'key' as an " -                        "option to choose/fetch different files from server. " -                        "Refer documentation or contact developers for more " -                        "info. Currently defaulting to given file '%s'", -                        filename); -        } - -        if (key && !filename) { -                sprintf (data_key, "volume-filename.%s", key); -                ret = dict_get_str (this->options, data_key, &filename); - -                if (ret < 0) { - -                        conf_dir_data = dict_get (this->options, "conf-dir"); -                        if (conf_dir_data) { -                                /* Check whether the specified directory exists, -                                   or directory specified is non standard */ -                                ret = stat (conf_dir_data->data, &buf); -                                if ((ret != 0) || !S_ISDIR (buf.st_mode)) { -                                        gf_log (this->name, GF_LOG_ERROR, -                                                "Directory '%s' doesn't" -                                                "exist, exiting.", -                                                conf_dir_data->data); -                                        ret = -1; -                                        goto out; -                                } -                                /* Make sure that conf-dir doesn't -                                 * contain ".." in path -                                 */ -                                if ((gf_strstr (conf_dir_data->data, -                                                "/", "..")) == -1) { -                                        ret = -1; -                                        gf_log (this->name, GF_LOG_ERROR, -                                                "%s: invalid conf_dir", -                                                conf_dir_data->data); -                                        goto out; -                                } - -                                /* Make sure that key doesn't -                                 * contain "../" in path -                                 */ - -                                if ((gf_strstr (key, "/", "..")) == -1) { -                                        ret = -1; -                                        gf_log (this->name, GF_LOG_ERROR, -                                                "%s: invalid key", key); -                                        goto out; -                                } - -                                conf_dir = gf_strdup (conf_dir_data->data); -                                free_conf_dir = 1; -                        } - -                        ret = gf_asprintf (&filename, "%s/%s.vol", -                                           conf_dir, key); -                        if (-1 == ret) -                                goto out; - -                        free_filename = 1; -                } -        } - -        if (!filename) { -                ret = dict_get_str (this->options, -                                    "volume-filename.default", &filename); -                if (ret < 0) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "no default volume filename given, " -                                "defaulting to %s", DEFAULT_VOLUME_FILE_PATH); -                        filename = DEFAULT_VOLUME_FILE_PATH; -                } -        } - -        ret = -1; - -        if ((filename) && (path_len > strlen (filename))) { -                strcpy (path, filename); -                ret = strlen (filename); -        } - -out: -        if (free_conf_dir) -                GF_FREE (conf_dir); - -        if (free_filename) -                GF_FREE (filename); - -        return ret; -} - -static int -_validate_volfile_checksum (xlator_t *this, char *key, -                            uint32_t checksum) -{ -        char                 filename[PATH_MAX] = {0,}; -        server_conf_t       *conf         = NULL; -        struct _volfile_ctx *temp_volfile = NULL; -        int                  ret          = 0; -        uint32_t             local_checksum = 0; - -        conf         = this->private; -        temp_volfile = conf->volfile; - -        if (!checksum) -                goto out; - -        if (!temp_volfile) { -                ret = build_volfile_path (this, key, filename, -                                          sizeof (filename)); -                if (ret <= 0) -                        goto out; -                ret = open (filename, O_RDONLY); -                if (-1 == ret) { -                        ret = 0; -                        gf_log (this->name, GF_LOG_DEBUG, -                                "failed to open volume file (%s) : %s", -                                filename, strerror (errno)); -                        goto out; -                } -                get_checksum_for_file (ret, &local_checksum); -                _volfile_update_checksum (this, key, local_checksum); -                close (ret); -        } - -        temp_volfile = conf->volfile; -        while (temp_volfile) { -                if ((NULL == key) && (NULL == temp_volfile->key)) -                        break; -                if ((NULL == key) || (NULL == temp_volfile->key)) { -                        temp_volfile = temp_volfile->next; -                        continue; -                } -                if (strcmp (temp_volfile->key, key) == 0) -                        break; -                temp_volfile = temp_volfile->next; -        } - -        if (!temp_volfile) -                goto out; - -        if ((temp_volfile->checksum) && -            (checksum != temp_volfile->checksum)) -                ret = -1; - -out: -        return ret; -} - -/* Management Calls */ -/* - * mop_getspec - getspec function for server protocol - * @frame: call frame - * @bound_xl: - * @params: - * - */ -static int -mop_getspec (call_frame_t *frame, xlator_t *bound_xl, -             gf_hdr_common_t *hdr, size_t hdrlen, -             struct iobuf *iobuf) -{ -        gf_hdr_common_t      *_hdr = NULL; -        gf_mop_getspec_rsp_t *rsp = NULL; -        int32_t               ret = -1; -        int32_t               op_errno = ENOENT; -        int32_t               gf_errno = 0; -        int32_t               spec_fd = -1; -        size_t                file_len = 0; -        size_t                _hdrlen = 0; -        char                  filename[PATH_MAX] = {0,}; -        struct stat           stbuf = {0,}; -        gf_mop_getspec_req_t *req = NULL; -        uint32_t              checksum = 0; -        uint32_t              flags  = 0; -        uint32_t              keylen = 0; -        char                 *key = NULL; -        server_conf_t        *conf = NULL; - -        req   = gf_param (hdr); -        flags = ntoh32 (req->flags); -        keylen = ntoh32 (req->keylen); -        if (keylen) { -                key = req->key; -        } - -        conf = frame->this->private; - -        ret = build_volfile_path (frame->this, key, filename, -                                  sizeof (filename)); -        if (ret > 0) { -                /* to allocate the proper buffer to hold the file data */ -                ret = stat (filename, &stbuf); -                if (ret < 0){ -                        gf_log (frame->this->name, GF_LOG_ERROR, -                                "Unable to stat %s (%s)", -                                filename, strerror (errno)); -                        goto fail; -                } - -                spec_fd = open (filename, O_RDONLY); -                if (spec_fd < 0) { -                        gf_log (frame->this->name, GF_LOG_ERROR, -                                "Unable to open %s (%s)", -                                filename, strerror (errno)); -                        goto fail; -                } -                ret = 0; -                file_len = stbuf.st_size; -                if (conf->verify_volfile_checksum) { -                        get_checksum_for_file (spec_fd, &checksum); -                        _volfile_update_checksum (frame->this, key, checksum); -                } -        } else { -                errno = ENOENT; -        } - -fail: -        op_errno = errno; - -        _hdrlen = gf_hdr_len (rsp, file_len + 1); -        _hdr    = gf_hdr_new (rsp, file_len + 1); -        rsp     = gf_param (_hdr); - -        _hdr->rsp.op_ret = hton32 (ret); -        gf_errno         = gf_errno_to_error (op_errno); -        _hdr->rsp.op_errno = hton32 (gf_errno); - -        if (file_len) { -                ret = read (spec_fd, rsp->spec, file_len); -                close (spec_fd); -        } -        protocol_server_reply (frame, GF_OP_TYPE_MOP_REPLY, GF_MOP_GETSPEC, -                               _hdr, _hdrlen, NULL, 0, NULL); - -        return 0; -} - - - -static int -server_checksum (call_frame_t *frame, xlator_t *bound_xl, -                 gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        gf_hdr_common_t     *rsp_hdr = NULL; -        gf_mop_ping_rsp_t   *rsp = NULL;     /* Using for  NULL */ -        size_t               rsp_hdrlen = 0; -        int32_t              gf_errno = 0; - -        rsp_hdrlen = gf_hdr_len (rsp, 0); -        rsp_hdr    = gf_hdr_new (rsp, 0); - -        gf_errno = gf_errno_to_error (ENOSYS); -        hdr->rsp.op_errno = hton32 (gf_errno); -        hdr->rsp.op_ret = -1; - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_CHECKSUM, -                               rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - -        return 0; -} - - -static int -server_rchecksum_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                      int32_t op_ret, int32_t op_errno, -                      uint32_t weak_checksum, uint8_t *strong_checksum) -{ -        gf_hdr_common_t       *hdr = NULL; -        gf_fop_rchecksum_rsp_t *rsp = NULL; -        size_t                 hdrlen = 0; -        int32_t                gf_errno = 0; - -        hdrlen = gf_hdr_len (rsp, MD5_DIGEST_LEN + 1); -        hdr    = gf_hdr_new (rsp, MD5_DIGEST_LEN + 1); -        rsp    = gf_param (hdr); - -        hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno        = gf_errno_to_error (op_errno); -        hdr->rsp.op_errno = hton32 (gf_errno); - -        if (op_ret >= 0) { -                rsp->weak_checksum = weak_checksum; - -                memcpy (rsp->strong_checksum, -                        strong_checksum, MD5_DIGEST_LEN); - -                rsp->strong_checksum[MD5_DIGEST_LEN] = '\0'; -        } - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_RCHECKSUM, -                               hdr, hdrlen, NULL, 0, NULL); - -        return 0; -} - -static int -server_rchecksum_resume (call_frame_t *frame, xlator_t *bound_xl) -{ -        server_state_t *state = NULL; -        int             op_ret = 0; -        int             op_errno = 0; - -        state = CALL_STATE (frame); - -        if (state->resolve.op_ret != 0) { -                op_ret   = state->resolve.op_ret; -                op_errno = state->resolve.op_errno; -                goto err; -        } - -        STACK_WIND (frame, server_rchecksum_cbk, -                    bound_xl, -                    bound_xl->fops->rchecksum, -                    state->fd, state->offset, state->size); - -        return 0; -err: -        server_rchecksum_cbk (frame, NULL, frame->this, -1, EINVAL, 0, NULL); - -        return 0; - -} - -static int -server_rchecksum (call_frame_t *frame, xlator_t *bound_xl, -                  gf_hdr_common_t *hdr, size_t hdrlen, -                  struct iobuf *iobuf) -{ -        gf_fop_rchecksum_req_t  *req = NULL; -        server_state_t          *state = NULL; -        server_connection_t     *conn = NULL; - -        conn = SERVER_CONNECTION(frame); - -        req = gf_param (hdr); - -        state = CALL_STATE(frame); - -        state->resolve.type = RESOLVE_MAY; -        state->resolve.fd_no = ntoh64 (req->fd); -        state->offset = ntoh64 (req->offset); -        state->size   = ntoh32 (req->len); - -        gf_resolve_and_resume (frame, server_rchecksum_resume); - -        return 0; -} - - -/* - * mop_unlock - unlock management function for server protocol - * @frame: call frame - * @bound_xl: - * @params: parameter dictionary - * - */ -static int -mop_getvolume (call_frame_t *frame, xlator_t *bound_xl, -               gf_hdr_common_t *hdr, size_t hdrlen, -               struct iobuf *iobuf) -{ -        return 0; -} - -struct __get_xl_struct { -        const char *name; -        xlator_t *reply; -}; - -static void __check_and_set (xlator_t *each, void *data) -{ -        if (!strcmp (each->name, -                     ((struct __get_xl_struct *) data)->name)) -                ((struct __get_xl_struct *) data)->reply = each; -} - -static xlator_t * -get_xlator_by_name (xlator_t *some_xl, const char *name) -{ -        struct __get_xl_struct get = { -                .name = name, -                .reply = NULL -        }; - -        xlator_foreach (some_xl, __check_and_set, &get); - -        return get.reply; -} - - -/* - * mop_setvolume - setvolume management function for server protocol - * @frame: call frame - * @bound_xl: - * @params: parameter dictionary - * - */ -static int -mop_setvolume (call_frame_t *frame, xlator_t *bound_xl, -               gf_hdr_common_t *req_hdr, size_t req_hdrlen, -               struct iobuf *iobuf) -{ -        server_connection_t         *conn = NULL; -        server_conf_t               *conf = NULL; -        gf_hdr_common_t             *rsp_hdr = NULL; -        gf_mop_setvolume_req_t      *req = NULL; -        gf_mop_setvolume_rsp_t      *rsp = NULL; -        peer_info_t                 *peerinfo = NULL; -        int32_t                      ret = -1; -        int32_t                      op_ret = -1; -        int32_t                      op_errno = EINVAL; -        int32_t                      gf_errno = 0; -        dict_t                      *reply = NULL; -        dict_t                      *config_params = NULL; -        dict_t                      *params = NULL; -        char                        *name = NULL; -        char                        *version = NULL; -        char                        *process_uuid = NULL; -        xlator_t                    *xl = NULL; -        transport_t                 *trans = NULL; -        size_t                       rsp_hdrlen = -1; -        size_t                       dict_len = -1; -        size_t                       req_dictlen = -1; -        char                        *msg = NULL; -        char                        *volfile_key = NULL; -        uint32_t                     checksum = 0; -        int32_t                      lru_limit = 1024; - -        params = dict_new (); -        reply  = dict_new (); - -        req    = gf_param (req_hdr); -        req_dictlen = ntoh32 (req->dict_len); -        ret = dict_unserialize (req->buf, req_dictlen, ¶ms); - -        config_params = dict_copy_with_ref (frame->this->options, NULL); -        trans         = TRANSPORT_FROM_FRAME(frame); -        conf          = SERVER_CONF(frame); - -        if (ret < 0) { -                ret = dict_set_str (reply, "ERROR", -                                    "Internal error: failed to unserialize " -                                    "request dictionary"); -                if (ret < 0) -                        gf_log (bound_xl->name, GF_LOG_DEBUG, -                                "failed to set error msg \"%s\"", -                                "Internal error: failed to unserialize " -                                "request dictionary"); - -                op_ret = -1; -                op_errno = EINVAL; -                goto fail; -        } - -        ret = dict_get_str (params, "process-uuid", &process_uuid); -        if (ret < 0) { -                ret = dict_set_str (reply, "ERROR", -                                    "UUID not specified"); -                if (ret < 0) -                        gf_log (bound_xl->name, GF_LOG_DEBUG, -                                "failed to set error msg"); - -                op_ret = -1; -                op_errno = EINVAL; -                goto fail; -        } - - -        conn = gf_server_connection_get (frame->this, process_uuid); -        if (trans->xl_private != conn) -                trans->xl_private = conn; - -        ret = dict_get_str (params, "protocol-version", &version); -        if (ret < 0) { -                ret = dict_set_str (reply, "ERROR", -                                    "No version number specified"); -                if (ret < 0) -                        gf_log (trans->xl->name, GF_LOG_DEBUG, -                                "failed to set error msg"); - -                op_ret = -1; -                op_errno = EINVAL; -                goto fail; -        } - -        ret = strcmp (version, GF_PROTOCOL_VERSION); -        if (ret != 0) { -                ret = gf_asprintf (&msg, "protocol version mismatch: client(%s) " -                                "- server(%s)", version, GF_PROTOCOL_VERSION); -                if (-1 == ret) { -                        gf_log (trans->xl->name, GF_LOG_ERROR, -                                "gf_asprintf failed while setting up error msg"); -                        goto fail; -                } -                ret = dict_set_dynstr (reply, "ERROR", msg); -                if (ret < 0) -                        gf_log (trans->xl->name, GF_LOG_DEBUG, -                                "failed to set error msg"); - -                op_ret = -1; -                op_errno = EINVAL; -                goto fail; -        } - -        ret = dict_get_str (params, -                            "remote-subvolume", &name); -        if (ret < 0) { -                ret = dict_set_str (reply, "ERROR", -                                    "No remote-subvolume option specified"); -                if (ret < 0) -                        gf_log (trans->xl->name, GF_LOG_DEBUG, -                                "failed to set error msg"); - -                op_ret = -1; -                op_errno = EINVAL; -                goto fail; -        } - -        xl = get_xlator_by_name (frame->this, name); -        if (xl == NULL) { -                ret = gf_asprintf (&msg, "remote-subvolume \"%s\" is not found", -                                name); -                if (-1 == ret) { -                        gf_log (trans->xl->name, GF_LOG_ERROR, -                                "gf_asprintf failed while setting error msg"); -                        goto fail; -                } -                ret = dict_set_dynstr (reply, "ERROR", msg); -                if (ret < 0) -                        gf_log (trans->xl->name, GF_LOG_DEBUG, -                                "failed to set error msg"); - -                op_ret = -1; -                op_errno = ENOENT; -                goto fail; -        } - -        if (conf->verify_volfile_checksum) { -                ret = dict_get_uint32 (params, "volfile-checksum", &checksum); -                if (ret == 0) { -                        ret = dict_get_str (params, "volfile-key", -                                            &volfile_key); - -                        ret = _validate_volfile_checksum (trans->xl, -                                                          volfile_key, -                                                          checksum); -                        if (-1 == ret) { -                                ret = dict_set_str (reply, "ERROR", -                                                    "volume-file checksum " -                                                    "varies from earlier " -                                                    "access"); -                                if (ret < 0) -                                        gf_log (trans->xl->name, GF_LOG_DEBUG, -                                                "failed to set error msg"); - -                                op_ret   = -1; -                                op_errno = ESTALE; -                                goto fail; -                        } -                } -        } - - -        peerinfo = &trans->peerinfo; -        ret = dict_set_static_ptr (params, "peer-info", peerinfo); -        if (ret < 0) -                gf_log (trans->xl->name, GF_LOG_DEBUG, -                        "failed to set peer-info"); -        ret = dict_set_str (params, "peer-info-name", peerinfo->identifier); -        if (ret < 0) -                gf_log (trans->xl->name, GF_LOG_DEBUG, -                        "failed to set peer-info-name"); - -        if (conf->auth_modules == NULL) { -                gf_log (trans->xl->name, GF_LOG_ERROR, -                        "Authentication module not initialized"); -        } - -        ret = gf_authenticate (params, config_params, -                               conf->auth_modules); -        if (ret == AUTH_ACCEPT) { -                gf_log (trans->xl->name, GF_LOG_INFO, -                        "accepted client from %s", -                        peerinfo->identifier); -                op_ret = 0; -                conn->bound_xl = xl; -                ret = dict_set_str (reply, "ERROR", "Success"); -                if (ret < 0) -                        gf_log (trans->xl->name, GF_LOG_DEBUG, -                                "failed to set error msg"); -        } else { -                gf_log (trans->xl->name, GF_LOG_ERROR, -                        "Cannot authenticate client from %s", -                        peerinfo->identifier); -                op_ret = -1; -                op_errno = EACCES; -                ret = dict_set_str (reply, "ERROR", "Authentication failed"); -                if (ret < 0) -                        gf_log (bound_xl->name, GF_LOG_DEBUG, -                                "failed to set error msg"); - -                goto fail; -        } - -        if (conn->bound_xl == NULL) { -                ret = dict_set_str (reply, "ERROR", -                                    "Check volfile and handshake " -                                    "options in protocol/client"); -                if (ret < 0) -                        gf_log (trans->xl->name, GF_LOG_DEBUG, -                                "failed to set error msg"); - -                op_ret = -1; -                op_errno = EACCES; -                goto fail; -        } - -        if ((conn->bound_xl != NULL) && -            (ret >= 0)                   && -            (conn->bound_xl->itable == NULL)) { -                /* create inode table for this bound_xl, if one doesn't -                   already exist */ -                lru_limit = INODE_LRU_LIMIT (frame->this); - -                gf_log (trans->xl->name, GF_LOG_TRACE, -                        "creating inode table with lru_limit=%"PRId32", " -                        "xlator=%s", lru_limit, conn->bound_xl->name); - -                conn->bound_xl->itable = -                        inode_table_new (lru_limit, -                                         conn->bound_xl); -        } - -        ret = dict_set_str (reply, "process-uuid", -                            xl->ctx->process_uuid); - -        ret = dict_set_uint64 (reply, "transport-ptr", -                               ((uint64_t) (long) trans)); - -fail: -        dict_len = dict_serialized_length (reply); -        if (dict_len < 0) { -                gf_log ("server", GF_LOG_DEBUG, -                        "failed to get serialized length of reply dict"); -                op_ret   = -1; -                op_errno = EINVAL; -                dict_len = 0; -        } - -        rsp_hdr    = gf_hdr_new (rsp, dict_len); -        rsp_hdrlen = gf_hdr_len (rsp, dict_len); -        rsp = gf_param (rsp_hdr); - -        if (dict_len) { -                ret = dict_serialize (reply, rsp->buf); -                if (ret < 0) { -                        gf_log ("server", GF_LOG_DEBUG, -                                "failed to serialize reply dict"); -                        op_ret = -1; -                        op_errno = -ret; -                } -        } -        rsp->dict_len = hton32 (dict_len); - -        rsp_hdr->rsp.op_ret = hton32 (op_ret); -        gf_errno = gf_errno_to_error (op_errno); -        rsp_hdr->rsp.op_errno = hton32 (gf_errno); - -        protocol_server_reply (frame, GF_OP_TYPE_MOP_REPLY, GF_MOP_SETVOLUME, -                               rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - -        dict_unref (params); -        dict_unref (reply); -        dict_unref (config_params); - -        return 0; -} - - -static int -mop_ping (call_frame_t *frame, xlator_t *bound_xl, -          gf_hdr_common_t *hdr, size_t hdrlen, -          struct iobuf *iobuf) -{ -        gf_hdr_common_t     *rsp_hdr = NULL; -        gf_mop_ping_rsp_t   *rsp = NULL; -        size_t               rsp_hdrlen = 0; - -        rsp_hdrlen = gf_hdr_len (rsp, 0); -        rsp_hdr    = gf_hdr_new (rsp, 0); - -        hdr->rsp.op_ret = 0; - -        protocol_server_reply (frame, GF_OP_TYPE_MOP_REPLY, GF_MOP_PING, -                               rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - -        return 0; -} - - -static int -mop_log (call_frame_t *frame, xlator_t *bound_xl, -         gf_hdr_common_t *hdr, size_t hdrlen, -         struct iobuf *iobuf) -{ -        gf_mop_log_req_t *    req = NULL; -        char *                msg = NULL; -        uint32_t           msglen = 0; - -        transport_t *       trans = NULL; - -        trans = TRANSPORT_FROM_FRAME (frame); - -        req    = gf_param (hdr); -        msglen = ntoh32 (req->msglen); - -        if (msglen) -                msg = req->msg; - -        gf_log_from_client (msg, trans->peerinfo.identifier); - -        return 0; -} - - -/* ENOSYS operations (for backword compatibility) */ -static int -server_setdents (call_frame_t *frame, xlator_t *bound_xl, -                 gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        gf_hdr_common_t     *rsp_hdr = NULL; -        gf_mop_ping_rsp_t   *rsp = NULL;     /* Using for  NULL */ -        size_t               rsp_hdrlen = 0; -        int32_t              gf_errno = 0; - -        rsp_hdrlen = gf_hdr_len (rsp, 0); -        rsp_hdr    = gf_hdr_new (rsp, 0); - -        gf_errno = gf_errno_to_error (ENOSYS); -        hdr->rsp.op_errno = hton32 (gf_errno); -        hdr->rsp.op_ret = -1; - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_SETDENTS, -                               rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* */ -static int -server_getdents (call_frame_t *frame, xlator_t *bound_xl, -                 gf_hdr_common_t *hdr, size_t hdrlen, -                 struct iobuf *iobuf) -{ -        gf_hdr_common_t     *rsp_hdr = NULL; -        gf_mop_ping_rsp_t   *rsp = NULL;     /* Using for  NULL */ -        size_t               rsp_hdrlen = 0; -        int32_t              gf_errno = 0; - -        rsp_hdrlen = gf_hdr_len (rsp, 0); -        rsp_hdr    = gf_hdr_new (rsp, 0); - -        gf_errno = gf_errno_to_error (ENOSYS); -        hdr->rsp.op_errno = hton32 (gf_errno); -        hdr->rsp.op_ret = -1; - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_GETDENTS, -                               rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* */ -static int -server_lock_notify (call_frame_t *frame, xlator_t *bound_xl, -                    gf_hdr_common_t *hdr, size_t hdrlen, -                    struct iobuf *iobuf) -{ -        gf_hdr_common_t     *rsp_hdr = NULL; -        gf_mop_ping_rsp_t   *rsp = NULL;     /* Using for  NULL */ -        size_t               rsp_hdrlen = 0; -        int32_t              gf_errno = 0; - -        rsp_hdrlen = gf_hdr_len (rsp, 0); -        rsp_hdr    = gf_hdr_new (rsp, 0); - -        gf_errno = gf_errno_to_error (ENOSYS); -        hdr->rsp.op_errno = hton32 (gf_errno); -        hdr->rsp.op_ret = -1; - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_LOCK_NOTIFY, -                               rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - -        return 0; -} - -/* */ -static int -server_lock_fnotify (call_frame_t *frame, xlator_t *bound_xl, -                     gf_hdr_common_t *hdr, size_t hdrlen, -                     struct iobuf *iobuf) -{ -        gf_hdr_common_t     *rsp_hdr = NULL; -        gf_mop_ping_rsp_t   *rsp = NULL;     /* Using for  NULL */ -        size_t               rsp_hdrlen = 0; -        int32_t              gf_errno = 0; - -        rsp_hdrlen = gf_hdr_len (rsp, 0); -        rsp_hdr    = gf_hdr_new (rsp, 0); - -        gf_errno = gf_errno_to_error (ENOSYS); -        hdr->rsp.op_errno = hton32 (gf_errno); -        hdr->rsp.op_ret = -1; - -        protocol_server_reply (frame, GF_OP_TYPE_FOP_REPLY, GF_PROTO_FOP_LOCK_FNOTIFY, -                               rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - -        return 0; -} - - -static int -mop_stats (call_frame_t *frame, xlator_t *bound_xl, -           gf_hdr_common_t *hdr, size_t hdrlen, -           struct iobuf *iobuf) -{ -        gf_hdr_common_t     *rsp_hdr = NULL; -        gf_mop_ping_rsp_t   *rsp = NULL;     /* Using for  NULL */ -        size_t               rsp_hdrlen = 0; -        int32_t              gf_errno = 0; - -        rsp_hdrlen = gf_hdr_len (rsp, 0); -        rsp_hdr    = gf_hdr_new (rsp, 0); - -        gf_errno = gf_errno_to_error (ENOSYS); -        hdr->rsp.op_errno = hton32 (gf_errno); -        hdr->rsp.op_ret = -1; - -        protocol_server_reply (frame, GF_OP_TYPE_MOP_REPLY, GF_MOP_STATS, -                               rsp_hdr, rsp_hdrlen, NULL, 0, NULL); - -        return 0; -} - - -/* - * get_frame_for_transport - get call frame for specified transport object - * - * @trans: transport object - * - */ -static call_frame_t * -get_frame_for_transport (transport_t *trans) -{ -        call_frame_t         *frame = NULL; -        call_pool_t          *pool = NULL; -        server_connection_t  *conn = NULL; -        server_state_t       *state = NULL;; - -        GF_VALIDATE_OR_GOTO("server", trans, out); - -        if (trans->xl && trans->xl->ctx) -                pool = trans->xl->ctx->pool; -        GF_VALIDATE_OR_GOTO("server", pool, out); - -        frame = create_frame (trans->xl, pool); -        GF_VALIDATE_OR_GOTO("server", frame, out); - -        state = GF_CALLOC (1, sizeof (*state), -                           gf_server_mt_server_state_t); -        GF_VALIDATE_OR_GOTO("server", state, out); - -        conn = trans->xl_private; -        if (conn) { -                if (conn->bound_xl) -                        state->itable = conn->bound_xl->itable; -                state->bound_xl = conn->bound_xl; -        } - -        state->trans = transport_ref (trans); -        state->resolve.fd_no = -1; -        state->resolve2.fd_no = -1; - -        frame->root->trans = conn; -        frame->root->state = state;        /* which socket */ -        frame->root->unique = 0;           /* which call */ - -out: -        return frame; -} - - -static int -server_decode_groups (call_frame_t *frame, gf_hdr_common_t *hdr) -{ -        int     i = 0; - -        if ((!frame) || (!hdr)) -                return 0; - -        frame->root->ngrps = ntoh32 (hdr->req.ngrps); -        if (frame->root->ngrps == 0) -                return 0; - -        if (frame->root->ngrps > GF_REQUEST_MAXGROUPS) -                return -1; - -        for (; i < frame->root->ngrps; ++i) -                frame->root->groups[i] = ntoh32 (hdr->req.groups[i]); - -        return 0; -} - - -/* - * get_frame_for_call - create a frame into the capable of - *                      generating and replying the reply packet by itself. - *                      By making a call with this frame, the last UNWIND - *                      function will have all needed state from its - *                      frame_t->root to send reply. - * @trans: - * @blk: - * @params: - * - * not for external reference - */ -static call_frame_t * -get_frame_for_call (transport_t *trans, gf_hdr_common_t *hdr) -{ -        call_frame_t *frame = NULL; -        int32_t      ret = -1; - -        frame = get_frame_for_transport (trans); - -        frame->root->op   = ntoh32 (hdr->op); -        frame->root->type = ntoh32 (hdr->type); - -        frame->root->uid         = ntoh32 (hdr->req.uid); -        frame->root->unique      = ntoh64 (hdr->callid);      /* which call */ -        frame->root->gid         = ntoh32 (hdr->req.gid); -        frame->root->pid         = ntoh32 (hdr->req.pid); -        frame->root->lk_owner    = ntoh64 (hdr->req.lk_owner); -        ret = server_decode_groups (frame, hdr); - -        if (ret) { -                //FRAME_DESTROY (frame); -                return NULL; -        } - -        return frame; -} - -/* - * prototype of operations function for each of mop and - * fop at server protocol level - * - * @frame: call frame pointer - * @bound_xl: the xlator that this frame is bound to - * @params: parameters dictionary - * - * to be used by protocol interpret, _not_ for exterenal reference - */ -typedef int32_t (*gf_op_t) (call_frame_t *frame, xlator_t *bould_xl, -                            gf_hdr_common_t *hdr, size_t hdrlen, -                            struct iobuf *iobuf); - - -static gf_op_t gf_fops[] = { -        [GF_PROTO_FOP_STAT]         =  server_stat, -        [GF_PROTO_FOP_READLINK]     =  server_readlink, -        [GF_PROTO_FOP_MKNOD]        =  server_mknod, -        [GF_PROTO_FOP_MKDIR]        =  server_mkdir, -        [GF_PROTO_FOP_UNLINK]       =  server_unlink, -        [GF_PROTO_FOP_RMDIR]        =  server_rmdir, -        [GF_PROTO_FOP_SYMLINK]      =  server_symlink, -        [GF_PROTO_FOP_RENAME]       =  server_rename, -        [GF_PROTO_FOP_LINK]         =  server_link, -        [GF_PROTO_FOP_TRUNCATE]     =  server_truncate, -        [GF_PROTO_FOP_OPEN]         =  server_open, -        [GF_PROTO_FOP_READ]         =  server_readv, -        [GF_PROTO_FOP_WRITE]        =  server_writev, -        [GF_PROTO_FOP_STATFS]       =  server_statfs, -        [GF_PROTO_FOP_FLUSH]        =  server_flush, -        [GF_PROTO_FOP_FSYNC]        =  server_fsync, -        [GF_PROTO_FOP_SETXATTR]     =  server_setxattr, -        [GF_PROTO_FOP_GETXATTR]     =  server_getxattr, -        [GF_PROTO_FOP_FGETXATTR]    =  server_fgetxattr, -        [GF_PROTO_FOP_FSETXATTR]    =  server_fsetxattr, -        [GF_PROTO_FOP_REMOVEXATTR]  =  server_removexattr, -        [GF_PROTO_FOP_OPENDIR]      =  server_opendir, -        [GF_PROTO_FOP_FSYNCDIR]     =  server_fsyncdir, -        [GF_PROTO_FOP_ACCESS]       =  server_access, -        [GF_PROTO_FOP_CREATE]       =  server_create, -        [GF_PROTO_FOP_FTRUNCATE]    =  server_ftruncate, -        [GF_PROTO_FOP_FSTAT]        =  server_fstat, -        [GF_PROTO_FOP_LK]           =  server_lk, -        [GF_PROTO_FOP_LOOKUP]       =  server_lookup, -        [GF_PROTO_FOP_READDIR]      =  server_readdir, -        [GF_PROTO_FOP_READDIRP]     =  server_readdirp, -        [GF_PROTO_FOP_INODELK]      =  server_inodelk, -        [GF_PROTO_FOP_FINODELK]     =  server_finodelk, -        [GF_PROTO_FOP_ENTRYLK]      =  server_entrylk, -        [GF_PROTO_FOP_FENTRYLK]     =  server_fentrylk, -        [GF_PROTO_FOP_CHECKSUM]     =  server_checksum, -        [GF_PROTO_FOP_RCHECKSUM]    =  server_rchecksum, -        [GF_PROTO_FOP_XATTROP]      =  server_xattrop, -        [GF_PROTO_FOP_FXATTROP]     =  server_fxattrop, -        [GF_PROTO_FOP_SETATTR]      =  server_setattr, -        [GF_PROTO_FOP_FSETATTR]     =  server_fsetattr, -        [GF_PROTO_FOP_SETDENTS]     =  server_setdents, -        [GF_PROTO_FOP_GETDENTS]     =  server_getdents, -        [GF_PROTO_FOP_LOCK_NOTIFY]  =  server_lock_notify, -        [GF_PROTO_FOP_LOCK_FNOTIFY] =  server_lock_fnotify, -}; - - - -static gf_op_t gf_mops[] = { -        [GF_MOP_SETVOLUME] = mop_setvolume, -        [GF_MOP_GETVOLUME] = mop_getvolume, -        [GF_MOP_GETSPEC]   = mop_getspec, -        [GF_MOP_PING]      = mop_ping, -        [GF_MOP_LOG]       = mop_log, -        [GF_MOP_STATS]     = mop_stats, -}; - -static gf_op_t gf_cbks[] = { -        [GF_CBK_FORGET]     = server_forget, -        [GF_CBK_RELEASE]    = server_release, -        [GF_CBK_RELEASEDIR] = server_releasedir -}; - -static int -protocol_server_interpret (xlator_t *this, transport_t *trans, -                           char *hdr_p, size_t hdrlen, struct iobuf *iobuf) -{ -        server_connection_t         *conn = NULL; -        gf_hdr_common_t             *hdr = NULL; -        xlator_t                    *bound_xl = NULL; -        call_frame_t                *frame = NULL; -        peer_info_t                 *peerinfo = NULL; -        int32_t                      type = -1; -        int32_t                      op = -1; -        int32_t                      ret = -1; - -        hdr  = (gf_hdr_common_t *)hdr_p; -        type = ntoh32 (hdr->type); -        op   = ntoh32 (hdr->op); - -        conn = trans->xl_private; -        if (conn) -                bound_xl = conn->bound_xl; - -        peerinfo = &trans->peerinfo; -        switch (type) { -        case GF_OP_TYPE_FOP_REQUEST: -                if ((op < 0) || (op >= GF_PROTO_FOP_MAXVALUE)) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "invalid fop %"PRId32" from client %s", -                                op, peerinfo->identifier); -                        break; -                } -                if (bound_xl == NULL) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "Received fop %"PRId32" before " -                                "authentication.", op); -                        break; -                } -                frame = get_frame_for_call (trans, hdr); -                if (!frame) { -                        ret = -1; -                        goto out; -                } -		frame->op = op; -                ret = gf_fops[op] (frame, bound_xl, hdr, hdrlen, iobuf); -                break; - -        case GF_OP_TYPE_MOP_REQUEST: -                if ((op < 0) || (op >= GF_MOP_MAXVALUE)) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "invalid mop %"PRId32" from client %s", -                                op, peerinfo->identifier); -                        break; -                } -                frame = get_frame_for_call (trans, hdr); -                if (!frame) { -                        ret = -1; -                        goto out; -                } -		frame->op = op; -                ret = gf_mops[op] (frame, bound_xl, hdr, hdrlen, iobuf); -                break; - -        case GF_OP_TYPE_CBK_REQUEST: -                if ((op < 0) || (op >= GF_CBK_MAXVALUE)) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "invalid cbk %"PRId32" from client %s", -                                op, peerinfo->identifier); -                        break; -                } -                if (bound_xl == NULL) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "Received cbk %d before authentication.", op); -                        break; -                } - -                frame = get_frame_for_call (trans, hdr); -                if (!frame) { -                        ret = -1; -                        goto out; -                } -                ret = gf_cbks[op] (frame, bound_xl, hdr, hdrlen, iobuf); -                break; - -        default: -                break; -        } -out: -        return ret; -} - - -/* - * server_fd - fdtable dump function for server protocol - * @this: - * - */ -static int -server_fd (xlator_t *this) -{ -         server_conf_t        *conf = NULL; -         server_connection_t  *trav = NULL; -         char                 key[GF_DUMP_MAX_BUF_LEN]; -         int                  i = 1; -         int                  ret = -1; - -         if (!this) -                 return -1; - -         conf = this->private; -         if (!conf) { -                gf_log (this->name, GF_LOG_WARNING, -                        "conf null in xlator"); -                return -1; -         } - -         gf_proc_dump_add_section("xlator.protocol.server.conn"); - -         ret = pthread_mutex_trylock (&conf->mutex); -         if (ret) { -                gf_log("", GF_LOG_WARNING, "Unable to dump fdtable" -                " errno: %d", errno); -                return -1; -        } - -         list_for_each_entry (trav, &conf->conns, list) { -                 if (trav->id) { -                         gf_proc_dump_build_key(key, -                                          "xlator.protocol.server.conn", -                                          "%d.id", i); -                         gf_proc_dump_write(key, "%s", trav->id); -                 } - -                 gf_proc_dump_build_key(key,"xlator.protocol.server.conn", -                                        "%d.ref",i) -                 gf_proc_dump_write(key, "%d", trav->ref); -                 if (trav->bound_xl) { -                         gf_proc_dump_build_key(key, -                                          "xlator.protocol.server.conn", -                                          "%d.bound_xl", i); -                         gf_proc_dump_write(key, "%s", trav->bound_xl->name); -                 } - -                 gf_proc_dump_build_key(key, -                                        "xlator.protocol.server.conn", -                                         "%d.id", i); -                 fdtable_dump(trav->fdtable,key); -                 i++; -         } -        pthread_mutex_unlock (&conf->mutex); - - -        return 0; - } - -static int -server_priv (xlator_t *this) -{ -        return 0; -} - -static int -server_inode (xlator_t *this) -{ -         server_conf_t        *conf = NULL; -         server_connection_t  *trav = NULL; -         char                 key[GF_DUMP_MAX_BUF_LEN]; -         int                  i = 1; -         int                  ret = -1; - -         if (!this) -                 return -1; - -         conf = this->private; -         if (!conf) { -                gf_log (this->name, GF_LOG_WARNING, -                        "conf null in xlator"); -                return -1; -         } - -         ret = pthread_mutex_trylock (&conf->mutex); -         if (ret) { -                gf_log("", GF_LOG_WARNING, "Unable to dump itable" -                " errno: %d", errno); -                return -1; -        } - -        list_for_each_entry (trav, &conf->conns, list) { -                 if (trav->bound_xl && trav->bound_xl->itable) { -                         gf_proc_dump_build_key(key, -                                          "xlator.protocol.server.conn", -                                          "%d.bound_xl.%s", -                                          i, trav->bound_xl->name); -                         inode_table_dump(trav->bound_xl->itable,key); -                         i++; -                 } -        } -        pthread_mutex_unlock (&conf->mutex); - - -        return 0; -} - - -static void -get_auth_types (dict_t *this, char *key, data_t *value, void *data) -{ -        dict_t   *auth_dict = NULL; -        char     *saveptr = NULL; -        char     *tmp = NULL; -        char     *key_cpy = NULL; -        int32_t   ret = -1; - -        auth_dict = data; -        key_cpy = gf_strdup (key); -        GF_VALIDATE_OR_GOTO("server", key_cpy, out); - -        tmp = strtok_r (key_cpy, ".", &saveptr); -        ret = strcmp (tmp, "auth"); -        if (ret == 0) { -                tmp = strtok_r (NULL, ".", &saveptr); -                if (strcmp (tmp, "ip") == 0) { -                        /* TODO: backward compatibility, remove when -                           newer versions are available */ -                        tmp = "addr"; -                        gf_log ("server", GF_LOG_WARNING, -                                "assuming 'auth.ip' to be 'auth.addr'"); -                } -                ret = dict_set_dynptr (auth_dict, tmp, NULL, 0); -                if (ret < 0) { -                        gf_log ("server", GF_LOG_DEBUG, -                                "failed to dict_set_dynptr"); -                } -        } - -        GF_FREE (key_cpy); -out: -        return; -} - - -static int -validate_auth_options (xlator_t *this, dict_t *dict) -{ -        int            ret = -1; -        int            error = 0; -        xlator_list_t *trav = NULL; -        data_pair_t   *pair = NULL; -        char          *saveptr = NULL; -        char          *tmp = NULL; -        char          *key_cpy = NULL; - -        trav = this->children; -        while (trav) { -                error = -1; -                for (pair = dict->members_list; pair; pair = pair->next) { -                        key_cpy = gf_strdup (pair->key); -                        tmp = strtok_r (key_cpy, ".", &saveptr); -                        ret = strcmp (tmp, "auth"); -                        if (ret == 0) { -                                /* for module type */ -                                tmp = strtok_r (NULL, ".", &saveptr); -                                /* for volume name */ -                                tmp = strtok_r (NULL, ".", &saveptr); -                        } - -                        if (strcmp (tmp, trav->xlator->name) == 0) { -                                error = 0; -                                GF_FREE (key_cpy); -                                break; -                        } -                        GF_FREE (key_cpy); -                } -                if (-1 == error) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "volume '%s' defined as subvolume, but no " -                                "authentication defined for the same", -                                trav->xlator->name); -                        break; -                } -                trav = trav->next; -        } - -        return error; -} - -int32_t -mem_acct_init (xlator_t *this) -{ -        int     ret = -1; - -        if (!this) -                return ret; - -        ret = xlator_mem_acct_init (this, gf_server_mt_end + 1); -         -        if (ret != 0) { -                gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" -                        " failed"); -                return ret; -        } - -        return ret; -} - - -/* - * init - called during server protocol initialization - * - * @this: - * - */ -int -init (xlator_t *this) -{ -        int32_t        ret = -1; -        transport_t   *trans = NULL; -        server_conf_t *conf = NULL; -        data_t        *data = NULL; -        data_t        *trace = NULL; - -        if (this->children == NULL) { -                gf_log (this->name, GF_LOG_ERROR, -                        "protocol/server should have subvolume"); -                goto out; -        } - -        trans = transport_load (this->options, this); -        if (trans == NULL) { -                gf_log (this->name, GF_LOG_ERROR, -                        "failed to load transport"); -                goto out; -        } - -        ret = transport_listen (trans); -        if (ret == -1) { -                gf_log (this->name, GF_LOG_ERROR, -                        "failed to bind/listen on socket"); -                goto out; -        } - -        conf = GF_CALLOC (1, sizeof (server_conf_t), -                          gf_server_mt_server_conf_t); -        GF_VALIDATE_OR_GOTO(this->name, conf, out); - -        INIT_LIST_HEAD (&conf->conns); -        pthread_mutex_init (&conf->mutex, NULL); - -        conf->trans = trans; - -        conf->auth_modules = dict_new (); -        GF_VALIDATE_OR_GOTO(this->name, conf->auth_modules, out); - -        dict_foreach (this->options, get_auth_types, -                      conf->auth_modules); -        ret = validate_auth_options (this, this->options); -        if (ret == -1) { -                /* logging already done in validate_auth_options function. */ -                goto out; -        } - -        ret = gf_auth_init (this, conf->auth_modules); -        if (ret) { -                dict_unref (conf->auth_modules); -                goto out; -        } - -        this->private = conf; - -        ret = dict_get_int32 (this->options, "inode-lru-limit", -                              &conf->inode_lru_limit); -        if (ret < 0) { -                conf->inode_lru_limit = 1024; -        } - -        ret = dict_get_int32 (this->options, "limits.transaction-size", -                              &conf->max_block_size); -        if (ret < 0) { -                gf_log (this->name, GF_LOG_TRACE, -                        "defaulting limits.transaction-size to %d", -                        DEFAULT_BLOCK_SIZE); -                conf->max_block_size = DEFAULT_BLOCK_SIZE; -        } - -        conf->verify_volfile_checksum = 1; -        data = dict_get (this->options, "verify-volfile-checksum"); -        if (data) { -                ret = gf_string2boolean(data->data, -                                        &conf->verify_volfile_checksum); -                if (ret != 0) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "wrong value for verify-volfile-checksum"); -                        conf->verify_volfile_checksum = 1; -                } -        } - -        trace = dict_get (this->options, "trace"); -	if (trace) { -		if (gf_string2boolean (trace->data, -				       &conf->trace) == -1) { -			gf_log (this->name, GF_LOG_ERROR, -				"'trace' takes on only boolean values."); -			return -1; -		} -	} - -#ifndef GF_DARWIN_HOST_OS -        { -                struct rlimit lim; - -                lim.rlim_cur = 1048576; -                lim.rlim_max = 1048576; - -                if (setrlimit (RLIMIT_NOFILE, &lim) == -1) { -                        gf_log (this->name, GF_LOG_WARNING, -                                "WARNING: Failed to set 'ulimit -n 1M': %s", -                                strerror(errno)); -                        lim.rlim_cur = 65536; -                        lim.rlim_max = 65536; - -                        if (setrlimit (RLIMIT_NOFILE, &lim) == -1) { -                                gf_log (this->name, GF_LOG_WARNING, -                                        "Failed to set max open fd to 64k: %s", -                                        strerror(errno)); -                        } else { -                                gf_log (this->name, GF_LOG_TRACE, -                                        "max open fd set to 64k"); -                        } -                } -        } -#endif -        this->graph->top = this; - -        ret = 0; -out: -        return ret; -} - - - -static int -protocol_server_pollin (xlator_t *this, transport_t *trans) -{ -        char                *hdr = NULL; -        size_t               hdrlen = 0; -        int                  ret = -1; -        struct iobuf        *iobuf = NULL; - - -        ret = transport_receive (trans, &hdr, &hdrlen, &iobuf); - -        if (ret == 0) -                ret = protocol_server_interpret (this, trans, hdr, -                                                 hdrlen, iobuf); - -        /* TODO: use mem-pool */ -        GF_FREE (hdr); - -        return ret; -} - - -/* - * fini - finish function for server protocol, called before - *        unloading server protocol. - * - * @this: - * - */ -void -fini (xlator_t *this) -{ -        server_conf_t *conf = this->private; - -        GF_VALIDATE_OR_GOTO(this->name, conf, out); - -        if (conf->auth_modules) { -                dict_unref (conf->auth_modules); -        } - -        GF_FREE (conf); -        this->private = NULL; -out: -        return; -} - -/* - * server_protocol_notify - notify function for server protocol - * @this: - * @trans: - * @event: - * - */ -int -notify (xlator_t *this, int32_t event, void *data, ...) -{ -        int          ret = 0; -        transport_t *trans = NULL; -        peer_info_t *peerinfo = NULL; -        peer_info_t *myinfo = NULL; - -        THIS = this; -        trans = data; -        if (!trans) { -                gf_log (this->name, GF_LOG_ERROR, "!trans"); -                goto out; -        } - -        peerinfo = &(trans->peerinfo); -        myinfo = &(trans->myinfo); - -        switch (event) { -        case GF_EVENT_POLLIN: -                ret = protocol_server_pollin (this, trans); -                break; -        case GF_EVENT_POLLERR: -        { -                gf_log (trans->xl->name, GF_LOG_INFO, "%s disconnected", -                        peerinfo->identifier); - -                ret = -1; -                transport_disconnect (trans); -                if (trans->xl_private == NULL) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "POLLERR received on (%s) even before " -                                "handshake with (%s) is successful", -                                myinfo->identifier, peerinfo->identifier); -                } else { -                        /* -                         * FIXME: shouldn't we check for return value? -                         * what should be done if cleanup fails? -                         */ -                        gf_server_connection_cleanup (this, trans->xl_private); -                } -        } -        break; - -        case GF_EVENT_TRANSPORT_CLEANUP: -        { -                if (trans->xl_private) { -                        gf_server_connection_put (this, trans->xl_private); -                } else { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "transport (%s) cleaned up even before " -                                "handshake with (%s) is successful", -                                myinfo->identifier, peerinfo->identifier); -                } -        } -        break; - -        default: -                default_notify (this, event, data); -                break; -        } -out: -        return ret; -} - - -struct xlator_fops fops = { -}; - -struct xlator_cbks cbks = { -}; - -struct xlator_dumpops dumpops = { -        .inode = server_inode, -        .priv  = server_priv, -        .fd    = server_fd, -}; - - -struct volume_options options[] = { -        { .key   = {"transport-type"}, -          .value = {"tcp", "socket", "ib-verbs", "unix", "ib-sdp", -                    "tcp/server", "ib-verbs/server"}, -          .type  = GF_OPTION_TYPE_STR -        }, -        { .key   = {"volume-filename.*"}, -          .type  = GF_OPTION_TYPE_PATH, -        }, -        { .key   = {"inode-lru-limit"}, -          .type  = GF_OPTION_TYPE_INT, -          .min   = 0, -          .max   = (1 * GF_UNIT_MB) -        }, -        { .key   = {"client-volume-filename"}, -          .type  = GF_OPTION_TYPE_PATH -        }, -        { .key   = {"verify-volfile-checksum"}, -          .type  = GF_OPTION_TYPE_BOOL -        }, -        { .key   = {"trace"}, -          .type  = GF_OPTION_TYPE_BOOL -        }, -        { .key   = {"conf-dir"}, -          .type  = GF_OPTION_TYPE_PATH, -        }, - -        { .key   = {NULL} }, -}; diff --git a/xlators/protocol/legacy/server/src/server-protocol.h b/xlators/protocol/legacy/server/src/server-protocol.h deleted file mode 100644 index be677603360..00000000000 --- a/xlators/protocol/legacy/server/src/server-protocol.h +++ /dev/null @@ -1,191 +0,0 @@ -/* -  Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _SERVER_PROTOCOL_H_ -#define _SERVER_PROTOCOL_H_ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include <pthread.h> - -#include "glusterfs.h" -#include "xlator.h" -#include "logging.h" -#include "call-stub.h" -#include "fd.h" -#include "byte-order.h" -#include "server-mem-types.h" -#include "authenticate.h" -#include "transport.h" - -#define DEFAULT_BLOCK_SIZE         4194304   /* 4MB */ -#define DEFAULT_VOLUME_FILE_PATH   CONFDIR "/glusterfs.vol" - -typedef struct _server_state server_state_t; - -struct _locker { -	struct list_head  lockers; -        char             *volume; -	loc_t             loc; -	fd_t             *fd; -	pid_t             pid; -}; - -struct _lock_table { -	struct list_head  file_lockers; -	struct list_head  dir_lockers; -	gf_lock_t         lock; -	size_t            count; -}; - - -/* private structure per connection (transport object) - * used as transport_t->xl_private - */ -struct _server_connection { -	struct list_head    list; -	char               *id; -	int                 ref; -        int                 active_transports; -	pthread_mutex_t     lock; -	char                disconnected; -	fdtable_t          *fdtable;  -	struct _lock_table *ltable; -	xlator_t           *bound_xl; -}; - -typedef struct _server_connection server_connection_t; - - -server_connection_t * -gf_server_connection_get (xlator_t *this, const char *id); - -void -gf_server_connection_put (xlator_t *this, server_connection_t *conn); - -int -gf_server_connection_cleanup (xlator_t *this, server_connection_t *conn); - -struct _volfile_ctx { -        struct _volfile_ctx *next; -        char                *key; -        uint32_t             checksum; -}; - -typedef struct { -        struct _volfile_ctx *volfile; - -	dict_t           *auth_modules; -	transport_t      *trans; -	int32_t           max_block_size; -	int32_t           inode_lru_limit; -	pthread_mutex_t   mutex; -	struct list_head  conns; -        gf_boolean_t      verify_volfile_checksum; -        gf_boolean_t      trace; -} server_conf_t; - - -typedef enum { -        RESOLVE_MUST = 1, -        RESOLVE_NOT, -        RESOLVE_MAY, -        RESOLVE_DONTCARE, -        RESOLVE_EXACT -} server_resolve_type_t; - - -struct resolve_comp { -        char      *basename; -        ino_t      ino; -        uint64_t   gen; -        inode_t   *inode; -}; - -typedef struct { -        server_resolve_type_t  type; -        uint64_t               fd_no; -        ino_t                  ino; -        uint64_t               gen; -        ino_t                  par; -        char                  *path; -        char                  *bname; -	char                  *resolved; -        int                    op_ret; -        int                    op_errno; -        loc_t                  deep_loc; -        struct resolve_comp   *components; -        int                    comp_count; -} server_resolve_t; - - -typedef int (*server_resume_fn_t) (call_frame_t *frame, xlator_t *bound_xl); - -int -gf_resolve_and_resume (call_frame_t *frame, server_resume_fn_t fn); - -struct _server_state { -	transport_t      *trans; -	xlator_t         *bound_xl; -        inode_table_t    *itable; - -        server_resume_fn_t resume_fn; - -	loc_t             loc; -	loc_t             loc2; -        server_resolve_t  resolve; -        server_resolve_t  resolve2; - -        /* used within resolve_and_resume */ -        loc_t            *loc_now; -        server_resolve_t *resolve_now; - -        struct iatt       stbuf; -        int               valid; - -	fd_t             *fd; -        dict_t           *params; -	int               flags; -        int               wbflags; -        struct iobuf     *iobuf; -        struct iobref    *iobref; - -	size_t            size; -	off_t             offset; -	mode_t            mode; -	dev_t             dev; -	size_t            nr_count; -	int               cmd; -	int               type; -	char             *name; -	int               name_len; - -	int               mask; -	char              is_revalidate; -	dict_t           *dict; -	struct gf_flock      flock; -        const char       *volume; -        dir_entry_t      *entry; -}; - - -#endif diff --git a/xlators/protocol/legacy/server/src/server-resolve.c b/xlators/protocol/legacy/server/src/server-resolve.c deleted file mode 100644 index 5a02be7ef90..00000000000 --- a/xlators/protocol/legacy/server/src/server-resolve.c +++ /dev/null @@ -1,658 +0,0 @@ -/* -  Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "server-protocol.h" -#include "server-helpers.h" - -#include "compat-errno.h" - -void -gf_server_print_request (call_frame_t *frame); - -static int -server_resolve_all (call_frame_t *frame); -static int -resolve_entry_simple (call_frame_t *frame); -static int -resolve_inode_simple (call_frame_t *frame); -static int -resolve_path_simple (call_frame_t *frame); - - -static int -component_count (const char *path) -{ -        int         count = 0; -        const char *trav = NULL; - -        trav = path; - -        for (trav = path; *trav; trav++) { -                if (*trav == '/') -                        count++; -        } - -        return count + 2; -} - - -static int -prepare_components (call_frame_t *frame) -{ -        server_state_t       *state = NULL; -        xlator_t             *this = NULL; -        server_resolve_t     *resolve = NULL; -        char                 *resolved = NULL; -        int                   count = 0; -        struct resolve_comp  *components = NULL; -        int                   i = 0; -        char                 *trav = NULL; - - -        state = CALL_STATE (frame); -        this  = frame->this; -        resolve = state->resolve_now; - -        resolved = gf_strdup (resolve->path); -        resolve->resolved = resolved; - -        count = component_count (resolve->path); -        components = GF_CALLOC (sizeof (*components), count, -                                gf_server_mt_resolve_comp); -        resolve->components = components; - -        components[0].basename = ""; -        components[0].ino      = 1; -        components[0].gen      = 0; -        components[0].inode    = state->itable->root; - -        i = 1; -        for (trav = resolved; *trav; trav++) { -                if (*trav == '/') { -                        components[i].basename = trav + 1; -                        *trav = 0; -                        i++; -                } -        } - -        return 0; -} - - -static int -resolve_loc_touchup (call_frame_t *frame) -{ -        server_state_t       *state = NULL; -        server_resolve_t     *resolve = NULL; -        loc_t                *loc = NULL; -        char                 *path = NULL; -        int                   ret = 0; - -        state = CALL_STATE (frame); - -        resolve = state->resolve_now; -        loc     = state->loc_now; - -        if (!loc->path) { -                if (loc->parent && resolve->bname) { -                        ret = inode_path (loc->parent, resolve->bname, &path); -                } else if (loc->inode) { -                        ret = inode_path (loc->inode, NULL, &path); -                } - -                if (!path) -                        path = gf_strdup (resolve->path); - -                loc->path = path; -        } - -        loc->name = strrchr (loc->path, '/'); -        if (loc->name) -                loc->name++; - -        if (!loc->parent && loc->inode) { -                loc->parent = inode_parent (loc->inode, 0, NULL); -        } - -        return 0; -} - - -static int -resolve_deep_continue (call_frame_t *frame) -{ -        server_state_t       *state = NULL; -        xlator_t             *this = NULL; -        server_resolve_t     *resolve = NULL; -        int                   ret = 0; - -        state = CALL_STATE (frame); -        this  = frame->this; -        resolve = state->resolve_now; - -        resolve->op_ret   = 0; -        resolve->op_errno = 0; - -        if (resolve->par) -                ret = resolve_entry_simple (frame); -        else if (resolve->ino) -                ret = resolve_inode_simple (frame); -        else if (resolve->path) -                ret = resolve_path_simple (frame); - -        resolve_loc_touchup (frame); - -        server_resolve_all (frame); - -        return 0; -} - - -static int -resolve_deep_cbk (call_frame_t *frame, void *cookie, xlator_t *this, -                  int op_ret, int op_errno, inode_t *inode, struct iatt *buf, -                  dict_t *xattr, struct iatt *postparent) -{ -        server_state_t       *state = NULL; -        server_resolve_t     *resolve = NULL; -        struct resolve_comp  *components = NULL; -        int                   i = 0; -        inode_t              *link_inode = NULL; - -        state = CALL_STATE (frame); -        resolve = state->resolve_now; -        components = resolve->components; - -        i = (long) cookie; - -        if (op_ret == -1) { -                goto get_out_of_here; -        } - -        if (i != 0) { -                /* no linking for root inode */ -                link_inode = inode_link (inode, resolve->deep_loc.parent, -                                         resolve->deep_loc.name, buf); -                inode_lookup (link_inode); -                components[i].inode  = link_inode; -                link_inode = NULL; -        } - -        loc_wipe (&resolve->deep_loc); - -        i++; /* next component */ - -        if (!components[i].basename) { -                /* all components of the path are resolved */ -                goto get_out_of_here; -        } - -        /* join the current component with the path resolved until now */ -        *(components[i].basename - 1) = '/'; - -        resolve->deep_loc.path   = gf_strdup (resolve->resolved); -        resolve->deep_loc.parent = inode_ref (components[i-1].inode); -        resolve->deep_loc.inode  = inode_new (state->itable); -        resolve->deep_loc.name   = components[i].basename; - -        STACK_WIND_COOKIE (frame, resolve_deep_cbk, (void *) (long) i, -                           BOUND_XL (frame), BOUND_XL (frame)->fops->lookup, -                           &resolve->deep_loc, NULL); -        return 0; - -get_out_of_here: -        resolve_deep_continue (frame); -        return 0; -} - - -static int -resolve_path_deep (call_frame_t *frame) -{ -        server_state_t     *state = NULL; -        xlator_t           *this = NULL; -        server_resolve_t   *resolve = NULL; -        int                 i = 0; - -        state = CALL_STATE (frame); -        this  = frame->this; -        resolve = state->resolve_now; - -        gf_log (BOUND_XL (frame)->name, GF_LOG_DEBUG, -                "RESOLVE %s() seeking deep resolution of %s", -                gf_fop_list[frame->root->op], resolve->path); - -        prepare_components (frame); - -        /* start from the root */ -        resolve->deep_loc.inode = state->itable->root; -        resolve->deep_loc.path  = gf_strdup ("/"); -        resolve->deep_loc.name  = ""; - -        STACK_WIND_COOKIE (frame, resolve_deep_cbk, (void *) (long) i, -                           BOUND_XL (frame), BOUND_XL (frame)->fops->lookup, -                           &resolve->deep_loc, NULL); -        return 0; -} - - -static int -resolve_path_simple (call_frame_t *frame) -{ -        server_state_t       *state = NULL; -        xlator_t             *this = NULL; -        server_resolve_t     *resolve = NULL; -        struct resolve_comp  *components = NULL; -        int                   ret = -1; -        int                   par_idx = 0; -        int                   ino_idx = 0; -        int                   i = 0; - -        state = CALL_STATE (frame); -        this  = frame->this; -        resolve = state->resolve_now; -        components = resolve->components; - -        if (!components) { -                resolve->op_ret   = -1; -                resolve->op_errno = ENOENT; -                goto out; -        } - -        for (i = 0; components[i].basename; i++) { -                par_idx = ino_idx; -                ino_idx = i; -        } - -        if (!components[par_idx].inode) { -                resolve->op_ret    = -1; -                resolve->op_errno  = ENOENT; -                goto out; -        } - -        if (!components[ino_idx].inode && -            (resolve->type == RESOLVE_MUST || resolve->type == RESOLVE_EXACT)) { -                resolve->op_ret    = -1; -                resolve->op_errno  = ENOENT; -                goto out; -        } - -        if (components[ino_idx].inode && resolve->type == RESOLVE_NOT) { -                resolve->op_ret    = -1; -                resolve->op_errno  = EEXIST; -                goto out; -        } - -        if (components[ino_idx].inode) -                state->loc_now->inode  = inode_ref (components[ino_idx].inode); -        state->loc_now->parent = inode_ref (components[par_idx].inode); - -        ret = 0; - -out: -        return ret; -} - -/* -  Check if the requirements are fulfilled by entries in the inode cache itself -  Return value: -  <= 0 - simple resolution was decisive and complete (either success or failure) -  > 0  - indecisive, need to perform deep resolution -*/ - -static int -resolve_entry_simple (call_frame_t *frame) -{ -        server_state_t     *state = NULL; -        xlator_t           *this = NULL; -        server_resolve_t   *resolve = NULL; -        inode_t            *parent = NULL; -        inode_t            *inode = NULL; -        int                 ret = 0; - -        state = CALL_STATE (frame); -        this  = frame->this; -        resolve = state->resolve_now; - -        parent = inode_get (state->itable, resolve->par, 0); -        if (!parent) { -                /* simple resolution is indecisive. need to perform -                   deep resolution */ -                resolve->op_ret   = -1; -                resolve->op_errno = ENOENT; -                ret = 1; - -                inode = inode_grep (state->itable, parent, resolve->bname); -                if (inode != NULL) { -                        gf_log (this->name, GF_LOG_DEBUG, "%"PRId64": inode " -                                "(pointer:%p ino: %"PRIu64") present but parent" -                                " is NULL for path (%s)", frame->root->unique, -                                inode, inode->ino, resolve->path); -                        inode_unref (inode); -                } -                goto out; -        } - -//        if (parent->ino != 1 && parent->generation != resolve->gen) { -        if (0) { -                /* simple resolution is decisive - request was for a -                   stale handle */ -                resolve->op_ret   = -1; -                resolve->op_errno = ENOENT; -                ret = -1; -                goto out; -        } - -        /* expected @parent was found from the inode cache */ -        state->loc_now->parent = inode_ref (parent); - -        inode = inode_grep (state->itable, parent, resolve->bname); -        if (!inode) { -                switch (resolve->type) { -                case RESOLVE_DONTCARE: -                case RESOLVE_NOT: -                        ret = 0; -                        break; -                case RESOLVE_MAY: -                        ret = 1; -                        break; -                default: -                        resolve->op_ret   = -1; -                        resolve->op_errno = ENOENT; -                        ret = 1; -                        break; -                } - -                goto out; -        } - -        if (resolve->type == RESOLVE_NOT) { -                gf_log (this->name, GF_LOG_DEBUG, "inode (pointer: %p ino:%" -                        PRIu64") found for path (%s) while type is RESOLVE_NOT", -                        inode, inode->ino, resolve->path); -                resolve->op_ret   = -1; -                resolve->op_errno = EEXIST; -                ret = -1; -                goto out; -        } - -        ret = 0; - -        state->loc_now->inode  = inode_ref (inode); - -out: -        if (parent) -                inode_unref (parent); - -        if (inode) -                inode_unref (inode); - -        return ret; -} - - -static int -server_resolve_entry (call_frame_t *frame) -{ -        server_state_t     *state = NULL; -        xlator_t           *this = NULL; -        server_resolve_t   *resolve = NULL; -        int                 ret = 0; -        loc_t              *loc = NULL; - -        state = CALL_STATE (frame); -        this  = frame->this; -        resolve = state->resolve_now; -        loc  = state->loc_now; - -        ret = resolve_entry_simple (frame); - -        if (ret > 0) { -                loc_wipe (loc); -                resolve_path_deep (frame); -                return 0; -        } - -        if (ret == 0) -                resolve_loc_touchup (frame); - -        server_resolve_all (frame); - -        return 0; -} - - -static int -resolve_inode_simple (call_frame_t *frame) -{ -        server_state_t     *state = NULL; -        xlator_t           *this = NULL; -        server_resolve_t   *resolve = NULL; -        inode_t            *inode = NULL; -        int                 ret = 0; - -        state = CALL_STATE (frame); -        this  = frame->this; -        resolve = state->resolve_now; - -        if (resolve->type == RESOLVE_EXACT) { -                inode = inode_get (state->itable, resolve->ino, resolve->gen); -        } else { -                inode = inode_get (state->itable, resolve->ino, 0); -        } - -        if (!inode) { -                resolve->op_ret   = -1; -                resolve->op_errno = ENOENT; -                ret = 1; -                goto out; -        } - -//        if (inode->ino != 1 && inode->generation != resolve->gen) { -        if (0) { -                resolve->op_ret      = -1; -                resolve->op_errno    = ENOENT; -                ret = -1; -                goto out; -        } - -        ret = 0; - -        state->loc_now->inode = inode_ref (inode); - -out: -        if (inode) -                inode_unref (inode); - -        return ret; -} - - -static int -server_resolve_inode (call_frame_t *frame) -{ -        server_state_t     *state = NULL; -        int                 ret = 0; -        loc_t              *loc = NULL; - -        state = CALL_STATE (frame); -        loc  = state->loc_now; - -        ret = resolve_inode_simple (frame); - -        if (ret > 0) { -                loc_wipe (loc); -                resolve_path_deep (frame); -                return 0; -        } - -        if (ret == 0) -                resolve_loc_touchup (frame); - -        server_resolve_all (frame); - -        return 0; -} - - -static int -server_resolve_fd (call_frame_t *frame) -{ -        server_state_t       *state = NULL; -        xlator_t             *this = NULL; -        server_resolve_t     *resolve = NULL; -        server_connection_t  *conn = NULL; -        uint64_t              fd_no = -1; - -        state = CALL_STATE (frame); -        this  = frame->this; -        resolve = state->resolve_now; -        conn  = SERVER_CONNECTION (frame); - -        fd_no = resolve->fd_no; - -        state->fd = gf_fd_fdptr_get (conn->fdtable, fd_no); - -        if (!state->fd) { -                resolve->op_ret   = -1; -                resolve->op_errno = EBADFD; -        } - -        server_resolve_all (frame); - -        return 0; -} - - -static int -server_resolve (call_frame_t *frame) -{ -        server_state_t     *state = NULL; -        xlator_t           *this = NULL; -        server_resolve_t   *resolve = NULL; - -        state = CALL_STATE (frame); -        this  = frame->this; -        resolve = state->resolve_now; - -        if (resolve->fd_no != -1) { - -                server_resolve_fd (frame); - -        } else if (resolve->par) { - -                server_resolve_entry (frame); - -        } else if (resolve->ino) { - -                server_resolve_inode (frame); - -        } else if (resolve->path) { - -                resolve_path_deep (frame); - -        } else  { - -                resolve->op_ret = -1; -                resolve->op_errno = EINVAL; - -                server_resolve_all (frame); -        } - -        return 0; -} - - -static int -server_resolve_done (call_frame_t *frame) -{ -        server_state_t    *state = NULL; -        xlator_t          *bound_xl = NULL; - -        state = CALL_STATE (frame); -        bound_xl = BOUND_XL (frame); - -        gf_server_print_request (frame); - -        state->resume_fn (frame, bound_xl); - -        return 0; -} - - -/* - * This function is called multiple times, once per resolving one location/fd. - * state->resolve_now is used to decide which location/fd is to be resolved now - */ -static int -server_resolve_all (call_frame_t *frame) -{ -        server_state_t    *state = NULL; -        xlator_t          *this = NULL; - -        this  = frame->this; -        state = CALL_STATE (frame); - -        if (state->resolve_now == NULL) { - -                state->resolve_now = &state->resolve; -                state->loc_now     = &state->loc; - -                server_resolve (frame); - -        } else if (state->resolve_now == &state->resolve) { - -                state->resolve_now = &state->resolve2; -                state->loc_now     = &state->loc2; - -                server_resolve (frame); - -        } else if (state->resolve_now == &state->resolve2) { - -                server_resolve_done (frame); - -        } else { -                gf_log (this->name, GF_LOG_ERROR, -                        "Invalid pointer for state->resolve_now"); -        } - -        return 0; -} - - -int -gf_resolve_and_resume (call_frame_t *frame, server_resume_fn_t fn) -{ -        server_state_t    *state = NULL; -        xlator_t          *this  = NULL; - -        state = CALL_STATE (frame); -        state->resume_fn = fn; - -        this = frame->this; - -        server_resolve_all (frame); - -        return 0; -} diff --git a/xlators/protocol/legacy/transport/Makefile.am b/xlators/protocol/legacy/transport/Makefile.am deleted file mode 100644 index e2f97437c12..00000000000 --- a/xlators/protocol/legacy/transport/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = socket $(IBVERBS_SUBDIR) - -CLEANFILES =  diff --git a/xlators/protocol/legacy/transport/ib-verbs/Makefile.am b/xlators/protocol/legacy/transport/ib-verbs/Makefile.am deleted file mode 100644 index f963effea22..00000000000 --- a/xlators/protocol/legacy/transport/ib-verbs/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = src
\ No newline at end of file diff --git a/xlators/protocol/legacy/transport/ib-verbs/src/Makefile.am b/xlators/protocol/legacy/transport/ib-verbs/src/Makefile.am deleted file mode 100644 index 3db7aff9871..00000000000 --- a/xlators/protocol/legacy/transport/ib-verbs/src/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ -# TODO : need to change transportdir - -transport_LTLIBRARIES = ib-verbs.la -transportdir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/transport - -ib_verbs_la_LDFLAGS = -module -avoidversion - -ib_verbs_la_SOURCES = ib-verbs.c name.c -ib_verbs_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la     \ -	-libverbs $(top_builddir)/xlators/protocol/legacy/lib/src/libgfproto.la - -noinst_HEADERS = ib-verbs.h name.h ib-verbs-mem-types.h - -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)  \ -	-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS)   \ -	-I$(top_srcdir)/xlators/protocol/legacy/transport/ib-verbs                    \ -	-I$(top_srcdir)/xlators/protocol/legacy/lib/src - -CLEANFILES = *~ diff --git a/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs-mem-types.h b/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs-mem-types.h deleted file mode 100644 index 80e81e56b85..00000000000 --- a/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs-mem-types.h +++ /dev/null @@ -1,39 +0,0 @@ - -/* -   Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -   This file is part of GlusterFS. - -   GlusterFS is free software; you can redistribute it and/or modify -   it under the terms of the GNU General Public License as published -   by the Free Software Foundation; either version 3 of the License, -   or (at your option) any later version. - -   GlusterFS is distributed in the hope that it will be useful, but -   WITHOUT ANY WARRANTY; without even the implied warranty of -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -   General Public License for more details. - -   You should have received a copy of the GNU General Public License -   along with this program.  If not, see -   <http://www.gnu.org/licenses/>. -*/ - - -#ifndef __IB_VERBS_MEM_TYPES_H__ -#define __IB_VERBS_MEM_TYPES_H__ - -#include "mem-types.h" - -enum gf_ib_verbs_mem_types_ { -        gf_ibv_mt_ib_verbs_private_t = gf_common_mt_end + 1, -        gf_ibv_mt_ib_verbs_ioq_t, -        gf_ibv_mt_transport_t, -        gf_ibv_mt_ib_verbs_local_t, -        gf_ibv_mt_ib_verbs_post_t, -        gf_ibv_mt_char, -        gf_ibv_mt_qpent, -        gf_ibv_mt_ib_verbs_device_t, -        gf_ibv_mt_end -}; -#endif - diff --git a/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.c b/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.c deleted file mode 100644 index 8b52fa88453..00000000000 --- a/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.c +++ /dev/null @@ -1,2625 +0,0 @@ -/* -  Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "dict.h" -#include "glusterfs.h" -#include "transport.h" -#include "protocol.h" -#include "logging.h" -#include "xlator.h" -#include "name.h" -#include "ib-verbs.h" -#include <signal.h> - -int32_t -gf_resolve_ip6 (const char *hostname,  -                uint16_t port,  -                int family,  -                void **dnscache,  -                struct addrinfo **addr_info); - -static uint16_t  -ib_verbs_get_local_lid (struct ibv_context *context, -                        int32_t port) -{ -        struct ibv_port_attr attr; - -        if (ibv_query_port (context, port, &attr)) -                return 0; - -        return attr.lid; -} - -static const char * -get_port_state_str(enum ibv_port_state pstate) -{ -	switch (pstate) { -	case IBV_PORT_DOWN:          return "PORT_DOWN"; -	case IBV_PORT_INIT:          return "PORT_INIT"; -	case IBV_PORT_ARMED:         return "PORT_ARMED"; -	case IBV_PORT_ACTIVE:        return "PORT_ACTIVE"; -	case IBV_PORT_ACTIVE_DEFER:  return "PORT_ACTIVE_DEFER"; -	default:                     return "invalid state"; -	} -} - -static int32_t -ib_check_active_port (struct ibv_context *ctx, uint8_t port) -{ -        struct ibv_port_attr port_attr; - -        int32_t ret           = 0; -        const char *state_str = NULL; - -        if (!ctx) { -		gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                        "Error in supplied context"); -                return -1; -	} - -        ret = ibv_query_port (ctx, port, &port_attr); - -        if (ret) { -                gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                        "Failed to query port %u properties", port); -                return -1; -        } - -        state_str = get_port_state_str (port_attr.state); -        gf_log ("transport/ib-verbs", GF_LOG_TRACE, -                "Infiniband PORT: (%u) STATE: (%s)", -                port, state_str); - -        if (port_attr.state == IBV_PORT_ACTIVE) -                return 0; - -	return -1; -} - -static int32_t -ib_get_active_port (struct ibv_context *ib_ctx) -{ -	struct ibv_device_attr ib_device_attr; - -	int32_t ret     = -1; -	uint8_t ib_port = 0; - -	if (!ib_ctx) { -		gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                        "Error in supplied context"); -		return -1; -	} -	if (ibv_query_device (ib_ctx, &ib_device_attr)) { -		gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                        "Failed to query device properties"); -		return -1; -	} - -	for (ib_port = 1; ib_port <= ib_device_attr.phys_port_cnt; ++ib_port) { -                ret = ib_check_active_port (ib_ctx, ib_port); -                if (ret == 0) -                        return ib_port; - -                gf_log ("transport/ib-verbs", GF_LOG_TRACE, -                        "Port:(%u) not active", ib_port); -                continue; -	} -	return ret; -} - - - -static void -ib_verbs_put_post (ib_verbs_queue_t *queue, -                   ib_verbs_post_t *post) -{ -        pthread_mutex_lock (&queue->lock); -        if (post->prev) { -                queue->active_count--; -                post->prev->next = post->next; -        } -        if (post->next) -                post->next->prev = post->prev; -        post->prev = &queue->passive_posts; -        post->next = post->prev->next; -        post->prev->next = post; -        post->next->prev = post; -        queue->passive_count++; -        pthread_mutex_unlock (&queue->lock); -} - - -static ib_verbs_post_t * -ib_verbs_new_post (ib_verbs_device_t *device, int32_t len) -{ -        ib_verbs_post_t *post; - -        post = (ib_verbs_post_t *) GF_CALLOC (1, sizeof (*post), -                                   gf_ibv_mt_ib_verbs_post_t); -        if (!post) -                return NULL; - -        post->buf_size = len; - -        post->buf = valloc (len); -        if (!post->buf) { -                GF_FREE (post); -                return NULL; -        } - -        post->mr = ibv_reg_mr (device->pd, -                               post->buf, -                               post->buf_size, -                               IBV_ACCESS_LOCAL_WRITE); -        if (!post->mr) { -                free (post->buf); -                GF_FREE (post); -                return NULL; -        } - -        return post; -} - - -static ib_verbs_post_t * -ib_verbs_get_post (ib_verbs_queue_t *queue) -{ -        ib_verbs_post_t *post; - -        pthread_mutex_lock (&queue->lock); -        { -                post = queue->passive_posts.next; -                if (post == &queue->passive_posts) -                        post = NULL; -     -                if (post) { -                        if (post->prev) -                                post->prev->next = post->next; -                        if (post->next) -                                post->next->prev = post->prev; -                        post->prev = &queue->active_posts; -                        post->next = post->prev->next; -                        post->prev->next = post; -                        post->next->prev = post; -                        post->reused++; -                        queue->active_count++; -                } -        } -        pthread_mutex_unlock (&queue->lock); - -        return post; -} - -void -ib_verbs_destroy_post (ib_verbs_post_t *post) -{ -        ibv_dereg_mr (post->mr); -        free (post->buf); -        GF_FREE (post); -} - - -static int32_t -__ib_verbs_quota_get (ib_verbs_peer_t *peer) -{ -        int32_t ret = -1; -        ib_verbs_private_t *priv = peer->trans->private; - -        if (priv->connected && peer->quota > 0) { -                ret = peer->quota--; -        } - -        return ret; -} - -/* -  static int32_t -  ib_verbs_quota_get (ib_verbs_peer_t *peer) -  { -  int32_t ret = -1; -  ib_verbs_private_t *priv = peer->trans->private; - -  pthread_mutex_lock (&priv->write_mutex); -  { -  ret = __ib_verbs_quota_get (peer); -  } -  pthread_mutex_unlock (&priv->write_mutex); - -  return ret; -  } -*/ - -static void  -__ib_verbs_ioq_entry_free (ib_verbs_ioq_t *entry) -{ -        list_del_init (&entry->list); -        if (entry->iobref) -                iobref_unref (entry->iobref); - -        /* TODO: use mem-pool */ -        GF_FREE (entry->buf); - -        /* TODO: use mem-pool */ -        GF_FREE (entry); -} - - -static void -__ib_verbs_ioq_flush (ib_verbs_peer_t *peer) -{ -        ib_verbs_ioq_t *entry = NULL, *dummy = NULL; - -        list_for_each_entry_safe (entry, dummy, &peer->ioq, list) { -                __ib_verbs_ioq_entry_free (entry); -        } -} - - -static int32_t -__ib_verbs_disconnect (transport_t *this) -{ -        ib_verbs_private_t *priv = this->private; -        int32_t ret = 0; - -        if (priv->connected || priv->tcp_connected) { -                fcntl (priv->sock, F_SETFL, O_NONBLOCK); -                if (shutdown (priv->sock, SHUT_RDWR) != 0) { -                        gf_log ("transport/ib-verbs", -                                GF_LOG_DEBUG, -                                "shutdown () - error: %s", -                                strerror (errno)); -                        ret = -errno; -                        priv->tcp_connected = 0; -                } -        } -   -        return ret; -} - - -static int32_t -ib_verbs_post_send (struct ibv_qp *qp, -                    ib_verbs_post_t *post, -                    int32_t len) -{ -        struct ibv_sge list = { -                .addr = (unsigned long) post->buf, -                .length = len, -                .lkey = post->mr->lkey -        }; - -        struct ibv_send_wr wr = { -                .wr_id      = (unsigned long) post, -                .sg_list    = &list, -                .num_sge    = 1, -                .opcode     = IBV_WR_SEND, -                .send_flags = IBV_SEND_SIGNALED, -        }, *bad_wr; - -        if (!qp) -                return -1; - -        return ibv_post_send (qp, &wr, &bad_wr); -} - - -static int32_t -__ib_verbs_ioq_churn_entry (ib_verbs_peer_t *peer, ib_verbs_ioq_t *entry) -{ -        int32_t ret = 0, quota = 0; -        ib_verbs_private_t *priv = peer->trans->private; -        ib_verbs_device_t *device = priv->device; -        ib_verbs_options_t *options = &priv->options; -        ib_verbs_post_t *post = NULL; -        int32_t len = 0; - -        quota = __ib_verbs_quota_get (peer); -        if (quota > 0) { -                post = ib_verbs_get_post (&device->sendq); -                if (!post)  -                        post = ib_verbs_new_post (device,  -                                                  (options->send_size + 2048)); - -                len = iov_length ((const struct iovec *)&entry->vector,  -                                  entry->count); -                if  (len >= (options->send_size + 2048)) { -                        gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                "increase value of option 'transport.ib-verbs." -                                "work-request-send-size' (given=> %"PRId64") " -                                "to send bigger (%d) messages",  -                                (options->send_size + 2048), len); -                        return -1; -                } - -                iov_unload (post->buf,  -                            (const struct iovec *)&entry->vector,  -                            entry->count); - -                ret = ib_verbs_post_send (peer->qp, post, len); -                if (!ret) { -                        __ib_verbs_ioq_entry_free (entry); -                        ret = len; -                } else { -                        gf_log ("transport/ib-verbs", GF_LOG_DEBUG, -                                "ibv_post_send failed with ret = %d", ret); -                        ib_verbs_put_post (&device->sendq, post); -                        __ib_verbs_disconnect (peer->trans); -                        ret = -1; -                }  -        } - -        return ret; -} - - -static int32_t -__ib_verbs_ioq_churn (ib_verbs_peer_t *peer) -{ -        ib_verbs_ioq_t *entry = NULL; -        int32_t ret = 0; - -        while (!list_empty (&peer->ioq)) -        { -                /* pick next entry */ -                entry = peer->ioq_next; - -                ret = __ib_verbs_ioq_churn_entry (peer, entry); - -                if (ret <= 0) -                        break; -        } - -        /* -          list_for_each_entry_safe (entry, dummy, &peer->ioq, list) { -          ret = __ib_verbs_ioq_churn_entry (peer, entry); -          if (ret <= 0) { -          break; -          } -          } -        */ - -        return ret; -} - -static int32_t -__ib_verbs_quota_put (ib_verbs_peer_t *peer) -{ -        int32_t ret; - -        peer->quota++; -        ret = peer->quota; - -        if (!list_empty (&peer->ioq)) { -                ret = __ib_verbs_ioq_churn (peer); -        } - -        return ret; -} - - -static int32_t -ib_verbs_quota_put (ib_verbs_peer_t *peer) -{ -        int32_t ret; -        ib_verbs_private_t *priv = peer->trans->private; - -        pthread_mutex_lock (&priv->write_mutex); -        { -                ret = __ib_verbs_quota_put (peer); -        } -        pthread_mutex_unlock (&priv->write_mutex); - -        return ret; -} - - -static int32_t -ib_verbs_post_recv (struct ibv_srq *srq, -                    ib_verbs_post_t *post) -{ -        struct ibv_sge list = { -                .addr   = (unsigned long) post->buf, -                .length = post->buf_size, -                .lkey   = post->mr->lkey -        }; - -        struct ibv_recv_wr wr = { -                .wr_id  = (unsigned long) post, -                .sg_list = &list, -                .num_sge = 1, -        }, *bad_wr; - -        return ibv_post_srq_recv (srq, &wr, &bad_wr); -} - - -static int32_t -ib_verbs_writev (transport_t *this, -                 ib_verbs_ioq_t *entry) -{ -        int32_t ret = 0, need_append = 1; -        ib_verbs_private_t *priv = this->private; -        ib_verbs_peer_t  *peer = NULL; - -        pthread_mutex_lock (&priv->write_mutex); -        { -                if (!priv->connected) { -                        gf_log (this->xl->name, GF_LOG_DEBUG, -                                "ib-verbs is not connected to post a " -                                "send request"); -                        ret = -1; -                        goto unlock; -                } - -                peer = &priv->peer; -                if (list_empty (&peer->ioq)) { -                        ret = __ib_verbs_ioq_churn_entry (peer, entry); -                        if (ret != 0) { -                                need_append = 0; -                        } -                } - -                if (need_append) { -                        list_add_tail (&entry->list, &peer->ioq); -                } -        } -unlock: -        pthread_mutex_unlock (&priv->write_mutex); -        return ret; -} - - -static ib_verbs_ioq_t * -ib_verbs_ioq_new (char *buf, int len, struct iovec *vector,  -                  int count, struct iobref *iobref) -{ -        ib_verbs_ioq_t *entry = NULL; - -        /* TODO: use mem-pool */ -        entry = GF_CALLOC (1, sizeof (*entry), gf_ibv_mt_ib_verbs_ioq_t); - -        GF_ASSERT (count <= (MAX_IOVEC-2)); - -        entry->header.colonO[0] = ':'; -        entry->header.colonO[1] = 'O'; -        entry->header.colonO[2] = '\0'; -        entry->header.version   = 42; -        entry->header.size1     = hton32 (len); -        entry->header.size2     = hton32 (iov_length (vector, count)); - -        entry->vector[0].iov_base = &entry->header; -        entry->vector[0].iov_len  = sizeof (entry->header); -        entry->count++; - -        entry->vector[1].iov_base = buf; -        entry->vector[1].iov_len  = len; -        entry->count++; - -        if (vector && count) -        { -                memcpy (&entry->vector[2], vector, sizeof (*vector) * count); -                entry->count += count; -        } - -        if (iobref) -                entry->iobref = iobref_ref (iobref); - -        entry->buf = buf; - -        INIT_LIST_HEAD (&entry->list); - -        return entry; -} - - -static int32_t -ib_verbs_submit (transport_t *this, char *buf, int32_t len, -                 struct iovec *vector, int count, struct iobref *iobref) -{ -        int32_t ret = 0; -        ib_verbs_ioq_t *entry = NULL; -   -        entry = ib_verbs_ioq_new (buf, len, vector, count, iobref); -        ret = ib_verbs_writev (this, entry); - -        if (ret > 0) { -                ret = 0; -        } - -        return ret; -} - -static int -ib_verbs_receive (transport_t *this, char **hdr_p, size_t *hdrlen_p, -                  struct iobuf **iobuf_p) -{ -        ib_verbs_private_t *priv = this->private; -        /* TODO: return error if !priv->connected, check with locks */ -        /* TODO: boundry checks for data_ptr/offset */ -        char *copy_from = NULL; -        ib_verbs_header_t *header = NULL; -        uint32_t size1, size2, data_len = 0; -        char *hdr = NULL; -        struct iobuf *iobuf = NULL; -        int32_t ret = 0; - -        pthread_mutex_lock (&priv->recv_mutex); -        { -/* -  while (!priv->data_ptr) -  pthread_cond_wait (&priv->recv_cond, &priv->recv_mutex); -*/ - -                copy_from = priv->data_ptr + priv->data_offset; - -                priv->data_ptr = NULL; -                data_len = priv->data_len; -                pthread_cond_broadcast (&priv->recv_cond); -        } -        pthread_mutex_unlock (&priv->recv_mutex); - -        header = (ib_verbs_header_t *)copy_from; -        if (strcmp (header->colonO, ":O")) { -                gf_log ("transport/ib-verbs", GF_LOG_DEBUG, -                        "%s: corrupt header received", this->xl->name); -                ret = -1; -                goto err; -        } - -        size1 = ntoh32 (header->size1); -        size2 = ntoh32 (header->size2); - -        if (data_len != (size1 + size2 + sizeof (*header))) { -                gf_log ("transport/ib-verbs", GF_LOG_DEBUG, -                        "%s: sizeof data read from transport is not equal " -                        "to the size specified in the header", -                        this->xl->name); -                ret = -1; -                goto err; -        } -                   -        copy_from += sizeof (*header); - -        if (size1) { -                hdr = GF_CALLOC (1, size1, gf_ibv_mt_char); -                if (!hdr) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "unable to allocate header for peer %s", -                                this->peerinfo.identifier); -                        ret = -ENOMEM; -                        goto err; -                } -                memcpy (hdr, copy_from, size1); -                copy_from += size1; -                *hdr_p = hdr; -        } -        *hdrlen_p = size1; - -        if (size2) { -                iobuf = iobuf_get (this->xl->ctx->iobuf_pool); -                if (!iobuf) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "unable to allocate IO buffer for peer %s", -                                this->peerinfo.identifier); -                        ret = -ENOMEM; -                        goto err; -                } -                memcpy (iobuf->ptr, copy_from, size2); -                *iobuf_p = iobuf; -        } - -err: -        return ret; -} - - -static void -ib_verbs_destroy_cq (transport_t *this) -{ -        ib_verbs_private_t *priv = this->private; -        ib_verbs_device_t *device = priv->device; -   -        if (device->recv_cq) -                ibv_destroy_cq (device->recv_cq); -        device->recv_cq = NULL; -   -        if (device->send_cq) -                ibv_destroy_cq (device->send_cq); -        device->send_cq = NULL; - -        return; -} - - -static int32_t -ib_verbs_create_cq (transport_t *this) -{ -        ib_verbs_private_t *priv = this->private; -        ib_verbs_options_t *options = &priv->options; -        ib_verbs_device_t *device = priv->device; -        int32_t ret = 0; - -        device->recv_cq = ibv_create_cq (priv->device->context, -                                         options->recv_count * 2, -                                         device, -                                         device->recv_chan, -                                         0); -        if (!device->recv_cq) { -                gf_log ("transport/ib-verbs", -                        GF_LOG_ERROR, -                        "%s: creation of CQ failed", -                        this->xl->name); -                ret = -1; -        } else if (ibv_req_notify_cq (device->recv_cq, 0)) { -                gf_log ("transport/ib-verbs", -                        GF_LOG_ERROR, -                        "%s: ibv_req_notify_cq on CQ failed", -                        this->xl->name); -                ret = -1; -        } -     -        do { -                /* TODO: make send_cq size dynamically adaptive */ -                device->send_cq = ibv_create_cq (priv->device->context, -                                                 options->send_count * 1024, -                                                 device, -                                                 device->send_chan, -                                                 0); -                if (!device->send_cq) { -                        gf_log ("transport/ib-verbs", -                                GF_LOG_ERROR, -                                "%s: creation of send_cq failed", -                                this->xl->name); -                        ret = -1; -                        break; -                } - -                if (ibv_req_notify_cq (device->send_cq, 0)) { -                        gf_log ("transport/ib-verbs", -                                GF_LOG_ERROR, -                                "%s: ibv_req_notify_cq on send_cq failed", -                                this->xl->name); -                        ret = -1; -                        break; -                } -        } while (0); - -        if (ret != 0) -                ib_verbs_destroy_cq (this); - -        return ret; -} - - -static void -ib_verbs_register_peer (ib_verbs_device_t *device, -                        int32_t qp_num, -                        ib_verbs_peer_t *peer) -{ -        struct _qpent *ent; -        ib_verbs_qpreg_t *qpreg = &device->qpreg; -        int32_t hash = qp_num % 42; - -        pthread_mutex_lock (&qpreg->lock); -        ent = qpreg->ents[hash].next; -        while ((ent != &qpreg->ents[hash]) && (ent->qp_num != qp_num)) -                ent = ent->next; -        if (ent->qp_num == qp_num) { -                pthread_mutex_unlock (&qpreg->lock); -                return; -        } -        ent = (struct _qpent *) GF_CALLOC (1, sizeof (*ent), gf_ibv_mt_qpent); -        if (!ent) -                return; -        /* TODO: ref reg->peer */ -        ent->peer = peer; -        ent->next = &qpreg->ents[hash]; -        ent->prev = ent->next->prev; -        ent->next->prev = ent; -        ent->prev->next = ent; -        ent->qp_num = qp_num; -        qpreg->count++; -        pthread_mutex_unlock (&qpreg->lock); -} - - -static void -ib_verbs_unregister_peer (ib_verbs_device_t *device, -                          int32_t qp_num) -{ -        struct _qpent *ent; -        ib_verbs_qpreg_t *qpreg = &device->qpreg; -        int32_t hash = qp_num % 42; - -        pthread_mutex_lock (&qpreg->lock); -        ent = qpreg->ents[hash].next; -        while ((ent != &qpreg->ents[hash]) && (ent->qp_num != qp_num)) -                ent = ent->next; -        if (ent->qp_num != qp_num) { -                pthread_mutex_unlock (&qpreg->lock); -                return; -        } -        ent->prev->next = ent->next; -        ent->next->prev = ent->prev; -        /* TODO: unref reg->peer */ -        GF_FREE (ent); -        qpreg->count--; -        pthread_mutex_unlock (&qpreg->lock); -} - - -static ib_verbs_peer_t * -__ib_verbs_lookup_peer (ib_verbs_device_t *device, int32_t qp_num) -{ -        struct _qpent    *ent   = NULL; -        ib_verbs_peer_t  *peer  = NULL; -        ib_verbs_qpreg_t *qpreg = NULL; -        int32_t hash            = 0; - -        qpreg = &device->qpreg; -        hash = qp_num % 42; -        ent = qpreg->ents[hash].next; -        while ((ent != &qpreg->ents[hash]) && (ent->qp_num != qp_num)) -                ent = ent->next; - -        if (ent != &qpreg->ents[hash]) { -                peer = ent->peer; -        } - -        return peer; -} - -/* -static ib_verbs_peer_t * -ib_verbs_lookup_peer (ib_verbs_device_t *device, -                      int32_t qp_num) -{ -        ib_verbs_qpreg_t *qpreg = NULL; -        ib_verbs_peer_t  *peer  = NULL; -  -        qpreg = &device->qpreg; -        pthread_mutex_lock (&qpreg->lock); -        { -                peer = __ib_verbs_lookup_peer (device, qp_num); -        } -        pthread_mutex_unlock (&qpreg->lock); - -        return peer; -} -*/ - - -static void -__ib_verbs_destroy_qp (transport_t *this) -{ -        ib_verbs_private_t *priv = this->private; - -        if (priv->peer.qp) { -                ib_verbs_unregister_peer (priv->device, priv->peer.qp->qp_num); -                ibv_destroy_qp (priv->peer.qp); -        } -        priv->peer.qp = NULL; - -        return; -} - - -static int32_t -ib_verbs_create_qp (transport_t *this) -{ -        ib_verbs_private_t *priv = this->private; -        ib_verbs_options_t *options = &priv->options; -        ib_verbs_device_t *device = priv->device; -        int32_t ret = 0; -        ib_verbs_peer_t *peer; - -        peer = &priv->peer; -        struct ibv_qp_init_attr init_attr = { -                .send_cq        = device->send_cq, -                .recv_cq        = device->recv_cq, -                .srq            = device->srq, -                .cap            = { -                        .max_send_wr  = peer->send_count, -                        .max_recv_wr  = peer->recv_count, -                        .max_send_sge = 1, -                        .max_recv_sge = 1 -                }, -                .qp_type = IBV_QPT_RC -        }; -   -        struct ibv_qp_attr attr = { -                .qp_state        = IBV_QPS_INIT, -                .pkey_index      = 0, -                .port_num        = options->port, -                .qp_access_flags = 0 -        }; -   -        peer->qp = ibv_create_qp (device->pd, &init_attr); -        if (!peer->qp) { -                gf_log ("transport/ib-verbs", -                        GF_LOG_CRITICAL, -                        "%s: could not create QP", -                        this->xl->name); -                ret = -1; -                goto out; -        } else if (ibv_modify_qp (peer->qp, &attr, -                                  IBV_QP_STATE              | -                                  IBV_QP_PKEY_INDEX         | -                                  IBV_QP_PORT               | -                                  IBV_QP_ACCESS_FLAGS)) { -                gf_log ("transport/ib-verbs", -                        GF_LOG_ERROR, -                        "%s: failed to modify QP to INIT state", -                        this->xl->name); -                ret = -1; -                goto out; -        } - -        peer->local_lid = ib_verbs_get_local_lid (device->context, -                                                  options->port); -        peer->local_qpn = peer->qp->qp_num; -        peer->local_psn = lrand48 () & 0xffffff; - -        ib_verbs_register_peer (device, peer->qp->qp_num, peer); - -out: -        if (ret == -1) -                __ib_verbs_destroy_qp (this); - -        return ret; -} - - -static void -ib_verbs_destroy_posts (transport_t *this) -{ - -} - - -static int32_t -__ib_verbs_create_posts (transport_t *this, -                         int32_t count, -                         int32_t size, -                         ib_verbs_queue_t *q) -{ -        int32_t i; -        int32_t ret = 0; -        ib_verbs_private_t *priv = this->private; -        ib_verbs_device_t *device = priv->device; - -        for (i=0 ; i<count ; i++) { -                ib_verbs_post_t *post; - -                post = ib_verbs_new_post (device, size + 2048); -                if (!post) { -                        gf_log ("transport/ib-verbs", -                                GF_LOG_ERROR, -                                "%s: post creation failed", -                                this->xl->name); -                        ret = -1; -                        break; -                } - -                ib_verbs_put_post (q, post); -        } -        return ret; -} - - -static int32_t -ib_verbs_create_posts (transport_t *this) -{ -        int32_t i, ret; -        ib_verbs_post_t *post = NULL; -        ib_verbs_private_t *priv = this->private; -        ib_verbs_options_t *options = &priv->options; -        ib_verbs_device_t *device = priv->device; - -        ret =  __ib_verbs_create_posts (this, options->send_count, -                                        options->send_size, -                                        &device->sendq); -        if (!ret) -                ret =  __ib_verbs_create_posts (this, options->recv_count, -                                                options->recv_size, -                                                &device->recvq); - -        if (!ret) { -                for (i=0 ; i<options->recv_count ; i++) { -                        post = ib_verbs_get_post (&device->recvq); -                        if (ib_verbs_post_recv (device->srq, post) != 0) { -                                ret = -1; -                                break; -                        } -                } -        } - -        if (ret) -                ib_verbs_destroy_posts (this); - -        return ret; -} - - -static int32_t -ib_verbs_connect_qp (transport_t *this) -{ -        ib_verbs_private_t *priv = this->private; -        ib_verbs_options_t *options = &priv->options; -        struct ibv_qp_attr attr = { -                .qp_state               = IBV_QPS_RTR, -                .path_mtu               = options->mtu, -                .dest_qp_num            = priv->peer.remote_qpn, -                .rq_psn                 = priv->peer.remote_psn, -                .max_dest_rd_atomic     = 1, -                .min_rnr_timer          = 12, -                .ah_attr                = { -                        .is_global      = 0, -                        .dlid           = priv->peer.remote_lid, -                        .sl             = 0, -                        .src_path_bits  = 0, -                        .port_num       = options->port -                } -        }; -        if (ibv_modify_qp (priv->peer.qp, &attr, -                           IBV_QP_STATE              | -                           IBV_QP_AV                 | -                           IBV_QP_PATH_MTU           | -                           IBV_QP_DEST_QPN           | -                           IBV_QP_RQ_PSN             | -                           IBV_QP_MAX_DEST_RD_ATOMIC | -                           IBV_QP_MIN_RNR_TIMER)) { -                gf_log ("transport/ib-verbs", -                        GF_LOG_CRITICAL, -                        "Failed to modify QP to RTR\n"); -                return -1; -        } - -        /* TODO: make timeout and retry_cnt configurable from options */ -        attr.qp_state       = IBV_QPS_RTS; -        attr.timeout        = 14; -        attr.retry_cnt      = 7; -        attr.rnr_retry      = 7; -        attr.sq_psn         = priv->peer.local_psn; -        attr.max_rd_atomic  = 1; -        if (ibv_modify_qp (priv->peer.qp, &attr, -                           IBV_QP_STATE              | -                           IBV_QP_TIMEOUT            | -                           IBV_QP_RETRY_CNT          | -                           IBV_QP_RNR_RETRY          | -                           IBV_QP_SQ_PSN             | -                           IBV_QP_MAX_QP_RD_ATOMIC)) { -                gf_log ("transport/ib-verbs", -                        GF_LOG_CRITICAL, -                        "Failed to modify QP to RTS\n"); -                return -1; -        } - -        return 0; -} - -static int32_t -__ib_verbs_teardown (transport_t *this) -{ -        ib_verbs_private_t *priv = this->private; - -        __ib_verbs_destroy_qp (this); - -        if (!list_empty (&priv->peer.ioq)) { -                __ib_verbs_ioq_flush (&priv->peer); -        } - -        /* TODO: decrement cq size */ -        return 0; -} - -/* - * return value: - *   0 = success (completed) - *  -1 = error - * > 0 = incomplete - */ - -static int -__tcp_rwv (transport_t *this, struct iovec *vector, int count, -           struct iovec **pending_vector, int *pending_count, -           int write) -{ -        ib_verbs_private_t *priv = NULL; -        int sock = -1; -        int ret = -1; -        struct iovec *opvector = vector; -        int opcount = count; -        int moved = 0; - -        priv = this->private; -        sock = priv->sock; - -        while (opcount) -        { -                if (write) -                { -                        ret = writev (sock, opvector, opcount); - -                        if (ret == 0 || (ret == -1 && errno == EAGAIN)) -                        { -                                /* done for now */ -                                break; -                        } -                } -                else -                { -                        ret = readv (sock, opvector, opcount); - -                        if (ret == -1 && errno == EAGAIN) -                        { -                                /* done for now */ -                                break; -                        } -                } - -                if (ret == 0) -                { -                        gf_log (this->xl->name, GF_LOG_DEBUG,  -                                "EOF from peer %s", this->peerinfo.identifier); -                        opcount = -1; -                        errno = ENOTCONN; -                        break; -                } - -                if (ret == -1) -                { -                        if (errno == EINTR) -                                continue; - -                        gf_log (this->xl->name, GF_LOG_DEBUG, -                                "%s failed (%s)", write ? "writev" : "readv", -                                strerror (errno)); -                        if (write && !priv->connected &&  -                            (errno == ECONNREFUSED)) -                                gf_log (this->xl->name, GF_LOG_ERROR, -                                        "possible mismatch of 'transport-type'" -                                        " in protocol server and client. " -                                        "check volume file"); -                        opcount = -1; -                        break; -                } - -                moved = 0; - -                while (moved < ret) -                { -                        if ((ret - moved) >= opvector[0].iov_len) -                        { -                                moved += opvector[0].iov_len; -                                opvector++; -                                opcount--; -                        } -                        else -                        { -                                opvector[0].iov_len -= (ret - moved); -                                opvector[0].iov_base += (ret - moved); -                                moved += (ret - moved); -                        } -                        while (opcount && !opvector[0].iov_len) -                        { -                                opvector++; -                                opcount--; -                        } -                } -        } - -        if (pending_vector) -                *pending_vector = opvector; - -        if (pending_count) -                *pending_count = opcount; - -        return opcount; -} - - -static int -__tcp_readv (transport_t *this, struct iovec *vector, int count, -             struct iovec **pending_vector, int *pending_count) -{ -        int ret = -1; - -        ret = __tcp_rwv (this, vector, count,  -                         pending_vector, pending_count, 0); - -        return ret; -} - - -static int -__tcp_writev (transport_t *this, struct iovec *vector, int count, -              struct iovec **pending_vector, int *pending_count) -{ -        int ret = -1; -        ib_verbs_private_t *priv = this->private; - -        ret = __tcp_rwv (this, vector, count, pending_vector,  -                         pending_count, 1); - -        if (ret > 0) { -                /* TODO: Avoid multiple calls when socket is already  -                   registered for POLLOUT */ -                priv->idx = event_select_on (this->xl->ctx->event_pool,  -                                             priv->sock, priv->idx, -1, 1); -        } else if (ret == 0) { -                priv->idx = event_select_on (this->xl->ctx->event_pool,  -                                             priv->sock, -                                             priv->idx, -1, 0); -        } - -        return ret; -} - - -static void * -ib_verbs_recv_completion_proc (void *data) -{ -        struct ibv_comp_channel *chan = data; -        ib_verbs_private_t      *priv = NULL; -        ib_verbs_device_t       *device; -        ib_verbs_post_t         *post; -        ib_verbs_peer_t         *peer; -        struct ibv_cq           *event_cq; -        struct ibv_wc            wc; -        void                    *event_ctx; -        int32_t                  ret  = 0; - - -        while (1) { -                ret = ibv_get_cq_event (chan, &event_cq, &event_ctx); -                if (ret) { -                        gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                "ibv_get_cq_event failed, terminating recv " -                                "thread %d (%d)", ret, errno); -                        continue; -                } - -                device = event_ctx; -     -                ret = ibv_req_notify_cq (event_cq, 0); -                if (ret) { -                        gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                "ibv_req_notify_cq on %s failed, terminating " -                                "recv thread: %d (%d)", -                                device->device_name, ret, errno); -                        continue; -                } - -                device = (ib_verbs_device_t *) event_ctx; - -                while ((ret = ibv_poll_cq (event_cq, 1, &wc)) > 0) { -                        post = (ib_verbs_post_t *) (long) wc.wr_id; - -                        pthread_mutex_lock (&device->qpreg.lock); -                        { -                                peer = __ib_verbs_lookup_peer (device, -                                                               wc.qp_num); - -                                /* -                                 * keep a refcount on transport so that it -                                 * doesnot get freed because of some error -                                 * indicated by wc.status till we are done -                                 * with usage of peer and thereby that of trans. -                                 */ -                                if (peer != NULL) { -                                        transport_ref (peer->trans); -                                } -                        } -                        pthread_mutex_unlock (&device->qpreg.lock); - -                        if (wc.status != IBV_WC_SUCCESS) { -                                gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                        "recv work request on `%s' returned " -                                        "error (%d)", -                                        device->device_name, -                                        wc.status); -                                if (peer) { -                                        transport_unref (peer->trans); -                                        transport_disconnect (peer->trans); -                                } - -                                if (post) { -                                        ib_verbs_post_recv (device->srq, post); -                                } -                                continue; -                        } - -                        if (peer) { -                                priv = peer->trans->private; -         -                                pthread_mutex_lock (&priv->recv_mutex); -                                { -                                        while (priv->data_ptr) -                                                pthread_cond_wait (&priv->recv_cond, -                                                                   &priv->recv_mutex); -           -                                        priv->data_ptr = post->buf; -                                        priv->data_offset = 0; -                                        priv->data_len = wc.byte_len; -           -                                        /*pthread_cond_broadcast (&priv->recv_cond);*/ -                                } -                                pthread_mutex_unlock (&priv->recv_mutex); -         -                                if ((ret = xlator_notify (peer->trans->xl, GF_EVENT_POLLIN,  -                                                          peer->trans, NULL)) == -1) { -                                        gf_log ("transport/ib-verbs", -                                                GF_LOG_DEBUG,  -                                                "pollin notification to %s " -                                                "failed, disconnecting " -                                                "transport",  -                                                peer->trans->xl->name); -                                        transport_disconnect (peer->trans); -                                } - -                                transport_unref (peer->trans); -                        } else { -                                gf_log ("transport/ib-verbs", -                                        GF_LOG_DEBUG, -                                        "could not lookup peer for qp_num: %d", -                                        wc.qp_num); -                        } -                        ib_verbs_post_recv (device->srq, post); -                } -     -                if (ret < 0) { -                        gf_log ("transport/ib-verbs", -                                GF_LOG_ERROR, -                                "ibv_poll_cq on `%s' returned error " -                                "(ret = %d, errno = %d)", -                                device->device_name, ret, errno); -                        continue; -                } -                ibv_ack_cq_events (event_cq, 1); -        } -        return NULL; -} - - -static void * -ib_verbs_send_completion_proc (void *data) -{ -        struct ibv_comp_channel *chan = data; -        ib_verbs_post_t *post; -        ib_verbs_peer_t *peer; -        struct ibv_cq *event_cq; -        void *event_ctx; -        ib_verbs_device_t *device; -        struct ibv_wc wc; -        int32_t ret; -         -        while (1) { -                ret = ibv_get_cq_event (chan, &event_cq, &event_ctx); -                if (ret) { -                        gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                "ibv_get_cq_event on failed, terminating " -                                "send thread: %d (%d)", ret, errno); -                        continue; -                } -        -                device = event_ctx; - -                ret = ibv_req_notify_cq (event_cq, 0); -                if (ret) { -                        gf_log ("transport/ib-verbs",  GF_LOG_ERROR, -                                "ibv_req_notify_cq on %s failed, terminating " -                                "send thread: %d (%d)", -                                device->device_name, ret, errno); -                        continue; -                } - -                while ((ret = ibv_poll_cq (event_cq, 1, &wc)) > 0) { -                        post = (ib_verbs_post_t *) (long) wc.wr_id; - -                        pthread_mutex_lock (&device->qpreg.lock); -                        { -                                peer = __ib_verbs_lookup_peer (device, -                                                               wc.qp_num); - -                                /* -                                 * keep a refcount on transport so that it -                                 * doesnot get freed because of some error -                                 * indicated by wc.status till we are done -                                 * with usage of peer and thereby that of trans. -                                 */ -                                if (peer != NULL) { -                                        transport_ref (peer->trans); -                                } -                        } -                        pthread_mutex_unlock (&device->qpreg.lock); - -                        if (wc.status != IBV_WC_SUCCESS) { -                                gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                        "send work request on `%s' returned " -                                        "error wc.status = %d, wc.vendor_err " -                                        "= %d, post->buf = %p, wc.byte_len = " -                                        "%d, post->reused = %d", -                                        device->device_name, wc.status,  -                                        wc.vendor_err, -                                        post->buf, wc.byte_len, post->reused); -                                if (wc.status == IBV_WC_RETRY_EXC_ERR) -                                        gf_log ("ib-verbs", GF_LOG_ERROR, -                                                "connection between client and" -                                                " server not working. check by" -                                                " running 'ibv_srq_pingpong'. " -                                                "also make sure subnet manager" -                                                " is running (eg: 'opensm'), " -                                                "or check if ib-verbs port is " -                                                "valid (or active) by running " -                                                " 'ibv_devinfo'. contact " -                                                "Gluster Support Team if " -                                                "the problem persists."); -                                if (peer) -                                        transport_disconnect (peer->trans); -                        } - -                        if (post) { -                                ib_verbs_put_post (&device->sendq, post); -                        } -       -                        if (peer) { -                                int quota_ret = ib_verbs_quota_put (peer); -                                if (quota_ret < 0) { -                                        gf_log ("ib-verbs", GF_LOG_DEBUG, -                                                "failed to send message"); -                                         -                                } - -                                transport_unref (peer->trans); -                        } else { -                                gf_log ("transport/ib-verbs", GF_LOG_DEBUG, -                                        "could not lookup peer for qp_num: %d", -                                        wc.qp_num); -                        } -                } - -                if (ret < 0) { -                        gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                "ibv_poll_cq on `%s' returned error (ret = %d," -                                " errno = %d)", -                                device->device_name, ret, errno); -                        continue; -                } -                ibv_ack_cq_events (event_cq, 1);  -        } - -        return NULL; -} - -static void -ib_verbs_options_init (transport_t *this) -{ -        ib_verbs_private_t *priv = this->private; -        ib_verbs_options_t *options = &priv->options; -        int32_t mtu; -        data_t *temp; - -        /* TODO: validate arguments from options below */ - -        options->send_size = this->xl->ctx->page_size * 4; /* 512 KB */ -        options->recv_size = this->xl->ctx->page_size * 4; /* 512 KB */ -        options->send_count = 32; -        options->recv_count = 32; - -        temp = dict_get (this->xl->options, -                         "transport.ib-verbs.work-request-send-count"); -        if (temp) -                options->send_count = data_to_int32 (temp); - -        temp = dict_get (this->xl->options, -                         "transport.ib-verbs.work-request-recv-count"); -        if (temp) -                options->recv_count = data_to_int32 (temp); - -        options->port = 0; -        temp = dict_get (this->xl->options, -                         "transport.ib-verbs.port"); -        if (temp) -                options->port = data_to_uint64 (temp); - -        options->mtu = mtu = IBV_MTU_2048; -        temp = dict_get (this->xl->options, -                         "transport.ib-verbs.mtu"); -        if (temp) -                mtu = data_to_int32 (temp); -        switch (mtu) { -        case 256: options->mtu = IBV_MTU_256; -                break; -        case 512: options->mtu = IBV_MTU_512; -                break; -        case 1024: options->mtu = IBV_MTU_1024; -                break; -        case 2048: options->mtu = IBV_MTU_2048; -                break; -        case 4096: options->mtu = IBV_MTU_4096; -                break; -        default: -                if (temp) -                        gf_log ("transport/ib-verbs", GF_LOG_WARNING, -                                "%s: unrecognized MTU value '%s', defaulting " -                                "to '2048'", this->xl->name, -                                data_to_str (temp)); -                else -                        gf_log ("transport/ib-verbs", GF_LOG_TRACE, -                                "%s: defaulting MTU to '2048'", -                                this->xl->name); -                options->mtu = IBV_MTU_2048; -                break; -        } - -        temp = dict_get (this->xl->options, -                         "transport.ib-verbs.device-name"); -        if (temp) -                options->device_name = gf_strdup (temp->data); - -        return; -} - -static void -ib_verbs_queue_init (ib_verbs_queue_t *queue) -{ -        pthread_mutex_init (&queue->lock, NULL); - -        queue->active_posts.next = &queue->active_posts; -        queue->active_posts.prev = &queue->active_posts; -        queue->passive_posts.next = &queue->passive_posts; -        queue->passive_posts.prev = &queue->passive_posts; -} - - -static ib_verbs_device_t * -ib_verbs_get_device (transport_t *this, -		     struct ibv_context *ibctx) -{ -        glusterfs_ctx_t *ctx        = this->xl->ctx; -        ib_verbs_private_t *priv    = this->private; -        ib_verbs_options_t *options = &priv->options; -        char *device_name           = priv->options.device_name; -        uint32_t port               = priv->options.port; - -        uint8_t active_port = 0; -        int32_t ret         = 0; -        int32_t i           = 0; - -        ib_verbs_device_t *trav; - -        trav = ctx->ib; -        while (trav) { -                if ((!strcmp (trav->device_name, device_name)) &&  -                    (trav->port == port)) -                        break; -                trav = trav->next; -        } - -        if (!trav) { - -                trav = GF_CALLOC (1, sizeof (*trav),  -                                  gf_ibv_mt_ib_verbs_device_t); -                if (!trav) -                        return NULL; -                priv->device = trav; - -                trav->context = ibctx; - -		ret = ib_get_active_port (trav->context); - -		if (ret < 0) { -			if (!port) { -				gf_log ("transport/ib-verbs", GF_LOG_ERROR, -					"Failed to find any active ports and " -					"none specified in volume file," -                                        " exiting"); -				return NULL; -			} -		} - -		active_port = ret; - -                if (port) { -                        ret = ib_check_active_port (trav->context, port); -                        if (ret < 0) { -                                gf_log ("transport/ib-verbs", GF_LOG_WARNING, -                                        "On device %s: provided port:%u is " -                                        "found to be offline, continuing to " -                                        "use the same port", device_name, port); -                        } -		} else { -			priv->options.port = active_port; -			port = active_port; -			gf_log ("transport/ib-verbs", GF_LOG_TRACE, -				"Port unspecified in volume file using active " -                                "port: %u", port); -                } - -                trav->device_name = gf_strdup (device_name); -                trav->port = port; - -                trav->next = ctx->ib; -                ctx->ib = trav; - -                trav->send_chan = ibv_create_comp_channel (trav->context); -                if (!trav->send_chan) { -                        gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                "%s: could not create send completion channel", -                                device_name); -                        /* TODO: cleanup current mess */ -                        return NULL; -                } -     -                trav->recv_chan = ibv_create_comp_channel (trav->context); -                if (!trav->recv_chan) { -                        gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                "could not create recv completion channel"); -                        /* TODO: cleanup current mess */ -                        return NULL; -                } -       -                if (ib_verbs_create_cq (this) < 0) { -                        gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                "%s: could not create CQ", -                                this->xl->name); -                        return NULL; -                } - -                /* protection domain */ -                trav->pd = ibv_alloc_pd (trav->context); - -                if (!trav->pd) { -                        gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                "%s: could not allocate protection domain", -                                this->xl->name); -                        return NULL; -                } - -                struct ibv_srq_init_attr attr = { -                        .attr = { -                                .max_wr = options->recv_count, -                                .max_sge = 1 -                        } -                }; -                trav->srq = ibv_create_srq (trav->pd, &attr); - -                if (!trav->srq) { -                        gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                "%s: could not create SRQ", -                                this->xl->name); -                        return NULL; -                } - -                /* queue init */ -                ib_verbs_queue_init (&trav->sendq); -                ib_verbs_queue_init (&trav->recvq); - -                if (ib_verbs_create_posts (this) < 0) { -                        gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                "%s: could not allocate posts", -                                this->xl->name); -                        return NULL; -                } - -                /* completion threads */ -                ret = pthread_create (&trav->send_thread, -                                      NULL, -                                      ib_verbs_send_completion_proc, -                                      trav->send_chan); -                if (ret) { -                        gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                "could not create send completion thread"); -                        return NULL; -                } -                ret = pthread_create (&trav->recv_thread, -                                      NULL, -                                      ib_verbs_recv_completion_proc, -                                      trav->recv_chan); -                if (ret) { -                        gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                "could not create recv completion thread"); -                        return NULL; -                } -   -                /* qpreg */ -                pthread_mutex_init (&trav->qpreg.lock, NULL); -                for (i=0; i<42; i++) { -                        trav->qpreg.ents[i].next = &trav->qpreg.ents[i]; -                        trav->qpreg.ents[i].prev = &trav->qpreg.ents[i]; -                } -        } -        return trav; -} - -static int32_t  -ib_verbs_init (transport_t *this) -{ -        ib_verbs_private_t *priv = this->private; -        ib_verbs_options_t *options = &priv->options; -        struct ibv_device **dev_list; -	struct ibv_context *ib_ctx = NULL; -	int32_t ret = 0; - -        ib_verbs_options_init (this); - -        { -                dev_list = ibv_get_device_list (NULL); - -		if (!dev_list) { -                        gf_log ("transport/ib-verbs", -                                GF_LOG_CRITICAL, -                                "Failed to get IB devices"); -			ret = -1; -			goto cleanup; -                } - -                if (!*dev_list) { -                        gf_log ("transport/ib-verbs", -                                GF_LOG_CRITICAL, -                                "No IB devices found"); -			ret = -1; -                        goto cleanup; -                } - -                if (!options->device_name) { -                        if (*dev_list) { -                                options->device_name =  -                                        gf_strdup (ibv_get_device_name (*dev_list)); -                        } else { -                                gf_log ("transport/ib-verbs", GF_LOG_CRITICAL, -                                        "IB device list is empty. Check for " -                                        "'ib_uverbs' module"); -                                return -1; -                                goto cleanup; -                        } -                } - -		while (*dev_list) { -                        if (!strcmp (ibv_get_device_name (*dev_list), -                                     options->device_name)) { -                                ib_ctx = ibv_open_device (*dev_list); - -                                if (!ib_ctx) { -                                        gf_log ("transport/ib-verbs", -                                                GF_LOG_ERROR, -                                                "Failed to get infiniband" -                                                "device context"); -                                        ret = -1; -                                        goto cleanup; -                                } -                                break; -                        } -			++dev_list; -		} - -		priv->device = ib_verbs_get_device (this, ib_ctx); - -                if (!priv->device) { -                        gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                "could not create ib_verbs device for %s", -                                options->device_name); -                        ret = -1; -			goto cleanup; -                } -        } - -        priv->peer.trans = this; -        INIT_LIST_HEAD (&priv->peer.ioq); -   -        pthread_mutex_init (&priv->read_mutex, NULL); -        pthread_mutex_init (&priv->write_mutex, NULL); -        pthread_mutex_init (&priv->recv_mutex, NULL); -        pthread_cond_init (&priv->recv_cond, NULL); - -cleanup: -	if (-1 == ret) { -		if (ib_ctx) -			ibv_close_device (ib_ctx); -	} - -	if (dev_list) -		ibv_free_device_list (dev_list); - -	return ret; -} - - -static int32_t -ib_verbs_disconnect (transport_t *this) -{ -        ib_verbs_private_t *priv = this->private; -        int32_t ret = 0; -  -        pthread_mutex_lock (&priv->write_mutex); -        { -                ret = __ib_verbs_disconnect (this); -        } -        pthread_mutex_unlock (&priv->write_mutex); - -        return ret; -} - - -static int32_t -__tcp_connect_finish (int fd) -{ -        int ret = -1; -        int optval = 0; -        socklen_t optlen = sizeof (int); - -        ret = getsockopt (fd, SOL_SOCKET, SO_ERROR, -                          (void *)&optval, &optlen); - -        if (ret == 0 && optval) -        { -                errno = optval; -                ret = -1; -        } - -        return ret; -} - -static inline void -ib_verbs_fill_handshake_data (char *buf, struct ib_verbs_nbio *nbio,  -                              ib_verbs_private_t *priv) -{ -        sprintf (buf, -                 "QP1:RECV_BLKSIZE=%08x:SEND_BLKSIZE=%08x\n" -                 "QP1:LID=%04x:QPN=%06x:PSN=%06x\n", -                 priv->peer.recv_size, -                 priv->peer.send_size, -                 priv->peer.local_lid, -                 priv->peer.local_qpn, -                 priv->peer.local_psn); - -        nbio->vector.iov_base = buf; -        nbio->vector.iov_len = strlen (buf) + 1; -        nbio->count = 1; -        return; -} - -static inline void -ib_verbs_fill_handshake_ack (char *buf, struct ib_verbs_nbio *nbio) -{ -        sprintf (buf, "DONE\n"); -        nbio->vector.iov_base = buf; -        nbio->vector.iov_len = strlen (buf) + 1; -        nbio->count = 1; -        return; -} - -static int -ib_verbs_handshake_pollin (transport_t *this) -{ -        int ret = 0; -        ib_verbs_private_t *priv = this->private; -        char *buf = priv->handshake.incoming.buf; -        int32_t recv_buf_size, send_buf_size; -        socklen_t sock_len; - -        if (priv->handshake.incoming.state == IB_VERBS_HANDSHAKE_COMPLETE) { -                return -1; -        } - -        pthread_mutex_lock (&priv->write_mutex); -        { -                while (priv->handshake.incoming.state != IB_VERBS_HANDSHAKE_COMPLETE) -                { -                        switch (priv->handshake.incoming.state)  -                        { -                        case IB_VERBS_HANDSHAKE_START: -                                buf = priv->handshake.incoming.buf = GF_CALLOC (1, 256, gf_ibv_mt_char); -                                ib_verbs_fill_handshake_data (buf, &priv->handshake.incoming, priv); -                                buf[0] = 0; -                                priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_RECEIVING_DATA; -                                break; - -                        case IB_VERBS_HANDSHAKE_RECEIVING_DATA: -                                ret = __tcp_readv (this,  -                                                   &priv->handshake.incoming.vector,  -                                                   priv->handshake.incoming.count, -                                                   &priv->handshake.incoming.pending_vector,  -                                                   &priv->handshake.incoming.pending_count); -                                if (ret == -1) { -                                        goto unlock; -                                } - -                                if (ret > 0) { -                                        gf_log (this->xl->name, GF_LOG_TRACE, -                                                "partial header read on NB socket. continue later"); -                                        goto unlock; -                                } -             -                                if (!ret) { -                                        priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_RECEIVED_DATA; -                                } -                                break; - -                        case IB_VERBS_HANDSHAKE_RECEIVED_DATA: -                                ret = sscanf (buf, -                                              "QP1:RECV_BLKSIZE=%08x:SEND_BLKSIZE=%08x\n" -                                              "QP1:LID=%04x:QPN=%06x:PSN=%06x\n", -                                              &recv_buf_size, -                                              &send_buf_size, -                                              &priv->peer.remote_lid, -                                              &priv->peer.remote_qpn, -                                              &priv->peer.remote_psn); - -                                if ((ret != 5) && (strncmp (buf, "QP1:", 4))) { -                                        gf_log ("transport/ib-verbs",  -                                                GF_LOG_CRITICAL, -                                                "%s: remote-host(%s)'s " -                                                "transport type is different", -                                                this->xl->name,  -                                                this->peerinfo.identifier); -                                        ret = -1; -                                        goto unlock; -                                } - -                                if (recv_buf_size < priv->peer.recv_size) -                                        priv->peer.recv_size = recv_buf_size; -                                if (send_buf_size < priv->peer.send_size) -                                        priv->peer.send_size = send_buf_size; -           -                                gf_log ("transport/ib-verbs", GF_LOG_TRACE, -                                        "%s: transacted recv_size=%d " -                                        "send_size=%d", -                                        this->xl->name, priv->peer.recv_size, -                                        priv->peer.send_size); - -                                priv->peer.quota = priv->peer.send_count; - -                                if (ib_verbs_connect_qp (this)) { -                                        gf_log ("transport/ib-verbs",  -                                                GF_LOG_ERROR, -                                                "%s: failed to connect with " -                                                "remote QP", this->xl->name); -                                        ret = -1; -                                        goto unlock; -                                } -                                ib_verbs_fill_handshake_ack (buf, &priv->handshake.incoming); -                                buf[0] = 0; -                                priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_RECEIVING_ACK; -                                break; - -                        case IB_VERBS_HANDSHAKE_RECEIVING_ACK: -                                ret = __tcp_readv (this,  -                                                   &priv->handshake.incoming.vector,  -                                                   priv->handshake.incoming.count, -                                                   &priv->handshake.incoming.pending_vector,  -                                                   &priv->handshake.incoming.pending_count); -                                if (ret == -1) { -                                        goto unlock; -                                } - -                                if (ret > 0) { -                                        gf_log (this->xl->name, GF_LOG_TRACE, -                                                "partial header read on NB " -                                                "socket. continue later"); -                                        goto unlock; -                                } -             -                                if (!ret) { -                                        priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_RECEIVED_ACK; -                                } -                                break; - -                        case IB_VERBS_HANDSHAKE_RECEIVED_ACK: -                                if (strncmp (buf, "DONE", 4)) { -                                        gf_log ("transport/ib-verbs",  -                                                GF_LOG_DEBUG, -                                                "%s: handshake-3 did not " -                                                "return 'DONE' (%s)", -                                                this->xl->name, buf); -                                        ret = -1; -                                        goto unlock; -                                } -                                ret = 0; -                                priv->connected = 1; -                                sock_len = sizeof (struct sockaddr_storage); -                                getpeername (priv->sock, -                                             (struct sockaddr *) &this->peerinfo.sockaddr, -                                             &sock_len); - -                                GF_FREE (priv->handshake.incoming.buf); -                                priv->handshake.incoming.buf = NULL; -                                priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_COMPLETE; -                        } -                } -        } -unlock: -        pthread_mutex_unlock (&priv->write_mutex); - -        if (ret == -1) { -                transport_disconnect (this); -        } else { -                ret = 0; -        } - -        if (!ret && priv->connected) { -                ret = xlator_notify (this->xl, GF_EVENT_CHILD_UP, this); -        } - -        return ret; -} - -static int  -ib_verbs_handshake_pollout (transport_t *this) -{ -        ib_verbs_private_t *priv = this->private; -        char *buf = priv->handshake.outgoing.buf; -        int32_t ret = 0; - -        if (priv->handshake.outgoing.state == IB_VERBS_HANDSHAKE_COMPLETE) { -                return 0; -        } - -        pthread_mutex_unlock (&priv->write_mutex); -        { -                while (priv->handshake.outgoing.state != IB_VERBS_HANDSHAKE_COMPLETE) -                { -                        switch (priv->handshake.outgoing.state)  -                        { -                        case IB_VERBS_HANDSHAKE_START: -                                buf = priv->handshake.outgoing.buf = GF_CALLOC (1, 256, gf_ibv_mt_char); -                                ib_verbs_fill_handshake_data (buf, &priv->handshake.outgoing, priv); -                                priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_SENDING_DATA; -                                break; - -                        case IB_VERBS_HANDSHAKE_SENDING_DATA: -                                ret = __tcp_writev (this,  -                                                    &priv->handshake.outgoing.vector,  -                                                    priv->handshake.outgoing.count, -                                                    &priv->handshake.outgoing.pending_vector,  -                                                    &priv->handshake.outgoing.pending_count); -                                if (ret == -1) { -                                        goto unlock; -                                } - -                                if (ret > 0) { -                                        gf_log (this->xl->name, GF_LOG_TRACE, -                                                "partial header read on NB socket. continue later"); -                                        goto unlock; -                                } -             -                                if (!ret) { -                                        priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_SENT_DATA; -                                } -                                break; - -                        case IB_VERBS_HANDSHAKE_SENT_DATA: -                                ib_verbs_fill_handshake_ack (buf, &priv->handshake.outgoing); -                                priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_SENDING_ACK; -                                break; - -                        case IB_VERBS_HANDSHAKE_SENDING_ACK: -                                ret = __tcp_writev (this, -                                                    &priv->handshake.outgoing.vector, -                                                    priv->handshake.outgoing.count, -                                                    &priv->handshake.outgoing.pending_vector, -                                                    &priv->handshake.outgoing.pending_count); - -                                if (ret == -1) { -                                        goto unlock; -                                } - -                                if (ret > 0) { -                                        gf_log (this->xl->name, GF_LOG_TRACE, -                                                "partial header read on NB " -                                                "socket. continue later"); -                                        goto unlock; -                                } -             -                                if (!ret) { -                                        GF_FREE (priv->handshake.outgoing.buf); -                                        priv->handshake.outgoing.buf = NULL; -                                        priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_COMPLETE; -                                } -                                break; -                        } -                } -        } -unlock: -        pthread_mutex_unlock (&priv->write_mutex); - -        if (ret == -1) { -                transport_disconnect (this); -        } else { -                ret = 0; -        } - -        return ret; -} - -static int -ib_verbs_handshake_pollerr (transport_t *this) -{ -        ib_verbs_private_t *priv = this->private; -        int32_t ret = 0; -        char need_unref = 0; - -        gf_log ("transport/ib-verbs", GF_LOG_DEBUG, -                "%s: peer disconnected, cleaning up", -                this->xl->name); - -        pthread_mutex_lock (&priv->write_mutex); -        { -                __ib_verbs_teardown (this); - -                if (priv->sock != -1) { -                        event_unregister (this->xl->ctx->event_pool,  -                                          priv->sock, priv->idx); -                        need_unref = 1; - -                        if (close (priv->sock) != 0) { -                                gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                        "close () - error: %s", -                                        strerror (errno)); -                                ret = -errno; -                        } -                        priv->tcp_connected = priv->connected = 0; -                        priv->sock = -1; -                } - -                if (priv->handshake.incoming.buf) { -                        GF_FREE (priv->handshake.incoming.buf); -                        priv->handshake.incoming.buf = NULL; -                } - -                priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_START; - -                if (priv->handshake.outgoing.buf) { -                        GF_FREE (priv->handshake.outgoing.buf); -                        priv->handshake.outgoing.buf = NULL; -                } - -                priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_START; -        } -        pthread_mutex_unlock (&priv->write_mutex); - -        xlator_notify (this->xl, GF_EVENT_POLLERR, this, NULL); - -        if (need_unref) -                transport_unref (this); - -        return 0; -} - - -static int -tcp_connect_finish (transport_t *this) -{ -        ib_verbs_private_t *priv = this->private; -        int error = 0, ret = 0; - -        pthread_mutex_lock (&priv->write_mutex); -        { -                ret = __tcp_connect_finish (priv->sock); - -                if (!ret) { -                        this->myinfo.sockaddr_len =  -                                sizeof (this->myinfo.sockaddr); -                        ret = getsockname (priv->sock, -                                           (struct sockaddr *)&this->myinfo.sockaddr,  -                                           &this->myinfo.sockaddr_len); -                        if (ret == -1)  -                        { -                                gf_log (this->xl->name, GF_LOG_ERROR, -                                        "getsockname on new client-socket %d " -                                        "failed (%s)",  -                                        priv->sock, strerror (errno)); -                                close (priv->sock); -                                error = 1; -                                goto unlock; -                        } - -                        gf_ibverbs_get_transport_identifiers (this); -                        priv->tcp_connected = 1; -                } - -                if (ret == -1 && errno != EINPROGRESS) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "tcp connect to %s failed (%s)",  -                                this->peerinfo.identifier, strerror (errno)); -                        error = 1; -                } -        } -unlock: -        pthread_mutex_unlock (&priv->write_mutex); - -        if (error) { -                transport_disconnect (this); -        } - -        return ret; -} - -static int -ib_verbs_event_handler (int fd, int idx, void *data, -                        int poll_in, int poll_out, int poll_err) -{ -        transport_t *this = data; -        ib_verbs_private_t *priv = this->private; -        ib_verbs_options_t *options = NULL; -        int ret = 0; - -        if (!priv->tcp_connected) { -                ret = tcp_connect_finish (this); -                if (priv->tcp_connected) { -                        options = &priv->options; - -                        priv->peer.send_count = options->send_count; -                        priv->peer.recv_count = options->recv_count; -                        priv->peer.send_size = options->send_size; -                        priv->peer.recv_size = options->recv_size; - -                        if ((ret = ib_verbs_create_qp (this)) < 0) { -                                gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                        "%s: could not create QP", -                                        this->xl->name); -                                transport_disconnect (this); -                        } -                } -        } - -        if (!ret && poll_out && priv->tcp_connected) { -                ret = ib_verbs_handshake_pollout (this); -        } - -        if (!ret && poll_in && priv->tcp_connected) { -                if (priv->handshake.incoming.state == IB_VERBS_HANDSHAKE_COMPLETE) { -                        gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                                "%s: pollin received on tcp socket (peer: %s) " -                                "after handshake is complete", -                                this->xl->name, this->peerinfo.identifier); -                        ib_verbs_handshake_pollerr (this); -                        return 0; -                } -                ret = ib_verbs_handshake_pollin (this); -        } - -        if (ret < 0 || poll_err) { -                ret = ib_verbs_handshake_pollerr (this); -        } - -        return 0; -} - -static int -__tcp_nonblock (int fd) -{ -        int flags = 0; -        int ret = -1; - -        flags = fcntl (fd, F_GETFL); - -        if (flags != -1) -                ret = fcntl (fd, F_SETFL, flags | O_NONBLOCK); - -        return ret; -} - -static int32_t -ib_verbs_connect (struct transport *this) -{ -        dict_t *options = this->xl->options; -   -        ib_verbs_private_t *priv = this->private; -   -        int32_t ret = 0; -        gf_boolean_t non_blocking = 1; -        struct sockaddr_storage sockaddr; -        socklen_t sockaddr_len = 0; - -        if (priv->connected) { -                return 0; -        } - -        if (dict_get (options, "non-blocking-io")) { -                char *nb_connect = data_to_str (dict_get (this->xl->options, -                                                          "non-blocking-io")); -           -                if (gf_string2boolean (nb_connect, &non_blocking) == -1) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "'non-blocking-io' takes only boolean " -                                "options, not taking any action"); -                        non_blocking = 1; -                } -        } - -        ret = gf_ibverbs_client_get_remote_sockaddr (this, -                                                     (struct sockaddr *)&sockaddr, -                                                     &sockaddr_len); -        if (ret != 0) { -                gf_log (this->xl->name, GF_LOG_DEBUG, -                        "cannot get remote address to connect"); -                return ret; -        } - -        pthread_mutex_lock (&priv->write_mutex); -        { -                if (priv->sock != -1) { -                        ret = 0; -                        goto unlock; -                } -   -                priv->sock = socket (((struct sockaddr *)&sockaddr)->sa_family, -                                     SOCK_STREAM, 0); -         -                if (priv->sock == -1) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "socket () - error: %s", strerror (errno)); -                        ret = -errno; -                        goto unlock; -                } - -                gf_log (this->xl->name, GF_LOG_TRACE, -                        "socket fd = %d", priv->sock); - -                memcpy (&this->peerinfo.sockaddr, &sockaddr, sockaddr_len); -                this->peerinfo.sockaddr_len = sockaddr_len; - -                ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family =  -                        ((struct sockaddr *)&this->peerinfo.sockaddr)->sa_family; - -                if (non_blocking)  -                { -                        ret = __tcp_nonblock (priv->sock); -         -                        if (ret == -1) -                        { -                                gf_log (this->xl->name, GF_LOG_ERROR, -                                        "could not set socket %d to non " -                                        "blocking mode (%s)", -                                        priv->sock, strerror (errno)); -                                close (priv->sock); -                                priv->sock = -1; -                                goto unlock; -                        } -                } - -                ret = gf_ibverbs_client_bind (this, -                                              (struct sockaddr *)&this->myinfo.sockaddr, -                                              &this->myinfo.sockaddr_len, priv->sock); -                if (ret == -1) -                { -                        gf_log (this->xl->name, GF_LOG_WARNING, -                                "client bind failed: %s", strerror (errno)); -                        close (priv->sock); -                        priv->sock = -1; -                        goto unlock; -                } - -                ret = connect (priv->sock,  -                               (struct sockaddr *)&this->peerinfo.sockaddr,  -                               this->peerinfo.sockaddr_len); -                if (ret == -1 && errno != EINPROGRESS) -                { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "connection attempt failed (%s)",  -                                strerror (errno)); -                        close (priv->sock); -                        priv->sock = -1; -                        goto unlock; -                } - -                priv->tcp_connected = priv->connected = 0; - -                transport_ref (this); - -                priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_START; -                priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_START; -                         -                priv->idx = event_register (this->xl->ctx->event_pool,  -                                            priv->sock, ib_verbs_event_handler, -                                            this, 1, 1);  -        } -unlock: -        pthread_mutex_unlock (&priv->write_mutex); - -        return ret; -} - -static int -ib_verbs_server_event_handler (int fd, int idx, void *data, -                               int poll_in, int poll_out, int poll_err) -{ -        int32_t main_sock = -1; -        transport_t *this, *trans = data; -        ib_verbs_private_t *priv = NULL; -        ib_verbs_private_t *trans_priv = (ib_verbs_private_t *) trans->private; -        ib_verbs_options_t *options = NULL; - -        if (!poll_in) -                return 0; - -        this = GF_CALLOC (1, sizeof (transport_t), -                          gf_ibv_mt_transport_t); -        if (!this) -                return 0; - -        priv = GF_CALLOC (1, sizeof (ib_verbs_private_t), -                          gf_ibv_mt_ib_verbs_private_t); -        if (!priv) { -                GF_FREE (this); -                return 0; -        } - -        this->private = priv; -        /* Copy all the ib_verbs related values in priv, from trans_priv  -           as other than QP, all the values remain same */ -        priv->device = trans_priv->device; -        priv->options = trans_priv->options; -        options = &priv->options; - -        this->ops = trans->ops; -        this->xl = trans->xl; -        this->init = trans->init; -        this->fini = trans->fini; - -        memcpy (&this->myinfo.sockaddr, &trans->myinfo.sockaddr,  -                trans->myinfo.sockaddr_len); -        this->myinfo.sockaddr_len = trans->myinfo.sockaddr_len; - -        main_sock = (trans_priv)->sock; -        this->peerinfo.sockaddr_len = sizeof (this->peerinfo.sockaddr); -        priv->sock = accept (main_sock,  -                             (struct sockaddr *)&this->peerinfo.sockaddr,  -                             &this->peerinfo.sockaddr_len); -        if (priv->sock == -1) { -                gf_log ("ib-verbs/server", GF_LOG_ERROR, -                        "accept() failed: %s", -                        strerror (errno)); -                GF_FREE (this->private); -                GF_FREE (this); -                return -1; -        } - -        priv->peer.trans = this; -        transport_ref (this); - -        gf_ibverbs_get_transport_identifiers (this); - -        priv->tcp_connected = 1; -        priv->handshake.incoming.state = IB_VERBS_HANDSHAKE_START; -        priv->handshake.outgoing.state = IB_VERBS_HANDSHAKE_START; - -        priv->peer.send_count = options->send_count; -        priv->peer.recv_count = options->recv_count; -        priv->peer.send_size = options->send_size; -        priv->peer.recv_size = options->recv_size; -        INIT_LIST_HEAD (&priv->peer.ioq); - -        if (ib_verbs_create_qp (this) < 0) { -                gf_log ("transport/ib-verbs", GF_LOG_ERROR, -                        "%s: could not create QP", -                        this->xl->name); -                transport_disconnect (this); -                return -1; -        } - -        priv->idx = event_register (this->xl->ctx->event_pool, priv->sock, -                                    ib_verbs_event_handler, this, 1, 1); - -        pthread_mutex_init (&priv->read_mutex, NULL); -        pthread_mutex_init (&priv->write_mutex, NULL); -        pthread_mutex_init (&priv->recv_mutex, NULL); -        /*  pthread_cond_init (&priv->recv_cond, NULL); */ - -        return 0; -} - -static int32_t -ib_verbs_listen (transport_t *this) -{ -        struct sockaddr_storage sockaddr; -        socklen_t sockaddr_len; -        ib_verbs_private_t *priv = this->private; -        int opt = 1, ret = 0; -        char service[NI_MAXSERV], host[NI_MAXHOST]; - -        memset (&sockaddr, 0, sizeof (sockaddr)); -        ret = gf_ibverbs_server_get_local_sockaddr (this, -                                                    (struct sockaddr *)&sockaddr, -                                                    &sockaddr_len); -        if (ret != 0) { -                gf_log (this->xl->name, GF_LOG_DEBUG, -                        "cannot find network address of server to bind to"); -                goto err; -        } - -        priv->sock = socket (((struct sockaddr *)&sockaddr)->sa_family,  -                             SOCK_STREAM, 0); -        if (priv->sock == -1) { -                gf_log ("ib-verbs/server", GF_LOG_CRITICAL, -                        "init: failed to create socket, error: %s", -                        strerror (errno)); -                GF_FREE (this->private); -                ret = -1; -                goto err; -        } - -        memcpy (&this->myinfo.sockaddr, &sockaddr, sockaddr_len); -        this->myinfo.sockaddr_len = sockaddr_len; - -        ret = getnameinfo ((struct sockaddr *)&this->myinfo.sockaddr,  -                           this->myinfo.sockaddr_len, -                           host, sizeof (host), -                           service, sizeof (service), -                           NI_NUMERICHOST); -        if (ret != 0) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "getnameinfo failed (%s)", gai_strerror (ret)); -                goto err; -        } -        sprintf (this->myinfo.identifier, "%s:%s", host, service); -  -        setsockopt (priv->sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof (opt)); -        if (bind (priv->sock, -                  (struct sockaddr *)&sockaddr, -                  sockaddr_len) != 0) { -                ret = -1; -                gf_log ("ib-verbs/server", GF_LOG_ERROR, -                        "init: failed to bind to socket for %s (%s)", -                        this->myinfo.identifier, strerror (errno)); -                goto err; -        } - -        if (listen (priv->sock, 10) != 0) { -                gf_log ("ib-verbs/server", GF_LOG_ERROR, -                        "init: listen () failed on socket for %s (%s)", -                        this->myinfo.identifier, strerror (errno)); -                ret = -1; -                goto err; -        } - -        /* Register the main socket */ -        priv->idx = event_register (this->xl->ctx->event_pool, priv->sock, -                                    ib_verbs_server_event_handler,  -                                    transport_ref (this), 1, 0); - -err: -        return ret; -} - -struct transport_ops tops = { -        .receive = ib_verbs_receive, -        .submit = ib_verbs_submit, -        .connect = ib_verbs_connect, -        .disconnect = ib_verbs_disconnect, -        .listen = ib_verbs_listen, -}; - -int32_t -init (transport_t *this) -{ -        ib_verbs_private_t *priv = GF_CALLOC (1, sizeof (*priv), -                                              gf_ibv_mt_ib_verbs_private_t); -        this->private = priv; -        priv->sock = -1; - -        if (ib_verbs_init (this)) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "Failed to initialize IB Device"); -                return -1; -        } - -        return 0; -} - -void   -fini (struct transport *this) -{ -        /* TODO: verify this function does graceful finish */ -        ib_verbs_private_t *priv = this->private; -        this->private = NULL; - -        pthread_mutex_destroy (&priv->recv_mutex); -        pthread_mutex_destroy (&priv->write_mutex); -        pthread_mutex_destroy (&priv->read_mutex); -        /*  pthread_cond_destroy (&priv->recv_cond); */ - -        gf_log (this->xl->name, GF_LOG_TRACE, -                "called fini on transport: %p", -                this); -        GF_FREE (priv); -        return; -} - -int32_t -mem_acct_init (xlator_t *this) -{ -        int     ret = -1; - -        if (!this) -                return ret; - -        ret = xlator_mem_acct_init (this, gf_common_mt_end + 1); -         -        if (ret != 0) { -                gf_log (this->name, GF_LOG_ERROR, "Memory accounting init" -                                "failed"); -                return ret; -        } - -        return ret; -} - -/* TODO: expand each option */ -struct volume_options options[] = { -        { .key   = {"transport.ib-verbs.port", -                    "ib-verbs-port"},  -          .type  = GF_OPTION_TYPE_INT, -          .min   = 1, -          .max   = 4, -          .description = "check the option by 'ibv_devinfo'" -        }, -        { .key   = {"transport.ib-verbs.mtu", -                    "ib-verbs-mtu"},  -          .type  = GF_OPTION_TYPE_INT, -        }, -        { .key   = {"transport.ib-verbs.device-name", -                    "ib-verbs-device-name"},  -          .type  = GF_OPTION_TYPE_ANY, -          .description = "check by 'ibv_devinfo'" -        }, -        { .key   = {"transport.ib-verbs.work-request-send-count", -                    "ib-verbs-work-request-send-count"},  -          .type  = GF_OPTION_TYPE_INT, -        }, -        { .key   = {"transport.ib-verbs.work-request-recv-count", -                    "ib-verbs-work-request-recv-count"},  -          .type  = GF_OPTION_TYPE_INT, -        }, -        { .key   = {"remote-port",  -                    "transport.remote-port", -                    "transport.ib-verbs.remote-port"},  -          .type  = GF_OPTION_TYPE_INT  -        }, -        { .key   = {"transport.ib-verbs.listen-port", "listen-port"},  -          .type  = GF_OPTION_TYPE_INT  -        }, -        { .key   = {"transport.ib-verbs.connect-path", "connect-path"},  -          .type  = GF_OPTION_TYPE_ANY  -        }, -        { .key   = {"transport.ib-verbs.bind-path", "bind-path"},  -          .type  = GF_OPTION_TYPE_ANY  -        }, -        { .key   = {"transport.ib-verbs.listen-path", "listen-path"},  -          .type  = GF_OPTION_TYPE_ANY  -        }, -        { .key   = {"transport.address-family", -                    "address-family"},  -          .value = {"inet", "inet6", "inet/inet6", "inet6/inet", -                    "unix", "inet-sdp" }, -          .type  = GF_OPTION_TYPE_STR  -        }, -        { .key   = {"transport.socket.lowlat"}, -          .type  = GF_OPTION_TYPE_BOOL -        }, -        { .key = {NULL} } -}; diff --git a/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.h b/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.h deleted file mode 100644 index 3818609b01f..00000000000 --- a/xlators/protocol/legacy/transport/ib-verbs/src/ib-verbs.h +++ /dev/null @@ -1,220 +0,0 @@ -/* -  Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _XPORT_IB_VERBS_H -#define _XPORT_IB_VERBS_H - - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#ifndef MAX_IOVEC -#define MAX_IOVEC 16 -#endif /* MAX_IOVEC */ - -#include "xlator.h" -#include "event.h" -#include "ib-verbs-mem-types.h" - -#include <stdio.h> -#include <list.h> -#include <arpa/inet.h> -#include <infiniband/verbs.h> - -#define GF_DEFAULT_IBVERBS_LISTEN_PORT 6997 - -/* options per transport end point */ -struct _ib_verbs_options { -        int32_t port; -        char *device_name; -        enum ibv_mtu mtu; -        int32_t  send_count; -        int32_t  recv_count; -        uint64_t recv_size; -        uint64_t send_size; -}; -typedef struct _ib_verbs_options ib_verbs_options_t; - - -struct _ib_verbs_header { -        char     colonO[3]; -        uint32_t size1; -        uint32_t size2; -        char     version; -} __attribute__((packed)); -typedef struct _ib_verbs_header ib_verbs_header_t; - -struct _ib_verbs_ioq { -        union { -                struct list_head list; -                struct { -                        struct _ib_verbs_ioq    *next; -                        struct _ib_verbs_ioq    *prev; -                }; -        }; -        ib_verbs_header_t  header; -        struct iovec       vector[MAX_IOVEC]; -        int                count; -        char              *buf; -        struct iobref     *iobref; -}; -typedef struct _ib_verbs_ioq ib_verbs_ioq_t; - -/* represents one communication peer, two per transport_t */ -struct _ib_verbs_peer { -        transport_t *trans; -        struct ibv_qp *qp; - -        int32_t recv_count; -        int32_t send_count; -        int32_t recv_size; -        int32_t send_size; - -        int32_t quota; -        union { -                struct list_head     ioq; -                struct { -                        ib_verbs_ioq_t        *ioq_next; -                        ib_verbs_ioq_t        *ioq_prev; -                }; -        }; - -        /* QP attributes, needed to connect with remote QP */ -        int32_t local_lid; -        int32_t local_psn; -        int32_t local_qpn; -        int32_t remote_lid; -        int32_t remote_psn; -        int32_t remote_qpn; -}; -typedef struct _ib_verbs_peer ib_verbs_peer_t; - - -struct _ib_verbs_post { -        struct _ib_verbs_post *next, *prev; -        struct ibv_mr *mr; -        char *buf; -        int32_t buf_size; -        char aux; -        int32_t reused; -        pthread_barrier_t wait; -}; -typedef struct _ib_verbs_post ib_verbs_post_t; - - -struct _ib_verbs_queue { -        ib_verbs_post_t active_posts, passive_posts; -        int32_t active_count, passive_count; -        pthread_mutex_t lock; -}; -typedef struct _ib_verbs_queue ib_verbs_queue_t; - - -struct _ib_verbs_qpreg { -        pthread_mutex_t lock; -        int32_t count; -        struct _qpent { -                struct _qpent *next, *prev; -                int32_t qp_num; -                ib_verbs_peer_t *peer; -        } ents[42]; -}; -typedef struct _ib_verbs_qpreg ib_verbs_qpreg_t; - -/* context per device, stored in global glusterfs_ctx_t->ib */ -struct _ib_verbs_device { -        struct _ib_verbs_device *next; -        const char *device_name; -        struct ibv_context *context; -        int32_t port; -        struct ibv_pd *pd; -        struct ibv_srq *srq; -        ib_verbs_qpreg_t qpreg; -        struct ibv_comp_channel *send_chan, *recv_chan; -        struct ibv_cq *send_cq, *recv_cq; -        ib_verbs_queue_t sendq, recvq; -        pthread_t send_thread, recv_thread; -}; -typedef struct _ib_verbs_device ib_verbs_device_t; - -typedef enum { -        IB_VERBS_HANDSHAKE_START = 0, -        IB_VERBS_HANDSHAKE_SENDING_DATA, -        IB_VERBS_HANDSHAKE_RECEIVING_DATA, -        IB_VERBS_HANDSHAKE_SENT_DATA, -        IB_VERBS_HANDSHAKE_RECEIVED_DATA, -        IB_VERBS_HANDSHAKE_SENDING_ACK, -        IB_VERBS_HANDSHAKE_RECEIVING_ACK, -        IB_VERBS_HANDSHAKE_RECEIVED_ACK, -        IB_VERBS_HANDSHAKE_COMPLETE, -} ib_verbs_handshake_state_t; - -struct ib_verbs_nbio { -        int state; -        char *buf; -        int count; -        struct iovec vector; -        struct iovec *pending_vector; -        int pending_count; -}; - - -struct _ib_verbs_private { -        int32_t sock; -        int32_t idx; -        unsigned char connected; -        unsigned char tcp_connected; -        unsigned char ib_connected; -        in_addr_t addr; -        unsigned short port; - -        /* IB Verbs Driver specific variables, pointers */ -        ib_verbs_peer_t peer; -        ib_verbs_device_t *device; -        ib_verbs_options_t options; - -        /* Used by trans->op->receive */ -        char *data_ptr; -        int32_t data_offset; -        int32_t data_len; - -        /* Mutex */ -        pthread_mutex_t read_mutex; -        pthread_mutex_t write_mutex; -        pthread_barrier_t handshake_barrier; -        char handshake_ret; - -        pthread_mutex_t recv_mutex; -        pthread_cond_t  recv_cond; - -        /* used during ib_verbs_handshake */ -        struct { -                struct ib_verbs_nbio incoming; -                struct ib_verbs_nbio outgoing; -                int               state; -                ib_verbs_header_t header; -                char *buf; -                size_t size; -        } handshake; -}; -typedef struct _ib_verbs_private ib_verbs_private_t; - -#endif /* _XPORT_IB_VERBS_H */ diff --git a/xlators/protocol/legacy/transport/ib-verbs/src/name.c b/xlators/protocol/legacy/transport/ib-verbs/src/name.c deleted file mode 100644 index 511a33a2267..00000000000 --- a/xlators/protocol/legacy/transport/ib-verbs/src/name.c +++ /dev/null @@ -1,712 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#include <sys/types.h> -#include <sys/socket.h> -#include <errno.h> -#include <netdb.h> -#include <string.h> - -#ifdef CLIENT_PORT_CEILING -#undef CLIENT_PORT_CEILING -#endif - -#define CLIENT_PORT_CEILING 1024 - -#ifndef AF_INET_SDP -#define AF_INET_SDP 27 -#endif - -#include "transport.h" -#include "ib-verbs.h" - -int32_t -gf_resolve_ip6 (const char *hostname,  -                uint16_t port,  -                int family,  -                void **dnscache,  -                struct addrinfo **addr_info); - -static int32_t -af_inet_bind_to_port_lt_ceiling (int fd, struct sockaddr *sockaddr,  -                                 socklen_t sockaddr_len, int ceiling) -{ -        int32_t ret = -1; -        /*  struct sockaddr_in sin = {0, }; */ -        uint16_t port = ceiling - 1; - -        while (port) -        { -                switch (sockaddr->sa_family) -                { -                case AF_INET6: -                        ((struct sockaddr_in6 *)sockaddr)->sin6_port = htons (port); -                        break; - -                case AF_INET_SDP: -                case AF_INET: -                        ((struct sockaddr_in *)sockaddr)->sin_port = htons (port); -                        break; -                } - -                ret = bind (fd, sockaddr, sockaddr_len); - -                if (ret == 0) -                        break; - -                if (ret == -1 && errno == EACCES) -                        break; - -                port--; -        } - -        return ret; -} - -static int32_t -af_unix_client_bind (transport_t *this,  -                     struct sockaddr *sockaddr,  -                     socklen_t sockaddr_len,  -                     int sock) -{ -        data_t *path_data = NULL; -        struct sockaddr_un *addr = NULL; -        int32_t ret = -1; - -        path_data = dict_get (this->xl->options,  -                              "transport.ib-verbs.bind-path"); -        if (path_data) { -                char *path = data_to_str (path_data); -                if (!path || strlen (path) > UNIX_PATH_MAX) { -                        gf_log (this->xl->name, GF_LOG_DEBUG, -                                "transport.ib-verbs.bind-path not specfied " -                                "for unix socket, letting connect to assign " -                                "default value"); -                        goto err; -                } - -                addr = (struct sockaddr_un *) sockaddr; -                strcpy (addr->sun_path, path); -                ret = bind (sock, (struct sockaddr *)addr, sockaddr_len); -                if (ret == -1) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "cannot bind to unix-domain socket %d (%s)",  -                                sock, strerror (errno)); -                        goto err; -                } -        } - -err: -        return ret; -} - -static int32_t -client_fill_address_family (transport_t *this, struct sockaddr *sockaddr) -{ -        data_t *address_family_data = NULL; - -        address_family_data = dict_get (this->xl->options,  -                                        "transport.address-family"); -        if (!address_family_data) { -                data_t *remote_host_data = NULL, *connect_path_data = NULL; -                remote_host_data = dict_get (this->xl->options, "remote-host"); -                connect_path_data = dict_get (this->xl->options,  -                                              "transport.ib-verbs.connect-path"); - -                if (!(remote_host_data || connect_path_data) ||  -                    (remote_host_data && connect_path_data)) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "address-family not specified and not able to " -                                "determine the same from other options " -                                "(remote-host:%s and connect-path:%s)",  -                                data_to_str (remote_host_data),  -                                data_to_str (connect_path_data)); -                        return -1; -                }  - -                if (remote_host_data) { -                        gf_log (this->xl->name, GF_LOG_DEBUG, -                                "address-family not specified, guessing it " -                                "to be inet/inet6"); -                        sockaddr->sa_family = AF_UNSPEC; -                } else { -                        gf_log (this->xl->name, GF_LOG_DEBUG, -                                "address-family not specified, guessing it " -                                "to be unix"); -                        sockaddr->sa_family = AF_UNIX; -                } - -        } else { -                char *address_family = data_to_str (address_family_data); -                if (!strcasecmp (address_family, "unix")) { -                        sockaddr->sa_family = AF_UNIX; -                } else if (!strcasecmp (address_family, "inet")) { -                        sockaddr->sa_family = AF_INET; -                } else if (!strcasecmp (address_family, "inet6")) { -                        sockaddr->sa_family = AF_INET6; -                } else if (!strcasecmp (address_family, "inet-sdp")) { -                        sockaddr->sa_family = AF_INET_SDP; -                } else if (!strcasecmp (address_family, "inet/inet6") -                           || !strcasecmp (address_family, "inet6/inet")) { -                        sockaddr->sa_family = AF_UNSPEC; -                } else { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "unknown address-family (%s) specified",  -                                address_family); -                        return -1; -                } -        } - -        return 0; -} - -static int32_t -af_inet_client_get_remote_sockaddr (transport_t *this,  -                                    struct sockaddr *sockaddr,  -                                    socklen_t *sockaddr_len) -{ -        dict_t *options = this->xl->options; -        data_t *remote_host_data = NULL; -        data_t *remote_port_data = NULL; -        char *remote_host = NULL; -        uint16_t remote_port = 0; -        struct addrinfo *addr_info = NULL; -        int32_t ret = 0; - -        remote_host_data = dict_get (options, "remote-host"); -        if (remote_host_data == NULL) -        { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "option remote-host missing in volume %s",  -                        this->xl->name); -                ret = -1; -                goto err; -        } - -        remote_host = data_to_str (remote_host_data); -        if (remote_host == NULL) -        { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "option remote-host has data NULL in volume %s",  -                        this->xl->name); -                ret = -1; -                goto err; -        } - -        remote_port_data = dict_get (options, "remote-port"); -        if (remote_port_data == NULL) -        { -                gf_log (this->xl->name, GF_LOG_DEBUG, -                        "option remote-port missing in volume %s. " -                        "Defaulting to %d", -                        this->xl->name, GF_DEFAULT_IBVERBS_LISTEN_PORT); - -                remote_port = GF_DEFAULT_IBVERBS_LISTEN_PORT; -        } -        else -        { -                remote_port = data_to_uint16 (remote_port_data); -        } - -        if (remote_port == (uint16_t)-1) -        { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "option remote-port has invalid port in volume %s", -                        this->xl->name); -                ret = -1; -                goto err; -        } - -        /* TODO: gf_resolve is a blocking call. kick in some -           non blocking dns techniques */ -        ret = gf_resolve_ip6 (remote_host, remote_port, -                              sockaddr->sa_family,  -                              &this->dnscache, &addr_info); -        if (ret == -1) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "DNS resolution failed on host %s", remote_host); -                goto err; -        } - -        memcpy (sockaddr, addr_info->ai_addr, addr_info->ai_addrlen); -        *sockaddr_len = addr_info->ai_addrlen; - -err: -        return ret; -} - -static int32_t -af_unix_client_get_remote_sockaddr (transport_t *this,  -                                    struct sockaddr *sockaddr,  -                                    socklen_t *sockaddr_len) -{ -        struct sockaddr_un *sockaddr_un = NULL; -        char *connect_path = NULL; -        data_t *connect_path_data = NULL; -        int32_t ret = 0; - -        connect_path_data = dict_get (this->xl->options,  -                                      "transport.ib-verbs.connect-path"); -        if (!connect_path_data) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "option transport.ib-verbs.connect-path not " -                        "specified for address-family unix"); -                ret = -1; -                goto err; -        } - -        connect_path = data_to_str (connect_path_data); -        if (!connect_path) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "connect-path is null-string"); -                ret = -1; -                goto err; -        } - -        if (strlen (connect_path) > UNIX_PATH_MAX) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "connect-path value length %"GF_PRI_SIZET" > " -                        "%d octets", strlen (connect_path), UNIX_PATH_MAX); -                ret = -1; -                goto err; -        } - -        gf_log (this->xl->name, -                GF_LOG_DEBUG, -                "using connect-path %s", connect_path); -        sockaddr_un = (struct sockaddr_un *)sockaddr; -        strcpy (sockaddr_un->sun_path, connect_path); -        *sockaddr_len = sizeof (struct sockaddr_un); - -err: -        return ret; -} - -static int32_t -af_unix_server_get_local_sockaddr (transport_t *this, -                                   struct sockaddr *addr, -                                   socklen_t *addr_len) -{ -        data_t *listen_path_data = NULL; -        char *listen_path = NULL; -        int32_t ret = 0; -        struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr; - - -        listen_path_data = dict_get (this->xl->options,  -                                     "transport.ib-verbs.listen-path"); -        if (!listen_path_data) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "missing option listen-path"); -                ret = -1; -                goto err; -        } - -        listen_path = data_to_str (listen_path_data); - -#ifndef UNIX_PATH_MAX -#define UNIX_PATH_MAX 108 -#endif - -        if (strlen (listen_path) > UNIX_PATH_MAX) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "option listen-path has value length %"GF_PRI_SIZET" > %d", -                        strlen (listen_path), UNIX_PATH_MAX); -                ret = -1; -                goto err; -        } - -        sunaddr->sun_family = AF_UNIX; -        strcpy (sunaddr->sun_path, listen_path); -        *addr_len = sizeof (struct sockaddr_un); - -err: -        return ret; -} - -static int32_t  -af_inet_server_get_local_sockaddr (transport_t *this,  -                                   struct sockaddr *addr,  -                                   socklen_t *addr_len) -{ -        struct addrinfo hints, *res = 0; -        data_t *listen_port_data = NULL, *listen_host_data = NULL; -        uint16_t listen_port = -1; -        char service[NI_MAXSERV], *listen_host = NULL; -        dict_t *options = NULL; -        int32_t ret = 0; - -        options = this->xl->options; - -        listen_port_data = dict_get (options, "transport.ib-verbs.listen-port"); -        listen_host_data = dict_get (options, "transport.ib-verbs.bind-address"); - -        if (listen_port_data) -        { -                listen_port = data_to_uint16 (listen_port_data); -        } else { -		if (addr->sa_family == AF_INET6) { -			struct sockaddr_in6 *in = (struct sockaddr_in6 *) addr; -			in->sin6_addr = in6addr_any; -			in->sin6_port = htons(listen_port); -			*addr_len = sizeof(struct sockaddr_in6); -                        goto out; -		} else if (addr->sa_family == AF_INET) { -			struct sockaddr_in *in = (struct sockaddr_in *) addr; -			in->sin_addr.s_addr = htonl(INADDR_ANY); -			in->sin_port = htons(listen_port); -			*addr_len = sizeof(struct sockaddr_in); -                        goto out; -		} -	} - -        if (listen_port == (uint16_t) -1) -                listen_port = GF_DEFAULT_IBVERBS_LISTEN_PORT; - - -        if (listen_host_data) -        { -                listen_host = data_to_str (listen_host_data); -        } - -        memset (service, 0, sizeof (service)); -        sprintf (service, "%d", listen_port); - -        memset (&hints, 0, sizeof (hints)); -        hints.ai_family = addr->sa_family; -        hints.ai_socktype = SOCK_STREAM; -        hints.ai_flags    = AI_ADDRCONFIG | AI_PASSIVE; - -        ret = getaddrinfo(listen_host, service, &hints, &res); -        if (ret != 0) { -                gf_log (this->xl->name, -                        GF_LOG_ERROR, -                        "getaddrinfo failed for host %s, service %s (%s)",  -                        listen_host, service, gai_strerror (ret)); -                ret = -1; -                goto out; -        } - -        memcpy (addr, res->ai_addr, res->ai_addrlen); -        *addr_len = res->ai_addrlen; - -        freeaddrinfo (res); - -out: -        return ret; -} - -int32_t -gf_ibverbs_client_bind (transport_t *this, -                        struct sockaddr *sockaddr, -                        socklen_t *sockaddr_len, -                        int sock) -{ -        int ret = 0; - -        *sockaddr_len = sizeof (struct sockaddr_in6); -        switch (sockaddr->sa_family) -        { -        case AF_INET_SDP: -        case AF_INET: -                *sockaddr_len = sizeof (struct sockaddr_in); - -        case AF_INET6: -                ret = af_inet_bind_to_port_lt_ceiling (sock, sockaddr,  -                                                       *sockaddr_len,  -                                                       CLIENT_PORT_CEILING); -                if (ret == -1) { -                        gf_log (this->xl->name, GF_LOG_WARNING, -                                "cannot bind inet socket (%d) to port " -                                "less than %d (%s)",  -                                sock, CLIENT_PORT_CEILING, strerror (errno)); -                        ret = 0; -                } -                break; - -        case AF_UNIX: -                *sockaddr_len = sizeof (struct sockaddr_un); -                ret = af_unix_client_bind (this, (struct sockaddr *)sockaddr,  -                                           *sockaddr_len, sock); -                break; - -        default: -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "unknown address family %d", sockaddr->sa_family); -                ret = -1; -                break; -        } - -        return ret; -} - -int32_t -gf_ibverbs_client_get_remote_sockaddr (transport_t *this, -                                       struct sockaddr *sockaddr, -                                       socklen_t *sockaddr_len) -{ -        int32_t ret = 0; -        char is_inet_sdp = 0; - -        ret = client_fill_address_family (this, sockaddr); -        if (ret) { -                ret = -1; -                goto err; -        } -  -        switch (sockaddr->sa_family) -        { -        case AF_INET_SDP: -                sockaddr->sa_family = AF_INET; -                is_inet_sdp = 1; - -        case AF_INET: -        case AF_INET6: -        case AF_UNSPEC: -                ret = af_inet_client_get_remote_sockaddr (this,  -                                                          sockaddr,  -                                                          sockaddr_len); - -                if (is_inet_sdp) { -                        sockaddr->sa_family = AF_INET_SDP; -                } - -                break; - -        case AF_UNIX: -                ret = af_unix_client_get_remote_sockaddr (this,  -                                                          sockaddr,  -                                                          sockaddr_len); -                break; - -        default: -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "unknown address-family %d", sockaddr->sa_family); -                ret = -1; -        } -   -err: -        return ret; -} - -int32_t -gf_ibverbs_server_get_local_sockaddr (transport_t *this, -                                      struct sockaddr *addr, -                                      socklen_t *addr_len) -{ -        data_t *address_family_data = NULL; -        int32_t ret = 0; -        char is_inet_sdp = 0; - -        address_family_data = dict_get (this->xl->options,  -                                        "transport.address-family"); -        if (address_family_data) { -                char *address_family = NULL; -                address_family = data_to_str (address_family_data); - -                if (!strcasecmp (address_family, "inet")) { -                        addr->sa_family = AF_INET; -                } else if (!strcasecmp (address_family, "inet6")) { -                        addr->sa_family = AF_INET6; -                } else if (!strcasecmp (address_family, "inet-sdp")) { -                        addr->sa_family = AF_INET_SDP; -                } else if (!strcasecmp (address_family, "unix")) { -                        addr->sa_family = AF_UNIX; -                } else if (!strcasecmp (address_family, "inet/inet6") -                           || !strcasecmp (address_family, "inet6/inet")) { -                        addr->sa_family = AF_UNSPEC; -                } else { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "unknown address family (%s) specified",  -                                address_family); -                        ret = -1; -                        goto err; -                } -        } else { -                gf_log (this->xl->name, GF_LOG_DEBUG, -                        "option address-family not specified, defaulting " -                        "to inet/inet6"); -                addr->sa_family = AF_UNSPEC; -        } - -        switch (addr->sa_family) -        { -        case AF_INET_SDP: -                is_inet_sdp = 1; -                addr->sa_family = AF_INET; - -        case AF_INET: -        case AF_INET6: -        case AF_UNSPEC: -                ret = af_inet_server_get_local_sockaddr (this, addr, addr_len); -                if (is_inet_sdp && !ret) { -                        addr->sa_family = AF_INET_SDP; -                } -                break; - -        case AF_UNIX: -                ret = af_unix_server_get_local_sockaddr (this, addr, addr_len); -                break; -        } - -err: -        return ret; -} - -int32_t  -fill_inet6_inet_identifiers (transport_t *this, struct sockaddr_storage *addr,  -                             int32_t addr_len, char *identifier) -{ -        int32_t ret = 0, tmpaddr_len = 0; -        char service[NI_MAXSERV], host[NI_MAXHOST]; -        struct sockaddr_storage tmpaddr; - -        memset (&tmpaddr, 0, sizeof (tmpaddr)); -        tmpaddr = *addr; -        tmpaddr_len = addr_len; - -        if (((struct sockaddr *) &tmpaddr)->sa_family == AF_INET6) { -                int32_t one_to_four, four_to_eight, twelve_to_sixteen; -                int16_t eight_to_ten, ten_to_twelve; -     -                one_to_four = four_to_eight = twelve_to_sixteen = 0; -                eight_to_ten = ten_to_twelve = 0; -     -                one_to_four = ((struct sockaddr_in6 *)  -                               &tmpaddr)->sin6_addr.s6_addr32[0]; -                four_to_eight = ((struct sockaddr_in6 *)  -                                 &tmpaddr)->sin6_addr.s6_addr32[1]; -#ifdef GF_SOLARIS_HOST_OS -                eight_to_ten = S6_ADDR16(((struct sockaddr_in6 *)  -                                          &tmpaddr)->sin6_addr)[4]; -#else -                eight_to_ten = ((struct sockaddr_in6 *)  -                                &tmpaddr)->sin6_addr.s6_addr16[4]; -#endif - -#ifdef GF_SOLARIS_HOST_OS -                ten_to_twelve = S6_ADDR16(((struct sockaddr_in6 *)  -                                           &tmpaddr)->sin6_addr)[5]; -#else -                ten_to_twelve = ((struct sockaddr_in6 *)  -                                 &tmpaddr)->sin6_addr.s6_addr16[5]; -#endif -                twelve_to_sixteen = ((struct sockaddr_in6 *)  -                                     &tmpaddr)->sin6_addr.s6_addr32[3]; - -                /* ipv4 mapped ipv6 address has -                   bits 0-80: 0 -                   bits 80-96: 0xffff -                   bits 96-128: ipv4 address  -                */ -  -                if (one_to_four == 0 && -                    four_to_eight == 0 && -                    eight_to_ten == 0 && -                    ten_to_twelve == -1) { -                        struct sockaddr_in *in_ptr = (struct sockaddr_in *)&tmpaddr; -                        memset (&tmpaddr, 0, sizeof (tmpaddr)); -       -                        in_ptr->sin_family = AF_INET; -                        in_ptr->sin_port = ((struct sockaddr_in6 *)addr)->sin6_port; -                        in_ptr->sin_addr.s_addr = twelve_to_sixteen; -                        tmpaddr_len = sizeof (*in_ptr); -                } -        } - -        ret = getnameinfo ((struct sockaddr *) &tmpaddr, -                           tmpaddr_len, -                           host, sizeof (host), -                           service, sizeof (service), -                           NI_NUMERICHOST | NI_NUMERICSERV); -        if (ret != 0) { -                gf_log (this->xl->name, -                        GF_LOG_ERROR, -                        "getnameinfo failed (%s)", gai_strerror (ret)); -        } - -        sprintf (identifier, "%s:%s", host, service); - -        return ret; -} - -int32_t -gf_ibverbs_get_transport_identifiers (transport_t *this) -{ -        int32_t ret = 0; -        char is_inet_sdp = 0; - -        switch (((struct sockaddr *) &this->myinfo.sockaddr)->sa_family) -        { -        case AF_INET_SDP: -                is_inet_sdp = 1; -                ((struct sockaddr *) &this->peerinfo.sockaddr)->sa_family = ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family = AF_INET; - -        case AF_INET: -        case AF_INET6: -        { -                ret = fill_inet6_inet_identifiers (this,  -                                                   &this->myinfo.sockaddr,  -                                                   this->myinfo.sockaddr_len, -                                                   this->myinfo.identifier); -                if (ret == -1) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "can't fill inet/inet6 identifier for server"); -                        goto err; -                } - -                ret = fill_inet6_inet_identifiers (this, -                                                   &this->peerinfo.sockaddr, -                                                   this->peerinfo.sockaddr_len, -                                                   this->peerinfo.identifier); -                if (ret == -1) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "can't fill inet/inet6 identifier for client"); -                        goto err; -                } - -                if (is_inet_sdp) { -                        ((struct sockaddr *) &this->peerinfo.sockaddr)->sa_family = ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family = AF_INET_SDP; -                } -        } -        break; - -        case AF_UNIX: -        { -                struct sockaddr_un *sunaddr = NULL; - -                sunaddr = (struct sockaddr_un *) &this->myinfo.sockaddr; -                strcpy (this->myinfo.identifier, sunaddr->sun_path); - -                sunaddr = (struct sockaddr_un *) &this->peerinfo.sockaddr; -                strcpy (this->peerinfo.identifier, sunaddr->sun_path); -        } -        break; - -        default: -                gf_log (this->xl->name, GF_LOG_ERROR,  -                        "unknown address family (%d)", -                        ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family); -                ret = -1; -                break; -        } - -err: -        return ret; -} diff --git a/xlators/protocol/legacy/transport/ib-verbs/src/name.h b/xlators/protocol/legacy/transport/ib-verbs/src/name.h deleted file mode 100644 index 366077fddd9..00000000000 --- a/xlators/protocol/legacy/transport/ib-verbs/src/name.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _IB_VERBS_NAME_H -#define _IB_VERBS_NAME_H - -#include <sys/socket.h> -#include <sys/un.h> - -#include "compat.h" - -int32_t -gf_ibverbs_client_bind (transport_t *this, -                        struct sockaddr *sockaddr, -                        socklen_t *sockaddr_len, -                        int sock); - -int32_t -gf_ibverbs_client_get_remote_sockaddr (transport_t *this, -                                    struct sockaddr *sockaddr, -                                    socklen_t *sockaddr_len); - -int32_t -gf_ibverbs_server_get_local_sockaddr (transport_t *this, -                                   struct sockaddr *addr, -                                   socklen_t *addr_len); - -int32_t -gf_ibverbs_get_transport_identifiers (transport_t *this); - -#endif /* _IB_VERBS_NAME_H */ diff --git a/xlators/protocol/legacy/transport/socket/Makefile.am b/xlators/protocol/legacy/transport/socket/Makefile.am deleted file mode 100644 index f963effea22..00000000000 --- a/xlators/protocol/legacy/transport/socket/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = src
\ No newline at end of file diff --git a/xlators/protocol/legacy/transport/socket/src/Makefile.am b/xlators/protocol/legacy/transport/socket/src/Makefile.am deleted file mode 100644 index 5952e18e97b..00000000000 --- a/xlators/protocol/legacy/transport/socket/src/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ -# TODO : change to proper transport dir - -transport_LTLIBRARIES = socket.la -transportdir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/transport - -socket_la_LDFLAGS = -module -avoidversion - -socket_la_SOURCES = socket.c name.c -socket_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ -	$(top_builddir)/xlators/protocol/legacy/lib/src/libgfproto.la - -noinst_HEADERS = socket.h name.h socket-mem-types.h - -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\ -	-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \ -	-I$(top_srcdir)/xlators/protocol/legacy/transport/socket/src   \ -	-I$(top_srcdir)/xlators/protocol/legacy/lib/src - -CLEANFILES = *~ diff --git a/xlators/protocol/legacy/transport/socket/src/name.c b/xlators/protocol/legacy/transport/socket/src/name.c deleted file mode 100644 index 644a0bc5e12..00000000000 --- a/xlators/protocol/legacy/transport/socket/src/name.c +++ /dev/null @@ -1,740 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <errno.h> -#include <netdb.h> -#include <string.h> - -#ifdef CLIENT_PORT_CEILING -#undef CLIENT_PORT_CEILING -#endif - -#define CLIENT_PORT_CEILING 1024 - -#ifndef AF_INET_SDP -#define AF_INET_SDP 27 -#endif - -static int gf_name_addr_enotspec_log; - -#include "transport.h" -#include "socket.h" - -int32_t -gf_resolve_ip6 (const char *hostname,  -                uint16_t port,  -                int family,  -                void **dnscache,  -                struct addrinfo **addr_info); - -static int32_t -af_inet_bind_to_port_lt_ceiling (int fd, struct sockaddr *sockaddr,  -                                 socklen_t sockaddr_len, int ceiling) -{ -        int32_t ret = -1; -        /*  struct sockaddr_in sin = {0, }; */ -        uint16_t port = ceiling - 1; - -        while (port) -        { -                switch (sockaddr->sa_family) -                { -                case AF_INET6: -                        ((struct sockaddr_in6 *)sockaddr)->sin6_port = htons (port); -                        break; - -                case AF_INET_SDP: -                case AF_INET: -                        ((struct sockaddr_in *)sockaddr)->sin_port = htons (port); -                        break; -                } - -                ret = bind (fd, sockaddr, sockaddr_len); - -                if (ret == 0) -                        break; - -                if (ret == -1 && errno == EACCES) -                        break; - -                port--; -        } - -        return ret; -} - -static int32_t -af_unix_client_bind (transport_t *this,  -                     struct sockaddr *sockaddr,  -                     socklen_t sockaddr_len,  -                     int sock) -{ -        data_t *path_data = NULL; -        struct sockaddr_un *addr = NULL; -        int32_t ret = 0; - -        path_data = dict_get (this->xl->options, "transport.socket.bind-path"); -        if (path_data) { -                char *path = data_to_str (path_data); -                if (!path || strlen (path) > UNIX_PATH_MAX) { -                        gf_log (this->xl->name, GF_LOG_TRACE, -                                "bind-path not specfied for unix socket, " -                                "letting connect to assign default value"); -                        goto err; -                } - -                addr = (struct sockaddr_un *) sockaddr; -                strcpy (addr->sun_path, path); -                ret = bind (sock, (struct sockaddr *)addr, sockaddr_len); -                if (ret == -1) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "cannot bind to unix-domain socket %d (%s)",  -                                sock, strerror (errno)); -                        goto err; -                } -        } else { -                gf_log (this->xl->name, GF_LOG_TRACE, -                        "bind-path not specfied for unix socket, " -                        "letting connect to assign default value"); -        } - -err: -        return ret; -} - -static int32_t -client_fill_address_family (transport_t *this, sa_family_t *sa_family) -{ -        data_t  *address_family_data = NULL; -        int32_t  ret                 = -1; - -        if (sa_family == NULL) { -                goto out; -        } - -        address_family_data = dict_get (this->xl->options,  -                                        "transport.address-family"); -        if (!address_family_data) { -                data_t *remote_host_data = NULL, *connect_path_data = NULL; -                remote_host_data = dict_get (this->xl->options, "remote-host"); -                connect_path_data = dict_get (this->xl->options,  -                                              "transport.socket.connect-path"); - -                if (!(remote_host_data || connect_path_data) ||  -                    (remote_host_data && connect_path_data)) { -                        GF_LOG_OCCASIONALLY (gf_name_addr_enotspec_log,  -                                             this->xl->name, GF_LOG_ERROR, -                                             "transport.address-family not specified and " -                                             "not able to determine the " -                                             "same from other options (remote-host:%s and " -                                             "transport.unix.connect-path:%s)",  -                                             data_to_str (remote_host_data),  -                                             data_to_str (connect_path_data)); -                        goto out; -                }  - -                if (remote_host_data) { -                        gf_log (this->xl->name, GF_LOG_DEBUG, -                                "address-family not specified, guessing it " -                                "to be inet/inet6"); -                        *sa_family = AF_UNSPEC; -                } else { -                        gf_log (this->xl->name, GF_LOG_DEBUG, -                                "address-family not specified, guessing it " -                                "to be unix"); -                        *sa_family = AF_UNIX; -                } - -        } else { -                char *address_family = data_to_str (address_family_data); -                if (!strcasecmp (address_family, "unix")) { -                        *sa_family = AF_UNIX; -                } else if (!strcasecmp (address_family, "inet")) { -                        *sa_family = AF_INET; -                } else if (!strcasecmp (address_family, "inet6")) { -                        *sa_family = AF_INET6; -                } else if (!strcasecmp (address_family, "inet-sdp")) { -                        *sa_family = AF_INET_SDP; -                } else if (!strcasecmp (address_family, "inet/inet6") -                           || !strcasecmp (address_family, "inet6/inet")) { -                        *sa_family = AF_UNSPEC; -                } else { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "unknown address-family (%s) specified",  -                                address_family); -                        goto out; -                } -        } - -        ret = 0; - -out: -        return ret; -} - -static int32_t -af_inet_client_get_remote_sockaddr (transport_t *this,  -                                    struct sockaddr *sockaddr,  -                                    socklen_t *sockaddr_len) -{ -        dict_t *options = this->xl->options; -        data_t *remote_host_data = NULL; -        data_t *remote_port_data = NULL; -        char *remote_host = NULL; -        uint16_t remote_port = 0; -        struct addrinfo *addr_info = NULL; -        int32_t ret = 0; - -        remote_host_data = dict_get (options, "remote-host"); -        if (remote_host_data == NULL) -        { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "option remote-host missing in volume %s", this->xl->name); -                ret = -1; -                goto err; -        } - -        remote_host = data_to_str (remote_host_data); -        if (remote_host == NULL) -        { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "option remote-host has data NULL in volume %s", this->xl->name); -                ret = -1; -                goto err; -        } - -        remote_port_data = dict_get (options, "remote-port"); -        if (remote_port_data == NULL) -        { -                gf_log (this->xl->name, GF_LOG_TRACE, -                        "option remote-port missing in volume %s. Defaulting to %d", -                        this->xl->name, GF_DEFAULT_SOCKET_LISTEN_PORT); - -                remote_port = GF_DEFAULT_SOCKET_LISTEN_PORT; -        } -        else -        { -                remote_port = data_to_uint16 (remote_port_data); -        } - -        if (remote_port == (uint16_t)-1) -        { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "option remote-port has invalid port in volume %s", -                        this->xl->name); -                ret = -1; -                goto err; -        } - -        /* TODO: gf_resolve is a blocking call. kick in some -           non blocking dns techniques */ -        ret = gf_resolve_ip6 (remote_host, remote_port, -                              sockaddr->sa_family, &this->dnscache, &addr_info); -        if (ret == -1) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "DNS resolution failed on host %s", remote_host); -                goto err; -        } - -        memcpy (sockaddr, addr_info->ai_addr, addr_info->ai_addrlen); -        *sockaddr_len = addr_info->ai_addrlen; - -err: -        return ret; -} - -static int32_t -af_unix_client_get_remote_sockaddr (transport_t *this,  -                                    struct sockaddr *sockaddr,  -                                    socklen_t *sockaddr_len) -{ -        struct sockaddr_un *sockaddr_un = NULL; -        char *connect_path = NULL; -        data_t *connect_path_data = NULL; -        int32_t ret = 0; - -        connect_path_data = dict_get (this->xl->options,  -                                      "transport.socket.connect-path"); -        if (!connect_path_data) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "option transport.unix.connect-path not specified for " -                        "address-family unix"); -                ret = -1; -                goto err; -        } - -        connect_path = data_to_str (connect_path_data); -        if (!connect_path) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "transport.unix.connect-path is null-string"); -                ret = -1; -                goto err; -        } - -        if (strlen (connect_path) > UNIX_PATH_MAX) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "connect-path value length %"GF_PRI_SIZET" > %d octets",  -                        strlen (connect_path), UNIX_PATH_MAX); -                ret = -1; -                goto err; -        } - -        gf_log (this->xl->name, GF_LOG_TRACE, -                "using connect-path %s", connect_path); -        sockaddr_un = (struct sockaddr_un *)sockaddr; -        strcpy (sockaddr_un->sun_path, connect_path); -        *sockaddr_len = sizeof (struct sockaddr_un); - -err: -        return ret; -} - -static int32_t -af_unix_server_get_local_sockaddr (transport_t *this, -                                   struct sockaddr *addr, -                                   socklen_t *addr_len) -{ -        data_t *listen_path_data = NULL; -        char *listen_path = NULL; -        int32_t ret = 0; -        struct sockaddr_un *sunaddr = (struct sockaddr_un *)addr; - - -        listen_path_data = dict_get (this->xl->options,  -                                     "transport.socket.listen-path"); -        if (!listen_path_data) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "missing option transport.socket.listen-path"); -                ret = -1; -                goto err; -        } - -        listen_path = data_to_str (listen_path_data); - -#ifndef UNIX_PATH_MAX -#define UNIX_PATH_MAX 108 -#endif - -        if (strlen (listen_path) > UNIX_PATH_MAX) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "option transport.unix.listen-path has value length " -                        "%"GF_PRI_SIZET" > %d", -                        strlen (listen_path), UNIX_PATH_MAX); -                ret = -1; -                goto err; -        } - -        sunaddr->sun_family = AF_UNIX; -        strcpy (sunaddr->sun_path, listen_path); -        *addr_len = sizeof (struct sockaddr_un); - -err: -        return ret; -} - -static int32_t -af_inet_server_get_local_sockaddr (transport_t *this, -                                   struct sockaddr *addr, -                                   socklen_t *addr_len) -{ -        struct addrinfo hints, *res = 0; -        data_t *listen_port_data = NULL, *listen_host_data = NULL; -        uint16_t listen_port = -1; -        char service[NI_MAXSERV], *listen_host = NULL; -        dict_t *options = NULL; -        int32_t ret = 0; - -        options = this->xl->options; - -        listen_port_data = dict_get (options, "transport.socket.listen-port"); -        listen_host_data = dict_get (options, "transport.socket.bind-address"); - -        if (listen_port_data) -        { -                listen_port = data_to_uint16 (listen_port_data); -        } - -        if (listen_port == (uint16_t) -1) -                listen_port = GF_DEFAULT_SOCKET_LISTEN_PORT; - - -        if (listen_host_data) -        { -                listen_host = data_to_str (listen_host_data); -        } else { -		if (addr->sa_family == AF_INET6) { -			struct sockaddr_in6 *in = (struct sockaddr_in6 *) addr; -			in->sin6_addr = in6addr_any; -			in->sin6_port = htons(listen_port); -			*addr_len = sizeof(struct sockaddr_in6); -                        goto out; -		} else if (addr->sa_family == AF_INET) { -			struct sockaddr_in *in = (struct sockaddr_in *) addr; -			in->sin_addr.s_addr = htonl(INADDR_ANY); -			in->sin_port = htons(listen_port); -			*addr_len = sizeof(struct sockaddr_in); -			goto out; -		} -	} - -        memset (service, 0, sizeof (service)); -        sprintf (service, "%d", listen_port); - -        memset (&hints, 0, sizeof (hints)); -        hints.ai_family = addr->sa_family; -        hints.ai_socktype = SOCK_STREAM; -        hints.ai_flags    = AI_ADDRCONFIG | AI_PASSIVE; - -        ret = getaddrinfo(listen_host, service, &hints, &res); -        if (ret != 0) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "getaddrinfo failed for host %s, service %s (%s)",  -                        listen_host, service, gai_strerror (ret)); -                ret = -1; -                goto out; -        } - -        memcpy (addr, res->ai_addr, res->ai_addrlen); -        *addr_len = res->ai_addrlen; - -        freeaddrinfo (res); - -out: -        return ret; -} - -int32_t -gf_client_bind (transport_t *this, -             struct sockaddr *sockaddr, -             socklen_t *sockaddr_len, -             int sock) -{ -        int ret = 0; - -        *sockaddr_len = sizeof (struct sockaddr_in6); -        switch (sockaddr->sa_family) -        { -        case AF_INET_SDP: -        case AF_INET: -                *sockaddr_len = sizeof (struct sockaddr_in); - -        case AF_INET6: -                ret = af_inet_bind_to_port_lt_ceiling (sock, sockaddr,  -                                                       *sockaddr_len, CLIENT_PORT_CEILING); -                if (ret == -1) { -                        gf_log (this->xl->name, GF_LOG_WARNING, -                                "cannot bind inet socket (%d) to port less than %d (%s)",  -                                sock, CLIENT_PORT_CEILING, strerror (errno)); -                        ret = 0; -                } -                break; - -        case AF_UNIX: -                *sockaddr_len = sizeof (struct sockaddr_un); -                ret = af_unix_client_bind (this, (struct sockaddr *)sockaddr,  -                                           *sockaddr_len, sock); -                break; - -        default: -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "unknown address family %d", sockaddr->sa_family); -                ret = -1; -                break; -        } - -        return ret; -} - -int32_t -gf_socket_client_get_remote_sockaddr (transport_t *this, -                                   struct sockaddr *sockaddr, -                                   socklen_t *sockaddr_len, -                                   sa_family_t *sa_family) -{ -        int32_t ret = 0; - -        if ((sockaddr == NULL) || (sockaddr_len == NULL) -            || (sa_family == NULL)) { -                ret = -1; -                goto err; -        } - - -        ret = client_fill_address_family (this, &sockaddr->sa_family); -        if (ret) { -                ret = -1; -                goto err; -        } -  -        *sa_family = sockaddr->sa_family; - -        switch (sockaddr->sa_family) -        { -        case AF_INET_SDP: -                sockaddr->sa_family = AF_INET; - -        case AF_INET: -        case AF_INET6: -        case AF_UNSPEC: -                ret = af_inet_client_get_remote_sockaddr (this, sockaddr, -                                                          sockaddr_len); -                break; - -        case AF_UNIX: -                ret = af_unix_client_get_remote_sockaddr (this, sockaddr, -                                                          sockaddr_len); -                break; - -        default: -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "unknown address-family %d", sockaddr->sa_family); -                ret = -1; -        } -   -        if (*sa_family == AF_UNSPEC) { -                *sa_family = sockaddr->sa_family; -        } - -err: -        return ret; -} - - -static int32_t -server_fill_address_family (transport_t *this, sa_family_t *sa_family) -{ -        data_t  *address_family_data = NULL; -        int32_t  ret                 = -1; -         -        if (sa_family == NULL) { -                goto out; -        } - -        address_family_data = dict_get (this->xl->options,  -                                        "transport.address-family"); -        if (address_family_data) { -                char *address_family = NULL; -                address_family = data_to_str (address_family_data); - -                if (!strcasecmp (address_family, "inet")) { -                        *sa_family = AF_INET; -                } else if (!strcasecmp (address_family, "inet6")) { -                        *sa_family = AF_INET6; -                } else if (!strcasecmp (address_family, "inet-sdp")) { -                        *sa_family = AF_INET_SDP; -                } else if (!strcasecmp (address_family, "unix")) { -                        *sa_family = AF_UNIX; -                } else if (!strcasecmp (address_family, "inet/inet6") -                           || !strcasecmp (address_family, "inet6/inet")) { -                        *sa_family = AF_UNSPEC; -                } else { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "unknown address family (%s) specified", address_family); -                        goto out; -                } -        } else { -                gf_log (this->xl->name, GF_LOG_DEBUG, -                        "option address-family not specified, defaulting to inet/inet6"); -                *sa_family = AF_UNSPEC; -        } - -        ret = 0; -out: -        return ret; -} - - -int32_t -gf_socket_server_get_local_sockaddr (transport_t *this, struct sockaddr *addr, -                                  socklen_t *addr_len, sa_family_t *sa_family) -{ -        int32_t ret = -1; - -        if ((addr == NULL) || (addr_len == NULL) || (sa_family == NULL)) { -                goto err; -        } - -        ret = server_fill_address_family (this, &addr->sa_family); -        if (ret == -1) { -                goto err; -        } - -        *sa_family = addr->sa_family; - -        switch (addr->sa_family) -        { -        case AF_INET_SDP: -                addr->sa_family = AF_INET; - -        case AF_INET: -        case AF_INET6: -        case AF_UNSPEC: -                ret = af_inet_server_get_local_sockaddr (this, addr, addr_len); -                break; - -        case AF_UNIX: -                ret = af_unix_server_get_local_sockaddr (this, addr, addr_len); -                break; -        } - -        if (*sa_family == AF_UNSPEC) { -                *sa_family = addr->sa_family; -        } - -err: -        return ret; -} - -static int32_t -fill_inet6_inet_identifiers (transport_t *this, struct sockaddr_storage *addr, -                             int32_t addr_len, char *identifier) -{ -        int32_t ret = 0, tmpaddr_len = 0; -        char service[NI_MAXSERV], host[NI_MAXHOST]; -        struct sockaddr_storage tmpaddr; - -        memset (&tmpaddr, 0, sizeof (tmpaddr)); -        tmpaddr = *addr; -        tmpaddr_len = addr_len; - -        if (((struct sockaddr *) &tmpaddr)->sa_family == AF_INET6) { -                int32_t one_to_four, four_to_eight, twelve_to_sixteen; -                int16_t eight_to_ten, ten_to_twelve; -     -                one_to_four = four_to_eight = twelve_to_sixteen = 0; -                eight_to_ten = ten_to_twelve = 0; -     -                one_to_four = ((struct sockaddr_in6 *) &tmpaddr)->sin6_addr.s6_addr32[0]; -                four_to_eight = ((struct sockaddr_in6 *) &tmpaddr)->sin6_addr.s6_addr32[1]; -#ifdef GF_SOLARIS_HOST_OS -                eight_to_ten = S6_ADDR16(((struct sockaddr_in6 *) &tmpaddr)->sin6_addr)[4]; -#else -                eight_to_ten = ((struct sockaddr_in6 *) &tmpaddr)->sin6_addr.s6_addr16[4]; -#endif - -#ifdef GF_SOLARIS_HOST_OS -                ten_to_twelve = S6_ADDR16(((struct sockaddr_in6 *) &tmpaddr)->sin6_addr)[5]; -#else -                ten_to_twelve = ((struct sockaddr_in6 *) &tmpaddr)->sin6_addr.s6_addr16[5]; -#endif - -                twelve_to_sixteen = ((struct sockaddr_in6 *) &tmpaddr)->sin6_addr.s6_addr32[3]; - -                /* ipv4 mapped ipv6 address has -                   bits 0-80: 0 -                   bits 80-96: 0xffff -                   bits 96-128: ipv4 address  -                */ -  -                if (one_to_four == 0 && -                    four_to_eight == 0 && -                    eight_to_ten == 0 && -                    ten_to_twelve == -1) { -                        struct sockaddr_in *in_ptr = (struct sockaddr_in *)&tmpaddr; -                        memset (&tmpaddr, 0, sizeof (tmpaddr)); -       -                        in_ptr->sin_family = AF_INET; -                        in_ptr->sin_port = ((struct sockaddr_in6 *)addr)->sin6_port; -                        in_ptr->sin_addr.s_addr = twelve_to_sixteen; -                        tmpaddr_len = sizeof (*in_ptr); -                } -        } - -        ret = getnameinfo ((struct sockaddr *) &tmpaddr, -                           tmpaddr_len, -                           host, sizeof (host), -                           service, sizeof (service), -                           NI_NUMERICHOST | NI_NUMERICSERV); -        if (ret != 0) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "getnameinfo failed (%s)", gai_strerror (ret)); -        } - -        sprintf (identifier, "%s:%s", host, service); - -        return ret; -} - -int32_t -gf_get_transport_identifiers (transport_t *this) -{ -        int32_t ret = 0; -        char is_inet_sdp = 0; - -        switch (((struct sockaddr *) &this->myinfo.sockaddr)->sa_family) -        { -        case AF_INET_SDP: -                is_inet_sdp = 1; -                ((struct sockaddr *) &this->peerinfo.sockaddr)->sa_family = ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family = AF_INET; - -        case AF_INET: -        case AF_INET6: -        { -                ret = fill_inet6_inet_identifiers (this,  -                                                   &this->myinfo.sockaddr,  -                                                   this->myinfo.sockaddr_len, -                                                   this->myinfo.identifier); -                if (ret == -1) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "cannot fill inet/inet6 identifier for server"); -                        goto err; -                } - -                ret = fill_inet6_inet_identifiers (this, -                                                   &this->peerinfo.sockaddr, -                                                   this->peerinfo.sockaddr_len, -                                                   this->peerinfo.identifier); -                if (ret == -1) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "cannot fill inet/inet6 identifier for client"); -                        goto err; -                } - -                if (is_inet_sdp) { -                        ((struct sockaddr *) &this->peerinfo.sockaddr)->sa_family = ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family = AF_INET_SDP; -                } -        } -        break; - -        case AF_UNIX: -        { -                struct sockaddr_un *sunaddr = NULL; - -                sunaddr = (struct sockaddr_un *) &this->myinfo.sockaddr; -                strcpy (this->myinfo.identifier, sunaddr->sun_path); - -                sunaddr = (struct sockaddr_un *) &this->peerinfo.sockaddr; -                strcpy (this->peerinfo.identifier, sunaddr->sun_path); -        } -        break; - -        default: -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "unknown address family (%d)",  -                        ((struct sockaddr *) &this->myinfo.sockaddr)->sa_family); -                ret = -1; -                break; -        } - -err: -        return ret; -} diff --git a/xlators/protocol/legacy/transport/socket/src/name.h b/xlators/protocol/legacy/transport/socket/src/name.h deleted file mode 100644 index 789cf13ef54..00000000000 --- a/xlators/protocol/legacy/transport/socket/src/name.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _SOCKET_NAME_H -#define _SOCKET_NAME_H - -#include "compat.h" - -int32_t -gf_client_bind (transport_t *this, -                struct sockaddr *sockaddr, -                socklen_t *sockaddr_len, -                int sock); - -int32_t -gf_socket_client_get_remote_sockaddr (transport_t *this, -                                      struct sockaddr *sockaddr, -                                      socklen_t *sockaddr_len, -                                      sa_family_t *sa_family); - -int32_t -gf_socket_server_get_local_sockaddr (transport_t *this, struct sockaddr *addr, -                                     socklen_t *addr_len, sa_family_t *sa_family); - -int32_t -gf_get_transport_identifiers (transport_t *this); - -#endif /* _SOCKET_NAME_H */ diff --git a/xlators/protocol/legacy/transport/socket/src/socket-mem-types.h b/xlators/protocol/legacy/transport/socket/src/socket-mem-types.h deleted file mode 100644 index 937b9d7a83a..00000000000 --- a/xlators/protocol/legacy/transport/socket/src/socket-mem-types.h +++ /dev/null @@ -1,36 +0,0 @@ - -/* -   Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -   This file is part of GlusterFS. - -   GlusterFS is free software; you can redistribute it and/or modify -   it under the terms of the GNU General Public License as published -   by the Free Software Foundation; either version 3 of the License, -   or (at your option) any later version. - -   GlusterFS is distributed in the hope that it will be useful, but -   WITHOUT ANY WARRANTY; without even the implied warranty of -   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -   General Public License for more details. - -   You should have received a copy of the GNU General Public License -   along with this program.  If not, see -   <http://www.gnu.org/licenses/>. -*/ - - -#ifndef __SOCKET_MEM_TYPES_H__ -#define __SOCKET_MEM_TYPES_H__ - -#include "mem-types.h" - -enum gf_socket_mem_types_ { -        gf_socket_mt_socket_private_t = gf_common_mt_end + 1, -        gf_socket_mt_ioq, -        gf_socket_mt_transport_t, -        gf_socket_mt_socket_local_t, -        gf_socket_mt_char, -        gf_socket_mt_end -}; -#endif - diff --git a/xlators/protocol/legacy/transport/socket/src/socket.c b/xlators/protocol/legacy/transport/socket/src/socket.c deleted file mode 100644 index 9272b058494..00000000000 --- a/xlators/protocol/legacy/transport/socket/src/socket.c +++ /dev/null @@ -1,1625 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "socket.h" -#include "name.h" -#include "dict.h" -#include "transport.h" -#include "logging.h" -#include "xlator.h" -#include "byte-order.h" -#include "common-utils.h" -#include "compat-errno.h" - -#include <fcntl.h> -#include <errno.h> -#include <netinet/tcp.h> - - -#define GF_LOG_ERRNO(errno) ((errno == ENOTCONN) ? GF_LOG_DEBUG : GF_LOG_ERROR) -#define SA(ptr) ((struct sockaddr *)ptr) - -static int socket_init (transport_t *this); - -/* - * return value: - *   0 = success (completed) - *  -1 = error - * > 0 = incomplete - */ - -static int -__socket_rwv (transport_t *this, struct iovec *vector, int count, -              struct iovec **pending_vector, int *pending_count, -              int write) -{ -        socket_private_t *priv = NULL; -        int               sock = -1; -        int               ret = -1; -        struct iovec     *opvector = NULL; -        int               opcount = 0; -        int               moved = 0; - -        priv = this->private; -        sock = priv->sock; - -	opvector = vector; -	opcount  = count; - -        while (opcount) { -                if (write) { -                        ret = writev (sock, opvector, opcount); - -                        if (ret == 0 || (ret == -1 && errno == EAGAIN)) { -                                /* done for now */ -                                break; -                        } -                } else { -                        ret = readv (sock, opvector, opcount); - -                        if (ret == -1 && errno == EAGAIN) { -                                /* done for now */ -                                break; -                        } -                } - -                if (ret == 0) { -                        /* Mostly due to 'umount' in client */ -                        gf_log (this->xl->name, GF_LOG_TRACE, -                                "EOF from peer %s", this->peerinfo.identifier); -                        opcount = -1; -                        errno = ENOTCONN; -                        break; -                } - -                if (ret == -1) { -                        if (errno == EINTR) -                                continue; - -                        gf_log (this->xl->name, GF_LOG_TRACE, -                                "%s failed (%s)", write ? "writev" : "readv", -                                strerror (errno)); -                        opcount = -1; -                        break; -                } - -                moved = 0; - -                while (moved < ret) { -                        if ((ret - moved) >= opvector[0].iov_len) { -                                moved += opvector[0].iov_len; -                                opvector++; -                                opcount--; -                        } else { -                                opvector[0].iov_len -= (ret - moved); -                                opvector[0].iov_base += (ret - moved); -                                moved += (ret - moved); -                        } -                        while (opcount && !opvector[0].iov_len) { -                                opvector++; -                                opcount--; -                        } -                } -        } - -        if (pending_vector) -                *pending_vector = opvector; - -        if (pending_count) -                *pending_count = opcount; - -        return opcount; -} - - -static int -__socket_readv (transport_t *this, struct iovec *vector, int count, -                struct iovec **pending_vector, int *pending_count) -{ -        int ret = -1; - -        ret = __socket_rwv (this, vector, count, -			    pending_vector, pending_count, 0); - -        return ret; -} - - -static int -__socket_writev (transport_t *this, struct iovec *vector, int count, -                 struct iovec **pending_vector, int *pending_count) -{ -        int ret = -1; - -        ret = __socket_rwv (this, vector, count, -			    pending_vector, pending_count, 1); - -        return ret; -} - - -static int -__socket_disconnect (transport_t *this) -{ -        socket_private_t *priv = NULL; -        int               ret = -1; - -        priv = this->private; - -        if (priv->sock != -1) { -                ret = shutdown (priv->sock, SHUT_RDWR); -                priv->connected = -1; -                gf_log (this->xl->name, GF_LOG_TRACE, -                        "shutdown() returned %d. set connection state to -1", -                        ret); -        } - -        return ret; -} - - -static int -__socket_server_bind (transport_t *this) -{ -        socket_private_t *priv = NULL; -        int               ret = -1; -	int               opt = 1; - -	priv = this->private; - -        ret = setsockopt (priv->sock, SOL_SOCKET, SO_REUSEADDR, -			  &opt, sizeof (opt)); - -        if (ret == -1) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "setsockopt() for SO_REUSEADDR failed (%s)", -                        strerror (errno)); -        } - -        ret = bind (priv->sock, (struct sockaddr *)&this->myinfo.sockaddr, -		    this->myinfo.sockaddr_len); - -        if (ret == -1) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "binding to %s failed: %s", -                        this->myinfo.identifier, strerror (errno)); -                if (errno == EADDRINUSE) { -                        gf_log (this->xl->name, GF_LOG_ERROR,  -                                "Port is already in use"); -                } -        } - -        return ret; -} - - -static int -__socket_nonblock (int fd) -{ -        int flags = 0; -        int ret = -1; - -        flags = fcntl (fd, F_GETFL); - -        if (flags != -1) -                ret = fcntl (fd, F_SETFL, flags | O_NONBLOCK); - -        return ret; -} - - -static int -__socket_nodelay (int fd) -{ -        int     on = 1; -        int     ret = -1; - -        ret = setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, -			  &on, sizeof (on)); -        if (!ret) -                gf_log ("", GF_LOG_TRACE, -                        "NODELAY enabled for socket %d", fd); - -        return ret; -} - - -static int -__socket_keepalive (int fd, int keepalive_intvl) -{ -        int     on = 1; -        int     ret = -1; - -        ret = setsockopt (fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof (on)); -        if (ret == -1) -                goto err; - -        if (keepalive_intvl == GF_USE_DEFAULT_KEEPALIVE) -                goto done; - -#ifndef GF_LINUX_HOST_OS -        ret = setsockopt (fd, IPPROTO_TCP, TCP_KEEPALIVE, &keepalive_intvl, -                          sizeof (keepalive_intvl)); -        if (ret == -1) -                goto err; -#else -        ret = setsockopt (fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepalive_intvl, -                          sizeof (keepalive_intvl)); -        if (ret == -1) -                goto err; - -        ret = setsockopt (fd, IPPROTO_TCP, TCP_KEEPINTVL, &keepalive_intvl, -                          sizeof (keepalive_intvl)); -        if (ret == -1) -                goto err; -#endif - -done: -        gf_log ("", GF_LOG_TRACE, "Keep-alive enabled for socket %d, interval " -                "%d", fd, keepalive_intvl); - -err: -        return ret; -} - - -static int -__socket_connect_finish (int fd) -{ -        int       ret = -1; -        int       optval = 0; -        socklen_t optlen = sizeof (int); - -        ret = getsockopt (fd, SOL_SOCKET, SO_ERROR, (void *)&optval, &optlen); - -        if (ret == 0 && optval) { -                errno = optval; -                ret = -1; -        } - -        return ret; -} - - -static void -__socket_reset (transport_t *this) -{ -        socket_private_t *priv = NULL; - -        priv = this->private; - -        /* TODO: use mem-pool on incoming data */ - -        if (priv->incoming.hdr_p) -                GF_FREE (priv->incoming.hdr_p); - -        if (priv->incoming.iobuf) -                iobuf_unref (priv->incoming.iobuf); - -        memset (&priv->incoming, 0, sizeof (priv->incoming)); - -        event_unregister (this->xl->ctx->event_pool, priv->sock, priv->idx); -        close (priv->sock); -        priv->sock = -1; -        priv->idx = -1; -        priv->connected = -1; -} - - -static struct ioq * -__socket_ioq_new (transport_t *this, char *buf, int len, -                  struct iovec *vector, int count, struct iobref *iobref) -{ -        socket_private_t *priv = NULL; -        struct ioq       *entry = NULL; - -        priv = this->private; - -        /* TODO: use mem-pool */ -        entry = GF_CALLOC (1, sizeof (*entry), -                           gf_common_mt_ioq); -        if (!entry) -                return NULL; - -        GF_ASSERT (count <= (MAX_IOVEC-2)); - -        entry->header.colonO[0] = ':'; -        entry->header.colonO[1] = 'O'; -        entry->header.colonO[2] = '\0'; -        entry->header.version   = 42; -        entry->header.size1     = hton32 (len); -        entry->header.size2     = hton32 (iov_length (vector, count)); - -        entry->vector[0].iov_base = &entry->header; -        entry->vector[0].iov_len  = sizeof (entry->header); -        entry->count++; - -        entry->vector[1].iov_base = buf; -        entry->vector[1].iov_len  = len; -        entry->count++; - -        if (vector && count) { -                memcpy (&entry->vector[2], vector, sizeof (*vector) * count); -                entry->count += count; -        } - -        entry->pending_vector = entry->vector; -        entry->pending_count  = entry->count; - -        if (iobref) -                entry->iobref = iobref_ref (iobref); - -        entry->buf = buf; - -        INIT_LIST_HEAD (&entry->list); - -        return entry; -} - - -static void -__socket_ioq_entry_free (struct ioq *entry) -{ -        list_del_init (&entry->list); -        if (entry->iobref) -                iobref_unref (entry->iobref); - -        /* TODO: use mem-pool */ -        GF_FREE (entry->buf); - -        /* TODO: use mem-pool */ -        GF_FREE (entry); -} - - -static void -__socket_ioq_flush (transport_t *this) -{ -        socket_private_t *priv = NULL; -        struct ioq       *entry = NULL; - -        priv = this->private; - -        while (!list_empty (&priv->ioq)) { -                entry = priv->ioq_next; -                __socket_ioq_entry_free (entry); -        } - -        return; -} - - -static int -__socket_ioq_churn_entry (transport_t *this, struct ioq *entry) -{ -        int ret = -1; - -        ret = __socket_writev (this, entry->pending_vector, -			       entry->pending_count, -                               &entry->pending_vector, -			       &entry->pending_count); - -        if (ret == 0) { -                /* current entry was completely written */ -                GF_ASSERT (entry->pending_count == 0); -                __socket_ioq_entry_free (entry); -        } - -        return ret; -} - - -static int -__socket_ioq_churn (transport_t *this) -{ -        socket_private_t *priv = NULL; -        int               ret = 0; -        struct ioq       *entry = NULL; - -        priv = this->private; - -        while (!list_empty (&priv->ioq)) { -                /* pick next entry */ -                entry = priv->ioq_next; - -                ret = __socket_ioq_churn_entry (this, entry); - -                if (ret != 0) -                        break; -        } - -        if (list_empty (&priv->ioq)) { -                /* all pending writes done, not interested in POLLOUT */ -                priv->idx = event_select_on (this->xl->ctx->event_pool, -					     priv->sock, priv->idx, -1, 0); -        } - -        return ret; -} - - -static int -socket_event_poll_err (transport_t *this) -{ -        socket_private_t *priv = NULL; -        int               ret = -1; - -        priv = this->private; - -        pthread_mutex_lock (&priv->lock); -        { -                __socket_ioq_flush (this); -                __socket_reset (this); -        } -        pthread_mutex_unlock (&priv->lock); - -        xlator_notify (this->xl, GF_EVENT_POLLERR, this); - -        return ret; -} - - -static int -socket_event_poll_out (transport_t *this) -{ -        socket_private_t *priv = NULL; -        int               ret = -1; - -        priv = this->private; - -        pthread_mutex_lock (&priv->lock); -        { -                if (priv->connected == 1) { -                        ret = __socket_ioq_churn (this); - -                        if (ret == -1) { -                                __socket_disconnect (this); -                        } -                } -        } -        pthread_mutex_unlock (&priv->lock); - -        xlator_notify (this->xl, GF_EVENT_POLLOUT, this); - -        return ret; -} - - -static int -__socket_proto_validate_header (transport_t *this, -				struct socket_header *header, -				size_t *size1_p, size_t *size2_p) -{ -        size_t size1 = 0; -	size_t size2 = 0; - -        if (strcmp (header->colonO, ":O")) { -                gf_log (this->xl->name, GF_LOG_DEBUG, -                        "socket header signature does not match :O (%x.%x.%x)", -                        header->colonO[0], header->colonO[1], -			header->colonO[2]); -                return -1; -        } - -        if (header->version != 42) { -                gf_log (this->xl->name, GF_LOG_DEBUG, -                        "socket header version does not match 42 != %d", -			header->version); -                return -1; -        } - -        size1 = ntoh32 (header->size1); -        size2 = ntoh32 (header->size2); - -        if (size1 <= 0 || size1 > 1048576) { -                gf_log (this->xl->name, GF_LOG_DEBUG, -                        "socket header has incorrect size1=%"GF_PRI_SIZET, -			size1); -                return -1; -        } - -        if (size2 > (131072)) { -                gf_log (this->xl->name, GF_LOG_DEBUG, -                        "socket header has incorrect size2=%"GF_PRI_SIZET, -			size2); -                return -1; -        } - -        if (size1_p) -                *size1_p = size1; - -        if (size2_p) -                *size2_p = size2; - -        return 0; -} - - - -/* socket protocol state machine */ - -static int -__socket_proto_state_machine (transport_t *this) -{ -        int                   ret = -1; -        socket_private_t     *priv = NULL; -        size_t                size1 = 0; -	size_t                size2 = 0; -        int                   previous_state = -1; -	struct socket_header *hdr = NULL; -        struct iobuf         *iobuf = NULL; - - -        priv = this->private; - -	while (priv->incoming.state != SOCKET_PROTO_STATE_COMPLETE) { -		/* debug check against infinite loops */ -		if (previous_state == priv->incoming.state) { -			gf_log (this->xl->name, GF_LOG_DEBUG, -				"state did not change! (%d) breaking", -				previous_state); -			ret = -1; -			goto unlock; -		} -		previous_state = priv->incoming.state; - -		switch (priv->incoming.state) { - -		case SOCKET_PROTO_STATE_NADA: -			priv->incoming.pending_vector = -				priv->incoming.vector; - -			priv->incoming.pending_vector->iov_base = -				&priv->incoming.header; - -			priv->incoming.pending_vector->iov_len  = -				sizeof (struct socket_header); - -			priv->incoming.state = -				SOCKET_PROTO_STATE_HEADER_COMING; -			break; - -		case SOCKET_PROTO_STATE_HEADER_COMING: - -			ret = __socket_readv (this, -					      priv->incoming.pending_vector, 1, -					      &priv->incoming.pending_vector, -					      NULL); -			if (ret == 0) { -				priv->incoming.state = -					SOCKET_PROTO_STATE_HEADER_CAME; -				break; -			} - -			if (ret == -1) { -				gf_log (this->xl->name, GF_LOG_TRACE, -					"read (%s) in state %d (%s)", -					strerror (errno), -					SOCKET_PROTO_STATE_HEADER_COMING,  -					this->peerinfo.identifier); -				goto unlock; -			} - -			if (ret > 0) { -				gf_log (this->xl->name, GF_LOG_TRACE, -					"partial header read on NB socket."); -				goto unlock; -			} -			break; - -		case SOCKET_PROTO_STATE_HEADER_CAME: -			hdr = &priv->incoming.header; -			ret = __socket_proto_validate_header (this, hdr, -							      &size1, &size2); - -			if (ret == -1) { -				gf_log (this->xl->name, GF_LOG_ERROR, -					"socket header validate failed (%s). " -					"possible mismatch of transport-type " -					"between server and client volumes, " -					"or version mismatch", -					this->peerinfo.identifier); -                                        goto unlock; -                        } - -                        priv->incoming.hdrlen = size1; -                        priv->incoming.buflen = size2; - -                        /* TODO: use mem-pool */ -                        priv->incoming.hdr_p  = GF_MALLOC (size1,  -                                                           gf_common_mt_char); -                        if (size2) { -                                /* TODO: sanity check size2 < page size -                                 */ -                                iobuf = iobuf_get (this->xl->ctx->iobuf_pool); -                                if (!iobuf) { -                                        gf_log (this->xl->name, GF_LOG_ERROR, -                                                "unable to allocate IO buffer " -                                                "for peer %s", -                                                this->peerinfo.identifier); -                                        ret = -ENOMEM; -                                        goto unlock; -                                } -                                priv->incoming.iobuf = iobuf; -                                priv->incoming.buf_p = iobuf->ptr; -                        } - -                        priv->incoming.vector[0].iov_base = -                                priv->incoming.hdr_p; - -                        priv->incoming.vector[0].iov_len  = size1; - -                        priv->incoming.vector[1].iov_base = -                                priv->incoming.buf_p; - -                        priv->incoming.vector[1].iov_len  = size2; -                        priv->incoming.count = size2 ? 2 : 1; - -                        priv->incoming.pending_vector = -                                priv->incoming.vector; - -                        priv->incoming.pending_count  = -                                priv->incoming.count; - -                        priv->incoming.state = -                                SOCKET_PROTO_STATE_DATA_COMING; -                        break; - -		case SOCKET_PROTO_STATE_DATA_COMING: - -			ret = __socket_readv (this, -					      priv->incoming.pending_vector, -					      priv->incoming.pending_count, -					      &priv->incoming.pending_vector, -					      &priv->incoming.pending_count); -			if (ret == 0) { -				priv->incoming.state = -					SOCKET_PROTO_STATE_DATA_CAME; -				break; -			} - -			if (ret == -1) { -				gf_log (this->xl->name, GF_LOG_DEBUG, -					"read (%s) in state %d (%s)", -					strerror (errno), -					SOCKET_PROTO_STATE_DATA_COMING, -					this->peerinfo.identifier); -				goto unlock; -			} - -			if (ret > 0) { -				gf_log (this->xl->name, GF_LOG_TRACE, -					"partial data read on NB socket"); -                                        goto unlock; -			} -			break; - -		case SOCKET_PROTO_STATE_DATA_CAME: -			memset (&priv->incoming.vector, 0, -				sizeof (priv->incoming.vector)); -			priv->incoming.pending_vector = NULL; -			priv->incoming.pending_count  = 0; -			priv->incoming.state = SOCKET_PROTO_STATE_COMPLETE; -			break; - -		case SOCKET_PROTO_STATE_COMPLETE: -			/* not reached */ -			break; - -		default: -			gf_log (this->xl->name, GF_LOG_DEBUG, -				"undefined state reached: %d", -				priv->incoming.state); -                                goto unlock; -		} -	} -unlock: - -        return ret; -} - - -static int -socket_proto_state_machine (transport_t *this) -{ -        socket_private_t *priv = NULL; -	int               ret = 0; - -	priv = this->private; - -	pthread_mutex_lock (&priv->lock); -	{ -		ret = __socket_proto_state_machine (this); -	} -        pthread_mutex_unlock (&priv->lock); - -	return ret; -} - - -static int -socket_event_poll_in (transport_t *this) -{ -        int ret = -1; - -        ret = socket_proto_state_machine (this); - -        /* call POLLIN on xlator even if complete block is not received, -           just to keep the last_received timestamp ticking */ - -        if (ret == 0) -                ret = xlator_notify (this->xl, GF_EVENT_POLLIN, this); - -        return ret; -} - - -static int -socket_connect_finish (transport_t *this) -{ -        int               ret = -1; -        socket_private_t *priv = NULL; -        int               event = -1; -        char              notify_xlator = 0; - -        priv = this->private; - -        pthread_mutex_lock (&priv->lock); -        { -		if (priv->connected) -			goto unlock; - -		ret = __socket_connect_finish (priv->sock); - -		if (ret == -1 && errno == EINPROGRESS) -			ret = 1; - -		if (ret == -1 && errno != EINPROGRESS) { -			if (!priv->connect_finish_log) { -				gf_log (this->xl->name, GF_LOG_ERROR, -					"connection to %s failed (%s)", -                                        this->peerinfo.identifier, -					strerror (errno)); -				priv->connect_finish_log = 1; -			} -			__socket_disconnect (this); -			notify_xlator = 1; -			event = GF_EVENT_POLLERR; -			goto unlock; -		} - -		if (ret == 0) { -			notify_xlator = 1; - -			this->myinfo.sockaddr_len = -				sizeof (this->myinfo.sockaddr); - -			ret = getsockname (priv->sock, -					   SA (&this->myinfo.sockaddr), -					   &this->myinfo.sockaddr_len); -			if (ret == -1) { -				gf_log (this->xl->name, GF_LOG_DEBUG, -					"getsockname on (%d) failed (%s)",  -					priv->sock, strerror (errno)); -				__socket_disconnect (this); -				event = GF_EVENT_POLLERR; -				goto unlock; -			} - -			priv->connected = 1; -			priv->connect_finish_log = 0; -			event = GF_EVENT_CHILD_UP; -			gf_get_transport_identifiers (this); -		} -        } -unlock: -        pthread_mutex_unlock (&priv->lock); - -        if (notify_xlator) -                xlator_notify (this->xl, event, this); - -        return 0; -} - - -static int -socket_event_handler (int fd, int idx, void *data, -                      int poll_in, int poll_out, int poll_err) -{ -        transport_t      *this = NULL; -        socket_private_t *priv = NULL; -        int               ret = 0; - -        this = data; -        priv = this->private; - -        pthread_mutex_lock (&priv->lock); -        { -                priv->idx = idx; -        } -        pthread_mutex_unlock (&priv->lock); - -        if (!priv->connected) { -                ret = socket_connect_finish (this); -        } - -        if (!ret && poll_out) { -                ret = socket_event_poll_out (this); -        } - -        if (!ret && poll_in) { -                ret = socket_event_poll_in (this); -        } - -        if (ret < 0 || poll_err) { -                socket_event_poll_err (this); -                transport_unref (this); -        } - -        return 0; -} - - -static int -socket_server_event_handler (int fd, int idx, void *data, -                             int poll_in, int poll_out, int poll_err) -{ -        transport_t             *this = NULL; -        socket_private_t        *priv = NULL; -        int                      ret = 0; -        int                      new_sock = -1; -        transport_t             *new_trans = NULL; -        struct sockaddr_storage  new_sockaddr = {0, }; -        socklen_t                addrlen = sizeof (new_sockaddr); -        socket_private_t        *new_priv = NULL; -	glusterfs_ctx_t         *ctx = NULL; - -        this = data; -        priv = this->private; -	ctx  = this->xl->ctx; - -        pthread_mutex_lock (&priv->lock); -        { -                priv->idx = idx; - -                if (poll_in) { -                        new_sock = accept (priv->sock, SA (&new_sockaddr), -					   &addrlen); - -                        if (new_sock == -1) -                                goto unlock; - -                        if (!priv->bio) { -                                ret = __socket_nonblock (new_sock); - -                                if (ret == -1) { -                                        gf_log (this->xl->name, GF_LOG_DEBUG, -                                                "NBIO on %d failed (%s)", -                                                new_sock, strerror (errno)); -                                        close (new_sock); -                                        goto unlock; -                                } -                        } - -                        if (priv->nodelay) { -                                ret = __socket_nodelay (new_sock); -                                if (ret == -1) { -                                        gf_log (this->xl->name, GF_LOG_ERROR, -                                                "setsockopt() failed for " -                                                "NODELAY (%s)", -                                                strerror (errno)); -                                } -                        } - -                        if (priv->keepalive) { -                                ret = __socket_keepalive (new_sock, -                                                          priv->keepaliveintvl); -                                if (ret == -1) -                                        gf_log (this->xl->name, GF_LOG_ERROR, -                                                "Failed to set keep-alive: %s", -                                                strerror (errno)); -                        } - -                        new_trans = GF_CALLOC (1, sizeof (*new_trans),  -                                               gf_common_mt_transport_t); -                        new_trans->xl = this->xl; -                        new_trans->fini = this->fini; - -                        memcpy (&new_trans->peerinfo.sockaddr, &new_sockaddr, -				addrlen); -                        new_trans->peerinfo.sockaddr_len = addrlen; - -                        new_trans->myinfo.sockaddr_len = -				sizeof (new_trans->myinfo.sockaddr); - -                        ret = getsockname (new_sock,  -                                           SA (&new_trans->myinfo.sockaddr), -                                           &new_trans->myinfo.sockaddr_len); -                        if (ret == -1) { -                                gf_log (this->xl->name, GF_LOG_DEBUG, -                                        "getsockname on %d failed (%s)",  -                                        new_sock, strerror (errno)); -                                close (new_sock); -                                goto unlock; -                        } - -                        gf_get_transport_identifiers (new_trans); -                        socket_init (new_trans); -                        new_trans->ops = this->ops; -                        new_trans->init = this->init; -                        new_trans->fini = this->fini; - -                        new_priv = new_trans->private; - -                        pthread_mutex_lock (&new_priv->lock); -                        { -                                new_priv->sock = new_sock; -                                new_priv->connected = 1; -         -                                transport_ref (new_trans); -                                new_priv->idx = -					event_register (ctx->event_pool, -							new_sock, -							socket_event_handler, -							new_trans, 1, 0); - -                                if (new_priv->idx == -1) -                                        ret = -1; -                        } -                        pthread_mutex_unlock (&new_priv->lock); -                } -        } -unlock: -        pthread_mutex_unlock (&priv->lock); - -        return ret; -} - - -static int -socket_disconnect (transport_t *this) -{ -        socket_private_t *priv = NULL; -        int               ret = -1; - -        priv = this->private; - -        pthread_mutex_lock (&priv->lock); -        { -                ret = __socket_disconnect (this); -        } -        pthread_mutex_unlock (&priv->lock); - -        return ret; -} - - -static int -socket_connect (transport_t *this) -{ -        int                      ret = -1; -	int                      sock = -1; -        socket_private_t        *priv = NULL; -        struct sockaddr_storage  sockaddr = {0, }; -        socklen_t                sockaddr_len = 0; -	glusterfs_ctx_t         *ctx = NULL; -        sa_family_t              sa_family = {0, }; - -        priv = this->private; -	ctx = this->xl->ctx; - -        if (!priv) { -                gf_log (this->xl->name, GF_LOG_DEBUG, -                        "connect() called on uninitialized transport"); -                goto err; -        } - -        pthread_mutex_lock (&priv->lock); -        { -                sock = priv->sock; -        } -        pthread_mutex_unlock (&priv->lock); - -        if (sock != -1) { -                gf_log (this->xl->name, GF_LOG_TRACE, -                        "connect () called on transport already connected"); -                ret = 0; -                goto err; -        } - -        ret = gf_socket_client_get_remote_sockaddr (this, SA (&sockaddr), -                                                 &sockaddr_len, &sa_family); -        if (ret == -1) { -                /* logged inside client_get_remote_sockaddr */ -                goto err; -        } - -        pthread_mutex_lock (&priv->lock); -        { -                if (priv->sock != -1) { -                        gf_log (this->xl->name, GF_LOG_TRACE, -                                "connect() -- already connected"); -                        goto unlock; -                } - -                memcpy (&this->peerinfo.sockaddr, &sockaddr, sockaddr_len); -                this->peerinfo.sockaddr_len = sockaddr_len; - -                priv->sock = socket (sa_family, SOCK_STREAM, 0); -                if (priv->sock == -1) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "socket creation failed (%s)", -				strerror (errno)); -                        goto unlock; -                } - -                /* Cant help if setting socket options fails. We can continue -                 * working nonetheless. -                 */ -                if (setsockopt (priv->sock, SOL_SOCKET, SO_RCVBUF, -                                &priv->windowsize, -                                sizeof (priv->windowsize)) < 0) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "setting receive window size failed: %d: %d: " -                                "%s", priv->sock, priv->windowsize, -                                strerror (errno)); -                } - -                if (setsockopt (priv->sock, SOL_SOCKET, SO_SNDBUF, -                                &priv->windowsize, -                                sizeof (priv->windowsize)) < 0) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "setting send window size failed: %d: %d: " -                                "%s", priv->sock, priv->windowsize, -                                strerror (errno)); -                } - - -                if (priv->nodelay && priv->lowlat) { -                        ret = __socket_nodelay (priv->sock); -                        if (ret == -1) { -                                gf_log (this->xl->name, GF_LOG_ERROR, -                                        "setsockopt() failed for NODELAY (%s)", -                                        strerror (errno)); -                        } -                } - -                if (!priv->bio) { -                        ret = __socket_nonblock (priv->sock); - -                        if (ret == -1) { -                                gf_log (this->xl->name, GF_LOG_ERROR, -                                        "NBIO on %d failed (%s)", -                                        priv->sock, strerror (errno)); -                                close (priv->sock); -                                priv->sock = -1; -                                goto unlock; -                        } -                } - -                if (priv->keepalive) { -                        ret = __socket_keepalive (priv->sock, -                                                  priv->keepaliveintvl); -                        if (ret == -1) -                                gf_log (this->xl->name, GF_LOG_ERROR, -                                        "Failed to set keep-alive: %s", -                                        strerror (errno)); -                } - -                SA (&this->myinfo.sockaddr)->sa_family = -			SA (&this->peerinfo.sockaddr)->sa_family; - -                ret = gf_client_bind (this, SA (&this->myinfo.sockaddr), -				   &this->myinfo.sockaddr_len, priv->sock); -                if (ret == -1) { -                        gf_log (this->xl->name, GF_LOG_WARNING, -                                "client bind failed: %s", strerror (errno)); -                        close (priv->sock); -                        priv->sock = -1; -                        goto unlock; -                } - -                ret = connect (priv->sock, SA (&this->peerinfo.sockaddr), -			       this->peerinfo.sockaddr_len); - -                if (ret == -1 && errno != EINPROGRESS) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "connection attempt failed (%s)", -				strerror (errno)); -                        close (priv->sock); -                        priv->sock = -1; -                        goto unlock; -                } - -                priv->connected = 0; - -                transport_ref (this); - -                priv->idx = event_register (ctx->event_pool, priv->sock, -                                            socket_event_handler, this, 1, 1); -                if (priv->idx == -1) -                        ret = -1; -        } -unlock: -        pthread_mutex_unlock (&priv->lock); - -err: -        return ret; -} - - -static int -socket_listen (transport_t *this) -{ -        socket_private_t *       priv = NULL; -        int                      ret = -1; -	int                      sock = -1; -        struct sockaddr_storage  sockaddr; -        socklen_t                sockaddr_len; -        peer_info_t             *myinfo = NULL; -	glusterfs_ctx_t         *ctx = NULL; -        sa_family_t              sa_family = {0, }; - -	priv   = this->private; -	myinfo = &this->myinfo; -	ctx    = this->xl->ctx; - -        pthread_mutex_lock (&priv->lock); -        { -                sock = priv->sock; -        } -        pthread_mutex_unlock (&priv->lock); - -        if (sock != -1)  { -                gf_log (this->xl->name, GF_LOG_DEBUG, -                        "already listening"); -                return ret; -        } - -        ret = gf_socket_server_get_local_sockaddr (this, SA (&sockaddr), -                                                &sockaddr_len, &sa_family); -        if (ret == -1) { -                return ret; -        } - -        pthread_mutex_lock (&priv->lock); -        { -                if (priv->sock != -1) { -                        gf_log (this->xl->name, GF_LOG_DEBUG, -                                "already listening"); -                        goto unlock; -                } - -                memcpy (&myinfo->sockaddr, &sockaddr, sockaddr_len); -                myinfo->sockaddr_len = sockaddr_len; - -                priv->sock = socket (sa_family, SOCK_STREAM, 0); - -                if (priv->sock == -1) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "socket creation failed (%s)", -				strerror (errno)); -                        goto unlock; -                } - -                /* Cant help if setting socket options fails. We can continue -                 * working nonetheless. -                 */ -                if (setsockopt (priv->sock, SOL_SOCKET, SO_RCVBUF, -                                &priv->windowsize, -                                sizeof (priv->windowsize)) < 0) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "setting receive window size failed: %d: %d: " -                                "%s", priv->sock, priv->windowsize, -                                strerror (errno)); -                } - -                if (setsockopt (priv->sock, SOL_SOCKET, SO_SNDBUF, -                                &priv->windowsize, -                                sizeof (priv->windowsize)) < 0) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                               "setting send window size failed: %d: %d: " -                                "%s", priv->sock, priv->windowsize, -                                strerror (errno)); -                } - -                if (priv->nodelay) { -                        ret = __socket_nodelay (priv->sock); -                        if (ret == -1) { -                                gf_log (this->xl->name, GF_LOG_ERROR, -                                        "setsockopt() failed for NODELAY (%s)", -                                        strerror (errno)); -                        } -                } - -                if (!priv->bio) { -                        ret = __socket_nonblock (priv->sock); - -                        if (ret == -1) { -                                gf_log (this->xl->name, GF_LOG_ERROR, -                                        "NBIO on %d failed (%s)", -                                        priv->sock, strerror (errno)); -                                close (priv->sock); -                                priv->sock = -1; -                                goto unlock; -                        } -                } - -                ret = __socket_server_bind (this); - -                if (ret == -1) { -                        /* logged inside __socket_server_bind() */ -                        close (priv->sock); -                        priv->sock = -1; -                        goto unlock; -                } - -                ret = listen (priv->sock, 10); - -                if (ret == -1) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "could not set socket %d to listen mode (%s)", -				priv->sock, strerror (errno)); -                        close (priv->sock); -                        priv->sock = -1; -                        goto unlock; -                } - -                transport_ref (this); - -                priv->idx = event_register (ctx->event_pool, priv->sock, -                                            socket_server_event_handler, -					    this, 1, 0); - -                if (priv->idx == -1) { -                        gf_log (this->xl->name, GF_LOG_DEBUG, -                                "could not register socket %d with events", -				priv->sock); -                        ret = -1; -                        close (priv->sock); -                        priv->sock = -1; -                        goto unlock; -                } -        } -unlock: -        pthread_mutex_unlock (&priv->lock); - -        return ret; -} - - -static int -socket_receive (transport_t *this, char **hdr_p, size_t *hdrlen_p, -                struct iobuf **iobuf_p) -{ -        socket_private_t *priv = NULL; -        int               ret = -1; - -        priv = this->private; - -        pthread_mutex_lock (&priv->lock); -        { -                if (priv->connected != 1) { -                        gf_log (this->xl->name, GF_LOG_DEBUG, -                                "socket not connected to receive"); -                        goto unlock; -                } - -                if (!hdr_p || !hdrlen_p || !iobuf_p) { -                        gf_log (this->xl->name, GF_LOG_DEBUG, -                                "bad parameters %p %p %p", -                                hdr_p, hdrlen_p, iobuf_p); -                        goto unlock; -                } - -                if (priv->incoming.state == SOCKET_PROTO_STATE_COMPLETE) { -                        *hdr_p    = priv->incoming.hdr_p; -                        *hdrlen_p = priv->incoming.hdrlen; -                        *iobuf_p  = priv->incoming.iobuf; - -                        memset (&priv->incoming, 0, sizeof (priv->incoming)); -                        priv->incoming.state = SOCKET_PROTO_STATE_NADA; - -                        ret = 0; -                } -        } -unlock: -        pthread_mutex_unlock (&priv->lock); - -        return ret; -} - - -/* TODO: implement per transfer limit */ -static int -socket_submit (transport_t *this, char *buf, int len, -               struct iovec *vector, int count, -               struct iobref *iobref) -{ -        socket_private_t *priv = NULL; -        int               ret = -1; -        char              need_poll_out = 0; -        char              need_append = 1; -        struct ioq       *entry = NULL; -	glusterfs_ctx_t  *ctx = NULL; - -        priv = this->private; -	ctx  = this->xl->ctx; - -        pthread_mutex_lock (&priv->lock); -        { -                if (priv->connected != 1) { -                        if (!priv->submit_log && !priv->connect_finish_log) { -                                gf_log (this->xl->name, GF_LOG_DEBUG, -                                        "not connected (priv->connected = %d)", -                                        priv->connected); -                                priv->submit_log = 1; -                        } -                        goto unlock; -                } - -                priv->submit_log = 0; -                entry = __socket_ioq_new (this, buf, len, vector, count, iobref); -                if (!entry) -                        goto unlock; - -                if (list_empty (&priv->ioq)) { -                        ret = __socket_ioq_churn_entry (this, entry); - -                        if (ret == 0) -                                need_append = 0; - -                        if (ret > 0) -                                need_poll_out = 1; -                } - -                if (need_append) { -                        list_add_tail (&entry->list, &priv->ioq); -                        ret = 0; -                } - -                if (need_poll_out) { -                        /* first entry to wait. continue writing on POLLOUT */ -                        priv->idx = event_select_on (ctx->event_pool, -						     priv->sock, -                                                     priv->idx, -1, 1); -                } -        } -unlock: -        pthread_mutex_unlock (&priv->lock); - -        return ret; -} - - -struct transport_ops tops = { -        .listen     = socket_listen, -        .connect    = socket_connect, -        .disconnect = socket_disconnect, -        .submit     = socket_submit, -        .receive    = socket_receive -}; - - -static int -socket_init (transport_t *this) -{ -        socket_private_t *priv = NULL; -        gf_boolean_t      tmp_bool = 0; -        uint64_t          windowsize = GF_DEFAULT_SOCKET_WINDOW_SIZE; -        char             *optstr = NULL; -        uint32_t          keepalive = 0; - -        if (this->private) { -                gf_log (this->xl->name, GF_LOG_DEBUG, -                        "double init attempted"); -                return -1; -        } - -        priv = GF_CALLOC (1, sizeof (*priv),  -                         gf_common_mt_socket_private_t); -        if (!priv) { -                gf_log (this->xl->name, GF_LOG_ERROR, -                        "calloc (1, %"GF_PRI_SIZET") returned NULL", -			sizeof (*priv)); -                return -1; -        } - -        pthread_mutex_init (&priv->lock, NULL); - -        priv->sock = -1; -        priv->idx = -1; -        priv->connected = -1; - -        INIT_LIST_HEAD (&priv->ioq); - -        if (dict_get (this->xl->options, "non-blocking-io")) { -                optstr = data_to_str (dict_get (this->xl->options, -                                                          "non-blocking-io")); -       -                if (gf_string2boolean (optstr, &tmp_bool) == -1) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "'non-blocking-io' takes only boolean options," -				" not taking any action"); -                        tmp_bool = 1; -                } -                priv->bio = 0; -                if (!tmp_bool) { -                        priv->bio = 1; -                        gf_log (this->xl->name, GF_LOG_WARNING, -                                "disabling non-blocking IO"); -                } -        } - -        optstr = NULL; -         -        // By default, we enable NODELAY -        priv->nodelay = 1; -        if (dict_get (this->xl->options, "transport.socket.nodelay")) { -                optstr = data_to_str (dict_get (this->xl->options, -                                                "transport.socket.nodelay")); - -                if (gf_string2boolean (optstr, &tmp_bool) == -1) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "'transport.socket.nodelay' takes only " -                                 "boolean options, not taking any action"); -                        tmp_bool = 1; -                } -                if (!tmp_bool) { -                        priv->nodelay = 0; -                        gf_log (this->xl->name, GF_LOG_DEBUG, -                                "disabling nodelay"); -                } -        } - - -        optstr = NULL; -        if (dict_get_str (this->xl->options, "transport.window-size", -                          &optstr) == 0) { -                if (gf_string2bytesize (optstr, &windowsize) != 0) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "invalid number format: %s", optstr); -                        return -1; -                } -        } - -        optstr = NULL; - -        if (dict_get_str (this->xl->options, "transport.socket.lowlat", -                          &optstr) == 0) { -                priv->lowlat = 1; -        } - -        /* Enable Keep-alive by default. */ -        priv->keepalive = 1; -        priv->keepaliveintvl = GF_USE_DEFAULT_KEEPALIVE; -        if (dict_get_str (this->xl->options, "transport.socket.keepalive", -                          &optstr) == 0) { -                if (gf_string2boolean (optstr, &tmp_bool) == -1) { -                        gf_log (this->xl->name, GF_LOG_ERROR, -                                "'transport.socket.keepalive' takes only " -                                 "boolean options, not taking any action"); -                        tmp_bool = 1; -                } - -                if (!tmp_bool) -                        priv->keepalive = 0; - -        } - -        if (dict_get_uint32 (this->xl->options, -                             "transport.socket.keepalive-interval", -                             &keepalive) == 0) { -                priv->keepaliveintvl = keepalive; -        } - -        priv->windowsize = (int)windowsize; -        this->private = priv; - -        return 0; -} - - -void -fini (transport_t *this) -{ -        socket_private_t *priv = this->private; - -        if (!priv) -                return; -        this->private = NULL; -        gf_log (this->xl->name, GF_LOG_TRACE, -                "transport %p destroyed", this); - -        pthread_mutex_destroy (&priv->lock); -        GF_FREE (priv); -} - - -int32_t -init (transport_t *this) -{ -        int ret = -1; - -        ret = socket_init (this); - -        if (ret == -1) { -                gf_log (this->xl->name, GF_LOG_DEBUG, "socket_init() failed"); -        } -   -        return ret; -} - -struct volume_options options[] = { -        { .key   = {"remote-port",  -                    "transport.remote-port", -                    "transport.socket.remote-port"},  -          .type  = GF_OPTION_TYPE_INT  -        }, -        { .key   = {"transport.socket.listen-port", "listen-port"},  -          .type  = GF_OPTION_TYPE_INT  -        }, -        { .key   = {"transport.socket.bind-address", "bind-address" },  -          .type  = GF_OPTION_TYPE_INTERNET_ADDRESS  -        }, -        { .key   = {"transport.socket.connect-path", "connect-path"},  -          .type  = GF_OPTION_TYPE_ANY  -        }, -        { .key   = {"transport.socket.bind-path", "bind-path"},  -          .type  = GF_OPTION_TYPE_ANY  -        }, -        { .key   = {"transport.socket.listen-path", "listen-path"},  -          .type  = GF_OPTION_TYPE_ANY  -        }, -        { .key   = { "transport.address-family", -                     "address-family" },  -          .value = {"inet", "inet6", "inet/inet6", "inet6/inet", -                    "unix", "inet-sdp" }, -          .type  = GF_OPTION_TYPE_STR  -        }, - -        { .key   = {"non-blocking-io"},  -          .type  = GF_OPTION_TYPE_BOOL -        }, -        { .key   = {"transport.window-size"}, -          .type  = GF_OPTION_TYPE_SIZET, -          .min   = GF_MIN_SOCKET_WINDOW_SIZE, -          .max   = GF_MAX_SOCKET_WINDOW_SIZE, -        }, -        { .key   = {"transport.socket.nodelay"}, -          .type  = GF_OPTION_TYPE_BOOL -        }, -        { .key   = {"transport.socket.lowlat"}, -          .type  = GF_OPTION_TYPE_BOOL -        }, -        { .key   = {"transport.socket.keepalive"}, -          .type  = GF_OPTION_TYPE_BOOL -        }, -        { .key   = {"transport.socket.keepalive-interval"}, -          .type  = GF_OPTION_TYPE_INT -        }, -        { .key = {NULL} } -}; - diff --git a/xlators/protocol/legacy/transport/socket/src/socket.h b/xlators/protocol/legacy/transport/socket/src/socket.h deleted file mode 100644 index e1dc9a91e67..00000000000 --- a/xlators/protocol/legacy/transport/socket/src/socket.h +++ /dev/null @@ -1,129 +0,0 @@ -/* -  Copyright (c) 2006-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _SOCKET_H -#define _SOCKET_H - - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include "event.h" -#include "transport.h" -#include "logging.h" -#include "dict.h" -#include "mem-pool.h" -#include "socket-mem-types.h" - -#ifndef MAX_IOVEC -#define MAX_IOVEC 16 -#endif /* MAX_IOVEC */ - -#define GF_DEFAULT_SOCKET_LISTEN_PORT 6996 - -/* This is the size set through setsockopt for - * both the TCP receive window size and the - * send buffer size. - * Till the time iobuf size becomes configurable, this size is set to include - * two iobufs + the GlusterFS protocol headers. - * Linux allows us to over-ride the max values for the system. - * Should we over-ride them? Because if we set a value larger than the default - * setsockopt will fail. Having larger values might be beneficial for - * IB links. - */ -#define GF_DEFAULT_SOCKET_WINDOW_SIZE   (512 * GF_UNIT_KB) -#define GF_MAX_SOCKET_WINDOW_SIZE       (1 * GF_UNIT_MB) -#define GF_MIN_SOCKET_WINDOW_SIZE       (128 * GF_UNIT_KB) - -#define GF_USE_DEFAULT_KEEPALIVE        (-1) - -typedef enum { -        SOCKET_PROTO_STATE_NADA = 0, -        SOCKET_PROTO_STATE_HEADER_COMING, -        SOCKET_PROTO_STATE_HEADER_CAME, -        SOCKET_PROTO_STATE_DATA_COMING, -        SOCKET_PROTO_STATE_DATA_CAME, -        SOCKET_PROTO_STATE_COMPLETE, -} socket_proto_state_t; - -struct socket_header { -        char     colonO[3]; -        uint32_t size1; -        uint32_t size2; -        char     version; -} __attribute__((packed)); - - -struct ioq { -        union { -                struct list_head list; -                struct { -                        struct ioq    *next; -                        struct ioq    *prev; -                }; -        }; -        struct socket_header  header; -        struct iovec       vector[MAX_IOVEC]; -        int                count; -        struct iovec      *pending_vector; -        int                pending_count; -        char              *buf; -        struct iobref     *iobref; -}; - - -typedef struct { -        int32_t                sock; -        int32_t                idx; -        unsigned char          connected; // -1 = not connected. 0 = in progress. 1 = connected -        char                   bio; -        char                   connect_finish_log; -        char                   submit_log; -        union { -                struct list_head     ioq; -                struct { -                        struct ioq        *ioq_next; -                        struct ioq        *ioq_prev; -                }; -        }; -        struct { -                int                  state; -                struct socket_header header; -                char                *hdr_p; -                size_t               hdrlen; -                struct iobuf        *iobuf; -                char                *buf_p; -                size_t               buflen; -                struct iovec         vector[2]; -                int                  count; -                struct iovec        *pending_vector; -                int                  pending_count; -        } incoming; -        pthread_mutex_t        lock; -        int                    windowsize; -        char                   lowlat; -        char                   nodelay; -        int                    keepalive; -        int                    keepaliveintvl; -} socket_private_t; - - -#endif diff --git a/xlators/storage/bdb/Makefile.am b/xlators/storage/bdb/Makefile.am deleted file mode 100644 index d471a3f9243..00000000000 --- a/xlators/storage/bdb/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -SUBDIRS = src - -CLEANFILES =  diff --git a/xlators/storage/bdb/src/Makefile.am b/xlators/storage/bdb/src/Makefile.am deleted file mode 100644 index 7e2376979ce..00000000000 --- a/xlators/storage/bdb/src/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ - -xlator_LTLIBRARIES = bdb.la -xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/testing/storage - -bdb_la_LDFLAGS = -module -avoidversion - -bdb_la_SOURCES = bctx.c bdb-ll.c bdb.c -bdb_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la  - -noinst_HEADERS = bdb.h  - -AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -D_GNU_SOURCE -D$(GF_HOST_OS) -Wall \ -	-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) - -AM_LDFLAGS = -ldb - -CLEANFILES =  - diff --git a/xlators/storage/bdb/src/bctx.c b/xlators/storage/bdb/src/bctx.c deleted file mode 100644 index 61560edfaea..00000000000 --- a/xlators/storage/bdb/src/bctx.c +++ /dev/null @@ -1,341 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#include <list.h> -#include <bdb.h> -#include <libgen.h> /* for dirname */ - -static void -__destroy_bctx (bctx_t *bctx) -{ -        if (bctx->directory) -                GF_FREE (bctx->directory); - -        if (bctx->db_path) -                GF_FREE (bctx->db_path); - -        GF_FREE (bctx); -} - -static void -__unhash_bctx (bctx_t *bctx) -{ -        list_del_init (&bctx->b_hash); -} - -static int32_t -bctx_table_prune (bctx_table_t *table) -{ -        int32_t ret = 0; -        struct list_head purge = {0,}; -        struct list_head *next = NULL; -        bctx_t *entry = NULL; -        bctx_t *del = NULL, *tmp = NULL; - -        if (!table) -                return 0; - -        INIT_LIST_HEAD (&purge); - -        LOCK (&table->lock); -        { -                if ((table->lru_limit) && -                    (table->lru_size > table->lru_limit)) { -                        while (table->lru_size > table->lru_limit) { -                                next = table->b_lru.next; -                                entry = list_entry (next, bctx_t, list); - -                                list_move_tail (next, &table->purge); -                                __unhash_bctx (entry); - -                                table->lru_size--; -                                ret++; -                        } -                } -                list_move_tail (&purge, &table->purge); -                list_del_init (&table->purge); -        } -        UNLOCK (&table->lock); - -        list_for_each_entry_safe (del, tmp, &purge, list) { -                list_del_init (&del->list); -                if (del->primary) { -                        ret = del->primary->close (del->primary, 0); -                        if (ret != 0) { -                                gf_log (table->this->name, GF_LOG_DEBUG, -                                        "_BCTX_TABLE_PRUNE %s: %s " -                                        "(failed to close primary database)", -                                        del->directory, db_strerror (ret)); -                        } else { -                                gf_log (table->this->name, GF_LOG_DEBUG, -                                        "_BCTX_TABLE_PRUNE %s (lru=%d)" -                                        "(closed primary database)", -                                        del->directory, table->lru_size); -                        } -                } -                if (del->secondary) { -                        ret = del->secondary->close (del->secondary, 0); -                        if (ret != 0) { -                                gf_log (table->this->name, GF_LOG_DEBUG, -                                        "_BCTX_TABLE_PRUNE %s: %s " -                                        "(failed to close secondary database)", -                                        del->directory, db_strerror (ret)); -                        } else { -                                gf_log (table->this->name, GF_LOG_DEBUG, -                                        "_BCTX_TABLE_PRUNE %s (lru=%d)" -                                        "(closed secondary database)", -                                        del->directory, table->lru_size); -                        } -                } -                __destroy_bctx (del); -        } - -        return ret; -} - - -/* struct bdb_ctx related */ -static inline uint32_t -bdb_key_hash (char *key, uint32_t hash_size) -{ -        uint32_t hash = 0; - -        hash = *key; - -        if (hash) { -                for (key += 1; *key != '\0'; key++) { -                        hash = (hash << 5) - hash + *key; -                } -        } - -        return (hash + *key) % hash_size; -} - -static void -__hash_bctx (bctx_t *bctx) -{ -        bctx_table_t *table = NULL; -        char *key = NULL; - -        table = bctx->table; - -        MAKE_KEY_FROM_PATH (key, bctx->directory); -        bctx->key_hash = bdb_key_hash (key, table->hash_size); - -        list_del_init (&bctx->b_hash); -        list_add (&bctx->b_hash, &table->b_hash[bctx->key_hash]); -} - -static inline bctx_t * -__bctx_passivate (bctx_t *bctx) -{ -        if (bctx->primary) { -                list_move_tail (&bctx->list, &(bctx->table->b_lru)); -                bctx->table->lru_size++; -        } else { -                list_move_tail (&bctx->list, &bctx->table->purge); -                __unhash_bctx (bctx); -        } -        return bctx; -} - -static inline bctx_t * -__bctx_activate (bctx_t *bctx) -{ -        list_move (&bctx->list, &bctx->table->active); -        bctx->table->lru_size--; - -        return bctx; -} - -static bctx_t * -__bdb_ctx_unref (bctx_t *bctx) -{ -        GF_ASSERT (bctx->ref); - -        --bctx->ref; - -        if (!bctx->ref) -                bctx = __bctx_passivate (bctx); - -        return bctx; -} - - -bctx_t * -bctx_unref (bctx_t *bctx) -{ -        bctx_table_t *table = NULL; - -        if (!bctx && !bctx->table) -                return NULL; - -        table = bctx->table; - -        LOCK (&table->lock); -        { -                bctx = __bdb_ctx_unref (bctx); -        } -        UNLOCK (&table->lock); - -        bctx_table_prune (table); - -        return bctx; -} - -/* - * NOTE: __bdb_ctx_ref() is called only after holding table->lock and - * bctx->lock, in that order - */ -static inline bctx_t * -__bctx_ref (bctx_t *bctx) -{ -        if (!bctx->ref) -                __bctx_activate (bctx); - -        bctx->ref++; - -        return bctx; -} - -bctx_t * -bctx_ref (bctx_t *bctx) -{ -        LOCK (&(bctx->table->lock)); -        { -                __bctx_ref (bctx); -        } -        UNLOCK (&(bctx->table->lock)); - -        return bctx; -} - - -#define BDB_THIS(table) (table->this) - -static inline bctx_t * -__create_bctx (bctx_table_t *table, -               const char *path) -{ -        bctx_t *bctx = NULL; -        char *db_path = NULL; - -        bctx = GF_CALLOC (1, sizeof (*bctx), gf_bdb_mt_bctx_t); -        GF_VALIDATE_OR_GOTO ("bctx", bctx, out); - -        bctx->table = table; -        bctx->directory = gf_strdup (path); -        GF_VALIDATE_OR_GOTO ("bctx", bctx->directory, out); - -        MAKE_REAL_PATH_TO_STORAGE_DB (db_path, BDB_THIS (table), path); - -        bctx->db_path = gf_strdup (db_path); -        GF_VALIDATE_OR_GOTO ("bctx", bctx->directory, out); - -        INIT_LIST_HEAD (&bctx->c_list); -        INIT_LIST_HEAD (&bctx->list); -        INIT_LIST_HEAD (&bctx->b_hash); - -        LOCK_INIT (&bctx->lock); - -        __hash_bctx (bctx); - -        list_add (&bctx->list, &table->b_lru); -        table->lru_size++; - -out: -        return bctx; -} - -/* bctx_lookup - lookup bctx_t for the directory @directory. - *               (see description of bctx_t in bdb.h) - * - * @table:     bctx_table_t for this instance of bdb. - * @directory: directory for which bctx_t is being looked up. - */ -bctx_t * -bctx_lookup (bctx_table_t *table, -             const char *directory) -{ -        char    *key = NULL; -        uint32_t key_hash = 0; -        bctx_t  *trav = NULL, *bctx = NULL, *tmp = NULL; -        int32_t  need_break = 0; - -        GF_VALIDATE_OR_GOTO ("bctx", table, out); -        GF_VALIDATE_OR_GOTO ("bctx", directory, out); - -        MAKE_KEY_FROM_PATH (key, directory); -        key_hash = bdb_key_hash (key, table->hash_size); - -        LOCK (&table->lock); -        { -                if (list_empty (&table->b_hash[key_hash])) { -                        goto creat_bctx; -                } - -                list_for_each_entry_safe (trav, tmp, &table->b_hash[key_hash], -                                          b_hash) { -                        LOCK(&trav->lock); -                        { -                                if (!strcmp(trav->directory, directory)) { -                                        bctx = __bctx_ref (trav); -                                        need_break = 1; -                                } -                        } -                        UNLOCK(&trav->lock); - -                        if (need_break) -                                break; -                } - -        creat_bctx: -                if (!bctx) { -                        bctx = __create_bctx (table, directory); -                        bctx = __bctx_ref (bctx); -                } -        } -        UNLOCK (&table->lock); -out: -        return bctx; -} - - -bctx_t * -bctx_parent (bctx_table_t *table, -             const char *path) -{ -        char   *pathname = NULL, *directory = NULL; -        bctx_t *bctx = NULL; - -        GF_VALIDATE_OR_GOTO ("bctx", table, out); -        GF_VALIDATE_OR_GOTO ("bctx", path, out); - -        pathname = gf_strdup (path); -        GF_VALIDATE_OR_GOTO ("bctx", pathname, out); -        directory = dirname (pathname); - -        bctx = bctx_lookup (table, directory); -        GF_VALIDATE_OR_GOTO ("bctx", bctx, out); - -out: -        if (pathname) -                free (pathname); -        return bctx; -} diff --git a/xlators/storage/bdb/src/bdb-ll.c b/xlators/storage/bdb/src/bdb-ll.c deleted file mode 100644 index f70ec47f494..00000000000 --- a/xlators/storage/bdb/src/bdb-ll.c +++ /dev/null @@ -1,1464 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#include <libgen.h> -#include "bdb.h" -#include <list.h> -#include "hashfn.h" -/* - * implement the procedures to interact with bdb */ - -/**************************************************************** - * - * General wrappers and utility procedures for bdb xlator - * - ****************************************************************/ - -ino_t -bdb_inode_transform (ino_t parent, -                     const char *name, -                     size_t namelen) -{ -        ino_t               ino = -1; -        uint64_t            hash = 0; - -        hash = gf_dm_hashfn (name, namelen); - -        ino = (((parent << 32) | 0x00000000ffffffffULL) -               & (hash | 0xffffffff00000000ULL)); - -        return ino; -} - -static int -bdb_generate_secondary_hash (DB *secondary, -                             const DBT *pkey, -                             const DBT *data, -                             DBT *skey) -{ -        char *primary = NULL; -        uint32_t *hash = NULL; - -        primary = pkey->data; - -        hash = GF_CALLOC (1, sizeof (uint32_t), gf_bdb_mt_uint32_t); - -        *hash = gf_dm_hashfn (primary, pkey->size); - -        skey->data = hash; -        skey->size = sizeof (hash); -        skey->flags = DB_DBT_APPMALLOC; - -        return 0; -} - -/*********************************************************** - * - *  bdb storage database utilities - * - **********************************************************/ - -/* - * bdb_db_open - opens a storage db. - * - * @ctx: context specific to the directory for which we are supposed to open db - * - * see, if we have empty slots to open a db. - *      if (no-empty-slots), then prune open dbs and close as many as possible - *      if (empty-slot-available), tika muchkonDu db open maaDu - * - */ -static int -bdb_db_open (bctx_t *bctx) -{ -        DB *primary   = NULL; -        DB *secondary = NULL; -        int32_t ret = -1; -        bctx_table_t *table = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb-ll", bctx, out); - -        table = bctx->table; -        GF_VALIDATE_OR_GOTO ("bdb-ll", table, out); - -        /* we have to do the following, we can't deny someone of db_open ;) */ -        ret = db_create (&primary, table->dbenv, 0); -        if (ret < 0) { -                gf_log ("bdb-ll", GF_LOG_DEBUG, -                        "_BDB_DB_OPEN %s: %s (failed to create database object" -                        " for primary database)", -                        bctx->directory, db_strerror (ret)); -                ret = -ENOMEM; -                goto out; -        } - -        if (table->page_size) { -                ret = primary->set_pagesize (primary, -                                             table->page_size); -                if (ret < 0) { -                        gf_log ("bdb-ll", GF_LOG_DEBUG, -                                "_BDB_DB_OPEN %s: %s (failed to set page-size " -                                "to %"PRIu64")", -                                bctx->directory, db_strerror (ret), -                                table->page_size); -                } else { -                        gf_log ("bdb-ll", GF_LOG_DEBUG, -                                "_BDB_DB_OPEN %s: page-size set to %"PRIu64, -                                bctx->directory, table->page_size); -                } -        } - -        ret = primary->open (primary, NULL, bctx->db_path, "primary", -                             table->access_mode, table->dbflags, 0); -        if (ret < 0) { -                gf_log ("bdb-ll", GF_LOG_ERROR, -                        "_BDB_DB_OPEN %s: %s " -                        "(failed to open primary database)", -                        bctx->directory, db_strerror (ret)); -                ret = -1; -                goto cleanup; -        } - -        ret = db_create (&secondary, table->dbenv, 0); -        if (ret < 0) { -                gf_log ("bdb-ll", GF_LOG_DEBUG, -                        "_BDB_DB_OPEN %s: %s (failed to create database object" -                        " for secondary database)", -                        bctx->directory, db_strerror (ret)); -                ret = -ENOMEM; -                goto cleanup; -        } - -        ret = secondary->open (secondary, NULL, bctx->db_path, "secondary", -                               table->access_mode, table->dbflags, 0); -        if (ret != 0 ) { -                gf_log ("bdb-ll", GF_LOG_ERROR, -                        "_BDB_DB_OPEN %s: %s " -                        "(failed to open secondary database)", -                        bctx->directory, db_strerror (ret)); -                ret = -1; -                goto cleanup; -        } - -        ret = primary->associate (primary, NULL, secondary, -                                  bdb_generate_secondary_hash, -#ifdef DB_IMMUTABLE_KEY -                                  DB_IMMUTABLE_KEY); -#else -                                  0); -#endif -        if (ret != 0 ) { -                gf_log ("bdb-ll", GF_LOG_ERROR, -                        "_BDB_DB_OPEN %s: %s " -                        "(failed to associate primary database with " -                        "secondary database)", -                        bctx->directory, db_strerror (ret)); -                ret = -1; -                goto cleanup; -        } - -out: -        bctx->primary = primary; -        bctx->secondary = secondary; - -        return ret; -cleanup: -        if (primary) -                primary->close (primary, 0); -        if (secondary) -                secondary->close (secondary, 0); - -        return ret; -} - -int32_t -bdb_cursor_close (bctx_t *bctx, -                  DBC *cursorp) -{ -        int32_t ret = -1; - -        GF_VALIDATE_OR_GOTO ("bdb-ll", bctx, out); -        GF_VALIDATE_OR_GOTO ("bdb-ll", cursorp, out); - -        LOCK (&bctx->lock); -        { -#ifdef HAVE_BDB_CURSOR_GET -                ret = cursorp->close (cursorp); -#else -                ret = cursorp->c_close (cursorp); -#endif -                if (ret < 0) { -                        gf_log ("bdb-ll", GF_LOG_DEBUG, -                                "_BDB_CURSOR_CLOSE %s: %s " -                                "(failed to close database cursor)", -                                bctx->directory, db_strerror (ret)); -                } -        } -        UNLOCK (&bctx->lock); - -out: -        return ret; -} - - -int32_t -bdb_cursor_open (bctx_t *bctx, -                 DBC **cursorpp) -{ -        int32_t ret = -1; - -        GF_VALIDATE_OR_GOTO ("bdb-ll", bctx, out); -        GF_VALIDATE_OR_GOTO ("bdb-ll", cursorpp, out); - -        LOCK (&bctx->lock); -        { -                if (bctx->secondary) { -                        /* do nothing, just continue */ -                        ret = 0; -                } else { -                        ret = bdb_db_open (bctx); -                        if (ret < 0) { -                                gf_log ("bdb-ll", GF_LOG_DEBUG, -                                        "_BDB_CURSOR_OPEN %s: ENOMEM " -                                        "(failed to open secondary database)", -                                        bctx->directory); -                                ret = -ENOMEM; -                        } else { -                                ret = 0; -                        } -                } - -                if (ret == 0) { -                        /* all set, open cursor */ -                        ret = bctx->secondary->cursor (bctx->secondary, -                                                       NULL, cursorpp, 0); -                        if (ret < 0) { -                                gf_log ("bdb-ll", GF_LOG_DEBUG, -                                        "_BDB_CURSOR_OPEN %s: %s " -                                        "(failed to open a cursor to database)", -                                        bctx->directory, db_strerror (ret)); -                        } -                } -        } -        UNLOCK (&bctx->lock); - -out: -        return ret; -} - - -/* cache related */ -static bdb_cache_t * -bdb_cache_lookup (bctx_t *bctx, -                  char *path) -{ -        bdb_cache_t *bcache = NULL; -        bdb_cache_t *trav   = NULL; -        char        *key    = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb-ll", bctx, out); -        GF_VALIDATE_OR_GOTO ("bdb-ll", path, out); - -        MAKE_KEY_FROM_PATH (key, path); - -        LOCK (&bctx->lock); -        { -                list_for_each_entry (trav, &bctx->c_list, c_list) { -                        if (!strcmp (trav->key, key)){ -                                bcache = trav; -                                break; -                        } -                } -        } -        UNLOCK (&bctx->lock); - -out: -        return bcache; -} - -static int32_t -bdb_cache_insert (bctx_t *bctx, -                  DBT *key, -                  DBT *data) -{ -        bdb_cache_t *bcache = NULL; -        int32_t ret = -1; - -        GF_VALIDATE_OR_GOTO ("bdb-ll", bctx, out); -        GF_VALIDATE_OR_GOTO ("bdb-ll", key, out); -        GF_VALIDATE_OR_GOTO ("bdb-ll", data, out); - -        LOCK (&bctx->lock); -        { -                if (bctx->c_count > 5) { -                        /* most of the times, we enter here */ -                        /* FIXME: ugly, not supposed to disect any of the -                         * 'struct list_head' directly */ -                        if (!list_empty (&bctx->c_list)) { -                                bcache = list_entry (bctx->c_list.prev, -                                                     bdb_cache_t, c_list); -                                list_del_init (&bcache->c_list); -                        } -                        if (bcache->key) { -                                GF_FREE (bcache->key); -                                bcache->key = GF_CALLOC (key->size + 1, -                                                         sizeof (char),  -                                                         gf_bdb_mt_char); -                                GF_VALIDATE_OR_GOTO ("bdb-ll", -                                                     bcache->key, unlock); -                                memcpy (bcache->key, (char *)key->data, -                                        key->size); -                        } else { -                                /* should never come here */ -                                gf_log ("bdb-ll", GF_LOG_DEBUG, -                                        "_BDB_CACHE_INSERT %s (%s) " -                                        "(found a cache entry with empty key)", -                                        bctx->directory, (char *)key->data); -                        } /* if(bcache->key)...else */ -                        if (bcache->data) { -                                GF_FREE (bcache->data); -                                bcache->data = memdup (data->data, data->size); -                                GF_VALIDATE_OR_GOTO ("bdb-ll", bcache->data, -                                                     unlock); -                                bcache->size = data->size; -                        } else { -                                /* should never come here */ -                                gf_log ("bdb-ll", GF_LOG_CRITICAL, -                                        "_BDB_CACHE_INSERT %s (%s) " -                                        "(found a cache entry with no data)", -                                        bctx->directory, (char *)key->data); -                        } /* if(bcache->data)...else */ -                        list_add (&bcache->c_list, &bctx->c_list); -                        ret = 0; -                } else { -                        /* we will be entering here very rarely */ -                        bcache = GF_CALLOC (1, sizeof (*bcache),  -                                            gf_bdb_mt_bdb_cache_t); -                        GF_VALIDATE_OR_GOTO ("bdb-ll", bcache, unlock); - -                        bcache->key = GF_CALLOC (key->size + 1, sizeof (char), -                                                 gf_bdb_mt_char); -                        GF_VALIDATE_OR_GOTO ("bdb-ll", bcache->key, unlock); -                        memcpy (bcache->key, key->data, key->size); - -                        bcache->data = memdup (data->data, data->size); -                        GF_VALIDATE_OR_GOTO ("bdb-ll", bcache->data, unlock); - -                        bcache->size = data->size; -                        list_add (&bcache->c_list, &bctx->c_list); -                        bctx->c_count++; -                        ret = 0; -                } /* if(private->c_count < 5)...else */ -        } -unlock: -        UNLOCK (&bctx->lock); -out: -        return ret; -} - -static int32_t -bdb_cache_delete (bctx_t *bctx, -                  const char *key) -{ -        bdb_cache_t *bcache = NULL; -        bdb_cache_t *trav   = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb-ll", bctx, out); -        GF_VALIDATE_OR_GOTO ("bdb-ll", key, out); - -        LOCK (&bctx->lock); -        { -                list_for_each_entry (trav, &bctx->c_list, c_list) { -                        if (!strcmp (trav->key, key)){ -                                bctx->c_count--; -                                bcache = trav; -                                break; -                        } -                } - -                if (bcache) { -                        list_del_init (&bcache->c_list); -                        GF_FREE (bcache->key); -                        GF_FREE (bcache->data); -                        GF_FREE (bcache); -                } -        } -        UNLOCK (&bctx->lock); - -out: -        return 0; -} - -void * -bdb_db_stat (bctx_t *bctx, -             DB_TXN *txnid, -             uint32_t flags) -{ -        DB     *storage = NULL; -        void   *stat    = NULL; -        int32_t ret     = -1; - -        LOCK (&bctx->lock); -        { -                if (bctx->primary == NULL) { -                        ret = bdb_db_open (bctx); -                        storage = bctx->primary; -                } else { -                        /* we are just fine, lets continue */ -                        storage = bctx->primary; -                } /* if(bctx->dbp==NULL)...else */ -        } -        UNLOCK (&bctx->lock); - -        GF_VALIDATE_OR_GOTO ("bdb-ll", storage, out); - -        ret = storage->stat (storage, txnid, &stat, flags); - -        if (ret < 0) { -                gf_log ("bdb-ll", GF_LOG_DEBUG, -                        "_BDB_DB_STAT %s: %s " -                        "(failed to do stat database)", -                        bctx->directory, db_strerror (ret)); -        } -out: -        return stat; - -} - -/* bdb_storage_get - retrieve a key/value pair corresponding to @path from the - *  corresponding db file. - * - * @bctx: bctx_t * corresponding to the parent directory of @path. (should - *  always be a valid bctx).  bdb_storage_get should never be called if - *  @bctx = NULL. - * @txnid: NULL if bdb_storage_get is not embedded in an explicit transaction - *  or a valid DB_TXN *, when embedded in an explicit transaction. - * @path: path of the file to read from (translated to a database key using - *  MAKE_KEY_FROM_PATH) - * @buf: char ** - pointer to a pointer to char. a read buffer is created in - *  this procedure and pointer to the buffer is passed through @buf to the - *  caller. - * @size: size of the file content to be read. - * @offset: offset from which the file content to be read. - * - * NOTE: bdb_storage_get tries to open DB, if @bctx->dbp == NULL - *  (@bctx->dbp == NULL, nobody has opened DB till now or DB was closed by - *  bdb_table_prune()). - * - * NOTE: if private->cache is set (bdb xlator's internal caching enabled), then - *  bdb_storage_get first looks up the cache for key/value pair. if - *  bdb_lookup_cache fails, then only DB->get() is called. also,  inserts a - *  newly read key/value pair to cache through bdb_insert_to_cache. - * - * return: 'number of bytes read' on success or -1 on error. - * - * also see: bdb_lookup_cache, bdb_insert_to_cache for details about bdb - *  xlator's internal cache. - */ -static int32_t -bdb_db_get (bctx_t *bctx, -            DB_TXN *txnid, -            const char *path, -            char *buf, -            size_t size, -            off_t offset) -{ -        DB          *storage    = NULL; -        DBT          key        = {0,}; -        DBT          value      = {0,}; -        int32_t      ret        = -1; -        size_t       copy_size  = 0; -        char        *key_string = NULL; -        bdb_cache_t *bcache     = NULL; -        int32_t      db_flags   = 0; -        uint8_t      need_break = 0; -        int32_t      retries    = 1; - -        GF_VALIDATE_OR_GOTO ("bdb-ll", bctx, out); -        GF_VALIDATE_OR_GOTO ("bdb-ll", path, out); - -        MAKE_KEY_FROM_PATH (key_string, path); - -        if (bctx->cache && -            ((bcache = bdb_cache_lookup (bctx, key_string)) != NULL)) { -                if (buf) { -                        copy_size = ((bcache->size - offset) < size)? -                                (bcache->size - offset) : size; - -                        memcpy (buf, (bcache->data + offset), copy_size); -                        ret = copy_size; -                } else { -                        ret = bcache->size; -                } -                 -                goto out; -        }  - -        LOCK (&bctx->lock); -        { -                if (bctx->primary == NULL) { -                        ret = bdb_db_open (bctx); -                        storage = bctx->primary; -                } else { -                        /* we are just fine, lets continue */ -                        storage = bctx->primary; -                } /* if(bctx->dbp==NULL)...else */ -        } -        UNLOCK (&bctx->lock); - -        GF_VALIDATE_OR_GOTO ("bdb-ll", storage, out); - -        key.data = (char *)key_string; -        key.size = strlen (key_string); -        key.flags = DB_DBT_USERMEM; - -        if (bctx->cache){ -                value.flags = DB_DBT_MALLOC; -        } else { -                if (size) { -                        value.data  = buf; -                        value.ulen  = size; -                        value.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL; -                } else { -                        value.flags = DB_DBT_MALLOC; -                } -                value.dlen = size; -                value.doff = offset; -        } - -        do { -                /* TODO: we prefer to give our own buffer to value.data -                 * and ask bdb to fill in it */ -                ret = storage->get (storage, txnid, &key, &value, -                                    db_flags); - -                if (ret == DB_NOTFOUND) { -                        gf_log ("bdb-ll", GF_LOG_DEBUG, -                                "_BDB_DB_GET %s - %s: ENOENT" -                                "(specified key not found in database)", -                                bctx->directory, key_string); -                        ret = -1; -                        need_break = 1; -                } else if (ret == DB_LOCK_DEADLOCK) { -                        retries++; -                        gf_log ("bdb-ll", GF_LOG_DEBUG, -                                "_BDB_DB_GET %s - %s" -                                "(deadlock detected, retrying for %d " -                                "time)", -                                bctx->directory, key_string, retries); -                } else if (ret == 0) { -                        /* successfully read data, lets set everything -                         * in place and return */ -                        if (bctx->cache) { -                                if (buf) { -                                        copy_size = ((value.size - offset) < size) ? -                                                (value.size - offset) : size; - -                                        memcpy (buf, (value.data + offset), -                                                copy_size); -                                        ret = copy_size; -                                } - -                                bdb_cache_insert (bctx, &key, &value); -                        } else { -                                ret = value.size; -                        } - -                        if (size == 0) -                                GF_FREE (value.data); - -                        need_break = 1; -                } else { -                        gf_log ("bdb-ll", GF_LOG_DEBUG, -                                "_BDB_DB_GET %s - %s: %s" -                                "(failed to retrieve specified key from" -                                " database)", -                                bctx->directory, key_string, -                                db_strerror (ret)); -                        ret = -1; -                        need_break = 1; -                } -        } while (!need_break); - -out: -        return ret; -}/* bdb_db_get */ - -/* TODO: handle errors here and log. propogate only the errno to caller */ -int32_t -bdb_db_fread (struct bdb_fd *bfd, char *buf, size_t size, off_t offset) -{ -        return bdb_db_get (bfd->ctx, NULL, bfd->key, buf, size, offset); -} - -int32_t -bdb_db_iread (struct bdb_ctx *bctx, const char *key, char **bufp) -{ -        char *buf = NULL; -        size_t size = 0; -        int64_t ret = 0; - -        ret = bdb_db_get (bctx, NULL, key, NULL, 0, 0); -        size = ret; - -        if (bufp) { -                buf = GF_CALLOC (size, sizeof (char), gf_bdb_mt_char); -                *bufp = buf; -                ret = bdb_db_get (bctx, NULL, key, buf, size, 0); -        } - -        return ret;  -} - -/* bdb_storage_put - insert a key/value specified to the corresponding DB. - * - * @bctx: bctx_t * corresponding to the parent directory of @path. - *        (should always be a valid bctx). bdb_storage_put should never be - *         called if @bctx = NULL. - * @txnid: NULL if bdb_storage_put is not embedded in an explicit transaction - *         or a valid DB_TXN *, when embedded in an explicit transaction. - * @key_string: key of the database entry. - * @buf: pointer to the buffer data to be written as data for @key_string. - * @size: size of @buf. - * @offset: offset in the key's data to be modified with provided data. - * @flags: valid flags are BDB_TRUNCATE_RECORD (to reduce the data of - *         @key_string to 0 size). - * - * NOTE: bdb_storage_put tries to open DB, if @bctx->dbp == NULL - *      (@bctx->dbp == NULL, nobody has opened DB till now or DB was closed by - *       bdb_table_prune()). - * - * NOTE: bdb_storage_put deletes the key/value from bdb xlator's internal cache. - * - * return: 0 on success or -1 on error. - * - * also see: bdb_cache_delete for details on how a cached key/value pair is - * removed. - */ -static int32_t -bdb_db_put (bctx_t *bctx, -            DB_TXN *txnid, -            const char *key_string, -            const char *buf, -            size_t size, -            off_t offset, -            int32_t flags) -{ -        DB     *storage = NULL; -        DBT     key = {0,}, value = {0,}; -        int32_t ret = -1; -        int32_t db_flags = DB_AUTO_COMMIT; -        uint8_t need_break = 0; -        int32_t retries = 1; - -        LOCK (&bctx->lock); -        { -                if (bctx->primary == NULL) { -                        ret = bdb_db_open (bctx); -                        storage = bctx->primary; -                } else { -                        /* we are just fine, lets continue */ -                        storage = bctx->primary; -                } -        } -        UNLOCK (&bctx->lock); - -        GF_VALIDATE_OR_GOTO ("bdb-ll", storage, out); - -        if (bctx->cache) { -                ret = bdb_cache_delete (bctx, (char *)key_string); -                GF_VALIDATE_OR_GOTO ("bdb-ll", (ret == 0), out); -        } - -        key.data = (void *)key_string; -        key.size = strlen (key_string); - -        /* NOTE: bdb lets us expand the file, suppose value.size > value.len, -         * then value.len bytes from value.doff offset and value.size bytes -         * will be written from value.doff and data from -         * value.doff + value.dlen will be pushed value.doff + value.size -         */ -        value.data = (void *)buf; - -        if (flags & BDB_TRUNCATE_RECORD) { -                value.size = size; -                value.doff = 0; -                value.dlen = offset; -        } else { -                value.size = size; -                value.dlen = size; -                value.doff = offset; -        } -        value.flags = DB_DBT_PARTIAL; -        if (buf == NULL && size == 0) -                /* truncate called us */ -                value.flags = 0; - -        do { -                ret = storage->put (storage, txnid, &key, &value, db_flags); -                if (ret == DB_LOCK_DEADLOCK) { -                        retries++; -                        gf_log ("bdb-ll", GF_LOG_DEBUG, -                                "_BDB_DB_PUT %s - %s" -                                "(deadlock detected, retying for %d time)", -                                bctx->directory, key_string, retries); -                } else if (ret) { -                        /* write failed */ -                        gf_log ("bdb-ll", GF_LOG_DEBUG, -                                "_BDB_DB_PUT %s - %s: %s" -                                "(failed to put specified entry into database)", -                                bctx->directory, key_string, db_strerror (ret)); -                        need_break = 1; -                } else { -                        /* successfully wrote */ -                        ret = 0; -                        need_break = 1; -                } -        } while (!need_break); -out: -        return ret; -}/* bdb_db_put */ - -int32_t -bdb_db_icreate (struct bdb_ctx *bctx, const char *key) -{ -        return bdb_db_put (bctx, NULL, key, NULL, 0, 0, 0); -} - -/* TODO: handle errors here and log. propogate only the errno to caller */ -int32_t -bdb_db_fwrite (struct bdb_fd *bfd, char *buf, size_t size, off_t offset) -{ -        return bdb_db_put (bfd->ctx, NULL, bfd->key, buf, size, offset, 0); -} - -/* TODO: handle errors here and log. propogate only the errno to caller */ -int32_t -bdb_db_iwrite (struct bdb_ctx *bctx, const char *key, char *buf, size_t size) -{ -        return bdb_db_put (bctx, NULL, key, buf, size, 0, 0); -} - -int32_t -bdb_db_itruncate (struct bdb_ctx *bctx, const char *key) -{ -        return bdb_db_put (bctx, NULL, key, NULL, 0, 1, 0); -} - -/* bdb_storage_del - delete a key/value pair corresponding to @path from - *  corresponding db file. - * - * @bctx: bctx_t * corresponding to the parent directory of @path. - *       (should always be a valid bctx). bdb_storage_del should never be called - *       if @bctx = NULL. - * @txnid: NULL if bdb_storage_del is not embedded in an explicit transaction - *   or a valid DB_TXN *, when embedded in an explicit transaction. - * @path: path to the file, whose key/value pair has to be deleted. - * - * NOTE: bdb_storage_del tries to open DB, if @bctx->dbp == NULL - *  (@bctx->dbp == NULL, nobody has opened DB till now or DB was closed by - *  bdb_table_prune()). - * - * return: 0 on success or -1 on error. - */ -static int32_t -bdb_db_del (bctx_t *bctx, -            DB_TXN *txnid, -            const char *key_string) -{ -        DB     *storage    = NULL; -        DBT     key        = {0,}; -        int32_t ret        = -1; -        int32_t db_flags   = 0; -        uint8_t need_break = 0; -        int32_t retries    = 1; - -        LOCK (&bctx->lock); -        { -                if (bctx->primary == NULL) { -                        ret = bdb_db_open (bctx); -                        storage = bctx->primary; -                } else { -                        /* we are just fine, lets continue */ -                        storage = bctx->primary; -                } -        } -        UNLOCK (&bctx->lock); - -        GF_VALIDATE_OR_GOTO ("bdb-ll", storage, out); - -        ret = bdb_cache_delete (bctx, key_string); -        GF_VALIDATE_OR_GOTO ("bdb-ll", (ret == 0), out); - -        key.data = (char *)key_string; -        key.size = strlen (key_string); -        key.flags = DB_DBT_USERMEM; - -        do { -                ret = storage->del (storage, txnid, &key, db_flags); - -                if (ret == DB_NOTFOUND) { -                        gf_log ("bdb-ll", GF_LOG_DEBUG, -                                "_BDB_DB_DEL %s - %s: ENOENT" -                                "(failed to delete entry, could not be " -                                "found in the database)", -                                bctx->directory, key_string); -                        need_break = 1; -                } else if (ret == DB_LOCK_DEADLOCK) { -                        retries++; -                        gf_log ("bdb-ll", GF_LOG_DEBUG, -                                "_BDB_DB_DEL %s - %s" -                                "(deadlock detected, retying for %d time)", -                                bctx->directory, key_string, retries); -                } else if (ret == 0) { -                        /* successfully deleted the entry */ -                        gf_log ("bdb-ll", GF_LOG_DEBUG, -                                "_BDB_DB_DEL %s - %s" -                                "(successfully deleted entry from database)", -                                bctx->directory, key_string); -                        ret = 0; -                        need_break = 1; -                } else { -                        gf_log ("bdb-ll", GF_LOG_DEBUG, -                                "_BDB_DB_DEL %s - %s: %s" -                                "(failed to delete entry from database)", -                                bctx->directory, key_string, db_strerror (ret)); -                        ret = -1; -                        need_break = 1; -                } -        } while (!need_break); -out: -        return ret; -} - -int32_t -bdb_db_iremove (bctx_t *bctx, -                const char *key) -{ -        return bdb_db_del (bctx, NULL, key); -} - -/* NOTE: bdb version compatibility wrapper */ -int32_t -bdb_cursor_get (DBC *cursorp, -                DBT *sec, DBT *pri, -                DBT *val, -                int32_t flags) -{ -        int32_t ret = -1; - -        GF_VALIDATE_OR_GOTO ("bdb-ll", cursorp, out); - -#ifdef HAVE_BDB_CURSOR_GET -        ret = cursorp->pget (cursorp, sec, pri, val, flags); -#else -        ret = cursorp->c_pget (cursorp, sec, pri, val, flags); -#endif -        if ((ret != 0)  && (ret != DB_NOTFOUND)) { -                gf_log ("bdb-ll", GF_LOG_DEBUG, -                        "_BDB_CURSOR_GET: %s" -                        "(failed to retrieve entry from database cursor)", -                        db_strerror (ret)); -        } - -out: -        return ret; -}/* bdb_cursor_get */ - -int32_t -bdb_dirent_size (DBT *key) -{ -        return GF_DIR_ALIGN (24 /* FIX MEEEE!!! */ + key->size); -} - - - -/* bdb_dbenv_init - initialize DB_ENV - * - *  initialization includes: - *   1. opening DB_ENV (db_env_create(), DB_ENV->open()). - *      NOTE: see private->envflags for flags used. - *   2. DB_ENV->set_lg_dir - set log directory to be used for storing log files - *     (log files are the files in which transaction logs are written by db). - *   3. DB_ENV->set_flags (DB_LOG_AUTOREMOVE) - set DB_ENV to automatically - *      clear the unwanted log files (flushed at each checkpoint). - *   4. DB_ENV->set_errfile - set errfile to be used by db to report detailed - *      error logs. used only for debbuging purpose. - * - * return: returns a valid DB_ENV * on success or NULL on error. - * - */ -static DB_ENV * -bdb_dbenv_init (xlator_t *this, -                char *directory) -{ -        /* Create a DB environment */ -        DB_ENV        *dbenv       = NULL; -        int32_t        ret         = 0; -        bdb_private_t *private     = NULL; -        int32_t        fatal_flags = 0; - -        VALIDATE_OR_GOTO (this, err); -        VALIDATE_OR_GOTO (directory, err); - -        private = this->private; -        VALIDATE_OR_GOTO (private, err); - -        ret = db_env_create (&dbenv, 0); -        VALIDATE_OR_GOTO ((ret == 0), err); - -        /* NOTE: set_errpfx returns 'void' */ -        dbenv->set_errpfx(dbenv, this->name); - -        ret = dbenv->set_lk_detect (dbenv, DB_LOCK_DEFAULT); -        VALIDATE_OR_GOTO ((ret == 0), err); - -        ret = dbenv->open(dbenv, directory, -                          private->envflags, -                          S_IRUSR | S_IWUSR); -        if ((ret != 0) && (ret != DB_RUNRECOVERY)) { -                gf_log (this->name, GF_LOG_CRITICAL, -                        "failed to join Berkeley DB environment at %s: %s." -                        "please run manual recovery and retry running " -                        "glusterfs", -                        directory, db_strerror (ret)); -                dbenv = NULL; -                goto err; -        } else if (ret == DB_RUNRECOVERY) { -                fatal_flags = ((private->envflags & (~DB_RECOVER)) -                               | DB_RECOVER_FATAL); -                ret = dbenv->open(dbenv, directory, fatal_flags, -                                  S_IRUSR | S_IWUSR); -                if (ret != 0) { -                        gf_log (this->name, GF_LOG_CRITICAL, -                                "failed to join Berkeley DB environment in " -                                "recovery mode at %s: %s. please run manual " -                                "recovery and retry running glusterfs", -                                directory, db_strerror (ret)); -                        dbenv = NULL; -                        goto err; -                } -        } - -        ret = 0; -#if (DB_VERSION_MAJOR == 4 &&                   \ -     DB_VERSION_MINOR == 7) -        if (private->log_auto_remove) { -                ret = dbenv->log_set_config (dbenv, DB_LOG_AUTO_REMOVE, 1); -        } else { -                ret = dbenv->log_set_config (dbenv, DB_LOG_AUTO_REMOVE, 0); -        } -#else -        if (private->log_auto_remove) { -                ret = dbenv->set_flags (dbenv, DB_LOG_AUTOREMOVE, 1); -        } else { -                ret = dbenv->set_flags (dbenv, DB_LOG_AUTOREMOVE, 0); -        } -#endif -        if (ret < 0) { -                gf_log ("bdb-ll", GF_LOG_ERROR, -                        "autoremoval of transactional log files could not be " -                        "configured (%s). you may have to do a manual " -                        "monitoring of transactional log files and remove " -                        "periodically.", -                        db_strerror (ret)); -                goto err; -        } - -        if (private->transaction) { -                ret = dbenv->set_flags(dbenv, DB_AUTO_COMMIT, 1); - -                if (ret != 0) { -                        gf_log ("bdb-ll", GF_LOG_DEBUG, -                                "configuration of auto-commit failed for " -                                "database environment at %s. none of the " -                                "operations will be embedded in transaction " -                                "unless explicitly done so.", -                                db_strerror (ret)); -                        goto err; -                } - -                if (private->txn_timeout) { -                        ret = dbenv->set_timeout (dbenv, private->txn_timeout, -                                                  DB_SET_TXN_TIMEOUT); -                        if (ret != 0) { -                                gf_log ("bdb-ll", GF_LOG_ERROR, -                                        "could not configure Berkeley DB " -                                        "transaction timeout to %d (%s). please" -                                        " review 'option transaction-timeout %d" -                                        "' option.", -                                        private->txn_timeout, -                                        db_strerror (ret), -                                        private->txn_timeout); -                                goto err; -                        } -                } - -                if (private->lock_timeout) { -                        ret = dbenv->set_timeout(dbenv, -                                                 private->txn_timeout, -                                                 DB_SET_LOCK_TIMEOUT); -                        if (ret < 0) { -                                gf_log ("bdb-ll", GF_LOG_ERROR, -                                        "could not configure Berkeley DB " -                                        "lock timeout to %d (%s). please" -                                        " review 'option lock-timeout %d" -                                        "' option.", -                                        private->lock_timeout, -                                        db_strerror (ret), -                                        private->lock_timeout); -                                goto err; -                        } -                } - -                ret = dbenv->set_lg_dir (dbenv, private->logdir); -                if (ret < 0) { -                        gf_log ("bdb-ll", GF_LOG_ERROR, -                                "failed to configure libdb transaction log " -                                "directory at %s. please review the " -                                "'option logdir %s' option.", -                                db_strerror (ret), private->logdir); -                        goto err; -                } -        } - -        if (private->errfile) { -                private->errfp = fopen (private->errfile, "a+"); -                if (private->errfp) { -                        dbenv->set_errfile (dbenv, private->errfp); -                } else { -                        gf_log ("bdb-ll", GF_LOG_ERROR, -                                "failed to open error logging file for " -                                "libdb (Berkeley DB) internal logging (%s)." -                                "please review the 'option errfile %s' option.", -                                strerror (errno), private->errfile); -                        goto err; -                } -        } - -        return dbenv; -err: -        if (dbenv) { -                dbenv->close (dbenv, 0); -        } - -        return NULL; -} - -#define BDB_ENV(this) ((((struct bdb_private *)this->private)->b_table)->dbenv) - -/* bdb_checkpoint - during transactional usage, db does not directly write the - *  data to db files, instead db writes a 'log' (similar to a journal entry) - *  into a log file. db normally clears the log files during opening of an - *  environment. since we expect a filesystem server to run for a pretty long - *  duration and flushing 'log's during dbenv->open would prove very costly, if - *  we accumulate the log entries for one complete run of glusterfs server. to - *  flush the logs frequently, db provides a mechanism called 'checkpointing'. - *  when we do a checkpoint, db flushes the logs to disk (writes changes to db - *  files) and we can also clear the accumulated log files after checkpointing. - *  NOTE: removing unwanted log files is not part of dbenv->txn_checkpoint() - *  call. - * - * @data: xlator_t of the current instance of bdb xlator. - * - *  bdb_checkpoint is called in a different thread from the main glusterfs - *  thread. bdb xlator creates the checkpoint thread after successfully opening - *  the db environment. - *  NOTE: bdb_checkpoint thread shares the DB_ENV handle with the filesystem - *  thread. - * - *  db environment checkpointing frequency is controlled by - *  'option checkpoint-timeout <time-in-seconds>' in volfile. - * - * NOTE: checkpointing thread is started only if 'option transaction on' - *      specified in volfile. checkpointing is not valid for non-transactional - *      environments. - * - */ -static void * -bdb_checkpoint (void *data) -{ -        xlator_t *this = NULL; -        struct bdb_private *private = NULL; -        DB_ENV *dbenv = NULL; -        int32_t ret = 0; -        uint32_t active = 0; - -        this = (xlator_t *) data; -        dbenv = BDB_ENV(this); -        private = this->private; - -        for (;;sleep (private->checkpoint_interval)) { -                LOCK (&private->active_lock); -                active = private->active; -                UNLOCK (&private->active_lock); - -                if (active) { -                        ret = dbenv->txn_checkpoint (dbenv, 1024, 0, 0); -                        if (ret) { -                                gf_log ("bdb-ll", GF_LOG_DEBUG, -                                        "_BDB_CHECKPOINT: %s" -                                        "(failed to checkpoint environment)", -                                        db_strerror (ret)); -                        } else { -                                gf_log ("bdb-ll", GF_LOG_DEBUG, -                                        "_BDB_CHECKPOINT: successfully " -                                        "checkpointed"); -                        } -                } else { -                        ret = dbenv->txn_checkpoint (dbenv, 1024, 0, 0); -                        if (ret) { -                                gf_log ("bdb-ll", GF_LOG_ERROR, -                                        "_BDB_CHECKPOINT: %s" -                                        "(final checkpointing failed. might " -                                        "need to run recovery tool manually on " -                                        "next usage of this database " -                                        "environment)", -                                        db_strerror (ret)); -                        } else { -                                gf_log ("bdb-ll", GF_LOG_DEBUG, -                                        "_BDB_CHECKPOINT: final successfully " -                                        "checkpointed"); -                        } -                        break; -                } -        } - -        return NULL; -} - - -/* bdb_db_init - initialize bdb xlator - * - * reads the options from @options dictionary and sets appropriate values in - * @this->private. also initializes DB_ENV. - * - * return: 0 on success or -1 on error - * (with logging the error through gf_log()). - */ -int -bdb_db_init (xlator_t *this, -             dict_t *options) -{ -        /* create a db entry for root */ -        int32_t        op_ret  = 0; -        bdb_private_t *private = NULL; -        bctx_table_t  *table = NULL; - -        char *checkpoint_interval_str = NULL; -        char *page_size_str           = NULL; -        char *lru_limit_str           = NULL; -        char *timeout_str             = NULL; -        char *access_mode             = NULL; -        char *endptr    = NULL; -        char *errfile   = NULL; -        char *directory = NULL; -        char *logdir    = NULL; -        char *mode      = NULL; -        char *mode_str  = NULL; -        int   ret = -1; -        int   idx = 0; -        struct stat stbuf = {0,}; - -        private = this->private; - -        /* cache is always on */ -        private->cache = ON; - -        ret = dict_get_str (options, "access-mode", &access_mode); -        if ((ret == 0) -            && (!strcmp (access_mode, "btree"))) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "using BTREE access mode to access libdb " -                        "(Berkeley DB)"); -                private->access_mode = DB_BTREE; -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "using HASH access mode to access libdb (Berkeley DB)"); -                private->access_mode = DB_HASH; -        } - -        ret = dict_get_str (options, "mode", &mode); -        if ((ret == 0) -            && (!strcmp (mode, "cache"))) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "cache data mode selected for 'storage/bdb'. filesystem" -                        " operations are not transactionally protected and " -                        "system crash does not guarantee recoverability of " -                        "data"); -                private->envflags = DB_CREATE | DB_INIT_LOG | -                        DB_INIT_MPOOL | DB_THREAD; -                private->dbflags = DB_CREATE | DB_THREAD; -                private->transaction = OFF; -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "persistent data mode selected for 'storage/bdb'. each" -                        "filesystem operation is guaranteed to be Berkeley DB " -                        "transaction protected."); -                private->transaction = ON; -                private->envflags = DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | -                        DB_INIT_MPOOL | DB_INIT_TXN | DB_RECOVER | DB_THREAD; -                private->dbflags = DB_CREATE | DB_THREAD; - - -                ret = dict_get_str (options, "lock-timeout", &timeout_str); - -                if (ret == 0) { -                        ret = gf_string2time (timeout_str, -                                              &private->lock_timeout); - -                        if (private->lock_timeout > 4260000) { -                                /* db allows us to DB_SET_LOCK_TIMEOUT to be -                                 * set to a maximum of 71 mins -                                 * (4260000 milliseconds) */ -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "Berkeley DB lock-timeout parameter " -                                        "(%d) is out of range. please specify" -                                        " a valid timeout value for " -                                        "lock-timeout and retry.", -                                        private->lock_timeout); -                                goto err; -                        } -                } -                ret = dict_get_str (options, "transaction-timeout", -                                    &timeout_str); -                if (ret == 0) { -                        ret = gf_string2time (timeout_str, -                                              &private->txn_timeout); - -                        if (private->txn_timeout > 4260000) { -                                /* db allows us to DB_SET_TXN_TIMEOUT to be set -                                 * to a maximum of 71 mins -                                 * (4260000 milliseconds) */ -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "Berkeley DB lock-timeout parameter " -                                        "(%d) is out of range. please specify" -                                        " a valid timeout value for " -                                        "lock-timeout and retry.", -                                        private->lock_timeout); -                                goto err; -                        } -                } - -                private->checkpoint_interval = BDB_DEFAULT_CHECKPOINT_INTERVAL; -                ret = dict_get_str (options, "checkpoint-interval", -                                    &checkpoint_interval_str); -                if (ret == 0) { -                        ret = gf_string2time (checkpoint_interval_str, -                                              &private->checkpoint_interval); - -                        if (ret < 0) { -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "'%"PRIu32"' is not a valid parameter " -                                        "for checkpoint-interval option. " -                                        "please specify a valid " -                                        "checkpoint-interval and retry", -                                        private->checkpoint_interval); -                                goto err; -                        } -                } -        } - -        ret = dict_get_str (options, "file-mode", &mode_str); -        if (ret == 0) { -                private->file_mode = strtol (mode_str, &endptr, 8); - -                if ((*endptr) || -                    (!IS_VALID_FILE_MODE(private->file_mode))) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "'%o' is not a valid parameter for file-mode " -                                "option. please specify a valid parameter for " -                                "file-mode and retry.", -                                private->file_mode); -                        goto err; -                } -        } else { -                private->file_mode = DEFAULT_FILE_MODE; -        } -        private->symlink_mode = private->file_mode | S_IFLNK; -        private->file_mode = private->file_mode | S_IFREG; - -        ret = dict_get_str (options, "dir-mode", &mode_str); -        if (ret == 0) { -                private->dir_mode = strtol (mode_str, &endptr, 8); -                if ((*endptr) || -                    (!IS_VALID_FILE_MODE(private->dir_mode))) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "'%o' is not a valid parameter for dir-mode " -                                "option. please specify a valid parameter for " -                                "dir-mode and retry.", -                                private->dir_mode); -                        goto err; -                } -        } else { -                private->dir_mode = DEFAULT_DIR_MODE; -        } - -        private->dir_mode = private->dir_mode | S_IFDIR; - -        table = GF_CALLOC (1, sizeof (*table), gf_bdb_mt_bctx_table_t); -        if (table == NULL) { -                gf_log ("bdb-ll", GF_LOG_CRITICAL, -                        "memory allocation for 'storage/bdb' internal " -                        "context table failed."); -                goto err; -        } - -        INIT_LIST_HEAD(&(table->b_lru)); -        INIT_LIST_HEAD(&(table->active)); -        INIT_LIST_HEAD(&(table->purge)); - -        LOCK_INIT (&table->lock); -        LOCK_INIT (&table->checkpoint_lock); - -        table->transaction = private->transaction; -        table->access_mode = private->access_mode; -        table->dbflags = private->dbflags; -        table->this    = this; - -        ret = dict_get_str (options, "lru-limit", -                            &lru_limit_str); - -        /* TODO: set max lockers and max txns to accomodate -         * for more than lru_limit */ -        if (ret == 0) { -                ret = gf_string2uint32 (lru_limit_str, -                                        &table->lru_limit); -                gf_log ("bdb-ll", GF_LOG_DEBUG, -                        "setting lru limit of 'storage/bdb' internal context" -                        "table to %d. maximum of %d unused databases can be " -                        "open at any given point of time.", -                        table->lru_limit, table->lru_limit); -        } else { -                table->lru_limit = BDB_DEFAULT_LRU_LIMIT; -        } - -        ret = dict_get_str (options, "page-size", -                            &page_size_str); - -        if (ret == 0) { -                ret = gf_string2bytesize (page_size_str, -                                          &table->page_size); -                if (ret < 0) { -                        gf_log ("bdb-ll", GF_LOG_ERROR, -                                "\"%s\" is an invalid parameter to " -                                "\"option page-size\". please specify a valid " -                                "size and retry.", -                                page_size_str); -                        goto err; -                } - -                if (!PAGE_SIZE_IN_RANGE(table->page_size)) { -                        gf_log ("bdb-ll", GF_LOG_ERROR, -                                "\"%s\" is out of range for Berkeley DB " -                                "page-size. allowed page-size range is %d to " -                                "%d. please specify a page-size value in the " -                                "range and retry.", -                                page_size_str, BDB_LL_PAGE_SIZE_MIN, -                                BDB_LL_PAGE_SIZE_MAX); -                        goto err; -                } -        } else { -                table->page_size = BDB_LL_PAGE_SIZE_DEFAULT; -        } - -        table->hash_size = BDB_DEFAULT_HASH_SIZE; -        table->b_hash = GF_CALLOC (BDB_DEFAULT_HASH_SIZE, -                                   sizeof (struct list_head), -                                   gf_bdb_mt_list_head); - -        for (idx = 0; idx < table->hash_size; idx++) -                INIT_LIST_HEAD(&(table->b_hash[idx])); - -        private->b_table = table; - -        ret = dict_get_str (options, "errfile", &errfile); -        if (ret == 0) { -                private->errfile = gf_strdup (errfile); -                gf_log (this->name, GF_LOG_DEBUG, -                        "using %s as error logging file for libdb (Berkeley DB " -                        "library) internal logging.", private->errfile); -        } - -        ret = dict_get_str (options, "directory", &directory); - -        if (ret == 0) { -                ret = dict_get_str (options, "logdir", &logdir); - -                if (ret < 0) { -                        gf_log ("bdb-ll", GF_LOG_DEBUG, -                                "using the database environment home " -                                "directory (%s) itself as transaction log " -                                "directory", directory); -                        private->logdir = gf_strdup (directory); - -                } else { -                        private->logdir = gf_strdup (logdir); - -                        op_ret = stat (private->logdir, &stbuf); -                        if ((op_ret != 0) -                            || (!S_ISDIR (stbuf.st_mode))) { -                                gf_log ("bdb-ll", GF_LOG_ERROR, -                                        "specified logdir %s does not exist. " -                                        "please provide a valid existing " -                                        "directory as parameter to 'option " -                                        "logdir'", -                                        private->logdir); -                                goto err; -                        } -                } - -                private->b_table->dbenv = bdb_dbenv_init (this, directory); -                if (private->b_table->dbenv == NULL) { -                        gf_log ("bdb-ll", GF_LOG_ERROR, -                                "initialization of database environment " -                                "failed"); -                        goto err; -                } else { -                        if (private->transaction) { -                                /* all well, start the checkpointing thread */ -                                LOCK_INIT (&private->active_lock); - -                                LOCK (&private->active_lock); -                                { -                                        private->active = 1; -                                } -                                UNLOCK (&private->active_lock); -                                pthread_create (&private->checkpoint_thread, -                                                NULL, bdb_checkpoint, this); -                        } -                } -        } - -        return op_ret; -err: -        if (table) { -                GF_FREE (table->b_hash); -                GF_FREE (table); -        } -        if (private) { -                if (private->errfile) -                        GF_FREE (private->errfile); - -                if (private->logdir) -                        GF_FREE (private->logdir); -        } - -        return -1; -} diff --git a/xlators/storage/bdb/src/bdb-mem-types.h b/xlators/storage/bdb/src/bdb-mem-types.h deleted file mode 100644 index e68b8c0cae6..00000000000 --- a/xlators/storage/bdb/src/bdb-mem-types.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - - -#ifndef __POSIX_MEM_TYPES_H__ -#define __POSIX_MEM_TYPES_H__ - -#include "mem-types.h" - -enum gf_bdb_mem_types_ { -        gf_bdb_mt_bctx_t = gf_common_mt_end + 1, -        gf_bdb_mt_bdb_fd, -        gf_bdb_mt_dir_entry_t, -        gf_bdb_mt_char, -        gf_bdb_mt_dir_entry_t, -        gf_bdb_mt_char, -        gf_bdb_mt_bdb_private, -        gf_bdb_mt_uint32_t, -        gf_bdb_mt_char, -        gf_bdb_mt_bdb_cache_t, -        gf_bdb_mt_char, -        gf_bdb_mt_bctx_table_t, -        gf_bdb_mt_list_head, -        gf_bdb_mt_end, -}; -#endif diff --git a/xlators/storage/bdb/src/bdb.c b/xlators/storage/bdb/src/bdb.c deleted file mode 100644 index 384094b57ad..00000000000 --- a/xlators/storage/bdb/src/bdb.c +++ /dev/null @@ -1,3603 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -/* bdb based storage translator - named as 'bdb' translator - * - * - * There can be only two modes for files existing on bdb translator: - * 1. DIRECTORY - directories are stored by bdb as regular directories on - * back-end file-system. directories also have an entry in the ns_db.db of - * their parent directory. - * 2. REGULAR FILE - regular files are stored as records in the storage_db.db - * present in the directory. regular files also have an entry in ns_db.db - * - * Internally bdb has a maximum of three different types of logical files - * associated with each directory: - * 1. storage_db.db - storage database, used to store the data corresponding to - *    regular files in the form of key/value pair. file-name is the 'key' and - *    data is 'value'. - * 2. directory (all subdirectories) - any subdirectory will have a regular - *    directory entry. - */ -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#define __XOPEN_SOURCE 500 - -#include <stdint.h> -#include <sys/time.h> -#include <errno.h> -#include <ftw.h> -#include <libgen.h> - -#include "glusterfs.h" -#include "dict.h" -#include "logging.h" -#include "bdb.h" -#include "xlator.h" -#include "defaults.h" -#include "common-utils.h" - -/* to be used only by fops, nobody else */ -#define BDB_ENV(this) ((((struct bdb_private *)this->private)->b_table)->dbenv) -#define B_TABLE(this) (((struct bdb_private *)this->private)->b_table) - - -int32_t -bdb_mknod (call_frame_t *frame, -           xlator_t *this, -           loc_t *loc, -           mode_t mode, -           dev_t dev) -{ -        int32_t     op_ret     = -1; -        int32_t     op_errno   = EINVAL; -        char       *key_string = NULL; /* after translating path to DB key */ -        char       *db_path    = NULL; -        bctx_t     *bctx       = NULL; -        struct stat stbuf      = {0,}; - - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); - -        if (!S_ISREG(mode)) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "MKNOD %"PRId64"/%s (%s): EPERM" -                        "(mknod supported only for regular files. " -                        "file mode '%o' not supported)", -                        loc->parent->ino, loc->name, loc->path, mode); -                op_ret = -1; -                op_errno = EPERM; -                goto out; -        } /* if(!S_ISREG(mode)) */ - -        bctx = bctx_parent (B_TABLE(this), loc->path); -        if (bctx == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "MKNOD %"PRId64"/%s (%s): ENOMEM" -                        "(failed to lookup database handle)", -                        loc->parent->ino, loc->name, loc->path); -                op_ret   = -1; -                op_errno = ENOMEM; -                goto out; -        } - -        MAKE_REAL_PATH_TO_STORAGE_DB (db_path, this, bctx->directory); - -        op_ret = lstat (db_path, &stbuf); -        if (op_ret != 0) { -                op_errno = EINVAL; -                gf_log (this->name, GF_LOG_DEBUG, -                        "MKNOD %"PRId64"/%s (%s): EINVAL" -                        "(failed to lookup database handle)", -                        loc->parent->ino, loc->name, loc->path); -                goto out; -        } - -        MAKE_KEY_FROM_PATH (key_string, loc->path); -        op_ret = bdb_db_icreate (bctx, key_string); -        if (op_ret > 0) { -                /* create successful */ -                stbuf.st_ino = bdb_inode_transform (loc->parent->ino, -                                                    key_string, -                                                    strlen (key_string)); -                stbuf.st_mode  = mode; -                stbuf.st_size = 0; -                stbuf.st_blocks = BDB_COUNT_BLOCKS (stbuf.st_size, \ -                                                    stbuf.st_blksize); -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "MKNOD %"PRId64"/%s (%s): ENOMEM" -                        "(failed to create database entry)", -                        loc->parent->ino, loc->name, loc->path); -                op_ret   = -1; -                op_errno = EINVAL; /* TODO: errno sari illa */ -                goto out; -        }/* if (!op_ret)...else */ - -out: -        if (bctx) { -                /* NOTE: bctx_unref always returns success, -                 * see description of bctx_unref for more details */ -                bctx_unref (bctx); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, loc->inode, &stbuf); -        return 0; -} - -static inline int32_t -is_dir_empty (xlator_t *this, -              loc_t *loc) -{ -        int32_t        ret       = 1; -        bctx_t        *bctx      = NULL; -        DIR           *dir       = NULL; -        char          *real_path = NULL; -        void          *dbstat    = NULL; -        struct dirent *entry     = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); - -        bctx = bctx_lookup (B_TABLE(this), loc->path); -        if (bctx == NULL) { -                ret = -ENOMEM; -                goto out; -        } - -        dbstat = bdb_db_stat (bctx, NULL, 0); -        if (dbstat) { -                switch (bctx->table->access_mode) -                { -                case DB_HASH: -                        ret = (((DB_HASH_STAT *)dbstat)->hash_nkeys == 0); -                        break; -                case DB_BTREE: -                case DB_RECNO: -                        ret = (((DB_BTREE_STAT *)dbstat)->bt_nkeys == 0); -                        break; -                case DB_QUEUE: -                        ret = (((DB_QUEUE_STAT *)dbstat)->qs_nkeys == 0); -                        break; -                case DB_UNKNOWN: -                        gf_log (this->name, GF_LOG_CRITICAL, -                                "unknown access-mode set for database"); -                        ret = 0; -                } -        } else { -                ret = -EBUSY; -                goto out; -        } - -        MAKE_REAL_PATH (real_path, this, loc->path); -        dir = opendir (real_path); -        if (dir == NULL) { -                ret = -errno; -                goto out; -        } - -        while ((entry = readdir (dir))) { -                if ((!IS_BDB_PRIVATE_FILE(entry->d_name)) && -                    (!IS_DOT_DOTDOT(entry->d_name))) { -                        ret = 0; -                        break; -                }/* if(!IS_BDB_PRIVATE_FILE()) */ -        } /* while(true) */ -        closedir (dir); -out: -        if (bctx) { -                /* NOTE: bctx_unref always returns success, -                 * see description of bctx_unref for more details */ -                bctx_unref (bctx); -        } - -        return ret; -} - -int32_t -bdb_rename (call_frame_t *frame, -            xlator_t *this, -            loc_t *oldloc, -            loc_t *newloc) -{ -        STACK_UNWIND (frame, -1, EXDEV, NULL); -        return 0; -} - -int32_t -bdb_link (call_frame_t *frame, -          xlator_t *this, -          loc_t *oldloc, -          loc_t *newloc) -{ -        STACK_UNWIND (frame, -1, EXDEV, NULL, NULL); -        return 0; -} - -int32_t -is_space_left (xlator_t *this, -               size_t size) -{ -        struct bdb_private *private = this->private; -        struct statvfs stbuf = {0,}; -        int32_t ret = -1; -        fsblkcnt_t req_blocks = 0; -        fsblkcnt_t usable_blocks = 0; - -        ret = statvfs (private->export_path, &stbuf); -        if (ret != 0) { -                ret = 0; -        } else { -                req_blocks = (size / stbuf.f_frsize) + 1; - -                usable_blocks = (stbuf.f_bfree - BDB_ENOSPC_THRESHOLD); - -                if (req_blocks < usable_blocks) -                        ret = 1; -                else -                        ret = 0; -        } - -        return ret; -} - -int32_t -bdb_create (call_frame_t *frame, -            xlator_t *this, -            loc_t *loc, -            int32_t flags, -            mode_t mode, -            fd_t *fd) -{ -        int32_t             op_ret     = -1; -        int32_t             op_errno   = EPERM; -        char               *db_path    = NULL; -        struct stat         stbuf      = {0,}; -        bctx_t             *bctx       = NULL; -        struct bdb_private *private    = NULL; -        char               *key_string = NULL; -        struct bdb_fd      *bfd        = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); -        GF_VALIDATE_OR_GOTO (this->name, fd, out); - -        private = this->private; - -        bctx = bctx_parent (B_TABLE(this), loc->path); -        if (bctx == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "CREATE %"PRId64"/%s (%s): ENOMEM" -                        "(failed to lookup database handle)", -                        loc->parent->ino, loc->name, loc->path); -                op_ret   = -1; -                op_errno = ENOMEM; -                goto out; -        } - -        MAKE_REAL_PATH_TO_STORAGE_DB (db_path, this, bctx->directory); -        op_ret = lstat (db_path, &stbuf); -        if (op_ret != 0) { -                op_errno = EINVAL; -                gf_log (this->name, GF_LOG_DEBUG, -                        "CREATE %"PRId64"/%s (%s): EINVAL" -                        "(database file missing)", -                        loc->parent->ino, loc->name, loc->path); -                goto out; -        } - -        MAKE_KEY_FROM_PATH (key_string, loc->path); -        op_ret = bdb_db_icreate (bctx, key_string); -        if (op_ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "CREATE %"PRId64"/%s (%s): ENOMEM" -                        "(failed to create database entry)", -                        loc->parent->ino, loc->name, loc->path); -                op_errno = EINVAL; /* TODO: errno sari illa */ -                goto out; -        } - -        /* create successful */ -        bfd = GF_CALLOC (1, sizeof (*bfd), gf_bdb_mt_bdb_fd); -        if (bfd == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "CREATE %"PRId64"/%s (%s): ENOMEM" -                        "(failed to allocate memory for internal fd context)", -                        loc->parent->ino, loc->name, loc->path); -                op_ret   = -1; -                op_errno = ENOMEM; -                goto out; -        } - -        /* NOTE: bdb_get_bctx_from () returns bctx with a ref */ -        bfd->ctx = bctx; -        bfd->key = gf_strdup (key_string); -        if (bfd->key == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "CREATE %"PRId64" (%s): ENOMEM" -                        "(failed to allocate memory for internal fd->key)", -                        loc->ino, loc->path); -                op_ret   = -1; -                op_errno = ENOMEM; -                goto out; -        } - -        BDB_FCTX_SET (fd, this, bfd); - -        stbuf.st_ino = bdb_inode_transform (loc->parent->ino, -                                            key_string, -                                            strlen (key_string)); -        stbuf.st_mode = private->file_mode; -        stbuf.st_size = 0; -        stbuf.st_nlink = 1; -        stbuf.st_blocks = BDB_COUNT_BLOCKS (stbuf.st_size, stbuf.st_blksize); -        op_ret = 0; -        op_errno = 0; -out: -        STACK_UNWIND (frame, op_ret, op_errno, fd, loc->inode, &stbuf); - -        return 0; -} - - -/* bdb_open - * - * as input parameters bdb_open gets the file name, i.e key. bdb_open should - * effectively - * do: store key, open storage db, store storage-db pointer. - * - */ -int32_t -bdb_open (call_frame_t *frame, -          xlator_t *this, -          loc_t *loc, -          int32_t flags, -          fd_t *fd, -          int32_t wbflags) -{ -        int32_t         op_ret     = -1; -        int32_t         op_errno   = EINVAL; -        bctx_t         *bctx       = NULL; -        char           *key_string = NULL; -        struct bdb_fd  *bfd        = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); -        GF_VALIDATE_OR_GOTO (this->name, fd, out); - -        bctx = bctx_parent (B_TABLE(this), loc->path); -        if (bctx == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "OPEN %"PRId64" (%s): ENOMEM" -                        "(failed to lookup database handle)", -                        loc->ino, loc->path); -                op_ret   = -1; -                op_errno = ENOMEM; -                goto out; -        } - -        bfd = GF_CALLOC (1, sizeof (*bfd), gf_bdb_mt_bdb_fd); -        if (bfd == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "OPEN %"PRId64" (%s): ENOMEM" -                        "(failed to allocate memory for internal fd context)", -                        loc->ino, loc->path); -                op_ret   = -1; -                op_errno = ENOMEM; -                goto out; -        } - -        /* NOTE: bctx_parent () returns bctx with a ref */ -        bfd->ctx = bctx; - -        MAKE_KEY_FROM_PATH (key_string, loc->path); -        bfd->key = gf_strdup (key_string); -        if (bfd->key == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "OPEN %"PRId64" (%s): ENOMEM" -                        "(failed to allocate memory for internal fd->key)", -                        loc->ino, loc->path); -                op_ret   = -1; -                op_errno = ENOMEM; -                goto out; -        } - -        BDB_FCTX_SET (fd, this, bfd); -        op_ret = 0; -out: -        STACK_UNWIND (frame, op_ret, op_errno, fd); - -        return 0; -} - -int32_t -bdb_readv (call_frame_t *frame, -           xlator_t *this, -           fd_t *fd, -           size_t size, -           off_t offset) -{ -        int32_t        op_ret     = -1; -        int32_t        op_errno   = EINVAL; -        struct iovec   vec        = {0,}; -        struct stat    stbuf      = {0,}; -        struct bdb_fd *bfd        = NULL; -        char          *db_path    = NULL; -        int32_t        read_size  = 0; -        struct iobref *iobref     = NULL; -        struct iobuf  *iobuf      = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, fd, out); - -        BDB_FCTX_GET (fd, this, &bfd); -        if (bfd == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "READV %"PRId64" - %"GF_PRI_SIZET",%"PRId64": EBADFD" -                        "(internal fd not found through fd)", -                        fd->inode->ino, size, offset); -                op_errno = EBADFD; -                op_ret = -1; -                goto out; -        } - -        MAKE_REAL_PATH_TO_STORAGE_DB (db_path, this, bfd->ctx->directory); -        op_ret = lstat (db_path, &stbuf); -        if (op_ret != 0) { -                op_errno = errno; -                gf_log (this->name, GF_LOG_DEBUG, -                        "READV %"PRId64" - %"GF_PRI_SIZET",%"PRId64": EINVAL" -                        "(database file missing)", -                        fd->inode->ino, size, offset); -                goto out; -        } - -        iobuf = iobuf_get (this->ctx->iobuf_pool); -        if (!iobuf) { -                gf_log (this->name, GF_LOG_ERROR, -                        "out of memory :("); -                op_ret = -1; -                op_errno = ENOMEM; -                goto out; -        } - -        /* we are ready to go */ -        op_ret = bdb_db_fread (bfd, iobuf->ptr, size, offset); -        read_size = op_ret; -        if (op_ret == -1) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "READV %"PRId64" - %"GF_PRI_SIZET",%"PRId64": EBADFD" -                        "(failed to find entry in database)", -                        fd->inode->ino, size, offset); -                op_ret   = -1; -                op_errno = ENOENT; -                goto out; -        } else if (op_ret == 0) { -                goto out; -        } - -        iobref = iobref_new (); -        if (iobref == NULL) { -                gf_log (this->name, GF_LOG_ERROR, -                        "out of memory :("); -                op_ret = -1; -                op_errno = ENOMEM; -                goto out; -        } - -        if (size < read_size) { -                op_ret = size; -                read_size = size; -        } - -        iobref_add (iobref, iobuf); - -        vec.iov_base = iobuf->ptr; -        vec.iov_len = read_size; - -        stbuf.st_ino = fd->inode->ino; -        stbuf.st_size = bdb_db_fread (bfd, NULL, 0, 0); -        stbuf.st_blocks = BDB_COUNT_BLOCKS (stbuf.st_size, stbuf.st_blksize); -        op_ret = size; -out: -        STACK_UNWIND (frame, op_ret, op_errno, &vec, 1, &stbuf, iobuf); - -        if (iobref) -                iobref_unref (iobref); - -        if (iobuf) -                iobuf_unref (iobuf); - -        return 0; -} - - -int32_t -bdb_writev (call_frame_t *frame, -            xlator_t *this, -            fd_t *fd, -            struct iovec *vector, -            int32_t count, -            off_t offset, -            struct iobref *iobref) -{ -        int32_t        op_ret   = -1; -        int32_t        op_errno = EINVAL; -        struct stat    stbuf    = {0,}; -        struct bdb_fd *bfd      = NULL; -        int32_t        idx      = 0; -        off_t          c_off    = offset; -        int32_t        c_ret    = -1; -        char          *db_path  = NULL; -        size_t         total_size = 0; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, fd, out); -        GF_VALIDATE_OR_GOTO (this->name, vector, out); - -        BDB_FCTX_GET (fd, this, &bfd); -        if (bfd == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "WRITEV %"PRId64" - %"PRId32",%"PRId64": EBADFD" -                        "(internal fd not found through fd)", -                        fd->inode->ino, count, offset); -                op_ret = -1; -                op_errno = EBADFD; -                goto out; -        } - -        MAKE_REAL_PATH_TO_STORAGE_DB (db_path, this, bfd->ctx->directory); -        op_ret = lstat (db_path, &stbuf); -        if (op_ret != 0) { -                op_errno = errno; -                gf_log (this->name, GF_LOG_ERROR, -                        "WRITEV %"PRId64" - %"PRId32",%"PRId64": EINVAL" -                        "(database file missing)", -                        fd->inode->ino, count, offset); -                goto out; -        } - -        for (idx = 0; idx < count; idx++) -                total_size += vector[idx].iov_len; - -        if (!is_space_left (this, total_size)) { -                gf_log (this->name, GF_LOG_ERROR, -                        "WRITEV %"PRId64" - %"PRId32" (%"GF_PRI_SIZET"),%" -                        PRId64": ENOSPC " -                        "(not enough space after internal measurement)", -                        fd->inode->ino, count, total_size, offset); -                op_ret = -1; -                op_errno = ENOSPC; -                goto out; -        } - -        /* we are ready to go */ -        for (idx = 0; idx < count; idx++) { -                c_ret = bdb_db_fwrite (bfd, vector[idx].iov_base, -                                       vector[idx].iov_len, c_off); -                if (c_ret < 0) { -                        gf_log (this->name, GF_LOG_ERROR, -                                "WRITEV %"PRId64" - %"PRId32",%"PRId64": EINVAL" -                                "(database write at %"PRId64" failed)", -                                fd->inode->ino, count, offset, c_off); -                        break; -                } else { -                        c_off += vector[idx].iov_len; -                } -                op_ret += vector[idx].iov_len; -        } /* for(idx=0;...)... */ - -        if (c_ret) { -                /* write failed after a point, not an error */ -                stbuf.st_size   = bdb_db_fread (bfd, NULL, 0, 0); -                stbuf.st_blocks = BDB_COUNT_BLOCKS (stbuf.st_size, -                                                    stbuf.st_blksize); -                goto out; -        } - -        /* NOTE: we want to increment stbuf->st_size, as stored in db */ -        stbuf.st_size   = op_ret; -        stbuf.st_blocks = BDB_COUNT_BLOCKS (stbuf.st_size, stbuf.st_blksize); -        op_errno = 0; - -out: -        STACK_UNWIND (frame, op_ret, op_errno, &stbuf); -        return 0; -} - -int32_t -bdb_flush (call_frame_t *frame, -           xlator_t *this, -           fd_t *fd) -{ -        int32_t        op_ret   = -1; -        int32_t        op_errno = EPERM; -        struct bdb_fd *bfd      = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, fd, out); - -        BDB_FCTX_GET (fd, this, &bfd); -        if (bfd == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "FLUSH %"PRId64": EBADFD" -                        "(internal fd not found through fd)", -                        fd->inode->ino); -                op_ret = -1; -                op_errno = EBADFD; -                goto out; -        } - -        /* do nothing */ -        op_ret = 0; -        op_errno = 0; - -out: -        STACK_UNWIND (frame, op_ret, op_errno); -        return 0; -} - -int32_t -bdb_release (xlator_t *this, -             fd_t *fd) -{ -        int32_t op_ret = -1; -        int32_t op_errno = EBADFD; -        struct bdb_fd *bfd = NULL; - -        BDB_FCTX_GET (fd, this, &bfd); -        if (bfd == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "RELEASE %"PRId64": EBADFD" -                        "(internal fd not found through fd)", -                        fd->inode->ino); -                op_ret = -1; -                op_errno = EBADFD; -                goto out; -        } - -        bctx_unref (bfd->ctx); -        bfd->ctx = NULL; - -        if (bfd->key) -                GF_FREE (bfd->key); /* we did strdup() in bdb_open() */ -        GF_FREE (bfd); -        op_ret = 0; -        op_errno = 0; - -out: -        return 0; -}/* bdb_release */ - - -int32_t -bdb_fsync (call_frame_t *frame, -           xlator_t *this, -           fd_t *fd, -           int32_t datasync) -{ -        STACK_UNWIND (frame, 0, 0); -        return 0; -}/* bdb_fsync */ - -static int gf_bdb_lk_log; - -int32_t -bdb_lk (call_frame_t *frame, -        xlator_t *this, -        fd_t *fd, -        int32_t cmd, -        struct gf_flock *lock) -{ -        struct gf_flock nullock = {0, }; - -        if (BDB_TIMED_LOG (ENOTSUP, gf_bdb_lk_log)) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "LK %"PRId64": ENOTSUP " -                        "(load \"features/locks\" translator to enable " -                        "lock support)", -                        fd->inode->ino); -        } - -        STACK_UNWIND (frame, -1, ENOTSUP, &nullock); -        return 0; -}/* bdb_lk */ - -/* bdb_lookup - * - * there are four possibilities for a file being looked up: - *  1. file exists and is a directory. - *  2. file exists and is a symlink. - *  3. file exists and is a regular file. - *  4. file does not exist. - * case 1 and 2 are handled by doing lstat() on the @loc. if the file is a - * directory or symlink, lstat() succeeds. lookup continues to check if the - * @loc belongs to case-3 only if lstat() fails. - * to check for case 3, bdb_lookup does a bdb_db_iread() for the given @loc. - * (see description of bdb_db_iread() for more details on how @loc is transformed - * into db handle and key). if check for case 1, 2 and 3 fail, we proceed to - * conclude that file doesn't exist (case 4). - * - * @frame:      call frame. - * @this:       xlator_t of this instance of bdb xlator. - * @loc:        loc_t specifying the file to operate upon. - * @need_xattr: if need_xattr != 0, we are asked to return all the extended - *   attributed of @loc, if any exist, in a dictionary. if @loc is a regular - *   file and need_xattr is set, then we look for value of need_xattr. if - *   need_xattr > sizo-of-the-file @loc, then the file content of @loc is - *   returned in dictionary of xattr with 'glusterfs.content' as dictionary key. - * - * NOTE: bdb currently supports only directories, symlinks and regular files. - * - * NOTE: bdb_lookup returns the 'struct stat' of underlying file itself, in - *  case of directory and symlink (st_ino is modified as bdb allocates its own - *  set of inodes of all files). for regular files, bdb uses 'struct stat' of - *  the database file in which the @loc is stored as templete and modifies - *  st_ino (see bdb_inode_transform for more details), st_mode (can be set in - *  volfile 'option file-mode <mode>'), st_size (exact size of the @loc - *  contents), st_blocks (block count on the underlying filesystem to - *  accomodate st_size, see BDB_COUNT_BLOCKS in bdb.h for more details). - */ -int32_t -bdb_lookup (call_frame_t *frame, -            xlator_t *this, -            loc_t *loc, -            dict_t *xattr_req) -{ -        struct stat stbuf           = {0, }; -        int32_t op_ret              = -1; -        int32_t op_errno            = ENOENT; -        dict_t *xattr               = NULL; -        char *pathname              = NULL; -        char *directory             = NULL; -        char *real_path             = NULL; -        bctx_t *bctx                = NULL; -        char *db_path               = NULL; -        struct bdb_private *private = NULL; -        char *key_string            = NULL; -        int32_t entry_size          = 0; -        char *file_content          = NULL; -        uint64_t   need_xattr       = 0; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); - -        private = this->private; - -        MAKE_REAL_PATH (real_path, this, loc->path); - -        pathname = gf_strdup (loc->path); -        GF_VALIDATE_OR_GOTO (this->name, pathname, out); - -        directory = dirname (pathname); -        GF_VALIDATE_OR_GOTO (this->name, directory, out); - -        if (!strcmp (directory, loc->path)) { -                /* SPECIAL CASE: looking up root */ -                op_ret = lstat (real_path, &stbuf); -                if (op_ret != 0) { -                        op_errno = errno; -                        gf_log (this->name, GF_LOG_DEBUG, -                                "LOOKUP %"PRId64" (%s): %s", -                                loc->ino, loc->path, strerror (op_errno)); -                        goto out; -                } - -                /* bctx_lookup() returns NULL only when its time to wind up, -                 * we should shutdown functioning */ -                bctx = bctx_lookup (B_TABLE(this), (char *)loc->path); -                if (bctx == NULL) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "LOOKUP %"PRId64" (%s): ENOMEM" -                                "(failed to lookup database handle)", -                                loc->ino, loc->path); -                        op_ret   = -1; -                        op_errno = ENOMEM; -                        goto out; -                } - -                stbuf.st_ino = 1; -                stbuf.st_mode = private->dir_mode; - -                op_ret = 0; -                goto out; -        } - -        MAKE_KEY_FROM_PATH (key_string, loc->path); -        op_ret = lstat (real_path, &stbuf); -        if ((op_ret == 0) && (S_ISDIR (stbuf.st_mode))){ -                bctx = bctx_lookup (B_TABLE(this), (char *)loc->path); -                if (bctx == NULL) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "LOOKUP %"PRId64"/%s (%s): ENOMEM" -                                "(failed to lookup database handle)", -                                loc->parent->ino, loc->name, loc->path); -                        op_ret   = -1; -                        op_errno = ENOMEM; -                        goto out; -                } - -                if (loc->ino) { -                        /* revalidating directory inode */ -                        stbuf.st_ino = loc->ino; -                } else { -                        stbuf.st_ino = bdb_inode_transform (loc->parent->ino, -                                                            key_string, -                                                            strlen (key_string)); -                } -                stbuf.st_mode = private->dir_mode; - -                op_ret = 0; -                goto out; - -        } else if (op_ret == 0) { -                /* a symlink */ -                bctx = bctx_parent (B_TABLE(this), loc->path); -                if (bctx == NULL) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "LOOKUP %"PRId64"/%s (%s): ENOMEM" -                                "(failed to lookup database handle)", -                                loc->parent->ino, loc->name, loc->path); -                        op_ret   = -1; -                        op_errno = ENOMEM; -                        goto out; -                } - -                if (loc->ino) { -                        stbuf.st_ino = loc->ino; -                } else { -                        stbuf.st_ino = bdb_inode_transform (loc->parent->ino, -                                                            key_string, -                                                            strlen (key_string)); -                } - -                stbuf.st_mode = private->symlink_mode; - -                op_ret = 0; -                goto out; - -        } - -        /* for regular files */ -        bctx = bctx_parent (B_TABLE(this), loc->path); -        if (bctx == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "LOOKUP %"PRId64"/%s (%s): ENOMEM" -                        "(failed to lookup database handle for parent)", -                        loc->parent->ino, loc->name, loc->path); -                op_ret   = -1; -                op_errno = ENOMEM; -                goto out; -        } - -        if (GF_FILE_CONTENT_REQUESTED(xattr_req, &need_xattr)) { -                entry_size = bdb_db_iread (bctx, key_string, &file_content); -        } else { -                entry_size = bdb_db_iread (bctx, key_string, NULL); -        } - -        op_ret = entry_size; -        if (op_ret == -1) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "LOOKUP %"PRId64"/%s (%s): ENOENT" -                        "(database entry not found)", -                        loc->parent->ino, loc->name, loc->path); -                op_errno = ENOENT; -                goto out; -        } - -        MAKE_REAL_PATH_TO_STORAGE_DB (db_path, this, bctx->directory); -        op_ret = lstat (db_path, &stbuf); -        if (op_ret != 0) { -                op_errno = errno; -                gf_log (this->name, GF_LOG_DEBUG, -                        "LOOKUP %"PRId64"/%s (%s): %s", -                        loc->parent->ino, loc->name, loc->path, -                        strerror (op_errno)); -                goto out; -        } - -        if (entry_size -            && (need_xattr >= entry_size) -            && (file_content)) { -                xattr = dict_new (); -                op_ret = dict_set_dynptr (xattr, "glusterfs.content", -                                          file_content, entry_size); -                if (op_ret < 0) { -                        /* continue without giving file contents */ -                        GF_FREE (file_content); -                } -        } else { -                if (file_content) -                        GF_FREE (file_content); -        } - -        if (loc->ino) { -                /* revalidate */ -                stbuf.st_ino = loc->ino; -                stbuf.st_size = entry_size; -                stbuf.st_blocks = BDB_COUNT_BLOCKS (stbuf.st_size, -                                                    stbuf.st_blksize); -        } else { -                /* fresh lookup, create an inode number */ -                stbuf.st_ino = bdb_inode_transform (loc->parent->ino, -                                                    key_string, -                                                    strlen (key_string)); -                stbuf.st_size = entry_size; -                stbuf.st_blocks = BDB_COUNT_BLOCKS (stbuf.st_size, -                                                    stbuf.st_blksize); -        }/* if(inode->ino)...else */ -        stbuf.st_nlink = 1; -        stbuf.st_mode = private->file_mode; - -        op_ret = 0; -out: -        if (bctx) { -                /* NOTE: bctx_unref always returns success, -                 * see description of bctx_unref for more details */ -                bctx_unref (bctx); -        } - -        if (pathname) -                GF_FREE (pathname); - -        if (xattr) -                dict_ref (xattr); - -        STACK_UNWIND (frame, op_ret, op_errno, loc->inode, &stbuf, xattr); - -        if (xattr) -                dict_unref (xattr); - -        return 0; - -}/* bdb_lookup */ - -int32_t -bdb_stat (call_frame_t *frame, -          xlator_t *this, -          loc_t *loc) -{ - -        struct stat stbuf           = {0,}; -        char *real_path             = NULL; -        int32_t op_ret              = -1; -        int32_t op_errno            = EINVAL; -        struct bdb_private *private = NULL; -        char *db_path               = NULL; -        bctx_t *bctx                = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); - -        private = this->private; -        GF_VALIDATE_OR_GOTO (this->name, private, out); - -        MAKE_REAL_PATH (real_path, this, loc->path); - -        op_ret = lstat (real_path, &stbuf); -        op_errno = errno; -        if (op_ret == 0) { -                /* directory or symlink */ -                stbuf.st_ino = loc->inode->ino; -                if (S_ISDIR(stbuf.st_mode)) -                        stbuf.st_mode = private->dir_mode; -                else -                        stbuf.st_mode = private->symlink_mode; -                /* we are done, lets unwind the stack */ -                goto out; -        } - -        bctx = bctx_parent (B_TABLE(this), loc->path); -        if (bctx == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "STAT %"PRId64" (%s): ENOMEM" -                        "(no database handle for parent)", -                        loc->ino, loc->path); -                op_ret = -1; -                op_errno = ENOMEM; -                goto out; -        } - -        MAKE_REAL_PATH_TO_STORAGE_DB (db_path, this, bctx->directory); -        op_ret = lstat (db_path, &stbuf); -        if (op_ret < 0) { -                op_errno = errno; -                gf_log (this->name, GF_LOG_DEBUG, -                        "STAT %"PRId64" (%s): %s" -                        "(failed to stat on database file)", -                        loc->ino, loc->path, strerror (op_errno)); -                goto out; -        } - -        stbuf.st_size = bdb_db_iread (bctx, loc->path, NULL); -        stbuf.st_blocks = BDB_COUNT_BLOCKS (stbuf.st_size, stbuf.st_blksize); -        stbuf.st_ino = loc->inode->ino; - -out: -        if (bctx) { -                /* NOTE: bctx_unref always returns success, -                 * see description of bctx_unref for more details */ -                bctx_unref (bctx); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - -        return 0; -}/* bdb_stat */ - - - -/* bdb_opendir - in the world of bdb, open/opendir is all about opening - *   correspondind databases. opendir in particular, opens the database for the - *   directory which is to be opened. after opening the database, a cursor to - *   the database is also created. cursor helps us get the dentries one after - *   the other, and cursor maintains the state about current positions in - *   directory. pack 'pointer to db', 'pointer to the cursor' into - *   struct bdb_dir and store it in fd->ctx, we get from our parent xlator. - * - * @frame: call frame - * @this:  our information, as we filled during init() - * @loc:   location information - * @fd:    file descriptor structure (glusterfs internal) - * - * return value - immaterial, async call. - * - */ -int32_t -bdb_opendir (call_frame_t *frame, -             xlator_t *this, -             loc_t *loc, -             fd_t *fd) -{ -        char           *real_path = NULL; -        int32_t         op_ret    = -1; -        int32_t         op_errno  = EINVAL; -        bctx_t         *bctx      = NULL; -        struct bdb_dir *bfd       = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); -        GF_VALIDATE_OR_GOTO (this->name, fd, out); - -        MAKE_REAL_PATH (real_path, this, loc->path); - -        bctx = bctx_lookup (B_TABLE(this), (char *)loc->path); -        if (bctx == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "OPENDIR %"PRId64" (%s): ENOMEM" -                        "(no database handle for directory)", -                        loc->ino, loc->path); -                op_ret = -1; -                op_errno = ENOMEM; -                goto out; -        } - -        bfd = GF_CALLOC (1, sizeof (*bfd), gf_bdb_mt_bdb_fd); -        if (bfd == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "OPENDIR %"PRId64" (%s): ENOMEM" -                        "(failed to allocate memory for internal fd)", -                        loc->ino, loc->path); -                op_ret = -1; -                op_errno = ENOMEM; -                goto err; -        } - -        bfd->dir = opendir (real_path); -        if (bfd->dir == NULL) { -                op_ret   = -1; -                op_errno = errno; -                gf_log (this->name, GF_LOG_DEBUG, -                        "OPENDIR %"PRId64" (%s): %s", -                        loc->ino, loc->path, strerror (op_errno)); -                goto err; -        } - -        /* NOTE: bctx_lookup() return bctx with ref */ -        bfd->ctx = bctx; - -        bfd->path = gf_strdup (real_path); -        if (bfd == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "OPENDIR %"PRId64" (%s): ENOMEM" -                        "(failed to allocate memory for internal fd->path)", -                        loc->ino, loc->path); -                op_ret = -1; -                op_errno = ENOMEM; -                goto err; -        } - -        BDB_FCTX_SET (fd, this, bfd); -        op_ret = 0; -out: -        STACK_UNWIND (frame, op_ret, op_errno, fd); -        return 0; -err: -        if (bctx) -                bctx_unref (bctx); -        if (bfd) { -                if (bfd->dir) -                        closedir (bfd->dir); - -                GF_FREE (bfd); -        } - -        return 0; -}/* bdb_opendir */ - -int32_t -bdb_getdents (call_frame_t *frame, -              xlator_t     *this, -              fd_t         *fd, -              size_t        size, -              off_t         off, -              int32_t       flag) -{ -        struct bdb_dir *bfd        = NULL; -        int32_t         op_ret     = -1; -        int32_t         op_errno   = EINVAL; -        size_t          filled     = 0; -        dir_entry_t     entries    = {0, }; -        dir_entry_t    *this_entry = NULL; -        char           *entry_path     = NULL; -        struct dirent  *dirent         = NULL; -        off_t           in_case    = 0; -        int32_t         this_size  = 0; -        DBC            *cursorp    = NULL; -        int32_t         ret            = -1; -        int32_t         real_path_len  = 0; -        int32_t         entry_path_len = 0; -        int32_t         count          = 0; -        off_t   offset = 0; -        size_t          tmp_name_len   = 0; -        struct stat     db_stbuf       = {0,}; -        struct stat     buf            = {0,}; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, fd, out); - -        BDB_FCTX_GET (fd, this, &bfd); -        if (bfd == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "GETDENTS %"PRId64" - %"GF_PRI_SIZET",%"PRId64 -                        " %o: EBADFD " -                        "(failed to find internal context in fd)", -                        fd->inode->ino, size, off, flag); -                op_errno = EBADFD; -                op_ret   = -1; -                goto out; -        } - -        op_ret = bdb_cursor_open (bfd->ctx, &cursorp); -        if (op_ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "GETDENTS %"PRId64" - %"GF_PRI_SIZET",%"PRId64 -                        ": EBADFD " -                        "(failed to open cursor to database handle)", -                        fd->inode->ino, size, off); -                op_errno = EBADFD; -                goto out; -        } - -        if (off) { -                DBT sec = {0,}, pri = {0,}, val = {0,}; -                sec.data = &(off); -                sec.size = sizeof (off); -                sec.flags = DB_DBT_USERMEM; -                val.dlen = 0; -                val.doff = 0; -                val.flags = DB_DBT_PARTIAL; - -                op_ret = bdb_cursor_get (cursorp, &sec, &pri, &val, DB_SET); -                if (op_ret == DB_NOTFOUND) { -                        offset = off; -                        goto dir_read; -                } -        } - -        while (filled <= size) { -                DBT sec = {0,}, pri = {0,}, val = {0,}; - -                this_entry = NULL; - -                sec.flags = DB_DBT_MALLOC; -                pri.flags = DB_DBT_MALLOC; -                val.dlen = 0; -                val.doff = 0; -                val.flags = DB_DBT_PARTIAL; -                op_ret = bdb_cursor_get (cursorp, &sec, &pri, &val, DB_NEXT); - -                if (op_ret == DB_NOTFOUND) { -                        /* we reached end of the directory */ -                        op_ret = 0; -                        op_errno = 0; -                        break; -                } else if (op_ret < 0) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "GETDENTS %"PRId64" - %"GF_PRI_SIZET -                                ",%"PRId64":" -                                "(failed to read the next entry from database)", -                                fd->inode->ino, size, off); -                        op_errno = ENOENT; -                        break; -                } /* if (op_ret == DB_NOTFOUND)...else if...else */ - -                if (pri.data == NULL) { -                        /* NOTE: currently ignore when we get key.data == NULL. -                         * FIXME: we should not get key.data = NULL */ -                        gf_log (this->name, GF_LOG_DEBUG, -                                "GETDENTS %"PRId64" - %"GF_PRI_SIZET -                                ",%"PRId64":" -                                "(null key read for entry from database)", -                                fd->inode->ino, size, off); -                        continue; -                }/* if(key.data)...else */ - -                this_entry = GF_CALLOC (1, sizeof (*this_entry),  -                                          gf_bdb_mt_dir_entry_t); -                if (this_entry == NULL) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "GETDENTS %"PRId64" - %"GF_PRI_SIZET",%"PRId64 -                                " - %s:" -                                "(failed to allocate memory for an entry)", -                                fd->inode->ino, size, off, strerror (errno)); -                        op_errno = ENOMEM; -                        op_ret   = -1; -                        goto out; -                } - -                this_entry->name = GF_CALLOC (pri.size + 1, sizeof (char), -                                              gf_bdb_mt_char); -                if (this_entry->name == NULL) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "GETDENTS %"PRId64" - %"GF_PRI_SIZET",%"PRId64 -                                " - %s:" -                                "(failed to allocate memory for an " -                                "entry->name)", -                                fd->inode->ino, size, off, strerror (errno)); -                        op_errno = ENOMEM; -                        op_ret   = -1; -                        goto out; -                } - -                memcpy (this_entry->name, pri.data, pri.size); -                this_entry->buf = db_stbuf; -                this_entry->buf.st_size = bdb_db_iread (bfd->ctx, -                                                        this_entry->name, NULL); -                this_entry->buf.st_blocks = BDB_COUNT_BLOCKS ( -                        this_entry->buf.st_size, -                        this_entry->buf.st_blksize); - -                this_entry->buf.st_ino = bdb_inode_transform (fd->inode->ino, -                                                              pri.data, -                                                              pri.size); -                count++; - -                this_entry->next = entries.next; -                this_entry->link = ""; -                entries.next = this_entry; -                /* if size is 0, count can never be = size, -                 * so entire dir is read */ -                if (sec.data) -                        GF_FREE (sec.data); - -                if (pri.data) -                        GF_FREE (pri.data); - -                if (count == size) -                        break; -        }/* while */ -        bdb_cursor_close (bfd->ctx, cursorp); -        op_ret = count; -        op_errno = 0; -        if (count >= size) -                goto out; -dir_read: -        /* hungry kyaa? */ -        if (!offset) { -                rewinddir (bfd->dir); -        } else { -                seekdir (bfd->dir, offset); -        } - -        while (filled <= size) { -                this_entry = NULL; -                this_size  = 0; - -                in_case = telldir (bfd->dir); -                dirent = readdir (bfd->dir); -                if (!dirent) -                        break; - -                if (IS_BDB_PRIVATE_FILE(dirent->d_name)) -                        continue; - -                tmp_name_len = strlen (dirent->d_name); -                if (entry_path_len < (real_path_len + 1 + (tmp_name_len) + 1)) { -                        entry_path_len = real_path_len + tmp_name_len + 1024; -                        entry_path = realloc (entry_path, entry_path_len); -                        if (entry_path == NULL) { -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "GETDENTS %"PRId64" - %"GF_PRI_SIZET"," -                                        "%"PRId64" - %s: (failed to allocate " -                                        "memory for an entry_path)", -                                        fd->inode->ino, size, off, -                                        strerror (errno)); -                                op_errno = ENOMEM; -                                op_ret   = -1; -                                goto out; -                        } -                } - -                memcpy (&entry_path[real_path_len+1], dirent->d_name, -                        tmp_name_len + 1); -                op_ret = stat (entry_path, &buf); -                if (op_ret < 0) { -                        op_errno = errno; -                        gf_log (this->name, GF_LOG_DEBUG, -                                "GETDENTS %"PRId64" - %"GF_PRI_SIZET",%"PRId64 -                                " - %s:" -                                " (failed to stat on an entry '%s')", -                                fd->inode->ino, size, off, -                                strerror (errno), entry_path); -                        goto out; /* FIXME: shouldn't we continue here */ -                } - -                if ((flag == GF_GET_DIR_ONLY) && -                    ((ret != -1) && (!S_ISDIR(buf.st_mode)))) { -                        continue; -                } - -                this_entry = GF_CALLOC (1, sizeof (*this_entry),  -                                          gf_bdb_mt_dir_entry_t); -                if (this_entry == NULL) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "GETDENTS %"PRId64" - %"GF_PRI_SIZET",%"PRId64 -                                " - %s:" -                                "(failed to allocate memory for an entry)", -                                fd->inode->ino, size, off, strerror (errno)); -                        op_errno = ENOMEM; -                        op_ret   = -1; -                        goto out; -                } - -                this_entry->name = gf_strdup (dirent->d_name); -                if (this_entry->name == NULL) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "GETDENTS %"PRId64" - %"GF_PRI_SIZET",%"PRId64 -                                " - %s:" -                                "(failed to allocate memory for an " -                                "entry->name)", -                                fd->inode->ino, size, off, strerror (errno)); -                        op_errno = ENOMEM; -                        op_ret   = -1; -                        goto out; -                } - -                this_entry->buf = buf; - -                this_entry->buf.st_ino = -1; -                if (S_ISLNK(this_entry->buf.st_mode)) { -                        char linkpath[PATH_MAX] = {0,}; -                        ret = readlink (entry_path, linkpath, PATH_MAX); -                        if (ret != -1) { -                                linkpath[ret] = '\0'; -                                this_entry->link = gf_strdup (linkpath); -                        } -                } else { -                        this_entry->link = ""; -                } - -                count++; - -                this_entry->next = entries.next; -                entries.next = this_entry; - -                /* if size is 0, count can never be = size, -                 * so entire dir is read */ -                if (count == size) -                        break; -        } -        op_ret = filled; -        op_errno = 0; - -out: -        gf_log (this->name, GF_LOG_DEBUG, -                "GETDENTS %"PRId64" - %"GF_PRI_SIZET" (%"PRId32")" -                "/%"GF_PRI_SIZET",%"PRId64":" -                "(failed to read the next entry from database)", -                fd->inode->ino, filled, count, size, off); - -        STACK_UNWIND (frame, count, op_errno, &entries); - -        while (entries.next) { -                this_entry = entries.next; -                entries.next = entries.next->next; -                GF_FREE (this_entry->name); -                GF_FREE (this_entry); -        } - -        return 0; -}/* bdb_getdents */ - - -int32_t -bdb_releasedir (xlator_t *this, -                fd_t *fd) -{ -        int32_t op_ret = 0; -        int32_t op_errno = 0; -        struct bdb_dir *bfd = NULL; - -        BDB_FCTX_GET (fd, this, &bfd); -        if (bfd == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "RELEASEDIR %"PRId64": EBADFD", -                        fd->inode->ino); -                op_errno = EBADFD; -                op_ret   = -1; -                goto out; -        } - -        if (bfd->path) { -                GF_FREE (bfd->path); -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "RELEASEDIR %"PRId64": (bfd->path is NULL)", -                        fd->inode->ino); -        } - -        if (bfd->dir) { -                closedir (bfd->dir); -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "RELEASEDIR %"PRId64": (bfd->dir is NULL)", -                        fd->inode->ino); -        } - -        if (bfd->ctx) { -                bctx_unref (bfd->ctx); -        } else { -                gf_log (this->name, GF_LOG_DEBUG, -                        "RELEASEDIR %"PRId64": (bfd->ctx is NULL)", -                        fd->inode->ino); -        } - -        GF_FREE (bfd); - -out: -        return 0; -}/* bdb_releasedir */ - - -int32_t -bdb_readlink (call_frame_t *frame, -              xlator_t *this, -              loc_t *loc, -              size_t size) -{ -        char   *dest      = NULL; -        int32_t op_ret    = -1; -        int32_t op_errno  = EPERM; -        char   *real_path = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); - -        dest = alloca (size + 1); -        GF_VALIDATE_OR_GOTO (this->name, dest, out); - -        MAKE_REAL_PATH (real_path, this, loc->path); - -        op_ret = readlink (real_path, dest, size); - -        if (op_ret > 0) -                dest[op_ret] = 0; - -        if (op_ret == -1) { -                op_errno = errno; -                gf_log (this->name, GF_LOG_DEBUG, -                        "READLINK %"PRId64" (%s): %s", -                        loc->ino, loc->path, strerror (op_errno)); -        } -out: -        STACK_UNWIND (frame, op_ret, op_errno, dest); - -        return 0; -}/* bdb_readlink */ - - -int32_t -bdb_mkdir (call_frame_t *frame, -           xlator_t *this, -           loc_t *loc, -           mode_t mode) -{ -        int32_t op_ret = -1; -        int32_t ret = -1; -        int32_t op_errno = EINVAL; -        char *real_path = NULL; -        struct stat stbuf = {0, }; -        bctx_t *bctx = NULL; -        char *key_string = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); - -        MAKE_KEY_FROM_PATH (key_string, loc->path); -        MAKE_REAL_PATH (real_path, this, loc->path); - -        op_ret = mkdir (real_path, mode); -        if (op_ret < 0) { -                op_errno = errno; -                gf_log (this->name, GF_LOG_DEBUG, -                        "MKDIR %"PRId64" (%s): %s", -                        loc->ino, loc->path, strerror (op_errno)); -                goto out; -        } - -        op_ret = chown (real_path, frame->root->uid, frame->root->gid); -        if (op_ret < 0) { -                op_errno = errno; -                gf_log (this->name, GF_LOG_DEBUG, -                        "MKDIR %"PRId64" (%s): %s " -                        "(failed to do chmod)", -                        loc->ino, loc->path, strerror (op_errno)); -                goto err; -        } - -        op_ret = lstat (real_path, &stbuf); -        if (op_ret < 0) { -                op_errno = errno; -                gf_log (this->name, GF_LOG_DEBUG, -                        "MKDIR %"PRId64" (%s): %s " -                        "(failed to do lstat)", -                        loc->ino, loc->path, strerror (op_errno)); -                goto err; -        } - -        bctx = bctx_lookup (B_TABLE(this), (char *)loc->path); -        if (bctx == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "MKDIR %"PRId64" (%s): ENOMEM" -                        "(no database handle for parent)", -                        loc->ino, loc->path); -                op_ret = -1; -                op_errno = ENOMEM; -                goto err; -        } - -        stbuf.st_ino = bdb_inode_transform (loc->parent->ino, key_string, -                                            strlen (key_string)); - -        goto out; - -err: -        ret = rmdir (real_path); -        if (ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "MKDIR %"PRId64" (%s): %s" -                        "(failed to do rmdir)", -                        loc->ino, loc->path, strerror (errno)); -        } - -out: -        if (bctx) { -                /* NOTE: bctx_unref always returns success, -                 * see description of bctx_unref for more details */ -                bctx_unref (bctx); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, loc->inode, &stbuf); - -        return 0; -}/* bdb_mkdir */ - - -int32_t -bdb_unlink (call_frame_t *frame, -            xlator_t *this, -            loc_t *loc) -{ -        int32_t op_ret    = -1; -        int32_t op_errno  = EINVAL; -        bctx_t *bctx      = NULL; -        char   *real_path = NULL; -        char   *key_string = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); - -        bctx = bctx_parent (B_TABLE(this), loc->path); -        if (bctx == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "UNLINK %"PRId64" (%s): ENOMEM" -                        "(no database handle for parent)", -                        loc->ino, loc->path); -                op_ret = -1; -                op_errno = ENOMEM; -                goto out; -        } - -        MAKE_KEY_FROM_PATH (key_string, loc->path); -        op_ret = bdb_db_iremove (bctx, key_string); -        if (op_ret == DB_NOTFOUND) { -                MAKE_REAL_PATH (real_path, this, loc->path); -                op_ret = unlink (real_path); -                if (op_ret != 0) { -                        op_errno = errno; -                        gf_log (this->name, GF_LOG_DEBUG, -                                "UNLINK %"PRId64" (%s): %s" -                                "(symlink unlink failed)", -                                loc->ino, loc->path, strerror (op_errno)); -                        goto out; -                } -        } else if (op_ret == 0) { -                op_errno = 0; -        } -out: -        if (bctx) { -                /* NOTE: bctx_unref always returns success, -                 * see description of bctx_unref for more details */ -                bctx_unref (bctx); -        } - -        STACK_UNWIND (frame, op_ret, op_errno); - -        return 0; -}/* bdb_unlink */ - - - -static int32_t -bdb_do_rmdir (xlator_t *this, -              loc_t *loc) -{ -        char   *real_path = NULL; -        int32_t ret       = -1; -        bctx_t *bctx      = NULL; -        DB_ENV *dbenv     = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); - -        dbenv = BDB_ENV(this); -        GF_VALIDATE_OR_GOTO (this->name, dbenv, out); - -        MAKE_REAL_PATH (real_path, this, loc->path); - -        bctx = bctx_lookup (B_TABLE(this), loc->path); -        if (bctx == NULL) { -                ret = -ENOMEM; -                goto out; -        } - -        LOCK(&bctx->lock); -        { -                if ((bctx->primary == NULL) -                    || (bctx->secondary == NULL)) { -                        goto unlock; -                } - -                ret = bctx->primary->close (bctx->primary, 0); -                if (ret < 0) { -                        ret = -EINVAL; -                } - -                ret = bctx->secondary->close (bctx->secondary, 0); -                if (ret < 0) { -                        ret = -EINVAL; -                } - -                ret = dbenv->dbremove (dbenv, NULL, bctx->db_path, -                                       "primary", 0); -                if (ret < 0) { -                        ret = -EBUSY; -                } - -                ret = dbenv->dbremove (dbenv, NULL, bctx->db_path, -                                       "secondary", 0); -                if (ret != 0) { -                        ret = -EBUSY; -                } -        } -unlock: -        UNLOCK(&bctx->lock); - -        if (ret) { -                goto out; -        } -        ret = rmdir (real_path); - -out: -        if (bctx) { -                /* NOTE: bctx_unref always returns success, -                 * see description of bctx_unref for more details */ -                bctx_unref (bctx); -        } - -        return ret; -} - -int32_t -bdb_rmdir (call_frame_t *frame, -           xlator_t *this, -           loc_t *loc) -{ -        int32_t op_ret   = -1; -        int32_t op_errno = 0; - -        op_ret = is_dir_empty (this, loc); -        if (op_ret < 0) { -                op_errno = -op_ret; -                gf_log (this->name, GF_LOG_DEBUG, -                        "RMDIR %"PRId64" (%s): %s" -                        "(internal rmdir routine returned error)", -                        loc->ino, loc->path, strerror (op_errno)); -        } else if (op_ret == 0) { -                op_ret   = -1; -                op_errno = ENOTEMPTY; -                gf_log (this->name, GF_LOG_DEBUG, -                        "RMDIR %"PRId64" (%s): ENOTEMPTY", -                        loc->ino, loc->path); -                goto out; -        } - -        op_ret = bdb_do_rmdir (this, loc); -        if (op_ret < 0) { -                op_errno = -op_ret; -                gf_log (this->name, GF_LOG_DEBUG, -                        "RMDIR %"PRId64" (%s): %s" -                        "(internal rmdir routine returned error)", -                        loc->ino, loc->path, strerror (op_errno)); -                goto out; -        } - -out: -        STACK_UNWIND (frame, op_ret, op_errno); - -        return 0; -} /* bdb_rmdir */ - -int32_t -bdb_symlink (call_frame_t *frame, -             xlator_t *this, -             const char *linkname, -             loc_t *loc) -{ -        int32_t             op_ret    = -1; -        int32_t             op_errno  = EINVAL; -        char               *real_path = NULL; -        struct stat         stbuf     = {0,}; -        struct bdb_private *private   = NULL; -        bctx_t             *bctx      = NULL; -        char               *key_string = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); -        GF_VALIDATE_OR_GOTO (this->name, linkname, out); - -        private = this->private; -        GF_VALIDATE_OR_GOTO (this->name, private, out); - -        MAKE_KEY_FROM_PATH (key_string, loc->path); - -        MAKE_REAL_PATH (real_path, this, loc->path); -        op_ret = symlink (linkname, real_path); -        op_errno = errno; -        if (op_ret == 0) { -                op_ret = lstat (real_path, &stbuf); -                if (op_ret != 0) { -                        op_errno = errno; -                        gf_log (this->name, GF_LOG_DEBUG, -                                "SYMLINK %"PRId64" (%s): %s", -                                loc->ino, loc->path, strerror (op_errno)); -                        goto err; -                } - -                bctx = bctx_parent (B_TABLE(this), loc->path); -                if (bctx == NULL) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "SYMLINK %"PRId64" (%s): ENOMEM" -                                "(no database handle for parent)", -                                loc->ino, loc->path); -                        op_ret = -1; -                        op_errno = ENOMEM; -                        goto err; -                } - -                stbuf.st_ino = bdb_inode_transform (loc->parent->ino, -                                                    key_string, -                                                    strlen (key_string)); -                stbuf.st_mode = private->symlink_mode; - -                goto out; -        } -err: -        op_ret = unlink (real_path); -        op_errno = errno; -        if (op_ret != 0) { -               gf_log (this->name, GF_LOG_DEBUG, -                       "SYMLINK %"PRId64" (%s): %s" -                       "(failed to unlink the created symlink)", -                       loc->ino, loc->path, strerror (op_errno)); -        } -        op_ret = -1; -        op_errno = ENOENT; -out: -        if (bctx) { -                /* NOTE: bctx_unref always returns success, -                 * see description of bctx_unref for more details */ -                bctx_unref (bctx); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, loc->inode, &stbuf); - -        return 0; -} /* bdb_symlink */ - -static int -bdb_do_chmod (xlator_t *this, -              const char *path, -              struct stat *stbuf) -{ -        int32_t ret = -1; - -        ret = lchmod (path, stbuf->st_mode); -        if ((ret == -1) && (errno == ENOSYS)) { -                ret = chmod (path, stbuf->st_mode); -        } - -        return ret; -} - -static int -bdb_do_chown (xlator_t *this, -              const char *path, -              struct stat *stbuf, -              int32_t valid) -{ -        int32_t ret = -1; -        uid_t uid = -1; -        gid_t gid = -1; - -        if (valid & GF_SET_ATTR_UID) -                uid = stbuf->st_uid; - -        if (valid & GF_SET_ATTR_GID) -                gid = stbuf->st_gid; - -        ret = lchown (path, uid, gid); - -        return ret; -} - -static int -bdb_do_utimes (xlator_t *this, -               const char *path, -               struct stat *stbuf) -{ -        int32_t ret = -1; -        struct timeval tv[2]     = {{0,},{0,}}; - -        tv[0].tv_sec  = stbuf->st_atime; -        tv[0].tv_usec = ST_ATIM_NSEC (stbuf) / 1000; -        tv[1].tv_sec  = stbuf->st_mtime; -        tv[1].tv_usec = ST_ATIM_NSEC (stbuf) / 1000; - -        ret = lutimes (path, tv); - -        return ret; -} - -int32_t -bdb_setattr (call_frame_t *frame, -             xlator_t *this, -             loc_t *loc, -             struct stat *stbuf, -             int32_t valid) -{ -        int32_t     op_ret    = -1; -        int32_t     op_errno  = EINVAL; -        char       *real_path = NULL; -        struct stat preop     = {0,}; -        struct stat postop    = {0,}; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); - -        MAKE_REAL_PATH (real_path, this, loc->path); -        op_ret = lstat (real_path, &preop); -        op_errno = errno; -        if (op_ret != 0) { -                if (op_errno == ENOENT) { -                        op_errno = EPERM; -                } else { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "CHMOD %"PRId64" (%s): %s" -                                "(pre-op lstat failed)", -                                loc->ino, loc->path, strerror (op_errno)); -                } -                goto out; -        } - -        /* directory or symlink */ -        if (valid & GF_SET_ATTR_MODE) { -                op_ret = bdb_do_chmod (this, real_path, stbuf); -                if (op_ret == -1) { -                        op_errno = errno; -                        gf_log (this->name, GF_LOG_ERROR, -                                "setattr (chmod) on %s failed: %s", loc->path, -                                strerror (op_errno)); -                        goto out; -                } -        } - -        if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)){ -                op_ret = bdb_do_chown (this, real_path, stbuf, valid); -                if (op_ret == -1) { -                        op_errno = errno; -                        gf_log (this->name, GF_LOG_ERROR, -                                "setattr (chown) on %s failed: %s", loc->path, -                                strerror (op_errno)); -                        goto out; -                } -        } - -        if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) { -                op_ret = bdb_do_utimes (this, real_path, stbuf); -                if (op_ret == -1) { -                        op_errno = errno; -                        gf_log (this->name, GF_LOG_ERROR, -                                "setattr (utimes) on %s failed: %s", loc->path, -                                strerror (op_errno)); -                        goto out; -                } -        } - -        op_ret = lstat (real_path, &postop); -        op_errno = errno; -        if (op_ret != 0) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "CHMOD %"PRId64" (%s): %s" -                                "(post-op lstat failed)", -                                loc->ino, loc->path, strerror (op_errno)); -        } - -out: -        STACK_UNWIND (frame, op_ret, op_errno, &preop, &postop); - -        return 0; -}/* bdb_setattr */ - -int32_t -bdb_fsetattr (call_frame_t *frame, -              xlator_t *this, -              fd_t *fd, -              struct stat *stbuf, -              int32_t valid) -{ -        int32_t     op_ret    = -1; -        int32_t     op_errno  = EPERM; -        struct stat preop     = {0,}; -        struct stat postop    = {0,}; - -        STACK_UNWIND (frame, op_ret, op_errno, &preop, &postop); - -        return 0; -}/* bdb_fsetattr */ - - -int32_t -bdb_truncate (call_frame_t *frame, -              xlator_t *this, -              loc_t *loc, -              off_t offset) -{ -        int32_t     op_ret     = -1; -        int32_t     op_errno   = EINVAL; -        char       *real_path  = NULL; -        struct stat stbuf      = {0,}; -        char       *db_path    = NULL; -        bctx_t     *bctx       = NULL; -        char       *key_string = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); - -        bctx = bctx_parent (B_TABLE(this), loc->path); -        if (bctx == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "TRUNCATE %"PRId64" (%s): ENOMEM" -                        "(no database handle for parent)", -                        loc->ino, loc->path); -                op_ret = -1; -                op_errno = ENOMEM; -                goto out; -        } - -        MAKE_REAL_PATH (real_path, this, loc->path); -        MAKE_KEY_FROM_PATH (key_string, loc->path); - -        /* now truncate */ -        MAKE_REAL_PATH_TO_STORAGE_DB (db_path, this, bctx->directory); -        op_ret = lstat (db_path, &stbuf); -        if (op_ret != 0) { -                op_errno = errno; -                gf_log (this->name, GF_LOG_DEBUG, -                        "TRUNCATE %"PRId64" (%s): %s" -                        "(lstat on database file failed)", -                        loc->ino, loc->path, strerror (op_errno)); -                goto out; -        } - -        if (loc->inode->ino) { -                stbuf.st_ino = loc->inode->ino; -        }else { -                stbuf.st_ino = bdb_inode_transform (loc->parent->ino, -                                                    key_string, -                                                    strlen (key_string)); -        } - -        op_ret = bdb_db_itruncate (bctx, key_string); -        if (op_ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "TRUNCATE %"PRId64" (%s): EINVAL" -                        "(truncating entry in  database failed - %s)", -                        loc->ino, loc->path, db_strerror (op_ret)); -                op_errno = EINVAL; /* TODO: better errno */ -        } - -out: -        if (bctx) { -                /* NOTE: bctx_unref always returns success, -                 * see description of bctx_unref for more details */ -                bctx_unref (bctx); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, &stbuf); - -        return 0; -}/* bdb_truncate */ - - -int32_t -bdb_statfs (call_frame_t *frame, -            xlator_t *this, -            loc_t *loc) - -{ -        int32_t        op_ret    = -1; -        int32_t        op_errno  = EINVAL; -        char          *real_path = NULL; -        struct statvfs buf       = {0, }; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); - -        MAKE_REAL_PATH (real_path, this, loc->path); - -        op_ret = statvfs (real_path, &buf); -        op_errno = errno; -out: -        STACK_UNWIND (frame, op_ret, op_errno, &buf); -        return 0; -}/* bdb_statfs */ - -static int gf_bdb_xattr_log; - -/* bdb_setxattr - set extended attributes. - * - * bdb allows setxattr operation only on directories. - *    bdb reservers 'glusterfs.file.<attribute-name>' to operate on the content - *  of the files under the specified directory. - * 'glusterfs.file.<attribute-name>' transforms to contents of file of name - * '<attribute-name>' under specified directory. - * - * @frame: call frame. - * @this:  xlator_t of this instance of bdb xlator. - * @loc:   loc_t specifying the file to operate upon. - * @dict:  list of extended attributes to set on @loc. - * @flags: can be XATTR_REPLACE (replace an existing extended attribute only if - *         it exists) or XATTR_CREATE (create an extended attribute only if it - *         doesn't already exist). - * - * - */ -int32_t -bdb_setxattr (call_frame_t *frame, -              xlator_t *this, -              loc_t *loc, -              dict_t *dict, -              int flags) -{ -        int32_t      op_ret = -1; -        int32_t      op_errno = EINVAL; -        data_pair_t *trav = dict->members_list; -        bctx_t      *bctx = NULL; -        char        *real_path = NULL; -        char        *key = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); -        GF_VALIDATE_OR_GOTO (this->name, dict, out); - -        MAKE_REAL_PATH (real_path, this, loc->path); -        if (!S_ISDIR (loc->inode->st_mode)) { -                op_ret   = -1; -                op_errno = ENOATTR; -                goto out; -        } - -        while (trav) { -                if (GF_FILE_CONTENT_REQUEST(trav->key) ) { -                        key = BDB_KEY_FROM_FREQUEST_KEY(trav->key); - -                        bctx = bctx_lookup (B_TABLE(this), loc->path); -                        if (bctx == NULL) { -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "SETXATTR %"PRId64" (%s) - %s: ENOMEM" -                                        "(no database handle for directory)", -                                        loc->ino, loc->path, key); -                                op_ret = -1; -                                op_errno = ENOMEM; -                                goto out; -                        } - -                        if (flags & XATTR_REPLACE) { -                                op_ret = bdb_db_itruncate (bctx, key); -                                if (op_ret == -1) { -                                        /* key doesn't exist in database */ -                                        gf_log (this->name, GF_LOG_DEBUG, -                                                "SETXATTR %"PRId64" (%s) - %s:" -                                                " (entry not present in " -                                                "database)", -                                                loc->ino, loc->path, key); -                                        op_ret = -1; -                                        op_errno = ENOATTR; -                                        break; -                                } -                                op_ret = bdb_db_iwrite (bctx, key, -                                                        trav->value->data, -                                                        trav->value->len); -                                if (op_ret != 0) { -                                        op_ret   = -1; -                                        op_errno = ENOATTR; -                                        break; -                                } -                        } else { -                                /* fresh create */ -                                op_ret = bdb_db_iwrite (bctx, key, -                                                        trav->value->data, -                                                        trav->value->len); -                                if (op_ret != 0) { -                                        op_ret   = -1; -                                        op_errno = EEXIST; -                                        break; -                                } else { -                                        op_ret = 0; -                                        op_errno = 0; -                                } /* if(op_ret!=0)...else */ -                        } /* if(flags&XATTR_REPLACE)...else */ -                        if (bctx) { -                                /* NOTE: bctx_unref always returns success, see -                                 * description of bctx_unref for more details */ -                                bctx_unref (bctx); -                        } -                } else { -                        /* do plain setxattr */ -                        op_ret = lsetxattr (real_path, -                                            trav->key, trav->value->data, -                                            trav->value->len, -                                            flags); -                        op_errno = errno; - -                        if ((op_errno == ENOATTR) || (op_errno == EEXIST)) { -                                /* don't log, normal behaviour */ -                                ; -                        } else if (BDB_TIMED_LOG (op_errno, gf_bdb_xattr_log)) { -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "SETXATTR %"PRId64" (%s) - %s: %s", -                                        loc->ino, loc->path, trav->key, -                                        strerror (op_errno)); -                                /* do not continue, break out */ -                                break; -                        } else { -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "SETXATTR %"PRId64" (%s) - %s: %s", -                                        loc->ino, loc->path, trav->key, -                                        strerror (op_errno)); -                        } -                } /* if(ZR_FILE_CONTENT_REQUEST())...else */ -                trav = trav->next; -        }/* while(trav) */ -out: -        STACK_UNWIND (frame, op_ret, op_errno); -        return 0; -}/* bdb_setxattr */ - - -/* bdb_gettxattr - get extended attributes. - * - * bdb allows getxattr operation only on directories. - * bdb_getxattr retrieves the whole content of the file, when - * glusterfs.file.<attribute-name> is specified. - * - * @frame: call frame. - * @this:  xlator_t of this instance of bdb xlator. - * @loc:   loc_t specifying the file to operate upon. - * @name:  name of extended attributes to get for @loc. - * - * NOTE: see description of bdb_setxattr for details on how - *     'glusterfs.file.<attribute-name>' is handles by bdb. - */ -int32_t -bdb_getxattr (call_frame_t *frame, -              xlator_t *this, -              loc_t *loc, -              const char *name) -{ -        int32_t op_ret         = 0; -        int32_t op_errno       = 0; -        dict_t *dict           = NULL; -        bctx_t *bctx           = NULL; -        char   *buf            = NULL; -        char   *key_string     = NULL; -        int32_t list_offset    = 0; -        size_t  size           = 0; -        size_t  remaining_size = 0; -        char   *real_path      = NULL; -        char    key[1024]      = {0,}; -        char   *value          = NULL; -        char   *list           = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); -        GF_VALIDATE_OR_GOTO (this->name, name, out); - -        dict = dict_new (); -        GF_VALIDATE_OR_GOTO (this->name, dict, out); - -        if (!S_ISDIR (loc->inode->st_mode)) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "GETXATTR %"PRId64" (%s) - %s: ENOATTR " -                        "(not a directory)", -                        loc->ino, loc->path, name); -                op_ret = -1; -                op_errno = ENOATTR; -                goto out; -        } - -        if (name && GF_FILE_CONTENT_REQUEST(name)) { -                bctx = bctx_lookup (B_TABLE(this), loc->path); -                if (bctx == NULL) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "GETXATTR %"PRId64" (%s) - %s: ENOMEM" -                                "(no database handle for directory)", -                                loc->ino, loc->path, name); -                        op_ret = -1; -                        op_errno = ENOMEM; -                        goto out; -                } - -                key_string = BDB_KEY_FROM_FREQUEST_KEY(name); - -                op_ret = bdb_db_iread (bctx, key_string, &buf); -                if (op_ret == -1) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "GETXATTR %"PRId64" (%s) - %s: ENOATTR" -                                "(attribute not present in database)", -                                loc->ino, loc->path, name); -                        op_errno = ENOATTR; -                        goto out; -                } - -                op_ret = dict_set_dynptr (dict, (char *)name, buf, op_ret); -                if (op_ret < 0) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "GETXATTR %"PRId64" (%s) - %s: ENOATTR" -                                "(attribute present in database, " -                                "dict set failed)", -                                loc->ino, loc->path, name); -                        op_errno = ENODATA; -                } - -                goto out; -        } - -        MAKE_REAL_PATH (real_path, this, loc->path); -        size = sys_llistxattr (real_path, NULL, 0); -        op_errno = errno; -        if (size < 0) { -                if (BDB_TIMED_LOG (op_errno, gf_bdb_xattr_log)) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "GETXATTR %"PRId64" (%s) - %s: %s", -                                loc->ino, loc->path, name, strerror (op_errno)); -                } else { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "GETXATTR %"PRId64" (%s) - %s: %s", -                                loc->ino, loc->path, name, strerror (op_errno)); -                } -                op_ret = -1; -                op_errno = ENOATTR; - -                goto out; -        } - -        if (size == 0) -                goto done; - -        list = alloca (size + 1); -        if (list == NULL) { -                op_ret   = -1; -                op_errno = errno; -                gf_log (this->name, GF_LOG_DEBUG, -                        "GETXATTR %"PRId64" (%s) - %s: %s", -                        loc->ino, loc->path, name, strerror (op_errno)); -        } - -        size = sys_llistxattr (real_path, list, size); -        op_ret   = size; -        if (op_ret == -1) { -                op_errno = errno; -                gf_log (this->name, GF_LOG_DEBUG, -                        "GETXATTR %"PRId64" (%s) - %s: %s", -                        loc->ino, loc->path, name, strerror (op_errno)); -                goto out; -        } - -        remaining_size = size; -        list_offset = 0; -        while (remaining_size > 0) { -                if(*(list+list_offset) == '\0') -                        break; - -                strcpy (key, list + list_offset); - -                op_ret = sys_lgetxattr (real_path, key, NULL, 0); -                if (op_ret == -1) -                        break; - -                value = GF_CALLOC (op_ret + 1, sizeof(char), gf_bdb_mt_char); -                GF_VALIDATE_OR_GOTO (this->name, value, out); - -                op_ret = sys_lgetxattr (real_path, key, value, -                                        op_ret); -                if (op_ret == -1) -                        break; -                value [op_ret] = '\0'; -                op_ret = dict_set_dynptr (dict, key, -                                          value, op_ret); -                if (op_ret < 0) { -                        GF_FREE (value); -                        gf_log (this->name, GF_LOG_DEBUG, -                                "GETXATTR %"PRId64" (%s) - %s: " -                                "(skipping key %s)", -                                loc->ino, loc->path, name, key); -                        continue; -                } -                remaining_size -= strlen (key) + 1; -                list_offset += strlen (key) + 1; -        } /* while(remaining_size>0) */ -done: -out: -        if(bctx) { -                /* NOTE: bctx_unref always returns success, -                 * see description of bctx_unref for more details */ -                bctx_unref (bctx); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, dict); - -        if (dict) -                dict_unref (dict); - -        return 0; -}/* bdb_getxattr */ - - -int32_t -bdb_removexattr (call_frame_t *frame, -                 xlator_t *this, -                 loc_t *loc, -                 const char *name) -{ -        int32_t op_ret    = -1; -        int32_t op_errno  = EINVAL; -        bctx_t *bctx      = NULL; -        char   *real_path = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); -        GF_VALIDATE_OR_GOTO (this->name, name, out); - -        if (!S_ISDIR(loc->inode->st_mode)) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "REMOVEXATTR %"PRId64" (%s) - %s: ENOATTR " -                        "(not a directory)", -                        loc->ino, loc->path, name); -                op_ret = -1; -                op_errno = ENOATTR; -                goto out; -        } - -        if (GF_FILE_CONTENT_REQUEST(name)) { -                bctx = bctx_lookup (B_TABLE(this), loc->path); -                if (bctx == NULL) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "REMOVEXATTR %"PRId64" (%s) - %s: ENOATTR" -                                "(no database handle for directory)", -                                loc->ino, loc->path, name); -                        op_ret = -1; -                        op_errno = ENOATTR; -                        goto out; -                } - -                op_ret = bdb_db_iremove (bctx, name); -                if (op_ret == -1) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "REMOVEXATTR %"PRId64" (%s) - %s: ENOATTR" -                                "(no such attribute in database)", -                                loc->ino, loc->path, name); -                        op_errno = ENOATTR; -                } -                goto out; -        } - -        MAKE_REAL_PATH(real_path, this, loc->path); -        op_ret = lremovexattr (real_path, name); -        op_errno = errno; -        if (op_ret == -1) { -                if (BDB_TIMED_LOG (op_errno, gf_bdb_xattr_log)) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "REMOVEXATTR %"PRId64" (%s) - %s: %s", -                                loc->ino, loc->path, name, strerror (op_errno)); -                } else { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "REMOVEXATTR %"PRId64" (%s) - %s: %s", -                                loc->ino, loc->path, name, strerror (op_errno)); -                } -        } /* if(op_ret == -1) */ -out: -        if (bctx) { -                /* NOTE: bctx_unref always returns success, -                 * see description of bctx_unref for more details */ -                bctx_unref (bctx); -        } - -        STACK_UNWIND (frame, op_ret, op_errno); -        return 0; -}/* bdb_removexattr */ - - -int32_t -bdb_fsyncdir (call_frame_t *frame, -              xlator_t *this, -              fd_t *fd, -              int datasync) -{ -        int32_t op_ret = -1; -        int32_t op_errno = EINVAL; -        struct bdb_fd *bfd = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, fd, out); - -        BDB_FCTX_GET (fd, this, &bfd); -        if (bfd == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "FSYNCDIR %"PRId64": EBADFD" -                        "(failed to find internal context from fd)", -                        fd->inode->ino); -                op_errno = EBADFD; -                op_ret   = -1; -        } - -out: -        STACK_UNWIND (frame, op_ret, op_errno); - -        return 0; -}/* bdb_fsycndir */ - - -int32_t -bdb_access (call_frame_t *frame, -            xlator_t *this, -            loc_t *loc, -            int32_t mask) -{ -        int32_t op_ret = -1; -        int32_t op_errno = EINVAL; -        char *real_path = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); - -        MAKE_REAL_PATH (real_path, this, loc->path); - -        op_ret = access (real_path, mask); -        op_errno = errno; -        /* TODO: implement for db entries */ -out: -        STACK_UNWIND (frame, op_ret, op_errno); -        return 0; -}/* bdb_access */ - - -int32_t -bdb_ftruncate (call_frame_t *frame, -               xlator_t *this, -               fd_t *fd, -               off_t offset) -{ -        int32_t op_ret = -1; -        int32_t op_errno = EPERM; -        struct stat buf = {0,}; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, fd, out); -        /* TODO: impelement */ -out: -        STACK_UNWIND (frame, op_ret, op_errno, &buf); - -        return 0; -} - - - -int32_t -bdb_setdents (call_frame_t *frame, -              xlator_t *this, -              fd_t *fd, -              int32_t flags, -              dir_entry_t *entries, -              int32_t count) -{ -        int32_t op_ret = -1, op_errno = EINVAL; -        char *entry_path = NULL; -        int32_t real_path_len = 0; -        int32_t entry_path_len = 0; -        int32_t ret = 0; -        struct bdb_dir *bfd = NULL; -        dir_entry_t *trav = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, fd, out); -        GF_VALIDATE_OR_GOTO (this->name, entries, out); - -        BDB_FCTX_GET (fd, this, &bfd); -        if (bfd == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "SETDENTS %"PRId64": EBADFD", -                        fd->inode->ino); -                op_errno = EBADFD; -                op_ret   = -1; -                goto out; -        } - -        real_path_len = strlen (bfd->path); -        entry_path_len = real_path_len + 256; -        entry_path = GF_CALLOC (1, entry_path_len, gf_bdb_mt_char); -        GF_VALIDATE_OR_GOTO (this->name, entry_path, out); - -        strcpy (entry_path, bfd->path); -        entry_path[real_path_len] = '/'; - -        trav = entries->next; -        while (trav) { -                char pathname[PATH_MAX] = {0,}; -                strcpy (pathname, entry_path); -                strcat (pathname, trav->name); - -                if (S_ISDIR(trav->buf.st_mode)) { -                        /* If the entry is directory, create it by calling -                         * 'mkdir'. If directory is not present, it will be -                         * created, if its present, no worries even if it fails. -                         */ -                        ret = mkdir (pathname, trav->buf.st_mode); -                        if ((ret == -1) && (errno != EEXIST)) { -                                op_errno = errno; -                                op_ret   = ret; -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "SETDENTS %"PRId64" - %s: %s " -                                        "(mkdir failed)", -                                        fd->inode->ino, pathname, -                                        strerror (op_errno)); -                                goto loop; -                        } - -                        /* Change the mode -                         * NOTE: setdents tries its best to restore the state -                         *       of storage. if chmod and chown fail, they can -                         *       be ignored now */ -                        ret = chmod (pathname, trav->buf.st_mode); -                        if (ret < 0) { -                                op_ret   = -1; -                                op_errno = errno; -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "SETDENTS %"PRId64" - %s: %s " -                                        "(chmod failed)", -                                        fd->inode->ino, pathname, -                                        strerror (op_errno)); -                                goto loop; -                        } -                        /* change the ownership */ -                        ret = chown (pathname, trav->buf.st_uid, -                                     trav->buf.st_gid); -                        if (ret != 0) { -                                op_ret   = -1; -                                op_errno = errno; -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "SETDENTS %"PRId64" - %s: %s " -                                        "(chown failed)", -                                        fd->inode->ino, pathname, -                                        strerror (op_errno)); -                                goto loop; -                        } -                } else if ((flags == GF_SET_IF_NOT_PRESENT) || -                           (flags != GF_SET_DIR_ONLY)) { -                        /* Create a 0 byte file here */ -                        if (S_ISREG (trav->buf.st_mode)) { -                                op_ret = bdb_db_icreate (bfd->ctx, -                                                         trav->name); -                                if (op_ret < 0) { -                                        gf_log (this->name, GF_LOG_DEBUG, -                                                "SETDENTS %"PRId64" (%s) - %s: " -                                                "%s (database entry creation" -                                                " failed)", -                                                fd->inode->ino, -                                                bfd->ctx->directory, trav->name, -                                                strerror (op_errno)); -                                } -                        } else if (S_ISLNK (trav->buf.st_mode)) { -                                /* TODO: impelement */; -                        } else { -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "SETDENTS %"PRId64" (%s) - %s mode=%o: " -                                        "(unsupported file type)", -                                        fd->inode->ino, -                                        bfd->ctx->directory, trav->name, -                                        trav->buf.st_mode); -                        } /* if(S_ISREG())...else */ -                } /* if(S_ISDIR())...else if */ -        loop: -                /* consider the next entry */ -                trav = trav->next; -        } /* while(trav) */ - -out: -        STACK_UNWIND (frame, op_ret, op_errno); - -        GF_FREE (entry_path); -        return 0; -} - -int32_t -bdb_fstat (call_frame_t *frame, -           xlator_t *this, -           fd_t *fd) -{ -        int32_t        op_ret   = -1; -        int32_t        op_errno = EINVAL; -        struct stat    stbuf    = {0,}; -        struct bdb_fd *bfd      = NULL; -        bctx_t        *bctx     = NULL; -        char          *db_path  = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, fd, out); - -        BDB_FCTX_GET (fd, this, &bfd); -        if (bfd == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "FSTAT %"PRId64": EBADFD " -                        "(failed to find internal context in fd)", -                        fd->inode->ino); -                op_errno = EBADFD; -                op_ret   = -1; -                goto out; -        } - -        bctx = bfd->ctx; - -        MAKE_REAL_PATH_TO_STORAGE_DB (db_path, this, bctx->directory); -        op_ret = lstat (db_path, &stbuf); -        op_errno = errno; -        if (op_ret != 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "FSTAT %"PRId64": %s" -                        "(failed to stat database file %s)", -                        fd->inode->ino, strerror (op_errno), db_path); -                goto out; -        } - -        stbuf.st_ino = fd->inode->ino; -        stbuf.st_size = bdb_db_fread (bfd, NULL, 0, 0); -        stbuf.st_blocks = BDB_COUNT_BLOCKS (stbuf.st_size, stbuf.st_blksize); - -out: -        STACK_UNWIND (frame, op_ret, op_errno, &stbuf); -        return 0; -} - -gf_dirent_t * -gf_dirent_for_namen (const char *name, -                     size_t len) -{ -        char *tmp_name = NULL; - -        tmp_name = alloca (len + 1); - -        memcpy (tmp_name, name, len); - -        tmp_name[len] = 0; - -        return gf_dirent_for_name (tmp_name); -} - -int32_t -bdb_readdir (call_frame_t *frame, -             xlator_t *this, -             fd_t *fd, -             size_t size, -             off_t off) -{ -        struct bdb_dir *bfd        = NULL; -        int32_t         op_ret     = -1; -        int32_t         op_errno   = EINVAL; -        size_t          filled     = 0; -        gf_dirent_t    *this_entry = NULL; -        gf_dirent_t     entries; -        struct dirent  *entry      = NULL; -        off_t           in_case    = 0; -        int32_t         this_size  = 0; -        DBC            *cursorp    = NULL; -        int32_t count = 0; -        off_t   offset = 0; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, fd, out); - -        INIT_LIST_HEAD (&entries.list); - -        BDB_FCTX_GET (fd, this, &bfd); -        if (bfd == NULL) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "READDIR %"PRId64" - %"GF_PRI_SIZET",%"PRId64": EBADFD " -                        "(failed to find internal context in fd)", -                        fd->inode->ino, size, off); -                op_errno = EBADFD; -                op_ret   = -1; -                goto out; -        } - -        op_ret = bdb_cursor_open (bfd->ctx, &cursorp); -        if (op_ret < 0) { -                gf_log (this->name, GF_LOG_DEBUG, -                        "READDIR %"PRId64" - %"GF_PRI_SIZET",%"PRId64": EBADFD " -                        "(failed to open cursor to database handle)", -                        fd->inode->ino, size, off); -                op_errno = EBADFD; -                goto out; -        } - -        if (off) { -                DBT sec = {0,}, pri = {0,}, val = {0,}; -                sec.data = &(off); -                sec.size = sizeof (off); -                sec.flags = DB_DBT_USERMEM; -                val.dlen = 0; -                val.doff = 0; -                val.flags = DB_DBT_PARTIAL; - -                op_ret = bdb_cursor_get (cursorp, &sec, &pri, &val, DB_SET); -                if (op_ret == DB_NOTFOUND) { -                        offset = off; -                        goto dir_read; -                } -        } - -        while (filled <= size) { -                DBT sec = {0,}, pri = {0,}, val = {0,}; - -                this_entry = NULL; - -                sec.flags = DB_DBT_MALLOC; -                pri.flags = DB_DBT_MALLOC; -                val.dlen = 0; -                val.doff = 0; -                val.flags = DB_DBT_PARTIAL; -                op_ret = bdb_cursor_get (cursorp, &sec, &pri, &val, DB_NEXT); - -                if (op_ret == DB_NOTFOUND) { -                        /* we reached end of the directory */ -                        op_ret = 0; -                        op_errno = 0; -                        break; -                } else if (op_ret < 0) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "READDIR %"PRId64" - %"GF_PRI_SIZET",%"PRId64":" -                                "(failed to read the next entry from database)", -                                fd->inode->ino, size, off); -                        op_errno = ENOENT; -                        break; -                } /* if (op_ret == DB_NOTFOUND)...else if...else */ - -                if (pri.data == NULL) { -                        /* NOTE: currently ignore when we get key.data == NULL. -                         * TODO: we should not get key.data = NULL */ -                        gf_log (this->name, GF_LOG_DEBUG, -                                "READDIR %"PRId64" - %"GF_PRI_SIZET",%"PRId64":" -                                "(null key read for entry from database)", -                                fd->inode->ino, size, off); -                        continue; -                }/* if(key.data)...else */ -                count++; -                this_size = bdb_dirent_size (&pri); -                if (this_size + filled > size) -                        break; -                /* TODO - consider endianness here */ -                this_entry = gf_dirent_for_namen ((const char *)pri.data, -                                                  pri.size); - -                this_entry->d_ino = bdb_inode_transform (fd->inode->ino, -                                                         pri.data, -                                                         pri.size); -                this_entry->d_off = *(uint32_t *)sec.data; -                this_entry->d_type = 0; -                this_entry->d_len = pri.size + 1; - -                if (sec.data) { -                        GF_FREE (sec.data); -                } - -                if (pri.data) -                        GF_FREE (pri.data); - -                list_add_tail (&this_entry->list, &entries.list); - -                filled += this_size; -        }/* while */ -        bdb_cursor_close (bfd->ctx, cursorp); -        op_ret = filled; -        op_errno = 0; -        if (filled >= size) { -                goto out; -        } -dir_read: -        /* hungry kyaa? */ -        if (!offset) { -                rewinddir (bfd->dir); -        } else { -                seekdir (bfd->dir, offset); -        } - -        while (filled <= size) { -                this_entry = NULL; -                entry      = NULL; -                this_size  = 0; - -                in_case = telldir (bfd->dir); -                entry = readdir (bfd->dir); -                if (!entry) -                        break; - -                if (IS_BDB_PRIVATE_FILE(entry->d_name)) -                        continue; - -                this_size = dirent_size (entry); - -                if (this_size + filled > size) { -                        seekdir (bfd->dir, in_case); -                        break; -                } - -                count++; - -                this_entry = gf_dirent_for_name (entry->d_name); -                this_entry->d_ino = entry->d_ino; - -                this_entry->d_off = entry->d_off; - -                this_entry->d_type = entry->d_type; -                this_entry->d_len = entry->d_reclen; - - -                list_add_tail (&this_entry->list, &entries.list); - -                filled += this_size; -        } -        op_ret = filled; -        op_errno = 0; - -out: -        gf_log (this->name, GF_LOG_DEBUG, -                "READDIR %"PRId64" - %"GF_PRI_SIZET" (%"PRId32")" -                "/%"GF_PRI_SIZET",%"PRId64":" -                "(failed to read the next entry from database)", -                fd->inode->ino, filled, count, size, off); - -        STACK_UNWIND (frame, count, op_errno, &entries); - -        gf_dirent_free (&entries); - -        return 0; -} - - -int32_t -bdb_stats (call_frame_t *frame, -           xlator_t *this, -           int32_t flags) - -{ -        int32_t op_ret   = 0; -        int32_t op_errno = 0; - -        struct xlator_stats xlstats = {0, }, *stats = NULL; -        struct statvfs buf = {0,}; -        struct timeval tv; -        struct bdb_private *private = NULL; -        int64_t avg_read = 0; -        int64_t avg_write = 0; -        int64_t _time_ms = 0; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); - -        private = (struct bdb_private *)(this->private); -        stats = &xlstats; - -        op_ret = statvfs (private->export_path, &buf); -        if (op_ret != 0) { -                op_errno = errno; -                gf_log (this->name, GF_LOG_DEBUG, -                        "STATS %s: %s", -                        private->export_path, strerror (op_errno)); -                goto out; -        } - -        stats->nr_files = private->stats.nr_files; - -        /* client info is maintained at FSd */ -        stats->nr_clients = private->stats.nr_clients; - -        /* Number of Free block in the filesystem. */ -        stats->free_disk       = buf.f_bfree * buf.f_bsize; -        stats->total_disk_size = buf.f_blocks * buf.f_bsize; /* */ -        stats->disk_usage      = (buf.f_blocks - buf.f_bavail) * buf.f_bsize; - -        /* Calculate read and write usage */ -        gettimeofday (&tv, NULL); - -        /* Read */ -        _time_ms = (tv.tv_sec - private->init_time.tv_sec) * 1000 + -                ((tv.tv_usec - private->init_time.tv_usec) / 1000); - -        avg_read  = (_time_ms) ? (private->read_value / _time_ms) : 0;/* KBps */ -        avg_write = (_time_ms) ? (private->write_value / _time_ms) : 0; - -        _time_ms = (tv.tv_sec - private->prev_fetch_time.tv_sec) * 1000 + -                ((tv.tv_usec - private->prev_fetch_time.tv_usec) / 1000); -        if (_time_ms -            && ((private->interval_read / _time_ms) > private->max_read)) { -                private->max_read = (private->interval_read / _time_ms); -        } -        if (_time_ms -            && ((private->interval_write / _time_ms) > private->max_write)) { -                private->max_write = private->interval_write / _time_ms; -        } - -        stats->read_usage = avg_read / private->max_read; -        stats->write_usage = avg_write / private->max_write; - -        gettimeofday (&(private->prev_fetch_time), NULL); -        private->interval_read = 0; -        private->interval_write = 0; - -out: -        STACK_UNWIND (frame, op_ret, op_errno, stats); -        return 0; -} - - -int32_t -bdb_inodelk (call_frame_t *frame, xlator_t *this, -             const char *volume, loc_t *loc, int32_t cmd, struct gf_flock *lock) -{ -        gf_log (this->name, GF_LOG_ERROR, -                "glusterfs internal locking request. please load " -                "'features/locks' translator to enable glusterfs " -                "support"); - -        STACK_UNWIND (frame, -1, ENOSYS); -        return 0; -} - - -int32_t -bdb_finodelk (call_frame_t *frame, xlator_t *this, -              const char *volume, fd_t *fd, int32_t cmd, struct gf_flock *lock) -{ -        gf_log (this->name, GF_LOG_ERROR, -                "glusterfs internal locking request. please load " -                "'features/locks' translator to enable glusterfs " -                "support"); - -        STACK_UNWIND (frame, -1, ENOSYS); -        return 0; -} - - -int32_t -bdb_entrylk (call_frame_t *frame, xlator_t *this, -             const char *volume, loc_t *loc, const char *basename, -             entrylk_cmd cmd, entrylk_type type) -{ -        gf_log (this->name, GF_LOG_ERROR, -                "glusterfs internal locking request. please load " -                "'features/locks' translator to enable glusterfs " -                "support"); - -        STACK_UNWIND (frame, -1, ENOSYS); -        return 0; -} - - -int32_t -bdb_fentrylk (call_frame_t *frame, xlator_t *this, -              const char *volume, fd_t *fd, const char *basename, -              entrylk_cmd cmd, entrylk_type type) -{ -        gf_log (this->name, GF_LOG_ERROR, -                "glusterfs internal locking request. please load " -                "'features/locks' translator to enable glusterfs " -                "support"); - -        STACK_UNWIND (frame, -1, ENOSYS); -        return 0; -} - -int32_t -bdb_checksum (call_frame_t *frame, -              xlator_t *this, -              loc_t *loc, -              int32_t flag) -{ -        char          *real_path = NULL; -        DIR           *dir       = NULL; -        struct dirent *dirent    = NULL; -        uint8_t        file_checksum[NAME_MAX] = {0,}; -        uint8_t        dir_checksum[NAME_MAX]  = {0,}; -        int32_t        op_ret   = -1; -        int32_t        op_errno = EINVAL; -        int32_t        idx = 0, length = 0; -        bctx_t        *bctx    = NULL; -        DBC           *cursorp = NULL; -        char          *data    = NULL; -        uint8_t        no_break = 1; - -        GF_VALIDATE_OR_GOTO ("bdb", frame, out); -        GF_VALIDATE_OR_GOTO ("bdb", this, out); -        GF_VALIDATE_OR_GOTO (this->name, loc, out); - -        MAKE_REAL_PATH (real_path, this, loc->path); - -        { -                dir = opendir (real_path); -                op_errno = errno; -                GF_VALIDATE_OR_GOTO (this->name, dir, out); -                while ((dirent = readdir (dir))) { -                        if (!dirent) -                                break; - -                        if (IS_BDB_PRIVATE_FILE(dirent->d_name)) -                                continue; - -                        length = strlen (dirent->d_name); -                        for (idx = 0; idx < length; idx++) -                                dir_checksum[idx] ^= dirent->d_name[idx]; -                } /* while((dirent...)) */ -                closedir (dir); -        } - -        { -                bctx = bctx_lookup (B_TABLE(this), (char *)loc->path); -                if (bctx == NULL) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "CHECKSUM %"PRId64" (%s): ENOMEM" -                                "(failed to lookup database handle)", -                                loc->inode->ino, loc->path); -                        op_ret   = -1; -                        op_errno = ENOMEM; -                        goto out; -                } - -                op_ret = bdb_cursor_open (bctx, &cursorp); -                if (op_ret < 0) { -                        gf_log (this->name, GF_LOG_DEBUG, -                                "CHECKSUM %"PRId64" (%s): EBADFD" -                                "(failed to open cursor to database handle)", -                                loc->inode->ino, loc->path); -                        op_ret   = -1; -                        op_errno = EBADFD; -                        goto out; -                } - - -                do { -                        DBT key = {0,}, value = {0,}, sec = {0,}; - -                        key.flags = DB_DBT_MALLOC; -                        value.doff = 0; -                        value.dlen = 0; -                        op_ret = bdb_cursor_get (cursorp, &sec, &key, -                                                 &value, DB_NEXT); - -                        if (op_ret == DB_NOTFOUND) { -                                op_ret = 0; -                                op_errno = 0; -                                no_break = 0; -                        } else if (op_ret == 0){ -                                /* successfully read */ -                                data = key.data; -                                length = key.size; -                                for (idx = 0; idx < length; idx++) -                                        file_checksum[idx] ^= data[idx]; - -                                GF_FREE (key.data); -                        } else { -                                gf_log (this->name, GF_LOG_DEBUG, -                                        "CHECKSUM %"PRId64" (%s)", -                                        loc->inode->ino, loc->path); -                                op_ret = -1; -                                op_errno = ENOENT; /* TODO: watch errno */ -                                no_break = 0; -                        }/* if(op_ret == DB_NOTFOUND)...else if...else */ -                } while (no_break); -                bdb_cursor_close (bctx, cursorp); -        } -out: -        if (bctx) { -                /* NOTE: bctx_unref always returns success, -                 * see description of bctx_unref for more details */ -                bctx_unref (bctx); -        } - -        STACK_UNWIND (frame, op_ret, op_errno, file_checksum, dir_checksum); - -        return 0; -} - -/** - * notify - when parent sends PARENT_UP, send CHILD_UP event from here - */ -int32_t -notify (xlator_t *this, -        int32_t event, -        void *data, -        ...) -{ -        switch (event) -        { -        case GF_EVENT_PARENT_UP: -        { -                /* Tell the parent that bdb xlator is up */ -                GF_ASSERT ((this->private != NULL) && -                        (BDB_ENV(this) != NULL)); -                default_notify (this, GF_EVENT_CHILD_UP, data); -        } -        break; -        default: -                /* */ -                break; -        } -        return 0; -} - - -int32_t -mem_acct_init (xlator_t *this) -{ -        int     ret = -1; - -        if (!this) -                return ret; - -        ret = xlator_mem_acct_init (this, gf_bdb_mt_end + 1); -         -        if (ret != 0) { -                gf_log(this->name, GF_LOG_ERROR, "Memory accounting init" -                                "failed"); -                return ret; -        } - -        return ret; -} - -/** - * init - - */ -int32_t -init (xlator_t *this) -{ -        int32_t             ret = -1; -        struct stat         buf = {0,}; -        struct bdb_private *_private = NULL; -        char               *directory = NULL; -        bctx_t             *bctx = NULL; - -        GF_VALIDATE_OR_GOTO ("bdb", this, out); - -        if (this->children) { -                gf_log (this->name, GF_LOG_ERROR, -                        "'storage/bdb' translator should be used as leaf node " -                        "in translator tree. please remove the subvolumes" -                        " specified and retry."); -                goto err; -        } - -        if (!this->parents) { -                gf_log (this->name, GF_LOG_ERROR, -                        "'storage/bdb' translator needs at least one among " -                        "'protocol/server' or 'mount/fuse' translator as " -                        "parent. please add 'protocol/server' or 'mount/fuse' " -                        "as parent of 'storage/bdb' and retry. or you can also" -                        " try specifying mount-point on command-line."); -                goto err; -        } - -        _private = GF_CALLOC (1, sizeof (*_private), gf_bdb_mt_bdb_private); -        if (_private == NULL) { -                gf_log (this->name, GF_LOG_ERROR, -                        "could not allocate memory for 'storage/bdb' " -                        "configuration data-structure. cannot continue from " -                        "here"); -                goto err; -        } - - -        ret = dict_get_str (this->options, "directory", &directory); -        if (ret < 0) { -                gf_log (this->name, GF_LOG_ERROR, -                        "'storage/bdb' needs at least " -                        "'option directory <path-to-export-directory>' as " -                        "minimal configuration option. please specify an " -                        "export directory using " -                        "'option directory <path-to-export-directory>' and " -                        "retry."); -                goto err; -        } - -        umask (000); /* umask `masking' is done at the client side */ - -        /* Check whether the specified directory exists, if not create it. */ -        ret = stat (directory, &buf); -        if (ret < 0) { -                gf_log (this->name, GF_LOG_ERROR, -                        "specified export path '%s' does not exist. " -                        "please create the export path '%s' and retry.", -                        directory, directory); -                goto err; -        } else if (!S_ISDIR (buf.st_mode)) { -                gf_log (this->name, GF_LOG_ERROR, -                        "specified export path '%s' is not a directory. " -                        "please specify a valid and existing directory as " -                        "export directory and retry.", -                        directory); -                goto err; -        } else { -                ret = 0; -        } - - -        _private->export_path = gf_strdup (directory); -        if (_private->export_path == NULL) { -                gf_log (this->name, GF_LOG_ERROR, -                        "could not allocate memory for 'storage/bdb' " -                        "configuration data-structure. cannot continue from " -                        "here"); -                goto err; -        } - -        _private->export_path_length = strlen (_private->export_path); - -        { -                /* Stats related variables */ -                gettimeofday (&_private->init_time, NULL); -                gettimeofday (&_private->prev_fetch_time, NULL); -                _private->max_read = 1; -                _private->max_write = 1; -        } - -        this->private = (void *)_private; - -        { -                ret = bdb_db_init (this, this->options); - -                if (ret < 0){ -                        gf_log (this->name, GF_LOG_ERROR, -                                "database environment initialisation failed. " -                                "manually run database recovery tool and " -                                "retry to run glusterfs"); -                        goto err; -                } else { -                        bctx = bctx_lookup (_private->b_table, "/"); -                        /* NOTE: we are not doing bctx_unref() for root bctx, -                         *      let it remain in active list forever */ -                        if (bctx == NULL) { -                                gf_log (this->name, GF_LOG_ERROR, -                                        "could not allocate memory for " -                                        "'storage/bdb' configuration data-" -                                        "structure. cannot continue from " -                                        "here"); -                                goto err; -                        } else { -                                ret = 0; -                                goto out; -                        } -                } -        } -err: -        if (_private) { -                if (_private->export_path) -                        GF_FREE (_private->export_path); - -                GF_FREE (_private); -        } -out: -        return ret; -} - -void -bctx_cleanup (struct list_head *head) -{ -        bctx_t *trav    = NULL; -        bctx_t *tmp     = NULL; -        DB     *storage = NULL; -        DB     *secondary = NULL; - -        list_for_each_entry_safe (trav, tmp, head, list) { -                LOCK (&trav->lock); -                { -                        storage = trav->primary; -                        trav->primary = NULL; - -                        secondary = trav->secondary; -                        trav->secondary = NULL; - -                        list_del_init (&trav->list); -                } -                UNLOCK (&trav->lock); - -                if (storage) { -                        storage->close (storage, 0); -                        storage = NULL; -                } - -                if (secondary) { -                        secondary->close (secondary, 0); -                        secondary = NULL; -                } -        } -        return; -} - -void -fini (xlator_t *this) -{ -        struct bdb_private *private = NULL; -        int32_t             ret     = 0; - -        private = this->private; - -        if (B_TABLE(this)) { -                /* close all the dbs from lru list */ -                bctx_cleanup (&(B_TABLE(this)->b_lru)); -                bctx_cleanup (&(B_TABLE(this)->active)); - -                if (BDB_ENV(this)) { -                        LOCK (&private->active_lock); -                        { -                                private->active = 0; -                        } -                        UNLOCK (&private->active_lock); - -                        ret = pthread_join (private->checkpoint_thread, NULL); -                        if (ret != 0) { -                                gf_log (this->name, GF_LOG_CRITICAL, -                                        "could not complete checkpointing " -                                        "database environment. this might " -                                        "result in inconsistencies in few" -                                        " recent data and meta-data " -                                        "operations"); -                        } - -                        BDB_ENV(this)->close (BDB_ENV(this), 0); -                } else { -                        /* impossible to reach here */ -                } - -                GF_FREE (B_TABLE(this)); -        } -        GF_FREE (private); -        return; -} - - -struct xlator_fops fops = { -        .lookup      = bdb_lookup, -        .stat        = bdb_stat, -        .opendir     = bdb_opendir, -        .readdir     = bdb_readdir, -        .readlink    = bdb_readlink, -        .mknod       = bdb_mknod, -        .mkdir       = bdb_mkdir, -        .unlink      = bdb_unlink, -        .rmdir       = bdb_rmdir, -        .symlink     = bdb_symlink, -        .rename      = bdb_rename, -        .link        = bdb_link, -        .truncate    = bdb_truncate, -        .create      = bdb_create, -        .open        = bdb_open, -        .readv       = bdb_readv, -        .writev      = bdb_writev, -        .statfs      = bdb_statfs, -        .flush       = bdb_flush, -        .fsync       = bdb_fsync, -        .setxattr    = bdb_setxattr, -        .getxattr    = bdb_getxattr, -        .removexattr = bdb_removexattr, -        .fsyncdir    = bdb_fsyncdir, -        .access      = bdb_access, -        .ftruncate   = bdb_ftruncate, -        .fstat       = bdb_fstat, -        .lk          = bdb_lk, -        .inodelk     = bdb_inodelk, -        .finodelk    = bdb_finodelk, -        .entrylk     = bdb_entrylk, -        .fentrylk    = bdb_fentrylk, -        .setdents    = bdb_setdents, -        .getdents    = bdb_getdents, -        .checksum    = bdb_checksum, -        .setattr     = bdb_setattr, -        .fsetattr    = bdb_fsetattr, -}; - -struct xlator_cbks cbks = { -        .release    = bdb_release, -        .releasedir = bdb_releasedir -}; - - -struct volume_options options[] = { -        { .key  = { "directory" }, -          .type = GF_OPTION_TYPE_PATH, -          .description = "export directory" -        }, -        { .key  = { "logdir" }, -          .type = GF_OPTION_TYPE_PATH, -          .description = "directory to be used by libdb for writing" -                         "transaction logs. NOTE: in absence of 'logdir' " -                         "export directory itself will be used as 'logdir' also" -        }, -        { .key  = { "errfile" }, -          .type = GF_OPTION_TYPE_PATH, -          .description = "path to be used for libdb error logging. " -                         "NOTE: absence of 'errfile' will disable any " -                         "error logging by libdb." -        }, -        { .key  = { "dir-mode" }, -          .type = GF_OPTION_TYPE_ANY /* base 8 number */ -        }, -        { .key  = { "file-mode" }, -          .type = GF_OPTION_TYPE_ANY, -          .description = "file mode for regular files. stat() on a regular file" -                         " returns the mode specified by this option. " -                         "NOTE: specify value in octal" -        }, -        { .key  = { "page-size" }, -          .type = GF_OPTION_TYPE_SIZET, -          .min  = 512, -          .max  = 16384, -          .description = "size of pages used to hold data by libdb. set it to " -                         "block size of exported filesystem for " -                         "optimal performance" -        }, -        { .key  = { "open-db-lru-limit" }, -          .type = GF_OPTION_TYPE_INT, -          .min  = 1, -          .max  = 2048, -          .description = "maximum number of per directory databases that can " -                         "be kept open. NOTE: for _advanced_ users only." -        }, -        { .key  = { "lock-timeout" }, -          .type = GF_OPTION_TYPE_TIME, -          .min  = 0, -          .max  = 4260000, -          .description = "define the maximum time a lock request can " -                         "be blocked by libdb. NOTE: only for _advanced_ users." -                         " do not specify this option when not sure." -        }, -        { .key  = { "checkpoint-interval" }, -          .type = GF_OPTION_TYPE_TIME, -          .min  = 1, -          .max  = 86400, -          .description = "define the time interval between two consecutive " -                         "libdb checpoints. setting to lower value will leave " -                         "bdb perform slowly, but guarantees that minimum data" -                         " will be lost in case of a crash. NOTE: this option " -                         "is valid only when " -                         "'option mode=\"persistent\"' is set." -        }, -        { .key  = { "transaction-timeout" }, -          .type = GF_OPTION_TYPE_TIME, -          .min  = 0, -          .max  = 4260000, -          .description = "maximum time for which a transaction can block " -                         "waiting for required resources." -        }, -        { .key   = { "mode" }, -          .type  = GF_OPTION_TYPE_BOOL, -          .value = { "cache", "persistent" }, -          .description = "cache: data recovery is not guaranteed in case " -                         "of crash. persistent: data recovery is guaranteed, " -                         "since all operations are transaction protected." -        }, -        { .key   = { "access-mode" }, -          .type  = GF_OPTION_TYPE_STR, -          .value = {"btree", "hash" }, -          .description = "chose the db access method. " -                         "NOTE: for _advanced_ users. leave the choice to " -                         "glusterfs when in doubt." -        }, -        { .key = { NULL } } -}; diff --git a/xlators/storage/bdb/src/bdb.h b/xlators/storage/bdb/src/bdb.h deleted file mode 100644 index da8937a0289..00000000000 --- a/xlators/storage/bdb/src/bdb.h +++ /dev/null @@ -1,530 +0,0 @@ -/* -  Copyright (c) 2008-2011 Gluster, Inc. <http://www.gluster.com> -  This file is part of GlusterFS. - -  GlusterFS is free software; you can redistribute it and/or modify -  it under the terms of the GNU General Public License as published -  by the Free Software Foundation; either version 3 of the License, -  or (at your option) any later version. - -  GlusterFS is distributed in the hope that it will be useful, but -  WITHOUT ANY WARRANTY; without even the implied warranty of -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU -  General Public License for more details. - -  You should have received a copy of the GNU General Public License -  along with this program.  If not, see -  <http://www.gnu.org/licenses/>. -*/ - -#ifndef _BDB_H -#define _BDB_H - -#ifndef _CONFIG_H -#define _CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <dirent.h> -#include <unistd.h> -#include <sys/types.h> -#include <dirent.h> - -#include <db.h> - -#ifdef linux -#ifdef __GLIBC__ -#include <sys/fsuid.h> -#else -#include <unistd.h> -#endif -#endif - -#ifdef HAVE_SYS_XATTR_H -#include <sys/xattr.h> -#endif - -#ifdef HAVE_SYS_EXTATTR_H -#include <sys/extattr.h> -#endif - -#include <pthread.h> -#include "xlator.h" -#include "inode.h" -#include "compat.h" -#include "compat-errno.h" -#include "fd.h" -#include "syscall.h" - -#define BDB_STORAGE    "/glusterfs_storage.db" - -/* numbers are not so reader-friendly, so lets have ON and OFF macros */ -#define ON  1 -#define OFF 0 - -#define BDB_DEFAULT_LRU_LIMIT 100 -#define BDB_DEFAULT_HASH_SIZE 100 - -#define BDB_ENOSPC_THRESHOLD 25600 - -#define BDB_DEFAULT_CHECKPOINT_INTERVAL 30 - -#define BCTX_ENV(bctx) (bctx->table->dbenv) - -#define BDB_EXPORT_PATH_LEN(_private) \ -        (((struct bdb_private *)_private)->export_path_length) - -#define BDB_KEY_FROM_FREQUEST_KEY(_key) (&(key[15])) - -#define BDB_EXPORT_PATH(_private) \ -        (((struct bdb_private *)_private)->export_path) -/* MAKE_REAL_PATH(var,this,path) - * make the real path on the underlying file-system - * - * @var:  destination to hold the real path - * @this: pointer to xlator_t corresponding to bdb xlator - * @path: path, as seen from mount-point - */ -#define MAKE_REAL_PATH(var, this, path) do {                            \ -                int base_len = BDB_EXPORT_PATH_LEN(this->private);      \ -                var = alloca (strlen (path) + base_len + 2);            \ -                strcpy (var, BDB_EXPORT_PATH(this->private));           \ -                strcpy (&var[base_len], path);                          \ -        } while (0) - - -#define BDB_TIMED_LOG(_errno,_counter)  \ -        ((_errno == ENOTSUP) && (((++_counter) % GF_UNIVERSAL_ANSWER) == 1)) - -#define GF_FILE_CONTENT_REQUEST ZR_FILE_CONTENT_REQUEST - -/* MAKE_REAL_PATH_TO_STORAGE_DB(var,this,path) - * make the real path to the storage-database file on file-system - * - * @var:  destination to hold the real path - * @this: pointer to xlator_t corresponding to bdb xlator - * @path: path of the directory, as seen from mount-point - */ -#define MAKE_REAL_PATH_TO_STORAGE_DB(var, this, path) do {              \ -                int base_len = BDB_EXPORT_PATH_LEN(this->private);      \ -                var = alloca (strlen (path) +                           \ -                              base_len +                                \ -                              strlen (BDB_STORAGE));                    \ -                strcpy (var, BDB_EXPORT_PATH(this->private));           \ -                strcpy (&var[base_len], path);                          \ -                strcat (var, BDB_STORAGE);                              \ -        } while (0) - -/* MAKE_KEY_FROM_PATH(key,path) - * make a 'key', which we use as key in the underlying database by using - * the path - * - * @key:  destination to hold the key - * @path: path to file as seen from mount-point - */ -#define MAKE_KEY_FROM_PATH(key, path) do {              \ -                char *tmp = alloca (strlen (path));     \ -                strcpy (tmp, path);                     \ -                key = basename (tmp);                   \ -        }while (0); - -/* IS_BDB_PRIVATE_FILE(name) - * check if a given 'name' is bdb xlator's internal file name - * - * @name: basename of a file. - * - * bdb xlator reserves file names 'glusterfs_storage.db', - * 'glusterfs_ns.db'(used by bdb xlator itself), 'log.*', '__db.*' - * (used by libdb) - */ -#define IS_BDB_PRIVATE_FILE(name) ((!strncmp(name, "__db.", 5)) ||      \ -                                   (!strcmp(name, "glusterfs_storage.db")) || \ -                                   (!strcmp(name, "glusterfs_ns.db")) || \ -                                   (!strncmp(name, "log.0000", 8))) - -/* check if 'name' is '.' or '..' entry */ -#define IS_DOT_DOTDOT(name) \ -        ((!strncmp(name,".", 1)) || (!strncmp(name,"..", 2))) - -/* BDB_ICTX_SET(this,inode,bctx) - * pointer to 'struct bdb_ctx' is stored in inode's ctx of all directories. - * this will happen either in lookup() or mkdir(). - * - * @this:  pointer xlator_t of bdb xlator. - * @inode: inode where 'struct bdb_ctx *' has to be stored. - * @bctx:  a 'struct bdb_ctx *' - */ -#define BDB_ICTX_SET(_inode,_this,_bctx) do{                            \ -                inode_ctx_put(_inode, _this, (uint64_t)(long)_bctx);    \ -        }while (0); - -#define BDB_ICTX_GET(_inode,_this,_bctxp) do {                  \ -                uint64_t tmp_bctx = 0;                          \ -                inode_ctx_get (_inode, _this, &tmp_bctx);       \ -                *_bctxp = tmp_bctx;                             \ -        }while (0); - -/* BDB_FCTX_SET(this,fd,bctx) - * pointer to 'struct bdb_ctx' is stored in inode's ctx of all directories. - * this will happen either in lookup() or mkdir(). - * - * @this:  pointer xlator_t of bdb xlator. - * @inode: inode where 'struct bdb_ctx *' has to be stored. - * @bctx:  a 'struct bdb_ctx *' - */ -#define BDB_FCTX_SET(_fd,_this,_bfd) do{                        \ -                fd_ctx_set(_fd, _this, (uint64_t)(long)_bfd);   \ -        }while (0); - -#define BDB_FCTX_GET(_fd,_this,_bfdp) do {              \ -                uint64_t tmp_bfd = 0;                   \ -                fd_ctx_get (_fd, _this, &tmp_bfd);      \ -                *_bfdp = (void *)(long)tmp_bfd;         \ -        }while (0); - - -/* maximum number of open dbs that bdb xlator will ever have */ -#define BDB_MAX_OPEN_DBS 100 - -/* convert file size to block-count */ -#define BDB_COUNT_BLOCKS(size,blksize) (((size + blksize - 1)/blksize) - 1) - -/* file permissions, again macros are more readable */ -#define RWXRWXRWX         0777 -#define DEFAULT_FILE_MODE 0600 -#define DEFAULT_DIR_MODE  0755 - -/* see, if have a valid file permissions specification in @mode */ -#define IS_VALID_FILE_MODE(mode) (!(mode & (~RWXRWXRWX))) -#define IS_VALID_DIR_MODE(mode)  (!(mode & (~(RWXRWXRWX))) - -/* maximum retries for a failed transactional operation */ -#define BDB_MAX_RETRIES 10 - -#define BDB_LL_PAGE_SIZE_DEFAULT    4096 -#define BDB_LL_PAGE_SIZE_MIN        4096 -#define BDB_LL_PAGE_SIZE_MAX        65536 - -#define PAGE_SIZE_IN_RANGE(_page_size)                  \ -        ((_page_size >= BDB_LL_PAGE_SIZE_MIN)           \ -         && (table->page_size <= BDB_LL_PAGE_SIZE_MAX)) - -typedef struct bctx_table bctx_table_t; -typedef struct bdb_ctx    bctx_t; -typedef struct bdb_cache  bdb_cache_t; -typedef struct bdb_private bdb_private_t; - -struct bctx_table { -        /* flags to be used for opening each database */ -        uint64_t            dbflags; - -        /* cache: can be either ON or OFF */ -        uint64_t            cache; - -        /* used to lock the 'struct bctx_table *' */ -        gf_lock_t           lock; - -        /* lock for checkpointing */ -        gf_lock_t           checkpoint_lock; - -        /* hash table of 'struct bdb_ctx' */ -        struct list_head   *b_hash; - -        /* list of active 'struct bdb_ctx' */ -        struct list_head    active; - -        /* lru list of inactive 'struct bdb_ctx' */ -        struct list_head    b_lru; -        struct list_head    purge; -        uint32_t            lru_limit; -        uint32_t            lru_size; -        uint32_t            hash_size; - -        /* access mode for accessing the databases, can be DB_HASH, DB_BTREE */ -        DBTYPE              access_mode; - -        /* DB_ENV under which every db operation is carried over */ -        DB_ENV             *dbenv; -        int32_t             transaction; -        xlator_t           *this; - -        /* page-size of DB, DB->set_pagesize(), should be set before DB->open */ -        uint64_t            page_size; -}; - -struct bdb_ctx { -        /* controller members */ - -        /* lru list of 'struct bdb_ctx's, a bdb_ctx can exist in one of -         * b_hash or lru lists */ -        struct list_head   list; - -        /* directory 'name' hashed list of 'struct bdb_ctx's */ -        struct list_head   b_hash; - -        struct bctx_table *table; -        int32_t            ref;         /* reference count */ -        gf_lock_t          lock;        /* used to lock this 'struct bdb_ctx' */ - -        char              *directory;   /* directory path */ - -        /* pointer to open database, that resides inside this directory */ -        DB                *primary; -        DB                *secondary; -        uint32_t           cache;       /* cache ON or OFF */ - -        /* per directory cache, bdb xlator's internal cache */ -        struct list_head   c_list;      /* linked list of cached records */ -        int32_t            c_count;     /* number of cached records */ - -        /* index to hash table list, to which this ctx belongs */ -        int32_t            key_hash; -        char              *db_path;     /* absolute path to db file */ -}; - -struct bdb_fd { -        /* pointer to bdb_ctx of the parent directory */ -        struct bdb_ctx *ctx; - -        /* name of the file. NOTE: basename, not the complete path */ -        char           *key; -        int32_t         flags;          /* open flags */ -}; - -struct bdb_dir { -        /* pointer to bdb_ctx of this directory */ -        struct bdb_ctx *ctx; - -        /* open directory pointer, as returned by opendir() */ -        DIR            *dir; - -        char           *path;             /* path to this directory */ -}; - -/* cache */ -struct bdb_cache { -        /* list of 'struct bdb_cache' under a 'struct bdb_ctx' */ -        struct list_head c_list; - -        /* name of the file this cache holds. NOTE: basename of file */ -        char            *key; -        char            *data;            /* file content */ - -        /* size of the file content that this cache holds */ -        size_t           size; -}; - - -struct bdb_private { -        /* pointer to inode table that we use */ -        inode_table_t      *itable; -        int32_t             temp;               /**/ -        char                is_stateless;       /**/ - -        /* path to the export directory -         * (option directory <export-path>) */ -        char               *export_path; - -        /* length of 'export_path' string */ -        int32_t             export_path_length; - -        /* statistics */ -        /* Statistics, provides activity of the server */ -        struct xlator_stats stats; - -        struct timeval      prev_fetch_time; -        struct timeval      init_time; -        int32_t             max_read;           /* */ -        int32_t             max_write;          /* */ - -        /* Used to calculate the max_read value */ -        int64_t             interval_read; - -        /* Used to calculate the max_write value */ -        int64_t             interval_write; -        int64_t             read_value;         /* Total read, from init */ -        int64_t             write_value;        /* Total write, from init */ - -        /* bdb xlator specific private data */ - -        /* flags used for opening DB_ENV for this xlator */ -        uint64_t            envflags; - -        /* flags to be used for opening each database */ -        uint64_t            dbflags; - -        /* cache: can be either ON or OFF */ -        uint64_t            cache; - -        /* transaction: can be either ON or OFF */ -        uint32_t            transaction; -        uint32_t            active; -        gf_lock_t           active_lock; -        struct bctx_table  *b_table; - -        /* access mode for accessing the databases, can be DB_HASH, DB_BTREE -         * (option access-mode <mode>) */ -        DBTYPE              access_mode; - -        /* mode for each and every file stored on bdb -         * (option file-mode <mode>) */ -        mode_t              file_mode; - -        /* mode for each and every directory stored on bdb -         * (option dir-mode <mode>) */ -        mode_t              dir_mode; - -        /* mode for each and every symlink stored on bdb */ -        mode_t              symlink_mode; - -        /* pthread_t object used for creating checkpoint thread */ -        pthread_t           checkpoint_thread; - -        /* time duration between two consecutive checkpoint operations. -         * (option checkpoint-interval <time-in-seconds>) */ -        uint32_t             checkpoint_interval; - -        /* environment log directory (option logdir <directory>) */ -        char               *logdir; - -        /* errfile path, used by environment to print detailed error log. -         * (option errfile <errfile-path>) */ -        char               *errfile; - -        /* DB_ENV->set_errfile() expects us to fopen -         * the errfile before doing DB_ENV->set_errfile() */ -        FILE               *errfp; - -       /* used by DB_ENV->set_timeout to set the timeout for -        * a transactionally encapsulated DB->operation() to -        * timeout before waiting for locks to be released. -        * (option transaction-timeout <time-in-milliseconds>) -        */ -        uint32_t            txn_timeout; -        uint32_t            lock_timeout; - -        /* DB_AUTO_LOG_REMOVE flag for DB_ENV*/ -        uint32_t            log_auto_remove; -        uint32_t            log_region_max; -}; - - -static inline int32_t -bdb_txn_begin (DB_ENV *dbenv, -               DB_TXN **ptxnid) -{ -        return dbenv->txn_begin (dbenv, NULL, ptxnid, 0); -} - -static inline int32_t -bdb_txn_abort (DB_TXN *txnid) -{ -        return txnid->abort (txnid); -} - -static inline int32_t -bdb_txn_commit (DB_TXN *txnid) -{ -        return txnid->commit (txnid, 0); -} - -void * -bdb_db_stat (bctx_t *bctx, -             DB_TXN *txnid, -             uint32_t flags); - -/*int32_t -bdb_db_get(struct bdb_ctx *bctx, -           DB_TXN *txnid, -           const char *key_string, -           char **buf, -           size_t size, -           off_t offset); -*/ -int32_t -bdb_db_fread (struct bdb_fd *bfd, char *bufp, size_t size, off_t offset); - -int32_t -bdb_db_iread (struct bdb_ctx *bctx, const char *key, char **bufp); - -#define BDB_TRUNCATE_RECORD 0xcafebabe - -/*int32_t -bdb_db_put (struct bdb_ctx *bctx, -            DB_TXN *txnid, -            const char *key_string, -            const char *buf, -            size_t size, -            off_t offset, -            int32_t flags); -*/ -int32_t -bdb_db_icreate (struct bdb_ctx *bctx, const char *key); - -int32_t -bdb_db_fwrite (struct bdb_fd *bfd, char *buf, size_t size, off_t offset); - -int32_t -bdb_db_iwrite (struct bdb_ctx *bctx, const char *key, char *buf, size_t size); - -int32_t -bdb_db_itruncate (struct bdb_ctx *bctx, const char *key); - -int32_t -bdb_db_iremove (struct bdb_ctx *bctx, -                const char *key); - -ino_t -bdb_inode_transform (ino_t parent, -                     const char *name, -                     size_t namelen); - -int32_t -bdb_cursor_open (struct bdb_ctx *bctx, -                 DBC **cursorp); - -int32_t -bdb_cursor_get (DBC *cursorp, -                DBT *sec, DBT *pri, -                DBT *value, -                int32_t flags); - - -int32_t -bdb_cursor_close (struct bdb_ctx *ctx, -                  DBC *cursorp); - - -int32_t -bdb_dirent_size (DBT *key); - -int32_t -dirent_size (struct dirent *entry); - -int -bdb_db_init (xlator_t *this, -             dict_t *options); - -void -bdb_dbs_from_dict_close (dict_t *this, -                         char *key, -                         data_t *value, -                         void *data); - -bctx_t * -bctx_lookup (struct bctx_table *table, -             const char *path); - -bctx_t * -bctx_parent -(struct bctx_table *table, - const char *path); - -bctx_t * -bctx_unref (bctx_t *ctx); - -bctx_t * -bctx_ref (bctx_t *ctx); - -#endif /* _BDB_H */  | 
