summaryrefslogtreecommitdiffstats
path: root/xlators/protocol
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
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')
-rw-r--r--xlators/protocol/client/src/client-handshake.c262
-rw-r--r--xlators/protocol/client/src/client-rpc-fops.c18
-rw-r--r--xlators/protocol/client/src/client.c15
-rw-r--r--xlators/protocol/server/src/server-handshake.c1
-rw-r--r--xlators/protocol/server/src/server-rpc-fops.c1
-rw-r--r--xlators/protocol/server/src/server.h2
6 files changed, 3 insertions, 296 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)
diff --git a/xlators/protocol/client/src/client-rpc-fops.c b/xlators/protocol/client/src/client-rpc-fops.c
index 99a6f6d7492..e77da7a27d6 100644
--- a/xlators/protocol/client/src/client-rpc-fops.c
+++ b/xlators/protocol/client/src/client-rpc-fops.c
@@ -14,12 +14,12 @@
#endif
#include "client.h"
+#include "rpc-common-xdr.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;
@@ -35,13 +35,10 @@ client_submit_vec_request (xlator_t *this, void *req, call_frame_t *frame,
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) {
@@ -95,19 +92,6 @@ client_submit_vec_request (xlator_t *this, void *req, call_frame_t *frame,
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);
diff --git a/xlators/protocol/client/src/client.c b/xlators/protocol/client/src/client.c
index 98fb10c34eb..7726c0b8445 100644
--- a/xlators/protocol/client/src/client.c
+++ b/xlators/protocol/client/src/client.c
@@ -29,7 +29,6 @@ extern rpc_clnt_prog_t clnt_dump_prog;
extern struct rpcclnt_cb_program gluster_cbk_prog;
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);
@@ -156,7 +155,6 @@ client_submit_request (xlator_t *this, void *req, call_frame_t *frame,
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, };
@@ -235,19 +233,6 @@ client_submit_request (xlator_t *this, void *req, call_frame_t *frame,
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);
-
ret = 0;
if (new_iobref)
diff --git a/xlators/protocol/server/src/server-handshake.c b/xlators/protocol/server/src/server-handshake.c
index a459f89e182..f3ae96ef2ae 100644
--- a/xlators/protocol/server/src/server-handshake.c
+++ b/xlators/protocol/server/src/server-handshake.c
@@ -16,6 +16,7 @@
#include "server.h"
#include "server-helpers.h"
+#include "rpc-common-xdr.h"
#include "glusterfs3-xdr.h"
#include "compat-errno.h"
#include "glusterfs3.h"
diff --git a/xlators/protocol/server/src/server-rpc-fops.c b/xlators/protocol/server/src/server-rpc-fops.c
index ebe62ae7c42..ce844197d90 100644
--- a/xlators/protocol/server/src/server-rpc-fops.c
+++ b/xlators/protocol/server/src/server-rpc-fops.c
@@ -18,6 +18,7 @@
#include "server.h"
#include "server-helpers.h"
+#include "rpc-common-xdr.h"
#include "glusterfs3-xdr.h"
#include "glusterfs3.h"
#include "compat-errno.h"
diff --git a/xlators/protocol/server/src/server.h b/xlators/protocol/server/src/server.h
index 782327d775b..c5ab579140d 100644
--- a/xlators/protocol/server/src/server.h
+++ b/xlators/protocol/server/src/server.h
@@ -174,8 +174,6 @@ struct _server_state {
extern struct rpcsvc_program gluster_handshake_prog;
extern struct rpcsvc_program glusterfs3_3_fop_prog;
-extern struct rpcsvc_program gluster_ping_prog;
-
typedef struct _server_ctx {
gf_lock_t fdtable_lock;