diff options
-rw-r--r-- | booster/src/Makefile.am | 4 | ||||
-rw-r--r-- | booster/src/booster-fd.c | 291 | ||||
-rw-r--r-- | booster/src/booster-fd.h | 72 | ||||
-rw-r--r-- | booster/src/booster.c | 210 |
4 files changed, 438 insertions, 139 deletions
diff --git a/booster/src/Makefile.am b/booster/src/Makefile.am index 8202e795cfe..a5158591226 100644 --- a/booster/src/Makefile.am +++ b/booster/src/Makefile.am @@ -2,8 +2,8 @@ xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/performance ldpreload_PROGRAMS = glusterfs-booster.so ldpreloaddir = $(libdir)/glusterfs/ -noinst_HEADERS = booster_fstab.h -glusterfs_booster_so_SOURCES = booster.c booster_stat.c booster_fstab.c +noinst_HEADERS = booster_fstab.h booster-fd.h +glusterfs_booster_so_SOURCES = booster.c booster_stat.c booster_fstab.c booster-fd.c glusterfs_booster_so_CFLAGS = -I$(top_srcdir)/libglusterfsclient/src/ -D_GNU_SOURCE -D$(GF_HOST_OS) -fPIC -Wall \ -pthread $(GF_BOOSTER_CFLAGS) glusterfs_booster_so_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE \ diff --git a/booster/src/booster-fd.c b/booster/src/booster-fd.c new file mode 100644 index 00000000000..78cde44ddab --- /dev/null +++ b/booster/src/booster-fd.c @@ -0,0 +1,291 @@ +/* + Copyright (c) 2009 Z RESEARCH, Inc. <http://www.zresearch.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 ("server-protocol/fd", + GF_LOG_ERROR, + "Negative number passed"); + return -1; + } + + while (result <= nr) + result *= 2; + + return result; +} + +int +booster_fdtable_expand (booster_fdtable_t *fdtable, uint nr) +{ + fd_t **oldfds = NULL; + uint oldmax_fds = -1; + uint cpy = 0; + int32_t ret = -1; + + if (fdtable == NULL || nr < 0) { + gf_log ("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; + + fdtable->fds = CALLOC (nr, sizeof (fd_t *)); + if (fdtable->fds == NULL) { + 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); + } + + ret = 0; +out: + FREE (oldfds); + + 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) { + 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 ("fd", GF_LOG_ERROR, "invalid argument"); + errno = EINVAL; + return -1; + } + + 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; + } + + if (!(fd < fdtable->max_fds)) { + gf_log ("fd", GF_LOG_ERROR, "invalid argument"); + 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; + } + + if (!(fd < fdtable->max_fds)) { + gf_log ("booster-fd", GF_LOG_ERROR, "invalid argument"); + 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 new file mode 100644 index 00000000000..43592e8255a --- /dev/null +++ b/booster/src/booster-fd.h @@ -0,0 +1,72 @@ +/* + Copyright (c) 2009 Z RESEARCH, Inc. <http://www.zresearch.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_fdtable { + int refcount; + unsigned int max_fds; + gf_lock_t lock; + fd_t **fds; +}; +typedef struct _booster_fdtable booster_fdtable_t; + +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 index 8dcfdc7e979..7a3da7da132 100644 --- a/booster/src/booster.c +++ b/booster/src/booster.c @@ -43,12 +43,19 @@ #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 +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 @@ -82,44 +89,6 @@ typedef enum { struct _inode; struct _dict; -struct _fd { - pid_t pid; - struct list_head inode_list; - struct _inode *inode; - struct _dict *ctx; - int32_t refcount; -}; - -typedef struct _fdtable fdtable_t; -typedef struct _fd fd_t; - - -inline void -gf_fd_put (struct _fdtable *fdtable, int64_t fd); - -struct _fd * -gf_fd_fdptr_get (struct _fdtable *fdtable, int64_t fd); - -struct _fdtable * -gf_fd_fdtable_alloc (void); - -void -gf_fd_fdtable_destroy (struct _fdtable *); - -int32_t -gf_fd_unused_get (struct _fdtable *fdtable, struct _fd *fdptr); - -int32_t -gf_fd_unused_get2 (struct _fdtable *fdtable, struct _fd *fdptr, int64_t fd); - -void -fd_unref (struct _fd *fd); - -fd_t * -fd_ref (struct _fd *fd); - -pid_t -getpid (void); ssize_t write (int fd, const void *buf, size_t count); @@ -229,7 +198,7 @@ struct booster_mount { }; typedef struct booster_mount booster_mount_t; -static fdtable_t *booster_glfs_fdtable = NULL; +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. @@ -257,39 +226,6 @@ booster_get_process_fd () #define BOOSTER_DEFAULT_LOG CONFDIR"/booster.log" #define BOOSTER_LOG_ENV_VAR "GLUSTERFS_BOOSTER_LOG" - -static inline glusterfs_file_t -booster_get_glfs_fd (fdtable_t *fdtable, int fd) -{ - fd_t *glfs_fd = NULL; - - glfs_fd = gf_fd_fdptr_get (fdtable, fd); - return glfs_fd; -} - - -static inline void -booster_put_glfs_fd (glusterfs_file_t glfs_fd) -{ - fd_unref ((fd_t *)glfs_fd); -} - - -static inline int32_t -booster_get_unused_fd (fdtable_t *fdtable, glusterfs_file_t glfs_fd, int fd) -{ - int32_t ret = -1; - ret = gf_fd_unused_get2 (fdtable, (fd_t *)glfs_fd, fd); - return ret; -} - - -static inline void -booster_put_fd (fdtable_t *fdtable, int fd) -{ - gf_fd_put (fdtable, fd); -} - void do_open (int fd, const char *pathname, int flags, mode_t mode, booster_op_t op) { @@ -382,7 +318,7 @@ do_open (int fd, const char *pathname, int flags, mode_t mode, booster_op_t op) goto out; } - if (booster_get_unused_fd (booster_glfs_fdtable, fh, fd) == -1) { + if (booster_fd_unused_get (booster_fdtable, fh, fd) == -1) { goto out; } fh = NULL; @@ -432,7 +368,7 @@ vmp_open (const char *pathname, int flags, ...) if (fd == -1) goto fh_close_out; - if (booster_get_unused_fd (booster_glfs_fdtable, fh, fd) == -1) + if (booster_fd_unused_get (booster_fdtable, fh, fd) == -1) goto realfd_close_out; return fd; @@ -578,7 +514,7 @@ vmp_creat (const char *pathname, mode_t mode) if (fd == -1) goto close_out; - if ((booster_get_unused_fd (booster_glfs_fdtable, fh, fd)) == -1) + if ((booster_fd_unused_get (booster_fdtable, fh, fd)) == -1) goto real_close_out; return fd; @@ -634,7 +570,7 @@ pread (int fd, void *buf, size_t count, unsigned long offset) ssize_t ret; glusterfs_file_t glfs_fd = 0; - glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd); + glfs_fd = booster_fdptr_get (booster_fdtable, fd); if (!glfs_fd) { if (real_pread == NULL) { errno = ENOSYS; @@ -643,7 +579,7 @@ pread (int fd, void *buf, size_t count, unsigned long offset) ret = real_pread (fd, buf, count, offset); } else { ret = glusterfs_pread (glfs_fd, buf, count, offset); - booster_put_glfs_fd (glfs_fd); + booster_fdptr_put (glfs_fd); } return ret; @@ -656,7 +592,7 @@ pread64 (int fd, void *buf, size_t count, uint64_t offset) ssize_t ret; glusterfs_file_t glfs_fd = 0; - glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd); + glfs_fd = booster_fdptr_get (booster_fdtable, fd); if (!glfs_fd) { if (real_pread64 == NULL) { errno = ENOSYS; @@ -677,7 +613,7 @@ read (int fd, void *buf, size_t count) int ret; glusterfs_file_t glfs_fd; - glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd); + glfs_fd = booster_fdptr_get (booster_fdtable, fd); if (!glfs_fd) { if (real_read == NULL) { errno = ENOSYS; @@ -686,7 +622,7 @@ read (int fd, void *buf, size_t count) ret = real_read (fd, buf, count); } else { ret = glusterfs_read (glfs_fd, buf, count); - booster_put_glfs_fd (glfs_fd); + booster_fdptr_put (glfs_fd); } return ret; @@ -699,7 +635,7 @@ readv (int fd, const struct iovec *vector, int count) int ret; glusterfs_file_t glfs_fd = 0; - glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd); + glfs_fd = booster_fdptr_get (booster_fdtable, fd); if (!glfs_fd) { if (real_readv == NULL) { errno = ENOSYS; @@ -708,7 +644,7 @@ readv (int fd, const struct iovec *vector, int count) ret = real_readv (fd, vector, count); } else { ret = glusterfs_readv (glfs_fd, vector, count); - booster_put_glfs_fd (glfs_fd); + booster_fdptr_put (glfs_fd); } return ret; @@ -721,7 +657,7 @@ write (int fd, const void *buf, size_t count) int ret; glusterfs_file_t glfs_fd = 0; - glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd); + glfs_fd = booster_fdptr_get (booster_fdtable, fd); if (!glfs_fd) { if (real_write == NULL) { @@ -731,7 +667,7 @@ write (int fd, const void *buf, size_t count) ret = real_write (fd, buf, count); } else { ret = glusterfs_write (glfs_fd, buf, count); - booster_put_glfs_fd (glfs_fd); + booster_fdptr_put (glfs_fd); } return ret; @@ -743,7 +679,7 @@ writev (int fd, const struct iovec *vector, int count) int ret = 0; glusterfs_file_t glfs_fd = 0; - glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd); + glfs_fd = booster_fdptr_get (booster_fdtable, fd); if (!glfs_fd) { if (real_writev == NULL) { @@ -753,7 +689,7 @@ writev (int fd, const struct iovec *vector, int count) ret = real_writev (fd, vector, count); } else { ret = glusterfs_writev (glfs_fd, vector, count); - booster_put_glfs_fd (glfs_fd); + booster_fdptr_put (glfs_fd); } return ret; @@ -766,7 +702,7 @@ pwrite (int fd, const void *buf, size_t count, unsigned long offset) int ret; glusterfs_file_t glfs_fd = 0; - glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd); + glfs_fd = booster_fdptr_get (booster_fdtable, fd); if (!glfs_fd) { if (real_pwrite == NULL) { @@ -776,7 +712,7 @@ pwrite (int fd, const void *buf, size_t count, unsigned long offset) ret = real_pwrite (fd, buf, count, offset); } else { ret = glusterfs_pwrite (glfs_fd, buf, count, offset); - booster_put_glfs_fd (glfs_fd); + booster_fdptr_put (glfs_fd); } return ret; @@ -789,7 +725,7 @@ pwrite64 (int fd, const void *buf, size_t count, uint64_t offset) int ret; glusterfs_file_t glfs_fd = 0; - glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd); + glfs_fd = booster_fdptr_get (booster_fdtable, fd); if (!glfs_fd) { if (real_pwrite64 == NULL) { @@ -799,7 +735,7 @@ pwrite64 (int fd, const void *buf, size_t count, uint64_t offset) ret = real_pwrite64 (fd, buf, count, offset); } else { ret = glusterfs_pwrite (glfs_fd, buf, count, offset); - booster_put_glfs_fd (glfs_fd); + booster_fdptr_put (glfs_fd); } return ret; @@ -812,12 +748,12 @@ close (int fd) int ret = -1; glusterfs_file_t glfs_fd = 0; - glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd); + glfs_fd = booster_fdptr_get (booster_fdtable, fd); if (glfs_fd) { - booster_put_fd (booster_glfs_fdtable, fd); + booster_fd_put (booster_fdtable, fd); ret = glusterfs_close (glfs_fd); - booster_put_glfs_fd (glfs_fd); + booster_fdptr_put (glfs_fd); } ret = real_close (fd); @@ -833,10 +769,10 @@ lseek (int filedes, unsigned long offset, int whence) int ret; glusterfs_file_t glfs_fd = 0; - glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, filedes); + glfs_fd = booster_fdptr_get (booster_fdtable, filedes); if (glfs_fd) { ret = glusterfs_lseek (glfs_fd, offset, whence); - booster_put_glfs_fd (glfs_fd); + booster_fdptr_put (glfs_fd); } else { if (real_lseek == NULL) { errno = ENOSYS; @@ -856,10 +792,10 @@ lseek64 (int filedes, uint64_t offset, int whence) glusterfs_file_t glfs_fd = 0; - glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, filedes); + glfs_fd = booster_fdptr_get (booster_fdtable, filedes); if (glfs_fd) { ret = glusterfs_lseek (glfs_fd, offset, whence); - booster_put_glfs_fd (glfs_fd); + booster_fdptr_put (glfs_fd); } else { if (real_lseek64 == NULL) { errno = ENOSYS; @@ -877,11 +813,11 @@ dup (int oldfd) int ret = -1, new_fd = -1; glusterfs_file_t glfs_fd = 0; - glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, oldfd); + glfs_fd = booster_fdptr_get (booster_fdtable, oldfd); new_fd = real_dup (oldfd); if (new_fd >=0 && glfs_fd) { - ret = booster_get_unused_fd (booster_glfs_fdtable, glfs_fd, + ret = booster_fd_unused_get (booster_fdtable, glfs_fd, new_fd); fd_ref ((fd_t *)glfs_fd); if (ret == -1) { @@ -890,7 +826,7 @@ dup (int oldfd) } if (glfs_fd) { - booster_put_glfs_fd (glfs_fd); + booster_fdptr_put (glfs_fd); } return new_fd; @@ -907,20 +843,20 @@ dup2 (int oldfd, int newfd) return newfd; } - old_glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, oldfd); - new_glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, 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_put_glfs_fd (new_glfs_fd); - booster_put_fd (booster_glfs_fdtable, newfd); + booster_fdptr_put (new_glfs_fd); + booster_fd_put (booster_fdtable, newfd); new_glfs_fd = 0; } if (old_glfs_fd) { - ret = booster_get_unused_fd (booster_glfs_fdtable, + ret = booster_fd_unused_get (booster_fdtable, old_glfs_fd, newfd); fd_ref ((fd_t *)old_glfs_fd); if (ret == -1) { @@ -930,11 +866,11 @@ dup2 (int oldfd, int newfd) } if (old_glfs_fd) { - booster_put_glfs_fd (old_glfs_fd); + booster_fdptr_put (old_glfs_fd); } if (new_glfs_fd) { - booster_put_glfs_fd (new_glfs_fd); + booster_fdptr_put (new_glfs_fd); } return ret; @@ -1020,7 +956,7 @@ fchown (int fd, uid_t owner, gid_t group) int ret = -1; glusterfs_file_t fh = NULL; - fh = booster_get_glfs_fd (booster_glfs_fdtable, fd); + fh = booster_fdptr_get (booster_fdtable, fd); if (!fh) { if (real_fchown == NULL) { errno = ENOSYS; @@ -1029,7 +965,7 @@ fchown (int fd, uid_t owner, gid_t group) ret = real_fchown (fd, owner, group); } else { ret = glusterfs_fchown (fh, owner, group); - booster_put_glfs_fd (fh); + booster_fdptr_put (fh); } return ret; @@ -1046,8 +982,8 @@ booster_init (void) int ret = -1; int pipefd[2]; - booster_glfs_fdtable = gf_fd_fdtable_alloc (); - if (!booster_glfs_fdtable) { + booster_fdtable = booster_fdtable_alloc (); + if (!booster_fdtable) { fprintf (stderr, "cannot allocate fdtable: %s\n", strerror (errno)); goto err; @@ -1088,16 +1024,16 @@ err: static void booster_cleanup (void) { - /* gf_fd_fdtable_destroy (booster_glfs_fdtable);*/ - /*for (i=0; i < booster_glfs_fdtable->max_fds; i++) { - if (booster_glfs_fdtable->fds[i]) { - fd_t *fd = booster_glfs_fdtable->fds[i]; + /* gf_fd_fdtable_destroy (booster_fdtable);*/ + /*for (i=0; i < booster_fdtable->max_fds; i++) { + if (booster_fdtable->fds[i]) { + fd_t *fd = booster_fdtable->fds[i]; free (fd); } }*/ - free (booster_glfs_fdtable); - booster_glfs_fdtable = NULL; + free (booster_fdtable); + booster_fdtable = NULL; /* * FIXME: there may be issues during execution of fini of individual @@ -1118,7 +1054,7 @@ fchmod (int fd, mode_t mode) int ret = -1; glusterfs_file_t fh = NULL; - fh = booster_get_glfs_fd (booster_glfs_fdtable, fd); + fh = booster_fdptr_get (booster_fdtable, fd); if (!fh) { if (real_fchmod == NULL) { errno = ENOSYS; @@ -1127,7 +1063,7 @@ fchmod (int fd, mode_t mode) ret = real_fchmod (fd, mode); } else { ret = glusterfs_fchmod (fh, mode); - booster_put_glfs_fd (fh); + booster_fdptr_put (fh); } return ret; @@ -1139,7 +1075,7 @@ fsync (int fd) int ret = -1; glusterfs_file_t fh = NULL; - fh = booster_get_glfs_fd (booster_glfs_fdtable, fd); + fh = booster_fdptr_get (booster_fdtable, fd); if (!fh) { if (real_fsync == NULL) { errno = ENOSYS; @@ -1148,7 +1084,7 @@ fsync (int fd) ret = real_fsync (fd); } else { ret = glusterfs_fsync (fh); - booster_put_glfs_fd (fh); + booster_fdptr_put (fh); } return ret; @@ -1160,7 +1096,7 @@ ftruncate (int fd, off_t length) int ret = -1; glusterfs_file_t fh = NULL; - fh = booster_get_glfs_fd (booster_glfs_fdtable, fd); + fh = booster_fdptr_get (booster_fdtable, fd); if (!fh) { if (real_ftruncate == NULL) { errno = ENOSYS; @@ -1169,7 +1105,7 @@ ftruncate (int fd, off_t length) ret = real_ftruncate (fd, length); } else { ret = glusterfs_ftruncate (fh, length); - booster_put_glfs_fd (fh); + booster_fdptr_put (fh); } return ret; @@ -1632,7 +1568,7 @@ booster_fxstat (int ver, int fd, void *buf) int ret = -1; glusterfs_file_t fh = NULL; - fh = booster_get_glfs_fd (booster_glfs_fdtable, fd); + fh = booster_fdptr_get (booster_fdtable, fd); if (!fh) { if (real___fxstat == NULL) { errno = ENOSYS; @@ -1643,7 +1579,7 @@ booster_fxstat (int ver, int fd, void *buf) ret = real___fxstat (ver, fd, sbuf); } else { ret = glusterfs_fstat (fh, sbuf); - booster_put_glfs_fd (fh); + booster_fdptr_put (fh); } out: @@ -1657,7 +1593,7 @@ booster_fxstat64 (int ver, int fd, void *buf) struct stat64 *sbuf = (struct stat64 *)buf; glusterfs_file_t fh = NULL; - fh = booster_get_glfs_fd (booster_glfs_fdtable, fd); + fh = booster_fdptr_get (booster_fdtable, fd); if (!fh) { if (real___fxstat64 == NULL) { ret = -1; @@ -1667,7 +1603,7 @@ booster_fxstat64 (int ver, int fd, void *buf) ret = real___fxstat64 (ver, fd, sbuf); } else { ret = glusterfs_fstat (fh, (struct stat *)sbuf); - booster_put_glfs_fd (fh); + booster_fdptr_put (fh); } out: @@ -1681,7 +1617,7 @@ booster_fstat (int fd, void *buf) int ret = -1; glusterfs_file_t fh = NULL; - fh = booster_get_glfs_fd (booster_glfs_fdtable, fd); + fh = booster_fdptr_get (booster_fdtable, fd); if (!fh) { if (real_fstat != NULL) ret = real_fstat (fd, sbuf); @@ -1694,7 +1630,7 @@ booster_fstat (int fd, void *buf) } } else { ret = glusterfs_fstat (fh, sbuf); - booster_put_glfs_fd (fh); + booster_fdptr_put (fh); } out: @@ -1708,7 +1644,7 @@ booster_fstat64 (int fd, void *buf) struct stat64 *sbuf = (struct stat64 *)buf; glusterfs_file_t fh = NULL; - fh = booster_get_glfs_fd (booster_glfs_fdtable, fd); + fh = booster_fdptr_get (booster_fdtable, fd); if (!fh) { if (real_fstat64 != NULL) ret = real_fstat64 (fd, sbuf); @@ -1727,7 +1663,7 @@ booster_fstat64 (int fd, void *buf) } } else { ret = glusterfs_fstat (fh, (struct stat *)sbuf); - booster_put_glfs_fd (fh); + booster_fdptr_put (fh); } out: @@ -2099,7 +2035,7 @@ sendfile (int out_fd, int in_fd, off_t *offset, size_t count) * handle sendfile in booster only if in_fd corresponds to a glusterfs * file handle */ - in_fh = booster_get_glfs_fd (booster_glfs_fdtable, in_fd); + in_fh = booster_fdptr_get (booster_fdtable, in_fd); if (!in_fh) { if (real_sendfile == NULL) { errno = ENOSYS; @@ -2109,7 +2045,7 @@ sendfile (int out_fd, int in_fd, off_t *offset, size_t count) } } else { ret = glusterfs_sendfile (out_fd, in_fh, offset, count); - booster_put_glfs_fd (in_fh); + booster_fdptr_put (in_fh); } return ret; @@ -2125,7 +2061,7 @@ sendfile64 (int out_fd, int in_fd, off_t *offset, size_t count) * handle sendfile in booster only if in_fd corresponds to a glusterfs * file handle */ - in_fh = booster_get_glfs_fd (booster_glfs_fdtable, in_fd); + in_fh = booster_fdptr_get (booster_fdtable, in_fd); if (!in_fh) { if (real_sendfile64 == NULL) { errno = ENOSYS; @@ -2135,7 +2071,7 @@ sendfile64 (int out_fd, int in_fd, off_t *offset, size_t count) } } else { ret = glusterfs_sendfile (out_fd, in_fh, offset, count); - booster_put_glfs_fd (in_fh); + booster_fdptr_put (in_fh); } return ret; @@ -2151,7 +2087,7 @@ fcntl (int fd, int cmd, ...) struct flock *lock = NULL; glusterfs_file_t glfs_fd = 0; - glfs_fd = booster_get_glfs_fd (booster_glfs_fdtable, fd); + glfs_fd = booster_fdptr_get (booster_fdtable, fd); switch (cmd) { case F_DUPFD: @@ -2241,7 +2177,7 @@ fcntl (int fd, int cmd, ...) out: if (glfs_fd) { - booster_put_glfs_fd (glfs_fd); + booster_fdptr_put (glfs_fd); } return ret; |