summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2010-06-21 07:00:04 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-06-21 20:21:10 -0700
commitfdd20492638fe98a62b5e6d5e82f18cf4799fd1a (patch)
tree98082d7bfdc66157f40666f2070d3a45b582327a /xlators
parentb9b8734a9496ccf5f8ed5527dc7714930a59948b (diff)
rpc protocol
Signed-off-by: Amar Tumballi <amar@gluster.com> Signed-off-by: Raghavendra G <raghavendra@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 875 (Implement a new protocol to provide proper backward/forward compatibility) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=875
Diffstat (limited to 'xlators')
-rw-r--r--xlators/protocol/Makefile.am4
-rw-r--r--xlators/protocol/auth/Makefile.am2
-rw-r--r--xlators/protocol/auth/addr/Makefile.am2
-rw-r--r--xlators/protocol/auth/addr/src/Makefile.am2
-rw-r--r--xlators/protocol/auth/login/Makefile.am2
-rw-r--r--xlators/protocol/auth/login/src/Makefile.am2
-rw-r--r--xlators/protocol/client/Makefile.am1
-rw-r--r--xlators/protocol/client/src/Makefile.am16
-rw-r--r--xlators/protocol/client/src/client-handshake.c738
-rw-r--r--xlators/protocol/client/src/client-helpers.c109
-rw-r--r--xlators/protocol/client/src/client-mem-types.h32
-rw-r--r--xlators/protocol/client/src/client.c1791
-rw-r--r--xlators/protocol/client/src/client.h125
-rw-r--r--xlators/protocol/client/src/client3_1-fops.c4662
-rw-r--r--xlators/protocol/lib/Makefile.am2
-rw-r--r--xlators/protocol/lib/src/Makefile.am11
-rw-r--r--xlators/protocol/lib/src/authenticate.c40
-rw-r--r--xlators/protocol/lib/src/authenticate.h6
-rw-r--r--xlators/protocol/lib/src/glusterfs-xdr.c1847
-rw-r--r--xlators/protocol/lib/src/glusterfs-xdr.h1337
-rw-r--r--xlators/protocol/lib/src/glusterfs3.x755
-rw-r--r--xlators/protocol/lib/src/msg-xdr.c1264
-rw-r--r--xlators/protocol/lib/src/msg-xdr.h536
-rw-r--r--xlators/protocol/lib/src/protocol-common.c109
-rw-r--r--xlators/protocol/lib/src/protocol-common.h104
-rw-r--r--xlators/protocol/rpc/Makefile.am1
-rw-r--r--xlators/protocol/rpc/rpc-lib/Makefile.am1
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/Makefile.am15
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/auth-glusterfs.c112
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/auth-null.c70
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/auth-unix.c90
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/rpc-clnt.c1281
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/rpc-clnt.h174
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/rpc-transport.c1300
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/rpc-transport.h287
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/rpcsvc-auth.c409
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/rpcsvc-common.h83
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/rpcsvc.c2010
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/rpcsvc.h584
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/xdr-common.h48
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/xdr-rpc.c189
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/xdr-rpc.h74
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/xdr-rpcclnt.c131
-rw-r--r--xlators/protocol/rpc/rpc-lib/src/xdr-rpcclnt.h51
-rw-r--r--xlators/protocol/rpc/rpc-transport/Makefile.am1
-rw-r--r--xlators/protocol/rpc/rpc-transport/socket/Makefile.am1
-rw-r--r--xlators/protocol/rpc/rpc-transport/socket/src/Makefile.am15
-rw-r--r--xlators/protocol/rpc/rpc-transport/socket/src/name.c737
-rw-r--r--xlators/protocol/rpc/rpc-transport/socket/src/name.h44
-rw-r--r--xlators/protocol/rpc/rpc-transport/socket/src/socket.c2307
-rw-r--r--xlators/protocol/rpc/rpc-transport/socket/src/socket.h190
-rw-r--r--xlators/protocol/server/Makefile.am1
-rw-r--r--xlators/protocol/server/src/Makefile.am22
-rw-r--r--xlators/protocol/server/src/server-handshake.c689
-rw-r--r--xlators/protocol/server/src/server-helpers.c1392
-rw-r--r--xlators/protocol/server/src/server-helpers.h89
-rw-r--r--xlators/protocol/server/src/server-mem-types.h37
-rw-r--r--xlators/protocol/server/src/server-resolve.c655
-rw-r--r--xlators/protocol/server/src/server.c687
-rw-r--r--xlators/protocol/server/src/server.h203
-rw-r--r--xlators/protocol/server/src/server3_1-fops.c4839
61 files changed, 32275 insertions, 43 deletions
diff --git a/xlators/protocol/Makefile.am b/xlators/protocol/Makefile.am
index 0e1eca0..b38506d 100644
--- a/xlators/protocol/Makefile.am
+++ b/xlators/protocol/Makefile.am
@@ -1,3 +1 @@
-SUBDIRS = lib auth legacy
-
-CLEANFILES =
+SUBDIRS = lib auth legacy rpc client server
diff --git a/xlators/protocol/auth/Makefile.am b/xlators/protocol/auth/Makefile.am
index 6bd54ee..e9e0ba9 100644
--- a/xlators/protocol/auth/Makefile.am
+++ b/xlators/protocol/auth/Makefile.am
@@ -1,3 +1 @@
SUBDIRS = addr login
-
-CLEANFILES =
diff --git a/xlators/protocol/auth/addr/Makefile.am b/xlators/protocol/auth/addr/Makefile.am
index d471a3f..af437a6 100644
--- a/xlators/protocol/auth/addr/Makefile.am
+++ b/xlators/protocol/auth/addr/Makefile.am
@@ -1,3 +1 @@
SUBDIRS = src
-
-CLEANFILES =
diff --git a/xlators/protocol/auth/addr/src/Makefile.am b/xlators/protocol/auth/addr/src/Makefile.am
index 2c94c94..ebf20b3 100644
--- a/xlators/protocol/auth/addr/src/Makefile.am
+++ b/xlators/protocol/auth/addr/src/Makefile.am
@@ -10,5 +10,3 @@ addr_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \
AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\
-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \
-I$(top_srcdir)/xlators/protocol/lib/src
-
-CLEANFILES =
diff --git a/xlators/protocol/auth/login/Makefile.am b/xlators/protocol/auth/login/Makefile.am
index d471a3f..af437a6 100644
--- a/xlators/protocol/auth/login/Makefile.am
+++ b/xlators/protocol/auth/login/Makefile.am
@@ -1,3 +1 @@
SUBDIRS = src
-
-CLEANFILES =
diff --git a/xlators/protocol/auth/login/src/Makefile.am b/xlators/protocol/auth/login/src/Makefile.am
index ef99a96..b3b625b 100644
--- a/xlators/protocol/auth/login/src/Makefile.am
+++ b/xlators/protocol/auth/login/src/Makefile.am
@@ -11,5 +11,3 @@ login_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \
AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\
-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \
-I$(top_srcdir)/xlators/protocol/lib/src
-
-CLEANFILES =
diff --git a/xlators/protocol/client/Makefile.am b/xlators/protocol/client/Makefile.am
new file mode 100644
index 0000000..af437a6
--- /dev/null
+++ b/xlators/protocol/client/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = src
diff --git a/xlators/protocol/client/src/Makefile.am b/xlators/protocol/client/src/Makefile.am
new file mode 100644
index 0000000..4028146
--- /dev/null
+++ b/xlators/protocol/client/src/Makefile.am
@@ -0,0 +1,16 @@
+
+xlator_LTLIBRARIES = client.la
+xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/alpha/protocol
+
+client_la_LDFLAGS = -module -avoidversion
+
+client_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \
+ $(top_builddir)/xlators/protocol/rpc/rpc-lib/src/libgfrpc.la \
+ $(top_builddir)/xlators/protocol/lib/src/libgfproto1.la
+
+client_la_SOURCES = client.c client-helpers.c client3_1-fops.c client-handshake.c
+noinst_HEADERS = client.h client-mem-types.h
+
+AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS) \
+ -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \
+ -I$(top_srcdir)/xlators/protocol/lib/src -I$(top_srcdir)/xlators/protocol/rpc/rpc-lib/src/
diff --git a/xlators/protocol/client/src/client-handshake.c b/xlators/protocol/client/src/client-handshake.c
new file mode 100644
index 0000000..79cabd1
--- /dev/null
+++ b/xlators/protocol/client/src/client-handshake.c
@@ -0,0 +1,738 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include "client.h"
+#include "xlator.h"
+#include "defaults.h"
+#include "glusterfs.h"
+#include "msg-xdr.h"
+#include "statedump.h"
+#include "compat-errno.h"
+
+extern rpc_clnt_prog_t clnt3_1_fop_prog;
+extern rpc_clnt_prog_t clnt3_1_mgmt_prog;
+
+/* Handshake */
+
+void
+rpc_client_ping_timer_expired (void *data)
+{
+ rpc_transport_t *trans = NULL;
+ rpc_clnt_connection_t *conn = NULL;
+ int disconnect = 0;
+ int transport_activity = 0;
+ struct timeval timeout = {0, };
+ struct timeval current = {0, };
+ struct rpc_clnt *clnt = NULL;
+ xlator_t *this = NULL;
+ clnt_conf_t *conf = NULL;
+
+ if (!data) {
+ goto out;
+ }
+
+ this = data;
+ conf = this->private;
+
+ conn = &conf->rpc->conn;
+ trans = conn->trans;
+
+ if (!clnt || !trans) {
+ goto out;
+ }
+
+ pthread_mutex_lock (&conn->lock);
+ {
+ if (conn->ping_timer)
+ gf_timer_call_cancel (this->ctx,
+ conn->ping_timer);
+ gettimeofday (&current, NULL);
+
+ if (((current.tv_sec - conn->last_received.tv_sec) <
+ conf->opt.ping_timeout)
+ || ((current.tv_sec - conn->last_sent.tv_sec) <
+ conf->opt.ping_timeout)) {
+ transport_activity = 1;
+ }
+
+ if (transport_activity) {
+ gf_log (trans->name, GF_LOG_TRACE,
+ "ping timer expired but transport activity "
+ "detected - not bailing transport");
+ timeout.tv_sec = conf->opt.ping_timeout;
+ timeout.tv_usec = 0;
+
+ conn->ping_timer =
+ gf_timer_call_after (this->ctx, timeout,
+ rpc_client_ping_timer_expired,
+ (void *) this);
+ if (conn->ping_timer == NULL)
+ gf_log (trans->name, GF_LOG_DEBUG,
+ "unable to setup timer");
+
+ } else {
+ conn->ping_started = 0;
+ conn->ping_timer = NULL;
+ disconnect = 1;
+ }
+ }
+ pthread_mutex_unlock (&conn->lock);
+
+ if (disconnect) {
+ gf_log (trans->name, GF_LOG_ERROR,
+ "Server %s has not responded in the last %d "
+ "seconds, disconnecting.",
+ conn->trans->peerinfo.identifier,
+ conf->opt.ping_timeout);
+
+ rpc_transport_disconnect (conn->trans);
+ }
+
+out:
+ return;
+}
+
+
+void
+client_start_ping (void *data)
+{
+ xlator_t *this = NULL;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_connection_t *conn = NULL;
+ int32_t ret = -1;
+ struct timeval timeout = {0, };
+ call_frame_t *frame = NULL;
+ int frame_count = 0;
+ rpc_transport_t *trans = NULL;
+
+ this = data;
+ conf = this->private;
+
+ conn = &conf->rpc->conn;
+ trans = conn->trans;
+
+ if (conf->opt.ping_timeout == 0)
+ return;
+
+ pthread_mutex_lock (&conn->lock);
+ {
+ if (conn->ping_timer)
+ gf_timer_call_cancel (this->ctx, conn->ping_timer);
+
+ conn->ping_timer = NULL;
+ conn->ping_started = 0;
+
+ if (conn->saved_frames)
+ /* treat the case where conn->saved_frames is NULL
+ as no pending frames */
+ frame_count = conn->saved_frames->count;
+
+ if ((frame_count == 0) || !conn->connected) {
+ /* using goto looked ugly here,
+ * hence getting out this way */
+ /* unlock */
+ pthread_mutex_unlock (&conn->lock);
+ return;
+ }
+
+ if (frame_count < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "saved_frames->count is %"PRId64,
+ conn->saved_frames->count);
+ conn->saved_frames->count = 0;
+ }
+
+ timeout.tv_sec = conf->opt.ping_timeout;
+ timeout.tv_usec = 0;
+
+ conn->ping_timer =
+ gf_timer_call_after (this->ctx, timeout,
+ rpc_client_ping_timer_expired,
+ (void *) this);
+
+ if (conn->ping_timer == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "unable to setup timer");
+ } else {
+ conn->ping_started = 1;
+ }
+ }
+ pthread_mutex_unlock (&conn->lock);
+
+ frame = create_frame (this, this->ctx->pool);
+ if (!frame)
+ goto fail;
+
+ ret = client_submit_request (this, NULL, frame, conf->handshake,
+ GF_HNDSK_PING, NULL, NULL);
+
+ return;
+fail:
+
+ if (frame) {
+ STACK_DESTROY (frame->root);
+ }
+
+ return;
+}
+
+
+int
+client_ping_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ xlator_t *this = NULL;
+ rpc_clnt_connection_t *conn = NULL;
+ struct timeval timeout = {0, };
+ call_frame_t *frame = NULL;
+ clnt_conf_t *conf = NULL;
+
+ frame = myframe;
+
+ this = frame->this;
+ conf = this->private;
+ conn = &conf->rpc->conn;
+
+ if (req->rpc_status == -1) {
+ /* timer expired and transport bailed out */
+ gf_log (this->name, GF_LOG_DEBUG, "timer must have expired");
+ goto out;
+ }
+
+ pthread_mutex_lock (&conn->lock);
+ {
+ timeout.tv_sec = conf->opt.ping_timeout;
+ timeout.tv_usec = 0;
+
+ gf_timer_call_cancel (this->ctx,
+ conn->ping_timer);
+
+ conn->ping_timer =
+ gf_timer_call_after (this->ctx, timeout,
+ client_start_ping, (void *)this);
+
+ if (conn->ping_timer == NULL)
+ gf_log (this->name, GF_LOG_DEBUG,
+ "gf_timer_call_after() returned NULL");
+ }
+ pthread_mutex_unlock (&conn->lock);
+out:
+ STACK_DESTROY (frame->root);
+ return 0;
+}
+
+
+int
+client_getspec_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe)
+{
+ gf_getspec_rsp rsp = {0,};
+ call_frame_t *frame = NULL;
+ clnt_conf_t *conf = NULL;
+ int ret = 0;
+ char spec[(32*1024)] = {0,};
+
+ frame = myframe;
+ conf = frame->this->private;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ rsp.spec = spec;
+ ret = xdr_to_dump_version_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 == rsp.op_ret) {
+ gf_log (frame->this->name, GF_LOG_ERROR,
+ "failed to get the 'volume file' from server");
+ goto out;
+ }
+
+out:
+ /* no _STRICT for mops */
+ STACK_UNWIND_STRICT (getspec, frame, rsp.op_ret, rsp.op_errno, rsp.spec);
+ return 0;
+}
+
+
+int
+client_post_handshake (call_frame_t *frame, xlator_t *this)
+{
+ clnt_conf_t *conf = NULL;
+ clnt_fd_ctx_t *tmp = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ xlator_list_t *parent = NULL;
+ struct list_head reopen_head;
+
+ if (!this || !this->private)
+ goto out;
+
+ conf = this->private;
+ INIT_LIST_HEAD (&reopen_head);
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ list_for_each_entry_safe (fdctx, tmp, &conf->saved_fds,
+ sfd_pos) {
+ if (fdctx->remote_fd != -1)
+ continue;
+
+ list_del_init (&fdctx->sfd_pos);
+ list_add_tail (&fdctx->sfd_pos, &reopen_head);
+ }
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ list_for_each_entry_safe (fdctx, tmp, &reopen_head, sfd_pos) {
+ list_del_init (&fdctx->sfd_pos);
+
+ if (fdctx->is_dir)
+ protocol_client_reopendir (this, fdctx);
+ else
+ protocol_client_reopen (this, fdctx);
+ }
+
+ parent = this->parents;
+
+ while (parent) {
+ xlator_notify (parent->xlator, GF_EVENT_CHILD_UP,
+ this);
+ parent = parent->next;
+ }
+
+out:
+ return 0;
+}
+
+int
+client_setvolume_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe)
+{
+ call_frame_t *frame = NULL;
+ clnt_conf_t *conf = NULL;
+ xlator_t *this = NULL;
+ dict_t *reply = NULL;
+ xlator_list_t *parent = NULL;
+ char *process_uuid = NULL;
+ char *remote_error = NULL;
+ char *remote_subvol = NULL;
+ rpc_transport_t *peer_trans = NULL;
+ gf_setvolume_rsp rsp = {0,};
+ uint64_t peertrans_int = 0;
+ int ret = 0;
+ int op_ret = 0;
+ int op_errno = 0;
+
+ frame = myframe;
+ this = frame->this;
+ conf = this->private;
+
+ if (-1 == req->rpc_status) {
+ op_ret = -1;
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ ret = xdr_to_setvolume_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ op_errno = EINVAL;
+ op_ret = -1;
+ goto out;
+ }
+ op_ret = rsp.op_ret;
+ op_errno = gf_error_to_errno (rsp.op_errno);
+ if (-1 == rsp.op_ret) {
+ gf_log (frame->this->name, GF_LOG_WARNING,
+ "failed to set the volume");
+ }
+
+ reply = dict_new ();
+ if (!reply)
+ goto out;
+
+ if (rsp.dict.dict_len) {
+ ret = dict_unserialize (rsp.dict.dict_val,
+ rsp.dict.dict_len, &reply);
+ if (ret < 0) {
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "failed to unserialize buffer to dict");
+ goto out;
+ }
+ }
+
+ ret = dict_get_str (reply, "ERROR", &remote_error);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "failed to get ERROR string from reply dict");
+ }
+
+ ret = dict_get_str (reply, "process-uuid", &process_uuid);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "failed to get 'process-uuid' from reply dict");
+ }
+
+ if (op_ret < 0) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "SETVOLUME on remote-host failed: %s",
+ remote_error ? remote_error : strerror (op_errno));
+ errno = op_errno;
+ if (op_errno == ESTALE) {
+ parent = this->parents;
+ while (parent) {
+ xlator_notify (parent->xlator,
+ GF_EVENT_VOLFILE_MODIFIED,
+ this);
+ parent = parent->next;
+ }
+ }
+ goto out;
+ }
+ ret = dict_get_str (this->options, "remote-subvolume",
+ &remote_subvol);
+ if (!remote_subvol)
+ goto out;
+
+ if (process_uuid &&
+ !strcmp (this->ctx->process_uuid, process_uuid)) {
+ ret = dict_get_uint64 (reply, "transport-ptr",
+ &peertrans_int);
+
+ peer_trans = (void *) (long) (peertrans_int);
+
+ gf_log (this->name, GF_LOG_WARNING,
+ "attaching to the local volume '%s'",
+ remote_subvol);
+
+ if (req->conn) {
+ /* TODO: Some issues with this logic at present */
+ //rpc_transport_setpeer (req->conn->trans, peer_trans);
+ }
+ }
+
+ gf_log (this->name, GF_LOG_NORMAL,
+ "Connected to %s, attached to remote volume '%s'.",
+ conf->rpc->conn.trans->peerinfo.identifier,
+ remote_subvol);
+
+ rpc_clnt_set_connected (&conf->rpc->conn);
+
+ op_ret = 0;
+ conf->connecting = 0;
+
+ /* TODO: more to test */
+ client_post_handshake (frame, frame->this);
+
+out:
+
+ if (-1 == op_ret) {
+ /* Let the connection/re-connection happen in
+ * background, for now, don't hang here,
+ * tell the parents that i am all ok..
+ */
+ parent = this->parents;
+ while (parent) {
+ xlator_notify (parent->xlator,
+ GF_EVENT_CHILD_CONNECTING, this);
+ parent = parent->next;
+ }
+
+ conf->connecting= 1;
+ }
+
+ if (rsp.dict.dict_val)
+ free (rsp.dict.dict_val);
+
+ STACK_DESTROY (frame->root);
+
+ if (reply)
+ dict_unref (reply);
+
+ return 0;
+}
+
+int
+client_setvolume (xlator_t *this, struct rpc_clnt *rpc)
+{
+ int ret = 0;
+ gf_setvolume_req req = {0,};
+ call_frame_t *fr = NULL;
+ char *process_uuid_xl = NULL;
+ clnt_conf_t *conf = NULL;
+ dict_t *options = NULL;
+
+ options = this->options;
+ conf = this->private;
+
+ if (conf->fops || !dict_get (options, "fops-version")) {
+ ret = dict_set_int32 (options, "fops-version",
+ conf->fops->prognum);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "failed to set version-fops(%d) in handshake msg",
+ conf->fops->prognum);
+ goto fail;
+ }
+ }
+
+ if (conf->mgmt) {
+ ret = dict_set_int32 (options, "mgmt-version", conf->mgmt->prognum);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "failed to set version-mgmt(%d) in handshake msg",
+ conf->mgmt->prognum);
+ goto fail;
+ }
+ }
+
+ ret = gf_asprintf (&process_uuid_xl, "%s-%s", this->ctx->process_uuid,
+ this->name);
+ if (-1 == ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "asprintf failed while setting process_uuid");
+ goto fail;
+ }
+ ret = dict_set_dynstr (options, "process-uuid", process_uuid_xl);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "failed to set process-uuid(%s) in handshake msg",
+ process_uuid_xl);
+ goto fail;
+ }
+
+ if (this->ctx->cmd_args.volfile_server) {
+ if (this->ctx->cmd_args.volfile_id)
+ ret = dict_set_str (options, "volfile-key",
+ this->ctx->cmd_args.volfile_id);
+ ret = dict_set_uint32 (options, "volfile-checksum",
+ this->graph->volfile_checksum);
+ }
+
+ req.dict.dict_len = dict_serialized_length (options);
+ if (req.dict.dict_len < 0) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "failed to get serialized length of dict");
+ ret = -1;
+ goto fail;
+ }
+ req.dict.dict_val = GF_CALLOC (1, req.dict.dict_len, 0);
+ ret = dict_serialize (options, req.dict.dict_val);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "failed to serialize dictionary");
+ goto fail;
+ }
+
+ fr = create_frame (this, this->ctx->pool);
+ if (!fr)
+ goto fail;
+
+ ret = client_submit_request (this, &req, fr, conf->handshake,
+ GF_HNDSK_SETVOLUME, NULL, xdr_from_setvolume_req);
+
+fail:
+ if (req.dict.dict_val)
+ GF_FREE (req.dict.dict_val);
+
+ return ret;
+}
+
+int
+select_server_supported_programs (xlator_t *this, char *msg)
+{
+ clnt_conf_t *conf = NULL;
+ char *tmp_str = NULL;
+ char *prog_str = NULL;
+ char *dup_str = NULL;
+ char *tmp_str1 = NULL;
+ char *tmp_msg = NULL;
+ char *progname = NULL;
+ char *progver_str = NULL;
+ char *prognum_str = NULL;
+ int ret = -1;
+ int progver = 0;
+ int prognum = 0;
+
+ if (!this || !msg)
+ goto out;
+
+ conf = this->private;
+
+ /* Reply in "Name:Program-Number:Program-Version,..." format */
+ tmp_msg = gf_strdup (msg);
+ prog_str = strtok_r (tmp_msg, ",", &tmp_str);
+ while (prog_str) {
+ dup_str = gf_strdup (prog_str);
+
+ progname = strtok_r (dup_str, ":", &tmp_str1);
+ prognum_str = strtok_r (NULL, ":", &tmp_str1);
+ if (!prognum_str) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "Supported versions not formatted");
+ goto out;
+ }
+ sscanf (prognum_str, "%d", &prognum);
+ progver_str = strtok_r (NULL, ":", &tmp_str1);
+ if (!progver_str) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "Supported versions not formatted");
+ goto out;
+ }
+ sscanf (progver_str, "%d", &progver);
+
+ /* Select 'programs' */
+ if ((clnt3_1_fop_prog.prognum == prognum) &&
+ (clnt3_1_fop_prog.progver == progver)) {
+ conf->fops = &clnt3_1_fop_prog;
+ gf_log (this->name, GF_LOG_INFO,
+ "Using Program %s, Num (%s), Version (%s)",
+ progname, prognum_str, progver_str);
+ ret = 0;
+ }
+ if ((clnt3_1_mgmt_prog.prognum == prognum) &&
+ (clnt3_1_mgmt_prog.progver == progver)) {
+ conf->mgmt = &clnt3_1_mgmt_prog;
+ gf_log (this->name, GF_LOG_INFO,
+ "Using Program %s, Num (%s), Version (%s)",
+ progname, prognum_str, progver_str);
+ ret = 0;
+ }
+
+ prog_str = strtok_r (NULL, ",", &tmp_str);
+ GF_FREE (dup_str);
+ }
+
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "none of the server versions are supported by client");
+ }
+ ret = 0;
+out:
+ if (tmp_msg)
+ GF_FREE (tmp_msg);
+ return ret;
+}
+
+int
+client_dump_version_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe)
+{
+ gf_dump_version_rsp rsp = {0,};
+ call_frame_t *frame = NULL;
+ clnt_conf_t *conf = NULL;
+ int ret = 0;
+
+ frame = myframe;
+ conf = frame->this->private;
+
+ if (-1 == req->rpc_status) {
+ gf_log ("", 1, "some error, retry again later");
+ goto out;
+ }
+
+ ret = xdr_to_dump_version_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ goto out;
+ }
+ if (-1 == rsp.op_ret) {
+ gf_log (frame->this->name, GF_LOG_ERROR,
+ "failed to get the 'versions' from server");
+ goto out;
+ }
+
+ /* Check for the proper version string */
+ /* Reply in "Name:Program-Number:Program-Version,..." format */
+ ret = select_server_supported_programs (frame->this,
+ rsp.msg.msg_val);
+ if (ret) {
+ gf_log (frame->this->name, GF_LOG_ERROR,
+ "Server versions are not present in this "
+ "release (%s)", rsp.msg.msg_val);
+ goto out;
+ }
+
+ client_setvolume (frame->this, conf->rpc);
+
+out:
+ /* don't use GF_FREE, buffer was allocated by libc */
+ if (rsp.msg.msg_val) {
+ free (rsp.msg.msg_val);
+ }
+
+ STACK_DESTROY (frame->root);
+ return ret;
+}
+
+int
+client_handshake (xlator_t *this, struct rpc_clnt *rpc)
+{
+ call_frame_t *frame = NULL;
+ clnt_conf_t *conf = NULL;
+ gf_dump_version_req req = {0,};
+ int ret = 0;
+
+ conf = this->private;
+ if (!conf->handshake)
+ goto out;
+
+ frame = create_frame (this, this->ctx->pool);
+ if (!frame)
+ goto out;
+
+ req.key = "fop-handshake";
+ req.gfs_id = 123456;
+ ret = client_submit_request (this, &req, frame, conf->handshake,
+ GF_HNDSK_DUMP_VERSION,
+ NULL, xdr_from_dump_version_req);
+
+out:
+ return ret;
+}
+
+
+/* */
+/* This table should ideally remain same irrespective of versions */
+static rpc_clnt_procedure_t clnt_handshake_actors[] = {
+ [GF_HNDSK_NULL] = { "NULL", NULL, NULL},
+ [GF_HNDSK_DUMP_VERSION] = { "VERSION", NULL, client_dump_version_cbk},
+ [GF_HNDSK_SETVOLUME] = { "SETVOLUME", NULL, client_setvolume_cbk},
+ [GF_HNDSK_GETSPEC] = { "GETSPEC", NULL, client_getspec_cbk },
+ [GF_HNDSK_PING] = { "PING", NULL, client_ping_cbk },
+};
+
+rpc_clnt_prog_t clnt_handshake_prog = {
+ .progname = "GlusterFS Handshake",
+ .prognum = GLUSTER_HNDSK_PROGRAM,
+ .progver = GLUSTER_HNDSK_VERSION,
+ .actor = clnt_handshake_actors,
+ .numproc = (sizeof (*clnt_handshake_actors) /
+ sizeof (rpc_clnt_procedure_t)),
+};
diff --git a/xlators/protocol/client/src/client-helpers.c b/xlators/protocol/client/src/client-helpers.c
new file mode 100644
index 0000000..ae091ed
--- /dev/null
+++ b/xlators/protocol/client/src/client-helpers.c
@@ -0,0 +1,109 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include "client.h"
+#include "fd.h"
+
+
+clnt_fd_ctx_t *
+this_fd_del_ctx (fd_t *file, xlator_t *this)
+{
+ int dict_ret = -1;
+ uint64_t ctxaddr = 0;
+
+ GF_VALIDATE_OR_GOTO ("client", this, out);
+ GF_VALIDATE_OR_GOTO (this->name, file, out);
+
+ dict_ret = fd_ctx_del (file, this, &ctxaddr);
+
+ if (dict_ret < 0) {
+ ctxaddr = 0;
+ }
+
+out:
+ return (clnt_fd_ctx_t *)(unsigned long)ctxaddr;
+}
+
+
+clnt_fd_ctx_t *
+this_fd_get_ctx (fd_t *file, xlator_t *this)
+{
+ int dict_ret = -1;
+ uint64_t ctxaddr = 0;
+
+ GF_VALIDATE_OR_GOTO ("client", this, out);
+ GF_VALIDATE_OR_GOTO (this->name, file, out);
+
+ dict_ret = fd_ctx_get (file, this, &ctxaddr);
+
+ if (dict_ret < 0) {
+ ctxaddr = 0;
+ }
+
+out:
+ return (clnt_fd_ctx_t *)(unsigned long)ctxaddr;
+}
+
+
+void
+this_fd_set_ctx (fd_t *file, xlator_t *this, loc_t *loc, clnt_fd_ctx_t *ctx)
+{
+ uint64_t oldaddr = 0;
+ int32_t ret = -1;
+
+ GF_VALIDATE_OR_GOTO ("client", this, out);
+ GF_VALIDATE_OR_GOTO (this->name, file, out);
+
+ ret = fd_ctx_get (file, this, &oldaddr);
+ if (ret >= 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "%s (%"PRId64"): trying duplicate remote fd set. ",
+ loc->path, loc->inode->ino);
+ }
+
+ ret = fd_ctx_set (file, this, (uint64_t)(unsigned long)ctx);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "%s (%"PRId64"): failed to set remote fd",
+ loc->path, loc->inode->ino);
+ }
+out:
+ return;
+}
+
+
+int
+client_local_wipe (clnt_local_t *local)
+{
+ if (local) {
+ loc_wipe (&local->loc);
+
+ if (local->fd)
+ fd_unref (local->fd);
+
+ GF_FREE (local);
+ }
+
+ return 0;
+}
diff --git a/xlators/protocol/client/src/client-mem-types.h b/xlators/protocol/client/src/client-mem-types.h
new file mode 100644
index 0000000..5fadfaf
--- /dev/null
+++ b/xlators/protocol/client/src/client-mem-types.h
@@ -0,0 +1,32 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+#ifndef __CLIENT_MEM_TYPES_H__
+#define __CLIENT_MEM_TYPES_H__
+
+#include "mem-types.h"
+
+enum gf_client_mem_types_ {
+ gf_client_mt_clnt_conf_t = gf_common_mt_end + 1,
+ gf_client_mt_clnt_local_t,
+ gf_client_mt_clnt_fdctx_t,
+ gf_client_mt_end,
+};
+#endif /* __CLIENT_MEM_TYPES_H__ */
diff --git a/xlators/protocol/client/src/client.c b/xlators/protocol/client/src/client.c
new file mode 100644
index 0000000..49e88bf
--- /dev/null
+++ b/xlators/protocol/client/src/client.c
@@ -0,0 +1,1791 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include "client.h"
+#include "xlator.h"
+#include "defaults.h"
+#include "glusterfs.h"
+#include "msg-xdr.h"
+#include "statedump.h"
+#include "compat-errno.h"
+
+extern rpc_clnt_prog_t clnt_handshake_prog;
+int
+client_handshake (xlator_t *this, struct rpc_clnt *rpc);
+
+void
+client_start_ping (void *data);
+
+int
+client_submit_request (xlator_t *this, void *req,
+ call_frame_t *frame, rpc_clnt_prog_t *prog, int procnum,
+ struct iobref *iobref, gfs_serialize_t sfunc)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ struct iovec iov = {0, };
+ struct iobuf *iobuf = NULL;
+ int count = 0;
+ char new_iobref = 0, start_ping = 0;
+
+ conf = this->private;
+
+ iobuf = iobuf_get (this->ctx->iobuf_pool);
+ if (!iobuf) {
+ goto out;
+ };
+
+ if (!iobref) {
+ iobref = iobref_new ();
+ if (!iobref) {
+ goto out;
+ }
+
+ new_iobref = 1;
+ }
+
+ iobref_add (iobref, iobuf);
+
+ iov.iov_base = iobuf->ptr;
+ iov.iov_len = 128 * GF_UNIT_KB;
+
+ /* Create the xdr payload */
+ if (req && sfunc) {
+ ret = sfunc (iov, req);
+ if (ret == -1) {
+ goto out;
+ }
+ iov.iov_len = ret;
+ count = 1;
+ }
+ /* Send the msg */
+ ret = rpc_clnt_submit (conf->rpc, prog, procnum, &iov, count, NULL, 0,
+ iobref, frame);
+
+ if (ret == 0) {
+ pthread_mutex_lock (&conf->rpc->conn.lock);
+ {
+ if (!conf->rpc->conn.ping_started) {
+ start_ping = 1;
+ }
+ }
+ pthread_mutex_unlock (&conf->rpc->conn.lock);
+ }
+
+ if (start_ping)
+ client_start_ping ((void *) this);
+
+ ret = 0;
+out:
+ if (new_iobref) {
+ iobref_unref (iobref);
+ }
+
+ iobuf_unref (iobuf);
+
+ return ret;
+}
+
+
+int32_t
+client_forget (xlator_t *this, inode_t *inode)
+{
+ /* Nothing here */
+ return 0;
+}
+
+int32_t
+client_releasedir (xlator_t *this, fd_t *fd)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+ call_frame_t *frame = NULL;
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+
+ proc = &conf->fops->actor[GF_FOP_RELEASEDIR];
+ if (proc->fn) {
+ frame = create_frame (this, this->ctx->pool);
+ if (!frame) {
+ goto out;
+ }
+ ret = proc->fn (frame, this, conf->fops, &args);
+ }
+out:
+ return 0;
+}
+
+int32_t
+client_release (xlator_t *this, fd_t *fd)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+ call_frame_t *frame = NULL;
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ proc = &conf->fops->actor[GF_FOP_RELEASE];
+ if (proc->fn) {
+ frame = create_frame (this, this->ctx->pool);
+ if (!frame) {
+ goto out;
+ }
+ ret = proc->fn (frame, this, conf->fops, &args);
+ }
+out:
+ return 0;
+}
+
+
+int32_t
+client_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc,
+ dict_t *xattr_req)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+ args.dict = xattr_req;
+
+ proc = &conf->fops->actor[GF_FOP_LOOKUP];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ /* think of avoiding a missing frame */
+ if (ret)
+ STACK_UNWIND_STRICT (lookup, frame, -1, ENOTCONN,
+ NULL, NULL, NULL, NULL);
+
+ return 0;
+}
+
+
+int32_t
+client_stat (call_frame_t *frame, xlator_t *this, loc_t *loc)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+
+ proc = &conf->fops->actor[GF_FOP_STAT];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (stat, frame, -1, ENOTCONN, NULL);
+
+
+ return 0;
+}
+
+
+int32_t
+client_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+ args.offset = offset;
+
+ proc = &conf->fops->actor[GF_FOP_TRUNCATE];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (truncate, frame, -1, ENOTCONN, NULL, NULL);
+
+
+ return 0;
+}
+
+
+int32_t
+client_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.offset = offset;
+
+ proc = &conf->fops->actor[GF_FOP_FTRUNCATE];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (ftruncate, frame, -1, ENOTCONN, NULL, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_access (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+ args.mask = mask;
+
+ proc = &conf->fops->actor[GF_FOP_ACCESS];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (access, frame, -1, ENOTCONN);
+
+ return 0;
+}
+
+
+
+
+int32_t
+client_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+ args.size = size;
+
+ proc = &conf->fops->actor[GF_FOP_READLINK];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (readlink, frame, -1, ENOTCONN, NULL, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode,
+ dev_t rdev)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+ args.mode = mode;
+ args.rdev = rdev;
+
+ proc = &conf->fops->actor[GF_FOP_MKNOD];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (mknod, frame, -1, ENOTCONN,
+ NULL, NULL, NULL, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc,
+ mode_t mode)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+ args.mode = mode;
+
+ proc = &conf->fops->actor[GF_FOP_MKDIR];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (mkdir, frame, -1, ENOTCONN,
+ NULL, NULL, NULL, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+
+ proc = &conf->fops->actor[GF_FOP_UNLINK];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (unlink, frame, -1, ENOTCONN,
+ NULL, NULL);
+
+ return 0;
+}
+
+int32_t
+client_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+
+ proc = &conf->fops->actor[GF_FOP_RMDIR];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ /* think of avoiding a missing frame */
+ if (ret)
+ STACK_UNWIND_STRICT (rmdir, frame, -1, ENOTCONN,
+ NULL, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_symlink (call_frame_t *frame, xlator_t *this, const char *linkpath,
+ loc_t *loc)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.linkname = linkpath;
+ args.loc = loc;
+
+ proc = &conf->fops->actor[GF_FOP_SYMLINK];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (symlink, frame, -1, ENOTCONN,
+ NULL, NULL, NULL, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc,
+ loc_t *newloc)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.oldloc = oldloc;
+ args.newloc = newloc;
+ proc = &conf->fops->actor[GF_FOP_RENAME];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (rename, frame, -1, ENOTCONN,
+ NULL, NULL, NULL, NULL, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc,
+ loc_t *newloc)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.oldloc = oldloc;
+ args.newloc = newloc;
+
+ proc = &conf->fops->actor[GF_FOP_LINK];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (link, frame, -1, ENOTCONN,
+ NULL, NULL, NULL, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_create (call_frame_t *frame, xlator_t *this, loc_t *loc,
+ int32_t flags, mode_t mode, fd_t *fd)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+ args.flags = flags;
+ args.mode = mode;
+ args.fd = fd;
+
+ proc = &conf->fops->actor[GF_FOP_CREATE];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (create, frame, -1, ENOTCONN,
+ NULL, NULL, NULL, NULL, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_open (call_frame_t *frame, xlator_t *this, loc_t *loc,
+ int32_t flags, fd_t *fd, int32_t wbflags)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+ args.flags = flags;
+ args.fd = fd;
+ args.wbflags = wbflags;
+
+ proc = &conf->fops->actor[GF_FOP_OPEN];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (open, frame, -1, ENOTCONN, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size,
+ off_t offset)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.size = size;
+ args.offset = offset;
+
+ proc = &conf->fops->actor[GF_FOP_READ];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (readv, frame, -1, ENOTCONN,
+ NULL, 0, NULL, NULL);
+
+ return 0;
+}
+
+
+
+
+int32_t
+client_writev (call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iovec *vector, int32_t count, off_t off,
+ struct iobref *iobref)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.vector = vector;
+ args.count = count;
+ args.offset = off;
+ args.iobref = iobref;
+
+ proc = &conf->fops->actor[GF_FOP_WRITE];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (writev, frame, -1, ENOTCONN, NULL, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_flush (call_frame_t *frame, xlator_t *this, fd_t *fd)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+
+ proc = &conf->fops->actor[GF_FOP_FLUSH];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (flush, frame, -1, ENOTCONN);
+
+ return 0;
+}
+
+
+
+int32_t
+client_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd,
+ int32_t flags)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.flags = flags;
+
+ proc = &conf->fops->actor[GF_FOP_FSYNC];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (fsync, frame, -1, ENOTCONN, NULL, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+
+ proc = &conf->fops->actor[GF_FOP_FSTAT];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (fstat, frame, -1, ENOTCONN, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+ args.fd = fd;
+
+ proc = &conf->fops->actor[GF_FOP_OPENDIR];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (opendir, frame, -1, ENOTCONN, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_fsyncdir (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.flags = flags;
+
+ proc = &conf->fops->actor[GF_FOP_FSYNCDIR];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (fsyncdir, frame, -1, ENOTCONN);
+
+ return 0;
+}
+
+
+
+int32_t
+client_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+
+ proc = &conf->fops->actor[GF_FOP_STATFS];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (statfs, frame, -1, ENOTCONN, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict,
+ int32_t flags)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+ args.dict = dict;
+ args.flags = flags;
+
+ proc = &conf->fops->actor[GF_FOP_SETXATTR];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (setxattr, frame, -1, ENOTCONN);
+
+ return 0;
+}
+
+
+
+int32_t
+client_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
+ dict_t *dict, int32_t flags)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.dict = dict;
+ args.flags = flags;
+
+ proc = &conf->fops->actor[GF_FOP_FSETXATTR];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (fsetxattr, frame, -1, ENOTCONN);
+
+ return 0;
+}
+
+
+
+
+int32_t
+client_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
+ const char *name)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.name = name;
+
+ proc = &conf->fops->actor[GF_FOP_FGETXATTR];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (fgetxattr, frame, -1, ENOTCONN, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
+ const char *name)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.name = name;
+ args.loc = loc;
+
+ proc = &conf->fops->actor[GF_FOP_GETXATTR];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (getxattr, frame, -1, ENOTCONN, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc,
+ gf_xattrop_flags_t flags, dict_t *dict)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+ args.flags = flags;
+ args.dict = dict;
+
+ proc = &conf->fops->actor[GF_FOP_XATTROP];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (xattrop, frame, -1, ENOTCONN, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_fxattrop (call_frame_t *frame, xlator_t *this, fd_t *fd,
+ gf_xattrop_flags_t flags, dict_t *dict)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.flags = flags;
+ args.dict = dict;
+
+ proc = &conf->fops->actor[GF_FOP_FXATTROP];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (fxattrop, frame, -1, ENOTCONN, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
+ const char *name)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.name = name;
+ args.loc = loc;
+
+ proc = &conf->fops->actor[GF_FOP_REMOVEXATTR];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (removexattr, frame, -1, ENOTCONN);
+
+ return 0;
+}
+
+
+int32_t
+client_lk (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd,
+ struct flock *lock)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.cmd = cmd;
+ args.flock = lock;
+
+ proc = &conf->fops->actor[GF_FOP_LK];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (lk, frame, -1, ENOTCONN, NULL);
+
+ return 0;
+}
+
+
+int32_t
+client_inodelk (call_frame_t *frame, xlator_t *this, const char *volume,
+ loc_t *loc, int32_t cmd, struct flock *lock)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+ args.cmd = cmd;
+ args.flock = lock;
+ args.volume = volume;
+
+ proc = &conf->fops->actor[GF_FOP_INODELK];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (inodelk, frame, -1, ENOTCONN);
+
+ return 0;
+}
+
+
+
+int32_t
+client_finodelk (call_frame_t *frame, xlator_t *this, const char *volume,
+ fd_t *fd, int32_t cmd, struct flock *lock)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.cmd = cmd;
+ args.flock = lock;
+ args.volume = volume;
+
+ proc = &conf->fops->actor[GF_FOP_FINODELK];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (finodelk, frame, -1, ENOTCONN);
+
+ return 0;
+}
+
+
+int32_t
+client_entrylk (call_frame_t *frame, xlator_t *this, const char *volume,
+ loc_t *loc, const char *basename, entrylk_cmd cmd,
+ entrylk_type type)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+ args.basename = basename;
+ args.type = type;
+ args.volume = volume;
+ args.cmd_entrylk = cmd;
+
+ proc = &conf->fops->actor[GF_FOP_ENTRYLK];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (entrylk, frame, -1, ENOTCONN);
+
+ return 0;
+}
+
+
+
+int32_t
+client_fentrylk (call_frame_t *frame, xlator_t *this, const char *volume,
+ fd_t *fd, const char *basename, entrylk_cmd cmd,
+ entrylk_type type)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.basename = basename;
+ args.type = type;
+ args.volume = volume;
+ args.cmd_entrylk = cmd;
+
+ proc = &conf->fops->actor[GF_FOP_FENTRYLK];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (fentrylk, frame, -1, ENOTCONN);
+
+ return 0;
+}
+
+
+int32_t
+client_checksum (call_frame_t *frame, xlator_t *this, loc_t *loc,
+ int32_t flag)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+ args.flags = flag;
+
+ proc = &conf->fops->actor[GF_FOP_CHECKSUM];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (checksum, frame, -1, ENOTCONN, NULL, NULL);
+
+ return 0;
+}
+
+
+
+int32_t
+client_rchecksum (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,
+ int32_t len)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.offset = offset;
+ args.len = len;
+
+ proc = &conf->fops->actor[GF_FOP_RCHECKSUM];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (rchecksum, frame, -1, ENOTCONN, 0, NULL);
+
+ return 0;
+}
+
+int32_t
+client_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd,
+ size_t size, off_t off)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.size = size;
+ args.offset = off;
+
+ proc = &conf->fops->actor[GF_FOP_READDIR];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (readdir, frame, -1, ENOTCONN, NULL);
+
+ return 0;
+}
+
+
+int32_t
+client_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd,
+ size_t size, off_t off)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.size = size;
+ args.offset = off;
+
+ proc = &conf->fops->actor[GF_FOP_READDIRP];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (readdirp, frame, -1, ENOTCONN, NULL);
+
+ return 0;
+}
+
+
+int32_t
+client_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc,
+ struct iatt *stbuf, int32_t valid)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.loc = loc;
+ args.stbuf = stbuf;
+ args.valid = valid;
+
+ proc = &conf->fops->actor[GF_FOP_SETATTR];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (setattr, frame, -1, ENOTCONN, NULL, NULL);
+
+ return 0;
+}
+
+int32_t
+client_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd,
+ struct iatt *stbuf, int32_t valid)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ rpc_clnt_procedure_t *proc = NULL;
+ clnt_args_t args = {0,};
+
+ conf = this->private;
+ if (!conf->fops)
+ goto out;
+
+ args.fd = fd;
+ args.stbuf = stbuf;
+ args.valid = valid;
+
+ proc = &conf->fops->actor[GF_FOP_FSETATTR];
+ if (proc->fn)
+ ret = proc->fn (frame, this, conf->fops, &args);
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (fsetattr, frame, -1, ENOTCONN, NULL, NULL);
+
+ return 0;
+}
+
+/////////////////
+int32_t
+client_getspec (call_frame_t *frame, xlator_t *this, const char *key,
+ int32_t flags)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+ gf_getspec_req req = {0,};
+
+ conf = this->private;
+ if (!conf->handshake)
+ goto out;
+
+ req.key = (char *)key;
+ req.flags = flags;
+
+ client_submit_request (this, &req, frame, conf->handshake,
+ GF_HNDSK_GETSPEC, NULL, xdr_from_getspec_req);
+ ret = 0;
+out:
+ if (ret)
+ STACK_UNWIND_STRICT (getspec, frame, -1, EINVAL, NULL);
+
+ return 0;
+}
+
+
+ int
+client_mark_fd_bad (xlator_t *this)
+{
+ clnt_conf_t *conf = NULL;
+ clnt_fd_ctx_t *tmp = NULL, *fdctx = NULL;
+
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ list_for_each_entry_safe (fdctx, tmp, &conf->saved_fds,
+ sfd_pos) {
+ fdctx->remote_fd = -1;
+ }
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ return 0;
+}
+
+
+int
+client_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
+ void *data)
+{
+ xlator_t *this = NULL;
+ char *handshake = NULL;
+ clnt_conf_t *conf = NULL;
+ int ret = 0;
+
+ this = mydata;
+ conf = this->private;
+
+ switch (event) {
+ case RPC_CLNT_CONNECT:
+ {
+ // connect happened, send 'get_supported_versions' mop
+ ret = dict_get_str (this->options, "disable-handshake",
+ &handshake);
+
+ gf_log (this->name, GF_LOG_TRACE, "got RPC_CLNT_CONNECT");
+
+ if ((ret < 0) || (strcasecmp (handshake, "on"))) {
+ ret = client_handshake (this, conf->rpc);
+
+ } else {
+ //conf->rpc->connected = 1;
+ ret = default_notify (this, GF_EVENT_CHILD_UP, NULL);
+ }
+ break;
+ }
+ case RPC_CLNT_DISCONNECT:
+
+ client_mark_fd_bad (this);
+
+ gf_log (this->name, GF_LOG_TRACE, "got RPC_CLNT_DISCONNECT");
+
+ default_notify (this, GF_EVENT_CHILD_DOWN, NULL);
+ break;
+
+ default:
+ gf_log (this->name, GF_LOG_TRACE,
+ "got some other RPC event %d", event);
+
+ break;
+ }
+
+ return 0;
+}
+
+
+int
+notify (xlator_t *this, int32_t event, void *data, ...)
+{
+ clnt_conf_t *conf = NULL;
+ void *trans = NULL;
+
+ conf = this->private;
+
+ switch (event) {
+ case GF_EVENT_PARENT_UP:
+ {
+ if (conf->rpc)
+ trans = conf->rpc->conn.trans;
+
+ if (!trans) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "transport init failed");
+ return 0;
+ }
+
+ gf_log (this->name, GF_LOG_DEBUG,
+ "got GF_EVENT_PARENT_UP, attempting connect "
+ "on transport");
+
+ rpc_clnt_reconnect (trans);
+ }
+ break;
+
+ default:
+ gf_log (this->name, GF_LOG_DEBUG,
+ "got %d, calling default_notify ()", event);
+
+ default_notify (this, event, data);
+ break;
+ }
+
+ return 0;
+}
+
+int
+build_client_config (xlator_t *this, clnt_conf_t *conf)
+{
+ int ret = 0;
+
+ ret = dict_get_str (this->options, "remote-subvolume",
+ &conf->opt.remote_subvolume);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "option 'remote-subvolume' not given");
+ goto out;
+ }
+
+ ret = dict_get_int32 (this->options, "frame-timeout",
+ &conf->rpc_conf.rpc_timeout);
+ if (ret >= 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "setting frame-timeout to %d",
+ conf->rpc_conf.rpc_timeout);
+ } else {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "defaulting frame-timeout to 30mins");
+ conf->rpc_conf.rpc_timeout = 1800;
+ }
+
+ ret = dict_get_int32 (this->options, "remote-port",
+ &conf->rpc_conf.remote_port);
+ if (ret >= 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "remote-port is %d", conf->rpc_conf.remote_port);
+ } else {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "defaulting remote-port to %d",
+ GF_PROTOCOL_DEFAULT_PORT);
+ conf->rpc_conf.remote_port = GF_PROTOCOL_DEFAULT_PORT;
+ }
+
+ ret = dict_get_int32 (this->options, "ping-timeout",
+ &conf->opt.ping_timeout);
+ if (ret >= 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "setting ping-timeout to %d", conf->opt.ping_timeout);
+ } else {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "defaulting ping-timeout to 42");
+ conf->opt.ping_timeout = GF_UNIVERSAL_ANSWER;
+ }
+
+ ret = 0;
+out:
+ return ret;}
+
+
+static int32_t
+mem_acct_init (xlator_t *this)
+{
+ int ret = -1;
+
+ if (!this)
+ return ret;
+
+ ret = xlator_mem_acct_init (this, gf_client_mt_end + 1);
+
+ if (ret != 0) {
+ gf_log (this->name, GF_LOG_ERROR, "Memory accounting init"
+ "failed");
+ return ret;
+ }
+
+ return ret;
+}
+
+
+int
+init (xlator_t *this)
+{
+ int ret = -1;
+ clnt_conf_t *conf = NULL;
+
+ /* */
+ if (this->children) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "FATAL: client protocol translator cannot have any "
+ "subvolumes");
+ goto out;
+ }
+
+ if (!this->parents) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "Volume is dangling. ");
+ }
+
+ ret = mem_acct_init (this);
+ if (ret)
+ goto out;
+
+ conf = GF_CALLOC (1, sizeof (*conf), gf_client_mt_clnt_conf_t);
+ if (!conf)
+ goto out;
+
+ pthread_mutex_init (&conf->lock, NULL);
+ INIT_LIST_HEAD (&conf->saved_fds);
+
+ ret = build_client_config (this, conf);
+ if (ret)
+ goto out;
+
+ conf->rpc = rpc_clnt_init (&conf->rpc_conf, this->options, this->ctx,
+ this->name);
+ if (!conf->rpc)
+ goto out;
+ conf->rpc->xid = 42; /* It should be enough random everytime :O */
+ ret = rpc_clnt_register_notify (conf->rpc, client_rpc_notify, this);
+ if (ret)
+ goto out;
+
+ conf->handshake = &clnt_handshake_prog;
+ this->private = conf;
+
+ ret = 0;
+out:
+ if (ret)
+ this->fini (this);
+
+ return ret;
+}
+
+void
+fini (xlator_t *this)
+{
+ clnt_conf_t *conf = NULL;
+
+ conf = this->private;
+ this->private = NULL;
+
+ if (conf) {
+ if (conf->rpc)
+ rpc_clnt_destroy (conf->rpc);
+
+ /* Saved Fds */
+ /* TODO: */
+
+ pthread_mutex_destroy (&conf->lock);
+
+ GF_FREE (conf);
+ }
+ return;
+}
+
+int
+client_priv_dump (xlator_t *this)
+{
+ clnt_conf_t *conf = NULL;
+ int ret = -1;
+ clnt_fd_ctx_t *tmp = NULL;
+ int i = 0;
+ char key[GF_DUMP_MAX_BUF_LEN];
+ char key_prefix[GF_DUMP_MAX_BUF_LEN];
+
+ if (!this)
+ return -1;
+
+ conf = this->private;
+ if (!conf) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "conf null in xlator");
+ return -1;
+ }
+
+ ret = pthread_mutex_trylock(&conf->lock);
+ if (ret) {
+ gf_log("", GF_LOG_WARNING, "Unable to lock client %s"
+ " errno: %d", this->name, errno);
+ return -1;
+ }
+
+ gf_proc_dump_build_key(key_prefix, "xlator.protocol.client",
+ "%s.priv", this->name);
+
+ gf_proc_dump_add_section(key_prefix);
+
+ list_for_each_entry(tmp, &conf->saved_fds, sfd_pos) {
+ gf_proc_dump_build_key(key, key_prefix,
+ "fd.%d.remote_fd", ++i);
+ gf_proc_dump_write(key, "%d", tmp->remote_fd);
+ }
+
+ gf_proc_dump_build_key(key, key_prefix, "connecting");
+ gf_proc_dump_write(key, "%d", conf->connecting);
+ gf_proc_dump_build_key(key, key_prefix, "last_sent");
+ gf_proc_dump_write(key, "%s", ctime(&conf->last_sent.tv_sec));
+ gf_proc_dump_build_key(key, key_prefix, "last_received");
+ gf_proc_dump_write(key, "%s", ctime(&conf->last_received.tv_sec));
+
+ pthread_mutex_unlock(&conf->lock);
+
+ return 0;
+
+}
+
+int32_t
+client_inodectx_dump (xlator_t *this, inode_t *inode)
+{
+ ino_t par = 0;
+ uint64_t gen = 0;
+ int ret = -1;
+ char key[GF_DUMP_MAX_BUF_LEN];
+
+ if (!inode)
+ return -1;
+
+ if (!this)
+ return -1;
+
+ ret = inode_ctx_get2 (inode, this, &par, &gen);
+
+ if (ret != 0)
+ return ret;
+
+ gf_proc_dump_build_key(key, "xlator.protocol.client",
+ "%s.inode.%ld.par",
+ this->name,inode->ino);
+ gf_proc_dump_write(key, "%ld, %ld", par, gen);
+
+ return 0;
+}
+
+
+
+
+struct xlator_cbks cbks = {
+ .forget = client_forget,
+ .release = client_release,
+ .releasedir = client_releasedir
+};
+
+struct xlator_fops fops = {
+ .stat = client_stat,
+ .readlink = client_readlink,
+ .mknod = client_mknod,
+ .mkdir = client_mkdir,
+ .unlink = client_unlink,
+ .rmdir = client_rmdir,
+ .symlink = client_symlink,
+ .rename = client_rename,
+ .link = client_link,
+ .truncate = client_truncate,
+ .open = client_open,
+ .readv = client_readv,
+ .writev = client_writev,
+ .statfs = client_statfs,
+ .flush = client_flush,
+ .fsync = client_fsync,
+ .setxattr = client_setxattr,
+ .getxattr = client_getxattr,
+ .fsetxattr = client_fsetxattr,
+ .fgetxattr = client_fgetxattr,
+ .removexattr = client_removexattr,
+ .opendir = client_opendir,
+ .readdir = client_readdir,
+ .readdirp = client_readdirp,
+ .fsyncdir = client_fsyncdir,
+ .access = client_access,
+ .ftruncate = client_ftruncate,
+ .fstat = client_fstat,
+ .create = client_create,
+ .lk = client_lk,
+ .inodelk = client_inodelk,
+ .finodelk = client_finodelk,
+ .entrylk = client_entrylk,
+ .fentrylk = client_fentrylk,
+ .lookup = client_lookup,
+ .checksum = client_checksum,
+ .rchecksum = client_rchecksum,
+ .xattrop = client_xattrop,
+ .fxattrop = client_fxattrop,
+ .setattr = client_setattr,
+ .fsetattr = client_fsetattr,
+ .getspec = client_getspec,
+};
+
+
+struct xlator_dumpops dumpops = {
+ .priv = client_priv_dump,
+ .inodectx = client_inodectx_dump,
+};
+
+
+struct volume_options options[] = {
+ { .key = {"username"},
+ .type = GF_OPTION_TYPE_ANY
+ },
+ { .key = {"password"},
+ .type = GF_OPTION_TYPE_ANY
+ },
+ { .key = {"transport-type"},
+ .value = {"tcp", "socket", "ib-verbs", "unix", "ib-sdp",
+ "tcp/client", "ib-verbs/client"},
+ .type = GF_OPTION_TYPE_STR
+ },
+ { .key = {"remote-host"},
+ .type = GF_OPTION_TYPE_INTERNET_ADDRESS
+ },
+ { .key = {"remote-subvolume"},
+ .type = GF_OPTION_TYPE_ANY
+ },
+ { .key = {"frame-timeout",
+ "rpc-timeout" },
+ .type = GF_OPTION_TYPE_TIME,
+ .min = 0,
+ .max = 86400,
+ },
+ { .key = {"ping-timeout"},
+ .type = GF_OPTION_TYPE_TIME,
+ .min = 1,
+ .max = 1013,
+ },
+ { .key = {NULL} },
+};
diff --git a/xlators/protocol/client/src/client.h b/xlators/protocol/client/src/client.h
new file mode 100644
index 0000000..9d713be
--- /dev/null
+++ b/xlators/protocol/client/src/client.h
@@ -0,0 +1,125 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _CLIENT_H
+#define _CLIENT_H
+
+#include <pthread.h>
+#include <stdint.h>
+
+#include "rpc-clnt.h"
+#include "list.h"
+#include "inode.h"
+#include "client-mem-types.h"
+#include "protocol-common.h"
+
+struct clnt_options {
+ char *remote_subvolume;
+ int ping_timeout;
+};
+
+typedef struct clnt_conf {
+ struct rpc_clnt *rpc;
+ struct clnt_options opt;
+ struct rpc_clnt_config rpc_conf;
+ struct list_head saved_fds;
+ pthread_mutex_t lock;
+ int connecting;
+ struct timeval last_sent;
+ struct timeval last_received;
+
+ rpc_clnt_prog_t *fops;
+ rpc_clnt_prog_t *mgmt;
+ rpc_clnt_prog_t *handshake;
+} clnt_conf_t;
+
+typedef struct _client_fd_ctx {
+ struct list_head sfd_pos; /* Stores the reference to this
+ fd's position in the saved_fds list.
+ */
+ int64_t remote_fd;
+ inode_t *inode;
+ uint64_t ino;
+ uint64_t gen;
+ char is_dir;
+ char released;
+ int32_t flags;
+ int32_t wbflags;
+} clnt_fd_ctx_t;
+
+typedef struct client_local {
+ loc_t loc;
+ loc_t loc2;
+ fd_t *fd;
+ clnt_fd_ctx_t *fdctx;
+ uint32_t flags;
+ uint32_t wbflags;
+ fop_cbk_fn_t op;
+} clnt_local_t;
+
+typedef struct client_args {
+ loc_t *loc;
+ fd_t *fd;
+ dict_t *xattr_req;
+ const char *linkname;
+ struct iobref *iobref;
+ struct iovec *vector;
+ dict_t *xattr;
+ struct iatt *stbuf;
+ dict_t *dict;
+ loc_t *oldloc;
+ loc_t *newloc;
+ const char *name;
+ struct flock *flock;
+ const char *volume;
+ const char *basename;
+ off_t offset;
+ int32_t mask;
+ int32_t cmd;
+ size_t size;
+ mode_t mode;
+ dev_t rdev;
+ int32_t flags;
+ int32_t wbflags;
+ int32_t count;
+ int32_t datasync;
+ entrylk_cmd cmd_entrylk;
+ entrylk_type type;
+ gf_xattrop_flags_t optype;
+ int32_t valid;
+ int32_t len;
+} clnt_args_t;
+
+typedef ssize_t (*gfs_serialize_t) (struct iovec outmsg, void *args);
+
+clnt_fd_ctx_t *this_fd_get_ctx (fd_t *file, xlator_t *this);
+clnt_fd_ctx_t *this_fd_del_ctx (fd_t *file, xlator_t *this);
+void this_fd_set_ctx (fd_t *file, xlator_t *this, loc_t *loc,
+ clnt_fd_ctx_t *ctx);
+
+int client_local_wipe (clnt_local_t *local);
+int client_submit_request (xlator_t *this, void *req,
+ call_frame_t *frame, rpc_clnt_prog_t *prog,
+ int procnum, struct iobref *iobref,
+ gfs_serialize_t sfunc);
+
+int protocol_client_reopendir (xlator_t *this, clnt_fd_ctx_t *fdctx);
+int protocol_client_reopen (xlator_t *this, clnt_fd_ctx_t *fdctx);
+
+#endif /* !_CLIENT_H */
diff --git a/xlators/protocol/client/src/client3_1-fops.c b/xlators/protocol/client/src/client3_1-fops.c
new file mode 100644
index 0000000..01b7843
--- /dev/null
+++ b/xlators/protocol/client/src/client3_1-fops.c
@@ -0,0 +1,4662 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include "client.h"
+#include "glusterfs-xdr.h"
+#include "msg-xdr.h"
+#include "compat-errno.h"
+
+void client_start_ping (void *data);
+rpc_clnt_prog_t clnt3_1_fop_prog;
+
+int
+client_submit_vec_request (xlator_t *this, void *req,
+ call_frame_t *frame, rpc_clnt_prog_t *prog, int procnum,
+ struct iovec *payload, int payloadcnt,
+ struct iobref *iobref, gfs_serialize_t sfunc)
+{
+ int ret = 0;
+ clnt_conf_t *conf = NULL;
+ struct iovec iov = {0, };
+ struct iobuf *iobuf = NULL;
+ int count = 0;
+ char new_iobref = 0;
+ int start_ping = 0;
+
+ start_ping = 0;
+
+ conf = this->private;
+
+ iobuf = iobuf_get (this->ctx->iobuf_pool);
+ if (!iobuf) {
+ goto out;
+ };
+
+ if (!iobref) {
+ iobref = iobref_new ();
+ if (!iobref) {
+ goto out;
+ }
+
+ new_iobref = 1;
+ }
+
+ iobref_add (iobref, iobuf);
+
+ iov.iov_base = iobuf->ptr;
+ iov.iov_len = 128 * GF_UNIT_KB;
+
+ /* Create the xdr payload */
+ if (req && sfunc) {
+ ret = sfunc (iov, req);
+ if (ret == -1) {
+ goto out;
+ }
+ iov.iov_len = ret;
+ count = 1;
+ }
+ /* Send the msg */
+ ret = rpc_clnt_submit (conf->rpc, prog, procnum, &iov, count,
+ payload, payloadcnt, iobref, frame);
+
+ if (ret == 0) {
+ pthread_mutex_lock (&conf->rpc->conn.lock);
+ {
+ if (!conf->rpc->conn.ping_started) {
+ start_ping = 1;
+ }
+ }
+ pthread_mutex_unlock (&conf->rpc->conn.lock);
+ }
+
+ if (start_ping)
+ client_start_ping ((void *) this);
+
+out:
+ if (new_iobref) {
+ iobref_unref (iobref);
+ }
+
+ iobuf_unref (iobuf);
+
+ return 0;
+}
+
+int
+client_fdctx_destroy (xlator_t *this, clnt_fd_ctx_t *fdctx)
+{
+ call_frame_t *fr = NULL;
+ int32_t ret = -1;
+
+ if (!fdctx)
+ goto out;
+
+ if (fdctx->remote_fd == -1)
+ goto out;
+
+ fr = create_frame (this, this->ctx->pool);
+
+ if (fdctx->is_dir) {
+ gfs3_releasedir_req req = {0,};
+ req.fd = fdctx->remote_fd;
+ client_submit_request (this, &req, fr, &clnt3_1_fop_prog,
+ GFS3_OP_RELEASEDIR, NULL,
+ xdr_from_releasedir_req);
+ } else {
+ gfs3_release_req req = {0,};
+ req.fd = fdctx->remote_fd;
+ client_submit_request (this, &req, fr, &clnt3_1_fop_prog,
+ GFS3_OP_RELEASE, NULL,
+ xdr_from_release_req);
+ }
+
+out:
+ fdctx->remote_fd = -1;
+ inode_unref (fdctx->inode);
+ GF_FREE (fdctx);
+
+ return ret;
+}
+
+int
+client3_1_reopen_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ int32_t ret = -1;
+ gfs3_open_rsp rsp = {0,};
+ clnt_local_t *local = NULL;
+ clnt_conf_t *conf = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ call_frame_t *frame = NULL;
+
+ frame = myframe;
+
+ local = frame->local;
+ conf = frame->this->private;
+ fdctx = local->fdctx;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_open_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "reopen on %s returned %d (%"PRId64")",
+ local->loc.path, rsp.op_ret, rsp.fd);
+
+ if (-1 != rsp.op_ret) {
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx->remote_fd = rsp.fd;
+
+ if (!fdctx->released) {
+ list_add_tail (&fdctx->sfd_pos, &conf->saved_fds);
+ fdctx = NULL;
+ }
+ }
+ pthread_mutex_unlock (&conf->lock);
+ }
+
+out:
+ if (fdctx)
+ client_fdctx_destroy (frame->this, fdctx);
+
+ frame->local = NULL;
+ STACK_DESTROY (frame->root);
+
+ client_local_wipe (local);
+
+ return 0;
+}
+
+int
+client3_1_reopendir_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ int32_t ret = -1;
+ gfs3_open_rsp rsp = {0,};
+ clnt_local_t *local = NULL;
+ clnt_conf_t *conf = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ call_frame_t *frame = NULL;
+
+ frame = myframe;
+ if (!frame || !frame->this)
+ goto out;
+
+ local = frame->local;
+ frame->local = NULL;
+ conf = frame->this->private;
+ fdctx = local->fdctx;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_opendir_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "reopendir on %s returned %d (%"PRId64")",
+ local->loc.path, rsp.op_ret, rsp.fd);
+
+ if (fdctx) {
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx->remote_fd = rsp.fd;
+
+ if (!fdctx->released) {
+ list_add_tail (&fdctx->sfd_pos, &conf->saved_fds);
+ fdctx = NULL;
+ }
+ }
+ pthread_mutex_unlock (&conf->lock);
+ }
+
+out:
+ if (fdctx)
+ client_fdctx_destroy (frame->this, fdctx);
+
+ frame->local = NULL;
+ STACK_DESTROY (frame->root);
+
+ client_local_wipe (local);
+
+ return 0;
+}
+
+int
+protocol_client_reopendir (xlator_t *this, clnt_fd_ctx_t *fdctx)
+{
+ int ret = -1;
+ gfs3_opendir_req req = {0,};
+ clnt_local_t *local = NULL;
+ inode_t *inode = NULL;
+ char *path = NULL;
+ call_frame_t *frame = NULL;
+ clnt_conf_t *conf = NULL;
+
+ if (!this || !fdctx)
+ goto out;
+
+ inode = fdctx->inode;
+ conf = this->private;
+
+ ret = inode_path (inode, NULL, &path);
+ if (ret < 0) {
+ goto out;
+ }
+
+ local = GF_CALLOC (1, sizeof (*local), 0);
+ if (!local) {
+ goto out;
+ }
+
+ local->fdctx = fdctx;
+ local->op = client3_1_reopendir_cbk;
+ local->loc.path = path;
+ path = NULL;
+
+ frame = create_frame (this, this->ctx->pool);
+ if (!frame) {
+ goto out;
+ }
+
+ req.ino = fdctx->ino;
+ req.gen = fdctx->gen;
+ req.path = (char *)local->loc.path;
+
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "attempting reopen on %s", local->loc.path);
+
+ frame->local = local; local = NULL;
+
+ client_submit_request (this, &req, frame, conf->fops,
+ GFS3_OP_OPENDIR, NULL, xdr_from_opendir_req);
+
+ return ret;
+
+out:
+ if (frame) {
+ frame->local = NULL;
+ STACK_DESTROY (frame->root);
+ }
+
+ if (local)
+ client_local_wipe (local);
+
+ if (path)
+ GF_FREE (path);
+
+ return 0;
+
+}
+
+int
+protocol_client_reopen (xlator_t *this, clnt_fd_ctx_t *fdctx)
+{
+ int ret = -1;
+ gfs3_open_req req = {0,};
+ clnt_local_t *local = NULL;
+ inode_t *inode = NULL;
+ char *path = NULL;
+ call_frame_t *frame = NULL;
+ clnt_conf_t *conf = NULL;
+
+ if (!this || !fdctx)
+ goto out;
+
+ inode = fdctx->inode;
+ conf = this->private;
+
+ ret = inode_path (inode, NULL, &path);
+ if (ret < 0) {
+ goto out;
+ }
+
+ frame = create_frame (this, this->ctx->pool);
+ if (!frame) {
+ goto out;
+ }
+
+ local = GF_CALLOC (1, sizeof (*local), 0);
+ if (!local) {
+ goto out;
+ }
+
+ local->fdctx = fdctx;
+ local->op = client3_1_reopen_cbk;
+ local->loc.path = path;
+ path = NULL;
+ frame->local = local;
+
+ req.ino = fdctx->ino;
+ req.gen = fdctx->gen;
+ req.flags = gf_flags_from_flags (fdctx->flags);
+ req.wbflags = fdctx->wbflags;
+ req.path = (char *)local->loc.path;
+
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "attempting reopen on %s", local->loc.path);
+
+ local = NULL;
+ client_submit_request (this, &req, frame, conf->fops,
+ GFS3_OP_OPEN, NULL, xdr_from_open_req);
+
+ return ret;
+
+out:
+ if (frame) {
+ frame->local = NULL;
+ STACK_DESTROY (frame->root);
+ }
+
+ if (local)
+ client_local_wipe (local);
+
+ if (path)
+ GF_FREE (path);
+
+ return 0;
+
+}
+
+
+
+int32_t
+client3_1_releasedir (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_conf_t *conf = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_args_t *args = NULL;
+ gfs3_releasedir_req req = {0,};
+ int64_t remote_fd = -1;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_del_ctx (args->fd, this);
+ if (fdctx != NULL) {
+ remote_fd = fdctx->remote_fd;
+
+ /* fdctx->remote_fd == -1 indicates a reopen attempt
+ in progress. Just mark ->released = 1 and let
+ reopen_cbk handle releasing
+ */
+
+ if (remote_fd != -1)
+ list_del_init (&fdctx->sfd_pos);
+
+ fdctx->released = 1;
+ }
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (remote_fd != -1) {
+ req.fd = remote_fd;
+ client_submit_request (this, &req, frame, prog,
+ GFS3_OP_RELEASEDIR,
+ NULL, xdr_from_releasedir_req);
+ inode_unref (fdctx->inode);
+ GF_FREE (fdctx);
+ }
+
+ return 0;
+unwind:
+ return 0;
+}
+
+int32_t
+client3_1_release (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ int64_t remote_fd = -1;
+ clnt_conf_t *conf = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_args_t *args = NULL;
+ gfs3_release_req req = {0,};
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_del_ctx (args->fd, this);
+ if (fdctx != NULL) {
+ remote_fd = fdctx->remote_fd;
+
+ /* fdctx->remote_fd == -1 indicates a reopen attempt
+ in progress. Just mark ->released = 1 and let
+ reopen_cbk handle releasing
+ */
+
+ if (remote_fd != -1)
+ list_del_init (&fdctx->sfd_pos);
+
+ fdctx->released = 1;
+ }
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (remote_fd != -1) {
+ req.fd = remote_fd;
+ client_submit_request (this, &req, frame, prog,
+ GFS3_OP_RELEASE, NULL,
+ xdr_from_release_req);
+ inode_unref (fdctx->inode);
+ GF_FREE (fdctx);
+ }
+ return 0;
+unwind:
+ return 0;
+}
+
+
+int32_t
+client3_1_lookup (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_local_t *local = NULL;
+ clnt_args_t *args = NULL;
+ gfs3_lookup_req req = {0,};
+ int ret = 0;
+ size_t dict_len = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t);
+ if (!local) {
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+
+ loc_copy (&local->loc, args->loc);
+ frame->local = local;
+
+ if (args->loc->ino != 1 && args->loc->parent) {
+ ret = inode_ctx_get2 (args->loc->parent, this,
+ &req.par, &req.gen);
+ if (args->loc->parent->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "LOOKUP %"PRId64"/%s (%s): failed to get "
+ "remote inode number for parent",
+ args->loc->parent->ino, args->loc->name,
+ args->loc->path);
+ goto unwind;
+ }
+ GF_VALIDATE_OR_GOTO (this->name, args->loc->name, unwind);
+ } else {
+ req.ino = 1;
+ }
+
+ if (args->dict) {
+ ret = dict_allocate_and_serialize (args->dict,
+ &req.dict.dict_val,
+ &dict_len);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "failed to get serialized length of dict");
+ op_errno = EINVAL;
+ goto unwind;
+ }
+ }
+
+ req.path = (char *)args->loc->path;
+ req.bname = (char *)args->loc->name;
+ req.dict.dict_len = dict_len;
+
+ client_submit_request (this, &req, frame,prog,
+ GFS3_OP_LOOKUP, NULL, xdr_from_lookup_req);
+
+ if (req.dict.dict_val) {
+ GF_FREE (req.dict.dict_val);
+ }
+
+ return 0;
+
+unwind:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT (lookup, frame, -1, op_errno, NULL, NULL, NULL, NULL);
+
+ if (local)
+ client_local_wipe (local);
+
+ if (req.dict.dict_val) {
+ GF_FREE (req.dict.dict_val);
+ }
+
+ return 0;
+}
+
+
+
+int32_t
+client3_1_stat (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_stat_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ ret = inode_ctx_get2 (args->loc->inode, this, &req.ino, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "STAT %"PRId64" (%s): "
+ "failed to get remote inode number",
+ args->loc->inode->ino, args->loc->path);
+ goto unwind;
+ }
+ req.path = (char *)args->loc->path;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_STAT,
+ NULL, xdr_from_stat_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (stat, frame, -1, op_errno, NULL);
+ return 0;
+}
+
+
+int32_t
+client3_1_truncate (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_truncate_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ ret = inode_ctx_get2 (args->loc->inode, this, &req.ino, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "STAT %"PRId64" (%s): "
+ "failed to get remote inode number",
+ args->loc->inode->ino, args->loc->path);
+ goto unwind;
+ }
+ req.path = (char *)args->loc->path;
+ req.offset = args->offset;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_TRUNCATE,
+ NULL, xdr_from_truncate_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (truncate, frame, -1, op_errno, NULL, NULL);
+ return 0;
+}
+
+
+int32_t
+client3_1_ftruncate (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ gfs3_ftruncate_req req = {0,};
+ int op_errno = EINVAL;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ req.offset = args->offset;
+ req.fd = fdctx->remote_fd;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_FTRUNCATE,
+ NULL, xdr_from_ftruncate_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (ftruncate, frame, -1, op_errno, NULL, NULL);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_access (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_access_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ ret = inode_ctx_get2 (args->loc->inode, this, &req.ino, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "STAT %"PRId64" (%s): "
+ "failed to get remote inode number",
+ args->loc->inode->ino, args->loc->path);
+ goto unwind;
+ }
+ req.path = (char *)args->loc->path;
+ req.mask = args->mask;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_ACCESS,
+ NULL, xdr_from_access_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (access, frame, -1, op_errno);
+ return 0;
+}
+
+int32_t
+client3_1_readlink (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_readlink_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ ret = inode_ctx_get2 (args->loc->inode, this, &req.ino, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "STAT %"PRId64" (%s): "
+ "failed to get remote inode number",
+ args->loc->inode->ino, args->loc->path);
+ goto unwind;
+ }
+ req.path = (char *)args->loc->path;
+ req.size = args->size;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_READLINK,
+ NULL, xdr_from_readlink_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (readlink, frame, -1, op_errno, NULL, NULL);
+ return 0;
+}
+
+
+
+
+int32_t
+client3_1_unlink (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_unlink_req req = {0,};
+ int ret = 0;
+ int op_errno = 0;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ ret = inode_ctx_get2 (args->loc->parent, this, &req.par, &req.gen);
+ if (args->loc->parent->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "STAT %"PRId64"/%s (%s): "
+ "failed to get remote inode number for parent",
+ args->loc->parent->ino, args->loc->name, args->loc->path);
+ goto unwind;
+ }
+ req.path = (char *)args->loc->path;
+ req.bname = (char *)args->loc->name;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_UNLINK,
+ NULL, xdr_from_unlink_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (unlink, frame, -1, op_errno, NULL, NULL);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_rmdir (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_rmdir_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ ret = inode_ctx_get2 (args->loc->parent, this, &req.par, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "STAT %"PRId64"/%s (%s): "
+ "failed to get remote inode number for parent",
+ args->loc->parent->ino, args->loc->name, args->loc->path);
+ goto unwind;
+ }
+ req.path = (char *)args->loc->path;
+ req.bname = (char *)args->loc->name;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_RMDIR,
+ NULL, xdr_from_rmdir_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (rmdir, frame, -1, op_errno, NULL, NULL);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_symlink (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_local_t *local = NULL;
+ clnt_args_t *args = NULL;
+ gfs3_symlink_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t);
+ if (!local) {
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+
+ loc_copy (&local->loc, args->loc);
+ frame->local = local;
+
+ ret = inode_ctx_get2 (args->loc->parent, this, &req.par, &req.gen);
+ if (args->loc->parent->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "SYMLINK %"PRId64"/%s (%s): failed to get remote inode"
+ " number parent",
+ args->loc->parent->ino, args->loc->name,
+ args->loc->path);
+ goto unwind;
+ }
+
+ req.path = (char *)args->loc->path;
+ req.linkname = (char *)args->linkname;
+ req.bname = (char *)args->loc->name;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_SYMLINK,
+ NULL, xdr_from_symlink_req);
+
+ return 0;
+unwind:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT (symlink, frame, -1, op_errno, NULL, NULL, NULL, NULL);
+ if (local)
+ client_local_wipe (local);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_rename (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_rename_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ ret = inode_ctx_get2 (args->oldloc->parent, this,
+ &req.oldpar, &req.oldgen);
+ if (args->oldloc->parent->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "RENAME %"PRId64"/%s (%s): failed to get remote inode "
+ "number for source parent", args->oldloc->parent->ino,
+ args->oldloc->name, args->oldloc->path);
+ goto unwind;
+ }
+
+ ret = inode_ctx_get2 (args->newloc->parent, this, &req.newpar,
+ &req.newgen);
+ if (args->newloc->parent->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "CREATE %"PRId64"/%s (%s): failed to get remote inode "
+ "number for destination parent",
+ args->newloc->parent->ino, args->newloc->name,
+ args->newloc->path);
+ goto unwind;
+ }
+
+ req.oldpath = (char *)args->oldloc->path;
+ req.oldbname = (char *)args->oldloc->name;
+ req.newpath = (char *)args->newloc->path;
+ req.newbname = (char *)args->newloc->name;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_RENAME,
+ NULL, xdr_from_rename_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (rename, frame, -1, op_errno, NULL, NULL, NULL, NULL, NULL);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_link (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_local_t *local = NULL;
+ clnt_args_t *args = NULL;
+ gfs3_link_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t);
+ if (!local) {
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+
+ loc_copy (&local->loc, args->oldloc);
+ frame->local = local;
+
+ ret = inode_ctx_get2 (args->oldloc->inode, this,
+ &req.oldino, &req.oldgen);
+ if (args->oldloc->parent->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "RENAME %"PRId64"/%s (%s): failed to get remote inode "
+ "number for source parent", args->oldloc->parent->ino,
+ args->oldloc->name, args->oldloc->path);
+ goto unwind;
+ }
+
+ ret = inode_ctx_get2 (args->newloc->parent, this, &req.newpar,
+ &req.newgen);
+ if (args->newloc->parent->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "CREATE %"PRId64"/%s (%s): failed to get remote inode "
+ "number for destination parent",
+ args->newloc->parent->ino, args->newloc->name,
+ args->newloc->path);
+ goto unwind;
+ }
+
+ req.oldpath = (char *)args->oldloc->path;
+ req.newpath = (char *)args->newloc->path;
+ req.newbname = (char *)args->newloc->name;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_LINK,
+ NULL, xdr_from_link_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (link, frame, -1, op_errno, NULL, NULL, NULL, NULL);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_mknod (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_local_t *local = NULL;
+ clnt_args_t *args = NULL;
+ gfs3_mknod_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t);
+ if (!local) {
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+
+ loc_copy (&local->loc, args->loc);
+ frame->local = local;
+
+ ret = inode_ctx_get2 (args->loc->parent, this, &req.par, &req.gen);
+ if (args->loc->parent->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "SYMLINK %"PRId64"/%s (%s): failed to get remote inode"
+ " number parent",
+ args->loc->parent->ino, args->loc->name,
+ args->loc->path);
+ goto unwind;
+ }
+
+ req.path = (char *)args->loc->path;
+ req.bname = (char *)args->loc->name;
+ req.mode = args->mode;
+ req.dev = args->rdev;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_MKNOD,
+ NULL, xdr_from_mknod_req);
+
+ return 0;
+unwind:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT (mknod, frame, -1, op_errno, NULL, NULL, NULL, NULL);
+ if (local)
+ client_local_wipe (local);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_mkdir (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_local_t *local = NULL;
+ clnt_args_t *args = NULL;
+ gfs3_mkdir_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t);
+ if (!local) {
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+
+ loc_copy (&local->loc, args->loc);
+ frame->local = local;
+
+ ret = inode_ctx_get2 (args->loc->parent, this, &req.par, &req.gen);
+ if (args->loc->parent->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "SYMLINK %"PRId64"/%s (%s): failed to get remote inode"
+ " number parent",
+ args->loc->parent->ino, args->loc->name,
+ args->loc->path);
+ goto unwind;
+ }
+
+ req.path = (char *)args->loc->path;
+ req.bname = (char *)args->loc->name;
+ req.mode = args->mode;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_MKDIR,
+ NULL, xdr_from_mkdir_req);
+
+ return 0;
+unwind:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT (mkdir, frame, -1, op_errno, NULL, NULL, NULL, NULL);
+ if (local)
+ client_local_wipe (local);
+ return 0;
+}
+
+
+int32_t
+client3_1_create (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_local_t *local = NULL;
+ clnt_args_t *args = NULL;
+ gfs3_create_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t);
+ if (!local) {
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+ local->fd = fd_ref (args->fd);
+ local->flags = args->flags;
+ loc_copy (&local->loc, args->loc);
+ frame->local = local;
+
+ ret = inode_ctx_get2 (args->loc->parent, this, &req.par, &req.gen);
+ if (args->loc->parent->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "SYMLINK %"PRId64"/%s (%s): failed to get remote inode"
+ " number parent",
+ args->loc->parent->ino, args->loc->name,
+ args->loc->path);
+ goto unwind;
+ }
+
+ req.path = (char *)args->loc->path;
+ req.bname = (char *)args->loc->name;
+ req.mode = args->mode;
+ req.flags = gf_flags_from_flags (args->flags);
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_CREATE,
+ NULL, xdr_from_create_req);
+
+ return 0;
+unwind:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT (create, frame, -1, op_errno, NULL, NULL, NULL, NULL, NULL);
+ if (local)
+ client_local_wipe (local);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_open (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_local_t *local = NULL;
+ clnt_args_t *args = NULL;
+ gfs3_open_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t);
+ if (!local) {
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+ local->fd = fd_ref (args->fd);
+ local->flags = args->flags;
+ local->wbflags = args->wbflags;
+ loc_copy (&local->loc, args->loc);
+ frame->local = local;
+
+ ret = inode_ctx_get2 (args->loc->inode, this, &req.ino, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "OPEN %"PRId64" (%s): "
+ "failed to get remote inode number",
+ args->loc->inode->ino, args->loc->path);
+ goto unwind;
+ }
+ req.flags = gf_flags_from_flags (args->flags);
+ req.wbflags = args->wbflags;
+ req.path = (char *)args->loc->path;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_OPEN,
+ NULL, xdr_from_open_req);
+
+ return 0;
+unwind:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT (open, frame, -1, op_errno, NULL);
+ if (local)
+ client_local_wipe (local);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_readv (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ int op_errno = ESTALE;
+ gfs3_read_req req = {0,};
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ req.size = args->size;
+ req.offset = args->offset;
+ req.fd = fdctx->remote_fd;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_READ,
+ NULL, xdr_from_readv_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (readv, frame, -1, op_errno, NULL, 0, NULL, NULL);
+ return 0;
+}
+
+
+int32_t
+client3_1_writev (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ gfs3_write_req req = {0,};
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ req.size = args->size;
+ req.offset = args->offset;
+ req.fd = fdctx->remote_fd;
+
+ /* TODO: Buffer */
+
+ client_submit_vec_request (this, &req, frame,prog, GFS3_OP_WRITE,
+ args->vector, args->count,
+ args->iobref, xdr_from_writev_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (writev, frame, -1, op_errno, NULL, NULL);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_flush (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_flush_req req = {0,};
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ req.fd = fdctx->remote_fd;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_FLUSH,
+ NULL, xdr_from_flush_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (flush, frame, -1, op_errno);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_fsync (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_fsync_req req = {0,};
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ int op_errno = 0;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ req.fd = fdctx->remote_fd;
+ req.data = args->flags;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_FSYNC,
+ NULL, xdr_from_fsync_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (fsync, frame, -1, op_errno, NULL, NULL);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_fstat (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_fstat_req req = {0,};
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ req.fd = fdctx->remote_fd;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_FSTAT,
+ NULL, xdr_from_fstat_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (fstat, frame, -1, op_errno, NULL);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_opendir (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_local_t *local = NULL;
+ clnt_args_t *args = NULL;
+ gfs3_opendir_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t);
+ if (!local) {
+ op_errno = ENOMEM;
+ goto unwind;
+ }
+ local->fd = fd_ref (args->fd);
+ loc_copy (&local->loc, args->loc);
+ frame->local = local;
+
+ ret = inode_ctx_get2 (args->loc->inode, this, &req.ino, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "OPEN %"PRId64" (%s): "
+ "failed to get remote inode number",
+ args->loc->inode->ino, args->loc->path);
+ goto unwind;
+ }
+ req.path = (char *)args->loc->path;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_OPENDIR,
+ NULL, xdr_from_opendir_req);
+
+ return 0;
+unwind:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT (opendir, frame, -1, op_errno, NULL);
+ if (local)
+ client_local_wipe (local);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_fsyncdir (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+
+{
+ clnt_args_t *args = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ int op_errno = ESTALE;
+ gfs3_fsyncdir_req req = {0,};
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ req.fd = fdctx->remote_fd;
+ req.data = args->flags;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_FSYNCDIR,
+ NULL, xdr_from_fsyncdir_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (fsyncdir, frame, -1, op_errno);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_statfs (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_statfs_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ if (args->loc->inode) {
+ ret = inode_ctx_get2 (args->loc->inode, this,
+ &req.ino, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "STATFS %"PRId64" (%s): "
+ "failed to get remote inode number",
+ args->loc->inode->ino, args->loc->path);
+ goto unwind;
+ }
+ }
+ req.path = (char *)args->loc->path;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_STATFS,
+ NULL, xdr_from_statfs_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (statfs, frame, -1, op_errno, NULL);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_setxattr (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_setxattr_req req = {0,};
+ int ret = 0;
+ size_t dict_len = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ ret = inode_ctx_get2 (args->loc->inode, this, &req.ino, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "SETXATTR %"PRId64" (%s): "
+ "failed to get remote inode number",
+ args->loc->inode->ino, args->loc->path);
+ goto unwind;
+ }
+ if (args->dict) {
+ ret = dict_allocate_and_serialize (args->dict,
+ &req.dict.dict_val,
+ &dict_len);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "failed to get serialized dict");
+ op_errno = EINVAL;
+ goto unwind;
+ }
+ req.dict.dict_len = dict_len;
+ }
+ req.flags = args->flags;
+ req.path = (char *)args->loc->path;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_SETXATTR,
+ NULL, xdr_from_setxattr_req);
+
+ if (req.dict.dict_val) {
+ GF_FREE (req.dict.dict_val);
+ }
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (setxattr, frame, -1, op_errno);
+ if (req.dict.dict_val) {
+ GF_FREE (req.dict.dict_val);
+ }
+ return 0;
+}
+
+
+
+int32_t
+client3_1_fsetxattr (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ gfs3_fsetxattr_req req = {0,};
+ int op_errno = ESTALE;
+ int ret = 0;
+ size_t dict_len = 0;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ req.fd = fdctx->remote_fd;
+ req.flags = args->flags;
+ req.ino = args->fd->inode->ino;
+
+ if (args->dict) {
+ ret = dict_allocate_and_serialize (args->dict,
+ &req.dict.dict_val,
+ &dict_len);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "failed to get serialized dict");
+ goto unwind;
+ }
+ req.dict.dict_len = dict_len;
+ }
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_FSETXATTR,
+ NULL, xdr_from_fsetxattr_req);
+
+ if (req.dict.dict_val) {
+ GF_FREE (req.dict.dict_val);
+ }
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (fsetxattr, frame, -1, op_errno);
+ if (req.dict.dict_val) {
+ GF_FREE (req.dict.dict_val);
+ }
+ return 0;
+}
+
+
+
+
+int32_t
+client3_1_fgetxattr (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ gfs3_fgetxattr_req req = {0,};
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ req.namelen = 1; /* Use it as a flag */
+ req.fd = fdctx->remote_fd;
+ req.name = (char *)args->name;
+ if (!req.name) {
+ req.name = "";
+ req.namelen = 0;
+ }
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_FGETXATTR,
+ NULL, xdr_from_fgetxattr_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (fgetxattr, frame, -1, op_errno, NULL);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_getxattr (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_getxattr_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ ret = inode_ctx_get2 (args->loc->inode, this, &req.ino, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "STAT %"PRId64" (%s): "
+ "failed to get remote inode number",
+ args->loc->inode->ino, args->loc->path);
+ goto unwind;
+ }
+
+ req.namelen = 1; /* Use it as a flag */
+ req.path = (char *)args->loc->path;
+ req.name = (char *)args->name;
+ if (!req.name) {
+ req.name = "";
+ req.namelen = 0;
+ }
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_GETXATTR,
+ NULL, xdr_from_getxattr_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (getxattr, frame, -1, op_errno, NULL);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_xattrop (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_xattrop_req req = {0,};
+ int ret = 0;
+ size_t dict_len = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ ret = inode_ctx_get2 (args->loc->inode, this, &req.ino, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "SETXATTR %"PRId64" (%s): "
+ "failed to get remote inode number",
+ args->loc->inode->ino, args->loc->path);
+ goto unwind;
+ }
+ if (args->dict) {
+ ret = dict_allocate_and_serialize (args->dict,
+ &req.dict.dict_val,
+ &dict_len);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "failed to get serialized dict");
+ op_errno = EINVAL;
+ goto unwind;
+ }
+ req.dict.dict_len = dict_len;
+ }
+ req.flags = args->flags;
+ req.path = (char *)args->loc->path;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_XATTROP,
+ NULL, xdr_from_xattrop_req);
+
+ if (req.dict.dict_val) {
+ GF_FREE (req.dict.dict_val);
+ }
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (xattrop, frame, -1, op_errno, NULL);
+ if (req.dict.dict_val) {
+ GF_FREE (req.dict.dict_val);
+ }
+ return 0;
+}
+
+
+
+int32_t
+client3_1_fxattrop (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ gfs3_fxattrop_req req = {0,};
+ int op_errno = ESTALE;
+ int ret = 0;
+ size_t dict_len = 0;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ req.fd = fdctx->remote_fd;
+ req.flags = args->flags;
+ req.ino = args->fd->inode->ino;
+
+ if (args->dict) {
+ ret = dict_allocate_and_serialize (args->dict,
+ &req.dict.dict_val,
+ &dict_len);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "failed to get serialized dict");
+ goto unwind;
+ }
+ req.dict.dict_len = dict_len;
+ }
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_FXATTROP,
+ NULL, xdr_from_fxattrop_req);
+ if (req.dict.dict_val) {
+ GF_FREE (req.dict.dict_val);
+ }
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (fxattrop, frame, -1, op_errno, NULL);
+ if (req.dict.dict_val) {
+ GF_FREE (req.dict.dict_val);
+ }
+ return 0;
+}
+
+
+
+int32_t
+client3_1_removexattr (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_removexattr_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ ret = inode_ctx_get2 (args->loc->inode, this, &req.ino, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "REMOVEXATTR %"PRId64" (%s): "
+ "failed to get remote inode number",
+ args->loc->inode->ino, args->loc->path);
+ goto unwind;
+ }
+ req.path = (char *)args->loc->path;
+ req.name = (char *)args->name;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_REMOVEXATTR,
+ NULL, xdr_from_removexattr_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (removexattr, frame, -1, op_errno);
+ return 0;
+}
+
+
+int32_t
+client3_1_lk (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_lk_req req = {0,};
+ int32_t gf_cmd = 0;
+ int32_t gf_type = 0;
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (args->cmd == F_GETLK || args->cmd == F_GETLK64)
+ gf_cmd = GF_LK_GETLK;
+ else if (args->cmd == F_SETLK || args->cmd == F_SETLK64)
+ gf_cmd = GF_LK_SETLK;
+ else if (args->cmd == F_SETLKW || args->cmd == F_SETLKW64)
+ gf_cmd = GF_LK_SETLKW;
+ else {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "Unknown cmd (%d)!", gf_cmd);
+ goto unwind;
+ }
+
+ switch (args->flock->l_type) {
+ case F_RDLCK:
+ gf_type = GF_LK_F_RDLCK;
+ break;
+ case F_WRLCK:
+ gf_type = GF_LK_F_WRLCK;
+ break;
+ case F_UNLCK:
+ gf_type = GF_LK_F_UNLCK;
+ break;
+ }
+
+ req.fd = fdctx->remote_fd;
+ req.cmd = gf_cmd;
+ req.type = gf_type;
+ gf_flock_from_flock (&req.flock, args->flock);
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_LK,
+ NULL, xdr_from_lk_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (lk, frame, -1, op_errno, NULL);
+ return 0;
+}
+
+
+int32_t
+client3_1_inodelk (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_inodelk_req req = {0,};
+ int ret = 0;
+ int32_t gf_cmd = 0;
+ int32_t gf_type = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ ret = inode_ctx_get2 (args->loc->inode, this, &req.ino, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "INODELK %"PRId64" (%s): "
+ "failed to get remote inode number",
+ args->loc->inode->ino, args->loc->path);
+ goto unwind;
+ }
+
+ if (args->cmd == F_GETLK || args->cmd == F_GETLK64)
+ gf_cmd = GF_LK_GETLK;
+ else if (args->cmd == F_SETLK || args->cmd == F_SETLK64)
+ gf_cmd = GF_LK_SETLK;
+ else if (args->cmd == F_SETLKW || args->cmd == F_SETLKW64)
+ gf_cmd = GF_LK_SETLKW;
+ else {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "Unknown cmd (%d)!", gf_cmd);
+ op_errno = EINVAL;
+ goto unwind;
+ }
+
+ switch (args->flock->l_type) {
+ case F_RDLCK:
+ gf_type = GF_LK_F_RDLCK;
+ break;
+ case F_WRLCK:
+ gf_type = GF_LK_F_WRLCK;
+ break;
+ case F_UNLCK:
+ gf_type = GF_LK_F_UNLCK;
+ break;
+ }
+
+ req.path = (char *)args->loc->path;
+ req.volume = (char *)args->volume;
+ req.cmd = gf_cmd;
+ req.type = gf_type;
+ gf_flock_from_flock (&req.flock, args->flock);
+
+ client_submit_request (this, &req, frame, prog, GFS3_OP_INODELK,
+ NULL, xdr_from_inodelk_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (inodelk, frame, -1, op_errno);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_finodelk (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_finodelk_req req = {0,};
+ int32_t gf_cmd = 0;
+ int32_t gf_type = 0;
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (args->cmd == F_GETLK || args->cmd == F_GETLK64)
+ gf_cmd = GF_LK_GETLK;
+ else if (args->cmd == F_SETLK || args->cmd == F_SETLK64)
+ gf_cmd = GF_LK_SETLK;
+ else if (args->cmd == F_SETLKW || args->cmd == F_SETLKW64)
+ gf_cmd = GF_LK_SETLKW;
+ else {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "Unknown cmd (%d)!", gf_cmd);
+ goto unwind;
+ }
+
+ switch (args->flock->l_type) {
+ case F_RDLCK:
+ gf_type = GF_LK_F_RDLCK;
+ break;
+ case F_WRLCK:
+ gf_type = GF_LK_F_WRLCK;
+ break;
+ case F_UNLCK:
+ gf_type = GF_LK_F_UNLCK;
+ break;
+ }
+
+ req.volume = (char *)args->volume;
+ req.fd = fdctx->remote_fd;
+ req.cmd = gf_cmd;
+ req.type = gf_type;
+ gf_flock_from_flock (&req.flock, args->flock);
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_FINODELK,
+ NULL, xdr_from_finodelk_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (finodelk, frame, -1, op_errno);
+ return 0;
+}
+
+
+int32_t
+client3_1_entrylk (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_entrylk_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ ret = inode_ctx_get2 (args->loc->inode, this, &req.ino, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "STAT %"PRId64" (%s): "
+ "failed to get remote inode number",
+ args->loc->inode->ino, args->loc->path);
+ goto unwind;
+ }
+ req.path = (char *)args->loc->path;
+ req.cmd = args->cmd_entrylk;
+ req.type = args->type;
+ req.volume = (char *)args->volume;
+ req.name = "";
+ if (args->basename) {
+ req.name = (char *)args->basename;
+ req.namelen = 1;
+ }
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_ENTRYLK,
+ NULL, xdr_from_entrylk_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (entrylk, frame, -1, op_errno);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_fentrylk (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_fentrylk_req req = {0,};
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ req.fd = fdctx->remote_fd;
+ req.cmd = args->cmd_entrylk;
+ req.type = args->type;
+ req.volume = (char *)args->volume;
+ req.name = "";
+ if (args->basename) {
+ req.name = (char *)args->basename;
+ req.namelen = 1;
+ }
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_FENTRYLK,
+ NULL, xdr_from_fentrylk_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (fentrylk, frame, -1, op_errno);
+ return 0;
+}
+
+
+
+
+int32_t
+client3_1_checksum (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_checksum_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ ret = inode_ctx_get2 (args->loc->inode, this, &req.ino, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "STAT %"PRId64" (%s): "
+ "failed to get remote inode number",
+ args->loc->inode->ino, args->loc->path);
+ goto unwind;
+ }
+ req.path = (char *)args->loc->path;
+ req.flag = args->flags;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_CHECKSUM,
+ NULL, xdr_from_checksum_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (checksum, frame, -1, op_errno, NULL, NULL);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_rchecksum (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ gfs3_rchecksum_req req = {0,};
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ req.len = args->len;
+ req.offset = args->offset;
+ req.fd = fdctx->remote_fd;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_RCHECKSUM,
+ NULL, xdr_from_rchecksum_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (rchecksum, frame, -1, op_errno, 0, NULL);
+ return 0;
+}
+
+
+
+int32_t
+client3_1_readdir (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ gfs3_readdir_req req = {0,};
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ req.size = args->size;
+ req.offset = args->offset;
+ req.fd = fdctx->remote_fd;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_READDIR,
+ NULL, xdr_from_readdir_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (readdir, frame, -1, op_errno, NULL);
+ return 0;
+}
+
+
+int32_t
+client3_1_readdirp (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_readdirp_req req = {0,};
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ req.size = args->size;
+ req.offset = args->offset;
+ req.fd = fdctx->remote_fd;
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_READDIRP,
+ NULL, xdr_from_readdirp_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (readdirp, frame, -1, op_errno, NULL);
+ return 0;
+}
+
+
+int32_t
+client3_1_setattr (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ gfs3_setattr_req req = {0,};
+ int ret = 0;
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+
+ ret = inode_ctx_get2 (args->loc->inode, this, &req.ino, &req.gen);
+ if (args->loc->inode->ino && ret < 0) {
+ gf_log (this->name, GF_LOG_TRACE,
+ "STAT %"PRId64" (%s): "
+ "failed to get remote inode number",
+ args->loc->inode->ino, args->loc->path);
+ goto unwind;
+ }
+ req.path = (char *)args->loc->path;
+ req.valid = args->valid;
+ gf_stat_from_iatt (&req.stbuf, args->stbuf);
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_SETATTR,
+ NULL, xdr_from_setattr_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (setattr, frame, -1, op_errno, NULL, NULL);
+ return 0;
+}
+
+int32_t
+client3_1_fsetattr (call_frame_t *frame, xlator_t *this, rpc_clnt_prog_t *prog,
+ void *data)
+{
+ clnt_args_t *args = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ clnt_conf_t *conf = NULL;
+ gfs3_fsetattr_req req = {0,};
+ int op_errno = ESTALE;
+
+ if (!frame || !this || !prog || !data)
+ goto unwind;
+
+ args = data;
+ conf = this->private;
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ fdctx = this_fd_get_ctx (args->fd, this);
+ }
+ pthread_mutex_unlock (&conf->lock);
+
+ if (fdctx == NULL) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "(%"PRId64"): failed to get fd ctx. EBADFD",
+ args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ if (fdctx->remote_fd == -1) {
+ gf_log (this->name, GF_LOG_DEBUG, "(%"PRId64"): failed to get"
+ " fd ctx. EBADFD", args->fd->inode->ino);
+ op_errno = EBADFD;
+ goto unwind;
+ }
+
+ req.fd = fdctx->remote_fd;
+ req.valid = args->valid;
+ gf_stat_from_iatt (&req.stbuf, args->stbuf);
+
+ client_submit_request (this, &req, frame,prog, GFS3_OP_FSETATTR,
+ NULL, xdr_from_fsetattr_req);
+
+ return 0;
+unwind:
+ STACK_UNWIND_STRICT (fsetattr, frame, -1, op_errno, NULL, NULL);
+ return 0;
+}
+
+/* CBK */
+int
+client3_1_release_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+
+ frame = myframe;
+ STACK_DESTROY (frame->root);
+ return 0;
+}
+int
+client3_1_releasedir_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+
+ frame = myframe;
+ STACK_DESTROY (frame->root);
+ return 0;
+}
+
+
+int
+client3_1_symlink_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gfs3_symlink_rsp rsp = {0,};
+ struct iatt stbuf = {0,};
+ struct iatt preparent = {0,};
+ struct iatt postparent = {0,};
+ int ret = 0;
+ clnt_local_t *local = NULL;
+ inode_t *inode = NULL;
+
+ frame = myframe;
+
+ local = frame->local;
+ frame->local = NULL;
+ inode = local->loc.inode;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_symlink_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.stat, &stbuf);
+
+ ret = inode_ctx_put2 (inode, frame->this,
+ stbuf.ia_ino, stbuf.ia_gen);
+ if (ret < 0) {
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "SYMLINK %"PRId64"/%s (%s): failed to set "
+ "remote inode number to inode ctx",
+ local->loc.parent->ino, local->loc.name,
+ local->loc.path);
+ }
+
+ gf_stat_to_iatt (&rsp.preparent, &preparent);
+ gf_stat_to_iatt (&rsp.postparent, &postparent);
+ }
+
+out:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT (symlink, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), inode, &stbuf,
+ &preparent, &postparent);
+
+ if (local)
+ client_local_wipe (local);
+
+ return 0;
+}
+
+
+int
+client3_1_mknod_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gfs3_mknod_rsp rsp = {0,};
+ struct iatt stbuf = {0,};
+ struct iatt preparent = {0,};
+ struct iatt postparent = {0,};
+ int ret = 0;
+ clnt_local_t *local = NULL;
+ inode_t *inode = NULL;
+
+ frame = myframe;
+
+ local = frame->local;
+ frame->local = NULL;
+ inode = local->loc.inode;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_mknod_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.stat, &stbuf);
+
+ ret = inode_ctx_put2 (inode, frame->this,
+ stbuf.ia_ino, stbuf.ia_gen);
+ if (ret < 0) {
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "MKNOD %"PRId64"/%s (%s): failed to set "
+ "remote inode number to inode ctx",
+ local->loc.parent->ino, local->loc.name,
+ local->loc.path);
+ }
+
+ gf_stat_to_iatt (&rsp.preparent, &preparent);
+ gf_stat_to_iatt (&rsp.postparent, &postparent);
+ }
+
+out:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT (mknod, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), inode,
+ &stbuf, &preparent, &postparent);
+
+ if (local)
+ client_local_wipe (local);
+
+ return 0;
+}
+
+int
+client3_1_mkdir_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gfs3_mkdir_rsp rsp = {0,};
+ struct iatt stbuf = {0,};
+ struct iatt preparent = {0,};
+ struct iatt postparent = {0,};
+ int ret = 0;
+ clnt_local_t *local = NULL;
+ inode_t *inode = NULL;
+
+ frame = myframe;
+
+ local = frame->local;
+ frame->local = NULL;
+ inode = local->loc.inode;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_mkdir_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.stat, &stbuf);
+
+ ret = inode_ctx_put2 (inode, frame->this,
+ stbuf.ia_ino, stbuf.ia_gen);
+ if (ret < 0) {
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "MKDIR %"PRId64"/%s (%s): failed to set "
+ "remote inode number to inode ctx",
+ local->loc.parent->ino, local->loc.name,
+ local->loc.path);
+ }
+
+ gf_stat_to_iatt (&rsp.preparent, &preparent);
+ gf_stat_to_iatt (&rsp.postparent, &postparent);
+ }
+
+out:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT (mkdir, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), inode,
+ &stbuf, &preparent, &postparent);
+
+ if (local)
+ client_local_wipe (local);
+
+ return 0;
+}
+
+int
+client3_1_open_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ clnt_local_t *local = NULL;
+ clnt_conf_t *conf = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ call_frame_t *frame = NULL;
+ fd_t *fd = NULL;
+ ino_t ino = 0;
+ uint64_t gen = 0;
+ int ret = 0;
+ gfs3_open_rsp rsp = {0,};
+
+ frame = myframe;
+ local = frame->local;
+
+ if (local->op) {
+ local->op (req, iov, 1, myframe);
+ return 0;
+ }
+
+ frame->local = NULL;
+ conf = frame->this->private;
+ fd = local->fd;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_open_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ fdctx = GF_CALLOC (1, sizeof (*fdctx),
+ gf_client_mt_clnt_fdctx_t);
+ if (!fdctx) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOMEM;
+ goto out;
+ }
+
+ inode_ctx_get2 (fd->inode, frame->this, &ino, &gen);
+
+ fdctx->remote_fd = rsp.fd;
+ fdctx->inode = inode_ref (fd->inode);
+ fdctx->ino = ino;
+ fdctx->gen = gen;
+ fdctx->flags = local->flags;
+ fdctx->wbflags = local->wbflags;
+
+ INIT_LIST_HEAD (&fdctx->sfd_pos);
+
+ this_fd_set_ctx (fd, frame->this, &local->loc, fdctx);
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ list_add_tail (&fdctx->sfd_pos, &conf->saved_fds);
+ }
+ pthread_mutex_unlock (&conf->lock);
+ }
+
+out:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT (open, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), fd);
+
+ client_local_wipe (local);
+
+ return 0;
+}
+
+
+int
+client3_1_stat_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ gfs3_stat_rsp rsp = {0,};
+ call_frame_t *frame = NULL;
+ struct iatt iatt = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_stat_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.stat, &iatt);
+ }
+
+out:
+ STACK_UNWIND_STRICT (stat, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &iatt);
+
+ return 0;
+}
+
+int
+client3_1_readlink_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ gfs3_readlink_rsp rsp = {0,};
+ call_frame_t *frame = NULL;
+ struct iatt iatt = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_readlink_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.buf, &iatt);
+ }
+
+out:
+ STACK_UNWIND_STRICT (readlink, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), rsp.path, &iatt);
+
+ /* This is allocated by the libc while decoding RPC msg */
+ /* Hence no 'GF_FREE', but just 'free' */
+ if (rsp.path)
+ free (rsp.path);
+
+ return 0;
+}
+
+int
+client3_1_unlink_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gfs3_unlink_rsp rsp = {0,};
+ struct iatt preparent = {0,};
+ struct iatt postparent = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_unlink_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.preparent, &preparent);
+ gf_stat_to_iatt (&rsp.postparent, &postparent);
+ }
+
+out:
+ STACK_UNWIND_STRICT (unlink, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &preparent,
+ &postparent);
+
+ return 0;
+}
+
+int
+client3_1_rmdir_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ gfs3_rmdir_rsp rsp = {0,};
+ call_frame_t *frame = NULL;
+ struct iatt preparent = {0,};
+ struct iatt postparent = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_rmdir_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.preparent, &preparent);
+ gf_stat_to_iatt (&rsp.postparent, &postparent);
+ }
+
+out:
+ STACK_UNWIND_STRICT (rmdir, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &preparent,
+ &postparent);
+
+ return 0;
+}
+
+
+int
+client3_1_truncate_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ gfs3_truncate_rsp rsp = {0,};
+ call_frame_t *frame = NULL;
+ struct iatt prestat = {0,};
+ struct iatt poststat = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_truncate_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.prestat, &prestat);
+ gf_stat_to_iatt (&rsp.poststat, &poststat);
+ }
+
+out:
+ STACK_UNWIND_STRICT (truncate, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &prestat,
+ &poststat);
+
+ return 0;
+}
+
+
+int
+client3_1_statfs_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ gfs3_statfs_rsp rsp = {0,};
+ call_frame_t *frame = NULL;
+ struct statvfs statfs = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_statfs_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_statfs_to_statfs (&rsp.statfs, &statfs);
+ }
+
+out:
+ STACK_UNWIND_STRICT (statfs, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &statfs);
+
+ return 0;
+}
+
+
+int
+client3_1_writev_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ gfs3_write_rsp rsp = {0,};
+ call_frame_t *frame = NULL;
+ struct iatt prestat = {0,};
+ struct iatt poststat = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_truncate_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.prestat, &prestat);
+ gf_stat_to_iatt (&rsp.poststat, &poststat);
+ }
+
+out:
+ STACK_UNWIND_STRICT (writev, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &prestat,
+ &poststat);
+
+ return 0;
+}
+
+int
+client3_1_flush_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gf_common_rsp rsp = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_common_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+out:
+ STACK_UNWIND_STRICT (flush, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno));
+
+ return 0;
+}
+
+int
+client3_1_fsync_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ gfs3_fsync_rsp rsp = {0,};
+ call_frame_t *frame = NULL;
+ struct iatt prestat = {0,};
+ struct iatt poststat = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_truncate_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.prestat, &prestat);
+ gf_stat_to_iatt (&rsp.poststat, &poststat);
+ }
+
+out:
+ STACK_UNWIND_STRICT (fsync, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &prestat,
+ &poststat);
+
+ return 0;
+}
+
+int
+client3_1_setxattr_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gf_common_rsp rsp = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_common_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+out:
+ STACK_UNWIND_STRICT (setxattr, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno));
+
+ return 0;
+}
+
+int
+client3_1_getxattr_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ dict_t *dict = NULL;
+ char *buf = NULL;
+ int dict_len = 0;
+ int op_ret = 0;
+ int op_errno = 0;
+ gfs3_getxattr_rsp rsp = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ op_ret = -1;
+ op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_getxattr_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ op_ret = -1;
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ op_errno = gf_error_to_errno (rsp.op_errno);
+ op_ret = rsp.op_ret;
+ if (-1 != op_ret) {
+ op_ret = -1;
+ dict_len = rsp.dict.dict_len;
+
+ if (dict_len > 0) {
+ dict = dict_new();
+ buf = memdup (rsp.dict.dict_val, rsp.dict.dict_len);
+
+ GF_VALIDATE_OR_GOTO (frame->this->name, dict, out);
+ GF_VALIDATE_OR_GOTO (frame->this->name, buf, out);
+
+ ret = dict_unserialize (buf, dict_len, &dict);
+ if (ret < 0) {
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "failed to unserialize xattr dict");
+ op_errno = EINVAL;
+ goto out;
+ }
+ dict->extra_free = buf;
+ buf = NULL;
+ }
+ op_ret = 0;
+ }
+
+out:
+ STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict);
+
+ if (rsp.dict.dict_val) {
+ /* don't use GF_FREE, this memory was allocated by libc
+ */
+ free (rsp.dict.dict_val);
+ rsp.dict.dict_val = NULL;
+ }
+
+ if (buf)
+ GF_FREE (buf);
+
+ if (dict)
+ dict_unref (dict);
+
+ return 0;
+}
+
+int
+client3_1_fgetxattr_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ char *buf = NULL;
+ dict_t *dict = NULL;
+ gfs3_fgetxattr_rsp rsp = {0,};
+ int ret = 0;
+ int dict_len = 0;
+ int op_ret = 0;
+ int op_errno = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ op_ret = -1;
+ op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_fgetxattr_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ op_ret = -1;
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ op_errno = gf_error_to_errno (rsp.op_errno);
+ op_ret = rsp.op_ret;
+ if (-1 != op_ret) {
+ op_ret = -1;
+ dict_len = rsp.dict.dict_len;
+
+ if (dict_len > 0) {
+ dict = dict_new();
+ GF_VALIDATE_OR_GOTO (frame->this->name, dict, out);
+ buf = memdup (rsp.dict.dict_val, rsp.dict.dict_len);
+ GF_VALIDATE_OR_GOTO (frame->this->name, buf, out);
+
+ ret = dict_unserialize (buf, dict_len, &dict);
+ if (ret < 0) {
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "failed to unserialize xattr dict");
+ op_errno = EINVAL;
+ goto out;
+ }
+ dict->extra_free = buf;
+ buf = NULL;
+ }
+ op_ret = 0;
+ }
+out:
+ STACK_UNWIND_STRICT (fgetxattr, frame, op_ret, op_errno, dict);
+ if (rsp.dict.dict_val) {
+ /* don't use GF_FREE, this memory was allocated by libc
+ */
+ free (rsp.dict.dict_val);
+ rsp.dict.dict_val = NULL;
+ }
+
+ if (buf)
+ GF_FREE (buf);
+
+ if (dict)
+ dict_unref (dict);
+
+ return 0;
+}
+
+int
+client3_1_removexattr_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gf_common_rsp rsp = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_common_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+out:
+ STACK_UNWIND_STRICT (removexattr, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno));
+
+ return 0;
+}
+
+int
+client3_1_fsyncdir_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gf_common_rsp rsp = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_common_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+out:
+ STACK_UNWIND_STRICT (fsyncdir, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno));
+
+ return 0;
+}
+
+int
+client3_1_access_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gf_common_rsp rsp = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_common_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+out:
+ STACK_UNWIND_STRICT (access, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno));
+
+ return 0;
+}
+
+
+int
+client3_1_ftruncate_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ gfs3_ftruncate_rsp rsp = {0,};
+ call_frame_t *frame = NULL;
+ struct iatt prestat = {0,};
+ struct iatt poststat = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_ftruncate_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.prestat, &prestat);
+ gf_stat_to_iatt (&rsp.poststat, &poststat);
+ }
+
+out:
+ STACK_UNWIND_STRICT (ftruncate, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &prestat,
+ &poststat);
+
+ return 0;
+}
+
+int
+client3_1_fstat_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ gfs3_fstat_rsp rsp = {0,};
+ call_frame_t *frame = NULL;
+ struct iatt stat = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_fstat_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.stat, &stat);
+ }
+
+out:
+ STACK_UNWIND_STRICT (fstat, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &stat);
+
+ return 0;
+}
+
+
+int
+client3_1_inodelk_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gf_common_rsp rsp = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_common_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+out:
+ STACK_UNWIND_STRICT (inodelk, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno));
+
+ return 0;
+}
+
+int
+client3_1_finodelk_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gf_common_rsp rsp = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_common_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+out:
+ STACK_UNWIND_STRICT (finodelk, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno));
+
+ return 0;
+}
+
+int
+client3_1_entrylk_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gf_common_rsp rsp = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_common_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+out:
+
+ STACK_UNWIND_STRICT (entrylk, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno));
+
+ return 0;
+}
+
+int
+client3_1_fentrylk_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gf_common_rsp rsp = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_common_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+out:
+ STACK_UNWIND_STRICT (fentrylk, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno));
+
+ return 0;
+}
+
+int
+client3_1_xattrop_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ dict_t *dict = NULL;
+ char *buf = NULL;
+ gfs3_xattrop_rsp rsp = {0,};
+ int ret = 0;
+ int op_ret = 0;
+ int dict_len = 0;
+ int op_errno = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ op_ret = -1;
+ op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_xattrop_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ op_ret = -1;
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ op_ret = rsp.op_ret;
+ if (-1 != op_ret) {
+ op_ret = -1;
+ dict_len = rsp.dict.dict_len;
+
+ if (dict_len > 0) {
+ dict = dict_new();
+ GF_VALIDATE_OR_GOTO (frame->this->name, dict, out);
+
+ buf = memdup (rsp.dict.dict_val, rsp.dict.dict_len);
+ GF_VALIDATE_OR_GOTO (frame->this->name, buf, out);
+ op_ret = dict_unserialize (buf, dict_len, &dict);
+ if (op_ret < 0) {
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "failed to unserialize xattr dict");
+ op_errno = EINVAL;
+ goto out;
+ }
+ dict->extra_free = buf;
+ buf = NULL;
+ }
+ op_ret = 0;
+ }
+
+out:
+
+ STACK_UNWIND_STRICT (xattrop, frame, op_ret,
+ gf_error_to_errno (rsp.op_errno), dict);
+
+ if (rsp.dict.dict_val) {
+ /* don't use GF_FREE, this memory was allocated by libc
+ */
+ free (rsp.dict.dict_val);
+ rsp.dict.dict_val = NULL;
+ }
+
+ if (buf)
+ GF_FREE (buf);
+
+ if (dict)
+ dict_unref (dict);
+
+ return 0;
+}
+
+int
+client3_1_fxattrop_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ dict_t *dict = NULL;
+ char *buf = NULL;
+ gfs3_fxattrop_rsp rsp = {0,};
+ int ret = 0;
+ int op_ret = 0;
+ int dict_len = 0;
+ int op_errno = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ op_ret = -1;
+ op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_fxattrop_rsp (*iov, &rsp);
+ if (ret < 0) {
+ op_ret = -1;
+ op_errno = EINVAL;
+ gf_log ("", GF_LOG_ERROR, "error");
+ goto out;
+ }
+
+ op_ret = rsp.op_ret;
+ if (-1 != op_ret) {
+ op_ret = -1;
+ dict_len = rsp.dict.dict_len;
+
+ if (dict_len > 0) {
+ dict = dict_new();
+ GF_VALIDATE_OR_GOTO (frame->this->name, dict, out);
+
+ buf = memdup (rsp.dict.dict_val, rsp.dict.dict_len);
+ GF_VALIDATE_OR_GOTO (frame->this->name, buf, out);
+ op_ret = dict_unserialize (buf, dict_len, &dict);
+ if (op_ret < 0) {
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "failed to unserialize xattr dict");
+ op_errno = EINVAL;
+ goto out;
+ }
+ dict->extra_free = buf;
+ buf = NULL;
+ }
+ op_ret = 0;
+ }
+
+out:
+
+ STACK_UNWIND_STRICT (fxattrop, frame, op_ret,
+ gf_error_to_errno (rsp.op_errno), dict);
+
+ if (rsp.dict.dict_val) {
+ /* don't use GF_FREE, this memory was allocated by libc
+ */
+ free (rsp.dict.dict_val);
+ rsp.dict.dict_val = NULL;
+ }
+
+ if (buf)
+ GF_FREE (buf);
+
+ if (dict)
+ dict_unref (dict);
+
+ return 0;
+}
+
+int
+client3_1_fsetxattr_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gf_common_rsp rsp = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_common_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+out:
+ STACK_UNWIND_STRICT (fsetxattr, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno));
+
+ return 0;
+}
+
+int
+client3_1_fsetattr_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gfs3_fsetattr_rsp rsp = {0,};
+ struct iatt prestat = {0,};
+ struct iatt poststat = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+ ret = xdr_to_fsetattr_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.statpre, &prestat);
+ gf_stat_to_iatt (&rsp.statpost, &poststat);
+ }
+
+out:
+ STACK_UNWIND_STRICT (fsetattr, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &prestat,
+ &poststat);
+
+ return 0;
+}
+
+
+int
+client3_1_setattr_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gfs3_setattr_rsp rsp = {0,};
+ struct iatt prestat = {0,};
+ struct iatt poststat = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_setattr_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.statpre, &prestat);
+ gf_stat_to_iatt (&rsp.statpost, &poststat);
+ }
+
+out:
+ STACK_UNWIND_STRICT (setattr, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &prestat,
+ &poststat);
+
+ return 0;
+}
+
+int
+client3_1_create_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ fd_t *fd = NULL;
+ inode_t *inode = NULL;
+ struct iatt stbuf = {0, };
+ struct iatt preparent = {0, };
+ struct iatt postparent = {0, };
+ int32_t ret = -1;
+ clnt_local_t *local = NULL;
+ clnt_conf_t *conf = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ gfs3_create_rsp rsp = {0,};
+
+ frame = myframe;
+ local = frame->local; frame->local = NULL;
+ conf = frame->this->private;
+ fd = local->fd;
+ inode = local->loc.inode;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_create_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.stat, &stbuf);
+
+ ret = inode_ctx_put2 (inode, frame->this,
+ stbuf.ia_ino, stbuf.ia_gen);
+ if (ret < 0) {
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "CREATE %"PRId64"/%s (%s): failed to set "
+ "remote inode number to inode ctx",
+ local->loc.parent->ino, local->loc.name,
+ local->loc.path);
+ }
+
+ gf_stat_to_iatt (&rsp.preparent, &preparent);
+ gf_stat_to_iatt (&rsp.postparent, &postparent);
+
+ fdctx = GF_CALLOC (1, sizeof (*fdctx),
+ gf_client_mt_clnt_fdctx_t);
+ if (!fdctx) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOMEM;
+ goto out;
+ }
+
+ fdctx->remote_fd = rsp.fd;
+ fdctx->inode = inode_ref (inode);
+ fdctx->ino = stbuf.ia_ino;
+ fdctx->gen = stbuf.ia_gen;
+ fdctx->flags = local->flags;
+
+ INIT_LIST_HEAD (&fdctx->sfd_pos);
+
+ this_fd_set_ctx (fd, frame->this, &local->loc, fdctx);
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ list_add_tail (&fdctx->sfd_pos, &conf->saved_fds);
+ }
+ pthread_mutex_unlock (&conf->lock);
+ }
+
+out:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT (create, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), fd, inode,
+ &stbuf, &preparent, &postparent);
+
+ client_local_wipe (local);
+ return 0;
+}
+
+
+int
+client3_1_rchecksum_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gfs3_rchecksum_rsp rsp = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_rchecksum_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+out:
+ STACK_UNWIND_STRICT (rchecksum, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno),
+ rsp.weak_checksum,
+ (uint8_t *)rsp.strong_checksum.strong_checksum_val);
+
+ if (rsp.strong_checksum.strong_checksum_val) {
+ /* This is allocated by the libc while decoding RPC msg */
+ /* Hence no 'GF_FREE', but just 'free' */
+ free (rsp.strong_checksum.strong_checksum_val);
+ }
+
+ return 0;
+}
+
+int
+client3_1_checksum_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gfs3_checksum_rsp rsp = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_checksum_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+out:
+ STACK_UNWIND_STRICT (checksum, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno),
+ (uint8_t *)rsp.fchecksum.fchecksum_val,
+ (uint8_t *)rsp.dchecksum.dchecksum_val);
+
+ /* This is allocated by the libc while decoding RPC msg */
+ /* Hence no 'GF_FREE', but just 'free' */
+ if (rsp.fchecksum.fchecksum_val) {
+ free (rsp.fchecksum.fchecksum_val);
+ }
+ if (rsp.dchecksum.dchecksum_val) {
+ free (rsp.dchecksum.dchecksum_val);
+ }
+ return 0;
+}
+
+int
+client3_1_lk_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ struct flock lock = {0,};
+ gfs3_lk_rsp rsp = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_lk_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (rsp.op_ret >= 0) {
+ gf_flock_to_flock (&rsp.flock, &lock);
+ }
+
+out:
+ STACK_UNWIND_STRICT (lk, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &lock);
+
+ return 0;
+}
+
+int
+client3_1_readdir_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gfs3_readdir_rsp rsp = {0,};
+ int32_t ret = 0;
+ gf_dirent_t entries;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_readdir_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ INIT_LIST_HEAD (&entries.list);
+ if (rsp.op_ret > 0) {
+ gf_dirent_unserialize (&entries, rsp.buf.buf_val,
+ rsp.buf.buf_len);
+ }
+
+out:
+ STACK_UNWIND_STRICT (readdir, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &entries);
+
+ if (rsp.op_ret != -1) {
+ gf_dirent_free (&entries);
+ }
+
+ /* This is allocated by the libc while decoding RPC msg */
+ /* Hence no 'GF_FREE', but just 'free' */
+ if (rsp.buf.buf_val)
+ free (rsp.buf.buf_val);
+
+ return 0;
+}
+
+
+int
+client3_1_readdirp_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gfs3_readdirp_rsp rsp = {0,};
+ int32_t ret = 0;
+ gf_dirent_t entries;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_readdirp_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ INIT_LIST_HEAD (&entries.list);
+ if (rsp.op_ret > 0) {
+ gf_dirent_unserialize (&entries, rsp.buf.buf_val,
+ rsp.buf.buf_len);
+ }
+
+out:
+ STACK_UNWIND_STRICT (readdirp, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &entries);
+
+ if (rsp.op_ret != -1) {
+ gf_dirent_free (&entries);
+ }
+
+ if (rsp.buf.buf_val) {
+ /* don't use GF_FREE as this memory was allocated by libc */
+ free (rsp.buf.buf_val);
+ }
+
+ return 0;
+}
+
+
+int
+client3_1_rename_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gfs3_rename_rsp rsp = {0,};
+ struct iatt stbuf = {0,};
+ struct iatt preoldparent = {0,};
+ struct iatt postoldparent = {0,};
+ struct iatt prenewparent = {0,};
+ struct iatt postnewparent = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_rename_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.stat, &stbuf);
+
+ gf_stat_to_iatt (&rsp.preoldparent, &preoldparent);
+ gf_stat_to_iatt (&rsp.postoldparent, &postoldparent);
+
+ gf_stat_to_iatt (&rsp.prenewparent, &prenewparent);
+ gf_stat_to_iatt (&rsp.postnewparent, &postnewparent);
+ }
+
+out:
+ STACK_UNWIND_STRICT (rename, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno),
+ &stbuf, &preoldparent, &postoldparent,
+ &preoldparent, &postoldparent);
+
+ return 0;
+}
+
+int
+client3_1_link_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ gfs3_link_rsp rsp = {0,};
+ struct iatt stbuf = {0,};
+ struct iatt preparent = {0,};
+ struct iatt postparent = {0,};
+ int ret = 0;
+ clnt_local_t *local = NULL;
+ inode_t *inode = NULL;
+
+ frame = myframe;
+
+ local = frame->local;
+ frame->local = NULL;
+ inode = local->loc.inode;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_link_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ gf_stat_to_iatt (&rsp.stat, &stbuf);
+
+ gf_stat_to_iatt (&rsp.preparent, &preparent);
+ gf_stat_to_iatt (&rsp.postparent, &postparent);
+ }
+
+out:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT (link, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), inode,
+ &stbuf, &preparent, &postparent);
+
+ client_local_wipe (local);
+ return 0;
+}
+
+
+int
+client3_1_opendir_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ clnt_local_t *local = NULL;
+ clnt_conf_t *conf = NULL;
+ clnt_fd_ctx_t *fdctx = NULL;
+ ino_t ino = 0;
+ uint64_t gen = 0;
+ call_frame_t *frame = NULL;
+ fd_t *fd = NULL;
+ int ret = 0;
+ gfs3_opendir_rsp rsp = {0,};
+
+ frame = myframe;
+ local = frame->local;
+
+ if (local->op) {
+ local->op (req, iov, 1, myframe);
+ return 0;
+ }
+
+ frame->local = NULL;
+ conf = frame->this->private;
+ fd = local->fd;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_opendir_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (-1 != rsp.op_ret) {
+ fdctx = GF_CALLOC (1, sizeof (*fdctx),
+ gf_client_mt_clnt_fdctx_t);
+ if (!fdctx) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOMEM;
+ goto out;
+ }
+
+ inode_ctx_get2 (fd->inode, frame->this, &ino, &gen);
+
+ fdctx->remote_fd = rsp.fd;
+ fdctx->inode = inode_ref (fd->inode);
+ fdctx->ino = ino;
+ fdctx->gen = gen;
+
+ fdctx->is_dir = 1;
+
+ INIT_LIST_HEAD (&fdctx->sfd_pos);
+
+ this_fd_set_ctx (fd, frame->this, &local->loc, fdctx);
+
+ pthread_mutex_lock (&conf->lock);
+ {
+ list_add_tail (&fdctx->sfd_pos, &conf->saved_fds);
+ }
+ pthread_mutex_unlock (&conf->lock);
+ }
+
+out:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT (opendir, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), fd);
+
+ client_local_wipe (local);
+
+ return 0;
+}
+
+
+int
+client3_1_lookup_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ clnt_local_t *local = NULL;
+ call_frame_t *frame = NULL;
+ int ret = 0;
+ gfs3_lookup_rsp rsp = {0,};
+ struct iatt stbuf = {0,};
+ struct iatt postparent = {0,};
+ int op_errno = 0;
+ ino_t oldino = 0;
+ uint64_t oldgen = 0;
+ dict_t *xattr = NULL;
+ inode_t *inode = NULL;
+ char *buf = NULL;
+
+ frame = myframe;
+ local = frame->local;
+ inode = local->loc.inode;
+ frame->local = NULL;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_lookup_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ op_errno = gf_error_to_errno (rsp.op_errno);
+ gf_stat_to_iatt (&rsp.postparent, &postparent);
+
+ if (rsp.op_ret == 0) {
+ rsp.op_ret = -1;
+ gf_stat_to_iatt (&rsp.stat, &stbuf);
+
+ ret = inode_ctx_get2 (inode, frame->this, &oldino, &oldgen);
+ if (oldino != stbuf.ia_ino || oldgen != stbuf.ia_gen) {
+ if (oldino) {
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "LOOKUP %"PRId64"/%s (%s): "
+ "inode number changed from "
+ "{%"PRId64",%"PRId64"} to {%"PRId64",%"PRId64"}",
+ local->loc.parent ?
+ local->loc.parent->ino : (uint64_t) 0,
+ local->loc.name,
+ local->loc.path,
+ oldgen, oldino, stbuf.ia_gen, stbuf.ia_ino);
+ op_errno = ESTALE;
+ goto out;
+ }
+
+ ret = inode_ctx_put2 (inode, frame->this,
+ stbuf.ia_ino, stbuf.ia_gen);
+ if (ret < 0) {
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "LOOKUP %"PRId64"/%s (%s) : "
+ "failed to set remote inode "
+ "number to inode ctx",
+ local->loc.parent ?
+ local->loc.parent->ino : (uint64_t) 0,
+ local->loc.name,
+ local->loc.path);
+ }
+ }
+
+ if (rsp.dict.dict_len > 0) {
+ xattr = dict_new();
+ GF_VALIDATE_OR_GOTO (frame->this->name, xattr, out);
+
+ buf = memdup (rsp.dict.dict_val, rsp.dict.dict_len);
+ GF_VALIDATE_OR_GOTO (frame->this->name, buf, out);
+
+ ret = dict_unserialize (buf, rsp.dict.dict_len, &xattr);
+ if (ret < 0) {
+ gf_log (frame->this->name, GF_LOG_DEBUG,
+ "%s (%"PRId64"): failed to "
+ "unserialize dictionary",
+ local->loc.path, inode->ino);
+ op_errno = EINVAL;
+ goto out;
+ }
+
+ xattr->extra_free = buf;
+ buf = NULL;
+ }
+
+ rsp.op_ret = 0;
+ }
+
+out:
+ frame->local = NULL;
+ STACK_UNWIND_STRICT (lookup, frame, rsp.op_ret, rsp.op_errno, inode,
+ &stbuf, xattr, &postparent);
+
+ client_local_wipe (local);
+
+ if (xattr)
+ dict_unref (xattr);
+
+ if (rsp.dict.dict_val) {
+ /* don't use GF_FREE, this memory was allocated by libc
+ */
+ free (rsp.dict.dict_val);
+ rsp.dict.dict_val = NULL;
+ }
+
+ if (buf) {
+ GF_FREE (buf);
+ }
+
+ return 0;
+}
+
+int
+client3_1_readv_cbk (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe)
+{
+ call_frame_t *frame = NULL;
+ struct iobref *iobref = NULL;
+ struct iovec vector = {0,};
+ struct iatt stat = {0,};
+ gfs3_read_rsp rsp = {0,};
+ int ret = 0;
+
+ frame = myframe;
+
+ if (-1 == req->rpc_status) {
+ rsp.op_ret = -1;
+ rsp.op_errno = ENOTCONN;
+ goto out;
+ }
+
+ ret = xdr_to_readv_rsp (*iov, &rsp);
+ if (ret < 0) {
+ gf_log ("", GF_LOG_ERROR, "error");
+ rsp.op_ret = -1;
+ rsp.op_errno = EINVAL;
+ goto out;
+ }
+
+ if (rsp.op_ret != -1) {
+ iobref = iobref_new ();
+ gf_stat_to_iatt (&rsp.stat, &stat);
+ vector.iov_len = rsp.op_ret;
+
+ if (rsp.op_ret > 0) {
+ vector.iov_base = req->rsp_procpayload->ptr;
+ iobref_add (iobref, req->rsp_procpayload);
+ }
+ }
+out:
+ STACK_UNWIND_STRICT (readv, frame, rsp.op_ret,
+ gf_error_to_errno (rsp.op_errno), &vector, 1,
+ &stat, iobref);
+
+ if (iobref) {
+ iobref_unref (iobref);
+ }
+
+ return 0;
+}
+
+/* Table Specific to FOPS */
+
+
+rpc_clnt_procedure_t clnt3_1_fop_actors[GF_FOP_MAXVALUE] = {
+ [GF_FOP_NULL] = {"NULL", NULL, NULL },
+ [GF_FOP_STAT] = { "STAT", client3_1_stat, client3_1_stat_cbk },
+ [GF_FOP_READLINK] = { "READLINK", client3_1_readlink, client3_1_readlink_cbk },
+ [GF_FOP_MKNOD] = { "MKNOD", client3_1_mknod, client3_1_mknod_cbk },
+ [GF_FOP_MKDIR] = { "MKDIR", client3_1_mkdir, client3_1_mkdir_cbk },
+ [GF_FOP_UNLINK] = { "UNLINK", client3_1_unlink, client3_1_unlink_cbk },
+ [GF_FOP_RMDIR] = { "RMDIR", client3_1_rmdir, client3_1_rmdir_cbk },
+ [GF_FOP_SYMLINK] = { "SYMLINK", client3_1_symlink, client3_1_symlink_cbk },
+ [GF_FOP_RENAME] = { "RENAME", client3_1_rename, client3_1_rename_cbk },
+ [GF_FOP_LINK] = { "LINK", client3_1_link, client3_1_link_cbk },
+ [GF_FOP_TRUNCATE] = { "TRUNCATE", client3_1_truncate, client3_1_truncate_cbk },
+ [GF_FOP_OPEN] = { "OPEN", client3_1_open, client3_1_open_cbk },
+ [GF_FOP_READ] = { "READ", client3_1_readv, client3_1_readv_cbk },
+ [GF_FOP_WRITE] = { "WRITE", client3_1_writev, client3_1_writev_cbk },
+ [GF_FOP_STATFS] = { "STATFS", client3_1_statfs, client3_1_statfs_cbk },
+ [GF_FOP_FLUSH] = { "FLUSH", client3_1_flush, client3_1_flush_cbk },
+ [GF_FOP_FSYNC] = { "FSYNC", client3_1_fsync, client3_1_fsync_cbk },
+ [GF_FOP_SETXATTR] = { "SETXATTR", client3_1_setxattr, client3_1_setxattr_cbk },
+ [GF_FOP_GETXATTR] = { "GETXATTR", client3_1_getxattr, client3_1_getxattr_cbk },
+ [GF_FOP_REMOVEXATTR] = { "REMOVEXATTR", client3_1_removexattr, client3_1_removexattr_cbk },
+ [GF_FOP_OPENDIR] = { "OPENDIR", client3_1_opendir, client3_1_opendir_cbk },
+ [GF_FOP_FSYNCDIR] = { "FSYNCDIR", client3_1_fsyncdir, client3_1_fsyncdir_cbk },
+ [GF_FOP_ACCESS] = { "ACCESS", client3_1_access, client3_1_access_cbk },
+ [GF_FOP_CREATE] = { "CREATE", client3_1_create, client3_1_create_cbk },
+ [GF_FOP_FTRUNCATE] = { "FTRUNCATE", client3_1_ftruncate, client3_1_ftruncate_cbk },
+ [GF_FOP_FSTAT] = { "FSTAT", client3_1_fstat, client3_1_fstat_cbk },
+ [GF_FOP_LK] = { "LK", client3_1_lk, client3_1_lk_cbk },
+ [GF_FOP_LOOKUP] = { "LOOKUP", client3_1_lookup, client3_1_lookup_cbk },
+ [GF_FOP_READDIR] = { "READDIR", client3_1_readdir, client3_1_readdir_cbk },
+ [GF_FOP_INODELK] = { "INODELK", client3_1_inodelk, client3_1_inodelk_cbk },
+ [GF_FOP_FINODELK] = { "FINODELK", client3_1_finodelk, client3_1_finodelk_cbk },
+ [GF_FOP_ENTRYLK] = { "ENTRYLK", client3_1_entrylk, client3_1_entrylk_cbk },
+ [GF_FOP_FENTRYLK] = { "FENTRYLK", client3_1_fentrylk, client3_1_fentrylk_cbk },
+ [GF_FOP_CHECKSUM] = { "CHECKSUM", client3_1_checksum, client3_1_checksum_cbk },
+ [GF_FOP_XATTROP] = { "XATTROP", client3_1_xattrop, client3_1_xattrop_cbk },
+ [GF_FOP_FXATTROP] = { "FXATTROP", client3_1_fxattrop, client3_1_fxattrop_cbk },
+ [GF_FOP_FGETXATTR] = { "FGETXATTR", client3_1_fgetxattr, client3_1_fgetxattr_cbk },
+ [GF_FOP_FSETXATTR] = { "FSETXATTR", client3_1_fsetxattr, client3_1_fsetxattr_cbk },
+ [GF_FOP_RCHECKSUM] = { "RCHECKSUM", client3_1_rchecksum, client3_1_rchecksum_cbk },
+ [GF_FOP_SETATTR] = { "SETATTR", client3_1_setattr, client3_1_setattr_cbk },
+ [GF_FOP_FSETATTR] = { "FSETATTR", client3_1_fsetattr, client3_1_fsetattr_cbk },
+ [GF_FOP_READDIRP] = { "READDIRP", client3_1_readdirp, client3_1_readdirp_cbk },
+ [GF_FOP_FORGET] = { "FORGET", NULL, client3_1_release_cbk },
+ [GF_FOP_RELEASE] = { "RELEASE", client3_1_release, client3_1_release_cbk },
+ [GF_FOP_RELEASEDIR] = { "RELEASEDIR", client3_1_releasedir, client3_1_releasedir_cbk },
+// [GF_FOP_GETSPEC] = { "GETSPEC", client_getspec, client_getspec_cbk },
+};
+
+rpc_clnt_prog_t clnt3_1_fop_prog = {
+ .progname = "GlusterFS 3.1",
+ .prognum = GLUSTER3_1_FOP_PROGRAM,
+ .progver = GLUSTER3_1_FOP_VERSION,
+ .numproc = GLUSTER3_1_FOP_PROCCNT,
+ .actor = clnt3_1_fop_actors,
+};
+
+rpc_clnt_procedure_t clnt3_1_mgmt_actors[] = {
+ {0,}
+};
+
+rpc_clnt_prog_t clnt3_1_mgmt_prog = {
+ .progname = "Mgmt 3.1",
+ .prognum = GLUSTER1_MGMT_PROGRAM,
+ .progver = GLUSTER1_MGMT_VERSION,
+ .actor = clnt3_1_mgmt_actors,
+ .numproc = (sizeof (*clnt3_1_mgmt_actors) /
+ sizeof (rpc_clnt_procedure_t)),
+};
diff --git a/xlators/protocol/lib/Makefile.am b/xlators/protocol/lib/Makefile.am
index d471a3f..af437a6 100644
--- a/xlators/protocol/lib/Makefile.am
+++ b/xlators/protocol/lib/Makefile.am
@@ -1,3 +1 @@
SUBDIRS = src
-
-CLEANFILES =
diff --git a/xlators/protocol/lib/src/Makefile.am b/xlators/protocol/lib/src/Makefile.am
index 6e0b5c4..ece59ef 100644
--- a/xlators/protocol/lib/src/Makefile.am
+++ b/xlators/protocol/lib/src/Makefile.am
@@ -3,12 +3,13 @@ lib_LTLIBRARIES = libgfproto1.la
libgfproto1_la_CFLAGS = -fPIC -Wall -g -shared -nostartfiles $(GF_CFLAGS) $(GF_DARWIN_LIBGLUSTERFS_CFLAGS)
libgfproto1_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 -D_GNU_SOURCE \
- -D$(GF_HOST_OS) -DLIBDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/auth\" \
- -DTRANSPORTDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/transport\" \
- -I$(CONTRIBDIR)/rbtree -I$(top_srcdir)/libglusterfs/src/
+ -D$(GF_HOST_OS) -DLIBDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/auth\" \
+ -DTRANSPORTDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/transport\" \
+ -I$(CONTRIBDIR)/rbtree -I$(top_srcdir)/libglusterfs/src/ \
+ -I$(top_srcdir)/xlators/protocol/rpc/rpc-lib/src/
libgfproto1_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
-libgfproto1_la_SOURCES = authenticate.c
+libgfproto1_la_SOURCES = authenticate.c protocol-common.c msg-xdr.c glusterfs-xdr.c
-noinst_HEADERS = authenticate.h
+noinst_HEADERS = authenticate.h protocol-common.h msg-xdr.h glusterfs-xdr.h
diff --git a/xlators/protocol/lib/src/authenticate.c b/xlators/protocol/lib/src/authenticate.c
index ff2b581..5205b54 100644
--- a/xlators/protocol/lib/src/authenticate.c
+++ b/xlators/protocol/lib/src/authenticate.c
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2007-2009 Gluster, Inc. <http://www.gluster.com>
+ Copyright (c) 2007-2010 Gluster, Inc. <http://www.gluster.com>
This file is part of GlusterFS.
GlusterFS is free software; you can redistribute it and/or modify
@@ -68,7 +68,7 @@ init (dict_t *this,
handle = dlopen (auth_file, RTLD_LAZY);
if (!handle) {
- gf_log ("authenticate", GF_LOG_ERROR, "dlopen(%s): %s\n",
+ gf_log ("authenticate", GF_LOG_ERROR, "dlopen(%s): %s\n",
auth_file, dlerror ());
dict_set (this, key, data_from_dynptr (NULL, 0));
GF_FREE (auth_file);
@@ -76,7 +76,7 @@ init (dict_t *this,
return;
}
GF_FREE (auth_file);
-
+
authenticate = dlsym (handle, "gf_auth");
if (!authenticate) {
gf_log ("authenticate", GF_LOG_ERROR,
@@ -100,12 +100,12 @@ init (dict_t *this,
if (auth_handle->vol_opt->given_opt == NULL) {
gf_log ("authenticate", GF_LOG_DEBUG,
"volume option validation not specified");
- }
+ }
auth_handle->authenticate = authenticate;
auth_handle->handle = handle;
- dict_set (this, key,
+ dict_set (this, key,
data_from_dynptr (auth_handle, sizeof (*auth_handle)));
}
@@ -133,10 +133,10 @@ gf_auth_init (xlator_t *xl, dict_t *auth_modules)
while (pair) {
handle = data_to_ptr (pair->value);
if (handle) {
- list_add_tail (&(handle->vol_opt->list),
+ list_add_tail (&(handle->vol_opt->list),
&(xl->volume_options));
- if (-1 ==
- validate_xlator_volume_options (xl,
+ if (-1 ==
+ validate_xlator_volume_options (xl,
handle->vol_opt->given_opt)) {
gf_log ("authenticate", GF_LOG_ERROR,
"volume option validation "
@@ -158,7 +158,7 @@ gf_auth_init (xlator_t *xl, dict_t *auth_modules)
static dict_t *__input_params;
static dict_t *__config_params;
-void
+void
map (dict_t *this,
char *key,
data_t *value,
@@ -168,17 +168,17 @@ map (dict_t *this,
auth_fn_t authenticate;
auth_handle_t *handle = NULL;
- if (value && (handle = data_to_ptr (value)) &&
+ if (value && (handle = data_to_ptr (value)) &&
(authenticate = handle->authenticate)) {
- dict_set (res, key,
- int_to_data (authenticate (__input_params,
+ dict_set (res, key,
+ int_to_data (authenticate (__input_params,
__config_params)));
} else {
dict_set (res, key, int_to_data (AUTH_DONT_CARE));
}
}
-void
+void
reduce (dict_t *this,
char *key,
data_t *value,
@@ -206,11 +206,11 @@ reduce (dict_t *this,
}
}
-
-auth_result_t
-gf_authenticate (dict_t *input_params,
- dict_t *config_params,
- dict_t *auth_modules)
+
+auth_result_t
+gf_authenticate (dict_t *input_params,
+ dict_t *config_params,
+ dict_t *auth_modules)
{
dict_t *results = NULL;
int64_t result = AUTH_DONT_CARE;
@@ -235,12 +235,12 @@ gf_authenticate (dict_t *input_params,
"accepting remote-client %s", name);
result = AUTH_REJECT;
}
-
+
dict_destroy (results);
return result;
}
-void
+void
gf_auth_fini (dict_t *auth_modules)
{
int32_t dummy;
diff --git a/xlators/protocol/lib/src/authenticate.h b/xlators/protocol/lib/src/authenticate.h
index e777146..93d7374 100644
--- a/xlators/protocol/lib/src/authenticate.h
+++ b/xlators/protocol/lib/src/authenticate.h
@@ -42,7 +42,7 @@ typedef enum {
AUTH_DONT_CARE
} auth_result_t;
-typedef auth_result_t (*auth_fn_t) (dict_t *input_params,
+typedef auth_result_t (*auth_fn_t) (dict_t *input_params,
dict_t *config_params);
typedef struct {
@@ -51,8 +51,8 @@ typedef struct {
volume_opt_list_t *vol_opt;
} auth_handle_t;
-auth_result_t gf_authenticate (dict_t *input_params,
- dict_t *config_params,
+auth_result_t gf_authenticate (dict_t *input_params,
+ dict_t *config_params,
dict_t *auth_modules);
int32_t gf_auth_init (xlator_t *xl, dict_t *auth_modules);
void gf_auth_fini (dict_t *auth_modules);
diff --git a/xlators/protocol/lib/src/glusterfs-xdr.c b/xlators/protocol/lib/src/glusterfs-xdr.c
new file mode 100644
index 0000000..2eccff2
--- /dev/null
+++ b/xlators/protocol/lib/src/glusterfs-xdr.c
@@ -0,0 +1,1847 @@
+/*
+ * Please do not edit this file.
+ * It was generated using rpcgen.
+ */
+
+#include "glusterfs-xdr.h"
+#include "iatt.h"
+
+bool_t
+xdr_gf_statfs (XDR *xdrs, gf_statfs *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->bsize))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->frsize))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->blocks))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->bfree))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->bavail))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->files))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ffree))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->favail))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->fsid))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->flag))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->namemax))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gf_flock (XDR *xdrs, gf_flock *objp)
+{
+
+ if (!xdr_u_int (xdrs, &objp->type))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->whence))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->start))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->len))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->pid))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gf_iatt (XDR *xdrs, gf_iatt *objp)
+{
+ register int32_t *buf;
+
+ if (xdrs->x_op == XDR_ENCODE) {
+ if (!xdr_u_quad_t (xdrs, &objp->ia_ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ia_gen))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ia_dev))
+ return FALSE;
+ buf = XDR_INLINE (xdrs, 4 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_u_int (xdrs, &objp->mode))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_nlink))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_uid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_gid))
+ return FALSE;
+
+ } else {
+ IXDR_PUT_U_LONG(buf, objp->mode);
+ IXDR_PUT_U_LONG(buf, objp->ia_nlink);
+ IXDR_PUT_U_LONG(buf, objp->ia_uid);
+ IXDR_PUT_U_LONG(buf, objp->ia_gid);
+ }
+ if (!xdr_u_quad_t (xdrs, &objp->ia_rdev))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ia_size))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_blksize))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ia_blocks))
+ return FALSE;
+ buf = XDR_INLINE (xdrs, 6 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_u_int (xdrs, &objp->ia_atime))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_atime_nsec))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_mtime))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_mtime_nsec))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_ctime))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_ctime_nsec))
+ return FALSE;
+ } else {
+ IXDR_PUT_U_LONG(buf, objp->ia_atime);
+ IXDR_PUT_U_LONG(buf, objp->ia_atime_nsec);
+ IXDR_PUT_U_LONG(buf, objp->ia_mtime);
+ IXDR_PUT_U_LONG(buf, objp->ia_mtime_nsec);
+ IXDR_PUT_U_LONG(buf, objp->ia_ctime);
+ IXDR_PUT_U_LONG(buf, objp->ia_ctime_nsec);
+ }
+ return TRUE;
+ } else if (xdrs->x_op == XDR_DECODE) {
+ if (!xdr_u_quad_t (xdrs, &objp->ia_ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ia_gen))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ia_dev))
+ return FALSE;
+ buf = XDR_INLINE (xdrs, 4 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_u_int (xdrs, &objp->mode))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_nlink))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_uid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_gid))
+ return FALSE;
+
+ } else {
+ objp->mode = IXDR_GET_U_LONG(buf);
+ objp->ia_nlink = IXDR_GET_U_LONG(buf);
+ objp->ia_uid = IXDR_GET_U_LONG(buf);
+ objp->ia_gid = IXDR_GET_U_LONG(buf);
+ }
+ if (!xdr_u_quad_t (xdrs, &objp->ia_rdev))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ia_size))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_blksize))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ia_blocks))
+ return FALSE;
+ buf = XDR_INLINE (xdrs, 6 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_u_int (xdrs, &objp->ia_atime))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_atime_nsec))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_mtime))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_mtime_nsec))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_ctime))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_ctime_nsec))
+ return FALSE;
+ } else {
+ objp->ia_atime = IXDR_GET_U_LONG(buf);
+ objp->ia_atime_nsec = IXDR_GET_U_LONG(buf);
+ objp->ia_mtime = IXDR_GET_U_LONG(buf);
+ objp->ia_mtime_nsec = IXDR_GET_U_LONG(buf);
+ objp->ia_ctime = IXDR_GET_U_LONG(buf);
+ objp->ia_ctime_nsec = IXDR_GET_U_LONG(buf);
+ }
+ return TRUE;
+ }
+
+ if (!xdr_u_quad_t (xdrs, &objp->ia_ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ia_gen))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ia_dev))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->mode))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_nlink))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_uid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_gid))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ia_rdev))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ia_size))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_blksize))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ia_blocks))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_atime))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_atime_nsec))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_mtime))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_mtime_nsec))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_ctime))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ia_ctime_nsec))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_stat_req (XDR *xdrs, gfs3_stat_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_stat_rsp (XDR *xdrs, gfs3_stat_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->stat))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_readlink_req (XDR *xdrs, gfs3_readlink_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->size))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_readlink_rsp (XDR *xdrs, gfs3_readlink_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->buf))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_mknod_req (XDR *xdrs, gfs3_mknod_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->par))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->dev))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->mode))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->bname, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_mknod_rsp (XDR *xdrs, gfs3_mknod_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->stat))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->preparent))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->postparent))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_mkdir_req (XDR *xdrs, gfs3_mkdir_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->par))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->mode))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->bname, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_mkdir_rsp (XDR *xdrs, gfs3_mkdir_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->stat))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->preparent))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->postparent))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_unlink_req (XDR *xdrs, gfs3_unlink_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->par))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->bname, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_unlink_rsp (XDR *xdrs, gfs3_unlink_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->preparent))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->postparent))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_rmdir_req (XDR *xdrs, gfs3_rmdir_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->par))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->bname, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_rmdir_rsp (XDR *xdrs, gfs3_rmdir_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->preparent))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->postparent))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_symlink_req (XDR *xdrs, gfs3_symlink_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->par))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->bname, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->linkname, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_symlink_rsp (XDR *xdrs, gfs3_symlink_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->stat))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->preparent))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->postparent))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_rename_req (XDR *xdrs, gfs3_rename_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->oldpar))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->oldgen))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->newpar))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->newgen))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->oldpath, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->oldbname, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->newpath, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->newbname, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_rename_rsp (XDR *xdrs, gfs3_rename_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->stat))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->preoldparent))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->postoldparent))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->prenewparent))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->postnewparent))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_link_req (XDR *xdrs, gfs3_link_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->oldino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->oldgen))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->newpar))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->newgen))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->oldpath, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->newpath, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->newbname, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_link_rsp (XDR *xdrs, gfs3_link_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->stat))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->preparent))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->postparent))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_truncate_req (XDR *xdrs, gfs3_truncate_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->offset))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_truncate_rsp (XDR *xdrs, gfs3_truncate_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->prestat))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->poststat))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_open_req (XDR *xdrs, gfs3_open_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->flags))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->wbflags))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_open_rsp (XDR *xdrs, gfs3_open_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_read_req (XDR *xdrs, gfs3_read_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->offset))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->size))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_read_rsp (XDR *xdrs, gfs3_read_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->stat))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->size))
+ return FALSE;
+
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_lookup_req (XDR *xdrs, gfs3_lookup_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->par))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->flags))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->bname, ~0))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val,
+ (u_int *) &objp->dict.dict_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_lookup_rsp (XDR *xdrs, gfs3_lookup_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->stat))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->postparent))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val,
+ (u_int *) &objp->dict.dict_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_write_req (XDR *xdrs, gfs3_write_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->offset))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->size))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_write_rsp (XDR *xdrs, gfs3_write_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->prestat))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->poststat))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_statfs_req (XDR *xdrs, gfs3_statfs_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_statfs_rsp (XDR *xdrs, gfs3_statfs_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_statfs (xdrs, &objp->statfs))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_lk_req (XDR *xdrs, gfs3_lk_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->cmd))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->type))
+ return FALSE;
+ if (!xdr_gf_flock (xdrs, &objp->flock))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_lk_rsp (XDR *xdrs, gfs3_lk_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_flock (xdrs, &objp->flock))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_inodelk_req (XDR *xdrs, gfs3_inodelk_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->cmd))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->type))
+ return FALSE;
+ if (!xdr_gf_flock (xdrs, &objp->flock))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->volume, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_finodelk_req (XDR *xdrs, gfs3_finodelk_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->cmd))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->type))
+ return FALSE;
+ if (!xdr_gf_flock (xdrs, &objp->flock))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->volume, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_flush_req (XDR *xdrs, gfs3_flush_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_fsync_req (XDR *xdrs, gfs3_fsync_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->data))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_fsync_rsp (XDR *xdrs, gfs3_fsync_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->prestat))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->poststat))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_setxattr_req (XDR *xdrs, gfs3_setxattr_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->flags))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_fsetxattr_req (XDR *xdrs, gfs3_fsetxattr_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->flags))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_xattrop_req (XDR *xdrs, gfs3_xattrop_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->flags))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_xattrop_rsp (XDR *xdrs, gfs3_xattrop_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_fxattrop_req (XDR *xdrs, gfs3_fxattrop_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->flags))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_fxattrop_rsp (XDR *xdrs, gfs3_fxattrop_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_getxattr_req (XDR *xdrs, gfs3_getxattr_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->namelen))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->name, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_getxattr_rsp (XDR *xdrs, gfs3_getxattr_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_fgetxattr_req (XDR *xdrs, gfs3_fgetxattr_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->namelen))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->name, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_fgetxattr_rsp (XDR *xdrs, gfs3_fgetxattr_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_removexattr_req (XDR *xdrs, gfs3_removexattr_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->name, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_opendir_req (XDR *xdrs, gfs3_opendir_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_opendir_rsp (XDR *xdrs, gfs3_opendir_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_fsyncdir_req (XDR *xdrs, gfs3_fsyncdir_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->data))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_readdir_req (XDR *xdrs, gfs3_readdir_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->offset))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->size))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_readdir_rsp (XDR *xdrs, gfs3_readdir_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->buf.buf_val, (u_int *) &objp->buf.buf_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_readdirp_req (XDR *xdrs, gfs3_readdirp_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->offset))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->size))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_readdirp_rsp (XDR *xdrs, gfs3_readdirp_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->buf.buf_val, (u_int *) &objp->buf.buf_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gf_setvolume_req (XDR *xdrs, gf_setvolume_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gf_setvolume_rsp (XDR *xdrs, gf_setvolume_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->dict.dict_val, (u_int *) &objp->dict.dict_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_access_req (XDR *xdrs, gfs3_access_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->mask))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_create_req (XDR *xdrs, gfs3_create_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->par))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->flags))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->mode))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->bname, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_create_rsp (XDR *xdrs, gfs3_create_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->stat))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->preparent))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->postparent))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_ftruncate_req (XDR *xdrs, gfs3_ftruncate_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->offset))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_ftruncate_rsp (XDR *xdrs, gfs3_ftruncate_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->prestat))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->poststat))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_fstat_req (XDR *xdrs, gfs3_fstat_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_fstat_rsp (XDR *xdrs, gfs3_fstat_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->stat))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_entrylk_req (XDR *xdrs, gfs3_entrylk_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->cmd))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->type))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->namelen))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->name, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->volume, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_fentrylk_req (XDR *xdrs, gfs3_fentrylk_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->cmd))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->type))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->namelen))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->name, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->volume, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_checksum_req (XDR *xdrs, gfs3_checksum_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->flag))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_checksum_rsp (XDR *xdrs, gfs3_checksum_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->fchecksum.fchecksum_val, (u_int *) &objp->fchecksum.fchecksum_len, ~0))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->dchecksum.dchecksum_val, (u_int *) &objp->dchecksum.dchecksum_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_setattr_req (XDR *xdrs, gfs3_setattr_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->stbuf))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->valid))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->path, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_setattr_rsp (XDR *xdrs, gfs3_setattr_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->statpre))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->statpost))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_fsetattr_req (XDR *xdrs, gfs3_fsetattr_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->stbuf))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->valid))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_fsetattr_rsp (XDR *xdrs, gfs3_fsetattr_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->statpre))
+ return FALSE;
+ if (!xdr_gf_iatt (xdrs, &objp->statpost))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_rchecksum_req (XDR *xdrs, gfs3_rchecksum_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->offset))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->len))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_rchecksum_rsp (XDR *xdrs, gfs3_rchecksum_rsp *objp)
+{
+ register int32_t *buf;
+
+
+ if (xdrs->x_op == XDR_ENCODE) {
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->weak_checksum))
+ return FALSE;
+
+ } else {
+ IXDR_PUT_LONG(buf, objp->op_ret);
+ IXDR_PUT_LONG(buf, objp->op_errno);
+ IXDR_PUT_U_LONG(buf, objp->weak_checksum);
+ }
+ if (!xdr_bytes (xdrs, (char **)&objp->strong_checksum.strong_checksum_val, (u_int *) &objp->strong_checksum.strong_checksum_len, ~0))
+ return FALSE;
+ return TRUE;
+ } else if (xdrs->x_op == XDR_DECODE) {
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->weak_checksum))
+ return FALSE;
+
+ } else {
+ objp->op_ret = IXDR_GET_LONG(buf);
+ objp->op_errno = IXDR_GET_LONG(buf);
+ objp->weak_checksum = IXDR_GET_U_LONG(buf);
+ }
+ if (!xdr_bytes (xdrs, (char **)&objp->strong_checksum.strong_checksum_val, (u_int *) &objp->strong_checksum.strong_checksum_len, ~0))
+ return FALSE;
+ return TRUE;
+ }
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->weak_checksum))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->strong_checksum.strong_checksum_val, (u_int *) &objp->strong_checksum.strong_checksum_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gf_getspec_req (XDR *xdrs, gf_getspec_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->flags))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->key, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gf_getspec_rsp (XDR *xdrs, gf_getspec_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->spec, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gf_log_req (XDR *xdrs, gf_log_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->msg.msg_val, (u_int *) &objp->msg.msg_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gf_notify_req (XDR *xdrs, gf_notify_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->flags))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->buf, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gf_notify_rsp (XDR *xdrs, gf_notify_rsp *objp)
+{
+ register int32_t *buf;
+
+ if (xdrs->x_op == XDR_ENCODE) {
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->flags))
+ return FALSE;
+
+ } else {
+ IXDR_PUT_LONG(buf, objp->op_ret);
+ IXDR_PUT_LONG(buf, objp->op_errno);
+ IXDR_PUT_U_LONG(buf, objp->flags);
+ }
+ if (!xdr_string (xdrs, &objp->buf, ~0))
+ return FALSE;
+ return TRUE;
+ } else if (xdrs->x_op == XDR_DECODE) {
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ buf = XDR_INLINE (xdrs, 3 * BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->flags))
+ return FALSE;
+
+ } else {
+ objp->op_ret = IXDR_GET_LONG(buf);
+ objp->op_errno = IXDR_GET_LONG(buf);
+ objp->flags = IXDR_GET_U_LONG(buf);
+ }
+ if (!xdr_string (xdrs, &objp->buf, ~0))
+ return FALSE;
+ return TRUE;
+ }
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->flags))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->buf, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_releasedir_req (XDR *xdrs, gfs3_releasedir_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gfs3_release_req (XDR *xdrs, gfs3_release_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->ino))
+ return FALSE;
+ if (!xdr_u_quad_t (xdrs, &objp->gen))
+ return FALSE;
+ if (!xdr_quad_t (xdrs, &objp->fd))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gf_common_rsp (XDR *xdrs, gf_common_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ return TRUE;
+}
+
+
+bool_t
+xdr_gf_dump_version_req (XDR *xdrs, gf_dump_version_req *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->flags))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->key, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_gf_dump_version_rsp (XDR *xdrs, gf_dump_version_rsp *objp)
+{
+
+ if (!xdr_u_quad_t (xdrs, &objp->gfs_id))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_ret))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->op_errno))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->flags))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **)&objp->msg.msg_val, (u_int *) &objp->msg.msg_len, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_auth_glusterfs_parms (XDR *xdrs, auth_glusterfs_parms *objp)
+{
+ register int32_t *buf;
+
+ int i;
+
+ if (xdrs->x_op == XDR_ENCODE) {
+ if (!xdr_u_quad_t (xdrs, &objp->lk_owner))
+ return FALSE;
+ buf = XDR_INLINE (xdrs, (4 + 16 )* BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_u_int (xdrs, &objp->pid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->uid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->gid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ngrps))
+ return FALSE;
+ if (!xdr_vector (xdrs, (char *)objp->groups, 16,
+ sizeof (u_int), (xdrproc_t) xdr_u_int))
+ return FALSE;
+ } else {
+ IXDR_PUT_U_LONG(buf, objp->pid);
+ IXDR_PUT_U_LONG(buf, objp->uid);
+ IXDR_PUT_U_LONG(buf, objp->gid);
+ IXDR_PUT_U_LONG(buf, objp->ngrps);
+ {
+ register u_int *genp;
+
+ for (i = 0, genp = objp->groups;
+ i < 16; ++i) {
+ IXDR_PUT_U_LONG(buf, *genp++);
+ }
+ }
+ }
+ return TRUE;
+ } else if (xdrs->x_op == XDR_DECODE) {
+ if (!xdr_u_quad_t (xdrs, &objp->lk_owner))
+ return FALSE;
+ buf = XDR_INLINE (xdrs, (4 + 16 )* BYTES_PER_XDR_UNIT);
+ if (buf == NULL) {
+ if (!xdr_u_int (xdrs, &objp->pid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->uid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->gid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ngrps))
+ return FALSE;
+ if (!xdr_vector (xdrs, (char *)objp->groups, 16,
+ sizeof (u_int), (xdrproc_t) xdr_u_int))
+ return FALSE;
+ } else {
+ objp->pid = IXDR_GET_U_LONG(buf);
+ objp->uid = IXDR_GET_U_LONG(buf);
+ objp->gid = IXDR_GET_U_LONG(buf);
+ objp->ngrps = IXDR_GET_U_LONG(buf);
+ {
+ register u_int *genp;
+
+ for (i = 0, genp = objp->groups;
+ i < 16; ++i) {
+ *genp++ = IXDR_GET_U_LONG(buf);
+ }
+ }
+ }
+ return TRUE;
+ }
+
+ if (!xdr_u_quad_t (xdrs, &objp->lk_owner))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->pid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->uid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->gid))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ngrps))
+ return FALSE;
+ if (!xdr_vector (xdrs, (char *)objp->groups, 16,
+ sizeof (u_int), (xdrproc_t) xdr_u_int))
+ return FALSE;
+ return TRUE;
+}
diff --git a/xlators/protocol/lib/src/glusterfs-xdr.h b/xlators/protocol/lib/src/glusterfs-xdr.h
new file mode 100644
index 0000000..3fb6d0b
--- /dev/null
+++ b/xlators/protocol/lib/src/glusterfs-xdr.h
@@ -0,0 +1,1337 @@
+/*
+ * Please do not edit this file.
+ * It was generated using rpcgen.
+ */
+
+#ifndef _GLUSTERFS3_H_RPCGEN
+#define _GLUSTERFS3_H_RPCGEN
+
+#include <rpc/rpc.h>
+#include "iatt.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#define GF_O_ACCMODE 003
+#define GF_O_RDONLY 00
+#define GF_O_WRONLY 01
+#define GF_O_RDWR 02
+#define GF_O_CREAT 0100
+#define GF_O_EXCL 0200
+#define GF_O_NOCTTY 0400
+#define GF_O_TRUNC 01000
+#define GF_O_APPEND 02000
+#define GF_O_NONBLOCK 04000
+#define GF_O_SYNC 010000
+#define GF_O_ASYNC 020000
+
+#define GF_O_DIRECT 040000
+#define GF_O_DIRECTORY 0200000
+#define GF_O_NOFOLLOW 0400000
+#define GF_O_NOATIME 01000000
+#define GF_O_CLOEXEC 02000000
+
+#define GF_O_LARGEFILE 0100000
+
+#define XLATE_BIT(from, to, bit) do { \
+ if (from & bit) \
+ to = to | GF_##bit; \
+ } while (0)
+
+#define UNXLATE_BIT(from, to, bit) do { \
+ if (from & GF_##bit) \
+ to = to | bit; \
+ } while (0)
+
+#define XLATE_ACCESSMODE(from, to) do { \
+ switch (from & O_ACCMODE) { \
+ case O_RDONLY: to |= GF_O_RDONLY; \
+ break; \
+ case O_WRONLY: to |= GF_O_WRONLY; \
+ break; \
+ case O_RDWR: to |= GF_O_RDWR; \
+ break; \
+ } \
+ } while (0)
+
+#define UNXLATE_ACCESSMODE(from, to) do { \
+ switch (from & GF_O_ACCMODE) { \
+ case GF_O_RDONLY: to |= O_RDONLY; \
+ break; \
+ case GF_O_WRONLY: to |= O_WRONLY; \
+ break; \
+ case GF_O_RDWR: to |= O_RDWR; \
+ break; \
+ } \
+ } while (0)
+
+static inline uint32_t
+gf_flags_from_flags (uint32_t flags)
+{
+ uint32_t gf_flags = 0;
+
+ XLATE_ACCESSMODE (flags, gf_flags);
+
+ XLATE_BIT (flags, gf_flags, O_CREAT);
+ XLATE_BIT (flags, gf_flags, O_EXCL);
+ XLATE_BIT (flags, gf_flags, O_NOCTTY);
+ XLATE_BIT (flags, gf_flags, O_TRUNC);
+ XLATE_BIT (flags, gf_flags, O_APPEND);
+ XLATE_BIT (flags, gf_flags, O_NONBLOCK);
+ XLATE_BIT (flags, gf_flags, O_SYNC);
+ XLATE_BIT (flags, gf_flags, O_ASYNC);
+
+ XLATE_BIT (flags, gf_flags, O_DIRECT);
+ XLATE_BIT (flags, gf_flags, O_DIRECTORY);
+ XLATE_BIT (flags, gf_flags, O_NOFOLLOW);
+#ifdef O_NOATIME
+ XLATE_BIT (flags, gf_flags, O_NOATIME);
+#endif
+#ifdef O_CLOEXEC
+ XLATE_BIT (flags, gf_flags, O_CLOEXEC);
+#endif
+ XLATE_BIT (flags, gf_flags, O_LARGEFILE);
+
+ return gf_flags;
+}
+
+static inline uint32_t
+gf_flags_to_flags (uint32_t gf_flags)
+{
+ uint32_t flags = 0;
+
+ UNXLATE_ACCESSMODE (gf_flags, flags);
+
+ UNXLATE_BIT (gf_flags, flags, O_CREAT);
+ UNXLATE_BIT (gf_flags, flags, O_EXCL);
+ UNXLATE_BIT (gf_flags, flags, O_NOCTTY);
+ UNXLATE_BIT (gf_flags, flags, O_TRUNC);
+ UNXLATE_BIT (gf_flags, flags, O_APPEND);
+ UNXLATE_BIT (gf_flags, flags, O_NONBLOCK);
+ UNXLATE_BIT (gf_flags, flags, O_SYNC);
+ UNXLATE_BIT (gf_flags, flags, O_ASYNC);
+
+ UNXLATE_BIT (gf_flags, flags, O_DIRECT);
+ UNXLATE_BIT (gf_flags, flags, O_DIRECTORY);
+ UNXLATE_BIT (gf_flags, flags, O_NOFOLLOW);
+#ifdef O_NOATIME
+ UNXLATE_BIT (gf_flags, flags, O_NOATIME);
+#endif
+#ifdef O_CLOEXEC
+ UNXLATE_BIT (gf_flags, flags, O_CLOEXEC);
+#endif
+ UNXLATE_BIT (gf_flags, flags, O_LARGEFILE);
+
+ return flags;
+}
+
+
+struct gf_statfs {
+ u_quad_t bsize;
+ u_quad_t frsize;
+ u_quad_t blocks;
+ u_quad_t bfree;
+ u_quad_t bavail;
+ u_quad_t files;
+ u_quad_t ffree;
+ u_quad_t favail;
+ u_quad_t fsid;
+ u_quad_t flag;
+ u_quad_t namemax;
+};
+typedef struct gf_statfs gf_statfs;
+
+static inline void
+gf_statfs_to_statfs (struct gf_statfs *gf_stat, struct statvfs *stat)
+{
+ if (!stat || !gf_stat)
+ return;
+
+ stat->f_bsize = (gf_stat->bsize);
+ stat->f_frsize = (gf_stat->frsize);
+ stat->f_blocks = (gf_stat->blocks);
+ stat->f_bfree = (gf_stat->bfree);
+ stat->f_bavail = (gf_stat->bavail);
+ stat->f_files = (gf_stat->files);
+ stat->f_ffree = (gf_stat->ffree);
+ stat->f_favail = (gf_stat->favail);
+ stat->f_fsid = (gf_stat->fsid);
+ stat->f_flag = (gf_stat->flag);
+ stat->f_namemax = (gf_stat->namemax);
+}
+
+
+static inline void
+gf_statfs_from_statfs (struct gf_statfs *gf_stat, struct statvfs *stat)
+{
+ if (!stat || !gf_stat)
+ return;
+
+ gf_stat->bsize = stat->f_bsize;
+ gf_stat->frsize = stat->f_frsize;
+ gf_stat->blocks = stat->f_blocks;
+ gf_stat->bfree = stat->f_bfree;
+ gf_stat->bavail = stat->f_bavail;
+ gf_stat->files = stat->f_files;
+ gf_stat->ffree = stat->f_ffree;
+ gf_stat->favail = stat->f_favail;
+ gf_stat->fsid = stat->f_fsid;
+ gf_stat->flag = stat->f_flag;
+ gf_stat->namemax = stat->f_namemax;
+}
+
+struct gf_flock {
+ u_int type;
+ u_int whence;
+ u_quad_t start;
+ u_quad_t len;
+ u_int pid;
+};
+typedef struct gf_flock gf_flock;
+
+
+static inline void
+gf_flock_to_flock (struct gf_flock *gf_flock, struct flock *flock)
+{
+ if (!flock || !gf_flock)
+ return;
+
+ flock->l_type = gf_flock->type;
+ flock->l_whence = gf_flock->whence;
+ flock->l_start = gf_flock->start;
+ flock->l_len = gf_flock->len;
+ flock->l_pid = gf_flock->pid;
+}
+
+
+static inline void
+gf_flock_from_flock (struct gf_flock *gf_flock, struct flock *flock)
+{
+ if (!flock || !gf_flock)
+ return;
+
+ gf_flock->type = (flock->l_type);
+ gf_flock->whence = (flock->l_whence);
+ gf_flock->start = (flock->l_start);
+ gf_flock->len = (flock->l_len);
+ gf_flock->pid = (flock->l_pid);
+}
+
+struct gf_iatt {
+ u_quad_t ia_ino;
+ u_quad_t ia_gen;
+ u_quad_t ia_dev;
+ u_int mode;
+ u_int ia_nlink;
+ u_int ia_uid;
+ u_int ia_gid;
+ u_quad_t ia_rdev;
+ u_quad_t ia_size;
+ u_int ia_blksize;
+ u_quad_t ia_blocks;
+ u_int ia_atime;
+ u_int ia_atime_nsec;
+ u_int ia_mtime;
+ u_int ia_mtime_nsec;
+ u_int ia_ctime;
+ u_int ia_ctime_nsec;
+} __attribute__((packed));
+typedef struct gf_iatt gf_iatt;
+
+
+static inline void
+gf_stat_to_iatt (struct gf_iatt *gf_stat, struct iatt *iatt)
+{
+ if (!iatt || !gf_stat)
+ return;
+
+ iatt->ia_ino = gf_stat->ia_ino ;
+ iatt->ia_gen = gf_stat->ia_gen ;
+ iatt->ia_dev = gf_stat->ia_dev ;
+ iatt->ia_type = ia_type_from_st_mode (gf_stat->mode) ;
+ iatt->ia_prot = ia_prot_from_st_mode (gf_stat->mode) ;
+ iatt->ia_nlink = gf_stat->ia_nlink ;
+ iatt->ia_uid = gf_stat->ia_uid ;
+ iatt->ia_gid = gf_stat->ia_gid ;
+ iatt->ia_rdev = gf_stat->ia_rdev ;
+ iatt->ia_size = gf_stat->ia_size ;
+ iatt->ia_blksize = gf_stat->ia_blksize ;
+ iatt->ia_blocks = gf_stat->ia_blocks ;
+ iatt->ia_atime = gf_stat->ia_atime ;
+ iatt->ia_atime_nsec = gf_stat->ia_atime_nsec ;
+ iatt->ia_mtime = gf_stat->ia_mtime ;
+ iatt->ia_mtime_nsec = gf_stat->ia_mtime_nsec ;
+ iatt->ia_ctime = gf_stat->ia_ctime ;
+ iatt->ia_ctime_nsec = gf_stat->ia_ctime_nsec ;
+}
+
+
+static inline void
+gf_stat_from_iatt (struct gf_iatt *gf_stat, struct iatt *iatt)
+{
+ if (!iatt || !gf_stat)
+ return;
+
+ gf_stat->ia_ino = iatt->ia_ino ;
+ gf_stat->ia_gen = iatt->ia_gen ;
+ gf_stat->ia_dev = iatt->ia_dev ;
+ gf_stat->mode = st_mode_from_ia (iatt->ia_prot, iatt->ia_type);
+ gf_stat->ia_nlink = iatt->ia_nlink ;
+ gf_stat->ia_uid = iatt->ia_uid ;
+ gf_stat->ia_gid = iatt->ia_gid ;
+ gf_stat->ia_rdev = iatt->ia_rdev ;
+ gf_stat->ia_size = iatt->ia_size ;
+ gf_stat->ia_blksize = iatt->ia_blksize ;
+ gf_stat->ia_blocks = iatt->ia_blocks ;
+ gf_stat->ia_atime = iatt->ia_atime ;
+ gf_stat->ia_atime_nsec = iatt->ia_atime_nsec ;
+ gf_stat->ia_mtime = iatt->ia_mtime ;
+ gf_stat->ia_mtime_nsec = iatt->ia_mtime_nsec ;
+ gf_stat->ia_ctime = iatt->ia_ctime ;
+ gf_stat->ia_ctime_nsec = iatt->ia_ctime_nsec ;
+}
+
+
+struct gf_dirent_nb {
+ uint64_t d_ino;
+ uint64_t d_off;
+ uint32_t d_len;
+ uint32_t d_type;
+ struct gf_iatt d_stat;
+ char d_name[0];
+} __attribute__((packed));
+
+
+/* Gluster FS Payload structures */
+
+struct gfs3_stat_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ char *path;
+};
+typedef struct gfs3_stat_req gfs3_stat_req;
+
+struct gfs3_stat_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+};
+typedef struct gfs3_stat_rsp gfs3_stat_rsp;
+
+struct gfs3_readlink_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ u_int size;
+ char *path;
+};
+typedef struct gfs3_readlink_req gfs3_readlink_req;
+
+struct gfs3_readlink_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt buf;
+ char *path;
+};
+typedef struct gfs3_readlink_rsp gfs3_readlink_rsp;
+
+struct gfs3_mknod_req {
+ u_quad_t gfs_id;
+ u_quad_t par;
+ u_quad_t gen;
+ u_quad_t dev;
+ u_int mode;
+ char *path;
+ char *bname;
+};
+typedef struct gfs3_mknod_req gfs3_mknod_req;
+
+struct gfs3_mknod_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ struct gf_iatt preparent;
+ struct gf_iatt postparent;
+};
+typedef struct gfs3_mknod_rsp gfs3_mknod_rsp;
+
+struct gfs3_mkdir_req {
+ u_quad_t gfs_id;
+ u_quad_t par;
+ u_quad_t gen;
+ u_int mode;
+ char *path;
+ char *bname;
+};
+typedef struct gfs3_mkdir_req gfs3_mkdir_req;
+
+struct gfs3_mkdir_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ struct gf_iatt preparent;
+ struct gf_iatt postparent;
+};
+typedef struct gfs3_mkdir_rsp gfs3_mkdir_rsp;
+
+struct gfs3_unlink_req {
+ u_quad_t gfs_id;
+ u_quad_t par;
+ u_quad_t gen;
+ char *path;
+ char *bname;
+};
+typedef struct gfs3_unlink_req gfs3_unlink_req;
+
+struct gfs3_unlink_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt preparent;
+ struct gf_iatt postparent;
+};
+typedef struct gfs3_unlink_rsp gfs3_unlink_rsp;
+
+struct gfs3_rmdir_req {
+ u_quad_t gfs_id;
+ u_quad_t par;
+ u_quad_t gen;
+ char *path;
+ char *bname;
+};
+typedef struct gfs3_rmdir_req gfs3_rmdir_req;
+
+struct gfs3_rmdir_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt preparent;
+ struct gf_iatt postparent;
+};
+typedef struct gfs3_rmdir_rsp gfs3_rmdir_rsp;
+
+struct gfs3_symlink_req {
+ u_quad_t gfs_id;
+ u_quad_t par;
+ u_quad_t gen;
+ char *path;
+ char *bname;
+ char *linkname;
+};
+typedef struct gfs3_symlink_req gfs3_symlink_req;
+
+struct gfs3_symlink_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ struct gf_iatt preparent;
+ struct gf_iatt postparent;
+};
+typedef struct gfs3_symlink_rsp gfs3_symlink_rsp;
+
+struct gfs3_rename_req {
+ u_quad_t gfs_id;
+ u_quad_t oldpar;
+ u_quad_t oldgen;
+ u_quad_t newpar;
+ u_quad_t newgen;
+ char *oldpath;
+ char *oldbname;
+ char *newpath;
+ char *newbname;
+};
+typedef struct gfs3_rename_req gfs3_rename_req;
+
+struct gfs3_rename_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ struct gf_iatt preoldparent;
+ struct gf_iatt postoldparent;
+ struct gf_iatt prenewparent;
+ struct gf_iatt postnewparent;
+};
+typedef struct gfs3_rename_rsp gfs3_rename_rsp;
+
+struct gfs3_link_req {
+ u_quad_t gfs_id;
+ u_quad_t oldino;
+ u_quad_t oldgen;
+ u_quad_t newpar;
+ u_quad_t newgen;
+ char *oldpath;
+ char *newpath;
+ char *newbname;
+};
+typedef struct gfs3_link_req gfs3_link_req;
+
+struct gfs3_link_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ struct gf_iatt preparent;
+ struct gf_iatt postparent;
+};
+typedef struct gfs3_link_rsp gfs3_link_rsp;
+
+struct gfs3_truncate_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ u_quad_t offset;
+ char *path;
+};
+typedef struct gfs3_truncate_req gfs3_truncate_req;
+
+struct gfs3_truncate_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt prestat;
+ struct gf_iatt poststat;
+};
+typedef struct gfs3_truncate_rsp gfs3_truncate_rsp;
+
+struct gfs3_open_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ u_int flags;
+ u_int wbflags;
+ char *path;
+};
+typedef struct gfs3_open_req gfs3_open_req;
+
+struct gfs3_open_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ quad_t fd;
+};
+typedef struct gfs3_open_rsp gfs3_open_rsp;
+
+struct gfs3_read_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+ u_quad_t offset;
+ u_int size;
+};
+typedef struct gfs3_read_req gfs3_read_req;
+
+struct gfs3_read_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ u_int size;
+} __attribute__((packed));
+typedef struct gfs3_read_rsp gfs3_read_rsp;
+
+struct gfs3_lookup_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t par;
+ u_quad_t gen;
+ u_int flags;
+ char *path;
+ char *bname;
+ struct {
+ u_int dict_len;
+ char *dict_val;
+ } dict;
+};
+typedef struct gfs3_lookup_req gfs3_lookup_req;
+
+struct gfs3_lookup_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ struct gf_iatt postparent;
+ struct {
+ u_int dict_len;
+ char *dict_val;
+ } dict;
+};
+typedef struct gfs3_lookup_rsp gfs3_lookup_rsp;
+
+struct gfs3_write_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+ u_quad_t offset;
+ u_int size;
+} __attribute__((packed));
+typedef struct gfs3_write_req gfs3_write_req;
+
+struct gfs3_write_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt prestat;
+ struct gf_iatt poststat;
+};
+typedef struct gfs3_write_rsp gfs3_write_rsp;
+
+struct gfs3_statfs_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ char *path;
+};
+typedef struct gfs3_statfs_req gfs3_statfs_req;
+
+struct gfs3_statfs_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_statfs statfs;
+};
+typedef struct gfs3_statfs_rsp gfs3_statfs_rsp;
+
+struct gfs3_lk_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+ u_int cmd;
+ u_int type;
+ struct gf_flock flock;
+};
+typedef struct gfs3_lk_req gfs3_lk_req;
+
+struct gfs3_lk_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_flock flock;
+};
+typedef struct gfs3_lk_rsp gfs3_lk_rsp;
+
+struct gfs3_inodelk_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ u_int cmd;
+ u_int type;
+ struct gf_flock flock;
+ char *path;
+ char *volume;
+};
+typedef struct gfs3_inodelk_req gfs3_inodelk_req;
+
+struct gfs3_finodelk_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+ u_int cmd;
+ u_int type;
+ struct gf_flock flock;
+ char *volume;
+};
+typedef struct gfs3_finodelk_req gfs3_finodelk_req;
+
+struct gfs3_flush_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+};
+typedef struct gfs3_flush_req gfs3_flush_req;
+
+struct gfs3_fsync_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+ u_int data;
+};
+typedef struct gfs3_fsync_req gfs3_fsync_req;
+
+struct gfs3_fsync_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt prestat;
+ struct gf_iatt poststat;
+};
+typedef struct gfs3_fsync_rsp gfs3_fsync_rsp;
+
+struct gfs3_setxattr_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ u_int flags;
+ struct {
+ u_int dict_len;
+ char *dict_val;
+ } dict;
+ char *path;
+};
+typedef struct gfs3_setxattr_req gfs3_setxattr_req;
+
+struct gfs3_fsetxattr_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+ u_int flags;
+ struct {
+ u_int dict_len;
+ char *dict_val;
+ } dict;
+};
+typedef struct gfs3_fsetxattr_req gfs3_fsetxattr_req;
+
+struct gfs3_xattrop_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ u_int flags;
+ struct {
+ u_int dict_len;
+ char *dict_val;
+ } dict;
+ char *path;
+};
+typedef struct gfs3_xattrop_req gfs3_xattrop_req;
+
+struct gfs3_xattrop_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct {
+ u_int dict_len;
+ char *dict_val;
+ } dict;
+};
+typedef struct gfs3_xattrop_rsp gfs3_xattrop_rsp;
+
+struct gfs3_fxattrop_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+ u_int flags;
+ struct {
+ u_int dict_len;
+ char *dict_val;
+ } dict;
+};
+typedef struct gfs3_fxattrop_req gfs3_fxattrop_req;
+
+struct gfs3_fxattrop_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct {
+ u_int dict_len;
+ char *dict_val;
+ } dict;
+};
+typedef struct gfs3_fxattrop_rsp gfs3_fxattrop_rsp;
+
+struct gfs3_getxattr_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ u_int namelen;
+ char *path;
+ char *name;
+};
+typedef struct gfs3_getxattr_req gfs3_getxattr_req;
+
+struct gfs3_getxattr_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct {
+ u_int dict_len;
+ char *dict_val;
+ } dict;
+};
+typedef struct gfs3_getxattr_rsp gfs3_getxattr_rsp;
+
+struct gfs3_fgetxattr_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+ u_int namelen;
+ char *name;
+};
+typedef struct gfs3_fgetxattr_req gfs3_fgetxattr_req;
+
+struct gfs3_fgetxattr_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct {
+ u_int dict_len;
+ char *dict_val;
+ } dict;
+};
+typedef struct gfs3_fgetxattr_rsp gfs3_fgetxattr_rsp;
+
+struct gfs3_removexattr_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ char *path;
+ char *name;
+};
+typedef struct gfs3_removexattr_req gfs3_removexattr_req;
+
+struct gfs3_opendir_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ char *path;
+};
+typedef struct gfs3_opendir_req gfs3_opendir_req;
+
+struct gfs3_opendir_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ quad_t fd;
+};
+typedef struct gfs3_opendir_rsp gfs3_opendir_rsp;
+
+struct gfs3_fsyncdir_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+ int data;
+};
+typedef struct gfs3_fsyncdir_req gfs3_fsyncdir_req;
+
+struct gfs3_readdir_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+ u_quad_t offset;
+ u_int size;
+};
+typedef struct gfs3_readdir_req gfs3_readdir_req;
+
+struct gfs3_readdir_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct {
+ u_int buf_len;
+ char *buf_val;
+ } buf;
+};
+typedef struct gfs3_readdir_rsp gfs3_readdir_rsp;
+
+struct gfs3_readdirp_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+ u_quad_t offset;
+ u_int size;
+};
+typedef struct gfs3_readdirp_req gfs3_readdirp_req;
+
+struct gfs3_readdirp_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct {
+ u_int buf_len;
+ char *buf_val;
+ } buf;
+};
+typedef struct gfs3_readdirp_rsp gfs3_readdirp_rsp;
+
+struct gf_setvolume_req {
+ u_quad_t gfs_id;
+ struct {
+ u_int dict_len;
+ char *dict_val;
+ } dict;
+};
+typedef struct gf_setvolume_req gf_setvolume_req;
+
+struct gf_setvolume_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct {
+ u_int dict_len;
+ char *dict_val;
+ } dict;
+};
+typedef struct gf_setvolume_rsp gf_setvolume_rsp;
+
+struct gfs3_access_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ u_int mask;
+ char *path;
+};
+typedef struct gfs3_access_req gfs3_access_req;
+
+struct gfs3_create_req {
+ u_quad_t gfs_id;
+ u_quad_t par;
+ u_quad_t gen;
+ u_int flags;
+ u_int mode;
+ char *path;
+ char *bname;
+};
+typedef struct gfs3_create_req gfs3_create_req;
+
+struct gfs3_create_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ u_quad_t fd;
+ struct gf_iatt preparent;
+ struct gf_iatt postparent;
+};
+typedef struct gfs3_create_rsp gfs3_create_rsp;
+
+struct gfs3_ftruncate_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+ u_quad_t offset;
+};
+typedef struct gfs3_ftruncate_req gfs3_ftruncate_req;
+
+struct gfs3_ftruncate_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt prestat;
+ struct gf_iatt poststat;
+};
+typedef struct gfs3_ftruncate_rsp gfs3_ftruncate_rsp;
+
+struct gfs3_fstat_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+};
+typedef struct gfs3_fstat_req gfs3_fstat_req;
+
+struct gfs3_fstat_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+};
+typedef struct gfs3_fstat_rsp gfs3_fstat_rsp;
+
+struct gfs3_entrylk_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ u_int cmd;
+ u_int type;
+ u_quad_t namelen;
+ char *path;
+ char *name;
+ char *volume;
+};
+typedef struct gfs3_entrylk_req gfs3_entrylk_req;
+
+struct gfs3_fentrylk_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+ u_int cmd;
+ u_int type;
+ u_quad_t namelen;
+ char *name;
+ char *volume;
+};
+typedef struct gfs3_fentrylk_req gfs3_fentrylk_req;
+
+struct gfs3_checksum_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ u_int flag;
+ char *path;
+};
+typedef struct gfs3_checksum_req gfs3_checksum_req;
+
+struct gfs3_checksum_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct {
+ u_int fchecksum_len;
+ char *fchecksum_val;
+ } fchecksum;
+ struct {
+ u_int dchecksum_len;
+ char *dchecksum_val;
+ } dchecksum;
+};
+typedef struct gfs3_checksum_rsp gfs3_checksum_rsp;
+
+struct gfs3_setattr_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ struct gf_iatt stbuf;
+ int valid;
+ char *path;
+};
+typedef struct gfs3_setattr_req gfs3_setattr_req;
+
+struct gfs3_setattr_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt statpre;
+ struct gf_iatt statpost;
+};
+typedef struct gfs3_setattr_rsp gfs3_setattr_rsp;
+
+struct gfs3_fsetattr_req {
+ u_quad_t gfs_id;
+ quad_t fd;
+ struct gf_iatt stbuf;
+ int valid;
+};
+typedef struct gfs3_fsetattr_req gfs3_fsetattr_req;
+
+struct gfs3_fsetattr_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt statpre;
+ struct gf_iatt statpost;
+};
+typedef struct gfs3_fsetattr_rsp gfs3_fsetattr_rsp;
+
+struct gfs3_rchecksum_req {
+ u_quad_t gfs_id;
+ quad_t fd;
+ u_quad_t offset;
+ u_int len;
+};
+typedef struct gfs3_rchecksum_req gfs3_rchecksum_req;
+
+struct gfs3_rchecksum_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ u_int weak_checksum;
+ struct {
+ u_int strong_checksum_len;
+ char *strong_checksum_val;
+ } strong_checksum;
+};
+typedef struct gfs3_rchecksum_rsp gfs3_rchecksum_rsp;
+
+struct gf_getspec_req {
+ u_quad_t gfs_id;
+ u_int flags;
+ char *key;
+};
+typedef struct gf_getspec_req gf_getspec_req;
+
+struct gf_getspec_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ char *spec;
+};
+typedef struct gf_getspec_rsp gf_getspec_rsp;
+
+struct gf_log_req {
+ u_quad_t gfs_id;
+ struct {
+ u_int msg_len;
+ char *msg_val;
+ } msg;
+};
+typedef struct gf_log_req gf_log_req;
+
+struct gf_notify_req {
+ u_quad_t gfs_id;
+ u_int flags;
+ char *buf;
+};
+typedef struct gf_notify_req gf_notify_req;
+
+struct gf_notify_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ u_int flags;
+ char *buf;
+};
+typedef struct gf_notify_rsp gf_notify_rsp;
+
+struct gfs3_releasedir_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+};
+typedef struct gfs3_releasedir_req gfs3_releasedir_req;
+
+struct gfs3_release_req {
+ u_quad_t gfs_id;
+ u_quad_t ino;
+ u_quad_t gen;
+ quad_t fd;
+};
+typedef struct gfs3_release_req gfs3_release_req;
+
+struct gf_common_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+};
+typedef struct gf_common_rsp gf_common_rsp;
+
+struct gf_dump_version_req {
+ u_quad_t gfs_id;
+ u_int flags;
+ char *key;
+};
+typedef struct gf_dump_version_req gf_dump_version_req;
+
+struct gf_dump_version_rsp {
+ u_quad_t gfs_id;
+ int op_ret;
+ int op_errno;
+ u_int flags;
+ struct {
+ u_int msg_len;
+ char *msg_val;
+ } msg;
+};
+typedef struct gf_dump_version_rsp gf_dump_version_rsp;
+
+struct auth_glusterfs_parms {
+ u_quad_t lk_owner;
+ u_int pid;
+ u_int uid;
+ u_int gid;
+ u_int ngrps;
+ u_int groups[16];
+};
+typedef struct auth_glusterfs_parms auth_glusterfs_parms;
+
+/* the xdr functions */
+
+#if defined(__STDC__) || defined(__cplusplus)
+extern bool_t xdr_gf_statfs (XDR *, gf_statfs*);
+extern bool_t xdr_gf_flock (XDR *, gf_flock*);
+extern bool_t xdr_gf_iatt (XDR *, gf_iatt*);
+extern bool_t xdr_gfs3_stat_req (XDR *, gfs3_stat_req*);
+extern bool_t xdr_gfs3_stat_rsp (XDR *, gfs3_stat_rsp*);
+extern bool_t xdr_gfs3_readlink_req (XDR *, gfs3_readlink_req*);
+extern bool_t xdr_gfs3_readlink_rsp (XDR *, gfs3_readlink_rsp*);
+extern bool_t xdr_gfs3_mknod_req (XDR *, gfs3_mknod_req*);
+extern bool_t xdr_gfs3_mknod_rsp (XDR *, gfs3_mknod_rsp*);
+extern bool_t xdr_gfs3_mkdir_req (XDR *, gfs3_mkdir_req*);
+extern bool_t xdr_gfs3_mkdir_rsp (XDR *, gfs3_mkdir_rsp*);
+extern bool_t xdr_gfs3_unlink_req (XDR *, gfs3_unlink_req*);
+extern bool_t xdr_gfs3_unlink_rsp (XDR *, gfs3_unlink_rsp*);
+extern bool_t xdr_gfs3_rmdir_req (XDR *, gfs3_rmdir_req*);
+extern bool_t xdr_gfs3_rmdir_rsp (XDR *, gfs3_rmdir_rsp*);
+extern bool_t xdr_gfs3_symlink_req (XDR *, gfs3_symlink_req*);
+extern bool_t xdr_gfs3_symlink_rsp (XDR *, gfs3_symlink_rsp*);
+extern bool_t xdr_gfs3_rename_req (XDR *, gfs3_rename_req*);
+extern bool_t xdr_gfs3_rename_rsp (XDR *, gfs3_rename_rsp*);
+extern bool_t xdr_gfs3_link_req (XDR *, gfs3_link_req*);
+extern bool_t xdr_gfs3_link_rsp (XDR *, gfs3_link_rsp*);
+extern bool_t xdr_gfs3_truncate_req (XDR *, gfs3_truncate_req*);
+extern bool_t xdr_gfs3_truncate_rsp (XDR *, gfs3_truncate_rsp*);
+extern bool_t xdr_gfs3_open_req (XDR *, gfs3_open_req*);
+extern bool_t xdr_gfs3_open_rsp (XDR *, gfs3_open_rsp*);
+extern bool_t xdr_gfs3_read_req (XDR *, gfs3_read_req*);
+extern bool_t xdr_gfs3_read_rsp (XDR *, gfs3_read_rsp*);
+extern bool_t xdr_gfs3_lookup_req (XDR *, gfs3_lookup_req*);
+extern bool_t xdr_gfs3_lookup_rsp (XDR *, gfs3_lookup_rsp*);
+extern bool_t xdr_gfs3_write_req (XDR *, gfs3_write_req*);
+extern bool_t xdr_gfs3_write_rsp (XDR *, gfs3_write_rsp*);
+extern bool_t xdr_gfs3_statfs_req (XDR *, gfs3_statfs_req*);
+extern bool_t xdr_gfs3_statfs_rsp (XDR *, gfs3_statfs_rsp*);
+extern bool_t xdr_gfs3_lk_req (XDR *, gfs3_lk_req*);
+extern bool_t xdr_gfs3_lk_rsp (XDR *, gfs3_lk_rsp*);
+extern bool_t xdr_gfs3_inodelk_req (XDR *, gfs3_inodelk_req*);
+extern bool_t xdr_gfs3_finodelk_req (XDR *, gfs3_finodelk_req*);
+extern bool_t xdr_gfs3_flush_req (XDR *, gfs3_flush_req*);
+extern bool_t xdr_gfs3_fsync_req (XDR *, gfs3_fsync_req*);
+extern bool_t xdr_gfs3_fsync_rsp (XDR *, gfs3_fsync_rsp*);
+extern bool_t xdr_gfs3_setxattr_req (XDR *, gfs3_setxattr_req*);
+extern bool_t xdr_gfs3_fsetxattr_req (XDR *, gfs3_fsetxattr_req*);
+extern bool_t xdr_gfs3_xattrop_req (XDR *, gfs3_xattrop_req*);
+extern bool_t xdr_gfs3_xattrop_rsp (XDR *, gfs3_xattrop_rsp*);
+extern bool_t xdr_gfs3_fxattrop_req (XDR *, gfs3_fxattrop_req*);
+extern bool_t xdr_gfs3_fxattrop_rsp (XDR *, gfs3_fxattrop_rsp*);
+extern bool_t xdr_gfs3_getxattr_req (XDR *, gfs3_getxattr_req*);
+extern bool_t xdr_gfs3_getxattr_rsp (XDR *, gfs3_getxattr_rsp*);
+extern bool_t xdr_gfs3_fgetxattr_req (XDR *, gfs3_fgetxattr_req*);
+extern bool_t xdr_gfs3_fgetxattr_rsp (XDR *, gfs3_fgetxattr_rsp*);
+extern bool_t xdr_gfs3_removexattr_req (XDR *, gfs3_removexattr_req*);
+extern bool_t xdr_gfs3_opendir_req (XDR *, gfs3_opendir_req*);
+extern bool_t xdr_gfs3_opendir_rsp (XDR *, gfs3_opendir_rsp*);
+extern bool_t xdr_gfs3_fsyncdir_req (XDR *, gfs3_fsyncdir_req*);
+extern bool_t xdr_gfs3_readdir_req (XDR *, gfs3_readdir_req*);
+extern bool_t xdr_gfs3_readdir_rsp (XDR *, gfs3_readdir_rsp*);
+extern bool_t xdr_gfs3_readdirp_req (XDR *, gfs3_readdirp_req*);
+extern bool_t xdr_gfs3_readdirp_rsp (XDR *, gfs3_readdirp_rsp*);
+extern bool_t xdr_gf_setvolume_req (XDR *, gf_setvolume_req*);
+extern bool_t xdr_gf_setvolume_rsp (XDR *, gf_setvolume_rsp*);
+extern bool_t xdr_gfs3_access_req (XDR *, gfs3_access_req*);
+extern bool_t xdr_gfs3_create_req (XDR *, gfs3_create_req*);
+extern bool_t xdr_gfs3_create_rsp (XDR *, gfs3_create_rsp*);
+extern bool_t xdr_gfs3_ftruncate_req (XDR *, gfs3_ftruncate_req*);
+extern bool_t xdr_gfs3_ftruncate_rsp (XDR *, gfs3_ftruncate_rsp*);
+extern bool_t xdr_gfs3_fstat_req (XDR *, gfs3_fstat_req*);
+extern bool_t xdr_gfs3_fstat_rsp (XDR *, gfs3_fstat_rsp*);
+extern bool_t xdr_gfs3_entrylk_req (XDR *, gfs3_entrylk_req*);
+extern bool_t xdr_gfs3_fentrylk_req (XDR *, gfs3_fentrylk_req*);
+extern bool_t xdr_gfs3_checksum_req (XDR *, gfs3_checksum_req*);
+extern bool_t xdr_gfs3_checksum_rsp (XDR *, gfs3_checksum_rsp*);
+extern bool_t xdr_gfs3_setattr_req (XDR *, gfs3_setattr_req*);
+extern bool_t xdr_gfs3_setattr_rsp (XDR *, gfs3_setattr_rsp*);
+extern bool_t xdr_gfs3_fsetattr_req (XDR *, gfs3_fsetattr_req*);
+extern bool_t xdr_gfs3_fsetattr_rsp (XDR *, gfs3_fsetattr_rsp*);
+extern bool_t xdr_gfs3_rchecksum_req (XDR *, gfs3_rchecksum_req*);
+extern bool_t xdr_gfs3_rchecksum_rsp (XDR *, gfs3_rchecksum_rsp*);
+extern bool_t xdr_gf_getspec_req (XDR *, gf_getspec_req*);
+extern bool_t xdr_gf_getspec_rsp (XDR *, gf_getspec_rsp*);
+extern bool_t xdr_gf_log_req (XDR *, gf_log_req*);
+extern bool_t xdr_gf_notify_req (XDR *, gf_notify_req*);
+extern bool_t xdr_gf_notify_rsp (XDR *, gf_notify_rsp*);
+extern bool_t xdr_gfs3_releasedir_req (XDR *, gfs3_releasedir_req*);
+extern bool_t xdr_gfs3_release_req (XDR *, gfs3_release_req*);
+extern bool_t xdr_gf_common_rsp (XDR *, gf_common_rsp*);
+extern bool_t xdr_gf_dump_version_req (XDR *, gf_dump_version_req *);
+extern bool_t xdr_gf_dump_version_rsp (XDR *, gf_dump_version_rsp *);
+extern bool_t xdr_auth_glusterfs_parms (XDR *, auth_glusterfs_parms*);
+
+#else /* K&R C */
+extern bool_t xdr_gf_statfs ();
+extern bool_t xdr_gf_flock ();
+extern bool_t xdr_gf_iatt ();
+extern bool_t xdr_gfs3_stat_req ();
+extern bool_t xdr_gfs3_stat_rsp ();
+extern bool_t xdr_gfs3_readlink_req ();
+extern bool_t xdr_gfs3_readlink_rsp ();
+extern bool_t xdr_gfs3_mknod_req ();
+extern bool_t xdr_gfs3_mknod_rsp ();
+extern bool_t xdr_gfs3_mkdir_req ();
+extern bool_t xdr_gfs3_mkdir_rsp ();
+extern bool_t xdr_gfs3_unlink_req ();
+extern bool_t xdr_gfs3_unlink_rsp ();
+extern bool_t xdr_gfs3_rmdir_req ();
+extern bool_t xdr_gfs3_rmdir_rsp ();
+extern bool_t xdr_gfs3_symlink_req ();
+extern bool_t xdr_gfs3_symlink_rsp ();
+extern bool_t xdr_gfs3_rename_req ();
+extern bool_t xdr_gfs3_rename_rsp ();
+extern bool_t xdr_gfs3_link_req ();
+extern bool_t xdr_gfs3_link_rsp ();
+extern bool_t xdr_gfs3_truncate_req ();
+extern bool_t xdr_gfs3_truncate_rsp ();
+extern bool_t xdr_gfs3_open_req ();
+extern bool_t xdr_gfs3_open_rsp ();
+extern bool_t xdr_gfs3_read_req ();
+extern bool_t xdr_gfs3_read_rsp ();
+extern bool_t xdr_gfs3_lookup_req ();
+extern bool_t xdr_gfs3_lookup_rsp ();
+extern bool_t xdr_gfs3_write_req ();
+extern bool_t xdr_gfs3_write_rsp ();
+extern bool_t xdr_gfs3_statfs_req ();
+extern bool_t xdr_gfs3_statfs_rsp ();
+extern bool_t xdr_gfs3_lk_req ();
+extern bool_t xdr_gfs3_lk_rsp ();
+extern bool_t xdr_gfs3_inodelk_req ();
+extern bool_t xdr_gfs3_finodelk_req ();
+extern bool_t xdr_gfs3_flush_req ();
+extern bool_t xdr_gfs3_fsync_req ();
+extern bool_t xdr_gfs3_fsync_rsp ();
+extern bool_t xdr_gfs3_setxattr_req ();
+extern bool_t xdr_gfs3_fsetxattr_req ();
+extern bool_t xdr_gfs3_xattrop_req ();
+extern bool_t xdr_gfs3_xattrop_rsp ();
+extern bool_t xdr_gfs3_fxattrop_req ();
+extern bool_t xdr_gfs3_fxattrop_rsp ();
+extern bool_t xdr_gfs3_getxattr_req ();
+extern bool_t xdr_gfs3_getxattr_rsp ();
+extern bool_t xdr_gfs3_fgetxattr_req ();
+extern bool_t xdr_gfs3_fgetxattr_rsp ();
+extern bool_t xdr_gfs3_removexattr_req ();
+extern bool_t xdr_gfs3_opendir_req ();
+extern bool_t xdr_gfs3_opendir_rsp ();
+extern bool_t xdr_gfs3_fsyncdir_req ();
+extern bool_t xdr_gfs3_readdir_req ();
+extern bool_t xdr_gfs3_readdir_rsp ();
+extern bool_t xdr_gfs3_readdirp_req ();
+extern bool_t xdr_gfs3_readdirp_rsp ();
+extern bool_t xdr_gf_setvolume_req ();
+extern bool_t xdr_gf_setvolume_rsp ();
+extern bool_t xdr_gfs3_access_req ();
+extern bool_t xdr_gfs3_create_req ();
+extern bool_t xdr_gfs3_create_rsp ();
+extern bool_t xdr_gfs3_ftruncate_req ();
+extern bool_t xdr_gfs3_ftruncate_rsp ();
+extern bool_t xdr_gfs3_fstat_req ();
+extern bool_t xdr_gfs3_fstat_rsp ();
+extern bool_t xdr_gfs3_entrylk_req ();
+extern bool_t xdr_gfs3_fentrylk_req ();
+extern bool_t xdr_gfs3_checksum_req ();
+extern bool_t xdr_gfs3_checksum_rsp ();
+extern bool_t xdr_gfs3_setattr_req ();
+extern bool_t xdr_gfs3_setattr_rsp ();
+extern bool_t xdr_gfs3_fsetattr_req ();
+extern bool_t xdr_gfs3_fsetattr_rsp ();
+extern bool_t xdr_gfs3_rchecksum_req ();
+extern bool_t xdr_gfs3_rchecksum_rsp ();
+extern bool_t xdr_gfs3_releasedir_req ();
+extern bool_t xdr_gfs3_release_req ();
+extern bool_t xdr_gf_getspec_req ();
+extern bool_t xdr_gf_getspec_rsp ();
+extern bool_t xdr_gf_log_req ();
+extern bool_t xdr_gf_notify_req ();
+extern bool_t xdr_gf_notify_rsp ();
+extern bool_t xdr_gf_common_rsp ();
+extern bool_t xdr_gf_dump_version_req ();
+extern bool_t xdr_gf_dump_version_rsp ();
+extern bool_t xdr_auth_glusterfs_parms ();
+
+#endif /* K&R C */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_GLUSTERFS3_H_RPCGEN */
diff --git a/xlators/protocol/lib/src/glusterfs3.x b/xlators/protocol/lib/src/glusterfs3.x
new file mode 100644
index 0000000..b6cc6e6
--- /dev/null
+++ b/xlators/protocol/lib/src/glusterfs3.x
@@ -0,0 +1,755 @@
+#define GF_REQUEST_MAXGROUPS 16
+struct gf_statfs {
+ unsigned hyper bsize;
+ unsigned hyper frsize;
+ unsigned hyper blocks;
+ unsigned hyper bfree;
+ unsigned hyper bavail;
+ unsigned hyper files;
+ unsigned hyper ffree;
+ unsigned hyper favail;
+ unsigned hyper fsid;
+ unsigned hyper flag;
+ unsigned hyper namemax;
+};
+
+struct gf_flock {
+ unsigned int type;
+ unsigned int whence;
+ unsigned hyper start;
+ unsigned hyper len;
+ unsigned int pid;
+} ;
+
+
+struct gf_iatt {
+ unsigned hyper ia_ino; /* inode number */
+ unsigned hyper ia_gen; /* generation number */
+ unsigned hyper ia_dev; /* backing device ID */
+ unsigned int mode; /* mode (type + protection )*/
+ unsigned int ia_nlink; /* Link count */
+ unsigned int ia_uid; /* user ID of owner */
+ unsigned int ia_gid; /* group ID of owner */
+ unsigned hyper ia_rdev; /* device ID (if special file) */
+ unsigned hyper ia_size; /* file size in bytes */
+ unsigned int ia_blksize; /* blocksize for filesystem I/O */
+ unsigned hyper ia_blocks; /* number of 512B blocks allocated */
+ unsigned int ia_atime; /* last access time */
+ unsigned int ia_atime_nsec;
+ unsigned int ia_mtime; /* last modification time */
+ unsigned int ia_mtime_nsec;
+ unsigned int ia_ctime; /* last status change time */
+ unsigned int ia_ctime_nsec;
+};
+
+struct gfs3_stat_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ string path<>; /* NULL terminated */
+};
+struct gfs3_stat_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+} ;
+
+
+struct gfs3_readlink_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ unsigned int size;
+ string path<>; /* NULL terminated */
+} ;
+ struct gfs3_readlink_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt buf;
+ string path<>; /* NULL terminated */
+} ;
+
+
+ struct gfs3_mknod_req {
+ unsigned hyper gfs_id;
+ unsigned hyper par;
+ unsigned hyper gen;
+ unsigned hyper dev;
+ unsigned int mode;
+ string path<>; /* NULL terminated */
+ string bname<>; /* NULL terminated */
+} ;
+ struct gfs3_mknod_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ struct gf_iatt preparent;
+ struct gf_iatt postparent;
+};
+
+
+ struct gfs3_mkdir_req {
+ unsigned hyper gfs_id;
+ unsigned hyper par;
+ unsigned hyper gen;
+ unsigned int mode;
+ string path<>; /* NULL terminated */
+ string bname<>; /* NULL terminated */
+} ;
+ struct gfs3_mkdir_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ struct gf_iatt preparent;
+ struct gf_iatt postparent;
+} ;
+
+
+ struct gfs3_unlink_req {
+ unsigned hyper gfs_id;
+ unsigned hyper par;
+ unsigned hyper gen;
+ string path<>; /* NULL terminated */
+ string bname<>; /* NULL terminated */
+};
+ struct gfs3_unlink_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt preparent;
+ struct gf_iatt postparent;
+};
+
+
+ struct gfs3_rmdir_req {
+ unsigned hyper gfs_id;
+ unsigned hyper par;
+ unsigned hyper gen;
+ string path<>;
+ string bname<>; /* NULL terminated */
+};
+ struct gfs3_rmdir_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt preparent;
+ struct gf_iatt postparent;
+};
+
+
+ struct gfs3_symlink_req {
+ unsigned hyper gfs_id;
+ unsigned hyper par;
+ unsigned hyper gen;
+ string path<>;
+ string bname<>;
+ string linkname<>;
+};
+ struct gfs3_symlink_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ struct gf_iatt preparent;
+ struct gf_iatt postparent;
+};
+
+
+ struct gfs3_rename_req {
+ unsigned hyper gfs_id;
+ unsigned hyper oldpar;
+ unsigned hyper oldgen;
+ unsigned hyper newpar;
+ unsigned hyper newgen;
+ string oldpath<>;
+ string oldbname<>; /* NULL terminated */
+ string newpath<>;
+ string newbname<>; /* NULL terminated */
+};
+ struct gfs3_rename_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ struct gf_iatt preoldparent;
+ struct gf_iatt postoldparent;
+ struct gf_iatt prenewparent;
+ struct gf_iatt postnewparent;
+};
+
+
+ struct gfs3_link_req {
+ unsigned hyper gfs_id;
+ unsigned hyper oldino;
+ unsigned hyper oldgen;
+ unsigned hyper newpar;
+ unsigned hyper newgen;
+ string oldpath<>;
+ string newpath<>;
+ string newbname<>;
+};
+ struct gfs3_link_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ struct gf_iatt preparent;
+ struct gf_iatt postparent;
+};
+
+ struct gfs3_truncate_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ unsigned hyper offset;
+ string path<>;
+};
+ struct gfs3_truncate_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt prestat;
+ struct gf_iatt poststat;
+};
+
+
+ struct gfs3_open_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ unsigned int flags;
+ unsigned int wbflags;
+ string path<>;
+};
+ struct gfs3_open_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ hyper fd;
+};
+
+
+ struct gfs3_read_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+ unsigned hyper offset;
+ unsigned int size;
+};
+ struct gfs3_read_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ string buf<>;
+} ;
+
+struct gfs3_lookup_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino; /* NOTE: used only in case of 'root' lookup */
+ unsigned hyper par;
+ unsigned hyper gen;
+ unsigned int flags;
+ string path<>;
+ string bname<>;
+ opaque dict<>;
+};
+ struct gfs3_lookup_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ struct gf_iatt postparent;
+ opaque dict<>;
+} ;
+
+
+
+ struct gfs3_write_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+ unsigned hyper offset;
+ unsigned int size;
+};
+ struct gfs3_write_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt prestat;
+ struct gf_iatt poststat;
+} ;
+
+
+ struct gfs3_statfs_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ string path<>;
+} ;
+ struct gfs3_statfs_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_statfs statfs;
+} ;
+
+ struct gfs3_lk_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+ unsigned int cmd;
+ unsigned int type;
+ struct gf_flock flock;
+} ;
+ struct gfs3_lk_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_flock flock;
+} ;
+
+ struct gfs3_inodelk_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ unsigned int cmd;
+ unsigned int type;
+ struct gf_flock flock;
+ string path<>;
+ string volume<>;
+} ;
+
+struct gfs3_finodelk_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+ unsigned int cmd;
+ unsigned int type;
+ struct gf_flock flock;
+ string volume<>;
+} ;
+
+
+ struct gfs3_flush_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+} ;
+
+
+ struct gfs3_fsync_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+ unsigned int data;
+} ;
+ struct gfs3_fsync_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt prestat;
+ struct gf_iatt poststat;
+} ;
+
+
+ struct gfs3_setxattr_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ unsigned int flags;
+ opaque dict<>;
+ string path<>;
+} ;
+
+
+
+ struct gfs3_fsetxattr_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+ unsigned int flags;
+ opaque dict<>;
+} ;
+
+
+
+ struct gfs3_xattrop_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ unsigned int flags;
+ opaque dict<>;
+ string path<>;
+} ;
+
+ struct gfs3_xattrop_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ opaque dict<>;
+} ;
+
+
+ struct gfs3_fxattrop_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+ unsigned int flags;
+ opaque dict<>;
+} ;
+
+ struct gfs3_fxattrop_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ opaque dict<>;
+} ;
+
+
+ struct gfs3_getxattr_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ unsigned int namelen;
+ string path<>;
+ string name<>;
+} ;
+ struct gfs3_getxattr_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ opaque dict<>;
+} ;
+
+
+ struct gfs3_fgetxattr_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+ unsigned int namelen;
+ string name<>;
+} ;
+ struct gfs3_fgetxattr_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ opaque dict<>;
+} ;
+
+
+ struct gfs3_removexattr_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ string path<>;
+ string name<>;
+} ;
+
+
+
+ struct gfs3_opendir_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ string path<>;
+} ;
+ struct gfs3_opendir_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ hyper fd;
+} ;
+
+
+ struct gfs3_fsyncdir_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+ int data;
+} ;
+
+ struct gfs3_readdir_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+ unsigned hyper offset;
+ unsigned int size;
+};
+struct gfs3_readdir_res {
+ unsigned hyper gfs_id;
+ opaque buf<>;
+} ;
+
+
+ struct gfs3_readdirp_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+ unsigned hyper offset;
+ unsigned int size;
+} ;
+ struct gfs3_readdirp_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ opaque buf<>;
+} ;
+
+
+ struct gf_setvolume_req {
+ unsigned hyper gfs_id;
+ opaque dict<>;
+} ;
+ struct gf_setvolume_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ opaque dict<>;
+} ;
+
+struct gfs3_access_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ unsigned int mask;
+ string path<>;
+} ;
+
+
+struct gfs3_create_req {
+ unsigned hyper gfs_id;
+ unsigned hyper par;
+ unsigned hyper gen;
+ unsigned int flags;
+ unsigned int mode;
+ string path<>;
+ string bname<>;
+} ;
+struct gfs3_create_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+ unsigned hyper fd;
+ struct gf_iatt preparent;
+ struct gf_iatt postparent;
+} ;
+
+
+
+struct gfs3_ftruncate_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+ unsigned hyper offset;
+} ;
+struct gfs3_ftruncate_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt prestat;
+ struct gf_iatt poststat;
+} ;
+
+
+struct gfs3_fstat_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+} ;
+ struct gfs3_fstat_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt stat;
+} ;
+
+
+
+ struct gfs3_entrylk_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ unsigned int cmd;
+ unsigned int type;
+ unsigned hyper namelen;
+ string path<>;
+ string name<>;
+ string volume<>;
+};
+
+ struct gfs3_fentrylk_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+ unsigned int cmd;
+ unsigned int type;
+ unsigned hyper namelen;
+ string name<>;
+ string volume<>;
+};
+
+
+struct gfs3_checksum_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ unsigned int flag;
+ string path<>;
+};
+ struct gfs3_checksum_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ opaque fchecksum<>;
+ opaque dchecksum<>;
+} ;
+
+ struct gfs3_setattr_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ struct gf_iatt stbuf;
+ int valid;
+ string path<>;
+} ;
+ struct gfs3_setattr_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt statpre;
+ struct gf_iatt statpost;
+} ;
+
+ struct gfs3_fsetattr_req {
+ unsigned hyper gfs_id;
+ hyper fd;
+ struct gf_iatt stbuf;
+ int valid;
+} ;
+ struct gfs3_fsetattr_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ struct gf_iatt statpre;
+ struct gf_iatt statpost;
+} ;
+
+ struct gfs3_rchecksum_req {
+ unsigned hyper gfs_id;
+ hyper fd;
+ unsigned hyper offset;
+ unsigned int len;
+} ;
+ struct gfs3_rchecksum_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ unsigned int weak_checksum;
+ opaque strong_checksum<>;
+} ;
+ struct gfs3_releasedir_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+} ;
+
+struct gfs3_release_req {
+ unsigned hyper gfs_id;
+ unsigned hyper ino;
+ unsigned hyper gen;
+ hyper fd;
+} ;
+
+
+ struct gf_getspec_req {
+ unsigned hyper gfs_id;
+ unsigned int flags;
+ string key<>;
+} ;
+ struct gf_getspec_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ string spec<>;
+} ;
+
+
+ struct gf_log_req {
+ unsigned hyper gfs_id;
+ opaque msg<>;
+};
+
+ struct gf_notify_req {
+ unsigned hyper gfs_id;
+ unsigned int flags;
+ string buf<>;
+} ;
+ struct gf_notify_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ unsigned int flags;
+ string buf<>;
+} ;
+
+
+
+struct gf_common_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+} ;
+
+
+struct gf_dump_version_req {
+ unsigned hyper gfs_id;
+ unsigned int flags;
+ string key<>;
+};
+
+
+struct gf_dump_version_rsp {
+ unsigned hyper gfs_id;
+ int op_ret;
+ int op_errno;
+ unsigned int flags;
+ opaque msg<>;
+};
+
+struct auth_glusterfs_parms {
+ unsigned int pid;
+ unsigned int uid;
+ unsigned int gid;
+
+ /* Number of groups being sent through the array above. */
+ unsigned int ngrps;
+
+ /* Array of groups to which the uid belongs apart from the primary group
+ * in gid.
+ */
+ unsigned int groups[GF_REQUEST_MAXGROUPS];
+
+ unsigned hyper lk_owner;
+};
diff --git a/xlators/protocol/lib/src/msg-xdr.c b/xlators/protocol/lib/src/msg-xdr.c
new file mode 100644
index 0000000..8cab372
--- /dev/null
+++ b/xlators/protocol/lib/src/msg-xdr.c
@@ -0,0 +1,1264 @@
+/*
+ Copyright (c) 2007-2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+#include "msg-xdr.h"
+
+
+ssize_t
+xdr_serialize_generic (struct iovec outmsg, void *res, xdrproc_t proc)
+{
+ ssize_t ret = -1;
+ XDR xdr;
+
+ if ((!outmsg.iov_base) || (!res) || (!proc))
+ return -1;
+
+ xdrmem_create (&xdr, outmsg.iov_base, (unsigned int)outmsg.iov_len,
+ XDR_ENCODE);
+
+ if (!proc (&xdr, res)) {
+ ret = -1;
+ goto ret;
+ }
+
+ ret = xdr_encoded_length (xdr);
+
+ret:
+ return ret;
+}
+
+
+ssize_t
+xdr_to_generic (struct iovec inmsg, void *args, xdrproc_t proc)
+{
+ XDR xdr;
+ ssize_t ret = -1;
+
+ if ((!inmsg.iov_base) || (!args) || (!proc))
+ return -1;
+
+ xdrmem_create (&xdr, inmsg.iov_base, (unsigned int)inmsg.iov_len,
+ XDR_DECODE);
+
+ if (!proc (&xdr, args)) {
+ ret = -1;
+ goto ret;
+ }
+
+ ret = xdr_decoded_length (xdr);
+ret:
+ return ret;
+}
+
+
+ssize_t
+xdr_to_generic_payload (struct iovec inmsg, void *args, xdrproc_t proc,
+ struct iovec *pendingpayload)
+{
+ XDR xdr;
+ ssize_t ret = -1;
+
+ if ((!inmsg.iov_base) || (!args) || (!proc))
+ return -1;
+
+ xdrmem_create (&xdr, inmsg.iov_base, (unsigned int)inmsg.iov_len,
+ XDR_DECODE);
+
+ if (!proc (&xdr, args)) {
+ ret = -1;
+ goto ret;
+ }
+
+ ret = xdr_decoded_length (xdr);
+
+ if (pendingpayload) {
+ pendingpayload->iov_base = xdr_decoded_remaining_addr (xdr);
+ pendingpayload->iov_len = xdr_decoded_remaining_len (xdr);
+ }
+
+ret:
+ return ret;
+}
+
+/* Encode */
+
+ssize_t
+xdr_serialize_getspec_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gf_getspec_rsp);
+
+}
+
+ssize_t
+xdr_serialize_lookup_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_lookup_rsp);
+
+}
+
+ssize_t
+xdr_serialize_common_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gf_common_rsp);
+
+}
+
+ssize_t
+xdr_serialize_setvolume_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gf_setvolume_rsp);
+
+}
+ssize_t
+xdr_serialize_statfs_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_statfs_rsp);
+
+}
+ssize_t
+xdr_serialize_stat_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_stat_rsp);
+
+}
+ssize_t
+xdr_serialize_fstat_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_fstat_rsp);
+
+}
+ssize_t
+xdr_serialize_open_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_open_rsp);
+
+}
+ssize_t
+xdr_serialize_read_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_read_rsp);
+
+}
+ssize_t
+xdr_serialize_write_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_write_rsp);
+
+}
+ssize_t
+xdr_serialize_rename_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_rename_rsp);
+
+}
+ssize_t
+xdr_serialize_fsync_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_fsync_rsp);
+
+}
+ssize_t
+xdr_serialize_rmdir_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_rmdir_rsp);
+}
+ssize_t
+xdr_serialize_unlink_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_unlink_rsp);
+}
+ssize_t
+xdr_serialize_writev_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_write_rsp);
+}
+ssize_t
+xdr_serialize_readv_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_read_rsp);
+}
+ssize_t
+xdr_serialize_readdir_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_readdir_rsp);
+}
+ssize_t
+xdr_serialize_readdirp_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_readdirp_rsp);
+}
+ssize_t
+xdr_serialize_rchecksum_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_rchecksum_rsp);
+}
+ssize_t
+xdr_serialize_setattr_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_setattr_rsp);
+}
+ssize_t
+xdr_serialize_fsetattr_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_fsetattr_rsp);
+}
+
+ssize_t
+xdr_serialize_readlink_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_readlink_rsp);
+
+}
+ssize_t
+xdr_serialize_symlink_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_symlink_rsp);
+
+}
+ssize_t
+xdr_serialize_create_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_create_rsp);
+
+}
+ssize_t
+xdr_serialize_link_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_link_rsp);
+
+}
+ssize_t
+xdr_serialize_mkdir_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_mkdir_rsp);
+
+}
+ssize_t
+xdr_serialize_mknod_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_mknod_rsp);
+
+}
+ssize_t
+xdr_serialize_getxattr_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_getxattr_rsp);
+
+}
+ssize_t
+xdr_serialize_fgetxattr_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_fgetxattr_rsp);
+
+}
+ssize_t
+xdr_serialize_xattrop_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_xattrop_rsp);
+
+}
+ssize_t
+xdr_serialize_fxattrop_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_fxattrop_rsp);
+}
+
+ssize_t
+xdr_serialize_truncate_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_truncate_rsp);
+}
+
+ssize_t
+xdr_serialize_lk_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_lk_rsp);
+}
+
+ssize_t
+xdr_serialize_opendir_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_opendir_rsp);
+}
+
+ssize_t
+xdr_serialize_checksum_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_checksum_rsp);
+}
+
+ssize_t
+xdr_serialize_ftruncate_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_ftruncate_rsp);
+}
+
+
+ssize_t
+xdr_serialize_dump_version_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_serialize_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gf_dump_version_rsp);
+}
+
+
+/* Decode */
+
+
+ssize_t
+xdr_to_dump_version_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gf_dump_version_req);
+}
+
+ssize_t
+xdr_to_lookup_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_lookup_req);
+}
+
+ssize_t
+xdr_to_getspec_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gf_getspec_req);
+
+}
+
+ssize_t
+xdr_to_setvolume_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gf_setvolume_req);
+
+}
+
+ssize_t
+xdr_to_statfs_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_statfs_req);
+
+}
+
+ssize_t
+xdr_to_fsync_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_fsync_req);
+
+}
+
+ssize_t
+xdr_to_flush_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_flush_req);
+
+}
+
+ssize_t
+xdr_to_xattrop_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_xattrop_req);
+
+}
+
+ssize_t
+xdr_to_fxattrop_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_fxattrop_req);
+
+}
+
+ssize_t
+xdr_to_getxattr_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_getxattr_req);
+
+}
+ssize_t
+xdr_to_fgetxattr_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_fgetxattr_req);
+
+}
+ssize_t
+xdr_to_open_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_open_req);
+
+}
+ssize_t
+xdr_to_create_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_create_req);
+
+}
+ssize_t
+xdr_to_symlink_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_symlink_req);
+}
+ssize_t
+xdr_to_link_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_link_req);
+}
+ssize_t
+xdr_to_readlink_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_readlink_req);
+}
+ssize_t
+xdr_to_rename_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_rename_req);
+}
+ssize_t
+xdr_to_mkdir_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_mkdir_req);
+}
+ssize_t
+xdr_to_mknod_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_mknod_req);
+}
+ssize_t
+xdr_to_readv_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_read_req);
+}
+ssize_t
+xdr_to_writev_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_write_req);
+}
+
+ssize_t
+xdr_to_readdir_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_readdir_req);
+}
+
+ssize_t
+xdr_to_opendir_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_opendir_req);
+}
+
+ssize_t
+xdr_to_rmdir_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_rmdir_req);
+}
+
+ssize_t
+xdr_to_fsetxattr_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_fsetxattr_req);
+}
+ssize_t
+xdr_to_setattr_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_setattr_req);
+}
+ssize_t
+xdr_to_fsetattr_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_fsetattr_req);
+}
+
+ssize_t
+xdr_to_finodelk_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_finodelk_req);
+}
+
+ssize_t
+xdr_to_inodelk_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_inodelk_req);
+}
+
+ssize_t
+xdr_to_ftruncate_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_ftruncate_req);
+}
+
+ssize_t
+xdr_to_fsyncdir_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_fsyncdir_req);
+}
+
+ssize_t
+xdr_to_fstat_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_fstat_req);
+}
+
+ssize_t
+xdr_to_checksum_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_checksum_req);
+}
+ssize_t
+xdr_to_rchecksum_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_rchecksum_req);
+}
+ssize_t
+xdr_to_removexattr_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_removexattr_req);
+}
+ssize_t
+xdr_to_setxattr_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_setxattr_req);
+}
+
+ssize_t
+xdr_to_fentrylk_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_fentrylk_req);
+}
+
+ssize_t
+xdr_to_entrylk_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_entrylk_req);
+}
+
+ssize_t
+xdr_to_lk_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_lk_req);
+}
+
+ssize_t
+xdr_to_stat_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_stat_req);
+}
+
+ssize_t
+xdr_to_release_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_release_req);
+}
+
+ssize_t
+xdr_to_readdirp_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_readdirp_req);
+}
+ssize_t
+xdr_to_truncate_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_truncate_req);
+}
+ssize_t
+xdr_to_access_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_access_req);
+}
+ssize_t
+xdr_to_unlink_req (struct iovec inmsg, void *args)
+{
+ return xdr_to_generic (inmsg, (void *)args,
+ (xdrproc_t)xdr_gfs3_unlink_req);
+}
+
+ssize_t
+xdr_from_lookup_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_lookup_req);
+
+}
+
+ssize_t
+xdr_from_stat_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_stat_req);
+
+}
+
+ssize_t
+xdr_from_fstat_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_fstat_req);
+
+}
+
+ssize_t
+xdr_from_mkdir_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_mkdir_req);
+
+}
+
+ssize_t
+xdr_from_mknod_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_mknod_req);
+
+}
+
+ssize_t
+xdr_from_symlink_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_symlink_req);
+
+}
+
+ssize_t
+xdr_from_readlink_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_readlink_req);
+
+}
+
+ssize_t
+xdr_from_rename_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_rename_req);
+
+}
+
+ssize_t
+xdr_from_link_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_link_req);
+
+}
+
+ssize_t
+xdr_from_create_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_create_req);
+
+}
+
+ssize_t
+xdr_from_open_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_open_req);
+
+}
+
+ssize_t
+xdr_from_opendir_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_opendir_req);
+
+}
+
+ssize_t
+xdr_from_readdir_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_readdir_req);
+
+}
+
+ssize_t
+xdr_from_readdirp_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_readdirp_req);
+
+}
+
+ssize_t
+xdr_from_fsyncdir_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_fsyncdir_req);
+
+}
+ssize_t
+xdr_from_releasedir_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_releasedir_req);
+
+}
+ssize_t
+xdr_from_release_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_release_req);
+
+}
+ssize_t
+xdr_from_lk_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_lk_req);
+
+}
+ssize_t
+xdr_from_entrylk_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_entrylk_req);
+
+}
+ssize_t
+xdr_from_fentrylk_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_fentrylk_req);
+
+}
+ssize_t
+xdr_from_inodelk_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_inodelk_req);
+
+}
+ssize_t
+xdr_from_finodelk_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_finodelk_req);
+
+}
+ssize_t
+xdr_from_setxattr_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_setxattr_req);
+
+}
+ssize_t
+xdr_from_fsetxattr_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_fsetxattr_req);
+
+}
+ssize_t
+xdr_from_getxattr_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_getxattr_req);
+
+}
+ssize_t
+xdr_from_fgetxattr_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_fgetxattr_req);
+
+}
+ssize_t
+xdr_from_removexattr_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_removexattr_req);
+
+}
+ssize_t
+xdr_from_xattrop_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_xattrop_req);
+
+}
+ssize_t
+xdr_from_fxattrop_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_fxattrop_req);
+
+}
+ssize_t
+xdr_from_access_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_access_req);
+
+}
+ssize_t
+xdr_from_setattr_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_setattr_req);
+
+}
+ssize_t
+xdr_from_truncate_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_truncate_req);
+
+}
+ssize_t
+xdr_from_ftruncate_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_ftruncate_req);
+
+}
+ssize_t
+xdr_from_fsetattr_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_fsetattr_req);
+
+}
+ssize_t
+xdr_from_readv_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_read_req);
+
+}
+ssize_t
+xdr_from_writev_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_write_req);
+
+}
+ssize_t
+xdr_from_fsync_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_fsync_req);
+
+}
+ssize_t
+xdr_from_flush_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_flush_req);
+
+}
+ssize_t
+xdr_from_statfs_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_statfs_req);
+
+}
+ssize_t
+xdr_from_checksum_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_checksum_req);
+
+}
+ssize_t
+xdr_from_rchecksum_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_rchecksum_req);
+
+}
+ssize_t
+xdr_from_getspec_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gf_getspec_req);
+
+}
+ssize_t
+xdr_from_setvolume_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gf_setvolume_req);
+
+}
+ssize_t
+xdr_from_dump_version_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gf_dump_version_req);
+
+}
+ssize_t
+xdr_from_rmdir_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_rmdir_req);
+
+}
+ssize_t
+xdr_from_unlink_req (struct iovec outmsg, void *req)
+{
+ return xdr_serialize_generic (outmsg, (void *)req,
+ (xdrproc_t)xdr_gfs3_unlink_req);
+
+}
+
+/* Client decode */
+
+ssize_t
+xdr_to_lookup_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_lookup_rsp);
+
+}
+
+ssize_t
+xdr_to_stat_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_stat_rsp);
+
+}
+
+ssize_t
+xdr_to_fstat_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_fstat_rsp);
+
+}
+
+ssize_t
+xdr_to_mkdir_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_mkdir_rsp);
+
+}
+
+ssize_t
+xdr_to_mknod_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_mknod_rsp);
+
+}
+
+ssize_t
+xdr_to_symlink_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_symlink_rsp);
+
+}
+
+ssize_t
+xdr_to_readlink_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_readlink_rsp);
+
+}
+
+ssize_t
+xdr_to_rename_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_rename_rsp);
+
+}
+
+ssize_t
+xdr_to_link_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_link_rsp);
+
+}
+
+ssize_t
+xdr_to_create_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_create_rsp);
+
+}
+
+ssize_t
+xdr_to_open_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_open_rsp);
+
+}
+
+ssize_t
+xdr_to_opendir_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_opendir_rsp);
+
+}
+
+ssize_t
+xdr_to_readdir_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_readdir_rsp);
+
+}
+
+ssize_t
+xdr_to_readdirp_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_readdirp_rsp);
+
+}
+ssize_t
+xdr_to_lk_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_lk_rsp);
+
+}
+ssize_t
+xdr_to_getxattr_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_getxattr_rsp);
+
+}
+ssize_t
+xdr_to_fgetxattr_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_fgetxattr_rsp);
+
+}
+ssize_t
+xdr_to_xattrop_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_xattrop_rsp);
+
+}
+ssize_t
+xdr_to_fxattrop_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_fxattrop_rsp);
+
+}
+ssize_t
+xdr_to_setattr_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_setattr_rsp);
+
+}
+ssize_t
+xdr_to_truncate_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_truncate_rsp);
+
+}
+ssize_t
+xdr_to_ftruncate_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_ftruncate_rsp);
+
+}
+ssize_t
+xdr_to_fsetattr_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_fsetattr_rsp);
+
+}
+ssize_t
+xdr_to_readv_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_read_rsp);
+
+}
+ssize_t
+xdr_to_writev_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_write_rsp);
+
+}
+ssize_t
+xdr_to_fsync_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_fsync_rsp);
+
+}
+ssize_t
+xdr_to_statfs_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_statfs_rsp);
+
+}
+ssize_t
+xdr_to_checksum_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_checksum_rsp);
+
+}
+ssize_t
+xdr_to_rchecksum_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_rchecksum_rsp);
+
+}
+ssize_t
+xdr_to_getspec_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gf_getspec_rsp);
+
+}
+ssize_t
+xdr_to_setvolume_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gf_setvolume_rsp);
+
+}
+ssize_t
+xdr_to_dump_version_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gf_dump_version_rsp);
+
+}
+ssize_t
+xdr_to_rmdir_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_rmdir_rsp);
+
+}
+ssize_t
+xdr_to_unlink_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gfs3_unlink_rsp);
+
+}
+ssize_t
+xdr_to_common_rsp (struct iovec outmsg, void *rsp)
+{
+ return xdr_to_generic (outmsg, (void *)rsp,
+ (xdrproc_t)xdr_gf_common_rsp);
+
+}
diff --git a/xlators/protocol/lib/src/msg-xdr.h b/xlators/protocol/lib/src/msg-xdr.h
new file mode 100644
index 0000000..4c383e5
--- /dev/null
+++ b/xlators/protocol/lib/src/msg-xdr.h
@@ -0,0 +1,536 @@
+/*
+ Copyright (c) 2007-2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+#ifndef _MSG_XDR_H
+#define _MSG_XDR_H
+
+#include <sys/uio.h>
+
+#include "glusterfs-xdr.h"
+
+#define xdr_decoded_remaining_addr(xdr) ((&xdr)->x_private)
+#define xdr_decoded_remaining_len(xdr) ((&xdr)->x_handy)
+#define xdr_encoded_length(xdr) (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base))
+#define xdr_decoded_length(xdr) (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base))
+
+
+/* FOPS */
+ssize_t
+xdr_serialize_lookup_rsp (struct iovec outmsg, void *resp);
+
+ssize_t
+xdr_serialize_getspec_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_common_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_setvolume_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_open_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_create_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_mknod_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_mkdir_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_symlink_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_link_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_rename_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_writev_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_readv_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_readdir_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_readdirp_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_opendir_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_setattr_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_fsetattr_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_truncate_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_ftruncate_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_checksum_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_statfs_rsp (struct iovec outmsg, void *rsp);
+
+
+ssize_t
+xdr_serialize_lk_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_xattrop_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_fxattrop_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_getxattr_rsp (struct iovec outmsg, void *rsp);
+
+
+ssize_t
+xdr_serialize_fgetxattr_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_unlink_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_rmdir_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_rchecksum_rsp (struct iovec outmsg, void *rsp);
+
+
+ssize_t
+xdr_serialize_fstat_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_fsync_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_readlink_rsp (struct iovec outmsg, void *rsp);
+
+ssize_t
+xdr_serialize_stat_rsp (struct iovec outmsg, void *rsp);
+
+
+ssize_t
+xdr_to_lookup_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_getspec_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_setvolume_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_statfs_req (struct iovec inmsg, void *args);
+
+
+ssize_t
+xdr_to_stat_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_getattr_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_fstat_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_setattr_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_fsetattr_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_readv_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_writev_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_fsetattr_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_readlink_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_create_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_open_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_release_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_xattrop_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_fxattrop_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_setxattr_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_fsetxattr_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_flush_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_unlink_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_fsync_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_ftruncate_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_truncate_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_getxattr_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_fgetxattr_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_removexattr_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_entrylk_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_fentrylk_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_inodelk_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_finodelk_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_lk_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_access_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_opendir_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_readdirp_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_readdir_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_fsyncdir_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_mknod_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_mkdir_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_symlink_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_rmdir_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_checksum_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_rchecksum_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_rename_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_link_req (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_from_lookup_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_getspec_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_stat_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_access_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_truncate_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_ftruncate_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_readlink_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_writev_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_readv_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_flush_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_fstat_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_fsync_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_open_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_unlink_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_rmdir_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_fsyncdir_req (struct iovec outmsg, void *args);
+
+
+ssize_t
+xdr_from_fsetxattr_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_setxattr_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_getxattr_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_fgetxattr_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_statfs_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_opendir_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_lk_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_inodelk_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_finodelk_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_entrylk_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_fentrylk_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_removexattr_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_xattrop_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_fxattrop_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_checksum_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_rchecksum_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_readdir_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_readdirp_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_setattr_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_fsetattr_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_symlink_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_rename_req (struct iovec outmsg, void *args);
+
+
+ssize_t
+xdr_from_link_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_rename_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_create_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_mkdir_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_mknod_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_releasedir_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_release_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_dump_version_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_from_setvolume_req (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_to_setvolume_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_dump_version_rsp (struct iovec inmsg, void *args);
+
+
+ssize_t
+xdr_serialize_dump_version_rsp (struct iovec outmsg, void *args);
+
+ssize_t
+xdr_to_dump_version_req (struct iovec inmsg, void *args);
+
+
+ssize_t
+xdr_to_statfs_rsp (struct iovec inmsg, void *args);
+
+
+ssize_t
+xdr_to_stat_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_fstat_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_rename_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_readlink_rsp (struct iovec inmsg, void *args);
+
+
+ssize_t
+xdr_to_link_rsp (struct iovec inmsg, void *args);
+
+
+ssize_t
+xdr_to_access_rsp (struct iovec inmsg, void *args);
+
+
+ssize_t
+xdr_to_truncate_rsp (struct iovec inmsg, void *args);
+
+
+ssize_t
+xdr_to_ftruncate_rsp (struct iovec inmsg, void *args);
+
+
+ssize_t
+xdr_to_unlink_rsp (struct iovec inmsg, void *args);
+
+
+ssize_t
+xdr_to_rmdir_rsp (struct iovec inmsg, void *args);
+
+
+ssize_t
+xdr_to_open_rsp (struct iovec inmsg, void *args);
+
+
+ssize_t
+xdr_to_create_rsp (struct iovec inmsg, void *args);
+
+
+ssize_t
+xdr_to_mkdir_rsp (struct iovec inmsg, void *args);
+
+
+ssize_t
+xdr_to_mknod_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_setattr_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_fsetattr_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_common_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_getxattr_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_fxattrop_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_xattrop_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_symlink_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_fgetxattr_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_checksum_rsp (struct iovec inmsg, void *args);
+ssize_t
+xdr_to_rchecksum_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_lk_rsp (struct iovec inmsg, void *args);
+ssize_t
+xdr_to_readdirp_rsp (struct iovec inmsg, void *args);
+
+ssize_t
+xdr_to_readdir_rsp (struct iovec inmsg, void *args);
+ssize_t
+xdr_to_opendir_rsp (struct iovec inmsg, void *args);
+ssize_t
+xdr_to_lookup_rsp (struct iovec inmsg, void *args);
+ssize_t
+xdr_to_readv_rsp (struct iovec inmsg, void *args);
+
+#endif /* !_MSG_XDR_H */
diff --git a/xlators/protocol/lib/src/protocol-common.c b/xlators/protocol/lib/src/protocol-common.c
new file mode 100644
index 0000000..4a9845e
--- /dev/null
+++ b/xlators/protocol/lib/src/protocol-common.c
@@ -0,0 +1,109 @@
+/*
+ Copyright (c) 2007-2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+#include "globals.h"
+#include "compat.h"
+#include "protocol-common.h"
+#include "glusterfs-xdr.h"
+
+
+static int
+gf_dirent_nb_size (gf_dirent_t *entries)
+{
+ return (sizeof (struct gf_dirent_nb) + strlen (entries->d_name) + 1);
+}
+
+int
+gf_dirent_serialize (gf_dirent_t *entries, char *buf, size_t buf_size)
+{
+ struct gf_dirent_nb *entry_nb = NULL;
+ gf_dirent_t *entry = NULL;
+ int size = 0;
+ int entry_size = 0;
+
+
+ list_for_each_entry (entry, &entries->list, list) {
+ entry_size = gf_dirent_nb_size (entry);
+
+ if (buf && (size + entry_size <= buf_size)) {
+ entry_nb = (void *) (buf + size);
+
+ entry_nb->d_ino = entry->d_ino;
+ entry_nb->d_off = entry->d_off;
+ entry_nb->d_len = entry->d_len;
+ entry_nb->d_type = entry->d_type;
+
+ gf_stat_from_iatt (&entry_nb->d_stat, &entry->d_stat);
+
+ strcpy (entry_nb->d_name, entry->d_name);
+ }
+ size += entry_size;
+ }
+
+ return size;
+}
+
+
+int
+gf_dirent_unserialize (gf_dirent_t *entries, const char *buf, size_t buf_size)
+{
+ struct gf_dirent_nb *entry_nb = NULL;
+ int remaining_size = 0;
+ int least_dirent_size = 0;
+ int count = 0;
+ gf_dirent_t *entry = NULL;
+ int entry_strlen = 0;
+ int entry_len = 0;
+
+
+ remaining_size = buf_size;
+ least_dirent_size = (sizeof (struct gf_dirent_nb) + 2);
+
+ while (remaining_size >= least_dirent_size) {
+ entry_nb = (void *)(buf + (buf_size - remaining_size));
+
+ entry_strlen = strnlen (entry_nb->d_name, remaining_size);
+ if (entry_strlen == remaining_size) {
+ break;
+ }
+
+ entry_len = sizeof (gf_dirent_t) + entry_strlen + 1;
+ entry = GF_CALLOC (1, entry_len, gf_common_mt_gf_dirent_t);
+ if (!entry) {
+ break;
+ }
+
+ entry->d_ino = entry_nb->d_ino;
+ entry->d_off = entry_nb->d_off;
+ entry->d_len = entry_nb->d_len;
+ entry->d_type = entry_nb->d_type;
+
+ gf_stat_to_iatt (&entry_nb->d_stat, &entry->d_stat);
+
+ strcpy (entry->d_name, entry_nb->d_name);
+
+ list_add_tail (&entry->list, &entries->list);
+
+ remaining_size -= (sizeof (*entry_nb) + entry_strlen + 1);
+ count++;
+ }
+
+ return count;
+}
diff --git a/xlators/protocol/lib/src/protocol-common.h b/xlators/protocol/lib/src/protocol-common.h
new file mode 100644
index 0000000..98a79d0
--- /dev/null
+++ b/xlators/protocol/lib/src/protocol-common.h
@@ -0,0 +1,104 @@
+/*
+ Copyright (c) 2007-2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _PROTOCOL_COMMON_H
+#define _PROTOCOL_COMMON_H
+
+#define GF_PROTOCOL_DEFAULT_PORT 6971
+
+#define GF_LOCAL_IOV 1 /* All headers are here */
+#define GF_EXTRA_IOV 2 /* needed for write/read etc */
+
+enum gf_fop_procnum {
+ GFS3_OP_NULL, /* 0 */
+ GFS3_OP_STAT,
+ GFS3_OP_READLINK,
+ GFS3_OP_MKNOD,
+ GFS3_OP_MKDIR,
+ GFS3_OP_UNLINK,
+ GFS3_OP_RMDIR,
+ GFS3_OP_SYMLINK,
+ GFS3_OP_RENAME,
+ GFS3_OP_LINK,
+ GFS3_OP_TRUNCATE,
+ GFS3_OP_OPEN,
+ GFS3_OP_READ,
+ GFS3_OP_WRITE,
+ GFS3_OP_STATFS,
+ GFS3_OP_FLUSH,
+ GFS3_OP_FSYNC,
+ GFS3_OP_SETXATTR,
+ GFS3_OP_GETXATTR,
+ GFS3_OP_REMOVEXATTR,
+ GFS3_OP_OPENDIR,
+ GFS3_OP_FSYNCDIR,
+ GFS3_OP_ACCESS,
+ GFS3_OP_CREATE,
+ GFS3_OP_FTRUNCATE,
+ GFS3_OP_FSTAT,
+ GFS3_OP_LK,
+ GFS3_OP_LOOKUP,
+ GFS3_OP_READDIR,
+ GFS3_OP_INODELK,
+ GFS3_OP_FINODELK,
+ GFS3_OP_ENTRYLK,
+ GFS3_OP_FENTRYLK,
+ GFS3_OP_CHECKSUM,
+ GFS3_OP_XATTROP,
+ GFS3_OP_FXATTROP,
+ GFS3_OP_FGETXATTR,
+ GFS3_OP_FSETXATTR,
+ GFS3_OP_RCHECKSUM,
+ GFS3_OP_SETATTR,
+ GFS3_OP_FSETATTR,
+ GFS3_OP_READDIRP,
+ GFS3_OP_RELEASE,
+ GFS3_OP_RELEASEDIR,
+ GFS3_OP_MAXVALUE,
+} ;
+
+enum gf_handshake_procnum {
+ GF_HNDSK_NULL,
+ GF_HNDSK_DUMP_VERSION,
+ GF_HNDSK_SETVOLUME,
+ GF_HNDSK_GETSPEC,
+ GF_HNDSK_PING,
+};
+
+enum gf_mgmt_procnum {
+ GF1_MGMT_NULL, /* 0 */
+};
+
+
+#define GLUSTER3_1_FOP_PROGRAM 1298437 /* Completely random */
+#define GLUSTER3_1_FOP_VERSION 310 /* 3.1.0 */
+#define GLUSTER3_1_FOP_PROCCNT GFS3_OP_MAXVALUE
+
+#define GLUSTER1_MGMT_PROGRAM 1298433 /* Completely random */
+#define GLUSTER1_MGMT_VERSION 1 /* 0.0.1 */
+
+#define GLUSTER_HNDSK_PROGRAM 14398633 /* Completely random */
+#define GLUSTER_HNDSK_VERSION 1 /* 0.0.1 */
+
+int
+gf_dirent_unserialize (gf_dirent_t *entries, const char *buf, size_t buf_size);
+int
+gf_dirent_serialize (gf_dirent_t *entries, char *buf, size_t buf_size);
+
+#endif /* !_PROTOCOL_COMMON_H */
diff --git a/xlators/protocol/rpc/Makefile.am b/xlators/protocol/rpc/Makefile.am
new file mode 100644
index 0000000..bd435fa
--- /dev/null
+++ b/xlators/protocol/rpc/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = rpc-lib rpc-transport
diff --git a/xlators/protocol/rpc/rpc-lib/Makefile.am b/xlators/protocol/rpc/rpc-lib/Makefile.am
new file mode 100644
index 0000000..af437a6
--- /dev/null
+++ b/xlators/protocol/rpc/rpc-lib/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = src
diff --git a/xlators/protocol/rpc/rpc-lib/src/Makefile.am b/xlators/protocol/rpc/rpc-lib/src/Makefile.am
new file mode 100644
index 0000000..4df8888
--- /dev/null
+++ b/xlators/protocol/rpc/rpc-lib/src/Makefile.am
@@ -0,0 +1,15 @@
+lib_LTLIBRARIES = libgfrpc.la
+libgfrpc_la_LDFLAGS = -module -avoidversion
+
+libgfrpc_la_SOURCES = auth-unix.c rpcsvc-auth.c rpcsvc.c auth-null.c \
+ rpc-transport.c xdr-rpc.c xdr-rpcclnt.c rpc-clnt.c auth-glusterfs.c
+libgfrpc_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
+
+noinst_HEADERS = rpcsvc.h rpc-transport.h xdr-common.h xdr-rpc.h xdr-rpcclnt.h \
+ rpc-clnt.h rpcsvc-common.h
+AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\
+ -I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS) \
+ -I$(top_srcdir)/xlators/protocol/lib/src \
+ -DRPC_TRANSPORTDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/rpc-transport\"
+
+CLEANFILES = *~
diff --git a/xlators/protocol/rpc/rpc-lib/src/auth-glusterfs.c b/xlators/protocol/rpc/rpc-lib/src/auth-glusterfs.c
new file mode 100644
index 0000000..165e52a
--- /dev/null
+++ b/xlators/protocol/rpc/rpc-lib/src/auth-glusterfs.c
@@ -0,0 +1,112 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include "rpcsvc.h"
+#include "list.h"
+#include "dict.h"
+#include "xdr-rpc.h"
+#include "glusterfs-xdr.h"
+
+ssize_t
+xdr_to_glusterfs_auth (char *buf, struct auth_glusterfs_parms *req)
+{
+ XDR xdr;
+ ssize_t ret = -1;
+
+ if ((!buf) || (!req))
+ return -1;
+
+ xdrmem_create (&xdr, buf, sizeof (struct auth_glusterfs_parms),
+ XDR_DECODE);
+ if (!xdr_auth_glusterfs_parms (&xdr, req)) {
+ ret = -1;
+ goto ret;
+ }
+
+ ret = (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base));
+ret:
+ return ret;
+
+}
+int
+auth_glusterfs_request_init (rpcsvc_request_t *req, void *priv)
+{
+ if (!req)
+ return -1;
+ memset (req->verf.authdata, 0, RPCSVC_MAX_AUTH_BYTES);
+ req->verf.datalen = 0;
+ req->verf.flavour = AUTH_NULL;
+
+ return 0;
+}
+
+int auth_glusterfs_authenticate (rpcsvc_request_t *req, void *priv)
+{
+ int ret = RPCSVC_AUTH_REJECT;
+ struct auth_glusterfs_parms au = {0,};
+
+ if (!req)
+ return ret;
+
+ ret = xdr_to_glusterfs_auth (req->cred.authdata, &au);
+ if (ret == -1) {
+ ret = RPCSVC_AUTH_REJECT;
+ goto err;
+ }
+
+ req->pid = au.pid;
+ req->uid = au.uid;
+ req->gid = au.gid;
+ req->lk_owner = au.lk_owner;
+ req->auxgidcount = au.ngrps;
+
+ gf_log (GF_RPCSVC, GF_LOG_TRACE, "Auth Info: pid: %u, uid: %d"
+ ", gid: %d, owner: %"PRId64,
+ req->pid, req->uid, req->gid, req->lk_owner);
+ ret = RPCSVC_AUTH_ACCEPT;
+err:
+ return ret;
+}
+
+rpcsvc_auth_ops_t auth_glusterfs_ops = {
+ .conn_init = NULL,
+ .request_init = auth_glusterfs_request_init,
+ .authenticate = auth_glusterfs_authenticate
+};
+
+rpcsvc_auth_t rpcsvc_auth_glusterfs = {
+ .authname = "AUTH_GLUSTERFS",
+ .authnum = AUTH_GLUSTERFS,
+ .authops = &auth_glusterfs_ops,
+ .authprivate = NULL
+};
+
+
+rpcsvc_auth_t *
+rpcsvc_auth_glusterfs_init (rpcsvc_t *svc, dict_t *options)
+{
+ return &rpcsvc_auth_glusterfs;
+}
diff --git a/xlators/protocol/rpc/rpc-lib/src/auth-null.c b/xlators/protocol/rpc/rpc-lib/src/auth-null.c
new file mode 100644
index 0000000..a2581a1
--- /dev/null
+++ b/xlators/protocol/rpc/rpc-lib/src/auth-null.c
@@ -0,0 +1,70 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include "rpcsvc.h"
+#include "list.h"
+#include "dict.h"
+
+
+int
+auth_null_request_init (rpcsvc_request_t *req, void *priv)
+{
+ if (!req)
+ return -1;
+
+ memset (req->cred.authdata, 0, RPCSVC_MAX_AUTH_BYTES);
+ req->cred.datalen = 0;
+
+ memset (req->verf.authdata, 0, RPCSVC_MAX_AUTH_BYTES);
+ req->verf.datalen = 0;
+
+ return 0;
+}
+
+int auth_null_authenticate (rpcsvc_request_t *req, void *priv)
+{
+ /* Always succeed. */
+ return RPCSVC_AUTH_ACCEPT;
+}
+
+rpcsvc_auth_ops_t auth_null_ops = {
+ .conn_init = NULL,
+ .request_init = auth_null_request_init,
+ .authenticate = auth_null_authenticate
+};
+
+rpcsvc_auth_t rpcsvc_auth_null = {
+ .authname = "AUTH_NULL",
+ .authnum = AUTH_NULL,
+ .authops = &auth_null_ops,
+ .authprivate = NULL
+};
+
+
+rpcsvc_auth_t *
+rpcsvc_auth_null_init (rpcsvc_t *svc, dict_t *options)
+{
+ return &rpcsvc_auth_null;
+}
diff --git a/xlators/protocol/rpc/rpc-lib/src/auth-unix.c b/xlators/protocol/rpc/rpc-lib/src/auth-unix.c
new file mode 100644
index 0000000..aed3c1f
--- /dev/null
+++ b/xlators/protocol/rpc/rpc-lib/src/auth-unix.c
@@ -0,0 +1,90 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include "rpcsvc.h"
+#include "list.h"
+#include "dict.h"
+#include "xdr-rpc.h"
+
+
+int
+auth_unix_request_init (rpcsvc_request_t *req, void *priv)
+{
+ if (!req)
+ return -1;
+ memset (req->verf.authdata, 0, RPCSVC_MAX_AUTH_BYTES);
+ req->verf.datalen = 0;
+ req->verf.flavour = AUTH_NULL;
+
+ return 0;
+}
+
+int auth_unix_authenticate (rpcsvc_request_t *req, void *priv)
+{
+ int ret = RPCSVC_AUTH_REJECT;
+ struct authunix_parms aup;
+ char machname[MAX_MACHINE_NAME];
+
+ if (!req)
+ return ret;
+
+ ret = xdr_to_auth_unix_cred (req->cred.authdata, req->cred.datalen,
+ &aup, machname, req->auxgids);
+ if (ret == -1) {
+ ret = RPCSVC_AUTH_REJECT;
+ goto err;
+ }
+
+ req->uid = aup.aup_uid;
+ req->gid = aup.aup_gid;
+ req->auxgidcount = aup.aup_len;
+
+ gf_log (GF_RPCSVC, GF_LOG_TRACE, "Auth Info: machine name: %s, uid: %d"
+ ", gid: %d", machname, req->uid, req->gid);
+ ret = RPCSVC_AUTH_ACCEPT;
+err:
+ return ret;
+}
+
+rpcsvc_auth_ops_t auth_unix_ops = {
+ .conn_init = NULL,
+ .request_init = auth_unix_request_init,
+ .authenticate = auth_unix_authenticate
+};
+
+rpcsvc_auth_t rpcsvc_auth_unix = {
+ .authname = "AUTH_UNIX",
+ .authnum = AUTH_UNIX,
+ .authops = &auth_unix_ops,
+ .authprivate = NULL
+};
+
+
+rpcsvc_auth_t *
+rpcsvc_auth_unix_init (rpcsvc_t *svc, dict_t *options)
+{
+ return &rpcsvc_auth_unix;
+}
diff --git a/xlators/protocol/rpc/rpc-lib/src/rpc-clnt.c b/xlators/protocol/rpc/rpc-lib/src/rpc-clnt.c
new file mode 100644
index 0000000..92f57e5
--- /dev/null
+++ b/xlators/protocol/rpc/rpc-lib/src/rpc-clnt.c
@@ -0,0 +1,1281 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include "rpc-clnt.h"
+#include "xdr-rpcclnt.h"
+#include "rpc-transport.h"
+#include "protocol-common.h"
+
+uint64_t
+rpc_clnt_new_callid (struct rpc_clnt *clnt)
+{
+ uint64_t callid = 0;
+
+ pthread_mutex_lock (&clnt->lock);
+ {
+ callid = ++clnt->xid;
+ }
+ pthread_mutex_unlock (&clnt->lock);
+
+ return callid;
+}
+
+
+struct saved_frame *
+__saved_frames_get_timedout (struct saved_frames *frames, uint32_t timeout,
+ struct timeval *current)
+{
+ struct saved_frame *bailout_frame = NULL, *tmp = NULL;
+
+ if (!list_empty(&frames->sf.list)) {
+ tmp = list_entry (frames->sf.list.next, typeof (*tmp), list);
+ if ((tmp->saved_at.tv_sec + timeout) < current->tv_sec) {
+ bailout_frame = tmp;
+ list_del_init (&bailout_frame->list);
+ frames->count--;
+ }
+ }
+
+ return bailout_frame;
+}
+
+
+struct saved_frame *
+__saved_frames_put (struct saved_frames *frames, void *frame,
+ int32_t procnum, rpc_clnt_prog_t *prog, int64_t callid)
+{
+ struct saved_frame *saved_frame = NULL;
+
+ saved_frame = GF_CALLOC (sizeof (*saved_frame), 1, 0);
+ if (!saved_frame) {
+ gf_log ("rpc-clnt", GF_LOG_ERROR, "out of memory");
+ goto out;
+ }
+ /* THIS should be saved and set back */
+
+ INIT_LIST_HEAD (&saved_frame->list);
+
+ saved_frame->capital_this = THIS;
+ saved_frame->frame = frame;
+ saved_frame->procnum = procnum;
+ saved_frame->callid = callid;
+ saved_frame->prog = prog;
+
+ gettimeofday (&saved_frame->saved_at, NULL);
+
+ list_add_tail (&saved_frame->list, &frames->sf.list);
+ frames->count++;
+
+out:
+ return saved_frame;
+}
+
+
+void
+saved_frames_delete (struct saved_frame *saved_frame,
+ rpc_clnt_connection_t *conn)
+{
+ if (!saved_frame || !conn) {
+ goto out;
+ }
+
+ pthread_mutex_lock (&conn->lock);
+ {
+ list_del_init (&saved_frame->list);
+ conn->saved_frames->count--;
+ }
+ pthread_mutex_unlock (&conn->lock);
+
+ GF_FREE (saved_frame);
+out:
+ return;
+}
+
+
+static void
+call_bail (void *data)
+{
+ struct rpc_clnt *clnt = NULL;
+ rpc_clnt_connection_t *conn = NULL;
+ struct timeval current;
+ struct list_head list;
+ struct saved_frame *saved_frame = NULL;
+ struct saved_frame *trav = NULL;
+ struct saved_frame *tmp = NULL;
+ struct tm frame_sent_tm;
+ char frame_sent[32] = {0,};
+ struct timeval timeout = {0,};
+ gf_timer_cbk_t timer_cbk = NULL;
+ struct rpc_req req;
+ struct iovec iov = {0,};
+
+ GF_VALIDATE_OR_GOTO ("client", data, out);
+
+ clnt = data;
+
+ conn = &clnt->conn;
+
+ gettimeofday (&current, NULL);
+ INIT_LIST_HEAD (&list);
+
+ pthread_mutex_lock (&conn->lock);
+ {
+ /* Chaining to get call-always functionality from
+ call-once timer */
+ if (conn->timer) {
+ timer_cbk = conn->timer->callbk;
+
+ timeout.tv_sec = 10;
+ timeout.tv_usec = 0;
+
+ gf_timer_call_cancel (clnt->ctx, conn->timer);
+ conn->timer = gf_timer_call_after (clnt->ctx,
+ timeout,
+ call_bail,
+ (void *) clnt);
+
+ if (conn->timer == NULL) {
+ gf_log (conn->trans->name, GF_LOG_DEBUG,
+ "Cannot create bailout timer");
+ }
+ }
+
+ do {
+ saved_frame =
+ __saved_frames_get_timedout (conn->saved_frames,
+ conn->frame_timeout,
+ &current);
+ if (saved_frame)
+ list_add (&saved_frame->list, &list);
+
+ } while (saved_frame);
+ }
+ pthread_mutex_unlock (&conn->lock);
+
+ list_for_each_entry_safe (trav, tmp, &list, list) {
+ localtime_r (&trav->saved_at.tv_sec, &frame_sent_tm);
+ strftime (frame_sent, 32, "%Y-%m-%d %H:%M:%S", &frame_sent_tm);
+
+ gf_log (conn->trans->name, GF_LOG_ERROR,
+ "bailing out frame type(%s) op(%s) frame sent = %s. "
+ "frame-timeout = %d",
+ trav->prog->progname,
+ trav->prog->actor[trav->procnum].procname, frame_sent,
+ conn->frame_timeout);
+
+ trav->prog->actor [trav->procnum].cbkfn (&req, &iov, 1,
+ trav->frame);
+
+ list_del_init (&trav->list);
+ GF_FREE (trav);
+ }
+out:
+ return;
+}
+
+
+/* to be called with conn->lock held */
+struct saved_frame *
+__save_frame (struct rpc_clnt *rpc_clnt, call_frame_t *frame, int procnum,
+ rpc_clnt_prog_t *prog, uint64_t callid)
+{
+ rpc_clnt_connection_t *conn = NULL;
+ struct timeval timeout = {0, };
+ struct saved_frame *saved_frame = NULL;
+
+ conn = &rpc_clnt->conn;
+
+ saved_frame = __saved_frames_put (conn->saved_frames, frame,
+ procnum, prog, callid);
+ if (saved_frame == NULL) {
+ goto out;
+ }
+
+ /* TODO: make timeout configurable */
+ if (conn->timer == NULL) {
+ timeout.tv_sec = 10;
+ timeout.tv_usec = 0;
+ conn->timer = gf_timer_call_after (rpc_clnt->ctx,
+ timeout,
+ call_bail,
+ (void *) rpc_clnt);
+ }
+
+out:
+ return saved_frame;
+}
+
+
+struct saved_frames *
+saved_frames_new (void)
+{
+ struct saved_frames *saved_frames = NULL;
+
+ saved_frames = GF_CALLOC (sizeof (*saved_frames), 1, 0);
+ if (!saved_frames) {
+ gf_log ("rpc-clnt", GF_LOG_ERROR, "out of memory");
+ return NULL;
+ }
+
+ INIT_LIST_HEAD (&saved_frames->sf.list);
+
+ return saved_frames;
+}
+
+
+int
+__saved_frame_copy (struct saved_frames *frames, int64_t callid,
+ struct saved_frame *saved_frame)
+{
+ struct saved_frame *tmp = NULL;
+ int ret = -1;
+
+ if (!saved_frame) {
+ ret = 0;
+ goto out;
+ }
+
+ list_for_each_entry (tmp, &frames->sf.list, list) {
+ if (tmp->callid == callid) {
+ *saved_frame = *tmp;
+ ret = 0;
+ break;
+ }
+ }
+
+out:
+ return ret;
+}
+
+
+struct saved_frame *
+__saved_frame_get (struct saved_frames *frames, int64_t callid)
+{
+ struct saved_frame *saved_frame = NULL;
+ struct saved_frame *tmp = NULL;
+
+ list_for_each_entry (tmp, &frames->sf.list, list) {
+ if (tmp->callid == callid) {
+ list_del_init (&tmp->list);
+ frames->count--;
+ saved_frame = tmp;
+ break;
+ }
+ }
+
+ if (saved_frame) {
+ THIS = saved_frame->capital_this;
+ }
+
+ return saved_frame;
+}
+
+void
+saved_frames_unwind (struct saved_frames *saved_frames)
+{
+ struct saved_frame *trav = NULL;
+ struct saved_frame *tmp = NULL;
+
+ struct rpc_req req;
+ struct iovec iov = {0,};
+
+ memset (&req, 0, sizeof (req));
+
+ req.rpc_status = -1;
+
+ list_for_each_entry_safe (trav, tmp, &saved_frames->sf.list, list) {
+ gf_log ("rpc-clnt", GF_LOG_ERROR,
+ "forced unwinding frame type(%s) op(%s)",
+ trav->prog->progname,
+ trav->prog->actor [trav->procnum].procname);
+
+ saved_frames->count--;
+
+ trav->prog->actor [trav->procnum].cbkfn (&req, &iov, 1,
+ trav->frame);
+
+ list_del_init (&trav->list);
+ GF_FREE (trav);
+ }
+}
+
+
+void
+saved_frames_destroy (struct saved_frames *frames)
+{
+ saved_frames_unwind (frames);
+
+ GF_FREE (frames);
+}
+
+
+void
+rpc_clnt_reconnect (void *trans_ptr)
+{
+ rpc_transport_t *trans = NULL;
+ rpc_clnt_connection_t *conn = NULL;
+ struct timeval tv = {0, 0};
+ int32_t ret = 0;
+ struct rpc_clnt *clnt = NULL;
+
+ trans = trans_ptr;
+ if (!trans || !trans->mydata)
+ return;
+
+ conn = trans->mydata;
+ clnt = conn->rpc_clnt;
+
+ pthread_mutex_lock (&conn->lock);
+ {
+ if (conn->reconnect)
+ gf_timer_call_cancel (clnt->ctx,
+ conn->reconnect);
+ conn->reconnect = 0;
+
+ if (conn->connected == 0) {
+ tv.tv_sec = 3;
+
+ gf_log (trans->name, GF_LOG_TRACE,
+ "attempting reconnect");
+ ret = rpc_transport_connect (trans);
+
+ conn->reconnect =
+ gf_timer_call_after (clnt->ctx, tv,
+ rpc_clnt_reconnect,
+ trans);
+ } else {
+ gf_log (trans->name, GF_LOG_TRACE,
+ "breaking reconnect chain");
+ }
+ }
+ pthread_mutex_unlock (&conn->lock);
+
+ if ((ret == -1) && (errno != EINPROGRESS) && (clnt->notifyfn)) {
+ clnt->notifyfn (clnt, clnt->mydata, RPC_CLNT_DISCONNECT, NULL);
+ }
+
+ return;
+}
+
+
+int
+rpc_clnt_fill_request_info (struct rpc_clnt *clnt, rpc_request_info_t *info)
+{
+ struct saved_frame saved_frame = {{}, 0};
+ int ret = -1;
+
+ pthread_mutex_lock (&clnt->conn.lock);
+ {
+ ret = __saved_frame_copy (clnt->conn.saved_frames, info->xid,
+ &saved_frame);
+ }
+ pthread_mutex_unlock (&clnt->conn.lock);
+
+ if (ret == -1) {
+ gf_log ("rpc-clnt", GF_LOG_CRITICAL, "cannot lookup the saved "
+ "frame corresponding to xid (%d)", info->xid);
+ goto out;
+ }
+
+ info->prognum = saved_frame.prog->prognum;
+ info->procnum = saved_frame.procnum;
+ info->progver = saved_frame.prog->progver;
+ info->rsp = saved_frame.rsp;
+
+ ret = 0;
+out:
+ return ret;
+}
+
+
+/*
+ * client_protocol_cleanup - cleanup function
+ * @trans: transport object
+ *
+ */
+int
+rpc_clnt_connection_cleanup (rpc_clnt_connection_t *conn)
+{
+ struct saved_frames *saved_frames = NULL;
+ struct rpc_clnt *clnt = NULL;
+
+ if (!conn) {
+ goto out;
+ }
+
+ clnt = conn->rpc_clnt;
+
+ gf_log ("rpc-clnt", GF_LOG_DEBUG,
+ "cleaning up state in transport object %p", conn->trans);
+
+ pthread_mutex_lock (&conn->lock);
+ {
+ saved_frames = conn->saved_frames;
+ conn->saved_frames = saved_frames_new ();
+
+ /* bailout logic cleanup */
+ if (conn->timer) {
+ gf_timer_call_cancel (clnt->ctx, conn->timer);
+ conn->timer = NULL;
+ }
+
+ if (conn->reconnect == NULL) {
+ /* :O This part is empty.. any thing missing? */
+ }
+
+ conn->connected = 0;
+ }
+ pthread_mutex_unlock (&conn->lock);
+
+ saved_frames_destroy (saved_frames);
+
+out:
+ return 0;
+}
+
+/*
+ * lookup_frame - lookup call frame corresponding to a given callid
+ * @trans: transport object
+ * @callid: call id of the frame
+ *
+ * not for external reference
+ */
+
+static struct saved_frame *
+lookup_frame (rpc_clnt_connection_t *conn, int64_t callid)
+{
+ struct saved_frame *frame = NULL;
+
+ pthread_mutex_lock (&conn->lock);
+ {
+ frame = __saved_frame_get (conn->saved_frames, callid);
+ }
+ pthread_mutex_unlock (&conn->lock);
+
+ return frame;
+}
+
+
+int
+rpc_clnt_reply_fill (rpc_transport_pollin_t *msg,
+ rpc_clnt_connection_t *conn,
+ struct rpc_msg *replymsg, struct iovec progmsg,
+ struct rpc_req *req, struct saved_frame *saved_frame)
+{
+ int ret = -1;
+
+ if ((!conn) || (!replymsg)|| (!req) || (!saved_frame) || (!msg)) {
+ goto out;
+ }
+
+ req->rpc_status = 0;
+ if ((rpc_reply_status (replymsg) == MSG_DENIED)
+ || (rpc_accepted_reply_status (replymsg) != SUCCESS)) {
+ req->rpc_status = -1;
+ }
+
+ req->xid = rpc_reply_xid (replymsg);
+ req->prog = saved_frame->prog;
+ req->procnum = saved_frame->procnum;
+ req->conn = conn;
+
+ req->rsp[0] = progmsg;
+
+ if (msg->vectored) {
+ req->rsp[1].iov_base = iobuf_ptr (msg->data.vector.iobuf2);
+ req->rsp[1].iov_len = msg->data.vector.size2;
+
+ req->rspcnt = 2;
+
+ req->rsp_prochdr = iobuf_ref (msg->data.vector.iobuf1);
+ req->rsp_procpayload = iobuf_ref (msg->data.vector.iobuf2);
+ } else {
+ req->rspcnt = 1;
+
+ req->rsp_prochdr = iobuf_ref (msg->data.simple.iobuf);
+ }
+
+ /* By this time, the data bytes for the auth scheme would have already
+ * been copied into the required sections of the req structure,
+ * we just need to fill in the meta-data about it now.
+ */
+ if (req->rpc_status == 0) {
+ /*
+ * req->verf.flavour = rpc_reply_verf_flavour (replymsg);
+ * req->verf.datalen = rpc_reply_verf_len (replymsg);
+ */
+ }
+
+ ret = 0;
+
+out:
+ return ret;
+}
+
+
+void
+rpc_clnt_reply_deinit (struct rpc_req *req)
+{
+ if (!req) {
+ goto out;
+ }
+
+ if (req->rsp_prochdr) {
+ iobuf_unref (req->rsp_prochdr);
+ }
+
+ if (req->rsp_procpayload) {
+ iobuf_unref (req->rsp_procpayload);
+ }
+
+out:
+ return;
+}
+
+
+/* TODO: use mem-pool for allocating requests */
+int
+rpc_clnt_reply_init (rpc_clnt_connection_t *conn, rpc_transport_pollin_t *msg,
+ struct rpc_req *req, struct saved_frame *saved_frame)
+{
+ char *msgbuf = NULL;
+ struct rpc_msg rpcmsg;
+ struct iovec progmsg; /* RPC Program payload */
+ size_t msglen = 0;
+ int ret = -1;
+
+ if (msg->vectored) {
+ msgbuf = iobuf_ptr (msg->data.vector.iobuf1);
+ msglen = msg->data.vector.size1;
+ } else {
+ msgbuf = iobuf_ptr (msg->data.simple.iobuf);
+ msglen = msg->data.simple.size;
+ }
+
+ ret = xdr_to_rpc_reply (msgbuf, msglen, &rpcmsg, &progmsg,
+ req->verf.authdata);
+ if (ret != 0) {
+ gf_log ("rpc-clnt", GF_LOG_ERROR, "RPC reply decoding failed");
+ goto out;
+ }
+
+ ret = rpc_clnt_reply_fill (msg, conn, &rpcmsg, progmsg, req,
+ saved_frame);
+ if (ret != 0) {
+ goto out;
+ }
+
+ gf_log ("rpc-clnt", GF_LOG_TRACE, "RPC XID: %"PRIx64", Program: %s,"
+ " ProgVers: %d, Proc: %d", saved_frame->callid,
+ saved_frame->prog->progname, saved_frame->prog->progver,
+ saved_frame->procnum);
+/* TODO: */
+ /* TODO: AUTH */
+ /* The verifier that is sent in a reply is a string that can be used as
+ * a shorthand in credentials for future transactions. We can opt not to
+ * use this shorthand, preffering to use the original AUTH_UNIX method
+ * for authentication (containing all the details for authentication in
+ * credential itself). Hence it is not mandatory for us to be checking
+ * the verifier. See Appendix A of rfc-5531 for more details.
+ */
+
+ /*
+ * ret = rpc_authenticate (req);
+ * if (ret == RPC_AUTH_REJECT) {
+ * gf_log ("rpc-clnt", GF_LOG_ERROR, "Failed authentication");
+ * ret = -1;
+ * goto out;
+ * }
+ */
+
+ /* If the error is not RPC_MISMATCH, we consider the call as accepted
+ * since we are not handling authentication failures for now.
+ */
+ req->rpc_status = 0;
+
+out:
+ if (ret != 0) {
+ req->rpc_status = -1;
+ }
+
+ return ret;
+}
+
+
+int
+rpc_clnt_handle_reply (struct rpc_clnt *clnt, rpc_transport_pollin_t *pollin)
+{
+ rpc_clnt_connection_t *conn = NULL;
+ struct saved_frame *saved_frame = NULL;
+ rpc_request_info_t *request_info = NULL;
+ int ret = -1;
+ struct rpc_req req = {0, };
+
+ conn = &clnt->conn;
+
+ request_info = pollin->private;
+
+ saved_frame = lookup_frame (conn, (int64_t)request_info->xid);
+ if (saved_frame == NULL) {
+ gf_log ("rpc-clnt", GF_LOG_CRITICAL, "cannot lookup the "
+ "saved frame for reply with xid (%d), "
+ "prog-version (%d), prog-num (%d),"
+ "procnum (%d)", request_info->xid,
+ request_info->progver, request_info->prognum,
+ request_info->procnum);
+ goto out;
+ }
+
+ ret = rpc_clnt_reply_init (conn, pollin, &req, saved_frame);
+ if (ret != 0) {
+ req.rpc_status = -1;
+ gf_log ("rpc-clnt", GF_LOG_DEBUG, "initialising rpc reply "
+ "failed");
+ }
+
+ saved_frame->prog->actor [request_info->procnum].cbkfn (&req, req.rsp,
+ req.rspcnt,
+ saved_frame->frame);
+
+ if (ret == 0) {
+ rpc_clnt_reply_deinit (&req);
+ }
+
+ ret = 0;
+out:
+
+ if (saved_frame) {
+ GF_FREE (saved_frame);
+ }
+
+ return ret;
+}
+
+
+inline void
+rpc_clnt_set_connected (rpc_clnt_connection_t *conn)
+{
+ if (!conn) {
+ goto out;
+ }
+
+ pthread_mutex_lock (&conn->lock);
+ {
+ conn->connected = 1;
+ }
+ pthread_mutex_unlock (&conn->lock);
+
+out:
+ return;
+}
+
+
+void
+rpc_clnt_unset_connected (rpc_clnt_connection_t *conn)
+{
+ if (!conn) {
+ goto out;
+ }
+
+ pthread_mutex_lock (&conn->lock);
+ {
+ conn->connected = 0;
+ }
+ pthread_mutex_unlock (&conn->lock);
+
+out:
+ return;
+}
+
+
+int
+rpc_clnt_notify (rpc_transport_t *trans, void *mydata,
+ rpc_transport_event_t event, void *data, ...)
+{
+ rpc_clnt_connection_t *conn = NULL;
+ struct rpc_clnt *clnt = NULL;
+ int ret = -1;
+ rpc_request_info_t *req_info = NULL;
+ rpc_transport_pollin_t *pollin = NULL;
+ struct timeval tv = {0, };
+
+ conn = mydata;
+ if (conn == NULL) {
+ goto out;
+ }
+ clnt = conn->rpc_clnt;
+
+ switch (event) {
+ case RPC_TRANSPORT_DISCONNECT:
+ {
+ rpc_clnt_connection_cleanup (&clnt->conn);
+
+ pthread_mutex_lock (&conn->lock);
+ {
+ if (conn->reconnect == NULL) {
+ tv.tv_sec = 10;
+
+ conn->reconnect =
+ gf_timer_call_after (clnt->ctx, tv,
+ rpc_clnt_reconnect,
+ conn->trans);
+ }
+ }
+ pthread_mutex_unlock (&conn->lock);
+
+ ret = clnt->notifyfn (clnt, clnt->mydata, RPC_CLNT_DISCONNECT,
+ NULL);
+ break;
+ }
+
+ case RPC_TRANSPORT_CLEANUP:
+ /* this event should not be received on a client for, a
+ * transport is only disconnected, but never destroyed.
+ */
+ ret = 0;
+ break;
+
+ case RPC_TRANSPORT_MAP_XID_REQUEST:
+ {
+ req_info = data;
+ ret = rpc_clnt_fill_request_info (clnt, req_info);
+ break;
+ }
+
+ case RPC_TRANSPORT_MSG_RECEIVED:
+ {
+ pollin = data;
+ ret = rpc_clnt_handle_reply (clnt, pollin);
+ /* ret = clnt->notifyfn (clnt, clnt->mydata, RPC_CLNT_MSG,
+ * data);
+ */
+ break;
+ }
+
+ case RPC_TRANSPORT_MSG_SENT:
+ {
+ pthread_mutex_lock (&conn->lock);
+ {
+ gettimeofday (&conn->last_sent, NULL);
+ }
+ pthread_mutex_unlock (&conn->lock);
+
+ ret = 0;
+ break;
+ }
+
+ case RPC_TRANSPORT_CONNECT:
+ {
+ ret = clnt->notifyfn (clnt, clnt->mydata, RPC_CLNT_CONNECT, NULL);
+ break;
+ }
+
+ case RPC_TRANSPORT_ACCEPT:
+ /* only meaningful on a server, no need of handling this event
+ * in a client.
+ */
+ ret = 0;
+ break;
+ }
+
+out:
+ return ret;
+}
+
+
+void
+rpc_clnt_connection_deinit (rpc_clnt_connection_t *conn)
+{
+ return;
+}
+
+
+inline int
+rpc_clnt_connection_init (struct rpc_clnt *clnt, glusterfs_ctx_t *ctx,
+ dict_t *options, char *name)
+{
+ int ret = -1;
+ rpc_clnt_connection_t *conn = NULL;
+
+ conn = &clnt->conn;
+ pthread_mutex_init (&clnt->conn.lock, NULL);
+
+ ret = dict_get_int32 (options, "frame-timeout",
+ &conn->frame_timeout);
+ if (ret >= 0) {
+ gf_log (name, GF_LOG_DEBUG,
+ "setting frame-timeout to %d", conn->frame_timeout);
+ } else {
+ gf_log (name, GF_LOG_DEBUG,
+ "defaulting frame-timeout to 30mins");
+ conn->frame_timeout = 1800;
+ }
+
+ conn->trans = rpc_transport_load (ctx, options, name);
+ if (!conn->trans) {
+ gf_log ("rpc-clnt", GF_LOG_DEBUG, "loading of new rpc-transport"
+ " failed");
+ goto out;
+ }
+
+ rpc_transport_ref (conn->trans);
+
+ conn->rpc_clnt = clnt;
+
+ ret = rpc_transport_register_notify (conn->trans, rpc_clnt_notify,
+ conn);
+ if (ret == -1) {
+ gf_log ("rpc-clnt", GF_LOG_DEBUG, "registering notify failed");
+ rpc_clnt_connection_cleanup (conn);
+ conn = NULL;
+ goto out;
+ }
+
+ conn->saved_frames = saved_frames_new ();
+ if (!conn->saved_frames) {
+ gf_log ("rpc-clnt", GF_LOG_DEBUG, "creation of saved_frames "
+ "failed");
+ rpc_clnt_connection_cleanup (conn);
+ goto out;
+ }
+
+ rpc_clnt_reconnect (conn->trans);
+
+ ret = 0;
+
+out:
+ return ret;
+}
+
+
+struct rpc_clnt *
+rpc_clnt_init (struct rpc_clnt_config *config, dict_t *options,
+ glusterfs_ctx_t *ctx, char *name)
+{
+ int ret = -1;
+ struct rpc_clnt *rpc = NULL;
+
+ rpc = GF_CALLOC (1, sizeof (*rpc), 0);
+ if (!rpc) {
+ gf_log ("rpc-clnt", GF_LOG_ERROR, "out of memory");
+ goto out;
+ }
+
+ pthread_mutex_init (&rpc->lock, NULL);
+
+ ret = rpc_clnt_connection_init (rpc, ctx, options, name);
+ if (ret == -1) {
+ pthread_mutex_destroy (&rpc->lock);
+ GF_FREE (rpc);
+ rpc = NULL;
+ goto out;
+ }
+ rpc->ctx = ctx;
+out:
+ return rpc;
+}
+
+
+int
+rpc_clnt_register_notify (struct rpc_clnt *rpc, rpc_clnt_notify_t fn,
+ void *mydata)
+{
+ rpc->mydata = mydata;
+ rpc->notifyfn = fn;
+
+ return 0;
+}
+
+ssize_t
+xdr_serialize_glusterfs_auth (char *dest, struct auth_glusterfs_parms *au)
+{
+ ssize_t ret = -1;
+ XDR xdr;
+
+ if ((!dest) || (!au))
+ return -1;
+
+ xdrmem_create (&xdr, dest, 1024,
+ XDR_ENCODE);
+
+ if (!xdr_auth_glusterfs_parms (&xdr, au)) {
+ ret = -1;
+ goto ret;
+ }
+
+ ret = (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base));
+
+ret:
+ return ret;
+}
+
+
+int
+rpc_clnt_fill_request (int prognum, int progver, int procnum, int payload,
+ uint64_t xid, struct auth_glusterfs_parms *au,
+ struct rpc_msg *request)
+{
+ int ret = -1;
+ char dest[1024] = {0,};
+
+ if (!request) {
+ goto out;
+ }
+
+ memset (request, 0, sizeof (*request));
+
+ request->rm_xid = xid;
+ request->rm_direction = CALL;
+
+ request->rm_call.cb_rpcvers = 2;
+ request->rm_call.cb_prog = prognum;
+ request->rm_call.cb_vers = progver;
+ request->rm_call.cb_proc = procnum;
+
+ /* TODO: Using AUTH_GLUSTERFS for time-being. Make it modular in
+ * future so it is easy to plug-in new authentication schemes.
+ */
+ ret = xdr_serialize_glusterfs_auth (dest, au);
+ if (ret == -1) {
+ gf_log ("rpc-clnt", GF_LOG_DEBUG, "cannot encode credentials");
+ goto out;
+ }
+
+ request->rm_call.cb_cred.oa_flavor = AUTH_GLUSTERFS;
+ request->rm_call.cb_cred.oa_base = dest;
+ request->rm_call.cb_cred.oa_length = ret;
+
+ request->rm_call.cb_verf.oa_flavor = AUTH_NONE;
+ request->rm_call.cb_verf.oa_base = NULL;
+ request->rm_call.cb_verf.oa_length = 0;
+
+ ret = 0;
+out:
+ return ret;
+}
+
+
+void
+rpc_clnt_set_lastfrag (uint32_t *fragsize) {
+ (*fragsize) |= 0x80000000U;
+}
+
+
+void
+rpc_clnt_set_frag_header_size (uint32_t size, char *haddr)
+{
+ size = htonl (size);
+ memcpy (haddr, &size, sizeof (size));
+}
+
+
+void
+rpc_clnt_set_last_frag_header_size (uint32_t size, char *haddr)
+{
+ rpc_clnt_set_lastfrag (&size);
+ rpc_clnt_set_frag_header_size (size, haddr);
+}
+
+
+struct iovec
+rpc_clnt_record_build_header (char *recordstart, size_t rlen,
+ struct rpc_msg *request, size_t payload)
+{
+ struct iovec requesthdr = {0, };
+ struct iovec txrecord = {0, 0};
+ size_t fraglen = 0;
+ int ret = -1;
+
+ /* After leaving aside the 4 bytes for the fragment header, lets
+ * encode the RPC reply structure into the buffer given to us.
+ */
+ ret = rpc_request_to_xdr (request, (recordstart + RPC_FRAGHDR_SIZE),
+ rlen, &requesthdr);
+ if (ret == -1) {
+ gf_log ("rpc-clnt", GF_LOG_DEBUG,
+ "Failed to create RPC request");
+ goto out;
+ }
+
+ fraglen = payload + requesthdr.iov_len;
+ gf_log ("rpc-clnt", GF_LOG_TRACE, "Request fraglen %zu, payload: %zu, "
+ "rpc hdr: %zu", fraglen, payload, requesthdr.iov_len);
+
+ /* Since we're not spreading RPC records over mutiple fragments
+ * we just set this fragment as the first and last fragment for this
+ * record.
+ */
+ rpc_clnt_set_last_frag_header_size (fraglen, recordstart);
+
+ /* Even though the RPC record starts at recordstart+RPCSVC_FRAGHDR_SIZE
+ * we need to transmit the record with the fragment header, which starts
+ * at recordstart.
+ */
+ txrecord.iov_base = recordstart;
+
+ /* Remember, this is only the vec for the RPC header and does not
+ * include the payload above. We needed the payload only to calculate
+ * the size of the full fragment. This size is sent in the fragment
+ * header.
+ */
+ txrecord.iov_len = RPC_FRAGHDR_SIZE + requesthdr.iov_len;
+
+out:
+ return txrecord;
+}
+
+
+struct iobuf *
+rpc_clnt_record_build_record (struct rpc_clnt *clnt, int prognum, int progver,
+ int procnum, size_t payload, uint64_t xid,
+ struct auth_glusterfs_parms *au, struct iovec *recbuf)
+{
+ struct rpc_msg request = {0, };
+ struct iobuf *request_iob = NULL;
+ char *record = NULL;
+ struct iovec recordhdr = {0, };
+ size_t pagesize = 0;
+ int ret = -1;
+
+ if ((!clnt) || (!recbuf) || (!au)) {
+ goto out;
+ }
+
+ /* First, try to get a pointer into the buffer which the RPC
+ * layer can use.
+ */
+ request_iob = iobuf_get (clnt->ctx->iobuf_pool);
+ if (!request_iob) {
+ gf_log ("rpc-clnt", GF_LOG_ERROR, "Failed to get iobuf");
+ goto out;
+ }
+
+ pagesize = ((struct iobuf_pool *)clnt->ctx->iobuf_pool)->page_size;
+
+ record = iobuf_ptr (request_iob); /* Now we have it. */
+
+ /* Fill the rpc structure and XDR it into the buffer got above. */
+ ret = rpc_clnt_fill_request (prognum, progver, procnum, payload, xid,
+ au, &request);
+ if (ret == -1) {
+ gf_log ("rpc-clnt", GF_LOG_DEBUG, "cannot build a rpc-request "
+ "xid (%"PRIu64")", xid);
+ goto out;
+ }
+
+ recordhdr = rpc_clnt_record_build_header (record, pagesize, &request,
+ payload);
+
+ //GF_FREE (request.rm_call.cb_cred.oa_base);
+
+ if (!recordhdr.iov_base) {
+ gf_log ("rpc-clnt", GF_LOG_ERROR, "Failed to build record "
+ " header");
+ iobuf_unref (request_iob);
+ request_iob = NULL;
+ recbuf->iov_base = NULL;
+ goto out;
+ }
+
+ recbuf->iov_base = recordhdr.iov_base;
+ recbuf->iov_len = recordhdr.iov_len;
+
+out:
+ return request_iob;
+}
+
+
+struct iobuf *
+rpc_clnt_record (struct rpc_clnt *clnt, call_frame_t *call_frame,
+ rpc_clnt_prog_t *prog,int procnum, size_t payload_len,
+ struct iovec *rpchdr, uint64_t callid)
+{
+ struct auth_glusterfs_parms au = {0, };
+ struct iobuf *request_iob = NULL;
+
+ if (!prog || !rpchdr || !call_frame) {
+ goto out;
+ }
+
+ au.pid = call_frame->root->pid;
+ au.uid = call_frame->root->uid;
+ au.gid = call_frame->root->gid;
+ au.ngrps = call_frame->root->ngrps;
+ au.lk_owner = call_frame->root->lk_owner;
+ if (!au.lk_owner)
+ au.lk_owner = au.pid;
+
+ gf_log ("", GF_LOG_TRACE, "Auth Info: pid: %u, uid: %d"
+ ", gid: %d, owner: %"PRId64,
+ au.pid, au.uid, au.gid, au.lk_owner);
+
+ memcpy (au.groups, call_frame->root->groups, 16);
+
+ //rpc_transport_get_myname (clnt->conn.trans, myname, UNIX_PATH_MAX);
+ //au.aup_machname = myname;
+
+ /* Assuming the client program would like to speak to the same versioned
+ * program on server.
+ */
+ request_iob = rpc_clnt_record_build_record (clnt, prog->prognum,
+ prog->progver,
+ procnum, payload_len,
+ callid, &au,
+ rpchdr);
+ if (!request_iob) {
+ gf_log ("rpc-clnt", GF_LOG_DEBUG, "cannot build rpc-record");
+ goto out;
+ }
+
+out:
+ return request_iob;
+}
+
+
+int
+rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, int procnum,
+ struct iovec *proghdr, int proghdrcount,
+ struct iovec *progpayload, int progpayloadcount,
+ struct iobref *iobref, void *frame)
+{
+ rpc_clnt_connection_t *conn = NULL;
+ struct iobuf *request_iob = NULL;
+ struct iovec rpchdr = {0,};
+ struct rpc_req rpcreq = {0,};
+ rpc_transport_req_t req;
+ int ret = -1;
+ int proglen = 0;
+ char new_iobref = 0;
+ uint64_t callid = 0;
+
+ if (!rpc || !prog || !frame) {
+ goto out;
+ }
+
+ memset (&req, 0, sizeof (req));
+
+ if (!iobref) {
+ iobref = iobref_new ();
+ if (!iobref) {
+ gf_log ("rpc-clnt", GF_LOG_ERROR, "out of memory");
+ goto out;
+ }
+
+ new_iobref = 1;
+ }
+
+ callid = rpc_clnt_new_callid (rpc);
+
+ conn = &rpc->conn;
+
+ pthread_mutex_lock (&conn->lock);
+ {
+ if (conn->connected == 0) {
+ rpc_transport_connect (conn->trans);
+ }
+
+ ret = -1;
+
+ if (conn->connected ||
+ /* FIXME: hack!! hack!! find a neater way to do this */
+ ((prog->prognum == GLUSTER_HNDSK_PROGRAM) &&
+ ((procnum == GF_HNDSK_SETVOLUME) ||
+ (procnum == GF_HNDSK_DUMP_VERSION)))) {
+ if (proghdr) {
+ proglen += iov_length (proghdr, proghdrcount);
+ }
+
+ if (progpayload) {
+ proglen += iov_length (progpayload,
+ progpayloadcount);
+ }
+
+ request_iob = rpc_clnt_record (rpc, frame, prog,
+ procnum, proglen,
+ &rpchdr, callid);
+ if (!request_iob) {
+ gf_log ("rpc-clnt", GF_LOG_DEBUG,
+ "cannot build rpc-record");
+ goto unlock;
+ }
+
+ iobref_add (iobref, request_iob);
+
+ req.msg.rpchdr = &rpchdr;
+ req.msg.rpchdrcount = 1;
+ req.msg.proghdr = proghdr;
+ req.msg.proghdrcount = proghdrcount;
+ req.msg.progpayload = progpayload;
+ req.msg.progpayloadcount = progpayloadcount;
+ req.msg.iobref = iobref;
+
+ ret = rpc_transport_submit_request (rpc->conn.trans,
+ &req);
+ if (ret == -1) {
+ gf_log ("rpc-clnt", GF_LOG_DEBUG,
+ "transmission of rpc-request failed");
+ }
+ }
+
+ if ((ret >= 0) && frame) {
+ gettimeofday (&conn->last_sent, NULL);
+ /* Save the frame in queue */
+ __save_frame (rpc, frame, procnum, prog, callid);
+ }
+
+ }
+unlock:
+ pthread_mutex_unlock (&conn->lock);
+
+ if (ret == -1) {
+ goto out;
+ }
+
+ ret = 0;
+
+out:
+ iobuf_unref (request_iob);
+
+ if (new_iobref && iobref) {
+ iobref_unref (iobref);
+ }
+
+ if (frame && (ret == -1)) {
+ rpcreq.rpc_status = -1;
+ prog->actor [procnum].cbkfn (&rpcreq, NULL, 0, frame);
+ }
+ return ret;
+}
+
+
+void
+rpc_clnt_destroy (struct rpc_clnt *rpc)
+{
+ rpc_clnt_connection_cleanup (&rpc->conn);
+ pthread_mutex_destroy (&rpc->lock);
+ pthread_mutex_destroy (&rpc->conn.lock);
+ GF_FREE (rpc);
+ return;
+}
diff --git a/xlators/protocol/rpc/rpc-lib/src/rpc-clnt.h b/xlators/protocol/rpc/rpc-lib/src/rpc-clnt.h
new file mode 100644
index 0000000..d962d02
--- /dev/null
+++ b/xlators/protocol/rpc/rpc-lib/src/rpc-clnt.h
@@ -0,0 +1,174 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _RPC_CLNT_H
+#define _RPC_CLNT_H
+
+#include "stack.h"
+#include "rpc-transport.h"
+#include "timer.h"
+#include "glusterfs-xdr.h"
+
+typedef enum {
+ RPC_CLNT_CONNECT,
+ RPC_CLNT_DISCONNECT,
+ RPC_CLNT_MSG
+} rpc_clnt_event_t;
+
+#define AUTH_GLUSTERFS 5
+
+struct xptr_clnt;
+struct rpc_req;
+struct rpc_clnt;
+struct rpc_clnt_config;
+struct rpc_clnt_program;
+
+typedef int (*rpc_clnt_notify_t) (struct rpc_clnt *rpc, void *mydata,
+ rpc_clnt_event_t fn, void *data);
+
+typedef int (*fop_cbk_fn_t) (struct rpc_req *req, struct iovec *iov, int count,
+ void *myframe);
+
+typedef int (*clnt_fn_t) (call_frame_t *, xlator_t *,
+ struct rpc_clnt_program *, void *args);
+
+struct saved_frame {
+ union {
+ struct list_head list;
+ struct {
+ struct saved_frame *frame_next;
+ struct saved_frame *frame_prev;
+ };
+ };
+ void *capital_this;
+ void *frame;
+ struct timeval saved_at;
+ int32_t procnum;
+ struct rpc_clnt_program *prog;
+ uint64_t callid;
+ rpc_transport_rsp_t rsp;
+};
+
+
+struct saved_frames {
+ int64_t count;
+ struct saved_frame sf;
+};
+
+/* TODO: */
+struct xptr_clnt {
+ int remote_port;
+ char * remote_host;
+
+ /* xptr specific */
+ peer_info_t peerinfo;
+};
+
+/* Initialized by procnum */
+typedef struct rpc_clnt_procedure {
+ char *procname;
+ clnt_fn_t fn;
+ fop_cbk_fn_t cbkfn;
+} rpc_clnt_procedure_t;
+
+typedef struct rpc_clnt_program {
+ char *progname;
+ int prognum;
+ int progver;
+ rpc_clnt_procedure_t *actor;
+ int numproc;
+} rpc_clnt_prog_t;
+
+#define RPC_MAX_AUTH_BYTES 400
+typedef struct rpc_auth_data {
+ int flavour;
+ int datalen;
+ char authdata[RPC_MAX_AUTH_BYTES];
+} rpc_auth_data_t;
+
+#define rpc_auth_flavour(au) ((au).flavour)
+
+struct rpc_clnt_connection {
+ pthread_mutex_t lock;
+ rpc_transport_t *trans;
+ gf_timer_t *reconnect;
+ gf_timer_t *timer;
+ gf_timer_t *ping_timer;
+ struct rpc_clnt *rpc_clnt;
+ char connected;
+ struct saved_frames *saved_frames;
+ int32_t frame_timeout;
+ struct timeval last_sent;
+ struct timeval last_received;
+ int32_t ping_started;
+};
+typedef struct rpc_clnt_connection rpc_clnt_connection_t;
+
+struct rpc_req {
+ rpc_clnt_connection_t *conn;
+ uint32_t xid;
+ struct iovec req[2];
+ int reqcnt;
+ struct iovec rsp[2];
+ int rspcnt;
+ struct iobuf *rsp_prochdr;
+ struct iobuf *rsp_procpayload;
+ int rpc_status;
+ rpc_auth_data_t verf;
+ rpc_clnt_prog_t *prog;
+ int procnum;
+};
+
+struct rpc_clnt {
+ pthread_mutex_t lock;
+ rpc_clnt_notify_t notifyfn;
+ rpc_clnt_connection_t conn;
+ void *mydata;
+ uint64_t xid;
+ glusterfs_ctx_t *ctx;
+};
+
+struct rpc_clnt_config {
+ int rpc_timeout;
+ int remote_port;
+ char * remote_host;
+};
+
+
+struct rpc_clnt * rpc_clnt_init (struct rpc_clnt_config *config,
+ dict_t *options, glusterfs_ctx_t *ctx,
+ char *name);
+
+int rpc_clnt_register_notify (struct rpc_clnt *rpc, rpc_clnt_notify_t fn,
+ void *mydata);
+
+int rpc_clnt_submit (struct rpc_clnt *rpc, rpc_clnt_prog_t *prog, int procnum,
+ struct iovec *proghdr, int proghdrcount,
+ struct iovec *progpayload, int progpayloadcount,
+ struct iobref *iobref, void *frame);
+
+void rpc_clnt_destroy (struct rpc_clnt *rpc);
+
+void rpc_clnt_set_connected (rpc_clnt_connection_t *conn);
+
+void rpc_clnt_unset_connected (rpc_clnt_connection_t *conn);
+
+void rpc_clnt_reconnect (void *trans_ptr);
+
+#endif /* !_RPC_CLNT_H */
diff --git a/xlators/protocol/rpc/rpc-lib/src/rpc-transport.c b/xlators/protocol/rpc/rpc-lib/src/rpc-transport.c
new file mode 100644
index 0000000..da3ba35
--- /dev/null
+++ b/xlators/protocol/rpc/rpc-lib/src/rpc-transport.c
@@ -0,0 +1,1300 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include <dlfcn.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/poll.h>
+#include <fnmatch.h>
+#include <stdint.h>
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include "logging.h"
+#include "rpc-transport.h"
+#include "glusterfs.h"
+/* FIXME: xlator.h is needed for volume_option_t, need to define the datatype
+ * in some other header
+ */
+#include "xlator.h"
+#include "list.h"
+
+#ifndef GF_OPTION_LIST_EMPTY
+#define GF_OPTION_LIST_EMPTY(_opt) (_opt->value[0] == NULL)
+#endif
+
+/* RFC 1123 & 952 */
+static char
+valid_host_name (char *address, int length)
+{
+ int i = 0;
+ char ret = 1;
+
+ if ((length > 75) || (length == 1)) {
+ ret = 0;
+ goto out;
+ }
+
+ if (!isalnum (address[length - 1])) {
+ ret = 0;
+ goto out;
+ }
+
+ for (i = 0; i < length; i++) {
+ if (!isalnum (address[i]) && (address[i] != '.')
+ && (address[i] != '-')) {
+ ret = 0;
+ goto out;
+ }
+ }
+
+out:
+ return ret;
+}
+
+static char
+valid_ipv4_address (char *address, int length)
+{
+ int octets = 0;
+ int value = 0;
+ char *tmp = NULL, *ptr = NULL, *prev = NULL, *endptr = NULL;
+ char ret = 1;
+
+ prev = tmp = gf_strdup (address);
+ prev = strtok_r (tmp, ".", &ptr);
+
+ while (prev != NULL)
+ {
+ octets++;
+ value = strtol (prev, &endptr, 10);
+ if ((value > 255) || (value < 0) || (endptr != NULL)) {
+ ret = 0;
+ goto out;
+ }
+
+ prev = strtok_r (NULL, ".", &ptr);
+ }
+
+ if (octets != 4) {
+ ret = 0;
+ }
+
+out:
+ GF_FREE (tmp);
+ return ret;
+}
+
+
+static char
+valid_ipv6_address (char *address, int length)
+{
+ int hex_numbers = 0;
+ int value = 0;
+ char *tmp = NULL, *ptr = NULL, *prev = NULL, *endptr = NULL;
+ char ret = 1;
+
+ tmp = gf_strdup (address);
+ prev = strtok_r (tmp, ":", &ptr);
+
+ while (prev != NULL)
+ {
+ hex_numbers++;
+ value = strtol (prev, &endptr, 16);
+ if ((value > 0xffff) || (value < 0)
+ || (endptr != NULL && *endptr != '\0')) {
+ ret = 0;
+ goto out;
+ }
+
+ prev = strtok_r (NULL, ":", &ptr);
+ }
+
+ if (hex_numbers > 8) {
+ ret = 0;
+ }
+
+out:
+ GF_FREE (tmp);
+ return ret;
+}
+
+
+static char
+valid_internet_address (char *address)
+{
+ char ret = 0;
+ int length = 0;
+
+ if (address == NULL) {
+ goto out;
+ }
+
+ length = strlen (address);
+ if (length == 0) {
+ goto out;
+ }
+
+ if (valid_ipv4_address (address, length)
+ || valid_ipv6_address (address, length)
+ || valid_host_name (address, length)) {
+ ret = 1;
+ }
+
+out:
+ return ret;
+}
+
+
+int
+__volume_option_value_validate (char *name,
+ data_pair_t *pair,
+ volume_option_t *opt)
+{
+ int i = 0;
+ int ret = -1;
+ uint64_t input_size = 0;
+ long long inputll = 0;
+
+ /* Key is valid, validate the option */
+ switch (opt->type) {
+ case GF_OPTION_TYPE_XLATOR:
+ break;
+
+ case GF_OPTION_TYPE_PATH:
+ {
+ if (strstr (pair->value->data, "../")) {
+ gf_log (name, GF_LOG_ERROR,
+ "invalid path given '%s'",
+ pair->value->data);
+ ret = -1;
+ goto out;
+ }
+
+ /* Make sure the given path is valid */
+ if (pair->value->data[0] != '/') {
+ gf_log (name, GF_LOG_WARNING,
+ "option %s %s: '%s' is not an "
+ "absolute path name",
+ pair->key, pair->value->data,
+ pair->value->data);
+ }
+ ret = 0;
+ }
+ break;
+ case GF_OPTION_TYPE_INT:
+ {
+ /* Check the range */
+ if (gf_string2longlong (pair->value->data,
+ &inputll) != 0) {
+ gf_log (name, GF_LOG_ERROR,
+ "invalid number format \"%s\" in "
+ "\"option %s\"",
+ pair->value->data, pair->key);
+ goto out;
+ }
+
+ if ((opt->min == 0) && (opt->max == 0)) {
+ gf_log (name, GF_LOG_DEBUG,
+ "no range check required for "
+ "'option %s %s'",
+ pair->key, pair->value->data);
+ ret = 0;
+ break;
+ }
+ if ((inputll < opt->min) ||
+ (inputll > opt->max)) {
+ gf_log (name, GF_LOG_WARNING,
+ "'%lld' in 'option %s %s' is out of "
+ "range [%"PRId64" - %"PRId64"]",
+ inputll, pair->key,
+ pair->value->data,
+ opt->min, opt->max);
+ }
+ ret = 0;
+ }
+ break;
+ case GF_OPTION_TYPE_SIZET:
+ {
+ /* Check the range */
+ if (gf_string2bytesize (pair->value->data,
+ &input_size) != 0) {
+ gf_log (name, GF_LOG_ERROR,
+ "invalid size format \"%s\" in "
+ "\"option %s\"",
+ pair->value->data, pair->key);
+ goto out;
+ }
+
+ if ((opt->min == 0) && (opt->max == 0)) {
+ gf_log (name, GF_LOG_DEBUG,
+ "no range check required for "
+ "'option %s %s'",
+ pair->key, pair->value->data);
+ ret = 0;
+ break;
+ }
+ if ((input_size < opt->min) ||
+ (input_size > opt->max)) {
+ gf_log (name, GF_LOG_ERROR,
+ "'%"PRId64"' in 'option %s %s' is "
+ "out of range [%"PRId64" - %"PRId64"]",
+ input_size, pair->key,
+ pair->value->data,
+ opt->min, opt->max);
+ }
+ ret = 0;
+ }
+ break;
+ case GF_OPTION_TYPE_BOOL:
+ {
+ /* Check if the value is one of
+ '0|1|on|off|no|yes|true|false|enable|disable' */
+ gf_boolean_t bool_value;
+ if (gf_string2boolean (pair->value->data,
+ &bool_value) != 0) {
+ gf_log (name, GF_LOG_ERROR,
+ "option %s %s: '%s' is not a valid "
+ "boolean value",
+ pair->key, pair->value->data,
+ pair->value->data);
+ goto out;
+ }
+ ret = 0;
+ }
+ break;
+ case GF_OPTION_TYPE_STR:
+ {
+ /* Check if the '*str' is valid */
+ if (GF_OPTION_LIST_EMPTY(opt)) {
+ ret = 0;
+ goto out;
+ }
+
+ for (i = 0; (i < ZR_OPTION_MAX_ARRAY_SIZE) &&
+ opt->value[i]; i++) {
+ if (strcasecmp (opt->value[i],
+ pair->value->data) == 0) {
+ ret = 0;
+ break;
+ }
+ }
+
+ if ((i == ZR_OPTION_MAX_ARRAY_SIZE)
+ || ((i < ZR_OPTION_MAX_ARRAY_SIZE)
+ && (!opt->value[i]))) {
+ /* enter here only if
+ * 1. reached end of opt->value array and haven't
+ * validated input
+ * OR
+ * 2. valid input list is less than
+ * ZR_OPTION_MAX_ARRAY_SIZE and input has not
+ * matched all possible input values.
+ */
+ char given_array[4096] = {0,};
+ for (i = 0; (i < ZR_OPTION_MAX_ARRAY_SIZE) &&
+ opt->value[i]; i++) {
+ strcat (given_array, opt->value[i]);
+ strcat (given_array, ", ");
+ }
+
+ gf_log (name, GF_LOG_ERROR,
+ "option %s %s: '%s' is not valid "
+ "(possible options are %s)",
+ pair->key, pair->value->data,
+ pair->value->data, given_array);
+
+ goto out;
+ }
+ }
+ break;
+ case GF_OPTION_TYPE_PERCENT:
+ {
+ uint32_t percent = 0;
+
+
+ /* Check if the value is valid percentage */
+ if (gf_string2percent (pair->value->data,
+ &percent) != 0) {
+ gf_log (name, GF_LOG_ERROR,
+ "invalid percent format \"%s\" "
+ "in \"option %s\"",
+ pair->value->data, pair->key);
+ goto out;
+ }
+
+ if ((percent < 0) || (percent > 100)) {
+ gf_log (name, GF_LOG_ERROR,
+ "'%d' in 'option %s %s' is out of "
+ "range [0 - 100]",
+ percent, pair->key,
+ pair->value->data);
+ }
+ ret = 0;
+ }
+ break;
+ case GF_OPTION_TYPE_PERCENT_OR_SIZET:
+ {
+ uint32_t percent = 0;
+ uint64_t input_size = 0;
+
+ /* Check if the value is valid percentage */
+ if (gf_string2percent (pair->value->data,
+ &percent) == 0) {
+ if (percent > 100) {
+ gf_log (name, GF_LOG_DEBUG,
+ "value given was greater than 100, "
+ "assuming this is actually a size");
+ if (gf_string2bytesize (pair->value->data,
+ &input_size) == 0) {
+ /* Check the range */
+ if ((opt->min == 0) &&
+ (opt->max == 0)) {
+ gf_log (name, GF_LOG_DEBUG,
+ "no range check "
+ "required for "
+ "'option %s %s'",
+ pair->key,
+ pair->value->data);
+ // It is a size
+ ret = 0;
+ goto out;
+ }
+ if ((input_size < opt->min) ||
+ (input_size > opt->max)) {
+ gf_log (name, GF_LOG_ERROR,
+ "'%"PRId64"' in "
+ "'option %s %s' is out"
+ " of range [%"PRId64""
+ "- %"PRId64"]",
+ input_size, pair->key,
+ pair->value->data,
+ opt->min, opt->max);
+ }
+ // It is a size
+ ret = 0;
+ goto out;
+ } else {
+ // It's not a percent or size
+ gf_log (name, GF_LOG_ERROR,
+ "invalid number format \"%s\" "
+ "in \"option %s\"",
+ pair->value->data, pair->key);
+ }
+
+ }
+ // It is a percent
+ ret = 0;
+ goto out;
+ } else {
+ if (gf_string2bytesize (pair->value->data,
+ &input_size) == 0) {
+ /* Check the range */
+ if ((opt->min == 0) && (opt->max == 0)) {
+ gf_log (name, GF_LOG_DEBUG,
+ "no range check required for "
+ "'option %s %s'",
+ pair->key, pair->value->data);
+ // It is a size
+ ret = 0;
+ goto out;
+ }
+ if ((input_size < opt->min) ||
+ (input_size > opt->max)) {
+ gf_log (name, GF_LOG_ERROR,
+ "'%"PRId64"' in 'option %s %s'"
+ " is out of range [%"PRId64" -"
+ " %"PRId64"]",
+ input_size, pair->key,
+ pair->value->data,
+ opt->min, opt->max);
+ }
+ } else {
+ // It's not a percent or size
+ gf_log (name, GF_LOG_ERROR,
+ "invalid number format \"%s\" "
+ "in \"option %s\"",
+ pair->value->data, pair->key);
+ }
+ //It is a size
+ ret = 0;
+ goto out;
+ }
+
+ }
+ break;
+ case GF_OPTION_TYPE_TIME:
+ {
+ uint32_t input_time = 0;
+
+ /* Check if the value is valid percentage */
+ if (gf_string2time (pair->value->data,
+ &input_time) != 0) {
+ gf_log (name,
+ GF_LOG_ERROR,
+ "invalid time format \"%s\" in "
+ "\"option %s\"",
+ pair->value->data, pair->key);
+ goto out;
+ }
+
+ if ((opt->min == 0) && (opt->max == 0)) {
+ gf_log (name, GF_LOG_DEBUG,
+ "no range check required for "
+ "'option %s %s'",
+ pair->key, pair->value->data);
+ ret = 0;
+ goto out;
+ }
+ if ((input_time < opt->min) ||
+ (input_time > opt->max)) {
+ gf_log (name, GF_LOG_ERROR,
+ "'%"PRIu32"' in 'option %s %s' is "
+ "out of range [%"PRId64" - %"PRId64"]",
+ input_time, pair->key,
+ pair->value->data,
+ opt->min, opt->max);
+ }
+ ret = 0;
+ }
+ break;
+ case GF_OPTION_TYPE_DOUBLE:
+ {
+ double input_time = 0.0;
+
+ /* Check if the value is valid double */
+ if (gf_string2double (pair->value->data,
+ &input_time) != 0) {
+ gf_log (name,
+ GF_LOG_ERROR,
+ "invalid time format \"%s\" in \"option %s\"",
+ pair->value->data, pair->key);
+ goto out;
+ }
+
+ if (input_time < 0.0) {
+ gf_log (name,
+ GF_LOG_ERROR,
+ "invalid time format \"%s\" in \"option %s\"",
+ pair->value->data, pair->key);
+ goto out;
+ }
+
+ if ((opt->min == 0) && (opt->max == 0)) {
+ gf_log (name, GF_LOG_DEBUG,
+ "no range check required for 'option %s %s'",
+ pair->key, pair->value->data);
+ ret = 0;
+ goto out;
+ }
+ ret = 0;
+ }
+ break;
+ case GF_OPTION_TYPE_INTERNET_ADDRESS:
+ {
+ if (valid_internet_address (pair->value->data)) {
+ ret = 0;
+ }
+ }
+ break;
+ case GF_OPTION_TYPE_ANY:
+ /* NO CHECK */
+ ret = 0;
+ break;
+ }
+
+out:
+ return ret;
+}
+
+/* FIXME: this procedure should be removed from transport */
+int
+validate_volume_options (char *name, dict_t *options, volume_option_t *opt)
+{
+ int i = 0;
+ int ret = -1;
+ int index = 0;
+ volume_option_t *trav = NULL;
+ data_pair_t *pairs = NULL;
+
+ if (!opt) {
+ ret = 0;
+ goto out;
+ }
+
+ /* First search for not supported options, if any report error */
+ pairs = options->members_list;
+ while (pairs) {
+ ret = -1;
+ for (index = 0;
+ opt[index].key && opt[index].key[0] ; index++) {
+ trav = &(opt[index]);
+ for (i = 0 ;
+ (i < ZR_VOLUME_MAX_NUM_KEY) &&
+ trav->key[i]; i++) {
+ /* Check if the key is valid */
+ if (fnmatch (trav->key[i],
+ pairs->key, FNM_NOESCAPE) == 0) {
+ ret = 0;
+ break;
+ }
+ }
+ if (!ret) {
+ if (i) {
+ gf_log (name, GF_LOG_WARNING,
+ "option '%s' is deprecated, "
+ "preferred is '%s', continuing"
+ " with correction",
+ trav->key[i], trav->key[0]);
+ /* TODO: some bytes lost */
+ pairs->key = gf_strdup (trav->key[0]);
+ }
+ break;
+ }
+ }
+ if (!ret) {
+ ret = __volume_option_value_validate (name, pairs, trav);
+ if (-1 == ret) {
+ goto out;
+ }
+ }
+
+ pairs = pairs->next;
+ }
+
+ ret = 0;
+ out:
+ return ret;
+}
+
+int32_t
+rpc_transport_get_myaddr (rpc_transport_t *this, char *peeraddr, int addrlen,
+ struct sockaddr *sa, size_t salen)
+{
+ if (!this)
+ return -1;
+
+ return this->ops->get_myaddr (this, peeraddr, addrlen, sa, salen);
+}
+
+int32_t
+rpc_transport_get_myname (rpc_transport_t *this, char *hostname, int hostlen)
+{
+ if (!this)
+ return -1;
+
+ return this->ops->get_myname (this, hostname, hostlen);
+}
+
+int32_t
+rpc_transport_get_peername (rpc_transport_t *this, char *hostname, int hostlen)
+{
+ if (!this)
+ return -1;
+ return this->ops->get_peername (this, hostname, hostlen);
+}
+
+int32_t
+rpc_transport_get_peeraddr (rpc_transport_t *this, char *peeraddr, int addrlen,
+ struct sockaddr *sa, size_t salen)
+{
+ if (!this)
+ return -1;
+ return this->ops->get_peeraddr (this, peeraddr, addrlen, sa, salen);
+}
+
+void
+rpc_transport_pollin_destroy (rpc_transport_pollin_t *pollin)
+{
+ if (!pollin) {
+ goto out;
+ }
+
+ if (pollin->vectored) {
+ if (pollin->data.vector.iobuf1) {
+ iobuf_unref (pollin->data.vector.iobuf1);
+ }
+
+ if (pollin->data.vector.iobuf2) {
+ iobuf_unref (pollin->data.vector.iobuf2);
+ }
+ } else {
+ if (pollin->data.simple.iobuf) {
+ iobuf_unref (pollin->data.simple.iobuf);
+ }
+ }
+
+ if (pollin->private) {
+ /* */
+ GF_FREE (pollin->private);
+ }
+
+ GF_FREE (pollin);
+out:
+ return;
+}
+
+
+rpc_transport_pollin_t *
+rpc_transport_pollin_alloc (rpc_transport_t *this, struct iobuf *iobuf,
+ size_t size, struct iobuf *vectored_buf,
+ size_t vectored_size, void *private)
+{
+ rpc_transport_pollin_t *msg = NULL;
+ msg = GF_CALLOC (1, sizeof (*msg), 0);
+ if (!msg) {
+ gf_log ("rpc-transport", GF_LOG_ERROR, "out of memory");
+ goto out;
+ }
+
+ if (vectored_buf) {
+ msg->vectored = 1;
+ msg->data.vector.iobuf1 = iobuf_ref (iobuf);
+ msg->data.vector.size1 = size;
+
+ msg->data.vector.iobuf2 = iobuf_ref (vectored_buf);
+ msg->data.vector.size2 = vectored_size;
+ } else {
+ msg->data.simple.iobuf = iobuf_ref (iobuf);
+ msg->data.simple.size = size;
+ }
+
+ msg->private = private;
+out:
+ return msg;
+}
+
+
+rpc_transport_pollin_t *
+rpc_transport_same_process_pollin_alloc (rpc_transport_t *this,
+ struct iovec *rpchdr, int rpchdrcount,
+ struct iovec *proghdr,
+ int proghdrcount,
+ struct iovec *progpayload,
+ int progpayloadcount,
+ rpc_transport_rsp_t *rsp,
+ char is_request)
+{
+ rpc_transport_pollin_t *msg = NULL;
+ int rpchdrlen = 0, proghdrlen = 0;
+ int progpayloadlen = 0;
+ char vectored = 0;
+ char *hdr = NULL, *progpayloadbuf = NULL;
+
+ if (!rpchdr || !proghdr) {
+ goto err;
+ }
+
+ msg = GF_CALLOC (1, sizeof (*msg), 0);
+ if (!msg) {
+ gf_log ("rpc-transport", GF_LOG_ERROR, "out of memory");
+ goto err;
+ }
+
+ rpchdrlen = iov_length (rpchdr, rpchdrcount);
+ proghdrlen = iov_length (proghdr, proghdrcount);
+
+ if (progpayload) {
+ vectored = 1;
+ progpayloadlen = iov_length (progpayload, progpayloadcount);
+ }
+
+ /* FIXME: we are assuming rpchdr and proghdr will fit into
+ * an iobuf (128KB)
+ */
+ if ((rpchdrlen + proghdrlen) > this->ctx->page_size) {
+ gf_log ("rpc_transport", GF_LOG_DEBUG, "program hdr and rpc"
+ " hdr together combined (%d) is bigger than "
+ "iobuf size (%zu)", (rpchdrlen + proghdrlen),
+ this->ctx->page_size);
+ goto err;
+ }
+
+ if (vectored) {
+ msg->data.vector.iobuf1 = iobuf_get (this->ctx->iobuf_pool);
+ if (!msg->data.vector.iobuf1) {
+ gf_log ("rpc_transport", GF_LOG_ERROR,
+ "out of memory");
+ goto err;
+ }
+
+ msg->data.vector.size1 = rpchdrlen + proghdrlen;
+ hdr = iobuf_ptr (msg->data.vector.iobuf1);
+
+ if (!is_request && rsp) {
+ msg->data.vector.iobuf2 = rsp->rspbuf;
+ progpayloadbuf = rsp->rspvec->iov_base;
+ } else {
+ msg->data.vector.iobuf2 = iobuf_get (this->ctx->iobuf_pool);
+ if (!msg->data.vector.iobuf2) {
+ gf_log ("rpc_transport", GF_LOG_ERROR,
+ "out of memory");
+ goto err;
+ }
+
+ progpayloadbuf = iobuf_ptr (msg->data.vector.iobuf2);
+ }
+ msg->data.vector.size2 = progpayloadlen;
+ } else {
+ if (!is_request && rsp) {
+ /* FIXME: Assuming rspvec contains only one vector */
+ hdr = rsp->rspvec->iov_base;
+ msg->data.simple.iobuf = rsp->rspbuf;
+ } else {
+ msg->data.simple.iobuf = iobuf_get (this->ctx->iobuf_pool);
+ if (!msg->data.simple.iobuf) {
+ gf_log ("rpc_transport", GF_LOG_ERROR,
+ "out of memory");
+ goto err;
+ }
+
+ hdr = iobuf_ptr (msg->data.simple.iobuf);
+ }
+
+ msg->data.simple.size = rpchdrlen + proghdrlen;
+ }
+
+ iov_unload (hdr, rpchdr, rpchdrcount);
+ hdr += rpchdrlen;
+ iov_unload (hdr, proghdr, proghdrcount);
+
+ if (progpayload) {
+ iov_unload (progpayloadbuf, progpayload,
+ progpayloadcount);
+ }
+
+ if (is_request) {
+ msg->private = rsp;
+ }
+ return msg;
+err:
+ if (msg) {
+ rpc_transport_pollin_destroy (msg);
+ }
+
+ return NULL;
+}
+
+
+rpc_transport_handover_t *
+rpc_transport_handover_alloc (rpc_transport_pollin_t *pollin)
+{
+ rpc_transport_handover_t *msg = NULL;
+
+ msg = GF_CALLOC (1, sizeof (*msg), 0);
+ if (!msg) {
+ gf_log ("rpc_transport", GF_LOG_ERROR, "out of memory");
+ goto out;
+ }
+
+ msg->pollin = pollin;
+ INIT_LIST_HEAD (&msg->list);
+out:
+ return msg;
+}
+
+
+void
+rpc_transport_handover_destroy (rpc_transport_handover_t *msg)
+{
+ if (!msg) {
+ goto out;
+ }
+
+ if (msg->pollin) {
+ rpc_transport_pollin_destroy (msg->pollin);
+ }
+
+ GF_FREE (msg);
+
+out:
+ return;
+}
+
+
+rpc_transport_t *
+rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *trans_name)
+{
+ struct rpc_transport *trans = NULL, *return_trans = NULL;
+ char *name = NULL;
+ void *handle = NULL;
+ char *type = NULL;
+ char str[] = "ERROR";
+ int32_t ret = -1;
+ int8_t is_tcp = 0, is_unix = 0, is_ibsdp = 0;
+ volume_opt_list_t *vol_opt = NULL;
+
+ GF_VALIDATE_OR_GOTO("rpc-transport", options, fail);
+ GF_VALIDATE_OR_GOTO("rpc-transport", ctx, fail);
+ GF_VALIDATE_OR_GOTO("rpc-transport", trans_name, fail);
+
+ trans = GF_CALLOC (1, sizeof (struct rpc_transport), 0);
+ GF_VALIDATE_OR_GOTO("rpc-transport", trans, fail);
+
+ trans->name = gf_strdup (trans_name);
+ GF_VALIDATE_OR_GOTO ("rpc-transport", trans->name, fail);
+
+ trans->ctx = ctx;
+ type = str;
+
+ /* Backward compatibility */
+ ret = dict_get_str (options, "rpc-transport-type", &type);
+ if (ret < 0) {
+ ret = dict_set_str (options, "rpc-transport-type", "socket");
+ if (ret < 0)
+ gf_log ("dict", GF_LOG_DEBUG,
+ "setting rpc-transport-type failed");
+ gf_log ("rpc-transport", GF_LOG_WARNING,
+ "missing 'option rpc-transport-type'. defaulting to "
+ "\"socket\"");
+ } else {
+ {
+ /* Backword compatibility to handle * /client,
+ * * /server.
+ */
+ char *tmp = strchr (type, '/');
+ if (tmp)
+ *tmp = '\0';
+ }
+
+ is_tcp = strcmp (type, "tcp");
+ is_unix = strcmp (type, "unix");
+ is_ibsdp = strcmp (type, "ib-sdp");
+ if ((is_tcp == 0) ||
+ (is_unix == 0) ||
+ (is_ibsdp == 0)) {
+ if (is_unix == 0)
+ ret = dict_set_str (options,
+ "rpc-transport.address-family",
+ "unix");
+ if (is_ibsdp == 0)
+ ret = dict_set_str (options,
+ "rpc-transport.address-family",
+ "inet-sdp");
+
+ if (ret < 0)
+ gf_log ("dict", GF_LOG_DEBUG,
+ "setting address-family failed");
+
+ ret = dict_set_str (options,
+ "rpc-transport-type", "socket");
+ if (ret < 0)
+ gf_log ("dict", GF_LOG_DEBUG,
+ "setting rpc-transport-type failed");
+ }
+ }
+
+ ret = dict_get_str (options, "rpc-transport-type", &type);
+ if (ret < 0) {
+ gf_log ("rpc-transport", GF_LOG_ERROR,
+ "'option rpc-transport-type <xx>' missing in volume '%s'",
+ trans_name);
+ goto fail;
+ }
+
+ ret = gf_asprintf (&name, "%s/%s.so", RPC_TRANSPORTDIR, type);
+ if (-1 == ret) {
+ gf_log ("rpc-transport", GF_LOG_ERROR, "asprintf failed");
+ goto fail;
+ }
+ gf_log ("rpc-transport", GF_LOG_DEBUG,
+ "attempt to load file %s", name);
+
+ handle = dlopen (name, RTLD_NOW|RTLD_GLOBAL);
+ if (handle == NULL) {
+ gf_log ("rpc-transport", GF_LOG_ERROR, "%s", dlerror ());
+ gf_log ("rpc-transport", GF_LOG_ERROR,
+ "volume '%s': rpc-transport-type '%s' is not valid or "
+ "not found on this machine",
+ trans_name, type);
+ goto fail;
+ }
+
+ trans->ops = dlsym (handle, "tops");
+ if (trans->ops == NULL) {
+ gf_log ("rpc-transport", GF_LOG_ERROR,
+ "dlsym (rpc_transport_ops) on %s", dlerror ());
+ goto fail;
+ }
+
+ trans->init = dlsym (handle, "init");
+ if (trans->init == NULL) {
+ gf_log ("rpc-transport", GF_LOG_ERROR,
+ "dlsym (gf_rpc_transport_init) on %s", dlerror ());
+ goto fail;
+ }
+
+ trans->fini = dlsym (handle, "fini");
+ if (trans->fini == NULL) {
+ gf_log ("rpc-transport", GF_LOG_ERROR,
+ "dlsym (gf_rpc_transport_fini) on %s", dlerror ());
+ goto fail;
+ }
+
+ vol_opt = GF_CALLOC (1, sizeof (volume_opt_list_t), 0);
+ if (!vol_opt) {
+ gf_log (trans_name, GF_LOG_ERROR, "out of memory");
+ goto fail;
+ }
+
+ vol_opt->given_opt = dlsym (handle, "options");
+ if (vol_opt->given_opt == NULL) {
+ gf_log ("rpc-transport", GF_LOG_DEBUG,
+ "volume option validation not specified");
+ } else {
+ /* FIXME: is adding really needed? */
+ /* list_add_tail (&vol_opt->list, &xl->volume_options); */
+ if (-1 ==
+ validate_volume_options (trans_name, options,
+ vol_opt->given_opt)) {
+ gf_log ("rpc-transport", GF_LOG_ERROR,
+ "volume option validation failed");
+ goto fail;
+ }
+ }
+
+ ret = trans->init (trans);
+ if (ret != 0) {
+ gf_log ("rpc-transport", GF_LOG_ERROR,
+ "'%s' initialization failed", type);
+ goto fail;
+ }
+
+ trans->options = options;
+
+ pthread_mutex_init (&trans->lock, NULL);
+ return_trans = trans;
+ return return_trans;
+
+fail:
+ if (trans) {
+ if (trans->name) {
+ GF_FREE (trans->name);
+ }
+
+ GF_FREE (trans);
+ }
+
+ if (name) {
+ GF_FREE (name);
+ }
+
+ if (vol_opt) {
+ GF_FREE (vol_opt);
+ }
+
+ return NULL;
+}
+
+
+int32_t
+rpc_transport_submit_request (rpc_transport_t *this, rpc_transport_req_t *req)
+{
+ int32_t ret = -1;
+ rpc_transport_t *peer_trans = NULL;
+ rpc_transport_pollin_t *pollin = NULL;
+ rpc_transport_handover_t *handover_msg = NULL;
+ rpc_transport_rsp_t *rsp = NULL;
+
+ if (this->peer_trans) {
+ peer_trans = this->peer_trans;
+
+ rsp = GF_CALLOC (1, sizeof (*rsp), 0);
+ if (!rsp) {
+ ret = -ENOMEM;
+ goto fail;
+ }
+
+ *rsp = req->rsp;
+
+ pollin = rpc_transport_same_process_pollin_alloc (this, req->msg.rpchdr,
+ req->msg.rpchdrcount,
+ req->msg.proghdr,
+ req->msg.proghdrcount,
+ req->msg.progpayload,
+ req->msg.progpayloadcount,
+ rsp, 1);
+ if (!pollin) {
+ GF_FREE (rsp);
+ ret = -ENOMEM;
+ goto fail;
+ }
+
+ handover_msg = rpc_transport_handover_alloc (pollin);
+ if (!handover_msg) {
+ rpc_transport_pollin_destroy (pollin);
+ ret = -ENOMEM;
+ goto fail;
+ }
+
+ pthread_mutex_lock (&peer_trans->handover.mutex);
+ {
+ list_add_tail (&handover_msg->list,
+ &peer_trans->handover.msgs);
+ pthread_cond_broadcast (&peer_trans->handover.cond);
+ }
+ pthread_mutex_unlock (&peer_trans->handover.mutex);
+
+ return 0;
+ }
+
+ GF_VALIDATE_OR_GOTO("rpc_transport", this, fail);
+ GF_VALIDATE_OR_GOTO("rpc_transport", this->ops, fail);
+
+ ret = this->ops->submit_request (this, req);
+fail:
+ return ret;
+}
+
+
+int32_t
+rpc_transport_submit_reply (rpc_transport_t *this, rpc_transport_reply_t *reply)
+{
+ int32_t ret = -1;
+ rpc_transport_t *peer_trans = NULL;
+ rpc_transport_pollin_t *pollin = NULL;
+ rpc_transport_handover_t *handover_msg = NULL;
+
+ if (this->peer_trans) {
+ peer_trans = this->peer_trans;
+
+ pollin = rpc_transport_same_process_pollin_alloc (this, reply->msg.rpchdr,
+ reply->msg.rpchdrcount,
+ reply->msg.proghdr,
+ reply->msg.proghdrcount,
+ reply->msg.progpayload,
+ reply->msg.progpayloadcount,
+ reply->private, 0);
+ if (!pollin) {
+ return -ENOMEM;
+ }
+
+ handover_msg = rpc_transport_handover_alloc (pollin);
+ if (!handover_msg) {
+ rpc_transport_pollin_destroy (pollin);
+ return -ENOMEM;
+ }
+
+ pthread_mutex_lock (&peer_trans->handover.mutex);
+ {
+ list_add_tail (&handover_msg->list,
+ &peer_trans->handover.msgs);
+ pthread_cond_broadcast (&peer_trans->handover.cond);
+ }
+ pthread_mutex_unlock (&peer_trans->handover.mutex);
+
+ return 0;
+ }
+
+ GF_VALIDATE_OR_GOTO("rpc_transport", this, fail);
+ GF_VALIDATE_OR_GOTO("rpc_transport", this->ops, fail);
+
+ ret = this->ops->submit_reply (this, reply);
+fail:
+ return ret;
+}
+
+
+int32_t
+rpc_transport_connect (rpc_transport_t *this)
+{
+ int ret = -1;
+
+ GF_VALIDATE_OR_GOTO("rpc_transport", this, fail);
+
+ ret = this->ops->connect (this);
+fail:
+ return ret;
+}
+
+
+int32_t
+rpc_transport_listen (rpc_transport_t *this)
+{
+ int ret = -1;
+
+ GF_VALIDATE_OR_GOTO("rpc_transport", this, fail);
+
+ ret = this->ops->listen (this);
+fail:
+ return ret;
+}
+
+
+int32_t
+rpc_transport_disconnect (rpc_transport_t *this)
+{
+ int32_t ret = -1;
+
+ GF_VALIDATE_OR_GOTO("rpc_transport", this, fail);
+
+ ret = this->ops->disconnect (this);
+fail:
+ return ret;
+}
+
+
+int32_t
+rpc_transport_destroy (rpc_transport_t *this)
+{
+ int32_t ret = -1;
+
+ GF_VALIDATE_OR_GOTO("rpc_transport", this, fail);
+
+ if (this->fini)
+ this->fini (this);
+ pthread_mutex_destroy (&this->lock);
+ GF_FREE (this);
+fail:
+ return ret;
+}
+
+
+rpc_transport_t *
+rpc_transport_ref (rpc_transport_t *this)
+{
+ rpc_transport_t *return_this = NULL;
+
+ GF_VALIDATE_OR_GOTO("rpc_transport", this, fail);
+
+ pthread_mutex_lock (&this->lock);
+ {
+ this->refcount ++;
+ }
+ pthread_mutex_unlock (&this->lock);
+
+ return_this = this;
+fail:
+ return return_this;
+}
+
+
+int32_t
+rpc_transport_unref (rpc_transport_t *this)
+{
+ int32_t refcount = 0;
+ int32_t ret = -1;
+
+ GF_VALIDATE_OR_GOTO("rpc_transport", this, fail);
+
+ pthread_mutex_lock (&this->lock);
+ {
+ refcount = --this->refcount;
+ }
+ pthread_mutex_unlock (&this->lock);
+
+ if (refcount == 0) {
+ /* xlator_notify (this->xl, GF_EVENT_RPC_TRANSPORT_CLEANUP,
+ this); */
+ rpc_transport_destroy (this);
+ }
+
+ ret = 0;
+fail:
+ return ret;
+}
+
+
+int32_t
+rpc_transport_notify (rpc_transport_t *this, rpc_transport_event_t event,
+ void *data, ...)
+{
+ int32_t ret = -1;
+
+ if (this == NULL) {
+ goto out;
+ }
+
+ //ret = this->notify (this, this->notify_data, event, data);
+ ret = this->notify (this, this->mydata, event, data);
+out:
+ return ret;
+}
+
+
+void *
+rpc_transport_peerproc (void *trans_data)
+{
+ rpc_transport_t *trans = NULL;
+ rpc_transport_handover_t *msg = NULL;
+
+ trans = trans_data;
+
+ while (1) {
+ pthread_mutex_lock (&trans->handover.mutex);
+ {
+ while (list_empty (&trans->handover.msgs))
+ pthread_cond_wait (&trans->handover.cond,
+ &trans->handover.mutex);
+
+ msg = list_entry (trans->handover.msgs.next,
+ rpc_transport_handover_t, list);
+
+ list_del_init (&msg->list);
+ }
+ pthread_mutex_unlock (&trans->handover.mutex);
+
+ rpc_transport_notify (trans, RPC_TRANSPORT_MSG_RECEIVED, msg->pollin);
+ rpc_transport_handover_destroy (msg);
+ }
+}
+
+
+int
+rpc_transport_setpeer (rpc_transport_t *trans, rpc_transport_t *peer_trans)
+{
+ trans->peer_trans = rpc_transport_ref (peer_trans);
+
+ INIT_LIST_HEAD (&trans->handover.msgs);
+ pthread_cond_init (&trans->handover.cond, NULL);
+ pthread_mutex_init (&trans->handover.mutex, NULL);
+ pthread_create (&trans->handover.thread, NULL,
+ rpc_transport_peerproc, trans);
+
+ peer_trans->peer_trans = rpc_transport_ref (trans);
+
+ INIT_LIST_HEAD (&peer_trans->handover.msgs);
+ pthread_cond_init (&peer_trans->handover.cond, NULL);
+ pthread_mutex_init (&peer_trans->handover.mutex, NULL);
+ pthread_create (&peer_trans->handover.thread, NULL,
+ rpc_transport_peerproc, peer_trans);
+
+ return 0;
+}
+
+
+inline int
+rpc_transport_register_notify (rpc_transport_t *trans,
+ rpc_transport_notify_t notify, void *mydata)
+{
+ int ret = -1;
+
+ if (trans == NULL) {
+ goto out;
+ }
+
+ trans->notify = notify;
+ trans->mydata = mydata;
+
+ ret = 0;
+out:
+ return ret;
+}
diff --git a/xlators/protocol/rpc/rpc-lib/src/rpc-transport.h b/xlators/protocol/rpc/rpc-lib/src/rpc-transport.h
new file mode 100644
index 0000000..06ac34a
--- /dev/null
+++ b/xlators/protocol/rpc/rpc-lib/src/rpc-transport.h
@@ -0,0 +1,287 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __RPC_TRANSPORT_H__
+#define __RPC_TRANSPORT_H__
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include <inttypes.h>
+#include <rpc/auth.h>
+#include <rpc/rpc_msg.h>
+
+/* Given the 4-byte fragment header, returns non-zero if this fragment
+ * is the last fragment for the RPC record being assemebled.
+ * RPC Record marking standard defines a 32 bit value as the fragment
+ * header with the MSB signifying whether the fragment is the last
+ * fragment for the record being asembled.
+ */
+#define RPC_LASTFRAG(fraghdr) ((uint32_t)(fraghdr & 0x80000000U))
+
+/* Given the 4-byte fragment header, extracts the bits that contain
+ * the fragment size.
+ */
+#define RPC_FRAGSIZE(fraghdr) ((uint32_t)(fraghdr & 0x7fffffffU))
+
+#define RPC_FRAGHDR_SIZE 4
+#define RPC_MSGTYPE_SIZE 8
+
+/* size of the msg from the start of call-body till and including credlen */
+#define RPC_CALL_BODY_SIZE 24
+
+#define RPC_REPLY_STATUS_SIZE 4
+
+#define RPC_AUTH_FLAVOUR_N_LENGTH_SIZE 8
+
+#define RPC_ACCEPT_STATUS_LEN 4
+
+struct rpc_transport_ops;
+typedef struct rpc_transport rpc_transport_t;
+
+#include "dict.h"
+#include "compat.h"
+#include "rpcsvc-common.h"
+
+struct peer_info {
+ struct sockaddr_storage sockaddr;
+ socklen_t sockaddr_len;
+ char identifier[UNIX_PATH_MAX];
+};
+typedef struct peer_info peer_info_t;
+
+typedef enum msg_type msg_type_t;
+
+typedef enum {
+ RPC_TRANSPORT_ACCEPT, /* New client has been accepted */
+ RPC_TRANSPORT_DISCONNECT, /* Connection is disconnected */
+ RPC_TRANSPORT_CLEANUP, /* connection is about to be freed */
+ /*RPC_TRANSPORT_READ,*/ /* An event used to enable rpcsvc to instruct
+ * transport the number of bytes to read.
+ * This helps in reading large msgs, wherein
+ * the rpc actors might decide to place the
+ * actor's payload in new iobufs separate
+ * from the rpc header, proghdr and
+ * authentication information. glusterfs/nfs
+ * read and write actors are few examples
+ * that might beniefit from this. While
+ * reading a single msg, this event may be
+ * delivered more than once.
+ */
+ RPC_TRANSPORT_MAP_XID_REQUEST, /* reciever of this event should send
+ * the prognum and procnum corresponding
+ * to xid.
+ */
+ RPC_TRANSPORT_MSG_RECEIVED, /* Complete rpc msg has been read */
+ RPC_TRANSPORT_CONNECT, /* client is connected to server */
+ RPC_TRANSPORT_MSG_SENT,
+} rpc_transport_event_t;
+
+struct rpc_transport_msg {
+ struct iovec *rpchdr;
+ int rpchdrcount;
+ struct iovec *proghdr;
+ int proghdrcount;
+ struct iovec *progpayload;
+ int progpayloadcount;
+ struct iobref *iobref;
+};
+typedef struct rpc_transport_msg rpc_transport_msg_t;
+
+struct rpc_transport_rsp {
+ /* as of now, the entire rsp payload is read into rspbuf and hence
+ * rspcount is always set to one.
+ */
+ struct iovec *rspvec;
+ int rspcount;
+ struct iobuf *rspbuf;
+};
+typedef struct rpc_transport_rsp rpc_transport_rsp_t;
+
+struct rpc_transport_req {
+ rpc_transport_msg_t msg;
+ rpc_transport_rsp_t rsp;
+};
+typedef struct rpc_transport_req rpc_transport_req_t;
+
+struct rpc_transport_reply {
+ rpc_transport_msg_t msg;
+ void *private;
+};
+typedef struct rpc_transport_reply rpc_transport_reply_t;
+
+struct rpc_request_info {
+ uint32_t xid;
+ int prognum;
+ int progver;
+ int procnum;
+ rpc_transport_rsp_t rsp;
+};
+typedef struct rpc_request_info rpc_request_info_t;
+
+
+struct rpc_transport_pollin {
+ union {
+ struct vectored {
+ struct iobuf *iobuf1;
+ size_t size1;
+ struct iobuf *iobuf2;
+ size_t size2;
+ } vector;
+ struct simple {
+ struct iobuf *iobuf;
+ size_t size;
+ } simple;
+ } data;
+ char vectored;
+ void *private;
+};
+typedef struct rpc_transport_pollin rpc_transport_pollin_t;
+
+typedef int (*rpc_transport_notify_t) (rpc_transport_t *, void *mydata,
+ rpc_transport_event_t, void *data, ...);
+struct rpc_transport {
+ struct rpc_transport_ops *ops;
+ void *private;
+ void *xl_private;
+ void *mydata;
+ pthread_mutex_t lock;
+ int32_t refcount;
+
+ glusterfs_ctx_t *ctx;
+ dict_t *options;
+ char *name;
+ void *dnscache;
+ data_t *buf;
+ int32_t (*init) (rpc_transport_t *this);
+ void (*fini) (rpc_transport_t *this);
+ rpc_transport_notify_t notify;
+ void *notify_data;
+ peer_info_t peerinfo;
+ peer_info_t myinfo;
+
+ rpc_transport_t *peer_trans;
+ struct {
+ pthread_mutex_t mutex;
+ pthread_cond_t cond;
+ pthread_t thread;
+ struct list_head msgs;
+ /* any request/reply will be transformed as pollin data on the
+ * peer, hence we are building up a pollin data even before
+ * handing it over to peer rpc_transport. In order to decide whether
+ * the pollin data is vectored or simple, we follow a simple
+ * algo i.e., if there is a progpayload in request/reply, its
+ * considered vectored, otherwise its a simple pollin data.
+ */
+ rpc_transport_pollin_t *msg;
+ } handover;
+};
+
+typedef struct {
+ rpc_transport_pollin_t *pollin;
+ struct list_head list;
+} rpc_transport_handover_t;
+
+struct rpc_transport_ops {
+ /* no need of receive op, msg will be delivered through an event
+ * notification
+ */
+ int32_t (*submit_request) (rpc_transport_t *this,
+ rpc_transport_req_t *req);
+ int32_t (*submit_reply) (rpc_transport_t *this,
+ rpc_transport_reply_t *reply);
+ int32_t (*connect) (rpc_transport_t *this);
+ int32_t (*listen) (rpc_transport_t *this);
+ int32_t (*disconnect) (rpc_transport_t *this);
+ int32_t (*get_peername) (rpc_transport_t *this, char *hostname,
+ int hostlen);
+ int32_t (*get_peeraddr) (rpc_transport_t *this, char *peeraddr,
+ int addrlen, struct sockaddr *sa,
+ socklen_t sasize);
+ int32_t (*get_myname) (rpc_transport_t *this, char *hostname,
+ int hostlen);
+ int32_t (*get_myaddr) (rpc_transport_t *this, char *peeraddr,
+ int addrlen, struct sockaddr *sa,
+ socklen_t sasize);
+};
+
+
+int32_t
+rpc_transport_listen (rpc_transport_t *this);
+
+int32_t
+rpc_transport_connect (rpc_transport_t *this);
+
+int32_t
+rpc_transport_disconnect (rpc_transport_t *this);
+
+int32_t
+rpc_transport_notify (rpc_transport_t *this, rpc_transport_event_t event,
+ void *data, ...);
+
+int32_t
+rpc_transport_submit_request (rpc_transport_t *this, rpc_transport_req_t *req);
+
+int32_t
+rpc_transport_submit_reply (rpc_transport_t *this,
+ rpc_transport_reply_t *reply);
+
+int32_t
+rpc_transport_destroy (rpc_transport_t *this);
+
+rpc_transport_t *
+rpc_transport_load (glusterfs_ctx_t *ctx, dict_t *options, char *name);
+
+rpc_transport_t *
+rpc_transport_ref (rpc_transport_t *trans);
+
+int32_t
+rpc_transport_unref (rpc_transport_t *trans);
+
+int
+rpc_transport_setpeer (rpc_transport_t *trans, rpc_transport_t *trans_peer);
+
+int
+rpc_transport_register_notify (rpc_transport_t *trans, rpc_transport_notify_t,
+ void *mydata);
+
+int32_t
+rpc_transport_get_peername (rpc_transport_t *this, char *hostname, int hostlen);
+
+int32_t
+rpc_transport_get_peeraddr (rpc_transport_t *this, char *peeraddr, int addrlen,
+ struct sockaddr *sa, size_t salen);
+
+int32_t
+rpc_transport_get_myname (rpc_transport_t *this, char *hostname, int hostlen);
+
+int32_t
+rpc_transport_get_myaddr (rpc_transport_t *this, char *peeraddr, int addrlen,
+ struct sockaddr *sa, size_t salen);
+
+rpc_transport_pollin_t *
+rpc_transport_pollin_alloc (rpc_transport_t *this, struct iobuf *iobuf,
+ size_t iobuf_size, struct iobuf *vectoriob,
+ size_t vectoriob_size, void *private);
+void
+rpc_transport_pollin_destroy (rpc_transport_pollin_t *pollin);
+
+#endif /* __RPC_TRANSPORT_H__ */
diff --git a/xlators/protocol/rpc/rpc-lib/src/rpcsvc-auth.c b/xlators/protocol/rpc/rpc-lib/src/rpcsvc-auth.c
new file mode 100644
index 0000000..50a55f5
--- /dev/null
+++ b/xlators/protocol/rpc/rpc-lib/src/rpcsvc-auth.c
@@ -0,0 +1,409 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include "rpcsvc.h"
+#include "logging.h"
+#include "dict.h"
+
+extern rpcsvc_auth_t *
+rpcsvc_auth_null_init (rpcsvc_t *svc, dict_t *options);
+
+extern rpcsvc_auth_t *
+rpcsvc_auth_unix_init (rpcsvc_t *svc, dict_t *options);
+
+extern rpcsvc_auth_t *
+rpcsvc_auth_glusterfs_init (rpcsvc_t *svc, dict_t *options);
+
+int
+rpcsvc_auth_add_initer (struct list_head *list, char *idfier,
+ rpcsvc_auth_initer_t init)
+{
+ struct rpcsvc_auth_list *new = NULL;
+
+ if ((!list) || (!init) || (!idfier))
+ return -1;
+
+ new = GF_CALLOC (1, sizeof (*new), 0);
+ if (!new) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Memory allocation failed");
+ return -1;
+ }
+
+ new->init = init;
+ strcpy (new->name, idfier);
+ INIT_LIST_HEAD (&new->authlist);
+ list_add_tail (&new->authlist, list);
+ return 0;
+}
+
+
+
+int
+rpcsvc_auth_add_initers (rpcsvc_t *svc)
+{
+ int ret = -1;
+
+ ret = rpcsvc_auth_add_initer (&svc->authschemes, "auth-glusterfs",
+ (rpcsvc_auth_initer_t)
+ rpcsvc_auth_glusterfs_init);
+ if (ret == -1) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to add AUTH_GLUSTERFS");
+ goto err;
+ }
+
+ ret = rpcsvc_auth_add_initer (&svc->authschemes, "auth-unix",
+ (rpcsvc_auth_initer_t)
+ rpcsvc_auth_unix_init);
+ if (ret == -1) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to add AUTH_UNIX");
+ goto err;
+ }
+
+ ret = rpcsvc_auth_add_initer (&svc->authschemes, "auth-null",
+ (rpcsvc_auth_initer_t)
+ rpcsvc_auth_null_init);
+ if (ret == -1) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to add AUTH_NULL");
+ goto err;
+ }
+
+ ret = 0;
+err:
+ return 0;
+}
+
+
+int
+rpcsvc_auth_init_auth (rpcsvc_t *svc, dict_t *options,
+ struct rpcsvc_auth_list *authitem)
+{
+ int ret = -1;
+
+ if ((!svc) || (!options) || (!authitem))
+ return -1;
+
+ if (!authitem->init) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "No init function defined");
+ ret = -1;
+ goto err;
+ }
+
+ authitem->auth = authitem->init (svc, options);
+ if (!authitem->auth) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Registration of auth failed:"
+ " %s", authitem->name);
+ ret = -1;
+ goto err;
+ }
+
+ authitem->enable = 1;
+ gf_log (GF_RPCSVC, GF_LOG_TRACE, "Authentication enabled: %s",
+ authitem->auth->authname);
+
+ ret = 0;
+err:
+ return ret;
+}
+
+
+int
+rpcsvc_auth_init_auths (rpcsvc_t *svc, dict_t *options)
+{
+ int ret = -1;
+ struct rpcsvc_auth_list *auth = NULL;
+ struct rpcsvc_auth_list *tmp = NULL;
+
+ if (!svc)
+ return -1;
+
+ if (list_empty (&svc->authschemes)) {
+ gf_log (GF_RPCSVC, GF_LOG_WARNING, "No authentication!");
+ ret = 0;
+ goto err;
+ }
+
+ /* If auth null and sys are not disabled by the user, we must enable
+ * it by default. This is a globally default rule, the user is still
+ * allowed to disable the two for particular subvolumes.
+ */
+ if (!dict_get (options, "rpc-auth.auth-null"))
+ ret = dict_set_str (options, "rpc-auth.auth-null", "on");
+
+ if (!dict_get (options, "rpc-auth.auth-unix"))
+ ret = dict_set_str (options, "rpc-auth.auth-unix", "on");
+
+ if (!dict_get (options, "rpc-auth.auth-glusterfs"))
+ ret = dict_set_str (options, "rpc-auth.auth-glusterfs", "on");
+
+ list_for_each_entry_safe (auth, tmp, &svc->authschemes, authlist) {
+ ret = rpcsvc_auth_init_auth (svc, options, auth);
+ if (ret == -1)
+ goto err;
+ }
+
+ ret = 0;
+err:
+ return ret;
+
+}
+
+int
+rpcsvc_auth_init (rpcsvc_t *svc, dict_t *options)
+{
+ int ret = -1;
+
+ if ((!svc) || (!options))
+ return -1;
+
+ ret = rpcsvc_auth_add_initers (svc);
+ if (ret == -1) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to add initers");
+ goto out;
+ }
+
+ ret = rpcsvc_auth_init_auths (svc, options);
+ if (ret == -1) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to init auth schemes");
+ goto out;
+ }
+
+out:
+ return ret;
+}
+
+
+rpcsvc_auth_t *
+__rpcsvc_auth_get_handler (rpcsvc_request_t *req)
+{
+ int ret = -1;
+ struct rpcsvc_auth_list *auth = NULL;
+ struct rpcsvc_auth_list *tmp = NULL;
+ rpcsvc_t *svc = NULL;
+
+ if (!req)
+ return NULL;
+
+ svc = rpcsvc_request_service (req);
+ if (!svc)
+ gf_log ("", 1, "something wrong, !svc");
+
+ if (list_empty (&svc->authschemes)) {
+ gf_log (GF_RPCSVC, GF_LOG_WARNING, "No authentication!");
+ ret = 0;
+ goto err;
+ }
+
+ list_for_each_entry_safe (auth, tmp, &svc->authschemes, authlist) {
+ if (!auth->enable)
+ continue;
+ if (auth->auth->authnum == req->cred.flavour)
+ goto err;
+
+ }
+
+ auth = NULL;
+err:
+ if (auth)
+ return auth->auth;
+ else
+ return NULL;
+}
+
+rpcsvc_auth_t *
+rpcsvc_auth_get_handler (rpcsvc_request_t *req)
+{
+ rpcsvc_auth_t *auth = NULL;
+
+ auth = __rpcsvc_auth_get_handler (req);
+ if (auth)
+ goto ret;
+
+ gf_log (GF_RPCSVC, GF_LOG_TRACE, "No auth handler: %d",
+ req->cred.flavour);
+
+ /* The requested scheme was not available so fall back the to one
+ * scheme that will always be present.
+ */
+ req->cred.flavour = AUTH_NULL;
+ req->verf.flavour = AUTH_NULL;
+ auth = __rpcsvc_auth_get_handler (req);
+ret:
+ return auth;
+}
+
+
+int
+rpcsvc_auth_request_init (rpcsvc_request_t *req)
+{
+ int ret = -1;
+ rpcsvc_auth_t *auth = NULL;
+
+ if (!req)
+ return -1;
+
+ auth = rpcsvc_auth_get_handler (req);
+ if (!auth)
+ goto err;
+ ret = 0;
+ gf_log (GF_RPCSVC, GF_LOG_TRACE, "Auth handler: %s", auth->authname);
+ if (!auth->authops->request_init)
+ ret = auth->authops->request_init (req, auth->authprivate);
+
+err:
+ return ret;
+}
+
+
+int
+rpcsvc_authenticate (rpcsvc_request_t *req)
+{
+ int ret = RPCSVC_AUTH_REJECT;
+ rpcsvc_auth_t *auth = NULL;
+ int minauth = 0;
+
+ if (!req)
+ return ret;
+
+ //minauth = rpcsvc_request_prog_minauth (req);
+ minauth = 1;
+ if (minauth > rpcsvc_request_cred_flavour (req)) {
+ gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Auth too weak");
+ rpcsvc_request_set_autherr (req, AUTH_TOOWEAK);
+ goto err;
+ }
+
+ auth = rpcsvc_auth_get_handler (req);
+ if (!auth) {
+ gf_log (GF_RPCSVC, GF_LOG_DEBUG, "No auth handler found");
+ goto err;
+ }
+
+ if (auth->authops->authenticate)
+ ret = auth->authops->authenticate (req, auth->authprivate);
+
+err:
+ return ret;
+}
+
+
+int
+rpcsvc_auth_array (rpcsvc_t *svc, char *volname, int *autharr, int arrlen)
+{
+ int count = 0;
+ int gen = RPCSVC_AUTH_REJECT;
+ int spec = RPCSVC_AUTH_REJECT;
+ int final = RPCSVC_AUTH_REJECT;
+ char *srchstr = NULL;
+ char *valstr = NULL;
+ gf_boolean_t boolval = _gf_false;
+ int ret = 0;
+
+ struct rpcsvc_auth_list *auth = NULL;
+ struct rpcsvc_auth_list *tmp = NULL;
+
+ if ((!svc) || (!autharr) || (!volname))
+ return -1;
+
+ memset (autharr, 0, arrlen * sizeof(int));
+ if (list_empty (&svc->authschemes)) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "No authentication!");
+ goto err;
+ }
+
+ list_for_each_entry_safe (auth, tmp, &svc->authschemes, authlist) {
+ if (count >= arrlen)
+ break;
+
+ gen = gf_asprintf (&srchstr, "rpc-auth.%s", auth->name);
+ if (gen == -1) {
+ count = -1;
+ goto err;
+ }
+
+ gen = RPCSVC_AUTH_REJECT;
+ if (dict_get (svc->options, srchstr)) {
+ ret = dict_get_str (svc->options, srchstr, &valstr);
+ if (ret == 0) {
+ ret = gf_string2boolean (valstr, &boolval);
+ if (ret == 0) {
+ if (boolval == _gf_true)
+ gen = RPCSVC_AUTH_ACCEPT;
+ } else
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Faile"
+ "d to read auth val");
+ } else
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Faile"
+ "d to read auth val");
+ }
+
+ GF_FREE (srchstr);
+ spec = gf_asprintf (&srchstr, "rpc-auth.%s.%s", auth->name,
+ volname);
+ if (spec == -1) {
+ count = -1;
+ goto err;
+ }
+
+ spec = RPCSVC_AUTH_DONTCARE;
+ if (dict_get (svc->options, srchstr)) {
+ ret = dict_get_str (svc->options, srchstr, &valstr);
+ if (ret == 0) {
+ ret = gf_string2boolean (valstr, &boolval);
+ if (ret == 0) {
+ if (boolval == _gf_true)
+ spec = RPCSVC_AUTH_ACCEPT;
+ else
+ spec = RPCSVC_AUTH_REJECT;
+ } else
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Faile"
+ "d to read auth val");
+ } else
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Faile"
+ "d to read auth val");
+ }
+
+ GF_FREE (srchstr);
+ final = rpcsvc_combine_gen_spec_volume_checks (gen, spec);
+ if (final == RPCSVC_AUTH_ACCEPT) {
+ autharr[count] = auth->auth->authnum;
+ ++count;
+ }
+ }
+
+err:
+ return count;
+}
+
+
+gid_t *
+rpcsvc_auth_unix_auxgids (rpcsvc_request_t *req, int *arrlen)
+{
+ if ((!req) || (!arrlen))
+ return NULL;
+
+ if ((req->cred.flavour != AUTH_UNIX) ||
+ (req->cred.flavour != AUTH_GLUSTERFS))
+ return NULL;
+
+ *arrlen = req->auxgidcount;
+ if (*arrlen == 0)
+ return NULL;
+
+ return &req->auxgids[0];
+}
diff --git a/xlators/protocol/rpc/rpc-lib/src/rpcsvc-common.h b/xlators/protocol/rpc/rpc-lib/src/rpcsvc-common.h
new file mode 100644
index 0000000..0b9d84c
--- /dev/null
+++ b/xlators/protocol/rpc/rpc-lib/src/rpcsvc-common.h
@@ -0,0 +1,83 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _RPCSVC_COMMON_H
+#define _RPCSVC_COMMON_H
+
+#include <pthread.h>
+#include "list.h"
+#include "compat.h"
+#include "glusterfs.h"
+#include "dict.h"
+
+typedef enum {
+ RPCSVC_EVENT_ACCEPT,
+ RPCSVC_EVENT_DISCONNECT,
+ RPCSVC_EVENT_LISTENER_DEAD,
+} rpcsvc_event_t;
+
+
+struct rpcsvc_state;
+
+typedef int (*rpcsvc_notify_t) (struct rpcsvc_state *, void *mydata,
+ rpcsvc_event_t, void *data);
+
+
+/* Contains global state required for all the RPC services.
+ */
+typedef struct rpcsvc_state {
+
+ /* Contains list of (program, version) handlers.
+ * other options.
+ */
+
+ pthread_mutex_t rpclock;
+
+ unsigned int memfactor;
+
+ /* List of the authentication schemes available. */
+ struct list_head authschemes;
+
+ /* Reference to the options */
+ dict_t *options;
+
+ /* Allow insecure ports. */
+ int allow_insecure;
+
+ glusterfs_ctx_t *ctx;
+
+ void *listener;
+
+ /* list of connections which will listen for incoming connections */
+ struct list_head listeners;
+
+ /* list of programs registered with rpcsvc */
+ struct list_head programs;
+
+ /* list of notification callbacks */
+ struct list_head notify;
+ int notify_count;
+
+ void *mydata; /* This is xlator */
+ rpcsvc_notify_t notifyfn;
+
+} rpcsvc_t;
+
+
+#endif /* #ifndef _RPCSVC_COMMON_H */
diff --git a/xlators/protocol/rpc/rpc-lib/src/rpcsvc.c b/xlators/protocol/rpc/rpc-lib/src/rpcsvc.c
new file mode 100644
index 0000000..10d7475
--- /dev/null
+++ b/xlators/protocol/rpc/rpc-lib/src/rpcsvc.c
@@ -0,0 +1,2010 @@
+/*
+ Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
+ This file is part of GlusterFS.
+
+ GlusterFS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ GlusterFS is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _CONFIG_H
+#define _CONFIG_H
+#include "config.h"
+#endif
+
+#include "rpcsvc.h"
+#include "rpc-transport.h"
+#include "dict.h"
+#include "logging.h"
+#include "byte-order.h"
+#include "common-utils.h"
+#include "compat-errno.h"
+#include "list.h"
+#include "xdr-rpc.h"
+#include "iobuf.h"
+#include "globals.h"
+
+#include <errno.h>
+#include <pthread.h>
+#include <stdlib.h>
+#include <rpc/rpc.h>
+#include <rpc/pmap_clnt.h>
+#include <arpa/inet.h>
+#include <rpc/xdr.h>
+#include <fnmatch.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+
+#define rpcsvc_alloc_request(con, request) \
+ do { \
+ request = (rpcsvc_request_t *) mem_get ((con)->rxpool); \
+ memset (request, 0, sizeof (rpcsvc_request_t)); \
+ } while (0)
+
+
+int
+rpcsvc_conn_peer_check_search (dict_t *options, char *pattern, char *clstr)
+{
+ int ret = -1;
+ char *addrtok = NULL;
+ char *addrstr = NULL;
+ char *svptr = NULL;
+
+ if ((!options) || (!clstr))
+ return -1;
+
+ if (!dict_get (options, pattern))
+ return -1;
+
+ ret = dict_get_str (options, pattern, &addrstr);
+ if (ret < 0) {
+ ret = -1;
+ goto err;
+ }
+
+ if (!addrstr) {
+ ret = -1;
+ goto err;
+ }
+
+ addrtok = strtok_r (addrstr, ",", &svptr);
+ while (addrtok) {
+
+ ret = fnmatch (addrtok, clstr, FNM_CASEFOLD);
+ if (ret == 0)
+ goto err;
+
+ addrtok = strtok_r (NULL, ",", &svptr);
+ }
+
+ ret = -1;
+err:
+
+ return ret;
+}
+
+
+int
+rpcsvc_conn_peer_check_allow (dict_t *options, char *volname, char *clstr)
+{
+ int ret = RPCSVC_AUTH_DONTCARE;
+ char *srchstr = NULL;
+ char globalrule[] = "rpc-auth.addr.allow";
+
+ if ((!options) || (!clstr))
+ return ret;
+
+ /* If volname is NULL, then we're searching for the general rule to
+ * determine the current address in clstr is allowed or not for all
+ * subvolumes.
+ */
+ if (volname) {
+ ret = gf_asprintf (&srchstr, "rpc-auth.addr.%s.allow", volname);
+ if (ret == -1) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed");
+ ret = RPCSVC_AUTH_DONTCARE;
+ goto out;
+ }
+ } else
+ srchstr = globalrule;
+
+ ret = rpcsvc_conn_peer_check_search (options, srchstr, clstr);
+ if (volname)
+ GF_FREE (srchstr);
+
+ if (ret == 0)
+ ret = RPCSVC_AUTH_ACCEPT;
+ else
+ ret = RPCSVC_AUTH_DONTCARE;
+out:
+ return ret;
+}
+
+int
+rpcsvc_conn_peer_check_reject (dict_t *options, char *volname, char *clstr)
+{
+ int ret = RPCSVC_AUTH_DONTCARE;
+ char *srchstr = NULL;
+ char generalrule[] = "rpc-auth.addr.reject";
+
+ if ((!options) || (!clstr))
+ return ret;
+
+ if (volname) {
+ ret = gf_asprintf (&srchstr, "rpc-auth.addr.%s.reject", volname);
+ if (ret == -1) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed");
+ ret = RPCSVC_AUTH_REJECT;
+ goto out;
+ }
+ } else
+ srchstr = generalrule;
+
+ ret = rpcsvc_conn_peer_check_search (options, srchstr, clstr);
+ if (volname)
+ GF_FREE (srchstr);
+
+ if (ret == 0)
+ ret = RPCSVC_AUTH_REJECT;
+ else
+ ret = RPCSVC_AUTH_DONTCARE;
+out:
+ return ret;
+}
+
+
+/* This function tests the results of the allow rule and the reject rule to
+ * combine them into a single result that can be used to determine if the
+ * connection should be allowed to proceed.
+ * Heres the test matrix we need to follow in this function.
+ *
+ * A - Allow, the result of the allow test. Never returns R.
+ * R - Reject, result of the reject test. Never returns A.
+ * Both can return D or dont care if no rule was given.
+ *
+ * | @allow | @reject | Result |
+ * | A | R | R |
+ * | D | D | D |
+ * | A | D | A |
+ * | D | R | R |
+ */
+int
+rpcsvc_combine_allow_reject_volume_check (int allow, int reject)
+{
+ int final = RPCSVC_AUTH_REJECT;
+
+ /* If allowed rule allows but reject rule rejects, we stay cautious
+ * and reject. */
+ if ((allow == RPCSVC_AUTH_ACCEPT) && (reject == RPCSVC_AUTH_REJECT))
+ final = RPCSVC_AUTH_REJECT;
+ /* if both are dont care, that is user did not specify for either allow
+ * or reject, we leave it up to the general rule to apply, in the hope
+ * that there is one.
+ */
+ else if ((allow == RPCSVC_AUTH_DONTCARE) &&
+ (reject == RPCSVC_AUTH_DONTCARE))
+ final = RPCSVC_AUTH_DONTCARE;
+ /* If one is dont care, the other one applies. */
+ else if ((allow == RPCSVC_AUTH_ACCEPT) &&
+ (reject == RPCSVC_AUTH_DONTCARE))
+ final = RPCSVC_AUTH_ACCEPT;
+ else if ((allow == RPCSVC_AUTH_DONTCARE) &&
+ (reject == RPCSVC_AUTH_REJECT))
+ final = RPCSVC_AUTH_REJECT;
+
+ return final;
+}
+
+
+/* Combines the result of the general rule test against, the specific rule
+ * to determine final permission for the client's address.
+ *
+ * | @gen | @spec | Result |
+ * | A | A | A |
+ * | A | R | R |
+ * | A | D | A |
+ * | D | A | A |
+ * | D | R | R |
+ * | D | D | D |
+ * | R | A | A |
+ * | R | D | R |
+ * | R | R | R |
+ */
+int
+rpcsvc_combine_gen_spec_addr_checks (int gen, int spec)
+{
+ int final = RPCSVC_AUTH_REJECT;
+
+ if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_ACCEPT))
+ final = RPCSVC_AUTH_ACCEPT;
+ else if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_REJECT))
+ final = RPCSVC_AUTH_REJECT;
+ else if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_DONTCARE))
+ final = RPCSVC_AUTH_ACCEPT;
+ else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec == RPCSVC_AUTH_ACCEPT))
+ final = RPCSVC_AUTH_ACCEPT;
+ else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec == RPCSVC_AUTH_REJECT))
+ final = RPCSVC_AUTH_REJECT;
+ else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec== RPCSVC_AUTH_DONTCARE))
+ final = RPCSVC_AUTH_DONTCARE;
+ else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_ACCEPT))
+ final = RPCSVC_AUTH_ACCEPT;
+ else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_DONTCARE))
+ final = RPCSVC_AUTH_REJECT;
+ else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_REJECT))
+ final = RPCSVC_AUTH_REJECT;
+
+ return final;
+}
+
+
+
+/* Combines the result of the general rule test against, the specific rule
+ * to determine final test for the connection coming in for a given volume.
+ *
+ * | @gen | @spec | Result |
+ * | A | A | A |
+ * | A | R | R |
+ * | A | D | A |
+ * | D | A | A |
+ * | D | R | R |
+ * | D | D | R |, special case, we intentionally disallow this.
+ * | R | A | A |
+ * | R | D | R |
+ * | R | R | R |
+ */
+int
+rpcsvc_combine_gen_spec_volume_checks (int gen, int spec)
+{
+ int final = RPCSVC_AUTH_REJECT;
+
+ if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_ACCEPT))
+ final = RPCSVC_AUTH_ACCEPT;
+ else if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_REJECT))
+ final = RPCSVC_AUTH_REJECT;
+ else if ((gen == RPCSVC_AUTH_ACCEPT) && (spec == RPCSVC_AUTH_DONTCARE))
+ final = RPCSVC_AUTH_ACCEPT;
+ else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec == RPCSVC_AUTH_ACCEPT))
+ final = RPCSVC_AUTH_ACCEPT;
+ else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec == RPCSVC_AUTH_REJECT))
+ final = RPCSVC_AUTH_REJECT;
+ /* On no rule, we reject. */
+ else if ((gen == RPCSVC_AUTH_DONTCARE) && (spec== RPCSVC_AUTH_DONTCARE))
+ final = RPCSVC_AUTH_REJECT;
+ else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_ACCEPT))
+ final = RPCSVC_AUTH_ACCEPT;
+ else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_DONTCARE))
+ final = RPCSVC_AUTH_REJECT;
+ else if ((gen == RPCSVC_AUTH_REJECT) && (spec == RPCSVC_AUTH_REJECT))
+ final = RPCSVC_AUTH_REJECT;
+
+ return final;
+}
+
+
+int
+rpcsvc_conn_peer_check_name (dict_t *options, char *volname,
+ rpcsvc_conn_t *conn)
+{
+ int ret = RPCSVC_AUTH_REJECT;
+ int aret = RPCSVC_AUTH_REJECT;
+ int rjret = RPCSVC_AUTH_REJECT;
+ char clstr[RPCSVC_PEER_STRLEN];
+
+ if (!conn)
+ return ret;
+
+ ret = rpcsvc_conn_peername (conn, clstr, RPCSVC_PEER_STRLEN);
+ if (ret != 0) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to get remote addr: "
+ "%s", gai_strerror (ret));
+ ret = RPCSVC_AUTH_REJECT;
+ goto err;
+ }
+
+ aret = rpcsvc_conn_peer_check_allow (options, volname, clstr);
+ rjret = rpcsvc_conn_peer_check_reject (options, volname, clstr);
+
+ ret = rpcsvc_combine_allow_reject_volume_check (aret, rjret);
+
+err:
+ return ret;
+}
+
+
+int
+rpcsvc_conn_peer_check_addr (dict_t *options, char *volname,rpcsvc_conn_t *conn)
+{
+ int ret = RPCSVC_AUTH_REJECT;
+ int aret = RPCSVC_AUTH_DONTCARE;
+ int rjret = RPCSVC_AUTH_REJECT;
+ char clstr[RPCSVC_PEER_STRLEN];
+
+ if (!conn)
+ return ret;
+
+ ret = rpcsvc_conn_peeraddr (conn, clstr, RPCSVC_PEER_STRLEN, NULL, 0);
+ if (ret != 0) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to get remote addr: "
+ "%s", gai_strerror (ret));
+ ret = RPCSVC_AUTH_REJECT;
+ goto err;
+ }
+
+ aret = rpcsvc_conn_peer_check_allow (options, volname, clstr);
+ rjret = rpcsvc_conn_peer_check_reject (options, volname, clstr);
+
+ ret = rpcsvc_combine_allow_reject_volume_check (aret, rjret);
+err:
+ return ret;
+}
+
+
+int
+rpcsvc_conn_check_volume_specific (dict_t *options, char *volname,
+ rpcsvc_conn_t *conn)
+{
+ int namechk = RPCSVC_AUTH_REJECT;
+ int addrchk = RPCSVC_AUTH_REJECT;
+ gf_boolean_t namelookup = _gf_true;
+ char *namestr = NULL;
+ int ret = 0;
+
+ if ((!options) || (!volname) || (!conn))
+ return RPCSVC_AUTH_REJECT;
+
+ /* Enabled by default */
+ if ((dict_get (options, "rpc-auth.addr.namelookup"))) {
+ ret = dict_get_str (options, "rpc-auth.addr.namelookup"
+ , &namestr);
+ if (ret == 0)
+ ret = gf_string2boolean (namestr, &namelookup);
+ }
+
+ /* We need two separate checks because the rules with addresses in them
+ * can be network addresses which can be general and names can be
+ * specific which will over-ride the network address rules.
+ */
+ if (namelookup)
+ namechk = rpcsvc_conn_peer_check_name (options, volname, conn);
+ addrchk = rpcsvc_conn_peer_check_addr (options, volname, conn);
+
+ if (namelookup)
+ ret = rpcsvc_combine_gen_spec_addr_checks (addrchk, namechk);
+ else
+ ret = addrchk;
+
+ return ret;
+}
+
+
+int
+rpcsvc_conn_check_volume_general (dict_t *options, rpcsvc_conn_t *conn)
+{
+ int addrchk = RPCSVC_AUTH_REJECT;
+ int namechk = RPCSVC_AUTH_REJECT;
+ gf_boolean_t namelookup = _gf_true;
+ char *namestr = NULL;
+ int ret = 0;
+
+ if ((!options) || (!conn))
+ return RPCSVC_AUTH_REJECT;
+
+ /* Enabled by default */
+ if ((dict_get (options, "rpc-auth.addr.namelookup"))) {
+ ret = dict_get_str (options, "rpc-auth.addr.namelookup"
+ , &namestr);
+ if (ret == 0)
+ ret = gf_string2boolean (namestr, &namelookup);
+ }
+
+ /* We need two separate checks because the rules with addresses in them
+ * can be network addresses which can be general and names can be
+ * specific which will over-ride the network address rules.
+ */
+ if (namelookup)
+ namechk = rpcsvc_conn_peer_check_name (options, NULL, conn);
+ addrchk = rpcsvc_conn_peer_check_addr (options, NULL, conn);
+
+ if (namelookup)
+ ret = rpcsvc_combine_gen_spec_addr_checks (addrchk, namechk);
+ else
+ ret = addrchk;
+
+ return ret;
+}
+
+int
+rpcsvc_conn_peer_check (dict_t *options, char *volname, rpcsvc_conn_t *conn)
+{
+ int general_chk = RPCSVC_AUTH_REJECT;
+ int specific_chk = RPCSVC_AUTH_REJECT;
+
+ if ((!options) || (!volname) || (!conn))
+ return RPCSVC_AUTH_REJECT;
+
+ general_chk = rpcsvc_conn_check_volume_general (options, conn);
+ specific_chk = rpcsvc_conn_check_volume_specific (options, volname,
+ conn);
+
+ return rpcsvc_combine_gen_spec_volume_checks (general_chk,specific_chk);
+}
+
+
+char *
+rpcsvc_volume_allowed (dict_t *options, char *volname)
+{
+ char globalrule[] = "rpc-auth.addr.allow";
+ char *srchstr = NULL;
+ char *addrstr = NULL;
+ int ret = -1;
+
+ if ((!options) || (!volname))
+ return NULL;
+
+ ret = gf_asprintf (&srchstr, "rpc-auth.addr.%s.allow", volname);
+ if (ret == -1) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed");
+ goto out;
+ }
+
+ if (!dict_get (options, srchstr)) {
+ GF_FREE (srchstr);
+ srchstr = globalrule;
+ ret = dict_get_str (options, srchstr, &addrstr);
+ } else
+ ret = dict_get_str (options, srchstr, &addrstr);
+
+out:
+ return addrstr;
+}
+
+
+
+/* Initialize the core of a connection */
+rpcsvc_conn_t *
+rpcsvc_conn_alloc (rpcsvc_t *svc, rpc_transport_t *trans)
+{
+ rpcsvc_conn_t *conn = NULL;
+ int ret = -1;
+ unsigned int poolcount = 0;
+
+ conn = GF_CALLOC (1, sizeof(*conn), 0);
+ if (!conn) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "memory allocation failed");
+ return NULL;
+ }
+
+ conn->trans = trans;
+ conn->svc = svc;
+ poolcount = RPCSVC_POOLCOUNT_MULT * svc->memfactor;
+
+ gf_log (GF_RPCSVC, GF_LOG_TRACE, "rx pool: %d", poolcount);
+ conn->rxpool = mem_pool_new (rpcsvc_request_t, poolcount);
+ if (!conn->rxpool) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "mem pool allocation failed");
+ goto free_conn;
+ }
+
+ /* Cannot consider a connection connected unless the user of this
+ * connection decides it is ready to use. It is possible that we have
+ * to free this connection soon after. That free will not happpen
+ * unless the state is disconnected.
+ */
+ conn->connstate = RPCSVC_CONNSTATE_DISCONNECTED;
+ pthread_mutex_init (&conn->connlock, NULL);
+ conn->connref = 0;
+
+ ret = 0;
+
+free_conn:
+ if (ret == -1) {
+ GF_FREE (conn);
+ conn = NULL;
+ }
+
+ return conn;
+}
+
+int
+rpcsvc_notify (rpc_transport_t *trans, void *mydata,
+ rpc_transport_event_t event, void *data, ...);
+
+void
+rpcsvc_conn_state_init (rpcsvc_conn_t *conn)
+{
+ if (!conn)
+ return;
+
+ ++conn->connref;
+ conn->connstate = RPCSVC_CONNSTATE_CONNECTED;
+}
+
+
+rpcsvc_notify_wrapper_t *
+rpcsvc_notify_wrapper_alloc (void)
+{
+ rpcsvc_notify_wrapper_t *wrapper = NULL;
+
+ wrapper = GF_CALLOC (1, sizeof (*wrapper), 0);
+ if (!wrapper) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "memory allocation failed");
+ goto out;
+ }
+
+ INIT_LIST_HEAD (&wrapper->list);
+out:
+ return wrapper;
+}
+
+
+void
+rpcsvc_listener_destroy (rpcsvc_listener_t *listener)
+{
+ rpcsvc_t *svc = NULL;
+
+ if (!listener) {
+ goto out;
+ }
+
+ if (!listener->conn) {
+ goto listener_free;
+ }
+
+ svc = listener->conn->svc;
+ if (!svc) {
+ goto listener_free;
+ }
+
+ pthread_mutex_lock (&svc->rpclock);
+ {
+ list_del_init (&listener->list);
+ }
+ pthread_mutex_unlock (&svc->rpclock);
+
+listener_free:
+ GF_FREE (listener);
+out:
+ return;
+}
+
+
+void
+rpcsvc_conn_destroy (rpcsvc_conn_t *conn)
+{
+ rpcsvc_notify_wrapper_t *wrapper = NULL;
+ rpcsvc_event_t event = 0;
+ rpcsvc_listener_t *listener = NULL;
+ rpcsvc_t *svc = NULL;
+ rpcsvc_notify_wrapper_t *wrappers = NULL;
+ int i = 0, wrapper_count = 0;
+
+ if (!conn)
+ goto out;
+
+ mem_pool_destroy (conn->rxpool);
+
+ listener = conn->listener;
+ if (!listener)
+ goto out;
+
+ event = (listener->conn == conn) ? RPCSVC_EVENT_LISTENER_DEAD
+ : RPCSVC_EVENT_DISCONNECT;
+
+ svc = conn->svc;
+ if (!svc)
+ goto out;
+
+ pthread_mutex_lock (&svc->rpclock);
+ {
+ wrappers = GF_CALLOC (svc->notify_count, sizeof (*wrapper), 0);
+ if (!wrappers) {
+ goto unlock;
+ }
+
+ list_for_each_entry (wrapper, &conn->listener->list,
+ list) {
+ if (wrapper->notify) {
+ wrappers[i++] = *wrapper;
+ }
+ }
+ wrapper_count = i;
+ }
+unlock:
+ pthread_mutex_unlock (&svc->rpclock);
+
+ if (wrappers) {
+ for (i = 0; i < wrapper_count; i++) {
+ wrappers[i].notify (conn->svc, wrappers[i].data,
+ event, conn);
+ }
+
+ GF_FREE (wrappers);
+ }
+
+ if (listener->conn == conn) {
+ rpcsvc_listener_destroy (listener);
+ }
+
+ /* Need to destory record state, txlists etc. */
+ GF_FREE (conn);
+out:
+ gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Connection destroyed");
+}
+
+
+rpcsvc_conn_t *
+rpcsvc_conn_init (rpcsvc_t *svc, rpc_transport_t *trans)
+{
+ int ret = -1;
+ rpcsvc_conn_t *conn = NULL;
+
+ conn = rpcsvc_conn_alloc (svc, trans);
+ if (!conn) {
+ ret = -1;
+ gf_log (GF_RPCSVC, GF_LOG_DEBUG, "cannot init a connection");
+ goto out;
+ }
+
+ ret = rpc_transport_register_notify (trans, rpcsvc_notify, conn);
+ if (ret == -1) {
+ gf_log (GF_RPCSVC, GF_LOG_DEBUG, "registering notify failed");
+ rpcsvc_conn_destroy (conn);
+ conn = NULL;
+ goto out;
+ }
+
+ rpcsvc_conn_state_init (conn);
+
+out:
+ return conn;
+}
+
+
+int
+__rpcsvc_conn_unref (rpcsvc_conn_t *conn)
+{
+ --conn->connref;
+ return conn->connref;
+}
+
+
+void
+__rpcsvc_conn_deinit (rpcsvc_conn_t *conn)
+{
+ if (!conn)
+ return;
+
+ if (rpcsvc_conn_check_active (conn)) {
+ conn->connstate = RPCSVC_CONNSTATE_DISCONNECTED;
+ }
+
+ if (conn->trans) {
+ rpc_transport_disconnect (conn->trans);
+ conn->trans = NULL;
+ }
+}
+
+
+void
+rpcsvc_conn_deinit (rpcsvc_conn_t *conn)
+{
+ int ref = 0;
+
+ if (!conn)
+ return;
+
+ pthread_mutex_lock (&conn->connlock);
+ {
+ __rpcsvc_conn_deinit (conn);
+ ref = __rpcsvc_conn_unref (conn);
+ }
+ pthread_mutex_unlock (&conn->connlock);
+
+ if (ref == 0)
+ rpcsvc_conn_destroy (conn);
+
+ return;
+}
+
+
+void
+rpcsvc_conn_unref (rpcsvc_conn_t *conn)
+{
+ int ref = 0;
+ if (!conn)
+ return;
+
+ pthread_mutex_lock (&conn->connlock);
+ {
+ ref = __rpcsvc_conn_unref (conn);
+ }
+ pthread_mutex_unlock (&conn->connlock);
+
+ if (ref == 0) {
+ rpcsvc_conn_destroy (conn);
+ }
+}
+
+
+int
+rpcsvc_conn_active (rpcsvc_conn_t *conn)
+{
+ int status = 0;
+
+ if (!conn)
+ return 0;
+
+ pthread_mutex_lock (&conn->connlock);
+ {
+ status = rpcsvc_conn_check_active (conn);
+ }
+ pthread_mutex_unlock (&conn->connlock);
+
+ return status;
+}
+
+
+void
+rpcsvc_conn_ref (rpcsvc_conn_t *conn)
+{
+ if (!conn)
+ return;
+
+ pthread_mutex_lock (&conn->connlock);
+ {
+ ++conn->connref;
+ }
+ pthread_mutex_unlock (&conn->connlock);
+
+ return;
+}
+
+
+int
+rpcsvc_conn_privport_check (rpcsvc_t *svc, char *volname, rpcsvc_conn_t *conn)
+{
+ struct sockaddr_in sa;
+ int ret = RPCSVC_AUTH_REJECT;
+ socklen_t sasize = sizeof (sa);
+ char *srchstr = NULL;
+ char *valstr = NULL;
+ int globalinsecure = RPCSVC_AUTH_REJECT;
+ int exportinsecure = RPCSVC_AUTH_DONTCARE;
+ uint16_t port = 0;
+ gf_boolean_t insecure = _gf_false;
+
+ if ((!svc) || (!volname) || (!conn))
+ return ret;
+
+ ret = rpcsvc_conn_peeraddr (conn, NULL, 0, (struct sockaddr *)&sa,
+ sasize);
+ if (ret != 0) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to get peer addr: %s",
+ gai_strerror (ret));
+ ret = RPCSVC_AUTH_REJECT;
+ goto err;
+ }
+
+ port = ntohs (sa.sin_port);
+ gf_log (GF_RPCSVC, GF_LOG_TRACE, "Client port: %d", (int)port);
+ /* If the port is already a privileged one, dont bother with checking
+ * options.
+ */
+ if (port <= 1024) {
+ ret = RPCSVC_AUTH_ACCEPT;
+ goto err;
+ }
+
+ /* Disabled by default */
+ if ((dict_get (svc->options, "rpc-auth.ports.insecure"))) {
+ ret = dict_get_str (svc->options, "rpc-auth.ports.insecure"
+ , &srchstr);
+ if (ret == 0) {
+ ret = gf_string2boolean (srchstr, &insecure);
+ if (ret == 0) {
+ if (insecure == _gf_true)
+ globalinsecure = RPCSVC_AUTH_ACCEPT;
+ } else
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to"
+ " read rpc-auth.ports.insecure value");
+ } else
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to"
+ " read rpc-auth.ports.insecure value");
+ }
+
+ /* Disabled by default */
+ ret = gf_asprintf (&srchstr, "rpc-auth.ports.%s.insecure", volname);
+ if (ret == -1) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "asprintf failed");
+ ret = RPCSVC_AUTH_REJECT;
+ goto err;
+ }
+
+ if (dict_get (svc->options, srchstr)) {
+ ret = dict_get_str (svc->options, srchstr, &valstr);
+ if (ret == 0) {
+ ret = gf_string2boolean (srchstr, &insecure);
+ if (ret == 0) {
+ if (insecure == _gf_true)
+ exportinsecure = RPCSVC_AUTH_ACCEPT;
+ else
+ exportinsecure = RPCSVC_AUTH_REJECT;
+ } else
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to"
+ " read rpc-auth.ports.insecure value");
+ } else
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to"
+ " read rpc-auth.ports.insecure value");
+ }
+
+ ret = rpcsvc_combine_gen_spec_volume_checks (globalinsecure,
+ exportinsecure);
+ if (ret == RPCSVC_AUTH_ACCEPT)
+ gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Unprivileged port allowed");
+ else
+ gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Unprivileged port not"
+ " allowed");
+
+err:
+ return ret;
+}
+
+
+/* This needs to change to returning errors, since
+ * we need to return RPC specific error messages when some
+ * of the pointers below are NULL.
+ */
+rpcsvc_actor_t *
+rpcsvc_program_actor (rpcsvc_conn_t *conn, rpcsvc_request_t *req)
+{
+ rpcsvc_program_t *program = NULL;
+ int err = SYSTEM_ERR;
+ rpcsvc_actor_t *actor = NULL;
+ rpcsvc_t *svc = NULL;
+ char found = 0;
+
+ if ((!conn) || (!req))
+ goto err;
+
+ svc = conn->svc;
+ pthread_mutex_lock (&svc->rpclock);
+ {
+ list_for_each_entry (program, &svc->programs, program) {
+ if (program->prognum == req->prognum) {
+ err = PROG_MISMATCH;
+ }
+
+ if ((program->prognum == req->prognum)
+ && (program->progver == req->progver)) {
+ found = 1;
+ break;
+ }
+ }
+ }
+ pthread_mutex_unlock (&svc->rpclock);
+
+ if (!found) {
+ if (err != PROG_MISMATCH) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR,
+ "RPC program not available");
+ err = PROG_UNAVAIL;
+ goto err;
+ }
+
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC program version not"
+ " available");
+ goto err;
+ }
+ req->prog = program;
+ if (!program->actors) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC System error");
+ err = SYSTEM_ERR;
+ goto err;
+ }
+
+ if ((req->procnum < 0) || (req->procnum >= program->numactors)) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC Program procedure not"
+ " available");
+ err = PROC_UNAVAIL;
+ goto err;
+ }
+
+ actor = &program->actors[req->procnum];
+ if (!actor->actor) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC Program procedure not"
+ " available");
+ err = PROC_UNAVAIL;
+ actor = NULL;
+ goto err;
+ }
+
+ err = SUCCESS;
+ gf_log (GF_RPCSVC, GF_LOG_TRACE, "Actor found: %s - %s",
+ program->progname, actor->procname);
+err:
+ if (req)
+ req->rpc_err = err;
+
+ return actor;
+}
+
+
+/* this procedure can only pass 4 arguments to registered notifyfn. To send more
+ * arguements call wrapper->notify directly.
+ */
+inline void
+rpcsvc_program_notify (rpcsvc_listener_t *listener, rpcsvc_event_t event,
+ void *data)
+{
+ rpcsvc_notify_wrapper_t *wrapper = NULL;
+
+ if (!listener) {
+ goto out;
+ }
+
+ list_for_each_entry (wrapper, &listener->list, list) {
+ if (wrapper->notify) {
+ wrapper->notify (listener->conn->svc,
+ wrapper->data,
+ event, data);
+ }
+ }
+
+out:
+ return;
+}
+
+
+int
+rpcsvc_accept (rpcsvc_conn_t *listen_conn, rpc_transport_t *new_trans)
+{
+ rpcsvc_listener_t *listener = NULL;
+ rpcsvc_conn_t *conn = NULL;
+ char clstr[RPCSVC_PEER_STRLEN];
+
+ listener = listen_conn->listener;
+ conn = rpcsvc_conn_init (listen_conn->svc, new_trans);
+ if (!conn) {
+ rpc_transport_disconnect (new_trans);
+ memset (clstr, 0, RPCSVC_PEER_STRLEN);
+ rpc_transport_get_peername (new_trans, clstr,
+ RPCSVC_PEER_STRLEN);
+ gf_log (GF_RPCSVC, GF_LOG_DEBUG, "allocating connection for "
+ "new transport (%s) failed", clstr);
+ goto out;
+ }
+
+ conn->listener = listener;
+
+ //rpcsvc_program_notify (listener, RPCSVC_EVENT_ACCEPT, conn);
+out:
+ return 0;
+}
+
+
+void
+rpcsvc_request_destroy (rpcsvc_conn_t *conn, rpcsvc_request_t *req)
+{
+ if (!conn || !req) {
+ goto out;
+ }
+
+ if (req->recordiob) {
+ iobuf_unref (req->recordiob);
+ }
+
+ if (req->vectorediob) {
+ iobuf_unref (req->vectorediob);
+ }
+
+ mem_put (conn->rxpool, req);
+out:
+ return;
+}
+
+
+rpcsvc_request_t *
+rpcsvc_request_init (rpcsvc_conn_t *conn, struct rpc_msg *callmsg,
+ struct iovec progmsg, rpc_transport_pollin_t *msg,
+ rpcsvc_request_t *req)
+{
+ if ((!conn) || (!callmsg)|| (!req) || (!msg))
+ return NULL;
+
+ /* We start a RPC request as always denied. */
+ req->rpc_status = MSG_DENIED;
+ req->xid = rpc_call_xid (callmsg);
+ req->prognum = rpc_call_program (callmsg);
+ req->progver = rpc_call_progver (callmsg);
+ req->procnum = rpc_call_progproc (callmsg);
+ req->conn = conn;
+ req->msg[0] = progmsg;
+ if (msg->vectored) {
+ req->msg[1].iov_base = iobuf_ptr (msg->data.vector.iobuf2);
+ req->msg[1].iov_len = msg->data.vector.size2;
+
+ req->recordiob = iobuf_ref (msg->data.vector.iobuf1);
+ req->vectorediob = iobuf_ref (msg->data.vector.iobuf2);
+ } else {
+ req->recordiob = iobuf_ref (msg->data.simple.iobuf);
+ }
+
+ req->trans_private = msg->private;
+
+ INIT_LIST_HEAD (&req->txlist);
+ req->payloadsize = 0;
+
+ /* By this time, the data bytes for the auth scheme would have already
+ * been copied into the required sections of the req structure,
+ * we just need to fill in the meta-data about it now.
+ */
+ req->cred.flavour = rpc_call_cred_flavour (callmsg);
+ req->cred.datalen = rpc_call_cred_len (callmsg);
+ req->verf.flavour = rpc_call_verf_flavour (callmsg);
+ req->verf.datalen = rpc_call_verf_len (callmsg);
+
+ /* AUTH */
+ rpcsvc_auth_request_init (req);
+ return req;
+}
+
+
+rpcsvc_request_t *
+rpcsvc_request_create (rpcsvc_conn_t *conn, rpc_transport_pollin_t *msg)
+{
+ char *msgbuf = NULL;
+ struct rpc_msg rpcmsg;
+ struct iovec progmsg; /* RPC Program payload */
+ rpcsvc_request_t *req = NULL;
+ size_t msglen = 0;
+ int ret = -1;
+
+ if (!conn)
+ return NULL;
+
+ /* We need to allocate the request before actually calling
+ * rpcsvc_request_init on the request so that we, can fill the auth
+ * data directly into the request structure from the message iobuf.
+ * This avoids a need to keep a temp buffer into which the auth data
+ * would've been copied otherwise.
+ */
+ rpcsvc_alloc_request (conn, req);
+ if (!req) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to alloc request");
+ goto err;
+ }
+
+ if (msg->vectored) {
+ msgbuf = iobuf_ptr (msg->data.vector.iobuf1);
+ msglen = msg->data.vector.size1;
+ } else {
+ msgbuf = iobuf_ptr (msg->data.simple.iobuf);
+ msglen = msg->data.simple.size;
+ }
+
+ ret = xdr_to_rpc_call (msgbuf, msglen, &rpcmsg, &progmsg,
+ req->cred.authdata,req->verf.authdata);
+
+ if (ret == -1) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC call decoding failed");
+ rpcsvc_request_seterr (req, GARBAGE_ARGS);
+ goto err;
+ }
+
+ ret = -1;
+ rpcsvc_request_init (conn, &rpcmsg, progmsg, msg, req);
+
+ gf_log (GF_RPCSVC, GF_LOG_TRACE, "RPC XID: %lx, Ver: %ld, Program: %ld,"
+ " ProgVers: %ld, Proc: %ld", rpc_call_xid (&rpcmsg),
+ rpc_call_rpcvers (&rpcmsg), rpc_call_program (&rpcmsg),
+ rpc_call_progver (&rpcmsg), rpc_call_progproc (&rpcmsg));
+
+ if (rpc_call_rpcvers (&rpcmsg) != 2) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "RPC version not supported");
+ rpcsvc_request_seterr (req, RPC_MISMATCH);
+ goto err;
+ }
+
+ ret = rpcsvc_authenticate (req);
+ if (ret == RPCSVC_AUTH_REJECT) {
+ /* No need to set auth_err, that is the responsibility of
+ * the authentication handler since only that know what exact
+ * error happened.
+ */
+ rpcsvc_request_seterr (req, AUTH_ERROR);
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed authentication");
+ ret = -1;
+ goto err;
+ }
+
+
+ /* If the error is not RPC_MISMATCH, we consider the call as accepted
+ * since we are not handling authentication failures for now.
+ */
+ req->rpc_status = MSG_ACCEPTED;
+ ret = 0;
+err:
+ if (ret == -1) {
+ ret = rpcsvc_error_reply (req);
+ req = NULL;
+ }
+
+ return req;
+}
+
+
+int
+rpcsvc_handle_rpc_call (rpcsvc_conn_t *conn, rpc_transport_pollin_t *msg)
+{
+ rpcsvc_actor_t *actor = NULL;
+ rpcsvc_request_t *req = NULL;
+ int ret = -1;
+
+ if (!conn)
+ return -1;
+
+ req = rpcsvc_request_create (conn, msg);
+ if (!req)
+ goto err;
+
+ if (!rpcsvc_request_accepted (req))
+ goto err_reply;
+
+ actor = rpcsvc_program_actor (conn, req);
+ if (!actor)
+ goto err_reply;
+
+ if (actor) {
+ if (req->vectorediob) {
+ if (actor->vector_actor) {
+ rpcsvc_conn_ref (conn);
+ ret = actor->vector_actor (req,
+ req->vectorediob);
+ } else {
+ rpcsvc_request_seterr (req, PROC_UNAVAIL);
+ gf_log (GF_RPCSVC, GF_LOG_ERROR,
+ "No vectored handler present");
+ ret = RPCSVC_ACTOR_ERROR;
+ }
+ } else if (actor->actor) {
+ rpcsvc_conn_ref (req->conn);
+ ret = actor->actor (req);
+ }
+ }
+
+err_reply:
+ if (ret == RPCSVC_ACTOR_ERROR)
+ ret = rpcsvc_error_reply (req);
+
+ /* No need to propagate error beyond this function since the reply
+ * has now been queued. */
+ ret = 0;
+err:
+ return ret;
+}
+
+
+int
+rpcsvc_notify (rpc_transport_t *trans, void *mydata,
+ rpc_transport_event_t event, void *data, ...)
+{
+ rpcsvc_conn_t *conn = NULL;
+ rpcsvc_t *svc = NULL;
+ int ret = -1;
+ rpc_transport_pollin_t *msg = NULL;
+ rpc_transport_t *new_trans = NULL;
+
+ conn = mydata;
+ if (conn == NULL) {
+ goto out;
+ }
+
+ svc = conn->svc;
+
+ switch (event) {
+ case RPC_TRANSPORT_ACCEPT:
+ new_trans = data;
+ ret = rpcsvc_accept (conn, new_trans);
+ break;
+
+ case RPC_TRANSPORT_DISCONNECT:
+ //rpcsvc_conn_deinit (conn);
+ ret = 0;
+ break;
+
+ case RPC_TRANSPORT_MSG_RECEIVED:
+ msg = data;
+ ret = rpcsvc_handle_rpc_call (conn, msg);
+ break;
+
+ case RPC_TRANSPORT_MSG_SENT:
+ ret = 0;
+ break;
+
+ case RPC_TRANSPORT_CONNECT:
+ /* do nothing, no need for rpcsvc to handle this, client should
+ * handle this event
+ */
+ gf_log ("rpcsvc", GF_LOG_CRITICAL,
+ "got CONNECT event, which should have not come");
+ ret = 0;
+ break;
+
+ case RPC_TRANSPORT_CLEANUP:
+ /* FIXME: think about this later */
+ ret = 0;
+ break;
+
+ case RPC_TRANSPORT_MAP_XID_REQUEST:
+ /* FIXME: think about this later */
+ gf_log ("rpcsvc", GF_LOG_CRITICAL,
+ "got MAP_XID event, which should have not come");
+ ret = 0;
+ break;
+ }
+
+out:
+ return ret;
+}
+
+
+void
+rpcsvc_set_lastfrag (uint32_t *fragsize) {
+ (*fragsize) |= 0x80000000U;
+}
+
+void
+rpcsvc_set_frag_header_size (uint32_t size, char *haddr)
+{
+ size = htonl (size);
+ memcpy (haddr, &size, sizeof (size));
+}
+
+void
+rpcsvc_set_last_frag_header_size (uint32_t size, char *haddr)
+{
+ rpcsvc_set_lastfrag (&size);
+ rpcsvc_set_frag_header_size (size, haddr);
+}
+
+
+/* Given the RPC reply structure and the payload handed by the RPC program,
+ * encode the RPC record header into the buffer pointed by recordstart.
+ */
+struct iovec
+rpcsvc_record_build_header (char *recordstart, size_t rlen,
+ struct rpc_msg reply, size_t payload)
+{
+ struct iovec replyhdr;
+ struct iovec txrecord = {0, 0};
+ size_t fraglen = 0;
+ int ret = -1;
+
+ /* After leaving aside the 4 bytes for the fragment header, lets
+ * encode the RPC reply structure into the buffer given to us.
+ */
+ ret = rpc_reply_to_xdr (&reply,(recordstart + RPCSVC_FRAGHDR_SIZE),
+ rlen, &replyhdr);
+ if (ret == -1) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to create RPC reply");
+ goto err;
+ }
+
+ fraglen = payload + replyhdr.iov_len;
+ gf_log (GF_RPCSVC, GF_LOG_TRACE, "Reply fraglen %zu, payload: %zu, "
+ "rpc hdr: %zu", fraglen, payload, replyhdr.iov_len);
+
+ /* Since we're not spreading RPC records over mutiple fragments
+ * we just set this fragment as the first and last fragment for this
+ * record.
+ */
+ rpcsvc_set_last_frag_header_size (fraglen, recordstart);
+
+ /* Even though the RPC record starts at recordstart+RPCSVC_FRAGHDR_SIZE
+ * we need to transmit the record with the fragment header, which starts
+ * at recordstart.
+ */
+ txrecord.iov_base = recordstart;
+
+ /* Remember, this is only the vec for the RPC header and does not
+ * include the payload above. We needed the payload only to calculate
+ * the size of the full fragment. This size is sent in the fragment
+ * header.
+ */
+ txrecord.iov_len = RPCSVC_FRAGHDR_SIZE + replyhdr.iov_len;
+err:
+ return txrecord;
+}
+
+
+int
+rpcsvc_conn_submit (rpcsvc_conn_t *conn, struct iovec *hdrvec,
+ int hdrcount, struct iovec *proghdr, int proghdrcount,
+ struct iovec *progpayload, int progpayloadcount,
+ struct iobref *iobref, void *priv)
+{
+ int ret = -1;
+ rpc_transport_reply_t reply = {{0, }};
+
+ if ((!conn) || (!hdrvec) || (!hdrvec->iov_base) || (!conn->trans)) {
+ goto out;
+ }
+
+ reply.msg.rpchdr = hdrvec;
+ reply.msg.rpchdrcount = hdrcount;
+ reply.msg.proghdr = proghdr;
+ reply.msg.proghdrcount = proghdrcount;
+ reply.msg.progpayload = progpayload;
+ reply.msg.progpayloadcount = progpayloadcount;
+ reply.msg.iobref = iobref;
+ reply.private = priv;
+
+ /* Now that we have both the RPC and Program buffers in xdr format
+ * lets hand it to the transmission layer.
+ */
+ if (!rpcsvc_conn_check_active (conn)) {
+ gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Connection inactive");
+ goto out;
+ }
+
+ ret = rpc_transport_submit_reply (conn->trans, &reply);
+
+out:
+ return ret;
+}
+
+
+int
+rpcsvc_fill_reply (rpcsvc_request_t *req, struct rpc_msg *reply)
+{
+ rpcsvc_program_t *prog = NULL;
+ if ((!req) || (!reply))
+ return -1;
+
+ prog = rpcsvc_request_program (req);
+ rpc_fill_empty_reply (reply, req->xid);
+
+ if (req->rpc_status == MSG_DENIED)
+ rpc_fill_denied_reply (reply, req->rpc_err, req->auth_err);
+ else if (req->rpc_status == MSG_ACCEPTED)
+ rpc_fill_accepted_reply (reply, req->rpc_err, prog->proglowvers,
+ prog->proghighvers, req->verf.flavour,
+ req->verf.datalen,
+ req->verf.authdata);
+ else
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Invalid rpc_status value");
+
+ return 0;
+}
+
+
+/* Given a request and the reply payload, build a reply and encodes the reply
+ * into a record header. This record header is encoded into the vector pointed
+ * to be recbuf.
+ * msgvec is the buffer that points to the payload of the RPC program.
+ * This buffer can be NULL, if an RPC error reply is being constructed.
+ * The only reason it is needed here is that in case the buffer is provided,
+ * we should account for the length of that buffer in the RPC fragment header.
+ */
+struct iobuf *
+rpcsvc_record_build_record (rpcsvc_request_t *req, size_t payload,
+ struct iovec *recbuf)
+{
+ struct rpc_msg reply;
+ struct iobuf *replyiob = NULL;
+ char *record = NULL;
+ struct iovec recordhdr = {0, };
+ size_t pagesize = 0;
+ rpcsvc_conn_t *conn = NULL;
+ rpcsvc_t *svc = NULL;
+
+ if ((!req) || (!req->conn) || (!recbuf))
+ return NULL;
+
+ /* First, try to get a pointer into the buffer which the RPC
+ * layer can use.
+ */
+ conn = req->conn;
+ svc = rpcsvc_conn_rpcsvc (conn);
+ replyiob = iobuf_get (svc->ctx->iobuf_pool);
+ pagesize = iobpool_pagesize ((struct iobuf_pool *)svc->ctx->iobuf_pool);
+ if (!replyiob) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to get iobuf");
+ goto err_exit;
+ }
+
+ record = iobuf_ptr (replyiob); /* Now we have it. */
+
+ /* Fill the rpc structure and XDR it into the buffer got above. */
+ rpcsvc_fill_reply (req, &reply);
+ recordhdr = rpcsvc_record_build_header (record, pagesize, reply,
+ payload);
+ if (!recordhdr.iov_base) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to build record "
+ " header");
+ iobuf_unref (replyiob);
+ replyiob = NULL;
+ recbuf->iov_base = NULL;
+ goto err_exit;
+ }
+
+ recbuf->iov_base = recordhdr.iov_base;
+ recbuf->iov_len = recordhdr.iov_len;
+err_exit:
+ return replyiob;
+}
+
+
+/*
+ * The function to submit a program message to the RPC service.
+ * This message is added to the transmission queue of the
+ * conn.
+ *
+ * Program callers are not expected to use the msgvec->iov_base
+ * address for anything else.
+ * Nor are they expected to free it once this function returns.
+ * Once the transmission of the buffer is completed by the RPC service,
+ * the memory area as referenced through @msg will be unrefed.
+ * If a higher layer does not want anything to do with this iobuf
+ * after this function returns, it should call unref on it. For keeping
+ * it around till the transmission is actually complete, rpcsvc also refs it.
+ * *
+ * If this function returns an error by returning -1, the
+ * higher layer programs should assume that a disconnection happened
+ * and should know that the conn memory area as well as the req structure
+ * has been freed internally.
+ *
+ * For now, this function assumes that a submit is always called
+ * to send a new record. Later, if there is a situation where different
+ * buffers for the same record come from different sources, then we'll
+ * need to change this code to account for multiple submit calls adding
+ * the buffers into a single record.
+ */
+
+int
+rpcsvc_submit_generic (rpcsvc_request_t *req, struct iovec *proghdr,
+ int hdrcount, struct iovec *payload, int payloadcount,
+ struct iobref *iobref)
+{
+ int ret = -1, i = 0;
+ struct iobuf *replyiob = NULL;
+ struct iovec recordhdr = {0, };
+ rpcsvc_conn_t *conn = NULL;
+ size_t msglen = 0;
+ char new_iobref = 0;
+
+ if ((!req) || (!req->conn))
+ return -1;
+
+ conn = req->conn;
+
+ for (i = 0; i < hdrcount; i++) {
+ msglen += proghdr[i].iov_len;
+ }
+
+ for (i = 0; i < payloadcount; i++) {
+ msglen += payload[i].iov_len;
+ }
+
+ gf_log (GF_RPCSVC, GF_LOG_TRACE, "Tx message: %zu", msglen);
+
+ /* Build the buffer containing the encoded RPC reply. */
+ replyiob = rpcsvc_record_build_record (req, msglen, &recordhdr);
+ if (!replyiob) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR,"Reply record creation failed");
+ goto disconnect_exit;
+ }
+
+ if (!iobref) {
+ iobref = iobref_new ();
+ if (!iobref) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "memory allocation "
+ "failed");
+ goto disconnect_exit;
+ }
+
+ new_iobref = 1;
+ }
+
+ iobref_add (iobref, replyiob);
+
+ ret = rpcsvc_conn_submit (conn, &recordhdr, 1, proghdr, hdrcount,
+ payload, payloadcount, iobref,
+ req->trans_private);
+
+ rpcsvc_request_destroy (conn, req);
+
+ if (ret == -1) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Failed to submit message");
+ }
+
+disconnect_exit:
+ if (replyiob) {
+ iobuf_unref (replyiob);
+ }
+
+ if (new_iobref) {
+ iobref_unref (iobref);
+ }
+
+ /* Note that a unref is called everytime a reply is sent. This is in
+ * response to the ref that is performed on the conn when a request is
+ * handed to the RPC program.
+ *
+ * The catch, however, is that if the reply is an rpc error, we must
+ * not unref. This is because the ref only contains
+ * references for the actors to which the request was handed plus one
+ * reference maintained by the RPC layer. By unrefing for a case where
+ * no actor was called, we will be losing the ref held for the RPC
+ * layer.
+ */
+ if ((rpcsvc_request_accepted (req)) &&
+ (rpcsvc_request_accepted_success (req)))
+ rpcsvc_conn_unref (conn);
+
+ return ret;
+}
+
+
+int
+rpcsvc_error_reply (rpcsvc_request_t *req)
+{
+ struct iovec dummyvec = {0, };
+
+ if (!req)
+ return -1;
+
+ /* At this point the req should already have been filled with the
+ * appropriate RPC error numbers.
+ */
+ return rpcsvc_submit_generic (req, &dummyvec, 0, NULL, 0, NULL);
+}
+
+
+/* Register the program with the local portmapper service. */
+int
+rpcsvc_program_register_portmap (rpcsvc_program_t *newprog, rpcsvc_conn_t *conn)
+{
+ int ret = 0;
+ struct sockaddr_in sa = {0, };
+
+ if (!newprog || !conn->trans) {
+ goto out;
+ }
+
+ if (!(pmap_set (newprog->prognum, newprog->progver, IPPROTO_TCP,
+ sa.sin_port))) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Could not register with"
+ " portmap");
+ goto out;
+ }
+
+ ret = 0;
+out:
+ return ret;
+}
+
+
+int
+rpcsvc_program_unregister_portmap (rpcsvc_program_t *prog)
+{
+ if (!prog)
+ return -1;
+
+ if (!(pmap_unset(prog->prognum, prog->progver))) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Could not unregister with"
+ " portmap");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+rpcsvc_listener_t *
+rpcsvc_get_listener (rpcsvc_t *svc, uint16_t port)
+{
+ rpcsvc_listener_t *listener = NULL;
+ char found = 0;
+
+ if (!svc) {
+ goto out;
+ }
+
+ pthread_mutex_lock (&svc->rpclock);
+ {
+ list_for_each_entry (listener, &svc->listeners, list) {
+ if (((struct sockaddr_in *)&listener->sa)->sin_port
+ == port) {
+ found = 1;
+ break;
+ }
+ }
+ }
+ pthread_mutex_unlock (&svc->rpclock);
+
+ if (!found) {
+ listener = NULL;
+ }
+
+out:
+ return listener;
+}
+
+
+/* The only difference between the generic submit and this one is that the
+ * generic submit is also used for submitting RPC error replies in where there
+ * are no payloads so the msgvec and msgbuf can be NULL.
+ * Since RPC programs should be using this function along with their payloads
+ * we must perform NULL checks before calling the generic submit.
+ */
+int
+rpcsvc_submit_message (rpcsvc_request_t *req, struct iovec *proghdr,
+ int hdrcount, struct iovec *payload, int payloadcount,
+ struct iobref *iobref)
+{
+ if ((!req) || (!req->conn) || (!proghdr) || (!proghdr->iov_base))
+ return -1;
+
+ return rpcsvc_submit_generic (req, proghdr, hdrcount, payload,
+ payloadcount, iobref);
+}
+
+
+int
+rpcsvc_program_unregister (rpcsvc_t *svc, rpcsvc_program_t prog)
+{
+ int ret = -1;
+
+ if (!svc)
+ return -1;
+
+ /* TODO: De-init the listening connection for this program. */
+ ret = rpcsvc_program_unregister_portmap (&prog);
+ if (ret == -1) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "portmap unregistration of"
+ " program failed");
+ goto err;
+ }
+
+ ret = 0;
+ gf_log (GF_RPCSVC, GF_LOG_DEBUG, "Program unregistered: %s, Num: %d,"
+ " Ver: %d, Port: %d", prog.progname, prog.prognum,
+ prog.progver, prog.progport);
+
+err:
+ if (ret == -1)
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "Program unregistration failed"
+ ": %s, Num: %d, Ver: %d, Port: %d", prog.progname,
+ prog.prognum, prog.progver, prog.progport);
+
+ return ret;
+}
+
+
+int
+rpcsvc_conn_peername (rpcsvc_conn_t *conn, char *hostname, int hostlen)
+{
+ if (!conn || !conn->trans)
+ return -1;
+
+ return rpc_transport_get_peername (conn->trans, hostname, hostlen);
+}
+
+
+int
+rpcsvc_conn_peeraddr (rpcsvc_conn_t *conn, char *addrstr, int addrlen,
+ struct sockaddr *sa, socklen_t sasize)
+{
+ if (!conn || !conn->trans)
+ return -1;
+
+ return rpc_transport_get_peeraddr(conn->trans, addrstr, addrlen, sa,
+ sasize);
+}
+
+
+rpcsvc_conn_t *
+rpcsvc_conn_create (rpcsvc_t *svc, dict_t *options, char *name)
+{
+ int ret = -1;
+ rpc_transport_t *trans = NULL;
+ rpcsvc_conn_t *conn = NULL;
+
+ trans = rpc_transport_load (svc->ctx, options, name);
+ if (!trans) {
+ gf_log (GF_RPCSVC, GF_LOG_DEBUG, "cannot create listener, "
+ "initing the transport failed");
+ goto out;
+ }
+
+ ret = rpc_transport_listen (trans);
+ if (ret == -1) {
+ gf_log (GF_RPCSVC, GF_LOG_DEBUG,
+ "listening on transport failed");
+ goto out;
+ }
+
+ conn = rpcsvc_conn_init (svc, trans);
+ if (!conn) {
+ ret = -1;
+ gf_log (GF_RPCSVC, GF_LOG_DEBUG,
+ "initializing connection for transport failed");
+ goto out;
+ }
+
+ ret = 0;
+out:
+ if ((ret == -1) && (trans)) {
+ rpc_transport_disconnect (trans);
+ }
+
+ return conn;
+}
+
+rpcsvc_listener_t *
+rpcsvc_listener_alloc (rpcsvc_t *svc, rpcsvc_conn_t *conn)
+{
+ rpcsvc_listener_t *listener = NULL;
+ int ret = -1;
+
+ listener = GF_CALLOC (1, sizeof (*listener), 0);
+ if (!listener) {
+ gf_log (GF_RPCSVC, GF_LOG_ERROR, "memory allocation failed");
+ goto out;
+ }
+
+ /* TODO: unresolved symbol */
+ ret = rpc_transport_get_myaddr (conn->trans, NULL, 0,
+ &listener->sa,
+ sizeof (listener->sa));
+ ret = 0;
+ if (ret == -1) {
+ GF_FREE (listener);
+ listener = NULL;
+ goto out;
+ }
+
+ listener->conn = conn;
+
+ INIT_LIST_HEAD (&listener->list);
+
+ pthread_mutex_lock (&svc->rpclock);
+ {
+ list_add_tail (&listener->list, &svc->listeners);
+ }
+ pthread_mutex_unlock (&svc->rpclock);
+out:
+ return listener;
+}
+
+
+rpcsvc_listener_t *
+rpcsvc_create_listener (rpcsvc_t *svc, dict_t *options, char *name)
+{
+ rpcsvc_conn_t *conn = NULL;
+ rpcsvc_listener_t *listener = NULL;
+
+ if (!svc || !options) {
+ goto out;
+ }
+
+ conn = rpcsvc_conn_create (svc, options, name);
+ if (!conn) {
+ goto out;
+ }
+
+ li