summaryrefslogtreecommitdiffstats
path: root/xlators/protocol/client/src/client-handshake.c
diff options
context:
space:
mode:
authorKrishnan Parthasarathi <kparthas@redhat.com>2014-04-07 10:57:45 +0530
committerAnand Avati <avati@redhat.com>2014-04-29 14:23:51 -0700
commitc61bc1f9e5874cb8380ec6398680fc71aea233b4 (patch)
treec02fee67ebcc7c43a6338d34c5700916e672c110 /xlators/protocol/client/src/client-handshake.c
parent91ab65f812ec3b674f53230eacbd0d71964d3d01 (diff)
glusterd: Ping timer implmentation
This patch refactors the existing client ping timer implementation, and makes use of the common code for implementing both client ping timer and the glusterd ping timer. A new gluster rpc program for ping is introduced. The ping timer is only started for peers that have this new program. The deafult glusterd ping timeout is 30 seconds. It is configurable by setting the option 'ping-timeout' in glusterd.vol . Also, this patch introduces changes in the glusterd-handshake path. The client programs for a peer are now set in the callback of dump_versions, for both the older handshake and the newer op-version handshake. This is the only place in the handshake process where we know what programs a peer supports. Change-Id: I035815ac13449ca47080ecc3253c0a9afbe9016a BUG: 1038261 Signed-off-by: Vijaikumar M <vmallika@redhat.com> Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com> Reviewed-on: http://review.gluster.org/5202 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'xlators/protocol/client/src/client-handshake.c')
-rw-r--r--xlators/protocol/client/src/client-handshake.c262
1 files changed, 0 insertions, 262 deletions
diff --git a/xlators/protocol/client/src/client-handshake.c b/xlators/protocol/client/src/client-handshake.c
index 85b0f757bf4..cf91c3b723c 100644
--- a/xlators/protocol/client/src/client-handshake.c
+++ b/xlators/protocol/client/src/client-handshake.c
@@ -29,9 +29,6 @@
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);
@@ -44,265 +41,6 @@ typedef struct client_fd_lk_local {
clnt_fd_ctx_t *fdctx;
}clnt_fd_lk_local_t;
-/* Handshake */
-
-void
-rpc_client_ping_timer_expired (void *data)
-{
- rpc_transport_t *trans = NULL;
- rpc_clnt_connection_t *conn = NULL;
- int disconnect = 0;
- int transport_activity = 0;
- struct timespec timeout = {0, };
- struct timeval current = {0, };
- struct rpc_clnt *clnt = NULL;
- xlator_t *this = NULL;
- clnt_conf_t *conf = NULL;
-
- this = data;
-
- if (!this || !this->private) {
- gf_log (THIS->name, GF_LOG_WARNING, "xlator initialization not done");
- goto out;
- }
-
- conf = this->private;
-
- clnt = conf->rpc;
- if (!clnt) {
- gf_log (this->name, GF_LOG_WARNING, "rpc not initialized");
- goto out;
- }
-
- conn = &clnt->conn;
- trans = conn->trans;
-
- if (!trans) {
- gf_log (this->name, GF_LOG_WARNING, "transport not initialized");
- goto out;
- }
-
- pthread_mutex_lock (&conn->lock);
- {
- if (conn->ping_timer)
- gf_timer_call_cancel (this->ctx,
- conn->ping_timer);
- gettimeofday (&current, NULL);
-
- if (((current.tv_sec - conn->last_received.tv_sec) <
- conf->opt.ping_timeout)
- || ((current.tv_sec - conn->last_sent.tv_sec) <
- conf->opt.ping_timeout)) {
- transport_activity = 1;
- }
-
- if (transport_activity) {
- gf_log (trans->name, GF_LOG_TRACE,
- "ping timer expired but transport activity "
- "detected - not bailing transport");
- timeout.tv_sec = conf->opt.ping_timeout;
- timeout.tv_nsec = 0;
-
- conn->ping_timer =
- gf_timer_call_after (this->ctx, timeout,
- rpc_client_ping_timer_expired,
- (void *) this);
- if (conn->ping_timer == NULL)
- gf_log (trans->name, GF_LOG_WARNING,
- "unable to setup ping timer");
-
- } else {
- conn->ping_started = 0;
- conn->ping_timer = NULL;
- disconnect = 1;
- }
- }
- pthread_mutex_unlock (&conn->lock);
-
- if (disconnect) {
- gf_log (trans->name, GF_LOG_CRITICAL,
- "server %s has not responded in the last %d "
- "seconds, disconnecting.",
- conn->trans->peerinfo.identifier,
- conf->opt.ping_timeout);
-
- rpc_transport_disconnect (conn->trans);
- }
-
-out:
- return;
-}
-
-void
-client_start_ping (void *data)
-{
- xlator_t *this = NULL;
- clnt_conf_t *conf = NULL;
- rpc_clnt_connection_t *conn = NULL;
- int32_t ret = -1;
- struct timespec timeout = {0, };
- call_frame_t *frame = NULL;
- int frame_count = 0;
-
- this = data;
- if (!this || !this->private) {
- gf_log (THIS->name, GF_LOG_WARNING, "xlator not initialized");
- goto fail;
- }
-
- conf = this->private;
- if (!conf->rpc) {
- gf_log (this->name, GF_LOG_WARNING, "rpc not initialized");
- goto fail;
- }
- conn = &conf->rpc->conn;
-
- if (conf->opt.ping_timeout == 0) {
- gf_log (this->name, GF_LOG_INFO, "ping timeout is 0, returning");
- return;
- }
-
- pthread_mutex_lock (&conn->lock);
- {
- if (conn->ping_timer)
- gf_timer_call_cancel (this->ctx, conn->ping_timer);
-
- conn->ping_timer = NULL;
- conn->ping_started = 0;
-
- if (conn->saved_frames)
- /* treat the case where conn->saved_frames is NULL
- as no pending frames */
- frame_count = conn->saved_frames->count;
-
- if ((frame_count == 0) || !conn->connected) {
- /* using goto looked ugly here,
- * hence getting out this way */
- /* unlock */
- gf_log (this->name, GF_LOG_DEBUG,
- "returning as transport is already disconnected"
- " OR there are no frames (%d || %d)",
- frame_count, !conn->connected);
-
- pthread_mutex_unlock (&conn->lock);
- return;
- }
-
- if (frame_count < 0) {
- gf_log (this->name, GF_LOG_WARNING,
- "saved_frames->count is %"PRId64,
- conn->saved_frames->count);
- conn->saved_frames->count = 0;
- }
-
- timeout.tv_sec = conf->opt.ping_timeout;
- timeout.tv_nsec = 0;
-
- conn->ping_timer =
- gf_timer_call_after (this->ctx, timeout,
- rpc_client_ping_timer_expired,
- (void *) this);
-
- if (conn->ping_timer == NULL) {
- gf_log (this->name, GF_LOG_WARNING,
- "unable to setup ping timer");
- } else {
- conn->ping_started = 1;
- }
- }
- pthread_mutex_unlock (&conn->lock);
-
- frame = create_frame (this, this->ctx->pool);
- if (!frame)
- goto fail;
-
- ret = client_submit_request (this, NULL, frame, conf->handshake,
- GF_HNDSK_PING, 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:
- if (frame) {
- STACK_DESTROY (frame->root);
- }
-
- return;
-}
-
-
-int
-client_ping_cbk (struct rpc_req *req, struct iovec *iov, int count,
- void *myframe)
-{
- xlator_t *this = NULL;
- rpc_clnt_connection_t *conn = NULL;
- struct timespec timeout = {0, };
- call_frame_t *frame = NULL;
- clnt_conf_t *conf = NULL;
-
- if (!myframe) {
- 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 (THIS->name, GF_LOG_WARNING,
- "xlator private is not set");
- goto out;
- }
-
- conf = this->private;
- conn = &conf->rpc->conn;
-
- 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_nsec = 0;
-
- gf_timer_call_cancel (this->ctx,
- conn->ping_timer);
-
- conn->ping_timer =
- gf_timer_call_after (this->ctx, timeout,
- client_start_ping, (void *)this);
-
- if (conn->ping_timer == NULL)
- gf_log (this->name, GF_LOG_WARNING,
- "failed to set the ping timer");
- }
-unlock:
- pthread_mutex_unlock (&conn->lock);
-out:
- if (frame)
- STACK_DESTROY (frame->root);
- return 0;
-}
-
-
int
client3_getspec_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)