pkg/cloudfs.spec | 4
pkg/configure.ac | 2
scripts/cloudfs | 1
scripts/volfilter.py | 1
xlators/features/uidmap/src/Makefile.am | 1
xlators/features/uidmap/src/uidmap.c | 2570 +++++++++++++++++++++++++++++++-
xlators/features/uidmap/src/uidmap.h | 17
7 files changed, 2507 insertions(+), 89 deletions(-)
New commits:
commit f3416443abb324d7aef5b45fc28b47c9954ddb64
Author: Kaleb S. KEITHLEY <kkeithle(a)cloudfs-node01.kkeithle.redhat.com>
Date: Thu May 19 15:01:17 2011 -0400
xlator to map tenant uids and gids from the client to unique uids and
gids on the server.
No attempt is made to avoid collisions between server-side uids and
gids among muliple tenants. To avoid collisions the per-tenant xlator
configuration may specify ranges that can not collide. (In fact that
seems like a good enhancement for the cloudfs python script that creates
the gluster volume config file.)
uids and gids are mapped for every fop, on the premise that we do not
(and probably cannot) know what down-stream xlators might do. Thus they
are mapped, early, so that any effects on the fop resulting from, e.g.
SELinux, will be performed with the nominally correct uid and gid.
The uidmap xlator has a simplistic map built in as the default,
implemented with a linear array that is malloced/realloced when new
mappings are created. This default mapper can be over-ridden by configuring
a smarter/faster mapper. And in fact one of the next tasks will be to
provide a tree-based mapper. Watch this space.
diff --git a/pkg/cloudfs.spec b/pkg/cloudfs.spec
index 6e5d336..503e99d 100644
--- a/pkg/cloudfs.spec
+++ b/pkg/cloudfs.spec
@@ -17,10 +17,10 @@ URL:
http://cloudfs.org
Source0:
http://cloudfs.org/dist/0.5/cloudfs-0.5.tgz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
-Requires: glusterfs = 3.1.4
+Requires: glusterfs = 3.1.3git
Requires: openssl
Requires: python
-BuildRequires: glusterfs-devel = 3.1.4
+BuildRequires: glusterfs-devel = 3.1.3git
BuildRequires: bison flex
BuildRequires: gcc make
BuildRequires: openssl-devel
diff --git a/pkg/configure.ac b/pkg/configure.ac
index f4d940d..c185be5 100644
--- a/pkg/configure.ac
+++ b/pkg/configure.ac
@@ -65,7 +65,7 @@ if test "x${have_spinlock}" = "xyes"; then
AC_DEFINE(HAVE_SPINLOCK, 1, [define if found spinlock])
fi
-GLUSTER_VERSION=3.1.4git
+GLUSTER_VERSION=3.1.3git
GF_HOST_OS=""
GF_LDFLAGS="-rdynamic"
GF_HOST_OS="GF_LINUX_HOST_OS"
diff --git a/scripts/cloudfs b/scripts/cloudfs
index ed521f1..7add059 100755
--- a/scripts/cloudfs
+++ b/scripts/cloudfs
@@ -100,6 +100,7 @@ def cloudify_server (volfile, users):
for user, pw in users:
new_stack = copy_stack(last.subvols[0],user)
volfilter.push_filter(graph,new_stack,"features/oplock")
+ volfilter.push_filter(graph,new_stack,"features/uidmap")
new_stack.name = user
subvols.append(new_stack)
diff --git a/scripts/volfilter.py b/scripts/volfilter.py
index 1b61595..b68611f 100755
--- a/scripts/volfilter.py
+++ b/scripts/volfilter.py
@@ -32,6 +32,7 @@ good_xlators = [
"features/access-control",
"features/locks",
"features/marker",
+ "features/uidmap",
"performance/io-threads",
"protocol/client",
"protocol/server",
diff --git a/xlators/features/uidmap/src/Makefile.am
b/xlators/features/uidmap/src/Makefile.am
index daba512..f603b77 100644
--- a/xlators/features/uidmap/src/Makefile.am
+++ b/xlators/features/uidmap/src/Makefile.am
@@ -1,3 +1,4 @@
+
xlator_LTLIBRARIES = uidmap.la
xlatordir = $(libdir)/glusterfs/$(GLUSTER_VERSION)/xlator/features
diff --git a/xlators/features/uidmap/src/uidmap.c b/xlators/features/uidmap/src/uidmap.c
index 9cab7df..3cd86c7 100644
--- a/xlators/features/uidmap/src/uidmap.c
+++ b/xlators/features/uidmap/src/uidmap.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011 Red Hat, Inc.
+ * Copyright © 2011 Red Hat, Inc.
*
* This file is part of CloudFS.
*
@@ -15,112 +15,2530 @@
*
* You should have received a copy of the GNU Affero General Public License *
* along with CloudFS. If not, see <
http://www.gnu.org/licenses/>.
- */
-
-#include <ctype.h>
-#include <sys/uio.h>
+*/
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif
+/**
+ * xlators/cluster/uidmap :
+ */
+
+#include <time.h>
+#include <dlfcn.h>
+#include <sys/file.h>
#include "glusterfs.h"
+#include "stack.h"
#include "xlator.h"
-#include "logging.h"
-#include "server/server.h"
-#include "server/server-helpers.h"
-
+#include "common-utils.h"
#include "uidmap.h"
-int32_t
-uidmap_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
- int32_t op_ret, int32_t op_errno, fd_t *fd)
+static uid_t uidmap_low_uid = 10000;
+static uid_t uidmap_hi_uid = 20000;
+static gid_t uidmap_low_gid = 10000;
+static gid_t uidmap_hi_gid = 20000;
+static short uidmap_root_squash = 1;
+static char *uidmap_tenant_override = NULL;
+
+#define CLOUDFS_NOBODY 65534
+
+typedef struct uid_map_entry {
+ uid_t me_client_uid;
+ uid_t me_server_uid;
+} uid_map_entry_t;
+
+typedef struct gid_map_entry {
+ uid_t me_client_gid;
+ uid_t me_server_gid;
+} gid_map_entry_t;
+
+typedef struct id_mapping {
+ uid_map_entry_t *im_uid_map;
+ unsigned short im_uid_map_len;
+ uid_t im_uid_low;
+ uid_t im_uid_high;
+ uid_t im_uid_next;
+ gid_map_entry_t *im_gid_map;
+ unsigned short im_gid_map_len;
+ gid_t im_gid_low;
+ gid_t im_gid_high;
+ gid_t im_gid_next;
+
+ pthread_mutex_t im_mtx;
+} id_mapping_t;
+
+static id_mapping_t uidmap_mapping = {
+ .im_uid_map = NULL,
+ .im_uid_map_len = 0,
+ .im_uid_low = 10000,
+ .im_uid_high = 20000,
+ .im_uid_next = 10000,
+ .im_gid_map = NULL,
+ .im_gid_map_len = 0,
+ .im_gid_low = 10000,
+ .im_gid_high = 20000,
+ .im_gid_next = 10000,
+ .im_mtx = PTHREAD_MUTEX_INITIALIZER
+};
+
+#define CFS_SIGNATURE "cloudfs map: default\n"
+#define CFS_UID_MAP_ENTRY "uid_map_entry:"
+#define CFS_UID_MAP_ENTRY_LEN 13
+#define CFS_UID_LOW "uid_low:"
+#define CFS_UID_LOW_LEN 8
+#define CFS_UID_HIGH "uid_high:"
+#define CFS_UID_HIGH_LEN 9
+#define CFS_UID_NEXT "uid_next:"
+#define CFS_UID_NEXT_LEN 9
+#define CFS_GID_MAP_ENTRY "gid_map_entry:"
+#define CFS_GID_MAP_ENTRY_LEN 13
+#define CFS_GID_LOW "gid_low:"
+#define CFS_GID_LOW_LEN 8
+#define CFS_GID_HIGH "gid_high:"
+#define CFS_GID_HIGH_LEN 9
+#define CFS_GID_NEXT "gid_next:"
+#define CFS_GID_NEXT_LEN 9
+
+
+static void
+uidmap_serialize_default(char *name)
+{
+ char fname[128], lkname[128];
+ (void) snprintf(lkname, sizeof lkname, "/var/lib/cloudfs/map_%s.lck",
name);
+ (void) snprintf(fname, sizeof fname, "/var/lib/cloudfs/map_%s", name);
+
+ int lockfd = open(lkname, O_CREAT|O_WRONLY, 0644);
+ if (lockfd != -1) {
+ int status = flock(lockfd, LOCK_EX);
+ if (status != -1) {
+ unsigned short i;
+ FILE *file = fopen(fname, "w");
+ if (file != NULL) {
+ (void) fprintf(file, "cloudfs map:
default\n");
+ for (i = 0; i < uidmap_mapping.im_uid_map_len; i++)
+ (void) fprintf(file, "%s: %u %u\n",
+ CFS_UID_MAP_ENTRY,
+
uidmap_mapping.im_uid_map[i].me_client_uid,
+
uidmap_mapping.im_uid_map[i].me_server_uid);
+ (void) fprintf(file, "%s: %u\n", CFS_UID_LOW,
uidmap_mapping.im_uid_low);
+ (void) fprintf(file, "%s: %u\n", CFS_UID_HIGH,
uidmap_mapping.im_uid_high);
+ (void) fprintf(file, "%s: %u\n", CFS_UID_NEXT,
uidmap_mapping.im_uid_next);
+ for (i = 0; i < uidmap_mapping.im_gid_map_len; i++)
+ (void) fprintf(file, "%s: %u %u\n",
+ CFS_GID_MAP_ENTRY,
+
uidmap_mapping.im_gid_map[i].me_client_gid,
+
uidmap_mapping.im_gid_map[i].me_server_gid);
+ (void) fprintf(file, "%s: %u\n", CFS_GID_LOW,
uidmap_mapping.im_gid_low);
+ (void) fprintf(file, "%s: %u\n", CFS_GID_HIGH,
uidmap_mapping.im_gid_high);
+ (void) fprintf(file, "%s: %u\n", CFS_GID_NEXT,
uidmap_mapping.im_gid_next);
+ (void) fclose(file);
+ }
+ (void) flock(lockfd, LOCK_UN);
+ }
+ (void) close(lockfd);
+ }
+}
+
+static int
+uidmap_deserialize_default(char *name)
{
- STACK_UNWIND_STRICT(open,frame,op_ret,op_errno,fd);
+ char fname[128], lkname[128];
+ (void) snprintf(lkname, sizeof lkname, "/var/lib/cloudfs/map_%s.lck",
name);
+ (void) snprintf(fname, sizeof fname, "/var/lib/cloudfs/map_%s", name);
+
+ int lockfd = open(lkname, O_CREAT|O_RDONLY, 0644);
+ if (lockfd != -1) {
+ int status = flock(lockfd, LOCK_EX);
+ if (status != -1) {
+ char scratch[128];
+ FILE *file = fopen(fname, "r");
+ if (file != NULL) {
+ char* sts;
+ /* read the first line (signature) of the file) */
+ if ((sts = fgets(scratch, sizeof scratch, file)) != (char
*) EOF && sts != NULL) {
+ if (strcmp("cloudfs map: default\n",
scratch) == 0) {
+ while ((sts = fgets(scratch, sizeof
scratch, file)) != (char *) EOF && sts != NULL) {
+ if (strncmp(scratch,
CFS_UID_MAP_ENTRY, CFS_UID_MAP_ENTRY_LEN) == 0) {
+ uid_t server_uid;
+ uid_t client_uid;
+ int num =
sscanf(&scratch[CFS_UID_MAP_ENTRY_LEN+1], " %u %u", &client_uid,
&server_uid);
+ if (num == 2) {
+ uid_map_entry_t
*uid_map_entry = NULL;
+
uidmap_mapping.im_uid_map = REALLOC(uidmap_mapping.im_uid_map, sizeof(uid_map_entry_t) *
(uidmap_mapping.im_uid_map_len + 1));
+ if
(uidmap_mapping.im_uid_map == NULL)
+ return
-1;
+ uid_map_entry =
&uidmap_mapping.im_uid_map[uidmap_mapping.im_uid_map_len++];
+
uid_map_entry->me_client_uid = client_uid;
+
uid_map_entry->me_server_uid = server_uid;
+ }
+ } else if (strncmp(scratch,
CFS_UID_LOW, CFS_UID_LOW_LEN) == 0) {
+ uidmap_mapping.im_uid_low
= (uid_t) strtoul(&scratch[CFS_UID_LOW_LEN+1], NULL, 10);
+ } else if (strncmp(scratch,
CFS_UID_HIGH, CFS_UID_HIGH_LEN) == 0) {
+
uidmap_mapping.im_uid_high = (uid_t) strtoul(&scratch[CFS_UID_HIGH_LEN+1], NULL, 10);
+ } else if (strncmp(scratch,
CFS_UID_NEXT, CFS_UID_NEXT_LEN) == 0) {
+
uidmap_mapping.im_uid_next = (uid_t) strtoul(&scratch[CFS_UID_NEXT_LEN+1], NULL, 10);
+ } else if (strncmp(scratch,
CFS_GID_MAP_ENTRY, CFS_GID_MAP_ENTRY_LEN) == 0) {
+ gid_t server_gid;
+ gid_t client_gid;
+ int num =
sscanf(&scratch[CFS_GID_MAP_ENTRY_LEN+1], " %u %u", &client_gid,
&server_gid);
+ if (num == 2) {
+ gid_map_entry_t
*gid_map_entry = NULL;
+
uidmap_mapping.im_gid_map = REALLOC(uidmap_mapping.im_gid_map, sizeof(gid_map_entry_t) *
(uidmap_mapping.im_gid_map_len + 1));
+ if
(uidmap_mapping.im_gid_map == NULL)
+ return
-1;
+ gid_map_entry =
&uidmap_mapping.im_gid_map[uidmap_mapping.im_gid_map_len++];
+
gid_map_entry->me_client_gid = client_gid;
+
gid_map_entry->me_server_gid = server_gid;
+ }
+ } else if (strncmp(scratch,
CFS_GID_LOW, CFS_GID_LOW_LEN) == 0) {
+ uidmap_mapping.im_gid_low
= (uid_t) strtoul(&scratch[CFS_GID_LOW_LEN+1], NULL, 10);
+ } else if (strncmp(scratch,
CFS_GID_HIGH, CFS_GID_HIGH_LEN) == 0) {
+
uidmap_mapping.im_gid_high = (uid_t) strtoul(&scratch[CFS_GID_HIGH_LEN+1], NULL, 10);
+ } else if (strncmp(scratch,
CFS_GID_NEXT, CFS_GID_NEXT_LEN) == 0) {
+
uidmap_mapping.im_gid_next = (uid_t) strtoul(&scratch[CFS_GID_NEXT_LEN+1], NULL, 10);
+ }
+ }
+ }
+ }
+ (void) fclose(file);
+ }
+ (void) flock(lockfd, LOCK_UN);
+ }
+ (void) close(lockfd);
+ }
return 0;
}
-int32_t
-uidmap_open (call_frame_t *frame, xlator_t *this,
- loc_t *loc, int32_t flags, fd_t *fd, int32_t wbflags)
+
+static int
+uidmap_map_default(struct _call_stack_t *stack, struct _xlator *xlator)
{
- uidmap_private_t *priv = this->private;
- xlator_t *child = FIRST_CHILD(this);
+ int need_serialize = 0;
- gf_log(this->name,GF_LOG_DEBUG,"mapping tenant %u, uid %u\n",
- priv->tenant, frame->root->uid);
+ if (stack->uid == 0 && uidmap_root_squash) {
+ stack->uid = stack->gid = CLOUDFS_NOBODY;
+ return 0;
+ }
- STACK_WIND(frame, uidmap_open_cbk, child, child->fops->open,
- loc,flags,fd,wbflags);
- return 0;
+ pthread_mutex_lock(&uidmap_mapping.im_mtx);
+ do {
+ /* look for an existing match */
+ char* name = uidmap_tenant_override ? uidmap_tenant_override :
xlator->name;
+ uid_map_entry_t *uid_map_entry = NULL;
+ gid_map_entry_t *gid_map_entry = NULL;
+ unsigned short index = 0;
+ for (; index < uidmap_mapping.im_uid_map_len; index++) {
+ if (uidmap_mapping.im_uid_map[index].me_client_uid ==
stack->uid) {
+
+ uid_map_entry = &uidmap_mapping.im_uid_map[index];
+ break;
+ }
+ }
+
+ /* couldn't find one, make a new one */
+ if (uid_map_entry == NULL) {
+ uid_map_entry_t *tmpmap = REALLOC(uidmap_mapping.im_uid_map,
sizeof(uid_map_entry_t) * (uidmap_mapping.im_uid_map_len + 1));
+
+ if (tmpmap == NULL) {
+ pthread_mutex_unlock(&uidmap_mapping.im_mtx);
+ return -1;
+ }
+
+ need_serialize = 1;
+
+ uidmap_mapping.im_uid_map = tmpmap;
+ uid_map_entry =
&uidmap_mapping.im_uid_map[uidmap_mapping.im_uid_map_len++];
+ uid_map_entry->me_client_uid = stack->uid;
+ uid_map_entry->me_server_uid = uidmap_mapping.im_uid_next++;
+ gf_log("map uid", GF_LOG_NORMAL,
+ "added new uid mapping for %s %u -> %u",
+ name, stack->uid, uid_map_entry->me_server_uid);
+ }
+
+ stack->uid = uid_map_entry->me_server_uid;
+
+ for (index = 0; index < uidmap_mapping.im_gid_map_len; index++) {
+ if (uidmap_mapping.im_gid_map[index].me_client_gid ==
stack->gid) {
+
+ gid_map_entry = &uidmap_mapping.im_gid_map[index];
+ break;
+ }
+ }
+
+ /* couldn't find one, make a new one */
+ if (gid_map_entry == NULL) {
+ gid_map_entry_t *tmpmap = REALLOC(uidmap_mapping.im_gid_map,
sizeof(gid_map_entry_t) * (uidmap_mapping.im_gid_map_len + 1));
+
+ if (tmpmap == NULL) {
+ pthread_mutex_unlock(&uidmap_mapping.im_mtx);
+ return -1;
+ }
+
+ need_serialize = 1;
+
+ uidmap_mapping.im_gid_map = tmpmap;
+ gid_map_entry =
&uidmap_mapping.im_gid_map[uidmap_mapping.im_gid_map_len++];
+ gid_map_entry->me_client_gid = stack->gid;
+ gid_map_entry->me_server_gid = uidmap_mapping.im_gid_next++;
+ gf_log("map gid", GF_LOG_NORMAL,
+ "added new gid mapping for %s %u -> %u",
+ name, stack->gid, gid_map_entry->me_server_gid);
+ }
+
+ stack->gid = gid_map_entry->me_server_gid;
+ } while (0);
+
+ if (need_serialize > 0)
+ uidmap_serialize_default(xlator->name);
+
+ pthread_mutex_unlock(&uidmap_mapping.im_mtx);
+
+ return 0;
}
-int32_t
-init (xlator_t *this)
-{
- uidmap_private_t *priv = NULL;
- char *db = NULL;
- uid_t tenant = 0;
-
- if (!this->children || this->children->next) {
- gf_log ("uidmap", GF_LOG_ERROR,
- "FATAL: uidmap should have exactly one child");
- return -1;
- }
-
- if (!this->parents) {
- gf_log (this->name, GF_LOG_WARNING,
- "dangling volume. check volfile ");
- }
-
- if (dict_get_str(this->options,"database",&db) != 0) {
- gf_log(this->name,GF_LOG_ERROR,"missing option: database");
- return -1;
- }
-
- if (dict_get_uint32(this->options,"tenant",&tenant) != 0) {
- gf_log(this->name,GF_LOG_ERROR,"missing option: tenant");
- return -1;
- }
-
- priv = CALLOC (1, sizeof(uidmap_private_t));
- if (!priv) {
- return -1;
- }
- priv->db_path = gf_strdup(db);
- priv->tenant = tenant;
- this->private = priv;
-
- gf_log ("uidmap", GF_LOG_INFO, "uidmap xlator loaded with db=%s
t=%u",
- priv->db_path, priv->tenant);
- return 0;
+
+static void
+uidmap_revmap_default(struct _call_stack_t *stack, uid_t *uid, gid_t *gid)
+{
+ unsigned int index = 0;
+ gf_log("revmap enter", GF_LOG_NORMAL, "revmap %u:%u", *uid,
*gid);
+ if (*uid != 0 && *uid != CLOUDFS_NOBODY) {
+ uid_map_entry_t *uid_map_entry = uidmap_mapping.im_uid_map;
+ for (; index < uidmap_mapping.im_uid_map_len; index++,
uid_map_entry++) {
+ if (*uid == uid_map_entry->me_server_uid)
+ *uid = uid_map_entry->me_client_uid;
+ }
+ }
+
+ if (*gid != 0 && *gid != CLOUDFS_NOBODY) {
+ gid_map_entry_t *gid_map_entry = uidmap_mapping.im_gid_map;
+ for (index = 0; index < uidmap_mapping.im_gid_map_len; index++,
gid_map_entry++) {
+ if (*gid == gid_map_entry->me_server_gid)
+ *gid = gid_map_entry->me_client_gid;
+ }
+ }
+ gf_log("revmap leave", GF_LOG_NORMAL, "revmap returning
%u:%u", *uid, *gid);
}
-void
-fini (xlator_t *this)
+static map_fn uidmap_map = NULL;
+static revmap_fn uidmap_revmap = NULL;
+static fini_fn uidmap_plugin_fini = NULL;
+
+
+static char *
+uidmap_stat_to_str(struct iatt *stbuf)
+{
+ char *statstr = NULL;
+ char atime_buf[256] = {0,};
+ char mtime_buf[256] = {0,};
+ char ctime_buf[256] = {0,};
+ int asprint_ret_value = 0;
+ uint64_t ia_time = 0;
+
+ ia_time = stbuf->ia_atime;
+ strftime(atime_buf, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = stbuf->ia_mtime;
+ strftime(mtime_buf, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = stbuf->ia_ctime;
+ strftime(ctime_buf, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ asprint_ret_value = gf_asprintf(&statstr,
+ "ia_ino=%"PRIu64
+ ", st_mode=%o,
ia_nlink=%"GF_PRI_NLINK", "
+ "ia_uid=%d, ia_gid=%d,
ia_size=%"PRId64", ia_blocks=%"PRId64
+ ", ia_atime=%s, ia_mtime=%s,
ia_ctime=%s",
+ stbuf->ia_ino,
+ st_mode_from_ia(stbuf->ia_prot,
stbuf->ia_type),
+ stbuf->ia_nlink, stbuf->ia_uid,
+ stbuf->ia_gid, stbuf->ia_size,
+ stbuf->ia_blocks, atime_buf,
+ mtime_buf, ctime_buf);
+
+ if (asprint_ret_value < 0)
+ statstr = NULL;
+
+ return statstr;
+}
+
+
+int
+uidmap_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 *buf,
+ struct iatt *preparent, struct iatt *postparent)
+{
+ char *statstr = NULL;
+ char *preparentstr = NULL;
+ char *postparentstr = NULL;
+
+ if (op_ret >= 0) {
+ statstr = uidmap_stat_to_str(buf);
+ preparentstr = uidmap_stat_to_str(preparent);
+ postparentstr = uidmap_stat_to_str(postparent);
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, fd=%p,
ino=%"PRIu64" "
+ "*stbuf {%s}, *preparent {%s}, *postparent = "
+ "{%s})",
+ frame->root->unique, op_ret, fd, inode->ino,
+ statstr, preparentstr, postparentstr);
+
+ if (statstr)
+ GF_FREE(statstr);
+ if (preparentstr)
+ GF_FREE(preparentstr);
+ if (postparentstr)
+ GF_FREE(postparentstr);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &buf->ia_uid, &buf->ia_gid);
+
+ STACK_UNWIND_STRICT(create, frame, op_ret, op_errno, fd, inode, buf,
+ preparent, postparent);
+ return 0;
+}
+
+
+int
+uidmap_open_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, fd_t *fd)
+{
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d, *fd=%p)",
+ frame->root->unique, op_ret, op_errno, fd);
+
+ STACK_UNWIND_STRICT(open, frame, op_ret, op_errno, fd);
+ return 0;
+}
+
+
+int
+uidmap_stat_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *buf)
+{
+ uint64_t ia_time = 0;
+ char atime_buf[256];
+ char mtime_buf[256];
+ char ctime_buf[256];
+
+ if (op_ret >= 0) {
+ ia_time = buf->ia_atime;
+ strftime(atime_buf, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = buf->ia_mtime;
+ strftime(mtime_buf, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = buf->ia_ctime;
+ strftime(ctime_buf, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, buf {"
+ "ia_ino=%"PRIu64", st_mode=%o,
ia_nlink=%"GF_PRI_NLINK", "
+ "ia_uid=%d, ia_gid=%d, ia_rdev=%"PRIu64",
ia_size=%"PRId64
+ ", ia_blksize=%"GF_PRI_BLKSIZE",
ia_blocks=%"PRId64", "
+ "ia_atime=%s, ia_mtime=%s, ia_ctime=%s})",
+ frame->root->unique, op_ret, buf->ia_ino,
+ st_mode_from_ia(buf->ia_prot, buf->ia_type),
+ buf->ia_nlink, buf->ia_uid, buf->ia_gid,
+ buf->ia_rdev, buf->ia_size, buf->ia_blksize,
+ buf->ia_blocks, atime_buf, mtime_buf, ctime_buf);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &buf->ia_uid, &buf->ia_gid);
+
+ STACK_UNWIND_STRICT(stat, frame, op_ret, op_errno, buf);
+ return 0;
+}
+
+
+int
+uidmap_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 *buf, struct iobref *iobref)
+{
+ uint64_t ia_time = 0;
+ char atime_buf[256];
+ char mtime_buf[256];
+ char ctime_buf[256];
+
+ if (op_ret >= 0) {
+ ia_time = buf->ia_atime;
+ strftime(atime_buf, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = buf->ia_mtime;
+ strftime(mtime_buf, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = buf->ia_ctime;
+ strftime(ctime_buf, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d, *buf {"
+ "ia_ino=%"PRIu64", st_mode=%o,
ia_nlink=%"GF_PRI_NLINK", "
+ "ia_uid=%d, ia_gid=%d, ia_rdev=%"PRIu64", "
+ "ia_size=%"PRId64",
ia_blksize=%"GF_PRI_BLKSIZE", "
+ "ia_blocks=%"PRId64", ia_atime=%s, ia_mtime=%s,
ia_ctime=%s})",
+ frame->root->unique, op_ret, op_errno, buf->ia_ino,
+ st_mode_from_ia(buf->ia_prot, buf->ia_type),
+ buf->ia_nlink, buf->ia_uid, buf->ia_gid,
+ buf->ia_rdev, buf->ia_size, buf->ia_blksize,
buf->ia_blocks,
+ atime_buf, mtime_buf, ctime_buf);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &buf->ia_uid, &buf->ia_gid);
+
+ STACK_UNWIND_STRICT(readv, frame, op_ret, op_errno, vector, count,
+ buf, iobref);
+ return 0;
+}
+
+
+int
+uidmap_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)
+{
+ char *preopstr = NULL;
+ char *postopstr = NULL;
+
+ if (op_ret >= 0) {
+ preopstr = uidmap_stat_to_str(prebuf);
+ postopstr = uidmap_stat_to_str(postbuf);
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, ino = %"PRIu64
+ ", *prebuf = {%s}, *postbuf = {%s})",
+ frame->root->unique, op_ret, postbuf->ia_ino,
+ preopstr, postopstr);
+
+ if (preopstr)
+ GF_FREE(preopstr);
+
+ if (postopstr)
+ GF_FREE(postopstr);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ /* (*uidmap_revmap)(frame->root, &buf->ia_uid, &buf->ia_gid);
*/
+
+ STACK_UNWIND_STRICT(writev, frame, op_ret, op_errno, prebuf, postbuf);
+ return 0;
+}
+
+
+
+int
+uidmap_readdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, gf_dirent_t *buf)
+{
+ struct _gf_dirent_t *entry;
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64" :(op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+
+ list_for_each_entry(entry, &buf->list, list) {
+ (*uidmap_revmap)(frame->root, &entry->d_stat.ia_uid,
&entry->d_stat.ia_gid);
+ }
+
+ STACK_UNWIND_STRICT(readdir, frame, op_ret, op_errno, buf);
+
+ return 0;
+}
+
+
+int
+uidmap_readdirp_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, gf_dirent_t *buf)
+{
+ struct _gf_dirent_t *entry = NULL;
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64" :(op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+
+ list_for_each_entry(entry, &buf->list, list) {
+ (*uidmap_revmap)(frame->root, &entry->d_stat.ia_uid,
&entry->d_stat.ia_gid);
+ }
+
+ STACK_UNWIND_STRICT(readdirp, frame, op_ret, op_errno, buf);
+
+ return 0;
+}
+
+
+int
+uidmap_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)
+{
+ char *preopstr = NULL;
+ char *postopstr = NULL;
+
+ if (op_ret >= 0) {
+ preopstr = uidmap_stat_to_str(prebuf);
+ postopstr = uidmap_stat_to_str(postbuf);
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, ino = %"PRIu64
+ ", *prebuf = {%s}, *postbuf = {%s}",
+ frame->root->unique, op_ret, postbuf->ia_ino,
+ preopstr, postopstr);
+
+ if (preopstr)
+ GF_FREE(preopstr);
+
+ if (postopstr)
+ GF_FREE(postopstr);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &prebuf->ia_uid,
&prebuf->ia_gid);
+ (*uidmap_revmap)(frame->root, &postbuf->ia_uid,
&postbuf->ia_gid);
+
+ STACK_UNWIND_STRICT(fsync, frame, op_ret, op_errno, prebuf, postbuf);
+
+ return 0;
+}
+
+
+int
+uidmap_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)
+{
+ uint64_t ia_time = 0;
+ char atime_pre[256] = {0,};
+ char mtime_pre[256] = {0,};
+ char ctime_pre[256] = {0,};
+ char atime_post[256] = {0,};
+ char mtime_post[256] = {0,};
+ char ctime_post[256] = {0,};
+
+ if (op_ret >= 0) {
+ ia_time = statpre->ia_atime;
+ strftime(atime_pre, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = statpre->ia_mtime;
+ strftime(mtime_pre, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = statpre->ia_ctime;
+ strftime(ctime_pre, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = statpost->ia_atime;
+ strftime(atime_post, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = statpost->ia_mtime;
+ strftime(mtime_post, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = statpost->ia_ctime;
+ strftime(ctime_post, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, *statpre "
+ "{ia_ino=%"PRIu64", st_mode=%o, ia_uid=%d, "
+ "ia_gid=%d, ia_atime=%s, ia_mtime=%s, "
+ "ia_ctime=%s}, *statpost {ia_ino=%"PRIu64", "
+ "st_mode=%o, ia_uid=%d, ia_gid=%d, ia_atime=%s,"
+ " ia_mtime=%s, ia_ctime=%s})",
+ frame->root->unique, op_ret, statpre->ia_ino,
+ st_mode_from_ia(statpre->ia_prot, statpre->ia_type),
+ statpre->ia_uid,
+ statpre->ia_gid, atime_pre, mtime_pre,
+ ctime_pre, statpost->ia_ino,
+ st_mode_from_ia(statpost->ia_prot, statpost->ia_type),
+ statpost->ia_uid, statpost->ia_gid, atime_post,
+ mtime_post, ctime_post);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &statpre->ia_uid,
&statpre->ia_gid);
+ (*uidmap_revmap)(frame->root, &statpost->ia_uid,
&statpost->ia_gid);
+
+ STACK_UNWIND_STRICT(setattr, frame, op_ret, op_errno, statpre, statpost);
+ return 0;
+}
+
+
+int
+uidmap_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)
+{
+ uint64_t ia_time = 0;
+ char atime_pre[256] = {0,};
+ char mtime_pre[256] = {0,};
+ char ctime_pre[256] = {0,};
+ char atime_post[256] = {0,};
+ char mtime_post[256] = {0,};
+ char ctime_post[256] = {0,};
+
+ if (op_ret >= 0) {
+ ia_time = statpre->ia_atime;
+ strftime(atime_pre, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = statpre->ia_mtime;
+ strftime(mtime_pre, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = statpre->ia_ctime;
+ strftime(ctime_pre, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = statpost->ia_atime;
+ strftime(atime_post, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = statpost->ia_mtime;
+ strftime(mtime_post, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = statpost->ia_ctime;
+ strftime(ctime_post, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, *statpre "
+ "{ia_ino=%"PRIu64", st_mode=%o, ia_uid=%d, "
+ "ia_gid=%d, ia_atime=%s, ia_mtime=%s, "
+ "ia_ctime=%s}, *statpost {ia_ino=%"PRIu64", "
+ "st_mode=%o, ia_uid=%d, ia_gid=%d, ia_atime=%s,"
+ " ia_mtime=%s, ia_ctime=%s})",
+ frame->root->unique, op_ret, statpre->ia_ino,
+ st_mode_from_ia(statpre->ia_prot, statpre->ia_type),
+ statpre->ia_uid,
+ statpre->ia_gid, atime_pre, mtime_pre,
+ ctime_pre, statpost->ia_ino,
+ st_mode_from_ia(statpost->ia_prot, statpost->ia_type),
+ statpost->ia_uid, statpost->ia_gid, atime_post,
+ mtime_post, ctime_post);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &statpre->ia_uid,
&statpre->ia_gid);
+ (*uidmap_revmap)(frame->root, &statpost->ia_uid,
&statpost->ia_gid);
+
+ STACK_UNWIND_STRICT(fsetattr, frame, op_ret, op_errno,
+ statpre, statpost);
+ return 0;
+}
+
+
+int
+uidmap_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)
+{
+ char *preparentstr = NULL;
+ char *postparentstr = NULL;
+
+ if (op_ret >= 0) {
+ preparentstr = uidmap_stat_to_str(preparent);
+ postparentstr = uidmap_stat_to_str(postparent);
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, *preparent = {%s}, "
+ "*postparent = {%s})",
+ frame->root->unique, op_ret, preparentstr,
+ postparentstr);
+
+ if (preparentstr)
+ GF_FREE(preparentstr);
+
+ if (postparentstr)
+ GF_FREE(postparentstr);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &preparent->ia_uid,
&preparent->ia_gid);
+ (*uidmap_revmap)(frame->root, &postparent->ia_uid,
&postparent->ia_gid);
+
+ STACK_UNWIND_STRICT(unlink, frame, op_ret, op_errno,
+ preparent, postparent);
+ return 0;
+}
+
+
+int
+uidmap_rename_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *buf,
+ struct iatt *preoldparent, struct iatt *postoldparent,
+ struct iatt *prenewparent, struct iatt *postnewparent)
+{
+ char *statstr = NULL;
+ char *preoldparentstr = NULL;
+ char *postoldparentstr = NULL;
+ char *prenewparentstr = NULL;
+ char *postnewparentstr = NULL;
+
+ if (op_ret >= 0) {
+ statstr = uidmap_stat_to_str(buf);
+ preoldparentstr = uidmap_stat_to_str(preoldparent);
+ postoldparentstr = uidmap_stat_to_str(postoldparent);
+
+ prenewparentstr = uidmap_stat_to_str(prenewparent);
+ postnewparentstr = uidmap_stat_to_str(postnewparent);
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, *stbuf = {%s}, "
+ "*preoldparent = {%s}, *postoldparent = {%s}"
+ " *prenewparent = {%s}, *postnewparent = {%s})",
+ frame->root->unique, op_ret, statstr,
+ preoldparentstr, postoldparentstr,
+ prenewparentstr, postnewparentstr);
+
+ if (preoldparentstr)
+ GF_FREE(preoldparentstr);
+
+ if (postoldparentstr)
+ GF_FREE(postoldparentstr);
+
+ if (prenewparentstr)
+ GF_FREE(prenewparentstr);
+
+ if (postnewparentstr)
+ GF_FREE(postnewparentstr);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d, buf
{ia_ino=%"PRIu64"})",
+ frame->root->unique, op_ret, op_errno,
+ (buf? buf->ia_ino : 0));
+
+ (*uidmap_revmap)(frame->root, &buf->ia_uid, &buf->ia_gid);
+
+ STACK_UNWIND_STRICT(rename, frame, op_ret, op_errno, buf,
+ preoldparent, postoldparent,
+ prenewparent, postnewparent);
+ return 0;
+}
+
+
+int
+uidmap_readlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno,
+ const char *buf, struct iatt *stbuf)
+{
+ char *statstr = NULL;
+
+ if (op_ret == 0) {
+ statstr = uidmap_stat_to_str(stbuf);
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d, buf=%s,
"
+ "stbuf = { %s })",
+ frame->root->unique, op_ret, op_errno, buf,
+ statstr);
+ if (statstr)
+ GF_FREE(statstr);
+ } else
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d",
+ frame->root->unique, op_ret, op_errno);
+
+ (*uidmap_revmap)(frame->root, &stbuf->ia_uid, &stbuf->ia_gid);
+
+ STACK_UNWIND_STRICT(readlink, frame, op_ret, op_errno, buf, stbuf);
+ return 0;
+}
+
+
+int
+uidmap_lookup_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno,
+ inode_t *inode, struct iatt *buf,
+ dict_t *xattr, struct iatt *postparent)
+{
+ char *statstr = NULL;
+ char *postparentstr = NULL;
+
+ if (op_ret >= 0) {
+ statstr = uidmap_stat_to_str(buf);
+ postparentstr = uidmap_stat_to_str(postparent);
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, ino=%"PRIu64",
"
+ "*buf {%s}, *postparent {%s}",
+ frame->root->unique, op_ret, inode->ino,
+ statstr, postparentstr);
+
+ if (statstr)
+ GF_FREE(statstr);
+ if (postparentstr)
+ GF_FREE(postparentstr);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &buf->ia_uid, &buf->ia_gid);
+ (*uidmap_revmap)(frame->root, &postparent->ia_uid,
&postparent->ia_gid);
+
+ STACK_UNWIND_STRICT(lookup, frame, op_ret, op_errno, inode, buf,
+ xattr, postparent);
+ return 0;
+}
+
+
+int
+uidmap_symlink_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno,
+ inode_t *inode, struct iatt *buf,
+ struct iatt *preparent, struct iatt *postparent)
+{
+ char *statstr = NULL;
+ char *preparentstr = NULL;
+ char *postparentstr = NULL;
+
+ if (op_ret >= 0) {
+ statstr = uidmap_stat_to_str(buf);
+ preparentstr = uidmap_stat_to_str(preparent);
+ postparentstr = uidmap_stat_to_str(postparent);
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, ino=%"PRIu64",
"
+ "*stbuf = {%s}, *preparent = {%s}, "
+ "*postparent = {%s})",
+ frame->root->unique, op_ret, inode->ino,
+ statstr, preparentstr, postparentstr);
+
+ if (statstr)
+ GF_FREE(statstr);
+
+ if (preparentstr)
+ GF_FREE(preparentstr);
+
+ if (postparentstr)
+ GF_FREE(postparentstr);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &buf->ia_uid, &buf->ia_gid);
+
+ STACK_UNWIND_STRICT(symlink, frame, op_ret, op_errno, inode, buf,
+ preparent, postparent);
+ return 0;
+}
+
+
+int
+uidmap_mknod_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno,
+ inode_t *inode, struct iatt *buf,
+ struct iatt *preparent, struct iatt *postparent)
+{
+ char *statstr = NULL;
+ char *preparentstr = NULL;
+ char *postparentstr = NULL;
+
+ if (op_ret >= 0) {
+ statstr = uidmap_stat_to_str(buf);
+ preparentstr = uidmap_stat_to_str(preparent);
+ postparentstr = uidmap_stat_to_str(postparent);
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, ino=%"PRIu64",
"
+ "*stbuf = {%s}, *preparent = {%s}, "
+ "*postparent = {%s})",
+ frame->root->unique, op_ret, inode->ino,
+ statstr, preparentstr, postparentstr);
+
+ if (statstr)
+ GF_FREE(statstr);
+
+ if (preparentstr)
+ GF_FREE(preparentstr);
+
+ if (postparentstr)
+ GF_FREE(postparentstr);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &buf->ia_uid, &buf->ia_gid);
+
+ STACK_UNWIND_STRICT(mknod, frame, op_ret, op_errno, inode, buf,
+ preparent, postparent);
+ return 0;
+}
+
+
+int
+uidmap_mkdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno,
+ inode_t *inode, struct iatt *buf,
+ struct iatt *preparent, struct iatt *postparent)
+{
+ char *statstr = NULL;
+ char *preparentstr = NULL;
+ char *postparentstr = NULL;
+
+ if (op_ret >= 0) {
+ statstr = uidmap_stat_to_str(buf);
+ preparentstr = uidmap_stat_to_str(preparent);
+ postparentstr = uidmap_stat_to_str(postparent);
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, ino = %"PRIu64
+ ", *stbuf = {%s}, *prebuf = {%s}, "
+ "*postbuf = {%s} )",
+ frame->root->unique, op_ret, buf->ia_ino,
+ statstr, preparentstr, postparentstr);
+
+ if (statstr)
+ GF_FREE(statstr);
+
+ if (preparentstr)
+ GF_FREE(preparentstr);
+
+ if (postparentstr)
+ GF_FREE(postparentstr);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &buf->ia_uid, &buf->ia_gid);
+
+ STACK_UNWIND_STRICT(mkdir, frame, op_ret, op_errno, inode, buf,
+ preparent, postparent);
+ return 0;
+}
+
+
+int
+uidmap_link_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno,
+ inode_t *inode, struct iatt *buf,
+ struct iatt *preparent, struct iatt *postparent)
+{
+ char *statstr = NULL;
+ char *preparentstr = NULL;
+ char *postparentstr = NULL;
+
+ if (op_ret >= 0) {
+ statstr = uidmap_stat_to_str(buf);
+ preparentstr = uidmap_stat_to_str(preparent);
+ postparentstr = uidmap_stat_to_str(postparent);
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, ino = %"PRIu64
+ ", *stbuf = {%s}, *prebuf = {%s}, "
+ "*postbuf = {%s})",
+ frame->root->unique, op_ret, buf->ia_ino,
+ statstr, preparentstr, postparentstr);
+
+ if (statstr)
+ GF_FREE(statstr);
+
+ if (preparentstr)
+ GF_FREE(preparentstr);
+
+ if (postparentstr)
+ GF_FREE(postparentstr);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &buf->ia_uid, &buf->ia_gid);
+
+ STACK_UNWIND_STRICT(link, frame, op_ret, op_errno, inode, buf,
+ preparent, postparent);
+ return 0;
+}
+
+
+int
+uidmap_flush_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno)
{
- uidmap_private_t *priv = this->private;
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+
+ STACK_UNWIND_STRICT(flush, frame, op_ret, op_errno);
+ return 0;
+}
+
+
+int
+uidmap_opendir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, fd_t *fd)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d, fd=%p)",
+ frame->root->unique, op_ret, op_errno, fd);
+
+ STACK_UNWIND_STRICT(opendir, frame, op_ret, op_errno, fd);
+ return 0;
+}
+
+
+int
+uidmap_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)
+{
+ char *preparentstr = NULL;
+ char *postparentstr = NULL;
+
+ if (op_ret >= 0) {
+ preparentstr = uidmap_stat_to_str(preparent);
+ postparentstr = uidmap_stat_to_str(postparent);
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, *prebuf = {%s}, "
+ "*postbuf = {%s}",
+ frame->root->unique, op_ret, preparentstr,
+ postparentstr);
+
+ if (preparentstr)
+ GF_FREE(preparentstr);
+
+ if (postparentstr)
+ GF_FREE(postparentstr);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &preparent->ia_uid,
&preparent->ia_gid);
+ (*uidmap_revmap)(frame->root, &postparent->ia_uid,
&postparent->ia_gid);
+
+ STACK_UNWIND_STRICT(rmdir, frame, op_ret, op_errno,
+ preparent, postparent);
+ return 0;
+}
+
+
+int
+uidmap_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)
+{
+ char *preopstr = NULL;
+ char *postopstr = NULL;
+
+ if (op_ret >= 0) {
+ preopstr = uidmap_stat_to_str(prebuf);
+ postopstr = uidmap_stat_to_str(postbuf);
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, *prebuf = {%s}, "
+ "*postbuf = {%s} )",
+ frame->root->unique, op_ret, preopstr,
+ postopstr);
+
+ if (preopstr)
+ GF_FREE(preopstr);
+
+ if (postopstr)
+ GF_FREE(postopstr);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &prebuf->ia_uid,
&prebuf->ia_gid);
+ (*uidmap_revmap)(frame->root, &postbuf->ia_uid,
&postbuf->ia_gid);
+
+ STACK_UNWIND_STRICT(truncate, frame, op_ret, op_errno, prebuf, postbuf);
+ return 0;
+}
+
+
+int
+uidmap_statfs_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct statvfs *buf)
+{
+ if (op_ret >= 0) {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": ({f_bsize=%lu, f_frsize=%lu,
f_blocks=%"GF_PRI_FSBLK
+ ", f_bfree=%"GF_PRI_FSBLK",
f_bavail=%"GF_PRI_FSBLK", "
+ "f_files=%"GF_PRI_FSBLK",
f_ffree=%"GF_PRI_FSBLK", f_favail=%"
+ GF_PRI_FSBLK", f_fsid=%lu, f_flag=%lu, f_namemax=%lu}) =>
ret=%d",
+ frame->root->unique, buf->f_bsize, buf->f_frsize,
buf->f_blocks,
+ buf->f_bfree, buf->f_bavail, buf->f_files,
buf->f_ffree,
+ buf->f_favail, buf->f_fsid, buf->f_flag,
buf->f_namemax, op_ret);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ STACK_UNWIND_STRICT(statfs, frame, op_ret, op_errno, buf);
+ return 0;
+}
+
+
+int
+uidmap_setxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+
+ STACK_UNWIND_STRICT(setxattr, frame, op_ret, op_errno);
+ return 0;
+}
+
+
+int
+uidmap_getxattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *dict)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d, dict=%p)",
+ frame->root->unique, op_ret, op_errno, dict);
+
+ STACK_UNWIND_STRICT(getxattr, frame, op_ret, op_errno, dict);
+
+ return 0;
+}
+
+
+int
+uidmap_removexattr_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+
+ STACK_UNWIND_STRICT(removexattr, frame, op_ret, op_errno);
+
+ return 0;
+}
+
+
+int
+uidmap_fsyncdir_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+
+ STACK_UNWIND_STRICT(fsyncdir, frame, op_ret, op_errno);
+ return 0;
+}
+
+
+int
+uidmap_access_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+
+ STACK_UNWIND_STRICT(access, frame, op_ret, op_errno);
+ return 0;
+}
+
+
+int
+uidmap_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)
+{
+ char *prebufstr = NULL;
+ char *postbufstr = NULL;
+
+ if (op_ret >= 0) {
+ prebufstr = uidmap_stat_to_str(prebuf);
+ postbufstr = uidmap_stat_to_str(postbuf);
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, *prebuf = {%s}, "
+ "*postbuf = {%s} )",
+ frame->root->unique, op_ret,
+ prebufstr, postbufstr);
+
+ if (prebufstr)
+ GF_FREE(prebufstr);
+
+ if (postbufstr)
+ GF_FREE(postbufstr);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &prebuf->ia_uid,
&prebuf->ia_gid);
+ (*uidmap_revmap)(frame->root, &postbuf->ia_uid,
&postbuf->ia_gid);
+
+ STACK_UNWIND_STRICT(ftruncate, frame, op_ret, op_errno, prebuf, postbuf);
+ return 0;
+}
+
+
+int
+uidmap_fstat_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct iatt *buf)
+{
+ uint64_t ia_time = 0;
+ char atime_buf[256] = {0, };
+ char mtime_buf[256] = {0, };
+ char ctime_buf[256] = {0, };
+
+ if (op_ret >= 0) {
+ ia_time = buf->ia_atime;
+ strftime(atime_buf, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = buf->ia_mtime;
+ strftime(mtime_buf, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = buf->ia_ctime;
+ strftime(ctime_buf, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, *buf {"
+ "ia_ino=%"PRIu64", st_mode=%o,
ia_nlink=%"GF_PRI_NLINK", "
+ "ia_uid=%d, ia_gid=%d, ia_rdev=%"PRIu64",
ia_size=%"PRId64", "
+ "ia_blksize=%"GF_PRI_BLKSIZE",
ia_blocks=%"PRId64", ia_atime=%s, "
+ "ia_mtime=%s, ia_ctime=%s})",
+ frame->root->unique, op_ret, buf->ia_ino,
+ st_mode_from_ia(buf->ia_prot, buf->ia_type),
+ buf->ia_nlink, buf->ia_uid, buf->ia_gid,
+ buf->ia_rdev, buf->ia_size, buf->ia_blksize,
+ buf->ia_blocks, atime_buf, mtime_buf, ctime_buf);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &buf->ia_uid, &buf->ia_gid);
+
+ STACK_UNWIND_STRICT(fstat, frame, op_ret, op_errno, buf);
+ return 0;
+}
+
+
+int
+uidmap_lk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct gf_flock *lock)
+{
+ uid_t uid;
+ gid_t gid;
+ if (op_ret >= 0) {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, {l_type=%d, l_whence=%d,
"
+ "l_start=%"PRId64", l_len=%"PRId64",
l_pid=%u})",
+ frame->root->unique, op_ret, lock->l_type,
lock->l_whence,
+ lock->l_start, lock->l_len, lock->l_pid);
+ } else {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+ }
+
+ (*uidmap_revmap)(frame->root, &uid, &gid);
+ lock->l_owner = uid;
+
+ STACK_UNWIND_STRICT(lk, frame, op_ret, op_errno, lock);
+ return 0;
+}
+
+
+
+int
+uidmap_entrylk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": op_ret=%d, op_errno=%d",
+ frame->root->unique, op_ret, op_errno);
+
+ STACK_UNWIND_STRICT(entrylk, frame, op_ret, op_errno);
+ return 0;
+}
+
+
+int
+uidmap_xattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *dict)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+
+ STACK_UNWIND_STRICT(xattrop, frame, op_ret, op_errno, dict);
+ return 0;
+}
+
+
+int
+uidmap_fxattrop_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, dict_t *dict)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (op_ret=%d, op_errno=%d)",
+ frame->root->unique, op_ret, op_errno);
+
+ STACK_UNWIND_STRICT(fxattrop, frame, op_ret, op_errno, dict);
+ return 0;
+}
+
+
+int
+uidmap_inodelk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": op_ret=%d, op_errno=%d",
+ frame->root->unique, op_ret, op_errno);
+
+ STACK_UNWIND_STRICT(inodelk, frame, op_ret, op_errno);
+ return 0;
+}
+
+
+int
+uidmap_finodelk_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": op_ret=%d, op_errno=%d",
+ frame->root->unique, op_ret, op_errno);
+
+ STACK_UNWIND_STRICT(finodelk, frame, op_ret, op_errno);
+ return 0;
+}
+
+
+int
+uidmap_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_NORMAL,
+ "%"PRId64": volume=%s, (loc= {path=%s,
ino=%"PRIu64"} basename=%s, cmd=%s, type=%s)",
+ frame->root->unique, volume, loc->path, loc->inode->ino,
basename,
+ ((cmd == ENTRYLK_LOCK) ? "ENTRYLK_LOCK" :
"ENTRYLK_UNLOCK"),
+ ((type == ENTRYLK_RDLCK) ? "ENTRYLK_RDLCK" :
"ENTRYLK_WRLCK"));
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_entrylk_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->entrylk,
+ volume, loc, basename, cmd, type);
+ return 0;
+}
+
+
+int
+uidmap_inodelk(call_frame_t *frame, xlator_t *this, const char *volume,
+ loc_t *loc, int32_t cmd, struct gf_flock *flock)
+{
+ char *cmd_str = NULL;
+ char *type_str = NULL;
+
+ switch (cmd) {
+#if F_GETLK != F_GETLK64
+ case F_GETLK64:
+#endif
+ case F_GETLK:
+ cmd_str = "GETLK";
+ break;
+
+#if F_SETLK != F_SETLK64
+ case F_SETLK64:
+#endif
+ case F_SETLK:
+ cmd_str = "SETLK";
+ break;
+
+#if F_SETLKW != F_SETLKW64
+ case F_SETLKW64:
+#endif
+ case F_SETLKW:
+ cmd_str = "SETLKW";
+ break;
+
+ default:
+ cmd_str = "UNKNOWN";
+ break;
+ }
+
+ switch (flock->l_type) {
+ case F_RDLCK:
+ type_str = "READ";
+ break;
+ case F_WRLCK:
+ type_str = "WRITE";
+ break;
+ case F_UNLCK:
+ type_str = "UNLOCK";
+ break;
+ default:
+ type_str = "UNKNOWN";
+ break;
+ }
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": volume=%s, (loc {path=%s,
ino=%"PRIu64"}, "
+ "cmd=%s, type=%s, start=%llu, len=%llu, pid=%llu)",
+ frame->root->unique, volume, loc->path, loc->inode->ino,
+ cmd_str, type_str, (unsigned long long) flock->l_start,
+ (unsigned long long) flock->l_len,
+ (unsigned long long) flock->l_pid);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_inodelk_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->inodelk,
+ volume, loc, cmd, flock);
+ return 0;
+}
+
+
+int
+uidmap_finodelk(call_frame_t *frame, xlator_t *this, const char *volume,
+ fd_t *fd, int32_t cmd, struct gf_flock *flock)
+{
+ char *cmd_str = NULL, *type_str = NULL;
+
+ switch (cmd) {
+#if F_GETLK != F_GETLK64
+ case F_GETLK64:
+#endif
+ case F_GETLK:
+ cmd_str = "GETLK";
+ break;
+
+#if F_SETLK != F_SETLK64
+ case F_SETLK64:
+#endif
+ case F_SETLK:
+ cmd_str = "SETLK";
+ break;
+
+#if F_SETLKW != F_SETLKW64
+ case F_SETLKW64:
+#endif
+ case F_SETLKW:
+ cmd_str = "SETLKW";
+ break;
+
+ default:
+ cmd_str = "UNKNOWN";
+ break;
+ }
+
+ switch (flock->l_type) {
+ case F_RDLCK:
+ type_str = "READ";
+ break;
+ case F_WRLCK:
+ type_str = "WRITE";
+ break;
+ case F_UNLCK:
+ type_str = "UNLOCK";
+ break;
+ default:
+ type_str = "UNKNOWN";
+ break;
+ }
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": volume=%s, (fd =%p, ino=%"PRIu64"},
"
+ "cmd=%s, type=%s, start=%llu, len=%llu, pid=%llu)",
+ frame->root->unique, volume, fd, fd->inode->ino,
+ cmd_str, type_str, (unsigned long long) flock->l_start,
+ (unsigned long long) flock->l_len,
+ (unsigned long long) flock->l_pid);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_finodelk_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->finodelk,
+ volume, fd, cmd, flock);
+ return 0;
+}
+
+
+int
+uidmap_xattrop(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ gf_xattrop_flags_t flags, dict_t *dict)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (path=%s, ino=%"PRIu64"
flags=%d)",
+ frame->root->unique, loc->path, loc->inode->ino, flags);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_xattrop_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->xattrop,
+ loc, flags, dict);
+
+ return 0;
+}
+
+
+int
+uidmap_fxattrop(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ gf_xattrop_flags_t flags, dict_t *dict)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (fd=%p, flags=%d)",
+ frame->root->unique, fd, flags);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_fxattrop_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fxattrop,
+ fd, flags, dict);
+
+ return 0;
+}
+
+
+int
+uidmap_lookup(call_frame_t *frame, xlator_t *this,
+ loc_t *loc, dict_t *xattr_req)
+{
+ /* TODO: print all the keys mentioned in xattr_req */
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s,
ino=%"PRIu64"})",
+ frame->root->unique, loc->path,
+ loc->inode->ino);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_lookup_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lookup,
+ loc, xattr_req);
+
+ return 0;
+}
+
+
+int
+uidmap_stat(call_frame_t *frame, xlator_t *this, loc_t *loc)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s,
ino=%"PRIu64"})",
+ frame->root->unique, loc->path, loc->inode->ino);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_stat_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->stat,
+ loc);
+
+ return 0;
+}
+
+
+int
+uidmap_readlink(call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s, ino=%"PRIu64"},
size=%"GF_PRI_SIZET")",
+ frame->root->unique, loc->path, loc->inode->ino, size);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_readlink_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readlink,
+ loc, size);
+
+ return 0;
+}
+
+
+int
+uidmap_mknod(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ mode_t mode, dev_t dev, dict_t *params)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s, ino=%"PRIu64"},
mode=%d, dev=%"GF_PRI_DEV")",
+ frame->root->unique, loc->path, loc->inode->ino, mode,
dev);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_mknod_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->mknod,
+ loc, mode, dev, params);
+
+ return 0;
+}
+
+
+int
+uidmap_mkdir(call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
+ dict_t *params)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (path=%s, ino=%"PRIu64",
mode=%d)",
+ frame->root->unique, loc->path,
+ ((loc->inode)? loc->inode->ino : 0), mode);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ gf_log(this->name, GF_LOG_NORMAL, "mkdir uid: %u, gid: %u",
+ frame->root->uid, frame->root->gid);
+
+ STACK_WIND(frame, uidmap_mkdir_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->mkdir,
+ loc, mode, params);
+ return 0;
+}
+
+
+int
+uidmap_unlink(call_frame_t *frame, xlator_t *this, loc_t *loc)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s,
ino=%"PRIu64"})",
+ frame->root->unique, loc->path, loc->inode->ino);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_unlink_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->unlink,
+ loc);
+ return 0;
+}
+
+
+int
+uidmap_rmdir(call_frame_t *frame, xlator_t *this, loc_t *loc, int flags)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s, ino=%"PRIu64"},
flags=%d)",
+ frame->root->unique, loc->path, loc->inode->ino, flags);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_rmdir_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->rmdir,
+ loc, flags);
+
+ return 0;
+}
+
+
+int
+uidmap_symlink(call_frame_t *frame, xlator_t *this, const char *linkpath,
+ loc_t *loc, dict_t *params)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (linkpath=%s, loc {path=%s,
ino=%"PRIu64"})",
+ frame->root->unique, linkpath, loc->path,
+ ((loc->inode)? loc->inode->ino : 0));
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_symlink_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->symlink,
+ linkpath, loc, params);
+
+ return 0;
+}
+
+
+int
+uidmap_rename(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (oldloc {path=%s, ino=%"PRIu64"},
"
+ "newloc{path=%s, ino=%"PRIu64"})",
+ frame->root->unique, oldloc->path, oldloc->ino,
+ newloc->path, newloc->ino);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_rename_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->rename,
+ oldloc, newloc);
+
+ return 0;
+}
+
+
+int
+uidmap_link(call_frame_t *frame, xlator_t *this, loc_t *oldloc, loc_t *newloc)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (oldloc {path=%s, ino=%"PRIu64"},
"
+ "newloc {path=%s, ino=%"PRIu64"})",
+ frame->root->unique, oldloc->path, oldloc->inode->ino,
+ newloc->path, newloc->inode->ino);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_link_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->link,
+ oldloc, newloc);
+ return 0;
+}
+
+
+int
+uidmap_setattr(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ struct iatt *stbuf, int32_t valid)
+{
+ uint64_t ia_time = 0;
+ char actime_str[256] = {0,};
+ char modtime_str[256] = {0,};
+
+ if (valid & GF_SET_ATTR_MODE) {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s,
ino=%"PRIu64"},"
+ " mode=%o)", frame->root->unique, loc->path,
+ loc->inode->ino,
+ st_mode_from_ia(stbuf->ia_prot, stbuf->ia_type));
+ }
+
+ if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)) {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s,
ino=%"PRIu64"},"
+ " uid=%o, gid=%o)",
+ frame->root->unique, loc->path, loc->inode->ino,
+ stbuf->ia_uid, stbuf->ia_gid);
+ }
+
+ if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) {
+ ia_time = stbuf->ia_atime;
+ strftime(actime_str, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = stbuf->ia_mtime;
+ strftime(modtime_str, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s,
ino=%"PRIu64"}, "
+ "*stbuf=%p {ia_atime=%s, ia_mtime=%s})",
+ frame->root->unique, loc->path, loc->inode->ino,
+ stbuf, actime_str, modtime_str);
+ }
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_setattr_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setattr,
+ loc, stbuf, valid);
+
+ return 0;
+}
+
+
+int
+uidmap_fsetattr(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iatt *stbuf, int32_t valid)
+{
+ uint64_t ia_time = 0;
+ char actime_str[256] = {0,};
+ char modtime_str[256] = {0,};
+
+ if (valid & GF_SET_ATTR_MODE) {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (*fd=%p, mode=%o)",
+ frame->root->unique, fd,
+ st_mode_from_ia(stbuf->ia_prot, stbuf->ia_type));
+ }
+
+ if (valid & (GF_SET_ATTR_UID | GF_SET_ATTR_GID)) {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (*fd=%p, uid=%o, gid=%o)",
+ frame->root->unique, fd,
+ stbuf->ia_uid, stbuf->ia_gid);
+ }
+
+ if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) {
+ ia_time = stbuf->ia_atime;
+ strftime(actime_str, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ ia_time = stbuf->ia_mtime;
+ strftime(modtime_str, 256, "[%b %d %H:%M:%S]",
+ localtime((time_t *)&ia_time));
+
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (*fd=%p"
+ "*stbuf=%p {ia_atime=%s, ia_mtime=%s})",
+ frame->root->unique, fd, stbuf, actime_str,
+ modtime_str);
+ }
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_fsetattr_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsetattr,
+ fd, stbuf, valid);
+
+ return 0;
+}
+
+
+int
+uidmap_truncate(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ off_t offset)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s, ino=%"PRIu64"},
offset=%"PRId64")",
+ frame->root->unique, loc->path, loc->inode->ino, offset);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_truncate_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->truncate,
+ loc, offset);
+
+ return 0;
+}
+
+
+int
+uidmap_open(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ int32_t flags, fd_t *fd, int32_t wbflags)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s, ino=%"PRIu64"},
flags=%d, "
+ "fd=%p, wbflags=%d)",
+ frame->root->unique, loc->path, loc->inode->ino, flags,
+ fd, wbflags);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_open_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->open,
+ loc, flags, fd, wbflags);
+ return 0;
+}
+
+
+int
+uidmap_create(call_frame_t *frame, xlator_t *this, loc_t *loc,
+ int32_t flags, mode_t mode, fd_t *fd, dict_t *params)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s, ino=%"PRIu64"},
flags=0%o mode=0%o)",
+ frame->root->unique, loc->path, loc->inode->ino, flags,
mode);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ gf_log(this->name, GF_LOG_NORMAL, "create uid: %u, gid: %u",
+ frame->root->uid, frame->root->gid);
+
+ STACK_WIND(frame, uidmap_create_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->create,
+ loc, flags, mode, fd, params);
+ return 0;
+}
+
+
+int
+uidmap_readv(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ size_t size, off_t offset)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (*fd=%p, size=%"GF_PRI_SIZET",
offset=%"PRId64")",
+ frame->root->unique, fd, size, offset);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_readv_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readv,
+ fd, size, offset);
+ return 0;
+}
+
+
+int
+uidmap_writev(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iovec *vector, int32_t count,
+ off_t offset, struct iobref *iobref)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (*fd=%p, *vector=%p, count=%d,
offset=%"PRId64")",
+ frame->root->unique, fd, vector, count, offset);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_writev_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->writev,
+ fd, vector, count, offset, iobref);
+ return 0;
+}
+
+
+int
+uidmap_statfs(call_frame_t *frame, xlator_t *this, loc_t *loc)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s,
ino=%"PRIu64"})",
+ frame->root->unique, loc->path,
+ ((loc->inode)? loc->inode->ino : 0));
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_statfs_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->statfs,
+ loc);
+ return 0;
+}
+
+
+int
+uidmap_flush(call_frame_t *frame, xlator_t *this, fd_t *fd)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (*fd=%p)", frame->root->unique,
fd);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_flush_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->flush,
+ fd);
+ return 0;
+}
+
+
+int
+uidmap_fsync(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (flags=%d, *fd=%p)",
frame->root->unique, flags, fd);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_fsync_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsync,
+ fd, flags);
+ return 0;
+}
+
+
+int
+uidmap_setxattr(call_frame_t *frame, xlator_t *this,
+ loc_t *loc, dict_t *dict, int32_t flags)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s, ino=%"PRIu64"},
dict=%p, flags=%d)",
+ frame->root->unique, loc->path,
+ ((loc->inode)? loc->inode->ino : 0), dict, flags);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_setxattr_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->setxattr,
+ loc, dict, flags);
+ return 0;
+}
+
+
+int
+uidmap_getxattr(call_frame_t *frame, xlator_t *this,
+ loc_t *loc, const char *name)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s, ino=%"PRIu64"}),
name=%s",
+ frame->root->unique, loc->path,
+ ((loc->inode)? loc->inode->ino : 0), name);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_getxattr_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->getxattr,
+ loc, name);
+ return 0;
+}
+
+
+int
+uidmap_removexattr(call_frame_t *frame, xlator_t *this,
+ loc_t *loc, const char *name)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (loc {path=%s, ino=%"PRIu64"},
name=%s)",
+ frame->root->unique, loc->path,
+ ((loc->inode)? loc->inode->ino : 0), name);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_removexattr_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->removexattr,
+ loc, name);
+
+ return 0;
+}
+
+
+int
+uidmap_opendir(call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64":( loc {path=%s, ino=%"PRIu64"},
fd=%p)",
+ frame->root->unique, loc->path, loc->inode->ino, fd);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_opendir_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->opendir,
+ loc, fd);
+ return 0;
+}
+
+int
+uidmap_readdirp(call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t offset)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (fd=%p, size=%"GF_PRI_SIZET",
offset=%"PRId64")",
+ frame->root->unique, fd, size, offset);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_readdirp_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readdirp,
+ fd, size, offset);
+
+ return 0;
+}
+
+
+int
+uidmap_readdir(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ size_t size, off_t offset)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (fd=%p, size=%"GF_PRI_SIZET",
offset=%"PRId64")",
+ frame->root->unique, fd, size, offset);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_readdir_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->readdir,
+ fd, size, offset);
+
+ return 0;
+}
+
+
+int
+uidmap_fsyncdir(call_frame_t *frame, xlator_t *this,
+ fd_t *fd, int32_t datasync)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (datasync=%d, *fd=%p)",
+ frame->root->unique, datasync, fd);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_fsyncdir_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fsyncdir,
+ fd, datasync);
+ return 0;
+}
+
+
+int
+uidmap_access(call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (*loc {path=%s, ino=%"PRIu64"},
mask=0%o)",
+ frame->root->unique, loc->path,
+ ((loc->inode)? loc->inode->ino : 0), mask);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_access_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->access,
+ loc, mask);
+ return 0;
+}
+
+
+int
+uidmap_ftruncate(call_frame_t *frame, xlator_t *this,
+ fd_t *fd, off_t offset)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (offset=%"PRId64", *fd=%p)",
+ frame->root->unique, offset, fd);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_ftruncate_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->ftruncate,
+ fd, offset);
+
+ return 0;
+}
+
+
+int
+uidmap_fstat(call_frame_t *frame, xlator_t *this, fd_t *fd)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (*fd=%p)", frame->root->unique,
fd);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_fstat_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->fstat,
+ fd);
+ return 0;
+}
+
+
+int
+uidmap_lk(call_frame_t *frame, xlator_t *this, fd_t *fd,
+ int32_t cmd, struct gf_flock *lock)
+{
+ gf_log(this->name, GF_LOG_NORMAL,
+ "%"PRId64": (*fd=%p, cmd=%d, lock {l_type=%d, l_whence=%d,
"
+ "l_start=%"PRId64", l_len=%"PRId64",
l_pid=%u})",
+ frame->root->unique, fd, cmd, lock->l_type, lock->l_whence,
+ lock->l_start, lock->l_len, lock->l_pid);
+
+ if ((*uidmap_map)(frame->root, this) == -1)
+ return -1;
+
+ STACK_WIND(frame, uidmap_lk_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->lk,
+ fd, cmd, lock);
+ return 0;
+}
+
+
+int32_t
+init(xlator_t *this)
+{
+ char *uid_range = NULL, *gid_range = NULL;
+ char *plugin = NULL;
+ void *handle = NULL;
+ char *root_squash = NULL;
+ char *tenant_override = NULL;
+ init_fn plugin_init = NULL;
+
+ if (!this)
+ return -1;
+
+ gf_log_set_loglevel(GF_LOG_NORMAL);
+
+ if (!this->children || this->children->next) {
+ gf_log(this->name, GF_LOG_ERROR,
+ "uidmap translator requires one subvolume");
+ return -1;
+ }
+ if (!this->parents) {
+ gf_log(this->name, GF_LOG_WARNING,
+ "dangling volume. check volfile ");
+ }
+
+ uid_range = data_to_str(dict_get(this->options, "uid-range"));
+ if (uid_range != NULL && *uid_range != 0) {
+ uid_t low, hi;
+ if (sscanf(uid_range, "%u-%u", &low, &hi) == 2) {
+ uidmap_low_uid = low; uidmap_hi_uid = hi;
+ uidmap_mapping.im_uid_low = uidmap_mapping.im_uid_next = low;
+ uidmap_mapping.im_uid_high = hi;
+ } else {
+ gf_log(this->name, GF_LOG_ERROR,
+ "invalid uid-range in config");
+ }
+ }
+
+ gid_range = data_to_str(dict_get(this->options, "gid-range"));
+ if (gid_range != NULL && *gid_range != 0) {
+ gid_t low, hi;
+ if (sscanf(gid_range, "%u-%u", &low, &hi) == 2) {
+ uidmap_low_gid = low; uidmap_hi_gid = hi;
+ uidmap_mapping.im_gid_low = uidmap_mapping.im_gid_next = low;
+ uidmap_mapping.im_gid_high = hi;
+ } else {
+ gf_log(this->name, GF_LOG_ERROR,
+ "invalid gid-range in config");
+ }
+ }
+
+ root_squash = data_to_str(dict_get(this->options, "root-squash"));
+ if (root_squash != NULL && *root_squash != 0) {
+ char* ptr = root_squash;
+ for (; *ptr != 0; ptr++)
+ *ptr = tolower(*ptr);
+ if (strcmp(root_squash, "no") == 0)
+ uidmap_root_squash = 0;
+ }
+
+ tenant_override = data_to_str(dict_get(this->options,
"tenant-override"));
+ if (tenant_override != NULL) {
+ uidmap_tenant_override = strdup(tenant_override);
+ }
+
+ plugin = data_to_str(dict_get(this->options, "uidmap-plugin"));
+
+ if (plugin != NULL && *plugin != 0) {
+ gf_log(this->name, GF_LOG_NORMAL, "loading: %s", plugin);
+ handle = dlopen(plugin, RTLD_NOW|RTLD_NODELETE);
+ if (handle) {
+ do {
+ uidmap_map = (map_fn) dlsym(handle, "map");
+ if (uidmap_map == NULL) {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "plugin missing map: %s",
dlerror());
+ break;
+ }
+
+ uidmap_revmap = (revmap_fn) dlsym(handle,
"revmap");
+ if (uidmap_revmap == NULL) {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "plugin missing revmap: %s",
dlerror());
+ break;
+ }
+
+ uidmap_plugin_fini = (fini_fn) dlsym(handle,
"fini");
+ if (uidmap_plugin_fini == NULL) {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "plugin missing fini: %s",
dlerror());
+ break;
+ }
+
+ plugin_init = (init_fn) dlsym(handle, "init");
+ if (plugin_init == NULL) {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "plugin missing init: %s",
dlerror());
+ } else {
+ if ((*plugin_init)(this, uidmap_tenant_override,
+ uidmap_low_uid, uidmap_hi_uid,
+ uidmap_low_gid, uidmap_hi_gid) != 0) {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "plugin init error");
+ }
+ }
+ } while (0);
+
+ if (dlclose(handle)) {
+ gf_log(this->name, GF_LOG_NORMAL,
+ "dlclose plugin: %s", dlerror());
+ }
+ }
+ }
+ if (uidmap_map == NULL) {
+ if (uidmap_deserialize_default(this->name) == -1)
+ return -1;
+ uidmap_map = uidmap_map_default;
+ uidmap_revmap = uidmap_revmap_default;
+ }
+
+ return 0;
+}
+
+void
+fini(xlator_t *this)
+{
+ if (!this)
+ return;
+
+ if (uidmap_plugin_fini)
+ uidmap_plugin_fini(this);
- GF_FREE(priv->db_path);
- FREE (priv);
+ gf_log(this->name, GF_LOG_NORMAL, "uidmap translator unloaded");
+ return;
}
struct xlator_fops fops = {
- .open = uidmap_open,
+ .stat = uidmap_stat,
+ .readlink = uidmap_readlink,
+ .mknod = uidmap_mknod,
+ .mkdir = uidmap_mkdir,
+ .unlink = uidmap_unlink,
+ .rmdir = uidmap_rmdir,
+ .symlink = uidmap_symlink,
+ .rename = uidmap_rename,
+ .link = uidmap_link,
+ .truncate = uidmap_truncate,
+ .open = uidmap_open,
+ .readv = uidmap_readv,
+ .writev = uidmap_writev,
+ .statfs = uidmap_statfs,
+ .flush = uidmap_flush,
+ .fsync = uidmap_fsync,
+ .setxattr = uidmap_setxattr,
+ .getxattr = uidmap_getxattr,
+ .removexattr = uidmap_removexattr,
+ .opendir = uidmap_opendir,
+ .readdir = uidmap_readdir,
+ .readdirp = uidmap_readdirp,
+ .fsyncdir = uidmap_fsyncdir,
+ .access = uidmap_access,
+ .ftruncate = uidmap_ftruncate,
+ .fstat = uidmap_fstat,
+ .create = uidmap_create,
+ .lk = uidmap_lk,
+ .inodelk = uidmap_inodelk,
+ .finodelk = uidmap_finodelk,
+ .entrylk = uidmap_entrylk,
+ .lookup = uidmap_lookup,
+ .xattrop = uidmap_xattrop,
+ .fxattrop = uidmap_fxattrop,
+ .setattr = uidmap_setattr,
+ .fsetattr = uidmap_fsetattr,
};
struct xlator_cbks cbks = {
};
struct volume_options options[] = {
- { .key = {"database"},
- .type = GF_OPTION_TYPE_PATH,
- .description = { "SQLite3 database" }
- },
- { .key = {"tenant"},
- .type = GF_OPTION_TYPE_INT,
- .description = { "Tenant ID" }
- },
+ { .key = {"uidmap-plugin", "plugin"},
+ .type = GF_OPTION_TYPE_PATH,
+ },
+ { .key = {"root-squash"},
+ .type = GF_OPTION_TYPE_STR,
+ .value = { "yes", "no"}
+ },
+ { .key = {"tenant-override", "override"},
+ .type = GF_OPTION_TYPE_STR
+ },
+ { .key = {"uid-range"},
+ .type = GF_OPTION_TYPE_STR,
+ },
+ { .key = {"gid-range"},
+ .type = GF_OPTION_TYPE_STR,
+ },
+ { .key = {NULL} },
};
diff --git a/xlators/features/uidmap/src/uidmap.h b/xlators/features/uidmap/src/uidmap.h
index 861f3b0..864bd5e 100644
--- a/xlators/features/uidmap/src/uidmap.h
+++ b/xlators/features/uidmap/src/uidmap.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011 Red Hat, Inc.
+ * Copyright © 2011 Red Hat, Inc.
*
* This file is part of CloudFS.
*
@@ -17,18 +17,15 @@
* along with CloudFS. If not, see <
http://www.gnu.org/licenses/>.
*/
-
#ifndef __UIDMAP_H__
#define __UIDMAP_H__
-#ifndef _CONFIG_H
-#define _CONFIG_H
-#include "config.h"
-#endif
+#include <sys/types.h>
-typedef struct {
- char *db_path;
- uid_t tenant;
-} uidmap_private_t;
+typedef int (* map_fn)(struct _call_stack_t *, struct _xlator *);
+typedef void (* revmap_fn)(struct _call_stack_t *, uid_t *, gid_t *);
+typedef int32_t (* init_fn)(struct _xlator *, char *, uid_t, uid_t, gid_t, gid_t);
+typedef void (* fini_fn)(struct _xlator *);
#endif /* __UIDMAP_H__ */
+