summaryrefslogtreecommitdiffstats
path: 4space:mode:
Diffstat (limited to 'xlators/features/mac-compat/src/mac-compat.c')
-rw-r--r--xlators/features/mac-compat/src/mac-compat.c52
1 files changed, 21 insertions, 31 deletions
diff --git a/xlators/features/mac-compat/src/mac-compat.c b/xlators/features/mac-compat/src/mac-compat.c
index 649d2ad5d..7cb550ad5 100644
--- a/xlators/features/mac-compat/src/mac-compat.c
+++ b/xlators/features/mac-compat/src/mac-compat.c
@@ -1,22 +1,12 @@
/*
- Copyright (c) 2008-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/>.
-*/
+ Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com>
+ This file is part of GlusterFS.
+ This file is licensed to you under your choice of the GNU Lesser
+ General Public License, version 3 or any later version (LGPLv3 or
+ later), or the GNU General Public License, version 2 (GPLv2), in all
+ cases as published by the Free Software Foundation.
+*/
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
@@ -57,7 +47,8 @@ static int32_t apple_xattr_len[] = {
int32_t
maccomp_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, dict_t *dict)
+ int32_t op_ret, int32_t op_errno, dict_t *dict,
+ dict_t *xdata)
{
intptr_t ax = (intptr_t)this->private;
int i = 0;
@@ -80,7 +71,7 @@ maccomp_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
}
}
- STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict);
+ STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict, xdata);
return 0;
}
@@ -88,7 +79,7 @@ maccomp_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t
maccomp_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
- const char *name)
+ const char *name, dict_t *xdata)
{
intptr_t ax = GF_XATTR_NONE;
int i = 0;
@@ -109,14 +100,14 @@ maccomp_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
STACK_WIND (frame, maccomp_getxattr_cbk,
FIRST_CHILD(this),
FIRST_CHILD(this)->fops->getxattr,
- loc, name);
+ loc, name, xdata);
return 0;
}
int32_t
maccomp_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
- const char *name)
+ const char *name, dict_t *xdata)
{
intptr_t ax = GF_XATTR_NONE;
int i = 0;
@@ -137,21 +128,21 @@ maccomp_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
STACK_WIND (frame, maccomp_getxattr_cbk,
FIRST_CHILD(this),
FIRST_CHILD(this)->fops->fgetxattr,
- fd, name);
+ fd, name, xdata);
return 0;
}
int32_t
maccomp_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno)
+ int32_t op_ret, int32_t op_errno, dict_t *xdata)
{
intptr_t ax = (intptr_t)this->private;
if (op_ret == -1 && ax != GF_XATTR_NONE)
op_ret = op_errno = 0;
- STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno);
+ STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno, xdata);
return 0;
}
@@ -159,7 +150,7 @@ maccomp_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
int32_t
maccomp_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict,
- int32_t flags)
+ int32_t flags, dict_t *xdata)
{
intptr_t ax = GF_XATTR_NONE;
int i = 0;
@@ -177,14 +168,14 @@ maccomp_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict,
STACK_WIND (frame, maccomp_setxattr_cbk,
FIRST_CHILD(this),
FIRST_CHILD(this)->fops->setxattr,
- loc, dict, flags);
+ loc, dict, flags, xdata);
return 0;
}
int32_t
maccomp_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict,
- int32_t flags)
+ int32_t flags, dict_t *xdata)
{
intptr_t ax = GF_XATTR_NONE;
int i = 0;
@@ -202,7 +193,7 @@ maccomp_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *dict,
STACK_WIND (frame, maccomp_setxattr_cbk,
FIRST_CHILD(this),
FIRST_CHILD(this)->fops->fsetxattr,
- fd, dict, flags);
+ fd, dict, flags, xdata);
return 0;
}
@@ -239,8 +230,7 @@ struct xlator_fops fops = {
.fsetxattr = maccomp_fsetxattr,
};
-struct xlator_cbks cbks = {
-};
+struct xlator_cbks cbks;
struct volume_options options[] = {
{ .key = {NULL} },
class='add'>+ char *vpath = NULL;
GF_VALIDATE_OR_GOTO (LIBGF_XL_NAME, ctx, out);
GF_VALIDATE_ABSOLUTE_PATH_OR_GOTO (LIBGF_XL_NAME, path, out);
@@ -2974,8 +3025,13 @@ op_over:
goto out;
}
+ vpath = NULL;
+ if (S_ISDIR (loc.inode->st_mode)) {
+ vpath = (char *)path;
+ }
+
if (!libgf_get_fd_ctx (fd)) {
- if (!libgf_alloc_fd_ctx (ctx, fd)) {
+ if (!libgf_alloc_fd_ctx (ctx, fd, vpath)) {
gf_log (LIBGF_XL_NAME, GF_LOG_ERROR, "Failed to"
" allocate fd context");
errno = EINVAL;
@@ -2985,7 +3041,7 @@ op_over:
}
if ((flags & O_TRUNC) && (((flags & O_ACCMODE) == O_RDWR)
- || ((flags & O_ACCMODE) == O_WRONLY))) {
+ || ((flags & O_ACCMODE) == O_WRONLY))) {
inode_ctx = libgf_get_inode_ctx (fd->inode);
if (S_ISREG (inode_ctx->stbuf.st_mode)) {
inode_ctx->stbuf.st_size = 0;
@@ -5495,7 +5551,7 @@ glusterfs_glh_opendir (glusterfs_handle_t handle, const char *path)
}
if (!libgf_get_fd_ctx (dirfd)) {
- if (!(libgf_alloc_fd_ctx (ctx, dirfd))) {
+ if (!(libgf_alloc_fd_ctx (ctx, dirfd, (char *)path))) {
gf_log (LIBGF_XL_NAME, GF_LOG_ERROR, "Context "
"allocation failed");
op_ret = -1;
@@ -7689,6 +7745,75 @@ unlock:
int
+glusterfs_fchdir (glusterfs_file_t fd)
+{
+ int op_ret = -1;
+ char vpath[PATH_MAX];
+ char vmp[PATH_MAX];
+ char *res = NULL;
+ libglusterfs_client_fd_ctx_t *fd_ctx = NULL;
+ glusterfs_handle_t handle = NULL;
+
+ GF_VALIDATE_OR_GOTO (LIBGF_XL_NAME, fd, out);
+
+ /* FIXME: there is a race-condition between glusterfs_fchdir and
+ glusterfs_close. If two threads of application call glusterfs_fchdir
+ and glusterfs_close on the same fd, there is a possibility of
+ glusterfs_fchdir accessing freed memory of fd_ctx.
+ */
+
+ fd_ctx = libgf_get_fd_ctx (fd);
+ if (!fd_ctx) {
+ errno = EBADF;
+ goto out;
+ }
+
+ pthread_mutex_lock (&fd_ctx->lock);
+ {
+ handle = fd_ctx->ctx;
+ strcpy (vpath, fd_ctx->vpath);
+ }
+ pthread_mutex_unlock (&fd_ctx->lock);
+
+ if (vpath[0] == '\0') {
+ errno = ENOTDIR;
+ goto out;
+ }
+
+ res = libgf_vmp_search_vmp (handle, vmp, PATH_MAX);
+ if (res == NULL) {
+ errno = EBADF;
+ goto out;
+ }
+
+ /* both vmp and vpath are terminated with '/'. Also path starts with a
+ '/'. Hence the extra '/' amounts to NULL character at the end of the
+ string.
+ */
+ if ((strlen (vmp) + strlen (vpath)) > PATH_MAX) {
+ errno = ENAMETOOLONG;
+ goto out;
+ }
+
+ pthread_mutex_lock (&cwdlock);
+ {
+ strcpy (cwd, vmp);
+ res = vpath;
+ if (res[0] == '/') {
+ res++;
+ }
+
+ strcat (cwd, res);
+ }
+ pthread_mutex_unlock (&cwdlock);
+
+ op_ret = 0;
+out:
+ return op_ret;
+}
+
+
+int
glusterfs_chdir (const char *path)
{
int32_t op_ret = -1;
diff --git a/libglusterfsclient/src/libglusterfsclient.h b/libglusterfsclient/src/libglusterfsclient.h
index 2486dd75450..74575fa61a7 100755
--- a/libglusterfsclient/src/libglusterfsclient.h
+++ b/libglusterfsclient/src/libglusterfsclient.h
@@ -1315,6 +1315,16 @@ glusterfs_fcntl (glusterfs_file_t fd, int cmd, ...);
int
glusterfs_chdir (const char *path);
+/*
+ * Change the current working directory to the path @fd is opened on.
+ *
+ * @fd : current working directory will be changed to path @fd is opened on.
+ *
+ * Returns 0 on success and -1 on with errno set appropriately.
+ */
+int
+glusterfs_fchdir (glusterfs_file_t fd);
+
/* FIXME: review the need for these apis */
/* added for log related initialization in booster fork implementation */
void