diff options
Diffstat (limited to 'xlators/protocol/client/src')
| -rw-r--r-- | xlators/protocol/client/src/Makefile.am | 13 | ||||
| -rw-r--r-- | xlators/protocol/client/src/client-callback.c | 25 | ||||
| -rw-r--r-- | xlators/protocol/client/src/client-handshake.c | 1086 | ||||
| -rw-r--r-- | xlators/protocol/client/src/client-helpers.c | 162 | ||||
| -rw-r--r-- | xlators/protocol/client/src/client-lk.c | 424 | ||||
| -rw-r--r-- | xlators/protocol/client/src/client-mem-types.h | 23 | ||||
| -rw-r--r-- | xlators/protocol/client/src/client-rpc-fops.c | 6203 | ||||
| -rw-r--r-- | xlators/protocol/client/src/client.c | 1047 | ||||
| -rw-r--r-- | xlators/protocol/client/src/client.h | 148 | ||||
| -rw-r--r-- | xlators/protocol/client/src/client3_1-fops.c | 5447 |
10 files changed, 8055 insertions, 6523 deletions
diff --git a/xlators/protocol/client/src/Makefile.am b/xlators/protocol/client/src/Makefile.am index 29c6e9dde..cf89d42da 100644 --- a/xlators/protocol/client/src/Makefile.am +++ b/xlators/protocol/client/src/Makefile.am @@ -2,16 +2,19 @@ xlator_LTLIBRARIES = client.la xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/protocol -client_la_LDFLAGS = -module -avoidversion +client_la_LDFLAGS = -module -avoid-version client_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ $(top_builddir)/rpc/rpc-lib/src/libgfrpc.la \ $(top_builddir)/rpc/xdr/src/libgfxdr.la -client_la_SOURCES = client.c client-helpers.c client3_1-fops.c \ +client_la_SOURCES = client.c client-helpers.c client-rpc-fops.c \ client-handshake.c client-callback.c client-lk.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)/rpc/xdr/src -I$(top_srcdir)/rpc/rpc-lib/src/
\ No newline at end of file +AM_CPPFLAGS = $(GF_CPPFLAGS) \ + -I$(top_srcdir)/libglusterfs/src \ + -I$(top_srcdir)/rpc/xdr/src -I$(top_srcdir)/rpc/rpc-lib/src/ + +AM_CFLAGS = -Wall $(GF_CFLAGS) diff --git a/xlators/protocol/client/src/client-callback.c b/xlators/protocol/client/src/client-callback.c index bfc864112..d886862f7 100644 --- a/xlators/protocol/client/src/client-callback.c +++ b/xlators/protocol/client/src/client-callback.c @@ -1,20 +1,11 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.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 Affero 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 - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. */ #ifndef _CONFIG_H @@ -26,7 +17,7 @@ #include "rpc-clnt.h" int -client_cbk_null (void *data) +client_cbk_null (struct rpc_clnt *rpc, void *mydata, void *data) { gf_log (THIS->name, GF_LOG_WARNING, "this function should not be called"); @@ -34,7 +25,7 @@ client_cbk_null (void *data) } int -client_cbk_fetchspec (void *data) +client_cbk_fetchspec (struct rpc_clnt *rpc, void *mydata, void *data) { gf_log (THIS->name, GF_LOG_WARNING, "this function should not be called"); @@ -42,7 +33,7 @@ client_cbk_fetchspec (void *data) } int -client_cbk_ino_flush (void *data) +client_cbk_ino_flush (struct rpc_clnt *rpc, void *mydata, void *data) { gf_log (THIS->name, GF_LOG_WARNING, "this function should not be called"); diff --git a/xlators/protocol/client/src/client-handshake.c b/xlators/protocol/client/src/client-handshake.c index 5af149d56..5668fea53 100644 --- a/xlators/protocol/client/src/client-handshake.c +++ b/xlators/protocol/client/src/client-handshake.c @@ -1,20 +1,11 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.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 Affero 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 - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. */ #ifndef _CONFIG_H @@ -22,6 +13,7 @@ #include "config.h" #endif +#include "fd-lk.h" #include "client.h" #include "xlator.h" #include "defaults.h" @@ -30,14 +22,28 @@ #include "compat-errno.h" #include "glusterfs3.h" -#include "portmap.h" +#include "portmap-xdr.h" +#include "rpc-common-xdr.h" -extern rpc_clnt_prog_t clnt3_1_fop_prog; +#define CLIENT_REOPEN_MAX_ATTEMPTS 1024 +extern rpc_clnt_prog_t clnt3_3_fop_prog; extern rpc_clnt_prog_t clnt_pmap_prog; int client_ping_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe); +int client_set_lk_version_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe); + +int client_set_lk_version (xlator_t *this); + +typedef struct client_fd_lk_local { + int ref; + gf_boolean_t error; + gf_lock_t lock; + clnt_fd_ctx_t *fdctx; +}clnt_fd_lk_local_t; + /* Handshake */ void @@ -47,7 +53,7 @@ rpc_client_ping_timer_expired (void *data) rpc_clnt_connection_t *conn = NULL; int disconnect = 0; int transport_activity = 0; - struct timeval timeout = {0, }; + struct timespec timeout = {0, }; struct timeval current = {0, }; struct rpc_clnt *clnt = NULL; xlator_t *this = NULL; @@ -56,7 +62,7 @@ rpc_client_ping_timer_expired (void *data) this = data; if (!this || !this->private) { - gf_log ("", GF_LOG_WARNING, "xlator initialization not done"); + gf_log (THIS->name, GF_LOG_WARNING, "xlator initialization not done"); goto out; } @@ -95,7 +101,7 @@ rpc_client_ping_timer_expired (void *data) "ping timer expired but transport activity " "detected - not bailing transport"); timeout.tv_sec = conf->opt.ping_timeout; - timeout.tv_usec = 0; + timeout.tv_nsec = 0; conn->ping_timer = gf_timer_call_after (this->ctx, timeout, @@ -134,13 +140,13 @@ client_start_ping (void *data) clnt_conf_t *conf = NULL; rpc_clnt_connection_t *conn = NULL; int32_t ret = -1; - struct timeval timeout = {0, }; + struct timespec timeout = {0, }; call_frame_t *frame = NULL; int frame_count = 0; this = data; if (!this || !this->private) { - gf_log ("", GF_LOG_WARNING, "xlator not initialized"); + gf_log (THIS->name, GF_LOG_WARNING, "xlator not initialized"); goto fail; } @@ -190,7 +196,7 @@ client_start_ping (void *data) } timeout.tv_sec = conf->opt.ping_timeout; - timeout.tv_usec = 0; + timeout.tv_nsec = 0; conn->ping_timer = gf_timer_call_after (this->ctx, timeout, @@ -211,15 +217,16 @@ client_start_ping (void *data) goto fail; ret = client_submit_request (this, NULL, frame, conf->handshake, - GF_HNDSK_PING, client_ping_cbk, NULL, NULL, - NULL, 0, NULL, 0, NULL); - if (ret) - goto fail; + GF_HNDSK_PING, client_ping_cbk, NULL, + NULL, 0, NULL, 0, NULL, (xdrproc_t)NULL); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, + "failed to start ping timer"); + } return; -fail: - gf_log ("", GF_LOG_ERROR, "failed to start ping timer"); +fail: if (frame) { STACK_DESTROY (frame->root); } @@ -234,42 +241,47 @@ client_ping_cbk (struct rpc_req *req, struct iovec *iov, int count, { xlator_t *this = NULL; rpc_clnt_connection_t *conn = NULL; - struct timeval timeout = {0, }; + struct timespec timeout = {0, }; call_frame_t *frame = NULL; clnt_conf_t *conf = NULL; if (!myframe) { - gf_log ("", GF_LOG_WARNING, "frame with the request is NULL"); + gf_log (THIS->name, GF_LOG_WARNING, + "frame with the request is NULL"); goto out; } frame = myframe; this = frame->this; if (!this || !this->private) { - gf_log ("", GF_LOG_WARNING, "xlator private is not set"); + gf_log (THIS->name, GF_LOG_WARNING, + "xlator private is not set"); goto out; } conf = this->private; conn = &conf->rpc->conn; - if (req->rpc_status == -1) { - if (conn->ping_timer != NULL) { - gf_log (this->name, GF_LOG_WARNING, "socket or ib" - " related error"); - gf_timer_call_cancel (this->ctx, conn->ping_timer); - conn->ping_timer = NULL; - } else { - /* timer expired and transport bailed out */ - gf_log (this->name, GF_LOG_WARNING, "timer must have " - "expired"); - } - goto out; - } - pthread_mutex_lock (&conn->lock); { + if (req->rpc_status == -1) { + if (conn->ping_timer != NULL) { + gf_log (this->name, GF_LOG_WARNING, + "socket or ib related error"); + gf_timer_call_cancel (this->ctx, + conn->ping_timer); + conn->ping_timer = NULL; + } else { + /* timer expired and transport bailed out */ + gf_log (this->name, GF_LOG_WARNING, + "timer must have expired"); + } + + goto unlock; + } + + timeout.tv_sec = conf->opt.ping_timeout; - timeout.tv_usec = 0; + timeout.tv_nsec = 0; gf_timer_call_cancel (this->ctx, conn->ping_timer); @@ -282,6 +294,7 @@ client_ping_cbk (struct rpc_req *req, struct iovec *iov, int count, gf_log (this->name, GF_LOG_WARNING, "failed to set the ping timer"); } +unlock: pthread_mutex_unlock (&conn->lock); out: if (frame) @@ -301,7 +314,7 @@ client3_getspec_cbk (struct rpc_req *req, struct iovec *iov, int count, frame = myframe; if (!frame || !frame->this) { - gf_log ("", GF_LOG_ERROR, "frame not found with the request, " + gf_log (THIS->name, GF_LOG_ERROR, "frame not found with the request, " "returning EINVAL"); rsp.op_ret = -1; rsp.op_errno = EINVAL; @@ -315,7 +328,7 @@ client3_getspec_cbk (struct rpc_req *req, struct iovec *iov, int count, goto out; } - ret = xdr_to_getspec_rsp (*iov, &rsp); + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_getspec_rsp); if (ret < 0) { gf_log (frame->this->name, GF_LOG_ERROR, "XDR decoding failed, returning EINVAL"); @@ -331,11 +344,11 @@ client3_getspec_cbk (struct rpc_req *req, struct iovec *iov, int count, } out: - STACK_UNWIND_STRICT (getspec, frame, rsp.op_ret, rsp.op_errno, rsp.spec); + CLIENT_STACK_UNWIND (getspec, frame, rsp.op_ret, rsp.op_errno, + rsp.spec); /* Don't use 'GF_FREE', this is allocated by libc */ - if (rsp.spec) - free (rsp.spec); + free (rsp.spec); return 0; } @@ -358,16 +371,17 @@ int32_t client3_getspec (call_frame_t *frame, xlator_t *this, void *data) ret = client_submit_request (this, &req, frame, conf->handshake, GF_HNDSK_GETSPEC, client3_getspec_cbk, - NULL, xdr_from_getspec_req, NULL, 0, - NULL, 0, NULL); + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gf_getspec_req); - if (ret) - goto unwind; + if (ret) { + gf_log (this->name, GF_LOG_WARNING, + "failed to send the request"); + } return 0; unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the request"); - STACK_UNWIND_STRICT (getspec, frame, -1, op_errno, NULL); + CLIENT_STACK_UNWIND (getspec, frame, -1, op_errno, NULL); return 0; } @@ -389,24 +403,554 @@ client_notify_parents_child_up (xlator_t *this) } int -client3_1_reopen_cbk (struct rpc_req *req, struct iovec *iov, int count, +clnt_fd_lk_reacquire_failed (xlator_t *this, clnt_fd_ctx_t *fdctx, + clnt_conf_t *conf) +{ + int ret = -1; + + GF_VALIDATE_OR_GOTO ("client", this, out); + GF_VALIDATE_OR_GOTO (this->name, conf, out); + GF_VALIDATE_OR_GOTO (this->name, fdctx, out); + + pthread_mutex_lock (&conf->lock); + { + fdctx->remote_fd = -1; + fdctx->lk_heal_state = GF_LK_HEAL_DONE; + } + pthread_mutex_unlock (&conf->lock); + + ret = 0; +out: + return ret; +} + +int +client_set_lk_version_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + int32_t ret = -1; + call_frame_t *fr = NULL; + gf_set_lk_ver_rsp rsp = {0,}; + + fr = (call_frame_t *) myframe; + GF_VALIDATE_OR_GOTO ("client", fr, out); + + if (req->rpc_status == -1) { + gf_log (fr->this->name, GF_LOG_WARNING, + "received RPC status error"); + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_set_lk_ver_rsp); + if (ret < 0) + gf_log (fr->this->name, GF_LOG_WARNING, + "xdr decoding failed"); + else + gf_log (fr->this->name, GF_LOG_INFO, + "Server lk version = %d", rsp.lk_ver); + + ret = 0; +out: + if (fr) + STACK_DESTROY (fr->root); + + return ret; +} + +//TODO: Check for all released fdctx and destroy them +int +client_set_lk_version (xlator_t *this) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + call_frame_t *frame = NULL; + gf_set_lk_ver_req req = {0, }; + + GF_VALIDATE_OR_GOTO ("client", this, err); + + conf = (clnt_conf_t *) this->private; + + req.lk_ver = client_get_lk_ver (conf); + ret = gf_asprintf (&req.uid, "%s-%s-%d", + this->ctx->process_uuid, this->name, + this->graph->id); + if (ret == -1) + goto err; + + frame = create_frame (this, this->ctx->pool); + if (!frame) { + ret = -1; + goto out; + } + + gf_log (this->name, GF_LOG_DEBUG, "Sending SET_LK_VERSION"); + + ret = client_submit_request (this, &req, frame, + conf->handshake, + GF_HNDSK_SET_LK_VER, + client_set_lk_version_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gf_set_lk_ver_req); +out: + GF_FREE (req.uid); + return ret; +err: + gf_log (this->name, GF_LOG_WARNING, + "Failed to send SET_LK_VERSION to server"); + + return ret; +} + +int +client_fd_lk_count (fd_lk_ctx_t *lk_ctx) +{ + int count = 0; + fd_lk_ctx_node_t *fd_lk = NULL; + + GF_VALIDATE_OR_GOTO ("client", lk_ctx, err); + + LOCK (&lk_ctx->lock); + { + list_for_each_entry (fd_lk, &lk_ctx->lk_list, next) + count++; + } + UNLOCK (&lk_ctx->lock); + + return count; +err: + return -1; +} + +clnt_fd_lk_local_t * +clnt_fd_lk_local_ref (xlator_t *this, clnt_fd_lk_local_t *local) +{ + GF_VALIDATE_OR_GOTO (this->name, local, out); + + LOCK (&local->lock); + { + local->ref++; + } + UNLOCK (&local->lock); +out: + return local; +} + +int +clnt_fd_lk_local_unref (xlator_t *this, clnt_fd_lk_local_t *local) +{ + int ref = -1; + + GF_VALIDATE_OR_GOTO (this->name, local, out); + + LOCK (&local->lock); + { + ref = --local->ref; + } + UNLOCK (&local->lock); + + if (ref == 0) { + LOCK_DESTROY (&local->lock); + GF_FREE (local); + } +out: + return ref; +} + +clnt_fd_lk_local_t * +clnt_fd_lk_local_create (clnt_fd_ctx_t *fdctx) +{ + clnt_fd_lk_local_t *local = NULL; + + local = GF_CALLOC (1, sizeof (clnt_fd_lk_local_t), + gf_client_mt_clnt_fd_lk_local_t); + if (!local) + goto out; + + local->ref = 1; + local->error = _gf_false; + local->fdctx = fdctx; + + LOCK_INIT (&local->lock); +out: + return local; +} + +void +clnt_mark_fd_bad (clnt_conf_t *conf, clnt_fd_ctx_t *fdctx) +{ + pthread_mutex_lock (&conf->lock); + { + fdctx->remote_fd = -1; + } + pthread_mutex_unlock (&conf->lock); +} + +int +clnt_release_reopen_fd_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + xlator_t *this = NULL; + call_frame_t *frame = NULL; + clnt_conf_t *conf = NULL; + clnt_fd_ctx_t *fdctx = NULL; + + frame = myframe; + this = frame->this; + fdctx = (clnt_fd_ctx_t *) frame->local; + conf = (clnt_conf_t *) this->private; + + clnt_fd_lk_reacquire_failed (this, fdctx, conf); + + fdctx->reopen_done (fdctx, this); + + frame->local = NULL; + STACK_DESTROY (frame->root); + + return 0; +} + +int +clnt_release_reopen_fd (xlator_t *this, clnt_fd_ctx_t *fdctx) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + call_frame_t *frame = NULL; + gfs3_release_req req = {{0,},}; + + conf = (clnt_conf_t *) this->private; + + frame = create_frame (this, this->ctx->pool); + if (!frame) + goto out; + + frame->local = (void *) fdctx; + req.fd = fdctx->remote_fd; + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_RELEASE, + clnt_release_reopen_fd_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_releasedir_req); + return 0; + out: + if (ret) { + clnt_fd_lk_reacquire_failed (this, fdctx, conf); + fdctx->reopen_done (fdctx, this); + if (frame) { + frame->local = NULL; + STACK_DESTROY (frame->root); + } + } + return 0; +} + +int +clnt_reacquire_lock_error (xlator_t *this, clnt_fd_ctx_t *fdctx, + clnt_conf_t *conf) +{ + int32_t ret = -1; + + GF_VALIDATE_OR_GOTO ("client", this, out); + GF_VALIDATE_OR_GOTO (this->name, fdctx, out); + GF_VALIDATE_OR_GOTO (this->name, conf, out); + + clnt_release_reopen_fd (this, fdctx); + + ret = 0; +out: + return ret; +} + +gf_boolean_t +clnt_fd_lk_local_error_status (xlator_t *this, + clnt_fd_lk_local_t *local) +{ + gf_boolean_t error = _gf_false; + + LOCK (&local->lock); + { + error = local->error; + } + UNLOCK (&local->lock); + + return error; +} + +int +clnt_fd_lk_local_mark_error (xlator_t *this, + clnt_fd_lk_local_t *local) +{ + int32_t ret = -1; + clnt_conf_t *conf = NULL; + gf_boolean_t error = _gf_false; + + GF_VALIDATE_OR_GOTO ("client", this, out); + GF_VALIDATE_OR_GOTO (this->name, local, out); + + conf = (clnt_conf_t *) this->private; + + LOCK (&local->lock); + { + error = local->error; + local->error = _gf_true; + } + UNLOCK (&local->lock); + + if (!error) + clnt_reacquire_lock_error (this, local->fdctx, conf); + ret = 0; +out: + return ret; +} + +int +client_reacquire_lock_cbk (struct rpc_req *req, struct iovec *iov, + int count, void *myframe) +{ + int32_t ret = -1; + xlator_t *this = NULL; + gfs3_lk_rsp rsp = {0,}; + call_frame_t *frame = NULL; + clnt_conf_t *conf = NULL; + clnt_fd_ctx_t *fdctx = NULL; + clnt_fd_lk_local_t *local = NULL; + struct gf_flock lock = {0,}; + + frame = (call_frame_t *) myframe; + this = frame->this; + local = (clnt_fd_lk_local_t *) frame->local; + conf = (clnt_conf_t *) this->private; + + if (req->rpc_status == -1) { + gf_log ("client", GF_LOG_WARNING, + "request failed at rpc"); + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_lk_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + goto out; + } + + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_ERROR, "lock request failed"); + ret = -1; + goto out; + } + + fdctx = local->fdctx; + + gf_proto_flock_to_flock (&rsp.flock, &lock); + + gf_log (this->name, GF_LOG_DEBUG, "%s type lock reacquired on file " + "with gfid %s from %"PRIu64 " to %"PRIu64, + get_lk_type (lock.l_type), uuid_utoa (fdctx->gfid), + lock.l_start, lock.l_start + lock.l_len); + + if (!clnt_fd_lk_local_error_status (this, local) && + clnt_fd_lk_local_unref (this, local) == 0) { + pthread_mutex_lock (&conf->lock); + { + fdctx->lk_heal_state = GF_LK_HEAL_DONE; + } + pthread_mutex_unlock (&conf->lock); + + fdctx->reopen_done (fdctx, this); + } + + ret = 0; +out: + if (ret < 0) { + clnt_fd_lk_local_mark_error (this, local); + + clnt_fd_lk_local_unref (this, local); + } + + frame->local = NULL; + STACK_DESTROY (frame->root); + + return ret; +} + +int +_client_reacquire_lock (xlator_t *this, clnt_fd_ctx_t *fdctx) +{ + int32_t ret = -1; + int32_t gf_cmd = 0; + int32_t gf_type = 0; + gfs3_lk_req req = {{0,},}; + struct gf_flock flock = {0,}; + fd_lk_ctx_t *lk_ctx = NULL; + clnt_fd_lk_local_t *local = NULL; + fd_lk_ctx_node_t *fd_lk = NULL; + call_frame_t *frame = NULL; + clnt_conf_t *conf = NULL; + + conf = (clnt_conf_t *) this->private; + lk_ctx = fdctx->lk_ctx; + + local = clnt_fd_lk_local_create (fdctx); + if (!local) { + gf_log (this->name, GF_LOG_WARNING, "clnt_fd_lk_local_create " + "failed, aborting reacquring of locks on %s.", + uuid_utoa (fdctx->gfid)); + clnt_reacquire_lock_error (this, fdctx, conf); + goto out; + } + + list_for_each_entry (fd_lk, &lk_ctx->lk_list, next) { + memcpy (&flock, &fd_lk->user_flock, + sizeof (struct gf_flock)); + + /* Always send F_SETLK even if the cmd was F_SETLKW */ + /* to avoid frame being blocked if lock cannot be granted. */ + ret = client_cmd_to_gf_cmd (F_SETLK, &gf_cmd); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, + "client_cmd_to_gf_cmd failed, " + "aborting reacquiring of locks"); + break; + } + + gf_type = client_type_to_gf_type (flock.l_type); + req.fd = fdctx->remote_fd; + req.cmd = gf_cmd; + req.type = gf_type; + (void) gf_proto_flock_from_flock (&req.flock, + &flock); + + memcpy (req.gfid, fdctx->gfid, 16); + + frame = create_frame (this, this->ctx->pool); + if (!frame) { + ret = -1; + break; + } + + frame->local = clnt_fd_lk_local_ref (this, local); + frame->root->lk_owner = fd_lk->user_flock.l_owner; + + ret = client_submit_request (this, &req, frame, + conf->fops, GFS3_OP_LK, + client_reacquire_lock_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_lk_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, + "reacquiring locks failed on file with gfid %s", + uuid_utoa (fdctx->gfid)); + break; + } + + ret = 0; + frame = NULL; + } + + if (local) + (void) clnt_fd_lk_local_unref (this, local); +out: + return ret; +} + +int +client_reacquire_lock (xlator_t *this, clnt_fd_ctx_t *fdctx) +{ + int32_t ret = -1; + fd_lk_ctx_t *lk_ctx = NULL; + + GF_VALIDATE_OR_GOTO ("client", this, out); + GF_VALIDATE_OR_GOTO (this->name, fdctx, out); + + if (client_fd_lk_list_empty (fdctx->lk_ctx, _gf_false)) { + gf_log (this->name, GF_LOG_DEBUG, + "fd lock list is empty"); + fdctx->reopen_done (fdctx, this); + } else { + lk_ctx = fdctx->lk_ctx; + + LOCK (&lk_ctx->lock); + { + (void) _client_reacquire_lock (this, fdctx); + } + UNLOCK (&lk_ctx->lock); + } + ret = 0; +out: + return ret; +} + +void +client_default_reopen_done (clnt_fd_ctx_t *fdctx, xlator_t *this) +{ + gf_log_callingfn (this->name, GF_LOG_WARNING, + "This function should never be called"); +} + +void +client_reopen_done (clnt_fd_ctx_t *fdctx, xlator_t *this) +{ + clnt_conf_t *conf = NULL; + gf_boolean_t destroy = _gf_false; + + conf = this->private; + + pthread_mutex_lock (&conf->lock); + { + fdctx->reopen_attempts = 0; + if (!fdctx->released) + list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); + else + destroy = _gf_true; + fdctx->reopen_done = client_default_reopen_done; + } + pthread_mutex_unlock (&conf->lock); + + if (destroy) + client_fdctx_destroy (this, fdctx); +} + +void +client_child_up_reopen_done (clnt_fd_ctx_t *fdctx, xlator_t *this) +{ + clnt_conf_t *conf = NULL; + uint64_t fd_count = 0; + + conf = this->private; + + LOCK (&conf->rec_lock); + { + fd_count = --(conf->reopen_fd_count); + } + UNLOCK (&conf->rec_lock); + + client_reopen_done (fdctx, this); + if (fd_count == 0) { + gf_log (this->name, GF_LOG_INFO, + "last fd open'd/lock-self-heal'd - notifying CHILD-UP"); + client_set_lk_version (this); + client_notify_parents_child_up (this); + } +} + +int +client3_3_reopen_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe) { int32_t ret = -1; gfs3_open_rsp rsp = {0,}; - int attempt_lock_recovery = _gf_false; - uint64_t fd_count = 0; + gf_boolean_t attempt_lock_recovery = _gf_false; clnt_local_t *local = NULL; clnt_conf_t *conf = NULL; clnt_fd_ctx_t *fdctx = NULL; call_frame_t *frame = NULL; + xlator_t *this = NULL; frame = myframe; - if (!frame || !frame->this) - goto out; - + this = frame->this; + conf = this->private; local = frame->local; - conf = frame->this->private; + fdctx = local->fdctx; if (-1 == req->rpc_status) { gf_log (frame->this->name, GF_LOG_WARNING, @@ -416,7 +960,7 @@ client3_1_reopen_cbk (struct rpc_req *req, struct iovec *iov, int count, goto out; } - ret = xdr_to_open_rsp (*iov, &rsp); + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_open_rsp); if (ret < 0) { gf_log (frame->this->name, GF_LOG_ERROR, "XDR decoding failed"); rsp.op_ret = -1; @@ -439,50 +983,38 @@ client3_1_reopen_cbk (struct rpc_req *req, struct iovec *iov, int count, goto out; } - fdctx = local->fdctx; - - if (!fdctx) { - gf_log (frame->this->name, GF_LOG_WARNING, "fdctx not found"); - ret = -1; - goto out; - } - pthread_mutex_lock (&conf->lock); { fdctx->remote_fd = rsp.fd; if (!fdctx->released) { - list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); - if (!list_empty (&fdctx->lock_list)) + if (conf->lk_heal && + !client_fd_lk_list_empty (fdctx->lk_ctx, + _gf_false)) { attempt_lock_recovery = _gf_true; - fdctx = NULL; + fdctx->lk_heal_state = GF_LK_HEAL_IN_PROGRESS; + } } } pthread_mutex_unlock (&conf->lock); ret = 0; - attempt_lock_recovery = _gf_false; /* temporarily */ - if (attempt_lock_recovery) { - ret = client_attempt_lock_recovery (frame->this, local->fdctx); - if (ret < 0) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "lock recovery not attempted on fd"); - } else { - gf_log (frame->this->name, GF_LOG_INFO, - "need to attempt lock recovery on %"PRIu64 - " open fds", fd_count); + /* Delay decrementing the reopen fd count untill all the + locks corresponding to this fd are acquired.*/ + gf_log (this->name, GF_LOG_DEBUG, "acquiring locks " + "on %s", local->loc.path); + ret = client_reacquire_lock (frame->this, local->fdctx); + if (ret) { + clnt_reacquire_lock_error (this, local->fdctx, conf); + gf_log (this->name, GF_LOG_WARNING, "acquiring locks " + "failed on %s", local->loc.path); } - } else { - fd_count = decrement_reopen_fd_count (frame->this, conf); } -out: - if (fdctx) - client_fdctx_destroy (frame->this, fdctx); - - if ((ret < 0) && frame && frame->this && conf) - decrement_reopen_fd_count (frame->this, conf); +out: + if (!attempt_lock_recovery) + fdctx->reopen_done (fdctx, this); frame->local = NULL; STACK_DESTROY (frame->root); @@ -493,7 +1025,7 @@ out: } int -client3_1_reopendir_cbk (struct rpc_req *req, struct iovec *iov, int count, +client3_3_reopendir_cbk (struct rpc_req *req, struct iovec *iov, int count, void *myframe) { int32_t ret = -1; @@ -504,11 +1036,10 @@ client3_1_reopendir_cbk (struct rpc_req *req, struct iovec *iov, int count, call_frame_t *frame = NULL; frame = myframe; - if (!frame || !frame->this) - goto out; + local = frame->local; + fdctx = local->fdctx; + conf = frame->this->private; - local = frame->local; - conf = frame->this->private; if (-1 == req->rpc_status) { gf_log (frame->this->name, GF_LOG_WARNING, @@ -518,7 +1049,7 @@ client3_1_reopendir_cbk (struct rpc_req *req, struct iovec *iov, int count, goto out; } - ret = xdr_to_opendir_rsp (*iov, &rsp); + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_opendir_rsp); if (ret < 0) { gf_log (frame->this->name, GF_LOG_ERROR, "XDR decoding failed"); rsp.op_ret = -1; @@ -541,78 +1072,44 @@ client3_1_reopendir_cbk (struct rpc_req *req, struct iovec *iov, int count, goto out; } - fdctx = local->fdctx; - if (!fdctx) { - gf_log (frame->this->name, GF_LOG_WARNING, "fdctx not found"); - ret = -1; - goto out; - } - 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); - decrement_reopen_fd_count (frame->this, conf); - ret = 0; - out: - if (fdctx) - client_fdctx_destroy (frame->this, fdctx); - - if ((ret < 0) && frame && frame->this && conf) - decrement_reopen_fd_count (frame->this, conf); - - if (frame) { - frame->local = NULL; - STACK_DESTROY (frame->root); - } + fdctx->reopen_done (fdctx, frame->this); + 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) +static int +protocol_client_reopendir (clnt_fd_ctx_t *fdctx, xlator_t *this) { 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) { - gf_log (this->name, GF_LOG_WARNING, - "couldn't build path from inode %s", - uuid_utoa (inode->gfid)); - goto out; - } - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); + local = mem_get0 (this->local_pool); if (!local) { ret = -1; goto out; } - local->fdctx = fdctx; - local->loc.path = path; - path = NULL; + + uuid_copy (local->loc.gfid, fdctx->gfid); + ret = loc_path (&local->loc, NULL); + if (ret < 0) + goto out; frame = create_frame (this, this->ctx->pool); if (!frame) { @@ -620,27 +1117,26 @@ protocol_client_reopendir (xlator_t *this, clnt_fd_ctx_t *fdctx) goto out; } - memcpy (req.gfid, inode->gfid, 16); - req.path = (char *)local->loc.path; + memcpy (req.gfid, fdctx->gfid, 16); gf_log (frame->this->name, GF_LOG_DEBUG, "attempting reopen on %s", local->loc.path); - frame->local = local; local = NULL; + frame->local = local; ret = client_submit_request (this, &req, frame, conf->fops, GFS3_OP_OPENDIR, - client3_1_reopendir_cbk, NULL, - xdr_from_opendir_req, NULL, 0, NULL, 0, - NULL); - if (ret) - goto out; + client3_3_reopendir_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_opendir_req); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "failed to send the re-opendir request"); + } - return ret; + return 0; out: - gf_log ("", GF_LOG_ERROR, "failed to send the re-opendir request"); - if (frame) { frame->local = NULL; STACK_DESTROY (frame->root); @@ -649,78 +1145,62 @@ out: if (local) client_local_wipe (local); - if (path) - GF_FREE (path); - if ((ret < 0) && this && conf) { - decrement_reopen_fd_count (this, conf); - } + fdctx->reopen_done (fdctx, this); return 0; } -int -protocol_client_reopen (xlator_t *this, clnt_fd_ctx_t *fdctx) +static int +protocol_client_reopenfile (clnt_fd_ctx_t *fdctx, xlator_t *this) { 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) { - gf_log (this->name, GF_LOG_WARNING, - "couldn't build path from inode %s", - uuid_utoa (inode->gfid)); - goto out; - } - frame = create_frame (this, this->ctx->pool); if (!frame) { ret = -1; goto out; } - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); + local = mem_get0 (this->local_pool); if (!local) { ret = -1; goto out; } local->fdctx = fdctx; - local->loc.path = path; - path = NULL; + uuid_copy (local->loc.gfid, fdctx->gfid); + ret = loc_path (&local->loc, NULL); + if (ret < 0) + goto out; + frame->local = local; - memcpy (req.gfid, inode->gfid, 16); + memcpy (req.gfid, fdctx->gfid, 16); req.flags = gf_flags_from_flags (fdctx->flags); - req.wbflags = fdctx->wbflags; - req.path = (char *)local->loc.path; + req.flags = req.flags & (~(O_TRUNC|O_CREAT|O_EXCL)); gf_log (frame->this->name, GF_LOG_DEBUG, "attempting reopen on %s", local->loc.path); - local = NULL; ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_OPEN, client3_1_reopen_cbk, NULL, - xdr_from_open_req, NULL, 0, NULL, 0, NULL); - if (ret) - goto out; + GFS3_OP_OPEN, client3_3_reopen_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_open_req); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "failed to send the re-open request"); + } - return ret; + return 0; out: - gf_log ("", GF_LOG_ERROR, "failed to send the re-open request"); - if (frame) { frame->local = NULL; STACK_DESTROY (frame->root); @@ -729,17 +1209,65 @@ out: if (local) client_local_wipe (local); - if (path) - GF_FREE (path); - - if ((ret < 0) && this && conf) { - decrement_reopen_fd_count (this, conf); - } + fdctx->reopen_done (fdctx, this); return 0; } +static void +protocol_client_reopen (clnt_fd_ctx_t *fdctx, xlator_t *this) +{ + if (fdctx->is_dir) + protocol_client_reopendir (fdctx, this); + else + protocol_client_reopenfile (fdctx, this); +} + +gf_boolean_t +__is_fd_reopen_in_progress (clnt_fd_ctx_t *fdctx) +{ + if (fdctx->reopen_done == client_default_reopen_done) + return _gf_false; + return _gf_true; +} + +void +client_attempt_reopen (fd_t *fd, xlator_t *this) +{ + clnt_conf_t *conf = NULL; + clnt_fd_ctx_t *fdctx = NULL; + gf_boolean_t reopen = _gf_false; + + if (!fd || !this) + goto out; + + conf = this->private; + pthread_mutex_lock (&conf->lock); + { + fdctx = this_fd_get_ctx (fd, this); + if (!fdctx) + goto unlock; + if (__is_fd_reopen_in_progress (fdctx)) + goto unlock; + if (fdctx->remote_fd != -1) + goto unlock; + + if (fdctx->reopen_attempts == CLIENT_REOPEN_MAX_ATTEMPTS) { + reopen = _gf_true; + fdctx->reopen_done = client_reopen_done; + list_del_init (&fdctx->sfd_pos); + } else { + fdctx->reopen_attempts++; + } + } +unlock: + pthread_mutex_unlock (&conf->lock); + if (reopen) + protocol_client_reopen (fdctx, this); +out: + return; +} int client_post_handshake (call_frame_t *frame, xlator_t *this) @@ -764,6 +1292,7 @@ client_post_handshake (call_frame_t *frame, xlator_t *this) if (fdctx->remote_fd != -1) continue; + fdctx->reopen_done = client_child_up_reopen_done; list_del_init (&fdctx->sfd_pos); list_add_tail (&fdctx->sfd_pos, &reopen_head); count++; @@ -782,14 +1311,12 @@ client_post_handshake (call_frame_t *frame, xlator_t *this) 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); + protocol_client_reopen (fdctx, this); } } else { gf_log (this->name, GF_LOG_DEBUG, - "no open fds - notifying all parents child up"); + "No fds to open - notifying all parents child up"); + client_set_lk_version (this); client_notify_parents_child_up (this); } out: @@ -809,7 +1336,9 @@ client_setvolume_cbk (struct rpc_req *req, struct iovec *iov, int count, void *m gf_setvolume_rsp rsp = {0,}; int ret = 0; int32_t op_ret = 0; - int32_t op_errno = 0; + int32_t op_errno = 0; + gf_boolean_t auth_fail = _gf_false; + uint32_t lk_ver = 0; frame = myframe; this = frame->this; @@ -822,7 +1351,7 @@ client_setvolume_cbk (struct rpc_req *req, struct iovec *iov, int count, void *m goto out; } - ret = xdr_to_setvolume_rsp (*iov, &rsp); + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_setvolume_rsp); if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); op_ret = -1; @@ -867,6 +1396,11 @@ client_setvolume_cbk (struct rpc_req *req, struct iovec *iov, int count, void *m "SETVOLUME on remote-host failed: %s", remote_error ? remote_error : strerror (op_errno)); errno = op_errno; + if (remote_error && + (strcmp ("Authentication failed", remote_error) == 0)) { + auth_fail = _gf_true; + op_ret = 0; + } if (op_errno == ESTALE) { ret = default_notify (this, GF_EVENT_VOLFILE_MODIFIED, NULL); if (ret) @@ -885,6 +1419,15 @@ client_setvolume_cbk (struct rpc_req *req, struct iovec *iov, int count, void *m goto out; } + ret = dict_get_uint32 (reply, "clnt-lk-version", &lk_ver); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, + "failed to find key 'clnt-lk-version' in the options"); + goto out; + } + + gf_log (this->name, GF_LOG_DEBUG, "clnt-lk-version = %d, " + "server-lk-version = %d", client_get_lk_ver (conf), lk_ver); /* TODO: currently setpeer path is broken */ /* if (process_uuid && req->conn && @@ -918,11 +1461,34 @@ client_setvolume_cbk (struct rpc_req *req, struct iovec *iov, int count, void *m conf->connecting = 0; conf->connected = 1; - /* TODO: more to test */ - client_post_handshake (frame, frame->this); + conf->need_different_port = 0; -out: + if (lk_ver != client_get_lk_ver (conf)) { + gf_log (this->name, GF_LOG_INFO, "Server and Client " + "lk-version numbers are not same, reopening the fds"); + client_mark_fd_bad (this); + client_post_handshake (frame, frame->this); + } else { + /*TODO: Traverse the saved fd list, and send + release to the server on fd's that were closed + during grace period */ + gf_log (this->name, GF_LOG_INFO, "Server and Client " + "lk-version numbers are same, no need to " + "reopen the fds"); + } +out: + if (auth_fail) { + gf_log (this->name, GF_LOG_INFO, "sending AUTH_FAILED event"); + ret = default_notify (this, GF_EVENT_AUTH_FAILED, NULL); + if (ret) + gf_log (this->name, GF_LOG_INFO, + "notify of AUTH_FAILED failed"); + conf->connecting = 0; + conf->connected = 0; + conf->last_sent_event = GF_EVENT_AUTH_FAILED; + ret = -1; + } if (-1 == op_ret) { /* Let the connection/re-connection happen in * background, for now, don't hang here, @@ -935,17 +1501,17 @@ out: "notify of CHILD_CONNECTING failed"); conf->last_sent_event = GF_EVENT_CHILD_CONNECTING; conf->connecting= 1; + ret = 0; } - if (rsp.dict.dict_val) - free (rsp.dict.dict_val); + free (rsp.dict.dict_val); STACK_DESTROY (frame->root); if (reply) dict_unref (reply); - return 0; + return ret; } int @@ -958,9 +1524,6 @@ client_setvolume (xlator_t *this, struct rpc_clnt *rpc) clnt_conf_t *conf = NULL; dict_t *options = NULL; - struct rpc_clnt_config config = {0, }; - - options = this->options; conf = this->private; @@ -985,13 +1548,19 @@ client_setvolume (xlator_t *this, struct rpc_clnt *rpc) } } - ret = gf_asprintf (&process_uuid_xl, "%s-%s", this->ctx->process_uuid, - this->name); + /* With multiple graphs possible in the same process, we need a + field to bring the uniqueness. Graph-ID should be enough to get the + job done + */ + ret = gf_asprintf (&process_uuid_xl, "%s-%s-%d", + this->ctx->process_uuid, this->name, + this->graph->id); 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, @@ -1000,6 +1569,13 @@ client_setvolume (xlator_t *this, struct rpc_clnt *rpc) goto fail; } + ret = dict_set_str (options, "client-version", PACKAGE_VERSION); + if (ret < 0) { + gf_log (this->name, GF_LOG_WARNING, + "failed to set client-version(%s) in handshake msg", + PACKAGE_VERSION); + } + if (this->ctx->cmd_args.volfile_server) { if (this->ctx->cmd_args.volfile_id) { ret = dict_set_str (options, "volfile-key", @@ -1015,13 +1591,22 @@ client_setvolume (xlator_t *this, struct rpc_clnt *rpc) "failed to set 'volfile-checksum'"); } - req.dict.dict_len = dict_serialized_length (options); - if (req.dict.dict_len < 0) { + ret = dict_set_int16 (options, "clnt-lk-version", + client_get_lk_ver (conf)); + if (ret < 0) { + gf_log (this->name, GF_LOG_WARNING, + "failed to set clnt-lk-version(%"PRIu32") in handshake msg", + client_get_lk_ver (conf)); + } + + ret = dict_serialized_length (options); + if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, "failed to get serialized length of dict"); ret = -1; goto fail; } + req.dict.dict_len = ret; req.dict.dict_val = GF_CALLOC (1, req.dict.dict_len, gf_client_mt_clnt_req_buf_t); ret = dict_serialize (options, req.dict.dict_val); @@ -1037,18 +1622,11 @@ client_setvolume (xlator_t *this, struct rpc_clnt *rpc) ret = client_submit_request (this, &req, fr, conf->handshake, GF_HNDSK_SETVOLUME, client_setvolume_cbk, - NULL, xdr_from_setvolume_req, NULL, 0, - NULL, 0, NULL); + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gf_setvolume_req); fail: - - if (ret) { - config.remote_port = -1; - rpc_clnt_reconfig (conf->rpc, &config); - } - - if (req.dict.dict_val) - GF_FREE (req.dict.dict_val); + GF_FREE (req.dict.dict_val); return ret; } @@ -1061,7 +1639,7 @@ select_server_supported_programs (xlator_t *this, gf_prog_detail *prog) int ret = -1; if (!this || !prog) { - gf_log ("", GF_LOG_WARNING, + gf_log (THIS->name, GF_LOG_WARNING, "xlator not found OR RPC program not found"); goto out; } @@ -1071,9 +1649,9 @@ select_server_supported_programs (xlator_t *this, gf_prog_detail *prog) while (trav) { /* Select 'programs' */ - if ((clnt3_1_fop_prog.prognum == trav->prognum) && - (clnt3_1_fop_prog.progver == trav->progver)) { - conf->fops = &clnt3_1_fop_prog; + if ((clnt3_3_fop_prog.prognum == trav->prognum) && + (clnt3_3_fop_prog.progver == trav->progver)) { + conf->fops = &clnt3_3_fop_prog; gf_log (this->name, GF_LOG_INFO, "Using Program %s, Num (%"PRId64"), " "Version (%"PRId64")", @@ -1100,7 +1678,7 @@ server_has_portmap (xlator_t *this, gf_prog_detail *prog) int ret = -1; if (!this || !prog) { - gf_log ("", GF_LOG_WARNING, + gf_log (THIS->name, GF_LOG_WARNING, "xlator not found OR RPC program not found"); goto out; } @@ -1135,7 +1713,7 @@ client_query_portmap_cbk (struct rpc_req *req, struct iovec *iov, int count, voi frame = myframe; if (!frame || !frame->this || !frame->this->private) { - gf_log ("", GF_LOG_WARNING, + gf_log (THIS->name, GF_LOG_WARNING, "frame not found with rpc request"); goto out; } @@ -1148,7 +1726,7 @@ client_query_portmap_cbk (struct rpc_req *req, struct iovec *iov, int count, voi goto out; } - ret = xdr_to_pmap_port_by_brick_rsp (*iov, &rsp); + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_pmap_port_by_brick_rsp); if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); goto out; @@ -1158,16 +1736,21 @@ client_query_portmap_cbk (struct rpc_req *req, struct iovec *iov, int count, voi ret = -1; gf_log (this->name, ((!conf->portmap_err_logged) ? GF_LOG_ERROR : GF_LOG_DEBUG), - "failed to get the port number for remote subvolume"); + "failed to get the port number for remote subvolume. " + "Please run 'gluster volume status' on server to see " + "if brick process is running."); conf->portmap_err_logged = 1; goto out; } conf->portmap_err_logged = 0; + conf->disconnect_err_logged = 0; config.remote_port = rsp.port; rpc_clnt_reconfig (conf->rpc, &config); + conf->skip_notify = 1; + conf->quick_reconnect = 1; out: if (frame) @@ -1177,7 +1760,6 @@ out: /* Need this to connect the same transport on different port */ /* ie, glusterd to glusterfsd */ rpc_transport_disconnect (conf->rpc->conn.trans); - rpc_clnt_reconnect (conf->rpc->conn.trans); } return ret; @@ -1193,6 +1775,8 @@ client_query_portmap (xlator_t *this, struct rpc_clnt *rpc) clnt_conf_t *conf = NULL; dict_t *options = NULL; char *remote_subvol = NULL; + char *xprt = NULL; + char brick_name[PATH_MAX] = {0,}; options = this->options; conf = this->private; @@ -1206,6 +1790,25 @@ client_query_portmap (xlator_t *this, struct rpc_clnt *rpc) req.brick = remote_subvol; + /* FIXME: Dirty work around */ + if (!dict_get_str (options, "transport-type", &xprt)) { + /* This logic is required only in case of 'rdma' client + transport-type and the volume is of 'tcp,rdma' + transport type. */ + if (!strcmp (xprt, "rdma")) { + if (!conf->need_different_port) { + snprintf (brick_name, PATH_MAX, "%s.rdma", + remote_subvol); + req.brick = brick_name; + conf->need_different_port = 1; + conf->skip_notify = 1; + } else { + conf->need_different_port = 0; + conf->skip_notify = 0; + } + } + } + fr = create_frame (this, this->ctx->pool); if (!fr) { ret = -1; @@ -1215,8 +1818,8 @@ client_query_portmap (xlator_t *this, struct rpc_clnt *rpc) ret = client_submit_request (this, &req, fr, &clnt_pmap_prog, GF_PMAP_PORTBYBRICK, client_query_portmap_cbk, - NULL, xdr_from_pmap_port_by_brick_req, - NULL, 0, NULL, 0, NULL); + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_pmap_port_by_brick_req); fail: return ret; @@ -1243,7 +1846,7 @@ client_dump_version_cbk (struct rpc_req *req, struct iovec *iov, int count, goto out; } - ret = xdr_to_dump_rsp (*iov, &rsp); + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_dump_rsp); if (ret < 0) { gf_log (frame->this->name, GF_LOG_ERROR, "XDR decoding failed"); goto out; @@ -1311,8 +1914,8 @@ client_handshake (xlator_t *this, struct rpc_clnt *rpc) req.gfs_id = 0xbabe; ret = client_submit_request (this, &req, frame, conf->dump, GF_DUMP_DUMP, client_dump_version_cbk, - NULL, xdr_from_dump_req, NULL, 0, NULL, 0, - NULL); + NULL, NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gf_dump_req); out: return ret; @@ -1323,6 +1926,7 @@ char *clnt_handshake_procs[GF_HNDSK_MAXVALUE] = { [GF_HNDSK_SETVOLUME] = "SETVOLUME", [GF_HNDSK_GETSPEC] = "GETSPEC", [GF_HNDSK_PING] = "PING", + [GF_HNDSK_SET_LK_VER] = "SET_LK_VER" }; rpc_clnt_prog_t clnt_handshake_prog = { diff --git a/xlators/protocol/client/src/client-helpers.c b/xlators/protocol/client/src/client-helpers.c index 85a9f89ed..5d9f00fdc 100644 --- a/xlators/protocol/client/src/client-helpers.c +++ b/xlators/protocol/client/src/client-helpers.c @@ -1,20 +1,11 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.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 Affero 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 - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. */ #ifndef _CONFIG_H @@ -25,6 +16,31 @@ #include "client.h" #include "fd.h" +int +client_fd_lk_list_empty (fd_lk_ctx_t *lk_ctx, gf_boolean_t try_lock) +{ + int ret = 1; + + if (!lk_ctx) { + ret = -1; + goto out; + } + + if (try_lock) { + ret = TRY_LOCK (&lk_ctx->lock); + if (ret != 0) { + ret = -1; + goto out; + } + } else { + LOCK (&lk_ctx->lock); + } + + ret = list_empty (&lk_ctx->lk_list); + UNLOCK (&lk_ctx->lock); +out: + return ret; +} clnt_fd_ctx_t * this_fd_del_ctx (fd_t *file, xlator_t *this) @@ -79,8 +95,8 @@ this_fd_set_ctx (fd_t *file, xlator_t *this, loc_t *loc, clnt_fd_ctx_t *ctx) if (ret >= 0) { if (loc) gf_log (this->name, GF_LOG_INFO, - "%s (%"PRId64"): trying duplicate remote fd set. ", - loc->path, loc->inode->ino); + "%s (%s): trying duplicate remote fd set. ", + loc->path, uuid_utoa (loc->inode->gfid)); else gf_log (this->name, GF_LOG_INFO, "%p: trying duplicate remote fd set. ", file); @@ -90,8 +106,8 @@ this_fd_set_ctx (fd_t *file, xlator_t *this, loc_t *loc, clnt_fd_ctx_t *ctx) if (ret < 0) { if (loc) gf_log (this->name, GF_LOG_WARNING, - "%s (%"PRId64"): failed to set remote fd", - loc->path, loc->inode->ino); + "%s (%s): failed to set remote fd", + loc->path, uuid_utoa (loc->inode->gfid)); else gf_log (this->name, GF_LOG_WARNING, "%p: failed to set remote fd", file); @@ -106,6 +122,7 @@ client_local_wipe (clnt_local_t *local) { if (local) { loc_wipe (&local->loc); + loc_wipe (&local->loc2); if (local->fd) { fd_unref (local->fd); @@ -115,7 +132,9 @@ client_local_wipe (clnt_local_t *local) iobref_unref (local->iobref); } - GF_FREE (local); + GF_FREE (local->name); + + mem_put (local); } return 0; @@ -154,15 +173,21 @@ out: } int -unserialize_rsp_direntp (struct gfs3_readdirp_rsp *rsp, gf_dirent_t *entries) +unserialize_rsp_direntp (xlator_t *this, fd_t *fd, + struct gfs3_readdirp_rsp *rsp, gf_dirent_t *entries) { struct gfs3_dirplist *trav = NULL; + char *buf = NULL; gf_dirent_t *entry = NULL; + inode_table_t *itable = NULL; int entry_len = 0; int ret = -1; trav = rsp->reply; + if (fd) + itable = fd->inode->table; + while (trav) { entry_len = gf_dirent_size (trav->name); entry = GF_CALLOC (1, entry_len, gf_common_mt_gf_dirent_t); @@ -178,6 +203,30 @@ unserialize_rsp_direntp (struct gfs3_readdirp_rsp *rsp, gf_dirent_t *entries) strcpy (entry->d_name, trav->name); + if (trav->dict.dict_val) { + /* Dictionary is sent along with response */ + buf = memdup (trav->dict.dict_val, trav->dict.dict_len); + if (!buf) + goto out; + + entry->dict = dict_new (); + + ret = dict_unserialize (buf, trav->dict.dict_len, + &entry->dict); + if (ret < 0) { + gf_log (THIS->name, GF_LOG_WARNING, + "failed to unserialize xattr dict"); + errno = EINVAL; + goto out; + } + entry->dict->extra_free = buf; + buf = NULL; + } + + entry->inode = inode_find (itable, entry->d_stat.ia_gfid); + if (!entry->inode) + entry->inode = inode_new (itable); + list_add_tail (&entry->list, &entries->list); trav = trav->nextentry; @@ -199,6 +248,7 @@ clnt_readdirp_rsp_cleanup (gfs3_readdirp_rsp *rsp) while (trav) { trav = trav->nextentry; /* on client, the rpc lib allocates this */ + free (prev->dict.dict_val); free (prev->name); free (prev); prev = trav; @@ -225,3 +275,75 @@ clnt_readdir_rsp_cleanup (gfs3_readdir_rsp *rsp) return 0; } + +int +client_get_remote_fd (xlator_t *this, fd_t *fd, int flags, int64_t *remote_fd) +{ + clnt_fd_ctx_t *fdctx = NULL; + clnt_conf_t *conf = NULL; + + GF_VALIDATE_OR_GOTO (this->name, fd, out); + GF_VALIDATE_OR_GOTO (this->name, remote_fd, out); + + conf = this->private; + pthread_mutex_lock (&conf->lock); + { + fdctx = this_fd_get_ctx (fd, this); + if (!fdctx) + *remote_fd = GF_ANON_FD_NO; + else if (__is_fd_reopen_in_progress (fdctx)) + *remote_fd = -1; + else + *remote_fd = fdctx->remote_fd; + } + pthread_mutex_unlock (&conf->lock); + + if ((flags & FALLBACK_TO_ANON_FD) && (*remote_fd == -1)) + *remote_fd = GF_ANON_FD_NO; + + return 0; +out: + return -1; +} + +gf_boolean_t +client_is_reopen_needed (fd_t *fd, xlator_t *this, int64_t remote_fd) +{ + clnt_fd_ctx_t *fdctx = NULL; + + fdctx = this_fd_get_ctx (fd, this); + if (fdctx && (fdctx->remote_fd == -1) && + (remote_fd == GF_ANON_FD_NO)) + return _gf_true; + return _gf_false; +} + +int +client_fd_fop_prepare_local (call_frame_t *frame, fd_t *fd, int64_t remote_fd) +{ + xlator_t *this = NULL; + clnt_conf_t *conf = NULL; + clnt_local_t *local = NULL; + int ret = 0; + + this = frame->this; + conf = this->private; + + if (!frame || !fd) { + ret = -EINVAL; + goto out; + } + + frame->local = mem_get0 (this->local_pool); + if (frame->local == NULL) { + ret = -ENOMEM; + goto out; + } + + local = frame->local; + local->fd = fd_ref (fd); + local->attempt_reopen = client_is_reopen_needed (fd, this, remote_fd); + return 0; +out: + return ret; +} diff --git a/xlators/protocol/client/src/client-lk.c b/xlators/protocol/client/src/client-lk.c index 068d44609..1fd8f0d50 100644 --- a/xlators/protocol/client/src/client-lk.c +++ b/xlators/protocol/client/src/client-lk.c @@ -1,32 +1,21 @@ /* - Copyright (c) 2008-2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.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 Affero 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 - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. */ #include "common-utils.h" #include "xlator.h" #include "client.h" +#include "lkowner.h" static void __insert_and_merge (clnt_fd_ctx_t *fdctx, client_posix_lock_t *lock); -static int -client_send_recovery_lock (call_frame_t *frame, xlator_t *this, - client_posix_lock_t *lock); static void __dump_client_lock (client_posix_lock_t *lock) { @@ -36,11 +25,11 @@ __dump_client_lock (client_posix_lock_t *lock) gf_log (this->name, GF_LOG_INFO, "{fd=%p}" - "{%s lk-owner:%"PRIu64" %"PRId64" - %"PRId64"}" + "{%s lk-owner:%s %"PRId64" - %"PRId64"}" "{start=%"PRId64" end=%"PRId64"}", lock->fd, lock->fl_type == F_WRLCK ? "Write-Lock" : "Read-Lock", - lock->owner, + lkowner_utoa (&lock->owner), lock->user_flock.l_start, lock->user_flock.l_len, lock->fl_start, @@ -133,12 +122,6 @@ add_locks (client_posix_lock_t *l1, client_posix_lock_t *l2) return sum; } -/* Return true if the locks have the same owner */ -static int -same_owner (client_posix_lock_t *l1, client_posix_lock_t *l2) -{ - return ((l1->owner == l2->owner)); -} /* Return true if the locks overlap, false otherwise */ static int @@ -285,11 +268,11 @@ __insert_and_merge (clnt_fd_ctx_t *fdctx, client_posix_lock_t *lock) if (!locks_overlap (conf, lock)) continue; - if (same_owner (conf, lock)) { + if (is_same_lkowner (&conf->owner, &lock->owner)) { if (conf->fl_type == lock->fl_type) { sum = add_locks (lock, conf); - sum->fd = lock->fd; + sum->fd = lock->fd; __delete_client_lock (conf); __destroy_client_lock (conf); @@ -301,8 +284,8 @@ __insert_and_merge (clnt_fd_ctx_t *fdctx, client_posix_lock_t *lock) } else { sum = add_locks (lock, conf); - sum->fd = conf->fd; - sum->owner = conf->owner; + sum->fd = conf->fd; + sum->owner = conf->owner; v = subtract_locks (sum, lock); @@ -365,9 +348,9 @@ destroy_client_lock (client_posix_lock_t *lock) } int32_t -delete_granted_locks_owner (fd_t *fd, uint64_t owner) +delete_granted_locks_owner (fd_t *fd, gf_lkowner_t *owner) { - clnt_fd_ctx_t *fdctx = NULL; + clnt_fd_ctx_t *fdctx = NULL; client_posix_lock_t *lock = NULL; client_posix_lock_t *tmp = NULL; xlator_t *this = NULL; @@ -380,7 +363,7 @@ delete_granted_locks_owner (fd_t *fd, uint64_t owner) this = THIS; fdctx = this_fd_get_ctx (fd, this); if (!fdctx) { - gf_log (this->name, GF_LOG_DEBUG, + gf_log (this->name, GF_LOG_WARNING, "fdctx not valid"); ret = -1; goto out; @@ -389,7 +372,7 @@ delete_granted_locks_owner (fd_t *fd, uint64_t owner) pthread_mutex_lock (&fdctx->mutex); { list_for_each_entry_safe (lock, tmp, &fdctx->lock_list, list) { - if (lock->owner == owner) { + if (!is_same_lkowner (&lock->owner, owner)) { list_del_init (&lock->list); list_add_tail (&lock->list, &delete_list); count++; @@ -404,7 +387,7 @@ delete_granted_locks_owner (fd_t *fd, uint64_t owner) } /* FIXME: Need to actually print the locks instead of count */ - gf_log (this->name, GF_LOG_DEBUG, + gf_log (this->name, GF_LOG_TRACE, "Number of locks cleared=%d", count); out: @@ -438,27 +421,12 @@ delete_granted_locks_fd (clnt_fd_ctx_t *fdctx) } /* FIXME: Need to actually print the locks instead of count */ - gf_log (this->name, GF_LOG_DEBUG, + gf_log (this->name, GF_LOG_TRACE, "Number of locks cleared=%d", count); return ret; } -static void -client_mark_bad_fd (fd_t *fd, clnt_fd_ctx_t *fdctx) -{ - xlator_t *this = NULL; - - this = THIS; - if (fdctx) - fdctx->remote_fd = -1; - - gf_log (this->name, GF_LOG_WARNING, - "marking the file descriptor (%p) bad", fd); - - this_fd_set_ctx (fd, this, NULL, fdctx); -} - int32_t client_cmd_to_gf_cmd (int32_t cmd, int32_t *gf_cmd) { @@ -486,14 +454,11 @@ client_cmd_to_gf_cmd (int32_t cmd, int32_t *gf_cmd) } static client_posix_lock_t * -new_client_lock (struct gf_flock *flock, uint64_t owner, +new_client_lock (struct gf_flock *flock, gf_lkowner_t *owner, int32_t cmd, fd_t *fd) { client_posix_lock_t *new_lock = NULL; - xlator_t *this = NULL; - - this = THIS; new_lock = GF_CALLOC (1, sizeof (*new_lock), gf_client_mt_clnt_lock_t); if (!new_lock) { @@ -512,7 +477,8 @@ new_client_lock (struct gf_flock *flock, uint64_t owner, else new_lock->fl_end = flock->l_start + flock->l_len - 1; - new_lock->owner = owner; + new_lock->owner = *owner; + new_lock->cmd = cmd; /* Not really useful */ out: @@ -530,8 +496,8 @@ client_save_number_fds (clnt_conf_t *conf, int count) } int -client_add_lock_for_recovery (fd_t *fd, struct gf_flock *flock, uint64_t owner, - int32_t cmd) +client_add_lock_for_recovery (fd_t *fd, struct gf_flock *flock, + gf_lkowner_t *owner, int32_t cmd) { clnt_fd_ctx_t *fdctx = NULL; xlator_t *this = NULL; @@ -569,350 +535,6 @@ out: } -static int -construct_reserve_unlock (struct gf_flock *lock, call_frame_t *frame, - client_posix_lock_t *client_lock) -{ - GF_ASSERT (lock); - GF_ASSERT (frame); - GF_ASSERT (frame->root->lk_owner); - - lock->l_type = F_UNLCK; - lock->l_start = 0; - lock->l_whence = SEEK_SET; - lock->l_len = 0; /* Whole file */ - lock->l_pid = (uint64_t)(unsigned long)frame->root; - - frame->root->lk_owner = client_lock->owner; - - return 0; -} - -static int -construct_reserve_lock (client_posix_lock_t *client_lock, call_frame_t *frame, - struct gf_flock *lock) -{ - GF_ASSERT (client_lock); - - memcpy (lock, &(client_lock->user_flock), sizeof (struct gf_flock)); - - frame->root->lk_owner = client_lock->owner; - - return 0; -} - -uint64_t -decrement_reopen_fd_count (xlator_t *this, clnt_conf_t *conf) -{ - uint64_t fd_count = 0; - - LOCK (&conf->rec_lock); - { - fd_count = --(conf->reopen_fd_count); - } - UNLOCK (&conf->rec_lock); - - if (fd_count == 0) { - gf_log (this->name, GF_LOG_INFO, - "last fd open'd/lock-self-heal'd - notifying CHILD-UP"); - client_notify_parents_child_up (this); - } - - return fd_count; -} - -int32_t -client_remove_reserve_lock_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct gf_flock *lock) -{ - clnt_local_t *local = NULL; - clnt_conf_t *conf = NULL; - - uint64_t fd_count = 0; - - local = frame->local; - conf = this->private; - - if (op_ret < 0) { - gf_log (this->name, GF_LOG_WARNING, - "removing reserver lock on fd failed: %s", - strerror(op_errno)); - goto cleanup; - } - - gf_log (this->name, GF_LOG_DEBUG, - "Removing reserve lock was successful."); - -cleanup: - frame->local = NULL; - - client_mark_bad_fd (local->client_lock->fd, local->fdctx); - - destroy_client_lock (local->client_lock); - client_local_wipe (local); - STACK_DESTROY (frame->root); - - fd_count = decrement_reopen_fd_count (this, conf); - gf_log (this->name, GF_LOG_DEBUG, - "Need to attempt lock recovery on %lld open fds", - (unsigned long long) fd_count); - return 0; -} - -static void -client_remove_reserve_lock (xlator_t *this, call_frame_t *frame, - client_posix_lock_t *lock) -{ - struct gf_flock unlock; - clnt_local_t *local = NULL; - - local = frame->local; - construct_reserve_unlock (&unlock, frame, lock); - - STACK_WIND (frame, client_remove_reserve_lock_cbk, - this, this->fops->lk, - lock->fd, F_RESLK_UNLCK, &unlock); -} - -static client_posix_lock_t * -get_next_recovery_lock (xlator_t *this, clnt_local_t *local) -{ - client_posix_lock_t *lock = NULL; - - pthread_mutex_lock (&local->mutex); - { - if (list_empty (&local->lock_list)) { - gf_log (this->name, GF_LOG_DEBUG, - "lock-list empty"); - goto unlock; - } - - lock = list_entry ((local->lock_list).next, typeof (*lock), list); - list_del_init (&lock->list); - } -unlock: - pthread_mutex_unlock (&local->mutex); - - return lock; - -} - -int32_t -client_reserve_lock_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct gf_flock *lock) -{ - - clnt_local_t *local = NULL; - clnt_conf_t *conf = NULL; - - uint64_t fd_count = 0; - - local = frame->local; - conf = this->private; - - /* Got the reserve lock. Check if lock is grantable and proceed - with the real lk call */ - - if (op_ret >= 0) { - /* Lock is grantable if flock reflects a successful getlk() call*/ - if (lock->l_type == F_UNLCK && lock->l_pid) { - gf_log (this->name, GF_LOG_INFO, - "Got the reservelk, but the lock is not grantable. "); - client_remove_reserve_lock (this, frame, local->client_lock); - goto out; - } - - gf_log (this->name, GF_LOG_DEBUG, "reserve lock succeeded"); - client_send_recovery_lock (frame, this, local->client_lock); - goto out; - } - - /* Somebody else has a reserve lk. Lock conflict detected. - Mark fd as bad */ - - gf_log (this->name, GF_LOG_WARNING, - "reservelk OP failed. aborting lock recovery"); - - client_mark_bad_fd (local->client_lock->fd, - local->fdctx); - destroy_client_lock (local->client_lock); - frame->local = NULL; - client_local_wipe (local); - STACK_DESTROY (frame->root); - - fd_count = decrement_reopen_fd_count (this, conf); - gf_log (this->name, GF_LOG_DEBUG, - "need to attempt lock recovery on %"PRIu64" open fds", - fd_count); - -out: - return 0; -} - -int32_t -client_recovery_lock_cbk (call_frame_t *frame, - void *cookie, - xlator_t *this, - int32_t op_ret, - int32_t op_errno, - struct gf_flock *lock) -{ - clnt_local_t *local = NULL; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - client_posix_lock_t *next_lock = NULL; - - struct gf_flock reserve_flock; - uint64_t fd_count = 0; - - local = frame->local; - conf = this->private; - - if (op_ret < 0) { - gf_log (this->name, GF_LOG_ERROR, - "lock recovery failed: %s", - strerror(op_errno)); - - client_mark_bad_fd (local->client_lock->fd, - local->fdctx); - goto cleanup; - - /* Lock recovered. Continue with reserve lock for next lock */ - } else { - gf_log (this->name, GF_LOG_DEBUG, - "lock recovered successfully - continuing with next lock."); - - next_lock = get_next_recovery_lock (this, local); - if (!next_lock) { - gf_log (this->name, GF_LOG_DEBUG, - "all locks recovered on fd"); - goto cleanup; - } - - construct_reserve_lock (next_lock, frame, &reserve_flock); - local->fdctx = fdctx; - local->client_lock = next_lock; - - STACK_WIND (frame, client_reserve_lock_cbk, - this, this->fops->lk, - next_lock->fd, F_RESLK_LCK, &reserve_flock); - goto out; - - } - -cleanup: - - frame->local = NULL; - client_local_wipe (local); - - if (local->client_lock) - destroy_client_lock (local->client_lock); - - STACK_DESTROY (frame->root); - - fd_count = decrement_reopen_fd_count (this, conf); - - gf_log (this->name, GF_LOG_DEBUG, - "need to attempt lock recovery on %"PRIu64" open fds", - fd_count); - -out: - return 0; -} - -static int -client_send_recovery_lock (call_frame_t *frame, xlator_t *this, - client_posix_lock_t *lock) -{ - - frame->root->lk_owner = lock->owner; - - /* Send all locks as F_SETLK to prevent the frame - from blocking if there is a conflict */ - - STACK_WIND (frame, client_recovery_lock_cbk, - this, this->fops->lk, - lock->fd, F_SETLK, - &(lock->user_flock)); - - return 0; -} - -static int -client_lockrec_init (clnt_fd_ctx_t *fdctx, clnt_local_t *local) -{ - - INIT_LIST_HEAD (&local->lock_list); - pthread_mutex_init (&local->mutex, NULL); - - pthread_mutex_lock (&fdctx->mutex); - { - list_splice_init (&fdctx->lock_list, &local->lock_list); - } - pthread_mutex_unlock (&fdctx->mutex); - - return 0; -} - - -int -client_attempt_lock_recovery (xlator_t *this, clnt_fd_ctx_t *fdctx) -{ - call_frame_t *frame = NULL; - clnt_local_t *local = NULL; - client_posix_lock_t *lock = NULL; - - struct gf_flock reserve_flock; - int ret = 0; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - ret = -ENOMEM; - goto out; - } - - client_lockrec_init (fdctx, local); - - lock = get_next_recovery_lock (this, local); - if (!lock) { - gf_log (this->name, GF_LOG_DEBUG, - "no locks found on fd"); - ret = -1; - goto out; - } - - frame = create_frame (this, this->ctx->pool); - if (!frame) { - gf_log (this->name, GF_LOG_ERROR, - "creating of frame failed, lock recovery failed"); - ret = -1; - goto out; - } - - construct_reserve_lock (lock, frame, &reserve_flock); - - frame->local = local; - local->fdctx = fdctx; - local->client_lock = lock; - - STACK_WIND (frame, client_reserve_lock_cbk, - this, this->fops->lk, - lock->fd, F_RESLK_LCK, &reserve_flock); - -out: - return ret; - - -} - int32_t client_dump_locks (char *name, inode_t *inode, dict_t *dict) diff --git a/xlators/protocol/client/src/client-mem-types.h b/xlators/protocol/client/src/client-mem-types.h index 7ef10a7e7..f6573da2d 100644 --- a/xlators/protocol/client/src/client-mem-types.h +++ b/xlators/protocol/client/src/client-mem-types.h @@ -1,20 +1,11 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.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 Affero 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 - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. */ @@ -25,10 +16,10 @@ 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_req_buf_t, gf_client_mt_clnt_fdctx_t, gf_client_mt_clnt_lock_t, + gf_client_mt_clnt_fd_lk_local_t, gf_client_mt_end, }; #endif /* __CLIENT_MEM_TYPES_H__ */ diff --git a/xlators/protocol/client/src/client-rpc-fops.c b/xlators/protocol/client/src/client-rpc-fops.c new file mode 100644 index 000000000..6355450c3 --- /dev/null +++ b/xlators/protocol/client/src/client-rpc-fops.c @@ -0,0 +1,6203 @@ +/* + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include "client.h" +#include "glusterfs3-xdr.h" +#include "glusterfs3.h" +#include "compat-errno.h" + +int32_t client3_getspec (call_frame_t *frame, xlator_t *this, void *data); +void client_start_ping (void *data); +rpc_clnt_prog_t clnt3_3_fop_prog; + + +int +client_submit_vec_request (xlator_t *this, void *req, call_frame_t *frame, + rpc_clnt_prog_t *prog, int procnum, + fop_cbk_fn_t cbkfn, + struct iovec *payload, int payloadcnt, + struct iobref *iobref, xdrproc_t xdrproc) +{ + int ret = 0; + clnt_conf_t *conf = NULL; + struct iovec iov = {0, }; + struct iobuf *iobuf = NULL; + int count = 0; + int start_ping = 0; + struct iobref *new_iobref = NULL; + ssize_t xdr_size = 0; + struct rpc_req rpcreq = {0, }; + + start_ping = 0; + + conf = this->private; + + if (req && xdrproc) { + xdr_size = xdr_sizeof (xdrproc, req); + iobuf = iobuf_get2 (this->ctx->iobuf_pool, xdr_size); + if (!iobuf) { + goto unwind; + }; + + new_iobref = iobref_new (); + if (!new_iobref) { + goto unwind; + } + + if (iobref != NULL) { + ret = iobref_merge (new_iobref, iobref); + if (ret != 0) { + gf_log (this->name, GF_LOG_WARNING, + "cannot merge iobref passed from caller " + "into new_iobref"); + } + } + + ret = iobref_add (new_iobref, iobuf); + if (ret != 0) { + gf_log (this->name, GF_LOG_WARNING, + "cannot add iobuf into iobref"); + goto unwind; + } + + iov.iov_base = iobuf->ptr; + iov.iov_len = iobuf_size (iobuf); + + /* Create the xdr payload */ + ret = xdr_serialize_generic (iov, req, xdrproc); + if (ret == -1) { + gf_log_callingfn ("", GF_LOG_WARNING, + "XDR function failed"); + goto unwind; + } + + iov.iov_len = ret; + count = 1; + } + + /* Send the msg */ + ret = rpc_clnt_submit (conf->rpc, prog, procnum, cbkfn, &iov, count, + payload, payloadcnt, new_iobref, frame, NULL, 0, + NULL, 0, NULL); + if (ret < 0) { + gf_log (this->name, GF_LOG_DEBUG, "rpc_clnt_submit failed"); + } + + 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); + + if (new_iobref) + iobref_unref (new_iobref); + + if (iobuf) + iobuf_unref (iobuf); + + return ret; + +unwind: + rpcreq.rpc_status = -1; + cbkfn (&rpcreq, NULL, 0, frame); + + if (new_iobref) + iobref_unref (new_iobref); + + if (iobuf) + iobuf_unref (iobuf); + + return ret; +} + +/* CBK */ + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + local = frame->local; + inode = local->loc.inode; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_symlink_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + /* no need to print the gfid, because it will be null, since + * symlink operation failed. + */ + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s. Path: (%s to %s)", + strerror (gf_error_to_errno (rsp.op_errno)), + local->loc.path, local->loc2.path); + } + + CLIENT_STACK_UNWIND (symlink, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), inode, &stbuf, + &preparent, &postparent, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + local = frame->local; + + inode = local->loc.inode; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_mknod_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s. Path: %s", + strerror (gf_error_to_errno (rsp.op_errno)), + local->loc.path); + } + + CLIENT_STACK_UNWIND (mknod, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), inode, + &stbuf, &preparent, &postparent, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + local = frame->local; + inode = local->loc.inode; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_mkdir_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s. Path: %s", + strerror (gf_error_to_errno (rsp.op_errno)), + local->loc.path); + } + + CLIENT_STACK_UNWIND (mkdir, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), inode, + &stbuf, &preparent, &postparent, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +_copy_gfid_from_inode_holders (uuid_t gfid, loc_t *loc, fd_t *fd) +{ + int ret = 0; + + if (fd && fd->inode && !uuid_is_null (fd->inode->gfid)) { + uuid_copy (gfid, fd->inode->gfid); + goto out; + } + + if (!loc) { + GF_ASSERT (0); + ret = -1; + goto out; + } + + if (loc->inode && !uuid_is_null (loc->inode->gfid)) { + uuid_copy (gfid, loc->inode->gfid); + } else if (!uuid_is_null (loc->gfid)) { + uuid_copy (gfid, loc->gfid); + } else { + GF_ASSERT (0); + ret = -1; + } +out: + return ret; +} + +int +client_add_fd_to_saved_fds (xlator_t *this, fd_t *fd, loc_t *loc, int32_t flags, + int64_t remote_fd, int is_dir) +{ + int ret = 0; + uuid_t gfid = {0}; + clnt_conf_t *conf = NULL; + clnt_fd_ctx_t *fdctx = NULL; + + conf = this->private; + ret = _copy_gfid_from_inode_holders (gfid, loc, fd); + if (ret) { + ret = -EINVAL; + goto out; + } + + fdctx = GF_CALLOC (1, sizeof (*fdctx), + gf_client_mt_clnt_fdctx_t); + if (!fdctx) { + ret = -ENOMEM; + goto out; + } + + uuid_copy (fdctx->gfid, gfid); + fdctx->is_dir = is_dir; + fdctx->remote_fd = remote_fd; + fdctx->flags = flags; + fdctx->lk_ctx = fd_lk_ctx_ref (fd->lk_ctx); + fdctx->lk_heal_state = GF_LK_HEAL_DONE; + fdctx->reopen_done = client_default_reopen_done; + + INIT_LIST_HEAD (&fdctx->sfd_pos); + INIT_LIST_HEAD (&fdctx->lock_list); + + this_fd_set_ctx (fd, this, loc, fdctx); + + pthread_mutex_lock (&conf->lock); + { + list_add_tail (&fdctx->sfd_pos, &conf->saved_fds); + } + pthread_mutex_unlock (&conf->lock); +out: + return ret; +} + +int +client3_3_open_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + call_frame_t *frame = NULL; + fd_t *fd = NULL; + int ret = 0; + gfs3_open_rsp rsp = {0,}; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + local = frame->local; + + 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_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_open_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (-1 != rsp.op_ret) { + ret = client_add_fd_to_saved_fds (frame->this, fd, &local->loc, + local->flags, rsp.fd, 0); + if (ret) { + rsp.op_ret = -1; + rsp.op_errno = -ret; + goto out; + } + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s. Path: %s (%s)", + strerror (gf_error_to_errno (rsp.op_errno)), + local->loc.path, loc_gfid_utoa (&local->loc)); + } + + CLIENT_STACK_UNWIND (open, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), fd, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_stat_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (-1 != rsp.op_ret) { + gf_stat_to_iatt (&rsp.stat, &iatt); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + + CLIENT_STACK_UNWIND (stat, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &iatt, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_readlink_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (-1 != rsp.op_ret) { + gf_stat_to_iatt (&rsp.buf, &iatt); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, (gf_error_to_errno(rsp.op_errno) == ENOENT)? + GF_LOG_DEBUG:GF_LOG_WARNING, "remote operation failed:" + " %s", strerror (gf_error_to_errno (rsp.op_errno))); + } + + CLIENT_STACK_UNWIND (readlink, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), rsp.path, + &iatt, xdata); + + /* This is allocated by the libc while decoding RPC msg */ + /* Hence no 'GF_FREE', but just 'free' */ + free (rsp.path); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_unlink_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, + ((gf_error_to_errno (rsp.op_errno) == ENOENT) + ? GF_LOG_DEBUG : GF_LOG_WARNING), + "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + + CLIENT_STACK_UNWIND (unlink, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &preparent, + &postparent, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_rmdir_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (rmdir, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &preparent, + &postparent, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_truncate_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (truncate, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_statfs_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (-1 != rsp.op_ret) { + gf_statfs_to_statfs (&rsp.statfs, &statfs); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (statfs, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &statfs, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + clnt_local_t *local = NULL; + + + this = THIS; + + frame = myframe; + local = frame->local; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_truncate_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } else if (rsp.op_ret >= 0) { + if (local->attempt_reopen) + client_attempt_reopen (local->fd, this); + } + CLIENT_STACK_UNWIND (writev, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_flush_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + clnt_local_t *local = NULL; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + gf_common_rsp rsp = {0,}; + int ret = 0; + + frame = myframe; + this = THIS; + local = frame->local; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (rsp.op_ret >= 0 && !fd_is_anonymous (local->fd)) { + /* Delete all saved locks of the owner issuing flush */ + ret = delete_granted_locks_owner (local->fd, &local->owner); + gf_log (this->name, GF_LOG_TRACE, + "deleting locks of owner (%s) returned %d", + lkowner_utoa (&local->owner), ret); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (flush, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_truncate_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (fsync, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + int op_errno = EINVAL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + op_errno = gf_error_to_errno (rsp.op_errno); + if (rsp.op_ret == -1) { + gf_log (this->name, ((op_errno == ENOTSUP) ? + GF_LOG_DEBUG : GF_LOG_WARNING), + "remote operation failed: %s", + strerror (op_errno)); + } + CLIENT_STACK_UNWIND (setxattr, frame, rsp.op_ret, op_errno, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_getxattr_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + dict_t *dict = NULL; + int op_errno = EINVAL; + gfs3_getxattr_rsp rsp = {0,}; + int ret = 0; + clnt_local_t *local = NULL; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + local = frame->local; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_getxattr_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + op_errno = EINVAL; + goto out; + } + + op_errno = gf_error_to_errno (rsp.op_errno); + if (-1 != rsp.op_ret) { + GF_PROTOCOL_DICT_UNSERIALIZE (frame->this, dict, + (rsp.dict.dict_val), + (rsp.dict.dict_len), rsp.op_ret, + op_errno, out); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, (((op_errno == ENOTSUP) || + (op_errno == ENODATA) || + (op_errno == ENOENT)) ? + GF_LOG_DEBUG : GF_LOG_WARNING), + "remote operation failed: %s. Path: %s (%s). Key: %s", + strerror (op_errno), + local->loc.path, loc_gfid_utoa (&local->loc), + (local->name) ? local->name : "(null)"); + } + + CLIENT_STACK_UNWIND (getxattr, frame, rsp.op_ret, op_errno, dict, xdata); + + /* don't use GF_FREE, this memory was allocated by libc */ + free (rsp.dict.dict_val); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + if (dict) + dict_unref (dict); + + return 0; +} + +int +client3_3_fgetxattr_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + dict_t *dict = NULL; + gfs3_fgetxattr_rsp rsp = {0,}; + int ret = 0; + int op_errno = EINVAL; + clnt_local_t *local = NULL; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + local = frame->local; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_fgetxattr_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + op_errno = EINVAL; + goto out; + } + + op_errno = gf_error_to_errno (rsp.op_errno); + if (-1 != rsp.op_ret) { + GF_PROTOCOL_DICT_UNSERIALIZE (frame->this, dict, + (rsp.dict.dict_val), + (rsp.dict.dict_len), rsp.op_ret, + op_errno, out); + } + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, ((op_errno == ENOTSUP) ? + GF_LOG_DEBUG : GF_LOG_WARNING), + "remote operation failed: %s", + strerror (op_errno)); + } + + CLIENT_STACK_UNWIND (fgetxattr, frame, rsp.op_ret, op_errno, dict, xdata); + + free (rsp.dict.dict_val); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + if (dict) + dict_unref (dict); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + + CLIENT_STACK_UNWIND (removexattr, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_fremovexattr_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (fremovexattr, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (fsyncdir, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (access, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_ftruncate_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (ftruncate, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_fstat_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (-1 != rsp.op_ret) { + gf_stat_to_iatt (&rsp.stat, &stat); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (fstat, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &stat, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if ((rsp.op_ret == -1) && + (EAGAIN != gf_error_to_errno (rsp.op_errno))) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (inodelk, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + clnt_local_t *local = NULL; + + + frame = myframe; + this = frame->this; + local = frame->local; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if ((rsp.op_ret == -1) && + (EAGAIN != gf_error_to_errno (rsp.op_errno))) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } else if (rsp.op_ret == 0) { + if (local->attempt_reopen) + client_attempt_reopen (local->fd, this); + } + CLIENT_STACK_UNWIND (finodelk, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if ((rsp.op_ret == -1) && + (EAGAIN != gf_error_to_errno (rsp.op_errno))) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + + CLIENT_STACK_UNWIND (entrylk, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if ((rsp.op_ret == -1) && + (EAGAIN != gf_error_to_errno (rsp.op_errno))) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + + CLIENT_STACK_UNWIND (fentrylk, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_xattrop_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + dict_t *dict = NULL; + gfs3_xattrop_rsp rsp = {0,}; + int ret = 0; + int op_errno = EINVAL; + clnt_local_t *local = NULL; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + local = frame->local; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_xattrop_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + op_errno = EINVAL; + goto out; + } + + op_errno = rsp.op_errno; + if (-1 != rsp.op_ret) { + GF_PROTOCOL_DICT_UNSERIALIZE (frame->this, dict, + (rsp.dict.dict_val), + (rsp.dict.dict_len), rsp.op_ret, + op_errno, out); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s. Path: %s (%s)", + strerror (gf_error_to_errno (rsp.op_errno)), + local->loc.path, loc_gfid_utoa (&local->loc)); + } + + CLIENT_STACK_UNWIND (xattrop, frame, rsp.op_ret, + gf_error_to_errno (op_errno), dict, xdata); + + free (rsp.dict.dict_val); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + if (dict) + dict_unref (dict); + + return 0; +} + +int +client3_3_fxattrop_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + dict_t *dict = NULL; + dict_t *xdata = NULL; + gfs3_fxattrop_rsp rsp = {0,}; + int ret = 0; + int op_errno = 0; + clnt_local_t *local = NULL; + xlator_t *this = NULL; + + this = THIS; + + frame = myframe; + local = frame->local; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_fxattrop_rsp); + if (ret < 0) { + rsp.op_ret = -1; + op_errno = EINVAL; + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + goto out; + } + op_errno = rsp.op_errno; + if (-1 != rsp.op_ret) { + GF_PROTOCOL_DICT_UNSERIALIZE (frame->this, dict, + (rsp.dict.dict_val), + (rsp.dict.dict_len), rsp.op_ret, + op_errno, out); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (frame->this, xdata, + (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), rsp.op_ret, + op_errno, out); +out: + + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s", + strerror (gf_error_to_errno (op_errno))); + } else if (rsp.op_ret == 0) { + if (local->attempt_reopen) + client_attempt_reopen (local->fd, this); + } + CLIENT_STACK_UNWIND (fxattrop, frame, rsp.op_ret, + gf_error_to_errno (op_errno), dict, xdata); + + free (rsp.dict.dict_val); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + if (dict) + dict_unref (dict); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + int op_errno = EINVAL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + op_errno = gf_error_to_errno (rsp.op_errno); + if (rsp.op_ret == -1) { + gf_log (this->name, ((op_errno == ENOTSUP) ? + GF_LOG_DEBUG : GF_LOG_WARNING), + "remote operation failed: %s", + strerror (op_errno)); + } + + CLIENT_STACK_UNWIND (fsetxattr, frame, rsp.op_ret, op_errno, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_fsetattr_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (fsetattr, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_fallocate_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_fallocate_rsp rsp = {0,}; + struct iatt prestat = {0,}; + struct iatt poststat = {0,}; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_fallocate_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (fallocate, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_discard_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_discard_rsp rsp = {0,}; + struct iatt prestat = {0,}; + struct iatt poststat = {0,}; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t) xdr_gfs3_discard_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (discard, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_zerofill_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfs3_zerofill_rsp rsp = {0,}; + struct iatt prestat = {0,}; + struct iatt poststat = {0,}; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic(*iov, &rsp, (xdrproc_t) xdr_gfs3_zerofill_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (zerofill, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_setattr_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (setattr, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + gfs3_create_rsp rsp = {0,}; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + local = frame->local; + 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_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_create_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + uuid_copy (local->loc.gfid, stbuf.ia_gfid); + ret = client_add_fd_to_saved_fds (frame->this, fd, &local->loc, + local->flags, rsp.fd, 0); + if (ret) { + rsp.op_ret = -1; + rsp.op_errno = -ret; + goto out; + } + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s. Path: %s", + strerror (gf_error_to_errno (rsp.op_errno)), + local->loc.path); + } + + CLIENT_STACK_UNWIND (create, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), fd, inode, + &stbuf, &preparent, &postparent, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_rchecksum_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (rchecksum, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), + rsp.weak_checksum, + (uint8_t *)rsp.strong_checksum.strong_checksum_val, + xdata); + + 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); + } + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_lk_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + clnt_local_t *local = NULL; + struct gf_flock lock = {0,}; + gfs3_lk_rsp rsp = {0,}; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + local = frame->local; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_lk_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (rsp.op_ret >= 0) { + gf_proto_flock_to_flock (&rsp.flock, &lock); + } + + /* Save the lock to the client lock cache to be able + to recover in the case of server reboot.*/ + /* + temporarily + if (local->cmd == F_SETLK || local->cmd == F_SETLKW) { + ret = client_add_lock_for_recovery (local->fd, &lock, + local->owner, local->cmd); + if (ret < 0) { + rsp.op_ret = -1; + rsp.op_errno = -ret; + } + } + */ + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if ((rsp.op_ret == -1) && + (EAGAIN != gf_error_to_errno (rsp.op_errno))) { + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + + CLIENT_STACK_UNWIND (lk, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &lock, xdata); + + free (rsp.xdata.xdata_val); + + free (rsp.flock.lk_owner.lk_owner_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + clnt_local_t *local = NULL; + gf_dirent_t entries; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + local = frame->local; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_readdir_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + INIT_LIST_HEAD (&entries.list); + if (rsp.op_ret > 0) { + unserialize_rsp_dirent (&rsp, &entries); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (frame->this, xdata, + (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), rsp.op_ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s remote_fd = %d", + strerror (gf_error_to_errno (rsp.op_errno)), + local->cmd); + } + CLIENT_STACK_UNWIND (readdir, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &entries, xdata); + + if (rsp.op_ret != -1) { + gf_dirent_free (&entries); + } + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + clnt_readdir_rsp_cleanup (&rsp); + + return 0; +} + + +int +client3_3_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; + clnt_local_t *local = NULL; + gf_dirent_t entries; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + local = frame->local; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_readdirp_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + INIT_LIST_HEAD (&entries.list); + if (rsp.op_ret > 0) { + unserialize_rsp_direntp (this, local->fd, &rsp, &entries); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (readdirp, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &entries, xdata); + + if (rsp.op_ret != -1) { + gf_dirent_free (&entries); + } + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + clnt_readdirp_rsp_cleanup (&rsp); + + return 0; +} + + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_rename_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } + CLIENT_STACK_UNWIND (rename, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), + &stbuf, &preoldparent, &postoldparent, + &prenewparent, &postnewparent, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + + local = frame->local; + inode = local->loc.inode; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_link_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + 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); + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s (%s -> %s)", + strerror (gf_error_to_errno (rsp.op_errno)), + local->loc.path, local->loc2.path); + } + + CLIENT_STACK_UNWIND (link, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), inode, + &stbuf, &preparent, &postparent, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client3_3_opendir_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + call_frame_t *frame = NULL; + fd_t *fd = NULL; + int ret = 0; + gfs3_opendir_rsp rsp = {0,}; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + local = frame->local; + + 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_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_opendir_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (-1 != rsp.op_ret) { + ret = client_add_fd_to_saved_fds (frame->this, fd, &local->loc, + 0, rsp.fd, 1); + if (ret) { + rsp.op_ret = -1; + rsp.op_errno = -ret; + goto out; + } + } + + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s. Path: %s (%s)", + strerror (gf_error_to_errno (rsp.op_errno)), + local->loc.path, loc_gfid_utoa (&local->loc)); + } + CLIENT_STACK_UNWIND (opendir, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), fd, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client3_3_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 = EINVAL; + dict_t *xdata = NULL; + inode_t *inode = NULL; + xlator_t *this = NULL; + + this = THIS; + + frame = myframe; + local = frame->local; + inode = local->loc.inode; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_lookup_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + 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 == -1) + goto out; + + rsp.op_ret = -1; + gf_stat_to_iatt (&rsp.stat, &stbuf); + + GF_PROTOCOL_DICT_UNSERIALIZE (frame->this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), rsp.op_ret, + op_errno, out); + + if ((!uuid_is_null (inode->gfid)) + && (uuid_compare (stbuf.ia_gfid, inode->gfid) != 0)) { + gf_log (frame->this->name, GF_LOG_DEBUG, + "gfid changed for %s", local->loc.path); + rsp.op_ret = -1; + op_errno = ESTALE; + goto out; + } + + rsp.op_ret = 0; + +out: + rsp.op_errno = op_errno; + if (rsp.op_ret == -1) { + /* any error other than ENOENT */ + if (rsp.op_errno != ENOENT) + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s. Path: %s (%s)", + strerror (rsp.op_errno), local->loc.path, + loc_gfid_utoa (&local->loc)); + else + gf_log (this->name, GF_LOG_TRACE, "not found on remote node"); + + } + + CLIENT_STACK_UNWIND (lookup, frame, rsp.op_ret, rsp.op_errno, inode, + &stbuf, xdata, &postparent); + + if (xdata) + dict_unref (xdata); + + free (rsp.xdata.xdata_val); + + return 0; +} + +int +client3_3_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[MAX_IOVEC] = {{0}, }; + struct iatt stat = {0,}; + gfs3_read_rsp rsp = {0,}; + int ret = 0, rspcount = 0; + clnt_local_t *local = NULL; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + memset (vector, 0, sizeof (vector)); + + frame = myframe; + local = frame->local; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_read_rsp); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (rsp.op_ret != -1) { + iobref = req->rsp_iobref; + gf_stat_to_iatt (&rsp.stat, &stat); + + vector[0].iov_len = rsp.op_ret; + if (rsp.op_ret > 0) + vector[0].iov_base = req->rsp[1].iov_base; + rspcount = 1; + } + GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), + (rsp.xdata.xdata_len), ret, + rsp.op_errno, out); + +#ifdef GF_TESTING_IO_XDATA + dict_dump (xdata); +#endif + +out: + if (rsp.op_ret == -1) { + gf_log (this->name, GF_LOG_WARNING, + "remote operation failed: %s", + strerror (gf_error_to_errno (rsp.op_errno))); + } else if (rsp.op_ret >= 0) { + if (local->attempt_reopen) + client_attempt_reopen (local->fd, this); + } + CLIENT_STACK_UNWIND (readv, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), vector, rspcount, + &stat, iobref, xdata); + + free (rsp.xdata.xdata_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client3_3_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_3_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 +client_fdctx_destroy (xlator_t *this, clnt_fd_ctx_t *fdctx) +{ + clnt_conf_t *conf = NULL; + call_frame_t *fr = NULL; + int32_t ret = -1; + char parent_down = 0; + fd_lk_ctx_t *lk_ctx = NULL; + + GF_VALIDATE_OR_GOTO ("client", this, out); + GF_VALIDATE_OR_GOTO (this->name, fdctx, out); + + conf = (clnt_conf_t *) this->private; + + if (fdctx->remote_fd == -1) { + gf_log (this->name, GF_LOG_DEBUG, "not a valid fd"); + goto out; + } + + pthread_mutex_lock (&conf->lock); + { + parent_down = conf->parent_down; + lk_ctx = fdctx->lk_ctx; + fdctx->lk_ctx = NULL; + } + pthread_mutex_unlock (&conf->lock); + + if (lk_ctx) + fd_lk_ctx_unref (lk_ctx); + + if (!parent_down) + rpc_clnt_ref (conf->rpc); + else + goto out; + + fr = create_frame (this, this->ctx->pool); + if (fr == NULL) { + goto out; + } + + ret = 0; + + if (fdctx->is_dir) { + gfs3_releasedir_req req = {{0,},}; + req.fd = fdctx->remote_fd; + gf_log (this->name, GF_LOG_TRACE, "sending releasedir on fd"); + client_submit_request (this, &req, fr, &clnt3_3_fop_prog, + GFS3_OP_RELEASEDIR, + client3_3_releasedir_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_releasedir_req); + } else { + gfs3_release_req req = {{0,},}; + req.fd = fdctx->remote_fd; + gf_log (this->name, GF_LOG_TRACE, "sending release on fd"); + client_submit_request (this, &req, fr, &clnt3_3_fop_prog, + GFS3_OP_RELEASE, + client3_3_release_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_release_req); + } + + rpc_clnt_unref (conf->rpc); +out: + if (fdctx) { + fdctx->remote_fd = -1; + GF_FREE (fdctx); + } + + if (ret && fr) + STACK_DESTROY (fr->root); + + return ret; +} + +int32_t +client3_3_releasedir (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_fd_ctx_t *fdctx = NULL; + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + + if (!this || !data) + goto out; + + 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) + client_fdctx_destroy (this, fdctx); +out: + + return 0; +} + +int32_t +client3_3_release (call_frame_t *frame, xlator_t *this, + void *data) +{ + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + clnt_fd_ctx_t *fdctx = NULL; + clnt_args_t *args = NULL; + lk_heal_state_t lk_heal_state = GF_LK_HEAL_DONE; + + if (!this || !data) + goto out; + + 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; + lk_heal_state = fdctx->lk_heal_state; + + /* fdctx->remote_fd == -1 indicates a reopen attempt + in progress. Just mark ->released = 1 and let + reopen_cbk handle releasing + */ + + if (remote_fd != -1 && + lk_heal_state == GF_LK_HEAL_DONE) + list_del_init (&fdctx->sfd_pos); + + fdctx->released = 1; + } + } + pthread_mutex_unlock (&conf->lock); + + if (remote_fd != -1 && lk_heal_state == GF_LK_HEAL_DONE) + client_fdctx_destroy (this, fdctx); +out: + return 0; +} + + +int32_t +client3_3_lookup (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_local_t *local = NULL; + clnt_args_t *args = NULL; + gfs3_lookup_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + data_t *content = NULL; + struct iovec vector[MAX_IOVEC] = {{0}, }; + int count = 0; + struct iobref *rsp_iobref = NULL; + struct iobuf *rsp_iobuf = NULL; + struct iovec *rsphdr = NULL; + + if (!frame || !this || !data) + goto unwind; + + memset (vector, 0, sizeof (vector)); + + conf = this->private; + args = data; + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + + if (!(args->loc && args->loc->inode)) + goto unwind; + + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + frame->local = local; + + if (args->loc->parent) { + if (!uuid_is_null (args->loc->parent->gfid)) + memcpy (req.pargfid, args->loc->parent->gfid, 16); + else + memcpy (req.pargfid, args->loc->pargfid, 16); + } else { + if (!uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + } + + if (args->xdata) { + content = dict_get (args->xdata, GF_CONTENT_KEY); + if (content != NULL) { + rsp_iobref = iobref_new (); + if (rsp_iobref == NULL) { + goto unwind; + } + + /* TODO: what is the size we should send ? */ + /* This change very much depends on quick-read + changes */ + rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); + if (rsp_iobuf == NULL) { + goto unwind; + } + + iobref_add (rsp_iobref, rsp_iobuf); + iobuf_unref (rsp_iobuf); + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr (rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + rsp_iobuf = NULL; + rsp_iobref = NULL; + } + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, + (&req.xdata.xdata_val), + req.xdata.xdata_len, + op_errno, unwind); + } + + if (args->loc->name) + req.bname = (char *)args->loc->name; + else + req.bname = ""; + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_LOOKUP, client3_3_lookup_cbk, + NULL, rsphdr, count, + NULL, 0, local->iobref, + (xdrproc_t)xdr_gfs3_lookup_req); + + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + return 0; + +unwind: + CLIENT_STACK_UNWIND (lookup, frame, -1, op_errno, NULL, NULL, NULL, + NULL); + + GF_FREE (req.xdata.xdata_val); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + return 0; +} + +int32_t +client3_3_stat (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_stat_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + if (!(args->loc && args->loc->inode)) + goto unwind; + + if (!uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.gfid)), + unwind, op_errno, EINVAL); + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_STAT, client3_3_stat_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_stat_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (stat, frame, -1, op_errno, NULL, NULL); + + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + +int32_t +client3_3_truncate (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_truncate_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + if (!(args->loc && args->loc->inode)) + goto unwind; + + if (!uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.gfid)), + unwind, op_errno, EINVAL); + req.offset = args->offset; + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_TRUNCATE, + client3_3_truncate_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_truncate_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (truncate, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + +int32_t +client3_3_ftruncate (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + gfs3_ftruncate_req req = {{0,},}; + int op_errno = EINVAL; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + req.offset = args->offset; + req.fd = remote_fd; + memcpy (req.gfid, args->fd->inode->gfid, 16); + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FTRUNCATE, + client3_3_ftruncate_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_ftruncate_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (ftruncate, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_access (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_access_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + if (!(args->loc && args->loc->inode)) + goto unwind; + + if (!uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.gfid)), + unwind, op_errno, EINVAL); + req.mask = args->mask; + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_ACCESS, + client3_3_access_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_access_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (access, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_readlink (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_readlink_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + clnt_local_t *local = NULL; + struct iobuf *rsp_iobuf = NULL; + struct iobref *rsp_iobref = NULL; + struct iovec *rsphdr = NULL; + int count = 0; + struct iovec vector[MAX_IOVEC] = {{0}, }; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + if (!(args->loc && args->loc->inode)) + goto unwind; + + if (!uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.gfid)), + unwind, op_errno, EINVAL); + req.size = args->size; + conf = this->private; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + + frame->local = local; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + rsp_iobref = iobref_new (); + if (rsp_iobref == NULL) { + goto unwind; + } + + rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); + if (rsp_iobuf == NULL) { + goto unwind; + } + + iobref_add (rsp_iobref, rsp_iobuf); + iobuf_unref (rsp_iobuf); + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr (rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + rsp_iobuf = NULL; + rsp_iobref = NULL; + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_READLINK, + client3_3_readlink_cbk, NULL, + rsphdr, count, NULL, 0, + local->iobref, + (xdrproc_t)xdr_gfs3_readlink_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + if (rsp_iobref != NULL) { + iobref_unref (rsp_iobref); + } + + CLIENT_STACK_UNWIND (readlink, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + + +int32_t +client3_3_unlink (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_unlink_req req = {{0,},}; + int ret = 0; + int op_errno = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + if (!(args->loc && args->loc->parent)) + goto unwind; + + if (!uuid_is_null (args->loc->parent->gfid)) + memcpy (req.pargfid, args->loc->parent->gfid, 16); + else + memcpy (req.pargfid, args->loc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.pargfid)), + unwind, op_errno, EINVAL); + req.bname = (char *)args->loc->name; + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_UNLINK, + client3_3_unlink_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_unlink_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (unlink, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_rmdir (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_rmdir_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + if (!(args->loc && args->loc->parent)) + goto unwind; + + if (!uuid_is_null (args->loc->parent->gfid)) + memcpy (req.pargfid, args->loc->parent->gfid, 16); + else + memcpy (req.pargfid, args->loc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.pargfid)), + unwind, op_errno, EINVAL); + req.bname = (char *)args->loc->name; + req.xflags = args->flags; + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_RMDIR, client3_3_rmdir_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_rmdir_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (rmdir, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_symlink (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_symlink_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + + frame->local = local; + + if (!(args->loc && args->loc->parent)) + goto unwind; + + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + + if (!uuid_is_null (args->loc->parent->gfid)) + memcpy (req.pargfid, args->loc->parent->gfid, 16); + else + memcpy (req.pargfid, args->loc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.pargfid)), + unwind, op_errno, EINVAL); + req.linkname = (char *)args->linkname; + req.bname = (char *)args->loc->name; + req.umask = args->umask; + local->loc2.path = gf_strdup (req.linkname); + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_SYMLINK, client3_3_symlink_cbk, + NULL, NULL, 0, NULL, + 0, NULL, (xdrproc_t)xdr_gfs3_symlink_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + + CLIENT_STACK_UNWIND (symlink, frame, -1, op_errno, NULL, NULL, NULL, + NULL, NULL); + + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_rename (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_rename_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + if (!(args->oldloc && args->newloc && args->oldloc->parent && + args->newloc->parent)) + goto unwind; + + if (!uuid_is_null (args->oldloc->parent->gfid)) + memcpy (req.oldgfid, args->oldloc->parent->gfid, 16); + else + memcpy (req.oldgfid, args->oldloc->pargfid, 16); + + if (!uuid_is_null (args->newloc->parent->gfid)) + memcpy (req.newgfid, args->newloc->parent->gfid, 16); + else + memcpy (req.newgfid, args->newloc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.oldgfid)), + unwind, op_errno, EINVAL); + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.newgfid)), + unwind, op_errno, EINVAL); + req.oldbname = (char *)args->oldloc->name; + req.newbname = (char *)args->newloc->name; + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_RENAME, client3_3_rename_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_rename_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (rename, frame, -1, op_errno, NULL, NULL, NULL, + NULL, NULL, NULL); + + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_link (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_link_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + if (!(args->oldloc && args->oldloc->inode && args->newloc && + args->newloc->parent)) + goto unwind; + + if (!uuid_is_null (args->oldloc->inode->gfid)) + memcpy (req.oldgfid, args->oldloc->inode->gfid, 16); + else + memcpy (req.oldgfid, args->oldloc->gfid, 16); + + if (!uuid_is_null (args->newloc->parent->gfid)) + memcpy (req.newgfid, args->newloc->parent->gfid, 16); + else + memcpy (req.newgfid, args->newloc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.oldgfid)), + unwind, op_errno, EINVAL); + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.newgfid)), + unwind, op_errno, EINVAL); + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + + loc_copy (&local->loc, args->oldloc); + loc_path (&local->loc, NULL); + loc_copy (&local->loc2, args->newloc); + loc_path (&local->loc2, NULL); + frame->local = local; + + req.newbname = (char *)args->newloc->name; + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_LINK, client3_3_link_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_link_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (link, frame, -1, op_errno, NULL, NULL, NULL, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_mknod (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_mknod_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + + if (!(args->loc && args->loc->parent)) + goto unwind; + + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + frame->local = local; + + if (!uuid_is_null (args->loc->parent->gfid)) + memcpy (req.pargfid, args->loc->parent->gfid, 16); + else + memcpy (req.pargfid, args->loc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.pargfid)), + unwind, op_errno, EINVAL); + req.bname = (char *)args->loc->name; + req.mode = args->mode; + req.dev = args->rdev; + req.umask = args->umask; + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_MKNOD, client3_3_mknod_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_mknod_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (mknod, frame, -1, op_errno, NULL, NULL, NULL, + NULL, NULL); + + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_mkdir (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_mkdir_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + + if (!(args->loc && args->loc->parent)) + goto unwind; + + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + frame->local = local; + + if (!uuid_is_null (args->loc->parent->gfid)) + memcpy (req.pargfid, args->loc->parent->gfid, 16); + else + memcpy (req.pargfid, args->loc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.pargfid)), + unwind, op_errno, EINVAL); + + req.bname = (char *)args->loc->name; + req.mode = args->mode; + req.umask = args->umask; + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_MKDIR, client3_3_mkdir_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_mkdir_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (mkdir, frame, -1, op_errno, NULL, NULL, NULL, + NULL, NULL); + + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + +int32_t +client3_3_create (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_create_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + if (!(args->loc && args->loc->parent)) + goto unwind; + + local->fd = fd_ref (args->fd); + local->flags = args->flags; + + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + frame->local = local; + + if (!uuid_is_null (args->loc->parent->gfid)) + memcpy (req.pargfid, args->loc->parent->gfid, 16); + else + memcpy (req.pargfid, args->loc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.pargfid)), + unwind, op_errno, EINVAL); + req.bname = (char *)args->loc->name; + req.mode = args->mode; + req.flags = gf_flags_from_flags (args->flags); + req.umask = args->umask; + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_CREATE, client3_3_create_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_create_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (create, frame, -1, op_errno, NULL, NULL, NULL, + NULL, NULL, NULL); + + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_open (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_open_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + if (!(args->loc && args->loc->inode)) + goto unwind; + + local->fd = fd_ref (args->fd); + local->flags = args->flags; + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + frame->local = local; + + if (!uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.gfid)), + unwind, op_errno, EINVAL); + req.flags = gf_flags_from_flags (args->flags); + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_OPEN, client3_3_open_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_open_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (open, frame, -1, op_errno, NULL, NULL); + + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_readv (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + clnt_local_t *local = NULL; + int op_errno = ESTALE; + gfs3_read_req req = {{0,},}; + int ret = 0; + struct iovec rsp_vec = {0, }; + struct iobuf *rsp_iobuf = NULL; + struct iobref *rsp_iobref = NULL; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, FALLBACK_TO_ANON_FD, + remote_fd, op_errno, unwind); + ret = client_fd_fop_prepare_local (frame, args->fd, remote_fd); + if (ret) { + op_errno = -ret; + goto unwind; + } + local = frame->local; + + req.size = args->size; + req.offset = args->offset; + req.fd = remote_fd; + req.flag = args->flags; + + memcpy (req.gfid, args->fd->inode->gfid, 16); + + rsp_iobuf = iobuf_get2 (this->ctx->iobuf_pool, args->size); + if (rsp_iobuf == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + rsp_iobref = iobref_new (); + if (rsp_iobref == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + iobref_add (rsp_iobref, rsp_iobuf); + iobuf_unref (rsp_iobuf); + + rsp_vec.iov_base = iobuf_ptr (rsp_iobuf); + rsp_vec.iov_len = iobuf_pagesize (rsp_iobuf); + + rsp_iobuf = NULL; + + if (args->size > rsp_vec.iov_len) { + gf_log (this->name, GF_LOG_WARNING, + "read-size (%lu) is bigger than iobuf size (%lu)", + (unsigned long)args->size, + (unsigned long)rsp_vec.iov_len); + op_errno = EINVAL; + goto unwind; + } + + local->iobref = rsp_iobref; + rsp_iobref = NULL; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_READ, client3_3_readv_cbk, NULL, + NULL, 0, &rsp_vec, 1, + local->iobref, + (xdrproc_t)xdr_gfs3_read_req); + if (ret) { + //unwind is done in the cbk + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + + CLIENT_STACK_UNWIND (readv, frame, -1, op_errno, NULL, 0, NULL, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + +int32_t +client3_3_writev (call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + gfs3_write_req req = {{0,},}; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, FALLBACK_TO_ANON_FD, + remote_fd, op_errno, unwind); + ret = client_fd_fop_prepare_local (frame, args->fd, remote_fd); + if (ret) { + op_errno = -ret; + goto unwind; + } + + req.size = args->size; + req.offset = args->offset; + req.fd = remote_fd; + req.flag = args->flags; + + memcpy (req.gfid, args->fd->inode->gfid, 16); + +#ifdef GF_TESTING_IO_XDATA + if (!args->xdata) + args->xdata = dict_new (); + + ret = dict_set_str (args->xdata, "testing-the-xdata-key", + "testing-the-xdata-value"); +#endif + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_vec_request (this, &req, frame, conf->fops, + GFS3_OP_WRITE, client3_3_writev_cbk, + args->vector, args->count, + args->iobref, + (xdrproc_t)xdr_gfs3_write_req); + if (ret) { + /* + * If the lower layers fail to submit a request, they'll also + * do the unwind for us (see rpc_clnt_submit), so don't unwind + * here in such cases. + */ + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND (writev, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + +int32_t +client3_3_flush (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + gfs3_flush_req req = {{0,},}; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + clnt_local_t *local = NULL; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + conf = this->private; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + + local->fd = fd_ref (args->fd); + local->owner = frame->root->lk_owner; + frame->local = local; + + req.fd = remote_fd; + memcpy (req.gfid, args->fd->inode->gfid, 16); + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FLUSH, client3_3_flush_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_flush_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + + return 0; + +unwind: + CLIENT_STACK_UNWIND (flush, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_fsync (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + gfs3_fsync_req req = {{0,},}; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + int op_errno = 0; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + req.fd = remote_fd; + req.data = args->flags; + memcpy (req.gfid, args->fd->inode->gfid, 16); + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FSYNC, client3_3_fsync_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_fsync_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + + } + + GF_FREE (req.xdata.xdata_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND (fsync, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_fstat (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + gfs3_fstat_req req = {{0,},}; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + req.fd = remote_fd; + memcpy (req.gfid, args->fd->inode->gfid, 16); + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FSTAT, client3_3_fstat_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_fstat_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND (fstat, frame, -1, op_errno, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_opendir (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_opendir_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + if (!(args->loc && args->loc->inode)) + goto unwind; + + local->fd = fd_ref (args->fd); + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + frame->local = local; + + if (!uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.gfid)), + unwind, op_errno, EINVAL); + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_OPENDIR, client3_3_opendir_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_opendir_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND (opendir, frame, -1, op_errno, NULL, NULL); + + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_fsyncdir (call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + gfs3_fsyncdir_req req = {{0,},}; + int ret = 0; + int32_t op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + req.fd = remote_fd; + req.data = args->flags; + memcpy (req.gfid, args->fd->inode->gfid, 16); + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FSYNCDIR, client3_3_fsyncdir_cbk, + NULL, NULL, 0, + NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_fsyncdir_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND (fsyncdir, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_statfs (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_statfs_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + if (!args->loc) + goto unwind; + + if (args->loc->inode) { + if (!uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + } else + req.gfid[15] = 1; + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.gfid)), + unwind, op_errno, EINVAL); + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_STATFS, client3_3_statfs_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_statfs_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND (statfs, frame, -1, op_errno, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_setxattr (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_setxattr_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + if (!(args->loc && args->loc->inode)) + goto unwind; + + if (!uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.gfid)), + unwind, op_errno, EINVAL); + if (args->xattr) { + GF_PROTOCOL_DICT_SERIALIZE (this, args->xattr, + (&req.dict.dict_val), + req.dict.dict_len, + op_errno, unwind); + } + + req.flags = args->flags; + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_SETXATTR, client3_3_setxattr_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_setxattr_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + GF_FREE (req.dict.dict_val); + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (setxattr, frame, -1, op_errno, NULL); + GF_FREE (req.dict.dict_val); + + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_fsetxattr (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + gfs3_fsetxattr_req req = {{0,},}; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + req.fd = remote_fd; + req.flags = args->flags; + memcpy (req.gfid, args->fd->inode->gfid, 16); + + if (args->xattr) { + GF_PROTOCOL_DICT_SERIALIZE (this, args->xattr, + (&req.dict.dict_val), + req.dict.dict_len, + op_errno, unwind); + } + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FSETXATTR, client3_3_fsetxattr_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_fsetxattr_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.dict.dict_val); + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (fsetxattr, frame, -1, op_errno, NULL); + GF_FREE (req.dict.dict_val); + + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + + +int32_t +client3_3_fgetxattr (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + gfs3_fgetxattr_req req = {{0,},}; + int op_errno = ESTALE; + int ret = 0; + int count = 0; + clnt_local_t *local = NULL; + struct iobref *rsp_iobref = NULL; + struct iobuf *rsp_iobuf = NULL; + struct iovec *rsphdr = NULL; + struct iovec vector[MAX_IOVEC] = {{0}, }; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + rsp_iobref = iobref_new (); + if (rsp_iobref == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + /* TODO: what is the size we should send ? */ + rsp_iobuf = iobuf_get2 (this->ctx->iobuf_pool, 8 * GF_UNIT_KB); + if (rsp_iobuf == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + iobref_add (rsp_iobref, rsp_iobuf); + iobuf_unref (rsp_iobuf); + + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr (rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize (rsp_iobuf);; + count = 1; + local->iobref = rsp_iobref; + rsp_iobuf = NULL; + rsp_iobref = NULL; + + req.namelen = 1; /* Use it as a flag */ + req.fd = remote_fd; + req.name = (char *)args->name; + if (!req.name) { + req.name = ""; + req.namelen = 0; + } + memcpy (req.gfid, args->fd->inode->gfid, 16); + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FGETXATTR, + client3_3_fgetxattr_cbk, NULL, + rsphdr, count, + NULL, 0, local->iobref, + (xdrproc_t)xdr_gfs3_fgetxattr_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + + return 0; +unwind: + CLIENT_STACK_UNWIND (fgetxattr, frame, -1, op_errno, NULL, NULL); + + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_getxattr (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_getxattr_req req = {{0,},}; + dict_t *dict = NULL; + int ret = 0; + int32_t op_ret = -1; + int op_errno = ESTALE; + int count = 0; + clnt_local_t *local = NULL; + struct iobref *rsp_iobref = NULL; + struct iobuf *rsp_iobuf = NULL; + struct iovec *rsphdr = NULL; + struct iovec vector[MAX_IOVEC] = {{0}, }; + + if (!frame || !this || !data) { + op_errno = 0; + goto unwind; + } + args = data; + + if (!args->loc) { + op_errno = EINVAL; + goto unwind; + } + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + if (args->name) + local->name = gf_strdup (args->name); + + frame->local = local; + + rsp_iobref = iobref_new (); + if (rsp_iobref == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + /* TODO: what is the size we should send ? */ + rsp_iobuf = iobuf_get2 (this->ctx->iobuf_pool, 8 * GF_UNIT_KB); + if (rsp_iobuf == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + iobref_add (rsp_iobref, rsp_iobuf); + iobuf_unref (rsp_iobuf); + + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr (rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + rsp_iobuf = NULL; + rsp_iobref = NULL; + + if (args->loc->inode && !uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.gfid)), + unwind, op_errno, EINVAL); + req.namelen = 1; /* Use it as a flag */ + + req.name = (char *)args->name; + if (!req.name) { + req.name = ""; + req.namelen = 0; + } + + conf = this->private; + + if (args && args->name) { + if (is_client_dump_locks_cmd ((char *)args->name)) { + dict = dict_new (); + ret = client_dump_locks ((char *)args->name, + args->loc->inode, + dict); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, + "Client dump locks failed"); + op_errno = EINVAL; + } + + GF_ASSERT (dict); + op_ret = 0; + op_errno = 0; + goto unwind; + } + } + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_GETXATTR, + client3_3_getxattr_cbk, NULL, + rsphdr, count, + NULL, 0, local->iobref, + (xdrproc_t)xdr_gfs3_getxattr_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + + return 0; +unwind: + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + + CLIENT_STACK_UNWIND (getxattr, frame, op_ret, op_errno, dict, NULL); + + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_xattrop (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_xattrop_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + int count = 0; + clnt_local_t *local = NULL; + struct iobref *rsp_iobref = NULL; + struct iobuf *rsp_iobuf = NULL; + struct iovec *rsphdr = NULL; + struct iovec vector[MAX_IOVEC] = {{0}, }; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + if (!(args->loc && args->loc->inode)) + goto unwind; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + rsp_iobref = iobref_new (); + if (rsp_iobref == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + /* TODO: what is the size we should send ? */ + rsp_iobuf = iobuf_get2 (this->ctx->iobuf_pool, 8 * GF_UNIT_KB); + if (rsp_iobuf == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + iobref_add (rsp_iobref, rsp_iobuf); + iobuf_unref (rsp_iobuf); + + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr (rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + rsp_iobuf = NULL; + rsp_iobref = NULL; + + if (!uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.gfid)), + unwind, op_errno, EINVAL); + if (args->xattr) { + GF_PROTOCOL_DICT_SERIALIZE (this, args->xattr, + (&req.dict.dict_val), + req.dict.dict_len, + op_errno, unwind); + } + + req.flags = args->flags; + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_XATTROP, + client3_3_xattrop_cbk, NULL, + rsphdr, count, + NULL, 0, local->iobref, + (xdrproc_t)xdr_gfs3_xattrop_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.dict.dict_val); + + GF_FREE (req.xdata.xdata_val); + + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + + return 0; +unwind: + CLIENT_STACK_UNWIND (xattrop, frame, -1, op_errno, NULL, NULL); + + GF_FREE (req.dict.dict_val); + + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_fxattrop (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + clnt_local_t *local = NULL; + gfs3_fxattrop_req req = {{0,},}; + int op_errno = ESTALE; + int ret = 0; + int count = 0; + struct iobref *rsp_iobref = NULL; + struct iobuf *rsp_iobuf = NULL; + struct iovec *rsphdr = NULL; + struct iovec vector[MAX_IOVEC] = {{0}, }; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, FALLBACK_TO_ANON_FD, + remote_fd, op_errno, unwind); + ret = client_fd_fop_prepare_local (frame, args->fd, remote_fd); + if (ret) { + op_errno = -ret; + goto unwind; + } + + local = frame->local; + + req.fd = remote_fd; + req.flags = args->flags; + memcpy (req.gfid, args->fd->inode->gfid, 16); + + rsp_iobref = iobref_new (); + if (rsp_iobref == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + /* TODO: what is the size we should send ? */ + rsp_iobuf = iobuf_get2 (this->ctx->iobuf_pool, 8 * GF_UNIT_KB); + if (rsp_iobuf == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + iobref_add (rsp_iobref, rsp_iobuf); + iobuf_unref (rsp_iobuf); + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr (rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + rsp_iobuf = NULL; + rsp_iobref = NULL; + + if (args->xattr) { + GF_PROTOCOL_DICT_SERIALIZE (this, args->xattr, + (&req.dict.dict_val), + req.dict.dict_len, + op_errno, unwind); + } + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FXATTROP, + client3_3_fxattrop_cbk, NULL, + rsphdr, count, + NULL, 0, local->iobref, + (xdrproc_t)xdr_gfs3_fxattrop_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.dict.dict_val); + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (fxattrop, frame, -1, op_errno, NULL, NULL); + + GF_FREE (req.dict.dict_val); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + +int32_t +client3_3_removexattr (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_removexattr_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + if (!(args->loc && args->loc->inode)) + goto unwind; + + if (!uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.gfid)), + unwind, op_errno, EINVAL); + req.name = (char *)args->name; + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_REMOVEXATTR, + client3_3_removexattr_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_removexattr_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (removexattr, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_fremovexattr (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_fremovexattr_req req = {{0,},}; + int ret = 0; + int64_t remote_fd = -1; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + if (!(args->fd && args->fd->inode)) + goto unwind; + + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + memcpy (req.gfid, args->fd->inode->gfid, 16); + req.name = (char *)args->name; + req.fd = remote_fd; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FREMOVEXATTR, + client3_3_fremovexattr_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_fremovexattr_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (fremovexattr, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_lk (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + gfs3_lk_req req = {{0,},}; + int32_t gf_cmd = 0; + int32_t gf_type = 0; + int64_t remote_fd = -1; + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + ret = client_cmd_to_gf_cmd (args->cmd, &gf_cmd); + if (ret) { + op_errno = EINVAL; + gf_log (this->name, GF_LOG_WARNING, + "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; + } + + local->owner = frame->root->lk_owner; + local->cmd = args->cmd; + local->fd = fd_ref (args->fd); + frame->local = local; + + req.fd = remote_fd; + req.cmd = gf_cmd; + req.type = gf_type; + gf_proto_flock_from_flock (&req.flock, args->flock); + + memcpy (req.gfid, args->fd->inode->gfid, 16); + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, GFS3_OP_LK, + client3_3_lk_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfs3_lk_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (lk, frame, -1, op_errno, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + +int32_t +client3_3_inodelk (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + 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 || !data) + goto unwind; + + args = data; + if (!(args->loc && args->loc->inode)) + goto unwind; + + if (!uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.gfid)), + unwind, op_errno, EINVAL); + 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_WARNING, + "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.volume = (char *)args->volume; + req.cmd = gf_cmd; + req.type = gf_type; + gf_proto_flock_from_flock (&req.flock, args->flock); + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_INODELK, + client3_3_inodelk_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_inodelk_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (inodelk, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_finodelk (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + gfs3_finodelk_req req = {{0,},}; + int32_t gf_cmd = 0; + int32_t gf_type = 0; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + CLIENT_GET_REMOTE_FD (this, args->fd, FALLBACK_TO_ANON_FD, + remote_fd, op_errno, unwind); + ret = client_fd_fop_prepare_local (frame, args->fd, remote_fd); + if (ret) { + op_errno = -ret; + 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_WARNING, + "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 = remote_fd; + req.cmd = gf_cmd; + req.type = gf_type; + gf_proto_flock_from_flock (&req.flock, args->flock); + memcpy (req.gfid, args->fd->inode->gfid, 16); + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FINODELK, + client3_3_finodelk_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_finodelk_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + return 0; +unwind: + CLIENT_STACK_UNWIND (finodelk, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + +int32_t +client3_3_entrylk (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_entrylk_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + if (!(args->loc && args->loc->inode)) + goto unwind; + + if (!uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.gfid)), + unwind, op_errno, EINVAL); + 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; + } + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_ENTRYLK, + client3_3_entrylk_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_entrylk_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (entrylk, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_fentrylk (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + gfs3_fentrylk_req req = {{0,},}; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + req.fd = 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; + } + memcpy (req.gfid, args->fd->inode->gfid, 16); + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FENTRYLK, + client3_3_fentrylk_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_fentrylk_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (fentrylk, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + +int32_t +client3_3_rchecksum (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + gfs3_rchecksum_req req = {0,}; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + req.len = args->len; + req.offset = args->offset; + req.fd = remote_fd; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_RCHECKSUM, + client3_3_rchecksum_cbk, NULL, + NULL, 0, NULL, + 0, NULL, + (xdrproc_t)xdr_gfs3_rchecksum_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (rchecksum, frame, -1, op_errno, 0, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + + +int32_t +client3_3_readdir (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + gfs3_readdir_req req = {{0,},}; + gfs3_readdir_rsp rsp = {0, }; + clnt_local_t *local = NULL; + int op_errno = ESTALE; + int ret = 0; + int count = 0; + struct iobref *rsp_iobref = NULL; + struct iobuf *rsp_iobuf = NULL; + struct iovec *rsphdr = NULL; + struct iovec vector[MAX_IOVEC] = {{0}, }; + int readdir_rsp_size = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + readdir_rsp_size = xdr_sizeof ((xdrproc_t) xdr_gfs3_readdir_rsp, &rsp) + + args->size; + + if ((readdir_rsp_size + GLUSTERFS_RPC_REPLY_SIZE + GLUSTERFS_RDMA_MAX_HEADER_SIZE) + > (GLUSTERFS_RDMA_INLINE_THRESHOLD)) { + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + rsp_iobref = iobref_new (); + if (rsp_iobref == NULL) { + goto unwind; + } + + /* TODO: what is the size we should send ? */ + /* This iobuf will live for only receiving the response, + so not harmful */ + rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); + if (rsp_iobuf == NULL) { + goto unwind; + } + + iobref_add (rsp_iobref, rsp_iobuf); + iobuf_unref (rsp_iobuf); + + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr (rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + rsp_iobuf = NULL; + rsp_iobref = NULL; + } + + req.size = args->size; + req.offset = args->offset; + req.fd = remote_fd; + + local->cmd = remote_fd; + + memcpy (req.gfid, args->fd->inode->gfid, 16); + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_READDIR, + client3_3_readdir_cbk, NULL, + rsphdr, count, + NULL, 0, rsp_iobref, + (xdrproc_t)xdr_gfs3_readdir_req); + + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + + return 0; + +unwind: + if (rsp_iobref) + iobref_unref (rsp_iobref); + + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + CLIENT_STACK_UNWIND (readdir, frame, -1, op_errno, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + + +int32_t +client3_3_readdirp (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + gfs3_readdirp_req req = {{0,},}; + gfs3_readdirp_rsp rsp = {0,}; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + int op_errno = ESTALE; + int ret = 0; + int count = 0; + int readdirp_rsp_size = 0; + struct iobref *rsp_iobref = NULL; + struct iobuf *rsp_iobuf = NULL; + struct iovec *rsphdr = NULL; + struct iovec vector[MAX_IOVEC] = {{0}, }; + clnt_local_t *local = NULL; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + readdirp_rsp_size = xdr_sizeof ((xdrproc_t) xdr_gfs3_readdirp_rsp, &rsp) + + args->size; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + if ((readdirp_rsp_size + GLUSTERFS_RPC_REPLY_SIZE + + GLUSTERFS_RDMA_MAX_HEADER_SIZE) + > (GLUSTERFS_RDMA_INLINE_THRESHOLD)) { + rsp_iobref = iobref_new (); + if (rsp_iobref == NULL) { + goto unwind; + } + + /* TODO: what is the size we should send ? */ + /* This iobuf will live for only receiving the response, + so not harmful */ + rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); + if (rsp_iobuf == NULL) { + goto unwind; + } + + iobref_add (rsp_iobref, rsp_iobuf); + iobuf_unref (rsp_iobuf); + + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr (rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + rsp_iobuf = NULL; + rsp_iobref = NULL; + } + + local->fd = fd_ref (args->fd); + + req.size = args->size; + req.offset = args->offset; + req.fd = remote_fd; + memcpy (req.gfid, args->fd->inode->gfid, 16); + + /* dict itself is 'xdata' here */ + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.dict.dict_val), + req.dict.dict_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_READDIRP, + client3_3_readdirp_cbk, NULL, + rsphdr, count, NULL, + 0, rsp_iobref, + (xdrproc_t)xdr_gfs3_readdirp_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.dict.dict_val); + + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + + return 0; +unwind: + if (rsp_iobref) + iobref_unref (rsp_iobref); + + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + GF_FREE (req.dict.dict_val); + + CLIENT_STACK_UNWIND (readdirp, frame, -1, op_errno, NULL, NULL); + return 0; +} + + +int32_t +client3_3_setattr (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfs3_setattr_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + if (!(args->loc && args->loc->inode)) + goto unwind; + + if (!uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !uuid_is_null (*((uuid_t*)req.gfid)), + unwind, op_errno, EINVAL); + req.valid = args->valid; + gf_stat_from_iatt (&req.stbuf, args->stbuf); + + conf = this->private; + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_SETATTR, + client3_3_setattr_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_setattr_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (setattr, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_fsetattr (call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + gfs3_fsetattr_req req = {0,}; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + req.fd = remote_fd; + req.valid = args->valid; + gf_stat_from_iatt (&req.stbuf, args->stbuf); + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FSETATTR, + client3_3_fsetattr_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_fsetattr_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (fsetattr, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_fallocate(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + gfs3_fallocate_req req = {{0},}; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + req.fd = remote_fd; + req.flags = args->flags; + req.offset = args->offset; + req.size = args->size; + memcpy(req.gfid, args->fd->inode->gfid, 16); + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FALLOCATE, + client3_3_fallocate_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfs3_fallocate_req); + if (ret) { + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + } + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (fallocate, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_discard(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + gfs3_discard_req req = {{0},}; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + req.fd = remote_fd; + req.offset = args->offset; + req.size = args->size; + memcpy(req.gfid, args->fd->inode->gfid, 16); + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request(this, &req, frame, conf->fops, + GFS3_OP_DISCARD, client3_3_discard_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t) xdr_gfs3_discard_req); + if (ret) + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(discard, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + +int32_t +client3_3_zerofill(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + gfs3_zerofill_req req = {{0},}; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD (this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + req.fd = remote_fd; + req.offset = args->offset; + req.size = args->size; + memcpy(req.gfid, args->fd->inode->gfid, 16); + + GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), + req.xdata.xdata_len, op_errno, unwind); + + ret = client_submit_request(this, &req, frame, conf->fops, + GFS3_OP_ZEROFILL, client3_3_zerofill_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t) xdr_gfs3_zerofill_req); + if (ret) + gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); + + GF_FREE (req.xdata.xdata_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(zerofill, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.xdata_val); + + return 0; +} + +/* Table Specific to FOPS */ + + +rpc_clnt_procedure_t clnt3_3_fop_actors[GF_FOP_MAXVALUE] = { + [GF_FOP_NULL] = { "NULL", NULL}, + [GF_FOP_STAT] = { "STAT", client3_3_stat }, + [GF_FOP_READLINK] = { "READLINK", client3_3_readlink }, + [GF_FOP_MKNOD] = { "MKNOD", client3_3_mknod }, + [GF_FOP_MKDIR] = { "MKDIR", client3_3_mkdir }, + [GF_FOP_UNLINK] = { "UNLINK", client3_3_unlink }, + [GF_FOP_RMDIR] = { "RMDIR", client3_3_rmdir }, + [GF_FOP_SYMLINK] = { "SYMLINK", client3_3_symlink }, + [GF_FOP_RENAME] = { "RENAME", client3_3_rename }, + [GF_FOP_LINK] = { "LINK", client3_3_link }, + [GF_FOP_TRUNCATE] = { "TRUNCATE", client3_3_truncate }, + [GF_FOP_OPEN] = { "OPEN", client3_3_open }, + [GF_FOP_READ] = { "READ", client3_3_readv }, + [GF_FOP_WRITE] = { "WRITE", client3_3_writev }, + [GF_FOP_STATFS] = { "STATFS", client3_3_statfs }, + [GF_FOP_FLUSH] = { "FLUSH", client3_3_flush }, + [GF_FOP_FSYNC] = { "FSYNC", client3_3_fsync }, + [GF_FOP_SETXATTR] = { "SETXATTR", client3_3_setxattr }, + [GF_FOP_GETXATTR] = { "GETXATTR", client3_3_getxattr }, + [GF_FOP_REMOVEXATTR] = { "REMOVEXATTR", client3_3_removexattr }, + [GF_FOP_OPENDIR] = { "OPENDIR", client3_3_opendir }, + [GF_FOP_FSYNCDIR] = { "FSYNCDIR", client3_3_fsyncdir }, + [GF_FOP_ACCESS] = { "ACCESS", client3_3_access }, + [GF_FOP_CREATE] = { "CREATE", client3_3_create }, + [GF_FOP_FTRUNCATE] = { "FTRUNCATE", client3_3_ftruncate }, + [GF_FOP_FSTAT] = { "FSTAT", client3_3_fstat }, + [GF_FOP_LK] = { "LK", client3_3_lk }, + [GF_FOP_LOOKUP] = { "LOOKUP", client3_3_lookup }, + [GF_FOP_READDIR] = { "READDIR", client3_3_readdir }, + [GF_FOP_INODELK] = { "INODELK", client3_3_inodelk }, + [GF_FOP_FINODELK] = { "FINODELK", client3_3_finodelk }, + [GF_FOP_ENTRYLK] = { "ENTRYLK", client3_3_entrylk }, + [GF_FOP_FENTRYLK] = { "FENTRYLK", client3_3_fentrylk }, + [GF_FOP_XATTROP] = { "XATTROP", client3_3_xattrop }, + [GF_FOP_FXATTROP] = { "FXATTROP", client3_3_fxattrop }, + [GF_FOP_FGETXATTR] = { "FGETXATTR", client3_3_fgetxattr }, + [GF_FOP_FSETXATTR] = { "FSETXATTR", client3_3_fsetxattr }, + [GF_FOP_RCHECKSUM] = { "RCHECKSUM", client3_3_rchecksum }, + [GF_FOP_SETATTR] = { "SETATTR", client3_3_setattr }, + [GF_FOP_FSETATTR] = { "FSETATTR", client3_3_fsetattr }, + [GF_FOP_READDIRP] = { "READDIRP", client3_3_readdirp }, + [GF_FOP_FALLOCATE] = { "FALLOCATE", client3_3_fallocate }, + [GF_FOP_DISCARD] = { "DISCARD", client3_3_discard }, + [GF_FOP_ZEROFILL] = { "ZEROFILL", client3_3_zerofill}, + [GF_FOP_RELEASE] = { "RELEASE", client3_3_release }, + [GF_FOP_RELEASEDIR] = { "RELEASEDIR", client3_3_releasedir }, + [GF_FOP_GETSPEC] = { "GETSPEC", client3_getspec }, + [GF_FOP_FREMOVEXATTR] = { "FREMOVEXATTR", client3_3_fremovexattr }, +}; + +/* Used From RPC-CLNT library to log proper name of procedure based on number */ +char *clnt3_3_fop_names[GFS3_OP_MAXVALUE] = { + [GFS3_OP_NULL] = "NULL", + [GFS3_OP_STAT] = "STAT", + [GFS3_OP_READLINK] = "READLINK", + [GFS3_OP_MKNOD] = "MKNOD", + [GFS3_OP_MKDIR] = "MKDIR", + [GFS3_OP_UNLINK] = "UNLINK", + [GFS3_OP_RMDIR] = "RMDIR", + [GFS3_OP_SYMLINK] = "SYMLINK", + [GFS3_OP_RENAME] = "RENAME", + [GFS3_OP_LINK] = "LINK", + [GFS3_OP_TRUNCATE] = "TRUNCATE", + [GFS3_OP_OPEN] = "OPEN", + [GFS3_OP_READ] = "READ", + [GFS3_OP_WRITE] = "WRITE", + [GFS3_OP_STATFS] = "STATFS", + [GFS3_OP_FLUSH] = "FLUSH", + [GFS3_OP_FSYNC] = "FSYNC", + [GFS3_OP_SETXATTR] = "SETXATTR", + [GFS3_OP_GETXATTR] = "GETXATTR", + [GFS3_OP_REMOVEXATTR] = "REMOVEXATTR", + [GFS3_OP_OPENDIR] = "OPENDIR", + [GFS3_OP_FSYNCDIR] = "FSYNCDIR", + [GFS3_OP_ACCESS] = "ACCESS", + [GFS3_OP_CREATE] = "CREATE", + [GFS3_OP_FTRUNCATE] = "FTRUNCATE", + [GFS3_OP_FSTAT] = "FSTAT", + [GFS3_OP_LK] = "LK", + [GFS3_OP_LOOKUP] = "LOOKUP", + [GFS3_OP_READDIR] = "READDIR", + [GFS3_OP_INODELK] = "INODELK", + [GFS3_OP_FINODELK] = "FINODELK", + [GFS3_OP_ENTRYLK] = "ENTRYLK", + [GFS3_OP_FENTRYLK] = "FENTRYLK", + [GFS3_OP_XATTROP] = "XATTROP", + [GFS3_OP_FXATTROP] = "FXATTROP", + [GFS3_OP_FGETXATTR] = "FGETXATTR", + [GFS3_OP_FSETXATTR] = "FSETXATTR", + [GFS3_OP_RCHECKSUM] = "RCHECKSUM", + [GFS3_OP_SETATTR] = "SETATTR", + [GFS3_OP_FSETATTR] = "FSETATTR", + [GFS3_OP_READDIRP] = "READDIRP", + [GFS3_OP_RELEASE] = "RELEASE", + [GFS3_OP_RELEASEDIR] = "RELEASEDIR", + [GFS3_OP_FREMOVEXATTR] = "FREMOVEXATTR", + [GFS3_OP_FALLOCATE] = "FALLOCATE", + [GFS3_OP_DISCARD] = "DISCARD", + [GFS3_OP_ZEROFILL] = "ZEROFILL", + +}; + +rpc_clnt_prog_t clnt3_3_fop_prog = { + .progname = "GlusterFS 3.3", + .prognum = GLUSTER_FOP_PROGRAM, + .progver = GLUSTER_FOP_VERSION, + .numproc = GLUSTER_FOP_PROCCNT, + .proctable = clnt3_3_fop_actors, + .procnames = clnt3_3_fop_names, +}; diff --git a/xlators/protocol/client/src/client.c b/xlators/protocol/client/src/client.c index ff766844d..1f7d13ea4 100644 --- a/xlators/protocol/client/src/client.c +++ b/xlators/protocol/client/src/client.c @@ -1,20 +1,11 @@ /* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.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 Affero 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 - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. */ @@ -40,22 +31,134 @@ int client_handshake (xlator_t *this, struct rpc_clnt *rpc); void client_start_ping (void *data); int client_init_rpc (xlator_t *this); int client_destroy_rpc (xlator_t *this); +int client_mark_fd_bad (xlator_t *this); + +int32_t +client_type_to_gf_type (short l_type) +{ + int32_t gf_type = GF_LK_EOL; + + switch (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; + } + + return gf_type; +} + +uint32_t +client_get_lk_ver (clnt_conf_t *conf) +{ + uint32_t lk_ver = 0; + + GF_VALIDATE_OR_GOTO ("client", conf, out); + + pthread_mutex_lock (&conf->lock); + { + lk_ver = conf->lk_version; + } + pthread_mutex_unlock (&conf->lock); +out: + return lk_ver; +} + +void +client_grace_timeout (void *data) +{ + int ver = 0; + xlator_t *this = NULL; + struct clnt_conf *conf = NULL; + struct rpc_clnt *rpc = NULL; + + GF_VALIDATE_OR_GOTO ("client", data, out); + + this = THIS; + + rpc = (struct rpc_clnt *) data; + + conf = (struct clnt_conf *) this->private; + + pthread_mutex_lock (&conf->lock); + { + ver = ++conf->lk_version; + /* ver == 0 is a special value used by server + to notify client that this is a fresh connect.*/ + if (ver == 0) + ver = ++conf->lk_version; + + gf_timer_call_cancel (this->ctx, conf->grace_timer); + conf->grace_timer = NULL; + } + pthread_mutex_unlock (&conf->lock); + + gf_log (this->name, GF_LOG_WARNING, + "client grace timer expired, updating " + "the lk-version to %d", ver); + + client_mark_fd_bad (this); +out: + return; +} + +int32_t +client_register_grace_timer (xlator_t *this, clnt_conf_t *conf) +{ + int32_t ret = -1; + + GF_VALIDATE_OR_GOTO ("client", this, out); + GF_VALIDATE_OR_GOTO (this->name, conf, out); + + pthread_mutex_lock (&conf->lock); + { + if (conf->grace_timer || !conf->grace_timer_needed) { + gf_log (this->name, GF_LOG_TRACE, + "Client grace timer is already set " + "or a grace-timer has already time out, " + "not registering a new timer"); + } else { + gf_log (this->name, GF_LOG_INFO, + "Registering a grace timer"); + + conf->grace_timer_needed = _gf_false; + + conf->grace_timer = + gf_timer_call_after (this->ctx, + conf->grace_ts, + client_grace_timeout, + conf->rpc); + } + } + pthread_mutex_unlock (&conf->lock); + + ret = 0; +out: + return ret; +} int client_submit_request (xlator_t *this, void *req, call_frame_t *frame, - rpc_clnt_prog_t *prog, int procnum, fop_cbk_fn_t cbk, - struct iobref *iobref, gfs_serialize_t sfunc, - struct iovec *rsphdr, int rsphdr_count, - struct iovec *rsp_payload, int rsp_payload_count, - struct iobref *rsp_iobref) -{ - int ret = -1; - clnt_conf_t *conf = NULL; - struct iovec iov = {0, }; - struct iobuf *iobuf = NULL; - int count = 0; - char start_ping = 0; - struct iobref *new_iobref = NULL; + rpc_clnt_prog_t *prog, int procnum, fop_cbk_fn_t cbkfn, + struct iobref *iobref, struct iovec *rsphdr, + int rsphdr_count, struct iovec *rsp_payload, + int rsp_payload_count, struct iobref *rsp_iobref, + xdrproc_t xdrproc) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + struct iovec iov = {0, }; + struct iobuf *iobuf = NULL; + int count = 0; + char start_ping = 0; + struct iobref *new_iobref = NULL; + ssize_t xdr_size = 0; + struct rpc_req rpcreq = {0, }; GF_VALIDATE_OR_GOTO ("client", this, out); GF_VALIDATE_OR_GOTO (this->name, prog, out); @@ -78,38 +181,39 @@ client_submit_request (xlator_t *this, void *req, call_frame_t *frame, goto out; } - iobuf = iobuf_get (this->ctx->iobuf_pool); - if (!iobuf) { - goto out; - }; + if (req && xdrproc) { + xdr_size = xdr_sizeof (xdrproc, req); + iobuf = iobuf_get2 (this->ctx->iobuf_pool, xdr_size); + if (!iobuf) { + goto out; + }; - new_iobref = iobref_new (); - if (!new_iobref) { - goto out; - } + new_iobref = iobref_new (); + if (!new_iobref) { + goto out; + } - if (iobref != NULL) { - ret = iobref_merge (new_iobref, iobref); + if (iobref != NULL) { + ret = iobref_merge (new_iobref, iobref); + if (ret != 0) { + gf_log (this->name, GF_LOG_WARNING, + "cannot merge iobref passed from caller " + "into new_iobref"); + } + } + + ret = iobref_add (new_iobref, iobuf); if (ret != 0) { gf_log (this->name, GF_LOG_WARNING, - "cannot merge iobref passed from caller " - "into new_iobref"); + "cannot add iobuf into iobref"); + goto out; } - } - - ret = iobref_add (new_iobref, iobuf); - if (ret != 0) { - gf_log (this->name, GF_LOG_WARNING, - "cannot add iobuf into iobref"); - goto out; - } - iov.iov_base = iobuf->ptr; - iov.iov_len = 128 * GF_UNIT_KB; + iov.iov_base = iobuf->ptr; + iov.iov_len = iobuf_size (iobuf); - /* Create the xdr payload */ - if (req && sfunc) { - ret = sfunc (iov, req); + /* Create the xdr payload */ + ret = xdr_serialize_generic (iov, req, xdrproc); if (ret == -1) { /* callingfn so that, we can get to know which xdr function was called */ @@ -120,9 +224,10 @@ client_submit_request (xlator_t *this, void *req, call_frame_t *frame, iov.iov_len = ret; count = 1; } + /* Send the msg */ - ret = rpc_clnt_submit (conf->rpc, prog, procnum, cbk, &iov, count, NULL, - 0, new_iobref, frame, rsphdr, rsphdr_count, + ret = rpc_clnt_submit (conf->rpc, prog, procnum, cbkfn, &iov, count, + NULL, 0, new_iobref, frame, rsphdr, rsphdr_count, rsp_payload, rsp_payload_count, rsp_iobref); if (ret < 0) { @@ -143,14 +248,27 @@ client_submit_request (xlator_t *this, void *req, call_frame_t *frame, client_start_ping ((void *) this); ret = 0; -out: - if (new_iobref != NULL) + + if (new_iobref) iobref_unref (new_iobref); if (iobuf) iobuf_unref (iobuf); return ret; + +out: + rpcreq.rpc_status = -1; + + cbkfn (&rpcreq, NULL, 0, frame); + + if (new_iobref) + iobref_unref (new_iobref); + + if (iobuf) + iobuf_unref (iobuf); + + return 0; } @@ -168,7 +286,6 @@ client_releasedir (xlator_t *this, fd_t *fd) 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 || !conf->fops) @@ -184,11 +301,7 @@ client_releasedir (xlator_t *this, fd_t *fd) goto out; } if (proc->fn) { - frame = create_frame (this, this->ctx->pool); - if (!frame) { - goto out; - } - ret = proc->fn (frame, this, &args); + ret = proc->fn (NULL, this, &args); } out: if (ret) @@ -204,7 +317,6 @@ client_release (xlator_t *this, fd_t *fd) 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 || !conf->fops) @@ -219,11 +331,7 @@ client_release (xlator_t *this, fd_t *fd) goto out; } if (proc->fn) { - frame = create_frame (this, this->ctx->pool); - if (!frame) { - goto out; - } - ret = proc->fn (frame, this, &args); + ret = proc->fn (NULL, this, &args); } out: if (ret) @@ -235,7 +343,7 @@ out: int32_t client_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, - dict_t *xattr_req) + dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -247,7 +355,7 @@ client_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, goto out; args.loc = loc; - args.dict = xattr_req; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_LOOKUP]; if (!proc) { @@ -269,7 +377,7 @@ out: int32_t -client_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) +client_stat (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -281,6 +389,7 @@ client_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) goto out; args.loc = loc; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_STAT]; if (!proc) { @@ -293,14 +402,15 @@ client_stat (call_frame_t *frame, xlator_t *this, loc_t *loc) ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (stat, frame, -1, ENOTCONN, NULL); + STACK_UNWIND_STRICT (stat, frame, -1, ENOTCONN, NULL, NULL); return 0; } int32_t -client_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset) +client_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, + off_t offset, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -313,6 +423,7 @@ client_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset) args.loc = loc; args.offset = offset; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_TRUNCATE]; if (!proc) { @@ -325,7 +436,7 @@ client_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset) ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (truncate, frame, -1, ENOTCONN, NULL, NULL); + STACK_UNWIND_STRICT (truncate, frame, -1, ENOTCONN, NULL, NULL, NULL); return 0; @@ -333,7 +444,8 @@ out: int32_t -client_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset) +client_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, + off_t offset, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -346,6 +458,7 @@ client_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset) args.fd = fd; args.offset = offset; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_FTRUNCATE]; if (!proc) { @@ -358,7 +471,7 @@ client_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset) ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (ftruncate, frame, -1, ENOTCONN, NULL, NULL); + STACK_UNWIND_STRICT (ftruncate, frame, -1, ENOTCONN, NULL, NULL, NULL); return 0; } @@ -366,7 +479,8 @@ out: int32_t -client_access (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask) +client_access (call_frame_t *frame, xlator_t *this, loc_t *loc, + int32_t mask, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -379,6 +493,7 @@ client_access (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask) args.loc = loc; args.mask = mask; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_ACCESS]; if (!proc) { @@ -391,7 +506,7 @@ client_access (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t mask) ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (access, frame, -1, ENOTCONN); + STACK_UNWIND_STRICT (access, frame, -1, ENOTCONN, NULL); return 0; } @@ -400,7 +515,8 @@ out: int32_t -client_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size) +client_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, + size_t size, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -413,6 +529,7 @@ client_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size) args.loc = loc; args.size = size; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_READLINK]; if (!proc) { @@ -425,7 +542,7 @@ client_readlink (call_frame_t *frame, xlator_t *this, loc_t *loc, size_t size) ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (readlink, frame, -1, ENOTCONN, NULL, NULL); + STACK_UNWIND_STRICT (readlink, frame, -1, ENOTCONN, NULL, NULL, NULL); return 0; } @@ -433,7 +550,7 @@ out: int client_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, - dev_t rdev, dict_t *params) + dev_t rdev, mode_t umask, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -447,7 +564,8 @@ client_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, args.loc = loc; args.mode = mode; args.rdev = rdev; - args.dict = params; + args.umask = umask; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_MKNOD]; if (!proc) { @@ -461,7 +579,7 @@ client_mknod (call_frame_t *frame, xlator_t *this, loc_t *loc, mode_t mode, out: if (ret) STACK_UNWIND_STRICT (mknod, frame, -1, ENOTCONN, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); return 0; } @@ -469,7 +587,7 @@ out: int client_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, - mode_t mode, dict_t *params) + mode_t mode, mode_t umask, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -482,7 +600,8 @@ client_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, args.loc = loc; args.mode = mode; - args.dict = params; + args.umask = umask; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_MKDIR]; if (!proc) { @@ -496,7 +615,7 @@ client_mkdir (call_frame_t *frame, xlator_t *this, loc_t *loc, out: if (ret) STACK_UNWIND_STRICT (mkdir, frame, -1, ENOTCONN, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); return 0; } @@ -504,7 +623,8 @@ out: int32_t -client_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) +client_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc, + int xflag, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -516,6 +636,8 @@ client_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) goto out; args.loc = loc; + args.xdata = xdata; + args.flags = xflag; proc = &conf->fops->proctable[GF_FOP_UNLINK]; if (!proc) { @@ -529,13 +651,14 @@ client_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc) out: if (ret) STACK_UNWIND_STRICT (unlink, frame, -1, ENOTCONN, - NULL, NULL); + NULL, NULL, NULL); return 0; } int32_t -client_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags) +client_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags, + dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -548,6 +671,7 @@ client_rmdir (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags) args.loc = loc; args.flags = flags; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_RMDIR]; if (!proc) { @@ -562,7 +686,7 @@ out: /* think of avoiding a missing frame */ if (ret) STACK_UNWIND_STRICT (rmdir, frame, -1, ENOTCONN, - NULL, NULL); + NULL, NULL, NULL); return 0; } @@ -570,7 +694,7 @@ out: int client_symlink (call_frame_t *frame, xlator_t *this, const char *linkpath, - loc_t *loc, dict_t *params) + loc_t *loc, mode_t umask, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -583,7 +707,8 @@ client_symlink (call_frame_t *frame, xlator_t *this, const char *linkpath, args.linkname = linkpath; args.loc = loc; - args.dict = params; + args.umask = umask; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_SYMLINK]; if (!proc) { @@ -597,7 +722,7 @@ client_symlink (call_frame_t *frame, xlator_t *this, const char *linkpath, out: if (ret) STACK_UNWIND_STRICT (symlink, frame, -1, ENOTCONN, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); return 0; } @@ -606,7 +731,7 @@ out: int32_t client_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, - loc_t *newloc) + loc_t *newloc, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -619,6 +744,8 @@ client_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, args.oldloc = oldloc; args.newloc = newloc; + args.xdata = xdata; + proc = &conf->fops->proctable[GF_FOP_RENAME]; if (!proc) { gf_log (this->name, GF_LOG_ERROR, @@ -631,7 +758,7 @@ client_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc, out: if (ret) STACK_UNWIND_STRICT (rename, frame, -1, ENOTCONN, - NULL, NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL, NULL); return 0; } @@ -640,7 +767,7 @@ out: int32_t client_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, - loc_t *newloc) + loc_t *newloc, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -653,6 +780,7 @@ client_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, args.oldloc = oldloc; args.newloc = newloc; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_LINK]; if (!proc) { @@ -666,7 +794,7 @@ client_link (call_frame_t *frame, xlator_t *this, loc_t *oldloc, out: if (ret) STACK_UNWIND_STRICT (link, frame, -1, ENOTCONN, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); return 0; } @@ -674,8 +802,8 @@ out: int32_t -client_create (call_frame_t *frame, xlator_t *this, loc_t *loc, - int32_t flags, mode_t mode, fd_t *fd, dict_t *params) +client_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, + mode_t mode, mode_t umask, fd_t *fd, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -687,10 +815,15 @@ client_create (call_frame_t *frame, xlator_t *this, loc_t *loc, goto out; args.loc = loc; - args.flags = flags; args.mode = mode; args.fd = fd; - args.dict = params; + args.umask = umask; + args.xdata = xdata; + + if (!conf->filter_o_direct) + args.flags = flags; + else + args.flags = (flags & ~O_DIRECT); proc = &conf->fops->proctable[GF_FOP_CREATE]; if (!proc) { @@ -704,7 +837,7 @@ client_create (call_frame_t *frame, xlator_t *this, loc_t *loc, out: if (ret) STACK_UNWIND_STRICT (create, frame, -1, ENOTCONN, - NULL, NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL, NULL); return 0; } @@ -713,7 +846,7 @@ out: int32_t client_open (call_frame_t *frame, xlator_t *this, loc_t *loc, - int32_t flags, fd_t *fd, int32_t wbflags) + int32_t flags, fd_t *fd, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -725,9 +858,13 @@ client_open (call_frame_t *frame, xlator_t *this, loc_t *loc, goto out; args.loc = loc; - args.flags = flags; args.fd = fd; - args.wbflags = wbflags; + args.xdata = xdata; + + if (!conf->filter_o_direct) + args.flags = flags; + else + args.flags = (flags & ~O_DIRECT); proc = &conf->fops->proctable[GF_FOP_OPEN]; if (!proc) { @@ -741,7 +878,7 @@ client_open (call_frame_t *frame, xlator_t *this, loc_t *loc, out: if (ret) - STACK_UNWIND_STRICT (open, frame, -1, ENOTCONN, NULL); + STACK_UNWIND_STRICT (open, frame, -1, ENOTCONN, NULL, NULL); return 0; } @@ -750,7 +887,7 @@ out: int32_t client_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, - off_t offset) + off_t offset, uint32_t flags, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -764,6 +901,8 @@ client_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, args.fd = fd; args.size = size; args.offset = offset; + args.flags = flags; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_READ]; if (!proc) { @@ -778,7 +917,7 @@ client_readv (call_frame_t *frame, xlator_t *this, fd_t *fd, size_t size, out: if (ret) STACK_UNWIND_STRICT (readv, frame, -1, ENOTCONN, - NULL, 0, NULL, NULL); + NULL, 0, NULL, NULL, NULL); return 0; } @@ -789,7 +928,7 @@ out: 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) + uint32_t flags, struct iobref *iobref, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -804,7 +943,9 @@ client_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, args.vector = vector; args.count = count; args.offset = off; + args.flags = flags; args.iobref = iobref; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_WRITE]; if (!proc) { @@ -817,15 +958,14 @@ client_writev (call_frame_t *frame, xlator_t *this, fd_t *fd, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (writev, frame, -1, ENOTCONN, NULL, NULL); + STACK_UNWIND_STRICT (writev, frame, -1, ENOTCONN, NULL, NULL, NULL); return 0; } - int32_t -client_flush (call_frame_t *frame, xlator_t *this, fd_t *fd) +client_flush (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -837,6 +977,7 @@ client_flush (call_frame_t *frame, xlator_t *this, fd_t *fd) goto out; args.fd = fd; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_FLUSH]; if (!proc) { @@ -849,7 +990,7 @@ client_flush (call_frame_t *frame, xlator_t *this, fd_t *fd) ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (flush, frame, -1, ENOTCONN); + STACK_UNWIND_STRICT (flush, frame, -1, ENOTCONN, NULL); return 0; } @@ -858,7 +999,7 @@ out: int32_t client_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, - int32_t flags) + int32_t flags, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -871,6 +1012,7 @@ client_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, args.fd = fd; args.flags = flags; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_FSYNC]; if (!proc) { @@ -883,7 +1025,7 @@ client_fsync (call_frame_t *frame, xlator_t *this, fd_t *fd, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (fsync, frame, -1, ENOTCONN, NULL, NULL); + STACK_UNWIND_STRICT (fsync, frame, -1, ENOTCONN, NULL, NULL, NULL); return 0; } @@ -891,7 +1033,7 @@ out: int32_t -client_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd) +client_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -903,6 +1045,7 @@ client_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd) goto out; args.fd = fd; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_FSTAT]; if (!proc) { @@ -915,7 +1058,7 @@ client_fstat (call_frame_t *frame, xlator_t *this, fd_t *fd) ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (fstat, frame, -1, ENOTCONN, NULL); + STACK_UNWIND_STRICT (fstat, frame, -1, ENOTCONN, NULL, NULL); return 0; } @@ -923,7 +1066,8 @@ out: int32_t -client_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd) +client_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd, + dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -936,6 +1080,7 @@ client_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd) args.loc = loc; args.fd = fd; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_OPENDIR]; if (!proc) { @@ -948,7 +1093,7 @@ client_opendir (call_frame_t *frame, xlator_t *this, loc_t *loc, fd_t *fd) ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (opendir, frame, -1, ENOTCONN, NULL); + STACK_UNWIND_STRICT (opendir, frame, -1, ENOTCONN, NULL, NULL); return 0; } @@ -956,7 +1101,7 @@ out: int32_t -client_fsyncdir (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags) +client_fsyncdir (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -969,6 +1114,7 @@ client_fsyncdir (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags) args.fd = fd; args.flags = flags; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_FSYNCDIR]; if (!proc) { @@ -981,7 +1127,7 @@ client_fsyncdir (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t flags) ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (fsyncdir, frame, -1, ENOTCONN); + STACK_UNWIND_STRICT (fsyncdir, frame, -1, ENOTCONN, NULL); return 0; } @@ -989,7 +1135,7 @@ out: int32_t -client_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc) +client_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1001,6 +1147,7 @@ client_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc) goto out; args.loc = loc; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_STATFS]; if (!proc) { @@ -1013,7 +1160,7 @@ client_statfs (call_frame_t *frame, xlator_t *this, loc_t *loc) ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (statfs, frame, -1, ENOTCONN, NULL); + STACK_UNWIND_STRICT (statfs, frame, -1, ENOTCONN, NULL, NULL); return 0; } @@ -1072,7 +1219,6 @@ out: static gf_boolean_t client_set_remote_options (char *value, xlator_t *this) { - clnt_conf_t *conf = NULL; char *dup_value = NULL; char *host = NULL; char *subvol = NULL; @@ -1083,8 +1229,6 @@ client_set_remote_options (char *value, xlator_t *this) int remote_port = 0; gf_boolean_t ret = _gf_false; - conf = this->private; - dup_value = gf_strdup (value); host = strtok_r (dup_value, ":", &tmp); subvol = strtok_r (NULL, ":", &tmp); @@ -1133,8 +1277,7 @@ client_set_remote_options (char *value, xlator_t *this) ret = _gf_true; out: - if (dup_value) - GF_FREE (dup_value); + GF_FREE (dup_value); return ret; } @@ -1142,7 +1285,7 @@ out: int32_t client_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, - int32_t flags) + int32_t flags, dict_t *xdata) { int ret = -1; int op_ret = -1; @@ -1158,8 +1301,10 @@ client_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, GF_ASSERT (value); gf_log (this->name, GF_LOG_INFO, "client rpc init command"); ret = client_set_remote_options (value, this); - if (ret) + if (ret) { + (void) client_destroy_rpc (this); ret = client_init_rpc (this); + } if (!ret) { op_ret = 0; @@ -1188,8 +1333,9 @@ client_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, } args.loc = loc; - args.dict = dict; + args.xattr = dict; args.flags = flags; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_SETXATTR]; if (!proc) { @@ -1206,7 +1352,7 @@ client_setxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *dict, } out: if (need_unwind) - STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno); + STACK_UNWIND_STRICT (setxattr, frame, op_ret, op_errno, NULL); return 0; } @@ -1215,7 +1361,7 @@ out: int32_t client_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, - dict_t *dict, int32_t flags) + dict_t *dict, int32_t flags, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1226,9 +1372,10 @@ client_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, if (!conf || !conf->fops) goto out; - args.fd = fd; - args.dict = dict; + args.fd = fd; + args.xattr = dict; args.flags = flags; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_FSETXATTR]; if (!proc) { @@ -1241,7 +1388,7 @@ client_fsetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (fsetxattr, frame, -1, ENOTCONN); + STACK_UNWIND_STRICT (fsetxattr, frame, -1, ENOTCONN, NULL); return 0; } @@ -1251,7 +1398,7 @@ out: int32_t client_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, - const char *name) + const char *name, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1264,6 +1411,7 @@ client_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, args.fd = fd; args.name = name; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_FGETXATTR]; if (!proc) { @@ -1276,7 +1424,7 @@ client_fgetxattr (call_frame_t *frame, xlator_t *this, fd_t *fd, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (fgetxattr, frame, -1, ENOTCONN, NULL); + STACK_UNWIND_STRICT (fgetxattr, frame, -1, ENOTCONN, NULL, NULL); return 0; } @@ -1285,7 +1433,7 @@ out: int32_t client_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - const char *name) + const char *name, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1298,6 +1446,7 @@ client_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, args.name = name; args.loc = loc; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_GETXATTR]; if (!proc) { @@ -1310,7 +1459,7 @@ client_getxattr (call_frame_t *frame, xlator_t *this, loc_t *loc, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (getxattr, frame, -1, ENOTCONN, NULL); + STACK_UNWIND_STRICT (getxattr, frame, -1, ENOTCONN, NULL, NULL); return 0; } @@ -1319,7 +1468,7 @@ out: int32_t client_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, - gf_xattrop_flags_t flags, dict_t *dict) + gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1332,7 +1481,8 @@ client_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, args.loc = loc; args.flags = flags; - args.dict = dict; + args.xattr = dict; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_XATTROP]; if (!proc) { @@ -1345,7 +1495,7 @@ client_xattrop (call_frame_t *frame, xlator_t *this, loc_t *loc, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (xattrop, frame, -1, ENOTCONN, NULL); + STACK_UNWIND_STRICT (xattrop, frame, -1, ENOTCONN, NULL, NULL); return 0; } @@ -1354,7 +1504,7 @@ out: int32_t client_fxattrop (call_frame_t *frame, xlator_t *this, fd_t *fd, - gf_xattrop_flags_t flags, dict_t *dict) + gf_xattrop_flags_t flags, dict_t *dict, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1367,7 +1517,8 @@ client_fxattrop (call_frame_t *frame, xlator_t *this, fd_t *fd, args.fd = fd; args.flags = flags; - args.dict = dict; + args.xattr = dict; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_FXATTROP]; if (!proc) { @@ -1380,7 +1531,7 @@ client_fxattrop (call_frame_t *frame, xlator_t *this, fd_t *fd, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (fxattrop, frame, -1, ENOTCONN, NULL); + STACK_UNWIND_STRICT (fxattrop, frame, -1, ENOTCONN, NULL, NULL); return 0; } @@ -1389,7 +1540,7 @@ out: int32_t client_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - const char *name) + const char *name, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1402,6 +1553,7 @@ client_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc, args.name = name; args.loc = loc; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_REMOVEXATTR]; if (!proc) { @@ -1414,15 +1566,47 @@ client_removexattr (call_frame_t *frame, xlator_t *this, loc_t *loc, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (removexattr, frame, -1, ENOTCONN); + STACK_UNWIND_STRICT (removexattr, frame, -1, ENOTCONN, NULL); return 0; } +int32_t +client_fremovexattr (call_frame_t *frame, xlator_t *this, fd_t *fd, + const char *name, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = {0,}; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + args.name = name; + args.fd = fd; + args.xdata = xdata; + + proc = &conf->fops->proctable[GF_FOP_FREMOVEXATTR]; + if (!proc) { + gf_log (this->name, GF_LOG_ERROR, + "rpc procedure not found for %s", + gf_fop_list[GF_FOP_FREMOVEXATTR]); + goto out; + } + if (proc->fn) + ret = proc->fn (frame, this, &args); +out: + if (ret) + STACK_UNWIND_STRICT (fremovexattr, frame, -1, ENOTCONN, NULL); + + return 0; +} int32_t client_lk (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd, - struct gf_flock *lock) + struct gf_flock *lock, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1436,6 +1620,7 @@ client_lk (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd, args.fd = fd; args.cmd = cmd; args.flock = lock; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_LK]; if (!proc) { @@ -1448,7 +1633,7 @@ client_lk (call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t cmd, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (lk, frame, -1, ENOTCONN, NULL); + STACK_UNWIND_STRICT (lk, frame, -1, ENOTCONN, NULL, NULL); return 0; } @@ -1456,7 +1641,7 @@ out: int32_t client_inodelk (call_frame_t *frame, xlator_t *this, const char *volume, - loc_t *loc, int32_t cmd, struct gf_flock *lock) + loc_t *loc, int32_t cmd, struct gf_flock *lock, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1471,6 +1656,7 @@ client_inodelk (call_frame_t *frame, xlator_t *this, const char *volume, args.cmd = cmd; args.flock = lock; args.volume = volume; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_INODELK]; if (!proc) { @@ -1483,7 +1669,7 @@ client_inodelk (call_frame_t *frame, xlator_t *this, const char *volume, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (inodelk, frame, -1, ENOTCONN); + STACK_UNWIND_STRICT (inodelk, frame, -1, ENOTCONN, NULL); return 0; } @@ -1492,7 +1678,7 @@ out: int32_t client_finodelk (call_frame_t *frame, xlator_t *this, const char *volume, - fd_t *fd, int32_t cmd, struct gf_flock *lock) + fd_t *fd, int32_t cmd, struct gf_flock *lock, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1507,6 +1693,7 @@ client_finodelk (call_frame_t *frame, xlator_t *this, const char *volume, args.cmd = cmd; args.flock = lock; args.volume = volume; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_FINODELK]; if (!proc) { @@ -1519,7 +1706,7 @@ client_finodelk (call_frame_t *frame, xlator_t *this, const char *volume, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (finodelk, frame, -1, ENOTCONN); + STACK_UNWIND_STRICT (finodelk, frame, -1, ENOTCONN, NULL); return 0; } @@ -1528,7 +1715,7 @@ out: 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) + entrylk_type type, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1544,6 +1731,7 @@ client_entrylk (call_frame_t *frame, xlator_t *this, const char *volume, args.type = type; args.volume = volume; args.cmd_entrylk = cmd; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_ENTRYLK]; if (!proc) { @@ -1556,7 +1744,7 @@ client_entrylk (call_frame_t *frame, xlator_t *this, const char *volume, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (entrylk, frame, -1, ENOTCONN); + STACK_UNWIND_STRICT (entrylk, frame, -1, ENOTCONN, NULL); return 0; } @@ -1566,7 +1754,7 @@ out: 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) + entrylk_type type, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1582,6 +1770,7 @@ client_fentrylk (call_frame_t *frame, xlator_t *this, const char *volume, args.type = type; args.volume = volume; args.cmd_entrylk = cmd; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_FENTRYLK]; if (!proc) { @@ -1594,7 +1783,7 @@ client_fentrylk (call_frame_t *frame, xlator_t *this, const char *volume, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (fentrylk, frame, -1, ENOTCONN); + STACK_UNWIND_STRICT (fentrylk, frame, -1, ENOTCONN, NULL); return 0; } @@ -1602,7 +1791,7 @@ out: int32_t client_rchecksum (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, - int32_t len) + int32_t len, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1616,6 +1805,7 @@ client_rchecksum (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, args.fd = fd; args.offset = offset; args.len = len; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_RCHECKSUM]; if (!proc) { @@ -1628,14 +1818,14 @@ client_rchecksum (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (rchecksum, frame, -1, ENOTCONN, 0, NULL); + STACK_UNWIND_STRICT (rchecksum, frame, -1, ENOTCONN, 0, NULL, NULL); return 0; } int32_t client_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, - size_t size, off_t off) + size_t size, off_t off, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1649,6 +1839,7 @@ client_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, args.fd = fd; args.size = size; args.offset = off; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_READDIR]; if (!proc) { @@ -1661,7 +1852,7 @@ client_readdir (call_frame_t *frame, xlator_t *this, fd_t *fd, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (readdir, frame, -1, ENOTCONN, NULL); + STACK_UNWIND_STRICT (readdir, frame, -1, ENOTCONN, NULL, NULL); return 0; } @@ -1669,7 +1860,7 @@ out: int32_t client_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, - size_t size, off_t off) + size_t size, off_t off, dict_t *dict) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1683,6 +1874,7 @@ client_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, args.fd = fd; args.size = size; args.offset = off; + args.xdata = dict; proc = &conf->fops->proctable[GF_FOP_READDIRP]; if (!proc) { @@ -1695,7 +1887,7 @@ client_readdirp (call_frame_t *frame, xlator_t *this, fd_t *fd, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (readdirp, frame, -1, ENOTCONN, NULL); + STACK_UNWIND_STRICT (readdirp, frame, -1, ENOTCONN, NULL, NULL); return 0; } @@ -1703,7 +1895,7 @@ out: int32_t client_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, - struct iatt *stbuf, int32_t valid) + struct iatt *stbuf, int32_t valid, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1717,6 +1909,7 @@ client_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, args.loc = loc; args.stbuf = stbuf; args.valid = valid; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_SETATTR]; if (!proc) { @@ -1729,14 +1922,14 @@ client_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (setattr, frame, -1, ENOTCONN, NULL, NULL); + STACK_UNWIND_STRICT (setattr, frame, -1, ENOTCONN, NULL, NULL, NULL); return 0; } int32_t client_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, - struct iatt *stbuf, int32_t valid) + struct iatt *stbuf, int32_t valid, dict_t *xdata) { int ret = -1; clnt_conf_t *conf = NULL; @@ -1750,6 +1943,7 @@ client_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, args.fd = fd; args.stbuf = stbuf; args.valid = valid; + args.xdata = xdata; proc = &conf->fops->proctable[GF_FOP_FSETATTR]; if (!proc) { @@ -1762,11 +1956,115 @@ client_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd, ret = proc->fn (frame, this, &args); out: if (ret) - STACK_UNWIND_STRICT (fsetattr, frame, -1, ENOTCONN, NULL, NULL); + STACK_UNWIND_STRICT (fsetattr, frame, -1, ENOTCONN, NULL, NULL, NULL); + + return 0; +} + +int32_t +client_fallocate(call_frame_t *frame, xlator_t *this, fd_t *fd, int32_t mode, + off_t offset, size_t len, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = {0,}; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + args.fd = fd; + args.flags = mode; + args.offset = offset; + args.size = len; + args.xdata = xdata; + + proc = &conf->fops->proctable[GF_FOP_FALLOCATE]; + if (!proc) { + gf_log (this->name, GF_LOG_ERROR, + "rpc procedure not found for %s", + gf_fop_list[GF_FOP_FALLOCATE]); + goto out; + } + if (proc->fn) + ret = proc->fn (frame, this, &args); +out: + if (ret) + STACK_UNWIND_STRICT (fallocate, frame, -1, ENOTCONN, NULL, NULL, NULL); return 0; } +int32_t +client_discard(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + size_t len, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = {0,}; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + args.fd = fd; + args.offset = offset; + args.size = len; + args.xdata = xdata; + + proc = &conf->fops->proctable[GF_FOP_DISCARD]; + if (!proc) { + gf_log (this->name, GF_LOG_ERROR, + "rpc procedure not found for %s", + gf_fop_list[GF_FOP_DISCARD]); + goto out; + } + if (proc->fn) + ret = proc->fn (frame, this, &args); +out: + if (ret) + STACK_UNWIND_STRICT(discard, frame, -1, ENOTCONN, NULL, NULL, NULL); + + return 0; +} + +int32_t +client_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + size_t len, dict_t *xdata) +{ + int ret = -1; + clnt_conf_t *conf = NULL; + rpc_clnt_procedure_t *proc = NULL; + clnt_args_t args = {0,}; + + conf = this->private; + if (!conf || !conf->fops) + goto out; + + args.fd = fd; + args.offset = offset; + args.size = len; + args.xdata = xdata; + + proc = &conf->fops->proctable[GF_FOP_ZEROFILL]; + if (!proc) { + gf_log (this->name, GF_LOG_ERROR, + "rpc procedure not found for %s", + gf_fop_list[GF_FOP_ZEROFILL]); + goto out; + } + if (proc->fn) + ret = proc->fn (frame, this, &args); +out: + if (ret) + STACK_UNWIND_STRICT(zerofill, frame, -1, ENOTCONN, + NULL, NULL, NULL); + + return 0; +} + int32_t client_getspec (call_frame_t *frame, xlator_t *this, const char *key, @@ -1804,7 +2102,7 @@ out: } - int +int client_mark_fd_bad (xlator_t *this) { clnt_conf_t *conf = NULL; @@ -1856,7 +2154,7 @@ client_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, gf_log (this->name, GF_LOG_DEBUG, "got RPC_CLNT_CONNECT"); if ((ret < 0) || (strcasecmp (handshake, "on"))) { - ret = client_handshake (this, conf->rpc); + ret = client_handshake (this, rpc); if (ret) gf_log (this->name, GF_LOG_WARNING, "handshake msg returned %d", ret); @@ -1871,16 +2169,46 @@ client_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, conf->last_sent_event = GF_EVENT_CHILD_UP; } } + + /* Cancel grace timer if set */ + pthread_mutex_lock (&conf->lock); + { + conf->grace_timer_needed = _gf_true; + + if (conf->grace_timer) { + gf_log (this->name, GF_LOG_WARNING, + "Cancelling the grace timer"); + + gf_timer_call_cancel (this->ctx, + conf->grace_timer); + + conf->grace_timer = NULL; + } + } + pthread_mutex_unlock (&conf->lock); + break; } case RPC_CLNT_DISCONNECT: - - client_mark_fd_bad (this); + if (!conf->lk_heal) + client_mark_fd_bad (this); + else + client_register_grace_timer (this, conf); if (!conf->skip_notify) { - if (conf->connected) - gf_log (this->name, GF_LOG_INFO, - "disconnected"); + if (conf->connected) { + gf_log (this->name, + ((!conf->disconnect_err_logged) + ? GF_LOG_INFO : GF_LOG_DEBUG), + "disconnected from %s. Client process " + "will keep trying to connect to " + "glusterd until brick's port is " + "available", + conf->rpc->conn.trans->peerinfo.identifier); + + if (conf->portmap_err_logged) + conf->disconnect_err_logged = 1; + } /* If the CHILD_DOWN event goes to parent xlator multiple times, the logic of parent xlator notify @@ -1904,6 +2232,15 @@ client_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, conf->connected = 0; conf->skip_notify = 0; + if (conf->quick_reconnect) { + conf->quick_reconnect = 0; + rpc_clnt_start (rpc); + + } else { + rpc->conn.config.remote_port = 0; + + } + break; default: @@ -1921,7 +2258,7 @@ out: int notify (xlator_t *this, int32_t event, void *data, ...) { - clnt_conf_t *conf = NULL; + clnt_conf_t *conf = NULL; conf = this->private; if (!conf) @@ -1935,8 +2272,22 @@ notify (xlator_t *this, int32_t event, void *data, ...) "on transport"); rpc_clnt_start (conf->rpc); + break; } - break; + + case GF_EVENT_PARENT_DOWN: + gf_log (this->name, GF_LOG_INFO, + "current graph is no longer active, destroying " + "rpc_client "); + + pthread_mutex_lock (&conf->lock); + { + conf->parent_down = 1; + } + pthread_mutex_unlock (&conf->lock); + + rpc_clnt_disable (conf->rpc); + break; default: gf_log (this->name, GF_LOG_DEBUG, @@ -1953,53 +2304,28 @@ notify (xlator_t *this, int32_t event, void *data, ...) int build_client_config (xlator_t *this, clnt_conf_t *conf) { - int ret = -1; + int ret = -1; if (!conf) goto out; - ret = dict_get_int32 (this->options, "frame-timeout", - &conf->rpc_conf.rpc_timeout); - if (ret >= 0) { - gf_log (this->name, GF_LOG_INFO, - "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; - } + GF_OPTION_INIT ("frame-timeout", conf->rpc_conf.rpc_timeout, + int32, out); - ret = dict_get_int32 (this->options, "remote-port", - &conf->rpc_conf.remote_port); - if (ret >= 0) { - gf_log (this->name, GF_LOG_INFO, - "remote-port is %d", conf->rpc_conf.remote_port); - } else { - gf_log (this->name, GF_LOG_DEBUG, - "defaulting remote-port to 'auto'"); - } + GF_OPTION_INIT ("remote-port", conf->rpc_conf.remote_port, + int32, out); - ret = dict_get_int32 (this->options, "ping-timeout", - &conf->opt.ping_timeout); - if (ret >= 0) { - gf_log (this->name, GF_LOG_INFO, - "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; - } + GF_OPTION_INIT ("ping-timeout", conf->opt.ping_timeout, + int32, out); - ret = dict_get_str (this->options, "remote-subvolume", - &conf->opt.remote_subvolume); - if (ret) { - /* This is valid only if 'cluster/pump' is the parent */ + GF_OPTION_INIT ("remote-subvolume", conf->opt.remote_subvolume, + path, out); + if (!conf->opt.remote_subvolume) gf_log (this->name, GF_LOG_WARNING, "option 'remote-subvolume' not given"); - ret = 1; - goto out; - } + + GF_OPTION_INIT ("filter-O_DIRECT", conf->filter_o_direct, + bool, out); ret = 0; out: @@ -2037,6 +2363,9 @@ client_destroy_rpc (xlator_t *this) goto out; if (conf->rpc) { + /* cleanup the saved-frames before last unref */ + rpc_clnt_connection_cleanup (&conf->rpc->conn); + conf->rpc = rpc_clnt_unref (conf->rpc); ret = 0; gf_log (this->name, GF_LOG_DEBUG, @@ -2045,7 +2374,7 @@ client_destroy_rpc (xlator_t *this) } gf_log (this->name, GF_LOG_WARNING, - "RPC destory called on already destroyed " + "RPC destroy called on already destroyed " "connection"); out: @@ -2067,7 +2396,7 @@ client_init_rpc (xlator_t *this) goto out; } - conf->rpc = rpc_clnt_new (this->options, this->ctx, this->name); + conf->rpc = rpc_clnt_new (this->options, this->ctx, this->name, 0); if (!conf->rpc) { gf_log (this->name, GF_LOG_ERROR, "failed to initialize RPC"); goto out; @@ -2082,7 +2411,8 @@ client_init_rpc (xlator_t *this) conf->handshake = &clnt_handshake_prog; conf->dump = &clnt_dump_prog; - ret = rpcclnt_cbk_program_register (conf->rpc, &gluster_cbk_prog); + ret = rpcclnt_cbk_program_register (conf->rpc, &gluster_cbk_prog, + this); if (ret) { gf_log (this->name, GF_LOG_ERROR, "failed to register callback program"); @@ -2096,32 +2426,41 @@ out: return ret; } + int -validate_options (xlator_t *this, char **op_errstr) +client_init_grace_timer (xlator_t *this, dict_t *options, + clnt_conf_t *conf) { - int ret = 0; - volume_opt_list_t *vol_opt = NULL; - volume_opt_list_t *tmp; + char *lk_heal = NULL; + int32_t ret = -1; + int32_t grace_timeout = -1; - if (!this) { - gf_log (this->name, GF_LOG_DEBUG, "'this' not a valid ptr"); - ret =-1; - goto out; - } + GF_VALIDATE_OR_GOTO ("client", this, out); + GF_VALIDATE_OR_GOTO (this->name, options, out); + GF_VALIDATE_OR_GOTO (this->name, conf, out); - if (list_empty (&this->volume_options)) - goto out; + conf->lk_heal = _gf_false; - vol_opt = list_entry (this->volume_options.next, - volume_opt_list_t, list); - list_for_each_entry_safe (vol_opt, tmp, &this->volume_options, list) { - ret = validate_xlator_volume_options_attacherr (this, - vol_opt->given_opt, - op_errstr); - } + ret = dict_get_str (options, "lk-heal", &lk_heal); + if (!ret) + gf_string2boolean (lk_heal, &conf->lk_heal); -out: + gf_log (this->name, GF_LOG_DEBUG, "lk-heal = %s", + (conf->lk_heal) ? "on" : "off"); + + ret = dict_get_int32 (options, "grace-timeout", &grace_timeout); + if (!ret) + conf->grace_ts.tv_sec = grace_timeout; + else + conf->grace_ts.tv_sec = 10; + conf->grace_ts.tv_nsec = 0; + + gf_log (this->name, GF_LOG_DEBUG, "Client grace timeout " + "value = %"PRIu64, conf->grace_ts.tv_sec); + + ret = 0; +out: return ret; } @@ -2129,10 +2468,7 @@ int reconfigure (xlator_t *this, dict_t *options) { clnt_conf_t *conf = NULL; - int ret = 0; - int timeout_ret = 0; - int ping_timeout = 0; - int frame_timeout = 0; + int ret = -1; int subvol_ret = 0; char *old_remote_subvol = NULL; char *new_remote_subvol = NULL; @@ -2141,70 +2477,18 @@ reconfigure (xlator_t *this, dict_t *options) conf = this->private; - timeout_ret = dict_get_int32 (options, "frame-timeout", - &frame_timeout); - if (timeout_ret == 0) { - if (frame_timeout < 5 ) { - gf_log (this->name, GF_LOG_ERROR, "Reconfiguration" - "'option frame-timeout %d failed , Min value" - " can be 5, Defaulting to old value (%d)" - , frame_timeout, conf->rpc_conf.rpc_timeout); - goto out; - } - - if (frame_timeout > 3600 ) { - gf_log (this->name, GF_LOG_ERROR, "Reconfiguration" - "'option frame-timeout %d failed , Max value" - "can be 3600, Defaulting to old value (%d)" - , frame_timeout, conf->rpc_conf.rpc_timeout); - goto out; - } - + GF_OPTION_RECONF ("frame-timeout", conf->rpc_conf.rpc_timeout, + options, int32, out); - gf_log (this->name, GF_LOG_DEBUG, - "Reconfiguring otion frame-timeout to %d", - frame_timeout); - - conf->rpc_conf.rpc_timeout = frame_timeout; - } - else - conf->rpc_conf.rpc_timeout = 1800; - - timeout_ret = dict_get_int32 (options, "ping-timeout", - &ping_timeout); - if (timeout_ret == 0) { - - if (ping_timeout < 5 ) { - gf_log (this->name, GF_LOG_WARNING, "Reconfiguration" - "'option ping-timeout %d failed , Min value" - " can be 5, Defaulting to old value (%d)" - , ping_timeout, conf->opt.ping_timeout); - goto out; - } - - if (ping_timeout > 1013 ) { - gf_log (this->name, GF_LOG_WARNING, "Reconfiguration" - "'option ping-timeout %d failed , Max value" - "can be 1013, Defaulting to old value (%d)" - , ping_timeout, conf->opt.ping_timeout); - goto out; - } - - gf_log (this->name, GF_LOG_DEBUG, "Reconfiguring " - "'option ping-timeout' to %d", ping_timeout); - conf->opt.ping_timeout = ping_timeout; - } - else - conf->opt.ping_timeout = GF_UNIVERSAL_ANSWER; + GF_OPTION_RECONF ("ping-timeout", conf->opt.ping_timeout, + options, int32, out); subvol_ret = dict_get_str (this->options, "remote-host", &old_remote_host); if (subvol_ret == 0) { - subvol_ret = dict_get_str (options, "remote-host", &new_remote_host); - if (subvol_ret == 0) { if (strcmp (old_remote_host, new_remote_host)) { ret = 1; @@ -2217,10 +2501,8 @@ reconfigure (xlator_t *this, dict_t *options) &old_remote_subvol); if (subvol_ret == 0) { - subvol_ret = dict_get_str (options, "remote-subvolume", &new_remote_subvol); - if (subvol_ret == 0) { if (strcmp (old_remote_subvol, new_remote_subvol)) { ret = 1; @@ -2229,18 +2511,26 @@ reconfigure (xlator_t *this, dict_t *options) } } + GF_OPTION_RECONF ("filter-O_DIRECT", conf->filter_o_direct, + options, bool, out); + + ret = client_init_grace_timer (this, options, conf); + if (ret) + goto out; + + ret = 0; out: 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 " @@ -2260,6 +2550,15 @@ init (xlator_t *this) pthread_mutex_init (&conf->lock, NULL); INIT_LIST_HEAD (&conf->saved_fds); + /* Initialize parameters for lock self healing*/ + conf->lk_version = 1; + conf->grace_timer = NULL; + conf->grace_timer_needed = _gf_true; + + ret = client_init_grace_timer (this, this->options, conf); + if (ret) + goto out; + LOCK_INIT (&conf->rec_lock); conf->last_sent_event = -1; /* To start with we don't have any events */ @@ -2281,6 +2580,13 @@ init (xlator_t *this) goto out; } + this->local_pool = mem_pool_new (clnt_local_t, 64); + if (!this->local_pool) { + ret = -1; + gf_log (this->name, GF_LOG_ERROR, + "failed to create local_t's memory pool"); + goto out; + } ret = client_init_rpc (this); out: @@ -2299,8 +2605,12 @@ fini (xlator_t *this) this->private = NULL; if (conf) { - if (conf->rpc) - rpc_clnt_unref (conf->rpc); + if (conf->rpc) { + /* cleanup the saved-frames before last unref */ + rpc_clnt_connection_cleanup (&conf->rpc->conn); + + rpc_clnt_unref (conf->rpc); + } /* Saved Fds */ /* TODO: */ @@ -2312,6 +2622,54 @@ fini (xlator_t *this) return; } +static void +client_fd_lk_ctx_dump (xlator_t *this, fd_lk_ctx_t *lk_ctx, int nth_fd) +{ + gf_boolean_t use_try_lock = _gf_true; + int ret = -1; + int lock_no = 0; + fd_lk_ctx_t *lk_ctx_ref = NULL; + fd_lk_ctx_node_t *plock = NULL; + char key[GF_DUMP_MAX_BUF_LEN] = {0,}; + + lk_ctx_ref = fd_lk_ctx_try_ref (lk_ctx); + if (!lk_ctx_ref) + return; + + ret = client_fd_lk_list_empty (lk_ctx_ref, (use_try_lock = _gf_true)); + if (ret != 0) + return; + + ret = TRY_LOCK (&lk_ctx_ref->lock); + if (ret) + return; + + gf_proc_dump_write ("------","------"); + + lock_no = 0; + list_for_each_entry (plock, &lk_ctx_ref->lk_list, next) { + snprintf (key, sizeof (key), "granted-posix-lock[%d]", + lock_no++); + gf_proc_dump_write (key, "owner = %s, cmd = %s " + "fl_type = %s, fl_start = %" + PRId64", fl_end = %"PRId64 + ", user_flock: l_type = %s, " + "l_start = %"PRId64", l_len = %"PRId64, + lkowner_utoa (&plock->user_flock.l_owner), + get_lk_cmd (plock->cmd), + get_lk_type (plock->fl_type), + plock->fl_start, plock->fl_end, + get_lk_type (plock->user_flock.l_type), + plock->user_flock.l_start, + plock->user_flock.l_len); + } + gf_proc_dump_write ("------","------"); + + UNLOCK (&lk_ctx_ref->lock); + fd_lk_ctx_unref (lk_ctx_ref); + +} + int client_priv_dump (xlator_t *this) { @@ -2326,18 +2684,12 @@ client_priv_dump (xlator_t *this) return -1; conf = this->private; - if (!conf) { - gf_log (this->name, GF_LOG_WARNING, - "conf null in xlator"); + if (!conf) return -1; - } ret = pthread_mutex_trylock(&conf->lock); - if (ret) { - gf_log(this->name, GF_LOG_WARNING, "Unable to lock client %s" - " errno: %d", this->name, errno); + if (ret) return -1; - } gf_proc_dump_build_key(key_prefix, "xlator.protocol.client", "%s.priv", this->name); @@ -2345,25 +2697,19 @@ client_priv_dump (xlator_t *this) 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); + sprintf (key, "fd.%d.remote_fd", i); gf_proc_dump_write(key, "%d", tmp->remote_fd); + client_fd_lk_ctx_dump (this, tmp->lk_ctx, i); + i++; } - 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)); + gf_proc_dump_write("connecting", "%d", conf->connecting); if (conf->rpc) { - gf_proc_dump_build_key(key, key_prefix, "total_bytes_read"); - gf_proc_dump_write(key, "%"PRIu64, + gf_proc_dump_write("total_bytes_read", "%"PRIu64, conf->rpc->conn.trans->total_bytes_read); - gf_proc_dump_build_key(key, key_prefix, "total_bytes_written"); - gf_proc_dump_write(key, "%"PRIu64, + gf_proc_dump_write("total_bytes_written", "%"PRIu64, conf->rpc->conn.trans->total_bytes_write); } pthread_mutex_unlock(&conf->lock); @@ -2375,26 +2721,13 @@ client_priv_dump (xlator_t *this) 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); + /*TODO*/ return 0; } @@ -2430,6 +2763,7 @@ struct xlator_fops fops = { .fsetxattr = client_fsetxattr, .fgetxattr = client_fgetxattr, .removexattr = client_removexattr, + .fremovexattr = client_fremovexattr, .opendir = client_opendir, .readdir = client_readdir, .readdirp = client_readdirp, @@ -2449,6 +2783,9 @@ struct xlator_fops fops = { .fxattrop = client_fxattrop, .setattr = client_setattr, .fsetattr = client_fsetattr, + .fallocate = client_fallocate, + .discard = client_discard, + .zerofill = client_zerofill, .getspec = client_getspec, }; @@ -2474,6 +2811,9 @@ struct volume_options options[] = { { .key = {"remote-host"}, .type = GF_OPTION_TYPE_INTERNET_ADDRESS }, + { .key = {"remote-port"}, + .type = GF_OPTION_TYPE_INT, + }, { .key = {"remote-subvolume"}, .type = GF_OPTION_TYPE_ANY }, @@ -2482,11 +2822,46 @@ struct volume_options options[] = { .type = GF_OPTION_TYPE_TIME, .min = 0, .max = 86400, + .default_value = "1800", + .description = "Time frame after which the (file) operation would be " + "declared as dead, if the server does not respond for " + "a particular (file) operation." }, { .key = {"ping-timeout"}, .type = GF_OPTION_TYPE_TIME, .min = 1, .max = 1013, + .default_value = "42", + .description = "Time duration for which the client waits to " + "check if the server is responsive." + }, + { .key = {"client-bind-insecure"}, + .type = GF_OPTION_TYPE_BOOL + }, + { .key = {"lk-heal"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "off", + .description = "Enables or disables the lock heal." + }, + { .key = {"grace-timeout"}, + .type = GF_OPTION_TYPE_INT, + .min = 10, + .max = 1800, + .description = "Sets the grace-timeout value. Valid range 10-1800." + }, + {.key = {"tcp-window-size"}, + .type = GF_OPTION_TYPE_SIZET, + .min = GF_MIN_SOCKET_WINDOW_SIZE, + .max = GF_MAX_SOCKET_WINDOW_SIZE, + .description = "Specifies the window size for tcp socket." + }, + { .key = {"filter-O_DIRECT"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "disable", + .description = "If enabled, in open() and creat() calls, O_DIRECT " + "flag will be filtered at the client protocol level so server will " + "still continue to cache the file. This works similar to NFS's " + "behavior of O_DIRECT", }, { .key = {NULL} }, }; diff --git a/xlators/protocol/client/src/client.h b/xlators/protocol/client/src/client.h index 40a3d5d3d..afab2d74f 100644 --- a/xlators/protocol/client/src/client.h +++ b/xlators/protocol/client/src/client.h @@ -1,20 +1,11 @@ /* - 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 Affero 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 - Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. */ #ifndef _CLIENT_H @@ -29,11 +20,49 @@ #include "client-mem-types.h" #include "protocol-common.h" #include "glusterfs3.h" +#include "fd-lk.h" /* FIXME: Needs to be defined in a common file */ #define CLIENT_CMD_CONNECT "trusted.glusterfs.client-connect" #define CLIENT_CMD_DISCONNECT "trusted.glusterfs.client-disconnect" #define CLIENT_DUMP_LOCKS "trusted.glusterfs.clientlk-dump" +#define GF_MAX_SOCKET_WINDOW_SIZE (1 * GF_UNIT_MB) +#define GF_MIN_SOCKET_WINDOW_SIZE (0) + +typedef enum { + GF_LK_HEAL_IN_PROGRESS, + GF_LK_HEAL_DONE, +} lk_heal_state_t; + +typedef enum { + DEFAULT_REMOTE_FD = 0, + FALLBACK_TO_ANON_FD = 1 +} clnt_remote_fd_flags_t; + +#define CLIENT_GET_REMOTE_FD(xl, fd, flags, remote_fd, op_errno, label) \ + do { \ + int _ret = 0; \ + _ret = client_get_remote_fd (xl, fd, flags, &remote_fd);\ + if (_ret < 0) { \ + op_errno = errno; \ + goto label; \ + } \ + if (remote_fd == -1) { \ + gf_log (xl->name, GF_LOG_WARNING, " (%s) " \ + "remote_fd is -1. EBADFD", \ + uuid_utoa (fd->inode->gfid)); \ + op_errno = EBADFD; \ + goto label; \ + } \ + } while (0) + +#define CLIENT_STACK_UNWIND(op, frame, params ...) do { \ + clnt_local_t *__local = frame->local; \ + frame->local = NULL; \ + STACK_UNWIND_STRICT (op, frame, params); \ + client_local_wipe (__local); \ + } while (0) + struct clnt_options { char *remote_subvolume; @@ -48,8 +77,6 @@ typedef struct clnt_conf { pthread_mutex_t lock; int connecting; int connected; - struct timeval last_sent; - struct timeval last_received; rpc_clnt_prog_t *fops; rpc_clnt_prog_t *mgmt; @@ -66,6 +93,33 @@ typedef struct clnt_conf { which was sent earlier */ char portmap_err_logged; /* flag used to prevent excessive logging */ + char disconnect_err_logged; /* flag used to prevent + excessive disconnect + logging */ + + char need_different_port; /* flag used to change the + portmap path in case of + 'tcp,rdma' on server */ + gf_boolean_t lk_heal; + uint16_t lk_version; /* this variable is used to distinguish + client-server transaction while + performing lock healing */ + struct timespec grace_ts; + gf_timer_t *grace_timer; + gf_boolean_t grace_timer_needed; /* The state of this flag will + be used to decide whether + a new grace-timer must be + registered or not. False + means dont register, true + means register */ + char parent_down; + gf_boolean_t quick_reconnect; /* When reconnecting after + portmap query, do not let + the reconnection happen after + the usual 3-second wait + */ + gf_boolean_t filter_o_direct; /* if set, filter O_DIRECT from + the flags list of open() */ } clnt_conf_t; typedef struct _client_fd_ctx { @@ -73,16 +127,16 @@ typedef struct _client_fd_ctx { 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; - + fd_lk_ctx_t *lk_ctx; pthread_mutex_t mutex; + lk_heal_state_t lk_heal_state; + uuid_t gfid; + void (*reopen_done) (struct _client_fd_ctx*, xlator_t *); struct list_head lock_list; /* List of all granted locks on this fd */ + int32_t reopen_attempts; } clnt_fd_ctx_t; typedef struct _client_posix_lock { @@ -93,8 +147,7 @@ typedef struct _client_posix_lock { off_t fl_end; short fl_type; int32_t cmd; /* the cmd for the lock call */ - uint64_t owner; /* lock owner from fuse */ - + gf_lkowner_t owner; /* lock owner from fuse */ struct list_head list; /* reference used to add to the fdctx list of locks */ } client_posix_lock_t; @@ -104,26 +157,25 @@ typedef struct client_local { fd_t *fd; clnt_fd_ctx_t *fdctx; uint32_t flags; - uint32_t wbflags; struct iobref *iobref; client_posix_lock_t *client_lock; - uint64_t owner; + gf_lkowner_t owner; int32_t cmd; struct list_head lock_list; pthread_mutex_t mutex; + char *name; + gf_boolean_t attempt_reopen; } 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; @@ -137,7 +189,6 @@ typedef struct client_args { mode_t mode; dev_t rdev; int32_t flags; - int32_t wbflags; int32_t count; int32_t datasync; entrylk_cmd cmd_entrylk; @@ -145,6 +196,9 @@ typedef struct client_args { gf_xattrop_flags_t optype; int32_t valid; int32_t len; + + mode_t umask; + dict_t *xdata; } clnt_args_t; typedef ssize_t (*gfs_serialize_t) (struct iovec outmsg, void *args); @@ -158,24 +212,21 @@ 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, fop_cbk_fn_t cbk, - struct iobref *iobref, gfs_serialize_t sfunc, + struct iobref *iobref, struct iovec *rsphdr, int rsphdr_count, struct iovec *rsp_payload, int rsp_count, - struct iobref *rsp_iobref); - -int protocol_client_reopendir (xlator_t *this, clnt_fd_ctx_t *fdctx); -int protocol_client_reopen (xlator_t *this, clnt_fd_ctx_t *fdctx); + struct iobref *rsp_iobref, xdrproc_t xdrproc); int unserialize_rsp_dirent (struct gfs3_readdir_rsp *rsp, gf_dirent_t *entries); -int unserialize_rsp_direntp (struct gfs3_readdirp_rsp *rsp, gf_dirent_t *entries); +int unserialize_rsp_direntp (xlator_t *this, fd_t *fd, + struct gfs3_readdirp_rsp *rsp, gf_dirent_t *entries); int clnt_readdir_rsp_cleanup (gfs3_readdir_rsp *rsp); int clnt_readdirp_rsp_cleanup (gfs3_readdirp_rsp *rsp); int client_attempt_lock_recovery (xlator_t *this, clnt_fd_ctx_t *fdctx); -int32_t delete_granted_locks_owner (fd_t *fd, uint64_t owner); -int client_add_lock_for_recovery (fd_t *fd, struct gf_flock *flock, uint64_t owner, - int32_t cmd); -uint64_t decrement_reopen_fd_count (xlator_t *this, clnt_conf_t *conf); +int32_t delete_granted_locks_owner (fd_t *fd, gf_lkowner_t *owner); +int client_add_lock_for_recovery (fd_t *fd, struct gf_flock *flock, + gf_lkowner_t *owner, int32_t cmd); int32_t delete_granted_locks_fd (clnt_fd_ctx_t *fdctx); int32_t client_cmd_to_gf_cmd (int32_t cmd, int32_t *gf_cmd); void client_save_number_fds (clnt_conf_t *conf, int count); @@ -186,4 +237,21 @@ int32_t client_dump_locks (char *name, inode_t *inode, dict_t *dict); int client_fdctx_destroy (xlator_t *this, clnt_fd_ctx_t *fdctx); +uint32_t client_get_lk_ver (clnt_conf_t *conf); + +int32_t client_type_to_gf_type (short l_type); + +int client_mark_fd_bad (xlator_t *this); + +int client_set_lk_version (xlator_t *this); + +int client_fd_lk_list_empty (fd_lk_ctx_t *lk_ctx, gf_boolean_t use_try_lock); +void client_default_reopen_done (clnt_fd_ctx_t *fdctx, xlator_t *this); +void client_attempt_reopen (fd_t *fd, xlator_t *this); +int client_get_remote_fd (xlator_t *this, fd_t *fd, int flags, + int64_t *remote_fd); +int client_fd_fop_prepare_local (call_frame_t *frame, fd_t *fd, + int64_t remote_fd); +gf_boolean_t +__is_fd_reopen_in_progress (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 deleted file mode 100644 index 492c469d8..000000000 --- a/xlators/protocol/client/src/client3_1-fops.c +++ /dev/null @@ -1,5447 +0,0 @@ -/* - Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU Affero 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 - Affero General Public License for more details. - - You should have received a copy of the GNU Affero 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 "glusterfs3-xdr.h" -#include "glusterfs3.h" -#include "compat-errno.h" - -int32_t client3_getspec (call_frame_t *frame, xlator_t *this, void *data); -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, fop_cbk_fn_t cbk, - 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; - int start_ping = 0; - struct iobref *new_iobref = NULL; - - start_ping = 0; - - conf = this->private; - - iobuf = iobuf_get (this->ctx->iobuf_pool); - if (!iobuf) { - goto out; - }; - - new_iobref = iobref_new (); - if (!new_iobref) { - goto out; - } - - if (iobref != NULL) { - ret = iobref_merge (new_iobref, iobref); - if (ret != 0) { - gf_log (this->name, GF_LOG_WARNING, - "cannot merge iobref passed from caller into " - "new_iobref"); - goto out; - } - } - - ret = iobref_add (new_iobref, iobuf); - if (ret != 0) { - gf_log (this->name, GF_LOG_WARNING, - "cannot add iobuf into iobref"); - goto out; - } - - 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) { - gf_log_callingfn ("", GF_LOG_WARNING, - "XDR function failed"); - goto out; - } - - iov.iov_len = ret; - count = 1; - } - /* Send the msg */ - ret = rpc_clnt_submit (conf->rpc, prog, procnum, cbk, &iov, count, - payload, payloadcnt, new_iobref, frame, NULL, 0, - NULL, 0, NULL); - if (ret < 0) { - gf_log (this->name, GF_LOG_DEBUG, "rpc_clnt_submit failed"); - } - - 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 != NULL) { - iobref_unref (new_iobref); - } - - iobuf_unref (iobuf); - - return 0; -} - -/* CBK */ - -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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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; - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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; - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - int ret = 0; - gfs3_open_rsp rsp = {0,}; - xlator_t *this = NULL; - - this = THIS; - - frame = myframe; - local = frame->local; - - 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 (this->name, 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; - } - - fdctx->remote_fd = rsp.fd; - fdctx->inode = inode_ref (fd->inode); - fdctx->flags = local->flags; - fdctx->wbflags = local->wbflags; - - INIT_LIST_HEAD (&fdctx->sfd_pos); - INIT_LIST_HEAD (&fdctx->lock_list); - - 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; - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - clnt_local_t *local = NULL; - xlator_t *this = NULL; - gf_common_rsp rsp = {0,}; - int ret = 0; - - frame = myframe; - this = THIS; - local = frame->local; - - 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 (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (rsp.op_ret >= 0) { - /* Delete all saved locks of the owner issuing flush */ - ret = delete_granted_locks_owner (local->fd, local->owner); - gf_log (this->name, GF_LOG_DEBUG, - "deleting locks of owner (%llu) returned %d", - (long long unsigned) local->owner, ret); - } - - frame->local = NULL; - if (local) - client_local_wipe (local); - -out: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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 = EINVAL; - gfs3_getxattr_rsp rsp = {0,}; - int ret = 0; - clnt_local_t *local = NULL; - xlator_t *this = NULL; - - this = THIS; - - frame = myframe; - local = frame->local; - frame->local = NULL; - - 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 (this->name, 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_WARNING, - "failed to unserialize xattr dict"); - op_errno = EINVAL; - goto out; - } - dict->extra_free = buf; - buf = NULL; - } - op_ret = 0; - } - -out: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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); - - client_local_wipe (local); - - 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 = EINVAL; - clnt_local_t *local = NULL; - xlator_t *this = NULL; - - this = THIS; - - frame = myframe; - local = frame->local; - frame->local = NULL; - - 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 (this->name, 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_WARNING, - "failed to unserialize xattr dict"); - op_errno = EINVAL; - goto out; - } - dict->extra_free = buf; - buf = NULL; - } - op_ret = 0; - } -out: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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); - - if (local) - client_local_wipe (local); - - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - if ((rsp.op_ret == -1) && - (EAGAIN != gf_error_to_errno (rsp.op_errno))) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - if ((rsp.op_ret == -1) && - (EAGAIN != gf_error_to_errno (rsp.op_errno))) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - - if ((rsp.op_ret == -1) && - (EAGAIN != gf_error_to_errno (rsp.op_errno))) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - if ((rsp.op_ret == -1) && - (EAGAIN != gf_error_to_errno (rsp.op_errno))) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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 = EINVAL; - clnt_local_t *local = NULL; - xlator_t *this = NULL; - - this = THIS; - - frame = myframe; - local = frame->local; - frame->local = NULL; - - 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 (this->name, GF_LOG_ERROR, "error"); - op_ret = -1; - op_errno = EINVAL; - goto out; - } - - op_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); - op_ret = dict_unserialize (buf, dict_len, &dict); - if (op_ret < 0) { - gf_log (frame->this->name, GF_LOG_WARNING, - "failed to unserialize xattr dict"); - op_errno = EINVAL; - goto out; - } - dict->extra_free = buf; - buf = NULL; - } - op_ret = 0; - } - -out: - - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - STACK_UNWIND_STRICT (xattrop, frame, op_ret, - gf_error_to_errno (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); - - client_local_wipe (local); - - 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; - clnt_local_t *local = NULL; - xlator_t *this = NULL; - - this = THIS; - - frame = myframe; - local = frame->local; - frame->local = NULL; - - 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 (this->name, GF_LOG_ERROR, "error"); - goto out; - } - op_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); - op_ret = dict_unserialize (buf, dict_len, &dict); - if (op_ret < 0) { - gf_log (frame->this->name, GF_LOG_WARNING, - "failed to unserialize xattr dict"); - op_errno = EINVAL; - goto out; - } - dict->extra_free = buf; - buf = NULL; - } - op_ret = 0; - } - -out: - - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - STACK_UNWIND_STRICT (fxattrop, frame, op_ret, - gf_error_to_errno (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); - - client_local_wipe (local); - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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,}; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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); - - 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->flags = local->flags; - - INIT_LIST_HEAD (&fdctx->sfd_pos); - INIT_LIST_HEAD (&fdctx->lock_list); - - 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; - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - -out: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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_lk_cbk (struct rpc_req *req, struct iovec *iov, int count, - void *myframe) -{ - call_frame_t *frame = NULL; - clnt_local_t *local = NULL; - struct gf_flock lock = {0,}; - gfs3_lk_rsp rsp = {0,}; - int ret = 0; - xlator_t *this = NULL; - - this = THIS; - - frame = myframe; - local = frame->local; - - 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 (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (rsp.op_ret >= 0) { - gf_proto_flock_to_flock (&rsp.flock, &lock); - } - - /* Save the lock to the client lock cache to be able - to recover in the case of server reboot.*/ - /* - temporarily - if (local->cmd == F_SETLK || local->cmd == F_SETLKW) { - ret = client_add_lock_for_recovery (local->fd, &lock, - local->owner, local->cmd); - if (ret < 0) { - rsp.op_ret = -1; - rsp.op_errno = -ret; - } - } - */ - - frame->local = NULL; - client_local_wipe (local); - -out: - if ((rsp.op_ret == -1) && - (EAGAIN != gf_error_to_errno (rsp.op_errno))) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - clnt_local_t *local = NULL; - gf_dirent_t entries; - xlator_t *this = NULL; - - this = THIS; - - frame = myframe; - local = frame->local; - frame->local = NULL; - - 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 (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - INIT_LIST_HEAD (&entries.list); - if (rsp.op_ret > 0) { - unserialize_rsp_dirent (&rsp, &entries); - } - -out: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - STACK_UNWIND_STRICT (readdir, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &entries); - - client_local_wipe (local); - - if (rsp.op_ret != -1) { - gf_dirent_free (&entries); - } - - clnt_readdir_rsp_cleanup (&rsp); - - 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; - clnt_local_t *local = NULL; - gf_dirent_t entries; - xlator_t *this = NULL; - - this = THIS; - - frame = myframe; - local = frame->local; - frame->local = NULL; - - 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 (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - INIT_LIST_HEAD (&entries.list); - if (rsp.op_ret > 0) { - unserialize_rsp_direntp (&rsp, &entries); - } - -out: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - STACK_UNWIND_STRICT (readdirp, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), &entries); - - client_local_wipe (local); - - if (rsp.op_ret != -1) { - gf_dirent_free (&entries); - } - - clnt_readdirp_rsp_cleanup (&rsp); - - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - STACK_UNWIND_STRICT (rename, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), - &stbuf, &preoldparent, &postoldparent, - &prenewparent, &postnewparent); - - 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; - xlator_t *this = NULL; - - this = THIS; - - 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 (this->name, 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; - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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; - call_frame_t *frame = NULL; - fd_t *fd = NULL; - int ret = 0; - gfs3_opendir_rsp rsp = {0,}; - xlator_t *this = NULL; - - this = THIS; - - frame = myframe; - local = frame->local; - - 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 (this->name, 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; - } - - fdctx->remote_fd = rsp.fd; - fdctx->inode = inode_ref (fd->inode); - fdctx->is_dir = 1; - - INIT_LIST_HEAD (&fdctx->sfd_pos); - INIT_LIST_HEAD (&fdctx->lock_list); - - 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; - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - 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 = EINVAL; - dict_t *xattr = NULL; - inode_t *inode = NULL; - char *buf = NULL; - xlator_t *this = NULL; - - this = THIS; - - frame = myframe; - local = frame->local; - inode = local->loc.inode; - frame->local = NULL; - - if (-1 == req->rpc_status) { - rsp.op_ret = -1; - op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_lookup_rsp (*iov, &rsp); - if (ret < 0) { - gf_log (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - 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 == -1) - goto out; - - rsp.op_ret = -1; - gf_stat_to_iatt (&rsp.stat, &stbuf); - - 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_WARNING, - "%s (%"PRId64"): failed to " - "unserialize dictionary", - local->loc.path, inode->ino); - op_errno = EINVAL; - goto out; - } - - xattr->extra_free = buf; - buf = NULL; - } - - if ((!uuid_is_null (inode->gfid)) - && (uuid_compare (stbuf.ia_gfid, inode->gfid) != 0)) { - gf_log (frame->this->name, GF_LOG_DEBUG, - "gfid changed for %s", local->loc.path); - rsp.op_ret = -1; - rsp.op_errno = ESTALE; - goto out; - } - - rsp.op_ret = 0; - -out: - rsp.op_errno = op_errno; - frame->local = NULL; - if (rsp.op_ret == -1) { - /* any error other than ENOENT or for revalidate for ENOENT too */ - if ((gf_error_to_errno (rsp.op_errno) != ENOENT) || - !uuid_is_null (local->loc.inode->gfid)) - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - else - gf_log (this->name, GF_LOG_TRACE, "not found on remote node"); - - } - 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[MAX_IOVEC] = {{0}, }; - struct iatt stat = {0,}; - gfs3_read_rsp rsp = {0,}; - int ret = 0, rspcount = 0; - clnt_local_t *local = NULL; - xlator_t *this = NULL; - - this = THIS; - - memset (vector, 0, sizeof (vector)); - - frame = myframe; - local = frame->local; - frame->local = NULL; - - 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 (this->name, GF_LOG_ERROR, "error"); - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (rsp.op_ret != -1) { - iobref = req->rsp_iobref; - gf_stat_to_iatt (&rsp.stat, &stat); - - vector[0].iov_len = rsp.op_ret; - if (rsp.op_ret > 0) - vector[0].iov_base = req->rsp[1].iov_base; - rspcount = 1; - } -out: - if (rsp.op_ret == -1) { - gf_log (this->name, GF_LOG_INFO, "remote operation failed: %s", - strerror (gf_error_to_errno (rsp.op_errno))); - } - STACK_UNWIND_STRICT (readv, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), vector, rspcount, - &stat, iobref); - - if (local) { - client_local_wipe (local); - } - - return 0; -} - -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 -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) { - gf_log (this->name, GF_LOG_DEBUG, "not a valid fd"); - goto out; - } - - fr = create_frame (this, this->ctx->pool); - - if (fdctx->is_dir) { - gfs3_releasedir_req req = {{0,},}; - req.fd = fdctx->remote_fd; - gf_log (this->name, GF_LOG_INFO, "sending releasedir on fd"); - ret = client_submit_request (this, &req, fr, &clnt3_1_fop_prog, - GFS3_OP_RELEASEDIR, - client3_1_releasedir_cbk, - NULL, xdr_from_releasedir_req, - NULL, 0, NULL, 0, NULL); - } else { - gfs3_release_req req = {{0,},}; - req.fd = fdctx->remote_fd; - gf_log (this->name, GF_LOG_INFO, "sending release on fd"); - ret = client_submit_request (this, &req, fr, &clnt3_1_fop_prog, - GFS3_OP_RELEASE, - client3_1_release_cbk, NULL, - xdr_from_release_req, NULL, 0, - NULL, 0, NULL); - } - -out: - if (!ret && fdctx) { - fdctx->remote_fd = -1; - inode_unref (fdctx->inode); - GF_FREE (fdctx); - } - - if (ret && fr) - STACK_DESTROY (fr->root); - - return ret; -} - -int32_t -client3_1_releasedir (call_frame_t *frame, xlator_t *this, - 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; - int ret = 0; - - if (!frame || !this || !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; - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_RELEASEDIR, - client3_1_releasedir_cbk, - NULL, xdr_from_releasedir_req, - NULL, 0, NULL, 0, NULL); - inode_unref (fdctx->inode); - GF_FREE (fdctx); - } - -unwind: - if (ret) - STACK_DESTROY (frame->root); - - return 0; -} - -int32_t -client3_1_release (call_frame_t *frame, xlator_t *this, - 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,},}; - int ret = 0; - - if (!frame || !this || !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; - - delete_granted_locks_fd (fdctx); - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_RELEASE, - client3_1_release_cbk, NULL, - xdr_from_release_req, NULL, 0, - NULL, 0, NULL); - inode_unref (fdctx->inode); - GF_FREE (fdctx); - } -unwind: - if (ret) - STACK_DESTROY (frame->root); - - return 0; -} - - -int32_t -client3_1_lookup (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - 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; - data_t *content = NULL; - struct iovec vector[MAX_IOVEC] = {{0}, }; - int count = 0; - struct iobref *rsp_iobref = NULL; - struct iobuf *rsp_iobuf = NULL; - struct iovec *rsphdr = NULL; - - if (!frame || !this || !data) - goto unwind; - - memset (vector, 0, sizeof (vector)); - - conf = this->private; - args = data; - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - - if (!(args->loc && args->loc->inode)) - goto unwind; - - loc_copy (&local->loc, args->loc); - frame->local = local; - - if (args->loc->parent) - memcpy (req.pargfid, args->loc->parent->gfid, 16); - else - memcpy (req.gfid, args->loc->inode->gfid, 16); - - if (args->dict) { - content = dict_get (args->dict, GF_CONTENT_KEY); - if (content != NULL) { - rsp_iobref = iobref_new (); - if (rsp_iobref == NULL) { - goto unwind; - } - - rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); - if (rsp_iobuf == NULL) { - goto unwind; - } - - iobref_add (rsp_iobref, rsp_iobuf); - iobuf_unref (rsp_iobuf); - rsphdr = &vector[0]; - rsphdr->iov_base = iobuf_ptr (rsp_iobuf); - rsphdr->iov_len - = rsp_iobuf->iobuf_arena->iobuf_pool->page_size; - count = 1; - rsp_iobuf = NULL; - local->iobref = rsp_iobref; - rsp_iobref = NULL; - } - - ret = dict_allocate_and_serialize (args->dict, - &req.dict.dict_val, - &dict_len); - if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, - "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; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_LOOKUP, client3_1_lookup_cbk, - NULL, xdr_from_lookup_req, rsphdr, count, - NULL, 0, local->iobref); - - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - - if (rsp_iobref != NULL) { - iobref_unref (rsp_iobref); - } - - return 0; - -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - - if (frame) - 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); - - if (rsp_iobref != NULL) { - iobref_unref (rsp_iobref); - } - - if (rsp_iobuf != NULL) { - iobuf_unref (rsp_iobuf); - } - - return 0; -} - - - -int32_t -client3_1_stat (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_stat_req req = {{0,},}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - if (!(args->loc && args->loc->inode)) - goto unwind; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.path = (char *)args->loc->path; - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_STAT, client3_1_stat_cbk, NULL, - xdr_from_stat_req, NULL, 0, NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop %s", - strerror (op_errno)); - STACK_UNWIND_STRICT (stat, frame, -1, op_errno, NULL); - return 0; -} - - -int32_t -client3_1_truncate (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_truncate_req req = {{0,},}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->loc && args->loc->inode)) - goto unwind; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.path = (char *)args->loc->path; - req.offset = args->offset; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_TRUNCATE, - client3_1_truncate_cbk, NULL, - xdr_from_truncate_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop %s", strerror (op_errno)); - STACK_UNWIND_STRICT (truncate, frame, -1, op_errno, NULL, NULL); - return 0; -} - - -int32_t -client3_1_ftruncate (call_frame_t *frame, xlator_t *this, - 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; - int ret = 0; - - if (!frame || !this || !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_WARNING, - "(%"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_WARNING, "(%"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; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FTRUNCATE, - client3_1_ftruncate_cbk, NULL, - xdr_from_ftruncate_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (ftruncate, frame, -1, op_errno, NULL, NULL); - return 0; -} - - - -int32_t -client3_1_access (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_access_req req = {{0,},}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->loc && args->loc->inode)) - goto unwind; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.path = (char *)args->loc->path; - req.mask = args->mask; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_ACCESS, - client3_1_access_cbk, NULL, - xdr_from_access_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (access, frame, -1, op_errno); - return 0; -} - -int32_t -client3_1_readlink (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_readlink_req req = {{0,},}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->loc && args->loc->inode)) - goto unwind; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.path = (char *)args->loc->path; - req.size = args->size; - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_READLINK, - client3_1_readlink_cbk, NULL, - xdr_from_readlink_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (readlink, frame, -1, op_errno, NULL, NULL); - return 0; -} - - - - -int32_t -client3_1_unlink (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_unlink_req req = {{0,},}; - int ret = 0; - int op_errno = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->loc && args->loc->parent)) - goto unwind; - - memcpy (req.pargfid, args->loc->parent->gfid, 16); - req.path = (char *)args->loc->path; - req.bname = (char *)args->loc->name; - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_UNLINK, - client3_1_unlink_cbk, NULL, - xdr_from_unlink_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (unlink, frame, -1, op_errno, NULL, NULL); - return 0; -} - - - -int32_t -client3_1_rmdir (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_rmdir_req req = {{0,},}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->loc && args->loc->parent)) - goto unwind; - - memcpy (req.pargfid, args->loc->parent->gfid, 16); - req.path = (char *)args->loc->path; - req.bname = (char *)args->loc->name; - req.flags = args->flags; - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_RMDIR, client3_1_rmdir_cbk, NULL, - xdr_from_rmdir_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (rmdir, frame, -1, op_errno, NULL, NULL); - return 0; -} - - - -int32_t -client3_1_symlink (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_local_t *local = NULL; - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_symlink_req req = {{0,},}; - size_t dict_len = 0; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - - if (!(args->loc && args->loc->parent)) - goto unwind; - - loc_copy (&local->loc, args->loc); - frame->local = local; - - memcpy (req.pargfid, args->loc->parent->gfid, 16); - req.path = (char *)args->loc->path; - req.linkname = (char *)args->linkname; - req.bname = (char *)args->loc->name; - 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_WARNING, - "failed to get serialized length of dict"); - op_errno = EINVAL; - goto unwind; - } - } - req.dict.dict_len = dict_len; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_SYMLINK, client3_1_symlink_cbk, - NULL, xdr_from_symlink_req, NULL, 0, NULL, - 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - if (frame) - frame->local = NULL; - - STACK_UNWIND_STRICT (symlink, 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_rename (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_rename_req req = {{0,},}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->oldloc && args->newloc && args->oldloc->parent && - args->newloc->parent)) - goto unwind; - - memcpy (req.oldgfid, args->oldloc->parent->gfid, 16); - memcpy (req.newgfid, args->newloc->parent->gfid, 16); - - req.oldpath = (char *)args->oldloc->path; - req.oldbname = (char *)args->oldloc->name; - req.newpath = (char *)args->newloc->path; - req.newbname = (char *)args->newloc->name; - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_RENAME, client3_1_rename_cbk, NULL, - xdr_from_rename_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - 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, - void *data) -{ - clnt_local_t *local = NULL; - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_link_req req = {{0,},}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->oldloc && args->oldloc->inode && args->newloc && - args->newloc->parent)) - goto unwind; - - memcpy (req.oldgfid, args->oldloc->inode->gfid, 16); - memcpy (req.newgfid, args->newloc->parent->gfid, 16); - - 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; - - req.oldpath = (char *)args->oldloc->path; - req.newpath = (char *)args->newloc->path; - req.newbname = (char *)args->newloc->name; - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_LINK, client3_1_link_cbk, NULL, - xdr_from_link_req, NULL, 0, NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - 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, - void *data) -{ - clnt_local_t *local = NULL; - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_mknod_req req = {{0,},}; - size_t dict_len = 0; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - - if (!(args->loc && args->loc->parent)) - goto unwind; - - loc_copy (&local->loc, args->loc); - frame->local = local; - - memcpy (req.pargfid, args->loc->parent->gfid, 16); - req.path = (char *)args->loc->path; - req.bname = (char *)args->loc->name; - req.mode = args->mode; - req.dev = args->rdev; - 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_WARNING, - "failed to get serialized length of dict"); - op_errno = EINVAL; - goto unwind; - } - } - req.dict.dict_len = dict_len; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_MKNOD, client3_1_mknod_cbk, NULL, - xdr_from_mknod_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - if (frame) - frame->local = NULL; - - STACK_UNWIND_STRICT (mknod, 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_mkdir (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_local_t *local = NULL; - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_mkdir_req req = {{0,},}; - size_t dict_len = 0; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - - if (!(args->loc && args->loc->parent)) - goto unwind; - - loc_copy (&local->loc, args->loc); - frame->local = local; - - memcpy (req.pargfid, args->loc->parent->gfid, 16); - req.path = (char *)args->loc->path; - req.bname = (char *)args->loc->name; - req.mode = args->mode; - 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_WARNING, - "failed to get serialized length of dict"); - op_errno = EINVAL; - goto unwind; - } - } - req.dict.dict_len = dict_len; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_MKDIR, client3_1_mkdir_cbk, NULL, - xdr_from_mkdir_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - if (frame) - frame->local = NULL; - - STACK_UNWIND_STRICT (mkdir, 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_create (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_local_t *local = NULL; - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_create_req req = {{0,},}; - size_t dict_len = 0; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - if (!(args->loc && args->loc->parent)) - goto unwind; - - local->fd = fd_ref (args->fd); - local->flags = args->flags; - - loc_copy (&local->loc, args->loc); - frame->local = local; - - memcpy (req.pargfid, args->loc->parent->gfid, 16); - req.path = (char *)args->loc->path; - req.bname = (char *)args->loc->name; - req.mode = args->mode; - req.flags = gf_flags_from_flags (args->flags); - 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_WARNING, - "failed to get serialized length of dict"); - op_errno = EINVAL; - goto unwind; - } - } - req.dict.dict_len = dict_len; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_CREATE, client3_1_create_cbk, NULL, - xdr_from_create_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - if (frame) - frame->local = NULL; - - STACK_UNWIND_STRICT (create, frame, -1, op_errno, NULL, 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_open (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_local_t *local = NULL; - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_open_req req = {{0,},}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - if (!(args->loc && args->loc->inode)) - 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; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.flags = gf_flags_from_flags (args->flags); - req.wbflags = args->wbflags; - req.path = (char *)args->loc->path; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_OPEN, client3_1_open_cbk, NULL, - xdr_from_open_req, NULL, 0, NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - if (frame) - 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, - 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,},}; - int ret = 0; - struct iovec rsp_vec = {0, }; - struct iobuf *rsp_iobuf = NULL; - struct iobref *rsp_iobref = NULL; - clnt_local_t *local = NULL; - - if (!frame || !this || !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_WARNING, - "(%"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_WARNING, "(%"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; - - rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); - if (rsp_iobuf == NULL) { - op_errno = ENOMEM; - goto unwind; - } - - rsp_iobref = iobref_new (); - if (rsp_iobref == NULL) { - op_errno = ENOMEM; - goto unwind; - } - - iobref_add (rsp_iobref, rsp_iobuf); - iobuf_unref (rsp_iobuf); - rsp_vec.iov_base = iobuf_ptr (rsp_iobuf); - rsp_vec.iov_len = rsp_iobuf->iobuf_arena->iobuf_pool->page_size; - - rsp_iobuf = NULL; - - if (args->size > rsp_vec.iov_len) { - gf_log (this->name, GF_LOG_WARNING, - "read-size (%lu) is bigger than iobuf size (%lu)", - (unsigned long)args->size, - (unsigned long)rsp_vec.iov_len); - op_errno = EINVAL; - goto unwind; - } - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (local == NULL) { - op_errno = ENOMEM; - goto unwind; - } - - local->iobref = rsp_iobref; - rsp_iobref = NULL; - frame->local = local; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_READ, client3_1_readv_cbk, NULL, - xdr_from_readv_req, NULL, 0, &rsp_vec, 1, - local->iobref); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - if (rsp_iobuf) { - iobuf_unref (rsp_iobuf); - } - - if (rsp_iobref) { - iobref_unref (rsp_iobref); - } - - 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, 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; - int ret = 0; - - if (!frame || !this || !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_WARNING, - "(%"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_WARNING, "(%"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; - - ret = client_submit_vec_request (this, &req, frame, conf->fops, GFS3_OP_WRITE, - client3_1_writev_cbk, - args->vector, args->count, - args->iobref, xdr_from_writev_req); - if (ret) - goto unwind; - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (writev, frame, -1, op_errno, NULL, NULL); - return 0; -} - - -int32_t -client3_1_flush (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - gfs3_flush_req req = {{0,},}; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - clnt_local_t *local = NULL; - int op_errno = ESTALE; - int ret = 0; - - if (!frame || !this || !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_WARNING, - "(%"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_WARNING, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - conf = this->private; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - STACK_UNWIND (frame, -1, ENOMEM); - return 0; - - } - - local->fd = fd_ref (args->fd); - local->owner = frame->root->lk_owner; - frame->local = local; - - req.fd = fdctx->remote_fd; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FLUSH, client3_1_flush_cbk, NULL, - xdr_from_flush_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (flush, frame, -1, op_errno); - return 0; -} - - - -int32_t -client3_1_fsync (call_frame_t *frame, xlator_t *this, - 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; - int ret = 0; - - if (!frame || !this || !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_WARNING, - "(%"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_WARNING, "(%"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; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FSYNC, client3_1_fsync_cbk, NULL, - xdr_from_fsync_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (fsync, frame, -1, op_errno, NULL, NULL); - return 0; -} - - - -int32_t -client3_1_fstat (call_frame_t *frame, xlator_t *this, - 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; - int ret = 0; - - if (!frame || !this || !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_WARNING, - "(%"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_WARNING, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - req.fd = fdctx->remote_fd; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FSTAT, client3_1_fstat_cbk, NULL, - xdr_from_fstat_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (fstat, frame, -1, op_errno, NULL); - return 0; -} - - - -int32_t -client3_1_opendir (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_local_t *local = NULL; - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_opendir_req req = {{0,},}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - if (!(args->loc && args->loc->inode)) - goto unwind; - - local->fd = fd_ref (args->fd); - loc_copy (&local->loc, args->loc); - frame->local = local; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.path = (char *)args->loc->path; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_OPENDIR, client3_1_opendir_cbk, - NULL, xdr_from_opendir_req, - NULL, 0, NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - if (frame) - 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, 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,},}; - int ret = 0; - - if (!frame || !this || !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_WARNING, - "(%"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_WARNING, "(%"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; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FSYNCDIR, client3_1_fsyncdir_cbk, - NULL, xdr_from_fsyncdir_req, NULL, 0, - NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (fsyncdir, frame, -1, op_errno); - return 0; -} - - - -int32_t -client3_1_statfs (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_statfs_req req = {{0,},}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!args->loc) - goto unwind; - - if (args->loc->inode) - memcpy (req.gfid, args->loc->inode->gfid, 16); - else - req.gfid[15] = 1; - - req.path = (char *)args->loc->path; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_STATFS, client3_1_statfs_cbk, NULL, - xdr_from_statfs_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (statfs, frame, -1, op_errno, NULL); - return 0; -} - - - -int32_t -client3_1_setxattr (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - 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 || !data) - goto unwind; - - args = data; - - if (!(args->loc && args->loc->inode)) - goto unwind; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - 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_WARNING, - "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; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_SETXATTR, client3_1_setxattr_cbk, - NULL, xdr_from_setxattr_req, NULL, 0, - NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - 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, - 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 || !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_WARNING, - "(%"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_WARNING, "(%"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; - memcpy (req.gfid, args->fd->inode->gfid, 16); - - 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_WARNING, - "failed to get serialized dict"); - goto unwind; - } - req.dict.dict_len = dict_len; - } - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FSETXATTR, client3_1_fsetxattr_cbk, - NULL, xdr_from_fsetxattr_req, NULL, 0, - NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - 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, - 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; - int ret = 0; - int count = 0; - clnt_local_t *local = NULL; - struct iobref *rsp_iobref = NULL; - struct iobuf *rsp_iobuf = NULL; - struct iovec *rsphdr = NULL; - struct iovec vector[MAX_IOVEC] = {{0}, }; - - if (!frame || !this || !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_WARNING, - "(%"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_WARNING, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - local = GF_CALLOC (1, sizeof (*local), - gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - frame->local = local; - - rsp_iobref = iobref_new (); - if (rsp_iobref == NULL) { - op_errno = ENOMEM; - goto unwind; - } - - rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); - if (rsp_iobuf == NULL) { - op_errno = ENOMEM; - goto unwind; - } - - iobref_add (rsp_iobref, rsp_iobuf); - iobuf_unref (rsp_iobuf); - rsphdr = &vector[0]; - rsphdr->iov_base = iobuf_ptr (rsp_iobuf); - rsphdr->iov_len = rsp_iobuf->iobuf_arena->iobuf_pool->page_size; - count = 1; - rsp_iobuf = NULL; - local->iobref = rsp_iobref; - rsp_iobref = NULL; - - 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; - } - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FGETXATTR, - client3_1_fgetxattr_cbk, NULL, - xdr_from_fgetxattr_req, rsphdr, count, - NULL, 0, local->iobref); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - local = frame->local; - frame->local = NULL; - - STACK_UNWIND_STRICT (fgetxattr, frame, -1, op_errno, NULL); - - client_local_wipe (local); - - if (rsp_iobuf) { - iobuf_unref (rsp_iobuf); - } - - if (rsp_iobref) { - iobref_unref (rsp_iobref); - } - - return 0; -} - - - -int32_t -client3_1_getxattr (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_getxattr_req req = {{0,},}; - dict_t *dict = NULL; - int ret = 0; - int32_t op_ret = 0; - int op_errno = ESTALE; - int count = 0; - clnt_local_t *local = NULL; - struct iobref *rsp_iobref = NULL; - struct iobuf *rsp_iobuf = NULL; - struct iovec *rsphdr = NULL; - struct iovec vector[MAX_IOVEC] = {{0}, }; - - if (!frame || !this || !data) { - op_ret = -1; - op_errno = 0; - goto unwind; - } - args = data; - - if (!(args->loc && args->loc->inode)) { - op_ret = -1; - op_errno = EINVAL; - goto unwind; - } - - local = GF_CALLOC (1, sizeof (*local), - gf_client_mt_clnt_local_t); - if (!local) { - op_ret = -1; - op_errno = ENOMEM; - goto unwind; - } - frame->local = local; - - rsp_iobref = iobref_new (); - if (rsp_iobref == NULL) { - op_ret = -1; - op_errno = ENOMEM; - goto unwind; - } - - rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); - if (rsp_iobuf == NULL) { - op_ret = -1; - op_errno = ENOMEM; - goto unwind; - } - - iobref_add (rsp_iobref, rsp_iobuf); - iobuf_unref (rsp_iobuf); - rsphdr = &vector[0]; - rsphdr->iov_base = iobuf_ptr (rsp_iobuf); - rsphdr->iov_len = rsp_iobuf->iobuf_arena->iobuf_pool->page_size; - count = 1; - rsp_iobuf = NULL; - local->iobref = rsp_iobref; - rsp_iobref = NULL; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - 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; - } - - conf = this->private; - - if (args && args->name) { - if (is_client_dump_locks_cmd ((char *)args->name)) { - dict = dict_new (); - ret = client_dump_locks ((char *)args->name, - args->loc->inode, - dict); - if (ret) { - gf_log (this->name, GF_LOG_WARNING, - "Client dump locks failed"); - op_ret = -1; - op_errno = EINVAL; - } - - GF_ASSERT (dict); - op_ret = 0; - op_errno = 0; - goto unwind; - } - } - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_GETXATTR, - client3_1_getxattr_cbk, NULL, - xdr_from_getxattr_req, rsphdr, count, - NULL, 0, local->iobref); - if (ret) { - op_ret = -1; - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - local = frame->local; - frame->local = NULL; - client_local_wipe (local); - - if (rsp_iobuf) { - iobuf_unref (rsp_iobuf); - } - - if (rsp_iobref) { - iobref_unref (rsp_iobref); - } - - STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno, dict); - - return 0; -} - - - -int32_t -client3_1_xattrop (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_xattrop_req req = {{0,},}; - int ret = 0; - size_t dict_len = 0; - int op_errno = ESTALE; - int count = 0; - clnt_local_t *local = NULL; - struct iobref *rsp_iobref = NULL; - struct iobuf *rsp_iobuf = NULL; - struct iovec *rsphdr = NULL; - struct iovec vector[MAX_IOVEC] = {{0}, }; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->loc && args->loc->inode)) - goto unwind; - - local = GF_CALLOC (1, sizeof (*local), - gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - frame->local = local; - - rsp_iobref = iobref_new (); - if (rsp_iobref == NULL) { - op_errno = ENOMEM; - goto unwind; - } - - rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); - if (rsp_iobuf == NULL) { - op_errno = ENOMEM; - goto unwind; - } - - iobref_add (rsp_iobref, rsp_iobuf); - iobuf_unref (rsp_iobuf); - rsphdr = &vector[0]; - rsphdr->iov_base = iobuf_ptr (rsp_iobuf); - rsphdr->iov_len = rsp_iobuf->iobuf_arena->iobuf_pool->page_size; - count = 1; - rsp_iobuf = NULL; - local->iobref = rsp_iobref; - rsp_iobref = NULL; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - 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_WARNING, - "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; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_XATTROP, - client3_1_xattrop_cbk, NULL, - xdr_from_xattrop_req, rsphdr, count, - NULL, 0, local->iobref); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - local = frame->local; - frame->local = NULL; - - STACK_UNWIND_STRICT (xattrop, frame, -1, op_errno, NULL); - - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - - client_local_wipe (local); - - if (rsp_iobuf) { - iobuf_unref (rsp_iobuf); - } - - if (rsp_iobref) { - iobref_unref (rsp_iobref); - } - - return 0; -} - - - -int32_t -client3_1_fxattrop (call_frame_t *frame, xlator_t *this, - 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; - int count = 0; - clnt_local_t *local = NULL; - struct iobref *rsp_iobref = NULL; - struct iobuf *rsp_iobuf = NULL; - struct iovec *rsphdr = NULL; - struct iovec vector[MAX_IOVEC] = {{0}, }; - - if (!frame || !this || !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_WARNING, - "(%"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_WARNING, "(%"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; - memcpy (req.gfid, args->fd->inode->gfid, 16); - - local = GF_CALLOC (1, sizeof (*local), - gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - frame->local = local; - - rsp_iobref = iobref_new (); - if (rsp_iobref == NULL) { - op_errno = ENOMEM; - goto unwind; - } - - rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); - if (rsp_iobuf == NULL) { - op_errno = ENOMEM; - goto unwind; - } - - iobref_add (rsp_iobref, rsp_iobuf); - iobuf_unref (rsp_iobuf); - rsphdr = &vector[0]; - rsphdr->iov_base = iobuf_ptr (rsp_iobuf); - rsphdr->iov_len = rsp_iobuf->iobuf_arena->iobuf_pool->page_size; - count = 1; - rsp_iobuf = NULL; - local->iobref = rsp_iobref; - rsp_iobref = NULL; - - 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_WARNING, - "failed to get serialized dict"); - goto unwind; - } - req.dict.dict_len = dict_len; - } - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FXATTROP, - client3_1_fxattrop_cbk, NULL, - xdr_from_fxattrop_req, rsphdr, count, - NULL, 0, local->iobref); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - local = frame->local; - frame->local = NULL; - - STACK_UNWIND_STRICT (fxattrop, frame, -1, op_errno, NULL); - - if (req.dict.dict_val) { - GF_FREE (req.dict.dict_val); - } - - client_local_wipe (local); - - if (rsp_iobref) { - iobref_unref (rsp_iobref); - } - - if (rsp_iobuf) { - iobuf_unref (rsp_iobuf); - } - - return 0; -} - - - -int32_t -client3_1_removexattr (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_removexattr_req req = {{0,},}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->loc && args->loc->inode)) - goto unwind; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.path = (char *)args->loc->path; - req.name = (char *)args->name; - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_REMOVEXATTR, - client3_1_removexattr_cbk, NULL, - xdr_from_removexattr_req, NULL, 0, NULL, - 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (removexattr, frame, -1, op_errno); - return 0; -} - - -int32_t -client3_1_lk (call_frame_t *frame, xlator_t *this, - 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_local_t *local = NULL; - clnt_conf_t *conf = NULL; - int op_errno = ESTALE; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - local = GF_CALLOC (1, sizeof (*local), gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - - 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_WARNING, - "(%"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_WARNING, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - ret = client_cmd_to_gf_cmd (args->cmd, &gf_cmd); - if (ret) { - op_errno = EINVAL; - gf_log (this->name, GF_LOG_WARNING, - "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; - } - - local->owner = frame->root->lk_owner; - local->cmd = args->cmd; - local->fd = fd_ref (args->fd); - frame->local = local; - - req.fd = fdctx->remote_fd; - req.cmd = gf_cmd; - req.type = gf_type; - gf_proto_flock_from_flock (&req.flock, args->flock); - - ret = client_submit_request (this, &req, frame, conf->fops, GFS3_OP_LK, - client3_1_lk_cbk, NULL, xdr_from_lk_req, - NULL, 0, NULL, 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (lk, frame, -1, op_errno, NULL); - return 0; -} - - -int32_t -client3_1_inodelk (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - 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 || !data) - goto unwind; - - args = data; - if (!(args->loc && args->loc->inode)) - goto unwind; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - 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_WARNING, - "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_proto_flock_from_flock (&req.flock, args->flock); - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_INODELK, - client3_1_inodelk_cbk, NULL, - xdr_from_inodelk_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (inodelk, frame, -1, op_errno); - return 0; -} - - - -int32_t -client3_1_finodelk (call_frame_t *frame, xlator_t *this, - 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; - int ret = 0; - - if (!frame || !this || !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_WARNING, - "(%"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_WARNING, "(%"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_WARNING, - "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_proto_flock_from_flock (&req.flock, args->flock); - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FINODELK, - client3_1_finodelk_cbk, NULL, - xdr_from_finodelk_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (finodelk, frame, -1, op_errno); - return 0; -} - - -int32_t -client3_1_entrylk (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_entrylk_req req = {{0,},}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->loc && args->loc->inode)) - goto unwind; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - 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; - } - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_ENTRYLK, - client3_1_entrylk_cbk, NULL, - xdr_from_entrylk_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (entrylk, frame, -1, op_errno); - return 0; -} - - - -int32_t -client3_1_fentrylk (call_frame_t *frame, xlator_t *this, - 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; - int ret = 0; - - if (!frame || !this || !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_WARNING, - "(%"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_WARNING, "(%"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; - } - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FENTRYLK, - client3_1_fentrylk_cbk, NULL, - xdr_from_fentrylk_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (fentrylk, frame, -1, op_errno); - return 0; -} - - -int32_t -client3_1_rchecksum (call_frame_t *frame, xlator_t *this, - 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; - int ret = 0; - - if (!frame || !this || !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_WARNING, - "(%"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_WARNING, "(%"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; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_RCHECKSUM, - client3_1_rchecksum_cbk, NULL, - xdr_from_rchecksum_req, NULL, 0, NULL, - 0, NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (rchecksum, frame, -1, op_errno, 0, NULL); - return 0; -} - - - -int32_t -client3_1_readdir (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - gfs3_readdir_req req = {{0,},}; - gfs3_readdir_rsp rsp = {0, }; - clnt_local_t *local = NULL; - int op_errno = ESTALE; - int ret = 0; - int count = 0; - struct iobref *rsp_iobref = NULL; - struct iobuf *rsp_iobuf = NULL; - struct iovec *rsphdr = NULL; - struct iovec vector[MAX_IOVEC] = {{0}, }; - int readdir_rsp_size = 0; - - if (!frame || !this || !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_WARNING, - "(%"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_WARNING, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - readdir_rsp_size = xdr_sizeof ((xdrproc_t) xdr_gfs3_readdir_rsp, &rsp) - + args->size; - - if ((readdir_rsp_size + GLUSTERFS_RPC_REPLY_SIZE + GLUSTERFS_RDMA_MAX_HEADER_SIZE) - > (GLUSTERFS_RDMA_INLINE_THRESHOLD)) { - local = GF_CALLOC (1, sizeof (*local), - gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - frame->local = local; - - rsp_iobref = iobref_new (); - if (rsp_iobref == NULL) { - goto unwind; - } - - rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); - if (rsp_iobuf == NULL) { - goto unwind; - } - - iobref_add (rsp_iobref, rsp_iobuf); - iobuf_unref (rsp_iobuf); - rsphdr = &vector[0]; - rsphdr->iov_base = iobuf_ptr (rsp_iobuf); - rsphdr->iov_len - = rsp_iobuf->iobuf_arena->iobuf_pool->page_size; - count = 1; - rsp_iobuf = NULL; - local->iobref = rsp_iobref; - } - - req.size = args->size; - req.offset = args->offset; - req.fd = fdctx->remote_fd; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_READDIR, - client3_1_readdir_cbk, NULL, - xdr_from_readdir_req, rsphdr, count, - NULL, 0, rsp_iobref); - rsp_iobref = NULL; - - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; - -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - local = frame->local; - frame->local = NULL; - client_local_wipe (local); - - if (rsp_iobref != NULL) { - iobref_unref (rsp_iobref); - } - - if (rsp_iobuf != NULL) { - iobuf_unref (rsp_iobuf); - } - - STACK_UNWIND_STRICT (readdir, frame, -1, op_errno, NULL); - return 0; -} - - -int32_t -client3_1_readdirp (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - gfs3_readdirp_req req = {{0,},}; - gfs3_readdirp_rsp rsp = {0,}; - clnt_fd_ctx_t *fdctx = NULL; - clnt_conf_t *conf = NULL; - int op_errno = ESTALE; - int ret = 0; - int count = 0; - int readdirp_rsp_size = 0; - struct iobref *rsp_iobref = NULL; - struct iobuf *rsp_iobuf = NULL; - struct iovec *rsphdr = NULL; - struct iovec vector[MAX_IOVEC] = {{0}, }; - clnt_local_t *local = NULL; - - if (!frame || !this || !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_WARNING, - "(%"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_WARNING, "(%"PRId64"): failed to get" - " fd ctx. EBADFD", args->fd->inode->ino); - op_errno = EBADFD; - goto unwind; - } - - readdirp_rsp_size = xdr_sizeof ((xdrproc_t) xdr_gfs3_readdirp_rsp, &rsp) - + args->size; - - if ((readdirp_rsp_size + GLUSTERFS_RPC_REPLY_SIZE - + GLUSTERFS_RDMA_MAX_HEADER_SIZE) - > (GLUSTERFS_RDMA_INLINE_THRESHOLD)) { - local = GF_CALLOC (1, sizeof (*local), - gf_client_mt_clnt_local_t); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - frame->local = local; - - rsp_iobref = iobref_new (); - if (rsp_iobref == NULL) { - goto unwind; - } - - rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); - if (rsp_iobuf == NULL) { - goto unwind; - } - - iobref_add (rsp_iobref, rsp_iobuf); - iobuf_unref (rsp_iobuf); - rsphdr = &vector[0]; - rsphdr->iov_base = iobuf_ptr (rsp_iobuf); - rsphdr->iov_len - = rsp_iobuf->iobuf_arena->iobuf_pool->page_size; - count = 1; - rsp_iobuf = NULL; - local->iobref = rsp_iobref; - rsp_iobref = NULL; - } - - req.size = args->size; - req.offset = args->offset; - req.fd = fdctx->remote_fd; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_READDIRP, - client3_1_readdirp_cbk, NULL, - xdr_from_readdirp_req, rsphdr, count, NULL, - 0, rsp_iobref); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - local = frame->local; - frame->local = NULL; - client_local_wipe (local); - - if (rsp_iobref) { - iobref_unref (rsp_iobref); - } - - if (rsp_iobuf) { - iobuf_unref (rsp_iobuf); - } - - STACK_UNWIND_STRICT (readdirp, frame, -1, op_errno, NULL); - return 0; -} - - -int32_t -client3_1_setattr (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs3_setattr_req req = {{0,},}; - int ret = 0; - int op_errno = ESTALE; - - if (!frame || !this || !data) - goto unwind; - - args = data; - - if (!(args->loc && args->loc->inode)) - goto unwind; - - memcpy (req.gfid, args->loc->inode->gfid, 16); - req.path = (char *)args->loc->path; - req.valid = args->valid; - gf_stat_from_iatt (&req.stbuf, args->stbuf); - - conf = this->private; - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_SETATTR, - client3_1_setattr_cbk, NULL, - xdr_from_setattr_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (setattr, frame, -1, op_errno, NULL, NULL); - return 0; -} - -int32_t -client3_1_fsetattr (call_frame_t *frame, xlator_t *this, 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; - int ret = 0; - - if (!frame || !this || !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_WARNING, - "(%"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_WARNING, "(%"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); - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FSETATTR, - client3_1_fsetattr_cbk, NULL, - xdr_from_fsetattr_req, NULL, 0, NULL, 0, - NULL); - if (ret) { - op_errno = ENOTCONN; - goto unwind; - } - - return 0; -unwind: - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop: %s", strerror (op_errno)); - STACK_UNWIND_STRICT (fsetattr, frame, -1, op_errno, NULL, NULL); - return 0; -} - - - -/* Table Specific to FOPS */ - - -rpc_clnt_procedure_t clnt3_1_fop_actors[GF_FOP_MAXVALUE] = { - [GF_FOP_NULL] = { "NULL", NULL}, - [GF_FOP_STAT] = { "STAT", client3_1_stat }, - [GF_FOP_READLINK] = { "READLINK", client3_1_readlink }, - [GF_FOP_MKNOD] = { "MKNOD", client3_1_mknod }, - [GF_FOP_MKDIR] = { "MKDIR", client3_1_mkdir }, - [GF_FOP_UNLINK] = { "UNLINK", client3_1_unlink }, - [GF_FOP_RMDIR] = { "RMDIR", client3_1_rmdir }, - [GF_FOP_SYMLINK] = { "SYMLINK", client3_1_symlink }, - [GF_FOP_RENAME] = { "RENAME", client3_1_rename }, - [GF_FOP_LINK] = { "LINK", client3_1_link }, - [GF_FOP_TRUNCATE] = { "TRUNCATE", client3_1_truncate }, - [GF_FOP_OPEN] = { "OPEN", client3_1_open }, - [GF_FOP_READ] = { "READ", client3_1_readv }, - [GF_FOP_WRITE] = { "WRITE", client3_1_writev }, - [GF_FOP_STATFS] = { "STATFS", client3_1_statfs }, - [GF_FOP_FLUSH] = { "FLUSH", client3_1_flush }, - [GF_FOP_FSYNC] = { "FSYNC", client3_1_fsync }, - [GF_FOP_SETXATTR] = { "SETXATTR", client3_1_setxattr }, - [GF_FOP_GETXATTR] = { "GETXATTR", client3_1_getxattr }, - [GF_FOP_REMOVEXATTR] = { "REMOVEXATTR", client3_1_removexattr }, - [GF_FOP_OPENDIR] = { "OPENDIR", client3_1_opendir }, - [GF_FOP_FSYNCDIR] = { "FSYNCDIR", client3_1_fsyncdir }, - [GF_FOP_ACCESS] = { "ACCESS", client3_1_access }, - [GF_FOP_CREATE] = { "CREATE", client3_1_create }, - [GF_FOP_FTRUNCATE] = { "FTRUNCATE", client3_1_ftruncate }, - [GF_FOP_FSTAT] = { "FSTAT", client3_1_fstat }, - [GF_FOP_LK] = { "LK", client3_1_lk }, - [GF_FOP_LOOKUP] = { "LOOKUP", client3_1_lookup }, - [GF_FOP_READDIR] = { "READDIR", client3_1_readdir }, - [GF_FOP_INODELK] = { "INODELK", client3_1_inodelk }, - [GF_FOP_FINODELK] = { "FINODELK", client3_1_finodelk }, - [GF_FOP_ENTRYLK] = { "ENTRYLK", client3_1_entrylk }, - [GF_FOP_FENTRYLK] = { "FENTRYLK", client3_1_fentrylk }, - [GF_FOP_XATTROP] = { "XATTROP", client3_1_xattrop }, - [GF_FOP_FXATTROP] = { "FXATTROP", client3_1_fxattrop }, - [GF_FOP_FGETXATTR] = { "FGETXATTR", client3_1_fgetxattr }, - [GF_FOP_FSETXATTR] = { "FSETXATTR", client3_1_fsetxattr }, - [GF_FOP_RCHECKSUM] = { "RCHECKSUM", client3_1_rchecksum }, - [GF_FOP_SETATTR] = { "SETATTR", client3_1_setattr }, - [GF_FOP_FSETATTR] = { "FSETATTR", client3_1_fsetattr }, - [GF_FOP_READDIRP] = { "READDIRP", client3_1_readdirp }, - [GF_FOP_RELEASE] = { "RELEASE", client3_1_release }, - [GF_FOP_RELEASEDIR] = { "RELEASEDIR", client3_1_releasedir }, - [GF_FOP_GETSPEC] = { "GETSPEC", client3_getspec }, -}; - -/* Used From RPC-CLNT library to log proper name of procedure based on number */ -char *clnt3_1_fop_names[GFS3_OP_MAXVALUE] = { - [GFS3_OP_NULL] = "NULL", - [GFS3_OP_STAT] = "STAT", - [GFS3_OP_READLINK] = "READLINK", - [GFS3_OP_MKNOD] = "MKNOD", - [GFS3_OP_MKDIR] = "MKDIR", - [GFS3_OP_UNLINK] = "UNLINK", - [GFS3_OP_RMDIR] = "RMDIR", - [GFS3_OP_SYMLINK] = "SYMLINK", - [GFS3_OP_RENAME] = "RENAME", - [GFS3_OP_LINK] = "LINK", - [GFS3_OP_TRUNCATE] = "TRUNCATE", - [GFS3_OP_OPEN] = "OPEN", - [GFS3_OP_READ] = "READ", - [GFS3_OP_WRITE] = "WRITE", - [GFS3_OP_STATFS] = "STATFS", - [GFS3_OP_FLUSH] = "FLUSH", - [GFS3_OP_FSYNC] = "FSYNC", - [GFS3_OP_SETXATTR] = "SETXATTR", - [GFS3_OP_GETXATTR] = "GETXATTR", - [GFS3_OP_REMOVEXATTR] = "REMOVEXATTR", - [GFS3_OP_OPENDIR] = "OPENDIR", - [GFS3_OP_FSYNCDIR] = "FSYNCDIR", - [GFS3_OP_ACCESS] = "ACCESS", - [GFS3_OP_CREATE] = "CREATE", - [GFS3_OP_FTRUNCATE] = "FTRUNCATE", - [GFS3_OP_FSTAT] = "FSTAT", - [GFS3_OP_LK] = "LK", - [GFS3_OP_LOOKUP] = "LOOKUP", - [GFS3_OP_READDIR] = "READDIR", - [GFS3_OP_INODELK] = "INODELK", - [GFS3_OP_FINODELK] = "FINODELK", - [GFS3_OP_ENTRYLK] = "ENTRYLK", - [GFS3_OP_FENTRYLK] = "FENTRYLK", - [GFS3_OP_XATTROP] = "XATTROP", - [GFS3_OP_FXATTROP] = "FXATTROP", - [GFS3_OP_FGETXATTR] = "FGETXATTR", - [GFS3_OP_FSETXATTR] = "FSETXATTR", - [GFS3_OP_RCHECKSUM] = "RCHECKSUM", - [GFS3_OP_SETATTR] = "SETATTR", - [GFS3_OP_FSETATTR] = "FSETATTR", - [GFS3_OP_READDIRP] = "READDIRP", - [GFS3_OP_RELEASE] = "RELEASE", - [GFS3_OP_RELEASEDIR] = "RELEASEDIR", -}; - -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, - .proctable = clnt3_1_fop_actors, - .procnames = clnt3_1_fop_names, -}; |
